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:
@@ -58,6 +58,14 @@ InterfacesAddOn::Name()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
InterfacesAddOn::Save()
|
||||||
|
{
|
||||||
|
printf("I am saved!\n");
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BView*
|
BView*
|
||||||
InterfacesAddOn::CreateView(BRect *bounds)
|
InterfacesAddOn::CreateView(BRect *bounds)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Philippe Houdoin
|
* Philippe Houdoin
|
||||||
* Fredrik Modéen
|
* Fredrik Modéen
|
||||||
|
* Alexander von Gluck, <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef INTERFACES_ADDON_H
|
#ifndef INTERFACES_ADDON_H
|
||||||
#define INTERFACES_ADDON_H
|
#define INTERFACES_ADDON_H
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
|
||||||
#include "NetworkSetupAddOn.h"
|
#include "NetworkSetupAddOn.h"
|
||||||
|
|
||||||
@@ -22,8 +23,9 @@ class InterfacesAddOn : public NetworkSetupAddOn, public BBox
|
|||||||
public:
|
public:
|
||||||
InterfacesAddOn(image_id addon_image);
|
InterfacesAddOn(image_id addon_image);
|
||||||
~InterfacesAddOn();
|
~InterfacesAddOn();
|
||||||
|
|
||||||
const char* Name();
|
const char* Name();
|
||||||
|
status_t Save();
|
||||||
BView* CreateView(BRect *bounds);
|
BView* CreateView(BRect *bounds);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "NetworkSetupAddOn.h"
|
#include "NetworkSetupAddOn.h"
|
||||||
|
|
||||||
#include <kernel/image.h>
|
#include <kernel/image.h>
|
||||||
@@ -14,10 +15,10 @@
|
|||||||
|
|
||||||
|
|
||||||
NetworkSetupAddOn::NetworkSetupAddOn(image_id image)
|
NetworkSetupAddOn::NetworkSetupAddOn(image_id image)
|
||||||
:
|
:
|
||||||
fIsDirty(false),
|
fIsDirty(false),
|
||||||
fProfile(NULL),
|
fProfile(NULL),
|
||||||
fAddonImage(image),
|
fAddonImage(image),
|
||||||
fAddonResources(NULL)
|
fAddonResources(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,6 @@ NetworkSetupAddOn::ImageId()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
NetworkSetupAddOn::Name()
|
NetworkSetupAddOn::Name()
|
||||||
{
|
{
|
||||||
@@ -103,7 +103,7 @@ NetworkSetupAddOn::Resources()
|
|||||||
image_info info;
|
image_info info;
|
||||||
if (get_image_info(fAddonImage, &info) != B_OK)
|
if (get_image_info(fAddonImage, &info) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BResources *resources = new BResources();
|
BResources *resources = new BResources();
|
||||||
BFile addon_file(info.name, O_RDONLY);
|
BFile addon_file(info.name, O_RDONLY);
|
||||||
if (resources->SetTo(&addon_file) == B_OK)
|
if (resources->SetTo(&addon_file) == B_OK)
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NETWORKSETUPADDON_H
|
#ifndef NETWORKSETUPADDON_H
|
||||||
#define NETWORKSETUPADDON_H
|
#define NETWORKSETUPADDON_H
|
||||||
|
|
||||||
|
|
||||||
#include <interface/View.h>
|
#include <interface/View.h>
|
||||||
#include <kernel/image.h> // for image_id
|
#include <kernel/image.h> // for image_id
|
||||||
#include <storage/Resources.h>
|
#include <storage/Resources.h>
|
||||||
|
|
||||||
|
|
||||||
class NetworkSetupProfile;
|
class NetworkSetupProfile;
|
||||||
|
|
||||||
@@ -17,35 +18,38 @@ class NetworkSetupAddOn {
|
|||||||
public:
|
public:
|
||||||
NetworkSetupAddOn(image_id addon_image);
|
NetworkSetupAddOn(image_id addon_image);
|
||||||
virtual ~NetworkSetupAddOn();
|
virtual ~NetworkSetupAddOn();
|
||||||
|
|
||||||
virtual BView * CreateView(BRect* bounds);
|
virtual BView * CreateView(BRect* bounds);
|
||||||
virtual status_t Save();
|
virtual status_t Save();
|
||||||
virtual status_t Revert();
|
virtual status_t Revert();
|
||||||
|
|
||||||
virtual const char * Name();
|
virtual const char * Name();
|
||||||
virtual status_t ProfileChanged(NetworkSetupProfile*
|
virtual status_t ProfileChanged(NetworkSetupProfile*
|
||||||
new_profile);
|
new_profile);
|
||||||
|
|
||||||
NetworkSetupProfile * Profile();
|
NetworkSetupProfile * Profile();
|
||||||
bool IsDirty();
|
bool IsDirty();
|
||||||
void SetDirty(bool dirty = true);
|
void SetDirty(bool dirty = true);
|
||||||
image_id ImageId();
|
image_id ImageId();
|
||||||
BResources* Resources();
|
BResources* Resources();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fIsDirty;
|
bool fIsDirty;
|
||||||
NetworkSetupProfile* fProfile;
|
NetworkSetupProfile* fProfile;
|
||||||
image_id fAddonImage;
|
image_id fAddonImage;
|
||||||
BResources* fAddonResources;
|
BResources* fAddonResources;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#define NETWORK_SETUP_ADDON_INSTANCIATE_FUNC_NAME "get_nth_addon"
|
#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);
|
int index);
|
||||||
|
|
||||||
extern NetworkSetupAddOn* get_nth_addon(image_id image, int index);
|
extern NetworkSetupAddOn* get_nth_addon(image_id image, int index);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // ifdef NETWORKSETUPADDON_H
|
#endif // ifdef NETWORKSETUPADDON_H
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
|
* Authors:
|
||||||
|
* Alexander von Gluck, <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "NetworkSetupAddOn.h"
|
|
||||||
#include "NetworkSetupWindow.h"
|
#include "NetworkSetupWindow.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -31,7 +33,8 @@
|
|||||||
NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 100, 300, 300), title, B_TITLED_WINDOW,
|
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
|
// ---- Profiles section
|
||||||
BMenu *profilesPopup = new BPopUpMenu("<none>");
|
BMenu *profilesPopup = new BPopUpMenu("<none>");
|
||||||
@@ -55,7 +58,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
|||||||
|
|
||||||
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
|
fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
|
||||||
new BMessage(kMsgRevert));
|
new BMessage(kMsgRevert));
|
||||||
fRevertButton->SetEnabled(false);
|
// fRevertButton->SetEnabled(false);
|
||||||
|
|
||||||
// Enable boxes resizing modes
|
// Enable boxes resizing modes
|
||||||
fPanel->SetResizingMode(B_FOLLOW_ALL);
|
fPanel->SetResizingMode(B_FOLLOW_ALL);
|
||||||
@@ -86,7 +89,6 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
|||||||
|
|
||||||
fAddonView = NULL;
|
fAddonView = NULL;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +130,25 @@ NetworkSetupWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
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: {
|
case kMsgAddonShow: {
|
||||||
if (fAddonView)
|
if (fAddonView)
|
||||||
fAddonView->RemoveSelf();
|
fAddonView->RemoveSelf();
|
||||||
@@ -264,24 +285,25 @@ NetworkSetupWindow::_BuildShowTabView(int32 msg_what)
|
|||||||
B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon);
|
B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon);
|
||||||
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
NetworkSetupAddOn *addon;
|
while ((fNetworkAddOnMap[fAddonCount]
|
||||||
int n = 0;
|
= get_nth_addon(addon_id, fAddonCount)) != NULL) {
|
||||||
while ((addon = get_nth_addon(addon_id, n)) != NULL) {
|
printf("Adding Tab: %d\n", fAddonCount);
|
||||||
BMessage* msg = new BMessage(msg_what);
|
BMessage* msg = new BMessage(msg_what);
|
||||||
|
|
||||||
BRect r(0, 0, 0, 0);
|
BRect r(0, 0, 0, 0);
|
||||||
BView* addon_view = addon->CreateView(&r);
|
BView* addon_view
|
||||||
|
= fNetworkAddOnMap[fAddonCount]->CreateView(&r);
|
||||||
fMinAddonViewRect = fMinAddonViewRect | r;
|
fMinAddonViewRect = fMinAddonViewRect | r;
|
||||||
|
|
||||||
msg->AddInt32("image_id", addon_id);
|
msg->AddInt32("image_id", addon_id);
|
||||||
msg->AddString("addon_path", addon_path.Path());
|
msg->AddString("addon_path", addon_path.Path());
|
||||||
msg->AddPointer("addon", addon);
|
msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]);
|
||||||
msg->AddPointer("addon_view", addon_view);
|
msg->AddPointer("addon_view", addon_view);
|
||||||
|
|
||||||
BTab *tab = new BTab;
|
BTab *tab = new BTab;
|
||||||
fPanel->AddTab(addon_view, tab);
|
fPanel->AddTab(addon_view, tab);
|
||||||
tab->SetLabel(addon->Name());
|
tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name());
|
||||||
n++;
|
fAddonCount++;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,21 @@
|
|||||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
|
* Authors:
|
||||||
|
* Alexander von Gluck, <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NETWORKSETUPWINDOW_H
|
#ifndef NETWORKSETUPWINDOW_H
|
||||||
#define NETWORKSETUPWINDOW_H
|
#define NETWORKSETUPWINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "NetworkSetupAddOn.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<int, NetworkSetupAddOn*> NetworkAddOnMap;
|
||||||
|
|
||||||
|
|
||||||
class NetworkSetupWindow;
|
class NetworkSetupWindow;
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
@@ -41,8 +51,11 @@ class NetworkSetupWindow : public BWindow
|
|||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
BButton* fApplyButton;
|
BButton* fApplyButton;
|
||||||
|
|
||||||
|
NetworkAddOnMap fNetworkAddOnMap;
|
||||||
|
|
||||||
BTabView* fPanel;
|
BTabView* fPanel;
|
||||||
BView* fAddonView;
|
BView* fAddonView;
|
||||||
|
int fAddonCount;
|
||||||
BRect fMinAddonViewRect;
|
BRect fMinAddonViewRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user