1 /***************************************************************************
2 * Copyright (C) 2005-2019 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>
26 #include <KNotifications/KNotification>
27 #include <KNotifyConfig/KNotifyConfigWidget>
32 #include "networkmodel.h"
36 KNotificationBackend::KNotificationBackend(QObject* parent)
37 : AbstractNotificationBackend(parent)
39 connect(QtUi::mainWindow()->systemTray(),
40 &SystemTray::activated,
42 selectOverload<SystemTray::ActivationReason>(&KNotificationBackend::notificationActivated));
47 void KNotificationBackend::notify(const Notification& n)
54 case HighlightFocused:
55 type = "HighlightFocused";
61 type = "PrivMsgFocused";
65 QString message = QString("<b><%1></b> %2").arg(n.sender, n.message.toHtmlEscaped());
66 KNotification* notification = KNotification::event(type,
68 icon::get("dialog-information").pixmap(48),
70 KNotification::RaiseWidgetOnActivation | KNotification::CloseWhenWidgetActivated
71 | KNotification::CloseOnTimeout);
73 selectOverload<uint>(&KNotification::activated),
75 selectOverload<>(&KNotificationBackend::notificationActivated));
76 notification->setActions(QStringList("View"));
77 notification->setProperty("notificationId", n.notificationId);
79 _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
84 void KNotificationBackend::removeNotificationById(uint notificationId)
86 QList<QPair<uint, QPointer<KNotification>>>::iterator i = _notifications.begin();
87 while (i != _notifications.end()) {
88 if (i->first == notificationId) {
91 i = _notifications.erase(i);
99 void KNotificationBackend::close(uint notificationId)
101 removeNotificationById(notificationId);
102 // if(!_notifications.count()) // FIXME make configurable
105 void KNotificationBackend::notificationActivated()
108 KNotification* n = qobject_cast<KNotification*>(sender());
110 id = n->property("notificationId").toUInt();
112 notificationActivated(id);
115 void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
117 if (reason == SystemTray::Trigger) {
118 if (_notifications.count())
119 notificationActivated(_notifications.first().first); // oldest one
121 GraphicalUi::toggleMainWidget();
125 void KNotificationBackend::notificationActivated(uint notificationId)
127 emit activated(notificationId);
130 void KNotificationBackend::updateToolTip()
132 QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
133 _notifications.count() ? tr("%n pending highlight(s)", "", _notifications.count())
137 SettingsPage* KNotificationBackend::createConfigWidget() const
139 return new ConfigWidget();
142 /***************************************************************************/
144 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget* parent)
145 : SettingsPage("Internal", "KNotification", parent)
147 _widget = new KNotifyConfigWidget(this);
148 _widget->setApplication("quassel");
150 QVBoxLayout* layout = new QVBoxLayout(this);
151 layout->addWidget(_widget);
153 connect(_widget, &KNotifyConfigWidget::changed, this, &ConfigWidget::widgetChanged);
156 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed)
158 setChangedState(changed);
161 void KNotificationBackend::ConfigWidget::load()
163 setChangedState(false);
166 void KNotificationBackend::ConfigWidget::save()