summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-25 16:07:56 +0000
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-25 16:07:56 +0000
commit2bf1b0f82a0d1142fda9f57e81e7103679fe9251 (patch)
treea3ef6589d997cb16203cb9257c97ceb6851cc01d /tdecore
parent274dd3ccb3dd38866e87c83bd5e6f1085ba861d9 (diff)
downloadtdelibs-2bf1b0f82a0d1142fda9f57e81e7103679fe9251.tar.gz
tdelibs-2bf1b0f82a0d1142fda9f57e81e7103679fe9251.zip
Add ConsoleKit support to TDE hardware library
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/CMakeLists.txt4
-rw-r--r--tdecore/tdehardwaredevices.cpp130
-rw-r--r--tdecore/tdehardwaredevices.h8
3 files changed, 136 insertions, 6 deletions
diff --git a/tdecore/CMakeLists.txt b/tdecore/CMakeLists.txt
index 179a8aa7a..bff0e51d0 100644
--- a/tdecore/CMakeLists.txt
+++ b/tdecore/CMakeLists.txt
@@ -37,6 +37,10 @@ if( WITH_UDISKS2 )
add_definitions( -DWITH_UDISKS2 )
endif( )
+if( WITH_CONSOLEKIT )
+ add_definitions( -DWITH_CONSOLEKIT )
+endif( )
+
if( WITH_LIBART )
add_subdirectory( svgicons )
set( KDESVGICONS kdesvgicons-static )
diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp
index 473d17312..f4fde484f 100644
--- a/tdecore/tdehardwaredevices.cpp
+++ b/tdecore/tdehardwaredevices.cpp
@@ -1167,7 +1167,7 @@ bool TDECPUDevice::canSetGovernor() {
if (dbusConn.isConnected()) {
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;
params << TQT_DBusData::fromInt32(coreNumber());
TQT_DBusMessage reply = hardwareControl.sendWithReply("CanSetCPUGovernor", params);
@@ -1201,7 +1201,7 @@ void TDECPUDevice::setGovernor(TQString gv) {
if (dbusConn.isConnected()) {
TQT_DBusProxy hardwareControl("org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.CPUGovernor", dbusConn);
- // set brightness
+ // set CPU governor
TQValueList<TQT_DBusData> params;
params << TQT_DBusData::fromInt32(coreNumber()) << TQT_DBusData::fromString(gv.lower());
hardwareControl.sendWithReply("SetCPUGovernor", params);
@@ -1407,20 +1407,79 @@ bool TDERootSystemDevice::canHibernate() {
}
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
// 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
+ maysd = true;
+ }
+#endif // WITH_CONSOLEKIT
+ return maysd;
+}
+
+bool TDERootSystemDevice::canReboot() {
TDEConfig *config = TDEGlobal::config();
config->reparseConfiguration(); // config may have changed in the KControl module
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
- maysd = true;
+ mayrb = true;
}
+#endif // WITH_CONSOLEKIT
- return maysd;
+ return mayrb;
}
void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
@@ -1505,6 +1564,30 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
}
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
// Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387
TQByteArray data;
@@ -1514,6 +1597,43 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true;
}
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) {
// Ummm...we're already active...
diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h
index 4c9b74940..1fe962207 100644
--- a/tdecore/tdehardwaredevices.h
+++ b/tdecore/tdehardwaredevices.h
@@ -1576,7 +1576,8 @@ enum TDESystemPowerState {
Standby,
Suspend,
Hibernate,
- PowerOff
+ PowerOff,
+ Reboot
};
};
@@ -1659,6 +1660,11 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
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
*/
void setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm);