2
0

SettingsTab.qml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <malte.veerman@gmail.com>
  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.Layouts 1.1
  21. import QtQuick.Controls 1.2
  22. import QtQuick.Dialogs 1.2
  23. import Fancontrol.Qml 1.0 as Fancontrol
  24. Item {
  25. property QtObject systemdCom: Fancontrol.base.hasSystemdCommunicator() ? Fancontrol.base.systemdCom : null
  26. property QtObject loader: Fancontrol.base.loader
  27. property int padding: 10
  28. property real textWidth: 0
  29. property var locale: Qt.locale()
  30. id: root
  31. anchors.fill: parent
  32. anchors.margins: 10
  33. Column {
  34. id: column
  35. anchors.fill: parent
  36. anchors.margins: padding
  37. spacing: 5
  38. RowLayout {
  39. width: parent.width
  40. Label {
  41. Layout.preferredWidth: root.textWidth
  42. clip: true
  43. text: i18n("Interval:")
  44. horizontalAlignment: Text.AlignRight
  45. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  46. }
  47. SpinBox {
  48. id: intervalSpinBox
  49. Layout.minimumWidth: implicitWidth
  50. Layout.fillWidth: true
  51. value: loader.interval
  52. suffix: " " + i18np("second", "seconds", loader.interval)
  53. minimumValue: 1.0
  54. onValueChanged: loader.interval = value
  55. Connections {
  56. target: loader
  57. onIntervalChanged: if (loader.interval != intervalSpinBox.value) intervalSpinBox.value = loader.interval
  58. }
  59. }
  60. }
  61. RowLayout {
  62. width: parent.width
  63. Label {
  64. Layout.preferredWidth: root.textWidth
  65. clip: true
  66. text: i18n("Minimum temperature for fan graphs:")
  67. horizontalAlignment: Text.AlignRight
  68. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  69. }
  70. SpinBox {
  71. id: minTempBox
  72. Layout.minimumWidth: implicitWidth
  73. Layout.fillWidth: true
  74. decimals: 2
  75. maximumValue: Number.POSITIVE_INFINITY
  76. minimumValue: Fancontrol.Units.fromKelvin(0, Fancontrol.base.unit)
  77. value: Fancontrol.Units.fromCelsius(Fancontrol.base.minTemp, Fancontrol.base.unit)
  78. suffix: Fancontrol.base.unit
  79. onValueChanged: {
  80. Fancontrol.base.minTemp = Fancontrol.Units.toCelsius(value, Fancontrol.base.unit);
  81. if (value > maxTempBox.value) maxTempBox.value = value;
  82. }
  83. Connections {
  84. target: Fancontrol.base
  85. onMinTempChanged: if (Fancontrol.base.minTemp != minTempBox.value) minTempBox.value = Fancontrol.base.minTemp
  86. }
  87. }
  88. }
  89. RowLayout {
  90. width: parent.width
  91. Label {
  92. Layout.preferredWidth: root.textWidth
  93. clip: true
  94. text: i18n("Maximum temperature for fan graphs:")
  95. horizontalAlignment: Text.AlignRight
  96. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  97. }
  98. SpinBox {
  99. id: maxTempBox
  100. Layout.minimumWidth: implicitWidth
  101. Layout.fillWidth: true
  102. decimals: 2
  103. maximumValue: Number.POSITIVE_INFINITY
  104. minimumValue: Fancontrol.Units.fromKelvin(0, Fancontrol.base.unit)
  105. value: Fancontrol.Units.fromCelsius(Fancontrol.base.maxTemp, Fancontrol.base.unit)
  106. suffix: Fancontrol.base.unit
  107. onValueChanged: {
  108. Fancontrol.base.maxTemp = Fancontrol.Units.toCelsius(value, Fancontrol.base.unit);
  109. if (value < minTempBox.value) minTempBox.value = value;
  110. }
  111. Connections {
  112. target: Fancontrol.base
  113. onMaxTempChanged: if (Fancontrol.base.maxTemp != maxTempBox.value) maxTempBox.value = Fancontrol.base.maxTemp
  114. }
  115. }
  116. }
  117. RowLayout {
  118. width: parent.width
  119. Label {
  120. Layout.preferredWidth: root.textWidth
  121. clip: true
  122. text: i18n("Path to the fancontrol config file:")
  123. horizontalAlignment: Text.AlignRight
  124. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  125. }
  126. Fancontrol.OptionInput {
  127. id: fileInput
  128. Layout.fillWidth: true
  129. value: Fancontrol.base.configUrl.toString().replace("file://", "")
  130. onTextChanged: Fancontrol.base.configUrl = text;
  131. }
  132. Button {
  133. iconName: "document-open"
  134. tooltip: i18n("Open config file")
  135. onClicked: openFileDialog.open();
  136. }
  137. }
  138. Loader {
  139. active: !!systemdCom
  140. sourceComponent: RowLayout {
  141. width: column.width
  142. Label {
  143. Layout.preferredWidth: root.textWidth
  144. clip: true
  145. text: i18n("Name of the fancontrol systemd service:")
  146. horizontalAlignment: Text.AlignRight
  147. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  148. }
  149. Fancontrol.OptionInput {
  150. id: serviceNameInput
  151. Layout.minimumWidth: implicitWidth
  152. Layout.fillWidth: true
  153. color: !!systemdCom && systemdCom.serviceExists ? "green" : "red"
  154. value: Fancontrol.base.serviceName
  155. onTextChanged: Fancontrol.base.serviceName = text
  156. }
  157. }
  158. }
  159. Loader {
  160. active: !!systemdCom
  161. sourceComponent: RowLayout {
  162. width: column.width
  163. Label {
  164. Layout.preferredWidth: root.textWidth
  165. clip: true
  166. text: i18n("Enable service at boot:")
  167. horizontalAlignment: Text.AlignRight
  168. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  169. }
  170. CheckBox {
  171. id: autostartBox
  172. Layout.minimumWidth: implicitWidth
  173. Layout.fillWidth: true
  174. checked: !!systemdCom ? systemdCom.serviceEnabled : false
  175. onCheckedChanged: {
  176. if (!!systemdCom) {
  177. systemdCom.serviceEnabled = checked;
  178. }
  179. }
  180. Connections {
  181. target: systemdCom
  182. onServiceEnabledChanged: if (systemdCom.serviceEnabled != autostartBox.checked) autostartBox.checked = systemdCom.serviceEnabled
  183. }
  184. }
  185. }
  186. }
  187. FileDialog {
  188. id: openFileDialog
  189. title: i18n("Please choose a configuration file")
  190. folder: "file:///etc"
  191. selectExisting: true
  192. selectMultiple: false
  193. modality: Qt.NonModal
  194. onAccepted: fileInput.text = fileUrl;
  195. }
  196. }
  197. }