2
0

KCM.qml 8.2 KB

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