Merge lp:~mhr3/unity-lens-applications/fix-964325 into lp:unity-lens-applications

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 281
Merged at revision: 281
Proposed branch: lp:~mhr3/unity-lens-applications/fix-964325
Merge into: lp:unity-lens-applications
Diff against target: 100 lines (+39/-24)
2 files modified
src/daemon.vala (+30/-24)
tests/manual/sort-order.txt (+9/-0)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/fix-964325
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+99487@code.launchpad.net

Commit message

Fix regression where Installed apps category wasn't sorted alphabetically

Description of the change

Fixes a regression where items in the "Installed" category weren't sorted alphabetically (if there's no search). We applied the popularity sorting even when the search string was empty, which shouldn't have been the case.

Added manual test, since the applications are sorted according to current locale which is non-trivial to check in bash.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks correct

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/daemon.vala'
2--- src/daemon.vala 2012-03-12 18:47:05 +0000
3+++ src/daemon.vala 2012-03-27 10:20:25 +0000
4@@ -472,6 +472,7 @@
5 Unity.Package.Sort.BY_NAME);
6 if (local_apps_active ())
7 {
8+ if (has_search) resort_pkg_search_results (appresults);
9 add_pkg_search_result (appresults, installed_uris, available_uris,
10 transaction, Category.INSTALLED);
11 }
12@@ -578,7 +579,8 @@
13 var timer = new Timer ();
14 var appresults = appsearcher.search (search_string, 0,
15 Unity.Package.SearchType.PREFIX,
16- Unity.Package.Sort.BY_RELEVANCY);
17+ Unity.Package.Sort.BY_RELEVANCY);
18+ resort_pkg_search_results (appresults);
19 add_pkg_search_result (appresults, installed_uris, available_uris, model,
20 Category.APPLICATIONS);
21
22@@ -792,6 +794,33 @@
23
24 return desktop_id;
25 }
26+
27+ /*
28+ * Performs secondary level sorting of the results according to popularity
29+ * of individual desktop files.
30+ */
31+ private void resort_pkg_search_results (Unity.Package.SearchResult results)
32+ {
33+ results.results.sort_with_data ((a, b) =>
34+ {
35+ /* We'll cluster the relevancies into a couple of bins, because
36+ * there can be multiple terms adding to the relevancy (especially
37+ * when doing one/two character prefix searches - ie a "f*" search
38+ * will have slightly higher relevancy for item with name "Search
39+ * _f_or _f_iles" than "_F_irefox", and that's not what we want)
40+ */
41+ int rel_a = a.relevancy / 10;
42+ int rel_b = b.relevancy / 10;
43+ if (rel_a == rel_b)
44+ {
45+ string id_a = extract_desktop_id (a.desktop_file);
46+ string id_b = extract_desktop_id (b.desktop_file);
47+ rel_a = popularity_map["application://" + id_a];
48+ rel_b = popularity_map["application://" + id_b];
49+ }
50+ return rel_b - rel_a; // we want higher relevancy first
51+ });
52+ }
53
54 private void add_pkg_search_result (Unity.Package.SearchResult results,
55 Set<string> installed_uris,
56@@ -804,29 +833,6 @@
57 var ratings_filter = scope.get_filter ("rating") as RatingsFilter;
58 uint n_added = 0;
59
60- if (category != Category.AVAILABLE)
61- {
62- results.results.sort_with_data ((a, b) =>
63- {
64- /* We'll cluster the relevancies into a couple of bins, because
65- * there can be multiple terms adding to the relevancy (especially
66- * when doing one/two character prefix searches - ie a "f*" search
67- * will have slightly higher relevancy for item with name "Search
68- * _f_or _f_iles" than "_F_irefox", and that's not what we want)
69- */
70- int rel_a = a.relevancy / 10;
71- int rel_b = b.relevancy / 10;
72- if (rel_a == rel_b)
73- {
74- string id_a = extract_desktop_id (a.desktop_file);
75- string id_b = extract_desktop_id (b.desktop_file);
76- rel_a = popularity_map["application://" + id_a];
77- rel_b = popularity_map["application://" + id_b];
78- }
79- return rel_b - rel_a; // we want higher relevancy first
80- });
81- }
82-
83 foreach (var pkginfo in results.results)
84 {
85 if (pkginfo.desktop_file == null)
86
87=== added directory 'tests/manual'
88=== added file 'tests/manual/sort-order.txt'
89--- tests/manual/sort-order.txt 1970-01-01 00:00:00 +0000
90+++ tests/manual/sort-order.txt 2012-03-27 10:20:25 +0000
91@@ -0,0 +1,9 @@
92+Sort order
93+==========
94+Tests that the sort order of the "Installed" category is alphabetical.
95+
96+#. Open the Dash and switch to the application lens.
97+#. Make sure that the search string is empty.
98+
99+Outcome
100+ The "Installed" category should be shown and the items within should be sorted alphabetically (respecting sorting of your locale).

Subscribers

People subscribed via source and target branches