From 818c28d43db0a46034ca4756f669630a7522c738 Mon Sep 17 00:00:00 2001 From: urnenfeld Date: Wed, 19 May 2010 18:05:30 +0000 Subject: [PATCH] * Add Behavior tab in Preferences with options in ticket #476 * Implement enabled ones * Add canditate preferences * Implement singleton-like preferences class CayaPreferences. These are working but they are not stored in file at closing --- application/ContactLinker.cpp | 18 ++-- application/Jamfile | 1 + application/preferences/CayaPreferences.h | 28 ++++++ .../preferences/PreferencesBehavior.cpp | 98 +++++++++++++++++++ application/preferences/PreferencesBehavior.h | 32 ++++++ .../preferences/PreferencesContainer.h | 36 +++++++ application/preferences/PreferencesDialog.cpp | 2 + 7 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 application/preferences/CayaPreferences.h create mode 100644 application/preferences/PreferencesBehavior.cpp create mode 100644 application/preferences/PreferencesBehavior.h create mode 100644 application/preferences/PreferencesContainer.h diff --git a/application/ContactLinker.cpp b/application/ContactLinker.cpp index c778caa..ce7a25d 100644 --- a/application/ContactLinker.cpp +++ b/application/ContactLinker.cpp @@ -17,6 +17,7 @@ #include "RosterItem.h" #include "WindowsManager.h" +#include "CayaPreferences.h" ContactLinker::ContactLinker(BString id, BMessenger msgn) : fChatWindow(NULL), @@ -37,7 +38,7 @@ ContactLinker::ContactLinker(BString id, BMessenger msgn) } -ChatWindow* +ChatWindow* ContactLinker::GetChatWindow() { if (fChatWindow == NULL) @@ -46,7 +47,7 @@ ContactLinker::GetChatWindow() } -void +void ContactLinker::DeleteWindow() { if (fChatWindow != NULL) { @@ -64,10 +65,15 @@ ContactLinker::ShowWindow() { if (fChatWindow == NULL) CreateChatWindow(); - fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE); + + if (CayaPreferences::Item()->MoveToCurrentWorkspace) + fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE); + if (fChatWindow->IsHidden()) fChatWindow->Show(); - fChatWindow->Activate(true); + + if (CayaPreferences::Item()->ActivateWindow) + fChatWindow->Activate(true); } @@ -145,8 +151,8 @@ ContactLinker::SetProtocolLooper(ProtocolLooper* looper) void ContactLinker::SetNotifyName(BString name) -{ - if (fName.Compare(name) != 0) { +{ + if (fName.Compare(name) != 0) { fName = name; NotifyString(STR_CONTACT_NAME, name); } diff --git a/application/Jamfile b/application/Jamfile index bcc90cc..cc87f2f 100644 --- a/application/Jamfile +++ b/application/Jamfile @@ -42,6 +42,7 @@ Application Caya : AccountView.cpp PreferencesDialog.cpp PreferencesAccounts.cpp + PreferencesBehavior.cpp # views ContactPopUp.cpp diff --git a/application/preferences/CayaPreferences.h b/application/preferences/CayaPreferences.h new file mode 100644 index 0000000..e57a363 --- /dev/null +++ b/application/preferences/CayaPreferences.h @@ -0,0 +1,28 @@ +/* + * Copyright 2010, Oliver Ruiz Dorantes. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _CAYA_PREFERENCES_H +#define _CAYA_PREFERENCES_H + +#include "PreferencesContainer.h" + +typedef struct CayaPreferencesData +{ + bool MoveToCurrentWorkspace; + bool ActivateWindow; + // Add here as much fields as desired + + CayaPreferencesData() + : + MoveToCurrentWorkspace(true), + ActivateWindow(true) + // Add here its default values + { } + + +}; + +typedef PreferencesContainer CayaPreferences; + +#endif // _CAYA_PREFERENCES_H diff --git a/application/preferences/PreferencesBehavior.cpp b/application/preferences/PreferencesBehavior.cpp new file mode 100644 index 0000000..45f6572 --- /dev/null +++ b/application/preferences/PreferencesBehavior.cpp @@ -0,0 +1,98 @@ +/* + * Copyright 2010, Oliver Ruiz Dorantes. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "CayaProtocol.h" +#include "PreferencesBehavior.h" +#include "CayaPreferences.h" +#include "ProtocolManager.h" +#include "ProtocolSettings.h" +#include "MainWindow.h" +#include "TheApp.h" + +const uint32 kToCurrentWorkspace = 'CBcw'; +const uint32 kActivateChatWindow = 'CBac'; + +PreferencesBehavior::PreferencesBehavior() + : BView("Behavior", B_WILL_DRAW) +{ + + fOnIncomming = new BStringView("onIncomming", "On incomming message ... "); + fOnIncomming->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); + fOnIncomming->SetFont(be_bold_font); + + fToCurrentWorkspace = new BCheckBox("ToCurrentWorkspace", + "Move window to current workspace", + new BMessage(kToCurrentWorkspace)); + + fActivateChatWindow = new BCheckBox("ActivateChatWindow", + "Get focus ", + new BMessage(kActivateChatWindow)); + + fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived", + "Play sound event", NULL); + fPlaySoundOnMessageReceived->SetEnabled(false); // not implemented + + fHideEmoticons = new BCheckBox("HideEmoticons", + "Hide Emoticons", NULL); + fHideEmoticons->SetEnabled(false); // not implemented + + fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow", + "Mark unread window chat", NULL); + fMarkUnreadWindow->SetEnabled(false); // not implemented + + const float spacing = be_control_look->DefaultItemSpacing(); + + SetLayout(new BGroupLayout(B_HORIZONTAL, spacing)); + AddChild(BGroupLayoutBuilder(B_VERTICAL) + .Add(fOnIncomming) + .AddGroup(B_VERTICAL, spacing) + .Add(fToCurrentWorkspace) + .Add(fActivateChatWindow) + .Add(fMarkUnreadWindow) + .Add(fPlaySoundOnMessageReceived) + .SetInsets(spacing * 2, spacing, spacing * 5, spacing) + .End() + .Add(fHideEmoticons) + .SetInsets(spacing, spacing, spacing, spacing) + .End() + + ); +} + + +void +PreferencesBehavior::AttachedToWindow() +{ + fToCurrentWorkspace->SetTarget(this); + fActivateChatWindow->SetTarget(this); + + fToCurrentWorkspace->SetValue(CayaPreferences::Item()->MoveToCurrentWorkspace); + fActivateChatWindow->SetValue(CayaPreferences::Item()->ActivateWindow); +} + + +void +PreferencesBehavior::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kToCurrentWorkspace: + CayaPreferences::Item()->MoveToCurrentWorkspace = fToCurrentWorkspace->Value(); + break; + case kActivateChatWindow: + CayaPreferences::Item()->ActivateWindow = fActivateChatWindow->Value(); + break; + + default: + BView::MessageReceived(message); + } +} diff --git a/application/preferences/PreferencesBehavior.h b/application/preferences/PreferencesBehavior.h new file mode 100644 index 0000000..9c95950 --- /dev/null +++ b/application/preferences/PreferencesBehavior.h @@ -0,0 +1,32 @@ +/* + * Copyright 2010, Oliver Ruiz Dorantes. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _PREFERENCES_BEHAVIOR_H +#define _PREFERENCES_BEHAVIOR_H + +#include + +class BCheckBox; +class BStringView; + +class PreferencesBehavior : public BView { +public: + PreferencesBehavior(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* msg); + +private: + + BStringView* fOnIncomming; + BCheckBox* fToCurrentWorkspace; + BCheckBox* fActivateChatWindow; + BCheckBox* fPlaySoundOnMessageReceived; + BCheckBox* fMarkUnreadWindow; + + BCheckBox* fHideEmoticons; + +}; + +#endif // _PREFERENCES_BEHAVIOR_H diff --git a/application/preferences/PreferencesContainer.h b/application/preferences/PreferencesContainer.h new file mode 100644 index 0000000..678d51b --- /dev/null +++ b/application/preferences/PreferencesContainer.h @@ -0,0 +1,36 @@ +/* + * Copyright 2010, Oliver Ruiz Dorantes. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _PREFERENCES_CONTAINER_H +#define _PREFERENCES_CONTAINER_H + +#include + +// TODO: added to main singleton class? +template T* Singleton::fInstance = 0; + + +template +class PreferencesContainer : public Singleton > { + +public: + static const char* fFilename; + + static SettingsType* + Item() + { + return &Get()->fSettings; + } + + // TODO: + // status_t Save(); + // status_t Load(); + +private: + SettingsType fSettings; + +}; + + +#endif // _PREFERENCES_CONTAINER_H diff --git a/application/preferences/PreferencesDialog.cpp b/application/preferences/PreferencesDialog.cpp index cad4e34..1b77145 100644 --- a/application/preferences/PreferencesDialog.cpp +++ b/application/preferences/PreferencesDialog.cpp @@ -14,6 +14,7 @@ #include "PreferencesDialog.h" #include "PreferencesAccounts.h" +#include "PreferencesBehavior.h" const uint32 kApply = 'SAVE'; @@ -24,6 +25,7 @@ PreferencesDialog::PreferencesDialog() { BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL); tabView->AddTab(new PreferencesAccounts()); + tabView->AddTab(new PreferencesBehavior()); BButton* ok = new BButton("OK", new BMessage(kApply));