diff options
author | Javier S. Pedro <dev.git@javispedro.com> | 2014-09-14 19:47:14 +0200 |
---|---|---|
committer | Javier S. Pedro <dev.git@javispedro.com> | 2014-09-14 19:47:14 +0200 |
commit | 4bc56bff80046b74926289be8825726296f39791 (patch) | |
tree | f7ebd1ddcbaf972181ce4515f22cb76f0fe94ea4 | |
parent | 4ec3c9fa5b33feb4f98401735664fa405107369c (diff) | |
download | salmeta-4bc56bff80046b74926289be8825726296f39791.tar.gz salmeta-4bc56bff80046b74926289be8825726296f39791.zip |
Prepare new plan for notification eavesdropping
-rw-r--r-- | salmeta.pro | 2 | ||||
-rw-r--r-- | src/notificationadaptor.cpp | 27 | ||||
-rw-r--r-- | src/notificationadaptor.h | 65 | ||||
-rw-r--r-- | src/notificationmonitor.cpp | 39 | ||||
-rw-r--r-- | src/notificationmonitor.h | 9 | ||||
-rw-r--r-- | src/org.freedesktop.Notifications.xml | 46 |
6 files changed, 17 insertions, 171 deletions
diff --git a/salmeta.pro b/salmeta.pro index 4a75956..8bf7ec8 100644 --- a/salmeta.pro +++ b/salmeta.pro @@ -19,7 +19,6 @@ SOURCES += src/salmeta.cpp \ src/widgetinfo.cpp \ src/widgetinfomodel.cpp \ src/availablewidgetsmodel.cpp \ - src/notificationadaptor.cpp \ src/notification.cpp HEADERS += \ @@ -32,7 +31,6 @@ HEADERS += \ src/widgetinfo.h \ src/widgetinfomodel.h \ src/availablewidgetsmodel.h \ - src/notificationadaptor.h \ src/notification.h OTHER_FILES += qml/salmeta.qml \ diff --git a/src/notificationadaptor.cpp b/src/notificationadaptor.cpp deleted file mode 100644 index 4279831..0000000 --- a/src/notificationadaptor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c NotificationAdaptor -a notificationadaptor.cpp org.freedesktop.Notifications.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#include "notificationadaptor.h" - -/* - * Implementation of adaptor class NotificationAdaptor - */ - -NotificationAdaptor::NotificationAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ -} - -uint NotificationAdaptor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout) -{ - // handle method call org.freedesktop.Notifications.Notify - static_cast<NotificationMonitor*>(parent())->handleNotification(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout); -} diff --git a/src/notificationadaptor.h b/src/notificationadaptor.h deleted file mode 100644 index 0fba973..0000000 --- a/src/notificationadaptor.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c NotificationAdaptor -a notificationadaptor.cpp org.freedesktop.Notifications.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef NOTIFICATIONADAPTOR -#define NOTIFICATIONADAPTOR - -#include <QtCore/QObject> -#include <QtCore/QMetaObject> -#include <QtCore/QVariant> -#include <QtDBus/QDBusAbstractAdaptor> -#include <QtCore/QList> -#include <QtCore/QMap> -#include <QtCore/QString> -#include <QtCore/QStringList> -#include <QtCore/QVariant> - -#include "notificationmonitor.h" - -/* - * Adaptor class for interface org.freedesktop.Notifications - */ -class NotificationAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") - Q_CLASSINFO("D-Bus Introspection", "" -" <interface name=\"org.freedesktop.Notifications\">\n" -" <method name=\"Notify\">\n" -" <arg direction=\"in\" type=\"s\" name=\"app_name\"/>\n" -" <arg direction=\"in\" type=\"u\" name=\"replaces_id\"/>\n" -" <arg direction=\"in\" type=\"s\" name=\"app_icon\"/>\n" -" <arg direction=\"in\" type=\"s\" name=\"summary\"/>\n" -" <arg direction=\"in\" type=\"s\" name=\"body\"/>\n" -" <arg direction=\"in\" type=\"as\" name=\"actions\"/>\n" -" <arg direction=\"in\" type=\"a{sv}\" name=\"hints\"/>\n" -" <arg direction=\"in\" type=\"i\" name=\"expire_timeout\"/>\n" -" <arg direction=\"out\" type=\"u\" name=\"id\"/>\n" -" <annotation value=\"QVariantHash\" name=\"org.qtproject.QtDBus.QtTypeName.In6\"/>\n" -" </method>\n" -" <method name=\"CloseNotification\">\n" -" <arg direction=\"in\" type=\"u\" name=\"id\"/>\n" -" </method>\n" -" </interface>\n" - <method name="CloseNotification"> - <arg name="id" type="u" direction="in"/> - </method> - "") -public: - explicit NotificationAdaptor(QObject *parent); - -public: // PROPERTIES -public Q_SLOTS: // METHODS - uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout); - void NotificationClosed(uint id, uint reason); -}; - -#endif diff --git a/src/notificationmonitor.cpp b/src/notificationmonitor.cpp index cdf4d50..50f7b91 100644 --- a/src/notificationmonitor.cpp +++ b/src/notificationmonitor.cpp @@ -3,29 +3,27 @@ #include <QtDBus/QDBusConnectionInterface> #include "notificationmonitor.h" -#include "notificationadaptor.h" static NotificationMonitor *global_monitor = 0; namespace { -void handleEavesdropCallFinished(QDBusPendingCallWatcher *watcher) -{ - QDBusPendingReply reply = *watcher; - if (reply.isError()) { - QDBusError error = reply.error(); - qWarning() << "Failure to eavesdrop for notifications:" << error.message(); - } else { - qDebug() << "Now eavesdropping notifications"; - } -} - } NotificationMonitor::NotificationMonitor(QObject *parent) : QObject(parent) { + QDBusConnection bus = QDBusConnection::sessionBus(); + + _watcher = new QDBusServiceWatcher("org.freedesktop.Notifications", bus, + QDBusServiceWatcher::WatchForOwnerChange, + this); + connect(_watcher, &QDBusServiceWatcher::serviceOwnerChanged, + this, &NotificationMonitor::handleServiceOwnerChanged); + + bus.interface()->call("AddMatch", + "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'"); } NotificationMonitor::~NotificationMonitor() @@ -35,25 +33,12 @@ NotificationMonitor::~NotificationMonitor() NotificationMonitor *NotificationMonitor::instance() { if (!global_monitor) { - QDBusConnection bus = QDBusConnection::sessionBus(); - - // First register the global monitor object that will listen for notifications... global_monitor = new NotificationMonitor; - new NotificationAdaptor(global_monitor); - bus.registerObject("/org/freedesktop/Notifications", global_monitor); - - // Now register for eavesdropping - QDBusConnectionInterface *dbus = bus.interface(); - QDBusPendingCall call = dbus->asyncCall("AddMatch", - "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'"); - - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call); - connect(watcher, &QDBusPendingCallWatcher::finished, &handleEavesdropCallFinished); } return global_monitor; } -void NotificationMonitor::handleNotification(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout) +void NotificationMonitor::handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) { - + qDebug() << "Service owner changed" << serviceName << oldOwner << newOwner; } diff --git a/src/notificationmonitor.h b/src/notificationmonitor.h index de9a0e7..eac06ff 100644 --- a/src/notificationmonitor.h +++ b/src/notificationmonitor.h @@ -3,6 +3,7 @@ #include <QtCore/QObject> #include <QtCore/QHash> +#include <QtDBus/QDBusServiceWatcher> #include "notification.h" @@ -22,12 +23,12 @@ private: explicit NotificationMonitor(QObject *parent = 0); private slots: - void handleNotification(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout); - void handleClosedNotification(uint id); - friend class NotificationAdaptor; + void handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); private: - QHash<int, + QDBusServiceWatcher *_watcher; + QHash<uint, Notification*> _pendingNotifications; + QHash<uint, Notification*> _notifications; }; #endif // NOTIFICATIONMONITOR_H diff --git a/src/org.freedesktop.Notifications.xml b/src/org.freedesktop.Notifications.xml deleted file mode 100644 index 89947c9..0000000 --- a/src/org.freedesktop.Notifications.xml +++ /dev/null @@ -1,46 +0,0 @@ -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> -<node> - <interface name="org.freedesktop.Notifications"> - <!-- Desktop Notification Specification interface --> - <method name="GetCapabilities"> - <arg name="capabilities" type="as" direction="out"/> - </method> - <method name="Notify"> - <arg name="app_name" type="s" direction="in"/> - <arg name="replaces_id" type="u" direction="in"/> - <arg name="app_icon" type="s" direction="in"/> - <arg name="summary" type="s" direction="in"/> - <arg name="body" type="s" direction="in"/> - <arg name="actions" type="as" direction="in"/> - <arg name="hints" type="a{sv}" direction="in"/> - <arg name="expire_timeout" type="i" direction="in"/> - <arg name="id" type="u" direction="out"/> - <annotation name="org.qtproject.QtDBus.QtTypeName.In6" value="QVariantHash"/> - </method> - <method name="CloseNotification"> - <arg name="id" type="u" direction="in"/> - </method> - <method name="GetServerInformation"> - <arg type="s" direction="out"/> - <arg name="name" type="s" direction="out"/> - <arg name="vendor" type="s" direction="out"/> - <arg name="version" type="s" direction="out"/> - </method> - <signal name="NotificationClosed"> - <arg name="id" type="u"/> - <arg name="reason" type="u"/> - </signal> - <signal name="ActionInvoked"> - <arg name="id" type="u"/> - <arg name="action_key" type="s"/> - </signal> - - <!-- Nemo extensions --> - <method name="GetNotifications"> - <arg name="app_name" type="s" direction="in"/> - <arg name="notifications" type="a(sussasa{sv}i)" direction="out"/> - <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList < Notification > "/> - </method> - </interface> -</node> - |