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 <ScrollView.h>
#include <String.h>
#include <Notification.h>
#include "BitmapView.h"
#include "CayaMessages.h"
#include "CayaProtocolMessages.h"
#include "CayaPreferences.h"
#include "ChatWindow.h"
#include "ContactLinker.h"
#include "EditingFilter.h"
@ -188,6 +190,32 @@ ChatWindow::ImMessage(BMessage* msg)
// Message received, clear status anyway
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;
}
case IM_CONTACT_STARTED_TYPING:
@ -206,6 +234,11 @@ ChatWindow::ImMessage(BMessage* msg)
}
}
void
ChatWindow::WindowActivated(bool active)
{
SetTitle(fContactLinker->GetName());
}
void
ChatWindow::ObserveString(int32 what, BString str)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ const uint32 kApply = 'SAVE';
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)
{
BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL);