The WebPreviews are now controlled via a neat state machine
[quassel.git] / src / qtui / knotificationbackend.cpp
1 /***************************************************************************
2 *   Copyright (C) 2005-09 by the Quassel Project                          *
3 *   devel@quassel-irc.org                                                 *
4 *                                                                         *
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.                                           *
9 *                                                                         *
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.                          *
14 *                                                                         *
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 ***************************************************************************/
20
21 #include <QVBoxLayout>
22
23 #include <KNotification>
24 #include <KNotifyConfigWidget>
25
26 #include "knotificationbackend.h"
27
28 #include "client.h"
29 #include "icon.h"
30 #include "iconloader.h"
31 #include "networkmodel.h"
32 #include "qtui.h"
33
34 KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
35
36 }
37
38 void KNotificationBackend::notify(const Notification &n) {
39   //QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
40   QString message = QString("<b>&lt;%1&gt;</b> %2").arg(n.sender, n.message);
41   KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
42                                 KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
43   connect(notification, SIGNAL(activated()), SLOT(notificationActivated()));
44 }
45
46 void KNotificationBackend::close(uint notificationId) {
47   Q_UNUSED(notificationId);
48 }
49
50 void KNotificationBackend::notificationActivated() {
51   emit activated();
52 }
53
54 SettingsPage *KNotificationBackend::createConfigWidget() const {
55   return new ConfigWidget();
56 }
57
58 /***************************************************************************/
59
60 KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent) {
61   _widget = new KNotifyConfigWidget(this);
62   _widget->setApplication("quassel");
63
64   QVBoxLayout *layout = new QVBoxLayout(this);
65   layout->addWidget(_widget);
66
67   connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool)));
68 }
69
70 void KNotificationBackend::ConfigWidget::widgetChanged(bool changed) {
71   setChangedState(changed);
72 }
73
74 void KNotificationBackend::ConfigWidget::load() {
75   setChangedState(false);
76 }
77
78 void KNotificationBackend::ConfigWidget::save() {
79   _widget->save();
80   load();
81 }