[plugins/screensaver] Port away from QDBusInterface
It's better overall and makes Kai happy
This commit is contained in:
parent
4372678c1f
commit
8b4eaa54b4
3 changed files with 87 additions and 18 deletions
|
@ -10,6 +10,7 @@ else()
|
||||||
set(kdeconnect_screensaver_inhibit_SRCS
|
set(kdeconnect_screensaver_inhibit_SRCS
|
||||||
screensaverinhibitplugin.cpp
|
screensaverinhibitplugin.cpp
|
||||||
)
|
)
|
||||||
|
qt5_add_dbus_interface(kdeconnect_screensaver_inhibit_SRCS org.freedesktop.ScreenSaver.xml screensaverinterface)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(debug_file_SRCS)
|
set(debug_file_SRCS)
|
||||||
|
|
80
plugins/screensaver-inhibit/org.freedesktop.ScreenSaver.xml
Normal file
80
plugins/screensaver-inhibit/org.freedesktop.ScreenSaver.xml
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||||
|
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||||
|
<node>
|
||||||
|
<interface name="org.freedesktop.ScreenSaver">
|
||||||
|
<signal name="ActiveChanged">
|
||||||
|
<arg type="b"/>
|
||||||
|
</signal>
|
||||||
|
<method name="Lock"/>
|
||||||
|
<method name="SimulateUserActivity"/>
|
||||||
|
<method name="GetActive">
|
||||||
|
<arg direction="out" type="b"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetActiveTime">
|
||||||
|
<arg direction="out" type="u" name="seconds"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetSessionIdleTime">
|
||||||
|
<arg direction="out" type="u" name="seconds"/>
|
||||||
|
</method>
|
||||||
|
<method name="SetActive">
|
||||||
|
<arg direction="out" type="b"/>
|
||||||
|
<arg direction="in" type="b" name="e"/>
|
||||||
|
</method>
|
||||||
|
<method name="Inhibit">
|
||||||
|
<arg direction="in" type="s" name="application_name"/>
|
||||||
|
<arg direction="in" type="s" name="reason_for_inhibit"/>
|
||||||
|
<arg direction="out" type="u" name="cookie"/>
|
||||||
|
</method>
|
||||||
|
<method name="UnInhibit">
|
||||||
|
<arg direction="in" type="u" name="cookie"/>
|
||||||
|
</method>
|
||||||
|
<method name="Throttle">
|
||||||
|
<arg direction="in" type="s" name="application_name"/>
|
||||||
|
<arg direction="in" type="s" name="reason_for_inhibit"/>
|
||||||
|
<arg direction="out" type="u" name="cookie"/>
|
||||||
|
</method>
|
||||||
|
<method name="UnThrottle">
|
||||||
|
<arg direction="in" type="u" name="cookie"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
<interface name="org.kde.screensaver">
|
||||||
|
<method name="SwitchUser"/>
|
||||||
|
<method name="configure"/>
|
||||||
|
<signal name="AboutToLock"/>
|
||||||
|
</interface>
|
||||||
|
<interface name="org.freedesktop.DBus.Properties">
|
||||||
|
<method name="Get">
|
||||||
|
<arg name="interface_name" type="s" direction="in"/>
|
||||||
|
<arg name="property_name" type="s" direction="in"/>
|
||||||
|
<arg name="value" type="v" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Set">
|
||||||
|
<arg name="interface_name" type="s" direction="in"/>
|
||||||
|
<arg name="property_name" type="s" direction="in"/>
|
||||||
|
<arg name="value" type="v" direction="in"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetAll">
|
||||||
|
<arg name="interface_name" type="s" direction="in"/>
|
||||||
|
<arg name="values" type="a{sv}" direction="out"/>
|
||||||
|
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
|
||||||
|
</method>
|
||||||
|
<signal name="PropertiesChanged">
|
||||||
|
<arg name="interface_name" type="s" direction="out"/>
|
||||||
|
<arg name="changed_properties" type="a{sv}" direction="out"/>
|
||||||
|
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
|
||||||
|
<arg name="invalidated_properties" type="as" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
</interface>
|
||||||
|
<interface name="org.freedesktop.DBus.Introspectable">
|
||||||
|
<method name="Introspect">
|
||||||
|
<arg name="xml_data" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
<interface name="org.freedesktop.DBus.Peer">
|
||||||
|
<method name="Ping"/>
|
||||||
|
<method name="GetMachineId">
|
||||||
|
<arg name="machine_uuid" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
|
|
|
@ -9,40 +9,28 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusInterface>
|
#include "screensaverinterface.h"
|
||||||
#include "kdeconnect_screensaverinhibit_debug.h"
|
#include "kdeconnect_screensaverinhibit_debug.h"
|
||||||
|
|
||||||
K_PLUGIN_CLASS_WITH_JSON(ScreensaverInhibitPlugin, "kdeconnect_screensaver_inhibit.json")
|
K_PLUGIN_CLASS_WITH_JSON(ScreensaverInhibitPlugin, "kdeconnect_screensaver_inhibit.json")
|
||||||
|
|
||||||
#define INHIBIT_SERVICE QStringLiteral("org.freedesktop.ScreenSaver")
|
#define INHIBIT_SERVICE QStringLiteral("org.freedesktop.ScreenSaver")
|
||||||
#define INHIBIT_INTERFACE INHIBIT_SERVICE
|
|
||||||
#define INHIBIT_PATH QStringLiteral("/ScreenSaver")
|
#define INHIBIT_PATH QStringLiteral("/ScreenSaver")
|
||||||
#define INHIBIT_METHOD QStringLiteral("Inhibit")
|
|
||||||
#define UNINHIBIT_METHOD QStringLiteral("UnInhibit")
|
|
||||||
#define SIMULATE_ACTIVITY_METHOD QStringLiteral("SimulateUserActivity")
|
|
||||||
|
|
||||||
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject* parent, const QVariantList& args)
|
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject* parent, const QVariantList& args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
{
|
{
|
||||||
QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE);
|
OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
|
||||||
|
|
||||||
QDBusMessage reply = inhibitInterface.call(INHIBIT_METHOD, QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
|
inhibitCookie = inhibitInterface.Inhibit(QStringLiteral("org.kde.kdeconnect.daemon"), i18n("Phone is connected"));
|
||||||
|
|
||||||
if (!reply.errorMessage().isEmpty()) {
|
|
||||||
qCDebug(KDECONNECT_PLUGIN_SCREENSAVERINHIBIT) << "Unable to inhibit the screensaver: " << reply.errorMessage();
|
|
||||||
inhibitCookie = 0;
|
|
||||||
} else {
|
|
||||||
// Store the cookie we receive, this will be sent back when sending the uninhibit call.
|
|
||||||
inhibitCookie = reply.arguments().at(0).toUInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
||||||
{
|
{
|
||||||
if (inhibitCookie == 0) return;
|
if (inhibitCookie == 0) return;
|
||||||
|
|
||||||
QDBusInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, INHIBIT_INTERFACE);
|
OrgFreedesktopScreenSaverInterface inhibitInterface(INHIBIT_SERVICE, INHIBIT_PATH, QDBusConnection::sessionBus(), this);
|
||||||
inhibitInterface.call(UNINHIBIT_METHOD, this->inhibitCookie);
|
inhibitInterface.UnInhibit(inhibitCookie);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simulate user activity because what ever manages the screensaver does not seem to start the timer
|
* Simulate user activity because what ever manages the screensaver does not seem to start the timer
|
||||||
|
@ -50,7 +38,7 @@ ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
||||||
* unlocked desktop which would be dangerous. Ideally we should not be doing this and the screen should
|
* unlocked desktop which would be dangerous. Ideally we should not be doing this and the screen should
|
||||||
* be locked anyway.
|
* be locked anyway.
|
||||||
*/
|
*/
|
||||||
inhibitInterface.call(SIMULATE_ACTIVITY_METHOD);
|
inhibitInterface.SimulateUserActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreensaverInhibitPlugin::connected()
|
void ScreensaverInhibitPlugin::connected()
|
||||||
|
|
Loading…
Reference in a new issue