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

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:26:46 UTC 2016


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

The following commit has been merged in the master branch:
commit d1658564f98e52624949c99b80b74d216ba0928b
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Fri Aug 16 00:25:13 2013 +0200

    Sort devices by status in KCM.
    
    Some coded added to keep the current selection when reordering.
---
 kcm/CMakeLists.txt                                 |  2 +-
 kcm/devicesmodel.cpp                               | 36 +++-----------
 kcm/devicesmodel.h                                 |  4 +-
 kcm/devicessortproxymodel.cpp                      | 57 ++++++++++++++++++++++
 .../tcpdevicelink.h => kcm/devicessortproxymodel.h | 39 ++++++---------
 kcm/kcm.cpp                                        | 51 +++++++++++++------
 kcm/kcm.h                                          |  7 ++-
 7 files changed, 123 insertions(+), 73 deletions(-)

diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt
index 9c39d42..7796122 100644
--- a/kcm/CMakeLists.txt
+++ b/kcm/CMakeLists.txt
@@ -1,5 +1,5 @@
 
-set(kcm_SRCS devicesmodel.cpp
+set(kcm_SRCS devicessortproxymodel.cpp devicesmodel.cpp
     kcm.cpp
     #wizard.cpp
     dbusinterfaces.cpp
diff --git a/kcm/devicesmodel.cpp b/kcm/devicesmodel.cpp
index 3500c7f..c03c52c 100644
--- a/kcm/devicesmodel.cpp
+++ b/kcm/devicesmodel.cpp
@@ -73,6 +73,8 @@ void DevicesModel::deviceStatusChanged(const QString& id)
     //FIXME: Emitting dataChanged does not invalidate the view, refreshDeviceList does
     //Q_EMIT dataChanged(index(0),index(rowCount()));
     refreshDeviceList();
+
+
 }
 
 void DevicesModel::refreshDeviceList()
@@ -91,36 +93,10 @@ void DevicesModel::refreshDeviceList()
         endInsertRows();
     }
 
-    Q_EMIT dataChanged(index(0),index(deviceIds.count()));
+    Q_EMIT dataChanged(index(0), index(deviceIds.count()));
 
 }
-/*
-bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
-{
-    if (row < 0 || row > m_deviceList.count() || count < 1) {
-        return false;
-    }
-    beginInsertRows(parent, row, row + count - 1);
-    for (int i = row; i < row + count; ++i) {
-        m_deviceList.insert(i, new Device());
-    }
-    endInsertRows();
-    return true;
-}
 
-bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
-{
-    if (row < 0 || row > m_deviceList.count() || count < 1) {
-        return false;
-    }
-    beginRemoveRows(parent, row, row + count - 1);
-    for (int i = row; i < row + count; ++i) {
-        m_deviceList.removeAt(row);
-    }
-    endRemoveRows();
-    return true;
-}
-*/
 QVariant DevicesModel::data(const QModelIndex &index, int role) const
 {
 
@@ -159,8 +135,10 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
             return QString(device->name());
         case StatusModelRole: {
             int status = StatusUnknown;
-            if (device->paired()) status |= StatusPaired;
-            if (device->reachable()) status |= StatusReachable;
+            if (device->reachable()) {
+                status |= StatusReachable;
+                if (device->paired()) status |= StatusPaired;
+            }
             return status;
         }
         default:
diff --git a/kcm/devicesmodel.h b/kcm/devicesmodel.h
index 1b9100f..42d1a9e 100644
--- a/kcm/devicesmodel.h
+++ b/kcm/devicesmodel.h
@@ -38,8 +38,8 @@ public:
     enum ModelRoles {
         NameModelRole = Qt::DisplayRole,
         IconModelRole = Qt::DecorationRole,
+        StatusModelRole = Qt::InitialSortOrderRole,
         IdModelRole = Qt::UserRole,
-        StatusModelRole //= Qt::UserRole+1
     };
     enum StatusFlags {
         StatusUnknown = 0x00,
@@ -53,8 +53,6 @@ public:
 
     virtual QVariant data(const QModelIndex &index, int role) const;
     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
-    //virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
-    //virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
 
     DeviceDbusInterface* getDevice(const QModelIndex& index);
 
diff --git a/kcm/devicessortproxymodel.cpp b/kcm/devicessortproxymodel.cpp
new file mode 100644
index 0000000..5cca655
--- /dev/null
+++ b/kcm/devicessortproxymodel.cpp
@@ -0,0 +1,57 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2013  <copyright holder> <email>
+ *
+ * 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 "devicessortproxymodel.h"
+#include "devicesmodel.h"
+
+#include <QDebug>
+
+DevicesSortProxyModel::DevicesSortProxyModel(DevicesModel* devicesModel)
+    : QSortFilterProxyModel(devicesModel)
+{
+    setSourceModel(devicesModel);
+    setSortRole(DevicesModel::StatusModelRole);
+    connect(devicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+            this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
+    sort(0);
+}
+
+void DevicesSortProxyModel::sourceDataChanged(QModelIndex , QModelIndex )
+{
+    sort(0);
+}
+
+bool DevicesSortProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
+{
+    QVariant leftData = sourceModel()->data(left, Qt::InitialSortOrderRole);
+    QVariant rightData = sourceModel()->data(right, Qt::InitialSortOrderRole);
+
+    return leftData.toInt() > rightData.toInt();
+}
+
+bool DevicesSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
+{
+    Q_UNUSED(source_row);
+    Q_UNUSED(source_parent);
+    //Possible to-do: Implement filter
+    return true;
+}
diff --git a/daemon/devicelinks/tcpdevicelink.h b/kcm/devicessortproxymodel.h
similarity index 58%
copy from daemon/devicelinks/tcpdevicelink.h
copy to kcm/devicessortproxymodel.h
index 2fbc2d2..6fca1dc 100644
--- a/daemon/devicelinks/tcpdevicelink.h
+++ b/kcm/devicessortproxymodel.h
@@ -1,5 +1,6 @@
-/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2013  <copyright holder> <email>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -16,36 +17,26 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
  */
 
-#ifndef TCPDEVICELINK_H
-#define TCPDEVICELINK_H
-
-#include <QObject>
-#include <QString>
-#include <qthread.h>
+#ifndef DEVICESSORTPROXYMODEL_H
+#define DEVICESSORTPROXYMODEL_H
 
-#include "devicelink.h"
-#include <QTcpSocket>
+#include <QSortFilterProxyModel>
 
-class AvahiTcpLinkProvider;
+class DevicesModel;
 
-class TcpDeviceLink
-    : public DeviceLink
+class DevicesSortProxyModel : public QSortFilterProxyModel
 {
     Q_OBJECT
-
 public:
-    TcpDeviceLink(const QString& d, LinkProvider* a, QTcpSocket* socket);
-
-    bool sendPackage(const NetworkPackage& np) const;
-
-private Q_SLOTS:
-    void dataReceived();
-
-private:
-    QTcpSocket* mSocket;
+    DevicesSortProxyModel(DevicesModel* devicesModel);
+    virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
+    virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
 
+public slots:
+    void sourceDataChanged(QModelIndex,QModelIndex);
 };
 
-#endif // UDPDEVICELINK_H
+#endif // DEVICESSORTPROXYMODEL_H
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index d6156c0..ca82bfc 100644
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -32,6 +32,8 @@
 #include <QDBusConnection>
 #include <QDBusInterface>
 
+#include "devicessortproxymodel.h"
+
 #include <KServiceTypeTrader>
 #include <KPluginInfo>
 #include <KDebug>
@@ -44,22 +46,33 @@ K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm"))
 KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
     : KCModule(KdeConnectKcmFactory::componentData(), parent)
     , kcmUi(new Ui::KdeConnectKcmUi())
-    , pairedDevicesList(new DevicesModel(this))
+    , devicesModel(new DevicesModel(this))
     , currentDevice(0)
     //, config(KSharedConfig::openConfig("kdeconnectrc"))
 {
     kcmUi->setupUi(this);
 
     kcmUi->deviceList->setIconSize(QSize(32,32));
-    kcmUi->deviceList->setModel(pairedDevicesList);
+
+    sortProxyModel = new DevicesSortProxyModel(devicesModel);
+
+    kcmUi->deviceList->setModel(sortProxyModel);
 
     kcmUi->deviceInfo->setVisible(false);
 
     setButtons(KCModule::NoAdditionalButton);
 
-    connect(kcmUi->deviceList, SIGNAL(pressed(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
-    connect(kcmUi->ping_button, SIGNAL(pressed()), this, SLOT(sendPing()));
-    connect(kcmUi->trust_checkbox,SIGNAL(toggled(bool)), this, SLOT(trustedStateChanged(bool)));
+    connect(devicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+            this, SLOT(resetSelection()));
+    connect(kcmUi->deviceList, SIGNAL(pressed(QModelIndex)),
+            this, SLOT(deviceSelected(QModelIndex)));
+    connect(kcmUi->ping_button, SIGNAL(pressed()),
+            this, SLOT(sendPing()));
+    connect(kcmUi->trust_checkbox, SIGNAL(toggled(bool)),
+            this, SLOT(trustedStateChanged(bool)));
+
+
+
 }
 
 KdeConnectKcm::~KdeConnectKcm()
@@ -67,21 +80,29 @@ KdeConnectKcm::~KdeConnectKcm()
 
 }
 
+void KdeConnectKcm::resetSelection()
+{
+    kcmUi->deviceList->selectionModel()->setCurrentIndex(sortProxyModel->mapFromSource(currentIndex), QItemSelectionModel::ClearAndSelect);
+}
+
 void KdeConnectKcm::deviceSelected(const QModelIndex& current)
 {
-    //Store previous selection
+
+    //Store previous device config
     pluginsConfigChanged();
 
+    currentIndex = sortProxyModel->mapToSource(current);
+
+    bool valid = currentIndex.isValid();
+    kcmUi->deviceInfo->setVisible(valid);
+    if (!valid) return;
+
     //FIXME: KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time
     delete kcmUi->pluginSelector;
     kcmUi->pluginSelector = new KPluginSelector(this);
     kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector);
 
-    bool valid = current.isValid();
-    kcmUi->deviceInfo->setVisible(valid);
-    if (!valid) return;
-
-    currentDevice = pairedDevicesList->getDevice(current);
+    currentDevice = devicesModel->getDevice(currentIndex);
     kcmUi->deviceName->setText(currentDevice->name());
     kcmUi->trust_checkbox->setChecked(currentDevice->paired());
 
@@ -92,14 +113,16 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
     KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(path + currentDevice->id());
     kcmUi->pluginSelector->addPlugins(scriptinfos, KPluginSelector::ReadConfigFile, "Plugins", QString(), deviceConfig);
 
-    connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), this, SLOT(pluginsConfigChanged()));
+    connect(kcmUi->pluginSelector, SIGNAL(changed(bool)),
+            this, SLOT(pluginsConfigChanged()));
 }
 
 void KdeConnectKcm::trustedStateChanged(bool b)
 {
     if (!currentDevice) return;
     currentDevice->setPair(b);
-    pairedDevicesList->deviceStatusChanged(currentDevice->id());
+    devicesModel->deviceStatusChanged(currentDevice->id());
+
 }
 
 void KdeConnectKcm::pluginsConfigChanged()
@@ -121,11 +144,9 @@ void KdeConnectKcm::save()
     KCModule::save();
 }
 
-
 void KdeConnectKcm::sendPing()
 {
     if (!currentDevice) return;
     currentDevice->sendPing();
 }
 
-
diff --git a/kcm/kcm.h b/kcm/kcm.h
index f03696d..81a46aa 100644
--- a/kcm/kcm.h
+++ b/kcm/kcm.h
@@ -37,6 +37,7 @@ class QStackedLayout;
 class QItemSelectionModel;
 class QDBusInterface;
 class DeviceDbusInterface;
+class DevicesSortProxyModel;
 
 namespace Ui {
     class KdeConnectKcmUi;
@@ -58,14 +59,18 @@ private Q_SLOTS:
     void trustedStateChanged(bool);
     void pluginsConfigChanged();
     void sendPing();
+    void resetSelection();
 
 private:
     Ui::KdeConnectKcmUi* kcmUi;
-    DevicesModel* pairedDevicesList;
+    DevicesModel* devicesModel;
+    DevicesSortProxyModel* sortProxyModel;
     AddDeviceWizard* addDeviceWizard;
     DeviceDbusInterface* currentDevice;
+    QModelIndex currentIndex;
     //KSharedConfigPtr config;
 
+
 };
 
 #endif

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list