small patch to gaimlogbackend



Hey,

This is a real small patch for GaimLogBackend that cleans up the way
we're getting the buddy icon and alias for the buddy in question.  There
was a bunch of duplicated code there and we were doing some of the XML
work twice.  This patch cleans that area up and should make it a little
quicker.  I'm pretty sure there was a FIXME at one point that pointed
out that this part was a little slow.  That's all for now.

--Mark.
Index: backends/GaimLogBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/GaimLogBackend.cs,v
retrieving revision 1.42
diff -u -r1.42 GaimLogBackend.cs
--- backends/GaimLogBackend.cs	4 Mar 2004 07:59:33 -0000	1.42
+++ backends/GaimLogBackend.cs	27 Apr 2004 04:39:08 -0000
@@ -56,8 +56,9 @@
 			idx.UpdateIndex ();
 
 			// Generate matches
-			string icon = GetIconForBuddy (idx.Buddyname);
-			string name = GetAliasForBuddy (idx.Buddyname);
+			Hashtable BuddyProperties = GetPropertiesOfBuddy (idx.Buddyname);
+			string name = (string)BuddyProperties["alias"];
+			string icon = (string)BuddyProperties["icon"];
 
 			for (int i = 0; i < idx.Convs.Count && i < 5; i++) {
 				Match match = new Match ("IMLog", clue);
@@ -132,61 +133,49 @@
 			return count;
 		}
 
-		private string GetIconForBuddy (string buddy)
+
+		private Hashtable GetPropertiesOfBuddy (string buddy)
 		{
-			string icon_path;
-			string home_dir  = Environment.GetEnvironmentVariable ("HOME");
-			string path      = Path.Combine (home_dir, ".gaim/blist.xml");
+			string home_dir = Environment.GetEnvironmentVariable ("HOME");
+			string path = Path.Combine (home_dir, ".gaim/blist.xml");
+
+			Console.WriteLine ("Getting properties for buddy: " + buddy);
 
-			icon_path = GetGaimIcon ();
+			Hashtable BuddyProperties = new Hashtable ();
 
-			Console.WriteLine ("Getting icon for buddy " + buddy);
+			string icon_path = "";
+			string alias = buddy;
 
 			try {
 				XmlDocument blist = new XmlDocument ();
 				blist.Load (path);
 
-				XmlNodeList nodes = blist.SelectNodes ("/gaim/blist/group/person/buddy/name");
+				XmlNodeList nodes = blist.SelectNodes ("/gaim/blist/group/contact/buddy/name");
 				foreach (XmlNode node in nodes) {
 					if (String.Compare (node.InnerText.ToLower().Replace(" ",""), buddy.ToLower().Replace(" ","")) == 0) {
 						XmlNode icon_node = node.ParentNode.SelectSingleNode ("setting[ name='buddy_icon']");
-						if (icon_node == null)
-							continue;
+						if (icon_node != null)
+							icon_path = icon_node.InnerText;
 
-						return icon_node.InnerText;
+						XmlNode alias_node = node.ParentNode.SelectSingleNode ("alias");
+						if (alias_node != null)
+							alias = alias_node.InnerText;
+						
+						break;
 					}
 				}
 			} catch {
-				Console.WriteLine ("Exception getting buddy icon");
+				Console.WriteLine ("Exception getting properties for buddy");
 			}
 
-			return icon_path;
-		}
-
-		private string GetAliasForBuddy (string buddy)
-		{
-			string home_dir  = Environment.GetEnvironmentVariable ("HOME");
-			string path      = Path.Combine (home_dir, ".gaim/blist.xml");
-
-			try {
-				XmlDocument blist = new XmlDocument ();
-				blist.Load (path);
-
-				XmlNodeList nodes = blist.SelectNodes ("/gaim/blist/group/contact/buddy/name");
-				foreach (XmlNode node in nodes) {
-					if (String.Compare (node.InnerText.ToLower().Replace(" ",""), buddy.ToLower().Replace(" ","")) == 0) {
-						XmlNode alias_node = node.ParentNode.SelectSingleNode ("alias");
-						if (alias_node == null)
-							continue;
-
-						return alias_node.InnerText;
-					}
-				}
-			} catch {
-				Console.WriteLine ("Exception getting buddy alias");
+			if (icon_path == "") {
+				icon_path = GetGaimIcon ();
 			}
 
-			return buddy;
+			BuddyProperties.Add ("alias", alias);
+			BuddyProperties.Add ("icon", icon_path);
+
+			return BuddyProperties;
 		}
 
 		private string GenerateTmpFile (GaimLogIndex idx, int conv_num)

Attachment: signature.asc
Description: This is a digitally signed message part



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