NetworkSetup: put interface settings in main window

* The initial design was probably inspired by Windows network settings,
which are a mess of nested windows and hyperlinks.
* Instead, the settings can be put directly inside the main window, like
it is done inthe media preflet. This makes the information available at
a glance and makes the UI easier to navigate.
* Remove the "configure" button and popup menu item. A single click is
now enough to show the settings for an interface

For this to work properly, complete the move to layout kit (there were a
few BRect-based constructorls left which would mess the layout) and
remove unneeded rectangle computations (layout kit does the job
already).

Further cleanup pending:
* Removal of the duplicate "revert" button
* Removal of the "save" button and switch to applying settings realtime
* Move the disable/enable and renegociate buttons inside the interface
settings
* Remove the top-level tab view (nested tab views are not nice) and
use a hierarchized list with both interfaces and services on the side
(like the Media preflet has audio and video).
This commit is contained in:
Adrien Destugues
2014-09-19 14:13:01 +02:00
parent 941986f7f4
commit 126a04e6d6
16 changed files with 57 additions and 109 deletions
@@ -30,7 +30,7 @@
// #pragma mark - InterfaceAddressView
InterfaceAddressView::InterfaceAddressView(BRect frame, int family,
InterfaceAddressView::InterfaceAddressView(int family,
NetworkSettings* settings)
:
BGroupView(B_VERTICAL),
@@ -30,8 +30,8 @@ class BTextControl;
class InterfaceAddressView : public BGroupView {
public:
InterfaceAddressView(BRect frame,
int family, NetworkSettings* settings);
InterfaceAddressView(int family,
NetworkSettings* settings);
virtual ~InterfaceAddressView();
virtual void AttachedToWindow();
@@ -32,8 +32,7 @@
// #pragma mark - InterfaceHardwareView
InterfaceHardwareView::InterfaceHardwareView(BRect frame,
NetworkSettings* settings)
InterfaceHardwareView::InterfaceHardwareView(NetworkSettings* settings)
:
BGroupView(B_VERTICAL),
fSettings(settings)
@@ -21,7 +21,7 @@ class BStringView;
class InterfaceHardwareView : public BGroupView {
public:
InterfaceHardwareView(BRect frame,
InterfaceHardwareView(
NetworkSettings* settings);
virtual ~InterfaceHardwareView();
@@ -8,7 +8,7 @@
*/
#include "InterfaceWindow.h"
#include "InterfaceView.h"
#include <Application.h>
#include <Button.h>
@@ -22,12 +22,9 @@
#define B_TRANSLATION_CONTEXT "InterfaceWindow"
InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
InterfaceView::InterfaceView(NetworkSettings* settings)
:
BWindow(BRect(50, 50, 370, 350), "Interface Settings",
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)
BView("Interface Settings", 0, 0)
{
fNetworkSettings = settings;
@@ -39,7 +36,6 @@ InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
fApplyButton = new BButton("save", B_TRANSLATE("Save"),
new BMessage(MSG_IP_SAVE));
SetDefaultButton(fApplyButton);
_PopulateTabs();
@@ -58,18 +54,24 @@ InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
}
InterfaceWindow::~InterfaceWindow()
InterfaceView::~InterfaceView()
{
}
void
InterfaceWindow::MessageReceived(BMessage* message)
InterfaceView::AttachedToWindow()
{
Window()->SetDefaultButton(fApplyButton);
}
void
InterfaceView::MessageReceived(BMessage* message)
{
protocols* supportedFamilies = fNetworkSettings->ProtocolVersions();
switch (message->what) {
case MSG_IP_REVERT:
for (int index = 0; index < MAX_PROTOCOLS; index++) {
if (supportedFamilies[index].present) {
@@ -85,32 +87,29 @@ InterfaceWindow::MessageReceived(BMessage* message)
fTabIPView[inet_id]->Save();
}
}
this->Quit();
break;
default:
BWindow::MessageReceived(message);
BView::MessageReceived(message);
}
}
status_t
InterfaceWindow::_PopulateTabs()
InterfaceView::_PopulateTabs()
{
BRect frame = fTabView->Bounds();
protocols* supportedFamilies = fNetworkSettings->ProtocolVersions();
BTab* hardwareTab = new BTab;
fTabHardwareView = new InterfaceHardwareView(frame,
fNetworkSettings);
fTabHardwareView = new InterfaceHardwareView(fNetworkSettings);
fTabView->AddTab(fTabHardwareView, hardwareTab);
hardwareTab->SetLabel(B_TRANSLATE("Interface"));
for (int index = 0; index < MAX_PROTOCOLS; index++) {
if (supportedFamilies[index].present) {
int inet_id = supportedFamilies[index].inet_id;
fTabIPView[inet_id] = new InterfaceAddressView(frame,
inet_id, fNetworkSettings);
fTabIPView[inet_id] = new InterfaceAddressView(inet_id,
fNetworkSettings);
BTab* tab = new BTab;
fTabView->AddTab(fTabIPView[inet_id], tab);
tab->SetLabel(supportedFamilies[index].name);
@@ -122,7 +121,7 @@ InterfaceWindow::_PopulateTabs()
bool
InterfaceWindow::QuitRequested()
InterfaceView::QuitRequested()
{
return true;
}
@@ -31,11 +31,12 @@ typedef std::map<int, InterfaceAddressView*> IPViewMap;
class BButton;
class BTabView;
class InterfaceWindow : public BWindow {
class InterfaceView : public BView {
public:
InterfaceWindow(NetworkSettings* settings);
virtual ~InterfaceWindow();
InterfaceView(NetworkSettings* settings);
virtual ~InterfaceView();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* mesage);
virtual bool QuitRequested();
@@ -16,7 +16,7 @@
#include "InterfacesAddOn.h"
#include "InterfaceWindow.h"
#include "InterfaceView.h"
#include <Alert.h>
#include <Button.h>
@@ -48,7 +48,7 @@ get_nth_addon(image_id image, int index)
InterfacesAddOn::InterfacesAddOn(image_id image)
:
NetworkSetupAddOn(image),
BBox(BRect(0, 0, 0, 0), NULL, B_FOLLOW_ALL, B_NAVIGABLE_JUMP, B_NO_BORDER)
BBox(NULL, B_NAVIGABLE_JUMP, B_NO_BORDER)
{
}
@@ -66,21 +66,16 @@ InterfacesAddOn::Name()
BView*
InterfacesAddOn::CreateView(BRect *bounds)
InterfacesAddOn::CreateView()
{
// Construct the ListView
fListView = new InterfacesListView("interfaces");
fListView->SetSelectionMessage(new BMessage(kMsgInterfaceSelected));
fListView->SetInvocationMessage(new BMessage(kMsgInterfaceConfigure));
BScrollView* scrollView = new BScrollView("scrollView", fListView,
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
// Construct the BButtons
fConfigure = new BButton("configure", B_TRANSLATE("Configure" B_UTF8_ELLIPSIS),
new BMessage(kMsgInterfaceConfigure));
fConfigure->SetEnabled(false);
fOnOff = new BButton("onoff", B_TRANSLATE("Disable"),
new BMessage(kMsgInterfaceToggle));
fOnOff->SetEnabled(false);
@@ -90,12 +85,11 @@ InterfacesAddOn::CreateView(BRect *bounds)
fRenegotiate->SetEnabled(false);
// Build the layout
SetLayout(new BGroupLayout(B_VERTICAL));
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
.Add(scrollView)
.AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
.Add(fConfigure)
.Add(fOnOff)
.AddGlue()
.Add(fRenegotiate)
@@ -104,7 +98,6 @@ InterfacesAddOn::CreateView(BRect *bounds)
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
);
*bounds = Bounds();
return this;
}
@@ -113,7 +106,6 @@ void
InterfacesAddOn::AttachedToWindow()
{
fListView->SetTarget(this);
fConfigure->SetTarget(this);
fOnOff->SetTarget(this);
fRenegotiate->SetTarget(this);
}
@@ -138,24 +130,20 @@ InterfacesAddOn::MessageReceived(BMessage* msg)
switch (msg->what) {
case kMsgInterfaceSelected:
{
fConfigure->SetEnabled(item != NULL);
fOnOff->SetEnabled(item != NULL);
fRenegotiate->SetEnabled(item != NULL);
if (item == NULL)
break;
fConfigure->SetEnabled(!item->IsDisabled());
fRenegotiate->SetEnabled(!item->IsDisabled());
fOnOff->SetLabel(item->IsDisabled() ? "Enable" : "Disable");
break;
}
case kMsgInterfaceConfigure:
{
if (item == NULL)
break;
InterfaceWindow* sw = new InterfaceWindow(item->GetSettings());
sw->Show();
// 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);
break;
}
@@ -165,7 +153,6 @@ InterfacesAddOn::MessageReceived(BMessage* msg)
break;
item->SetDisabled(!item->IsDisabled());
fConfigure->SetEnabled(!item->IsDisabled());
fOnOff->SetLabel(item->IsDisabled() ? "Enable" : "Disable");
fRenegotiate->SetEnabled(!item->IsDisabled());
fListView->Invalidate();
@@ -19,7 +19,6 @@
static const uint32 kMsgInterfaceSelected = 'ifce';
static const uint32 kMsgInterfaceConfigure = 'ifcf';
static const uint32 kMsgInterfaceToggle = 'onof';
static const uint32 kMsgInterfaceRenegotiate = 'redo';
@@ -36,14 +35,13 @@ public:
const char* Name();
status_t Save();
BView* CreateView(BRect *bounds);
BView* CreateView();
void AttachedToWindow();
void MessageReceived(BMessage* msg);
private:
InterfacesListView* fListView;
BButton* fConfigure;
BButton* fOnOff;
BButton* fRenegotiate;
};
@@ -42,7 +42,7 @@
#include <AutoDeleter.h>
#include "InterfacesAddOn.h"
#include "InterfaceWindow.h"
#include "InterfaceView.h"
#define ICON_SIZE 37
@@ -121,19 +121,19 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
BBitmap* stateIcon(NULL);
if (fSettings->IsDisabled()) {
interfaceState << "disabled";
interfaceState = "disabled";
stateIcon = fIconOffline;
} else if (!fInterface.HasLink()) {
interfaceState << "no link";
interfaceState = "no link";
stateIcon = fIconOffline;
} else if ((fSettings->IPAddr(AF_INET).IsEmpty()
&& fSettings->IPAddr(AF_INET6).IsEmpty())
&& (fSettings->AutoConfigure(AF_INET)
|| fSettings->AutoConfigure(AF_INET6))) {
interfaceState << "connecting" B_UTF8_ELLIPSIS;
interfaceState = "connecting" B_UTF8_ELLIPSIS;
stateIcon = fIconPending;
} else {
interfaceState << "connected";
interfaceState = "connected";
stateIcon = fIconOnline;
}
@@ -185,7 +185,7 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
list->DrawString(Name(), namePt);
list->SetFont(be_plain_font);
list->DrawString(interfaceState, statePt);
if (!fSettings->IsDisabled()) {
// Render IPv4 Address
BString ipv4Str(B_TRANSLATE_COMMENT("IP:", "IPv4 address label"));
@@ -196,7 +196,7 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
list->DrawString(ipv4Str, line2Pt);
}
// Render IPv6 Address (if present)
if (!fSettings->IsDisabled()
&& !fSettings->IPAddr(AF_INET6).IsEmpty()) {
@@ -337,7 +337,8 @@ InterfaceListItem::_PopulateBitmaps(const char* mediaType) {
InterfacesListView::InterfacesListView(const char* name)
:
BListView(name)
BListView(name, B_SINGLE_SELECTION_LIST,
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{
fContextMenu = new BPopUpMenu("context menu", false, false);
}
@@ -366,14 +367,6 @@ InterfacesListView::AttachedToWindow()
}
void
InterfacesListView::FrameResized(float width, float height)
{
BListView::FrameResized(width, height);
Invalidate();
}
void
InterfacesListView::DetachedFromWindow()
{
@@ -430,9 +423,6 @@ InterfacesListView::MouseDown(BPoint where)
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(
@@ -450,14 +440,6 @@ InterfacesListView::MouseDown(BPoint where)
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();
@@ -541,6 +523,10 @@ InterfacesListView::_InitList()
AddItem(new InterfaceListItem(interface.Name()));
}
// FIXME compute this according to the actual size of the largest item
// instead.
SetExplicitMinSize(BSize(10 + B_LARGE_ICON
+ StringWidth("/dev/net/MMMMMMMMMMM xxxxxxxxxx"), B_SIZE_UNSET));
return B_OK;
}
@@ -76,7 +76,6 @@ public:
protected:
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where);
@@ -17,7 +17,7 @@ Addon Interfaces :
InterfacesAddOn.cpp
InterfacesListView.cpp
NetworkSettings.cpp
InterfaceWindow.cpp
InterfaceView.cpp
InterfaceAddressView.cpp
InterfaceHardwareView.cpp
@@ -40,7 +40,7 @@ DoCatalogs Interfaces :
:
InterfacesAddOn.cpp
InterfacesListView.cpp
InterfaceWindow.cpp
InterfaceView.cpp
InterfaceAddressView.cpp
InterfaceHardwareView.cpp
;
+1 -1
View File
@@ -13,4 +13,4 @@ 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 DialUpAddOn ;
#SubInclude HAIKU_TOP src tests kits net preflet DialUpAddOn ;
@@ -30,15 +30,6 @@ NetworkSetupAddOn::~NetworkSetupAddOn()
}
BView*
NetworkSetupAddOn::CreateView(BRect* bounds)
{
BView *v = new BView(*bounds, "a view", B_FOLLOW_ALL, B_WILL_DRAW);
v->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
return v;
}
status_t
NetworkSetupAddOn::Save()
{
@@ -19,7 +19,7 @@ class NetworkSetupAddOn {
NetworkSetupAddOn(image_id addon_image);
virtual ~NetworkSetupAddOn();
virtual BView * CreateView(BRect* bounds);
virtual BView * CreateView() = 0;
virtual status_t Save();
virtual status_t Revert();
@@ -82,9 +82,6 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
_BuildShowTabView(kMsgAddonShow);
fPanel->SetExplicitMinSize(BSize(fMinAddonViewRect.Width(),
fMinAddonViewRect.Height()));
fAddonView = NULL;
CenterOnScreen();
@@ -241,12 +238,6 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what)
if (!search_paths)
return;
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;
char* search_path = strtok_r(search_paths, ":", &next_path_token);
@@ -302,10 +293,8 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what)
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;
= fNetworkAddOnMap[fAddonCount]->CreateView();
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
@@ -56,7 +56,6 @@ class NetworkSetupWindow : public BWindow
BTabView* fPanel;
BView* fAddonView;
int fAddonCount;
BRect fMinAddonViewRect;
};