]> git.sur5r.net Git - minitube/blob - src/idle/src/idle_linux.cpp
Update watch file to use releases instead of tags
[minitube] / src / idle / src / idle_linux.cpp
1 #include "idle.h"
2
3 #include <QtCore>
4 #include <QDBusInterface>
5 #include <QDBusReply>
6 #include <QDBusConnectionInterface>
7
8 namespace {
9
10 const char *fdDisplayService = "org.freedesktop.ScreenSaver";
11 const char *fdDisplayPath = "/org/freedesktop/ScreenSaver";
12 const char *fdDisplayInterface = fdDisplayService;
13
14 const char *gnomeSystemService = "org.gnome.SessionManager";
15 const char *gnomeSystemPath = "/org/gnome/SessionManager";
16 const char *gnomeSystemInterface = gnomeSystemService;
17
18 quint32 cookie;
19 QString errorMessage;
20
21 bool handleReply(const QDBusReply<quint32> &reply) {
22     if (reply.isValid()) {
23         cookie = reply.value();
24         qDebug() << "Success!" << cookie;
25         errorMessage.clear();
26         return true;
27     }
28     errorMessage = reply.error().message();
29     return false;
30 }
31
32 }
33
34 bool Idle::preventDisplaySleep(const QString &reason) {
35     QDBusInterface dbus(fdDisplayService, fdDisplayPath, fdDisplayInterface);
36     QDBusReply<quint32> reply = dbus.call("Inhibit", QCoreApplication::applicationName(), reason);
37     return handleReply(reply);
38 }
39
40 bool Idle::allowDisplaySleep() {
41     QDBusInterface dbus(fdDisplayService, fdDisplayPath, fdDisplayInterface);
42     dbus.call("UnInhibit", cookie);
43     return true;
44 }
45
46 QString Idle::displayErrorMessage() {
47     return errorMessage;
48 }
49
50 bool Idle::preventSystemSleep(const QString &reason) {
51     QDBusInterface dbus(gnomeSystemService, gnomeSystemPath, gnomeSystemInterface);
52     QDBusReply<quint32> reply = dbus.call("Inhibit", QCoreApplication::applicationName(), reason);
53     return handleReply(reply);
54 }
55
56 bool Idle::allowSystemSleep() {
57     QDBusInterface dbus(gnomeSystemService, gnomeSystemPath, gnomeSystemInterface);
58     dbus.call("UnInhibit", cookie);
59     return true;
60 }
61
62 QString Idle::systemErrorMessage() {
63     return errorMessage;
64 }
65