gobjectification: bc844c78: Group adding work

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


-----------------------------------------------------------------
Revision: bc844c78a1f9c9b205762689563f0c07a54f175a
Ancestor: 2fbbe42e8102ea9c785c06c6be7a4d7163266cf7
Author: aluink at soc.pidgin.im
Date: 2009-08-01T14:56:57
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/bc844c78a1f9c9b205762689563f0c07a54f175a

Modified files:
        libpurple/blist-node.c libpurple/blist-node.h
        libpurple/buddy.c libpurple/chat.c libpurple/contact.c
        libpurple/contact.h libpurple/group.c

ChangeLog: 

Group adding work

-------------- next part --------------
============================================================
--- libpurple/blist-node.c	25dab095710c44dd8d4358680388414f7220283f
+++ libpurple/blist-node.c	d8eb580f1897b2ae200a011426896d92c47d7855
@@ -614,6 +614,18 @@ purple_blist_node_prev(PurpleBlistNode *
 	return NULL;
 }
 
+gboolean
+purple_blist_node_is_online(PurpleBlistNode *node)
+{
+	PurpleBlistNodeClass *klass;
+
+	g_return_val_if_fail(PURPLE_IS_BLIST_NODE(node), FALSE);
+	klass = PURPLE_GET_BLIST_NODE_CLASS(node);
+	if(klass && klass->is_online)
+		return klass->is_online(node);
+	return FALSE;
+}
+
 /******************/
 /*  GObject Code  */
 /******************/
@@ -671,6 +683,7 @@ purple_blist_node_class_init(PurpleBlist
 	klass->parent = purple_blist_node_real_parent;
 	klass->next = purple_blist_node_real_next;
 	klass->prev = purple_blist_node_real_prev;
+	klass->is_online = NULL;
 
 	purple_signal_register( purple_blist_node_handle(),
 													"group-removed",
============================================================
--- libpurple/blist-node.h	7c551a3b5950a1ec22cf358e449afa236cd39d72
+++ libpurple/blist-node.h	871f35b0d7192f7a85ea312482921189b24421d0
@@ -83,6 +83,7 @@ struct _PurpleBlistNodeClass {
 	PurpleBlistNode *(*parent)(PurpleBlistNode *child);
 	PurpleBlistNode *(*next)(PurpleBlistNode *node);
 	PurpleBlistNode *(*prev)(PurpleBlistNode *node);
+	gboolean (*is_online)(PurpleBlistNode *node);
 
 	void (*purple_reserved1)(void);
 	void (*purple_reserved2)(void);
@@ -269,6 +270,13 @@ gboolean purple_blist_node_is_empty(Purp
 gboolean purple_blist_node_is_empty(PurpleBlistNode *node);
 
 /**
+ * Returns if a blist-node is online
+ *
+ * @return the online status
+ */
+gboolean purple_blist_node_is_online(PurpleBlistNode *node);
+
+/**
  * Retrieves a named integer setting from a node in the buddy list
  *
  * @param node  The node to retrieve the data from
============================================================
--- libpurple/buddy.c	95fac21bf4aee01f8469764d0ce421511bb335e8
+++ libpurple/buddy.c	b82ac2cda8d38d5ae788d7bf0a49dcce3e7e7cd9
@@ -32,7 +32,7 @@
 #include "xmlnode.h"
 #include "buddy.h"
 
-static GObjectClass *parent_class = NULL;
+static PurpleBlistNodeClass *parent_class = NULL;
 
 struct _PurpleBuddyPrivate {
 	char *name;                             /**< The name of the buddy. */
@@ -466,6 +466,22 @@ purple_buddy_set_account(PurpleBuddy *bu
 	priv->account = account;
 }
 
+static gboolean
+purple_buddy_is_online(PurpleBlistNode *node)
+{
+	PurpleBuddy *buddy;
+	PurplePresence *presence;
+	PurpleStatus *status;
+
+	g_return_val_if_fail(node, FALSE);
+	buddy = PURPLE_BUDDY(node);
+
+	presence = purple_buddy_get_presence(buddy);
+	status = purple_presence_get_active_status(presence);
+	return purple_status_is_online(status);
+
+}
+
 /******************/
 /*  GObject Code  */
 /******************/
@@ -530,7 +546,7 @@ purple_buddy_finalize(GObject *object)
 	 * get freed while the timeout is pending and this line can
 	 * be removed. */
 	while (g_source_remove_by_user_data((gpointer *)buddy));
-	parent_class->finalize(object);
+	G_OBJECT_CLASS(parent_class)->finalize(object);
 }
 
 PurpleGroup *
@@ -588,6 +604,10 @@ purple_buddy_class_init(PurpleBuddyClass
 {
 	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 
+	parent_class = PURPLE_BLIST_NODE_CLASS(klass);
+	parent_class->is_online = purple_buddy_is_online;
+
+
 	parent_class = g_type_class_peek_parent(klass);
 	obj_class->finalize = purple_buddy_finalize;
 
============================================================
--- libpurple/chat.c	c1cc93b946628f634f5a1b90d6d748558ecdc2da
+++ libpurple/chat.c	38ba33a0d999a7fdc7d562764138ae448640339e
@@ -225,6 +225,15 @@ purple_chat_set_components(PurpleChat *c
 	chat->components = components;
 }
 
+static gboolean
+purple_chat_is_online(PurpleBlistNode *node)
+{
+	PurpleChat *chat;
+
+	g_return_val_if_fail(node, FALSE);
+	return purple_account_is_connected(PURPLE_CHAT(chat)->account);
+}
+
 /******************/
 /*  GObject Code  */
 /******************/
@@ -241,7 +250,7 @@ enum {
 #define PROP_ACCOUNT_S "account"
 #define PROP_COMPONENTS_S "components"
 
-static GObjectClass *parent_class = NULL;
+static PurpleBlistNodeClass *parent_class = NULL;
 
 PurpleChat *purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components)
 {
@@ -265,7 +274,7 @@ purple_chat_finalize(GObject *object)
 	g_hash_table_destroy(chat->components);
 	g_free(chat->alias);
 	PURPLE_DBUS_UNREGISTER_POINTER(chat);
-	parent_class->finalize(object);
+	G_OBJECT_CLASS(parent_class)->finalize(object);
 }
 
 static void
@@ -314,6 +323,9 @@ purple_chat_class_init(PurpleChatClass *
 {
 	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 
+	parent_class = PURPLE_BLIST_NODE_CLASS(klass);
+	parent_class->is_online = purple_chat_is_online;
+
 	parent_class = g_type_class_peek_parent(klass);
 	obj_class->finalize = purple_chat_finalize;
 
============================================================
--- libpurple/contact.c	dcb0e75282a90707139d8d17f17fbe4ad1f487c5
+++ libpurple/contact.c	ff0d6ddc74569d73985dc7ea888cecb3c5592997
@@ -317,9 +317,30 @@ static void
 }
 
 static void
+purple_contact_child_update(PurpleContact *contact, PurpleBlistNode *child)
+{
+	g_return_if_fail(contact);
+	g_return_if_fail(child);
+
+	if(purple_blist_node_is_online(child)){
+		contact->online++;
+	} else {
+		contact->online--;
+	}
+}
+
+static void
 purple_contact_add_buddy_child(PurpleBlistNode *parent, PurpleBlistNode *child)
 {
+	PurpleContact *contact;
+	
+	g_return_if_fail(parent);
+	g_return_if_fail(child);
 
+	contact = PURPLE_CONTACT(parent);
+
+	purple_contact_child_update(contact, child);
+
 }
 
 static void
@@ -328,6 +349,13 @@ purple_contact_add_buddy_sibling(PurpleB
 
 }
 
+static gboolean
+purple_contact_is_online(PurpleBlistNode *contact)
+{
+	g_return_val_if_fail(contact, FALSE);
+	return purple_contact_get_online(PURPLE_CONTACT(contact)) > 0;
+}
+
 static void
 purple_contact_remove_buddy(PurpleBlistNode *child)
 {
@@ -345,6 +373,8 @@ purple_contact_remove_buddy(PurpleBlistN
 
 	/* emit a node-updated signal here */
 
+	purple_signal_emit(purple_blist_node_get_handle(), "node-updated", contact);
+
 #warning The ui calls havent been thought out yet, as to where they ought to go.
 	/* Re-sort the contact */
 	if (purple_blist_node_first_child(PURPLE_BLIST_NODE(contact)) && contact->priority == buddy) {
@@ -377,6 +407,7 @@ purple_contact_class_init(PurpleContactC
 	parent_class->add_sibling = purple_contact_add_buddy_sibling;
 	parent_class->add_child = purple_contact_add_buddy_child;
 	parent_class->remove = purple_contact_remove_buddy;
+	parent_class->is_online = purple_contact_is_online;
 
 	obj_class->finalize = purple_contact_finalize;
 }
============================================================
--- libpurple/contact.h	5d8bd3aa66ac07cddb3fb79ba83df13c8884e72e
+++ libpurple/contact.h	50e38be12ebf581548a180a68044a1272db0e8c9
@@ -170,7 +170,7 @@ void purple_contact_buddy_status_update(
 void purple_contact_buddy_status_update(PurpleContact *contact, PurpleStatus *status, PurpleStatus *old_status);
 
 /**
- * Returns the number of buddies that correspond to online buddies
+ * Returns the number of buddies that correspond to online accounts
  *
  * @param contact The contact
  */
============================================================
--- libpurple/group.c	fa05064deffe944819664db0a75877e57e784d7c
+++ libpurple/group.c	f9d6f29ddb66545b1cd9ac9c53f9e380727d5068
@@ -93,11 +93,14 @@ static void
 }
 
 static void
-purple_group_add_update(PurpleGroup *group, PurpleBlistNode *child)
+purple_group_child_updated(PurpleGroup *group, PurpleBlistNode *child)
 {
 	PurpleChat *chat;
 	PurpleContact *contact;
 
+	g_return_if_fail(group);
+	g_return_if_fail(child);
+	
 	if(PURPLE_IS_CHAT(child)){
 		chat = PURPLE_CHAT(child);
 		if (purple_account_is_connected(chat->account)) {
@@ -108,6 +111,38 @@ purple_group_add_update(PurpleGroup *gro
 		contact = PURPLE_CONTACT(child);
 		if(purple_contact_get_online(contact) > 0)
 			group->online++;
+		if(purple_contact_get_currentsize(contact) == 1)/* Just came online */
+			group->currentsize++;
+	} else {
+		g_warn_if_reached();
+	}
+}
+
+static void
+purple_group_add_child_helper(PurpleGroup *group, PurpleBlistNode *child)
+{
+
+	PurpleChat *chat;
+	PurpleContact *contact;
+
+	g_return_if_fail(PURPLE_IS_GROUP(group));
+
+	purple_signal_connect(purple_blist_node_get_handle(), "node-updated", /* What to connect to */
+		group, /* Object receiving the signal */
+		PURPLE_CALLBACK(purple_group_child_updated), /* Callback function */
+		group /* Data to pass to the callback function */
+	);
+
+	if(PURPLE_IS_CHAT(child)){
+		chat = PURPLE_CHAT(child);
+		if (purple_account_is_connected(chat->account)) {
+			group->online++;
+			group->currentsize++;
+		}
+	} else if(PURPLE_IS_CONTACT(child)){
+		contact = PURPLE_CONTACT(child);
+		if(purple_contact_get_online(contact) > 0)
+			group->online++;
 		if(purple_contact_get_currentsize(contact) > 0)
 			group->currentsize++;
 	} else {
@@ -119,6 +154,11 @@ purple_group_add_update(PurpleGroup *gro
 	#warning Is this schedule save necessary?
 	purple_blist_schedule_save();
 	purple_signal_emit(purple_blist_node_get_handle(), "node-added", child);
+	purple_signal_connect(purple_blist_node_get_handle(), "node-updated", /* What to connect to */
+		group, /* Object receiving the signal */
+		PURPLE_CALLBACK(purple_group_child_updated), /* Callback function */
+		group /* Data to pass to the callback function */
+	);
 
 }
 
@@ -127,19 +167,21 @@ purple_group_add_sibling(PurpleBlistNode
 {
 	g_return_if_fail(node);
 	g_return_if_fail(PURPLE_IS_GROUP(purple_blist_node_parent(location)));
+	
+	purple_group_add_child_helper(PURPLE_GROUP(purple_blist_node_parent(location)), node);
 
 	parent_class->add_sibling(node, location);
-	purple_group_add_update(PURPLE_GROUP(purple_blist_node_parent(location)), node);
 }
 
 static void
 purple_group_add_child(PurpleBlistNode *parent, PurpleBlistNode *child)
 {
-	g_return_if_fail(parent);
+	g_return_if_fail(PURPLE_IS_GROUP(parent));
 	g_return_if_fail(child);
 
+	purple_group_add_child_helper(PURPLE_GROUP(parent), child);
+
 	parent_class->add_child(parent, child);
-	purple_group_add_update(PURPLE_GROUP(parent), child);
 }
 
 static void
@@ -227,40 +269,7 @@ GList *purple_group_get_buddies(PurpleGr
 	return buddies;
 }
 
-void
-purple_group_contact_updated(PurpleGroup *group, PurpleContact *contact)
-{
-	g_return_if_fail(group);
-	g_return_if_fail(contact);
-
-	if (purple_contact_get_online(contact) > 0)
-		group->online++;
-	else
-		group->online--;
-
-	if (purple_contact_get_currentsize(contact) > 0)
-		group->currentsize++;
-	else
-		group->currentsize--;
-}
-
 static void
-purple_group_add_contact(PurpleGroup *group, PurpleContact *contact, PurpleBlistNode *node)
-{
-	g_return_if_fail(group);
-	g_return_if_fail(contact);
-
-	if (node && (PURPLE_IS_CONTACT(node) ||
-				PURPLE_IS_CHAT(node))) {
-		purple_blist_node_add_sibling(PURPLE_BLIST_NODE(contact), node);
-	} else {
-		purple_blist_node_add_child(PURPLE_BLIST_NODE(group), PURPLE_BLIST_NODE(contact));
-	}	
-	purple_group_contact_updated(group, contact);
-	group->totalsize++;
-}
-
-static void
 purple_group_set_name(PurpleGroup *group, const char *name)
 {
 	g_return_if_fail(group != NULL);
@@ -300,6 +309,7 @@ purple_group_finalize(GObject *object)
 purple_group_finalize(GObject *object)
 {
 	PurpleGroup *group = PURPLE_GROUP(object);
+	purple_signals_disconnect_by_handle(group);
 	g_free(group->name);
 	PURPLE_DBUS_UNREGISTER_POINTER(group);
 	G_OBJECT_CLASS(parent_class)->finalize(object);


More information about the Commits mailing list