Re: Gaim Aliases in Beagle, and maybe buddy icons



On Sat, 2004-08-14 at 22:06 -0700, Matt Jones wrote:
> It turns out I had to add "file://" in front of the image path, so
> here's support for loading buddy icons (or, at least some icons). If a
> buddy icon is not found, it displays the icons for the service of the
> buddy (only for aim/oscar, but adding more is very simple), and it
> defaults to the standard icon if the buddy isn't found in gaim's account
> list (in case you've deleted the person from your list).
> 
> To use, apply this patch and drop ImBuddy.cs in Util/

Forgot to attach. Here they are.
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	15 Aug 2004 05:02:56 -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	15 Aug 2004 05:02:56 -0000
@@ -25,6 +25,8 @@
 //
 
 using System;
+using Beagle.Util;
+using System.IO;
 
 namespace Beagle.Tile {
 
@@ -33,16 +35,48 @@
 	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"];
+			}
+			if (key == "fixme:buddyicon") {
+				if (buddy == null)
+					return "gnome-gaim.png";
+				else if (buddy.BuddyIconLocation != "") {
+					string icon = Environment.GetEnvironmentVariable ("HOME");
+					icon = Path.Combine (icon, ".gaim");
+					icon = Path.Combine (icon, "icons");
+					icon = Path.Combine (icon, buddy.BuddyIconLocation);
+					icon = "file://" + icon;
+					return icon;
+				}
+				else if (buddy.Protocol == "prpl-oscar") {
+					return "file:///usr/share/pixmaps/gaim/status/default/aim.png";
+				}
+				else
+					return "gnome-gaim.png";
+			}
 			return hit [key];
 		}
 	}
Index: Tiles/template-im-log.html
===================================================================
RCS file: /cvs/gnome/beagle/Tiles/template-im-log.html,v
retrieving revision 1.3
diff -u -r1.3 template-im-log.html
--- Tiles/template-im-log.html	24 Jul 2004 21:57:45 -0000	1.3
+++ Tiles/template-im-log.html	15 Aug 2004 05:02:56 -0000
@@ -2,7 +2,7 @@
 <tr valign="top"><td>
 <table bgcolor="#e5f5e5" cellpadding="4" width="100%" height="100%">
 <tr valign="top">
-<td><a href="@Uri@"><img src="gnome-gaim.png" border="0"></a></td>
+<td><a href="@Uri@"><img src="@fixme:buddyicon@" border="0"></a></td>
 <td>
 <font size="2">IM with <strong>@fixme:speakingto@</strong></font><br>
 <font size="1">
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	15 Aug 2004 05:02:56 -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	\
//
// 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)];
		}

	}

}


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