Axel told me the preflet is too complicated (thank you!). He was right, but I was a lazy programmer ;).

So here is the new version with much simpler dialogs.
The "Protocols" section is removed and all protocols add their own section. Protocols are now added/removed by changing the state of "Enabled" (a checkbox) in their section.
IPCP is named "TCP/IP", so everybody should know what can be found there.
All optional fields are marked as such ("(Optional)" to the right of each field).
Some labels were renamed (Dial -> Connect, etc.).
Added possibility to build a german version (I will ask some people around here if they find it easy to use).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7156 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2004-04-04 11:43:42 +00:00
parent efbf097f79
commit 8e0e1d0d3c
19 changed files with 655 additions and 1125 deletions
@@ -4,11 +4,11 @@
// //
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected] // Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ExtrasAddon saves the loaded settings. // ConnectionOptionsAddon saves the loaded settings.
// ExtrasView saves the current settings. // ConnectionOptionsView saves the current settings.
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
#include "ExtrasAddon.h" #include "ConnectionOptionsAddon.h"
#include "MessageDriverSettingsUtils.h" #include "MessageDriverSettingsUtils.h"
@@ -16,33 +16,47 @@
#include <settings_tools.h> #include <settings_tools.h>
#define MSG_UPDATE_CONTROLS 'UPDC' // message constants
static const uint32 kMsgUpdateControls = 'UPDC';
// labels
#ifdef LANG_GERMAN
static const char *kLabelConnectionOptions = "Verbindungs-Optionen";
static const char *kLabelDialOnDemand = "Bei Bedarf Automatisch Verbinden";
static const char *kLabelAskBeforeDialing = "Vor Dem Verbinden Fragen";
static const char *kLabelAutoRedial = "Verbindung Automatisch Wiederherstellen";
#else
static const char *kLabelConnectionOptions = "Connection Options";
static const char *kLabelDialOnDemand = "Connect Automatically When Needed";
static const char *kLabelAskBeforeDialing = "Ask Before Dialing";
static const char *kLabelAutoRedial = "Redial Automatically";
#endif
ExtrasAddon::ExtrasAddon(BMessage *addons) ConnectionOptionsAddon::ConnectionOptionsAddon(BMessage *addons)
: DialUpAddon(addons), : DialUpAddon(addons),
fSettings(NULL), fSettings(NULL),
fProfile(NULL), fProfile(NULL),
fExtrasView(NULL) fConnectionOptionsView(NULL)
{ {
} }
ExtrasAddon::~ExtrasAddon() ConnectionOptionsAddon::~ConnectionOptionsAddon()
{ {
} }
bool bool
ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) ConnectionOptionsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
{ {
fIsNew = isNew; fIsNew = isNew;
fDoesDialOnDemand = fAskBeforeDialing = fDoesAutoRedial = false; fDoesDialOnDemand = fAskBeforeDialing = fDoesAutoRedial = false;
fSettings = settings; fSettings = settings;
fProfile = profile; fProfile = profile;
if(fExtrasView) if(fConnectionOptionsView)
fExtrasView->Reload(); fConnectionOptionsView->Reload();
// reset all views (empty settings) // reset all views (empty settings)
if(!settings || !profile || isNew) if(!settings || !profile || isNew)
@@ -80,8 +94,8 @@ ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &parameter); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &parameter);
} }
if(fExtrasView) if(fConnectionOptionsView)
fExtrasView->Reload(); fConnectionOptionsView->Reload();
// reload new settings // reload new settings
return true; return true;
@@ -89,33 +103,33 @@ ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
void void
ExtrasAddon::IsModified(bool *settings, bool *profile) const ConnectionOptionsAddon::IsModified(bool *settings, bool *profile) const
{ {
*settings = *profile = false; *settings = *profile = false;
if(!fSettings || !fExtrasView) if(!fSettings || !fConnectionOptionsView)
return; return;
*settings = DoesDialOnDemand() != fExtrasView->DoesDialOnDemand() *settings = DoesDialOnDemand() != fConnectionOptionsView->DoesDialOnDemand()
|| AskBeforeDialing() != fExtrasView->AskBeforeDialing() || AskBeforeDialing() != fConnectionOptionsView->AskBeforeDialing()
|| DoesAutoRedial() != fExtrasView->DoesAutoRedial(); || DoesAutoRedial() != fConnectionOptionsView->DoesAutoRedial();
} }
bool bool
ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) ConnectionOptionsAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
{ {
if(!fSettings || !settings) if(!fSettings || !settings)
return false; return false;
BMessage parameter; BMessage parameter;
if(fExtrasView->DoesDialOnDemand()) { if(fConnectionOptionsView->DoesDialOnDemand()) {
parameter.MakeEmpty(); parameter.MakeEmpty();
parameter.AddString(MDSU_NAME, PPP_DIAL_ON_DEMAND_KEY); parameter.AddString(MDSU_NAME, PPP_DIAL_ON_DEMAND_KEY);
parameter.AddString(MDSU_VALUES, "enabled"); parameter.AddString(MDSU_VALUES, "enabled");
settings->AddMessage(MDSU_PARAMETERS, &parameter); settings->AddMessage(MDSU_PARAMETERS, &parameter);
if(fExtrasView->AskBeforeDialing()) { if(fConnectionOptionsView->AskBeforeDialing()) {
parameter.MakeEmpty(); parameter.MakeEmpty();
parameter.AddString(MDSU_NAME, PPP_ASK_BEFORE_DIALING_KEY); parameter.AddString(MDSU_NAME, PPP_ASK_BEFORE_DIALING_KEY);
parameter.AddString(MDSU_VALUES, "enabled"); parameter.AddString(MDSU_VALUES, "enabled");
@@ -123,7 +137,7 @@ ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempor
} }
} }
if(fExtrasView->DoesAutoRedial()) { if(fConnectionOptionsView->DoesAutoRedial()) {
parameter.MakeEmpty(); parameter.MakeEmpty();
parameter.AddString(MDSU_NAME, PPP_AUTO_REDIAL_KEY); parameter.AddString(MDSU_NAME, PPP_AUTO_REDIAL_KEY);
parameter.AddString(MDSU_VALUES, "enabled"); parameter.AddString(MDSU_VALUES, "enabled");
@@ -135,7 +149,7 @@ ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempor
bool bool
ExtrasAddon::GetPreferredSize(float *width, float *height) const ConnectionOptionsAddon::GetPreferredSize(float *width, float *height) const
{ {
BRect rect; BRect rect;
if(Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect) != B_OK) if(Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect) != B_OK)
@@ -152,58 +166,50 @@ ExtrasAddon::GetPreferredSize(float *width, float *height) const
BView* BView*
ExtrasAddon::CreateView(BPoint leftTop) ConnectionOptionsAddon::CreateView(BPoint leftTop)
{ {
if(!fExtrasView) { if(!fConnectionOptionsView) {
BRect rect; BRect rect;
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect); Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
fExtrasView = new ExtrasView(this, rect); fConnectionOptionsView = new ConnectionOptionsView(this, rect);
fExtrasView->Reload(); fConnectionOptionsView->Reload();
} }
fExtrasView->MoveTo(leftTop); fConnectionOptionsView->MoveTo(leftTop);
return fExtrasView; return fConnectionOptionsView;
} }
ExtrasView::ExtrasView(ExtrasAddon *addon, BRect frame) ConnectionOptionsView::ConnectionOptionsView(ConnectionOptionsAddon *addon, BRect frame)
: BView(frame, "Extras", B_FOLLOW_NONE, 0), : BView(frame, kLabelConnectionOptions, B_FOLLOW_NONE, 0),
fAddon(addon) fAddon(addon)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
rect.InsetBy(10, 10); rect.InsetBy(10, 10);
rect.bottom = rect.top + 15; rect.bottom = rect.top + 15;
fDialOnDemand = new BRadioButton(rect, "DialOnDemand", "Dial On Demand", fDialOnDemand = new BCheckBox(rect, "DialOnDemand", kLabelDialOnDemand,
new BMessage(MSG_UPDATE_CONTROLS)); new BMessage(kMsgUpdateControls));
rect.top = rect.bottom + 3; rect.top = rect.bottom + 3;
rect.bottom = rect.top + 15; rect.bottom = rect.top + 15;
rect.left += 15; rect.left += 20;
fAskBeforeDialing = new BCheckBox(rect, "AskBeforeDialing", "Ask Before Dialing", fAskBeforeDialing = new BCheckBox(rect, "AskBeforeDialing", kLabelAskBeforeDialing,
NULL); NULL);
rect.left -= 15; rect.left -= 20;
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 15;
fDialManually = new BRadioButton(rect, "DialManually", "Dial Manually",
new BMessage(MSG_UPDATE_CONTROLS));
rect.top = rect.bottom + 20; rect.top = rect.bottom + 20;
rect.bottom = rect.top + 15; rect.bottom = rect.top + 15;
fAutoRedial = new BCheckBox(rect, "AutoRedial", "Auto-Redial", NULL); fAutoRedial = new BCheckBox(rect, "AutoRedial", kLabelAutoRedial, NULL);
AddChild(fDialOnDemand); AddChild(fDialOnDemand);
AddChild(fAskBeforeDialing); AddChild(fAskBeforeDialing);
AddChild(fDialManually);
AddChild(fAutoRedial); AddChild(fAutoRedial);
} }
void void
ExtrasView::Reload() ConnectionOptionsView::Reload()
{ {
if(Addon()->DoesDialOnDemand() || Addon()->IsNew()) fDialOnDemand->SetValue(Addon()->DoesDialOnDemand() || Addon()->IsNew());
fDialOnDemand->SetValue(1); // this is enabled by default
else
fDialManually->SetValue(1);
fAskBeforeDialing->SetValue(Addon()->AskBeforeDialing()); fAskBeforeDialing->SetValue(Addon()->AskBeforeDialing());
fAutoRedial->SetValue(Addon()->DoesAutoRedial()); fAutoRedial->SetValue(Addon()->DoesAutoRedial());
@@ -215,19 +221,18 @@ ExtrasView::Reload()
void void
ExtrasView::AttachedToWindow() ConnectionOptionsView::AttachedToWindow()
{ {
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
fDialOnDemand->SetTarget(this); fDialOnDemand->SetTarget(this);
fDialManually->SetTarget(this);
} }
void void
ExtrasView::MessageReceived(BMessage *message) ConnectionOptionsView::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case MSG_UPDATE_CONTROLS: case kMsgUpdateControls:
UpdateControls(); UpdateControls();
break; break;
@@ -238,13 +243,12 @@ ExtrasView::MessageReceived(BMessage *message)
void void
ExtrasView::UpdateControls() ConnectionOptionsView::UpdateControls()
{ {
if(fDialManually->Value()) if(fDialOnDemand->Value())
fAskBeforeDialing->SetEnabled(false);
else
fAskBeforeDialing->SetEnabled(true); fAskBeforeDialing->SetEnabled(true);
else
fAskBeforeDialing->SetEnabled(false);
fAskBeforeDialing->SetValue(1); fAskBeforeDialing->SetValue(fDialOnDemand->Value());
// this should be enabled by default
} }
@@ -4,25 +4,25 @@
// //
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected] // Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ExtrasAddon saves the loaded settings. // ConnectionOptionsAddon saves the loaded settings.
// ExtrasView saves the current settings. // ConnectionOptionsView saves the current settings.
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
#ifndef _EXTRAS_ADDON__H #ifndef _CONNECTION_OPTIONS_ADDON__H
#define _EXTRAS_ADDON__H #define _CONNECTION_OPTIONS_ADDON__H
#include <DialUpAddon.h> #include <DialUpAddon.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <RadioButton.h> #include <RadioButton.h>
class ExtrasView; class ConnectionOptionsView;
class ExtrasAddon : public DialUpAddon { class ConnectionOptionsAddon : public DialUpAddon {
public: public:
ExtrasAddon(BMessage *addons); ConnectionOptionsAddon(BMessage *addons);
virtual ~ExtrasAddon(); virtual ~ConnectionOptionsAddon();
bool IsNew() const bool IsNew() const
{ return fIsNew; } { return fIsNew; }
@@ -53,15 +53,15 @@ class ExtrasAddon : public DialUpAddon {
bool fDoesDialOnDemand, fAskBeforeDialing, fDoesAutoRedial; bool fDoesDialOnDemand, fAskBeforeDialing, fDoesAutoRedial;
BMessage *fSettings, *fProfile; BMessage *fSettings, *fProfile;
// saves last settings state // saves last settings state
ExtrasView *fExtrasView; ConnectionOptionsView *fConnectionOptionsView;
}; };
class ExtrasView : public BView { class ConnectionOptionsView : public BView {
public: public:
ExtrasView(ExtrasAddon *addon, BRect frame); ConnectionOptionsView(ConnectionOptionsAddon *addon, BRect frame);
ExtrasAddon *Addon() const ConnectionOptionsAddon *Addon() const
{ return fAddon; } { return fAddon; }
void Reload(); void Reload();
@@ -79,9 +79,8 @@ class ExtrasView : public BView {
void UpdateControls(); void UpdateControls();
private: private:
ExtrasAddon *fAddon; ConnectionOptionsAddon *fAddon;
BCheckBox *fAskBeforeDialing, *fAutoRedial; BCheckBox *fDialOnDemand, *fAskBeforeDialing, *fAutoRedial;
BRadioButton *fDialOnDemand, *fDialManually;
}; };
+1 -5
View File
@@ -6,7 +6,7 @@ All add-ons must add a "Valid" boolean value to every recognized parameter. The
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
Add-on registration: Add-on registration:
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
Tabs: Tabs and Protocols (protocols are tabs):
DUN_TAB_ADDON_TYPE : pointer to DialUpAddon object DUN_TAB_ADDON_TYPE : pointer to DialUpAddon object
Authenticators: Authenticators:
@@ -21,10 +21,6 @@ DUN_AUTHENTICATOR_ADDON_TYPE : BMessage with the following entries:
Devices: Devices:
DUN_DEVICE_ADDON_TYPE : pointer to DialUpAddon object DUN_DEVICE_ADDON_TYPE : pointer to DialUpAddon object
Protocols:
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:
DUN_DELETE_ON_QUIT : pointer to DialUpAddon object - this will be deleted when the preflet quits DUN_DELETE_ON_QUIT : pointer to DialUpAddon object - this will be deleted when the preflet quits
(you should register all your addons here, too) (you should register all your addons here, too)
@@ -18,6 +18,11 @@
#include <Point.h> #include <Point.h>
// -------------------------------------------
// uncomment the language (English by default)
// #define LANG_GERMAN
// -------------------------------------------
#define DUN_MAXIMUM_PRIORITY 50 #define DUN_MAXIMUM_PRIORITY 50
// add-on types // add-on types
@@ -13,7 +13,7 @@
#include "DialUpView.h" #include "DialUpView.h"
#define DIAL_UP_SIGNATURE "application/x-obos.dial-up-preflet" static const char *kSignature = "application/x-obos.dial-up-preflet";
class DialUpApplication : public BApplication { class DialUpApplication : public BApplication {
@@ -33,16 +33,18 @@ class DialUpWindow : public BWindow {
int main() int main()
{ {
DialUpApplication *app = new DialUpApplication(); new DialUpApplication();
app->Run(); be_app->Run();
delete be_app;
return 0; return 0;
} }
DialUpApplication::DialUpApplication() DialUpApplication::DialUpApplication()
: BApplication(DIAL_UP_SIGNATURE) : BApplication(kSignature)
{ {
BRect rect(150, 50, 450, 435); BRect rect(150, 50, 450, 435);
DialUpWindow *window = new DialUpWindow(rect); DialUpWindow *window = new DialUpWindow(rect);
+177 -80
View File
@@ -14,14 +14,13 @@
#include "TextRequestDialog.h" #include "TextRequestDialog.h"
// built-in add-ons // built-in add-ons
#include "ExtrasAddon.h" #include "ConnectionOptionsAddon.h"
#include "GeneralAddon.h" #include "GeneralAddon.h"
#include "IPCPAddon.h" #include "IPCPAddon.h"
#include "PPPoEAddon.h" #include "PPPoEAddon.h"
#include "ProtocolsAddon.h"
#include <PPPInterface.h> #include <PPPInterface.h>
#include <settings_tools.h>
#include <TemplateList.h> #include <TemplateList.h>
#include <Application.h> #include <Application.h>
@@ -41,35 +40,74 @@
#include <Path.h> #include <Path.h>
#define MSG_CREATE_NEW 'NEWI' // message constants
#define MSG_FINISH_CREATE_NEW 'FNEW' static const uint32 kMsgCreateNew = 'NEWI';
#define MSG_DELETE_CURRENT 'DELI' static const uint32 kMsgFinishCreateNew = 'FNEW';
#define MSG_SELECT_INTERFACE 'SELI' static const uint32 kMsgDeleteCurrent = 'DELI';
#define MSG_CONNECT_BUTTON 'CONI' static const uint32 kMsgSelectInterface = 'SELI';
static const uint32 kMsgConnectButton = 'CONI';
#define LABEL_CREATE_NEW "Create New..." // labels
#define LABEL_DELETE_CURRENT "Delete Current" #ifdef LANG_GERMAN
static const char *kLabelInterface = "Verbindung: ";
static const char *kLabelInterfaceName = "Verbindungs-Name: ";
static const char *kLabelNewInterface = "Neue Verbindung";
static const char *kLabelCreateNew = "Neu...";
static const char *kLabelDeleteCurrent = "Auswahl Löschen";
static const char *kLabelConnect = "Verbinden";
static const char *kLabelDisconnect = "Trennen";
static const char *kLabelOK = "OK";
#else
static const char *kLabelInterface = "Interface: ";
static const char *kLabelInterfaceName = "Interface Name: ";
static const char *kLabelNewInterface = "New Interface";
static const char *kLabelCreateNew = "Create New...";
static const char *kLabelDeleteCurrent = "Delete Current";
static const char *kLabelConnect = "Connect";
static const char *kLabelDisconnect = "Disconnect";
static const char *kLabelOK = "OK";
#endif
#define LABEL_CONNECT "Connect" // connection status strings
#define LABEL_DISCONNECT "Disconnect" #ifdef LANG_GERMAN
static const char *kTextConnecting = "Verbinde...";
static const char *kTextConnectionEstablished = "Verbindung hergestellt.";
static const char *kTextNotConnected = "Nicht verbunden.";
static const char *kTextAuthenticating = "Authentifizierung...";
static const char *kTextAuthenticationFailed = "Authentifizierung fehlgeschlagen!";
static const char *kTextConnectionLost = "Verbindung verloren!";
static const char *kTextCreationError = "Fehler beim Initialisieren!";
static const char *kTextNoInterfacesFound = "Kein Verbindungen gefunden...";
#else
static const char *kTextConnecting = "Connecting...";
static const char *kTextConnectionEstablished = "Connection established.";
static const char *kTextNotConnected = "Not connected.";
static const char *kTextAuthenticating = "Authenticating...";
static const char *kTextAuthenticationFailed = "Authentication failed!";
static const char *kTextConnectionLost = "Connection lost!";
static const char *kTextCreationError = "Error creating interface!";
static const char *kTextNoInterfacesFound = "No interfaces found...";
#endif
#define TEXT_CONNECTING "Connecting..." // error strings for alerts
#define TEXT_CONNECTION_ESTABLISHED "Connection established." #ifdef LANG_GERMAN
#define TEXT_NOT_CONNECTED "Not connected." static const char *kErrorTitle = "Fehler";
#define TEXT_DEVICE_ERROR "Device error!" static const char *kErrorNoPPPStack = "Fehler: Kein Zugriff auf den PPP Stack!";
#define TEXT_AUTHENTICATING "Authenticating..." static const char *kErrorInterfaceExists = "Fehler: Eine Verbindung mit diesem Namen "
#define TEXT_AUTHENTICATION_FAILED "Authentication failed!" "existiert bereits!";
#define TEXT_CONNECTION_LOST "Connection lost!" static const char *kErrorLoadingFailed = "Fehler: Konfiguration ist fehlerhaft! Die "
#define TEXT_CREATION_ERROR "Error creating interface!" "Einstellungen werden zurückgesetzt.";
#define TEXT_NO_INTERFACES_FOUND "No interfaces found..." static const char *kErrorSavingFailed = "Fehler: Speichern der Einstellungen ist "
#define TEXT_OK "OK" "fehlgeschlagen!";
#define ERROR_TITLE "Error" #else
#define ERROR_NO_PPP_STACK "Error: Could not find the PPP stack!" static const char *kErrorTitle = "Error";
#define ERROR_INTERFACE_EXISTS "Error: An interface with this name already " \ static const char *kErrorNoPPPStack = "Error: Could not access the PPP stack!";
"exists!" static const char *kErrorInterfaceExists = "Error: An interface with this name "
#define ERROR_LOADING_FAILED "Error: Failed loading interface! The current " \ "already exists!";
"settings will be deleted." static const char *kErrorLoadingFailed = "Error: Failed loading interface! The "
#define ERROR_SAVING_FAILED "Error: Failed saving interface settings!" "current settings will be deleted.";
static const char *kErrorSavingFailed = "Error: Failed saving interface settings!";
#endif
static static
@@ -99,12 +137,12 @@ DialUpView::DialUpView(BRect frame)
fAddons.AddMessenger(DUN_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(kLabelCreateNew);
BRect rect = bounds; BRect rect = bounds;
rect.InsetBy(5, 5); rect.InsetBy(5, 5);
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fMenuField = new BMenuField(rect, "Interfaces", "Interface:", fInterfaceMenu); fMenuField = new BMenuField(rect, "Interfaces", kLabelInterface, fInterfaceMenu);
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 10); fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 5);
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
rect.bottom = bounds.bottom rect.bottom = bounds.bottom
@@ -119,20 +157,20 @@ DialUpView::DialUpView(BRect frame)
stringRect.top += (stringRect.Height() - 15) / 2; stringRect.top += (stringRect.Height() - 15) / 2;
stringRect.bottom = stringRect.top + 15; stringRect.bottom = stringRect.top + 15;
fStringView = new BStringView(stringRect, "NoInterfacesFound", fStringView = new BStringView(stringRect, "NoInterfacesFound",
TEXT_NO_INTERFACES_FOUND); kTextNoInterfacesFound);
fStringView->SetAlignment(B_ALIGN_CENTER); fStringView->SetAlignment(B_ALIGN_CENTER);
fStringView->Hide(); fStringView->Hide();
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, "StatusView", TEXT_NOT_CONNECTED); fStatusView = new BStringView(rect, "StatusView", kTextNotConnected);
rect.InsetBy(0, -5); rect.InsetBy(0, -5);
rect.left = rect.right + 5; rect.left = rect.right + 5;
rect.right = bounds.right - 5; rect.right = bounds.right - 5;
fConnectButton = new BButton(rect, "ConnectButton", LABEL_CONNECT, fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect,
new BMessage(MSG_CONNECT_BUTTON)); new BMessage(kMsgConnectButton));
AddChild(fMenuField); AddChild(fMenuField);
AddChild(fTabView); AddChild(fTabView);
@@ -174,8 +212,11 @@ DialUpView::AttachedToWindow()
fInterfaceMenu->SetTargetForItems(this); fInterfaceMenu->SetTargetForItems(this);
fConnectButton->SetTarget(this); fConnectButton->SetTarget(this);
if(fListener.InitCheck() != B_OK) if(fListener.InitCheck() != B_OK) {
(new BAlert(ERROR_TITLE, ERROR_NO_PPP_STACK, TEXT_OK))->Go(NULL); (new BAlert(kErrorTitle, kErrorNoPPPStack, kLabelOK,
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
fConnectButton->Hide();
}
} }
@@ -188,12 +229,12 @@ DialUpView::MessageReceived(BMessage *message)
break; break;
// ------------------------------------------------- // -------------------------------------------------
case MSG_CREATE_NEW: { case kMsgCreateNew: {
(new TextRequestDialog("New Interface", "Interface Name: "))->Go( (new TextRequestDialog(kLabelNewInterface, kLabelInterfaceName))->Go(
new BInvoker(new BMessage(MSG_FINISH_CREATE_NEW), this)); new BInvoker(new BMessage(kMsgFinishCreateNew), this));
} break; } break;
case MSG_FINISH_CREATE_NEW: { case kMsgFinishCreateNew: {
int32 which; int32 which;
message->FindInt32("which", &which); message->FindInt32("which", &which);
const char *name = message->FindString("text"); const char *name = message->FindString("text");
@@ -205,7 +246,7 @@ DialUpView::MessageReceived(BMessage *message)
} break; } break;
// ------------------------------------------------- // -------------------------------------------------
case MSG_DELETE_CURRENT: { case kMsgDeleteCurrent: {
if(!fCurrentItem) if(!fCurrentItem)
return; return;
@@ -229,13 +270,13 @@ DialUpView::MessageReceived(BMessage *message)
// this stops watching the deleted interface // this stops watching the deleted interface
} break; } break;
case MSG_SELECT_INTERFACE: { case kMsgSelectInterface: {
int32 index; int32 index;
message->FindInt32("index", &index); message->FindInt32("index", &index);
SelectInterface(index); SelectInterface(index);
} break; } break;
case MSG_CONNECT_BUTTON: { case kMsgConnectButton: {
if(!fCurrentItem || fUpDownThread != -1) if(!fCurrentItem || fUpDownThread != -1)
return; return;
@@ -250,6 +291,42 @@ DialUpView::MessageReceived(BMessage *message)
} }
bool
DialUpView::SelectInterfaceNamed(const char *name)
{
BMenuItem *item = fInterfaceMenu->FindItem(name);
int32 index = fInterfaceMenu->IndexOf(item);
if(!item || index >= CountInterfaces())
return false;
SelectInterface(index);
return true;
}
BView*
DialUpView::AuthenticationView() const
{
return fGeneralAddon ? fGeneralAddon->AuthenticationView() : NULL;
}
BView*
DialUpView::StatusView() const
{
return fStatusView;
}
BView*
DialUpView::ConnectButton() const
{
return fConnectButton;
}
bool bool
DialUpView::LoadSettings(bool isNew) DialUpView::LoadSettings(bool isNew)
{ {
@@ -377,18 +454,28 @@ DialUpView::SaveSettingsToFile()
void void
DialUpView::UpDownThread() DialUpView::UpDownThread()
{ {
SaveSettingsToFile();
BMessage settings, profile;
SaveSettings(&settings, &profile, true);
// save temporary profile
driver_settings *temporaryProfile = MessageToDriverSettings(profile);
PPPInterface interface; PPPInterface interface;
if(fWatching == PPP_UNDEFINED_INTERFACE_ID) { if(fWatching == PPP_UNDEFINED_INTERFACE_ID) {
interface = fListener.Manager().InterfaceWithName(fCurrentItem->Label()); interface = fListener.Manager().InterfaceWithName(fCurrentItem->Label());
if(interface.InitCheck() != B_OK) if(interface.InitCheck() != B_OK)
interface = fListener.Manager().CreateInterfaceWithName( interface = fListener.Manager().CreateInterfaceWithName(
fCurrentItem->Label()); fCurrentItem->Label(), temporaryProfile);
} else } else {
interface = fWatching; interface = fWatching;
interface.SetProfile(temporaryProfile);
}
free_driver_settings(temporaryProfile);
if(interface.InitCheck() != B_OK) { if(interface.InitCheck() != B_OK) {
Window()->Lock(); Window()->Lock();
fStatusView->SetText(TEXT_CREATION_ERROR); fStatusView->SetText(kTextCreationError);
Window()->Unlock(); Window()->Unlock();
return; return;
} }
@@ -505,7 +592,7 @@ DialUpView::CreateTabs()
if(!addon->GetPreferredSize(&width, &height)) if(!addon->GetPreferredSize(&width, &height))
continue; continue;
target = addon->CreateView(BPoint(0,0)); target = addon->CreateView(BPoint(0, 0));
if(!target) if(!target)
continue; continue;
@@ -521,47 +608,52 @@ DialUpView::UpdateStatus(int32 code)
case PPP_REPORT_UP_ABORTED: case PPP_REPORT_UP_ABORTED:
case PPP_REPORT_DOWN_SUCCESSFUL: case PPP_REPORT_DOWN_SUCCESSFUL:
case PPP_REPORT_CONNECTION_LOST: { case PPP_REPORT_CONNECTION_LOST: {
fConnectButton->SetLabel(LABEL_CONNECT); fConnectButton->SetLabel(kLabelConnect);
} break; } break;
default: default:
fConnectButton->SetLabel(LABEL_DISCONNECT); fConnectButton->SetLabel(kLabelDisconnect);
} }
// maybe the information string must stay // maybe the information string must stay
if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL) if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL)
return; return;
if(fListener.InitCheck() != B_OK) {
fStatusView->SetText(kErrorNoPPPStack);
return;
}
switch(code) { switch(code) {
case PPP_REPORT_GOING_UP: case PPP_REPORT_GOING_UP:
fKeepLabel = false; fKeepLabel = false;
fStatusView->SetText(TEXT_CONNECTING); fStatusView->SetText(kTextConnecting);
break; break;
case PPP_REPORT_UP_SUCCESSFUL: case PPP_REPORT_UP_SUCCESSFUL:
fKeepLabel = false; fKeepLabel = false;
fStatusView->SetText(TEXT_CONNECTION_ESTABLISHED); fStatusView->SetText(kTextConnectionEstablished);
break; break;
case PPP_REPORT_UP_ABORTED: case PPP_REPORT_UP_ABORTED:
case PPP_REPORT_DOWN_SUCCESSFUL: case PPP_REPORT_DOWN_SUCCESSFUL:
fStatusView->SetText(TEXT_NOT_CONNECTED); fStatusView->SetText(kTextNotConnected);
break; break;
case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED: case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED:
case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED: case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED:
fStatusView->SetText(TEXT_AUTHENTICATING); fStatusView->SetText(kTextAuthenticating);
break; break;
case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED: case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED:
case PPP_REPORT_PEER_AUTHENTICATION_FAILED: case PPP_REPORT_PEER_AUTHENTICATION_FAILED:
fKeepLabel = true; fKeepLabel = true;
fStatusView->SetText(TEXT_AUTHENTICATION_FAILED); fStatusView->SetText(kTextAuthenticationFailed);
break; break;
case PPP_REPORT_CONNECTION_LOST: case PPP_REPORT_CONNECTION_LOST:
fKeepLabel = true; fKeepLabel = true;
fStatusView->SetText(TEXT_CONNECTION_LOST); fStatusView->SetText(kTextConnectionLost);
break; break;
} }
} }
@@ -612,10 +704,10 @@ void
DialUpView::LoadInterfaces() DialUpView::LoadInterfaces()
{ {
fInterfaceMenu->AddSeparatorItem(); fInterfaceMenu->AddSeparatorItem();
fInterfaceMenu->AddItem(new BMenuItem(LABEL_CREATE_NEW, fInterfaceMenu->AddItem(new BMenuItem(kLabelCreateNew,
new BMessage(MSG_CREATE_NEW))); new BMessage(kMsgCreateNew)));
fDeleterItem = new BMenuItem(LABEL_DELETE_CURRENT, fDeleterItem = new BMenuItem(kLabelDeleteCurrent,
new BMessage(MSG_DELETE_CURRENT)); new BMessage(kMsgDeleteCurrent));
fInterfaceMenu->AddItem(fDeleterItem); fInterfaceMenu->AddItem(fDeleterItem);
BDirectory settingsDirectory; BDirectory settingsDirectory;
@@ -635,32 +727,33 @@ void
DialUpView::LoadAddons() DialUpView::LoadAddons()
{ {
// Load integrated add-ons: // Load integrated add-ons:
// "Extras" tab // "Connection Options" tab
ExtrasAddon *extrasAddon = new ExtrasAddon(&fAddons); ConnectionOptionsAddon *connectionOptionsAddon =
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, extrasAddon); new ConnectionOptionsAddon(&fAddons);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, extrasAddon); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, connectionOptionsAddon);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, connectionOptionsAddon);
// "General" tab // "General" tab
GeneralAddon *generalAddon = new GeneralAddon(&fAddons); GeneralAddon *fGeneralAddon = new GeneralAddon(&fAddons);
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, generalAddon); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, fGeneralAddon);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, generalAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, fGeneralAddon);
// "IPCP" protocol // "IPCP" protocol
IPCPAddon *ipcpAddon = new IPCPAddon(&fAddons); IPCPAddon *ipcpAddon = new IPCPAddon(&fAddons);
fAddons.AddPointer(DUN_PROTOCOL_ADDON_TYPE, ipcpAddon); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, ipcpAddon);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, ipcpAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, ipcpAddon);
// "PPPoE" device // "PPPoE" device
PPPoEAddon *pppoeAddon = new PPPoEAddon(&fAddons); PPPoEAddon *pppoeAddon = new PPPoEAddon(&fAddons);
fAddons.AddPointer(DUN_DEVICE_ADDON_TYPE, pppoeAddon); fAddons.AddPointer(DUN_DEVICE_ADDON_TYPE, pppoeAddon);
fAddons.AddPointer(DUN_DELETE_ON_QUIT, 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"); #ifdef LANG_GERMAN
addon.AddString("FriendlyName", "Unverschlüsselt");
#else
addon.AddString("FriendlyName", "Plain-text Authentication"); addon.AddString("FriendlyName", "Plain-text Authentication");
#endif
addon.AddString("TechnicalName", "PAP"); addon.AddString("TechnicalName", "PAP");
addon.AddString("KernelModuleName", "pap");
fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon); fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon);
// addon.MakeEmpty(); // for next authenticator // addon.MakeEmpty(); // for next authenticator
@@ -673,11 +766,12 @@ void
DialUpView::AddInterface(const char *name, bool isNew = false) 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(NULL); (new BAlert(kErrorTitle, kErrorInterfaceExists, kLabelOK,
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
return; return;
} }
BMenuItem *item = new BMenuItem(name, new BMessage(MSG_SELECT_INTERFACE)); BMenuItem *item = new BMenuItem(name, new BMessage(kMsgSelectInterface));
item->SetTarget(this); item->SetTarget(this);
int32 index = FindNextMenuInsertionIndex(fInterfaceMenu, name); int32 index = FindNextMenuInsertionIndex(fInterfaceMenu, name);
if(index > CountInterfaces()) if(index > CountInterfaces())
@@ -698,7 +792,8 @@ DialUpView::SelectInterface(int32 index, bool isNew = false)
return; return;
if(fCurrentItem && !SaveSettingsToFile()) if(fCurrentItem && !SaveSettingsToFile())
(new BAlert(ERROR_TITLE, ERROR_SAVING_FAILED, TEXT_OK))->Go(NULL); (new BAlert(kErrorTitle, kErrorSavingFailed, kLabelOK,
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
if(index >= CountInterfaces() || index < 0) { if(index >= CountInterfaces() || index < 0) {
if(CountInterfaces() > 0) if(CountInterfaces() > 0)
@@ -723,10 +818,12 @@ DialUpView::SelectInterface(int32 index, bool isNew = false)
LoadSettings(false); LoadSettings(false);
// tell modules to unload all settings // tell modules to unload all settings
else if(!isNew && !LoadSettings(false)) { else if(!isNew && !LoadSettings(false)) {
(new BAlert(ERROR_TITLE, ERROR_LOADING_FAILED, TEXT_OK))->Go(NULL); (new BAlert(kErrorTitle, kErrorLoadingFailed, kLabelOK,
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
LoadSettings(true); LoadSettings(true);
} else if(isNew && !LoadSettings(true)) } else if(isNew && !LoadSettings(true))
(new BAlert(ERROR_TITLE, ERROR_LOADING_FAILED, TEXT_OK))->Go(NULL); (new BAlert(kErrorTitle, kErrorLoadingFailed, kLabelOK,
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
} }
@@ -748,7 +845,7 @@ DialUpView::UpdateControls()
} else if(!fTabView->IsHidden() && CountInterfaces() == 0) { } else if(!fTabView->IsHidden() && CountInterfaces() == 0) {
fDeleterItem->SetEnabled(false); fDeleterItem->SetEnabled(false);
fInterfaceMenu->SetRadioMode(false); fInterfaceMenu->SetRadioMode(false);
fInterfaceMenu->Superitem()->SetLabel(LABEL_CREATE_NEW); fInterfaceMenu->Superitem()->SetLabel(kLabelCreateNew);
fTabView->Hide(); fTabView->Hide();
fStringView->Show(); fStringView->Show();
fConnectButton->SetEnabled(false); fConnectButton->SetEnabled(false);
+10 -1
View File
@@ -8,11 +8,13 @@
#ifndef _DIAL_UP_VIEW__H #ifndef _DIAL_UP_VIEW__H
#define _DIAL_UP_VIEW__H #define _DIAL_UP_VIEW__H
#include <View.h>
#include <Message.h> #include <Message.h>
#include <View.h>
#include <PPPInterfaceListener.h> #include <PPPInterfaceListener.h>
class GeneralAddon;
class DialUpView : public BView { class DialUpView : public BView {
public: public:
@@ -24,6 +26,12 @@ class DialUpView : public BView {
void UpDownThread(); void UpDownThread();
// used by ppp_server
bool SelectInterfaceNamed(const char *name);
BView *AuthenticationView() const;
BView *StatusView() const;
BView *ConnectButton() const;
private: private:
void GetPPPDirectories(BDirectory *settingsDirectory, void GetPPPDirectories(BDirectory *settingsDirectory,
BDirectory *profileDirectory) const; BDirectory *profileDirectory) const;
@@ -58,6 +66,7 @@ class DialUpView : public BView {
BMenuItem *fCurrentItem, *fDeleterItem; BMenuItem *fCurrentItem, *fDeleterItem;
ppp_interface_id fWatching; ppp_interface_id fWatching;
GeneralAddon *fGeneralAddon;
bool fKeepLabel; bool fKeepLabel;
BStringView *fStatusView; BStringView *fStatusView;
BButton *fConnectButton; BButton *fConnectButton;
@@ -25,12 +25,36 @@
#include <PPPDefs.h> #include <PPPDefs.h>
#define MSG_SELECT_DEVICE 'SELD' // message constants
#define MSG_SELECT_AUTHENTICATOR 'SELA' static const uint32 kMsgSelectDevice = 'SELD';
static const uint32 kMsgSelectAuthenticator = 'SELA';
// labels
#ifdef LANG_GERMAN
static const char *kLabelGeneral = "Allgemein";
static const char *kLabelDevice = "Gerät: ";
static const char *kLabelNoDevicesFound = "Keine Geräte Gefunden!";
static const char *kLabelAuthenticator = "Login: ";
static const char *kLabelNoAuthenticatorsFound = "Keine Login-Methoden gefunden!";
static const char *kLabelName = "Name: ";
static const char *kLabelPassword = "Password: ";
static const char *kLabelSavePassword = "Password Speichern";
static const char *kLabelNone = "Ohne";
#else
static const char *kLabelGeneral = "General";
static const char *kLabelDevice = "Device: ";
static const char *kLabelNoDevicesFound = "No Devices Found!";
static const char *kLabelAuthenticator = "Login: ";
static const char *kLabelNoAuthenticatorsFound = "No Authenticators Found!";
static const char *kLabelName = "Name: ";
static const char *kLabelPassword = "Password: ";
static const char *kLabelSavePassword = "Save Password";
static const char *kLabelNone = "None";
#endif
#define GENERAL_TAB_AUTHENTICATION "Authentication" // string constants for information saved in the settings message
#define GENERAL_TAB_AUTHENTICATORS "Authenticators" static const char *kGeneralTabAuthentication = "Authentication";
static const char *kGeneralTabAuthenticators = "Authenticators";
#define DEFAULT_AUTHENTICATOR "PAP" #define DEFAULT_AUTHENTICATOR "PAP"
@@ -141,11 +165,11 @@ GeneralAddon::LoadAuthenticationSettings()
// 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(GENERAL_TAB_AUTHENTICATORS, name); authentication.AddString(kGeneralTabAuthenticators, name);
++fAuthenticatorsCount; ++fAuthenticatorsCount;
} }
fSettings->AddMessage(GENERAL_TAB_AUTHENTICATION, &authentication); fSettings->AddMessage(kGeneralTabAuthentication, &authentication);
bool hasUsername = false; bool hasUsername = false;
// a username must be present // a username must be present
@@ -218,14 +242,14 @@ GeneralAddon::IsAuthenticationModified(bool *settings, bool *profile) const
*settings = fGeneralView->AuthenticatorName(); *settings = fGeneralView->AuthenticatorName();
else { else {
BMessage authentication; BMessage authentication;
if(fSettings->FindMessage(GENERAL_TAB_AUTHENTICATION, &authentication) != B_OK) { if(fSettings->FindMessage(kGeneralTabAuthentication, &authentication) != B_OK) {
*settings = *profile = false; *settings = *profile = false;
return; return;
// error! // error!
} }
BString authenticator; BString authenticator;
if(authentication.FindString(GENERAL_TAB_AUTHENTICATORS, if(authentication.FindString(kGeneralTabAuthenticators,
&authenticator) != B_OK) { &authenticator) != B_OK) {
*settings = *profile = false; *settings = *profile = false;
return; return;
@@ -303,14 +327,21 @@ GeneralAddon::CreateView(BPoint leftTop)
BRect rect; BRect rect;
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect); Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
fGeneralView = new GeneralView(this, rect); fGeneralView = new GeneralView(this, rect);
fGeneralView->Reload();
} }
fGeneralView->MoveTo(leftTop); fGeneralView->MoveTo(leftTop);
fGeneralView->Reload();
return fGeneralView; return fGeneralView;
} }
BView*
GeneralAddon::AuthenticationView() const
{
return fGeneralView ? fGeneralView->AuthenticationView() : NULL;
}
bool bool
GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const
{ {
@@ -351,7 +382,7 @@ GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
GeneralView::GeneralView(GeneralAddon *addon, BRect frame) GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
: BView(frame, "General", B_FOLLOW_NONE, 0), : BView(frame, kLabelGeneral, B_FOLLOW_NONE, 0),
fAddon(addon) fAddon(addon)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
@@ -368,41 +399,49 @@ GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
fAuthenticationBox = new BBox(rect, "Authentication"); fAuthenticationBox = new BBox(rect, "Authentication");
fDeviceField = new BMenuField(BRect(5, 0, 250, 20), "Device", fDeviceField = new BMenuField(BRect(5, 0, 250, 20), "Device",
"Device:", new BPopUpMenu("No Devices Found!")); kLabelDevice, new BPopUpMenu(kLabelNoDevicesFound));
fDeviceField->SetDivider(StringWidth(fDeviceField->Label()) + 10); fDeviceField->SetDivider(StringWidth(fDeviceField->Label()) + 5);
fDeviceField->Menu()->SetRadioMode(true); fDeviceField->Menu()->SetRadioMode(true);
AddDevices(); AddDevices();
fDeviceBox->SetLabel(fDeviceField); fDeviceBox->SetLabel(fDeviceField);
fAuthenticatorField = new BMenuField(BRect(5, 0, 250, 20), "Authenticator", fAuthenticatorField = new BMenuField(BRect(5, 0, 250, 20), "Authenticator",
"Authenticator:", new BPopUpMenu("No Authenticators Found!")); kLabelAuthenticator, new BPopUpMenu(kLabelNoAuthenticatorsFound));
fAuthenticatorField->SetDivider(StringWidth(fAuthenticatorField->Label()) + 10); fAuthenticatorField->SetDivider(StringWidth(fAuthenticatorField->Label()) + 5);
fAuthenticatorField->Menu()->SetRadioMode(true); fAuthenticatorField->Menu()->SetRadioMode(true);
AddAuthenticators(); AddAuthenticators();
fAuthenticationBox->SetLabel(fAuthenticatorField); fAuthenticationBox->SetLabel(fAuthenticatorField);
rect = fAuthenticationBox->Bounds(); rect = fAuthenticationBox->Bounds();
rect.InsetBy(10, 0); rect.InsetBy(10, 5);
rect.top = 25; rect.top = 25;
// fAuthenticationView = new BControl(rect, "authenticationView", NULL, NULL,
// B_FOLLOW_NONE, 0);
// BControl automatically sets the view color when attached (we want that)
fAuthenticationView = new BView(rect, "authenticationView", B_FOLLOW_NONE, 0);
fAuthenticationView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rect = fAuthenticationView->Bounds();
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fUsername = new BTextControl(rect, "username", "Name: ", NULL, NULL); fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fPassword = new BTextControl(rect, "password", "Password: ", NULL, NULL); fPassword = new BTextControl(rect, "password", kLabelPassword, NULL, NULL);
fPassword->TextView()->HideTyping(true); fPassword->TextView()->HideTyping(true);
float usernameWidth = StringWidth(fUsername->Label()) + 5;
float passwordWidth = StringWidth(fPassword->Label()) + 5; // set dividers
float width = max(usernameWidth, passwordWidth); float width = max(StringWidth(fUsername->Label()),
fUsername->SetDivider(width); StringWidth(fPassword->Label()));
fPassword->SetDivider(width); fUsername->SetDivider(width + 5);
fPassword->SetDivider(width + 5);
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fSavePassword = new BCheckBox(rect, "SavePassword", "Save Password", NULL); fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
fAuthenticationBox->AddChild(fUsername); fAuthenticationView->AddChild(fUsername);
fAuthenticationBox->AddChild(fPassword); fAuthenticationView->AddChild(fPassword);
fAuthenticationBox->AddChild(fSavePassword); fAuthenticationView->AddChild(fSavePassword);
fAuthenticationBox->AddChild(fAuthenticationView);
AddChild(fDeviceBox); AddChild(fDeviceBox);
AddChild(fAuthenticationBox); AddChild(fAuthenticationBox);
@@ -446,9 +485,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(GENERAL_TAB_AUTHENTICATION, if(Addon()->Settings()->FindMessage(kGeneralTabAuthentication,
&authentication) == B_OK) &authentication) == B_OK)
authentication.FindString(GENERAL_TAB_AUTHENTICATORS, &authenticator); authentication.FindString(kGeneralTabAuthenticators, &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);
@@ -521,7 +560,7 @@ void
GeneralView::MessageReceived(BMessage *message) GeneralView::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case MSG_SELECT_DEVICE: case kMsgSelectDevice:
if(message->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon)) if(message->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon))
!= B_OK) != B_OK)
fDeviceAddon = NULL; fDeviceAddon = NULL;
@@ -534,7 +573,7 @@ GeneralView::MessageReceived(BMessage *message)
} }
break; break;
case MSG_SELECT_AUTHENTICATOR: case kMsgSelectAuthenticator:
UpdateControls(); UpdateControls();
break; break;
@@ -608,7 +647,7 @@ void
GeneralView::AddDevices() GeneralView::AddDevices()
{ {
AddAddonsToMenu(Addon()->Addons(), fDeviceField->Menu(), DUN_DEVICE_ADDON_TYPE, AddAddonsToMenu(Addon()->Addons(), fDeviceField->Menu(), DUN_DEVICE_ADDON_TYPE,
MSG_SELECT_DEVICE); kMsgSelectDevice);
} }
@@ -616,7 +655,8 @@ void
GeneralView::AddAuthenticators() GeneralView::AddAuthenticators()
{ {
fAuthenticatorDefault = NULL; fAuthenticatorDefault = NULL;
fAuthenticatorNone = new BMenuItem("None", new BMessage(MSG_SELECT_AUTHENTICATOR)); fAuthenticatorNone = new BMenuItem(kLabelNone,
new BMessage(kMsgSelectAuthenticator));
fAuthenticatorField->Menu()->AddItem(fAuthenticatorNone); fAuthenticatorField->Menu()->AddItem(fAuthenticatorNone);
fAuthenticatorNone->SetMarked(true); fAuthenticatorNone->SetMarked(true);
fAuthenticatorField->Menu()->AddSeparatorItem(); fAuthenticatorField->Menu()->AddSeparatorItem();
@@ -626,7 +666,7 @@ GeneralView::AddAuthenticators()
for(int32 index = 0; for(int32 index = 0;
Addon()->Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index, Addon()->Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
&addon) == B_OK; index++) { &addon) == B_OK; index++) {
BMessage *message = new BMessage(MSG_SELECT_AUTHENTICATOR); BMessage *message = new BMessage(kMsgSelectAuthenticator);
message->AddString("KernelModuleName", addon.FindString("KernelModuleName")); message->AddString("KernelModuleName", addon.FindString("KernelModuleName"));
BString name, technicalName, friendlyName; BString name, technicalName, friendlyName;
@@ -65,6 +65,9 @@ class GeneralAddon : public DialUpAddon {
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);
// used by ppp_server
BView *AuthenticationView() const;
private: private:
bool GetAuthenticator(const BString& moduleName, BMessage *entry) const; bool GetAuthenticator(const BString& moduleName, BMessage *entry) const;
bool MarkAuthenticatorAsValid(const BString& moduleName); bool MarkAuthenticatorAsValid(const BString& moduleName);
@@ -109,6 +112,10 @@ class GeneralView : public BView {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
// used by ppp_server
BView *AuthenticationView() const
{ return fAuthenticationView; }
private: private:
void ReloadDeviceView(); void ReloadDeviceView();
void UpdateControls(); void UpdateControls();
@@ -120,6 +127,7 @@ class GeneralView : public BView {
GeneralAddon *fAddon; GeneralAddon *fAddon;
DialUpAddon *fDeviceAddon; DialUpAddon *fDeviceAddon;
BBox *fDeviceBox, *fAuthenticationBox; BBox *fDeviceBox, *fAuthenticationBox;
BView *fAuthenticationView;
BMenuField *fDeviceField, *fAuthenticatorField; BMenuField *fDeviceField, *fAuthenticatorField;
BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault; BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault;
BTextControl *fUsername, *fPassword; BTextControl *fUsername, *fPassword;
+126 -131
View File
@@ -5,7 +5,7 @@
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected] // Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// IPCPAddon saves the loaded settings. // IPCPAddon saves the loaded settings.
// IPCPWindow saves the current settings. // IPCPView saves the current settings.
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
#include "IPCPAddon.h" #include "IPCPAddon.h"
@@ -14,23 +14,38 @@
#include <stl_algobase.h> #include <stl_algobase.h>
// for max() // for max()
#include <Box.h> #include <StringView.h>
#include <Button.h>
#include <PPPDefs.h> #include <PPPDefs.h>
#include <IPCP.h> #include <IPCP.h>
// from IPCP addon // from IPCP addon
#define BUTTON_WIDTH 80 // GUI constants
static const uint32 kDefaultButtonWidth = 80;
#define MSG_CHANGE_SETTINGS 'CHGS' // message constants
#define MSG_RESET_SETTINGS 'RSTS' static const uint32 kMsgUpdateControls = 'UCTL';
// labels
#ifdef LANG_GERMAN
static const char *kLabelIPCP = "TCP/IP";
static const char *kLabelEnabled = "Verwenden";
static const char *kLabelIPAddress = "IP Adresse: ";
static const char *kLabelPrimaryDNS = "Primärer DNS: ";
static const char *kLabelSecondaryDNS = "Sekundärer DNS: ";
static const char *kLabelOptional = "(Optional)";
#else
static const char *kLabelIPCP = "TCP/IP";
static const char *kLabelEnabled = "Enabled";
static const char *kLabelIPAddress = "IP Address: ";
static const char *kLabelPrimaryDNS = "Primary DNS: ";
static const char *kLabelSecondaryDNS = "Secondary DNS: ";
static const char *kLabelOptional = "(Optional)";
#endif
static const char kFriendlyName[] = "IPv4 (TCP/IP): Internet Protocol"; // add-on descriptions
static const char kTechnicalName[] = "IPCP"; static const char *kKernelModuleName = "ipcp";
static const char kKernelModuleName[] = "ipcp";
IPCPAddon::IPCPAddon(BMessage *addons) IPCPAddon::IPCPAddon(BMessage *addons)
@@ -38,11 +53,6 @@ IPCPAddon::IPCPAddon(BMessage *addons)
fSettings(NULL), fSettings(NULL),
fProfile(NULL) fProfile(NULL)
{ {
float windowHeight = 3 * 20 // text controls
+ 35 // buttons
+ 4 * 5 + 10 + 20; // space between controls and bottom
BRect rect(350, 250, 650, 250 + windowHeight);
fIPCPWindow = new IPCPWindow(this, rect);
} }
@@ -51,46 +61,28 @@ IPCPAddon::~IPCPAddon()
} }
const char*
IPCPAddon::FriendlyName() const
{
return kFriendlyName;
}
const char*
IPCPAddon::TechnicalName() const
{
return kTechnicalName;
}
const char*
IPCPAddon::KernelModuleName() const
{
return kKernelModuleName;
}
bool bool
IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
{ {
fIsNew = isNew; fIsNew = isNew;
fIsEnabled = false;
fIPAddress = fPrimaryDNS = fSecondaryDNS = ""; fIPAddress = fPrimaryDNS = fSecondaryDNS = "";
fSettings = settings; fSettings = settings;
fProfile = profile; fProfile = profile;
if(!settings || !profile || isNew) {
fIPCPWindow->Reload(); if(fIPCPView)
// reset all views fIPCPView->Reload();
// reset all views (empty settings)
if(!settings || !profile || isNew)
return true; return true;
}
BMessage protocol; BMessage protocol;
// settings // settings
int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol); int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol);
if(protocolIndex < 0) if(protocolIndex < 0)
return false; return true;
protocol.AddBool(MDSU_VALID, true); protocol.AddBool(MDSU_VALID, true);
fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
@@ -98,7 +90,9 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
// profile // profile
protocolIndex = FindIPCPProtocol(*fProfile, &protocol); protocolIndex = FindIPCPProtocol(*fProfile, &protocol);
if(protocolIndex < 0) if(protocolIndex < 0)
return false; return true;
fIsEnabled = true;
// the "Local" side parameter // the "Local" side parameter
BMessage local; BMessage local;
@@ -151,7 +145,8 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
protocol.AddBool(MDSU_VALID, true); protocol.AddBool(MDSU_VALID, true);
fProfile->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); fProfile->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
fIPCPWindow->Reload(); if(fIPCPView)
fIPCPView->Reload();
return true; return true;
} }
@@ -160,18 +155,15 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
void void
IPCPAddon::IsModified(bool *settings, bool *profile) const IPCPAddon::IsModified(bool *settings, bool *profile) const
{ {
// some part of this work is done by the "Protocols" tab, thus we do not need to
// check whether we are a new protocol or not
*settings = false;
if(!fSettings) { if(!fSettings) {
*profile = false; *settings = *profile = false;
return; return;
} }
*profile = (fIPAddress != fIPCPWindow->IPAddress() *settings = fIsEnabled != fIPCPView->IsEnabled();
|| fPrimaryDNS != fIPCPWindow->PrimaryDNS() *profile = (*settings || fIPAddress != fIPCPView->IPAddress()
|| fSecondaryDNS != fIPCPWindow->SecondaryDNS()); || fPrimaryDNS != fIPCPView->PrimaryDNS()
|| fSecondaryDNS != fIPCPView->SecondaryDNS());
} }
@@ -181,6 +173,9 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar
if(!fSettings || !settings) if(!fSettings || !settings)
return false; return false;
if(!fIPCPView->IsEnabled())
return true;
BMessage protocol, local; BMessage protocol, local;
protocol.AddString(MDSU_NAME, PPP_PROTOCOL_KEY); protocol.AddString(MDSU_NAME, PPP_PROTOCOL_KEY);
protocol.AddString(MDSU_VALUES, kKernelModuleName); protocol.AddString(MDSU_VALUES, kKernelModuleName);
@@ -191,30 +186,30 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar
local.AddString(MDSU_NAME, IPCP_LOCAL_SIDE_KEY); local.AddString(MDSU_NAME, IPCP_LOCAL_SIDE_KEY);
bool needsLocal = false; bool needsLocal = false;
if(fIPCPWindow->IPAddress() && strlen(fIPCPWindow->IPAddress()) > 0) { if(fIPCPView->IPAddress() && strlen(fIPCPView->IPAddress()) > 0) {
// save IP address, too // save IP address, too
needsLocal = true; needsLocal = true;
BMessage ip; BMessage ip;
ip.AddString(MDSU_NAME, IPCP_IP_ADDRESS_KEY); ip.AddString(MDSU_NAME, IPCP_IP_ADDRESS_KEY);
ip.AddString(MDSU_VALUES, fIPCPWindow->IPAddress()); ip.AddString(MDSU_VALUES, fIPCPView->IPAddress());
local.AddMessage(MDSU_PARAMETERS, &ip); local.AddMessage(MDSU_PARAMETERS, &ip);
} }
if(fIPCPWindow->PrimaryDNS() && strlen(fIPCPWindow->PrimaryDNS()) > 0) { if(fIPCPView->PrimaryDNS() && strlen(fIPCPView->PrimaryDNS()) > 0) {
// save service name, too // save service name, too
needsLocal = true; needsLocal = true;
BMessage dns; BMessage dns;
dns.AddString(MDSU_NAME, IPCP_PRIMARY_DNS_KEY); dns.AddString(MDSU_NAME, IPCP_PRIMARY_DNS_KEY);
dns.AddString(MDSU_VALUES, fIPCPWindow->PrimaryDNS()); dns.AddString(MDSU_VALUES, fIPCPView->PrimaryDNS());
local.AddMessage(MDSU_PARAMETERS, &dns); local.AddMessage(MDSU_PARAMETERS, &dns);
} }
if(fIPCPWindow->SecondaryDNS() && strlen(fIPCPWindow->SecondaryDNS()) > 0) { if(fIPCPView->SecondaryDNS() && strlen(fIPCPView->SecondaryDNS()) > 0) {
// save service name, too // save service name, too
needsLocal = true; needsLocal = true;
BMessage dns; BMessage dns;
dns.AddString(MDSU_NAME, IPCP_SECONDARY_DNS_KEY); dns.AddString(MDSU_NAME, IPCP_SECONDARY_DNS_KEY);
dns.AddString(MDSU_VALUES, fIPCPWindow->SecondaryDNS()); dns.AddString(MDSU_VALUES, fIPCPView->SecondaryDNS());
local.AddMessage(MDSU_PARAMETERS, &dns); local.AddMessage(MDSU_PARAMETERS, &dns);
} }
@@ -230,10 +225,15 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar
bool bool
IPCPAddon::GetPreferredSize(float *width, float *height) const IPCPAddon::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) if(width)
*width = fIPCPWindow->Bounds().Width(); *width = rect.Width();
if(height) if(height)
*height = fIPCPWindow->Bounds().Height(); *height = rect.Height();
return true; return true;
} }
@@ -242,9 +242,15 @@ IPCPAddon::GetPreferredSize(float *width, float *height) const
BView* BView*
IPCPAddon::CreateView(BPoint leftTop) IPCPAddon::CreateView(BPoint leftTop)
{ {
fIPCPWindow->MoveTo(leftTop); if(!fIPCPView) {
fIPCPWindow->Show(); BRect rect;
return NULL; Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
fIPCPView = new IPCPView(this, rect);
fIPCPView->Reload();
}
fIPCPView->MoveTo(leftTop);
return fIPCPView;
} }
@@ -265,103 +271,92 @@ IPCPAddon::FindIPCPProtocol(const BMessage& message, BMessage *protocol) const
} }
IPCPWindow::IPCPWindow(IPCPAddon *addon, BRect frame) IPCPView::IPCPView(IPCPAddon *addon, BRect frame)
: BWindow(frame, "IPCP Settings", B_MODAL_WINDOW, : BView(frame, kLabelIPCP, B_FOLLOW_NONE, 0),
B_NOT_RESIZABLE | B_NOT_CLOSABLE),
fAddon(addon) fAddon(addon)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
BView *backgroundView = new BView(rect, "backgroundView", B_FOLLOW_NONE, 0); rect.InsetBy(10, 10);
backgroundView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); rect.bottom = rect.top + 15;
rect.InsetBy(5, 5); fIsEnabled = new BCheckBox(rect, "isEnabled", kLabelEnabled,
new BMessage(kMsgUpdateControls));
float boxHeight = 20 // space at top rect.left += 15;
+ 3 * 20 // size of controls // indent the other controls to indicate that they depend on this control
+ 4 * 5; // space between controls and bottom
rect.bottom = rect.top + boxHeight;
BBox *ipcpBox = new BBox(rect, "IPCP");
ipcpBox->SetLabel("IPCP");
rect = ipcpBox->Bounds();
rect.InsetBy(10, 0);
rect.top = 20;
rect.bottom = rect.top + 20;
fIPAddress = new BTextControl(rect, "ip", "IP Address: ", NULL, NULL);
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fPrimaryDNS = new BTextControl(rect, "primaryDNS", "Primary DNS: ", NULL, NULL); BRect optionalRect(rect);
rect.right -= 75;
fIPAddress = new BTextControl(rect, "ip", kLabelIPAddress, NULL, NULL);
optionalRect.left = rect.right + 5;
optionalRect.bottom = optionalRect.top + 15;
AddChild(new BStringView(optionalRect, "optional_1", kLabelOptional));
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fSecondaryDNS = new BTextControl(rect, "secondaryDNS", "Secondary DNS: ", NULL, fPrimaryDNS = new BTextControl(rect, "primaryDNS", kLabelPrimaryDNS, NULL, NULL);
optionalRect.top = rect.top;
optionalRect.bottom = optionalRect.top + 15;
AddChild(new BStringView(optionalRect, "optional_2", kLabelOptional));
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20;
fSecondaryDNS = new BTextControl(rect, "secondaryDNS", kLabelSecondaryDNS, NULL,
NULL); NULL);
optionalRect.top = rect.top;
optionalRect.bottom = optionalRect.top + 15;
AddChild(new BStringView(optionalRect, "optional_3", kLabelOptional));
// set divider of text controls // set divider of text controls
float ipAddressWidth = backgroundView->StringWidth(fIPAddress->Label()) + 5; float controlWidth = max(max(StringWidth(fIPAddress->Label()),
float primaryDNSWidth = backgroundView->StringWidth(fPrimaryDNS->Label()) + 5; StringWidth(fPrimaryDNS->Label())), StringWidth(fSecondaryDNS->Label()));
float secondaryDNSWidth = backgroundView->StringWidth(fSecondaryDNS->Label()) + 5; fIPAddress->SetDivider(controlWidth + 5);
float controlWidth = max(max(ipAddressWidth, primaryDNSWidth), secondaryDNSWidth); fPrimaryDNS->SetDivider(controlWidth + 5);
fSecondaryDNS->SetDivider(controlWidth + 5);
fIPAddress->SetDivider(controlWidth); AddChild(fIsEnabled);
fPrimaryDNS->SetDivider(controlWidth); AddChild(fIPAddress);
fSecondaryDNS->SetDivider(controlWidth); AddChild(fPrimaryDNS);
AddChild(fSecondaryDNS);
// add buttons to service window
rect = ipcpBox->Frame();
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 25;
rect.left = rect.right - BUTTON_WIDTH;
fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SETTINGS));
rect.right = rect.left - 10;
rect.left = rect.right - BUTTON_WIDTH;
fCancelButton = new BButton(rect, "CancelButton", "Cancel",
new BMessage(MSG_RESET_SETTINGS));
ipcpBox->AddChild(fIPAddress);
ipcpBox->AddChild(fPrimaryDNS);
ipcpBox->AddChild(fSecondaryDNS);
backgroundView->AddChild(ipcpBox);
backgroundView->AddChild(fCancelButton);
backgroundView->AddChild(fOKButton);
AddChild(backgroundView);
SetDefaultButton(fOKButton);
Run();
// this must be called in order for Reload() to work properly
} }
void void
IPCPWindow::Reload() IPCPView::Reload()
{ {
Lock(); fIsEnabled->SetValue(Addon()->IsEnabled() || Addon()->IsNew());
fIPAddress->MakeFocus(true); // enable TCP/IP by default
fIPAddress->SetText(Addon()->IPAddress()); fIPAddress->SetText(Addon()->IPAddress());
fPreviousIPAddress = Addon()->IPAddress();
fPrimaryDNS->SetText(Addon()->PrimaryDNS()); fPrimaryDNS->SetText(Addon()->PrimaryDNS());
fPreviousPrimaryDNS = Addon()->PrimaryDNS();
fSecondaryDNS->SetText(Addon()->SecondaryDNS()); fSecondaryDNS->SetText(Addon()->SecondaryDNS());
fPreviousSecondaryDNS = Addon()->SecondaryDNS();
Unlock(); UpdateControls();
} }
void void
IPCPWindow::MessageReceived(BMessage *message) IPCPView::AttachedToWindow()
{
SetViewColor(Parent()->ViewColor());
fIsEnabled->SetTarget(this);
}
void
IPCPView::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case MSG_CHANGE_SETTINGS: case kMsgUpdateControls:
Hide(); UpdateControls();
fPreviousIPAddress = fIPAddress->Text();
fPreviousPrimaryDNS = fPrimaryDNS->Text();
fPreviousSecondaryDNS = fSecondaryDNS->Text();
break;
case MSG_RESET_SETTINGS:
Hide();
fIPAddress->SetText(fPreviousIPAddress.String());
fPrimaryDNS->SetText(fPreviousPrimaryDNS.String());
fPrimaryDNS->SetText(fPreviousPrimaryDNS.String());
break; break;
default: default:
BWindow::MessageReceived(message); BView::MessageReceived(message);
} }
} }
void
IPCPView::UpdateControls()
{
fIPAddress->SetEnabled(IsEnabled());
fPrimaryDNS->SetEnabled(IsEnabled());
fSecondaryDNS->SetEnabled(IsEnabled());
}
+17 -10
View File
@@ -13,11 +13,11 @@
#include <DialUpAddon.h> #include <DialUpAddon.h>
#include <CheckBox.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
#include <Window.h>
class IPCPWindow; class IPCPView;
class IPCPAddon : public DialUpAddon { class IPCPAddon : public DialUpAddon {
@@ -28,6 +28,8 @@ class IPCPAddon : public DialUpAddon {
bool IsNew() const bool IsNew() const
{ return fIsNew; } { return fIsNew; }
bool IsEnabled() const
{ return fIsEnabled; }
const char *IPAddress() const const char *IPAddress() const
{ return fIPAddress.String(); } { return fIPAddress.String(); }
const char *PrimaryDNS() const const char *PrimaryDNS() const
@@ -40,9 +42,8 @@ class IPCPAddon : public DialUpAddon {
BMessage *Profile() const BMessage *Profile() const
{ return fProfile; } { return fProfile; }
virtual const char *FriendlyName() const; virtual int32 Position() const
virtual const char *TechnicalName() const; { return 10; }
virtual const char *KernelModuleName() const;
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
virtual void IsModified(bool *settings, bool *profile) const; virtual void IsModified(bool *settings, bool *profile) const;
@@ -55,22 +56,24 @@ class IPCPAddon : public DialUpAddon {
int32 FindIPCPProtocol(const BMessage& message, BMessage *protocol) const; int32 FindIPCPProtocol(const BMessage& message, BMessage *protocol) const;
private: private:
bool fIsNew; bool fIsNew, fIsEnabled;
BString fIPAddress, fPrimaryDNS, fSecondaryDNS; BString fIPAddress, fPrimaryDNS, fSecondaryDNS;
BMessage *fSettings, *fProfile; BMessage *fSettings, *fProfile;
// saves last settings state // saves last settings state
IPCPWindow *fIPCPWindow; IPCPView *fIPCPView;
}; };
class IPCPWindow : public BWindow { class IPCPView : public BView {
public: public:
IPCPWindow(IPCPAddon *addon, BRect frame); IPCPView(IPCPAddon *addon, BRect frame);
IPCPAddon *Addon() const IPCPAddon *Addon() const
{ return fAddon; } { return fAddon; }
void Reload(); void Reload();
bool IsEnabled() const
{ return fIsEnabled->Value(); }
const char *IPAddress() const const char *IPAddress() const
{ return fIPAddress->Text(); } { return fIPAddress->Text(); }
const char *PrimaryDNS() const const char *PrimaryDNS() const
@@ -78,13 +81,17 @@ class IPCPWindow : public BWindow {
const char *SecondaryDNS() const const char *SecondaryDNS() const
{ return fSecondaryDNS->Text(); } { return fSecondaryDNS->Text(); }
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
private:
void UpdateControls();
private: private:
IPCPAddon *fAddon; IPCPAddon *fAddon;
BCheckBox *fIsEnabled;
BButton *fCancelButton, *fOKButton; BButton *fCancelButton, *fOKButton;
BTextControl *fIPAddress, *fPrimaryDNS, *fSecondaryDNS; BTextControl *fIPAddress, *fPrimaryDNS, *fSecondaryDNS;
BString fPreviousIPAddress, fPreviousPrimaryDNS, fPreviousSecondaryDNS;
}; };
+1 -2
View File
@@ -18,11 +18,10 @@ SimpleTest DialUpPreflet :
TextRequestDialog.cpp TextRequestDialog.cpp
# built-in add-ons # built-in add-ons
ExtrasAddon.cpp ConnectionOptionsAddon.cpp
GeneralAddon.cpp GeneralAddon.cpp
IPCPAddon.cpp IPCPAddon.cpp
PPPoEAddon.cpp PPPoEAddon.cpp
ProtocolsAddon.cpp
; ;
LinkSharedOSLibs DialUpPreflet : libppp.a be ; LinkSharedOSLibs DialUpPreflet : libppp.a be ;
@@ -7,7 +7,8 @@
#include "MessageDriverSettingsUtils.h" #include "MessageDriverSettingsUtils.h"
#include <driver_settings.h> #include <PPPDefs.h>
#include <settings_tools.h>
#include <File.h> #include <File.h>
#include <Message.h> #include <Message.h>
#include <String.h> #include <String.h>
@@ -15,6 +16,9 @@
#include <cstdio> #include <cstdio>
static bool AddParameters(const BMessage& message, driver_settings *to);
bool bool
FindMessageParameter(const char *name, const BMessage& message, BMessage *save, FindMessageParameter(const char *name, const BMessage& message, BMessage *save,
int32 *startIndex = NULL) int32 *startIndex = NULL)
@@ -35,6 +39,68 @@ FindMessageParameter(const char *name, const BMessage& message, BMessage *save,
} }
static
bool
AddValues(const BMessage& message, driver_parameter *parameter)
{
const char *value;
for(int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK;
index++)
if(!add_driver_parameter_value(value, parameter))
return false;
return true;
}
inline
bool
AddParameters(const BMessage& message, driver_parameter *to)
{
if(!to)
return false;
return AddParameters(message,
reinterpret_cast<driver_settings*>(&to->parameter_count));
}
static
bool
AddParameters(const BMessage& message, driver_settings *to)
{
const char *name;
BMessage current;
driver_parameter *parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index,
&current) == B_OK; index++) {
name = current.FindString(MDSU_NAME);
parameter = new_driver_parameter(name);
if(!AddValues(current, parameter))
return false;
AddParameters(current, parameter);
add_driver_parameter(parameter, to);
}
return true;
}
driver_settings*
MessageToDriverSettings(const BMessage& message)
{
driver_settings *settings = new_driver_settings();
if(!AddParameters(message, settings)) {
free_driver_settings(settings);
return NULL;
}
return settings;
}
static static
bool bool
AddParameter(const driver_parameter *parameter, BMessage *message) AddParameter(const driver_parameter *parameter, BMessage *message)
@@ -10,6 +10,7 @@
#include <SupportDefs.h> #include <SupportDefs.h>
struct driver_settings;
class BMessage; class BMessage;
class BFile; class BFile;
@@ -22,7 +23,10 @@ class BFile;
extern bool FindMessageParameter(const char *name, const BMessage& message, extern bool FindMessageParameter(const char *name, const BMessage& message,
BMessage *save, int32 *startIndex = NULL); BMessage *save, int32 *startIndex = NULL);
extern driver_settings *MessageToDriverSettings(const BMessage& message);
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);
#endif #endif
+67 -143
View File
@@ -17,30 +17,57 @@
// for max() // for max()
#include <Box.h> #include <Box.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>
#include <Window.h>
#include <PPPManager.h> #include <PPPManager.h>
#include <PPPoE.h> #include <PPPoE.h>
// from PPPoE addon // from PPPoE addon
#define BUTTON_WIDTH 80
#define MSG_SELECT_INTERFACE 'SELI' // GUI constants
#define MSG_SELECT_OTHER 'SELO' static const uint32 kDefaultButtonWidth = 80;
#define MSG_FINISH_SELECT_OTHER 'FISO'
#define MSG_SHOW_SERVICE_WINDOW 'SHSW'
#define MSG_CHANGE_SERVICE 'CHGS'
#define MSG_RESET_SERVICE 'RESS'
static const char kFriendlyName[] = "DSL, Cable, etc."; // message constants
static const char kTechnicalName[] = "PPPoE"; static const uint32 kMsgSelectInterface = 'SELI';
static const char kKernelModuleName[] = "pppoe"; static const uint32 kMsgSelectOther = 'SELO';
static const uint32 kMsgFinishSelectOther = 'FISO';
static const uint32 kMsgShowServiceWindow = 'SHSW';
static const uint32 kMsgChangeService = 'CHGS';
static const uint32 kMsgResetService = 'RESS';
// labels
#ifdef LANG_GERMAN
static const char *kLabelInterfaceName = "Netzwerk-Adapter: ";
static const char *kLabelOptional = "(Optional)";
static const char *kLabelOtherInterface = "Anderer:";
static const char *kLabelSelectInterface = "Adapter Auswählen...";
static const char *kLabelServiceName = "Service: ";
#else
static const char *kLabelInterfaceName = "Network Interface: ";
static const char *kLabelOptional = "(Optional)";
static const char *kLabelOtherInterface = "Other:";
static const char *kLabelSelectInterface = "Select Interface...";
static const char *kLabelServiceName = "Service: ";
#endif
// requests
#ifdef LANG_GERMAN
static const char *kRequestInterfaceName = "Name Des Adapters: ";
#else
static const char *kRequestInterfaceName = "Network Interface Name: ";
#endif
// add-on descriptions
#ifdef LANG_GERMAN
static const char *kFriendlyName = "Breitband: DSL, Kabel, etc.";
#else
static const char *kFriendlyName = "Broadband: DSL, Cable, etc.";
#endif
static const char *kTechnicalName = "PPPoE";
static const char *kKernelModuleName = "pppoe";
PPPoEAddon::PPPoEAddon(BMessage *addons) PPPoEAddon::PPPoEAddon(BMessage *addons)
@@ -50,8 +77,8 @@ PPPoEAddon::PPPoEAddon(BMessage *addons)
fPPPoEView(NULL) fPPPoEView(NULL)
{ {
fHeight = 20 // interface name control fHeight = 20 // interface name control
+ 25 // service button + 20 // service control
+ 5; // space between controls + 5 + 2; // space between controls and bottom
} }
@@ -87,7 +114,7 @@ bool
PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
{ {
fIsNew = isNew; fIsNew = isNew;
fInterfaceName = fACName = fServiceName = ""; fInterfaceName = fServiceName = "";
fSettings = settings; fSettings = settings;
fProfile = profile; fProfile = profile;
if(!settings || !profile || isNew) { if(!settings || !profile || isNew) {
@@ -118,15 +145,6 @@ PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
device.ReplaceMessage(MDSU_PARAMETERS, index, &parameter); device.ReplaceMessage(MDSU_PARAMETERS, index, &parameter);
} }
index = 0;
if(!FindMessageParameter(PPPoE_AC_NAME_KEY, device, &parameter, &index)
|| parameter.FindString(MDSU_VALUES, &fACName) != B_OK)
fACName = "";
else {
parameter.AddBool(MDSU_VALID, true);
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(MDSU_VALUES, &fServiceName) != B_OK) || parameter.FindString(MDSU_VALUES, &fServiceName) != B_OK)
@@ -154,7 +172,6 @@ PPPoEAddon::IsModified(bool *settings, bool *profile) const
} }
*settings = (fInterfaceName != fPPPoEView->InterfaceName() *settings = (fInterfaceName != fPPPoEView->InterfaceName()
|| fACName != fPPPoEView->ACName()
|| fServiceName != fPPPoEView->ServiceName()); || fServiceName != fPPPoEView->ServiceName());
} }
@@ -175,14 +192,6 @@ PPPoEAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempora
interface.AddString(MDSU_VALUES, fPPPoEView->InterfaceName()); interface.AddString(MDSU_VALUES, fPPPoEView->InterfaceName());
device.AddMessage(MDSU_PARAMETERS, &interface); device.AddMessage(MDSU_PARAMETERS, &interface);
if(fPPPoEView->ACName() && strlen(fPPPoEView->ACName()) > 0) {
// save access concentrator, too
BMessage ac;
ac.AddString(MDSU_NAME, PPPoE_AC_NAME_KEY);
ac.AddString(MDSU_VALUES, fPPPoEView->ACName());
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;
@@ -225,10 +234,10 @@ PPPoEAddon::CreateView(BPoint leftTop)
BRect rect(0, 0, width, fHeight); BRect rect(0, 0, width, fHeight);
fPPPoEView = new PPPoEView(this, rect); fPPPoEView = new PPPoEView(this, rect);
fPPPoEView->Reload();
} }
fPPPoEView->MoveTo(leftTop); fPPPoEView->MoveTo(leftTop);
fPPPoEView->Reload();
return fPPPoEView; return fPPPoEView;
} }
@@ -240,75 +249,25 @@ PPPoEView::PPPoEView(PPPoEAddon *addon, BRect frame)
BRect rect = Bounds(); BRect rect = Bounds();
rect.InsetBy(5, 0); rect.InsetBy(5, 0);
rect.bottom = 20; rect.bottom = 20;
fInterface = new BMenuField(rect, "interface", "Interface: ", fInterface = new BMenuField(rect, "interface", kLabelInterfaceName,
new BPopUpMenu("Select Interface...")); new BPopUpMenu(kLabelSelectInterface));
fInterface->SetDivider(StringWidth(fInterface->Label()) + 5); fInterface->SetDivider(StringWidth(fInterface->Label()) + 5);
fInterface->Menu()->AddSeparatorItem(); fInterface->Menu()->AddSeparatorItem();
fOtherInterface = new BMenuItem("Other:", new BMessage(MSG_SELECT_OTHER)); fOtherInterface = new BMenuItem(kLabelOtherInterface,
new BMessage(kMsgSelectOther));
fInterface->Menu()->AddItem(fOtherInterface); fInterface->Menu()->AddItem(fOtherInterface);
rect.top = rect.bottom + 5;
rect.bottom = rect.top + 45;
fServiceButton = new BButton(rect, "ServiceButton", "Service",
new BMessage(MSG_SHOW_SERVICE_WINDOW));
fServiceButton->ResizeToPreferred();
// create service window
float boxHeight = 20 // space at top
+ 2 * 20 // size of controls
+ 2 * 5; // space between controls and bottom
float windowHeight = boxHeight
+ 35 // buttons
+ 2 * 5; // space between controls and bottom
rect.Set(350, 250, 650, 250 + windowHeight);
fServiceWindow = new BWindow(rect, "Service", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_NOT_CLOSABLE);
rect = fServiceWindow->Bounds();
BView *serviceView = new BView(rect, "serviceView", B_FOLLOW_NONE, 0);
serviceView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rect.InsetBy(5, 5);
rect.bottom = rect.top + boxHeight;
BBox *serviceBox = new BBox(rect, "Service");
serviceBox->SetLabel("Service");
rect = serviceBox->Bounds();
rect.InsetBy(10, 0);
rect.top = 20;
rect.bottom = rect.top + 20;
fACName = new BTextControl(rect, "ac", "AC: ", NULL, NULL);
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
fServiceName = new BTextControl(rect, "service", "Service: ", NULL, NULL); rect.right -= 75;
fServiceName = new BTextControl(rect, "service", kLabelServiceName, NULL, NULL);
// set divider of text controls fServiceName->SetDivider(StringWidth(fServiceName->Label()) + 5);
float acNameWidth = StringWidth(fACName->Label()) + 5; rect.left = rect.right + 5;
float serviceNameWidth = StringWidth(fServiceName->Label()) + 5; rect.right += 75;
float width = max(acNameWidth, serviceNameWidth); rect.bottom = rect.top + 15;
fACName->SetDivider(width); AddChild(new BStringView(rect, "optional", kLabelOptional));
fServiceName->SetDivider(width);
// add buttons to service window
rect = serviceBox->Frame();
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 25;
rect.left = rect.right - BUTTON_WIDTH;
fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SERVICE));
rect.right = rect.left - 10;
rect.left = rect.right - BUTTON_WIDTH;
fCancelButton = new BButton(rect, "CancelButton", "Cancel",
new BMessage(MSG_RESET_SERVICE));
serviceBox->AddChild(fACName);
serviceBox->AddChild(fServiceName);
serviceView->AddChild(serviceBox);
serviceView->AddChild(fCancelButton);
serviceView->AddChild(fOKButton);
fServiceWindow->AddChild(serviceView);
fServiceWindow->SetDefaultButton(fOKButton);
fServiceWindow->Run();
// this must be called in order for Reload() to work properly
AddChild(fInterface); AddChild(fInterface);
AddChild(fServiceButton); AddChild(fServiceName);
} }
@@ -321,17 +280,8 @@ PPPoEView::~PPPoEView()
void void
PPPoEView::Reload() PPPoEView::Reload()
{ {
// update interface settings
ReloadInterfaces(); ReloadInterfaces();
// update service settings (in service window => must be locked)
fServiceWindow->Lock();
fACName->SetText(Addon()->ACName());
fPreviousACName = Addon()->ACName();
fServiceName->MakeFocus(true);
fServiceName->SetText(Addon()->ServiceName()); fServiceName->SetText(Addon()->ServiceName());
fPreviousServiceName = Addon()->ServiceName();
fServiceWindow->Unlock();
} }
@@ -340,11 +290,7 @@ PPPoEView::AttachedToWindow()
{ {
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
fInterface->Menu()->SetTargetForItems(this); fInterface->Menu()->SetTargetForItems(this);
fServiceButton->SetTarget(this);
fACName->SetTarget(this);
fServiceName->SetTarget(this); fServiceName->SetTarget(this);
fCancelButton->SetTarget(this);
fOKButton->SetTarget(this);
} }
@@ -352,19 +298,19 @@ void
PPPoEView::MessageReceived(BMessage *message) PPPoEView::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what) {
case MSG_SELECT_INTERFACE: { case kMsgSelectInterface: {
BMenuItem *item = fInterface->Menu()->FindMarked(); BMenuItem *item = fInterface->Menu()->FindMarked();
if(item) if(item)
fInterfaceName = item->Label(); fInterfaceName = item->Label();
} break; } break;
case MSG_SELECT_OTHER: case kMsgSelectOther:
(new TextRequestDialog("InterfaceName", "Interface Name: ", (new TextRequestDialog("InterfaceName", kRequestInterfaceName,
fInterfaceName.String()))->Go(new BInvoker( fInterfaceName.String()))->Go(new BInvoker(
new BMessage(MSG_FINISH_SELECT_OTHER), this)); new BMessage(kMsgFinishSelectOther), this));
break; break;
case MSG_FINISH_SELECT_OTHER: { case kMsgFinishSelectOther: {
int32 which; int32 which;
message->FindInt32("which", &which); message->FindInt32("which", &which);
@@ -389,35 +335,13 @@ PPPoEView::MessageReceived(BMessage *message)
return; return;
} }
BString label("Other: "); BString label(kLabelOtherInterface);
label << name; label << " " << name;
fOtherInterface->SetLabel(label.String()); fOtherInterface->SetLabel(label.String());
fOtherInterface->SetMarked(true); fOtherInterface->SetMarked(true);
// XXX: this is needed to tell the owning menu to update its label // XXX: this is needed to tell the owning menu to update its label
} break; } break;
case MSG_SHOW_SERVICE_WINDOW:
fServiceWindow->MoveTo(center_on_screen(fServiceWindow->Bounds(),
Window()));
fServiceWindow->Show();
break;
case MSG_CHANGE_SERVICE:
fServiceWindow->Hide();
fServiceWindow->Lock();
fPreviousACName = fACName->Text();
fPreviousServiceName = fServiceName->Text();
fServiceWindow->Unlock();
break;
case MSG_RESET_SERVICE:
fServiceWindow->Hide();
fServiceWindow->Lock();
fACName->SetText(fPreviousACName.String());
fServiceName->SetText(fPreviousServiceName.String());
fServiceWindow->Unlock();
break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
} }
@@ -431,7 +355,7 @@ PPPoEView::ReloadInterfaces()
BMenu *menu = fInterface->Menu(); BMenu *menu = fInterface->Menu();
while(menu->CountItems() > 2) while(menu->CountItems() > 2)
delete menu->RemoveItem((int32) 0); delete menu->RemoveItem((int32) 0);
fOtherInterface->SetLabel("Other:"); fOtherInterface->SetLabel(kLabelOtherInterface);
PPPManager manager; PPPManager manager;
char *interfaces = new char[8192]; char *interfaces = new char[8192];
@@ -443,7 +367,7 @@ PPPoEView::ReloadInterfaces()
char *name = interfaces; char *name = interfaces;
int32 insertAt; int32 insertAt;
for(int32 index = 0; index < count; index++) { for(int32 index = 0; index < count; index++) {
item = new BMenuItem(name, new BMessage(MSG_SELECT_INTERFACE)); item = new BMenuItem(name, new BMessage(kMsgSelectInterface));
insertAt = FindNextMenuInsertionIndex(menu, name); insertAt = FindNextMenuInsertionIndex(menu, name);
if(insertAt > menu->CountItems() - 2) if(insertAt > menu->CountItems() - 2)
insertAt = menu->CountItems() - 2; insertAt = menu->CountItems() - 2;
@@ -467,8 +391,8 @@ PPPoEView::ReloadInterfaces()
if(item && menu->IndexOf(item) <= menu->CountItems() - 2) if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
item->SetMarked(true); item->SetMarked(true);
else if(Addon()->InterfaceName()) { else if(Addon()->InterfaceName()) {
BString label("Other: "); BString label(kLabelOtherInterface);
label << fInterfaceName; label << " " << fInterfaceName;
fOtherInterface->SetLabel(label.String()); fOtherInterface->SetLabel(label.String());
fOtherInterface->SetMarked(true); fOtherInterface->SetMarked(true);
} }
+2 -10
View File
@@ -29,8 +29,6 @@ class PPPoEAddon : public DialUpAddon {
const char *InterfaceName() const const char *InterfaceName() const
{ return fInterfaceName.String(); } { return fInterfaceName.String(); }
const char *ACName() const
{ return fACName.String(); }
const char *ServiceName() const const char *ServiceName() const
{ return fServiceName.String(); } { return fServiceName.String(); }
@@ -57,7 +55,7 @@ class PPPoEAddon : public DialUpAddon {
private: private:
bool fIsNew; bool fIsNew;
BString fInterfaceName, fACName, fServiceName; BString fInterfaceName, fServiceName;
BMessage *fSettings, *fProfile; BMessage *fSettings, *fProfile;
// saves last settings state // saves last settings state
PPPoEView *fPPPoEView; PPPoEView *fPPPoEView;
@@ -77,8 +75,6 @@ class PPPoEView : public BView {
const char *InterfaceName() const const char *InterfaceName() const
{ return fInterfaceName.String(); } { return fInterfaceName.String(); }
const char *ACName() const
{ return fACName->Text(); }
const char *ServiceName() const const char *ServiceName() const
{ return fServiceName->Text(); } { return fServiceName->Text(); }
@@ -90,14 +86,10 @@ class PPPoEView : public BView {
private: private:
PPPoEAddon *fAddon; PPPoEAddon *fAddon;
BButton *fServiceButton, *fCancelButton, *fOKButton;
BMenuField *fInterface; BMenuField *fInterface;
BMenuItem *fOtherInterface; BMenuItem *fOtherInterface;
BString fInterfaceName; BString fInterfaceName;
BTextControl *fACName, *fServiceName; BTextControl *fServiceName;
BWindow *fServiceWindow;
BString fPreviousACName, fPreviousServiceName;
// for the case that the user presses "Cancel" in the service window
}; };
@@ -1,521 +0,0 @@
//-----------------------------------------------------------------------
// 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_FINISH_ADD_PROTOCOL 'FADD'
#define MSG_REMOVE_PROTOCOL 'REMP'
#define MSG_SHOW_PREFERENCES 'SHOW'
#define MSG_UPDATE_BUTTONS 'UBTN'
#define PROTOCOLS_TAB_PROTOCOLS "Protocols"
#define DEFAULT_PROTOCOL "IPCP"
// this protocol is added by default when creating a new interface
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)
{
// get protocol and ask it to load its settings
BString name;
if(parameter.FindString(MDSU_VALUES, &name) == B_OK) {
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,
MSG_FINISH_ADD_PROTOCOL);
}
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, false);
// add a default protocol for new interfaces
if(Addon()->IsNew())
RegisterProtocol(DEFAULT_PROTOCOL);
fListView->Select(0);
// XXX: unfortunately, this does not work when the BListView is detached
UpdateButtons();
}
void
ProtocolsView::AttachedToWindow()
{
fProtocolsMenu->SetTargetForItems(this);
SetViewColor(Parent()->ViewColor());
fListView->SetTarget(this);
fAddButton->SetTarget(this);
fRemoveButton->SetTarget(this);
fPreferencesButton->SetTarget(this);
// XXX: a workaround for the bug in BListView that causes Select() only to work
// when it is attached to a window
if(fListView->CurrentSelection() < 0)
fListView->Select(0);
}
void
ProtocolsView::DetachedFromWindow()
{
// XXX: Is this a bug in BeOS? While BListView is detached the index for the
// currently selected item does not get updated when it is removed.
// Workaround: call DeselectAll() before it gets detached
fListView->DeselectAll();
}
void
ProtocolsView::MessageReceived(BMessage *message)
{
switch(message->what) {
case MSG_ADD_PROTOCOL: {
fProtocolsMenu->Go(fAddButton->ConvertToScreen(
fAddButton->Bounds().RightTop()), true, true, true);
} break;
case MSG_FINISH_ADD_PROTOCOL: {
int32 index;
message->FindInt32("index", &index);
index = RegisterProtocol(index);
// this returns the new index of the item (now for the list view)
UpdateButtons();
if(index > 0)
fListView->Select(index);
} break;
case MSG_REMOVE_PROTOCOL: {
UnregisterProtocol(fListView->CurrentSelection());
UpdateButtons();
fListView->Select(0);
} break;
case MSG_SHOW_PREFERENCES: {
AddonItem *selected = dynamic_cast<AddonItem*>(
fListView->ItemAt(fListView->CurrentSelection()));
if(selected) {
DialUpAddon *addon = selected->Addon();
float width, height;
addon->GetPreferredSize(&width, &height);
BRect rect(0, 0, width, height);
addon->CreateView(center_on_screen(rect, Window()));
// 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;
}
int32
ProtocolsView::RegisterProtocol(const char *technicalName, bool reload = true)
{
if(!technicalName)
return -1;
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->TechnicalName()
&& !strcmp(addon->TechnicalName(), technicalName))
return RegisterProtocol(index, reload);
}
return -1;
}
int32
ProtocolsView::RegisterProtocol(const DialUpAddon *protocol, bool reload = true)
{
if(!protocol)
return -1;
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)
return RegisterProtocol(index, reload);
}
return -1;
}
int32
ProtocolsView::RegisterProtocol(int32 index, bool reload = true)
{
DialUpAddon *addon;
BMenuItem *remove = fProtocolsMenu->ItemAt(index);
if(!remove || remove->Message()->FindPointer("Addon",
reinterpret_cast<void**>(&addon)) != B_OK)
return -1;
const char *label = remove->Label();
AddonItem *item = new AddonItem(label, addon);
index = FindNextListInsertionIndex(fListView, label);
fListView->AddItem(item, index);
fProtocolsMenu->RemoveItem(remove);
delete remove;
addon->LoadSettings(Addon()->Settings(), Addon()->Profile(), reload);
return index;
}
void
ProtocolsView::UnregisterProtocol(int32 index)
{
AddonItem *remove = dynamic_cast<AddonItem*>(fListView->RemoveItem(index));
if(!remove)
return;
const char *label = remove->Text();
BMessage *message = new BMessage(MSG_FINISH_ADD_PROTOCOL);
message->AddPointer("Addon", remove->Addon());
BMenuItem *item = new BMenuItem(label, message);
item->SetTarget(this);
index = FindNextMenuInsertionIndex(fProtocolsMenu, label);
fProtocolsMenu->AddItem(item, index);
delete remove;
}
void
ProtocolsView::UpdateButtons()
{
AddonItem *item = dynamic_cast<AddonItem*>(fListView->ItemAt(
fListView->CurrentSelection()));
if(fProtocolsMenu->CountItems() == 0)
fAddButton->SetEnabled(false);
else
fAddButton->SetEnabled(true);
if(!item)
fRemoveButton->SetEnabled(false);
else
fRemoveButton->SetEnabled(true);
float width, height;
if(!item || !item->Addon()->GetPreferredSize(&width, &height))
fPreferencesButton->SetEnabled(false);
else
fPreferencesButton->SetEnabled(true);
}
@@ -1,102 +0,0 @@
//-----------------------------------------------------------------------
// 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 DetachedFromWindow();
virtual void MessageReceived(BMessage *message);
int32 CountProtocols() const
{ return fListView->CountItems(); }
DialUpAddon *ProtocolAt(int32 index) const;
bool HasProtocol(const BString& moduleName) const;
private:
int32 RegisterProtocol(const char *technicalName, bool reload = true);
int32 RegisterProtocol(const DialUpAddon *protocol, bool reload = true);
int32 RegisterProtocol(int32 index, bool reload = true);
// 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
@@ -12,17 +12,23 @@
#include <TextControl.h> #include <TextControl.h>
#define WINDOW_WIDTH 250 // GUI constants
#define WINDOW_HEIGHT 5 + 20 + 10 + 25 + 5 static const uint32 kWindowWidth = 250;
#define WINDOW_RECT BRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) static const uint32 kWindowHeight = 5 + 20 + 10 + 25 + 5;
#define BUTTON_WIDTH 80 static const BRect kWindowRect(0, 0, kWindowWidth, kWindowHeight);
static const uint32 kDefaultButtonWidth = 80;
const int32 kMsgButton = 'MBTN'; // message constants
static const int32 kMsgButton = 'MBTN';
// labels
static const char *kLabelOK = "OK";
static const char *kLabelCancel = "Cancel";
TextRequestDialog::TextRequestDialog(const char *title, const char *request, TextRequestDialog::TextRequestDialog(const char *title, const char *request,
const char *text = NULL) const char *text = NULL)
: BWindow(WINDOW_RECT, title, B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE, 0), : BWindow(kWindowRect, title, B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE, 0),
fInvoker(NULL) fInvoker(NULL)
{ {
BRect rect = Bounds(); BRect rect = Bounds();
@@ -37,14 +43,14 @@ TextRequestDialog::TextRequestDialog(const char *title, const char *request,
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
rect.bottom = rect.top + 25; rect.bottom = rect.top + 25;
rect.left = rect.right - BUTTON_WIDTH; rect.left = rect.right - kDefaultButtonWidth;
BMessage message(kMsgButton); BMessage message(kMsgButton);
message.AddInt32("which", 1); message.AddInt32("which", 1);
BButton *okButton = new BButton(rect, "okButton", "OK", new BMessage(message)); BButton *okButton = new BButton(rect, "okButton", kLabelOK, new BMessage(message));
rect.right = rect.left - 10; rect.right = rect.left - 10;
rect.left = rect.right - BUTTON_WIDTH; rect.left = rect.right - kDefaultButtonWidth;
message.ReplaceInt32("which", 0); message.ReplaceInt32("which", 0);
BButton *cancelButton = new BButton(rect, "cancelButton", "Cancel", BButton *cancelButton = new BButton(rect, "cancelButton", kLabelCancel,
new BMessage(message)); new BMessage(message));
backgroundView->AddChild(okButton); backgroundView->AddChild(okButton);
backgroundView->AddChild(cancelButton); backgroundView->AddChild(cancelButton);