1 /***************************************************************************
2 * Copyright (C) 2005-2014 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <KNotification>
22 #include <KNotifyConfigWidget>
23 #include <QTextDocument>
24 #include <QVBoxLayout>
26 #include "knotificationbackend.h"
30 #include "iconloader.h"
32 #include "networkmodel.h"
35 KNotificationBackend::KNotificationBackend(QObject *parent)
36 : AbstractNotificationBackend(parent)
38 connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
39 SLOT(notificationActivated(SystemTray::ActivationReason)));
45 void KNotificationBackend::notify(const Notification &n)
50 type = "Highlight"; break;
51 case HighlightFocused:
52 type = "HighlightFocused"; break;
54 type = "PrivMsg"; break;
56 type = "PrivMsgFocused"; break;
59 #if QT_VERSION < 0x050000
60 QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
62 QString message = QString("<b><%1></b> %2").arg(n.sender, n.message.toHtmlEscaped());
64 KNotification *notification = KNotification::event(type, message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
65 KNotification::RaiseWidgetOnActivation
66 |KNotification::CloseWhenWidgetActivated
67 |KNotification::CloseOnTimeout);
68 connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
69 notification->setActions(QStringList("View"));
70 notification->setProperty("notificationId", n.notificationId);
72 _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
75 QtUi::mainWindow()->systemTray()->setAlert(true);
79 void KNotificationBackend::removeNotificationById(uint notificationId)
81 QList<QPair<uint, QPointer<KNotification> > >::iterator i = _notifications.begin();
82 while (i != _notifications.end()) {
83 if (i->first == notificationId) {
86 i = _notifications.erase(i);
95 void KNotificationBackend::close(uint notificationId)
97 removeNotificationById(notificationId);
98 //if(!_notifications.count()) // FIXME make configurable
99 QtUi::mainWindow()->systemTray()->setAlert(false);
103 void KNotificationBackend::notificationActivated()
106 KNotification *n = qobject_cast<KNotification *>(sender());
108 id = n->property("notificationId").toUInt();
110 notificationActivated(id);
114 void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
116 if (reason == SystemTray::Trigger) {
117 if (_notifications.count())
118 notificationActivated(_notifications.first().first); // oldest one
120 GraphicalUi::toggleMainWidget();
125 void KNotificationBackend::notificationActivated(uint notificationId)
127 emit activated(notificationId);
131 void KNotificationBackend::updateToolTip()
133 QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
134 _notifications.count() ? tr("%n pending highlight(s)", "", _notifications.count()) : QString());
138 SettingsPage *KNotificationBackend::createConfigWidget() const
140 return new ConfigWidget();
144 /***************************************************************************/
146 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent)
148 _widget = new KNotifyConfigWidget(this);
149 _widget->setApplication("quassel");
151 QVBoxLayout *layout = new QVBoxLayout(this);
152 layout->addWidget(_widget);
154 connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
158 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed)
160 setChangedState(changed);
164 void KNotificationBackend::ConfigWidget::load()
166 setChangedState(false);
170 void KNotificationBackend::ConfigWidget::save()