SettingsTab.qml 6.5 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 "../scripts/arrayfunctions.js" as ArrayFunctions
  23. import "../scripts/units.js" as Units
  24. Item {
  25. property QtObject loader
  26. property QtObject systemdCom
  27. property real minTemp: 30.0
  28. property real maxTemp: 90.0
  29. property int interval: loader ? loader.interval : 1
  30. property int padding: 10
  31. property string unit: i18n("Celsius")
  32. property real textWidth: 0
  33. id: root
  34. anchors.fill: parent
  35. anchors.topMargin: 5
  36. onIntervalChanged: {
  37. if (loader !== null) {
  38. var fans = ArrayFunctions.allPwmFans(loader.hwmons);
  39. for (var i=0; i<fans.length; i++) {
  40. fans[i].interval = interval;
  41. }
  42. }
  43. }
  44. Column {
  45. id: column
  46. anchors.fill: parent
  47. anchors.margins: padding
  48. spacing: 5
  49. RowLayout {
  50. width: parent.width
  51. Text {
  52. Layout.preferredWidth: root.textWidth
  53. clip: true
  54. text: i18n("Interval:")
  55. horizontalAlignment: Text.AlignRight
  56. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  57. }
  58. OptionInput {
  59. id: intervalValue
  60. Layout.minimumWidth: implicitWidth
  61. Layout.fillWidth: true
  62. inputMethodHints: Qt.ImhDigitsOnly
  63. text: interval
  64. onTextChanged: if (text != "") loader.interval = parseInt(text)
  65. }
  66. }
  67. RowLayout {
  68. width: parent.width
  69. Text {
  70. Layout.preferredWidth: root.textWidth
  71. clip: true
  72. text: i18n("Minimum temperature for fan graphs:")
  73. horizontalAlignment: Text.AlignRight
  74. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  75. }
  76. OptionInput {
  77. id: minTempValue
  78. Layout.minimumWidth: implicitWidth
  79. Layout.fillWidth: true
  80. inputMethodHints: Qt.ImhDigitsOnly
  81. onTextChanged: if (activeFocus) minTemp = Units.toCelsius(text, unit)
  82. Component.onCompleted: text = Units.fromCelsius(minTemp, unit)
  83. }
  84. }
  85. RowLayout {
  86. width: parent.width
  87. Text {
  88. Layout.preferredWidth: root.textWidth
  89. clip: true
  90. text: i18n("Maximum temperature for fan graphs:")
  91. horizontalAlignment: Text.AlignRight
  92. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  93. }
  94. OptionInput {
  95. id: maxTempValue
  96. Layout.minimumWidth: implicitWidth
  97. Layout.fillWidth: true
  98. inputMethodHints: Qt.ImhDigitsOnly
  99. text: Units.fromCelsius(maxTemp, unit.currentText)
  100. onTextChanged: if (activeFocus) maxTemp = Units.toCelsius(text, unit)
  101. Component.onCompleted: text = Units.fromCelsius(maxTemp, unit)
  102. }
  103. }
  104. RowLayout {
  105. width: parent.width
  106. Text {
  107. Layout.preferredWidth: root.textWidth
  108. clip: true
  109. text: i18n("Unit:")
  110. horizontalAlignment: Text.AlignRight
  111. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  112. }
  113. ComboBox {
  114. id: unitBox
  115. Layout.minimumWidth: implicitWidth
  116. Layout.fillWidth: true
  117. model: [i18n("Celsius"), i18n("Kelvin"), i18n("Fahrenheit")]
  118. currentIndex: find(root.unit)
  119. onCurrentIndexChanged: {
  120. minTempValue.text = Units.fromCelsius(minTemp, currentIndex);
  121. maxTempValue.text = Units.fromCelsius(maxTemp, currentIndex);
  122. }
  123. }
  124. }
  125. Loader {
  126. active: systemdCom
  127. sourceComponent: RowLayout {
  128. width: column.width
  129. Text {
  130. Layout.preferredWidth: root.textWidth
  131. clip: true
  132. text: i18n("Name of the fancontrol systemd service:")
  133. horizontalAlignment: Text.AlignRight
  134. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  135. }
  136. OptionInput {
  137. id: serviceName
  138. Layout.minimumWidth: implicitWidth
  139. Layout.fillWidth: true
  140. color: systemdCom.serviceExists ? "green" : "red"
  141. text: systemdCom.serviceName
  142. onTextChanged: systemdCom.serviceName = text
  143. }
  144. }
  145. }
  146. Loader {
  147. active: systemdCom
  148. sourceComponent: RowLayout {
  149. width: column.width
  150. Text {
  151. Layout.preferredWidth: root.textWidth
  152. clip: true
  153. text: i18n("Fancontrol systemd service autostart:")
  154. horizontalAlignment: Text.AlignRight
  155. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  156. }
  157. ComboBox {
  158. id: autostartBox
  159. Layout.minimumWidth: implicitWidth
  160. Layout.fillWidth: true
  161. model: [i18n("disabled") , i18n("enabled")]
  162. currentIndex: systemdCom.serviceEnabled ? 1 : 0
  163. onCurrentIndexChanged: systemdCom.serviceEnabled = (currentIndex == 1) ? true : false
  164. }
  165. }
  166. }
  167. }
  168. }