From 8d04f539c25bbc547868c6e2e597ea6b919d4378 Mon Sep 17 00:00:00 2001 From: barrett Date: Sun, 4 Mar 2012 02:27:16 +0000 Subject: [PATCH] Added code that allow the deskbar replicant to be disabled/enabled from the preferences --- application/AccountManager.cpp | 6 +-- application/AccountManager.h | 4 +- application/MainWindow.cpp | 28 +------------- application/MainWindow.h | 3 -- application/Server.cpp | 1 + application/preferences/CayaPreferences.h | 6 ++- .../preferences/PreferencesBehavior.cpp | 38 ++++++++++++++++--- application/preferences/PreferencesBehavior.h | 1 + application/views/ReplicantStatusView.cpp | 28 ++++++++++++++ application/views/ReplicantStatusView.h | 4 ++ 10 files changed, 78 insertions(+), 41 deletions(-) diff --git a/application/AccountManager.cpp b/application/AccountManager.cpp index c8ae15a..90645ce 100644 --- a/application/AccountManager.cpp +++ b/application/AccountManager.cpp @@ -93,18 +93,18 @@ AccountManager::SetStatus(CayaStatus status, const char* str) // Notify status change fStatus = status; NotifyInteger(INT_ACCOUNT_STATUS, (int32)fStatus); - _ReplicantStatusNotify((CayaStatus)status); + ReplicantStatusNotify((CayaStatus)status); } } void -AccountManager::_ReplicantStatusNotify(CayaStatus status) +AccountManager::ReplicantStatusNotify(CayaStatus status, bool wait) { if(fReplicantMessenger != NULL && fReplicantMessenger->IsValid()) { printf("notification sent\n"); BMessage mess(IM_OWN_STATUS_SET); mess.AddInt32("status", status); fReplicantMessenger->SendMessage(&mess); - } + } } diff --git a/application/AccountManager.h b/application/AccountManager.h index 92884bd..bb4c7cf 100644 --- a/application/AccountManager.h +++ b/application/AccountManager.h @@ -22,12 +22,12 @@ public: const char* str = NULL); void SetReplicantMessenger(BMessenger* messenger); + void ReplicantStatusNotify(CayaStatus status, + bool wait = false); private: AccountManager(); ~AccountManager(); - void _ReplicantStatusNotify(CayaStatus status); - CayaStatus fStatus; BMessenger* fReplicantMessenger; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index cad0f9b..4ec66c6 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -109,7 +108,7 @@ MainWindow::MainWindow() CenterOnScreen(); //TODO check for errors here - _InstallReplicant(); + ReplicantStatusView::InstallReplicant(); } @@ -127,7 +126,7 @@ MainWindow::QuitRequested() fListView->MakeEmpty(); fServer->Quit(); CayaPreferences::Get()->Save(); - _RemoveReplicant(); + ReplicantStatusView::RemoveReplicant(); be_app->PostMessage(B_QUIT_REQUESTED); return true; } @@ -403,26 +402,3 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active) else fWorkspaceChanged = true; } - - -// The following methods install -// and remove the Caya's replicant -// from Deskbar. -status_t -MainWindow::_InstallReplicant() -{ - BDeskbar deskbar; - if (deskbar.HasItem("ReplicantStatusView")) { - _RemoveReplicant(); - } - ReplicantStatusView* view = new ReplicantStatusView(); - return deskbar.AddItem(view); -} - - -status_t -MainWindow::_RemoveReplicant() -{ - BDeskbar deskbar; - return deskbar.RemoveItem("ReplicantStatusView"); -} diff --git a/application/MainWindow.h b/application/MainWindow.h index f8a0150..4265875 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -45,9 +45,6 @@ public: void RemoveItem(RosterItem*); private: - status_t _InstallReplicant(); - status_t _RemoveReplicant(); - StatusView* fStatusView; RosterListView* fListView; Server* fServer; diff --git a/application/Server.cpp b/application/Server.cpp index cf0242e..ef8aaac 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -166,6 +166,7 @@ Server::Filter(BMessage* message, BHandler **target) } AccountManager* accountManager = AccountManager::Get(); accountManager->SetReplicantMessenger(messenger); + accountManager->ReplicantStatusNotify(accountManager->Status()); break; } diff --git a/application/preferences/CayaPreferences.h b/application/preferences/CayaPreferences.h index 6ab7442..4728370 100644 --- a/application/preferences/CayaPreferences.h +++ b/application/preferences/CayaPreferences.h @@ -12,12 +12,16 @@ typedef struct _CayaPreferencesData bool MoveToCurrentWorkspace; bool ActivateWindow; bool IgnoreEmoticons; + bool HideCayaDeskbar; + bool DisableReplicant; _CayaPreferencesData() : MoveToCurrentWorkspace(true), ActivateWindow(true), - IgnoreEmoticons(false) + IgnoreEmoticons(false), + HideCayaDeskbar(false), + DisableReplicant(false) { } } CayaPreferencesData; diff --git a/application/preferences/PreferencesBehavior.cpp b/application/preferences/PreferencesBehavior.cpp index 3aa56dd..f7ca27b 100644 --- a/application/preferences/PreferencesBehavior.cpp +++ b/application/preferences/PreferencesBehavior.cpp @@ -7,24 +7,27 @@ #include #include #include +#include #include #include #include #include +#include "AccountManager.h" #include "CayaProtocol.h" #include "PreferencesBehavior.h" #include "CayaPreferences.h" #include "ProtocolManager.h" #include "ProtocolSettings.h" #include "MainWindow.h" +#include "ReplicantStatusView.h" #include "TheApp.h" const uint32 kToCurrentWorkspace = 'CBcw'; const uint32 kActivateChatWindow = 'CBac'; const uint32 kDisableReplicant = 'DSrp'; const uint32 kPermanentReplicant ='PRpt'; -const uint32 kHideCayaTracker = 'HCtk'; +const uint32 kHideCayaDeskbar = 'HCtk'; @@ -51,23 +54,25 @@ PreferencesBehavior::PreferencesBehavior() fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow", "Mark unread window chat", NULL); fMarkUnreadWindow->SetEnabled(false); + + fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant", + "Mark unread the Deskbar Replicant", NULL); + fMarkUnreadReplicant->SetEnabled(false); // not implemented - fReplicantString = new BStringView("ReplicantString", "Replicant"); + fReplicantString = new BStringView("ReplicantString", "Deskbar Replicant"); fReplicantString->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); fReplicantString->SetFont(be_bold_font); fDisableReplicant = new BCheckBox("DisableReplicant", - "Disable Deskbar replicant", NULL); - fDisableReplicant->SetEnabled(true); + "Disable Deskbar replicant", new BMessage(kDisableReplicant)); fPermanentReplicant = new BCheckBox("PermanentReplicant", "Permanent Deskbar Replicant", NULL); fPermanentReplicant->SetEnabled(false); fHideCayaDeskbar = new BCheckBox("HideCayaDeskbar", - "Hide Caya field in Deskbar", NULL); - fHideCayaDeskbar->SetEnabled(true); + "Hide Caya field in Deskbar", new BMessage(kHideCayaDeskbar)); const float spacing = be_control_look->DefaultItemSpacing(); @@ -78,6 +83,7 @@ PreferencesBehavior::PreferencesBehavior() .Add(fToCurrentWorkspace) .Add(fActivateChatWindow) .Add(fMarkUnreadWindow) + .Add(fMarkUnreadReplicant) .Add(fPlaySoundOnMessageReceived) .SetInsets(spacing * 2, spacing, spacing, spacing) .End() @@ -100,11 +106,17 @@ PreferencesBehavior::AttachedToWindow() { fToCurrentWorkspace->SetTarget(this); fActivateChatWindow->SetTarget(this); + fHideCayaDeskbar->SetTarget(this); + fDisableReplicant->SetTarget(this); fToCurrentWorkspace->SetValue( CayaPreferences::Item()->MoveToCurrentWorkspace); fActivateChatWindow->SetValue( CayaPreferences::Item()->ActivateWindow); + fHideCayaDeskbar->SetValue( + CayaPreferences::Item()->HideCayaDeskbar); + fDisableReplicant->SetValue( + CayaPreferences::Item()->DisableReplicant); } @@ -120,6 +132,20 @@ PreferencesBehavior::MessageReceived(BMessage* message) CayaPreferences::Item()->ActivateWindow = fActivateChatWindow->Value(); break; + case kHideCayaDeskbar: + CayaPreferences::Item()->HideCayaDeskbar + = fHideCayaDeskbar->Value(); + break; + case kDisableReplicant: + CayaPreferences::Item()->DisableReplicant + = fDisableReplicant->Value(); + + if (fDisableReplicant->Value() == true) + ReplicantStatusView::RemoveReplicant(); + else + ReplicantStatusView::InstallReplicant(); + + break; default: BView::MessageReceived(message); } diff --git a/application/preferences/PreferencesBehavior.h b/application/preferences/PreferencesBehavior.h index a63a737..6b860df 100644 --- a/application/preferences/PreferencesBehavior.h +++ b/application/preferences/PreferencesBehavior.h @@ -25,6 +25,7 @@ private: BCheckBox* fActivateChatWindow; BCheckBox* fPlaySoundOnMessageReceived; BCheckBox* fMarkUnreadWindow; + BCheckBox* fMarkUnreadReplicant; BStringView* fReplicantString; BCheckBox* fDisableReplicant; diff --git a/application/views/ReplicantStatusView.cpp b/application/views/ReplicantStatusView.cpp index 45123ac..b5cb83d 100644 --- a/application/views/ReplicantStatusView.cpp +++ b/application/views/ReplicantStatusView.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include "BitmapView.h" #include "Caya.h" #include "CayaMessages.h" +#include "CayaPreferences.h" #include "CayaProtocolMessages.h" #include "CayaUtils.h" #include "NicknameTextControl.h" @@ -353,3 +355,29 @@ instantiate_deskbar_item(void) { return new ReplicantStatusView(); } + + +// The following methods install +// and remove the Caya's replicant +// from Deskbar. +status_t +ReplicantStatusView::InstallReplicant() +{ + if (CayaPreferences::Item()->DisableReplicant == true) + return B_OK; + + BDeskbar deskbar; + if (deskbar.HasItem("ReplicantStatusView")) { + ReplicantStatusView::RemoveReplicant(); + } + ReplicantStatusView* view = new ReplicantStatusView(); + return deskbar.AddItem(view); +} + + +status_t +ReplicantStatusView::RemoveReplicant() +{ + BDeskbar deskbar; + return deskbar.RemoveItem("ReplicantStatusView"); +} diff --git a/application/views/ReplicantStatusView.h b/application/views/ReplicantStatusView.h index 558f784..43c6127 100644 --- a/application/views/ReplicantStatusView.h +++ b/application/views/ReplicantStatusView.h @@ -43,6 +43,10 @@ public: static ReplicantStatusView* Instantiate(BMessage* archive); void MouseDown(BPoint point); + + + static status_t InstallReplicant(); + static status_t RemoveReplicant(); private: void _Init(); void _BuildMenu();