libpurple/protocols/jabber/roster.c

branch
soc.2013.gobjectification.plugins
changeset 37143
728319cb659f
parent 37101
8ba9a23354ff
parent 35961
87fd9126902a
child 37144
8b63b9948107
--- a/libpurple/protocols/jabber/roster.c	Tue Apr 29 04:05:13 2014 +0530
+++ b/libpurple/protocols/jabber/roster.c	Sun May 04 06:28:56 2014 +0530
@@ -113,9 +113,9 @@
 	buddies = purple_blist_find_buddies(purple_connection_get_account(js->gc), jid);
 
 	if(!groups) {
-		if(!buddies)
-			groups = g_slist_append(groups, g_strdup(_("Buddies")));
-		else {
+		if(!buddies) {
+			groups = g_slist_append(groups, JABBER_ROSTER_DEFAULT_GROUP);
+		} else {
 			/* TODO: What should we do here? Removing the local buddies
 			 * is wrong, but so is letting the group state get out of sync with
 			 * the server.
@@ -137,7 +137,19 @@
 		 * to the server, the buddy will be dropped from one of the groups.
 		 * Not optimal, but better than the alternative, I think.
 		 */
-		if((l = g_slist_find_custom(groups, purple_group_get_name(g), (GCompareFunc)purple_utf8_strcasecmp))) {
+		l = g_slist_find_custom(groups, purple_group_get_name(g),
+			(GCompareFunc)purple_utf8_strcasecmp);
+		if (!l && g == purple_blist_get_default_group()) {
+			l = g_slist_find_custom(groups, JABBER_ROSTER_DEFAULT_GROUP,
+				(GCompareFunc)purple_utf8_strcasecmp);
+		}
+		if (!l && g == purple_blist_get_default_group()) {
+			l = g_slist_find_custom(groups,
+				_purple_blist_get_localized_default_group_name(),
+				(GCompareFunc)purple_utf8_strcasecmp);
+		}
+
+		if (l) {
 			/* The buddy is already on the local list. Update info. */
 			const char *servernick, *balias;
 
@@ -153,10 +165,10 @@
 			groups = g_slist_delete_link(groups, l);
 		} else {
 			/* This buddy isn't in the group on the server anymore */
-			purple_debug_info("jabber", "jabber_roster_parse(): Removing %s "
-			                  "from group '%s' on the local list\n",
-			                  purple_buddy_get_name(b),
-			                  purple_group_get_name(g));
+			purple_debug_info("jabber", "jabber_roster_parse(): "
+				"Removing %s from group '%s' on the local list",
+				purple_buddy_get_name(b),
+				jabber_roster_group_get_global_name(g));
 			purple_blist_remove_buddy(b);
 		}
 	}
@@ -253,7 +265,7 @@
 
 				if (group_name == NULL || *group_name == '\0')
 					/* Changing this string?  Look in add_purple_buddy_to_groups */
-					group_name = g_strdup(_("Buddies"));
+					group_name = g_strdup(JABBER_ROSTER_DEFAULT_GROUP);
 
 				/*
 				 * See the note in add_purple_buddy_to_groups; the core handles
@@ -322,7 +334,8 @@
 		while(buddies) {
 			b = buddies->data;
 			g = purple_buddy_get_group(b);
-			groups = g_slist_append(groups, (char *)purple_group_get_name(g));
+			groups = g_slist_append(groups,
+				(char *)jabber_roster_group_get_global_name(g));
 			buddies = g_slist_remove(buddies, b);
 		}
 
@@ -450,7 +463,7 @@
 	while(buddies) {
 		b = buddies->data;
 		g = purple_buddy_get_group(b);
-		gname = purple_group_get_name(g);
+		gname = jabber_roster_group_get_global_name(g);
 		if(!strcmp(gname, old_group))
 			groups = g_slist_append(groups, (char*)new_group); /* ick */
 		else
@@ -468,7 +481,7 @@
 		PurpleGroup *group, GList *moved_buddies)
 {
 	GList *l;
-	const char *gname = purple_group_get_name(group);
+	const char *gname = jabber_roster_group_get_global_name(group);
 	for(l = moved_buddies; l; l = l->next) {
 		PurpleBuddy *buddy = l->data;
 		jabber_roster_group_change(gc, purple_buddy_get_name(buddy), old_name, gname);
@@ -489,12 +502,14 @@
 		while(buddies) {
 			tmpbuddy = buddies->data;
 			tmpgroup = purple_buddy_get_group(tmpbuddy);
-			groups = g_slist_append(groups, (char *)purple_group_get_name(tmpgroup));
+			groups = g_slist_append(groups,
+				(char *)jabber_roster_group_get_global_name(tmpgroup));
 			buddies = g_slist_remove(buddies, tmpbuddy);
 		}
 
-		purple_debug_info("jabber", "jabber_roster_remove_buddy(): Removing %s from %s\n",
-		                  purple_buddy_get_name(buddy), purple_group_get_name(group));
+		purple_debug_info("jabber", "jabber_roster_remove_buddy(): "
+			"Removing %s from %s", purple_buddy_get_name(buddy),
+			jabber_roster_group_get_global_name(group));
 
 		jabber_roster_update(purple_connection_get_protocol_data(gc), name, groups);
 	} else {
@@ -512,3 +527,21 @@
 		jabber_iq_send(iq);
 	}
 }
+
+const gchar *
+jabber_roster_group_get_global_name(PurpleGroup *group)
+{
+	const gchar *name = NULL;
+
+	if (group)
+		name = purple_group_get_name(group);
+
+	if (name == NULL)
+		name = JABBER_ROSTER_DEFAULT_GROUP;
+	else if (g_strcmp0(name, PURPLE_BLIST_DEFAULT_GROUP_NAME) == 0)
+		name = JABBER_ROSTER_DEFAULT_GROUP;
+	else if (g_strcmp0(name, _purple_blist_get_localized_default_group_name()) == 0)
+		name = JABBER_ROSTER_DEFAULT_GROUP;
+
+	return name;
+}

mercurial