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.
This commit is contained in:
Adrien Destugues
2014-09-19 17:52:10 +02:00
parent 76a607d2fe
commit 763cd902f6
6 changed files with 58 additions and 72 deletions
@@ -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);
}
}
@@ -16,6 +16,7 @@
#include <map>
#include <TabView.h>
#include <Window.h>
@@ -31,25 +32,21 @@ typedef std::map<int, InterfaceAddressView*> 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;
};
@@ -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;
}
@@ -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;
};
@@ -38,6 +38,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
fAddonCount(0)
{
// ---- Profiles section
#if 0
BMenu *profilesPopup = new BPopUpMenu("<none>");
_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++;
@@ -53,7 +53,7 @@ class NetworkSetupWindow : public BWindow
NetworkAddOnMap fNetworkAddOnMap;
BTabView* fPanel;
BView* fPanel;
BView* fAddonView;
int fAddonCount;
};