|
|
|
@ -89,12 +89,6 @@ void TDERootSystemDevice::internalSetDiskSpaceNeededForHibernation(unsigned long
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canSetHibernationMethod() {
|
|
|
|
|
TQString hibernationnode = "/sys/power/disk";
|
|
|
|
|
int rval = access (hibernationnode.ascii(), W_OK);
|
|
|
|
|
if (rval == 0) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -113,18 +107,16 @@ bool TDERootSystemDevice::canSetHibernationMethod() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canFreeze() {
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
int rval = access (statenode.ascii(), W_OK);
|
|
|
|
|
TQString hibernationnode = "/sys/power/disk";
|
|
|
|
|
int rval = access(hibernationnode.ascii(), W_OK);
|
|
|
|
|
if (rval == 0) {
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Freeze)) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canFreeze() {
|
|
|
|
|
#ifdef WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -143,18 +135,18 @@ bool TDERootSystemDevice::canFreeze() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canStandby() {
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
int rval = access (statenode.ascii(), W_OK);
|
|
|
|
|
int rval = access(statenode.ascii(), W_OK);
|
|
|
|
|
if (rval == 0) {
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Standby)) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Freeze)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canStandby() {
|
|
|
|
|
#ifdef WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -173,36 +165,18 @@ bool TDERootSystemDevice::canStandby() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canSuspend() {
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
int rval = access (statenode.ascii(), W_OK);
|
|
|
|
|
int rval = access(statenode.ascii(), W_OK);
|
|
|
|
|
if (rval == 0) {
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Suspend)) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Standby)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canSuspend() {
|
|
|
|
|
#ifdef WITH_LOGINDPOWER
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -283,30 +257,16 @@ 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 hybrid suspend?
|
|
|
|
|
// can suspend?
|
|
|
|
|
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
|
|
|
|
|
"org.trinitydesktop.hardwarecontrol",
|
|
|
|
|
"/org/trinitydesktop/hardwarecontrol",
|
|
|
|
|
"org.trinitydesktop.hardwarecontrol.Power",
|
|
|
|
|
"CanHybridSuspend");
|
|
|
|
|
"CanSuspend");
|
|
|
|
|
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
|
|
|
|
|
return reply[0].toBool();
|
|
|
|
@ -315,6 +275,18 @@ bool TDERootSystemDevice::canHybridSuspend() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
int rval = access(statenode.ascii(), W_OK);
|
|
|
|
|
if (rval == 0) {
|
|
|
|
|
if (powerStates().contains(TDESystemPowerState::Suspend)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canHybridSuspend() {
|
|
|
|
|
#ifdef WITH_LOGINDPOWER
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -356,30 +328,16 @@ 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 hibernate?
|
|
|
|
|
// can hybrid suspend?
|
|
|
|
|
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
|
|
|
|
|
"org.trinitydesktop.hardwarecontrol",
|
|
|
|
|
"/org/trinitydesktop/hardwarecontrol",
|
|
|
|
|
"org.trinitydesktop.hardwarecontrol.Power",
|
|
|
|
|
"CanHibernate");
|
|
|
|
|
"CanHybridSuspend");
|
|
|
|
|
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
|
|
|
|
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
|
|
|
|
|
return reply[0].toBool();
|
|
|
|
@ -388,6 +346,20 @@ bool TDERootSystemDevice::canHibernate() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canHibernate() {
|
|
|
|
|
#ifdef WITH_LOGINDPOWER
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -468,14 +440,42 @@ bool TDERootSystemDevice::canHibernate() {
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_HAL
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canPowerOff() {
|
|
|
|
|
TDEConfig config("ksmserverrc", true);
|
|
|
|
|
config.setGroup("General" );
|
|
|
|
|
if (!config.readBoolEntry( "offerShutdown", true )) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LOGINDPOWER
|
|
|
|
@ -518,16 +518,17 @@ bool TDERootSystemDevice::canPowerOff() {
|
|
|
|
|
// Can we power down this system?
|
|
|
|
|
// This should probably be checked via DCOP and therefore interface with TDM
|
|
|
|
|
// if ( DM().canShutdown() ) {
|
|
|
|
|
// return TRUE;
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
return TRUE;
|
|
|
|
|
return true;
|
|
|
|
|
//return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDERootSystemDevice::canReboot() {
|
|
|
|
|
TDEConfig config("ksmserverrc", true);
|
|
|
|
|
config.setGroup("General" );
|
|
|
|
|
if (!config.readBoolEntry( "offerShutdown", true )) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LOGINDPOWER
|
|
|
|
@ -570,40 +571,13 @@ bool TDERootSystemDevice::canReboot() {
|
|
|
|
|
// Can we power down this system?
|
|
|
|
|
// This should probably be checked via DCOP and therefore interface with TDM
|
|
|
|
|
// if ( DM().canShutdown() ) {
|
|
|
|
|
// return TRUE;
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
return TRUE;
|
|
|
|
|
return true;
|
|
|
|
|
//return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESystemHibernationMethod hm) {
|
|
|
|
|
TQString hibernationnode = "/sys/power/disk";
|
|
|
|
|
TQFile file( hibernationnode );
|
|
|
|
|
if ( file.open( IO_WriteOnly ) ) {
|
|
|
|
|
TQString hibernationCommand;
|
|
|
|
|
if (hm == TDESystemHibernationMethod::Platform) {
|
|
|
|
|
hibernationCommand = "platform";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Shutdown) {
|
|
|
|
|
hibernationCommand = "shutdown";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Reboot) {
|
|
|
|
|
hibernationCommand = "reboot";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::TestProc) {
|
|
|
|
|
hibernationCommand = "testproc";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Test) {
|
|
|
|
|
hibernationCommand = "test";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Suspend) {
|
|
|
|
|
hibernationCommand = "suspend";
|
|
|
|
|
}
|
|
|
|
|
TQTextStream stream( &file );
|
|
|
|
|
stream << hibernationCommand;
|
|
|
|
|
file.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
|
|
|
|
@ -641,6 +615,33 @@ void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESy
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_TDEHWLIB_DAEMONS
|
|
|
|
|
|
|
|
|
|
TQString hibernationnode = "/sys/power/disk";
|
|
|
|
|
TQFile file( hibernationnode );
|
|
|
|
|
if ( file.open( IO_WriteOnly ) ) {
|
|
|
|
|
TQString hibernationCommand;
|
|
|
|
|
if (hm == TDESystemHibernationMethod::Platform) {
|
|
|
|
|
hibernationCommand = "platform";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Shutdown) {
|
|
|
|
|
hibernationCommand = "shutdown";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Reboot) {
|
|
|
|
|
hibernationCommand = "reboot";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::TestProc) {
|
|
|
|
|
hibernationCommand = "testproc";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Test) {
|
|
|
|
|
hibernationCommand = "test";
|
|
|
|
|
}
|
|
|
|
|
else if (hm == TDESystemHibernationMethod::Suspend) {
|
|
|
|
|
hibernationCommand = "suspend";
|
|
|
|
|
}
|
|
|
|
|
TQTextStream stream( &file );
|
|
|
|
|
stream << hibernationCommand;
|
|
|
|
|
file.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool check_CanSetSuspend(char* state, char* disk, char* mem) {
|
|
|
|
@ -720,145 +721,6 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
|
|
|
|
|
if ((ps == TDESystemPowerState::Freeze) || (ps == TDESystemPowerState::Standby) ||
|
|
|
|
|
(ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate) ||
|
|
|
|
|
(ps == TDESystemPowerState::HybridSuspend)) {
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
TQString disknode = "/sys/power/disk";
|
|
|
|
|
TQString memnode = "/sys/power/mem_sleep";
|
|
|
|
|
TQFile statefile( statenode );
|
|
|
|
|
TQFile diskfile( disknode );
|
|
|
|
|
TQFile memfile( memnode );
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
diskCommand = "s2idle";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Standby) {
|
|
|
|
|
if (check_CanSetSuspend("standby", NULL, NULL)) {
|
|
|
|
|
stateCommand = "standby";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
diskCommand = "shallow";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Suspend) {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
if (check_CanSetSuspend("mem", NULL, "deep")) {
|
|
|
|
|
diskCommand = "deep";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::HybridSuspend) {
|
|
|
|
|
stateCommand = "disk";
|
|
|
|
|
diskCommand = "suspend";
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Hibernate) {
|
|
|
|
|
stateCommand = "disk";
|
|
|
|
|
if (check_CanSetSuspend("disk", "shutdown", NULL)) {
|
|
|
|
|
diskCommand = "shutdown";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
diskCommand = "platform";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memWriteOk = (memCommand == TQString::null);
|
|
|
|
|
if (memCommand != TQString::null && memfile.open( IO_WriteOnly )) {
|
|
|
|
|
memWriteOk = true;
|
|
|
|
|
TQTextStream memstream( &memfile );
|
|
|
|
|
memstream << memCommand;
|
|
|
|
|
memfile.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
{
|
|
|
|
|
// No support for "freeze" in org.freedesktop.login1
|
|
|
|
@ -1013,6 +875,145 @@ 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
|
|
|
|
|
|
|
|
|
|
TQString statenode = "/sys/power/state";
|
|
|
|
|
TQString disknode = "/sys/power/disk";
|
|
|
|
|
TQString memnode = "/sys/power/mem_sleep";
|
|
|
|
|
TQFile statefile( statenode );
|
|
|
|
|
TQFile diskfile( disknode );
|
|
|
|
|
TQFile memfile( memnode );
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
diskCommand = "s2idle";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Standby) {
|
|
|
|
|
if (check_CanSetSuspend("standby", NULL, NULL)) {
|
|
|
|
|
stateCommand = "standby";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
diskCommand = "shallow";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Suspend) {
|
|
|
|
|
stateCommand = "mem";
|
|
|
|
|
if (check_CanSetSuspend("mem", NULL, "deep")) {
|
|
|
|
|
diskCommand = "deep";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::HybridSuspend) {
|
|
|
|
|
stateCommand = "disk";
|
|
|
|
|
diskCommand = "suspend";
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::Hibernate) {
|
|
|
|
|
stateCommand = "disk";
|
|
|
|
|
if (check_CanSetSuspend("disk", "shutdown", NULL)) {
|
|
|
|
|
diskCommand = "shutdown";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
diskCommand = "platform";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memWriteOk = (memCommand == TQString::null);
|
|
|
|
|
if (memCommand != TQString::null && memfile.open( IO_WriteOnly )) {
|
|
|
|
|
memWriteOk = true;
|
|
|
|
|
TQTextStream memstream( &memfile );
|
|
|
|
|
memstream << memCommand;
|
|
|
|
|
memfile.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (ps == TDESystemPowerState::PowerOff) {
|
|
|
|
@ -1038,6 +1039,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_LOGINDPOWER
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CONSOLEKIT
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn;
|
|
|
|
@ -1055,6 +1057,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_CONSOLEKIT
|
|
|
|
|
|
|
|
|
|
// Power down the system using a DCOP command
|
|
|
|
|
/* As found at http://lists.kde.org/?l=kde-linux&m=115770988603387
|
|
|
|
|
Logout parameters explanation:
|
|
|
|
@ -1105,6 +1108,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_LOGINDPOWER
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CONSOLEKIT
|
|
|
|
|
{
|
|
|
|
|
TQT_DBusConnection dbusConn;
|
|
|
|
@ -1122,6 +1126,7 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_CONSOLEKIT
|
|
|
|
|
|
|
|
|
|
// Power down the system using a DCOP command
|
|
|
|
|
// See above PowerOff section for logout() parameters explanation
|
|
|
|
|
TQByteArray data;
|
|
|
|
|