2014-12-29 08:03:41 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2014 Pramod Dematagoda <pmdematagoda@mykolab.ch>
|
2014-12-29 08:03:41 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2014-12-29 08:03:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "screensaverinhibitplugin.h"
|
|
|
|
|
2023-07-24 13:18:47 +01:00
|
|
|
#include "generated/systeminterfaces/screensaver.h"
|
2014-12-29 08:03:41 +00:00
|
|
|
#include <KLocalizedString>
|
2015-01-11 04:14:01 +00:00
|
|
|
#include <KPluginFactory>
|
2014-12-29 08:03:41 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
|
2019-06-12 21:16:54 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(ScreensaverInhibitPlugin, "kdeconnect_screensaver_inhibit.json")
|
2015-01-11 04:14:01 +00:00
|
|
|
|
2019-05-05 14:58:50 +01:00
|
|
|
#define INHIBIT_SERVICE QStringLiteral("org.freedesktop.ScreenSaver")
|
|
|
|
#define INHIBIT_PATH QStringLiteral("/ScreenSaver")
|
2014-12-29 08:03:41 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args)
|
2014-12-29 08:03:41 +00:00
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
{
|
2020-07-30 00:00:01 +01:00
|
|
|
OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
|
2014-12-29 08:03:41 +00:00
|
|
|
|
2020-07-30 00:00:01 +01:00
|
|
|
inhibitCookie = inhibitInterface.Inhibit(QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
|
2014-12-29 08:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
if (inhibitCookie == 0)
|
|
|
|
return;
|
2015-04-04 18:05:55 +01:00
|
|
|
|
2020-07-30 00:00:01 +01:00
|
|
|
OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
|
|
|
|
inhibitInterface.UnInhibit(inhibitCookie);
|
2015-04-04 18:05:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-07-30 00:00:01 +01:00
|
|
|
inhibitInterface.SimulateUserActivity();
|
2014-12-29 08:03:41 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_screensaverinhibitplugin.cpp"
|
2015-01-11 04:14:01 +00:00
|
|
|
#include "screensaverinhibitplugin.moc"
|