4 #include <QDBusInterface>
6 #include <QDBusConnectionInterface>
10 const char *fdDisplayService = "org.freedesktop.ScreenSaver";
11 const char *fdDisplayPath = "/org/freedesktop/ScreenSaver";
12 const char *fdDisplayInterface = fdDisplayService;
14 const char *gnomeSystemService = "org.gnome.SessionManager";
15 const char *gnomeSystemPath = "/org/gnome/SessionManager";
16 const char *gnomeSystemInterface = gnomeSystemService;
21 bool handleReply(const QDBusReply<quint32> &reply) {
22 if (reply.isValid()) {
23 cookie = reply.value();
24 qDebug() << "Success!" << cookie;
28 errorMessage = reply.error().message();
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);
40 bool Idle::allowDisplaySleep() {
41 QDBusInterface dbus(fdDisplayService, fdDisplayPath, fdDisplayInterface);
42 dbus.call("UnInhibit", cookie);
46 QString Idle::displayErrorMessage() {
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);
56 bool Idle::allowSystemSleep() {
57 QDBusInterface dbus(gnomeSystemService, gnomeSystemPath, gnomeSystemInterface);
58 dbus.call("UnInhibit", cookie);
62 QString Idle::systemErrorMessage() {