~unity-team/unity-lens-files/unity-lens-files-0.6

« back to all changes in this revision

Viewing changes to src/daemon.vala

  • Committer: Michal Hruby
  • Date: 2011-09-22 13:32:02 UTC
  • mfrom: (189.1.3 unity-lens-files)
  • Revision ID: michal.mhr@gmail.com-20110922133202-99v10rio8qcjxdz4
MergeĀ fromĀ <lp:~mhr3/unity-lens-files/folder-fixes>

Show diffs side-by-side

added added

removed removed

Lines of Context:
376
376
        get_current_size_limits (out min_size, out max_size);
377
377
 
378
378
        Unity.FilesLens.append_events_sorted (results, results_model,
379
 
                                              min_size, max_size);
 
379
                                              min_size, max_size, false);
380
380
 
381
381
      } catch (GLib.Error e) {
382
382
        warning ("Error performing global search '%s': %s",
414
414
 
415
415
      string type_id = get_current_type ();
416
416
 
417
 
      var result_type = type_id == "folder" ? ResultType.MOST_RECENT_ORIGIN
418
 
                                            : ResultType.MOST_RECENT_SUBJECTS;
 
417
      bool origin_grouping = type_id == "folders";
 
418
      var result_type = origin_grouping ? ResultType.MOST_RECENT_ORIGIN
 
419
                                        : ResultType.MOST_RECENT_SUBJECTS;
419
420
 
420
421
      /* Grab the pre-compiled template we're going to use */
421
422
      var templates = new PtrArray.sized(1);
457
458
        /* FIXME: Add downloads */
458
459
        
459
460
        Unity.FilesLens.append_events_sorted (results, results_model,
460
 
                                              min_size, max_size);
 
461
                                              min_size, max_size,
 
462
                                              origin_grouping);
461
463
 
462
464
      } catch (GLib.Error e) {
463
465
        warning ("Error performing global search '%s': %s",
582
584
      
583
585
      string type_id = get_current_type ();
584
586
 
585
 
      var result_type = type_id == "folder" ? ResultType.MOST_RECENT_ORIGIN
586
 
                                            : ResultType.MOST_RECENT_SUBJECTS;
 
587
      bool origin_grouping = type_id == "folders";
 
588
      var result_type = origin_grouping ? ResultType.MOST_RECENT_ORIGIN
 
589
                                        : ResultType.MOST_RECENT_SUBJECTS;
 
590
 
587
591
 
588
592
      /* Grab the pre-compiled template we're going to use */
589
593
      var templates = new PtrArray.sized(1);
606
610
 
607
611
        results_model.clear ();
608
612
 
609
 
        if (type_id == "all" || type_id == "folder")
610
 
          append_bookmarks (bookmarks.list(), results_model);
 
613
        if (type_id == "all" || type_id == "folders")
 
614
        {
 
615
          append_bookmarks (bookmarks.list (), results_model, Categories.FOLDERS);
 
616
        }
611
617
 
612
618
        int64 min_size, max_size;
613
619
        get_current_size_limits (out min_size, out max_size);
615
621
        yield update_downloads_async (results_model);
616
622
 
617
623
        Unity.FilesLens.append_events_sorted (results, results_model,
618
 
                                              min_size, max_size);
 
624
                                              min_size, max_size,
 
625
                                              origin_grouping);
619
626
 
620
627
      } catch (GLib.Error e) {
621
628
        warning ("Error performing empty search: %s",
636
643
 
637
644
    private void append_bookmarks (GLib.List<Bookmark> bookmarks,
638
645
                                   Dee.Model results_model,
639
 
                                   Categories category = Categories.FOLDERS)
 
646
                                   Categories category)
640
647
    {
641
648
      foreach (var bookmark in bookmarks)
642
649
      {
727
734
   * these events are already sorted with descending timestamps */
728
735
  public void append_events_sorted (Zeitgeist.ResultSet events,
729
736
                                    Dee.Model results,
730
 
                                    int64 min_size, int64 max_size)
 
737
                                    int64 min_size, int64 max_size,
 
738
                                    bool use_origin)
731
739
  {
732
740
     foreach (var ev in events)
733
741
      {
735
743
          {
736
744
            // FIXME: We only use the first subject...
737
745
            Zeitgeist.Subject su = ev.get_subject(0);
738
 
            
739
 
            string uri = su.get_uri ();
740
 
            string display_name = su.get_text ();
741
 
            string mimetype = su.get_mimetype () != null ?
742
 
                          su.get_mimetype () : "application/octet-stream";
 
746
 
 
747
            string uri;
 
748
            string display_name;
 
749
            string mimetype;
 
750
 
 
751
            if (use_origin)
 
752
            {
 
753
              uri = su.get_origin ();
 
754
              display_name = "";
 
755
              mimetype = "inode/directory";
 
756
            }
 
757
            else
 
758
            {
 
759
              uri = su.get_uri ();
 
760
              display_name = su.get_text ();
 
761
              mimetype = su.get_mimetype ();
 
762
              mimetype = su.get_mimetype () != null ?
 
763
                         su.get_mimetype () : "application/octet-stream";
 
764
            }
 
765
            if (uri == null) continue;
743
766
            File file = File.new_for_uri (uri);
744
 
            
 
767
 
 
768
            if (display_name == null || display_name == "")
 
769
            {
 
770
              display_name = Path.get_basename (file.get_parse_name ());
 
771
            }
 
772
 
745
773
            bool check_size = min_size > 0 || max_size < int64.MAX;
746
774
            /* Don't check existence on non-native files as http:// and
747
775
             * friends are *very* expensive to query */
762
790
                continue;
763
791
              }
764
792
            }
765
 
#if 0    
766
 
            if (section == Section.FOLDERS)
767
 
              {
768
 
                File dir = File.new_for_uri(uri).get_parent();
769
 
                uri = dir.get_uri ();
770
 
                try{
771
 
                  FileInfo info = dir.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
772
 
                                                FileQueryInfoFlags.NONE);
773
 
                display_name = info.get_display_name ();
774
 
              } catch (GLib.Error e) {
775
 
                /* Bugger, we fall back to basename, which might not be
776
 
                 * valid UTF8... */
777
 
                warning ("Unable to get display name for %s", uri);
778
 
                display_name = dir.get_basename ();
779
 
              }
780
 
              mimetype = "inode/directory";
781
 
              }
782
 
#endif           
783
793
            string icon = Utils.get_icon_for_uri (uri, mimetype);
784
 
            
 
794
 
785
795
            uint category_id;
786
 
            string comment = "";
 
796
            string comment = file.get_parse_name ();
787
797
            
788
 
            category_id = file.query_file_type (0, null) == FileType.DIRECTORY ? Categories.FOLDERS
789
 
                                                                          : Categories.RECENT;
 
798
            category_id = file.query_file_type (0, null) == FileType.DIRECTORY ?
 
799
              Categories.FOLDERS : Categories.RECENT;
790
800
            results.append (uri, icon, category_id, mimetype,
791
801
                            display_name, comment);
792
 
            
 
802
 
793
803
          }
794
804
      }
795
805
   }