Make builder and interface_file local to the init function.

This commit is contained in:
Matthew Brush 2011-09-23 21:29:32 -07:00 committed by Matthew Brush
parent fb4f21613b
commit d7538c83e1

View File

@ -32,8 +32,6 @@
#include "support.h" #include "support.h"
static gchar* interface_file = NULL;
static GtkBuilder* builder = NULL;
static GHashTable* objects_table = NULL; static GHashTable* objects_table = NULL;
@ -112,28 +110,33 @@ void interface_add_object(GObject *obj, const gchar *name)
void interface_init(void) void interface_init(void)
{ {
gchar *interface_file;
const gchar *name; const gchar *name;
GError *error; GError *error;
GSList *iter, *all_objects; GSList *iter, *all_objects;
GtkBuilder *builder;
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
g_return_if_fail(builder == NULL); g_return_if_fail(builder == NULL);
interface_file = g_build_filename(GEANY_DATADIR, "geany", "geany.glade", NULL); builder = gtk_builder_new();
if (! builder)
if (! (builder = gtk_builder_new()))
{ {
g_error("Failed to initialize the user-interface"); g_error("Failed to initialize the user-interface");
return; return;
} }
error = NULL; error = NULL;
interface_file = g_build_filename(GEANY_DATADIR, "geany", "geany.glade", NULL);
if (! gtk_builder_add_from_file(builder, interface_file, &error)) if (! gtk_builder_add_from_file(builder, interface_file, &error))
{ {
g_error("Failed to load the user-interface file: %s", error->message); g_error("Failed to load the user-interface file: %s", error->message);
g_error_free(error); g_error_free(error);
g_free(interface_file);
g_object_unref(builder);
return; return;
} }
g_free(interface_file);
gtk_builder_connect_signals(builder, NULL); gtk_builder_connect_signals(builder, NULL);
@ -163,14 +166,13 @@ void interface_init(void)
} }
} }
g_slist_free(all_objects); g_slist_free(all_objects);
g_object_unref(builder);
} }
void interface_finalize(void) void interface_finalize(void)
{ {
g_free(interface_file);
if (objects_table != NULL) if (objects_table != NULL)
g_hash_table_destroy(objects_table); g_hash_table_destroy(objects_table);
if (builder != NULL)
g_object_unref(builder);
} }