Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / Tiles / File.cs
blobb3f257278eaa7bba5fe159eaa040d539c7b56756
1 using System;
2 using System.Diagnostics;
3 using System.Runtime.InteropServices;
4 using Mono.Unix;
5 using Beagle.Util;
7 namespace Search.Tiles {
9 public class FileActivator : TileActivator {
11 public FileActivator () : base ()
13 AddSupportedFlavor (new HitFlavor (null, "File", null));
16 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
18 return new TileFile (hit, query);
22 public class TileFile : TileTemplate {
24 public TileFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
26 Title = GetTitle ();
27 EnableOpenWith = true;
29 if (Hit.FileInfo != null) {
30 Timestamp = Hit.FileInfo.LastWriteTimeUtc;
31 Description = Utils.NiceShortDate (Timestamp);
34 AddAction (new TileAction (Catalog.GetString ("Reveal in Folder"), RevealInFolder));
35 AddAction (new TileAction (Catalog.GetString ("E-Mail"), Email));
36 // AddAction (new TileAction (Catalog.GetString ("Instant-Message"), InstantMessage));
37 AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));
40 static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
42 protected override void LoadIcon (Gtk.Image image, int size)
44 // The File tile doesn't respect the icon size because
45 // 48 is too small for thumbnails
46 if (!thumbnailer.SetThumbnailIcon (image, Hit, size))
47 base.LoadIcon (image, size);
50 private string GetTitle ()
52 string title = Hit.GetFirstProperty ("dc:title");
54 if (title == null || title == "")
55 title = Hit.GetFirstProperty ("beagle:ExactFilename");
57 return title;
60 public override void Open ()
62 base.OpenFromMime (Hit);
65 public void OpenWith ()
67 // FIXME: base.OpenWith
70 public void RevealInFolder ()
72 string path = Hit.FileInfo.DirectoryName;
74 // FIXME: When nautilus implements this, then we should
75 // also select the file in the folder.
77 SafeProcess p = new SafeProcess ();
79 #if ENABLE_DESKTOP_LAUNCH
80 p.Arguments = new string [] { "desktop-launch", path };
81 #else
82 p.Arguments = new string [] { "nautilus", "--no-desktop", path };
83 #endif
84 try {
85 p.Start ();
86 } catch (Exception e) {
87 Console.WriteLine ("Cannot open folder: " + e);
91 public void Email ()
93 try {
94 OpenFromUri (String.Format ("mailto:?attach={0}", Hit.FileInfo.FullName));
95 } catch (Exception e) {
96 Console.WriteLine ("Error sending email: " + e);
100 public void InstantMessage ()
102 // FIXME: base.InstantMessage
105 public void MoveToTrash ()
107 // FIXME: Ask for confirmation
109 try {
110 // FIXME: Check if KDE uses ~/.Trash too (there is a spec at fd.o)
111 string trash_dir = System.IO.Path.Combine (Beagle.Util.PathFinder.HomeDir, ".Trash");
113 // FIXME: This throws an exception if the file exists
114 Hit.FileInfo.MoveTo (System.IO.Path.Combine (trash_dir, Hit.FileInfo.Name));
115 } catch (Exception e) {
116 Console.WriteLine (e);
120 protected override DetailsPane GetDetails ()
122 DetailsPane details = new DetailsPane ();
124 details.AddLabelPair (Catalog.GetString ("Title:"), GetTitle ());
125 details.AddLabelPair (Catalog.GetString ("Last Edited:"), Utils.NiceLongDate (Timestamp));
127 if (Hit ["dc:author"] != null)
128 details.AddLabelPair (Catalog.GetString ("Author:"), Hit ["dc:author"]);
130 details.AddLabelPair (Catalog.GetString ("Full Path:"), Hit.Uri.LocalPath);
131 details.AddSnippet ();
133 return details;