Added code that allow the deskbar replicant to be disabled/enabled from the preferences

This commit is contained in:
barrett 2012-03-04 02:27:16 +00:00
parent cf7646fb00
commit 8d04f539c2
10 changed files with 78 additions and 41 deletions

View File

@ -93,13 +93,13 @@ AccountManager::SetStatus(CayaStatus status, const char* str)
// Notify status change // Notify status change
fStatus = status; fStatus = status;
NotifyInteger(INT_ACCOUNT_STATUS, (int32)fStatus); NotifyInteger(INT_ACCOUNT_STATUS, (int32)fStatus);
_ReplicantStatusNotify((CayaStatus)status); ReplicantStatusNotify((CayaStatus)status);
} }
} }
void void
AccountManager::_ReplicantStatusNotify(CayaStatus status) AccountManager::ReplicantStatusNotify(CayaStatus status, bool wait)
{ {
if(fReplicantMessenger != NULL && fReplicantMessenger->IsValid()) { if(fReplicantMessenger != NULL && fReplicantMessenger->IsValid()) {
printf("notification sent\n"); printf("notification sent\n");

View File

@ -22,12 +22,12 @@ public:
const char* str = NULL); const char* str = NULL);
void SetReplicantMessenger(BMessenger* messenger); void SetReplicantMessenger(BMessenger* messenger);
void ReplicantStatusNotify(CayaStatus status,
bool wait = false);
private: private:
AccountManager(); AccountManager();
~AccountManager(); ~AccountManager();
void _ReplicantStatusNotify(CayaStatus status);
CayaStatus fStatus; CayaStatus fStatus;
BMessenger* fReplicantMessenger; BMessenger* fReplicantMessenger;

View File

@ -12,7 +12,6 @@
#include <Alert.h> #include <Alert.h>
#include <Button.h> #include <Button.h>
#include <CardLayout.h> #include <CardLayout.h>
#include <Deskbar.h>
#include <ListView.h> #include <ListView.h>
#include <Box.h> #include <Box.h>
#include <CheckBox.h> #include <CheckBox.h>
@ -109,7 +108,7 @@ MainWindow::MainWindow()
CenterOnScreen(); CenterOnScreen();
//TODO check for errors here //TODO check for errors here
_InstallReplicant(); ReplicantStatusView::InstallReplicant();
} }
@ -127,7 +126,7 @@ MainWindow::QuitRequested()
fListView->MakeEmpty(); fListView->MakeEmpty();
fServer->Quit(); fServer->Quit();
CayaPreferences::Get()->Save(); CayaPreferences::Get()->Save();
_RemoveReplicant(); ReplicantStatusView::RemoveReplicant();
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }
@ -403,26 +402,3 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active)
else else
fWorkspaceChanged = true; 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");
}

View File

@ -45,9 +45,6 @@ public:
void RemoveItem(RosterItem*); void RemoveItem(RosterItem*);
private: private:
status_t _InstallReplicant();
status_t _RemoveReplicant();
StatusView* fStatusView; StatusView* fStatusView;
RosterListView* fListView; RosterListView* fListView;
Server* fServer; Server* fServer;

View File

@ -166,6 +166,7 @@ Server::Filter(BMessage* message, BHandler **target)
} }
AccountManager* accountManager = AccountManager::Get(); AccountManager* accountManager = AccountManager::Get();
accountManager->SetReplicantMessenger(messenger); accountManager->SetReplicantMessenger(messenger);
accountManager->ReplicantStatusNotify(accountManager->Status());
break; break;
} }

View File

@ -12,12 +12,16 @@ typedef struct _CayaPreferencesData
bool MoveToCurrentWorkspace; bool MoveToCurrentWorkspace;
bool ActivateWindow; bool ActivateWindow;
bool IgnoreEmoticons; bool IgnoreEmoticons;
bool HideCayaDeskbar;
bool DisableReplicant;
_CayaPreferencesData() _CayaPreferencesData()
: :
MoveToCurrentWorkspace(true), MoveToCurrentWorkspace(true),
ActivateWindow(true), ActivateWindow(true),
IgnoreEmoticons(false) IgnoreEmoticons(false),
HideCayaDeskbar(false),
DisableReplicant(false)
{ {
} }
} CayaPreferencesData; } CayaPreferencesData;

View File

@ -7,24 +7,27 @@
#include <Button.h> #include <Button.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <Deskbar.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h> #include <StringView.h>
#include "AccountManager.h"
#include "CayaProtocol.h" #include "CayaProtocol.h"
#include "PreferencesBehavior.h" #include "PreferencesBehavior.h"
#include "CayaPreferences.h" #include "CayaPreferences.h"
#include "ProtocolManager.h" #include "ProtocolManager.h"
#include "ProtocolSettings.h" #include "ProtocolSettings.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "ReplicantStatusView.h"
#include "TheApp.h" #include "TheApp.h"
const uint32 kToCurrentWorkspace = 'CBcw'; const uint32 kToCurrentWorkspace = 'CBcw';
const uint32 kActivateChatWindow = 'CBac'; const uint32 kActivateChatWindow = 'CBac';
const uint32 kDisableReplicant = 'DSrp'; const uint32 kDisableReplicant = 'DSrp';
const uint32 kPermanentReplicant ='PRpt'; const uint32 kPermanentReplicant ='PRpt';
const uint32 kHideCayaTracker = 'HCtk'; const uint32 kHideCayaDeskbar = 'HCtk';
@ -51,23 +54,25 @@ PreferencesBehavior::PreferencesBehavior()
fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow", fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow",
"Mark unread window chat", NULL); "Mark unread window chat", NULL);
fMarkUnreadWindow->SetEnabled(false); fMarkUnreadWindow->SetEnabled(false);
fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant",
"Mark unread the Deskbar Replicant", NULL);
fMarkUnreadReplicant->SetEnabled(false);
// not implemented // not implemented
fReplicantString = new BStringView("ReplicantString", "Replicant"); fReplicantString = new BStringView("ReplicantString", "Deskbar Replicant");
fReplicantString->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); fReplicantString->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fReplicantString->SetFont(be_bold_font); fReplicantString->SetFont(be_bold_font);
fDisableReplicant = new BCheckBox("DisableReplicant", fDisableReplicant = new BCheckBox("DisableReplicant",
"Disable Deskbar replicant", NULL); "Disable Deskbar replicant", new BMessage(kDisableReplicant));
fDisableReplicant->SetEnabled(true);
fPermanentReplicant = new BCheckBox("PermanentReplicant", fPermanentReplicant = new BCheckBox("PermanentReplicant",
"Permanent Deskbar Replicant", NULL); "Permanent Deskbar Replicant", NULL);
fPermanentReplicant->SetEnabled(false); fPermanentReplicant->SetEnabled(false);
fHideCayaDeskbar = new BCheckBox("HideCayaDeskbar", fHideCayaDeskbar = new BCheckBox("HideCayaDeskbar",
"Hide Caya field in Deskbar", NULL); "Hide Caya field in Deskbar", new BMessage(kHideCayaDeskbar));
fHideCayaDeskbar->SetEnabled(true);
const float spacing = be_control_look->DefaultItemSpacing(); const float spacing = be_control_look->DefaultItemSpacing();
@ -78,6 +83,7 @@ PreferencesBehavior::PreferencesBehavior()
.Add(fToCurrentWorkspace) .Add(fToCurrentWorkspace)
.Add(fActivateChatWindow) .Add(fActivateChatWindow)
.Add(fMarkUnreadWindow) .Add(fMarkUnreadWindow)
.Add(fMarkUnreadReplicant)
.Add(fPlaySoundOnMessageReceived) .Add(fPlaySoundOnMessageReceived)
.SetInsets(spacing * 2, spacing, spacing, spacing) .SetInsets(spacing * 2, spacing, spacing, spacing)
.End() .End()
@ -100,11 +106,17 @@ PreferencesBehavior::AttachedToWindow()
{ {
fToCurrentWorkspace->SetTarget(this); fToCurrentWorkspace->SetTarget(this);
fActivateChatWindow->SetTarget(this); fActivateChatWindow->SetTarget(this);
fHideCayaDeskbar->SetTarget(this);
fDisableReplicant->SetTarget(this);
fToCurrentWorkspace->SetValue( fToCurrentWorkspace->SetValue(
CayaPreferences::Item()->MoveToCurrentWorkspace); CayaPreferences::Item()->MoveToCurrentWorkspace);
fActivateChatWindow->SetValue( fActivateChatWindow->SetValue(
CayaPreferences::Item()->ActivateWindow); CayaPreferences::Item()->ActivateWindow);
fHideCayaDeskbar->SetValue(
CayaPreferences::Item()->HideCayaDeskbar);
fDisableReplicant->SetValue(
CayaPreferences::Item()->DisableReplicant);
} }
@ -120,6 +132,20 @@ PreferencesBehavior::MessageReceived(BMessage* message)
CayaPreferences::Item()->ActivateWindow CayaPreferences::Item()->ActivateWindow
= fActivateChatWindow->Value(); = fActivateChatWindow->Value();
break; 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: default:
BView::MessageReceived(message); BView::MessageReceived(message);
} }

View File

@ -25,6 +25,7 @@ private:
BCheckBox* fActivateChatWindow; BCheckBox* fActivateChatWindow;
BCheckBox* fPlaySoundOnMessageReceived; BCheckBox* fPlaySoundOnMessageReceived;
BCheckBox* fMarkUnreadWindow; BCheckBox* fMarkUnreadWindow;
BCheckBox* fMarkUnreadReplicant;
BStringView* fReplicantString; BStringView* fReplicantString;
BCheckBox* fDisableReplicant; BCheckBox* fDisableReplicant;

View File

@ -9,6 +9,7 @@
#include <Application.h> #include <Application.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Deskbar.h>
#include <IconUtils.h> #include <IconUtils.h>
#include <Message.h> #include <Message.h>
#include <MenuField.h> #include <MenuField.h>
@ -24,6 +25,7 @@
#include "BitmapView.h" #include "BitmapView.h"
#include "Caya.h" #include "Caya.h"
#include "CayaMessages.h" #include "CayaMessages.h"
#include "CayaPreferences.h"
#include "CayaProtocolMessages.h" #include "CayaProtocolMessages.h"
#include "CayaUtils.h" #include "CayaUtils.h"
#include "NicknameTextControl.h" #include "NicknameTextControl.h"
@ -353,3 +355,29 @@ instantiate_deskbar_item(void)
{ {
return new ReplicantStatusView(); 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");
}

View File

@ -43,6 +43,10 @@ public:
static ReplicantStatusView* Instantiate(BMessage* archive); static ReplicantStatusView* Instantiate(BMessage* archive);
void MouseDown(BPoint point); void MouseDown(BPoint point);
static status_t InstallReplicant();
static status_t RemoveReplicant();
private: private:
void _Init(); void _Init();
void _BuildMenu(); void _BuildMenu();