Hello hackers! Got bored during the morning so I cooked this patch. * Renders your indexed IM conversations * Limiter for displayed types (File, Mail, Contact, ImLog) * Some smaller fixes NOTE: The attached image goes into engine/images. Please let me know if the patch is OK to commit. Next I'm going to work on using Beagle's tiles for rendering. Lukas.
--- backends/BeagleBackend.cs.~1.5.~ 2004-06-29 21:23:39.000000000 +0200 +++ backends/BeagleBackend.cs 2004-07-18 14:42:17.000000000 +0200 @@ -5,6 +5,7 @@ // // Author: // Nat Friedman <nat novell com> +// Lukas Lipka <lukas pmad net> // @@ -21,7 +22,6 @@ class BeagleBackend : Backend { private QueryDriver queryDriver; - private static double DECAY = 0.3; // How quickly to decay old files public override bool Startup () { @@ -83,11 +83,71 @@ foreach (string key in hit.Keys) match [key] = hit [key]; break; + + case "IMLog": + match ["SpeakingTo"] = hit ["SpeakingTo"]; + match ["StartTime"] = hit ["StartTime"]; + match ["EndTime"] = hit ["EndTime"]; + break; + } return match; } + private const int MAXFILE = 10; + private const int MAXIM = 5; + private const int MAXMAIL = 5; + private const int MAXCONTACT = 5; + + private int count_file = 0; + private int count_im = 0; + private int count_mail = 0; + private int count_contact = 0; + + private bool HitCount (Hit hit) + { + switch (hit.Type) { + case "File": + if (count_file != MAXFILE) { + count_file++; + return true; + } + break; + + case "MailMessage": + if (count_mail != MAXMAIL) { + count_mail++; + return true; + } + break; + + case "Contact": + if (count_contact != MAXCONTACT) { + count_contact++; + return true; + } + break; + + case "IMLog": + if (count_im != MAXIM) { + count_im++; + return true; + } + break; + + default: + return true; + } + + return false; + } + + private void HitCountEnd () + { + count_file = count_im = count_contact = count_mail = 0; + } + public override BackendResult ProcessCluePacket (CluePacket cp) { if (! this.Initialized) @@ -99,24 +159,26 @@ if (! ClueTypeSubscribed (clue)) continue; - string clue_text = clue.Text.ToLower (); + string clue_text = clue.Text; Query query = new Query (clue_text); + query.AddDomain (QueryDomain.Neighorhood); + query.AddDomain (QueryDomain.Global); + QueryResult results = queryDriver.Query (query); // Wait for all results to come back before // preceeding. (FIXME?) results.Wait (); - - int i = 0; foreach (Hit hit in results.Hits) { - i ++; - if (i > 10) - break; - Match match = HitToMatch (hit, clue); - result.AddMatch (match); + if (HitCount (hit)) { + Match match = HitToMatch (hit, clue); + result.AddMatch (match); + } } + + HitCountEnd (); } return result; --- engine/Makefile.am.~1.50.~ 2004-06-29 21:23:40.000000000 +0200 +++ engine/Makefile.am 2004-07-18 13:52:26.000000000 +0200 @@ -27,7 +27,8 @@ -resource:$(srcdir)/images/mail-new.png,mail-new.png \ -resource:$(srcdir)/images/mail-replied.png,mail-replied.png \ -resource:$(srcdir)/images/mail-read.png,mail-read.png \ - -resource:$(srcdir)/images/rss.png,rss.png + -resource:$(srcdir)/images/rss.png,rss.png \ + -resource:$(srcdir)/images/gnome-gaim.png,gnome-gaim.png DASHBOARD_CSFILES = \ $(srcdir)/Backend.cs \ --- engine/images/Makefile.am.~1.5.~ 2004-02-19 05:30:23.000000000 +0100 +++ engine/images/Makefile.am 2004-07-18 11:17:27.000000000 +0200 @@ -17,6 +17,7 @@ mail-new.png \ mail-read.png \ mail-replied.png \ - rss.png + rss.png \ + gnome-gaim.png EXTRA_DIST = $(noinst_DATA) --- renderers/IMLogMatchRenderer.cs.~1.7.~ 2004-03-04 08:32:54.000000000 +0100 +++ renderers/IMLogMatchRenderer.cs 2004-07-18 13:56:59.000000000 +0200 @@ -9,6 +9,8 @@ using System; using System.Collections; +using System.Xml; +using System.IO; [assembly:Dashboard.MatchRendererFactory ("Dashboard.IMLogMatchRenderer")] @@ -21,73 +23,95 @@ Type = "IMLog"; } - private class AliasComparer : IComparer { + private class SpeakingToComparer : IComparer { public int Compare (object a, object b) { Match m1 = (Match) a; Match m2 = (Match) b; - return String.Compare ((string) m1 ["Alias"], (string) m2 ["Alias"]); + return String.Compare ((string) m1 ["SpeakingTo"], (string) m2 ["SpeakingTo"]); } } public override string HTMLRenderMatches (ArrayList matches) { - string html = ""; - string current_alias = null; + StringWriter sw = new StringWriter (); + XmlWriter xw = new XmlTextWriter (sw); - // Sort by alias - matches.Sort (new AliasComparer ()); + xw.WriteStartElement ("div"); - foreach (Match m in matches) { - string alias = (string) m ["Alias"]; + // Sort by nickname + matches.Sort (new SpeakingToComparer ()); + + foreach (Match m in matches) + HTMLRenderSingleIm (m, xw); - if (current_alias != null && current_alias != alias) - html += "</table>\n\n"; // Footer + xw.WriteEndElement (); //div + xw.Close (); - if (current_alias != alias) - html += HTMLRenderHeader (m); - - html += HTMLRenderSingleIMConv (m); - - current_alias = alias; - } - - html += "</table>\n\n"; // Footer - - return html; + return sw.ToString (); } - private string HTMLRenderHeader (Match m) + private void HTMLRenderSingleIm (Match m, XmlWriter xw) { - string html; - - html = String.Format ("<table border=0 width=100%>" + - " <tr bgcolor=#ecd953>" + - " <td> <img border=0 src=\"{0}\"> </td>" + - " <td valign=center>" + - " <font size=+1>Conversations with {1}</font>" + - " </td>" + - " </tr>", - m ["Icon"], - m ["Alias"]); - - return html; - } - - private string HTMLRenderSingleIMConv (Match m) - { - string html; - - html = String.Format ("<tr bgcolor=#f7ec93>" + - " <td colspan=2> <font size=-1>" + - " <a style=\"text-decoration: none;\" href=\"{1}\">{0}</a>" + - " </font></td>" + - "</tr>", - m ["Date"], - m ["URL"]); + string speaking_to = Convert.ToString (m ["SpeakingTo"]); + string uri = Convert.ToString (m ["URI"]); + string start_time = Convert.ToString (m ["StartTime"]); + string end_time = Convert.ToString (m ["EndTime"]); + + xw.WriteStartElement ("table"); + xw.WriteAttributeString ("bgcolor", "#dddddd"); + xw.WriteAttributeString ("cellpadding", "0"); + xw.WriteAttributeString ("cellspacing", "1"); + xw.WriteAttributeString ("width", "100%"); + xw.WriteAttributeString ("height", "100%"); + xw.WriteStartElement ("tr"); + xw.WriteAttributeString ("valign", "top"); + xw.WriteStartElement ("td"); + + xw.WriteStartElement ("table"); + xw.WriteAttributeString ("bgcolor", "#e5f5e5"); + xw.WriteAttributeString ("cellpadding", "4"); + xw.WriteAttributeString ("width", "100%"); + xw.WriteAttributeString ("height", "100%"); + xw.WriteStartElement ("tr"); + xw.WriteAttributeString ("valign", "top"); + xw.WriteStartElement ("td"); + xw.WriteStartElement ("a"); + xw.WriteAttributeString ("href", uri); + xw.WriteStartElement ("img"); + xw.WriteAttributeString ("src", "internal:gnome-gaim.png"); + xw.WriteAttributeString ("border", "0"); + xw.WriteEndElement (); // img + xw.WriteEndElement (); // a + xw.WriteEndElement (); // td + + xw.WriteStartElement ("td"); + xw.WriteStartElement ("font"); + xw.WriteAttributeString ("size", "2"); + xw.WriteString ("IM with "); + xw.WriteStartElement ("strong"); + xw.WriteString (speaking_to); + xw.WriteEndElement (); // strong + xw.WriteEndElement (); // font + xw.WriteStartElement ("br"); + xw.WriteEndElement (); // br + xw.WriteStartElement ("font"); + xw.WriteAttributeString ("size", "1"); + xw.WriteString ("Started " + start_time); + xw.WriteStartElement ("br"); + xw.WriteEndElement (); // br + xw.WriteString ("Finished " + end_time); + xw.WriteEndElement (); //font + xw.WriteEndElement (); //td + xw.WriteEndElement (); //tr + xw.WriteEndElement (); //table + xw.WriteEndElement (); //td + xw.WriteEndElement (); //tr + xw.WriteEndElement (); //table + - return html; + } } }
Attachment:
gnome-gaim.png
Description: PNG image