added gateway textbox and new NetworkSettings function to support; made address tabview accessible by BMessage handler to reload current settings (revert); renamed Cancel button to "Revert" (it verks!); small style fix thanks to Clemens

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40511 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV 2011-02-15 16:25:37 +00:00
parent ead4d20c7a
commit 8332dfe78c
6 changed files with 47 additions and 19 deletions

View File

@ -31,20 +31,24 @@ InterfaceAddressView::InterfaceAddressView(BRect frame, const char* name,
NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fNetmaskField = new BTextControl(frame, "netmask", "Netmask:",
NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fGatewayField = new BTextControl(frame, "gateway", "Gateway:",
NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fAddressField->GetPreferredSize(&textControlW, &textControlH);
float labelSize = ( textControlW + 50 )
- fAddressField->StringWidth("XXX.XXX.XXX.XXX");
_RevertFields();
RevertFields();
// Do the initial field population
fAddressField->SetDivider(labelSize);
fNetmaskField->SetDivider(labelSize);
fGatewayField->SetDivider(labelSize);
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(fAddressField)
.Add(fNetmaskField)
.Add(fGatewayField)
.AddGlue()
.SetInsets(10, 10, 10, 10)
);
@ -58,11 +62,12 @@ InterfaceAddressView::~InterfaceAddressView()
status_t
InterfaceAddressView::_RevertFields()
InterfaceAddressView::RevertFields()
{
// Populate address fields with current settings
fAddressField->SetText(fSettings->IP(fFamily));
fNetmaskField->SetText(fSettings->Netmask(fFamily));
fNetmaskField->SetText(fSettings->Gateway(fFamily));
return B_OK;
}

View File

@ -22,9 +22,9 @@ public:
const char* name, int family,
NetworkSettings* settings);
virtual ~InterfaceAddressView();
status_t RevertFields();
private:
status_t _RevertFields();
NetworkSettings* fSettings;
int fFamily;

View File

@ -8,7 +8,6 @@
#include "InterfaceWindow.h"
#include "InterfaceAddressView.h"
#include <Application.h>
@ -17,7 +16,8 @@
InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
: BWindow(BRect(50, 50, 370, 350), "Interface Settings",
:
BWindow(BRect(50, 50, 370, 350), "Interface Settings",
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE,
B_CURRENT_WORKSPACE)
@ -29,8 +29,8 @@ InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
new BMessage(APPLY_MSG));
fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
new BMessage(CANCEL_MSG));
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
new BMessage(REVERT_MSG));
fTabView->SetResizingMode(B_FOLLOW_ALL);
// ensure tab container matches window size
@ -43,7 +43,7 @@ InterfaceWindow::InterfaceWindow(NetworkSettings* settings)
.Add(fTabView)
.AddGroup(B_HORIZONTAL, 5)
.AddGlue()
.Add(fCancelButton)
.Add(fRevertButton)
.Add(fApplyButton)
.End()
.SetInsets(10, 10, 10, 10)
@ -60,6 +60,12 @@ void
InterfaceWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case REVERT_MSG:
// RFC : we could check fTabView for Selection
// here and only revert the selected tab.
fIPv4TabView->RevertFields();
fIPv6TabView->RevertFields();
break;
default:
BWindow::MessageReceived(message);
}
@ -71,18 +77,18 @@ status_t
InterfaceWindow::_PopulateTabs()
{
BRect frame = fTabView->Bounds();
BView* view4 = new InterfaceAddressView(frame, "net_settings_ipv4",
fIPv4TabView = new InterfaceAddressView(frame, "net_settings_ipv4",
AF_INET, fNetworkSettings);
BView* view6 = new InterfaceAddressView(frame, "net_settings_ipv6",
fIPv6TabView = new InterfaceAddressView(frame, "net_settings_ipv6",
AF_INET6, fNetworkSettings);
BTab* tab4 = new BTab;
BTab* tab6 = new BTab;
fTabView->AddTab(view4, tab4);
fTabView->AddTab(fIPv4TabView, tab4);
tab4->SetLabel("IPv4");
fTabView->AddTab(view6, tab6);
fTabView->AddTab(fIPv6TabView, tab6);
tab6->SetLabel("IPv6");
return B_OK;

View File

@ -11,6 +11,7 @@
#define INTERFACE_WINDOW_H
#include "NetworkSettings.h"
#include "InterfaceAddressView.h"
#include <Button.h>
#include <Catalog.h>
@ -22,7 +23,7 @@
enum {
APPLY_MSG = 'aply',
CANCEL_MSG = 'cncl'
REVERT_MSG = 'rvrt'
};
@ -38,8 +39,11 @@ private:
NetworkSettings* fNetworkSettings;
BButton* fApplyButton;
BButton* fCancelButton;
BButton* fRevertButton;
BTabView* fTabView;
InterfaceAddressView* fIPv4TabView;
InterfaceAddressView* fIPv6TabView;
};

View File

@ -109,7 +109,7 @@ NetworkSettings::ReadConfiguration()
if ((route.flags & RTF_GATEWAY) != 0) {
sockaddr_in* inetAddress = (sockaddr_in*)route.gateway;
fGateway = inet_ntoa(inetAddress->sin_addr);
fIPv4Gateway = inet_ntoa(inetAddress->sin_addr);
}
int32 addressSize = 0;
@ -235,6 +235,16 @@ NetworkSettings::Netmask(int family)
}
const char*
NetworkSettings::Gateway(int family)
{
if (family == AF_INET6)
return fIPv6Gateway.ToString();
return fIPv4Gateway.ToString();
}
int32
NetworkSettings::PrefixLen(int family)
{

View File

@ -41,9 +41,9 @@ public:
const char* IP(int family);
const char* Netmask(int family);
const char* Gateway(int family);
int32 PrefixLen(int family);
const char* Gateway() { return fGateway.String(); }
const char* Name() { return fName.String(); }
const char* Domain() { return fDomain.String(); }
bool AutoConfigure() { return fIPv4Auto; }
@ -60,15 +60,18 @@ private:
BNetworkInterface fNetworkInterface;
// IPv4 address configuration
bool fIPv4Auto;
bool fIPv6Auto;
BNetworkAddress fIPv4Addr;
BNetworkAddress fIPv4Mask;
BNetworkAddress fIPv4Gateway;
// IPv6 address configuration
bool fIPv6Auto;
BNetworkAddress fIPv6Addr;
BNetworkAddress fIPv6Mask;
BNetworkAddress fIPv6Gateway;
BString fGateway;
BString fName;
BString fDomain;
bool fDisabled;