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 3 of the License, or (at your option) any
9 * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
14 #include "QLightDM/power.h"
16 #include <QtCore/QVariant>
17 #include <QtDBus/QDBusInterface>
18 #include <QtDBus/QDBusReply>
22 using namespace QLightDM;
24 class PowerInterface::PowerInterfacePrivate
27 PowerInterfacePrivate();
28 QScopedPointer<QDBusInterface> powerManagementInterface;
29 QScopedPointer<QDBusInterface> consoleKitInterface;
32 PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() :
33 powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())),
34 consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()))
39 PowerInterface::PowerInterface(QObject *parent)
41 d(new PowerInterfacePrivate)
45 PowerInterface::~PowerInterface()
50 bool PowerInterface::canSuspend()
52 QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
53 if (reply.isValid()) {
61 void PowerInterface::suspend()
63 d->powerManagementInterface->call("Suspend");
66 bool PowerInterface::canHibernate()
68 QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
69 if (reply.isValid()) {
77 void PowerInterface::hibernate()
79 d->powerManagementInterface->call("Hibernate");
82 bool PowerInterface::canShutdown()
84 QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
85 if (reply.isValid()) {
93 void PowerInterface::shutdown()
95 d->consoleKitInterface->call("Stop");
98 bool PowerInterface::canRestart()
100 QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
101 if (reply.isValid()) {
102 return reply.value();
109 void PowerInterface::restart()
111 d->consoleKitInterface->call("Restart");
114 #include "power_moc.cpp"