1 /***************************************************************************
2 * Copyright (C) 2005-08 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 "desktopnotificationbackend.h"
24 #include "clientsettings.h"
25 #include "networkmodel.h"
27 DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
28 _dbusInterface = new org::freedesktop::Notifications(
29 "org.freedesktop.Notifications",
30 "/org/freedesktop/Notifications",
31 QDBusConnection::sessionBus(), this);
32 _dbusNotificationId = 0;
33 connect(_dbusInterface, SIGNAL(NotificationClosed(uint, uint)), SLOT(desktopNotificationClosed(uint, uint)));
34 connect(_dbusInterface, SIGNAL(ActionInvoked(uint, const QString &)), SLOT(desktopNotificationInvoked(uint, const QString&)));
36 NotificationSettings notificationSettings;
37 _enabled = notificationSettings.value("DesktopNotification/Enabled", false).toBool();
38 _xHint = notificationSettings.value("DesktopNotification/XHint", 0).toInt();
39 _yHint = notificationSettings.value("DesktopNotification/YHint", 0).toInt();
40 notificationSettings.notify("DesktopNotification/Enabled", this, SLOT(enabledChanged(const QVariant &)));
41 notificationSettings.notify("DesktopNotification/XHint", this, SLOT(xHintChanged(const QVariant &)));
42 notificationSettings.notify("DesktopNotification/YHint", this, SLOT(yHintChanged(const QVariant &)));
45 DesktopNotificationBackend::~DesktopNotificationBackend() {
49 void DesktopNotificationBackend::enabledChanged(const QVariant &v) {
50 _enabled = v.toBool();
53 void DesktopNotificationBackend::xHintChanged(const QVariant &v) {
57 void DesktopNotificationBackend::yHintChanged(const QVariant &v) {
61 void DesktopNotificationBackend::notify(const Notification &n) {
64 QMap<QString, QVariant> hints;
66 hints["x"] = _xHint; // Standard hint: x location for the popup to show up
67 hints["y"] = _yHint; // Standard hint: y location for the popup to show up
69 // actions << "click" << "Click Me!";
71 QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
72 QString message = QString("<%1> %2").arg(n.sender, n.message);
74 QDBusReply<uint> reply = _dbusInterface->Notify(
75 "Quassel IRC", // Application name
76 _dbusNotificationId, // ID of previous notification to replace
77 "quassel", // Icon to display
78 title, // Summary / Header of the message to display
79 message, // Body of the message to display
80 actions, // Actions from which the user may choose
81 hints, // Hints to the server displaying the message
82 5000 // Timeout in milliseconds
85 if(!reply.isValid()) {
87 // could also happen if no notification service runs, so... whatever :)
88 //qDebug() << "Error on sending notification..." << reply.error();
91 _dbusNotificationId = reply.value();
95 void DesktopNotificationBackend::close(uint notificationId) {
96 Q_UNUSED(notificationId);
99 void DesktopNotificationBackend::desktopNotificationClosed(uint id, uint reason) {
100 Q_UNUSED(id); Q_UNUSED(reason);
101 // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
102 _dbusNotificationId = 0;
106 void DesktopNotificationBackend::desktopNotificationInvoked(uint id, const QString & action) {
107 Q_UNUSED(id); Q_UNUSED(action);
108 // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();