KCM.qml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 org.kde.kcm 1.0
  23. import "../scripts/arrayfunctions.js" as ArrayFunctions
  24. import "../scripts/units.js" as Units
  25. Item {
  26. property QtObject base: kcm.base
  27. property var locale: Qt.locale()
  28. property real textWidth: 0
  29. id: root
  30. implicitWidth: 1024
  31. implicitHeight: 768
  32. ColumnLayout {
  33. id: noFansInfo
  34. width: parent.width
  35. anchors.verticalCenter: parent.verticalCenter
  36. spacing: 20
  37. visible: kcm.loader.allPwmFans.length == 0
  38. Label {
  39. Layout.alignment: Qt.AlignCenter
  40. text: i18n("There are no pwm capable fans in your system.")
  41. font.pointSize: 14
  42. font.bold: true
  43. }
  44. Button {
  45. Layout.alignment: Qt.AlignCenter
  46. text: i18n("Detect fans")
  47. onClicked: kcm.loader.detectSensors()
  48. }
  49. }
  50. CheckBox {
  51. id: enabledBox
  52. visible: kcm.loader.allPwmFans.length > 0
  53. Layout.alignment: Qt.AlignLeft | Qt.AlignTop
  54. text: i18n("Control fans manually")
  55. checked: kcm.manualControl
  56. onCheckedChanged: kcm.manualControl = checked
  57. Connections {
  58. target: kcm
  59. onManualControlChanged: enabledBox.checked = kcm.manualControl
  60. }
  61. }
  62. ColumnLayout {
  63. width: parent.width
  64. anchors.bottom: parent.bottom
  65. anchors.top: enabledBox.bottom
  66. visible: enabledBox.checked
  67. RowLayout {
  68. visible: enabledBox.checked && kcm.loader.allPwmFans.length > 0
  69. Label {
  70. text: i18n("Fan:")
  71. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  72. renderType: Text.NativeRendering
  73. }
  74. ComboBox {
  75. id: fanCombobox
  76. model: ArrayFunctions.namesWithPaths(kcm.loader.allPwmFans)
  77. Layout.fillWidth: true
  78. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  79. }
  80. Button {
  81. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  82. text: i18n("Detect fans")
  83. iconName: kcm.needsAuthorization ? "dialog-password" : ""
  84. onClicked: kcm.loader.detectSensors()
  85. }
  86. }
  87. Loader {
  88. Layout.fillWidth: true
  89. Layout.fillHeight: true
  90. active: !!kcm.loader.allPwmFans[fanCombobox.currentIndex]
  91. sourceComponent: PwmFan {
  92. minimizable: false
  93. unit: kcm.base.unit
  94. fan: kcm.loader.allPwmFans[fanCombobox.currentIndex]
  95. loader: kcm.loader
  96. systemdCom: kcm.systemdCom
  97. minTemp: kcm.base.minTemp
  98. maxTemp: kcm.base.maxTemp
  99. }
  100. }
  101. Row {
  102. property bool expanded: false
  103. id: expand
  104. Image {
  105. id: arrow
  106. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  107. fillMode: Image.PreserveAspectFit
  108. height: advancedLabel.implicitHeight
  109. }
  110. Label {
  111. id: advancedLabel
  112. text: i18n("Advanced settings")
  113. font.bold: true
  114. }
  115. }
  116. MouseArea {
  117. anchors.fill: expand
  118. onClicked: expand.expanded = expand.expanded ? false : true
  119. }
  120. RowLayout {
  121. visible: expand.expanded
  122. Label {
  123. Layout.preferredWidth: root.textWidth
  124. clip: true
  125. text: i18n("Interval:")
  126. horizontalAlignment: Text.AlignRight
  127. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  128. }
  129. OptionInput {
  130. id: intervalValue
  131. Layout.minimumWidth: implicitWidth
  132. Layout.fillWidth: true
  133. inputMethodHints: Qt.ImhDigitsOnly
  134. validator: IntValidator { bottom: 0 }
  135. value: base.loader ? base.loader.interval : 1
  136. type: "int"
  137. onTextChanged: {
  138. if (activeFocus && text && root.locale) {
  139. var value = Number.fromLocaleString(root.locale, text);
  140. if (value) base.loader.interval = value;
  141. }
  142. }
  143. }
  144. }
  145. RowLayout {
  146. visible: expand.expanded
  147. Label {
  148. Layout.preferredWidth: root.textWidth
  149. clip: true
  150. text: i18n("Minimum temperature for fan graphs:")
  151. horizontalAlignment: Text.AlignRight
  152. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  153. }
  154. OptionInput {
  155. id: minTempValue
  156. Layout.minimumWidth: implicitWidth
  157. Layout.fillWidth: true
  158. inputMethodHints: Qt.ImhFormattedNumbersOnly
  159. validator: DoubleValidator { top: base.maxTemp }
  160. value: Units.fromCelsius(base.minTemp, base.unit)
  161. type: "double"
  162. onTextChanged: {
  163. if (activeFocus && text && root.locale) {
  164. var value = Units.toCelsius(Number.fromLocaleString(locale, text), base.unit);
  165. if (value) base.minTemp = value;
  166. }
  167. }
  168. }
  169. }
  170. RowLayout {
  171. visible: expand.expanded
  172. Label {
  173. Layout.preferredWidth: root.textWidth
  174. clip: true
  175. text: i18n("Maximum temperature for fan graphs:")
  176. horizontalAlignment: Text.AlignRight
  177. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  178. }
  179. OptionInput {
  180. id: maxTempValue
  181. Layout.minimumWidth: implicitWidth
  182. Layout.fillWidth: true
  183. inputMethodHints: Qt.ImhFormattedNumbersOnly
  184. validator: DoubleValidator { bottom: base.minTemp }
  185. value: Units.fromCelsius(base.maxTemp, base.unit)
  186. type: "double"
  187. onTextChanged: {
  188. if (activeFocus && text && root.locale) {
  189. var value = Units.toCelsius(Number.fromLocaleString(locale, text), base.unit);
  190. if (value) base.maxTemp = value;
  191. }
  192. }
  193. }
  194. }
  195. RowLayout {
  196. visible: expand.expanded
  197. Label {
  198. Layout.preferredWidth: root.textWidth
  199. clip: true
  200. text: i18n("Name of the fancontrol systemd service:")
  201. horizontalAlignment: Text.AlignRight
  202. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  203. }
  204. OptionInput {
  205. Layout.minimumWidth: implicitWidth
  206. Layout.fillWidth: true
  207. color: base.systemdCom.serviceExists ? "green" : "red"
  208. value: base.serviceName
  209. type: "string"
  210. onTextChanged: base.serviceName = text
  211. }
  212. }
  213. }
  214. }