Network Preflet: Allow more than 2 DNS
Change the way DNS are entered: now the user can enter multiple DNS servers addresses separated by a comma. Actually we handle also spaces or semicolon. Network Preflet: Fix GetDNSListFromString
This commit is contained in:
@@ -84,6 +84,24 @@ MatchPattern(const char* string, const char* pattern)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int32
|
||||||
|
GetDNSListFromString(BString string, BObjectList<BString>& list)
|
||||||
|
{
|
||||||
|
for (size_t startPos = 0;
|
||||||
|
(startPos = strcspn(string.String(), "1234567890"))
|
||||||
|
!= (size_t)string.Length();) {
|
||||||
|
/*size_t startPos = strcspn(string.String(), "1234567890");
|
||||||
|
if (startPos == (size_t)string.Length())
|
||||||
|
break;*/
|
||||||
|
string.Remove(0, startPos);
|
||||||
|
size_t endPos = strcspn(string.String(), ",; ");
|
||||||
|
BString *dns = new BString();
|
||||||
|
string.MoveInto(*dns, 0, endPos);
|
||||||
|
if (!list.AddItem(dns))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -91,12 +109,14 @@ MatchPattern(const char* string, const char* pattern)
|
|||||||
#define B_TRANSLATION_CONTEXT "EthernetSettingsView"
|
#define B_TRANSLATION_CONTEXT "EthernetSettingsView"
|
||||||
|
|
||||||
|
|
||||||
class IPV4AddressTextControl : public BTextControl {
|
// A TextControl which doesn't accept any charachter on creation
|
||||||
public:
|
class CustomTextControl : public BTextControl {
|
||||||
IPV4AddressTextControl(const char* label,
|
public:
|
||||||
const char* initialText,
|
CustomTextControl(const char* label,
|
||||||
BMessage* message);
|
const char* initialText,
|
||||||
virtual ~IPV4AddressTextControl();
|
BMessage* message);
|
||||||
|
virtual ~CustomTextControl();
|
||||||
|
void AllowChars(const char* chars);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -154,9 +174,10 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 3);
|
layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 3);
|
||||||
layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 3);
|
layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 3);
|
||||||
|
|
||||||
fIPTextControl = new IPV4AddressTextControl(
|
fIPTextControl = new CustomTextControl(
|
||||||
B_TRANSLATE("IP address:"), "", NULL);
|
B_TRANSLATE("IP address:"), "", NULL);
|
||||||
SetupTextControl(fIPTextControl);
|
SetupTextControl(fIPTextControl);
|
||||||
|
((CustomTextControl*)fIPTextControl)->AllowChars("0123456789.");
|
||||||
|
|
||||||
BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
|
BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
|
||||||
layoutItem->SetExplicitMinSize(BSize(
|
layoutItem->SetExplicitMinSize(BSize(
|
||||||
@@ -166,43 +187,38 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 4);
|
layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 4);
|
||||||
layout->AddItem(layoutItem, 1, 4);
|
layout->AddItem(layoutItem, 1, 4);
|
||||||
|
|
||||||
fNetMaskTextControl = new IPV4AddressTextControl(
|
fNetMaskTextControl = new CustomTextControl(
|
||||||
B_TRANSLATE("Netmask:"), "", NULL);
|
B_TRANSLATE("Netmask:"), "", NULL);
|
||||||
SetupTextControl(fNetMaskTextControl);
|
SetupTextControl(fNetMaskTextControl);
|
||||||
layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 5);
|
layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 5);
|
||||||
layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 5);
|
layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 5);
|
||||||
|
((CustomTextControl*)fNetMaskTextControl)->AllowChars("0123456789.");
|
||||||
|
|
||||||
fGatewayTextControl = new IPV4AddressTextControl(
|
fGatewayTextControl = new CustomTextControl(
|
||||||
B_TRANSLATE("Gateway:"), "", NULL);
|
B_TRANSLATE("Gateway:"), "", NULL);
|
||||||
SetupTextControl(fGatewayTextControl);
|
SetupTextControl(fGatewayTextControl);
|
||||||
layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 6);
|
layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 6);
|
||||||
layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 6);
|
layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 6);
|
||||||
|
((CustomTextControl*)fGatewayTextControl)->AllowChars("0123456789.");
|
||||||
|
|
||||||
// TODO: Replace the DNS text controls by a BListView with add/remove
|
fDNSTextControl = new BTextControl(
|
||||||
// functionality and so on...
|
B_TRANSLATE("DNS:"), "", NULL);
|
||||||
fPrimaryDNSTextControl = new IPV4AddressTextControl(
|
SetupTextControl(fDNSTextControl);
|
||||||
B_TRANSLATE("DNS #1:"), "", NULL);
|
layout->AddItem(fDNSTextControl->CreateLabelLayoutItem(), 0, 7);
|
||||||
SetupTextControl(fPrimaryDNSTextControl);
|
layout->AddItem(fDNSTextControl->CreateTextViewLayoutItem(), 1, 7);
|
||||||
layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 7);
|
((CustomTextControl*)fDNSTextControl)->AllowChars("0123456789.;, ");
|
||||||
layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7);
|
|
||||||
|
|
||||||
fSecondaryDNSTextControl = new IPV4AddressTextControl(
|
|
||||||
B_TRANSLATE("DNS #2:"), "", NULL);
|
|
||||||
SetupTextControl(fSecondaryDNSTextControl);
|
|
||||||
layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 8);
|
|
||||||
layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 8);
|
|
||||||
|
|
||||||
fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL);
|
fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL);
|
||||||
SetupTextControl(fDomainTextControl);
|
SetupTextControl(fDomainTextControl);
|
||||||
layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 9);
|
layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8);
|
||||||
layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 9);
|
layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8);
|
||||||
|
|
||||||
fErrorMessage = new BStringView("error", "");
|
fErrorMessage = new BStringView("error", "");
|
||||||
fErrorMessage->SetAlignment(B_ALIGN_LEFT);
|
fErrorMessage->SetAlignment(B_ALIGN_LEFT);
|
||||||
fErrorMessage->SetFont(be_bold_font);
|
fErrorMessage->SetFont(be_bold_font);
|
||||||
fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
|
||||||
layout->AddView(fErrorMessage, 1, 10);
|
layout->AddView(fErrorMessage, 1, 9);
|
||||||
|
|
||||||
// button group (TODO: move to window, but take care of
|
// button group (TODO: move to window, but take care of
|
||||||
// enabling/disabling)
|
// enabling/disabling)
|
||||||
@@ -237,8 +253,7 @@ EthernetSettingsView::AttachedToWindow()
|
|||||||
fIPTextControl->SetTarget(this);
|
fIPTextControl->SetTarget(this);
|
||||||
fNetMaskTextControl->SetTarget(this);
|
fNetMaskTextControl->SetTarget(this);
|
||||||
fGatewayTextControl->SetTarget(this);
|
fGatewayTextControl->SetTarget(this);
|
||||||
fPrimaryDNSTextControl->SetTarget(this);
|
fDNSTextControl->SetTarget(this);
|
||||||
fSecondaryDNSTextControl->SetTarget(this);
|
|
||||||
fDomainTextControl->SetTarget(this);
|
fDomainTextControl->SetTarget(this);
|
||||||
fDeviceMenuField->Menu()->SetTargetForItems(this);
|
fDeviceMenuField->Menu()->SetTargetForItems(this);
|
||||||
fNetworkMenuField->Menu()->SetTargetForItems(this);
|
fNetworkMenuField->Menu()->SetTargetForItems(this);
|
||||||
@@ -315,10 +330,8 @@ EthernetSettingsView::MessageReceived(BMessage* message)
|
|||||||
&& _ValidateControl(fNetMaskTextControl)
|
&& _ValidateControl(fNetMaskTextControl)
|
||||||
&& (strlen(fGatewayTextControl->Text()) == 0
|
&& (strlen(fGatewayTextControl->Text()) == 0
|
||||||
|| _ValidateControl(fGatewayTextControl))
|
|| _ValidateControl(fGatewayTextControl))
|
||||||
&& (strlen(fPrimaryDNSTextControl->Text()) == 0
|
/*&& (strlen(fDNSTextControl->Text()) == 0
|
||||||
|| _ValidateControl(fPrimaryDNSTextControl))
|
|| _ValidateControl(fDNSTextControl)*/)
|
||||||
&& (strlen(fSecondaryDNSTextControl->Text()) == 0
|
|
||||||
|| _ValidateControl(fSecondaryDNSTextControl)))
|
|
||||||
_SaveConfiguration();
|
_SaveConfiguration();
|
||||||
break;
|
break;
|
||||||
case kMsgChange:
|
case kMsgChange:
|
||||||
@@ -431,8 +444,7 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
|||||||
fIPTextControl->SetText("");
|
fIPTextControl->SetText("");
|
||||||
fGatewayTextControl->SetText("");
|
fGatewayTextControl->SetText("");
|
||||||
fNetMaskTextControl->SetText("");
|
fNetMaskTextControl->SetText("");
|
||||||
fPrimaryDNSTextControl->SetText("");
|
fDNSTextControl->SetText("");
|
||||||
fSecondaryDNSTextControl->SetText("");
|
|
||||||
fDomainTextControl->SetText("");
|
fDomainTextControl->SetText("");
|
||||||
|
|
||||||
fTypeMenuField->SetEnabled(settings != NULL);
|
fTypeMenuField->SetEnabled(settings != NULL);
|
||||||
@@ -525,15 +537,15 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
|||||||
fGatewayTextControl->SetText(settings->Gateway());
|
fGatewayTextControl->SetText(settings->Gateway());
|
||||||
fNetMaskTextControl->SetText(settings->Netmask());
|
fNetMaskTextControl->SetText(settings->Netmask());
|
||||||
|
|
||||||
if (settings->NameServers().CountItems() >= 2) {
|
BString dns;
|
||||||
fSecondaryDNSTextControl->SetText(
|
for (int32 n = 0; n < settings->NameServers().CountItems(); n++) {
|
||||||
settings->NameServers().ItemAt(1)->String());
|
if (n != 0)
|
||||||
|
dns.Append(", ");
|
||||||
|
dns.Append(settings->NameServers().ItemAt(n)->String());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings->NameServers().CountItems() >= 1) {
|
fDNSTextControl->SetText(dns.String());
|
||||||
fPrimaryDNSTextControl->SetText(
|
|
||||||
settings->NameServers().ItemAt(0)->String());
|
|
||||||
}
|
|
||||||
fDomainTextControl->SetText(settings->Domain());
|
fDomainTextControl->SetText(settings->Domain());
|
||||||
|
|
||||||
_EnableTextControls(enableControls);
|
_EnableTextControls(enableControls);
|
||||||
@@ -546,8 +558,7 @@ EthernetSettingsView::_EnableTextControls(bool enable)
|
|||||||
fIPTextControl->SetEnabled(enable);
|
fIPTextControl->SetEnabled(enable);
|
||||||
fGatewayTextControl->SetEnabled(enable);
|
fGatewayTextControl->SetEnabled(enable);
|
||||||
fNetMaskTextControl->SetEnabled(enable);
|
fNetMaskTextControl->SetEnabled(enable);
|
||||||
fPrimaryDNSTextControl->SetEnabled(enable);
|
fDNSTextControl->SetEnabled(enable);
|
||||||
fSecondaryDNSTextControl->SetEnabled(enable);
|
|
||||||
fDomainTextControl->SetEnabled(enable);
|
fDomainTextControl->SetEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,10 +582,10 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
|||||||
B_TRANSLATE("Disabled")) == 0);
|
B_TRANSLATE("Disabled")) == 0);
|
||||||
|
|
||||||
fCurrentSettings->NameServers().MakeEmpty();
|
fCurrentSettings->NameServers().MakeEmpty();
|
||||||
fCurrentSettings->NameServers().AddItem(new BString(
|
|
||||||
fPrimaryDNSTextControl->Text()));
|
BString dnsList = fDNSTextControl->Text();
|
||||||
fCurrentSettings->NameServers().AddItem(new BString(
|
GetDNSListFromString(dnsList, fCurrentSettings->NameServers());
|
||||||
fSecondaryDNSTextControl->Text()));
|
|
||||||
fCurrentSettings->SetDomain(fDomainTextControl->Text());
|
fCurrentSettings->SetDomain(fDomainTextControl->Text());
|
||||||
|
|
||||||
fApplyButton->SetEnabled(false);
|
fApplyButton->SetEnabled(false);
|
||||||
@@ -746,10 +757,8 @@ EthernetSettingsView::_ValidateControl(BTextControl* control)
|
|||||||
errorMessage << B_TRANSLATE("Netmask is invalid");
|
errorMessage << B_TRANSLATE("Netmask is invalid");
|
||||||
} else if (control == fGatewayTextControl) {
|
} else if (control == fGatewayTextControl) {
|
||||||
errorMessage << B_TRANSLATE("Gateway is invalid");
|
errorMessage << B_TRANSLATE("Gateway is invalid");
|
||||||
} else if (control == fPrimaryDNSTextControl) {
|
} else if (control == fDNSTextControl) {
|
||||||
errorMessage << B_TRANSLATE("DNS #1 is invalid");
|
errorMessage << B_TRANSLATE("DNS list is invalid");
|
||||||
} else if (control == fSecondaryDNSTextControl) {
|
|
||||||
errorMessage << B_TRANSLATE("DNS #2 is invalid");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fErrorMessage->SetText(errorMessage.String());
|
fErrorMessage->SetText(errorMessage.String());
|
||||||
@@ -761,26 +770,28 @@ EthernetSettingsView::_ValidateControl(BTextControl* control)
|
|||||||
|
|
||||||
|
|
||||||
// IPV4AddressTextControl
|
// IPV4AddressTextControl
|
||||||
IPV4AddressTextControl::IPV4AddressTextControl(const char* label,
|
CustomTextControl::CustomTextControl(const char* label,
|
||||||
const char* initialText, BMessage* message)
|
const char* initialText, BMessage* message)
|
||||||
:
|
:
|
||||||
BTextControl(label, initialText, message)
|
BTextControl(label, initialText, message)
|
||||||
{
|
{
|
||||||
// TODO: Would be nice to have a formatted input control
|
// TODO: Would be nice to have a formatted input control
|
||||||
// TODO: Would be nice to have a "DisallowAllExcept" method
|
|
||||||
// TODO: This doesn't block multi-byte characters
|
// TODO: This doesn't block multi-byte characters
|
||||||
for (uint32 i = (uint32)0; i <= 255; i++)
|
for (uint32 i = (uint32)0; i <= 255; i++)
|
||||||
TextView()->DisallowChar(i);
|
TextView()->DisallowChar(i);
|
||||||
|
|
||||||
for (uint32 i = (uint32)'0'; i <= (uint32)'9'; i++)
|
|
||||||
TextView()->AllowChar(i);
|
|
||||||
|
|
||||||
TextView()->AllowChar((uint32)'.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
IPV4AddressTextControl::~IPV4AddressTextControl()
|
CustomTextControl::~CustomTextControl()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CustomTextControl::AllowChars(const char* chars)
|
||||||
|
{
|
||||||
|
int numChars = strlen(chars);
|
||||||
|
for (int i = 0; i < numChars; i++)
|
||||||
|
TextView()->AllowChar((uint32)chars[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ private:
|
|||||||
BTextControl* fNetMaskTextControl;
|
BTextControl* fNetMaskTextControl;
|
||||||
BTextControl* fGatewayTextControl;
|
BTextControl* fGatewayTextControl;
|
||||||
|
|
||||||
BTextControl* fPrimaryDNSTextControl;
|
BTextControl* fDNSTextControl;
|
||||||
BTextControl* fSecondaryDNSTextControl;
|
|
||||||
BTextControl* fDomainTextControl;
|
BTextControl* fDomainTextControl;
|
||||||
|
|
||||||
BStringView* fErrorMessage;
|
BStringView* fErrorMessage;
|
||||||
|
|||||||
Reference in New Issue
Block a user