changeset 24368:9ea84135db24

Remove that hack involving GtkIMHtmlSmileys Thanks to Sadrul for hinting about the solution
author Marcus Lundblad <ml@update.uu.se>
date Wed, 05 Nov 2008 23:24:01 +0000
parents 4acda11bf672
children f4cb55854e87
files pidgin/gtkimhtml.c pidgin/gtkthemes.c
diffstat 2 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Mon Nov 03 20:36:38 2008 +0000
+++ b/pidgin/gtkimhtml.c	Wed Nov 05 23:24:01 2008 +0000
@@ -2045,29 +2045,6 @@
 	return 0;
 }
 
-/* a hack-around to prevent trying to doing gtk_smiley_tree_remove on a
- GtkIMHtml that no longer lives... I know this is ugly, but I couldn't find
- a better way to handle it for now, since there lives a list GtkIMHtmlSmileys
- in gtksmiley.c and those can end up having dangling imhtml pointers */
-static gboolean
-gtk_imhtml_is_alive(const GtkIMHtml *imhtml)
-{
-	GList *convs;
-	
-	for (convs = purple_get_conversations() ; convs != NULL ;
-		 convs = g_list_next(convs)) {
-		PurpleConversation *conv = (PurpleConversation *) convs->data;
-			 
-		if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
-			if (GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml) == imhtml
-				|| GTK_IMHTML(PIDGIN_CONVERSATION(conv)->entry) == imhtml) {
-				return TRUE;
-			}
-		}
-	}
-	return FALSE;
-}
-
 static void
 gtk_imhtml_disassociate_smiley_foreach(gpointer key, gpointer value,
 	gpointer user_data)
@@ -2078,12 +2055,22 @@
 }
 
 static void
+gtk_imhtml_disconnect_smiley(GtkIMHtml *imhtml, GtkIMHtmlSmiley *smiley)
+{
+	smiley->imhtml = NULL;
+	g_signal_handlers_disconnect_matched(imhtml, G_SIGNAL_MATCH_DATA, 0, 0,
+		NULL, NULL, smiley);
+}
+
+static void
 gtk_imhtml_disassociate_smiley(GtkIMHtmlSmiley *smiley)
 {
-	if (smiley->imhtml && gtk_imhtml_is_alive(smiley->imhtml)) {
+	if (smiley->imhtml) {
 		gtk_smiley_tree_remove(smiley->imhtml->default_smilies, smiley);
 		g_hash_table_foreach(smiley->imhtml->smiley_data, 
 			gtk_imhtml_disassociate_smiley_foreach, smiley);
+		g_signal_handlers_disconnect_matched(smiley->imhtml, G_SIGNAL_MATCH_DATA,
+			0, 0, NULL, NULL, smiley);
 		smiley->imhtml = NULL;
 	}
 }
@@ -2104,9 +2091,19 @@
 		g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree);
 	}
 
+	/* need to disconnect old imhtml, if there is one */
+	if (smiley->imhtml) {
+		g_signal_handlers_disconnect_matched(smiley->imhtml, G_SIGNAL_MATCH_DATA,
+			0, 0, NULL, NULL, smiley);
+	}
+	
 	smiley->imhtml = imhtml;
 
 	gtk_smiley_tree_insert (tree, smiley);
+	
+	/* connect destroy signal for the imhtml */
+	g_signal_connect(imhtml, "destroy", G_CALLBACK(gtk_imhtml_disconnect_smiley), 
+		smiley);
 }
 
 static gboolean
--- a/pidgin/gtkthemes.c	Mon Nov 03 20:36:38 2008 +0000
+++ b/pidgin/gtkthemes.c	Wed Nov 05 23:24:01 2008 +0000
@@ -169,6 +169,12 @@
 	for (wer = theme->list; wer != NULL; wer = theme->list) {
 		while (wer->smileys) {
 			GtkIMHtmlSmiley *uio = wer->smileys->data;
+			
+			if (uio->imhtml) {
+				g_signal_handlers_disconnect_matched(uio->imhtml, G_SIGNAL_MATCH_DATA,
+					0, 0, NULL, NULL, uio);
+			}
+				
 			if (uio->icon)
 				g_object_unref(uio->icon);
 			if (g_hash_table_lookup(already_freed, uio->file) == NULL) {