/pidgin/main: 1d8446f396b6: blist: define default group better

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Apr 30 12:41:03 EDT 2014


Changeset: 1d8446f396b6aa2197018893539f2f071d8160a8
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-30 18:40 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/1d8446f396b6

Description:

blist: define default group better

diffstat:

 libpurple/blistnodetypes.c                 |   8 ++++--
 libpurple/buddylist.c                      |  35 ++++++++++++++++++-----------
 libpurple/buddylist.h                      |   6 ++++-
 libpurple/protocols/gg/purplew.c           |   7 +++++-
 libpurple/protocols/gg/purplew.h           |   2 -
 libpurple/protocols/gg/roster.c            |   6 ++--
 libpurple/protocols/jabber/roster.c        |   9 ++++---
 libpurple/protocols/oscar/family_feedbag.c |   3 +-
 libpurple/protocols/oscar/oscar.c          |  12 +++++-----
 libpurple/protocols/simple/simple.c        |   7 +----
 libpurple/protocols/yahoo/libymsg.c        |   6 +----
 pidgin/gtkblist.c                          |   3 +-
 pidgin/plugins/gevolution/gevo-util.c      |  10 +++-----
 pidgin/plugins/gevolution/gevolution.c     |   3 +-
 14 files changed, 65 insertions(+), 52 deletions(-)

diffs (truncated from 331 to 300 lines):

diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -531,7 +531,7 @@ PurpleGroup *purple_buddy_get_group(Purp
 	g_return_val_if_fail(PURPLE_IS_BUDDY(buddy), NULL);
 
 	if (PURPLE_BLIST_NODE(buddy)->parent == NULL)
-		return NULL;
+		return purple_blist_get_default_group();
 
 	return PURPLE_GROUP(PURPLE_BLIST_NODE(buddy)->parent->parent);
 }
@@ -1723,8 +1723,10 @@ purple_group_new(const char *name)
 {
 	PurpleGroup *group;
 
-	g_return_val_if_fail(name  != NULL, NULL);
-	g_return_val_if_fail(*name != '\0', NULL);
+	if (name == NULL || name[0] == '\0')
+		name = PURPLE_BLIST_DEFAULT_GROUP_NAME;
+	if (g_strcmp0(name, "Buddies") == 0)
+		name = PURPLE_BLIST_DEFAULT_GROUP_NAME;
 
 	group = purple_blist_find_group(name);
 	if (group != NULL)
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -584,9 +584,6 @@ parse_group(PurpleXmlNode *groupnode)
 	PurpleGroup *group;
 	PurpleXmlNode *cnode;
 
-	if (!name)
-		name = _("Buddies");
-
 	group = purple_group_new(name);
 	purple_blist_add_group(group,
 			purple_blist_get_last_sibling(purplebuddylist->root));
@@ -930,7 +927,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 	} else {
 		g = group;
 		if (g == NULL)
-			g = purple_group_new(_("Buddies"));
+			g = purple_blist_get_default_group();
 		/* Add group to blist if isn't already on it. Fixes #2752. */
 		if (!purple_blist_find_group(purple_group_get_name(g))) {
 			purple_blist_add_group(g,
@@ -1074,14 +1071,8 @@ void purple_blist_add_contact(PurpleCont
 		g = PURPLE_GROUP(node->parent);
 	else if (group)
 		g = group;
-	else {
-		g = purple_blist_find_group(_("Buddies"));
-		if (g == NULL) {
-			g = purple_group_new(_("Buddies"));
-			purple_blist_add_group(g,
-					purple_blist_get_last_sibling(purplebuddylist->root));
-		}
-	}
+	else
+		g = purple_blist_get_default_group();
 
 	gnode = (PurpleBlistNode*)g;
 	cnode = (PurpleBlistNode*)contact;
@@ -1600,7 +1591,11 @@ PurpleGroup *purple_blist_find_group(con
 	PurpleGroup *group;
 
 	g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL);
-	g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL);
+
+	if (name == NULL || name[0] == '\0')
+		name = PURPLE_BLIST_DEFAULT_GROUP_NAME;
+	if (g_strcmp0(name, "Buddies") == 0)
+		name = PURPLE_BLIST_DEFAULT_GROUP_NAME;
 
 	key = g_utf8_collate_key(name, -1);
 	group = g_hash_table_lookup(groups_cache, key);
@@ -1609,6 +1604,20 @@ PurpleGroup *purple_blist_find_group(con
 	return group;
 }
 
+PurpleGroup *
+purple_blist_get_default_group(void)
+{
+	PurpleGroup *group;
+
+	group = purple_blist_find_group(PURPLE_BLIST_DEFAULT_GROUP_NAME);
+	if (!group) {
+		group = purple_group_new(PURPLE_BLIST_DEFAULT_GROUP_NAME);
+		purple_blist_add_group(group, NULL);
+	}
+
+	return group;
+}
+
 PurpleChat *
 purple_blist_find_chat(PurpleAccount *account, const char *name)
 {
diff --git a/libpurple/buddylist.h b/libpurple/buddylist.h
--- a/libpurple/buddylist.h
+++ b/libpurple/buddylist.h
@@ -47,6 +47,8 @@ typedef struct _PurpleBuddyListClass  Pu
 
 typedef struct _PurpleBlistUiOps PurpleBlistUiOps;
 
+#define PURPLE_BLIST_DEFAULT_GROUP_NAME _("Buddies")
+
 /**************************************************************************/
 /* Data Structures                                                        */
 /**************************************************************************/
@@ -281,7 +283,7 @@ void purple_blist_add_chat(PurpleChat *c
  *
  * The buddy will be inserted right after node or prepended to the
  * group if node is NULL.  If both are NULL, the buddy will be added to
- * the "Buddies" group.
+ * the default group.
  */
 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
 
@@ -398,6 +400,8 @@ GSList *purple_blist_find_buddies(Purple
  */
 PurpleGroup *purple_blist_find_group(const char *name);
 
+PurpleGroup *purple_blist_get_default_group(void);
+
 /**
  * purple_blist_find_chat:
  * @account: The chat's account.
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
@@ -85,7 +85,12 @@ PurpleGroup * ggp_purplew_buddy_get_grou
 	PurpleGroup *group = purple_buddy_get_group(buddy);
 	if (!group)
 		return NULL;
-	if (0 == strcmp(GGP_PURPLEW_GROUP_DEFAULT, purple_group_get_name(group)))
+	if (0 == g_strcmp0(PURPLE_BLIST_DEFAULT_GROUP_NAME,
+		purple_group_get_name(group)))
+	{
+		return NULL;
+	}
+	if (0 == g_strcmp0("Buddies", purple_group_get_name(group)))
 		return NULL;
 	return group;
 }
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
@@ -33,8 +33,6 @@
 #include <internal.h>
 #include <libgadu.h>
 
-#define GGP_PURPLEW_GROUP_DEFAULT _("Buddies")
-
 /**
  * Adds an input handler in purple event loop for http request.
  *
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
@@ -452,7 +452,7 @@ static gboolean ggp_roster_reply_list_re
 	is_bot = (strcmp(id, GGP_ROSTER_GROUPID_BOTS) == 0 ||
 		g_strcmp0(name, "Pomocnicy") == 0);
 	is_default = (strcmp(id, GGP_ROSTER_GROUPID_DEFAULT) == 0 ||
-		g_strcmp0(name, GGP_PURPLEW_GROUP_DEFAULT) == 0 ||
+		g_strcmp0(name, PURPLE_BLIST_DEFAULT_GROUP_NAME) == 0 ||
 		g_strcmp0(name, "[default]") == 0);
 
 	if (!content->bots_group_id && is_bot)
@@ -913,8 +913,8 @@ static gboolean ggp_roster_send_update_g
 		"\"%s\"->\"%s\"\n", old_name, new_name);
 
 	/* moving to or from default group instead of renaming it */
-	if (0 == g_strcmp0(old_name, GGP_PURPLEW_GROUP_DEFAULT) ||
-		0 == g_strcmp0(new_name, GGP_PURPLEW_GROUP_DEFAULT))
+	if (0 == g_strcmp0(old_name, PURPLE_BLIST_DEFAULT_GROUP_NAME) ||
+		0 == g_strcmp0(new_name, PURPLE_BLIST_DEFAULT_GROUP_NAME))
 	{
 		PurpleGroup *group;
 		GList *group_buddies;
diff --git a/libpurple/protocols/jabber/roster.c b/libpurple/protocols/jabber/roster.c
--- a/libpurple/protocols/jabber/roster.c
+++ b/libpurple/protocols/jabber/roster.c
@@ -113,9 +113,10 @@ static void add_purple_buddy_to_groups(J
 	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,
+				g_strdup(PURPLE_BLIST_DEFAULT_GROUP_NAME));
+		} 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.
@@ -253,7 +254,7 @@ void jabber_roster_parse(JabberStream *j
 
 				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(PURPLE_BLIST_DEFAULT_GROUP_NAME);
 
 				/*
 				 * See the note in add_purple_buddy_to_groups; the core handles
diff --git a/libpurple/protocols/oscar/family_feedbag.c b/libpurple/protocols/oscar/family_feedbag.c
--- a/libpurple/protocols/oscar/family_feedbag.c
+++ b/libpurple/protocols/oscar/family_feedbag.c
@@ -796,7 +796,8 @@ static int aim_ssi_cleanlist(OscarData *
 				aim_ssi_del_from_private_list(od, NULL, cur->type);
 		} else if ((cur->type == AIM_SSI_TYPE_BUDDY) && ((cur->gid == 0x0000) || (!aim_ssi_itemlist_find(&od->ssi.local, cur->gid, 0x0000)))) {
 			char *alias = aim_ssi_getalias(&od->ssi.local, NULL, cur->name);
-			aim_ssi_addbuddy(od, cur->name, _("Buddies"), NULL, alias, NULL, NULL, FALSE);
+			aim_ssi_addbuddy(od, cur->name, PURPLE_BLIST_DEFAULT_GROUP_NAME,
+				NULL, alias, NULL, NULL, FALSE);
 			aim_ssi_delbuddy(od, cur->name, NULL);
 			g_free(alias);
 		}
diff --git a/libpurple/protocols/oscar/oscar.c b/libpurple/protocols/oscar/oscar.c
--- a/libpurple/protocols/oscar/oscar.c
+++ b/libpurple/protocols/oscar/oscar.c
@@ -3823,9 +3823,9 @@ static int purple_ssi_parselist(OscarDat
 					gname = groupitem ? groupitem->name : NULL;
 					gname_utf8 = oscar_utf8_try_convert(account, od, gname);
 
-					g = purple_blist_find_group(gname_utf8 ? gname_utf8 : _("Buddies"));
+					g = purple_blist_find_group(gname_utf8);
 					if (g == NULL) {
-						g = purple_group_new(gname_utf8 ? gname_utf8 : _("Buddies"));
+						g = purple_group_new(gname_utf8);
 						purple_blist_add_group(g, NULL);
 					}
 
@@ -4049,13 +4049,13 @@ purple_ssi_parseaddmod(OscarData *od, Fl
 		 */
 		b = purple_buddy_new(account, name, alias_utf8);
 
-		if (!(g = purple_blist_find_group(gname_utf8 ? gname_utf8 : _("Buddies")))) {
-			g = purple_group_new(gname_utf8 ? gname_utf8 : _("Buddies"));
+		if (!(g = purple_blist_find_group(gname_utf8))) {
+			g = purple_group_new(gname_utf8);
 			purple_blist_add_group(g, NULL);
 		}
 
-		purple_debug_info("oscar",
-				   "ssi: adding buddy %s to group %s to local list\n", name, gname_utf8 ? gname_utf8 : _("Buddies"));
+		purple_debug_info("oscar", "ssi: adding buddy %s to group %s to"
+			" local list", name, gname_utf8 ? gname_utf8 : "(default)");
 		purple_blist_add_buddy(b, NULL, g, NULL);
 
 		/* Mobile users should always be online */
diff --git a/libpurple/protocols/simple/simple.c b/libpurple/protocols/simple/simple.c
--- a/libpurple/protocols/simple/simple.c
+++ b/libpurple/protocols/simple/simple.c
@@ -896,11 +896,8 @@ static gboolean simple_add_lcs_contacts(
 				g = purple_group_new(name_group);
 		}
 
-		if (!g) {
-			g = purple_blist_find_group("Buddies");
-			if(!g)
-				g = purple_group_new("Buddies");
-		}
+		if (!g)
+			g = purple_blist_get_default_group();
 
 		for(item = purple_xmlnode_get_child(isc, "contact"); item; item = purple_xmlnode_get_next_twin(item))
 		{
diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -5019,11 +5019,7 @@ void yahoo_add_buddy(PurpleConnection *g
 	if (fed != YAHOO_FEDERATION_NONE)
 		fed_bname += 4;
 
-	g = purple_buddy_get_group(buddy);
-	if (g)
-		group = purple_group_get_name(g);
-	else
-		group = "Buddies";
+	group = purple_group_get_name(purple_buddy_get_group(buddy));
 
 	group2 = yahoo_string_encode(gc, group, FALSE);
 	pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id);
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -7182,7 +7182,8 @@ groups_tree(void)
 
 	if (purple_blist_get_buddy_list()->root == NULL)
 	{
-		list  = g_list_append(list, (gpointer)_("Buddies"));
+		list  = g_list_append(list,
+			(gpointer)PURPLE_BLIST_DEFAULT_GROUP_NAME);
 	}
 	else
 	{
diff --git a/pidgin/plugins/gevolution/gevo-util.c b/pidgin/plugins/gevolution/gevo-util.c
--- a/pidgin/plugins/gevolution/gevo-util.c



More information about the Commits mailing list