Added IPv4Interface add-on for Network preferences.
* Took over most code from the former InterfacesAddOn, and moved it to where it should be. * However, it doesn't work yet at all.
This commit is contained in:
parent
03242441a6
commit
85fb1470bf
@ -9,6 +9,7 @@ SubInclude HAIKU_TOP src add-ons kernel ;
|
||||
SubInclude HAIKU_TOP src add-ons locale ;
|
||||
SubInclude HAIKU_TOP src add-ons mail_daemon ;
|
||||
SubInclude HAIKU_TOP src add-ons media ;
|
||||
SubInclude HAIKU_TOP src add-ons network_settings ;
|
||||
SubInclude HAIKU_TOP src add-ons print ;
|
||||
SubInclude HAIKU_TOP src add-ons screen_savers ;
|
||||
SubInclude HAIKU_TOP src add-ons translators ;
|
||||
|
4
src/add-ons/network_settings/Jamfile
Normal file
4
src/add-ons/network_settings/Jamfile
Normal file
@ -0,0 +1,4 @@
|
||||
SubDir HAIKU_TOP src add-ons network_settings ;
|
||||
|
||||
SubInclude HAIKU_TOP src add-ons network_settings ipv4 ;
|
||||
#SubInclude HAIKU_TOP src add-ons network_settings ipv6 ;
|
148
src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp
Normal file
148
src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, <axeld@pinc-software.de>
|
||||
*/
|
||||
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <NetworkSettingsAddOn.h>
|
||||
#include <StringItem.h>
|
||||
|
||||
#include "InterfaceAddressView.h"
|
||||
|
||||
|
||||
using namespace BNetworkKit;
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "IPv4InterfaceAddOn"
|
||||
|
||||
|
||||
class IPv4InterfaceAddOn : public BNetworkSettingsAddOn {
|
||||
public:
|
||||
IPv4InterfaceAddOn(image_id image);
|
||||
virtual ~IPv4InterfaceAddOn();
|
||||
|
||||
virtual BNetworkSettingsInterfaceItem*
|
||||
CreateNextInterfaceItem(uint32& cookie,
|
||||
const char* interface);
|
||||
};
|
||||
|
||||
|
||||
class IPv4InterfaceItem : public BNetworkSettingsInterfaceItem {
|
||||
public:
|
||||
IPv4InterfaceItem(const char* interface);
|
||||
virtual ~IPv4InterfaceItem();
|
||||
|
||||
virtual BListItem* ListItem();
|
||||
virtual BView* View();
|
||||
|
||||
virtual status_t Apply();
|
||||
virtual status_t Revert();
|
||||
virtual bool IsRevertable();
|
||||
|
||||
private:
|
||||
BStringItem* fItem;
|
||||
InterfaceAddressView*
|
||||
fView;
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
IPv4InterfaceItem::IPv4InterfaceItem(const char* interface)
|
||||
:
|
||||
BNetworkSettingsInterfaceItem(interface),
|
||||
fItem(new BStringItem(B_TRANSLATE("IPv4"))),
|
||||
fView(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IPv4InterfaceItem::~IPv4InterfaceItem()
|
||||
{
|
||||
if (fView->Parent() == NULL)
|
||||
delete fView;
|
||||
|
||||
delete fItem;
|
||||
}
|
||||
|
||||
|
||||
BListItem*
|
||||
IPv4InterfaceItem::ListItem()
|
||||
{
|
||||
return fItem;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
IPv4InterfaceItem::View()
|
||||
{
|
||||
if (fView == NULL) {
|
||||
// TODO!
|
||||
fView = new InterfaceAddressView(AF_INET, Interface());
|
||||
}
|
||||
return fView;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
IPv4InterfaceItem::Apply()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
IPv4InterfaceItem::Revert()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
IPv4InterfaceItem::IsRevertable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
IPv4InterfaceAddOn::IPv4InterfaceAddOn(image_id image)
|
||||
:
|
||||
BNetworkSettingsAddOn(image)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IPv4InterfaceAddOn::~IPv4InterfaceAddOn()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BNetworkSettingsInterfaceItem*
|
||||
IPv4InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie,
|
||||
const char* interface)
|
||||
{
|
||||
if (cookie++ == 0)
|
||||
return new IPv4InterfaceItem(interface);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
extern "C"
|
||||
BNetworkSettingsAddOn*
|
||||
instantiate_network_settings_add_on(image_id image)
|
||||
{
|
||||
return new IPv4InterfaceAddOn(image);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2013 Haiku, Inc. All rights reserved.
|
||||
* Copyright 2004-2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
|
||||
#include "InterfaceAddressView.h"
|
||||
#include "NetworkSettings.h"
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
@ -27,15 +26,22 @@
|
||||
#define B_TRANSLATION_CONTEXT "IntefaceAddressView"
|
||||
|
||||
|
||||
enum {
|
||||
M_MODE_AUTO = 'iato',
|
||||
M_MODE_STATIC = 'istc',
|
||||
M_MODE_OFF = 'ioff'
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - InterfaceAddressView
|
||||
|
||||
|
||||
InterfaceAddressView::InterfaceAddressView(int family,
|
||||
NetworkSettings* settings)
|
||||
const char* interface)
|
||||
:
|
||||
BGroupView(B_VERTICAL),
|
||||
fSettings(settings),
|
||||
fFamily(family)
|
||||
fFamily(family),
|
||||
fInterface(interface)
|
||||
{
|
||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||
|
||||
@ -52,7 +58,7 @@ InterfaceAddressView::InterfaceAddressView(int family,
|
||||
fModePopUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Automatic"),
|
||||
new BMessage(M_MODE_AUTO)));
|
||||
}
|
||||
|
||||
|
||||
fModePopUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
||||
new BMessage(M_MODE_STATIC)));
|
||||
fModePopUpMenu->AddSeparatorItem();
|
||||
@ -175,6 +181,8 @@ InterfaceAddressView::Revert()
|
||||
{
|
||||
// Populate address fields with current settings
|
||||
|
||||
// TODO!
|
||||
/*
|
||||
int32 mode;
|
||||
if (fSettings->AutoConfigure(fFamily)) {
|
||||
mode = M_MODE_AUTO;
|
||||
@ -199,7 +207,7 @@ InterfaceAddressView::Revert()
|
||||
fNetmaskField->SetText(fSettings->Netmask(fFamily));
|
||||
fGatewayField->SetText(fSettings->Gateway(fFamily));
|
||||
}
|
||||
|
||||
*/
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -210,11 +218,11 @@ InterfaceAddressView::Save()
|
||||
BMenuItem* item = fModePopUpMenu->FindMarked();
|
||||
if (item == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
/*
|
||||
fSettings->SetIP(fFamily, fAddressField->Text());
|
||||
fSettings->SetNetmask(fFamily, fNetmaskField->Text());
|
||||
fSettings->SetGateway(fFamily, fGatewayField->Text());
|
||||
fSettings->SetAutoConfigure(fFamily, item->Command() == M_MODE_AUTO);
|
||||
|
||||
*/
|
||||
return B_OK;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2013 Haiku, Inc. All rights reserved.
|
||||
* Copyright 2004-2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -10,16 +10,8 @@
|
||||
#define INTERFACE_ADDRESS_VIEW_H
|
||||
|
||||
|
||||
#include "NetworkSettings.h"
|
||||
|
||||
#include <GroupView.h>
|
||||
|
||||
|
||||
enum {
|
||||
M_MODE_AUTO = 'iato',
|
||||
M_MODE_STATIC = 'istc',
|
||||
M_MODE_OFF = 'ioff'
|
||||
};
|
||||
#include <NetworkInterface.h>
|
||||
|
||||
|
||||
class BMenuField;
|
||||
@ -28,10 +20,11 @@ class BPopUpMenu;
|
||||
class BRect;
|
||||
class BTextControl;
|
||||
|
||||
|
||||
class InterfaceAddressView : public BGroupView {
|
||||
public:
|
||||
InterfaceAddressView(int family,
|
||||
NetworkSettings* settings);
|
||||
const char* interface);
|
||||
virtual ~InterfaceAddressView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
@ -44,8 +37,8 @@ private:
|
||||
void _EnableFields(bool enable);
|
||||
void _ShowFields(bool show);
|
||||
|
||||
NetworkSettings* fSettings;
|
||||
int fFamily;
|
||||
BNetworkInterface fInterface;
|
||||
|
||||
BPopUpMenu* fModePopUpMenu;
|
||||
BMenuField* fModeField;
|
25
src/add-ons/network_settings/ipv4/Jamfile
Normal file
25
src/add-ons/network_settings/ipv4/Jamfile
Normal file
@ -0,0 +1,25 @@
|
||||
SubDir HAIKU_TOP src add-ons network_settings ipv4 ;
|
||||
|
||||
#UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] ;
|
||||
#UseHeaders [ FDirName $(HAIKU_TOP) src servers net ] : true ;
|
||||
|
||||
UsePublicHeaders [ FDirName add-ons network_settings ] ;
|
||||
UsePrivateHeaders shared ;
|
||||
|
||||
|
||||
AddResources Interfaces :
|
||||
InterfacesIcons.rdef
|
||||
;
|
||||
|
||||
Addon IPv4Interface :
|
||||
IPv4InterfaceAddOn.cpp
|
||||
InterfaceAddressView.cpp
|
||||
|
||||
: be bnetapi libshared.a <nogrist>Network [ TargetLibsupc++ ]
|
||||
[ TargetLibstdc++ ] localestub
|
||||
;
|
||||
|
||||
DoCatalogs IPv4Interface : x-vnd.Haiku-IPv4Interface :
|
||||
IPv4InterfaceAddOn.cpp
|
||||
InterfaceAddressView.cpp
|
||||
;
|
@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2013 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus
|
||||
* Axel Dörfler
|
||||
* Andre Alves Garzia, andre@andregarzia.com
|
||||
* Alexander von Gluck, kallisti5@unixzen.com
|
||||
* Philippe Houdoin
|
||||
* Fredrik Modéen
|
||||
* Philippe Saint-Pierre
|
||||
* Hugo Santos
|
||||
* John Scipione, jscipione@gmail.com
|
||||
*/
|
||||
|
||||
|
||||
#include "InterfacesAddOn.h"
|
||||
#include "InterfaceView.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Directory.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
#include <Path.h>
|
||||
#include <ScrollView.h>
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "InterfacesAddOn"
|
||||
|
||||
|
||||
NetworkSetupAddOn*
|
||||
get_nth_addon(image_id image, int index)
|
||||
{
|
||||
if (index == 0)
|
||||
return new InterfacesAddOn(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
InterfacesAddOn::InterfacesAddOn(image_id image)
|
||||
:
|
||||
NetworkSetupAddOn(image),
|
||||
BBox(NULL, B_NAVIGABLE_JUMP, B_NO_BORDER),
|
||||
fListView(NULL)
|
||||
{
|
||||
SetName("Interfaces");
|
||||
}
|
||||
|
||||
|
||||
InterfacesAddOn::~InterfacesAddOn()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
InterfacesAddOn::CreateView()
|
||||
{
|
||||
// Construct the ListView
|
||||
fListView = new InterfacesListView("interfaces");
|
||||
fListView->SetSelectionMessage(new BMessage(kMsgInterfaceSelected));
|
||||
|
||||
BScrollView* scrollView = new BScrollView("scrollView", fListView,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
|
||||
|
||||
// Build the layout
|
||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||
|
||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
||||
.Add(scrollView)
|
||||
);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfacesAddOn::AttachedToWindow()
|
||||
{
|
||||
fListView->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
// FIXME with this scheme the apply and revert button will only take effect for
|
||||
// the currently shown interface. This can be confusing, it would be better to
|
||||
// keep the state of all interfaces and allow reverting and saving all of them.
|
||||
status_t
|
||||
InterfacesAddOn::Save()
|
||||
{
|
||||
// TODO : Profile?
|
||||
|
||||
InterfaceView* settingsView = _SettingsView();
|
||||
if (settingsView != NULL)
|
||||
settingsView->Apply();
|
||||
|
||||
BString settingsData;
|
||||
|
||||
status_t result = fListView->SaveItems(settingsData);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
if (settingsData.IsEmpty()) {
|
||||
// Nothing to save, all interfaces are auto-configured
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
BPath path;
|
||||
result = find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, true);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
path.Append("network");
|
||||
create_directory(path.Path(), 0755);
|
||||
|
||||
path.Append("interfaces");
|
||||
|
||||
BFile settingsFile(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||
result = settingsFile.Write(settingsData.String(),settingsData.Length());
|
||||
if (result != settingsData.Length())
|
||||
return result;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InterfacesAddOn::Revert()
|
||||
{
|
||||
InterfaceView* settingsView = _SettingsView();
|
||||
if (settingsView != NULL)
|
||||
settingsView->Revert();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfacesAddOn::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case kMsgInterfaceSelected:
|
||||
_ShowPanel();
|
||||
break;
|
||||
|
||||
case B_OBSERVER_NOTICE_CHANGE:
|
||||
fListView->Invalidate();
|
||||
break;
|
||||
|
||||
default:
|
||||
BBox::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfacesAddOn::Show()
|
||||
{
|
||||
BView::Show();
|
||||
_ShowPanel();
|
||||
}
|
||||
|
||||
|
||||
InterfaceView*
|
||||
InterfacesAddOn::_SettingsView()
|
||||
{
|
||||
BView* view = Window()->FindView("panel")->ChildAt(0);
|
||||
return dynamic_cast<InterfaceView*>(view);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfacesAddOn::_ShowPanel()
|
||||
{
|
||||
int nr = fListView->CurrentSelection();
|
||||
InterfaceListItem *item = NULL;
|
||||
if (nr != -1)
|
||||
item = dynamic_cast<InterfaceListItem*>(fListView->ItemAt(nr));
|
||||
|
||||
if (item == NULL)
|
||||
return;
|
||||
|
||||
BView* panel = Window()->FindView("panel");
|
||||
BView* settingsView = panel->ChildAt(0);
|
||||
|
||||
// Remove currently displayed settings view
|
||||
if (settingsView != NULL) {
|
||||
settingsView->RemoveSelf();
|
||||
delete settingsView;
|
||||
}
|
||||
|
||||
settingsView = new InterfaceView(item->GetSettings());
|
||||
Window()->FindView("panel")->AddChild(settingsView);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
SubDir HAIKU_TOP src preferences network InterfacesAddOn ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ;
|
||||
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src preferences network ] ;
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src servers net ] : true ;
|
||||
|
||||
UsePrivateHeaders net shared ;
|
||||
UseLibraryHeaders agg ;
|
||||
|
||||
|
||||
AddResources Interfaces :
|
||||
InterfacesIcons.rdef
|
||||
;
|
||||
|
||||
Addon Interfaces :
|
||||
InterfacesAddOn.cpp
|
||||
InterfacesListView.cpp
|
||||
NetworkSettings.cpp
|
||||
InterfaceView.cpp
|
||||
InterfaceAddressView.cpp
|
||||
InterfaceHardwareView.cpp
|
||||
|
||||
# from src/apps/networkstatus
|
||||
RadioView.cpp
|
||||
WirelessNetworkMenuItem.cpp
|
||||
:
|
||||
be libshared.a
|
||||
<nogrist>Network
|
||||
$(TARGET_NETWORK_LIBS)
|
||||
libbnetapi.so
|
||||
[ TargetLibsupc++ ]
|
||||
[ TargetLibstdc++ ]
|
||||
localestub
|
||||
libicon.a libagg.a
|
||||
;
|
||||
|
||||
DoCatalogs Interfaces :
|
||||
x-vnd.Haiku-InterfacesAddOn
|
||||
:
|
||||
InterfacesAddOn.cpp
|
||||
InterfacesListView.cpp
|
||||
InterfaceView.cpp
|
||||
InterfaceAddressView.cpp
|
||||
InterfaceHardwareView.cpp
|
||||
;
|
Loading…
Reference in New Issue
Block a user