2
0

Application.qml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 org.kde.kirigami 2.3 as Kirigami
  23. import Fancontrol.Gui 1.0 as Gui
  24. import Fancontrol.Qml 1.0 as Fancontrol
  25. Kirigami.ApplicationWindow {
  26. id: window
  27. property string leftPage
  28. readonly property QtObject pwmFanModel: Fancontrol.Base.pwmFanModel
  29. property QtObject fan: pwmFanModel.length > 0 ? pwmFanModel.fan(0) : null
  30. function showWindow() {
  31. window.show()
  32. window.raise()
  33. window.requestActivate()
  34. }
  35. title: i18n("Fancontrol-GUI")
  36. minimumWidth: Kirigami.Units.gridUnit * 20
  37. minimumHeight: Kirigami.Units.gridUnit * 15
  38. reachableModeEnabled: false
  39. pageStack.defaultColumnWidth: Kirigami.Units.gridUnit * 25
  40. onLeftPageChanged: {
  41. window.pageStack.clear();
  42. if (leftPage) {
  43. var url = Qt.resolvedUrl(leftPage);
  44. var component = Qt.createComponent(url);
  45. if (component.status == Component.Ready) {
  46. var page = component.createObject(window.pageStack);
  47. if (page)
  48. window.pageStack.push(page);
  49. else
  50. console.log("Error creating page object: %1", url);
  51. } else {
  52. console.log("Error creating page component: %1", component.errorString());
  53. }
  54. }
  55. }
  56. onWideScreenChanged: drawer.drawerOpen = wideScreen
  57. // onClosing: {
  58. // if (Fancontrol.Base.needsApply && !saveOnCloseDialog.answered) {
  59. // close.accepted = false;
  60. // saveOnCloseDialog.open();
  61. // return;
  62. // }
  63. // }
  64. Component.onCompleted: {
  65. Fancontrol.Base.load();
  66. window.visible = !Fancontrol.Base.startMinimized;
  67. leftPage = "SensorsTab.qml";
  68. }
  69. globalDrawer: Kirigami.GlobalDrawer {
  70. id: drawer
  71. width: Kirigami.Units.gridUnit * 10
  72. modal: !window.wideScreen
  73. handleVisible: !window.wideScreen
  74. resetMenuOnTriggered: false
  75. function populateFans() {
  76. for (var i=fansAction.children.length-1; i>=0; i--) {
  77. fansAction.children[i].destroy();
  78. }
  79. var actions = [];
  80. for (var i=0; i<20; i++) {
  81. var action = fanActionComponent.createObject(fansAction, { "index": i });
  82. if (action)
  83. actions.push(action);
  84. else
  85. console.log("Error creating fan action with index %1", i);
  86. }
  87. fansAction.children = actions;
  88. }
  89. Component {
  90. id: fanActionComponent
  91. Kirigami.Action {
  92. property int index
  93. property QtObject fan: pwmFanModel.fan(index)
  94. text: !!fan ? fan.name : ""
  95. visible: !!fan
  96. checked: window.fan === fan
  97. onTriggered: window.fan = fan
  98. }
  99. }
  100. Component.onCompleted: populateFans()
  101. Connections {
  102. target: pwmFanModel
  103. onFansChanged: {
  104. for (var i=0; i<pwmFanModel.length && i<fansAction.children.length; i++) {
  105. fansAction.children[i].fan = pwmFanModel.fan(i);
  106. }
  107. }
  108. }
  109. actions: [
  110. Kirigami.Action {
  111. text: i18n("Sensors")
  112. checked: window.leftPage === "SensorsTab.qml"
  113. onTriggered: window.leftPage = "SensorsTab.qml"
  114. },
  115. Kirigami.Action {
  116. id: fansAction
  117. text: i18n("Fans")
  118. checked: window.leftPage === "PwmFansTab.qml"
  119. onTriggered: window.leftPage = "PwmFansTab.qml"
  120. },
  121. Kirigami.Action {
  122. text: i18n("Configfile")
  123. checked: window.leftPage === "ConfigfileTab.qml"
  124. onTriggered: window.leftPage = "ConfigfileTab.qml"
  125. },
  126. Kirigami.Action {
  127. text: i18n("Settings")
  128. checked: window.leftPage === "SettingsTab.qml"
  129. onTriggered: window.leftPage = "SettingsTab.qml"
  130. }
  131. ]
  132. }
  133. contextDrawer: Kirigami.ContextDrawer {}
  134. Loader {
  135. id: trayLoader
  136. active: Fancontrol.Base.showTray
  137. sourceComponent: Component {
  138. Gui.SystemTrayIcon {
  139. title: "Fancontrol-GUI"
  140. iconName: "org.kde.fancontrol.gui"
  141. profileModel: Fancontrol.Base.profileModel
  142. onActivateRequested: window.showWindow()
  143. onActivateProfile: {
  144. Fancontrol.Base.applyProfile(profile);
  145. Fancontrol.Base.apply();
  146. }
  147. }
  148. }
  149. }
  150. Fancontrol.ErrorDialog {
  151. id: errorDialog
  152. visible: false
  153. x: (parent.width - width) / 2
  154. y: (parent.height - height) / 2
  155. }
  156. // Dialog {
  157. // id: saveOnCloseDialog
  158. //
  159. // property bool answered: false
  160. //
  161. // visible: false
  162. // modal: true
  163. // title: i18n("Unsaved changes")
  164. // standardButtons: Dialog.Cancel | Dialog.Discard | Dialog.Apply
  165. // x: (window.width - width) / 2
  166. // y: (window.height - height) / 2
  167. //
  168. // onRejected: close()
  169. // onDiscarded: {
  170. // answered = true;
  171. // close();
  172. // window.close();
  173. // }
  174. // onApplied: {
  175. // Fancontrol.Base.apply();
  176. // answered = true;
  177. // close();
  178. // window.close();
  179. // }
  180. //
  181. // Label {
  182. // id: text
  183. // anchors.centerIn: parent
  184. // text: i18n("There are unsaved changes.\nDo you want to apply these changes?")
  185. // }
  186. // }
  187. }