2
using System.Diagnostics;
3
using System.Runtime.InteropServices;
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 (hit);
28
if (Hit.FileInfo != null) {
29
Timestamp = Hit.FileInfo.LastWriteTimeUtc;
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));
38
if (! String.IsNullOrEmpty (Hit.GetFirstProperty("dc:author"))) {
39
AddAction(new TileAction ("Find Documents From Same Author", Gtk.Stock.Find, FindSameAuthor));
42
EnableOpenWith = true;
45
static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
47
protected override void LoadIcon (Gtk.Image image, int size)
49
// The File tile doesn't respect the icon size because
50
// 48 is too small for thumbnails
51
if (!thumbnailer.SetThumbnailIcon (image, Hit, size))
52
base.LoadIcon (image, size);
54
// FIXME: Multiple emblems
55
string emblem = Hit.GetFirstProperty ("nautilus:emblem");
59
Gdk.Pixbuf icon_pixbuf = image.Pixbuf.Copy ();
60
Gdk.Pixbuf emblem_pixbuf = WidgetFu.LoadThemeIcon ("emblem-" + emblem, 24);
62
if (icon_pixbuf == null || emblem_pixbuf == null) {
63
if (icon_pixbuf != null)
64
icon_pixbuf.Dispose ();
66
if (emblem_pixbuf == null)
67
emblem_pixbuf.Dispose ();
72
// If the icon itself is smaller than our requested
73
// emblem, just display the emblem.
74
if (icon_pixbuf.Height < emblem_pixbuf.Height || icon_pixbuf.Width < emblem_pixbuf.Width) {
75
icon_pixbuf.Dispose ();
76
image.Pixbuf.Dispose ();
77
image.Pixbuf = emblem_pixbuf;
81
emblem_pixbuf.Composite (icon_pixbuf, 0, 0,
82
emblem_pixbuf.Width, emblem_pixbuf.Height,
83
0, 0, 1, 1, Gdk.InterpType.Bilinear, 255);
84
image.Pixbuf.Dispose ();
85
image.Pixbuf = icon_pixbuf;
88
protected static string GetTitle (Beagle.Hit hit, bool get_parent)
93
title = Utils.GetFirstPropertyOfParent (hit, "dc:title");
95
title = hit.GetFirstProperty ("dc:title");
97
if (title == null || title == "") {
99
title = Utils.GetFirstPropertyOfParent (hit, "beagle:ExactFilename");
101
title = hit.GetFirstProperty ("beagle:ExactFilename");
107
protected static string GetTitle (Beagle.Hit hit)
109
return GetTitle (hit, false);
112
public override void Open ()
114
base.OpenFromMime (Hit);
117
public void OpenWith ()
119
// FIXME: base.OpenWith
122
public void RevealInFolder ()
124
string path = Hit.FileInfo.DirectoryName;
126
// FIXME: When nautilus implements this, then we should
127
// also select the file in the folder.
129
SafeProcess p = new SafeProcess ();
131
#if ENABLE_DESKTOP_LAUNCH
132
p.Arguments = new string [] { "desktop-launch", path };
133
#elif ENABLE_XDG_OPEN
134
p.Arguments = new string [] { "xdg-open", path };
136
p.Arguments = new string [] { "nautilus", "--no-desktop", path };
140
} catch (Exception e) {
141
Console.WriteLine ("Cannot open folder: " + e);
148
OpenFromUri (String.Format ("mailto:?attach={0}", Hit.FileInfo.FullName));
149
} catch (Exception e) {
150
Console.WriteLine ("Error sending email: " + e);
154
public void InstantMessage ()
156
// FIXME: base.InstantMessage
159
public void MoveToTrash ()
161
// FIXME: Ask for confirmation
164
// FIXME: Check if KDE uses ~/.Trash too (there is a spec at fd.o)
165
string trash_dir = System.IO.Path.Combine (Beagle.Util.PathFinder.HomeDir, ".Trash");
167
// FIXME: This throws an exception if the file exists
168
Hit.FileInfo.MoveTo (System.IO.Path.Combine (trash_dir, Hit.FileInfo.Name));
169
} catch (Exception e) {
170
Console.WriteLine (e);
174
protected override DetailsPane GetDetails ()
176
DetailsPane details = new DetailsPane ();
178
details.AddLabelPair (Catalog.GetString ("Title:"), GetTitle (Hit));
179
details.AddLabelPair (Catalog.GetString ("Last Edited:"), Utils.NiceLongDate (Timestamp));
181
if (Hit ["dc:author"] != null)
182
details.AddLabelPair (Catalog.GetString ("Author:"), Hit ["dc:author"]);
184
details.AddLabelPair (Catalog.GetString ("Full Path:"), Hit.Uri.LocalPath);
185
details.AddSnippet ();
190
public void FindSameAuthor()
192
SafeProcess p = new SafeProcess ();
193
string author = Hit.GetFirstProperty("dc:author");
194
if( String.IsNullOrEmpty(author))
195
author = Hit.GetFirstProperty("dc:creator");
196
p.Arguments = new string [] { "beagle-search", String.Format ("author:{0} OR creator:{0}", author) };
199
} catch (Exception e) {
200
Console.WriteLine ("Error launching new search: " + e.Message);