Changeset View
Changeset View
Standalone View
Standalone View
plugins/runcommand/runcommandplugin.cpp
Show All 24 Lines | |||||
25 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
26 | #include <QProcess> | 26 | #include <QProcess> | ||
27 | #include <QDir> | 27 | #include <QDir> | ||
28 | #include <QLoggingCategory> | 28 | #include <QLoggingCategory> | ||
29 | #include <QSettings> | 29 | #include <QSettings> | ||
30 | #include <QJsonDocument> | 30 | #include <QJsonDocument> | ||
31 | #include <KShell> | 31 | #include <KShell> | ||
32 | 32 | | |||
33 | #include <core/networkpackage.h> | 33 | #include <core/networkpacket.h> | ||
34 | #include <core/device.h> | 34 | #include <core/device.h> | ||
35 | 35 | | |||
36 | #define PACKAGE_TYPE_RUNCOMMAND QStringLiteral("kdeconnect.runcommand") | 36 | #define PACKET_TYPE_RUNCOMMAND QStringLiteral("kdeconnect.runcommand") | ||
37 | 37 | | |||
38 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_runcommand.json", registerPlugin< RunCommandPlugin >(); ) | 38 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_runcommand.json", registerPlugin< RunCommandPlugin >(); ) | ||
39 | 39 | | |||
40 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_RUNCOMMAND, "kdeconnect.plugin.runcommand") | 40 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_RUNCOMMAND, "kdeconnect.plugin.runcommand") | ||
41 | 41 | | |||
42 | RunCommandPlugin::RunCommandPlugin(QObject* parent, const QVariantList& args) | 42 | RunCommandPlugin::RunCommandPlugin(QObject* parent, const QVariantList& args) | ||
43 | : KdeConnectPlugin(parent, args) | 43 | : KdeConnectPlugin(parent, args) | ||
44 | { | 44 | { | ||
45 | connect(config(), &KdeConnectPluginConfig::configChanged, this, &RunCommandPlugin::configChanged); | 45 | connect(config(), &KdeConnectPluginConfig::configChanged, this, &RunCommandPlugin::configChanged); | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | RunCommandPlugin::~RunCommandPlugin() | 48 | RunCommandPlugin::~RunCommandPlugin() | ||
49 | { | 49 | { | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | bool RunCommandPlugin::receivePackage(const NetworkPackage& np) | 52 | bool RunCommandPlugin::receivePacket(const NetworkPacket& np) | ||
53 | { | 53 | { | ||
54 | if (np.get<bool>(QStringLiteral("requestCommandList"), false)) { | 54 | if (np.get<bool>(QStringLiteral("requestCommandList"), false)) { | ||
55 | sendConfig(); | 55 | sendConfig(); | ||
56 | return true; | 56 | return true; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | if (np.has(QStringLiteral("key"))) { | 59 | if (np.has(QStringLiteral("key"))) { | ||
60 | QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->get<QByteArray>(QStringLiteral("commands"), "{}")); | 60 | QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->get<QByteArray>(QStringLiteral("commands"), "{}")); | ||
Show All 16 Lines | |||||
77 | { | 77 | { | ||
78 | 78 | | |||
79 | sendConfig(); | 79 | sendConfig(); | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | void RunCommandPlugin::sendConfig() | 82 | void RunCommandPlugin::sendConfig() | ||
83 | { | 83 | { | ||
84 | QString commands = config()->get<QString>(QStringLiteral("commands"),QStringLiteral("{}")); | 84 | QString commands = config()->get<QString>(QStringLiteral("commands"),QStringLiteral("{}")); | ||
85 | NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND, {{"commandList", commands}}); | 85 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}}); | ||
86 | sendPackage(np); | 86 | sendPacket(np); | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | void RunCommandPlugin::configChanged() { | 89 | void RunCommandPlugin::configChanged() { | ||
90 | sendConfig(); | 90 | sendConfig(); | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | #include "runcommandplugin.moc" | 93 | #include "runcommandplugin.moc" |