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
@@ -118,12 +118,13 @@ EthernetSettingsView::AttachedToWindow()
fApplyButton->SetTarget(this); fApplyButton->SetTarget(this);
fDeviceMenuField->Menu()->SetTargetForItems(this); fDeviceMenuField->Menu()->SetTargetForItems(this);
// Display first adapter by default. // display settigs of first adapter on startup
Settings* settings = fSettings.ItemAt(0);
BMessage* info = new BMessage(kMsgInfo); if (settings) {
info->AddString("interface", fSettings.ItemAt(0)->GetName()); BMessage info(kMsgInfo);
_ShowConfiguration(info); info.AddString("interface", settings->GetName());
_ShowConfiguration(&info);
}
} }
@@ -133,21 +134,19 @@ EthernetSettingsView::DetachedFromWindow()
} }
EthernetSettingsView::EthernetSettingsView(BRect rect) EthernetSettingsView::EthernetSettingsView(BRect frame)
: BView(rect, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW) : BView(frame, "EthernetSettingsView", B_FOLLOW_ALL, B_WILL_DRAW)
{ {
float defaultWidth = 190;
float inset = ceilf(be_plain_font->Size() * 0.8); 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)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fSettings.MakeEmpty();
fSocket = socket(AF_INET, SOCK_DGRAM, 0); fSocket = socket(AF_INET, SOCK_DGRAM, 0);
_GatherInterfaces(); _GatherInterfaces();
BPopUpMenu* devmenu = new BPopUpMenu("devices"); BPopUpMenu* devmenu = new BPopUpMenu("devices");
for (int32 i = 0; i < fInterfaces.CountItems(); i++) { for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
BString& name = *fInterfaces.ItemAt(i); BString& name = *fInterfaces.ItemAt(i);
BString label = name; BString label = name;
@@ -155,12 +154,8 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
info->AddString("interface", name.String()); info->AddString("interface", name.String());
BMenuItem* item = new BMenuItem(label.String(), info); BMenuItem* item = new BMenuItem(label.String(), info);
devmenu->AddItem(item); devmenu->AddItem(item);
} }
BPopUpMenu* modemenu = new BPopUpMenu("modes"); BPopUpMenu* modemenu = new BPopUpMenu("modes");
BMenuItem* staticitem = new BMenuItem("Static", NULL); BMenuItem* staticitem = new BMenuItem("Static", NULL);
modemenu->AddItem(staticitem); modemenu->AddItem(staticitem);
@@ -175,7 +170,6 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
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->SetDivider(
fTypeMenuField->StringWidth(fTypeMenuField->Label()) + 8); fTypeMenuField->StringWidth(fTypeMenuField->Label()) + 8);
@@ -233,8 +227,6 @@ EthernetSettingsView::EthernetSettingsView(BRect rect)
fApplyButton->MoveTo( fApplyButton->MoveTo(
fSecondaryDNSTextControl->Frame().LeftBottom() + BPoint(0,10)); fSecondaryDNSTextControl->Frame().LeftBottom() + BPoint(0,10));
AddChild(fApplyButton); AddChild(fApplyButton);
} }
EthernetSettingsView::~EthernetSettingsView() EthernetSettingsView::~EthernetSettingsView()
@@ -243,11 +235,8 @@ EthernetSettingsView::~EthernetSettingsView()
} }
void void
EthernetSettingsView::_ShowConfiguration(BMessage* message) EthernetSettingsView::_ShowConfiguration(const BMessage* message)
{ {
// Clear the inputs. // Clear the inputs.
fIPTextControl->SetText(""); fIPTextControl->SetText("");
fGatewayTextControl->SetText(""); fGatewayTextControl->SetText("");
@@ -260,36 +249,33 @@ EthernetSettingsView::_ShowConfiguration(BMessage* message)
if (message->FindString("interface", &name) != B_OK) if (message->FindString("interface", &name) != B_OK)
return; return;
int i; for (int32 i = 0; i < fSettings.CountItems(); i++) {
for (i=0; i<fSettings.CountItems();i++) { Settings* settings = fSettings.ItemAt(i);
if (strcmp(fSettings.ItemAt(i)->GetName(), name) == 0) { if (strcmp(settings->GetName(), name) != 0)
continue;
fDeviceMenuField->Menu()->FindItem(name)->SetMarked(true); 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) { fIPTextControl->SetText(settings->GetIP());
fGatewayTextControl->SetText(settings->GetGateway());
fNetMaskTextControl->SetText(settings->GetNetmask());
if (settings->GetAutoConfigure() == true)
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(true); fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(true);
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(false); else
} else {
fTypeMenuField->Menu()->FindItem("Static")->SetMarked(true); fTypeMenuField->Menu()->FindItem("Static")->SetMarked(true);
fTypeMenuField->Menu()->FindItem("DHCP")->SetMarked(false);
} // fTypeMenuField->Menu()->SetLabelFromMarked(true);
fTypeMenuField->Menu()->SetLabelFromMarked(true); // fDeviceMenuField->Menu()->SetLabelFromMarked(true);
fDeviceMenuField->Menu()->SetLabelFromMarked(true);
if (settings->fNameservers.CountItems() >= 2) {
if (fSettings.ItemAt(i)->fNameservers.CountItems() == 2) {
fSecondaryDNSTextControl->SetText( fSecondaryDNSTextControl->SetText(
fSettings.ItemAt(i)->fNameservers.ItemAt(1)->String()); settings->fNameservers.ItemAt(1)->String());
} }
if (fSettings.ItemAt(i)->fNameservers.CountItems() >= 1) { if (settings->fNameservers.CountItems() >= 1) {
fPrimaryDNSTextControl->SetText( fPrimaryDNSTextControl->SetText(
fSettings.ItemAt(i)->fNameservers.ItemAt(0)->String()); settings->fNameservers.ItemAt(0)->String());
}
} }
} }
} }
@@ -26,7 +26,7 @@ static const uint32 kMsgInfo = 'info';
class EthernetSettingsView : public BView { class EthernetSettingsView : public BView {
public: public:
EthernetSettingsView(BRect rect); EthernetSettingsView(BRect frame);
virtual ~EthernetSettingsView(); virtual ~EthernetSettingsView();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@@ -53,7 +53,7 @@ class EthernetSettingsView : public BView {
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(BMessage* message); void _ShowConfiguration(const BMessage* message);
void _SaveConfiguration(); void _SaveConfiguration();
void _SaveDNSConfiguration(); void _SaveDNSConfiguration();
void _SaveAdaptersConfiguration(); void _SaveAdaptersConfiguration();
-6
View File
@@ -1,7 +1,5 @@
SubDir HAIKU_TOP src preferences network ; SubDir HAIKU_TOP src preferences network ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders shared ; UsePrivateHeaders shared ;
Preference Network : Preference Network :
@@ -12,7 +10,3 @@ Preference Network :
: be root $(HAIKU_NETWORK_LIBS) : be root $(HAIKU_NETWORK_LIBS)
; ;
Package haiku-networksettings :
Network :
boot home Desktop haiku-networksettings ;