Warning, /plasma/plasma-mobile/kcms/powermanagement/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2011 Sebastian Kügler <sebas@kde.org>
0003     SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org>
0004     SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0005     SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 import QtQuick 2.2
0011 import QtQuick.Controls 2.10 as QQC2
0012 import QtQuick.Layouts 1.11
0013 
0014 import org.kde.kirigami 2.10 as Kirigami
0015 import org.kde.plasma.components 3.0 as PlasmaComponents
0016 import org.kde.kcmutils
0017 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0018 import org.kde.kcm.power.mobile.private 1.0
0019 
0020 SimpleKCM {
0021     id: powermanagementModule
0022 
0023     leftPadding: 0
0024     rightPadding: 0
0025     topPadding: 0
0026     bottomPadding: Kirigami.Units.gridUnit
0027 
0028     ColumnLayout {
0029         width: parent.width
0030         spacing: 0
0031 
0032         FormCard.FormHeader {
0033             title: i18n("Devices")
0034         }
0035 
0036         FormCard.FormCard {
0037             Repeater {
0038                 model: kcm.batteries
0039 
0040                 delegate: FormCard.AbstractFormDelegate {
0041                     Layout.fillWidth: true
0042 
0043                     onClicked: kcm.push("BatteryPage.qml", { "battery": model.battery, "vendor": model.vendor, "product": model.product, "currentUdi": model.udi })
0044 
0045                     contentItem: RowLayout {
0046                         spacing: Kirigami.Units.gridUnit
0047 
0048                         Kirigami.Icon {
0049                             implicitWidth: Kirigami.Units.iconSizes.smallMedium
0050                             implicitHeight: Kirigami.Units.iconSizes.smallMedium
0051                             Layout.rightMargin: Kirigami.Units.largeSpacing
0052                             source: {
0053                                 switch (model.battery.type) {
0054                                     case 3: return model.battery.chargeState === 1 ? "battery-full-charging" : "battery-full"
0055                                     case 2: return "battery-ups"
0056                                     case 9: return "monitor"
0057                                     case 4: return "input-mouse"
0058                                     case 5: return "input-keyboard"
0059                                     case 1: return "phone"
0060                                     case 7: return "smartphone"
0061                                     default: return "paint-unknown"
0062                                 }
0063                             }
0064                         }
0065 
0066                         ColumnLayout {
0067                             Layout.fillWidth: true
0068                             spacing: Kirigami.Units.smallSpacing
0069 
0070                             QQC2.Label {
0071                                 Layout.fillWidth: true
0072                                 elide: Text.ElideRight
0073                                 wrapMode: Text.Wrap
0074                                 maximumLineCount: 2
0075                                 color: Kirigami.Theme.textColor
0076                                 text: {
0077                                     let batteryType;
0078                                     switch (model.battery.type) {
0079                                         case 3: batteryType = i18n("Internal battery"); break;
0080                                         case 2: batteryType = i18n("UPS battery"); break;
0081                                         case 9: batteryType = i18n("Monitor battery"); break;
0082                                         case 4: batteryType = i18n("Mouse battery"); break;
0083                                         case 5: batteryType = i18n("Keyboard battery"); break;
0084                                         case 1: batteryType = i18n("PDA battery"); break;
0085                                         case 7: batteryType = i18n("Phone battery"); break;
0086                                         default: batteryType = i18n("Unknown battery"); break;
0087                                     }
0088 
0089                                     const chargePercent = i18nc("%1 is the charge percent, % is the percent sign", "%1%", Number(battery.chargePercent).toLocaleString(Qt.locale(), "f", 0));
0090 
0091                                     return (model.battery.chargeState === Battery.Charging) ? i18nc("%1 is battery type, %2 is charge percent", "%1 %2 (Charging)", batteryType, chargePercent) : i18nc("%1 is battery type, %2 is charge percent", "%1 %2", batteryType, chargePercent);
0092                                 }
0093                             }
0094 
0095                             QQC2.ProgressBar {
0096                                 Layout.fillWidth: true
0097                                 from: 0
0098                                 to: 100
0099                                 value: model.battery.chargePercent
0100                             }
0101                         }
0102 
0103                         Kirigami.Icon {
0104                             Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
0105                             source: "arrow-right"
0106                             implicitWidth: Math.round(Kirigami.Units.iconSizes.small * 0.75)
0107                             implicitHeight: Math.round(Kirigami.Units.iconSizes.small * 0.75)
0108                         }
0109                     }
0110                 }
0111             }
0112         }
0113 
0114         FormCard.FormHeader {
0115             title: i18n("Screen")
0116         }
0117 
0118         FormCard.FormCard {
0119             FormCard.FormComboBoxDelegate {
0120                 id: dimScreenCombo
0121                 text: i18nc("Part of a sentence like 'Dim screen after 5 minutes'", "Dim screen after")
0122                 model: kcm.timeOptions()
0123                 currentIndex: kcm.dimScreenIdx
0124                 Component.onCompleted: dialog.parent = powermanagementModule
0125                 onCurrentIndexChanged: kcm.dimScreenIdx = currentIndex
0126             }
0127 
0128             FormCard.FormDelegateSeparator { above: dimScreenCombo; below: screenOffCombo }
0129 
0130             FormCard.FormComboBoxDelegate {
0131                 id: screenOffCombo
0132                 text: i18nc("Part of a sentence like 'Turn off screen after 5 minutes'", "Turn off screen after")
0133                 model: kcm.timeOptions()
0134                 currentIndex: kcm.screenOffIdx
0135                 Component.onCompleted: dialog.parent = powermanagementModule
0136                 onCurrentIndexChanged: kcm.screenOffIdx = currentIndex
0137             }
0138 
0139             FormCard.FormDelegateSeparator { above: screenOffCombo; below: suspendCombo }
0140 
0141             FormCard.FormComboBoxDelegate {
0142                 id: suspendCombo
0143                 text: i18nc("Part of a sentence like 'Suspend device after 5 minutes'", "Suspend device after")
0144                 model: kcm.timeOptions()
0145                 currentIndex: kcm.suspendSessionIdx
0146                 Component.onCompleted: dialog.parent = powermanagementModule
0147                 onCurrentIndexChanged: kcm.suspendSessionIdx = currentIndex
0148             }
0149         }
0150     }
0151 }