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
=== modified file 'configure.ac'
--- configure.ac 2012-01-24 11:30:08 +0000
+++ configure.ac 2012-01-26 14:02:36 +0000
@@ -15,7 +15,7 @@
15# Init the other things we depend on15# Init the other things we depend on
16#############################################16#############################################
17AM_MAINTAINER_MODE17AM_MAINTAINER_MODE
18AM_PROG_VALAC([0.12.1])18AM_PROG_VALAC([0.14.0])
19AS_IF([test -z "$VALAC"], [AC_MSG_ERROR(["No valac compiler found."])])19AS_IF([test -z "$VALAC"], [AC_MSG_ERROR(["No valac compiler found."])])
20AC_PROG_CC20AC_PROG_CC
21AC_PROG_CXX21AC_PROG_CXX
2222
=== modified file 'src/daemon.vala'
--- src/daemon.vala 2012-01-25 08:38:17 +0000
+++ src/daemon.vala 2012-01-26 14:02:36 +0000
@@ -249,7 +249,7 @@
249249
250 /* Type filter */250 /* Type filter */
251 {251 {
252 var filter = new RadioOptionFilter ("type", _("Type"));252 var filter = new CheckOptionFilter ("type", _("Type"));
253 filter.sort_type = Unity.OptionsFilter.SortType.DISPLAY_NAME;253 filter.sort_type = Unity.OptionsFilter.SortType.DISPLAY_NAME;
254 254
255 filter.add_option ("accessories", _("Accessories"));255 filter.add_option ("accessories", _("Accessories"));
@@ -358,7 +358,7 @@
358 }358 }
359359
360 private string prepare_zg_search_string (Unity.LensSearch search,360 private string prepare_zg_search_string (Unity.LensSearch search,
361 string type_id="all")361 OptionsFilter? options)
362 {362 {
363 string s = search.search_string.strip ();363 string s = search.search_string.strip ();
364 364
@@ -368,12 +368,12 @@
368 if (s != "")368 if (s != "")
369 s = @"app:($s)";369 s = @"app:($s)";
370 else370 else
371 return type_queries.lookup(type_id);371 return extract_type_query (options);
372 372
373 if (type_id == "all")373 if (options == null || !options.filtering)
374 return s;374 return s;
375 else375 else
376 return s + @" AND $(type_queries.lookup(type_id))";376 return s + " AND " + extract_type_query (options);
377 }377 }
378378
379 private async void update_scope_search (Unity.LensSearch search,379 private async void update_scope_search (Unity.LensSearch search,
@@ -385,17 +385,15 @@
385385
386 debug ("Searching for: %s", search.search_string);386 debug ("Searching for: %s", search.search_string);
387 387
388 var filter = scope.get_filter ("type") as RadioOptionFilter;388 var filter = scope.get_filter ("type") as OptionsFilter;
389 Unity.FilterOption? option = filter.get_active_option ();
390 string type_id = option == null ? "all" : option.id;
391389
392 string pkg_search_string = prepare_pkg_search_string (search, type_id);390 string pkg_search_string = prepare_pkg_search_string (search, filter);
393391
394 bool has_search = !Utils.is_search_empty (search);392 bool has_search = !Utils.is_search_empty (search);
395 393
396 Timer timer = new Timer ();394 Timer timer = new Timer ();
397395
398 var zg_search_string = prepare_zg_search_string (search, type_id);396 var zg_search_string = prepare_zg_search_string (search, filter);
399397
400 var transaction = new Dee.Transaction (model);398 var transaction = new Dee.Transaction (model);
401 transaction.clear ();399 transaction.clear ();
@@ -469,7 +467,7 @@
469 else467 else
470 {468 {
471 timer.start ();469 timer.start ();
472 string? filter_query = prepare_pkg_search_string (search, type_id);470 string? filter_query = prepare_pkg_search_string (search, filter);
473 var random_pkgresults = pkgsearcher.get_random_apps (filter_query, 12);471 var random_pkgresults = pkgsearcher.get_random_apps (filter_query, 12);
474 add_pkg_search_result (random_pkgresults, installed_uris, available_uris,472 add_pkg_search_result (random_pkgresults, installed_uris, available_uris,
475 model, Category.AVAILABLE, 6);473 model, Category.AVAILABLE, 6);
@@ -506,7 +504,7 @@
506 504
507 model.clear ();505 model.clear ();
508 506
509 var search_string = prepare_pkg_search_string (search, "all");507 var search_string = prepare_pkg_search_string (search, null);
510 Set<string> installed_uris = new HashSet<string> ();508 Set<string> installed_uris = new HashSet<string> ();
511 Set<string> available_uris = new HashSet<string> ();509 Set<string> available_uris = new HashSet<string> ();
512 var timer = new Timer ();510 var timer = new Timer ();
@@ -538,7 +536,7 @@
538 536
539 Timer timer = new Timer ();537 Timer timer = new Timer ();
540538
541 var zg_search_string = prepare_zg_search_string (search, "all");539 var zg_search_string = prepare_zg_search_string (search, null);
542540
543 if (local_apps_active () && display_recent_apps) {541 if (local_apps_active () && display_recent_apps) {
544 try {542 try {
@@ -569,15 +567,51 @@
569567
570 search.finished ();568 search.finished ();
571 }569 }
570
571 private const string[] option_types =
572 {
573 "accessories",
574 "education",
575 "game",
576 "graphics",
577 "internet",
578 "fonts",
579 "office",
580 "media",
581 "customization",
582 "accessibility",
583 "developer",
584 "science-and-engineering",
585 "system"
586 };
587
588 private string extract_type_query (OptionsFilter? options)
589 {
590 if (options == null || !options.filtering) return "NOT category:XYZ";
591
592 string? result = null;
593 foreach (unowned string type_id in option_types)
594 {
595 var option = options.get_option (type_id);
596 if (option == null) continue;
597 if (!option.active) continue;
598
599 if (result == null) result = type_queries[type_id];
600 else result += " OR " + type_queries[type_id];
601 }
602
603 return result == null ? "NOT category:XYZ" : result;
604 }
572 605
573 private string prepare_pkg_search_string (Unity.LensSearch search, string type_id="all")606 private string prepare_pkg_search_string (Unity.LensSearch search,
607 OptionsFilter? options)
574 {608 {
575 if (Utils.is_search_empty (search))609 if (Utils.is_search_empty (search))
576 {610 {
577 if (type_id == "all")611 if (options == null || !options.filtering)
578 return "type:Application";612 return "type:Application";
579 else613 else
580 return @"type:Application AND $(type_queries.lookup(type_id))";614 return "type:Application AND " + extract_type_query (options);
581 }615 }
582 else616 else
583 {617 {
@@ -592,10 +626,10 @@
592 * match 'd-feet' etc. */626 * match 'd-feet' etc. */
593 s = s.delimit ("-", ' ');627 s = s.delimit ("-", ' ');
594628
595 if (type_id == "all")629 if (options == null || !options.filtering)
596 return @"type:Application AND $s";630 return "type:Application AND " + s;
597 else631 else
598 return @"type:Application AND $(type_queries.lookup(type_id)) AND $s";632 return "type:Application AND %s AND %s".printf (extract_type_query (options), s);
599 }633 }
600 }634 }
601 635

Subscribers

People subscribed via source and target branches