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.
29 using System
.Collections
;
30 using System
.Diagnostics
;
35 namespace Beagle
.Tile
{
37 [HitFlavor (Name
="Conversations", Rank
=900, Emblem
="emblem-im-log.png", Color
="#e5f5ef",
39 public class TileImLog
: TileFromHitTemplate
{
42 private static Hashtable buddy_emails
= new Hashtable ();
45 private string email
= null;
46 private string speaking_alias
= null;
48 public TileImLog (Hit _hit
) : base (_hit
,
49 "template-im-log.html")
51 if (Hit
["fixme:speakingto_alias"] != null)
52 email
= GetEmailForName (Hit
["fixme:speakingto_alias"]);
55 protected override void PopulateTemplate ()
57 base.PopulateTemplate ();
59 Template
["nice_duration"] = "(" +
60 StringFu
.DurationToPrettyString (
61 StringFu
.StringToDateTime (Hit
["fixme:endtime"]),
62 StringFu
.StringToDateTime (Hit
["fixme:starttime"])) + ")";
63 if (Template
["nice_duration"] == "()")
64 Template
["nice_duration"] = "";
67 Template
["SendMailAction"] = Catalog
.GetString ("Send Mail");
69 // FIXME: This is a temporary hack until gaim supports other protocols than AIM via gaim-remote
70 if (Hit
["fixme:protocol"] == "aim")
71 Template
["SendIMAction"] = Catalog
.GetString ("Send IM");
73 speaking_alias
= (Hit
["fixme:speakingto_alias"] != null) ? Hit
["fixme:speakingto_alias"] : Hit
["fixme:speakingto"];
75 // FIXME: Hack to figure out if the conversation is taken place in a chat room
76 if (Hit
["fixme:speakingto"].EndsWith (".chat"))
77 Template
["title"] = String
.Format (Catalog
.GetString ("Conversation in {0}"), speaking_alias
.Replace(".chat",""));
79 Template
["title"] = String
.Format (Catalog
.GetString ("Conversation with {0}"), speaking_alias
);
81 if (Hit
["fixme:speakingto_icon"] != null && File
.Exists (Hit
["fixme:speakingto_icon"]))
82 Template
["Icon"] = StringFu
.PathToQuotedFileUri (Hit
["fixme:speakingto_icon"]);
84 Template
["Icon"] = Images
.GetHtmlSource ("gnome-gaim.png", "image/png");
87 if (Hit
["fixme:protocol"] == "aim") {
88 string status
= GalagoTools
.GetPresence (Hit
["fixme:protocol"], Hit
["fixme:speakingto"]);
89 if (status
!= null && status
!= "")
90 Template
["Presence"] = status
;
96 static bool ebook_failed
= false;
99 private string GetEmailForName (string name
)
102 if (name
== null || name
== "")
105 Evolution
.Book addressbook
= null;
108 // If we've previously failed to open the
109 // addressbook, don't keep trying.
113 // We keep a little cache so we don't have to query
114 // the addressbook too often.
115 if (buddy_emails
.Contains (name
)) {
116 string str
= (string)buddy_emails
[name
];
117 return str
!= "" ? str
: null;
120 // Connect to the Evolution addressbook.
122 addressbook
= Evolution
.Book
.NewSystemAddressbook ();
123 addressbook
.Open (true);
124 } catch (Exception e
) {
125 Console
.WriteLine ("\nCould not open Evolution addressbook:\n" + e
);
132 String
.Format ("(is \"full_name\" \"{0}\")", name
);
134 Evolution
.BookQuery query
= Evolution
.BookQuery
.FromString (qstr
);
135 Evolution
.Contact
[] matches
= addressbook
.GetContacts (query
);
136 foreach (Evolution
.Contact c
in matches
) {
137 Console
.WriteLine ("FIXME: querying the evolution addressbook instead of using Lucene, this is slow and dumb");
138 Console
.WriteLine ("Got match: {0} {1}", c
.FullName
, c
.Email1
);
139 if (c
.Email1
!= null) {
140 buddy_emails
[name
] = c
.Email1
;
144 buddy_emails
[name
] = "";
151 public override void Open ()
153 //FIXME: At least for now
154 Process p
= new Process ();
155 p
.StartInfo
.UseShellExecute
= true;
156 p
.StartInfo
.FileName
= "beagle-imlogviewer";
157 p
.StartInfo
.Arguments
= String
.Format ("--client \"{0}\" --highlight-search \"{1}\" {2}",
158 Hit
["fixme:client"], Query
.QuotedText
, Hit
.Uri
.LocalPath
);
162 } catch (Exception e
) {
163 Console
.WriteLine ("Unable to run {0}: {1}", p
.StartInfo
.FileName
, e
.Message
);
168 public void SendMailForIm ()
171 SendMailToAddress (email
, null);
175 public void SendIm ()
177 SendImAim (Hit
["fixme:speakingto"]);