changeset 15325:e3ea20c6e73f

[gaim-migrate @ 18115] Add a destroy-notify function for the blist-headline. If you close a headline by clicking the cross, or if some headline is replaced by another one, this is not going to leak anymore. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 12 Jan 2007 22:17:32 +0000
parents 99dcbb8c4557
children ac460d00e235
files gtk/gtkblist.c gtk/gtkblist.h gtk/gtknotify.c
diffstat 3 files changed, 47 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtkblist.c	Fri Jan 12 17:43:25 2007 +0000
+++ b/gtk/gtkblist.c	Fri Jan 12 22:17:32 2007 +0000
@@ -3800,10 +3800,19 @@
 	return FALSE;
 }
 
+static void
+reset_headline(GaimGtkBuddyList *gtkblist)
+{
+	gtkblist->headline_callback = NULL;
+	gtkblist->headline_data = NULL;
+	gtkblist->headline_destroy = NULL;
+}
+
 static gboolean
 headline_click_callback(gpointer data)
 {
 	((GSourceFunc)gtkblist->headline_callback)(gtkblist->headline_data);
+	reset_headline(gtkblist);
 	return FALSE;
 }
 
@@ -3813,6 +3822,11 @@
 	gtk_widget_hide(gtkblist->headline_hbox);
 	if (gtkblist->headline_callback && !headline_hover_close((int)event->x, (int)event->y))
 		g_idle_add((GSourceFunc)headline_click_callback, gtkblist->headline_data);
+	else {
+		if (gtkblist->headline_destroy)
+			gtkblist->headline_destroy(gtkblist->headline_data);
+		reset_headline(gtkblist);
+	}
 	return TRUE;
 }
 
@@ -5678,13 +5692,19 @@
 }
 
 void
-gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback, gpointer user_data)
-{
+gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback,
+			gpointer user_data, GDestroyNotify destroy)
+{
+	/* Destroy any existing headline first */
+	if (gtkblist->headline_destroy)
+		gtkblist->headline_destroy(gtkblist->headline_data);
+
 	gtk_label_set_markup(GTK_LABEL(gtkblist->headline_label), text);
 	gtk_image_set_from_pixbuf(GTK_IMAGE(gtkblist->headline_image), pixbuf);
 
 	gtkblist->headline_callback = callback;
 	gtkblist->headline_data = user_data;
+	gtkblist->headline_destroy = destroy;
 	gtk_widget_show_all(gtkblist->headline_hbox);
 }
 
--- a/gtk/gtkblist.h	Fri Jan 12 17:43:25 2007 +0000
+++ b/gtk/gtkblist.h	Fri Jan 12 22:17:32 2007 +0000
@@ -106,6 +106,7 @@
 	GdkPixbuf *headline_close;      /**< Close image for closing the headline without triggering the callback */
 	GCallback headline_callback;    /**< Callback for headline notifications */
 	gpointer headline_data;         /**< User data for headline notifications */
+	GDestroyNotify headline_destroy; /**< Callback to use for destroying the headline-data */
 	gboolean changing_style;        /**< True when changing GTK+ theme style */
 	
 	GtkWidget *error_buttons;        /**< Box containing the connection error buttons */
@@ -340,7 +341,9 @@
  * @param pixbuf    The GdkPixbuf for the icon
  * @param callback  The callback to call when headline is clicked
  * @param user_data The userdata to include in the callback
+ * @param destroy   The callback to call when headline is closed or replaced by another headline.
  */
-void gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback, gpointer user_data);
+void gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback, gpointer user_data,
+		GDestroyNotify destroy);
 
 #endif /* _GAIM_GTKBLIST_H_ */
--- a/gtk/gtknotify.c	Fri Jan 12 17:43:25 2007 +0000
+++ b/gtk/gtknotify.c	Fri Jan 12 22:17:32 2007 +0000
@@ -155,6 +155,15 @@
 }
 
 static void
+reset_mail_dialog(GtkDialog *dialog)
+{
+	gaim_debug_fatal("WRTF!!", "resetting mail dialog\n");
+	gtk_widget_destroy(mail_dialog->dialog);
+	g_free(mail_dialog);
+	mail_dialog = NULL;
+}
+
+static void
 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data)
 {
 	gaim_notify_close(GAIM_NOTIFY_FORMATTED, win);
@@ -312,12 +321,18 @@
 };
 
 static void
+free_inbox(struct inbox_info *inbox)
+{
+	g_free(inbox->url);
+	g_free(inbox);
+}
+
+static void
 open_inbox_cb(struct inbox_info *inbox)
 {
 	if (inbox->url)
 		gaim_notify_uri(inbox->handle, inbox->url);
-	g_free(inbox->url);
-	g_free(inbox);
+	free_inbox(inbox);
 }
 
 
@@ -348,7 +363,8 @@
 		inbox->handle = gc;
 		inbox->url = urls ? g_strdup(urls[0]) : NULL;
 		gaim_gtk_blist_set_headline(label_text, 
-					    pixbuf, G_CALLBACK(open_inbox_cb), inbox);
+					    pixbuf, G_CALLBACK(open_inbox_cb), inbox,
+					    (GDestroyNotify)free_inbox);
 		g_object_unref(pixbuf);
 		return NULL;
 	}
@@ -540,7 +556,8 @@
 							    "<b>You have %d new e-mails.</b>",
 							    mail_dialog->total_count), mail_dialog->total_count);
 		gaim_gtk_blist_set_headline(label_text, 
-					    pixbuf, G_CALLBACK(gtk_widget_show_all), dialog);
+					    pixbuf, G_CALLBACK(gtk_widget_show_all), dialog,
+					    (GDestroyNotify)reset_mail_dialog);
 		g_object_unref(pixbuf);
 	}