summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehardwaredevices.cpp
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/tdehardwaredevices.cpp
parent274dd3ccb3dd38866e87c83bd5e6f1085ba861d9 (diff)
downloadtdelibs-2bf1b0f82a0d1142fda9f57e81e7103679fe9251.tar.gz
tdelibs-2bf1b0f82a0d1142fda9f57e81e7103679fe9251.zip
Add ConsoleKit support to TDE hardware library
Diffstat (limited to 'tdecore/tdehardwaredevices.cpp')
-rw-r--r--tdecore/tdehardwaredevices.cpp130
1 files changed, 125 insertions, 5 deletions
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...