[devhelp/gnome-2-28] Clean up application windows on 'Quit' action



commit 691e90f44f2e07e691ed303bb7afb8050fb3943b
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Tue Sep 29 17:38:40 2009 -0500

    Clean up application windows on 'Quit' action
    
    Previously, when the 'Quit' action was activated, we just called
    gtk_main_quit(), but that doesn't give the application a chance to clean up all
    open windows, etc.  This resulted in a leak at exit (I know, not a big deal to
    leak at exit, but still...) because each open window didn't get a chance to
    unref their priv->base member, so the g_object_unref(base) in main() did not
    actually result in the base object being destroyed, so the DhBase destructor was
    never being called when the application was exited using the 'Quit' action (it
    was behaving correctly when the windows were closed by the window manager).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=596808
    (cherry picked from commit f1738eedca89bc32bc806779cf7f800f2dfa5423)

 src/dh-base.c   |   13 +++++++++++++
 src/dh-base.h   |    1 +
 src/dh-window.c |    2 +-
 3 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/src/dh-base.c b/src/dh-base.c
index 707e320..9d10bd6 100644
--- a/src/dh-base.c
+++ b/src/dh-base.c
@@ -599,3 +599,16 @@ dh_base_get_window (DhBase *base)
 
         return window;
 }
+
+void
+dh_base_quit (DhBase *base)
+{
+        DhBasePriv *priv = GET_PRIVATE (base);
+
+        /* Make sure all of the windows get a chance to release their resources
+         * properly.  As they get destroyed,
+         * base_window_or_assistant_finalized_cb() will be called, and when the
+         * last one is removed, we will quit */
+        g_slist_foreach (priv->windows, (GFunc)gtk_widget_destroy, NULL);
+        g_slist_foreach (priv->assistants, (GFunc)gtk_widget_destroy, NULL);
+}
diff --git a/src/dh-base.h b/src/dh-base.h
index 0c25697..bb76930 100644
--- a/src/dh-base.h
+++ b/src/dh-base.h
@@ -54,6 +54,7 @@ GtkWidget *  dh_base_get_window                      (DhBase *base);
 GtkWidget *  dh_base_get_window_on_current_workspace (DhBase *base);
 GNode *      dh_base_get_book_tree                   (DhBase *base);
 GList *      dh_base_get_keywords                    (DhBase *base);
+void         dh_base_quit                            (DhBase *base);
 
 G_END_DECLS
 
diff --git a/src/dh-window.c b/src/dh-window.c
index efbd925..2a121d3 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -215,7 +215,7 @@ static void
 window_activate_quit (GtkAction *action,
                       DhWindow  *window)
 {
-        gtk_main_quit ();
+        dh_base_quit (window->priv->base);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]