Changeset View
Changeset View
Standalone View
Standalone View
plugins/remotecommands/remotecommandsplugin.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_REQUEST QLatin1String("kdeconnect.runcommand.request") | 36 | #define PACKET_TYPE_RUNCOMMAND_REQUEST QLatin1String("kdeconnect.runcommand.request") | ||
37 | 37 | | |||
38 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecommands.json", registerPlugin< RemoteCommandsPlugin >(); ) | 38 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecommands.json", registerPlugin< RemoteCommandsPlugin >(); ) | ||
39 | 39 | | |||
40 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECOMMANDS, "kdeconnect.plugin.remotecommands") | 40 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECOMMANDS, "kdeconnect.plugin.remotecommands") | ||
41 | 41 | | |||
42 | RemoteCommandsPlugin::RemoteCommandsPlugin(QObject* parent, const QVariantList& args) | 42 | RemoteCommandsPlugin::RemoteCommandsPlugin(QObject* parent, const QVariantList& args) | ||
43 | : KdeConnectPlugin(parent, args) | 43 | : KdeConnectPlugin(parent, args) | ||
44 | , m_commands("{}") | 44 | , m_commands("{}") | ||
45 | { | 45 | { | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | RemoteCommandsPlugin::~RemoteCommandsPlugin() = default; | 48 | RemoteCommandsPlugin::~RemoteCommandsPlugin() = default; | ||
49 | 49 | | |||
50 | bool RemoteCommandsPlugin::receivePackage(const NetworkPackage& np) | 50 | bool RemoteCommandsPlugin::receivePacket(const NetworkPacket& np) | ||
51 | { | 51 | { | ||
52 | if (np.has(QStringLiteral("commandList"))) { | 52 | if (np.has(QStringLiteral("commandList"))) { | ||
53 | setCommands(np.get<QByteArray>(QStringLiteral("commandList"))); | 53 | setCommands(np.get<QByteArray>(QStringLiteral("commandList"))); | ||
54 | return true; | 54 | return true; | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | return false; | 57 | return false; | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | void RemoteCommandsPlugin::connected() | 60 | void RemoteCommandsPlugin::connected() | ||
61 | { | 61 | { | ||
62 | NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}}); | 62 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}}); | ||
63 | sendPackage(np); | 63 | sendPacket(np); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | QString RemoteCommandsPlugin::dbusPath() const | 66 | QString RemoteCommandsPlugin::dbusPath() const | ||
67 | { | 67 | { | ||
68 | return "/modules/kdeconnect/devices/" + device()->id() + "/remotecommands"; | 68 | return "/modules/kdeconnect/devices/" + device()->id() + "/remotecommands"; | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | void RemoteCommandsPlugin::setCommands(const QByteArray& cmds) | 71 | void RemoteCommandsPlugin::setCommands(const QByteArray& cmds) | ||
72 | { | 72 | { | ||
73 | if (m_commands != cmds) { | 73 | if (m_commands != cmds) { | ||
74 | m_commands = cmds; | 74 | m_commands = cmds; | ||
75 | Q_EMIT commandsChanged(m_commands); | 75 | Q_EMIT commandsChanged(m_commands); | ||
76 | } | 76 | } | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | void RemoteCommandsPlugin::triggerCommand(const QString& key) | 79 | void RemoteCommandsPlugin::triggerCommand(const QString& key) | ||
80 | { | 80 | { | ||
81 | NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST, {{ "key", key }}); | 81 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{ "key", key }}); | ||
82 | sendPackage(np); | 82 | sendPacket(np); | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | #include "remotecommandsplugin.moc" | 85 | #include "remotecommandsplugin.moc" |