Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / Tiles / Image.cs
blobe9c82e1f542b6f7f3375b56c00f0038c9f0a4f8e
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"].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)
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 = icon;
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"]);
86 return details;
89 #if NOT_YET
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")
97 return;
99 SafeProcess p = new SafeProcess ();
100 p.Arguments = new string[] { "f-spot", "--import", Hit.FileInfo.FullName };
102 try {
103 p.Start ();
104 } catch (Exception e) {
105 Console.WriteLine ("Error launching F-Spot: " + e);
108 #endif
110 public void SetAsWallpaper ()
112 int width = 0;
113 int height = 0;
115 if (Hit ["fixme:width"] != null && Hit ["fixme:width"] == "") {
116 width = Int32.Parse (Hit ["fixme:width"]);
117 height = Int32.Parse (Hit ["fixme:height"]);
118 } else {
119 if (! System.IO.File.Exists (Hit.FileInfo.FullName))
120 return;
122 Gdk.Pixbuf p = new Gdk.Pixbuf (Hit.FileInfo.FullName);
123 width = p.Width;
124 height = p.Height;
127 GConf.Client client = new GConf.Client ();
128 client.Set ("/desktop/gnome/background/picture_filename", Hit.FileInfo.FullName);
130 if (width <= 640) {
131 if (width == height) {
132 // Tile
133 client.Set ("/desktop/gnome/background/picture_options",
134 "wallpaper");
135 } else {
136 // Center
137 client.Set ("/desktop/gnome/background/picture_options",
138 "centered");
140 } else if (height >= width) {
141 // Stretch vertically, but not horizontally
142 client.Set ("/desktop/gnome/background/picture_options",
143 "scaled");
144 } else {
145 // Fit to screen
146 client.Set ("/desktop/gnome/background/picture_options",
147 "stretched");
150 client.SuggestSync ();