changeset 16977:563a42d98e3a

Fix ticket #387.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 09 May 2007 21:03:40 +0000
parents e7d7b5b88691
children d637851abeb8 1d7e0acc8a3e
files pidgin/gtkblist.c pidgin/gtkconv.c pidgin/gtknotify.c
diffstat 3 files changed, 67 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkblist.c	Wed May 09 19:34:07 2007 +0000
+++ b/pidgin/gtkblist.c	Wed May 09 21:03:40 2007 +0000
@@ -274,6 +274,11 @@
 
 static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b)
 {
+	PurpleNotifyUserInfo *info = purple_notify_user_info_new();
+	purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving..."));
+	purple_notify_userinfo(b->account->gc, purple_buddy_get_name(b), info, NULL, NULL);
+	purple_notify_user_info_destroy(info);
+
 	serv_get_info(b->account->gc, b->name);
 }
 
--- a/pidgin/gtkconv.c	Wed May 09 19:34:07 2007 +0000
+++ b/pidgin/gtkconv.c	Wed May 09 21:03:40 2007 +0000
@@ -672,6 +672,11 @@
 	PurpleConversation *conv = gtkconv->active_conv;
 
 	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
+		PurpleNotifyUserInfo *info = purple_notify_user_info_new();
+		purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving..."));
+		purple_notify_userinfo(conv->account->gc, purple_conversation_get_name(conv), info, NULL, NULL);
+		purple_notify_user_info_destroy(info);
+
 		serv_get_info(purple_conversation_get_gc(conv),
 					  purple_conversation_get_name(conv));
 
--- a/pidgin/gtknotify.c	Wed May 09 19:34:07 2007 +0000
+++ b/pidgin/gtknotify.c	Wed May 09 21:03:40 2007 +0000
@@ -549,6 +549,21 @@
 	return FALSE;
 }
 
+static GtkIMHtmlOptions
+notify_imhtml_options()
+{
+	GtkIMHtmlOptions options = 0;
+
+	if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting"))
+		options |= GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_FONTS | GTK_IMHTML_NO_SIZES;
+
+	options |= GTK_IMHTML_NO_COMMENTS;
+	options |= GTK_IMHTML_NO_TITLE;
+	options |= GTK_IMHTML_NO_NEWLINE;
+	options |= GTK_IMHTML_NO_SCROLL;
+	return options;
+}
+
 static void *
 pidgin_notify_formatted(const char *title, const char *primary,
 						  const char *secondary, const char *text)
@@ -559,7 +574,6 @@
 	GtkWidget *button;
 	GtkWidget *imhtml;
 	GtkWidget *frame;
-	int options = 0;
 	char label_text[2048];
 	char *linked_text, *primary_esc, *secondary_esc;
 
@@ -614,20 +628,13 @@
 	g_signal_connect(G_OBJECT(window), "key_press_event",
 					 G_CALLBACK(formatted_input_cb), NULL);
 
-	/* Add the text to the gtkimhtml */
-	if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting"))
-		options |= GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_FONTS | GTK_IMHTML_NO_SIZES;
-
-	options |= GTK_IMHTML_NO_COMMENTS;
-	options |= GTK_IMHTML_NO_TITLE;
-	options |= GTK_IMHTML_NO_NEWLINE;
-	options |= GTK_IMHTML_NO_SCROLL;
-
 	/* Make sure URLs are clickable */
 	linked_text = purple_markup_linkify(text);
-	gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text, options);
+	gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text, notify_imhtml_options());
 	g_free(linked_text);
 
+	g_object_set_data(G_OBJECT(window), "info-widget", imhtml);
+
 	/* Show the window */
 	gtk_widget_show(window);
 
@@ -856,18 +863,53 @@
 	return data;
 }
 
+/** Xerox'ed from Finch! How the tables have turned!! ;) **/
+/** 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(GtkWidget *widget, gpointer key)
+{
+	g_hash_table_remove(userinfo, key);
+}
+
 static void *
 pidgin_notify_userinfo(PurpleConnection *gc, const char *who,
 						 PurpleNotifyUserInfo *user_info)
 {
-	char *primary, *info;
+	char *info;
 	void *ui_handle;
+	char *key = userinfo_hash(purple_connection_get_account(gc), who);
+
+	if (!userinfo) {
+		userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+	}
 
-	primary = g_strdup_printf(_("Info for %s"), who);
 	info = purple_notify_user_info_get_text_with_newline(user_info, "<br />");
-	ui_handle = pidgin_notify_formatted(_("Buddy Information"), primary, NULL, info);
+	ui_handle = g_hash_table_lookup(userinfo, key);
+	if (ui_handle != NULL) {
+		GtkIMHtml *imhtml = g_object_get_data(G_OBJECT(ui_handle), "info-widget");
+		char *linked_text = purple_markup_linkify(info);
+		gtk_imhtml_clear(imhtml);
+		gtk_imhtml_append_text(imhtml, linked_text, notify_imhtml_options());
+		g_free(linked_text);
+		g_free(key);
+	} else {
+		char *primary = g_strdup_printf(_("Info for %s"), who);
+		ui_handle = pidgin_notify_formatted(_("Buddy Information"), primary, NULL, info);
+		g_hash_table_insert(userinfo, key, ui_handle);
+		g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key);
+		g_free(primary);
+	}
 	g_free(info);
-	g_free(primary);
 	return ui_handle;
 }