kdeconnect-kde/plugins/ping/pingplugin.cpp

54 lines
1.5 KiB
C++
Raw Normal View History

/**
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
2013-08-13 04:14:46 +01:00
#include "pingplugin.h"
2013-09-04 20:19:02 +01:00
#include <KLocalizedString>
#include <KPluginFactory>
2015-03-10 04:59:36 +00:00
#include <QDBusConnection>
#include <QDebug>
2015-03-10 04:59:36 +00:00
#include <core/daemon.h>
#include <core/device.h>
#include "plugin_ping_debug.h"
K_PLUGIN_CLASS_WITH_JSON(PingPlugin, "kdeconnect_ping.json")
2014-09-21 23:45:41 +01:00
void PingPlugin::receivePacket(const NetworkPacket &np)
{
Daemon::instance()->sendSimpleNotification(QStringLiteral("pingReceived"),
device()->name(),
np.get<QString>(QStringLiteral("message"), i18n("Ping!")),
QStringLiteral("dialog-ok"));
}
void PingPlugin::sendPing()
{
NetworkPacket np(PACKET_TYPE_PING);
bool success = sendPacket(np);
2014-09-21 23:45:41 +01:00
qCDebug(KDECONNECT_PLUGIN_PING) << "sendPing:" << success;
}
void PingPlugin::sendPing(const QString &customMessage)
2014-09-27 04:39:38 +01:00
{
NetworkPacket np(PACKET_TYPE_PING);
2014-09-27 04:39:38 +01:00
if (!customMessage.isEmpty()) {
np.set(QStringLiteral("message"), customMessage);
2014-09-27 04:39:38 +01:00
}
bool success = sendPacket(np);
qCDebug(KDECONNECT_PLUGIN_PING) << "sendPing:" << success;
2014-09-27 04:39:38 +01:00
}
QString PingPlugin::dbusPath() const
{
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/ping");
}
#include "moc_pingplugin.cpp"
#include "pingplugin.moc"