File indexing completed on 2024-04-21 04:56:52
0001 /** 0002 * SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "remotecommandsplugin.h" 0008 0009 #include <KPluginFactory> 0010 0011 #include <core/device.h> 0012 #include <core/networkpacket.h> 0013 0014 #include "plugin_remotecommands_debug.h" 0015 0016 #define PACKET_TYPE_RUNCOMMAND_REQUEST QLatin1String("kdeconnect.runcommand.request") 0017 0018 K_PLUGIN_CLASS_WITH_JSON(RemoteCommandsPlugin, "kdeconnect_remotecommands.json") 0019 0020 RemoteCommandsPlugin::RemoteCommandsPlugin(QObject *parent, const QVariantList &args) 0021 : KdeConnectPlugin(parent, args) 0022 , m_commands("{}") 0023 , m_canAddCommand(false) 0024 { 0025 } 0026 0027 void RemoteCommandsPlugin::receivePacket(const NetworkPacket &np) 0028 { 0029 if (np.has(QStringLiteral("commandList"))) { 0030 m_canAddCommand = np.get<bool>(QStringLiteral("canAddCommand")); 0031 setCommands(np.get<QByteArray>(QStringLiteral("commandList"))); 0032 } 0033 } 0034 0035 void RemoteCommandsPlugin::connected() 0036 { 0037 NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("requestCommandList"), true}}); 0038 sendPacket(np); 0039 } 0040 0041 QString RemoteCommandsPlugin::dbusPath() const 0042 { 0043 return QLatin1String("/modules/kdeconnect/devices/%1/remotecommands").arg(device()->id()); 0044 } 0045 0046 void RemoteCommandsPlugin::setCommands(const QByteArray &cmds) 0047 { 0048 if (m_commands != cmds) { 0049 m_commands = cmds; 0050 Q_EMIT commandsChanged(m_commands); 0051 } 0052 } 0053 0054 void RemoteCommandsPlugin::triggerCommand(const QString &key) 0055 { 0056 NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("key"), key}}); 0057 sendPacket(np); 0058 } 0059 0060 void RemoteCommandsPlugin::editCommands() 0061 { 0062 NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("setup"), true}}); 0063 sendPacket(np); 0064 } 0065 0066 #include "moc_remotecommandsplugin.cpp" 0067 #include "remotecommandsplugin.moc"