changeset 26796:0924698e2362

Add blist-node-(added|removed) and deprecate buddy-(added|removed). Closes #8309
author Paul Aurich <paul@darkrain42.org>
date Sun, 03 May 2009 17:10:51 +0000
parents ca7daa65bf0d
children 50edd9c80577
files ChangeLog.API doc/blist-signals.dox libpurple/blist.c libpurple/plugins/signals-test.c pidgin/gtkconv.c
diffstat 5 files changed, 109 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sun May 03 06:50:44 2009 +0000
+++ b/ChangeLog.API	Sun May 03 17:10:51 2009 +0000
@@ -13,6 +13,8 @@
 			* account-actions-changed
 			* account-created
 			* account-destroying
+		* blist-node-added and blist-node-removed signals (see
+		  blist-signals.dox)
 		* purple_buddy_destroy
 		* purple_buddy_get_protocol_data
 		* purple_buddy_set_protocol_data
@@ -54,6 +56,7 @@
 		  xmlnode_remove_with_namespace.
 
 		Deprecated:
+		* buddy-added and buddy-removed blist signals
 		* purple_buddy_get_local_alias
 		* purple_notify_user_info_remove_entry
 		* purple_status_type_set_primary_attr
--- a/doc/blist-signals.dox	Sun May 03 06:50:44 2009 +0000
+++ b/doc/blist-signals.dox	Sun May 03 17:10:51 2009 +0000
@@ -74,13 +74,30 @@
    a GList of PurpleBlistNodeAction's allowing a plugin to add menu items
  @endsignaldef
 
+ @signaldef blist-node-added
+  @signalproto
+void (*blist_node_added)(PurpleBlistNode *node)
+  @endsignalproto
+  @signaldesc
+   Emitted when a new blist node is added to the buddy list.
+ @endsignaldef
+
+ @signaldef blist-node-removed
+  @signalproto
+void (*blist_node_removed)(PurpleBlistNode *node)
+  @endsignalproto
+  @signaldesc
+   Emitted when a blist node is removed from the buddy list.
+ @endsignaldef
+
  @signaldef buddy-added
   @signalproto
 void (*buddy_added)(PurpleBuddy *buddy)
   @endsignalproto
   @signaldesc
    Emitted when a new buddy is added to the buddy list.
-  @endsignaldef
+  @deprecated Use blist-node-added instead.
+ @endsignaldef
 
  @signaldef buddy-removed
   @signalproto
@@ -88,7 +105,8 @@
   @endsignalproto
   @signaldesc
    Emitted when a buddy is removed from the buddy list.
-  @endsignaldef
+  @deprecated Use blist-node-removed instead.
+ @endsignaldef
 
  @signaldef buddy-icon-changed
   @signalproto
--- a/libpurple/blist.c	Sun May 03 06:50:44 2009 +0000
+++ b/libpurple/blist.c	Sun May 03 17:10:51 2009 +0000
@@ -1468,6 +1468,9 @@
 
 	if (ops && ops->update)
 		ops->update(purplebuddylist, (PurpleBlistNode *)cnode);
+
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-added",
+			cnode);
 }
 
 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node)
@@ -1615,6 +1618,9 @@
 
 	/* Signal that the buddy has been added */
 	purple_signal_emit(purple_blist_get_handle(), "buddy-added", buddy);
+
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-added",
+			PURPLE_BLIST_NODE(buddy));
 }
 
 PurpleContact *purple_contact_new()
@@ -1952,6 +1958,9 @@
 		for (node = gnode->child; node; node = node->next)
 			ops->update(purplebuddylist, node);
 	}
+
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-added",
+			gnode);
 }
 
 void purple_blist_remove_contact(PurpleContact *contact)
@@ -1994,6 +2003,9 @@
 		if (ops && ops->remove)
 			ops->remove(purplebuddylist, node);
 
+		purple_signal_emit(purple_blist_get_handle(), "blist-node-removed",
+				PURPLE_BLIST_NODE(contact));
+
 		/* Delete the node */
 		purple_contact_destroy(contact);
 	}
@@ -2066,6 +2078,9 @@
 	/* Signal that the buddy has been removed before freeing the memory for it */
 	purple_signal_emit(purple_blist_get_handle(), "buddy-removed", buddy);
 
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-removed",
+			PURPLE_BLIST_NODE(buddy));
+
 	purple_buddy_destroy(buddy);
 
 	/* If the contact is empty then remove it */
@@ -2109,6 +2124,9 @@
 	if (ops && ops->remove)
 		ops->remove(purplebuddylist, node);
 
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-removed",
+			PURPLE_BLIST_NODE(chat));
+
 	/* Delete the node */
 	purple_chat_destroy(chat);
 }
@@ -2141,6 +2159,9 @@
 	if (ops && ops->remove)
 		ops->remove(purplebuddylist, node);
 
+	purple_signal_emit(purple_blist_get_handle(), "blist-node-removed",
+			PURPLE_BLIST_NODE(group));
+
 	/* Remove the group from all accounts that are online */
 	for (l = purple_connections_get_all(); l != NULL; l = l->next)
 	{
@@ -2973,6 +2994,16 @@
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
 										PURPLE_SUBTYPE_BLIST_BUDDY));
 
+	purple_signal_register(handle, "blist-node-added",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_BLIST_NODE));
+
+	purple_signal_register(handle, "blist-node-removed",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_BLIST_NODE));
+
 	purple_signal_register(handle, "buddy-added",
 						 purple_marshal_VOID__POINTER, NULL, 1,
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
--- a/libpurple/plugins/signals-test.c	Sun May 03 06:50:44 2009 +0000
+++ b/libpurple/plugins/signals-test.c	Sun May 03 17:10:51 2009 +0000
@@ -145,16 +145,39 @@
 }
 
 static void
-buddy_added_cb(PurpleBuddy *buddy, void *data)
+blist_node_added_cb(PurpleBlistNode *bnode, void *data)
 {
-	purple_debug_misc("signals test", "buddy_added_cb (%s)\n",
-	                  purple_buddy_get_name(buddy));
+	const char *name;
+	if (PURPLE_BLIST_NODE_IS_GROUP(bnode))
+		name = purple_group_get_name(PURPLE_GROUP(bnode));
+	else if (PURPLE_BLIST_NODE_IS_CONTACT(bnode))
+		/* Close enough */
+		name = purple_contact_get_alias(PURPLE_CONTACT(bnode));
+	else if (PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+		name = purple_buddy_get_name(PURPLE_BUDDY(bnode));
+	else
+		name = "(unknown)";
+
+	purple_debug_misc("signals test", "blist_node_added_cb (%s)\n",
+	                  name ? name : "(null)");
 }
 
 static void
-buddy_removed_cb(PurpleBuddy *buddy, void *data)
+blist_node_removed_cb(PurpleBlistNode *bnode, void *data)
 {
-	purple_debug_misc("signals test", "buddy_removed_cb (%s)\n", purple_buddy_get_name(buddy));
+	const char *name;
+	if (PURPLE_BLIST_NODE_IS_GROUP(bnode))
+		name = purple_group_get_name(PURPLE_GROUP(bnode));
+	else if (PURPLE_BLIST_NODE_IS_CONTACT(bnode))
+		/* Close enough */
+		name = purple_contact_get_alias(PURPLE_CONTACT(bnode));
+	else if (PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+		name = purple_buddy_get_name(PURPLE_BUDDY(bnode));
+	else
+		name = "(unknown)";
+
+	purple_debug_misc("signals test", "blist_node_removed_cb (%s)\n",
+	                  name ? name : "(null)");
 }
 
 static void
@@ -643,10 +666,10 @@
 						plugin, PURPLE_CALLBACK(buddy_signed_on_cb), NULL);
 	purple_signal_connect(blist_handle, "buddy-signed-off",
 						plugin, PURPLE_CALLBACK(buddy_signed_off_cb), NULL);
-	purple_signal_connect(blist_handle, "buddy-added",
-						plugin, PURPLE_CALLBACK(buddy_added_cb), NULL);
-	purple_signal_connect(blist_handle, "buddy-removed",
-						plugin, PURPLE_CALLBACK(buddy_removed_cb), NULL);
+	purple_signal_connect(blist_handle, "blist-node-added",
+						plugin, PURPLE_CALLBACK(blist_node_added_cb), NULL);
+	purple_signal_connect(blist_handle, "blist-node-removed",
+						plugin, PURPLE_CALLBACK(blist_node_removed_cb), NULL);
 	purple_signal_connect(blist_handle, "buddy-icon-changed",
 						plugin, PURPLE_CALLBACK(buddy_icon_changed_cb), NULL);
 	purple_signal_connect(blist_handle, "blist-node-aliased",
--- a/pidgin/gtkconv.c	Sun May 03 06:50:44 2009 +0000
+++ b/pidgin/gtkconv.c	Sun May 03 17:10:51 2009 +0000
@@ -4496,19 +4496,26 @@
 }
 
 static void
-buddy_added_cb(PurpleBuddy *buddy, PurpleConversation *conv)
-{
-	buddy_cb_common(buddy, conv, TRUE);
-}
-
-static void
-buddy_removed_cb(PurpleBuddy *buddy, PurpleConversation *conv)
-{
+buddy_added_cb(PurpleBlistNode *node, PurpleConversation *conv)
+{
+	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
+		return;
+
+	buddy_cb_common(PURPLE_BUDDY(node), conv, TRUE);
+}
+
+static void
+buddy_removed_cb(PurpleBlistNode *node, PurpleConversation *conv)
+{
+	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
+		return;
+
 	/* If there's another buddy for the same "dude" on the list, do nothing. */
-	if (purple_find_buddy(buddy->account, buddy->name) != NULL)
+	if (purple_find_buddy(purple_buddy_get_account(PURPLE_BUDDY(node)),
+		                  purple_buddy_get_name(PURPLE_BUDDY(node))) != NULL)
 		return;
 
-	buddy_cb_common(buddy, conv, FALSE);
+	buddy_cb_common(PURPLE_BUDDY(node), conv, FALSE);
 }
 
 static void send_menu_cb(GtkWidget *widget, PidginConversation *gtkconv)
@@ -4747,9 +4754,9 @@
 	                                               "weight", CHAT_USERS_WEIGHT_COLUMN,
 	                                               NULL);
 
-	purple_signal_connect(blist_handle, "buddy-added",
+	purple_signal_connect(blist_handle, "blist-node-added",
 						gtkchat, PURPLE_CALLBACK(buddy_added_cb), conv);
-	purple_signal_connect(blist_handle, "buddy-removed",
+	purple_signal_connect(blist_handle, "blist-node-removed",
 						gtkchat, PURPLE_CALLBACK(buddy_removed_cb), conv);
 	purple_signal_connect(blist_handle, "blist-node-aliased",
 						gtkchat, PURPLE_CALLBACK(blist_node_aliased_cb), conv);
@@ -5121,7 +5128,8 @@
 	GList *list;
 
 	g_return_if_fail(bnode);
-	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(bnode));
+	if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+		return;
 
 	for (list = pidgin_conv_windows_get_list(); list; list = list->next)
 	{
@@ -8017,9 +8025,9 @@
                         handle, PURPLE_CALLBACK(account_status_changed_cb), NULL);
 
 	/* Callbacks to update a conversation */
-	purple_signal_connect(blist_handle, "buddy-added", handle,
+	purple_signal_connect(blist_handle, "blist-node-added", handle,
 						G_CALLBACK(buddy_update_cb), NULL);
-	purple_signal_connect(blist_handle, "buddy-removed", handle,
+	purple_signal_connect(blist_handle, "blist-node-removed", handle,
 						G_CALLBACK(buddy_update_cb), NULL);
 	purple_signal_connect(blist_handle, "buddy-signed-on",
 						handle, PURPLE_CALLBACK(update_buddy_sign), "on");