Add systemd/logind power management backend to TDE hardware library

This resolves Bug 1941
pull/16/head
Francois Andriot 10 years ago committed by Slávek Banko
parent bb647dca15
commit 316893d449

@ -88,6 +88,7 @@ OPTION( WITH_GAMIN "Enable FAM/GAMIN support" ${WITH_ALL_OPTIONS} )
option( WITH_TDEHWLIB_DAEMONS "Enable daemons for TDE hwlib" ${WITH_ALL_OPTIONS} ) option( WITH_TDEHWLIB_DAEMONS "Enable daemons for TDE hwlib" ${WITH_ALL_OPTIONS} )
option( WITH_HAL "Enable HAL support" OFF ) option( WITH_HAL "Enable HAL support" OFF )
option( WITH_DEVKITPOWER "Enable DeviceKit Power support" OFF ) option( WITH_DEVKITPOWER "Enable DeviceKit Power support" OFF )
option( WITH_LOGINDPOWER "Enable Logind/Systemd Power support" OFF )
option( WITH_UPOWER "Enable uPower support" ${WITH_ALL_OPTIONS} ) option( WITH_UPOWER "Enable uPower support" ${WITH_ALL_OPTIONS} )
option( WITH_UDISKS "Enable uDisks support" ${WITH_ALL_OPTIONS} ) option( WITH_UDISKS "Enable uDisks support" ${WITH_ALL_OPTIONS} )
option( WITH_UDISKS2 "Enable uDisks2 support" ${WITH_ALL_OPTIONS} ) option( WITH_UDISKS2 "Enable uDisks2 support" ${WITH_ALL_OPTIONS} )

@ -36,6 +36,10 @@ if( WITH_DEVKITPOWER )
add_definitions( -DWITH_DEVKITPOWER ) add_definitions( -DWITH_DEVKITPOWER )
endif( ) endif( )
if( WITH_LOGINDPOWER )
add_definitions( -DWITH_LOGINDPOWER )
endif( )
if( WITH_UPOWER ) if( WITH_UPOWER )
add_definitions( -DWITH_UPOWER ) add_definitions( -DWITH_UPOWER )
endif( ) endif( )

@ -221,6 +221,24 @@ bool TDERootSystemDevice::canSuspend() {
} }
} }
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
// can suspend?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"CanSuspend");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return (reply[0].toString() == "yes");
}
}
}
#endif // WITH_LOGINDPOWER
#ifdef WITH_UPOWER #ifdef WITH_UPOWER
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@ -322,6 +340,24 @@ bool TDERootSystemDevice::canHibernate() {
} }
} }
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
// can hibernate?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"CanHibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return (reply[0].toString() == "yes");
}
}
}
#endif // WITH_LOGINDPOWER
#ifdef WITH_UPOWER #ifdef WITH_UPOWER
{ {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@ -410,41 +446,53 @@ bool TDERootSystemDevice::canPowerOff() {
config->reparseConfiguration(); // config may have changed in the KControl module config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" ); config->setGroup("General" );
bool maysd = false; if (!config->readBoolEntry( "offerShutdown", true )) {
#ifdef WITH_CONSOLEKIT return FALSE;
if (config->readBoolEntry( "offerShutdown", true )) { }
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn); // can power off?
if (consoleKitManager.canSend()) { TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
// can power off? "org.freedesktop.login1",
TQValueList<TQT_DBusData> params; "/org/freedesktop/login1",
TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanStop", params); "org.freedesktop.login1.Manager",
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { "CanPowerOff");
maysd = reply[0].toBool(); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
} if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
else { return (reply[0].toString() == "yes");
maysd = false;
}
}
else {
maysd = false;
} }
} }
else { }
maysd = false; #endif // WITH_LOGINDPOWER
#ifdef WITH_CONSOLEKIT
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
// can power off?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"CanStop");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
}
} }
} }
#else // WITH_CONSOLEKIT #endif // WITH_CONSOLEKIT
// FIXME // FIXME
// Can we power down this system? // Can we power down this system?
// This should probably be checked via DCOP and therefore interface with TDM // This should probably be checked via DCOP and therefore interface with TDM
if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME // if ( DM().canShutdown() ) {
maysd = true; // return TRUE;
} // }
#endif // WITH_CONSOLEKIT return TRUE;
return maysd;
} }
bool TDERootSystemDevice::canReboot() { bool TDERootSystemDevice::canReboot() {
@ -452,41 +500,53 @@ bool TDERootSystemDevice::canReboot() {
config->reparseConfiguration(); // config may have changed in the KControl module config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" ); config->setGroup("General" );
bool mayrb = false; if (!config->readBoolEntry( "offerShutdown", true )) {
#ifdef WITH_CONSOLEKIT return FALSE;
if (config->readBoolEntry( "offerShutdown", true )) { }
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn); // can reboot?
if (consoleKitManager.canSend()) { TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
// can reboot? "org.freedesktop.login1",
TQValueList<TQT_DBusData> params; "/org/freedesktop/login1",
TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanRestart", params); "org.freedesktop.login1.Manager",
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { "CanReboot");
mayrb = reply[0].toBool(); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
} if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
else { return (reply[0].toString() == "yes");
mayrb = false;
}
}
else {
mayrb = false;
} }
} }
else { }
mayrb = false; #endif // WITH_LOGINDPOWER
#ifdef WITH_CONSOLEKIT
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
// can reboot?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"CanRestart");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
}
} }
} }
#else // WITH_CONSOLEKIT #endif // WITH_CONSOLEKIT
// FIXME // FIXME
// Can we power down this system? // Can we power down this system?
// This should probably be checked via DCOP and therefore interface with TDM // This should probably be checked via DCOP and therefore interface with TDM
if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME // if ( DM().canShutdown() ) {
mayrb = true; // return TRUE;
} // }
#endif // WITH_CONSOLEKIT return TRUE;
return mayrb;
} }
void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) { void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
@ -575,6 +635,37 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true; return true;
} }
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
if (ps == TDESystemPowerState::Suspend) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"Suspend");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage) {
return true;
}
}
else if (ps == TDESystemPowerState::Hibernate) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"Hibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage) {
return true;
}
}
}
}
#endif // WITH_LOGINDPOWER
#ifdef WITH_UPOWER #ifdef WITH_UPOWER
{ {
TQT_DBusConnection dbusConn; TQT_DBusConnection dbusConn;
@ -726,11 +817,31 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return false; return false;
} }
else if (ps == TDESystemPowerState::PowerOff) { else if (ps == TDESystemPowerState::PowerOff) {
#ifdef WITH_CONSOLEKIT
TDEConfig *config = TDEGlobal::config(); TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" ); config->setGroup("General" );
if (config->readBoolEntry( "offerShutdown", true )) { if (!config->readBoolEntry( "offerShutdown", true )) {
return false;
}
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"PowerOff");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage) {
return true;
}
}
}
#endif // WITH_LOGINDPOWER
#ifdef WITH_CONSOLEKIT
{
TQT_DBusConnection dbusConn; TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) { if ( dbusConn.isConnected() ) {
@ -739,17 +850,13 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
"/org/freedesktop/ConsoleKit/Manager", "/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager", "org.freedesktop.ConsoleKit.Manager",
"Stop"); "Stop");
dbusConn.sendWithReply(msg); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
return true; if (reply.type() == TQT_DBusMessage::ReplyMessage) {
} return true;
else { }
return false;
} }
} }
else { #endif // WITH_CONSOLEKIT
return false;
}
#else // WITH_CONSOLEKIT
// Power down the system using a DCOP command // Power down the system using a DCOP command
// Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387 // Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387
TQByteArray data; TQByteArray data;
@ -759,14 +866,33 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true; return true;
} }
return false; return false;
#endif // WITH_CONSOLEKIT
} }
else if (ps == TDESystemPowerState::Reboot) { else if (ps == TDESystemPowerState::Reboot) {
#ifdef WITH_CONSOLEKIT
TDEConfig *config = TDEGlobal::config(); TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" ); config->setGroup("General" );
if (config->readBoolEntry( "offerShutdown", true )) { if (!config->readBoolEntry( "offerShutdown", true )) {
return false;
}
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"Reboot");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage) {
return true;
}
}
}
#endif // WITH_LOGINDPOWER
#ifdef WITH_CONSOLEKIT
{
TQT_DBusConnection dbusConn; TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) { if ( dbusConn.isConnected() ) {
@ -775,17 +901,13 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
"/org/freedesktop/ConsoleKit/Manager", "/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager", "org.freedesktop.ConsoleKit.Manager",
"Restart"); "Restart");
dbusConn.sendWithReply(msg); TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
return true; if (reply.type() == TQT_DBusMessage::ReplyMessage) {
} return true;
else { }
return false;
} }
} }
else { #endif // WITH_CONSOLEKIT
return false;
}
#else // WITH_CONSOLEKIT
// Power down the system using a DCOP command // Power down the system using a DCOP command
// Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387 // Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387
TQByteArray data; TQByteArray data;
@ -795,7 +917,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true; return true;
} }
return false; return false;
#endif // WITH_CONSOLEKIT
} }
else if (ps == TDESystemPowerState::Active) { else if (ps == TDESystemPowerState::Active) {
// Ummm...we're already active... // Ummm...we're already active...

Loading…
Cancel
Save