summaryrefslogtreecommitdiffstats
path: root/src/tdepowersave.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tdepowersave.cpp')
-rw-r--r--src/tdepowersave.cpp152
1 files changed, 133 insertions, 19 deletions
diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp
index d214a3b..e6d6e53 100644
--- a/src/tdepowersave.cpp
+++ b/src/tdepowersave.cpp
@@ -74,12 +74,12 @@ tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTr
config->writeEntry("AlreadyStarted", true);
// check whether APM, ACPI, PMU, CPUFreq or Suspend2Disk/ram supported, otherwise end up
// and don't start tdepowersave ever again until force_acpi_check == true.
- if (!hwinfo->hasACPI() && !hwinfo->hasAPM() && !hwinfo->hasPMU() &&
- !hwinfo->supportCPUFreq() && !suspend.suspend2disk && !suspend.suspend2ram){
+ if (!hwinfo->hasACPI() && !hwinfo->hasAPM() && !hwinfo->hasPMU() && !hwinfo->supportCPUFreq() &&
+ !suspend.suspend2disk && !suspend.suspend2ram && !suspend.suspend_hybrid) {
config->writeEntry("Autostart", false);
config->sync();
- kdError() << "This machine does not support ACPI, APM, PMU, CPUFreq, Suspend2Disk nor "
- << "Suspend2RAM. Please close tdepowersave now." << endl;
+ kdError() << "This machine does not support ACPI, APM, PMU, CPUFreq, Suspend2Disk, "
+ << "Suspend2RAM nor Hybrid Suspend. Please close tdepowersave now." << endl;
exit(-1);
}
}
@@ -186,18 +186,16 @@ void tdepowersave::initMenu() {
#endif
SLEEP_SEPARATOR_MENU_ID = this->contextMenu()->insertSeparator();
- SUSPEND2DISK_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk",
- TQIconSet::Automatic),
- i18n("Hibernate"), this,
- TQT_SLOT(do_suspend2disk()));
- SUSPEND2RAM_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram",
- TQIconSet::Automatic),
- i18n("Sleep"), 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()));
+ SUSPEND2RAM_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_ram",
+ TQIconSet::Automatic), i18n("Sleep"), this, TQT_SLOT(do_suspend2ram()));
+ SUSPEND2DISK_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk",
+ TQIconSet::Automatic), i18n("Hibernate"), this, TQT_SLOT(do_suspend2disk()));
+ SUSPEND_HYBRID_MENU_ID = this->contextMenu()->insertItem( SmallIconSet("suspend_to_disk",
+ TQIconSet::Automatic), i18n("Hybrid Suspend"), this, TQT_SLOT(do_suspend_hybrid()));
speed_menu = new TQPopupMenu(this, i18n("Set CPU Frequency Policy").ascii());
speed_menu->insertItem(i18n("Performance"), PERFORMANCE);
@@ -691,7 +689,7 @@ void tdepowersave::slotConfigProcessExited(TDEProcess *proc){
/*!
* \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.
+ * If there is a error while "suspend to disk" the user get a messagebox.
* 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
@@ -746,6 +744,62 @@ bool tdepowersave::do_suspend2disk(){
}
/*!
+ * \b TQT_SLOT to send the command for "hybrid suspend" to TDE hardware library.
+ * If there is a error while "hybrid suspend" the user get a messagebox.
+ * This function need a power management backend in TDE hardware library for "hybrid suspend".
+ * \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_suspend_hybrid(){
+ kdDebugFuncIn(trace);
+
+ if (suspend.suspend_hybrid) {
+ if (suspend.suspend_hybrid_allowed || suspend.suspend_hybrid_allowed == -1) {
+ calledSuspend = SUSPEND_HYBRID;
+ 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(SUSPEND_HYBRID);
+
+ if (ret) {
+ kdDebugFuncOut(trace);
+ return true;
+ } else {
+ KPassivePopup::message( i18n("WARNING"),i18n("Hybrid Suspend failed"),
+ SmallIcon("messagebox_warning", 20), this,
+ i18n("Warning").ascii(), 15000);
+ kdDebugFuncOut(trace);
+ return false;
+ }
+ } else {
+ KPassivePopup::message( i18n("WARNING"),
+ i18n("Hybrid Suspend disabled by administrator."),
+ SmallIcon("messagebox_warning", 20),
+ this, i18n("Warning").ascii(), 15000);
+ this->contextMenu()->setItemEnabled(SUSPEND_HYBRID_MENU_ID, false);
+ kdDebugFuncOut(trace);
+ return false;
+ }
+ } else {
+ kdWarning() << "This machine does not provide hybrid suspend state" << endl;
+ kdDebugFuncOut(trace);
+ return false;
+ }
+}
+
+/*!
* \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 a messagebox.
* This function need a power management backend in TDE hardware library for "suspend to RAM".
@@ -927,6 +981,11 @@ void tdepowersave::do_autosuspendWarn() {
allowed = true;
}
}
+ else if(settings->autoInactiveAction == "Hybrid Suspend") {
+ if ( suspend.suspend_hybrid && (suspend.suspend_hybrid_allowed || suspend.suspend_hybrid_allowed == -1)) {
+ allowed = true;
+ }
+ }
else if (settings->autoInactiveAction == "Sleep") {
if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
allowed = true;
@@ -953,6 +1012,8 @@ void tdepowersave::do_autosuspendWarn() {
if(settings->autoInactiveAction == "Hibernate") {
countdown->setPixmap("suspend2disk");
+ } else if(settings->autoInactiveAction == "Hybrid Suspend") {
+ countdown->setPixmap("suspend2disk");
} else if (settings->autoInactiveAction == "Sleep") {
countdown->setPixmap("suspend2ram");
} else if (settings->autoInactiveAction == "Freeze") {
@@ -995,8 +1056,6 @@ void tdepowersave::do_autosuspendWarn() {
*/
bool tdepowersave::do_autosuspend(bool cancel) {
kdDebugFuncIn(trace);
-
- // TODO: check if this is really needed, it get called also on the suspend methodes
autoSuspend->stop();
if (!cancel) {
@@ -1008,6 +1067,8 @@ bool tdepowersave::do_autosuspend(bool cancel) {
if(settings->autoSuspend && !contextMenu()->isItemChecked(AUTOSUSPEND_MENU_ID)) {
if(settings->autoInactiveAction == "Hibernate") {
return do_suspend2disk();
+ } else if(settings->autoInactiveAction == "Hybrid Suspend") {
+ return do_suspend_hybrid();
} else if (settings->autoInactiveAction == "Sleep") {
return do_suspend2ram();
} else if (settings->autoInactiveAction == "Freeze") {
@@ -1456,10 +1517,11 @@ void tdepowersave::update(){
redraw_pixmap = 1;
}
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(SUSPEND2RAM_MENU_ID, false);
+ this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, false);
+ this->contextMenu()->setItemVisible(SUSPEND_HYBRID_MENU_ID, false);
this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, false);
this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, false);
this->contextMenu()->setItemVisible(SCHEME_MENU_ID, false);
@@ -1479,10 +1541,11 @@ void tdepowersave::update(){
hwinfo->update_info_cpufreq_policy_changed = true;
suspend = hwinfo->getSuspendSupport();
}
- 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(SUSPEND2RAM_MENU_ID, true);
+ this->contextMenu()->setItemVisible(SUSPEND2DISK_MENU_ID, true);
+ this->contextMenu()->setItemVisible(SUSPEND_HYBRID_MENU_ID, true);
this->contextMenu()->setItemVisible(SLEEP_SEPARATOR_MENU_ID, true);
this->contextMenu()->setItemVisible(SCHEME_SEPARATOR_MENU_ID, true);
this->contextMenu()->setItemVisible(SCHEME_MENU_ID, true);
@@ -1500,6 +1563,16 @@ void tdepowersave::update(){
this->contextMenu()->setItemEnabled(SUSPEND2DISK_MENU_ID, false);
}
+ if (suspend.suspend_hybrid && (suspend.suspend_hybrid_allowed ||
+ suspend.suspend_hybrid_allowed == -1)) {
+ this->contextMenu()->setItemEnabled(SUSPEND_HYBRID_MENU_ID, true);
+ } else {
+ if (!suspend.suspend_hybrid)
+ this->contextMenu()->setItemVisible(SUSPEND_HYBRID_MENU_ID, false);
+ else
+ this->contextMenu()->setItemEnabled(SUSPEND_HYBRID_MENU_ID, false);
+ }
+
if (suspend.suspend2ram && (suspend.suspend2ram_allowed ||
suspend.suspend2ram_allowed == -1)) {
this->contextMenu()->setItemEnabled(SUSPEND2RAM_MENU_ID, true);
@@ -1907,6 +1980,11 @@ void tdepowersave::setAutoSuspend( bool resumed ){
allowed = true;
}
}
+ else if(settings->autoInactiveAction == "Hybrid Suspend") {
+ if ( suspend.suspend_hybrid && (suspend.suspend_hybrid_allowed || suspend.suspend_hybrid_allowed == -1)) {
+ allowed = true;
+ }
+ }
else if (settings->autoInactiveAction == "Sleep") {
if( suspend.suspend2ram && (suspend.suspend2ram_allowed || suspend.suspend2ram_allowed == -1)) {
allowed = true;
@@ -2148,6 +2226,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_SUSPEND_HYBRID:
+ TQTimer::singleShot(100, this, TQT_SLOT(do_suspend_hybrid()));
+ break;
case GO_FREEZE:
TQTimer::singleShot(100, this, TQT_SLOT(do_freeze()));
break;
@@ -2269,6 +2350,11 @@ void tdepowersave::notifySuspend( int suspendType ) {
i18n("System is going into %1 now.").
arg(i18n("hibernation")));
break;
+ case SUSPEND_HYBRID:
+ KNotifyClient::event( this->winId(), "suspend_hybrid_event",
+ i18n("System is going into %1 now.").
+ arg(i18n("hybrid suspension")));
+ break;
case SUSPEND2RAM:
KNotifyClient::event( this->winId(), "suspend2ram_event",
i18n("System is going into %1 now.").
@@ -2334,6 +2420,11 @@ void tdepowersave::handleResumeSignal() {
i18n("System is resumed from %1.").arg(
i18n("hibernation")));
break;
+ case SUSPEND_HYBRID:
+ KNotifyClient::event( this->winId(), "resume_from_suspend_hybrid_event",
+ i18n("System is resumed from %1.").arg(
+ i18n("hybrid suspension")));
+ break;
case SUSPEND2RAM:
KNotifyClient::event( this->winId(), "resume_from_suspend2ram_event",
i18n("System is resumed from %1.").arg(
@@ -2389,6 +2480,10 @@ void tdepowersave::handleResumeSignal() {
logview = new LogViewer ("/var/log/suspend2disk.log");
logview->show();
break;
+ case SUSPEND_HYBRID:
+ logview = new LogViewer ("/var/log/suspend_hybrid.log");
+ logview->show();
+ break;
case SUSPEND2RAM:
logview = new LogViewer ("/var/log/suspend2ram.log");
logview->show();
@@ -2461,6 +2556,9 @@ TQString tdepowersave::getSuspendString (int type) {
case SUSPEND2DISK:
return i18n("Hibernate");
break;
+ case SUSPEND_HYBRID:
+ return i18n("Hybrid Suspend");
+ break;
case SUSPEND2RAM:
return i18n("Sleep");
break;
@@ -2612,6 +2710,10 @@ TQStringList tdepowersave::allowed_sleepingStates(){
suspend.suspend2disk_allowed == -1)){
sleepList.append("suspendToDisk");
}
+ if (suspend.suspend_hybrid && (suspend.suspend_hybrid_allowed ||
+ suspend.suspend_hybrid_allowed == -1)){
+ sleepList.append("suspendHybrid");
+ }
if (suspend.suspend2ram && (suspend.suspend2ram_allowed ||
suspend.suspend2ram_allowed == -1)){
sleepList.append("suspendToRAM");
@@ -2697,6 +2799,18 @@ bool tdepowersave::do_suspendToDisk(){
}
/*!
+ * DCOP Interface funtion to send the hybrid suspend command to powersave.
+ * \return boolean with the result of calling do_suspend_hybrid()
+ * \retval true if successful
+ * \retval false if not supported or powersaved not running
+ */
+bool tdepowersave::do_suspendHybrid(){
+ kdDebugFuncIn(trace);
+ kdDebugFuncOut(trace);
+ return do_suspend_hybrid();
+}
+
+/*!
* DCOP Interface funtion to send the suspend to disk command to powersave.
* \return boolean with the result of calling do_suspend2ram()
* \retval true if successful