cvsimport
[beagle.git] / search / Tiles / ArchivedFile.cs
blobffefd0153b156795e513b75f90b726be54e5476b
1 using System;
2 using System.Diagnostics;
3 using Mono.Unix;
4 using Beagle.Util;
6 namespace Search.Tiles {
8 public class ArchivedFileActivator : TileActivator {
10 public ArchivedFileActivator () : base ()
12 AddSupportedFlavor (new HitFlavor (null, "File", null));
15 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
17 return new TileArchivedFile (hit, query);
20 public override bool Validate (Beagle.Hit hit)
22 if (! base.Validate (hit))
23 return false;
25 string str = hit.GetFirstProperty ("fixme:inside_archive");
26 if (hit.ParentUri == null || str == null || str == "false")
27 return false;
29 Weight += 1;
31 return true;
35 public class TileArchivedFile : TileFile {
37 public TileArchivedFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
39 Description = String.Format (Catalog.GetString ("Inside archive {0}"), GetTitle (hit, true));
42 protected override void LoadIcon (Gtk.Image image, int size)
44 base.LoadIcon (image, size);
46 string parent_mime_type = XdgMime.GetMimeTypeFromFileName (Hit.EscapedParentUri);
48 if (parent_mime_type == null)
49 return;
51 Gdk.Pixbuf emblem = WidgetFu.LoadMimeIcon (parent_mime_type, 24);
53 if (emblem == null)
54 return;
56 Gdk.Pixbuf icon = image.Pixbuf.Copy ();
58 emblem.Composite (icon,
59 0, // dest_x
60 icon.Height - emblem.Height, // dest_y
61 emblem.Width, // dest_width
62 emblem.Height, // dest_height
63 0, // offset_x
64 icon.Height - emblem.Height, // offset_y
65 1, 1, // scale
66 Gdk.InterpType.Bilinear, 255);
68 image.Pixbuf.Dispose ();
69 image.Pixbuf = icon;
72 protected override DetailsPane GetDetails ()
74 DetailsPane details = new DetailsPane ();
76 details.AddLabelPair (Catalog.GetString ("Title:"), GetTitle (Hit));
77 details.AddLabelPair (Catalog.GetString ("File Name:"), Hit.Uri.Fragment.Substring (1)); // Substring to move past the initial #
78 details.AddLabelPair (Catalog.GetString ("Inside File:"), Hit.Uri.LocalPath);
80 if (Hit ["dc:author"] != null)
81 details.AddLabelPair (Catalog.GetString ("Author:"), Hit ["dc:author"]);
83 details.AddSnippet ();
85 return details;