diff options
author | David Edmundson <david@davidedmundson.co.uk> | 2011-11-15 19:51:42 +0000 |
---|---|---|
committer | David Edmundson <david@davidedmundson.co.uk> | 2011-11-15 19:51:42 +0000 |
commit | 3e8c3c0fff6e5c5fd64f67e6b52a7c3956994684 (patch) | |
tree | 0901660f9e02f2558e75b35d834fc35e6c1c1dd4 /liblightdm-qt/power.cpp | |
parent | 99ce0161fa544dd19422ddf3e26c2c143f77ffe0 (diff) | |
download | lightdm-3e8c3c0fff6e5c5fd64f67e6b52a7c3956994684.tar.gz |
Turn power interface into a proper class.
Diffstat (limited to 'liblightdm-qt/power.cpp')
-rw-r--r-- | liblightdm-qt/power.cpp | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/liblightdm-qt/power.cpp b/liblightdm-qt/power.cpp index 2f75fbb3..46bd8312 100644 --- a/liblightdm-qt/power.cpp +++ b/liblightdm-qt/power.cpp @@ -21,91 +21,94 @@ using namespace QLightDM; -static QDBusInterface* powerManagementInterface = NULL; -static QDBusInterface* consoleKitInterface = NULL; - -static bool setupPowerManagementInterface () +class PowerInterface::PowerInterfacePrivate +{ +public: + PowerInterfacePrivate(); + QScopedPointer<QDBusInterface> powerManagementInterface; + QScopedPointer<QDBusInterface> consoleKitInterface; +}; + +PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() : + powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())), + consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus())) { - if (!powerManagementInterface) - powerManagementInterface = new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus()); - return powerManagementInterface != NULL; } -static bool setupConsoleKitInterface () + +PowerInterface::PowerInterface(QObject *parent) + : QObject(parent), + d(new PowerInterfacePrivate) { - if (!consoleKitInterface) - consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()); - return consoleKitInterface != NULL; } -bool QLightDM::canSuspend() +PowerInterface::~PowerInterface() { - if (!setupPowerManagementInterface()) - return false; + delete d; +} - QDBusReply<bool> reply = powerManagementInterface->call("SuspendAllowed"); - if (reply.isValid()) +bool PowerInterface::canSuspend() +{ + QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::suspend() +void PowerInterface::suspend() { - if (setupPowerManagementInterface()) - powerManagementInterface->call("Suspend"); + d->powerManagementInterface->call("Suspend"); } -bool QLightDM::canHibernate() +bool PowerInterface::canHibernate() { - if (!setupPowerManagementInterface()) - return false; - - QDBusReply<bool> reply = powerManagementInterface->call("HibernateAllowed"); - if (reply.isValid()) + QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::hibernate() +void PowerInterface::hibernate() { - if (setupConsoleKitInterface()) - powerManagementInterface->call("Hibernate"); + d->powerManagementInterface->call("Hibernate"); } -bool QLightDM::canShutdown() +bool PowerInterface::canShutdown() { - if (!setupConsoleKitInterface()) - return false; - - QDBusReply<bool> reply = consoleKitInterface->call("CanStop"); - if (reply.isValid()) + QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::shutdown() +void PowerInterface::shutdown() { - if (setupConsoleKitInterface()) - consoleKitInterface->call("Stop"); + d->consoleKitInterface->call("Stop"); } -bool QLightDM::canRestart() +bool PowerInterface::canRestart() { - if (!setupConsoleKitInterface()) - return false; - - QDBusReply<bool> reply = consoleKitInterface->call("CanRestart"); - if (reply.isValid()) + QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::restart() +void PowerInterface::restart() { - if (setupConsoleKitInterface()) - consoleKitInterface->call("Restart"); + d->consoleKitInterface->call("Restart"); } + +#include "power_moc.cpp" |