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:
@@ -26,14 +26,14 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
|
||||||
|
#include "IPAddressControl.h"
|
||||||
|
|
||||||
|
|
||||||
static const int32 kMsgAddServer = 'adds';
|
static const int32 kMsgAddServer = 'adds';
|
||||||
static const int32 kMsgDeleteServer = 'dels';
|
static const int32 kMsgDeleteServer = 'dels';
|
||||||
static const int32 kMsgMoveUp = 'mvup';
|
static const int32 kMsgMoveUp = 'mvup';
|
||||||
static const int32 kMsgMoveDown = 'mvdn';
|
static const int32 kMsgMoveDown = 'mvdn';
|
||||||
static const int32 kMsgEditServer = 'edit';
|
|
||||||
static const int32 kMsgApply = 'aply';
|
static const int32 kMsgApply = 'aply';
|
||||||
|
|
||||||
|
|
||||||
@@ -46,8 +46,7 @@ DNSSettingsView::DNSSettingsView()
|
|||||||
BView("dns", 0)
|
BView("dns", 0)
|
||||||
{
|
{
|
||||||
fServerListView = new BListView("nameservers");
|
fServerListView = new BListView("nameservers");
|
||||||
fTextControl = new BTextControl("", "", NULL);
|
fTextControl = new IPAddressControl(AF_UNSPEC, "server", "");
|
||||||
fTextControl->SetModificationMessage(new BMessage(kMsgEditServer));
|
|
||||||
fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 18,
|
fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 18,
|
||||||
B_SIZE_UNSET));
|
B_SIZE_UNSET));
|
||||||
|
|
||||||
@@ -158,14 +157,6 @@ DNSSettingsView::MessageReceived(BMessage* message)
|
|||||||
fServerListView->SwapItems(index, index + 1);
|
fServerListView->SwapItems(index, index + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kMsgEditServer:
|
|
||||||
{
|
|
||||||
struct in_addr dummy;
|
|
||||||
bool success = inet_aton(fTextControl->Text(), &dummy);
|
|
||||||
fTextControl->MarkAsInvalid(!success);
|
|
||||||
fAddButton->SetEnabled(success);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kMsgApply:
|
case kMsgApply:
|
||||||
_SaveDNSConfiguration();
|
_SaveDNSConfiguration();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings dnsclient ;
|
|||||||
|
|
||||||
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
||||||
UsePrivateHeaders app libroot kernel net ;
|
UsePrivateHeaders app libroot kernel net ;
|
||||||
|
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
|
||||||
|
|
||||||
Addon DNSClientService :
|
Addon DNSClientService :
|
||||||
DNSClientServiceAddOn.cpp
|
DNSClientServiceAddOn.cpp
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
|
#include "IPAddressControl.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "IntefaceAddressView"
|
#define B_TRANSLATION_CONTEXT "IntefaceAddressView"
|
||||||
@@ -74,15 +76,23 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
|||||||
|
|
||||||
float minimumWidth = be_control_look->DefaultItemSpacing() * 16;
|
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->SetToolTip(B_TRANSLATE("Your IP address"));
|
||||||
fAddressField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
|
fAddressField->TextView()->SetExplicitMinSize(
|
||||||
fNetmaskField = new BTextControl(B_TRANSLATE("Netmask:"), NULL, NULL);
|
BSize(minimumWidth, B_SIZE_UNSET));
|
||||||
fNetmaskField->SetToolTip(B_TRANSLATE("The netmask defines your local network"));
|
fAddressField->SetAllowEmpty(false);
|
||||||
fNetmaskField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
|
fNetmaskField = new IPAddressControl(fFamily, B_TRANSLATE("Netmask:"),
|
||||||
fGatewayField = new BTextControl(B_TRANSLATE("Gateway:"), NULL, NULL);
|
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->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"),
|
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
|
||||||
new BMessage(kMsgApply));
|
new BMessage(kMsgApply));
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class BMessage;
|
|||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
class BRect;
|
class BRect;
|
||||||
class BTextControl;
|
class BTextControl;
|
||||||
|
class IPAddressControl;
|
||||||
|
|
||||||
|
|
||||||
using namespace BNetworkKit;
|
using namespace BNetworkKit;
|
||||||
@@ -65,9 +66,9 @@ private:
|
|||||||
|
|
||||||
BPopUpMenu* fModePopUpMenu;
|
BPopUpMenu* fModePopUpMenu;
|
||||||
BMenuField* fModeField;
|
BMenuField* fModeField;
|
||||||
BTextControl* fAddressField;
|
IPAddressControl* fAddressField;
|
||||||
BTextControl* fNetmaskField;
|
IPAddressControl* fNetmaskField;
|
||||||
BTextControl* fGatewayField;
|
IPAddressControl* fGatewayField;
|
||||||
BButton* fApplyButton;
|
BButton* fApplyButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings ipv4 ;
|
|||||||
|
|
||||||
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared ;
|
||||||
|
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
|
||||||
|
|
||||||
Addon IPv4Interface :
|
Addon IPv4Interface :
|
||||||
IPv4InterfaceAddOn.cpp
|
IPv4InterfaceAddOn.cpp
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons network_settings ipv6 ;
|
|||||||
|
|
||||||
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared ;
|
||||||
|
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] : false ;
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons network_settings ipv4 ] ;
|
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
|
||||||
@@ -13,6 +13,7 @@ Preference Network :
|
|||||||
NetworkSettingsAddOn.cpp
|
NetworkSettingsAddOn.cpp
|
||||||
InterfaceListItem.cpp
|
InterfaceListItem.cpp
|
||||||
InterfaceView.cpp
|
InterfaceView.cpp
|
||||||
|
IPAddressControl.cpp
|
||||||
|
|
||||||
# from NetworkStatus
|
# from NetworkStatus
|
||||||
RadioView.cpp
|
RadioView.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user