File indexing completed on 2024-05-19 09:32:07
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Jakob Petsovits <jpetso@petsovits.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KCModuleData> 0010 #include <KQuickManagedConfigModule> 0011 0012 #include <QList> 0013 #include <QVariant> 0014 0015 // Profile configuration for PowerDevil, i.e. separate settings for AC/Battery/LowBattery power states 0016 0017 class PowerButtonActionModel; 0018 class PowerProfileModel; 0019 class SleepModeModel; 0020 0021 namespace PowerDevil 0022 { 0023 class ProfileSettings; 0024 class GlobalSettings; 0025 class ExternalServiceSettings; 0026 0027 class ProfilesConfigData : public KCModuleData 0028 { 0029 Q_OBJECT 0030 0031 Q_PROPERTY(QObject *global READ global CONSTANT) 0032 Q_PROPERTY(QObject *profileAC READ profileAC CONSTANT) 0033 Q_PROPERTY(QObject *profileBattery READ profileBattery CONSTANT) 0034 Q_PROPERTY(QObject *profileLowBattery READ profileLowBattery CONSTANT) 0035 0036 public: 0037 explicit ProfilesConfigData(QObject *parent, const KPluginMetaData &metaData); 0038 explicit ProfilesConfigData(QObject *parent, bool isMobile, bool isVM, bool canSuspend, bool canHibernate); 0039 ~ProfilesConfigData() override; 0040 0041 GlobalSettings *global() const; 0042 ProfileSettings *profileAC() const; 0043 ProfileSettings *profileBattery() const; 0044 ProfileSettings *profileLowBattery() const; 0045 0046 private: 0047 GlobalSettings *m_globalSettings; 0048 ProfileSettings *m_settingsAC; 0049 ProfileSettings *m_settingsBattery; 0050 ProfileSettings *m_settingsLowBattery; 0051 }; 0052 0053 class ProfilesConfigKCM : public KQuickManagedConfigModule 0054 { 0055 Q_OBJECT 0056 0057 // e.g. {"BrightnessControl": true, "KeyboardBrightnessControl": false, "SuspendSession": true, ...} 0058 Q_PROPERTY(QVariantMap supportedActions READ supportedActions NOTIFY supportedActionsChanged) 0059 0060 Q_PROPERTY(QObject *settings READ settings CONSTANT) 0061 Q_PROPERTY(QObject *externalServiceSettings READ externalServiceSettings CONSTANT) 0062 Q_PROPERTY(QString currentProfile READ currentProfile NOTIFY currentProfileChanged) 0063 Q_PROPERTY(bool supportsBatteryProfiles READ supportsBatteryProfiles NOTIFY supportsBatteryProfilesChanged) 0064 0065 Q_PROPERTY(bool isPowerSupplyBatteryPresent READ isPowerSupplyBatteryPresent NOTIFY isPowerSupplyBatteryPresentChanged) 0066 Q_PROPERTY(bool isPeripheralBatteryPresent READ isPeripheralBatteryPresent NOTIFY isPeripheralBatteryPresentChanged) 0067 Q_PROPERTY(bool isLidPresent READ isLidPresent NOTIFY isLidPresentChanged) 0068 Q_PROPERTY(bool isPowerButtonPresent READ isPowerButtonPresent NOTIFY isPowerButtonPresentChanged) 0069 0070 Q_PROPERTY(bool isChargeStartThresholdSupported READ isChargeStartThresholdSupported NOTIFY isChargeStartThresholdSupportedChanged) 0071 Q_PROPERTY(bool isChargeStopThresholdSupported READ isChargeStopThresholdSupported NOTIFY isChargeStopThresholdSupportedChanged) 0072 Q_PROPERTY(bool chargeStopThresholdMightNeedReconnect READ chargeStopThresholdMightNeedReconnect NOTIFY chargeStopThresholdMightNeedReconnectChanged) 0073 0074 Q_PROPERTY(bool powerManagementServiceRegistered READ powerManagementServiceRegistered NOTIFY powerManagementServiceRegisteredChanged) 0075 Q_PROPERTY(QString powerManagementServiceErrorReason READ powerManagementServiceErrorReason NOTIFY powerManagementServiceErrorReasonChanged) 0076 0077 Q_PROPERTY(QObject *autoSuspendActionModel READ autoSuspendActionModel CONSTANT) 0078 Q_PROPERTY(QObject *batteryCriticalActionModel READ batteryCriticalActionModel CONSTANT) 0079 Q_PROPERTY(QObject *powerButtonActionModel READ powerButtonActionModel CONSTANT) 0080 Q_PROPERTY(QObject *lidActionModel READ lidActionModel CONSTANT) 0081 Q_PROPERTY(QObject *sleepModeModel READ sleepModeModel CONSTANT) 0082 Q_PROPERTY(QObject *powerProfileModel READ powerProfileModel CONSTANT) 0083 0084 public: 0085 ProfilesConfigKCM(QObject *parent, const KPluginMetaData &metaData); 0086 0087 bool isSaveNeeded() const override; 0088 0089 QVariantMap supportedActions() const; 0090 0091 ProfilesConfigData *settings() const; 0092 ExternalServiceSettings *externalServiceSettings() const; 0093 QString currentProfile() const; 0094 bool supportsBatteryProfiles() const; 0095 0096 bool isPowerSupplyBatteryPresent() const; 0097 bool isPeripheralBatteryPresent() const; 0098 bool isLidPresent() const; 0099 bool isPowerButtonPresent() const; 0100 0101 bool isChargeStartThresholdSupported() const; 0102 bool isChargeStopThresholdSupported() const; 0103 bool chargeStopThresholdMightNeedReconnect() const; 0104 0105 QObject *autoSuspendActionModel() const; 0106 QObject *batteryCriticalActionModel() const; 0107 QObject *powerButtonActionModel() const; 0108 QObject *lidActionModel() const; 0109 QObject *sleepModeModel() const; 0110 QObject *powerProfileModel() const; 0111 0112 bool powerManagementServiceRegistered() const; 0113 QString powerManagementServiceErrorReason() const; 0114 0115 public Q_SLOTS: 0116 void load() override; 0117 void save() override; 0118 0119 Q_SIGNALS: 0120 void supportedActionsChanged(); 0121 0122 void currentProfileChanged(); 0123 void supportsBatteryProfilesChanged(); 0124 0125 void isPowerSupplyBatteryPresentChanged(); 0126 void isPeripheralBatteryPresentChanged(); 0127 void isLidPresentChanged(); 0128 void isPowerButtonPresentChanged(); 0129 0130 void isChargeStartThresholdSupportedChanged(); 0131 void isChargeStopThresholdSupportedChanged(); 0132 void chargeStopThresholdMightNeedReconnectChanged(); 0133 0134 void powerManagementServiceRegisteredChanged(); 0135 void powerManagementServiceErrorReasonChanged(); 0136 0137 private: 0138 void setCurrentProfile(const QString ¤tProfile); 0139 void setSupportsBatteryProfiles(bool); 0140 0141 void setPowerSupplyBatteryPresent(bool); 0142 void setPeripheralBatteryPresent(bool); 0143 void setLidPresent(bool); 0144 void setPowerButtonPresent(bool); 0145 0146 void setPowerManagementServiceRegistered(bool); 0147 void setPowerManagementServiceErrorReason(const QString &); 0148 void onServiceRegistered(const QString &service); 0149 void onServiceUnregistered(const QString &service); 0150 0151 QVariantMap m_supportedActions; 0152 0153 ProfilesConfigData *m_settings; 0154 ExternalServiceSettings *m_externalServiceSettings; 0155 QString m_currentProfile; 0156 bool m_supportsBatteryProfiles; 0157 0158 bool m_isPowerSupplyBatteryPresent; 0159 bool m_isPeripheralBatteryPresent; 0160 bool m_isLidPresent; 0161 bool m_isPowerButtonPresent; 0162 0163 bool m_powerManagementServiceRegistered; 0164 QString m_powerManagementServiceErrorReason; 0165 0166 PowerButtonActionModel *m_autoSuspendActionModel; 0167 PowerButtonActionModel *m_batteryCriticalActionModel; 0168 PowerButtonActionModel *m_powerButtonActionModel; 0169 PowerButtonActionModel *m_lidActionModel; 0170 SleepModeModel *m_sleepModeModel; 0171 PowerProfileModel *m_powerProfileModel; 0172 }; 0173 0174 } // namespace PowerDevil