From bcc5118ba4d25f47d10d2fca7191bd80ff986321 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Sun, 9 May 2010 06:27:48 +0000 Subject: [PATCH] Added AccountDialog and AccountView, previously the code was in PreferencesAccounts.cpp. --- application/Jamfile | 2 + application/preferences/AccountDialog.cpp | 90 ++++++++++++ application/preferences/AccountDialog.h | 29 ++++ application/preferences/AccountView.cpp | 77 ++++++++++ application/preferences/AccountView.h | 19 +++ .../preferences/PreferencesAccounts.cpp | 139 +----------------- application/preferences/PreferencesDialog.cpp | 6 +- 7 files changed, 221 insertions(+), 141 deletions(-) create mode 100644 application/preferences/AccountDialog.cpp create mode 100644 application/preferences/AccountDialog.h create mode 100644 application/preferences/AccountView.cpp create mode 100644 application/preferences/AccountView.h diff --git a/application/Jamfile b/application/Jamfile index dac368a..5d41f07 100644 --- a/application/Jamfile +++ b/application/Jamfile @@ -29,7 +29,9 @@ Application caya : WindowsManager.cpp # preferences + AccountDialog.cpp AccountListItem.cpp + AccountView.cpp PreferencesDialog.cpp PreferencesAccounts.cpp diff --git a/application/preferences/AccountDialog.cpp b/application/preferences/AccountDialog.cpp new file mode 100644 index 0000000..07d9ae7 --- /dev/null +++ b/application/preferences/AccountDialog.cpp @@ -0,0 +1,90 @@ +/* + * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "AccountDialog.h" +#include "AccountView.h" +#include "ProtocolSettings.h" + +const uint32 kCancel = 'CANC'; +const uint32 kOK = 'SAVE'; + + +AccountDialog::AccountDialog(const char* title, CayaProtocol* cayap, + const char* account = NULL) + : BWindow(BRect(0, 0, 1, 1), title, B_MODAL_WINDOW, B_NOT_RESIZABLE | + B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) +{ + fSettings = new ProtocolSettings(cayap); + + fAccountName = new BTextControl("accountName", "Account name:", NULL, NULL); + fAccountName->SetFont(be_bold_font); + if (account) { + fAccountName->SetText(account); + fAccountName->SetEnabled(false); + } else + fAccountName->MakeFocus(true); + + Divider* divider = new Divider("divider", B_WILL_DRAW); + + fTop = new AccountView("top"); + if (account) + fSettings->Load(account, fTop); + else + fSettings->LoadTemplate(fTop); + + BButton* cancel = new BButton("Cancel", new BMessage(kCancel)); + BButton* ok = new BButton("OK", new BMessage(kOK)); + + const float spacing = be_control_look->DefaultItemSpacing(); + + SetLayout(new BGroupLayout(B_VERTICAL, spacing)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) + .Add(fAccountName) + .Add(divider) + .Add(fTop) + .AddGroup(B_HORIZONTAL, spacing) + .AddGlue() + .Add(cancel) + .Add(ok) + .End() + .AddGlue() + .SetInsets(spacing, spacing, spacing, 0) + ); + + CenterOnScreen(); +} + + +void +AccountDialog::MessageReceived(BMessage* msg) +{ + switch (msg->what) { + case kOK: + if (fSettings->Save(fAccountName->Text(), fTop) == B_OK) + Close(); +// TODO: Error! + break; + case kCancel: + Close(); + break; + case kChanged: + msg->PrintToStream(); + break; + default: + BWindow::MessageReceived(msg); + } +} diff --git a/application/preferences/AccountDialog.h b/application/preferences/AccountDialog.h new file mode 100644 index 0000000..e0653d0 --- /dev/null +++ b/application/preferences/AccountDialog.h @@ -0,0 +1,29 @@ +/* + * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _ACCOUNT_DIALOG_H +#define _ACCOUNT_DIALOG_H + +#include + +class BTextControl; + +class AccountView; +class CayaProtocol; +class ProtocolSettings; + +class AccountDialog : public BWindow { +public: + AccountDialog(const char* title, CayaProtocol* cayap, + const char* account = NULL); + + virtual void MessageReceived(BMessage* msg); + +private: + ProtocolSettings* fSettings; + AccountView* fTop; + BTextControl* fAccountName; +}; + +#endif // _ACCOUNT_DIALOG_H diff --git a/application/preferences/AccountView.cpp b/application/preferences/AccountView.cpp new file mode 100644 index 0000000..d309e74 --- /dev/null +++ b/application/preferences/AccountView.cpp @@ -0,0 +1,77 @@ +/* + * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "AccountView.h" + + +AccountView::AccountView(const char* name) + : BView(name, B_WILL_DRAW) +{ +} + + +void +AccountView::AttachedToWindow() +{ + // Once we are attached to window, the GUI is already created + // so we can set our window as target for messages + for (int32 i = 0; i < CountChildren(); i++) { + BView* child = ChildAt(i); + + BMenu* menu = dynamic_cast(child); + BMenuField* menuField + = dynamic_cast(child); + BTextControl* textControl + = dynamic_cast(child); + NotifyingTextView* textView + = dynamic_cast(child); + BCheckBox* checkBox = dynamic_cast(child); + + if (menuField) + menu = menuField->Menu(); + + if (menu) { + for (int32 j = 0; j < menu->CountItems(); j++) { + BMenuItem* item = menu->ItemAt(j); + item->SetMessage(new BMessage(kChanged)); + item->SetTarget(Window()); + } + + menu->SetTargetForItems(Window()); + } + + if (textControl) { + textControl->SetMessage(new BMessage(kChanged)); + textControl->SetTarget(Window()); + } + + if (checkBox) { + checkBox->SetMessage(new BMessage(kChanged)); + checkBox->SetTarget(Window()); + } + + if (textView) { + textView->SetMessage(new BMessage(kChanged)); + textView->SetTarget(Window()); + } + } +} diff --git a/application/preferences/AccountView.h b/application/preferences/AccountView.h new file mode 100644 index 0000000..20fc33b --- /dev/null +++ b/application/preferences/AccountView.h @@ -0,0 +1,19 @@ +/* + * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _ACCOUNT_VIEW_H +#define _ACCOUNT_VIEW_H + +#include + +const uint32 kChanged = 'CHGD'; + +class AccountView : public BView { +public: + AccountView(const char* name); + + virtual void AttachedToWindow(); +}; + +#endif // _ACCOUNT_VIEW_H diff --git a/application/preferences/PreferencesAccounts.cpp b/application/preferences/PreferencesAccounts.cpp index 41a2285..1a2f450 100644 --- a/application/preferences/PreferencesAccounts.cpp +++ b/application/preferences/PreferencesAccounts.cpp @@ -8,21 +8,16 @@ #include #include -#include #include #include #include #include -#include #include -#include -#include #include -#include -#include #include +#include "AccountDialog.h" #include "AccountListItem.h" #include "CayaProtocol.h" #include "PreferencesAccounts.h" @@ -34,138 +29,6 @@ const uint32 kEditAccount = 'EDAC'; const uint32 kDelAccount = 'DLAC'; const uint32 kSelect = 'SELT'; -const uint32 kCancel = 'CANC'; -const uint32 kOK = 'SAVE'; - -const uint32 kChanged = 'CHGD'; - - -class AccountView : public BView { -public: - AccountView(const char* name) - : BView(name, B_WILL_DRAW) - { - } - - void AttachedToWindow() - { - // Once we are attached to window, the GUI is already created - // so we can set our window as target for messages - for (int32 i = 0; i < CountChildren(); i++) { - BView* child = ChildAt(i); - - BMenu* menu = dynamic_cast(child); - BMenuField* menuField - = dynamic_cast(child); - BTextControl* textControl - = dynamic_cast(child); - NotifyingTextView* textView - = dynamic_cast(child); - BCheckBox* checkBox = dynamic_cast(child); - - if (menuField) - menu = menuField->Menu(); - - if (menu) { - for (int32 j = 0; j < menu->CountItems(); j++) { - BMenuItem* item = menu->ItemAt(j); - item->SetMessage(new BMessage(kChanged)); - item->SetTarget(Window()); - } - - menu->SetTargetForItems(Window()); - } - - if (textControl) { - textControl->SetMessage(new BMessage(kChanged)); - textControl->SetTarget(Window()); - } - - if (checkBox) { - checkBox->SetMessage(new BMessage(kChanged)); - checkBox->SetTarget(Window()); - } - - if (textView) { - textView->SetMessage(new BMessage(kChanged)); - textView->SetTarget(Window()); - } - } - } -}; - - -class AccountDialog : public BWindow { -public: - AccountDialog(const char* title, CayaProtocol* cayap, const char* account = NULL) - : BWindow(BRect(0, 0, 1, 1), title, B_MODAL_WINDOW, B_NOT_RESIZABLE | - B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) - { - fSettings = new ProtocolSettings(cayap); - - fAccountName = new BTextControl("accountName", "Account name:", NULL, NULL); - fAccountName->SetFont(be_bold_font); - if (account) { - fAccountName->SetText(account); - fAccountName->SetEnabled(false); - } else - fAccountName->MakeFocus(true); - - Divider* divider = new Divider("divider", B_WILL_DRAW); - - fTop = new AccountView("top"); - if (account) - fSettings->Load(account, fTop); - else - fSettings->LoadTemplate(fTop); - - BButton* cancel = new BButton("Cancel", new BMessage(kCancel)); - BButton* ok = new BButton("OK", new BMessage(kOK)); - - const float spacing = be_control_look->DefaultItemSpacing(); - - SetLayout(new BGroupLayout(B_VERTICAL, spacing)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) - .Add(fAccountName) - .Add(divider) - .Add(fTop) - .AddGroup(B_HORIZONTAL, spacing) - .AddGlue() - .Add(cancel) - .Add(ok) - .End() - .AddGlue() - .SetInsets(spacing, spacing, spacing, 0) - ); - - CenterOnScreen(); - } - - void MessageReceived(BMessage* msg) - { - switch (msg->what) { - case kOK: - if (fSettings->Save(fAccountName->Text(), fTop) == B_OK) - Close(); -// TODO: Error! - break; - case kCancel: - Close(); - break; - case kChanged: - msg->PrintToStream(); - break; - default: - BWindow::MessageReceived(msg); - } - } - -private: - ProtocolSettings* fSettings; - AccountView* fTop; - BTextControl* fAccountName; -}; - PreferencesAccounts::PreferencesAccounts() : BView("Accounts", B_WILL_DRAW) diff --git a/application/preferences/PreferencesDialog.cpp b/application/preferences/PreferencesDialog.cpp index 933785a..cad4e34 100644 --- a/application/preferences/PreferencesDialog.cpp +++ b/application/preferences/PreferencesDialog.cpp @@ -15,7 +15,7 @@ #include "PreferencesDialog.h" #include "PreferencesAccounts.h" -const int32 kOK = 'SAVE'; +const uint32 kApply = 'SAVE'; PreferencesDialog::PreferencesDialog() @@ -25,7 +25,7 @@ PreferencesDialog::PreferencesDialog() BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL); tabView->AddTab(new PreferencesAccounts()); - BButton* ok = new BButton("OK", new BMessage(kOK)); + BButton* ok = new BButton("OK", new BMessage(kApply)); const float spacing = be_control_look->DefaultItemSpacing(); @@ -49,7 +49,7 @@ void PreferencesDialog::MessageReceived(BMessage* msg) { switch (msg->what) { - case kOK: + case kApply: Close(); break; default: