2 * Copyright (C) 2010-2011 David Edmundson
3 * Copyright (C) 2010-2011 Robert Ancell
4 * Author: David Edmundson <kde@davidedmundson.co.uk>
6 * This library is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation; either version 2 or version 3 of the License.
9 * See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
13 #include "QLightDM/power.h"
15 #include <QtCore/QVariant>
16 #include <QtDBus/QDBusInterface>
17 #include <QtDBus/QDBusReply>
21 using namespace QLightDM;
23 class PowerInterface::PowerInterfacePrivate
26 PowerInterfacePrivate();
27 QScopedPointer<QDBusInterface> powerManagementInterface;
28 QScopedPointer<QDBusInterface> consoleKitInterface;
31 PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() :
32 powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())),
33 consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()))
38 PowerInterface::PowerInterface(QObject *parent)
40 d(new PowerInterfacePrivate)
44 PowerInterface::~PowerInterface()
49 bool PowerInterface::canSuspend()
51 QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
52 if (reply.isValid()) {
60 void PowerInterface::suspend()
62 d->powerManagementInterface->call("Suspend");
65 bool PowerInterface::canHibernate()
67 QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
68 if (reply.isValid()) {
76 void PowerInterface::hibernate()
78 d->powerManagementInterface->call("Hibernate");
81 bool PowerInterface::canShutdown()
83 QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
84 if (reply.isValid()) {
92 void PowerInterface::shutdown()
94 d->consoleKitInterface->call("Stop");
97 bool PowerInterface::canRestart()
99 QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
100 if (reply.isValid()) {
101 return reply.value();
108 void PowerInterface::restart()
110 d->consoleKitInterface->call("Restart");
113 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
114 #include "power_moc5.cpp"
116 #include "power_moc4.cpp"