changeset 4722:534eaa4ead94

[gaim-migrate @ 5034] Provided a generic way for prpls to put text in the second line of the Big List and removed a hideous Yahoo! buddy menu hack in the process committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 12 Mar 2003 06:37:40 +0000
parents 91ef4fae4a49
children 39068784aa08
files src/buddy.c src/protocols/yahoo/yahoo.c src/prpl.h
diffstat 3 files changed, 46 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddy.c	Wed Mar 12 02:27:28 2003 +0000
+++ b/src/buddy.c	Wed Mar 12 06:37:40 2003 +0000
@@ -545,12 +545,14 @@
 {
 	char *name = gaim_get_buddy_alias(b);
 	char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL;
+	struct prpl* prpl = find_prpl(b->account->protocol);
+
 	/* XXX Clean up this crap */
 
 	int ihrs, imin;
-	char *idletime = "";
-	char *warning = idletime;
-	time_t t;
+	char *idletime = NULL, *warning = NULL;
+	const char *statustext = NULL;
+       	time_t t;
 
 	if (!(blist_options & OPT_BLIST_SHOW_ICONS)) {
 		if (b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS) {
@@ -567,27 +569,39 @@
 	ihrs = (t - b->idle) / 3600;
 	imin = ((t - b->idle) / 60) % 60;
 
+	if (prpl->status_text) {
+		char *tmp = prpl->status_text(b);
+		if (tmp)
+			statustext = g_markup_escape_text(tmp, strlen(tmp));
+	}
+	
 	if (b->idle) {
 		if (ihrs)
 			idletime = g_strdup_printf(_("Idle (%dh%02dm)"), ihrs, imin);
 		else
 			idletime = g_strdup_printf(_("Idle (%dm)"), imin);
 	}
-
+	
 	if (b->evil > 0)
 		warning = g_strdup_printf(_("Warned (%d%%)"), b->evil);
-
+	
 	if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS)
-		text =  g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s %s</span>",
+		text =  g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s %s %s</span>",
 					esc,
-					idletime, warning);
+					statustext != NULL ? statustext : "",
+					idletime != NULL ? idletime : "", 
+					warning != NULL ? warning : "");
 	else
-		text = g_strdup_printf("%s\n<span color='dim grey' size='smaller'>%s %s</span>", esc, idletime, warning);
-
-	if (idletime[0])
+		text = g_strdup_printf("%s\n<span color='dim grey' size='smaller'>%s %s %s</span>", esc, 
+				       statustext != NULL ? statustext :  "",
+				       idletime != NULL ? idletime : "", 
+				       warning != NULL ? warning : "");
+	if (idletime)
 		g_free(idletime);
-	if (warning[0])
+	if (warning)
 		g_free(warning);
+	if (statustext)
+		g_free(statustext);
 
 	return text;
 }
--- a/src/protocols/yahoo/yahoo.c	Wed Mar 12 02:27:28 2003 +0000
+++ b/src/protocols/yahoo/yahoo.c	Wed Mar 12 06:37:40 2003 +0000
@@ -1064,6 +1064,18 @@
 	open_url(NULL, url);
 	g_free(game);
 }
+
+static const char *yahoo_status_text(struct buddy *b)
+{
+	struct yahoo_data *yd = (struct yahoo_data*)b->account->gc->proto_data;
+	if (b->uc & UC_UNAVAILABLE && b->uc >> 2 != YAHOO_STATUS_IDLE) {
+	       	if ((b->uc >> 2) != YAHOO_STATUS_CUSTOM)
+			return yahoo_get_status_string(b->uc >> 2);
+		else
+			return g_hash_table_lookup(yd->hash, b->name);
+	}
+}
+
 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who)
 {
 	GList *m = NULL;
@@ -1073,21 +1085,7 @@
 						  segfault and get the bug report. */
 	static char buf[1024];
 	static char buf2[1024];
-	
-	if (b->uc & UC_UNAVAILABLE && b->uc >> 2 != YAHOO_STATUS_IDLE) {
-		pbm = g_new0(struct proto_buddy_menu, 1);
-		if ((b->uc >> 2) != YAHOO_STATUS_CUSTOM)
-			g_snprintf(buf, sizeof buf, 
-				   "Status: %s", yahoo_get_status_string(b->uc >> 2));
-		else
-			g_snprintf(buf, sizeof buf, "Custom Status: %s",
-				   (char *)g_hash_table_lookup(yd->hash, b->name));
-		pbm->label = buf;
-		pbm->callback = NULL;
-		pbm->gc = gc;
-		m = g_list_append(m, pbm);
-	}
-	
+
 	if (b->uc | YAHOO_STATUS_GAME) {
 		char *game = g_hash_table_lookup(yd->games, b->name);
 		char *room;
@@ -1111,7 +1109,7 @@
 			m = g_list_append(m, pbm);
 		}
 	}
-
+	
 	return m;
 }
 
@@ -1348,6 +1346,7 @@
 	ret->close = yahoo_close;
 	ret->buddy_menu = yahoo_buddy_menu;
 	ret->list_icon = yahoo_list_icon;
+	ret->status_text = yahoo_status_text;
 	ret->actions = yahoo_actions;
 	ret->send_im = yahoo_send_im;
 	ret->away_states = yahoo_away_states;
--- a/src/prpl.h	Wed Mar 12 02:27:28 2003 +0000
+++ b/src/prpl.h	Wed Mar 12 06:37:40 2003 +0000
@@ -190,6 +190,12 @@
 	 * interpret and display as relevant
 	 */
 	void (* list_emblems)(struct buddy *buddy, char **se, char **sw, char **nw, char **ne);
+
+	/**
+	 * Gets a short string representing this buddy's status.  This will be shown
+	 * on the buddy list.
+	 */
+	const char *(* status_text)(struct buddy *buddy);
 	
 	GList *(* away_states)(struct gaim_connection *gc);
 	GList *(* actions)(struct gaim_connection *gc);