a bit of cleanup

* Network can only be built for Haiku, so no package and no BeOS compatible
  declaration in Jamfile
* some style cleanup in EthernetSettingsView
* fixed EthernetSettingsView::AttachedToWindow(): fixed leaking of the
  initial message, fixed potential crashing bug when no device was present
  on the system


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22238 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-09-17 14:05:06 +00:00
parent 3be5951a14
commit 5406d829a8
3 changed files with 39 additions and 59 deletions

View File

@ -118,12 +118,13 @@ EthernetSettingsView::AttachedToWindow()
fApplyButton->SetTarget(this);
fDeviceMenuField->Menu()->SetTargetForItems(this);
// Display first adapter by default.
BMessage* info = new BMessage(kMsgInfo);
info->AddString("interface", fSettings.ItemAt(0)->GetName());
_ShowConfiguration(info);
// display settigs of first adapter on startup
Settings* settings = fSettings.ItemAt(0);
if (settings) {
BMessage info(kMsgInfo);
info.AddString("interface", settings->GetName());
_ShowConfiguration(&info);
}
}
@ -133,21 +134,19 @@ EthernetSettingsView::DetachedFromWindow()
}
EthernetSettingsView::EthernetSettingsView(BRect rect)
: BView(rect, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW)
EthernetSettingsView::EthernetSettingsView(BRect frame)
: BView(frame, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW)
{
float defaultWidth = 190;
float inset = ceilf(be_plain_font->Size() * 0.8);
BRect frame(inset,inset, defaultWidth, 50);
frame.OffsetTo(B_ORIGIN);
frame.InsetBy(inset, inset);
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fSettings.MakeEmpty();
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
_GatherInterfaces();
BPopUpMenu* devmenu = new BPopUpMenu("devices");
BPopUpMenu* devmenu = new BPopUpMenu("devices");
for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
BString& name = *fInterfaces.ItemAt(i);
BString label = name;
@ -155,12 +154,8 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
info->AddString("interface", name.String());
BMenuItem* item = new BMenuItem(label.String(), info);
devmenu->AddItem(item);
}
BPopUpMenu* modemenu = new BPopUpMenu("modes");
BMenuItem* staticitem = new BMenuItem("Static", NULL);
modemenu->AddItem(staticitem);
@ -174,7 +169,6 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
fDeviceMenuField->StringWidth(fDeviceMenuField->Label()) + 8);
AddChild(fDeviceMenuField);
fDeviceMenuField->ResizeToPreferred();
fTypeMenuField = new BMenuField(frame, "type", "Mode:", modemenu);
fTypeMenuField->SetDivider(
@ -233,8 +227,6 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
fApplyButton->MoveTo(
fSecondaryDNSTextControl->Frame().LeftBottom() + BPoint(0,10));
AddChild(fApplyButton);
}
EthernetSettingsView::~EthernetSettingsView()
@ -243,11 +235,8 @@ EthernetSettingsView::~EthernetSettingsView()
}
void
EthernetSettingsView::_ShowConfiguration(BMessage* message)
EthernetSettingsView::_ShowConfiguration(const BMessage* message)
{
// Clear the inputs.
fIPTextControl->SetText("");
fGatewayTextControl->SetText("");
@ -260,37 +249,34 @@ EthernetSettingsView::_ShowConfiguration(BMessage* message)
if (message->FindString("interface", &name) != B_OK)
return;
int i;
for (i=0; i<fSettings.CountItems();i++) {
if (strcmp(fSettings.ItemAt(i)->GetName(), name) == 0) {
fDeviceMenuField->Menu()->FindItem(name)->SetMarked(true);
fIPTextControl->SetText(fSettings.ItemAt(i)->GetIP());
fGatewayTextControl->SetText(fSettings.ItemAt(i)->GetGateway());
fNetMaskTextControl->SetText(fSettings.ItemAt(i)->GetNetmask());
if (fSettings.ItemAt(i)->GetAutoConfigure() == true) {
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(true);
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(false);
for (int32 i = 0; i < fSettings.CountItems(); i++) {
Settings* settings = fSettings.ItemAt(i);
if (strcmp(settings->GetName(), name) != 0)
continue;
} else {
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(true);
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(false);
fDeviceMenuField->Menu()->FindItem(name)->SetMarked(true);
}
fTypeMenuField->Menu()->SetLabelFromMarked(true);
fDeviceMenuField->Menu()->SetLabelFromMarked(true);
fIPTextControl->SetText(settings->GetIP());
fGatewayTextControl->SetText(settings->GetGateway());
fNetMaskTextControl->SetText(settings->GetNetmask());
if (settings->GetAutoConfigure() == true)
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(true);
else
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(true);
if (fSettings.ItemAt(i)->fNameservers.CountItems() == 2) {
fSecondaryDNSTextControl->SetText(
fSettings.ItemAt(i)->fNameservers.ItemAt(1)->String());
}
if (fSettings.ItemAt(i)->fNameservers.CountItems() >= 1) {
fPrimaryDNSTextControl->SetText(
fSettings.ItemAt(i)->fNameservers.ItemAt(0)->String());
}
// fTypeMenuField->Menu()->SetLabelFromMarked(true);
// fDeviceMenuField->Menu()->SetLabelFromMarked(true);
if (settings->fNameservers.CountItems() >= 2) {
fSecondaryDNSTextControl->SetText(
settings->fNameservers.ItemAt(1)->String());
}
if (settings->fNameservers.CountItems() >= 1) {
fPrimaryDNSTextControl->SetText(
settings->fNameservers.ItemAt(0)->String());
}
}
}

View File

@ -26,7 +26,7 @@ static const uint32 kMsgInfo = 'info';
class EthernetSettingsView : public BView {
public:
EthernetSettingsView(BRect rect);
EthernetSettingsView(BRect frame);
virtual ~EthernetSettingsView();
virtual void MessageReceived(BMessage* message);
@ -53,7 +53,7 @@ class EthernetSettingsView : public BView {
int fSocket;
void _GatherInterfaces();
bool _PrepareRequest(struct ifreq& request, const char* name);
void _ShowConfiguration(BMessage* message);
void _ShowConfiguration(const BMessage* message);
void _SaveConfiguration();
void _SaveDNSConfiguration();
void _SaveAdaptersConfiguration();

View File

@ -1,7 +1,5 @@
SubDir HAIKU_TOP src preferences network ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders shared ;
Preference Network :
@ -12,7 +10,3 @@ Preference Network :
: be root $(HAIKU_NETWORK_LIBS)
;
Package haiku-networksettings :
Network :
boot home Desktop haiku-networksettings ;