/soc/2012/tomkiewicz/gg: 103df11c3ff8: Gadu-Gadu: roster - defau...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Jul 14 11:50:33 EDT 2012


Changeset: 103df11c3ff84cc9dd6033f374caa166021c0be4
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-07-14 17:50 +0200
Branch:	 soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/103df11c3ff8

Description:

Gadu-Gadu: roster - default group rename

diffstat:

 libpurple/protocols/gg/purplew.c |  29 ++++++++++++++++++++++++++++-
 libpurple/protocols/gg/purplew.h |   4 ++++
 libpurple/protocols/gg/roster.c  |  21 ++++++++++++---------
 3 files changed, 44 insertions(+), 10 deletions(-)

diffs (116 lines):

diff --git a/libpurple/protocols/gg/purplew.c b/libpurple/protocols/gg/purplew.c
--- a/libpurple/protocols/gg/purplew.c
+++ b/libpurple/protocols/gg/purplew.c
@@ -59,7 +59,34 @@
 	PurpleGroup *group = purple_buddy_get_group(buddy);
 	if (!group)
 		return NULL;
-	if (0 == strcmp(_("Buddies"), purple_group_get_name(group)))
+	if (0 == strcmp(GGP_PURPLEW_GROUP_DEFAULT, purple_group_get_name(group)))
 		return NULL;
 	return group;
 }
+
+GList * ggp_purplew_group_get_buddies(PurpleGroup *group, PurpleAccount *account)
+{
+	GList *buddies = NULL;
+	PurpleBlistNode *gnode, *cnode, *bnode;
+	
+	g_return_val_if_fail(group != NULL, NULL);
+	
+	gnode = PURPLE_BLIST_NODE(group);
+	for (cnode = gnode->child; cnode; cnode = cnode->next)
+	{
+		if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
+			continue;
+		for (bnode = cnode->child; bnode; bnode = bnode->next)
+		{
+			PurpleBuddy *buddy;
+			if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
+				continue;
+			
+			buddy = PURPLE_BUDDY(bnode);
+			if (account == NULL || buddy->account == account)
+				buddies = g_list_append(buddies, buddy);
+		}
+	}
+	
+	return buddies;
+}
diff --git a/libpurple/protocols/gg/purplew.h b/libpurple/protocols/gg/purplew.h
--- a/libpurple/protocols/gg/purplew.h
+++ b/libpurple/protocols/gg/purplew.h
@@ -4,6 +4,8 @@
 #include <internal.h>
 #include <libgadu.h>
 
+#define GGP_PURPLEW_GROUP_DEFAULT _("Buddies")
+
 /**
  * Adds an input handler in purple event loop for http request.
  *
@@ -39,4 +41,6 @@
 // ignores default group
 PurpleGroup * ggp_purplew_buddy_get_group_only(PurpleBuddy *buddy);
 
+GList * ggp_purplew_group_get_buddies(PurpleGroup *group, PurpleAccount *account);
+
 #endif /* _GGP_PURPLEW_H */
diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -12,7 +12,6 @@
 #define GGP_ROSTER_GROUPID_DEFAULT "00000000-0000-0000-0000-000000000000"
 
 // TODO: ignored contacts synchronization (?)
-// TODO: rename default group
 
 typedef struct
 {
@@ -343,7 +342,7 @@
 	is_bot = (strcmp(id, "0b345af6-0001-0000-0000-000000000004") == 0 ||
 		g_strcmp0(name, "Pomocnicy") == 0);
 	is_default = (strcmp(id, GGP_ROSTER_GROUPID_DEFAULT) == 0 ||
-		g_strcmp0(name, _("Buddies")) == 0 ||
+		g_strcmp0(name, GGP_PURPLEW_GROUP_DEFAULT) == 0 ||
 		g_strcmp0(name, _("[default]")) == 0);
 	
 	if (!content->bots_group_id && is_bot)
@@ -792,10 +791,10 @@
 
 static gboolean ggp_roster_send_update_group_rename(PurpleConnection *gc, ggp_roster_change *change)
 {
+	PurpleAccount *account = purple_connection_get_account(gc);
 	ggp_roster_content *content = ggp_roster_get_rdata(gc)->content;
 	const char *old_name = change->data.group_rename.old_name;
 	const char *new_name = change->data.group_rename.new_name;
-	//PurpleGroup *group;
 	xmlnode *group_node;
 	const char *group_id;
 
@@ -803,15 +802,19 @@
 	
 	purple_debug_misc("gg", "ggp_roster_send_update_group_rename: old_name=%s, new_name=%s\n", old_name, new_name);
 
-	/*
-	group = purple_find_group(old_name);
-	if (!group)
+	if (0 == g_strcmp0(old_name, GGP_PURPLEW_GROUP_DEFAULT) ||
+		0 == g_strcmp0(new_name, GGP_PURPLEW_GROUP_DEFAULT))
 	{
-		purple_debug_info("gg", "ggp_roster_send_update_group_rename: %s not found\n", old_name);
+		PurpleGroup *group;
+		GList *group_buddies;
+		group = purple_find_group(new_name);
+		if (!group)
+			return TRUE;
+		purple_debug_info("gg", "ggp_roster_send_update_group_rename: invalidating buddies in default group\n");
+		for (group_buddies = ggp_purplew_group_get_buddies(group, account); group_buddies; group_buddies = g_list_remove_link(group_buddies, group_buddies))
+			ggp_roster_set_synchronized(gc, group_buddies->data, FALSE);
 		return TRUE;
 	}
-	*/
-	
 	group_id = g_hash_table_lookup(content->group_ids, old_name);
 	if (!group_id)
 	{



More information about the Commits mailing list