public:
PowerInterfacePrivate();
QScopedPointer<QDBusInterface> powerManagementInterface;
- QScopedPointer<QDBusInterface> consoleKitInterface;
QScopedPointer<QDBusInterface> login1Interface;
};
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())),
login1Interface(new QDBusInterface("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()))
{
}
bool PowerInterface::canShutdown()
{
- if (d->login1Interface->isValid()) {
- QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
- if (reply1.isValid()) {
- return reply1.value() == "yes";
- }
- }
- qWarning() << d->login1Interface->lastError();
-
- QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop");
- if (reply.isValid()) {
- return reply.value();
+ QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
+ if (reply1.isValid()) {
+ return reply1.value() == "yes";
}
return false;
bool PowerInterface::shutdown()
{
QDBusReply<void> reply;
- if (d->login1Interface->isValid())
- reply = d->login1Interface->call("PowerOff", false);
- else
- reply = d->consoleKitInterface->call("Stop");
+ reply = d->login1Interface->call("PowerOff", false);
return reply.isValid();
}
bool PowerInterface::canRestart()
{
- if (d->login1Interface->isValid()) {
- QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
- if (reply1.isValid()) {
- return reply1.value() == "yes";
- }
- }
- qWarning() << d->login1Interface->lastError();
-
- QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart");
- if (reply.isValid()) {
- return reply.value();
+ QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
+ if (reply1.isValid()) {
+ return reply1.value() == "yes";
}
return false;
bool PowerInterface::restart()
{
QDBusReply<void> reply;
- if (d->login1Interface->isValid())
- reply = d->login1Interface->call("Reboot", false);
- else
- reply = d->consoleKitInterface->call("Restart");
+ reply = d->login1Interface->call("Reboot", false);
return reply.isValid();
}