Network: broadcast updates, remove apply button.
* Network now monitors all network, and network settings changes, and will notify all add-ons about those changes. * Removed the global apply button. Instead, the static IP configuration now got that button. All other changes will be instant.
This commit is contained in:
@@ -23,6 +23,10 @@ enum BNetworkSettingsType {
|
||||
B_NETWORK_SETTINGS_TYPE_OTHER = 'othr'
|
||||
};
|
||||
|
||||
enum {
|
||||
kMsgSettingsItemUpdated = 'SIup'
|
||||
};
|
||||
|
||||
class BNetworkProfile;
|
||||
class BNetworkSettings;
|
||||
|
||||
@@ -42,10 +46,12 @@ public:
|
||||
const BNetworkProfile*
|
||||
Profile() const;
|
||||
|
||||
virtual status_t Apply() = 0;
|
||||
virtual status_t Revert() = 0;
|
||||
virtual bool IsRevertable() = 0;
|
||||
|
||||
virtual void SettingsUpdated(uint32 type);
|
||||
virtual void ConfigurationUpdated(const BMessage& message);
|
||||
|
||||
private:
|
||||
const BNetworkProfile*
|
||||
fProfile;
|
||||
|
||||
@@ -42,10 +42,11 @@ public:
|
||||
virtual BListItem* ListItem();
|
||||
virtual BView* View();
|
||||
|
||||
virtual status_t Apply();
|
||||
virtual status_t Revert();
|
||||
virtual bool IsRevertable();
|
||||
|
||||
virtual void ConfigurationUpdated(const BMessage& message);
|
||||
|
||||
private:
|
||||
BNetworkSettings& fSettings;
|
||||
BStringItem* fItem;
|
||||
@@ -94,13 +95,6 @@ IPv4InterfaceItem::View()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
IPv4InterfaceItem::Apply()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
IPv4InterfaceItem::Revert()
|
||||
{
|
||||
@@ -115,6 +109,14 @@ IPv4InterfaceItem::IsRevertable()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPv4InterfaceItem::ConfigurationUpdated(const BMessage& message)
|
||||
{
|
||||
if (fView != NULL)
|
||||
fView->ConfigurationUpdated(message);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutBuilder.h>
|
||||
@@ -31,6 +32,7 @@
|
||||
const uint32 kModeAuto = 'iato';
|
||||
const uint32 kModeStatic = 'istc';
|
||||
const uint32 kModeDisabled = 'ioff';
|
||||
const uint32 kMsgApply = 'aply';
|
||||
|
||||
|
||||
// #pragma mark - InterfaceAddressView
|
||||
@@ -82,6 +84,11 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
||||
fGatewayField->SetToolTip(B_TRANSLATE("Your gateway to the internet"));
|
||||
fGatewayField->TextView()->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
|
||||
|
||||
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
|
||||
new BMessage(kMsgApply));
|
||||
fApplyButton->SetExplicitAlignment(
|
||||
BAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_UNSET));
|
||||
|
||||
fSettings.GetInterface(interface, fOriginalInterface);
|
||||
fInterfaceSettings = fOriginalInterface;
|
||||
_UpdateFields();
|
||||
@@ -93,6 +100,7 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
||||
.AddTextControl(fNetmaskField, 0, 2, B_ALIGN_RIGHT)
|
||||
.AddTextControl(fGatewayField, 0, 3, B_ALIGN_RIGHT)
|
||||
.End()
|
||||
.Add(fApplyButton)
|
||||
.AddGlue();
|
||||
}
|
||||
|
||||
@@ -120,6 +128,11 @@ InterfaceAddressView::MessageReceived(BMessage* message)
|
||||
case kModeStatic:
|
||||
case kModeDisabled:
|
||||
_SetModeField(message->what);
|
||||
if (message->what != kModeStatic)
|
||||
_UpdateSettings();
|
||||
break;
|
||||
|
||||
case kMsgApply:
|
||||
_UpdateSettings();
|
||||
break;
|
||||
|
||||
@@ -129,18 +142,6 @@ InterfaceAddressView::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - InterfaceAddressView private methods
|
||||
|
||||
|
||||
void
|
||||
InterfaceAddressView::_EnableFields(bool enable)
|
||||
{
|
||||
fAddressField->SetEnabled(enable);
|
||||
fNetmaskField->SetEnabled(enable);
|
||||
fGatewayField->SetEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - InterfaceAddressView public methods
|
||||
|
||||
|
||||
@@ -177,22 +178,50 @@ InterfaceAddressView::Revert()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InterfaceAddressView::Save()
|
||||
void
|
||||
InterfaceAddressView::ConfigurationUpdated(const BMessage& message)
|
||||
{
|
||||
const char* device = message.GetString("device", NULL);
|
||||
if (strcmp(device, fInterface.Name()) != 0)
|
||||
return;
|
||||
|
||||
_UpdateFields();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - InterfaceAddressView private methods
|
||||
|
||||
|
||||
void
|
||||
InterfaceAddressView::_Apply()
|
||||
{
|
||||
BMenuItem* item = fModePopUpMenu->FindMarked();
|
||||
if (item == NULL)
|
||||
return B_ERROR;
|
||||
return;
|
||||
/*
|
||||
fSettings->SetIP(fFamily, fAddressField->Text());
|
||||
fSettings->SetNetmask(fFamily, fNetmaskField->Text());
|
||||
fSettings->SetGateway(fFamily, fGatewayField->Text());
|
||||
fSettings->SetAutoConfigure(fFamily, item->Command() == kModeAuto);
|
||||
*/
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfaceAddressView::_EnableFields(bool enable)
|
||||
{
|
||||
fAddressField->SetEnabled(enable);
|
||||
fNetmaskField->SetEnabled(enable);
|
||||
fGatewayField->SetEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
/*! Updates the UI to match the current interface configuration.
|
||||
|
||||
The interface settings may be consulted to determine if the
|
||||
automatic configuration has been specified, if there was no
|
||||
configuration yet.
|
||||
*/
|
||||
void
|
||||
InterfaceAddressView::_UpdateFields()
|
||||
{
|
||||
@@ -257,4 +286,27 @@ InterfaceAddressView::_SetModeField(uint32 mode)
|
||||
void
|
||||
InterfaceAddressView::_UpdateSettings()
|
||||
{
|
||||
BMessage interface;
|
||||
fSettings.GetInterface(fInterface.Name(), interface);
|
||||
|
||||
interface.SetString("device", fInterface.Name());
|
||||
|
||||
uint32 mode = kModeAuto;
|
||||
BMenuItem* item = fModePopUpMenu->FindMarked();
|
||||
if (item != NULL)
|
||||
mode = item->Message()->what;
|
||||
|
||||
// Remove previous address for family
|
||||
|
||||
switch (mode) {
|
||||
case kModeAuto:
|
||||
default:
|
||||
break;
|
||||
case kModeDisabled:
|
||||
break;
|
||||
case kModeStatic:
|
||||
break;
|
||||
}
|
||||
|
||||
fSettings.AddInterface(interface);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <NetworkSettings.h>
|
||||
|
||||
|
||||
class BButton;
|
||||
class BMenuField;
|
||||
class BMessage;
|
||||
class BPopUpMenu;
|
||||
@@ -38,7 +39,11 @@ public:
|
||||
status_t Revert();
|
||||
status_t Save();
|
||||
|
||||
void ConfigurationUpdated(const BMessage& message);
|
||||
|
||||
|
||||
private:
|
||||
void _Apply();
|
||||
void _EnableFields(bool enable);
|
||||
void _UpdateFields();
|
||||
void _SetModeField(uint32 mode);
|
||||
@@ -57,6 +62,7 @@ private:
|
||||
BTextControl* fAddressField;
|
||||
BTextControl* fNetmaskField;
|
||||
BTextControl* fGatewayField;
|
||||
BButton* fApplyButton;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,18 @@ BNetworkSettingsItem::Profile() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkSettingsItem::SettingsUpdated(uint32 type)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkSettingsItem::ConfigurationUpdated(const BMessage& message)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <Directory.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <NetworkInterface.h>
|
||||
#include <NetworkNotifications.h>
|
||||
#include <NetworkRoster.h>
|
||||
#include <OutlineListView.h>
|
||||
#include <Path.h>
|
||||
@@ -49,7 +50,6 @@ const char* kNetworkStatusSignature = "application/x-vnd.Haiku-NetworkStatus";
|
||||
static const uint32 kMsgProfileSelected = 'prof';
|
||||
static const uint32 kMsgProfileManage = 'mngp';
|
||||
static const uint32 kMsgProfileNew = 'newp';
|
||||
static const uint32 kMsgApply = 'aply';
|
||||
static const uint32 kMsgRevert = 'rvrt';
|
||||
static const uint32 kMsgToggleReplicant = 'trep';
|
||||
static const uint32 kMsgItemSelected = 'ItSl';
|
||||
@@ -78,10 +78,6 @@ NetworkWindow::NetworkWindow()
|
||||
|
||||
// Settings section
|
||||
|
||||
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
|
||||
new BMessage(kMsgApply));
|
||||
SetDefaultButton(fApplyButton);
|
||||
|
||||
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
|
||||
new BMessage(kMsgRevert));
|
||||
// fRevertButton->SetEnabled(false);
|
||||
@@ -124,7 +120,6 @@ NetworkWindow::NetworkWindow()
|
||||
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
||||
.Add(fRevertButton)
|
||||
.AddGlue()
|
||||
.Add(fApplyButton)
|
||||
.End();
|
||||
|
||||
_ScanInterfaces();
|
||||
@@ -141,11 +136,15 @@ NetworkWindow::NetworkWindow()
|
||||
CenterOnScreen();
|
||||
|
||||
fSettings.StartMonitoring(this);
|
||||
start_watching_network(B_WATCH_NETWORK_INTERFACE_CHANGES
|
||||
| B_WATCH_NETWORK_LINK_CHANGES | B_WATCH_NETWORK_WLAN_CHANGES, this);
|
||||
}
|
||||
|
||||
|
||||
NetworkWindow::~NetworkWindow()
|
||||
{
|
||||
stop_watching_network(this);
|
||||
fSettings.StopMonitoring(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,10 +169,7 @@ NetworkWindow::MessageReceived(BMessage* message)
|
||||
if (message->FindString("path", &path) != B_OK)
|
||||
break;
|
||||
|
||||
BPath name(path);
|
||||
bool isCurrent = strcmp(name.Leaf(), "current") == 0;
|
||||
|
||||
fApplyButton->SetEnabled(!isCurrent);
|
||||
// TODO!
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -196,14 +192,6 @@ NetworkWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case kMsgApply:
|
||||
{
|
||||
SettingsMap::const_iterator iterator = fSettingsMap.begin();
|
||||
for (; iterator != fSettingsMap.end(); iterator++)
|
||||
iterator->second->Apply();
|
||||
break;
|
||||
}
|
||||
|
||||
case kMsgToggleReplicant:
|
||||
{
|
||||
_ShowReplicant(
|
||||
@@ -217,6 +205,16 @@ NetworkWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case B_NETWORK_MONITOR:
|
||||
_BroadcastConfigurationUpdate(*message);
|
||||
break;
|
||||
|
||||
case BNetworkSettings::kMsgInterfaceSettingsUpdated:
|
||||
case BNetworkSettings::kMsgNetworkSettingsUpdated:
|
||||
case BNetworkSettings::kMsgServiceSettingsUpdated:
|
||||
_BroadcastSettingsUpdate(message->what);
|
||||
break;
|
||||
|
||||
default:
|
||||
inherited::MessageReceived(message);
|
||||
}
|
||||
@@ -452,6 +450,24 @@ NetworkWindow::_SelectItem(BListItem* listItem)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkWindow::_BroadcastSettingsUpdate(uint32 type)
|
||||
{
|
||||
SettingsMap::const_iterator iterator = fSettingsMap.begin();
|
||||
for (; iterator != fSettingsMap.end(); iterator++)
|
||||
iterator->second->SettingsUpdated(type);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkWindow::_BroadcastConfigurationUpdate(const BMessage& message)
|
||||
{
|
||||
SettingsMap::const_iterator iterator = fSettingsMap.begin();
|
||||
for (; iterator != fSettingsMap.end(); iterator++)
|
||||
iterator->second->ConfigurationUpdated(message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NetworkWindow::_ShowReplicant(bool show)
|
||||
{
|
||||
|
||||
@@ -44,6 +44,9 @@ private:
|
||||
_SettingsItemFor(BListItem* item);
|
||||
BListItem* _ListItemFor(BNetworkSettingsType type);
|
||||
void _SelectItem(BListItem* listItem);
|
||||
void _BroadcastSettingsUpdate(uint32 type);
|
||||
void _BroadcastConfigurationUpdate(
|
||||
const BMessage& message);
|
||||
|
||||
bool _IsReplicantInstalled();
|
||||
void _ShowReplicant(bool show);
|
||||
@@ -69,7 +72,6 @@ private:
|
||||
BView* fAddOnShellView;
|
||||
|
||||
BButton* fRevertButton;
|
||||
BButton* fApplyButton;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user