on eba99af help sign in
unity8/tests/mocks/Unity/Indicators/IndicatorsModel.qml
261 lines 12 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.4
18import Unity.Indicators 0.1 as Indicators
19import Unity.InputInfo 0.1
20import AccountsService 0.1
21import "fakeindicatorsmodeldata.js" as FakeIndicators
23Indicators.FakeIndicatorsModel {
24 id: root
26 property var light: false
28 onLightChanged: load()
30 property var originalModelData: [
31 {
32 "identifier": "indicator-keyboard",
33 "indicatorProperties": {
34 "enabled": true,
35 "busName": "com.canonical.indicators.fake0",
36 "menuObjectPath": "/com/canonical/indicators/fake0",
37 "actionsObjectPath": "/com/canonical/indicators/fake0"
38 }
39 },
40 {
41 "identifier": "fake-indicator-bluetooth",
42 "indicatorProperties": {
43 "enabled": true,
44 "busName": "com.canonical.indicators.fake1",
45 "menuObjectPath": "/com/canonical/indicators/fake1",
46 "actionsObjectPath": "/com/canonical/indicators/fake1"
47 }
48 },
49 {
50 "identifier": "fake-indicator-network",
51 "indicatorProperties": {
52 "enabled": true,
53 "busName": "com.canonical.indicators.fake2",
54 "menuObjectPath": "/com/canonical/indicators/fake2",
55 "actionsObjectPath": "/com/canonical/indicators/fake2"
56 }
57 },
58 {
59 "identifier": "fake-indicator-messages",
60 "indicatorProperties": {
61 "enabled": true,
62 "busName": "com.canonical.indicators.fake3",
63 "menuObjectPath": "/com/canonical/indicators/fake3",
64 "actionsObjectPath": "/com/canonical/indicators/fake3"
65 }
66 },
67 {
68 "identifier": "fake-indicator-files",
69 "indicatorProperties": {
70 "enabled": true,
71 "busName": "com.canonical.indicators.fake4",
72 "menuObjectPath": "/com/canonical/indicators/fake4",
73 "actionsObjectPath": "/com/canonical/indicators/fake4"
74 }
75 },
76 {
77 "identifier": "fake-indicator-sound",
78 "indicatorProperties": {
79 "enabled": true,
80 "busName": "com.canonical.indicators.fake5",
81 "menuObjectPath": "/com/canonical/indicators/fake5",
82 "actionsObjectPath": "/com/canonical/indicators/fake5"
83 }
84 },
85 {
86 "identifier": "fake-indicator-power",
87 "indicatorProperties": {
88 "enabled": true,
89 "busName": "com.canonical.indicators.fake6",
90 "menuObjectPath": "/com/canonical/indicators/fake6",
91 "actionsObjectPath": "/com/canonical/indicators/fake6"
92 }
93 },
94 {
95 "identifier": "fake-indicator-datetime",
96 "indicatorProperties": {
97 "enabled": true,
98 "busName": "com.canonical.indicators.fake7",
99 "menuObjectPath": "/com/canonical/indicators/fake7",
100 "actionsObjectPath": "/com/canonical/indicators/fake7"
101 }
102 },
103 {
104 "identifier": "fake-indicator-session",
105 "indicatorProperties": {
106 "enabled": true,
107 "busName": "com.canonical.indicators.fake8",
108 "menuObjectPath": "/com/canonical/indicators/fake8",
109 "actionsObjectPath": "/com/canonical/indicators/fake8"
110 }
111 }
112 ]
114 Component.onCompleted: {
115 // init data for the fake indicator-keyboard
116 MockInputDeviceBackend.addMockDevice("/indicator_kbd0", InputInfo.Keyboard);
117 AccountsService.keymaps = ["us", "cs"];
118 }
120 Component.onDestruction: {
121 MockInputDeviceBackend.removeDevice("/indicator_kbd0");
122 AccountsService.keymaps = ["us"];
123 }
125 function load(profile) {
126 unload();
127 root.modelData = originalModelData;
129 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake0",
130 getUnityMenuModelData("indicator-keyboard",
131 "English (F)",
132 "",
133 [ "image://theme/input-keyboard-symbolic" ],
134 root.light));
135 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
136 getUnityMenuModelData("fake-indicator-bluetooth",
137 "Bluetooth (F)",
138 "",
139 [ "image://theme/bluetooth-active" ],
140 root.light));
141 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake2",
142 getUnityMenuModelData("fake-indicator-network",
143 "Network (F)",
144 "",
145 [ "image://theme/simcard-error", "image://theme/wifi-high" ],
146 root.light));
147 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake3",
148 getUnityMenuModelData("fake-indicator-messages",
149 "Messages (F)",
150 "",
151 [ "image://theme/messages-new" ],
152 root.light));
153 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake4",
154 getUnityMenuModelData("fake-indicator-files",
155 "Files (F)",
156 "",
157 [ "image://theme/transfer-progress" ],
158 root.light));
159 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake5",
160 getUnityMenuModelData("fake-indicator-sound",
161 "Sound (F)",
162 "",
163 [ "image://theme/audio-volume-high" ],
164 root.light));
165 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake6",
166 getUnityMenuModelData("fake-indicator-power",
167 "Battery (F)",
168 "",
169 [ "image://theme/battery-020" ],
170 root.light));
171 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake7",
172 getUnityMenuModelData("fake-indicator-datetime",
173 "Upcoming Events (F)",
174 "12:04",
175 [],
176 root.light));
177 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake8",
178 getUnityMenuModelData("fake-indicator-session",
179 "System (F)",
180 "",
181 ["image://theme/system-devices-panel"],
182 root.light));
183 }
185 function getUnityMenuModelData(identifier, title, label, icons, light) {
186 var menudata = undefined;
187 var maxItems = 1;
188 if (!light) {
189 var menudata = FakeIndicators.fakeMenuData[identifier];
190 maxItems = 8;
191 }
193 if (menudata !== undefined) {
194 var rootState = menudata[0]["rowData"].actionState;
195 rootState.title = title;
196 rootState.label = label;
197 rootState.icons = icons;
198 return menudata;
199 }
201 var root = [{
202 "rowData": { // 1
203 "label": "",
204 "sensitive": true,
205 "isSeparator": false,
206 "icon": "",
207 "type": "com.canonical.indicator.root",
208 "ext": {},
209 "action": "",
210 "actionState": {
211 "title": title,
212 "label": label,
213 "icons": icons,
214 "visible": true
215 },
216 "isCheck": false,
217 "isRadio": false,
218 "isToggled": false
219 },
220 "submenu": []
221 }];
223 var submenus = [];
224 for (var i = 0; i < maxItems; i++) {
225 var submenu = {
226 "rowData": { // 1.1
227 "label": identifier,
228 "sensitive": true,
229 "isSeparator": false,
230 "icon": "",
231 "type": undefined,
232 "ext": {},
233 "action": "",
234 "actionState": {},
235 "isCheck": false,
236 "isRadio": false,
237 "isToggled": false
238 }};
239 submenus.push(submenu);
240 }
241 root[0]["submenu"] = submenus;
243 return root;
244 }
246 function setIndicatorVisible(identifier, visible) {
247 for (var i = 0; i < originalModelData.length; i++) {
248 if (originalModelData[i]["identifier"] === identifier) {
249 var data = Indicators.UnityMenuModelCache.getCachedModelData(
250 originalModelData[i]["indicatorProperties"]["menuObjectPath"]);
252 data[0]["rowData"]["actionState"]["visible"] = visible;
254 Indicators.UnityMenuModelCache.setCachedModelData(
255 originalModelData[i]["indicatorProperties"]["menuObjectPath"],
256 data);
257 break;
258 }
259 }
260 }