gaimlog backend



The gaimlog backend didn't work if GAIM doesn't log in HTML -- I have
"Strip HTML from logs" enabled in the prefs.

I attach a patch which hopefully fixes that, and it also starts to make
a stab at putting the correct conversation ends info in, but it looks
like the indexing needs rewriting to get this done properly and I've not
got the time just yet.

-- Edd

Index: backend-gaimlog.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/backend-gaimlog.cs,v
retrieving revision 1.14
diff -u -r1.14 backend-gaimlog.cs
--- backend-gaimlog.cs	20 Jul 2003 15:53:23 -0000	1.14
+++ backend-gaimlog.cs	21 Jul 2003 09:58:54 -0000
@@ -5,6 +5,7 @@
 using System.Collections;
 using System.Runtime.InteropServices;
 using System.Xml;
+using System.Text.RegularExpressions;
 
 namespace Dashboard {
 
@@ -82,9 +83,21 @@
 		// Whether or not we have loaded the index file.
 		private bool IndexLoaded = false;
 
+		// start of conversation
+		private const string CONV_START
+			= "---- New Conversation @ ";
+
+		// regex for finding date
+		private const string REGEX_DATE
+			= "Conversation @ (\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+)";
+
+		private Regex dateregex;
+
 		public GaimLogIndex (string buddyname)
 		{
 			Buddyname = buddyname;
+			dateregex = new Regex (REGEX_DATE,
+					RegexOptions.IgnoreCase | RegexOptions.Compiled);
 		}
 
 		private string GetIndexPath ()
@@ -188,13 +201,18 @@
 
 		private string ExtractDateFromLine (string logline)
 		{
-			return logline.Substring (50, 24); // FIXME: Nasty hardcoded crap
+			System.Text.RegularExpressions.Match m;
+			m = dateregex.Match (logline);
+			if (m.Success) 
+				return m.Groups[1].ToString ();
+			else
+				return "NO DATE";
 		}
 
 		private bool LineMarksConversationStart (string logline)
 		{
 			// FIXME: Nasty hardcoded crap
-			if (logline.IndexOf ("<HR><BR><H3 Align=Center> ---- New Conversation @ ") == 0) {
+			if (logline.IndexOf (CONV_START) >= 0) {
 				return true;
 			}
 
@@ -333,6 +351,10 @@
 
 			for (int i = (Convs.Count - 1); i >= 0; i --) {
 				GaimLogIndexEntry entry = (GaimLogIndexEntry) Convs [i];
+				if (i > 0) {
+					GaimLogIndexEntry nextent = (GaimLogIndexEntry) Convs [i-1];
+					entry.EndOffset = nextent.StartOffset;
+				}
 				sw.WriteLine (String.Format ("{0},{1},{2}",
 							     entry.Date,
 							     entry.StartOffset,


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