summaryrefslogtreecommitdiff
path: root/liblightdm-qt/power.cpp
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2011-07-19 16:51:41 +1000
committerRobert Ancell <robert.ancell@canonical.com>2011-07-19 16:51:41 +1000
commit2c065d7e158a4a7518baab86d19ce119354f0af6 (patch)
tree23b14a997df8d724046d72e50ddeca055a4ee27b /liblightdm-qt/power.cpp
parentb757a685fb1c2a87ce8cde72e5d7ab71b0ee3412 (diff)
downloadlightdm-2c065d7e158a4a7518baab86d19ce119354f0af6.tar.gz
Split power management code out of QLightDM::Greeter
Diffstat (limited to 'liblightdm-qt/power.cpp')
-rw-r--r--liblightdm-qt/power.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/liblightdm-qt/power.cpp b/liblightdm-qt/power.cpp
new file mode 100644
index 00000000..1feafcbe
--- /dev/null
+++ b/liblightdm-qt/power.cpp
@@ -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");
+}