[OpenDocString] kdeconnect-kde (cpp)
linkprovider.cpp
LinkProvider::LinkProvider()
{
    // Terminate connections when we sleep or shut down.
    QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"),
                                         QStringLiteral("/org/freedesktop/login1"),
                                         QStringLiteral("org.freedesktop.login1.Manager"),
                                         QStringLiteral("PrepareForSleep"),
                                         this,
                                         SLOT(suspend(bool)));
    QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"),
                                         QStringLiteral("/org/freedesktop/login1"),
                                         QStringLiteral("org.freedesktop.login1.Manager"),
                                         QStringLiteral("PrepareForShutdown"),
                                         this,
                                         SLOT(suspend(bool)));
}
This links to the OS bus when we sleep or shut down.
void LinkProvider::suspend(bool suspend)
{
    if (suspend) {
        qCDebug(KDECONNECT_CORE) << "Stopping connection for suspension";
        onStop();
    } else {
        qCDebug(KDECONNECT_CORE) << "Restarting connection after suspension";
        onStart();
    }
}
This code sets the suspend flag and stops the connection if it is necessary. If it is false, it logs a message and restarts the connection after the suspension.