Merge lp:~stolowski/unity-scope-click/fix-1343242 into lp:unity-scope-click

Proposed by Paweł Stołowski
Status: Merged
Approved by: dobey
Approved revision: 300
Merged at revision: 299
Proposed branch: lp:~stolowski/unity-scope-click/fix-1343242
Merge into: lp:unity-scope-click
Diff against target: 128 lines (+31/-54)
2 files modified
scope/clickstore/store-query.cpp (+29/-53)
scope/clickstore/store-query.h (+2/-1)
To merge this branch: bzr merge lp:~stolowski/unity-scope-click/fix-1343242
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+243681@code.launchpad.net

Commit message

Report all departments in the Store scope so that Shell receives also the siblings of current department and can properly render departments menu when going to a specific department via 'Ubuntu store' button of Apps scope.

Description of the change

Report all departments in the Store scope so that Shell receives also the siblings of current department and can properly render departments menu when going to a specific department via 'Ubuntu store' button of Apps scope.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

Looks ok to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/clickstore/store-query.cpp'
2--- scope/clickstore/store-query.cpp 2014-10-22 19:32:37 +0000
3+++ scope/clickstore/store-query.cpp 2014-12-04 15:01:55 +0000
4@@ -224,62 +224,40 @@
5 });
6 }
7
8-//
9-// creates department menu with narrowed-down list of subdepartments of current department, as
10-// returned by server call
11-void click::Query::populate_departments(const click::DepartmentList& subdepts, const std::string& current_dep_id, unity::scopes::Department::SPtr &root)
12+unity::scopes::Department::SPtr click::Query::fromClickDepartment(const click::Department::SCPtr click_dept, const std::string& current_dept_id, const click::DepartmentList& subdepts)
13 {
14+ const std::locale loc("");
15+ unity::scopes::Department::SPtr dep = unity::scopes::Department::create(click_dept->id(), query(), click_dept->name());
16+ if (click_dept->has_children_flag())
17+ {
18+ dep->set_has_subdepartments();
19+ }
20 unity::scopes::DepartmentList departments;
21
22- // create a list of subdepartments of current department
23- foreach (auto d, subdepts)
24+ // subdepts is a list of subdepartments of current department fetched from the Store for current search; if we encountered current department in the tree,
25+ // insert the list from the server rather than the one from internal cache.
26+ for (auto click_subdep: (click_dept->id() == current_dept_id ? subdepts : click_dept->sub_departments()))
27 {
28- unity::scopes::Department::SPtr department = unity::scopes::Department::create(d->id(), query(), d->name());
29- if (d->has_children_flag())
30- {
31- department->set_has_subdepartments();
32- }
33- departments.push_back(department);
34+ departments.push_back(fromClickDepartment(click_subdep, current_dept_id, subdepts));
35 }
36-
37- const std::locale loc("");
38 departments.sort([&loc](const unity::scopes::Department::SCPtr &d1, const unity::scopes::Department::SCPtr &d2) -> bool {
39 return loc(d1->label(), d2->label()) > 0;
40- });
41-
42- if (current_dep_id != "")
43- {
44- auto curr_dpt = impl->department_lookup.get_department_info(current_dep_id);
45- if (curr_dpt != nullptr)
46- {
47- unity::scopes::Department::SPtr current = unity::scopes::Department::create(current_dep_id, query(), curr_dpt->name());
48- if (departments.size() > 0) // this may be a leaf department
49- {
50- current->set_subdepartments(departments);
51- }
52-
53- auto parent_info = impl->department_lookup.get_parent(current_dep_id);
54- if (parent_info != nullptr)
55- {
56- root = unity::scopes::Department::create(parent_info->id(), query(), parent_info->name());
57- root->set_subdepartments({current});
58- return;
59- }
60- else
61- {
62- root = unity::scopes::Department::create("", query(), _("All"));
63- root->set_subdepartments({current});
64- return;
65- }
66- }
67- else
68- {
69- qWarning() << "Unknown department:" << QString::fromStdString(current_dep_id);
70- }
71- }
72-
73- root = unity::scopes::Department::create("", query(), _("All"));
74- root->set_subdepartments(departments);
75+ });
76+ dep->set_subdepartments(departments);
77+
78+ return dep;
79+}
80+
81+//
82+// creates department menu with narrowed-down list of subdepartments of current department, as
83+// returned by server call
84+unity::scopes::Department::SPtr click::Query::populate_departments(const click::DepartmentList& subdepts, const std::string& current_dep_id)
85+{
86+ // Return complete departments tree (starting from 'All') every time, rather than only parent - current - children; this is the only
87+ // way we can display siblings corrctly when navigating from Apps scope straight into a subdepartment of Store - see LP #1343242.
88+ // For currently visible department include its subdepartments as returned for current search by the server (subdepts) -
89+ // all others are constructed from the department lookup.
90+ return fromClickDepartment(impl->department_lookup.get_department_info(""), current_dep_id, subdepts);
91 }
92
93 // recursively store all departments in the departments database
94@@ -446,9 +424,8 @@
95
96 if (query().department_id() == "") // top-level departments
97 {
98- unity::scopes::Department::SPtr root;
99 auto subdepts = curdep->sub_departments();
100- populate_departments(subdepts, query().department_id(), root);
101+ auto root = populate_departments(subdepts, query().department_id());
102 push_departments(searchReply, root);
103
104 qDebug() << "pushing cached highlights";
105@@ -464,8 +441,7 @@
106 if (error == click::Index::Error::NoError)
107 {
108 qDebug() << "departments call completed";
109- unity::scopes::Department::SPtr root;
110- populate_departments(depts, query().department_id(), root);
111+ auto root = populate_departments(depts, query().department_id());
112 push_departments(searchReply, root);
113 push_highlights(searchReply, highlights, locallyInstalledApps);
114 }
115
116=== modified file 'scope/clickstore/store-query.h'
117--- scope/clickstore/store-query.h 2014-10-17 19:36:02 +0000
118+++ scope/clickstore/store-query.h 2014-12-04 15:01:55 +0000
119@@ -84,7 +84,8 @@
120 pay::PurchasedList purchased_apps;
121
122 protected:
123- virtual void populate_departments(const click::DepartmentList& depts, const std::string& current_department_id, unity::scopes::Department::SPtr &root);
124+ virtual unity::scopes::Department::SPtr fromClickDepartment(const click::Department::SCPtr click_dept, const std::string& current_dept_id, const click::DepartmentList& subdepts);
125+ virtual unity::scopes::Department::SPtr populate_departments(const click::DepartmentList& depts, const std::string& current_department_id);
126 virtual void store_departments(const click::DepartmentList& depts);
127 virtual void push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root);
128 virtual void add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& installedPackages);

Subscribers

People subscribed via source and target branches