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

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


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

The following commit has been merged in the master branch:
commit df3581459a1c66146748e4872edd5f35911bba8a
Author: Aleix Pol <aleixpol at kde.org>
Date:   Tue Sep 8 17:28:47 2015 +0200

    Add a test that makes sure that capabilities are gathered correctly
    
    While at it, fix the logic, because it wasn't working all that well.
    
    Reviewed by Albert Vaca
---
 core/device.cpp                                | 47 +++++++++++++++++++-------
 core/device.h                                  |  5 ++-
 tests/CMakeLists.txt                           |  1 +
 tests/{sendfiletest.cpp => pluginloadtest.cpp} | 43 +++++++++--------------
 4 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/core/device.cpp b/core/device.cpp
index c1a7535..64ab0fb 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -76,7 +76,7 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
     , m_protocolVersion(identityPackage.get<int>("protocolVersion"))
 {
     addLink(identityPackage, dl);
-    
+
     //Register in bus
     QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
 
@@ -109,6 +109,7 @@ void Device::reloadPlugins()
     QHash<QString, KdeConnectPlugin*> newPluginMap;
     QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface;
     QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface;
+    QSet<QString> supportedIncomingInterfaces;
     QStringList missingPlugins;
 
     if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
@@ -119,12 +120,7 @@ void Device::reloadPlugins()
 
         //Code borrowed from KWin
         foreach (const QString& pluginName, loader->getPluginList()) {
-            QString enabledKey = pluginName + QString::fromLatin1("Enabled");
-
-            bool isPluginEnabled = (pluginStates.hasKey(enabledKey) ? pluginStates.readEntry(enabledKey, false)
-                                                            : loader->getPluginInfo(pluginName).isEnabledByDefault());
-
-            if (isPluginEnabled) {
+            if (isPluginEnabled(pluginName)) {
                 KdeConnectPlugin* plugin = m_plugins.take(pluginName);
                 QStringList incomingInterfaces, outgoingInterfaces;
                 if (plugin) {
@@ -135,6 +131,7 @@ void Device::reloadPlugins()
                     incomingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-SupportedPackageType");
                     outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-OutgoingPackageType");
                 }
+                supportedIncomingInterfaces += incomingInterfaces.toSet();
 
                 //If we don't find intersection with the received on one end and the sent on the other, we don't
                 //let the plugin stay
@@ -167,22 +164,28 @@ void Device::reloadPlugins()
 
     //Erase all left plugins in the original map (meaning that we don't want
     //them anymore, otherwise they would have been moved to the newPluginMap)
+    const QStringList newSupportedIncomingInterfaces = supportedIncomingInterfaces.toList();
+    const bool capabilitiesChanged = (m_pluginsByOutgoingInterface != newPluginsByOutgoingInterface
+                                     || m_supportedIncomingInterfaces != newSupportedIncomingInterfaces);
     qDeleteAll(m_plugins);
     m_plugins = newPluginMap;
-    m_pluginsByIncomingInterface = newPluginsByIncomingInterface;
     m_pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
+    m_supportedIncomingInterfaces = newSupportedIncomingInterfaces;
+    m_pluginsByIncomingInterface = newPluginsByIncomingInterface;
     m_missingPlugins = missingPlugins;
 
     Q_FOREACH(KdeConnectPlugin* plugin, m_plugins) {
         plugin->connected();
     }
-
     Q_EMIT pluginsChanged();
 
-    NetworkPackage np(PACKAGE_TYPE_CAPABILITIES);
-    np.set<QStringList>("SupportedIncomingInterfaces", m_pluginsByIncomingInterface.keys());
-    np.set<QStringList>("SupportedOutgoingInterfaces", m_pluginsByOutgoingInterface.keys());
-    sendPackage(np);
+    if (capabilitiesChanged)
+    {
+        NetworkPackage np(PACKAGE_TYPE_CAPABILITIES);
+        np.set<QStringList>("SupportedIncomingInterfaces", newSupportedIncomingInterfaces);
+        np.set<QStringList>("SupportedOutgoingInterfaces", newPluginsByOutgoingInterface.keys());
+        sendPackage(np);
+    }
 }
 
 QString Device::pluginsConfigFile() const
@@ -544,3 +547,21 @@ KdeConnectPlugin* Device::plugin(const QString& pluginName) const
 {
     return m_plugins[pluginName];
 }
+
+void Device::setPluginEnabled(const QString& pluginName, bool enabled)
+{
+    KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins");
+
+    const QString enabledKey = pluginName + QStringLiteral("Enabled");
+    pluginStates.writeEntry(enabledKey, enabled);
+    reloadPlugins();
+}
+
+bool Device::isPluginEnabled(const QString& pluginName) const
+{
+    const QString enabledKey = pluginName + QStringLiteral("Enabled");
+    KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins");
+
+    return (pluginStates.hasKey(enabledKey) ? pluginStates.readEntry(enabledKey, false)
+                                            : PluginLoader::instance()->getPluginInfo(pluginName).isEnabledByDefault());
+}
diff --git a/core/device.h b/core/device.h
index 2e1d48b..6814c4a 100644
--- a/core/device.h
+++ b/core/device.h
@@ -104,7 +104,9 @@ public:
 
     Q_SCRIPTABLE QString pluginsConfigFile() const;
 
-    KdeConnectPlugin* plugin(const QString& plugin) const;
+    KdeConnectPlugin* plugin(const QString& pluginName) const;
+    void setPluginEnabled(const QString& pluginName, bool enabled);
+    bool isPluginEnabled(const QString& pluginName) const;
 
 public Q_SLOTS:
     ///sends a @p np package to the device
@@ -156,6 +158,7 @@ private: //Fields (TODO: dPointer!)
     QTimer m_pairingTimeut;
     QSet<QString> m_incomingCapabilities;
     QSet<QString> m_outgoingCapabilities;
+    QStringList m_supportedIncomingInterfaces;
     QStringList m_missingPlugins;
 };
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f921881..0ebc919 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -14,6 +14,7 @@ set(kdeconnect_libraries
     qca-qt5
 )
 
+ecm_add_test(pluginloadtest.cpp LINK_LIBRARIES ${kdeconnect_libraries})
 ecm_add_test(sendfiletest.cpp LINK_LIBRARIES ${kdeconnect_libraries})
 ecm_add_test(networkpackagetests.cpp LINK_LIBRARIES ${kdeconnect_libraries})
 ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})
diff --git a/tests/sendfiletest.cpp b/tests/pluginloadtest.cpp
similarity index 65%
copy from tests/sendfiletest.cpp
copy to tests/pluginloadtest.cpp
index 8e96c0b..4b175a2 100644
--- a/tests/sendfiletest.cpp
+++ b/tests/pluginloadtest.cpp
@@ -24,6 +24,7 @@
 #include <QTest>
 #include <QTemporaryFile>
 #include <QSignalSpy>
+#include <QStandardPaths>
 
 #include <KIO/AccessManager>
 
@@ -64,45 +65,33 @@ private:
     QNetworkAccessManager* m_nam;
 };
 
-class TestSendFile : public QObject
+class PluginLoadTest : public QObject
 {
     Q_OBJECT
     public:
-        TestSendFile() : mDaemon(new TestDaemon) {}
+        PluginLoadTest() : mDaemon(new TestDaemon) {
+            QStandardPaths::setTestModeEnabled(true);
+        }
 
     private Q_SLOTS:
-        void testSend() {
+        void testPlugins() {
             Device* d = mDaemon->devicesList().first();
-            QCOMPARE(d->isReachable(), true);
-            QCOMPARE(d->isPaired(), true);
-
-            QByteArray content("12312312312313213123213123");
-
-            QTemporaryFile temp;
-            temp.open();
-            temp.write(content);
-            temp.close();
-
-            KdeConnectPlugin* plugin = d->plugin("kdeconnect_share");
-            QVERIFY(plugin);
-            plugin->metaObject()->invokeMethod(plugin, "shareUrl", Q_ARG(QString, QUrl::fromLocalFile(temp.fileName()).toString()));
-
-            QSignalSpy spy(plugin, SIGNAL(fileReceived(QUrl)));
-            QVERIFY(spy.wait(2000));
+            QVERIFY(d->isPaired());
+            QVERIFY(d->isReachable());
 
-            QVariantList args = spy.takeFirst();
-            QUrl sentFile = args.first().toUrl();
+            d->setPluginEnabled("kdeconnect_mousepad", false);
+            QCOMPARE(d->isPluginEnabled("kdeconnect_mousepad"), false);
+            QVERIFY(d->missingPlugins().contains("kdeconnect_remotecontrol"));
 
-            QFile file(sentFile.toLocalFile());
-            QCOMPARE(file.size(), content.size());
-            QVERIFY(file.open(QIODevice::ReadOnly));
-            QCOMPARE(file.readAll(), content);
+            d->setPluginEnabled("kdeconnect_mousepad", true);
+            QCOMPARE(d->isPluginEnabled("kdeconnect_mousepad"), true);
+            QVERIFY(!d->missingPlugins().contains("kdeconnect_remotecontrol"));
         }
 
     private:
         TestDaemon* mDaemon;
 };
 
-QTEST_MAIN(TestSendFile);
+QTEST_MAIN(PluginLoadTest);
 
-#include "sendfiletest.moc"
+#include "pluginloadtest.moc"

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list