on 2ef5ca5 help sign in
unity8/tests/mocks/Unity/Indicators/IndicatorsModel.qml
178 lines 7.8 kB history raw
1/*
2 * Copyright (C) 2013 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.0
18import Unity.Indicators 0.1 as Indicators
20Indicators.FakeIndicatorsModel {
21 id: root
23 property var originalModelData: [
24 {
25 "identifier": "fake-indicator-bluetooth",
26 "indicatorProperties": {
27 "enabled": true,
28 "busName": "com.canonical.indicators.fake1",
29 "menuObjectPath": "/com/canonical/indicators/fake1",
30 "actionsObjectPath": "/com/canonical/indicators/fake1"
31 }
32 },
33 {
34 "identifier": "fake-indicator-network",
35 "indicatorProperties": {
36 "enabled": true,
37 "busName": "com.canonical.indicators.fake2",
38 "menuObjectPath": "/com/canonical/indicators/fake2",
39 "actionsObjectPath": "/com/canonical/indicators/fake2"
40 }
41 },
42 {
43 "identifier": "fake-indicator-messages",
44 "indicatorProperties": {
45 "enabled": true,
46 "busName": "com.canonical.indicators.fake3",
47 "menuObjectPath": "/com/canonical/indicators/fake3",
48 "actionsObjectPath": "/com/canonical/indicators/fake3"
49 }
50 },
51 {
52 "identifier": "fake-indicator-sound",
53 "indicatorProperties": {
54 "enabled": true,
55 "busName": "com.canonical.indicators.fake4",
56 "menuObjectPath": "/com/canonical/indicators/fake4",
57 "actionsObjectPath": "/com/canonical/indicators/fake4"
58 }
59 },
60 {
61 "identifier": "fake-indicator-power",
62 "indicatorProperties": {
63 "enabled": true,
64 "busName": "com.canonical.indicators.fake5",
65 "menuObjectPath": "/com/canonical/indicators/fake5",
66 "actionsObjectPath": "/com/canonical/indicators/fake5"
67 }
68 },
69 {
70 "identifier": "fake-indicator-datetime",
71 "indicatorProperties": {
72 "enabled": true,
73 "busName": "com.canonical.indicators.fake6",
74 "menuObjectPath": "/com/canonical/indicators/fake6",
75 "actionsObjectPath": "/com/canonical/indicators/fake6"
76 }
77 }
78 ]
80 function load(profile) {
81 unload();
82 root.modelData = originalModelData;
84 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
85 getUnityMenuModelData("fake-indicator-bluetooth",
86 "Bluetooth (F)",
87 "",
88 [ "image://theme/bluetooth-active" ]));
89 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake2",
90 getUnityMenuModelData("fake-indicator-network",
91 "Network (F)",
92 "",
93 [ "image://theme/simcard-error", "image://theme/wifi-high" ]));
94 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake3",
95 getUnityMenuModelData("fake-indicator-messages",
96 "Messages (F)",
97 "",
98 [ "image://theme/messages-new" ]));
99 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake4",
100 getUnityMenuModelData("fake-indicator-sound",
101 "Sound (F)",
102 "",
103 [ "image://theme/audio-volume-high" ]));
104 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake5",
105 getUnityMenuModelData("fake-indicator-power",
106 "Battery (F)",
107 "",
108 [ "image://theme/battery-020" ]));
109 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake6",
110 getUnityMenuModelData("fake-indicator-datetime",
111 "Upcoming Events (F)",
112 "12:04",
113 []));
114 }
116 function getUnityMenuModelData(identifier, title, label, icons) {
117 var root = [{
118 "rowData": { // 1
119 "label": "",
120 "sensitive": true,
121 "isSeparator": false,
122 "icon": "",
123 "type": "com.canonical.indicator.root",
124 "ext": {},
125 "action": "",
126 "actionState": {
127 "title": title,
128 "label": label,
129 "icons": icons,
130 "visible": true
131 },
132 "isCheck": false,
133 "isRadio": false,
134 "isToggled": false
135 },
136 "submenu": []
137 }];
139 var submenus = [];
140 for (var i = 0; i < 8; i++) {
141 var submenu = {
142 "rowData": { // 1.1
143 "label": identifier,
144 "sensitive": true,
145 "isSeparator": false,
146 "icon": "",
147 "type": undefined,
148 "ext": {},
149 "action": "",
150 "actionState": {},
151 "isCheck": false,
152 "isRadio": false,
153 "isToggled": false
154 }};
155 submenus.push(submenu);
156 }
157 root[0]["submenu"] = submenus;
159 return root;
160 }
162 function setIndicatorVisible(identifier, visible) {
163 for (var i = 0; i < originalModelData.length; i++) {
164 if (originalModelData[i]["identifier"] === identifier) {
165 var data = Indicators.UnityMenuModelCache.getCachedModelData(
166 originalModelData[i]["indicatorProperties"]["menuObjectPath"]);
168 data[0]["rowData"]["actionState"]["visible"] = visible;
170 Indicators.UnityMenuModelCache.setCachedModelData(
171 originalModelData[i]["indicatorProperties"]["menuObjectPath"],
172 data);
173 break;
174 }
175 }
177 }