From c9b05e5212da4ff051d0e8f3022faa5b4b45fb63 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Mon, 21 Feb 2011 18:59:58 +0000 Subject: [PATCH] when loading addons, put them in a map so we can access them later easily; use addon instances stored in map and call Save/Revert for each through dynamic addon osmosis; little style cleanup git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40602 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../InterfacesAddOn/InterfacesAddOn.cpp | 8 ++++ .../preflet/InterfacesAddOn/InterfacesAddOn.h | 6 ++- .../kits/net/preflet/NetworkSetupAddOn.cpp | 12 ++--- .../kits/net/preflet/NetworkSetupAddOn.h | 22 ++++++---- .../kits/net/preflet/NetworkSetupWindow.cpp | 44 ++++++++++++++----- .../kits/net/preflet/NetworkSetupWindow.h | 15 ++++++- 6 files changed, 78 insertions(+), 29 deletions(-) diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp index 3642e36ed0..904ae9b0e0 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp @@ -58,6 +58,14 @@ InterfacesAddOn::Name() } +status_t +InterfacesAddOn::Save() +{ + printf("I am saved!\n"); + return B_OK; +} + + BView* InterfacesAddOn::CreateView(BRect *bounds) { diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h index 962f0856f6..de6ef900a4 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.h @@ -5,6 +5,7 @@ * Authors: * Philippe Houdoin * Fredrik Modéen + * Alexander von Gluck, */ #ifndef INTERFACES_ADDON_H #define INTERFACES_ADDON_H @@ -12,7 +13,7 @@ #include #include -#include +#include #include "NetworkSetupAddOn.h" @@ -22,8 +23,9 @@ class InterfacesAddOn : public NetworkSetupAddOn, public BBox public: InterfacesAddOn(image_id addon_image); ~InterfacesAddOn(); - + const char* Name(); + status_t Save(); BView* CreateView(BRect *bounds); enum { diff --git a/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp b/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp index 51d92b7044..6add6161bc 100644 --- a/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp @@ -4,6 +4,7 @@ * */ + #include "NetworkSetupAddOn.h" #include @@ -14,10 +15,10 @@ NetworkSetupAddOn::NetworkSetupAddOn(image_id image) - : - fIsDirty(false), - fProfile(NULL), - fAddonImage(image), + : + fIsDirty(false), + fProfile(NULL), + fAddonImage(image), fAddonResources(NULL) { } @@ -88,7 +89,6 @@ NetworkSetupAddOn::ImageId() } - const char* NetworkSetupAddOn::Name() { @@ -103,7 +103,7 @@ NetworkSetupAddOn::Resources() image_info info; if (get_image_info(fAddonImage, &info) != B_OK) return NULL; - + BResources *resources = new BResources(); BFile addon_file(info.name, O_RDONLY); if (resources->SetTo(&addon_file) == B_OK) diff --git a/src/tests/kits/net/preflet/NetworkSetupAddOn.h b/src/tests/kits/net/preflet/NetworkSetupAddOn.h index 59a9f56180..b63103e896 100644 --- a/src/tests/kits/net/preflet/NetworkSetupAddOn.h +++ b/src/tests/kits/net/preflet/NetworkSetupAddOn.h @@ -3,13 +3,14 @@ * Distributed under the terms of the MIT License. * */ - #ifndef NETWORKSETUPADDON_H #define NETWORKSETUPADDON_H + #include #include // for image_id -#include +#include + class NetworkSetupProfile; @@ -17,35 +18,38 @@ class NetworkSetupAddOn { public: NetworkSetupAddOn(image_id addon_image); virtual ~NetworkSetupAddOn(); - + virtual BView * CreateView(BRect* bounds); - virtual status_t Save(); + virtual status_t Save(); virtual status_t Revert(); - + virtual const char * Name(); - virtual status_t ProfileChanged(NetworkSetupProfile* + virtual status_t ProfileChanged(NetworkSetupProfile* new_profile); - + NetworkSetupProfile * Profile(); bool IsDirty(); void SetDirty(bool dirty = true); image_id ImageId(); BResources* Resources(); - + private: bool fIsDirty; NetworkSetupProfile* fProfile; image_id fAddonImage; BResources* fAddonResources; }; + extern "C" { #define NETWORK_SETUP_ADDON_INSTANCIATE_FUNC_NAME "get_nth_addon" -typedef NetworkSetupAddOn* (*network_setup_addon_instantiate)(image_id image, +typedef NetworkSetupAddOn* (*network_setup_addon_instantiate)(image_id image, int index); extern NetworkSetupAddOn* get_nth_addon(image_id image, int index); } + #endif // ifdef NETWORKSETUPADDON_H + diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp index 7496410138..2ae595d353 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp @@ -2,9 +2,11 @@ * Copyright 2004-2011 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * + * Authors: + * Alexander von Gluck, */ -#include "NetworkSetupAddOn.h" + #include "NetworkSetupWindow.h" #include @@ -31,7 +33,8 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) : BWindow(BRect(100, 100, 300, 300), title, B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), + fAddonCount(0) { // ---- Profiles section BMenu *profilesPopup = new BPopUpMenu(""); @@ -55,7 +58,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); - fRevertButton->SetEnabled(false); + // fRevertButton->SetEnabled(false); // Enable boxes resizing modes fPanel->SetResizingMode(B_FOLLOW_ALL); @@ -86,7 +89,6 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title) fAddonView = NULL; - } @@ -128,6 +130,25 @@ NetworkSetupWindow::MessageReceived(BMessage* msg) break; } + case kMsgRevert: { + for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) { + NetworkSetupAddOn* addon + = fNetworkAddOnMap[addonIndex]; + addon->Revert(); + } + break; + } + + + case kMsgApply: { + for (int addonIndex = 0; addonIndex < fAddonCount; addonIndex++) { + NetworkSetupAddOn* addon + = fNetworkAddOnMap[addonIndex]; + addon->Save(); + } + break; + } + case kMsgAddonShow: { if (fAddonView) fAddonView->RemoveSelf(); @@ -264,24 +285,25 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what) B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon); if (status == B_OK) { - NetworkSetupAddOn *addon; - int n = 0; - while ((addon = get_nth_addon(addon_id, n)) != NULL) { + while ((fNetworkAddOnMap[fAddonCount] + = get_nth_addon(addon_id, fAddonCount)) != NULL) { + printf("Adding Tab: %d\n", fAddonCount); BMessage* msg = new BMessage(msg_what); BRect r(0, 0, 0, 0); - BView* addon_view = addon->CreateView(&r); + BView* addon_view + = fNetworkAddOnMap[fAddonCount]->CreateView(&r); fMinAddonViewRect = fMinAddonViewRect | r; msg->AddInt32("image_id", addon_id); msg->AddString("addon_path", addon_path.Path()); - msg->AddPointer("addon", addon); + msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]); msg->AddPointer("addon_view", addon_view); BTab *tab = new BTab; fPanel->AddTab(addon_view, tab); - tab->SetLabel(addon->Name()); - n++; + tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name()); + fAddonCount++; } continue; } diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.h b/src/tests/kits/net/preflet/NetworkSetupWindow.h index a1f300e5bd..f5ee37dd4a 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.h +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.h @@ -2,11 +2,21 @@ * Copyright 2004-2011 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * + * Authors: + * Alexander von Gluck, */ - #ifndef NETWORKSETUPWINDOW_H #define NETWORKSETUPWINDOW_H + +#include "NetworkSetupAddOn.h" + +#include + + +typedef std::map NetworkAddOnMap; + + class NetworkSetupWindow; #include @@ -41,8 +51,11 @@ class NetworkSetupWindow : public BWindow BButton* fRevertButton; BButton* fApplyButton; + NetworkAddOnMap fNetworkAddOnMap; + BTabView* fPanel; BView* fAddonView; + int fAddonCount; BRect fMinAddonViewRect; };