1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 "knotificationbackend.h"
23 #include <QTextDocument>
24 #include <QVBoxLayout>
27 # include <KNotification>
28 # include <KNotifyConfigWidget>
30 # include <KNotifications/KNotification>
31 # include <KNotifyConfig/KNotifyConfigWidget>
37 #include "networkmodel.h"
40 KNotificationBackend::KNotificationBackend(QObject *parent)
41 : AbstractNotificationBackend(parent)
43 connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
44 SLOT(notificationActivated(SystemTray::ActivationReason)));
50 void KNotificationBackend::notify(const Notification &n)
55 type = "Highlight"; break;
56 case HighlightFocused:
57 type = "HighlightFocused"; break;
59 type = "PrivMsg"; break;
61 type = "PrivMsgFocused"; break;
64 #if QT_VERSION < 0x050000
65 QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
67 QString message = QString("<b><%1></b> %2").arg(n.sender, n.message.toHtmlEscaped());
69 KNotification *notification = KNotification::event(type, message, icon::get("dialog-information").pixmap(48), QtUi::mainWindow(),
70 KNotification::RaiseWidgetOnActivation
71 |KNotification::CloseWhenWidgetActivated
72 |KNotification::CloseOnTimeout);
73 connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
74 notification->setActions(QStringList("View"));
75 notification->setProperty("notificationId", n.notificationId);
77 _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
83 void KNotificationBackend::removeNotificationById(uint notificationId)
85 QList<QPair<uint, QPointer<KNotification> > >::iterator i = _notifications.begin();
86 while (i != _notifications.end()) {
87 if (i->first == notificationId) {
90 i = _notifications.erase(i);
99 void KNotificationBackend::close(uint notificationId)
101 removeNotificationById(notificationId);
102 //if(!_notifications.count()) // FIXME make configurable
106 void KNotificationBackend::notificationActivated()
109 KNotification *n = qobject_cast<KNotification *>(sender());
111 id = n->property("notificationId").toUInt();
113 notificationActivated(id);
117 void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
119 if (reason == SystemTray::Trigger) {
120 if (_notifications.count())
121 notificationActivated(_notifications.first().first); // oldest one
123 GraphicalUi::toggleMainWidget();
128 void KNotificationBackend::notificationActivated(uint notificationId)
130 emit activated(notificationId);
134 void KNotificationBackend::updateToolTip()
136 QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
137 _notifications.count() ? tr("%n pending highlight(s)", "", _notifications.count()) : QString());
141 SettingsPage *KNotificationBackend::createConfigWidget() const
143 return new ConfigWidget();
147 /***************************************************************************/
149 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent)
151 _widget = new KNotifyConfigWidget(this);
152 _widget->setApplication("quassel");
154 QVBoxLayout *layout = new QVBoxLayout(this);
155 layout->addWidget(_widget);
157 connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
161 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed)
163 setChangedState(changed);
167 void KNotificationBackend::ConfigWidget::load()
169 setChangedState(false);
173 void KNotificationBackend::ConfigWidget::save()