Back to index

lightdm  1.3.2
power.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 David Edmundson
00003  * Copyright (C) 2010-2011 Robert Ancell
00004  * Author: David Edmundson <kde@davidedmundson.co.uk>
00005  *
00006  * This library is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free
00008  * Software Foundation; either version 3 of the License, or (at your option) any
00009  * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
00010  * license.
00011  */
00012 
00013 
00014 #include "QLightDM/power.h"
00015 
00016 #include <QtCore/QVariant>
00017 #include <QtDBus/QDBusInterface>
00018 #include <QtDBus/QDBusReply>
00019 
00020 #include "config.h"
00021 
00022 using namespace QLightDM;
00023 
00024 class PowerInterface::PowerInterfacePrivate
00025 {
00026 public:
00027     PowerInterfacePrivate();
00028     QScopedPointer<QDBusInterface> powerManagementInterface;
00029     QScopedPointer<QDBusInterface> consoleKitInterface;
00030 };
00031 
00032 PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() :
00033     powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())),
00034     consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()))
00035 {
00036 }
00037 
00038 
00039 PowerInterface::PowerInterface(QObject *parent)
00040     : QObject(parent),
00041       d(new PowerInterfacePrivate)
00042 {
00043 }
00044 
00045 PowerInterface::~PowerInterface()
00046 {
00047     delete d;
00048 }
00049 
00050 bool PowerInterface::canSuspend()
00051 {
00052     QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
00053     if (reply.isValid()) {
00054         return reply.value();
00055     }
00056     else {
00057         return false;
00058     }
00059 }
00060 
00061 void PowerInterface::suspend()
00062 {
00063     d->powerManagementInterface->call("Suspend");
00064 }
00065 
00066 bool PowerInterface::canHibernate()
00067 {
00068     QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
00069     if (reply.isValid()) {
00070         return reply.value();
00071     }
00072     else {
00073         return false;
00074     }
00075 }
00076 
00077 void PowerInterface::hibernate()
00078 {
00079     d->powerManagementInterface->call("Hibernate");
00080 }
00081 
00082 bool PowerInterface::canShutdown()
00083 {
00084     QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
00085     if (reply.isValid()) {
00086         return reply.value();
00087     }
00088     else {
00089         return false;
00090     }
00091 }
00092 
00093 void PowerInterface::shutdown()
00094 {
00095     d->consoleKitInterface->call("Stop");
00096 }
00097 
00098 bool PowerInterface::canRestart()
00099 {
00100     QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
00101     if (reply.isValid()) {
00102         return reply.value();
00103     }
00104     else {
00105         return false;
00106     }
00107 }
00108 
00109 void PowerInterface::restart()
00110 {
00111     d->consoleKitInterface->call("Restart");
00112 }
00113 
00114 #include "power_moc.cpp"