]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Split power management code out of QLightDM::Greeter
authorRobert Ancell <robert.ancell@canonical.com>
Tue, 19 Jul 2011 06:51:41 +0000 (16:51 +1000)
committerRobert Ancell <robert.ancell@canonical.com>
Tue, 19 Jul 2011 06:51:41 +0000 (16:51 +1000)
liblightdm-qt/Makefile.am
liblightdm-qt/QLightDM/Power [new file with mode: 0644]
liblightdm-qt/QLightDM/power.h [new file with mode: 0644]
liblightdm-qt/greeter.cpp
liblightdm-qt/power.cpp [new file with mode: 0644]

index 3a1601d6cd140f58c617360fc8214f87454146db..c7c7ff7b976bb5935db077b24f5b1940121db3c8 100644 (file)
@@ -25,6 +25,7 @@ liblightdm_qt_1_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \
 liblightdm_qt_1_la_SOURCES = \
        greeter.cpp \
        language.cpp \
+       power.cpp \
        sessionsmodel.cpp \
        user.cpp \
        usersmodel.cpp \
diff --git a/liblightdm-qt/QLightDM/Power b/liblightdm-qt/QLightDM/Power
new file mode 100644 (file)
index 0000000..04d0071
--- /dev/null
@@ -0,0 +1 @@
+#include "power.h"
diff --git a/liblightdm-qt/QLightDM/power.h b/liblightdm-qt/QLightDM/power.h
new file mode 100644 (file)
index 0000000..e3a0a12
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Copyright (C) 2010-2011 Robert Ancell
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_POWER_H
+#define QLIGHTDM_POWER_H
+
+namespace QLightDM
+{
+    bool canSuspend();
+    bool canHibernate();
+    bool canShutdown();
+    bool canRestart();
+    void suspend();
+    void hibernate();
+    void shutdown();
+    void restart();
+};
+
+#endif // QLIGHTDM_POWER_H
index 89ea1808e7fb5e0be347a0593ea37a6a8d7647cd..5b3a264a80641878dd5c6875f734e1fdbac32162 100644 (file)
@@ -61,10 +61,6 @@ class GreeterPrivate
 public:
     SessionsModel *sessionsModel;
 
-    QDBusInterface* lightdmInterface;
-    QDBusInterface* powerManagementInterface;
-    QDBusInterface* consoleKitInterface;
-
     QHash<QString, QString> hints;
 
     int toServerFd;
@@ -178,10 +174,6 @@ void Greeter::connectToServer()
         busType = QDBusConnection::sessionBus();
     }
 
-    d->lightdmInterface = new QDBusInterface("org.freedesktop.DisplayManager", "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", busType);
-    d->powerManagementInterface = new QDBusInterface("org.freedesktop.PowerManagement","/org/freedesktop/PowerManagement", "org.freedesktop.PowerManagement");
-    d->consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit");
-
     char* fd = getenv("LIGHTDM_TO_SERVER_FD");
     if(!fd) {
        qDebug() << "No LIGHTDM_TO_SERVER_FD environment variable";
@@ -458,59 +450,3 @@ int Greeter::autologinTimeoutHint() const
 {
     return d->hints.value ("autologin-timeout", "0").toInt ();
 }
-
-bool Greeter::canSuspend() const
-{
-    QDBusReply<bool> reply = d->powerManagementInterface->call("CanSuspend");
-    if (reply.isValid())
-        return reply.value();
-    else
-        return false;
-}
-
-void Greeter::suspend()
-{
-    d->powerManagementInterface->call("Suspend");
-}
-
-bool Greeter::canHibernate() const
-{
-    QDBusReply<bool> reply = d->powerManagementInterface->call("CanHibernate");
-    if (reply.isValid())
-        return reply.value();
-    else
-        return false;
-}
-
-void Greeter::hibernate()
-{
-    d->powerManagementInterface->call("Hibernate");
-}
-
-bool Greeter::canShutdown() const
-{
-    QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
-    if (reply.isValid())
-        return reply.value();
-    else
-        return false;
-}
-
-void Greeter::shutdown()
-{
-    d->consoleKitInterface->call("stop");
-}
-
-bool Greeter::canRestart() const
-{
-    QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
-    if (reply.isValid())
-        return reply.value();
-    else
-        return false;
-}
-
-void Greeter::restart()
-{
-    d->consoleKitInterface->call("Restart");
-}
diff --git a/liblightdm-qt/power.cpp b/liblightdm-qt/power.cpp
new file mode 100644 (file)
index 0000000..1feafcb
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson
+ * Copyright (C) 2010-2011 Robert Ancell
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#include "config.h"
+
+#include "QLightDM/Power"
+
+#include <QtCore/QVariant>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusReply>
+
+using namespace QLightDM;
+
+static QDBusInterface* powerManagementInterface = NULL;
+static QDBusInterface* consoleKitInterface = NULL;
+
+static bool setupPowerManagementInterface ()
+{
+    if (!powerManagementInterface)
+        powerManagementInterface = new QDBusInterface("org.freedesktop.PowerManagement","/org/freedesktop/PowerManagement", "org.freedesktop.PowerManagement");
+    return powerManagementInterface != NULL;
+}
+
+static bool setupConsoleKitInterface ()
+{
+    if (!consoleKitInterface)
+        consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit");
+    return consoleKitInterface != NULL;
+}
+
+bool canSuspend()
+{
+    if (!setupPowerManagementInterface())
+        return false;
+
+    QDBusReply<bool> reply = powerManagementInterface->call("CanSuspend");
+    if (reply.isValid())
+        return reply.value();
+    else
+        return false;
+}
+
+void suspend()
+{
+    if (setupPowerManagementInterface())
+        powerManagementInterface->call("Suspend");
+}
+
+bool canHibernate()
+{
+    if (!setupPowerManagementInterface())
+        return false;
+
+    QDBusReply<bool> reply = powerManagementInterface->call("CanHibernate");
+    if (reply.isValid())
+        return reply.value();
+    else
+        return false;
+}
+
+void hibernate()
+{
+    if (setupConsoleKitInterface())
+        powerManagementInterface->call("Hibernate");
+}
+
+bool canShutdown()
+{
+    if (!setupConsoleKitInterface())
+        return false;
+
+    QDBusReply<bool> reply = consoleKitInterface->call("CanStop");
+    if (reply.isValid())
+        return reply.value();
+    else
+        return false;
+}
+
+void shutdown()
+{
+    if (setupConsoleKitInterface())
+        consoleKitInterface->call("stop");
+}
+
+bool canRestart()
+{
+    if (!setupConsoleKitInterface())
+        return false;
+
+    QDBusReply<bool> reply = consoleKitInterface->call("CanRestart");
+    if (reply.isValid())
+        return reply.value();
+    else
+        return false;
+}
+
+void restart()
+{
+    if (setupConsoleKitInterface())
+        consoleKitInterface->call("Restart");
+}