Move the new network preflet at the right place.
This commit is contained in:
@@ -1,798 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* Stephan Assmuß
|
|
||||||
* Axel Dörfler
|
|
||||||
* Hugo Santos
|
|
||||||
* Philippe Saint-Pierre
|
|
||||||
* Vegard Wærp
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "EthernetSettingsView.h"
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <Alert.h>
|
|
||||||
#include <Application.h>
|
|
||||||
#include <Beep.h>
|
|
||||||
#include <Box.h>
|
|
||||||
#include <Button.h>
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <Directory.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <GridView.h>
|
|
||||||
#include <GroupView.h>
|
|
||||||
#include <MenuField.h>
|
|
||||||
#include <MenuItem.h>
|
|
||||||
#include <NetworkDevice.h>
|
|
||||||
#include <NetworkInterface.h>
|
|
||||||
#include <NetworkNotifications.h>
|
|
||||||
#include <NetworkRoster.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <PopUpMenu.h>
|
|
||||||
#include <Slider.h>
|
|
||||||
#include <SpaceLayoutItem.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
#include <TextControl.h>
|
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
#include "WirelessNetworkMenuItem.h"
|
|
||||||
|
|
||||||
|
|
||||||
static const uint32 kMsgApply = 'aply';
|
|
||||||
static const uint32 kMsgRevert = 'rvrt';
|
|
||||||
static const uint32 kMsgClose = 'clse';
|
|
||||||
static const uint32 kMsgField = 'fild';
|
|
||||||
static const uint32 kMsgInfo = 'info';
|
|
||||||
static const uint32 kMsgStaticMode = 'stcm';
|
|
||||||
static const uint32 kMsgDHCPMode = 'dynm';
|
|
||||||
static const uint32 kMsgDisabledMode = 'disa';
|
|
||||||
static const uint32 kMsgChange = 'chng';
|
|
||||||
static const uint32 kMsgNetwork = 'netw';
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
SetupTextControl(BTextControl *control)
|
|
||||||
{
|
|
||||||
control->SetModificationMessage(new BMessage(kMsgChange));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool
|
|
||||||
MatchPattern(const char* string, const char* pattern)
|
|
||||||
{
|
|
||||||
regex_t compiled;
|
|
||||||
bool result = regcomp(&compiled, pattern, REG_NOSUB | REG_EXTENDED) == 0
|
|
||||||
&& regexec(&compiled, string, 0, NULL, 0) == 0;
|
|
||||||
regfree(&compiled);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int32
|
|
||||||
GetDNSListFromString(const char* text, BObjectList<BString>& list)
|
|
||||||
{
|
|
||||||
BString string = text;
|
|
||||||
for (;;) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
return list.CountItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
|
||||||
#define B_TRANSLATION_CONTEXT "EthernetSettingsView"
|
|
||||||
|
|
||||||
|
|
||||||
// A TextControl which doesn't accept any charachter on creation
|
|
||||||
class RestrictedTextControl : public BTextControl {
|
|
||||||
public:
|
|
||||||
RestrictedTextControl(const char* label,
|
|
||||||
const char* initialText,
|
|
||||||
BMessage* message);
|
|
||||||
virtual ~RestrictedTextControl();
|
|
||||||
void AllowChars(const char* chars);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
EthernetSettingsView::EthernetSettingsView()
|
|
||||||
:
|
|
||||||
BView("EthernetSettingsView", 0, NULL),
|
|
||||||
fCurrentSettings(NULL)
|
|
||||||
{
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
|
|
||||||
_GatherInterfaces();
|
|
||||||
|
|
||||||
// build the GUI
|
|
||||||
BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL);
|
|
||||||
SetLayout(rootLayout);
|
|
||||||
|
|
||||||
BGridView* controlsGroup = new BGridView();
|
|
||||||
BGridLayout* layout = controlsGroup->GridLayout();
|
|
||||||
|
|
||||||
// insets
|
|
||||||
float inset = ceilf(be_plain_font->Size() * 0.7);
|
|
||||||
rootLayout->SetInsets(inset, inset, inset, inset);
|
|
||||||
rootLayout->SetSpacing(inset);
|
|
||||||
layout->SetSpacing(inset, inset);
|
|
||||||
|
|
||||||
BPopUpMenu* modeMenu = new BPopUpMenu("modes");
|
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
|
||||||
new BMessage(kMsgStaticMode)));
|
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"),
|
|
||||||
new BMessage(kMsgDHCPMode)));
|
|
||||||
modeMenu->AddSeparatorItem();
|
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"),
|
|
||||||
new BMessage(kMsgDisabledMode)));
|
|
||||||
|
|
||||||
BPopUpMenu* networkMenu = new BPopUpMenu("networks");
|
|
||||||
|
|
||||||
BPopUpMenu* deviceMenu = new BPopUpMenu(B_TRANSLATE("<no adapter>"));
|
|
||||||
fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu);
|
|
||||||
_BuildInterfacesMenu();
|
|
||||||
|
|
||||||
layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0);
|
|
||||||
layout->AddItem(fDeviceMenuField->CreateMenuBarLayoutItem(), 1, 0);
|
|
||||||
|
|
||||||
BStringView* hardwareAddressLabel = new BStringView(
|
|
||||||
"HardwareAddressLabel", B_TRANSLATE("Hardware address:"));
|
|
||||||
fHardwareAddress = new BStringView("HardwareAddress", "");
|
|
||||||
layout->AddView(hardwareAddressLabel, 0, 1);
|
|
||||||
layout->AddView(fHardwareAddress, 1, 1);
|
|
||||||
|
|
||||||
fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), networkMenu);
|
|
||||||
layout->AddItem(fNetworkMenuField->CreateLabelLayoutItem(), 0, 2);
|
|
||||||
layout->AddItem(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 2);
|
|
||||||
|
|
||||||
fTypeMenuField = new BMenuField(B_TRANSLATE("Mode:"), modeMenu);
|
|
||||||
layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 3);
|
|
||||||
layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 3);
|
|
||||||
|
|
||||||
fIPTextControl = new RestrictedTextControl(
|
|
||||||
B_TRANSLATE("IP address:"), "", NULL);
|
|
||||||
SetupTextControl(fIPTextControl);
|
|
||||||
((RestrictedTextControl*)fIPTextControl)->AllowChars("0123456789.");
|
|
||||||
|
|
||||||
BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
|
|
||||||
layoutItem->SetExplicitMinSize(BSize(
|
|
||||||
fIPTextControl->StringWidth("XXX.XXX.XXX.XXX") + inset,
|
|
||||||
B_SIZE_UNSET));
|
|
||||||
|
|
||||||
layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 4);
|
|
||||||
layout->AddItem(layoutItem, 1, 4);
|
|
||||||
|
|
||||||
fNetMaskTextControl = new RestrictedTextControl(
|
|
||||||
B_TRANSLATE("Netmask:"), "", NULL);
|
|
||||||
SetupTextControl(fNetMaskTextControl);
|
|
||||||
layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 5);
|
|
||||||
layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 5);
|
|
||||||
((RestrictedTextControl*)fNetMaskTextControl)->AllowChars("0123456789.");
|
|
||||||
|
|
||||||
fGatewayTextControl = new RestrictedTextControl(
|
|
||||||
B_TRANSLATE("Gateway:"), "", NULL);
|
|
||||||
SetupTextControl(fGatewayTextControl);
|
|
||||||
layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 6);
|
|
||||||
layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 6);
|
|
||||||
((RestrictedTextControl*)fGatewayTextControl)->AllowChars("0123456789.");
|
|
||||||
|
|
||||||
fDNSTextControl = new BTextControl(
|
|
||||||
B_TRANSLATE("DNS:"), "", NULL);
|
|
||||||
SetupTextControl(fDNSTextControl);
|
|
||||||
layout->AddItem(fDNSTextControl->CreateLabelLayoutItem(), 0, 7);
|
|
||||||
layout->AddItem(fDNSTextControl->CreateTextViewLayoutItem(), 1, 7);
|
|
||||||
((RestrictedTextControl*)fDNSTextControl)->AllowChars("0123456789.;, ");
|
|
||||||
fDNSTextControl->SetToolTip(B_TRANSLATE("DNS Servers, comma-separated"));
|
|
||||||
|
|
||||||
fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL);
|
|
||||||
SetupTextControl(fDomainTextControl);
|
|
||||||
layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8);
|
|
||||||
layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8);
|
|
||||||
|
|
||||||
fErrorMessage = new BStringView("error", "");
|
|
||||||
fErrorMessage->SetAlignment(B_ALIGN_LEFT);
|
|
||||||
fErrorMessage->SetFont(be_bold_font);
|
|
||||||
fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
|
||||||
|
|
||||||
layout->AddView(fErrorMessage, 1, 9);
|
|
||||||
|
|
||||||
// button group (TODO: move to window, but take care of
|
|
||||||
// enabling/disabling)
|
|
||||||
BGroupView* buttonGroup = new BGroupView(B_HORIZONTAL);
|
|
||||||
|
|
||||||
fRevertButton = new BButton(B_TRANSLATE("Revert"),
|
|
||||||
new BMessage(kMsgRevert));
|
|
||||||
fRevertButton->SetEnabled(false);
|
|
||||||
buttonGroup->GroupLayout()->AddView(fRevertButton);
|
|
||||||
|
|
||||||
buttonGroup->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
|
|
||||||
|
|
||||||
fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply));
|
|
||||||
fApplyButton->SetEnabled(false);
|
|
||||||
buttonGroup->GroupLayout()->AddView(fApplyButton);
|
|
||||||
|
|
||||||
rootLayout->AddView(controlsGroup);
|
|
||||||
rootLayout->AddView(buttonGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EthernetSettingsView::~EthernetSettingsView()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
fApplyButton->SetTarget(this);
|
|
||||||
fRevertButton->SetTarget(this);
|
|
||||||
fIPTextControl->SetTarget(this);
|
|
||||||
fNetMaskTextControl->SetTarget(this);
|
|
||||||
fGatewayTextControl->SetTarget(this);
|
|
||||||
fDNSTextControl->SetTarget(this);
|
|
||||||
fDomainTextControl->SetTarget(this);
|
|
||||||
fDeviceMenuField->Menu()->SetTargetForItems(this);
|
|
||||||
fNetworkMenuField->Menu()->SetTargetForItems(this);
|
|
||||||
fTypeMenuField->Menu()->SetTargetForItems(this);
|
|
||||||
|
|
||||||
// Display settigs of first adapter on startup, if any
|
|
||||||
_ShowConfiguration(fSettings.ItemAt(0));
|
|
||||||
|
|
||||||
int flags = B_WATCH_NETWORK_INTERFACE_CHANGES;
|
|
||||||
start_watching_network(flags, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::DetachedFromWindow()
|
|
||||||
{
|
|
||||||
stop_watching_network(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
switch (message->what) {
|
|
||||||
case B_NETWORK_MONITOR:
|
|
||||||
{
|
|
||||||
int32 opcode;
|
|
||||||
message->FindInt32("opcode", &opcode);
|
|
||||||
const char* interfaceName;
|
|
||||||
message->FindString("interface", &interfaceName);
|
|
||||||
switch (opcode) {
|
|
||||||
case B_NETWORK_INTERFACE_ADDED:
|
|
||||||
_InterfaceAdded(interfaceName);
|
|
||||||
break;
|
|
||||||
case B_NETWORK_INTERFACE_REMOVED:
|
|
||||||
_InterfaceRemoved(interfaceName);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// TODO: Support interface changed, etc.
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
_BuildInterfacesMenu();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kMsgStaticMode:
|
|
||||||
case kMsgDHCPMode:
|
|
||||||
case kMsgDisabledMode:
|
|
||||||
case kMsgNetwork:
|
|
||||||
_EnableTextControls(message->what == kMsgStaticMode);
|
|
||||||
fApplyButton->SetEnabled(true);
|
|
||||||
fRevertButton->SetEnabled(true);
|
|
||||||
break;
|
|
||||||
case kMsgInfo:
|
|
||||||
{
|
|
||||||
const char* name;
|
|
||||||
if (message->FindString("interface", &name) != B_OK)
|
|
||||||
break;
|
|
||||||
for (int32 i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
Settings* settings = fSettings.ItemAt(i);
|
|
||||||
if (strcmp(settings->Name(), name) == 0) {
|
|
||||||
_ShowConfiguration(settings);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kMsgRevert:
|
|
||||||
_ShowConfiguration(fCurrentSettings);
|
|
||||||
fRevertButton->SetEnabled(false);
|
|
||||||
break;
|
|
||||||
case kMsgApply:
|
|
||||||
{
|
|
||||||
if (_ValidateControl(fIPTextControl)
|
|
||||||
&& _ValidateControl(fNetMaskTextControl)
|
|
||||||
&& (strlen(fGatewayTextControl->Text()) == 0
|
|
||||||
|| _ValidateControl(fGatewayTextControl)))
|
|
||||||
_SaveConfiguration();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kMsgChange:
|
|
||||||
fErrorMessage->SetText("");
|
|
||||||
fApplyButton->SetEnabled(true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BView::MessageReceived(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_GatherInterfaces()
|
|
||||||
{
|
|
||||||
// iterate over all interfaces and retrieve minimal status
|
|
||||||
|
|
||||||
fInterfaces.MakeEmpty();
|
|
||||||
|
|
||||||
BNetworkRoster& roster = BNetworkRoster::Default();
|
|
||||||
BNetworkInterface interface;
|
|
||||||
uint32 cookie = 0;
|
|
||||||
|
|
||||||
while (roster.GetNextInterface(&cookie, interface) == B_OK) {
|
|
||||||
if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0]) {
|
|
||||||
_InterfaceAdded(interface.Name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_BuildInterfacesMenu()
|
|
||||||
{
|
|
||||||
BMenu* menu = fDeviceMenuField->Menu();
|
|
||||||
BMenuItem* marked = menu->FindMarked();
|
|
||||||
BString markedName;
|
|
||||||
if (marked != NULL) {
|
|
||||||
markedName = marked->Label();
|
|
||||||
marked->SetMarked(false);
|
|
||||||
}
|
|
||||||
menu->RemoveItems(0, menu->CountItems(), true);
|
|
||||||
|
|
||||||
for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
|
|
||||||
BString& name = *fInterfaces.ItemAt(i);
|
|
||||||
BString label = name;
|
|
||||||
BMessage* info = new BMessage(kMsgInfo);
|
|
||||||
info->AddString("interface", name.String());
|
|
||||||
BMenuItem* item = new BMenuItem(label.String(), info);
|
|
||||||
menu->AddItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Window() != NULL)
|
|
||||||
menu->SetTargetForItems(this);
|
|
||||||
|
|
||||||
int32 numItems = menu->CountItems();
|
|
||||||
if (numItems > 0) {
|
|
||||||
fDeviceMenuField->Menu()->SetEnabled(true);
|
|
||||||
BMenuItem* item = NULL;
|
|
||||||
if (numItems == 1)
|
|
||||||
item = menu->ItemAt(0);
|
|
||||||
else
|
|
||||||
item = menu->FindItem(markedName.String());
|
|
||||||
if (item != NULL)
|
|
||||||
item->SetMarked(true);
|
|
||||||
} else {
|
|
||||||
fDeviceMenuField->Menu()->SetEnabled(false);
|
|
||||||
_ShowConfiguration((Settings*)NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_InterfaceAdded(const char* name)
|
|
||||||
{
|
|
||||||
fInterfaces.AddItem(new BString(name));
|
|
||||||
fSettings.AddItem(new Settings(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_InterfaceRemoved(const char* name)
|
|
||||||
{
|
|
||||||
BString s;
|
|
||||||
for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
|
|
||||||
if (fInterfaces.ItemAt(i)->Compare(name) == 0) {
|
|
||||||
delete fInterfaces.RemoveItemAt(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32 i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
if (strcmp(fSettings.ItemAt(i)->Name(), name) == 0) {
|
|
||||||
Settings* settings = fSettings.RemoveItemAt(i);
|
|
||||||
if (strcmp(settings->Name(), fCurrentSettings->Name()) == 0)
|
|
||||||
_ShowConfiguration((Settings*)NULL);
|
|
||||||
delete settings;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
|
||||||
{
|
|
||||||
fCurrentSettings = settings;
|
|
||||||
|
|
||||||
// Clear the inputs.
|
|
||||||
fIPTextControl->SetText("");
|
|
||||||
fGatewayTextControl->SetText("");
|
|
||||||
fNetMaskTextControl->SetText("");
|
|
||||||
fDNSTextControl->SetText("");
|
|
||||||
fDomainTextControl->SetText("");
|
|
||||||
|
|
||||||
fTypeMenuField->SetEnabled(settings != NULL);
|
|
||||||
|
|
||||||
bool enableControls = false;
|
|
||||||
BMenuItem* item;
|
|
||||||
|
|
||||||
if (settings != NULL)
|
|
||||||
fHardwareAddress->SetText(settings->HardwareAddress());
|
|
||||||
else
|
|
||||||
fHardwareAddress->SetText("");
|
|
||||||
if (settings == NULL || settings->IsDisabled())
|
|
||||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled"));
|
|
||||||
else if (settings->AutoConfigure())
|
|
||||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP"));
|
|
||||||
else {
|
|
||||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static"));
|
|
||||||
enableControls = true;
|
|
||||||
}
|
|
||||||
if (item != NULL)
|
|
||||||
item->SetMarked(true);
|
|
||||||
|
|
||||||
if (settings == NULL) {
|
|
||||||
if (!fNetworkMenuField->IsHidden(fNetworkMenuField))
|
|
||||||
fNetworkMenuField->Hide();
|
|
||||||
_EnableTextControls(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show/hide networks menu
|
|
||||||
BNetworkDevice device(settings->Name());
|
|
||||||
if (fNetworkMenuField->IsHidden(fNetworkMenuField) && device.IsWireless()) {
|
|
||||||
fNetworkMenuField->Show();
|
|
||||||
Window()->InvalidateLayout();
|
|
||||||
} else if (!fNetworkMenuField->IsHidden(fNetworkMenuField)
|
|
||||||
&& !device.IsWireless()) {
|
|
||||||
fNetworkMenuField->Hide();
|
|
||||||
Window()->InvalidateLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device.IsWireless()) {
|
|
||||||
// Rebuild network menu
|
|
||||||
BMenu* menu = fNetworkMenuField->Menu();
|
|
||||||
menu->RemoveItems(0, menu->CountItems(), true);
|
|
||||||
|
|
||||||
std::set<BNetworkAddress> associated;
|
|
||||||
BNetworkAddress address;
|
|
||||||
uint32 cookie = 0;
|
|
||||||
while (device.GetNextAssociatedNetwork(cookie, address) == B_OK)
|
|
||||||
associated.insert(address);
|
|
||||||
|
|
||||||
wireless_network network;
|
|
||||||
int32 count = 0;
|
|
||||||
cookie = 0;
|
|
||||||
while (device.GetNextNetwork(cookie, network) == B_OK) {
|
|
||||||
BMessage* message = new BMessage(kMsgNetwork);
|
|
||||||
message->AddString("device", device.Name());
|
|
||||||
message->AddString("name", network.name);
|
|
||||||
|
|
||||||
BMenuItem* item = new WirelessNetworkMenuItem(network.name,
|
|
||||||
network.signal_strength,
|
|
||||||
network.authentication_mode, message);
|
|
||||||
if (associated.find(network.address) != associated.end())
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item);
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (count == 0) {
|
|
||||||
BMenuItem* item = new BMenuItem(
|
|
||||||
B_TRANSLATE("<no wireless networks found>"), NULL);
|
|
||||||
item->SetEnabled(false);
|
|
||||||
menu->AddItem(item);
|
|
||||||
} else {
|
|
||||||
BMenuItem* item = new BMenuItem(
|
|
||||||
B_TRANSLATE("Choose automatically"), NULL);
|
|
||||||
if (menu->FindMarked() == NULL)
|
|
||||||
item->SetMarked(true);
|
|
||||||
menu->AddItem(item, 0);
|
|
||||||
menu->AddItem(new BSeparatorItem(), 1);
|
|
||||||
}
|
|
||||||
menu->SetTargetForItems(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
item = fDeviceMenuField->Menu()->FindItem(settings->Name());
|
|
||||||
if (item != NULL)
|
|
||||||
item->SetMarked(true);
|
|
||||||
|
|
||||||
fIPTextControl->SetText(settings->IP());
|
|
||||||
fGatewayTextControl->SetText(settings->Gateway());
|
|
||||||
fNetMaskTextControl->SetText(settings->Netmask());
|
|
||||||
|
|
||||||
BString dns;
|
|
||||||
for (int32 n = 0; n < settings->NameServers().CountItems(); n++) {
|
|
||||||
if (n != 0)
|
|
||||||
dns.Append(", ");
|
|
||||||
dns.Append(settings->NameServers().ItemAt(n)->String());
|
|
||||||
}
|
|
||||||
|
|
||||||
fDNSTextControl->SetText(dns.String());
|
|
||||||
|
|
||||||
fDomainTextControl->SetText(settings->Domain());
|
|
||||||
|
|
||||||
_EnableTextControls(enableControls);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_EnableTextControls(bool enable)
|
|
||||||
{
|
|
||||||
fIPTextControl->SetEnabled(enable);
|
|
||||||
fGatewayTextControl->SetEnabled(enable);
|
|
||||||
fNetMaskTextControl->SetEnabled(enable);
|
|
||||||
fDNSTextControl->SetEnabled(enable);
|
|
||||||
fDomainTextControl->SetEnabled(enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_ApplyControlsToConfiguration()
|
|
||||||
{
|
|
||||||
if (!fCurrentSettings)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fCurrentSettings->SetIP(fIPTextControl->Text());
|
|
||||||
fCurrentSettings->SetNetmask(fNetMaskTextControl->Text());
|
|
||||||
fCurrentSettings->SetGateway(fGatewayTextControl->Text());
|
|
||||||
|
|
||||||
fCurrentSettings->SetAutoConfigure(
|
|
||||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
|
||||||
B_TRANSLATE("DHCP")) == 0);
|
|
||||||
|
|
||||||
fCurrentSettings->SetDisabled(
|
|
||||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
|
||||||
B_TRANSLATE("Disabled")) == 0);
|
|
||||||
|
|
||||||
fCurrentSettings->NameServers().MakeEmpty();
|
|
||||||
|
|
||||||
GetDNSListFromString(fDNSTextControl->Text(),
|
|
||||||
fCurrentSettings->NameServers());
|
|
||||||
|
|
||||||
fCurrentSettings->SetDomain(fDomainTextControl->Text());
|
|
||||||
|
|
||||||
fApplyButton->SetEnabled(false);
|
|
||||||
fRevertButton->SetEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_SaveConfiguration()
|
|
||||||
{
|
|
||||||
_ApplyControlsToConfiguration();
|
|
||||||
_SaveDNSConfiguration();
|
|
||||||
_SaveAdaptersConfiguration();
|
|
||||||
if (fCurrentSettings->AutoConfigure())
|
|
||||||
_TriggerAutoConfig(fCurrentSettings->Name());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_SaveDNSConfiguration()
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append("network/resolv.conf");
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
|
|
||||||
if (file.InitCheck() != B_OK) {
|
|
||||||
fprintf(stderr, "failed to open %s for writing: %s\n", path.Path(),
|
|
||||||
strerror(file.InitCheck()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BString content("# Generated by Network Preflet\n");
|
|
||||||
// loop over all adapters
|
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
Settings* settings = fSettings.ItemAt(i);
|
|
||||||
for (int j = 0; j < settings->NameServers().CountItems(); j++) {
|
|
||||||
if (settings->NameServers().ItemAt(j)->Length() > 0) {
|
|
||||||
content << "nameserver\t"
|
|
||||||
<< settings->NameServers().ItemAt(j)->String()
|
|
||||||
<< "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strlen(settings->Domain()) > 0) {
|
|
||||||
content << "domain\t"
|
|
||||||
<< settings->Domain()
|
|
||||||
<< "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.Write(content.String(), content.Length());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EthernetSettingsView::_SaveAdaptersConfiguration()
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
status_t status = _GetPath("interfaces", path);
|
|
||||||
if (status < B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FILE* fp = NULL;
|
|
||||||
// loop over all adapters. open the settings file only once,
|
|
||||||
// append the settins of each non-autoconfiguring adapter
|
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
|
||||||
Settings* settings = fSettings.ItemAt(i);
|
|
||||||
|
|
||||||
std::vector<wireless_network> networks = settings->WirelessNetworks();
|
|
||||||
if (settings->AutoConfigure() && networks.empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
|
||||||
fp = fopen(path.Path(), "w");
|
|
||||||
if (fp == NULL) {
|
|
||||||
fprintf(stderr, "failed to open file %s to write "
|
|
||||||
"configuration: %s\n", path.Path(), strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp, "interface %s {\n",
|
|
||||||
settings->Name());
|
|
||||||
|
|
||||||
if (settings->IsDisabled())
|
|
||||||
fprintf(fp, "\tdisabled\ttrue\n");
|
|
||||||
else if (!settings->AutoConfigure()) {
|
|
||||||
fprintf(fp, "\taddress {\n");
|
|
||||||
fprintf(fp, "\t\tfamily\tinet\n");
|
|
||||||
fprintf(fp, "\t\taddress\t%s\n", settings->IP());
|
|
||||||
fprintf(fp, "\t\tgateway\t%s\n", settings->Gateway());
|
|
||||||
fprintf(fp, "\t\tmask\t%s\n", settings->Netmask());
|
|
||||||
fprintf(fp, "\t}\n");
|
|
||||||
}
|
|
||||||
if (!networks.empty()) {
|
|
||||||
for (size_t index = 0; index < networks.size(); index++) {
|
|
||||||
wireless_network& network = networks[index];
|
|
||||||
fprintf(fp, "\tnetwork %s {\n", network.name);
|
|
||||||
fprintf(fp, "\t\tmac\t%s\n",
|
|
||||||
network.address.ToString().String());
|
|
||||||
fprintf(fp, "\t}\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(fp, "}\n\n");
|
|
||||||
}
|
|
||||||
if (fp) {
|
|
||||||
printf("%s saved.\n", path.Path());
|
|
||||||
fclose(fp);
|
|
||||||
} else {
|
|
||||||
// all configuration is DHCP, so delete interfaces file.
|
|
||||||
remove(path.Path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
EthernetSettingsView::_TriggerAutoConfig(const char* device)
|
|
||||||
{
|
|
||||||
BNetworkInterface interface(device);
|
|
||||||
status_t status = interface.AutoConfigure(AF_INET);
|
|
||||||
|
|
||||||
if (status == B_BAD_PORT_ID) {
|
|
||||||
BAlert* alert = new BAlert("error", B_TRANSLATE("The net_server needs to run for "
|
|
||||||
"the auto configuration!"), B_TRANSLATE("OK"));
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
alert->Go();
|
|
||||||
} else if (status != B_OK) {
|
|
||||||
BString errorMessage(B_TRANSLATE("Auto-configuring failed: "));
|
|
||||||
errorMessage << strerror(status);
|
|
||||||
BAlert* alert = new BAlert("error", errorMessage.String(), "OK");
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
|
||||||
alert->Go();
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
EthernetSettingsView::_GetPath(const char* name, BPath& path)
|
|
||||||
{
|
|
||||||
if (find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, true) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append("network");
|
|
||||||
create_directory(path.Path(), 0755);
|
|
||||||
|
|
||||||
if (name != NULL)
|
|
||||||
path.Append(name);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
EthernetSettingsView::_ValidateControl(BTextControl* control)
|
|
||||||
{
|
|
||||||
static const char* pattern = "^(25[0-5]|2[0-4][0-9]|[01][0-9]{2}|[0-9]"
|
|
||||||
"{1,2})(\\.(25[0-5]|2[0-4][0-9]|[01][0-9]{2}|[0-9]{1,2})){3}$";
|
|
||||||
|
|
||||||
if (control->IsEnabled() && !MatchPattern(control->Text(), pattern)) {
|
|
||||||
control->MakeFocus();
|
|
||||||
BString errorMessage;
|
|
||||||
|
|
||||||
if (control == fIPTextControl) {
|
|
||||||
errorMessage << B_TRANSLATE("IP address is invalid");
|
|
||||||
} else if (control == fNetMaskTextControl) {
|
|
||||||
errorMessage << B_TRANSLATE("Netmask is invalid");
|
|
||||||
} else if (control == fGatewayTextControl) {
|
|
||||||
errorMessage << B_TRANSLATE("Gateway is invalid");
|
|
||||||
} else if (control == fDNSTextControl) {
|
|
||||||
errorMessage << B_TRANSLATE("DNS list is invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
fErrorMessage->SetText(errorMessage.String());
|
|
||||||
beep();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// IPV4AddressTextControl
|
|
||||||
RestrictedTextControl::RestrictedTextControl(const char* label,
|
|
||||||
const char* initialText, BMessage* message)
|
|
||||||
:
|
|
||||||
BTextControl(label, initialText, message)
|
|
||||||
{
|
|
||||||
// TODO: Would be nice to have a formatted input control
|
|
||||||
// TODO: This doesn't block multi-byte characters
|
|
||||||
for (uint32 i = (uint32)0; i <= 255; i++)
|
|
||||||
TextView()->DisallowChar(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* virtual */
|
|
||||||
RestrictedTextControl::~RestrictedTextControl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
RestrictedTextControl::AllowChars(const char* chars)
|
|
||||||
{
|
|
||||||
int numChars = strlen(chars);
|
|
||||||
for (int i = 0; i < numChars; i++)
|
|
||||||
TextView()->AllowChar((uint32)chars[i]);
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* Axel Dörfler
|
|
||||||
* Hugo Santos
|
|
||||||
* Vegard Wærp
|
|
||||||
*/
|
|
||||||
#ifndef ETHERNET_SETTINGS_VIEW_H
|
|
||||||
#define ETHERNET_SETTINGS_VIEW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <ObjectList.h>
|
|
||||||
#include <View.h>
|
|
||||||
|
|
||||||
#include <posix/regex.h>
|
|
||||||
|
|
||||||
|
|
||||||
class BButton;
|
|
||||||
class BMenuField;
|
|
||||||
class BPath;
|
|
||||||
class BTextControl;
|
|
||||||
class BStringView;
|
|
||||||
class Settings;
|
|
||||||
|
|
||||||
|
|
||||||
class EthernetSettingsView : public BView {
|
|
||||||
public:
|
|
||||||
EthernetSettingsView();
|
|
||||||
virtual ~EthernetSettingsView();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void DetachedFromWindow();
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void _GatherInterfaces();
|
|
||||||
void _BuildInterfacesMenu();
|
|
||||||
void _InterfaceAdded(const char* name);
|
|
||||||
void _InterfaceRemoved(const char* name);
|
|
||||||
void _ShowConfiguration(Settings* settings);
|
|
||||||
void _EnableTextControls(bool enable);
|
|
||||||
void _SaveConfiguration();
|
|
||||||
void _SaveDNSConfiguration();
|
|
||||||
void _SaveAdaptersConfiguration();
|
|
||||||
void _ApplyControlsToConfiguration();
|
|
||||||
status_t _GetPath(const char* name, BPath& path);
|
|
||||||
status_t _TriggerAutoConfig(const char* device);
|
|
||||||
|
|
||||||
bool _ValidateControl(BTextControl* control);
|
|
||||||
private:
|
|
||||||
|
|
||||||
BButton* fApplyButton;
|
|
||||||
BButton* fRevertButton;
|
|
||||||
// TODO: buttons should be moved to window instead
|
|
||||||
BMenuField* fDeviceMenuField;
|
|
||||||
BStringView* fHardwareAddress;
|
|
||||||
BMenuField* fNetworkMenuField;
|
|
||||||
BMenuField* fTypeMenuField;
|
|
||||||
BTextControl* fIPTextControl;
|
|
||||||
BTextControl* fNetMaskTextControl;
|
|
||||||
BTextControl* fGatewayTextControl;
|
|
||||||
|
|
||||||
BTextControl* fDNSTextControl;
|
|
||||||
BTextControl* fDomainTextControl;
|
|
||||||
|
|
||||||
BStringView* fErrorMessage;
|
|
||||||
|
|
||||||
// TODO: DNS settings do not belong here, do they?
|
|
||||||
BObjectList<BString> fInterfaces;
|
|
||||||
// TODO: the view should not know about the interfaces,
|
|
||||||
// it should only display the given interface, move
|
|
||||||
// one level up.
|
|
||||||
BObjectList<Settings> fSettings;
|
|
||||||
// TODO: the view should not know about a list
|
|
||||||
// of settings, instead it should be configured
|
|
||||||
// to a specific setting from the code one level up
|
|
||||||
Settings* fCurrentSettings;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* ETHERNET_SETTINGS_VIEW_H */
|
|
||||||
@@ -1,26 +1,22 @@
|
|||||||
SubDir HAIKU_TOP src preferences network ;
|
SubDir HAIKU_TOP src tests kits net preflet ;
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ;
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ;
|
||||||
|
|
||||||
UsePrivateHeaders net shared ;
|
Preference NetworkSetup :
|
||||||
|
NetworkSetup.cpp
|
||||||
Preference Network :
|
NetworkSetupWindow.cpp
|
||||||
NetworkApp.cpp
|
NetworkSetupProfile.cpp
|
||||||
NetworkWindow.cpp
|
NetworkSetupAddOn.cpp
|
||||||
EthernetSettingsView.cpp
|
|
||||||
Settings.cpp
|
|
||||||
|
|
||||||
# from NetworkStatus
|
# from NetworkStatus
|
||||||
RadioView.cpp
|
RadioView.cpp
|
||||||
WirelessNetworkMenuItem.cpp
|
WirelessNetworkMenuItem.cpp
|
||||||
|
|
||||||
: be $(HAIKU_NETWORK_LIBS) [ TargetLibstdc++ ] [ TargetLibsupc++ ]
|
: be root [ TargetLibstdc++ ] localestub
|
||||||
localestub libbnetapi.so
|
: NetworkSetup.rdef
|
||||||
: Network.rdef
|
|
||||||
;
|
;
|
||||||
|
|
||||||
DoCatalogs Network :
|
SubInclude HAIKU_TOP src tests kits net preflet InterfacesAddOn ;
|
||||||
x-vnd.Haiku-Network
|
SubInclude HAIKU_TOP src tests kits net preflet ServicesAddOn ;
|
||||||
:
|
#SubInclude HAIKU_TOP src tests kits net preflet DummyAddOn ;
|
||||||
EthernetSettingsView.cpp
|
#SubInclude HAIKU_TOP src tests kits net preflet MultipleAddOns ;
|
||||||
NetworkWindow.cpp
|
#SubInclude HAIKU_TOP src tests kits net preflet DialUpAddOn ;
|
||||||
;
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
|
|
||||||
resource app_signature "application/x-vnd.Haiku-Network";
|
|
||||||
|
|
||||||
resource app_name_catalog_entry "x-vnd.Haiku-Network:System name:Network";
|
|
||||||
|
|
||||||
resource app_flags B_SINGLE_LAUNCH;
|
|
||||||
|
|
||||||
resource app_version {
|
|
||||||
major = 1,
|
|
||||||
middle = 0,
|
|
||||||
minor = 0,
|
|
||||||
|
|
||||||
variety = B_APPV_DEVELOPMENT,
|
|
||||||
internal = 0,
|
|
||||||
|
|
||||||
short_info = "Network",
|
|
||||||
long_info = "Network ©2007-2009 Haiku"
|
|
||||||
};
|
|
||||||
|
|
||||||
resource vector_icon {
|
|
||||||
$"6E6369660B0500020016023A3D24339506B715A93DDB134A79084A1A1100D7FF"
|
|
||||||
$"B80594020016023A3D24339506B715A93DDB134A79084A1A1100D2FF8505C402"
|
|
||||||
$"0016023A692E36692FBA2ECD3E2ECC4B89A4496318005CFF83020016023C8000"
|
|
||||||
$"0000000000003C00004AC00049000000F4FFDB03A9FF00020106033C00000000"
|
|
||||||
$"000000003C00004680004680000B9EEDFF2567CEFFFF0473B3020106033C0000"
|
|
||||||
$"0000000000003C000046800046800000B9FF97BE05D65EFF04994304016E0F0A"
|
|
||||||
$"044C60516060505C4E02043334BD6D34B7B434263926BBDC26BE0E333EB7B43E"
|
|
||||||
$"BD6D3E403940BE0E40BBDC0A0651365A395A504C5E425842400A084C444C5EC3"
|
|
||||||
$"AFCB27C3AFC72B4450C15AC9CB425842400A04C1EFC6634450C15AC9CBC1DECA"
|
|
||||||
$"180A04C317C6E8C1EFC663C1DECA18C316CACE0A04C3AFCB27C3AFC72BC317C6"
|
|
||||||
$"E8C316CACE0A0451365A394C4442400A044C445A395A504C5E0A04484648484A"
|
|
||||||
$"C3234AC2570404BE404A3246324A323E4236423C4232373202042E22BB3722B5"
|
|
||||||
$"F022222E22B5F022BB372E3AB5F03ABB373A3A2E3ABB373AB5F00608BFDBB506"
|
|
||||||
$"B560B506B560B443B638222E22B75722BAB3B717BD1FB52DBC80B717BD1F2836"
|
|
||||||
$"28322A34263024302E2828282A2826060CA2EBAF2E28B98632263428302E302C"
|
|
||||||
$"303036323436BBB3BC32BBB3BC32BCB6BB513A2E3ABA053AB668B9EDB3FDBBE9"
|
|
||||||
$"B493B9EDB3FD2E2430260614BFDDAFABE82E22B90C22B72A22B506B560B5E6B4"
|
|
||||||
$"68B506B56028282826282A242E30283226302A3436B717BD1FB717BD1FB78EBD"
|
|
||||||
$"452E3AB80E3AB9C53ABBB3BC32BADCBCEBBBB3BC3234363632302E3030302C34"
|
|
||||||
$"283226B953282E30262E24B9EDB3FDB9EDB3FDB980B3DD0D0A0A020001000A0A"
|
|
||||||
$"010A124000000000000000003FB6DB42000043249201178400040A00030A020B"
|
|
||||||
$"1001178400040A010103000A020104000A030105000A040106000A060107000A"
|
|
||||||
$"050108000A0301091001178100040A070109000A08010E000A09020C0D00"
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2007 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* With code from:
|
|
||||||
* Axel Dörfler
|
|
||||||
* Hugo Santos
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "NetworkApp.h"
|
|
||||||
#include "NetworkWindow.h"
|
|
||||||
|
|
||||||
NetworkApp::NetworkApp()
|
|
||||||
: BApplication("application/x-vnd.Haiku-Network")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkApp::~NetworkApp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
NetworkApp::ReadyToRun()
|
|
||||||
{
|
|
||||||
fEthWindow = new NetworkWindow();
|
|
||||||
fEthWindow->Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
NetworkApp app;
|
|
||||||
app.Run();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2007 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* With code from:
|
|
||||||
* Axel Dorfler
|
|
||||||
* Hugo Santos
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NETWORK_APP_H
|
|
||||||
#define NETWORK_APP_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <Application.h>
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <Locale.h>
|
|
||||||
|
|
||||||
#include "NetworkWindow.h"
|
|
||||||
|
|
||||||
class NetworkApp : public BApplication {
|
|
||||||
public:
|
|
||||||
NetworkApp();
|
|
||||||
virtual ~NetworkApp();
|
|
||||||
|
|
||||||
virtual void ReadyToRun();
|
|
||||||
private:
|
|
||||||
NetworkWindow *fEthWindow;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* NETWORK_APP_H */
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "NetworkWindow.h"
|
|
||||||
|
|
||||||
#include <Application.h>
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <GroupLayout.h>
|
|
||||||
#include <Locale.h>
|
|
||||||
|
|
||||||
#include "EthernetSettingsView.h"
|
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
|
||||||
#define B_TRANSLATION_CONTEXT "NetworkWindow"
|
|
||||||
|
|
||||||
|
|
||||||
NetworkWindow::NetworkWindow()
|
|
||||||
:
|
|
||||||
BWindow(BRect(50, 50, 269, 302), B_TRANSLATE_SYSTEM_NAME("Network"),
|
|
||||||
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
|
|
||||||
| B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_QUIT_ON_WINDOW_CLOSE)
|
|
||||||
{
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
|
||||||
GetLayout()->AddView(new EthernetSettingsView());
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
*/
|
|
||||||
#ifndef NETWORK_WINDOW_H
|
|
||||||
#define NETWORK_WINDOW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <Window.h>
|
|
||||||
|
|
||||||
|
|
||||||
class NetworkWindow : public BWindow {
|
|
||||||
public:
|
|
||||||
NetworkWindow();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NETWORK_WINDOW_H
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* Axel Dörfler, [email protected].
|
|
||||||
* Vegard Wærp, [email protected]
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <resolv.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sockio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <driver_settings.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <NetworkDevice.h>
|
|
||||||
#include <NetworkInterface.h>
|
|
||||||
#include <NetworkRoster.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <String.h>
|
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings(const char* name)
|
|
||||||
:
|
|
||||||
fAuto(true),
|
|
||||||
fDisabled(false),
|
|
||||||
fNameServers(5, true)
|
|
||||||
{
|
|
||||||
fName = name;
|
|
||||||
|
|
||||||
ReadConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Settings::~Settings()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! Returns all associated wireless networks. */
|
|
||||||
std::vector<wireless_network>
|
|
||||||
Settings::WirelessNetworks()
|
|
||||||
{
|
|
||||||
std::vector<wireless_network> networks;
|
|
||||||
|
|
||||||
BNetworkDevice device(fName);
|
|
||||||
if (device.IsWireless()) {
|
|
||||||
wireless_network wirelessNetwork;
|
|
||||||
uint32 cookie = 0;
|
|
||||||
while (device.GetNextAssociatedNetwork(cookie, wirelessNetwork) == B_OK)
|
|
||||||
networks.push_back(wirelessNetwork);
|
|
||||||
}
|
|
||||||
|
|
||||||
return networks;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Settings::ReadConfiguration()
|
|
||||||
{
|
|
||||||
BNetworkInterface interface(fName);
|
|
||||||
BNetworkAddress hardwareAddress;
|
|
||||||
if (interface.GetHardwareAddress(hardwareAddress) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fHardwareAddress = hardwareAddress.ToString();
|
|
||||||
BNetworkInterfaceAddress address;
|
|
||||||
|
|
||||||
// TODO: We only get the first address
|
|
||||||
if (interface.GetAddressAt(0, address) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fIP = address.Address().ToString();
|
|
||||||
fNetmask = address.Mask().ToString();
|
|
||||||
|
|
||||||
int family = AF_INET;
|
|
||||||
if (address.Address().Family() != AF_UNSPEC)
|
|
||||||
family = address.Address().Family();
|
|
||||||
|
|
||||||
BNetworkAddress gatewayAddress;
|
|
||||||
if (interface.GetDefaultRoute(family, gatewayAddress) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fGateway = gatewayAddress.ToString();
|
|
||||||
|
|
||||||
uint32 flags = interface.Flags();
|
|
||||||
|
|
||||||
fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
|
||||||
fDisabled = (flags & IFF_UP) == 0;
|
|
||||||
|
|
||||||
// read resolv.conf for the dns.
|
|
||||||
fNameServers.MakeEmpty();
|
|
||||||
|
|
||||||
res_init();
|
|
||||||
res_state state = __res_state();
|
|
||||||
|
|
||||||
if (state != NULL) {
|
|
||||||
for (int i = 0; i < state->nscount; i++) {
|
|
||||||
fNameServers.AddItem(
|
|
||||||
new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
|
|
||||||
}
|
|
||||||
fDomain = state->dnsrch[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Andre Alves Garzia, [email protected]
|
|
||||||
* Vegard Wærp, [email protected]
|
|
||||||
*/
|
|
||||||
#ifndef SETTINGS_H
|
|
||||||
#define SETTINGS_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <NetworkDevice.h>
|
|
||||||
#include <ObjectList.h>
|
|
||||||
#include <String.h>
|
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
|
||||||
public:
|
|
||||||
Settings(const char* name);
|
|
||||||
virtual ~Settings();
|
|
||||||
|
|
||||||
void SetIP(const BString& ip)
|
|
||||||
{ fIP = ip; }
|
|
||||||
void SetGateway(const BString& ip)
|
|
||||||
{ fGateway = ip; }
|
|
||||||
void SetNetmask(const BString& ip)
|
|
||||||
{ fNetmask = ip; }
|
|
||||||
void SetDomain(const BString& domain)
|
|
||||||
{ fDomain = domain; }
|
|
||||||
void SetAutoConfigure(bool autoConfigure)
|
|
||||||
{ fAuto = autoConfigure; }
|
|
||||||
void SetDisabled(bool disabled)
|
|
||||||
{ fDisabled = disabled; }
|
|
||||||
|
|
||||||
const char* HardwareAddress() {
|
|
||||||
return fHardwareAddress.String();
|
|
||||||
}
|
|
||||||
const char* IP() { return fIP.String(); }
|
|
||||||
const char* Gateway() { return fGateway.String(); }
|
|
||||||
const char* Netmask() { return fNetmask.String(); }
|
|
||||||
const char* Name() { return fName.String(); }
|
|
||||||
const char* Domain() { return fDomain.String(); }
|
|
||||||
bool AutoConfigure() { return fAuto; }
|
|
||||||
bool IsDisabled() { return fDisabled; }
|
|
||||||
|
|
||||||
std::vector<wireless_network> WirelessNetworks();
|
|
||||||
|
|
||||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
|
||||||
|
|
||||||
void ReadConfiguration();
|
|
||||||
|
|
||||||
private:
|
|
||||||
BString fHardwareAddress;
|
|
||||||
BString fIP;
|
|
||||||
BString fGateway;
|
|
||||||
BString fNetmask;
|
|
||||||
BString fName;
|
|
||||||
BString fDomain;
|
|
||||||
bool fAuto;
|
|
||||||
bool fDisabled;
|
|
||||||
BObjectList<BString> fNameServers;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* SETTINGS_H */
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
SubDir HAIKU_TOP src tests kits net preflet ;
|
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ;
|
|
||||||
|
|
||||||
Preference NetworkSetup :
|
|
||||||
NetworkSetup.cpp
|
|
||||||
NetworkSetupWindow.cpp
|
|
||||||
NetworkSetupProfile.cpp
|
|
||||||
NetworkSetupAddOn.cpp
|
|
||||||
|
|
||||||
# from NetworkStatus
|
|
||||||
RadioView.cpp
|
|
||||||
WirelessNetworkMenuItem.cpp
|
|
||||||
|
|
||||||
: be root [ TargetLibstdc++ ] localestub
|
|
||||||
: NetworkSetup.rdef
|
|
||||||
;
|
|
||||||
|
|
||||||
SubInclude HAIKU_TOP src tests kits net preflet InterfacesAddOn ;
|
|
||||||
SubInclude HAIKU_TOP src tests kits net preflet ServicesAddOn ;
|
|
||||||
#SubInclude HAIKU_TOP src tests kits net preflet DummyAddOn ;
|
|
||||||
#SubInclude HAIKU_TOP src tests kits net preflet MultipleAddOns ;
|
|
||||||
#SubInclude HAIKU_TOP src tests kits net preflet DialUpAddOn ;
|
|
||||||
Reference in New Issue
Block a user