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

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


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

The following commit has been merged in the master branch:
commit cf4a9b86392b6e4f7f1155b90efc03fe3210e004
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Sat Sep 12 03:38:44 2015 -0700

    First implementation of runcommand plugin
---
 plugins/CMakeLists.txt                             |   1 +
 plugins/runcommand/CMakeLists.txt                  |  26 ++++
 plugins/runcommand/kdeconnect_runcommand.json      |  32 +++++
 .../kdeconnect_runcommand_config.desktop           |  10 ++
 plugins/runcommand/runcommand_config.cpp           | 139 +++++++++++++++++++++
 .../runcommand_config.h}                           |  24 ++--
 plugins/runcommand/runcommandplugin.cpp            |  91 ++++++++++++++
 .../runcommandplugin.h}                            |  28 +++--
 8 files changed, 327 insertions(+), 24 deletions(-)

diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 2fb4014..bc90749 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -8,6 +8,7 @@ add_subdirectory(telephony)
 add_subdirectory(share)
 add_subdirectory(notifications)
 add_subdirectory(battery)
+add_subdirectory(runcommand)
 if(NOT WIN32)
     add_subdirectory(pausemusic)
     add_subdirectory(mpriscontrol)
diff --git a/plugins/runcommand/CMakeLists.txt b/plugins/runcommand/CMakeLists.txt
new file mode 100644
index 0000000..4a244cc
--- /dev/null
+++ b/plugins/runcommand/CMakeLists.txt
@@ -0,0 +1,26 @@
+set(kdeconnect_runcommand_SRCS
+    runcommandplugin.cpp
+)
+
+kdeconnect_add_plugin(kdeconnect_runcommand JSON kdeconnect_runcommand.json SOURCES ${kdeconnect_runcommand_SRCS})
+
+target_link_libraries(kdeconnect_runcommand
+    kdeconnectcore
+    Qt5::DBus
+    KF5::I18n)
+
+#----------------------
+
+set( kdeconnect_runcommand_config_SRCS runcommand_config.cpp )
+
+add_library(kdeconnect_runcommand_config MODULE ${kdeconnect_runcommand_config_SRCS} )
+target_link_libraries( kdeconnect_runcommand_config
+    kdeconnectpluginkcm
+    KF5::I18n
+    KF5::CoreAddons
+    KF5::ConfigWidgets
+
+)
+
+install(TARGETS kdeconnect_runcommand_config DESTINATION ${PLUGIN_INSTALL_DIR} )
+install(FILES kdeconnect_runcommand_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
diff --git a/plugins/runcommand/kdeconnect_runcommand.json b/plugins/runcommand/kdeconnect_runcommand.json
new file mode 100644
index 0000000..ed2042a
--- /dev/null
+++ b/plugins/runcommand/kdeconnect_runcommand.json
@@ -0,0 +1,32 @@
+{
+    "Encoding": "UTF-8", 
+    "KPlugin": {
+        "Authors": [
+            {
+                "Email": "albertvaka at gmail.com", 
+                "Name": "Albert Vaca"
+            },
+            {
+                "Email": "david at davidedmundson.co.uk", 
+                "Name": "David Edmundson"
+            }
+        ], 
+        "Description": "Execute console commands remotely",
+        "EnabledByDefault": true, 
+        "Icon": "system-run",
+        "Id": "kdeconnect_runcommand",
+        "License": "GPL", 
+        "Name": "Run commands",
+        "ServiceTypes": [
+            "KdeConnect/Plugin"
+        ], 
+        "Version": "0.1", 
+        "Website": "http://albertvaka.wordpress.com"
+    }, 
+    "X-KdeConnect-OutgoingPackageType": [
+        "kdeconnect.runcommand"
+    ], 
+    "X-KdeConnect-SupportedPackageType": [
+        "kdeconnect.runcommand"
+    ]
+}
diff --git a/plugins/runcommand/kdeconnect_runcommand_config.desktop b/plugins/runcommand/kdeconnect_runcommand_config.desktop
new file mode 100644
index 0000000..71b868c
--- /dev/null
+++ b/plugins/runcommand/kdeconnect_runcommand_config.desktop
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=KCModule
+
+X-KDE-Library=kdeconnect_runcommand_config
+X-KDE-ParentComponents=kdeconnect_runcommand
+
+Name=Run Command plugin settings
+
+Categories=Qt;KDE;X-KDE-settings-kdeconnect;
diff --git a/plugins/runcommand/runcommand_config.cpp b/plugins/runcommand/runcommand_config.cpp
new file mode 100644
index 0000000..896c363
--- /dev/null
+++ b/plugins/runcommand/runcommand_config.cpp
@@ -0,0 +1,139 @@
+/**
+ * Copyright 2015 David Edmundson <davidedmundson at kde.org>
+ *
+ * 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 "runcommand_config.h"
+
+#include <QStandardPaths>
+#include <QTableView>
+#include <QHBoxLayout>
+#include <QStandardItemModel>
+#include <QDebug>
+#include <QUuid>
+#include <QJsonDocument>
+
+#include <KLocalizedString>
+
+#include <KPluginFactory>
+
+K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<RunCommandConfig>();)
+
+RunCommandConfig::RunCommandConfig(QWidget *parent, const QVariantList& args)
+    : KdeConnectPluginKcm(parent, args, "kdeconnect_runcommand_config")
+{
+    QTableView *table = new QTableView(this);
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->addWidget(table);
+    setLayout(layout);
+
+    m_entriesModel = new QStandardItemModel(this);
+    table->setModel(m_entriesModel);
+
+    m_entriesModel->setHorizontalHeaderLabels(QStringList() << i18n("Name") << i18n("Command"));
+
+}
+
+RunCommandConfig::~RunCommandConfig()
+{
+}
+
+void RunCommandConfig::defaults()
+{
+    KCModule::defaults();
+    m_entriesModel->clear();
+
+    Q_EMIT changed(true);
+}
+
+void RunCommandConfig::load()
+{
+    KCModule::load();
+
+    QJsonDocument jsonDocument = QJsonDocument::fromJson(config()->get<QByteArray>("commands", "{}"));
+    QJsonObject jsonConfig = jsonDocument.object();
+    foreach(const QString &key, jsonConfig.keys()) {
+        const QJsonObject entry = jsonConfig[key].toObject();
+        const QString name = entry["name"].toString();
+        const QString command = entry["command"].toString();
+
+        QStandardItem *newName = new QStandardItem(name);
+        newName->setEditable(true);
+        newName->setData(key);
+        QStandardItem *newCommand = new QStandardItem(command);
+        newName->setEditable(true);
+
+        m_entriesModel->appendRow(QList<QStandardItem*>() << newName << newCommand);
+    }
+    insertEmptyRow();
+    connect(m_entriesModel, &QAbstractItemModel::dataChanged, this, &RunCommandConfig::onDataChanged);
+
+    Q_EMIT changed(false);
+}
+
+void RunCommandConfig::save()
+{
+    QJsonObject jsonConfig;
+    for (int i=0;i < m_entriesModel->rowCount(); i++) {
+        QString key = m_entriesModel->item(i, 0)->data().toString();
+        const QString name = m_entriesModel->item(i, 0)->text();
+        const QString command = m_entriesModel->item(i, 1)->text();
+
+        if (name.isEmpty() || command.isEmpty()) {
+            continue;
+        }
+
+        if (key.isEmpty()) {
+            key = QUuid::createUuid().toString();
+        }
+        QJsonObject entry;
+        entry["name"] = name;
+        entry["command"] = command;
+        jsonConfig[key] = entry;
+    }
+    QJsonDocument document;
+    document.setObject(jsonConfig);
+    config()->set("commands", document.toJson());
+
+    KCModule::save();
+
+    Q_EMIT changed(false);
+}
+
+void RunCommandConfig::insertEmptyRow()
+{
+    QStandardItem *newName = new QStandardItem;
+    newName->setEditable(true);
+    QStandardItem *newCommand = new QStandardItem;
+    newName->setEditable(true);
+
+    m_entriesModel->appendRow(QList<QStandardItem*>() << newName << newCommand);
+}
+
+void RunCommandConfig::onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
+{
+    changed(true);
+    Q_UNUSED(topLeft);
+    if (bottomRight.row() == m_entriesModel->rowCount() - 1) {
+        //TODO check both entries are still empty
+        insertEmptyRow();
+    }
+}
+
+
+#include "runcommand_config.moc"
diff --git a/plugins/share/share_config.h b/plugins/runcommand/runcommand_config.h
similarity index 69%
copy from plugins/share/share_config.h
copy to plugins/runcommand/runcommand_config.h
index f4ecadf..a6683a9 100644
--- a/plugins/share/share_config.h
+++ b/plugins/runcommand/runcommand_config.h
@@ -1,5 +1,5 @@
 /**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ * Copyright 2015 David Edmundson <davidedmundson at kde.org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -23,25 +23,27 @@
 
 #include "kcmplugin/kdeconnectpluginkcm.h"
 
-namespace Ui {
-    class ShareConfigUi;
-}
+class QStandardItemModel;
 
-class ShareConfig
+class RunCommandConfig
     : public KdeConnectPluginKcm
 {
     Q_OBJECT
 public:
-    ShareConfig(QWidget *parent, const QVariantList&);
-    virtual ~ShareConfig();
+    RunCommandConfig(QWidget *parent, const QVariantList&);
+    virtual ~RunCommandConfig();
 
 public Q_SLOTS:
-    virtual void save() override;
-    virtual void load() override;
-    virtual void defaults() override;
+    virtual void save() Q_DECL_OVERRIDE;
+    virtual void load();
+    virtual void defaults();
 
+private Q_SLOTS:
+    void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
 private:
-    Ui::ShareConfigUi* m_ui;
+    void insertEmptyRow();
+
+    QStandardItemModel *m_entriesModel;
 
 };
 
diff --git a/plugins/runcommand/runcommandplugin.cpp b/plugins/runcommand/runcommandplugin.cpp
new file mode 100644
index 0000000..b9616bc
--- /dev/null
+++ b/plugins/runcommand/runcommandplugin.cpp
@@ -0,0 +1,91 @@
+/**
+ * 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 "runcommandplugin.h"
+
+#include <KPluginFactory>
+
+#include <QDBusConnection>
+#include <QProcess>
+#include <QDir>
+#include <QLoggingCategory>
+#include <QSettings>
+#include <qt/QtCore/qjsondocument.h>
+#include <QJsonDocument>
+
+#include <core/networkpackage.h>
+#include <core/device.h>
+
+#define PACKAGE_TYPE_RUNCOMMAND QLatin1String("kdeconnect.runcommand")
+
+K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_runcommand.json", registerPlugin< RunCommandPlugin >(); )
+
+Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_RUNCOMMAND, "kdeconnect.plugin.runcommand")
+
+RunCommandPlugin::RunCommandPlugin(QObject* parent, const QVariantList& args)
+    : KdeConnectPlugin(parent, args)
+{
+}
+
+RunCommandPlugin::~RunCommandPlugin()
+{
+}
+
+bool RunCommandPlugin::receivePackage(const NetworkPackage& np)
+{
+    if (np.get<bool>("requestCommandList", false)) {
+        sendConfig();
+        return true;
+    }
+
+    if (np.has("key")) {
+        QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->get<QByteArray>("commands", "{}"));
+        QJsonObject commands = commandsDocument.object();
+        QString key = np.get<QString>("key");
+        QJsonValue value = commands[key];
+        if (value == QJsonValue::Undefined) {
+            qCWarning(KDECONNECT_PLUGIN_RUNCOMMAND) << key << "is not a configured command";
+        }
+        QJsonObject command = value.toObject();
+        QString name = command["name"].toString();
+        QString commandLine = command["command"].toString();
+        QProcess::execute(commandLine);
+        return true;
+    }
+
+    return false;
+}
+
+void RunCommandPlugin::connected()
+{
+
+}
+
+void RunCommandPlugin::sendConfig()
+{
+    QString commands = config()->get<QString>("commands","{}");
+    NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND);
+    np.set("commandList", commands);
+    qDebug() << "SENT" << np.serialize();
+    sendPackage(np);
+}
+
+
+#include "runcommandplugin.moc"
diff --git a/plugins/findmyphone/findmyphoneplugin.h b/plugins/runcommand/runcommandplugin.h
similarity index 71%
copy from plugins/findmyphone/findmyphoneplugin.h
copy to plugins/runcommand/runcommandplugin.h
index 03d15a6..610770c 100644
--- a/plugins/findmyphone/findmyphoneplugin.h
+++ b/plugins/runcommand/runcommandplugin.h
@@ -1,5 +1,5 @@
 /**
- * Copyright 2014 Apoorv Parle <apparle at gmail.com>
+ * Copyright 2015 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
@@ -18,33 +18,35 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PINGPLUGIN_H
-#define PINGPLUGIN_H
+#ifndef RUNCOMMANDPLUGIN_H
+#define RUNCOMMANDPLUGIN_H
 
 #include <QObject>
 
 #include <core/kdeconnectplugin.h>
+#include <QFile>
+#include <QFileSystemWatcher>
+#include <QMap>
+#include <QPair>
+#include <QString>
 
-#define PACKAGE_TYPE_FINDMYPHONE QStringLiteral("kdeconnect.findmyphone")
-
-class FindMyPhonePlugin
+class Q_DECL_EXPORT RunCommandPlugin
     : public KdeConnectPlugin
 {
     Q_OBJECT
-    Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.findmyphone")
 
 public:
-    explicit FindMyPhonePlugin(QObject *parent, const QVariantList &args);
-    virtual ~FindMyPhonePlugin();
-    
-    Q_SCRIPTABLE void ring();
+    explicit RunCommandPlugin(QObject *parent, const QVariantList &args);
+    virtual ~RunCommandPlugin();
+
 
 public Q_SLOTS:
-    virtual void connected();
     virtual bool receivePackage(const NetworkPackage& np);
+    virtual void connected();
 
 private:
-    QString dbusPath() const;
+    void sendConfig();
+
 };
 
 #endif

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list