Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/package/contents/ui/main.qml
Show All 31 Lines | |||||
32 | 32 | | |||
33 | KCM.SimpleKCM { | 33 | KCM.SimpleKCM { | ||
34 | id: root | 34 | id: root | ||
35 | 35 | | |||
36 | KCM.ConfigModule.quickHelp: i18n("This module lets you see energy information and statistics.") | 36 | KCM.ConfigModule.quickHelp: i18n("This module lets you see energy information and statistics.") | ||
37 | 37 | | |||
38 | property QtObject currentBattery: null | 38 | property QtObject currentBattery: null | ||
39 | property string currentUdi: "" | 39 | property string currentUdi: "" | ||
40 | property string currentVendor: "" | ||||
41 | property string currentProduct: "" | ||||
40 | property bool compact: (root.width / units.gridUnit) < 25 | 42 | property bool compact: (root.width / units.gridUnit) < 25 | ||
41 | 43 | | |||
42 | onCurrentBatteryChanged: { | 44 | onCurrentBatteryChanged: { | ||
43 | if (!currentBattery) { | 45 | if (!currentBattery) { | ||
44 | currentBattery = kcm.batteries.get(0) | 46 | currentBattery = kcm.batteries.battery(0) | ||
47 | currentVendor = kcm.batteries.vendor(0) | ||||
48 | currentProduct = kcm.batteries.product(0) | ||||
45 | currentUdi = kcm.batteries.udi(0) | 49 | currentUdi = kcm.batteries.udi(0) | ||
46 | } | 50 | } | ||
47 | } | 51 | } | ||
48 | 52 | | |||
49 | property bool showWakeUps: true | 53 | property bool showWakeUps: true | ||
50 | property int historyType: HistoryModel.ChargeType | 54 | property int historyType: HistoryModel.ChargeType | ||
51 | 55 | | |||
52 | readonly property var details: [ | 56 | readonly property var details: [ | ||
53 | { | 57 | { | ||
54 | title: i18n("Battery"), | 58 | title: i18n("Battery"), | ||
55 | data: [ | 59 | data: [ | ||
56 | {label: i18n("Rechargeable"), value: "rechargeable"}, | 60 | {label: i18n("Rechargeable"), value: "rechargeable"}, | ||
57 | {label: i18n("Charge state"), value: "chargeState", modifier: "chargeState"}, | 61 | {label: i18n("Charge state"), value: "chargeState", modifier: "chargeState"}, | ||
58 | {label: i18n("Capacity degradation"), value: "capacity", unit: i18n("%"), precision: 0} | 62 | {label: i18n("Current charge"), value: "chargePercent", unit: i18n("%"), precision: 0}, | ||
63 | {label: i18n("Capacity degradation"), value: "capacity", unit: i18n("%"), precision: 0}, | ||||
64 | {label: i18n("Vendor"), value: "vendor", source:"Vendor"}, | ||||
65 | {label: i18n("Model"), value: "model", source:"Product"}, | ||||
66 | {label: i18n("Serial Number"), value: "serial"} | ||||
59 | ] | 67 | ] | ||
60 | }, | 68 | }, | ||
61 | { | 69 | { | ||
62 | title: i18n("Energy"), | 70 | title: i18n("Energy"), | ||
63 | data: [ | 71 | data: [ | ||
64 | {label: i18nc("current power draw from the battery in W", "Consumption"), value: "energyRate", unit: i18nc("Watt", "W"), precision: 2}, | 72 | {label: i18nc("current power draw from the battery in W", "Consumption"), value: "energyRate", unit: i18nc("Watt", "W"), precision: 2}, | ||
65 | {label: i18n("Voltage"), value: "voltage", unit: i18nc("Volt", "V"), precision: 2}, | 73 | {label: i18n("Voltage"), value: "voltage", unit: i18nc("Volt", "V"), precision: 2}, | ||
66 | {label: i18n("Remaining energy"), value: "energy", unit: i18nc("Watt-hours", "Wh"), precision: 2}, | 74 | {label: i18n("Remaining energy"), value: "energy", unit: i18nc("Watt-hours", "Wh"), precision: 2}, | ||
67 | {label: i18n("Last full charge"), value: "energyFull", unit: i18nc("Watt-hours", "Wh"), precision: 2}, | 75 | {label: i18n("Last full charge"), value: "energyFull", unit: i18nc("Watt-hours", "Wh"), precision: 2}, | ||
68 | {label: i18n("Original charge capacity"), value: "energyFullDesign", unit: i18nc("Watt-hours", "Wh"), precision: 2} | 76 | {label: i18n("Original charge capacity"), value: "energyFullDesign", unit: i18nc("Watt-hours", "Wh"), precision: 2} | ||
69 | ] | 77 | ] | ||
70 | }, | 78 | }, | ||
71 | { | 79 | { | ||
72 | title: i18n("Environment"), | 80 | title: i18n("Environment"), | ||
73 | data: [ | 81 | data: [ | ||
74 | {label: i18n("Temperature"), value: "temperature", unit: i18nc("Degree Celsius", "°C"), precision: 2} | 82 | {label: i18n("Temperature"), value: "temperature", unit: i18nc("Degree Celsius", "°C"), precision: 2} | ||
75 | ] | 83 | ] | ||
76 | }, | 84 | }, | ||
77 | { | | |||
78 | title: i18n("Manufacturer"), | | |||
79 | data: [ | | |||
80 | {label: i18n("Vendor"), value: "vendor"}, | | |||
81 | {label: i18n("Model"), value: "model"}, | | |||
82 | {label: i18n("Serial Number"), value: "serial"} | | |||
83 | ] | | |||
84 | } | | |||
85 | ] | 85 | ] | ||
86 | 86 | | |||
87 | function modifier_chargeState(value) { | 87 | function modifier_chargeState(value) { | ||
88 | switch(value) { | 88 | switch(value) { | ||
89 | case 0: return i18n("Not charging") | 89 | case 0: return i18n("Not charging") | ||
90 | case 1: return i18n("Charging") | 90 | case 1: return i18n("Charging") | ||
91 | case 2: return i18n("Discharging") | 91 | case 2: return i18n("Discharging") | ||
92 | case 3: return i18n("Fully charged") | 92 | case 3: return i18n("Fully charged") | ||
93 | } | 93 | } | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | Component.onCompleted: { | 96 | Component.onCompleted: { | ||
97 | currentBattery = kcm.batteries.get(0) | 97 | currentBattery = kcm.batteries.get(0) | ||
98 | currentVendor = kcm.batteries.vendor(0) | ||||
99 | currentProduct = kcm.batteries.product(0) | ||||
98 | currentUdi = kcm.batteries.udi(0) | 100 | currentUdi = kcm.batteries.udi(0) | ||
99 | } | 101 | } | ||
100 | 102 | | |||
101 | implicitWidth: units.gridUnit * 30 | 103 | implicitWidth: units.gridUnit * 30 | ||
102 | implicitHeight: !!currentBattery ? units.gridUnit * 30 : units.gridUnit * 12 | 104 | implicitHeight: !!currentBattery ? units.gridUnit * 30 : units.gridUnit * 12 | ||
103 | 105 | | |||
104 | readonly property var timespanComboChoices: [i18n("Last hour"),i18n("Last 2 hours"),i18n("Last 12 hours"),i18n("Last 24 hours"),i18n("Last 48 hours"), i18n("Last 7 days")] | 106 | readonly property var timespanComboChoices: [i18n("Last hour"),i18n("Last 2 hours"),i18n("Last 12 hours"),i18n("Last 24 hours"),i18n("Last 48 hours"), i18n("Last 7 days")] | ||
105 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | 107 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | ||
Show All 15 Lines | 120 | Repeater { | |||
121 | QQC2.Button { | 123 | QQC2.Button { | ||
122 | id: button | 124 | id: button | ||
123 | width: height | 125 | width: height | ||
124 | height: tabView.height | 126 | height: tabView.height | ||
125 | checked: model.battery == root.currentBattery | 127 | checked: model.battery == root.currentBattery | ||
126 | checkable: true | 128 | checkable: true | ||
127 | onClicked: { | 129 | onClicked: { | ||
128 | root.currentUdi = model.udi | 130 | root.currentUdi = model.udi | ||
131 | root.currentVendor = model.vendor | ||||
132 | root.currentProduct = model.product | ||||
129 | root.currentBattery = model.battery | 133 | root.currentBattery = model.battery | ||
134 | | ||||
130 | // override checked property | 135 | // override checked property | ||
131 | checked = Qt.binding(function() { | 136 | checked = Qt.binding(function() { | ||
132 | return model.battery == root.currentBattery | 137 | return model.battery == root.currentBattery | ||
133 | }) | 138 | }) | ||
134 | 139 | | |||
135 | showWakeUps = (index === 0) | 140 | showWakeUps = (index === 0) | ||
136 | } | 141 | } | ||
137 | 142 | | |||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Line(s) | 394 | delegate: Kirigami.FormLayout { | |||
417 | Repeater { | 422 | Repeater { | ||
418 | id: detailsRepeater | 423 | id: detailsRepeater | ||
419 | model: modelData.data || [] | 424 | model: modelData.data || [] | ||
420 | 425 | | |||
421 | QQC2.Label { | 426 | QQC2.Label { | ||
422 | id: valueLabel | 427 | id: valueLabel | ||
423 | Kirigami.FormData.label: i18n("%1:", modelData.label) | 428 | Kirigami.FormData.label: i18n("%1:", modelData.label) | ||
424 | text: { | 429 | text: { | ||
425 | var value = currentBattery[modelData.value] | 430 | var value; | ||
431 | if (modelData.source) { | ||||
432 | value = root["current" + modelData.source]; | ||||
broulik: Can you make this more generic, e.g.
```
value = root["current" + uppercasefirst(modelData. | |||||
meven: Nice suggestion :) | |||||
433 | } else { | ||||
434 | value = currentBattery[modelData.value] | ||||
435 | } | ||||
426 | 436 | | |||
427 | // There's no "degradation" value we can look up, so | 437 | // There's no "degradation" value we can look up, so | ||
428 | // instead, process the capacity value to produce it | 438 | // instead, process the capacity value to produce it | ||
429 | if (modelData.value == "capacity") { | 439 | if (modelData.value == "capacity") { | ||
430 | value = 100 - value | 440 | value = 100 - value | ||
431 | } | 441 | } | ||
432 | 442 | | |||
433 | if (typeof value === "boolean") { | 443 | if (typeof value === "boolean") { | ||
Show All 34 Lines |
Can you make this more generic, e.g.