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

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


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

The following commit has been merged in the master branch:
commit 238d81a408d6153af8e110d12d5e0d6accd28f3d
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Tue Aug 13 23:23:32 2013 +0200

    Changing dbus interface to improve communication with kcm and the solid backend
---
 cmakemacros.txt                                    | 26 +++++++++++
 daemon/CMakeLists.txt                              | 25 +----------
 daemon/daemon.cpp                                  | 48 +++++++++++++++-----
 daemon/daemon.h                                    | 10 +++--
 daemon/device.cpp                                  | 27 ++++++-----
 daemon/device.h                                    | 13 +++---
 ...tterypackageinterface.cpp => batteryplugin.cpp} |  0
 .../{batterypackageinterface.h => batteryplugin.h} |  0
 .../plugins/battery/devicebatteryinformation_p.cpp | 27 -----------
 .../plugins/battery/devicebatteryinformation_p.h   | 52 ----------------------
 daemon/plugins/pluginloader.h                      |  4 +-
 kcm/devicesmodel.cpp                               | 35 ++++++++++-----
 kcm/devicesmodel.h                                 |  2 +
 13 files changed, 121 insertions(+), 148 deletions(-)

diff --git a/cmakemacros.txt b/cmakemacros.txt
new file mode 100644
index 0000000..9d4810d
--- /dev/null
+++ b/cmakemacros.txt
@@ -0,0 +1,26 @@
+
+include(KDE4Defaults)
+macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file) #OPTIONS qdbus_options
+    QT4_EXTRACT_OPTIONS(
+        extra_files_ignore
+        qdbus_options
+        ${ARGN}
+    )
+    qt4_generate_dbus_interface(
+        ${header_file}
+        ${output_xml_file}
+        OPTIONS ${qdbus_options}
+    )
+    add_custom_target(
+        ${output_xml_file}
+        SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
+    )
+    install(
+        FILES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
+        DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}
+    )
+    add_dependencies(
+        ${main_project_target}
+        ${output_xml_file}
+    )
+endmacro (generate_and_install_dbus_interface)
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index d65c51c..dd86002 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -29,30 +29,7 @@ target_link_libraries(kded_kdeconnect
     ${QT_QTNETWORK_LIBRARY}
 )
 
-macro (generate_and_install_dbus_interface main_project_target header_file output_xml_file) #OPTIONS qdbus_options
-    QT4_EXTRACT_OPTIONS(
-        extra_files_ignore
-        qdbus_options
-        ${ARGN}
-    )
-    qt4_generate_dbus_interface(
-        ${header_file}
-        ${output_xml_file}
-        OPTIONS ${qdbus_options}
-    )
-    add_custom_target(
-        ${output_xml_file}
-        SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
-    )
-    install(
-        FILES ${CMAKE_CURRENT_BINARY_DIR}/${output_xml_file}
-        DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}
-    )
-    add_dependencies(
-        ${main_project_target}
-        ${output_xml_file}
-    )
-endmacro (generate_and_install_dbus_interface)
+include(../cmakemacros.txt)
 
 generate_and_install_dbus_interface(
     kded_kdeconnect
diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp
index f58cc21..5b6faf5 100644
--- a/daemon/daemon.cpp
+++ b/daemon/daemon.cpp
@@ -67,7 +67,9 @@ Daemon::Daemon(QObject *parent, const QList<QVariant>&)
         const KConfigGroup& data = known.group(id);
         const QString& name = data.readEntry<QString>("name", defaultName);
         Device* device = new Device(id, name);
+        connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceReachableStatusChanged()));
         mDevices[id] = device;
+        Q_EMIT deviceAdded(id);
     }
     
     QNetworkSession* network = new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration());
@@ -103,6 +105,17 @@ void Daemon::forceOnNetworkChange()
     }
 }
 
+QStringList Daemon::visibleDevices()
+{
+    QStringList ret;
+    Q_FOREACH(Device* device, mDevices) {
+        if (device->reachable()) {
+            ret.append(device->id());
+        }
+    }
+    return ret;
+}
+
 QStringList Daemon::devices()
 {
     return mDevices.keys();
@@ -120,16 +133,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
         Device* device = mDevices[id];
         device->addLink(dl);
 
-        /*if (device->paired()) {
-            KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent
-            notification->setPixmap(KIcon("dialog-ok").pixmap(48, 48));
-            notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
-            notification->setTitle(device->name());
-            notification->setText("Succesfully connected");
-            notification->sendEvent();
-        }*/
-
-        Q_EMIT deviceStatusChanged(id);
+        Q_EMIT deviceVisibilityChanged(id, true);
         
     } else {
         qDebug() << "It is a new device";
@@ -137,9 +141,31 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
         const QString& name = identityPackage.get<QString>("deviceName");
 
         Device* device = new Device(id, name, dl);
+        connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceReachableStatusChanged()));
         mDevices[id] = device;
 
-        Q_EMIT newDeviceAdded(id);
+        Q_EMIT deviceAdded(id);
+        Q_EMIT deviceVisibilityChanged(id, true);
+    }
+
+}
+
+void Daemon::onDeviceReachableStatusChanged()
+{
+
+    Device* device = (Device*)sender();
+    QString id = device->id();
+
+    if (!device->reachable()) {
+
+        Q_EMIT deviceVisibilityChanged(id, false);
+
+        if (!device->paired()) {
+            Q_EMIT deviceRemoved(id);
+            mDevices.remove(id);
+            device->deleteLater();
+        }
+
     }
 
 }
diff --git a/daemon/daemon.h b/daemon/daemon.h
index c4cb119..a53c345 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -62,15 +62,17 @@ public Q_SLOTS:
     Q_SCRIPTABLE void forceOnNetworkChange();
 
     //Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
-    Q_SCRIPTABLE QStringList devices();
+    Q_SCRIPTABLE QStringList devices(); //All known devices
+    Q_SCRIPTABLE QStringList visibleDevices(); //Only visible devices
 
 Q_SIGNALS:
-    Q_SCRIPTABLE void newDeviceAdded(const QString& id);
-    Q_SCRIPTABLE void deviceStatusChanged(const QString& id);
-
+    Q_SCRIPTABLE void deviceAdded(const QString& id);
+    Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
+    Q_SCRIPTABLE void deviceVisibilityChanged(const QString& id, bool isVisible);
 
 private Q_SLOTS:
     void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl);
+    void onDeviceReachableStatusChanged();
 
 private:
 
diff --git a/daemon/device.cpp b/daemon/device.cpp
index 099fd9a..6445309 100644
--- a/daemon/device.cpp
+++ b/daemon/device.cpp
@@ -24,7 +24,7 @@ Device::Device(const QString& id, const QString& name)
     m_knownIdentiy = true;
 
     //Register in bus
-    QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
+    QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors | QDBusConnection::ExportChildObjects);
 
     reloadPlugins();
 }
@@ -37,7 +37,7 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link)
     m_knownIdentiy = true;
 
     //Register in bus
-    QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
+    QDBusConnection::sessionBus().registerObject("/modules/kdeconnect/devices/"+id, this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors | QDBusConnection::ExportChildObjects);
 
     addLink(link);
 
@@ -61,6 +61,11 @@ Device::Device(const QString& id, const QString& name, DeviceLink* link)
 }
 */
 
+bool Device::hasPlugin(const QString& name)
+{
+    return m_plugins.contains(name);
+}
+
 void Device::reloadPlugins()
 {
 
@@ -86,14 +91,15 @@ void Device::reloadPlugins()
 
             connect(this, SIGNAL(receivedPackage(const NetworkPackage&)),
                     plugin, SLOT(receivePackage(const NetworkPackage&)));
-    //        connect(packageInterface, SIGNAL(sendPackage(const NetworkPackage&)),
+    //        connect(plugin, SIGNAL(sendPackage(const NetworkPackage&)),
     //                device, SLOT(sendPackage(const NetworkPackage&)));
 
 
-            m_plugins.append(plugin);
+            m_plugins[pluginName] = plugin;
         }
     }
 
+    Q_EMIT pluginsChanged();
 
 }
 
@@ -125,15 +131,16 @@ void Device::addLink(DeviceLink* link)
 
     m_deviceLinks.append(link);
 
-    //TODO: Somehow destroy previous device links from the same provider,
-    //but if we do it here, the provider will keep a broken ref!
+    //Theoretically we will never add two links from the same provider (the provider should destroy
+    //the old one before this is called), so we do not have to worry about destroying old links.
+    //Actually, we should not destroy them or the provider will store an invalid ref!
 
     connect(link, SIGNAL(receivedPackage(NetworkPackage)), this, SLOT(privateReceivedPackage(NetworkPackage)));
 
     qSort(m_deviceLinks.begin(),m_deviceLinks.end(),lessThan);
 
     if (m_deviceLinks.size() == 1) {
-        emit reachableStatusChanged();
+        Q_EMIT reachableStatusChanged();
     }
 
 }
@@ -150,7 +157,7 @@ void Device::removeLink(DeviceLink* link)
     qDebug() << "RemoveLink"<< m_deviceLinks.size() << "links remaining";
 
     if (m_deviceLinks.empty()) {
-        emit reachableStatusChanged();
+        Q_EMIT reachableStatusChanged();
     }
 }
 
@@ -162,8 +169,8 @@ bool Device::sendPackage(const NetworkPackage& np) const
     }
 
     Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
-        //TODO: Actually detect if a package is received or not, now when have TCP
-        //"ESTABLISHED" connections that look legit and return true when we use them,
+        //TODO: Actually detect if a package is received or not, now we keep TCP
+        //"ESTABLISHED" connections that look legit (return true when we use them),
         //but that are actually broken
         if (dl->sendPackage(np)) return true;
     }
diff --git a/daemon/device.h b/daemon/device.h
index 556e470..083b171 100644
--- a/daemon/device.h
+++ b/daemon/device.h
@@ -24,7 +24,7 @@
 #include <QObject>
 #include <QDBusConnection>
 #include <QString>
-#include <qvector.h>
+#include <QMap>
 
 #include "networkpackage.h"
 
@@ -61,6 +61,7 @@ public:
     Q_SCRIPTABLE bool trusted() const { return m_paired; }
     Q_SCRIPTABLE bool paired() const { return m_paired; }
     Q_SCRIPTABLE bool reachable() const { return !m_deviceLinks.empty(); }
+    Q_SCRIPTABLE bool hasPlugin(const QString& name);
 
     //Send and receive
 Q_SIGNALS:
@@ -74,22 +75,22 @@ public Q_SLOTS:
     Q_SCRIPTABLE void reloadPlugins();
     Q_SCRIPTABLE void sendPing();
 
-Q_SIGNALS:
-    void reachableStatusChanged();
-    
 private Q_SLOTS:
     void linkDestroyed(QObject* o = 0);
     void privateReceivedPackage(const NetworkPackage& np);
 
+Q_SIGNALS:
+    void reachableStatusChanged();
+    void pluginsChanged();
+
 private:
     bool m_paired;
     QString m_deviceId;
     QString m_deviceName;
     QList<DeviceLink*> m_deviceLinks;
-    QList<KdeConnectPlugin*> m_plugins;
+    QMap<QString, KdeConnectPlugin*> m_plugins;
     bool m_knownIdentiy;
 
-
 };
 
 Q_DECLARE_METATYPE(Device*)
diff --git a/daemon/plugins/battery/batterypackageinterface.cpp b/daemon/plugins/battery/batteryplugin.cpp
similarity index 100%
rename from daemon/plugins/battery/batterypackageinterface.cpp
rename to daemon/plugins/battery/batteryplugin.cpp
diff --git a/daemon/plugins/battery/batterypackageinterface.h b/daemon/plugins/battery/batteryplugin.h
similarity index 100%
rename from daemon/plugins/battery/batterypackageinterface.h
rename to daemon/plugins/battery/batteryplugin.h
diff --git a/daemon/plugins/battery/devicebatteryinformation_p.cpp b/daemon/plugins/battery/devicebatteryinformation_p.cpp
deleted file mode 100644
index 647746f..0000000
--- a/daemon/plugins/battery/devicebatteryinformation_p.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
- *
- * 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 "devicebatteryinformation_p.h"
-
-DeviceBatteryInformation::DeviceBatteryInformation(QObject* parent)
-    : QDBusAbstractAdaptor(parent)
-{
-
-}
diff --git a/daemon/plugins/battery/devicebatteryinformation_p.h b/daemon/plugins/battery/devicebatteryinformation_p.h
deleted file mode 100644
index 8f0dfab..0000000
--- a/daemon/plugins/battery/devicebatteryinformation_p.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
- *
- * 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/>.
- */
-
-#ifndef DEVICEBATTERYINFORMATION_H
-#define DEVICEBATTERYINFORMATION_H
-
-#include <QObject>
-#include <QDBusAbstractAdaptor>
-
-class DeviceBatteryInformation
-    : public QDBusAbstractAdaptor
-{
-    Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.battery")
-    Q_PROPERTY( int charge READ charge NOTIFY chargingChange )
-    Q_PROPERTY( bool isCharging READ isCharging NOTIFY chargingChange )
-
-public:
-    DeviceBatteryInformation(QObject* parent = 0);
-
-    int charge() { return mCharge; }
-    void setCharge(int charge) { mCharge = charge; emit chargingChange(); }
-    bool isCharging() { return mIsCharging; }
-    void setCharging(bool isCharging) { mIsCharging = isCharging; emit chargingChange(); }
-
-private:
-    bool mIsCharging;
-    int mCharge;
-
-Q_SIGNALS:
-    Q_SCRIPTABLE void chargingChange();
-
-};
-
-#endif //DEVICEBATTERYINFORMATION_H
\ No newline at end of file
diff --git a/daemon/plugins/pluginloader.h b/daemon/plugins/pluginloader.h
index 0665d2f..0fe87b8 100644
--- a/daemon/plugins/pluginloader.h
+++ b/daemon/plugins/pluginloader.h
@@ -18,8 +18,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PACKAGEINTERFACELOADER_H
-#define PACKAGEINTERFACELOADER_H
+#ifndef PLUGINLOADER_H
+#define PLUGINLOADER_H
 
 #include <QObject>
 #include <QMap>
diff --git a/kcm/devicesmodel.cpp b/kcm/devicesmodel.cpp
index 990f87b..d784256 100644
--- a/kcm/devicesmodel.cpp
+++ b/kcm/devicesmodel.cpp
@@ -33,23 +33,17 @@ DevicesModel::DevicesModel(QObject *parent)
     , m_dbusInterface(new DaemonDbusInterface(this))
 {
     QList<QString> deviceIds = m_dbusInterface->devices();
-    connect(m_dbusInterface,SIGNAL(newDeviceAdded(QString)),this,SLOT(deviceAdded(QString)));
     Q_FOREACH(const QString& id, deviceIds) {
         deviceAdded(id);
     }
-    connect(m_dbusInterface,SIGNAL(deviceStatusChanged(QString)),this,SLOT(deviceStatusChanged(QString)));
-    //connect(m_dbusInterface,SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemoved(QString));
-}
 
-DevicesModel::~DevicesModel()
-{
+    connect(m_dbusInterface,SIGNAL(deviceAdded(QString)),this,SLOT(deviceAdded(QString)));
+    connect(m_dbusInterface,SIGNAL(deviceVisibilityChanged(QString,bool)),this,SLOT(deviceStatusChanged(QString)));
+    connect(m_dbusInterface,SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemoved(QString)));
 }
 
-void DevicesModel::deviceStatusChanged(const QString& id)
+DevicesModel::~DevicesModel()
 {
-    Q_UNUSED(id);
-    qDebug() << "deviceStatusChanged";
-    emit dataChanged(index(0),index(rowCount()));
 }
 
 void DevicesModel::deviceAdded(const QString& id)
@@ -60,8 +54,26 @@ void DevicesModel::deviceAdded(const QString& id)
     endInsertRows();
     */
 
-    //Full refresh
     Q_UNUSED(id);
+    refreshDeviceList();
+}
+
+void DevicesModel::deviceRemoved(const QString& id)
+{
+    Q_UNUSED(id);
+    refreshDeviceList();
+}
+
+
+void DevicesModel::deviceStatusChanged(const QString& id)
+{
+    Q_UNUSED(id);
+    emit dataChanged(index(0),index(rowCount()));
+}
+
+void DevicesModel::refreshDeviceList()
+{
+
     if (m_deviceList.count() > 0) {
         beginRemoveRows(QModelIndex(), 0, m_deviceList.count() - 1);
         m_deviceList.clear();
@@ -75,7 +87,6 @@ void DevicesModel::deviceAdded(const QString& id)
     }
 
 }
-
 /*
 bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
 {
diff --git a/kcm/devicesmodel.h b/kcm/devicesmodel.h
index c266ff2..adba660 100644
--- a/kcm/devicesmodel.h
+++ b/kcm/devicesmodel.h
@@ -56,6 +56,8 @@ public Q_SLOTS:
 
 private Q_SLOTS:
     void deviceAdded(const QString& id);
+    void deviceRemoved(const QString& id);
+    void refreshDeviceList();
 
 private:
     DaemonDbusInterface* m_dbusInterface;

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list