Libksysguard

ConfigSensors.qml
1 /*
2  * Copyright 2019 Marco Martin <[email protected]>
3  * Copyright 2019 David Edmundson <[email protected]>
4  * Copyright 2019 Arjen Hiemstra <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 import QtQuick 2.9
23 import QtQuick.Layouts 1.2
24 import QtQuick.Controls 2.2 as QQC2
25 import QtQml.Models 2.12
26 
27 import Qt.labs.platform 1.1 as Platform
28 
29 import org.kde.kirigami 2.8 as Kirigami
30 import org.kde.kquickcontrols 2.0
31 
32 import org.kde.kitemmodels 1.0 as KItemModels
33 
34 import org.kde.quickcharts 1.0 as Charts
35 import org.kde.ksysguard.sensors 1.0 as Sensors
36 import org.kde.ksysguard.faces 1.0 as Faces
37 
38 import "./" as Local
39 
40 ColumnLayout {
41  id: root
42 
43  signal configurationChanged
44 
45  property var cfg_totalSensors: []
46  property var cfg_highPrioritySensorIds: []
47  property var cfg_sensorColors: {}
48 
49  property var cfg_lowPrioritySensorIds: []
50 
51  onCfg_totalSensorsChanged: configurationChanged();
52  onCfg_highPrioritySensorIdsChanged: configurationChanged();
53  onCfg_sensorColorsChanged: configurationChanged();
54  onCfg_lowPrioritySensorIdsChanged: configurationChanged();
55 
56  property Faces.SensorFaceController controller
57 
58  function saveConfig() {
59  controller.totalSensors = cfg_totalSensors;
60  controller.highPrioritySensorIds = cfg_highPrioritySensorIds;
61  controller.sensorColors = cfg_sensorColors;
62  controller.lowPrioritySensorIds = cfg_lowPrioritySensorIds;
63  }
64 
65  function loadConfig() {
66  cfg_totalSensors = controller.totalSensors;
67  totalChoice.selected = controller.totalSensors;
68 
69  cfg_highPrioritySensorIds = controller.highPrioritySensorIds;
70  highPriorityChoice.selected = controller.highPrioritySensorIds;
71 
72  cfg_sensorColors = controller.sensorColors;
73 
74  cfg_lowPrioritySensorIds = controller.lowPrioritySensorIds;
75  lowPriorityChoice.selected = controller.lowPrioritySensorIds;
76  }
77 
78  // When the ui is open in systemsettings and the page is switched around,
79  // it gets reparented to null. use this to reload its config every time the
80  // page is current again. So any non saved change to the sensor list gets forgotten.
81  onParentChanged: {
82  if (parent) {
83  loadConfig()
84  }
85  }
86 
87  Component.onCompleted: loadConfig()
88 
89  Connections {
90  target: controller
91  function onTotalSensorsChanged() {
92  Qt.callLater(root.loadConfig);
93  }
94  function onHighPrioritySensorIdsChanged() {
95  Qt.callLater(root.loadConfig);
96  }
97  function onSensorColorsChanged() {
98  Qt.callLater(root.loadConfig);
99  }
100  function onLowPrioritySensorIdsChanged() {
101  Qt.callLater(root.loadConfig);
102  }
103  }
104 
105  Platform.ColorDialog {
106  id: colorDialog
107  property string destinationSensor
108 
109  currentColor: destinationSensor != "" ? controller.sensorColors[destinationSensor] : ""
110  onAccepted: {
111  cfg_sensorColors[destinationSensor] = color
112  root.cfg_sensorColorsChanged();
113  }
114  }
115 
116 
117  QQC2.Label {
118  text: i18ndp("KSysGuardSensorFaces", "Total Sensor", "Total Sensors", controller.maxTotalSensors)
119  visible: controller.supportsTotalSensors
120  }
121  Local.Choices {
122  id: totalChoice
123  Layout.fillWidth: true
124  visible: controller.supportsTotalSensors
125  supportsColors: false
126  maxAllowedSensors: controller.maxTotalSensors
127 
128  onSelectedChanged: root.cfg_totalSensors = selected
129  }
130 
131  QQC2.Label {
132  text: i18nd("KSysGuardSensorFaces", "Sensors")
133  }
134  Local.Choices {
135  id: highPriorityChoice
136  Layout.fillWidth: true
137  supportsColors: controller.supportsSensorsColors
138 
139  onSelectedChanged: root.cfg_highPrioritySensorIds = selected
140 
141  colors: root.cfg_sensorColors
142  onSelectColor: {
143  colorDialog.destinationSensor = sensorId
144  colorDialog.open()
145  }
146  onColorForSensorGenerated: {
147  cfg_sensorColors[sensorId] = color
148  root.cfg_sensorColorsChanged();
149  }
150  }
151 
152  QQC2.Label {
153  text: i18nd("KSysGuardSensorFaces", "Text-Only Sensors")
154  visible: controller.supportsLowPrioritySensors
155  }
156  Local.Choices {
157  id: lowPriorityChoice
158  Layout.fillWidth: true
159  visible: controller.supportsLowPrioritySensors
160  supportsColors: false
161 
162  onSelectedChanged: root.cfg_lowPrioritySensorIds = selected
163  }
164 
165  Item {
166  Layout.fillHeight: true
167  }
168 }
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...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 02:46:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.