~kamstrup/unity-lens-files/gi-friendly-api-tweaks

« back to all changes in this revision

Viewing changes to src/daemon.vala

  • Committer: Mikkel Kamstrup Erlandsen
  • Date: 2011-03-23 10:17:22 UTC
  • mfrom: (162.1.3 folder-search)
  • Revision ID: mikkel.kamstrup@gmail.com-20110323101722-o3dd05bazz8r4jce
Merge Mikkel's branch lp:~kamstrup/unity-place-files/folder-search:

 * Make bookmarked folders searchable

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    private Zeitgeist.Index index;
45
45
    private Zeitgeist.Monitor monitor;
46
46
 
 
47
    private Bookmarks bookmarks;
 
48
 
47
49
    private Unity.PlaceController control;
48
50
    private Unity.PlaceEntryInfo files;
49
51
    private Unity.Browser<BrowsingState> browser;
131
133
 
132
134
      log = new Zeitgeist.Log();
133
135
      index = new Zeitgeist.Index();
 
136
      
 
137
      bookmarks = new Bookmarks ();
134
138
 
135
139
      /* Listen for section changes */
136
140
      files.notify["active-section"].connect (
586
590
      var templates = section_templates.get((int)Section.ALL_FILES);
587
591
      
588
592
      try {
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(),
593
597
                                          templates,
594
598
                                          Zeitgeist.StorageState.ANY,
595
 
                                          50,
 
599
                                          20,
596
600
                                          ResultType.MOST_RECENT_SUBJECTS,
597
601
                                          null);
598
602
        
601
605
               results.size (), results.estimated_matches (),
602
606
               search_string, timer.elapsed()*1000);
603
607
 
 
608
 
 
609
        var bookmark_matches = bookmarks.prefix_search (search.get_search_string());
 
610
 
 
611
        /* Clean up results model */
604
612
        if (!is_filter_search)
605
613
          {
606
614
            /* Don't clear the results before the first ones are ready */
607
615
            results_model.clear ();
 
616
            
 
617
            append_bookmarks (bookmark_matches, results_model, Group.TOP_RESULTS);
608
618
            Unity.FilesPlace.append_events_sorted (results,
609
619
                                                   results_model,
610
620
                                                   groups_model,
614
624
        else
615
625
          {
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);
 
629
            
 
630
            foreach (var bookmark in bookmark_matches)
 
631
              {
 
632
                valid_uris.add (bookmark.uri);
 
633
              }
 
634
            
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);
697
713
 
 
714
        /* Clean up results model */
698
715
        if (!is_filter_search)
699
716
          {
700
717
            /* Don't clear the results before the first ones are ready */
713
730
              }
714
731
          }
715
732
        
 
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);
 
739
        
716
740
        var seen_uris = Unity.FilesPlace.append_events_sorted (results,
717
 
                                                                results_model,
718
 
                                                                groups_model,
719
 
                                                                section,
720
 
                                                                Group.TOP_RESULTS);
 
741
                                                               results_model,
 
742
                                                               groups_model,
 
743
                                                               section,
 
744
                                                               Group.TOP_RESULTS);
721
745
        
722
746
        /* Get time-grouped results */
723
747
        var result_type = section == Section.FOLDERS ?
871
895
        
872
896
        if (section == Section.ALL_FILES)
873
897
          {
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);
876
900
          }
877
901
 
895
919
      });
896
920
    }
897
921
 
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)
900
925
    {
901
 
      // FIXME: Monitor bookmarks file and update on changes
902
 
      string contents;
903
 
      
904
 
      try {
905
 
        var favorites_file = @"$(Environment.get_home_dir())/.gtk-bookmarks";
906
 
        FileUtils.get_contents (favorites_file, out contents);
907
 
        
908
 
      } catch (FileError e) {
909
 
        warning ("Failed to read favorites: %s", e.message);
910
 
        return;
911
 
      }
912
 
      
913
 
      string[] favorites = contents.split ("\n");
914
 
      string mimetype = "inode/directory";
915
 
      
916
 
      foreach (var uri in favorites)
 
926
      foreach (var bookmark in bookmarks)
917
927
      {
918
 
        if (uri == "")
919
 
          continue;
920
 
              
921
 
        string[] parts = uri.split (" ", 2);
922
 
        string display_name;
923
 
        
924
 
        if (parts.length == 1)
925
 
          {
926
 
            display_name = Uri.unescape_string (uri);
927
 
            display_name = Filename.display_basename (display_name);
928
 
          }
929
 
        else if (parts.length == 2)
930
 
          {
931
 
            uri = parts[0];
932
 
            display_name = parts[1];
933
 
          }
934
 
        else
935
 
          {
936
 
            warning ("Internal error computing display name for favorite '%s'",
937
 
                     uri);
938
 
            display_name = uri;
939
 
          }
940
 
        
941
 
        var icon = Utils.get_icon_for_uri (uri, mimetype);
942
 
        
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,
 
930
                              bookmark.uri);
945
931
      }
946
932
    }
947
933