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

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


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

The following commit has been merged in the master branch:
commit 7af7dbdc2f0f28edb9e546290bd2bfc3b50dc698
Author: Aleix Pol <aleixpol at kde.org>
Date:   Sat Mar 14 02:30:35 2015 +0100

    Improve DevicesModel::receivedDeviceList
    
    Make the population asynchronous on dbus. Wait for the device list and
    don't populate it until it's ready. There's no reason to block.
    Don't emit after endInsertRows. It doesn't help, as the views will have
    already refreshed.
---
 interfaces/devicesmodel.cpp | 40 ++++++++++++++++++++++++++--------------
 interfaces/devicesmodel.h   |  5 ++++-
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp
index a3cba83..1debc4a 100644
--- a/interfaces/devicesmodel.cpp
+++ b/interfaces/devicesmodel.cpp
@@ -100,13 +100,8 @@ void DevicesModel::setDisplayFilter(int flags)
 
 void DevicesModel::refreshDeviceList()
 {
-    if (!m_deviceList.isEmpty()) {
-        beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
-        m_deviceList.clear();
-        endRemoveRows();
-    }
-
     if (!m_dbusInterface->isValid()) {
+        clearDevices();
         qCDebug(KDECONNECT_INTERFACES) << "dbus interface not valid";
         return;
     }
@@ -115,22 +110,39 @@ void DevicesModel::refreshDeviceList()
     bool onlyReachable = (m_displayFilter & StatusReachable);
 
     QDBusPendingReply<QStringList> pendingDeviceIds = m_dbusInterface->devices(onlyReachable, onlyPaired);
-    pendingDeviceIds.waitForFinished();
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingDeviceIds, this);
+
+    QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+                     this, SLOT(receivedDeviceList(QDBusPendingCallWatcher*)));
+}
+
+void DevicesModel::receivedDeviceList(QDBusPendingCallWatcher* watcher)
+{
+    clearDevices();
+    QDBusPendingReply<QStringList> pendingDeviceIds = *watcher;
     if (pendingDeviceIds.isError()) {
         qCDebug(KDECONNECT_INTERFACES) << pendingDeviceIds.error();
         return;
     }
 
-    const QStringList& deviceIds = pendingDeviceIds.value();
+    Q_ASSERT(m_deviceList.isEmpty());
+    const QStringList deviceIds = pendingDeviceIds.value();
+    beginInsertRows(QModelIndex(), 0, deviceIds.count());
     Q_FOREACH(const QString& id, deviceIds) {
-        int firstRow = m_deviceList.size();
-        int lastRow = firstRow;
-        beginInsertRows(QModelIndex(), firstRow, lastRow);
-        m_deviceList.append(new DeviceDbusInterface(id,this));
-        endInsertRows();
+        m_deviceList.append(new DeviceDbusInterface(id, this));
     }
+    endInsertRows();
+    watcher->deleteLater();
+}
 
-    Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
+void DevicesModel::clearDevices()
+{
+    if (!m_deviceList.isEmpty()) {
+        beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
+        qDeleteAll(m_deviceList);
+        m_deviceList.clear();
+        endRemoveRows();
+    }
 }
 
 QVariant DevicesModel::data(const QModelIndex& index, int role) const
diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h
index caa3f0a..6fc0acd 100644
--- a/interfaces/devicesmodel.h
+++ b/interfaces/devicesmodel.h
@@ -21,13 +21,13 @@
 #ifndef DEVICESMODEL_H
 #define DEVICESMODEL_H
 
-#include <QAbstractItemModel>
 #include <QAbstractListModel>
 #include <QPixmap>
 #include <QList>
 
 #include "interfaces/kdeconnectinterfaces_export.h"
 
+class QDBusPendingCallWatcher;
 class DaemonDbusInterface;
 class DeviceDbusInterface;
 
@@ -74,11 +74,14 @@ private Q_SLOTS:
     void deviceAdded(const QString& id);
     void deviceRemoved(const QString& id);
     void refreshDeviceList();
+    void receivedDeviceList(QDBusPendingCallWatcher* watcher);
 
 Q_SIGNALS:
     void rowsChanged();
 
 private:
+    void clearDevices();
+
     DaemonDbusInterface* m_dbusInterface;
     QList<DeviceDbusInterface*> m_deviceList;
     StatusFlags m_displayFilter;

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list