~ubuntu-branches/ubuntu/raring/konversation/raring

« back to all changes in this revision

Viewing changes to .pc/message-indicator/0001-Adds-support-for-Message-Indicator.diff/src/notificationhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-08-11 17:53:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100811175327-vj8gal6554f0cdck
Tags: 1.3.1-1ubuntu2
* Add back correct debian/patches/series file, adds back in
  kubuntu_01_default_channels.diff message-indicator/0001-Adds-
  support-for-Message-Indicator.diff LP: #616422
* Remove obsolete debian/patches/kubuntu/ directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This program is free software; you can redistribute it and/or modify
 
3
  it under the terms of the GNU General Public License as published by
 
4
  the Free Software Foundation; either version 2 of the License, or
 
5
  (at your option) any later version.
 
6
*/
 
7
 
 
8
/*
 
9
  copyright: (C) 2004 by Peter Simonsson
 
10
  email:     psn@linux.se
 
11
*/
 
12
 
 
13
#include "notificationhandler.h"
 
14
#include "common.h"
 
15
#include "chatwindow.h"
 
16
#include "application.h"
 
17
#include "mainwindow.h"
 
18
#include "viewcontainer.h"
 
19
#include "trayicon.h"
 
20
#include "server.h"
 
21
 
 
22
#include <QTextDocument>
 
23
 
 
24
#include <KNotification>
 
25
 
 
26
 
 
27
namespace Konversation
 
28
{
 
29
 
 
30
    NotificationHandler::NotificationHandler(Application* parent)
 
31
        : QObject(parent)
 
32
    {
 
33
        m_mainWindow = parent->getMainWindow();
 
34
    }
 
35
 
 
36
    NotificationHandler::~NotificationHandler()
 
37
    {
 
38
    }
 
39
 
 
40
    void NotificationHandler::message(ChatWindow* chatWin, const QString& fromNick, const QString& message)
 
41
    {
 
42
        if (!chatWin || !chatWin->notificationsEnabled())
 
43
            return;
 
44
 
 
45
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
46
            return;
 
47
 
 
48
        QString cleanedMessage = removeIrcMarkup(message);
 
49
        QString forKNotify = Qt::escape(cleanedMessage);
 
50
 
 
51
        KNotification::event(QString::fromLatin1("message"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
 
52
 
 
53
        if(!Preferences::self()->trayNotifyOnlyOwnNick())
 
54
        {
 
55
            startTrayNotification(chatWin);
 
56
        }
 
57
 
 
58
 
 
59
        if(Preferences::self()->oSDShowChannel() &&
 
60
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
61
        {
 
62
            Application* konvApp = static_cast<Application*>(kapp);
 
63
            konvApp->osd->show('(' + chatWin->getName() + ") <" + fromNick + "> " + cleanedMessage);
 
64
        }
 
65
 
 
66
    }
 
67
 
 
68
    void NotificationHandler::nick(ChatWindow* chatWin, const QString& fromNick, const QString& message)
 
69
    {
 
70
        if (!chatWin || !chatWin->notificationsEnabled())
 
71
            return;
 
72
 
 
73
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
74
            return;
 
75
 
 
76
        QString cleanedMessage = removeIrcMarkup(message);
 
77
        QString forKNotify = Qt::escape(cleanedMessage);
 
78
 
 
79
        KNotification::event(QString::fromLatin1("nick"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
 
80
 
 
81
        startTrayNotification(chatWin);
 
82
 
 
83
        Application* konvApp = static_cast<Application*>(kapp);
 
84
 
 
85
        if((Preferences::self()->oSDShowChannel() || Preferences::self()->oSDShowOwnNick()) &&
 
86
            (!m_mainWindow->isActiveWindow() ||
 
87
            (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
88
        {
 
89
            konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3",chatWin->getName(),fromNick,cleanedMessage));
 
90
        }
 
91
    }
 
92
 
 
93
    void NotificationHandler::queryMessage(ChatWindow* chatWin,
 
94
                                           const QString& fromNick, const QString& message)
 
95
    {
 
96
        if (!chatWin || !chatWin->notificationsEnabled())
 
97
            return;
 
98
 
 
99
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
100
            return;
 
101
 
 
102
        QString cleanedMessage = removeIrcMarkup(message);
 
103
        QString forKNotify = Qt::escape(cleanedMessage);
 
104
 
 
105
        KNotification::event(QString::fromLatin1("queryMessage"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
 
106
 
 
107
        startTrayNotification(chatWin);
 
108
 
 
109
        Application* konvApp = static_cast<Application*>(kapp);
 
110
 
 
111
        if(Preferences::self()->oSDShowQuery() && (!m_mainWindow->isActiveWindow() ||
 
112
           (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
113
        {
 
114
            konvApp->osd->show(i18n("[Query] &lt;%1&gt; %2",fromNick,cleanedMessage));
 
115
        }
 
116
    }
 
117
 
 
118
    void NotificationHandler::startTrayNotification(ChatWindow* chatWin)
 
119
    {
 
120
        if (!chatWin || !chatWin->notificationsEnabled())
 
121
            return;
 
122
 
 
123
        if (!chatWin->getServer() || (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer()->isAway()))
 
124
            return;
 
125
 
 
126
        if (!m_mainWindow->isActiveWindow() && chatWin->getServer()->isConnected() && m_mainWindow->systemTrayIcon())
 
127
            m_mainWindow->systemTrayIcon()->startNotification();
 
128
 
 
129
    }
 
130
 
 
131
    void NotificationHandler::join(ChatWindow* chatWin, const QString& nick)
 
132
    {
 
133
        if (!chatWin || !chatWin->notificationsEnabled())
 
134
            return;
 
135
 
 
136
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
137
            return;
 
138
 
 
139
        KNotification::event(QString::fromLatin1("join"), i18n("%1 joined %2",nick, chatWin->getName()), QPixmap(), m_mainWindow);
 
140
 
 
141
        // OnScreen Message
 
142
        if(Preferences::self()->oSDShowChannelEvent() &&
 
143
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
144
        {
 
145
            Application* konvApp = static_cast<Application*>(kapp);
 
146
            konvApp->osd->show(i18n("%1 joined %2",nick, chatWin->getName()));
 
147
        }
 
148
    }
 
149
 
 
150
    void NotificationHandler::part(ChatWindow* chatWin, const QString& nick)
 
151
    {
 
152
        if (!chatWin || !chatWin->notificationsEnabled())
 
153
            return;
 
154
 
 
155
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
156
            return;
 
157
 
 
158
        KNotification::event(QString::fromLatin1("part"), i18n("%1 parted %2",nick, chatWin->getName()), QPixmap(), m_mainWindow);
 
159
 
 
160
        // OnScreen Message
 
161
        if(Preferences::self()->oSDShowChannelEvent() &&
 
162
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
163
        {
 
164
            Application* konvApp = static_cast<Application*>(kapp);
 
165
            konvApp->osd->show(i18n("%1 parted %2",nick, chatWin->getName()));
 
166
        }
 
167
    }
 
168
 
 
169
    void NotificationHandler::quit(ChatWindow* chatWin, const QString& nick)
 
170
    {
 
171
        if (!chatWin || !chatWin->notificationsEnabled())
 
172
            return;
 
173
 
 
174
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
175
            return;
 
176
 
 
177
        KNotification::event(QString::fromLatin1("part"), i18n("%1 quit %2",nick, chatWin->getServer()->getServerName()), QPixmap(), m_mainWindow);
 
178
    }
 
179
 
 
180
    void NotificationHandler::nickChange(ChatWindow* chatWin, const QString& oldNick, const QString& newNick)
 
181
    {
 
182
        if (!chatWin || !chatWin->notificationsEnabled())
 
183
            return;
 
184
 
 
185
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
186
            return;
 
187
 
 
188
        KNotification::event(QString::fromLatin1("nickchange"), i18n("%1 changed nickname to %2",oldNick, newNick), QPixmap(), m_mainWindow);
 
189
    }
 
190
 
 
191
    void NotificationHandler::dccIncoming(ChatWindow* chatWin, const QString& fromNick)
 
192
    {
 
193
        if (!chatWin || !chatWin->notificationsEnabled())
 
194
            return;
 
195
 
 
196
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
197
            return;
 
198
 
 
199
        KNotification::event(QString::fromLatin1("dcc_incoming"), i18n("%1 wants to send a file to you",fromNick), QPixmap(), m_mainWindow);
 
200
    }
 
201
 
 
202
    void NotificationHandler::dccError(ChatWindow* chatWin, const QString& error)
 
203
    {
 
204
        if (!chatWin || !chatWin->notificationsEnabled())
 
205
            return;
 
206
 
 
207
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
208
            return;
 
209
 
 
210
        KNotification::event(QString::fromLatin1("dcc_error"), i18n("An Error has occurred in a DCC transfer: %1",error), QPixmap(), m_mainWindow);
 
211
    }
 
212
 
 
213
    void NotificationHandler::dccTransferDone(ChatWindow* chatWin, const QString& file)
 
214
    {
 
215
        if (!chatWin || !chatWin->notificationsEnabled())
 
216
            return;
 
217
 
 
218
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
219
            return;
 
220
 
 
221
        KNotification::event(QString::fromLatin1("dcctransfer_done"), i18nc("%1 - filename","%1 File Transfer is complete",file), QPixmap(), m_mainWindow);
 
222
    }
 
223
 
 
224
    void NotificationHandler::mode(ChatWindow* chatWin, const QString& /*nick*/)
 
225
    {
 
226
        if (!chatWin || !chatWin->notificationsEnabled())
 
227
            return;
 
228
 
 
229
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
230
            return;
 
231
 
 
232
        KNotification *ev=new KNotification("mode", m_mainWindow);
 
233
        ev->sendEvent();
 
234
    }
 
235
 
 
236
    void NotificationHandler::query(ChatWindow* chatWin, const QString& fromNick)
 
237
    {
 
238
        if (!chatWin || !chatWin->notificationsEnabled())
 
239
            return;
 
240
 
 
241
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
242
            return;
 
243
 
 
244
        startTrayNotification(chatWin);
 
245
 
 
246
        KNotification *ev=new KNotification("query", m_mainWindow);
 
247
        ev->setText(i18n("%1 has started a conversation (query) with you.",fromNick));
 
248
        ev->sendEvent();
 
249
    }
 
250
 
 
251
    void NotificationHandler::nickOnline(ChatWindow* chatWin, const QString& nick)
 
252
    {
 
253
        if (!chatWin || !chatWin->notificationsEnabled())
 
254
            return;
 
255
 
 
256
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
257
            return;
 
258
 
 
259
        KNotification *ev=new KNotification("notify", m_mainWindow);
 
260
        ev->setText(i18n("%1 is online (%2).", nick, chatWin->getServer()->getServerName()));
 
261
        ev->sendEvent();
 
262
 
 
263
    }
 
264
 
 
265
    void NotificationHandler::nickOffline(ChatWindow* chatWin, const QString& nick)
 
266
    {
 
267
        if (!chatWin || !chatWin->notificationsEnabled())
 
268
            return;
 
269
 
 
270
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
271
            return;
 
272
 
 
273
        KNotification *ev=new KNotification("notify", m_mainWindow);
 
274
        ev->setText(i18n("%1 went offline (%2).", nick, chatWin->getServer()->getServerName()));
 
275
        ev->sendEvent();
 
276
 
 
277
    }
 
278
 
 
279
    void NotificationHandler::kick(ChatWindow* chatWin, const QString& channel,const QString& nick)
 
280
    {
 
281
        if (!chatWin || !chatWin->notificationsEnabled())
 
282
            return;
 
283
 
 
284
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
285
            return;
 
286
 
 
287
        KNotification *ev=new KNotification("kick", m_mainWindow);
 
288
        ev->setText(i18n("You are kicked by %1 from %2", nick, channel));
 
289
        ev->sendEvent();
 
290
 
 
291
    }
 
292
 
 
293
    void NotificationHandler::dccChat(ChatWindow* chatWin, const QString& nick)
 
294
    {
 
295
        if (!chatWin || !chatWin->notificationsEnabled())
 
296
            return;
 
297
 
 
298
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
299
            return;
 
300
 
 
301
        KNotification *ev=new KNotification("dccChat", m_mainWindow);
 
302
        ev->setText(i18n("%1 started a dcc chat with you", nick));
 
303
        ev->sendEvent();
 
304
 
 
305
    }
 
306
 
 
307
    void NotificationHandler::highlight(ChatWindow* chatWin, const QString& fromNick, const QString& message)
 
308
    {
 
309
        if (!chatWin || !chatWin->notificationsEnabled())
 
310
            return;
 
311
 
 
312
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
313
            return;
 
314
 
 
315
        startTrayNotification(chatWin);
 
316
 
 
317
        QString cleanedMessage = removeIrcMarkup(message);
 
318
        QString forKNotify = Qt::escape(cleanedMessage);
 
319
 
 
320
        if(fromNick.isEmpty())
 
321
            KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) *** %2</html>").arg(chatWin->getName()).arg(forKNotify), QPixmap(), m_mainWindow);
 
322
        else
 
323
            KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) &lt;%2&gt; %3</html>").arg(chatWin->getName()).arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
 
324
 
 
325
        if(Preferences::self()->oSDShowOwnNick() &&
 
326
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
327
        {
 
328
            Application* konvApp = static_cast<Application*>(kapp);
 
329
            // if there was no nick associated, this must be a command message, so don't try displaying
 
330
            // an empty nick in <>
 
331
            if(fromNick.isEmpty())
 
332
                konvApp->osd->show(i18n("[HighLight] (%1) *** %2",chatWin->getName(),cleanedMessage));
 
333
            // normal highlight message
 
334
            else
 
335
                konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3",chatWin->getName(),fromNick,cleanedMessage));
 
336
        }
 
337
    }
 
338
 
 
339
    void NotificationHandler::connectionFailure(ChatWindow* chatWin, const QString& server)
 
340
    {
 
341
        if (!chatWin || !chatWin->notificationsEnabled())
 
342
            return;
 
343
 
 
344
        KNotification *ev=new KNotification("connectionFailure", m_mainWindow);
 
345
        ev->setText(i18n("Failed to connect to %1", server));
 
346
        ev->sendEvent();
 
347
 
 
348
    }
 
349
 
 
350
    void NotificationHandler::channelJoin(ChatWindow* chatWin, const QString& channel)
 
351
    {
 
352
        if (!chatWin || !chatWin->notificationsEnabled())
 
353
            return;
 
354
 
 
355
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
 
356
            return;
 
357
 
 
358
        KNotification::event(QString::fromLatin1("channelJoin"), i18n("You have joined %1.",channel), QPixmap(), m_mainWindow);
 
359
    }
 
360
 
 
361
}
 
362
 
 
363
#include "notificationhandler.moc"