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"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
2015-01-11 04:14:01 +00:00
|
|
|
#include <KPluginFactory>
|
2014-12-29 08:03:41 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusInterface>
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "kdeconnect_screensaverinhibit_debug.h"
|
2014-12-29 08:03:41 +00:00
|
|
|
|
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_INTERFACE INHIBIT_SERVICE
|
|
|
|
#define INHIBIT_PATH QStringLiteral("/ScreenSaver")
|
|
|
|
#define INHIBIT_METHOD QStringLiteral("Inhibit")
|
|
|
|
#define UNINHIBIT_METHOD QStringLiteral("UnInhibit")
|
|
|
|
#define SIMULATE_ACTIVITY_METHOD QStringLiteral("SimulateUserActivity")
|
2014-12-29 08:03:41 +00:00
|
|
|
|
|
|
|
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject* parent, const QVariantList& args)
|
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
{
|
2015-04-04 18:05:55 +01:00
|
|
|
QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE);
|
2014-12-29 08:03:41 +00:00
|
|
|
|
2019-05-13 23:35:44 +01:00
|
|
|
QDBusMessage reply = inhibitInterface.call(INHIBIT_METHOD, QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
|
2014-12-29 08:03:41 +00:00
|
|
|
|
2019-06-10 15:40:28 +01:00
|
|
|
if (!reply.errorMessage().isEmpty()) {
|
2015-01-11 04:14:01 +00:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_SCREENSAVERINHIBIT) << "Unable to inhibit the screensaver: " << reply.errorMessage();
|
2015-04-04 18:05:55 +01:00
|
|
|
inhibitCookie = 0;
|
|
|
|
} else {
|
2015-01-11 04:14:01 +00:00
|
|
|
// Store the cookie we receive, this will be sent back when sending the uninhibit call.
|
2015-09-12 08:53:05 +01:00
|
|
|
inhibitCookie = reply.arguments().at(0).toUInt();
|
2015-04-04 18:05:55 +01:00
|
|
|
}
|
2014-12-29 08:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
|
|
|
{
|
2015-04-04 18:05:55 +01:00
|
|
|
if (inhibitCookie == 0) return;
|
|
|
|
|
|
|
|
QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE);
|
|
|
|
inhibitInterface.call(UNINHIBIT_METHOD, this->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.call(SIMULATE_ACTIVITY_METHOD);
|
2014-12-29 08:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensaverInhibitPlugin::connected()
|
2015-04-04 18:05:55 +01:00
|
|
|
{
|
|
|
|
}
|
2014-12-29 08:03:41 +00:00
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
bool ScreensaverInhibitPlugin::receivePacket(const NetworkPacket& np)
|
2014-12-29 08:03:41 +00:00
|
|
|
{
|
2015-01-11 04:14:01 +00:00
|
|
|
Q_UNUSED(np);
|
|
|
|
return false;
|
2014-12-29 08:03:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 04:14:01 +00:00
|
|
|
#include "screensaverinhibitplugin.moc"
|