Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/package/contents/ui/main.qml
Show All 35 Lines | 33 | KCM.SimpleKCM { | |||
---|---|---|---|---|---|
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: "" | 40 | property string currentVendor: "" | ||
41 | property string currentProduct: "" | 41 | property string currentProduct: "" | ||
42 | property bool compact: (root.width / units.gridUnit) < 25 | 42 | property bool compact: (root.width / units.gridUnit) < 25 | ||
43 | 43 | | |||
44 | function initCurrentBattery() { | ||||
45 | currentBattery = kcm.batteries.data(kcm.batteries.index(0, 0), BatteryModel.BatteryRole) | ||||
46 | currentVendor = kcm.batteries.data(kcm.batteries.index(0, 0), BatteryModel.VendorRole) | ||||
47 | currentProduct = kcm.batteries.data(kcm.batteries.index(0, 0), BatteryModel.ProductRole) | ||||
48 | currentUdi = kcm.batteries.data(kcm.batteries.index(0, 0), BatteryModel.UdiRole) | ||||
49 | } | ||||
50 | | ||||
51 | Component.onCompleted: initCurrentBattery() | ||||
52 | | ||||
44 | onCurrentBatteryChanged: { | 53 | onCurrentBatteryChanged: { | ||
45 | if (!currentBattery) { | 54 | if (!currentBattery) { | ||
46 | currentBattery = kcm.batteries.battery(0) | 55 | initCurrentBattery() | ||
47 | currentVendor = kcm.batteries.vendor(0) | | |||
48 | currentProduct = kcm.batteries.product(0) | | |||
49 | currentUdi = kcm.batteries.udi(0) | | |||
50 | } | 56 | } | ||
51 | } | 57 | } | ||
52 | 58 | | |||
53 | property bool showWakeUps: true | 59 | property bool showWakeUps: true | ||
54 | property int historyType: HistoryModel.ChargeType | 60 | property int historyType: HistoryModel.ChargeType | ||
55 | 61 | | |||
56 | readonly property var details: [ | 62 | readonly property var details: [ | ||
57 | { | 63 | { | ||
Show All 29 Lines | |||||
87 | function modifier_chargeState(value) { | 93 | function modifier_chargeState(value) { | ||
88 | switch(value) { | 94 | switch(value) { | ||
89 | case 0: return i18n("Not charging") | 95 | case 0: return i18n("Not charging") | ||
90 | case 1: return i18n("Charging") | 96 | case 1: return i18n("Charging") | ||
91 | case 2: return i18n("Discharging") | 97 | case 2: return i18n("Discharging") | ||
92 | case 3: return i18n("Fully charged") | 98 | case 3: return i18n("Fully charged") | ||
93 | } | 99 | } | ||
94 | } | 100 | } | ||
95 | 101 | | |||
96 | Component.onCompleted: { | | |||
97 | currentBattery = kcm.batteries.get(0) | | |||
98 | currentVendor = kcm.batteries.vendor(0) | | |||
99 | currentProduct = kcm.batteries.product(0) | | |||
100 | currentUdi = kcm.batteries.udi(0) | | |||
101 | } | | |||
102 | | ||||
103 | implicitWidth: units.gridUnit * 30 | 102 | implicitWidth: units.gridUnit * 30 | ||
broulik: You could probably move that into a `function initCurrent()` or similar and call it in both… | |||||
104 | implicitHeight: !!currentBattery ? units.gridUnit * 30 : units.gridUnit * 12 | 103 | implicitHeight: !!currentBattery ? units.gridUnit * 30 : units.gridUnit * 12 | ||
105 | 104 | | |||
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 timespanComboChoices: [i18n("Last hour"),i18n("Last 2 hours"),i18n("Last 12 hours"),i18n("Last 24 hours"),i18n("Last 48 hours"), i18n("Last 7 days")] | ||
107 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | 106 | readonly property var timespanComboDurations: [3600, 7200, 43200, 86400, 172800, 604800] | ||
108 | 107 | | |||
109 | ColumnLayout { | 108 | ColumnLayout { | ||
110 | id: column | 109 | id: column | ||
111 | QQC2.ScrollView { | 110 | QQC2.ScrollView { | ||
▲ Show 20 Lines • Show All 360 Lines • Show Last 20 Lines |
You could probably move that into a function initCurrent() or similar and call it in both this and the change handler
You can also probably cache the index in a variable to only query it once