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

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 263
Merged at revision: 262
Proposed branch: lp:~mhr3/unity-lens-applications/fix-841847
Merge into: lp:unity-lens-applications
Diff against target: 166 lines (+54/-20)
2 files modified
configure.ac (+1/-1)
src/daemon.vala (+53/-19)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/fix-841847
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+90150@code.launchpad.net

Description of the change

Allow selection of multiple categories in the type filter. UNBLOCK

To post a comment you must log in.
263. By Michal Hruby

Bump vala requirement (we no longer compile with 0.12)

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Tested against Unity trunk and works very well. I am not particularly keen on maintaining a dupe list of the filter ids, but it doesn't seem to be easily fixable without a major refactoring. Otherwise, the code looks great.

All in all, nice work!

(wrt testing - this branch is currently exceptionally hard to test in an automated manner. I took extra care in the review (and to some degree the branch can be considered a refactoring so I don't see big risk from this branch))

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-01-24 11:30:08 +0000
3+++ configure.ac 2012-01-26 14:02:36 +0000
4@@ -15,7 +15,7 @@
5 # Init the other things we depend on
6 #############################################
7 AM_MAINTAINER_MODE
8-AM_PROG_VALAC([0.12.1])
9+AM_PROG_VALAC([0.14.0])
10 AS_IF([test -z "$VALAC"], [AC_MSG_ERROR(["No valac compiler found."])])
11 AC_PROG_CC
12 AC_PROG_CXX
13
14=== modified file 'src/daemon.vala'
15--- src/daemon.vala 2012-01-25 08:38:17 +0000
16+++ src/daemon.vala 2012-01-26 14:02:36 +0000
17@@ -249,7 +249,7 @@
18
19 /* Type filter */
20 {
21- var filter = new RadioOptionFilter ("type", _("Type"));
22+ var filter = new CheckOptionFilter ("type", _("Type"));
23 filter.sort_type = Unity.OptionsFilter.SortType.DISPLAY_NAME;
24
25 filter.add_option ("accessories", _("Accessories"));
26@@ -358,7 +358,7 @@
27 }
28
29 private string prepare_zg_search_string (Unity.LensSearch search,
30- string type_id="all")
31+ OptionsFilter? options)
32 {
33 string s = search.search_string.strip ();
34
35@@ -368,12 +368,12 @@
36 if (s != "")
37 s = @"app:($s)";
38 else
39- return type_queries.lookup(type_id);
40+ return extract_type_query (options);
41
42- if (type_id == "all")
43+ if (options == null || !options.filtering)
44 return s;
45 else
46- return s + @" AND $(type_queries.lookup(type_id))";
47+ return s + " AND " + extract_type_query (options);
48 }
49
50 private async void update_scope_search (Unity.LensSearch search,
51@@ -385,17 +385,15 @@
52
53 debug ("Searching for: %s", search.search_string);
54
55- var filter = scope.get_filter ("type") as RadioOptionFilter;
56- Unity.FilterOption? option = filter.get_active_option ();
57- string type_id = option == null ? "all" : option.id;
58+ var filter = scope.get_filter ("type") as OptionsFilter;
59
60- string pkg_search_string = prepare_pkg_search_string (search, type_id);
61+ string pkg_search_string = prepare_pkg_search_string (search, filter);
62
63 bool has_search = !Utils.is_search_empty (search);
64
65 Timer timer = new Timer ();
66
67- var zg_search_string = prepare_zg_search_string (search, type_id);
68+ var zg_search_string = prepare_zg_search_string (search, filter);
69
70 var transaction = new Dee.Transaction (model);
71 transaction.clear ();
72@@ -469,7 +467,7 @@
73 else
74 {
75 timer.start ();
76- string? filter_query = prepare_pkg_search_string (search, type_id);
77+ string? filter_query = prepare_pkg_search_string (search, filter);
78 var random_pkgresults = pkgsearcher.get_random_apps (filter_query, 12);
79 add_pkg_search_result (random_pkgresults, installed_uris, available_uris,
80 model, Category.AVAILABLE, 6);
81@@ -506,7 +504,7 @@
82
83 model.clear ();
84
85- var search_string = prepare_pkg_search_string (search, "all");
86+ var search_string = prepare_pkg_search_string (search, null);
87 Set<string> installed_uris = new HashSet<string> ();
88 Set<string> available_uris = new HashSet<string> ();
89 var timer = new Timer ();
90@@ -538,7 +536,7 @@
91
92 Timer timer = new Timer ();
93
94- var zg_search_string = prepare_zg_search_string (search, "all");
95+ var zg_search_string = prepare_zg_search_string (search, null);
96
97 if (local_apps_active () && display_recent_apps) {
98 try {
99@@ -569,15 +567,51 @@
100
101 search.finished ();
102 }
103+
104+ private const string[] option_types =
105+ {
106+ "accessories",
107+ "education",
108+ "game",
109+ "graphics",
110+ "internet",
111+ "fonts",
112+ "office",
113+ "media",
114+ "customization",
115+ "accessibility",
116+ "developer",
117+ "science-and-engineering",
118+ "system"
119+ };
120+
121+ private string extract_type_query (OptionsFilter? options)
122+ {
123+ if (options == null || !options.filtering) return "NOT category:XYZ";
124+
125+ string? result = null;
126+ foreach (unowned string type_id in option_types)
127+ {
128+ var option = options.get_option (type_id);
129+ if (option == null) continue;
130+ if (!option.active) continue;
131+
132+ if (result == null) result = type_queries[type_id];
133+ else result += " OR " + type_queries[type_id];
134+ }
135+
136+ return result == null ? "NOT category:XYZ" : result;
137+ }
138
139- private string prepare_pkg_search_string (Unity.LensSearch search, string type_id="all")
140+ private string prepare_pkg_search_string (Unity.LensSearch search,
141+ OptionsFilter? options)
142 {
143 if (Utils.is_search_empty (search))
144 {
145- if (type_id == "all")
146+ if (options == null || !options.filtering)
147 return "type:Application";
148 else
149- return @"type:Application AND $(type_queries.lookup(type_id))";
150+ return "type:Application AND " + extract_type_query (options);
151 }
152 else
153 {
154@@ -592,10 +626,10 @@
155 * match 'd-feet' etc. */
156 s = s.delimit ("-", ' ');
157
158- if (type_id == "all")
159- return @"type:Application AND $s";
160+ if (options == null || !options.filtering)
161+ return "type:Application AND " + s;
162 else
163- return @"type:Application AND $(type_queries.lookup(type_id)) AND $s";
164+ return "type:Application AND %s AND %s".printf (extract_type_query (options), s);
165 }
166 }
167

Subscribers

People subscribed via source and target branches