170
171
var src_filter = new Unity.CheckOptionFilter ("sources", _("Sources"));
171
172
foreach (var node in ScopeRegistry.instance ().scopes)
173
debug ("Category filter add: %s", node.scope_info.id);
174
cat_filter.add_option (node.scope_info.id, node.scope_info.name); //add master scope id to 'Categories'
174
if (node.scope_info.visible)
176
debug ("Category filter add: %s", node.scope_info.id);
177
cat_filter.add_option (node.scope_info.id, node.scope_info.name); //add master scope id to 'Categories'
175
179
foreach (var scope in node.sub_scopes)
177
debug ("Sources filter add: %s", scope.id);
178
src_filter.add_option (scope.id, scope.name);
181
if (scope.visible) // should we also hide subsope if master is not visible?
183
debug ("Sources filter add: %s", scope.id);
184
src_filter.add_option (scope.id, scope.name);
181
188
src_filter.show_all_button = false;
408
415
// may map to null, in that case there is no filtering based on sub-scopes (all subscopes of given master will be queried).
409
416
var search_scopes = new HashTable<string, Gee.Set<string>?> (str_hash, str_equal);
411
// apply user filters only if search string is unchanged (or smart scopes are disabled completly).
418
// filters are updated during the search, but may need to be updated again afterwards if we find out there wero no results for some categories
419
bool needs_filter_update = false;
421
// default filter view flag; default view is kind of a special case that kicks in when search query is empty:
422
// user can modify filters at will, and they are stored in gsettings key.
423
// this flag prevents filter updates based on what scopes were actually searched and if they had results, so that user can comfortably
424
// edit the all the filters without loosing them every second.
425
bool default_view = false;
427
bool empty_query = (scope_search.search_string.strip ().length == 0);
429
// apply user filters only if search string is unchanged, the query is empty or smart scopes are disabled completly.
412
430
// this mean user set filters *after* entering a query and we apply them;
413
431
// otherwise smart scopes recommendations will take precedence.
414
if (search_query_changed == SearchQueryChange.NOT_CHANGED || sss_client == null)
432
// if search query is empty, then apply default user's filters.
433
if (search_query_changed == SearchQueryChange.NOT_CHANGED || empty_query || sss_client == null)
435
// if query is empty but it's not just a filter change (i.e. state is REMOVES_FROM_PREVIOUS_QUERY or NEW_QUERY),
436
// then apply default user filters.
437
if (empty_query && search_query_changed != SearchQueryChange.NOT_CHANGED)
439
var default_filters = scope_mgr.home_lens_default_view;
440
if (default_filters.length > 0)
442
debug ("Empty query, applying default filter view");
443
needs_filter_update |= FilterState.set_filters (scope_search, default_filters);
448
debug ("Updating filter interrelationships");
449
needs_filter_update |= filter_state.update_filter_relations (scope_search);
450
debug ("Filter interrelationships changed: %s", needs_filter_update.to_string ());
415
452
SearchUtil.scopes_to_query_from_filters (scope_search.get_filter ("sources") as Unity.OptionsFilter,
416
453
scope_search.get_filter ("categories") as Unity.OptionsFilter,
456
// if this search request is a filter change only, then update user's default view in gsettings
457
if (search_query_changed == SearchQueryChange.NOT_CHANGED && empty_query)
460
debug ("Updating user's default filter view");
461
scope_mgr.home_lens_default_view = SearchUtil.scopes_to_query_to_array (search_scopes);
419
465
// initiate Smart Scopes Search (if enabled and query not empty)
420
466
if (smart_scopes_ready == true)
422
if (search_query_changed == SearchQueryChange.EMPTY_QUERY)
424
470
if (channel_id_map.has_session_id_for_channel (scope_search.channel_id))
530
579
bool use_recommended_scopes = false;
532
// filters are updated during the search, but may need to be updated again afterwards if we find out there wero no results for some categories
533
bool needs_filter_update = false;
535
581
// dispatch search to scopes recommended by smart scopes service
536
if (smart_scopes_ready && search_query_changed != SearchQueryChange.EMPTY_QUERY)
582
if (smart_scopes_ready && !empty_query)
538
584
// wait for smart scopes service query to finish
539
585
if (wait_for_sss_query_finished == true)
552
598
if (search_query_changed != SearchQueryChange.NOT_CHANGED && !direct_search && recommended_search_scopes.length () > 0)
553
599
use_recommended_scopes = true;
555
debug ("Updating filter state");
556
var filters = SearchUtil.update_filters (search_scopes, use_recommended_scopes ? recommended_search_scopes : null, scope_search, false, out needs_filter_update);
601
// only update filters with searched scopes when not in the default view, otherwise default view filters may get de-selected
604
debug ("Updating filter state");
605
needs_filter_update |= SearchUtil.update_filters (search_scopes, use_recommended_scopes ? recommended_search_scopes : null,
606
scope_search, false);
609
if (needs_filter_update)
611
var filters = FilterState.create_filter_set (scope_search);
559
612
debug ("Sending updated filters");
560
613
scope_search.push_filter_settings (filters);
602
655
debug ("search finished");
604
//FIXME: make sure we're synchronized after pushing data
606
657
signal_categories_order (scope_search, recommended_search_scopes);
608
659
// update filter state again, but this time check result counts and send the update only if any of the highlighted masters has no results
609
filters = SearchUtil.update_filters (search_scopes, use_recommended_scopes ? recommended_search_scopes : null, scope_search, true, out needs_filter_update);
610
if (filters != null && needs_filter_update)
661
needs_filter_update |= SearchUtil.update_filters (search_scopes, use_recommended_scopes ? recommended_search_scopes : null, scope_search, true);
663
if (needs_filter_update)
665
var filters = FilterState.create_filter_set (scope_search);
612
666
debug ("Sending updated filters");
613
667
scope_search.push_filter_settings (filters);