Commit c8dbbed6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Move the send ping code to the ping plugin

turn it into a dbus call to the plugin

Reviewed by Albert Vaca
parent 59cab0dc
...@@ -40,6 +40,7 @@ int main(int argc, char** argv) ...@@ -40,6 +40,7 @@ int main(int argc, char** argv)
options.add("share <path>", ki18n("Share a file to a said device")); options.add("share <path>", ki18n("Share a file to a said device"));
options.add("pair", ki18n("Request pairing 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("unpair", ki18n("Stop pairing to a said device"));
options.add("ping", ki18n("Sends a ping to said device"));
options.add("device <dev>", ki18n("Device ID")); options.add("device <dev>", ki18n("Device ID"));
KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs::addCmdLineOptions( options );
KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
...@@ -98,6 +99,9 @@ int main(int argc, char** argv) ...@@ -98,6 +99,9 @@ int main(int argc, char** argv)
QDBusPendingReply<void> req = dev.unpair(); QDBusPendingReply<void> req = dev.unpair();
req.waitForFinished(); 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 } else
KCmdLineArgs::usageError(i18n("Nothing to be done with the device")); KCmdLineArgs::usageError(i18n("Nothing to be done with the device"));
} }
......
...@@ -470,13 +470,6 @@ QStringList Device::availableLinks() const ...@@ -470,13 +470,6 @@ QStringList Device::availableLinks() const
return sl; 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) { Device::DeviceType Device::str2type(QString deviceType) {
if (deviceType == "desktop") return Desktop; if (deviceType == "desktop") return Desktop;
if (deviceType == "laptop") return Laptop; if (deviceType == "laptop") return Laptop;
......
...@@ -105,7 +105,6 @@ public Q_SLOTS: ...@@ -105,7 +105,6 @@ public Q_SLOTS:
Q_SCRIPTABLE void requestPair(); Q_SCRIPTABLE void requestPair();
Q_SCRIPTABLE void unpair(); Q_SCRIPTABLE void unpair();
Q_SCRIPTABLE void reloadPlugins(); //From kconf Q_SCRIPTABLE void reloadPlugins(); //From kconf
Q_SCRIPTABLE void sendPing();
void acceptPairing(); void acceptPairing();
void rejectPairing(); void rejectPairing();
......
...@@ -250,5 +250,6 @@ void KdeConnectKcm::save() ...@@ -250,5 +250,6 @@ void KdeConnectKcm::save()
void KdeConnectKcm::sendPing() void KdeConnectKcm::sendPing()
{ {
if (!currentDevice) return; 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);
} }
...@@ -59,4 +59,4 @@ Comment[uk]=Надсилання і отримання сигналів підт ...@@ -59,4 +59,4 @@ Comment[uk]=Надсилання і отримання сигналів підт
Comment[x-test]=xxSend and receive pingsxx Comment[x-test]=xxSend and receive pingsxx
X-KdeConnect-SupportedPackageType=kdeconnect.ping X-KdeConnect-SupportedPackageType=kdeconnect.ping
# X-KdeConnect-OutgoingPackageType=kdeconnect.ping X-KdeConnect-OutgoingPackageType=kdeconnect.ping
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <core/kdebugnamespace.h> #include <core/kdebugnamespace.h>
#include <core/device.h> #include <core/device.h>
#include <QDBusConnection>
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PingPlugin >(); ) K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PingPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_ping", "kdeconnect-plugins") ) K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_ping", "kdeconnect-plugins") )
...@@ -53,3 +54,20 @@ bool PingPlugin::receivePackage(const NetworkPackage& np) ...@@ -53,3 +54,20 @@ bool PingPlugin::receivePackage(const NetworkPackage& np)
return true; 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";
}
...@@ -29,15 +29,20 @@ class KDE_EXPORT PingPlugin ...@@ -29,15 +29,20 @@ class KDE_EXPORT PingPlugin
: public KdeConnectPlugin : public KdeConnectPlugin
{ {
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.ping")
public: public:
explicit PingPlugin(QObject *parent, const QVariantList &args); explicit PingPlugin(QObject *parent, const QVariantList &args);
virtual ~PingPlugin(); virtual ~PingPlugin();
Q_SCRIPTABLE void sendPing();
public Q_SLOTS: public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np); virtual bool receivePackage(const NetworkPackage& np);
virtual void connected() { }; virtual void connected();
private:
QString dbusPath() const;
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment