KCM.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. Loader {
  53. anchors.centerIn: parent
  54. active: pwmFanModel.length === 0
  55. sourceComponent: Label {
  56. text: i18n("There are no pwm capable fans in your system.\nTry running 'sensors-detect' in a terminal and restart this application.")
  57. horizontalAlignment: Text.AlignHCenter
  58. font.pointSize: 14
  59. font.bold: true
  60. }
  61. }
  62. header: CheckBox {
  63. id: enabledBox
  64. text: i18n("Control fans manually")
  65. checked: systemdCom.serviceEnabled && systemdCom.serviceActive && pwmFanModel.length > 0
  66. enabled: pwmFanModel.length > 0
  67. onCheckedChanged: {
  68. systemdCom.serviceActive = enabledBox.checked;
  69. loader.restartServiceAfterTesting = checked;
  70. }
  71. Connections {
  72. target: systemdCom
  73. onServiceActiveChanged: if (systemdCom.serviceActive != enabledBox.checked) enabledBox.checked = systemdCom.serviceActive
  74. }
  75. }
  76. Rectangle {
  77. id: fansListViewBackground
  78. Kirigami.Theme.colorSet: Kirigami.Theme.View
  79. anchors {
  80. top: parent.top
  81. bottom: parent.bottom
  82. left: parent.left
  83. }
  84. width: root.width / 5
  85. color: Kirigami.Theme.backgroundColor
  86. visible: enabledBox.checked
  87. border.width: 1
  88. border.color: Kirigami.Theme.textColor
  89. ListView {
  90. id: fansListView
  91. anchors.fill: parent
  92. anchors.margins: fansListViewBackground.border.width
  93. boundsBehavior: Flickable.StopAtBounds
  94. flickableDirection: Flickable.AutoFlickIfNeeded
  95. model: pwmFanModel
  96. header: Kirigami.BasicListItem {
  97. label: '<b>' + i18n("Fans") + '</b>'
  98. reserveSpaceForIcon: false
  99. hoverEnabled: false
  100. separatorVisible: false
  101. leftPadding: Kirigami.Units.smallSpacing
  102. }
  103. delegate: Kirigami.BasicListItem {
  104. property QtObject fan: object
  105. label: display
  106. reserveSpaceForIcon: false
  107. hoverEnabled: true
  108. highlighted: ListView.isCurrentItem
  109. separatorVisible: false
  110. onPressedChanged: if (pressed) fansListView.currentIndex = index;
  111. }
  112. }
  113. }
  114. Fancontrol.FanHeader {
  115. id: fanHeader
  116. fan: root.fan
  117. visible: enabledBox.checked
  118. anchors {
  119. top: parent.top
  120. left: fansListViewBackground.right
  121. right: parent.right
  122. margins: Kirigami.Units.smallSpacing
  123. }
  124. }
  125. Loader {
  126. anchors {
  127. top: fanHeader.bottom
  128. left: fansListViewBackground.right
  129. right: parent.right
  130. bottom: settingsColumn.top
  131. }
  132. active: !!root.fan
  133. visible: enabledBox.checked
  134. sourceComponent: Fancontrol.FanItem {
  135. fan: root.fan
  136. }
  137. }
  138. Column {
  139. id: settingsColumn
  140. anchors {
  141. left: fansListViewBackground.right
  142. right: parent.right
  143. bottom: parent.bottom
  144. }
  145. height: childrenRect.height
  146. visible: enabledBox.checked
  147. Item {
  148. id: advancedButton
  149. property bool expanded: false
  150. width: parent.width
  151. height: childrenRect.height
  152. Image {
  153. id: advancedArrow
  154. source: parent.expanded ? "image://icon/go-down" : "image://icon/go-next"
  155. fillMode: Image.PreserveAspectFit
  156. height: advancedLabel.implicitHeight
  157. }
  158. Label {
  159. id: advancedLabel
  160. anchors.left: advancedArrow.right
  161. text: i18n("Advanced settings")
  162. font.bold: true
  163. }
  164. MouseArea {
  165. anchors.fill: parent
  166. onClicked: parent.expanded = !parent.expanded
  167. }
  168. }
  169. Fancontrol.SettingsForm {
  170. id: settingsArea
  171. width: parent.width
  172. showAll: false
  173. clip: true
  174. state: advancedButton.expanded ? "VISIBLE" : "HIDDEN"
  175. states: [
  176. State {
  177. name: "VISIBLE"
  178. PropertyChanges {
  179. target: settingsArea
  180. height: implicitHeight
  181. }
  182. },
  183. State {
  184. name: "HIDDEN"
  185. PropertyChanges {
  186. target: settingsArea
  187. height: 0
  188. }
  189. }
  190. ]
  191. transitions: Transition {
  192. NumberAnimation {
  193. properties: "height"
  194. easing.type: Easing.InOutQuad
  195. }
  196. }
  197. }
  198. }
  199. Fancontrol.ErrorDialog {
  200. id: errorDialog
  201. modal: true
  202. anchors.centerIn: root
  203. }
  204. }