gobjectification: 5af1e924: Some more fixes for the buddylist.

sadrul at pidgin.im sadrul at pidgin.im
Tue Jul 6 17:20:32 EDT 2010


----------------------------------------------------------------------
Revision: 5af1e924b84e34ca9fa723833da8796c66a78463
Parent:   0379396dde576bccfa74fcd060da4396b868ea40
Author:   sadrul at pidgin.im
Date:     07/06/10 14:55:43
Branch:   im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/5af1e924b84e34ca9fa723833da8796c66a78463

Changelog: 

Some more fixes for the buddylist.

purple_buddy_new now takes an additional parameter, 'parent', indicating
the parent node for the buddy (a PurpleContact or a PurpleGroup).

Changes against parent 0379396dde576bccfa74fcd060da4396b868ea40

  patched  libpurple/buddy.c
  patched  libpurple/buddy.h
  patched  libpurple/chat.c
  patched  libpurple/contact.c
  patched  libpurple/group.c

-------------- next part --------------
============================================================
--- libpurple/buddy.c	dc6e8990c10d20a7bb799e3401100b9b29180c69
+++ libpurple/buddy.c	88c47b1edbc341a158edb8a887f646bc71962c74
@@ -66,8 +66,9 @@ parse_buddy(PurpleGroup *group, PurpleCo
 
 	account = purple_accounts_find(acct_name, proto ? proto : protocol);
 
-	if (!account)
+	if (!account) {
 		return;
+	}
 
 	if ((x = xmlnode_get_child(bnode, "name")))
 		name = xmlnode_get_data(x);
@@ -78,9 +79,7 @@ parse_buddy(PurpleGroup *group, PurpleCo
 	if ((x = xmlnode_get_child(bnode, "alias")))
 		alias = xmlnode_get_data(x);
 
-	buddy = purple_buddy_new(account, name, alias);
-	purple_blist_add_buddy(buddy, contact, group,
-	purple_blist_get_last_child(PURPLE_BLIST_NODE(contact)));
+	buddy = purple_buddy_new(account, name, alias, PURPLE_BLIST_NODE(contact));
 
 	for (x = xmlnode_get_child(bnode, "setting"); x; x = xmlnode_get_next_twin(x)) {
 		parse_setting(PURPLE_BLIST_NODE(buddy), x);
@@ -517,16 +516,23 @@ enum {
 #define PROP_NAME_S "name"
 #define PROP_ALIAS_S "alias"
 
-PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias)
+PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name,
+		const char *alias, PurpleBlistNode *parent)
 {
+	PurpleBuddy *buddy;
 	g_return_val_if_fail(account != NULL, NULL);
 	g_return_val_if_fail(name != NULL, NULL);
 
-	return g_object_new(PURPLE_BUDDY_TYPE,
+	buddy = g_object_new(PURPLE_BUDDY_TYPE,
 			PROP_ACCOUNT_S, account,
 			PROP_NAME_S, name,
 			PROP_ALIAS_S, alias,
 			NULL);
+
+	purple_blist_node_add_child(parent, PURPLE_BLIST_NODE(buddy));
+	g_signal_emit_by_name(G_OBJECT(buddy), "new");
+
+	return buddy;
 }
 
 /* GObject destructor function */
@@ -635,8 +641,8 @@ purple_buddy_class_init(PurpleBuddyClass
 	g_type_class_add_private(klass, sizeof(PurpleBuddyPrivate));
 
 	g_object_class_install_property(obj_class, PROP_ACCOUNT,
-			g_param_spec_string(PROP_ACCOUNT_S, _("Account"),
-				_("The account for the buddy."), NULL,
+			g_param_spec_object(PROP_ACCOUNT_S, _("Account"),
+				_("The account for the buddy."), PURPLE_TYPE_ACCOUNT,
 				G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)
 			);
 	g_object_class_install_property(obj_class, PROP_NAME,
@@ -695,3 +701,4 @@ purple_buddy_get_type(void)
 
 	return type;
 }
+
============================================================
--- libpurple/chat.c	3b3ffc036c604747ae394457ab019d907471d4e0
+++ libpurple/chat.c	a54c107940854fd211df35c73d58a7d924601c65
@@ -376,14 +376,14 @@ purple_chat_class_init(PurpleChatClass *
 			);
 
 	g_object_class_install_property(obj_class, PROP_ACCOUNT,
-			g_param_spec_string(PROP_ACCOUNT_S, _("Account"),
-				_("The account for the chat."), NULL,
-				G_PARAM_CONSTRUCT_ONLY)
+			g_param_spec_object(PROP_ACCOUNT_S, _("Account"),
+				_("The account for the chat."), PURPLE_TYPE_ACCOUNT,
+				G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)
 			);
 
 	g_object_class_install_property(obj_class, PROP_COMPONENTS,
-			g_param_spec_string(PROP_COMPONENTS_S, _("Components"),
-				_("The components for the chat."), NULL,
+			g_param_spec_pointer(PROP_COMPONENTS_S, _("Components"),
+				_("The components for the chat."),
 				G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY)
 			);
 }
============================================================
--- libpurple/contact.c	8181dcd2bfb0ef1e0a0b65004664a031d51e8f9a
+++ libpurple/contact.c	6a330790a9f0ab8fbd63b0d12abd20299a6c7f01
@@ -85,8 +85,7 @@ parse_contact(PurpleGroup *group, xmlnod
 	xmlnode *x;
 	const char *alias;
 
-	purple_blist_node_add_sibling(PURPLE_BLIST_NODE(contact),
-			purple_blist_get_last_child(PURPLE_BLIST_NODE(group)));
+	purple_blist_node_add_child(PURPLE_BLIST_NODE(group), PURPLE_BLIST_NODE(contact));
 
 	if ((alias = xmlnode_get_attrib(cnode, "alias"))) {
 		purple_blist_alias_contact(contact, alias);
============================================================
--- libpurple/group.c	e69b8e270669c02814fd8d04c801ea2ed1ac78c3
+++ libpurple/group.c	fdd617cf8758351835b69b239517ad620da0e69e
@@ -157,15 +157,11 @@ purple_group_add_child(PurpleBlistNode *
 static void
 purple_group_add_child(PurpleBlistNode *parent, PurpleBlistNode *child)
 {
-	PurpleGroupPrivate *priv;
-	PurpleGroup *group;
-
+	/* This simply makes sure that a PurpleContact is created in case 'child' is a
+	 * PurpleBuddy */
 	g_return_if_fail(PURPLE_IS_GROUP(parent));
 	g_return_if_fail(child);
 
-	group = PURPLE_GROUP(parent);
-	priv = PURPLE_GROUP_GET_PRIVATE(group);
-
 	if (PURPLE_IS_BUDDY(child)) {
 		/* Create a PurpleContact with 'child', then add the contact. */
 		PurpleBlistNode *contact = PURPLE_BLIST_NODE(purple_contact_new());
@@ -174,7 +170,14 @@ purple_group_add_child(PurpleBlistNode *
 	}
 
 	parent_class->add_child(parent, child);
+}
 
+static void
+group_child_added(PurpleGroup *group, PurpleBlistNode *child, gpointer null)
+{
+	PurpleGroupPrivate *priv;
+	priv = PURPLE_GROUP_GET_PRIVATE(group);
+
 	if (PURPLE_IS_CHAT(child)) {
 		PurpleChat *chat = PURPLE_CHAT(child);
 		PurpleAccount *account = purple_chat_get_account(chat);
@@ -434,6 +437,8 @@ purple_group_init(GTypeInstance *instanc
 	if (ops && ops->new_node)
 		ops->new_node(PURPLE_BLIST_NODE(group));
 
+	/* Update the online/size counts when a new child is added. */
+	g_signal_connect(G_OBJECT(group), "child-added", G_CALLBACK(group_child_added), NULL);
 	PURPLE_DBUS_REGISTER_POINTER(group, PurpleGroup);
 }
 
============================================================
--- libpurple/buddy.h	f36d8ab3cd982c74dcb898dc0b05d4c490a9f8ea
+++ libpurple/buddy.h	ba45f8636141881c89d64bc7dd042d3b4cbcb1dd
@@ -70,12 +70,16 @@ void parse_buddy(PurpleGroup *group, Pur
  * @param account    The account this buddy will get added to
  * @param name       The name of the new buddy
  * @param alias      The alias of the new buddy (or NULL if unaliased)
+ * @param parent     A PurpleGroup or PurpleContact object, indicating the group or
+ *                   contact the buddy belongs to.
+ *
  * @return           A newly allocated buddy
  *
  * @see purple_account_add_buddy
  * @see purple_blist_add_buddy
  */
-PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias);
+PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name,
+		const char *alias, PurpleBlistNode *parent);
 
 /**
  * Destroys a buddy


More information about the Commits mailing list