44
44
private Zeitgeist.Index index;
45
45
private Zeitgeist.Monitor monitor;
47
private Bookmarks bookmarks;
47
49
private Unity.PlaceController control;
48
50
private Unity.PlaceEntryInfo files;
49
51
private Unity.Browser<BrowsingState> browser;
132
134
log = new Zeitgeist.Log();
133
135
index = new Zeitgeist.Index();
137
bookmarks = new Bookmarks ();
135
139
/* Listen for section changes */
136
140
files.notify["active-section"].connect (
586
590
var templates = section_templates.get((int)Section.ALL_FILES);
589
/* Get relevancy ranked results for the "Top Results" group */
593
/* Get results ranked by recency */
590
594
var timer = new Timer ();
591
595
var results = yield index.search (search_string,
592
596
new Zeitgeist.TimeRange.anytime(),
594
598
Zeitgeist.StorageState.ANY,
596
600
ResultType.MOST_RECENT_SUBJECTS,
601
605
results.size (), results.estimated_matches (),
602
606
search_string, timer.elapsed()*1000);
609
var bookmark_matches = bookmarks.prefix_search (search.get_search_string());
611
/* Clean up results model */
604
612
if (!is_filter_search)
606
614
/* Don't clear the results before the first ones are ready */
607
615
results_model.clear ();
617
append_bookmarks (bookmark_matches, results_model, Group.TOP_RESULTS);
608
618
Unity.FilesPlace.append_events_sorted (results,
616
626
/* Remove all rows from the results_model that are not
617
* in the new result set */
627
* in the new result set or matching bookmarks */
618
628
Set<string> valid_uris = Utils.get_uri_set (results);
630
foreach (var bookmark in bookmark_matches)
632
valid_uris.add (bookmark.uri);
619
635
unowned ModelIter iter = results_model.get_first_iter();
620
636
unowned ModelIter end = results_model.get_last_iter ();
621
637
unowned ModelIter current_row;
695
711
results.size (), results.estimated_matches (),
696
712
search_string, timer.elapsed()*1000);
714
/* Clean up results model */
698
715
if (!is_filter_search)
700
717
/* Don't clear the results before the first ones are ready */
733
/* First add any matching folder bookmarks.
734
* Note: This only works without dupes on incremental search
735
* because the folders are in the Top Results group which we
736
* always clean out on each update */
737
var bookmark_matches = bookmarks.prefix_search (search.get_search_string());
738
append_bookmarks (bookmark_matches, results_model, Group.TOP_RESULTS);
716
740
var seen_uris = Unity.FilesPlace.append_events_sorted (results,
722
746
/* Get time-grouped results */
723
747
var result_type = section == Section.FOLDERS ?
872
896
if (section == Section.ALL_FILES)
874
yield update_favorites_async (results_model, groups_model);
898
append_bookmarks (bookmarks.list(), results_model);
875
899
yield update_downloads_async (results_model, groups_model);
898
private async void update_favorites_async (Dee.Model results_model,
899
Dee.Model groups_model)
922
private void append_bookmarks (GLib.List<Bookmark> bookmarks,
923
Dee.Model results_model,
924
Group group = Group.FAVORITE_FOLDERS)
901
// FIXME: Monitor bookmarks file and update on changes
905
var favorites_file = @"$(Environment.get_home_dir())/.gtk-bookmarks";
906
FileUtils.get_contents (favorites_file, out contents);
908
} catch (FileError e) {
909
warning ("Failed to read favorites: %s", e.message);
913
string[] favorites = contents.split ("\n");
914
string mimetype = "inode/directory";
916
foreach (var uri in favorites)
926
foreach (var bookmark in bookmarks)
921
string[] parts = uri.split (" ", 2);
924
if (parts.length == 1)
926
display_name = Uri.unescape_string (uri);
927
display_name = Filename.display_basename (display_name);
929
else if (parts.length == 2)
932
display_name = parts[1];
936
warning ("Internal error computing display name for favorite '%s'",
941
var icon = Utils.get_icon_for_uri (uri, mimetype);
943
results_model.append (uri, icon, Group.FAVORITE_FOLDERS,
944
mimetype, display_name, uri);
928
results_model.append (bookmark.uri, bookmark.icon, group,
929
bookmark.mimetype, bookmark.display_name,