changeset 12970:ec9b92104904

[gaim-migrate @ 15323] Pass the tooltip GString to the prpls. This make the prpl tooltip_text consistent with the drawing-tooltip signal callbacks. It also eliminates a little bit of duplicated code from the prpls. It's also theoretically more efficient, but I'm sure the difference is irrelevant. However, this change will allow me to kill a bunch more duplicated code. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Fri, 20 Jan 2006 20:35:18 +0000
parents b98a28bf29d9
children 7bd4dbf26c00
files src/gtkblist.c src/protocols/bonjour/bonjour.c src/protocols/gg/gg.c src/protocols/jabber/jabber.c src/protocols/msn/msn.c src/protocols/novell/novell.c src/protocols/oscar/oscar.c src/protocols/sametime/sametime.c src/protocols/silc/buddy.c src/protocols/silc/silcgaim.h src/protocols/yahoo/yahoo.c src/protocols/yahoo/yahoo.h src/protocols/yahoo/yahoo_profile.c src/prpl.h
diffstat 14 files changed, 77 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkblist.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/gtkblist.c	Fri Jan 20 20:35:18 2006 +0000
@@ -2698,6 +2698,7 @@
 
 
 		/* Offline? */
+		/* FIXME: Why is this status special-cased by the core? -- rlaager */
 		if (!GAIM_BUDDY_IS_ONLINE(b)) {
 			g_string_append_printf(str, _("\n<b>Status:</b> Offline"));
 		}
@@ -2705,19 +2706,7 @@
 		if (prpl_info && prpl_info->tooltip_text)
 		{
 			/* Additional text from the PRPL */
-			const char *end;
-			tmp = prpl_info->tooltip_text(b, full);
-
-			if (tmp && !g_utf8_validate(tmp, -1, &end))
-			{
-				char *new = g_strndup(tmp, g_utf8_pointer_to_offset(tmp, end));
-				g_free(tmp);
-				tmp = new;
-			}
-
-			if (tmp != NULL)
-				g_string_append(str, tmp);
-			g_free(tmp);
+			prpl_info->tooltip_text(b, str, full);
 		}
 
 		/* These are Easter Eggs.  Patches to remove them will be rejected. */
--- a/src/protocols/bonjour/bonjour.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/bonjour/bonjour.c	Fri Jan 20 20:35:18 2006 +0000
@@ -306,10 +306,9 @@
 	return NULL;
 }
 
-static char *
-bonjour_tooltip_text(GaimBuddy *buddy, gboolean full)
+static void
+bonjour_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full)
 {
-	GString *ret;
 	GaimPresence *presence;
 	GaimStatus *status;
 	const char *status_description;
@@ -326,12 +325,9 @@
 	else
 		status_description = gaim_status_get_name(status);
 
-	ret = g_string_new("");
-	g_string_append_printf(ret, _("\n<b>Status:</b> %s"), status_description);
+	g_string_append_printf(str, _("\n<b>Status:</b> %s"), status_description);
 	if (message != NULL)
-		g_string_append_printf(ret, _("\n<b>Message:</b> %s"), message);
-
-	return g_string_free(ret, FALSE);
+		g_string_append_printf(str, _("\n<b>Message:</b> %s"), message);
 }
 
 static gboolean
--- a/src/protocols/gg/gg.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/gg/gg.c	Fri Jan 20 20:35:18 2006 +0000
@@ -1383,12 +1383,11 @@
 }
 /* }}} */
 
-/* static char *ggp_tooltip_text(GaimBuddy *b, gboolean full) {{{ */
-static char *ggp_tooltip_text(GaimBuddy *b, gboolean full)
+/* static void ggp_tooltip_text(GaimBuddy *b, GString *str, gboolean full) {{{ */
+static void ggp_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
 {
 	GaimStatus *status;
 	char *text;
-	gchar *ret;
 	const char *msg, *name;
 
 	status = gaim_presence_get_active_status(gaim_buddy_get_presence(b));
@@ -1400,16 +1399,14 @@
 		text = g_markup_escape_text(tmp, -1);
 		g_free(tmp);
 
-		ret = g_strdup_printf("\n<b>%s:</b> %s: %s",
-				      _("Status"), name, text);
+		g_string_append_printf(str, "\n<b>%s:</b> %s: %s",
+				       _("Status"), name, text);
 
 		g_free(text);
 	} else {
-		ret = g_strdup_printf("\n<b>%s:</b> %s",
-				      _("Status"), name);
+		g_string_append_printf(str, "\n<b>%s:</b> %s",
+				       _("Status"), name);
 	}
-
-	return ret;
 }
 /* }}} */
 
--- a/src/protocols/jabber/jabber.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/jabber/jabber.c	Fri Jan 20 20:35:18 2006 +0000
@@ -1001,19 +1001,17 @@
 	return ret;
 }
 
-static char *jabber_tooltip_text(GaimBuddy *b, gboolean full)
+static void jabber_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
 {
 	JabberBuddy *jb;
-	GString *ret;
 
-	g_return_val_if_fail(b != NULL, NULL);
-	g_return_val_if_fail(b->account != NULL, NULL);
-	g_return_val_if_fail(b->account->gc != NULL, NULL);
-	g_return_val_if_fail(b->account->gc->proto_data != NULL, NULL);
+	g_return_if_fail(b != NULL);
+	g_return_if_fail(b->account != NULL);
+	g_return_if_fail(b->account->gc != NULL);
+	g_return_if_fail(b->account->gc->proto_data != NULL);
 
 	jb = jabber_buddy_find(b->account->gc->proto_data, b->name,
 			FALSE);
-	ret = g_string_new("");
 
 	if(jb) {
 		JabberBuddyResource *jbr = NULL;
@@ -1036,7 +1034,7 @@
 				else
 					sub = _("None");
 			}
-			g_string_append_printf(ret, "\n<b>%s:</b> %s", _("Subscription"), sub);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Subscription"), sub);
 		}
 
 		for(l=jb->resources; l; l = l->next) {
@@ -1064,7 +1062,7 @@
 				text = NULL;
 			}
 
-			g_string_append_printf(ret, "\n<b>%s%s:</b> %s%s%s",
+			g_string_append_printf(str, "\n<b>%s%s:</b> %s%s%s",
 					_("Status"),
 					res ? res : "",
 					state,
@@ -1076,12 +1074,10 @@
 		}
 
 		if(!GAIM_BUDDY_IS_ONLINE(b) && jb->error_msg) {
-			g_string_append_printf(ret, "\n<b>%s:</b> %s",
+			g_string_append_printf(str, "\n<b>%s:</b> %s",
 					_("Error"), jb->error_msg);
 		}
 	}
-
-	return g_string_free(ret, FALSE);
 }
 
 static GList *jabber_status_types(GaimAccount *account)
--- a/src/protocols/msn/msn.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/msn/msn.c	Fri Jan 20 20:35:18 2006 +0000
@@ -536,27 +536,25 @@
 	return NULL;
 }
 
-static char *
-msn_tooltip_text(GaimBuddy *buddy, gboolean full)
+static void
+msn_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full)
 {
 	MsnUser *user;
 	GaimPresence *presence = gaim_buddy_get_presence(buddy);
 	GaimStatus *status = gaim_presence_get_active_status(presence);
-	GString *s;
 
 	user = buddy->proto_data;
 
-	s = g_string_new("");
 	if (gaim_presence_is_online(presence))
 	{
-		g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Status"),
+		g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Status"),
 							   gaim_presence_is_idle(presence) ?
 							   _("Idle") : gaim_status_get_name(status));
 	}
 
 	if (full && user)
 	{
-		g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Has you"),
+		g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Has you"),
 							   (user->list_op & (1 << MSN_LIST_RL)) ?
 							   _("Yes") : _("No"));
 
@@ -565,12 +563,10 @@
 	 * XXX: This can die as soon as gaim_privacy_check() knows that
 	 * XXX: this prpl always honors both the allow and deny lists. */
 	if (user)
-		g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Blocked"),
+		g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Blocked"),
 							   (user->list_op & (1 << MSN_LIST_BL)) ?
 							   _("Yes") : _("No"));
 	}
-
-	return g_string_free(s, FALSE);
 }
 
 static GList *
@@ -1359,7 +1355,8 @@
 	if (b)
 	{
 		GaimPresence *presence;
-		char *statustext = msn_tooltip_text(b, TRUE);
+		GString *str = g_string_new("");
+		char *tmp;
 
 		presence = gaim_buddy_get_presence(b);
 
@@ -1379,15 +1376,12 @@
 			g_free(nicktext);
 		}
 
-		if (statustext)
-		{
-			char *tmp;
-			tmp = gaim_strreplace((*statustext == '\n' ? statustext + 1 : statustext),
-								  "\n", "<br>");
-			g_free(statustext);
-			g_string_append_printf(s, "%s<br>", tmp);
-			g_free(tmp);
-		}
+		msn_tooltip_text(b, str, TRUE);
+		tmp = gaim_strreplace((*str->str == '\n' ? str->str + 1 : str->str),
+							  "\n", "<br>");
+		g_string_free(str, TRUE);
+		g_string_append_printf(s, "%s<br>", tmp);
+		g_free(tmp);
 	}
 
 	return g_string_free(s, FALSE);
--- a/src/protocols/novell/novell.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/novell/novell.c	Fri Jan 20 20:35:18 2006 +0000
@@ -2817,8 +2817,8 @@
 	return "novell";
 }
 
-static char *
-novell_tooltip_text(GaimBuddy * buddy, gboolean full)
+static void
+novell_tooltip_text(GaimBuddy * buddy, GString * str, gboolean full)
 {
 	NMUserRecord *user_record = NULL;
 	GaimConnection *gc;
@@ -2829,11 +2829,11 @@
 	const char *text = NULL;
 
 	if (buddy == NULL)
-		return "";
+		return; 
 
 	gc = gaim_account_get_connection(buddy->account);
 	if (gc == NULL || (user = gc->proto_data) == NULL)
-		return "";
+		return;
 
 	if (GAIM_BUDDY_IS_ONLINE(buddy)) {
 		user_record = nm_find_user_record(user, buddy->name);
@@ -2863,17 +2863,15 @@
 			}
 
 			if (text)
-				ret_text = g_strdup_printf("\n<b>%s:</b> %s"
-										   "\n<b>%s:</b> %s",
-										   _("Status"), status_str,
-										   _("Message"), text);
+				g_string_append_printf(str, "\n<b>%s:</b> %s"
+										    "\n<b>%s:</b> %s",
+										    _("Status"), status_str,
+										    _("Message"), text);
 			else
-				ret_text = g_strdup_printf("\n<b>%s:</b> %s",
-										   _("Status"), status_str);
+				g_string_append_printf(str, "\n<b>%s:</b> %s",
+										    _("Status"), status_str);
 		}
 	}
-
-	return ret_text;
 }
 
 static void
--- a/src/protocols/oscar/oscar.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/oscar/oscar.c	Fri Jan 20 20:35:18 2006 +0000
@@ -7715,11 +7715,10 @@
 	*ne = emblems[3];
 }
 
-static char *oscar_tooltip_text(GaimBuddy *b, gboolean full) {
+static void oscar_tooltip_text(GaimBuddy *b, GString *str, gboolean full) {
 	GaimConnection *gc = b->account->gc;
 	OscarData *od = gc->proto_data;
 	aim_userinfo_t *userinfo = aim_locate_finduserinfo(od->sess, b->name);
-	GString *str = g_string_new("");
 
 	if (GAIM_BUDDY_IS_ONLINE(b)) {
 		GaimPresence *presence;
@@ -7761,8 +7760,6 @@
 			}
 		}
 	}
-
-	return g_string_free(str, FALSE);
 }
 
 static char *oscar_status_text(GaimBuddy *b)
--- a/src/protocols/sametime/sametime.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/sametime/sametime.c	Fri Jan 20 20:35:18 2006 +0000
@@ -3173,12 +3173,11 @@
 }
 
 
-static char *mw_prpl_tooltip_text(GaimBuddy *b, gboolean full) {
+static void mw_prpl_tooltip_text(GaimBuddy *b, GString *str, gboolean full) {
   GaimConnection *gc;
   struct mwGaimPluginData *pd;
   struct mwAwareIdBlock idb = { mwAware_USER, b->name, NULL };
 
-  GString *str;
   const char *message;
   const char *status;
   char *tmp;
@@ -3186,8 +3185,6 @@
   gc = b->account->gc;
   pd = gc->proto_data;
 
-  str = g_string_new(NULL);
-
   message = mwServiceAware_getText(pd->srvc_aware, &idb);
   status = status_text(b);
 
@@ -3211,8 +3208,6 @@
       g_string_append(str, _("\n<b>External User</b>"));
     }
   }
-
-  return g_string_free(str, FALSE);
 }
 
 
--- a/src/protocols/silc/buddy.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/silc/buddy.c	Fri Jan 20 20:35:18 2006 +0000
@@ -1509,7 +1509,7 @@
 	return NULL;
 }
 
-char *silcgaim_tooltip_text(GaimBuddy *b, gboolean full)
+void silcgaim_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
 {
 	SilcGaim sg = b->account->gc->proto_data;
 	SilcClient client = sg->client;
@@ -1517,72 +1517,65 @@
 	SilcClientID *client_id = b->proto_data;
 	SilcClientEntry client_entry;
 	char *moodstr, *statusstr, *contactstr, *langstr, *devicestr, *tzstr, *geostr;
-	GString *s;
-	char *buf;
 	char tmp[256];
 
-	s = g_string_new("");
-
 	/* Get the client entry. */
 	client_entry = silc_client_get_client_by_id(client, conn, client_id);
 	if (!client_entry)
-	  return NULL;
+	  return;
 
 	if (client_entry->nickname)
-	  g_string_append_printf(s, "\n<b>%s:</b> %s", _("Nickname"),
+	  g_string_append_printf(str, "\n<b>%s:</b> %s", _("Nickname"),
 				 client_entry->nickname);
 	if (client_entry->username && client_entry->hostname)
-	  g_string_append_printf(s, "\n<b>%s:</b> %s@%s", _("Username"),
+	  g_string_append_printf(str, "\n<b>%s:</b> %s@%s", _("Username"),
 				 client_entry->username, client_entry->hostname);
 	if (client_entry->mode) {
-	  g_string_append_printf(s, "\n<b>%s:</b> ", _("User Modes"));
+	  g_string_append_printf(str, "\n<b>%s:</b> ", _("User Modes"));
 	  memset(tmp, 0, sizeof(tmp));
 	  silcgaim_get_umode_string(client_entry->mode,
 				    tmp, sizeof(tmp) - strlen(tmp));
-	  g_string_append_printf(s, "%s", tmp);
+	  g_string_append_printf(str, "%s", tmp);
 	}
 
 	silcgaim_parse_attrs(client_entry->attrs, &moodstr, &statusstr, &contactstr, &langstr, &devicestr, &tzstr, &geostr);
 
 	if (statusstr) {
-		g_string_append_printf(s, "\n<b>%s:</b> %s", _("Message"), statusstr);
+		g_string_append_printf(str, "\n<b>%s:</b> %s", _("Message"), statusstr);
 		g_free(statusstr);
 	}
 
 	if (full) {
 		if (moodstr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Mood"), moodstr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Mood"), moodstr);
 			g_free(moodstr);
 		}
 
 		if (contactstr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Contact"), contactstr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Preferred Contact"), contactstr);
 			g_free(contactstr);
 		}
 
 		if (langstr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Language"), langstr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Preferred Language"), langstr);
 			g_free(langstr);
 		}
 
 		if (devicestr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Device"), devicestr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Device"), devicestr);
 			g_free(devicestr);
 		}
 
 		if (tzstr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Timezone"), tzstr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Timezone"), tzstr);
 			g_free(tzstr);
 		}
 
 		if (geostr) {
-			g_string_append_printf(s, "\n<b>%s:</b> %s", _("Geolocation"), geostr);
+			g_string_append_printf(str, "\n<b>%s:</b> %s", _("Geolocation"), geostr);
 			g_free(geostr);
 		}
 	}
-
-	buf = g_string_free(s, FALSE);
-	return buf;
 }
 
 static void
--- a/src/protocols/silc/silcgaim.h	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/silc/silcgaim.h	Fri Jan 20 20:35:18 2006 +0000
@@ -107,7 +107,7 @@
 				   SilcClientEntry client_entry,
 				   const char *hostname, SilcUInt16 port);
 void silcgaim_idle_set(GaimConnection *gc, int idle);
-char *silcgaim_tooltip_text(GaimBuddy *b, gboolean full);
+void silcgaim_tooltip_text(GaimBuddy *b, GString *str, gboolean full);
 char *silcgaim_status_text(GaimBuddy *b);
 gboolean silcgaim_ip_is_private(const char *ip);
 void silcgaim_ftp_send_file(GaimConnection *gc, const char *name, const char *file);
--- a/src/protocols/yahoo/yahoo.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/yahoo/yahoo.c	Fri Jan 20 20:35:18 2006 +0000
@@ -2778,11 +2778,10 @@
 	}
 }
 
-char *yahoo_tooltip_text(GaimBuddy *b, gboolean full)
+void yahoo_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
 {
 	YahooFriend *f;
 	char *escaped, *status = NULL, *presence = NULL;
-	GString *s = g_string_new("");
 
 	f = yahoo_friend_find(b->account->gc, b->name);
 	if (!f)
@@ -2791,7 +2790,7 @@
 		switch (f->status) {
 		case YAHOO_STATUS_CUSTOM:
 			if (!yahoo_friend_get_status_message(f))
-				return NULL;
+				return;
 			status = g_strdup(yahoo_friend_get_status_message(f));
 			break;
 		case YAHOO_STATUS_OFFLINE:
@@ -2818,16 +2817,14 @@
 
 	if (status != NULL) {
 		escaped = g_markup_escape_text(status, strlen(status));
-		g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Status"), escaped);
+		g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Status"), escaped);
 		g_free(status);
 		g_free(escaped);
 	}
 
 	if (presence != NULL)
-		g_string_append_printf(s, _("\n<b>%s:</b> %s"),
+		g_string_append_printf(str, _("\n<b>%s:</b> %s"),
 				_("Presence"), presence);
-
-	return g_string_free(s, FALSE);
 }
 
 static void yahoo_addbuddyfrommenu_cb(GaimBlistNode *node, gpointer data)
--- a/src/protocols/yahoo/yahoo.h	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/yahoo/yahoo.h	Fri Jan 20 20:35:18 2006 +0000
@@ -177,7 +177,7 @@
 char *yahoo_string_decode(GaimConnection *gc, const char *str, gboolean utf8);
 
 /* previously-static functions, now needed for yahoo_profile.c */
-char *yahoo_tooltip_text(GaimBuddy *b, gboolean full);
+void yahoo_tooltip_text(GaimBuddy *b, GString *str, gboolean full);
 
 /* yahoo_profile.c */
 void yahoo_get_info(GaimConnection *gc, const char *name);
--- a/src/protocols/yahoo/yahoo_profile.c	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/protocols/yahoo/yahoo_profile.c	Fri Jan 20 20:35:18 2006 +0000
@@ -668,7 +668,9 @@
 			info_data->name);
 
 	if (b) {
-		char *statustext = yahoo_tooltip_text(b, TRUE);
+		GString *str = g_string_new("");
+		char *tmp;
+
 		if(b->alias && b->alias[0]) {
 			char *aliastext = g_markup_escape_text(b->alias, -1);
 			g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext);
@@ -682,14 +684,14 @@
 			g_free(idletime);
 		}
 		#endif
-		if (statustext) {
-			char *tmp;
-			g_strstrip(statustext);
-			tmp = gaim_strreplace(statustext, "\n", "<br>");
-			g_free(statustext);
-			g_string_append_printf(s, "%s<br>", tmp);
-			g_free(tmp);
-		}
+
+		yahoo_tooltip_text(b, str, TRUE);
+		tmp = gaim_strreplace((*str->str == '\n' ? str->str + 1 : str->str),
+							  "\n", "<br>");
+		g_string_free(str, TRUE);
+		g_string_append_printf(s, "%s<br>", tmp);
+		g_free(tmp);
+
 		if ((f = yahoo_friend_find(info_data->gc, b->name))) {
 			const char *ip;
 			if ((ip = yahoo_friend_get_ip(f)))
--- a/src/prpl.h	Fri Jan 20 17:24:54 2006 +0000
+++ b/src/prpl.h	Fri Jan 20 20:35:18 2006 +0000
@@ -189,9 +189,9 @@
 	char *(*status_text)(GaimBuddy *buddy);
 
 	/**
-	 * Gets a string to put in the buddy list tooltip.
+	 * Allows the prpl to add text to a buddy's tooltip.
 	 */
-	char *(*tooltip_text)(GaimBuddy *buddy, gboolean full);
+	void (*tooltip_text)(GaimBuddy *buddy, GString *str, gboolean full);
 
 	/**
 	 * This must be implemented, and must add at least the offline