From c8dbbed685cb6abde9cf13958764c6b30446b0b9 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 27 Jun 2014 18:21:40 +0200 Subject: [PATCH] Move the send ping code to the ping plugin turn it into a dbus call to the plugin Reviewed by Albert Vaca --- cli/kdeconnect-cli.cpp | 4 ++++ core/device.cpp | 7 ------- core/device.h | 1 - kcm/kcm.cpp | 3 ++- plugins/ping/kdeconnect_ping.desktop | 2 +- plugins/ping/pingplugin.cpp | 18 ++++++++++++++++++ plugins/ping/pingplugin.h | 7 ++++++- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp index a4c4fd8d..d425bd3e 100644 --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -40,6 +40,7 @@ int main(int argc, char** argv) 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("ping", ki18n("Sends a ping to said device")); options.add("device ", ki18n("Device ID")); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); @@ -98,6 +99,9 @@ int main(int argc, char** argv) QDBusPendingReply req = dev.unpair(); req.waitForFinished(); } + } else if(args->isSet("ping")) { + QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/ping", "org.kde.kdeconnect.device.ping", "sendPing"); + QDBusConnection::sessionBus().call(msg); } else KCmdLineArgs::usageError(i18n("Nothing to be done with the device")); } diff --git a/core/device.cpp b/core/device.cpp index 29982e70..b0051401 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -470,13 +470,6 @@ QStringList Device::availableLinks() const return sl; } -void Device::sendPing() -{ - NetworkPackage np(PACKAGE_TYPE_PING); - bool success = sendPackage(np); - kDebug(kdeconnect_kded()) << "sendPing:" << success; -} - Device::DeviceType Device::str2type(QString deviceType) { if (deviceType == "desktop") return Desktop; if (deviceType == "laptop") return Laptop; diff --git a/core/device.h b/core/device.h index ec757b8d..d1543007 100644 --- a/core/device.h +++ b/core/device.h @@ -105,7 +105,6 @@ public Q_SLOTS: Q_SCRIPTABLE void requestPair(); Q_SCRIPTABLE void unpair(); Q_SCRIPTABLE void reloadPlugins(); //From kconf - Q_SCRIPTABLE void sendPing(); void acceptPairing(); void rejectPairing(); diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 78a39cf9..f809a53c 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -250,5 +250,6 @@ void KdeConnectKcm::save() void KdeConnectKcm::sendPing() { if (!currentDevice) return; - currentDevice->sendPing(); + QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+currentDevice->id()+"/ping", "org.kde.kdeconnect.device.ping", "sendPing"); + QDBusConnection::sessionBus().call(msg); } diff --git a/plugins/ping/kdeconnect_ping.desktop b/plugins/ping/kdeconnect_ping.desktop index 23bfe8eb..aa6c7a54 100644 --- a/plugins/ping/kdeconnect_ping.desktop +++ b/plugins/ping/kdeconnect_ping.desktop @@ -59,4 +59,4 @@ Comment[uk]=Надсилання і отримання сигналів підт Comment[x-test]=xxSend and receive pingsxx X-KdeConnect-SupportedPackageType=kdeconnect.ping -# X-KdeConnect-OutgoingPackageType=kdeconnect.ping +X-KdeConnect-OutgoingPackageType=kdeconnect.ping diff --git a/plugins/ping/pingplugin.cpp b/plugins/ping/pingplugin.cpp index 182cdbcd..5d5575c0 100644 --- a/plugins/ping/pingplugin.cpp +++ b/plugins/ping/pingplugin.cpp @@ -26,6 +26,7 @@ #include #include +#include K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PingPlugin >(); ) K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_ping", "kdeconnect-plugins") ) @@ -53,3 +54,20 @@ bool PingPlugin::receivePackage(const NetworkPackage& np) return true; } + +void PingPlugin::sendPing() +{ + NetworkPackage np(PACKAGE_TYPE_PING); + bool success = sendPackage(np); + kDebug(kdeconnect_kded()) << "sendPing:" << success; +} + +void PingPlugin::connected() +{ + QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); +} + +QString PingPlugin::dbusPath() const +{ + return "/modules/kdeconnect/devices/" + device()->id() + "/ping"; +} diff --git a/plugins/ping/pingplugin.h b/plugins/ping/pingplugin.h index f31e6604..31563074 100644 --- a/plugins/ping/pingplugin.h +++ b/plugins/ping/pingplugin.h @@ -29,15 +29,20 @@ class KDE_EXPORT PingPlugin : public KdeConnectPlugin { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.ping") public: explicit PingPlugin(QObject *parent, const QVariantList &args); virtual ~PingPlugin(); + Q_SCRIPTABLE void sendPing(); + public Q_SLOTS: virtual bool receivePackage(const NetworkPackage& np); - virtual void connected() { }; + virtual void connected(); +private: + QString dbusPath() const; }; #endif -- 2.24.1