changeset 25972:e3f2b16f75da

Always show the top resource first in the tooltip
author Marcus Lundblad <ml@update.uu.se>
date Fri, 06 Feb 2009 22:45:52 +0000
parents b955681d9597
children 6f1bd5f3aaa0
files libpurple/protocols/jabber/jabber.c
diffstat 1 files changed, 61 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Fri Feb 06 22:07:57 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Feb 06 22:45:52 2009 +0000
@@ -1683,6 +1683,56 @@
 	return ret;
 }
 
+static void
+jabber_tooltip_add_resource_text(JabberBuddyResource *jbr, 
+	PurpleNotifyUserInfo *user_info, gboolean multiple_resources)
+{
+	char *text = NULL;
+	char *res = NULL;
+	char *label, *value;
+	const char *state;
+
+	if(jbr->status) {
+		char *tmp;
+		text = purple_strreplace(jbr->status, "\n", "<br />\n");
+		tmp = purple_markup_strip_html(text);
+		g_free(text);
+		text = g_markup_escape_text(tmp, -1);
+		g_free(tmp);
+	}
+
+	if(jbr->name)
+		res = g_strdup_printf(" (%s)", jbr->name);
+
+	state = jabber_buddy_state_get_name(jbr->state);
+	if (text != NULL && !purple_utf8_strcasecmp(state, text)) {
+		g_free(text);
+		text = NULL;
+	}
+
+	label = g_strdup_printf("%s%s", _("Status"), (res ? res : ""));
+	value = g_strdup_printf("%s%s%s", state, (text ? ": " : ""), (text ? text : ""));
+
+	purple_notify_user_info_add_pair(user_info, label, value);
+	g_free(label);
+	g_free(value);
+	g_free(text);
+	
+	/* if the resource is idle, show that */
+	/* only show it if there is more than one resource available for
+	the buddy, since the "general" idleness will be shown anyway,
+	this way we can see see the idleness of lower-priority resources */
+	if (jbr->idle && multiple_resources) {
+		gchar *idle_str = 
+			purple_str_seconds_to_string(time(NULL) - jbr->idle);
+		label = g_strdup_printf("%s%s", _("Idle"), (res ? res : ""));
+		purple_notify_user_info_add_pair(user_info, label, idle_str);
+		g_free(idle_str);
+		g_free(label);
+	}
+	g_free(res);
+}
+
 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full)
 {
 	JabberBuddy *jb;
@@ -1703,60 +1753,22 @@
 		const char *mood;
 		gboolean multiple_resources = 
 			jb->resources && g_list_next(jb->resources);
-
+		JabberBuddyResource *top_jbr = jabber_buddy_find_resource(jb, NULL);
+		
+		/* resource-specific info for the top resource */
+		jabber_tooltip_add_resource_text(top_jbr, user_info, 
+			multiple_resources);
+		
 		for(l=jb->resources; l; l = l->next) {
-			char *text = NULL;
 			char *res = NULL;
-			char *label, *value;
-			const char *state;
+			char *label;
 
 			jbr = l->data;
-
-			if(jbr->status) {
-				char *tmp;
-				text = purple_strreplace(jbr->status, "\n", "<br />\n");
-				tmp = purple_markup_strip_html(text);
-				g_free(text);
-				text = g_markup_escape_text(tmp, -1);
-				g_free(tmp);
-			}
-
-			if(jbr->name)
-				res = g_strdup_printf(" (%s)", jbr->name);
-
-			state = jabber_buddy_state_get_name(jbr->state);
-			if (text != NULL && !purple_utf8_strcasecmp(state, text)) {
-				g_free(text);
-				text = NULL;
+			/* the remaining resources */
+			if (jbr != top_jbr) {
+				jabber_tooltip_add_resource_text(jbr, user_info,
+					multiple_resources);
 			}
-
-			label = g_strdup_printf("%s%s",
-							_("Status"), (res ? res : ""));
-			value = g_strdup_printf("%s%s%s",
-							state,
-							(text ? ": " : ""),
-							(text ? text : ""));
-
-			purple_notify_user_info_add_pair(user_info, label, value);
-			g_free(label);
-			g_free(value);
-			g_free(text);
-			
-			/* if the resource is idle, show that */
-			/* only show it if there is more than one resource available for
-			 the buddy, since the "general" idleness will be shown anyway,
-			 this way we can see see the idleness of lower-priority resources */
-			if (jbr->idle && multiple_resources) {
-				gchar *idle_str = 
-					purple_str_seconds_to_string(time(NULL) - jbr->idle);
-				label = g_strdup_printf("%s%s",
-					_("Idle"), (res ? res : ""));
-				purple_notify_user_info_add_pair(user_info, label, idle_str);
-				g_free(idle_str);
-				g_free(label);
-			}
-			
-			g_free(res);
 		}
 		
 		if (full) {