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
);
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
);
49 // FIXME: Multiple emblems
50 string emblem
= Hit
.GetFirstProperty ("fixme:emblem");
54 Gdk
.Pixbuf icon_pixbuf
= image
.Pixbuf
;
55 Gdk
.Pixbuf emblem_pixbuf
= WidgetFu
.LoadThemeIcon ("emblem-" + emblem
, 24);
57 Console
.WriteLine ("icon: {0} {1}x{2}", icon_pixbuf
, icon_pixbuf
.Width
, icon_pixbuf
.Height
);
58 Console
.WriteLine ("emblem: {0} {1}x{2}", emblem_pixbuf
, emblem_pixbuf
.Width
, emblem_pixbuf
.Height
);
60 if (icon_pixbuf
== null || emblem_pixbuf
== null)
63 // If the icon itself is smaller than our requested
64 // emblem, just display the emblem.
65 if (icon_pixbuf
.Height
< emblem_pixbuf
.Height
|| icon_pixbuf
.Width
< emblem_pixbuf
.Width
) {
66 image
.Pixbuf
= emblem_pixbuf
;
70 emblem_pixbuf
.Composite (icon_pixbuf
, 0,
71 icon_pixbuf
.Height
- emblem_pixbuf
.Height
,
72 emblem_pixbuf
.Width
, emblem_pixbuf
.Height
,
73 0, 0, 1, 1, Gdk
.InterpType
.Bilinear
, 255);
74 //image.Pixbuf = icon_pixbuf;
77 protected static string GetTitle (Beagle
.Hit hit
, bool get_parent
)
82 title
= Utils
.GetFirstPropertyOfParent (hit
, "dc:title");
84 title
= hit
.GetFirstProperty ("dc:title");
86 if (title
== null || title
== "") {
88 title
= Utils
.GetFirstPropertyOfParent (hit
, "beagle:ExactFilename");
90 title
= hit
.GetFirstProperty ("beagle:ExactFilename");
96 protected static string GetTitle (Beagle
.Hit hit
)
98 return GetTitle (hit
, false);
101 public override void Open ()
103 base.OpenFromMime (Hit
);
106 public void OpenWith ()
108 // FIXME: base.OpenWith
111 public void RevealInFolder ()
113 string path
= Hit
.FileInfo
.DirectoryName
;
115 // FIXME: When nautilus implements this, then we should
116 // also select the file in the folder.
118 SafeProcess p
= new SafeProcess ();
120 #if ENABLE_DESKTOP_LAUNCH
121 p
.Arguments
= new string [] { "desktop-launch", path }
;
122 #elif ENABLE_XDG_OPEN
123 p
.Arguments
= new string [] { "xdg-open", path }
;
125 p
.Arguments
= new string [] { "nautilus", "--no-desktop", path }
;
129 } catch (Exception e
) {
130 Console
.WriteLine ("Cannot open folder: " + e
);
137 OpenFromUri (String
.Format ("mailto:?attach={0}", Hit
.FileInfo
.FullName
));
138 } catch (Exception e
) {
139 Console
.WriteLine ("Error sending email: " + e
);
143 public void InstantMessage ()
145 // FIXME: base.InstantMessage
148 public void MoveToTrash ()
150 // FIXME: Ask for confirmation
153 // FIXME: Check if KDE uses ~/.Trash too (there is a spec at fd.o)
154 string trash_dir
= System
.IO
.Path
.Combine (Beagle
.Util
.PathFinder
.HomeDir
, ".Trash");
156 // FIXME: This throws an exception if the file exists
157 Hit
.FileInfo
.MoveTo (System
.IO
.Path
.Combine (trash_dir
, Hit
.FileInfo
.Name
));
158 } catch (Exception e
) {
159 Console
.WriteLine (e
);
163 protected override DetailsPane
GetDetails ()
165 DetailsPane details
= new DetailsPane ();
167 details
.AddLabelPair (Catalog
.GetString ("Title:"), GetTitle (Hit
));
168 details
.AddLabelPair (Catalog
.GetString ("Last Edited:"), Utils
.NiceLongDate (Timestamp
));
170 if (Hit
["dc:author"] != null)
171 details
.AddLabelPair (Catalog
.GetString ("Author:"), Hit
["dc:author"]);
173 details
.AddLabelPair (Catalog
.GetString ("Full Path:"), Hit
.Uri
.LocalPath
);
174 details
.AddSnippet ();