1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QVBoxLayout>
23 #include <KNotification>
24 #include <KNotifyConfigWidget>
25 #include <QTextDocument>
27 #include "knotificationbackend.h"
31 #include "iconloader.h"
32 #include "networkmodel.h"
34 #include "systemtray.h"
36 KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
37 connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
38 SLOT(notificationActivated(QSystemTrayIcon::ActivationReason)));
41 void KNotificationBackend::notify(const Notification &n) {
42 QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
43 KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
44 KNotification::RaiseWidgetOnActivation
45 |KNotification::CloseWhenWidgetActivated
46 |KNotification::CloseOnTimeout);
47 connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
48 connect(notification, SIGNAL(closed()), SLOT(notificationClosed()));
49 notification->setActions(QStringList("View"));
50 _notificationIds[notification] = n.notificationId;
52 QtUi::mainWindow()->systemTray()->setAlert(true);
55 void KNotificationBackend::close(uint notificationId) {
56 Q_UNUSED(notificationId);
57 QtUi::mainWindow()->systemTray()->setAlert(false);
60 void KNotificationBackend::notificationActivated() {
62 KNotification *n = qobject_cast<KNotification *>(sender());
63 if(n && _notificationIds.contains(n))
64 id = _notificationIds.value(n);
66 notificationActivated(id);
69 void KNotificationBackend::notificationActivated(QSystemTrayIcon::ActivationReason reason) {
70 if(reason == QSystemTrayIcon::Trigger && _notificationIds.count() > 0) {
71 notificationActivated(_notificationIds.values().at(0)); // we choose a random one for now
75 void KNotificationBackend::notificationActivated(uint notificationId) {
76 QHash<KNotification *, uint>::iterator i = _notificationIds.begin();
77 while(i != _notificationIds.end()) {
78 if(i.value() == notificationId)
79 i = _notificationIds.erase(i);
84 QtUi::mainWindow()->systemTray()->setInhibitActivation();
85 emit activated(notificationId);
87 if(!_notificationIds.count())
88 QtUi::mainWindow()->systemTray()->setAlert(false);
92 void KNotificationBackend::notificationClosed() {
93 KNotification *n = qobject_cast<KNotification *>(sender());
94 if(n && _notificationIds.contains(n))
95 _notificationIds.remove(n);
98 SettingsPage *KNotificationBackend::createConfigWidget() const {
99 return new ConfigWidget();
102 /***************************************************************************/
104 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent) {
105 _widget = new KNotifyConfigWidget(this);
106 _widget->setApplication("quassel");
108 QVBoxLayout *layout = new QVBoxLayout(this);
109 layout->addWidget(_widget);
111 connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
114 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed) {
115 setChangedState(changed);
118 void KNotificationBackend::ConfigWidget::load() {
119 setChangedState(false);
122 void KNotificationBackend::ConfigWidget::save() {