2023-03-14 01:45:47 +00:00
/ *
SPDX - FileCopyrightText: 2011 Sebastian Kügler < sebas @ kde . org >
SPDX - FileCopyrightText: 2012 Marco Martin < mart @ kde . org >
SPDX - FileCopyrightText: 2015 Kai Uwe Broulik < kde @ privat . broulik . de >
SPDX - FileCopyrightText: 2022 Devin Lin < devin @ kde . org >
SPDX - License - Identifier: LGPL - 2.0 - or - later
* /
import QtQuick 2.2
import QtQuick . Controls 2.10 as QQC2
import QtQuick . Layouts 1.11
import org . kde . kirigami 2.10 as Kirigami
2023-03-14 23:50:53 +00:00
import org . kde . plasma . components 3.0 as PlasmaComponents
2023-06-06 19:31:58 +00:00
import org . kde . kcmutils
2023-09-21 19:08:02 +00:00
import org . kde . kirigamiaddons . formcard 1.0 as FormCard
2023-03-14 01:45:47 +00:00
import org . kde . kcm . power . mobile . private 1.0
SimpleKCM {
id: powermanagementModule
2023-09-21 19:08:02 +00:00
2023-03-14 01:45:47 +00:00
leftPadding: 0
rightPadding: 0
2023-09-21 19:08:02 +00:00
topPadding: 0
2023-03-14 01:45:47 +00:00
bottomPadding: Kirigami . Units . gridUnit
ColumnLayout {
width: parent . width
spacing: 0
2023-09-21 19:08:02 +00:00
FormCard . FormHeader {
title: i18n ( "Devices" )
}
FormCard . FormCard {
Repeater {
model: kcm . batteries
delegate: FormCard . AbstractFormDelegate {
Layout.fillWidth: true
onClicked: kcm . push ( "BatteryPage.qml" , { "battery" : model . battery , "vendor" : model . vendor , "product" : model . product , "currentUdi" : model . udi } )
contentItem: RowLayout {
spacing: Kirigami . Units . gridUnit
Kirigami . Icon {
implicitWidth: Kirigami . Units . iconSizes . smallMedium
implicitHeight: Kirigami . Units . iconSizes . smallMedium
2023-11-08 17:57:27 +00:00
Layout.rightMargin: Kirigami . Units . largeSpacing
2023-09-21 19:08:02 +00:00
source: {
switch ( model . battery . type ) {
case 3 : return model . battery . chargeState === 1 ? "battery-full-charging" : "battery-full"
case 2 : return "battery-ups"
case 9 : return "monitor"
case 4 : return "input-mouse"
case 5 : return "input-keyboard"
case 1 : return "phone"
case 7 : return "smartphone"
default: return "paint-unknown"
2023-03-14 01:45:47 +00:00
}
}
2023-09-21 19:08:02 +00:00
}
ColumnLayout {
Layout.fillWidth: true
spacing: Kirigami . Units . smallSpacing
QQC2 . Label {
2023-03-14 01:45:47 +00:00
Layout.fillWidth: true
2023-09-21 19:08:02 +00:00
elide: Text . ElideRight
wrapMode: Text . Wrap
maximumLineCount: 2
color: Kirigami . Theme . textColor
text: {
let batteryType ;
switch ( model . battery . type ) {
case 3 : batteryType = i18n ( "Internal battery" ) ; break ;
case 2 : batteryType = i18n ( "UPS battery" ) ; break ;
case 9 : batteryType = i18n ( "Monitor battery" ) ; break ;
case 4 : batteryType = i18n ( "Mouse battery" ) ; break ;
case 5 : batteryType = i18n ( "Keyboard battery" ) ; break ;
case 1 : batteryType = i18n ( "PDA battery" ) ; break ;
case 7 : batteryType = i18n ( "Phone battery" ) ; break ;
default: batteryType = i18n ( "Unknown battery" ) ; break ;
2023-03-14 01:45:47 +00:00
}
2023-09-21 19:08:02 +00:00
2024-01-03 13:01:38 +00:00
const chargePercent = i18nc ( "%1 is the charge percent, % is the percent sign" , "%1%" , Number ( battery . chargePercent ) . toLocaleString ( Qt . locale ( ) , "f" , 0 ) ) ;
2023-09-21 19:08:02 +00:00
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 ) ;
2023-03-14 01:45:47 +00:00
}
}
2023-09-21 19:08:02 +00:00
QQC2 . ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: model . battery . chargePercent
2023-03-14 01:45:47 +00:00
}
}
2023-09-21 19:08:02 +00:00
Kirigami . Icon {
Layout.alignment: Qt . AlignRight | Qt . AlignVCenter
source: "arrow-right"
implicitWidth: Math . round ( Kirigami . Units . iconSizes . small * 0.75 )
implicitHeight: Math . round ( Kirigami . Units . iconSizes . small * 0.75 )
}
2023-03-14 01:45:47 +00:00
}
}
}
}
2023-09-21 19:08:02 +00:00
FormCard . FormHeader {
title: i18n ( "Screen" )
}
2023-03-14 01:45:47 +00:00
2023-09-21 19:08:02 +00:00
FormCard . FormCard {
FormCard . FormComboBoxDelegate {
id: dimScreenCombo
text: i18nc ( "Part of a sentence like 'Dim screen after 5 minutes'" , "Dim screen after" )
model: kcm . timeOptions ( )
currentIndex: kcm . dimScreenIdx
Component.onCompleted: dialog . parent = powermanagementModule
onCurrentIndexChanged: kcm . dimScreenIdx = currentIndex
}
2023-03-14 01:45:47 +00:00
2023-09-21 19:08:02 +00:00
FormCard . FormDelegateSeparator { above: dimScreenCombo ; below: screenOffCombo }
2023-03-14 01:45:47 +00:00
2023-09-21 19:08:02 +00:00
FormCard . FormComboBoxDelegate {
id: screenOffCombo
text: i18nc ( "Part of a sentence like 'Turn off screen after 5 minutes'" , "Turn off screen after" )
model: kcm . timeOptions ( )
currentIndex: kcm . screenOffIdx
Component.onCompleted: dialog . parent = powermanagementModule
onCurrentIndexChanged: kcm . screenOffIdx = currentIndex
}
2023-03-14 01:45:47 +00:00
2023-09-21 19:08:02 +00:00
FormCard . FormDelegateSeparator { above: screenOffCombo ; below: suspendCombo }
2023-03-14 01:45:47 +00:00
2023-09-21 19:08:02 +00:00
FormCard . FormComboBoxDelegate {
id: suspendCombo
text: i18nc ( "Part of a sentence like 'Suspend device after 5 minutes'" , "Suspend device after" )
model: kcm . timeOptions ( )
currentIndex: kcm . suspendSessionIdx
Component.onCompleted: dialog . parent = powermanagementModule
onCurrentIndexChanged: kcm . suspendSessionIdx = currentIndex
2023-03-14 01:45:47 +00:00
}
}
}
}