2022-03-13 21:47:42 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
2023-03-17 02:44:36 +00:00
|
|
|
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
|
2023-11-02 11:08:17 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
2026-05-09 08:00:36 +00:00
|
|
|
import org.kde.plasma.private.mobileshell.gamingshellplugin as GamingShell
|
2022-03-13 21:47:42 +00:00
|
|
|
|
2024-07-27 03:47:44 +00:00
|
|
|
QS.QuickSetting {
|
2026-05-09 08:00:36 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
readonly property var profileOrder: ["power-saver", "balanced", "performance"]
|
|
|
|
|
readonly property bool profileAvailable: GamingShell.PowerProfileControl.available
|
|
|
|
|
&& GamingShell.PowerProfileControl.profiles.length > 0
|
|
|
|
|
property var toggle: profileAvailable ? root.cycleProfile : undefined
|
|
|
|
|
|
2022-03-13 21:47:42 +00:00
|
|
|
text: i18n("Battery")
|
2026-05-09 08:00:36 +00:00
|
|
|
status: profileAvailable
|
|
|
|
|
? i18n("%1% - %2", MobileShell.BatteryInfo.percent, profileLabel(GamingShell.PowerProfileControl.activeProfile))
|
|
|
|
|
: i18n("%1%", MobileShell.BatteryInfo.percent)
|
|
|
|
|
icon: profileAvailable ? profileIcon(GamingShell.PowerProfileControl.activeProfile)
|
|
|
|
|
: "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "")
|
|
|
|
|
enabled: profileAvailable && GamingShell.PowerProfileControl.activeProfile !== "balanced"
|
2022-03-13 21:47:42 +00:00
|
|
|
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
2026-05-09 08:00:36 +00:00
|
|
|
|
|
|
|
|
function profileLabel(profile) {
|
|
|
|
|
switch (profile) {
|
|
|
|
|
case "performance": return i18n("Performance")
|
|
|
|
|
case "balanced": return i18n("Balanced")
|
|
|
|
|
case "power-saver": return i18n("Power Saver")
|
|
|
|
|
default: return profile
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function profileIcon(profile) {
|
|
|
|
|
switch (profile) {
|
|
|
|
|
case "performance": return "speedometer"
|
|
|
|
|
case "power-saver": return "battery-profile-powersave"
|
|
|
|
|
default: return "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cycleProfile() {
|
|
|
|
|
let availableProfiles = []
|
|
|
|
|
for (let i = 0; i < profileOrder.length; ++i) {
|
|
|
|
|
let profile = profileOrder[i]
|
|
|
|
|
if (GamingShell.PowerProfileControl.profiles.indexOf(profile) >= 0) {
|
|
|
|
|
availableProfiles.push(profile)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (availableProfiles.length === 0) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let currentIndex = availableProfiles.indexOf(GamingShell.PowerProfileControl.activeProfile)
|
|
|
|
|
let nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % availableProfiles.length
|
|
|
|
|
GamingShell.PowerProfileControl.activeProfile = availableProfiles[nextIndex]
|
|
|
|
|
}
|
2022-03-13 21:47:42 +00:00
|
|
|
}
|