From b272ab86b3d6b038515044da8706a19d925e3597 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Sat, 14 Nov 2020 06:38:04 +0530 Subject: [PATCH] lockdeviceplugin: make plugin useful through CLI by --lock and --unlock --- cli/kdeconnect-cli.cpp | 11 +++++++++++ plugins/lockdevice/lockdeviceplugin.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp index 3096629b8..915c7266d 100644 --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -51,6 +51,7 @@ int main(int argc, char** argv) parser.addOption(QCommandLineOption(QStringLiteral("share-text"), i18n("Share text to a said device"), QStringLiteral("text"))); parser.addOption(QCommandLineOption(QStringLiteral("list-notifications"), i18n("Display the notifications on a said device"))); parser.addOption(QCommandLineOption(QStringLiteral("lock"), i18n("Lock the specified device"))); + parser.addOption(QCommandLineOption(QStringLiteral("unlock"), i18n("Unlock the specified device"))); parser.addOption(QCommandLineOption(QStringLiteral("send-sms"), i18n("Sends an SMS. Requires destination"), i18n("message"))); parser.addOption(QCommandLineOption(QStringLiteral("destination"), i18n("Phone number to send the message"), i18n("phone number"))); parser.addOption(QCommandLineOption(QStringLiteral("attachment"), i18n("File urls to send attachments with the message (can be passed multiple times)"), i18n("file urls"))); @@ -205,6 +206,16 @@ int main(int argc, char** argv) msg.setArguments(QVariantList() << parser.value(QStringLiteral("share-text"))); blockOnReply(DBusHelper::sessionBus().asyncCall(msg)); QTextStream(stdout) << i18n("Shared text: %1", parser.value(QStringLiteral("share-text"))) << endl; + } else if (parser.isSet(QStringLiteral("lock")) || parser.isSet(QStringLiteral("unlock"))) { + LockDeviceDbusInterface iface(device); + iface.setLocked(parser.isSet(QStringLiteral("lock"))); + + DeviceDbusInterface deviceIface(device); + if (parser.isSet(QStringLiteral("lock"))) { + QTextStream(stdout) << i18nc("device has requested to lock peer device", "Requested to lock %1.", deviceIface.name()) << endl; + } else { + QTextStream(stdout) << i18nc("device has requested to unlock peer device", "Requested to unlock %1.", deviceIface.name()) << endl; + } } else if(parser.isSet(QStringLiteral("pair"))) { DeviceDbusInterface dev(device); if (!dev.isReachable()) { diff --git a/plugins/lockdevice/lockdeviceplugin.h b/plugins/lockdevice/lockdeviceplugin.h index d3b502e2b..b4d4b1ad0 100644 --- a/plugins/lockdevice/lockdeviceplugin.h +++ b/plugins/lockdevice/lockdeviceplugin.h @@ -29,7 +29,7 @@ public: ~LockDevicePlugin() override; bool isLocked() const; - void setLocked(bool b); + Q_SCRIPTABLE void setLocked(bool); QString dbusPath() const override; void connected() override;