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;
53 public string UniqueKey
{
54 get { return "_tile_" + uid; }
59 set { query = value; }
62 ////////////////////////
64 abstract public void Render (TileRenderContext ctx
);
66 ////////////////////////
68 virtual public bool HandleUrlRequest (string url
)
73 ////////////////////////
75 private TileChangedHandler changedHandler
= null;
77 public void SetChangedHandler (TileChangedHandler ch
)
82 protected virtual void Changed ()
84 if (changedHandler
!= null)
85 changedHandler (this);
88 private void OnErrorDialogResponse (object o
, ResponseArgs args
)
90 ((MessageDialog
)o
).Destroy ();
94 protected void LaunchError (string format
, params string[] args
)
96 string message
= String
.Format (format
, args
);
97 MessageDialog dlg
= new MessageDialog (null,
103 dlg
.Response
+= OnErrorDialogResponse
;
109 public virtual void Open ()
111 System
.Console
.WriteLine ("Warning: Open method not implemented for this tile type");
114 protected void OpenFolder (string path
)
116 if (path
== null || path
== "")
119 Process p
= new Process ();
120 p
.StartInfo
.UseShellExecute
= false;
121 p
.StartInfo
.FileName
= "nautilus";
122 if ((!path
.StartsWith ("\"")) && (!path
.EndsWith ("\"")))
123 path
= "\"" + path
+ "\"";
124 p
.StartInfo
.Arguments
= path
;
128 } catch (Exception e
) {
129 Console
.WriteLine ("Cannot open folder in Nautilus: " + e
);
133 protected void OpenFromMime (Hit hit
)
135 OpenFromMime (hit
, null, false);
138 protected void OpenFromMime (Hit hit
,
139 string command_fallback
,
140 bool expects_uris_fallback
)
142 string argument
= null;
143 string command
= command_fallback
;
144 bool expects_uris
= expects_uris_fallback
;
146 BU
.GnomeVFSMimeApplication app
;
147 app
= BU
.GnomeIconLookup
.GetDefaultAction (hit
.MimeType
);
149 if (app
.command
!= null) {
150 command
= app
.command
;
151 expects_uris
= (app
.expects_uris
!= BU
.GnomeVFSMimeApplicationArgumentType
.Path
);
154 if (command
== null) {
155 LaunchError ("Can't open MimeType '{0}'", hit
.MimeType
);
160 argument
= String
.Format ("'{0}'", hit
.Uri
);
162 argument
= hit
.PathQuoted
;
165 Console
.WriteLine ("Cmd: {0}", command
);
166 Console
.WriteLine ("Arg: {0}", argument
);
168 Process p
= new Process ();
169 p
.StartInfo
.UseShellExecute
= false;
170 p
.StartInfo
.FileName
= command
;
171 p
.StartInfo
.Arguments
= argument
;
175 } catch (Exception e
) {
176 Console
.WriteLine ("Error in OpenFromMime: " + e
);
180 protected void SendMailToAddress (string email
, string attach
)
182 if ((email
== null || email
== "") && (attach
== null || attach
== "")) {
183 Console
.WriteLine ("SendMail got empty email address and attachment");
187 Process p
= new Process ();
188 p
.StartInfo
.UseShellExecute
= false;
189 p
.StartInfo
.FileName
= "evolution";
190 p
.StartInfo
.Arguments
= "mailto:";
192 if (email
!= null && email
!= "")
193 p
.StartInfo
.Arguments
+= email
;
195 if (attach
!= null && attach
!= "")
196 p
.StartInfo
.Arguments
+= "?attach=" + attach
;
200 } catch (Exception e
) {
201 Console
.WriteLine ("Error launching Evolution composer: " + e
);
205 protected void SendIm (string protocol
,
208 if (screenname
== null || screenname
== "")
211 Console
.WriteLine ("SendImAim {0}", screenname
);
212 Process p
= new Process ();
213 p
.StartInfo
.UseShellExecute
= false;
214 p
.StartInfo
.FileName
= "gaim-remote";
215 p
.StartInfo
.Arguments
= "uri " + "protocol" + " :goim?screenname=" + screenname
;
219 } catch (Exception e
) {
220 Console
.WriteLine ("Error launching gaim-remote: " + e
);
224 protected void SendImAim (string screenname
)
226 SendIm ("aim", screename
);
229 protected void SendImIcq (string screenname
)
231 SendIm ("icq", screename
);
234 protected void SendImJabber (string screenname
)
236 SendIm ("jabber", screename
);
239 protected void SendImMsn (string screenname
)
241 SendIm ("msn", screename
);
244 protected void SendImYahoo (string screenname
)
246 SendIm ("yahoo", screename
);
249 protected void SendImGroupwise (string screenname
)
251 SendIm ("novell", screename
);