]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - liblightdm-qt/power.cpp
Merge with trunk
[sojka/lightdm.git] / liblightdm-qt / power.cpp
1 /*
2  * Copyright (C) 2010-2011 David Edmundson
3  * Copyright (C) 2010-2011 Robert Ancell
4  * Author: David Edmundson <kde@davidedmundson.co.uk>
5  *
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.
10  */
11
12
13 #include "QLightDM/power.h"
14
15 #include <QtCore/QVariant>
16 #include <QtDBus/QDBusInterface>
17 #include <QtDBus/QDBusReply>
18
19 #include "config.h"
20
21 using namespace QLightDM;
22
23 class PowerInterface::PowerInterfacePrivate
24 {
25 public:
26     PowerInterfacePrivate();
27     QScopedPointer<QDBusInterface> powerManagementInterface;
28     QScopedPointer<QDBusInterface> consoleKitInterface;
29 };
30
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()))
34 {
35 }
36
37
38 PowerInterface::PowerInterface(QObject *parent)
39     : QObject(parent),
40       d(new PowerInterfacePrivate)
41 {
42 }
43
44 PowerInterface::~PowerInterface()
45 {
46     delete d;
47 }
48
49 bool PowerInterface::canSuspend()
50 {
51     QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed");
52     if (reply.isValid()) {
53         return reply.value();
54     }
55     else {
56         return false;
57     }
58 }
59
60 void PowerInterface::suspend()
61 {
62     d->powerManagementInterface->call("Suspend");
63 }
64
65 bool PowerInterface::canHibernate()
66 {
67     QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed");
68     if (reply.isValid()) {
69         return reply.value();
70     }
71     else {
72         return false;
73     }
74 }
75
76 void PowerInterface::hibernate()
77 {
78     d->powerManagementInterface->call("Hibernate");
79 }
80
81 bool PowerInterface::canShutdown()
82 {
83     QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
84     if (reply.isValid()) {
85         return reply.value();
86     }
87     else {
88         return false;
89     }
90 }
91
92 void PowerInterface::shutdown()
93 {
94     d->consoleKitInterface->call("Stop");
95 }
96
97 bool PowerInterface::canRestart()
98 {
99     QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
100     if (reply.isValid()) {
101         return reply.value();
102     }
103     else {
104         return false;
105     }
106 }
107
108 void PowerInterface::restart()
109 {
110     d->consoleKitInterface->call("Restart");
111 }
112
113 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
114 #include "power_moc5.cpp"
115 #else
116 #include "power_moc4.cpp"
117 #endif