From 7932407f2523acbb34fb14442670e83197ec1d92 Mon Sep 17 00:00:00 2001 From: Waldemar Kornewald Date: Wed, 31 Mar 2004 11:39:47 +0000 Subject: [PATCH] Added "Extras" tab for setting dial-on-demand and auto-redial. Some changes to the UI. This preflet should finally be usable and support the most important features (devices, authenticators, protocols). Currently, there is only support for PPPoE, PAP, and IPCP. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7131 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kits/net/DialUpPreflet/DialUpView.cpp | 84 ++++-- src/tests/kits/net/DialUpPreflet/DialUpView.h | 6 +- .../kits/net/DialUpPreflet/ExtrasAddon.cpp | 250 ++++++++++++++++++ .../kits/net/DialUpPreflet/ExtrasAddon.h | 88 ++++++ .../kits/net/DialUpPreflet/GeneralAddon.cpp | 25 +- .../kits/net/DialUpPreflet/GeneralAddon.h | 2 +- .../kits/net/DialUpPreflet/IPCPAddon.cpp | 13 +- src/tests/kits/net/DialUpPreflet/Jamfile | 1 + .../kits/net/DialUpPreflet/PPPoEAddon.cpp | 23 +- .../kits/net/DialUpPreflet/ProtocolsAddon.cpp | 28 ++ .../kits/net/DialUpPreflet/ProtocolsAddon.h | 1 + src/tests/kits/net/DialUpPreflet/TODO | 5 +- 12 files changed, 478 insertions(+), 48 deletions(-) create mode 100644 src/tests/kits/net/DialUpPreflet/ExtrasAddon.cpp create mode 100644 src/tests/kits/net/DialUpPreflet/ExtrasAddon.h diff --git a/src/tests/kits/net/DialUpPreflet/DialUpView.cpp b/src/tests/kits/net/DialUpPreflet/DialUpView.cpp index b88b910f08..e97b2f87f0 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpView.cpp +++ b/src/tests/kits/net/DialUpPreflet/DialUpView.cpp @@ -14,6 +14,7 @@ #include "TextRequestDialog.h" // built-in add-ons +#include "ExtrasAddon.h" #include "GeneralAddon.h" #include "IPCPAddon.h" #include "PPPoEAddon.h" @@ -60,7 +61,7 @@ #define TEXT_AUTHENTICATION_FAILED "Authentication failed!" #define TEXT_CONNECTION_LOST "Connection lost!" #define TEXT_CREATION_ERROR "Error creating interface!" -#define TEXT_NO_INTERFACE_SELECTED "No interface selected..." +#define TEXT_NO_INTERFACES_FOUND "No interfaces found..." #define TEXT_OK "OK" #define ERROR_TITLE "Error" #define ERROR_NO_PPP_STACK "Error: Could not find the PPP stack!" @@ -68,6 +69,7 @@ "exists!" #define ERROR_LOADING_FAILED "Error: Failed loading interface! The current " \ "settings will be deleted." +#define ERROR_SAVING_FAILED "Error: Failed saving interface settings!" static @@ -108,11 +110,19 @@ DialUpView::DialUpView(BRect frame) rect.bottom = bounds.bottom - 20 // height of bottom controls - 20; // space for bottom controls - fTabView = new BTabView(rect, "TabView"); - BRect tabViewRect = fTabView->Bounds(); + fTabView = new BTabView(rect, "TabView", B_WIDTH_FROM_LABEL); + BRect tabViewRect(fTabView->Bounds()); tabViewRect.bottom -= fTabView->TabHeight(); fAddons.AddRect(DUN_TAB_VIEW_RECT, tabViewRect); + BRect stringRect(rect); + stringRect.top += (stringRect.Height() - 15) / 2; + stringRect.bottom = stringRect.top + 15; + fStringView = new BStringView(stringRect, "NoInterfacesFound", + TEXT_NO_INTERFACES_FOUND); + fStringView->SetAlignment(B_ALIGN_CENTER); + fStringView->Hide(); + rect.top = rect.bottom + 15; rect.bottom = rect.top + 15; rect.right = rect.left + 200; @@ -126,6 +136,7 @@ DialUpView::DialUpView(BRect frame) AddChild(fMenuField); AddChild(fTabView); + AddChild(fStringView); AddChild(fStatusView); AddChild(fConnectButton); @@ -136,6 +147,7 @@ DialUpView::DialUpView(BRect frame) fCurrentItem = NULL; // reset, otherwise SelectInterface will not load the settings SelectInterface(0); + UpdateControls(); } @@ -194,6 +206,9 @@ DialUpView::MessageReceived(BMessage *message) // ------------------------------------------------- case MSG_DELETE_CURRENT: { + if(!fCurrentItem) + return; + fInterfaceMenu->RemoveItem(fCurrentItem); BDirectory settings, profile; GetPPPDirectories(&settings, &profile); @@ -205,10 +220,13 @@ DialUpView::MessageReceived(BMessage *message) delete fCurrentItem; fCurrentItem = NULL; - if(CountInterfaces() == 0) - fInterfaceMenu->SetRadioMode(false); - else - SelectInterface(0); + BMenuItem *marked = fInterfaceMenu->FindMarked(); + if(marked) + marked->SetMarked(false); + + UpdateControls(); + SelectInterface(0); + // this stops watching the deleted interface } break; case MSG_SELECT_INTERFACE: { @@ -316,7 +334,8 @@ DialUpView::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempora settings->AddString("InterfaceName", fCurrentItem->Label()); for(int32 index = 0; index < addons.CountItems(); index++) - addons.ItemAt(index)->SaveSettings(settings, profile, saveTemporary); + if(!addons.ItemAt(index)->SaveSettings(settings, profile, saveTemporary)) + return false; return true; } @@ -595,8 +614,9 @@ DialUpView::LoadInterfaces() fInterfaceMenu->AddSeparatorItem(); fInterfaceMenu->AddItem(new BMenuItem(LABEL_CREATE_NEW, new BMessage(MSG_CREATE_NEW))); - fInterfaceMenu->AddItem(new BMenuItem(LABEL_DELETE_CURRENT, - new BMessage(MSG_DELETE_CURRENT))); + fDeleterItem = new BMenuItem(LABEL_DELETE_CURRENT, + new BMessage(MSG_DELETE_CURRENT)); + fInterfaceMenu->AddItem(fDeleterItem); BDirectory settingsDirectory; BEntry entry; @@ -615,6 +635,10 @@ void DialUpView::LoadAddons() { // Load integrated add-ons: + // "Extras" tab + ExtrasAddon *extrasAddon = new ExtrasAddon(&fAddons); + fAddons.AddPointer(DUN_TAB_ADDON_TYPE, extrasAddon); + fAddons.AddPointer(DUN_DELETE_ON_QUIT, extrasAddon); // "General" tab GeneralAddon *generalAddon = new GeneralAddon(&fAddons); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, generalAddon); @@ -631,6 +655,7 @@ DialUpView::LoadAddons() ProtocolsAddon *protocolsAddon = new ProtocolsAddon(&fAddons); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, protocolsAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, protocolsAddon); + // "PAP" authenticator BMessage addon; addon.AddString("KernelModuleName", "pap"); @@ -658,8 +683,8 @@ DialUpView::AddInterface(const char *name, bool isNew = false) if(index > CountInterfaces()) index = CountInterfaces(); fInterfaceMenu->AddItem(item, index); - if(CountInterfaces() == 1) - fInterfaceMenu->SetLabelFromMarked(true); + UpdateControls(); + item->SetMarked(true); SelectInterface(index, isNew); } @@ -672,7 +697,8 @@ DialUpView::SelectInterface(int32 index, bool isNew = false) if(fCurrentItem && item == fCurrentItem) return; - SaveSettingsToFile(); + if(fCurrentItem && !SaveSettingsToFile()) + (new BAlert(ERROR_TITLE, ERROR_SAVING_FAILED, TEXT_OK))->Go(NULL); if(index >= CountInterfaces() || index < 0) { if(CountInterfaces() > 0) @@ -682,11 +708,6 @@ DialUpView::SelectInterface(int32 index, bool isNew = false) WatchInterface(PPP_UNDEFINED_INTERFACE_ID); } } else { - if(!fCurrentItem) { - fTabView->Show(); - fConnectButton->SetEnabled(true); - } - fCurrentItem = fInterfaceMenu->ItemAt(index); if(!fCurrentItem) { SelectInterface(0); @@ -694,16 +715,14 @@ DialUpView::SelectInterface(int32 index, bool isNew = false) } fCurrentItem->SetMarked(true); + fDeleterItem->SetEnabled(true); WatchInterface(fListener.Manager().InterfaceWithName(fCurrentItem->Label())); } - if(!fCurrentItem) { + if(!fCurrentItem) LoadSettings(false); // tell modules to unload all settings - - fTabView->Hide(); - fConnectButton->SetEnabled(false); - } else if(!isNew && !LoadSettings(false)) { + else if(!isNew && !LoadSettings(false)) { (new BAlert(ERROR_TITLE, ERROR_LOADING_FAILED, TEXT_OK))->Go(NULL); LoadSettings(true); } else if(isNew && !LoadSettings(true)) @@ -716,3 +735,22 @@ DialUpView::CountInterfaces() const { return fInterfaceMenu->CountItems() - 3; } + + +void +DialUpView::UpdateControls() +{ + if(fTabView->IsHidden() && CountInterfaces() > 0) { + fInterfaceMenu->SetLabelFromMarked(true); + fStringView->Hide(); + fTabView->Show(); + fConnectButton->SetEnabled(true); + } else if(!fTabView->IsHidden() && CountInterfaces() == 0) { + fDeleterItem->SetEnabled(false); + fInterfaceMenu->SetRadioMode(false); + fInterfaceMenu->Superitem()->SetLabel(LABEL_CREATE_NEW); + fTabView->Hide(); + fStringView->Show(); + fConnectButton->SetEnabled(false); + } +} diff --git a/src/tests/kits/net/DialUpPreflet/DialUpView.h b/src/tests/kits/net/DialUpPreflet/DialUpView.h index cfe9543e2a..4230273c6e 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpView.h +++ b/src/tests/kits/net/DialUpPreflet/DialUpView.h @@ -45,6 +45,8 @@ class DialUpView : public BView { void AddInterface(const char *name, bool isNew = false); void SelectInterface(int32 index, bool isNew = false); int32 CountInterfaces() const; + + void UpdateControls(); private: PPPInterfaceListener fListener; @@ -53,7 +55,7 @@ class DialUpView : public BView { BMessage fAddons, fSettings, fProfile; driver_settings *fDriverSettings; - BMenuItem *fCurrentItem; + BMenuItem *fCurrentItem, *fDeleterItem; ppp_interface_id fWatching; bool fKeepLabel; @@ -61,6 +63,8 @@ class DialUpView : public BView { BButton *fConnectButton; BPopUpMenu *fInterfaceMenu; BMenuField *fMenuField; + BStringView *fStringView; + // shows "No interfaces found..." notice BTabView *fTabView; }; diff --git a/src/tests/kits/net/DialUpPreflet/ExtrasAddon.cpp b/src/tests/kits/net/DialUpPreflet/ExtrasAddon.cpp new file mode 100644 index 0000000000..94d3444f03 --- /dev/null +++ b/src/tests/kits/net/DialUpPreflet/ExtrasAddon.cpp @@ -0,0 +1,250 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- +// ExtrasAddon saves the loaded settings. +// ExtrasView saves the current settings. +//----------------------------------------------------------------------- + +#include "ExtrasAddon.h" + +#include "MessageDriverSettingsUtils.h" + +#include +#include + + +#define MSG_UPDATE_CONTROLS 'UPDC' + + +ExtrasAddon::ExtrasAddon(BMessage *addons) + : DialUpAddon(addons), + fSettings(NULL), + fProfile(NULL), + fExtrasView(NULL) +{ +} + + +ExtrasAddon::~ExtrasAddon() +{ +} + + +bool +ExtrasAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) +{ + fIsNew = isNew; + fDoesDialOnDemand = fAskBeforeDialing = fDoesAutoRedial = false; + fSettings = settings; + fProfile = profile; + + if(fExtrasView) + fExtrasView->Reload(); + // reset all views (empty settings) + + if(!settings || !profile || isNew) + return true; + + BMessage parameter; + int32 index = 0; + const char *value; + if(FindMessageParameter(PPP_DIAL_ON_DEMAND_KEY, *fSettings, ¶meter, &index) + && parameter.FindString(MDSU_VALUES, &value) == B_OK) { + if(get_boolean_value(value, false)) + fDoesDialOnDemand = true; + + parameter.AddBool(MDSU_VALID, true); + fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); + } + + index = 0; + if(FindMessageParameter(PPP_ASK_BEFORE_DIALING_KEY, *fSettings, ¶meter, &index) + && parameter.FindString(MDSU_VALUES, &value) == B_OK) { + if(get_boolean_value(value, false)) + fAskBeforeDialing = true; + + parameter.AddBool(MDSU_VALID, true); + fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); + } + + index = 0; + if(FindMessageParameter(PPP_AUTO_REDIAL_KEY, *fSettings, ¶meter, &index) + && parameter.FindString(MDSU_VALUES, &value) == B_OK) { + if(get_boolean_value(value, false)) + fDoesAutoRedial = true; + + parameter.AddBool(MDSU_VALID, true); + fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); + } + + if(fExtrasView) + fExtrasView->Reload(); + // reload new settings + + return true; +} + + +void +ExtrasAddon::IsModified(bool *settings, bool *profile) const +{ + *settings = *profile = false; + + if(!fSettings || !fExtrasView) + return; + + *settings = DoesDialOnDemand() != fExtrasView->DoesDialOnDemand() + || AskBeforeDialing() != fExtrasView->AskBeforeDialing() + || DoesAutoRedial() != fExtrasView->DoesAutoRedial(); +} + + +bool +ExtrasAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) +{ + if(!fSettings || !settings) + return false; + + BMessage parameter; + if(fExtrasView->DoesDialOnDemand()) { + parameter.MakeEmpty(); + parameter.AddString(MDSU_NAME, PPP_DIAL_ON_DEMAND_KEY); + parameter.AddString(MDSU_VALUES, "enabled"); + settings->AddMessage(MDSU_PARAMETERS, ¶meter); + + if(fExtrasView->AskBeforeDialing()) { + parameter.MakeEmpty(); + parameter.AddString(MDSU_NAME, PPP_ASK_BEFORE_DIALING_KEY); + parameter.AddString(MDSU_VALUES, "enabled"); + settings->AddMessage(MDSU_PARAMETERS, ¶meter); + } + } + + if(fExtrasView->DoesAutoRedial()) { + parameter.MakeEmpty(); + parameter.AddString(MDSU_NAME, PPP_AUTO_REDIAL_KEY); + parameter.AddString(MDSU_VALUES, "enabled"); + settings->AddMessage(MDSU_PARAMETERS, ¶meter); + } + + return true; +} + + +bool +ExtrasAddon::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* +ExtrasAddon::CreateView(BPoint leftTop) +{ + if(!fExtrasView) { + BRect rect; + Addons()->FindRect(DUN_TAB_VIEW_RECT, &rect); + fExtrasView = new ExtrasView(this, rect); + fExtrasView->Reload(); + } + + fExtrasView->MoveTo(leftTop); + return fExtrasView; +} + + +ExtrasView::ExtrasView(ExtrasAddon *addon, BRect frame) + : BView(frame, "Extras", B_FOLLOW_NONE, 0), + fAddon(addon) +{ + BRect rect = Bounds(); + rect.InsetBy(10, 10); + rect.bottom = rect.top + 15; + fDialOnDemand = new BRadioButton(rect, "DialOnDemand", "Dial On Demand", + new BMessage(MSG_UPDATE_CONTROLS)); + rect.top = rect.bottom + 3; + rect.bottom = rect.top + 15; + rect.left += 15; + fAskBeforeDialing = new BCheckBox(rect, "AskBeforeDialing", "Ask Before Dialing", + NULL); + rect.left -= 15; + rect.top = rect.bottom + 5; + rect.bottom = rect.top + 15; + fDialManually = new BRadioButton(rect, "DialManually", "Dial Manually", + new BMessage(MSG_UPDATE_CONTROLS)); + rect.top = rect.bottom + 20; + rect.bottom = rect.top + 15; + fAutoRedial = new BCheckBox(rect, "AutoRedial", "Auto-Redial", NULL); + + AddChild(fDialOnDemand); + AddChild(fAskBeforeDialing); + AddChild(fDialManually); + AddChild(fAutoRedial); +} + + +void +ExtrasView::Reload() +{ + if(Addon()->DoesDialOnDemand() || Addon()->IsNew()) + fDialOnDemand->SetValue(1); + else + fDialManually->SetValue(1); + + fAskBeforeDialing->SetValue(Addon()->AskBeforeDialing()); + fAutoRedial->SetValue(Addon()->DoesAutoRedial()); + + if(!Addon()->Settings()) + return; + + UpdateControls(); +} + + +void +ExtrasView::AttachedToWindow() +{ + SetViewColor(Parent()->ViewColor()); + fDialOnDemand->SetTarget(this); + fDialManually->SetTarget(this); +} + + +void +ExtrasView::MessageReceived(BMessage *message) +{ + switch(message->what) { + case MSG_UPDATE_CONTROLS: + UpdateControls(); + break; + + default: + BView::MessageReceived(message); + } +} + + +void +ExtrasView::UpdateControls() +{ + if(fDialManually->Value()) + fAskBeforeDialing->SetEnabled(false); + else + fAskBeforeDialing->SetEnabled(true); + + fAskBeforeDialing->SetValue(1); + // this should be enabled by default +} diff --git a/src/tests/kits/net/DialUpPreflet/ExtrasAddon.h b/src/tests/kits/net/DialUpPreflet/ExtrasAddon.h new file mode 100644 index 0000000000..d8d18c6a10 --- /dev/null +++ b/src/tests/kits/net/DialUpPreflet/ExtrasAddon.h @@ -0,0 +1,88 @@ +//----------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de +//----------------------------------------------------------------------- +// ExtrasAddon saves the loaded settings. +// ExtrasView saves the current settings. +//----------------------------------------------------------------------- + +#ifndef _EXTRAS_ADDON__H +#define _EXTRAS_ADDON__H + +#include + +#include +#include + +class ExtrasView; + + +class ExtrasAddon : public DialUpAddon { + public: + ExtrasAddon(BMessage *addons); + virtual ~ExtrasAddon(); + + bool IsNew() const + { return fIsNew; } + + bool DoesDialOnDemand() const + { return fDoesDialOnDemand; } + bool AskBeforeDialing() const + { return fAskBeforeDialing; } + bool DoesAutoRedial() const + { return fDoesAutoRedial; } + + BMessage *Settings() const + { return fSettings; } + BMessage *Profile() const + { return fProfile; } + + virtual int32 Position() const + { return 50; } + virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); + virtual void IsModified(bool *settings, bool *profile) const; + virtual bool SaveSettings(BMessage *settings, BMessage *profile, + bool saveTemporary); + virtual bool GetPreferredSize(float *width, float *height) const; + virtual BView *CreateView(BPoint leftTop); + + private: + bool fIsNew; + bool fDoesDialOnDemand, fAskBeforeDialing, fDoesAutoRedial; + BMessage *fSettings, *fProfile; + // saves last settings state + ExtrasView *fExtrasView; +}; + + +class ExtrasView : public BView { + public: + ExtrasView(ExtrasAddon *addon, BRect frame); + + ExtrasAddon *Addon() const + { return fAddon; } + void Reload(); + + bool DoesDialOnDemand() const + { return fDialOnDemand->Value(); } + bool AskBeforeDialing() const + { return fAskBeforeDialing->Value(); } + bool DoesAutoRedial() const + { return fAutoRedial->Value(); } + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage *message); + + private: + void UpdateControls(); + + private: + ExtrasAddon *fAddon; + BCheckBox *fAskBeforeDialing, *fAutoRedial; + BRadioButton *fDialOnDemand, *fDialManually; +}; + + +#endif diff --git a/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp b/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp index a8b917ef57..5e13c0eb08 100644 --- a/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp @@ -33,6 +33,10 @@ #define GENERAL_TAB_AUTHENTICATORS "Authenticators" +#define DEFAULT_AUTHENTICATOR "PAP" + // this authenticator is selected by default when creating a new interface + + GeneralAddon::GeneralAddon(BMessage *addons) : DialUpAddon(addons), fHasPassword(false), @@ -424,9 +428,12 @@ GeneralView::Reload() break; } - if(fDeviceAddon && fDeviceAddon == Addon()->DeviceAddon()) { + if(fDeviceAddon && fDeviceAddon == Addon()->DeviceAddon()) item->SetMarked(true); - ReloadDeviceView(); + else if(Addon()->IsNew() && fDeviceField->Menu()->CountItems() > 0) { + item = fDeviceField->Menu()->ItemAt(0); + item->SetMarked(true); + item->Message()->FindPointer("Addon", reinterpret_cast(&fDeviceAddon)); } else { fDeviceAddon = NULL; item = fDeviceField->Menu()->FindMarked(); @@ -434,6 +441,8 @@ GeneralView::Reload() item->SetMarked(false); } + ReloadDeviceView(); + if(Addon()->CountAuthenticators() > 0) { BString kernelModule, authenticator; BMessage authentication; @@ -450,7 +459,9 @@ GeneralView::Reload() break; } } - } else + } else if(Addon()->IsNew() && fAuthenticatorDefault) + fAuthenticatorDefault->SetMarked(true); + else fAuthenticatorNone->SetMarked(true); fUsername->SetText(Addon()->Username()); @@ -604,11 +615,13 @@ GeneralView::AddDevices() void GeneralView::AddAuthenticators() { + fAuthenticatorDefault = NULL; fAuthenticatorNone = new BMenuItem("None", new BMessage(MSG_SELECT_AUTHENTICATOR)); 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, @@ -634,7 +647,9 @@ GeneralView::AddAuthenticators() int32 insertAt = FindNextMenuInsertionIndex(fAuthenticatorField->Menu(), name.String(), 2); - fAuthenticatorField->Menu()->AddItem(new BMenuItem(name.String(), message), - insertAt); + item = new BMenuItem(name.String(), message); + if(hasTechnicalName && technicalName == DEFAULT_AUTHENTICATOR) + fAuthenticatorDefault = item; + fAuthenticatorField->Menu()->AddItem(item, insertAt); } } diff --git a/src/tests/kits/net/DialUpPreflet/GeneralAddon.h b/src/tests/kits/net/DialUpPreflet/GeneralAddon.h index 5f23b38150..2cce75a519 100644 --- a/src/tests/kits/net/DialUpPreflet/GeneralAddon.h +++ b/src/tests/kits/net/DialUpPreflet/GeneralAddon.h @@ -121,7 +121,7 @@ class GeneralView : public BView { DialUpAddon *fDeviceAddon; BBox *fDeviceBox, *fAuthenticationBox; BMenuField *fDeviceField, *fAuthenticatorField; - BMenuItem *fAuthenticatorNone; + BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault; BTextControl *fUsername, *fPassword; BCheckBox *fSavePassword; }; diff --git a/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp b/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp index 59cd1c5388..1eb0ba78a6 100644 --- a/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp @@ -22,6 +22,8 @@ // from IPCP addon +#define BUTTON_WIDTH 80 + #define MSG_CHANGE_SETTINGS 'CHGS' #define MSG_RESET_SETTINGS 'RSTS' @@ -38,7 +40,7 @@ IPCPAddon::IPCPAddon(BMessage *addons) { float windowHeight = 3 * 20 // text controls + 35 // buttons - + 5 * 5 + 10 + 20; // space between controls and bottom + + 4 * 5 + 10 + 20; // space between controls and bottom BRect rect(350, 250, 650, 250 + windowHeight); fIPCPWindow = new IPCPWindow(this, rect); } @@ -306,13 +308,12 @@ IPCPWindow::IPCPWindow(IPCPAddon *addon, BRect frame) rect = ipcpBox->Frame(); rect.top = rect.bottom + 10; rect.bottom = rect.top + 25; - float buttonWidth = (rect.Width() - 10) / 2; - rect.right = rect.left + buttonWidth; + rect.left = rect.right - BUTTON_WIDTH; + fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SETTINGS)); + rect.right = rect.left - 10; + rect.left = rect.right - BUTTON_WIDTH; fCancelButton = new BButton(rect, "CancelButton", "Cancel", new BMessage(MSG_RESET_SETTINGS)); - rect.left = rect.right + 10; - rect.right = rect.left + buttonWidth; - fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SETTINGS)); ipcpBox->AddChild(fIPAddress); ipcpBox->AddChild(fPrimaryDNS); diff --git a/src/tests/kits/net/DialUpPreflet/Jamfile b/src/tests/kits/net/DialUpPreflet/Jamfile index e86b768023..106d81d9dc 100644 --- a/src/tests/kits/net/DialUpPreflet/Jamfile +++ b/src/tests/kits/net/DialUpPreflet/Jamfile @@ -18,6 +18,7 @@ SimpleTest DialUpPreflet : TextRequestDialog.cpp # built-in add-ons + ExtrasAddon.cpp GeneralAddon.cpp IPCPAddon.cpp PPPoEAddon.cpp diff --git a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp index 7eaa2a73f5..343888f62e 100644 --- a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp @@ -29,6 +29,7 @@ #include // from PPPoE addon +#define BUTTON_WIDTH 80 #define MSG_SELECT_INTERFACE 'SELI' #define MSG_SELECT_OTHER 'SELO' @@ -289,13 +290,12 @@ PPPoEView::PPPoEView(PPPoEAddon *addon, BRect frame) rect = serviceBox->Frame(); rect.top = rect.bottom + 10; rect.bottom = rect.top + 25; - float buttonWidth = (rect.Width() - 10) / 2; - rect.right = rect.left + buttonWidth; + rect.left = rect.right - BUTTON_WIDTH; + fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SERVICE)); + rect.right = rect.left - 10; + rect.left = rect.right - BUTTON_WIDTH; fCancelButton = new BButton(rect, "CancelButton", "Cancel", new BMessage(MSG_RESET_SERVICE)); - rect.left = rect.right + 10; - rect.right = rect.left + buttonWidth; - fOKButton = new BButton(rect, "OKButton", "OK", new BMessage(MSG_CHANGE_SERVICE)); serviceBox->AddChild(fACName); serviceBox->AddChild(fServiceName); @@ -453,12 +453,15 @@ PPPoEView::ReloadInterfaces() name += strlen(name) + 1; } - delete interfaces; - - if(!Addon()->InterfaceName()) - fInterfaceName = ""; - else + // set interface or some default value if nothing was found + if(Addon()->InterfaceName()) 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) diff --git a/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.cpp b/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.cpp index a65080a9b7..1debaa3669 100644 --- a/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.cpp @@ -34,6 +34,10 @@ #define PROTOCOLS_TAB_PROTOCOLS "Protocols" +#define DEFAULT_PROTOCOL "IPCP" + // this protocol is added by default when creating a new interface + + ProtocolsAddon::ProtocolsAddon(BMessage *addons) : DialUpAddon(addons), fProtocolsCount(0), @@ -299,6 +303,10 @@ ProtocolsView::Reload() index, reinterpret_cast(&protocol)) == B_OK; index++) RegisterProtocol(protocol, false); + // add a default protocol for new interfaces + if(Addon()->IsNew()) + RegisterProtocol(DEFAULT_PROTOCOL); + fListView->Select(0); // XXX: unfortunately, this does not work when the BListView is detached @@ -409,6 +417,26 @@ ProtocolsView::HasProtocol(const BString& moduleName) const } +int32 +ProtocolsView::RegisterProtocol(const char *technicalName, bool reload = true) +{ + if(!technicalName) + return -1; + + DialUpAddon *addon; + BMenuItem *item; + for(int32 index = 0; index < fProtocolsMenu->CountItems(); index++) { + item = fProtocolsMenu->ItemAt(index); + if(item && item->Message()->FindPointer("Addon", + reinterpret_cast(&addon)) == B_OK && addon->TechnicalName() + && !strcmp(addon->TechnicalName(), technicalName)) + return RegisterProtocol(index, reload); + } + + return -1; +} + + int32 ProtocolsView::RegisterProtocol(const DialUpAddon *protocol, bool reload = true) { diff --git a/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.h b/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.h index 4292f6c5b7..cb6bbe7702 100644 --- a/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.h +++ b/src/tests/kits/net/DialUpPreflet/ProtocolsAddon.h @@ -81,6 +81,7 @@ class ProtocolsView : public BView { bool HasProtocol(const BString& moduleName) const; private: + int32 RegisterProtocol(const char *technicalName, bool reload = true); int32 RegisterProtocol(const DialUpAddon *protocol, bool reload = true); int32 RegisterProtocol(int32 index, bool reload = true); // moves the protocol from the pop-up menu to the list view diff --git a/src/tests/kits/net/DialUpPreflet/TODO b/src/tests/kits/net/DialUpPreflet/TODO index a3f7bf06bd..76d2b2763a 100644 --- a/src/tests/kits/net/DialUpPreflet/TODO +++ b/src/tests/kits/net/DialUpPreflet/TODO @@ -1,9 +1,10 @@ Short-term TODOs: -- add "Extras" tab for changing dial-behaviour (auto-redial, dial-on-demand, etc.) - add "Revert Changes" button -- load add-ons +- load add-ons from /boot/home/config/add-ons/DialUpPreflet - move DEVNOTES into a doxygen file and document the rest of the API - IPCP: check for incorrect settings (only IP addresses should be entered) +- PPPoE: refresh interfaces list every second or so +- Extras: add field for entering number of dial retries and delay between retries Long-term TODOs: - (maybe) allow selecting multiple authenticators (in expert-mode)