void EthernetSettingsView::MessageReceived(BMessage* message) { switch (message->what) { case kMsgStaticMode: case kMsgDHCPMode: case kMsgDisabledMode: case kMsgNetwork: _EnableTextControls(message->what == kMsgStaticMode); fApplyButton->SetEnabled(true); fRevertButton->SetEnabled(true); break; case kMsgInfo: { const char* name; if (message->FindString("interface", &name) != B_OK) break; for (int32 i = 0; i < fSettings.CountItems(); i++) { Settings* settings = fSettings.ItemAt(i); if (strcmp(settings->Name(), name) == 0) { _ShowConfiguration(settings); break; } } break; } case kMsgRevert: _ShowConfiguration(fCurrentSettings); fRevertButton->SetEnabled(false); break; case kMsgApply: if (_ValidateControl(fIPTextControl) && _ValidateControl(fNetMaskTextControl) && (strlen(fGatewayTextControl->Text()) == 0 || _ValidateControl(fGatewayTextControl)) && (strlen(fPrimaryDNSTextControl->Text()) == 0 || _ValidateControl(fPrimaryDNSTextControl)) && (strlen(fSecondaryDNSTextControl->Text()) == 0 || _ValidateControl(fSecondaryDNSTextControl))) _SaveConfiguration(); break; case kMsgChange: fErrorMessage->SetText(""); fApplyButton->SetEnabled(true); break; default: BView::MessageReceived(message); } }
void EthernetSettingsView::_ShowConfiguration(Settings* settings) { fCurrentSettings = settings; // Clear the inputs. fIPTextControl->SetText(""); fGatewayTextControl->SetText(""); fNetMaskTextControl->SetText(""); fPrimaryDNSTextControl->SetText(""); fSecondaryDNSTextControl->SetText(""); bool enableControls = false; fTypeMenuField->SetEnabled(settings != NULL); if (settings) { BMenuItem* item = fDeviceMenuField->Menu()->FindItem( settings->Name()); if (item) item->SetMarked(true); fIPTextControl->SetText(settings->IP()); fGatewayTextControl->SetText(settings->Gateway()); fNetMaskTextControl->SetText(settings->Netmask()); if (settings->AutoConfigure() == true) item = fTypeMenuField->Menu()->FindItem(TR("DHCP")); else item = fTypeMenuField->Menu()->FindItem(TR("Static")); if (item) item->SetMarked(true); enableControls = settings->AutoConfigure() == false; if (settings->NameServers().CountItems() >= 2) { fSecondaryDNSTextControl->SetText( settings->NameServers().ItemAt(1)->String()); } if (settings->NameServers().CountItems() >= 1) { fPrimaryDNSTextControl->SetText( settings->NameServers().ItemAt(0)->String()); } } _EnableTextControls(enableControls); }
void EthernetSettingsView::_ShowConfiguration(Settings* settings) { fCurrentSettings = settings; // Clear the inputs. fIPTextControl->SetText(""); fGatewayTextControl->SetText(""); fNetMaskTextControl->SetText(""); fPrimaryDNSTextControl->SetText(""); fSecondaryDNSTextControl->SetText(""); fDomainTextControl->SetText(""); fDeviceMenuField->SetEnabled(settings != NULL); fTypeMenuField->SetEnabled(settings != NULL); bool enableControls = false; BMenuItem* item; if (settings == NULL || settings->IsDisabled()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled")); else if (settings->AutoConfigure()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP")); else { item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static")); enableControls = true; } if (item != NULL) item->SetMarked(true); if (settings == NULL) { if (!fNetworkMenuField->IsHidden(fNetworkMenuField)) fNetworkMenuField->Hide(); _EnableTextControls(false); return; } // Show/hide networks menu BNetworkDevice device(settings->Name()); if (fNetworkMenuField->IsHidden(fNetworkMenuField) && device.IsWireless()) { fNetworkMenuField->Show(); Window()->InvalidateLayout(); } else if (!fNetworkMenuField->IsHidden(fNetworkMenuField) && !device.IsWireless()) { fNetworkMenuField->Hide(); Window()->InvalidateLayout(); } if (device.IsWireless()) { // Rebuild network menu BMenu* menu = fNetworkMenuField->Menu(); menu->RemoveItems(0, menu->CountItems(), true); wireless_network network; int32 count = 0; uint32 cookie = 0; while (device.GetNextNetwork(cookie, network) == B_OK) { BMessage* message = new BMessage(kMsgNetwork); message->AddString("device", device.Name()); message->AddString("name", network.name); BMenuItem* item = new WirelessNetworkMenuItem(network.name, network.signal_strength, (network.flags & B_NETWORK_IS_ENCRYPTED) != 0, message); if (fCurrentSettings->WirelessNetwork() == network.name) item->SetMarked(true); menu->AddItem(item); count++; } if (count == 0) { BMenuItem* item = new BMenuItem( B_TRANSLATE("<no wireless networks found>"), NULL); item->SetEnabled(false); menu->AddItem(item); } else { BMenuItem* item = new BMenuItem( B_TRANSLATE("Choose automatically"), NULL); if (menu->FindMarked() == NULL) item->SetMarked(true); menu->AddItem(item, 0); menu->AddItem(new BSeparatorItem(), 1); } menu->SetTargetForItems(this); } item = fDeviceMenuField->Menu()->FindItem(settings->Name()); if (item != NULL) item->SetMarked(true); fIPTextControl->SetText(settings->IP()); fGatewayTextControl->SetText(settings->Gateway()); fNetMaskTextControl->SetText(settings->Netmask()); if (settings->NameServers().CountItems() >= 2) { fSecondaryDNSTextControl->SetText( settings->NameServers().ItemAt(1)->String()); } if (settings->NameServers().CountItems() >= 1) { fPrimaryDNSTextControl->SetText( settings->NameServers().ItemAt(0)->String()); } fDomainTextControl->SetText(settings->Domain()); _EnableTextControls(enableControls); }
void IPSettingsView::_ShowConfiguration(Settings* settings) { // Clear the inputs. fIPTextControl->SetText(""); fGatewayTextControl->SetText(""); fNetMaskTextControl->SetText(""); fPrimaryDNSTextControl->SetText(""); fSecondaryDNSTextControl->SetText(""); fDomainTextControl->SetText(""); fDeviceMenuField->SetEnabled(settings != NULL); fTypeMenuField->SetEnabled(settings != NULL); bool enableControls = false; BMenuItem* item; if (settings == NULL || settings->IsDisabled()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled")); else if (settings->AutoConfigure()) item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP")); else { item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static")); enableControls = true; } if (item != NULL) item->SetMarked(true); if (settings == NULL) { if (!fNetworkMenuField->IsHidden(fNetworkMenuField)) fNetworkMenuField->Hide(); _EnableTextControls(false); return; } // Show/hide networks menu BNetworkDevice device(settings->Name()); if (fNetworkMenuField->IsHidden(fNetworkMenuField) && device.IsWireless()) { fNetworkMenuField->Show(); Window()->InvalidateLayout(); } else if (!fNetworkMenuField->IsHidden(fNetworkMenuField) && !device.IsWireless()) { fNetworkMenuField->Hide(); Window()->InvalidateLayout(); } item = fDeviceMenuField->Menu()->FindItem(settings->Name()); if (item != NULL) item->SetMarked(true); fIPTextControl->SetText(settings->IP()); fGatewayTextControl->SetText(settings->Gateway()); fNetMaskTextControl->SetText(settings->Netmask()); if (settings->NameServers().CountItems() >= 2) { fSecondaryDNSTextControl->SetText( settings->NameServers().ItemAt(1)->String()); } if (settings->NameServers().CountItems() >= 1) { fPrimaryDNSTextControl->SetText( settings->NameServers().ItemAt(0)->String()); } fDomainTextControl->SetText(settings->Domain()); _EnableTextControls(enableControls); }