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"].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
;
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);
68 protected override DetailsPane
GetDetails ()
70 DetailsPane details
= new DetailsPane ();
72 // FIXME: The icon needs a nice frame as in the spec (?)
74 details
.AddTitleLabel (Title
);
75 details
.AddTextLabel (Description
);
76 details
.AddNewLine ();
78 details
.AddLabelPair (Catalog
.GetString ("Modified:"), Utils
.NiceVeryLongDate (Hit
.FileInfo
.LastWriteTime
));
79 details
.AddLabelPair (Catalog
.GetString ("Full Path:"), Hit
.Uri
.LocalPath
);
81 if (Hit
["fspot:Description"] != null && Hit
["fspot:Description"] != "") {
82 details
.AddNewLine ();
83 details
.AddTextLabel (Hit
["fspot:Description"]);
90 // FIXME: fspot doesnt allow to import a particular file
91 // only a whole directory
92 public void AddToLibrary ()
94 // FIXME: check if f-spot is installed
96 if (Hit
["fspot:IsIndexed"] == "true")
99 SafeProcess p
= new SafeProcess ();
100 p
.Arguments
= new string[] { "f-spot", "--import", Hit.FileInfo.FullName }
;
104 } catch (Exception e
) {
105 Console
.WriteLine ("Error launching F-Spot: " + e
);
110 public void SetAsWallpaper ()
115 if (Hit
["fixme:width"] != null && Hit
["fixme:width"] == "") {
116 width
= Int32
.Parse (Hit
["fixme:width"]);
117 height
= Int32
.Parse (Hit
["fixme:height"]);
119 if (! System
.IO
.File
.Exists (Hit
.FileInfo
.FullName
))
122 Gdk
.Pixbuf p
= new Gdk
.Pixbuf (Hit
.FileInfo
.FullName
);
127 GConf
.Client client
= new GConf
.Client ();
128 client
.Set ("/desktop/gnome/background/picture_filename", Hit
.FileInfo
.FullName
);
131 if (width
== height
) {
133 client
.Set ("/desktop/gnome/background/picture_options",
137 client
.Set ("/desktop/gnome/background/picture_options",
140 } else if (height
>= width
) {
141 // Stretch vertically, but not horizontally
142 client
.Set ("/desktop/gnome/background/picture_options",
146 client
.Set ("/desktop/gnome/background/picture_options",
150 client
.SuggestSync ();