diff --git a/daemon/actions/bundled/handlebuttonevents.h b/daemon/actions/bundled/handlebuttonevents.h --- a/daemon/actions/bundled/handlebuttonevents.h +++ b/daemon/actions/bundled/handlebuttonevents.h @@ -73,6 +73,7 @@ uint m_lidAction = 0; bool m_triggerLidActionWhenExternalMonitorPresent = false; bool m_externalMonitorPresent = false; + bool m_suspendThenHibernateEnabled = false; uint m_powerButtonAction = 0; uint m_sleepButtonAction = 1; diff --git a/daemon/actions/bundled/handlebuttonevents.cpp b/daemon/actions/bundled/handlebuttonevents.cpp --- a/daemon/actions/bundled/handlebuttonevents.cpp +++ b/daemon/actions/bundled/handlebuttonevents.cpp @@ -186,6 +186,7 @@ bool HandleButtonEvents::loadAction(const KConfigGroup& config) { // Read configs + m_suspendThenHibernateEnabled = config.readEntry("suspendThenHibernate", false); m_lidAction = config.readEntry("lidAction", 0); m_triggerLidActionWhenExternalMonitorPresent = config.readEntry("triggerLidActionWhenExternalMonitorPresent", false); m_powerButtonAction = config.readEntry("powerButtonAction", 0); diff --git a/daemon/actions/bundled/handlebuttoneventsconfig.h b/daemon/actions/bundled/handlebuttoneventsconfig.h --- a/daemon/actions/bundled/handlebuttoneventsconfig.h +++ b/daemon/actions/bundled/handlebuttoneventsconfig.h @@ -42,6 +42,7 @@ QList< QPair< QString, QWidget* > > buildUi() override; private: + QCheckBox *m_enableSuspendThenHibernate; QComboBox *m_lidCloseCombo; QCheckBox *m_triggerLidActionWhenExternalMonitorPresent; QComboBox *m_powerButtonCombo; diff --git a/daemon/actions/bundled/handlebuttoneventsconfig.cpp b/daemon/actions/bundled/handlebuttoneventsconfig.cpp --- a/daemon/actions/bundled/handlebuttoneventsconfig.cpp +++ b/daemon/actions/bundled/handlebuttoneventsconfig.cpp @@ -60,6 +60,13 @@ if (m_powerButtonCombo) { configGroup().writeEntry("powerButtonAction", m_powerButtonCombo->itemData(m_powerButtonCombo->currentIndex()).toUInt()); } + if(m_enableSuspendThenHibernate) { + // save true only if the system can suspend and hibernate + configGroup().writeEntry( + "suspendThenHibernate", m_enableSuspendThenHibernate->isChecked()); + } else { + configGroup().writeEntry("suspendThenHibernate", false); + } configGroup().sync(); } @@ -77,11 +84,16 @@ if (m_powerButtonCombo) { m_powerButtonCombo->setCurrentIndex(m_powerButtonCombo->findData(QVariant::fromValue(configGroup().readEntry("powerButtonAction", 0)))); } + if (m_enableSuspendThenHibernate) { + // check if the system can suspend and hibernate before setting the value. + m_enableSuspendThenHibernate->setChecked(configGroup().readEntry("suspendThenHibernate", false)); + } } QList< QPair< QString, QWidget* > > HandleButtonEventsConfig::buildUi() { // Create the boxes + m_enableSuspendThenHibernate = new QCheckBox(i18nc("Hibernate after a delay when suspended", "Hibernate after a delay when suspended")); m_lidCloseCombo = new QComboBox; m_triggerLidActionWhenExternalMonitorPresent = new QCheckBox( i18nc("Execute action on lid close even when external monitor is connected", "Even when an external monitor is connected") @@ -104,9 +116,6 @@ if (PowerManagement::instance()->canHybridSuspend()) { box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode); } - if (PowerManagement::instance()->canSuspendThenHibernate()) { - box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Suspend then Hibernate"), (uint)SuspendSession::SuspendThenHibernateMode); - } box->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); box->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); if (box != m_lidCloseCombo) { @@ -119,6 +128,7 @@ connect(m_lidCloseCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_triggerLidActionWhenExternalMonitorPresent, SIGNAL(stateChanged(int)), this, SLOT(setChanged())); connect(m_powerButtonCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); + connect(m_enableSuspendThenHibernate, SIGNAL(stateChanged(int)), this, SLOT(setChanged())); bool lidFound = false; bool powerFound = true; // HACK This needs proper API!! @@ -154,6 +164,13 @@ m_powerButtonCombo->deleteLater(); m_powerButtonCombo = nullptr; } + if (PowerManagement::instance()->canSuspendThenHibernate()) { + retlist.append(qMakePair< QString, QWidget* >(QLatin1Literal("NONE"), m_enableSuspendThenHibernate)); + } else { + m_enableSuspendThenHibernate->deleteLater(); + m_enableSuspendThenHibernate = nullptr; + } + // unified width for the comboboxes int comboBoxMaxWidth = 300; @@ -163,6 +180,9 @@ if (m_powerButtonCombo) { comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_powerButtonCombo->sizeHint().width()); } + if (m_enableSuspendThenHibernate) { + comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_enableSuspendThenHibernate->sizeHint().width()); + } if (m_lidCloseCombo) { m_lidCloseCombo->setMinimumWidth(300); m_lidCloseCombo->setMaximumWidth(comboBoxMaxWidth); @@ -171,6 +191,10 @@ m_powerButtonCombo->setMinimumWidth(300); m_powerButtonCombo->setMaximumWidth(comboBoxMaxWidth); } + if(m_enableSuspendThenHibernate) { + m_enableSuspendThenHibernate->setMinimumWidth(300); + m_enableSuspendThenHibernate->setMaximumWidth(comboBoxMaxWidth); + } return retlist; } diff --git a/daemon/actions/bundled/suspendsession.h b/daemon/actions/bundled/suspendsession.h --- a/daemon/actions/bundled/suspendsession.h +++ b/daemon/actions/bundled/suspendsession.h @@ -49,8 +49,7 @@ LogoutDialogMode = 16, LockScreenMode = 32, TurnOffScreenMode = 64, - ToggleScreenOnOffMode = 128, - SuspendThenHibernateMode = 256 + ToggleScreenOnOffMode = 128 }; explicit SuspendSession(QObject *parent); @@ -69,7 +68,6 @@ void suspendToRam(); void suspendToDisk(); void suspendHybrid(); - void suspendThenHibernate(); Q_SIGNALS: void aboutToSuspend(); @@ -79,6 +77,7 @@ void triggerSuspendSession(uint action); private: + bool m_suspendThenHibernateEnabled = false; int m_idleTime = 0; uint m_autoType; QVariantMap m_savedArgs; diff --git a/daemon/actions/bundled/suspendsession.cpp b/daemon/actions/bundled/suspendsession.cpp --- a/daemon/actions/bundled/suspendsession.cpp +++ b/daemon/actions/bundled/suspendsession.cpp @@ -111,7 +111,7 @@ const auto mode = static_cast(args["Type"].toUInt()); - if (mode == ToRamMode || mode == ToDiskMode || mode == SuspendHybridMode || mode == SuspendThenHibernateMode) { + if (mode == ToRamMode || mode == ToDiskMode || mode == SuspendHybridMode) { // don't suspend if shutting down if (KWorkSpace::isShuttingDown()) { qCDebug(POWERDEVIL) << "Not suspending because a shutdown is in progress"; @@ -134,7 +134,11 @@ switch ((Mode) (args["Type"].toUInt())) { case ToRamMode: Q_EMIT aboutToSuspend(); - suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToRam); + if (m_suspendThenHibernateEnabled) { + suspendJob = backend()->suspend(PowerDevil::BackendInterface::SuspendThenHibernate); + } else { + suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToRam); + } break; case ToDiskMode: Q_EMIT aboutToSuspend(); @@ -144,10 +148,6 @@ Q_EMIT aboutToSuspend(); suspendJob = backend()->suspend(PowerDevil::BackendInterface::HybridSuspend); break; - case SuspendThenHibernateMode: - Q_EMIT aboutToSuspend(); - suspendJob = backend()->suspend(PowerDevil::BackendInterface::SuspendThenHibernate); - break; case ShutdownMode: KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo, KWorkSpace::ShutdownTypeHalt); break; @@ -183,6 +183,9 @@ } m_autoType = config.readEntry("suspendType", 0); } + if (config.isValid() && config.hasKey("suspendThenHibernate")) { + m_suspendThenHibernateEnabled = config.readEntry("suspendThenHibernate", false); + } return true; } @@ -202,11 +205,6 @@ triggerSuspendSession(ToRamMode); } -void SuspendSession::suspendThenHibernate() -{ - triggerSuspendSession(SuspendThenHibernateMode); -} - void SuspendSession::triggerSuspendSession(uint action) { trigger({ diff --git a/daemon/actions/bundled/suspendsessionconfig.h b/daemon/actions/bundled/suspendsessionconfig.h --- a/daemon/actions/bundled/suspendsessionconfig.h +++ b/daemon/actions/bundled/suspendsessionconfig.h @@ -24,6 +24,7 @@ #include class KComboBox; +class QCheckBox; class QSpinBox; namespace PowerDevil { @@ -43,6 +44,7 @@ private: QSpinBox *m_idleTime; + QCheckBox *m_suspendThenHibernateEnabled; KComboBox *m_comboBox; }; diff --git a/daemon/actions/bundled/suspendsessionconfig.cpp b/daemon/actions/bundled/suspendsessionconfig.cpp --- a/daemon/actions/bundled/suspendsessionconfig.cpp +++ b/daemon/actions/bundled/suspendsessionconfig.cpp @@ -25,12 +25,13 @@ #include #include +#include #include #include #include #include +#include #include -#include #include "suspendsession.h" K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin(); ) @@ -53,6 +54,12 @@ { configGroup().writeEntry< uint >("suspendType", m_comboBox->itemData(m_comboBox->currentIndex()).toUInt()); configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000); + if (m_suspendThenHibernateEnabled) { + configGroup().writeEntry( + "suspendThenHibernate", m_suspendThenHibernateEnabled->isChecked()); + } else { + configGroup().writeEntry("suspendThenHibernate", false); + } configGroup().sync(); } @@ -64,10 +71,15 @@ uint suspendType = configGroup().readEntry< uint >("suspendType", 0); m_comboBox->setCurrentIndex(m_comboBox->findData(suspendType)); m_idleTime->setValue((configGroup().readEntry("idleTime", 600000) / 60) / 1000); + if (m_suspendThenHibernateEnabled) { + m_suspendThenHibernateEnabled->setChecked(configGroup().readEntry("suspendThenHibernate", false)); + } } QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi() { + m_suspendThenHibernateEnabled = new QCheckBox( + i18nc("Hibernate after a delay when suspended", "Hibernate after a delay when suspended")); QWidget *tempWidget = new QWidget; QHBoxLayout *hlay = new QHBoxLayout; m_comboBox = new KComboBox; @@ -87,9 +99,6 @@ if (PowerManagement::instance()->canHybridSuspend()) { m_comboBox->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode); } - if (PowerManagement::instance()->canSuspendThenHibernate()) { - m_comboBox->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Suspend then Hibernate"), (uint)SuspendSession::SuspendThenHibernateMode); - } m_comboBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); m_comboBox->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); @@ -105,11 +114,26 @@ connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged())); + connect(m_suspendThenHibernateEnabled, SIGNAL(stateChanged(int)), this, SLOT(setChanged())); + + if (PowerManagement::instance()->canSuspendThenHibernate()) { + retlist.append(qMakePair< QString, QWidget* >(QLatin1Literal("NONE"), m_suspendThenHibernateEnabled)); + } else { + m_suspendThenHibernateEnabled->deleteLater(); + m_suspendThenHibernateEnabled = nullptr; + } + + int comboBoxMaxWidth = 300; + if (m_suspendThenHibernateEnabled) { + comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_suspendThenHibernateEnabled->sizeHint().width()); + m_suspendThenHibernateEnabled->setMinimumWidth(300); + m_suspendThenHibernateEnabled->setMaximumWidth(comboBoxMaxWidth); + } return retlist; } } } - +r #include "suspendsessionconfig.moc" diff --git a/daemon/org.freedesktop.PowerManagement.xml b/daemon/org.freedesktop.PowerManagement.xml --- a/daemon/org.freedesktop.PowerManagement.xml +++ b/daemon/org.freedesktop.PowerManagement.xml @@ -11,7 +11,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/daemon/powerdevilfdoconnector.cpp b/daemon/powerdevilfdoconnector.cpp --- a/daemon/powerdevilfdoconnector.cpp +++ b/daemon/powerdevilfdoconnector.cpp @@ -93,11 +93,6 @@ triggerSuspendSession(BundledActions::SuspendSession::SuspendHybridMode); } -void FdoConnector::SuspendThenHibernate() -{ - triggerSuspendSession(BundledActions::SuspendSession::SuspendThenHibernateMode); -} - bool FdoConnector::HasInhibit() { return PolicyAgent::instance()->requirePolicyCheck(PolicyAgent::InterruptSession) != PolicyAgent::None; diff --git a/kcmodule/activities/activitywidget.cpp b/kcmodule/activities/activitywidget.cpp --- a/kcmodule/activities/activitywidget.cpp +++ b/kcmodule/activities/activitywidget.cpp @@ -100,10 +100,6 @@ m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } - if (PowerDevil::PowerManagement::instance()->canSuspendThenHibernate()) { - m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), - i18n("Suspend then Hibernate"), (uint)SuspendSession::SuspendThenHibernateMode); - } m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); m_ui->actLikeComboBox->clear();