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
;
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 GnomeFu
.VFSMimeApplication app
;
173 app
= GnomeFu
.GetDefaultAction (hit
.MimeType
);
174 if (app
.command
!= null) {
175 command
= app
.command
;
176 expects_uris
= (app
.expects_uris
!= GnomeFu
.VFSMimeApplicationArgumentType
.Path
);
179 if (command
== null) {
180 LaunchError ("Can't open MimeType '{0}'", hit
.MimeType
);
184 if (args_fallback
!= null)
185 argument
= args_fallback
;
190 argument
= String
.Format ("{0} '{1}'", argument
, hit
.Uri
);
192 argument
= String
.Format ("{0} {1}", argument
, hit
.PathQuoted
);
195 // Sometimes the command is 'quoted'
196 if (command
.IndexOf ('\'') == 0 && command
.LastIndexOf ('\'') == command
.Length
- 1)
197 command
= command
.Trim ('\'');
199 // This won't work if a program really has a space in
200 // the filename, but I think other things would break
201 // with that too, and in practice it doesn't seem to
203 int idx
= command
.IndexOf (' ');
205 argument
= String
.Format ("{0} {1}", command
.Substring (idx
+ 1), argument
);
206 command
= command
.Substring (0, idx
);
209 Console
.WriteLine ("Cmd: {0}", command
);
210 Console
.WriteLine ("Arg: {0}", argument
);
212 Process p
= new Process ();
213 p
.StartInfo
.UseShellExecute
= false;
214 p
.StartInfo
.FileName
= command
;
215 p
.StartInfo
.Arguments
= argument
;
219 } catch (Exception e
) {
220 Console
.WriteLine ("Error in OpenFromMime: " + e
);
224 protected void SendFile (string attach
)
226 if ((attach
== null || attach
== "")) {
227 Console
.WriteLine ("SendFile got empty attachment");
231 Process p
= new Process ();
232 p
.StartInfo
.UseShellExecute
= false;
233 p
.StartInfo
.FileName
= "nautilus-sendto";
234 p
.StartInfo
.Arguments
= String
.Format ("--default-dir=/ '{0}'", attach
);
238 } catch (Exception e
) {
239 // Fall back to just email
240 SendMailToAddress (null, attach
);
244 protected void SendMailToAddress (string email
, string attach
)
246 if ((email
== null || email
== "") && (attach
== null || attach
== "")) {
247 Console
.WriteLine ("SendMail got empty email address and attachment");
251 Process p
= new Process ();
252 p
.StartInfo
.UseShellExecute
= false;
253 p
.StartInfo
.FileName
= "evolution";
254 p
.StartInfo
.Arguments
= "\"mailto:";
256 if (email
!= null && email
!= "")
257 p
.StartInfo
.Arguments
+= email
;
259 if (attach
!= null && attach
!= "")
260 p
.StartInfo
.Arguments
+= "?attach=" + attach
;
262 p
.StartInfo
.Arguments
+= "\"";
266 } catch (Exception e
) {
267 Console
.WriteLine ("Error launching Evolution composer: " + e
);
271 protected void SendIm (string protocol
,
274 if (screenname
== null)
277 Console
.WriteLine ("SendImAim {0}", screenname
);
278 Process p
= new Process ();
279 p
.StartInfo
.UseShellExecute
= false;
280 p
.StartInfo
.FileName
= "gaim-remote";
281 p
.StartInfo
.Arguments
= "uri " + protocol
+ ":goim?screenname=" + screenname
;
285 } catch (Exception e
) {
286 Console
.WriteLine ("Error launching gaim-remote: " + e
);
290 protected void SendImAim (string screenname
)
292 SendIm ("aim", screenname
);
295 protected void SendImIcq (string screenname
)
297 SendIm ("icq", screenname
);
300 protected void SendImJabber (string screenname
)
302 SendIm ("jabber", screenname
);
305 protected void SendImMsn (string screenname
)
307 SendIm ("msn", screenname
);
310 protected void SendImYahoo (string screenname
)
312 SendIm ("yahoo", screenname
);
315 protected void SendImGroupwise (string screenname
)
317 SendIm ("novell", screenname
);