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 | if (m_suspendThenHibernateEnabled) { | ||||
138 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::SuspendThenHibernate); | ||||
139 | } else { | ||||
137 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToRam); | 140 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToRam); | ||
141 | } | ||||
abalaji: How about avoiding the duplicate `suspendJob = backend()->suspend()` calls by doing:
```… | |||||
138 | break; | 142 | break; | ||
139 | case ToDiskMode: | 143 | case ToDiskMode: | ||
140 | Q_EMIT aboutToSuspend(); | 144 | Q_EMIT aboutToSuspend(); | ||
141 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToDisk); | 145 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::ToDisk); | ||
142 | break; | 146 | break; | ||
143 | case SuspendHybridMode: | 147 | case SuspendHybridMode: | ||
144 | Q_EMIT aboutToSuspend(); | 148 | Q_EMIT aboutToSuspend(); | ||
145 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::HybridSuspend); | 149 | suspendJob = backend()->suspend(PowerDevil::BackendInterface::HybridSuspend); | ||
Show All 19 Lines | |||||
165 | if (suspendJob) { | 169 | if (suspendJob) { | ||
166 | // TODO connect(suspendJob, &KJob::error ??, this, [this]() { m_fadeEffect->stop(); }); | 170 | // TODO connect(suspendJob, &KJob::error ??, this, [this]() { m_fadeEffect->stop(); }); | ||
167 | suspendJob->start(); | 171 | suspendJob->start(); | ||
168 | } | 172 | } | ||
169 | } | 173 | } | ||
170 | 174 | | |||
171 | bool SuspendSession::loadAction(const KConfigGroup& config) | 175 | bool SuspendSession::loadAction(const KConfigGroup& config) | ||
172 | { | 176 | { | ||
173 | if (config.isValid() && config.hasKey("idleTime") && config.hasKey("suspendType")) { | 177 | if (config.isValid() && config.hasKey("idleTime") && config.hasKey("suspendType")) { | ||
abalaji: Factor the `config.isValid()` out of the two `if` statements | |||||
174 | // Add the idle timeout | 178 | // Add the idle timeout | ||
175 | m_idleTime = config.readEntry<int>("idleTime", 0); | 179 | m_idleTime = config.readEntry<int>("idleTime", 0); | ||
176 | if (m_idleTime) { | 180 | if (m_idleTime) { | ||
177 | registerIdleTimeout(m_idleTime - 5000); | 181 | registerIdleTimeout(m_idleTime - 5000); | ||
178 | registerIdleTimeout(m_idleTime); | 182 | registerIdleTimeout(m_idleTime); | ||
179 | } | 183 | } | ||
180 | m_autoType = config.readEntry<uint>("suspendType", 0); | 184 | m_autoType = config.readEntry<uint>("suspendType", 0); | ||
181 | } | 185 | } | ||
186 | if (config.isValid() && config.hasKey("suspendThenHibernate")) { | ||||
187 | m_suspendThenHibernateEnabled = config.readEntry<bool>("suspendThenHibernate", false); | ||||
188 | } | ||||
182 | 189 | | |||
183 | return true; | 190 | return true; | ||
184 | } | 191 | } | ||
185 | 192 | | |||
186 | void SuspendSession::suspendHybrid() | 193 | void SuspendSession::suspendHybrid() | ||
187 | { | 194 | { | ||
188 | triggerSuspendSession(SuspendHybridMode); | 195 | triggerSuspendSession(SuspendHybridMode); | ||
189 | } | 196 | } | ||
Show All 21 Lines |
How about avoiding the duplicate suspendJob = backend()->suspend() calls by doing: