]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-qt/power.cpp
Revert removal of ConsoleKit support.
[sojka/lightdm.git] / liblightdm-qt / power.cpp
index fa366a1fb739d77dec63f236e97be0f12f6c60c3..a8cb4fae834973bde1c690d5b3f30aa37d70ba9e 100644 (file)
@@ -26,11 +26,13 @@ class PowerInterface::PowerInterfacePrivate
 public:
     PowerInterfacePrivate();
     QScopedPointer<QDBusInterface> powerManagementInterface;
+    QScopedPointer<QDBusInterface> consoleKitInterface;
     QScopedPointer<QDBusInterface> login1Interface;
 };
 
 PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() :
     powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())),
+    consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus())),
     login1Interface(new QDBusInterface("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()))
 {
 }
@@ -115,9 +117,17 @@ bool PowerInterface::hibernate()
 
 bool PowerInterface::canShutdown()
 {
-    QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
-    if (reply1.isValid()) {
-        return reply1.value() == "yes";
+    if (d->login1Interface->isValid()) {
+        QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
+        if (reply1.isValid()) {
+            return reply1.value() == "yes";
+        }
+    }
+    qWarning() << d->login1Interface->lastError();
+
+    QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
+    if (reply.isValid()) {
+        return reply.value();
     }
 
     return false;
@@ -126,15 +136,26 @@ bool PowerInterface::canShutdown()
 bool PowerInterface::shutdown()
 {
     QDBusReply<void> reply;
-    reply = d->login1Interface->call("PowerOff", false);
+    if (d->login1Interface->isValid())
+        reply = d->login1Interface->call("PowerOff", false);
+    else
+        reply = d->consoleKitInterface->call("Stop");
     return reply.isValid();
 }
 
 bool PowerInterface::canRestart()
 {
-    QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
-    if (reply1.isValid()) {
-        return reply1.value() == "yes";
+    if (d->login1Interface->isValid()) {
+        QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
+        if (reply1.isValid()) {
+            return reply1.value() == "yes";
+        }
+    }
+    qWarning() << d->login1Interface->lastError();
+
+    QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
+    if (reply.isValid()) {
+        return reply.value();
     }
 
     return false;
@@ -143,7 +164,10 @@ bool PowerInterface::canRestart()
 bool PowerInterface::restart()
 {
     QDBusReply<void> reply;
-    reply = d->login1Interface->call("Reboot", false);
+    if (d->login1Interface->isValid())
+        reply = d->login1Interface->call("Reboot", false);
+    else
+        reply = d->consoleKitInterface->call("Restart");
     return reply.isValid();
 }