diff src/blist.c @ 11454:201617d49573

[gaim-migrate @ 13693] This commit includes a number of changes: 1. Aliases are now used consistently in chats. If the prpl uses unique screen names for chats (e.g. Jabber), then aliases are not used at all. 2. The chat list is now colorized to match the colors used in the chat itself. 3. Buddies are bolded in the chat user list. 4. Buddies are sorted above non-buddies in the chat user list. 5. The chat user list is ellipsized when possible (i.e. on GTK+ 2.6.0 or above). 6. I've accepted patch #1178248, by Matt Amato to add "buddy-added" and "buddy-removed" signals. These were used in my implementation of #3 and #4, to update the GUI when users are added or removed from the buddy list. 7. I've added a "blist-node-aliased" signal that is emitted when a buddy, contact, or chat is aliased. 8. Since it was hard to separate and I need it at some point, I'm letting it slip in... I've changed GaimConversation.log to be a GList named logs. This way, we can have multiple logs for a single conversation. This will be necessary to implement unnamed chat logging in some reasonable fasion (see my notes in the TODO file). committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 06 Sep 2005 03:04:07 +0000
parents f191b5bc199b
children 3314953511de
line wrap: on
line diff
--- a/src/blist.c	Tue Sep 06 02:35:26 2005 +0000
+++ b/src/blist.c	Tue Sep 06 03:04:07 2005 +0000
@@ -850,10 +850,10 @@
 void gaim_blist_alias_chat(GaimChat *chat, const char *alias)
 {
 	GaimBlistUiOps *ops = gaimbuddylist->ui_ops;
+	char *old_alias = chat->alias;
 
 	g_return_if_fail(chat != NULL);
 
-	g_free(chat->alias);
 	if ((alias != NULL) && (*alias != '\0'))
 		chat->alias = g_strdup(alias);
 	else
@@ -863,16 +863,20 @@
 
 	if (ops && ops->update)
 		ops->update(gaimbuddylist, (GaimBlistNode *)chat);
+
+	gaim_signal_emit(gaim_blist_get_handle(), "blist-node-aliased",
+					 chat, old_alias);
+	g_free(old_alias);
 }
 
 void gaim_blist_alias_buddy(GaimBuddy *buddy, const char *alias)
 {
 	GaimBlistUiOps *ops = gaimbuddylist->ui_ops;
 	GaimConversation *conv;
+	char *old_alias = buddy->alias;
 
 	g_return_if_fail(buddy != NULL);
 
-	g_free(buddy->alias);
 	if ((alias != NULL) && (*alias != '\0'))
 		buddy->alias = g_strdup(alias);
 	else
@@ -887,16 +891,20 @@
 											   buddy->account);
 	if (conv)
 		gaim_conversation_autoset_title(conv);
+
+	gaim_signal_emit(gaim_blist_get_handle(), "blist-node-aliased",
+					 buddy, old_alias);
+	g_free(old_alias);
 }
 
 void gaim_blist_server_alias_buddy(GaimBuddy *buddy, const char *alias)
 {
 	GaimBlistUiOps *ops = gaimbuddylist->ui_ops;
 	GaimConversation *conv;
+	char *old_alias = buddy->server_alias;
 
 	g_return_if_fail(buddy != NULL);
 
-	g_free(buddy->server_alias);
 	if ((alias != NULL) && (*alias != '\0') && g_utf8_validate(alias, -1, NULL))
 		buddy->server_alias = g_strdup(alias);
 	else
@@ -911,6 +919,10 @@
 											   buddy->account);
 	if (conv)
 		gaim_conversation_autoset_title(conv);
+
+	gaim_signal_emit(gaim_blist_get_handle(), "blist-node-aliased",
+					 buddy, old_alias);
+	g_free(old_alias);
 }
 
 /*
@@ -1338,6 +1350,9 @@
 
 	if (ops && ops->update)
 		ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
+
+	/* Signal that the buddy has been added */
+	gaim_signal_emit(gaim_blist_get_handle(), "buddy-added", buddy);
 }
 
 GaimContact *gaim_contact_new()
@@ -1361,12 +1376,10 @@
 void gaim_contact_set_alias(GaimContact *contact, const char *alias)
 {
 	GaimBlistUiOps *ops = gaimbuddylist->ui_ops;
+	char *old_alias = contact->alias;
 
 	g_return_if_fail(contact != NULL);
 
-	if (contact->alias != NULL)
-		g_free(contact->alias);
-
 	if ((alias != NULL) && (*alias != '\0'))
 		contact->alias = g_strdup(alias);
 	else
@@ -1376,6 +1389,10 @@
 
 	if (ops && ops->update)
 		ops->update(gaimbuddylist, (GaimBlistNode*)contact);
+
+	gaim_signal_emit(gaim_blist_get_handle(), "blist-node-aliased",
+					 contact, old_alias);
+	g_free(old_alias);
 }
 
 const char *gaim_contact_get_alias(GaimContact* contact)
@@ -1670,7 +1687,7 @@
 		}
 		/*
 		 * Remove the last buddy and trigger the deletion of the contact.
-		 * It would probably be cleaner if contact-deletion was done after 
+		 * It would probably be cleaner if contact-deletion was done after
 		 * a timeout?  Or if it had to be done manually, like below?
 		 */
 		gaim_blist_remove_buddy((GaimBuddy*)node->child);
@@ -1756,6 +1773,9 @@
 	if (ops && ops->remove)
 		ops->remove(gaimbuddylist, node);
 
+	/* Signal that the buddy has been removed before freeing the memory for it */
+	gaim_signal_emit(gaim_blist_get_handle(), "buddy-removed", buddy);
+
 	/* Delete the node */
 	if (buddy->timer > 0)
 		gaim_timeout_remove(buddy->timer);
@@ -1839,7 +1859,7 @@
 		buf = g_strdup_printf(ngettext("%d buddy from group %s was not removed "
 									   "because its account was not logged in."
 									   "  This buddy and the group were not "
-									   "removed.\n", 
+									   "removed.\n",
 									   "%d buddies from group %s were not "
 									   "removed because their accounts were "
 									   "not logged in.  These buddies and "
@@ -2601,6 +2621,16 @@
 						 gaim_value_new(GAIM_TYPE_SUBTYPE,
 										GAIM_SUBTYPE_BLIST_BUDDY));
 
+	gaim_signal_register(handle, "buddy-added",
+						 gaim_marshal_VOID__POINTER, NULL, 1,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_BLIST_BUDDY));
+
+	gaim_signal_register(handle, "buddy-removed",
+						 gaim_marshal_VOID__POINTER, NULL, 1,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_BLIST_BUDDY));
+
 	gaim_signal_register(handle, "update-idle", gaim_marshal_VOID, NULL, 0);
 
 	gaim_signal_register(handle, "blist-node-extended-menu",
@@ -2608,6 +2638,12 @@
 			     gaim_value_new(GAIM_TYPE_SUBTYPE,
 					    GAIM_SUBTYPE_BLIST_NODE),
 			     gaim_value_new(GAIM_TYPE_BOXED, "GList **"));
+
+	gaim_signal_register(handle, "blist-node-aliased",
+						 gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_BLIST_NODE),
+						 gaim_value_new(GAIM_TYPE_STRING));
 }
 
 void