11import QtQuick.Controls as QQC2
14import Qt.labs.platform as Platform
16import org.kde.kirigami as Kirigami
17import org.kde.kquickcontrols
19import org.kde.kitemmodels as KItemModels
21import org.kde.quickcharts as Charts
22import org.kde.ksysguard.sensors as Sensors
23import org.kde.ksysguard.faces as Faces
30 signal configurationChanged
32 property var cfg_totalSensors: []
33 property var cfg_highPrioritySensorIds: []
34 property var cfg_sensorColors:
new Object()
35 property var cfg_lowPrioritySensorIds: []
36 property var cfg_sensorLabels: new Object()
38 onCfg_totalSensorsChanged: configurationChanged();
39 onCfg_highPrioritySensorIdsChanged: configurationChanged();
40 onCfg_sensorColorsChanged: configurationChanged();
41 onCfg_lowPrioritySensorIdsChanged: configurationChanged();
42 onCfg_sensorLabelsChanged: configurationChanged();
44 property Faces.SensorFaceController controller
49 function arrayCompare(array1, array2) {
50 if (array1.length !== array2.length) {
53 return array1.every(function(value, index) {
return value === array2[index]});
56 function saveConfig() {
57 controller.totalSensors = cfg_totalSensors;
58 controller.highPrioritySensorIds = cfg_highPrioritySensorIds;
59 controller.sensorColors = cfg_sensorColors;
60 controller.lowPrioritySensorIds = cfg_lowPrioritySensorIds;
61 controller.sensorLabels = cfg_sensorLabels;
64 function loadConfig() {
65 if (!arrayCompare(cfg_totalSensors, controller.totalSensors)) {
66 cfg_totalSensors = controller.totalSensors;
67 totalChoice.selected = controller.totalSensors;
70 if (!arrayCompare(cfg_highPrioritySensorIds, controller.highPrioritySensorIds)) {
71 cfg_highPrioritySensorIds = controller.highPrioritySensorIds;
72 highPriorityChoice.selected = controller.highPrioritySensorIds;
75 if(JSON.stringify(cfg_sensorColors) != JSON.stringify(controller.sensorColors)) {
76 cfg_sensorColors = controller.sensorColors;
79 if (!arrayCompare(cfg_lowPrioritySensorIds, controller.lowPrioritySensorIds)) {
80 cfg_lowPrioritySensorIds = controller.lowPrioritySensorIds;
81 lowPriorityChoice.selected = controller.lowPrioritySensorIds;
83 if(JSON.stringify(cfg_sensorLabels) != JSON.stringify(controller.sensorLabels)) {
84 cfg_sensorLabels = controller.sensorLabels;
97 Component.onCompleted: loadConfig()
101 function onTotalSensorsChanged() {
102 Qt.callLater(root.loadConfig);
104 function onHighPrioritySensorIdsChanged() {
105 Qt.callLater(root.loadConfig);
107 function onSensorColorsChanged() {
108 Qt.callLater(root.loadConfig);
110 function onLowPrioritySensorIdsChanged() {
111 Qt.callLater(root.loadConfig);
113 function onSensorLabelsChanged() {
114 Qt.callLater(root.loadConfig);
118 Platform.ColorDialog {
120 property string destinationSensor
122 currentColor: destinationSensor !=
"" ? controller.sensorColors[destinationSensor] :
""
124 cfg_sensorColors[destinationSensor] =
Qt.rgba(color.r, color.g, color.b, color.a);
125 root.cfg_sensorColorsChanged();
131 text:
i18ndp(
"KSysGuardSensorFaces",
"Total Sensor",
"Total Sensors", controller.maxTotalSensors)
132 visible: controller.supportsTotalSensors
136 Layout.fillWidth:
true
137 visible: controller.supportsTotalSensors
138 supportsColors:
false
139 maxAllowedSensors: controller.maxTotalSensors
140 labels: root.cfg_sensorLabels
142 onSelectedChanged: root.cfg_totalSensors = selected
143 onSensorLabelChanged: (sensorId,
label) => {
144 cfg_sensorLabels[sensorId] =
label
145 root.cfg_sensorLabelsChanged()
150 text:
i18nd(
"KSysGuardSensorFaces",
"Sensors")
153 id: highPriorityChoice
154 Layout.fillWidth:
true
155 supportsColors: controller.supportsSensorsColors
156 labels: root.cfg_sensorLabels
158 onSelectedChanged: root.cfg_highPrioritySensorIds = selected
160 colors: root.cfg_sensorColors
161 onSelectColor: sensorId => {
162 colorDialog.destinationSensor = sensorId
165 onColorForSensorGenerated: (sensorId, color) => {
166 cfg_sensorColors[sensorId] = color
167 root.cfg_sensorColorsChanged();
169 onSensorLabelChanged: (sensorId,
label) => {
170 cfg_sensorLabels[sensorId] =
label
171 root.cfg_sensorLabelsChanged()
176 text:
i18nd(
"KSysGuardSensorFaces",
"Text-Only Sensors")
177 visible: controller.supportsLowPrioritySensors
180 id: lowPriorityChoice
181 Layout.fillWidth:
true
182 visible: controller.supportsLowPrioritySensors
183 supportsColors:
false
184 labels: root.cfg_sensorLabels
186 onSelectedChanged: root.cfg_lowPrioritySensorIds = selected
187 onSensorLabelChanged: (sensorId,
label) => {
188 cfg_sensorLabels[sensorId] =
label
189 root.cfg_sensorLabelsChanged()
194 Layout.fillHeight:
true
QString i18ndp(const char *domain, const char *singular, const char *plural, const TYPE &arg...)
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)