Some more work on the DialUpPreflet code.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6927 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -24,6 +24,11 @@ Devices:
|
|||||||
Protocols:
|
Protocols:
|
||||||
"Protocol" : pointer to DialUpAddon object
|
"Protocol" : pointer to DialUpAddon object
|
||||||
|
|
||||||
|
Addons that must be deleted:
|
||||||
|
"DeleteMe" : pointer to DialUpAddon object - this will be deleted on exit (you should register all your
|
||||||
|
addons here, too)
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------
|
||||||
Additional data in the BMessage object for add-ons:
|
Additional data in the BMessage object for add-ons:
|
||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ class DialUpAddon {
|
|||||||
|
|
||||||
const BMessage *Addons() const
|
const BMessage *Addons() const
|
||||||
{ return fAddons; }
|
{ return fAddons; }
|
||||||
bool IsValid() const
|
|
||||||
{ return fIsValid; }
|
|
||||||
// This value will be set after all add-ons are registered.
|
|
||||||
// Add-ons with a non-existant kernel module are invalid!
|
|
||||||
|
|
||||||
virtual const char *FriendlyName() const
|
virtual const char *FriendlyName() const
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
@@ -49,10 +45,8 @@ class DialUpAddon {
|
|||||||
{ return 0; }
|
{ return 0; }
|
||||||
// allows to set order in which modules are asked to add the settings
|
// allows to set order in which modules are asked to add the settings
|
||||||
|
|
||||||
virtual bool LoadSettings(BMessage *settings, BMessage *profile)
|
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||||
{ return false; }
|
{ return false; }
|
||||||
// The interface's device is saved to "device" when loading
|
|
||||||
// settings or when a new device is selected.
|
|
||||||
virtual void IsModified(bool& settings, bool& profile) const
|
virtual void IsModified(bool& settings, bool& profile) const
|
||||||
{ settings = profile = false; }
|
{ settings = profile = false; }
|
||||||
virtual bool SaveSettings(BMessage *settings, BMessage *profile,
|
virtual bool SaveSettings(BMessage *settings, BMessage *profile,
|
||||||
@@ -73,7 +67,6 @@ class DialUpAddon {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BMessage *fAddons;
|
BMessage *fAddons;
|
||||||
bool fIsValid;
|
|
||||||
|
|
||||||
char _reserved[31];
|
char _reserved[31];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,10 +54,14 @@
|
|||||||
#define TEXT_AUTHENTICATION_FAILED "Authentication failed!"
|
#define TEXT_AUTHENTICATION_FAILED "Authentication failed!"
|
||||||
#define TEXT_CONNECTION_LOST "Connection lost!"
|
#define TEXT_CONNECTION_LOST "Connection lost!"
|
||||||
#define TEXT_CREATION_ERROR "Error creating interface!"
|
#define TEXT_CREATION_ERROR "Error creating interface!"
|
||||||
|
#define TEXT_NO_INTERFACE_SELECTED "No interface selected..."
|
||||||
#define TEXT_OK "OK"
|
#define TEXT_OK "OK"
|
||||||
#define ERROR_TITLE "Error"
|
#define ERROR_TITLE "Error"
|
||||||
#define ERROR_NO_PPP_STACK "Error: Could not find the PPP stack!"
|
#define ERROR_NO_PPP_STACK "Error: Could not find the PPP stack!"
|
||||||
#define ERROR_INTERFACE_EXISTS "Error: An interface with this name already exists!"
|
#define ERROR_INTERFACE_EXISTS "Error: An interface with this name already " \
|
||||||
|
"exists!"
|
||||||
|
#define ERROR_LOADING_FAILED "Error: Failed loading interface! The current " \
|
||||||
|
"settings will be deleted."
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -86,13 +90,6 @@ DialUpView::DialUpView(BRect frame)
|
|||||||
BMessenger messenger(this);
|
BMessenger messenger(this);
|
||||||
fAddons.AddMessenger("Messenger", messenger);
|
fAddons.AddMessenger("Messenger", messenger);
|
||||||
|
|
||||||
// load integrated add-ons
|
|
||||||
fAddons.AddPointer("Tab", new GeneralAddon(&fAddons));
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// load all add-ons
|
|
||||||
// register them and check if each one has a kernel module (set fIsValid)
|
|
||||||
|
|
||||||
// create pop-up with all interfaces and "New..."/"Delete current" items
|
// create pop-up with all interfaces and "New..."/"Delete current" items
|
||||||
fInterfaceMenu = new BPopUpMenu(LABEL_CREATE_NEW);
|
fInterfaceMenu = new BPopUpMenu(LABEL_CREATE_NEW);
|
||||||
BRect rect = bounds;
|
BRect rect = bounds;
|
||||||
@@ -101,23 +98,6 @@ DialUpView::DialUpView(BRect frame)
|
|||||||
fMenuField = new BMenuField(rect, "Interfaces", "Interface:", fInterfaceMenu);
|
fMenuField = new BMenuField(rect, "Interfaces", "Interface:", fInterfaceMenu);
|
||||||
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 10);
|
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 10);
|
||||||
|
|
||||||
fInterfaceMenu->AddSeparatorItem();
|
|
||||||
fInterfaceMenu->AddItem(new BMenuItem(LABEL_CREATE_NEW,
|
|
||||||
new BMessage(MSG_CREATE_NEW)));
|
|
||||||
fInterfaceMenu->AddItem(new BMenuItem(LABEL_DELETE_CURRENT,
|
|
||||||
new BMessage(MSG_DELETE_CURRENT)));
|
|
||||||
|
|
||||||
BDirectory settingsDirectory;
|
|
||||||
BEntry entry;
|
|
||||||
BPath path;
|
|
||||||
GetPPPDirectories(&settingsDirectory, NULL);
|
|
||||||
while(settingsDirectory.GetNextEntry(&entry) == B_OK) {
|
|
||||||
if(entry.IsFile()) {
|
|
||||||
entry.GetPath(&path);
|
|
||||||
AddInterface(path.Leaf());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rect.top = rect.bottom + 10;
|
rect.top = rect.bottom + 10;
|
||||||
rect.bottom = bounds.bottom
|
rect.bottom = bounds.bottom
|
||||||
- 20 // height of bottom controls
|
- 20 // height of bottom controls
|
||||||
@@ -127,10 +107,16 @@ DialUpView::DialUpView(BRect frame)
|
|||||||
tabViewRect.bottom -= fTabView->TabHeight();
|
tabViewRect.bottom -= fTabView->TabHeight();
|
||||||
fAddons.AddRect("TabViewRect", tabViewRect);
|
fAddons.AddRect("TabViewRect", tabViewRect);
|
||||||
|
|
||||||
|
// BRect noInterfacesRect(rect);
|
||||||
|
// noInterfacesRect.top = rect.top + rect.Width() / 2;
|
||||||
|
// noInterfacesRect.bottom = noInterfacesRect.top + 15;
|
||||||
|
// fNoInterfacesStringView = new BStringView(noInterfacesRect, "NoInterfacesView",
|
||||||
|
// TEXT_NO_INTERFACE_SELECTED);
|
||||||
|
|
||||||
rect.top = rect.bottom + 15;
|
rect.top = rect.bottom + 15;
|
||||||
rect.bottom = rect.top + 15;
|
rect.bottom = rect.top + 15;
|
||||||
rect.right = rect.left + 200;
|
rect.right = rect.left + 200;
|
||||||
fStatusView = new BStringView(rect, "StringView", TEXT_NOT_CONNECTED);
|
fStatusView = new BStringView(rect, "StatusView", TEXT_NOT_CONNECTED);
|
||||||
|
|
||||||
rect.InsetBy(0, -5);
|
rect.InsetBy(0, -5);
|
||||||
rect.left = rect.right + 5;
|
rect.left = rect.right + 5;
|
||||||
@@ -143,8 +129,12 @@ DialUpView::DialUpView(BRect frame)
|
|||||||
AddChild(fStatusView);
|
AddChild(fStatusView);
|
||||||
AddChild(fConnectButton);
|
AddChild(fConnectButton);
|
||||||
|
|
||||||
|
// initialize
|
||||||
|
LoadInterfaces();
|
||||||
|
LoadAddons();
|
||||||
CreateTabs();
|
CreateTabs();
|
||||||
|
fCurrentItem = NULL;
|
||||||
|
// reset, otherwise SelectInterface will not load the settings
|
||||||
SelectInterface(0);
|
SelectInterface(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +149,7 @@ DialUpView::~DialUpView()
|
|||||||
// free known add-on types (these should free their known add-on types, etc.)
|
// free known add-on types (these should free their known add-on types, etc.)
|
||||||
DialUpAddon *addon;
|
DialUpAddon *addon;
|
||||||
for(int32 index = 0;
|
for(int32 index = 0;
|
||||||
fAddons.FindPointer("Tab", index,
|
fAddons.FindPointer("DeleteMe", index,
|
||||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
reinterpret_cast<void**>(&addon)) == B_OK;
|
||||||
index++)
|
index++)
|
||||||
delete addon;
|
delete addon;
|
||||||
@@ -188,7 +178,7 @@ DialUpView::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_CREATE_NEW: {
|
case MSG_CREATE_NEW: {
|
||||||
AddInterface("New interface");
|
AddInterface("New interface", true);
|
||||||
if(fCurrentItem)
|
if(fCurrentItem)
|
||||||
fCurrentItem->SetMarked(true);
|
fCurrentItem->SetMarked(true);
|
||||||
} break;
|
} break;
|
||||||
@@ -225,12 +215,38 @@ DialUpView::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
bool
|
||||||
DialUpView::LoadSettings()
|
DialUpView::LoadSettings(bool isNew)
|
||||||
{
|
{
|
||||||
BMessage settings;
|
fSettings.MakeEmpty();
|
||||||
|
fProfile.MakeEmpty();
|
||||||
|
BMessage *settingsPointer = fCurrentItem ? &fSettings : NULL,
|
||||||
|
*profilePointer = fCurrentItem ? &fProfile : NULL;
|
||||||
|
|
||||||
// TODO: load settings
|
if(fCurrentItem && !isNew) {
|
||||||
|
BString name("pppidf/");
|
||||||
|
name << fCurrentItem->Label();
|
||||||
|
if(!ReadMessageDriverSettings(name.String(), fSettings))
|
||||||
|
return false;
|
||||||
|
name = "pppidf/profile/";
|
||||||
|
name << fCurrentItem->Label();
|
||||||
|
if(!ReadMessageDriverSettings(name.String(), fProfile))
|
||||||
|
profilePointer = settingsPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
DialUpAddon *addon;
|
||||||
|
for(int32 index = 0; fAddons.FindPointer("Tab", index,
|
||||||
|
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||||
|
if(!addon)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!addon->LoadSettings(settingsPointer, profilePointer, isNew))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check if settings are valid
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -242,11 +258,9 @@ DialUpView::IsModified(bool& settings, bool& profile)
|
|||||||
// for current addon
|
// for current addon
|
||||||
|
|
||||||
DialUpAddon *addon;
|
DialUpAddon *addon;
|
||||||
for(int32 index = 0;
|
for(int32 index = 0; fAddons.FindPointer("Tab", index,
|
||||||
fAddons.FindPointer("Tab", index,
|
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
if(!addon)
|
||||||
index++) {
|
|
||||||
if(!addon || !addon->IsValid())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addon->IsModified(addonSettingsChanged, addonProfileChanged);
|
addon->IsModified(addonSettingsChanged, addonProfileChanged);
|
||||||
@@ -271,7 +285,7 @@ DialUpView::SaveSettings(BMessage& settings, BMessage& profile, bool saveModifie
|
|||||||
fAddons.FindPointer("Tab", index,
|
fAddons.FindPointer("Tab", index,
|
||||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
reinterpret_cast<void**>(&addon)) == B_OK;
|
||||||
index++) {
|
index++) {
|
||||||
if(!addon || !addon->IsValid())
|
if(!addon)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int32 insertIndex = 0;
|
int32 insertIndex = 0;
|
||||||
@@ -284,7 +298,7 @@ DialUpView::SaveSettings(BMessage& settings, BMessage& profile, bool saveModifie
|
|||||||
|
|
||||||
settings.AddInt32("Interface", static_cast<int32>(fWatching));
|
settings.AddInt32("Interface", static_cast<int32>(fWatching));
|
||||||
if(fCurrentItem)
|
if(fCurrentItem)
|
||||||
settings.AddString("Name", fCurrentItem->Label());
|
settings.AddString("InterfaceName", fCurrentItem->Label());
|
||||||
|
|
||||||
for(int32 index = 0; index < addons.CountItems(); index++)
|
for(int32 index = 0; index < addons.CountItems(); index++)
|
||||||
addons.ItemAt(index)->SaveSettings(&settings, &profile, saveModified);
|
addons.ItemAt(index)->SaveSettings(&settings, &profile, saveModified);
|
||||||
@@ -440,7 +454,7 @@ DialUpView::CreateTabs()
|
|||||||
fAddons.FindPointer("Tab", index,
|
fAddons.FindPointer("Tab", index,
|
||||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
reinterpret_cast<void**>(&addon)) == B_OK;
|
||||||
index++) {
|
index++) {
|
||||||
if(!addon || !addon->IsValid() || addon->Position() < 0)
|
if(!addon || addon->Position() < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int32 insertIndex = 0;
|
int32 insertIndex = 0;
|
||||||
@@ -522,13 +536,14 @@ DialUpView::UpdateStatus(int32 code)
|
|||||||
void
|
void
|
||||||
DialUpView::WatchInterface(ppp_interface_id ID)
|
DialUpView::WatchInterface(ppp_interface_id ID)
|
||||||
{
|
{
|
||||||
if(fWatching == ID)
|
// This method can be used to update the interface's connection status.
|
||||||
return;
|
|
||||||
|
|
||||||
|
if(fWatching != ID) {
|
||||||
fListener.StopWatchingInterfaces();
|
fListener.StopWatchingInterfaces();
|
||||||
|
|
||||||
if(ID == PPP_UNDEFINED_INTERFACE_ID || fListener.WatchInterface(ID))
|
if(ID == PPP_UNDEFINED_INTERFACE_ID || fListener.WatchInterface(ID))
|
||||||
fWatching = ID;
|
fWatching = ID;
|
||||||
|
}
|
||||||
|
|
||||||
// update status
|
// update status
|
||||||
PPPInterface interface(fWatching);
|
PPPInterface interface(fWatching);
|
||||||
@@ -560,7 +575,50 @@ DialUpView::WatchInterface(ppp_interface_id ID)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DialUpView::AddInterface(const char *name)
|
DialUpView::LoadInterfaces()
|
||||||
|
{
|
||||||
|
fInterfaceMenu->AddSeparatorItem();
|
||||||
|
fInterfaceMenu->AddItem(new BMenuItem(LABEL_CREATE_NEW,
|
||||||
|
new BMessage(MSG_CREATE_NEW)));
|
||||||
|
fInterfaceMenu->AddItem(new BMenuItem(LABEL_DELETE_CURRENT,
|
||||||
|
new BMessage(MSG_DELETE_CURRENT)));
|
||||||
|
|
||||||
|
BDirectory settingsDirectory;
|
||||||
|
BEntry entry;
|
||||||
|
BPath path;
|
||||||
|
GetPPPDirectories(&settingsDirectory, NULL);
|
||||||
|
while(settingsDirectory.GetNextEntry(&entry) == B_OK) {
|
||||||
|
if(entry.IsFile()) {
|
||||||
|
entry.GetPath(&path);
|
||||||
|
AddInterface(path.Leaf(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DialUpView::LoadAddons()
|
||||||
|
{
|
||||||
|
// Load integrated add-ons:
|
||||||
|
// "General" tab
|
||||||
|
GeneralAddon *generalAddon = new GeneralAddon(&fAddons);
|
||||||
|
fAddons.AddPointer("Tab", generalAddon);
|
||||||
|
fAddons.AddPointer("DeleteMe", generalAddon);
|
||||||
|
// "PAP" authenticator
|
||||||
|
BMessage addon;
|
||||||
|
addon.AddString("KernelModuleName", "pap");
|
||||||
|
addon.AddString("FriendlyName", "Plain-text Authentication");
|
||||||
|
addon.AddString("TechnicalName", "PAP");
|
||||||
|
fAddons.AddMessage("Authenticator", &addon);
|
||||||
|
// addon.MakeEmpty();
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// load all add-ons from the add-ons folder
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DialUpView::AddInterface(const char *name, bool isNew = false)
|
||||||
{
|
{
|
||||||
if(fInterfaceMenu->FindItem(name)) {
|
if(fInterfaceMenu->FindItem(name)) {
|
||||||
(new BAlert(ERROR_TITLE, ERROR_INTERFACE_EXISTS, TEXT_OK))->Go();
|
(new BAlert(ERROR_TITLE, ERROR_INTERFACE_EXISTS, TEXT_OK))->Go();
|
||||||
@@ -572,12 +630,12 @@ DialUpView::AddInterface(const char *name)
|
|||||||
fInterfaceMenu->AddItem(item, CountInterfaces());
|
fInterfaceMenu->AddItem(item, CountInterfaces());
|
||||||
if(CountInterfaces() == 1)
|
if(CountInterfaces() == 1)
|
||||||
fInterfaceMenu->SetLabelFromMarked(true);
|
fInterfaceMenu->SetLabelFromMarked(true);
|
||||||
SelectInterface(CountInterfaces() - 1);
|
SelectInterface(CountInterfaces() - 1, isNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DialUpView::SelectInterface(int32 index)
|
DialUpView::SelectInterface(int32 index, bool isNew = false)
|
||||||
{
|
{
|
||||||
BMenuItem *item = fInterfaceMenu->FindMarked();
|
BMenuItem *item = fInterfaceMenu->FindMarked();
|
||||||
if(fCurrentItem && item == fCurrentItem)
|
if(fCurrentItem && item == fCurrentItem)
|
||||||
@@ -593,6 +651,13 @@ DialUpView::SelectInterface(int32 index)
|
|||||||
WatchInterface(PPP_UNDEFINED_INTERFACE_ID);
|
WatchInterface(PPP_UNDEFINED_INTERFACE_ID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(!fCurrentItem) {
|
||||||
|
fTabView->Show();
|
||||||
|
// fTabView->MoveBy(-Bounds().Width(), 0);
|
||||||
|
// fNoInterfacesStringView->MoveBy(Bounds().Width(), 0);
|
||||||
|
fConnectButton->SetEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
fCurrentItem = fInterfaceMenu->ItemAt(index);
|
fCurrentItem = fInterfaceMenu->ItemAt(index);
|
||||||
if(!fCurrentItem) {
|
if(!fCurrentItem) {
|
||||||
SelectInterface(0);
|
SelectInterface(0);
|
||||||
@@ -603,7 +668,21 @@ DialUpView::SelectInterface(int32 index)
|
|||||||
WatchInterface(fListener.Manager().InterfaceWithName(fCurrentItem->Label()));
|
WatchInterface(fListener.Manager().InterfaceWithName(fCurrentItem->Label()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadSettings();
|
if(!fCurrentItem) {
|
||||||
|
LoadSettings(false);
|
||||||
|
// tell modules to unload all settings
|
||||||
|
|
||||||
|
fTabView->Hide();
|
||||||
|
// fTabView->MoveBy(Bounds().Width(), 0);
|
||||||
|
// fNoInterfacesStringView->MoveBy(-Bounds().Width(), 0);
|
||||||
|
fConnectButton->SetEnabled(false);
|
||||||
|
} else if(isNew && !LoadSettings(true)) {
|
||||||
|
(new BAlert(ERROR_TITLE, ERROR_LOADING_FAILED, TEXT_OK))->Go();
|
||||||
|
LoadSettings(true);
|
||||||
|
} else if(!LoadSettings(false)) {
|
||||||
|
(new BAlert(ERROR_TITLE, ERROR_LOADING_FAILED, TEXT_OK))->Go();
|
||||||
|
LoadSettings(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,16 @@ class DialUpView : public BView {
|
|||||||
void UpdateStatus(int32 code);
|
void UpdateStatus(int32 code);
|
||||||
void WatchInterface(ppp_interface_id ID);
|
void WatchInterface(ppp_interface_id ID);
|
||||||
|
|
||||||
void LoadSettings();
|
bool LoadSettings(bool isNew);
|
||||||
void IsModified(bool& settings, bool& profile);
|
void IsModified(bool& settings, bool& profile);
|
||||||
bool SaveSettings(BMessage& settings, BMessage& profile, bool saveTemporary);
|
bool SaveSettings(BMessage& settings, BMessage& profile, bool saveTemporary);
|
||||||
bool SaveSettingsToFile();
|
bool SaveSettingsToFile();
|
||||||
|
|
||||||
void AddInterface(const char *name);
|
void LoadInterfaces();
|
||||||
void SelectInterface(int32 index);
|
void LoadAddons();
|
||||||
|
|
||||||
|
void AddInterface(const char *name, bool isNew = false);
|
||||||
|
void SelectInterface(int32 index, bool isNew = false);
|
||||||
int32 CountInterfaces() const;
|
int32 CountInterfaces() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -48,7 +51,7 @@ class DialUpView : public BView {
|
|||||||
|
|
||||||
thread_id fUpDownThread;
|
thread_id fUpDownThread;
|
||||||
|
|
||||||
BMessage fAddons, fSettings;
|
BMessage fAddons, fSettings, fProfile;
|
||||||
driver_settings *fDriverSettings;
|
driver_settings *fDriverSettings;
|
||||||
BMenuItem *fCurrentItem;
|
BMenuItem *fCurrentItem;
|
||||||
ppp_interface_id fWatching;
|
ppp_interface_id fWatching;
|
||||||
@@ -59,6 +62,7 @@ class DialUpView : public BView {
|
|||||||
BPopUpMenu *fInterfaceMenu;
|
BPopUpMenu *fInterfaceMenu;
|
||||||
BMenuField *fMenuField;
|
BMenuField *fMenuField;
|
||||||
BTabView *fTabView;
|
BTabView *fTabView;
|
||||||
|
// BStringView *fNoInterfacesStringView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
// GeneralAddon saves the loaded settings.
|
||||||
|
// GeneralView saves the current settings.
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
#include "GeneralAddon.h"
|
#include "GeneralAddon.h"
|
||||||
|
|
||||||
@@ -20,9 +23,12 @@
|
|||||||
#include <PPPDefs.h>
|
#include <PPPDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define MSG_SELECT_DEVICE 'SELD'
|
||||||
|
#define MSG_SELECT_AUTHENTICATOR 'SELA'
|
||||||
|
|
||||||
|
|
||||||
GeneralAddon::GeneralAddon(BMessage *addons)
|
GeneralAddon::GeneralAddon(BMessage *addons)
|
||||||
: DialUpAddon(addons),
|
: DialUpAddon(addons),
|
||||||
fHasDevice(false),
|
|
||||||
fHasPassword(false),
|
fHasPassword(false),
|
||||||
fAuthenticatorsCount(0),
|
fAuthenticatorsCount(0),
|
||||||
fSettings(NULL),
|
fSettings(NULL),
|
||||||
@@ -39,15 +45,30 @@ GeneralAddon::~GeneralAddon()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
DialUpAddon*
|
||||||
GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile)
|
GeneralAddon::FindDevice(const BString& moduleName) const
|
||||||
{
|
{
|
||||||
fHasDevice = fHasPassword = false;
|
DialUpAddon *addon;
|
||||||
fDevice = fUsername = fPassword = "";
|
for(int32 index = 0; Addons()->FindPointer("Device", index,
|
||||||
|
reinterpret_cast<void**>(addon)); index++)
|
||||||
|
if(addon && moduleName == addon->KernelModuleName())
|
||||||
|
return addon;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||||
|
{
|
||||||
|
fIsNew = isNew;
|
||||||
|
fHasPassword = false;
|
||||||
|
fDeviceName = fUsername = fPassword = "";
|
||||||
|
fDeviceAddon = NULL;
|
||||||
fAuthenticatorsCount = 0;
|
fAuthenticatorsCount = 0;
|
||||||
fSettings = settings;
|
fSettings = settings;
|
||||||
fProfile = profile;
|
fProfile = profile;
|
||||||
if(!settings)
|
if(!settings || !profile || isNew)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!LoadDeviceSettings(settings, profile))
|
if(!LoadDeviceSettings(settings, profile))
|
||||||
@@ -63,30 +84,40 @@ GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile)
|
|||||||
bool
|
bool
|
||||||
GeneralAddon::LoadDeviceSettings(BMessage *settings, BMessage *profile)
|
GeneralAddon::LoadDeviceSettings(BMessage *settings, BMessage *profile)
|
||||||
{
|
{
|
||||||
fHasDevice = false;
|
int32 index = 0;
|
||||||
fDevice = "";
|
BMessage device;
|
||||||
|
if(!FindMessageParameter(PPP_DEVICE_KEY, *settings, device, &index))
|
||||||
|
return false;
|
||||||
|
// TODO: tell user that device specification is missing
|
||||||
|
|
||||||
return true;
|
if(!device.FindString("Values", &fDeviceName))
|
||||||
|
return false;
|
||||||
|
// TODO: tell user that device specification is missing
|
||||||
|
|
||||||
|
device.AddBool("Valid", true);
|
||||||
|
settings->ReplaceMessage("Parameters", index, &device);
|
||||||
|
|
||||||
|
fDeviceAddon = FindDevice(fDeviceName);
|
||||||
|
if(!fDeviceAddon)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return fDeviceAddon->LoadSettings(settings, profile, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GeneralAddon::LoadAuthenticationSettings(BMessage *settings, BMessage *profile)
|
GeneralAddon::LoadAuthenticationSettings(BMessage *settings, BMessage *profile)
|
||||||
{
|
{
|
||||||
fHasPassword = false;
|
|
||||||
fUsername = fPassword = "";
|
|
||||||
fAuthenticatorsCount = 0;
|
|
||||||
|
|
||||||
// we only handle the profile (although settings could contain different data)
|
// we only handle the profile (although settings could contain different data)
|
||||||
BMessage authentication, *item = FindMessageParameter(PPP_AUTHENTICATOR_KEY,
|
int32 itemIndex = 0;
|
||||||
*profile);
|
BMessage authentication, item;
|
||||||
|
|
||||||
if(!item)
|
if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *profile, item, &itemIndex))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// find authenticators (though we load all authenticators, we only use one)
|
// find authenticators (though we load all authenticators, we only use one)
|
||||||
BString name;
|
BString name;
|
||||||
for(int32 index = 0; item->FindString("values", index, &name) == B_OK; index++) {
|
for(int32 index = 0; item.FindString("Values", index, &name) == B_OK; index++) {
|
||||||
BMessage authenticator;
|
BMessage authenticator;
|
||||||
if(!GetAuthenticator(name, &authenticator))
|
if(!GetAuthenticator(name, &authenticator))
|
||||||
return false;
|
return false;
|
||||||
@@ -103,21 +134,28 @@ GeneralAddon::LoadAuthenticationSettings(BMessage *settings, BMessage *profile)
|
|||||||
// a username must be present
|
// a username must be present
|
||||||
|
|
||||||
// load username and password
|
// load username and password
|
||||||
BMessage *parameter = FindMessageParameter("username", *item);
|
BMessage parameter;
|
||||||
if(parameter && parameter->FindString("values", &fUsername) == B_OK) {
|
int32 parameterIndex = 0;
|
||||||
|
if(FindMessageParameter("User", item, parameter, ¶meterIndex)
|
||||||
|
&& parameter.FindString("Values", &fUsername) == B_OK) {
|
||||||
hasUsername = true;
|
hasUsername = true;
|
||||||
parameter->AddBool("Valid", true);
|
parameter.AddBool("Valid", true);
|
||||||
|
item.ReplaceMessage("Parameters", parameterIndex, ¶meter);
|
||||||
}
|
}
|
||||||
|
|
||||||
parameter = FindMessageParameter("password", *item);
|
parameterIndex = 0;
|
||||||
if(parameter && parameter->FindString("values", &fPassword) == B_OK) {
|
if(FindMessageParameter("Password", item, parameter, ¶meterIndex)
|
||||||
|
&& parameter.FindString("Values", &fPassword) == B_OK) {
|
||||||
fHasPassword = true;
|
fHasPassword = true;
|
||||||
parameter->AddBool("Valid", true);
|
parameter.AddBool("Valid", true);
|
||||||
|
item.ReplaceMessage("Parameters", parameterIndex, ¶meter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell DUN whether everything is valid
|
// tell DUN whether everything is valid
|
||||||
if(hasUsername)
|
if(hasUsername)
|
||||||
item->AddBool("Valid", true);
|
item.AddBool("Valid", true);
|
||||||
|
|
||||||
|
profile->ReplaceMessage("Parameters", itemIndex, &item);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -144,7 +182,7 @@ GeneralAddon::IsModified(bool& settings, bool& profile) const
|
|||||||
void
|
void
|
||||||
GeneralAddon::IsDeviceModified(bool& settings, bool& profile) const
|
GeneralAddon::IsDeviceModified(bool& settings, bool& profile) const
|
||||||
{
|
{
|
||||||
if(fHasDevice)
|
if(fDeviceAddon)
|
||||||
settings = (!fGeneralView->DeviceName() || fGeneralView->IsDeviceModified());
|
settings = (!fGeneralView->DeviceName() || fGeneralView->IsDeviceModified());
|
||||||
else
|
else
|
||||||
settings = fGeneralView->DeviceName();
|
settings = fGeneralView->DeviceName();
|
||||||
@@ -187,22 +225,41 @@ GeneralAddon::IsAuthenticationModified(bool& settings, bool& profile) const
|
|||||||
bool
|
bool
|
||||||
GeneralAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
|
GeneralAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
|
||||||
{
|
{
|
||||||
if(!fSettings || !settings)
|
if(!fSettings || !settings || !fGeneralView->DeviceName())
|
||||||
|
return false;
|
||||||
|
// TODO: tell user that a device is needed (if we fail because of this)
|
||||||
|
|
||||||
|
if(fGeneralView->AuthenticatorName()) {
|
||||||
|
BMessage authenticator;
|
||||||
|
authenticator.AddString("Name", PPP_AUTHENTICATOR_KEY);
|
||||||
|
authenticator.AddString("Values", fGeneralView->AuthenticatorName());
|
||||||
|
|
||||||
|
BMessage username;
|
||||||
|
username.AddString("Name", "User");
|
||||||
|
username.AddString("Values", fGeneralView->Username());
|
||||||
|
authenticator.AddMessage("Parameters", &username);
|
||||||
|
|
||||||
|
if(saveTemporary || fGeneralView->DoesSavePassword()) {
|
||||||
|
// save password, too
|
||||||
|
BMessage password;
|
||||||
|
password.AddString("Name", "Password");
|
||||||
|
password.AddString("Values", fGeneralView->Password());
|
||||||
|
authenticator.AddMessage("Parameters", &password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DialUpAddon *addon = FindDevice(fGeneralView->DeviceName());
|
||||||
|
if(!addon)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: save settings
|
return addon->SaveSettings(settings, profile, saveTemporary);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GeneralAddon::GetPreferredSize(float *width, float *height) const
|
GeneralAddon::GetPreferredSize(float *width, float *height) const
|
||||||
{
|
{
|
||||||
if(!fSettings)
|
BRect rect(0, 0, 200, 300);
|
||||||
return false;
|
|
||||||
|
|
||||||
BRect rect(0,0,200,300);
|
|
||||||
// set default values
|
// set default values
|
||||||
Addons()->FindRect("TabViewRect", &rect);
|
Addons()->FindRect("TabViewRect", &rect);
|
||||||
|
|
||||||
@@ -218,13 +275,12 @@ GeneralAddon::GetPreferredSize(float *width, float *height) const
|
|||||||
BView*
|
BView*
|
||||||
GeneralAddon::CreateView(BPoint leftTop)
|
GeneralAddon::CreateView(BPoint leftTop)
|
||||||
{
|
{
|
||||||
if(!fSettings)
|
BRect rect;
|
||||||
return NULL;
|
if(Addons()->FindRect("TabViewRect", &rect) != B_OK);
|
||||||
|
rect.Set(0, 0, 200, 300);
|
||||||
BRect rect(0,0,200,300);
|
|
||||||
// set default values
|
// set default values
|
||||||
Addons()->FindRect("TabViewRect", &rect);
|
|
||||||
|
|
||||||
|
fGeneralView->MoveTo(leftTop);
|
||||||
fGeneralView->Reload();
|
fGeneralView->Reload();
|
||||||
return fGeneralView;
|
return fGeneralView;
|
||||||
}
|
}
|
||||||
@@ -251,15 +307,16 @@ GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const
|
|||||||
bool
|
bool
|
||||||
GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
|
GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
|
||||||
{
|
{
|
||||||
BMessage *authenticator;
|
BMessage authenticator;
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
BString name;
|
BString name;
|
||||||
|
|
||||||
for(; (authenticator = FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings,
|
for(; FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings, authenticator,
|
||||||
&index)); index++) {
|
&index); index++) {
|
||||||
authenticator->FindString("KernelModuleName", &name);
|
authenticator.FindString("KernelModuleName", &name);
|
||||||
if(name == moduleName) {
|
if(name == moduleName) {
|
||||||
authenticator->AddBool("Valid", true);
|
authenticator.AddBool("Valid", true);
|
||||||
|
fSettings->ReplaceMessage("Parameters", index, &authenticator);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,22 +336,24 @@ GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
|||||||
rect.top = rect.bottom + 10;
|
rect.top = rect.bottom + 10;
|
||||||
rect.bottom = rect.top
|
rect.bottom = rect.top
|
||||||
+ 25 // space for topmost control
|
+ 25 // space for topmost control
|
||||||
+ 2 * 20 // size of controls
|
+ 3 * 20 // size of controls
|
||||||
+ 2 * 5; // space beween controls and bottom of box
|
+ 3 * 5; // space beween controls and bottom of box
|
||||||
fAuthenticationBox = new BBox(rect, "Authentication");
|
fAuthenticationBox = new BBox(rect, "Authentication");
|
||||||
|
|
||||||
BString deviceLabel("Device: ");
|
fDeviceField = new BMenuField(BRect(5, 0, 250, 25), "Device",
|
||||||
deviceLabel << "PPPoE";
|
"Device:", new BPopUpMenu("No Devices Found!"));
|
||||||
// TODO: get real device name
|
fDeviceField->SetDivider(fDeviceField->StringWidth(fDeviceField->Label()) + 10);
|
||||||
BStringView *deviceLabelView = new BStringView(BRect(0,0,250,25), "Device",
|
fDeviceField->Menu()->SetRadioMode(true);
|
||||||
deviceLabel.String());
|
AddDevices();
|
||||||
fDeviceBox->SetLabel(deviceLabelView);
|
fDeviceBox->SetLabel(fDeviceField);
|
||||||
|
|
||||||
fAuthenticator = new BMenuField(BRect(5,0,250,25), "Authenticator",
|
fAuthenticatorField = new BMenuField(BRect(5, 0, 250, 25), "Authenticator",
|
||||||
"Authenticator:", new BPopUpMenu("No Authenticators Found!"));
|
"Authenticator:", new BPopUpMenu("No Authenticators Found!"));
|
||||||
fAuthenticator->SetDivider(fAuthenticator->StringWidth(
|
fAuthenticatorField->SetDivider(fAuthenticatorField->StringWidth(
|
||||||
fAuthenticator->Label()) + 10);
|
fAuthenticatorField->Label()) + 10);
|
||||||
fAuthenticationBox->SetLabel(fAuthenticator);
|
fAuthenticatorField->Menu()->SetRadioMode(true);
|
||||||
|
AddAuthenticators();
|
||||||
|
fAuthenticationBox->SetLabel(fAuthenticatorField);
|
||||||
|
|
||||||
rect = fAuthenticationBox->Bounds();
|
rect = fAuthenticationBox->Bounds();
|
||||||
rect.InsetBy(10, 0);
|
rect.InsetBy(10, 0);
|
||||||
@@ -305,9 +364,13 @@ GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
|||||||
rect.bottom = rect.top + 20;
|
rect.bottom = rect.top + 20;
|
||||||
fPassword = new BTextControl(rect, "password", "Password: ", NULL, NULL);
|
fPassword = new BTextControl(rect, "password", "Password: ", NULL, NULL);
|
||||||
fPassword->TextView()->HideTyping(true);
|
fPassword->TextView()->HideTyping(true);
|
||||||
|
rect.top = rect.bottom + 5;
|
||||||
|
rect.bottom = rect.top + 20;
|
||||||
|
fSavePassword = new BCheckBox(rect, "SavePassword", "Save Password", NULL);
|
||||||
|
|
||||||
fAuthenticationBox->AddChild(fUsername);
|
fAuthenticationBox->AddChild(fUsername);
|
||||||
fAuthenticationBox->AddChild(fPassword);
|
fAuthenticationBox->AddChild(fPassword);
|
||||||
|
fAuthenticationBox->AddChild(fSavePassword);
|
||||||
|
|
||||||
AddChild(fDeviceBox);
|
AddChild(fDeviceBox);
|
||||||
AddChild(fAuthenticationBox);
|
AddChild(fAuthenticationBox);
|
||||||
@@ -316,13 +379,95 @@ GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
|||||||
|
|
||||||
GeneralView::~GeneralView()
|
GeneralView::~GeneralView()
|
||||||
{
|
{
|
||||||
|
// TODO: delete device add-on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GeneralView::Reload()
|
GeneralView::Reload()
|
||||||
{
|
{
|
||||||
|
// TODO: reload settings:
|
||||||
|
// - select device and authenticator
|
||||||
|
// - add device view (and move authenticator view to fit)
|
||||||
|
// - set username, password, and checkbox
|
||||||
|
|
||||||
|
fDeviceAddon = NULL;
|
||||||
|
|
||||||
|
BMenuItem *item;
|
||||||
|
for(int32 index = 0; index < fDeviceField->Menu()->CountItems(); index++) {
|
||||||
|
item = fDeviceField->Menu()->ItemAt(index);
|
||||||
|
if(item && item->Message() && item->Message()->FindPointer("Addon",
|
||||||
|
reinterpret_cast<void**>(&fDeviceAddon)) == B_OK
|
||||||
|
&& fDeviceAddon == Addon()->DeviceAddon())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fDeviceAddon == Addon()->DeviceAddon()) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
ReloadDeviceView();
|
||||||
|
} else {
|
||||||
|
fDeviceAddon = NULL;
|
||||||
|
item = fDeviceField->Menu()->FindMarked();
|
||||||
|
if(item)
|
||||||
|
item->SetMarked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Addon()->CountAuthenticators() > 0) {
|
||||||
|
BString kernelModule, authenticator;
|
||||||
|
BMessage authentication;
|
||||||
|
if(Addon()->Settings()->FindMessage("Authentication", &authentication) == B_OK)
|
||||||
|
authentication.FindString("Authenticators", &authenticator);
|
||||||
|
for(int32 index = 0; index < fDeviceField->Menu()->CountItems(); index++) {
|
||||||
|
item = fDeviceField->Menu()->ItemAt(index);
|
||||||
|
if(item && item->Message()
|
||||||
|
&& item->Message()->FindString("KernelModuleName",
|
||||||
|
&kernelModule) == B_OK && kernelModule == authenticator) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
fAuthenticatorNone->SetMarked(true);
|
||||||
|
|
||||||
|
fUsername->SetText(Addon()->Username());
|
||||||
|
fPassword->SetText(Addon()->Password());
|
||||||
|
fSavePassword->SetValue(Addon()->HasPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
GeneralView::DeviceName() const
|
||||||
|
{
|
||||||
|
if(fDeviceAddon)
|
||||||
|
return fDeviceAddon->KernelModuleName();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
GeneralView::AuthenticatorName() const
|
||||||
|
{
|
||||||
|
BMenuItem *marked = fAuthenticatorField->Menu()->FindMarked();
|
||||||
|
if(marked && marked != fAuthenticatorNone)
|
||||||
|
return marked->Message()->FindString("KernelModuleName");
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
GeneralView::IsDeviceModified() const
|
||||||
|
{
|
||||||
|
if(fDeviceAddon != Addon()->DeviceAddon())
|
||||||
|
return true;
|
||||||
|
else if(fDeviceAddon) {
|
||||||
|
bool settings, profile;
|
||||||
|
fDeviceAddon->IsModified(settings, profile);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -330,6 +475,10 @@ void
|
|||||||
GeneralView::AttachedToWindow()
|
GeneralView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
fDeviceField->Menu()->SetTargetForItems(this);
|
||||||
|
fAuthenticatorField->Menu()->SetTargetForItems(this);
|
||||||
|
fUsername->SetTarget(this);
|
||||||
|
fPassword->SetTarget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -337,8 +486,146 @@ void
|
|||||||
GeneralView::MessageReceived(BMessage *message)
|
GeneralView::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what) {
|
switch(message->what) {
|
||||||
|
case MSG_SELECT_DEVICE:
|
||||||
|
if(message->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon))
|
||||||
|
!= B_OK)
|
||||||
|
fDeviceAddon = NULL;
|
||||||
|
else {
|
||||||
|
if(fDeviceAddon != Addon()->DeviceAddon())
|
||||||
|
fDeviceAddon->LoadSettings(Addon()->Settings(), Addon()->Profile(),
|
||||||
|
Addon()->IsNew());
|
||||||
|
|
||||||
|
ReloadDeviceView();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MSG_SELECT_AUTHENTICATOR:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GeneralView::ReloadDeviceView()
|
||||||
|
{
|
||||||
|
// first remove existing device view(s)
|
||||||
|
while(fDeviceBox->CountChildren() > 0)
|
||||||
|
fDeviceBox->RemoveChild(fDeviceBox->ChildAt(0));
|
||||||
|
|
||||||
|
BRect rect(fDeviceBox->Bounds());
|
||||||
|
rect.top = 25;
|
||||||
|
float width, height;
|
||||||
|
if(!fDeviceAddon->GetPreferredSize(&width, &height)) {
|
||||||
|
width = 50;
|
||||||
|
height = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(width > rect.Width())
|
||||||
|
width = rect.Width();
|
||||||
|
if(height < 10)
|
||||||
|
height = 10;
|
||||||
|
|
||||||
|
rect.InsetBy((rect.Width() - width) / 2, 0);
|
||||||
|
rect.bottom = rect.top + height;
|
||||||
|
float deltaY = rect.Height() - fDeviceBox->Bounds().Height();
|
||||||
|
fDeviceBox->ResizeBy(0, deltaY);
|
||||||
|
fAuthenticationBox->MoveBy(0, deltaY);
|
||||||
|
|
||||||
|
BView *deviceView = fDeviceAddon->CreateView(rect.LeftTop());
|
||||||
|
if(deviceView)
|
||||||
|
fDeviceBox->AddChild(deviceView);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GeneralView::AddDevices()
|
||||||
|
{
|
||||||
|
AddAddonsToMenu(fDeviceField->Menu(), "Device", MSG_SELECT_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GeneralView::AddAuthenticators()
|
||||||
|
{
|
||||||
|
fAuthenticatorNone = new BMenuItem("None", new BMessage(MSG_SELECT_AUTHENTICATOR));
|
||||||
|
fAuthenticatorField->Menu()->AddItem(fAuthenticatorNone);
|
||||||
|
fAuthenticatorNone->SetMarked(true);
|
||||||
|
fAuthenticatorField->Menu()->AddSeparatorItem();
|
||||||
|
|
||||||
|
BMessage addon;
|
||||||
|
for(int32 index = 0;
|
||||||
|
Addon()->Addons()->FindMessage("Authenticator", index, &addon) == B_OK;
|
||||||
|
index++) {
|
||||||
|
BMessage *message = new BMessage(MSG_SELECT_AUTHENTICATOR);
|
||||||
|
message->AddString("Authenticator", addon.FindString("KernelModuleName"));
|
||||||
|
|
||||||
|
BString name, technicalName, friendlyName;
|
||||||
|
bool hasTechnicalName
|
||||||
|
= (addon.FindString("TechnicalName", &technicalName) == B_OK);
|
||||||
|
bool hasFriendlyName
|
||||||
|
= (addon.FindString("FriendlyName", &friendlyName) == B_OK);
|
||||||
|
if(hasTechnicalName) {
|
||||||
|
name << technicalName;
|
||||||
|
if(hasFriendlyName)
|
||||||
|
name << " (";
|
||||||
|
}
|
||||||
|
if(hasFriendlyName) {
|
||||||
|
name << friendlyName;
|
||||||
|
if(hasTechnicalName)
|
||||||
|
name << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 insertAt = FindNextAddonInsertionIndex(fAuthenticatorField->Menu(),
|
||||||
|
name, 2);
|
||||||
|
fAuthenticatorField->Menu()->AddItem(new BMenuItem(name.String(), message),
|
||||||
|
insertAt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GeneralView::AddAddonsToMenu(BMenu *menu, const char *type, uint32 what)
|
||||||
|
{
|
||||||
|
DialUpAddon *addon;
|
||||||
|
for(int32 index = 0; Addon()->Addons()->FindPointer(type, index,
|
||||||
|
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||||
|
if(!addon || (!addon->FriendlyName() && !addon->TechnicalName()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BMessage *message = new BMessage(what);
|
||||||
|
message->AddPointer("Addon", addon);
|
||||||
|
|
||||||
|
BString name;
|
||||||
|
if(addon->TechnicalName()) {
|
||||||
|
name << addon->TechnicalName();
|
||||||
|
if(addon->FriendlyName())
|
||||||
|
name << " (";
|
||||||
|
}
|
||||||
|
if(addon->FriendlyName()) {
|
||||||
|
name << addon->FriendlyName();
|
||||||
|
if(addon->TechnicalName())
|
||||||
|
name << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 insertAt = FindNextAddonInsertionIndex(menu, name);
|
||||||
|
menu->AddItem(new BMenuItem(name.String(), message), insertAt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
GeneralView::FindNextAddonInsertionIndex(BMenu *menu, const BString& name,
|
||||||
|
int32 index = 0)
|
||||||
|
{
|
||||||
|
BMenuItem *item;
|
||||||
|
for(; index < menu->CountItems(); index++) {
|
||||||
|
item = menu->ItemAt(index);
|
||||||
|
if(item && name.ICompare(item->Label()) <= 0)
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,13 +4,16 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
// GeneralAddon saves the loaded settings.
|
||||||
|
// GeneralView saves the current settings.
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _GENERAL_ADDON__H
|
#ifndef _GENERAL_ADDON__H
|
||||||
#define _GENERAL_ADDON__H
|
#define _GENERAL_ADDON__H
|
||||||
|
|
||||||
#include <DialUpAddon.h>
|
#include <DialUpAddon.h>
|
||||||
|
|
||||||
#include <View.h>
|
#include <CheckBox.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
@@ -23,14 +26,33 @@ class GeneralAddon : public DialUpAddon {
|
|||||||
GeneralAddon(BMessage *addons);
|
GeneralAddon(BMessage *addons);
|
||||||
virtual ~GeneralAddon();
|
virtual ~GeneralAddon();
|
||||||
|
|
||||||
|
bool IsNew() const
|
||||||
|
{ return fIsNew; }
|
||||||
|
|
||||||
|
const char *DeviceName() const
|
||||||
|
{ return fDeviceName.String(); }
|
||||||
const char *Username() const
|
const char *Username() const
|
||||||
{ return fUsername.String(); }
|
{ return fUsername.String(); }
|
||||||
const char *Password() const
|
const char *Password() const
|
||||||
{ return fPassword.String(); }
|
{ return fPassword.String(); }
|
||||||
|
bool HasPassword() const
|
||||||
|
{ return fHasPassword; }
|
||||||
|
|
||||||
|
DialUpAddon *FindDevice(const BString& moduleName) const;
|
||||||
|
DialUpAddon *DeviceAddon() const
|
||||||
|
{ return fDeviceAddon; }
|
||||||
|
|
||||||
|
int32 CountAuthenticators() const
|
||||||
|
{ return fAuthenticatorsCount; }
|
||||||
|
|
||||||
|
BMessage *Settings() const
|
||||||
|
{ return fSettings; }
|
||||||
|
BMessage *Profile() const
|
||||||
|
{ return fProfile; }
|
||||||
|
|
||||||
virtual int32 Position() const
|
virtual int32 Position() const
|
||||||
{ return 0; }
|
{ return 0; }
|
||||||
virtual bool LoadSettings(BMessage *settings, BMessage *profile);
|
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
|
||||||
bool LoadDeviceSettings(BMessage *settings, BMessage *profile);
|
bool LoadDeviceSettings(BMessage *settings, BMessage *profile);
|
||||||
bool LoadAuthenticationSettings(BMessage *settings, BMessage *profile);
|
bool LoadAuthenticationSettings(BMessage *settings, BMessage *profile);
|
||||||
|
|
||||||
@@ -48,8 +70,9 @@ class GeneralAddon : public DialUpAddon {
|
|||||||
bool MarkAuthenticatorAsValid(const BString& moduleName);
|
bool MarkAuthenticatorAsValid(const BString& moduleName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fHasDevice, fHasPassword;
|
bool fIsNew, fHasPassword;
|
||||||
BString fDevice, fUsername, fPassword;
|
BString fDeviceName, fUsername, fPassword;
|
||||||
|
DialUpAddon *fDeviceAddon;
|
||||||
int32 fAuthenticatorsCount;
|
int32 fAuthenticatorsCount;
|
||||||
BMessage *fSettings, *fProfile;
|
BMessage *fSettings, *fProfile;
|
||||||
// saves last settings state
|
// saves last settings state
|
||||||
@@ -71,27 +94,32 @@ class GeneralView : public BView {
|
|||||||
const char *Password() const
|
const char *Password() const
|
||||||
{ return fPassword->Text(); }
|
{ return fPassword->Text(); }
|
||||||
bool DoesSavePassword() const
|
bool DoesSavePassword() const
|
||||||
{ return true; }
|
{ return fSavePassword->Value(); }
|
||||||
// TODO: implement me!
|
|
||||||
|
|
||||||
const char *DeviceName() const
|
const char *DeviceName() const;
|
||||||
{ return NULL; }
|
const char *AuthenticatorName() const;
|
||||||
// TODO: implement me!
|
bool IsDeviceModified() const;
|
||||||
const char *AuthenticatorName() const
|
|
||||||
{ return NULL; }
|
|
||||||
// TODO: implement me!
|
|
||||||
bool IsDeviceModified() const
|
|
||||||
{ return false; }
|
|
||||||
// TODO: implement me!
|
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ReloadDeviceView();
|
||||||
|
|
||||||
|
void AddDevices();
|
||||||
|
void AddAuthenticators();
|
||||||
|
void AddAddonsToMenu(BMenu *menu, const char *type, uint32 what);
|
||||||
|
int32 FindNextAddonInsertionIndex(BMenu *menu, const BString& name,
|
||||||
|
int32 index = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GeneralAddon *fAddon;
|
GeneralAddon *fAddon;
|
||||||
|
DialUpAddon *fDeviceAddon;
|
||||||
BBox *fDeviceBox, *fAuthenticationBox;
|
BBox *fDeviceBox, *fAuthenticationBox;
|
||||||
BMenuField *fAuthenticator;
|
BMenuField *fDeviceField, *fAuthenticatorField;
|
||||||
|
BMenuItem *fAuthenticatorNone;
|
||||||
BTextControl *fUsername, *fPassword;
|
BTextControl *fUsername, *fPassword;
|
||||||
|
BCheckBox *fSavePassword;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,27 +9,22 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
BMessage*
|
bool
|
||||||
FindMessageParameter(const char *name, BMessage& message, int32 *startIndex = NULL)
|
FindMessageParameter(const char *name, BMessage& message, BMessage& save,
|
||||||
|
int32 *startIndex = NULL)
|
||||||
{
|
{
|
||||||
// XXX: this is a hack and should be removed when we can replace BMessage with
|
// XXX: this should be removed when we can replace BMessage with something better
|
||||||
// something better
|
|
||||||
const BMessage *parameter;
|
|
||||||
BString string;
|
BString string;
|
||||||
ssize_t size;
|
|
||||||
int32 index = startIndex ? *startIndex : 0;
|
int32 index = startIndex ? *startIndex : 0;
|
||||||
for(; message.FindData("parameters", B_MESSAGE_TYPE, index,
|
for(; message.FindMessage("Parameters", index, &save) == B_OK; index++) {
|
||||||
reinterpret_cast<const void**>(¶meter), &size) == B_OK;
|
if(save.FindString("Name", &string) == B_OK && string.ICompare(name) == 0) {
|
||||||
index++) {
|
|
||||||
if(parameter->FindString("name", &string) == B_OK
|
|
||||||
&& string.ICompare(name)) {
|
|
||||||
if(startIndex)
|
if(startIndex)
|
||||||
*startIndex = index;
|
*startIndex = index;
|
||||||
return const_cast<BMessage*>(parameter);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -41,18 +36,18 @@ AddParameter(const driver_parameter *parameter, BMessage& message)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(parameter->name)
|
if(parameter->name)
|
||||||
message.AddString("name", parameter->name);
|
message.AddString("Name", parameter->name);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(int32 index = 0; index < parameter->value_count; index++)
|
for(int32 index = 0; index < parameter->value_count; index++)
|
||||||
if(parameter->values[index])
|
if(parameter->values[index])
|
||||||
message.AddString("values", parameter->values[index]);
|
message.AddString("Values", parameter->values[index]);
|
||||||
|
|
||||||
for(int32 index = 0; index < parameter->parameter_count; index++) {
|
for(int32 index = 0; index < parameter->parameter_count; index++) {
|
||||||
BMessage parameterMessage;
|
BMessage parameterMessage;
|
||||||
AddParameter(¶meter->parameters[index], parameterMessage);
|
AddParameter(¶meter->parameters[index], parameterMessage);
|
||||||
message.AddMessage("parameters", ¶meterMessage);
|
message.AddMessage("Parameters", ¶meterMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -75,7 +70,7 @@ ReadMessageDriverSettings(const char *name, BMessage& message)
|
|||||||
for(int32 index = 0; index < settings->parameter_count; index++) {
|
for(int32 index = 0; index < settings->parameter_count; index++) {
|
||||||
BMessage parameter;
|
BMessage parameter;
|
||||||
AddParameter(&settings->parameters[index], parameter);
|
AddParameter(&settings->parameters[index], parameter);
|
||||||
message.AddMessage("parameters", ¶meter);
|
message.AddMessage("Parameters", ¶meter);
|
||||||
}
|
}
|
||||||
|
|
||||||
unload_driver_settings(handle);
|
unload_driver_settings(handle);
|
||||||
@@ -89,20 +84,20 @@ bool
|
|||||||
WriteParameter(BFile& file, const BMessage& parameter, int32 level)
|
WriteParameter(BFile& file, const BMessage& parameter, int32 level)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
if(parameter.FindString("name", &name) != B_OK || !name)
|
if(parameter.FindString("Name", &name) != B_OK || !name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BString line;
|
BString line;
|
||||||
line.SetTo('\t', level);
|
line.SetTo('\t', level);
|
||||||
line << name << ' ';
|
line << name << ' ';
|
||||||
|
|
||||||
for(int32 index = 0; parameter.FindString("values", index, &name) == B_OK; index++)
|
for(int32 index = 0; parameter.FindString("Values", index, &name) == B_OK; index++)
|
||||||
if(name)
|
if(name)
|
||||||
line << name << ' ';
|
line << name << ' ';
|
||||||
|
|
||||||
type_code type;
|
type_code type;
|
||||||
int32 parameterCount;
|
int32 parameterCount;
|
||||||
parameter.GetInfo("parameters", &type, ¶meterCount);
|
parameter.GetInfo("Parameters", &type, ¶meterCount);
|
||||||
|
|
||||||
if(parameterCount > 0)
|
if(parameterCount > 0)
|
||||||
line << '{';
|
line << '{';
|
||||||
@@ -112,7 +107,7 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
|
|||||||
|
|
||||||
if(parameterCount > 0) {
|
if(parameterCount > 0) {
|
||||||
BMessage subParameter;
|
BMessage subParameter;
|
||||||
for(int32 index = 0; parameter.FindMessage("parameters", index,
|
for(int32 index = 0; parameter.FindMessage("Parameters", index,
|
||||||
&subParameter) == B_OK; index++)
|
&subParameter) == B_OK; index++)
|
||||||
WriteParameter(file, subParameter, level + 1);
|
WriteParameter(file, subParameter, level + 1);
|
||||||
|
|
||||||
@@ -134,7 +129,7 @@ WriteMessageDriverSettings(BFile& file, const BMessage& message)
|
|||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, SEEK_SET);
|
||||||
|
|
||||||
BMessage parameter;
|
BMessage parameter;
|
||||||
for(int32 index = 0; message.FindMessage("parameters", index, ¶meter) == B_OK;
|
for(int32 index = 0; message.FindMessage("Parameters", index, ¶meter) == B_OK;
|
||||||
index++)
|
index++)
|
||||||
WriteParameter(file, parameter, 0);
|
WriteParameter(file, parameter, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class BMessage;
|
|||||||
class BFile;
|
class BFile;
|
||||||
|
|
||||||
|
|
||||||
extern BMessage *FindMessageParameter(const char *name, BMessage& message,
|
extern bool FindMessageParameter(const char *name, BMessage& message,
|
||||||
int32 *startIndex = NULL);
|
BMessage& save, int32 *startIndex = NULL);
|
||||||
|
|
||||||
extern bool ReadMessageDriverSettings(const char *name, BMessage& message);
|
extern bool ReadMessageDriverSettings(const char *name, BMessage& message);
|
||||||
extern bool WriteMessageDriverSettings(BFile& file, const BMessage& message);
|
extern bool WriteMessageDriverSettings(BFile& file, const BMessage& message);
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ BUGs/Hacks:
|
|||||||
- FIXME: the MessageDriverSettings API uses a little hack to allow adding new entries to sub-messages without replacing the old one
|
- FIXME: the MessageDriverSettings API uses a little hack to allow adding new entries to sub-messages without replacing the old one
|
||||||
|
|
||||||
Short-term TODOs:
|
Short-term TODOs:
|
||||||
|
- see if we can reuse some code from the original DUN preflet
|
||||||
- add "Protocols" tab
|
- add "Protocols" tab
|
||||||
- add "Extras" tab for changing dial-behaviour (auto-redial, dial-on-demand, etc.)
|
- add "Extras" tab for changing dial-behaviour (auto-redial, dial-on-demand, etc.)
|
||||||
- add "Revert changes" button
|
- add "Revert Changes" button
|
||||||
- load add-ons
|
- load add-ons
|
||||||
- write IP (IPCP) protocol add-on
|
- write IP (IPCP) protocol add-on
|
||||||
- write PAP authenticator add-on
|
- write PAP authenticator add-on
|
||||||
|
|||||||
Reference in New Issue
Block a user