added 4 changesets to branch 'refs/remotes/axeld-github/network-preferences' old head: 3643b2f0d72040d18f1908f0e4064ddb23885751 new head: 21afc9a587a5ec14c3e5fd5995874daccddb343d overview: https://github.com/axeld/haiku/compare/3643b2f0d720...21afc9a587a5 ---------------------------------------------------------------------------- 50929a5aedb0: BNetworkSettingsAddOn: added missing destructor. c0fb7bbea215: Network: fixed mixed up AddUnder() arguments. * BOutlineListView is the worst of the interface kit. f6d1c5221fb4: Network: fixed broken item frame retrieval. * Completely superfluous and expensive for BListView items, and just wrong for BOutlineListView items. * Also increased the width of the item, as we must take the tree offset into account ourselves (really, great API). 21afc9a587a5: 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. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 12 files changed, 212 insertions(+), 281 deletions(-) .../network_settings/NetworkSettingsAddOn.h | 1 + src/add-ons/Jamfile | 1 + src/add-ons/network_settings/Jamfile | 4 + .../network_settings/ipv4/IPv4InterfaceAddOn.cpp | 148 ++++++++++++++ .../ipv4}/InterfaceAddressView.cpp | 26 ++- .../ipv4}/InterfaceAddressView.h | 17 +- src/add-ons/network_settings/ipv4/Jamfile | 25 +++ src/preferences/network/InterfaceListItem.cpp | 7 +- .../network/InterfacesAddOn/InterfacesAddOn.cpp | 202 ------------------- src/preferences/network/InterfacesAddOn/Jamfile | 46 ----- src/preferences/network/NetworkSettingsAddOn.cpp | 5 + src/preferences/network/NetworkWindow.cpp | 11 +- ############################################################################ Commit: 50929a5aedb0564ca590fd7cc4818452c5efbc55 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Feb 13 20:38:59 2015 UTC BNetworkSettingsAddOn: added missing destructor. ---------------------------------------------------------------------------- diff --git a/headers/os/add-ons/network_settings/NetworkSettingsAddOn.h b/headers/os/add-ons/network_settings/NetworkSettingsAddOn.h index f05259b..98d39b7 100644 --- a/headers/os/add-ons/network_settings/NetworkSettingsAddOn.h +++ b/headers/os/add-ons/network_settings/NetworkSettingsAddOn.h @@ -55,6 +55,7 @@ class BNetworkSettingsInterfaceItem : public BNetworkSettingsItem { public: BNetworkSettingsInterfaceItem( const char* interface); + virtual ~BNetworkSettingsInterfaceItem(); virtual BNetworkSettingsType Type() const; diff --git a/src/preferences/network/NetworkSettingsAddOn.cpp b/src/preferences/network/NetworkSettingsAddOn.cpp index 5553641..d581bf7 100644 --- a/src/preferences/network/NetworkSettingsAddOn.cpp +++ b/src/preferences/network/NetworkSettingsAddOn.cpp @@ -51,6 +51,11 @@ BNetworkSettingsInterfaceItem::BNetworkSettingsInterfaceItem( } +BNetworkSettingsInterfaceItem::~BNetworkSettingsInterfaceItem() +{ +} + + BNetworkSettingsType BNetworkSettingsInterfaceItem::Type() const { ############################################################################ Commit: c0fb7bbea2150dfc79181f70de145b87bcc05012 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Feb 13 20:40:37 2015 UTC Network: fixed mixed up AddUnder() arguments. * BOutlineListView is the worst of the interface kit. ---------------------------------------------------------------------------- diff --git a/src/preferences/network/NetworkWindow.cpp b/src/preferences/network/NetworkWindow.cpp index b47ae03..3fe0d2a 100644 --- a/src/preferences/network/NetworkWindow.cpp +++ b/src/preferences/network/NetworkWindow.cpp @@ -351,7 +351,7 @@ NetworkWindow::_ScanAddOns() fSettingsMap[item->ListItem()] = item; // TODO: sort - fListView->AddUnder(interfaceItem, item->ListItem()); + fListView->AddUnder(item->ListItem(), interfaceItem); } } @@ -364,8 +364,8 @@ NetworkWindow::_ScanAddOns() fSettingsMap[item->ListItem()] = item; // TODO: sort - fListView->AddUnder(_ListItemFor(item->Type()), - item->ListItem()); + fListView->AddUnder(item->ListItem(), + _ListItemFor(item->Type())); } } } @@ -414,7 +414,7 @@ NetworkWindow::_ListItemFor(BNetworkSettingsType type) void NetworkWindow::_SelectItem(BListItem* listItem) { - if (fAddOnShellView->CountChildren() > 0) + while (fAddOnShellView->CountChildren() > 0) fAddOnShellView->ChildAt(0)->RemoveSelf(); BView* nextView = NULL; @@ -433,9 +433,6 @@ NetworkWindow::_SelectItem(BListItem* listItem) if (nextView != NULL) fAddOnShellView->AddChild(nextView); - - fAddOnShellView->Invalidate(); - InvalidateLayout(); } ############################################################################ Commit: f6d1c5221fb4bb2239dcb141be1464bfc12de2f8 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Feb 13 20:41:26 2015 UTC Network: fixed broken item frame retrieval. * Completely superfluous and expensive for BListView items, and just wrong for BOutlineListView items. * Also increased the width of the item, as we must take the tree offset into account ourselves (really, great API). ---------------------------------------------------------------------------- diff --git a/src/preferences/network/InterfaceListItem.cpp b/src/preferences/network/InterfaceListItem.cpp index 64e6c02..f7d5592 100644 --- a/src/preferences/network/InterfaceListItem.cpp +++ b/src/preferences/network/InterfaceListItem.cpp @@ -51,7 +51,7 @@ InterfaceListItem::~InterfaceListItem() void -InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) +InterfaceListItem::DrawItem(BView* owner, BRect bounds, bool complete) { BOutlineListView* list = dynamic_cast<BOutlineListView*>(owner); if (list == NULL) @@ -59,9 +59,6 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) owner->PushState(); - BRect bounds = list->ItemFrame(list->IndexOf(this)); - - //rgb_color highColor = list->HighColor(); rgb_color lowColor = list->LowColor(); if (IsSelected() || complete) { @@ -169,7 +166,7 @@ InterfaceListItem::Update(BView* owner, const BFont* font) _UpdateState(); - SetWidth(fIcon->Bounds().Width() + 24 + SetWidth(fIcon->Bounds().Width() + 44 + be_bold_font->StringWidth(fDeviceName.String()) + owner->StringWidth(_StateText())); SetHeight(std::max(3 * lineHeight + 4, fIcon->Bounds().Height() + 8)); ############################################################################ Commit: 21afc9a587a5ec14c3e5fd5995874daccddb343d Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Feb 13 20:49:19 2015 UTC 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. ---------------------------------------------------------------------------- diff --git a/src/add-ons/Jamfile b/src/add-ons/Jamfile index 905ba43..aae192c 100644 --- a/src/add-ons/Jamfile +++ b/src/add-ons/Jamfile @@ -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 ; diff --git a/src/add-ons/network_settings/Jamfile b/src/add-ons/network_settings/Jamfile new file mode 100644 index 0000000..8163bca --- /dev/null +++ b/src/add-ons/network_settings/Jamfile @@ -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 ; diff --git a/src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp b/src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp new file mode 100644 index 0000000..165bdac --- /dev/null +++ b/src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp @@ -0,0 +1,148 @@ +/* + * Copyright 2015 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, <axeld@xxxxxxxxxxxxxxxx> + */ + + +#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); +} diff --git a/src/preferences/network/InterfacesAddOn/InterfaceAddressView.cpp b/src/add-ons/network_settings/ipv4/InterfaceAddressView.cpp similarity index 95% rename from src/preferences/network/InterfacesAddOn/InterfaceAddressView.cpp rename to src/add-ons/network_settings/ipv4/InterfaceAddressView.cpp index a2636fd..c2825bf 100644 --- a/src/preferences/network/InterfacesAddOn/InterfaceAddressView.cpp +++ b/src/add-ons/network_settings/ipv4/InterfaceAddressView.cpp @@ -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; } diff --git a/src/preferences/network/InterfacesAddOn/InterfaceAddressView.h b/src/add-ons/network_settings/ipv4/InterfaceAddressView.h similarity index 79% rename from src/preferences/network/InterfacesAddOn/InterfaceAddressView.h rename to src/add-ons/network_settings/ipv4/InterfaceAddressView.h index 047413f..530ba9f 100644 --- a/src/preferences/network/InterfacesAddOn/InterfaceAddressView.h +++ b/src/add-ons/network_settings/ipv4/InterfaceAddressView.h @@ -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; diff --git a/src/add-ons/network_settings/ipv4/Jamfile b/src/add-ons/network_settings/ipv4/Jamfile new file mode 100644 index 0000000..38840b7 --- /dev/null +++ b/src/add-ons/network_settings/ipv4/Jamfile @@ -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 shared <nogrist>Network [ TargetLibsupc++ ] + [ TargetLibstdc++ ] localestub +; + +DoCatalogs IPv4Interface : x-vnd.Haiku-IPv4Interface : + IPv4InterfaceAddOn.cpp + InterfaceAddressView.cpp +; diff --git a/src/preferences/network/InterfacesAddOn/InterfacesAddOn.cpp b/src/preferences/network/InterfacesAddOn/InterfacesAddOn.cpp deleted file mode 100644 index 886e5c3..0000000 --- a/src/preferences/network/InterfacesAddOn/InterfacesAddOn.cpp +++ /dev/null @@ -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@xxxxxxxxxxxxxxx - * Alexander von Gluck, kallisti5@xxxxxxxxxxx - * Philippe Houdoin - * Fredrik Modéen - * Philippe Saint-Pierre - * Hugo Santos - * John Scipione, jscipione@xxxxxxxxx - */ - - -#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); -} diff --git a/src/preferences/network/InterfacesAddOn/Jamfile b/src/preferences/network/InterfacesAddOn/Jamfile deleted file mode 100644 index c8992fd..0000000 --- a/src/preferences/network/InterfacesAddOn/Jamfile +++ /dev/null @@ -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 -;