File indexing completed on 2024-04-14 04:51:49

0001 /**
0002  * SPDX-FileCopyrightText: 2014 Pramod Dematagoda <pmdematagoda@mykolab.ch>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "screensaverinhibitplugin.h"
0008 
0009 #include "generated/systeminterfaces/screensaver.h"
0010 #include <KLocalizedString>
0011 #include <KPluginFactory>
0012 #include <QDBusConnection>
0013 
0014 K_PLUGIN_CLASS_WITH_JSON(ScreensaverInhibitPlugin, "kdeconnect_screensaver_inhibit.json")
0015 
0016 #define INHIBIT_SERVICE QStringLiteral("org.freedesktop.ScreenSaver")
0017 #define INHIBIT_PATH QStringLiteral("/ScreenSaver")
0018 
0019 ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args)
0020     : KdeConnectPlugin(parent, args)
0021 {
0022     OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
0023 
0024     inhibitCookie = inhibitInterface.Inhibit(QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
0025 }
0026 
0027 ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
0028 {
0029     if (inhibitCookie == 0)
0030         return;
0031 
0032     OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
0033     inhibitInterface.UnInhibit(inhibitCookie);
0034 
0035     /*
0036      * Simulate user activity because what ever manages the screensaver does not seem to start the timer
0037      * automatically when all inhibitions are lifted and the user does nothing which results in an
0038      * unlocked desktop which would be dangerous. Ideally we should not be doing this and the screen should
0039      * be locked anyway.
0040      */
0041     inhibitInterface.SimulateUserActivity();
0042 }
0043 
0044 #include "moc_screensaverinhibitplugin.cpp"
0045 #include "screensaverinhibitplugin.moc"