KCM.qml 7.8 KB

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