* Added the wireless network setting to the Settings class, and also read out
the initial value from the "interface" settings file. * The setting should now work as expected. * Also consider interfaces in configuring state as being automatically managed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39842 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -59,7 +59,7 @@ static const uint32 kMsgStaticMode = 'stcm';
|
||||
static const uint32 kMsgDHCPMode = 'dynm';
|
||||
static const uint32 kMsgDisabledMode = 'disa';
|
||||
static const uint32 kMsgChange = 'chng';
|
||||
static const uint32 kMsgJoinNetwork = 'join';
|
||||
static const uint32 kMsgNetwork = 'netw';
|
||||
|
||||
|
||||
static void
|
||||
@@ -92,7 +92,8 @@ MatchPattern(const char* string, const char* pattern)
|
||||
|
||||
|
||||
EthernetSettingsView::EthernetSettingsView()
|
||||
: BView("EthernetSettingsView", 0, NULL),
|
||||
:
|
||||
BView("EthernetSettingsView", 0, NULL),
|
||||
fCurrentSettings(NULL)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
@@ -205,6 +206,7 @@ EthernetSettingsView::EthernetSettingsView()
|
||||
buttonGroup->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||
|
||||
fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply));
|
||||
fApplyButton->SetEnabled(false);
|
||||
buttonGroup->GroupLayout()->AddView(fApplyButton);
|
||||
|
||||
rootLayout->AddView(controlsGroup);
|
||||
@@ -251,6 +253,7 @@ EthernetSettingsView::MessageReceived(BMessage* message)
|
||||
case kMsgStaticMode:
|
||||
case kMsgDHCPMode:
|
||||
case kMsgDisabledMode:
|
||||
case kMsgNetwork:
|
||||
_EnableTextControls(message->what == kMsgStaticMode);
|
||||
fApplyButton->SetEnabled(true);
|
||||
fRevertButton->SetEnabled(true);
|
||||
@@ -348,13 +351,15 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||
int32 count = 0;
|
||||
uint32 cookie = 0;
|
||||
while (device.GetNextNetwork(cookie, network) == B_OK) {
|
||||
BMessage* message = new BMessage(kMsgJoinNetwork);
|
||||
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++;
|
||||
@@ -367,7 +372,8 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||
} else {
|
||||
BMenuItem* item = new BMenuItem(
|
||||
B_TRANSLATE("Choose automatically"), NULL);
|
||||
item->SetMarked(true);
|
||||
if (menu->FindMarked() == NULL)
|
||||
item->SetMarked(true);
|
||||
menu->AddItem(item, 0);
|
||||
menu->AddItem(new BSeparatorItem(), 1);
|
||||
}
|
||||
@@ -377,40 +383,37 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||
bool enableControls = false;
|
||||
fTypeMenuField->SetEnabled(settings != NULL);
|
||||
|
||||
if (settings) {
|
||||
BMenuItem* item = fDeviceMenuField->Menu()->FindItem(
|
||||
settings->Name());
|
||||
if (item)
|
||||
item->SetMarked(true);
|
||||
BMenuItem* item = fDeviceMenuField->Menu()->FindItem(settings->Name());
|
||||
if (item)
|
||||
item->SetMarked(true);
|
||||
|
||||
fIPTextControl->SetText(settings->IP());
|
||||
fGatewayTextControl->SetText(settings->Gateway());
|
||||
fNetMaskTextControl->SetText(settings->Netmask());
|
||||
fIPTextControl->SetText(settings->IP());
|
||||
fGatewayTextControl->SetText(settings->Gateway());
|
||||
fNetMaskTextControl->SetText(settings->Netmask());
|
||||
|
||||
enableControls = false;
|
||||
enableControls = false;
|
||||
|
||||
if (settings->IsDisabled())
|
||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled"));
|
||||
else if (settings->AutoConfigure() == true)
|
||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP"));
|
||||
else {
|
||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static"));
|
||||
enableControls = true;
|
||||
}
|
||||
if (item)
|
||||
item->SetMarked(true);
|
||||
|
||||
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());
|
||||
if (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)
|
||||
item->SetMarked(true);
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -438,6 +441,16 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
||||
fCurrentSettings->SetNetmask(fNetMaskTextControl->Text());
|
||||
fCurrentSettings->SetGateway(fGatewayTextControl->Text());
|
||||
|
||||
if (!fNetworkMenuField->IsHidden(fNetworkMenuField)) {
|
||||
if (fNetworkMenuField->Menu()->ItemAt(0)->IsMarked()) {
|
||||
fCurrentSettings->SetWirelessNetwork(NULL);
|
||||
} else {
|
||||
BMenuItem* item = fNetworkMenuField->Menu()->FindMarked();
|
||||
if (item != NULL)
|
||||
fCurrentSettings->SetWirelessNetwork(item->Label());
|
||||
}
|
||||
}
|
||||
|
||||
fCurrentSettings->SetAutoConfigure(
|
||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
||||
B_TRANSLATE("DHCP")) == 0);
|
||||
@@ -521,7 +534,7 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||
Settings* settings = fSettings.ItemAt(i);
|
||||
|
||||
if (settings->AutoConfigure())
|
||||
if (settings->AutoConfigure() && settings->WirelessNetwork() == "")
|
||||
continue;
|
||||
|
||||
if (fp == NULL) {
|
||||
@@ -538,20 +551,18 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||
|
||||
if (settings->IsDisabled())
|
||||
fprintf(fp, "\tdisabled\ttrue\n");
|
||||
else {
|
||||
else if (!settings->AutoConfigure()) {
|
||||
fprintf(fp, "\taddress {\n");
|
||||
fprintf(fp, "\t\tfamily\tinet\n");
|
||||
fprintf(fp, "\t\taddress\t%s\n", settings->IP());
|
||||
fprintf(fp, "\t\tgateway\t%s\n", settings->Gateway());
|
||||
fprintf(fp, "\t\tmask\t%s\n", settings->Netmask());
|
||||
if (!fNetworkMenuField->IsHidden(fNetworkMenuField)
|
||||
&& !fNetworkMenuField->Menu()->ItemAt(0)->IsMarked()) {
|
||||
BMenuItem* item = fNetworkMenuField->Menu()->FindMarked();
|
||||
if (item != NULL)
|
||||
fprintf(fp, "\t\tnetwork\t%s", item->Label());
|
||||
}
|
||||
fprintf(fp, "\t}\n");
|
||||
}
|
||||
if (settings->WirelessNetwork() != "") {
|
||||
fprintf(fp, "\tnetwork\t%s\n",
|
||||
settings->WirelessNetwork().String());
|
||||
}
|
||||
fprintf(fp, "}\n\n");
|
||||
}
|
||||
if (fp) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2009 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -23,7 +23,9 @@
|
||||
#include <sys/sockio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <driver_settings.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
|
||||
@@ -32,7 +34,7 @@
|
||||
|
||||
Settings::Settings(const char* name)
|
||||
:
|
||||
fAuto(true),
|
||||
fAuto(true),
|
||||
fDisabled(false),
|
||||
fNameServers(5, true)
|
||||
{
|
||||
@@ -148,9 +150,60 @@ Settings::ReadConfiguration()
|
||||
if (ioctl(fSocket, SIOCGIFFLAGS, &request, sizeof(struct ifreq)) == 0)
|
||||
flags = request.ifr_flags;
|
||||
|
||||
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
||||
fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
||||
fDisabled = (flags & IFF_UP) == 0;
|
||||
|
||||
// Read wireless network from interfaces
|
||||
|
||||
fWirelessNetwork.SetTo(NULL);
|
||||
|
||||
BPath path;
|
||||
find_directory(B_COMMON_SETTINGS_DIRECTORY, &path);
|
||||
path.Append("network");
|
||||
path.Append("interfaces");
|
||||
|
||||
void* handle = load_driver_settings(path.Path());
|
||||
if (handle != NULL) {
|
||||
const driver_settings* settings = get_driver_settings(handle);
|
||||
if (settings != NULL) {
|
||||
for (int32 i = 0; i < settings->parameter_count; i++) {
|
||||
driver_parameter& top = settings->parameters[i];
|
||||
if (!strcmp(top.name, "interface")) {
|
||||
// The name of the interface can either be the value of
|
||||
// the "interface" parameter, or a separate "name" parameter
|
||||
const char* name = NULL;
|
||||
if (top.value_count > 0) {
|
||||
name = top.values[0];
|
||||
if (fName != name)
|
||||
continue;
|
||||
}
|
||||
|
||||
// search "network" parameter
|
||||
for (int32 j = 0; j < top.parameter_count; j++) {
|
||||
driver_parameter& sub = top.parameters[j];
|
||||
if (name == NULL && !strcmp(sub.name, "name")
|
||||
&& sub.value_count > 0) {
|
||||
name = sub.values[0];
|
||||
if (fName != sub.values[0])
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp(sub.name, "network")
|
||||
&& sub.value_count > 0) {
|
||||
fWirelessNetwork.SetTo(sub.values[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// We found our interface
|
||||
if (fName == name)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
unload_driver_settings(handle);
|
||||
}
|
||||
|
||||
// read resolv.conf for the dns.
|
||||
fNameServers.MakeEmpty();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2009 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -19,14 +19,20 @@ public:
|
||||
Settings(const char* name);
|
||||
virtual ~Settings();
|
||||
|
||||
void SetIP(BString ip) { fIP = ip; }
|
||||
void SetGateway(BString ip) { fGateway = ip; }
|
||||
void SetNetmask(BString ip) { fNetmask = ip; }
|
||||
void SetDomain(BString domain) { fDomain = domain; }
|
||||
void SetIP(const BString& ip)
|
||||
{ fIP = ip; }
|
||||
void SetGateway(const BString& ip)
|
||||
{ fGateway = ip; }
|
||||
void SetNetmask(const BString& ip)
|
||||
{ fNetmask = ip; }
|
||||
void SetDomain(const BString& domain)
|
||||
{ fDomain = domain; }
|
||||
void SetAutoConfigure(bool autoConfigure)
|
||||
{ fAuto = autoConfigure; }
|
||||
void SetDisabled(bool disabled)
|
||||
void SetDisabled(bool disabled)
|
||||
{ fDisabled = disabled; }
|
||||
void SetWirelessNetwork(const char* name)
|
||||
{ fWirelessNetwork.SetTo(name); }
|
||||
|
||||
const char* IP() { return fIP.String(); }
|
||||
const char* Gateway() { return fGateway.String(); }
|
||||
@@ -35,6 +41,7 @@ public:
|
||||
const char* Domain() { return fDomain.String(); }
|
||||
bool AutoConfigure() { return fAuto; }
|
||||
bool IsDisabled() { return fDisabled; }
|
||||
const BString& WirelessNetwork() { return fWirelessNetwork; }
|
||||
|
||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||
|
||||
@@ -52,6 +59,8 @@ private:
|
||||
bool fAuto;
|
||||
bool fDisabled;
|
||||
BObjectList<BString> fNameServers;
|
||||
BString fWirelessNetwork;
|
||||
};
|
||||
|
||||
|
||||
#endif /* SETTINGS_H */
|
||||
|
||||
Reference in New Issue
Block a user