SettingsForm.qml 6.4 KB

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