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) {
40 void KNotificationBackend::notify(const Notification &n) {
41 QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
42 KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
43 KNotification::RaiseWidgetOnActivation
44 |KNotification::CloseWhenWidgetActivated
45 |KNotification::CloseOnTimeout);
46 connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
47 connect(notification, SIGNAL(closed()), SLOT(notificationClosed()));
48 notification->setActions(QStringList("View"));
49 _notificationIds[notification] = n.notificationId;
51 QtUi::mainWindow()->systemTray()->setAlert(true);
54 void KNotificationBackend::close(uint notificationId) {
55 Q_UNUSED(notificationId);
56 QtUi::mainWindow()->systemTray()->setAlert(false);
59 void KNotificationBackend::notificationActivated() {
61 KNotification *n = qobject_cast<KNotification *>(sender());
62 if(n && _notificationIds.contains(n))
63 id = _notificationIds.value(n);
68 void KNotificationBackend::notificationClosed() {
69 KNotification *n = qobject_cast<KNotification *>(sender());
70 if(n && _notificationIds.contains(n))
71 _notificationIds.remove(n);
74 SettingsPage *KNotificationBackend::createConfigWidget() const {
75 return new ConfigWidget();
78 /***************************************************************************/
80 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent) {
81 _widget = new KNotifyConfigWidget(this);
82 _widget->setApplication("quassel");
84 QVBoxLayout *layout = new QVBoxLayout(this);
85 layout->addWidget(_widget);
87 connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
90 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed) {
91 setChangedState(changed);
94 void KNotificationBackend::ConfigWidget::load() {
95 setChangedState(false);
98 void KNotificationBackend::ConfigWidget::save() {