Added the Protocols tab. Could not test it because currently there is no IPCP addon.

Replaced direct identifier specification for BMessage with #define'd values, so typos cannot arise.
Moved some functions into InterfaceUtils so they are available for all add-ons (this will later become part of a static library for the DialUpAddon API).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7065 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2004-03-25 11:59:34 +00:00
parent a1a4146fcc
commit 3dbb75a676
16 changed files with 836 additions and 180 deletions
+10 -8
View File
@@ -7,10 +7,10 @@ All add-ons must add a "Valid" boolean value to every recognized parameter. The
Add-on registration: Add-on registration:
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
Tabs: Tabs:
"Tab" : pointer to DialUpAddon object DUN_TAB_ADDON_TYPE : pointer to DialUpAddon object
Authenticators: Authenticators:
"Authenticator" : BMessage with the following entries: DUN_AUTHENTICATOR_ADDON_TYPE : BMessage with the following entries:
{ {
"KernelModule" : string "KernelModule" : string
"TechnicalName" : string "TechnicalName" : string
@@ -19,18 +19,20 @@ Authenticators:
} }
Devices: Devices:
"Device" : pointer to DialUpAddon object DUN_DEVICE_ADDON_TYPE : pointer to DialUpAddon object
Protocols: Protocols:
"Protocol" : pointer to DialUpAddon object Note: CreateView() should NOT return a view, but open a preferences window (B_MODAL_WINDOW)!
DUN_PROTOCOL_ADDON_TYPE : pointer to DialUpAddon object
Addons that must be deleted: Addons that must be deleted:
"DeleteMe" : pointer to DialUpAddon object - this will be deleted on exit (you should register all your DUN_DELETE_ON_QUIT : pointer to DialUpAddon object - this will be deleted when the preflet quits
addons here, too) (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:
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
"Messenger" : BMessenger - This messenger can be used to send messages to the preflet DUN_MESSENGER : BMessenger - This messenger can be used to send messages to the preflet
"TabViewRect" : BRect - This rect should be used for tabs DUN_TAB_VIEW_RECT : BRect - This rect should be used for tabs
DUN_DEVICE_VIEW_WIDTH : float - Maximum width a device add-on's view may have
+14 -1
View File
@@ -18,7 +18,20 @@
#include <Point.h> #include <Point.h>
#define DUN_MAXIMUM_PRIORITY 50 #define DUN_MAXIMUM_PRIORITY 50
// add-on types
#define DUN_TAB_ADDON_TYPE "Tab"
#define DUN_AUTHENTICATOR_ADDON_TYPE "Authenticator"
#define DUN_DEVICE_ADDON_TYPE "Device"
#define DUN_PROTOCOL_ADDON_TYPE "Protocol"
// other information contained in the add-ons BMessage object
#define DUN_DELETE_ON_QUIT "DeleteMe"
// the DialUpAddon objects in this list will be deleted when the preflet quits
#define DUN_MESSENGER "Messenger"
#define DUN_TAB_VIEW_RECT "TabViewRect"
#define DUN_DEVICE_VIEW_WIDTH "DeviceViewWidth"
class DialUpAddon { class DialUpAddon {
+20 -29
View File
@@ -8,11 +8,13 @@
#include "DialUpView.h" #include "DialUpView.h"
#include "DialUpAddon.h" #include "DialUpAddon.h"
#include "InterfaceUtils.h"
#include "MessageDriverSettingsUtils.h" #include "MessageDriverSettingsUtils.h"
// built-in add-ons // built-in add-ons
#include "GeneralAddon.h" #include "GeneralAddon.h"
#include "PPPoEAddon.h" #include "PPPoEAddon.h"
#include "ProtocolsAddon.h"
#include <PPPInterface.h> #include <PPPInterface.h>
@@ -90,7 +92,7 @@ DialUpView::DialUpView(BRect frame)
// add messenger to us so add-ons can contact us // add messenger to us so add-ons can contact us
BMessenger messenger(this); BMessenger messenger(this);
fAddons.AddMessenger("Messenger", messenger); fAddons.AddMessenger(DUN_MESSENGER, messenger);
// 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);
@@ -107,7 +109,7 @@ DialUpView::DialUpView(BRect frame)
fTabView = new BTabView(rect, "TabView"); fTabView = new BTabView(rect, "TabView");
BRect tabViewRect = fTabView->Bounds(); BRect tabViewRect = fTabView->Bounds();
tabViewRect.bottom -= fTabView->TabHeight(); tabViewRect.bottom -= fTabView->TabHeight();
fAddons.AddRect("TabViewRect", tabViewRect); fAddons.AddRect(DUN_TAB_VIEW_RECT, tabViewRect);
rect.top = rect.bottom + 15; rect.top = rect.bottom + 15;
rect.bottom = rect.top + 15; rect.bottom = rect.top + 15;
@@ -145,7 +147,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("DeleteMe", index, fAddons.FindPointer(DUN_DELETE_ON_QUIT, index,
reinterpret_cast<void**>(&addon)) == B_OK; reinterpret_cast<void**>(&addon)) == B_OK;
index++) index++)
delete addon; delete addon;
@@ -232,7 +234,7 @@ DialUpView::LoadSettings(bool isNew)
} }
DialUpAddon *addon; DialUpAddon *addon;
for(int32 index = 0; fAddons.FindPointer("Tab", index, for(int32 index = 0; fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
reinterpret_cast<void**>(&addon)) == B_OK; index++) { reinterpret_cast<void**>(&addon)) == B_OK; index++) {
if(!addon) if(!addon)
continue; continue;
@@ -255,7 +257,7 @@ DialUpView::IsModified(bool& settings, bool& profile)
// for current addon // for current addon
DialUpAddon *addon; DialUpAddon *addon;
for(int32 index = 0; fAddons.FindPointer("Tab", index, for(int32 index = 0; fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
reinterpret_cast<void**>(&addon)) == B_OK; index++) { reinterpret_cast<void**>(&addon)) == B_OK; index++) {
if(!addon) if(!addon)
continue; continue;
@@ -278,7 +280,7 @@ DialUpView::SaveSettings(BMessage& settings, BMessage& profile, bool saveModifie
DialUpAddon *addon; DialUpAddon *addon;
TemplateList<DialUpAddon*> addons; TemplateList<DialUpAddon*> addons;
for(int32 index = 0; for(int32 index = 0;
fAddons.FindPointer("Tab", index, fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
reinterpret_cast<void**>(&addon)) == B_OK; reinterpret_cast<void**>(&addon)) == B_OK;
index++) { index++) {
if(!addon) if(!addon)
@@ -440,14 +442,14 @@ DialUpView::HandleReportMessage(BMessage *message)
void void
DialUpView::CreateTabs() DialUpView::CreateTabs()
{ {
// create tabs for all registered and valid "Tab" add-ons // create tabs for all registered and valid tab add-ons
DialUpAddon *addon; DialUpAddon *addon;
BView *target; BView *target;
float width, height; float width, height;
TemplateList<DialUpAddon*> addons; TemplateList<DialUpAddon*> addons;
for(int32 index = 0; for(int32 index = 0;
fAddons.FindPointer("Tab", index, fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
reinterpret_cast<void**>(&addon)) == B_OK; reinterpret_cast<void**>(&addon)) == B_OK;
index++) { index++) {
if(!addon || addon->Position() < 0) if(!addon || addon->Position() < 0)
@@ -598,19 +600,23 @@ DialUpView::LoadAddons()
// Load integrated add-ons: // Load integrated add-ons:
// "General" tab // "General" tab
GeneralAddon *generalAddon = new GeneralAddon(&fAddons); GeneralAddon *generalAddon = new GeneralAddon(&fAddons);
fAddons.AddPointer("Tab", generalAddon); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, generalAddon);
fAddons.AddPointer("DeleteMe", generalAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, generalAddon);
// "PPPoE" device // "PPPoE" device
PPPoEAddon *pppoeAddon = new PPPoEAddon(&fAddons); PPPoEAddon *pppoeAddon = new PPPoEAddon(&fAddons);
fAddons.AddPointer("Device", pppoeAddon); fAddons.AddPointer(DUN_DEVICE_ADDON_TYPE, pppoeAddon);
fAddons.AddPointer("DeleteMe", pppoeAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, pppoeAddon);
// "Protocols" tab
ProtocolsAddon *protocolsAddon = new ProtocolsAddon(&fAddons);
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, protocolsAddon);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, protocolsAddon);
// "PAP" authenticator // "PAP" authenticator
BMessage addon; BMessage addon;
addon.AddString("KernelModuleName", "pap"); addon.AddString("KernelModuleName", "pap");
addon.AddString("FriendlyName", "Plain-text Authentication"); addon.AddString("FriendlyName", "Plain-text Authentication");
addon.AddString("TechnicalName", "PAP"); addon.AddString("TechnicalName", "PAP");
fAddons.AddMessage("Authenticator", &addon); fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon);
// addon.MakeEmpty(); // addon.MakeEmpty(); // for next authenticator
// TODO: // TODO:
// load all add-ons from the add-ons folder // load all add-ons from the add-ons folder
@@ -687,18 +693,3 @@ DialUpView::CountInterfaces() const
{ {
return fInterfaceMenu->CountItems() - 3; return fInterfaceMenu->CountItems() - 3;
} }
int32
DialUpView::FindNextMenuInsertionIndex(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;
}
@@ -45,8 +45,6 @@ class DialUpView : public BView {
void AddInterface(const char *name, bool isNew = false); void AddInterface(const char *name, bool isNew = false);
void SelectInterface(int32 index, bool isNew = false); void SelectInterface(int32 index, bool isNew = false);
int32 CountInterfaces() const; int32 CountInterfaces() const;
int32 FindNextMenuInsertionIndex(BMenu *menu, const BString& name,
int32 index = 0);
private: private:
PPPInterfaceListener fListener; PPPInterfaceListener fListener;
@@ -10,13 +10,13 @@
#include "GeneralAddon.h" #include "GeneralAddon.h"
#include "InterfaceUtils.h"
#include "MessageDriverSettingsUtils.h" #include "MessageDriverSettingsUtils.h"
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Messenger.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <StringView.h> #include <StringView.h>
@@ -27,6 +27,10 @@
#define MSG_SELECT_AUTHENTICATOR 'SELA' #define MSG_SELECT_AUTHENTICATOR 'SELA'
#define GENERAL_TAB_AUTHENTICATION "Authentication"
#define GENERAL_TAB_AUTHENTICATORS "Authenticators"
GeneralAddon::GeneralAddon(BMessage *addons) GeneralAddon::GeneralAddon(BMessage *addons)
: DialUpAddon(addons), : DialUpAddon(addons),
fHasPassword(false), fHasPassword(false),
@@ -47,7 +51,7 @@ DialUpAddon*
GeneralAddon::FindDevice(const BString& moduleName) const GeneralAddon::FindDevice(const BString& moduleName) const
{ {
DialUpAddon *addon; DialUpAddon *addon;
for(int32 index = 0; Addons()->FindPointer("Device", index, for(int32 index = 0; Addons()->FindPointer(DUN_DEVICE_ADDON_TYPE, index,
reinterpret_cast<void**>(&addon)) == B_OK; index++) reinterpret_cast<void**>(&addon)) == B_OK; index++)
if(addon && moduleName == addon->KernelModuleName()) if(addon && moduleName == addon->KernelModuleName())
return addon; return addon;
@@ -74,10 +78,10 @@ GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
if(!settings || !profile || isNew) if(!settings || !profile || isNew)
return true; return true;
if(!LoadDeviceSettings(settings, profile)) if(!LoadDeviceSettings())
return false; return false;
if(!LoadAuthenticationSettings(settings, profile)) if(!LoadAuthenticationSettings())
return false; return false;
if(fGeneralView) if(fGeneralView)
@@ -89,53 +93,53 @@ GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
bool bool
GeneralAddon::LoadDeviceSettings(BMessage *settings, BMessage *profile) GeneralAddon::LoadDeviceSettings()
{ {
int32 index = 0; int32 index = 0;
BMessage device; BMessage device;
if(!FindMessageParameter(PPP_DEVICE_KEY, *settings, device, &index)) if(!FindMessageParameter(PPP_DEVICE_KEY, *fSettings, device, &index))
return false; return false;
// TODO: tell user that device specification is missing // TODO: tell user that device specification is missing
if(device.FindString("Values", &fDeviceName) != B_OK) if(device.FindString(MDSU_VALUES, &fDeviceName) != B_OK)
return false; return false;
// TODO: tell user that device specification is missing // TODO: tell user that device specification is missing
device.AddBool("Valid", true); device.AddBool(MDSU_VALID, true);
settings->ReplaceMessage("Parameters", index, &device); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &device);
fDeviceAddon = FindDevice(fDeviceName); fDeviceAddon = FindDevice(fDeviceName);
if(!fDeviceAddon) if(!fDeviceAddon)
return false; return false;
return fDeviceAddon->LoadSettings(settings, profile, false); return fDeviceAddon->LoadSettings(fSettings, fProfile, false);
} }
bool bool
GeneralAddon::LoadAuthenticationSettings(BMessage *settings, BMessage *profile) GeneralAddon::LoadAuthenticationSettings()
{ {
// we only handle the profile (although settings could contain different data) // we only handle the profile (although settings could contain different data)
int32 itemIndex = 0; int32 itemIndex = 0;
BMessage authentication, item; BMessage authentication, item;
if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *profile, item, &itemIndex)) if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fProfile, 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(MDSU_VALUES, index, &name) == B_OK; index++) {
BMessage authenticator; BMessage authenticator;
if(!GetAuthenticator(name, &authenticator)) if(!GetAuthenticator(name, &authenticator))
return false; return false;
// fatal error: we do not know how to handle this authenticator // fatal error: we do not know how to handle this authenticator
MarkAuthenticatorAsValid(name); MarkAuthenticatorAsValid(name);
authentication.AddString("Authenticators", name); authentication.AddString(GENERAL_TAB_AUTHENTICATORS, name);
++fAuthenticatorsCount; ++fAuthenticatorsCount;
} }
fSettings->AddMessage("Authentication", &authentication); fSettings->AddMessage(GENERAL_TAB_AUTHENTICATION, &authentication);
bool hasUsername = false; bool hasUsername = false;
// a username must be present // a username must be present
@@ -144,25 +148,25 @@ GeneralAddon::LoadAuthenticationSettings(BMessage *settings, BMessage *profile)
BMessage parameter; BMessage parameter;
int32 parameterIndex = 0; int32 parameterIndex = 0;
if(FindMessageParameter("User", item, parameter, &parameterIndex) if(FindMessageParameter("User", item, parameter, &parameterIndex)
&& parameter.FindString("Values", &fUsername) == B_OK) { && parameter.FindString(MDSU_VALUES, &fUsername) == B_OK) {
hasUsername = true; hasUsername = true;
parameter.AddBool("Valid", true); parameter.AddBool(MDSU_VALID, true);
item.ReplaceMessage("Parameters", parameterIndex, &parameter); item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, &parameter);
} }
parameterIndex = 0; parameterIndex = 0;
if(FindMessageParameter("Password", item, parameter, &parameterIndex) if(FindMessageParameter("Password", item, parameter, &parameterIndex)
&& parameter.FindString("Values", &fPassword) == B_OK) { && parameter.FindString(MDSU_VALUES, &fPassword) == B_OK) {
fHasPassword = true; fHasPassword = true;
parameter.AddBool("Valid", true); parameter.AddBool(MDSU_VALID, true);
item.ReplaceMessage("Parameters", parameterIndex, &parameter); item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, &parameter);
} }
// tell DUN whether everything is valid // tell DUN whether everything is valid
if(hasUsername) if(hasUsername)
item.AddBool("Valid", true); item.AddBool(MDSU_VALID, true);
profile->ReplaceMessage("Parameters", itemIndex, &item); fProfile->ReplaceMessage(MDSU_PARAMETERS, itemIndex, &item);
return true; return true;
} }
@@ -213,14 +217,14 @@ GeneralAddon::IsAuthenticationModified(bool& settings, bool& profile) const
settings = fGeneralView->AuthenticatorName(); settings = fGeneralView->AuthenticatorName();
else { else {
BMessage authentication; BMessage authentication;
if(fSettings->FindMessage("Authentication", &authentication) != B_OK) { if(fSettings->FindMessage(GENERAL_TAB_AUTHENTICATION, &authentication) != B_OK) {
settings = profile = false; settings = profile = false;
return; return;
// error! // error!
} }
BString authenticator; BString authenticator;
if(authentication.FindString("Authenticators", &authenticator) != B_OK) { if(authentication.FindString(GENERAL_TAB_AUTHENTICATORS, &authenticator) != B_OK) {
settings = profile = false; settings = profile = false;
return; return;
// error! // error!
@@ -248,24 +252,24 @@ GeneralAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempo
if(fGeneralView->AuthenticatorName()) { if(fGeneralView->AuthenticatorName()) {
BMessage authenticator; BMessage authenticator;
authenticator.AddString("Name", PPP_AUTHENTICATOR_KEY); authenticator.AddString(MDSU_NAME, PPP_AUTHENTICATOR_KEY);
authenticator.AddString("Values", fGeneralView->AuthenticatorName()); authenticator.AddString(MDSU_VALUES, fGeneralView->AuthenticatorName());
settings->AddMessage("Parameters", &authenticator); settings->AddMessage(MDSU_PARAMETERS, &authenticator);
BMessage username; BMessage username;
username.AddString("Name", "User"); username.AddString(MDSU_NAME, "User");
username.AddString("Values", fGeneralView->Username()); username.AddString(MDSU_VALUES, fGeneralView->Username());
authenticator.AddMessage("Parameters", &username); authenticator.AddMessage(MDSU_PARAMETERS, &username);
if(saveTemporary || fGeneralView->DoesSavePassword()) { if(saveTemporary || fGeneralView->DoesSavePassword()) {
// save password, too // save password, too
BMessage password; BMessage password;
password.AddString("Name", "Password"); password.AddString(MDSU_NAME, "Password");
password.AddString("Values", fGeneralView->Password()); password.AddString(MDSU_VALUES, fGeneralView->Password());
authenticator.AddMessage("Parameters", &password); authenticator.AddMessage(MDSU_PARAMETERS, &password);
} }
profile->AddMessage("Parameters", &authenticator); profile->AddMessage(MDSU_PARAMETERS, &authenticator);
} }
return true; return true;
@@ -276,7 +280,7 @@ bool
GeneralAddon::GetPreferredSize(float *width, float *height) const GeneralAddon::GetPreferredSize(float *width, float *height) const
{ {
BRect rect; BRect rect;
if(Addons()->FindRect("TabViewRect", &rect) != B_OK) if(Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect) != B_OK)
rect.Set(0, 0, 200, 300); rect.Set(0, 0, 200, 300);
// set default values // set default values
@@ -294,7 +298,7 @@ GeneralAddon::CreateView(BPoint leftTop)
{ {
if(!fGeneralView) { if(!fGeneralView) {
BRect rect; BRect rect;
Addons()->FindRect("TabViewRect", &rect); Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
fGeneralView = new GeneralView(this, rect); fGeneralView = new GeneralView(this, rect);
} }
@@ -311,8 +315,8 @@ GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const
return false; return false;
BString name; BString name;
for(int32 index = 0; Addons()->FindMessage("Authenticator", index, entry) == B_OK; for(int32 index = 0; Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
index++) { entry) == B_OK; index++) {
entry->FindString("KernelModuleName", &name); entry->FindString("KernelModuleName", &name);
if(name == moduleName) if(name == moduleName)
return true; return true;
@@ -333,8 +337,8 @@ GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
&index); index++) { &index); index++) {
authenticator.FindString("KernelModuleName", &name); authenticator.FindString("KernelModuleName", &name);
if(name == moduleName) { if(name == moduleName) {
authenticator.AddBool("Valid", true); authenticator.AddBool(MDSU_VALID, true);
fSettings->ReplaceMessage("Parameters", index, &authenticator); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &authenticator);
return true; return true;
} }
} }
@@ -344,14 +348,15 @@ GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
GeneralView::GeneralView(GeneralAddon *addon, BRect frame) GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
: BView(frame, "GeneralView", B_FOLLOW_NONE, 0), : BView(frame, "General", B_FOLLOW_NONE, 0),
fAddon(addon) fAddon(addon)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
rect.InsetBy(5, 5); rect.InsetBy(5, 5);
rect.bottom = 100; rect.bottom = 100;
fDeviceBox = new BBox(rect, "Device"); fDeviceBox = new BBox(rect, "Device");
Addon()->Addons()->AddFloat("DeviceViewWidth", fDeviceBox->Bounds().Width() - 10); Addon()->Addons()->AddFloat(DUN_DEVICE_VIEW_WIDTH,
fDeviceBox->Bounds().Width() - 10);
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
@@ -436,8 +441,9 @@ GeneralView::Reload()
if(Addon()->CountAuthenticators() > 0) { if(Addon()->CountAuthenticators() > 0) {
BString kernelModule, authenticator; BString kernelModule, authenticator;
BMessage authentication; BMessage authentication;
if(Addon()->Settings()->FindMessage("Authentication", &authentication) == B_OK) if(Addon()->Settings()->FindMessage(GENERAL_TAB_AUTHENTICATION,
authentication.FindString("Authenticators", &authenticator); &authentication) == B_OK)
authentication.FindString(GENERAL_TAB_AUTHENTICATORS, &authenticator);
BMenu *menu = fAuthenticatorField->Menu(); BMenu *menu = fAuthenticatorField->Menu();
for(int32 index = 0; index < menu->CountItems(); index++) { for(int32 index = 0; index < menu->CountItems(); index++) {
item = menu->ItemAt(index); item = menu->ItemAt(index);
@@ -575,7 +581,8 @@ GeneralView::ReloadDeviceView()
void void
GeneralView::AddDevices() GeneralView::AddDevices()
{ {
AddAddonsToMenu(fDeviceField->Menu(), "Device", MSG_SELECT_DEVICE); AddAddonsToMenu(Addon()->Addons(), fDeviceField->Menu(), DUN_DEVICE_ADDON_TYPE,
MSG_SELECT_DEVICE);
} }
@@ -589,8 +596,8 @@ GeneralView::AddAuthenticators()
BMessage addon; BMessage addon;
for(int32 index = 0; for(int32 index = 0;
Addon()->Addons()->FindMessage("Authenticator", index, &addon) == B_OK; Addon()->Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
index++) { &addon) == B_OK; index++) {
BMessage *message = new BMessage(MSG_SELECT_AUTHENTICATOR); BMessage *message = new BMessage(MSG_SELECT_AUTHENTICATOR);
message->AddString("KernelModuleName", addon.FindString("KernelModuleName")); message->AddString("KernelModuleName", addon.FindString("KernelModuleName"));
@@ -616,48 +623,3 @@ GeneralView::AddAuthenticators()
insertAt); 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 = FindNextMenuInsertionIndex(menu, name);
menu->AddItem(new BMenuItem(name.String(), message), insertAt);
}
}
int32
GeneralView::FindNextMenuInsertionIndex(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;
}
@@ -14,7 +14,6 @@
#include <DialUpAddon.h> #include <DialUpAddon.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Message.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
@@ -53,8 +52,8 @@ class GeneralAddon : public DialUpAddon {
virtual int32 Position() const virtual int32 Position() const
{ return 0; } { return 0; }
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
bool LoadDeviceSettings(BMessage *settings, BMessage *profile); bool LoadDeviceSettings();
bool LoadAuthenticationSettings(BMessage *settings, BMessage *profile); bool LoadAuthenticationSettings();
virtual bool HasTemporaryProfile() const; virtual bool HasTemporaryProfile() const;
virtual void IsModified(bool& settings, bool& profile) const; virtual void IsModified(bool& settings, bool& profile) const;
@@ -109,9 +108,6 @@ class GeneralView : public BView {
void AddDevices(); void AddDevices();
void AddAuthenticators(); void AddAuthenticators();
void AddAddonsToMenu(BMenu *menu, const char *type, uint32 what);
int32 FindNextMenuInsertionIndex(BMenu *menu, const BString& name,
int32 index = 0);
private: private:
GeneralAddon *fAddon; GeneralAddon *fAddon;
@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
#include "InterfaceUtils.h"
#include "DialUpAddon.h"
#include <ListView.h>
#include <Menu.h>
#include <MenuItem.h>
#include <String.h>
#include <StringItem.h>
int32
FindNextMenuInsertionIndex(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;
}
int32
FindNextListInsertionIndex(BListView *list, const BString& name)
{
int32 index = 0;
BStringItem *item;
for(; index < list->CountItems(); index++) {
item = static_cast<BStringItem*>(list->ItemAt(index));
if(item && name.ICompare(item->Text()) <= 0)
return index;
}
return index;
}
void
AddAddonsToMenu(const BMessage *source, BMenu *menu, const char *type, uint32 what)
{
DialUpAddon *addon;
for(int32 index = 0; source->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 = FindNextMenuInsertionIndex(menu, name);
menu->AddItem(new BMenuItem(name.String(), message), insertAt);
}
}
@@ -0,0 +1,26 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
#ifndef _INTERFACE_UTILS__H
#define _INTERFACE_UTILS__H
#include <SupportDefs.h>
class DialUpAddon;
class BListView;
class BMenu;
class BString;
extern int32 FindNextMenuInsertionIndex(BMenu *menu, const BString& name,
int32 index = 0);
extern int32 FindNextListInsertionIndex(BListView *list, const BString& name);
extern void AddAddonsToMenu(const BMessage *source, BMenu *menu, const char *type,
uint32 what);
#endif
+2
View File
@@ -12,11 +12,13 @@ SimpleTest DialUpPreflet :
DialUpView.cpp DialUpView.cpp
# utils # utils
InterfaceUtils.cpp
MessageDriverSettingsUtils.cpp MessageDriverSettingsUtils.cpp
# built-in add-ons # built-in add-ons
GeneralAddon.cpp GeneralAddon.cpp
PPPoEAddon.cpp PPPoEAddon.cpp
ProtocolsAddon.cpp
; ;
LinkSharedOSLibs DialUpPreflet : libppp.a be ; LinkSharedOSLibs DialUpPreflet : libppp.a be ;
@@ -1,3 +1,10 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
#include "MessageDriverSettingsUtils.h" #include "MessageDriverSettingsUtils.h"
#include <driver_settings.h> #include <driver_settings.h>
@@ -15,8 +22,8 @@ FindMessageParameter(const char *name, BMessage& message, BMessage& save,
// XXX: this should be removed when we can replace BMessage with something better // XXX: this should be removed when we can replace BMessage with something better
BString string; BString string;
int32 index = startIndex ? *startIndex : 0; int32 index = startIndex ? *startIndex : 0;
for(; message.FindMessage("Parameters", index, &save) == B_OK; index++) { for(; message.FindMessage(MDSU_PARAMETERS, index, &save) == B_OK; index++) {
if(save.FindString("Name", &string) == B_OK && string.ICompare(name) == 0) { if(save.FindString(MDSU_NAME, &string) == B_OK && string.ICompare(name) == 0) {
if(startIndex) if(startIndex)
*startIndex = index; *startIndex = index;
return true; return true;
@@ -35,18 +42,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(MDSU_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(MDSU_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(&parameter->parameters[index], parameterMessage); AddParameter(&parameter->parameters[index], parameterMessage);
message.AddMessage("Parameters", &parameterMessage); message.AddMessage(MDSU_PARAMETERS, &parameterMessage);
} }
return true; return true;
@@ -71,7 +78,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", &parameter); message.AddMessage(MDSU_PARAMETERS, &parameter);
} }
unload_driver_settings(handle); unload_driver_settings(handle);
@@ -96,7 +103,7 @@ 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(MDSU_NAME, &name) != B_OK || !name)
return false; return false;
BString line, word(name); BString line, word(name);
@@ -110,7 +117,7 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
line << '\"'; line << '\"';
line << ' '; line << ' ';
for(int32 index = 0; parameter.FindString("Values", index, &name) == B_OK; index++) for(int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK; index++)
if(name) { if(name) {
word = name; word = name;
EscapeWord(word); EscapeWord(word);
@@ -125,7 +132,7 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
type_code type; type_code type;
int32 parameterCount; int32 parameterCount;
parameter.GetInfo("Parameters", &type, &parameterCount); parameter.GetInfo(MDSU_PARAMETERS, &type, &parameterCount);
if(parameterCount > 0) if(parameterCount > 0)
line << '{'; line << '{';
@@ -135,7 +142,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(MDSU_PARAMETERS, index,
&subParameter) == B_OK; index++) &subParameter) == B_OK; index++)
WriteParameter(file, subParameter, level + 1); WriteParameter(file, subParameter, level + 1);
@@ -158,7 +165,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, &parameter) == B_OK; for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK;
index++) { index++) {
if(index > 0) if(index > 0)
file.Write("\n", 1); file.Write("\n", 1);
@@ -1,3 +1,10 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
#ifndef _MESSAGE_DRIVER_SETTINGS_UTILS__H #ifndef _MESSAGE_DRIVER_SETTINGS_UTILS__H
#define _MESSAGE_DRIVER_SETTINGS_UTILS__H #define _MESSAGE_DRIVER_SETTINGS_UTILS__H
@@ -6,6 +13,11 @@
class BMessage; class BMessage;
class BFile; class BFile;
#define MDSU_NAME "Name"
#define MDSU_VALUES "Values"
#define MDSU_PARAMETERS "Parameters"
#define MDSU_VALID "Valid"
extern bool FindMessageParameter(const char *name, BMessage& message, extern bool FindMessageParameter(const char *name, BMessage& message,
BMessage& save, int32 *startIndex = NULL); BMessage& save, int32 *startIndex = NULL);
+29 -26
View File
@@ -49,6 +49,8 @@ PPPoEAddon::PPPoEAddon(BMessage *addons)
PPPoEAddon::~PPPoEAddon() PPPoEAddon::~PPPoEAddon()
{ {
delete fPPPoEView;
// this may have been set to NULL from the view's destructor!
} }
@@ -93,41 +95,41 @@ PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
// error: no device // error: no device
BString name; BString name;
if(device.FindString("Values", &name) != B_OK || name != kKernelModuleName) if(device.FindString(MDSU_VALUES, &name) != B_OK || name != kKernelModuleName)
return false; return false;
// error: no device // error: no device
BMessage parameter; BMessage parameter;
int32 index = 0; int32 index = 0;
if(!FindMessageParameter(PPPoE_INTERFACE_KEY, device, parameter, &index) if(!FindMessageParameter(PPPoE_INTERFACE_KEY, device, parameter, &index)
|| parameter.FindString("Values", &fInterfaceName) != B_OK) || parameter.FindString(MDSU_VALUES, &fInterfaceName) != B_OK)
return false; return false;
// error: no interface // error: no interface
else { else {
parameter.AddBool("Valid", true); parameter.AddBool(MDSU_VALID, true);
device.ReplaceMessage("Parameters", index, &parameter); device.ReplaceMessage(MDSU_PARAMETERS, index, &parameter);
} }
index = 0; index = 0;
if(!FindMessageParameter(PPPoE_AC_NAME_KEY, device, parameter, &index) if(!FindMessageParameter(PPPoE_AC_NAME_KEY, device, parameter, &index)
|| parameter.FindString("Values", &fACName) != B_OK) || parameter.FindString(MDSU_VALUES, &fACName) != B_OK)
fACName = ""; fACName = "";
else { else {
parameter.AddBool("Valid", true); parameter.AddBool(MDSU_VALID, true);
device.ReplaceMessage("Parameters", index, &parameter); device.ReplaceMessage(MDSU_PARAMETERS, index, &parameter);
} }
index = 0; index = 0;
if(!FindMessageParameter(PPPoE_SERVICE_NAME_KEY, device, parameter, &index) if(!FindMessageParameter(PPPoE_SERVICE_NAME_KEY, device, parameter, &index)
|| parameter.FindString("Values", &fServiceName) != B_OK) || parameter.FindString(MDSU_VALUES, &fServiceName) != B_OK)
fServiceName = ""; fServiceName = "";
else { else {
parameter.AddBool("Valid", true); parameter.AddBool(MDSU_VALID, true);
device.ReplaceMessage("Parameters", index, &parameter); device.ReplaceMessage(MDSU_PARAMETERS, index, &parameter);
} }
device.AddBool("Valid", true); device.AddBool(MDSU_VALID, true);
fSettings->ReplaceMessage("Parameters", deviceIndex, &device); fSettings->ReplaceMessage(MDSU_PARAMETERS, deviceIndex, &device);
return true; return true;
} }
@@ -157,30 +159,30 @@ PPPoEAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempora
// TODO: tell user that an interface is needed (if we fail because of this) // TODO: tell user that an interface is needed (if we fail because of this)
BMessage device, interface; BMessage device, interface;
device.AddString("Name", PPP_DEVICE_KEY); device.AddString(MDSU_NAME, PPP_DEVICE_KEY);
device.AddString("Values", kKernelModuleName); device.AddString(MDSU_VALUES, kKernelModuleName);
interface.AddString("Name", PPPoE_INTERFACE_KEY); interface.AddString(MDSU_NAME, PPPoE_INTERFACE_KEY);
interface.AddString("Values", fPPPoEView->InterfaceName()); interface.AddString(MDSU_VALUES, fPPPoEView->InterfaceName());
device.AddMessage("Parameters", &interface); device.AddMessage(MDSU_PARAMETERS, &interface);
if(fPPPoEView->ACName() && strlen(fPPPoEView->ACName()) > 0) { if(fPPPoEView->ACName() && strlen(fPPPoEView->ACName()) > 0) {
// save access concentrator, too // save access concentrator, too
BMessage ac; BMessage ac;
ac.AddString("Name", PPPoE_AC_NAME_KEY); ac.AddString(MDSU_NAME, PPPoE_AC_NAME_KEY);
ac.AddString("Values", fPPPoEView->ACName()); ac.AddString(MDSU_VALUES, fPPPoEView->ACName());
device.AddMessage("Parameters", &ac); device.AddMessage(MDSU_PARAMETERS, &ac);
} }
if(fPPPoEView->ServiceName() && strlen(fPPPoEView->ServiceName()) > 0) { if(fPPPoEView->ServiceName() && strlen(fPPPoEView->ServiceName()) > 0) {
// save service name, too // save service name, too
BMessage service; BMessage service;
service.AddString("Name", PPPoE_SERVICE_NAME_KEY); service.AddString(MDSU_NAME, PPPoE_SERVICE_NAME_KEY);
service.AddString("Values", fPPPoEView->ServiceName()); service.AddString(MDSU_VALUES, fPPPoEView->ServiceName());
device.AddMessage("Parameters", &service); device.AddMessage(MDSU_PARAMETERS, &service);
} }
settings->AddMessage("Parameters", &device); settings->AddMessage(MDSU_PARAMETERS, &device);
return true; return true;
} }
@@ -190,7 +192,7 @@ bool
PPPoEAddon::GetPreferredSize(float *width, float *height) const PPPoEAddon::GetPreferredSize(float *width, float *height) const
{ {
float viewWidth; float viewWidth;
if(Addons()->FindFloat("DeviceViewWidth", &viewWidth) != B_OK) if(Addons()->FindFloat(DUN_DEVICE_VIEW_WIDTH, &viewWidth) != B_OK)
viewWidth = 270; viewWidth = 270;
// default value // default value
@@ -208,7 +210,7 @@ PPPoEAddon::CreateView(BPoint leftTop)
{ {
if(!fPPPoEView) { if(!fPPPoEView) {
float width; float width;
if(!Addons()->FindFloat("DeviceViewWidth", &width)) if(!Addons()->FindFloat(DUN_DEVICE_VIEW_WIDTH, &width))
width = 270; width = 270;
// default value // default value
@@ -303,6 +305,7 @@ PPPoEView::PPPoEView(PPPoEAddon *addon, BRect frame)
PPPoEView::~PPPoEView() PPPoEView::~PPPoEView()
{ {
Addon()->UnregisterView();
} }
@@ -13,8 +13,6 @@
#include <DialUpAddon.h> #include <DialUpAddon.h>
#include <CheckBox.h>
#include <Message.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
@@ -53,6 +51,9 @@ class PPPoEAddon : public DialUpAddon {
bool saveTemporary); bool saveTemporary);
virtual bool GetPreferredSize(float *width, float *height) const; virtual bool GetPreferredSize(float *width, float *height) const;
virtual BView *CreateView(BPoint leftTop); virtual BView *CreateView(BPoint leftTop);
void UnregisterView()
{ fPPPoEView = NULL; }
private: private:
bool fIsNew; bool fIsNew;
@@ -0,0 +1,468 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
// ProtocolsAddon saves the loaded settings.
// ProtocolsView saves the current settings.
//-----------------------------------------------------------------------
#include "ProtocolsAddon.h"
#include "InterfaceUtils.h"
#include "MessageDriverSettingsUtils.h"
#include <Button.h>
#include <ListView.h>
#include <MenuItem.h>
#include <Message.h>
#include <PopUpMenu.h>
#include <ScrollView.h>
#include <StringItem.h>
#include <PPPDefs.h>
#define MSG_ADD_PROTOCOL 'ADDP'
#define MSG_REMOVE_PROTOCOL 'REMP'
#define MSG_SHOW_PREFERENCES 'SHOW'
#define MSG_UPDATE_BUTTONS 'UBTN'
#define PROTOCOLS_TAB_PROTOCOLS "Protocols"
ProtocolsAddon::ProtocolsAddon(BMessage *addons)
: DialUpAddon(addons),
fProtocolsCount(0),
fSettings(NULL),
fProfile(NULL),
fProtocolsView(NULL)
{
}
ProtocolsAddon::~ProtocolsAddon()
{
}
bool
ProtocolsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
{
fIsNew = isNew;
fProtocolsCount = 0;
fSettings = settings;
fProfile = profile;
if(fProtocolsView)
fProtocolsView->Reload();
// reset all views (empty settings)
if(!settings || !profile || isNew)
return true;
// ask protocols to load their settings
BMessage parameter;
for(int32 index = 0; FindMessageParameter(PPP_PROTOCOL_KEY, *fProfile, parameter,
&index); index++)
if(!LoadProtocolSettings(parameter))
return false;
// error: some protocol did not accept its settings
if(fProtocolsView)
fProtocolsView->Reload();
// reload new settings
return true;
}
bool
ProtocolsAddon::LoadProtocolSettings(const BMessage& parameter)
{
// TODO: Maybe we should only load the first add-on because we cannot know
// whether the settings are acceptable for all listed protocols.
// In addition to this, maybe the protocol itself chose this format because
// it consists of two modules.
// get protocols and ask them to load their settings
BString name;
for(int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK;
index++) {
DialUpAddon *protocol;
if(!GetProtocol(name, &protocol))
return false;
// fatal error: we do not know how to handle this protocol
if(!protocol->LoadSettings(fSettings, fProfile, false))
return false;
// error: protocol did not accept its settings
fSettings->AddPointer(PROTOCOLS_TAB_PROTOCOLS, protocol);
++fProtocolsCount;
}
return true;
}
bool
ProtocolsAddon::HasTemporaryProfile() const
{
if(!fProtocolsView)
return false;
DialUpAddon *protocol;
for(int32 index = 0; index < fProtocolsView->CountProtocols(); index++) {
protocol = fProtocolsView->ProtocolAt(index);
if(protocol && protocol->HasTemporaryProfile())
return true;
}
return false;
}
void
ProtocolsAddon::IsModified(bool& settings, bool& profile) const
{
settings = profile = false;
if(!fSettings || !fProtocolsView)
return;
if(CountProtocols() != fProtocolsView->CountProtocols()) {
settings = profile = true;
return;
}
DialUpAddon *protocol;
bool protocolSettingsChanged, protocolProfileChanged;
// for current protocol
for(int32 index = 0; fSettings->FindPointer(PROTOCOLS_TAB_PROTOCOLS, index,
reinterpret_cast<void**>(&protocol)) == B_OK; index++) {
if(!protocol->KernelModuleName() // this is actually an error
|| !fProtocolsView->HasProtocol(protocol->KernelModuleName())) {
settings = profile = true;
return;
}
protocol->IsModified(protocolSettingsChanged, protocolProfileChanged);
if(protocolSettingsChanged)
settings = true;
if(protocolProfileChanged)
profile = true;
}
}
bool
ProtocolsAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
{
if(!fSettings || !settings)
return false;
DialUpAddon *protocol;
for(int32 index = 0; index < fProtocolsView->CountProtocols(); index++) {
protocol = fProtocolsView->ProtocolAt(index);
if(!protocol->SaveSettings(settings, profile, saveTemporary))
return false;
}
return true;
}
bool
ProtocolsAddon::GetPreferredSize(float *width, float *height) const
{
BRect rect;
if(Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect) != B_OK)
rect.Set(0, 0, 200, 300);
// set default values
if(width)
*width = rect.Width();
if(height)
*height = rect.Height();
return true;
}
BView*
ProtocolsAddon::CreateView(BPoint leftTop)
{
if(!fProtocolsView) {
BRect rect;
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
fProtocolsView = new ProtocolsView(this, rect);
}
fProtocolsView->MoveTo(leftTop);
fProtocolsView->Reload();
return fProtocolsView;
}
bool
ProtocolsAddon::GetProtocol(const BString& moduleName, DialUpAddon **protocol) const
{
if(!protocol)
return false;
for(int32 index = 0; Addons()->FindPointer(DUN_PROTOCOL_ADDON_TYPE, index,
reinterpret_cast<void**>(protocol)) == B_OK; index++)
if((*protocol)->KernelModuleName()
&& moduleName == (*protocol)->KernelModuleName())
return true;
return false;
}
// we need a simple BListItem that can hold a pointer to the DialUpAddon it represents
class AddonItem : public BStringItem {
public:
AddonItem(const char *label, DialUpAddon *addon) : BStringItem(label),
fAddon(addon) {}
DialUpAddon *Addon() const
{ return fAddon; }
private:
DialUpAddon *fAddon;
};
ProtocolsView::ProtocolsView(ProtocolsAddon *addon, BRect frame)
: BView(frame, "Protocols", B_FOLLOW_NONE, 0),
fAddon(addon)
{
BRect rect = Bounds();
rect.InsetBy(10, 10);
rect.bottom = 200;
BRect listViewRect(rect);
listViewRect.right -= B_V_SCROLL_BAR_WIDTH;
fListView = new BListView(listViewRect, "Protocols");
fListView->SetInvocationMessage(new BMessage(MSG_SHOW_PREFERENCES));
fListView->SetSelectionMessage(new BMessage(MSG_UPDATE_BUTTONS));
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 25;
float buttonWidth = (rect.Width() - 20) / 3;
rect.right = rect.left + buttonWidth;
fAddButton = new BButton(rect, "AddButton", "Add Protocol",
new BMessage(MSG_ADD_PROTOCOL));
rect.left = rect.right + 10;
rect.right = rect.left + buttonWidth;
fRemoveButton = new BButton(rect, "RemoveButton", "Remove",
new BMessage(MSG_REMOVE_PROTOCOL));
rect.left = rect.right + 10;
rect.right = rect.left + buttonWidth;
fPreferencesButton = new BButton(rect, "PreferencesButton", "Preferences",
new BMessage(MSG_SHOW_PREFERENCES));
AddChild(new BScrollView("ScrollView", fListView, B_FOLLOW_NONE, 0, false, true));
AddChild(fAddButton);
AddChild(fRemoveButton);
AddChild(fPreferencesButton);
fProtocolsMenu = new BPopUpMenu("UnregisteredProtocols", false, false);
AddAddonsToMenu(Addon()->Addons(), fProtocolsMenu, DUN_PROTOCOL_ADDON_TYPE, 0);
}
ProtocolsView::~ProtocolsView()
{
delete fProtocolsMenu;
AddonItem *item;
while(fListView->CountItems() > 0) {
item = dynamic_cast<AddonItem*>(fListView->RemoveItem((int32) 0));
delete item;
}
}
void
ProtocolsView::Reload()
{
// move all protocols back to the menu
while(CountProtocols() > 0)
UnregisterProtocol(0);
if(!Addon()->Settings())
return;
// move all registered protocols to the list
DialUpAddon *protocol;
for(int32 index = 0; Addon()->Settings()->FindPointer(PROTOCOLS_TAB_PROTOCOLS,
index, reinterpret_cast<void**>(&protocol)) == B_OK; index++)
RegisterProtocol(protocol);
fListView->Select(0);
UpdateButtons();
}
void
ProtocolsView::AttachedToWindow()
{
SetViewColor(Parent()->ViewColor());
fListView->SetTarget(this);
fAddButton->SetTarget(this);
fRemoveButton->SetTarget(this);
fPreferencesButton->SetTarget(this);
}
void
ProtocolsView::MessageReceived(BMessage *message)
{
switch(message->what) {
case MSG_ADD_PROTOCOL: {
BMenuItem *selected = fProtocolsMenu->Go(fAddButton->ConvertToScreen(
fAddButton->Bounds().RightTop()));
RegisterProtocol(fProtocolsMenu->IndexOf(selected));
UpdateButtons();
} break;
case MSG_REMOVE_PROTOCOL: {
AddonItem *selected = dynamic_cast<AddonItem*>(
fListView->RemoveItem(fListView->CurrentSelection()));
UnregisterProtocol(fListView->IndexOf(selected));
UpdateButtons();
} break;
case MSG_SHOW_PREFERENCES: {
AddonItem *selected = dynamic_cast<AddonItem*>(
fListView->ItemAt(fListView->CurrentSelection()));
if(selected) {
DialUpAddon *addon = selected->Addon();
addon->CreateView(ConvertToScreen(Bounds().LeftTop()));
// show the preferences window
}
} break;
case MSG_UPDATE_BUTTONS:
UpdateButtons();
break;
default:
BView::MessageReceived(message);
}
}
DialUpAddon*
ProtocolsView::ProtocolAt(int32 index) const
{
AddonItem *item = dynamic_cast<AddonItem*>(fListView->ItemAt(index));
if(item)
return item->Addon();
return NULL;
}
bool
ProtocolsView::HasProtocol(const BString& moduleName) const
{
AddonItem *item;
for(int32 index = 0; index < CountProtocols(); index++) {
item = dynamic_cast<AddonItem*>(fListView->ItemAt(index));
if(item && moduleName == item->Addon()->KernelModuleName())
return true;
}
return false;
}
void
ProtocolsView::RegisterProtocol(const DialUpAddon *protocol)
{
if(!protocol)
return;
DialUpAddon *addon;
BMenuItem *item;
for(int32 index = 0; index < fProtocolsMenu->CountItems(); index++) {
item = fProtocolsMenu->ItemAt(index);
if(item && item->Message()->FindPointer("Addon",
reinterpret_cast<void**>(addon)) == B_OK && addon == protocol) {
RegisterProtocol(index);
return;
}
}
}
void
ProtocolsView::RegisterProtocol(int32 index)
{
DialUpAddon *addon;
BMenuItem *remove = fProtocolsMenu->ItemAt(index);
if(!remove || remove->Message()->FindPointer("Addon",
reinterpret_cast<void**>(addon)) != B_OK)
return;
const char *label = remove->Label();
AddonItem *item = new AddonItem(label, addon);
index = FindNextListInsertionIndex(fListView, label);
fListView->AddItem(item, index);
fProtocolsMenu->RemoveItem(remove);
delete remove;
}
void
ProtocolsView::UnregisterProtocol(int32 index)
{
AddonItem *remove = dynamic_cast<AddonItem*>(fListView->ItemAt(index));
if(!remove)
return;
const char *label = remove->Text();
BMessage *message = new BMessage(MSG_ADD_PROTOCOL);
// the 'what' field is merely set to get around the compiler warning
message->AddPointer("Addon", remove->Addon());
BMenuItem *item = new BMenuItem(label, message);
index = FindNextMenuInsertionIndex(fProtocolsMenu, label);
fProtocolsMenu->AddItem(item, index);
delete remove;
}
void
ProtocolsView::UpdateButtons()
{
if(fProtocolsMenu->CountItems() == 0)
fAddButton->SetEnabled(false);
else
fAddButton->SetEnabled(true);
if(CountProtocols() == 0)
fRemoveButton->SetEnabled(false);
else
fRemoveButton->SetEnabled(true);
AddonItem *item = dynamic_cast<AddonItem*>(fListView->ItemAt(
fListView->CurrentSelection()));
float width, height;
if(!item || !item->Addon()->GetPreferredSize(&width, &height))
fPreferencesButton->SetEnabled(false);
else
fPreferencesButton->SetEnabled(true);
}
@@ -0,0 +1,100 @@
//-----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//-----------------------------------------------------------------------
// ProtocolsAddon saves the loaded settings.
// ProtocolsView saves the current settings.
//-----------------------------------------------------------------------
#ifndef _PROTOCOLS_ADDON__H
#define _PROTOCOLS_ADDON__H
#include <DialUpAddon.h>
#include <ListView.h>
#include <String.h>
class ProtocolsView;
class ProtocolsAddon : public DialUpAddon {
public:
ProtocolsAddon(BMessage *addons);
virtual ~ProtocolsAddon();
bool IsNew() const
{ return fIsNew; }
int32 CountProtocols() const
{ return fProtocolsCount; }
BMessage *Settings() const
{ return fSettings; }
BMessage *Profile() const
{ return fProfile; }
virtual int32 Position() const
{ return 10; }
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
bool LoadProtocolSettings(const BMessage& parameter);
virtual bool HasTemporaryProfile() const;
virtual void IsModified(bool& settings, bool& profile) const;
virtual bool SaveSettings(BMessage *settings, BMessage *profile,
bool saveTemporary);
virtual bool GetPreferredSize(float *width, float *height) const;
virtual BView *CreateView(BPoint leftTop);
private:
bool GetProtocol(const BString& moduleName, DialUpAddon **protocol) const;
private:
bool fIsNew;
int32 fProtocolsCount;
BMessage *fSettings, *fProfile;
// saves last settings state
ProtocolsView *fProtocolsView;
};
class ProtocolsView : public BView {
public:
ProtocolsView(ProtocolsAddon *addon, BRect frame);
virtual ~ProtocolsView();
ProtocolsAddon *Addon() const
{ return fAddon; }
void Reload();
bool HasTemporaryProfile() const;
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
int32 CountProtocols() const
{ return fListView->CountItems(); }
DialUpAddon *ProtocolAt(int32 index) const;
bool HasProtocol(const BString& moduleName) const;
private:
void RegisterProtocol(const DialUpAddon *protocol);
void RegisterProtocol(int32 index);
// moves the protocol from the pop-up menu to the list view
void UnregisterProtocol(int32 index);
// moves the protocol from the list view to the pop-up menu
void UpdateButtons();
// enables/disables buttons depending on the current state
private:
ProtocolsAddon *fAddon;
BButton *fAddButton, *fRemoveButton, *fPreferencesButton;
BListView *fListView;
BPopUpMenu *fProtocolsMenu;
};
#endif
+3 -2
View File
@@ -1,12 +1,13 @@
Short-term TODOs: Short-term TODOs:
- see if we can reuse some code from the original DUN preflet - see if we can reuse some code from the original DUN preflet
- 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
- move DEVNOTES into a doxygen file and document the rest of the API - move DEVNOTES into a doxygen file and document the rest of the API
- use dynamic window positioning based on screen size instead of static coordinates - use dynamic window positioning based on screen size instead of static coordinates
- really delete interface description files when removing an interface
- open dialog asking for interface name when creating a new interface
Long-term TODOs: Long-term TODOs:
- allow selecting multiple authenticators - (maybe) allow selecting multiple authenticators (in expert-mode)