gobjectification: 6a2a3dff: Contact adding fixes

aluink at soc.pidgin.im aluink at soc.pidgin.im
Sat Aug 1 11:25:38 EDT 2009


-----------------------------------------------------------------
Revision: 6a2a3dffbdee3ccb840acaf66b6a320c5b2a09ab
Ancestor: bc844c78a1f9c9b205762689563f0c07a54f175a
Author: aluink at soc.pidgin.im
Date: 2009-08-01T15:22:31
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/6a2a3dffbdee3ccb840acaf66b6a320c5b2a09ab

Modified files:
        libpurple/contact.c

ChangeLog: 

Contact adding fixes

-------------- next part --------------
============================================================
--- libpurple/contact.c	ff0d6ddc74569d73985dc7ea888cecb3c5592997
+++ libpurple/contact.c	ec701099aca17eca95047c1575dd178c0944a868
@@ -317,12 +317,12 @@ static void
 }
 
 static void
-purple_contact_child_update(PurpleContact *contact, PurpleBlistNode *child)
+purple_contact_child_updated(PurpleContact *contact, PurpleBuddy *child)
 {
-	g_return_if_fail(contact);
-	g_return_if_fail(child);
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	g_return_if_fail(PURPLE_IS_BUDDY(child));
 
-	if(purple_blist_node_is_online(child)){
+	if(purple_blist_node_is_online(PURPLE_BLIST_NODE(child))){
 		contact->online++;
 	} else {
 		contact->online--;
@@ -330,29 +330,50 @@ static void
 }
 
 static void
-purple_contact_add_buddy_child(PurpleBlistNode *parent, PurpleBlistNode *child)
+purple_contact_add_helper(PurpleContact *contact, PurpleBuddy *buddy)
 {
-	PurpleContact *contact;
-	
-	g_return_if_fail(parent);
-	g_return_if_fail(child);
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	g_return_if_fail(PURPLE_IS_BUDDY(buddy));
 
-	contact = PURPLE_CONTACT(parent);
+	#warning: gotta be a better way than just repeating this over and over
+	purple_signal_connect(purple_blist_node_get_handle(), "node-updated", /* What to connect to */
+		contact, /* Object receiving the signal */
+		PURPLE_CALLBACK(purple_contact_child_updated), /* Callback function */
+		contact /* Data to pass to the callback function */
+	);
 
-	purple_contact_child_update(contact, child);
+	purple_contact_child_updated(contact, buddy);
+}
 
+static void
+purple_contact_add_buddy_child(PurpleBlistNode *parent, PurpleBlistNode *child)
+{
+	g_return_if_fail(PURPLE_IS_CONTACT(parent));
+	g_return_if_fail(PURPLE_IS_BUDDY(child));
+
+	purple_contact_add_helper(PURPLE_CONTACT(parent), PURPLE_BUDDY(child));
+	parent_class->add_child(parent, child);
+
 }
 
 static void
 purple_contact_add_buddy_sibling(PurpleBlistNode *child, PurpleBlistNode *location)
 {
+	PurpleContact *contact;
 
+	g_return_if_fail(PURPLE_IS_CONTACT(purple_blist_node_parent(location)));
+	g_return_if_fail(PURPLE_IS_BUDDY(child));
+
+	contact = PURPLE_CONTACT(purple_blist_node_parent(location));
+
+	purple_contact_add_helper(contact, PURPLE_BUDDY(child));
+	parent_class->add_sibling(child, location);
 }
 
 static gboolean
 purple_contact_is_online(PurpleBlistNode *contact)
 {
-	g_return_val_if_fail(contact, FALSE);
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), FALSE);
 	return purple_contact_get_online(PURPLE_CONTACT(contact)) > 0;
 }
 
@@ -394,6 +415,7 @@ purple_contact_finalize(GObject *object)
 {
 	PurpleContact *contact = PURPLE_CONTACT(object);
 	g_free(contact->alias);
+	purple_signals_disconnect_by_handle(contact);
 	PURPLE_DBUS_UNREGISTER_POINTER(contact);
 	G_OBJECT_CLASS(parent_class)->finalize(object);
 }


More information about the Commits mailing list