KCM.qml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: ListModel {
  77. property var fans: kcm.loader.allPwmFans
  78. id: fanList
  79. Component.onCompleted: {
  80. for (var i=0; i<fans.length; i++) {
  81. fanList.append({"text": ArrayFunctions.nameWithPath(fans[i])});
  82. }
  83. }
  84. }
  85. Layout.fillWidth: true
  86. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  87. }
  88. Button {
  89. Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
  90. text: i18n("Detect fans")
  91. iconName: kcm.needsAuthorization ? "dialog-password" : ""
  92. onClicked: kcm.loader.detectSensors()
  93. }
  94. }
  95. Loader {
  96. Layout.fillWidth: true
  97. Layout.fillHeight: true
  98. active: !!kcm.loader.allPwmFans[fanComboBox.currentIndex]
  99. sourceComponent: PwmFan {
  100. unit: kcm.base.unit
  101. fan: kcm.loader.allPwmFans[fanComboBox.currentIndex]
  102. loader: kcm.loader
  103. systemdCom: kcm.systemdCom
  104. minTemp: kcm.base.minTemp
  105. maxTemp: kcm.base.maxTemp
  106. onNameChanged: {
  107. if (fanComboBox.currentText != ArrayFunctions.nameWithPath(fan)) {
  108. fanList.setProperty(fanComboBox.currentIndex, "text", ArrayFunctions.nameWithPath(fan));
  109. }
  110. }
  111. }
  112. }
  113. Row {
  114. property bool expanded: false
  115. id: expand
  116. Image {
  117. id: arrow
  118. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  119. fillMode: Image.PreserveAspectFit
  120. height: advancedLabel.implicitHeight
  121. }
  122. Label {
  123. id: advancedLabel
  124. text: i18n("Advanced settings")
  125. font.bold: true
  126. }
  127. }
  128. MouseArea {
  129. anchors.fill: expand
  130. onClicked: expand.expanded = expand.expanded ? false : true
  131. }
  132. RowLayout {
  133. visible: expand.expanded
  134. Label {
  135. Layout.preferredWidth: root.textWidth
  136. clip: true
  137. text: i18n("Interval:")
  138. horizontalAlignment: Text.AlignRight
  139. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  140. }
  141. SpinBox {
  142. Layout.minimumWidth: implicitWidth
  143. Layout.fillWidth: true
  144. value: base.loader ? base.loader.interval : 1
  145. suffix: " " + (value > 1 ? i18n("seconds") : i18n("second"))
  146. minimumValue: 1.0
  147. onValueChanged: base.loader.interval = value
  148. }
  149. }
  150. RowLayout {
  151. visible: expand.expanded
  152. Label {
  153. Layout.preferredWidth: root.textWidth
  154. clip: true
  155. text: i18n("Minimum temperature for fan graphs:")
  156. horizontalAlignment: Text.AlignRight
  157. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  158. }
  159. SpinBox {
  160. id: minTempBox
  161. Layout.minimumWidth: implicitWidth
  162. Layout.fillWidth: true
  163. decimals: 2
  164. maximumValue: maxTempBox.value
  165. minimumValue: Units.fromKelvin(0, base.unit)
  166. value: Units.fromCelsius(base.minTemp, base.unit)
  167. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  168. onValueChanged: base.minTemp = value
  169. }
  170. }
  171. RowLayout {
  172. visible: expand.expanded
  173. Label {
  174. Layout.preferredWidth: root.textWidth
  175. clip: true
  176. text: i18n("Maximum temperature for fan graphs:")
  177. horizontalAlignment: Text.AlignRight
  178. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  179. }
  180. SpinBox {
  181. id: maxTempBox
  182. Layout.minimumWidth: implicitWidth
  183. Layout.fillWidth: true
  184. decimals: 2
  185. maximumValue: Number.POSITIVE_INFINITY
  186. minimumValue: minTempBox.value
  187. value: Units.fromCelsius(base.maxTemp, base.unit)
  188. suffix: base.unit == 0 ? i18n("°C") : base.unit == 1 ? i18n("K") : i18n("°F")
  189. onValueChanged: base.maxTemp = value
  190. }
  191. }
  192. RowLayout {
  193. visible: expand.expanded
  194. Label {
  195. Layout.preferredWidth: root.textWidth
  196. clip: true
  197. text: i18n("Name of the fancontrol systemd service:")
  198. horizontalAlignment: Text.AlignRight
  199. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  200. }
  201. OptionInput {
  202. Layout.minimumWidth: implicitWidth
  203. Layout.fillWidth: true
  204. color: base.systemdCom.serviceExists ? "green" : "red"
  205. value: base.serviceName
  206. onTextChanged: base.serviceName = text
  207. }
  208. }
  209. }
  210. }