KCM.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. readonly property QtObject loader: Fancontrol.Base.loader
  28. readonly property QtObject systemdCom: Fancontrol.Base.systemdCom
  29. readonly property QtObject pwmFanModel: Fancontrol.Base.pwmFanModel
  30. readonly property QtObject tempModel: Fancontrol.Base.tempModel
  31. readonly property QtObject profileModel: Fancontrol.Base.profileModel
  32. readonly property QtObject fan: fansListView.currentItem ? fansListView.currentItem.fan : null
  33. id: root
  34. implicitWidth: Kirigami.Units.gridUnit * 50
  35. implicitHeight: Kirigami.Units.gridUnit * 40
  36. KCM.ConfigModule.quickHelp: i18n("This module lets you configure your PWM fans.")
  37. Connections {
  38. target: Fancontrol.Base
  39. onNeedsApplyChanged: kcm.needsSave = Fancontrol.Base.needsApply
  40. }
  41. Connections {
  42. target: kcm
  43. onAboutToSave: {
  44. Fancontrol.Base.apply();
  45. }
  46. onAboutToLoad: {
  47. Fancontrol.Base.load();
  48. enabledBox.checked = systemdCom.serviceActive;
  49. }
  50. onAboutToDefault: enabledBox.checked = false
  51. }
  52. ColumnLayout {
  53. id: noFansInfo
  54. width: root.width
  55. y: root.height / 2 - height / 2
  56. spacing: Kirigami.Units.smallSpacing * 2
  57. visible: pwmFanModel.length === 0
  58. Label {
  59. Layout.alignment: Qt.AlignCenter
  60. text: i18n("There are no pwm capable fans in your system.")
  61. font.pointSize: 14
  62. font.bold: true
  63. }
  64. Button {
  65. Layout.alignment: Qt.AlignCenter
  66. text: loader.sensorsDetected ? i18n("Detect fans again") : i18n("Detect fans")
  67. icon.name: kcm.needsAuthorization ? "dialog-password" : ""
  68. onClicked: loader.detectSensors()
  69. }
  70. }
  71. header: CheckBox {
  72. id: enabledBox
  73. text: i18n("Control fans manually")
  74. checked: systemdCom.serviceEnabled && systemdCom.serviceActive;
  75. onCheckedChanged: {
  76. systemdCom.serviceActive = enabledBox.checked;
  77. loader.restartServiceAfterTesting = checked;
  78. }
  79. Connections {
  80. target: systemdCom
  81. onServiceActiveChanged: if (systemdCom.serviceActive != enabledBox.checked) enabledBox.checked = systemdCom.serviceActive
  82. }
  83. }
  84. Rectangle {
  85. id: fansListViewBackground
  86. Kirigami.Theme.colorSet: Kirigami.Theme.View
  87. anchors {
  88. top: parent.top
  89. bottom: parent.bottom
  90. left: parent.left
  91. }
  92. width: root.width / 5
  93. color: Kirigami.Theme.backgroundColor
  94. visible: enabledBox.checked
  95. border.width: 1
  96. border.color: Kirigami.Theme.textColor
  97. ListView {
  98. id: fansListView
  99. anchors.fill: parent
  100. anchors.margins: fansListViewBackground.border.width
  101. clip: true
  102. boundsBehavior: Flickable.StopAtBounds
  103. flickableDirection: Flickable.AutoFlickIfNeeded
  104. model: pwmFanModel
  105. header: Kirigami.BasicListItem {
  106. label: '<b>' + i18n("Fans") + '</b>'
  107. reserveSpaceForIcon: false
  108. hoverEnabled: false
  109. separatorVisible: false
  110. leftPadding: Kirigami.Units.smallSpacing
  111. }
  112. delegate: Kirigami.BasicListItem {
  113. property QtObject fan: object
  114. label: display
  115. reserveSpaceForIcon: false
  116. hoverEnabled: true
  117. highlighted: ListView.isCurrentItem
  118. separatorVisible: false
  119. onPressedChanged: if (pressed) fansListView.currentIndex = index;
  120. }
  121. }
  122. }
  123. Fancontrol.FanHeader {
  124. id: fanHeader
  125. fan: root.fan
  126. visible: enabledBox.checked
  127. anchors {
  128. top: parent.top
  129. left: fansListViewBackground.right
  130. right: parent.right
  131. margins: Kirigami.Units.smallSpacing
  132. }
  133. }
  134. Loader {
  135. anchors {
  136. top: fanHeader.bottom
  137. left: fansListViewBackground.right
  138. right: parent.right
  139. bottom: settingsColumn.top
  140. }
  141. active: !!root.fan
  142. visible: enabledBox.checked
  143. sourceComponent: Fancontrol.FanItem {
  144. fan: root.fan
  145. }
  146. }
  147. Column {
  148. id: settingsColumn
  149. anchors {
  150. left: fansListViewBackground.right
  151. right: parent.right
  152. bottom: parent.bottom
  153. }
  154. height: childrenRect.height
  155. visible: enabledBox.checked
  156. Item {
  157. id: advancedButton
  158. property bool expanded: false
  159. width: parent.width
  160. height: childrenRect.height
  161. Image {
  162. id: advancedArrow
  163. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  164. fillMode: Image.PreserveAspectFit
  165. height: advancedLabel.implicitHeight
  166. }
  167. Label {
  168. id: advancedLabel
  169. anchors.left: advancedArrow.right
  170. text: i18n("Advanced settings")
  171. font.bold: true
  172. }
  173. MouseArea {
  174. anchors.fill: parent
  175. onClicked: parent.expanded = !parent.expanded
  176. }
  177. }
  178. Fancontrol.SettingsForm {
  179. id: settingsArea
  180. width: parent.width
  181. showAll: false
  182. clip: true
  183. state: advancedButton.expanded ? "VISIBLE" : "HIDDEN"
  184. states: [
  185. State {
  186. name: "VISIBLE"
  187. PropertyChanges {
  188. target: settingsArea
  189. height: implicitHeight
  190. }
  191. },
  192. State {
  193. name: "HIDDEN"
  194. PropertyChanges {
  195. target: settingsArea
  196. height: 0
  197. }
  198. }
  199. ]
  200. transitions: Transition {
  201. NumberAnimation {
  202. properties: "height"
  203. easing.type: Easing.InOutQuad
  204. }
  205. }
  206. }
  207. }
  208. Fancontrol.ErrorDialog {
  209. id: errorDialog
  210. modal: true
  211. anchors.centerIn: root
  212. }
  213. }