changeset 30834:a6511abec788

A couple of refactorings related to oscar_utf8_try_convert().
author ivan.komarov@soc.pidgin.im
date Thu, 05 Aug 2010 23:43:24 +0000
parents 11c54d781835
children d48ae82c58ac
files libpurple/protocols/oscar/encoding.c libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/userinfo.c
diffstat 3 files changed, 29 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/encoding.c	Thu Aug 05 22:57:01 2010 +0000
+++ b/libpurple/protocols/oscar/encoding.c	Thu Aug 05 23:43:24 2010 +0000
@@ -92,6 +92,12 @@
 	const char *charset = NULL;
 	char *ret = NULL;
 
+	if (msg == NULL)
+		return NULL;
+
+	if (g_utf8_validate(msg, -1, NULL))
+		return g_strdup(msg);
+
 	if (od->icq)
 		charset = purple_account_get_string(account, "encoding", NULL);
 
--- a/libpurple/protocols/oscar/oscar.c	Thu Aug 05 22:57:01 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Thu Aug 05 23:43:24 2010 +0000
@@ -3883,13 +3883,7 @@
 
 					groupitem = aim_ssi_itemlist_find(od->ssi.local, curitem->gid, 0x0000);
 					gname = groupitem ? groupitem->name : NULL;
-					if (gname != NULL) {
-						if (g_utf8_validate(gname, -1, NULL))
-							gname_utf8 = g_strdup(gname);
-						else
-							gname_utf8 = oscar_utf8_try_convert(account, od, gname);
-					} else
-						gname_utf8 = NULL;
+					gname_utf8 = oscar_utf8_try_convert(account, od, gname);
 
 					g = purple_find_group(gname_utf8 ? gname_utf8 : _("Orphans"));
 					if (g == NULL) {
@@ -3898,14 +3892,7 @@
 					}
 
 					alias = aim_ssi_getalias(od->ssi.local, gname, curitem->name);
-					if (alias != NULL) {
-						if (g_utf8_validate(alias, -1, NULL))
-							alias_utf8 = g_strdup(alias);
-						else
-							alias_utf8 = oscar_utf8_try_convert(account, od, alias);
-						g_free(alias);
-					} else
-						alias_utf8 = NULL;
+					alias_utf8 = oscar_utf8_try_convert(account, od, alias);
 
 					b = purple_find_buddy_in_group(account, curitem->name, g);
 					if (b) {
@@ -3947,13 +3934,7 @@
 				char *gname_utf8;
 
 				gname = curitem->name;
-				if (gname != NULL) {
-					if (g_utf8_validate(gname, -1, NULL))
-						gname_utf8 = g_strdup(gname);
-					else
-						gname_utf8 = oscar_utf8_try_convert(account, od, gname);
-				} else
-					gname_utf8 = NULL;
+				gname_utf8 = oscar_utf8_try_convert(account, od, gname);
 
 				if (gname_utf8 != NULL && purple_find_group(gname_utf8) == NULL) {
 					g = purple_group_new(gname_utf8);
@@ -4126,15 +4107,7 @@
 	gname_utf8 = gname ? oscar_utf8_try_convert(account, od, gname) : NULL;
 
 	alias = aim_ssi_getalias(od->ssi.local, gname, name);
-	if (alias != NULL)
-	{
-		if (g_utf8_validate(alias, -1, NULL))
-			alias_utf8 = g_strdup(alias);
-		else
-			alias_utf8 = oscar_utf8_try_convert(account, od, alias);
-	}
-	else
-		alias_utf8 = NULL;
+	alias_utf8 = oscar_utf8_try_convert(account, od, alias);
 	g_free(alias);
 
 	b = purple_find_buddy(account, name);
--- a/libpurple/protocols/oscar/userinfo.c	Thu Aug 05 22:57:01 2010 +0000
+++ b/libpurple/protocols/oscar/userinfo.c	Thu Aug 05 23:43:24 2010 +0000
@@ -140,7 +140,7 @@
 
 static void
 oscar_user_info_convert_and_add(PurpleAccount *account, OscarData *od, PurpleNotifyUserInfo *user_info,
-								const char *name, const char *value)
+					const char *name, const char *value)
 {
 	gchar *utf8;
 
@@ -150,6 +150,20 @@
 	}
 }
 
+static void
+oscar_user_info_convert_and_add_hyperlink(PurpleAccount *account, OscarData *od, PurpleNotifyUserInfo *user_info,
+						const char *name, const char *value, const char *url_prefix)
+{
+	gchar *utf8;
+
+	if (value && value[0] && (utf8 = oscar_utf8_try_convert(account, od, value))) {
+		gchar *tmp = g_strdup_printf("<a href=\"%s%s\">%s</a>", url_prefix, utf8, utf8);
+		purple_notify_user_info_add_pair(user_info, name, tmp);
+		g_free(utf8);
+		g_free(tmp);
+	}
+}
+
 /**
  * @brief Append the status information to a user_info struct
  *
@@ -381,8 +395,6 @@
 	struct buddyinfo *bi;
 	gchar who[16];
 	PurpleNotifyUserInfo *user_info;
-	gchar *utf8;
-	gchar *buf;
 	const gchar *alias;
 
 	if (!info->uin)
@@ -410,21 +422,11 @@
 	}
 	oscar_user_info_convert_and_add(account, od, user_info, _("First Name"), info->first);
 	oscar_user_info_convert_and_add(account, od, user_info, _("Last Name"), info->last);
-	if (info->email && info->email[0] && (utf8 = oscar_utf8_try_convert(account, od, info->email))) {
-		buf = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", utf8, utf8);
-		purple_notify_user_info_add_pair(user_info, _("Email Address"), buf);
-		g_free(buf);
-		g_free(utf8);
-	}
+	oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Email Address"), info->email, "mailto:");
 	if (info->numaddresses && info->email2) {
 		int i;
 		for (i = 0; i < info->numaddresses; i++) {
-			if (info->email2[i] && info->email2[i][0] && (utf8 = oscar_utf8_try_convert(account, od, info->email2[i]))) {
-				buf = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", utf8, utf8);
-				purple_notify_user_info_add_pair(user_info, _("Email Address"), buf);
-				g_free(buf);
-				g_free(utf8);
-			}
+			oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Email Address"), info->email2[i], "mailto:");
 		}
 	}
 	oscar_user_info_convert_and_add(account, od, user_info, _("Mobile Phone"), info->mobile);
@@ -454,13 +456,7 @@
 		snprintf(age, sizeof(age), "%hhd", info->age);
 		purple_notify_user_info_add_pair(user_info, _("Age"), age);
 	}
-	if (info->personalwebpage && info->personalwebpage[0] && (utf8 = oscar_utf8_try_convert(account, od, info->personalwebpage))) {
-		buf = g_strdup_printf("<a href=\"%s\">%s</a>", utf8, utf8);
-		purple_notify_user_info_add_pair(user_info, _("Personal Web Page"), buf);
-		g_free(buf);
-		g_free(utf8);
-	}
-
+	oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Personal Web Page"), info->email, "");
 	if (buddy != NULL)
 		oscar_user_info_append_status(gc, user_info, buddy, /* aim_userinfo_t */ NULL, /* strip_html_tags */ FALSE);
 
@@ -489,13 +485,7 @@
 		oscar_user_info_convert_and_add(account, od, user_info, _("Company"), info->workcompany);
 		oscar_user_info_convert_and_add(account, od, user_info, _("Division"), info->workdivision);
 		oscar_user_info_convert_and_add(account, od, user_info, _("Position"), info->workposition);
-
-		if (info->workwebpage && info->workwebpage[0] && (utf8 = oscar_utf8_try_convert(account, od, info->workwebpage))) {
-			char *webpage = g_strdup_printf("<a href=\"%s\">%s</a>", utf8, utf8);
-			purple_notify_user_info_add_pair(user_info, _("Web Page"), webpage);
-			g_free(webpage);
-			g_free(utf8);
-		}
+		oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Web Page"), info->email, "");
 	}
 
 	if (buddy != NULL)