1 /***************************************************************************
2 * Copyright (C) 2005-09 Canonical Ltd *
3 * author: aurelien.gateau@canonical.com *
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 "indicatornotificationbackend.h"
23 #include <qindicateserver.h>
24 #include <qindicateindicatormessage.h>
26 #include "clientsettings.h"
30 class Indicator : public QIndicate::IndicatorMessage {
32 uint lastNotificationId;
35 IndicatorNotificationBackend::IndicatorNotificationBackend(QObject *parent)
36 : AbstractNotificationBackend(parent)
38 NotificationSettings notificationSettings;
39 _enabled = notificationSettings.value("Indicator/Enabled", true).toBool();
41 notificationSettings.notify("Indicator/Enabled", this, SLOT(enabledChanged(const QVariant &)));
43 _server = QIndicate::Server::defaultInstance();
44 _server->setType("message.im");
45 _server->setDesktopFile(DESKTOP_FILE);
51 IndicatorNotificationBackend::~IndicatorNotificationBackend() {
52 qDeleteAll(_indicatorHash);
55 void IndicatorNotificationBackend::notify(const Notification ¬ification) {
59 if (notification.type != Highlight && notification.type != PrivMsg) {
62 Indicator *indicator = _indicatorHash.value(notification.bufferId);
64 indicator = new Indicator;
65 _indicatorHash.insert(notification.bufferId, indicator);
67 indicator->lastNotificationId = notification.notificationId;
68 indicator->setProperty("sender", notification.sender);
69 indicator->setProperty("time", QTime::currentTime());
70 qDebug() << "FIXME icon";
74 void IndicatorNotificationBackend::close(uint notificationId) {
75 // If we find an indicator whose lastNotificationId is notificationId, we
78 IndicatorHash::Iterator
79 it = _indicatorHash.begin(),
80 end = _indicatorHash.end();
81 for (; it != end; ++it) {
82 if (it.value()->lastNotificationId == notificationId) {
87 // Not found, maybe there was no indicator for this notification or another
88 // notification happened after
91 _indicatorHash.erase(it);
95 void IndicatorNotificationBackend::enabledChanged(const QVariant &v) {
96 _enabled = v.toBool();
99 // TODO: Create indicators for existing highlighted buffers?
102 qDeleteAll(_indicatorHash);
106 SettingsPage *IndicatorNotificationBackend::createConfigWidget() const {
107 return new ConfigWidget();
110 /***************************************************************************/
112 IndicatorNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent)
113 : SettingsPage("Internal", "IndicatorNotification", parent)
117 connect(ui.enabled, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
120 IndicatorNotificationBackend::ConfigWidget::~ConfigWidget() {
123 void IndicatorNotificationBackend::ConfigWidget::widgetChanged() {
124 bool changed = enabled != ui.enabled->isChecked();
126 if(changed != hasChanged()) setChangedState(changed);
129 bool IndicatorNotificationBackend::ConfigWidget::hasDefaults() const {
133 void IndicatorNotificationBackend::ConfigWidget::defaults() {
134 ui.enabled->setChecked(false);
138 void IndicatorNotificationBackend::ConfigWidget::load() {
139 NotificationSettings s;
140 enabled = s.value("Indicator/Enabled", false).toBool();
142 ui.enabled->setChecked(enabled);
143 setChangedState(false);
146 void IndicatorNotificationBackend::ConfigWidget::save() {
147 NotificationSettings s;
148 s.setValue("Indicator/Enabled", ui.enabled->isChecked());