Libksysguard

ConfigAppearance.qml
1/*
2 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
4 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9import QtQuick
10import QtQuick.Layouts
11import QtQuick.Controls as QQC2
12
13import org.kde.kirigami as Kirigami
14import org.kde.kquickcontrols
15import org.kde.config
16import org.kde.newstuff as NewStuff
17
18import org.kde.quickcharts as Charts
19import org.kde.ksysguard.sensors as Sensors
20import org.kde.ksysguard.faces as Faces
21
22Kirigami.FormLayout {
23 id: root
24
25 signal configurationChanged
26
27 function saveConfig() {
28 controller.title = cfg_title;
29 controller.faceId = cfg_chartFace;
30 controller.showTitle = cfg_showTitle
31 controller.updateRateLimit = cfg_updateRateLimit
32
33 var preset = pendingPreset;
34 pendingPreset = "";
35 if (preset != "") {
36 controller.loadPreset(preset);
37 root.controller.highPrioritySensorColors = automaticColorSource.colors
38 }
39 }
40
41 property Faces.SensorFaceController controller
42 property alias cfg_title: titleField.text
43 property alias cfg_showTitle: showTitleCheckbox.checked
44 property string cfg_chartFace
45 property alias cfg_updateRateLimit: updateRateLimitSpinBox.value
46
47 onCfg_titleChanged: configurationChanged();
48 onCfg_showTitleChanged: configurationChanged()
49 onCfg_chartFaceChanged: configurationChanged();
50 onCfg_updateRateLimitChanged: configurationChanged();
51
52 // config keys of the selected preset to be applied on save
53 property string pendingPreset
54
55 Component.onCompleted: {
56 cfg_title = controller.title;
57 cfg_chartFace = controller.faceId;
58 cfg_showTitle = controller.showTitle
59 cfg_updateRateLimit = controller.updateRateLimit
60 }
61
62 Charts.ColorGradientSource {
63 id: automaticColorSource
64 baseColor: Kirigami.Theme.highlightColor
65 itemCount: root.controller.highPrioritySensorIds.length
66 }
67
68 Kirigami.Dialog {
69 id: presetDialog
70 modal: true
71
72 title: i18nd("KSysGuardSensorFaces", "Load Preset")
73
74 ListView {
75 implicitWidth: Kirigami.Units.gridUnit * 15
76 implicitHeight: Kirigami.Units.gridUnit * 20
77 focus: true
78 model: controller.availablePresetsModel
79 delegate: QQC2.ItemDelegate {
80 id: delegate
81 width: ListView.view.width
82
83 text: model.display
84
85 contentItem: RowLayout {
86 spacing: Kirigami.Units.smallSpacing
87
88 property bool truncated: label.truncated
89
90 QQC2.Label {
91 id: label
92 Layout.fillWidth: true
93 elide: Text.ElideRight
94 text: delegate.text
95 }
96
97 QQC2.ToolButton {
98 id: deleteButton
99 text: i18nd("KSysGuardSensorFaces", "Delete this preset")
100 icon.name: "delete"
101 visible: model.writable
102 onClicked: controller.uninstallPreset(model.pluginId);
103 display: QQC2.ToolButton.IconOnly
104
105 QQC2.ToolTip {
106 text: deleteButton.text
107 }
108 }
109 }
110
111 onClicked: {
112 cfg_title = model.display;
113 pendingPreset = model.pluginId;
114 if (model.config.chartFace) {
115 cfg_chartFace = model.config.chartFace;
116 }
117
118 root.configurationChanged();
119 presetDialog.close();
120 }
121 }
122 }
123 }
124 RowLayout {
125 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Presets:")
126
127 QQC2.Button {
128 icon.name: "document-open"
129 text: i18nd("KSysGuardSensorFaces", "Load Preset...")
130 onClicked: presetDialog.open()
131 }
132
133 NewStuff.Button {
134 Accessible.name: i18nd("KSysGuardSensorFaces", "Get new presets...")
135 configFile: "systemmonitor-presets.knsrc"
136 text: ""
137 onEntryEvent: controller.availablePresetsModel.reload();
138 QQC2.ToolTip {
139 text: parent.Accessible.name
140 }
141 }
142
143 QQC2.Button {
144 id: saveButton
145 icon.name: "document-save"
146 text: i18nd("KSysGuardSensorFaces", "Save Settings As Preset")
147 onClicked: controller.savePreset();
148 }
149 }
150
152 Kirigami.FormData.isSection: true
153 }
154
155 RowLayout {
156 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Title:")
157 QQC2.TextField {
158 id: titleField
159 }
160 QQC2.CheckBox {
161 id: showTitleCheckbox
162 text: i18nd("KSysGuardSensorFaces", "Show Title")
163 }
164 }
165
166 RowLayout {
167 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Display Style:")
168 QQC2.ComboBox {
169 id: faceCombo
170 model: controller.availableFacesModel
171 textRole: "display"
172 currentIndex: {
173 // TODO just make an indexOf invocable on the model?
174 for (var i = 0; i < count; ++i) {
175 if (model.pluginId(i) === cfg_chartFace) {
176 return i;
177 }
178 }
179 return -1;
180 }
181 onActivated: {
182 cfg_chartFace = model.pluginId(index);
183 }
184 }
185
186 NewStuff.Button {
187 text: i18nd("KSysGuardSensorFaces", "Get New Display Styles...")
188 configFile: "systemmonitor-faces.knsrc"
189 onEntryEvent: controller.availableFacesModel.reload();
190 }
191 }
192
193 QQC2.SpinBox {
194 id: updateRateLimitSpinBox
195 Layout.preferredWidth: titleField.implicitWidth
196
197 Kirigami.FormData.label: i18nd("KSysGuardSensorFaces", "Minimum Time Between Updates:")
198
199 from: 0
200 to: 600000
201 stepSize: 500
202 editable: true
203
204 textFromValue: function(value, locale) {
205 if (value <= 0) {
206 return i18nd("KSysGuardSensorFaces", "No Limit");
207 } else {
208 var seconds = value / 1000;
209 if (seconds == 1) { // Manual plural handling because i18ndp doesn't handle floats :(
210 return i18nd("KSysGuardSensorFaces", "1 second");
211 } else {
212 return i18nd("KSysGuardSensorFaces", "%1 seconds", seconds);
213 }
214 }
215 }
216 valueFromText: function(value, locale) {
217 // Don't use fromLocaleString here since it will error out on extra
218 // characters like the (potentially translated) seconds that gets
219 // added above. Instead parseInt ignores non-numeric characters.
220 var v = parseInt(value)
221 if (isNaN(v)) {
222 return 0;
223 } else {
224 return v * 1000;
225 }
226 }
227 }
228}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.