SettingsForm.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.6
  20. import QtQuick.Layouts 1.2
  21. import QtQuick.Controls 2.1
  22. import QtQuick.Dialogs 1.2
  23. import org.kde.kirigami 2.3 as Kirigami
  24. import Fancontrol.Qml 1.0 as Fancontrol
  25. import "units.js" as Units
  26. Kirigami.FormLayout {
  27. id: root
  28. readonly property QtObject systemdCom: Fancontrol.Base.hasSystemdCommunicator ? Fancontrol.Base.systemdCom : null
  29. readonly property QtObject loader: Fancontrol.Base.loader
  30. readonly property string unit: Fancontrol.Base.unit
  31. property bool showAll: true
  32. SpinBox {
  33. id: intervalSpinBox
  34. readonly property string suffix: ' ' + i18np("second", "seconds", value)
  35. Kirigami.FormData.label: i18n("Interval:")
  36. Layout.fillWidth: true
  37. value: loader.interval
  38. from: 1.0
  39. editable: true
  40. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 0) + suffix }
  41. valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
  42. onValueModified: loader.interval = value
  43. Connections {
  44. target: loader
  45. onIntervalChanged: {
  46. if (loader.interval != intervalSpinBox.value)
  47. intervalSpinBox.value = loader.interval;
  48. }
  49. }
  50. }
  51. SpinBox {
  52. id: minTempBox
  53. readonly property int celsiusValue: Units.toCelsius(value, unit)
  54. readonly property string suffix: i18n(unit)
  55. Kirigami.FormData.label: i18n("Minimum temperature for fan graphs:")
  56. Layout.fillWidth: true
  57. from: Units.fromKelvin(0, unit)
  58. to: 999
  59. inputMethodHints: Qt.ImhFormattedNumbersOnly
  60. editable: true
  61. value: Units.fromCelsius(Fancontrol.Base.minTemp, unit)
  62. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
  63. valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
  64. onCelsiusValueChanged: {
  65. if (celsiusValue >= maxTempBox.celsiusValue)
  66. maxTempBox.value = Math.max(value + 1, Units.fromCelsius(Units.toCelsius(value, unit) + 1, unit));
  67. Fancontrol.Base.minTemp = celsiusValue;
  68. }
  69. Connections {
  70. target: Fancontrol.Base
  71. onMinTempChanged: {
  72. if (Fancontrol.Base.minTemp !== minTempBox.celsiusValue)
  73. minTempBox.value = Units.fromCelsius(Fancontrol.Base.minTemp, unit);
  74. }
  75. }
  76. }
  77. SpinBox {
  78. id: maxTempBox
  79. readonly property int celsiusValue: Units.toCelsius(value, unit)
  80. readonly property string suffix: i18n(unit)
  81. Kirigami.FormData.label: i18n("Maximum temperature for fan graphs:")
  82. Layout.fillWidth: true
  83. from: Units.fromKelvin(0, unit)
  84. to: 999
  85. inputMethodHints: Qt.ImhFormattedNumbersOnly
  86. editable: true
  87. value: Units.fromCelsius(Fancontrol.Base.maxTemp, unit)
  88. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
  89. valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
  90. onCelsiusValueChanged: {
  91. if (celsiusValue <= minTempBox.celsiusValue)
  92. minTempBox.value = Math.min(value - 1, Units.fromCelsius(Units.toCelsius(value, unit) - 1, unit));
  93. Fancontrol.Base.maxTemp = celsiusValue;
  94. }
  95. Connections {
  96. target: Fancontrol.Base
  97. onMaxTempChanged: {
  98. if (Fancontrol.Base.maxTemp !== maxTempBox.celsuisValue)
  99. maxTempBox.value = Units.fromCelsius(Fancontrol.Base.maxTemp, unit);
  100. }
  101. }
  102. }
  103. RowLayout {
  104. Kirigami.FormData.label: i18n("Path to the fancontrol config file:")
  105. Layout.fillWidth: true
  106. TextField {
  107. id: fileInput
  108. Layout.fillWidth: true
  109. text: Fancontrol.Base.configUrl.toString().replace("file://", "")
  110. onTextChanged: Fancontrol.Base.configUrl = text;
  111. Connections {
  112. target: Fancontrol.Base
  113. onConfigUrlChanged: if(Fancontrol.Base.configUrl.toString().replace("file://", "") != fileInput.text) fileInput.text = Fancontrol.Base.configUrl.toString().replace("file://", "")
  114. }
  115. }
  116. Button {
  117. icon.name: "document-open"
  118. // tooltip: i18n("Open config file")
  119. onClicked: openFileDialog.open();
  120. }
  121. }
  122. TextField {
  123. id: serviceNameInput
  124. visible: !!systemdCom
  125. Kirigami.FormData.label: i18n("Name of the fancontrol systemd service:")
  126. Layout.fillWidth: true
  127. color: !!systemdCom && systemdCom.serviceExists ? "green" : "red"
  128. text: Fancontrol.Base.serviceName
  129. onTextChanged: Fancontrol.Base.serviceName = text
  130. Connections {
  131. target: Fancontrol.Base
  132. onServiceNameChanged: if(Fancontrol.Base.serviceName != serviceNameInput.text) serviceNameInput.text = Fancontrol.Base.serviceName
  133. }
  134. }
  135. CheckBox {
  136. id: trayBox
  137. Kirigami.FormData.label: i18n("Show tray icon:")
  138. checked: Fancontrol.Base.showTray
  139. visible: showAll
  140. onCheckedChanged: Fancontrol.Base.showTray = checked
  141. Connections {
  142. target: Fancontrol.Base
  143. onShowTrayChanged: if (Fancontrol.Base.showTray != trayBox.checked) trayBox.checked = Fancontrol.Base.showTray
  144. }
  145. }
  146. CheckBox {
  147. id: startMinimizedBox
  148. Kirigami.FormData.label: i18n("Start minimized:")
  149. checked: Fancontrol.Base.startMinimized
  150. visible: showAll
  151. onCheckedChanged: Fancontrol.Base.startMinimized = checked
  152. Connections {
  153. target: Fancontrol.Base
  154. onStartMinimizedChanged: if (Fancontrol.Base.startMinimized != startMinimizedBox.checked) startMinimizedBox.checked = Fancontrol.Base.startMinimized
  155. }
  156. }
  157. FileDialog {
  158. id: openFileDialog
  159. title: i18n("Please choose a configuration file")
  160. folder: "file:///etc"
  161. selectExisting: true
  162. selectMultiple: false
  163. modality: Qt.NonModal
  164. onAccepted: fileInput.text = fileUrl;
  165. }
  166. }