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

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


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

The following commit has been merged in the master branch:
commit a9d2840664a90e11461d31180cd3d5320fefd61f
Author: Aleix Pol <aleixpol at kde.org>
Date:   Wed Sep 9 20:09:04 2015 +0200

    Use acquire and release instead of a boolean property
    
    This way we hope we won't end up without discovery if 2 instances need
    discovery at the same time.
    
    Reviewed by Albert Vaca
---
 core/daemon.cpp             | 33 ++++++++++++++++++++-------------
 core/daemon.h               |  8 ++++----
 interfaces/devicesmodel.cpp | 15 ++++++++++++++-
 kcm/kcm.cpp                 |  3 ---
 4 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/core/daemon.cpp b/core/daemon.cpp
index 81084c2..9af4819 100644
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@ -44,7 +44,7 @@ struct DaemonPrivate
     //Every known device
     QMap<QString, Device*> mDevices;
 
-    bool discoveryMode = false;
+    QSet<QString> mDiscoveryModeAcquisitions;
 };
 
 Daemon* Daemon::instance()
@@ -91,23 +91,26 @@ Daemon::Daemon(QObject *parent, bool testMode)
     qCDebug(KDECONNECT_CORE) << "KdeConnect daemon started";
 }
 
-void Daemon::setDiscoveryEnabled(bool b)
+void Daemon::acquireDiscoveryMode(const QString &key)
 {
-//     qDebug() << "setting discover..." << b;
-    if (b == d->discoveryMode)
-        return;
+    bool oldState = d->mDiscoveryModeAcquisitions.isEmpty();
 
-    d->discoveryMode = b;
-    if (b) {
+    d->mDiscoveryModeAcquisitions.insert(key);
+
+    if (oldState != d->mDiscoveryModeAcquisitions.isEmpty()) {
         forceOnNetworkChange();
-    } else {
-        cleanDevices();
     }
 }
 
-bool Daemon::isDiscoveryEnabled() const
+void Daemon::releaseDiscoveryMode(const QString &key)
 {
-    return d->discoveryMode;
+    bool oldState = d->mDiscoveryModeAcquisitions.isEmpty();
+
+    d->mDiscoveryModeAcquisitions.remove(key);
+
+    if (oldState != d->mDiscoveryModeAcquisitions.isEmpty()) {
+        cleanDevices();
+    }
 }
 
 void Daemon::removeDevice(Device* device)
@@ -165,7 +168,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
 
         //we discard the connections that we created but it's not paired.
         //we keep the remotely initiated ones, since the remotes require them
-        if (!isDiscoveryEnabled() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
+        if (!isDiscoveringDevices() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
             device->deleteLater();
         } else {
             connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
@@ -218,8 +221,12 @@ QList<Device*> Daemon::devicesList() const
     return d->mDevices.values();
 }
 
+bool Daemon::isDiscoveringDevices() const
+{
+    return !d->mDiscoveryModeAcquisitions.isEmpty();
+}
+
 Daemon::~Daemon()
 {
 
 }
-
diff --git a/core/daemon.h b/core/daemon.h
index 91cfc48..dca3e07 100644
--- a/core/daemon.h
+++ b/core/daemon.h
@@ -37,7 +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)
+    Q_PROPERTY(bool isDiscoveringDevices READ isDiscoveringDevices)
 
 public:
     explicit Daemon(QObject *parent, bool testMode = false);
@@ -50,9 +50,6 @@ public:
      */
     static Daemon* instance();
 
-    bool isDiscoveryEnabled() const;
-    void setDiscoveryEnabled(bool b);
-
     QList<Device*> devicesList() const;
 
     virtual void requestPairing(Device *d) = 0;
@@ -60,6 +57,8 @@ public:
     virtual QNetworkAccessManager* networkAccessManager();
 
 public Q_SLOTS:
+    Q_SCRIPTABLE void acquireDiscoveryMode(const QString &id);
+    Q_SCRIPTABLE void releaseDiscoveryMode(const QString &id);
 
     Q_SCRIPTABLE void forceOnNetworkChange();
 
@@ -80,6 +79,7 @@ private Q_SLOTS:
     void onDeviceStatusChanged();
 
 private:
+    bool isDiscoveringDevices() const;
     void removeDevice(Device* d);
     void cleanDevices();
 
diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp
index 9b30ce8..7b0fdbb 100644
--- a/interfaces/devicesmodel.cpp
+++ b/interfaces/devicesmodel.cpp
@@ -34,6 +34,10 @@
 
 Q_LOGGING_CATEGORY(KDECONNECT_INTERFACES, "kdeconnect.interfaces");
 
+static QString createId() { return QCoreApplication::instance()->applicationName()+QString::number(QCoreApplication::applicationPid()); }
+
+Q_GLOBAL_STATIC_WITH_ARGS(QString, s_keyId, (createId()));
+
 DevicesModel::DevicesModel(QObject *parent)
     : QAbstractListModel(parent)
     , m_dbusInterface(new DaemonDbusInterface(this))
@@ -59,7 +63,8 @@ DevicesModel::DevicesModel(QObject *parent)
     connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &DevicesModel::refreshDeviceList);
     connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &DevicesModel::clearDevices);
 
-    refreshDeviceList();
+    //refresh the view, acquireDiscoveryMode if necessary
+    setDisplayFilter(NoFilter);
 }
 
 QHash< int, QByteArray > DevicesModel::roleNames() const
@@ -74,6 +79,7 @@ QHash< int, QByteArray > DevicesModel::roleNames() const
 
 DevicesModel::~DevicesModel()
 {
+    m_dbusInterface->releaseDiscoveryMode(*s_keyId);
 }
 
 int DevicesModel::rowForDevice(const QString& id) const
@@ -147,6 +153,13 @@ int DevicesModel::displayFilter() const
 void DevicesModel::setDisplayFilter(int flags)
 {
     m_displayFilter = (StatusFilterFlag)flags;
+
+    const bool onlyReachable = (m_displayFilter & StatusFilterFlag::Reachable);
+    if (onlyReachable)
+        m_dbusInterface->releaseDiscoveryMode(*s_keyId);
+    else
+        m_dbusInterface->acquireDiscoveryMode(*s_keyId);
+
     refreshDeviceList();
 }
 
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index 82fcab4..a2ac580 100644
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -103,8 +103,6 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
             this, SLOT(renameDone()));
     connect(kcmUi->renameShow_button,SIGNAL(clicked()),
             this, SLOT(renameShow()));
-
-    daemon->setDiscoveryEnabled(true);
 }
 
 void KdeConnectKcm::renameShow()
@@ -134,7 +132,6 @@ void KdeConnectKcm::setRenameMode(bool b) {
 
 KdeConnectKcm::~KdeConnectKcm()
 {
-    daemon->setDiscoveryEnabled(false);
     delete kcmUi;
 }
 

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list