diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp index c90469d228..83857bd586 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.cpp @@ -1,18 +1,33 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #include "InterfaceAddressView.h" #include "NetworkSettings.h" +#include +#include #include #include +#include +#include +#include +#include #include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "IntefaceAddressView" + + +// #pragma mark - InterfaceAddressView InterfaceAddressView::InterfaceAddressView(BRect frame, int family, @@ -27,26 +42,31 @@ InterfaceAddressView::InterfaceAddressView(BRect frame, int family, // Create our controls fModePopUpMenu = new BPopUpMenu("modes"); - fModePopUpMenu->AddItem(new BMenuItem("Automatic", + fModePopUpMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"), new BMessage(M_MODE_AUTO))); - fModePopUpMenu->AddItem(new BMenuItem("Static", + fModePopUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"), new BMessage(M_MODE_STATIC))); fModePopUpMenu->AddSeparatorItem(); - fModePopUpMenu->AddItem(new BMenuItem("None", - new BMessage(M_MODE_NONE))); + fModePopUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Off"), + new BMessage(M_MODE_OFF))); - fModeField = new BMenuField("Mode:", fModePopUpMenu); - fModeField->SetToolTip(BString("The method for obtaining an IP address")); + fModeField = new BMenuField(B_TRANSLATE("Mode:"), fModePopUpMenu); + fModeField->SetToolTip(BString(B_TRANSLATE("The method for obtaining an IP address"))); - fAddressField = new BTextControl("IP Address:", NULL, NULL); - fAddressField->SetToolTip(BString("Your internet protocol address")); - fNetmaskField = new BTextControl("Netmask:", NULL, NULL); - fNetmaskField->SetToolTip(BString("Your netmask (subnet)")); - fGatewayField = new BTextControl("Gateway:", NULL, NULL); - fGatewayField->SetToolTip(BString("Your gateway (router)")); + float minimumWidth = be_control_look->DefaultItemSpacing() * 16; - RevertFields(); - // Do the initial field population + fAddressField = new BTextControl(B_TRANSLATE("IP Address:"), NULL, NULL); + fAddressField->SetToolTip(BString(B_TRANSLATE("Your IP address"))); + fAddressField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + fNetmaskField = new BTextControl(B_TRANSLATE("Netmask:"), NULL, NULL); + fNetmaskField->SetToolTip(BString(B_TRANSLATE("Your netmask"))); + fNetmaskField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + fGatewayField = new BTextControl(B_TRANSLATE("Gateway:"), NULL, NULL); + fGatewayField->SetToolTip(BString(B_TRANSLATE("Your gateway"))); + fGatewayField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + + Revert(); + // Populate the fields BLayoutBuilder::Group<>(this) .AddGrid() @@ -67,6 +87,9 @@ InterfaceAddressView::~InterfaceAddressView() } +// #pragma mark - InterfaceAddressView virtual methods + + void InterfaceAddressView::AttachedToWindow() { @@ -80,71 +103,109 @@ InterfaceAddressView::MessageReceived(BMessage* message) switch (message->what) { case M_MODE_AUTO: _EnableFields(false); + _ShowFields(true); break; + case M_MODE_STATIC: _EnableFields(true); + _ShowFields(true); break; - case M_MODE_NONE: - _EnableFields(false); + + case M_MODE_OFF: fAddressField->SetText(""); fNetmaskField->SetText(""); fGatewayField->SetText(""); + _EnableFields(false); + _ShowFields(false); break; + default: BView::MessageReceived(message); } } +// #pragma mark - InterfaceAddressView private methods + + void -InterfaceAddressView::_EnableFields(bool enabled) +InterfaceAddressView::_EnableFields(bool enable) { - fAddressField->SetEnabled(enabled); - fNetmaskField->SetEnabled(enabled); - fGatewayField->SetEnabled(enabled); + fAddressField->SetEnabled(enable); + fNetmaskField->SetEnabled(enable); + fGatewayField->SetEnabled(enable); } +void +InterfaceAddressView::_ShowFields(bool show) +{ + if (show) { + if (fAddressField->IsHidden()) + fAddressField->Show(); + if (fNetmaskField->IsHidden()) + fNetmaskField->Show(); + if (fGatewayField->IsHidden()) + fGatewayField->Show(); + } else { + if (!fAddressField->IsHidden()) + fAddressField->Hide(); + if (!fNetmaskField->IsHidden()) + fNetmaskField->Hide(); + if (!fGatewayField->IsHidden()) + fGatewayField->Hide(); + } +} + + +// #pragma mark - InterfaceAddressView public methods + + status_t -InterfaceAddressView::RevertFields() +InterfaceAddressView::Revert() { // Populate address fields with current settings - const char* currMode = fSettings->AutoConfigure(fFamily) - ? "Automatic" : "Static"; - - _EnableFields(!fSettings->AutoConfigure(fFamily)); - // if Autoconfigured, disable address fields until changed - - if (fSettings->IPAddr(fFamily).IsEmpty() - && !fSettings->AutoConfigure(fFamily)) - { - currMode = "None"; + int32 mode; + if (fSettings->AutoConfigure(fFamily)) { + mode = M_MODE_AUTO; _EnableFields(false); + _ShowFields(true); + } else if (fSettings->IPAddr(fFamily).IsEmpty()) { + mode = M_MODE_OFF; + _EnableFields(false); + _ShowFields(false); + } else { + mode = M_MODE_STATIC; + _EnableFields(true); + _ShowFields(true); } - BMenuItem* item = fModePopUpMenu->FindItem(currMode); - if (item) + BMenuItem* item = fModePopUpMenu->FindItem(mode); + if (item != NULL) item->SetMarked(true); - fAddressField->SetText(fSettings->IP(fFamily)); - fNetmaskField->SetText(fSettings->Netmask(fFamily)); - fGatewayField->SetText(fSettings->Gateway(fFamily)); + if (!fSettings->IPAddr(fFamily).IsEmpty()) { + fAddressField->SetText(fSettings->IP(fFamily)); + fNetmaskField->SetText(fSettings->Netmask(fFamily)); + fGatewayField->SetText(fSettings->Gateway(fFamily)); + } return B_OK; } status_t -InterfaceAddressView::SaveFields() +InterfaceAddressView::Save() { + BMenuItem* item = fModePopUpMenu->FindMarked(); + if (item == NULL) + return B_ERROR; + fSettings->SetIP(fFamily, fAddressField->Text()); fSettings->SetNetmask(fFamily, fNetmaskField->Text()); fSettings->SetGateway(fFamily, fGatewayField->Text()); - - BMenuItem* item = fModePopUpMenu->FindItem("Automatic"); - fSettings->SetAutoConfigure(fFamily, item->IsMarked()); + fSettings->SetAutoConfigure(fFamily, item->Command() == M_MODE_AUTO); return B_OK; } - diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h index 5fbf274659..8d700e84c8 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceAddressView.h @@ -1,9 +1,10 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #ifndef INTERFACE_ADDRESS_VIEW_H #define INTERFACE_ADDRESS_VIEW_H @@ -11,33 +12,37 @@ #include "NetworkSettings.h" -#include -#include -#include -#include #include enum { M_MODE_AUTO = 'iato', M_MODE_STATIC = 'istc', - M_MODE_NONE = 'inon' + M_MODE_OFF = 'ioff' }; +class BMenuField; +class BMessage; +class BPopUpMenu; +class BRect; +class BTextControl; + class InterfaceAddressView : public BGroupView { public: InterfaceAddressView(BRect frame, int family, NetworkSettings* settings); virtual ~InterfaceAddressView(); - virtual void MessageReceived(BMessage* message); - virtual void AttachedToWindow(); - status_t RevertFields(); - status_t SaveFields(); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + + status_t Revert(); + status_t Save(); private: - void _EnableFields(bool enabled); + void _EnableFields(bool enable); + void _ShowFields(bool show); NetworkSettings* fSettings; int fFamily; @@ -50,5 +55,4 @@ private: }; -#endif /* INTERFACE_ADDRESS_VIEW_H */ - +#endif // INTERFACE_ADDRESS_VIEW_H diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp index 7584ebb5d6..c5d9e6453e 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp @@ -1,17 +1,33 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #include "InterfaceHardwareView.h" #include "NetworkSettings.h" +#include +#include #include +#include #include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "IntefaceHardwareView" + + +// #pragma mark - InterfaceHardwareView InterfaceHardwareView::InterfaceHardwareView(BRect frame, @@ -24,22 +40,34 @@ InterfaceHardwareView::InterfaceHardwareView(BRect frame, // TODO : Small graph of throughput? - // TODO : Use strings instead of TextControls - fStatusField = new BTextControl("Status:", NULL, NULL); - fStatusField->SetEnabled(false); - fMACField = new BTextControl("MAC Address:", NULL, NULL); - fMACField->SetEnabled(false); - fSpeedField = new BTextControl("Link Speed:", NULL, NULL); - fSpeedField->SetEnabled(false); + float minimumWidth = be_control_look->DefaultItemSpacing() * 16; - RevertFields(); - // Do the initial field population + BStringView* status = new BStringView("status label", B_TRANSLATE("Status:")); + status->SetAlignment(B_ALIGN_RIGHT); + fStatusField = new BStringView("status field", ""); + fStatusField->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + BStringView* macAddress = new BStringView("mac address label", + B_TRANSLATE("MAC address:")); + macAddress->SetAlignment(B_ALIGN_RIGHT); + fMacAddressField = new BStringView("mac address field", ""); + fMacAddressField->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + BStringView* linkSpeed = new BStringView("link speed label", + B_TRANSLATE("Link speed:")); + linkSpeed->SetAlignment(B_ALIGN_RIGHT); + fLinkSpeedField = new BStringView("link speed field", ""); + fLinkSpeedField->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + + Revert(); + // Populate the fields BLayoutBuilder::Group<>(this) .AddGrid() - .AddTextControl(fStatusField, 0, 0, B_ALIGN_RIGHT) - .AddTextControl(fMACField, 0, 1, B_ALIGN_RIGHT) - .AddTextControl(fSpeedField, 0, 2, B_ALIGN_RIGHT) + .Add(status, 0, 0) + .Add(fStatusField, 1, 0) + .Add(macAddress, 0, 1) + .Add(fMacAddressField, 1, 1) + .Add(linkSpeed, 0, 2) + .Add(fLinkSpeedField, 1, 2) .End() .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, @@ -53,6 +81,9 @@ InterfaceHardwareView::~InterfaceHardwareView() } +// #pragma mark - InterfaceHardwareView virtual methods + + void InterfaceHardwareView::AttachedToWindow() { @@ -70,26 +101,29 @@ InterfaceHardwareView::MessageReceived(BMessage* message) } +// #pragma mark - InterfaceHardwareView public methods + + status_t -InterfaceHardwareView::RevertFields() +InterfaceHardwareView::Revert() { // Populate fields with current settings if (fSettings->HasLink()) - fStatusField->SetText("connected"); + fStatusField->SetText(B_TRANSLATE("connected")); else - fStatusField->SetText("disconnected"); + fStatusField->SetText(B_TRANSLATE("disconnected")); + + fMacAddressField->SetText(fSettings->HardwareAddress()); // TODO : Find how to get link speed - fSpeedField->SetText("100 Mb/s"); + fLinkSpeedField->SetText("100 Mb/s"); return B_OK; } status_t -InterfaceHardwareView::SaveFields() +InterfaceHardwareView::Save() { - return B_OK; } - diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h index a6c3e6a6a1..7e023b754c 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h @@ -1,9 +1,10 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #ifndef INTERFACE_HARDWARE_VIEW_H #define INTERFACE_HARDWARE_VIEW_H @@ -11,35 +12,34 @@ #include "NetworkSettings.h" -#include -#include -#include -#include -#include #include +class BMessage; +class BRect; +class BStringView; + class InterfaceHardwareView : public BGroupView { public: InterfaceHardwareView(BRect frame, NetworkSettings* settings); virtual ~InterfaceHardwareView(); + virtual void MessageReceived(BMessage* message); virtual void AttachedToWindow(); - status_t RevertFields(); - status_t SaveFields(); - + status_t Revert(); + status_t Save(); private: void _EnableFields(bool enabled); NetworkSettings* fSettings; - BTextControl* fStatusField; - BTextControl* fMACField; - BTextControl* fSpeedField; + BStringView* fStatusField; + BStringView* fMacAddressField; + BStringView* fLinkSpeedField; }; -#endif /* INTERFACE_HARDWARE_VIEW_H */ +#endif // INTERFACE_HARDWARE_VIEW_H diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp index ece7e8bdee..424c8b60ae 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp @@ -1,55 +1,59 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #include "InterfaceWindow.h" #include - -#include +#include +#include +#include +#include +#include #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "NetworkSetupWindow" +#define B_TRANSLATION_CONTEXT "InterfaceWindow" InterfaceWindow::InterfaceWindow(NetworkSettings* settings) : BWindow(BRect(50, 50, 370, 350), "Interface Settings", - B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE, - B_CURRENT_WORKSPACE) + B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS, B_CURRENT_WORKSPACE) { fNetworkSettings = settings; fTabView = new BTabView("settings_tabs"); - - fApplyButton = new BButton("save", B_TRANSLATE("Save"), - new BMessage(MSG_IP_SAVE)); + fTabView->SetTabWidth(B_WIDTH_FROM_LABEL); fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(MSG_IP_REVERT)); - fTabView->SetResizingMode(B_FOLLOW_ALL); - // ensure tab container matches window size + fApplyButton = new BButton("save", B_TRANSLATE("Save"), + new BMessage(MSG_IP_SAVE)); + SetDefaultButton(fApplyButton); _PopulateTabs(); SetLayout(new BGroupLayout(B_VERTICAL)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) + AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING) .Add(fTabView) - .AddGroup(B_HORIZONTAL, 5) - .AddGlue() + .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(fRevertButton) + .AddGlue() .Add(fApplyButton) .End() - .SetInsets(10, 10, 10, 10) + .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, + B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) ); } @@ -65,21 +69,20 @@ InterfaceWindow::MessageReceived(BMessage* message) protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); switch (message->what) { + case MSG_IP_REVERT: - for (int index = 0; index < MAX_PROTOCOLS; index++) - { + for (int index = 0; index < MAX_PROTOCOLS; index++) { if (supportedFamilies[index].present) { int inet_id = supportedFamilies[index].inet_id; - fTabIPView[inet_id]->RevertFields(); + fTabIPView[inet_id]->Revert(); } } break; case MSG_IP_SAVE: - for (int index = 0; index < MAX_PROTOCOLS; index++) - { + for (int index = 0; index < MAX_PROTOCOLS; index++) { if (supportedFamilies[index].present) { int inet_id = supportedFamilies[index].inet_id; - fTabIPView[inet_id]->SaveFields(); + fTabIPView[inet_id]->Save(); } } this->Quit(); @@ -97,15 +100,15 @@ InterfaceWindow::_PopulateTabs() BRect frame = fTabView->Bounds(); protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); - BTab* hardwaretab = new BTab; + BTab* hardwareTab = new BTab; fTabHardwareView = new InterfaceHardwareView(frame, fNetworkSettings); - fTabView->AddTab(fTabHardwareView, hardwaretab); + fTabView->AddTab(fTabHardwareView, hardwareTab); if (fNetworkSettings->IsEthernet()) - hardwaretab->SetLabel("Wired"); + hardwareTab->SetLabel(B_TRANSLATE("Wired")); else - hardwaretab->SetLabel("Wirless"); + hardwareTab->SetLabel(B_TRANSLATE("Wirless")); for (int index = 0; index < MAX_PROTOCOLS; index++) { @@ -128,4 +131,3 @@ InterfaceWindow::QuitRequested() { return true; } - diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h index d0e06e16ba..ddce7e500c 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.h @@ -1,9 +1,10 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #ifndef INTERFACE_WINDOW_H #define INTERFACE_WINDOW_H @@ -13,15 +14,10 @@ #include "InterfaceAddressView.h" #include "InterfaceHardwareView.h" -#include -#include -#include -#include -#include -#include - #include +#include + enum { MSG_IP_SAVE = 'ipap', @@ -32,25 +28,30 @@ enum { typedef std::map IPViewMap; +class BButton; +class BTabView; + class InterfaceWindow : public BWindow { public: - InterfaceWindow(NetworkSettings* settings); - virtual ~InterfaceWindow(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage* mesage); + InterfaceWindow(NetworkSettings* settings); + virtual ~InterfaceWindow(); + + virtual void MessageReceived(BMessage* mesage); + virtual bool QuitRequested(); private: - status_t _PopulateTabs(); + status_t _PopulateTabs(); - NetworkSettings* fNetworkSettings; - BButton* fApplyButton; - BButton* fRevertButton; - BTabView* fTabView; + NetworkSettings* fNetworkSettings; - IPViewMap fTabIPView; - InterfaceHardwareView* fTabHardwareView; + BButton* fRevertButton; + BButton* fApplyButton; + + BTabView* fTabView; + + IPViewMap fTabIPView; + InterfaceHardwareView* fTabHardwareView; }; -#endif /* INTERFACE_WINDOW_H */ - +#endif // INTERFACE_WINDOW_H diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp index acaacd6405..df11a7d3e9 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp @@ -1,30 +1,38 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: - * Andre Alves Garzia, andre@andregarzia.com - * Stephan Assmuß + * Stephan Aßmus * Axel Dörfler + * Andre Alves Garzia, andre@andregarzia.com + * Alexander von Gluck, kallisti5@unixzen.com * Philippe Houdoin * Fredrik Modéen - * Hugo Santos * Philippe Saint-Pierre - * Alexander von Gluck, kallisti5@unixzen.com + * Hugo Santos + * John Scipione, jscipione@gmail.com */ #include "InterfacesAddOn.h" #include "InterfaceWindow.h" -#include - #include +#include +#include +#include #include #include +#include +#include #include +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "InterfacesAddOn" + + NetworkSetupAddOn* get_nth_addon(image_id image, int index) { @@ -60,42 +68,40 @@ InterfacesAddOn::Name() BView* InterfacesAddOn::CreateView(BRect *bounds) { - BRect intViewRect = *bounds; - // Construct the ListView - fListview = new InterfacesListView(intViewRect, - "interfaces", B_FOLLOW_ALL_SIDES); - fListview->SetSelectionMessage(new BMessage(kMsgInterfaceSelected)); - fListview->SetInvocationMessage(new BMessage(kMsgInterfaceConfigure)); + fListView = new InterfacesListView("interfaces"); + fListView->SetSelectionMessage(new BMessage(kMsgInterfaceSelected)); + fListView->SetInvocationMessage(new BMessage(kMsgInterfaceConfigure)); - BScrollView* scrollView = new BScrollView(NULL, fListview, - B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true); + BScrollView* scrollView = new BScrollView("scrollView", fListView, + B_WILL_DRAW | B_FRAME_EVENTS, false, true); // Construct the BButtons - fConfigure = new BButton(intViewRect, "configure", - "Configure" B_UTF8_ELLIPSIS, new BMessage(kMsgInterfaceConfigure)); + fConfigure = new BButton("configure", B_TRANSLATE("Configure" B_UTF8_ELLIPSIS), + new BMessage(kMsgInterfaceConfigure)); fConfigure->SetEnabled(false); - fOnOff = new BButton(intViewRect, "onoff", "Disable", + fOnOff = new BButton("onoff", B_TRANSLATE("Disable"), new BMessage(kMsgInterfaceToggle)); fOnOff->SetEnabled(false); - fRenegotiate = new BButton(intViewRect, "heal", - "Renegotiate", new BMessage(kMsgInterfaceRenegotiate)); + fRenegotiate = new BButton("heal", B_TRANSLATE("Renegotiate"), + new BMessage(kMsgInterfaceRenegotiate)); fRenegotiate->SetEnabled(false); // Build the layout SetLayout(new BGroupLayout(B_VERTICAL)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) + AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING) .Add(scrollView) - .AddGroup(B_HORIZONTAL, 5) + .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(fConfigure) .Add(fOnOff) .AddGlue() .Add(fRenegotiate) .End() - .SetInsets(10, 10, 10, 10) + .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, + B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) ); *bounds = Bounds(); @@ -106,7 +112,7 @@ InterfacesAddOn::CreateView(BRect *bounds) void InterfacesAddOn::AttachedToWindow() { - fListview->SetTarget(this); + fListView->SetTarget(this); fConfigure->SetTarget(this); fOnOff->SetTarget(this); fRenegotiate->SetTarget(this); @@ -117,18 +123,17 @@ status_t InterfacesAddOn::Save() { // TODO : Profile? - return fListview->SaveItems(); + return fListView->SaveItems(); } void InterfacesAddOn::MessageReceived(BMessage* msg) { - int nr = fListview->CurrentSelection(); + int nr = fListView->CurrentSelection(); InterfaceListItem *item = NULL; - if (nr != -1) { - item = dynamic_cast(fListview->ItemAt(nr)); - } + if (nr != -1) + item = dynamic_cast(fListView->ItemAt(nr)); switch (msg->what) { case kMsgInterfaceSelected: @@ -136,7 +141,7 @@ InterfacesAddOn::MessageReceived(BMessage* msg) fConfigure->SetEnabled(item != NULL); fOnOff->SetEnabled(item != NULL); fRenegotiate->SetEnabled(item != NULL); - if (!item) + if (item == NULL) break; fConfigure->SetEnabled(!item->IsDisabled()); fRenegotiate->SetEnabled(!item->IsDisabled()); @@ -146,7 +151,7 @@ InterfacesAddOn::MessageReceived(BMessage* msg) case kMsgInterfaceConfigure: { - if (!item) + if (item == NULL) break; InterfaceWindow* sw = new InterfaceWindow(item->GetSettings()); @@ -156,20 +161,20 @@ InterfacesAddOn::MessageReceived(BMessage* msg) case kMsgInterfaceToggle: { - if (!item) + if (item == NULL) break; item->SetDisabled(!item->IsDisabled()); fConfigure->SetEnabled(!item->IsDisabled()); fOnOff->SetLabel(item->IsDisabled() ? "Enable" : "Disable"); fRenegotiate->SetEnabled(!item->IsDisabled()); - fListview->Invalidate(); + fListView->Invalidate(); break; } case kMsgInterfaceRenegotiate: { - if (!item) + if (item == NULL) break; NetworkSettings* ns = item->GetSettings(); diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h index dc73ba80d8..b70635112f 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h @@ -1,20 +1,18 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: + * Alexander von Gluck, * Philippe Houdoin * Fredrik Modéen - * Alexander von Gluck, + * John Scipione, jscipione@gmail.com */ #ifndef INTERFACES_ADDON_H #define INTERFACES_ADDON_H #include -#include -#include -#include #include "NetworkSetupAddOn.h" #include "InterfacesListView.h" @@ -26,6 +24,9 @@ static const uint32 kMsgInterfaceToggle = 'onof'; static const uint32 kMsgInterfaceRenegotiate = 'redo'; +class BButton; +class BView; + class InterfacesAddOn : public NetworkSetupAddOn, public BBox { public: @@ -41,12 +42,12 @@ public: void MessageReceived(BMessage* msg); private: - InterfacesListView* fListview; + InterfacesListView* fListView; BButton* fConfigure; BButton* fOnOff; BButton* fRenegotiate; }; -#endif /*INTERFACES_ADDON_H*/ +#endif // INTERFACES_ADDON_H diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp index cf64a38342..9d94011380 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.cpp @@ -1,11 +1,12 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com * Philippe Houdoin * Fredrik Modéen - * Alexander von Gluck IV, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ @@ -19,24 +20,39 @@ #include #include #include +#include #include #include +#include +#include #include #include -#include +#include #include #include #include +#include +#include #include +#include +#include #include #include -#include "NetworkSettings.h" +#include "InterfacesAddOn.h" +#include "InterfaceWindow.h" -// #pragma mark - +#define ICON_SIZE 37 + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "InterfacesListView" + + +// #pragma mark - our_image function status_t @@ -53,7 +69,7 @@ our_image(image_info& image) } -// #pragma mark - +// #pragma mark - InterfaceListItem InterfaceListItem::InterfaceListItem(const char* name) @@ -73,22 +89,7 @@ InterfaceListItem::~InterfaceListItem() } -void -InterfaceListItem::Update(BView* owner, const BFont* font) -{ - BListItem::Update(owner, font); - font_height height; - font->GetHeight(&height); - - float lineHeight = ceilf(height.ascent) + ceilf(height.descent) - + ceilf(height.leading); - - fFirstlineOffset = 2 + ceilf(height.ascent + height.leading / 2); - fSecondlineOffset = fFirstlineOffset + lineHeight; - fThirdlineOffset = fFirstlineOffset + (lineHeight * 2); - - SetHeight(3 * lineHeight + 4); -} +// #pragma mark - InterfaceListItem public methods void @@ -96,22 +97,22 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) { BListView* list = dynamic_cast(owner); - if (!list) + if (list == NULL) return; owner->PushState(); BRect bounds = list->ItemFrame(list->IndexOf(this)); - rgb_color black = {0, 0, 0, 255}; + rgb_color highColor = list->HighColor(); + rgb_color lowColor = list->LowColor(); if (IsSelected() || complete) { if (IsSelected()) { - list->SetHighColor(tint_color(list->ViewColor(), - B_HIGHLIGHT_BACKGROUND_TINT)); - } else { - list->SetHighColor(list->LowColor()); - } + list->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR)); + list->SetLowColor(list->HighColor()); + } else + list->SetHighColor(lowColor); list->FillRect(bounds); } @@ -139,18 +140,18 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) // Set the initial bounds of item contents BPoint iconPt = bounds.LeftTop(); BPoint namePt = bounds.LeftTop(); - BPoint v4addrPt = bounds.LeftTop(); - BPoint v6addrPt = bounds.LeftTop(); + BPoint line2Pt = bounds.LeftTop(); + BPoint line3Pt = bounds.LeftTop(); BPoint statePt = bounds.RightTop(); iconPt += BPoint(4, 4); statePt += BPoint(0, fFirstlineOffset); namePt += BPoint(ICON_SIZE + 12, fFirstlineOffset); - v4addrPt += BPoint(ICON_SIZE + 12, fSecondlineOffset); - v6addrPt += BPoint(ICON_SIZE + 12, fThirdlineOffset); + line2Pt += BPoint(ICON_SIZE + 12, fSecondlineOffset); + line3Pt += BPoint(ICON_SIZE + 12, fThirdlineOffset); - statePt - -= BPoint(be_plain_font->StringWidth(interfaceState.String()), 0); + statePt -= BPoint( + be_plain_font->StringWidth(interfaceState.String()) + 4.0f, 0); if (fSettings->IsDisabled()) { list->SetDrawingMode(B_OP_ALPHA); @@ -162,46 +163,75 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) list->DrawBitmapAsync(fIcon, iconPt); list->DrawBitmapAsync(stateIcon, iconPt); - if (fSettings->IsDisabled()) - list->SetHighColor(tint_color(black, B_LIGHTEN_1_TINT)); - else - list->SetHighColor(black); + if (fSettings->IsDisabled()) { + rgb_color textColor; + if (IsSelected()) + textColor = ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR); + else + textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); + + if (textColor.red + textColor.green + textColor.blue > 128 * 3) + list->SetHighColor(tint_color(textColor, B_DARKEN_1_TINT)); + else + list->SetHighColor(tint_color(textColor, B_LIGHTEN_1_TINT)); + } else { + if (IsSelected()) + list->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); + else + list->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); + } list->SetFont(be_bold_font); list->DrawString(Name(), namePt); list->SetFont(be_plain_font); - list->DrawString(interfaceState, statePt); - + if (!fSettings->IsDisabled()) { // Render IPv4 Address - BString v4str("IPv4: "); - + BString ipv4Str(B_TRANSLATE_COMMENT("IP:", "IPv4 address label")); if (fSettings->IPAddr(AF_INET).IsEmpty()) - v4str << "none"; - else { - v4str << fSettings->IP(AF_INET); - } - - if (fSettings->AutoConfigure(AF_INET)) - v4str << " (DHCP)"; + ipv4Str << " " << B_TRANSLATE("None"); else - v4str << " (static)"; + ipv4Str << " " << BString(fSettings->IP(AF_INET)); - list->DrawString(v4str.String(), v4addrPt); + list->DrawString(ipv4Str, line2Pt); + } + + // Render IPv6 Address (if present) + if (!fSettings->IsDisabled() + && !fSettings->IPAddr(AF_INET6).IsEmpty()) { + BString ipv6Str(B_TRANSLATE_COMMENT("IPv6:", "IPv6 address label")); + ipv6Str << " " << BString(fSettings->IP(AF_INET6)); - // Render IPv6 Address (if present) - if (!fSettings->IPAddr(AF_INET6).IsEmpty()) { - BString v6str("IPv6: "); - v6str << fSettings->IP(AF_INET6); - list->DrawString(v6str, v6addrPt); - } + list->DrawString(ipv6Str, line3Pt); } owner->PopState(); } +void +InterfaceListItem::Update(BView* owner, const BFont* font) +{ + BListItem::Update(owner, font); + font_height height; + font->GetHeight(&height); + + float lineHeight = ceilf(height.ascent) + ceilf(height.descent) + + ceilf(height.leading); + + fFirstlineOffset = 2 + ceilf(height.ascent + height.leading / 2); + fSecondlineOffset = fFirstlineOffset + lineHeight; + fThirdlineOffset = fFirstlineOffset + (lineHeight * 2); + + SetHeight(max(3 * lineHeight + 4, fIcon->Bounds().Height() + 8)); + // either to the text height or icon height, whichever is taller +} + + +// #pragma mark - InterfaceListItem private methods + + void InterfaceListItem::_Init() { @@ -299,17 +329,17 @@ InterfaceListItem::_PopulateBitmaps(const char* mediaType) { 0, B_RGBA32); BIconUtils::GetVectorIcon(onlineHVIF, iconSize, fIconOnline); } - - } -// #pragma mark - +// #pragma mark - InterfaceListView -InterfacesListView::InterfacesListView(BRect rect, const char* name, uint32 resizingMode) - : BListView(rect, name, B_SINGLE_SELECTION_LIST, resizingMode) +InterfacesListView::InterfacesListView(const char* name) + : + BListView(name) { + fContextMenu = new BPopUpMenu("context menu", false, false); } @@ -318,6 +348,9 @@ InterfacesListView::~InterfacesListView() } +// #pragma mark - InterfaceListView protected methods + + void InterfacesListView::AttachedToWindow() { @@ -327,12 +360,16 @@ InterfacesListView::AttachedToWindow() start_watching_network( B_WATCH_NETWORK_INTERFACE_CHANGES | B_WATCH_NETWORK_LINK_CHANGES, this); + + Select(0); + // Select the first item in the list } void InterfacesListView::FrameResized(float width, float height) { + BListView::FrameResized(width, height); Invalidate(); } @@ -345,9 +382,9 @@ InterfacesListView::DetachedFromWindow() stop_watching_network(this); // free all items, they will be retrieved again in AttachedToWindow() - for (int32 i = CountItems(); i-- > 0;) { + for (int32 i = CountItems(); i-- > 0;) delete ItemAt(i); - } + MakeEmpty(); } @@ -366,7 +403,77 @@ InterfacesListView::MessageReceived(BMessage* message) } -InterfaceListItem * +void +InterfacesListView::MouseDown(BPoint where) +{ + int32 buttons = 0; + Window()->CurrentMessage()->FindInt32("buttons", &buttons); + + if ((B_SECONDARY_MOUSE_BUTTON & buttons) == 0) { + // If not secondary mouse button do the default + BListView::MouseDown(where); + return; + } + + InterfaceListItem* item = FindItem(where); + if (item == NULL) + return; + + // Remove all items from the menu + for (int32 i = fContextMenu->CountItems(); i >= 0; --i) { + BMenuItem* menuItem = fContextMenu->RemoveItem(i); + delete menuItem; + } + + // Now add the ones we want + if (item->GetSettings()->IsDisabled()) { + fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Enable"), + new BMessage(kMsgInterfaceToggle))); + } else { + fContextMenu->AddItem(new BMenuItem( + B_TRANSLATE("Configure" B_UTF8_ELLIPSIS), + new BMessage(kMsgInterfaceConfigure))); + if (item->GetSettings()->AutoConfigure(AF_INET) + || item->GetSettings()->AutoConfigure(AF_INET6)) { + fContextMenu->AddItem(new BMenuItem( + B_TRANSLATE("Renegotiate Address"), + new BMessage(kMsgInterfaceRenegotiate))); + } + fContextMenu->AddItem(new BSeparatorItem()); + fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Disable"), + new BMessage(kMsgInterfaceToggle))); + } + + fContextMenu->ResizeToPreferred(); + BMenuItem* selected = fContextMenu->Go(ConvertToScreen(where)); + if (selected == NULL) + return; + + switch (selected->Message()->what) { + case kMsgInterfaceConfigure: + { + InterfaceWindow* win = new InterfaceWindow(item->GetSettings()); + win->MoveTo(ConvertToScreen(where)); + win->Show(); + break; + } + + case kMsgInterfaceToggle: + item->SetDisabled(!item->IsDisabled()); + Invalidate(); + break; + + case kMsgInterfaceRenegotiate: + item->GetSettings()->RenegotiateAddresses(); + break; + } +} + + +// #pragma mark - InterfaceListView public methods + + +InterfaceListItem* InterfacesListView::FindItem(const char* name) { for (int32 i = CountItems(); i-- > 0;) { @@ -382,6 +489,22 @@ InterfacesListView::FindItem(const char* name) } +InterfaceListItem* +InterfacesListView::FindItem(BPoint where) +{ + for (int32 i = CountItems(); i-- > 0;) { + InterfaceListItem* item = dynamic_cast(ItemAt(i)); + if (item == NULL) + continue; + + if (ItemFrame(i).Contains(where)) + return item; + } + + return NULL; +} + + status_t InterfacesListView::SaveItems() { @@ -403,6 +526,9 @@ InterfacesListView::SaveItems() } +// #pragma mark - InterfaceListView private methods + + status_t InterfacesListView::_InitList() { @@ -411,9 +537,8 @@ InterfacesListView::_InitList() uint32 cookie = 0; while (roster.GetNextInterface(&cookie, interface) == B_OK) { - if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0]) { + if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0]) AddItem(new InterfaceListItem(interface.Name())); - } } return B_OK; @@ -447,29 +572,28 @@ InterfacesListView::_HandleNetworkMessage(BMessage* message) return; InterfaceListItem* item = FindItem(name); - if (!item) + if (item == NULL) printf("InterfaceListItem %s not found!\n", name); switch (opcode) { case B_NETWORK_INTERFACE_CHANGED: case B_NETWORK_DEVICE_LINK_CHANGED: - if (item) + if (item != NULL) InvalidateItem(IndexOf(item)); break; case B_NETWORK_INTERFACE_ADDED: - if (item) + if (item != NULL) InvalidateItem(IndexOf(item)); else AddItem(new InterfaceListItem(name)); break; case B_NETWORK_INTERFACE_REMOVED: - if (item) { + if (item != NULL) { RemoveItem(item); delete item; } break; } } - diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.h index 8bf8ded916..5ea4f0804c 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesListView.h @@ -1,35 +1,30 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: + * Alexander von Gluck, kallisti5@unixzen.com * Philippe Houdoin * Fredrik Modéen - * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com */ #ifndef INTERFACES_LIST_VIEW_H #define INTERFACES_LIST_VIEW_H -#include -#include -#include -#include - -#include #include #include -#include -#include -#include -#include -#include #include "NetworkSettings.h" -#define ICON_SIZE 37 - +class BBitmap; +class BMenuItem; +class BNetworkInterface; +class BPoint; +class BPopUpMenu; +class BSeparatorItem; +class BString; class InterfaceListItem : public BListItem { public: @@ -71,13 +66,11 @@ private: class InterfacesListView : public BListView { public: - InterfacesListView(BRect rect, const char* name, - uint32 resizingMode - = B_FOLLOW_LEFT | B_FOLLOW_TOP); - + InterfacesListView(const char* name); virtual ~InterfacesListView(); InterfaceListItem* FindItem(const char* name); + InterfaceListItem* FindItem(BPoint where); status_t SaveItems(); protected: @@ -86,11 +79,16 @@ protected: virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint where); private: + // Context menu + BPopUpMenu* fContextMenu; + status_t _InitList(); status_t _UpdateList(); void _HandleNetworkMessage(BMessage* message); }; -#endif /*INTERFACES_LIST_VIEW_H*/ + +#endif // INTERFACES_LIST_VIEW_H diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/Jamfile b/src/tests/kits/net/preflet/InterfacesAddOn/Jamfile index d3e28d5f68..10e61e55d9 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/Jamfile +++ b/src/tests/kits/net/preflet/InterfacesAddOn/Jamfile @@ -34,3 +34,13 @@ Addon Interfaces : $(HAIKU_LOCALE_LIBS) libicon.a libagg.a ; + +DoCatalogs Interfaces : + x-vnd.Haiku-InterfacesAddOn + : + InterfacesAddOn.cpp + InterfacesListView.cpp + InterfaceWindow.cpp + InterfaceAddressView.cpp + InterfaceHardwareView.cpp +; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp index 7b6a866e90..ce7da8d209 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp @@ -1,12 +1,13 @@ /* - * Copyright 2004-2011 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: - * Andre Alves Garzia, andre@andregarzia.com * Axel Dörfler, axeld@pinc-software.de. - * Vegard Wærp, vegarwa@online.no + * Andre Alves Garzia, andre@andregarzia.com * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com + * Vegard Wærp, vegarwa@online.no */ @@ -18,20 +19,17 @@ #include #include #include -#include -#include #include #include #include +#include #include #include #include #include #include -#include - NetworkSettings::NetworkSettings(const char* name) : @@ -353,3 +351,14 @@ NetworkSettings::RenegotiateAddresses() return B_OK; } + + +const char* +NetworkSettings::HardwareAddress() +{ + BNetworkAddress macAddress; + if (fNetworkInterface->GetHardwareAddress(macAddress) == B_OK) + return macAddress.ToString(); + + return NULL; +} diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h index 2df798993e..d2b476a332 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h @@ -1,22 +1,22 @@ /* - * Copyright 2004-2010 Haiku, Inc. All rights reserved. + * Copyright 2004-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Andre Alves Garzia, andre@andregarzia.com - * Vegard Wærp, vegarwa@online.no * Alexander von Gluck, kallisti5@unixzen.com + * John Scipione, jscipione@gmail.com + * Vegard Wærp, vegarwa@online.no */ #ifndef SETTINGS_H #define SETTINGS_H +#include + +#include #include #include -#include -#include - -#include #define MAX_PROTOCOLS 7 @@ -39,6 +39,8 @@ typedef struct _protocols { } protocols; +class BString; + class NetworkSettings { public: NetworkSettings(const char* name); @@ -48,11 +50,11 @@ public: { return fProtocols; } void SetIP(int family, const char* ip) - { fAddress[family].SetTo(ip); } + { fAddress[family].SetTo(family, ip); } void SetNetmask(int family, const char* mask) - { fNetmask[family].SetTo(mask); } + { fNetmask[family].SetTo(family, mask); } void SetGateway(int family, const char* ip) - { fGateway[family].SetTo(ip); } + { fGateway[family].SetTo(family, ip); } void SetAutoConfigure(int family, bool autoConf) { fAutoConfigure[family] = autoConf; } @@ -64,7 +66,6 @@ public: // void SetDomain(const BString& domain) // { fDomain = domain; } - bool AutoConfigure(int family) { return fAutoConfigure[family]; } BNetworkAddress IPAddr(int family) @@ -91,6 +92,8 @@ public: bool HasLink() { return fNetworkDevice->HasLink(); } + const char* HardwareAddress(); + const BString& WirelessNetwork() { return fWirelessNetwork; } BObjectList& NameServers() { return fNameServers; } @@ -128,4 +131,4 @@ private: }; -#endif /* SETTINGS_H */ +#endif // SETTINGS_H diff --git a/src/tests/kits/net/preflet/Jamfile b/src/tests/kits/net/preflet/Jamfile index 601ce31e6e..c5a5a1df5f 100644 --- a/src/tests/kits/net/preflet/Jamfile +++ b/src/tests/kits/net/preflet/Jamfile @@ -10,7 +10,7 @@ Preference NetworkSetup : ; SubInclude HAIKU_TOP src tests kits net preflet InterfacesAddOn ; -SubInclude HAIKU_TOP src tests kits net preflet ServicesAddOn ; -SubInclude HAIKU_TOP src tests kits net preflet DummyAddOn ; -SubInclude HAIKU_TOP src tests kits net preflet MultipleAddOns ; +#SubInclude HAIKU_TOP src tests kits net preflet ServicesAddOn ; +#SubInclude HAIKU_TOP src tests kits net preflet DummyAddOn ; +#SubInclude HAIKU_TOP src tests kits net preflet MultipleAddOns ; # SubInclude HAIKU_TOP src tests kits net preflet DialUpAddOn ; diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp index 70f566dc8a..3344faee31 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -50,46 +51,43 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) fPanel = new BTabView("showview_box"); - // ---- Bottom globals buttons section - BBox *bottomDivider = new BBox(B_EMPTY_STRING); - bottomDivider->SetBorder(B_PLAIN_BORDER); - fApplyButton = new BButton("apply", B_TRANSLATE("Apply"), new BMessage(kMsgApply)); + SetDefaultButton(fApplyButton); fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); // fRevertButton->SetEnabled(false); // Enable boxes resizing modes - fPanel->SetResizingMode(B_FOLLOW_ALL); + //fPanel->SetResizingMode(B_FOLLOW_ALL); // Build the layout SetLayout(new BGroupLayout(B_VERTICAL)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) - .AddGroup(B_HORIZONTAL, 5) + AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING) + .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(profilesMenuField) .AddGlue() .End() .Add(fPanel) - .Add(bottomDivider) - .AddGroup(B_HORIZONTAL, 5) - .AddGlue() + .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(fRevertButton) + .AddGlue() .Add(fApplyButton) .End() - .SetInsets(10, 10, 10, 10) + .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, + B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) ); _BuildShowTabView(kMsgAddonShow); - bottomDivider->SetExplicitMaxSize(BSize(B_SIZE_UNSET, 1)); fPanel->SetExplicitMinSize(BSize(fMinAddonViewRect.Width(), fMinAddonViewRect.Height())); fAddonView = NULL; + CenterOnScreen(); } @@ -243,7 +241,11 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what) if (!search_paths) return; - fMinAddonViewRect.Set(0, 0, 375, 225); // Minimum size + float minimumWidth = be_control_look->DefaultItemSpacing() * 37; + float minimumHight = be_control_look->DefaultItemSpacing() * 25; + + fMinAddonViewRect.Set(0, 0, minimumWidth, minimumHight); + // Minimum size search_paths = strdup(search_paths); char* next_path_token; @@ -287,37 +289,37 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what) int tabCount = 0; - if (status == B_OK) { - while ((fNetworkAddOnMap[fAddonCount] - = get_nth_addon(addon_id, tabCount)) != NULL) { - printf("Adding Tab: %d\n", fAddonCount); - BMessage* msg = new BMessage(msg_what); - - BRect r(0, 0, 0, 0); - BView* addon_view - = fNetworkAddOnMap[fAddonCount]->CreateView(&r); - fMinAddonViewRect = fMinAddonViewRect | r; - - msg->AddInt32("image_id", addon_id); - msg->AddString("addon_path", addon_path.Path()); - msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]); - msg->AddPointer("addon_view", addon_view); - - BTab *tab = new BTab; - fPanel->AddTab(addon_view, tab); - tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name()); - fAddonCount++; - // Number of tab addons total - tabCount++; - // Tabs for *this* addon - } + if (status != B_OK) { + // No "addon instantiate function" symbol found in this addon + printf("No symbol \"get_nth_addon\" found in %s addon: not a " + "network setup addon!\n", addon_path.Path()); + unload_add_on(addon_id); continue; } - // No "addon instantiate function" symbol found in this addon - printf("No symbol \"get_nth_addon\" found in %s addon: not a " - "network setup addon!\n", addon_path.Path()); - unload_add_on(addon_id); + while ((fNetworkAddOnMap[fAddonCount] + = get_nth_addon(addon_id, tabCount)) != NULL) { + printf("Adding Tab: %d\n", fAddonCount); + BMessage* msg = new BMessage(msg_what); + + BRect r(0, 0, 0, 0); + BView* addon_view + = fNetworkAddOnMap[fAddonCount]->CreateView(&r); + fMinAddonViewRect = fMinAddonViewRect | r; + + msg->AddInt32("image_id", addon_id); + msg->AddString("addon_path", addon_path.Path()); + msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]); + msg->AddPointer("addon_view", addon_view); + + BTab* tab = new BTab; + fPanel->AddTab(addon_view, tab); + tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name()); + fAddonCount++; + // Number of tab addons total + tabCount++; + // Tabs for *this* addon + } } }