[OpenDocString] kdeconnect-kde (cpp)
pingplugin.cpp
PingPlugin::PingPlugin(QObject *parent, const QVariantList &args)
    : KdeConnectPlugin(parent, args)
{
    //     qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin constructor for device" << device()->name();
}
Constructs a KdeConnectPlugin object and pings it for the current device.
PingPlugin::~PingPlugin()
{
    //     qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin destructor for device" << device()->name();
}
This removes the plugin object from the internal list of plugins.
bool PingPlugin::receivePacket(const NetworkPacket &np)
{
    Daemon::instance()->sendSimpleNotification(QStringLiteral("pingReceived"),
                                               device()->name(),
                                               np.get(QStringLiteral("message"), i18n("Ping!")),
                                               QStringLiteral("dialog-ok"));

    return true;
}
This sends a network packet to the device, and returns true on success.
void PingPlugin::sendPing()
{
    NetworkPacket np(PACKET_TYPE_PING);
    bool success = sendPacket(np);
    qCDebug(KDECONNECT_PLUGIN_PING) << "sendPing:" << success;
}
This sends a PING network packet.
void PingPlugin::sendPing(const QString &customMessage)
{
    NetworkPacket np(PACKET_TYPE_PING);
    if (!customMessage.isEmpty()) {
        np.set(QStringLiteral("message"), customMessage);
    }
    bool success = sendPacket(np);
    qCDebug(KDECONNECT_PLUGIN_PING) << "sendPing:" << success;
}
This sends a ping network packet, with a custom message.
QString PingPlugin::dbusPath() const
{
    return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/ping");
}
Returns the dbus path as a QString.