Use signal for gui disposement. Whena gui is closed, the library data is relesed

This commit is contained in:
Mario Hüttel 2019-03-16 16:09:29 +01:00
parent 5357aff1b8
commit b9cc8570ac
2 changed files with 33 additions and 7 deletions

View File

@ -41,6 +41,10 @@
#include "tree-renderer/lib-cell-renderer.h"
#include "gds-parser/gds-tree-checker.h"
enum gds_render_gui_signal_sig_ids {SIGNAL_WINDOW_CLOSED = 0, SIGNAL_COUNT};
static guint gds_render_gui_signals[SIGNAL_COUNT];
struct _GdsRenderGui {
/* Parent GObject */
GObject parent;
@ -78,6 +82,11 @@ static gboolean on_window_close(gpointer window, GdkEvent *event, gpointer user)
g_clear_object(&self->main_window);
gtk_widget_destroy(GTK_WIDGET(window));
/* Delete loaded library data */
clear_lib_list(&self->gds_libraries);
g_signal_emit(self, gds_render_gui_signals[SIGNAL_WINDOW_CLOSED], 0);
return TRUE;
}
@ -424,13 +433,14 @@ static void gds_render_gui_dispose(GObject *gobject)
self = RENDERER_GUI(gobject);
clear_lib_list(&self->gds_libraries);
g_clear_object(&self->cell_tree_view);
g_clear_object(&self->convert_button);
g_clear_object(&self->layer_selector);
g_clear_object(&self->cell_tree_store);
g_clear_object(&self->cell_search_entry);
if (self->main_window) {
g_signal_handlers_destroy(self->main_window);
gtk_widget_destroy(GTK_WIDGET(self->main_window));
@ -445,6 +455,17 @@ static void gds_render_gui_class_init(GdsRenderGuiClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gds_render_gui_signals[SIGNAL_WINDOW_CLOSED] =
g_signal_newv("window-closed", RENDERER_TYPE_GUI,
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
NULL,
NULL,
NULL,
NULL,
G_TYPE_NONE,
0,
NULL);
gobject_class->dispose = gds_render_gui_dispose;
}

17
main.c
View File

@ -71,6 +71,15 @@ const static GActionEntry app_actions[] = {
{"about", app_about, NULL, NULL, NULL, {0}}
};
static void gui_window_closed_callback(GdsRenderGui *gui, gpointer user_data)
{
GList **gui_list = (GList **)user_data;
/* Dispose of Gui element */
*gui_list = g_list_remove(*gui_list, gui);
g_object_unref(gui);
}
static void gapp_activate(GApplication *app, gpointer user_data)
{
GtkWindow *main_window;
@ -81,6 +90,8 @@ static void gapp_activate(GApplication *app, gpointer user_data)
gui = gds_render_gui_new();
appdata->gui_list = g_list_append(appdata->gui_list, gui);
g_signal_connect(gui, "window-closed", G_CALLBACK(gui_window_closed_callback), &appdata->gui_list);
main_window = gds_render_gui_get_main_window(gui);
gtk_application_add_window(GTK_APPLICATION(app), main_window);
@ -127,12 +138,6 @@ static int start_gui(int argc, char **argv)
app_status = g_application_run(G_APPLICATION(gapp), argc, argv);
g_object_unref(gapp);
/* Destroy gui_list */
for (list_iter = appdata.gui_list; list_iter != NULL; list_iter = g_list_next(list_iter)) {
gui = RENDERER_GUI(list_iter->data);
g_object_unref(gui);
}
g_list_free(appdata.gui_list);
return app_status;