changeset 11910:700ec4523c04

[gaim-migrate @ 14201] begone, buddy->present! committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 30 Oct 2005 23:33:36 +0000
parents 1b029c5898af
children fe12abd6b879
files src/blist.c src/blist.h src/gtkblist.c src/protocols/oscar/oscar.c
diffstat 4 files changed, 75 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Sun Oct 30 23:21:22 2005 +0000
+++ b/src/blist.c	Sun Oct 30 23:33:36 2005 +0000
@@ -710,39 +710,6 @@
 		ops->set_visible(gaimbuddylist, show);
 }
 
-static gboolean presence_update_timeout_cb(GaimBuddy *buddy)
-{
-	GaimBlistUiOps *ops = gaimbuddylist->ui_ops;
-	GaimConversation *conv;
-
-	g_return_val_if_fail(buddy != NULL, FALSE);
-
-	if (buddy->present == GAIM_BUDDY_SIGNING_ON) {
-		buddy->present = GAIM_BUDDY_ONLINE;
-	} else if (buddy->present == GAIM_BUDDY_SIGNING_OFF) {
-		buddy->present = GAIM_BUDDY_OFFLINE;
-		((GaimContact*)((GaimBlistNode*)buddy)->parent)->online--;
-		if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 0)
-			((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online--;
-	}
-
-	buddy->timer = 0;
-
-	if (ops && ops->update)
-		ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
-
-	conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name,
-											   buddy->account);
-	if (conv) {
-		if (buddy->present == GAIM_BUDDY_ONLINE)
-			gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE);
-		else if (buddy->present == GAIM_BUDDY_OFFLINE)
-			gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE);
-	}
-
-	return FALSE;
-}
-
 void
 gaim_blist_update_buddy_status(GaimBuddy *buddy, GaimStatus *old_status)
 {
@@ -761,28 +728,19 @@
 
 	if (gaim_status_is_online(status) &&
 		!gaim_status_is_online(old_status)) {
-		int old_present = buddy->present;
-
-		buddy->present = GAIM_BUDDY_SIGNING_ON;
+
 		gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-on", buddy);
-		if (old_present != GAIM_BUDDY_SIGNING_OFF) {
-			((GaimContact*)((GaimBlistNode*)buddy)->parent)->online++;
-			if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 1)
-				((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online++;
-		}
-		if (buddy->timer > 0)
-			gaim_timeout_remove(buddy->timer);
-		buddy->timer = gaim_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy);
-
+
+		((GaimContact*)((GaimBlistNode*)buddy)->parent)->online++;
+		if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 1)
+			((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online++;
 	} else if (!gaim_status_is_online(status) &&
 				gaim_status_is_online(old_status)) {
-		buddy->present = GAIM_BUDDY_SIGNING_OFF;
 		gaim_blist_node_set_int(&buddy->node, "last_seen", time(NULL));
 		gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-off", buddy);
-		if (buddy->timer > 0)
-			gaim_timeout_remove(buddy->timer);
-		buddy->timer = gaim_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy);
-
+		((GaimContact*)((GaimBlistNode*)buddy)->parent)->online--;
+		if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 0)
+			((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online--;
 	} else if (gaim_status_is_available(status) &&
 			   !gaim_status_is_available(old_status)) {
 		gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy);
@@ -1781,8 +1739,6 @@
 	gaim_signal_emit(gaim_blist_get_handle(), "buddy-removed", buddy);
 
 	/* Delete the node */
-	if (buddy->timer > 0)
-		gaim_timeout_remove(buddy->timer);
 	if (buddy->icon != NULL)
 		gaim_buddy_icon_unref(buddy->icon);
 	g_hash_table_destroy(buddy->node.settings);
--- a/src/blist.h	Sun Oct 30 23:21:22 2005 +0000
+++ b/src/blist.h	Sun Oct 30 23:33:36 2005 +0000
@@ -58,15 +58,6 @@
 #define GAIM_BLIST_NODE_IS_CONTACT(n) ((n)->type == GAIM_BLIST_CONTACT_NODE)
 #define GAIM_BLIST_NODE_IS_GROUP(n)   ((n)->type == GAIM_BLIST_GROUP_NODE)
 
-typedef enum
-{
-	GAIM_BUDDY_SIGNING_OFF = -1,
-	GAIM_BUDDY_OFFLINE = 0,
-	GAIM_BUDDY_ONLINE,
-	GAIM_BUDDY_SIGNING_ON
-
-} GaimBuddyPresenceState;
-
 #define GAIM_BUDDY_IS_ONLINE(b) \
 	((b) != NULL && gaim_account_is_connected((b)->account) && \
 	 gaim_presence_is_online(gaim_buddy_get_presence(b)))
@@ -111,12 +102,9 @@
 	char *name;                             /**< The screenname of the buddy. */
 	char *alias;                            /**< The user-set alias of the buddy */
 	char *server_alias;                     /**< The server-specified alias of the buddy.  (i.e. MSN "Friendly Names") */
-	GaimBuddyPresenceState present;         /**< This is 0 if the buddy appears offline, 1 if he appears online, and 2 if
-						    he has recently signed on */
 	void *proto_data;                       /**< This allows the prpl to associate whatever data it wants with a buddy */
 	GaimBuddyIcon *icon;                    /**< The buddy icon. */
 	GaimAccount *account;           	/**< the account this buddy belongs to */
-	guint timer;				/**< The timer handle. */
 	GaimPresence *presence;
 };
 
--- a/src/gtkblist.c	Sun Oct 30 23:21:22 2005 +0000
+++ b/src/gtkblist.c	Sun Oct 30 23:33:36 2005 +0000
@@ -127,6 +127,8 @@
 struct _gaim_gtk_blist_node {
 	GtkTreeRowReference *row;
 	gboolean contact_expanded;
+	gboolean recent_signonoff;
+	gint recent_signonoff_timer;
 };
 
 
@@ -2122,11 +2124,18 @@
 
 static gboolean buddy_is_displayable(GaimBuddy *buddy)
 {
-	return (buddy && gaim_account_is_connected(buddy->account) &&
+	struct _gaim_gtk_blist_node *gtknode;
+
+	if(!buddy)
+		return FALSE;
+
+	gtknode = ((GaimBlistNode*)buddy)->ui_data;
+
+	return (gaim_account_is_connected(buddy->account) &&
 			(gaim_presence_is_online(buddy->presence) ||
-		buddy->present == GAIM_BUDDY_SIGNING_OFF ||
-		gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies") ||
-			gaim_blist_node_get_bool((GaimBlistNode*)buddy, "show_offline")));
+			 (gtknode && gtknode->recent_signonoff) ||
+			 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies") ||
+			 gaim_blist_node_get_bool((GaimBlistNode*)buddy, "show_offline")));
 }
 
 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv)
@@ -2544,8 +2553,7 @@
 		}
 
 		/* Last Seen */
-		if ((!GAIM_BUDDY_IS_ONLINE(b) && b->present != GAIM_BUDDY_SIGNING_OFF) ||
-			b->present == GAIM_BUDDY_SIGNING_ON)
+		if (!GAIM_BUDDY_IS_ONLINE(b))
 		{
 			struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode *)c)->ui_data;
 			GaimBlistNode *bnode;
@@ -2632,6 +2640,7 @@
 	char *filename;
 	const char *protoname = NULL;
 	struct _gaim_gtk_blist_node *gtknode = node->ui_data;
+	struct _gaim_gtk_blist_node *gtkbuddynode = NULL;
 	struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15},
 		{NULL, 0, 0}, {NULL, 15, 0}};
 	GaimPresence *presence = NULL;
@@ -2639,10 +2648,13 @@
 	GaimChat *chat = NULL;
 
 	if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
-		if(!gtknode->contact_expanded)
+		if(!gtknode->contact_expanded) {
 			buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
+			gtkbuddynode = ((GaimBlistNode*)buddy)->ui_data;
+		}
 	} else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
 		buddy = (GaimBuddy*)node;
+		gtkbuddynode = node->ui_data;
 	} else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
 		chat = (GaimChat*)node;
 	} else {
@@ -2669,7 +2681,7 @@
 			protoname = prpl_info->list_icon(account, buddy);
 		}
 		if(prpl_info && prpl_info->list_emblems && buddy) {
-			if(buddy->present != GAIM_BUDDY_SIGNING_OFF)
+			if(!gtknode->recent_signonoff)
 				prpl_info->list_emblems(buddy, &emblems[0].filename,
 						&emblems[1].filename, &emblems[2].filename,
 						&emblems[3].filename);
@@ -2682,9 +2694,9 @@
 		emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL;
 	}
 
-	if(buddy && buddy->present == GAIM_BUDDY_SIGNING_ON) {
+	if(buddy && GAIM_BUDDY_IS_ONLINE(buddy) && gtkbuddynode->recent_signonoff) {
 			filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL);
-	} else if(buddy && buddy->present == GAIM_BUDDY_SIGNING_OFF) {
+	} else if(buddy && !GAIM_BUDDY_IS_ONLINE(buddy) && gtkbuddynode->recent_signonoff) {
 			filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL);
 	} else if(buddy || chat) {
 		char *image = g_strdup_printf("%s.png", protoname);
@@ -3494,6 +3506,8 @@
 
 static void gaim_gtk_blist_remove(GaimBuddyList *list, GaimBlistNode *node)
 {
+	struct _gaim_gtk_blist_node *gtknode = node->ui_data;
+
 	gaim_request_close_with_handle(node);
 
 	gaim_gtk_blist_hide_node(list, node);
@@ -3509,6 +3523,10 @@
 	/* Of course it still causes problems - this breaks dragging buddies into
 	 * contacts, the dragged buddy mysteriously 'disappears'. Stu. */
 	/* I think it's fixed now. Stu. */
+
+	if(gtknode->recent_signonoff_timer > 0)
+		gaim_timeout_remove(gtknode->recent_signonoff_timer);
+
 	g_free(node->ui_data);
 	node->ui_data = NULL;
 }
@@ -3778,7 +3796,7 @@
 
 	if (gtkparentnode->contact_expanded &&
 		(gaim_presence_is_online(buddy->presence) ||
-		buddy->present == GAIM_BUDDY_SIGNING_OFF ||
+		(0 /* XXX: if we just signed off, need to show logout.png */) ||
 			(gaim_account_is_connected(buddy->account) &&
 				gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) ||
 			gaim_blist_node_get_bool(node->parent, "show_offline")))
@@ -4585,6 +4603,39 @@
 	return &handle;
 }
 
+static gboolean buddy_signonoff_timeout_cb(GaimBuddy *buddy)
+{
+	struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode*)buddy)->ui_data;
+	GaimConversation *conv;
+
+	gtknode->recent_signonoff = FALSE;
+	gtknode->recent_signonoff_timer = 0;
+
+	gaim_gtk_blist_update(NULL, (GaimBlistNode*)buddy);
+
+	if((conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account))) {
+		if(GAIM_BUDDY_IS_ONLINE(buddy)) {
+			gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE);
+		} else {
+			gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE);
+		}
+	}
+
+	return FALSE;
+}
+
+static void buddy_signonoff_cb(GaimBuddy *buddy)
+{
+	struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode*)buddy)->ui_data;
+
+	gtknode->recent_signonoff = TRUE;
+
+	if(gtknode->recent_signonoff_timer > 0)
+		gaim_timeout_remove(gtknode->recent_signonoff_timer);
+	gtknode->recent_signonoff_timer = gaim_timeout_add(10000,
+			(GSourceFunc)buddy_signonoff_timeout_cb, buddy);
+}
+
 void gaim_gtk_blist_init(void)
 {
 	void *gtk_blist_handle = gaim_gtk_blist_get_handle();
@@ -4616,6 +4667,10 @@
 						 gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
 						 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_BLIST_NODE),
 						 gaim_value_new_outgoing(GAIM_TYPE_BOXED, "GString *"));
+
+
+	gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gtk_blist_handle, GAIM_CALLBACK(buddy_signonoff_cb), NULL);
+	gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gtk_blist_handle, GAIM_CALLBACK(buddy_signonoff_cb), NULL);
 }
 
 void
--- a/src/protocols/oscar/oscar.c	Sun Oct 30 23:21:22 2005 +0000
+++ b/src/protocols/oscar/oscar.c	Sun Oct 30 23:33:36 2005 +0000
@@ -6315,7 +6315,7 @@
 			   For more details, see SF issue 1179452.
 			*/
 			GaimBuddy *buddy = gaim_find_buddy(gc->account, name);
-			if (buddy && buddy->present != 0) {
+			if (buddy && GAIM_BUDDY_IS_ONLINE(buddy)) {
 				args.features = features_icq;
 				args.featureslen = sizeof(features_icq);
 			} else {