/soc/2013/ankitkv/gobjectification: 7f5a2fc8ef9c: Refactored bli...

Ankit Vani a at nevitus.org
Tue Jul 9 06:48:34 EDT 2013


Changeset: 7f5a2fc8ef9cd485de09b90691ca7a361ac8892a
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-09 16:18 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/7f5a2fc8ef9c

Description:

Refactored blistnodetypes and BuddyList.xs according to API changes

diffstat:

 libpurple/blistnodetypes.c                 |   27 ++---
 libpurple/blistnodetypes.h                 |    2 +-
 libpurple/buddylist.c                      |   14 ++-
 libpurple/buddylist.h                      |   12 ++-
 libpurple/plugins/perl/common/BuddyList.xs |  126 +++++++++++++---------------
 5 files changed, 96 insertions(+), 85 deletions(-)

diffs (truncated from 355 to 300 lines):

diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -22,6 +22,7 @@
  */
 #include "internal.h"
 #include "dbus-maybe.h"
+#include "debug.h"
 
 #define PURPLE_BUDDY_GET_PRIVATE(obj) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_BUDDY, PurpleBuddyPrivate))
@@ -136,6 +137,8 @@ purple_strings_are_different(const char 
 			((one == NULL || *one == '\0') && (two == NULL || *two == '\0')));
 }
 
+PurpleBListNode *purple_blist_get_last_child(PurpleBListNode *node);
+
 /**************************************************************************/
 /* Buddy API                                                              */
 /**************************************************************************/
@@ -155,7 +158,7 @@ purple_buddy_set_icon(PurpleBuddy *buddy
 
 	purple_signal_emit(purple_blist_get_handle(), "buddy-icon-changed", buddy);
 
-	purple_blist_update_node(PURPLE_BLIST_NODE(buddy));
+	purple_blist_node_update(PURPLE_BLIST_NODE(buddy));
 }
 
 PurpleBuddyIcon *
@@ -182,10 +185,11 @@ void
 purple_buddy_set_name(PurpleBuddy *buddy, const char *name)
 {
 	PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+	PurpleBListUiOps *ops = purple_blist_get_ui_ops();
 
 	g_return_if_fail(priv != NULL);
 
-	purple_blist_update_cache(buddy, name);
+	purple_blist_update_buddies_cache(buddy, name);
 
 	g_free(priv->name);
 	priv->name = purple_utf8_strip_unprintables(name);
@@ -301,17 +305,17 @@ purple_buddy_set_local_alias(PurpleBuddy
 	if ((alias != NULL) && (*alias != '\0'))
 		new_alias = purple_utf8_strip_unprintables(alias);
 
-	if (!purple_strings_are_different(priv->alias, new_alias)) {
+	if (!purple_strings_are_different(priv->local_alias, new_alias)) {
 		g_free(new_alias);
 		return;
 	}
 
-	old_alias = priv->alias;
+	old_alias = priv->local_alias;
 
 	if ((new_alias != NULL) && (*new_alias != '\0'))
-		priv->alias = new_alias;
+		priv->local_alias = new_alias;
 	else {
-		priv->alias = NULL;
+		priv->local_alias = NULL;
 		g_free(new_alias); /* could be "\0" */
 	}
 
@@ -413,7 +417,6 @@ PurplePresence *purple_buddy_get_presenc
 void
 purple_buddy_update_status(PurpleBuddy *buddy, PurpleStatus *old_status)
 {
-	PurpleBListUiOps *ops = purple_blist_get_ui_ops();
 	PurpleStatus *status;
 	PurpleBListNode *cnode;
 	PurpleContact *contact;
@@ -1450,7 +1453,6 @@ void purple_group_set_name(PurpleGroup *
 	} else {
 		/* A simple rename */
 		PurpleBListNode *cnode, *bnode;
-		gchar* key;
 
 		/* Build a GList of all buddies in this group */
 		for (cnode = PURPLE_BLIST_NODE(source)->child; cnode != NULL; cnode = cnode->next) {
@@ -1459,15 +1461,10 @@ void purple_group_set_name(PurpleGroup *
 					moved_buddies = g_list_append(moved_buddies, bnode);
 		}
 
+		purple_blist_update_groups_cache(source, new_name);
+
 		old_name = priv->name;
 		priv->name = new_name;
-
-		key = g_utf8_collate_key(old_name, -1);
-		g_hash_table_remove(groups_cache, key);
-		g_free(key);
-
-		key = g_utf8_collate_key(new_name, -1);
-		g_hash_table_insert(groups_cache, key, source);
 	}
 
 	/* Save our changes */
diff --git a/libpurple/blistnodetypes.h b/libpurple/blistnodetypes.h
--- a/libpurple/blistnodetypes.h
+++ b/libpurple/blistnodetypes.h
@@ -357,7 +357,7 @@ const char *purple_buddy_get_contact_ali
 
 /**
  * Returns the correct name to display for a buddy. In order of precedence:
- * the buddy's alias; the buddy's server alias; the buddy's contact alias;
+ * the buddy's local alias; the buddy's server alias; the buddy's contact alias;
  * the buddy's user name.
  *
  * @param buddy   The buddy whose alias will be returned.
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -69,7 +69,7 @@ static PurpleBListNode *purple_blist_get
 	return n;
 }
 
-static PurpleBListNode *purple_blist_get_last_child(PurpleBListNode *node)
+PurpleBListNode *purple_blist_get_last_child(PurpleBListNode *node)
 {
 	if (!node)
 		return NULL;
@@ -767,7 +767,7 @@ void purple_blist_set_visible(gboolean s
 		ops->set_visible(purplebuddylist, show);
 }
 
-void purple_blist_update_cache(PurpleBuddy *buddy, const char *new_name)
+void purple_blist_update_buddies_cache(PurpleBuddy *buddy, const char *new_name)
 {
 	struct _purple_hbuddy *hb, *hb2;
 	GHashTable *account_buddies;
@@ -799,6 +799,16 @@ void purple_blist_update_cache(PurpleBud
 	g_hash_table_replace(account_buddies, hb2, buddy);
 }
 
+void purple_blist_update_groups_cache(PurpleGroup *group, const char *new_name)
+{
+		gchar* key = g_utf8_collate_key(purple_group_get_name(group), -1);
+		g_hash_table_remove(groups_cache, key);
+		g_free(key);
+
+		key = g_utf8_collate_key(new_name, -1);
+		g_hash_table_insert(groups_cache, key, group);
+}
+
 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBListNode *node)
 {
 	PurpleBListNode *cnode = PURPLE_BLIST_NODE(chat);
diff --git a/libpurple/buddylist.h b/libpurple/buddylist.h
--- a/libpurple/buddylist.h
+++ b/libpurple/buddylist.h
@@ -188,7 +188,17 @@ void purple_blist_set_visible(gboolean s
  * @param buddy  The buddy whose name will be changed.
  * @param name   The new name of the buddy.
  */
-void purple_blist_update_cache(PurpleBuddy *buddy, const char *new_name);
+void purple_blist_update_buddies_cache(PurpleBuddy *buddy, const char *new_name);
+
+/**
+ * Updates the groups hash table when a group has been renamed. This only
+ * updates the cache, the caller is responsible for the actual renaming of
+ * the group after updating the cache.
+ *
+ * @param group  The group whose name will be changed.
+ * @param name   The new name of the group.
+ */
+void purple_blist_update_groups_cache(PurpleGroup *group, const char *new_name);
 
 /**
  * Adds a new chat to the buddy list.
diff --git a/libpurple/plugins/perl/common/BuddyList.xs b/libpurple/plugins/perl/common/BuddyList.xs
--- a/libpurple/plugins/perl/common/BuddyList.xs
+++ b/libpurple/plugins/perl/common/BuddyList.xs
@@ -10,37 +10,6 @@ chat_components_foreach(gpointer key, gp
 		purple_debug_error("perl", "hv_store failed\n");
 }
 
-MODULE = Purple::BuddyList  PACKAGE = Purple  PREFIX = purple_
-PROTOTYPES: ENABLE
-
-Purple::BuddyList
-purple_blist_get_buddy_list()
-
-MODULE = Purple::BuddyList  PACKAGE = Purple::Find  PREFIX = purple_find_
-PROTOTYPES: ENABLE
-
-Purple::BuddyList::Buddy
-purple_blist_find_buddy(account, name)
-	Purple::Account account
-	const char * name
-
-void
-purple_blist_find_buddies(account, name)
-	Purple::Account account
-	const char * name
-PREINIT:
-	GSList *l, *ll;
-PPCODE:
-	ll = purple_blist_find_buddies(account, name);
-	for (l = ll; l != NULL; l = l->next) {
-		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::BuddyList::Buddy")));
-	}
-	g_slist_free(ll);
-
-Purple::BuddyList::Group
-purple_blist_find_group(name)
-	const char *name
-
 MODULE = Purple::BuddyList  PACKAGE = Purple::Find  PREFIX = purple_
 PROTOTYPES: ENABLE
 
@@ -72,6 +41,11 @@ void
 purple_contact_invalidate_priority_buddy(contact)
 	Purple::BuddyList::Contact contact
 
+void
+purple_contact_merge(source, node)
+	Purple::BuddyList::Contact source
+	Purple::BuddyList::Node node
+
 MODULE = Purple::BuddyList  PACKAGE = Purple::BuddyList::Group  PREFIX = purple_group_
 PROTOTYPES: ENABLE
 
@@ -96,6 +70,11 @@ purple_group_on_account(group, account)
 	Purple::BuddyList::Group  group
 	Purple::Account account
 
+void
+purple_group_set_name(group, name)
+	Purple::BuddyList::Group  group
+	const char * name
+
 const char *
 purple_group_get_name(group)
 	Purple::BuddyList::Group group
@@ -103,6 +82,31 @@ purple_group_get_name(group)
 MODULE = Purple::BuddyList  PACKAGE = Purple::BuddyList  PREFIX = purple_blist_
 PROTOTYPES: ENABLE
 
+Purple::BuddyList
+purple_blist_get_buddy_list()
+
+Purple::BuddyList::Buddy
+purple_blist_find_buddy(account, name)
+	Purple::Account account
+	const char * name
+
+void
+purple_blist_find_buddies(account, name)
+	Purple::Account account
+	const char * name
+PREINIT:
+	GSList *l, *ll;
+PPCODE:
+	ll = purple_blist_find_buddies(account, name);
+	for (l = ll; l != NULL; l = l->next) {
+		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::BuddyList::Buddy")));
+	}
+	g_slist_free(ll);
+
+Purple::BuddyList::Group
+purple_blist_find_group(name)
+	const char *name
+
 void
 purple_blist_add_contact(contact, group, node)
 	Purple::BuddyList::Contact contact
@@ -110,11 +114,6 @@ purple_blist_add_contact(contact, group,
 	Purple::BuddyList::Node node
 
 void
-purple_contact_merge(source, node)
-	Purple::BuddyList::Contact source
-	Purple::BuddyList::Node node
-
-void
 purple_blist_add_group(group, node)
 	Purple::BuddyList::Group  group
 	Purple::BuddyList::Node node
@@ -161,36 +160,6 @@ purple_blist_set_visible(show)
 	gboolean show
 
 void
-purple_buddy_update_status(buddy, old_status)
-	Purple::BuddyList::Buddy buddy
-	Purple::Status old_status
-
-void
-purple_buddy_set_name(buddy, name)
-	Purple::BuddyList::Buddy buddy
-	const char * name
-
-void
-purple_buddy_set_local_alias(buddy, alias)
-	Purple::BuddyList::Buddy buddy
-	const char * alias
-
-void
-purple_buddy_set_server_alias(buddy, alias)
-	Purple::BuddyList::Buddy buddy



More information about the Commits mailing list