Network: added IPAddressControl.

* Based on Adrien's previous work in the DNS settings view.
* The IPv* and DNS add-ons are now using it.
This commit is contained in:
Axel Dörfler
2015-03-27 13:25:18 +01:00
parent 06cdb6558f
commit d0b107f311
9 changed files with 148 additions and 22 deletions
@@ -26,14 +26,14 @@
#include <Path.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextControl.h>
#include "IPAddressControl.h"
static const int32 kMsgAddServer = 'adds';
static const int32 kMsgDeleteServer = 'dels';
static const int32 kMsgMoveUp = 'mvup';
static const int32 kMsgMoveDown = 'mvdn';
static const int32 kMsgEditServer = 'edit';
static const int32 kMsgApply = 'aply';
@@ -46,8 +46,7 @@ DNSSettingsView::DNSSettingsView()
BView("dns", 0)
{
fServerListView = new BListView("nameservers");
fTextControl = new BTextControl("", "", NULL);
fTextControl->SetModificationMessage(new BMessage(kMsgEditServer));
fTextControl = new IPAddressControl(AF_UNSPEC, "server", "");
fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 18,
B_SIZE_UNSET));
@@ -158,14 +157,6 @@ DNSSettingsView::MessageReceived(BMessage* message)
fServerListView->SwapItems(index, index + 1);
break;
}
case kMsgEditServer:
{
struct in_addr dummy;
bool success = inet_aton(fTextControl->Text(), &dummy);
fTextControl->MarkAsInvalid(!success);
fAddButton->SetEnabled(success);
break;
}
case kMsgApply:
_SaveDNSConfiguration();
break;
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings dnsclient ;
UsePublicHeaders [ FDirName add-ons network_settings ] ;
UsePrivateHeaders app libroot kernel net ;
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
Addon DNSClientService :
DNSClientServiceAddOn.cpp
@@ -24,6 +24,8 @@
#include <StringView.h>
#include <TextControl.h>
#include "IPAddressControl.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "IntefaceAddressView"
@@ -74,15 +76,23 @@ InterfaceAddressView::InterfaceAddressView(int family,
float minimumWidth = be_control_look->DefaultItemSpacing() * 16;
fAddressField = new BTextControl(B_TRANSLATE("IP Address:"), NULL, NULL);
fAddressField = new IPAddressControl(fFamily, B_TRANSLATE("IP Address:"),
NULL);
fAddressField->SetToolTip(B_TRANSLATE("Your IP address"));
fAddressField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
fNetmaskField = new BTextControl(B_TRANSLATE("Netmask:"), NULL, NULL);
fNetmaskField->SetToolTip(B_TRANSLATE("The netmask defines your local network"));
fNetmaskField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
fGatewayField = new BTextControl(B_TRANSLATE("Gateway:"), NULL, NULL);
fAddressField->TextView()->SetExplicitMinSize(
BSize(minimumWidth, B_SIZE_UNSET));
fAddressField->SetAllowEmpty(false);
fNetmaskField = new IPAddressControl(fFamily, B_TRANSLATE("Netmask:"),
NULL);
fNetmaskField->SetToolTip(B_TRANSLATE(
"The netmask defines your local network"));
fNetmaskField->TextView()->SetExplicitMinSize(
BSize(minimumWidth, B_SIZE_UNSET));
fGatewayField = new IPAddressControl(fFamily, B_TRANSLATE("Gateway:"),
NULL);
fGatewayField->SetToolTip(B_TRANSLATE("Your gateway to the internet"));
fGatewayField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
fGatewayField->TextView()->SetExplicitMinSize(
BSize(minimumWidth, B_SIZE_UNSET));
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
new BMessage(kMsgApply));
@@ -22,6 +22,7 @@ class BMessage;
class BPopUpMenu;
class BRect;
class BTextControl;
class IPAddressControl;
using namespace BNetworkKit;
@@ -65,9 +66,9 @@ private:
BPopUpMenu* fModePopUpMenu;
BMenuField* fModeField;
BTextControl* fAddressField;
BTextControl* fNetmaskField;
BTextControl* fGatewayField;
IPAddressControl* fAddressField;
IPAddressControl* fNetmaskField;
IPAddressControl* fGatewayField;
BButton* fApplyButton;
};
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings ipv4 ;
UsePublicHeaders [ FDirName add-ons network_settings ] ;
UsePrivateHeaders shared ;
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
Addon IPv4Interface :
IPv4InterfaceAddOn.cpp
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings ipv6 ;
UsePublicHeaders [ FDirName add-ons network_settings ] ;
UsePrivateHeaders shared ;
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons network_settings ipv4 ] ;
@@ -0,0 +1,84 @@
/*
* Copyright 2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, <[email protected]>
*/
#include "IPAddressControl.h"
#include <NetworkAddress.h>
static const uint32 kMsgModified = 'txmd';
IPAddressControl::IPAddressControl(int family, const char* label,
const char* name)
:
BTextControl(name, label, "", NULL),
fFamily(family),
fAllowEmpty(true)
{
SetModificationMessage(new BMessage(kMsgModified));
}
IPAddressControl::~IPAddressControl()
{
}
bool
IPAddressControl::AllowEmpty() const
{
return fAllowEmpty;
}
void
IPAddressControl::SetAllowEmpty(bool empty)
{
fAllowEmpty = empty;
}
void
IPAddressControl::AttachedToWindow()
{
BTextControl::AttachedToWindow();
SetTarget(this);
_UpdateMark();
}
void
IPAddressControl::MessageReceived(BMessage* message)
{
switch (message->what) {
case kMsgModified:
_UpdateMark();
break;
default:
BTextControl::MessageReceived(message);
break;
}
}
void
IPAddressControl::_UpdateMark()
{
if (TextLength() == 0) {
MarkAsInvalid(!fAllowEmpty);
return;
}
BNetworkAddress address;
bool success = address.SetTo(fFamily, Text()) == B_OK;
MarkAsInvalid(!success);
}
@@ -0,0 +1,36 @@
/*
* Copyright 2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, <[email protected]>
*/
#ifndef IP_ADDRESS_CONTROL_H
#define IP_ADDRESS_CONTROL_H
#include <TextControl.h>
class IPAddressControl : public BTextControl {
public:
IPAddressControl(int family, const char* label,
const char* name);
virtual ~IPAddressControl();
bool AllowEmpty() const;
void SetAllowEmpty(bool empty);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
private:
void _UpdateMark();
private:
int fFamily;
bool fAllowEmpty;
};
#endif // IP_ADDRESS_CONTROL_H
+1
View File
@@ -13,6 +13,7 @@ Preference Network :
NetworkSettingsAddOn.cpp
InterfaceListItem.cpp
InterfaceView.cpp
IPAddressControl.cpp
# from NetworkStatus
RadioView.cpp