[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:29:25 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=2a74eb6

The following commit has been merged in the master branch:
commit 2a74eb68f883bd17731aec98cdaaa87ab6d849a6
Author: Holger Kaelberer <holger.k at elberer.de>
Date:   Thu Sep 10 16:36:03 2015 +0200

    notifications: add initial support for desktop-to-xxx notifications
    
    Eavesdrop on the Notify call of the org.freedesktop.Notifications
    dbus-interface, proxy all caught notifications to our peer device and
    track them in the internal notifications-list.
    
    Also fix "cancel" requests from peer devices, by cutting of
    kdeconnect-android's id-prefix.
---
 plugins/notifications/CMakeLists.txt               |   1 +
 .../notifications/notificationsdbusinterface.cpp   |  19 +++-
 plugins/notifications/notificationsdbusinterface.h |   2 +-
 plugins/notifications/notificationslistener.cpp    | 101 +++++++++++++++++++++
 ...tificationsplugin.h => notificationslistener.h} |  40 ++++----
 plugins/notifications/notificationsplugin.cpp      |   3 +
 plugins/notifications/notificationsplugin.h        |   2 +
 7 files changed, 141 insertions(+), 27 deletions(-)

diff --git a/plugins/notifications/CMakeLists.txt b/plugins/notifications/CMakeLists.txt
index 41c5b78..fbb459e 100644
--- a/plugins/notifications/CMakeLists.txt
+++ b/plugins/notifications/CMakeLists.txt
@@ -4,6 +4,7 @@ set(kdeconnect_notifications_SRCS
     notification.cpp
     notificationsplugin.cpp
     notificationsdbusinterface.cpp
+    notificationslistener.cpp
 )
 
 kdeconnect_add_plugin(kdeconnect_notifications JSON kdeconnect_notifications.json SOURCES ${kdeconnect_notifications_SRCS})
diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp
index 3c504c6..4e2c7e0 100644
--- a/plugins/notifications/notificationsdbusinterface.cpp
+++ b/plugins/notifications/notificationsdbusinterface.cpp
@@ -45,6 +45,7 @@ NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin)
 
 NotificationsDbusInterface::~NotificationsDbusInterface()
 {
+    qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface";
 }
 
 void NotificationsDbusInterface::clearNotifications()
@@ -60,7 +61,21 @@ QStringList NotificationsDbusInterface::activeNotifications()
 void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
 {
     if (np.get<bool>("isCancel")) {
-        removeNotification(np.get<QString>("id"));
+        QString id = np.get<QString>("id");
+        // cut off kdeconnect-android's prefix if there:
+        if (id.startsWith("org.kde.kdeconnect_tp::"))
+            id = id.mid(id.indexOf("::") + 2);
+        removeNotification(id);
+    } else if (np.get<bool>("isRequest")) {
+        for (const auto& n: mNotifications) {
+            NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
+            np.set("id", n->internalId());
+            np.set("appName", n->appName());
+            np.set("ticker", n->ticker());
+            np.set("isClearable", n->dismissable());
+            np.set("requestAnswer", true);
+            mPlugin->sendPackage(np);
+        }
     } else {
 
         //TODO: Uncoment when we are able to display app icon on plasmoid
@@ -114,7 +129,7 @@ void NotificationsDbusInterface::removeNotification(const QString& internalId)
     qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId;
 
     if (!mInternalIdToPublicId.contains(internalId)) {
-        qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found";
+        qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found: " << internalId;
         return;
     }
 
diff --git a/plugins/notifications/notificationsdbusinterface.h b/plugins/notifications/notificationsdbusinterface.h
index 21d5a6a..fd36a10 100644
--- a/plugins/notifications/notificationsdbusinterface.h
+++ b/plugins/notifications/notificationsdbusinterface.h
@@ -45,6 +45,7 @@ public:
     void processPackage(const NetworkPackage& np);
     void clearNotifications();
     void dismissRequested(const QString& notification);
+    void addNotification(Notification* noti);
 
 public Q_SLOTS:
     Q_SCRIPTABLE QStringList activeNotifications();
@@ -54,7 +55,6 @@ Q_SIGNALS:
     Q_SCRIPTABLE void notificationRemoved(const QString& publicId);
 
 private /*methods*/:
-    void addNotification(Notification* noti);
     void removeNotification(const QString& internalId);
     QString newId(); //Generates successive identifitiers to use as public ids
 
diff --git a/plugins/notifications/notificationslistener.cpp b/plugins/notifications/notificationslistener.cpp
new file mode 100644
index 0000000..88ad98b
--- /dev/null
+++ b/plugins/notifications/notificationslistener.cpp
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2015 Holger Kaelberer <holger.k at elberer.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusInterface>
+#include <QtDebug>
+#include <QLoggingCategory>
+
+#include <core/device.h>
+#include <core/kdeconnectplugin.h>
+
+#include "notificationslistener.h"
+#include "notificationsplugin.h"
+#include "notification_debug.h"
+#include "notificationsdbusinterface.h"
+
+NotificationsListener::NotificationsListener(KdeConnectPlugin* aPlugin,
+                                             NotificationsDbusInterface* aDbusInterface)
+    : QDBusAbstractAdaptor(aPlugin),
+      mPlugin(aPlugin),
+      dbusInterface(aDbusInterface)
+{
+    bool ret = QDBusConnection::sessionBus()
+                .registerObject("/org/freedesktop/Notifications",
+                                this,
+                                QDBusConnection::ExportScriptableContents);
+    if (!ret)
+        qCWarning(KDECONNECT_PLUGIN_NOTIFICATION)
+                << "Error registering notifications listener for device"
+                << mPlugin->device()->name() << ":"
+                << QDBusConnection::sessionBus().lastError();
+    else
+        qCDebug(KDECONNECT_PLUGIN_NOTIFICATION)
+                << "Registered notifications listener for device"
+                << mPlugin->device()->name();
+
+    QDBusInterface iface("org.freedesktop.DBus", "/org/freedesktop/DBus",
+                         "org.freedesktop.DBus");
+    iface.call("AddMatch",
+               "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
+}
+
+NotificationsListener::~NotificationsListener()
+{
+    qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsListener";
+    QDBusInterface iface("org.freedesktop.DBus", "/org/freedesktop/DBus",
+                         "org.freedesktop.DBus");
+    QDBusMessage res = iface.call("RemoveMatch",
+                                  "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
+    QDBusConnection::sessionBus().unregisterObject("/org/freedesktop/Notifications");
+}
+
+uint NotificationsListener::Notify(const QString &appName, uint replacesId,
+                                   const QString &appIcon,
+                                   const QString &summary, const QString &body,
+                                   const QStringList &actions,
+                                   const QVariantMap &hints, int timeout)
+{
+    static int id = 0;
+    qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Got notification appName=" << appName << "replacesId=" << replacesId << "appIcon=" << appIcon << "summary=" << summary << "body=" << body << "actions=" << actions << "hints=" << hints << "timeout=" << timeout;
+    Q_UNUSED(hints);
+    Q_UNUSED(actions);
+    Q_UNUSED(appIcon);
+    Q_UNUSED(body);
+
+    // skip our own notifications
+    if (appName == QLatin1String("KDE Connect"))
+        return 0;
+
+    NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
+    np.set("id", QString::number(replacesId > 0 ? replacesId : ++id));
+    np.set("appName", appName);
+    np.set("ticker", summary);
+    np.set("isClearable", timeout == 0);  // KNotifications are persistent if
+                                          // timeout == 0, for other notifications
+                                          // clearability is pointless
+
+    Notification *notification = new Notification(np, QString(), this);
+    dbusInterface->addNotification(notification);
+
+    mPlugin->sendPackage(np);
+
+    return (replacesId > 0 ? replacesId : id);
+}
diff --git a/plugins/notifications/notificationsplugin.h b/plugins/notifications/notificationslistener.h
similarity index 54%
copy from plugins/notifications/notificationsplugin.h
copy to plugins/notifications/notificationslistener.h
index 7cc67c5..7887b59 100644
--- a/plugins/notifications/notificationsplugin.h
+++ b/plugins/notifications/notificationslistener.h
@@ -1,5 +1,5 @@
 /**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ * Copyright 2015 Holger Kaelberer <holger.k at elberer.de>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -18,37 +18,29 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef NOTIFICATIONSPLUGIN_H
-#define NOTIFICATIONSPLUGIN_H
+#include <QtDBus/QDBusAbstractAdaptor>
+#include <core/device.h>
 
-#include <knotification.h>
-
-#include <core/kdeconnectplugin.h>
-#define PACKAGE_TYPE_NOTIFICATION QLatin1String("kdeconnect.notification")
-
-/*
- * This class is just a proxy for NotificationsDbusInterface
- * because it can not inherit from QDBusAbstractAdaptor and
- * KdeConnectPlugin at the same time (both are QObject)
- */
+class KdeConnectPlugin;
 class NotificationsDbusInterface;
+class Notification;
 
-class NotificationsPlugin
-    : public KdeConnectPlugin
+class NotificationsListener : public QDBusAbstractAdaptor
 {
     Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications")
 
 public:
-    explicit NotificationsPlugin(QObject *parent, const QVariantList &args);
-    virtual ~NotificationsPlugin();
-    
-public Q_SLOTS:
-    virtual bool receivePackage(const NetworkPackage& np) override;
-    virtual void connected() override;
+    explicit NotificationsListener(KdeConnectPlugin* aPlugin,
+                                   NotificationsDbusInterface* aDbusInterface);
+    virtual ~NotificationsListener();
 
 private:
-    NotificationsDbusInterface* notificationsDbusInterface;
+    KdeConnectPlugin* mPlugin;
+    NotificationsDbusInterface* dbusInterface;
 
+public Q_SLOTS:
+    Q_SCRIPTABLE uint Notify(const QString&, uint, const QString&,
+                             const QString&, const QString&,
+                             const QStringList&, const QVariantMap&, int);
 };
-
-#endif
diff --git a/plugins/notifications/notificationsplugin.cpp b/plugins/notifications/notificationsplugin.cpp
index badb5d3..f47f5d8 100644
--- a/plugins/notifications/notificationsplugin.cpp
+++ b/plugins/notifications/notificationsplugin.cpp
@@ -21,6 +21,7 @@
 #include "notificationsplugin.h"
 
 #include "notificationsdbusinterface.h"
+#include "notificationslistener.h"
 #include "notification_debug.h"
 
 #include <KPluginFactory>
@@ -33,6 +34,7 @@ NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& ar
     : KdeConnectPlugin(parent, args)
 {
     notificationsDbusInterface = new NotificationsDbusInterface(this);
+    notificationsListener = new NotificationsListener(this, notificationsDbusInterface);
 }
 
 void NotificationsPlugin::connected()
@@ -44,6 +46,7 @@ void NotificationsPlugin::connected()
 
 NotificationsPlugin::~NotificationsPlugin()
 {
+    qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsPlugin";
     //FIXME: Qt dbus does not allow to remove an adaptor! (it causes a crash in
     // the next dbus access to its parent). The implication of not deleting this
     // is that disabling the plugin leaks the interface. As a mitigation we are
diff --git a/plugins/notifications/notificationsplugin.h b/plugins/notifications/notificationsplugin.h
index 7cc67c5..599c89c 100644
--- a/plugins/notifications/notificationsplugin.h
+++ b/plugins/notifications/notificationsplugin.h
@@ -32,6 +32,7 @@
  * KdeConnectPlugin at the same time (both are QObject)
  */
 class NotificationsDbusInterface;
+class NotificationsListener;
 
 class NotificationsPlugin
     : public KdeConnectPlugin
@@ -48,6 +49,7 @@ public Q_SLOTS:
 
 private:
     NotificationsDbusInterface* notificationsDbusInterface;
+    NotificationsListener* notificationsListener;
 
 };
 

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list