From 763cd902f672f7912ebeddca25c2d8e848728ae7 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 19 Sep 2014 15:24:50 +0200 Subject: [PATCH] NetworkSetup: simplify UI layout * Temporarily disable the non-working Profiles popup * Remove the currently single-tabbed TabView * Remove duplicate apply and revert buttons in the interfaces add-on. The goal here is to remove functionalities not available in the current network preferences, and finish the other parts, so we can put this new preferences panel in service now. We can re-add the extra functionality later. --- .../preflet/InterfacesAddOn/InterfaceView.cpp | 68 ++++++------------- .../preflet/InterfacesAddOn/InterfaceView.h | 13 ++-- .../InterfacesAddOn/InterfacesAddOn.cpp | 25 +++++-- .../preflet/InterfacesAddOn/InterfacesAddOn.h | 4 ++ .../kits/net/preflet/NetworkSetupWindow.cpp | 18 ++--- .../kits/net/preflet/NetworkSetupWindow.h | 2 +- 6 files changed, 58 insertions(+), 72 deletions(-) diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.cpp index 63142f7b1a..b33393214c 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.cpp @@ -24,33 +24,11 @@ InterfaceView::InterfaceView(NetworkSettings* settings) : - BView("Interface Settings", 0, 0) + BTabView("settings_tabs") { fNetworkSettings = settings; - - fTabView = new BTabView("settings_tabs"); - fTabView->SetTabWidth(B_WIDTH_FROM_LABEL); - - fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), - new BMessage(MSG_IP_REVERT)); - - fApplyButton = new BButton("save", B_TRANSLATE("Save"), - new BMessage(MSG_IP_SAVE)); - + SetTabWidth(B_WIDTH_FROM_LABEL); _PopulateTabs(); - - SetLayout(new BGroupLayout(B_VERTICAL)); - - AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING) - .Add(fTabView) - .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) - .Add(fRevertButton) - .AddGlue() - .Add(fApplyButton) - .End() - .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, - B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) - ); } @@ -60,38 +38,30 @@ InterfaceView::~InterfaceView() void -InterfaceView::AttachedToWindow() +InterfaceView::Revert() { - Window()->SetDefaultButton(fApplyButton); + protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); + + for (int index = 0; index < MAX_PROTOCOLS; index++) { + if (supportedFamilies[index].present) { + int inet_id = supportedFamilies[index].inet_id; + fTabIPView[inet_id]->Revert(); + } + } } void -InterfaceView::MessageReceived(BMessage* message) +InterfaceView::Apply() { protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); - switch (message->what) { - case MSG_IP_REVERT: - for (int index = 0; index < MAX_PROTOCOLS; index++) { - if (supportedFamilies[index].present) { - int inet_id = supportedFamilies[index].inet_id; - fTabIPView[inet_id]->Revert(); - } - } - break; - case MSG_IP_SAVE: - for (int index = 0; index < MAX_PROTOCOLS; index++) { - if (supportedFamilies[index].present) { - int inet_id = supportedFamilies[index].inet_id; - fTabIPView[inet_id]->Save(); - } - } - break; - default: - BView::MessageReceived(message); + for (int index = 0; index < MAX_PROTOCOLS; index++) { + if (supportedFamilies[index].present) { + int inet_id = supportedFamilies[index].inet_id; + fTabIPView[inet_id]->Save(); + } } - } @@ -102,7 +72,7 @@ InterfaceView::_PopulateTabs() BTab* hardwareTab = new BTab; fTabHardwareView = new InterfaceHardwareView(fNetworkSettings); - fTabView->AddTab(fTabHardwareView, hardwareTab); + AddTab(fTabHardwareView, hardwareTab); hardwareTab->SetLabel(B_TRANSLATE("Interface")); for (int index = 0; index < MAX_PROTOCOLS; index++) { @@ -111,7 +81,7 @@ InterfaceView::_PopulateTabs() fTabIPView[inet_id] = new InterfaceAddressView(inet_id, fNetworkSettings); BTab* tab = new BTab; - fTabView->AddTab(fTabIPView[inet_id], tab); + AddTab(fTabIPView[inet_id], tab); tab->SetLabel(supportedFamilies[index].name); } } diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h index aec81d25d0..749f594bfd 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h @@ -16,6 +16,7 @@ #include +#include #include @@ -31,25 +32,21 @@ typedef std::map IPViewMap; class BButton; class BTabView; -class InterfaceView : public BView { +class InterfaceView : public BTabView { public: InterfaceView(NetworkSettings* settings); virtual ~InterfaceView(); - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage* mesage); virtual bool QuitRequested(); + void Apply(); + void Revert(); + private: status_t _PopulateTabs(); NetworkSettings* fNetworkSettings; - BButton* fRevertButton; - BButton* fApplyButton; - - BTabView* fTabView; - IPViewMap fTabIPView; InterfaceHardwareView* fTabHardwareView; }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp index 323eb178a9..0851c13d1b 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp @@ -50,6 +50,7 @@ InterfacesAddOn::InterfacesAddOn(image_id image) NetworkSetupAddOn(image), BBox(NULL, B_NAVIGABLE_JUMP, B_NO_BORDER) { + fSettingsView = NULL; } @@ -111,14 +112,27 @@ InterfacesAddOn::AttachedToWindow() } +// FIXME with this scheme the apply and revert button will only take effect for +// the currently shown interface. This can be confusing, it would be better to +// keep the state of all interfaces and allow reverting and saving all of them. status_t InterfacesAddOn::Save() { // TODO : Profile? + + fSettingsView->Apply(); return fListView->SaveItems(); } +status_t +InterfacesAddOn::Revert() +{ + fSettingsView->Revert(); + return B_OK; +} + + void InterfacesAddOn::MessageReceived(BMessage* msg) { @@ -139,11 +153,12 @@ InterfacesAddOn::MessageReceived(BMessage* msg) // TODO it would be better to reuse the view instead of recreating // one. - InterfaceView* sw = new InterfaceView(item->GetSettings()); - BView* old = ChildAt(1); - RemoveChild(old); - delete old; - AddChild(sw); + if (fSettingsView != NULL) { + fSettingsView->RemoveSelf(); + delete fSettingsView; + } + fSettingsView = new InterfaceView(item->GetSettings()); + AddChild(fSettingsView); break; } diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h index c36c5d0f45..46636c5ec6 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h @@ -26,6 +26,8 @@ static const uint32 kMsgInterfaceRenegotiate = 'redo'; class BButton; class BView; +class InterfaceView; + class InterfacesAddOn : public NetworkSetupAddOn, public BBox { public: @@ -34,6 +36,7 @@ public: const char* Name(); status_t Save(); + status_t Revert(); BView* CreateView(); @@ -42,6 +45,7 @@ public: private: InterfacesListView* fListView; + InterfaceView* fSettingsView; BButton* fOnOff; BButton* fRenegotiate; }; diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp index e1e5dcd1dd..156cacbe6c 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp @@ -38,6 +38,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) fAddonCount(0) { // ---- Profiles section +#if 0 BMenu *profilesPopup = new BPopUpMenu(""); _BuildProfilesMenu(profilesPopup, kMsgProfileSelected); @@ -46,10 +47,11 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) profilesMenuField->SetFont(be_bold_font); profilesMenuField->SetEnabled(false); +#endif // ---- Settings section - fPanel = new BTabView("showview_box"); + fPanel = new BGroupView(B_VERTICAL); fApplyButton = new BButton("apply", B_TRANSLATE("Apply"), new BMessage(kMsgApply)); @@ -59,17 +61,16 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) new BMessage(kMsgRevert)); // fRevertButton->SetEnabled(false); - // Enable boxes resizing modes - //fPanel->SetResizingMode(B_FOLLOW_ALL); - // Build the layout SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING) +#if 0 .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(profilesMenuField) .AddGlue() .End() +#endif .Add(fPanel) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(fRevertButton) @@ -154,8 +155,6 @@ NetworkSetupWindow::MessageReceived(BMessage* msg) break; fPanel->AddChild(fAddonView); - fAddonView->ResizeTo(fPanel->Bounds().Width(), - fPanel->Bounds().Height()); break; } @@ -301,9 +300,10 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what) 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()); + // FIXME rework this: we don't want to use a tab view here, + // instead add-ons should populate the "interfaces" list with + // interfaces, services, etc. + fPanel->AddChild(addon_view); fAddonCount++; // Number of tab addons total tabCount++; diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.h b/src/tests/kits/net/preflet/NetworkSetupWindow.h index 8c2a7655d6..4931b0e155 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.h +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.h @@ -53,7 +53,7 @@ class NetworkSetupWindow : public BWindow NetworkAddOnMap fNetworkAddOnMap; - BTabView* fPanel; + BView* fPanel; BView* fAddonView; int fAddonCount; };