MCPcopy Create free account
hub / github.com/KDE/kdeconnect-kde / receivePacket

Method receivePacket

plugins/runcommand/runcommandplugin.cpp:44–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void RunCommandPlugin::receivePacket(const NetworkPacket &np)
45{
46 if (np.get<bool>(QStringLiteral("requestCommandList"), false)) {
47 sendConfig();
48 return;
49 }
50
51 if (np.has(QStringLiteral("key"))) {
52 QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->getByteArray(QStringLiteral("commands"), "{}"));
53 QJsonObject commands = commandsDocument.object();
54 QString key = np.get<QString>(QStringLiteral("key"));
55 QJsonValue value = commands[key];
56 if (value == QJsonValue::Undefined) {
57 qCWarning(KDECONNECT_PLUGIN_RUNCOMMAND) << key << "is not a configured command";
58 }
59 const QJsonObject commandJson = value.toObject();
60 qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << COMMAND << ARGS << commandJson[QStringLiteral("command")].toString();
61 QProcess::startDetached(QStringLiteral(COMMAND), QStringList{QStringLiteral(ARGS), commandJson[QStringLiteral("command")].toString()});
62 } else if (np.has(QStringLiteral("setup"))) {
63 OpenConfig oc;
64 oc.openConfiguration(device()->id(), QStringLiteral("kdeconnect_runcommand"));
65 }
66}
67
68void RunCommandPlugin::connected()
69{

Callers

nothing calls this directly

Calls 4

getByteArrayMethod · 0.80
toStringMethod · 0.80
openConfigurationMethod · 0.80
idMethod · 0.45

Tested by

no test coverage detected