Changeset View
Changeset View
Standalone View
Standalone View
plugins/remotecommands/remotecommandsplugin.cpp
Show All 17 Lines | |||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "remotecommandsplugin.h" | 21 | #include "remotecommandsplugin.h" | ||
22 | 22 | | |||
23 | #include <KPluginFactory> | 23 | #include <KPluginFactory> | ||
24 | 24 | | |||
25 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
26 | #include <QProcess> | | |||
27 | #include <QDir> | | |||
28 | #include <QLoggingCategory> | 26 | #include <QLoggingCategory> | ||
29 | #include <QSettings> | | |||
30 | #include <QJsonDocument> | 27 | #include <QJsonDocument> | ||
31 | #include <KShell> | | |||
32 | 28 | | |||
33 | #include <core/networkpacket.h> | 29 | #include <core/networkpacket.h> | ||
34 | #include <core/device.h> | 30 | #include <core/device.h> | ||
31 | #include "remotecommandsdbusinterface.h" | ||||
35 | 32 | | |||
36 | #define PACKET_TYPE_RUNCOMMAND_REQUEST QLatin1String("kdeconnect.runcommand.request") | 33 | #define PACKET_TYPE_RUNCOMMAND_REQUEST QLatin1String("kdeconnect.runcommand.request") | ||
37 | 34 | | |||
38 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecommands.json", registerPlugin< RemoteCommandsPlugin >(); ) | 35 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecommands.json", registerPlugin< RemoteCommandsPlugin >(); ) | ||
39 | 36 | | |||
40 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECOMMANDS, "kdeconnect.plugin.remotecommands") | 37 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECOMMANDS, "kdeconnect.plugin.remotecommands") | ||
41 | 38 | | |||
42 | RemoteCommandsPlugin::RemoteCommandsPlugin(QObject* parent, const QVariantList& args) | 39 | RemoteCommandsPlugin::RemoteCommandsPlugin(QObject* parent, const QVariantList& args) | ||
43 | : KdeConnectPlugin(parent, args) | 40 | : KdeConnectPlugin(parent, args) | ||
44 | , m_commands("{}") | 41 | , m_iface(new RemoteCommandsDbusInterface(this)) | ||
45 | { | 42 | { | ||
46 | } | 43 | } | ||
47 | 44 | | |||
48 | RemoteCommandsPlugin::~RemoteCommandsPlugin() = default; | 45 | RemoteCommandsPlugin::~RemoteCommandsPlugin() = default; | ||
49 | 46 | | |||
50 | bool RemoteCommandsPlugin::receivePacket(const NetworkPacket& np) | 47 | bool RemoteCommandsPlugin::receivePacket(const NetworkPacket& np) | ||
51 | { | 48 | { | ||
52 | if (np.has(QStringLiteral("commandList"))) { | 49 | return m_iface->receivePacket(np); | ||
53 | setCommands(np.get<QByteArray>(QStringLiteral("commandList"))); | | |||
54 | return true; | | |||
55 | } | | |||
56 | | ||||
57 | return false; | | |||
58 | } | 50 | } | ||
59 | 51 | | |||
60 | void RemoteCommandsPlugin::connected() | 52 | void RemoteCommandsPlugin::connected() | ||
61 | { | 53 | { | ||
62 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}}); | 54 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}}); | ||
63 | sendPacket(np); | 55 | sendPacket(np); | ||
64 | } | 56 | } | ||
65 | 57 | | |||
66 | QString RemoteCommandsPlugin::dbusPath() const | 58 | QString RemoteCommandsPlugin::dbusPath() const | ||
67 | { | 59 | { | ||
68 | return "/modules/kdeconnect/devices/" + device()->id() + "/remotecommands"; | 60 | return "/modules/kdeconnect/devices/" + device()->id() + "/remotecommands"; | ||
69 | } | 61 | } | ||
70 | 62 | | |||
71 | void RemoteCommandsPlugin::setCommands(const QByteArray& cmds) | | |||
72 | { | | |||
73 | if (m_commands != cmds) { | | |||
74 | m_commands = cmds; | | |||
75 | Q_EMIT commandsChanged(m_commands); | | |||
76 | } | | |||
77 | } | | |||
78 | | ||||
79 | void RemoteCommandsPlugin::triggerCommand(const QString& key) | | |||
80 | { | | |||
81 | NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{ "key", key }}); | | |||
82 | sendPacket(np); | | |||
83 | } | | |||
84 | | ||||
85 | #include "remotecommandsplugin.moc" | 63 | #include "remotecommandsplugin.moc" |