1 /***************************************************************************
2 * Copyright (C) 2005-2015 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>
24 #include <QTextDocument>
25 #include <QVBoxLayout>
27 #include "knotificationbackend.h"
31 #include "networkmodel.h"
34 KNotificationBackend::KNotificationBackend(QObject *parent)
35 : AbstractNotificationBackend(parent)
37 connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
38 SLOT(notificationActivated(SystemTray::ActivationReason)));
44 void KNotificationBackend::notify(const Notification &n)
49 type = "Highlight"; break;
50 case HighlightFocused:
51 type = "HighlightFocused"; break;
53 type = "PrivMsg"; break;
55 type = "PrivMsgFocused"; break;
58 #if QT_VERSION < 0x050000
59 QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
61 QString message = QString("<b><%1></b> %2").arg(n.sender, n.message.toHtmlEscaped());
63 KNotification *notification = KNotification::event(type, message, QIcon::fromTheme("dialog-information").pixmap(48), QtUi::mainWindow(),
64 KNotification::RaiseWidgetOnActivation
65 |KNotification::CloseWhenWidgetActivated
66 |KNotification::CloseOnTimeout);
67 connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
68 notification->setActions(QStringList("View"));
69 notification->setProperty("notificationId", n.notificationId);
71 _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
74 QtUi::mainWindow()->systemTray()->setAlert(true);
78 void KNotificationBackend::removeNotificationById(uint notificationId)
80 QList<QPair<uint, QPointer<KNotification> > >::iterator i = _notifications.begin();
81 while (i != _notifications.end()) {
82 if (i->first == notificationId) {
85 i = _notifications.erase(i);
94 void KNotificationBackend::close(uint notificationId)
96 removeNotificationById(notificationId);
97 //if(!_notifications.count()) // FIXME make configurable
98 QtUi::mainWindow()->systemTray()->setAlert(false);
102 void KNotificationBackend::notificationActivated()
105 KNotification *n = qobject_cast<KNotification *>(sender());
107 id = n->property("notificationId").toUInt();
109 notificationActivated(id);
113 void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason)
115 if (reason == SystemTray::Trigger) {
116 if (_notifications.count())
117 notificationActivated(_notifications.first().first); // oldest one
119 GraphicalUi::toggleMainWidget();
124 void KNotificationBackend::notificationActivated(uint notificationId)
126 emit activated(notificationId);
130 void KNotificationBackend::updateToolTip()
132 QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
133 _notifications.count() ? tr("%n pending highlight(s)", "", _notifications.count()) : QString());
137 SettingsPage *KNotificationBackend::createConfigWidget() const
139 return new ConfigWidget();
143 /***************************************************************************/
145 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : 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, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
157 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed)
159 setChangedState(changed);
163 void KNotificationBackend::ConfigWidget::load()
165 setChangedState(false);
169 void KNotificationBackend::ConfigWidget::save()