pidgin: 9a919561: Remove that hack involving GtkIMHtmlSmil...

malu at pidgin.im malu at pidgin.im
Wed Nov 5 18:25:28 EST 2008


-----------------------------------------------------------------
Revision: 9a91956125003141d6eb6d89094aa76ae479879a
Ancestor: 633ffe234af48ead3631ae62e23840b4438fcf5f
Author: malu at pidgin.im
Date: 2008-11-05T23:24:01
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9a91956125003141d6eb6d89094aa76ae479879a

Modified files:
        pidgin/gtkimhtml.c pidgin/gtkthemes.c

ChangeLog: 

Remove that hack involving GtkIMHtmlSmileys
Thanks to Sadrul for hinting about the solution

-------------- next part --------------
============================================================
--- pidgin/gtkimhtml.c	15cbdaed36b28411bf555ace284f51ad3bcf72ec
+++ pidgin/gtkimhtml.c	e6d9c36f8a08f24eaac37d6d3f21885b40cc432a
@@ -2045,29 +2045,6 @@ gtk_smiley_tree_lookup (GtkSmileyTree *t
 	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
 }
 
 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 @@ gtk_imhtml_associate_smiley (GtkIMHtml  
 		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
============================================================
--- pidgin/gtkthemes.c	e916342140982886e50abb172e5139f184256be9
+++ pidgin/gtkthemes.c	7fbff18d2f55de2dd1262f95f2d89e776ff4c7d9
@@ -169,6 +169,12 @@ pidgin_themes_destroy_smiley_theme_smile
 	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) {


More information about the Commits mailing list