KCM.qml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. SpinBox {
  130. Layout.minimumWidth: implicitWidth
  131. Layout.fillWidth: true
  132. value: base.loader ? base.loader.interval : 1
  133. suffix: " " + (value > 1 ? i18n("seconds") : i18n("second"))
  134. minimumValue: 1.0
  135. onValueChanged: base.loader.interval = value
  136. }
  137. }
  138. RowLayout {
  139. visible: expand.expanded
  140. Label {
  141. Layout.preferredWidth: root.textWidth
  142. clip: true
  143. text: i18n("Minimum temperature for fan graphs:")
  144. horizontalAlignment: Text.AlignRight
  145. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  146. }
  147. SpinBox {
  148. id: minTempBox
  149. Layout.minimumWidth: implicitWidth
  150. Layout.fillWidth: true
  151. decimals: 2
  152. maximumValue: maxTempBox.value
  153. minimumValue: Units.fromKelvin(0, base.unit)
  154. value: Units.fromCelsius(base.minTemp, base.unit)
  155. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  156. onValueChanged: base.minTemp = value
  157. }
  158. }
  159. RowLayout {
  160. visible: expand.expanded
  161. Label {
  162. Layout.preferredWidth: root.textWidth
  163. clip: true
  164. text: i18n("Maximum temperature for fan graphs:")
  165. horizontalAlignment: Text.AlignRight
  166. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  167. }
  168. SpinBox {
  169. id: maxTempBox
  170. Layout.minimumWidth: implicitWidth
  171. Layout.fillWidth: true
  172. decimals: 2
  173. maximumValue: Number.POSITIVE_INFINITY
  174. minimumValue: minTempBox.value
  175. value: Units.fromCelsius(base.maxTemp, base.unit)
  176. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  177. onValueChanged: base.maxTemp = value
  178. }
  179. }
  180. RowLayout {
  181. visible: expand.expanded
  182. Label {
  183. Layout.preferredWidth: root.textWidth
  184. clip: true
  185. text: i18n("Name of the fancontrol systemd service:")
  186. horizontalAlignment: Text.AlignRight
  187. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  188. }
  189. OptionInput {
  190. Layout.minimumWidth: implicitWidth
  191. Layout.fillWidth: true
  192. color: base.systemdCom.serviceExists ? "green" : "red"
  193. value: base.serviceName
  194. onTextChanged: base.serviceName = text
  195. }
  196. }
  197. }
  198. }