SettingsForm.qml 6.5 KB

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