gobjectification: b92015e0: Hide contact members

aluink at soc.pidgin.im aluink at soc.pidgin.im
Mon Aug 3 23:55:45 EDT 2009


-----------------------------------------------------------------
Revision: b92015e0f6052ff5c302d3f6daf4aecdaf400027
Ancestor: 31146d0cdfc652391cb42db42bbbfe27650d706e
Author: aluink at soc.pidgin.im
Date: 2009-08-04T03:50:11
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/b92015e0f6052ff5c302d3f6daf4aecdaf400027

Modified files:
        libpurple/blist.c libpurple/blist.h libpurple/buddy.c
        libpurple/buddy.h libpurple/contact.c libpurple/contact.h

ChangeLog: 

Hide contact members

-------------- next part --------------
============================================================
--- libpurple/blist.c	15be403dfac57b4baedf58c821dacf1acee44d85
+++ libpurple/blist.c	095008a8c6d966806343154287726bfd47653246
@@ -1104,6 +1104,8 @@ void purple_blist_add_account(PurpleAcco
 	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleBuddyList *list = PURPLE_BLIST;
 
+	/* There are long/nasty lines in this function, and it's sibling remove, 
+	 * for now until we can do most of this with signals */
 
 	if (!ops || !ops->update)
 		return;
@@ -1119,9 +1121,10 @@ void purple_blist_add_account(PurpleAcco
 						if (PURPLE_IS_BUDDY(bnode) &&
 								purple_buddy_get_account(PURPLE_BUDDY(bnode)) == account) {
 							recompute = TRUE;
-							(PURPLE_CONTACT(cnode))->currentsize++;
-							if ((PURPLE_CONTACT(cnode))->currentsize == 1)
-								(PURPLE_GROUP(gnode))->currentsize++;
+							purple_contact_set_currentsize(PURPLE_CONTACT(cnode), 
+								purple_contact_get_currentsize(PURPLE_CONTACT(cnode))+1);
+							if (purple_contact_get_currentsize(PURPLE_CONTACT(cnode)) == 1)
+								PURPLE_GROUP(gnode)->currentsize++;
 							ops->update(bnode);
 						}
 					}
@@ -1132,8 +1135,8 @@ void purple_blist_add_account(PurpleAcco
 					}
 			} else if (PURPLE_IS_CHAT(cnode) &&
 					purple_chat_get_account(PURPLE_CHAT(cnode)) == account) {
-				(PURPLE_GROUP(gnode))->online++;
-				(PURPLE_GROUP(gnode))->currentsize++;
+				PURPLE_GROUP(gnode)->online++;
+				PURPLE_GROUP(gnode)->currentsize++;
 				ops->update(cnode);
 			}
 		}
@@ -1175,22 +1178,24 @@ void purple_blist_remove_account(PurpleA
 						presence = purple_buddy_get_presence(buddy);
 
 						if(purple_presence_is_online(presence)) {
-							contact->online--;
-							if (contact->online == 0)
+							purple_contact_set_currentsize(contact,
+								purple_contact_get_currentsize(contact)-1);
+							if (purple_contact_get_online(contact) == 0)
 								group->online--;
 
 							purple_blist_node_set_int(&buddy->node,
 													"last_seen", time(NULL));
 						}
 
-						contact->currentsize--;
-						if (contact->currentsize == 0)
+						purple_contact_set_currentsize(contact,
+							purple_contact_get_currentsize(contact)-1);
+						if (purple_contact_get_currentsize(contact) == 0)
 							group->currentsize--;
 
 						if (!g_list_find(list, presence))
 							list = g_list_prepend(list, presence);
 
-						if (contact->priority == buddy)
+						if (purple_contact_get_priority_buddy(contact) == buddy)
 							purple_contact_invalidate_priority_buddy(contact);
 						else
 							recompute = TRUE;
@@ -1366,16 +1371,16 @@ void purple_blist_add_buddy(PurpleBuddy 
 
 	if (bnode->parent) {
 		if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
-			((PurpleContact*)bnode->parent)->online--;
+			/*((PurpleContact*)bnode->parent)->online--;
 			if (((PurpleContact*)bnode->parent)->online == 0)
-				(PURPLE_GROUP(bnode->parent->parent))->online--;
+				(PURPLE_GROUP(bnode->parent->parent))->online--;*/
 		}
 		if (purple_account_is_connected(purple_buddy_get_account(buddy))) {
-			((PurpleContact*)bnode->parent)->currentsize--;
+/*			((PurpleContact*)bnode->parent)->currentsize--;
 			if (((PurpleContact*)bnode->parent)->currentsize == 0)
-				(PURPLE_GROUP(bnode->parent->parent))->currentsize--;
+				(PURPLE_GROUP(bnode->parent->parent))->currentsize--;*/
 		}
-		((PurpleContact*)bnode->parent)->totalsize--;
+/*		((PurpleContact*)bnode->parent)->totalsize--;*/
 		/* the group totalsize will be taken care of by remove_contact below */
 
 		if (bnode->parent->parent != PURPLE_BLIST_NODE(g))
@@ -1431,7 +1436,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 		bnode->parent = cnode;
 	}
 
-	if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
+/*	if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
 		if (++(PURPLE_CONTACT(bnode->parent)->online) == 1)
 			PURPLE_GROUP(bnode->parent->parent)->online++;
 	}
@@ -1439,7 +1444,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 		if (++(PURPLE_CONTACT(bnode->parent)->currentsize) == 1)
 			PURPLE_GROUP(bnode->parent->parent)->currentsize++;
 	}
-	PURPLE_CONTACT(bnode->parent)->totalsize++;
+	PURPLE_CONTACT(bnode->parent)->totalsize++;*/
 
 	hb = g_new(struct _purple_hbuddy, 1);
 	hb->name = g_strdup(purple_normalize(purple_buddy_get_account(buddy), purple_buddy_get_name(buddy)));
============================================================
--- libpurple/blist.h	3ae362bbe097e323dbbf496b40969ada5b4a818a
+++ libpurple/blist.h	d99eb684af9d4347a1c60c2acbea26dc9ea737db
@@ -294,6 +294,11 @@ void purple_blist_add_chat(PurpleChat *c
 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node);
 
 /**
+ *
+ * THIS METHOD IS BROKEN AND WILL SOON BE REMOVED
+ * IT'S ONLY AROUND TO LOOK AT THE LOGIC DURING THE
+ * REWRITE
+ *
  * Adds a new buddy to the buddy list.
  *
  * The buddy will be inserted right after node or prepended to the
@@ -305,6 +310,7 @@ void purple_blist_add_chat(PurpleChat *c
  * @param group   The group to add the new buddy to.
  * @param node    The insertion point.  Pass in NULL to add the node as
  *                the first child in the given group.
+ * @deprecated
  */
 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
 
============================================================
--- libpurple/buddy.c	29a366bd54cedfaab7b9ceb67a2a786f5c98bae1
+++ libpurple/buddy.c	3598cc1bfc250ec71b0d243a654563f6576429ff
@@ -32,6 +32,8 @@
 #include "xmlnode.h"
 #include "buddy.h"
 
+#define PURPLE_BUDDY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PURPLE_BUDDY_TYPE, PurpleBuddyPrivate))
+
 static PurpleBlistNodeClass *parent_class = NULL;
 
 struct _PurpleBuddyPrivate {
============================================================
--- libpurple/buddy.h	cf28a3312c8746fbb70e281e3bb9e638ab0fdb1c
+++ libpurple/buddy.h	28eacde7c47142ebe6ee427c2255e7d2eea43a16
@@ -44,7 +44,6 @@ typedef struct _PurpleBuddyClass PurpleB
 #define PURPLE_BUDDY_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_BUDDY_TYPE, PurpleBuddyClass))
 #define PURPLE_IS_BUDDY_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BUDDY_TYPE))
 #define PURPLE_GET_BUDDY_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BUDDY_TYPE, PurpleBuddyClass))
-#define PURPLE_BUDDY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PURPLE_BUDDY_TYPE, PurpleBuddyPrivate))
 
 #if !(defined PURPLE_HIDE_STRUCTS) || (defined _PURPLE_BUDDY_C_)
 /**
============================================================
--- libpurple/contact.c	ec701099aca17eca95047c1575dd178c0944a868
+++ libpurple/contact.c	7829c4b6ea110aeb0218b14552efa2674fcc71a5
@@ -31,22 +31,34 @@
 #include "signals.h"
 #include "xmlnode.h"
 
+#define PURPLE_CONTACT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PURPLE_CONTACT_TYPE, PurpleContactPrivate))
+
+struct _PurpleContactPrivate {
+	char *alias;            /**< The user-set alias of the contact */
+	int totalsize;		    /**< The number of buddies in this contact */
+	int currentsize;	    /**< The number of buddies in this contact corresponding to online accounts */
+	int online;			    /**< The number of buddies in this contact who are currently online */
+	PurpleBuddy *priority;    /**< The "top" buddy for this contact */
+	gboolean priority_valid; /**< Is priority valid? */
+};
+
 static PurpleBlistNodeClass *parent_class = NULL;
 
 xmlnode *
 contact_to_xmlnode(PurpleBlistNode *cnode)
 {
 	xmlnode *node, *child;
-	PurpleContact *contact;
 	PurpleBlistNode *bnode;
+	PurpleContactPrivate *priv;
 
-	contact = PURPLE_CONTACT(cnode);
+	g_return_val_if_fail(PURPLE_IS_CONTACT(cnode), NULL);
+	priv = PURPLE_CONTACT_GET_PRIVATE(cnode);
 
 	node = xmlnode_new("contact");
 
-	if (contact->alias != NULL)
+	if (priv->alias != NULL)
 	{
-		xmlnode_set_attrib(node, "alias", contact->alias);
+		xmlnode_set_attrib(node, "alias", priv->alias);
 	}
 
 	/* Write buddies */
@@ -100,11 +112,12 @@ purple_contact_compute_priority_buddy(Pu
 {
 	PurpleBlistNode *bnode;
 	PurpleBuddy *new_priority = NULL;
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
-	g_return_if_fail(contact != NULL);
-
-	contact->priority = NULL;
-	for (bnode = (PURPLE_BLIST_NODE(contact))->child;
+	priv->priority = NULL;
+	for (bnode = purple_blist_node_first_child(PURPLE_BLIST_NODE(contact));
 			bnode != NULL;
 			bnode = bnode->next)
 	{
@@ -135,8 +148,8 @@ purple_contact_compute_priority_buddy(Pu
 		}
 	}
 
-	contact->priority = new_priority;
-	contact->priority_valid = TRUE;
+	priv->priority = new_priority;
+	priv->priority_valid = TRUE;
 }
 
 /*****************************************************************************
@@ -150,23 +163,26 @@ void purple_blist_alias_contact(PurpleCo
 	PurpleBlistNode *bnode;
 	char *old_alias;
 	char *new_alias = NULL;
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
 	g_return_if_fail(contact != NULL);
 
 	if ((alias != NULL) && (*alias != '\0'))
 		new_alias = purple_utf8_strip_unprintables(alias);
 
-	if (!purple_strings_are_different(contact->alias, new_alias)) {
+	if (!purple_strings_are_different(priv->alias, new_alias)) {
 		g_free(new_alias);
 		return;
 	}
 
-	old_alias = contact->alias;
+	old_alias = priv->alias;
 
 	if ((new_alias != NULL) && (*new_alias != '\0'))
-		contact->alias = new_alias;
+		priv->alias = new_alias;
 	else {
-		contact->alias = NULL;
+		priv->alias = NULL;
 		g_free(new_alias); /* could be "\0" */
 	}
 
@@ -203,42 +219,79 @@ PurpleContact *purple_buddy_get_contact(
 	return PURPLE_CONTACT(PURPLE_BLIST_NODE(buddy)->parent);
 }
 
+int purple_contact_get_totalsize(PurpleContact *contact)
+{
+	PurpleContactPrivate *priv;
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), 0);
+
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	return priv->totalsize;
+}
+
+void purple_contact_set_totalsize(PurpleContact *contact, int value)
+{
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	priv->totalsize = value;
+}
+
 int
 purple_contact_get_online(PurpleContact *contact)
 {
-	g_return_val_if_fail(contact, 0);
-	return contact->online;
+	PurpleContactPrivate *priv;
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), 0);
+
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	return priv->online;
 }
 
 void
 purple_contact_set_online(PurpleContact *contact, int count)
 {
-	g_return_if_fail(contact);
-	contact->online = count;
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	priv->online = count;
 }
 
 int
 purple_contact_get_currentsize(PurpleContact *contact)
 {
-	g_return_val_if_fail(contact, 0);
-	return contact->currentsize;
+	PurpleContactPrivate *priv;
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), 0);
+
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	return priv->currentsize;
 }
 
 void
-purple_contact_buddy_status_update(PurpleContact *contact, PurpleStatus *status, PurpleStatus *old_status)
+purple_contact_set_currentsize(PurpleContact *contact, int value)
 {
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+	priv->currentsize = value;
+}
 
-	g_return_if_fail(contact);
+void
+purple_contact_buddy_status_update(PurpleContact *contact, PurpleStatus *status, PurpleStatus *old_status)
+{
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
 	if (purple_status_is_online(status) &&
 		!purple_status_is_online(old_status)) {
 
-		if (++(contact->online) == 1)
+		if (++(priv->online) == 1)
 			PURPLE_GROUP(contact->node.parent)->online++;
 	} else if (!purple_status_is_online(status) &&
 				purple_status_is_online(old_status)) {
 
-		if (--(contact->online) == 0)
+		if (--(priv->online) == 0)
 			PURPLE_GROUP(contact->node.parent)->online--;
 	}
 }
@@ -253,10 +306,12 @@ const char *purple_contact_get_alias(Pur
 
 const char *purple_contact_get_alias(PurpleContact* contact)
 {
-	g_return_val_if_fail(contact != NULL, NULL);
+	PurpleContactPrivate *priv;
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
-	if (contact->alias)
-		return contact->alias;
+	if (priv->alias)
+		return priv->alias;
 
 	return purple_buddy_get_alias(purple_contact_get_priority_buddy(contact));
 }
@@ -301,31 +356,37 @@ void purple_contact_invalidate_priority_
 
 void purple_contact_invalidate_priority_buddy(PurpleContact *contact)
 {
-	g_return_if_fail(contact != NULL);
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(contact));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
-	contact->priority_valid = FALSE;
+	priv->priority_valid = FALSE;
 }
 
 PurpleBuddy *purple_contact_get_priority_buddy(PurpleContact *contact)
 {
-	g_return_val_if_fail(contact != NULL, NULL);
+	PurpleContactPrivate *priv;
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
-	if (!contact->priority_valid)
+	if (!priv->priority_valid)
 		purple_contact_compute_priority_buddy(contact);
 
-	return contact->priority;
+	return priv->priority;
 }
 
 static void
 purple_contact_child_updated(PurpleContact *contact, PurpleBuddy *child)
 {
+	PurpleContactPrivate *priv;
 	g_return_if_fail(PURPLE_IS_CONTACT(contact));
 	g_return_if_fail(PURPLE_IS_BUDDY(child));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
 	if(purple_blist_node_is_online(PURPLE_BLIST_NODE(child))){
-		contact->online++;
+		priv->online++;
 	} else {
-		contact->online--;
+		priv->online--;
 	}
 }
 
@@ -343,6 +404,7 @@ purple_contact_add_helper(PurpleContact 
 	);
 
 	purple_contact_child_updated(contact, buddy);
+	/* Need to fire a signal for the containing group can do whatever */
 }
 
 static void
@@ -352,8 +414,6 @@ purple_contact_add_buddy_child(PurpleBli
 	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
@@ -367,7 +427,6 @@ purple_contact_add_buddy_sibling(PurpleB
 	contact = PURPLE_CONTACT(purple_blist_node_parent(location));
 
 	purple_contact_add_helper(contact, PURPLE_BUDDY(child));
-	parent_class->add_sibling(child, location);
 }
 
 static gboolean
@@ -383,14 +442,16 @@ purple_contact_remove_buddy(PurpleBlistN
 	PurpleContact *contact;
 	PurpleBuddy *buddy = PURPLE_BUDDY(child);
 	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
-	g_return_if_fail(purple_blist_node_parent(child));
+	PurpleContactPrivate *priv;
+	g_return_if_fail(PURPLE_IS_CONTACT(purple_blist_node_parent(child)));
 	contact = PURPLE_CONTACT(purple_blist_node_parent(child));
+	priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
 	if (PURPLE_BUDDY_IS_ONLINE(buddy))
-		contact->online--;
+		priv->online--;
 	if (purple_account_is_connected(purple_buddy_get_account(buddy)))
-		contact->currentsize--;
-	contact->totalsize--;
+		priv->currentsize--;
+	priv->totalsize--;
 
 	/* emit a node-updated signal here */
 
@@ -398,7 +459,7 @@ purple_contact_remove_buddy(PurpleBlistN
 
 #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) {
+	if (purple_blist_node_first_child(PURPLE_BLIST_NODE(contact)) && priv->priority == buddy) {
 		purple_contact_invalidate_priority_buddy(contact);
 		if (ops && ops->update)
 			ops->update(PURPLE_BLIST_NODE(contact));
@@ -413,10 +474,10 @@ purple_contact_finalize(GObject *object)
 static void
 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);
+	PurpleContactPrivate *priv = PURPLE_CONTACT_GET_PRIVATE(object);
+	g_free(priv->alias);
+	purple_signals_disconnect_by_handle(object);
+	PURPLE_DBUS_UNREGISTER_POINTER(object);
 	G_OBJECT_CLASS(parent_class)->finalize(object);
 }
 
@@ -431,6 +492,8 @@ purple_contact_class_init(PurpleContactC
 	parent_class->remove = purple_contact_remove_buddy;
 	parent_class->is_online = purple_contact_is_online;
 
+	g_type_class_add_private(klass, sizeof(PurpleContactPrivate));
+
 	obj_class->finalize = purple_contact_finalize;
 }
 
@@ -439,10 +502,11 @@ purple_contact_init(GTypeInstance *insta
 {
 	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
 	PurpleContact *contact = PURPLE_CONTACT(instance);
+	PurpleContactPrivate *priv = contact->priv = PURPLE_CONTACT_GET_PRIVATE(contact);
 
-	contact->totalsize = 0;
-	contact->currentsize = 0;
-	contact->online = 0;
+	priv->totalsize = 0;
+	priv->currentsize = 0;
+	priv->online = 0;
 
 	if (ops && ops->new_node)
 		ops->new_node(PURPLE_BLIST_NODE(contact));
============================================================
--- libpurple/contact.h	50e38be12ebf581548a180a68044a1272db0e8c9
+++ libpurple/contact.h	7812075adf491445519b8765faf797b23967815f
@@ -49,12 +49,7 @@ struct _PurpleContact {
  */
 struct _PurpleContact {
 	PurpleBlistNode node;		/**< The node that this contact inherits from. */
-	char *alias;            /**< The user-set alias of the contact */
-	int totalsize;		    /**< The number of buddies in this contact */
-	int currentsize;	    /**< The number of buddies in this contact corresponding to online accounts */
-	int online;			    /**< The number of buddies in this contact who are currently online */
-	PurpleBuddy *priority;    /**< The "top" buddy for this contact */
-	gboolean priority_valid; /**< Is priority valid? */
+	PurpleContactPrivate *priv;
 };
 
 struct _PurpleContactClass {
@@ -144,6 +139,12 @@ PurpleContact *purple_buddy_get_contact(
  */
 PurpleContact *purple_buddy_get_contact(PurpleBuddy *buddy);
 
+/* Not sure if these will stick around, so not bothering with
+ * docs just yet 
+ */
+int purple_contact_get_totalsize(PurpleContact *contact);
+void purple_contact_set_totalsize(PurpleContact *contact, int value);
+
 /**
  * Returns the number of online buddies for this contact.
  *
@@ -169,6 +170,9 @@ void purple_contact_buddy_status_update(
  */
 void purple_contact_buddy_status_update(PurpleContact *contact, PurpleStatus *status, PurpleStatus *old_status);
 
+/* See comments for totalsize accessors */
+void purple_contact_set_currentsize(PurpleContact *contact, int value);
+
 /**
  * Returns the number of buddies that correspond to online accounts
  *


More information about the Commits mailing list