Ticket #8293: Network.diff

File Network.diff, 5.8 KB (added by donn, 9 years ago)

Network pref patch

  • src/preferences/network/EthernetSettingsView.cpp

    diff --git a/src/preferences/network/EthernetSettingsView.cpp b/src/preferences/network/EthernetSettingsView.cpp
    index 0250b24..65404f0 100644
    a b static const uint32 kMsgField = 'fild';  
    5757static const uint32 kMsgInfo = 'info';
    5858static const uint32 kMsgStaticMode = 'stcm';
    5959static const uint32 kMsgDHCPMode = 'dynm';
     60static const uint32 kMsgIPv4Type = 'ipv4';
     61static const uint32 kMsgIPv6Type = 'ipv6';
    6062static const uint32 kMsgDisabledMode = 'disa';
    6163static const uint32 kMsgChange = 'chng';
    6264static const uint32 kMsgNetwork = 'netw';
    EthernetSettingsView::EthernetSettingsView()  
    187189    layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8);
    188190    layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8);
    189191
     192    BPopUpMenu* inet4Menu = new BPopUpMenu("IP type");
     193    inet4Menu->AddItem(new BMenuItem(B_TRANSLATE("IPv4 only"),
     194        new BMessage(kMsgIPv4Type)));
     195    inet4Menu->AddItem(new BMenuItem(B_TRANSLATE("IPv4 and IPv6"),
     196        new BMessage(kMsgIPv6Type)));
     197    fInet4MenuField = new BMenuField(B_TRANSLATE("IP Type:"), inet4Menu);
     198    layout->AddItem(fInet4MenuField->CreateLabelLayoutItem(), 0, 9);
     199    layout->AddItem(fInet4MenuField->CreateMenuBarLayoutItem(), 1, 9);
     200
    190201    fErrorMessage = new BStringView("error", "");
    191202    fErrorMessage->SetAlignment(B_ALIGN_LEFT);
    192203    fErrorMessage->SetFont(be_bold_font);
    193204    fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
    194205
    195     layout->AddView(fErrorMessage, 1, 9);
     206    layout->AddView(fErrorMessage, 1, 10);
    196207
    197208    // button group (TODO: move to window, but take care of
    198209    // enabling/disabling)
    EthernetSettingsView::AttachedToWindow()  
    234245    fDeviceMenuField->Menu()->SetTargetForItems(this);
    235246    fNetworkMenuField->Menu()->SetTargetForItems(this);
    236247    fTypeMenuField->Menu()->SetTargetForItems(this);
     248    fInet4MenuField->Menu()->SetTargetForItems(this);
    237249
    238250    // Display settigs of first adapter on startup, if any
    239251    _ShowConfiguration(fSettings.ItemAt(0));
    EthernetSettingsView::MessageReceived(BMessage* message)  
    258270            fApplyButton->SetEnabled(true);
    259271            fRevertButton->SetEnabled(true);
    260272            break;
     273        case kMsgIPv4Type:
     274        case kMsgIPv6Type:
     275            fApplyButton->SetEnabled(true);
     276            fRevertButton->SetEnabled(true);
     277            break;
    261278        case kMsgInfo:
    262279        {
    263280            const char* name;
    EthernetSettingsView::_ShowConfiguration(Settings* settings)  
    332349
    333350    fDeviceMenuField->SetEnabled(settings != NULL);
    334351    fTypeMenuField->SetEnabled(settings != NULL);
     352    fInet4MenuField->SetEnabled(settings != NULL);
    335353
    336354    bool enableControls = false;
    337355    BMenuItem* item;
    EthernetSettingsView::_ShowConfiguration(Settings* settings)  
    347365    if (item != NULL)
    348366        item->SetMarked(true);
    349367
     368    if (settings == NULL || settings->Inet4())
     369        item = fInet4MenuField->Menu()->FindItem(B_TRANSLATE("IPv4 only"));
     370    else
     371        item = fInet4MenuField->Menu()->FindItem(B_TRANSLATE("IPv4 and IPv6"));
     372    if (item != NULL)
     373        item->SetMarked(true);
     374
    350375    if (settings == NULL) {
    351376        if (!fNetworkMenuField->IsHidden(fNetworkMenuField))
    352377            fNetworkMenuField->Hide();
    EthernetSettingsView::_ApplyControlsToConfiguration()  
    473498        fSecondaryDNSTextControl->Text()));
    474499    fCurrentSettings->SetDomain(fDomainTextControl->Text());
    475500
     501    fCurrentSettings->SetInet4(
     502        strcmp(fInet4MenuField->Menu()->FindMarked()->Label(),
     503            B_TRANSLATE("IPv4 only")) == 0);
     504
    476505    fApplyButton->SetEnabled(false);
    477506    fRevertButton->SetEnabled(true);
    478507}
    EthernetSettingsView::_SaveDNSConfiguration()  
    521550                << settings->Domain()
    522551                << "\n";
    523552        }
     553        if (settings->Inet4()) {
     554            content << "options inet4\n";
     555        }
    524556    }
    525557
    526558    file.Write(content.String(), content.Length());
  • src/preferences/network/EthernetSettingsView.h

    diff --git a/src/preferences/network/EthernetSettingsView.h b/src/preferences/network/EthernetSettingsView.h
    index 24fd31f..135ace4 100644
    a b private:  
    5757                BMenuField*     fDeviceMenuField;
    5858                BMenuField*     fNetworkMenuField;
    5959                BMenuField*     fTypeMenuField;
     60                BMenuField*     fInet4MenuField;
    6061                BTextControl*   fIPTextControl;
    6162                BTextControl*   fNetMaskTextControl;
    6263                BTextControl*   fGatewayTextControl;
  • src/preferences/network/Settings.cpp

    diff --git a/src/preferences/network/Settings.cpp b/src/preferences/network/Settings.cpp
    index 8601b56..747537d 100644
    a b Settings::Settings(const char* name)  
    3636    :
    3737    fAuto(true),
    3838    fDisabled(false),
    39     fNameServers(5, true)
     39    fNameServers(5, true),
     40    fInet4(true)
    4041{
    4142    fSocket = socket(AF_INET, SOCK_DGRAM, 0);
    4243    fName = name;
    Settings::ReadConfiguration()  
    216217                new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
    217218        }
    218219        fDomain = state->dnsrch[0];
     220        fInet4 = (state->options & RES_USE_INET4) != 0;
    219221    }
    220222}
  • src/preferences/network/Settings.h

    diff --git a/src/preferences/network/Settings.h b/src/preferences/network/Settings.h
    index 2f54ca7..6d03eaf 100644
    a b public:  
    3333                                    { fDisabled = disabled; }
    3434            void                SetWirelessNetwork(const char* name)
    3535                                    { fWirelessNetwork.SetTo(name); }
     36            void                SetInet4(bool inet4)
     37                                    { fInet4 = inet4; }
    3638
    3739            const char*         IP()  { return fIP.String(); }
    3840            const char*         Gateway()  { return fGateway.String(); }
    public:  
    4143            const char*         Domain() { return fDomain.String(); }
    4244            bool                AutoConfigure() { return fAuto; }
    4345            bool                IsDisabled() { return fDisabled; }
     46            bool                Inet4() { return fInet4; }
    4447            const BString&      WirelessNetwork() { return fWirelessNetwork; }
    4548
    4649            BObjectList<BString>& NameServers() { return fNameServers; }
    private:  
    6063            bool                fDisabled;
    6164            BObjectList<BString> fNameServers;
    6265            BString             fWirelessNetwork;
     66            bool                fInet4;
    6367};
    6468
    6569