2 using System
.Diagnostics
;
3 using System
.Runtime
.InteropServices
;
6 namespace Search
.Tiles
{
8 public class ApplicationActivator
: TileActivator
{
10 public ApplicationActivator () : base ()
12 AddSupportedFlavor (new HitFlavor (null, null, "application/x-desktop"));
15 [DllImport ("libgnome-desktop-2.so.2")]
16 static extern IntPtr
gnome_desktop_item_new_from_uri (string uri
, int flags
, IntPtr error
);
18 [DllImport ("libgnome-desktop-2.so.2")]
19 static extern string gnome_desktop_item_get_string (IntPtr ditem
, string attr
);
21 [DllImport ("libgnome-desktop-2.so.2")]
22 static extern void gnome_desktop_item_unref (IntPtr ditem
);
26 ~
ApplicationActivator ()
28 if (ditem
!= IntPtr
.Zero
)
29 gnome_desktop_item_unref (ditem
);
32 // invalid .desktop files get filtered out by Validate(), so they won't
33 // show up as Application tiles, but will show up as File tiles. But
34 // valid .desktop files marked to not show up in GNOME get eaten by
35 // BuildTile instead, so that they won't get picked up by the File tile.
37 // FIXME: we shouldn't be hardcoding GNOME in BuildTile, it should depend
38 // on what the running desktop is.
40 public override bool Validate (Beagle
.Hit hit
)
42 if (!base.Validate (hit
))
45 ditem
= gnome_desktop_item_new_from_uri (hit
.EscapedUri
, 0, IntPtr
.Zero
);
46 if (ditem
== IntPtr
.Zero
)
49 // Make sure this is a real desktop file, not a .desktop.in
50 string _name
= gnome_desktop_item_get_string (ditem
, "_Name");
57 public override Tile
BuildTile (Beagle
.Hit hit
, Beagle
.Query query
)
59 if (ditem
== IntPtr
.Zero
)
62 string notshow
= gnome_desktop_item_get_string (ditem
, "NotShowIn");
63 if (notshow
!= null && notshow
.IndexOf ("GNOME") != -1)
66 string onlyshow
= gnome_desktop_item_get_string (ditem
, "OnlyShowIn");
67 if (onlyshow
!= null && onlyshow
.IndexOf ("GNOME") == -1)
70 return new Application (hit
, query
, ditem
);
74 public class Application
: TileTemplate
{
78 public Application (Beagle
.Hit hit
, Beagle
.Query query
, IntPtr ditem
) : this (hit
, query
)
81 // AddAction (new TileAction (Catalog.GetString ("Move to trash"), Gtk.Stock.Delete, MoveToTrash));
84 protected Application (Beagle
.Hit hit
, Beagle
.Query query
) : base (hit
, query
)
86 Group
= TileGroup
.Application
;
87 Title
= Hit
.GetFirstProperty ("fixme:Name");
88 Description
= Hit
["fixme:Comment"];
91 protected override void LoadIcon (Gtk
.Image image
, int size
)
93 Gdk
.Pixbuf icon
= null;
94 string path
= Hit
["fixme:Icon"];
96 if (path
!= null && path
!= "") {
98 if (path
.StartsWith ("/")) {
99 icon
= new Gdk
.Pixbuf (path
);
101 if (path
.EndsWith (".png"))
102 icon
= WidgetFu
.LoadThemeIcon (path
.Substring (0, path
.Length
-4), size
);
104 icon
= WidgetFu
.LoadThemeIcon (path
, size
);
107 string kde_path
= Beagle
.Util
.KdeUtils
.LookupIcon (path
);
109 if (System
.IO
.File
.Exists (kde_path
))
110 icon
= new Gdk
.Pixbuf (kde_path
);
113 } catch (Exception e
) {
114 Console
.WriteLine ("Unable to load icon '{0}': {1}", path
, e
.Message
);
119 if (icon
.Height
> size
) {
120 int scaled_width
= (int) ((double) size
/ (double) icon
.Height
* icon
.Width
);
122 icon
= icon
.ScaleSimple (scaled_width
, size
, Gdk
.InterpType
.Bilinear
);
127 base.LoadIcon (image
, size
);
130 [DllImport ("libgnome-desktop-2.so.2")]
131 static extern int gnome_desktop_item_launch (IntPtr ditem
, IntPtr file_list
, int flags
, IntPtr error
);
133 public override void Open ()
135 if (gnome_desktop_item_launch (ditem
, IntPtr
.Zero
, 0, IntPtr
.Zero
) == -1)
136 Console
.WriteLine ("Unable to launch application");
140 public void MoveToTrash ()
142 // FIXME: What is the default way to uninstall an application
143 // in a distro-independent way?
145 // FIXME: The chance that the code below works is 1:100 :-)
146 ProcessStartInfo pi
= new ProcessStartInfo ("rpm");
147 pi
.Arguments
= String
.Format ("-e {0}", Hit
["fixme:Exec"]);
148 //Process.Start (pi); // FIXME: Safe sex
150 Console
.WriteLine ("Would run 'rpm {0}'", pi
.Arguments
);