2
* psigrowlnotifier.cpp: Psi's interface to Growl
3
* Copyright (C) 2005 Remko Troncon
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* You can also redistribute and/or modify this program under the
11
* terms of the Psi License, specified in the accompanied COPYING
12
* file, as published by the Psi Project; either dated January 1st,
13
* 2005, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this library; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#include <qstringlist.h>
29
#include "psiaccount.h"
31
#include "growlnotifier.h"
32
#include "psigrowlnotifier.h"
37
* A class representing the notification context, which will be passed to
38
* Growl, and then passed back when a notification is clicked.
40
class NotificationContext
43
NotificationContext(PsiAccount* a, Jid j) : account_(a), jid_(j) { }
44
PsiAccount* account() { return account_; }
45
Jid jid() { return jid_; }
55
* (Private) constructor of the PsiGrowlNotifier.
56
* Initializes notifications and registers with Growl through GrowlNotifier.
58
PsiGrowlNotifier::PsiGrowlNotifier()
60
// Initialize all notifications
62
nots << QObject::tr("Contact becomes Available");
63
nots << QObject::tr("Contact becomes Unavailable");
64
nots << QObject::tr("Contact changes Status");
65
nots << QObject::tr("Incoming Message");
66
nots << QObject::tr("Incoming Headline");
67
nots << QObject::tr("Incoming File");
69
// Initialize default notifications
71
defaults << QObject::tr("Contact becomes Available");
72
defaults << QObject::tr("Incoming Message");
73
defaults << QObject::tr("Incoming Headline");
74
defaults << QObject::tr("Incoming File");
76
// Register with Growl
77
gn_ = new GrowlNotifier(nots, defaults, "Psi");
82
* Requests the global PsiGrowlNotifier instance.
83
* If PsiGrowlNotifier wasn't initialized yet, it is initialized.
85
* \see GrowlNotifier()
86
* \return A pointer to the PsiGrowlNotifier instance
88
PsiGrowlNotifier* PsiGrowlNotifier::instance()
91
instance_ = new PsiGrowlNotifier();
98
* Requests a popup to be sent to Growl.
100
* \param account The requesting account.
101
* \param type The type of popup to be sent.
102
* \param jid The originating jid
103
* \param uli The originating userlist item. Can be NULL.
104
* \param event The originating event. Can be NULL.
106
void PsiGrowlNotifier::popup(PsiAccount* account, PsiPopup::PopupType type, const Jid& jid, const Resource& r, const UserListItem* uli, PsiEvent* event)
110
QString title, desc, contact;
111
QString statusTxt = status2txt(makeSTATUS(r.status()));
112
QString statusMsg = r.status().status();
113
if (uli && !uli->name().isEmpty())
114
contact = uli->name();
116
contact = jid.bare();
119
// FIXME: Lookup the client version
120
if (account->avatarFactory())
121
icon = account->avatarFactory()->getAvatar(jid, "Psi");
124
// Default value for the title
128
case PsiPopup::AlertOnline:
129
name = QObject::tr("Contact becomes Available");
130
title = QString("%1 (%2)").arg(contact).arg(statusTxt);
132
//icon = is->statusPQString(jid, r.status());
134
case PsiPopup::AlertOffline:
135
name = QObject::tr("Contact becomes Unavailable");
136
title = QString("%1 (%2)").arg(contact).arg(statusTxt);
138
//icon = is->statusPQString(jid, r.status());
140
case PsiPopup::AlertStatusChange:
141
name = QObject::tr("Contact changes Status");
142
title = QString("%1 (%2)").arg(contact).arg(statusTxt);
144
//icon = is->statusPQString(jid, r.status());
146
case PsiPopup::AlertMessage: {
147
name = QObject::tr("Incoming Message");
148
title = QObject::tr("%1 says:").arg(contact);
149
const Message* jmessage = &((MessageEvent *)event)->message();
150
desc = jmessage->body();
151
//icon = IconsetFactory::iconPQString("psi/message");
154
case PsiPopup::AlertChat: {
155
name = QObject::tr("Incoming Message");
156
const Message* jmessage = &((MessageEvent *)event)->message();
157
desc = jmessage->body();
158
//icon = IconsetFactory::iconPQString("psi/start-chat");
161
case PsiPopup::AlertHeadline: {
162
name = QObject::tr("Incoming Headline");
163
const Message* jmessage = &((MessageEvent *)event)->message();
164
if ( !jmessage->subject().isEmpty())
165
title = jmessage->subject();
166
desc = jmessage->body();
167
//icon = IconsetFactory::iconPQString("psi/headline");
170
case PsiPopup::AlertFile:
171
name = QObject::tr("Incoming File");
172
desc = QObject::tr("[Incoming File]");
173
//icon = IconsetFactory::iconPQString("psi/file");
180
NotificationContext* context = new NotificationContext(account, jid);
181
gn_->notify(name, title, desc, icon, false, this, SLOT(notificationClicked(void*)), SLOT(notificationTimedOut(void*)), context);
184
void PsiGrowlNotifier::notificationClicked(void* c)
186
NotificationContext* context = (NotificationContext*) c;
187
context->account()->actionDefault(context->jid());
191
void PsiGrowlNotifier::notificationTimedOut(void* c)
193
NotificationContext* context = (NotificationContext*) c;
197
PsiGrowlNotifier* PsiGrowlNotifier::instance_ = 0;