changeset 16936:9a568611fa4a

When getting information, show "Information: Retrieving..." before the data reaches from the server. This addresses #387.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 06 May 2007 21:55:07 +0000
parents 49f66fab6b31
children 7e4a22162bb6 3d0aec991e5d 50a9c82d32a1
files finch/gntblist.c finch/gntnotify.c
diffstat 2 files changed, 77 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntblist.c	Sun May 06 21:40:29 2007 +0000
+++ b/finch/gntblist.c	Sun May 06 21:55:07 2007 +0000
@@ -819,6 +819,13 @@
 static void
 finch_blist_get_buddy_info_cb(PurpleBuddy *buddy, PurpleBlistNode *selected)
 {
+	/* Add a userinfo with a "Retrieving information", which will later be updated
+	 * when the server finally returns the information. */
+	PurpleNotifyUserInfo *info = purple_notify_user_info_new();
+	purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving..."));
+	purple_notify_userinfo(buddy->account->gc, purple_buddy_get_name(buddy), info, NULL, NULL);
+	purple_notify_user_info_destroy(info);
+
 	serv_get_info(buddy->account->gc, purple_buddy_get_name(buddy));
 }
 
--- a/finch/gntnotify.c	Sun May 06 21:40:29 2007 +0000
+++ b/finch/gntnotify.c	Sun May 06 21:55:07 2007 +0000
@@ -27,6 +27,7 @@
 #include <gntbutton.h>
 #include <gntlabel.h>
 #include <gnttree.h>
+#include <gntutils.h>
 
 #include <util.h>
 
@@ -72,11 +73,26 @@
 	if (primary)
 		gnt_box_add_widget(GNT_BOX(window),
 				gnt_label_new_with_format(primary, pf));
-	if (secondary)
-		gnt_box_add_widget(GNT_BOX(window),
-				gnt_label_new_with_format(secondary, sf));
 
 	button = gnt_button_new(_("OK"));
+
+	if (secondary) {
+		GntWidget *msg;
+		if (type == PURPLE_NOTIFY_FORMATTED) {
+			int width = -1, height = -1;
+			msg = gnt_text_view_new();
+			gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(msg), secondary, sf);
+			gnt_text_view_scroll(GNT_TEXT_VIEW(msg), 0);
+			gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(msg), button);
+			gnt_util_get_text_bound(secondary, &width, &height);
+			gnt_widget_set_size(msg, width + 3, height + 1);
+		} else {
+			msg = gnt_label_new_with_format(secondary, sf);
+		}
+		gnt_box_add_widget(GNT_BOX(window), msg);
+		g_object_set_data(G_OBJECT(window), "info-widget", msg);
+	}
+
 	gnt_box_add_widget(GNT_BOX(window), button);
 	g_signal_connect_swapped(G_OBJECT(button), "activate",
 			G_CALLBACK(gnt_widget_destroy), window);
@@ -219,19 +235,63 @@
 			url ? &url : NULL);
 }
 
+/** User information. **/
+static GHashTable *userinfo;
+
+static char *
+userinfo_hash(PurpleAccount *account, const char *who)
+{
+	char key[256];
+	snprintf(key, sizeof(key), "%s - %s", purple_account_get_username(account), purple_normalize(account, who));
+	return g_utf8_strup(key, -1);
+}
+
+static void
+remove_userinfo(GntWidget *widget, gpointer key)
+{
+	g_hash_table_remove(userinfo, key);
+}
+
 static void *
 finch_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info)
 {
-	/* Xeroxed from gtknotify.c */
 	char *primary;
 	char *info;
 	void *ui_handle;
-	
-	primary = g_strdup_printf(_("Info for %s"), who);
+	char *key = userinfo_hash(purple_connection_get_account(gc), who);
+
 	info = purple_notify_user_info_get_text_with_newline(user_info, "<BR>");
-	ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info);
+
+	ui_handle = g_hash_table_lookup(userinfo, key);
+	if (ui_handle != NULL) {
+		GntTextView *msg = GNT_TEXT_VIEW(g_object_get_data(G_OBJECT(ui_handle), "info-widget"));
+		char *strip = purple_markup_strip_html(info);
+		int tvw, tvh, width, height, ntvw, ntvh;
+
+		gnt_widget_get_size(GNT_WIDGET(ui_handle), &width, &height);
+		gnt_widget_get_size(GNT_WIDGET(msg), &tvw, &tvh);
+
+		/* Ideally, I would replace the information in "info". But replacing tagged text is a
+		 * bit nasty right now. So clear the view and add the new stuff instead. */
+		gnt_text_view_clear(msg);
+		gnt_text_view_append_text_with_flags(msg, strip, GNT_TEXT_FLAG_NORMAL);
+		gnt_text_view_scroll(msg, 0);
+		gnt_util_get_text_bound(strip, &ntvw, &ntvh);
+		ntvw += 3;
+		ntvh++;
+
+		gnt_screen_resize_widget(GNT_WIDGET(ui_handle), width + (ntvw - tvw), height + (ntvh - tvh));
+		g_free(strip);
+		g_free(key);
+	} else {
+		primary = g_strdup_printf(_("Info for %s"), who);
+		ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info);
+		g_hash_table_insert(userinfo, key, ui_handle);
+		g_free(primary);
+		g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key);
+	}
+
 	g_free(info);
-	g_free(primary);
 	return ui_handle;
 }
 
@@ -365,10 +425,12 @@
 
 void finch_notify_init()
 {
+	userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 }
 
 void finch_notify_uninit()
 {
+	g_hash_table_destroy(userinfo);
 }