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
This commit is contained in:
parent
025c4ea25a
commit
c9b05e5212
@ -58,6 +58,14 @@ InterfacesAddOn::Name()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InterfacesAddOn::Save()
|
||||
{
|
||||
printf("I am saved!\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
InterfacesAddOn::CreateView(BRect *bounds)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Authors:
|
||||
* Philippe Houdoin
|
||||
* Fredrik Modéen
|
||||
* Alexander von Gluck, <kallisti5@unixzen.com>
|
||||
*/
|
||||
#ifndef INTERFACES_ADDON_H
|
||||
#define INTERFACES_ADDON_H
|
||||
@ -12,7 +13,7 @@
|
||||
|
||||
#include <Box.h>
|
||||
#include <ListView.h>
|
||||
#include <Button.h>
|
||||
#include <Button.h>
|
||||
|
||||
#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 {
|
||||
|
@ -4,6 +4,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "NetworkSetupAddOn.h"
|
||||
|
||||
#include <kernel/image.h>
|
||||
@ -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)
|
||||
|
@ -3,13 +3,14 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETWORKSETUPADDON_H
|
||||
#define NETWORKSETUPADDON_H
|
||||
|
||||
|
||||
#include <interface/View.h>
|
||||
#include <kernel/image.h> // for image_id
|
||||
#include <storage/Resources.h>
|
||||
#include <storage/Resources.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
@ -2,9 +2,11 @@
|
||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander von Gluck, <kallisti5@unixzen.com>
|
||||
*/
|
||||
|
||||
#include "NetworkSetupAddOn.h"
|
||||
|
||||
#include "NetworkSetupWindow.h"
|
||||
|
||||
#include <Application.h>
|
||||
@ -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("<none>");
|
||||
@ -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;
|
||||
}
|
||||
|
@ -2,11 +2,21 @@
|
||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander von Gluck, <kallisti5@unixzen.com>
|
||||
*/
|
||||
|
||||
#ifndef NETWORKSETUPWINDOW_H
|
||||
#define NETWORKSETUPWINDOW_H
|
||||
|
||||
|
||||
#include "NetworkSetupAddOn.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<int, NetworkSetupAddOn*> NetworkAddOnMap;
|
||||
|
||||
|
||||
class NetworkSetupWindow;
|
||||
|
||||
#include <Window.h>
|
||||
@ -41,8 +51,11 @@ class NetworkSetupWindow : public BWindow
|
||||
BButton* fRevertButton;
|
||||
BButton* fApplyButton;
|
||||
|
||||
NetworkAddOnMap fNetworkAddOnMap;
|
||||
|
||||
BTabView* fPanel;
|
||||
BView* fAddonView;
|
||||
int fAddonCount;
|
||||
BRect fMinAddonViewRect;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user