[PATCH] Beagle backend v2



Ok so here goes the last version. I will not spam any more.

L.
--- backends/BeagleBackend.cs.~1.5.~	2004-06-29 21:23:39.000000000 +0200
+++ backends/BeagleBackend.cs	2004-07-18 21:47:16.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,74 @@
 				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;
 		}
 
+		class HitTypeLimiter
+		{
+			private int File = 0;
+			private int IMLog = 0;
+			private int Mail = 0;
+			private int Contact = 0;
+			
+			private const int MAX_FILE = 10;
+			private const int MAX_IMLOG = 5;
+			private const int MAX_MAIL = 5;
+			private const int MAX_CONTACT = 5;
+
+			public HitTypeLimiter ()
+			{
+				
+			}
+			
+			public bool Limit (Hit hit)
+			{
+				switch (hit.Type) {
+				case "File":
+					if (File != MAX_FILE) {
+						File++;
+						return true;
+					}
+					break;
+					
+				case "MailMessage":
+					if (Mail != MAX_MAIL) {
+						Mail++;
+						return true;
+					}
+					break;
+					
+				case "Contact":
+					if (Contact != MAX_CONTACT) {
+						Contact++;
+						return true;
+					}
+					break;
+					
+				case "IMLog":
+					if (IMLog != MAX_IMLOG) {
+						IMLog++;
+						return true;
+					}
+					break;
+					
+				default:
+					return true;
+				}
+				
+				return false;
+			}
+		}
+
 		public override BackendResult ProcessCluePacket (CluePacket cp)
 		{
 			if (! this.Initialized)
@@ -99,23 +162,25 @@
 				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 ();
 
+				HitTypeLimiter limiter = new HitTypeLimiter ();
 
-				int i = 0;
 				foreach (Hit hit in results.Hits) {
-					i ++;
-					if (i > 10)
-						break;
-					Match match = HitToMatch (hit, clue);
-					result.AddMatch (match);
+					if (limiter.Limit (hit)) {
+						Match match = HitToMatch (hit, clue);
+						result.AddMatch (match);
+					}
 				}
 			}
 
--- 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]