Changeset View
Changeset View
Standalone View
Standalone View
daemon/actions/bundled/suspendsession.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 128 | if (args["GraceFade"].toBool()) { | |||
---|---|---|---|---|---|
129 | return; | 129 | return; | ||
130 | } | 130 | } | ||
131 | 131 | | |||
132 | // Switch for real action | 132 | // Switch for real action | ||
133 | KJob *suspendJob = nullptr; | 133 | KJob *suspendJob = nullptr; | ||
134 | switch ((Mode) (args["Type"].toUInt())) { | 134 | switch ((Mode) (args["Type"].toUInt())) { | ||
135 | case ToRamMode: | 135 | case ToRamMode: | ||
136 | Q_EMIT aboutToSuspend(); | 136 | Q_EMIT aboutToSuspend(); | ||
137 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToRam); | 137 | suspendJob = backend()->suspend(m_suspendThenHibernateEnabled | ||
138 | ? PowerDevil::BackendInterface::SuspendThenHibernate : PowerDevil::BackendInterface::ToRam); | ||||
abalaji: How about avoiding the duplicate `suspendJob = backend()->suspend()` calls by doing:
```… | |||||
138 | break; | 139 | break; | ||
139 | case ToDiskMode: | 140 | case ToDiskMode: | ||
140 | Q_EMIT aboutToSuspend(); | 141 | Q_EMIT aboutToSuspend(); | ||
141 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToDisk); | 142 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToDisk); | ||
142 | break; | 143 | break; | ||
143 | case SuspendHybridMode: | 144 | case SuspendHybridMode: | ||
144 | Q_EMIT aboutToSuspend(); | 145 | Q_EMIT aboutToSuspend(); | ||
145 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::HybridSuspend); | 146 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::HybridSuspend); | ||
Show All 18 Lines | |||||
164 | 165 | | |||
165 | if (suspendJob) { | 166 | if (suspendJob) { | ||
166 | // TODO connect(suspendJob, &KJob::error ??, this, [this]() { m_fadeEffect->stop(); }); | 167 | // TODO connect(suspendJob, &KJob::error ??, this, [this]() { m_fadeEffect->stop(); }); | ||
167 | suspendJob->start(); | 168 | suspendJob->start(); | ||
168 | } | 169 | } | ||
169 | } | 170 | } | ||
170 | 171 | | |||
171 | bool SuspendSession::loadAction(const KConfigGroup& config) | 172 | bool SuspendSession::loadAction(const KConfigGroup& config) | ||
172 | { | 173 | { | ||
173 | if (config.isValid() && config.hasKey("idleTime") && config.hasKey("suspendType")) { | 174 | if (config.isValid()) { | ||
abalaji: Factor the `config.isValid()` out of the two `if` statements | |||||
175 | if (config.hasKey("idleTime") && config.hasKey("suspendType")) { | ||||
174 | // Add the idle timeout | 176 | // Add the idle timeout | ||
175 | m_idleTime = config.readEntry<int>("idleTime", 0); | 177 | m_idleTime = config.readEntry<int>("idleTime", 0); | ||
176 | if (m_idleTime) { | 178 | if (m_idleTime) { | ||
177 | registerIdleTimeout(m_idleTime - 5000); | 179 | registerIdleTimeout(m_idleTime - 5000); | ||
178 | registerIdleTimeout(m_idleTime); | 180 | registerIdleTimeout(m_idleTime); | ||
179 | } | 181 | } | ||
180 | m_autoType = config.readEntry<uint>("suspendType", 0); | 182 | m_autoType = config.readEntry<uint>("suspendType", 0); | ||
181 | } | 183 | } | ||
182 | 184 | if (config.hasKey("suspendThenHibernate")) { | |||
185 | m_suspendThenHibernateEnabled = config.readEntry<bool>("suspendThenHibernate", false); | ||||
186 | } | ||||
187 | } | ||||
183 | return true; | 188 | return true; | ||
184 | } | 189 | } | ||
185 | 190 | | |||
186 | void SuspendSession::suspendHybrid() | 191 | void SuspendSession::suspendHybrid() | ||
187 | { | 192 | { | ||
188 | triggerSuspendSession(SuspendHybridMode); | 193 | triggerSuspendSession(SuspendHybridMode); | ||
189 | } | 194 | } | ||
190 | 195 | | |||
Show All 20 Lines |
How about avoiding the duplicate suspendJob = backend()->suspend() calls by doing: