Merge lp:~stolowski/unity-scope-click/departments into lp:unity-scope-click/devel
- departments
- Merge into devel
Status: | Superseded |
---|---|
Proposed branch: | lp:~stolowski/unity-scope-click/departments |
Merge into: | lp:unity-scope-click/devel |
Diff against target: |
2394 lines (+1473/-114) (has conflicts) 33 files modified
CMakeLists.txt (+1/-1) debian/control (+1/-1) libclickscope/click/CMakeLists.txt (+3/-0) libclickscope/click/department-lookup.cpp (+84/-0) libclickscope/click/department-lookup.h (+58/-0) libclickscope/click/departments.cpp (+164/-0) libclickscope/click/departments.h (+83/-0) libclickscope/click/highlights.cpp (+95/-0) libclickscope/click/highlights.h (+72/-0) libclickscope/click/index.cpp (+70/-5) libclickscope/click/index.h (+7/-2) libclickscope/click/package.h (+1/-0) libclickscope/click/preview.cpp (+1/-0) libclickscope/click/scope_activation.cpp (+11/-5) libclickscope/click/scope_activation.h (+2/-2) libclickscope/click/webclient.cpp (+2/-1) libclickscope/click/webclient.h (+1/-1) libclickscope/tests/CMakeLists.txt (+2/-0) libclickscope/tests/fake_json.h (+236/-0) libclickscope/tests/mock_network_access_manager.h (+1/-0) libclickscope/tests/mock_webclient.h (+2/-2) libclickscope/tests/test_bootstrap.cpp (+73/-0) libclickscope/tests/test_departments.cpp (+108/-0) libclickscope/tests/test_index.cpp (+10/-10) scope/clickapps/apps-query.cpp (+11/-12) scope/clickapps/apps-scope.cpp (+5/-6) scope/clickapps/apps-scope.h (+3/-3) scope/clickstore/store-query.cpp (+233/-16) scope/clickstore/store-query.h (+16/-3) scope/clickstore/store-scope.cpp (+25/-5) scope/clickstore/store-scope.h (+12/-2) scope/tests/integration/webclient_integration.cpp (+3/-1) scope/tests/test_query.cpp (+77/-36) Text conflict in scope/clickstore/store-scope.cpp |
To merge this branch: | bzr merge lp:~stolowski/unity-scope-click/departments |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
dobey (community) | Needs Fixing | ||
Review via email: mp+219211@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-06-18.
Commit message
Add support for departments and highlights.
Description of the change
Add support for departments and highlights.
dobey (dobey) wrote : | # |
Can you also add a commit with --fixes=lp:1209224 to link that bug?
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:254
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
dobey (dobey) wrote : | # |
This conflicts with the changes in https:/
- 255. By Paweł Stołowski
-
Forgot about highlights.
- 256. By Paweł Stołowski
-
Merged 0.5.0 update branch.
- 257. By Paweł Stołowski
-
Merged devel.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:255
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 258. By Paweł Stołowski
-
Reuse code between bootstrap and departments call.
- 259. By Paweł Stołowski
-
Cleanups. Check department href in tests.
- 260. By Paweł Stołowski
-
Test get_department_
info(). - 261. By Paweł Stołowski
-
Added tests for broken departments json.
- 262. By Paweł Stołowski
-
Don't pass departments with search.
- 263. By Paweł Stołowski
-
Test for invalid highlights. Cleanups.
- 264. By Paweł Stołowski
-
Reuse push_package().
- 265. By Paweł Stołowski
-
Fixed comment.
- 266. By Paweł Stołowski
-
Test bootstrap call.
- 267. By Paweł Stołowski
-
Merged devel.
Unmerged revisions
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-05-27 13:15:52 +0000 | |||
3 | +++ CMakeLists.txt 2014-06-18 18:08:01 +0000 | |||
4 | @@ -21,7 +21,7 @@ | |||
5 | 21 | 21 | ||
6 | 22 | include(FindPkgConfig) | 22 | include(FindPkgConfig) |
7 | 23 | 23 | ||
9 | 24 | pkg_check_modules(UNITY_SCOPES REQUIRED libunity-scopes>=0.4.0 libunity-api>=0.1.3) | 24 | pkg_check_modules(UNITY_SCOPES REQUIRED libunity-scopes>=0.5.0 libunity-api>=0.1.3) |
10 | 25 | add_definitions(${UNITY_SCOPES_CFLAGS} ${UNITY_SCOPES_CFLAGS_OTHER}) | 25 | add_definitions(${UNITY_SCOPES_CFLAGS} ${UNITY_SCOPES_CFLAGS_OTHER}) |
11 | 26 | 26 | ||
12 | 27 | find_package (PkgConfig REQUIRED) | 27 | find_package (PkgConfig REQUIRED) |
13 | 28 | 28 | ||
14 | === modified file 'debian/control' | |||
15 | --- debian/control 2014-06-13 15:21:16 +0000 | |||
16 | +++ debian/control 2014-06-18 18:08:01 +0000 | |||
17 | @@ -13,7 +13,7 @@ | |||
18 | 13 | libubuntu-download-manager-common-dev (>= 0.3+14.10.20140430-0ubuntu1), | 13 | libubuntu-download-manager-common-dev (>= 0.3+14.10.20140430-0ubuntu1), |
19 | 14 | libubuntuoneauth-2.0-dev, | 14 | libubuntuoneauth-2.0-dev, |
20 | 15 | libunity-api-dev (>= 7.80.7), | 15 | libunity-api-dev (>= 7.80.7), |
22 | 16 | libunity-scopes-dev (>= 0.4.0), | 16 | libunity-scopes-dev (>= 0.5.0), |
23 | 17 | pkg-config, | 17 | pkg-config, |
24 | 18 | python3-all, | 18 | python3-all, |
25 | 19 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 19 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
26 | 20 | 20 | ||
27 | === modified file 'libclickscope/click/CMakeLists.txt' | |||
28 | --- libclickscope/click/CMakeLists.txt 2014-06-13 15:21:16 +0000 | |||
29 | +++ libclickscope/click/CMakeLists.txt 2014-06-18 18:08:01 +0000 | |||
30 | @@ -11,6 +11,9 @@ | |||
31 | 11 | add_library(${SCOPE_LIB_NAME} STATIC | 11 | add_library(${SCOPE_LIB_NAME} STATIC |
32 | 12 | configuration.cpp | 12 | configuration.cpp |
33 | 13 | download-manager.cpp | 13 | download-manager.cpp |
34 | 14 | department-lookup.cpp | ||
35 | 15 | departments.cpp | ||
36 | 16 | highlights.cpp | ||
37 | 14 | index.cpp | 17 | index.cpp |
38 | 15 | interface.cpp | 18 | interface.cpp |
39 | 16 | key_file_locator.cpp | 19 | key_file_locator.cpp |
40 | 17 | 20 | ||
41 | === added file 'libclickscope/click/department-lookup.cpp' | |||
42 | --- libclickscope/click/department-lookup.cpp 1970-01-01 00:00:00 +0000 | |||
43 | +++ libclickscope/click/department-lookup.cpp 2014-06-18 18:08:01 +0000 | |||
44 | @@ -0,0 +1,84 @@ | |||
45 | 1 | /* | ||
46 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
47 | 3 | * | ||
48 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
49 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
50 | 6 | * by the Free Software Foundation. | ||
51 | 7 | * | ||
52 | 8 | * This program is distributed in the hope that it will be useful, but | ||
53 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
54 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
55 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
56 | 12 | * | ||
57 | 13 | * You should have received a copy of the GNU General Public License along | ||
58 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
59 | 15 | * | ||
60 | 16 | * In addition, as a special exception, the copyright holders give | ||
61 | 17 | * permission to link the code of portions of this program with the | ||
62 | 18 | * OpenSSL library under certain conditions as described in each | ||
63 | 19 | * individual source file, and distribute linked combinations | ||
64 | 20 | * including the two. | ||
65 | 21 | * You must obey the GNU General Public License in all respects | ||
66 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
67 | 23 | * file(s) with this exception, you may extend this exception to your | ||
68 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
69 | 25 | * do not wish to do so, delete this exception statement from your | ||
70 | 26 | * version. If you delete this exception statement from all source | ||
71 | 27 | * files in the program, then also delete it here. | ||
72 | 28 | */ | ||
73 | 29 | |||
74 | 30 | #include "department-lookup.h" | ||
75 | 31 | |||
76 | 32 | namespace click | ||
77 | 33 | { | ||
78 | 34 | |||
79 | 35 | DepartmentLookup::DepartmentLookup() | ||
80 | 36 | { | ||
81 | 37 | } | ||
82 | 38 | |||
83 | 39 | void DepartmentLookup::rebuild(const Department::SPtr& dept) | ||
84 | 40 | { | ||
85 | 41 | departments[dept->id()] = dept; | ||
86 | 42 | for (auto const& subdep: dept->sub_departments()) | ||
87 | 43 | { | ||
88 | 44 | parent_lut[subdep->id()] = dept; | ||
89 | 45 | rebuild(subdep); | ||
90 | 46 | } | ||
91 | 47 | } | ||
92 | 48 | |||
93 | 49 | void DepartmentLookup::rebuild(const std::list<Department::SPtr>& root_departments) | ||
94 | 50 | { | ||
95 | 51 | parent_lut.clear(); | ||
96 | 52 | departments.clear(); | ||
97 | 53 | for (auto const& dep: root_departments) | ||
98 | 54 | { | ||
99 | 55 | rebuild(dep); | ||
100 | 56 | } | ||
101 | 57 | } | ||
102 | 58 | |||
103 | 59 | Department::SPtr DepartmentLookup::get_parent(const std::string& department_id) const | ||
104 | 60 | { | ||
105 | 61 | auto it = parent_lut.find(department_id); | ||
106 | 62 | if (it != parent_lut.end()) | ||
107 | 63 | { | ||
108 | 64 | return it->second; | ||
109 | 65 | } | ||
110 | 66 | return Department::SPtr(nullptr); | ||
111 | 67 | } | ||
112 | 68 | |||
113 | 69 | Department::SPtr DepartmentLookup::get_department_info(const std::string& department_id) const | ||
114 | 70 | { | ||
115 | 71 | auto it = departments.find(department_id); | ||
116 | 72 | if (it != departments.end()) | ||
117 | 73 | { | ||
118 | 74 | return it->second; | ||
119 | 75 | } | ||
120 | 76 | return nullptr; | ||
121 | 77 | } | ||
122 | 78 | |||
123 | 79 | int DepartmentLookup::size() const | ||
124 | 80 | { | ||
125 | 81 | return parent_lut.size(); | ||
126 | 82 | } | ||
127 | 83 | |||
128 | 84 | } | ||
129 | 0 | 85 | ||
130 | === added file 'libclickscope/click/department-lookup.h' | |||
131 | --- libclickscope/click/department-lookup.h 1970-01-01 00:00:00 +0000 | |||
132 | +++ libclickscope/click/department-lookup.h 2014-06-18 18:08:01 +0000 | |||
133 | @@ -0,0 +1,58 @@ | |||
134 | 1 | /* | ||
135 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
136 | 3 | * | ||
137 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
138 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
139 | 6 | * by the Free Software Foundation. | ||
140 | 7 | * | ||
141 | 8 | * This program is distributed in the hope that it will be useful, but | ||
142 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
143 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
144 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
145 | 12 | * | ||
146 | 13 | * You should have received a copy of the GNU General Public License along | ||
147 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
148 | 15 | * | ||
149 | 16 | * In addition, as a special exception, the copyright holders give | ||
150 | 17 | * permission to link the code of portions of this program with the | ||
151 | 18 | * OpenSSL library under certain conditions as described in each | ||
152 | 19 | * individual source file, and distribute linked combinations | ||
153 | 20 | * including the two. | ||
154 | 21 | * You must obey the GNU General Public License in all respects | ||
155 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
156 | 23 | * file(s) with this exception, you may extend this exception to your | ||
157 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
158 | 25 | * do not wish to do so, delete this exception statement from your | ||
159 | 26 | * version. If you delete this exception statement from all source | ||
160 | 27 | * files in the program, then also delete it here. | ||
161 | 28 | */ | ||
162 | 29 | |||
163 | 30 | #ifndef CLICK_DEPARTMENT_LOOKUP_H | ||
164 | 31 | #define CLICK_DEPARTMENT_LOOKUP_H | ||
165 | 32 | |||
166 | 33 | #include "departments.h" | ||
167 | 34 | #include <string> | ||
168 | 35 | #include <memory> | ||
169 | 36 | #include <map> | ||
170 | 37 | |||
171 | 38 | namespace click | ||
172 | 39 | { | ||
173 | 40 | |||
174 | 41 | class DepartmentLookup | ||
175 | 42 | { | ||
176 | 43 | public: | ||
177 | 44 | DepartmentLookup(); | ||
178 | 45 | void rebuild(const std::list<Department::SPtr>& root_departments); | ||
179 | 46 | Department::SPtr get_parent(const std::string& department_id) const; | ||
180 | 47 | Department::SPtr get_department_info(const std::string& department_id) const; | ||
181 | 48 | int size() const; | ||
182 | 49 | |||
183 | 50 | private: | ||
184 | 51 | void rebuild(const Department::SPtr& dept); | ||
185 | 52 | std::map<std::string, Department::SPtr> parent_lut; | ||
186 | 53 | std::map<std::string, Department::SPtr> departments; | ||
187 | 54 | }; | ||
188 | 55 | |||
189 | 56 | } | ||
190 | 57 | |||
191 | 58 | #endif | ||
192 | 0 | 59 | ||
193 | === added file 'libclickscope/click/departments.cpp' | |||
194 | --- libclickscope/click/departments.cpp 1970-01-01 00:00:00 +0000 | |||
195 | +++ libclickscope/click/departments.cpp 2014-06-18 18:08:01 +0000 | |||
196 | @@ -0,0 +1,164 @@ | |||
197 | 1 | /* | ||
198 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
199 | 3 | * | ||
200 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
201 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
202 | 6 | * by the Free Software Foundation. | ||
203 | 7 | * | ||
204 | 8 | * This program is distributed in the hope that it will be useful, but | ||
205 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
206 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
207 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
208 | 12 | * | ||
209 | 13 | * You should have received a copy of the GNU General Public License along | ||
210 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
211 | 15 | * | ||
212 | 16 | * In addition, as a special exception, the copyright holders give | ||
213 | 17 | * permission to link the code of portions of this program with the | ||
214 | 18 | * OpenSSL library under certain conditions as described in each | ||
215 | 19 | * individual source file, and distribute linked combinations | ||
216 | 20 | * including the two. | ||
217 | 21 | * You must obey the GNU General Public License in all respects | ||
218 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
219 | 23 | * file(s) with this exception, you may extend this exception to your | ||
220 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
221 | 25 | * do not wish to do so, delete this exception statement from your | ||
222 | 26 | * version. If you delete this exception statement from all source | ||
223 | 27 | * files in the program, then also delete it here. | ||
224 | 28 | */ | ||
225 | 29 | |||
226 | 30 | #include "departments.h" | ||
227 | 31 | #include <iostream> | ||
228 | 32 | |||
229 | 33 | namespace click | ||
230 | 34 | { | ||
231 | 35 | |||
232 | 36 | /*Department::Department(const std::string& id, const std::string& name) | ||
233 | 37 | : id_(id), | ||
234 | 38 | name_(name), | ||
235 | 39 | href_(""), //FIXME | ||
236 | 40 | has_children_flag_(false) | ||
237 | 41 | { | ||
238 | 42 | }*/ | ||
239 | 43 | |||
240 | 44 | Department::Department(const std::string& id, const std::string &name, const std::string& href, bool has_children) | ||
241 | 45 | : id_(id), | ||
242 | 46 | name_(name), | ||
243 | 47 | href_(href), | ||
244 | 48 | has_children_flag_(has_children) | ||
245 | 49 | { | ||
246 | 50 | } | ||
247 | 51 | |||
248 | 52 | std::string Department::id() const | ||
249 | 53 | { | ||
250 | 54 | return id_; | ||
251 | 55 | } | ||
252 | 56 | |||
253 | 57 | std::string Department::name() const | ||
254 | 58 | { | ||
255 | 59 | return name_; | ||
256 | 60 | } | ||
257 | 61 | |||
258 | 62 | std::string Department::href() const | ||
259 | 63 | { | ||
260 | 64 | return href_; | ||
261 | 65 | } | ||
262 | 66 | |||
263 | 67 | bool Department::has_children_flag() const | ||
264 | 68 | { | ||
265 | 69 | return has_children_flag_; | ||
266 | 70 | } | ||
267 | 71 | |||
268 | 72 | void Department::set_subdepartments(const std::list<Department::SPtr>& deps) | ||
269 | 73 | { | ||
270 | 74 | sub_departments_ = deps; | ||
271 | 75 | } | ||
272 | 76 | |||
273 | 77 | std::list<Department::SPtr> Department::sub_departments() const | ||
274 | 78 | { | ||
275 | 79 | return sub_departments_; | ||
276 | 80 | } | ||
277 | 81 | |||
278 | 82 | std::list<Department::SPtr> Department::from_json_node(const Json::Value& node) | ||
279 | 83 | { | ||
280 | 84 | std::list<Department::SPtr> deps; | ||
281 | 85 | |||
282 | 86 | for (uint i = 0; i < node.size(); i++) | ||
283 | 87 | { | ||
284 | 88 | auto const item = node[i]; | ||
285 | 89 | if (item.isObject() && item.isMember(Department::JsonKeys::name)) | ||
286 | 90 | { | ||
287 | 91 | auto name = item[Department::JsonKeys::name].asString(); | ||
288 | 92 | const bool has_children = item.isMember(Department::JsonKeys::has_children) ? item[Department::JsonKeys::has_children].asBool() : false; | ||
289 | 93 | |||
290 | 94 | auto const links = item[Department::JsonKeys::links]; | ||
291 | 95 | auto const self = links[Department::JsonKeys::self]; | ||
292 | 96 | auto const href = self[Department::JsonKeys::href].asString(); | ||
293 | 97 | |||
294 | 98 | auto dep = std::make_shared<Department>(name, name, href, has_children); //FIXME: id | ||
295 | 99 | if (item.isObject() && item.isMember(Department::JsonKeys::embedded)) | ||
296 | 100 | { | ||
297 | 101 | auto const emb = item[Department::JsonKeys::embedded]; | ||
298 | 102 | if (emb.isObject() && emb.isMember(Department::JsonKeys::department)) | ||
299 | 103 | { | ||
300 | 104 | auto const ditem = emb[Department::JsonKeys::department]; | ||
301 | 105 | auto const subdeps = from_json_node(ditem); | ||
302 | 106 | dep->set_subdepartments(subdeps); | ||
303 | 107 | } | ||
304 | 108 | } | ||
305 | 109 | deps.push_back(dep); | ||
306 | 110 | } | ||
307 | 111 | } | ||
308 | 112 | |||
309 | 113 | return deps; | ||
310 | 114 | } | ||
311 | 115 | |||
312 | 116 | std::list<Department::SPtr> Department::from_json_root_node(const Json::Value& root) | ||
313 | 117 | { | ||
314 | 118 | if (root.isObject() && root.isMember(Department::JsonKeys::embedded)) | ||
315 | 119 | { | ||
316 | 120 | auto const emb = root[Department::JsonKeys::embedded]; | ||
317 | 121 | if (emb.isObject() && emb.isMember(Department::JsonKeys::department)) | ||
318 | 122 | { | ||
319 | 123 | auto const ditem = emb[Department::JsonKeys::department]; | ||
320 | 124 | return from_json_node(ditem); | ||
321 | 125 | } | ||
322 | 126 | } | ||
323 | 127 | |||
324 | 128 | return std::list<Department::SPtr>(); | ||
325 | 129 | } | ||
326 | 130 | |||
327 | 131 | std::list<Department::SPtr> Department::from_json(const std::string& json) | ||
328 | 132 | { | ||
329 | 133 | Json::Reader reader; | ||
330 | 134 | Json::Value root; | ||
331 | 135 | |||
332 | 136 | try | ||
333 | 137 | { | ||
334 | 138 | if (!reader.parse(json, root)) { | ||
335 | 139 | throw std::runtime_error(reader.getFormattedErrorMessages()); | ||
336 | 140 | } | ||
337 | 141 | |||
338 | 142 | if (root.isObject() && root.isMember(Department::JsonKeys::embedded)) | ||
339 | 143 | { | ||
340 | 144 | auto const emb = root[Department::JsonKeys::embedded]; | ||
341 | 145 | if (emb.isObject() && emb.isMember(Department::JsonKeys::department)) | ||
342 | 146 | { | ||
343 | 147 | auto const ditem = emb[Department::JsonKeys::department]; | ||
344 | 148 | return from_json_node(ditem); | ||
345 | 149 | } | ||
346 | 150 | } | ||
347 | 151 | } | ||
348 | 152 | catch (const std::exception& e) | ||
349 | 153 | { | ||
350 | 154 | std::cerr << "Error parsing departments: " << e.what() << std::endl; | ||
351 | 155 | } | ||
352 | 156 | catch (...) | ||
353 | 157 | { | ||
354 | 158 | std::cerr << "Unknown error when parsing departments" << std::endl; | ||
355 | 159 | } | ||
356 | 160 | |||
357 | 161 | return std::list<Department::SPtr>(); | ||
358 | 162 | } | ||
359 | 163 | |||
360 | 164 | } | ||
361 | 0 | 165 | ||
362 | === added file 'libclickscope/click/departments.h' | |||
363 | --- libclickscope/click/departments.h 1970-01-01 00:00:00 +0000 | |||
364 | +++ libclickscope/click/departments.h 2014-06-18 18:08:01 +0000 | |||
365 | @@ -0,0 +1,83 @@ | |||
366 | 1 | /* | ||
367 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
368 | 3 | * | ||
369 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
370 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
371 | 6 | * by the Free Software Foundation. | ||
372 | 7 | * | ||
373 | 8 | * This program is distributed in the hope that it will be useful, but | ||
374 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
375 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
376 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
377 | 12 | * | ||
378 | 13 | * You should have received a copy of the GNU General Public License along | ||
379 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
380 | 15 | * | ||
381 | 16 | * In addition, as a special exception, the copyright holders give | ||
382 | 17 | * permission to link the code of portions of this program with the | ||
383 | 18 | * OpenSSL library under certain conditions as described in each | ||
384 | 19 | * individual source file, and distribute linked combinations | ||
385 | 20 | * including the two. | ||
386 | 21 | * You must obey the GNU General Public License in all respects | ||
387 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
388 | 23 | * file(s) with this exception, you may extend this exception to your | ||
389 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
390 | 25 | * do not wish to do so, delete this exception statement from your | ||
391 | 26 | * version. If you delete this exception statement from all source | ||
392 | 27 | * files in the program, then also delete it here. | ||
393 | 28 | */ | ||
394 | 29 | |||
395 | 30 | #ifndef CLICK_DEPARTMENTS_H | ||
396 | 31 | #define CLICK_DEPARTMENTS_H | ||
397 | 32 | |||
398 | 33 | #include <string> | ||
399 | 34 | #include <list> | ||
400 | 35 | #include <memory> | ||
401 | 36 | #include <json/json.h> | ||
402 | 37 | |||
403 | 38 | namespace click | ||
404 | 39 | { | ||
405 | 40 | |||
406 | 41 | class Department | ||
407 | 42 | { | ||
408 | 43 | public: | ||
409 | 44 | typedef std::shared_ptr<Department> SPtr; | ||
410 | 45 | typedef std::shared_ptr<Department const> SCPtr; | ||
411 | 46 | |||
412 | 47 | struct JsonKeys | ||
413 | 48 | { | ||
414 | 49 | JsonKeys() = delete; | ||
415 | 50 | constexpr static const char* name {"name"}; | ||
416 | 51 | constexpr static const char* embedded {"_embedded"}; | ||
417 | 52 | constexpr static const char* department {"clickindex:department"}; | ||
418 | 53 | constexpr static const char* has_children {"has_children"}; | ||
419 | 54 | constexpr static const char* links {"_links"}; | ||
420 | 55 | constexpr static const char* self {"self"}; | ||
421 | 56 | constexpr static const char* href {"href"}; | ||
422 | 57 | }; | ||
423 | 58 | |||
424 | 59 | //Department(const std::string &id, const std::string &name); | ||
425 | 60 | Department(const std::string &id, const std::string &name, const std::string& href, bool has_children); | ||
426 | 61 | std::string id() const; | ||
427 | 62 | std::string name() const; | ||
428 | 63 | std::string href() const; | ||
429 | 64 | bool has_children_flag() const; | ||
430 | 65 | void set_subdepartments(const std::list<Department::SPtr>& deps); | ||
431 | 66 | std::list<Department::SPtr> sub_departments() const; | ||
432 | 67 | static std::list<Department::SPtr> from_json(const std::string& json); | ||
433 | 68 | static std::list<Department::SPtr> from_json_root_node(const Json::Value& val); | ||
434 | 69 | |||
435 | 70 | private: | ||
436 | 71 | static std::list<Department::SPtr> from_json_node(const Json::Value& val); | ||
437 | 72 | std::string id_; | ||
438 | 73 | std::string name_; | ||
439 | 74 | std::string href_; | ||
440 | 75 | bool has_children_flag_; | ||
441 | 76 | std::list<Department::SPtr> sub_departments_; | ||
442 | 77 | }; | ||
443 | 78 | |||
444 | 79 | typedef std::list<Department::SPtr> DepartmentList; | ||
445 | 80 | |||
446 | 81 | } | ||
447 | 82 | |||
448 | 83 | #endif | ||
449 | 0 | 84 | ||
450 | === added file 'libclickscope/click/highlights.cpp' | |||
451 | --- libclickscope/click/highlights.cpp 1970-01-01 00:00:00 +0000 | |||
452 | +++ libclickscope/click/highlights.cpp 2014-06-18 18:08:01 +0000 | |||
453 | @@ -0,0 +1,95 @@ | |||
454 | 1 | /* | ||
455 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
456 | 3 | * | ||
457 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
458 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
459 | 6 | * by the Free Software Foundation. | ||
460 | 7 | * | ||
461 | 8 | * This program is distributed in the hope that it will be useful, but | ||
462 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
463 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
464 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
465 | 12 | * | ||
466 | 13 | * You should have received a copy of the GNU General Public License along | ||
467 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
468 | 15 | * | ||
469 | 16 | * In addition, as a special exception, the copyright holders give | ||
470 | 17 | * permission to link the code of portions of this program with the | ||
471 | 18 | * OpenSSL library under certain conditions as described in each | ||
472 | 19 | * individual source file, and distribute linked combinations | ||
473 | 20 | * including the two. | ||
474 | 21 | * You must obey the GNU General Public License in all respects | ||
475 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
476 | 23 | * file(s) with this exception, you may extend this exception to your | ||
477 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
478 | 25 | * do not wish to do so, delete this exception statement from your | ||
479 | 26 | * version. If you delete this exception statement from all source | ||
480 | 27 | * files in the program, then also delete it here. | ||
481 | 28 | */ | ||
482 | 29 | |||
483 | 30 | #include "highlights.h" | ||
484 | 31 | #include <iostream> | ||
485 | 32 | |||
486 | 33 | namespace click | ||
487 | 34 | { | ||
488 | 35 | |||
489 | 36 | Highlight::Highlight(const std::string& name) | ||
490 | 37 | : name_(name) | ||
491 | 38 | { | ||
492 | 39 | } | ||
493 | 40 | |||
494 | 41 | Highlight::Highlight(const std::string& name, const Packages& pkgs) | ||
495 | 42 | : name_(name), | ||
496 | 43 | packages_(pkgs) | ||
497 | 44 | { | ||
498 | 45 | } | ||
499 | 46 | |||
500 | 47 | void Highlight::add_package(const Package& pkg) | ||
501 | 48 | { | ||
502 | 49 | packages_.push_back(pkg); | ||
503 | 50 | } | ||
504 | 51 | |||
505 | 52 | std::string Highlight::name() const | ||
506 | 53 | { | ||
507 | 54 | return name_; | ||
508 | 55 | } | ||
509 | 56 | |||
510 | 57 | Packages Highlight::packages() const | ||
511 | 58 | { | ||
512 | 59 | return packages_; | ||
513 | 60 | } | ||
514 | 61 | |||
515 | 62 | std::list<Highlight> Highlight::from_json_node(const Json::Value& node) | ||
516 | 63 | { | ||
517 | 64 | std::list<Highlight> highlights; | ||
518 | 65 | |||
519 | 66 | for (uint i = 0; i < node.size(); i++) | ||
520 | 67 | { | ||
521 | 68 | auto const item = node[i]; | ||
522 | 69 | if (item.isObject() && item.isMember(Highlight::JsonKeys::name)) | ||
523 | 70 | { | ||
524 | 71 | auto name = item[Highlight::JsonKeys::name].asString(); | ||
525 | 72 | auto pkgs = package_list_from_json_node(item); | ||
526 | 73 | highlights.push_back(Highlight(name, pkgs)); | ||
527 | 74 | } | ||
528 | 75 | } | ||
529 | 76 | |||
530 | 77 | return highlights; | ||
531 | 78 | } | ||
532 | 79 | |||
533 | 80 | std::list<Highlight> Highlight::from_json_root_node(const Json::Value& root) | ||
534 | 81 | { | ||
535 | 82 | if (root.isObject() && root.isMember(Highlight::JsonKeys::embedded)) | ||
536 | 83 | { | ||
537 | 84 | auto const emb = root[Highlight::JsonKeys::embedded]; | ||
538 | 85 | if (emb.isObject() && emb.isMember(Highlight::JsonKeys::highlight)) | ||
539 | 86 | { | ||
540 | 87 | auto const hl = emb[Highlight::JsonKeys::highlight]; | ||
541 | 88 | return from_json_node(hl); | ||
542 | 89 | } | ||
543 | 90 | } | ||
544 | 91 | |||
545 | 92 | return std::list<Highlight>(); | ||
546 | 93 | } | ||
547 | 94 | |||
548 | 95 | } | ||
549 | 0 | 96 | ||
550 | === added file 'libclickscope/click/highlights.h' | |||
551 | --- libclickscope/click/highlights.h 1970-01-01 00:00:00 +0000 | |||
552 | +++ libclickscope/click/highlights.h 2014-06-18 18:08:01 +0000 | |||
553 | @@ -0,0 +1,72 @@ | |||
554 | 1 | /* | ||
555 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
556 | 3 | * | ||
557 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
558 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
559 | 6 | * by the Free Software Foundation. | ||
560 | 7 | * | ||
561 | 8 | * This program is distributed in the hope that it will be useful, but | ||
562 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
563 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
564 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
565 | 12 | * | ||
566 | 13 | * You should have received a copy of the GNU General Public License along | ||
567 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
568 | 15 | * | ||
569 | 16 | * In addition, as a special exception, the copyright holders give | ||
570 | 17 | * permission to link the code of portions of this program with the | ||
571 | 18 | * OpenSSL library under certain conditions as described in each | ||
572 | 19 | * individual source file, and distribute linked combinations | ||
573 | 20 | * including the two. | ||
574 | 21 | * You must obey the GNU General Public License in all respects | ||
575 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
576 | 23 | * file(s) with this exception, you may extend this exception to your | ||
577 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
578 | 25 | * do not wish to do so, delete this exception statement from your | ||
579 | 26 | * version. If you delete this exception statement from all source | ||
580 | 27 | * files in the program, then also delete it here. | ||
581 | 28 | */ | ||
582 | 29 | |||
583 | 30 | #ifndef CLICK_HIGHLIGHTS_H | ||
584 | 31 | #define CLICK_HIGHLIGHTS_H | ||
585 | 32 | |||
586 | 33 | #include <string> | ||
587 | 34 | #include <list> | ||
588 | 35 | #include <json/json.h> | ||
589 | 36 | #include <click/package.h> | ||
590 | 37 | |||
591 | 38 | namespace click | ||
592 | 39 | { | ||
593 | 40 | |||
594 | 41 | class Highlight | ||
595 | 42 | { | ||
596 | 43 | public: | ||
597 | 44 | struct JsonKeys | ||
598 | 45 | { | ||
599 | 46 | JsonKeys() = delete; | ||
600 | 47 | constexpr static const char* name {"name"}; | ||
601 | 48 | constexpr static const char* embedded {"_embedded"}; | ||
602 | 49 | constexpr static const char* highlight {"clickindex:highlight"}; | ||
603 | 50 | }; | ||
604 | 51 | |||
605 | 52 | Highlight(const std::string& name); | ||
606 | 53 | Highlight(const std::string& name, const Packages& pkgs); | ||
607 | 54 | void add_package(const Package& pkg); | ||
608 | 55 | |||
609 | 56 | std::string name() const; | ||
610 | 57 | Packages packages() const; | ||
611 | 58 | |||
612 | 59 | static std::list<Highlight> from_json_root_node(const Json::Value& val); | ||
613 | 60 | |||
614 | 61 | private: | ||
615 | 62 | static std::list<Highlight> from_json_node(const Json::Value& val); | ||
616 | 63 | |||
617 | 64 | std::string name_; | ||
618 | 65 | Packages packages_; | ||
619 | 66 | }; | ||
620 | 67 | |||
621 | 68 | typedef std::list<Highlight> HighlightList; | ||
622 | 69 | |||
623 | 70 | } | ||
624 | 71 | |||
625 | 72 | #endif | ||
626 | 0 | 73 | ||
627 | === modified file 'libclickscope/click/index.cpp' | |||
628 | --- libclickscope/click/index.cpp 2014-06-12 21:05:25 +0000 | |||
629 | +++ libclickscope/click/index.cpp 2014-06-18 18:08:01 +0000 | |||
630 | @@ -88,11 +88,15 @@ | |||
631 | 88 | 88 | ||
632 | 89 | } | 89 | } |
633 | 90 | 90 | ||
635 | 91 | std::string Index::build_index_query(const std::string& query) | 91 | std::string Index::build_index_query(const std::string& query, const std::string& department) |
636 | 92 | { | 92 | { |
637 | 93 | std::stringstream result; | 93 | std::stringstream result; |
638 | 94 | 94 | ||
639 | 95 | result << query; | 95 | result << query; |
640 | 96 | if (!department.empty()) { | ||
641 | 97 | result << ",department:" << department; | ||
642 | 98 | } | ||
643 | 99 | |||
644 | 96 | return result.str(); | 100 | return result.str(); |
645 | 97 | } | 101 | } |
646 | 98 | 102 | ||
647 | @@ -110,10 +114,10 @@ | |||
648 | 110 | }; | 114 | }; |
649 | 111 | } | 115 | } |
650 | 112 | 116 | ||
652 | 113 | click::web::Cancellable Index::search (const std::string& query, std::function<void(click::Packages)> callback) | 117 | click::web::Cancellable Index::search (const std::string& query, const std::string& department, std::function<void(click::Packages, click::DepartmentList)> callback) |
653 | 114 | { | 118 | { |
654 | 115 | click::web::CallParams params; | 119 | click::web::CallParams params; |
656 | 116 | const std::string built_query(build_index_query(query)); | 120 | const std::string built_query(build_index_query(query, department)); |
657 | 117 | params.add(click::QUERY_ARGNAME, built_query.c_str()); | 121 | params.add(click::QUERY_ARGNAME, built_query.c_str()); |
658 | 118 | QSharedPointer<click::web::Response> response(client->call( | 122 | QSharedPointer<click::web::Response> response(client->call( |
659 | 119 | get_base_url() + click::SEARCH_PATH, "GET", false, build_headers(), "", params)); | 123 | get_base_url() + click::SEARCH_PATH, "GET", false, build_headers(), "", params)); |
660 | @@ -123,22 +127,83 @@ | |||
661 | 123 | Json::Value root; | 127 | Json::Value root; |
662 | 124 | 128 | ||
663 | 125 | click::Packages pl; | 129 | click::Packages pl; |
664 | 130 | click::DepartmentList depts; | ||
665 | 126 | if (reader.parse(reply.toUtf8().constData(), root)) { | 131 | if (reader.parse(reply.toUtf8().constData(), root)) { |
666 | 127 | pl = click::package_list_from_json_node(root); | 132 | pl = click::package_list_from_json_node(root); |
667 | 128 | qDebug() << "found packages:" << pl.size(); | 133 | qDebug() << "found packages:" << pl.size(); |
668 | 134 | depts = click::Department::from_json_root_node(root); | ||
669 | 129 | } | 135 | } |
671 | 130 | callback(pl); | 136 | callback(pl, depts); |
672 | 131 | }); | 137 | }); |
673 | 132 | QObject::connect(response.data(), &click::web::Response::error, [=](QString /*description*/) { | 138 | QObject::connect(response.data(), &click::web::Response::error, [=](QString /*description*/) { |
674 | 133 | qDebug() << "No packages found due to network error"; | 139 | qDebug() << "No packages found due to network error"; |
675 | 134 | click::Packages pl; | 140 | click::Packages pl; |
676 | 141 | click::DepartmentList depts; | ||
677 | 135 | qDebug() << "calling callback"; | 142 | qDebug() << "calling callback"; |
679 | 136 | callback(pl); | 143 | callback(pl, depts); |
680 | 137 | qDebug() << " ...Done!"; | 144 | qDebug() << " ...Done!"; |
681 | 138 | }); | 145 | }); |
682 | 139 | return click::web::Cancellable(response); | 146 | return click::web::Cancellable(response); |
683 | 140 | } | 147 | } |
684 | 141 | 148 | ||
685 | 149 | click::web::Cancellable Index::bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback) | ||
686 | 150 | { | ||
687 | 151 | click::web::CallParams params; | ||
688 | 152 | QSharedPointer<click::web::Response> response(client->call( | ||
689 | 153 | get_base_url() + click::BOOTSTRAP_PATH, "GET", false, build_headers(), "", params)); | ||
690 | 154 | |||
691 | 155 | QObject::connect(response.data(), &click::web::Response::finished, [=](QString reply) { | ||
692 | 156 | qDebug() << "bootstrap request finished"; | ||
693 | 157 | Json::Reader reader; | ||
694 | 158 | Json::Value root; | ||
695 | 159 | |||
696 | 160 | click::DepartmentList depts; | ||
697 | 161 | click::HighlightList highlights; | ||
698 | 162 | if (reader.parse(reply.toUtf8().constData(), root)) { | ||
699 | 163 | depts = Department::from_json_root_node(root); | ||
700 | 164 | highlights = Highlight::from_json_root_node(root); | ||
701 | 165 | } | ||
702 | 166 | callback(depts, highlights, click::Index::Error::NoError, 0); | ||
703 | 167 | }); | ||
704 | 168 | QObject::connect(response.data(), &click::web::Response::error, [=](QString /*description*/, int error_code) { | ||
705 | 169 | qWarning() << "bootstrap call failed due to network error, code" << error_code; | ||
706 | 170 | const click::DepartmentList depts; | ||
707 | 171 | const click::HighlightList highlights; | ||
708 | 172 | qDebug() << "bootstrap: calling callback"; | ||
709 | 173 | callback(depts, highlights, click::Index::Error::NetworkError, error_code); | ||
710 | 174 | }); | ||
711 | 175 | return click::web::Cancellable(response); | ||
712 | 176 | } | ||
713 | 177 | |||
714 | 178 | click::web::Cancellable Index::departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error)> callback) | ||
715 | 179 | { | ||
716 | 180 | click::web::CallParams params; | ||
717 | 181 | QSharedPointer<click::web::Response> response(client->call( | ||
718 | 182 | department_href, "GET", false, build_headers(), "", params)); | ||
719 | 183 | |||
720 | 184 | QObject::connect(response.data(), &click::web::Response::finished, [=](QString reply) { | ||
721 | 185 | qDebug() << "departments request finished"; | ||
722 | 186 | Json::Reader reader; | ||
723 | 187 | Json::Value root; | ||
724 | 188 | |||
725 | 189 | click::DepartmentList depts; | ||
726 | 190 | click::HighlightList highlights; | ||
727 | 191 | if (reader.parse(reply.toUtf8().constData(), root)) { | ||
728 | 192 | depts = Department::from_json_root_node(root); | ||
729 | 193 | highlights = Highlight::from_json_root_node(root); | ||
730 | 194 | } | ||
731 | 195 | callback(depts, highlights, click::Index::Error::NoError); | ||
732 | 196 | }); | ||
733 | 197 | QObject::connect(response.data(), &click::web::Response::error, [=](QString /*description*/) { | ||
734 | 198 | qWarning() << "departments call failed due to network error"; | ||
735 | 199 | const click::DepartmentList depts; | ||
736 | 200 | const click::HighlightList highlights; | ||
737 | 201 | qDebug() << "departments: calling callback"; | ||
738 | 202 | callback(depts, highlights, click::Index::Error::NetworkError); | ||
739 | 203 | }); | ||
740 | 204 | return click::web::Cancellable(response); | ||
741 | 205 | } | ||
742 | 206 | |||
743 | 142 | click::web::Cancellable Index::get_details (const std::string& package_name, std::function<void(PackageDetails, click::Index::Error)> callback) | 207 | click::web::Cancellable Index::get_details (const std::string& package_name, std::function<void(PackageDetails, click::Index::Error)> callback) |
744 | 143 | { | 208 | { |
745 | 144 | QSharedPointer<click::web::Response> response = client->call | 209 | QSharedPointer<click::web::Response> response = client->call |
746 | 145 | 210 | ||
747 | === modified file 'libclickscope/click/index.h' | |||
748 | --- libclickscope/click/index.h 2014-06-12 21:05:25 +0000 | |||
749 | +++ libclickscope/click/index.h 2014-06-18 18:08:01 +0000 | |||
750 | @@ -38,6 +38,8 @@ | |||
751 | 38 | #include <click/webclient.h> | 38 | #include <click/webclient.h> |
752 | 39 | 39 | ||
753 | 40 | #include "package.h" | 40 | #include "package.h" |
754 | 41 | #include <click/departments.h> | ||
755 | 42 | #include <click/highlights.h> | ||
756 | 41 | 43 | ||
757 | 42 | 44 | ||
758 | 43 | namespace click { | 45 | namespace click { |
759 | @@ -47,6 +49,7 @@ | |||
760 | 47 | const std::string SEARCH_BASE_URL_ENVVAR = "U1_SEARCH_BASE_URL"; | 49 | const std::string SEARCH_BASE_URL_ENVVAR = "U1_SEARCH_BASE_URL"; |
761 | 48 | const std::string SEARCH_BASE_URL = "https://search.apps.ubuntu.com/"; | 50 | const std::string SEARCH_BASE_URL = "https://search.apps.ubuntu.com/"; |
762 | 49 | const std::string SEARCH_PATH = "api/v1/search"; | 51 | const std::string SEARCH_PATH = "api/v1/search"; |
763 | 52 | const std::string BOOTSTRAP_PATH = "api/v1"; | ||
764 | 50 | const std::string SUPPORTED_FRAMEWORKS = "framework:ubuntu-sdk-13.10"; | 53 | const std::string SUPPORTED_FRAMEWORKS = "framework:ubuntu-sdk-13.10"; |
765 | 51 | const std::string QUERY_ARGNAME = "q"; | 54 | const std::string QUERY_ARGNAME = "q"; |
766 | 52 | const std::string ARCHITECTURE = "architecture:"; | 55 | const std::string ARCHITECTURE = "architecture:"; |
767 | @@ -64,15 +67,17 @@ | |||
768 | 64 | protected: | 67 | protected: |
769 | 65 | QSharedPointer<web::Client> client; | 68 | QSharedPointer<web::Client> client; |
770 | 66 | QSharedPointer<Configuration> configuration; | 69 | QSharedPointer<Configuration> configuration; |
772 | 67 | virtual std::string build_index_query(const std::string& query); | 70 | virtual std::string build_index_query(const std::string& query, const std::string& department); |
773 | 68 | virtual std::map<std::string, std::string> build_headers(); | 71 | virtual std::map<std::string, std::string> build_headers(); |
774 | 69 | 72 | ||
775 | 70 | public: | 73 | public: |
776 | 71 | enum class Error {NoError, CredentialsError, NetworkError}; | 74 | enum class Error {NoError, CredentialsError, NetworkError}; |
777 | 72 | Index(const QSharedPointer<click::web::Client>& client, | 75 | Index(const QSharedPointer<click::web::Client>& client, |
778 | 73 | const QSharedPointer<Configuration> configuration=QSharedPointer<Configuration>(new Configuration())); | 76 | const QSharedPointer<Configuration> configuration=QSharedPointer<Configuration>(new Configuration())); |
780 | 74 | virtual click::web::Cancellable search (const std::string& query, std::function<void(Packages)> callback); | 77 | virtual click::web::Cancellable search (const std::string& query, const std::string& department, std::function<void(Packages, DepartmentList)> callback); |
781 | 75 | virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback); | 78 | virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback); |
782 | 79 | virtual click::web::Cancellable bootstrap(std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); | ||
783 | 80 | virtual click::web::Cancellable departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error)> callback); | ||
784 | 76 | virtual ~Index(); | 81 | virtual ~Index(); |
785 | 77 | 82 | ||
786 | 78 | static std::string get_base_url (); | 83 | static std::string get_base_url (); |
787 | 79 | 84 | ||
788 | === modified file 'libclickscope/click/package.h' | |||
789 | --- libclickscope/click/package.h 2014-06-13 22:42:02 +0000 | |||
790 | +++ libclickscope/click/package.h 2014-06-18 18:08:01 +0000 | |||
791 | @@ -34,6 +34,7 @@ | |||
792 | 34 | #include <string> | 34 | #include <string> |
793 | 35 | #include <unordered_set> | 35 | #include <unordered_set> |
794 | 36 | #include <vector> | 36 | #include <vector> |
795 | 37 | #include <functional> | ||
796 | 37 | 38 | ||
797 | 38 | #include <json/json.h> | 39 | #include <json/json.h> |
798 | 39 | 40 | ||
799 | 40 | 41 | ||
800 | === modified file 'libclickscope/click/preview.cpp' | |||
801 | --- libclickscope/click/preview.cpp 2014-06-17 21:05:05 +0000 | |||
802 | +++ libclickscope/click/preview.cpp 2014-06-18 18:08:01 +0000 | |||
803 | @@ -57,6 +57,7 @@ | |||
804 | 57 | const unity::scopes::ActionMetadata& metadata, | 57 | const unity::scopes::ActionMetadata& metadata, |
805 | 58 | const QSharedPointer<click::web::Client>& client, | 58 | const QSharedPointer<click::web::Client>& client, |
806 | 59 | const QSharedPointer<click::network::AccessManager>& nam) | 59 | const QSharedPointer<click::network::AccessManager>& nam) |
807 | 60 | : PreviewQueryBase(result, metadata) | ||
808 | 60 | { | 61 | { |
809 | 61 | strategy.reset(choose_strategy(result, metadata, client, nam)); | 62 | strategy.reset(choose_strategy(result, metadata, client, nam)); |
810 | 62 | } | 63 | } |
811 | 63 | 64 | ||
812 | === modified file 'libclickscope/click/scope_activation.cpp' | |||
813 | --- libclickscope/click/scope_activation.cpp 2014-05-28 07:42:24 +0000 | |||
814 | +++ libclickscope/click/scope_activation.cpp 2014-06-18 18:08:01 +0000 | |||
815 | @@ -33,6 +33,11 @@ | |||
816 | 33 | #include <click/qtbridge.h> | 33 | #include <click/qtbridge.h> |
817 | 34 | #include <unity/scopes/ActivationResponse.h> | 34 | #include <unity/scopes/ActivationResponse.h> |
818 | 35 | 35 | ||
819 | 36 | click::ScopeActivation::ScopeActivation(const unity::scopes::Result& result, const unity::scopes::ActionMetadata& metadata) | ||
820 | 37 | : unity::scopes::ActivationQueryBase(result, metadata) | ||
821 | 38 | { | ||
822 | 39 | } | ||
823 | 40 | |||
824 | 36 | unity::scopes::ActivationResponse click::ScopeActivation::activate() | 41 | unity::scopes::ActivationResponse click::ScopeActivation::activate() |
825 | 37 | { | 42 | { |
826 | 38 | auto response = unity::scopes::ActivationResponse(status_); | 43 | auto response = unity::scopes::ActivationResponse(status_); |
827 | @@ -50,18 +55,19 @@ | |||
828 | 50 | hints_[key] = value; | 55 | hints_[key] = value; |
829 | 51 | } | 56 | } |
830 | 52 | 57 | ||
833 | 53 | click::PerformUninstallAction::PerformUninstallAction(const unity::scopes::Result& result, const unity::scopes::ActivationResponse& response) | 58 | click::PerformUninstallAction::PerformUninstallAction(const unity::scopes::Result& result, const unity::scopes::ActionMetadata& metadata, const unity::scopes::ActivationResponse& response) |
834 | 54 | : result(result), | 59 | : unity::scopes::ActivationQueryBase(result, metadata), |
835 | 55 | response(response) | 60 | response(response) |
836 | 56 | { | 61 | { |
837 | 57 | } | 62 | } |
838 | 58 | 63 | ||
839 | 59 | unity::scopes::ActivationResponse click::PerformUninstallAction::activate() | 64 | unity::scopes::ActivationResponse click::PerformUninstallAction::activate() |
840 | 60 | { | 65 | { |
841 | 66 | auto const res = result(); | ||
842 | 61 | click::Package package; | 67 | click::Package package; |
846 | 62 | package.title = result.title(); | 68 | package.title = res.title(); |
847 | 63 | package.name = result["name"].get_string(); | 69 | package.name = res["name"].get_string(); |
848 | 64 | package.version = result["version"].get_string(); | 70 | package.version = res["version"].get_string(); |
849 | 65 | qt::core::world::enter_with_task([this, package] () | 71 | qt::core::world::enter_with_task([this, package] () |
850 | 66 | { | 72 | { |
851 | 67 | click::PackageManager manager; | 73 | click::PackageManager manager; |
852 | 68 | 74 | ||
853 | === modified file 'libclickscope/click/scope_activation.h' | |||
854 | --- libclickscope/click/scope_activation.h 2014-05-28 07:42:24 +0000 | |||
855 | +++ libclickscope/click/scope_activation.h 2014-06-18 18:08:01 +0000 | |||
856 | @@ -40,11 +40,10 @@ | |||
857 | 40 | class PerformUninstallAction: public unity::scopes::ActivationQueryBase | 40 | class PerformUninstallAction: public unity::scopes::ActivationQueryBase |
858 | 41 | { | 41 | { |
859 | 42 | public: | 42 | public: |
861 | 43 | PerformUninstallAction(const unity::scopes::Result& result, const unity::scopes::ActivationResponse& response); | 43 | PerformUninstallAction(const unity::scopes::Result& result, const unity::scopes::ActionMetadata& metadata, const unity::scopes::ActivationResponse& response); |
862 | 44 | unity::scopes::ActivationResponse activate() override; | 44 | unity::scopes::ActivationResponse activate() override; |
863 | 45 | 45 | ||
864 | 46 | private: | 46 | private: |
865 | 47 | unity::scopes::Result result; | ||
866 | 48 | unity::scopes::ActivationResponse response; | 47 | unity::scopes::ActivationResponse response; |
867 | 49 | }; | 48 | }; |
868 | 50 | 49 | ||
869 | @@ -53,6 +52,7 @@ | |||
870 | 53 | unity::scopes::ActivationResponse activate() override; | 52 | unity::scopes::ActivationResponse activate() override; |
871 | 54 | 53 | ||
872 | 55 | public: | 54 | public: |
873 | 55 | ScopeActivation(const unity::scopes::Result& result, const unity::scopes::ActionMetadata& metadata); | ||
874 | 56 | void setStatus(unity::scopes::ActivationResponse::Status status); | 56 | void setStatus(unity::scopes::ActivationResponse::Status status); |
875 | 57 | void setHint(std::string key, unity::scopes::Variant value); | 57 | void setHint(std::string key, unity::scopes::Variant value); |
876 | 58 | 58 | ||
877 | 59 | 59 | ||
878 | === modified file 'libclickscope/click/webclient.cpp' | |||
879 | --- libclickscope/click/webclient.cpp 2014-05-23 18:45:01 +0000 | |||
880 | +++ libclickscope/click/webclient.cpp 2014-06-18 18:08:01 +0000 | |||
881 | @@ -176,7 +176,8 @@ | |||
882 | 176 | { | 176 | { |
883 | 177 | auto message = reply->errorString() + QString(" (%1)").arg(network_error); | 177 | auto message = reply->errorString() + QString(" (%1)").arg(network_error); |
884 | 178 | qWarning() << "Network error:" << message << "\n" << reply->readAll(); | 178 | qWarning() << "Network error:" << message << "\n" << reply->readAll(); |
886 | 179 | emit error(message); | 179 | int error_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
887 | 180 | emit error(message, error_code); | ||
888 | 180 | } | 181 | } |
889 | 181 | 182 | ||
890 | 182 | void click::web::Response::abort() | 183 | void click::web::Response::abort() |
891 | 183 | 184 | ||
892 | === modified file 'libclickscope/click/webclient.h' | |||
893 | --- libclickscope/click/webclient.h 2014-05-23 18:45:01 +0000 | |||
894 | +++ libclickscope/click/webclient.h 2014-06-18 18:08:01 +0000 | |||
895 | @@ -84,7 +84,7 @@ | |||
896 | 84 | 84 | ||
897 | 85 | signals: | 85 | signals: |
898 | 86 | void finished(QByteArray result); | 86 | void finished(QByteArray result); |
900 | 87 | void error(QString description); | 87 | void error(QString description, int error_code); |
901 | 88 | 88 | ||
902 | 89 | private: | 89 | private: |
903 | 90 | QSharedPointer<click::network::Reply> reply; | 90 | QSharedPointer<click::network::Reply> reply; |
904 | 91 | 91 | ||
905 | === modified file 'libclickscope/tests/CMakeLists.txt' | |||
906 | --- libclickscope/tests/CMakeLists.txt 2014-05-26 14:27:31 +0000 | |||
907 | +++ libclickscope/tests/CMakeLists.txt 2014-06-18 18:08:01 +0000 | |||
908 | @@ -28,6 +28,8 @@ | |||
909 | 28 | test_reviews.cpp | 28 | test_reviews.cpp |
910 | 29 | test_smartconnect.cpp | 29 | test_smartconnect.cpp |
911 | 30 | test_webclient.cpp | 30 | test_webclient.cpp |
912 | 31 | test_bootstrap.cpp | ||
913 | 32 | test_departments.cpp | ||
914 | 31 | 33 | ||
915 | 32 | ${CMAKE_CURRENT_BINARY_DIR}/test_data.cpp | 34 | ${CMAKE_CURRENT_BINARY_DIR}/test_data.cpp |
916 | 33 | ) | 35 | ) |
917 | 34 | 36 | ||
918 | === modified file 'libclickscope/tests/fake_json.h' | |||
919 | --- libclickscope/tests/fake_json.h 2014-06-13 23:18:41 +0000 | |||
920 | +++ libclickscope/tests/fake_json.h 2014-06-18 18:08:01 +0000 | |||
921 | @@ -150,6 +150,242 @@ | |||
922 | 150 | } | 150 | } |
923 | 151 | )foo"; | 151 | )foo"; |
924 | 152 | 152 | ||
925 | 153 | const std::string FAKE_JSON_BOOTSTRAP = R"( | ||
926 | 154 | { | ||
927 | 155 | "_embedded": { | ||
928 | 156 | "clickindex:department": [ | ||
929 | 157 | { | ||
930 | 158 | "has_children": false, | ||
931 | 159 | "_links": { | ||
932 | 160 | "self": { | ||
933 | 161 | "href": "https://search.apps.staging.ubuntu.com/api/v1/departments/fake-subdepartment"} | ||
934 | 162 | }, | ||
935 | 163 | "name": "Fake Subdepartment", "slug": "fake-subdepartment"} | ||
936 | 164 | ], | ||
937 | 165 | "clickindex:highlight": [ | ||
938 | 166 | { | ||
939 | 167 | "_embedded": { | ||
940 | 168 | "clickindex:package": [ | ||
941 | 169 | { | ||
942 | 170 | "publisher": "Awesome Widget Company", | ||
943 | 171 | "name": "org.example.awesomelauncher", | ||
944 | 172 | "title": "Awesome Launcher", | ||
945 | 173 | "price": 1.99, | ||
946 | 174 | "_links": { | ||
947 | 175 | "self": { | ||
948 | 176 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomelauncher"} | ||
949 | 177 | }, | ||
950 | 178 | "icon": "http://example.org/media/org.example.awesomelauncher/icons/icon16.png" | ||
951 | 179 | }, | ||
952 | 180 | { | ||
953 | 181 | "publisher": "Awesome Widget Company", | ||
954 | 182 | "name": "org.example.awesomewidget", | ||
955 | 183 | "title": "Awesome Widget", "price": 1.99, | ||
956 | 184 | "_links": { | ||
957 | 185 | "self": { | ||
958 | 186 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomewidget" | ||
959 | 187 | } | ||
960 | 188 | }, | ||
961 | 189 | "icon": "http://example.org/media/org.example.awesomewidget/icons/icon16.png"} | ||
962 | 190 | ] | ||
963 | 191 | }, | ||
964 | 192 | "_links": { | ||
965 | 193 | "self": { | ||
966 | 194 | "href": "https://search.apps.staging.ubuntu.com/api/v1/highlights/top-apps" | ||
967 | 195 | } | ||
968 | 196 | }, | ||
969 | 197 | "name": "Top Apps", "slug": "top-apps" | ||
970 | 198 | }, | ||
971 | 199 | { | ||
972 | 200 | "_embedded": { | ||
973 | 201 | "clickindex:package": [ | ||
974 | 202 | { | ||
975 | 203 | "publisher": "Awesome Widget Company", | ||
976 | 204 | "name": "org.example.awesomelauncher", | ||
977 | 205 | "title": "Awesome Launcher", | ||
978 | 206 | "price": 1.99, | ||
979 | 207 | "_links": { | ||
980 | 208 | "self": { | ||
981 | 209 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomelauncher" | ||
982 | 210 | } | ||
983 | 211 | }, | ||
984 | 212 | "icon": "http://example.org/media/org.example.awesomelauncher/icons/icon16.png" | ||
985 | 213 | }, | ||
986 | 214 | { | ||
987 | 215 | "publisher": "Awesome Widget Company", | ||
988 | 216 | "name": "org.example.awesomewidget", | ||
989 | 217 | "title": "Awesome Widget", | ||
990 | 218 | "price": 1.99, | ||
991 | 219 | "_links": { | ||
992 | 220 | "self": { | ||
993 | 221 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomewidget" | ||
994 | 222 | } | ||
995 | 223 | }, | ||
996 | 224 | "icon": "http://example.org/media/org.example.awesomewidget/icons/icon16.png" | ||
997 | 225 | } | ||
998 | 226 | ] | ||
999 | 227 | }, | ||
1000 | 228 | "_links": { | ||
1001 | 229 | "self": { | ||
1002 | 230 | "href": "https://search.apps.staging.ubuntu.com/api/v1/highlights/most-purchased" | ||
1003 | 231 | } | ||
1004 | 232 | }, | ||
1005 | 233 | "name": "Most Purchased", | ||
1006 | 234 | "slug": "most-purchased" | ||
1007 | 235 | }, | ||
1008 | 236 | { | ||
1009 | 237 | "_embedded": { | ||
1010 | 238 | "clickindex:package": [ | ||
1011 | 239 | { | ||
1012 | 240 | "publisher": "Awesome Widget Company", | ||
1013 | 241 | "name": "org.example.awesomelauncher", | ||
1014 | 242 | "title": "Awesome Launcher", | ||
1015 | 243 | "price": 1.99, | ||
1016 | 244 | "_links": { | ||
1017 | 245 | "self": { | ||
1018 | 246 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomelauncher" | ||
1019 | 247 | } | ||
1020 | 248 | }, | ||
1021 | 249 | "icon": "http://example.org/media/org.example.awesomelauncher/icons/icon16.png" | ||
1022 | 250 | }, | ||
1023 | 251 | { | ||
1024 | 252 | "publisher": "Awesome Widget Company", | ||
1025 | 253 | "name": "org.example.awesomewidget", | ||
1026 | 254 | "title": "Awesome Widget", | ||
1027 | 255 | "price": 1.99, | ||
1028 | 256 | "_links": { | ||
1029 | 257 | "self": { | ||
1030 | 258 | "href": "https://search.apps.staging.ubuntu.com/api/v1/package/org.example.awesomewidget" | ||
1031 | 259 | } | ||
1032 | 260 | }, | ||
1033 | 261 | "icon": "http://example.org/media/org.example.awesomewidget/icons/icon16.png" | ||
1034 | 262 | } | ||
1035 | 263 | ] | ||
1036 | 264 | }, | ||
1037 | 265 | "_links": { | ||
1038 | 266 | "self": { | ||
1039 | 267 | "href": "https://search.apps.staging.ubuntu.com/api/v1/highlights/new-releases" | ||
1040 | 268 | } | ||
1041 | 269 | }, | ||
1042 | 270 | "name": "New Releases", | ||
1043 | 271 | "slug": "new-releases" | ||
1044 | 272 | } | ||
1045 | 273 | ] | ||
1046 | 274 | }, "has_children": true, | ||
1047 | 275 | "_links": { | ||
1048 | 276 | "curies": [ | ||
1049 | 277 | { | ||
1050 | 278 | "href": "https://search.apps.staging.ubuntu.com/docs/v1/relations.html{#rel}", | ||
1051 | 279 | "name": "clickindex", "templated": true | ||
1052 | 280 | } | ||
1053 | 281 | ], | ||
1054 | 282 | "self": { | ||
1055 | 283 | "href": "https://search.apps.staging.ubuntu.com/api/v1/departments/fake-department-with-subdepartments" | ||
1056 | 284 | }, | ||
1057 | 285 | "collection": { | ||
1058 | 286 | "href": "https://search.apps.staging.ubuntu.com/api/v1/departments" | ||
1059 | 287 | } | ||
1060 | 288 | }, | ||
1061 | 289 | "name": "Fake Department With Subdepartments", | ||
1062 | 290 | "slug": "fake-department-with-subdepartments" | ||
1063 | 291 | })"; | ||
1064 | 292 | |||
1065 | 293 | const std::string FAKE_JSON_DEPARTMENTS_ONLY = R"( | ||
1066 | 294 | { | ||
1067 | 295 | "_links": { | ||
1068 | 296 | "self": { | ||
1069 | 297 | "href": "https://search.apps.ubuntu.com/api/v1/departments" | ||
1070 | 298 | }, | ||
1071 | 299 | "curies": [ | ||
1072 | 300 | { | ||
1073 | 301 | "name": "clickindex", | ||
1074 | 302 | "href": "https://search.apps.ubuntu.com/docs/v1/relations.html{#rel}", | ||
1075 | 303 | "templated": true | ||
1076 | 304 | } | ||
1077 | 305 | ] | ||
1078 | 306 | }, | ||
1079 | 307 | "_embedded": { | ||
1080 | 308 | "clickindex:department": [ | ||
1081 | 309 | { | ||
1082 | 310 | "name": "Games", | ||
1083 | 311 | "_links": { | ||
1084 | 312 | "self": { | ||
1085 | 313 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Games" | ||
1086 | 314 | } | ||
1087 | 315 | }, | ||
1088 | 316 | "_embedded": { | ||
1089 | 317 | "clickindex:department": [ | ||
1090 | 318 | { | ||
1091 | 319 | "name": "Board Games", | ||
1092 | 320 | "_links": { | ||
1093 | 321 | "self": { | ||
1094 | 322 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Games/Board+Games" | ||
1095 | 323 | } | ||
1096 | 324 | } | ||
1097 | 325 | } | ||
1098 | 326 | ] | ||
1099 | 327 | } | ||
1100 | 328 | }, | ||
1101 | 329 | { | ||
1102 | 330 | "name": "Graphics", | ||
1103 | 331 | "_links": { | ||
1104 | 332 | "self": { | ||
1105 | 333 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Graphics" | ||
1106 | 334 | } | ||
1107 | 335 | }, | ||
1108 | 336 | "_embedded": { | ||
1109 | 337 | "clickindex:department": [ | ||
1110 | 338 | { | ||
1111 | 339 | "name": "Drawing", | ||
1112 | 340 | "_links": { | ||
1113 | 341 | "self": { | ||
1114 | 342 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Graphics/Drawing" | ||
1115 | 343 | } | ||
1116 | 344 | } | ||
1117 | 345 | } | ||
1118 | 346 | ] | ||
1119 | 347 | } | ||
1120 | 348 | }, | ||
1121 | 349 | { | ||
1122 | 350 | "name": "Internet", | ||
1123 | 351 | "_links": { | ||
1124 | 352 | "self": { | ||
1125 | 353 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Internet" | ||
1126 | 354 | } | ||
1127 | 355 | }, | ||
1128 | 356 | "_embedded": { | ||
1129 | 357 | "clickindex:department": [ | ||
1130 | 358 | { | ||
1131 | 359 | "name": "Chat", | ||
1132 | 360 | "_links": { | ||
1133 | 361 | "self": { | ||
1134 | 362 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Internet/Chat" | ||
1135 | 363 | } | ||
1136 | 364 | } | ||
1137 | 365 | }, | ||
1138 | 366 | { | ||
1139 | 367 | "name": "Mail", | ||
1140 | 368 | "_links": { | ||
1141 | 369 | "self": { | ||
1142 | 370 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Internet/Mail" | ||
1143 | 371 | } | ||
1144 | 372 | } | ||
1145 | 373 | }, | ||
1146 | 374 | { | ||
1147 | 375 | "name": "Web Browsers", | ||
1148 | 376 | "_links": { | ||
1149 | 377 | "self": { | ||
1150 | 378 | "href": "https://search.apps.ubuntu.com/api/v1/departments/Internet/Web+Browsers" | ||
1151 | 379 | } | ||
1152 | 380 | } | ||
1153 | 381 | } | ||
1154 | 382 | ] | ||
1155 | 383 | } | ||
1156 | 384 | } | ||
1157 | 385 | ] | ||
1158 | 386 | } | ||
1159 | 387 | })"; | ||
1160 | 388 | |||
1161 | 153 | const std::string FAKE_JSON_MANIFEST_REMOVABLE = R"foo( | 389 | const std::string FAKE_JSON_MANIFEST_REMOVABLE = R"foo( |
1162 | 154 | { | 390 | { |
1163 | 155 | "_removable": 1, | 391 | "_removable": 1, |
1164 | 156 | 392 | ||
1165 | === modified file 'libclickscope/tests/mock_network_access_manager.h' | |||
1166 | --- libclickscope/tests/mock_network_access_manager.h 2014-05-20 19:33:41 +0000 | |||
1167 | +++ libclickscope/tests/mock_network_access_manager.h 2014-06-18 18:08:01 +0000 | |||
1168 | @@ -48,6 +48,7 @@ | |||
1169 | 48 | { | 48 | { |
1170 | 49 | // Set a default value for QByteArray-returning mocked methods. | 49 | // Set a default value for QByteArray-returning mocked methods. |
1171 | 50 | ::testing::DefaultValue<QByteArray>::Set(QByteArray("")); | 50 | ::testing::DefaultValue<QByteArray>::Set(QByteArray("")); |
1172 | 51 | ON_CALL(*this, attribute(::testing::_)).WillByDefault(::testing::Return(0)); | ||
1173 | 51 | } | 52 | } |
1174 | 52 | 53 | ||
1175 | 53 | MOCK_METHOD0(abort, void()); | 54 | MOCK_METHOD0(abort, void()); |
1176 | 54 | 55 | ||
1177 | === modified file 'libclickscope/tests/mock_webclient.h' | |||
1178 | --- libclickscope/tests/mock_webclient.h 2014-05-23 18:45:01 +0000 | |||
1179 | +++ libclickscope/tests/mock_webclient.h 2014-06-18 18:08:01 +0000 | |||
1180 | @@ -86,7 +86,7 @@ | |||
1181 | 86 | const click::web::CallParams& params)); | 86 | const click::web::CallParams& params)); |
1182 | 87 | QSharedPointer<click::web::Response> call( | 87 | QSharedPointer<click::web::Response> call( |
1183 | 88 | const std::string& iri, | 88 | const std::string& iri, |
1185 | 89 | const click::web::CallParams& params=click::web::CallParams()) { | 89 | const click::web::CallParams& params=click::web::CallParams()) override { |
1186 | 90 | return callImpl(iri, "GET", false, | 90 | return callImpl(iri, "GET", false, |
1187 | 91 | std::map<std::string, std::string>(), "", params); | 91 | std::map<std::string, std::string>(), "", params); |
1188 | 92 | } | 92 | } |
1189 | @@ -96,7 +96,7 @@ | |||
1190 | 96 | bool sign = false, | 96 | bool sign = false, |
1191 | 97 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), | 97 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), |
1192 | 98 | const std::string& data = "", | 98 | const std::string& data = "", |
1194 | 99 | const click::web::CallParams& params=click::web::CallParams()) { | 99 | const click::web::CallParams& params=click::web::CallParams()) override { |
1195 | 100 | return callImpl(iri, method, sign, headers, data, params); | 100 | return callImpl(iri, method, sign, headers, data, params); |
1196 | 101 | } | 101 | } |
1197 | 102 | }; | 102 | }; |
1198 | 103 | 103 | ||
1199 | === added file 'libclickscope/tests/test_bootstrap.cpp' | |||
1200 | --- libclickscope/tests/test_bootstrap.cpp 1970-01-01 00:00:00 +0000 | |||
1201 | +++ libclickscope/tests/test_bootstrap.cpp 2014-06-18 18:08:01 +0000 | |||
1202 | @@ -0,0 +1,73 @@ | |||
1203 | 1 | /* | ||
1204 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
1205 | 3 | * | ||
1206 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1207 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1208 | 6 | * by the Free Software Foundation. | ||
1209 | 7 | * | ||
1210 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1211 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1212 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1213 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1214 | 12 | * | ||
1215 | 13 | * You should have received a copy of the GNU General Public License along | ||
1216 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1217 | 15 | * | ||
1218 | 16 | * In addition, as a special exception, the copyright holders give | ||
1219 | 17 | * permission to link the code of portions of this program with the | ||
1220 | 18 | * OpenSSL library under certain conditions as described in each | ||
1221 | 19 | * individual source file, and distribute linked combinations | ||
1222 | 20 | * including the two. | ||
1223 | 21 | * You must obey the GNU General Public License in all respects | ||
1224 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
1225 | 23 | * file(s) with this exception, you may extend this exception to your | ||
1226 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
1227 | 25 | * do not wish to do so, delete this exception statement from your | ||
1228 | 26 | * version. If you delete this exception statement from all source | ||
1229 | 27 | * files in the program, then also delete it here. | ||
1230 | 28 | */ | ||
1231 | 29 | |||
1232 | 30 | #include <gtest/gtest.h> | ||
1233 | 31 | #include "fake_json.h" | ||
1234 | 32 | #include <json/reader.h> | ||
1235 | 33 | #include <json/value.h> | ||
1236 | 34 | #include <click/highlights.h> | ||
1237 | 35 | #include <click/departments.h> | ||
1238 | 36 | |||
1239 | 37 | class BootstrapTest: public ::testing::Test | ||
1240 | 38 | { | ||
1241 | 39 | protected: | ||
1242 | 40 | void SetUp() override | ||
1243 | 41 | { | ||
1244 | 42 | } | ||
1245 | 43 | }; | ||
1246 | 44 | |||
1247 | 45 | TEST_F(BootstrapTest, testParsing) | ||
1248 | 46 | { | ||
1249 | 47 | Json::Reader reader; | ||
1250 | 48 | Json::Value root; | ||
1251 | 49 | |||
1252 | 50 | EXPECT_TRUE(reader.parse(FAKE_JSON_BOOTSTRAP, root)); | ||
1253 | 51 | |||
1254 | 52 | { | ||
1255 | 53 | auto highlights = click::Highlight::from_json_root_node(root); | ||
1256 | 54 | EXPECT_EQ(3u, highlights.size()); | ||
1257 | 55 | auto it = highlights.begin(); | ||
1258 | 56 | EXPECT_EQ("Top Apps", it->name()); | ||
1259 | 57 | EXPECT_EQ(2u, it->packages().size()); | ||
1260 | 58 | ++it; | ||
1261 | 59 | EXPECT_EQ("Most Purchased", it->name()); | ||
1262 | 60 | EXPECT_EQ(2u, it->packages().size()); | ||
1263 | 61 | ++it; | ||
1264 | 62 | EXPECT_EQ("New Releases", it->name()); | ||
1265 | 63 | EXPECT_EQ(2u, it->packages().size()); | ||
1266 | 64 | } | ||
1267 | 65 | { | ||
1268 | 66 | auto depts = click::Department::from_json_root_node(root); | ||
1269 | 67 | EXPECT_EQ(1u, depts.size()); | ||
1270 | 68 | auto it = depts.begin(); | ||
1271 | 69 | EXPECT_EQ("Fake Subdepartment", (*it)->name()); | ||
1272 | 70 | EXPECT_FALSE((*it)->has_children_flag()); | ||
1273 | 71 | EXPECT_EQ("https://search.apps.staging.ubuntu.com/api/v1/departments/fake-subdepartment", (*it)->href()); | ||
1274 | 72 | } | ||
1275 | 73 | } | ||
1276 | 0 | 74 | ||
1277 | === removed file 'libclickscope/tests/test_data.cpp' | |||
1278 | === added file 'libclickscope/tests/test_departments.cpp' | |||
1279 | --- libclickscope/tests/test_departments.cpp 1970-01-01 00:00:00 +0000 | |||
1280 | +++ libclickscope/tests/test_departments.cpp 2014-06-18 18:08:01 +0000 | |||
1281 | @@ -0,0 +1,108 @@ | |||
1282 | 1 | /* | ||
1283 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
1284 | 3 | * | ||
1285 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1286 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1287 | 6 | * by the Free Software Foundation. | ||
1288 | 7 | * | ||
1289 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1290 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1291 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1292 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1293 | 12 | * | ||
1294 | 13 | * You should have received a copy of the GNU General Public License along | ||
1295 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1296 | 15 | * | ||
1297 | 16 | * In addition, as a special exception, the copyright holders give | ||
1298 | 17 | * permission to link the code of portions of this program with the | ||
1299 | 18 | * OpenSSL library under certain conditions as described in each | ||
1300 | 19 | * individual source file, and distribute linked combinations | ||
1301 | 20 | * including the two. | ||
1302 | 21 | * You must obey the GNU General Public License in all respects | ||
1303 | 22 | * for all of the code used other than OpenSSL. If you modify | ||
1304 | 23 | * file(s) with this exception, you may extend this exception to your | ||
1305 | 24 | * version of the file(s), but you are not obligated to do so. If you | ||
1306 | 25 | * do not wish to do so, delete this exception statement from your | ||
1307 | 26 | * version. If you delete this exception statement from all source | ||
1308 | 27 | * files in the program, then also delete it here. | ||
1309 | 28 | */ | ||
1310 | 29 | |||
1311 | 30 | #include <gtest/gtest.h> | ||
1312 | 31 | #include "fake_json.h" | ||
1313 | 32 | #include <click/departments.h> | ||
1314 | 33 | #include <click/department-lookup.h> | ||
1315 | 34 | |||
1316 | 35 | class DepartmentsTest : public ::testing::Test | ||
1317 | 36 | { | ||
1318 | 37 | protected: | ||
1319 | 38 | void SetUp() override | ||
1320 | 39 | { | ||
1321 | 40 | } | ||
1322 | 41 | }; | ||
1323 | 42 | |||
1324 | 43 | TEST_F(DepartmentsTest, testParsing) | ||
1325 | 44 | { | ||
1326 | 45 | const std::string jsonstr(FAKE_JSON_DEPARTMENTS_ONLY); | ||
1327 | 46 | auto depts = click::Department::from_json(jsonstr); | ||
1328 | 47 | EXPECT_EQ(3u, depts.size()); | ||
1329 | 48 | auto it = depts.cbegin(); | ||
1330 | 49 | { | ||
1331 | 50 | auto dep = *it; | ||
1332 | 51 | EXPECT_EQ("Games", dep->id()); | ||
1333 | 52 | EXPECT_EQ("Games", dep->name()); | ||
1334 | 53 | EXPECT_FALSE(dep->has_children_flag()); | ||
1335 | 54 | auto subdepts = dep->sub_departments(); | ||
1336 | 55 | EXPECT_EQ(1u, subdepts.size()); | ||
1337 | 56 | auto sit = subdepts.cbegin(); | ||
1338 | 57 | EXPECT_EQ("Board Games", (*sit)->name()); | ||
1339 | 58 | } | ||
1340 | 59 | { | ||
1341 | 60 | ++it; | ||
1342 | 61 | auto dep = *it; | ||
1343 | 62 | EXPECT_EQ("Graphics", dep->id()); | ||
1344 | 63 | EXPECT_EQ("Graphics", dep->name()); | ||
1345 | 64 | EXPECT_FALSE(dep->has_children_flag()); | ||
1346 | 65 | auto subdepts = dep->sub_departments(); | ||
1347 | 66 | EXPECT_EQ(1u, subdepts.size()); | ||
1348 | 67 | auto sit = subdepts.cbegin(); | ||
1349 | 68 | EXPECT_EQ("Drawing", (*sit)->name()); | ||
1350 | 69 | } | ||
1351 | 70 | { | ||
1352 | 71 | ++it; | ||
1353 | 72 | auto dep = *it; | ||
1354 | 73 | EXPECT_EQ("Internet", dep->id()); | ||
1355 | 74 | EXPECT_EQ("Internet", dep->name()); | ||
1356 | 75 | EXPECT_FALSE(dep->has_children_flag()); | ||
1357 | 76 | auto subdepts = dep->sub_departments(); | ||
1358 | 77 | EXPECT_EQ(3u, subdepts.size()); | ||
1359 | 78 | auto sit = subdepts.cbegin(); | ||
1360 | 79 | auto subdep = *sit; | ||
1361 | 80 | EXPECT_EQ("Chat", subdep->name()); | ||
1362 | 81 | subdep = *(++sit); | ||
1363 | 82 | EXPECT_EQ("Mail", subdep->name()); | ||
1364 | 83 | subdep = *(++sit); | ||
1365 | 84 | EXPECT_EQ("Web Browsers", subdep->name()); | ||
1366 | 85 | } | ||
1367 | 86 | } | ||
1368 | 87 | |||
1369 | 88 | TEST_F(DepartmentsTest, testLookup) | ||
1370 | 89 | { | ||
1371 | 90 | auto dep_games = std::make_shared<click::Department>("games", "Games", "", false); | ||
1372 | 91 | auto dep_rpg = std::make_shared<click::Department>("rpg", "RPG", "", false); | ||
1373 | 92 | auto dep_strategy = std::make_shared<click::Department>("strategy", "Strategy", "", false); | ||
1374 | 93 | const std::list<click::Department::SPtr> departments {dep_rpg, dep_strategy}; | ||
1375 | 94 | dep_games->set_subdepartments(departments); | ||
1376 | 95 | |||
1377 | 96 | const std::list<click::Department::SPtr> root {dep_games}; | ||
1378 | 97 | click::DepartmentLookup lut; | ||
1379 | 98 | lut.rebuild(root); | ||
1380 | 99 | |||
1381 | 100 | EXPECT_EQ(2u, lut.size()); | ||
1382 | 101 | EXPECT_EQ("games", lut.get_parent("strategy")->id()); | ||
1383 | 102 | EXPECT_EQ("games", lut.get_parent("rpg")->id()); | ||
1384 | 103 | EXPECT_EQ(nullptr, lut.get_parent("games")); | ||
1385 | 104 | |||
1386 | 105 | lut.rebuild(root); | ||
1387 | 106 | EXPECT_EQ(2u, lut.size()); | ||
1388 | 107 | } | ||
1389 | 108 | |||
1390 | 0 | 109 | ||
1391 | === modified file 'libclickscope/tests/test_index.cpp' | |||
1392 | --- libclickscope/tests/test_index.cpp 2014-06-12 21:05:25 +0000 | |||
1393 | +++ libclickscope/tests/test_index.cpp 2014-06-18 18:08:01 +0000 | |||
1394 | @@ -52,8 +52,8 @@ | |||
1395 | 52 | click::Index(client, configuration) | 52 | click::Index(client, configuration) |
1396 | 53 | { | 53 | { |
1397 | 54 | } | 54 | } |
1398 | 55 | MOCK_METHOD1(build_index_query, std::string(const std::string&)); | ||
1399 | 56 | MOCK_METHOD0(build_headers, std::map<std::string, std::string>()); | 55 | MOCK_METHOD0(build_headers, std::map<std::string, std::string>()); |
1400 | 56 | MOCK_METHOD2(build_index_query, std::string(const std::string&, const std::string&)); | ||
1401 | 57 | }; | 57 | }; |
1402 | 58 | 58 | ||
1403 | 59 | class MockConfiguration : public click::Configuration { | 59 | class MockConfiguration : public click::Configuration { |
1404 | @@ -100,7 +100,7 @@ | |||
1405 | 100 | .Times(1) | 100 | .Times(1) |
1406 | 101 | .WillOnce(Return(response)); | 101 | .WillOnce(Return(response)); |
1407 | 102 | 102 | ||
1409 | 103 | indexPtr->search("", [](click::Packages) {}); | 103 | indexPtr->search("", "", [](click::Packages, click::DepartmentList) {}); |
1410 | 104 | } | 104 | } |
1411 | 105 | 105 | ||
1412 | 106 | TEST_F(IndexTest, testSearchSendsBuiltQueryAsParam) | 106 | TEST_F(IndexTest, testSearchSendsBuiltQueryAsParam) |
1413 | @@ -116,11 +116,11 @@ | |||
1414 | 116 | .Times(1) | 116 | .Times(1) |
1415 | 117 | .WillOnce(Return(response)); | 117 | .WillOnce(Return(response)); |
1416 | 118 | 118 | ||
1418 | 119 | EXPECT_CALL(*indexPtr, build_index_query(FAKE_QUERY)) | 119 | EXPECT_CALL(*indexPtr, build_index_query(FAKE_QUERY, "")) |
1419 | 120 | .Times(1) | 120 | .Times(1) |
1420 | 121 | .WillOnce(Return(FAKE_BUILT_QUERY)); | 121 | .WillOnce(Return(FAKE_BUILT_QUERY)); |
1421 | 122 | 122 | ||
1423 | 123 | indexPtr->search(FAKE_QUERY, [](click::Packages) {}); | 123 | indexPtr->search(FAKE_QUERY, "", [](click::Packages, click::DepartmentList) {}); |
1424 | 124 | } | 124 | } |
1425 | 125 | 125 | ||
1426 | 126 | TEST_F(IndexTest, testSearchSendsRightPath) | 126 | TEST_F(IndexTest, testSearchSendsRightPath) |
1427 | @@ -133,7 +133,7 @@ | |||
1428 | 133 | .Times(1) | 133 | .Times(1) |
1429 | 134 | .WillOnce(Return(response)); | 134 | .WillOnce(Return(response)); |
1430 | 135 | 135 | ||
1432 | 136 | indexPtr->search("", [](click::Packages) {}); | 136 | indexPtr->search("", "", [](click::Packages, click::DepartmentList) {}); |
1433 | 137 | } | 137 | } |
1434 | 138 | 138 | ||
1435 | 139 | TEST_F(IndexTest, testSearchCallbackIsCalled) | 139 | TEST_F(IndexTest, testSearchCallbackIsCalled) |
1436 | @@ -150,7 +150,7 @@ | |||
1437 | 150 | .WillOnce(Return(response)); | 150 | .WillOnce(Return(response)); |
1438 | 151 | EXPECT_CALL(*this, search_callback(_)).Times(1); | 151 | EXPECT_CALL(*this, search_callback(_)).Times(1); |
1439 | 152 | 152 | ||
1441 | 153 | indexPtr->search("", [this](click::Packages packages){ | 153 | indexPtr->search("", "", [this](click::Packages packages, click::DepartmentList){ |
1442 | 154 | search_callback(packages); | 154 | search_callback(packages); |
1443 | 155 | }); | 155 | }); |
1444 | 156 | response->replyFinished(); | 156 | response->replyFinished(); |
1445 | @@ -171,7 +171,7 @@ | |||
1446 | 171 | click::Packages empty_package_list; | 171 | click::Packages empty_package_list; |
1447 | 172 | EXPECT_CALL(*this, search_callback(empty_package_list)).Times(1); | 172 | EXPECT_CALL(*this, search_callback(empty_package_list)).Times(1); |
1448 | 173 | 173 | ||
1450 | 174 | indexPtr->search("", [this](click::Packages packages){ | 174 | indexPtr->search("", "", [this](click::Packages packages, click::DepartmentList){ |
1451 | 175 | search_callback(packages); | 175 | search_callback(packages); |
1452 | 176 | }); | 176 | }); |
1453 | 177 | response->replyFinished(); | 177 | response->replyFinished(); |
1454 | @@ -200,7 +200,7 @@ | |||
1455 | 200 | }; | 200 | }; |
1456 | 201 | EXPECT_CALL(*this, search_callback(single_package_list)).Times(1); | 201 | EXPECT_CALL(*this, search_callback(single_package_list)).Times(1); |
1457 | 202 | 202 | ||
1459 | 203 | indexPtr->search("", [this](click::Packages packages){ | 203 | indexPtr->search("", "", [this](click::Packages packages, click::DepartmentList){ |
1460 | 204 | search_callback(packages); | 204 | search_callback(packages); |
1461 | 205 | }); | 205 | }); |
1462 | 206 | response->replyFinished(); | 206 | response->replyFinished(); |
1463 | @@ -215,7 +215,7 @@ | |||
1464 | 215 | .Times(1) | 215 | .Times(1) |
1465 | 216 | .WillOnce(Return(response)); | 216 | .WillOnce(Return(response)); |
1466 | 217 | 217 | ||
1468 | 218 | auto search_operation = indexPtr->search("", [](click::Packages) {}); | 218 | auto search_operation = indexPtr->search("", "", [](click::Packages, click::DepartmentList) {}); |
1469 | 219 | EXPECT_CALL(reply.instance, abort()).Times(1); | 219 | EXPECT_CALL(reply.instance, abort()).Times(1); |
1470 | 220 | search_operation.cancel(); | 220 | search_operation.cancel(); |
1471 | 221 | } | 221 | } |
1472 | @@ -234,7 +234,7 @@ | |||
1473 | 234 | .Times(1) | 234 | .Times(1) |
1474 | 235 | .WillOnce(Return(response)); | 235 | .WillOnce(Return(response)); |
1475 | 236 | EXPECT_CALL(reply.instance, errorString()).Times(1).WillOnce(Return("fake error")); | 236 | EXPECT_CALL(reply.instance, errorString()).Times(1).WillOnce(Return("fake error")); |
1477 | 237 | indexPtr->search("", [this](click::Packages packages){ | 237 | indexPtr->search("", "", [this](click::Packages packages, click::DepartmentList){ |
1478 | 238 | search_callback(packages); | 238 | search_callback(packages); |
1479 | 239 | }); | 239 | }); |
1480 | 240 | 240 | ||
1481 | 241 | 241 | ||
1482 | === modified file 'scope/clickapps/apps-query.cpp' | |||
1483 | --- scope/clickapps/apps-query.cpp 2014-06-10 21:09:52 +0000 | |||
1484 | +++ scope/clickapps/apps-query.cpp 2014-06-18 18:08:01 +0000 | |||
1485 | @@ -128,25 +128,24 @@ | |||
1486 | 128 | 128 | ||
1487 | 129 | struct click::Query::Private | 129 | struct click::Query::Private |
1488 | 130 | { | 130 | { |
1492 | 131 | Private(const unity::scopes::CannedQuery& query, click::Index& index, const scopes::SearchMetadata& metadata) | 131 | Private(click::Index& index, const scopes::SearchMetadata& metadata) |
1493 | 132 | : query(query), | 132 | : index(index), |
1491 | 133 | index(index), | ||
1494 | 134 | meta(metadata) | 133 | meta(metadata) |
1495 | 135 | { | 134 | { |
1496 | 136 | } | 135 | } |
1497 | 137 | unity::scopes::CannedQuery query; | ||
1498 | 138 | click::Index& index; | 136 | click::Index& index; |
1499 | 139 | scopes::SearchMetadata meta; | 137 | scopes::SearchMetadata meta; |
1500 | 140 | }; | 138 | }; |
1501 | 141 | 139 | ||
1502 | 142 | click::Query::Query(unity::scopes::CannedQuery const& query, click::Index& index, scopes::SearchMetadata const& metadata) | 140 | click::Query::Query(unity::scopes::CannedQuery const& query, click::Index& index, scopes::SearchMetadata const& metadata) |
1504 | 143 | : impl(new Private(query, index, metadata)) | 141 | : unity::scopes::SearchQueryBase(query, metadata), |
1505 | 142 | impl(new Private(index, metadata)) | ||
1506 | 144 | { | 143 | { |
1507 | 145 | } | 144 | } |
1508 | 146 | 145 | ||
1509 | 147 | void click::Query::cancelled() | 146 | void click::Query::cancelled() |
1510 | 148 | { | 147 | { |
1512 | 149 | qDebug() << "cancelling search of" << QString::fromStdString(impl->query.query_string()); | 148 | qDebug() << "cancelling search of" << QString::fromStdString(query().query_string()); |
1513 | 150 | } | 149 | } |
1514 | 151 | 150 | ||
1515 | 152 | click::Query::~Query() | 151 | click::Query::~Query() |
1516 | @@ -171,10 +170,10 @@ | |||
1517 | 171 | static const std::string title = _("Get more apps in Ubuntu store"); | 170 | static const std::string title = _("Get more apps in Ubuntu store"); |
1518 | 172 | auto name = title; | 171 | auto name = title; |
1519 | 173 | 172 | ||
1522 | 174 | std::string query = impl->query.query_string(); | 173 | std::string querystr = query().query_string(); |
1523 | 175 | std::transform(query.begin(), query.end(), query.begin(), ::tolower); | 174 | std::transform(querystr.begin(), querystr.end(), querystr.begin(), ::tolower); |
1524 | 176 | std::transform(name.begin(), name.end(), name.begin(), ::tolower); | 175 | std::transform(name.begin(), name.end(), name.begin(), ::tolower); |
1526 | 177 | if (query.empty() || name.find(query) != std::string::npos) | 176 | if (querystr.empty() || name.find(querystr) != std::string::npos) |
1527 | 178 | { | 177 | { |
1528 | 179 | scopes::CategoryRenderer rdr(CATEGORY_STORE); | 178 | scopes::CategoryRenderer rdr(CATEGORY_STORE); |
1529 | 180 | auto cat = searchReply->register_category("store", "", "", rdr); | 179 | auto cat = searchReply->register_category("store", "", "", rdr); |
1530 | @@ -196,13 +195,13 @@ | |||
1531 | 196 | 195 | ||
1532 | 197 | void click::Query::run(scopes::SearchReplyProxy const& searchReply) | 196 | void click::Query::run(scopes::SearchReplyProxy const& searchReply) |
1533 | 198 | { | 197 | { |
1535 | 199 | auto query = impl->query.query_string(); | 198 | auto querystr = query().query_string(); |
1536 | 200 | std::string categoryTemplate = CATEGORY_APPS_SEARCH; | 199 | std::string categoryTemplate = CATEGORY_APPS_SEARCH; |
1538 | 201 | if (query.empty()) { | 200 | if (querystr.empty()) { |
1539 | 202 | categoryTemplate = CATEGORY_APPS_DISPLAY; | 201 | categoryTemplate = CATEGORY_APPS_DISPLAY; |
1540 | 203 | } | 202 | } |
1541 | 204 | auto localResults = clickInterfaceInstance().find_installed_apps( | 203 | auto localResults = clickInterfaceInstance().find_installed_apps( |
1543 | 205 | query); | 204 | querystr); |
1544 | 206 | 205 | ||
1545 | 207 | push_local_results( | 206 | push_local_results( |
1546 | 208 | searchReply, | 207 | searchReply, |
1547 | 209 | 208 | ||
1548 | === modified file 'scope/clickapps/apps-scope.cpp' | |||
1549 | --- scope/clickapps/apps-scope.cpp 2014-06-12 14:26:26 +0000 | |||
1550 | +++ scope/clickapps/apps-scope.cpp 2014-06-18 18:08:01 +0000 | |||
1551 | @@ -54,13 +54,11 @@ | |||
1552 | 54 | { | 54 | { |
1553 | 55 | } | 55 | } |
1554 | 56 | 56 | ||
1556 | 57 | int click::Scope::start(std::string const&, scopes::RegistryProxy const&) | 57 | void click::Scope::start(std::string const&, scopes::RegistryProxy const&) |
1557 | 58 | { | 58 | { |
1558 | 59 | setlocale(LC_ALL, ""); | 59 | setlocale(LC_ALL, ""); |
1559 | 60 | bindtextdomain(GETTEXT_PACKAGE, GETTEXT_LOCALEDIR); | 60 | bindtextdomain(GETTEXT_PACKAGE, GETTEXT_LOCALEDIR); |
1560 | 61 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); | 61 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
1561 | 62 | |||
1562 | 63 | return VERSION; | ||
1563 | 64 | } | 62 | } |
1564 | 65 | 63 | ||
1565 | 66 | void click::Scope::run() | 64 | void click::Scope::run() |
1566 | @@ -91,14 +89,15 @@ | |||
1567 | 91 | } | 89 | } |
1568 | 92 | 90 | ||
1569 | 93 | 91 | ||
1571 | 94 | unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& /* widget_id */, std::string const& action_id) | 92 | unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, |
1572 | 93 | std::string const& /* widget_id */, std::string const& action_id) | ||
1573 | 95 | { | 94 | { |
1574 | 96 | if (action_id == click::Preview::Actions::CONFIRM_UNINSTALL) { | 95 | if (action_id == click::Preview::Actions::CONFIRM_UNINSTALL) { |
1575 | 97 | const unity::scopes::CannedQuery cquery("clickscope"); | 96 | const unity::scopes::CannedQuery cquery("clickscope"); |
1577 | 98 | return scopes::ActivationQueryBase::UPtr(new PerformUninstallAction(result, unity::scopes::ActivationResponse(cquery))); | 97 | return scopes::ActivationQueryBase::UPtr(new PerformUninstallAction(result, metadata, unity::scopes::ActivationResponse(cquery))); |
1578 | 99 | } | 98 | } |
1579 | 100 | 99 | ||
1581 | 101 | auto activation = new ScopeActivation(); | 100 | auto activation = new ScopeActivation(result, metadata); |
1582 | 102 | qDebug() << "perform_action called with action_id" << QString().fromStdString(action_id); | 101 | qDebug() << "perform_action called with action_id" << QString().fromStdString(action_id); |
1583 | 103 | 102 | ||
1584 | 104 | if (action_id == click::Preview::Actions::UNINSTALL_CLICK) { | 103 | if (action_id == click::Preview::Actions::UNINSTALL_CLICK) { |
1585 | 105 | 104 | ||
1586 | === modified file 'scope/clickapps/apps-scope.h' | |||
1587 | --- scope/clickapps/apps-scope.h 2014-05-27 06:57:52 +0000 | |||
1588 | +++ scope/clickapps/apps-scope.h 2014-06-18 18:08:01 +0000 | |||
1589 | @@ -49,14 +49,14 @@ | |||
1590 | 49 | Scope(); | 49 | Scope(); |
1591 | 50 | ~Scope(); | 50 | ~Scope(); |
1592 | 51 | 51 | ||
1594 | 52 | virtual int start(std::string const&, scopes::RegistryProxy const&) override; | 52 | virtual void start(std::string const&, scopes::RegistryProxy const&) override; |
1595 | 53 | 53 | ||
1596 | 54 | virtual void run() override; | 54 | virtual void run() override; |
1597 | 55 | virtual void stop() override; | 55 | virtual void stop() override; |
1598 | 56 | 56 | ||
1600 | 57 | virtual scopes::SearchQueryBase::UPtr search(scopes::CannedQuery const& q, scopes::SearchMetadata const&) override; | 57 | virtual scopes::SearchQueryBase::UPtr search(scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) override; |
1601 | 58 | unity::scopes::PreviewQueryBase::UPtr preview(const unity::scopes::Result&, | 58 | unity::scopes::PreviewQueryBase::UPtr preview(const unity::scopes::Result&, |
1603 | 59 | const unity::scopes::ActionMetadata&) override; | 59 | const unity::scopes::ActionMetadata& hints) override; |
1604 | 60 | 60 | ||
1605 | 61 | virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override; | 61 | virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override; |
1606 | 62 | 62 | ||
1607 | 63 | 63 | ||
1608 | === modified file 'scope/clickstore/store-query.cpp' | |||
1609 | --- scope/clickstore/store-query.cpp 2014-06-13 23:18:41 +0000 | |||
1610 | +++ scope/clickstore/store-query.cpp 2014-06-18 18:08:01 +0000 | |||
1611 | @@ -30,6 +30,7 @@ | |||
1612 | 30 | #include <click/application.h> | 30 | #include <click/application.h> |
1613 | 31 | #include <click/interface.h> | 31 | #include <click/interface.h> |
1614 | 32 | #include "store-query.h" | 32 | #include "store-query.h" |
1615 | 33 | #include "store-scope.h" | ||
1616 | 33 | #include <click/qtbridge.h> | 34 | #include <click/qtbridge.h> |
1617 | 34 | 35 | ||
1618 | 35 | #include <click/key_file_locator.h> | 36 | #include <click/key_file_locator.h> |
1619 | @@ -37,6 +38,7 @@ | |||
1620 | 37 | #include <unity/scopes/Annotation.h> | 38 | #include <unity/scopes/Annotation.h> |
1621 | 38 | #include <unity/scopes/CategoryRenderer.h> | 39 | #include <unity/scopes/CategoryRenderer.h> |
1622 | 39 | #include <unity/scopes/CategorisedResult.h> | 40 | #include <unity/scopes/CategorisedResult.h> |
1623 | 41 | #include <unity/scopes/Department.h> | ||
1624 | 40 | #include <unity/scopes/CannedQuery.h> | 42 | #include <unity/scopes/CannedQuery.h> |
1625 | 41 | #include <unity/scopes/SearchReply.h> | 43 | #include <unity/scopes/SearchReply.h> |
1626 | 42 | #include <unity/scopes/SearchMetadata.h> | 44 | #include <unity/scopes/SearchMetadata.h> |
1627 | @@ -93,20 +95,26 @@ | |||
1628 | 93 | 95 | ||
1629 | 94 | struct click::Query::Private | 96 | struct click::Query::Private |
1630 | 95 | { | 97 | { |
1634 | 96 | Private(const unity::scopes::CannedQuery& query, click::Index& index, const scopes::SearchMetadata& metadata) | 98 | Private(click::Index& index, click::DepartmentLookup& depts, |
1635 | 97 | : query(query), | 99 | click::HighlightList& highlights, const scopes::SearchMetadata& metadata) |
1636 | 98 | index(index), | 100 | : index(index), |
1637 | 101 | department_lookup(depts), | ||
1638 | 102 | highlights(highlights), | ||
1639 | 99 | meta(metadata) | 103 | meta(metadata) |
1640 | 100 | { | 104 | { |
1641 | 101 | } | 105 | } |
1642 | 102 | unity::scopes::CannedQuery query; | ||
1643 | 103 | click::Index& index; | 106 | click::Index& index; |
1644 | 107 | click::DepartmentLookup& department_lookup; | ||
1645 | 108 | click::HighlightList& highlights; | ||
1646 | 104 | scopes::SearchMetadata meta; | 109 | scopes::SearchMetadata meta; |
1647 | 105 | click::web::Cancellable search_operation; | 110 | click::web::Cancellable search_operation; |
1648 | 106 | }; | 111 | }; |
1649 | 107 | 112 | ||
1652 | 108 | click::Query::Query(unity::scopes::CannedQuery const& query, click::Index& index, scopes::SearchMetadata const& metadata) | 113 | click::Query::Query(unity::scopes::CannedQuery const& query, click::Index& index, click::DepartmentLookup& depts, |
1653 | 109 | : impl(new Private(query, index, metadata)) | 114 | click::HighlightList& highlights, |
1654 | 115 | scopes::SearchMetadata const& metadata) | ||
1655 | 116 | : unity::scopes::SearchQueryBase(query, metadata), | ||
1656 | 117 | impl(new Private(index, depts, highlights, metadata)) | ||
1657 | 110 | { | 118 | { |
1658 | 111 | } | 119 | } |
1659 | 112 | 120 | ||
1660 | @@ -117,7 +125,7 @@ | |||
1661 | 117 | 125 | ||
1662 | 118 | void click::Query::cancelled() | 126 | void click::Query::cancelled() |
1663 | 119 | { | 127 | { |
1665 | 120 | qDebug() << "cancelling search of" << QString::fromStdString(impl->query.query_string()); | 128 | qDebug() << "cancelling search of" << QString::fromStdString(query().query_string()); |
1666 | 121 | impl->search_operation.cancel(); | 129 | impl->search_operation.cancel(); |
1667 | 122 | } | 130 | } |
1668 | 123 | 131 | ||
1669 | @@ -155,6 +163,166 @@ | |||
1670 | 155 | }); | 163 | }); |
1671 | 156 | } | 164 | } |
1672 | 157 | 165 | ||
1673 | 166 | // | ||
1674 | 167 | // creates department menu with narrowed-down list of subdepartments of current department, as | ||
1675 | 168 | // returned by server call | ||
1676 | 169 | void click::Query::populate_departments(const click::DepartmentList& subdepts, const std::string& current_dep_id, unity::scopes::Department::SPtr &root) | ||
1677 | 170 | { | ||
1678 | 171 | unity::scopes::DepartmentList departments; | ||
1679 | 172 | |||
1680 | 173 | // create a list of subdepartments of current department | ||
1681 | 174 | foreach (auto d, subdepts) | ||
1682 | 175 | { | ||
1683 | 176 | unity::scopes::Department::SPtr department = unity::scopes::Department::create(d->id(), query(), d->name()); | ||
1684 | 177 | if (d->has_children_flag()) | ||
1685 | 178 | { | ||
1686 | 179 | department->set_has_subdepartments(); | ||
1687 | 180 | } | ||
1688 | 181 | departments.push_back(department); | ||
1689 | 182 | } | ||
1690 | 183 | |||
1691 | 184 | if (current_dep_id != "") | ||
1692 | 185 | { | ||
1693 | 186 | auto curr_dpt = impl->department_lookup.get_department_info(current_dep_id); | ||
1694 | 187 | if (curr_dpt != nullptr) | ||
1695 | 188 | { | ||
1696 | 189 | unity::scopes::Department::SPtr current = unity::scopes::Department::create(current_dep_id, query(), curr_dpt->name()); | ||
1697 | 190 | if (departments.size() > 0) // this may be a leaf department | ||
1698 | 191 | { | ||
1699 | 192 | current->set_subdepartments(departments); | ||
1700 | 193 | } | ||
1701 | 194 | |||
1702 | 195 | auto parent_info = impl->department_lookup.get_parent(current_dep_id); | ||
1703 | 196 | if (parent_info != nullptr) | ||
1704 | 197 | { | ||
1705 | 198 | root = unity::scopes::Department::create(parent_info->id(), query(), parent_info->name()); | ||
1706 | 199 | root->set_subdepartments({current}); | ||
1707 | 200 | return; | ||
1708 | 201 | } | ||
1709 | 202 | else | ||
1710 | 203 | { | ||
1711 | 204 | root = unity::scopes::Department::create("", query(), _("All departments")); | ||
1712 | 205 | root->set_subdepartments({current}); | ||
1713 | 206 | return; | ||
1714 | 207 | } | ||
1715 | 208 | } | ||
1716 | 209 | else | ||
1717 | 210 | { | ||
1718 | 211 | qWarning() << "Unknown department:" << QString::fromStdString(current_dep_id); | ||
1719 | 212 | } | ||
1720 | 213 | } | ||
1721 | 214 | |||
1722 | 215 | root = unity::scopes::Department::create("", query(), _("All departments")); | ||
1723 | 216 | root->set_subdepartments(departments); | ||
1724 | 217 | } | ||
1725 | 218 | |||
1726 | 219 | void click::Query::push_package(const scopes::SearchReplyProxy& searchReply, scopes::Category::SCPtr category, const PackageSet &installedPackages, const Package& pkg) | ||
1727 | 220 | { | ||
1728 | 221 | qDebug() << "pushing result" << QString::fromStdString(pkg.name); | ||
1729 | 222 | try { | ||
1730 | 223 | scopes::CategorisedResult res(category); | ||
1731 | 224 | res.set_title(pkg.title); | ||
1732 | 225 | res.set_art(pkg.icon_url); | ||
1733 | 226 | res.set_uri(pkg.url); | ||
1734 | 227 | res[click::Query::ResultKeys::NAME] = pkg.name; | ||
1735 | 228 | auto installed = installedPackages.find(pkg); | ||
1736 | 229 | if (installed != installedPackages.end()) { | ||
1737 | 230 | res[click::Query::ResultKeys::INSTALLED] = true; | ||
1738 | 231 | res["subtitle"] = _("✔ INSTALLED"); | ||
1739 | 232 | res[click::Query::ResultKeys::VERSION] = installed->version; | ||
1740 | 233 | } else { | ||
1741 | 234 | res[click::Query::ResultKeys::INSTALLED] = false; | ||
1742 | 235 | // TODO: get the real price from the webservice (upcoming branch) | ||
1743 | 236 | res["subtitle"] = _("FREE"); | ||
1744 | 237 | } | ||
1745 | 238 | |||
1746 | 239 | this->push_result(searchReply, res); | ||
1747 | 240 | } catch(const std::exception& e){ | ||
1748 | 241 | qDebug() << "PackageDetails::loadJson: Exception thrown while decoding JSON: " << e.what() ; | ||
1749 | 242 | } catch(...){ | ||
1750 | 243 | qDebug() << "no reason to catch"; | ||
1751 | 244 | } | ||
1752 | 245 | } | ||
1753 | 246 | |||
1754 | 247 | void click::Query::push_highlights(const scopes::SearchReplyProxy& searchReply, const HighlightList& highlights, const PackageSet &locallyInstalledApps) | ||
1755 | 248 | { | ||
1756 | 249 | std::string categoryTemplate = CATEGORY_APPS_DISPLAY; //FIXME | ||
1757 | 250 | scopes::CategoryRenderer renderer(categoryTemplate); | ||
1758 | 251 | |||
1759 | 252 | for (auto const& hl: highlights) | ||
1760 | 253 | { | ||
1761 | 254 | auto category = register_category(searchReply, hl.name(), hl.name(), "", renderer); //FIXME: highlight slug | ||
1762 | 255 | for (auto const& pkg: hl.packages()) | ||
1763 | 256 | { | ||
1764 | 257 | push_package(searchReply, category, locallyInstalledApps, pkg); | ||
1765 | 258 | } | ||
1766 | 259 | } | ||
1767 | 260 | qDebug() << "Highlights pushed"; | ||
1768 | 261 | } | ||
1769 | 262 | |||
1770 | 263 | void click::Query::push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root) | ||
1771 | 264 | { | ||
1772 | 265 | if (root != nullptr) | ||
1773 | 266 | { | ||
1774 | 267 | try | ||
1775 | 268 | { | ||
1776 | 269 | qDebug() << "pushing departments"; | ||
1777 | 270 | searchReply->register_departments(root); | ||
1778 | 271 | } | ||
1779 | 272 | catch (const std::exception& e) | ||
1780 | 273 | { | ||
1781 | 274 | qWarning() << "Failed to register departments for query " << QString::fromStdString(query().query_string()) << | ||
1782 | 275 | ", current department " << QString::fromStdString(query().department_id()) << ": " << e.what(); | ||
1783 | 276 | } | ||
1784 | 277 | } | ||
1785 | 278 | else | ||
1786 | 279 | { | ||
1787 | 280 | qWarning() << "No departments data for query " << QString::fromStdString(query().query_string()) << | ||
1788 | 281 | "', current department " << QString::fromStdString(query().department_id()); | ||
1789 | 282 | } | ||
1790 | 283 | } | ||
1791 | 284 | |||
1792 | 285 | // | ||
1793 | 286 | // push highlights and departments | ||
1794 | 287 | // use cached highlights for root department, otherwise run an async job for highlights of current department. | ||
1795 | 288 | void click::Query::add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& locallyInstalledApps) | ||
1796 | 289 | { | ||
1797 | 290 | auto curdep = impl->department_lookup.get_department_info(query().department_id()); | ||
1798 | 291 | assert(curdep); | ||
1799 | 292 | auto subdepts = curdep->sub_departments(); | ||
1800 | 293 | if (query().department_id() == "") // top-level departments | ||
1801 | 294 | { | ||
1802 | 295 | unity::scopes::Department::SPtr root; | ||
1803 | 296 | populate_departments(subdepts, query().department_id(), root); | ||
1804 | 297 | push_departments(searchReply, root); | ||
1805 | 298 | |||
1806 | 299 | qDebug() << "pushing cached highlights"; | ||
1807 | 300 | push_highlights(searchReply, impl->highlights, locallyInstalledApps); | ||
1808 | 301 | this->finished(searchReply); //FIXME: this shouldn't be needed | ||
1809 | 302 | } | ||
1810 | 303 | else | ||
1811 | 304 | { | ||
1812 | 305 | qDebug() << "starting departments call for department" << QString::fromStdString(curdep->id()) << ", href" << QString::fromStdString(curdep->href()); | ||
1813 | 306 | impl->search_operation = impl->index.departments(curdep->href(), [this, locallyInstalledApps, searchReply](const DepartmentList& depts, | ||
1814 | 307 | const HighlightList& highlights, Index::Error error) | ||
1815 | 308 | { | ||
1816 | 309 | if (error == click::Index::Error::NoError) | ||
1817 | 310 | { | ||
1818 | 311 | qDebug() << "departments call completed"; | ||
1819 | 312 | unity::scopes::Department::SPtr root; | ||
1820 | 313 | populate_departments(depts, query().department_id(), root); | ||
1821 | 314 | push_departments(searchReply, root); | ||
1822 | 315 | push_highlights(searchReply, highlights, locallyInstalledApps); | ||
1823 | 316 | } | ||
1824 | 317 | else | ||
1825 | 318 | { | ||
1826 | 319 | qWarning() << "departments call failed"; | ||
1827 | 320 | } | ||
1828 | 321 | this->finished(searchReply); //FIXME: this shouldn't be needed | ||
1829 | 322 | }); | ||
1830 | 323 | } | ||
1831 | 324 | } | ||
1832 | 325 | |||
1833 | 158 | void click::Query::add_available_apps(scopes::SearchReplyProxy const& searchReply, | 326 | void click::Query::add_available_apps(scopes::SearchReplyProxy const& searchReply, |
1834 | 159 | const PackageSet& installedPackages, | 327 | const PackageSet& installedPackages, |
1835 | 160 | const std::string& categoryTemplate) | 328 | const std::string& categoryTemplate) |
1836 | @@ -162,12 +330,14 @@ | |||
1837 | 162 | scopes::CategoryRenderer categoryRenderer(categoryTemplate); | 330 | scopes::CategoryRenderer categoryRenderer(categoryTemplate); |
1838 | 163 | auto category = register_category(searchReply, "appstore", _("Available"), "", categoryRenderer); | 331 | auto category = register_category(searchReply, "appstore", _("Available"), "", categoryRenderer); |
1839 | 164 | 332 | ||
1840 | 333 | assert(searchReply); | ||
1841 | 334 | |||
1842 | 165 | run_under_qt([=]() | 335 | run_under_qt([=]() |
1843 | 166 | { | 336 | { |
1845 | 167 | auto search_cb = [this, searchReply, category, installedPackages](Packages packages) { | 337 | auto search_cb = [this, searchReply, category, installedPackages](Packages packages, DepartmentList) { |
1846 | 168 | qDebug("search callback"); | 338 | qDebug("search callback"); |
1847 | 169 | 339 | ||
1849 | 170 | // handle packages data | 340 | // handle packages data; FIXME: use push_package() |
1850 | 171 | foreach (auto p, packages) { | 341 | foreach (auto p, packages) { |
1851 | 172 | qDebug() << "pushing result" << QString::fromStdString(p.name); | 342 | qDebug() << "pushing result" << QString::fromStdString(p.name); |
1852 | 173 | try { | 343 | try { |
1853 | @@ -195,11 +365,58 @@ | |||
1854 | 195 | } | 365 | } |
1855 | 196 | } | 366 | } |
1856 | 197 | qDebug() << "search completed"; | 367 | qDebug() << "search completed"; |
1862 | 198 | this->finished(searchReply); | 368 | this->finished(searchReply); //FIXME: this shouldn't be needed |
1863 | 199 | }; | 369 | }; |
1864 | 200 | 370 | ||
1865 | 201 | qDebug() << "starting search of" << QString::fromStdString(impl->query.query_string()); | 371 | // this is the case when we do bootstrap for the first time, or it failed last time |
1866 | 202 | impl->search_operation = impl->index.search(impl->query.query_string(), search_cb); | 372 | if (impl->department_lookup.size() == 0 && !click::Scope::use_old_api()) |
1867 | 373 | { | ||
1868 | 374 | qDebug() << "performing bootstrap request"; | ||
1869 | 375 | impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages](const DepartmentList& deps, const | ||
1870 | 376 | HighlightList& highlights, click::Index::Error error, int error_code) { | ||
1871 | 377 | if (error == click::Index::Error::NoError) | ||
1872 | 378 | { | ||
1873 | 379 | qDebug() << "bootstrap request completed"; | ||
1874 | 380 | auto root = std::make_shared<click::Department>("", "All Departments", "", true); | ||
1875 | 381 | root->set_subdepartments(deps); | ||
1876 | 382 | DepartmentList rdeps { root }; | ||
1877 | 383 | impl->department_lookup.rebuild(rdeps); | ||
1878 | 384 | impl->highlights = highlights; | ||
1879 | 385 | qDebug() << "Total number of departments:" << impl->department_lookup.size() << ", highlights:" << highlights.size(); | ||
1880 | 386 | } | ||
1881 | 387 | else | ||
1882 | 388 | { | ||
1883 | 389 | qWarning() << "bootstrap request failed"; | ||
1884 | 390 | if (error_code == 405) // method not allowed | ||
1885 | 391 | { | ||
1886 | 392 | qDebug() << "bootstrap not available, using old API"; | ||
1887 | 393 | click::Scope::set_use_old_api(); | ||
1888 | 394 | } | ||
1889 | 395 | } | ||
1890 | 396 | |||
1891 | 397 | if (query().query_string().empty() && !click::Scope::use_old_api()) | ||
1892 | 398 | { | ||
1893 | 399 | add_highlights(searchReply, installedPackages); | ||
1894 | 400 | } | ||
1895 | 401 | else | ||
1896 | 402 | { | ||
1897 | 403 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); | ||
1898 | 404 | impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); | ||
1899 | 405 | } | ||
1900 | 406 | }); | ||
1901 | 407 | } | ||
1902 | 408 | else | ||
1903 | 409 | { | ||
1904 | 410 | if (query().query_string().empty() && !click::Scope::use_old_api()) | ||
1905 | 411 | { | ||
1906 | 412 | add_highlights(searchReply, installedPackages); | ||
1907 | 413 | } | ||
1908 | 414 | else // normal search | ||
1909 | 415 | { | ||
1910 | 416 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); | ||
1911 | 417 | impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); | ||
1912 | 418 | } | ||
1913 | 419 | } | ||
1914 | 203 | }); | 420 | }); |
1915 | 204 | } | 421 | } |
1916 | 205 | 422 | ||
1917 | @@ -222,9 +439,9 @@ | |||
1918 | 222 | 439 | ||
1919 | 223 | void click::Query::run(scopes::SearchReplyProxy const& searchReply) | 440 | void click::Query::run(scopes::SearchReplyProxy const& searchReply) |
1920 | 224 | { | 441 | { |
1922 | 225 | auto query = impl->query.query_string(); | 442 | auto q = query().query_string(); |
1923 | 226 | std::string categoryTemplate = CATEGORY_APPS_SEARCH; | 443 | std::string categoryTemplate = CATEGORY_APPS_SEARCH; |
1925 | 227 | if (query.empty()) { | 444 | if (q.empty()) { |
1926 | 228 | categoryTemplate = CATEGORY_APPS_DISPLAY; | 445 | categoryTemplate = CATEGORY_APPS_DISPLAY; |
1927 | 229 | } | 446 | } |
1928 | 230 | 447 | ||
1929 | 231 | 448 | ||
1930 | === modified file 'scope/clickstore/store-query.h' | |||
1931 | --- scope/clickstore/store-query.h 2014-06-16 14:09:21 +0000 | |||
1932 | +++ scope/clickstore/store-query.h 2014-06-18 18:08:01 +0000 | |||
1933 | @@ -32,10 +32,16 @@ | |||
1934 | 32 | 32 | ||
1935 | 33 | 33 | ||
1936 | 34 | #include <unity/scopes/SearchQueryBase.h> | 34 | #include <unity/scopes/SearchQueryBase.h> |
1937 | 35 | #include <unity/scopes/Department.h> | ||
1938 | 35 | 36 | ||
1939 | 36 | namespace scopes = unity::scopes; | 37 | namespace scopes = unity::scopes; |
1940 | 37 | 38 | ||
1941 | 38 | #include <QSharedPointer> | 39 | #include <QSharedPointer> |
1942 | 40 | #include <set> | ||
1943 | 41 | |||
1944 | 42 | #include <click/department-lookup.h> | ||
1945 | 43 | #include <click/package.h> | ||
1946 | 44 | #include <click/highlights.h> | ||
1947 | 39 | #include <click/interface.h> | 45 | #include <click/interface.h> |
1948 | 40 | 46 | ||
1949 | 41 | namespace click | 47 | namespace click |
1950 | @@ -43,6 +49,7 @@ | |||
1951 | 43 | 49 | ||
1952 | 44 | class Application; | 50 | class Application; |
1953 | 45 | class Index; | 51 | class Index; |
1954 | 52 | class DepartmentLookup; | ||
1955 | 46 | 53 | ||
1956 | 47 | class Query : public scopes::SearchQueryBase | 54 | class Query : public scopes::SearchQueryBase |
1957 | 48 | { | 55 | { |
1958 | @@ -69,7 +76,8 @@ | |||
1959 | 69 | constexpr static const char* VERSION{"version"}; | 76 | constexpr static const char* VERSION{"version"}; |
1960 | 70 | }; | 77 | }; |
1961 | 71 | 78 | ||
1963 | 72 | Query(unity::scopes::CannedQuery const& query, click::Index& index, scopes::SearchMetadata const& metadata); | 79 | Query(unity::scopes::CannedQuery const& query, click::Index& index, click::DepartmentLookup& dept_lookup, click::HighlightList& highlights, |
1964 | 80 | scopes::SearchMetadata const& metadata); | ||
1965 | 73 | virtual ~Query(); | 81 | virtual ~Query(); |
1966 | 74 | 82 | ||
1967 | 75 | virtual void cancelled() override; | 83 | virtual void cancelled() override; |
1968 | @@ -77,8 +85,10 @@ | |||
1969 | 77 | virtual void run(scopes::SearchReplyProxy const& reply) override; | 85 | virtual void run(scopes::SearchReplyProxy const& reply) override; |
1970 | 78 | 86 | ||
1971 | 79 | protected: | 87 | protected: |
1974 | 80 | virtual void add_available_apps(const scopes::SearchReplyProxy &searchReply, | 88 | virtual void populate_departments(const click::DepartmentList& depts, const std::string& current_department_id, unity::scopes::Department::SPtr &root); |
1975 | 81 | const PackageSet &installedPackages, const std::string &category); | 89 | virtual void push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root); |
1976 | 90 | virtual void add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& installedPackages); | ||
1977 | 91 | virtual void add_available_apps(const scopes::SearchReplyProxy &searchReply, const PackageSet &installedPackages, const std::string &category); | ||
1978 | 82 | virtual click::Interface& clickInterfaceInstance(); | 92 | virtual click::Interface& clickInterfaceInstance(); |
1979 | 83 | virtual PackageSet get_installed_packages(); | 93 | virtual PackageSet get_installed_packages(); |
1980 | 84 | virtual bool push_result(const scopes::SearchReplyProxy &searchReply, scopes::CategorisedResult const& res); | 94 | virtual bool push_result(const scopes::SearchReplyProxy &searchReply, scopes::CategorisedResult const& res); |
1981 | @@ -88,6 +98,9 @@ | |||
1982 | 88 | std::string const& title, | 98 | std::string const& title, |
1983 | 89 | std::string const& icon, | 99 | std::string const& icon, |
1984 | 90 | scopes::CategoryRenderer const& renderer_template); | 100 | scopes::CategoryRenderer const& renderer_template); |
1985 | 101 | virtual void push_package(const scopes::SearchReplyProxy& searchReply, scopes::Category::SCPtr category, const PackageSet &locallyInstalledApps, | ||
1986 | 102 | const click::Package& pkg); | ||
1987 | 103 | virtual void push_highlights(const scopes::SearchReplyProxy& searchReply, const HighlightList& highlights, const PackageSet &locallyInstalledApps); | ||
1988 | 91 | virtual void run_under_qt(const std::function<void()> &task); | 104 | virtual void run_under_qt(const std::function<void()> &task); |
1989 | 92 | 105 | ||
1990 | 93 | private: | 106 | private: |
1991 | 94 | 107 | ||
1992 | === modified file 'scope/clickstore/store-scope.cpp' | |||
1993 | --- scope/clickstore/store-scope.cpp 2014-06-17 21:32:44 +0000 | |||
1994 | +++ scope/clickstore/store-scope.cpp 2014-06-18 18:08:01 +0000 | |||
1995 | @@ -28,6 +28,7 @@ | |||
1996 | 28 | */ | 28 | */ |
1997 | 29 | 29 | ||
1998 | 30 | #include <click/qtbridge.h> | 30 | #include <click/qtbridge.h> |
1999 | 31 | #include <click/department-lookup.h> | ||
2000 | 31 | #include "store-scope.h" | 32 | #include "store-scope.h" |
2001 | 32 | #include "store-query.h" | 33 | #include "store-query.h" |
2002 | 33 | #include <click/preview.h> | 34 | #include <click/preview.h> |
2003 | @@ -42,27 +43,38 @@ | |||
2004 | 42 | 43 | ||
2005 | 43 | #include <logging.h> | 44 | #include <logging.h> |
2006 | 44 | 45 | ||
2007 | 46 | bool click::Scope::old_api = false; | ||
2008 | 45 | 47 | ||
2009 | 46 | click::Scope::Scope() | 48 | click::Scope::Scope() |
2010 | 47 | { | 49 | { |
2011 | 48 | nam.reset(new click::network::AccessManager()); | 50 | nam.reset(new click::network::AccessManager()); |
2012 | 49 | client.reset(new click::web::Client(nam)); | 51 | client.reset(new click::web::Client(nam)); |
2013 | 50 | index.reset(new click::Index(client)); | 52 | index.reset(new click::Index(client)); |
2014 | 53 | depts.reset(new click::DepartmentLookup()); | ||
2015 | 54 | highlights.reset(new click::HighlightList()); | ||
2016 | 51 | } | 55 | } |
2017 | 52 | 56 | ||
2018 | 53 | click::Scope::~Scope() | 57 | click::Scope::~Scope() |
2019 | 54 | { | 58 | { |
2020 | 55 | } | 59 | } |
2021 | 56 | 60 | ||
2023 | 57 | int click::Scope::start(std::string const&, scopes::RegistryProxy const&) | 61 | void click::Scope::set_use_old_api() |
2024 | 62 | { | ||
2025 | 63 | old_api = true; | ||
2026 | 64 | } | ||
2027 | 65 | |||
2028 | 66 | bool click::Scope::use_old_api() | ||
2029 | 67 | { | ||
2030 | 68 | return old_api; | ||
2031 | 69 | } | ||
2032 | 70 | |||
2033 | 71 | void click::Scope::start(std::string const&, scopes::RegistryProxy const&) | ||
2034 | 58 | { | 72 | { |
2035 | 59 | setlocale(LC_ALL, ""); | 73 | setlocale(LC_ALL, ""); |
2036 | 60 | // FIXME: This is wrong, but needed for json-cpp workaround. | 74 | // FIXME: This is wrong, but needed for json-cpp workaround. |
2037 | 61 | setlocale(LC_MONETARY, "C"); | 75 | setlocale(LC_MONETARY, "C"); |
2038 | 62 | bindtextdomain(GETTEXT_PACKAGE, GETTEXT_LOCALEDIR); | 76 | bindtextdomain(GETTEXT_PACKAGE, GETTEXT_LOCALEDIR); |
2039 | 63 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); | 77 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
2040 | 64 | |||
2041 | 65 | return VERSION; | ||
2042 | 66 | } | 78 | } |
2043 | 67 | 79 | ||
2044 | 68 | void click::Scope::run() | 80 | void click::Scope::run() |
2045 | @@ -70,7 +82,6 @@ | |||
2046 | 70 | static const int zero = 0; | 82 | static const int zero = 0; |
2047 | 71 | auto emptyCb = [this]() | 83 | auto emptyCb = [this]() |
2048 | 72 | { | 84 | { |
2049 | 73 | |||
2050 | 74 | }; | 85 | }; |
2051 | 75 | 86 | ||
2052 | 76 | qt::core::world::build_and_run(zero, nullptr, emptyCb); | 87 | qt::core::world::build_and_run(zero, nullptr, emptyCb); |
2053 | @@ -83,7 +94,7 @@ | |||
2054 | 83 | 94 | ||
2055 | 84 | scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) | 95 | scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) |
2056 | 85 | { | 96 | { |
2058 | 86 | return scopes::SearchQueryBase::UPtr(new click::Query(q, *index, metadata)); | 97 | return scopes::SearchQueryBase::UPtr(new click::Query(q, *index, *depts, *highlights, metadata)); |
2059 | 87 | } | 98 | } |
2060 | 88 | 99 | ||
2061 | 89 | 100 | ||
2062 | @@ -93,12 +104,21 @@ | |||
2063 | 93 | return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam)}; | 104 | return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam)}; |
2064 | 94 | } | 105 | } |
2065 | 95 | 106 | ||
2066 | 107 | <<<<<<< TREE | ||
2067 | 96 | unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& /* result */, unity::scopes::ActionMetadata const& metadata, | 108 | unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& /* result */, unity::scopes::ActionMetadata const& metadata, |
2068 | 97 | std::string const& widget_id, std::string const& _action_id) | 109 | std::string const& widget_id, std::string const& _action_id) |
2069 | 110 | ======= | ||
2070 | 111 | unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& /* widget_id */, std::string const& action_id) | ||
2071 | 112 | >>>>>>> MERGE-SOURCE | ||
2072 | 98 | { | 113 | { |
2073 | 114 | <<<<<<< TREE | ||
2074 | 99 | std::string action_id = _action_id; | 115 | std::string action_id = _action_id; |
2075 | 100 | auto activation = new ScopeActivation(); | 116 | auto activation = new ScopeActivation(); |
2076 | 101 | qDebug() << "perform_action called with widget_id" << QString::fromStdString(widget_id) << "and action_id:" << QString::fromStdString(action_id); | 117 | qDebug() << "perform_action called with widget_id" << QString::fromStdString(widget_id) << "and action_id:" << QString::fromStdString(action_id); |
2077 | 118 | ======= | ||
2078 | 119 | auto activation = new ScopeActivation(result, metadata); | ||
2079 | 120 | qDebug() << "perform_action called with action_id" << QString().fromStdString(action_id); | ||
2080 | 121 | >>>>>>> MERGE-SOURCE | ||
2081 | 102 | 122 | ||
2082 | 103 | // if the purchase is completed, do the install | 123 | // if the purchase is completed, do the install |
2083 | 104 | if (action_id == "purchaseCompleted") { | 124 | if (action_id == "purchaseCompleted") { |
2084 | 105 | 125 | ||
2085 | === modified file 'scope/clickstore/store-scope.h' | |||
2086 | --- scope/clickstore/store-scope.h 2014-05-27 06:57:52 +0000 | |||
2087 | +++ scope/clickstore/store-scope.h 2014-06-18 18:08:01 +0000 | |||
2088 | @@ -30,6 +30,7 @@ | |||
2089 | 30 | #ifndef CLICK_SCOPE_H | 30 | #ifndef CLICK_SCOPE_H |
2090 | 31 | #define CLICK_SCOPE_H | 31 | #define CLICK_SCOPE_H |
2091 | 32 | 32 | ||
2092 | 33 | #include <memory> | ||
2093 | 33 | #include <click/network_access_manager.h> | 34 | #include <click/network_access_manager.h> |
2094 | 34 | #include <click/webclient.h> | 35 | #include <click/webclient.h> |
2095 | 35 | 36 | ||
2096 | @@ -43,29 +44,38 @@ | |||
2097 | 43 | 44 | ||
2098 | 44 | namespace click | 45 | namespace click |
2099 | 45 | { | 46 | { |
2100 | 47 | |||
2101 | 48 | class DepartmentLookup; | ||
2102 | 49 | |||
2103 | 46 | class Scope : public scopes::ScopeBase | 50 | class Scope : public scopes::ScopeBase |
2104 | 47 | { | 51 | { |
2105 | 48 | public: | 52 | public: |
2106 | 49 | Scope(); | 53 | Scope(); |
2107 | 50 | ~Scope(); | 54 | ~Scope(); |
2108 | 51 | 55 | ||
2110 | 52 | virtual int start(std::string const&, scopes::RegistryProxy const&) override; | 56 | virtual void start(std::string const&, scopes::RegistryProxy const&) override; |
2111 | 53 | 57 | ||
2112 | 54 | virtual void run() override; | 58 | virtual void run() override; |
2113 | 55 | virtual void stop() override; | 59 | virtual void stop() override; |
2114 | 56 | 60 | ||
2116 | 57 | virtual scopes::SearchQueryBase::UPtr search(scopes::CannedQuery const& q, scopes::SearchMetadata const&) override; | 61 | virtual scopes::SearchQueryBase::UPtr search(scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) override; |
2117 | 58 | unity::scopes::PreviewQueryBase::UPtr preview(const unity::scopes::Result&, | 62 | unity::scopes::PreviewQueryBase::UPtr preview(const unity::scopes::Result&, |
2118 | 59 | const unity::scopes::ActionMetadata&) override; | 63 | const unity::scopes::ActionMetadata&) override; |
2119 | 60 | 64 | ||
2120 | 61 | virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override; | 65 | virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override; |
2121 | 62 | 66 | ||
2122 | 67 | static void set_use_old_api(); | ||
2123 | 68 | static bool use_old_api(); | ||
2124 | 69 | |||
2125 | 63 | private: | 70 | private: |
2126 | 64 | QSharedPointer<click::network::AccessManager> nam; | 71 | QSharedPointer<click::network::AccessManager> nam; |
2127 | 65 | QSharedPointer<click::web::Client> client; | 72 | QSharedPointer<click::web::Client> client; |
2128 | 66 | QSharedPointer<click::Index> index; | 73 | QSharedPointer<click::Index> index; |
2129 | 74 | std::shared_ptr<click::DepartmentLookup> depts; | ||
2130 | 75 | std::shared_ptr<click::HighlightList> highlights; | ||
2131 | 67 | 76 | ||
2132 | 68 | std::string installApplication(unity::scopes::Result const& result); | 77 | std::string installApplication(unity::scopes::Result const& result); |
2133 | 78 | static bool old_api; | ||
2134 | 69 | }; | 79 | }; |
2135 | 70 | } | 80 | } |
2136 | 71 | #endif // CLICK_SCOPE_H | 81 | #endif // CLICK_SCOPE_H |
2137 | 72 | 82 | ||
2138 | === modified file 'scope/tests/integration/webclient_integration.cpp' | |||
2139 | --- scope/tests/integration/webclient_integration.cpp 2014-06-12 21:05:25 +0000 | |||
2140 | +++ scope/tests/integration/webclient_integration.cpp 2014-06-18 18:08:01 +0000 | |||
2141 | @@ -30,6 +30,7 @@ | |||
2142 | 30 | #include <click/network_access_manager.h> | 30 | #include <click/network_access_manager.h> |
2143 | 31 | #include <click/webclient.h> | 31 | #include <click/webclient.h> |
2144 | 32 | #include <click/index.h> | 32 | #include <click/index.h> |
2145 | 33 | #include <click/departments.h> | ||
2146 | 33 | 34 | ||
2147 | 34 | #include <QCoreApplication> | 35 | #include <QCoreApplication> |
2148 | 35 | #include <QDebug> | 36 | #include <QDebug> |
2149 | @@ -102,7 +103,8 @@ | |||
2150 | 102 | new click::web::Client(namPtr)); | 103 | new click::web::Client(namPtr)); |
2151 | 103 | click::Index index(clientPtr); | 104 | click::Index index(clientPtr); |
2152 | 104 | click::Packages packages; | 105 | click::Packages packages; |
2154 | 105 | index.search("qr,architecture:armhf", [&, this](click::Packages found_packages){ | 106 | index.search("qr,architecture:armhf", "", [&, this](click::Packages found_packages, click::DepartmentList){ |
2155 | 107 | //TODO departments | ||
2156 | 106 | packages = found_packages; | 108 | packages = found_packages; |
2157 | 107 | Quit(); | 109 | Quit(); |
2158 | 108 | }); | 110 | }); |
2159 | 109 | 111 | ||
2160 | === modified file 'scope/tests/test_query.cpp' | |||
2161 | --- scope/tests/test_query.cpp 2014-06-12 22:17:42 +0000 | |||
2162 | +++ scope/tests/test_query.cpp 2014-06-18 18:08:01 +0000 | |||
2163 | @@ -45,6 +45,7 @@ | |||
2164 | 45 | #include <unity/scopes/CannedQuery.h> | 45 | #include <unity/scopes/CannedQuery.h> |
2165 | 46 | #include <unity/scopes/ScopeBase.h> | 46 | #include <unity/scopes/ScopeBase.h> |
2166 | 47 | #include <unity/scopes/SearchReply.h> | 47 | #include <unity/scopes/SearchReply.h> |
2167 | 48 | #include <unity/scopes/testing/MockSearchReply.h> | ||
2168 | 48 | 49 | ||
2169 | 49 | using namespace ::testing; | 50 | using namespace ::testing; |
2170 | 50 | using namespace click; | 51 | using namespace click; |
2171 | @@ -57,30 +58,45 @@ | |||
2172 | 57 | 58 | ||
2173 | 58 | class MockIndex : public click::Index { | 59 | class MockIndex : public click::Index { |
2174 | 59 | click::Packages packages; | 60 | click::Packages packages; |
2175 | 61 | click::DepartmentList departments; | ||
2176 | 62 | click::DepartmentList bootstrap_departments; | ||
2177 | 63 | click::HighlightList bootstrap_highlights; | ||
2178 | 60 | public: | 64 | public: |
2180 | 61 | MockIndex(click::Packages packages = click::Packages()) | 65 | MockIndex(click::Packages packages = click::Packages(), |
2181 | 66 | click::DepartmentList departments = click::DepartmentList(), | ||
2182 | 67 | click::DepartmentList boot_departments = click::DepartmentList()) | ||
2183 | 62 | : Index(QSharedPointer<click::web::Client>()), | 68 | : Index(QSharedPointer<click::web::Client>()), |
2199 | 63 | packages(packages) | 69 | packages(packages), |
2200 | 64 | { | 70 | departments(departments), |
2201 | 65 | 71 | bootstrap_departments(boot_departments) | |
2202 | 66 | } | 72 | { |
2203 | 67 | 73 | ||
2204 | 68 | click::web::Cancellable search(const std::string &query, std::function<void (click::Packages)> callback) override | 74 | } |
2205 | 69 | { | 75 | |
2206 | 70 | do_search(query, callback); | 76 | click::web::Cancellable search(const std::string &query, const std::string& department, std::function<void (click::Packages, click::DepartmentList)> callback) override |
2207 | 71 | callback(packages); | 77 | { |
2208 | 72 | return click::web::Cancellable(); | 78 | do_search(query, department, callback); |
2209 | 73 | } | 79 | callback(packages, departments); |
2210 | 74 | 80 | return click::web::Cancellable(); | |
2211 | 75 | MOCK_METHOD2(do_search, | 81 | } |
2212 | 76 | void(const std::string&, | 82 | |
2213 | 77 | std::function<void(click::Packages)>)); | 83 | click::web::Cancellable bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback) override |
2214 | 84 | { | ||
2215 | 85 | callback(bootstrap_departments, bootstrap_highlights, click::Index::Error::NoError, 0); | ||
2216 | 86 | return click::web::Cancellable(); | ||
2217 | 87 | } | ||
2218 | 88 | |||
2219 | 89 | MOCK_METHOD3(do_search, | ||
2220 | 90 | void(const std::string&, const std::string&, | ||
2221 | 91 | std::function<void(click::Packages, click::DepartmentList)>)); | ||
2222 | 78 | }; | 92 | }; |
2223 | 79 | 93 | ||
2224 | 80 | class MockQueryBase : public click::Query { | 94 | class MockQueryBase : public click::Query { |
2225 | 81 | public: | 95 | public: |
2226 | 82 | MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index, | 96 | MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index, |
2228 | 83 | scopes::SearchMetadata const& metadata) : click::Query(query, index, metadata) | 97 | click::DepartmentLookup& depts, |
2229 | 98 | click::HighlightList& highlights, | ||
2230 | 99 | scopes::SearchMetadata const& metadata) : click::Query(query, index, depts, highlights, metadata) | ||
2231 | 84 | { | 100 | { |
2232 | 85 | 101 | ||
2233 | 86 | } | 102 | } |
2234 | @@ -94,7 +110,9 @@ | |||
2235 | 94 | class MockQuery : public MockQueryBase { | 110 | class MockQuery : public MockQueryBase { |
2236 | 95 | public: | 111 | public: |
2237 | 96 | MockQuery(const unity::scopes::CannedQuery& query, click::Index& index, | 112 | MockQuery(const unity::scopes::CannedQuery& query, click::Index& index, |
2239 | 97 | scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, metadata) | 113 | click::DepartmentLookup& depts, |
2240 | 114 | click::HighlightList& highlights, | ||
2241 | 115 | scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, highlights, metadata) | ||
2242 | 98 | { | 116 | { |
2243 | 99 | 117 | ||
2244 | 100 | } | 118 | } |
2245 | @@ -118,7 +136,9 @@ | |||
2246 | 118 | class MockQueryRun : public MockQueryBase { | 136 | class MockQueryRun : public MockQueryBase { |
2247 | 119 | public: | 137 | public: |
2248 | 120 | MockQueryRun(const unity::scopes::CannedQuery& query, click::Index& index, | 138 | MockQueryRun(const unity::scopes::CannedQuery& query, click::Index& index, |
2250 | 121 | scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, metadata) | 139 | click::DepartmentLookup& depts, |
2251 | 140 | click::HighlightList& highlights, | ||
2252 | 141 | scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, highlights, metadata) | ||
2253 | 122 | { | 142 | { |
2254 | 123 | 143 | ||
2255 | 124 | } | 144 | } |
2256 | @@ -147,12 +167,16 @@ | |||
2257 | 147 | TEST(QueryTest, testAddAvailableAppsCallsClickIndex) | 167 | TEST(QueryTest, testAddAvailableAppsCallsClickIndex) |
2258 | 148 | { | 168 | { |
2259 | 149 | MockIndex mock_index; | 169 | MockIndex mock_index; |
2260 | 170 | click::DepartmentLookup dept_lookup; | ||
2261 | 171 | click::HighlightList highlights; | ||
2262 | 150 | scopes::SearchMetadata metadata("en_EN", "phone"); | 172 | scopes::SearchMetadata metadata("en_EN", "phone"); |
2263 | 151 | PackageSet no_installed_packages; | 173 | PackageSet no_installed_packages; |
2264 | 152 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 174 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2268 | 153 | MockQuery q(query, mock_index, metadata); | 175 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2269 | 154 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)).Times(1); | 176 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)).Times(1); |
2270 | 155 | scopes::SearchReplyProxy reply; | 177 | |
2271 | 178 | scopes::testing::MockSearchReply mock_reply; | ||
2272 | 179 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
2273 | 156 | 180 | ||
2274 | 157 | scopes::CategoryRenderer renderer("{}"); | 181 | scopes::CategoryRenderer renderer("{}"); |
2275 | 158 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 182 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
2276 | @@ -166,17 +190,21 @@ | |||
2277 | 166 | {"name", "title", 0.0, "icon", "uri"} | 190 | {"name", "title", 0.0, "icon", "uri"} |
2278 | 167 | }; | 191 | }; |
2279 | 168 | MockIndex mock_index(packages); | 192 | MockIndex mock_index(packages); |
2280 | 193 | click::DepartmentLookup dept_lookup; | ||
2281 | 194 | click::HighlightList highlights; | ||
2282 | 169 | scopes::SearchMetadata metadata("en_EN", "phone"); | 195 | scopes::SearchMetadata metadata("en_EN", "phone"); |
2283 | 170 | PackageSet no_installed_packages; | 196 | PackageSet no_installed_packages; |
2284 | 171 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 197 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2287 | 172 | MockQuery q(query, mock_index, metadata); | 198 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2288 | 173 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 199 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
2289 | 174 | 200 | ||
2290 | 175 | scopes::CategoryRenderer renderer("{}"); | 201 | scopes::CategoryRenderer renderer("{}"); |
2291 | 176 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 202 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
2292 | 177 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); | 203 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); |
2293 | 178 | 204 | ||
2295 | 179 | scopes::SearchReplyProxy reply; | 205 | scopes::testing::MockSearchReply mock_reply; |
2296 | 206 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
2297 | 207 | |||
2298 | 180 | auto expected_title = packages.front().title; | 208 | auto expected_title = packages.front().title; |
2299 | 181 | EXPECT_CALL(q, push_result(_, Property(&scopes::CategorisedResult::title, expected_title))); | 209 | EXPECT_CALL(q, push_result(_, Property(&scopes::CategorisedResult::title, expected_title))); |
2300 | 182 | q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE); | 210 | q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE); |
2301 | @@ -188,17 +216,20 @@ | |||
2302 | 188 | {"name", "title", 0.0, "icon", "uri"} | 216 | {"name", "title", 0.0, "icon", "uri"} |
2303 | 189 | }; | 217 | }; |
2304 | 190 | MockIndex mock_index(packages); | 218 | MockIndex mock_index(packages); |
2305 | 219 | click::DepartmentLookup dept_lookup; | ||
2306 | 220 | click::HighlightList highlights; | ||
2307 | 191 | scopes::SearchMetadata metadata("en_EN", "phone"); | 221 | scopes::SearchMetadata metadata("en_EN", "phone"); |
2308 | 192 | PackageSet no_installed_packages; | 222 | PackageSet no_installed_packages; |
2309 | 193 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 223 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2312 | 194 | MockQuery q(query, mock_index, metadata); | 224 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2313 | 195 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 225 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
2314 | 196 | 226 | ||
2315 | 197 | scopes::CategoryRenderer renderer("{}"); | 227 | scopes::CategoryRenderer renderer("{}"); |
2316 | 198 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 228 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
2317 | 199 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); | 229 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); |
2318 | 200 | 230 | ||
2320 | 201 | scopes::SearchReplyProxy reply; | 231 | scopes::testing::MockSearchReply mock_reply; |
2321 | 232 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
2322 | 202 | EXPECT_CALL(q, finished(_)); | 233 | EXPECT_CALL(q, finished(_)); |
2323 | 203 | q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE); | 234 | q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE); |
2324 | 204 | } | 235 | } |
2325 | @@ -209,10 +240,12 @@ | |||
2326 | 209 | {"name", "title", 0.0, "icon", "uri"} | 240 | {"name", "title", 0.0, "icon", "uri"} |
2327 | 210 | }; | 241 | }; |
2328 | 211 | MockIndex mock_index(packages); | 242 | MockIndex mock_index(packages); |
2329 | 243 | click::DepartmentLookup dept_lookup; | ||
2330 | 244 | click::HighlightList highlights; | ||
2331 | 212 | scopes::SearchMetadata metadata("en_EN", "phone"); | 245 | scopes::SearchMetadata metadata("en_EN", "phone"); |
2332 | 213 | PackageSet no_installed_packages; | 246 | PackageSet no_installed_packages; |
2333 | 214 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 247 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2335 | 215 | MockQueryRun q(query, mock_index, metadata); | 248 | MockQueryRun q(query, mock_index, dept_lookup, highlights, metadata); |
2336 | 216 | auto reply = scopes::SearchReplyProxy(); | 249 | auto reply = scopes::SearchReplyProxy(); |
2337 | 217 | EXPECT_CALL(q, get_installed_packages()).WillOnce(Return(no_installed_packages)); | 250 | EXPECT_CALL(q, get_installed_packages()).WillOnce(Return(no_installed_packages)); |
2338 | 218 | EXPECT_CALL(q, add_available_apps(reply, no_installed_packages, _)); | 251 | EXPECT_CALL(q, add_available_apps(reply, no_installed_packages, _)); |
2339 | @@ -234,15 +267,18 @@ | |||
2340 | 234 | PackageSet one_installed_package { | 267 | PackageSet one_installed_package { |
2341 | 235 | {"org.example.app2", "0.2"} | 268 | {"org.example.app2", "0.2"} |
2342 | 236 | }; | 269 | }; |
2343 | 270 | click::DepartmentLookup dept_lookup; | ||
2344 | 271 | click::HighlightList highlights; | ||
2345 | 237 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 272 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2348 | 238 | MockQuery q(query, mock_index, metadata); | 273 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2349 | 239 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 274 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
2350 | 240 | 275 | ||
2351 | 241 | scopes::CategoryRenderer renderer("{}"); | 276 | scopes::CategoryRenderer renderer("{}"); |
2352 | 242 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 277 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
2353 | 243 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); | 278 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); |
2354 | 244 | 279 | ||
2356 | 245 | scopes::SearchReplyProxy reply; | 280 | scopes::testing::MockSearchReply mock_reply; |
2357 | 281 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
2358 | 246 | auto expected_name1 = packages.front().name; | 282 | auto expected_name1 = packages.front().name; |
2359 | 247 | EXPECT_CALL(q, push_result(_, HasPackageName(expected_name1))); | 283 | EXPECT_CALL(q, push_result(_, HasPackageName(expected_name1))); |
2360 | 248 | auto expected_name2 = packages.back().name; | 284 | auto expected_name2 = packages.back().name; |
2361 | @@ -261,15 +297,18 @@ | |||
2362 | 261 | PackageSet one_installed_package { | 297 | PackageSet one_installed_package { |
2363 | 262 | {"org.example.app2", "0.2"} | 298 | {"org.example.app2", "0.2"} |
2364 | 263 | }; | 299 | }; |
2365 | 300 | click::DepartmentLookup dept_lookup; | ||
2366 | 301 | click::HighlightList highlights; | ||
2367 | 264 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 302 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2370 | 265 | MockQuery q(query, mock_index, metadata); | 303 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2371 | 266 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)); | 304 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
2372 | 267 | 305 | ||
2373 | 268 | scopes::CategoryRenderer renderer("{}"); | 306 | scopes::CategoryRenderer renderer("{}"); |
2374 | 269 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); | 307 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
2375 | 270 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); | 308 | EXPECT_CALL(q, register_category(_, _, _, _, _)).WillOnce(Return(ptrCat)); |
2376 | 271 | 309 | ||
2378 | 272 | scopes::SearchReplyProxy reply; | 310 | scopes::testing::MockSearchReply mock_reply; |
2379 | 311 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); | ||
2380 | 273 | EXPECT_CALL(q, push_result(_, IsInstalled(true))); | 312 | EXPECT_CALL(q, push_result(_, IsInstalled(true))); |
2381 | 274 | EXPECT_CALL(q, push_result(_, IsInstalled(false))); | 313 | EXPECT_CALL(q, push_result(_, IsInstalled(false))); |
2382 | 275 | q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE); | 314 | q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE); |
2383 | @@ -288,8 +327,10 @@ | |||
2384 | 288 | }; | 327 | }; |
2385 | 289 | MockIndex mock_index(uninstalled_packages); | 328 | MockIndex mock_index(uninstalled_packages); |
2386 | 290 | scopes::SearchMetadata metadata("en_EN", "phone"); | 329 | scopes::SearchMetadata metadata("en_EN", "phone"); |
2387 | 330 | click::DepartmentLookup dept_lookup; | ||
2388 | 331 | click::HighlightList highlights; | ||
2389 | 291 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); | 332 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
2391 | 292 | MockQuery q(query, mock_index, metadata); | 333 | MockQuery q(query, mock_index, dept_lookup, highlights, metadata); |
2392 | 293 | PackageSet installed_packages{{"package_1", "0.1"}}; | 334 | PackageSet installed_packages{{"package_1", "0.1"}}; |
2393 | 294 | 335 | ||
2394 | 295 | FakeInterface fake_interface; | 336 | FakeInterface fake_interface; |
426 +std::map< std::string, std::string> Index:: build_headers( const std::string& language) click:: web::Response> response( client- >call( BOOTSTRAP_ PATH, "GET", false, build_headers( "en"), "", params)); //TODO: language
438 + {"Accept-Language", language},
486 + QSharedPointer<
487 + get_base_url() + click::
You don't need to do all this work to pass the language around or set Accept-Language manually. It is already added automatically in web::Client::cal().