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

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:28:57 UTC 2016


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

The following commit has been merged in the master branch:
commit 4023bf0599abba81a9ab711366f56733477f1df1
Author: Aleix Pol <aleixpol at kde.org>
Date:   Tue Sep 8 09:30:55 2015 +0200

    Only keep connections alive with unpaired devices when discovery is enabled
    
    At the moment, we were keeping the connection alive with every reachable
    device. While this works optimally for most use-cases, on networks with
    several devices with KDE Connect, the amount of connections grows
    exponentially.
    
    Reviewed by Albert Vaca
    
    CCBUG: 352424
---
 core/backends/loopback/loopbacklinkprovider.cpp |  2 -
 core/backends/loopback/loopbacklinkprovider.h   |  3 +-
 core/daemon.cpp                                 | 59 ++++++++++++++++++-------
 core/daemon.h                                   |  9 +++-
 core/device.cpp                                 |  2 +-
 kcm/kcm.cpp                                     |  2 +
 6 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/core/backends/loopback/loopbacklinkprovider.cpp b/core/backends/loopback/loopbacklinkprovider.cpp
index 5442c82..88eb22d 100644
--- a/core/backends/loopback/loopbacklinkprovider.cpp
+++ b/core/backends/loopback/loopbacklinkprovider.cpp
@@ -25,7 +25,6 @@
 LoopbackLinkProvider::LoopbackLinkProvider()
     : identityPackage(PACKAGE_TYPE_IDENTITY)
 {
-    loopbackDeviceLink = 0;
     NetworkPackage::createIdentityPackage(&identityPackage);
 }
 
@@ -55,7 +54,6 @@ void LoopbackLinkProvider::onStop()
 {
     if (loopbackDeviceLink) {
         delete loopbackDeviceLink;
-        loopbackDeviceLink = 0;
     }
 }
 
diff --git a/core/backends/loopback/loopbacklinkprovider.h b/core/backends/loopback/loopbacklinkprovider.h
index 9dcb529..b4190d1 100644
--- a/core/backends/loopback/loopbacklinkprovider.h
+++ b/core/backends/loopback/loopbacklinkprovider.h
@@ -23,6 +23,7 @@
 
 #include "../linkprovider.h"
 #include "loopbackdevicelink.h"
+#include <QPointer>
 
 class LoopbackLinkProvider
     : public LinkProvider
@@ -40,7 +41,7 @@ public:
     virtual void onNetworkChange();
 
 private:
-    LoopbackDeviceLink* loopbackDeviceLink;
+    QPointer<LoopbackDeviceLink> loopbackDeviceLink;
     NetworkPackage identityPackage;
     
 };
diff --git a/core/daemon.cpp b/core/daemon.cpp
index 1aa5ad6..ec97166 100644
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@ -44,6 +44,7 @@ struct DaemonPrivate
     //Every known device
     QMap<QString, Device*> mDevices;
 
+    bool discoveryMode = false;
 };
 
 Daemon* Daemon::instance()
@@ -80,8 +81,8 @@ Daemon::Daemon(QObject *parent, bool testMode)
     Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
         connect(a, SIGNAL(onConnectionReceived(NetworkPackage,DeviceLink*)),
                 this, SLOT(onNewDeviceLink(NetworkPackage,DeviceLink*)));
+        a->onStart();
     }
-    setDiscoveryEnabled(true);
 
     //Register on DBus
     QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
@@ -92,11 +93,36 @@ Daemon::Daemon(QObject *parent, bool testMode)
 
 void Daemon::setDiscoveryEnabled(bool b)
 {
-    Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
-        if (b)
-            a->onStart();
-        else
-            a->onStop();
+//     qDebug() << "setting discover..." << b;
+    if (b == d->discoveryMode)
+        return;
+
+    d->discoveryMode = b;
+    if (b) {
+        forceOnNetworkChange();
+    } else {
+        cleanDevices();
+    }
+}
+
+bool Daemon::isDiscoveryEnabled() const
+{
+    return d->discoveryMode;
+}
+
+void Daemon::removeDevice(Device* device)
+{
+    d->mDevices.remove(device->id());
+    device->deleteLater();
+    Q_EMIT deviceRemoved(device->id());
+}
+
+void Daemon::cleanDevices()
+{
+    Q_FOREACH(Device* device, d->mDevices) {
+        if (!device->isPaired()) {
+            removeDevice(device);
+        }
     }
 }
 
@@ -134,31 +160,32 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
             Q_EMIT deviceVisibilityChanged(id, true);
         }
     } else {
+        Device* device = new Device(this, identityPackage, dl);
         //qCDebug(KDECONNECT_CORE) << "It is a new device";
 
-        Device* device = new Device(this, identityPackage, dl);
-        connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
-        connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));
-        d->mDevices[id] = device;
+        if (d->discoveryMode && !device->isPaired()) {
+            device->deleteLater();
+        } else {
+            connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
+            connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));
+            d->mDevices[id] = device;
 
-        Q_EMIT deviceAdded(id);
+            Q_EMIT deviceAdded(id);
+        }
     }
 }
 
 void Daemon::onDeviceStatusChanged()
 {
     Device* device = (Device*)sender();
-    QString id = device->id();
 
     qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "status changed. Reachable:" << device->isReachable() << ". Paired: " << device->isPaired();
 
     if (!device->isReachable() && !device->isPaired()) {
         qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
-        d->mDevices.remove(id);
-        device->deleteLater();
-        Q_EMIT deviceRemoved(id);
+        removeDevice(device);
     } else {
-        Q_EMIT deviceVisibilityChanged(id, device->isReachable());
+        Q_EMIT deviceVisibilityChanged(device->id(), device->isReachable());
     }
 
 }
diff --git a/core/daemon.h b/core/daemon.h
index 4ef2415..91cfc48 100644
--- a/core/daemon.h
+++ b/core/daemon.h
@@ -37,6 +37,7 @@ class KDECONNECTCORE_EXPORT Daemon
 {
     Q_OBJECT
     Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.daemon")
+    Q_PROPERTY(bool discoveryEnabled READ isDiscoveryEnabled WRITE setDiscoveryEnabled)
 
 public:
     explicit Daemon(QObject *parent, bool testMode = false);
@@ -49,8 +50,9 @@ public:
      */
     static Daemon* instance();
 
-    //After calling this, signal deviceDiscovered will be triggered for each device
-    Q_SCRIPTABLE void setDiscoveryEnabled(bool b);
+    bool isDiscoveryEnabled() const;
+    void setDiscoveryEnabled(bool b);
+
     QList<Device*> devicesList() const;
 
     virtual void requestPairing(Device *d) = 0;
@@ -78,6 +80,9 @@ private Q_SLOTS:
     void onDeviceStatusChanged();
 
 private:
+    void removeDevice(Device* d);
+    void cleanDevices();
+
     QScopedPointer<struct DaemonPrivate> d;
 };
 
diff --git a/core/device.cpp b/core/device.cpp
index dc938e9..1d02f68 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -93,7 +93,7 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
 
 Device::~Device()
 {
-
+    qDeleteAll(m_deviceLinks);
 }
 
 bool Device::hasPlugin(const QString& name) const
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index d79b4a2..f8997f8 100644
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -104,6 +104,7 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
     connect(kcmUi->renameShow_button,SIGNAL(clicked()),
             this, SLOT(renameShow()));
 
+    daemon->setDiscoveryEnabled(true);
 }
 
 void KdeConnectKcm::renameShow()
@@ -133,6 +134,7 @@ void KdeConnectKcm::setRenameMode(bool b) {
 
 KdeConnectKcm::~KdeConnectKcm()
 {
+    daemon->setDiscoveryEnabled(false);
     delete kcmUi;
 }
 

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list