PATCH: displays gaim buddy's alias in output



This patch is a method (GetAliasForBuddy) that parses through gaim's
blist.xml file in the same way that GetIconForBuddy does, returning the
buddy's alias if it exists and their screenname if it doesn't.  The
output of this function is then used to display the buddy's name in
dashboard.  The patch also includes a very small fix to GetIconForBuddy,
since it wasn't comparing the strings correctly if there were spaces in
the screenname.
I know it's a small improvement, but it seemed like a good place to
start my work on dashboard.  The patch follows:

Index: backend-gaimlog.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/backend-gaimlog.cs,v
retrieving revision 1.21
diff -u -r1.21 backend-gaimlog.cs
--- backend-gaimlog.cs	1 Aug 2003 19:54:10 -0000	1.21
+++ backend-gaimlog.cs	5 Aug 2003 23:43:42 -0000
@@ -497,7 +497,7 @@
 
 				XmlNodeList nodes = blist.SelectNodes
("/gaim/blist/group/person/buddy/name");
 				foreach (XmlNode node in nodes) {
-					if (String.Compare (node.InnerText.ToLower (), buddy.ToLower ())
== 0) {
+					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;
@@ -512,14 +512,45 @@
 			return icon_path;
 		}
 
+		private string GetAliasForBuddy (string buddy)
+		{
+			string home_dir  = Environment.GetEnvironmentVariable ("HOME");
+			string path      = Path.Combine (home_dir, ".gaim/blist.xml");
+
+			Console.WriteLine ("Getting alias...");
+
+			try {
+				XmlDocument blist = new XmlDocument ();
+				blist.Load (path);
+
+				XmlNodeList nodes = blist.SelectNodes
("/gaim/blist/group/person/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");
+			}
+
+			return buddy;
+		}
+
 		private string GenerateHTML (GaimLogIndex idx)
 		{
 			string html;
 			string icon;
+			string name;
 
 			icon = this.GetIconForBuddy (idx.Buddyname);
 
-			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>",
icon, idx.Buddyname);
+			name = this.GetAliasForBuddy (idx.Buddyname);
+
+			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>",
icon, name);
 
 			for (int i = 0; i < 3 && i < idx.Convs.Count; i ++) {
 				string tmp = GenerateTmpFile (idx, i);

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]