Customizable ping messages.
This commit is contained in:
parent
2cffbedcd4
commit
f41fb4de2a
3 changed files with 24 additions and 9 deletions
|
@ -37,14 +37,15 @@ int main(int argc, char** argv)
|
||||||
KCmdLineArgs::init(argc, argv, &about);
|
KCmdLineArgs::init(argc, argv, &about);
|
||||||
KCmdLineOptions options;
|
KCmdLineOptions options;
|
||||||
options.add("l")
|
options.add("l")
|
||||||
.add("list-devices", ki18n("List all devices"));
|
.add("list-devices", ki18n("List all devices."));
|
||||||
options.add("refresh", ki18n("Search for devices in the network and re-establish connections."));
|
options.add("refresh", ki18n("Search for devices in the network and re-establish connections."));
|
||||||
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("ping", ki18n("Send a ping to said device."));
|
||||||
options.add("share <path>", ki18n("Share a file to a said device"));
|
options.add("ping-msg <message>", ki18n("Same as ping but you can customize the shown message."));
|
||||||
options.add("list-notifications", ki18n("Display the notifications on a said device"));
|
options.add("share <path>", ki18n("Share a file to a said device."));
|
||||||
options.add("device <dev>", ki18n("Device ID"));
|
options.add("list-notifications", ki18n("Display the notifications on a said device."));
|
||||||
|
options.add("device <dev>", ki18n("Device ID."));
|
||||||
KCmdLineArgs::addCmdLineOptions( options );
|
KCmdLineArgs::addCmdLineOptions( options );
|
||||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||||
KApplication app;
|
KApplication app;
|
||||||
|
@ -103,8 +104,12 @@ 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")) {
|
} else if(args->isSet("ping") || args->isSet("ping-msg")) {
|
||||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/ping", "org.kde.kdeconnect.device.ping", "sendPing");
|
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/ping", "org.kde.kdeconnect.device.ping", "sendPing");
|
||||||
|
if (args->isSet("ping-msg")) {
|
||||||
|
QString message = args->getOption("ping-msg");
|
||||||
|
msg.setArguments(QVariantList() << message);
|
||||||
|
}
|
||||||
QDBusConnection::sessionBus().call(msg);
|
QDBusConnection::sessionBus().call(msg);
|
||||||
} else if(args->isSet("list-notifications")) {
|
} else if(args->isSet("list-notifications")) {
|
||||||
NotificationsModel notifications;
|
NotificationsModel notifications;
|
||||||
|
|
|
@ -52,7 +52,6 @@ bool PingPlugin::receivePackage(const NetworkPackage& np)
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PingPlugin::sendPing()
|
void PingPlugin::sendPing()
|
||||||
|
@ -62,6 +61,16 @@ void PingPlugin::sendPing()
|
||||||
kDebug(debugArea()) << "sendPing:" << success;
|
kDebug(debugArea()) << "sendPing:" << success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PingPlugin::sendPing(const QString& customMessage)
|
||||||
|
{
|
||||||
|
NetworkPackage np(PACKAGE_TYPE_PING);
|
||||||
|
if (!customMessage.isEmpty()) {
|
||||||
|
np.set("message", customMessage);
|
||||||
|
}
|
||||||
|
bool success = sendPackage(np);
|
||||||
|
kDebug(debugArea()) << "sendPing:" << success;
|
||||||
|
}
|
||||||
|
|
||||||
void PingPlugin::connected()
|
void PingPlugin::connected()
|
||||||
{
|
{
|
||||||
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
|
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
virtual ~PingPlugin();
|
virtual ~PingPlugin();
|
||||||
|
|
||||||
Q_SCRIPTABLE void sendPing();
|
Q_SCRIPTABLE void sendPing();
|
||||||
|
Q_SCRIPTABLE void sendPing(const QString& customMessage);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual bool receivePackage(const NetworkPackage& np);
|
virtual bool receivePackage(const NetworkPackage& np);
|
||||||
|
|
Loading…
Reference in a new issue