-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathpowermanagementsettings.cpp
368 lines (301 loc) · 11.3 KB
/
powermanagementsettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
*
* Authors:
* Christian Surlykke <[email protected]>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include <QDebug>
#include <LXQt/Power>
#include "powermanagementsettings.h"
// the pause state is only for the tray icon and is not saved
bool PowerManagementSettings::mIdlenessWatcherPaused = false;
namespace PowerManagementSettingsConstants
{
const QString RUN_CHECK_LEVEL { QSL("runCheckLevel") };
const QString ENABLE_BATTERY_WATCHER_KEY { QSL("enableBatteryWatcher") };
const QString ENABLE_LID_WATCHER_KEY { QSL("enableLidWatcher") };
const QString ENABLE_IDLENESS_WATCHER_KEY { QL1S("enableIdlenessWatcher") };
const QString ENABLE_IDLENESS_BACKLIGHT_WATCHER_KEY { QL1S("enableIdlenessBacklightWatcher") };
const QString LID_CLOSED_ACTION_KEY { QL1S("lidClosedAction") };
const QString LID_CLOSED_AC_ACTION_KEY { QL1S("lidClosedAcAction") };
const QString LID_CLOSED_EXT_MON_ACTION_KEY { QL1S("lidClosedExtMonAction") };
const QString LID_CLOSED_EXT_MON_AC_ACTION_KEY { QL1S("lidClosedExtMonAcAction") };
const QString ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY { QL1S("enableExtMonLidClosedActions") };
const QString POWER_LOW_ACTION_KEY { QL1S("powerLowAction") };
const QString POWER_LOW_WARNING_KEY { QL1S("powerLowWarning") };
const QString POWER_LOW_LEVEL_KEY { QL1S("powerLowLevel") };
const QString SHOW_ICON_KEY { QL1S("showIcon") };
const QString USE_THEME_ICONS_KEY { QL1S("useThemeIcons") };
const QString ICON_TYPE_KEY { QL1S("iconType") };
const QString IDLENESS_AC_ACTION_KEY { QL1S("idlenessACAction") };
const QString IDLENESS_AC_TIME { QL1S("idlenessACTime") };
const QString IDLENESS_BATTERY_ACTION_KEY { QL1S("idlenessBatteryAction") };
const QString IDLENESS_BATTERY_TIME { QL1S("idlenessBatteryTime") };
const QString IDLENESS_BACKLIGHT_TIME { QL1S("idlenessTime") };
const QString IDLENESS_BACKLIGHT { QL1S("backlightIdleness") };
const QString IDLENESS_BACKLIGHT_ON_BATTERY_DISCHARGING { QL1S("backlightIdlenessOnBatteryDischarging") };
const QString DISABLE_IDLENESS_WHEN_FULLSCREEN { QL1S("disableIdlenessWhenFullscreen") };
const QString POWER_KEY_ACTION { QL1S("powerKeyAction") };
const QString SUSPEND_KEY_ACTION { QL1S("suspendKeyAction") };
const QString HIBERNATE_KEY_ACTION { QL1S("hibernateKeyAction") };
}
using namespace PowerManagementSettingsConstants;
PowerManagementSettings::PowerManagementSettings(QObject* parent) : LXQt::Settings(QSL("lxqt-powermanagement"), parent)
{
}
PowerManagementSettings::~PowerManagementSettings()
{
}
int PowerManagementSettings::getRunCheckLevel()
{
return value(RUN_CHECK_LEVEL, 0).toInt();
}
void PowerManagementSettings::setRunCheckLevel(int newLevel)
{
setValue(RUN_CHECK_LEVEL, newLevel);
}
bool PowerManagementSettings::isBatteryWatcherEnabled()
{
return value(ENABLE_BATTERY_WATCHER_KEY, true).toBool();
}
void PowerManagementSettings::setBatteryWatcherEnabled(bool batteryWatcherEnabled)
{
setValue(ENABLE_BATTERY_WATCHER_KEY, batteryWatcherEnabled);
}
int PowerManagementSettings::getPowerLowAction()
{
return value(POWER_LOW_ACTION_KEY, -1).toInt();
}
void PowerManagementSettings::setPowerLowAction(int powerLowAction)
{
setValue(POWER_LOW_ACTION_KEY, powerLowAction);
}
int PowerManagementSettings::getPowerLowLevel()
{
return value(POWER_LOW_LEVEL_KEY, 5).toInt();
}
void PowerManagementSettings::setPowerLowLevel(int powerLowLevel)
{
setValue(POWER_LOW_LEVEL_KEY, powerLowLevel);
}
int PowerManagementSettings::getPowerLowWarningTime()
{
return value(POWER_LOW_WARNING_KEY, 30).toInt();
}
void PowerManagementSettings::setPowerLowWarningTime(int powerLowWarningTime)
{
setValue(POWER_LOW_WARNING_KEY, powerLowWarningTime);
}
bool PowerManagementSettings::isShowIcon()
{
return value(SHOW_ICON_KEY, true).toBool();
}
void PowerManagementSettings::setShowIcon(bool showIcon)
{
setValue(SHOW_ICON_KEY, showIcon);
}
PowerManagementSettings::IconType PowerManagementSettings::getIconType() const
{
const QVariant v = value(ICON_TYPE_KEY);
if (v.isValid())
return v.value<IconType>();
// fallback to legacy values
return value(USE_THEME_ICONS_KEY, false).toBool() ? ICON_THEME : ICON_CIRCLE;
}
void PowerManagementSettings::setIconType(IconType type)
{
setValue(ICON_TYPE_KEY, type);
}
bool PowerManagementSettings::isLidWatcherEnabled()
{
return value(ENABLE_LID_WATCHER_KEY, true).toBool();
}
void PowerManagementSettings::setLidWatcherEnabled(bool lidWatcherEnabled)
{
setValue(ENABLE_LID_WATCHER_KEY, lidWatcherEnabled);
}
int PowerManagementSettings::getLidClosedAcAction()
{
return value(LID_CLOSED_AC_ACTION_KEY, LXQt::Power::Action::PowerSuspend).toInt();
}
void PowerManagementSettings::setLidClosedAcAction(int lidClosedAcAction)
{
setValue(LID_CLOSED_AC_ACTION_KEY, lidClosedAcAction);
}
int PowerManagementSettings::getLidClosedAction()
{
return value(LID_CLOSED_ACTION_KEY, LXQt::Power::Action::PowerSuspend).toInt();
}
void PowerManagementSettings::setLidClosedAction(int lidClosedAction)
{
setValue(LID_CLOSED_ACTION_KEY, lidClosedAction);
}
int PowerManagementSettings::getLidClosedExtMonAcAction()
{
return value(LID_CLOSED_EXT_MON_AC_ACTION_KEY, -1).toInt();
}
void PowerManagementSettings::setLidClosedExtMonAcAction(int lidClosedExtMonAcAction)
{
setValue(LID_CLOSED_EXT_MON_AC_ACTION_KEY, lidClosedExtMonAcAction);
}
int PowerManagementSettings::getLidClosedExtMonAction()
{
return value(LID_CLOSED_EXT_MON_ACTION_KEY, -1).toInt();
}
void PowerManagementSettings::setLidClosedExtMonAction(int lidClosedExtMonAction)
{
setValue(LID_CLOSED_EXT_MON_ACTION_KEY, lidClosedExtMonAction);
}
bool PowerManagementSettings::isEnableExtMonLidClosedActions()
{
return value(ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY, 0).toBool();
}
void PowerManagementSettings::setEnableExtMonLidClosedActions(bool enableExtMonLidClosedActions)
{
setValue(ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY, enableExtMonLidClosedActions);
}
bool PowerManagementSettings::isIdlenessWatcherEnabled()
{
return value(ENABLE_IDLENESS_WATCHER_KEY, false).toBool();
}
void PowerManagementSettings::setIdlenessWatcherEnabled(bool idlenessWatcherEnabled)
{
setValue(ENABLE_IDLENESS_WATCHER_KEY, idlenessWatcherEnabled);
}
int PowerManagementSettings::getIdlenessACAction()
{
// defaults to nothing (-1) and eventually load legacy value
int oldValue = value(QL1S("idlenessAction"), -1).toInt();
return value(IDLENESS_AC_ACTION_KEY, oldValue).toInt();
}
void PowerManagementSettings::setIdlenessACAction(int idlenessAction)
{
setValue(IDLENESS_AC_ACTION_KEY, idlenessAction);
}
QTime PowerManagementSettings::getIdlenessACTime()
{
// 1. The default value is 15 minutes (the legacy key is also read);
// 2. Intervals greater than or equal to one hour aren't supported; and
// 3. Intervals smaller than one minute are prevented.
int oldValue = qBound(60, value(QL1S("idlenessTimeSecs"), 900).toInt(), 3599);
int m = oldValue / 60;
int s = oldValue - m * 60;
return value(IDLENESS_AC_TIME, QTime(0, m, s)).toTime();
}
void PowerManagementSettings::setIdlenessACTime(QTime idlenessTime)
{
setValue(IDLENESS_AC_TIME, idlenessTime);
}
int PowerManagementSettings::getIdlenessBatteryAction()
{
// defaults to nothing (-1) and eventually load legacy value
int oldValue = value(QL1S("idlenessAction"), -1).toInt();
return value(IDLENESS_BATTERY_ACTION_KEY, oldValue).toInt();
}
void PowerManagementSettings::setIdlenessBatteryAction(int idlenessAction)
{
setValue(IDLENESS_BATTERY_ACTION_KEY, idlenessAction);
}
QTime PowerManagementSettings::getIdlenessBatteryTime()
{
// 1. The default value is 15 minutes (the legacy key is also read);
// 2. Intervals greater than or equal to one hour aren't supported; and
// 3. Intervals smaller than one minute are prevented.
int oldValue = qBound(60, value(QL1S("idlenessTimeSecs"), 900).toInt(), 3599);
int m = oldValue / 60;
int s = oldValue - m * 60;
return value(IDLENESS_BATTERY_TIME, QTime(0, m, s)).toTime();
}
void PowerManagementSettings::setIdlenessBatteryTime(QTime idlenessTime)
{
setValue(IDLENESS_BATTERY_TIME, idlenessTime);
}
bool PowerManagementSettings::isIdlenessBacklightWatcherEnabled()
{
return value(ENABLE_IDLENESS_BACKLIGHT_WATCHER_KEY, false).toBool();
}
void PowerManagementSettings::setIdlenessBacklightWatcherEnabled(bool idlenessBacklightWatcherEnabled)
{
setValue(ENABLE_IDLENESS_BACKLIGHT_WATCHER_KEY, idlenessBacklightWatcherEnabled);
}
QTime PowerManagementSettings::getIdlenessBacklightTime()
{
// default to 1 minute
return value(IDLENESS_BACKLIGHT_TIME, QTime(0, 1)).toTime();
}
void PowerManagementSettings::setIdlenessBacklightTime(QTime idlenessBacklightTime)
{
setValue(IDLENESS_BACKLIGHT_TIME, idlenessBacklightTime);
}
int PowerManagementSettings::getBacklight()
{
return value(IDLENESS_BACKLIGHT, 50).toInt();
}
void PowerManagementSettings::setBacklight(int backlight)
{
setValue(IDLENESS_BACKLIGHT, backlight);
}
bool PowerManagementSettings::isIdlenessBacklightOnBatteryDischargingEnabled()
{
return value(IDLENESS_BACKLIGHT_ON_BATTERY_DISCHARGING, true).toBool();
}
void PowerManagementSettings::setIdlenessBacklightOnBatteryDischargingEnabled(bool enabled)
{
setValue(IDLENESS_BACKLIGHT_ON_BATTERY_DISCHARGING, enabled);
}
bool PowerManagementSettings::isDisableIdlenessWhenFullscreenEnabled()
{
return value(DISABLE_IDLENESS_WHEN_FULLSCREEN, false).toBool();
}
void PowerManagementSettings::setDisableIdlenessWhenFullscreen(bool enabled)
{
setValue(DISABLE_IDLENESS_WHEN_FULLSCREEN, enabled);
}
int PowerManagementSettings::getPowerKeyAction()
{
return value(POWER_KEY_ACTION, LXQt::Power::Action::PowerShutdown).toInt();
}
void PowerManagementSettings::setPowerKeyAction(int action)
{
setValue(POWER_KEY_ACTION, action);
}
int PowerManagementSettings::getSuspendKeyAction()
{
return value(SUSPEND_KEY_ACTION, LXQt::Power::Action::PowerSuspend).toInt();
}
void PowerManagementSettings::setSuspendKeyAction(int action)
{
setValue(SUSPEND_KEY_ACTION, action);
}
int PowerManagementSettings::getHibernateKeyAction()
{
return value(HIBERNATE_KEY_ACTION, LXQt::Power::Action::PowerHibernate).toInt();
}
void PowerManagementSettings::setHibernateKeyAction(int action)
{
setValue(HIBERNATE_KEY_ACTION, action);
}
bool PowerManagementSettings::isIdlenessWatcherPaused() const
{
return mIdlenessWatcherPaused;
}
void PowerManagementSettings::setIdlenessWatcherPaused(bool idlenessWatcherPaused) {
mIdlenessWatcherPaused = idlenessWatcherPaused;
}