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