cvsimport
[beagle.git] / Tiles / TileLauncher.cs
blob0e6f812c03bd53ca64acdf2c103800608b0bb3df
1 //
2 // TileLauncher.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 // Copyright (C) 2004 Joe Gasiorek
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Diagnostics;
30 using System.IO;
31 using System.Text;
32 using System.Globalization;
34 using Gnome;
36 using BU = Beagle.Util;
38 namespace Beagle.Tile {
39 [HitFlavor (Name="Applications",Rank=800, Emblem="emblem-file.png", Color="#f5f5fe",
40 Type="File", MimeType="application/x-desktop")]
41 public class TileLauncher : TileFromHitTemplate {
43 Hit hit;
45 public TileLauncher (Hit _hit) : base (_hit, "template-launcher.html")
47 hit = _hit;
50 [TileAction]
51 public override void Open ()
53 Process p = new Process ();
54 p.StartInfo.UseShellExecute = true;
55 p.StartInfo.FileName = hit ["fixme:Exec"];
56 Console.WriteLine ("LAUNCHER: going to run {0}", hit ["fixme:Exec"]);
57 try {
58 p.Start ();
59 } catch (Exception e) {
60 Console.WriteLine ("Unable to run {0}: {1}", p.StartInfo.FileName, e.Message);
64 private string ImagePath ()
66 if (hit == null)
67 return null;
69 string path = hit ["fixme:Icon"];
70 if (path == null)
71 return null;
72 if (path.StartsWith ("/")) {
73 // don't worry about themes
74 return path;
75 } else {
76 IconTheme icon_theme = new IconTheme ();
77 int base_size;
78 string icon_path;
80 // Try GNOME Icons
81 if (path.EndsWith (".png"))
82 icon_path = icon_theme.LookupIcon (path.Substring (0, path.Length-4), -1, IconData.Zero, out base_size);
83 else
84 icon_path = icon_theme.LookupIcon (path, -1, IconData.Zero, out base_size);
86 if (icon_path != null)
87 return icon_path;
89 // Fall back to KDE icons
90 return BU.KdeUtils.LookupIcon (path);
94 // FIXME: This doesn't work for all locales
95 static string locale = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
96 static string name_key = String.Format ("fixme:Name[{0}]",locale);
97 static string comment_key = String.Format ("fixme:Comment[{0}]",locale);
99 protected override void PopulateTemplate ()
101 base.PopulateTemplate ();
102 String icon = Images.GetHtmlSource (ImagePath (), Hit.MimeType);
104 if (icon != null)
105 Template["Icon"] = icon;
106 else
107 Template["Icon"] = Images.GetHtmlSource ("document", "image/png");
109 string name = Hit [name_key];
110 string comment = Hit [comment_key];
112 if (name == null || name == "")
113 name = Hit ["fixme:Name"];
115 if (comment == null || comment == "")
116 comment = Hit ["fixme:Comment"];
118 Template ["Name"] = name;
119 Template ["Comment"] = comment;