From 8516381043654ed7fef3ee12ea17ed676ff107f4 Mon Sep 17 00:00:00 2001 From: barrett Date: Thu, 8 Mar 2012 22:55:13 +0000 Subject: [PATCH] Enabled notifications using the BNotification API, including enable/disable settings. The plugins that support it are XMPP and MSN. Added another tab in the preferences window named Replicant and moved the replicant settings here. --- application/Jamfile | 1 + application/MainWindow.cpp | 5 +- application/Server.cpp | 16 +++-- application/preferences/CayaPreferences.h | 13 +++- .../preferences/PreferencesBehavior.cpp | 65 ++++++++----------- application/preferences/PreferencesBehavior.h | 7 +- application/preferences/PreferencesDialog.cpp | 2 + 7 files changed, 56 insertions(+), 53 deletions(-) diff --git a/application/Jamfile b/application/Jamfile index 24678ed..9379c2f 100644 --- a/application/Jamfile +++ b/application/Jamfile @@ -44,6 +44,7 @@ Application Caya : PreferencesDialog.cpp PreferencesAccounts.cpp PreferencesBehavior.cpp + PreferencesReplicant.cpp PreferencesChatWindow.cpp # views diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 4ec66c6..d1f28ee 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -289,7 +289,9 @@ MainWindow::ImMessage(BMessage* msg) // Sort list view again fListView->Sort(); -#if 0 + if (!CayaPreferences::Item()->NotifyContactStatus) + break; + switch (status) { case CAYA_ONLINE: case CAYA_OFFLINE: @@ -314,7 +316,6 @@ MainWindow::ImMessage(BMessage* msg) default: break; } -#endif } break; } diff --git a/application/Server.cpp b/application/Server.cpp index c0add0b..c266750 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -23,6 +23,7 @@ #include "ProtocolLooper.h" #include "CayaMessages.h" #include "CayaProtocol.h" +#include "CayaPreferences.h" #include "CayaProtocolMessages.h" #include "ChatWindow.h" #include "ImageCache.h" @@ -97,7 +98,7 @@ Server::SendProtocolMessage(BMessage* msg) looper->PostMessage(msg); } } - + void Server::SendAllProtocolMessage(BMessage* msg) @@ -343,7 +344,9 @@ Server::ImMessage(BMessage* msg) return result; if (msg->FindFloat("progress", &progress) != B_OK) return result; -#if 0 + + if (!CayaPreferences::Item()->NotifyProtocolStatus) + break; CayaProtocolAddOn* addOn = ProtocolManager::Get()->ProtocolAddOn(protocol); @@ -355,7 +358,7 @@ Server::ImMessage(BMessage* msg) notification.SetContent(message); notification.SetProgress(progress); notification.Send(); -#endif + break; } case IM_NOTIFICATION: @@ -374,17 +377,20 @@ Server::ImMessage(BMessage* msg) if (msg->FindString("message", &message) != B_OK) return result; -#if 0 + if (!CayaPreferences::Item()->NotifyProtocolStatus) + break; + CayaProtocolAddOn* addOn = ProtocolManager::Get()->ProtocolAddOn(protocol); + BNotification notification((notification_type)type); notification.SetGroup(BString("Caya")); notification.SetTitle(title); notification.SetIcon(addOn->Icon()); notification.SetContent(message); notification.Send(); -#endif + break; } diff --git a/application/preferences/CayaPreferences.h b/application/preferences/CayaPreferences.h index 4728370..9979c5b 100644 --- a/application/preferences/CayaPreferences.h +++ b/application/preferences/CayaPreferences.h @@ -11,17 +11,24 @@ typedef struct _CayaPreferencesData { bool MoveToCurrentWorkspace; bool ActivateWindow; - bool IgnoreEmoticons; + bool HideCayaDeskbar; bool DisableReplicant; + bool IgnoreEmoticons; + + bool NotifyProtocolStatus; + bool NotifyContactStatus; + _CayaPreferencesData() : MoveToCurrentWorkspace(true), ActivateWindow(true), - IgnoreEmoticons(false), HideCayaDeskbar(false), - DisableReplicant(false) + DisableReplicant(true), + IgnoreEmoticons(false), + NotifyProtocolStatus(true), + NotifyContactStatus(false) { } } CayaPreferencesData; diff --git a/application/preferences/PreferencesBehavior.cpp b/application/preferences/PreferencesBehavior.cpp index f7ca27b..58b9dbe 100644 --- a/application/preferences/PreferencesBehavior.cpp +++ b/application/preferences/PreferencesBehavior.cpp @@ -25,10 +25,8 @@ const uint32 kToCurrentWorkspace = 'CBcw'; const uint32 kActivateChatWindow = 'CBac'; -const uint32 kDisableReplicant = 'DSrp'; -const uint32 kPermanentReplicant ='PRpt'; -const uint32 kHideCayaDeskbar = 'HCtk'; - +const uint32 kNotifyProtocolsLogin = 'NTpl'; +const uint32 kNotifyContactStatus = 'NTcl'; PreferencesBehavior::PreferencesBehavior() @@ -60,19 +58,15 @@ PreferencesBehavior::PreferencesBehavior() fMarkUnreadReplicant->SetEnabled(false); // not implemented - fReplicantString = new BStringView("ReplicantString", "Deskbar Replicant"); - fReplicantString->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); - fReplicantString->SetFont(be_bold_font); + fNotifications = new BStringView("notifications", "Deskbar Notifications"); + fNotifications->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); + fNotifications->SetFont(be_bold_font); - fDisableReplicant = new BCheckBox("DisableReplicant", - "Disable Deskbar replicant", new BMessage(kDisableReplicant)); + fNotifyProtocols = new BCheckBox("EnableProtocolNotify", + "Enable protocol status notifications",new BMessage(kNotifyProtocolsLogin)); - fPermanentReplicant = new BCheckBox("PermanentReplicant", - "Permanent Deskbar Replicant", NULL); - fPermanentReplicant->SetEnabled(false); - - fHideCayaDeskbar = new BCheckBox("HideCayaDeskbar", - "Hide Caya field in Deskbar", new BMessage(kHideCayaDeskbar)); + fNotifyContactStatus = new BCheckBox("EnableContactNotify", + "Enable contact status notifications",new BMessage(kNotifyContactStatus)); const float spacing = be_control_look->DefaultItemSpacing(); @@ -85,14 +79,13 @@ PreferencesBehavior::PreferencesBehavior() .Add(fMarkUnreadWindow) .Add(fMarkUnreadReplicant) .Add(fPlaySoundOnMessageReceived) - .SetInsets(spacing * 2, spacing, spacing, spacing) + . SetInsets(spacing * 2, spacing, spacing, spacing) .End() - .Add(fReplicantString) + .Add(fNotifications) .AddGroup(B_VERTICAL, spacing) - .Add(fDisableReplicant) - .Add(fPermanentReplicant) - .Add(fHideCayaDeskbar) - .SetInsets(spacing * 2, spacing, spacing, spacing) + .Add(fNotifyProtocols) + .Add(fNotifyContactStatus) + . SetInsets(spacing * 2, spacing, spacing, spacing) .End() .AddGlue() .SetInsets(spacing, spacing, spacing, spacing) @@ -106,17 +99,17 @@ PreferencesBehavior::AttachedToWindow() { fToCurrentWorkspace->SetTarget(this); fActivateChatWindow->SetTarget(this); - fHideCayaDeskbar->SetTarget(this); - fDisableReplicant->SetTarget(this); + fNotifyProtocols->SetTarget(this); + fNotifyContactStatus->SetTarget(this); fToCurrentWorkspace->SetValue( CayaPreferences::Item()->MoveToCurrentWorkspace); fActivateChatWindow->SetValue( CayaPreferences::Item()->ActivateWindow); - fHideCayaDeskbar->SetValue( - CayaPreferences::Item()->HideCayaDeskbar); - fDisableReplicant->SetValue( - CayaPreferences::Item()->DisableReplicant); + fNotifyProtocols->SetValue( + CayaPreferences::Item()->NotifyProtocolStatus); + fNotifyContactStatus->SetValue( + CayaPreferences::Item()->NotifyContactStatus); } @@ -132,19 +125,13 @@ PreferencesBehavior::MessageReceived(BMessage* message) CayaPreferences::Item()->ActivateWindow = fActivateChatWindow->Value(); break; - case kHideCayaDeskbar: - CayaPreferences::Item()->HideCayaDeskbar - = fHideCayaDeskbar->Value(); + case kNotifyProtocolsLogin: + CayaPreferences::Item()->NotifyProtocolStatus + = fNotifyProtocols->Value(); break; - case kDisableReplicant: - CayaPreferences::Item()->DisableReplicant - = fDisableReplicant->Value(); - - if (fDisableReplicant->Value() == true) - ReplicantStatusView::RemoveReplicant(); - else - ReplicantStatusView::InstallReplicant(); - + case kNotifyContactStatus: + CayaPreferences::Item()->NotifyContactStatus + = fNotifyContactStatus->Value(); break; default: BView::MessageReceived(message); diff --git a/application/preferences/PreferencesBehavior.h b/application/preferences/PreferencesBehavior.h index 6b860df..9e2a202 100644 --- a/application/preferences/PreferencesBehavior.h +++ b/application/preferences/PreferencesBehavior.h @@ -27,10 +27,9 @@ private: BCheckBox* fMarkUnreadWindow; BCheckBox* fMarkUnreadReplicant; - BStringView* fReplicantString; - BCheckBox* fDisableReplicant; - BCheckBox* fPermanentReplicant; - BCheckBox* fHideCayaDeskbar; + BStringView* fNotifications; + BCheckBox* fNotifyProtocols; + BCheckBox* fNotifyContactStatus; }; diff --git a/application/preferences/PreferencesDialog.cpp b/application/preferences/PreferencesDialog.cpp index 2d098f6..3208933 100644 --- a/application/preferences/PreferencesDialog.cpp +++ b/application/preferences/PreferencesDialog.cpp @@ -15,6 +15,7 @@ #include "PreferencesAccounts.h" #include "PreferencesBehavior.h" #include "PreferencesChatWindow.h" +#include "PreferencesReplicant.h" const uint32 kApply = 'SAVE'; @@ -27,6 +28,7 @@ PreferencesDialog::PreferencesDialog() tabView->AddTab(new PreferencesAccounts()); tabView->AddTab(new PreferencesBehavior()); tabView->AddTab(new PreferencesChatWindow()); + tabView->AddTab(new PreferencesReplicant()); BButton* ok = new BButton("OK", new BMessage(kApply));