diff --git a/plugins/runcommand/kdeconnect_runcommand.json b/plugins/runcommand/kdeconnect_runcommand.json --- a/plugins/runcommand/kdeconnect_runcommand.json +++ b/plugins/runcommand/kdeconnect_runcommand.json @@ -102,6 +102,10 @@ "kdeconnect.runcommand" ], "X-KdeConnect-SupportedPackageType": [ - "kdeconnect.runcommand.request" + "kdeconnect.runcommand.request", + "kdeconnect.runcommand.add" + ], + "X-KdeConnect-IngoingPackageType": [ + "kdeconnect.runcommand.add" ] } diff --git a/plugins/runcommand/runcommand_config.cpp b/plugins/runcommand/runcommand_config.cpp --- a/plugins/runcommand/runcommand_config.cpp +++ b/plugins/runcommand/runcommand_config.cpp @@ -142,5 +142,4 @@ } } - #include "runcommand_config.moc" diff --git a/plugins/runcommand/runcommandplugin.h b/plugins/runcommand/runcommandplugin.h --- a/plugins/runcommand/runcommandplugin.h +++ b/plugins/runcommand/runcommandplugin.h @@ -44,6 +44,7 @@ private Q_SLOTS: void configChanged(); + void addCommand(const QString& name, const QString& command); private: void sendConfig(); diff --git a/plugins/runcommand/runcommandplugin.cpp b/plugins/runcommand/runcommandplugin.cpp --- a/plugins/runcommand/runcommandplugin.cpp +++ b/plugins/runcommand/runcommandplugin.cpp @@ -29,11 +29,13 @@ #include #include #include +#include #include #include #define PACKAGE_TYPE_RUNCOMMAND QStringLiteral("kdeconnect.runcommand") +#define PACKAGE_TYPE_RUNCOMMAND_ADD QStringLiteral("kdeconnect.runcommand.add") K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_runcommand.json", registerPlugin< RunCommandPlugin >(); ) @@ -51,6 +53,12 @@ bool RunCommandPlugin::receivePackage(const NetworkPackage& np) { + if(np.type() == PACKAGE_TYPE_RUNCOMMAND_ADD) { + QString name = np.get("name"); + QString command = np.get("command"); + addCommand(name, command); + } + if (np.get(QStringLiteral("requestCommandList"), false)) { sendConfig(); return true; @@ -90,4 +98,20 @@ sendConfig(); } +void RunCommandPlugin::addCommand(const QString& name, const QString& command) +{ + QJsonDocument jsonDocument = QJsonDocument::fromJson(config()->get(QStringLiteral("commands"), "{}")); + QJsonObject jsonConfig = jsonDocument.object(); + + QString key = QUuid::createUuid().toString(); + QJsonObject entry; + entry[QStringLiteral("name")] = name; + entry[QStringLiteral("command")] = command; + jsonConfig[key] = entry; + + QJsonDocument document; + document.setObject(jsonConfig); + config()->set(QStringLiteral("commands"), document.toJson(QJsonDocument::Compact)); +} + #include "runcommandplugin.moc"