KCM.qml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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.Controls 2.1
  21. import QtQuick.Layouts 1.2
  22. import QtQuick.Dialogs 1.2
  23. import org.kde.kirigami 2.3 as Kirigami
  24. import org.kde.kcm 1.0 as KCM
  25. import Fancontrol.Qml 1.0 as Fancontrol
  26. Kirigami.Page {
  27. property QtObject loader: Fancontrol.Base.loader
  28. property QtObject systemdCom: Fancontrol.Base.systemdCom
  29. property QtObject pwmFanModel: Fancontrol.Base.pwmFanModel
  30. property QtObject tempModel: Fancontrol.Base.tempModel
  31. property QtObject profileModel: Fancontrol.Base.profileModel
  32. property real textWidth: 0
  33. property var pwmFans: pwmFanModel.fans
  34. property QtObject fan: pwmFans[fansListView.currentIndex]
  35. id: root
  36. implicitWidth: Kirigami.Units.gridUnit * 50
  37. implicitHeight: Kirigami.Units.gridUnit * 40
  38. KCM.ConfigModule.quickHelp: i18n("This module lets you configure your PWM fans.")
  39. Connections {
  40. target: Fancontrol.Base
  41. onNeedsApplyChanged: kcm.needsSave = Fancontrol.Base.needsApply
  42. }
  43. Connections {
  44. target: kcm
  45. onAboutToSave: {
  46. Fancontrol.Base.apply();
  47. }
  48. onAboutToLoad: {
  49. Fancontrol.Base.load();
  50. enabledBox.checked = systemdCom.serviceActive;
  51. }
  52. onAboutToDefault: enabledBox.checked = false
  53. }
  54. // contextualActions: [
  55. // Kirigami.Action {
  56. // text: i18n("Profiles")
  57. //
  58. // Kirigami.Action {
  59. // id: loadProfilesAction
  60. //
  61. // text: i18n("Load profile")
  62. // }
  63. // Kirigami.Action {
  64. // text: i18n("Save profile")
  65. // icon.name: "document-save"
  66. // onTriggered: Fancontrol.Base.saveProfile(profileComboBox.saveText)
  67. // }
  68. // Kirigami.Action {
  69. // text: i18n("Delete profile")
  70. // icon.name: "edit-delete"
  71. // onTriggered: Fancontrol.Base.deleteProfile(profileComboBox.currentIndex)
  72. // }
  73. // },
  74. // Kirigami.Action {
  75. // text: loader.sensorsDetected ? i18n("Detect fans again") : i18n("Detect fans")
  76. // icon.name: "dialog-password"
  77. // onTriggered: loader.detectSensors()
  78. // },
  79. // Kirigami.Action {
  80. // visible: !!systemdCom && !!fan
  81. // text: !!fan ? fan.testing ? i18n("Abort test") : i18n("Test start and stop values") : ""
  82. // icon.name: "dialog-password"
  83. // onTriggered: {
  84. // if (fan.testing) {
  85. // fan.abortTest();
  86. // } else {
  87. // fan.test();
  88. // }
  89. // }
  90. // }
  91. // ]
  92. ColumnLayout {
  93. id: noFansInfo
  94. width: root.width
  95. y: root.height / 2 - height / 2
  96. spacing: Kirigami.Units.smallSpacing * 2
  97. visible: pwmFans.length === 0
  98. Label {
  99. Layout.alignment: Qt.AlignCenter
  100. text: i18n("There are no pwm capable fans in your system.")
  101. font.pointSize: 14
  102. font.bold: true
  103. }
  104. Button {
  105. Layout.alignment: Qt.AlignCenter
  106. text: loader.sensorsDetected ? i18n("Detect fans again") : i18n("Detect fans")
  107. icon.name: kcm.needsAuthorization ? "dialog-password" : ""
  108. onClicked: loader.detectSensors()
  109. }
  110. }
  111. header: CheckBox {
  112. id: enabledBox
  113. text: i18n("Control fans manually")
  114. checked: systemdCom.serviceEnabled && systemdCom.serviceActive;
  115. onCheckedChanged: {
  116. systemdCom.serviceActive = enabledBox.checked;
  117. loader.restartServiceAfterTesting = checked;
  118. }
  119. Connections {
  120. target: systemdCom
  121. onServiceActiveChanged: if (systemdCom.serviceActive != enabledBox.checked) enabledBox.checked = systemdCom.serviceActive
  122. }
  123. }
  124. Rectangle {
  125. id: fansListViewBackground
  126. Kirigami.Theme.colorSet: Kirigami.Theme.View
  127. anchors {
  128. top: parent.top
  129. bottom: parent.bottom
  130. left: parent.left
  131. }
  132. width: root.width / 5
  133. color: Kirigami.Theme.backgroundColor
  134. visible: enabledBox.checked
  135. border.width: 1
  136. border.color: Kirigami.Theme.textColor
  137. ListView {
  138. id: fansListView
  139. anchors.fill: parent
  140. anchors.margins: fansListViewBackground.border.width
  141. clip: true
  142. boundsBehavior: Flickable.StopAtBounds
  143. flickableDirection: Flickable.AutoFlickIfNeeded
  144. model: pwmFanModel
  145. header: Kirigami.BasicListItem {
  146. label: '<b>' + i18n("Fans") + '</b>'
  147. reserveSpaceForIcon: false
  148. hoverEnabled: false
  149. separatorVisible: false
  150. leftPadding: Kirigami.Units.smallSpacing
  151. }
  152. delegate: Kirigami.BasicListItem {
  153. label: display
  154. reserveSpaceForIcon: false
  155. hoverEnabled: true
  156. highlighted: ListView.isCurrentItem
  157. separatorVisible: false
  158. onPressedChanged: if (pressed) fansListView.currentIndex = index;
  159. }
  160. }
  161. }
  162. Fancontrol.FanHeader {
  163. id: fanHeader
  164. fan: root.fan
  165. visible: enabledBox.checked
  166. anchors {
  167. top: parent.top
  168. left: fansListViewBackground.right
  169. right: parent.right
  170. margins: Kirigami.Units.smallSpacing
  171. }
  172. }
  173. Loader {
  174. anchors {
  175. top: fanHeader.bottom
  176. left: fansListViewBackground.right
  177. right: parent.right
  178. bottom: settingsColumn.top
  179. }
  180. active: !!root.fan
  181. visible: enabledBox.checked
  182. sourceComponent: Fancontrol.FanItem {
  183. unit: Fancontrol.Base.unit
  184. fan: root.fan
  185. systemdCom: root.systemdCom
  186. tempModel: root.tempModel
  187. minTemp: Fancontrol.Base.minTemp
  188. maxTemp: Fancontrol.Base.maxTemp
  189. }
  190. }
  191. Column {
  192. id: settingsColumn
  193. anchors {
  194. left: fansListViewBackground.right
  195. right: parent.right
  196. bottom: parent.bottom
  197. }
  198. height: childrenRect.height
  199. visible: enabledBox.checked
  200. Item {
  201. id: advancedButton
  202. property bool expanded: false
  203. width: parent.width
  204. height: childrenRect.height
  205. Image {
  206. id: advancedArrow
  207. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  208. fillMode: Image.PreserveAspectFit
  209. height: advancedLabel.implicitHeight
  210. }
  211. Label {
  212. id: advancedLabel
  213. anchors.left: advancedArrow.right
  214. text: i18n("Advanced settings")
  215. font.bold: true
  216. }
  217. MouseArea {
  218. anchors.fill: parent
  219. onClicked: parent.expanded = !parent.expanded
  220. }
  221. }
  222. Fancontrol.SettingsForm {
  223. id: settingsArea
  224. width: parent.width
  225. showAll: false
  226. clip: true
  227. state: advancedButton.expanded ? "VISIBLE" : "HIDDEN"
  228. states: [
  229. State {
  230. name: "VISIBLE"
  231. PropertyChanges {
  232. target: settingsArea
  233. height: implicitHeight
  234. }
  235. },
  236. State {
  237. name: "HIDDEN"
  238. PropertyChanges {
  239. target: settingsArea
  240. height: 0
  241. }
  242. }
  243. ]
  244. transitions: Transition {
  245. NumberAnimation {
  246. properties: "height"
  247. easing.type: Easing.InOutQuad
  248. }
  249. }
  250. }
  251. }
  252. Fancontrol.ErrorDialog {
  253. id: errorDialog
  254. modal: true
  255. anchors.centerIn: root
  256. }
  257. }