2
0

KCM.qml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. import QtQuick 2.4
  20. import QtQuick.Controls 1.3
  21. import QtQuick.Layouts 1.1
  22. import QtQuick.Dialogs 1.2
  23. import org.kde.kcm 1.0
  24. import "../scripts/arrayfunctions.js" as ArrayFunctions
  25. import "../scripts/units.js" as Units
  26. Item {
  27. property QtObject base: kcm.base
  28. property var locale: Qt.locale()
  29. property real textWidth: 0
  30. id: root
  31. implicitWidth: 1024
  32. implicitHeight: 768
  33. ColumnLayout {
  34. id: noFansInfo
  35. width: parent.width
  36. anchors.verticalCenter: parent.verticalCenter
  37. spacing: 20
  38. visible: kcm.loader.allPwmFans.length == 0
  39. Label {
  40. Layout.alignment: Qt.AlignCenter
  41. text: i18n("There are no pwm capable fans in your system.")
  42. font.pointSize: 14
  43. font.bold: true
  44. }
  45. Button {
  46. Layout.alignment: Qt.AlignCenter
  47. text: i18n("Detect fans")
  48. iconName: kcm.needsAuthorization ? "dialog-password" : ""
  49. onClicked: kcm.loader.detectSensors()
  50. }
  51. }
  52. CheckBox {
  53. id: enabledBox
  54. visible: kcm.loader.allPwmFans.length > 0
  55. Layout.alignment: Qt.AlignLeft | Qt.AlignTop
  56. text: i18n("Control fans manually")
  57. checked: kcm.manualControl
  58. onCheckedChanged: kcm.manualControl = checked
  59. Connections {
  60. target: kcm
  61. onManualControlChanged: enabledBox.checked = kcm.manualControl
  62. }
  63. }
  64. ColumnLayout {
  65. width: parent.width
  66. anchors.bottom: parent.bottom
  67. anchors.top: enabledBox.bottom
  68. visible: enabledBox.checked
  69. RowLayout {
  70. visible: enabledBox.checked && kcm.loader.allPwmFans.length > 0
  71. Label {
  72. text: i18n("Fan:")
  73. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  74. renderType: Text.NativeRendering
  75. }
  76. ComboBox {
  77. id: fanComboBox
  78. model: ListModel { //ListModel because array of names would reset currentIndex to 0 if a name changes
  79. property var fans: kcm.loader.allPwmFans
  80. id: fanList
  81. Component.onCompleted: {
  82. for (var i=0; i<fans.length; i++) {
  83. fanList.append({"text": ArrayFunctions.nameWithPath(fans[i])});
  84. }
  85. }
  86. }
  87. Layout.fillWidth: true
  88. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  89. }
  90. Button {
  91. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  92. text: i18n("Detect fans")
  93. iconName: kcm.needsAuthorization ? "dialog-password" : ""
  94. onClicked: kcm.loader.detectSensors()
  95. }
  96. }
  97. Loader {
  98. Layout.fillWidth: true
  99. Layout.fillHeight: true
  100. active: !!kcm.loader.allPwmFans[fanComboBox.currentIndex]
  101. sourceComponent: PwmFan {
  102. unit: kcm.base.unit
  103. fan: kcm.loader.allPwmFans[fanComboBox.currentIndex]
  104. loader: kcm.loader
  105. systemdCom: kcm.systemdCom
  106. minTemp: kcm.base.minTemp
  107. maxTemp: kcm.base.maxTemp
  108. onNameChanged: {
  109. if (fanComboBox.currentText != ArrayFunctions.nameWithPath(fan)) {
  110. fanList.setProperty(fanComboBox.currentIndex, "text", ArrayFunctions.nameWithPath(fan));
  111. }
  112. }
  113. }
  114. }
  115. Row {
  116. property bool expanded: false
  117. id: expand
  118. Image {
  119. id: arrow
  120. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  121. fillMode: Image.PreserveAspectFit
  122. height: advancedLabel.implicitHeight
  123. }
  124. Label {
  125. id: advancedLabel
  126. text: i18n("Advanced settings")
  127. font.bold: true
  128. }
  129. }
  130. MouseArea {
  131. anchors.fill: expand
  132. onClicked: expand.expanded = expand.expanded ? false : true
  133. }
  134. RowLayout {
  135. visible: expand.expanded
  136. Label {
  137. Layout.preferredWidth: root.textWidth
  138. clip: true
  139. text: i18n("Interval:")
  140. horizontalAlignment: Text.AlignRight
  141. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  142. }
  143. SpinBox {
  144. Layout.minimumWidth: implicitWidth
  145. Layout.fillWidth: true
  146. value: base.loader ? base.loader.interval : 1
  147. suffix: " " + (value > 1 ? i18n("seconds") : i18n("second"))
  148. minimumValue: 1.0
  149. onValueChanged: base.loader.interval = value
  150. }
  151. }
  152. RowLayout {
  153. visible: expand.expanded
  154. Label {
  155. Layout.preferredWidth: root.textWidth
  156. clip: true
  157. text: i18n("Minimum temperature for fan graphs:")
  158. horizontalAlignment: Text.AlignRight
  159. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  160. }
  161. SpinBox {
  162. id: minTempBox
  163. Layout.minimumWidth: implicitWidth
  164. Layout.fillWidth: true
  165. decimals: 2
  166. maximumValue: maxTempBox.value
  167. minimumValue: Units.fromKelvin(0, base.unit)
  168. value: Units.fromCelsius(base.minTemp, base.unit)
  169. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  170. onValueChanged: base.minTemp = value
  171. }
  172. }
  173. RowLayout {
  174. visible: expand.expanded
  175. Label {
  176. Layout.preferredWidth: root.textWidth
  177. clip: true
  178. text: i18n("Maximum temperature for fan graphs:")
  179. horizontalAlignment: Text.AlignRight
  180. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  181. }
  182. SpinBox {
  183. id: maxTempBox
  184. Layout.minimumWidth: implicitWidth
  185. Layout.fillWidth: true
  186. decimals: 2
  187. maximumValue: Number.POSITIVE_INFINITY
  188. minimumValue: minTempBox.value
  189. value: Units.fromCelsius(base.maxTemp, base.unit)
  190. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  191. onValueChanged: base.maxTemp = value
  192. }
  193. }
  194. RowLayout {
  195. visible: expand.expanded
  196. Label {
  197. Layout.preferredWidth: root.textWidth
  198. clip: true
  199. text: i18n("Name of the fancontrol systemd service:")
  200. horizontalAlignment: Text.AlignRight
  201. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  202. }
  203. OptionInput {
  204. Layout.minimumWidth: implicitWidth
  205. Layout.fillWidth: true
  206. color: base.systemdCom.serviceExists ? "green" : "red"
  207. value: base.serviceName
  208. onTextChanged: base.serviceName = text
  209. }
  210. }
  211. RowLayout {
  212. visible: expand.expanded
  213. Label {
  214. Layout.preferredWidth: root.textWidth
  215. clip: true
  216. text: i18n("Path to the fancontrol config file:")
  217. horizontalAlignment: Text.AlignRight
  218. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  219. }
  220. OptionInput {
  221. Layout.minimumWidth: implicitWidth
  222. Layout.fillWidth: true
  223. text: base.configUrl.toString().replace("file://", "")
  224. color: base.configValid ? "green" : "red"
  225. onTextChanged: base.configUrl = text
  226. }
  227. Button {
  228. action: loadAction
  229. }
  230. }
  231. }
  232. Action {
  233. id: loadAction
  234. iconName: "document-open"
  235. onTriggered: openFileDialog.open()
  236. tooltip: i18n("Load configuration file")
  237. shortcut: StandardKey.Open
  238. }
  239. FileDialog {
  240. id: openFileDialog
  241. title: i18n("Please choose a configuration file")
  242. folder: "file:///etc"
  243. selectExisting: true
  244. selectMultiple: false
  245. onAccepted: {
  246. base.configUrl = fileUrl;
  247. }
  248. }
  249. ErrorDialog {
  250. id: errorDialog
  251. modality: Qt.ApplicationModal
  252. text: base.loader.error
  253. }
  254. Connections {
  255. target: base.loader
  256. onCriticalError: errorDialog.open()
  257. }
  258. }