changeset 9860:65b3156f9f48

[gaim-migrate @ 10739] (21:34:57) shx: and after applying the on of the memleak... (21:35:15) shx: patch to auto update msn buddy icons committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 25 Aug 2004 01:43:54 +0000
parents 42f6b69c9d8e
children 68561f39acdc
files src/protocols/msn/history.h src/protocols/msn/msn.h src/protocols/msn/slp.c src/protocols/msn/slp.h src/protocols/msn/switchboard.c src/protocols/msn/user.c src/protocols/msn/userlist.c src/protocols/msn/userlist.h
diffstat 8 files changed, 124 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/history.h	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/history.h	Wed Aug 25 01:43:54 2004 +0000
@@ -24,7 +24,7 @@
 #ifndef _MSN_HISTORY_H
 #define _MSN_HISTORY_H
 
-#define MSN_HIST_ELEMS 8
+#define MSN_HIST_ELEMS 0x30
 
 typedef struct _MsnHistory MsnHistory;
 
--- a/src/protocols/msn/msn.h	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/msn.h	Wed Aug 25 01:43:54 2004 +0000
@@ -115,6 +115,4 @@
 	 (MSN_CLIENT_ID_RESERVED_2 <<  8) | \
 	 (MSN_CLIENT_ID_CAPABILITIES))
 
-void msn_request_buddy_icon(GaimConnection *gc, const char *who);
-
 #endif /* _MSN_H_ */
--- a/src/protocols/msn/slp.c	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/slp.c	Wed Aug 25 01:43:54 2004 +0000
@@ -40,6 +40,8 @@
 static void send_decline(MsnSlpCall *slpcall, const char *branch,
 						 const char *type, const char *content);
 
+void msn_request_user_display(MsnUser *user);
+
 /**************************************************************************
  * Util
  **************************************************************************/
@@ -753,32 +755,6 @@
 	g_strfreev(tokens);
 }
 
-void
-got_user_display(MsnSlpCall *slpcall,
-				 const char *data, long long size)
-{
-	const char *info;
-	GaimAccount *account;
-	GSList *sl;
-
-	info = slpcall->data_info;
-	gaim_debug_info("msn", "Got User Display: %s\n", info);
-
-	account = slpcall->slplink->session->account;
-
-	/* TODO: I think we need better buddy icon core functions. */
-	gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user,
-								  (void *)data, size);
-
-	sl = gaim_find_buddies(account, slpcall->slplink->remote_user);
-
-	for (; sl != NULL; sl = sl->next)
-	{
-		GaimBuddy *buddy = (GaimBuddy *)sl->data;
-		gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info);
-	}
-}
-
 static gboolean
 buddy_icon_cached(GaimConnection *gc, MsnObject *obj)
 {
@@ -816,30 +792,130 @@
 }
 
 void
-msn_request_buddy_icon(GaimConnection *gc, const char *passport)
+msn_release_buddy_icon_request(MsnUserList *userlist)
 {
-	MsnSession *session;
-	MsnSlpLink *slplink;
 	MsnUser *user;
-	MsnObject *obj;
-	const char *info;
+
+	while (userlist->buddy_icon_window > 0)
+	{
+		GQueue *queue;
+		GaimAccount *account;
+		const char *username;
+
+		queue = userlist->buddy_icon_requests;
+
+		if (g_queue_is_empty(userlist->buddy_icon_requests))
+			break;
+
+		user = g_queue_pop_head(queue);
 
-	session = gc->proto_data;
+		account  = userlist->session->account;
+		username = user->passport;
 
-	g_return_if_fail(session->protocol_ver == 9);
+		msn_request_user_display(user);
+		userlist->buddy_icon_window--;
+	}
+}
 
-	slplink = msn_session_get_slplink(session, passport);
+void
+msn_queue_buddy_icon_request(MsnUser *user)
+{
+	GaimAccount *account;
+	MsnObject *obj;
+	GQueue *queue;
 
-	user = msn_userlist_find_user(session->userlist, passport);
+	account = user->userlist->session->account;
 
 	obj = msn_user_get_object(user);
 
 	if (obj == NULL)
+	{
 		/* It seems the user has not set a msnobject */
+		GSList *sl;
+
+		/* TODO: I think we need better buddy icon core functions. */
+		gaim_buddy_icons_set_for_user(account, user->passport, NULL, -1);
+
+		sl = gaim_find_buddies(account, user->passport);
+
+		for (; sl != NULL; sl = sl->next)
+		{
+			GaimBuddy *buddy = (GaimBuddy *)sl->data;
+			gaim_blist_node_remove_setting((GaimBlistNode*)buddy, "icon_checksum");
+		}
+
 		return;
+	}
+
+	if (!buddy_icon_cached(account->gc, obj))
+	{
+		MsnUserList *userlist;
+
+		userlist = user->userlist;
+		queue = userlist->buddy_icon_requests;
+
+		g_queue_push_tail(queue, user);
+
+		if (userlist->buddy_icon_window > 0)
+			msn_release_buddy_icon_request(userlist);
+	}
+}
+
+void
+got_user_display(MsnSlpCall *slpcall,
+				 const char *data, long long size)
+{
+	const char *info;
+	GaimAccount *account;
+	GSList *sl;
+
+	info = slpcall->data_info;
+	gaim_debug_info("msn", "Got User Display: %s\n", info);
+
+	account = slpcall->slplink->session->account;
+
+	/* TODO: I think we need better buddy icon core functions. */
+	gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user,
+								  (void *)data, size);
+
+	sl = gaim_find_buddies(account, slpcall->slplink->remote_user);
+
+	for (; sl != NULL; sl = sl->next)
+	{
+		GaimBuddy *buddy = (GaimBuddy *)sl->data;
+		gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info);
+	}
+
+	slpcall->slplink->session->userlist->buddy_icon_window++;
+	msn_release_buddy_icon_request(slpcall->slplink->session->userlist);
+}
+
+void
+msn_request_user_display(MsnUser *user)
+{
+	GaimAccount *account;
+	MsnSession *session;
+	MsnSlpLink *slplink;
+	MsnObject *obj;
+	const char *info;
+
+	session = user->userlist->session;
+	account = session->account;
+
+	slplink = msn_session_get_slplink(session, user->passport);
+
+	obj = msn_user_get_object(user);
 
 	info = msn_object_get_sha1c(obj);
 
-	if (!buddy_icon_cached(gc, obj))
+	if (g_ascii_strcasecmp(user->passport,
+						   gaim_account_get_username(account)))
+	{
 		msn_slplink_request_object(slplink, info, got_user_display, obj);
+	}
+	else
+	{
+		session->userlist->buddy_icon_window++;
+		msn_release_buddy_icon_request(session->userlist);
+	}
 }
--- a/src/protocols/msn/slp.h	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/slp.h	Wed Aug 25 01:43:54 2004 +0000
@@ -24,7 +24,7 @@
 #ifndef _MSN_SLP_H_
 #define _MSN_SLP_H_
 
-#define DEBUG_SLP 1
+/* #define DEBUG_SLP 1 */
 /* #define DEBUG_SLP_FILES 1 */
 
 #include "slpcall.h"
@@ -45,4 +45,6 @@
 void msn_xfer_cancel(GaimXfer *xfer);
 void msn_xfer_end_cb(MsnSlpCall *slpcall);
 
+void msn_queue_buddy_icon_request(MsnUser *user);
+
 #endif /* _MSN_SLP_H_ */
--- a/src/protocols/msn/switchboard.c	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/switchboard.c	Wed Aug 25 01:43:54 2004 +0000
@@ -130,27 +130,8 @@
 ans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSwitchBoard *swboard;
-#if 1
-	MsnSession *session;
 
-	session = cmdproc->session;
 	swboard = cmdproc->servconn->data;
-
-	/* send_clientcaps(swboard); */
-
-	if (session->protocol_ver >= 9)
-	{
-		GList *l;
-
-		/* But we already know the switchboard... */
-		/* What if there is more than one user? */
-		for (l = swboard->users; l != NULL; l = l->next)
-		{
-			msn_request_buddy_icon(session->account->gc, l->data);
-		}
-	}
-#endif
-
 	swboard->ready = TRUE;
 }
 
@@ -256,12 +237,6 @@
 	msn_switchboard_process_queue(swboard);
 
 	send_clientcaps(swboard);
-
-#if 1
-	if (session->protocol_ver >= 9)
-		/* But we already know the switchboard... */
-		msn_request_buddy_icon(gc, passport);
-#endif
 }
 
 static void
--- a/src/protocols/msn/user.c	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/user.c	Wed Aug 25 01:43:54 2004 +0000
@@ -23,6 +23,7 @@
  */
 #include "msn.h"
 #include "user.h"
+#include "slp.h"
 
 MsnUser *
 msn_user_new(MsnUserList *userlist, const char *passport,
@@ -285,18 +286,8 @@
 
 	user->msnobj = obj;
 
-	if ((obj != NULL) && (user->list_op & MSN_LIST_FL_OP))
-	{
-		/* TODO: I think we need better buddy icon core functions */
-		GaimAccount *account;
-		const char *username;
-
-		account  = user->userlist->session->account;
-		username = msn_object_get_creator(obj);
-
-		if (gaim_find_conversation_with_account(username, account) != NULL)
-			msn_request_buddy_icon(account->gc, username);
-	}
+	if (user->list_op & MSN_LIST_FL_OP)
+		msn_queue_buddy_icon_request(user);
 }
 
 void
--- a/src/protocols/msn/userlist.c	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/userlist.c	Wed Aug 25 01:43:54 2004 +0000
@@ -397,6 +397,8 @@
 	userlist = g_new0(MsnUserList, 1);
 
 	userlist->session = session;
+	userlist->buddy_icon_requests = g_queue_new();
+	userlist->buddy_icon_window = 5;
 
 	return userlist;
 }
--- a/src/protocols/msn/userlist.h	Wed Aug 25 01:35:24 2004 +0000
+++ b/src/protocols/msn/userlist.h	Wed Aug 25 01:43:54 2004 +0000
@@ -56,6 +56,9 @@
 	GList *users;
 	GList *groups;
 
+	GQueue *buddy_icon_requests;
+	int buddy_icon_window;
+
 	int fl_users_count;
 
 };