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:
+61
-57
@@ -4,11 +4,11 @@
|
||||
//
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||
//-----------------------------------------------------------------------
|
||||
// ExtrasAddon saves the loaded settings.
|
||||
// ExtrasView saves the current settings.
|
||||
// ConnectionOptionsAddon saves the loaded settings.
|
||||
// ConnectionOptionsView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ExtrasAddon.h"
|
||||
#include "ConnectionOptionsAddon.h"
|
||||
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
|
||||
@@ -16,33 +16,47 @@
|
||||
#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),
|
||||
fSettings(NULL),
|
||||
fProfile(NULL),
|
||||
fExtrasView(NULL)
|
||||
fConnectionOptionsView(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ExtrasAddon::~ExtrasAddon()
|
||||
ConnectionOptionsAddon::~ConnectionOptionsAddon()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
ConnectionOptionsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fDoesDialOnDemand = fAskBeforeDialing = fDoesAutoRedial = false;
|
||||
fSettings = settings;
|
||||
fProfile = profile;
|
||||
|
||||
if(fExtrasView)
|
||||
fExtrasView->Reload();
|
||||
if(fConnectionOptionsView)
|
||||
fConnectionOptionsView->Reload();
|
||||
// reset all views (empty settings)
|
||||
|
||||
if(!settings || !profile || isNew)
|
||||
@@ -80,8 +94,8 @@ ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
if(fExtrasView)
|
||||
fExtrasView->Reload();
|
||||
if(fConnectionOptionsView)
|
||||
fConnectionOptionsView->Reload();
|
||||
// reload new settings
|
||||
|
||||
return true;
|
||||
@@ -89,33 +103,33 @@ ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
|
||||
|
||||
void
|
||||
ExtrasAddon::IsModified(bool *settings, bool *profile) const
|
||||
ConnectionOptionsAddon::IsModified(bool *settings, bool *profile) const
|
||||
{
|
||||
*settings = *profile = false;
|
||||
|
||||
if(!fSettings || !fExtrasView)
|
||||
if(!fSettings || !fConnectionOptionsView)
|
||||
return;
|
||||
|
||||
*settings = DoesDialOnDemand() != fExtrasView->DoesDialOnDemand()
|
||||
|| AskBeforeDialing() != fExtrasView->AskBeforeDialing()
|
||||
|| DoesAutoRedial() != fExtrasView->DoesAutoRedial();
|
||||
*settings = DoesDialOnDemand() != fConnectionOptionsView->DoesDialOnDemand()
|
||||
|| AskBeforeDialing() != fConnectionOptionsView->AskBeforeDialing()
|
||||
|| DoesAutoRedial() != fConnectionOptionsView->DoesAutoRedial();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
|
||||
ConnectionOptionsAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary)
|
||||
{
|
||||
if(!fSettings || !settings)
|
||||
return false;
|
||||
|
||||
BMessage parameter;
|
||||
if(fExtrasView->DoesDialOnDemand()) {
|
||||
if(fConnectionOptionsView->DoesDialOnDemand()) {
|
||||
parameter.MakeEmpty();
|
||||
parameter.AddString(MDSU_NAME, PPP_DIAL_ON_DEMAND_KEY);
|
||||
parameter.AddString(MDSU_VALUES, "enabled");
|
||||
settings->AddMessage(MDSU_PARAMETERS, ¶meter);
|
||||
|
||||
if(fExtrasView->AskBeforeDialing()) {
|
||||
if(fConnectionOptionsView->AskBeforeDialing()) {
|
||||
parameter.MakeEmpty();
|
||||
parameter.AddString(MDSU_NAME, PPP_ASK_BEFORE_DIALING_KEY);
|
||||
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.AddString(MDSU_NAME, PPP_AUTO_REDIAL_KEY);
|
||||
parameter.AddString(MDSU_VALUES, "enabled");
|
||||
@@ -135,7 +149,7 @@ ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempor
|
||||
|
||||
|
||||
bool
|
||||
ExtrasAddon::GetPreferredSize(float *width, float *height) const
|
||||
ConnectionOptionsAddon::GetPreferredSize(float *width, float *height) const
|
||||
{
|
||||
BRect rect;
|
||||
if(Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect) != B_OK)
|
||||
@@ -152,58 +166,50 @@ ExtrasAddon::GetPreferredSize(float *width, float *height) const
|
||||
|
||||
|
||||
BView*
|
||||
ExtrasAddon::CreateView(BPoint leftTop)
|
||||
ConnectionOptionsAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
if(!fExtrasView) {
|
||||
if(!fConnectionOptionsView) {
|
||||
BRect rect;
|
||||
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
|
||||
fExtrasView = new ExtrasView(this, rect);
|
||||
fExtrasView->Reload();
|
||||
fConnectionOptionsView = new ConnectionOptionsView(this, rect);
|
||||
fConnectionOptionsView->Reload();
|
||||
}
|
||||
|
||||
fExtrasView->MoveTo(leftTop);
|
||||
return fExtrasView;
|
||||
fConnectionOptionsView->MoveTo(leftTop);
|
||||
return fConnectionOptionsView;
|
||||
}
|
||||
|
||||
|
||||
ExtrasView::ExtrasView(ExtrasAddon *addon, BRect frame)
|
||||
: BView(frame, "Extras", B_FOLLOW_NONE, 0),
|
||||
ConnectionOptionsView::ConnectionOptionsView(ConnectionOptionsAddon *addon, BRect frame)
|
||||
: BView(frame, kLabelConnectionOptions, B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(10, 10);
|
||||
rect.bottom = rect.top + 15;
|
||||
fDialOnDemand = new BRadioButton(rect, "DialOnDemand", "Dial On Demand",
|
||||
new BMessage(MSG_UPDATE_CONTROLS));
|
||||
fDialOnDemand = new BCheckBox(rect, "DialOnDemand", kLabelDialOnDemand,
|
||||
new BMessage(kMsgUpdateControls));
|
||||
rect.top = rect.bottom + 3;
|
||||
rect.bottom = rect.top + 15;
|
||||
rect.left += 15;
|
||||
fAskBeforeDialing = new BCheckBox(rect, "AskBeforeDialing", "Ask Before Dialing",
|
||||
rect.left += 20;
|
||||
fAskBeforeDialing = new BCheckBox(rect, "AskBeforeDialing", kLabelAskBeforeDialing,
|
||||
NULL);
|
||||
rect.left -= 15;
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 15;
|
||||
fDialManually = new BRadioButton(rect, "DialManually", "Dial Manually",
|
||||
new BMessage(MSG_UPDATE_CONTROLS));
|
||||
rect.left -= 20;
|
||||
rect.top = rect.bottom + 20;
|
||||
rect.bottom = rect.top + 15;
|
||||
fAutoRedial = new BCheckBox(rect, "AutoRedial", "Auto-Redial", NULL);
|
||||
fAutoRedial = new BCheckBox(rect, "AutoRedial", kLabelAutoRedial, NULL);
|
||||
|
||||
AddChild(fDialOnDemand);
|
||||
AddChild(fAskBeforeDialing);
|
||||
AddChild(fDialManually);
|
||||
AddChild(fAutoRedial);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExtrasView::Reload()
|
||||
ConnectionOptionsView::Reload()
|
||||
{
|
||||
if(Addon()->DoesDialOnDemand() || Addon()->IsNew())
|
||||
fDialOnDemand->SetValue(1);
|
||||
else
|
||||
fDialManually->SetValue(1);
|
||||
|
||||
fDialOnDemand->SetValue(Addon()->DoesDialOnDemand() || Addon()->IsNew());
|
||||
// this is enabled by default
|
||||
fAskBeforeDialing->SetValue(Addon()->AskBeforeDialing());
|
||||
fAutoRedial->SetValue(Addon()->DoesAutoRedial());
|
||||
|
||||
@@ -215,19 +221,18 @@ ExtrasView::Reload()
|
||||
|
||||
|
||||
void
|
||||
ExtrasView::AttachedToWindow()
|
||||
ConnectionOptionsView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fDialOnDemand->SetTarget(this);
|
||||
fDialManually->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExtrasView::MessageReceived(BMessage *message)
|
||||
ConnectionOptionsView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MSG_UPDATE_CONTROLS:
|
||||
case kMsgUpdateControls:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
@@ -238,13 +243,12 @@ ExtrasView::MessageReceived(BMessage *message)
|
||||
|
||||
|
||||
void
|
||||
ExtrasView::UpdateControls()
|
||||
ConnectionOptionsView::UpdateControls()
|
||||
{
|
||||
if(fDialManually->Value())
|
||||
fAskBeforeDialing->SetEnabled(false);
|
||||
else
|
||||
if(fDialOnDemand->Value())
|
||||
fAskBeforeDialing->SetEnabled(true);
|
||||
else
|
||||
fAskBeforeDialing->SetEnabled(false);
|
||||
|
||||
fAskBeforeDialing->SetValue(1);
|
||||
// this should be enabled by default
|
||||
fAskBeforeDialing->SetValue(fDialOnDemand->Value());
|
||||
}
|
||||
+14
-15
@@ -4,25 +4,25 @@
|
||||
//
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||
//-----------------------------------------------------------------------
|
||||
// ExtrasAddon saves the loaded settings.
|
||||
// ExtrasView saves the current settings.
|
||||
// ConnectionOptionsAddon saves the loaded settings.
|
||||
// ConnectionOptionsView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#ifndef _EXTRAS_ADDON__H
|
||||
#define _EXTRAS_ADDON__H
|
||||
#ifndef _CONNECTION_OPTIONS_ADDON__H
|
||||
#define _CONNECTION_OPTIONS_ADDON__H
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <RadioButton.h>
|
||||
|
||||
class ExtrasView;
|
||||
class ConnectionOptionsView;
|
||||
|
||||
|
||||
class ExtrasAddon : public DialUpAddon {
|
||||
class ConnectionOptionsAddon : public DialUpAddon {
|
||||
public:
|
||||
ExtrasAddon(BMessage *addons);
|
||||
virtual ~ExtrasAddon();
|
||||
ConnectionOptionsAddon(BMessage *addons);
|
||||
virtual ~ConnectionOptionsAddon();
|
||||
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
@@ -53,15 +53,15 @@ class ExtrasAddon : public DialUpAddon {
|
||||
bool fDoesDialOnDemand, fAskBeforeDialing, fDoesAutoRedial;
|
||||
BMessage *fSettings, *fProfile;
|
||||
// saves last settings state
|
||||
ExtrasView *fExtrasView;
|
||||
ConnectionOptionsView *fConnectionOptionsView;
|
||||
};
|
||||
|
||||
|
||||
class ExtrasView : public BView {
|
||||
class ConnectionOptionsView : public BView {
|
||||
public:
|
||||
ExtrasView(ExtrasAddon *addon, BRect frame);
|
||||
ConnectionOptionsView(ConnectionOptionsAddon *addon, BRect frame);
|
||||
|
||||
ExtrasAddon *Addon() const
|
||||
ConnectionOptionsAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
|
||||
@@ -79,9 +79,8 @@ class ExtrasView : public BView {
|
||||
void UpdateControls();
|
||||
|
||||
private:
|
||||
ExtrasAddon *fAddon;
|
||||
BCheckBox *fAskBeforeDialing, *fAutoRedial;
|
||||
BRadioButton *fDialOnDemand, *fDialManually;
|
||||
ConnectionOptionsAddon *fAddon;
|
||||
BCheckBox *fDialOnDemand, *fAskBeforeDialing, *fAutoRedial;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ All add-ons must add a "Valid" boolean value to every recognized parameter. The
|
||||
--------------------------------------------------------------------------------------
|
||||
Add-on registration:
|
||||
--------------------------------------------------------------------------------------
|
||||
Tabs:
|
||||
Tabs and Protocols (protocols are tabs):
|
||||
DUN_TAB_ADDON_TYPE : pointer to DialUpAddon object
|
||||
|
||||
Authenticators:
|
||||
@@ -21,10 +21,6 @@ DUN_AUTHENTICATOR_ADDON_TYPE : BMessage with the following entries:
|
||||
Devices:
|
||||
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:
|
||||
DUN_DELETE_ON_QUIT : pointer to DialUpAddon object - this will be deleted when the preflet quits
|
||||
(you should register all your addons here, too)
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
#include <Point.h>
|
||||
|
||||
|
||||
// -------------------------------------------
|
||||
// uncomment the language (English by default)
|
||||
// #define LANG_GERMAN
|
||||
// -------------------------------------------
|
||||
|
||||
#define DUN_MAXIMUM_PRIORITY 50
|
||||
|
||||
// add-on types
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#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 {
|
||||
@@ -33,16 +33,18 @@ class DialUpWindow : public BWindow {
|
||||
|
||||
int main()
|
||||
{
|
||||
DialUpApplication *app = new DialUpApplication();
|
||||
new DialUpApplication();
|
||||
|
||||
app->Run();
|
||||
be_app->Run();
|
||||
|
||||
delete be_app;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
DialUpApplication::DialUpApplication()
|
||||
: BApplication(DIAL_UP_SIGNATURE)
|
||||
: BApplication(kSignature)
|
||||
{
|
||||
BRect rect(150, 50, 450, 435);
|
||||
DialUpWindow *window = new DialUpWindow(rect);
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
#include "TextRequestDialog.h"
|
||||
|
||||
// built-in add-ons
|
||||
#include "ExtrasAddon.h"
|
||||
#include "ConnectionOptionsAddon.h"
|
||||
#include "GeneralAddon.h"
|
||||
#include "IPCPAddon.h"
|
||||
#include "PPPoEAddon.h"
|
||||
#include "ProtocolsAddon.h"
|
||||
|
||||
|
||||
#include <PPPInterface.h>
|
||||
#include <settings_tools.h>
|
||||
#include <TemplateList.h>
|
||||
|
||||
#include <Application.h>
|
||||
@@ -41,35 +40,74 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
#define MSG_CREATE_NEW 'NEWI'
|
||||
#define MSG_FINISH_CREATE_NEW 'FNEW'
|
||||
#define MSG_DELETE_CURRENT 'DELI'
|
||||
#define MSG_SELECT_INTERFACE 'SELI'
|
||||
#define MSG_CONNECT_BUTTON 'CONI'
|
||||
// message constants
|
||||
static const uint32 kMsgCreateNew = 'NEWI';
|
||||
static const uint32 kMsgFinishCreateNew = 'FNEW';
|
||||
static const uint32 kMsgDeleteCurrent = 'DELI';
|
||||
static const uint32 kMsgSelectInterface = 'SELI';
|
||||
static const uint32 kMsgConnectButton = 'CONI';
|
||||
|
||||
#define LABEL_CREATE_NEW "Create New..."
|
||||
#define LABEL_DELETE_CURRENT "Delete Current"
|
||||
// labels
|
||||
#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"
|
||||
#define LABEL_DISCONNECT "Disconnect"
|
||||
// connection status strings
|
||||
#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..."
|
||||
#define TEXT_CONNECTION_ESTABLISHED "Connection established."
|
||||
#define TEXT_NOT_CONNECTED "Not connected."
|
||||
#define TEXT_DEVICE_ERROR "Device error!"
|
||||
#define TEXT_AUTHENTICATING "Authenticating..."
|
||||
#define TEXT_AUTHENTICATION_FAILED "Authentication failed!"
|
||||
#define TEXT_CONNECTION_LOST "Connection lost!"
|
||||
#define TEXT_CREATION_ERROR "Error creating interface!"
|
||||
#define TEXT_NO_INTERFACES_FOUND "No interfaces found..."
|
||||
#define TEXT_OK "OK"
|
||||
#define ERROR_TITLE "Error"
|
||||
#define ERROR_NO_PPP_STACK "Error: Could not find the PPP stack!"
|
||||
#define ERROR_INTERFACE_EXISTS "Error: An interface with this name already " \
|
||||
"exists!"
|
||||
#define ERROR_LOADING_FAILED "Error: Failed loading interface! The current " \
|
||||
"settings will be deleted."
|
||||
#define ERROR_SAVING_FAILED "Error: Failed saving interface settings!"
|
||||
// error strings for alerts
|
||||
#ifdef LANG_GERMAN
|
||||
static const char *kErrorTitle = "Fehler";
|
||||
static const char *kErrorNoPPPStack = "Fehler: Kein Zugriff auf den PPP Stack!";
|
||||
static const char *kErrorInterfaceExists = "Fehler: Eine Verbindung mit diesem Namen "
|
||||
"existiert bereits!";
|
||||
static const char *kErrorLoadingFailed = "Fehler: Konfiguration ist fehlerhaft! Die "
|
||||
"Einstellungen werden zurückgesetzt.";
|
||||
static const char *kErrorSavingFailed = "Fehler: Speichern der Einstellungen ist "
|
||||
"fehlgeschlagen!";
|
||||
#else
|
||||
static const char *kErrorTitle = "Error";
|
||||
static const char *kErrorNoPPPStack = "Error: Could not access the PPP stack!";
|
||||
static const char *kErrorInterfaceExists = "Error: An interface with this name "
|
||||
"already exists!";
|
||||
static const char *kErrorLoadingFailed = "Error: Failed loading interface! The "
|
||||
"current settings will be deleted.";
|
||||
static const char *kErrorSavingFailed = "Error: Failed saving interface settings!";
|
||||
#endif
|
||||
|
||||
|
||||
static
|
||||
@@ -99,12 +137,12 @@ DialUpView::DialUpView(BRect frame)
|
||||
fAddons.AddMessenger(DUN_MESSENGER, messenger);
|
||||
|
||||
// create pop-up with all interfaces and "New..."/"Delete current" items
|
||||
fInterfaceMenu = new BPopUpMenu(LABEL_CREATE_NEW);
|
||||
fInterfaceMenu = new BPopUpMenu(kLabelCreateNew);
|
||||
BRect rect = bounds;
|
||||
rect.InsetBy(5, 5);
|
||||
rect.bottom = rect.top + 20;
|
||||
fMenuField = new BMenuField(rect, "Interfaces", "Interface:", fInterfaceMenu);
|
||||
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 10);
|
||||
fMenuField = new BMenuField(rect, "Interfaces", kLabelInterface, fInterfaceMenu);
|
||||
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 5);
|
||||
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = bounds.bottom
|
||||
@@ -119,20 +157,20 @@ DialUpView::DialUpView(BRect frame)
|
||||
stringRect.top += (stringRect.Height() - 15) / 2;
|
||||
stringRect.bottom = stringRect.top + 15;
|
||||
fStringView = new BStringView(stringRect, "NoInterfacesFound",
|
||||
TEXT_NO_INTERFACES_FOUND);
|
||||
kTextNoInterfacesFound);
|
||||
fStringView->SetAlignment(B_ALIGN_CENTER);
|
||||
fStringView->Hide();
|
||||
|
||||
rect.top = rect.bottom + 15;
|
||||
rect.bottom = rect.top + 15;
|
||||
rect.right = rect.left + 200;
|
||||
fStatusView = new BStringView(rect, "StatusView", TEXT_NOT_CONNECTED);
|
||||
fStatusView = new BStringView(rect, "StatusView", kTextNotConnected);
|
||||
|
||||
rect.InsetBy(0, -5);
|
||||
rect.left = rect.right + 5;
|
||||
rect.right = bounds.right - 5;
|
||||
fConnectButton = new BButton(rect, "ConnectButton", LABEL_CONNECT,
|
||||
new BMessage(MSG_CONNECT_BUTTON));
|
||||
fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect,
|
||||
new BMessage(kMsgConnectButton));
|
||||
|
||||
AddChild(fMenuField);
|
||||
AddChild(fTabView);
|
||||
@@ -174,8 +212,11 @@ DialUpView::AttachedToWindow()
|
||||
fInterfaceMenu->SetTargetForItems(this);
|
||||
fConnectButton->SetTarget(this);
|
||||
|
||||
if(fListener.InitCheck() != B_OK)
|
||||
(new BAlert(ERROR_TITLE, ERROR_NO_PPP_STACK, TEXT_OK))->Go(NULL);
|
||||
if(fListener.InitCheck() != B_OK) {
|
||||
(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;
|
||||
|
||||
// -------------------------------------------------
|
||||
case MSG_CREATE_NEW: {
|
||||
(new TextRequestDialog("New Interface", "Interface Name: "))->Go(
|
||||
new BInvoker(new BMessage(MSG_FINISH_CREATE_NEW), this));
|
||||
case kMsgCreateNew: {
|
||||
(new TextRequestDialog(kLabelNewInterface, kLabelInterfaceName))->Go(
|
||||
new BInvoker(new BMessage(kMsgFinishCreateNew), this));
|
||||
} break;
|
||||
|
||||
case MSG_FINISH_CREATE_NEW: {
|
||||
case kMsgFinishCreateNew: {
|
||||
int32 which;
|
||||
message->FindInt32("which", &which);
|
||||
const char *name = message->FindString("text");
|
||||
@@ -205,7 +246,7 @@ DialUpView::MessageReceived(BMessage *message)
|
||||
} break;
|
||||
// -------------------------------------------------
|
||||
|
||||
case MSG_DELETE_CURRENT: {
|
||||
case kMsgDeleteCurrent: {
|
||||
if(!fCurrentItem)
|
||||
return;
|
||||
|
||||
@@ -229,13 +270,13 @@ DialUpView::MessageReceived(BMessage *message)
|
||||
// this stops watching the deleted interface
|
||||
} break;
|
||||
|
||||
case MSG_SELECT_INTERFACE: {
|
||||
case kMsgSelectInterface: {
|
||||
int32 index;
|
||||
message->FindInt32("index", &index);
|
||||
SelectInterface(index);
|
||||
} break;
|
||||
|
||||
case MSG_CONNECT_BUTTON: {
|
||||
case kMsgConnectButton: {
|
||||
if(!fCurrentItem || fUpDownThread != -1)
|
||||
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
|
||||
DialUpView::LoadSettings(bool isNew)
|
||||
{
|
||||
@@ -377,18 +454,28 @@ DialUpView::SaveSettingsToFile()
|
||||
void
|
||||
DialUpView::UpDownThread()
|
||||
{
|
||||
SaveSettingsToFile();
|
||||
BMessage settings, profile;
|
||||
SaveSettings(&settings, &profile, true);
|
||||
// save temporary profile
|
||||
driver_settings *temporaryProfile = MessageToDriverSettings(profile);
|
||||
|
||||
PPPInterface interface;
|
||||
if(fWatching == PPP_UNDEFINED_INTERFACE_ID) {
|
||||
interface = fListener.Manager().InterfaceWithName(fCurrentItem->Label());
|
||||
if(interface.InitCheck() != B_OK)
|
||||
interface = fListener.Manager().CreateInterfaceWithName(
|
||||
fCurrentItem->Label());
|
||||
} else
|
||||
fCurrentItem->Label(), temporaryProfile);
|
||||
} else {
|
||||
interface = fWatching;
|
||||
interface.SetProfile(temporaryProfile);
|
||||
}
|
||||
|
||||
free_driver_settings(temporaryProfile);
|
||||
|
||||
if(interface.InitCheck() != B_OK) {
|
||||
Window()->Lock();
|
||||
fStatusView->SetText(TEXT_CREATION_ERROR);
|
||||
fStatusView->SetText(kTextCreationError);
|
||||
Window()->Unlock();
|
||||
return;
|
||||
}
|
||||
@@ -505,7 +592,7 @@ DialUpView::CreateTabs()
|
||||
if(!addon->GetPreferredSize(&width, &height))
|
||||
continue;
|
||||
|
||||
target = addon->CreateView(BPoint(0,0));
|
||||
target = addon->CreateView(BPoint(0, 0));
|
||||
if(!target)
|
||||
continue;
|
||||
|
||||
@@ -521,47 +608,52 @@ DialUpView::UpdateStatus(int32 code)
|
||||
case PPP_REPORT_UP_ABORTED:
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
case PPP_REPORT_CONNECTION_LOST: {
|
||||
fConnectButton->SetLabel(LABEL_CONNECT);
|
||||
fConnectButton->SetLabel(kLabelConnect);
|
||||
} break;
|
||||
|
||||
default:
|
||||
fConnectButton->SetLabel(LABEL_DISCONNECT);
|
||||
fConnectButton->SetLabel(kLabelDisconnect);
|
||||
}
|
||||
|
||||
// maybe the information string must stay
|
||||
if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL)
|
||||
return;
|
||||
|
||||
if(fListener.InitCheck() != B_OK) {
|
||||
fStatusView->SetText(kErrorNoPPPStack);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
case PPP_REPORT_GOING_UP:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(TEXT_CONNECTING);
|
||||
fStatusView->SetText(kTextConnecting);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_UP_SUCCESSFUL:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(TEXT_CONNECTION_ESTABLISHED);
|
||||
fStatusView->SetText(kTextConnectionEstablished);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_UP_ABORTED:
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
fStatusView->SetText(TEXT_NOT_CONNECTED);
|
||||
fStatusView->SetText(kTextNotConnected);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED:
|
||||
case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED:
|
||||
fStatusView->SetText(TEXT_AUTHENTICATING);
|
||||
fStatusView->SetText(kTextAuthenticating);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED:
|
||||
case PPP_REPORT_PEER_AUTHENTICATION_FAILED:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(TEXT_AUTHENTICATION_FAILED);
|
||||
fStatusView->SetText(kTextAuthenticationFailed);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_CONNECTION_LOST:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(TEXT_CONNECTION_LOST);
|
||||
fStatusView->SetText(kTextConnectionLost);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -612,10 +704,10 @@ void
|
||||
DialUpView::LoadInterfaces()
|
||||
{
|
||||
fInterfaceMenu->AddSeparatorItem();
|
||||
fInterfaceMenu->AddItem(new BMenuItem(LABEL_CREATE_NEW,
|
||||
new BMessage(MSG_CREATE_NEW)));
|
||||
fDeleterItem = new BMenuItem(LABEL_DELETE_CURRENT,
|
||||
new BMessage(MSG_DELETE_CURRENT));
|
||||
fInterfaceMenu->AddItem(new BMenuItem(kLabelCreateNew,
|
||||
new BMessage(kMsgCreateNew)));
|
||||
fDeleterItem = new BMenuItem(kLabelDeleteCurrent,
|
||||
new BMessage(kMsgDeleteCurrent));
|
||||
fInterfaceMenu->AddItem(fDeleterItem);
|
||||
|
||||
BDirectory settingsDirectory;
|
||||
@@ -635,32 +727,33 @@ void
|
||||
DialUpView::LoadAddons()
|
||||
{
|
||||
// Load integrated add-ons:
|
||||
// "Extras" tab
|
||||
ExtrasAddon *extrasAddon = new ExtrasAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, extrasAddon);
|
||||
fAddons.AddPointer(DUN_DELETE_ON_QUIT, extrasAddon);
|
||||
// "Connection Options" tab
|
||||
ConnectionOptionsAddon *connectionOptionsAddon =
|
||||
new ConnectionOptionsAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, connectionOptionsAddon);
|
||||
fAddons.AddPointer(DUN_DELETE_ON_QUIT, connectionOptionsAddon);
|
||||
// "General" tab
|
||||
GeneralAddon *generalAddon = new GeneralAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, generalAddon);
|
||||
fAddons.AddPointer(DUN_DELETE_ON_QUIT, generalAddon);
|
||||
GeneralAddon *fGeneralAddon = new GeneralAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, fGeneralAddon);
|
||||
fAddons.AddPointer(DUN_DELETE_ON_QUIT, fGeneralAddon);
|
||||
// "IPCP" protocol
|
||||
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);
|
||||
// "PPPoE" device
|
||||
PPPoEAddon *pppoeAddon = new PPPoEAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_DEVICE_ADDON_TYPE, 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
|
||||
BMessage addon;
|
||||
addon.AddString("KernelModuleName", "pap");
|
||||
#ifdef LANG_GERMAN
|
||||
addon.AddString("FriendlyName", "Unverschlüsselt");
|
||||
#else
|
||||
addon.AddString("FriendlyName", "Plain-text Authentication");
|
||||
#endif
|
||||
addon.AddString("TechnicalName", "PAP");
|
||||
addon.AddString("KernelModuleName", "pap");
|
||||
fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon);
|
||||
// addon.MakeEmpty(); // for next authenticator
|
||||
|
||||
@@ -673,11 +766,12 @@ void
|
||||
DialUpView::AddInterface(const char *name, bool isNew = false)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
BMenuItem *item = new BMenuItem(name, new BMessage(MSG_SELECT_INTERFACE));
|
||||
BMenuItem *item = new BMenuItem(name, new BMessage(kMsgSelectInterface));
|
||||
item->SetTarget(this);
|
||||
int32 index = FindNextMenuInsertionIndex(fInterfaceMenu, name);
|
||||
if(index > CountInterfaces())
|
||||
@@ -698,7 +792,8 @@ DialUpView::SelectInterface(int32 index, bool isNew = false)
|
||||
return;
|
||||
|
||||
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(CountInterfaces() > 0)
|
||||
@@ -723,10 +818,12 @@ DialUpView::SelectInterface(int32 index, bool isNew = false)
|
||||
LoadSettings(false);
|
||||
// tell modules to unload all settings
|
||||
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);
|
||||
} 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) {
|
||||
fDeleterItem->SetEnabled(false);
|
||||
fInterfaceMenu->SetRadioMode(false);
|
||||
fInterfaceMenu->Superitem()->SetLabel(LABEL_CREATE_NEW);
|
||||
fInterfaceMenu->Superitem()->SetLabel(kLabelCreateNew);
|
||||
fTabView->Hide();
|
||||
fStringView->Show();
|
||||
fConnectButton->SetEnabled(false);
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#ifndef _DIAL_UP_VIEW__H
|
||||
#define _DIAL_UP_VIEW__H
|
||||
|
||||
#include <View.h>
|
||||
#include <Message.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <PPPInterfaceListener.h>
|
||||
|
||||
class GeneralAddon;
|
||||
|
||||
|
||||
class DialUpView : public BView {
|
||||
public:
|
||||
@@ -23,6 +25,12 @@ class DialUpView : public BView {
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
void UpDownThread();
|
||||
|
||||
// used by ppp_server
|
||||
bool SelectInterfaceNamed(const char *name);
|
||||
BView *AuthenticationView() const;
|
||||
BView *StatusView() const;
|
||||
BView *ConnectButton() const;
|
||||
|
||||
private:
|
||||
void GetPPPDirectories(BDirectory *settingsDirectory,
|
||||
@@ -58,6 +66,7 @@ class DialUpView : public BView {
|
||||
BMenuItem *fCurrentItem, *fDeleterItem;
|
||||
ppp_interface_id fWatching;
|
||||
|
||||
GeneralAddon *fGeneralAddon;
|
||||
bool fKeepLabel;
|
||||
BStringView *fStatusView;
|
||||
BButton *fConnectButton;
|
||||
|
||||
@@ -25,12 +25,36 @@
|
||||
#include <PPPDefs.h>
|
||||
|
||||
|
||||
#define MSG_SELECT_DEVICE 'SELD'
|
||||
#define MSG_SELECT_AUTHENTICATOR 'SELA'
|
||||
// message constants
|
||||
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"
|
||||
#define GENERAL_TAB_AUTHENTICATORS "Authenticators"
|
||||
// string constants for information saved in the settings message
|
||||
static const char *kGeneralTabAuthentication = "Authentication";
|
||||
static const char *kGeneralTabAuthenticators = "Authenticators";
|
||||
|
||||
|
||||
#define DEFAULT_AUTHENTICATOR "PAP"
|
||||
@@ -141,11 +165,11 @@ GeneralAddon::LoadAuthenticationSettings()
|
||||
// fatal error: we do not know how to handle this authenticator
|
||||
|
||||
MarkAuthenticatorAsValid(name);
|
||||
authentication.AddString(GENERAL_TAB_AUTHENTICATORS, name);
|
||||
authentication.AddString(kGeneralTabAuthenticators, name);
|
||||
++fAuthenticatorsCount;
|
||||
}
|
||||
|
||||
fSettings->AddMessage(GENERAL_TAB_AUTHENTICATION, &authentication);
|
||||
fSettings->AddMessage(kGeneralTabAuthentication, &authentication);
|
||||
|
||||
bool hasUsername = false;
|
||||
// a username must be present
|
||||
@@ -218,14 +242,14 @@ GeneralAddon::IsAuthenticationModified(bool *settings, bool *profile) const
|
||||
*settings = fGeneralView->AuthenticatorName();
|
||||
else {
|
||||
BMessage authentication;
|
||||
if(fSettings->FindMessage(GENERAL_TAB_AUTHENTICATION, &authentication) != B_OK) {
|
||||
if(fSettings->FindMessage(kGeneralTabAuthentication, &authentication) != B_OK) {
|
||||
*settings = *profile = false;
|
||||
return;
|
||||
// error!
|
||||
}
|
||||
|
||||
BString authenticator;
|
||||
if(authentication.FindString(GENERAL_TAB_AUTHENTICATORS,
|
||||
if(authentication.FindString(kGeneralTabAuthenticators,
|
||||
&authenticator) != B_OK) {
|
||||
*settings = *profile = false;
|
||||
return;
|
||||
@@ -303,14 +327,21 @@ GeneralAddon::CreateView(BPoint leftTop)
|
||||
BRect rect;
|
||||
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
|
||||
fGeneralView = new GeneralView(this, rect);
|
||||
fGeneralView->Reload();
|
||||
}
|
||||
|
||||
fGeneralView->MoveTo(leftTop);
|
||||
fGeneralView->Reload();
|
||||
return fGeneralView;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
GeneralAddon::AuthenticationView() const
|
||||
{
|
||||
return fGeneralView ? fGeneralView->AuthenticationView() : NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const
|
||||
{
|
||||
@@ -351,7 +382,7 @@ GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
|
||||
|
||||
|
||||
GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
||||
: BView(frame, "General", B_FOLLOW_NONE, 0),
|
||||
: BView(frame, kLabelGeneral, B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
@@ -368,41 +399,49 @@ GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
||||
fAuthenticationBox = new BBox(rect, "Authentication");
|
||||
|
||||
fDeviceField = new BMenuField(BRect(5, 0, 250, 20), "Device",
|
||||
"Device:", new BPopUpMenu("No Devices Found!"));
|
||||
fDeviceField->SetDivider(StringWidth(fDeviceField->Label()) + 10);
|
||||
kLabelDevice, new BPopUpMenu(kLabelNoDevicesFound));
|
||||
fDeviceField->SetDivider(StringWidth(fDeviceField->Label()) + 5);
|
||||
fDeviceField->Menu()->SetRadioMode(true);
|
||||
AddDevices();
|
||||
fDeviceBox->SetLabel(fDeviceField);
|
||||
|
||||
fAuthenticatorField = new BMenuField(BRect(5, 0, 250, 20), "Authenticator",
|
||||
"Authenticator:", new BPopUpMenu("No Authenticators Found!"));
|
||||
fAuthenticatorField->SetDivider(StringWidth(fAuthenticatorField->Label()) + 10);
|
||||
kLabelAuthenticator, new BPopUpMenu(kLabelNoAuthenticatorsFound));
|
||||
fAuthenticatorField->SetDivider(StringWidth(fAuthenticatorField->Label()) + 5);
|
||||
fAuthenticatorField->Menu()->SetRadioMode(true);
|
||||
AddAuthenticators();
|
||||
fAuthenticationBox->SetLabel(fAuthenticatorField);
|
||||
|
||||
rect = fAuthenticationBox->Bounds();
|
||||
rect.InsetBy(10, 0);
|
||||
rect.InsetBy(10, 5);
|
||||
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;
|
||||
fUsername = new BTextControl(rect, "username", "Name: ", NULL, NULL);
|
||||
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
|
||||
rect.top = rect.bottom + 5;
|
||||
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);
|
||||
float usernameWidth = StringWidth(fUsername->Label()) + 5;
|
||||
float passwordWidth = StringWidth(fPassword->Label()) + 5;
|
||||
float width = max(usernameWidth, passwordWidth);
|
||||
fUsername->SetDivider(width);
|
||||
fPassword->SetDivider(width);
|
||||
|
||||
// set dividers
|
||||
float width = max(StringWidth(fUsername->Label()),
|
||||
StringWidth(fPassword->Label()));
|
||||
fUsername->SetDivider(width + 5);
|
||||
fPassword->SetDivider(width + 5);
|
||||
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
fSavePassword = new BCheckBox(rect, "SavePassword", "Save Password", NULL);
|
||||
fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL);
|
||||
|
||||
fAuthenticationBox->AddChild(fUsername);
|
||||
fAuthenticationBox->AddChild(fPassword);
|
||||
fAuthenticationBox->AddChild(fSavePassword);
|
||||
fAuthenticationView->AddChild(fUsername);
|
||||
fAuthenticationView->AddChild(fPassword);
|
||||
fAuthenticationView->AddChild(fSavePassword);
|
||||
fAuthenticationBox->AddChild(fAuthenticationView);
|
||||
|
||||
AddChild(fDeviceBox);
|
||||
AddChild(fAuthenticationBox);
|
||||
@@ -446,9 +485,9 @@ GeneralView::Reload()
|
||||
if(Addon()->CountAuthenticators() > 0) {
|
||||
BString kernelModule, authenticator;
|
||||
BMessage authentication;
|
||||
if(Addon()->Settings()->FindMessage(GENERAL_TAB_AUTHENTICATION,
|
||||
if(Addon()->Settings()->FindMessage(kGeneralTabAuthentication,
|
||||
&authentication) == B_OK)
|
||||
authentication.FindString(GENERAL_TAB_AUTHENTICATORS, &authenticator);
|
||||
authentication.FindString(kGeneralTabAuthenticators, &authenticator);
|
||||
BMenu *menu = fAuthenticatorField->Menu();
|
||||
for(int32 index = 0; index < menu->CountItems(); index++) {
|
||||
item = menu->ItemAt(index);
|
||||
@@ -521,7 +560,7 @@ void
|
||||
GeneralView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MSG_SELECT_DEVICE:
|
||||
case kMsgSelectDevice:
|
||||
if(message->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon))
|
||||
!= B_OK)
|
||||
fDeviceAddon = NULL;
|
||||
@@ -534,7 +573,7 @@ GeneralView::MessageReceived(BMessage *message)
|
||||
}
|
||||
break;
|
||||
|
||||
case MSG_SELECT_AUTHENTICATOR:
|
||||
case kMsgSelectAuthenticator:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
@@ -608,7 +647,7 @@ void
|
||||
GeneralView::AddDevices()
|
||||
{
|
||||
AddAddonsToMenu(Addon()->Addons(), fDeviceField->Menu(), DUN_DEVICE_ADDON_TYPE,
|
||||
MSG_SELECT_DEVICE);
|
||||
kMsgSelectDevice);
|
||||
}
|
||||
|
||||
|
||||
@@ -616,7 +655,8 @@ void
|
||||
GeneralView::AddAuthenticators()
|
||||
{
|
||||
fAuthenticatorDefault = NULL;
|
||||
fAuthenticatorNone = new BMenuItem("None", new BMessage(MSG_SELECT_AUTHENTICATOR));
|
||||
fAuthenticatorNone = new BMenuItem(kLabelNone,
|
||||
new BMessage(kMsgSelectAuthenticator));
|
||||
fAuthenticatorField->Menu()->AddItem(fAuthenticatorNone);
|
||||
fAuthenticatorNone->SetMarked(true);
|
||||
fAuthenticatorField->Menu()->AddSeparatorItem();
|
||||
@@ -626,7 +666,7 @@ GeneralView::AddAuthenticators()
|
||||
for(int32 index = 0;
|
||||
Addon()->Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
|
||||
&addon) == B_OK; index++) {
|
||||
BMessage *message = new BMessage(MSG_SELECT_AUTHENTICATOR);
|
||||
BMessage *message = new BMessage(kMsgSelectAuthenticator);
|
||||
message->AddString("KernelModuleName", addon.FindString("KernelModuleName"));
|
||||
|
||||
BString name, technicalName, friendlyName;
|
||||
|
||||
@@ -64,6 +64,9 @@ class GeneralAddon : public DialUpAddon {
|
||||
bool saveTemporary);
|
||||
virtual bool GetPreferredSize(float *width, float *height) const;
|
||||
virtual BView *CreateView(BPoint leftTop);
|
||||
|
||||
// used by ppp_server
|
||||
BView *AuthenticationView() const;
|
||||
|
||||
private:
|
||||
bool GetAuthenticator(const BString& moduleName, BMessage *entry) const;
|
||||
@@ -108,6 +111,10 @@ class GeneralView : public BView {
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
// used by ppp_server
|
||||
BView *AuthenticationView() const
|
||||
{ return fAuthenticationView; }
|
||||
|
||||
private:
|
||||
void ReloadDeviceView();
|
||||
@@ -120,6 +127,7 @@ class GeneralView : public BView {
|
||||
GeneralAddon *fAddon;
|
||||
DialUpAddon *fDeviceAddon;
|
||||
BBox *fDeviceBox, *fAuthenticationBox;
|
||||
BView *fAuthenticationView;
|
||||
BMenuField *fDeviceField, *fAuthenticatorField;
|
||||
BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault;
|
||||
BTextControl *fUsername, *fPassword;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// Copyright (c) 2003-2004 Waldemar Kornewald, [email protected]
|
||||
//-----------------------------------------------------------------------
|
||||
// IPCPAddon saves the loaded settings.
|
||||
// IPCPWindow saves the current settings.
|
||||
// IPCPView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "IPCPAddon.h"
|
||||
@@ -14,23 +14,38 @@
|
||||
#include <stl_algobase.h>
|
||||
// for max()
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include <PPPDefs.h>
|
||||
#include <IPCP.h>
|
||||
// from IPCP addon
|
||||
|
||||
|
||||
#define BUTTON_WIDTH 80
|
||||
// GUI constants
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
#define MSG_CHANGE_SETTINGS 'CHGS'
|
||||
#define MSG_RESET_SETTINGS 'RSTS'
|
||||
// message constants
|
||||
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";
|
||||
static const char kTechnicalName[] = "IPCP";
|
||||
static const char kKernelModuleName[] = "ipcp";
|
||||
// add-on descriptions
|
||||
static const char *kKernelModuleName = "ipcp";
|
||||
|
||||
|
||||
IPCPAddon::IPCPAddon(BMessage *addons)
|
||||
@@ -38,11 +53,6 @@ IPCPAddon::IPCPAddon(BMessage *addons)
|
||||
fSettings(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
|
||||
IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fIsEnabled = false;
|
||||
fIPAddress = fPrimaryDNS = fSecondaryDNS = "";
|
||||
fSettings = settings;
|
||||
fProfile = profile;
|
||||
if(!settings || !profile || isNew) {
|
||||
fIPCPWindow->Reload();
|
||||
// reset all views
|
||||
|
||||
if(fIPCPView)
|
||||
fIPCPView->Reload();
|
||||
// reset all views (empty settings)
|
||||
|
||||
if(!settings || !profile || isNew)
|
||||
return true;
|
||||
}
|
||||
|
||||
BMessage protocol;
|
||||
|
||||
// settings
|
||||
int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol);
|
||||
if(protocolIndex < 0)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
protocol.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
|
||||
@@ -98,7 +90,9 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
// profile
|
||||
protocolIndex = FindIPCPProtocol(*fProfile, &protocol);
|
||||
if(protocolIndex < 0)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
fIsEnabled = true;
|
||||
|
||||
// the "Local" side parameter
|
||||
BMessage local;
|
||||
@@ -151,7 +145,8 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
protocol.AddBool(MDSU_VALID, true);
|
||||
fProfile->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
|
||||
|
||||
fIPCPWindow->Reload();
|
||||
if(fIPCPView)
|
||||
fIPCPView->Reload();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -160,18 +155,15 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
void
|
||||
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) {
|
||||
*profile = false;
|
||||
*settings = *profile = false;
|
||||
return;
|
||||
}
|
||||
|
||||
*profile = (fIPAddress != fIPCPWindow->IPAddress()
|
||||
|| fPrimaryDNS != fIPCPWindow->PrimaryDNS()
|
||||
|| fSecondaryDNS != fIPCPWindow->SecondaryDNS());
|
||||
*settings = fIsEnabled != fIPCPView->IsEnabled();
|
||||
*profile = (*settings || fIPAddress != fIPCPView->IPAddress()
|
||||
|| fPrimaryDNS != fIPCPView->PrimaryDNS()
|
||||
|| fSecondaryDNS != fIPCPView->SecondaryDNS());
|
||||
}
|
||||
|
||||
|
||||
@@ -181,6 +173,9 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar
|
||||
if(!fSettings || !settings)
|
||||
return false;
|
||||
|
||||
if(!fIPCPView->IsEnabled())
|
||||
return true;
|
||||
|
||||
BMessage protocol, local;
|
||||
protocol.AddString(MDSU_NAME, PPP_PROTOCOL_KEY);
|
||||
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);
|
||||
bool needsLocal = false;
|
||||
|
||||
if(fIPCPWindow->IPAddress() && strlen(fIPCPWindow->IPAddress()) > 0) {
|
||||
if(fIPCPView->IPAddress() && strlen(fIPCPView->IPAddress()) > 0) {
|
||||
// save IP address, too
|
||||
needsLocal = true;
|
||||
BMessage ip;
|
||||
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);
|
||||
}
|
||||
|
||||
if(fIPCPWindow->PrimaryDNS() && strlen(fIPCPWindow->PrimaryDNS()) > 0) {
|
||||
if(fIPCPView->PrimaryDNS() && strlen(fIPCPView->PrimaryDNS()) > 0) {
|
||||
// save service name, too
|
||||
needsLocal = true;
|
||||
BMessage dns;
|
||||
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);
|
||||
}
|
||||
|
||||
if(fIPCPWindow->SecondaryDNS() && strlen(fIPCPWindow->SecondaryDNS()) > 0) {
|
||||
if(fIPCPView->SecondaryDNS() && strlen(fIPCPView->SecondaryDNS()) > 0) {
|
||||
// save service name, too
|
||||
needsLocal = true;
|
||||
BMessage dns;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -230,10 +225,15 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar
|
||||
bool
|
||||
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)
|
||||
*width = fIPCPWindow->Bounds().Width();
|
||||
*width = rect.Width();
|
||||
if(height)
|
||||
*height = fIPCPWindow->Bounds().Height();
|
||||
*height = rect.Height();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -242,9 +242,15 @@ IPCPAddon::GetPreferredSize(float *width, float *height) const
|
||||
BView*
|
||||
IPCPAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
fIPCPWindow->MoveTo(leftTop);
|
||||
fIPCPWindow->Show();
|
||||
return NULL;
|
||||
if(!fIPCPView) {
|
||||
BRect rect;
|
||||
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)
|
||||
: BWindow(frame, "IPCP Settings", B_MODAL_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_CLOSABLE),
|
||||
IPCPView::IPCPView(IPCPAddon *addon, BRect frame)
|
||||
: BView(frame, kLabelIPCP, B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
BView *backgroundView = new BView(rect, "backgroundView", B_FOLLOW_NONE, 0);
|
||||
backgroundView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
rect.InsetBy(5, 5);
|
||||
|
||||
float boxHeight = 20 // space at top
|
||||
+ 3 * 20 // size of controls
|
||||
+ 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.InsetBy(10, 10);
|
||||
rect.bottom = rect.top + 15;
|
||||
fIsEnabled = new BCheckBox(rect, "isEnabled", kLabelEnabled,
|
||||
new BMessage(kMsgUpdateControls));
|
||||
rect.left += 15;
|
||||
// indent the other controls to indicate that they depend on this control
|
||||
rect.top = rect.bottom + 5;
|
||||
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.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);
|
||||
optionalRect.top = rect.top;
|
||||
optionalRect.bottom = optionalRect.top + 15;
|
||||
AddChild(new BStringView(optionalRect, "optional_3", kLabelOptional));
|
||||
|
||||
// set divider of text controls
|
||||
float ipAddressWidth = backgroundView->StringWidth(fIPAddress->Label()) + 5;
|
||||
float primaryDNSWidth = backgroundView->StringWidth(fPrimaryDNS->Label()) + 5;
|
||||
float secondaryDNSWidth = backgroundView->StringWidth(fSecondaryDNS->Label()) + 5;
|
||||
float controlWidth = max(max(ipAddressWidth, primaryDNSWidth), secondaryDNSWidth);
|
||||
float controlWidth = max(max(StringWidth(fIPAddress->Label()),
|
||||
StringWidth(fPrimaryDNS->Label())), StringWidth(fSecondaryDNS->Label()));
|
||||
fIPAddress->SetDivider(controlWidth + 5);
|
||||
fPrimaryDNS->SetDivider(controlWidth + 5);
|
||||
fSecondaryDNS->SetDivider(controlWidth + 5);
|
||||
|
||||
fIPAddress->SetDivider(controlWidth);
|
||||
fPrimaryDNS->SetDivider(controlWidth);
|
||||
fSecondaryDNS->SetDivider(controlWidth);
|
||||
|
||||
// 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
|
||||
AddChild(fIsEnabled);
|
||||
AddChild(fIPAddress);
|
||||
AddChild(fPrimaryDNS);
|
||||
AddChild(fSecondaryDNS);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPWindow::Reload()
|
||||
IPCPView::Reload()
|
||||
{
|
||||
Lock();
|
||||
fIPAddress->MakeFocus(true);
|
||||
fIsEnabled->SetValue(Addon()->IsEnabled() || Addon()->IsNew());
|
||||
// enable TCP/IP by default
|
||||
fIPAddress->SetText(Addon()->IPAddress());
|
||||
fPreviousIPAddress = Addon()->IPAddress();
|
||||
fPrimaryDNS->SetText(Addon()->PrimaryDNS());
|
||||
fPreviousPrimaryDNS = Addon()->PrimaryDNS();
|
||||
fSecondaryDNS->SetText(Addon()->SecondaryDNS());
|
||||
fPreviousSecondaryDNS = Addon()->SecondaryDNS();
|
||||
Unlock();
|
||||
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPWindow::MessageReceived(BMessage *message)
|
||||
IPCPView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fIsEnabled->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MSG_CHANGE_SETTINGS:
|
||||
Hide();
|
||||
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());
|
||||
case kMsgUpdateControls:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::UpdateControls()
|
||||
{
|
||||
fIPAddress->SetEnabled(IsEnabled());
|
||||
fPrimaryDNS->SetEnabled(IsEnabled());
|
||||
fSecondaryDNS->SetEnabled(IsEnabled());
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
#include <Window.h>
|
||||
|
||||
class IPCPWindow;
|
||||
class IPCPView;
|
||||
|
||||
|
||||
class IPCPAddon : public DialUpAddon {
|
||||
@@ -28,6 +28,8 @@ class IPCPAddon : public DialUpAddon {
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
|
||||
bool IsEnabled() const
|
||||
{ return fIsEnabled; }
|
||||
const char *IPAddress() const
|
||||
{ return fIPAddress.String(); }
|
||||
const char *PrimaryDNS() const
|
||||
@@ -40,9 +42,8 @@ class IPCPAddon : public DialUpAddon {
|
||||
BMessage *Profile() const
|
||||
{ return fProfile; }
|
||||
|
||||
virtual const char *FriendlyName() const;
|
||||
virtual const char *TechnicalName() const;
|
||||
virtual const char *KernelModuleName() const;
|
||||
virtual int32 Position() const
|
||||
{ return 10; }
|
||||
|
||||
virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
|
||||
virtual void IsModified(bool *settings, bool *profile) const;
|
||||
@@ -55,22 +56,24 @@ class IPCPAddon : public DialUpAddon {
|
||||
int32 FindIPCPProtocol(const BMessage& message, BMessage *protocol) const;
|
||||
|
||||
private:
|
||||
bool fIsNew;
|
||||
bool fIsNew, fIsEnabled;
|
||||
BString fIPAddress, fPrimaryDNS, fSecondaryDNS;
|
||||
BMessage *fSettings, *fProfile;
|
||||
// saves last settings state
|
||||
IPCPWindow *fIPCPWindow;
|
||||
IPCPView *fIPCPView;
|
||||
};
|
||||
|
||||
|
||||
class IPCPWindow : public BWindow {
|
||||
class IPCPView : public BView {
|
||||
public:
|
||||
IPCPWindow(IPCPAddon *addon, BRect frame);
|
||||
IPCPView(IPCPAddon *addon, BRect frame);
|
||||
|
||||
IPCPAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
|
||||
bool IsEnabled() const
|
||||
{ return fIsEnabled->Value(); }
|
||||
const char *IPAddress() const
|
||||
{ return fIPAddress->Text(); }
|
||||
const char *PrimaryDNS() const
|
||||
@@ -78,13 +81,17 @@ class IPCPWindow : public BWindow {
|
||||
const char *SecondaryDNS() const
|
||||
{ return fSecondaryDNS->Text(); }
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
void UpdateControls();
|
||||
|
||||
private:
|
||||
IPCPAddon *fAddon;
|
||||
BCheckBox *fIsEnabled;
|
||||
BButton *fCancelButton, *fOKButton;
|
||||
BTextControl *fIPAddress, *fPrimaryDNS, *fSecondaryDNS;
|
||||
BString fPreviousIPAddress, fPreviousPrimaryDNS, fPreviousSecondaryDNS;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -18,11 +18,10 @@ SimpleTest DialUpPreflet :
|
||||
TextRequestDialog.cpp
|
||||
|
||||
# built-in add-ons
|
||||
ExtrasAddon.cpp
|
||||
ConnectionOptionsAddon.cpp
|
||||
GeneralAddon.cpp
|
||||
IPCPAddon.cpp
|
||||
PPPoEAddon.cpp
|
||||
ProtocolsAddon.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs DialUpPreflet : libppp.a be ;
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
|
||||
#include <driver_settings.h>
|
||||
#include <PPPDefs.h>
|
||||
#include <settings_tools.h>
|
||||
#include <File.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
@@ -15,6 +16,9 @@
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
static bool AddParameters(const BMessage& message, driver_settings *to);
|
||||
|
||||
|
||||
bool
|
||||
FindMessageParameter(const char *name, const BMessage& message, BMessage *save,
|
||||
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,
|
||||
¤t) == 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
|
||||
bool
|
||||
AddParameter(const driver_parameter *parameter, BMessage *message)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
struct driver_settings;
|
||||
class BMessage;
|
||||
class BFile;
|
||||
|
||||
@@ -22,7 +23,10 @@ class BFile;
|
||||
extern bool FindMessageParameter(const char *name, const BMessage& message,
|
||||
BMessage *save, int32 *startIndex = NULL);
|
||||
|
||||
extern driver_settings *MessageToDriverSettings(const BMessage& message);
|
||||
|
||||
extern bool ReadMessageDriverSettings(const char *name, BMessage *message);
|
||||
extern bool WriteMessageDriverSettings(BFile& file, const BMessage& message);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,30 +17,57 @@
|
||||
// for max()
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Messenger.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <PPPManager.h>
|
||||
#include <PPPoE.h>
|
||||
// from PPPoE addon
|
||||
|
||||
#define BUTTON_WIDTH 80
|
||||
|
||||
#define MSG_SELECT_INTERFACE 'SELI'
|
||||
#define MSG_SELECT_OTHER 'SELO'
|
||||
#define MSG_FINISH_SELECT_OTHER 'FISO'
|
||||
#define MSG_SHOW_SERVICE_WINDOW 'SHSW'
|
||||
#define MSG_CHANGE_SERVICE 'CHGS'
|
||||
#define MSG_RESET_SERVICE 'RESS'
|
||||
// GUI constants
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
static const char kFriendlyName[] = "DSL, Cable, etc.";
|
||||
static const char kTechnicalName[] = "PPPoE";
|
||||
static const char kKernelModuleName[] = "pppoe";
|
||||
// message constants
|
||||
static const uint32 kMsgSelectInterface = 'SELI';
|
||||
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)
|
||||
@@ -50,8 +77,8 @@ PPPoEAddon::PPPoEAddon(BMessage *addons)
|
||||
fPPPoEView(NULL)
|
||||
{
|
||||
fHeight = 20 // interface name control
|
||||
+ 25 // service button
|
||||
+ 5; // space between controls
|
||||
+ 20 // service control
|
||||
+ 5 + 2; // space between controls and bottom
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +114,7 @@ bool
|
||||
PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fInterfaceName = fACName = fServiceName = "";
|
||||
fInterfaceName = fServiceName = "";
|
||||
fSettings = settings;
|
||||
fProfile = profile;
|
||||
if(!settings || !profile || isNew) {
|
||||
@@ -118,15 +145,6 @@ PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew)
|
||||
device.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if(!FindMessageParameter(PPPoE_AC_NAME_KEY, device, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fACName) != B_OK)
|
||||
fACName = "";
|
||||
else {
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
device.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if(!FindMessageParameter(PPPoE_SERVICE_NAME_KEY, device, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fServiceName) != B_OK)
|
||||
@@ -154,7 +172,6 @@ PPPoEAddon::IsModified(bool *settings, bool *profile) const
|
||||
}
|
||||
|
||||
*settings = (fInterfaceName != fPPPoEView->InterfaceName()
|
||||
|| fACName != fPPPoEView->ACName()
|
||||
|| fServiceName != fPPPoEView->ServiceName());
|
||||
}
|
||||
|
||||
@@ -175,14 +192,6 @@ PPPoEAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempora
|
||||
interface.AddString(MDSU_VALUES, fPPPoEView->InterfaceName());
|
||||
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) {
|
||||
// save service name, too
|
||||
BMessage service;
|
||||
@@ -225,10 +234,10 @@ PPPoEAddon::CreateView(BPoint leftTop)
|
||||
|
||||
BRect rect(0, 0, width, fHeight);
|
||||
fPPPoEView = new PPPoEView(this, rect);
|
||||
fPPPoEView->Reload();
|
||||
}
|
||||
|
||||
fPPPoEView->MoveTo(leftTop);
|
||||
fPPPoEView->Reload();
|
||||
return fPPPoEView;
|
||||
}
|
||||
|
||||
@@ -240,75 +249,25 @@ PPPoEView::PPPoEView(PPPoEAddon *addon, BRect frame)
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(5, 0);
|
||||
rect.bottom = 20;
|
||||
fInterface = new BMenuField(rect, "interface", "Interface: ",
|
||||
new BPopUpMenu("Select Interface..."));
|
||||
fInterface = new BMenuField(rect, "interface", kLabelInterfaceName,
|
||||
new BPopUpMenu(kLabelSelectInterface));
|
||||
fInterface->SetDivider(StringWidth(fInterface->Label()) + 5);
|
||||
fInterface->Menu()->AddSeparatorItem();
|
||||
fOtherInterface = new BMenuItem("Other:", new BMessage(MSG_SELECT_OTHER));
|
||||
fOtherInterface = new BMenuItem(kLabelOtherInterface,
|
||||
new BMessage(kMsgSelectOther));
|
||||
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.bottom = rect.top + 20;
|
||||
fServiceName = new BTextControl(rect, "service", "Service: ", NULL, NULL);
|
||||
|
||||
// set divider of text controls
|
||||
float acNameWidth = StringWidth(fACName->Label()) + 5;
|
||||
float serviceNameWidth = StringWidth(fServiceName->Label()) + 5;
|
||||
float width = max(acNameWidth, serviceNameWidth);
|
||||
fACName->SetDivider(width);
|
||||
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
|
||||
rect.right -= 75;
|
||||
fServiceName = new BTextControl(rect, "service", kLabelServiceName, NULL, NULL);
|
||||
fServiceName->SetDivider(StringWidth(fServiceName->Label()) + 5);
|
||||
rect.left = rect.right + 5;
|
||||
rect.right += 75;
|
||||
rect.bottom = rect.top + 15;
|
||||
AddChild(new BStringView(rect, "optional", kLabelOptional));
|
||||
|
||||
AddChild(fInterface);
|
||||
AddChild(fServiceButton);
|
||||
AddChild(fServiceName);
|
||||
}
|
||||
|
||||
|
||||
@@ -321,17 +280,8 @@ PPPoEView::~PPPoEView()
|
||||
void
|
||||
PPPoEView::Reload()
|
||||
{
|
||||
// update interface settings
|
||||
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());
|
||||
fPreviousServiceName = Addon()->ServiceName();
|
||||
fServiceWindow->Unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -340,11 +290,7 @@ PPPoEView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fInterface->Menu()->SetTargetForItems(this);
|
||||
fServiceButton->SetTarget(this);
|
||||
fACName->SetTarget(this);
|
||||
fServiceName->SetTarget(this);
|
||||
fCancelButton->SetTarget(this);
|
||||
fOKButton->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -352,19 +298,19 @@ void
|
||||
PPPoEView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case MSG_SELECT_INTERFACE: {
|
||||
case kMsgSelectInterface: {
|
||||
BMenuItem *item = fInterface->Menu()->FindMarked();
|
||||
if(item)
|
||||
fInterfaceName = item->Label();
|
||||
} break;
|
||||
|
||||
case MSG_SELECT_OTHER:
|
||||
(new TextRequestDialog("InterfaceName", "Interface Name: ",
|
||||
case kMsgSelectOther:
|
||||
(new TextRequestDialog("InterfaceName", kRequestInterfaceName,
|
||||
fInterfaceName.String()))->Go(new BInvoker(
|
||||
new BMessage(MSG_FINISH_SELECT_OTHER), this));
|
||||
new BMessage(kMsgFinishSelectOther), this));
|
||||
break;
|
||||
|
||||
case MSG_FINISH_SELECT_OTHER: {
|
||||
case kMsgFinishSelectOther: {
|
||||
int32 which;
|
||||
message->FindInt32("which", &which);
|
||||
|
||||
@@ -389,35 +335,13 @@ PPPoEView::MessageReceived(BMessage *message)
|
||||
return;
|
||||
}
|
||||
|
||||
BString label("Other: ");
|
||||
label << name;
|
||||
BString label(kLabelOtherInterface);
|
||||
label << " " << name;
|
||||
fOtherInterface->SetLabel(label.String());
|
||||
fOtherInterface->SetMarked(true);
|
||||
// XXX: this is needed to tell the owning menu to update its label
|
||||
} 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:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
@@ -431,7 +355,7 @@ PPPoEView::ReloadInterfaces()
|
||||
BMenu *menu = fInterface->Menu();
|
||||
while(menu->CountItems() > 2)
|
||||
delete menu->RemoveItem((int32) 0);
|
||||
fOtherInterface->SetLabel("Other:");
|
||||
fOtherInterface->SetLabel(kLabelOtherInterface);
|
||||
|
||||
PPPManager manager;
|
||||
char *interfaces = new char[8192];
|
||||
@@ -443,7 +367,7 @@ PPPoEView::ReloadInterfaces()
|
||||
char *name = interfaces;
|
||||
int32 insertAt;
|
||||
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);
|
||||
if(insertAt > menu->CountItems() - 2)
|
||||
insertAt = menu->CountItems() - 2;
|
||||
@@ -467,8 +391,8 @@ PPPoEView::ReloadInterfaces()
|
||||
if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
|
||||
item->SetMarked(true);
|
||||
else if(Addon()->InterfaceName()) {
|
||||
BString label("Other: ");
|
||||
label << fInterfaceName;
|
||||
BString label(kLabelOtherInterface);
|
||||
label << " " << fInterfaceName;
|
||||
fOtherInterface->SetLabel(label.String());
|
||||
fOtherInterface->SetMarked(true);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ class PPPoEAddon : public DialUpAddon {
|
||||
|
||||
const char *InterfaceName() const
|
||||
{ return fInterfaceName.String(); }
|
||||
const char *ACName() const
|
||||
{ return fACName.String(); }
|
||||
const char *ServiceName() const
|
||||
{ return fServiceName.String(); }
|
||||
|
||||
@@ -57,7 +55,7 @@ class PPPoEAddon : public DialUpAddon {
|
||||
|
||||
private:
|
||||
bool fIsNew;
|
||||
BString fInterfaceName, fACName, fServiceName;
|
||||
BString fInterfaceName, fServiceName;
|
||||
BMessage *fSettings, *fProfile;
|
||||
// saves last settings state
|
||||
PPPoEView *fPPPoEView;
|
||||
@@ -77,8 +75,6 @@ class PPPoEView : public BView {
|
||||
|
||||
const char *InterfaceName() const
|
||||
{ return fInterfaceName.String(); }
|
||||
const char *ACName() const
|
||||
{ return fACName->Text(); }
|
||||
const char *ServiceName() const
|
||||
{ return fServiceName->Text(); }
|
||||
|
||||
@@ -90,14 +86,10 @@ class PPPoEView : public BView {
|
||||
|
||||
private:
|
||||
PPPoEAddon *fAddon;
|
||||
BButton *fServiceButton, *fCancelButton, *fOKButton;
|
||||
BMenuField *fInterface;
|
||||
BMenuItem *fOtherInterface;
|
||||
BString fInterfaceName;
|
||||
BTextControl *fACName, *fServiceName;
|
||||
BWindow *fServiceWindow;
|
||||
BString fPreviousACName, fPreviousServiceName;
|
||||
// for the case that the user presses "Cancel" in the service window
|
||||
BTextControl *fServiceName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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, ¶meter,
|
||||
&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>
|
||||
|
||||
|
||||
#define WINDOW_WIDTH 250
|
||||
#define WINDOW_HEIGHT 5 + 20 + 10 + 25 + 5
|
||||
#define WINDOW_RECT BRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
#define BUTTON_WIDTH 80
|
||||
// GUI constants
|
||||
static const uint32 kWindowWidth = 250;
|
||||
static const uint32 kWindowHeight = 5 + 20 + 10 + 25 + 5;
|
||||
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,
|
||||
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)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
@@ -37,14 +43,14 @@ TextRequestDialog::TextRequestDialog(const char *title, const char *request,
|
||||
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = rect.top + 25;
|
||||
rect.left = rect.right - BUTTON_WIDTH;
|
||||
rect.left = rect.right - kDefaultButtonWidth;
|
||||
BMessage message(kMsgButton);
|
||||
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.left = rect.right - BUTTON_WIDTH;
|
||||
rect.left = rect.right - kDefaultButtonWidth;
|
||||
message.ReplaceInt32("which", 0);
|
||||
BButton *cancelButton = new BButton(rect, "cancelButton", "Cancel",
|
||||
BButton *cancelButton = new BButton(rect, "cancelButton", kLabelCancel,
|
||||
new BMessage(message));
|
||||
backgroundView->AddChild(okButton);
|
||||
backgroundView->AddChild(cancelButton);
|
||||
|
||||
Reference in New Issue
Block a user