summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2018-11-11 21:41:57 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-02-06 23:37:11 +0900
commit0c6b1db799036bb02d2217368a0d78125ba3db87 (patch)
tree089ddf6e5069bf797924ad76e2a900f3ec292346
parentcebadfa114d50a465f9d04d59da5015fed673b26 (diff)
downloadtdelibs-0c6b1db799036bb02d2217368a0d78125ba3db87.tar.gz
tdelibs-0c6b1db799036bb02d2217368a0d78125ba3db87.zip
Improved detection of available options for
freeze/standby/suspend/hybrid suspend/hibernate when udev is not available. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdecore/tdehw/tderootsystemdevice.cpp270
1 files changed, 133 insertions, 137 deletions
diff --git a/tdecore/tdehw/tderootsystemdevice.cpp b/tdecore/tdehw/tderootsystemdevice.cpp
index e53342ae..c11f346f 100644
--- a/tdecore/tdehw/tderootsystemdevice.cpp
+++ b/tdecore/tdehw/tderootsystemdevice.cpp
@@ -123,9 +123,6 @@ bool TDERootSystemDevice::canFreeze() {
if (powerStates().contains(TDESystemPowerState::Freeze)) {
return TRUE;
}
- else {
- return FALSE;
- }
}
#ifdef WITH_TDEHWLIB_DAEMONS
@@ -156,9 +153,6 @@ bool TDERootSystemDevice::canStandby() {
if (powerStates().contains(TDESystemPowerState::Standby)) {
return TRUE;
}
- else {
- return FALSE;
- }
}
#ifdef WITH_TDEHWLIB_DAEMONS
@@ -189,10 +183,25 @@ bool TDERootSystemDevice::canSuspend() {
if (powerStates().contains(TDESystemPowerState::Suspend)) {
return TRUE;
}
- else {
- return FALSE;
+ }
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ // can suspend?
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "CanSuspend");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ return reply[0].toBool();
+ }
}
}
+#endif // WITH_TDEHWLIB_DAEMONS
#ifdef WITH_LOGINDPOWER
{
@@ -274,16 +283,30 @@ bool TDERootSystemDevice::canSuspend() {
}
#endif // WITH_HAL
+ return FALSE;
+}
+
+bool TDERootSystemDevice::canHybridSuspend() {
+ TQString statenode = "/sys/power/state";
+ TQString disknode = "/sys/power/disk";
+ int state_rval = access (statenode.ascii(), W_OK);
+ int disk_rval = access (disknode.ascii(), W_OK);
+ if (state_rval == 0 && disk_rval == 0) {
+ if (powerStates().contains(TDESystemPowerState::HybridSuspend)) {
+ return TRUE;
+ }
+ }
+
#ifdef WITH_TDEHWLIB_DAEMONS
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can suspend?
+ // can hybrid suspend?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanSuspend");
+ "CanHybridSuspend");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -292,23 +315,6 @@ bool TDERootSystemDevice::canSuspend() {
}
#endif // WITH_TDEHWLIB_DAEMONS
- return FALSE;
-}
-
-bool TDERootSystemDevice::canHybridSuspend() {
- TQString statenode = "/sys/power/state";
- TQString disknode = "/sys/power/disk";
- int state_rval = access (statenode.ascii(), W_OK);
- int disk_rval = access (disknode.ascii(), W_OK);
- if (state_rval == 0 && disk_rval == 0) {
- if (powerStates().contains(TDESystemPowerState::HybridSuspend)) {
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
-
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@@ -350,16 +356,30 @@ bool TDERootSystemDevice::canHybridSuspend() {
}
#endif // WITH_HAL
+ return FALSE;
+}
+
+bool TDERootSystemDevice::canHibernate() {
+ TQString statenode = "/sys/power/state";
+ TQString disknode = "/sys/power/disk";
+ int state_rval = access (statenode.ascii(), W_OK);
+ int disk_rval = access (disknode.ascii(), W_OK);
+ if (state_rval == 0 && disk_rval == 0) {
+ if (powerStates().contains(TDESystemPowerState::Hibernate)) {
+ return TRUE;
+ }
+ }
+
#ifdef WITH_TDEHWLIB_DAEMONS
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
- // can hybrid suspend?
+ // can hibernate?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
- "CanHybridSuspend");
+ "CanHibernate");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
@@ -368,23 +388,6 @@ bool TDERootSystemDevice::canHybridSuspend() {
}
#endif // WITH_TDEHWLIB_DAEMONS
- return FALSE;
-}
-
-bool TDERootSystemDevice::canHibernate() {
- TQString statenode = "/sys/power/state";
- TQString disknode = "/sys/power/disk";
- int state_rval = access (statenode.ascii(), W_OK);
- int disk_rval = access (disknode.ascii(), W_OK);
- if (state_rval == 0 && disk_rval == 0) {
- if (powerStates().contains(TDESystemPowerState::Hibernate)) {
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
-
#ifdef WITH_LOGINDPOWER
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@@ -465,24 +468,6 @@ bool TDERootSystemDevice::canHibernate() {
}
#endif // WITH_HAL
-#ifdef WITH_TDEHWLIB_DAEMONS
- {
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- // can hibernate?
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "CanHibernate");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
- return reply[0].toBool();
- }
- }
- }
-#endif // WITH_TDEHWLIB_DAEMONS
-
return FALSE;
}
@@ -744,6 +729,9 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
TQString stateCommand = TQString::null;
TQString diskCommand = TQString::null;
TQString memCommand = TQString::null;
+ bool stateWriteOk = false;
+ bool diskWriteOk = false;
+ bool memWriteOk = false;
if (ps == TDESystemPowerState::Freeze) {
if (check_CanSetSuspend("freeze", NULL, NULL)) {
stateCommand = "freeze";
@@ -782,22 +770,94 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
}
+ memWriteOk = (memCommand == TQString::null);
if (memCommand != TQString::null && memfile.open( IO_WriteOnly )) {
+ memWriteOk = true;
TQTextStream memstream( &memfile );
memstream << memCommand;
memfile.close();
}
- if (diskCommand != TQString::null && diskfile.open( IO_WriteOnly )) {
- TQTextStream diskstream( &diskfile );
- diskstream << diskCommand;
- diskfile.close();
+ if (memWriteOk) {
+ diskWriteOk = (diskCommand == TQString::null);
+ if (diskCommand != TQString::null && diskfile.open( IO_WriteOnly )) {
+ diskWriteOk = true;
+ TQTextStream diskstream( &diskfile );
+ diskstream << diskCommand;
+ diskfile.close();
+ }
+ if (diskWriteOk) {
+ if (stateCommand != TQString::null && statefile.open( IO_WriteOnly )) {
+ TQTextStream statestream( &statefile );
+ statestream << stateCommand;
+ statefile.close();
+ return true;
+ }
+ }
}
- if (stateCommand != TQString::null && statefile.open( IO_WriteOnly )) {
- TQTextStream statestream( &statefile );
- statestream << stateCommand;
- statefile.close();
- return true;
+
+#ifdef WITH_TDEHWLIB_DAEMONS
+ {
+ TQT_DBusConnection dbusConn;
+ dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if ( dbusConn.isConnected() ) {
+ if (ps == TDESystemPowerState::Freeze) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Freeze");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ else if (ps == TDESystemPowerState::Standby) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Standby");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ else if (ps == TDESystemPowerState::Suspend) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Suspend");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ else if (ps == TDESystemPowerState::HybridSuspend) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "HybridSuspend");
+ 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.trinitydesktop.hardwarecontrol",
+ "/org/trinitydesktop/hardwarecontrol",
+ "org.trinitydesktop.hardwarecontrol.Power",
+ "Hibernate");
+ TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
+ if (reply.type() == TQT_DBusMessage::ReplyMessage) {
+ return true;
+ }
+ }
+ }
}
+#endif // WITH_TDEHWLIB_DAEMONS
#ifdef WITH_LOGINDPOWER
{
@@ -953,70 +1013,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
}
#endif // WITH_HAL
-#ifdef WITH_TDEHWLIB_DAEMONS
- {
- TQT_DBusConnection dbusConn;
- dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if ( dbusConn.isConnected() ) {
- if (ps == TDESystemPowerState::Freeze) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "Freeze");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
- }
- }
- else if (ps == TDESystemPowerState::Standby) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "Standby");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
- }
- }
- else if (ps == TDESystemPowerState::Suspend) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "Suspend");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
- }
- }
- else if (ps == TDESystemPowerState::HybridSuspend) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "HybridSuspend");
- 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.trinitydesktop.hardwarecontrol",
- "/org/trinitydesktop/hardwarecontrol",
- "org.trinitydesktop.hardwarecontrol.Power",
- "Hibernate");
- TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
- if (reply.type() == TQT_DBusMessage::ReplyMessage) {
- return true;
- }
- }
- }
- }
-#endif // WITH_TDEHWLIB_DAEMONS
-
return false;
}
else if (ps == TDESystemPowerState::PowerOff) {