Move the send ping code to the ping plugin

turn it into a dbus call to the plugin

Reviewed by Albert Vaca
This commit is contained in:
Aleix Pol 2014-06-27 18:21:40 +02:00
parent 59cab0dc06
commit c8dbbed685
7 changed files with 31 additions and 11 deletions

View file

@ -40,6 +40,7 @@ int main(int argc, char** argv)
options.add("share <path>", 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 <dev>", ki18n("Device ID"));
KCmdLineArgs::addCmdLineOptions( options );
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
@ -98,6 +99,9 @@ int main(int argc, char** argv)
QDBusPendingReply<void> 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"));
}

View file

@ -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;

View file

@ -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();

View file

@ -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);
}

View file

@ -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

View file

@ -26,6 +26,7 @@
#include <core/kdebugnamespace.h>
#include <core/device.h>
#include <QDBusConnection>
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";
}

View file

@ -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