* some more cleanup and refactoring in EthernetSettingsView
* added Revert button * added enabling/disabling of text controls according to Mode setting git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22239 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -53,7 +53,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "AutoDeleter.h"
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -69,8 +69,10 @@ EthernetSettingsView::_PrepareRequest(struct ifreq& request, const char* name)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::_GatherInterfaces() {
|
EthernetSettingsView::_GatherInterfaces()
|
||||||
|
{
|
||||||
// iterate over all interfaces and retrieve minimal status
|
// iterate over all interfaces and retrieve minimal status
|
||||||
|
|
||||||
ifconf config;
|
ifconf config;
|
||||||
@@ -82,33 +84,30 @@ EthernetSettingsView::_GatherInterfaces() {
|
|||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void *buffer = malloc(count * sizeof(struct ifreq));
|
void* buffer = malloc(count * sizeof(struct ifreq));
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
MemoryDeleter deleter(buffer);
|
||||||
|
|
||||||
config.ifc_len = count * sizeof(struct ifreq);
|
config.ifc_len = count * sizeof(struct ifreq);
|
||||||
config.ifc_buf = buffer;
|
config.ifc_buf = buffer;
|
||||||
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
|
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ifreq* interface = (ifreq *)buffer;
|
ifreq* interface = (ifreq*)buffer;
|
||||||
|
|
||||||
fInterfaces.MakeEmpty();
|
fInterfaces.MakeEmpty();
|
||||||
|
|
||||||
for (uint32 i = 0; i < count; i++) {
|
for (uint32 i = 0; i < count; i++) {
|
||||||
if (strncmp(interface->ifr_name, "loop", 4) && interface->ifr_name[0])
|
if (strncmp(interface->ifr_name, "loop", 4) && interface->ifr_name[0]) {
|
||||||
{
|
|
||||||
fInterfaces.AddItem(new BString(interface->ifr_name));
|
fInterfaces.AddItem(new BString(interface->ifr_name));
|
||||||
fSettings.AddItem(new Settings(interface->ifr_name));
|
fSettings.AddItem(new Settings(interface->ifr_name));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
|
||||||
+ interface->ifr_addr.sa_len);
|
+ interface->ifr_addr.sa_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,15 +115,12 @@ void
|
|||||||
EthernetSettingsView::AttachedToWindow()
|
EthernetSettingsView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
fApplyButton->SetTarget(this);
|
fApplyButton->SetTarget(this);
|
||||||
|
fRevertButton->SetTarget(this);
|
||||||
fDeviceMenuField->Menu()->SetTargetForItems(this);
|
fDeviceMenuField->Menu()->SetTargetForItems(this);
|
||||||
|
fTypeMenuField->Menu()->SetTargetForItems(this);
|
||||||
|
|
||||||
// display settigs of first adapter on startup
|
// display settigs of first adapter on startup
|
||||||
Settings* settings = fSettings.ItemAt(0);
|
_ShowConfiguration(fSettings.ItemAt(0));
|
||||||
if (settings) {
|
|
||||||
BMessage info(kMsgInfo);
|
|
||||||
info.AddString("interface", settings->GetName());
|
|
||||||
_ShowConfiguration(&info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,10 +132,15 @@ EthernetSettingsView::DetachedFromWindow()
|
|||||||
|
|
||||||
EthernetSettingsView::EthernetSettingsView(BRect frame)
|
EthernetSettingsView::EthernetSettingsView(BRect frame)
|
||||||
: BView(frame, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW)
|
: BView(frame, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW)
|
||||||
|
, fInterfaces()
|
||||||
|
, fSettings()
|
||||||
|
, fCurrentSettings(NULL)
|
||||||
{
|
{
|
||||||
float inset = ceilf(be_plain_font->Size() * 0.8);
|
float inset = ceilf(be_plain_font->Size() * 0.8);
|
||||||
frame.OffsetTo(B_ORIGIN);
|
frame.OffsetTo(inset, inset);
|
||||||
frame.InsetBy(inset, inset);
|
frame.right = StringWidth("IP Address XXX.XXX.XXX.XXX") + 50;
|
||||||
|
frame.bottom = frame.top + 15; // just a starting point
|
||||||
|
BPoint spacing(0, inset);
|
||||||
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
@@ -157,76 +158,93 @@ EthernetSettingsView::EthernetSettingsView(BRect frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BPopUpMenu* modemenu = new BPopUpMenu("modes");
|
BPopUpMenu* modemenu = new BPopUpMenu("modes");
|
||||||
BMenuItem* staticitem = new BMenuItem("Static", NULL);
|
modemenu->AddItem(new BMenuItem("Static", new BMessage(kMsgMode)));
|
||||||
modemenu->AddItem(staticitem);
|
modemenu->AddItem(new BMenuItem("DHCP", new BMessage(kMsgMode)));
|
||||||
BMenuItem* dhcpitem = new BMenuItem("DHCP", NULL);
|
|
||||||
modemenu->AddItem(dhcpitem);
|
|
||||||
//BMenuItem* offitem = new BMenuItem("Disconnected", NULL);
|
//BMenuItem* offitem = new BMenuItem("Disconnected", NULL);
|
||||||
//modemenu->AddItem(offitem);
|
//modemenu->AddItem(offitem);
|
||||||
|
|
||||||
fDeviceMenuField = new BMenuField(frame, "networkcards", "Adapter:", devmenu);
|
fDeviceMenuField = new BMenuField(frame, "networkcards", "Adapter:", devmenu);
|
||||||
fDeviceMenuField->SetDivider(
|
|
||||||
fDeviceMenuField->StringWidth(fDeviceMenuField->Label()) + 8);
|
|
||||||
AddChild(fDeviceMenuField);
|
AddChild(fDeviceMenuField);
|
||||||
fDeviceMenuField->ResizeToPreferred();
|
fDeviceMenuField->ResizeToPreferred();
|
||||||
|
|
||||||
fTypeMenuField = new BMenuField(frame, "type", "Mode:", modemenu);
|
fTypeMenuField = new BMenuField(frame, "type", "Mode:", modemenu);
|
||||||
fTypeMenuField->SetDivider(
|
fTypeMenuField->MoveTo(fDeviceMenuField->Frame().LeftBottom() + spacing);
|
||||||
fTypeMenuField->StringWidth(fTypeMenuField->Label()) + 8);
|
|
||||||
fTypeMenuField->MoveTo(fDeviceMenuField->Frame().LeftBottom() + BPoint(0,10));
|
|
||||||
AddChild(fTypeMenuField);
|
AddChild(fTypeMenuField);
|
||||||
fTypeMenuField->ResizeToPreferred();
|
fTypeMenuField->ResizeToPreferred();
|
||||||
|
|
||||||
fIPTextControl = new BTextControl(frame, "ip", "IP Address:", "", NULL,
|
fIPTextControl = new BTextControl(frame, "ip", "IP Address:", "", NULL);
|
||||||
B_FOLLOW_TOP, B_WILL_DRAW );
|
fIPTextControl->MoveTo(fTypeMenuField->Frame().LeftBottom() + spacing);
|
||||||
fIPTextControl->SetDivider(
|
|
||||||
fIPTextControl->StringWidth(fIPTextControl->Label()) + 8);
|
|
||||||
fIPTextControl->MoveTo(fTypeMenuField->Frame().LeftBottom() + BPoint(0,10));
|
|
||||||
fIPTextControl->ResizeToPreferred();
|
fIPTextControl->ResizeToPreferred();
|
||||||
AddChild(fIPTextControl);
|
AddChild(fIPTextControl);
|
||||||
|
|
||||||
fNetMaskTextControl = new BTextControl(frame, "mask", "Netmask:", "", NULL,
|
fNetMaskTextControl = new BTextControl(frame, "mask", "Netmask:", "", NULL);
|
||||||
B_FOLLOW_TOP, B_WILL_DRAW );
|
|
||||||
fNetMaskTextControl->SetDivider(
|
|
||||||
fNetMaskTextControl->StringWidth(fNetMaskTextControl->Label()) + 8);
|
|
||||||
fNetMaskTextControl->MoveTo(
|
fNetMaskTextControl->MoveTo(
|
||||||
fIPTextControl->Frame().LeftBottom() + BPoint(0,10));
|
fIPTextControl->Frame().LeftBottom() + spacing);
|
||||||
AddChild(fNetMaskTextControl);
|
AddChild(fNetMaskTextControl);
|
||||||
fNetMaskTextControl->ResizeToPreferred();
|
fNetMaskTextControl->ResizeToPreferred();
|
||||||
|
|
||||||
fGatewayTextControl = new BTextControl(frame, "gateway", "Gateway:", "",
|
fGatewayTextControl = new BTextControl(frame, "gateway", "Gateway:", "",
|
||||||
NULL, B_FOLLOW_TOP, B_WILL_DRAW );
|
NULL);
|
||||||
fGatewayTextControl->SetDivider(
|
|
||||||
fGatewayTextControl->StringWidth(fGatewayTextControl->Label()) + 8);
|
|
||||||
fGatewayTextControl->MoveTo(
|
fGatewayTextControl->MoveTo(
|
||||||
fNetMaskTextControl->Frame().LeftBottom() + BPoint(0,10));
|
fNetMaskTextControl->Frame().LeftBottom() + spacing);
|
||||||
AddChild(fGatewayTextControl);
|
AddChild(fGatewayTextControl);
|
||||||
fGatewayTextControl->ResizeToPreferred();
|
fGatewayTextControl->ResizeToPreferred();
|
||||||
|
|
||||||
fPrimaryDNSTextControl = new BTextControl(
|
fPrimaryDNSTextControl = new BTextControl(frame, "dns1", "DNS #1:", "",
|
||||||
frame, "dns1", "DNS #1:", "", NULL, B_FOLLOW_TOP, B_WILL_DRAW );
|
NULL);
|
||||||
fPrimaryDNSTextControl->SetDivider(
|
|
||||||
fPrimaryDNSTextControl->StringWidth(fPrimaryDNSTextControl->Label()) + 8);
|
|
||||||
fPrimaryDNSTextControl->MoveTo(
|
fPrimaryDNSTextControl->MoveTo(
|
||||||
fGatewayTextControl->Frame().LeftBottom() + BPoint(0,10));
|
fGatewayTextControl->Frame().LeftBottom() + spacing);
|
||||||
AddChild(fPrimaryDNSTextControl);
|
AddChild(fPrimaryDNSTextControl);
|
||||||
fPrimaryDNSTextControl->ResizeToPreferred();
|
fPrimaryDNSTextControl->ResizeToPreferred();
|
||||||
|
|
||||||
fSecondaryDNSTextControl = new BTextControl(
|
fSecondaryDNSTextControl = new BTextControl(frame, "dns2", "DNS #2:", "",
|
||||||
frame, "dns2", "DNS #2:", "", NULL, B_FOLLOW_TOP, B_WILL_DRAW );
|
NULL);
|
||||||
fSecondaryDNSTextControl->SetDivider(
|
|
||||||
fSecondaryDNSTextControl->StringWidth(
|
|
||||||
fSecondaryDNSTextControl->Label()) + 8);
|
|
||||||
fSecondaryDNSTextControl->MoveTo(
|
fSecondaryDNSTextControl->MoveTo(
|
||||||
fPrimaryDNSTextControl->Frame().LeftBottom() + BPoint(0,10));
|
fPrimaryDNSTextControl->Frame().LeftBottom() + spacing);
|
||||||
AddChild(fSecondaryDNSTextControl);
|
AddChild(fSecondaryDNSTextControl);
|
||||||
fSecondaryDNSTextControl->ResizeToPreferred();
|
fSecondaryDNSTextControl->ResizeToPreferred();
|
||||||
|
|
||||||
|
fRevertButton = new BButton(frame, "revert", "Revert",
|
||||||
|
new BMessage(kMsgRevert));
|
||||||
|
fRevertButton->ResizeToPreferred();
|
||||||
|
fRevertButton->MoveTo(
|
||||||
|
fSecondaryDNSTextControl->Frame().LeftBottom() + spacing);
|
||||||
|
AddChild(fRevertButton);
|
||||||
|
|
||||||
fApplyButton = new BButton(frame, "apply", "Apply", new BMessage(kMsgApply));
|
fApplyButton = new BButton(frame, "apply", "Apply", new BMessage(kMsgApply));
|
||||||
fApplyButton->ResizeToPreferred();
|
fApplyButton->ResizeToPreferred();
|
||||||
fApplyButton->MoveTo(
|
fApplyButton->MoveTo(
|
||||||
fSecondaryDNSTextControl->Frame().LeftBottom() + BPoint(0,10));
|
fSecondaryDNSTextControl->Frame().RightBottom() + spacing
|
||||||
|
+ BPoint(-fApplyButton->Frame().Width(), 0));
|
||||||
AddChild(fApplyButton);
|
AddChild(fApplyButton);
|
||||||
|
|
||||||
|
ResizeTo(frame.Width() + 2 * inset, fApplyButton->Frame().bottom + inset);
|
||||||
|
|
||||||
|
// take care of label alignment
|
||||||
|
float maxLabelWidth
|
||||||
|
= fDeviceMenuField->StringWidth(fDeviceMenuField->Label());
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fTypeMenuField->StringWidth(fTypeMenuField->Label()));
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fIPTextControl->StringWidth(fIPTextControl->Label()));
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fNetMaskTextControl->StringWidth(fNetMaskTextControl->Label()));
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fGatewayTextControl->StringWidth(fGatewayTextControl->Label()));
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fPrimaryDNSTextControl->StringWidth(fPrimaryDNSTextControl->Label()));
|
||||||
|
maxLabelWidth = max_c(maxLabelWidth,
|
||||||
|
fSecondaryDNSTextControl->StringWidth(
|
||||||
|
fSecondaryDNSTextControl->Label()));
|
||||||
|
|
||||||
|
fDeviceMenuField->SetDivider(maxLabelWidth + 8);
|
||||||
|
fTypeMenuField->SetDivider(maxLabelWidth + 8);
|
||||||
|
|
||||||
|
fIPTextControl->SetDivider(maxLabelWidth + 8);
|
||||||
|
fNetMaskTextControl->SetDivider(maxLabelWidth + 8);
|
||||||
|
fGatewayTextControl->SetDivider(maxLabelWidth + 8);
|
||||||
|
fPrimaryDNSTextControl->SetDivider(maxLabelWidth + 8);
|
||||||
|
fSecondaryDNSTextControl->SetDivider(maxLabelWidth + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
EthernetSettingsView::~EthernetSettingsView()
|
EthernetSettingsView::~EthernetSettingsView()
|
||||||
@@ -235,83 +253,84 @@ EthernetSettingsView::~EthernetSettingsView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::_ShowConfiguration(const BMessage* message)
|
EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||||
{
|
{
|
||||||
|
fCurrentSettings = settings;
|
||||||
|
|
||||||
// Clear the inputs.
|
// Clear the inputs.
|
||||||
fIPTextControl->SetText("");
|
fIPTextControl->SetText("");
|
||||||
fGatewayTextControl->SetText("");
|
fGatewayTextControl->SetText("");
|
||||||
fNetMaskTextControl->SetText("");
|
fNetMaskTextControl->SetText("");
|
||||||
fPrimaryDNSTextControl->SetText("");
|
fPrimaryDNSTextControl->SetText("");
|
||||||
fSecondaryDNSTextControl->SetText("");
|
fSecondaryDNSTextControl->SetText("");
|
||||||
|
|
||||||
|
|
||||||
const char* name;
|
|
||||||
if (message->FindString("interface", &name) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
Settings* settings = fSettings.ItemAt(i);
|
|
||||||
if (strcmp(settings->GetName(), name) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
fDeviceMenuField->Menu()->FindItem(name)->SetMarked(true);
|
bool enableControls = false;
|
||||||
|
fTypeMenuField->SetEnabled(settings != NULL);
|
||||||
|
|
||||||
|
if (settings) {
|
||||||
|
BMenuItem* item = fDeviceMenuField->Menu()->FindItem(
|
||||||
|
settings->GetName());
|
||||||
|
if (item)
|
||||||
|
item->SetMarked(true);
|
||||||
|
|
||||||
fIPTextControl->SetText(settings->GetIP());
|
fIPTextControl->SetText(settings->GetIP());
|
||||||
fGatewayTextControl->SetText(settings->GetGateway());
|
fGatewayTextControl->SetText(settings->GetGateway());
|
||||||
fNetMaskTextControl->SetText(settings->GetNetmask());
|
fNetMaskTextControl->SetText(settings->GetNetmask());
|
||||||
|
|
||||||
if (settings->GetAutoConfigure() == true)
|
|
||||||
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(true);
|
|
||||||
else
|
|
||||||
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(true);
|
|
||||||
|
|
||||||
// fTypeMenuField->Menu()->SetLabelFromMarked(true);
|
if (settings->GetAutoConfigure() == true)
|
||||||
// fDeviceMenuField->Menu()->SetLabelFromMarked(true);
|
item = fTypeMenuField->Menu()->FindItem("DHCP");
|
||||||
|
else
|
||||||
|
item = fTypeMenuField->Menu()->FindItem("Static");
|
||||||
|
if (item)
|
||||||
|
item->SetMarked(true);
|
||||||
|
|
||||||
|
enableControls = settings->GetAutoConfigure() == false;
|
||||||
|
|
||||||
if (settings->fNameservers.CountItems() >= 2) {
|
if (settings->fNameservers.CountItems() >= 2) {
|
||||||
fSecondaryDNSTextControl->SetText(
|
fSecondaryDNSTextControl->SetText(
|
||||||
settings->fNameservers.ItemAt(1)->String());
|
settings->fNameservers.ItemAt(1)->String());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings->fNameservers.CountItems() >= 1) {
|
if (settings->fNameservers.CountItems() >= 1) {
|
||||||
fPrimaryDNSTextControl->SetText(
|
fPrimaryDNSTextControl->SetText(
|
||||||
settings->fNameservers.ItemAt(0)->String());
|
settings->fNameservers.ItemAt(0)->String());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_EnableTextControls(enableControls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
EthernetSettingsView::_EnableTextControls(bool enable)
|
||||||
|
{
|
||||||
|
fIPTextControl->SetEnabled(enable);
|
||||||
|
fGatewayTextControl->SetEnabled(enable);
|
||||||
|
fNetMaskTextControl->SetEnabled(enable);
|
||||||
|
fPrimaryDNSTextControl->SetEnabled(enable);
|
||||||
|
fSecondaryDNSTextControl->SetEnabled(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::_ApplyControlsToConfiguration()
|
EthernetSettingsView::_ApplyControlsToConfiguration()
|
||||||
{
|
{
|
||||||
|
if (!fCurrentSettings)
|
||||||
int i;
|
return;
|
||||||
for (i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(fSettings.ItemAt(i)->
|
fCurrentSettings->SetIP(fIPTextControl->Text());
|
||||||
GetName(), fDeviceMenuField->Menu()->FindMarked()->Label()) == 0) {
|
fCurrentSettings->SetNetmask(fNetMaskTextControl->Text());
|
||||||
fSettings.ItemAt(i)->
|
fCurrentSettings->SetGateway(fGatewayTextControl->Text());
|
||||||
SetIP(fIPTextControl->Text());
|
|
||||||
fSettings.ItemAt(i)->
|
|
||||||
SetNetmask(fNetMaskTextControl->Text());
|
|
||||||
fSettings.ItemAt(i)->
|
|
||||||
SetGateway(fGatewayTextControl->Text());
|
|
||||||
if (strcmp(fTypeMenuField->Menu()->FindMarked()->Label(), "DHCP")
|
|
||||||
== 0)
|
|
||||||
fSettings.ItemAt(i)->SetAutoConfigure(true);
|
|
||||||
else
|
|
||||||
fSettings.ItemAt(i)->SetAutoConfigure(false);
|
|
||||||
|
|
||||||
|
fCurrentSettings->SetAutoConfigure(
|
||||||
fSettings.ItemAt(i)->fNameservers.MakeEmpty();
|
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(), "DHCP") == 0);
|
||||||
fSettings.ItemAt(i)->fNameservers.AddItem(new BString(
|
|
||||||
fPrimaryDNSTextControl->Text()));
|
fCurrentSettings->fNameservers.MakeEmpty();
|
||||||
fSettings.ItemAt(i)->fNameservers.AddItem(new BString(
|
fCurrentSettings->fNameservers.AddItem(new BString(
|
||||||
fSecondaryDNSTextControl->Text()));
|
fPrimaryDNSTextControl->Text()));
|
||||||
|
fCurrentSettings->fNameservers.AddItem(new BString(
|
||||||
}
|
fSecondaryDNSTextControl->Text()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -322,29 +341,29 @@ EthernetSettingsView::_SaveConfiguration()
|
|||||||
_SaveAdaptersConfiguration();
|
_SaveAdaptersConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::_SaveDNSConfiguration()
|
EthernetSettingsView::_SaveDNSConfiguration()
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp = fopen("/etc/resolv.conf", "w");
|
||||||
if ((fp = fopen("/etc/resolv.conf", "w")) != NULL) {
|
if (fp == NULL)
|
||||||
fprintf(fp, "# Generated by Network Preflet\n");
|
return;
|
||||||
int i;
|
|
||||||
for (i = 0; i < fSettings.CountItems(); i++) {
|
fprintf(fp, "# Generated by Network Preflet\n");
|
||||||
// loop all the adapters.
|
// loop over all adapters
|
||||||
int j;
|
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||||
for (j = 0; j < fSettings.ItemAt(i)->fNameservers.CountItems(); j++) {
|
Settings* settings = fSettings.ItemAt(i);
|
||||||
if (strcmp(
|
for (int j = 0; j < settings->fNameservers.CountItems(); j++) {
|
||||||
fSettings.ItemAt(i)->fNameservers.ItemAt(j)->String(), "") != 0) {
|
if (settings->fNameservers.ItemAt(j)->Length() > 0) {
|
||||||
fprintf(fp, "nameserver\t%s\n",
|
fprintf(fp, "nameserver\t%s\n",
|
||||||
fSettings.ItemAt(i)->fNameservers.ItemAt(j)->String());
|
settings->fNameservers.ItemAt(j)->String());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
}
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::_SaveAdaptersConfiguration()
|
EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||||
{
|
{
|
||||||
@@ -354,14 +373,12 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
bool allDHCP = true;
|
|
||||||
// loop over all adapters. open the settings file only once,
|
// loop over all adapters. open the settings file only once,
|
||||||
// append the settins of each non-autoconfiguring adapter
|
// append the settins of each non-autoconfiguring adapter
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||||
if (fSettings.ItemAt(i)->GetAutoConfigure())
|
if (fSettings.ItemAt(i)->GetAutoConfigure())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
allDHCP = false;
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fp = fopen(path.Path(), "w");
|
fp = fopen(path.Path(), "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
@@ -385,14 +402,13 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
|||||||
if (fp) {
|
if (fp) {
|
||||||
printf("%s saved.\n", path.Path());
|
printf("%s saved.\n", path.Path());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (allDHCP) {
|
|
||||||
// all configuration is DHCP, so delete interfaces file.
|
// all configuration is DHCP, so delete interfaces file.
|
||||||
remove(path.Path());
|
remove(path.Path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
EthernetSettingsView::_GetPath(const char* name, BPath& path)
|
EthernetSettingsView::_GetPath(const char* name, BPath& path)
|
||||||
{
|
{
|
||||||
@@ -407,12 +423,30 @@ EthernetSettingsView::_GetPath(const char* name, BPath& path)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EthernetSettingsView::MessageReceived(BMessage* message)
|
EthernetSettingsView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgInfo:
|
case kMsgMode:
|
||||||
_ShowConfiguration(message);
|
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked())
|
||||||
|
_EnableTextControls(strcmp(item->Label(), "DHCP") != 0);
|
||||||
|
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->GetName(), name) == 0) {
|
||||||
|
_ShowConfiguration(settings);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kMsgRevert:
|
||||||
|
_ShowConfiguration(fCurrentSettings);
|
||||||
break;
|
break;
|
||||||
case kMsgApply:
|
case kMsgApply:
|
||||||
_SaveConfiguration();
|
_SaveConfiguration();
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ class BMenuField;
|
|||||||
class BTextControl;
|
class BTextControl;
|
||||||
|
|
||||||
static const uint32 kMsgApply = 'aply';
|
static const uint32 kMsgApply = 'aply';
|
||||||
|
static const uint32 kMsgRevert = 'rvrt';
|
||||||
static const uint32 kMsgClose = 'clse';
|
static const uint32 kMsgClose = 'clse';
|
||||||
static const uint32 kMsgField = 'fild';
|
static const uint32 kMsgField = 'fild';
|
||||||
static const uint32 kMsgInfo = 'info';
|
static const uint32 kMsgInfo = 'info';
|
||||||
|
static const uint32 kMsgMode = 'mode';
|
||||||
|
|
||||||
class EthernetSettingsView : public BView {
|
class EthernetSettingsView : public BView {
|
||||||
public:
|
public:
|
||||||
@@ -37,8 +39,8 @@ class EthernetSettingsView : public BView {
|
|||||||
void LoadProfile(BString profileName);
|
void LoadProfile(BString profileName);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BButton* fCloseButton;
|
|
||||||
BButton* fApplyButton;
|
BButton* fApplyButton;
|
||||||
|
BButton* fRevertButton;
|
||||||
BMenuField* fDeviceMenuField;
|
BMenuField* fDeviceMenuField;
|
||||||
BMenuField* fTypeMenuField;
|
BMenuField* fTypeMenuField;
|
||||||
BTextControl* fIPTextControl;
|
BTextControl* fIPTextControl;
|
||||||
@@ -48,19 +50,19 @@ class EthernetSettingsView : public BView {
|
|||||||
BTextControl* fSecondaryDNSTextControl;
|
BTextControl* fSecondaryDNSTextControl;
|
||||||
BObjectList<BString> fInterfaces;
|
BObjectList<BString> fInterfaces;
|
||||||
BObjectList<Settings> fSettings;
|
BObjectList<Settings> fSettings;
|
||||||
|
Settings* fCurrentSettings;
|
||||||
|
|
||||||
int32 fStatus;
|
int32 fStatus;
|
||||||
int fSocket;
|
int fSocket;
|
||||||
void _GatherInterfaces();
|
void _GatherInterfaces();
|
||||||
bool _PrepareRequest(struct ifreq& request, const char* name);
|
bool _PrepareRequest(struct ifreq& request, const char* name);
|
||||||
void _ShowConfiguration(const BMessage* message);
|
void _ShowConfiguration(Settings* settings);
|
||||||
|
void _EnableTextControls(bool enable);
|
||||||
void _SaveConfiguration();
|
void _SaveConfiguration();
|
||||||
void _SaveDNSConfiguration();
|
void _SaveDNSConfiguration();
|
||||||
void _SaveAdaptersConfiguration();
|
void _SaveAdaptersConfiguration();
|
||||||
void _ApplyControlsToConfiguration();
|
void _ApplyControlsToConfiguration();
|
||||||
status_t _GetPath(const char* name, BPath& path);
|
status_t _GetPath(const char* name, BPath& path);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ETHERNET_SETTINGS_VIEW_H */
|
#endif /* ETHERNET_SETTINGS_VIEW_H */
|
||||||
|
|||||||
@@ -16,15 +16,14 @@
|
|||||||
|
|
||||||
|
|
||||||
NetworkWindow::NetworkWindow()
|
NetworkWindow::NetworkWindow()
|
||||||
: BWindow(BRect(50, 50, 269, 302), "Network",
|
: BWindow(BRect(50, 50, 269, 302), "Network", B_TITLED_WINDOW,
|
||||||
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
|
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
||||||
| B_NOT_ZOOMABLE)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
fEthView = new EthernetSettingsView(Bounds());
|
fEthView = new EthernetSettingsView(Bounds());
|
||||||
|
ResizeTo(fEthView->Frame().Width(), fEthView->Frame().Height());
|
||||||
|
|
||||||
AddChild(fEthView);
|
AddChild(fEthView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user