From 02e18a97593af05fb1e8838eb7a146c2a15e9fa3 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 23 Jun 2014 18:15:10 +0200 Subject: [PATCH] Extend kdeconnect-cli Make it show whether devices are paired. Let it un/pair devices. Reviewed by Albert Vaca --- cli/kdeconnect-cli.cpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp index 184ef7e66..d7f0da331 100644 --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -23,20 +23,23 @@ #include #include #include +#include #include #include #include int main(int argc, char** argv) { - KAboutData about("kctool", "kdeconnect-cli", ki18n(("kctool")), "1.0", ki18n("KDE Connect CLI tool"), + KAboutData about("kdeconnect-cli", "kdeconnect-cli", ki18n(("kdeconnect-cli")), "1.0", ki18n("KDE Connect CLI tool"), KAboutData::License_GPL, ki18n("(C) 2013 Aleix Pol Gonzalez")); about.addAuthor( ki18n("Aleix Pol Gonzalez"), KLocalizedString(), "aleixpol@kde.org" ); KCmdLineArgs::init(argc, argv, &about); KCmdLineOptions options; options.add("l") .add("list-devices", ki18n("List all devices")); - options.add("share ", ki18n("Share a file")); + options.add("share ", ki18n("Share a file to a said device")); + options.add("pair", ki18n("Request pairing to a said device")); + options.add("unpair", ki18n("Stop pairing to a said device")); options.add("device ", ki18n("Device ID")); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); @@ -46,8 +49,10 @@ int main(int argc, char** argv) devices.setDisplayFilter(DevicesModel::StatusUnknown); for(int i=0, rows=devices.rowCount(); iisSet("share")) { url = args->makeURL(args->getOption("share").toLatin1()); - } - args->clear(); - - if(!url.isEmpty() && !device.isEmpty()) { - QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/share", "org.kde.kdeconnect.device.share", "shareUrl"); - msg.setArguments(QVariantList() << url.toString()); - - QDBusConnection::sessionBus().call(msg); + args->clear(); + if(!url.isEmpty() && !device.isEmpty()) { + QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/share", "org.kde.kdeconnect.device.share", "shareUrl"); + msg.setArguments(QVariantList() << url.toString()); + QDBusConnection::sessionBus().call(msg); + } else + KCmdLineArgs::usageError(i18n("Couldn't share %1", url.toString())); + } else if(args->isSet("pair")) { + DeviceDbusInterface dev(device); + if(dev.isPaired()) + std::cout << "Already paired" << std::endl; + else { + QDBusPendingReply req = dev.requestPair(); + req.waitForFinished(); + } + } else if(args->isSet("unpair")) { + DeviceDbusInterface dev(device); + if(!dev.isPaired()) + std::cout << "Already not paired" << std::endl; + else { + QDBusPendingReply req = dev.unpair(); + req.waitForFinished(); + } } else KCmdLineArgs::usageError(i18n("Nothing to be done with the device")); }