First draft of a NetworkSetup preflet AddOn interface. Dummy addon included...

Local (BoneYard or not) add-ons should not be under a sub-folder ./add-ons/boneyard/
anymore.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4835 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2003-09-28 08:54:21 +00:00
parent 752ad410c3
commit fcb83407a1
5 changed files with 149 additions and 14 deletions
+1
View File
@@ -3,5 +3,6 @@ SubDir OBOS_TOP src tests kits net preflet ;
SimpleTest Network :
Network.cpp
NetworkWindow.cpp
NetworkSetupAddOn.cpp
: be root
;
@@ -0,0 +1,45 @@
#include <stdlib.h>
#include "NetworkSetupAddOn.h"
NetworkSetupAddOn::NetworkSetupAddOn()
: fIsDirty(false), fProfile(NULL)
{
}
NetworkSetupAddOn::~NetworkSetupAddOn()
{
}
BView * NetworkSetupAddOn::CreateView(BRect *bounds)
{
BView *v = new BView(*bounds, "a view", B_FOLLOW_ALL, B_WILL_DRAW);
v->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
return v;
}
status_t NetworkSetupAddOn::Save()
{
return B_OK;
}
status_t NetworkSetupAddOn::Revert()
{
return B_OK;
}
status_t NetworkSetupAddOn::SetProfile(NetworkProfile *new_profile)
{
fProfile = new_profile;
return B_OK;
}
const char * NetworkSetupAddOn::Name()
{
return "Dummy NetworkSetupAddon";
}
@@ -0,0 +1,42 @@
#ifndef NETWORKSETUPADDON_H
#define NETWORKSETUPADDON_H
#include <View.h>
class NetworkProfile;
class NetworkSetupAddOn {
public:
NetworkSetupAddOn();
virtual ~NetworkSetupAddOn();
virtual BView * CreateView(BRect *bounds);
virtual status_t Save();
virtual status_t Revert();
virtual const char *Name();
status_t SetProfile(NetworkProfile *new_profile);
NetworkProfile * Profile();
bool IsDirty();
void SetDirty(bool dirty = true);
private:
bool fIsDirty;
NetworkProfile * fProfile;
};
inline bool NetworkSetupAddOn::IsDirty() { return fIsDirty; };
inline void NetworkSetupAddOn::SetDirty(bool dirty) { fIsDirty = dirty; };
inline NetworkProfile * NetworkSetupAddOn::Profile() { return fProfile; };
extern "C" {
typedef NetworkSetupAddOn * (*network_setup_addon_instantiate)(void);
NetworkSetupAddOn * get_addon(void);
}
#endif // ifdef NETWORKSETUPADDON_H
+41 -14
View File
@@ -8,7 +8,8 @@
#include <StorageKit.h>
#include <SupportKit.h>
#include <BoneyardAddOn.h>
#include "BoneyardAddOn.h"
#include "NetworkSetupAddOn.h"
#include "NetworkWindow.h"
@@ -165,17 +166,25 @@ void NetworkWindow::MessageReceived
case SHOW_MSG: {
BYAddon *by;
NetworkSetupAddOn *addon;
if (fShowView)
fShowView->RemoveSelf();
fShowView = NULL;
if (msg->FindPointer("byaddon", (void **) &by) != B_OK)
break;
by = NULL;
addon = NULL;
if (msg->FindPointer("addon", (void **) &addon) != B_OK) {
if (msg->FindPointer("byaddon", (void **) &by) != B_OK)
break;
};
fShowRect = fPanel->Bounds();
fShowView = by->CreateView(&fShowRect);
if (addon)
fShowView = addon->CreateView(&fShowRect);
else
fShowView = by->CreateView(&fShowRect);
if (fShowView) {
fPanel->AddChild(fShowView);
// fShowView->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
@@ -311,11 +320,11 @@ void NetworkWindow::BuildShowMenu
path.Append(search_path + 3);
} else {
path.SetTo(search_path);
path.Append("boneyard");
};
search_path = strtok_r(NULL, ":", &next_path_token);
path.Append("boneyard");
printf("Looking into %s\n", path.Path());
dir.SetTo(path.Path());
@@ -336,21 +345,39 @@ void NetworkWindow::BuildShowMenu
printf("Addon %s loaded.\n", addon_path.Path());
by_instantiate_func func;
by_instantiate_func by_func;
network_setup_addon_instantiate ns_func;
status_t status;
status = get_image_symbol(addon_id, "instantiate", B_SYMBOL_TYPE_TEXT, (void **) &func);
if (status != B_OK) {
// No "modules" symbol found in this addon
printf("Symbol \"instantiate\" not found in %s addon: not a module addon!\n", addon_path.Path());
} else {
BYAddon *by = func();
status = get_image_symbol(addon_id, "get_addon", B_SYMBOL_TYPE_TEXT, (void **) &ns_func);
if (status == B_OK) {
NetworkSetupAddOn *addon;
addon = ns_func();
BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("byaddon", by);
menu->AddItem(new BMenuItem(by->Name(), msg));
msg->AddPointer("addon", addon);
menu->AddItem(new BMenuItem(addon->Name(), msg));
continue;
};
status = get_image_symbol(addon_id, "instantiate", B_SYMBOL_TYPE_TEXT, (void **) &by_func);
if (status == B_OK) {
BYAddon *addon;
addon = by_func();
BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("byaddon", addon);
menu->AddItem(new BMenuItem(addon->Name(), msg));
continue;
};
// No "modules" symbol found in this addon
printf("Symbol \"instantiate\" not found in %s addon: not a module addon!\n", addon_path.Path());
unload_add_on(addon_id);
};
};
@@ -0,0 +1,20 @@
#include <stdlib.h>
#include "NetworkSetupAddOn.h"
class StatusAddOn : public NetworkSetupAddOn {
public:
const char * Name();
};
const char * StatusAddOn::Name()
{
return "Status";
}
NetworkSetupAddOn * get_addon()
{
return new StatusAddOn();
}