SettingsTab.qml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Layouts 1.1
  21. import QtQuick.Controls 1.2
  22. import QtQml 2.2
  23. import "../scripts/arrayfunctions.js" as ArrayFunctions
  24. import "../scripts/units.js" as Units
  25. Item {
  26. property QtObject gui
  27. property QtObject systemdCom: gui && gui.hasSystemdCommunicator() ? gui.systemdCom : null
  28. property QtObject loader : gui ? gui.loader : null
  29. property int padding: 10
  30. property real textWidth: 0
  31. property var locale: Qt.locale()
  32. id: root
  33. anchors.fill: parent
  34. anchors.topMargin: 5
  35. Column {
  36. id: column
  37. anchors.fill: parent
  38. anchors.margins: padding
  39. spacing: 5
  40. RowLayout {
  41. width: parent.width
  42. Label {
  43. Layout.preferredWidth: root.textWidth
  44. clip: true
  45. text: i18n("Interval:")
  46. horizontalAlignment: Text.AlignRight
  47. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  48. }
  49. OptionInput {
  50. id: intervalValue
  51. Layout.minimumWidth: implicitWidth
  52. Layout.fillWidth: true
  53. inputMethodHints: Qt.ImhDigitsOnly
  54. validator: IntValidator { bottom: 0 }
  55. text: Number(gui ? gui.interval : 1).toLocaleString(locale, 'f', 0)
  56. onTextChanged: {
  57. if (activeFocus && text && root.locale) {
  58. var value = Number.fromLocaleString(root.locale, text);
  59. if (value) gui.interval = value;
  60. }
  61. }
  62. }
  63. }
  64. RowLayout {
  65. width: parent.width
  66. Label {
  67. Layout.preferredWidth: root.textWidth
  68. clip: true
  69. text: i18n("Minimum temperature for fan graphs:")
  70. horizontalAlignment: Text.AlignRight
  71. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  72. }
  73. OptionInput {
  74. id: minTempValue
  75. Layout.minimumWidth: implicitWidth
  76. Layout.fillWidth: true
  77. inputMethodHints: Qt.ImhFormattedNumbersOnly
  78. validator: DoubleValidator {}
  79. Component.onCompleted: text = Number(Units.fromCelsius(gui.minTemp, gui.unit)).toLocaleString()
  80. onTextChanged: {
  81. if (activeFocus && text && root.locale) {
  82. var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
  83. if (value) gui.minTemp = value;
  84. }
  85. }
  86. Connections {
  87. target: gui
  88. onUnitChanged: minTempValue.text = Units.fromCelsius(gui.minTemp, gui.unit)
  89. }
  90. }
  91. }
  92. RowLayout {
  93. width: parent.width
  94. Label {
  95. Layout.preferredWidth: root.textWidth
  96. clip: true
  97. text: i18n("Maximum temperature for fan graphs:")
  98. horizontalAlignment: Text.AlignRight
  99. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  100. }
  101. OptionInput {
  102. id: maxTempValue
  103. Layout.minimumWidth: implicitWidth
  104. Layout.fillWidth: true
  105. inputMethodHints: Qt.ImhFormattedNumbersOnly
  106. validator: DoubleValidator {}
  107. Component.onCompleted: text = Number(Units.fromCelsius(gui.maxTemp, gui.unit)).toLocaleString()
  108. onTextChanged: {
  109. if (activeFocus && text && root.locale) {
  110. var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
  111. if (value) gui.maxTemp = value;
  112. }
  113. }
  114. Connections {
  115. target: gui
  116. onUnitChanged: maxTempValue.text = Units.fromCelsius(gui.maxTemp, gui.unit)
  117. }
  118. }
  119. }
  120. Loader {
  121. active: systemdCom
  122. sourceComponent: RowLayout {
  123. width: column.width
  124. Label {
  125. Layout.preferredWidth: root.textWidth
  126. clip: true
  127. text: i18n("Name of the fancontrol systemd service:")
  128. horizontalAlignment: Text.AlignRight
  129. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  130. }
  131. OptionInput {
  132. id: serviceName
  133. Layout.minimumWidth: implicitWidth
  134. Layout.fillWidth: true
  135. color: systemdCom.serviceExists ? "green" : "red"
  136. text: gui.serviceName
  137. onTextChanged: gui.serviceName = text
  138. }
  139. }
  140. }
  141. Loader {
  142. active: systemdCom
  143. sourceComponent: RowLayout {
  144. width: column.width
  145. Label {
  146. Layout.preferredWidth: root.textWidth
  147. clip: true
  148. text: i18n("Fancontrol systemd service autostart:")
  149. horizontalAlignment: Text.AlignRight
  150. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  151. }
  152. CheckBox {
  153. id: autostartBox
  154. Layout.minimumWidth: implicitWidth
  155. Layout.fillWidth: true
  156. checked: systemdCom.serviceEnabled
  157. onCheckedChanged: systemdCom.serviceEnabled = checked
  158. }
  159. }
  160. }
  161. Button {
  162. x: maxTempValue.x
  163. text: i18n("Detect fans")
  164. onClicked: loader.detectSensors()
  165. }
  166. }
  167. }