changeset 24115:9564593d170c

Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley is deleted. Closes #7159
author Marcus Lundblad <ml@update.uu.se>
date Thu, 25 Sep 2008 04:49:44 +0000
parents 6c8f5ebbb6b7
children b19a3458e6b2
files pidgin/gtkimhtml.c
diffstat 1 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Wed Sep 24 17:01:32 2008 +0000
+++ b/pidgin/gtkimhtml.c	Thu Sep 25 04:49:44 2008 +0000
@@ -348,6 +348,9 @@
 			g_string_free (t->values, TRUE);
 			g_free (t->children);
 		}
+		if (t && t->image) {
+			t->image->imhtml = NULL;
+		}
 		g_free (t);
 	}
 }
@@ -1958,7 +1961,6 @@
 	}
 }
 
-/* this isn't used yet
 static void gtk_smiley_tree_remove (GtkSmileyTree     *tree,
 			GtkIMHtmlSmiley   *smiley)
 {
@@ -1974,7 +1976,7 @@
 
 		pos = strchr (t->values->str, *x);
 		if (pos)
-			t = t->children [(int) pos - (int) t->values->str];
+			t = t->children [(unsigned int) pos - (unsigned int) t->values->str];
 		else
 			return;
 
@@ -1985,8 +1987,6 @@
 		t->image = NULL;
 	}
 }
-*/
-
 
 static gint
 gtk_smiley_tree_lookup (GtkSmileyTree *tree,
@@ -2046,6 +2046,25 @@
 	return 0;
 }
 
+static void
+gtk_imhtml_disassociate_smiley_foreach(gpointer key, gpointer value,
+	gpointer user_data)
+{
+	GtkSmileyTree *tree = (GtkSmileyTree *) value;
+	GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) user_data;
+	gtk_smiley_tree_remove(tree, smiley);
+}
+
+static void
+gtk_imhtml_disassociate_smiley(GtkIMHtmlSmiley *smiley)
+{
+	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);
+	}
+}
+
 void
 gtk_imhtml_associate_smiley (GtkIMHtml       *imhtml,
 			     const gchar     *sml,
@@ -5617,12 +5636,14 @@
 	smiley->smile = g_strdup(shortcut);
 	smiley->hidden = hide;
 	smiley->flags = flags;
+	smiley->imhtml = NULL;
 	gtk_imhtml_smiley_reload(smiley);
 	return smiley;
 }
 
 void gtk_imhtml_smiley_destroy(GtkIMHtmlSmiley *smiley)
 {
+	gtk_imhtml_disassociate_smiley(smiley);
 	g_free(smiley->smile);
 	g_free(smiley->file);
 	if (smiley->icon)