22
22
using namespace QLightDM;
24
static QDBusInterface* powerManagementInterface = NULL;
25
static QDBusInterface* consoleKitInterface = NULL;
27
static bool setupPowerManagementInterface ()
29
if (!powerManagementInterface)
30
powerManagementInterface = new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus());
31
return powerManagementInterface != NULL;
34
static bool setupConsoleKitInterface ()
36
if (!consoleKitInterface)
37
consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
38
return consoleKitInterface != NULL;
41
bool QLightDM::canSuspend()
43
if (!setupPowerManagementInterface())
46
QDBusReply<bool> reply = powerManagementInterface->call("SuspendAllowed");
53
void QLightDM::suspend()
55
if (setupPowerManagementInterface())
56
powerManagementInterface->call("Suspend");
59
bool QLightDM::canHibernate()
61
if (!setupPowerManagementInterface())
64
QDBusReply<bool> reply = powerManagementInterface->call("HibernateAllowed");
71
void QLightDM::hibernate()
73
if (setupConsoleKitInterface())
74
powerManagementInterface->call("Hibernate");
77
bool QLightDM::canShutdown()
79
if (!setupConsoleKitInterface())
82
QDBusReply<bool> reply = consoleKitInterface->call("CanStop");
89
void QLightDM::shutdown()
91
if (setupConsoleKitInterface())
92
consoleKitInterface->call("Stop");
95
bool QLightDM::canRestart()
97
if (!setupConsoleKitInterface())
100
QDBusReply<bool> reply = consoleKitInterface->call("CanRestart");
102
return reply.value();
107
void QLightDM::restart()
109
if (setupConsoleKitInterface())
110
consoleKitInterface->call("Restart");
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"