2 using System
.Diagnostics
;
7 namespace Search
.Tiles
{
9 public class ImageActivator
: TileActivator
{
11 public ImageActivator () : base ()
13 AddSupportedFlavor (new HitFlavor (null, "File", "image/*"));
16 public override Tile
BuildTile (Beagle
.Hit hit
, Beagle
.Query query
)
18 return new Image (hit
, query
);
22 public class Image
: TileFile
{
24 public Image (Beagle
.Hit hit
, Beagle
.Query query
) : base (hit
, query
)
26 Group
= TileGroup
.Image
;
28 Title
= Hit
["beagle:ExactFilename"];
30 if (Hit
["beagle:FilenameExtension"] != null && Hit
["beagle:FilenameExtension"].Length
> 0)
31 Description
= Hit
["beagle:FilenameExtension"].Substring (1).ToUpper ();
33 if (Hit
["fixme:width"] != null && Hit
["fixme:width"] != "")
34 Description
+= String
.Format (" {0}x{1}", Hit
["fixme:width"], Hit
["fixme:height"]);
36 Description
+= String
.Format (" ({0})", StringFu
.FileLengthToString (Hit
.FileInfo
.Length
));
38 // AddAction (new TileAction (Catalog.GetString ("Add to Library"), Gtk.Stock.Add, AddToLibrary));
39 AddAction (new TileAction (Catalog
.GetString ("Set as Wallpaper"), SetAsWallpaper
));
42 protected override void LoadIcon (Gtk
.Image image
, int size
)
44 base.LoadIcon (image
, size
);
46 // Draw the F-Spot overlay
47 if (size
> 32 && Hit
["fspot:IsIndexed"] == "true") {
48 Gdk
.Pixbuf icon
= image
.Pixbuf
.Copy ();
49 Gdk
.Pixbuf emblem
= Beagle
.Images
.GetPixbuf ("emblem-fspot.png", 24, 24);
51 if (icon
== null || emblem
== null)
54 // FIXME: Ideally we'd composite into a fresh new pixbuf of
55 // the correct size in this case, but really, who's going to
56 // have images shorter or narrower than 16 pixels in f-spot??
57 if (icon
.Height
< emblem
.Height
|| icon
.Width
< emblem
.Width
)
60 emblem
.Composite (icon
, 0, icon
.Height
- emblem
.Height
, emblem
.Width
,
61 emblem
.Height
, 0, icon
.Height
- emblem
.Height
, 1, 1,
62 Gdk
.InterpType
.Bilinear
, 255);
64 image
.Pixbuf
.Dispose ();
69 protected override DetailsPane
GetDetails ()
71 DetailsPane details
= new DetailsPane ();
73 // FIXME: The icon needs a nice frame as in the spec (?)
75 details
.AddTitleLabel (Title
);
76 details
.AddTextLabel (Description
);
77 details
.AddNewLine ();
79 details
.AddLabelPair (Catalog
.GetString ("Modified:"), Utils
.NiceVeryLongDate (Hit
.FileInfo
.LastWriteTime
));
80 details
.AddLabelPair (Catalog
.GetString ("Full Path:"), Hit
.Uri
.LocalPath
);
82 if (Hit
["fspot:Description"] != null && Hit
["fspot:Description"] != "") {
83 details
.AddNewLine ();
84 details
.AddTextLabel (Hit
["fspot:Description"]);
91 // FIXME: fspot doesnt allow to import a particular file
92 // only a whole directory
93 public void AddToLibrary ()
95 // FIXME: check if f-spot is installed
97 if (Hit
["fspot:IsIndexed"] == "true")
100 SafeProcess p
= new SafeProcess ();
101 p
.Arguments
= new string[] { "f-spot", "--import", Hit.FileInfo.FullName }
;
105 } catch (Exception e
) {
106 Console
.WriteLine ("Error launching F-Spot: " + e
);
111 public void SetAsWallpaper ()
116 if (Hit
["fixme:width"] != null && Hit
["fixme:width"] == "") {
117 width
= Int32
.Parse (Hit
["fixme:width"]);
118 height
= Int32
.Parse (Hit
["fixme:height"]);
120 if (! System
.IO
.File
.Exists (Hit
.FileInfo
.FullName
))
123 Gdk
.Pixbuf p
= new Gdk
.Pixbuf (Hit
.FileInfo
.FullName
);
128 GConf
.Client client
= new GConf
.Client ();
129 client
.Set ("/desktop/gnome/background/picture_filename", Hit
.FileInfo
.FullName
);
132 if (width
== height
) {
134 client
.Set ("/desktop/gnome/background/picture_options",
138 client
.Set ("/desktop/gnome/background/picture_options",
141 } else if (height
>= width
) {
142 // Stretch vertically, but not horizontally
143 client
.Set ("/desktop/gnome/background/picture_options",
147 client
.Set ("/desktop/gnome/background/picture_options",
151 client
.SuggestSync ();