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.
9
copyright: (C) 2004 by Peter Simonsson
13
#include "notificationhandler.h"
15
#include "chatwindow.h"
16
#include "application.h"
17
#include "mainwindow.h"
18
#include "viewcontainer.h"
22
#include <QTextDocument>
24
#include <KNotification>
27
namespace Konversation
30
NotificationHandler::NotificationHandler(Application* parent)
33
m_mainWindow = parent->getMainWindow();
36
NotificationHandler::~NotificationHandler()
40
void NotificationHandler::message(ChatWindow* chatWin, const QString& fromNick, const QString& message)
42
if (!chatWin || !chatWin->notificationsEnabled())
45
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
48
QString cleanedMessage = removeIrcMarkup(message);
49
QString forKNotify = Qt::escape(cleanedMessage);
51
KNotification::event(QString::fromLatin1("message"), QString("<html><%1> %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
53
if(!Preferences::self()->trayNotifyOnlyOwnNick())
55
startTrayNotification(chatWin);
59
if(Preferences::self()->oSDShowChannel() &&
60
(!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
62
Application* konvApp = static_cast<Application*>(kapp);
63
konvApp->osd->show('(' + chatWin->getName() + ") <" + fromNick + "> " + cleanedMessage);
68
void NotificationHandler::nick(ChatWindow* chatWin, const QString& fromNick, const QString& message)
70
if (!chatWin || !chatWin->notificationsEnabled())
73
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
76
QString cleanedMessage = removeIrcMarkup(message);
77
QString forKNotify = Qt::escape(cleanedMessage);
79
KNotification::event(QString::fromLatin1("nick"), QString("<html><%1> %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
81
startTrayNotification(chatWin);
83
Application* konvApp = static_cast<Application*>(kapp);
85
if((Preferences::self()->oSDShowChannel() || Preferences::self()->oSDShowOwnNick()) &&
86
(!m_mainWindow->isActiveWindow() ||
87
(chatWin != m_mainWindow->getViewContainer()->getFrontView())))
89
konvApp->osd->show(i18n("[HighLight] (%1) <%2> %3",chatWin->getName(),fromNick,cleanedMessage));
93
void NotificationHandler::queryMessage(ChatWindow* chatWin,
94
const QString& fromNick, const QString& message)
96
if (!chatWin || !chatWin->notificationsEnabled())
99
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
102
QString cleanedMessage = removeIrcMarkup(message);
103
QString forKNotify = Qt::escape(cleanedMessage);
105
KNotification::event(QString::fromLatin1("queryMessage"), QString("<html><%1> %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
107
startTrayNotification(chatWin);
109
Application* konvApp = static_cast<Application*>(kapp);
111
if(Preferences::self()->oSDShowQuery() && (!m_mainWindow->isActiveWindow() ||
112
(chatWin != m_mainWindow->getViewContainer()->getFrontView())))
114
konvApp->osd->show(i18n("[Query] <%1> %2",fromNick,cleanedMessage));
118
void NotificationHandler::startTrayNotification(ChatWindow* chatWin)
120
if (!chatWin || !chatWin->notificationsEnabled())
123
if (!chatWin->getServer() || (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer()->isAway()))
126
if (!m_mainWindow->isActiveWindow() && chatWin->getServer()->isConnected() && m_mainWindow->systemTrayIcon())
127
m_mainWindow->systemTrayIcon()->startNotification();
131
void NotificationHandler::join(ChatWindow* chatWin, const QString& nick)
133
if (!chatWin || !chatWin->notificationsEnabled())
136
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
139
KNotification::event(QString::fromLatin1("join"), i18n("%1 joined %2",nick, chatWin->getName()), QPixmap(), m_mainWindow);
142
if(Preferences::self()->oSDShowChannelEvent() &&
143
(!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
145
Application* konvApp = static_cast<Application*>(kapp);
146
konvApp->osd->show(i18n("%1 joined %2",nick, chatWin->getName()));
150
void NotificationHandler::part(ChatWindow* chatWin, const QString& nick)
152
if (!chatWin || !chatWin->notificationsEnabled())
155
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
158
KNotification::event(QString::fromLatin1("part"), i18n("%1 parted %2",nick, chatWin->getName()), QPixmap(), m_mainWindow);
161
if(Preferences::self()->oSDShowChannelEvent() &&
162
(!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
164
Application* konvApp = static_cast<Application*>(kapp);
165
konvApp->osd->show(i18n("%1 parted %2",nick, chatWin->getName()));
169
void NotificationHandler::quit(ChatWindow* chatWin, const QString& nick)
171
if (!chatWin || !chatWin->notificationsEnabled())
174
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
177
KNotification::event(QString::fromLatin1("part"), i18n("%1 quit %2",nick, chatWin->getServer()->getServerName()), QPixmap(), m_mainWindow);
180
void NotificationHandler::nickChange(ChatWindow* chatWin, const QString& oldNick, const QString& newNick)
182
if (!chatWin || !chatWin->notificationsEnabled())
185
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
188
KNotification::event(QString::fromLatin1("nickchange"), i18n("%1 changed nickname to %2",oldNick, newNick), QPixmap(), m_mainWindow);
191
void NotificationHandler::dccIncoming(ChatWindow* chatWin, const QString& fromNick)
193
if (!chatWin || !chatWin->notificationsEnabled())
196
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
199
KNotification::event(QString::fromLatin1("dcc_incoming"), i18n("%1 wants to send a file to you",fromNick), QPixmap(), m_mainWindow);
202
void NotificationHandler::dccError(ChatWindow* chatWin, const QString& error)
204
if (!chatWin || !chatWin->notificationsEnabled())
207
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
210
KNotification::event(QString::fromLatin1("dcc_error"), i18n("An Error has occurred in a DCC transfer: %1",error), QPixmap(), m_mainWindow);
213
void NotificationHandler::dccTransferDone(ChatWindow* chatWin, const QString& file)
215
if (!chatWin || !chatWin->notificationsEnabled())
218
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
221
KNotification::event(QString::fromLatin1("dcctransfer_done"), i18nc("%1 - filename","%1 File Transfer is complete",file), QPixmap(), m_mainWindow);
224
void NotificationHandler::mode(ChatWindow* chatWin, const QString& /*nick*/)
226
if (!chatWin || !chatWin->notificationsEnabled())
229
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
232
KNotification *ev=new KNotification("mode", m_mainWindow);
236
void NotificationHandler::query(ChatWindow* chatWin, const QString& fromNick)
238
if (!chatWin || !chatWin->notificationsEnabled())
241
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
244
startTrayNotification(chatWin);
246
KNotification *ev=new KNotification("query", m_mainWindow);
247
ev->setText(i18n("%1 has started a conversation (query) with you.",fromNick));
251
void NotificationHandler::nickOnline(ChatWindow* chatWin, const QString& nick)
253
if (!chatWin || !chatWin->notificationsEnabled())
256
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
259
KNotification *ev=new KNotification("notify", m_mainWindow);
260
ev->setText(i18n("%1 is online (%2).", nick, chatWin->getServer()->getServerName()));
265
void NotificationHandler::nickOffline(ChatWindow* chatWin, const QString& nick)
267
if (!chatWin || !chatWin->notificationsEnabled())
270
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
273
KNotification *ev=new KNotification("notify", m_mainWindow);
274
ev->setText(i18n("%1 went offline (%2).", nick, chatWin->getServer()->getServerName()));
279
void NotificationHandler::kick(ChatWindow* chatWin, const QString& channel,const QString& nick)
281
if (!chatWin || !chatWin->notificationsEnabled())
284
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
287
KNotification *ev=new KNotification("kick", m_mainWindow);
288
ev->setText(i18n("You are kicked by %1 from %2", nick, channel));
293
void NotificationHandler::dccChat(ChatWindow* chatWin, const QString& nick)
295
if (!chatWin || !chatWin->notificationsEnabled())
298
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
301
KNotification *ev=new KNotification("dccChat", m_mainWindow);
302
ev->setText(i18n("%1 started a dcc chat with you", nick));
307
void NotificationHandler::highlight(ChatWindow* chatWin, const QString& fromNick, const QString& message)
309
if (!chatWin || !chatWin->notificationsEnabled())
312
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
315
startTrayNotification(chatWin);
317
QString cleanedMessage = removeIrcMarkup(message);
318
QString forKNotify = Qt::escape(cleanedMessage);
320
if(fromNick.isEmpty())
321
KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) *** %2</html>").arg(chatWin->getName()).arg(forKNotify), QPixmap(), m_mainWindow);
323
KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) <%2> %3</html>").arg(chatWin->getName()).arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
325
if(Preferences::self()->oSDShowOwnNick() &&
326
(!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
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
335
konvApp->osd->show(i18n("[HighLight] (%1) <%2> %3",chatWin->getName(),fromNick,cleanedMessage));
339
void NotificationHandler::connectionFailure(ChatWindow* chatWin, const QString& server)
341
if (!chatWin || !chatWin->notificationsEnabled())
344
KNotification *ev=new KNotification("connectionFailure", m_mainWindow);
345
ev->setText(i18n("Failed to connect to %1", server));
350
void NotificationHandler::channelJoin(ChatWindow* chatWin, const QString& channel)
352
if (!chatWin || !chatWin->notificationsEnabled())
355
if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
358
KNotification::event(QString::fromLatin1("channelJoin"), i18n("You have joined %1.",channel), QPixmap(), m_mainWindow);
363
#include "notificationhandler.moc"