tests/kits/net: Remove old version of the DialUpPreflet.
Hopefully there aren't any more copies of this hiding in the tree....
This commit is contained in:
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// ConnectionOptionsAddon saves the loaded settings.
|
||||
// ConnectionOptionsView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ConnectionOptionsAddon.h"
|
||||
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
|
||||
#include <PPPDefs.h>
|
||||
#include <settings_tools.h>
|
||||
|
||||
|
||||
// message constants
|
||||
static const uint32 kMsgUpdateControls = 'UCTL';
|
||||
|
||||
// labels
|
||||
static const char *kLabelConnectionOptions = "Options";
|
||||
static const char *kLabelAskBeforeConnecting = "Ask Before Connecting";
|
||||
static const char *kLabelAutoReconnect = "Reconnect Automatically";
|
||||
|
||||
|
||||
ConnectionOptionsAddon::ConnectionOptionsAddon(BMessage *addons)
|
||||
: DialUpAddon(addons),
|
||||
fSettings(NULL),
|
||||
fConnectionOptionsView(NULL)
|
||||
{
|
||||
CreateView(BPoint(0,0));
|
||||
fDeleteView = true;
|
||||
}
|
||||
|
||||
|
||||
ConnectionOptionsAddon::~ConnectionOptionsAddon()
|
||||
{
|
||||
if(fDeleteView)
|
||||
delete fConnectionOptionsView;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ConnectionOptionsAddon::LoadSettings(BMessage *settings, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fAskBeforeConnecting = fDoesAutoReconnect = false;
|
||||
fSettings = settings;
|
||||
|
||||
fConnectionOptionsView->Reload();
|
||||
// reset all views (empty settings)
|
||||
|
||||
if(!settings || isNew)
|
||||
return true;
|
||||
|
||||
BMessage parameter;
|
||||
int32 index = 0;
|
||||
const char *value;
|
||||
if(FindMessageParameter(PPP_ASK_BEFORE_CONNECTING_KEY, *fSettings, ¶meter,
|
||||
&index) && parameter.FindString(MDSU_VALUES, &value) == B_OK) {
|
||||
if(get_boolean_value(value, false))
|
||||
fAskBeforeConnecting = true;
|
||||
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if(FindMessageParameter(PPP_AUTO_RECONNECT_KEY, *fSettings, ¶meter, &index)
|
||||
&& parameter.FindString(MDSU_VALUES, &value) == B_OK) {
|
||||
if(get_boolean_value(value, false))
|
||||
fDoesAutoReconnect = true;
|
||||
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
fConnectionOptionsView->Reload();
|
||||
// reload new settings
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionOptionsAddon::IsModified(bool *settings) const
|
||||
{
|
||||
*settings = false;
|
||||
|
||||
if(!fSettings || !fConnectionOptionsView)
|
||||
return;
|
||||
|
||||
*settings = AskBeforeConnecting() != fConnectionOptionsView->AskBeforeConnecting()
|
||||
|| DoesAutoReconnect() != fConnectionOptionsView->DoesAutoReconnect();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ConnectionOptionsAddon::SaveSettings(BMessage *settings)
|
||||
{
|
||||
if(!fSettings || !settings)
|
||||
return false;
|
||||
|
||||
BMessage parameter;
|
||||
if(fConnectionOptionsView->DoesAutoReconnect()) {
|
||||
parameter.MakeEmpty();
|
||||
parameter.AddString(MDSU_NAME, PPP_AUTO_RECONNECT_KEY);
|
||||
parameter.AddString(MDSU_VALUES, "enabled");
|
||||
settings->AddMessage(MDSU_PARAMETERS, ¶meter);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ConnectionOptionsAddon::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*
|
||||
ConnectionOptionsAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
if(!fConnectionOptionsView) {
|
||||
BRect rect;
|
||||
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
|
||||
fConnectionOptionsView = new ConnectionOptionsView(this, rect);
|
||||
}
|
||||
|
||||
fDeleteView = false;
|
||||
|
||||
fConnectionOptionsView->MoveTo(leftTop);
|
||||
fConnectionOptionsView->Reload();
|
||||
return fConnectionOptionsView;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
fAskBeforeConnecting = new BCheckBox(rect, "AskBeforeConnecting",
|
||||
kLabelAskBeforeConnecting, NULL);
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 15;
|
||||
fAutoReconnect = new BCheckBox(rect, "AutoReconnect", kLabelAutoReconnect, NULL);
|
||||
|
||||
AddChild(fAskBeforeConnecting);
|
||||
AddChild(fAutoReconnect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionOptionsView::Reload()
|
||||
{
|
||||
fAskBeforeConnecting->SetValue(Addon()->AskBeforeConnecting());
|
||||
fAutoReconnect->SetValue(Addon()->DoesAutoReconnect());
|
||||
|
||||
if(!Addon()->Settings())
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConnectionOptionsView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// ConnectionOptionsAddon saves the loaded settings.
|
||||
// ConnectionOptionsView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#ifndef _CONNECTION_OPTIONS_ADDON__H
|
||||
#define _CONNECTION_OPTIONS_ADDON__H
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <RadioButton.h>
|
||||
|
||||
class ConnectionOptionsView;
|
||||
|
||||
|
||||
class ConnectionOptionsAddon : public DialUpAddon {
|
||||
public:
|
||||
ConnectionOptionsAddon(BMessage *addons);
|
||||
virtual ~ConnectionOptionsAddon();
|
||||
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
|
||||
bool AskBeforeConnecting() const
|
||||
{ return fAskBeforeConnecting; }
|
||||
bool DoesAutoReconnect() const
|
||||
{ return fDoesAutoReconnect; }
|
||||
|
||||
BMessage *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
virtual int32 Position() const
|
||||
{ return 50; }
|
||||
virtual bool LoadSettings(BMessage *settings, bool isNew);
|
||||
virtual void IsModified(bool *settings) const;
|
||||
virtual bool SaveSettings(BMessage *settings);
|
||||
virtual bool GetPreferredSize(float *width, float *height) const;
|
||||
virtual BView *CreateView(BPoint leftTop);
|
||||
|
||||
private:
|
||||
bool fIsNew, fDeleteView;
|
||||
bool fAskBeforeConnecting, fDoesAutoReconnect;
|
||||
BMessage *fSettings;
|
||||
// saves last settings state
|
||||
ConnectionOptionsView *fConnectionOptionsView;
|
||||
};
|
||||
|
||||
|
||||
class ConnectionOptionsView : public BView {
|
||||
public:
|
||||
ConnectionOptionsView(ConnectionOptionsAddon *addon, BRect frame);
|
||||
|
||||
ConnectionOptionsAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
|
||||
bool AskBeforeConnecting() const
|
||||
{ return fAskBeforeConnecting->Value(); }
|
||||
bool DoesAutoReconnect() const
|
||||
{ return fAutoReconnect->Value(); }
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
private:
|
||||
ConnectionOptionsAddon *fAddon;
|
||||
BCheckBox *fAskBeforeConnecting, *fAutoReconnect;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,34 +0,0 @@
|
||||
--------------------------------------------------------------------------------------
|
||||
Notes for add-on developers:
|
||||
--------------------------------------------------------------------------------------
|
||||
All add-ons must add a "Valid" boolean value to every recognized parameter. The preflet will check if all values were recognized and if not it will ask the user if he wants to edit the interface anyway...
|
||||
|
||||
--------------------------------------------------------------------------------------
|
||||
Add-on registration:
|
||||
--------------------------------------------------------------------------------------
|
||||
Tabs and Protocols (protocols are tabs):
|
||||
DUN_TAB_ADDON_TYPE : pointer to DialUpAddon object
|
||||
|
||||
Authenticators:
|
||||
DUN_AUTHENTICATOR_ADDON_TYPE : BMessage with the following entries:
|
||||
{
|
||||
"KernelModule" : string
|
||||
"TechnicalName" : string
|
||||
"FriendlyName" : string
|
||||
"Position" : int32
|
||||
}
|
||||
|
||||
Devices:
|
||||
DUN_DEVICE_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)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------------
|
||||
Additional data in the BMessage object for add-ons:
|
||||
--------------------------------------------------------------------------------------
|
||||
DUN_MESSENGER : BMessenger - This messenger can be used to send messages to the preflet
|
||||
DUN_TAB_VIEW_RECT : BRect - This rect should be used for tabs
|
||||
DUN_DEVICE_VIEW_WIDTH : float - Maximum width a device add-on's view may have
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
/*! \class DialUpAddon
|
||||
\brief Base class for DialUpPreflet add-ons.
|
||||
|
||||
DialUp add-ons must export the following function: \n
|
||||
bool register(BMessage *addons) \n
|
||||
You should add your DialUpAddon object to the given BMessage. \n
|
||||
\n
|
||||
Most add-ons are simple pointers to a DialUpAddon object. \n
|
||||
\n
|
||||
Note for tab-addons: The BView object is deleted AFTER the DialUpAddon (except you
|
||||
remove and delete it in the DialUpAddon destructor).
|
||||
*/
|
||||
|
||||
#ifndef _DIAL_UP_ADDON__H
|
||||
#define _DIAL_UP_ADDON__H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <Point.h>
|
||||
|
||||
|
||||
#define DUN_MAXIMUM_PRIORITY 50
|
||||
|
||||
// add-on types
|
||||
#define DUN_TAB_ADDON_TYPE "Tab"
|
||||
#define DUN_AUTHENTICATOR_ADDON_TYPE "Authenticator"
|
||||
#define DUN_DEVICE_ADDON_TYPE "Device"
|
||||
#define DUN_PROTOCOL_ADDON_TYPE "Protocol"
|
||||
|
||||
// other information contained in the add-ons BMessage object
|
||||
#define DUN_DELETE_ON_QUIT "DeleteMe"
|
||||
// the DialUpAddon objects in this list will be deleted when the preflet quits
|
||||
#define DUN_MESSENGER "Messenger"
|
||||
#define DUN_TAB_VIEW_RECT "TabViewRect"
|
||||
#define DUN_DEVICE_VIEW_WIDTH "DeviceViewWidth"
|
||||
|
||||
|
||||
class DialUpAddon {
|
||||
friend class DialUpView;
|
||||
|
||||
public:
|
||||
//! Constructor. The BMessage is the one passed to the \c register() function.
|
||||
DialUpAddon(BMessage *addons) : fAddons(addons) {}
|
||||
//! Destructor. Does nothing.
|
||||
virtual ~DialUpAddon() {}
|
||||
|
||||
//! Returns the BMessage object holding all add-ons.
|
||||
BMessage *Addons() const
|
||||
{ return fAddons; }
|
||||
|
||||
//! Returns a name readable by humans without much technical knowledge.
|
||||
virtual const char *FriendlyName() const
|
||||
{ return NULL; }
|
||||
//! Returns the technical name of this module.
|
||||
virtual const char *TechnicalName() const
|
||||
{ return NULL; }
|
||||
//! Returns the name of the associated kernel module or \c NULL.
|
||||
virtual const char *KernelModuleName() const
|
||||
{ return NULL; }
|
||||
//! Mostly used by tabs to describe where they should appear.
|
||||
virtual int32 Position() const
|
||||
{ return -1; }
|
||||
//! Allows setting an order in which modules are asked to add the settings.
|
||||
virtual int32 Priority() const
|
||||
{ return 0; }
|
||||
|
||||
/*! \brief Load the given settings.
|
||||
|
||||
\param isNew Specifies if this is a newly created interface.
|
||||
|
||||
\return \c true if loading was successful or \c false otherwise.
|
||||
*/
|
||||
virtual bool LoadSettings(BMessage *settings, bool isNew)
|
||||
{ return false; }
|
||||
//! Are the settings modified?
|
||||
virtual void IsModified(bool *settings) const
|
||||
{ *settings = false; }
|
||||
/*! \brief Save the given settings.
|
||||
|
||||
\return \c true if saving was successful or \c false otherwise.
|
||||
*/
|
||||
virtual bool SaveSettings(BMessage *settings)
|
||||
{ return false; }
|
||||
/*! \brief Get the preferred view size.
|
||||
|
||||
\return \c false if this module does not export a BView object.
|
||||
*/
|
||||
virtual bool GetPreferredSize(float *width, float *height) const
|
||||
{ return false; }
|
||||
/*! \brief Returns the module's BView object.
|
||||
|
||||
\param leftTop Specifies the view's left-top coordinates.
|
||||
*/
|
||||
virtual BView *CreateView(BPoint leftTop)
|
||||
{ return NULL; }
|
||||
|
||||
private:
|
||||
virtual void _Reserved1() {}
|
||||
virtual void _Reserved2() {}
|
||||
virtual void _Reserved3() {}
|
||||
virtual void _Reserved4() {}
|
||||
|
||||
private:
|
||||
BMessage *fAddons;
|
||||
|
||||
int32 _reserved[7];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2004, Waldemar Kornewald <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
#include "DialUpView.h"
|
||||
|
||||
|
||||
static const char *kSignature = "application/x-vnd.haiku.connect-up-preflet";
|
||||
|
||||
|
||||
class DialUpApplication : public BApplication {
|
||||
public:
|
||||
DialUpApplication();
|
||||
};
|
||||
|
||||
|
||||
class DialUpWindow : public BWindow {
|
||||
public:
|
||||
DialUpWindow(BRect frame);
|
||||
|
||||
virtual bool QuitRequested()
|
||||
{ be_app->PostMessage(B_QUIT_REQUESTED); return true; }
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
new DialUpApplication();
|
||||
|
||||
be_app->Run();
|
||||
|
||||
delete be_app;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
DialUpApplication::DialUpApplication()
|
||||
: BApplication(kSignature)
|
||||
{
|
||||
BRect rect(150, 50, 450, 435);
|
||||
DialUpWindow *window = new DialUpWindow(rect);
|
||||
window->MoveTo(center_on_screen(rect, window));
|
||||
window->Show();
|
||||
}
|
||||
|
||||
|
||||
DialUpWindow::DialUpWindow(BRect frame)
|
||||
: BWindow(frame, "DialUp", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
DialUpView *view = new DialUpView(Bounds());
|
||||
|
||||
AddChild(view);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
DialUpPreflet.rdef
|
||||
*/
|
||||
|
||||
resource app_signature "application/x-vnd.haiku.connect-up-preflet";
|
||||
|
||||
/* BEOS:APP_FLAGS :
|
||||
00000000 = SINGLE LAUNCH
|
||||
00000001 = MULTIPLE LAUNCH
|
||||
00000002 = EXCLUSIVE LAUNCH
|
||||
00000004 = BACKGROUND APP + SINGLE LAUNCH
|
||||
00000005 = BACKGROUND APP + MULTIPLE LAUNCH
|
||||
00000006 = BACKGROUND APP + EXCLUSIVE LAUNCH
|
||||
00000008 = ARGV_ONLY + SINGLE LAUNCH
|
||||
00000009 = ARGV_ONLY + MULTIPLE LAUNCH
|
||||
0000000A = ARGV_ONLY + EXCLUSIVE LAUNCH
|
||||
0000000C = ARGV_ONLY + BACKGROUND APP + SINGLE LAUNCH
|
||||
0000000D = ARGV_ONLY + BACKGROUND APP + MULTIPLE LAUNCH
|
||||
0000000E = ARGV_ONLY + BACKGROUND APP + EXCLUSIVE LAUNCH
|
||||
*/
|
||||
|
||||
resource app_flags 0x00000000;
|
||||
|
||||
resource app_version {
|
||||
major = 0,
|
||||
middle = 1,
|
||||
minor = 0,
|
||||
|
||||
/* 0 = development 1 = alpha 2 = beta
|
||||
3 = gamma 4 = golden master 5 = final */
|
||||
variety = 0,
|
||||
|
||||
internal = 0,
|
||||
|
||||
short_info = "DialUpPreflet",
|
||||
long_info = "PPP interface configuration tool."
|
||||
};
|
||||
@@ -1,633 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "DialUpView.h"
|
||||
#include "DialUpAddon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
#include "TextRequestDialog.h"
|
||||
|
||||
#include <PPPInterface.h>
|
||||
#include <settings_tools.h>
|
||||
#include <TemplateList.h>
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Messenger.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <StringView.h>
|
||||
#include <TabView.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
// GUI constants
|
||||
static const uint32 kInterfaceFieldWidth = 175;
|
||||
|
||||
// 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';
|
||||
static const uint32 kMsgUpdateDefaultInterface = 'UPDT';
|
||||
|
||||
// labels
|
||||
static const char *kLabelInterface = "Interface: ";
|
||||
static const char *kLabelInterfaceName = "Interface Name: ";
|
||||
static const char *kLabelCreateNewInterface = "Create New Interface";
|
||||
static const char *kLabelCreateNew = "Create New...";
|
||||
static const char *kLabelDefaultInterface = "Default";
|
||||
static const char *kLabelDeleteCurrent = "Delete Current";
|
||||
static const char *kLabelConnect = "Connect";
|
||||
static const char *kLabelDisconnect = "Disconnect";
|
||||
static const char *kLabelOK = "OK";
|
||||
|
||||
// connection status strings
|
||||
static const char *kTextConnecting = "Connecting...";
|
||||
static const char *kTextConnectionEstablished = "Connection established.";
|
||||
static const char *kTextNotConnected = "Not connected.";
|
||||
static const char *kTextDeviceUpFailed = "Failed to connect.";
|
||||
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 = "Please create a new interface...";
|
||||
static const char *kTextChooseInterfaceName = "Please choose a new name for this "
|
||||
"interface.";
|
||||
|
||||
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!";
|
||||
|
||||
|
||||
DialUpView::DialUpView(BRect frame)
|
||||
: BView(frame, "DialUpView", B_FOLLOW_NONE, 0),
|
||||
fListener(this),
|
||||
fCurrentItem(NULL),
|
||||
fKeepLabel(false)
|
||||
{
|
||||
BRect bounds = Bounds();
|
||||
// for caching
|
||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
|
||||
// add messenger to us so add-ons can contact us
|
||||
BMessenger messenger(this);
|
||||
fSettings.Addons().AddMessenger(DUN_MESSENGER, messenger);
|
||||
|
||||
// create pop-up with all interfaces and "New..."/"Delete current" items
|
||||
fInterfaceMenu = new BPopUpMenu(kLabelCreateNew);
|
||||
BRect rect = bounds;
|
||||
rect.InsetBy(5, 5);
|
||||
rect.right = kInterfaceFieldWidth;
|
||||
rect.bottom = rect.top + 20;
|
||||
fMenuField = new BMenuField(rect, "Interfaces", kLabelInterface, fInterfaceMenu);
|
||||
fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 5);
|
||||
rect.top += 3;
|
||||
rect.bottom -= 2;
|
||||
rect.left = rect.right + 5;
|
||||
rect.right = bounds.right - 5;
|
||||
fDefaultInterface = new BCheckBox(rect, "Default", kLabelDefaultInterface,
|
||||
new BMessage(kMsgUpdateDefaultInterface));
|
||||
rect.left = bounds.left + 5;
|
||||
rect.top = rect.bottom + 12;
|
||||
rect.bottom = bounds.bottom
|
||||
- 20 // height of bottom controls
|
||||
- 20; // space for bottom controls
|
||||
fTabView = new BTabView(rect, "TabView", B_WIDTH_FROM_LABEL);
|
||||
BRect tabViewRect(fTabView->Bounds());
|
||||
tabViewRect.bottom -= fTabView->TabHeight();
|
||||
fSettings.Addons().AddRect(DUN_TAB_VIEW_RECT, tabViewRect);
|
||||
|
||||
BRect tmpRect(rect);
|
||||
tmpRect.top += (tmpRect.Height() - 15) / 2;
|
||||
tmpRect.bottom = tmpRect.top + 15;
|
||||
fStringView = new BStringView(tmpRect, "NoInterfacesFound",
|
||||
kTextNoInterfacesFound);
|
||||
fStringView->SetAlignment(B_ALIGN_CENTER);
|
||||
fStringView->Hide();
|
||||
tmpRect.top = tmpRect.bottom + 10;
|
||||
tmpRect.bottom = tmpRect.top + 25;
|
||||
fCreateNewButton = new BButton(tmpRect, "CreateNewButton",
|
||||
kLabelCreateNewInterface, new BMessage(kMsgCreateNew));
|
||||
fCreateNewButton->ResizeToPreferred();
|
||||
tmpRect.left = (rect.Width() - fCreateNewButton->Bounds().Width()) / 2 + rect.left;
|
||||
fCreateNewButton->MoveTo(tmpRect.left, tmpRect.top);
|
||||
fCreateNewButton->Hide();
|
||||
|
||||
rect.top = rect.bottom + 15;
|
||||
rect.bottom = rect.top + 15;
|
||||
rect.right = rect.left + 200;
|
||||
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", kLabelConnect,
|
||||
new BMessage(kMsgConnectButton));
|
||||
|
||||
AddChild(fMenuField);
|
||||
AddChild(fDefaultInterface);
|
||||
AddChild(fTabView);
|
||||
AddChild(fStringView);
|
||||
AddChild(fCreateNewButton);
|
||||
AddChild(fStatusView);
|
||||
AddChild(fConnectButton);
|
||||
|
||||
// initialize
|
||||
fListener.WatchManager();
|
||||
LoadInterfaces();
|
||||
fSettings.LoadAddons();
|
||||
CreateTabs();
|
||||
fCurrentItem = NULL;
|
||||
// reset, otherwise SelectInterface will not load the settings
|
||||
SelectInterface(0);
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
|
||||
DialUpView::~DialUpView()
|
||||
{
|
||||
fListener.StopWatchingInterface();
|
||||
fListener.StopWatchingManager();
|
||||
fSettings.SaveSettingsToFile();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::AttachedToWindow()
|
||||
{
|
||||
fInterfaceMenu->SetTargetForItems(this);
|
||||
fCreateNewButton->SetTarget(this);
|
||||
fConnectButton->SetTarget(this);
|
||||
fDefaultInterface->SetTarget(this);
|
||||
fDefaultInterface->Hide();
|
||||
// TODO: remove this when we have full COD support
|
||||
|
||||
if(fListener.InitCheck() != B_OK) {
|
||||
(new BAlert(kErrorTitle, kErrorNoPPPStack, kLabelOK,
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
|
||||
fConnectButton->Hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case PPP_REPORT_MESSAGE:
|
||||
HandleReportMessage(message);
|
||||
break;
|
||||
|
||||
// -------------------------------------------------
|
||||
case kMsgCreateNew: {
|
||||
UpdateControls();
|
||||
(new TextRequestDialog(kLabelCreateNewInterface, kTextChooseInterfaceName,
|
||||
kLabelInterfaceName))->Go(
|
||||
new BInvoker(new BMessage(kMsgFinishCreateNew), this));
|
||||
} break;
|
||||
|
||||
case kMsgFinishCreateNew: {
|
||||
int32 which;
|
||||
message->FindInt32("which", &which);
|
||||
const char *name = message->FindString("text");
|
||||
if(which == 1 && name && strlen(name) > 0)
|
||||
AddInterface(name, true);
|
||||
|
||||
if(fCurrentItem)
|
||||
fCurrentItem->SetMarked(true);
|
||||
|
||||
UpdateControls();
|
||||
|
||||
// a newly created interface is set to default if there is no default one
|
||||
if(PPPManager::DefaultInterface() == "") {
|
||||
fDefaultInterface->SetValue(true);
|
||||
PPPManager::SetDefaultInterface(name);
|
||||
}
|
||||
} break;
|
||||
// -------------------------------------------------
|
||||
|
||||
case kMsgDeleteCurrent: {
|
||||
if(!fCurrentItem)
|
||||
return;
|
||||
|
||||
const char *name = fCurrentItem->Message()->FindString("name");
|
||||
if(PPPManager::DefaultInterface() == name)
|
||||
PPPManager::SetDefaultInterface("");
|
||||
fInterfaceMenu->RemoveItem(fCurrentItem);
|
||||
BDirectory settings;
|
||||
PPPManager::GetSettingsDirectory(&settings);
|
||||
BEntry entry;
|
||||
settings.FindEntry(name, &entry);
|
||||
entry.Remove();
|
||||
delete fCurrentItem;
|
||||
fCurrentItem = NULL;
|
||||
|
||||
BMenuItem *marked = fInterfaceMenu->FindMarked();
|
||||
if(marked)
|
||||
marked->SetMarked(false);
|
||||
|
||||
UpdateControls();
|
||||
SelectInterface(0);
|
||||
// this stops watching the deleted interface
|
||||
} break;
|
||||
|
||||
case kMsgSelectInterface: {
|
||||
int32 index;
|
||||
message->FindInt32("index", &index);
|
||||
SelectInterface(index);
|
||||
} break;
|
||||
|
||||
case kMsgConnectButton: {
|
||||
if(!fCurrentItem)
|
||||
return;
|
||||
|
||||
BringUpOrDown();
|
||||
} break;
|
||||
|
||||
case kMsgUpdateDefaultInterface:
|
||||
UpdateDefaultInterface();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::BringUpOrDown()
|
||||
{
|
||||
fSettings.SaveSettingsToFile();
|
||||
BMessage settings;
|
||||
fSettings.SaveSettings(&settings);
|
||||
|
||||
PPPInterface interface;
|
||||
ppp_interface_info_t info;
|
||||
|
||||
// if going up: delete interface in order for the settings changes to take effect
|
||||
interface = fListener.Manager().InterfaceWithName(
|
||||
fCurrentItem->Message()->FindString("name"));
|
||||
interface.GetInterfaceInfo(&info);
|
||||
if(interface.InitCheck() == B_OK && info.info.state == PPP_INITIAL_STATE
|
||||
&& info.info.phase == PPP_DOWN_PHASE)
|
||||
fListener.Manager().DeleteInterface(interface.ID());
|
||||
|
||||
interface = fListener.Manager().CreateInterfaceWithName(
|
||||
fCurrentItem->Message()->FindString("name"));
|
||||
|
||||
if(interface.InitCheck() != B_OK) {
|
||||
Window()->Lock();
|
||||
fStatusView->SetText(kTextCreationError);
|
||||
Window()->Unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
interface.GetInterfaceInfo(&info);
|
||||
if(info.info.state == PPP_INITIAL_STATE && info.info.phase == PPP_DOWN_PHASE) {
|
||||
interface.SetPassword(fSettings.SessionPassword());
|
||||
interface.SetAskBeforeConnecting(false);
|
||||
interface.Up();
|
||||
} else
|
||||
interface.Down();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::HandleReportMessage(BMessage *message)
|
||||
{
|
||||
if(!fCurrentItem)
|
||||
return;
|
||||
|
||||
ppp_interface_id id;
|
||||
if(message->FindInt32("interface", reinterpret_cast<int32*>(&id)) != B_OK
|
||||
|| (fListener.Interface() != PPP_UNDEFINED_INTERFACE_ID
|
||||
&& id != fListener.Interface()))
|
||||
return;
|
||||
|
||||
int32 type, code;
|
||||
message->FindInt32("type", &type);
|
||||
message->FindInt32("code", &code);
|
||||
|
||||
if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) {
|
||||
PPPInterface interface(id);
|
||||
if(interface.InitCheck() != B_OK
|
||||
|| strcasecmp(interface.Name(),
|
||||
fCurrentItem->Message()->FindString("name")))
|
||||
return;
|
||||
|
||||
WatchInterface(id);
|
||||
} else if(type == PPP_CONNECTION_REPORT)
|
||||
UpdateStatus(code);
|
||||
else if(type == PPP_DESTRUCTION_REPORT)
|
||||
WatchInterface(fListener.Manager().InterfaceWithName(
|
||||
fCurrentItem->Message()->FindString("name")));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::CreateTabs()
|
||||
{
|
||||
// create tabs for all registered and valid tab add-ons
|
||||
DialUpAddon *addon;
|
||||
BView *target;
|
||||
float width, height;
|
||||
TemplateList<DialUpAddon*> addons;
|
||||
|
||||
for(int32 index = 0;
|
||||
fSettings.Addons().FindPointer(DUN_TAB_ADDON_TYPE, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
||||
index++) {
|
||||
if(!addon || addon->Position() < 0)
|
||||
continue;
|
||||
|
||||
int32 insertIndex = 0;
|
||||
for(; insertIndex < addons.CountItems(); insertIndex++)
|
||||
if(addons.ItemAt(insertIndex)->Position() > addon->Position())
|
||||
break;
|
||||
|
||||
addons.AddItem(addon, insertIndex);
|
||||
}
|
||||
|
||||
for(int32 index = 0; index < addons.CountItems(); index++) {
|
||||
addon = addons.ItemAt(index);
|
||||
|
||||
if(!addon->GetPreferredSize(&width, &height))
|
||||
continue;
|
||||
|
||||
target = addon->CreateView(BPoint(0, 0));
|
||||
if(!target)
|
||||
continue;
|
||||
|
||||
fTabView->AddTab(target, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::UpdateStatus(int32 code)
|
||||
{
|
||||
switch(code) {
|
||||
case PPP_REPORT_DEVICE_UP_FAILED:
|
||||
case PPP_REPORT_AUTHENTICATION_FAILED:
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
case PPP_REPORT_CONNECTION_LOST:
|
||||
fConnectButton->SetLabel(kLabelConnect);
|
||||
break;
|
||||
|
||||
default:
|
||||
fConnectButton->SetLabel(kLabelDisconnect);
|
||||
}
|
||||
|
||||
// maybe the status string must not be changed (codes that set fKeepLabel to false
|
||||
// should still be handled)
|
||||
if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL)
|
||||
return;
|
||||
|
||||
if(fListener.InitCheck() != B_OK) {
|
||||
fStatusView->SetText(kErrorNoPPPStack);
|
||||
return;
|
||||
}
|
||||
|
||||
// only errors should set fKeepLabel to true
|
||||
switch(code) {
|
||||
case PPP_REPORT_GOING_UP:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(kTextConnecting);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_UP_SUCCESSFUL:
|
||||
fKeepLabel = false;
|
||||
fStatusView->SetText(kTextConnectionEstablished);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_DOWN_SUCCESSFUL:
|
||||
fStatusView->SetText(kTextNotConnected);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_DEVICE_UP_FAILED:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextDeviceUpFailed);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_AUTHENTICATION_REQUESTED:
|
||||
fStatusView->SetText(kTextAuthenticating);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_AUTHENTICATION_FAILED:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextAuthenticationFailed);
|
||||
break;
|
||||
|
||||
case PPP_REPORT_CONNECTION_LOST:
|
||||
fKeepLabel = true;
|
||||
fStatusView->SetText(kTextConnectionLost);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::WatchInterface(ppp_interface_id ID)
|
||||
{
|
||||
fListener.WatchInterface(ID);
|
||||
|
||||
// update status
|
||||
PPPInterface interface(fListener.Interface());
|
||||
if(interface.InitCheck() != B_OK)
|
||||
UpdateStatus(PPP_REPORT_DOWN_SUCCESSFUL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::LoadInterfaces()
|
||||
{
|
||||
fInterfaceMenu->AddSeparatorItem();
|
||||
fInterfaceMenu->AddItem(new BMenuItem(kLabelCreateNewInterface,
|
||||
new BMessage(kMsgCreateNew)));
|
||||
fDeleterItem = new BMenuItem(kLabelDeleteCurrent,
|
||||
new BMessage(kMsgDeleteCurrent));
|
||||
fInterfaceMenu->AddItem(fDeleterItem);
|
||||
|
||||
BDirectory settingsDirectory;
|
||||
BEntry entry;
|
||||
BPath path;
|
||||
PPPManager::GetSettingsDirectory(&settingsDirectory);
|
||||
while(settingsDirectory.GetNextEntry(&entry) == B_OK) {
|
||||
if(entry.IsFile()) {
|
||||
entry.GetPath(&path);
|
||||
AddInterface(path.Leaf(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::AddInterface(const char *name, bool isNew = false)
|
||||
{
|
||||
if(FindInterface(name)) {
|
||||
(new BAlert(kErrorTitle, kErrorInterfaceExists, kLabelOK,
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
BMessage *message = new BMessage(kMsgSelectInterface);
|
||||
message->AddString("name", name);
|
||||
BString label(name);
|
||||
if(PPPManager::DefaultInterface() == label)
|
||||
label << " (" << kLabelDefaultInterface << ")";
|
||||
BMenuItem *item = new BMenuItem(label.String(), message);
|
||||
item->SetTarget(this);
|
||||
int32 index = FindNextMenuInsertionIndex(fInterfaceMenu, name);
|
||||
if(index > CountInterfaces())
|
||||
index = CountInterfaces();
|
||||
fInterfaceMenu->AddItem(item, index);
|
||||
UpdateControls();
|
||||
|
||||
item->SetMarked(true);
|
||||
SelectInterface(index, isNew);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::SelectInterface(int32 index, bool isNew = false)
|
||||
{
|
||||
BMenuItem *item = fInterfaceMenu->FindMarked();
|
||||
if(fCurrentItem && item == fCurrentItem)
|
||||
return;
|
||||
|
||||
if(fCurrentItem && !fSettings.SaveSettingsToFile())
|
||||
(new BAlert(kErrorTitle, kErrorSavingFailed, kLabelOK,
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
|
||||
|
||||
if(index >= CountInterfaces() || index < 0) {
|
||||
if(CountInterfaces() > 0)
|
||||
SelectInterface(0);
|
||||
else {
|
||||
fCurrentItem = NULL;
|
||||
WatchInterface(PPP_UNDEFINED_INTERFACE_ID);
|
||||
}
|
||||
} else {
|
||||
fCurrentItem = fInterfaceMenu->ItemAt(index);
|
||||
if(!fCurrentItem) {
|
||||
SelectInterface(0);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *name = fCurrentItem->Message() ?
|
||||
fCurrentItem->Message()->FindString("name") : NULL;
|
||||
fDefaultInterface->SetValue(name && PPPManager::DefaultInterface() == name);
|
||||
fCurrentItem->SetMarked(true);
|
||||
fDeleterItem->SetEnabled(true);
|
||||
fInterfaceMenu->Superitem()->SetLabel(name);
|
||||
WatchInterface(fListener.Manager().InterfaceWithName(name));
|
||||
}
|
||||
|
||||
UpdateControls();
|
||||
|
||||
if(!fCurrentItem)
|
||||
fSettings.LoadSettings(NULL, false);
|
||||
// tell modules to unload all settings
|
||||
else if(!isNew && !fSettings.LoadSettings(
|
||||
fCurrentItem->Message()->FindString("name"), false)) {
|
||||
(new BAlert(kErrorTitle, kErrorLoadingFailed, kLabelOK,
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
|
||||
fSettings.LoadSettings(fCurrentItem->Message()->FindString("name"), true);
|
||||
} else if(isNew && !fSettings.LoadSettings(
|
||||
fCurrentItem->Message()->FindString("name"), true))
|
||||
(new BAlert(kErrorTitle, kErrorLoadingFailed, kLabelOK,
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
DialUpView::CountInterfaces() const
|
||||
{
|
||||
return fInterfaceMenu->CountItems() - 3;
|
||||
}
|
||||
|
||||
|
||||
BMenuItem*
|
||||
DialUpView::FindInterface(BString name)
|
||||
{
|
||||
BMenuItem *item;
|
||||
for(int32 index = 0; index < CountInterfaces(); index++) {
|
||||
item = fInterfaceMenu->ItemAt(index);
|
||||
if(item && item->Message() && item->Message()->HasString("name")
|
||||
&& name == item->Message()->FindString("name"))
|
||||
return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::UpdateControls()
|
||||
{
|
||||
if(fTabView->IsHidden() && CountInterfaces() > 0) {
|
||||
fInterfaceMenu->SetLabelFromMarked(true);
|
||||
fStringView->Hide();
|
||||
fCreateNewButton->Hide();
|
||||
fTabView->Show();
|
||||
fDefaultInterface->Show();
|
||||
fConnectButton->SetEnabled(true);
|
||||
} else if(!fTabView->IsHidden() && CountInterfaces() == 0) {
|
||||
fDeleterItem->SetEnabled(false);
|
||||
fInterfaceMenu->SetRadioMode(false);
|
||||
fInterfaceMenu->Superitem()->SetLabel(kLabelCreateNew);
|
||||
fTabView->Hide();
|
||||
fDefaultInterface->Hide();
|
||||
fStringView->Show();
|
||||
fCreateNewButton->Show();
|
||||
fConnectButton->SetEnabled(false);
|
||||
}
|
||||
|
||||
// move default checkbox next to interface menu (its size might have changed)
|
||||
float width = fInterfaceMenu->StringWidth(fMenuField->Label())
|
||||
+ fInterfaceMenu->StringWidth(fInterfaceMenu->Superitem()->Label()) + 30;
|
||||
if(width > kInterfaceFieldWidth)
|
||||
width = kInterfaceFieldWidth;
|
||||
fDefaultInterface->MoveTo(fMenuField->Frame().left + width,
|
||||
fDefaultInterface->Frame().top);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DialUpView::UpdateDefaultInterface()
|
||||
{
|
||||
const char *name = fCurrentItem->Message()->FindString("name");
|
||||
BMenuItem *defaultItem = FindInterface(PPPManager::DefaultInterface());
|
||||
if(fDefaultInterface->Value()) {
|
||||
if(!PPPManager::SetDefaultInterface(name)) {
|
||||
fDefaultInterface->SetValue(0);
|
||||
return;
|
||||
}
|
||||
if(defaultItem)
|
||||
defaultItem->SetLabel(defaultItem->Message()->FindString("name"));
|
||||
|
||||
BString label(name);
|
||||
label << " (" << kLabelDefaultInterface << ")";
|
||||
fCurrentItem->SetLabel(label.String());
|
||||
} else {
|
||||
PPPManager::SetDefaultInterface("");
|
||||
fCurrentItem->SetLabel(name);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _DIAL_UP_VIEW__H
|
||||
#define _DIAL_UP_VIEW__H
|
||||
|
||||
#include <Message.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <PPPInterfaceListener.h>
|
||||
#include <PTPSettings.h>
|
||||
|
||||
|
||||
class DialUpView : public BView {
|
||||
public:
|
||||
DialUpView(BRect frame);
|
||||
virtual ~DialUpView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
void BringUpOrDown();
|
||||
|
||||
void HandleReportMessage(BMessage *message);
|
||||
void CreateTabs();
|
||||
|
||||
void UpdateStatus(int32 code);
|
||||
void WatchInterface(ppp_interface_id ID);
|
||||
|
||||
void LoadInterfaces();
|
||||
|
||||
void AddInterface(const char *name, bool isNew = false);
|
||||
void SelectInterface(int32 index, bool isNew = false);
|
||||
int32 CountInterfaces() const;
|
||||
BMenuItem *FindInterface(BString name);
|
||||
|
||||
void UpdateControls();
|
||||
void UpdateDefaultInterface();
|
||||
|
||||
private:
|
||||
PPPInterfaceListener fListener;
|
||||
PTPSettings fSettings;
|
||||
|
||||
thread_id fUpDownThread;
|
||||
|
||||
BMenuItem *fCurrentItem, *fDeleterItem;
|
||||
|
||||
bool fKeepLabel;
|
||||
BStringView *fStatusView;
|
||||
BButton *fConnectButton, *fCreateNewButton;
|
||||
BPopUpMenu *fInterfaceMenu;
|
||||
BMenuField *fMenuField;
|
||||
BCheckBox *fDefaultInterface;
|
||||
BStringView *fStringView;
|
||||
// shows "No interfaces found..." notice
|
||||
BTabView *fTabView;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,670 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GeneralAddon saves the loaded settings.
|
||||
// GeneralView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "GeneralAddon.h"
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
#include <stl_algobase.h>
|
||||
// for max()
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include <PPPDefs.h>
|
||||
|
||||
|
||||
// message constants
|
||||
static const uint32 kMsgSelectDevice = 'SELD';
|
||||
static const uint32 kMsgSelectAuthenticator = 'SELA';
|
||||
|
||||
// labels
|
||||
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 = "Username: ";
|
||||
static const char *kLabelPassword = "Password: ";
|
||||
static const char *kLabelSavePassword = "Save Password";
|
||||
static const char *kLabelNone = "None";
|
||||
|
||||
// string constants for information saved in the settings message
|
||||
static const char *kGeneralTabAuthentication = "Authentication";
|
||||
static const char *kGeneralTabAuthenticators = "Authenticators";
|
||||
|
||||
|
||||
#define DEFAULT_AUTHENTICATOR "PAP"
|
||||
// this authenticator is selected by default when creating a new interface
|
||||
|
||||
|
||||
GeneralAddon::GeneralAddon(BMessage *addons)
|
||||
: DialUpAddon(addons),
|
||||
fHasPassword(false),
|
||||
fDeleteView(false),
|
||||
fAuthenticatorsCount(0),
|
||||
fSettings(NULL),
|
||||
fGeneralView(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GeneralAddon::~GeneralAddon()
|
||||
{
|
||||
if(fDeleteView)
|
||||
delete fGeneralView;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
GeneralAddon::SessionPassword() const
|
||||
{
|
||||
if(fGeneralView && fGeneralView->AuthenticatorName())
|
||||
return fGeneralView->Password();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
DialUpAddon*
|
||||
GeneralAddon::FindDevice(const BString& moduleName) const
|
||||
{
|
||||
DialUpAddon *addon;
|
||||
for(int32 index = 0; Addons()->FindPointer(DUN_DEVICE_ADDON_TYPE, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK; index++)
|
||||
if(addon && moduleName == addon->KernelModuleName())
|
||||
return addon;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::LoadSettings(BMessage *settings, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fHasPassword = false;
|
||||
fDeviceName = fUsername = fPassword = "";
|
||||
fDeviceAddon = NULL;
|
||||
fAuthenticatorsCount = 0;
|
||||
fSettings = settings;
|
||||
|
||||
if(!fGeneralView) {
|
||||
CreateView(BPoint(0,0));
|
||||
fDeleteView = true;
|
||||
}
|
||||
|
||||
fGeneralView->Reload();
|
||||
// reset all views (empty settings)
|
||||
|
||||
if(!settings || isNew)
|
||||
return true;
|
||||
|
||||
if(!LoadDeviceSettings())
|
||||
return false;
|
||||
|
||||
if(!LoadAuthenticationSettings())
|
||||
return false;
|
||||
|
||||
fGeneralView->Reload();
|
||||
// reload new settings
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::LoadDeviceSettings()
|
||||
{
|
||||
int32 index = 0;
|
||||
BMessage device;
|
||||
if(!FindMessageParameter(PPP_DEVICE_KEY, *fSettings, &device, &index))
|
||||
return false;
|
||||
// TODO: tell user that device specification is missing
|
||||
|
||||
if(device.FindString(MDSU_VALUES, &fDeviceName) != B_OK)
|
||||
return false;
|
||||
// TODO: tell user that device specification is missing
|
||||
|
||||
device.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &device);
|
||||
|
||||
fDeviceAddon = FindDevice(fDeviceName);
|
||||
if(!fDeviceAddon)
|
||||
return false;
|
||||
|
||||
return fDeviceAddon->LoadSettings(fSettings, false);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::LoadAuthenticationSettings()
|
||||
{
|
||||
int32 itemIndex = 0;
|
||||
BMessage authentication, item;
|
||||
|
||||
if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings, &item, &itemIndex))
|
||||
return true;
|
||||
|
||||
// find authenticators (though we load all authenticators, we only use one)
|
||||
BString name;
|
||||
for(int32 index = 0; item.FindString(MDSU_VALUES, index, &name) == B_OK; index++) {
|
||||
BMessage authenticator;
|
||||
if(!GetAuthenticator(name, &authenticator))
|
||||
return false;
|
||||
// fatal error: we do not know how to handle this authenticator
|
||||
|
||||
MarkAuthenticatorAsValid(name);
|
||||
authentication.AddString(kGeneralTabAuthenticators, name);
|
||||
++fAuthenticatorsCount;
|
||||
}
|
||||
|
||||
fSettings->AddMessage(kGeneralTabAuthentication, &authentication);
|
||||
|
||||
bool hasUsername = false;
|
||||
// a username must be present
|
||||
|
||||
// load username and password
|
||||
BMessage parameter;
|
||||
int32 parameterIndex = 0;
|
||||
if(FindMessageParameter(PPP_USERNAME_KEY, *fSettings, ¶meter, ¶meterIndex)
|
||||
&& parameter.FindString(MDSU_VALUES, &fUsername) == B_OK) {
|
||||
hasUsername = true;
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter);
|
||||
}
|
||||
|
||||
parameterIndex = 0;
|
||||
if(FindMessageParameter(PPP_PASSWORD_KEY, *fSettings, ¶meter, ¶meterIndex)
|
||||
&& parameter.FindString(MDSU_VALUES, &fPassword) == B_OK) {
|
||||
fHasPassword = true;
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter);
|
||||
}
|
||||
|
||||
// tell DUN whether everything is valid
|
||||
if(hasUsername)
|
||||
item.AddBool(MDSU_VALID, true);
|
||||
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, itemIndex, &item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralAddon::IsModified(bool *settings) const
|
||||
{
|
||||
if(!fSettings) {
|
||||
*settings = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool deviceSettings, authenticationSettings;
|
||||
|
||||
IsDeviceModified(&deviceSettings);
|
||||
IsAuthenticationModified(&authenticationSettings);
|
||||
|
||||
*settings = (deviceSettings || authenticationSettings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralAddon::IsDeviceModified(bool *settings) const
|
||||
{
|
||||
fGeneralView->IsDeviceModified(settings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralAddon::IsAuthenticationModified(bool *settings) const
|
||||
{
|
||||
// currently we only support selecting one authenticator
|
||||
if(fAuthenticatorsCount == 0)
|
||||
*settings = fGeneralView->AuthenticatorName();
|
||||
else {
|
||||
BMessage authentication;
|
||||
if(fSettings->FindMessage(kGeneralTabAuthentication,
|
||||
&authentication) != B_OK) {
|
||||
*settings = false;
|
||||
return;
|
||||
// error!
|
||||
}
|
||||
|
||||
BString authenticator;
|
||||
if(authentication.FindString(kGeneralTabAuthenticators,
|
||||
&authenticator) != B_OK) {
|
||||
*settings = false;
|
||||
return;
|
||||
// error!
|
||||
}
|
||||
|
||||
*settings = (!fGeneralView->AuthenticatorName()
|
||||
|| authenticator != fGeneralView->AuthenticatorName()
|
||||
|| fUsername != fGeneralView->Username()
|
||||
|| (fPassword != fGeneralView->Password() && fHasPassword)
|
||||
|| fHasPassword != fGeneralView->DoesSavePassword());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::SaveSettings(BMessage *settings)
|
||||
{
|
||||
if(!fSettings || !settings || !fGeneralView->DeviceName())
|
||||
return false;
|
||||
// TODO: tell user that a device is needed (if we fail because of this)
|
||||
|
||||
if(!fGeneralView->DeviceAddon()
|
||||
|| !fGeneralView->DeviceAddon()->SaveSettings(settings))
|
||||
return false;
|
||||
|
||||
if(fGeneralView->AuthenticatorName()) {
|
||||
BMessage authenticator;
|
||||
authenticator.AddString(MDSU_NAME, PPP_AUTHENTICATOR_KEY);
|
||||
authenticator.AddString(MDSU_VALUES, fGeneralView->AuthenticatorName());
|
||||
settings->AddMessage(MDSU_PARAMETERS, &authenticator);
|
||||
|
||||
BMessage username;
|
||||
username.AddString(MDSU_NAME, PPP_USERNAME_KEY);
|
||||
username.AddString(MDSU_VALUES, fGeneralView->Username());
|
||||
settings->AddMessage(MDSU_PARAMETERS, &username);
|
||||
|
||||
if(fGeneralView->DoesSavePassword()) {
|
||||
// save password, too
|
||||
BMessage password;
|
||||
password.AddString(MDSU_NAME, PPP_PASSWORD_KEY);
|
||||
password.AddString(MDSU_VALUES, fGeneralView->Password());
|
||||
settings->AddMessage(MDSU_PARAMETERS, &password);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::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*
|
||||
GeneralAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
if(!fGeneralView) {
|
||||
BRect rect;
|
||||
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
|
||||
fGeneralView = new GeneralView(this, rect);
|
||||
}
|
||||
|
||||
fDeleteView = false;
|
||||
|
||||
fGeneralView->MoveTo(leftTop);
|
||||
fGeneralView->Reload();
|
||||
return fGeneralView;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const
|
||||
{
|
||||
if(!entry)
|
||||
return false;
|
||||
|
||||
BString name;
|
||||
for(int32 index = 0; Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
|
||||
entry) == B_OK; index++) {
|
||||
entry->FindString("KernelModuleName", &name);
|
||||
if(name == moduleName)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GeneralAddon::MarkAuthenticatorAsValid(const BString& moduleName)
|
||||
{
|
||||
BMessage authenticator;
|
||||
int32 index = 0;
|
||||
BString name;
|
||||
|
||||
for(; FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings, &authenticator,
|
||||
&index); index++) {
|
||||
authenticator.FindString("KernelModuleName", &name);
|
||||
if(name == moduleName) {
|
||||
authenticator.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &authenticator);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
GeneralView::GeneralView(GeneralAddon *addon, BRect frame)
|
||||
: BView(frame, kLabelGeneral, B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(5, 5);
|
||||
rect.bottom = 100;
|
||||
fDeviceBox = new BBox(rect, "Device");
|
||||
Addon()->Addons()->AddFloat(DUN_DEVICE_VIEW_WIDTH,
|
||||
fDeviceBox->Bounds().Width() - 10);
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = rect.top
|
||||
+ 25 // space for topmost control
|
||||
+ 3 * 20 // size of controls
|
||||
+ 3 * 5; // space beween controls and bottom of box
|
||||
fAuthenticationBox = new BBox(rect, "Authentication");
|
||||
|
||||
fDeviceField = new BMenuField(BRect(5, 0, 250, 20), "Device",
|
||||
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",
|
||||
kLabelAuthenticator, new BPopUpMenu(kLabelNoAuthenticatorsFound));
|
||||
fAuthenticatorField->SetDivider(StringWidth(fAuthenticatorField->Label()) + 5);
|
||||
fAuthenticatorField->Menu()->SetRadioMode(true);
|
||||
AddAuthenticators();
|
||||
fAuthenticationBox->SetLabel(fAuthenticatorField);
|
||||
|
||||
rect = fAuthenticationBox->Bounds();
|
||||
rect.InsetBy(10, 25);
|
||||
rect.bottom = rect.top + 20;
|
||||
fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL);
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
fPassword = new BTextControl(rect, "password", kLabelPassword, NULL, NULL);
|
||||
fPassword->TextView()->HideTyping(true);
|
||||
|
||||
// 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", kLabelSavePassword, NULL);
|
||||
|
||||
fAuthenticationBox->AddChild(fUsername);
|
||||
fAuthenticationBox->AddChild(fPassword);
|
||||
fAuthenticationBox->AddChild(fSavePassword);
|
||||
|
||||
AddChild(fDeviceBox);
|
||||
AddChild(fAuthenticationBox);
|
||||
}
|
||||
|
||||
|
||||
GeneralView::~GeneralView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::Reload()
|
||||
{
|
||||
fDeviceAddon = NULL;
|
||||
|
||||
BMenuItem *item = NULL;
|
||||
for(int32 index = 0; index < fDeviceField->Menu()->CountItems(); index++) {
|
||||
item = fDeviceField->Menu()->ItemAt(index);
|
||||
if(item && item->Message() && item->Message()->FindPointer("Addon",
|
||||
reinterpret_cast<void**>(&fDeviceAddon)) == B_OK
|
||||
&& fDeviceAddon == Addon()->DeviceAddon())
|
||||
break;
|
||||
}
|
||||
|
||||
if(fDeviceAddon && fDeviceAddon == Addon()->DeviceAddon())
|
||||
item->SetMarked(true);
|
||||
else if(Addon()->IsNew() && fDeviceField->Menu()->CountItems() > 0) {
|
||||
item = fDeviceField->Menu()->ItemAt(0);
|
||||
item->SetMarked(true);
|
||||
item->Message()->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon));
|
||||
fDeviceAddon->LoadSettings(Addon()->Settings(), true);
|
||||
} else {
|
||||
fDeviceAddon = NULL;
|
||||
item = fDeviceField->Menu()->FindMarked();
|
||||
if(item)
|
||||
item->SetMarked(false);
|
||||
}
|
||||
|
||||
if(Addon()->CountAuthenticators() > 0) {
|
||||
BString kernelModule, authenticator;
|
||||
BMessage authentication;
|
||||
if(Addon()->Settings()->FindMessage(kGeneralTabAuthentication,
|
||||
&authentication) == B_OK)
|
||||
authentication.FindString(kGeneralTabAuthenticators, &authenticator);
|
||||
BMenu *menu = fAuthenticatorField->Menu();
|
||||
for(int32 index = 0; index < menu->CountItems(); index++) {
|
||||
item = menu->ItemAt(index);
|
||||
if(item && item->Message()
|
||||
&& item->Message()->FindString("KernelModuleName",
|
||||
&kernelModule) == B_OK && kernelModule == authenticator) {
|
||||
item->SetMarked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if(Addon()->IsNew() && fAuthenticatorDefault)
|
||||
fAuthenticatorDefault->SetMarked(true);
|
||||
else
|
||||
fAuthenticatorNone->SetMarked(true);
|
||||
|
||||
fUsername->SetText(Addon()->Username());
|
||||
fPassword->SetText(Addon()->Password());
|
||||
fSavePassword->SetValue(Addon()->HasPassword());
|
||||
|
||||
ReloadDeviceView();
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
GeneralView::DeviceName() const
|
||||
{
|
||||
if(fDeviceAddon)
|
||||
return fDeviceAddon->KernelModuleName();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
GeneralView::AuthenticatorName() const
|
||||
{
|
||||
BMenuItem *marked = fAuthenticatorField->Menu()->FindMarked();
|
||||
if(marked && marked != fAuthenticatorNone)
|
||||
return marked->Message()->FindString("KernelModuleName");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::IsDeviceModified(bool *settings) const
|
||||
{
|
||||
if(fDeviceAddon != Addon()->DeviceAddon())
|
||||
*settings = true;
|
||||
else if(fDeviceAddon)
|
||||
fDeviceAddon->IsModified(settings);
|
||||
else
|
||||
*settings = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fDeviceField->Menu()->SetTargetForItems(this);
|
||||
fAuthenticatorField->Menu()->SetTargetForItems(this);
|
||||
fUsername->SetTarget(this);
|
||||
fPassword->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case kMsgSelectDevice:
|
||||
if(message->FindPointer("Addon", reinterpret_cast<void**>(&fDeviceAddon))
|
||||
!= B_OK)
|
||||
fDeviceAddon = NULL;
|
||||
else {
|
||||
if(fDeviceAddon != Addon()->DeviceAddon())
|
||||
fDeviceAddon->LoadSettings(Addon()->Settings(), Addon()->IsNew());
|
||||
|
||||
ReloadDeviceView();
|
||||
}
|
||||
break;
|
||||
|
||||
case kMsgSelectAuthenticator:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::ReloadDeviceView()
|
||||
{
|
||||
// first remove existing device view(s)
|
||||
while(fDeviceBox->CountChildren() > 1)
|
||||
fDeviceBox->RemoveChild(fDeviceBox->ChildAt(1));
|
||||
|
||||
if(!fDeviceAddon)
|
||||
return;
|
||||
|
||||
BRect rect(fDeviceBox->Bounds());
|
||||
float width, height;
|
||||
if(!fDeviceAddon->GetPreferredSize(&width, &height)) {
|
||||
width = rect.Width();
|
||||
height = 50;
|
||||
}
|
||||
|
||||
if(width > rect.Width())
|
||||
width = rect.Width();
|
||||
if(height < 10)
|
||||
height = 10;
|
||||
// set minimum height
|
||||
else if(height > 200)
|
||||
height = 200;
|
||||
// set maximum height
|
||||
|
||||
rect.InsetBy((rect.Width() - width) / 2, 0);
|
||||
// center horizontally
|
||||
rect.top = 25;
|
||||
rect.bottom = rect.top + height;
|
||||
float deltaY = height + 30 - fDeviceBox->Bounds().Height();
|
||||
fDeviceBox->ResizeBy(0, deltaY);
|
||||
fAuthenticationBox->MoveBy(0, deltaY);
|
||||
|
||||
BView *deviceView = fDeviceAddon->CreateView(rect.LeftTop());
|
||||
if(deviceView)
|
||||
fDeviceBox->AddChild(deviceView);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::UpdateControls()
|
||||
{
|
||||
BMenu *menu = fAuthenticatorField->Menu();
|
||||
int32 index = menu->IndexOf(menu->FindMarked());
|
||||
if(index < 0)
|
||||
fAuthenticatorNone->SetMarked(true);
|
||||
|
||||
if(index == 0) {
|
||||
fUsername->SetEnabled(false);
|
||||
fPassword->SetEnabled(false);
|
||||
fSavePassword->SetEnabled(false);
|
||||
} else {
|
||||
fUsername->SetEnabled(true);
|
||||
fPassword->SetEnabled(true);
|
||||
fSavePassword->SetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::AddDevices()
|
||||
{
|
||||
AddAddonsToMenu(Addon()->Addons(), fDeviceField->Menu(), DUN_DEVICE_ADDON_TYPE,
|
||||
kMsgSelectDevice);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GeneralView::AddAuthenticators()
|
||||
{
|
||||
fAuthenticatorDefault = NULL;
|
||||
fAuthenticatorNone = new BMenuItem(kLabelNone,
|
||||
new BMessage(kMsgSelectAuthenticator));
|
||||
fAuthenticatorField->Menu()->AddItem(fAuthenticatorNone);
|
||||
fAuthenticatorNone->SetMarked(true);
|
||||
fAuthenticatorField->Menu()->AddSeparatorItem();
|
||||
|
||||
BMenuItem *item;
|
||||
BMessage addon;
|
||||
for(int32 index = 0;
|
||||
Addon()->Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index,
|
||||
&addon) == B_OK; index++) {
|
||||
BMessage *message = new BMessage(kMsgSelectAuthenticator);
|
||||
message->AddString("KernelModuleName", addon.FindString("KernelModuleName"));
|
||||
|
||||
BString name, technicalName, friendlyName;
|
||||
bool hasTechnicalName
|
||||
= (addon.FindString("TechnicalName", &technicalName) == B_OK);
|
||||
bool hasFriendlyName
|
||||
= (addon.FindString("FriendlyName", &friendlyName) == B_OK);
|
||||
if(hasTechnicalName) {
|
||||
name << technicalName;
|
||||
if(hasFriendlyName)
|
||||
name << " (";
|
||||
}
|
||||
if(hasFriendlyName) {
|
||||
name << friendlyName;
|
||||
if(hasTechnicalName)
|
||||
name << ")";
|
||||
}
|
||||
|
||||
int32 insertAt = FindNextMenuInsertionIndex(fAuthenticatorField->Menu(),
|
||||
name.String(), 2);
|
||||
item = new BMenuItem(name.String(), message);
|
||||
if(hasTechnicalName && technicalName == DEFAULT_AUTHENTICATOR)
|
||||
fAuthenticatorDefault = item;
|
||||
fAuthenticatorField->Menu()->AddItem(item, insertAt);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GeneralAddon saves the loaded settings.
|
||||
// GeneralView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#ifndef _GENERAL_ADDON__H
|
||||
#define _GENERAL_ADDON__H
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
class GeneralView;
|
||||
|
||||
|
||||
class GeneralAddon : public DialUpAddon {
|
||||
public:
|
||||
GeneralAddon(BMessage *addons);
|
||||
virtual ~GeneralAddon();
|
||||
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
|
||||
const char *DeviceName() const
|
||||
{ return fDeviceName.String(); }
|
||||
const char *Username() const
|
||||
{ return fUsername.String(); }
|
||||
const char *Password() const
|
||||
{ return fPassword.String(); }
|
||||
const char *SessionPassword() const;
|
||||
bool HasPassword() const
|
||||
{ return fHasPassword; }
|
||||
|
||||
DialUpAddon *FindDevice(const BString& moduleName) const;
|
||||
DialUpAddon *DeviceAddon() const
|
||||
{ return fDeviceAddon; }
|
||||
|
||||
int32 CountAuthenticators() const
|
||||
{ return fAuthenticatorsCount; }
|
||||
|
||||
BMessage *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
virtual int32 Position() const
|
||||
{ return 0; }
|
||||
virtual bool LoadSettings(BMessage *settings, bool isNew);
|
||||
bool LoadDeviceSettings();
|
||||
bool LoadAuthenticationSettings();
|
||||
|
||||
virtual void IsModified(bool *settings) const;
|
||||
void IsDeviceModified(bool *settings) const;
|
||||
void IsAuthenticationModified(bool *settings) const;
|
||||
|
||||
virtual bool SaveSettings(BMessage *settings);
|
||||
virtual bool GetPreferredSize(float *width, float *height) const;
|
||||
virtual BView *CreateView(BPoint leftTop);
|
||||
|
||||
private:
|
||||
bool GetAuthenticator(const BString& moduleName, BMessage *entry) const;
|
||||
bool MarkAuthenticatorAsValid(const BString& moduleName);
|
||||
|
||||
private:
|
||||
bool fIsNew, fHasPassword, fDeleteView;
|
||||
BString fDeviceName, fUsername, fPassword;
|
||||
DialUpAddon *fDeviceAddon;
|
||||
int32 fAuthenticatorsCount;
|
||||
BMessage *fSettings;
|
||||
// saves last settings state
|
||||
GeneralView *fGeneralView;
|
||||
};
|
||||
|
||||
|
||||
class GeneralView : public BView {
|
||||
public:
|
||||
GeneralView(GeneralAddon *addon, BRect frame);
|
||||
virtual ~GeneralView();
|
||||
|
||||
GeneralAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
|
||||
const char *Username() const
|
||||
{ return fUsername->Text(); }
|
||||
const char *Password() const
|
||||
{ return fPassword->Text(); }
|
||||
bool DoesSavePassword() const
|
||||
{ return fSavePassword->Value(); }
|
||||
|
||||
DialUpAddon *DeviceAddon() const
|
||||
{ return fDeviceAddon; }
|
||||
const char *DeviceName() const;
|
||||
const char *AuthenticatorName() const;
|
||||
void IsDeviceModified(bool *settings) const;
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
void ReloadDeviceView();
|
||||
void UpdateControls();
|
||||
|
||||
void AddDevices();
|
||||
void AddAuthenticators();
|
||||
|
||||
private:
|
||||
GeneralAddon *fAddon;
|
||||
DialUpAddon *fDeviceAddon;
|
||||
BBox *fDeviceBox, *fAuthenticationBox;
|
||||
BMenuField *fDeviceField, *fAuthenticatorField;
|
||||
BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault;
|
||||
BTextControl *fUsername, *fPassword;
|
||||
BCheckBox *fSavePassword;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,351 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// IPCPAddon saves the loaded settings.
|
||||
// IPCPView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "IPCPAddon.h"
|
||||
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
#include <stl_algobase.h>
|
||||
// for max()
|
||||
|
||||
#include <StringView.h>
|
||||
|
||||
#include <PPPDefs.h>
|
||||
#include <IPCP.h>
|
||||
// from IPCP addon
|
||||
|
||||
|
||||
// GUI constants
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
// message constants
|
||||
static const uint32 kMsgUpdateControls = 'UCTL';
|
||||
|
||||
// labels
|
||||
static const char *kLabelIPCP = "TCP/IP";
|
||||
static const char *kLabelIPAddress = "IP Address: ";
|
||||
static const char *kLabelPrimaryDNS = "Primary DNS: ";
|
||||
static const char *kLabelSecondaryDNS = "Secondary DNS: ";
|
||||
static const char *kLabelOptional = "(Optional)";
|
||||
static const char *kLabelExtendedOptions = "Extended Options:";
|
||||
static const char *kLabelEnabled = "Enable TCP/IP Protocol";
|
||||
|
||||
// add-on descriptions
|
||||
static const char *kKernelModuleName = "ipcp";
|
||||
|
||||
|
||||
IPCPAddon::IPCPAddon(BMessage *addons)
|
||||
: DialUpAddon(addons),
|
||||
fSettings(NULL),
|
||||
fIPCPView(NULL)
|
||||
{
|
||||
CreateView(BPoint(0,0));
|
||||
fDeleteView = true;
|
||||
}
|
||||
|
||||
|
||||
IPCPAddon::~IPCPAddon()
|
||||
{
|
||||
if(fDeleteView)
|
||||
delete fIPCPView;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
IPCPAddon::LoadSettings(BMessage *settings, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fIsEnabled = false;
|
||||
fIPAddress = fPrimaryDNS = fSecondaryDNS = "";
|
||||
fSettings = settings;
|
||||
|
||||
fIPCPView->Reload();
|
||||
// reset all views (empty settings)
|
||||
|
||||
if(!settings || isNew)
|
||||
return true;
|
||||
|
||||
BMessage protocol;
|
||||
|
||||
int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol);
|
||||
if(protocolIndex < 0)
|
||||
return true;
|
||||
|
||||
protocol.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
|
||||
|
||||
fIsEnabled = true;
|
||||
|
||||
// the "Local" side parameter
|
||||
BMessage local;
|
||||
int32 localSideIndex = 0;
|
||||
if(!FindMessageParameter(IPCP_LOCAL_SIDE_KEY, protocol, &local, &localSideIndex))
|
||||
local.MakeEmpty();
|
||||
// just fall through and pretend we have an empty "Local" side parameter
|
||||
|
||||
// now load the supported parameters (the client-relevant subset)
|
||||
BString name;
|
||||
BMessage parameter;
|
||||
int32 index = 0;
|
||||
if(!FindMessageParameter(IPCP_IP_ADDRESS_KEY, local, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fIPAddress) != B_OK)
|
||||
fIPAddress = "";
|
||||
else {
|
||||
if(fIPAddress == "auto")
|
||||
fIPAddress = "";
|
||||
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if(!FindMessageParameter(IPCP_PRIMARY_DNS_KEY, local, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fPrimaryDNS) != B_OK)
|
||||
fPrimaryDNS = "";
|
||||
else {
|
||||
if(fPrimaryDNS == "auto")
|
||||
fPrimaryDNS = "";
|
||||
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if(!FindMessageParameter(IPCP_SECONDARY_DNS_KEY, local, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fSecondaryDNS) != B_OK)
|
||||
fSecondaryDNS = "";
|
||||
else {
|
||||
if(fSecondaryDNS == "auto")
|
||||
fSecondaryDNS = "";
|
||||
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
local.AddBool(MDSU_VALID, true);
|
||||
protocol.ReplaceMessage(MDSU_PARAMETERS, localSideIndex, &local);
|
||||
protocol.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol);
|
||||
|
||||
fIPCPView->Reload();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPAddon::IsModified(bool *settings) const
|
||||
{
|
||||
if(!fSettings) {
|
||||
*settings = false;
|
||||
return;
|
||||
}
|
||||
|
||||
*settings = (fIsEnabled != fIPCPView->IsEnabled()
|
||||
|| fIPAddress != fIPCPView->IPAddress()
|
||||
|| fPrimaryDNS != fIPCPView->PrimaryDNS()
|
||||
|| fSecondaryDNS != fIPCPView->SecondaryDNS());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
IPCPAddon::SaveSettings(BMessage *settings)
|
||||
{
|
||||
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);
|
||||
// the settings contain a simple "protocol ipcp" string
|
||||
|
||||
// now create the settings with all subparameters
|
||||
local.AddString(MDSU_NAME, IPCP_LOCAL_SIDE_KEY);
|
||||
bool needsLocal = false;
|
||||
|
||||
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, fIPCPView->IPAddress());
|
||||
local.AddMessage(MDSU_PARAMETERS, &ip);
|
||||
}
|
||||
|
||||
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, fIPCPView->PrimaryDNS());
|
||||
local.AddMessage(MDSU_PARAMETERS, &dns);
|
||||
}
|
||||
|
||||
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, fIPCPView->SecondaryDNS());
|
||||
local.AddMessage(MDSU_PARAMETERS, &dns);
|
||||
}
|
||||
|
||||
if(needsLocal)
|
||||
protocol.AddMessage(MDSU_PARAMETERS, &local);
|
||||
|
||||
settings->AddMessage(MDSU_PARAMETERS, &protocol);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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 = rect.Width();
|
||||
if(height)
|
||||
*height = rect.Height();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
IPCPAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
if(!fIPCPView) {
|
||||
BRect rect;
|
||||
Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect);
|
||||
fIPCPView = new IPCPView(this, rect);
|
||||
}
|
||||
|
||||
fDeleteView = false;
|
||||
|
||||
fIPCPView->MoveTo(leftTop);
|
||||
fIPCPView->Reload();
|
||||
return fIPCPView;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
IPCPAddon::FindIPCPProtocol(const BMessage& message, BMessage *protocol) const
|
||||
{
|
||||
if(!protocol)
|
||||
return -1;
|
||||
|
||||
BString name;
|
||||
for(int32 index = 0; FindMessageParameter(PPP_PROTOCOL_KEY, message, protocol,
|
||||
&index); index++)
|
||||
if(protocol->FindString(MDSU_VALUES, &name) == B_OK
|
||||
&& name == kKernelModuleName)
|
||||
return index;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
IPCPView::IPCPView(IPCPAddon *addon, BRect frame)
|
||||
: BView(frame, kLabelIPCP, B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(10, 10);
|
||||
rect.bottom = rect.top + 20;
|
||||
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;
|
||||
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));
|
||||
rect.top = rect.bottom + 50;
|
||||
rect.bottom = rect.top + 10;
|
||||
AddChild(new BStringView(rect, "expert", kLabelExtendedOptions));
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 15;
|
||||
fIsEnabled = new BCheckBox(rect, "isEnabled", kLabelEnabled,
|
||||
new BMessage(kMsgUpdateControls));
|
||||
|
||||
// set divider of text controls
|
||||
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);
|
||||
|
||||
AddChild(fIsEnabled);
|
||||
AddChild(fIPAddress);
|
||||
AddChild(fPrimaryDNS);
|
||||
AddChild(fSecondaryDNS);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::Reload()
|
||||
{
|
||||
fIsEnabled->SetValue(Addon()->IsEnabled() || Addon()->IsNew());
|
||||
// enable TCP/IP by default
|
||||
fIPAddress->SetText(Addon()->IPAddress());
|
||||
fPrimaryDNS->SetText(Addon()->PrimaryDNS());
|
||||
fSecondaryDNS->SetText(Addon()->SecondaryDNS());
|
||||
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fIsEnabled->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case kMsgUpdateControls:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IPCPView::UpdateControls()
|
||||
{
|
||||
fIPAddress->SetEnabled(IsEnabled());
|
||||
fPrimaryDNS->SetEnabled(IsEnabled());
|
||||
fSecondaryDNS->SetEnabled(IsEnabled());
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// IPCPAddon saves the loaded settings.
|
||||
// IPCPView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#ifndef _IPCP_ADDON__H
|
||||
#define _IPCP_ADDON__H
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <CheckBox.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
class IPCPView;
|
||||
|
||||
|
||||
class IPCPAddon : public DialUpAddon {
|
||||
public:
|
||||
IPCPAddon(BMessage *addons);
|
||||
virtual ~IPCPAddon();
|
||||
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
|
||||
bool IsEnabled() const
|
||||
{ return fIsEnabled; }
|
||||
const char *IPAddress() const
|
||||
{ return fIPAddress.String(); }
|
||||
const char *PrimaryDNS() const
|
||||
{ return fPrimaryDNS.String(); }
|
||||
const char *SecondaryDNS() const
|
||||
{ return fSecondaryDNS.String(); }
|
||||
|
||||
BMessage *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
virtual int32 Position() const
|
||||
{ return 10; }
|
||||
|
||||
virtual bool LoadSettings(BMessage *settings, bool isNew);
|
||||
virtual void IsModified(bool *settings) const;
|
||||
virtual bool SaveSettings(BMessage *settings);
|
||||
virtual bool GetPreferredSize(float *width, float *height) const;
|
||||
virtual BView *CreateView(BPoint leftTop);
|
||||
|
||||
private:
|
||||
int32 FindIPCPProtocol(const BMessage& message, BMessage *protocol) const;
|
||||
|
||||
private:
|
||||
bool fIsNew, fIsEnabled, fDeleteView;
|
||||
BString fIPAddress, fPrimaryDNS, fSecondaryDNS;
|
||||
BMessage *fSettings;
|
||||
// saves last settings state
|
||||
IPCPView *fIPCPView;
|
||||
};
|
||||
|
||||
|
||||
class IPCPView : public BView {
|
||||
public:
|
||||
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
|
||||
{ return fPrimaryDNS->Text(); }
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
#include "DialUpAddon.h"
|
||||
#include <ListView.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Screen.h>
|
||||
#include <String.h>
|
||||
#include <ListItem.h>
|
||||
// contains StringItem class declaration
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
BPoint
|
||||
center_on_screen(BRect rect, BWindow *window = NULL)
|
||||
{
|
||||
BRect screenFrame = BScreen(window).Frame();
|
||||
BPoint point((screenFrame.Width() - rect.Width()) / 2.0,
|
||||
(screenFrame.Height() - rect.Height()) / 2.0);
|
||||
if(!screenFrame.Contains(point))
|
||||
point.Set(0, 0);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FindNextMenuInsertionIndex(BMenu *menu, const char *name, int32 index = 0)
|
||||
{
|
||||
BMenuItem *item;
|
||||
for(; index < menu->CountItems(); index++) {
|
||||
item = menu->ItemAt(index);
|
||||
if(item && strcasecmp(name, item->Label()) <= 0)
|
||||
return index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
FindNextListInsertionIndex(BListView *list, const char *name)
|
||||
{
|
||||
int32 index = 0;
|
||||
BStringItem *item;
|
||||
for(; index < list->CountItems(); index++) {
|
||||
item = static_cast<BStringItem*>(list->ItemAt(index));
|
||||
if(item && strcasecmp(name, item->Text()) <= 0)
|
||||
return index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddAddonsToMenu(const BMessage *source, BMenu *menu, const char *type, uint32 what)
|
||||
{
|
||||
DialUpAddon *addon;
|
||||
for(int32 index = 0; source->FindPointer(type, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||
if(!addon || (!addon->FriendlyName() && !addon->TechnicalName()))
|
||||
continue;
|
||||
|
||||
BMessage *message = new BMessage(what);
|
||||
message->AddPointer("Addon", addon);
|
||||
|
||||
BString name;
|
||||
if(addon->TechnicalName()) {
|
||||
name << addon->TechnicalName();
|
||||
if(addon->FriendlyName())
|
||||
name << " (";
|
||||
}
|
||||
if(addon->FriendlyName()) {
|
||||
name << addon->FriendlyName();
|
||||
if(addon->TechnicalName())
|
||||
name << ")";
|
||||
}
|
||||
|
||||
int32 insertAt = FindNextMenuInsertionIndex(menu, name.String());
|
||||
menu->AddItem(new BMenuItem(name.String(), message), insertAt);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _INTERFACE_UTILS__H
|
||||
#define _INTERFACE_UTILS__H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class DialUpAddon;
|
||||
class BListView;
|
||||
class BMenu;
|
||||
class BString;
|
||||
class BWindow;
|
||||
|
||||
|
||||
extern BPoint center_on_screen(BRect rect, BWindow *window = NULL);
|
||||
extern int32 FindNextMenuInsertionIndex(BMenu *menu, const char *name,
|
||||
int32 index = 0);
|
||||
extern int32 FindNextListInsertionIndex(BListView *list, const char *name);
|
||||
extern void AddAddonsToMenu(const BMessage *source, BMenu *menu, const char *type,
|
||||
uint32 what);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests kits net DialUpPreflet ;
|
||||
|
||||
UsePrivateHeaders net ;
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libppp
|
||||
headers ] : true ;
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared
|
||||
libkernelppp headers ] : true ;
|
||||
|
||||
# additonal headers for built-in add-ons:
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp pppoe ]
|
||||
: true ; # PPPoE
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp ipcp ]
|
||||
: true ; # IPCP
|
||||
|
||||
SubDirSysHdrs $(SUBDIR) ;
|
||||
|
||||
AddResources DialUpPreflet : DialUpPreflet.rdef ;
|
||||
|
||||
SimpleTest DialUpPreflet :
|
||||
# Application
|
||||
DialUpApplication.cpp
|
||||
DialUpView.cpp
|
||||
|
||||
# utils (TODO: move some of them into a separate library)
|
||||
InterfaceUtils.cpp
|
||||
TextRequestDialog.cpp
|
||||
PTPSettings.cpp
|
||||
|
||||
# built-in add-ons
|
||||
ConnectionOptionsAddon.cpp
|
||||
GeneralAddon.cpp
|
||||
IPCPAddon.cpp
|
||||
PPPoEAddon.cpp
|
||||
;
|
||||
|
||||
LinkAgainst DialUpPreflet : libppp.a be ;
|
||||
@@ -1,381 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// PPPoEAddon saves the loaded settings.
|
||||
// PPPoEView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "PPPoEAddon.h"
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
#include "TextRequestDialog.h"
|
||||
#include <stl_algobase.h>
|
||||
// for max()
|
||||
|
||||
#include <Box.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include <PPPManager.h>
|
||||
#include <PPPoE.h>
|
||||
// from PPPoE addon
|
||||
|
||||
|
||||
// GUI constants
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
// 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
|
||||
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: ";
|
||||
|
||||
// requests
|
||||
static const char *kRequestInterfaceName = "Network Interface Name: ";
|
||||
|
||||
// add-on descriptions
|
||||
static const char *kFriendlyName = "Broadband: DSL, Cable, etc.";
|
||||
static const char *kTechnicalName = "PPPoE";
|
||||
static const char *kKernelModuleName = "pppoe";
|
||||
|
||||
|
||||
PPPoEAddon::PPPoEAddon(BMessage *addons)
|
||||
: DialUpAddon(addons),
|
||||
fSettings(NULL),
|
||||
fPPPoEView(NULL)
|
||||
{
|
||||
fHeight = 20 // interface name control
|
||||
+ 20 // service control
|
||||
+ 5 + 2; // space between controls and bottom
|
||||
CreateView(BPoint(0,0));
|
||||
}
|
||||
|
||||
|
||||
PPPoEAddon::~PPPoEAddon()
|
||||
{
|
||||
delete fPPPoEView;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
PPPoEAddon::FriendlyName() const
|
||||
{
|
||||
return kFriendlyName;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
PPPoEAddon::TechnicalName() const
|
||||
{
|
||||
return kTechnicalName;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
PPPoEAddon::KernelModuleName() const
|
||||
{
|
||||
return kKernelModuleName;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPoEAddon::LoadSettings(BMessage *settings, bool isNew)
|
||||
{
|
||||
fIsNew = isNew;
|
||||
fInterfaceName = fServiceName = "";
|
||||
fSettings = settings;
|
||||
|
||||
fPPPoEView->Reload();
|
||||
|
||||
if(!settings || isNew)
|
||||
return true;
|
||||
|
||||
BMessage device;
|
||||
int32 deviceIndex = 0;
|
||||
if(!FindMessageParameter(PPP_DEVICE_KEY, *fSettings, &device, &deviceIndex))
|
||||
return false;
|
||||
// error: no device
|
||||
|
||||
BString name;
|
||||
if(device.FindString(MDSU_VALUES, &name) != B_OK || name != kKernelModuleName)
|
||||
return false;
|
||||
// error: no device
|
||||
|
||||
BMessage parameter;
|
||||
int32 index = 0;
|
||||
if(!FindMessageParameter(PPPoE_INTERFACE_KEY, device, ¶meter, &index)
|
||||
|| parameter.FindString(MDSU_VALUES, &fInterfaceName) != B_OK)
|
||||
return false;
|
||||
// error: no interface
|
||||
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)
|
||||
fServiceName = "";
|
||||
else {
|
||||
parameter.AddBool(MDSU_VALID, true);
|
||||
device.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter);
|
||||
}
|
||||
|
||||
device.AddBool(MDSU_VALID, true);
|
||||
fSettings->ReplaceMessage(MDSU_PARAMETERS, deviceIndex, &device);
|
||||
|
||||
fPPPoEView->Reload();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPoEAddon::IsModified(bool *settings) const
|
||||
{
|
||||
if(!fSettings) {
|
||||
*settings = false;
|
||||
return;
|
||||
}
|
||||
|
||||
*settings = (fInterfaceName != fPPPoEView->InterfaceName()
|
||||
|| fServiceName != fPPPoEView->ServiceName());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPoEAddon::SaveSettings(BMessage *settings)
|
||||
{
|
||||
if(!fSettings || !settings || !fPPPoEView->InterfaceName()
|
||||
|| strlen(fPPPoEView->InterfaceName()) == 0)
|
||||
return false;
|
||||
// TODO: tell user that an interface is needed (if we fail because of this)
|
||||
|
||||
BMessage device, interface;
|
||||
device.AddString(MDSU_NAME, PPP_DEVICE_KEY);
|
||||
device.AddString(MDSU_VALUES, kKernelModuleName);
|
||||
|
||||
interface.AddString(MDSU_NAME, PPPoE_INTERFACE_KEY);
|
||||
interface.AddString(MDSU_VALUES, fPPPoEView->InterfaceName());
|
||||
device.AddMessage(MDSU_PARAMETERS, &interface);
|
||||
|
||||
if(fPPPoEView->ServiceName() && strlen(fPPPoEView->ServiceName()) > 0) {
|
||||
// save service name, too
|
||||
BMessage service;
|
||||
service.AddString(MDSU_NAME, PPPoE_SERVICE_NAME_KEY);
|
||||
service.AddString(MDSU_VALUES, fPPPoEView->ServiceName());
|
||||
device.AddMessage(MDSU_PARAMETERS, &service);
|
||||
}
|
||||
|
||||
settings->AddMessage(MDSU_PARAMETERS, &device);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPoEAddon::GetPreferredSize(float *width, float *height) const
|
||||
{
|
||||
float viewWidth;
|
||||
if(Addons()->FindFloat(DUN_DEVICE_VIEW_WIDTH, &viewWidth) != B_OK)
|
||||
viewWidth = 270;
|
||||
// default value
|
||||
|
||||
if(width)
|
||||
*width = viewWidth;
|
||||
if(height)
|
||||
*height = fHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
PPPoEAddon::CreateView(BPoint leftTop)
|
||||
{
|
||||
if(!fPPPoEView) {
|
||||
float width;
|
||||
if(Addons()->FindFloat(DUN_DEVICE_VIEW_WIDTH, &width) != B_OK)
|
||||
width = 270;
|
||||
// default value
|
||||
|
||||
BRect rect(0, 0, width, fHeight);
|
||||
fPPPoEView = new PPPoEView(this, rect);
|
||||
}
|
||||
|
||||
fPPPoEView->MoveTo(leftTop);
|
||||
fPPPoEView->Reload();
|
||||
return fPPPoEView;
|
||||
}
|
||||
|
||||
|
||||
PPPoEView::PPPoEView(PPPoEAddon *addon, BRect frame)
|
||||
: BView(frame, "PPPoEView", B_FOLLOW_NONE, 0),
|
||||
fAddon(addon)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(5, 0);
|
||||
rect.bottom = 20;
|
||||
fInterface = new BMenuField(rect, "interface", kLabelInterfaceName,
|
||||
new BPopUpMenu(kLabelSelectInterface));
|
||||
fInterface->SetDivider(StringWidth(fInterface->Label()) + 5);
|
||||
fInterface->Menu()->AddSeparatorItem();
|
||||
fOtherInterface = new BMenuItem(kLabelOtherInterface,
|
||||
new BMessage(kMsgSelectOther));
|
||||
fInterface->Menu()->AddItem(fOtherInterface);
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
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(fServiceName);
|
||||
}
|
||||
|
||||
|
||||
PPPoEView::~PPPoEView()
|
||||
{
|
||||
Addon()->UnregisterView();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPoEView::Reload()
|
||||
{
|
||||
ReloadInterfaces();
|
||||
fServiceName->SetText(Addon()->ServiceName());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPoEView::AttachedToWindow()
|
||||
{
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
fInterface->Menu()->SetTargetForItems(this);
|
||||
fServiceName->SetTarget(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPoEView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case kMsgSelectInterface: {
|
||||
BMenuItem *item = fInterface->Menu()->FindMarked();
|
||||
if(item)
|
||||
fInterfaceName = item->Label();
|
||||
} break;
|
||||
|
||||
case kMsgSelectOther:
|
||||
(new TextRequestDialog("InterfaceName", NULL, kRequestInterfaceName,
|
||||
fInterfaceName.String()))->Go(new BInvoker(
|
||||
new BMessage(kMsgFinishSelectOther), this));
|
||||
break;
|
||||
|
||||
case kMsgFinishSelectOther: {
|
||||
int32 which;
|
||||
message->FindInt32("which", &which);
|
||||
|
||||
const char *name = message->FindString("text");
|
||||
BMenu *menu = fInterface->Menu();
|
||||
BMenuItem *item;
|
||||
if(which != 1 || !name || strlen(name) == 0) {
|
||||
item = menu->FindItem(fInterfaceName.String());
|
||||
if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
|
||||
item->SetMarked(true);
|
||||
else
|
||||
fOtherInterface->SetMarked(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fInterfaceName = name;
|
||||
|
||||
item = menu->FindItem(fInterfaceName.String());
|
||||
if(item && menu->IndexOf(item) <= menu->CountItems() - 2) {
|
||||
item->SetMarked(true);
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPoEView::ReloadInterfaces()
|
||||
{
|
||||
// delete all items and request a new bunch from the pppoe kernel module
|
||||
BMenu *menu = fInterface->Menu();
|
||||
while(menu->CountItems() > 2)
|
||||
delete menu->RemoveItem((int32) 0);
|
||||
fOtherInterface->SetLabel(kLabelOtherInterface);
|
||||
|
||||
PPPManager manager;
|
||||
char *interfaces = new char[8192];
|
||||
// reserve enough space for approximately 512 entries
|
||||
int32 count = manager.ControlModule("pppoe", PPPoE_GET_INTERFACES, interfaces,
|
||||
8192);
|
||||
|
||||
BMenuItem *item;
|
||||
char *name = interfaces;
|
||||
int32 insertAt;
|
||||
for(int32 index = 0; index < count; index++) {
|
||||
item = new BMenuItem(name, new BMessage(kMsgSelectInterface));
|
||||
insertAt = FindNextMenuInsertionIndex(menu, name);
|
||||
if(insertAt > menu->CountItems() - 2)
|
||||
insertAt = menu->CountItems() - 2;
|
||||
|
||||
item->SetTarget(this);
|
||||
menu->AddItem(item, insertAt);
|
||||
name += strlen(name) + 1;
|
||||
}
|
||||
|
||||
// set interface or some default value if nothing was found
|
||||
if(Addon()->InterfaceName() && strlen(Addon()->InterfaceName()) > 0)
|
||||
fInterfaceName = Addon()->InterfaceName();
|
||||
else if(count > 0)
|
||||
fInterfaceName = interfaces;
|
||||
else
|
||||
fInterfaceName = "";
|
||||
|
||||
delete interfaces;
|
||||
|
||||
item = menu->FindItem(fInterfaceName.String());
|
||||
if(item && menu->IndexOf(item) <= menu->CountItems() - 2)
|
||||
item->SetMarked(true);
|
||||
else if(Addon()->InterfaceName()) {
|
||||
BString label(kLabelOtherInterface);
|
||||
label << " " << fInterfaceName;
|
||||
fOtherInterface->SetLabel(label.String());
|
||||
fOtherInterface->SetMarked(true);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// PPPoEAddon saves the loaded settings.
|
||||
// PPPoEView saves the current settings.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#ifndef _PPPoE_ADDON__H
|
||||
#define _PPPoE_ADDON__H
|
||||
|
||||
#include <DialUpAddon.h>
|
||||
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
class PPPoEView;
|
||||
|
||||
|
||||
class PPPoEAddon : public DialUpAddon {
|
||||
public:
|
||||
PPPoEAddon(BMessage *addons);
|
||||
virtual ~PPPoEAddon();
|
||||
|
||||
bool IsNew() const
|
||||
{ return fIsNew; }
|
||||
|
||||
const char *InterfaceName() const
|
||||
{ return fInterfaceName.String(); }
|
||||
const char *ServiceName() const
|
||||
{ return fServiceName.String(); }
|
||||
|
||||
BMessage *Settings() const
|
||||
{ return fSettings; }
|
||||
|
||||
virtual const char *FriendlyName() const;
|
||||
virtual const char *TechnicalName() const;
|
||||
virtual const char *KernelModuleName() const;
|
||||
|
||||
virtual bool LoadSettings(BMessage *settings, bool isNew);
|
||||
|
||||
virtual void IsModified(bool *settings) const;
|
||||
|
||||
virtual bool SaveSettings(BMessage *settings);
|
||||
virtual bool GetPreferredSize(float *width, float *height) const;
|
||||
virtual BView *CreateView(BPoint leftTop);
|
||||
|
||||
void UnregisterView()
|
||||
{ fPPPoEView = NULL; }
|
||||
|
||||
private:
|
||||
bool fIsNew;
|
||||
BString fInterfaceName, fServiceName;
|
||||
BMessage *fSettings;
|
||||
// saves last settings state
|
||||
PPPoEView *fPPPoEView;
|
||||
float fHeight;
|
||||
// height of PPPoEView
|
||||
};
|
||||
|
||||
|
||||
class PPPoEView : public BView {
|
||||
public:
|
||||
PPPoEView(PPPoEAddon *addon, BRect frame);
|
||||
virtual ~PPPoEView();
|
||||
|
||||
PPPoEAddon *Addon() const
|
||||
{ return fAddon; }
|
||||
void Reload();
|
||||
|
||||
const char *InterfaceName() const
|
||||
{ return fInterfaceName.String(); }
|
||||
const char *ServiceName() const
|
||||
{ return fServiceName->Text(); }
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
void ReloadInterfaces();
|
||||
|
||||
private:
|
||||
PPPoEAddon *fAddon;
|
||||
BMenuField *fInterface;
|
||||
BMenuItem *fOtherInterface;
|
||||
BString fInterfaceName;
|
||||
BTextControl *fServiceName;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <PTPSettings.h>
|
||||
|
||||
#include <PPPDefs.h>
|
||||
#include <PPPManager.h>
|
||||
|
||||
// built-in add-ons
|
||||
#include "ConnectionOptionsAddon.h"
|
||||
#include "GeneralAddon.h"
|
||||
#include "IPCPAddon.h"
|
||||
#include "PPPoEAddon.h"
|
||||
|
||||
#include "MessageDriverSettingsUtils.h"
|
||||
#include <TemplateList.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <File.h>
|
||||
#include <driver_settings.h>
|
||||
|
||||
|
||||
PTPSettings::PTPSettings()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PTPSettings::~PTPSettings()
|
||||
{
|
||||
// free known add-on types (these should free their known add-on types, etc.)
|
||||
DialUpAddon *addon;
|
||||
for(int32 index = 0;
|
||||
fAddons.FindPointer(DUN_DELETE_ON_QUIT, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK;
|
||||
index++)
|
||||
delete addon;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char*
|
||||
PTPSettings::SessionPassword() const
|
||||
{
|
||||
return fGeneralAddon->SessionPassword();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PTPSettings::LoadSettings(const char *interfaceName, bool isNew)
|
||||
{
|
||||
if(interfaceName && strlen(interfaceName) == 0)
|
||||
return false;
|
||||
|
||||
fCurrent = interfaceName ? interfaceName : "";
|
||||
fSettings.MakeEmpty();
|
||||
BMessage *settingsPointer = interfaceName ? &fSettings : NULL;
|
||||
|
||||
if(interfaceName && !isNew) {
|
||||
BString name("ptpnet/");
|
||||
name << fCurrent;
|
||||
if(!ReadMessageDriverSettings(name.String(), &fSettings))
|
||||
return false;
|
||||
}
|
||||
|
||||
DialUpAddon *addon;
|
||||
for(int32 index = 0; fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||
if(!addon)
|
||||
continue;
|
||||
|
||||
if(!addon->LoadSettings(settingsPointer, isNew))
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: check if settings are valid
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PTPSettings::IsModified(bool *settings)
|
||||
{
|
||||
*settings = false;
|
||||
bool addonSettingsChanged;
|
||||
|
||||
DialUpAddon *addon;
|
||||
for(int32 index = 0; fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||
if(!addon)
|
||||
continue;
|
||||
|
||||
addon->IsModified(&addonSettingsChanged);
|
||||
if(addonSettingsChanged)
|
||||
*settings = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PTPSettings::SaveSettings(BMessage *settings)
|
||||
{
|
||||
if(fCurrent.Length() == 0 || !settings)
|
||||
return false;
|
||||
|
||||
DialUpAddon *addon;
|
||||
TemplateList<DialUpAddon*> addons;
|
||||
for(int32 index = 0;
|
||||
fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index,
|
||||
reinterpret_cast<void**>(&addon)) == B_OK; index++) {
|
||||
if(!addon)
|
||||
continue;
|
||||
|
||||
int32 insertIndex = 0;
|
||||
for(; insertIndex < addons.CountItems(); insertIndex++)
|
||||
if(addons.ItemAt(insertIndex)->Priority() <= addon->Priority())
|
||||
break;
|
||||
|
||||
addons.AddItem(addon, insertIndex);
|
||||
}
|
||||
|
||||
// prepare for next release with support different PTP types
|
||||
BMessage parameter;
|
||||
parameter.AddString(MDSU_NAME, "PTPType");
|
||||
parameter.AddString(MDSU_VALUES, "ppp");
|
||||
settings->AddMessage(MDSU_PARAMETERS, ¶meter);
|
||||
settings->AddString("InterfaceName", fCurrent);
|
||||
|
||||
for(int32 index = 0; index < addons.CountItems(); index++)
|
||||
if(!addons.ItemAt(index)->SaveSettings(settings))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PTPSettings::SaveSettingsToFile()
|
||||
{
|
||||
bool settingsChanged;
|
||||
IsModified(&settingsChanged);
|
||||
if(!settingsChanged)
|
||||
return true;
|
||||
|
||||
BMessage settings;
|
||||
if(!SaveSettings(&settings))
|
||||
return false;
|
||||
|
||||
BDirectory settingsDirectory;
|
||||
if(!PPPManager::GetSettingsDirectory(&settingsDirectory))
|
||||
return false;
|
||||
|
||||
BFile file;
|
||||
if(settingsChanged) {
|
||||
settingsDirectory.CreateFile(fCurrent.String(), &file);
|
||||
WriteMessageDriverSettings(file, settings);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PTPSettings::LoadAddons()
|
||||
{
|
||||
// Load built-in add-ons:
|
||||
// "Connection Options" tab
|
||||
ConnectionOptionsAddon *connectionOptionsAddon =
|
||||
new ConnectionOptionsAddon(&fAddons);
|
||||
fAddons.AddPointer(DUN_TAB_ADDON_TYPE, connectionOptionsAddon);
|
||||
fAddons.AddPointer(DUN_DELETE_ON_QUIT, connectionOptionsAddon);
|
||||
// "General" tab
|
||||
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_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);
|
||||
|
||||
// "PAP" authenticator
|
||||
BMessage addon;
|
||||
addon.AddString("FriendlyName", "Plain-text Authentication");
|
||||
addon.AddString("TechnicalName", "PAP");
|
||||
addon.AddString("KernelModuleName", "pap");
|
||||
fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon);
|
||||
// addon.MakeEmpty(); // for next authenticator
|
||||
|
||||
// TODO: load all add-ons from the add-ons folder
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _PTP_SETTINGS__H
|
||||
#define _PTP_SETTINGS__H
|
||||
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class GeneralAddon;
|
||||
|
||||
|
||||
class PTPSettings {
|
||||
public:
|
||||
PTPSettings();
|
||||
~PTPSettings();
|
||||
|
||||
BMessage& Addons()
|
||||
{ return fAddons; }
|
||||
const BString& CurrentInterface() const
|
||||
{ return fCurrent; }
|
||||
const char *SessionPassword() const;
|
||||
|
||||
bool LoadSettings(const char *interfaceName, bool isNew);
|
||||
void IsModified(bool *settings);
|
||||
bool SaveSettings(BMessage *settings);
|
||||
bool SaveSettingsToFile();
|
||||
|
||||
void LoadAddons();
|
||||
// must be called manually
|
||||
|
||||
private:
|
||||
BMessage fAddons, fSettings;
|
||||
BString fCurrent;
|
||||
GeneralAddon *fGeneralAddon;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,12 +0,0 @@
|
||||
Short-term TODOs:
|
||||
- add "Revert Changes" button
|
||||
- IPCP: check for incorrect settings (only IP addresses should be entered)
|
||||
- PPPoE: refresh interfaces list every second or so
|
||||
- ConnectionOptions: add field for entering number of connect retries and delay between retries
|
||||
|
||||
Mid-term TODOs:
|
||||
- load add-ons from /boot/home/config/add-ons/ptp
|
||||
|
||||
Long-term TODOs:
|
||||
- (maybe) allow selecting multiple authenticators (in expert-mode)
|
||||
- move DEVNOTES into a doxygen file and document the rest of the API
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "TextRequestDialog.h"
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
#include <Button.h>
|
||||
#include <TextControl.h>
|
||||
#include <TextView.h>
|
||||
|
||||
|
||||
// GUI constants
|
||||
static const uint32 kWindowWidth = 250;
|
||||
static const uint32 kWindowHeight = 10 + 20 + 10 + 25 + 5;
|
||||
static const BRect kWindowRect(0, 0, kWindowWidth, kWindowHeight);
|
||||
static const uint32 kDefaultButtonWidth = 80;
|
||||
|
||||
// message constants
|
||||
static const uint32 kMsgButton = 'MBTN';
|
||||
static const uint32 kMsgUpdateControls = 'UCTL';
|
||||
|
||||
// labels
|
||||
static const char *kLabelOK = "OK";
|
||||
static const char *kLabelCancel = "Cancel";
|
||||
|
||||
|
||||
TextRequestDialog::TextRequestDialog(const char *title, const char *information,
|
||||
const char *request, const char *text = NULL)
|
||||
: BWindow(kWindowRect, title, B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE, 0),
|
||||
fInvoker(NULL)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
BView *backgroundView = new BView(rect, "background", B_FOLLOW_ALL_SIDES, 0);
|
||||
backgroundView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
rect.InsetBy(5, 5);
|
||||
rect.bottom = rect.top;
|
||||
// init
|
||||
|
||||
if(information) {
|
||||
BRect textRect(rect);
|
||||
textRect.OffsetTo(0, 0);
|
||||
fTextView = new BTextView(rect, "TextView", textRect, B_FOLLOW_NONE,
|
||||
B_WILL_DRAW);
|
||||
fTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
fTextView->MakeSelectable(false);
|
||||
fTextView->MakeEditable(false);
|
||||
fTextView->SetText(information);
|
||||
float textHeight = fTextView->TextHeight(0, fTextView->CountLines());
|
||||
backgroundView->ResizeBy(0, textHeight + 5);
|
||||
ResizeBy(0, textHeight + 5);
|
||||
fTextView->ResizeBy(0, textHeight - textRect.Height());
|
||||
rect.bottom += textHeight + 5;
|
||||
backgroundView->AddChild(fTextView);
|
||||
} else
|
||||
fTextView = NULL;
|
||||
|
||||
rect.top = rect.bottom + 5;
|
||||
rect.bottom = rect.top + 20;
|
||||
fTextControl = new BTextControl(rect, "request", request, text, NULL);
|
||||
fTextControl->SetModificationMessage(new BMessage(kMsgUpdateControls));
|
||||
fTextControl->SetDivider(fTextControl->StringWidth(fTextControl->Label()) + 5);
|
||||
if(text && strlen(text) > 0)
|
||||
fTextControl->TextView()->SelectAll();
|
||||
|
||||
rect.top = rect.bottom + 10;
|
||||
rect.bottom = rect.top + 25;
|
||||
rect.left = rect.right - kDefaultButtonWidth;
|
||||
BMessage message(kMsgButton);
|
||||
message.AddInt32("which", 1);
|
||||
fOKButton = new BButton(rect, "okButton", kLabelOK, new BMessage(message));
|
||||
rect.right = rect.left - 10;
|
||||
rect.left = rect.right - kDefaultButtonWidth;
|
||||
message.ReplaceInt32("which", 0);
|
||||
BButton *cancelButton = new BButton(rect, "cancelButton", kLabelCancel,
|
||||
new BMessage(message));
|
||||
backgroundView->AddChild(cancelButton);
|
||||
backgroundView->AddChild(fOKButton);
|
||||
backgroundView->AddChild(fTextControl);
|
||||
AddChild(backgroundView);
|
||||
|
||||
fTextControl->MakeFocus(true);
|
||||
SetDefaultButton(fOKButton);
|
||||
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
|
||||
TextRequestDialog::~TextRequestDialog()
|
||||
{
|
||||
delete fInvoker;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextRequestDialog::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case kMsgButton: {
|
||||
if(!fInvoker || !fInvoker->Message())
|
||||
return;
|
||||
|
||||
int32 which;
|
||||
message->FindInt32("which", &which);
|
||||
BMessage toSend(*fInvoker->Message());
|
||||
toSend.AddInt32("which", which);
|
||||
if(which == 1)
|
||||
toSend.AddString("text", fTextControl->Text());
|
||||
|
||||
fInvoker->Invoke(&toSend);
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
} break;
|
||||
|
||||
case kMsgUpdateControls:
|
||||
UpdateControls();
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TextRequestDialog::QuitRequested()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TextRequestDialog::Go(BInvoker *invoker)
|
||||
{
|
||||
fInvoker = invoker;
|
||||
MoveTo(center_on_screen(Bounds()));
|
||||
Show();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextRequestDialog::UpdateControls()
|
||||
{
|
||||
fOKButton->SetEnabled(fTextControl->TextView()->TextLength() > 0);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _TEXT_REQUEST_CONNECTOG__H
|
||||
#define _TEXT_REQUEST_CONNECTOG__H
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
class TextRequestDialog : public BWindow {
|
||||
public:
|
||||
TextRequestDialog(const char *title, const char *information,
|
||||
const char *request, const char *text = NULL);
|
||||
virtual ~TextRequestDialog();
|
||||
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
status_t Go(BInvoker *invoker);
|
||||
|
||||
private:
|
||||
void UpdateControls();
|
||||
|
||||
private:
|
||||
BTextView *fTextView;
|
||||
// displays information text
|
||||
BButton *fOKButton;
|
||||
BTextControl *fTextControl;
|
||||
BInvoker *fInvoker;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -33,7 +33,6 @@ SimpleTest NetEndpointTest : NetEndpointTest.cpp
|
||||
SimpleTest wlan_test : wlan_test.cpp : $(TARGET_NETWORK_LIBS) bnetapi be ;
|
||||
|
||||
SubInclude HAIKU_TOP src tests kits net cookie ;
|
||||
SubInclude HAIKU_TOP src tests kits net DialUpPreflet ;
|
||||
SubInclude HAIKU_TOP src tests kits net icmp ;
|
||||
SubInclude HAIKU_TOP src tests kits net ipv6 ;
|
||||
HaikuSubInclude libnetapi ;
|
||||
|
||||
Reference in New Issue
Block a user