[OpenDocString] kdeconnect-kde (cpp)
screensaverinhibitplugin.cpp
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args)
    : KdeConnectPlugin(parent, args)
{
    OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);

    inhibitCookie = inhibitInterface.Inhibit(QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
}
Constructs a new instance of the ScreensaverInhibitPlugin class. The inhibit cookie is created and sent to the QDBusConnection::sessionBus(), and the daemon is connected.
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
{
    if (inhibitCookie == 0)
        return;

    OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
    inhibitInterface.UnInhibit(inhibitCookie);

    /*
     * Simulate user activity because what ever manages the screensaver does not seem to start the timer
     * automatically when all inhibitions are lifted and the user does nothing which results in an
     * unlocked desktop which would be dangerous. Ideally we should not be doing this and the screen should
     * be locked anyway.
     */
    inhibitInterface.SimulateUserActivity();
}
This removes the inhibit cookie from the internal list of inhibits, and sets the timer to stop the timer automatically when all inhibitions are lifted and the user does nothing when all inhibitions are lifted and the screen should not be locked. It is also possible to set the timer to start the timer automatically when all inhibitions are lifted and the screen should not be locked.
void ScreensaverInhibitPlugin::connected()
{
}
This implements the connection attempt at the end of the procedure.
bool ScreensaverInhibitPlugin::receivePacket(const NetworkPacket &np)
{
    Q_UNUSED(np);
    return false;
}
This retrieves a packet from the inhibit plugin and marks it for delivery.