4 // Copyright (C) 2004 Novell, Inc.
5 // Copyright (C) 2004 Joe Gasiorek
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.
29 using System
.Diagnostics
;
32 using System
.Globalization
;
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
{
45 public TileLauncher (Hit _hit
) : base (_hit
, "template-launcher.html")
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"]);
59 } catch (Exception e
) {
60 Console
.WriteLine ("Unable to run {0}: {1}", p
.StartInfo
.FileName
, e
.Message
);
64 private string ImagePath ()
69 string path
= hit
["fixme:Icon"];
72 if (path
.StartsWith ("/")) {
73 // don't worry about themes
76 IconTheme icon_theme
= new IconTheme ();
81 if (path
.EndsWith (".png"))
82 icon_path
= icon_theme
.LookupIcon (path
.Substring (0, path
.Length
-4), -1, IconData
.Zero
, out base_size
);
84 icon_path
= icon_theme
.LookupIcon (path
, -1, IconData
.Zero
, out base_size
);
86 if (icon_path
!= null)
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
);
105 Template
["Icon"] = icon
;
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
;