cvsimport
[beagle.git] / search / Tiles / Image.cs
blob69596f5596ad197c69a7053d75c5e1f50b83d3a3
1 using System;
2 using System.Diagnostics;
3 using Mono.Unix;
5 using Beagle.Util;
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)
52 return;
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)
58 return;
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 ();
65 image.Pixbuf = icon;
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"]);
87 return details;
90 #if NOT_YET
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")
98 return;
100 SafeProcess p = new SafeProcess ();
101 p.Arguments = new string[] { "f-spot", "--import", Hit.FileInfo.FullName };
103 try {
104 p.Start ();
105 } catch (Exception e) {
106 Console.WriteLine ("Error launching F-Spot: " + e);
109 #endif
111 public void SetAsWallpaper ()
113 int width = 0;
114 int height = 0;
116 if (Hit ["fixme:width"] != null && Hit ["fixme:width"] == "") {
117 width = Int32.Parse (Hit ["fixme:width"]);
118 height = Int32.Parse (Hit ["fixme:height"]);
119 } else {
120 if (! System.IO.File.Exists (Hit.FileInfo.FullName))
121 return;
123 Gdk.Pixbuf p = new Gdk.Pixbuf (Hit.FileInfo.FullName);
124 width = p.Width;
125 height = p.Height;
128 GConf.Client client = new GConf.Client ();
129 client.Set ("/desktop/gnome/background/picture_filename", Hit.FileInfo.FullName);
131 if (width <= 640) {
132 if (width == height) {
133 // Tile
134 client.Set ("/desktop/gnome/background/picture_options",
135 "wallpaper");
136 } else {
137 // Center
138 client.Set ("/desktop/gnome/background/picture_options",
139 "centered");
141 } else if (height >= width) {
142 // Stretch vertically, but not horizontally
143 client.Set ("/desktop/gnome/background/picture_options",
144 "scaled");
145 } else {
146 // Fit to screen
147 client.Set ("/desktop/gnome/background/picture_options",
148 "stretched");
151 client.SuggestSync ();