Add ConsoleKit support to TDE hardware library

pull/16/head
Timothy Pearson 12 years ago
parent 274dd3ccb3
commit 2bf1b0f82a

@ -83,9 +83,10 @@ OPTION( WITH_PCRE "Enable pcre regex support for kjs" ON )
OPTION( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} ) OPTION( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} )
OPTION( WITH_INOTIFY "Enable inotify support for tdeio" ON ) OPTION( WITH_INOTIFY "Enable inotify support for tdeio" ON )
OPTION( WITH_GAMIN "Enable FAM/GAMIN support" ${WITH_ALL_OPTIONS} ) OPTION( WITH_GAMIN "Enable FAM/GAMIN support" ${WITH_ALL_OPTIONS} )
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} )
option( WITH_CONSOLEKIT "Enable ConsoleKit support" ${WITH_ALL_OPTIONS} )
OPTION( WITH_NETWORK_MANAGER_BACKEND "Enable network-manager support" OFF ) OPTION( WITH_NETWORK_MANAGER_BACKEND "Enable network-manager support" OFF )
OPTION( WITH_SUDO_TDESU_BACKEND "Use sudo as backend for tdesu (default is su)" OFF ) OPTION( WITH_SUDO_TDESU_BACKEND "Use sudo as backend for tdesu (default is su)" OFF )
OPTION( WITH_OLD_XDG_STD "Use the pre R14.0.0 XDG standard where both TDE and KDE are recognized in desktop files" OFF ) OPTION( WITH_OLD_XDG_STD "Use the pre R14.0.0 XDG standard where both TDE and KDE are recognized in desktop files" OFF )

@ -423,3 +423,7 @@
<!ENTITY kscore "<application>KScore</application>"> <!ENTITY kscore "<application>KScore</application>">
<!ENTITY ttdemidi "<application>ttdemidi</application>"> <!ENTITY ttdemidi "<application>ttdemidi</application>">
<!ENTITY quanta "<application>Quanta</application>"> <!ENTITY quanta "<application>Quanta</application>">
<!ENTITY tde-release-version "R14.0.0 [DEVELOPMENT]">
<!ENTITY tde-release-date "April 25, 2013">
<!ENTITY tde-copyright-date "2010-2013">

@ -37,6 +37,10 @@ if( WITH_UDISKS2 )
add_definitions( -DWITH_UDISKS2 ) add_definitions( -DWITH_UDISKS2 )
endif( ) endif( )
if( WITH_CONSOLEKIT )
add_definitions( -DWITH_CONSOLEKIT )
endif( )
if( WITH_LIBART ) if( WITH_LIBART )
add_subdirectory( svgicons ) add_subdirectory( svgicons )
set( KDESVGICONS kdesvgicons-static ) set( KDESVGICONS kdesvgicons-static )

@ -1167,7 +1167,7 @@ bool TDECPUDevice::canSetGovernor() {
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol,CPUGovernor", dbusConn); TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol,CPUGovernor", dbusConn);
// can set brightness? // can set CPU governor?
TQValueList<TQT_DBusData> params; TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromInt32(coreNumber()); params << TQT_DBusData::fromInt32(coreNumber());
TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params); TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params);
@ -1201,7 +1201,7 @@ void TDECPUDevice::setGovernor(TQString gv) {
if (dbusConn.isConnected()) { if (dbusConn.isConnected()) {
TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn); TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
// set brightness // set CPU governor
TQValueList<TQT_DBusData> params; TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower()); params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
hardwareControl.sendWithReply("SetCPUGovernor", params); hardwareControl.sendWithReply("SetCPUGovernor", params);
@ -1407,20 +1407,79 @@ bool TDERootSystemDevice::canHibernate() {
} }
bool TDERootSystemDevice::canPowerOff() { bool TDERootSystemDevice::canPowerOff() {
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" );
bool maysd = false;
#ifdef WITH_CONSOLEKIT
if (config->readBoolEntry( "offerShutdown", true )) {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn);
// can power off?
TQValueList<TQT_DBusData> params;
TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanStop", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
maysd = reply[0].toBool();
}
else {
maysd = false;
}
}
else {
maysd = false;
}
}
#else // 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 KDM // This should probably be checked via DCOP and therefore interface with KDM
if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME
maysd = true;
}
#endif // WITH_CONSOLEKIT
return maysd;
}
bool TDERootSystemDevice::canReboot() {
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" );
bool maysd = false; bool mayrb = false;
#ifdef WITH_CONSOLEKIT
if (config->readBoolEntry( "offerShutdown", true )) {
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQT_DBusProxy consoleKitManager("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", dbusConn);
// can reboot?
TQValueList<TQT_DBusData> params;
TQT_DBusMessage reply = consoleKitManager.sendWithReply("CanRestart", params);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
mayrb = reply[0].toBool();
}
else {
mayrb = false;
}
}
else {
mayrb = false;
}
}
#else // WITH_CONSOLEKIT
// FIXME
// Can we power down this system?
// This should probably be checked via DCOP and therefore interface with KDM
if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME if (config->readBoolEntry( "offerShutdown", true )/* && DM().canShutdown()*/) { // FIXME
maysd = true; mayrb = true;
} }
#endif // WITH_CONSOLEKIT
return maysd; return mayrb;
} }
void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) { void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
@ -1505,6 +1564,30 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
} }
} }
else if (ps == TDESystemPowerState::PowerOff) { else if (ps == TDESystemPowerState::PowerOff) {
#ifdef WITH_CONSOLEKIT
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" );
if (config->readBoolEntry( "offerShutdown", true )) {
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"Stop");
dbusConn.sendWithReply(msg);
return true;
}
else {
return false;
}
}
else {
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;
@ -1514,6 +1597,43 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true; return true;
} }
return false; return false;
#endif // WITH_CONSOLEKIT
}
else if (ps == TDESystemPowerState::Reboot) {
#ifdef WITH_CONSOLEKIT
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
config->setGroup("General" );
if (config->readBoolEntry( "offerShutdown", true )) {
TQT_DBusConnection dbusConn;
dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if ( dbusConn.isConnected() ) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.freedesktop.ConsoleKit",
"/org/freedesktop/ConsoleKit/Manager",
"org.freedesktop.ConsoleKit.Manager",
"Restart");
dbusConn.sendWithReply(msg);
return true;
}
else {
return false;
}
}
else {
return false;
}
#else // WITH_CONSOLEKIT
// Power down the system using a DCOP command
// Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387
TQByteArray data;
TQDataStream arg(data, IO_WriteOnly);
arg << (int)0 << (int)1 << (int)2;
if ( kapp->dcopClient()->send("ksmserver", "default", "logout(int,int,int)", data) ) {
return true;
}
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...

@ -1576,7 +1576,8 @@ enum TDESystemPowerState {
Standby, Standby,
Suspend, Suspend,
Hibernate, Hibernate,
PowerOff PowerOff,
Reboot
}; };
}; };
@ -1658,6 +1659,11 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
*/ */
bool canPowerOff(); bool canPowerOff();
/**
* @return TRUE if permissions allow the system to be rebooted, FALSE if not
*/
bool canReboot();
/** /**
* @param hm a TDESystemHibernationMethod::TDESystemHibernationMethod with the desired hibernation method * @param hm a TDESystemHibernationMethod::TDESystemHibernationMethod with the desired hibernation method
*/ */

Loading…
Cancel
Save