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
)
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");
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 }
;
82 p
.Arguments
= new string [] { "nautilus", "--no-desktop", path }
;
86 } catch (Exception e
) {
87 Console
.WriteLine ("Cannot open folder: " + e
);
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
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 ();