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