diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2013-09-22 14:56:47 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2013-09-22 14:56:47 +0200 |
commit | 160e6f21b8d578aeaba5105082cbb61f46811ef1 (patch) | |
tree | 62a3660023eefc4efc498c6025bde1759d6b2e1c /src/tdepowersave.cpp | |
parent | e113ed917ca8d86e607c7fc70accd681cfefb0a4 (diff) | |
download | tdepowersave-160e6f21b8d578aeaba5105082cbb61f46811ef1.tar.gz tdepowersave-160e6f21b8d578aeaba5105082cbb61f46811ef1.zip |
Add support for freeze suspend state
Diffstat (limited to 'src/tdepowersave.cpp')
-rw-r--r-- | src/tdepowersave.cpp | 137 |
1 files changed, 127 insertions, 10 deletions
diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp index b54b990..73b569d 100644 --- a/src/tdepowersave.cpp +++ b/src/tdepowersave.cpp @@ -194,6 +194,8 @@ void tdepowersave::initMenu() { TQIconSet::Automatic), i18n("Suspend to RAM"), this, TQT_SLOT(do_suspend2ram())); + FREEZE_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram", TQIconSet::Automatic), + i18n("Freeze"), this, TQT_SLOT(do_freeze())); STANDBY_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("stand_by", TQIconSet::Automatic), i18n("Standby"), this, TQT_SLOT(do_standby())); @@ -685,9 +687,9 @@ void tdepowersave::slotConfigProcessExited(TDEProcess *proc){ } /*! - * \b TQT_SLOT to send the command for "suspend to disk" to HAL daemon. + * \b TQT_SLOT to send the command for "suspend to disk" to TDE hardware library. * If there is a error while "suspend to disk" the user get e messagebox. - * This function need a running HAL daemon for "suspend to disk". + * This function need a power management backend in TDE hardware library for "suspend to disk". * \return boolean with the result of the operation * \retval true if successful * \retval false if command not supported or if powersaved not running @@ -734,16 +736,16 @@ bool tdepowersave::do_suspend2disk(){ return false; } } else { - kdWarning() << "This machine does not provide suspend2disk via HAL" << endl; + kdWarning() << "This machine does not provide suspend to disk state" << endl; kdDebugFuncOut(trace); return false; } } /*! - * \b TQT_SLOT to send the command for "suspend to RAM" to the HAL daemon. + * \b TQT_SLOT to send the command for "suspend to RAM" to the TDE hardware library. * If there is a error while "suspend to RAM" the user get e messagebox. - * This function need a running HAL daemon for "suspend to RAM". + * This function need a power management backend in TDE hardware library for "suspend to RAM". * \return boolean with the result of the operation * \retval true if successful * \retval false if command not supported or if powersaved not running @@ -790,16 +792,71 @@ bool tdepowersave::do_suspend2ram(){ return false; } } else { - kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; + kdWarning() << "This machine does not provide suspend to ram state" << endl; kdDebugFuncOut(trace); return false; } } /*! - * \b TQT_SLOT to send the command for "stand-by" to the HAL daemon. + * \b TQT_SLOT to send the command for "freeze" to the TDE hardware library. + * If there is a error while "freeze" the user get e messagebox. + * This function need a power management backend in TDE hardware library for "freeze". + * \return boolean with the result of the operation + * \retval true if successful + * \retval false if command not supported or if powersaved not running + */ +bool tdepowersave::do_freeze(){ + kdDebugFuncIn(trace); + + if (suspend.freeze) { + if (suspend.freeze_allowed || suspend.freeze_allowed == -1) { + calledSuspend = FREEZE; + if (!handleMounts(true)) { + kdWarning() << "Could not umount ..." << endl; + calledSuspend = -1; + kdDebugFuncOut(trace); + return false; + } + + if(settings->lockOnSuspend) { + display->lockScreen( settings->lockmethod ); + } + + autoSuspend->stop(); + autoDimm->stop(); + notifySuspend(calledSuspend); + bool ret = hwinfo->suspend(FREEZE); + + if (ret) { + kdDebugFuncOut(trace); + return true; + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Freeze failed"), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + kdDebugFuncOut(trace); + return false; + } + } else { + KPassivePopup::message( i18n("WARNING"),i18n("Freeze disabled by administrator."), + SmallIcon("messagebox_warning", 20), this, + i18n("Warning").ascii(), 15000); + this->contextMenu()->setItemEnabled(FREEZE_MENU_ID, false); + kdDebugFuncOut(trace); + return false; + } + } else { + kdWarning() << "This machine does not provide freeze suspend state" << endl; + kdDebugFuncOut(trace); + return false; + } +} + +/*! + * \b TQT_SLOT to send the command for "stand-by" to the TDE hardware library. * If there is a error while "stand-by" the user get e messagebox. - * This function need a running HAL daemon for "stand-by". + * This function need a power management backend in TDE hardware library for "stand-by". * \return boolean with the result of the operation * \retval true if successful * \retval false if command not supported or if powersaved not running @@ -845,7 +902,7 @@ bool tdepowersave::do_standby(){ return false; } } else { - kdWarning() << "This machine does not provide suspend2ram via HAL" << endl; + kdWarning() << "This machine does not provide standby suspend state" << endl; kdDebugFuncOut(trace); return false; } @@ -872,6 +929,11 @@ void tdepowersave::do_autosuspendWarn() { allowed = true; } } + else if (settings->autoInactiveAction == "Freeze") { + if ( suspend.freeze && (suspend.freeze_allowed || suspend.freeze_allowed == -1)) { + allowed = true; + } + } else if (settings->autoInactiveAction == "Standby") { if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) { allowed = true; @@ -890,6 +952,8 @@ void tdepowersave::do_autosuspendWarn() { countdown->setPixmap("suspend2disk"); } else if (settings->autoInactiveAction == "Suspend to RAM") { countdown->setPixmap("suspend2ram"); + } else if (settings->autoInactiveAction == "Freeze") { + countdown->setPixmap("suspend2ram"); } else if (settings->autoInactiveAction == "Standby") { countdown->setPixmap("standby"); } else { @@ -943,6 +1007,8 @@ bool tdepowersave::do_autosuspend(bool chancel) { return do_suspend2disk(); } else if (settings->autoInactiveAction == "Suspend to RAM") { return do_suspend2ram(); + } else if (settings->autoInactiveAction == "Freeze") { + return do_freeze(); } else if (settings->autoInactiveAction == "Standby") { return do_standby(); } else { @@ -1389,6 +1455,7 @@ void tdepowersave::update(){ if (!hwinfo->isOnline()){ this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false); this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, false); + this->contextMenu()->setItemVisible(FREEZE_MENU_ID, false); this->contextMenu()->setItemVisible(STANDBY_MENU_ID, false); this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, false); this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false); @@ -1411,6 +1478,7 @@ void tdepowersave::update(){ } this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, true); this->contextMenu()->setItemVisible(SUSPEND2RAM_MENU_ID, true); + this->contextMenu()->setItemVisible(FREEZE_MENU_ID, true); this->contextMenu()->setItemVisible(STANDBY_MENU_ID, true); this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, true); this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true); @@ -1439,6 +1507,15 @@ void tdepowersave::update(){ this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, false); } + if (suspend.freeze && (suspend.freeze_allowed || suspend.freeze_allowed == -1)) { + this->contextMenu()->setItemEnabled(FREEZE_MENU_ID, true); + } else { + if (!suspend.freeze) + this->contextMenu()->setItemVisible(FREEZE_MENU_ID, false); + else + this->contextMenu()->setItemEnabled(FREEZE_MENU_ID, false); + } + if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) { this->contextMenu()->setItemEnabled(STANDBY_MENU_ID, true); } else { @@ -1840,6 +1917,11 @@ void tdepowersave::setAutoSuspend( bool resumed ){ allowed = true; } } + else if (settings->autoInactiveAction == "Freeze") { + if ( suspend.freeze && (suspend.freeze_allowed || suspend.freeze_allowed == -1)) { + allowed = true; + } + } else if (settings->autoInactiveAction == "Standby") { if ( suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)) { allowed = true; @@ -2071,6 +2153,9 @@ void tdepowersave::handleActionCall ( action action, int value , bool checkAC, b case GO_SUSPEND2DISK: TQTimer::singleShot(100, this, TQT_SLOT(do_suspend2disk())); break; + case GO_FREEZE: + TQTimer::singleShot(100, this, TQT_SLOT(do_freeze())); + break; case BRIGHTNESS: hwinfo->setBrightness( -1, value ); break; @@ -2192,6 +2277,11 @@ void tdepowersave::notifySuspend( int suspendType ) { i18n("System is going into %1 now."). arg(i18n("Suspend to RAM"))); break; + case FREEZE: + KNotifyClient::event( this->winId(), "freeze_event", + i18n("System is going into %1 now."). + arg(i18n("Freeze"))); + break; case STANDBY: KNotifyClient::event( this->winId(), "standby_event", i18n("System is going into %1 now."). @@ -2252,6 +2342,11 @@ void tdepowersave::handleResumeSignal() { i18n("System is resumed from %1.").arg( i18n("Suspend to RAM"))); break; + case FREEZE: + KNotifyClient::event( this->winId(), "resume_from_freeze_event", + i18n("System is resumed from %1.").arg( + i18n("Freeze"))); + break; case STANDBY: KNotifyClient::event( this->winId(), "resume_from_standby_event", i18n("System is resumed from %1.").arg( @@ -2301,6 +2396,10 @@ void tdepowersave::handleResumeSignal() { logview = new LogViewer ("/var/log/suspend2ram.log"); logview->show(); break; + case FREEZE: + logview = new LogViewer ("/var/log/freeze.log"); + logview->show(); + break; case STANDBY: logview = new LogViewer ("/var/log/standby.log"); logview->show(); @@ -2368,6 +2467,9 @@ TQString tdepowersave::getSuspendString (int type) { case SUSPEND2RAM: return i18n("Suspend to RAM"); break; + case FREEZE: + return i18n("Freeze"); + break; case STANDBY: return i18n("Standby"); break; @@ -2517,6 +2619,9 @@ TQStringList tdepowersave::allowed_sleepingStates(){ suspend.suspend2ram_allowed == -1)){ sleepList.append("suspendToRAM"); } + if (suspend.freeze && (suspend.freeze_allowed || suspend.freeze_allowed == -1)){ + sleepList.append("freeze"); + } if (suspend.standby && (suspend.standby_allowed || suspend.standby_allowed == -1)){ sleepList.append("standBy"); } @@ -2607,7 +2712,19 @@ bool tdepowersave::do_suspendToRAM(){ } /*! - * DCOP Interface funtion to send the suspend to disk command to powersave. + * DCOP Interface funtion to send the freeze command to powersave. + * \return boolean with the result of calling do_freeze() + * \retval true if successful + * \retval false if not supported or powersaved not running + */ +bool tdepowersave::do_suspendFreeze(){ + kdDebugFuncIn(trace); + kdDebugFuncOut(trace); + return do_freeze(); +} + +/*! + * DCOP Interface funtion to send the standby command to powersave. * \return boolean with the result of calling do_standby() * \retval true if successful * \retval false if not supported or powersaved not running |