Gaim Aliases in Beagle, and maybe buddy icons



Hi - 

I've just hacked in support for displaying buddy aliases in beagle
tiles, read from a users gaim buddy list (blist.xml). I have support for
reading in icons (or, more correctly, icon locations), and I've attached
a patch to enable displaying buddy icons, but GtkHTML doesn't like the
format in which gaim stores images. If anyone knows how to fix this,
then just apply the patch and the icons will show up. 
Someone might want to test this patch (the basic one) with evolution-
gaim integration activated (or any other plugin that modifies the buddy
list) - I'm not sure how this works, and it shouldn't affect anything
anyways, but just in case.

To use - apply the attached patch (im-buddy.diff), and place ImBuddy.cs
in the Utils folder.

-- Matt Jones
//
// ImBuddy.cs
//
// Copyright (C) 2004 Matthew Jones <mattharrison sbcglobal net>
//

//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

using System;
using System.Collections;
using System.Xml;

namespace Beagle.Util {

	public class ImBuddy {
		public string Protocol = "";
		public string OwnerAccountName = "";
		public string BuddyAccountName = "";
		public string Alias = "";
		public string BuddyIconLocation = "";
		public string BuddyIconChecksum = "";

		public ImBuddy (string protocol, string owneraccount, string buddyaccount, string alias, string iconlocation, string iconchecksum) {
			Protocol = protocol;
			OwnerAccountName = owneraccount;
			BuddyAccountName = buddyaccount;
			Alias = alias;
			BuddyIconLocation = iconlocation;
			BuddyIconChecksum = iconchecksum;
		}
	}
	
	///////////////////////////////////////////////////////////////////////////////

	public abstract class ImBuddyListReader {

		public bool verbose = false;

		public Hashtable buddyList = new Hashtable ();

		abstract public void Read (string path);

		public void DebugPrint (string str) {
			if (!verbose)
				return;
			System.Console.WriteLine (str);
		}

		public class ImBuddyComparer : IComparer {
			
			int IComparer.Compare (Object x, Object y) {
				string accountx, accounty;
	
				try {
					accountx = ((ImBuddy) x).BuddyAccountName;
				} catch {
					accountx = "";
				}
				
				try {
					accounty = ((ImBuddy) y).BuddyAccountName;
				} catch {
					accounty = "";
				}
	
				return System.String.Compare (accountx, accounty);
			}
		}

		public class ImBuddyAliasComparer : IComparer {
			
			int IComparer.Compare (Object x, Object y) {
				string account;
				
				try {
					account = (string) x;
					return System.String.Compare ((string)x, ((ImBuddy) y).BuddyAccountName);
				} catch {
					return System.String.Compare (((ImBuddy) x).BuddyAccountName, (string)y);
				}
			}
		}
	}
	
	public class GaimBuddyListReader : ImBuddyListReader {

		private string Format (string name) {
			return name.ToLower ().Replace (" ", "");
		}

		override public void Read (string path)
		{
			XmlDocument accounts = new XmlDocument ();
			accounts.Load (path);

			XmlNodeList buddies = accounts.SelectNodes ("//buddy");
			
			foreach (XmlNode buddy in buddies) {
				string protocol, owner, other, alias, iconlocation, iconchecksum;
				
				protocol = "";
				owner = "";
				other = "";
				alias = "";
				iconlocation = "";
				iconchecksum = "";

				foreach (XmlAttribute attr in buddy.Attributes) {
					switch (attr.Name) {
						case "account":
							owner = attr.Value;
							DebugPrint ("owner: " + owner);
							break;
						case "proto":
							protocol = attr.Value;
							DebugPrint ("protocol: " + protocol);
							break;
					}
				}
				
				foreach (XmlNode attr in buddy.ChildNodes) {
					switch (attr.LocalName) {
						case "name":
							other = attr.InnerText;
							DebugPrint ("other: " + other);
							break;
						case "alias":
							alias = attr.InnerText;
							DebugPrint ("alias: " + alias);
							break;
						case "setting":
							foreach (XmlAttribute subattr in attr.Attributes) {
								if (subattr.Name == "name" && subattr.Value == "buddy_icon")
								{
									iconlocation = attr.InnerText;
									DebugPrint ("iconlocation: " + iconlocation);
								}
								else if ( subattr.Name == "name" && subattr.Value == "icon_checksum")
								{
									iconchecksum = attr.InnerText;
									DebugPrint ("iconchecksum: " + iconchecksum);
								}
							}
							break;
					}
				}

				ImBuddy old;

				if (buddyList.ContainsKey (Format(other))) {
					old = (ImBuddy)buddyList[Format(other)];
					if (old.Alias == "" && alias != "")
						old.Alias = alias;
					if (old.BuddyIconLocation == "" && iconlocation == "") {
						old.BuddyIconLocation = iconlocation;
						old.BuddyIconChecksum = iconchecksum;
					}
					buddyList.Remove (Format(other));
					buddyList.Add (Format(other), old);
				} 
				else
					buddyList.Add (Format(other), new ImBuddy (protocol, owner, Format(other), alias, iconlocation, iconchecksum));
			}
			
//			IComparer imbuddycomparer = new ImBuddyComparer ();
//			buddyList.Sort (imbuddycomparer);
			
		}

		public ImBuddy Search (string buddy) {
			return (ImBuddy)buddyList[Format(buddy)];
		}

	}

}
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/beagle/ChangeLog,v
retrieving revision 1.5
diff -u -r1.5 ChangeLog
--- ChangeLog	28 Jul 2004 18:52:31 -0000	1.5
+++ ChangeLog	14 Aug 2004 06:34:16 -0000
@@ -1,3 +1,8 @@
+2004-08-13  Matt Jones	<mattharrison sbcglobal net>
+	
+	* Utils/ImBuddy.cs: Support for reading gaim buddy lists
+	* Tiles/TileImLog.cs: Display gaim alias and icon if available
+
 2004-07-28  Alex Graveley  <alex ximian com>
 
 	* tools/IndexWebContent.cs: Rename --uri to --url, to match
Index: Tiles/TileImLog.cs
===================================================================
RCS file: /cvs/gnome/beagle/Tiles/TileImLog.cs,v
retrieving revision 1.4
diff -u -r1.4 TileImLog.cs
--- Tiles/TileImLog.cs	31 Jul 2004 21:51:44 -0000	1.4
+++ Tiles/TileImLog.cs	14 Aug 2004 06:34:17 -0000
@@ -25,6 +25,8 @@
 //
 
 using System;
+using Beagle.Util;
+using System.IO;
 
 namespace Beagle.Tile {
 
@@ -33,16 +35,31 @@
 	public class TileImLog : TileFromTemplate {
 
 		Hit hit;
+		ImBuddy buddy = null;
+		static GaimBuddyListReader list = null;
 
 		public TileImLog (Hit _hit) : base ("template-im-log.html")
 		{
+			if (list == null) {
+				list = new GaimBuddyListReader ();
+				string buddylist = Environment.GetEnvironmentVariable ("HOME");
+				buddylist = Path.Combine (buddylist, ".gaim");
+				buddylist = Path.Combine (buddylist, "blist.xml");
+				list.Read (buddylist);
+			}
 			hit = _hit;
+			buddy = list.Search (hit ["fixme:speakingto"]);
 		}
 
 		override protected string ExpandKey (string key)
 		{
 			if (key == "Uri")
 				return hit.Uri;
+			if (key == "fixme:speakingto") {
+				if (buddy != null && buddy.Alias != "")
+					return buddy.Alias + " (" + hit ["fixme:speakingto"] + ")";
+				return hit["fixme:speakingto"];
+			}
 			return hit [key];
 		}
 	}
Index: Util/Makefile.am
===================================================================
RCS file: /cvs/gnome/beagle/Util/Makefile.am,v
retrieving revision 1.15
diff -u -r1.15 Makefile.am
--- Util/Makefile.am	1 Aug 2004 00:21:11 -0000	1.15
+++ Util/Makefile.am	14 Aug 2004 06:34:17 -0000
@@ -19,6 +19,7 @@
 	$(srcdir)/FSpotTools.cs		\
 	$(srcdir)/Id3.cs		\
 	$(srcdir)/ImLog.cs		\
+	$(srcdir)/ImBuddy.cs		\
 	$(srcdir)/Logger.cs		\
 	$(srcdir)/MultiReader.cs	\
 	$(srcdir)/NautilusTools.cs	\
--- Tiles/TileImLog.cs	2004-08-13 23:47:19.364175440 -0700
+++ Tiles/TileImLog-Icons.cs	2004-08-13 23:46:44.076539976 -0700
@@ -61,14 +61,14 @@
 				return hit["fixme:speakingto"];
 			}
 			if (key == "fixme:buddyicon") {
-//				if (buddy != null && buddy.BuddyIconLocation != "") {
-//					string icon = Environment.GetEnvironmentVariable ("HOME");
-//					icon = Path.Combine (icon, ".gaim");
-//					icon = Path.Combine (icon, "icons");
-//					icon = Path.Combine (icon, buddy.BuddyIconLocation);
-//					return icon;
-//				}
-//				else
+				if (buddy != null && buddy.BuddyIconLocation != "") {
+					string icon = Environment.GetEnvironmentVariable ("HOME");
+					icon = Path.Combine (icon, ".gaim");
+					icon = Path.Combine (icon, "icons");
+					icon = Path.Combine (icon, buddy.BuddyIconLocation);
+					return icon;
+				}
+				else
 					return "gnome-gaim.png";
 			}
 			return hit [key];


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