Patch from Maciej Janiszewski which adds support for hiding offline contacts, message notifications and caya can now set the window title to unread state, all functions can be disabled from settings as well. Thanks\!

This commit is contained in:
barrett 2013-04-06 19:47:04 +00:00
parent 53c5c02d66
commit 007af3d89a
8 changed files with 101 additions and 13 deletions

View File

@ -22,10 +22,12 @@
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <String.h> #include <String.h>
#include <Notification.h>
#include "BitmapView.h" #include "BitmapView.h"
#include "CayaMessages.h" #include "CayaMessages.h"
#include "CayaProtocolMessages.h" #include "CayaProtocolMessages.h"
#include "CayaPreferences.h"
#include "ChatWindow.h" #include "ChatWindow.h"
#include "ContactLinker.h" #include "ContactLinker.h"
#include "EditingFilter.h" #include "EditingFilter.h"
@ -188,6 +190,32 @@ ChatWindow::ImMessage(BMessage* msg)
// Message received, clear status anyway // Message received, clear status anyway
fStatus->SetText(""); fStatus->SetText("");
if (IsActive()) break;
// Mark unread window
if (CayaPreferences::Item()->MarkUnreadWindow) {
BString title = "[*] ";
title<<fContactLinker->GetName();
SetTitle(title);
}
// Check if the user want the notification
if (!CayaPreferences::Item()->NotifyNewMessage)
break;
BString notify_message;
notify_message << "You've got new message from ";
notify_message << fContactLinker->GetName().String();
BNotification notification(B_INFORMATION_NOTIFICATION);
notification.SetGroup(BString("Caya"));
notification.SetTitle(BString("New message"));
notification.SetIcon(fAvatar->Bitmap());
notification.SetContent(notify_message);
notification.Send();
break; break;
} }
case IM_CONTACT_STARTED_TYPING: case IM_CONTACT_STARTED_TYPING:
@ -206,6 +234,11 @@ ChatWindow::ImMessage(BMessage* msg)
} }
} }
void
ChatWindow::WindowActivated(bool active)
{
SetTitle(fContactLinker->GetName());
}
void void
ChatWindow::ObserveString(int32 what, BString str) ChatWindow::ObserveString(int32 what, BString str)

View File

@ -23,6 +23,7 @@ public:
virtual void ShowWindow(); virtual void ShowWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
void WindowActivated(bool active);
virtual bool QuitRequested(); virtual bool QuitRequested();
void UpdateAvatar(); void UpdateAvatar();

View File

@ -278,11 +278,13 @@ MainWindow::ImMessage(BMessage* msg)
// Add or remove item // Add or remove item
switch (status) { switch (status) {
case CAYA_OFFLINE: /*case CAYA_OFFLINE:
// By default offline contacts are hidden // By default offline contacts are hidden
if (!CayaPreferences::Item()->HideOffline)
break;
if (HasItem(rosterItem)) if (HasItem(rosterItem))
RemoveItem(rosterItem); RemoveItem(rosterItem);
return; return;*/
default: default:
// Add item because it has a non-offline status // Add item because it has a non-offline status
if (!HasItem(rosterItem)) if (!HasItem(rosterItem))
@ -377,7 +379,11 @@ void
MainWindow::AddItem(RosterItem* item) MainWindow::AddItem(RosterItem* item)
{ {
// Don't add offline items and avoid duplicates // Don't add offline items and avoid duplicates
if ((item->Status() == CAYA_OFFLINE) || HasItem(item)) if ((item->Status() == CAYA_OFFLINE)
&& CayaPreferences::Item()->HideOffline)
return;
if (HasItem(item))
return; return;
// Add item and sort // Add item and sort

View File

@ -16,11 +16,14 @@ CayaPreferencesData::CayaPreferencesData()
MoveToCurrentWorkspace(true), MoveToCurrentWorkspace(true),
RaiseOnMessageReceived(false), RaiseOnMessageReceived(false),
RaiseUserIsTyping(false), RaiseUserIsTyping(false),
MarkUnreadWindow(true),
HideCayaDeskbar(false), HideCayaDeskbar(false),
DisableReplicant(true), DisableReplicant(true),
IgnoreEmoticons(false), IgnoreEmoticons(false),
NotifyProtocolStatus(true), NotifyProtocolStatus(true),
NotifyContactStatus(false) NotifyContactStatus(false),
NotifyNewMessage(true),
HideOffline(true)
{ {
} }
@ -60,7 +63,7 @@ CayaPreferencesData::FlattenedSize() const
// NOTE add the size of every settings // NOTE add the size of every settings
// you added. // you added.
ssize_t size = sizeof(bool) * 8; ssize_t size = sizeof(bool) * 11;
return size; return size;
} }
@ -80,9 +83,11 @@ CayaPreferencesData::Flatten(BPositionIO* flatData) const
_AddBool(flatData, MoveToCurrentWorkspace); _AddBool(flatData, MoveToCurrentWorkspace);
_AddBool(flatData, RaiseOnMessageReceived); _AddBool(flatData, RaiseOnMessageReceived);
_AddBool(flatData, RaiseUserIsTyping); _AddBool(flatData, RaiseUserIsTyping);
_AddBool(flatData, MarkUnreadWindow);
_AddBool(flatData, NotifyProtocolStatus); _AddBool(flatData, NotifyProtocolStatus);
_AddBool(flatData, NotifyContactStatus); _AddBool(flatData, NotifyContactStatus);
_AddBool(flatData, NotifyNewMessage);
// Replicant // Replicant
_AddBool(flatData, HideCayaDeskbar); _AddBool(flatData, HideCayaDeskbar);
@ -90,6 +95,9 @@ CayaPreferencesData::Flatten(BPositionIO* flatData) const
// Chat window // Chat window
_AddBool(flatData, IgnoreEmoticons); _AddBool(flatData, IgnoreEmoticons);
// Contact list
_AddBool(flatData, HideOffline);
// Usage example for strings : // Usage example for strings :
// _AddString(flatData, yourBString.String()); // _AddString(flatData, yourBString.String());
@ -97,8 +105,6 @@ CayaPreferencesData::Flatten(BPositionIO* flatData) const
// NOTE : The order is very important, Unflatten and Flatten // NOTE : The order is very important, Unflatten and Flatten
// classes should read/write the values in the same order. // classes should read/write the values in the same order.
_AddString(flatData, "str");
return B_OK; return B_OK;
} }
@ -144,9 +150,11 @@ CayaPreferencesData::Unflatten(type_code code, BPositionIO* flatData)
MoveToCurrentWorkspace = _ReadBool(flatData); MoveToCurrentWorkspace = _ReadBool(flatData);
RaiseOnMessageReceived = _ReadBool(flatData); RaiseOnMessageReceived = _ReadBool(flatData);
RaiseUserIsTyping = _ReadBool(flatData); RaiseUserIsTyping = _ReadBool(flatData);
MarkUnreadWindow = _ReadBool(flatData);
NotifyProtocolStatus = _ReadBool(flatData); NotifyProtocolStatus = _ReadBool(flatData);
NotifyContactStatus = _ReadBool(flatData); NotifyContactStatus = _ReadBool(flatData);
NotifyNewMessage = _ReadBool(flatData);
// Replicant // Replicant
HideCayaDeskbar = _ReadBool(flatData); HideCayaDeskbar = _ReadBool(flatData);
@ -154,6 +162,9 @@ CayaPreferencesData::Unflatten(type_code code, BPositionIO* flatData)
// Chat window // Chat window
IgnoreEmoticons = _ReadBool(flatData); IgnoreEmoticons = _ReadBool(flatData);
// Contact list
HideOffline = _ReadBool(flatData);
// Usage example for strings : // Usage example for strings :
// const char* str = _ReadString(flatData); // const char* str = _ReadString(flatData);
@ -195,9 +206,8 @@ const char*
CayaPreferencesData::_ReadString(BPositionIO* data) CayaPreferencesData::_ReadString(BPositionIO* data)
{ {
size_t len; size_t len;
char* ret;
data->Read(&len, sizeof(size_t)); data->Read(&len, sizeof(size_t));
ret = new char[len]; char* ret = new char[len];
data->Read(ret, len); data->Read(ret, len);
return ret; return ret;

View File

@ -28,13 +28,17 @@ public:
bool MoveToCurrentWorkspace; bool MoveToCurrentWorkspace;
bool RaiseOnMessageReceived; bool RaiseOnMessageReceived;
bool RaiseUserIsTyping; bool RaiseUserIsTyping;
bool MarkUnreadWindow;
bool NotifyProtocolStatus; bool NotifyProtocolStatus;
bool NotifyContactStatus; bool NotifyContactStatus;
bool NotifyNewMessage;
bool HideCayaDeskbar; bool HideCayaDeskbar;
bool DisableReplicant; bool DisableReplicant;
bool IgnoreEmoticons; bool IgnoreEmoticons;
bool HideOffline;
private: private:
void _AddBool(BPositionIO* data, bool value) const; void _AddBool(BPositionIO* data, bool value) const;
void _AddString(BPositionIO* data, void _AddString(BPositionIO* data,

View File

@ -28,6 +28,9 @@ const uint32 kRaiseOnMessageReceived = 'FCmr';
const uint32 kRaiseUserIsTyping = 'FCit'; const uint32 kRaiseUserIsTyping = 'FCit';
const uint32 kNotifyProtocolsLogin = 'NTpl'; const uint32 kNotifyProtocolsLogin = 'NTpl';
const uint32 kNotifyContactStatus = 'NTcl'; const uint32 kNotifyContactStatus = 'NTcl';
const uint32 kNotifyNewMessage = 'NTms';
const uint32 kMarkUnreadWindow = 'MKuw';
const uint32 kHideOffline = 'HiOf';
PreferencesBehavior::PreferencesBehavior() PreferencesBehavior::PreferencesBehavior()
@ -37,6 +40,10 @@ PreferencesBehavior::PreferencesBehavior()
fOnIncoming = new BStringView("onIncoming", "On incoming message..."); fOnIncoming = new BStringView("onIncoming", "On incoming message...");
fOnIncoming->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); fOnIncoming->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fOnIncoming->SetFont(be_bold_font); fOnIncoming->SetFont(be_bold_font);
fHideOffline = new BCheckBox("HideOfflineContacts",
"Hide offline contacts",
new BMessage(kHideOffline));
fToCurrentWorkspace = new BCheckBox("ToCurrentWorkspace", fToCurrentWorkspace = new BCheckBox("ToCurrentWorkspace",
"Move window to current workspace", "Move window to current workspace",
@ -55,8 +62,8 @@ PreferencesBehavior::PreferencesBehavior()
fPlaySoundOnMessageReceived->SetEnabled(false); // not implemented fPlaySoundOnMessageReceived->SetEnabled(false); // not implemented
fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow", fMarkUnreadWindow = new BCheckBox("MarkUnreadWindow",
"Mark unread window chat", NULL); "Mark unread window chat", new BMessage(kMarkUnreadWindow));
fMarkUnreadWindow->SetEnabled(false); /*fMarkUnreadWindow->SetEnabled(false); implementing it right now*/
fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant", fMarkUnreadReplicant = new BCheckBox("MarkUnreadReplicant",
"Mark unread the Deskbar Replicant", NULL); "Mark unread the Deskbar Replicant", NULL);
@ -74,6 +81,9 @@ PreferencesBehavior::PreferencesBehavior()
fNotifyContactStatus = new BCheckBox("EnableContactNotify", fNotifyContactStatus = new BCheckBox("EnableContactNotify",
"Enable contact status notifications",new BMessage(kNotifyContactStatus)); "Enable contact status notifications",new BMessage(kNotifyContactStatus));
fNotifyNewMessage = new BCheckBox("EnableMessageNotify",
"Enable message notifications", new BMessage(kNotifyNewMessage));
const float spacing = be_control_look->DefaultItemSpacing(); const float spacing = be_control_look->DefaultItemSpacing();
@ -81,6 +91,7 @@ PreferencesBehavior::PreferencesBehavior()
AddChild(BGroupLayoutBuilder(B_VERTICAL) AddChild(BGroupLayoutBuilder(B_VERTICAL)
.Add(fOnIncoming) .Add(fOnIncoming)
.AddGroup(B_VERTICAL, spacing) .AddGroup(B_VERTICAL, spacing)
.Add(fHideOffline)
.Add(fToCurrentWorkspace) .Add(fToCurrentWorkspace)
.Add(fRaiseOnMessageReceived) .Add(fRaiseOnMessageReceived)
.Add(fRaiseUserIsTyping) .Add(fRaiseUserIsTyping)
@ -93,6 +104,7 @@ PreferencesBehavior::PreferencesBehavior()
.AddGroup(B_VERTICAL, spacing) .AddGroup(B_VERTICAL, spacing)
.Add(fNotifyProtocols) .Add(fNotifyProtocols)
.Add(fNotifyContactStatus) .Add(fNotifyContactStatus)
.Add(fNotifyNewMessage)
. SetInsets(spacing * 2, spacing, spacing, spacing) . SetInsets(spacing * 2, spacing, spacing, spacing)
.End() .End()
.AddGlue() .AddGlue()
@ -105,22 +117,30 @@ PreferencesBehavior::PreferencesBehavior()
void void
PreferencesBehavior::AttachedToWindow() PreferencesBehavior::AttachedToWindow()
{ {
fHideOffline->SetTarget(this);
fToCurrentWorkspace->SetTarget(this); fToCurrentWorkspace->SetTarget(this);
fRaiseUserIsTyping->SetTarget(this); fRaiseUserIsTyping->SetTarget(this);
fRaiseOnMessageReceived->SetTarget(this); fRaiseOnMessageReceived->SetTarget(this);
fNotifyProtocols->SetTarget(this); fNotifyProtocols->SetTarget(this);
fNotifyContactStatus->SetTarget(this); fNotifyContactStatus->SetTarget(this);
fNotifyNewMessage->SetTarget(this);
fHideOffline->SetValue(
CayaPreferences::Item()->HideOffline);
fToCurrentWorkspace->SetValue( fToCurrentWorkspace->SetValue(
CayaPreferences::Item()->MoveToCurrentWorkspace); CayaPreferences::Item()->MoveToCurrentWorkspace);
fRaiseUserIsTyping->SetValue( fRaiseUserIsTyping->SetValue(
CayaPreferences::Item()->RaiseUserIsTyping); CayaPreferences::Item()->RaiseUserIsTyping);
fRaiseOnMessageReceived->SetValue( fRaiseOnMessageReceived->SetValue(
CayaPreferences::Item()->RaiseOnMessageReceived); CayaPreferences::Item()->RaiseOnMessageReceived);
fMarkUnreadWindow->SetValue(
CayaPreferences::Item()->MarkUnreadWindow);
fNotifyProtocols->SetValue( fNotifyProtocols->SetValue(
CayaPreferences::Item()->NotifyProtocolStatus); CayaPreferences::Item()->NotifyProtocolStatus);
fNotifyContactStatus->SetValue( fNotifyContactStatus->SetValue(
CayaPreferences::Item()->NotifyContactStatus); CayaPreferences::Item()->NotifyContactStatus);
fNotifyNewMessage->SetValue(
CayaPreferences::Item()->NotifyNewMessage);
} }
@ -128,6 +148,10 @@ void
PreferencesBehavior::MessageReceived(BMessage* message) PreferencesBehavior::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kHideOffline:
CayaPreferences::Item()->HideOffline
= fHideOffline->Value();
break;
case kToCurrentWorkspace: case kToCurrentWorkspace:
CayaPreferences::Item()->MoveToCurrentWorkspace CayaPreferences::Item()->MoveToCurrentWorkspace
= fToCurrentWorkspace->Value(); = fToCurrentWorkspace->Value();
@ -148,6 +172,14 @@ PreferencesBehavior::MessageReceived(BMessage* message)
CayaPreferences::Item()->NotifyContactStatus CayaPreferences::Item()->NotifyContactStatus
= fNotifyContactStatus->Value(); = fNotifyContactStatus->Value();
break; break;
case kNotifyNewMessage:
CayaPreferences::Item()->NotifyNewMessage
= fNotifyNewMessage->Value();
break;
case kMarkUnreadWindow:
CayaPreferences::Item()->MarkUnreadWindow
= fMarkUnreadWindow->Value();
break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
} }

View File

@ -21,6 +21,7 @@ public:
private: private:
BStringView* fOnIncoming; BStringView* fOnIncoming;
BCheckBox* fHideOffline;
BCheckBox* fToCurrentWorkspace; BCheckBox* fToCurrentWorkspace;
BCheckBox* fRaiseOnMessageReceived; BCheckBox* fRaiseOnMessageReceived;
BCheckBox* fRaiseUserIsTyping; BCheckBox* fRaiseUserIsTyping;
@ -31,6 +32,7 @@ private:
BStringView* fNotifications; BStringView* fNotifications;
BCheckBox* fNotifyProtocols; BCheckBox* fNotifyProtocols;
BCheckBox* fNotifyContactStatus; BCheckBox* fNotifyContactStatus;
BCheckBox* fNotifyNewMessage;
}; };

View File

@ -21,7 +21,7 @@ const uint32 kApply = 'SAVE';
PreferencesDialog::PreferencesDialog() PreferencesDialog::PreferencesDialog()
: BWindow(BRect(0, 0, 500, 500), "Preferences", B_TITLED_WINDOW, : BWindow(BRect(0, 0, 500, 550), "Preferences", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE) B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE)
{ {
BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL); BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL);