4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all 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
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 using System
.Diagnostics
;
30 using BU
= Beagle
.Util
;
32 namespace Beagle
.Tile
{
34 public delegate void TileActionHandler ();
35 public delegate void TileChangedHandler (Tile tile
);
37 public abstract class Tile
{
39 static private object uidSrcLock
= new object ();
40 static private long uidSrc
= 0;
55 public string UniqueKey
{
56 get { return "_tile_" + uid; }
71 set { query = value; }
74 ////////////////////////
76 abstract public void Render (TileRenderContext ctx
);
78 ////////////////////////
80 virtual public bool HandleUrlRequest (string url
)
85 ////////////////////////
87 private TileChangedHandler changedHandler
= null;
89 public void SetChangedHandler (TileChangedHandler ch
)
94 protected virtual void Changed ()
96 if (changedHandler
!= null)
97 changedHandler (this);
100 private void OnErrorDialogResponse (object o
, ResponseArgs args
)
102 ((MessageDialog
)o
).Destroy ();
106 protected void LaunchError (string format
, params string[] args
)
108 string message
= String
.Format (format
, args
);
109 MessageDialog dlg
= new MessageDialog (null,
115 dlg
.Response
+= OnErrorDialogResponse
;
121 public virtual void Open ()
123 System
.Console
.WriteLine ("Warning: Open method not implemented for this tile type");
126 protected void OpenFolder (string path
)
128 if (path
== null || path
== "")
131 Process p
= new Process ();
132 p
.StartInfo
.UseShellExecute
= false;
134 if ((!path
.StartsWith ("\"")) && (!path
.EndsWith ("\"")))
135 path
= "\"" + path
+ "\"";
136 #if ENABLE_DESKTOP_LAUNCH
137 p
.StartInfo
.FileName
= "desktop-launch";
138 p
.StartInfo
.Arguments
= path
;
140 p
.StartInfo
.FileName
= "nautilus";
141 p
.StartInfo
.Arguments
= "--no-desktop " + path
;
145 } catch (Exception e
) {
146 Console
.WriteLine ("Cannot open folder: " + e
);
150 protected void OpenFromMime (Hit hit
)
152 OpenFromMime (hit
, null, null, false);
155 protected void OpenFromMime (Hit hit
,
156 string command_fallback
,
157 string args_fallback
,
158 bool expects_uris_fallback
)
161 string command
= command_fallback
;
162 bool expects_uris
= expects_uris_fallback
;
164 // FIXME: This is evil. Nautilus should be handling
165 // inode/directory, not just x-directory/normal
166 if (hit
.MimeType
== "inode/directory")
167 hit
.MimeType
= "x-directory/normal";
168 #if ENABLE_DESKTOP_LAUNCH
169 command
= "desktop-launch";
172 BU
.GnomeVFSMimeApplication app
;
173 app
= BU
.GnomeIconLookup
.GetDefaultAction (hit
.MimeType
);
175 if (app
.command
!= null) {
176 command
= app
.command
;
177 expects_uris
= (app
.expects_uris
!= BU
.GnomeVFSMimeApplicationArgumentType
.Path
);
180 if (command
== null) {
181 LaunchError ("Can't open MimeType '{0}'", hit
.MimeType
);
185 if (args_fallback
!= null)
186 argument
= args_fallback
;
191 argument
= String
.Format ("{0} '{1}'", argument
, hit
.Uri
);
193 argument
= String
.Format ("{0} {1}", argument
, hit
.PathQuoted
);
196 // Sometimes the command is 'quoted'
197 if (command
.IndexOf ('\'') == 0 && command
.LastIndexOf ('\'') == command
.Length
- 1)
198 command
= command
.Trim ('\'');
200 // This won't work if a program really has a space in
201 // the filename, but I think other things would break
202 // with that too, and in practice it doesn't seem to
204 int idx
= command
.IndexOf (' ');
206 argument
= String
.Format ("{0} {1}", command
.Substring (idx
+ 1), argument
);
207 command
= command
.Substring (0, idx
);
210 Console
.WriteLine ("Cmd: {0}", command
);
211 Console
.WriteLine ("Arg: {0}", argument
);
213 Process p
= new Process ();
214 p
.StartInfo
.UseShellExecute
= false;
215 p
.StartInfo
.FileName
= command
;
216 p
.StartInfo
.Arguments
= argument
;
220 } catch (Exception e
) {
221 Console
.WriteLine ("Error in OpenFromMime: " + e
);
225 protected void SendFile (string attach
)
227 if ((attach
== null || attach
== "")) {
228 Console
.WriteLine ("SendFile got empty attachment");
232 Process p
= new Process ();
233 p
.StartInfo
.UseShellExecute
= false;
234 p
.StartInfo
.FileName
= "nautilus-sendto";
235 p
.StartInfo
.Arguments
= String
.Format ("--default-dir=/ '{0}'", attach
);
239 } catch (Exception e
) {
240 // Fall back to just email
241 SendMailToAddress (null, attach
);
245 protected void SendMailToAddress (string email
, string attach
)
247 if ((email
== null || email
== "") && (attach
== null || attach
== "")) {
248 Console
.WriteLine ("SendMail got empty email address and attachment");
252 Process p
= new Process ();
253 p
.StartInfo
.UseShellExecute
= false;
254 p
.StartInfo
.FileName
= "evolution";
255 p
.StartInfo
.Arguments
= "\"mailto:";
257 if (email
!= null && email
!= "")
258 p
.StartInfo
.Arguments
+= email
;
260 if (attach
!= null && attach
!= "")
261 p
.StartInfo
.Arguments
+= "?attach=" + attach
;
263 p
.StartInfo
.Arguments
+= "\"";
267 } catch (Exception e
) {
268 Console
.WriteLine ("Error launching Evolution composer: " + e
);
272 protected void SendIm (string protocol
,
275 if (screenname
== null)
278 Console
.WriteLine ("SendImAim {0}", screenname
);
279 Process p
= new Process ();
280 p
.StartInfo
.UseShellExecute
= false;
281 p
.StartInfo
.FileName
= "gaim-remote";
282 p
.StartInfo
.Arguments
= "uri " + protocol
+ ":goim?screenname=" + screenname
;
286 } catch (Exception e
) {
287 Console
.WriteLine ("Error launching gaim-remote: " + e
);
291 protected void SendImAim (string screenname
)
293 SendIm ("aim", screenname
);
296 protected void SendImIcq (string screenname
)
298 SendIm ("icq", screenname
);
301 protected void SendImJabber (string screenname
)
303 SendIm ("jabber", screenname
);
306 protected void SendImMsn (string screenname
)
308 SendIm ("msn", screenname
);
311 protected void SendImYahoo (string screenname
)
313 SendIm ("yahoo", screenname
);
316 protected void SendImGroupwise (string screenname
)
318 SendIm ("novell", screenname
);