4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 using System
.Collections
;
30 using System
.Diagnostics
;
32 using System
.Reflection
;
37 using BU
= Beagle
.Util
;
41 public class HitRendererHtml
: HitRenderer
{
43 private Gtk
.HTML html
= new Gtk
.HTML ();
44 private Hashtable tiles
= new Hashtable ();
46 public HitRendererHtml ()
48 this.html
.LinkClicked
+= new LinkClickedHandler (LinkClicked
);
49 this.html
.UrlRequested
+= new UrlRequestedHandler (UrlRequested
);
52 ////////////////////////////////////
54 private Tile
HitToTile (Hit hit
)
58 // FIXME: We don't want to allow heterogenous containers.
63 t
= new Tile ("contact.html", hit
);
67 t
= new Tile ("file-generic.html", hit
);
71 t
= new Tile ("im-log.html", hit
);
75 string icon
= "mail.png";
76 if (hit
["_IsAnswered"] != null)
77 icon
= "mail-replied.png";
78 else if (hit
["_IsSeen"] != null)
79 icon
= "mail-read.png";
80 hit
["mail:Icon"] = icon
;
82 if (hit
["_IsSent"] != null)
83 t
= new Tile ("email-sent.html", hit
);
85 t
= new Tile ("email.html", hit
);
89 t
= new Tile ("web-history.html", hit
);
93 if (hit
.Source
== "Google")
94 t
= new Tile ("google.html", hit
);
101 protected override bool ProcessHit (Hit hit
)
103 Tile tile
= HitToTile (hit
);
111 protected override void ProcessClear ()
116 ////////////////////////////////////
118 public override Gtk
.Widget Widget
{
122 protected override void DoRefresh ()
124 Gtk
.HTMLStream stream
= html
.Begin ();
125 stream
.Write ("<html><body>");
126 if (DisplayedCount
> 0) {
127 // FIXME: layout in a table, or something
128 for (int i
= FirstDisplayed
; i
<= LastDisplayed
; ++i
) {
129 Hit hit
= (Hit
) Hits
[i
];
130 Tile t
= (Tile
) tiles
[hit
];
131 stream
.Write (t
.Html
);
134 stream
.Write ("</body></html>");
137 ///////////////////////////////////
140 // Provides data for urls requested (images). Things prefixed
141 // with `internal:' we pull for one of the embedded streams
143 private void UrlRequested (object o
, UrlRequestedArgs args
)
145 Stream s
= DataBarn
.GetStream (args
.Url
);
147 Console
.WriteLine ("Could not obtain image '{0}'", args
.Url
);
151 byte [] buffer
= new byte [8192];
153 while ( (n
= s
.Read (buffer
, 0, 8192)) != 0)
154 args
.Handle
.Write (buffer
, n
);
157 private void LinkClicked (object o
, LinkClickedArgs args
)
159 String command
= null, arguments
= null;
161 if (args
.Url
.StartsWith ("exec:")) {
162 command
= args
.Url
.Substring ("exec:".Length
);
163 int i
= command
.IndexOf (' ');
165 arguments
= command
.Substring (i
+1);
166 command
= command
.Substring (0, i
);
168 } else if (args
.Url
.StartsWith ("http")) {
169 command
= "epiphany";
170 arguments
= args
.Url
;
171 } else if (args
.Url
.StartsWith ("email")) {
172 command
= "evolution-1.5";
173 arguments
= args
.Url
;
174 } else if (args
.Url
.StartsWith ("mailto:")) {
175 command
= "evolution-1.5";
176 arguments
= args
.Url
;
177 } else if (args
.Url
.StartsWith ("file://")) {
178 // Hacky: we extract the mime type from inside of
180 arguments
= args
.Url
.Substring ("file://".Length
);
181 int i
= arguments
.IndexOf (' ');
184 mimeType
= BU
.GnomeIconLookup
.GetMimeType (arguments
);
186 mimeType
= arguments
.Substring (i
+1);
187 arguments
= arguments
.Substring (0, i
);
190 // Try to open w/ the default handler
191 BU
.GnomeVFSMimeApplication app
;
192 app
= BU
.GnomeIconLookup
.GetDefaultAction (mimeType
);
193 command
= app
.command
;
196 Console
.WriteLine ("Command=[{0}] Args=[{1}]", command
, arguments
);
198 if (command
!= null) {
199 Process p
= new Process ();
200 p
.StartInfo
.UseShellExecute
= false;
201 p
.StartInfo
.FileName
= command
;
202 if (arguments
!= null)
203 p
.StartInfo
.Arguments
= arguments
;