CVS as a backup tool :-)
Commit some change made on draft network setup preflet. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5891 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
#include "BoneyardAddOn.h"
|
||||||
|
|
||||||
|
_EXPORT void boneyard_do_save() {}
|
||||||
|
_EXPORT void boneyard_do_revert() {}
|
||||||
|
|
||||||
|
BYDataEntry::BYDataEntry(const char *name, const char *value, const char *comment)
|
||||||
|
{
|
||||||
|
m_name = (char *) name;
|
||||||
|
m_value = (char *) value;
|
||||||
|
m_comment = (char *) comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
BYDataEntry::~BYDataEntry() {}
|
||||||
|
|
||||||
|
const char * BYDataEntry::Name() { return m_name; }
|
||||||
|
const char * BYDataEntry::Value() { return m_value; }
|
||||||
|
const char * BYDataEntry::Comment() { return m_comment; }
|
||||||
|
void BYDataEntry::SetValue(char *value) { m_value = value; }
|
||||||
|
void BYDataEntry::SetComment(char *comment) { m_comment = comment; }
|
||||||
|
|
||||||
|
void BYDataEntry::_ReservedDataEntry1() {}
|
||||||
|
void BYDataEntry::_ReservedDataEntry2() {}
|
||||||
|
|
||||||
|
BYAddon::BYAddon() {}
|
||||||
|
BYAddon::~BYAddon() {}
|
||||||
|
BView * BYAddon::CreateView(BRect *bounds) { return NULL; }
|
||||||
|
void BYAddon::Revert() {}
|
||||||
|
void BYAddon::Save() {}
|
||||||
|
|
||||||
|
const char *BYAddon::Name() { return "noname"; }
|
||||||
|
const char *BYAddon::Section() { return "noname"; }
|
||||||
|
const char *BYAddon::Description() { return "noname"; }
|
||||||
|
const BList *BYAddon::FileList() { return NULL; }
|
||||||
|
int BYAddon::Importance() { return 10; }
|
||||||
|
|
||||||
|
const BList *BYAddon::ObtainSectionData() { return NULL; } // get all BYDataEntrys for my section.
|
||||||
|
const char *BYAddon::GetValue(const char *name) { return ""; } // get a value from your section.
|
||||||
|
void BYAddon::SetValue(const char *name,const char *data) {} // set a value in your section.
|
||||||
|
void BYAddon::ClearValue(const char *name) {} // remove an entry from your section.
|
||||||
|
void BYAddon::ClearSectionData() {} // remove all entries from your section.
|
||||||
|
bool BYAddon::IsDirty() { return false; } // query dirty status
|
||||||
|
void BYAddon::SetDirty(bool _dirty) {} // set dirty status
|
||||||
|
const BList *BYAddon::GetAddonList() { return NULL; } // get all add-ons in the cradle.
|
||||||
|
|
||||||
|
void BYAddon::_ReservedAddon1() {}
|
||||||
|
void BYAddon::_ReservedAddon2() {}
|
||||||
|
void BYAddon::_ReservedAddon3() {}
|
||||||
|
void BYAddon::_ReservedAddon4() {}
|
||||||
|
void BYAddon::_ReservedAddon5() {}
|
||||||
|
void BYAddon::_ReservedAddon6() {}
|
||||||
|
void BYAddon::_ReservedAddon7() {}
|
||||||
|
void BYAddon::_ReservedAddon8() {}
|
||||||
|
|
||||||
|
// void BYAddon::GetAddonList();
|
||||||
|
|
||||||
|
void save_config();
|
||||||
|
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
SubDir OBOS_TOP src tests kits net preflet ;
|
SubDir OBOS_TOP src tests kits net preflet ;
|
||||||
|
|
||||||
SimpleTest Network :
|
SimpleTest NetworkSetup :
|
||||||
Network.cpp
|
NetworkSetup.cpp
|
||||||
NetworkWindow.cpp
|
NetworkSetupWindow.cpp
|
||||||
|
NetworkSetupProfile.cpp
|
||||||
NetworkSetupAddOn.cpp
|
NetworkSetupAddOn.cpp
|
||||||
|
BoneyardAddOn.cpp
|
||||||
: be root
|
: be root
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#include <Application.h>
|
||||||
|
#include <Window.h>
|
||||||
|
#include <Alert.h>
|
||||||
|
|
||||||
|
#include "NetworkSetupWindow.h"
|
||||||
|
|
||||||
|
#define SOFTWARE_EDITOR "obos"
|
||||||
|
#define SOFTWARE_NAME "Network Setup"
|
||||||
|
#define SOFTWARE_VERSION_LABEL "0.1.0 alpha"
|
||||||
|
|
||||||
|
const char * APPLICATION_SIGNATURE = "application/x-vnd." SOFTWARE_EDITOR "-" SOFTWARE_NAME;
|
||||||
|
|
||||||
|
const char * STR_ABOUT_TITLE = "About " SOFTWARE_NAME;
|
||||||
|
const char * STR_ABOUT_BUTTON = "Big Deal"; // "Hum?"
|
||||||
|
const char * STR_ABOUT_TEXT = SOFTWARE_NAME " " SOFTWARE_VERSION_LABEL "\n" \
|
||||||
|
"A little Network setup tool.\n\n" \
|
||||||
|
"The " SOFTWARE_NAME " Team:\n\n" \
|
||||||
|
"OpenBeOS Networking Team\n" \
|
||||||
|
"\n" \
|
||||||
|
"Thanks to:\n" \
|
||||||
|
"Be Inc.\n" \
|
||||||
|
"Internet\n" \
|
||||||
|
"Life\n";
|
||||||
|
|
||||||
|
class Application : public BApplication
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructors, destructors, operators...
|
||||||
|
Application();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Virtual function overrides
|
||||||
|
void ReadyToRun(void);
|
||||||
|
// virtual void MessageReceived(BMessage * msg);
|
||||||
|
virtual void AboutRequested();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Create an application instance
|
||||||
|
Application * app;
|
||||||
|
|
||||||
|
app = new Application();
|
||||||
|
app->Run();
|
||||||
|
delete app;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
Application::Application()
|
||||||
|
: BApplication(APPLICATION_SIGNATURE)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------
|
||||||
|
void Application::ReadyToRun(void)
|
||||||
|
{
|
||||||
|
// Open at least one window!
|
||||||
|
NetworkSetupWindow *window;
|
||||||
|
|
||||||
|
window = new NetworkSetupWindow(SOFTWARE_NAME);
|
||||||
|
window->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------
|
||||||
|
void Application::AboutRequested(void)
|
||||||
|
{
|
||||||
|
BAlert * about_box;
|
||||||
|
|
||||||
|
about_box = new BAlert(STR_ABOUT_TITLE, STR_ABOUT_TEXT, STR_ABOUT_BUTTON);
|
||||||
|
about_box->Go();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
NetworkSetupAddOn::NetworkSetupAddOn()
|
NetworkSetupAddOn::NetworkSetupAddOn()
|
||||||
: fIsDirty(false), fProfile(NULL)
|
: is_dirty(false), profile(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,9 +32,9 @@ status_t NetworkSetupAddOn::Revert()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t NetworkSetupAddOn::SetProfile(NetworkProfile *new_profile)
|
status_t NetworkSetupAddOn::ProfileChanged(NetworkSetupProfile *new_profile)
|
||||||
{
|
{
|
||||||
fProfile = new_profile;
|
profile = new_profile;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,33 +3,32 @@
|
|||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
class NetworkProfile;
|
class NetworkSetupProfile;
|
||||||
|
|
||||||
class NetworkSetupAddOn {
|
class NetworkSetupAddOn {
|
||||||
public:
|
public:
|
||||||
NetworkSetupAddOn();
|
NetworkSetupAddOn();
|
||||||
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();
|
||||||
|
|
||||||
|
status_t ProfileChanged(NetworkSetupProfile *new_profile);
|
||||||
status_t SetProfile(NetworkProfile *new_profile);
|
NetworkSetupProfile * Profile();
|
||||||
NetworkProfile * Profile();
|
bool IsDirty();
|
||||||
bool IsDirty();
|
void SetDirty(bool dirty = true);
|
||||||
void SetDirty(bool dirty = true);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fIsDirty;
|
bool is_dirty;
|
||||||
NetworkProfile * fProfile;
|
NetworkSetupProfile * profile;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool NetworkSetupAddOn::IsDirty() { return fIsDirty; };
|
inline bool NetworkSetupAddOn::IsDirty() { return is_dirty; };
|
||||||
inline void NetworkSetupAddOn::SetDirty(bool dirty) { fIsDirty = dirty; };
|
inline void NetworkSetupAddOn::SetDirty(bool dirty) { is_dirty = dirty; };
|
||||||
inline NetworkProfile * NetworkSetupAddOn::Profile() { return fProfile; };
|
inline NetworkSetupProfile * NetworkSetupAddOn::Profile() { return profile; };
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "NetworkSetupProfile.h"
|
||||||
|
|
||||||
|
|
||||||
|
NetworkSetupProfile::NetworkSetupProfile()
|
||||||
|
{
|
||||||
|
root = new BEntry();
|
||||||
|
path = new BPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkSetupProfile::NetworkSetupProfile(const char *path)
|
||||||
|
{
|
||||||
|
SetTo(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkSetupProfile::NetworkSetupProfile(const entry_ref *ref)
|
||||||
|
{
|
||||||
|
SetTo(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkSetupProfile::NetworkSetupProfile(BEntry *entry)
|
||||||
|
{
|
||||||
|
SetTo(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NetworkSetupProfile::~NetworkSetupProfile()
|
||||||
|
{
|
||||||
|
delete root;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::SetTo(const char *path)
|
||||||
|
{
|
||||||
|
BEntry *entry = new BEntry(path);
|
||||||
|
SetTo(entry);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::SetTo(const entry_ref *ref)
|
||||||
|
{
|
||||||
|
BEntry *entry = new BEntry(ref);
|
||||||
|
SetTo(entry);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::SetTo(BEntry *entry)
|
||||||
|
{
|
||||||
|
delete root;
|
||||||
|
delete path;
|
||||||
|
root = entry;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char * NetworkSetupProfile::Name()
|
||||||
|
{
|
||||||
|
if (!name) {
|
||||||
|
root->GetPath(path);
|
||||||
|
name = path->Leaf();
|
||||||
|
};
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::SetName(const char *name)
|
||||||
|
{
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NetworkSetupProfile::Unset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NetworkSetupProfile::Exists()
|
||||||
|
{
|
||||||
|
return root->Exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::Create()
|
||||||
|
{
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::Delete()
|
||||||
|
{
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NetworkSetupProfile::IsDefault()
|
||||||
|
{
|
||||||
|
return is_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NetworkSetupProfile::IsActive()
|
||||||
|
{
|
||||||
|
return is_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t NetworkSetupProfile::MakeActive()
|
||||||
|
{
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef NETWORKSETUPPROFILE_H
|
||||||
|
#define NETWORKSETUPPROFILE_H
|
||||||
|
|
||||||
|
#include <StorageKit.h>
|
||||||
|
|
||||||
|
class NetworkSetupProfile {
|
||||||
|
public:
|
||||||
|
NetworkSetupProfile();
|
||||||
|
NetworkSetupProfile(const char *path);
|
||||||
|
NetworkSetupProfile(const entry_ref *ref);
|
||||||
|
NetworkSetupProfile(BEntry *entry);
|
||||||
|
virtual ~NetworkSetupProfile();
|
||||||
|
|
||||||
|
status_t SetTo(const char *path);
|
||||||
|
status_t SetTo(const entry_ref *ref);
|
||||||
|
status_t SetTo(BEntry *entry);
|
||||||
|
|
||||||
|
void Unset();
|
||||||
|
|
||||||
|
bool Exists();
|
||||||
|
|
||||||
|
const char * Name();
|
||||||
|
status_t SetName(const char *name);
|
||||||
|
|
||||||
|
status_t Create();
|
||||||
|
status_t Delete();
|
||||||
|
|
||||||
|
virtual bool IsDefault();
|
||||||
|
virtual bool IsActive();
|
||||||
|
virtual status_t MakeActive();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BEntry * root;
|
||||||
|
BPath * path;
|
||||||
|
bool is_default;
|
||||||
|
bool is_active;
|
||||||
|
const char * name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ifdef NETWORKSETUPPROFILE_H
|
||||||
|
|
||||||
@@ -0,0 +1,474 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <app/Application.h>
|
||||||
|
#include <app/Roster.h>
|
||||||
|
#include <InterfaceKit.h>
|
||||||
|
#include <StorageKit.h>
|
||||||
|
#include <SupportKit.h>
|
||||||
|
|
||||||
|
#include "BoneyardAddOn.h"
|
||||||
|
#include "NetworkSetupAddOn.h"
|
||||||
|
|
||||||
|
#include "NetworkSetupWindow.h"
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
NetworkSetupWindow::NetworkSetupWindow(const char *title)
|
||||||
|
: BWindow(BRect(100, 100, 600, 600), title, B_TITLED_WINDOW,
|
||||||
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
||||||
|
{
|
||||||
|
BMenu *menu;
|
||||||
|
BBox *box, *group, *line;
|
||||||
|
BButton *button;
|
||||||
|
BCheckBox *check;
|
||||||
|
BRect r;
|
||||||
|
float w, h;
|
||||||
|
float x, y;
|
||||||
|
// float min_w, min_h;
|
||||||
|
|
||||||
|
#define H_MARGIN 10
|
||||||
|
#define V_MARGIN 10
|
||||||
|
#define SMALL_MARGIN 3
|
||||||
|
|
||||||
|
box = new BBox(Bounds(), NULL, B_FOLLOW_ALL,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
|
B_PLAIN_BORDER);
|
||||||
|
AddChild(box);
|
||||||
|
|
||||||
|
r = box->Bounds();
|
||||||
|
r.InsetBy(H_MARGIN, V_MARGIN);
|
||||||
|
|
||||||
|
// ---- Profiles section
|
||||||
|
|
||||||
|
menu = new BPopUpMenu("<none>");
|
||||||
|
fProfilesMenu = new BMenuField(r, "profiles_menu", PROFILE_LABEL, menu);
|
||||||
|
|
||||||
|
fProfilesMenu->SetFont(be_bold_font);
|
||||||
|
fProfilesMenu->SetDivider(be_bold_font->StringWidth(PROFILE_LABEL "#"));
|
||||||
|
box->AddChild(fProfilesMenu);
|
||||||
|
// fProfilesMenu->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
|
||||||
|
|
||||||
|
fProfilesMenu->ResizeToPreferred();
|
||||||
|
fProfilesMenu->GetPreferredSize(&w, &h);
|
||||||
|
|
||||||
|
button = new BButton(r, "manage_profiles", MANAGE_PROFILES_LABEL,
|
||||||
|
new BMessage(MANAGE_PROFILES_MSG),
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
button->MoveTo(r.right - w, r.top);
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fManageProfilesButton = button;
|
||||||
|
|
||||||
|
/*
|
||||||
|
r.left += w/2 + H_MARGIN;
|
||||||
|
|
||||||
|
button = new BButton(r, "new_profile", NEW_PROFILE_LABEL,
|
||||||
|
new BMessage(NEW_PROFILE_MSG),
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fNewProfileButton = button;
|
||||||
|
|
||||||
|
r.left += w + SMALL_MARGIN;
|
||||||
|
button = new BButton(r, "copy_profile", COPY_PROFILE_LABEL,
|
||||||
|
new BMessage(COPY_PROFILE_MSG),
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fCopyProfileButton = button;
|
||||||
|
|
||||||
|
r.left += w + SMALL_MARGIN;
|
||||||
|
button = new BButton(r, "delete_profile", DELETE_PROFILE_LABEL,
|
||||||
|
new BMessage(DELETE_PROFILE_MSG),
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fDeleteProfileButton = button;
|
||||||
|
|
||||||
|
r.left = H_MARGIN;
|
||||||
|
*/
|
||||||
|
r.top += h + V_MARGIN;
|
||||||
|
|
||||||
|
// ---- Separator line between Profiles section and Settings section
|
||||||
|
line = new BBox(BRect(r.left, r.top, r.right, r.top + 1), NULL,
|
||||||
|
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
|
||||||
|
box->AddChild(line);
|
||||||
|
|
||||||
|
BuildProfilesMenu(menu, SELECT_PROFILE_MSG);
|
||||||
|
|
||||||
|
r.top += V_MARGIN;
|
||||||
|
|
||||||
|
// ---- Bottom globals buttons section
|
||||||
|
#if 1
|
||||||
|
check = new BCheckBox(r, "dont_touch", DONT_TOUCH_LABEL,
|
||||||
|
new BMessage(DONT_TOUCH_MSG),
|
||||||
|
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT);
|
||||||
|
check->GetPreferredSize(&w, &h);
|
||||||
|
check->ResizeToPreferred();
|
||||||
|
check->SetValue(B_CONTROL_ON);
|
||||||
|
check->MoveTo(H_MARGIN, r.bottom - h);
|
||||||
|
box->AddChild(check);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
button = new BButton(r, "apply_now", APPLY_NOW_LABEL,
|
||||||
|
new BMessage(APPLY_NOW_MSG),
|
||||||
|
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
x = r.right - w;
|
||||||
|
button->MoveTo(x, r.bottom - h);
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fApplyNowButton = button;
|
||||||
|
|
||||||
|
button = new BButton(r, "revert", REVERT_LABEL,
|
||||||
|
new BMessage(REVERT_MSG),
|
||||||
|
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
button->MoveTo(x - w - SMALL_MARGIN, r.bottom - h);
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fRevertButton = button;
|
||||||
|
fRevertButton->SetEnabled(false);
|
||||||
|
|
||||||
|
// ---- Separator line between settings section and bottom buttons sections
|
||||||
|
|
||||||
|
y = r.bottom - h - V_MARGIN;
|
||||||
|
line = new BBox(BRect(-1, y, Bounds().right + 1, y + 1), NULL,
|
||||||
|
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
|
||||||
|
box->AddChild(line);
|
||||||
|
|
||||||
|
r.bottom = y - V_MARGIN;
|
||||||
|
|
||||||
|
// ---- Show settings section
|
||||||
|
|
||||||
|
menu = new BPopUpMenu("<nothing>");
|
||||||
|
|
||||||
|
// Make the show popup field half the whole width and centered
|
||||||
|
fShowMenu = new BMenuField(r, "show_menu", SHOW_LABEL, menu);
|
||||||
|
fShowMenu->SetFont(be_plain_font);
|
||||||
|
fShowMenu->SetDivider(be_plain_font->StringWidth(SHOW_LABEL "#"));
|
||||||
|
box->AddChild(fShowMenu);
|
||||||
|
// fShowMenu->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
|
||||||
|
|
||||||
|
fShowMenu->ResizeToPreferred();
|
||||||
|
fShowMenu->GetPreferredSize(&w, &h);
|
||||||
|
|
||||||
|
BuildShowMenu(menu, SHOW_MSG);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
button = new BButton(r, "help", HELP_LABEL,
|
||||||
|
new BMessage(HELP_MSG),
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
|
||||||
|
button->GetPreferredSize(&w, &h);
|
||||||
|
button->ResizeToPreferred();
|
||||||
|
button->MoveTo(r.right - w, r.top);
|
||||||
|
box->AddChild(button);
|
||||||
|
|
||||||
|
fHelpButton = button;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
r.top += h + SMALL_MARGIN;
|
||||||
|
r.left = H_MARGIN;
|
||||||
|
|
||||||
|
fPanel = new BBox(r, "showview_box", B_FOLLOW_ALL,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
|
B_PLAIN_BORDER);
|
||||||
|
box->AddChild(fPanel);
|
||||||
|
|
||||||
|
fShowRect = fPanel->Bounds();
|
||||||
|
fShowView = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
NetworkSetupWindow::~NetworkSetupWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
bool NetworkSetupWindow::QuitRequested()
|
||||||
|
{
|
||||||
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
void NetworkSetupWindow::MessageReceived
|
||||||
|
(
|
||||||
|
BMessage * msg
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (msg->what) {
|
||||||
|
case NEW_PROFILE_MSG:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COPY_PROFILE_MSG:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DELETE_PROFILE_MSG: {
|
||||||
|
BString text;
|
||||||
|
|
||||||
|
text << "Are you sure you want to remove '";
|
||||||
|
text << fProfilesMenu->MenuItem()->Label();
|
||||||
|
text << "' profile?";
|
||||||
|
BAlert *alert = new BAlert("Hum...", text.String() ,"Cancel", "Delete",
|
||||||
|
NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
|
||||||
|
alert->SetShortcut(0, B_ESCAPE);
|
||||||
|
alert->Go();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SELECT_PROFILE_MSG: {
|
||||||
|
BPath name;
|
||||||
|
const char *path;
|
||||||
|
bool is_default;
|
||||||
|
bool is_current;
|
||||||
|
|
||||||
|
if (msg->FindString("path", &path) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
name.SetTo(path);
|
||||||
|
|
||||||
|
is_default = (strcmp(name.Leaf(), "default") == 0);
|
||||||
|
is_current = (strcmp(name.Leaf(), "current") == 0);
|
||||||
|
|
||||||
|
// fDeleteProfileButton->SetEnabled(!is_default);
|
||||||
|
fApplyNowButton->SetEnabled(!is_current);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SHOW_MSG: {
|
||||||
|
BYAddon *by;
|
||||||
|
NetworkSetupAddOn *addon;
|
||||||
|
|
||||||
|
if (fShowView)
|
||||||
|
fShowView->RemoveSelf();
|
||||||
|
|
||||||
|
fShowView = NULL;
|
||||||
|
|
||||||
|
by = NULL;
|
||||||
|
addon = NULL;
|
||||||
|
if (msg->FindPointer("addon", (void **) &addon) != B_OK) {
|
||||||
|
if (msg->FindPointer("byaddon", (void **) &by) != B_OK)
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
fShowRect = fPanel->Bounds();
|
||||||
|
if (addon)
|
||||||
|
fShowView = addon->CreateView(&fShowRect);
|
||||||
|
else
|
||||||
|
fShowView = by->CreateView(&fShowRect);
|
||||||
|
if (fShowView) {
|
||||||
|
fPanel->AddChild(fShowView);
|
||||||
|
// fShowView->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
|
||||||
|
fShowView->ResizeTo(fPanel->Bounds().Width(), fPanel->Bounds().Height());
|
||||||
|
};
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
inherited::MessageReceived(msg);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
void NetworkSetupWindow::BuildProfilesMenu
|
||||||
|
(
|
||||||
|
BMenu *menu,
|
||||||
|
int32 msg_what
|
||||||
|
)
|
||||||
|
{
|
||||||
|
BMenuItem * item;
|
||||||
|
char current_profile[256] = { 0 };
|
||||||
|
|
||||||
|
menu->SetRadioMode(true);
|
||||||
|
|
||||||
|
BDirectory dir("/etc/network/profiles");
|
||||||
|
|
||||||
|
if (dir.InitCheck() == B_OK) {
|
||||||
|
BEntry entry;
|
||||||
|
BMessage *msg;
|
||||||
|
|
||||||
|
dir.Rewind();
|
||||||
|
while (dir.GetNextEntry(&entry) >= 0) {
|
||||||
|
BPath name;
|
||||||
|
entry.GetPath(&name);
|
||||||
|
|
||||||
|
if (entry.IsSymLink() &&
|
||||||
|
strcmp("current", name.Leaf()) == 0) {
|
||||||
|
BSymLink symlink(&entry);
|
||||||
|
|
||||||
|
if (symlink.IsAbsolute())
|
||||||
|
// oh oh, sorry, wrong symlink...
|
||||||
|
continue;
|
||||||
|
|
||||||
|
symlink.ReadLink(current_profile, sizeof(current_profile));
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!entry.IsDirectory())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
msg = new BMessage(msg_what);
|
||||||
|
msg->AddString("path", name.Path());
|
||||||
|
|
||||||
|
item = new BMenuItem(name.Leaf(), msg);
|
||||||
|
menu->AddItem(item);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
|
menu->AddItem(new BMenuItem(NEW_PROFILE_LABEL, new BMessage(NEW_PROFILE_MSG)));
|
||||||
|
menu->AddItem(new BMenuItem(RENAME_PROFILE_LABEL, new BMessage(RENAME_PROFILE_MSG)));
|
||||||
|
menu->AddItem(new BMenuItem(DELETE_PROFILE_LABEL, new BMessage(DELETE_PROFILE_MSG)));
|
||||||
|
*/
|
||||||
|
if (strlen(current_profile)) {
|
||||||
|
item = menu->FindItem(current_profile);
|
||||||
|
if (item) {
|
||||||
|
BString label;
|
||||||
|
bool is_default = (strcmp(current_profile, "default") == 0);
|
||||||
|
|
||||||
|
label << item->Label();
|
||||||
|
label << " (current)";
|
||||||
|
item->SetLabel(label.String());
|
||||||
|
item->SetMarked(true);
|
||||||
|
|
||||||
|
// fDeleteProfileButton->SetEnabled(!is_default);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
void NetworkSetupWindow::BuildShowMenu
|
||||||
|
(
|
||||||
|
BMenu *menu,
|
||||||
|
int32 msg_what
|
||||||
|
)
|
||||||
|
{
|
||||||
|
menu->SetRadioMode(true);
|
||||||
|
|
||||||
|
menu->AddItem(new BMenuItem("Status", new BMessage(msg_what)));
|
||||||
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
|
/*
|
||||||
|
menu->AddItem(item = new BMenuItem("vt86c100/0 interface", 0));
|
||||||
|
item->SetMarked(true);
|
||||||
|
menu->AddItem(item = new BMenuItem("rtl8136/0 interface", 0));
|
||||||
|
menu->AddItem(item = new BMenuItem("Dialup", 0));
|
||||||
|
menu->AddItem(item = new BMenuItem("Identity", 0));
|
||||||
|
menu->AddItem(item = new BMenuItem("Services", 0));
|
||||||
|
*/
|
||||||
|
|
||||||
|
BPath path;
|
||||||
|
BPath addon_path;
|
||||||
|
BDirectory dir;
|
||||||
|
BEntry entry;
|
||||||
|
char * search_paths;
|
||||||
|
char * search_path;
|
||||||
|
char * next_path_token;
|
||||||
|
|
||||||
|
search_paths = getenv("ADDON_PATH");
|
||||||
|
if (!search_paths)
|
||||||
|
// Nowhere to search addons!!!
|
||||||
|
return;
|
||||||
|
|
||||||
|
search_paths = strdup(search_paths);
|
||||||
|
search_path = strtok_r(search_paths, ":", &next_path_token);
|
||||||
|
|
||||||
|
while (search_path) {
|
||||||
|
if (strncmp(search_path, "%A/", 3) == 0) {
|
||||||
|
// compute "%A/..." path
|
||||||
|
app_info ai;
|
||||||
|
|
||||||
|
be_app->GetAppInfo(&ai);
|
||||||
|
entry.SetTo(&ai.ref);
|
||||||
|
entry.GetPath(&path);
|
||||||
|
path.GetParent(&path);
|
||||||
|
path.Append(search_path + 3);
|
||||||
|
} else {
|
||||||
|
path.SetTo(search_path);
|
||||||
|
path.Append("boneyard");
|
||||||
|
};
|
||||||
|
|
||||||
|
search_path = strtok_r(NULL, ":", &next_path_token);
|
||||||
|
|
||||||
|
printf("Looking into %s\n", path.Path());
|
||||||
|
|
||||||
|
dir.SetTo(path.Path());
|
||||||
|
if (dir.InitCheck() != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
dir.Rewind();
|
||||||
|
while (dir.GetNextEntry(&entry) >= 0) {
|
||||||
|
if (entry.IsDirectory())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
entry.GetPath(&addon_path);
|
||||||
|
image_id addon_id = load_add_on(addon_path.Path());
|
||||||
|
if (addon_id < 0) {
|
||||||
|
printf("Failed to load %s addon: %s.\n", addon_path.Path(), strerror(addon_id));
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
printf("Addon %s loaded.\n", addon_path.Path());
|
||||||
|
|
||||||
|
by_instantiate_func by_func;
|
||||||
|
network_setup_addon_instantiate ns_func;
|
||||||
|
status_t status;
|
||||||
|
|
||||||
|
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("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);
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
free(search_paths);
|
||||||
|
|
||||||
|
menu->AddItem(new BMenuItem("Very long label of network stuff to set/display", new BMessage(msg_what)));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#ifndef NETWORKSETUPWINDOW_H
|
||||||
|
#define NETWORKSETUPWINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <InterfaceKit.h>
|
||||||
|
|
||||||
|
#define PROFILE_LABEL "Profile:"
|
||||||
|
#define NEW_PROFILE_LABEL "New" B_UTF8_ELLIPSIS
|
||||||
|
#define COPY_PROFILE_LABEL "Copy" B_UTF8_ELLIPSIS
|
||||||
|
#define DELETE_PROFILE_LABEL "Delete"
|
||||||
|
|
||||||
|
#define MANAGE_PROFILES_LABEL "Manage profiles" B_UTF8_ELLIPSIS
|
||||||
|
|
||||||
|
#define SHOW_LABEL "Show:"
|
||||||
|
|
||||||
|
#define DONT_TOUCH_LABEL "Prevent unwanted changes"
|
||||||
|
#define SAVE_LABEL "Save"
|
||||||
|
#define HELP_LABEL "Help"
|
||||||
|
#define REVERT_LABEL "Revert"
|
||||||
|
#define APPLY_NOW_LABEL "Apply Now"
|
||||||
|
|
||||||
|
class NetworkSetupWindow : public BWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructors, destructors, operators...
|
||||||
|
NetworkSetupWindow(const char *title);
|
||||||
|
~NetworkSetupWindow();
|
||||||
|
|
||||||
|
typedef BWindow inherited;
|
||||||
|
|
||||||
|
// Virtual function overrides
|
||||||
|
public:
|
||||||
|
// public constantes
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SELECT_PROFILE_MSG = 'prof',
|
||||||
|
MANAGE_PROFILES_MSG = 'mngp',
|
||||||
|
NEW_PROFILE_MSG = 'newp',
|
||||||
|
COPY_PROFILE_MSG = 'cpyp',
|
||||||
|
DELETE_PROFILE_MSG = 'delp',
|
||||||
|
SHOW_MSG = 'show',
|
||||||
|
HELP_MSG = 'help',
|
||||||
|
DONT_TOUCH_MSG = 'lock',
|
||||||
|
APPLY_NOW_MSG = 'aply',
|
||||||
|
REVERT_MSG = 'rvrt'
|
||||||
|
};
|
||||||
|
|
||||||
|
bool QuitRequested();
|
||||||
|
void MessageReceived(BMessage * msg);
|
||||||
|
|
||||||
|
// From here, it's none of your business! ;-)
|
||||||
|
private:
|
||||||
|
void BuildProfilesMenu(BMenu *menu, int32 msg);
|
||||||
|
void BuildShowMenu(BMenu *menu, int32 msg);
|
||||||
|
|
||||||
|
BMenuField *fProfilesMenu;
|
||||||
|
BMenuField *fShowMenu;
|
||||||
|
BButton *fManageProfilesButton;
|
||||||
|
// BButton *fNewProfileButton;
|
||||||
|
// BButton *fCopyProfileButton;
|
||||||
|
// BButton *fDeleteProfileButton;
|
||||||
|
BButton *fHelpButton;
|
||||||
|
BButton *fRevertButton;
|
||||||
|
BButton *fApplyNowButton;
|
||||||
|
|
||||||
|
BBox *fPanel;
|
||||||
|
BView *fShowView;
|
||||||
|
BRect fShowRect;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ifdef NETWORKSETUPWINDOW_H
|
||||||
|
|
||||||
Reference in New Issue
Block a user