X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fdesktopnotificationbackend.cpp;h=dedade7017fbfc91335ddc396363409e72287954;hp=45d18b59802dce9afd171cc954c14ea37201900b;hb=42ff4d2a759746ccd65440a0dfc2e233e0b777ed;hpb=0c498574d2f26bae581bc8f9a01e739e1f9c3872 diff --git a/src/qtui/desktopnotificationbackend.cpp b/src/qtui/desktopnotificationbackend.cpp index 45d18b59..dedade70 100644 --- a/src/qtui/desktopnotificationbackend.cpp +++ b/src/qtui/desktopnotificationbackend.cpp @@ -1,5 +1,5 @@ /*************************************************************************** -* Copyright (C) 2005-08 by the Quassel Project * +* Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -26,18 +26,23 @@ #include "clientsettings.h" #include "networkmodel.h" -DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) { - _configWidget = new ConfigWidget(); - +DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) + : AbstractNotificationBackend(parent), + _lastDbusId(0) +{ _dbusInterface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", QDBusConnection::sessionBus(), this); + if(!_dbusInterface->isValid()) { + qWarning() << "DBus notification service not available!"; + return; + } + QStringList desktopCapabilities = _dbusInterface->GetCapabilities(); _daemonSupportsMarkup = desktopCapabilities.contains("body-markup"); - _lastDbusId = 0; connect(_dbusInterface, SIGNAL(NotificationClosed(uint, uint)), SLOT(desktopNotificationClosed(uint, uint))); connect(_dbusInterface, SIGNAL(ActionInvoked(uint, const QString &)), SLOT(desktopNotificationInvoked(uint, const QString&))); @@ -59,10 +64,6 @@ DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) : Abstra notificationSettings.notify("DesktopNotification/QueueNotifications", this, SLOT(queueNotificationsChanged(const QVariant &))); } -DesktopNotificationBackend::~DesktopNotificationBackend() { - delete _configWidget; -} - void DesktopNotificationBackend::enabledChanged(const QVariant &v) { _enabled = v.toBool(); } @@ -92,7 +93,7 @@ void DesktopNotificationBackend::useTimeoutChanged(const QVariant &v) { } void DesktopNotificationBackend::notify(const Notification &n) { - if(_enabled) { + if(_enabled && _dbusInterface->isValid() && (n.type == Highlight || n.type == PrivMsg)) { QStringList actions; QMap hints; @@ -103,7 +104,7 @@ void DesktopNotificationBackend::notify(const Notification &n) { uint oldId = _queueNotifications ? 0 : _lastDbusId; - // actions << "click" << "Click Me!"; + actions << "activate" << "View"; QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId); QString message = QString("<%1> %2").arg(n.sender, n.message); @@ -151,11 +152,19 @@ void DesktopNotificationBackend::desktopNotificationClosed(uint id, uint reason) void DesktopNotificationBackend::desktopNotificationInvoked(uint id, const QString & action) { - Q_UNUSED(id); Q_UNUSED(action); + Q_UNUSED(action); + foreach(uint ourid, _idMap.keys()) { + if(_idMap.value(ourid) != id) + continue; + emit activated(ourid); + return; + } + + emit activated(); } -SettingsPage *DesktopNotificationBackend::configWidget() const { - return _configWidget; +SettingsPage *DesktopNotificationBackend::createConfigWidget() const { + return new ConfigWidget(); } /***************************************************************************/ @@ -203,7 +212,7 @@ void DesktopNotificationBackend::ConfigWidget::load() { NotificationSettings s; enabled = s.value("DesktopNotification/Enabled", false).toBool(); useTimeout = s.value("DesktopNotification/UseTimeout", true).toBool(); - timeout = s.value("DesktopNotification/Timeout", 10).toInt(); + timeout = s.value("DesktopNotification/Timeout", 10000).toInt(); useHints = s.value("DesktopNotification/UseHints", false).toBool(); xHint = s.value("DesktopNotification/XHint", 0).toInt(); yHint = s.value("DesktopNotification/YHint", 0).toInt();