Merge lp:~gary-wzl77/scope-aggregator/4.8-opt into lp:scope-aggregator
- 4.8-opt
- Merge into vivid-trunk
Status: | Merged |
---|---|
Approved by: | Kyle Nitzsche |
Approved revision: | 174 |
Merged at revision: | 165 |
Proposed branch: | lp:~gary-wzl77/scope-aggregator/4.8-opt |
Merge into: | lp:scope-aggregator |
Prerequisite: | lp:~knitzsche/scope-aggregator/4.8-local-hints |
Diff against target: |
3146 lines (+869/-930) 9 files modified
include/aggchildscope.h (+38/-44) include/query.h (+91/-85) include/scope.h (+19/-7) src/CMakeLists.txt (+3/-0) src/action.cpp (+2/-4) src/aggchildscope.cpp (+46/-46) src/query.cpp (+158/-96) src/scope.cpp (+106/-93) src/utils.cpp (+406/-555) |
To merge this branch: | bzr merge lp:~gary-wzl77/scope-aggregator/4.8-opt |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kyle Nitzsche (community) | Approve | ||
Zhang Enwei (community) | Approve | ||
Jin | Pending | ||
Penk Chen | Pending | ||
Review via email: mp+298494@code.launchpad.net |
Commit message
1.compile time optimization for string(
2.load json file in one function(
3.specify 'const' keyword for some variable in some cases.
4.pass by reference instead of by value if possible.
5.don't allocated memory(make_shared) based on local variable to avoid copy constructor.
6 remove duplicated obj creation.
7.fix invalid pointer for us::Category::SCPtr when look_up is called.
8.remove redundant files.
Description of the change
Considering this MP
https:/
The major change was made by Kyle against scope aggregator , I think it's good timing to fix another problems we have in our previous version(including the above MP). So that we have some performance optimization as well in 4.8 other than local-hints feature.
I've tested bollywood/boosk aggregator scope, both work well.
Could you please review this MP and test other aggregator scopes against this MP?
Thanks.
Kyle Nitzsche (knitzsche) wrote : | # |
Kyle Nitzsche (knitzsche) wrote : | # |
Please note that my no-hints branch incorrectly add images/icon/. I deleted that dir before I merged to trunk.
Kyle Nitzsche (knitzsche) wrote : | # |
Thanks for the optimizations!
Please note my inline comments below and handle them as you think best before merging to trunk and bzr tagging to 4.8, including:
* your make-pot.sh is behind trunk
I tested and all worked well this against:
* https:/
* https:/
* https:/
* https:/
Zhang Enwei (zhangew401) wrote : | # |
works well on china-dashboard
Gary.Wang (gary-wzl77) wrote : | # |
Thanks for you tips, Kyle. Please see my inline comments.
Thanks enwei for your verification.
Gary.Wang (gary-wzl77) wrote : | # |
@Kyle,I apologize for this big commits, Enwei and I tested 3 aggregator scope(bollywood, books, china-dash). All works fine.
if you can have a quick test for the following branch against latest commits. That would be great.
* https:/
* https:/
* https:/
* https:/
I will merge into trunk after you review the latest commit.
Thanks.
Kyle Nitzsche (knitzsche) wrote : | # |
Hi Gary,
I tested against the four branches and it looks good to me.
Not sure why you moved the load_hints_config() method from utils.cpp to query.cpp, but it does not matter :)
I see you added the methods to get AggScope props like scope_id - cool.
And awesome that you followed the advice to only load the various json files once!
Cheers
Preview Diff
1 | === modified file 'include/aggchildscope.h' |
2 | --- include/aggchildscope.h 2015-07-14 09:12:40 +0000 |
3 | +++ include/aggchildscope.h 2016-06-29 10:31:52 +0000 |
4 | @@ -44,17 +44,16 @@ |
5 | \param id the fully qualified scope id (for example: com.canonical.scopes.photos-local_photos_local) |
6 | |
7 | */ |
8 | - AggChildScope(const std::string id); |
9 | - |
10 | - void set_local_id(const std::string local_id); |
11 | - |
12 | - std::string local_id(); |
13 | + AggChildScope(std::string const & id); |
14 | + |
15 | + void set_local_id(std::string const & local_id); |
16 | + const std::string & local_id() const; |
17 | |
18 | /** |
19 | \brief Set our poinnter to the scope's ScopeMetadata |
20 | \param ScopeMetadata |
21 | */ |
22 | - void set_metadata(us::ScopeMetadata const &); |
23 | + void set_metadata(us::ScopeMetadata const & metadata); |
24 | |
25 | /** |
26 | \brief Return a pointer to the scope's ScopeMetadata |
27 | @@ -66,13 +65,13 @@ |
28 | \brief Set the displayed category title. Not defined when using_category_title_incoming. |
29 | \param title_ The title |
30 | */ |
31 | - void set_category_title(const std::string title_); |
32 | + void set_category_title(std::string const & title); |
33 | |
34 | /** |
35 | \brief Return the Category title. Not defined when using_category_title_incoming. |
36 | \return title |
37 | */ |
38 | - std::string category_title(); |
39 | + const std::string & category_title() const; |
40 | |
41 | /** |
42 | \brief The displayed category title |
43 | @@ -149,29 +148,29 @@ |
44 | /** |
45 | \brief The json defining the CategoryRenderer json used when surfacing the first result. You must also declare surface_template to handle the rest. |
46 | */ |
47 | - void set_first_result_template(const std::string first_result_template); |
48 | + void set_first_result_template(std::string const &first_result_template); |
49 | |
50 | /** |
51 | \brief Return the json defining the CategoryRenderer template used when surfacing first result. |
52 | */ |
53 | - std::string first_result_template(); |
54 | + const std::string & first_result_template() const; |
55 | /** |
56 | * |
57 | \brief The json defining the CategoryRenderer template used when surfacing results. |
58 | \param surface_template The json passed to the CategoryRenderer |
59 | */ |
60 | - void set_surface_template(const std::string surface_template); |
61 | + void set_surface_template(std::string const &surface_template); |
62 | |
63 | /** |
64 | \brief Return the json defining the CategoryRenderer template used when surfacing results. |
65 | */ |
66 | - std::string surface_template(); |
67 | - |
68 | - void set_first_common_template_id(std::string id); |
69 | - std::string first_common_template_id(); |
70 | - |
71 | - void set_surface_common_template_id(std::string id); |
72 | - std::string surface_common_template_id(); |
73 | + const std::string & surface_template() const; |
74 | + |
75 | + void set_first_common_template_id(std::string const &id); |
76 | + const std::string & first_common_template_id() const; |
77 | + |
78 | + void set_surface_common_template_id(std::string const &id); |
79 | + const std::string & surface_common_template_id() const; |
80 | |
81 | /** |
82 | \brief Sets whether this scope overrides the category render via json. |
83 | @@ -188,13 +187,13 @@ |
84 | /** |
85 | \brief Return the json defining the CategoryRenderer template used when displaying search results. |
86 | */ |
87 | - std::string search_template(); |
88 | + const std::string & search_template() const; |
89 | |
90 | /** |
91 | \brief The json defining the CategoryRenderer template used when displaying search results. |
92 | \param search_template The json passed to the CategoryRenderer |
93 | */ |
94 | - void set_search_template(const std::string search_template); |
95 | + void set_search_template(std::string const &search_template); |
96 | |
97 | /** |
98 | \brief Sets whether this scope overrides the category render via json in search mode. |
99 | @@ -212,37 +211,37 @@ |
100 | \brief Display child scope results only from the specific department |
101 | \param department_id The ID of the child scope department. |
102 | */ |
103 | - void set_child_department(const std::string department_id_); |
104 | + void set_child_department(std::string const &department_id_); |
105 | |
106 | /** |
107 | \brief Return child department id |
108 | \return Return child department id |
109 | */ |
110 | - std::string child_department(); |
111 | + const std::string & child_department() const; |
112 | |
113 | /** |
114 | \brief Places this scope in the department whose id is passed. |
115 | \param department_id The ID of the department. |
116 | */ |
117 | - void set_department(const std::string department_id_); |
118 | + void set_department(std::string const &department_id_); |
119 | |
120 | /** |
121 | \brief Return scope's department id |
122 | \return Return scope's department id |
123 | */ |
124 | - std::string department(); |
125 | + const std::string & department() const; |
126 | |
127 | /** |
128 | \brief Display child scope results only from the specified category |
129 | \parm category_id The ID of the cagtegory of the result. |
130 | */ |
131 | - void set_child_category(const std::string category_id); |
132 | + void set_child_category(std::string const &category_id); |
133 | |
134 | /** |
135 | \brief Return the category_id. Undefined it not using set_child_category() |
136 | \return The child_category |
137 | */ |
138 | - std::string child_category(); |
139 | + const std::string & child_category() const; |
140 | /** |
141 | \brief Limit child scope results to this number. |
142 | Note: Only use this when also using set_child_category(), otherwise use set_cardinality() |
143 | @@ -279,7 +278,7 @@ |
144 | \brief Return scope ID |
145 | \return The scope ID. |
146 | */ |
147 | - std::string id(); |
148 | + const std::string & id() const; |
149 | |
150 | /** |
151 | \brief Determines whether category has link to the child scope |
152 | @@ -312,7 +311,7 @@ |
153 | \brief Find out whether the scope is enabled in settings |
154 | \return True when scope is enabled. |
155 | */ |
156 | - bool enabled(const us::VariantMap settings); |
157 | + bool enabled(us::VariantMap const &settings); |
158 | |
159 | /** |
160 | \brief Return this scope by ScopeProxy |
161 | @@ -323,7 +322,7 @@ |
162 | \brief This is called automatically. You generally do not need to call this. If the scope is in the registry, its proxy is saved and its |
163 | \param A RegistryProxy |
164 | */ |
165 | - void set_proxy(us::RegistryProxy const); |
166 | + void set_proxy(us::RegistryProxy const &proxy); |
167 | |
168 | /** |
169 | \brief This is called automatically and you generally do not need to call this. Increments the results_idx; |
170 | @@ -340,24 +339,19 @@ |
171 | bool buffer(); |
172 | |
173 | void set_category_scope(bool); |
174 | - |
175 | bool category_scope(); |
176 | |
177 | - void set_category_id(std::string); |
178 | - |
179 | - std::string category_id(); |
180 | + void set_category_id(std::string const &category_id); |
181 | + const std::string & category_id() const; |
182 | |
183 | void set_keyword_scope(bool); |
184 | - |
185 | bool keyword_scope(); |
186 | |
187 | - void set_keyword(std::string); |
188 | - |
189 | - std::string keyword(); |
190 | - |
191 | - void set_keyword_scope_shared_cat_name(std::string); |
192 | - |
193 | - std::string keyword_scope_shared_cat_name(); |
194 | + void set_keyword(std::string const &keyword); |
195 | + const std::string & keyword() const; |
196 | + |
197 | + void set_keyword_scope_shared_cat_name(std::string const &shared_cat_name); |
198 | + const std::string & keyword_scope_shared_cat_name() const; |
199 | |
200 | bool keyword_uses_shared_cat(); |
201 | |
202 | @@ -403,11 +397,11 @@ |
203 | bool override_surface_template_ = true; |
204 | bool override_search_template_ = true; |
205 | std::string TEMPLATE_NOT_LOGGED_IN; |
206 | - std::string TEMPLATE_FIRST_RESULT; |
207 | + std::string template_first_result_; |
208 | std::string first_common_template_id_; |
209 | - std::string TEMPLATE_SURFACE; |
210 | + std::string template_surface_; |
211 | std::string surface_common_template_id_; |
212 | - std::string TEMPLATE_SEARCH; |
213 | + std::string template_search_; |
214 | bool source_finder_; |
215 | }; |
216 | |
217 | |
218 | === modified file 'include/query.h' |
219 | --- include/query.h 2016-06-23 20:49:09 +0000 |
220 | +++ include/query.h 2016-06-29 10:31:52 +0000 |
221 | @@ -34,16 +34,75 @@ |
222 | |
223 | #include <QJsonObject> |
224 | |
225 | +struct category { |
226 | + std::string id; |
227 | + std::string title; |
228 | + std::string dept_id; |
229 | + int cardinality = -1; |
230 | + bool use_incoming_title = false; |
231 | + std::string category_link_to_child_specified; |
232 | + std::string renderer; |
233 | + std::string search_renderer; |
234 | + std::vector<std::pair<std::string,std::string>> scopes; // id and local_id of scopes |
235 | + std::vector<std::string> keywords; // keywords in this cat |
236 | + std::vector<std::pair<std::string,std::string>> keyword_ids; // id and local id of keywords |
237 | +}; |
238 | + |
239 | +struct dept { |
240 | + std::string id;//actual scope id |
241 | + std::string local_id;//locally unique id to allow same scope multiple times |
242 | + std::string title; |
243 | + std::string keyword;// optional. stores msgid to look up title |
244 | + bool root = false; |
245 | +}; |
246 | + |
247 | +struct keyword { |
248 | + std::string id; // the keyword string |
249 | + int cardinality = -1; |
250 | + std::string dept_id; |
251 | + std::string dept_title_msgid; |
252 | + bool link_to_child = false; |
253 | + std::vector<std::string> exclude_scopes; // id of exclude scopes |
254 | + std::vector<std::string> display_order; // id of display order scopes |
255 | +}; |
256 | + |
257 | +struct child_scope { |
258 | + //these are the json keys for each child scope |
259 | + std::string id;//required in json |
260 | + std::string local_id;//required in json |
261 | + bool link_to_child = true;//when false, category has no link to child |
262 | + bool source_finder = false; //means this scope is to search the store for sources |
263 | + std::string category_title = "";//optional in json required |
264 | + bool using_category_title_incoming = false;//when true, set cat title from first incoming result |
265 | + bool using_category_title_display_name = false;//when true, set cat title from result scope's display name |
266 | + std::string category_title_ = "";//use in json when title i18ned |
267 | + std::string first_result_template = "";//required in json |
268 | + std::string surface_template = "";//required in json |
269 | + std::string search_template = "";//if not present in json, surface_template used for search |
270 | + int cardinality = 6;//optional in json, else use this default |
271 | + std::string child_category = "";//optional in json |
272 | + int child_category_max_results = 6;//optional in json else use this default when child_category used |
273 | + std::string child_department = "";//optional in json |
274 | + std::string department = "";//optional in json |
275 | + bool only_in_search = false;//optional in json |
276 | + //the rest are NOT json keys |
277 | + bool using_child_category_max_results = false;//NOT A JSON KEY |
278 | + bool overriding_surface_template = false;//NOT A JSON KEY |
279 | + bool overriding_search_template = false;//NOT A JSON KEY |
280 | + std::vector<std::shared_ptr<std::pair<std::string,std::string>>> swap_result_attributes; |
281 | + std::pair<std::string,std::string> if_category_use_template; |
282 | + std::map<std::string, std::string> result_category_id_to_common_template;//id is result category id. maps to id to use in common_templates |
283 | +}; |
284 | + |
285 | class Query : public unity::scopes::SearchQueryBase |
286 | { |
287 | public: |
288 | Query(const unity::scopes::CannedQuery &query, |
289 | const unity::scopes::SearchMetadata &metadata, |
290 | - const std::string scope_dir, |
291 | - const std::string cache_dir, |
292 | + std::string const &scope_dir, |
293 | + std::string const &cache_dir, |
294 | unity::scopes::RegistryProxy const& registry, |
295 | - AggScope * agg_scope |
296 | - ); |
297 | + AggScope * agg_scope); |
298 | ~Query(); |
299 | virtual void cancelled() override; |
300 | |
301 | @@ -52,20 +111,30 @@ |
302 | bool using_departments = true; |
303 | |
304 | private: |
305 | - std::string scope_id;//this scope's for use in log messages |
306 | - struct category { |
307 | - std::string id; |
308 | - std::string title; |
309 | - std::string dept_id; |
310 | - int cardinality = -1; |
311 | - bool use_incoming_title = false; |
312 | - std::string category_link_to_child_specified; |
313 | - std::string renderer; |
314 | - std::string search_renderer; |
315 | - std::vector<std::pair<std::string,std::string>> scopes; // id and local_id of scopes |
316 | - std::vector<std::string> keywords; // keywords in this cat |
317 | - std::vector<std::pair<std::string,std::string>> keyword_ids; // id and local id of keywords |
318 | - }; |
319 | + void load_cardinality_setting(QJsonObject const &root); |
320 | + int get_cardinality_setting(); |
321 | + |
322 | + void make_declared_scopes(); |
323 | + void make_keyword_scopes(); |
324 | + void make_categories(); |
325 | + |
326 | + void load_declarations(QJsonObject const &root); |
327 | + void load_hints_config(QJsonObject const &root); |
328 | + void set_scope_order(); |
329 | + |
330 | + void display_local_hints_quickstart(us::SearchReplyProxy const& upstream_reply_); |
331 | + void display_hints_quickstart(us::SearchReplyProxy const& upstream_reply_); |
332 | + bool show_hints(us::SearchReplyProxy const& upstream_reply_); |
333 | + bool hints_exists(); |
334 | + bool hints_hidden(); |
335 | + void dismiss_hints_quickstart(); |
336 | + |
337 | + void check_result_fallbacks(unity::scopes::CategorisedResult &res, std::string const& common_id); |
338 | + void create_departments(us::SearchReplyProxy const &reply_); |
339 | + void handle_current_child_scopes(bool empty_search, us::SearchReplyProxy const& upstream_reply); |
340 | + void handle_child_scope_results(std::string const &query_string, bool empty_search, us::SearchReplyProxy const& upstream_reply); |
341 | + void noSources(unity::scopes::SearchReplyProxy const& reply); |
342 | +private: |
343 | std::map<std::string,std::string> localId_defaultQryStr; |
344 | std::map<std::string,std::string> scopeLocalId_childDept_m; // local_id of scope to scope's child department |
345 | std::vector<std::shared_ptr<category>> categories; |
346 | @@ -82,44 +151,15 @@ |
347 | std::map<std::string,bool> categoryId_isSecondResult; |
348 | std::list<std::string> declared_category_keywords;// the declared list of category keywords, in declared order |
349 | |
350 | - int get_setting_cardinality(); |
351 | std::vector<int> setting_cardinalities; // values defined in qQuery constructor and settings.ini |
352 | std::map<std::string,std::string> common_templates; // common_template id to common_template in json |
353 | std::map<std::string,std::shared_ptr<std::map<std::string,std::vector<std::string>>>> common_templates_fallbacks; // common_template id key to result field key to list of fallback field keys in result |
354 | std::map<std::string,us::Category::SCPtr> registered_common_categories;//id is unique to scope and common category id. |
355 | - void check_result_fallbacks(unity::scopes::CategorisedResult &res, std::string cat_id); |
356 | - struct child_scope { |
357 | - //these are the json keys for each child scope |
358 | - std::string id;//required in json |
359 | - std::string local_id;//required in json |
360 | - bool link_to_child = true;//when false, category has no link to child |
361 | - bool source_finder = false; //means this scope is to search the store for sources |
362 | - std::string category_title = "";//optional in json required |
363 | - bool using_category_title_incoming = false;//when true, set cat title from first incoming result |
364 | - bool using_category_title_display_name = false;//when true, set cat title from result scope's display name |
365 | - std::string category_title_ = "";//use in json when title i18ned |
366 | - std::string first_result_template = "";//required in json |
367 | - std::string surface_template = "";//required in json |
368 | - std::string search_template = "";//if not present in json, surface_template used for search |
369 | - int cardinality = 6;//optional in json, else use this default |
370 | - std::string child_category = "";//optional in json |
371 | - int child_category_max_results = 6;//optional in json else use this default when child_category used |
372 | - std::string child_department = "";//optional in json |
373 | - std::string department = "";//optional in json |
374 | - bool only_in_search = false;//optional in json |
375 | - //the rest are NOT json keys |
376 | - bool using_child_category_max_results = false;//NOT A JSON KEY |
377 | - bool overriding_surface_template = false;//NOT A JSON KEY |
378 | - bool overriding_search_template = false;//NOT A JSON KEY |
379 | - std::vector<std::shared_ptr<std::pair<std::string,std::string>>> swap_result_attributes; |
380 | - std::pair<std::string,std::string> if_category_use_template; |
381 | - std::map<std::string, std::string> result_category_id_to_common_template;//id is result category id. maps to id to use in common_templates |
382 | - }; |
383 | + |
384 | std::vector<std::shared_ptr<child_scope>> child_scopes;// pulled from child_sccopes.json |
385 | std::map<std::string,std::shared_ptr<child_scope>> child_scopes_m;//id to child_scope |
386 | std::vector<std::string> current_scopes;// scope local_id |
387 | std::vector<std::string> current_scopeIds;// keyword cate scope ids to prevent dups |
388 | - void set_scope_order(); |
389 | std::vector<std::string> declared_order;// scope local_id or keyword |
390 | std::vector<std::string> scopes_ordered;// scope local id or keyword |
391 | /* |
392 | @@ -136,39 +176,18 @@ |
393 | */ |
394 | std::map<std::string,std::vector<std::string>> type_ids_m;// |
395 | |
396 | - |
397 | - struct dept { |
398 | - std::string id;//actual scope id |
399 | - std::string local_id;//locally unique id to allow same scope multiple times |
400 | - std::string title; |
401 | - std::string keyword;// optional. stores msgid to look up title |
402 | - bool root = false; |
403 | - }; |
404 | std::map<std::string,std::string> localId_id_m;//use scope's local_id to get its fully qualified id |
405 | std::string dept_id_of_root; |
406 | std::string dept_id_of_root_keywords_only; |
407 | |
408 | std::map<std::string,std::shared_ptr<dept>> depts; // dept id to dept ptr |
409 | - struct keyword { |
410 | - std::string id; // the keyword string |
411 | - int cardinality = -1; |
412 | - std::string dept_id; |
413 | - std::string dept_title_msgid; |
414 | - bool link_to_child = false; |
415 | - std::vector<std::string> exclude_scopes; // id of exclude scopes |
416 | - std::vector<std::string> display_order; // id of display order scopes |
417 | - }; |
418 | + |
419 | std::vector<std::shared_ptr<keyword>> keywords;// pulled from child_sccopes.json |
420 | std::map<std::string, std::shared_ptr<keyword>> id_keyword_map;//keyword id (the keyword string) to keyword instance |
421 | std::map<std::string,std::string> keyword_deptTitleMsgid; // keyword to msgid used to look up its title |
422 | std::map<std::string,std::string> keyword_deptId; |
423 | std::map<std::string,std::string> keyword_surfaceRdr; |
424 | |
425 | - void getDeclaredChildScopes(); |
426 | - void make_declared_scopes(); |
427 | - void make_keyword_scopes(); |
428 | - void make_categories(); |
429 | - void load_declarations(); |
430 | us::ChildScopeList current_child_scopes; |
431 | |
432 | std::string first_result_owner; // set to first declaared keyword or scope that declared a first result renderer |
433 | @@ -184,11 +203,9 @@ |
434 | std::map<std::string,us::Category::SCPtr> catname_catptr;//store pointer to shared category |
435 | std::map<std::string,us::Category::SCPtr> catname_keyword_catptr;//store pointer to keyword not shared |
436 | std::map<std::string,bool> sharedcat_catregistered;//stores whether the shared cat's ctegory is registered yet |
437 | - void create_departments(us::SearchReplyProxy const &reply_); |
438 | - void handle_current_child_scopes(bool empty_search, us::SearchReplyProxy const& upstream_reply); |
439 | - void handle_child_scope_results(std::string query_string, bool empty_search, us::SearchReplyProxy const& upstream_reply); |
440 | + |
441 | std::vector<us::ScopeProxy> scopes; // will hold all enabled and present child scopes |
442 | - std::map<std::string,std::shared_ptr<AggChildScope>> scopes_m;//key is local_id |
443 | + std::map<std::string, std::shared_ptr<AggChildScope>> scopes_m;//key is local_id |
444 | std::map<int,std::string> scopes_m_int_localId; |
445 | std::string scope_dir_; |
446 | std::string cache_dir_; |
447 | @@ -196,8 +213,6 @@ |
448 | unity::scopes::RegistryProxy registry_; |
449 | AggScope *agg_scope_; |
450 | |
451 | - void noSources(unity::scopes::SearchReplyProxy const& reply); |
452 | - |
453 | bool local_hints = false; |
454 | bool no_network_msg = false; |
455 | bool no_location_msg = false; |
456 | @@ -206,16 +221,8 @@ |
457 | bool hints_quickstart = false; |
458 | QString hints_file = "hints_is_hidden"; |
459 | QString firstboot = "firstboot"; |
460 | - QJsonObject root; |
461 | QJsonObject hints_local_json; |
462 | |
463 | - void load_hints_config(); |
464 | - bool hints_exists(); |
465 | - void display_local_hints_quickstart(us::SearchReplyProxy const& upstream_reply_); |
466 | - void display_hints_quickstart(us::SearchReplyProxy const& upstream_reply_); |
467 | - bool show_hints(us::SearchReplyProxy const& upstream_reply_); |
468 | - bool hints_hidden(); |
469 | - void dismiss_hints_quickstart(); |
470 | std::string HINTS_SCOPE_ID;//fqn of hints scope |
471 | std::string HINTS_THIS_SCOPE;//tells hints which agg scope this is |
472 | std::string HINTS_HIDE;//tells hints to stop displaying |
473 | @@ -223,7 +230,6 @@ |
474 | bool has_one_source=false;//true means scope is installed |
475 | int keyword_cardinality = 5; |
476 | |
477 | - void load_cardinality_settings(); |
478 | }; |
479 | |
480 | #endif |
481 | |
482 | === modified file 'include/scope.h' |
483 | --- include/scope.h 2016-06-11 23:54:53 +0000 |
484 | +++ include/scope.h 2016-06-29 10:31:52 +0000 |
485 | @@ -26,9 +26,13 @@ |
486 | #include <unity/scopes/QueryBase.h> |
487 | #include <unity/scopes/PreviewQueryBase.h> |
488 | |
489 | +#include <QJsonObject> |
490 | + |
491 | class AggScope : public unity::scopes::ScopeBase |
492 | { |
493 | public: |
494 | + enum class IdType {id, local_id}; |
495 | + |
496 | AggScope(); |
497 | |
498 | virtual void start(std::string const& scope_name) override; |
499 | @@ -41,17 +45,25 @@ |
500 | virtual unity::scopes::SearchQueryBase::UPtr search(unity::scopes::CannedQuery const& q, |
501 | unity::scopes::SearchMetadata const&) override; |
502 | |
503 | - unity::scopes::ActivationQueryBase::UPtr |
504 | - activate(unity::scopes::Result const& result, |
505 | - unity::scopes::ActionMetadata const& metadata)override; |
506 | + unity::scopes::ActivationQueryBase::UPtr activate(unity::scopes::Result const& result, |
507 | + unity::scopes::ActionMetadata const& metadata)override; |
508 | |
509 | unity::scopes::ChildScopeList find_child_scopes() const override; |
510 | |
511 | - enum class IdType {id, local_id}; |
512 | - |
513 | std::vector<std::string> get_declared_scopes(IdType) const; |
514 | std::vector<std::string> get_declared_keywords() const; |
515 | - std::string scope_id; |
516 | - |
517 | + |
518 | + const std::string & scope_id() const; |
519 | + const std::string & lang() const; |
520 | + const std::string & country() const; |
521 | + const QJsonObject & child_root() const; |
522 | + const QJsonObject & hints_root() const; |
523 | + |
524 | +private: |
525 | + std::string scope_id_; |
526 | + std::string lang_; |
527 | + std::string country_; |
528 | + QJsonObject child_root_; |
529 | + QJsonObject hints_root_; |
530 | }; |
531 | #endif |
532 | |
533 | === modified file 'src/CMakeLists.txt' |
534 | --- src/CMakeLists.txt 2016-06-11 23:54:53 +0000 |
535 | +++ src/CMakeLists.txt 2016-06-29 10:31:52 +0000 |
536 | @@ -17,6 +17,9 @@ |
537 | set_property(TARGET ${SO_NAME} PROPERTY COMPILE_FLAGS ${UNITY_SCOPES_CFLAGS}) |
538 | qt5_use_modules(${SO_NAME} Network) |
539 | |
540 | +add_definitions(-DCHILD_JSON_FILE="child_scopes.json") |
541 | +add_definitions(-DHINTS_JSON_FILE="hints.json") |
542 | + |
543 | install( |
544 | TARGETS ${SO_NAME} |
545 | LIBRARY DESTINATION "${SCOPE_INSTALLDIR}" |
546 | |
547 | === modified file 'src/action.cpp' |
548 | --- src/action.cpp 2016-06-16 06:48:02 +0000 |
549 | +++ src/action.cpp 2016-06-29 10:31:52 +0000 |
550 | @@ -28,8 +28,7 @@ |
551 | |
552 | namespace usc = unity::scopes; |
553 | |
554 | -Action:: |
555 | -Action(usc::Result const& result, |
556 | +Action::Action(usc::Result const& result, |
557 | usc::ActionMetadata const& metadata, |
558 | std::string const& cache_dir, |
559 | std::string const& scope_id) |
560 | @@ -39,8 +38,7 @@ |
561 | { |
562 | } |
563 | |
564 | -usc::ActivationResponse |
565 | -Action::activate() |
566 | +usc::ActivationResponse Action::activate() |
567 | { |
568 | if (result()["action"].get_string() == "hide_hints") |
569 | { |
570 | |
571 | === modified file 'src/aggchildscope.cpp' |
572 | --- src/aggchildscope.cpp 2016-06-23 19:37:49 +0000 |
573 | +++ src/aggchildscope.cpp 2016-06-29 10:31:52 +0000 |
574 | @@ -21,27 +21,27 @@ |
575 | |
576 | namespace us = unity::scopes; |
577 | |
578 | -AggChildScope::AggChildScope(const std::string id) : |
579 | +AggChildScope::AggChildScope(std::string const &id) : |
580 | id_(id) |
581 | { |
582 | } |
583 | |
584 | -void AggChildScope::set_local_id(const std::string local_id) |
585 | +void AggChildScope::set_local_id(std::string const &local_id) |
586 | { |
587 | local_id_ = local_id; |
588 | } |
589 | |
590 | -std::string AggChildScope::local_id() |
591 | +const std::string & AggChildScope::local_id() const |
592 | { |
593 | return local_id_; |
594 | } |
595 | |
596 | -void AggChildScope::set_category_title(const std::string title_) |
597 | +void AggChildScope::set_category_title(std::string const &title_) |
598 | { |
599 | cat_title = title_; |
600 | } |
601 | |
602 | -std::string AggChildScope::category_title() |
603 | +const std::string & AggChildScope::category_title() const |
604 | { |
605 | return cat_title; |
606 | } |
607 | @@ -77,24 +77,24 @@ |
608 | return cat; |
609 | } |
610 | |
611 | -void AggChildScope::set_first_result_template(const std::string first_result_template) |
612 | -{ |
613 | - TEMPLATE_FIRST_RESULT = first_result_template; |
614 | -} |
615 | - |
616 | -std::string AggChildScope::first_result_template() |
617 | -{ |
618 | - return TEMPLATE_FIRST_RESULT; |
619 | -} |
620 | - |
621 | -void AggChildScope::set_surface_template(const std::string surface_template) |
622 | -{ |
623 | - TEMPLATE_SURFACE = surface_template; |
624 | -} |
625 | - |
626 | -std::string AggChildScope::surface_template() |
627 | -{ |
628 | - return TEMPLATE_SURFACE; |
629 | +void AggChildScope::set_first_result_template(std::string const &first_result_template) |
630 | +{ |
631 | + template_first_result_ = first_result_template; |
632 | +} |
633 | + |
634 | +const std::string & AggChildScope::first_result_template() const |
635 | +{ |
636 | + return template_first_result_; |
637 | +} |
638 | + |
639 | +void AggChildScope::set_surface_template(std::string const &surface_template) |
640 | +{ |
641 | + template_surface_ = surface_template; |
642 | +} |
643 | + |
644 | +const std::string & AggChildScope::surface_template() const |
645 | +{ |
646 | + return template_surface_; |
647 | } |
648 | |
649 | void AggChildScope::set_override_surface_template(bool b) |
650 | @@ -107,14 +107,14 @@ |
651 | return override_surface_template_; |
652 | } |
653 | |
654 | -std::string AggChildScope::search_template() |
655 | +const std::string & AggChildScope::search_template() const |
656 | { |
657 | - return TEMPLATE_SEARCH; |
658 | + return template_search_; |
659 | } |
660 | |
661 | -void AggChildScope::set_search_template(const std::string search_template) |
662 | +void AggChildScope::set_search_template(std::string const &search_template) |
663 | { |
664 | - TEMPLATE_SEARCH = search_template; |
665 | + template_search_ = search_template; |
666 | } |
667 | |
668 | void AggChildScope::set_override_search_template(bool b) |
669 | @@ -127,33 +127,33 @@ |
670 | return override_search_template_; |
671 | } |
672 | |
673 | -void AggChildScope::set_child_department(const std::string id_) |
674 | +void AggChildScope::set_child_department(std::string const &id_) |
675 | { |
676 | subsearch_dept_id = id_; |
677 | } |
678 | |
679 | -std::string AggChildScope::child_department() |
680 | +const std::string & AggChildScope::child_department() const |
681 | { |
682 | return subsearch_dept_id; |
683 | } |
684 | |
685 | -void AggChildScope::set_department(const std::string id_) |
686 | +void AggChildScope::set_department(std::string const &id_) |
687 | { |
688 | dept_id = id_; |
689 | } |
690 | |
691 | -std::string AggChildScope::department() |
692 | +const std::string & AggChildScope::department() const |
693 | { |
694 | return dept_id; |
695 | } |
696 | |
697 | -void AggChildScope::set_child_category(const std::string category_id) |
698 | +void AggChildScope::set_child_category(std::string const &category_id) |
699 | { |
700 | category_id_ = category_id; |
701 | using_category = true; |
702 | } |
703 | |
704 | -std::string AggChildScope::child_category() |
705 | +const std::string & AggChildScope::child_category() const |
706 | { |
707 | return category_id_; |
708 | } |
709 | @@ -184,7 +184,7 @@ |
710 | return cardinality_; |
711 | } |
712 | |
713 | -std::string AggChildScope::id() |
714 | +const std::string & AggChildScope::id() const |
715 | { |
716 | return id_; |
717 | } |
718 | @@ -199,7 +199,7 @@ |
719 | return using_category_link_to_child; |
720 | } |
721 | |
722 | -void AggChildScope::set_proxy(us::RegistryProxy registry) |
723 | +void AggChildScope::set_proxy(us::RegistryProxy const ®istry) |
724 | { |
725 | |
726 | auto scopes = registry->list(); |
727 | @@ -222,7 +222,7 @@ |
728 | return scope_metadata_; |
729 | } |
730 | |
731 | -bool AggChildScope::enabled(const us::VariantMap settings) |
732 | +bool AggChildScope::enabled(us::VariantMap const & settings) |
733 | { |
734 | if (! settings.at(id()).get_bool()) |
735 | { |
736 | @@ -266,12 +266,12 @@ |
737 | return category_scope_; |
738 | } |
739 | |
740 | -void AggChildScope::set_category_id(std::string id) |
741 | +void AggChildScope::set_category_id(std::string const &id) |
742 | { |
743 | category_scope_id_ = id; |
744 | } |
745 | |
746 | -std::string AggChildScope::category_id() |
747 | +const std::string & AggChildScope::category_id() const |
748 | { |
749 | return category_scope_id_; |
750 | } |
751 | @@ -286,23 +286,23 @@ |
752 | return keyword_scope_; |
753 | } |
754 | |
755 | -void AggChildScope::set_keyword(std::string kw) |
756 | +void AggChildScope::set_keyword(std::string const &kw) |
757 | { |
758 | keyword_ = kw; |
759 | } |
760 | |
761 | -std::string AggChildScope::keyword() |
762 | +const std::string & AggChildScope::keyword() const |
763 | { |
764 | return keyword_; |
765 | } |
766 | |
767 | -void AggChildScope::set_keyword_scope_shared_cat_name(std::string cat) |
768 | +void AggChildScope::set_keyword_scope_shared_cat_name(std::string const &cat) |
769 | { |
770 | keyword_scope_shared_cat_name_ = cat; |
771 | uses_shared_cat_ = true; |
772 | } |
773 | |
774 | -std::string AggChildScope::keyword_scope_shared_cat_name() |
775 | +const std::string & AggChildScope::keyword_scope_shared_cat_name() const |
776 | { |
777 | return keyword_scope_shared_cat_name_; |
778 | } |
779 | @@ -332,22 +332,22 @@ |
780 | return source_finder_; |
781 | } |
782 | |
783 | -void AggChildScope::set_first_common_template_id(std::string id) |
784 | +void AggChildScope::set_first_common_template_id(std::string const &id) |
785 | { |
786 | first_common_template_id_ = id; |
787 | } |
788 | |
789 | -std::string AggChildScope::first_common_template_id() |
790 | +const std::string & AggChildScope::first_common_template_id() const |
791 | { |
792 | return first_common_template_id_; |
793 | } |
794 | |
795 | -void AggChildScope::set_surface_common_template_id(std::string id) |
796 | +void AggChildScope::set_surface_common_template_id(std::string const &id) |
797 | { |
798 | surface_common_template_id_ = id; |
799 | } |
800 | |
801 | -std::string AggChildScope::surface_common_template_id() |
802 | +const std::string & AggChildScope::surface_common_template_id() const |
803 | { |
804 | return surface_common_template_id_; |
805 | } |
806 | |
807 | === modified file 'src/query.cpp' |
808 | --- src/query.cpp 2016-06-23 19:37:49 +0000 |
809 | +++ src/query.cpp 2016-06-29 10:31:52 +0000 |
810 | @@ -25,8 +25,9 @@ |
811 | #include "i18n.h" |
812 | |
813 | #include <locale.h> |
814 | - |
815 | #include <iostream> |
816 | +#include <fstream> |
817 | +#include <sstream> |
818 | |
819 | #include <unity/scopes/Annotation.h> |
820 | #include <unity/scopes/CategorisedResult.h> |
821 | @@ -41,12 +42,20 @@ |
822 | #include <QDir> |
823 | #include <QDebug> |
824 | #include <QDateTime> |
825 | +#include <QJsonParseError> |
826 | +#include <QJsonDocument> |
827 | +#include <QJsonObject> |
828 | +#include <QJsonArray> |
829 | |
830 | namespace us = unity::scopes; |
831 | using namespace std; |
832 | |
833 | #define UNUSED(x) (void)(x); |
834 | |
835 | +static constexpr const char *TRUE = "true"; |
836 | +static constexpr const char *FALSE = "false"; |
837 | +static constexpr const char *LOCAL = "local"; |
838 | + |
839 | namespace |
840 | { |
841 | |
842 | @@ -60,25 +69,20 @@ |
843 | return QString::fromStdString(str); |
844 | } |
845 | |
846 | - |
847 | } // anonymous |
848 | |
849 | - |
850 | Query::Query(us::CannedQuery const& query, |
851 | - us::SearchMetadata const& metadata, |
852 | - const std::string scope_dir, |
853 | - const std::string cache_dir, |
854 | - us::RegistryProxy const& registry, |
855 | - AggScope * agg_scope |
856 | - ) : |
857 | + us::SearchMetadata const& metadata, |
858 | + std::string const& scope_dir, |
859 | + std::string const& cache_dir, |
860 | + us::RegistryProxy const& registry, |
861 | + AggScope * agg_scope) : |
862 | us::SearchQueryBase(query, metadata), |
863 | scope_dir_(scope_dir), |
864 | cache_dir_(cache_dir), |
865 | registry_(registry), |
866 | agg_scope_(agg_scope) |
867 | { |
868 | - setlocale(LC_ALL, ""); |
869 | - scope_id = agg_scope_->scope_id; |
870 | } |
871 | |
872 | Query::~Query() |
873 | @@ -108,7 +112,6 @@ |
874 | |
875 | void Query::run(us::SearchReplyProxy const& upstream_reply) |
876 | { |
877 | - |
878 | if (!registry_) { |
879 | throw us::ConfigException("No registry available, cannot locate child scopes"); |
880 | return; |
881 | @@ -120,7 +123,7 @@ |
882 | |
883 | bool empty_search = query_string.empty(); |
884 | |
885 | - load_hints_config(); |
886 | + load_hints_config(agg_scope_->hints_root()); |
887 | |
888 | bool hide_hints_quickstart = false; |
889 | |
890 | @@ -211,9 +214,10 @@ |
891 | { |
892 | qDebug() << "==== HINTS NO NET. simple message"; |
893 | std::string cat_id = "no_net_msg"; |
894 | - us::Category::SCPtr msg_cat; |
895 | - if (!upstream_reply->lookup_category(cat_id)) |
896 | - msg_cat = upstream_reply->register_category(cat_id, "", "", us::CategoryRenderer(MSG)); |
897 | + us::Category::SCPtr msg_cat = upstream_reply->lookup_category(cat_id); |
898 | + if (!msg_cat) |
899 | + msg_cat = upstream_reply->register_category(cat_id, "", "", us::CategoryRenderer(MSG)); |
900 | + |
901 | us::CategorisedResult res(msg_cat); |
902 | res["art"] = scope_dir_ + "/images/ubuntu.png"; |
903 | qDebug() << "=== HINTS. art: " << QString::fromStdString(scope_dir_ + "images/ubuntu.png"); |
904 | @@ -248,7 +252,11 @@ |
905 | if (no_location_msg && local_hints) |
906 | { |
907 | std::string cat_id = "no_location_msg"; |
908 | - us::Category::SCPtr msg_cat; |
909 | + |
910 | + us::Category::SCPtr msg_cat = upstream_reply->lookup_category(cat_id); |
911 | + if (!msg_cat) |
912 | + msg_cat = upstream_reply->register_category(cat_id, "", "", us::CategoryRenderer(MSG)); |
913 | + |
914 | if (!upstream_reply->lookup_category(cat_id)) |
915 | msg_cat = upstream_reply->register_category(cat_id, "", "", us::CategoryRenderer(MSG)); |
916 | |
917 | @@ -280,10 +288,10 @@ |
918 | } |
919 | |
920 | //load declared cardinality settings, if any |
921 | - load_cardinality_settings(); |
922 | + load_cardinality_setting(agg_scope_->child_root()); |
923 | |
924 | //load scope and keyword declarations |
925 | - load_declarations(); |
926 | + load_declarations(agg_scope_->child_root()); |
927 | |
928 | // create declared child scope instances and depts from child_scopes.json |
929 | make_declared_scopes(); |
930 | @@ -310,28 +318,82 @@ |
931 | create_departments(upstream_reply); |
932 | } |
933 | else |
934 | - qWarning () << QString("%1: NOT using departments").arg(qstr(scope_id)); |
935 | + { |
936 | + qWarning () << QString("%1: NOT using departments").arg(qstr(agg_scope_->scope_id())); |
937 | + } |
938 | |
939 | // set up handling for results and handle them, including buffering to ensure order |
940 | handle_child_scope_results(query_string, empty_search, upstream_reply); |
941 | |
942 | } |
943 | |
944 | -void Query::check_result_fallbacks(us::CategorisedResult &res, std::string common_id) |
945 | +void Query::load_hints_config(const QJsonObject &root) |
946 | +{ |
947 | + // try to open hints.json and get vals, else no hints |
948 | + if (!root.contains(QStringLiteral("using_hints"))) |
949 | + return; |
950 | + |
951 | + if (root[QStringLiteral("using_hints")].toString() != TRUE) |
952 | + return; |
953 | + |
954 | + uses_hints = true; |
955 | + |
956 | + if (!root.contains(QStringLiteral("hints_source"))) |
957 | + return; |
958 | + |
959 | + if (root[QStringLiteral("hints_source")].toString() == LOCAL) |
960 | + { |
961 | + local_hints = true; |
962 | + if (root.contains(QStringLiteral("local"))) { |
963 | + hints_local_json = root[QStringLiteral("local")].toObject(); |
964 | + } |
965 | + } |
966 | + |
967 | + if (root.contains(QStringLiteral("quick_start_help")) |
968 | + && sstr(root[QStringLiteral("quick_start_help")].toString()) == TRUE) |
969 | + hints_quickstart = true; |
970 | + if (root.contains(QStringLiteral("message_on_no_network")) |
971 | + && sstr(root[QStringLiteral("message_on_no_network")].toString()) == TRUE) |
972 | + no_network_msg = true; |
973 | + if (root.contains(QStringLiteral("message_on_no_location")) |
974 | + && sstr(root[QStringLiteral("message_on_no_location")].toString()) == TRUE) |
975 | + no_location_msg = true; |
976 | + |
977 | + if (!local_hints) |
978 | + { |
979 | + if (root.contains(QStringLiteral("hints_scope"))) |
980 | + { |
981 | + QJsonObject hints_scope = root[QStringLiteral("hints_scope")].toObject(); |
982 | + if (hints_scope.contains(QStringLiteral("hints_scope_id"))) |
983 | + HINTS_SCOPE_ID = sstr(hints_scope[QStringLiteral("hints_scope_id")].toString()); |
984 | + else |
985 | + uses_hints = false; |
986 | + if (hints_scope.contains(QStringLiteral("hints_this_scope"))) |
987 | + HINTS_THIS_SCOPE = sstr(hints_scope[QStringLiteral("hints_this_scope")].toString()); |
988 | + else |
989 | + uses_hints = false; |
990 | + //this key is deprecated. it previously specified the query string the hints scope |
991 | + //sent to the agg scope to signal hints quick start should be permanently dismissed. |
992 | + //scope-aggregator 4.4 stopped using this. |
993 | + if (hints_scope.contains(QStringLiteral("hints_hide"))) |
994 | + HINTS_HIDE = sstr(hints_scope[QStringLiteral("hints_hide")].toString()); |
995 | + else |
996 | + uses_hints = false; |
997 | + } |
998 | + } |
999 | +} |
1000 | + |
1001 | +void Query::check_result_fallbacks(us::CategorisedResult &res, std::string const &common_id) |
1002 | { |
1003 | qDebug() << "=== check FALLB common id: "<< qstr(common_id); |
1004 | - for (auto fb : common_templates_fallbacks) |
1005 | - { |
1006 | - qDebug() << "=== check FALLB RES. a fallback found"; |
1007 | - } |
1008 | if ( common_templates_fallbacks.find(common_id) != common_templates_fallbacks.end()) |
1009 | { |
1010 | qDebug() << "=== check FALLB common id found"; |
1011 | - auto map = *common_templates_fallbacks[common_id]; |
1012 | + const auto & map = *common_templates_fallbacks[common_id]; |
1013 | for(auto iter = map.begin(); iter != map.end(); ++iter) |
1014 | { |
1015 | qDebug() << "==== check FALLB first: " << qstr(iter->first); |
1016 | - for (auto field : iter->second) |
1017 | + for (const auto & field : iter->second) |
1018 | { |
1019 | qDebug() << "==== check FALLB field: " << qstr(field); |
1020 | if (res[iter->first].get_string().empty()) |
1021 | @@ -348,7 +410,8 @@ |
1022 | /** |
1023 | * Cycle through scopes in order. For each, set up buffering and handle the current CategorisedResult (or use default handling). Results from the first scope are not buffered, that is they are displayed as soon as they arrive. Results from other scopes are held (buffered) until all preceding scopes have results, thus ensuring scope ordering |
1024 | */ |
1025 | -void Query::handle_child_scope_results(std::string query_string, bool empty_search, us::SearchReplyProxy const& upstream_reply) |
1026 | +void Query::handle_child_scope_results(std::string const &query_string, bool empty_search, |
1027 | + us::SearchReplyProxy const& upstream_reply) |
1028 | { |
1029 | std::vector<std::shared_ptr<ResultForwarder>> replies; // used for buffering/category ordering |
1030 | std::vector<std::string> added_by_localId; |
1031 | @@ -361,7 +424,7 @@ |
1032 | //if the query is no longer valid, return |
1033 | if (!this->valid()) |
1034 | { |
1035 | - qWarning () << QString("%1: Query is no longer valid. Stopping").arg(qstr(scope_id)); |
1036 | + qWarning () << QString("%1: Query is no longer valid. Stopping").arg(qstr(agg_scope_->scope_id())); |
1037 | return; |
1038 | } |
1039 | qDebug() << "==== handle. checking scope locali_id: " << qstr(local_id); |
1040 | @@ -377,7 +440,7 @@ |
1041 | us::MetadataMap::const_iterator scope_it; |
1042 | scope_it = reg_scopes.find(localId_id_m[local_id]); |
1043 | if (scope_it == reg_scopes.end()) { |
1044 | - qWarning () << QString("%1: scope is NOT REGISTERED, skipping: %2").arg(qstr(scope_id), qstr(localId_id_m[local_id])); |
1045 | + qWarning () << QString("%1: scope is NOT REGISTERED, skipping: %2").arg(qstr(agg_scope_->scope_id()), qstr(localId_id_m[local_id])); |
1046 | continue; |
1047 | } |
1048 | |
1049 | @@ -397,18 +460,15 @@ |
1050 | bool found_as_enabled = false; |
1051 | for (auto cs : current_child_scopes)//FQ ids |
1052 | { |
1053 | - if (cs.id == localId_id_m[local_id]) |
1054 | + if (cs.enabled && cs.id == localId_id_m[local_id]) |
1055 | { |
1056 | - if (cs.enabled) |
1057 | - { |
1058 | - found_as_enabled = true; |
1059 | - } |
1060 | + found_as_enabled = true; |
1061 | } |
1062 | } |
1063 | |
1064 | if (!found_as_enabled) |
1065 | { |
1066 | - qWarning () << QString("%1: scope is NOT ENABLED, skipping: %2").arg(qstr(scope_id), qstr(localId_id_m[local_id])); |
1067 | + qWarning () << QString("%1: scope is NOT ENABLED, skipping: %2").arg(qstr(agg_scope_->scope_id()), qstr(localId_id_m[local_id])); |
1068 | continue; |
1069 | } |
1070 | |
1071 | @@ -427,7 +487,8 @@ |
1072 | } |
1073 | } |
1074 | |
1075 | - if (found_as_exclude) { |
1076 | + if (found_as_exclude) |
1077 | + { |
1078 | continue; |
1079 | } |
1080 | |
1081 | @@ -634,7 +695,9 @@ |
1082 | ); |
1083 | } |
1084 | else |
1085 | + { |
1086 | res.set_category(upstream_reply->lookup_category(cat_id)); |
1087 | + } |
1088 | } |
1089 | else if (!upstream_reply->lookup_category(cat_id)) |
1090 | { |
1091 | @@ -648,77 +711,76 @@ |
1092 | res.set_category(upstream_reply->lookup_category(cat_id)); |
1093 | } |
1094 | else |
1095 | + { |
1096 | res.set_category(upstream_reply->lookup_category(cat_id)); |
1097 | + } |
1098 | } |
1099 | else |
1100 | + { |
1101 | res.set_category(upstream_reply->lookup_category(cat_id)); |
1102 | qDebug() << "==== KW SHAREDCAT not uses first result. cat_id: " << qstr(cat_id); |
1103 | + } |
1104 | } |
1105 | } |
1106 | else // keyword scope does not use a shared category |
1107 | { |
1108 | qDebug() << "==== KW not SHAREDCAT"; |
1109 | - qDebug() << "==== KW not SHAREDCAT. first result for scope: " << qstr(scope->local_id()); |
1110 | - scope->set_is_first_result(false); |
1111 | - //cat_title = inc_res_cat_title; |
1112 | - //if (cat_title.empty()){ |
1113 | - cat_title = registry_->get_metadata(scope->id()).display_name(); |
1114 | - //} |
1115 | - qDebug() << "==== KW not SHAREDCAT. local_id: " << qstr(scope->local_id()); |
1116 | - qDebug() << "==== KW not SHAREDCAT. cat_ttile: " << qstr(cat_title); |
1117 | - //if (keyword_catname_renderer.find(keyword) != keyword_catname_renderer.end())// has a decared surface template |
1118 | - if (!keyword_catname_renderer[keyword].empty()) |
1119 | - { |
1120 | - qDebug() << "==== KW not SHAREDCAT. declared renderer "; |
1121 | - qDebug() << "==== KW not SHAREDCAR. keyword: " << qstr(scope->keyword()); |
1122 | - cat_id = scope->keyword() + ":keyword:not_shared_category:declared_renderer:surfacing:" + cat_title; |
1123 | - rdr = keyword_catname_renderer[keyword]; |
1124 | - } |
1125 | - else // use result template |
1126 | - { |
1127 | - qDebug() << "==== KW not SHAREDCAT. incoming renderer"; |
1128 | - cat_id = scope->keyword() + ":keyword:not_shared_category:incoming_renderer:surfacing:" + cat_title; |
1129 | - rdr = res.category()->renderer_template().data(); |
1130 | - } |
1131 | - qDebug() << "==== KW not SHAREDCAT. cat_id: " << qstr(cat_id); |
1132 | - if (scope->category_link_to_child()) |
1133 | - { |
1134 | - if (!upstream_reply->lookup_category(cat_id)) |
1135 | - { |
1136 | - upstream_reply->register_category |
1137 | - ( |
1138 | - cat_id, |
1139 | - cat_title, |
1140 | - "", |
1141 | - us::CannedQuery(scope->id(), query_string, scope->child_department()), |
1142 | - us::CategoryRenderer(rdr) |
1143 | - ); |
1144 | - } |
1145 | + qDebug() << "==== KW not SHAREDCAT. first result for scope: " << qstr(scope->local_id()); |
1146 | + scope->set_is_first_result(false); |
1147 | + //cat_title = inc_res_cat_title; |
1148 | + //if (cat_title.empty()){ |
1149 | + cat_title = registry_->get_metadata(scope->id()).display_name(); |
1150 | + //} |
1151 | + qDebug() << "==== KW not SHAREDCAT. local_id: " << qstr(scope->local_id()); |
1152 | + qDebug() << "==== KW not SHAREDCAT. cat_ttile: " << qstr(cat_title); |
1153 | + //if (keyword_catname_renderer.find(keyword) != keyword_catname_renderer.end())// has a decared surface template |
1154 | + if (!keyword_catname_renderer[keyword].empty()) |
1155 | + { |
1156 | + qDebug() << "==== KW not SHAREDCAT. declared renderer "; |
1157 | + qDebug() << "==== KW not SHAREDCAR. keyword: " << qstr(scope->keyword()); |
1158 | + cat_id = scope->keyword() + ":keyword:not_shared_category:declared_renderer:surfacing:" + cat_title; |
1159 | + rdr = keyword_catname_renderer[keyword]; |
1160 | + } |
1161 | + else // use result template |
1162 | + { |
1163 | + qDebug() << "==== KW not SHAREDCAT. incoming renderer"; |
1164 | + cat_id = scope->keyword() + ":keyword:not_shared_category:incoming_renderer:surfacing:" + cat_title; |
1165 | + rdr = res.category()->renderer_template().data(); |
1166 | + } |
1167 | + qDebug() << "==== KW not SHAREDCAT. cat_id: " << qstr(cat_id); |
1168 | + if (scope->category_link_to_child()) |
1169 | + { |
1170 | + if (!upstream_reply->lookup_category(cat_id)) |
1171 | + { |
1172 | + upstream_reply->register_category |
1173 | + ( |
1174 | + cat_id, |
1175 | + cat_title, |
1176 | + "", |
1177 | + us::CannedQuery(scope->id(), query_string, scope->child_department()), |
1178 | + us::CategoryRenderer(rdr) |
1179 | + ); |
1180 | + } |
1181 | res.set_category(upstream_reply->lookup_category(cat_id)); |
1182 | - } |
1183 | - else |
1184 | - { |
1185 | - if (!upstream_reply->lookup_category(cat_id)) |
1186 | - { |
1187 | - upstream_reply->register_category |
1188 | - ( |
1189 | - cat_id, |
1190 | - cat_title, |
1191 | - "", |
1192 | - us::CategoryRenderer(rdr) |
1193 | - ); |
1194 | - } |
1195 | - res.set_category(upstream_reply->lookup_category(cat_id)); |
1196 | - } |
1197 | + } |
1198 | + else |
1199 | + { |
1200 | + if (!upstream_reply->lookup_category(cat_id)) |
1201 | + { |
1202 | + upstream_reply->register_category |
1203 | + ( |
1204 | + cat_id, |
1205 | + cat_title, |
1206 | + "", |
1207 | + us::CategoryRenderer(rdr) |
1208 | + ); |
1209 | + } |
1210 | + res.set_category(upstream_reply->lookup_category(cat_id)); |
1211 | + } |
1212 | } |
1213 | } |
1214 | else if (scope->category_scope()) |
1215 | { |
1216 | - /* |
1217 | - qDebug() << "==== LINK loop categoryId_linkToChildSpecified size: " << categoryId_linkToChildSpecified.size(); |
1218 | - for (auto spec : categoryId_linkToChildSpecified) |
1219 | - qDebug() << "==== LINK loop: " << qstr(spec.second); |
1220 | - */ |
1221 | std::string category_id = scope->category_id(); |
1222 | qDebug() << "==== CATREG RESULT scope: " << qstr(scope->id()) << " title: " <<qstr(cat_title); |
1223 | |
1224 | @@ -1214,15 +1276,15 @@ |
1225 | qDebug() << "==== scopes.size(): " << scopes.size(); |
1226 | qDebug() << "==== replies.size(): " << replies.size(); |
1227 | // create and chain result forwarders to enforce proper order of categores |
1228 | - for (unsigned int i = 1; i < scopes.size(); ++i) { |
1229 | - for (unsigned int j = 0; j < i; ++j) { |
1230 | + for (size_t i = 1; i < scopes.size(); ++i) { |
1231 | + for (size_t j = 0; j < i; ++j) { |
1232 | replies[j]->add_observer(replies[i]); |
1233 | } |
1234 | } |
1235 | |
1236 | // dispatch search to subscopes |
1237 | // also set cardinality, default and per scope |
1238 | - for (unsigned int i = 0; i < replies.size(); ++i) { |
1239 | + for (size_t i = 0; i < replies.size(); ++i) { |
1240 | us::SearchMetadata metadata(search_metadata()); |
1241 | std::string locID = scopes_m_int_localId[i]; |
1242 | qDebug() << "==== locID: " << QString::fromStdString(locID); |
1243 | |
1244 | === modified file 'src/scope.cpp' |
1245 | --- src/scope.cpp 2016-06-23 19:37:49 +0000 |
1246 | +++ src/scope.cpp 2016-06-29 10:31:52 +0000 |
1247 | @@ -23,8 +23,11 @@ |
1248 | #include "i18n.h" |
1249 | #include "action.h" |
1250 | |
1251 | +#include <fstream> |
1252 | +#include <sstream> |
1253 | #include <unity-scopes.h> |
1254 | |
1255 | + |
1256 | #include <QDebug> |
1257 | #include <QFile> |
1258 | #include <QFile> |
1259 | @@ -48,11 +51,41 @@ |
1260 | return QString::fromStdString(str); |
1261 | } |
1262 | |
1263 | +static std::tuple<std::string, std::string> locale_info() |
1264 | +{ |
1265 | + std::string lc = setlocale(LC_ALL, ""); |
1266 | + std::string lc_lang = lc.size() > 5 ? lc.substr(0, 2) : ""; |
1267 | + std::string lc_country = lc.size() > 5 ? lc.substr(3, 2) : ""; |
1268 | + return std::make_tuple(lc_lang, lc_country); |
1269 | +} |
1270 | + |
1271 | +static bool load_json_file(QJsonObject& root, std::string const & file_path, std::string const & scope_id) |
1272 | +{ |
1273 | + std::ifstream f(file_path); |
1274 | + if (!f.good()) |
1275 | + { |
1276 | + qWarning() << QString("%1. Can't find child json file path: %2").arg( |
1277 | + qstr(scope_id), |
1278 | + qstr(file_path)); |
1279 | + return false; |
1280 | + } |
1281 | + |
1282 | + std::stringstream buffer; |
1283 | + buffer << f.rdbuf(); |
1284 | + std::string bytes = buffer.str(); |
1285 | + |
1286 | + QJsonDocument doc = QJsonDocument::fromJson(qstr(bytes).toUtf8()); |
1287 | + |
1288 | + if (!doc.isNull() && doc.isObject()) { |
1289 | + root = doc.object(); |
1290 | + return true; |
1291 | + } |
1292 | + |
1293 | + return false; |
1294 | +} |
1295 | |
1296 | } // anonymous |
1297 | |
1298 | - |
1299 | - |
1300 | AggScope::AggScope() |
1301 | { |
1302 | } |
1303 | @@ -60,7 +93,20 @@ |
1304 | void AggScope::start(std::string const& scope_name) |
1305 | { |
1306 | qDebug() <<"==== AggScope scope_name" << qstr(scope_name); |
1307 | - scope_id = scope_name; |
1308 | + |
1309 | + scope_id_ = scope_name; |
1310 | + |
1311 | + auto l_info = locale_info(); |
1312 | + lang_ = std::get<0>(l_info); |
1313 | + country_ = std::get<1>(l_info); |
1314 | + |
1315 | + std::string child_json_path = scope_directory() + "/" + CHILD_JSON_FILE; |
1316 | + if (!load_json_file(child_root_, child_json_path, scope_id_)) |
1317 | + qCritical("load child json file failed"); |
1318 | + |
1319 | + std::string hints_json_path = scope_directory() + "/" + HINTS_JSON_FILE; |
1320 | + if (!load_json_file(hints_root_, hints_json_path, scope_id_)) |
1321 | + qCritical("load hints json file failed"); |
1322 | } |
1323 | |
1324 | void AggScope::stop() |
1325 | @@ -70,13 +116,9 @@ |
1326 | us::SearchQueryBase::UPtr AggScope::search(us::CannedQuery const &q, |
1327 | us::SearchMetadata const &metadata) |
1328 | { |
1329 | - |
1330 | - const QString scopePath = QString::fromStdString(scope_directory()); |
1331 | - const QString cachePath = QString::fromStdString(cache_directory()); |
1332 | - |
1333 | textdomain(GETTEXT_DOMAIN.toStdString().c_str()); |
1334 | |
1335 | - QString tdir = QString("%1/locale/").arg(scopePath); |
1336 | + QString tdir = QString("%1/locale/").arg(qstr(scope_directory())); |
1337 | bindtextdomain(GETTEXT_DOMAIN.toStdString().c_str(), tdir.toStdString().c_str()); |
1338 | |
1339 | us::SearchQueryBase::UPtr query(new Query(q, metadata, |
1340 | @@ -97,68 +139,43 @@ |
1341 | { |
1342 | std::vector<std::string> declared_scopes; |
1343 | |
1344 | - QString f_fn_qs = QString("%1/child_scopes.json").arg(QString::fromStdString(scope_directory())); |
1345 | - QFile f_f; |
1346 | - f_f.setFileName(f_fn_qs); |
1347 | - |
1348 | - if (!f_f.exists()) |
1349 | - { |
1350 | - qWarning() << QString("%1 not found. No settingsfor declared child scopes.").arg(f_fn_qs); |
1351 | - return declared_scopes; |
1352 | - } |
1353 | - |
1354 | - f_f.open(QIODevice::ReadOnly); |
1355 | - QByteArray data = f_f.readAll(); |
1356 | - |
1357 | - QJsonParseError err; |
1358 | - QJsonDocument doc = QJsonDocument::fromJson(data, &err); |
1359 | - //qDebug() << doc.toJson(); |
1360 | - |
1361 | - if (err.error != QJsonParseError::NoError) |
1362 | - { |
1363 | - qWarning() << QString("Failed to parse %1 data: ").arg(f_fn_qs) << err.errorString(); |
1364 | - return declared_scopes; |
1365 | - } |
1366 | - |
1367 | - QJsonObject doc_o = doc.object(); |
1368 | - |
1369 | //TODO. pass doc_o to Query for all use cases for speed |
1370 | - QJsonArray scopes_and_keywords_a = doc_o["order"].toArray(); |
1371 | + QJsonArray scopes_and_keywords_a = child_root_[QStringLiteral("order")].toArray(); |
1372 | |
1373 | - for (const auto item_ : scopes_and_keywords_a) |
1374 | + for (const auto & item_ : scopes_and_keywords_a) |
1375 | { |
1376 | QJsonObject item_o = item_.toObject(); |
1377 | - if (item_o.contains("scope")) |
1378 | + if (item_o.contains(QStringLiteral("scope"))) |
1379 | { |
1380 | - QJsonObject scope_o = item_o["scope"].toObject(); |
1381 | + QJsonObject scope_o = item_o[QStringLiteral("scope")].toObject(); |
1382 | if (type == IdType::local_id) |
1383 | { |
1384 | - std::string local_id = scope_o["local_id"].toString().toStdString(); |
1385 | + std::string local_id = scope_o[QStringLiteral("local_id")].toString().toStdString(); |
1386 | declared_scopes.emplace_back(local_id); |
1387 | } |
1388 | else |
1389 | { |
1390 | - std::string id = scope_o["id"].toString().toStdString(); |
1391 | + std::string id = scope_o[QStringLiteral("id")].toString().toStdString(); |
1392 | declared_scopes.emplace_back(id); |
1393 | } |
1394 | } |
1395 | - else if (item_o.contains("category")) |
1396 | + else if (item_o.contains(QStringLiteral("category"))) |
1397 | { |
1398 | - QJsonObject cat_o = item_o["category"].toObject(); |
1399 | - if (cat_o.contains("scopes")) |
1400 | + QJsonObject cat_o = item_o[QStringLiteral("category")].toObject(); |
1401 | + if (cat_o.contains(QStringLiteral("scopes"))) |
1402 | { |
1403 | - QJsonArray scopes_a = cat_o["scopes"].toArray(); |
1404 | - for (auto item : scopes_a) |
1405 | + QJsonArray scopes_a = cat_o[QStringLiteral("scopes")].toArray(); |
1406 | + for (const auto &item : scopes_a) |
1407 | { |
1408 | QJsonObject scope_o = item.toObject(); |
1409 | if (type == IdType::local_id) |
1410 | { |
1411 | - std::string local_id = scope_o["local_id"].toString().toStdString(); |
1412 | + std::string local_id = scope_o[QStringLiteral("local_id")].toString().toStdString(); |
1413 | declared_scopes.emplace_back(local_id); |
1414 | } |
1415 | else |
1416 | { |
1417 | - std::string id = scope_o["id"].toString().toStdString(); |
1418 | + std::string id = scope_o[QStringLiteral("id")].toString().toStdString(); |
1419 | declared_scopes.emplace_back(id); |
1420 | } |
1421 | } |
1422 | @@ -166,8 +183,6 @@ |
1423 | } |
1424 | } |
1425 | |
1426 | - f_f.flush(); |
1427 | - f_f.close(); |
1428 | return declared_scopes; |
1429 | } |
1430 | |
1431 | @@ -175,53 +190,27 @@ |
1432 | { |
1433 | std::vector<std::string> keywords; |
1434 | |
1435 | - QString f_fn_qs = QString("%1/child_scopes.json").arg(QString::fromStdString(scope_directory())); |
1436 | - QFile f_f; |
1437 | - f_f.setFileName(f_fn_qs); |
1438 | - |
1439 | - if (!f_f.exists()) |
1440 | - { |
1441 | - qWarning() << QString("%1: child_scopes.json not found. Not aggregating keyworded child scopes.").arg(qstr(SCOPE_ID)); |
1442 | - return keywords; |
1443 | - } |
1444 | - |
1445 | - f_f.open(QIODevice::ReadOnly); |
1446 | - QByteArray data = f_f.readAll(); |
1447 | - |
1448 | - QJsonParseError err; |
1449 | - QJsonDocument doc = QJsonDocument::fromJson(data, &err); |
1450 | - |
1451 | - if (err.error != QJsonParseError::NoError) |
1452 | - { |
1453 | - qWarning() << QString("%1:Failed to parse keywords.json data. Error: ").arg(qstr(SCOPE_ID), err.errorString()); |
1454 | - f_f.flush(); |
1455 | - f_f.close(); |
1456 | - return keywords; |
1457 | - } |
1458 | - |
1459 | - QJsonObject doc_o = doc.object(); |
1460 | - |
1461 | - QJsonArray order_a = doc_o["order"].toArray(); |
1462 | - |
1463 | - for (const auto order_item_o : order_a) |
1464 | + QJsonArray order_a = child_root_[QStringLiteral("order")].toArray(); |
1465 | + |
1466 | + for (const auto & order_item_o : order_a) |
1467 | { |
1468 | QJsonObject o_ = order_item_o.toObject(); |
1469 | |
1470 | - if (o_.contains("keyword")) |
1471 | + if (o_.contains(QStringLiteral("keyword"))) |
1472 | { |
1473 | - QJsonObject keyword_o = o_["keyword"].toObject(); |
1474 | - keywords.emplace_back(keyword_o["keyword"].toString().toStdString()); |
1475 | + QJsonObject keyword_o = o_[QStringLiteral("keyword")].toObject(); |
1476 | + keywords.emplace_back(keyword_o[QStringLiteral("keyword")].toString().toStdString()); |
1477 | } |
1478 | - if (o_.contains("category")) |
1479 | + if (o_.contains(QStringLiteral("category"))) |
1480 | { |
1481 | - QJsonObject category_o = o_["category"].toObject(); |
1482 | - if (category_o.contains("keywords")) |
1483 | + QJsonObject category_o = o_[QStringLiteral("category")].toObject(); |
1484 | + if (category_o.contains(QStringLiteral("keywords"))) |
1485 | { |
1486 | - QJsonArray keywords_a = category_o["keywords"].toArray(); |
1487 | - for (const auto item_o : keywords_a) |
1488 | + QJsonArray keywords_a = category_o[QStringLiteral("keywords")].toArray(); |
1489 | + for (const auto & item_o : keywords_a) |
1490 | { |
1491 | QJsonObject keyword_o = item_o.toObject(); |
1492 | - std::string id = keyword_o["id"].toString().toStdString(); |
1493 | + std::string id = keyword_o[QStringLiteral("id")].toString().toStdString(); |
1494 | auto iter = std::find(keywords.begin(), keywords.end(), id); |
1495 | if (iter == keywords.end()) |
1496 | { |
1497 | @@ -235,7 +224,6 @@ |
1498 | return keywords; |
1499 | } |
1500 | |
1501 | - |
1502 | us::ChildScopeList AggScope::find_child_scopes() const |
1503 | { |
1504 | std::vector<std::string> declared_scopes = get_declared_scopes(IdType::id); |
1505 | @@ -270,7 +258,7 @@ |
1506 | { |
1507 | auto keywords = item.keywords(); |
1508 | bool found = false; |
1509 | - for (std::string kw : keywords_l) |
1510 | + for (const auto &kw : keywords_l) |
1511 | { |
1512 | if (keywords.find(kw) != keywords.end()) |
1513 | { |
1514 | @@ -290,7 +278,7 @@ |
1515 | return found;//seems to be ok to return the same scope multiple times (in the case of multiple keyword matches) |
1516 | }); |
1517 | |
1518 | - for (auto const& kw_scope : kw_scopes) |
1519 | + for (const auto &kw_scope : kw_scopes) |
1520 | { |
1521 | // verify the keyword scope is not a dup of a declared scope |
1522 | auto iter = find(declared_scopes.begin(), declared_scopes.end(), kw_scope.first); |
1523 | @@ -300,17 +288,42 @@ |
1524 | } |
1525 | } |
1526 | |
1527 | - for (auto cd : list) |
1528 | + for (const auto &cd : list) |
1529 | qDebug() << "==== child scope id: " << qstr(cd.id); |
1530 | + |
1531 | return list; |
1532 | } |
1533 | |
1534 | us::ActivationQueryBase::UPtr AggScope::activate(us::Result const& result, |
1535 | us::ActionMetadata const& metadata) |
1536 | { |
1537 | - return us::ActivationQueryBase::UPtr(new Action(result, metadata, cache_directory(), scope_id)); |
1538 | -} |
1539 | - |
1540 | + return us::ActivationQueryBase::UPtr(new Action(result, metadata, cache_directory(), scope_id_)); |
1541 | +} |
1542 | + |
1543 | +const std::string & AggScope::scope_id() const |
1544 | +{ |
1545 | + return scope_id_; |
1546 | +} |
1547 | + |
1548 | +const std::string & AggScope::lang() const |
1549 | +{ |
1550 | + return lang_; |
1551 | +} |
1552 | + |
1553 | +const std::string & AggScope::country() const |
1554 | +{ |
1555 | + return country_; |
1556 | +} |
1557 | + |
1558 | +const QJsonObject & AggScope::child_root() const |
1559 | +{ |
1560 | + return child_root_; |
1561 | +} |
1562 | + |
1563 | +const QJsonObject & AggScope::hints_root() const |
1564 | +{ |
1565 | + return hints_root_; |
1566 | +} |
1567 | |
1568 | #define EXPORT __attribute__ ((visibility ("default"))) |
1569 | |
1570 | |
1571 | === modified file 'src/utils.cpp' |
1572 | --- src/utils.cpp 2016-06-23 20:49:09 +0000 |
1573 | +++ src/utils.cpp 2016-06-29 10:31:52 +0000 |
1574 | @@ -38,13 +38,9 @@ |
1575 | |
1576 | #define UNUSED(x) (void)(x); |
1577 | |
1578 | -QString locale_qs = QString::fromStdString(setlocale(LC_ALL, "")); |
1579 | -QString lang = locale_qs.left(2); |
1580 | -QString mid = locale_qs.left(5); |
1581 | -QString country = mid.right(2).toLower(); |
1582 | - |
1583 | static constexpr const char *TRUE = "true"; |
1584 | static constexpr const char *FALSE = "false"; |
1585 | + |
1586 | namespace |
1587 | { |
1588 | |
1589 | @@ -58,72 +54,24 @@ |
1590 | return QString::fromStdString(str); |
1591 | } |
1592 | |
1593 | -static bool load_json_file(QJsonObject& root, std::string const & file_path, std::string const & scope_id) |
1594 | -{ |
1595 | - std::ifstream f(file_path); |
1596 | - if (!f.good()) |
1597 | - { |
1598 | - qWarning() << QString("%1. Can't find child json file path: %2").arg( |
1599 | - qstr(scope_id), |
1600 | - qstr(file_path)); |
1601 | - return false; |
1602 | - } |
1603 | - |
1604 | - std::stringstream buffer; |
1605 | - buffer << f.rdbuf(); |
1606 | - std::string bytes = buffer.str(); |
1607 | - |
1608 | - QJsonDocument doc = QJsonDocument::fromJson(qstr(bytes).toUtf8()); |
1609 | - |
1610 | - if (!doc.isNull()) { |
1611 | - if (doc.isObject()) { |
1612 | - root = doc.object(); |
1613 | - } |
1614 | - else |
1615 | - return false; |
1616 | - } |
1617 | - else |
1618 | - return false; |
1619 | - return true; |
1620 | -} |
1621 | - |
1622 | } // anonymous namespace |
1623 | |
1624 | |
1625 | -void Query::load_cardinality_settings() |
1626 | +void Query::load_cardinality_setting(QJsonObject const &root) |
1627 | { |
1628 | - |
1629 | - QString child_scopes_fn_qs = QString("%1/child_scopes.json").arg(qstr(scope_dir_)); |
1630 | - |
1631 | - QFile child_scopes_f; |
1632 | - child_scopes_f.setFileName(child_scopes_fn_qs); |
1633 | - child_scopes_f.open(QIODevice::ReadOnly); |
1634 | - QByteArray data = child_scopes_f.readAll(); |
1635 | - |
1636 | - QJsonParseError err; |
1637 | - QJsonDocument doc = QJsonDocument::fromJson(data, &err); |
1638 | - |
1639 | - if (err.error != QJsonParseError::NoError) |
1640 | - { |
1641 | - qCritical() << "Failed to parse child_scopes.json data: " << err.errorString(); |
1642 | - return; |
1643 | - } |
1644 | - |
1645 | - QJsonObject doc_o = doc.object(); |
1646 | - |
1647 | - if (doc_o.contains("cardinality_settings")) |
1648 | - { |
1649 | - QJsonArray card_a = doc_o["cardinality_settings"].toArray(); |
1650 | - for (auto item : card_a) |
1651 | + if (root.contains(QStringLiteral("cardinality_settings"))) |
1652 | + { |
1653 | + QJsonArray card_a = root[QStringLiteral("cardinality_settings")].toArray(); |
1654 | + for (const auto & item : card_a) |
1655 | { |
1656 | QJsonObject item_o = item.toObject(); |
1657 | - qDebug() << " ===== CARD. found declared value: " << item_o["value"].toInt(); |
1658 | - setting_cardinalities.push_back(item_o["value"].toInt()); |
1659 | + qDebug() << " ===== CARD. found declared value: " << item_o[QStringLiteral("value")].toInt(); |
1660 | + setting_cardinalities.push_back(item_o[QStringLiteral("value")].toInt()); |
1661 | } |
1662 | } |
1663 | } |
1664 | |
1665 | -int Query::get_setting_cardinality() |
1666 | +int Query::get_cardinality_setting() |
1667 | { |
1668 | us::VariantMap settings_ = settings(); |
1669 | auto it = settings_.find("cardinality"); |
1670 | @@ -138,71 +86,50 @@ |
1671 | /* |
1672 | * Load declarations from child_scopes.json |
1673 | */ |
1674 | -void Query::load_declarations() |
1675 | +void Query::load_declarations(QJsonObject const &root) |
1676 | { |
1677 | - |
1678 | - QString child_scopes_fn_qs = QString("%1/child_scopes.json").arg(qstr(scope_dir_)); |
1679 | - |
1680 | - QFile child_scopes_f; |
1681 | - child_scopes_f.setFileName(child_scopes_fn_qs); |
1682 | - child_scopes_f.open(QIODevice::ReadOnly); |
1683 | - QByteArray data = child_scopes_f.readAll(); |
1684 | - |
1685 | - QJsonParseError err; |
1686 | - QJsonDocument doc = QJsonDocument::fromJson(data, &err); |
1687 | - |
1688 | - if (err.error != QJsonParseError::NoError) |
1689 | - { |
1690 | - qCritical() << "Failed to parse child_scopes.json data: " << err.errorString(); |
1691 | - return; |
1692 | - } |
1693 | - |
1694 | - QJsonObject doc_o = doc.object(); |
1695 | - |
1696 | - QJsonArray common_templates_a = doc_o["common_templates"].toArray(); |
1697 | - |
1698 | - for (const auto item_ : common_templates_a) |
1699 | + QJsonArray common_templates_a = root[QStringLiteral("common_templates")].toArray(); |
1700 | + |
1701 | + for (const auto & item_ : common_templates_a) |
1702 | { |
1703 | QJsonObject template_o = item_.toObject(); |
1704 | - std::string id = template_o["id"].toString().toStdString(); |
1705 | + std::string id = template_o[QStringLiteral("id")].toString().toStdString(); |
1706 | |
1707 | - QJsonObject template__ = template_o["template"].toObject(); |
1708 | + QJsonObject template__ = template_o[QStringLiteral("template")].toObject(); |
1709 | QJsonDocument t_d(template__); |
1710 | - std::string template_ = ::sstr(t_d.toJson()); |
1711 | - |
1712 | - common_templates[id] = template_; |
1713 | - if (template_o.contains("fallbacks")) |
1714 | + common_templates[id] = ::sstr(t_d.toJson()); |
1715 | + if (template_o.contains(QStringLiteral("fallbacks"))) |
1716 | { |
1717 | qDebug() << "==== FALLBACK in fallbacks, id: " << qstr(id); |
1718 | - QJsonArray fallbacks_a = template_o["fallbacks"].toArray(); |
1719 | - std::map<std::string,std::vector<std::string>> fallbacks_m; |
1720 | + QJsonArray fallbacks_a = template_o[QStringLiteral("fallbacks")].toArray(); |
1721 | + auto fallbacks_m = std::make_shared<std::map<std::string,std::vector<std::string>>>(); |
1722 | std::vector<std::string> fields; |
1723 | - for (const auto fb_ : fallbacks_a) |
1724 | + for (const auto & fb_ : fallbacks_a) |
1725 | { |
1726 | QJsonObject fb_o = fb_.toObject(); |
1727 | - std::string key = fb_o["key"].toString().toStdString(); |
1728 | + std::string key = fb_o[QStringLiteral("key")].toString().toStdString(); |
1729 | qDebug() << "==== FALLBACK key: " <<qstr(key); |
1730 | - QJsonArray fields_a = fb_o["fields"].toArray(); |
1731 | - for (const auto f_ : fields_a) |
1732 | + QJsonArray fields_a = fb_o[QStringLiteral("fields")].toArray(); |
1733 | + for (const auto & f_ : fields_a) |
1734 | { |
1735 | QJsonObject f_o = f_.toObject(); |
1736 | - std::string field= f_o["field"].toString().toStdString(); |
1737 | + std::string field= f_o[QStringLiteral("field")].toString().toStdString(); |
1738 | qDebug() << "==== FALLBACK field: " <<qstr(field); |
1739 | fields.emplace_back(field); |
1740 | } |
1741 | - fallbacks_m[key] = fields; |
1742 | + (*fallbacks_m)[key] = fields; |
1743 | } |
1744 | - std::shared_ptr<std::map<std::string,std::vector<std::string>>> fbs = std::make_shared<std::map<std::string,std::vector<std::string>>>(fallbacks_m); |
1745 | - common_templates_fallbacks[id] = fbs; |
1746 | + |
1747 | + common_templates_fallbacks[id] = fallbacks_m; |
1748 | qDebug() << "==== load FALLB size 1: " << common_templates_fallbacks.size(); |
1749 | - for (auto t : common_templates_fallbacks) |
1750 | + for (const auto & t : common_templates_fallbacks) |
1751 | { |
1752 | qDebug() << "==== load FALLB template id : " << qstr(t.first); |
1753 | auto m_ptr = t.second; |
1754 | - for (auto &v : *m_ptr) |
1755 | + for (const auto & v : *m_ptr) |
1756 | { |
1757 | qDebug() << "==== load FALLB c_t_f result component " << qstr(v.first); |
1758 | - for (auto f : v.second) |
1759 | + for (const auto & f : v.second) |
1760 | { |
1761 | qDebug() << "==== load FALLB c_t_f result fallback " << qstr(f); |
1762 | } |
1763 | @@ -211,15 +138,14 @@ |
1764 | } |
1765 | } |
1766 | } |
1767 | - QJsonObject departments_o = doc_o["departments"].toObject(); |
1768 | - if (doc_o.contains("departments")) |
1769 | + if (root.contains(QStringLiteral("departments"))) |
1770 | { |
1771 | - QJsonObject departments_o = doc_o["departments"].toObject(); |
1772 | + QJsonObject departments_o = root[QStringLiteral("departments")].toObject(); |
1773 | |
1774 | bool use_depts = false; |
1775 | - if (departments_o.contains("do_not_use_departments")) |
1776 | + if (departments_o.contains(QStringLiteral("do_not_use_departments"))) |
1777 | { |
1778 | - if (departments_o["do_not_use_departments"].toString() != "true") |
1779 | + if (departments_o[QStringLiteral("do_not_use_departments")].toString() != "true") |
1780 | { |
1781 | using_departments = true; |
1782 | use_depts = true; |
1783 | @@ -231,446 +157,435 @@ |
1784 | } |
1785 | if (use_depts) |
1786 | { |
1787 | - QJsonArray declarations_a = departments_o["declarations"].toArray(); |
1788 | - for (const auto item_ : declarations_a) |
1789 | + QJsonArray declarations_a = departments_o[QStringLiteral("declarations")].toArray(); |
1790 | + for (const auto & item_ : declarations_a) |
1791 | { |
1792 | - dept d_; |
1793 | - std::shared_ptr<dept> dept_ = std::make_shared<dept>(d_); |
1794 | + auto dept_ptr = std::make_shared<dept>(); |
1795 | QJsonObject dept_o = item_.toObject(); |
1796 | - dept_->id = dept_o["id"].toString().toStdString(); |
1797 | - dept_->title = _(dept_o["_title"].toString().toStdString().c_str()); |
1798 | - if (dept_o.contains("root")) |
1799 | + dept_ptr->id = dept_o[QStringLiteral("id")].toString().toStdString(); |
1800 | + dept_ptr->title = _(dept_o[QStringLiteral("_title")].toString().toStdString().c_str()); |
1801 | + if (dept_o.contains(QStringLiteral("root"))) |
1802 | { |
1803 | - if (dept_o["root"].toString() == "true") |
1804 | + if (dept_o[QStringLiteral("root")].toString() == TRUE) |
1805 | { |
1806 | - dept_->root = true; |
1807 | - dept_id_of_root = dept_->id; |
1808 | + dept_ptr->root = true; |
1809 | + dept_id_of_root = dept_ptr->id; |
1810 | } |
1811 | } |
1812 | - depts[dept_->id] = dept_; |
1813 | + depts[dept_ptr->id] = dept_ptr; |
1814 | } |
1815 | } |
1816 | } |
1817 | - QJsonArray order_a = doc_o["order"].toArray(); |
1818 | + QJsonArray order_a = root[QStringLiteral("order")].toArray(); |
1819 | |
1820 | - for (const auto item_o_ : order_a) |
1821 | + for (const auto & item_o_ : order_a) |
1822 | { |
1823 | QJsonObject item_o = item_o_.toObject(); |
1824 | |
1825 | - if (item_o.contains("category")) |
1826 | + if (item_o.contains(QStringLiteral("category"))) |
1827 | { |
1828 | - QJsonObject cat_o = item_o["category"].toObject(); |
1829 | - category cat_; |
1830 | - std::shared_ptr<category> cat = std::make_shared<category>(cat_); |
1831 | - cat->id = cat_o["id"].toString().toStdString(); |
1832 | - |
1833 | - cat->title = cat_o["_title"].toString().toStdString(); |
1834 | - cat->dept_id = cat_o["department"].toString().toStdString(); |
1835 | - |
1836 | - categoryId_titleMsgid[cat->id] = cat->title; |
1837 | - categoryIds.emplace_back(cat->id); |
1838 | - |
1839 | - if (cat_o.contains("link_to_child_specified")) |
1840 | + QJsonObject cat_o = item_o[QStringLiteral("category")].toObject(); |
1841 | + std::shared_ptr<category> cat_ptr = std::make_shared<category>(); |
1842 | + cat_ptr->id = cat_o[QStringLiteral("id")].toString().toStdString(); |
1843 | + |
1844 | + cat_ptr->title = cat_o[QStringLiteral("_title")].toString().toStdString(); |
1845 | + cat_ptr->dept_id = cat_o[QStringLiteral("department")].toString().toStdString(); |
1846 | + |
1847 | + categoryId_titleMsgid[cat_ptr->id] = cat_ptr->title; |
1848 | + categoryIds.emplace_back(cat_ptr->id); |
1849 | + |
1850 | + if (cat_o.contains(QStringLiteral("link_to_child_specified"))) |
1851 | { |
1852 | - categoryId_linkToChildSpecified[cat->id] = cat_o["link_to_child_specified"].toString().toStdString(); |
1853 | + categoryId_linkToChildSpecified[cat_ptr->id] = cat_o[QStringLiteral("link_to_child_specified")].toString().toStdString(); |
1854 | } |
1855 | - int card = get_setting_cardinality(); |
1856 | + int card = get_cardinality_setting(); |
1857 | if (card > 0) |
1858 | { |
1859 | - cat->cardinality = card; |
1860 | + cat_ptr->cardinality = card; |
1861 | } |
1862 | // but let declaration for category override user settings |
1863 | - if (cat_o.contains("cardinality")) |
1864 | + if (cat_o.contains(QStringLiteral("cardinality"))) |
1865 | { |
1866 | - int cardinality_ = cat_o["cardinality"].toInt(); |
1867 | - if (cardinality_ > -1 ) |
1868 | + int cardinality_ = cat_o[QStringLiteral("cardinality")].toInt(); |
1869 | + if (cardinality_ > -1) |
1870 | { |
1871 | - cat->cardinality = cardinality_; |
1872 | + cat_ptr->cardinality = cardinality_; |
1873 | } |
1874 | } |
1875 | - qDebug() << "=== CAT UTILs. id: " << qstr(cat->id) << " cardinality: " << QString::number(cat->cardinality); |
1876 | + qDebug() << "=== CAT UTILs. id: " << qstr(cat_ptr->id) << " cardinality: " << QString::number(cat_ptr->cardinality); |
1877 | |
1878 | - if (cat_o.contains("first_result_renderer_common_id")) |
1879 | + if (cat_o.contains(QStringLiteral("first_result_renderer_common_id"))) |
1880 | { |
1881 | - std::string id = cat_o["first_result_renderer_common_id"].toString().toStdString(); |
1882 | - categoryId_first_result_renderers[cat->id] = common_templates[id]; |
1883 | - categoryId_firstRdrs_catId2commonId[cat->id] = id; |
1884 | + std::string id = cat_o[QStringLiteral("first_result_renderer_common_id")].toString().toStdString(); |
1885 | + categoryId_first_result_renderers[cat_ptr->id] = common_templates[id]; |
1886 | + categoryId_firstRdrs_catId2commonId[cat_ptr->id] = id; |
1887 | } |
1888 | - else if (cat_o.contains("first_result_renderer")) |
1889 | + else if (cat_o.contains(QStringLiteral("first_result_renderer"))) |
1890 | { |
1891 | - QJsonObject template_o = cat_o["first_result_renderer"].toObject(); |
1892 | + QJsonObject template_o = cat_o[QStringLiteral("first_result_renderer")].toObject(); |
1893 | QJsonDocument t_d(template_o); |
1894 | - categoryId_first_result_renderers[cat->id] = sstr(t_d.toJson()); |
1895 | + categoryId_first_result_renderers[cat_ptr->id] = sstr(t_d.toJson()); |
1896 | } |
1897 | - else if (cat_o.contains("first_result_template")) |
1898 | + else if (cat_o.contains(QStringLiteral("first_result_template"))) |
1899 | { |
1900 | //support deprecated for backwards compatibiliity |
1901 | - qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'").arg(qstr(scope_id)); |
1902 | - QJsonObject template_o = cat_o["first_result_template"].toObject(); |
1903 | + qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'") |
1904 | + .arg(qstr(agg_scope_->scope_id())); |
1905 | + QJsonObject template_o = cat_o[QStringLiteral("first_result_template")].toObject(); |
1906 | QJsonDocument t_d(template_o); |
1907 | - categoryId_first_result_renderers[cat->id] = sstr(t_d.toJson()); |
1908 | + categoryId_first_result_renderers[cat_ptr->id] = sstr(t_d.toJson()); |
1909 | } |
1910 | |
1911 | - if (cat_o.contains("renderer_common_id")) |
1912 | + if (cat_o.contains(QStringLiteral("renderer_common_id"))) |
1913 | { |
1914 | - std::string id = cat_o["renderer_common_id"].toString().toStdString(); |
1915 | - cat->renderer = common_templates[id]; |
1916 | - categoryId_surfaceRdrs_catId2commonId[cat->id] = id; |
1917 | + std::string id = cat_o[QStringLiteral("renderer_common_id")].toString().toStdString(); |
1918 | + cat_ptr->renderer = common_templates[id]; |
1919 | + categoryId_surfaceRdrs_catId2commonId[cat_ptr->id] = id; |
1920 | } |
1921 | - else if (cat_o.contains("renderer")) |
1922 | + else if (cat_o.contains(QStringLiteral("renderer"))) |
1923 | { |
1924 | - QJsonObject renderer_o = cat_o["renderer"].toObject(); |
1925 | + QJsonObject renderer_o = cat_o[QStringLiteral("renderer")].toObject(); |
1926 | QJsonDocument st_d(renderer_o); |
1927 | - cat->renderer = sstr(st_d.toJson()); |
1928 | + cat_ptr->renderer = sstr(st_d.toJson()); |
1929 | } |
1930 | |
1931 | - if (cat_o.contains("search_renderer_common_id")) |
1932 | + if (cat_o.contains(QStringLiteral("search_renderer_common_id"))) |
1933 | { |
1934 | qDebug() << "==== UTILs. load. CATRES. search_renderer_common_id"; |
1935 | - std::string id = cat_o["search_renderer_common_id"].toString().toStdString(); |
1936 | - cat->search_renderer = common_templates[id]; |
1937 | + std::string id = cat_o[QStringLiteral("search_renderer_common_id")].toString().toStdString(); |
1938 | + cat_ptr->search_renderer = common_templates[id]; |
1939 | } |
1940 | - else if (cat_o.contains("search_renderer")) |
1941 | + else if (cat_o.contains(QStringLiteral("search_renderer"))) |
1942 | { |
1943 | qDebug() << "==== UTILs. load. CATRES. search_renderer"; |
1944 | - QJsonObject renderer_o = cat_o["search_renderer"].toObject(); |
1945 | + QJsonObject renderer_o = cat_o[QStringLiteral("search_renderer")].toObject(); |
1946 | QJsonDocument st_d(renderer_o); |
1947 | - cat->search_renderer = sstr(st_d.toJson()); |
1948 | + cat_ptr->search_renderer = sstr(st_d.toJson()); |
1949 | } |
1950 | |
1951 | - if (cat_o.contains("scopes")) |
1952 | + if (cat_o.contains(QStringLiteral("scopes"))) |
1953 | { |
1954 | - QJsonArray scope_a = cat_o["scopes"].toArray(); |
1955 | + QJsonArray scope_a = cat_o[QStringLiteral("scopes")].toArray(); |
1956 | |
1957 | for (const auto item : scope_a) |
1958 | { |
1959 | QJsonObject scope_o = item.toObject(); |
1960 | - std::string id = scope_o["id"].toString().toStdString(); |
1961 | - std::string local_id = scope_o["local_id"].toString().toStdString(); |
1962 | + std::string id = scope_o[QStringLiteral("id")].toString().toStdString(); |
1963 | + std::string local_id = scope_o[QStringLiteral("local_id")].toString().toStdString(); |
1964 | |
1965 | //TODO doc that a child_department may include LANGCODE for replacement |
1966 | //from locale lang code, and COUNTRYCODE with locale country code |
1967 | - if (scope_o.contains("child_department")) |
1968 | + if (scope_o.contains(QStringLiteral("child_department"))) |
1969 | { |
1970 | - QString child_dept = scope_o["child_department"].toString(); |
1971 | - if (lang.size() == 2) |
1972 | - { |
1973 | - if (child_dept.contains("LANGCODE")) |
1974 | - child_dept = child_dept.replace("LANGCODE", lang); |
1975 | - scopeLocalId_childDept_m[local_id] = child_dept.toStdString(); |
1976 | - } |
1977 | - if (country.size() == 2) |
1978 | - { |
1979 | + QString child_dept = scope_o[QStringLiteral("child_department")].toString(); |
1980 | |
1981 | - if (child_dept.contains("COUNTRYCODE")) |
1982 | - child_dept = child_dept.replace("COUNTRYCODE", country); |
1983 | - scopeLocalId_childDept_m[local_id] = child_dept.toStdString(); |
1984 | - } |
1985 | - qDebug() << qstr("=== CHDEPT. lang: %1 local %2. dept %3").arg(lang, qstr(local_id), qstr(scopeLocalId_childDept_m[local_id])); |
1986 | + if (agg_scope_->lang().size() == 2 && child_dept.contains(QStringLiteral("LANGCODE"))) |
1987 | + { |
1988 | + child_dept = child_dept.replace(QStringLiteral("LANGCODE"), qstr(agg_scope_->lang())); |
1989 | + scopeLocalId_childDept_m[local_id] = child_dept.toStdString(); |
1990 | + } |
1991 | + if (agg_scope_->country().size() == 2 && child_dept.contains(QStringLiteral("COUNTRYCODE"))) |
1992 | + { |
1993 | + child_dept = child_dept.replace(QStringLiteral("COUNTRYCODE"), qstr(agg_scope_->country())); |
1994 | + scopeLocalId_childDept_m[local_id] = child_dept.toStdString(); |
1995 | + } |
1996 | + qDebug() << qstr("=== CHDEPT. lang: %1 local %2. dept %3").arg(qstr(agg_scope_->lang()), |
1997 | + qstr(local_id), qstr(scopeLocalId_childDept_m[local_id])); |
1998 | } |
1999 | - if (scope_o.contains("default_query_string")) |
2000 | + if (scope_o.contains(QStringLiteral("default_query_string"))) |
2001 | { |
2002 | |
2003 | - std::string default_qry_str = scope_o["default_query_string"].toString().toStdString(); |
2004 | + std::string default_qry_str = scope_o[QStringLiteral("default_query_string")].toString().toStdString(); |
2005 | localId_defaultQryStr[local_id] = default_qry_str; |
2006 | } |
2007 | |
2008 | - cat->scopes.emplace_back(std::pair<std::string,std::string>(id,local_id)); |
2009 | + cat_ptr->scopes.emplace_back(std::pair<std::string,std::string>(id,local_id)); |
2010 | } |
2011 | } |
2012 | - if (cat_o.contains("keywords")) |
2013 | + if (cat_o.contains(QStringLiteral("keywords"))) |
2014 | { |
2015 | - QJsonArray keyword_a = cat_o["keywords"].toArray(); |
2016 | + QJsonArray keyword_a = cat_o[QStringLiteral("keywords")].toArray(); |
2017 | |
2018 | - for (const auto item : keyword_a) |
2019 | + for (const auto & item : keyword_a) |
2020 | { |
2021 | QJsonObject keyword_o = item.toObject(); |
2022 | - std::string id = keyword_o["id"].toString().toStdString(); |
2023 | - std::string local_id = keyword_o["local_id"].toString().toStdString(); |
2024 | - cat->keywords.emplace_back(id); |
2025 | - cat->keyword_ids.emplace_back(std::pair<std::string,std::string>(id,local_id)); |
2026 | + std::string id = keyword_o[QStringLiteral("id")].toString().toStdString(); |
2027 | + std::string local_id = keyword_o[QStringLiteral("local_id")].toString().toStdString(); |
2028 | + cat_ptr->keywords.emplace_back(id); |
2029 | + cat_ptr->keyword_ids.emplace_back(std::pair<std::string,std::string>(id,local_id)); |
2030 | declared_category_keywords.emplace_back(id); |
2031 | } |
2032 | } |
2033 | |
2034 | - declared_order.emplace_back(cat->id); |
2035 | - categories.emplace_back(cat); |
2036 | - id_category_m[cat->id] = cat; |
2037 | + declared_order.emplace_back(cat_ptr->id); |
2038 | + categories.emplace_back(cat_ptr); |
2039 | + id_category_m[cat_ptr->id] = cat_ptr; |
2040 | } // end "category" |
2041 | |
2042 | - if (item_o.contains("scope")) |
2043 | + if (item_o.contains(QStringLiteral("scope"))) |
2044 | { |
2045 | - QJsonObject scope_o = item_o["scope"].toObject(); |
2046 | - child_scope cs_; |
2047 | - std::shared_ptr<child_scope> cs = std::make_shared<child_scope>(cs_); |
2048 | - |
2049 | - cs->id = scope_o["id"].toString().toStdString(); |
2050 | - cs->local_id = scope_o["local_id"].toString().toStdString(); |
2051 | + QJsonObject scope_o = item_o[QStringLiteral("scope")].toObject(); |
2052 | + std::shared_ptr<child_scope> cs = std::make_shared<child_scope>(); |
2053 | + cs->id = scope_o[QStringLiteral("id")].toString().toStdString(); |
2054 | + cs->local_id = scope_o[QStringLiteral("local_id")].toString().toStdString(); |
2055 | declared_order.emplace_back(cs->local_id); |
2056 | |
2057 | - if (scope_o.contains("department")) |
2058 | - cs->department = scope_o["department"].toString().toStdString(); |
2059 | + if (scope_o.contains(QStringLiteral("department"))) |
2060 | + cs->department = scope_o[QStringLiteral("department")].toString().toStdString(); |
2061 | |
2062 | - if (scope_o.contains("link_to_child")) |
2063 | + cs->link_to_child = true; |
2064 | + if (scope_o.contains(QStringLiteral("link_to_child"))) |
2065 | { |
2066 | - if (scope_o["link_to_child"].toString() == "false") |
2067 | + if (scope_o[QStringLiteral("link_to_child")].toString() == FALSE) |
2068 | cs->link_to_child = false; |
2069 | } |
2070 | - else |
2071 | - { |
2072 | - cs->link_to_child = true; |
2073 | - } |
2074 | - |
2075 | - if (scope_o.contains("source_finder")) |
2076 | - { |
2077 | - if (scope_o["source_finder"].toString() == "true") { |
2078 | - cs->source_finder = true; |
2079 | - } |
2080 | - } |
2081 | - |
2082 | - if (scope_o.contains("category_title_use_incoming")) |
2083 | + |
2084 | + cs->source_finder = false; |
2085 | + if (scope_o.contains(QStringLiteral("source_finder")) |
2086 | + && scope_o[QStringLiteral("source_finder")].toString() == TRUE) { |
2087 | + cs->source_finder = true; |
2088 | + } |
2089 | + |
2090 | + if (scope_o.contains(QStringLiteral("category_title_use_incoming"))) |
2091 | { |
2092 | cs->using_category_title_incoming = true; |
2093 | } |
2094 | - else if (scope_o.contains("category_title_use_display_name")) |
2095 | + else if (scope_o.contains(QStringLiteral("category_title_use_display_name"))) |
2096 | { |
2097 | cs->using_category_title_display_name = true; |
2098 | } |
2099 | else |
2100 | { |
2101 | - if (scope_o.contains("category_title")) |
2102 | - cs->category_title = scope_o["category_title"].toString().toStdString(); |
2103 | + if (scope_o.contains(QStringLiteral("category_title"))) |
2104 | + cs->category_title = scope_o[QStringLiteral("category_title")].toString().toStdString(); |
2105 | |
2106 | - if (scope_o.contains("_category_title")) |
2107 | - cs->category_title_ = scope_o["_category_title"].toString().toStdString(); |
2108 | + if (scope_o.contains(QStringLiteral("_category_title"))) |
2109 | + cs->category_title_ = scope_o[QStringLiteral("_category_title")].toString().toStdString(); |
2110 | qDebug() << "==== TITLE_: " << qstr(cs->category_title); |
2111 | qDebug() << "==== TITLE_: " << qstr(cs->category_title_); |
2112 | } |
2113 | |
2114 | //TODO doc that a child_department may include LANGCODE for replacement |
2115 | //from locale lang code, and COUNTRYCODE with locale country code |
2116 | - if (scope_o.contains("child_department")) |
2117 | + if (scope_o.contains(QStringLiteral("child_department"))) |
2118 | { |
2119 | - QString child_dept = scope_o["child_department"].toString(); |
2120 | - if (lang.size() == 2) |
2121 | - { |
2122 | - if (child_dept.contains("LANGCODE")) |
2123 | - child_dept = child_dept.replace("LANGCODE", lang); |
2124 | - } |
2125 | - if (country.size() == 2) |
2126 | - { |
2127 | + QString child_dept = scope_o[QStringLiteral("child_department")].toString(); |
2128 | |
2129 | - if (child_dept.contains("COUNTRYCODE")) |
2130 | - child_dept = child_dept.replace("COUNTRYCODE", country); |
2131 | + if (agg_scope_->lang().size() == 2 && child_dept.contains("LANGCODE")) |
2132 | + { |
2133 | + child_dept = child_dept.replace("LANGCODE", qstr(agg_scope_->lang())); |
2134 | + } |
2135 | + if (agg_scope_->country().size() == 2 && child_dept.contains("COUNTRYCODE")) |
2136 | + { |
2137 | + child_dept = child_dept.replace("COUNTRYCODE", qstr(agg_scope_->country())); |
2138 | } |
2139 | cs->child_department = child_dept.toStdString(); |
2140 | } |
2141 | |
2142 | - if (scope_o.contains("child_category")) |
2143 | - cs->child_category = scope_o["child_category"].toString().toStdString(); |
2144 | - |
2145 | - if (scope_o.contains("child_category_max_results")) |
2146 | - { |
2147 | - cs->child_category_max_results = (int)scope_o["child_category_max_results"].toInt(); |
2148 | - cs->using_child_category_max_results = true; |
2149 | - } |
2150 | - else if (scope_o.contains("child_category")) |
2151 | - cs->using_child_category_max_results = true; |
2152 | - |
2153 | - int card = get_setting_cardinality(); |
2154 | + if (scope_o.contains(QStringLiteral("child_category"))) |
2155 | + cs->child_category = scope_o[QStringLiteral("child_category")].toString().toStdString(); |
2156 | + |
2157 | + if (scope_o.contains(QStringLiteral("child_category_max_results"))) |
2158 | + { |
2159 | + cs->child_category_max_results = scope_o[QStringLiteral("child_category_max_results")].toInt(); |
2160 | + cs->using_child_category_max_results = true; |
2161 | + } |
2162 | + else if (scope_o.contains(QStringLiteral("child_category"))) |
2163 | + { |
2164 | + cs->using_child_category_max_results = true; |
2165 | + } |
2166 | + |
2167 | + int card = get_cardinality_setting(); |
2168 | if (card > 0) |
2169 | { |
2170 | cs->cardinality = card; |
2171 | } |
2172 | // but let declaration for category override user settings |
2173 | - if (scope_o.contains("cardinality")) |
2174 | + if (scope_o.contains(QStringLiteral("cardinality"))) |
2175 | { |
2176 | - int cardinality_ = scope_o["cardinality"].toInt(); |
2177 | + int cardinality_ = scope_o[QStringLiteral("cardinality")].toInt(); |
2178 | if (cardinality_ > -1) |
2179 | { |
2180 | cs->cardinality = cardinality_; |
2181 | } |
2182 | } |
2183 | - if (scope_o.contains("first_result_renderer_common_id")) |
2184 | + if (scope_o.contains(QStringLiteral("first_result_renderer_common_id"))) |
2185 | { |
2186 | - std::string id = scope_o["first_result_renderer_common_id"].toString().toStdString(); |
2187 | + std::string id = scope_o[QStringLiteral("first_result_renderer_common_id")].toString().toStdString(); |
2188 | cs->first_result_template = common_templates[id]; |
2189 | } |
2190 | - else if (scope_o.contains("first_result_renderer")) |
2191 | + else if (scope_o.contains(QStringLiteral("first_result_renderer"))) |
2192 | { |
2193 | - QJsonObject template_o = scope_o["first_result_renderer"].toObject(); |
2194 | + QJsonObject template_o = scope_o[QStringLiteral("first_result_renderer")].toObject(); |
2195 | QJsonDocument t_d(template_o); |
2196 | cs->first_result_template = sstr(t_d.toJson()); |
2197 | } |
2198 | - else if (scope_o.contains("first_result_template")) |
2199 | + else if (scope_o.contains(QStringLiteral("first_result_template"))) |
2200 | { |
2201 | //support deprecated for backwards compatibiliity |
2202 | - qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'").arg(qstr(scope_id)); |
2203 | - QJsonObject template_o = scope_o["first_result_template"].toObject(); |
2204 | + qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'").arg(qstr(agg_scope_->scope_id())); |
2205 | + QJsonObject template_o = scope_o[QStringLiteral("first_result_template")].toObject(); |
2206 | QJsonDocument t_d(template_o); |
2207 | cs->first_result_template = sstr(t_d.toJson()); |
2208 | } |
2209 | |
2210 | - if (scope_o.contains("renderer_common_id")) |
2211 | + if (scope_o.contains(QStringLiteral("renderer_common_id"))) |
2212 | { |
2213 | - std::string id = scope_o["renderer_common_id"].toString().toStdString(); |
2214 | + std::string id = scope_o[QStringLiteral("renderer_common_id")].toString().toStdString(); |
2215 | cs->surface_template = common_templates[id]; |
2216 | cs->overriding_surface_template = true; |
2217 | } |
2218 | - else if (scope_o.contains("renderer")) |
2219 | + else if (scope_o.contains(QStringLiteral("renderer"))) |
2220 | { |
2221 | - QJsonObject surface_template_o = scope_o["renderer"].toObject(); |
2222 | + QJsonObject surface_template_o = scope_o[QStringLiteral("renderer")].toObject(); |
2223 | QJsonDocument st_d(surface_template_o); |
2224 | cs->surface_template = sstr(st_d.toJson()); |
2225 | cs->overriding_surface_template = true; |
2226 | } |
2227 | - else if (scope_o.contains("surface_template")) |
2228 | + else if (scope_o.contains(QStringLiteral("surface_template"))) |
2229 | { |
2230 | //support deprecated for backwards compatibility |
2231 | - qWarning () << QString("%1: DEPRECATED use of 'surface_template'. Switch to 'surface_renderer'").arg(qstr(scope_id)); |
2232 | - QJsonObject surface_template_o = scope_o["surface_template"].toObject(); |
2233 | + qWarning () << QString("%1: DEPRECATED use of 'surface_template'. Switch to 'surface_renderer'").arg(qstr(agg_scope_->scope_id())); |
2234 | + QJsonObject surface_template_o = scope_o[QStringLiteral("surface_template")].toObject(); |
2235 | QJsonDocument st_d(surface_template_o); |
2236 | cs->surface_template = sstr(st_d.toJson()); |
2237 | cs->overriding_surface_template = true; |
2238 | } |
2239 | |
2240 | - if (scope_o.contains("search_renderer_common_id")) |
2241 | + if (scope_o.contains(QStringLiteral("search_renderer_common_id"))) |
2242 | { |
2243 | qDebug() << "==== SEARCH red com fouund"; |
2244 | std::string id = scope_o["search_renderer_common_id"].toString().toStdString(); |
2245 | cs->search_template = common_templates[id]; |
2246 | cs->overriding_search_template = true; |
2247 | } |
2248 | - else if (scope_o.contains("search_renderer")) |
2249 | + else if (scope_o.contains(QStringLiteral("search_renderer"))) |
2250 | { |
2251 | - QJsonObject search_template_o = scope_o["search_renderer"].toObject(); |
2252 | + QJsonObject search_template_o = scope_o[QStringLiteral("search_renderer")].toObject(); |
2253 | QJsonDocument search_d(search_template_o); |
2254 | cs->search_template = sstr(search_d.toJson()); |
2255 | cs->overriding_search_template = true; |
2256 | } |
2257 | - else if (scope_o.contains("search_template")) |
2258 | + else if (scope_o.contains(QStringLiteral("search_template"))) |
2259 | { |
2260 | //support deprecated for backwards compatibility |
2261 | - qWarning () << QString("%1: DEPRECATED use of 'search_template'. Switch to 'search_renderer'").arg(qstr(scope_id)); |
2262 | - QJsonObject search_template_o = scope_o["search_template"].toObject(); |
2263 | + qWarning () << QString("%1: DEPRECATED use of 'search_template'. Switch to 'search_renderer'").arg(qstr(agg_scope_->scope_id())); |
2264 | + QJsonObject search_template_o = scope_o[QStringLiteral("search_template")].toObject(); |
2265 | QJsonDocument search_d(search_template_o); |
2266 | cs->search_template = sstr(search_d.toJson()); |
2267 | cs->overriding_search_template = true; |
2268 | } |
2269 | |
2270 | - if (scope_o.contains("swap_result_attributes")) |
2271 | + if (scope_o.contains(QStringLiteral("swap_result_attributes"))) |
2272 | { |
2273 | - QJsonArray swaps_a = scope_o["swap_result_attributes"].toArray(); |
2274 | - for (const auto swap_o_ : swaps_a) |
2275 | + QJsonArray swaps_a = scope_o[QStringLiteral("swap_result_attributes")].toArray(); |
2276 | + for (const auto & swap_o_ : swaps_a) |
2277 | { |
2278 | QJsonObject swap_o = swap_o_.toObject(); |
2279 | - std::pair<std::string,std::string> swap; |
2280 | - swap.first = swap_o["incoming_result_key"].toString().toStdString(); |
2281 | - swap.second = swap_o["new_result_key"].toString().toStdString(); |
2282 | - std::shared_ptr<std::pair<std::string,std::string>> swap_ = std::make_shared<std::pair<std::string,std::string>>(swap); |
2283 | + auto swap_ = std::make_shared<std::pair<std::string,std::string>>(); |
2284 | + (*swap_).first = swap_o[QStringLiteral("incoming_result_key")].toString().toStdString(); |
2285 | + (*swap_).second = swap_o[QStringLiteral("new_result_key")].toString().toStdString(); |
2286 | cs->swap_result_attributes.emplace_back(swap_); |
2287 | } |
2288 | - |
2289 | } |
2290 | |
2291 | - if (scope_o.contains("result_category_id_to_common_template")) |
2292 | + if (scope_o.contains(QStringLiteral("result_category_id_to_common_template"))) |
2293 | { |
2294 | - QJsonArray items_a = scope_o["result_category_id_to_common_template"].toArray(); |
2295 | - for (const auto item_o_ : items_a) |
2296 | + QJsonArray items_a = scope_o[QStringLiteral("result_category_id_to_common_template")].toArray(); |
2297 | + for (const auto & item_o_ : items_a) |
2298 | { |
2299 | QJsonObject item_o = item_o_.toObject(); |
2300 | - std::string res_cat_id = item_o["result_category_id"].toString().toStdString(); |
2301 | - std::string common_template = item_o["common_template"].toString().toStdString(); |
2302 | + std::string res_cat_id = item_o[QStringLiteral("result_category_id")].toString().toStdString(); |
2303 | + std::string common_template = item_o[QStringLiteral("common_template")].toString().toStdString(); |
2304 | cs->result_category_id_to_common_template[res_cat_id] = common_template; |
2305 | } |
2306 | } |
2307 | |
2308 | - if (scope_o.contains("default_query_string")) |
2309 | + if (scope_o.contains(QStringLiteral("default_query_string"))) |
2310 | { |
2311 | - QString default_query_string = scope_o["default_query_string"].toString(); |
2312 | + QString default_query_string = scope_o[QStringLiteral("default_query_string")].toString(); |
2313 | localId_defaultQryStr[cs->local_id] = default_query_string.toStdString(); |
2314 | } |
2315 | |
2316 | - if (scope_o.contains("only_in_search") && scope_o["only_in_search"] == "true") |
2317 | + if (scope_o.contains(QStringLiteral("only_in_search")) |
2318 | + && scope_o[QStringLiteral("only_in_search")] == TRUE) |
2319 | { |
2320 | cs->only_in_search = true; |
2321 | cs->overriding_search_template = true; |
2322 | - } else { |
2323 | - cs->only_in_search = false; |
2324 | } |
2325 | |
2326 | child_scopes.emplace_back(cs); |
2327 | child_scopes_m[cs->local_id] = cs; |
2328 | type_ids_m[cs->local_id].emplace_back(cs->local_id); |
2329 | } // end "scope" |
2330 | - else if (item_o.contains("keyword")) |
2331 | + else if (item_o.contains(QStringLiteral("keyword"))) |
2332 | { |
2333 | - keyword keyword_; |
2334 | - QJsonObject keyword_o = item_o["keyword"].toObject(); |
2335 | - std::string keyword_id = keyword_o["keyword"].toString().toStdString(); |
2336 | - keyword_.id = keyword_id; |
2337 | + auto keyword_ = std::make_shared<keyword>(); |
2338 | + QJsonObject keyword_o = item_o[QStringLiteral("keyword")].toObject(); |
2339 | + std::string keyword_id = keyword_o[QStringLiteral("keyword")].toString().toStdString(); |
2340 | + keyword_->id = keyword_id; |
2341 | |
2342 | declared_keywords.emplace_back(keyword_id); |
2343 | declared_order.emplace_back(keyword_id); |
2344 | |
2345 | - int card = get_setting_cardinality(); |
2346 | + int card = get_cardinality_setting(); |
2347 | if (card > 0) |
2348 | { |
2349 | - keyword_.cardinality = card; |
2350 | + keyword_->cardinality = card; |
2351 | } |
2352 | // but let declaration for category override user settings |
2353 | - if (keyword_o.contains("cardinality")) |
2354 | + if (keyword_o.contains(QStringLiteral("cardinality"))) |
2355 | { |
2356 | - int keyword_cardinality_ = keyword_o["cardinality"].toInt(); |
2357 | + int keyword_cardinality_ = keyword_o[QStringLiteral("cardinality")].toInt(); |
2358 | if (keyword_cardinality_ > -1) |
2359 | { |
2360 | - keyword_.cardinality = keyword_cardinality_; |
2361 | + keyword_->cardinality = keyword_cardinality_; |
2362 | } |
2363 | } |
2364 | if (using_departments) |
2365 | { |
2366 | - std::string dept_title_msgid = keyword_o["_department_title"].toString().toStdString(); |
2367 | + std::string dept_title_msgid = keyword_o[QStringLiteral("_department_title")].toString().toStdString(); |
2368 | keyword_deptTitleMsgid[keyword_id] = dept_title_msgid; |
2369 | - if (keyword_o.contains("department")) |
2370 | + if (keyword_o.contains(QStringLiteral("department"))) |
2371 | { |
2372 | - |
2373 | - std::string kwdept = keyword_o["department"].toString().toStdString(); |
2374 | + std::string kwdept = keyword_o[QStringLiteral("department")].toString().toStdString(); |
2375 | keyword_deptId[keyword_id] = kwdept; |
2376 | - keyword_.dept_id = kwdept; |
2377 | + keyword_->dept_id = kwdept; |
2378 | } |
2379 | else if (dept_id_of_root_keywords_only.empty()) |
2380 | dept_id_of_root_keywords_only = keyword_id; |
2381 | } |
2382 | std::string category; |
2383 | - if (keyword_o.contains("shared_category")) |
2384 | + if (keyword_o.contains(QStringLiteral("shared_category"))) |
2385 | { |
2386 | category = keyword_id; // note category is synomous with keyword and is therefore used even when not shared category |
2387 | //note: removed support for shared_category value other than "true" |
2388 | - if (keyword_o["shared_category"] == "true") |
2389 | + if (keyword_o[QStringLiteral("shared_category")] == TRUE) |
2390 | { |
2391 | - std::string title_msgid = keyword_o["_shared_category_title"].toString().toStdString(); |
2392 | + std::string title_msgid = keyword_o[QStringLiteral("_shared_category_title")].toString().toStdString(); |
2393 | shared_keyword_cat_titlemsgid[category] = title_msgid; |
2394 | shared_keyword_cats[keyword_id] = category; |
2395 | shared_keywords.emplace_back(keyword_id); |
2396 | } |
2397 | } |
2398 | //we do not support first result with non shared category keyword scopes |
2399 | - if (category == keyword_id && keyword_o.contains("first_result_renderer_common_id")) |
2400 | + if (category == keyword_id && keyword_o.contains(QStringLiteral("first_result_renderer_common_id"))) |
2401 | { |
2402 | - std::string id = keyword_o["first_result_renderer_common_id"].toString().toStdString(); |
2403 | + std::string id = keyword_o[QStringLiteral("first_result_renderer_common_id")].toString().toStdString(); |
2404 | keyword_catname_first_result_renderers[category] = common_templates[id]; |
2405 | } |
2406 | - else if (category == keyword_id && keyword_o.contains("first_result_renderer")) |
2407 | + else if (category == keyword_id && keyword_o.contains(QStringLiteral("first_result_renderer"))) |
2408 | { |
2409 | - QJsonObject template_o = keyword_o["first_result_renderer"].toObject(); |
2410 | + QJsonObject template_o = keyword_o[QStringLiteral("first_result_renderer")].toObject(); |
2411 | QJsonDocument t_d(template_o); |
2412 | keyword_catname_first_result_renderers[category] = sstr(t_d.toJson()); |
2413 | } |
2414 | - else if (category == keyword_id && keyword_o.contains("first_result_template")) |
2415 | + else if (category == keyword_id && keyword_o.contains(QStringLiteral("first_result_template"))) |
2416 | { |
2417 | //support deprecated for backwards compatibiliity |
2418 | - qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'").arg(qstr(scope_id)); |
2419 | - QJsonObject template_o = keyword_o["first_result_template"].toObject(); |
2420 | + qWarning () << QString("%1: DEPRECATED use of 'first_result_template'. Switch to 'first_result_renderer'") |
2421 | + .arg(qstr(agg_scope_->scope_id())); |
2422 | + QJsonObject template_o = keyword_o[QStringLiteral("first_result_template")].toObject(); |
2423 | QJsonDocument t_d(template_o); |
2424 | keyword_catname_first_result_renderers[category] = sstr(t_d.toJson()); |
2425 | } |
2426 | @@ -679,78 +594,76 @@ |
2427 | //is the same as with a declared scope, which means "renderer_common_id", "renderer", |
2428 | //"first_result_renderer_common_id", "first_result_renderer", "search_renderer_common_id", |
2429 | //and "search_renderer" |
2430 | - if (keyword_o.contains("renderer_common_id")) |
2431 | + if (keyword_o.contains(QStringLiteral("renderer_common_id"))) |
2432 | { |
2433 | qDebug() << "==== UTILs. load. KW CAT. renderer_common_id. keyword&category: " << qstr(category);; |
2434 | - std::string id = keyword_o["renderer_common_id"].toString().toStdString(); |
2435 | + std::string id = keyword_o[QStringLiteral("renderer_common_id")].toString().toStdString(); |
2436 | keyword_catname_renderer[category] = common_templates[id]; |
2437 | |
2438 | qDebug() << "==== UTILs. load. KW CAT. renderer_common_id: "<< qstr(keyword_catname_renderer[category]).replace("\n", " "); |
2439 | } |
2440 | - else if (keyword_o.contains("renderer")) |
2441 | + else if (keyword_o.contains(QStringLiteral("renderer"))) |
2442 | { |
2443 | qDebug() << "==== UTILs. load. KW CAT. renderer"; |
2444 | - QJsonObject renderer_o = keyword_o["renderer"].toObject(); |
2445 | + QJsonObject renderer_o = keyword_o[QStringLiteral("renderer")].toObject(); |
2446 | QJsonDocument rdr_d(renderer_o); |
2447 | keyword_catname_renderer[category] = sstr(rdr_d.toJson()); |
2448 | |
2449 | qDebug() << "==== UTILs. load. KW CAT. renderer:" << qstr(keyword_catname_renderer[category]).replace("\n", " "); |
2450 | } |
2451 | - else if (keyword_o.contains("category_renderer_common_id")) |
2452 | + else if (keyword_o.contains(QStringLiteral("category_renderer_common_id"))) |
2453 | { |
2454 | qDebug() << "==== UTILs. load. KW SHARED CAT. category_renderer_common_id"; |
2455 | - std::string id = keyword_o["category_renderer_common_id"].toString().toStdString(); |
2456 | + std::string id = keyword_o[QStringLiteral("category_renderer_common_id")].toString().toStdString(); |
2457 | keyword_catname_renderer[category] = common_templates[id]; |
2458 | } |
2459 | - else if (keyword_o.contains("category_renderer")) |
2460 | + else if (keyword_o.contains(QStringLiteral("category_renderer"))) |
2461 | { |
2462 | qDebug() << "==== UTILs. load. KW CAT. category_renderer"; |
2463 | - QJsonObject renderer_o = keyword_o["category_renderer"].toObject(); |
2464 | + QJsonObject renderer_o = keyword_o[QStringLiteral("category_renderer")].toObject(); |
2465 | QJsonDocument rdr_d(renderer_o); |
2466 | keyword_catname_renderer[category] = sstr(rdr_d.toJson()); |
2467 | } |
2468 | - if (keyword_o.contains("search_renderer_common_id")) |
2469 | + if (keyword_o.contains(QStringLiteral("search_renderer_common_id"))) |
2470 | { |
2471 | - std::string id = keyword_o["search_renderer_common_id"].toString().toStdString(); |
2472 | + std::string id = keyword_o[QStringLiteral("search_renderer_common_id")].toString().toStdString(); |
2473 | keyword_catname_search_renderer[category] = common_templates[id]; |
2474 | } |
2475 | - else if (keyword_o.contains("search_renderer")) |
2476 | + else if (keyword_o.contains(QStringLiteral("search_renderer"))) |
2477 | { |
2478 | - QJsonObject renderer_o = keyword_o["search_renderer"].toObject(); |
2479 | + QJsonObject renderer_o = keyword_o[QStringLiteral("search_renderer")].toObject(); |
2480 | QJsonDocument rdr_d(renderer_o); |
2481 | keyword_catname_search_renderer[category] = sstr(rdr_d.toJson()); |
2482 | } |
2483 | - if (keyword_o.contains("link_to_child")) |
2484 | - { |
2485 | - if (keyword_o["link_to_child"].toString() == "true") |
2486 | - keyword_.link_to_child = true; |
2487 | - } |
2488 | - if (keyword_o.contains("exclude_scopes")) |
2489 | - { |
2490 | - QJsonArray scope_a = keyword_o["exclude_scopes"].toArray(); |
2491 | - |
2492 | - for (const auto item : scope_a) |
2493 | - { |
2494 | - QJsonObject scope_o = item.toObject(); |
2495 | - std::string id = scope_o["id"].toString().toStdString(); |
2496 | - keyword_.exclude_scopes.emplace_back(id); |
2497 | - } |
2498 | - } |
2499 | - if (keyword_o.contains("display_order")) |
2500 | - { |
2501 | - QJsonArray scope_a = keyword_o["display_order"].toArray(); |
2502 | - |
2503 | - for (const auto item : scope_a) |
2504 | - { |
2505 | - QJsonObject scope_o = item.toObject(); |
2506 | - std::string id = scope_o["id"].toString().toStdString(); |
2507 | - keyword_.display_order.emplace_back(id); |
2508 | - } |
2509 | - } |
2510 | - |
2511 | - std::shared_ptr<keyword> kw_ptr = std::make_shared<keyword>(keyword_); |
2512 | - keywords.emplace_back(kw_ptr); |
2513 | - id_keyword_map[keyword_id] = kw_ptr; |
2514 | + if (keyword_o.contains(QStringLiteral("link_to_child")) |
2515 | + && keyword_o[QStringLiteral("link_to_child")].toString() == TRUE) { |
2516 | + keyword_->link_to_child = true; |
2517 | + } |
2518 | + if (keyword_o.contains(QStringLiteral("exclude_scopes"))) |
2519 | + { |
2520 | + QJsonArray scope_a = keyword_o[QStringLiteral("exclude_scopes")].toArray(); |
2521 | + |
2522 | + for (const auto & item : scope_a) |
2523 | + { |
2524 | + QJsonObject scope_o = item.toObject(); |
2525 | + std::string id = scope_o[QStringLiteral("id")].toString().toStdString(); |
2526 | + keyword_->exclude_scopes.emplace_back(id); |
2527 | + } |
2528 | + } |
2529 | + if (keyword_o.contains(QStringLiteral("display_order"))) |
2530 | + { |
2531 | + QJsonArray scope_a = keyword_o[QStringLiteral("display_order")].toArray(); |
2532 | + |
2533 | + for (const auto & item : scope_a) |
2534 | + { |
2535 | + QJsonObject scope_o = item.toObject(); |
2536 | + std::string id = scope_o[QStringLiteral("id")].toString().toStdString(); |
2537 | + keyword_->display_order.emplace_back(id); |
2538 | + } |
2539 | + } |
2540 | + |
2541 | + keywords.emplace_back(keyword_); |
2542 | + id_keyword_map[keyword_id] = keyword_; |
2543 | } |
2544 | } |
2545 | //for (auto str : declared_order) |
2546 | @@ -762,12 +675,12 @@ |
2547 | for (std::string id : declared_order) |
2548 | { |
2549 | //qDebug() << "==== SET ORDER. DECLARED order id: " << qstr(id); |
2550 | - for (auto pr : type_ids_m) |
2551 | + for (const auto & pr : type_ids_m) |
2552 | { |
2553 | if (pr.first == id) |
2554 | { |
2555 | bool foundKeyword = false; |
2556 | - for (auto kwv : keywords) |
2557 | + for (const auto & kwv : keywords) |
2558 | { |
2559 | if (id == kwv->id) |
2560 | { |
2561 | @@ -777,7 +690,7 @@ |
2562 | std::vector<std::string>::iterator orderIter; |
2563 | std::vector<std::string> order_keyscopes; |
2564 | std::vector<std::string> unorder_keyscopes; |
2565 | - for (std::string scope_id : pr.second) |
2566 | + for (const auto & scope_id : pr.second) |
2567 | { |
2568 | bool foundScope = false; |
2569 | for (int i = 0; i < (int)kwv->display_order.size() ; i++) |
2570 | @@ -822,7 +735,7 @@ |
2571 | |
2572 | if (!foundKeyword) |
2573 | { |
2574 | - for (auto id_ : pr.second) |
2575 | + for (const auto & id_ : pr.second) |
2576 | { |
2577 | scopes_ordered.emplace_back(id_); |
2578 | qDebug() << "==== SET ORDER DECLARED adding to scopes_ordered id: " << qstr(id_); |
2579 | @@ -831,7 +744,7 @@ |
2580 | } |
2581 | } |
2582 | } |
2583 | - for(auto sc : scopes_ordered) { |
2584 | + for(const auto & sc : scopes_ordered) { |
2585 | qDebug() << "==== FINAL ORDER: " << qstr(sc); |
2586 | } |
2587 | } |
2588 | @@ -846,102 +759,104 @@ |
2589 | //iterate declared child scopes |
2590 | for (std::shared_ptr<child_scope> child : child_scopes) |
2591 | { |
2592 | - AggChildScope ch(child->id); |
2593 | - |
2594 | - ch.set_local_id(child->local_id); |
2595 | + auto ch_ptr = std::make_shared<AggChildScope>(child->id); |
2596 | + ch_ptr->set_local_id(child->local_id); |
2597 | |
2598 | localId_id_m[child->local_id] = child->id; |
2599 | |
2600 | if (child->using_category_title_incoming) |
2601 | { |
2602 | - ch.set_category_title_incoming(true); |
2603 | + ch_ptr->set_category_title_incoming(true); |
2604 | } |
2605 | else if (child->using_category_title_display_name) |
2606 | { |
2607 | - ch.set_category_title_display_name(true); |
2608 | + ch_ptr->set_category_title_display_name(true); |
2609 | } |
2610 | else |
2611 | { |
2612 | if (child->category_title_ != "") |
2613 | { |
2614 | - ch.set_category_title(_(child->category_title_.c_str())); |
2615 | + ch_ptr->set_category_title(_(child->category_title_.c_str())); |
2616 | } |
2617 | else |
2618 | - ch.set_category_title(child->category_title); |
2619 | + ch_ptr->set_category_title(child->category_title); |
2620 | } |
2621 | |
2622 | if (child->child_department != "") |
2623 | - ch.set_child_department(child->child_department); |
2624 | + ch_ptr->set_child_department(child->child_department); |
2625 | |
2626 | if (child->department != "") |
2627 | - ch.set_department(child->department); |
2628 | + ch_ptr->set_department(child->department); |
2629 | |
2630 | - ch.set_category_link_to_child(child->link_to_child); |
2631 | + ch_ptr->set_category_link_to_child(child->link_to_child); |
2632 | |
2633 | if (child->child_category != "") |
2634 | - ch.set_child_category(child->child_category); |
2635 | + ch_ptr->set_child_category(child->child_category); |
2636 | |
2637 | if (child->using_child_category_max_results) |
2638 | - ch.set_child_category_max_results(child->child_category_max_results); |
2639 | + ch_ptr->set_child_category_max_results(child->child_category_max_results); |
2640 | |
2641 | - int card = get_setting_cardinality(); |
2642 | + int card = get_cardinality_setting(); |
2643 | if (card > 0) |
2644 | - ch.set_cardinality(card); |
2645 | + ch_ptr->set_cardinality(card); |
2646 | if (child->cardinality >= -1) // let declared override user settings |
2647 | - ch.set_cardinality(child->cardinality); |
2648 | + ch_ptr->set_cardinality(child->cardinality); |
2649 | |
2650 | if (!child->first_result_template.empty()) |
2651 | - ch.set_first_result_template(child->first_result_template); |
2652 | + ch_ptr->set_first_result_template(child->first_result_template); |
2653 | |
2654 | if (child->overriding_surface_template) |
2655 | { |
2656 | - ch.set_surface_template(child->surface_template); |
2657 | + ch_ptr->set_surface_template(child->surface_template); |
2658 | } |
2659 | else |
2660 | - ch.set_override_surface_template(false); |
2661 | + { |
2662 | + ch_ptr->set_override_surface_template(false); |
2663 | + } |
2664 | |
2665 | if (child->overriding_search_template) |
2666 | { |
2667 | - ch.set_search_template(child->search_template); |
2668 | + ch_ptr->set_search_template(child->search_template); |
2669 | } |
2670 | else |
2671 | - ch.set_override_search_template(false); |
2672 | - |
2673 | - ch.set_only_in_search(child->only_in_search); |
2674 | - |
2675 | - ch.set_source_finder(child->source_finder); |
2676 | - qWarning () << QString("%1: ADDING DECLARED child scope: %2, local_id: %3").arg(qstr(scope_id), qstr(ch.id()), qstr(ch.local_id())); |
2677 | - scopes_m[ch.local_id()] = std::make_shared<AggChildScope>(ch); |
2678 | - current_scopes.emplace_back(ch.local_id()); |
2679 | - |
2680 | + { |
2681 | + ch_ptr->set_override_search_template(false); |
2682 | + } |
2683 | + |
2684 | + ch_ptr->set_only_in_search(child->only_in_search); |
2685 | + |
2686 | + ch_ptr->set_source_finder(child->source_finder); |
2687 | + qWarning () << QString("%1: ADDING DECLARED child scope: %2, local_id: %3") |
2688 | + .arg(qstr(agg_scope_->scope_id()), qstr(ch_ptr->id()), qstr(ch_ptr->local_id())); |
2689 | + scopes_m[ch_ptr->local_id()] = ch_ptr; |
2690 | + current_scopes.emplace_back(ch_ptr->local_id()); |
2691 | } |
2692 | - return; |
2693 | } |
2694 | |
2695 | void Query::create_departments(us::SearchReplyProxy const &reply_) |
2696 | { |
2697 | //create depts for declared keywords |
2698 | - for (auto item : keyword_deptTitleMsgid) |
2699 | + for (const auto & item : keyword_deptTitleMsgid) |
2700 | { |
2701 | auto iter = keyword_deptId.find(item.first); |
2702 | if (iter != keyword_deptId.end()) |
2703 | { |
2704 | continue; |
2705 | } |
2706 | - dept d; |
2707 | - d.title = _(item.second.c_str()); |
2708 | - d.id = item.first; |
2709 | - depts[d.id] = std::make_shared<dept>(d); |
2710 | + auto dept_ptr = std::make_shared<dept>(); |
2711 | + dept_ptr->title = _(item.second.c_str()); |
2712 | + dept_ptr->id = item.first; |
2713 | + depts[dept_ptr->id] = dept_ptr; |
2714 | } |
2715 | |
2716 | + if (dept_id_of_root.empty())//means no declared scopes, only keywords |
2717 | + dept_id_of_root = dept_id_of_root_keywords_only; |
2718 | + |
2719 | us::DepartmentList depts_; |
2720 | us::CannedQuery cannedQuery("aggregator"); |
2721 | - if (dept_id_of_root.empty())//means no declared scopes, only keywords |
2722 | - dept_id_of_root = dept_id_of_root_keywords_only; |
2723 | cannedQuery.set_department_id(dept_id_of_root); |
2724 | - us::Department::SPtr topDept; |
2725 | - topDept = move(us::Department::create("", cannedQuery, depts[dept_id_of_root]->title)); |
2726 | - for ( auto & item : depts) |
2727 | + us::Department::SPtr topDept = move(us::Department::create("", cannedQuery, depts[dept_id_of_root]->title)); |
2728 | + for (const auto & item : depts) |
2729 | { |
2730 | if (item.first == dept_id_of_root) |
2731 | continue; |
2732 | @@ -960,16 +875,13 @@ |
2733 | { |
2734 | for (auto const& keyword_child : current_child_scopes) |
2735 | { |
2736 | - |
2737 | if (!keyword_child.enabled) |
2738 | continue; |
2739 | - |
2740 | - |
2741 | - AggChildScope keych(keyword_child.id); |
2742 | + auto keych_ptr = std::make_shared<AggChildScope>(keyword_child.id); |
2743 | QString time_str = QDateTime::currentDateTimeUtc().toString(); |
2744 | - keych.set_keyword_scope(true); |
2745 | - dept d; |
2746 | - d.id = keyword_child.id; |
2747 | + keych_ptr->set_keyword_scope(true); |
2748 | + auto dept_ptr = std::make_shared<dept>(); |
2749 | + dept_ptr->id = keyword_child.id; |
2750 | std::string id = keyword_child.id; |
2751 | bool found = false; |
2752 | for (auto kw : declared_keywords) |
2753 | @@ -994,19 +906,21 @@ |
2754 | if (iter1 != current_scopes.end()) // don't add as keyword if already added as declared |
2755 | continue; |
2756 | |
2757 | - keych.set_local_id(keyword_child.id + ":" + kw); |
2758 | - type_ids_m[kw].emplace_back(keych.local_id()); |
2759 | - d.keyword = kw; |
2760 | - keych.set_department(kw); |
2761 | - keych.set_keyword(kw); |
2762 | - keych.set_category_link_to_child(id_keyword_map[kw]->link_to_child); |
2763 | + keych_ptr->set_local_id(keyword_child.id + ":" + kw); |
2764 | + type_ids_m[kw].emplace_back(keych_ptr->local_id()); |
2765 | + dept_ptr->keyword = kw; |
2766 | + keych_ptr->set_department(kw); |
2767 | + keych_ptr->set_keyword(kw); |
2768 | + keych_ptr->set_category_link_to_child(id_keyword_map[kw]->link_to_child); |
2769 | if (!keyword_catname_renderer[kw].empty()) |
2770 | { |
2771 | qDebug()<< "==== UTILs. adding renderer to: " << qstr(keyword_child.id); |
2772 | - keych.set_surface_template(keyword_catname_renderer[kw]);// this is overwritten below for shared cat scopes |
2773 | + keych_ptr->set_surface_template(keyword_catname_renderer[kw]);// this is overwritten below for shared cat scopes |
2774 | } |
2775 | else |
2776 | + { |
2777 | qDebug()<< "==== UTILs. renderer not declared: " << qstr(keyword_child.id); |
2778 | + } |
2779 | |
2780 | bool a_dup = false; |
2781 | // if this keyword scope is already a declared scope in the current dept, don't add it |
2782 | @@ -1021,7 +935,7 @@ |
2783 | |
2784 | for (std::shared_ptr<child_scope> cs : child_scopes) |
2785 | { |
2786 | - if (keych.local_id() != cs->id) |
2787 | + if (keych_ptr->local_id() != cs->id) |
2788 | continue; |
2789 | if (curr_dept_id == "") |
2790 | { |
2791 | @@ -1047,11 +961,11 @@ |
2792 | if (keyword_deptId.find(kw) != keyword_deptId.end()) |
2793 | { |
2794 | // keyword is declared to use declared department, so use it |
2795 | - keych.set_department(keyword_deptId[kw]); |
2796 | + keych_ptr->set_department(keyword_deptId[kw]); |
2797 | } |
2798 | else |
2799 | { |
2800 | - depts[kw] = std::make_shared<dept>(d); |
2801 | + depts[kw] = dept_ptr; |
2802 | } |
2803 | } |
2804 | |
2805 | @@ -1059,8 +973,8 @@ |
2806 | if (iter != shared_keywords.end()) |
2807 | { |
2808 | //qWarning() << "==== ID JUST set kw: "<< qstr(keych.keyword()); |
2809 | - qDebug() << QString("==== UTILs. set ky scope kw %1 as a a shared cat in kw: %2").arg(qstr(keych.id()), qstr(kw)); |
2810 | - keych.set_keyword_scope_shared_cat_name(shared_keyword_cats[kw]); |
2811 | + qDebug() << QString("==== UTILs. set ky scope kw %1 as a a shared cat in kw: %2").arg(qstr(keych_ptr->id()), qstr(kw)); |
2812 | + keych_ptr->set_keyword_scope_shared_cat_name(shared_keyword_cats[kw]); |
2813 | |
2814 | //initially the category is set to false meaning there have been |
2815 | //no results yet for it and it has not yet been registered |
2816 | @@ -1071,7 +985,7 @@ |
2817 | qDebug() << "===== UTILs. keywordSharedCat_isFirstResult[kw] " << keywordSharedCat_isFirstResult[kw]; |
2818 | keywordSharedCat_isSecondResult[kw] = false; |
2819 | qDebug() << "===== UTILs. kw shared surface: " << qstr(keyword_catname_renderer[kw]).replace("\n"," "); |
2820 | - keych.set_surface_template(keyword_catname_renderer[kw]); |
2821 | + keych_ptr->set_surface_template(keyword_catname_renderer[kw]); |
2822 | // if (keyword_catname_first_result_renderers[kw].empty()) |
2823 | // keych.set_first_resulte_template(keyword_catname_first_result_renderer[kw]); |
2824 | } |
2825 | @@ -1085,11 +999,12 @@ |
2826 | std::string curr_dept_id = query().department_id(); |
2827 | if (curr_dept_id.empty()) |
2828 | curr_dept_id = "root"; |
2829 | - qWarning() << "==== ID 2 KEYWORD: " << qstr(keych.keyword()); |
2830 | - qWarning () << QString("%1: ADDING KEYWORD child scope: %2, local_id %3, by keyword %4, to department: %5").arg(qstr(scope_id), qstr(keych.id()), qstr(keych.local_id()), qstr (keych.keyword()), qstr(curr_dept_id)); |
2831 | - scopes_m[keych.local_id()] = std::make_shared<AggChildScope>(keych); |
2832 | - localId_id_m[keych.local_id()] = keych.id(); |
2833 | - current_scopes.emplace_back(keych.local_id()); |
2834 | + qWarning() << "==== ID 2 KEYWORD: " << qstr(keych_ptr->keyword()); |
2835 | + qWarning () << QString("%1: ADDING KEYWORD child scope: %2, local_id %3, by keyword %4, to department: %5") |
2836 | + .arg(qstr(agg_scope_->scope_id()), qstr(keych_ptr->id()), qstr(keych_ptr->local_id()), qstr (keych_ptr->keyword()), qstr(curr_dept_id)); |
2837 | + scopes_m[keych_ptr->local_id()] = keych_ptr; |
2838 | + localId_id_m[keych_ptr->local_id()] = keych_ptr->id(); |
2839 | + current_scopes.emplace_back(keych_ptr->local_id()); |
2840 | } |
2841 | } |
2842 | |
2843 | @@ -1106,32 +1021,32 @@ |
2844 | { |
2845 | qDebug() << "==== MKCAT SCOPE scope id"<< qstr(ids.first); |
2846 | qDebug() << "==== MKCAT SCOPE scope loca_id"<< qstr(ids.second); |
2847 | - AggChildScope scope(ids.first); |
2848 | - scope.set_category_scope(true); |
2849 | - scope.set_category_id(cat->id); |
2850 | + auto scope_ptr = std::make_shared<AggChildScope>(ids.first); |
2851 | + scope_ptr->set_category_scope(true); |
2852 | + scope_ptr->set_category_id(cat->id); |
2853 | qDebug() << "==== MKCAT SCOPE cat card"<< QString::number(cat->cardinality); |
2854 | - scope.set_cardinality(cat->cardinality); |
2855 | - qDebug() << "==== MKCAT SCOPE get cat card"<< QString::number(scope.cardinality()); |
2856 | - scope.set_local_id(ids.second); |
2857 | + scope_ptr->set_cardinality(cat->cardinality); |
2858 | + qDebug() << "==== MKCAT SCOPE get cat card"<< QString::number(scope_ptr->cardinality()); |
2859 | + scope_ptr->set_local_id(ids.second); |
2860 | if (!scopeLocalId_childDept_m[ids.second].empty()) |
2861 | { |
2862 | - scope.set_child_department(scopeLocalId_childDept_m[ids.second]); |
2863 | + scope_ptr->set_child_department(scopeLocalId_childDept_m[ids.second]); |
2864 | } |
2865 | - scope.set_surface_template(cat->renderer); |
2866 | - scope.set_search_template(cat->search_renderer); |
2867 | + scope_ptr->set_surface_template(cat->renderer); |
2868 | + scope_ptr->set_search_template(cat->search_renderer); |
2869 | if (using_departments) |
2870 | - scope.set_department(cat->dept_id); |
2871 | + scope_ptr->set_department(cat->dept_id); |
2872 | qDebug() << "==== MKCAT SCOPE cat dept_id"<< qstr(cat->dept_id); |
2873 | - qDebug() << "==== MKCAT SCOPE scope dept_id"<< qstr(scope.department()); |
2874 | - scope.set_keyword_scope(false); |
2875 | - scopes_m[scope.local_id()] = std::make_shared<AggChildScope>(scope); |
2876 | - type_ids_m[cat->id].emplace_back(scope.local_id()); |
2877 | - localId_id_m[scope.local_id()] = scope.id(); |
2878 | - current_scopes.emplace_back(scope.local_id()); |
2879 | - qWarning () << QString("%1: ADDING CATEGORY SCOPE child scope: %2 to dept %3").arg(qstr(scope_id), qstr(scope.local_id()), qstr(scope.department())); |
2880 | + qDebug() << "==== MKCAT SCOPE scope dept_id"<< qstr(scope_ptr->department()); |
2881 | + scope_ptr->set_keyword_scope(false); |
2882 | + scopes_m[scope_ptr->local_id()] = scope_ptr; |
2883 | + type_ids_m[cat->id].emplace_back(scope_ptr->local_id()); |
2884 | + localId_id_m[scope_ptr->local_id()] = scope_ptr->id(); |
2885 | + current_scopes.emplace_back(scope_ptr->local_id()); |
2886 | + qWarning () << QString("%1: ADDING CATEGORY SCOPE child scope: %2 to dept %3") |
2887 | + .arg(qstr(agg_scope_->scope_id()), qstr(scope_ptr->local_id()), qstr(scope_ptr->department())); |
2888 | } |
2889 | |
2890 | - |
2891 | for (auto const& keyword_child : current_child_scopes) |
2892 | { |
2893 | qDebug() << "==== CATKW id START "; |
2894 | @@ -1139,7 +1054,6 @@ |
2895 | continue; |
2896 | |
2897 | std::string id = keyword_child.id; |
2898 | - AggChildScope keych(id); |
2899 | for (auto kw : cat->keywords) |
2900 | { |
2901 | qDebug() << "==== CATKW child id: " << qstr(id); |
2902 | @@ -1157,40 +1071,42 @@ |
2903 | continue; |
2904 | |
2905 | qDebug() << qstr("==== CATKW ID found: %1 %2").arg(qstr(kw),qstr(id)); |
2906 | - AggChildScope keych(id); |
2907 | + auto keych_ptr = std::make_shared<AggChildScope>(id); |
2908 | std::string local_id = id + ":category=" + cat->id + ":keyword=" + kw; |
2909 | - keych.set_local_id(local_id); |
2910 | - keych.set_category_link_to_child(false);//TODO revisit |
2911 | - keych.set_category_scope(true); |
2912 | - keych.set_category_id(cat->id); |
2913 | + keych_ptr->set_local_id(local_id); |
2914 | + keych_ptr->set_category_link_to_child(false);//TODO revisit |
2915 | + keych_ptr->set_category_scope(true); |
2916 | + keych_ptr->set_category_id(cat->id); |
2917 | qDebug() << "==== CATKW adding id: " << qstr(id); |
2918 | qDebug() << "==== CATKW adding kw: " << qstr(kw); |
2919 | - type_ids_m[cat->id].emplace_back(keych.local_id()); |
2920 | - keych.set_keyword(kw); |
2921 | - qDebug() << "==== CATKW: " << qstr(keych.keyword()); |
2922 | - keych.set_department(cat->dept_id); |
2923 | - keych.set_department(cat->dept_id); |
2924 | - keych.set_cardinality(cat->cardinality); |
2925 | + type_ids_m[cat->id].emplace_back(keych_ptr->local_id()); |
2926 | + keych_ptr->set_keyword(kw); |
2927 | + qDebug() << "==== CATKW: " << qstr(keych_ptr->keyword()); |
2928 | + keych_ptr->set_department(cat->dept_id); |
2929 | + keych_ptr->set_department(cat->dept_id); |
2930 | + keych_ptr->set_cardinality(cat->cardinality); |
2931 | |
2932 | // set more default values |
2933 | categoryId_isFirstResult[kw] = true; |
2934 | categoryId_isSecondResult[kw] = false; |
2935 | - keych.set_surface_template(cat->renderer); |
2936 | - keych.set_search_template(cat->search_renderer); |
2937 | + keych_ptr->set_surface_template(cat->renderer); |
2938 | + keych_ptr->set_search_template(cat->search_renderer); |
2939 | |
2940 | if (categoryId_firstRdrs_catId2commonId.find(cat->id) != categoryId_firstRdrs_catId2commonId.end()) |
2941 | { |
2942 | - keych.set_first_common_template_id(categoryId_firstRdrs_catId2commonId[cat->id]); |
2943 | + keych_ptr->set_first_common_template_id(categoryId_firstRdrs_catId2commonId[cat->id]); |
2944 | } |
2945 | if (categoryId_surfaceRdrs_catId2commonId.find(cat->id) != categoryId_surfaceRdrs_catId2commonId.end()) |
2946 | { |
2947 | - keych.set_surface_common_template_id(categoryId_surfaceRdrs_catId2commonId[cat->id]); |
2948 | + keych_ptr->set_surface_common_template_id(categoryId_surfaceRdrs_catId2commonId[cat->id]); |
2949 | } |
2950 | |
2951 | - qWarning () << QString("%1: ADDING CATEGORY KEYWORD child scope: %2, by keyword %3, to department: %4").arg(qstr(scope_id), qstr(keych.id()), qstr(kw), qstr(cat->dept_id)); |
2952 | - scopes_m[keych.local_id()] = std::make_shared<AggChildScope>(keych); |
2953 | - localId_id_m[keych.local_id()] = keych.id(); |
2954 | - current_scopes.emplace_back(keych.local_id()); |
2955 | + qWarning () << QString("%1: ADDING CATEGORY KEYWORD child scope: %2, by keyword %3, to department: %4") |
2956 | + .arg(qstr(agg_scope_->scope_id()), qstr(keych_ptr->id()), qstr(kw), qstr(cat->dept_id)); |
2957 | + |
2958 | + scopes_m[keych_ptr->local_id()] = keych_ptr; |
2959 | + localId_id_m[keych_ptr->local_id()] = keych_ptr->id(); |
2960 | + current_scopes.emplace_back(keych_ptr->local_id()); |
2961 | current_scopeIds.emplace_back(id); |
2962 | } |
2963 | } |
2964 | @@ -1263,68 +1179,6 @@ |
2965 | reply->push(res); |
2966 | } |
2967 | |
2968 | -void Query::load_hints_config() |
2969 | -{ |
2970 | - // try to open hints.json and get vals, else no hints |
2971 | - if (!load_json_file(root, scope_dir_ + "/hints.json", scope_id)) |
2972 | - { |
2973 | - return; |
2974 | - } |
2975 | - if (root.contains("using_hints")) |
2976 | - { |
2977 | - if (root["using_hints"].toString() == TRUE) |
2978 | - uses_hints = true; |
2979 | - else |
2980 | - return; |
2981 | - } |
2982 | - else |
2983 | - return; |
2984 | - if (root.contains("hints_source")) |
2985 | - { |
2986 | - if (root["hints_source"].toString() == "local") |
2987 | - { |
2988 | - local_hints = true; |
2989 | - if (root.contains("local")) { |
2990 | - hints_local_json = root["local"].toObject(); |
2991 | - } |
2992 | - } |
2993 | - } |
2994 | - else |
2995 | - return; |
2996 | - if (root.contains("quick_start_help")) |
2997 | - if (sstr(root["quick_start_help"].toString()) == TRUE) |
2998 | - hints_quickstart = true; |
2999 | - if (root.contains("message_on_no_network")) |
3000 | - if (sstr(root["message_on_no_network"].toString()) == TRUE) |
3001 | - no_network_msg = true; |
3002 | - if (root.contains("message_on_no_location")) |
3003 | - if (sstr(root["message_on_no_location"].toString()) == TRUE) |
3004 | - no_location_msg = true; |
3005 | - if (!local_hints) |
3006 | - { |
3007 | - if (root.contains("hints_scope")) |
3008 | - { |
3009 | - QJsonObject hints_scope = root["hints_scope"].toObject(); |
3010 | - if (hints_scope.contains("hints_scope_id")) |
3011 | - HINTS_SCOPE_ID = sstr(hints_scope["hints_scope_id"].toString()); |
3012 | - else |
3013 | - uses_hints = false; |
3014 | - if (hints_scope.contains("hints_this_scope")) |
3015 | - HINTS_THIS_SCOPE = sstr(hints_scope["hints_this_scope"].toString()); |
3016 | - else |
3017 | - uses_hints = false; |
3018 | - //this key is deprecated. it previously specified the query string the hints scope |
3019 | - //sent to the agg scope to signal hints quick start should be permanently dismissed. |
3020 | - //scope-aggregator 4.4 stopped using this. |
3021 | - if (hints_scope.contains("hints_hide")) |
3022 | - HINTS_HIDE = sstr(hints_scope["hints_hide"].toString()); |
3023 | - else |
3024 | - uses_hints = false; |
3025 | - } |
3026 | - } |
3027 | - return; |
3028 | -} |
3029 | - |
3030 | bool Query::hints_exists() |
3031 | { |
3032 | auto scopes = registry_->list(); |
3033 | @@ -1342,71 +1196,69 @@ |
3034 | { |
3035 | if (!local_hints) |
3036 | return; |
3037 | - if (!hints_local_json.contains("content")) |
3038 | + if (!hints_local_json.contains(QStringLiteral("content"))) |
3039 | return; |
3040 | - auto content = hints_local_json["content"].toObject(); |
3041 | - if (!content.contains("categories")) |
3042 | + auto content = hints_local_json[QStringLiteral("content")].toObject(); |
3043 | + if (!content.contains(QStringLiteral("categories"))) |
3044 | return; |
3045 | |
3046 | - QJsonArray cats = content["categories"].toArray(); |
3047 | + QJsonArray cats = content[QStringLiteral("categories")].toArray(); |
3048 | for (const auto & cat_ : cats) |
3049 | { |
3050 | auto cat = cat_.toObject(); |
3051 | |
3052 | - std::string id = sstr(cat["id"].toString()); |
3053 | - std::string title = _(sstr(cat["_title"].toString()).c_str()); |
3054 | - QJsonDocument layout_d(cat["layout"].toObject()); |
3055 | + std::string id = sstr(cat[QStringLiteral("id")].toString()); |
3056 | + std::string title = _(sstr(cat[QStringLiteral("_title")].toString()).c_str()); |
3057 | + QJsonDocument layout_d(cat[QStringLiteral("layout")].toObject()); |
3058 | std::string local_hints_template = sstr(layout_d.toJson()); |
3059 | auto category = upstream_reply_->lookup_category(id); |
3060 | if (!category) { |
3061 | category = upstream_reply_->register_category(id, title, "", us::CategoryRenderer(local_hints_template)); |
3062 | } |
3063 | - QJsonArray items = cat["items"].toArray(); |
3064 | + QJsonArray items = cat[QStringLiteral("items")].toArray(); |
3065 | for (const auto & res__ : items) |
3066 | { |
3067 | auto res_ = res__.toObject(); |
3068 | us::CategorisedResult res(category); |
3069 | - res.set_title(_(sstr(res_["_title"].toString()).c_str())); |
3070 | - res["subtitle"] = _(sstr(res_["_subtitle"].toString()).c_str()); |
3071 | - res["description"] = _(sstr(res_["_description"].toString()).c_str()); |
3072 | + res.set_title(_(sstr(res_[QStringLiteral("_title")].toString()).c_str())); |
3073 | + res["subtitle"] = _(sstr(res_[QStringLiteral("_subtitle")].toString()).c_str()); |
3074 | + res["description"] = _(sstr(res_[QStringLiteral("_description")].toString()).c_str()); |
3075 | std::string uri = "http://www.ubuntu.com"; |
3076 | if (res_.contains("uri")) |
3077 | { |
3078 | uri = sstr(res_["uri"].toString()); |
3079 | } |
3080 | - if (res_.contains("action")) |
3081 | + if (res_.contains(QStringLiteral("action"))) |
3082 | { |
3083 | - auto action = res_["action"].toObject(); |
3084 | + auto action = res_[QStringLiteral("action")].toObject(); |
3085 | VariantBuilder builder; |
3086 | builder.add_tuple({ |
3087 | {"id", Variant("Open")}, |
3088 | - {"label", Variant(_(sstr(action["_name"].toString()).c_str()))}, |
3089 | - {"uri", Variant(sstr(action["uri"].toString()))} |
3090 | + {"label", Variant(_(sstr(action[QStringLiteral("_name")].toString()).c_str()))}, |
3091 | + {"uri", Variant(sstr(action[QStringLiteral("uri")].toString()))} |
3092 | }); |
3093 | res["actions"]=builder.end(); |
3094 | - if (action.contains("uri")) |
3095 | + if (action.contains(QStringLiteral("uri"))) |
3096 | { |
3097 | - uri = sstr(action["uri"].toString()); |
3098 | + uri = sstr(action[QStringLiteral("uri")].toString()); |
3099 | } |
3100 | } |
3101 | - if (res_.contains("oaccount")) |
3102 | + if (res_.contains(QStringLiteral("oaccount"))) |
3103 | { |
3104 | - auto oaccount = res_["oaccount"].toObject(); |
3105 | - auto queryScope = sstr(oaccount["QueryScope"].toString()); |
3106 | + auto oaccount = res_[QStringLiteral("oaccount")].toObject(); |
3107 | + auto queryScope = sstr(oaccount[QStringLiteral("QueryScope")].toString()); |
3108 | |
3109 | - us::OnlineAccountClient oa_client(sstr(oaccount["ServiceName"].toString()), |
3110 | - sstr(oaccount["ServiceType"].toString()), |
3111 | - sstr(oaccount["ProviderName"].toString())); |
3112 | + us::OnlineAccountClient oa_client(sstr(oaccount[QStringLiteral("ServiceName")].toString()), |
3113 | + sstr(oaccount[QStringLiteral("ServiceType")].toString()), |
3114 | + sstr(oaccount[QStringLiteral("ProviderName")].toString())); |
3115 | bool alreadyLoggedIn = false; |
3116 | oa_client.refresh_service_statuses(); |
3117 | auto vectoraccounts = oa_client.get_service_statuses(); |
3118 | - bool loggedIn; |
3119 | for (auto const& status : oa_client.get_service_statuses()) |
3120 | { |
3121 | if (status.service_enabled) |
3122 | { |
3123 | alreadyLoggedIn = true; |
3124 | - loggedIn = true; |
3125 | break; |
3126 | } |
3127 | } |
3128 | @@ -1426,7 +1278,7 @@ |
3129 | OnlineAccountClient::DoNothing); |
3130 | |
3131 | } |
3132 | - if (res_.contains("hide_hints")) |
3133 | + if (res_.contains(QStringLiteral("hide_hints"))) |
3134 | { |
3135 | qDebug() << "=== NHINTS. utils. hide hints found in json"; |
3136 | res["action"] = "hide_hints"; |
3137 | @@ -1459,8 +1311,7 @@ |
3138 | auto filepath2 = QString::fromStdString(cache_dir_) +"/" + firstboot; |
3139 | if (QFile::exists(filepath1) || QFile::exists(filepath2)) |
3140 | return true; |
3141 | - else |
3142 | - return false; //don't show hints as fall back |
3143 | + return false; //don't show hints as fall back |
3144 | } |
3145 | |
3146 | void Query::dismiss_hints_quickstart() { |
Thanks Gary,
I already merged no-hints to trunk but I did not tagged trunk as 4.8 so, after review you can still merge this to trunk and bzr tag 4.8.
Initial comment: we want most of this (use references instead of values, const, and such).
Please note that this MP is not against the final no-hints branch (make-pot.sh trunk/no-hints changes are not present).
I'll continue with the review.