File indexing completed on 2024-04-28 05:36:17

0001 /*
0002  *  SPDX-FileCopyrightText: SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
0003  *  SPDX-FileCopyrightText: SPDX-FileCopyrightText: 2023 Jakob Petsovits <jpetso@petsovits.com>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "powerdevilsettingsdefaults.h"
0009 
0010 #include "powerdevilenums.h"
0011 
0012 namespace PowerDevil
0013 {
0014 
0015 int GlobalDefaults::defaultBatteryCriticalAction(bool canSuspend, bool canHibernate)
0016 {
0017     if (!canHibernate) {
0018         return qToUnderlying(canSuspend ? PowerButtonAction::Sleep : PowerButtonAction::NoAction);
0019     }
0020 
0021     return qToUnderlying(PowerDevil::PowerButtonAction::Hibernate);
0022 }
0023 
0024 bool ProfileDefaults::defaultUseProfileSpecificDisplayBrightness(const QString &profileGroup)
0025 {
0026     return profileGroup == QStringLiteral("AC")        ? false
0027         : profileGroup == QStringLiteral("Battery")    ? false
0028         : profileGroup == QStringLiteral("LowBattery") ? true
0029                                                        : false; // any other profileGroup
0030 }
0031 
0032 int ProfileDefaults::defaultDisplayBrightness(const QString &profileGroup)
0033 {
0034     return profileGroup == QStringLiteral("AC")        ? 70 // not managed by default, see above
0035         : profileGroup == QStringLiteral("Battery")    ? 70 // not managed by default, see above
0036         : profileGroup == QStringLiteral("LowBattery") ? 30 // less brightness
0037                                                        : 70; // any other profileGroup
0038 }
0039 
0040 bool ProfileDefaults::defaultDimDisplayWhenIdle()
0041 {
0042     // We want to dim the screen after a while, definitely
0043     return true;
0044 }
0045 
0046 int ProfileDefaults::defaultDimDisplayIdleTimeoutSec(const QString &profileGroup, bool isMobile)
0047 {
0048     if (isMobile) {
0049         return profileGroup == QStringLiteral("AC")        ? 300 // 5 minutes
0050             : profileGroup == QStringLiteral("Battery")    ? 30 // half a minute
0051             : profileGroup == QStringLiteral("LowBattery") ? 30 // half a minute
0052                                                            : 30; // any other profileGroup
0053     }
0054 
0055     return profileGroup == QStringLiteral("AC")        ? 300 // 5 minutes
0056         : profileGroup == QStringLiteral("Battery")    ? 120 // 2 minutes
0057         : profileGroup == QStringLiteral("LowBattery") ? 60 // 1 minute
0058                                                        : 300; // any other profileGroup
0059 }
0060 
0061 bool ProfileDefaults::defaultTurnOffDisplayWhenIdle()
0062 {
0063     // Screen always gets turned off by default, the question is just how to long to wait
0064     return true;
0065 }
0066 
0067 int ProfileDefaults::defaultTurnOffDisplayIdleTimeoutSec(const QString &profileGroup, bool isMobile)
0068 {
0069     if (isMobile) {
0070         return profileGroup == QStringLiteral("AC")        ? 60 // 1 minute
0071             : profileGroup == QStringLiteral("Battery")    ? 60 // 1 minute
0072             : profileGroup == QStringLiteral("LowBattery") ? 30 // half a minute
0073                                                            : 60; // any other profileGroup
0074     }
0075 
0076     return profileGroup == QStringLiteral("AC")        ? 600 // 10 minutes
0077         : profileGroup == QStringLiteral("Battery")    ? 300 // 5 minutes
0078         : profileGroup == QStringLiteral("LowBattery") ? 120 // 2 minutes
0079                                                        : 600; // any other profileGroup
0080 }
0081 
0082 bool ProfileDefaults::defaultLockBeforeTurnOffDisplay(bool isMobile)
0083 {
0084     return isMobile;
0085 }
0086 
0087 unsigned int ProfileDefaults::defaultAutoSuspendAction(bool isVM, bool canSuspend)
0088 {
0089     if (!defaultAutoSuspendWhenIdle(isVM, canSuspend)) {
0090         return qToUnderlying(PowerButtonAction::NoAction);
0091     }
0092     return defaultAutoSuspendType();
0093 }
0094 
0095 bool ProfileDefaults::defaultAutoSuspendWhenIdle(bool isVM, bool canSuspend)
0096 {
0097     // Don't auto suspend by default when running in a virtual machine as it won't save energy anyway
0098     // and can cause hangs, see bug 473835
0099     if (isVM) {
0100         return false;
0101     }
0102     // Even on AC power, suspend after a rather long period of inactivity. Energy is precious!
0103     return canSuspend;
0104 }
0105 
0106 int ProfileDefaults::defaultAutoSuspendIdleTimeoutSec(const QString &profileGroup, bool isMobile)
0107 {
0108     if (isMobile) {
0109         return profileGroup == QStringLiteral("AC")        ? 420 // 7 minutes
0110             : profileGroup == QStringLiteral("Battery")    ? 300 // 5 minutes
0111             : profileGroup == QStringLiteral("LowBattery") ? 300 // 5 minutes
0112                                                            : 300; // any other profileGroup
0113     }
0114 
0115     return profileGroup == QStringLiteral("AC")        ? 900 // 15 minutes
0116         : profileGroup == QStringLiteral("Battery")    ? 600 // 10 minutes
0117         : profileGroup == QStringLiteral("LowBattery") ? 300 // 5 minutes
0118                                                        : 900; // any other profileGroup
0119 }
0120 
0121 unsigned int ProfileDefaults::defaultAutoSuspendType()
0122 {
0123     return qToUnderlying(PowerButtonAction::Sleep);
0124 }
0125 
0126 unsigned int ProfileDefaults::defaultPowerButtonAction(bool isMobile)
0127 {
0128     return qToUnderlying(isMobile ? PowerButtonAction::ToggleScreenOnOff : PowerButtonAction::PromptLogoutDialog);
0129 }
0130 
0131 unsigned int ProfileDefaults::defaultPowerDownAction()
0132 {
0133     return qToUnderlying(PowerButtonAction::PromptLogoutDialog);
0134 }
0135 
0136 unsigned int ProfileDefaults::defaultLidAction(bool isVM, bool canSuspend)
0137 {
0138     // Don't auto suspend by default when running in a virtual machine as it won't save energy anyway
0139     // and can cause hangs, see bug 473835
0140     if (isVM) {
0141         return qToUnderlying(PowerButtonAction::NoAction);
0142     }
0143     return qToUnderlying(canSuspend ? PowerButtonAction::Sleep : PowerButtonAction::TurnOffScreen);
0144 }
0145 
0146 } // namespace PowerDevil