Forgot to bump FSQ version. Weekend syndrome.
[beagle.git] / search / Tiles / File.cs
blobb888b5895ee00a54f6b00411cd234184a832c1e6
1 using System;
2 using System.Diagnostics;
3 using System.Runtime.InteropServices;
4 using Mono.Unix;
6 namespace Search.Tiles {
8 public class FileActivator : TileActivator {
10 public FileActivator () : base ()
12 AddSupportedFlavor (new HitFlavor (null, "File", null));
15 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
17 return new TileFile (hit, query);
21 public class TileFile : TileTemplate {
23 public TileFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
25 Title = GetTitle ();
26 EnableOpenWith = true;
28 if (Hit.FileInfo != null) {
29 Timestamp = Hit.FileInfo.LastWriteTime;
30 Description = Utils.NiceShortDate (Timestamp);
33 AddAction (new TileAction (Catalog.GetString ("Reveal in Folder"), RevealInFolder));
34 AddAction (new TileAction (Catalog.GetString ("E-Mail"), Email));
35 // AddAction (new TileAction (Catalog.GetString ("Instant-Message"), InstantMessage));
36 AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));
39 static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
41 protected override void LoadIcon (Gtk.Image image, int size)
43 if (!thumbnailer.SetThumbnailIcon (image, Hit, size))
44 base.LoadIcon (image, size);
47 private string GetTitle ()
49 string title = Hit.GetFirstProperty ("dc:title");
51 if (title == null || title == "")
52 title = Hit.GetFirstProperty ("beagle:ExactFilename");
54 return title;
57 public override void Open ()
59 base.OpenFromMime (Hit);
62 public void OpenWith ()
64 // FIXME: base.OpenWith
67 public void RevealInFolder ()
69 string path = Hit.FileInfo.DirectoryName;
71 Process p = new Process ();
72 p.StartInfo.UseShellExecute = false;
74 if ((! path.StartsWith ("\"")) && (! path.EndsWith ("\"")))
75 path = "\"" + path + "\"";
77 // FIXME: When nautilus implements this, then we should
78 // also select the file in the folder.
80 #if ENABLE_DESKTOP_LAUNCH
81 p.StartInfo.FileName = "desktop-launch";
82 p.StartInfo.Arguments = path;
83 #else
84 p.StartInfo.FileName = "nautilus";
85 p.StartInfo.Arguments = "--no-desktop " + path;
86 #endif
87 try {
88 p.Start ();
89 } catch (Exception e) {
90 Console.WriteLine ("Cannot open folder: " + e);
94 public void Email ()
96 Process p = new Process ();
97 p.StartInfo.UseShellExecute = false;
98 p.StartInfo.FileName = "evolution";
99 p.StartInfo.Arguments = String.Format ("\"mailto:?attach={0}\"", Hit.FileInfo.FullName);
101 try {
102 p.Start () ;
103 } catch (Exception e) {
104 Console.WriteLine ("Error launching Evolution composer: " + e);
108 public void InstantMessage ()
110 // FIXME: base.InstantMessage
113 public void MoveToTrash ()
115 // FIXME: Ask for confirmation
117 try {
118 // FIXME: Check if KDE uses ~/.Trash too (there is a spec at fd.o)
119 string trash_dir = System.IO.Path.Combine (Beagle.Util.PathFinder.HomeDir, ".Trash");
121 // FIXME: This throws an exception if the file exists
122 Hit.FileInfo.MoveTo (System.IO.Path.Combine (trash_dir, Hit.FileInfo.Name));
123 } catch (Exception e) {
124 Console.WriteLine (e);
128 protected override DetailsPane GetDetails ()
130 DetailsPane details = new DetailsPane ();
132 details.AddLabelPair (Catalog.GetString ("Title:"),
133 GetTitle (),
134 0, 1);
135 details.AddLabelPair (Catalog.GetString ("Last Edited:"),
136 Utils.NiceLongDate (Timestamp),
137 1, 1);
138 if (Hit ["dc:author"] != null) {
139 details.AddLabelPair (Catalog.GetString ("Author:"),
140 Hit ["dc:author"],
141 1, 3);
143 details.AddLabelPair (Catalog.GetString ("Full Path:"),
144 Hit.Uri.LocalPath,
145 2, 1);
146 details.AddSnippet (3, 1);
148 return details;