Network/IPv4Interface: settings are now applied instantly.
* Via the BNetworkSettings class. * The static IP mode still requires an extra apply button. * IP input is not validated at all yet, we could also automatically fill in the network mask once the IP has been entered.
This commit is contained in:
parent
e4f4658a1b
commit
59f911ab03
@ -117,6 +117,7 @@ void
|
|||||||
InterfaceAddressView::AttachedToWindow()
|
InterfaceAddressView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
fModePopUpMenu->SetTargetForItems(this);
|
fModePopUpMenu->SetTargetForItems(this);
|
||||||
|
fApplyButton->SetTarget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -127,6 +128,9 @@ InterfaceAddressView::MessageReceived(BMessage* message)
|
|||||||
case kModeAuto:
|
case kModeAuto:
|
||||||
case kModeStatic:
|
case kModeStatic:
|
||||||
case kModeDisabled:
|
case kModeDisabled:
|
||||||
|
if (message->what == fLastMode)
|
||||||
|
break;
|
||||||
|
|
||||||
_SetModeField(message->what);
|
_SetModeField(message->what);
|
||||||
if (message->what != kModeStatic)
|
if (message->what != kModeStatic)
|
||||||
_UpdateSettings();
|
_UpdateSettings();
|
||||||
@ -181,8 +185,8 @@ InterfaceAddressView::Revert()
|
|||||||
void
|
void
|
||||||
InterfaceAddressView::ConfigurationUpdated(const BMessage& message)
|
InterfaceAddressView::ConfigurationUpdated(const BMessage& message)
|
||||||
{
|
{
|
||||||
const char* device = message.GetString("device", NULL);
|
const char* interface = message.GetString("interface", NULL);
|
||||||
if (strcmp(device, fInterface.Name()) != 0)
|
if (interface == NULL || strcmp(interface, fInterface.Name()) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_UpdateFields();
|
_UpdateFields();
|
||||||
@ -192,27 +196,13 @@ InterfaceAddressView::ConfigurationUpdated(const BMessage& message)
|
|||||||
// #pragma mark - InterfaceAddressView private methods
|
// #pragma mark - InterfaceAddressView private methods
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InterfaceAddressView::_Apply()
|
|
||||||
{
|
|
||||||
BMenuItem* item = fModePopUpMenu->FindMarked();
|
|
||||||
if (item == NULL)
|
|
||||||
return;
|
|
||||||
/*
|
|
||||||
fSettings->SetIP(fFamily, fAddressField->Text());
|
|
||||||
fSettings->SetNetmask(fFamily, fNetmaskField->Text());
|
|
||||||
fSettings->SetGateway(fFamily, fGatewayField->Text());
|
|
||||||
fSettings->SetAutoConfigure(fFamily, item->Command() == kModeAuto);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InterfaceAddressView::_EnableFields(bool enable)
|
InterfaceAddressView::_EnableFields(bool enable)
|
||||||
{
|
{
|
||||||
fAddressField->SetEnabled(enable);
|
fAddressField->SetEnabled(enable);
|
||||||
fNetmaskField->SetEnabled(enable);
|
fNetmaskField->SetEnabled(enable);
|
||||||
fGatewayField->SetEnabled(enable);
|
fGatewayField->SetEnabled(enable);
|
||||||
|
fApplyButton->SetEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -279,6 +269,8 @@ InterfaceAddressView::_SetModeField(uint32 mode)
|
|||||||
fNetmaskField->SetText(NULL);
|
fNetmaskField->SetText(NULL);
|
||||||
fGatewayField->SetText(NULL);
|
fGatewayField->SetText(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fLastMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -288,25 +280,93 @@ InterfaceAddressView::_UpdateSettings()
|
|||||||
{
|
{
|
||||||
BMessage interface;
|
BMessage interface;
|
||||||
fSettings.GetInterface(fInterface.Name(), interface);
|
fSettings.GetInterface(fInterface.Name(), interface);
|
||||||
|
BNetworkInterfaceSettings settings(interface);
|
||||||
|
|
||||||
interface.SetString("device", fInterface.Name());
|
settings.SetName(fInterface.Name());
|
||||||
|
|
||||||
|
// Remove previous address for family
|
||||||
|
|
||||||
|
int32 index = _FindFirstAddress(settings, fFamily);
|
||||||
|
if (index < 0)
|
||||||
|
index = _FindFirstAddress(settings, AF_UNSPEC);
|
||||||
|
if (index >= 0 && index < settings.CountAddresses()) {
|
||||||
|
BNetworkInterfaceAddressSettings& address = settings.AddressAt(index);
|
||||||
|
printf("family = %d", address.Family());
|
||||||
|
_ConfigureAddress(address);
|
||||||
|
} else {
|
||||||
|
BNetworkInterfaceAddressSettings address;
|
||||||
|
_ConfigureAddress(address);
|
||||||
|
settings.AddAddress(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface.MakeEmpty();
|
||||||
|
|
||||||
|
// TODO: better error reporting!
|
||||||
|
status_t status = settings.GetMessage(interface);
|
||||||
|
if (status == B_OK)
|
||||||
|
fSettings.AddInterface(interface);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Could not add interface: %s\n", strerror(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
InterfaceAddressView::_Mode() const
|
||||||
|
{
|
||||||
uint32 mode = kModeAuto;
|
uint32 mode = kModeAuto;
|
||||||
BMenuItem* item = fModePopUpMenu->FindMarked();
|
BMenuItem* item = fModePopUpMenu->FindMarked();
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
mode = item->Message()->what;
|
mode = item->Message()->what;
|
||||||
|
|
||||||
// Remove previous address for family
|
return mode;
|
||||||
|
}
|
||||||
switch (mode) {
|
|
||||||
case kModeAuto:
|
|
||||||
default:
|
int32
|
||||||
break;
|
InterfaceAddressView::_FindFirstAddress(
|
||||||
case kModeDisabled:
|
const BNetworkInterfaceSettings& settings, int family)
|
||||||
break;
|
{
|
||||||
case kModeStatic:
|
for (int32 index = 0; index < settings.CountAddresses(); index++) {
|
||||||
break;
|
const BNetworkInterfaceAddressSettings address
|
||||||
}
|
= settings.AddressAt(index);
|
||||||
|
if (address.Family() == family)
|
||||||
fSettings.AddInterface(interface);
|
return index;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InterfaceAddressView::_ConfigureAddress(
|
||||||
|
BNetworkInterfaceAddressSettings& settings)
|
||||||
|
{
|
||||||
|
uint32 mode = _Mode();
|
||||||
|
|
||||||
|
printf("family: %d\n", (int)fFamily);
|
||||||
|
settings.SetFamily(fFamily);
|
||||||
|
settings.SetAutoConfigure(mode == kModeAuto);
|
||||||
|
|
||||||
|
settings.Address().Unset();
|
||||||
|
settings.Mask().Unset();
|
||||||
|
settings.Peer().Unset();
|
||||||
|
settings.Broadcast().Unset();
|
||||||
|
settings.Gateway().Unset();
|
||||||
|
|
||||||
|
if (mode == kModeStatic) {
|
||||||
|
_SetAddress(settings.Address(), fAddressField->Text());
|
||||||
|
_SetAddress(settings.Mask(), fNetmaskField->Text());
|
||||||
|
_SetAddress(settings.Gateway(), fGatewayField->Text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InterfaceAddressView::_SetAddress(BNetworkAddress& address, const char* text)
|
||||||
|
{
|
||||||
|
BString string(text);
|
||||||
|
string.Trim();
|
||||||
|
if (string.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
address.SetTo(string.String());
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,25 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Apply();
|
|
||||||
void _EnableFields(bool enable);
|
void _EnableFields(bool enable);
|
||||||
void _UpdateFields();
|
void _UpdateFields();
|
||||||
void _SetModeField(uint32 mode);
|
void _SetModeField(uint32 mode);
|
||||||
void _UpdateSettings();
|
void _UpdateSettings();
|
||||||
|
uint32 _Mode() const;
|
||||||
|
int32 _FindFirstAddress(
|
||||||
|
const BNetworkInterfaceSettings& settings,
|
||||||
|
int family);
|
||||||
|
|
||||||
|
void _ConfigureAddress(
|
||||||
|
BNetworkInterfaceAddressSettings& address);
|
||||||
|
void _SetAddress(BNetworkAddress& address,
|
||||||
|
const char* text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fFamily;
|
int fFamily;
|
||||||
BNetworkInterface fInterface;
|
BNetworkInterface fInterface;
|
||||||
BNetworkSettings& fSettings;
|
BNetworkSettings& fSettings;
|
||||||
|
uint32 fLastMode;
|
||||||
|
|
||||||
BMessage fOriginalInterface;
|
BMessage fOriginalInterface;
|
||||||
BMessage fInterfaceSettings;
|
BMessage fInterfaceSettings;
|
||||||
|
Loading…
Reference in New Issue
Block a user