on bbbdccd help sign in
unity8/tests/qmltests/Stages/ApplicationCheckBox.qml
114 lines 3.2 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import QtQuick.Layouts 1.1
19import Ubuntu.Components 1.3
20import Unity.Application 0.1
22RowLayout {
23 id: root
24 property string appId
25 property bool checked: false
27 enabled: appId !== "unity8-dash"
29 onCheckedChanged: {
30 if (d.bindGuard) { return; }
31 d.bindGuard = true;
33 if (checked) {
34 ApplicationManager.startApplication(root.appId);
35 } else {
36 ApplicationManager.stopApplication(root.appId);
37 }
38 d.bindGuard = false;
39 }
41 QtObject {
42 id: d
43 property bool bindGuard: false
44 property var application: null
45 Component.onCompleted: {
46 application = ApplicationManager.findApplication(root.appId);
47 }
48 }
50 Connections {
51 target: ApplicationManager
52 onCountChanged: {
53 d.application = ApplicationManager.findApplication(root.appId);
54 }
55 }
57 Layout.fillWidth: true
58 CheckBox {
59 id: checkbox
60 checked: false
61 activeFocusOnPress: false
63 onTriggered: {
64 if (d.bindGuard) { return; }
65 d.bindGuard = true;
67 if (checked) {
68 ApplicationManager.startApplication(root.appId);
69 } else {
70 ApplicationManager.stopApplication(root.appId);
71 }
72 d.bindGuard = false;
73 }
74 onCheckedChanged: {
75 if (d.bindGuard) { return; }
76 d.bindGuard = true;
78 root.checked = checked;
80 d.bindGuard = false;
81 }
82 Binding {
83 target: checkbox
84 property: "checked"
85 value: d.application != null
86 }
87 }
88 Label {
89 id: appIdLabel
90 text: root.appId
91 color: "white"
92 anchors.verticalCenter: parent.verticalCenter
93 }
94 Rectangle {
95 color: {
96 if (d.application) {
97 if (d.application.state === ApplicationInfoInterface.Starting) {
98 return "yellow";
99 } else if (d.application.state === ApplicationInfoInterface.Running) {
100 return "green";
101 } else if (d.application.state === ApplicationInfoInterface.Suspended) {
102 return "blue";
103 } else {
104 return "darkred";
105 }
106 } else {
107 return "darkred";
108 }
109 }
110 width: height
111 height: appIdLabel.height * 0.7
112 anchors.verticalCenter: parent.verticalCenter
113 }