89
85
urls = new UrlChecker ();
91
87
/* Listen for filter changes */
92
scope.filters_changed.connect (
94
if (scope.active_search != null)
97
scope.notify_property ("active-search");
88
scope.filters_changed.connect (() => {
89
scope.queue_search_changed (SearchType.DEFAULT);
92
scope.generate_search_key.connect ((lens_search) => {
93
return lens_search.search_string.strip ();
102
96
/* Listen for changes to the lens entry search */
103
scope.notify["active-search"].connect (
105
var search = scope.active_search;
107
if (!(Utils.search_has_really_changed (previous_search, search) || is_dirty))
112
if (search_is_invalid (search))
114
update_without_search_async.begin(search);
118
update_search_async.begin (search);
120
previous_search = search;
124
/* Listen for changes to the global search */
125
scope.notify["active-global-search"].connect (
128
var search = scope.active_global_search;
130
if (search_is_invalid (search))
133
if (!Utils.search_has_really_changed (previous_search, search))
136
update_global_search_async.begin (search);
137
previous_search = search;
97
scope.search_changed.connect ((lens_search, search_type, cancellable) =>
99
dispatch_search.begin (lens_search, search_type, cancellable);
105
private async void dispatch_search (LensSearch lens_search,
106
SearchType search_type,
107
Cancellable cancellable)
109
if (search_type == SearchType.GLOBAL)
111
yield update_global_search_async (lens_search, cancellable);
115
yield update_search_async (lens_search, cancellable);
118
// make sure we don't forget to emit this (if we didn't get cancelled)
119
if (!cancellable.is_cancelled ()) lens_search.finished ();
144
122
private void populate_filters ()
146
124
var filters = new GLib.List<Unity.Filter> ();
327
private async void update_global_search_async (LensSearch search)
305
private async void update_global_search_async (LensSearch search,
306
Cancellable cancellable)
329
var results_model = scope.global_results_model;
308
var results_model = search.results_model;
331
310
if (search_is_invalid (search))
337
/* Prevent concurrent searches and concurrent updates of our models,
338
* by preventing any notify signals from propagating to us.
339
* Important: Remeber to thaw the notifys again! */
340
scope.freeze_notify ();
342
316
var search_string = prepare_search_string (search);
344
318
var templates = new PtrArray.sized(1);
379
353
Unity.FilesLens.append_events_sorted (results, results_model,
380
354
min_size, max_size, false);
356
} catch (IOError.CANCELLED ioe) {
382
358
} catch (GLib.Error e) {
383
359
warning ("Error performing global search '%s': %s",
384
360
search.search_string, e.message);
387
/* Allow new searches once we enter an idle again.
388
* We don't do it directly from here as that could mean we start
389
* changing the model even before we had flushed out current changes
392
scope.thaw_notify ();
399
private async void update_search_async (LensSearch search)
364
private async void update_search_async (LensSearch search,
365
Cancellable cancellable)
401
367
if (search_is_invalid (search))
403
update_without_search_async.begin (search);
369
yield update_without_search_async (search, cancellable);
407
var results_model = scope.results_model;
373
var results_model = search.results_model;
409
/* Prevent concurrent searches and concurrent updates of our models,
410
* by preventing any notify signals from propagating to us.
411
* Important: Remeber to thaw the notifys again! */
412
scope.freeze_notify ();
414
375
var search_string = prepare_search_string (search);
416
377
string type_id = get_current_type ();
460
420
min_size, max_size,
461
421
origin_grouping);
463
yield update_downloads_async (results_model, search.search_string);
423
yield update_downloads_async (results_model, cancellable,
424
search.search_string);
426
} catch (IOError.CANCELLED ioe) {
465
428
} catch (GLib.Error e) {
466
429
warning ("Error performing global search '%s': %s",
467
430
search.search_string, e.message);
470
/* Allow new searches once we enter an idle again.
471
* We don't do it directly from here as that could mean we start
472
* changing the model even before we had flushed out current changes
475
scope.thaw_notify ();
482
434
private string get_current_type ()
577
private async void update_without_search_async (LensSearch search)
529
private async void update_without_search_async (LensSearch search,
530
Cancellable cancellable)
579
var results_model = scope.results_model;
532
var results_model = search.results_model;
581
/* Prevent concurrent searches and concurrent updates of our models,
582
* by preventing any notify signals from propagating to us.
583
* Important: Remeber to thaw the notifys again! */
584
scope.freeze_notify ();
586
534
string type_id = get_current_type ();
588
536
bool origin_grouping = type_id == "folders";
623
571
min_size, max_size,
624
572
origin_grouping);
626
yield update_downloads_async (results_model);
574
yield update_downloads_async (results_model, cancellable);
576
} catch (IOError.CANCELLED ioe) {
628
578
} catch (GLib.Error e) {
629
579
warning ("Error performing empty search: %s",
633
/* Allow new searches once we enter an idle again.
634
* We don't do it directly from here as that could mean we start
635
* changing the model even before we had flushed out current changes
638
scope.thaw_notify ();
645
584
private void append_bookmarks (GLib.List<Bookmark> bookmarks,
657
596
private async void update_downloads_async (Dee.Model results_model,
658
string? name_filter = null)
597
Cancellable cancellable, string? name_filter = null) throws IOError
660
599
// FIXME: Store the Downloads folder and update on changes
661
600
unowned string download_path =
673
612
download_path, e.message);
616
if (cancellable.is_cancelled ())
617
throw new IOError.CANCELLED ("Search was cancelled");
677
619
/* Sort files by mtime, we do an ugly nested ternary
678
620
* to avoid potential long/int overflow */
727
669
/* Emitting notify here will make us recheck if the search results
728
670
* need update. In the negative case this is a noop */
730
scope.notify_property ("active-search");
671
// FIXME: no it isn't a noop
672
scope.queue_search_changed (SearchType.DEFAULT);
735
676
private const string ATTR_HIDDEN = FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
736
677
private const string ATTR_SIZE_AND_HIDDEN = FILE_ATTRIBUTE_STANDARD_SIZE +