SettingsTab.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. value: gui.loader ? gui.loader.interval : 1
  56. type: "int"
  57. onTextChanged: {
  58. if (activeFocus && text && root.locale) {
  59. var value = Number.fromLocaleString(root.locale, text);
  60. if (value) gui.loader.interval = value;
  61. }
  62. }
  63. }
  64. }
  65. RowLayout {
  66. width: parent.width
  67. Label {
  68. Layout.preferredWidth: root.textWidth
  69. clip: true
  70. text: i18n("Minimum temperature for fan graphs:")
  71. horizontalAlignment: Text.AlignRight
  72. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  73. }
  74. OptionInput {
  75. Layout.minimumWidth: implicitWidth
  76. Layout.fillWidth: true
  77. inputMethodHints: Qt.ImhFormattedNumbersOnly
  78. validator: DoubleValidator { top: gui.maxTemp }
  79. value: Units.fromCelsius(gui.minTemp, gui.unit)
  80. type: "double"
  81. onTextChanged: {
  82. if (activeFocus && text && root.locale) {
  83. var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
  84. if (value) gui.minTemp = value;
  85. }
  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. OptionInput {
  99. id: maxTempValue
  100. Layout.minimumWidth: implicitWidth
  101. Layout.fillWidth: true
  102. inputMethodHints: Qt.ImhFormattedNumbersOnly
  103. validator: DoubleValidator { bottom: gui.minTemp }
  104. value: Units.fromCelsius(gui.maxTemp, gui.unit)
  105. type: "double"
  106. onTextChanged: {
  107. if (activeFocus && text && root.locale) {
  108. var value = Units.toCelsius(Number.fromLocaleString(locale, text), gui.unit);
  109. if (value) gui.maxTemp = value;
  110. }
  111. }
  112. }
  113. }
  114. Loader {
  115. active: systemdCom
  116. sourceComponent: RowLayout {
  117. width: column.width
  118. Label {
  119. Layout.preferredWidth: root.textWidth
  120. clip: true
  121. text: i18n("Name of the fancontrol systemd service:")
  122. horizontalAlignment: Text.AlignRight
  123. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  124. }
  125. OptionInput {
  126. Layout.minimumWidth: implicitWidth
  127. Layout.fillWidth: true
  128. color: systemdCom.serviceExists ? "green" : "red"
  129. value: gui.serviceName
  130. type: "string"
  131. onTextChanged: gui.serviceName = text
  132. }
  133. }
  134. }
  135. Loader {
  136. active: systemdCom
  137. sourceComponent: RowLayout {
  138. width: column.width
  139. Label {
  140. Layout.preferredWidth: root.textWidth
  141. clip: true
  142. text: i18n("Fancontrol systemd service autostart:")
  143. horizontalAlignment: Text.AlignRight
  144. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  145. }
  146. CheckBox {
  147. id: autostartBox
  148. Layout.minimumWidth: implicitWidth
  149. Layout.fillWidth: true
  150. checked: systemdCom.serviceEnabled
  151. onCheckedChanged: systemdCom.serviceEnabled = checked
  152. }
  153. }
  154. }
  155. Button {
  156. x: maxTempValue.x
  157. text: i18n("Detect fans")
  158. iconName: "dialog-password"
  159. onClicked: loader.detectSensors()
  160. }
  161. }
  162. }