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
=== modified file 'src/daemon.vala'
--- src/daemon.vala 2012-03-12 18:47:05 +0000
+++ src/daemon.vala 2012-03-27 10:20:25 +0000
@@ -472,6 +472,7 @@
472 Unity.Package.Sort.BY_NAME);472 Unity.Package.Sort.BY_NAME);
473 if (local_apps_active ())473 if (local_apps_active ())
474 {474 {
475 if (has_search) resort_pkg_search_results (appresults);
475 add_pkg_search_result (appresults, installed_uris, available_uris,476 add_pkg_search_result (appresults, installed_uris, available_uris,
476 transaction, Category.INSTALLED);477 transaction, Category.INSTALLED);
477 }478 }
@@ -578,7 +579,8 @@
578 var timer = new Timer ();579 var timer = new Timer ();
579 var appresults = appsearcher.search (search_string, 0,580 var appresults = appsearcher.search (search_string, 0,
580 Unity.Package.SearchType.PREFIX,581 Unity.Package.SearchType.PREFIX,
581 Unity.Package.Sort.BY_RELEVANCY); 582 Unity.Package.Sort.BY_RELEVANCY);
583 resort_pkg_search_results (appresults);
582 add_pkg_search_result (appresults, installed_uris, available_uris, model,584 add_pkg_search_result (appresults, installed_uris, available_uris, model,
583 Category.APPLICATIONS);585 Category.APPLICATIONS);
584 586
@@ -792,6 +794,33 @@
792794
793 return desktop_id;795 return desktop_id;
794 }796 }
797
798 /*
799 * Performs secondary level sorting of the results according to popularity
800 * of individual desktop files.
801 */
802 private void resort_pkg_search_results (Unity.Package.SearchResult results)
803 {
804 results.results.sort_with_data ((a, b) =>
805 {
806 /* We'll cluster the relevancies into a couple of bins, because
807 * there can be multiple terms adding to the relevancy (especially
808 * when doing one/two character prefix searches - ie a "f*" search
809 * will have slightly higher relevancy for item with name "Search
810 * _f_or _f_iles" than "_F_irefox", and that's not what we want)
811 */
812 int rel_a = a.relevancy / 10;
813 int rel_b = b.relevancy / 10;
814 if (rel_a == rel_b)
815 {
816 string id_a = extract_desktop_id (a.desktop_file);
817 string id_b = extract_desktop_id (b.desktop_file);
818 rel_a = popularity_map["application://" + id_a];
819 rel_b = popularity_map["application://" + id_b];
820 }
821 return rel_b - rel_a; // we want higher relevancy first
822 });
823 }
795 824
796 private void add_pkg_search_result (Unity.Package.SearchResult results,825 private void add_pkg_search_result (Unity.Package.SearchResult results,
797 Set<string> installed_uris,826 Set<string> installed_uris,
@@ -804,29 +833,6 @@
804 var ratings_filter = scope.get_filter ("rating") as RatingsFilter;833 var ratings_filter = scope.get_filter ("rating") as RatingsFilter;
805 uint n_added = 0;834 uint n_added = 0;
806835
807 if (category != Category.AVAILABLE)
808 {
809 results.results.sort_with_data ((a, b) =>
810 {
811 /* We'll cluster the relevancies into a couple of bins, because
812 * there can be multiple terms adding to the relevancy (especially
813 * when doing one/two character prefix searches - ie a "f*" search
814 * will have slightly higher relevancy for item with name "Search
815 * _f_or _f_iles" than "_F_irefox", and that's not what we want)
816 */
817 int rel_a = a.relevancy / 10;
818 int rel_b = b.relevancy / 10;
819 if (rel_a == rel_b)
820 {
821 string id_a = extract_desktop_id (a.desktop_file);
822 string id_b = extract_desktop_id (b.desktop_file);
823 rel_a = popularity_map["application://" + id_a];
824 rel_b = popularity_map["application://" + id_b];
825 }
826 return rel_b - rel_a; // we want higher relevancy first
827 });
828 }
829
830 foreach (var pkginfo in results.results)836 foreach (var pkginfo in results.results)
831 {837 {
832 if (pkginfo.desktop_file == null)838 if (pkginfo.desktop_file == null)
833839
=== added directory 'tests/manual'
=== added file 'tests/manual/sort-order.txt'
--- tests/manual/sort-order.txt 1970-01-01 00:00:00 +0000
+++ tests/manual/sort-order.txt 2012-03-27 10:20:25 +0000
@@ -0,0 +1,9 @@
1Sort order
2==========
3Tests that the sort order of the "Installed" category is alphabetical.
4
5#. Open the Dash and switch to the application lens.
6#. Make sure that the search string is empty.
7
8Outcome
9 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