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'
|
B_NETWORK_SETTINGS_TYPE_OTHER = 'othr'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kMsgSettingsItemUpdated = 'SIup'
|
||||||
|
};
|
||||||
|
|
||||||
class BNetworkProfile;
|
class BNetworkProfile;
|
||||||
class BNetworkSettings;
|
class BNetworkSettings;
|
||||||
|
|
||||||
@@ -42,10 +46,12 @@ public:
|
|||||||
const BNetworkProfile*
|
const BNetworkProfile*
|
||||||
Profile() const;
|
Profile() const;
|
||||||
|
|
||||||
virtual status_t Apply() = 0;
|
|
||||||
virtual status_t Revert() = 0;
|
virtual status_t Revert() = 0;
|
||||||
virtual bool IsRevertable() = 0;
|
virtual bool IsRevertable() = 0;
|
||||||
|
|
||||||
|
virtual void SettingsUpdated(uint32 type);
|
||||||
|
virtual void ConfigurationUpdated(const BMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const BNetworkProfile*
|
const BNetworkProfile*
|
||||||
fProfile;
|
fProfile;
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ public:
|
|||||||
virtual BListItem* ListItem();
|
virtual BListItem* ListItem();
|
||||||
virtual BView* View();
|
virtual BView* View();
|
||||||
|
|
||||||
virtual status_t Apply();
|
|
||||||
virtual status_t Revert();
|
virtual status_t Revert();
|
||||||
virtual bool IsRevertable();
|
virtual bool IsRevertable();
|
||||||
|
|
||||||
|
virtual void ConfigurationUpdated(const BMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BNetworkSettings& fSettings;
|
BNetworkSettings& fSettings;
|
||||||
BStringItem* fItem;
|
BStringItem* fItem;
|
||||||
@@ -94,13 +95,6 @@ IPv4InterfaceItem::View()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
IPv4InterfaceItem::Apply()
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
IPv4InterfaceItem::Revert()
|
IPv4InterfaceItem::Revert()
|
||||||
{
|
{
|
||||||
@@ -115,6 +109,14 @@ IPv4InterfaceItem::IsRevertable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
IPv4InterfaceItem::ConfigurationUpdated(const BMessage& message)
|
||||||
|
{
|
||||||
|
if (fView != NULL)
|
||||||
|
fView->ConfigurationUpdated(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
const uint32 kModeAuto = 'iato';
|
const uint32 kModeAuto = 'iato';
|
||||||
const uint32 kModeStatic = 'istc';
|
const uint32 kModeStatic = 'istc';
|
||||||
const uint32 kModeDisabled = 'ioff';
|
const uint32 kModeDisabled = 'ioff';
|
||||||
|
const uint32 kMsgApply = 'aply';
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - InterfaceAddressView
|
// #pragma mark - InterfaceAddressView
|
||||||
@@ -82,6 +84,11 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
|||||||
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"),
|
||||||
|
new BMessage(kMsgApply));
|
||||||
|
fApplyButton->SetExplicitAlignment(
|
||||||
|
BAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_UNSET));
|
||||||
|
|
||||||
fSettings.GetInterface(interface, fOriginalInterface);
|
fSettings.GetInterface(interface, fOriginalInterface);
|
||||||
fInterfaceSettings = fOriginalInterface;
|
fInterfaceSettings = fOriginalInterface;
|
||||||
_UpdateFields();
|
_UpdateFields();
|
||||||
@@ -93,6 +100,7 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
|||||||
.AddTextControl(fNetmaskField, 0, 2, B_ALIGN_RIGHT)
|
.AddTextControl(fNetmaskField, 0, 2, B_ALIGN_RIGHT)
|
||||||
.AddTextControl(fGatewayField, 0, 3, B_ALIGN_RIGHT)
|
.AddTextControl(fGatewayField, 0, 3, B_ALIGN_RIGHT)
|
||||||
.End()
|
.End()
|
||||||
|
.Add(fApplyButton)
|
||||||
.AddGlue();
|
.AddGlue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +128,11 @@ InterfaceAddressView::MessageReceived(BMessage* message)
|
|||||||
case kModeStatic:
|
case kModeStatic:
|
||||||
case kModeDisabled:
|
case kModeDisabled:
|
||||||
_SetModeField(message->what);
|
_SetModeField(message->what);
|
||||||
|
if (message->what != kModeStatic)
|
||||||
|
_UpdateSettings();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgApply:
|
||||||
_UpdateSettings();
|
_UpdateSettings();
|
||||||
break;
|
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
|
// #pragma mark - InterfaceAddressView public methods
|
||||||
|
|
||||||
|
|
||||||
@@ -177,22 +178,50 @@ InterfaceAddressView::Revert()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
void
|
||||||
InterfaceAddressView::Save()
|
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();
|
BMenuItem* item = fModePopUpMenu->FindMarked();
|
||||||
if (item == NULL)
|
if (item == NULL)
|
||||||
return B_ERROR;
|
return;
|
||||||
/*
|
/*
|
||||||
fSettings->SetIP(fFamily, fAddressField->Text());
|
fSettings->SetIP(fFamily, fAddressField->Text());
|
||||||
fSettings->SetNetmask(fFamily, fNetmaskField->Text());
|
fSettings->SetNetmask(fFamily, fNetmaskField->Text());
|
||||||
fSettings->SetGateway(fFamily, fGatewayField->Text());
|
fSettings->SetGateway(fFamily, fGatewayField->Text());
|
||||||
fSettings->SetAutoConfigure(fFamily, item->Command() == kModeAuto);
|
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
|
void
|
||||||
InterfaceAddressView::_UpdateFields()
|
InterfaceAddressView::_UpdateFields()
|
||||||
{
|
{
|
||||||
@@ -257,4 +286,27 @@ InterfaceAddressView::_SetModeField(uint32 mode)
|
|||||||
void
|
void
|
||||||
InterfaceAddressView::_UpdateSettings()
|
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>
|
#include <NetworkSettings.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BButton;
|
||||||
class BMenuField;
|
class BMenuField;
|
||||||
class BMessage;
|
class BMessage;
|
||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
@@ -38,7 +39,11 @@ public:
|
|||||||
status_t Revert();
|
status_t Revert();
|
||||||
status_t Save();
|
status_t Save();
|
||||||
|
|
||||||
|
void ConfigurationUpdated(const BMessage& message);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _Apply();
|
||||||
void _EnableFields(bool enable);
|
void _EnableFields(bool enable);
|
||||||
void _UpdateFields();
|
void _UpdateFields();
|
||||||
void _SetModeField(uint32 mode);
|
void _SetModeField(uint32 mode);
|
||||||
@@ -57,6 +62,7 @@ private:
|
|||||||
BTextControl* fAddressField;
|
BTextControl* fAddressField;
|
||||||
BTextControl* fNetmaskField;
|
BTextControl* fNetmaskField;
|
||||||
BTextControl* fGatewayField;
|
BTextControl* fGatewayField;
|
||||||
|
BButton* fApplyButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,18 @@ BNetworkSettingsItem::Profile() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BNetworkSettingsItem::SettingsUpdated(uint32 type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BNetworkSettingsItem::ConfigurationUpdated(const BMessage& message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <NetworkInterface.h>
|
#include <NetworkInterface.h>
|
||||||
|
#include <NetworkNotifications.h>
|
||||||
#include <NetworkRoster.h>
|
#include <NetworkRoster.h>
|
||||||
#include <OutlineListView.h>
|
#include <OutlineListView.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
@@ -49,7 +50,6 @@ const char* kNetworkStatusSignature = "application/x-vnd.Haiku-NetworkStatus";
|
|||||||
static const uint32 kMsgProfileSelected = 'prof';
|
static const uint32 kMsgProfileSelected = 'prof';
|
||||||
static const uint32 kMsgProfileManage = 'mngp';
|
static const uint32 kMsgProfileManage = 'mngp';
|
||||||
static const uint32 kMsgProfileNew = 'newp';
|
static const uint32 kMsgProfileNew = 'newp';
|
||||||
static const uint32 kMsgApply = 'aply';
|
|
||||||
static const uint32 kMsgRevert = 'rvrt';
|
static const uint32 kMsgRevert = 'rvrt';
|
||||||
static const uint32 kMsgToggleReplicant = 'trep';
|
static const uint32 kMsgToggleReplicant = 'trep';
|
||||||
static const uint32 kMsgItemSelected = 'ItSl';
|
static const uint32 kMsgItemSelected = 'ItSl';
|
||||||
@@ -78,10 +78,6 @@ NetworkWindow::NetworkWindow()
|
|||||||
|
|
||||||
// Settings section
|
// Settings section
|
||||||
|
|
||||||
fApplyButton = new BButton("apply", B_TRANSLATE("Apply"),
|
|
||||||
new BMessage(kMsgApply));
|
|
||||||
SetDefaultButton(fApplyButton);
|
|
||||||
|
|
||||||
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
|
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
|
||||||
new BMessage(kMsgRevert));
|
new BMessage(kMsgRevert));
|
||||||
// fRevertButton->SetEnabled(false);
|
// fRevertButton->SetEnabled(false);
|
||||||
@@ -124,7 +120,6 @@ NetworkWindow::NetworkWindow()
|
|||||||
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
||||||
.Add(fRevertButton)
|
.Add(fRevertButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(fApplyButton)
|
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
_ScanInterfaces();
|
_ScanInterfaces();
|
||||||
@@ -141,11 +136,15 @@ NetworkWindow::NetworkWindow()
|
|||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
|
|
||||||
fSettings.StartMonitoring(this);
|
fSettings.StartMonitoring(this);
|
||||||
|
start_watching_network(B_WATCH_NETWORK_INTERFACE_CHANGES
|
||||||
|
| B_WATCH_NETWORK_LINK_CHANGES | B_WATCH_NETWORK_WLAN_CHANGES, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NetworkWindow::~NetworkWindow()
|
NetworkWindow::~NetworkWindow()
|
||||||
{
|
{
|
||||||
|
stop_watching_network(this);
|
||||||
|
fSettings.StopMonitoring(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,10 +169,7 @@ NetworkWindow::MessageReceived(BMessage* message)
|
|||||||
if (message->FindString("path", &path) != B_OK)
|
if (message->FindString("path", &path) != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
BPath name(path);
|
// TODO!
|
||||||
bool isCurrent = strcmp(name.Leaf(), "current") == 0;
|
|
||||||
|
|
||||||
fApplyButton->SetEnabled(!isCurrent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,14 +192,6 @@ NetworkWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kMsgApply:
|
|
||||||
{
|
|
||||||
SettingsMap::const_iterator iterator = fSettingsMap.begin();
|
|
||||||
for (; iterator != fSettingsMap.end(); iterator++)
|
|
||||||
iterator->second->Apply();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case kMsgToggleReplicant:
|
case kMsgToggleReplicant:
|
||||||
{
|
{
|
||||||
_ShowReplicant(
|
_ShowReplicant(
|
||||||
@@ -217,6 +205,16 @@ NetworkWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case B_NETWORK_MONITOR:
|
||||||
|
_BroadcastConfigurationUpdate(*message);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BNetworkSettings::kMsgInterfaceSettingsUpdated:
|
||||||
|
case BNetworkSettings::kMsgNetworkSettingsUpdated:
|
||||||
|
case BNetworkSettings::kMsgServiceSettingsUpdated:
|
||||||
|
_BroadcastSettingsUpdate(message->what);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
inherited::MessageReceived(message);
|
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
|
void
|
||||||
NetworkWindow::_ShowReplicant(bool show)
|
NetworkWindow::_ShowReplicant(bool show)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ private:
|
|||||||
_SettingsItemFor(BListItem* item);
|
_SettingsItemFor(BListItem* item);
|
||||||
BListItem* _ListItemFor(BNetworkSettingsType type);
|
BListItem* _ListItemFor(BNetworkSettingsType type);
|
||||||
void _SelectItem(BListItem* listItem);
|
void _SelectItem(BListItem* listItem);
|
||||||
|
void _BroadcastSettingsUpdate(uint32 type);
|
||||||
|
void _BroadcastConfigurationUpdate(
|
||||||
|
const BMessage& message);
|
||||||
|
|
||||||
bool _IsReplicantInstalled();
|
bool _IsReplicantInstalled();
|
||||||
void _ShowReplicant(bool show);
|
void _ShowReplicant(bool show);
|
||||||
@@ -69,7 +72,6 @@ private:
|
|||||||
BView* fAddOnShellView;
|
BView* fAddOnShellView;
|
||||||
|
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
BButton* fApplyButton;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user