3 #include <QDBusConnectionInterface>
4 #include <QDBusInterface>
10 const QString fdDisplayService = "org.freedesktop.ScreenSaver";
11 const QString fdDisplayPath = "/org/freedesktop/ScreenSaver";
12 const QString fdDisplayInterface = fdDisplayService;
14 const QString gnomeSystemService = "org.gnome.SessionManager";
15 const QString gnomeSystemPath = "/org/gnome/SessionManager";
16 const QString gnomeSystemInterface = gnomeSystemService;
18 const QString inhibitMethod = "Inhibit";
19 const QString uninhibitMethod = "UnInhibit";
24 bool handleReply(const QDBusReply<quint32> &reply) {
25 if (reply.isValid()) {
26 cookie = reply.value();
30 errorMessage = reply.error().message();
36 bool Idle::preventDisplaySleep(const QString &reason) {
37 QDBusInterface dbus(fdDisplayService, fdDisplayPath, fdDisplayInterface);
38 QDBusReply<quint32> reply =
39 dbus.call(inhibitMethod, QCoreApplication::applicationName(), reason);
40 return handleReply(reply);
43 bool Idle::allowDisplaySleep() {
44 QDBusInterface dbus(fdDisplayService, fdDisplayPath, fdDisplayInterface);
45 dbus.call(uninhibitMethod, cookie);
49 QString Idle::displayErrorMessage() {
53 bool Idle::preventSystemSleep(const QString &reason) {
54 QDBusInterface dbus(gnomeSystemService, gnomeSystemPath, gnomeSystemInterface);
55 QDBusReply<quint32> reply =
56 dbus.call(inhibitMethod, QCoreApplication::applicationName(), reason);
57 return handleReply(reply);
60 bool Idle::allowSystemSleep() {
61 QDBusInterface dbus(gnomeSystemService, gnomeSystemPath, gnomeSystemInterface);
62 dbus.call(uninhibitMethod, cookie);
66 QString Idle::systemErrorMessage() {