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()
{
- QDBusReply<QString> reply1 = d->login1Interface->call("CanPowerOff");
- if (reply1.isValid()) {
- return reply1.value() == "yes";
+ 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();
}
return false;
bool PowerInterface::shutdown()
{
QDBusReply<void> reply;
- reply = d->login1Interface->call("PowerOff", false);
+ if (d->login1Interface->isValid())
+ reply = d->login1Interface->call("PowerOff", false);
+ else
+ reply = d->consoleKitInterface->call("Stop");
return reply.isValid();
}
bool PowerInterface::canRestart()
{
- QDBusReply<QString> reply1 = d->login1Interface->call("CanReboot");
- if (reply1.isValid()) {
- return reply1.value() == "yes";
+ 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();
}
return false;
bool PowerInterface::restart()
{
QDBusReply<void> reply;
- reply = d->login1Interface->call("Reboot", false);
+ if (d->login1Interface->isValid())
+ reply = d->login1Interface->call("Reboot", false);
+ else
+ reply = d->consoleKitInterface->call("Restart");
return reply.isValid();
}