summaryrefslogtreecommitdiff
path: root/gladeui
diff options
context:
space:
mode:
authorVincent Geddes <vgeddes@src.gnome.org>2007-07-01 14:19:47 +0000
committerVincent Geddes <vgeddes@src.gnome.org>2007-07-01 14:19:47 +0000
commit01535eef9b3ae1e15b747ba6e000793e6d6b7487 (patch)
treeced69b966f62eec01add46dc206253b77170b05f /gladeui
parenta6db19a9238f7eaf133beb4af0fd651d06951eec (diff)
downloadglade-01535eef9b3ae1e15b747ba6e000793e6d6b7487.tar.gz
Add glade_catalog_destroy_all(). Use g_slice_new() for mem allocation.
* gladeui/glade-catalog.h, gladeui/glade-catalog.c: Add glade_catalog_destroy_all(). Use g_slice_new() for mem allocation. * gladeui/glade-app.c: Free catalogs in finalize. svn path=/trunk/; revision=1421
Diffstat (limited to 'gladeui')
-rw-r--r--gladeui/glade-app.c12
-rw-r--r--gladeui/glade-catalog.c264
-rw-r--r--gladeui/glade-catalog.h38
-rw-r--r--gladeui/glade-palette.c2
4 files changed, 173 insertions, 143 deletions
diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c
index 65d47cbd..06270497 100644
--- a/gladeui/glade-app.c
+++ b/gladeui/glade-app.c
@@ -182,18 +182,14 @@ glade_app_dispose (GObject *app)
static void
glade_app_finalize (GObject *app)
{
-
-#ifdef G_OS_WIN32
g_free (catalogs_dir);
g_free (modules_dir);
g_free (bindings_dir);
g_free (pixmaps_dir);
g_free (locale_dir);
-#endif
-
- glade_binding_unload_all ();
-
- glade_catalog_modules_close ();
+
+ glade_binding_unload_all ();
+ glade_catalog_destroy_all ();
G_OBJECT_CLASS (glade_app_parent_class)->finalize (app);
}
@@ -451,7 +447,7 @@ glade_app_init (GladeApp *app)
app->priv->accel_group = NULL;
/* Initialize app objects */
- app->priv->catalogs = glade_catalog_load_all ();
+ app->priv->catalogs = (GList *) glade_catalog_load_all ();
/* Create palette */
app->priv->palette = (GladePalette *) glade_palette_new (app->priv->catalogs);
diff --git a/gladeui/glade-catalog.c b/gladeui/glade-catalog.c
index 8b55dfef..903a6be4 100644
--- a/gladeui/glade-catalog.c
+++ b/gladeui/glade-catalog.c
@@ -21,23 +21,19 @@
* Chema Celorio <chema@celorio.com>
*/
-
-#include <string.h>
-
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <glib.h>
-#include <glib/gi18n-lib.h>
#include "glade.h"
#include "glade-catalog.h"
#include "glade-widget-adaptor.h"
#include "glade-binding.h"
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
typedef void (*GladeCatalogInitFunc) (void);
struct _GladeCatalog
@@ -74,8 +70,8 @@ struct _GladeCatalog
struct _GladeWidgetGroup
{
- gchar *name; /* Group name */
- gchar *title; /* Group name in the palette */
+ gchar *name; /* Group name */
+ gchar *title; /* Group name in the palette */
gboolean expanded; /* Whether group is expanded in the palette */
@@ -83,16 +79,27 @@ struct _GladeWidgetGroup
};
static void catalog_load (GladeCatalog *catalog);
+
static GladeCatalog *catalog_open (const gchar *filename);
+
static GList *catalog_sort (GList *catalogs);
+
static gboolean catalog_load_classes (GladeCatalog *catalog,
+
GladeXmlNode *widgets_node);
+
static gboolean catalog_load_group (GladeCatalog *catalog,
+
GladeXmlNode *group_node);
-static void widget_group_free (GladeWidgetGroup *group);
+static void widget_group_destroy (GladeWidgetGroup *group);
+
+static void catalog_destroy (GladeCatalog *catalog);
+
+static void module_close (GModule *module);
+
-/* List of catalog names successfully loaded.
+/* List of catalogs successfully loaded.
*/
static GList *loaded_catalogs = NULL;
@@ -111,6 +118,30 @@ catalog_get_function (GladeCatalog *catalog,
}
static GladeCatalog *
+catalog_allocate (void)
+{
+ GladeCatalog *catalog;
+
+ catalog = g_slice_new0 (GladeCatalog);
+
+ catalog->language = NULL;
+ catalog->library = NULL;
+ catalog->name = NULL;
+ catalog->dep_catalog = NULL;
+ catalog->domain = NULL;
+ catalog->book = NULL;
+ catalog->icon_prefix = NULL;
+ catalog->init_function_name = NULL;
+ catalog->module = NULL;
+
+ catalog->context = NULL;
+ catalog->adaptors = NULL;
+ catalog->widget_groups = NULL;
+
+ return catalog;
+}
+
+static GladeCatalog *
catalog_open (const gchar *filename)
{
GladeCatalog *catalog;
@@ -139,15 +170,14 @@ catalog_open (const gchar *filename)
return NULL;
}
- catalog = g_new0 (GladeCatalog, 1);
+ catalog = catalog_allocate ();
catalog->context = context;
catalog->name = glade_xml_get_property_string (root, GLADE_TAG_NAME);
if (!catalog->name)
{
g_warning ("Couldn't find required property 'name' in catalog root node");
- g_free (catalog);
- glade_xml_context_free (context);
+ catalog_destroy (catalog);
return NULL;
}
@@ -159,29 +189,17 @@ catalog_open (const gchar *filename)
g_warning ("%s language is not supported. "
"Make sure the corresponding GladeBinding module is available.",
catalog->language);
- g_free (catalog->name);
- g_free (catalog->language);
- g_free (catalog);
- glade_xml_context_free (context);
+ catalog_destroy (catalog);
return NULL;
}
- loaded_catalogs = g_list_prepend (loaded_catalogs, g_strdup (catalog->name));
+ catalog->library = glade_xml_get_property_string (root, GLADE_TAG_LIBRARY);
+ catalog->dep_catalog = glade_xml_get_property_string (root, GLADE_TAG_DEPENDS);
+ catalog->domain = glade_xml_get_property_string (root, GLADE_TAG_DOMAIN);
+ catalog->book = glade_xml_get_property_string (root, GLADE_TAG_BOOK);
+ catalog->icon_prefix = glade_xml_get_property_string (root, GLADE_TAG_ICON_PREFIX);
+ catalog->init_function_name = glade_xml_get_value_string (root, GLADE_TAG_INIT_FUNCTION);
- catalog->library =
- glade_xml_get_property_string (root, GLADE_TAG_LIBRARY);
- catalog->dep_catalog =
- glade_xml_get_property_string (root, GLADE_TAG_DEPENDS);
- catalog->domain =
- glade_xml_get_property_string (root, GLADE_TAG_DOMAIN);
- catalog->book =
- glade_xml_get_property_string (root, GLADE_TAG_BOOK);
- catalog->icon_prefix =
- glade_xml_get_property_string (root, GLADE_TAG_ICON_PREFIX);
- catalog->init_function_name =
- glade_xml_get_value_string (root, GLADE_TAG_INIT_FUNCTION);
-
-
/* catalog->icon_prefix defaults to catalog->name */
if (!catalog->icon_prefix)
catalog->icon_prefix = g_strdup (catalog->name);
@@ -289,9 +307,13 @@ catalog_load_library (GladeCatalog *catalog)
GModule *module;
if (modules == NULL)
- modules = g_hash_table_new (g_str_hash, g_str_equal);
+ modules = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) module_close);
- if (catalog->library == NULL) return NULL;
+ if (catalog->library == NULL)
+ return NULL;
if (catalog->language)
{
@@ -352,7 +374,7 @@ catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node)
GladeWidgetGroup *group;
GladeXmlNode *node;
- group = g_new0 (GladeWidgetGroup, 1);
+ group = g_slice_new0 (GladeWidgetGroup);
group->name = glade_xml_get_property_string (group_node,
GLADE_TAG_NAME);
@@ -360,8 +382,7 @@ catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node)
if (!group->name)
{
g_warning ("Required property 'name' not found in group node");
-
- widget_group_free (group);
+ widget_group_destroy (group);
return FALSE;
}
@@ -370,8 +391,7 @@ catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node)
if (!group->title)
{
g_warning ("Required property 'title' not found in group node");
-
- widget_group_free (group);
+ widget_group_destroy (group);
return FALSE;
}
@@ -426,25 +446,12 @@ catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node)
group->adaptors = g_list_reverse (group->adaptors);
- catalog->widget_groups = g_list_prepend (catalog->widget_groups,
- group);
+ catalog->widget_groups = g_list_prepend (catalog->widget_groups, group);
return TRUE;
}
-static void
-widget_group_free (GladeWidgetGroup *group)
-{
- g_return_if_fail (group != NULL);
-
- g_free (group->name);
- g_free (group->title);
-
- /* The actual widget classes will be free elsewhere */
- g_list_free (group->adaptors);
-}
-
-GList *
+const GList *
glade_catalog_load_all (void)
{
GDir *dir;
@@ -485,6 +492,7 @@ glade_catalog_load_all (void)
g_warning ("Unable to open the catalog file %s.\n",
filename);
}
+ g_dir_close (dir);
/* After sorting, execute init function and then load */
catalogs = catalog_sort (catalogs);
@@ -492,7 +500,8 @@ glade_catalog_load_all (void)
for (l = catalogs; l; l = l->next)
{
catalog = l->data;
- if (catalog->init_function) catalog->init_function ();
+ if (catalog->init_function)
+ catalog->init_function ();
}
for (l = catalogs; l; l = l->next)
@@ -501,8 +510,9 @@ glade_catalog_load_all (void)
catalog_load (catalog);
}
- g_dir_close (dir);
- return catalogs;
+ loaded_catalogs = catalogs;
+
+ return loaded_catalogs;
}
const gchar *
@@ -529,34 +539,83 @@ glade_catalog_get_adaptors (GladeCatalog *catalog)
return catalog->adaptors;
}
-void
-glade_catalog_free (GladeCatalog *catalog)
+gboolean
+glade_catalog_is_loaded (const gchar *name)
{
- GList *list;
+ GList *l;
+
+ g_return_val_if_fail (name != NULL, FALSE);
+ g_assert (loaded_catalogs != NULL);
+
+ for (l = loaded_catalogs; l; l = l->next)
+ {
+ GladeCatalog *catalog = GLADE_CATALOG (l->data);
+ if (strcmp (catalog->name, name) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
- if (catalog == NULL)
- return;
+static void
+catalog_destroy (GladeCatalog *catalog)
+{
+ g_return_if_fail (GLADE_IS_CATALOG (catalog));
g_free (catalog->name);
- if (catalog->book)
- g_free (catalog->book);
-
- if (catalog->icon_prefix)
- g_free (catalog->icon_prefix);
-
- for (list = catalog->adaptors; list; list = list->next)
- g_object_unref (list->data);
-
- g_list_free (catalog->adaptors);
+ g_free (catalog->language);
+ g_free (catalog->library);
+ g_free (catalog->dep_catalog);
+ g_free (catalog->domain);
+ g_free (catalog->book);
+ g_free (catalog->icon_prefix);
+ g_free (catalog->init_function_name);
+
+ if (catalog->adaptors)
+ {
+ /* TODO: free adaptors */
+ g_list_free (catalog->adaptors);
+ }
+
+ if (catalog->widget_groups)
+ {
+ g_list_foreach (catalog->widget_groups, (GFunc) widget_group_destroy, NULL);
+ g_list_free (catalog->widget_groups);
+ }
+
+ if (catalog->context)
+ glade_xml_context_free (catalog->context);
+
+ g_slice_free (GladeCatalog, catalog);
+}
- for (list = catalog->widget_groups; list; list = list->next)
- widget_group_free (GLADE_WIDGET_GROUP (list->data));
-
- g_list_free (catalog->widget_groups);
-
+static void
+module_close (GModule *module)
+{
+ g_module_close (module);
+}
+
+void
+glade_catalog_destroy_all (void)
+{
+ /* close catalogs */
+ if (loaded_catalogs)
+ {
+ GList *l;
+ for (l = loaded_catalogs; l; l = l->next)
+ catalog_destroy (GLADE_CATALOG (l->data));
+ g_list_free (loaded_catalogs);
+ loaded_catalogs = NULL;
+ }
- g_free (catalog);
+ /* close plugin modules */
+ if (modules)
+ {
+ g_hash_table_destroy (modules);
+ modules = NULL;
+ }
}
+
const gchar *
glade_widget_group_get_name (GladeWidgetGroup *group)
{
@@ -581,7 +640,7 @@ glade_widget_group_get_expanded (GladeWidgetGroup *group)
return group->expanded;
}
-GList *
+const GList *
glade_widget_group_get_adaptors (GladeWidgetGroup *group)
{
g_return_val_if_fail (group != NULL, NULL);
@@ -589,37 +648,16 @@ glade_widget_group_get_adaptors (GladeWidgetGroup *group)
return group->adaptors;
}
-gboolean
-glade_catalog_is_loaded (const gchar *name)
+static void
+widget_group_destroy (GladeWidgetGroup *group)
{
- GList *l;
- g_return_val_if_fail (name != NULL, FALSE);
- for (l = loaded_catalogs; l; l = l->next)
- if (!strcmp (name, (gchar *)l->data))
- return TRUE;
- return FALSE;
-}
-
+ g_return_if_fail (GLADE_IS_WIDGET_GROUP (group));
+
+ g_free (group->name);
+ g_free (group->title);
+ g_list_free (group->adaptors);
-static void
-catalog_module_close (gpointer key, gpointer value, gpointer user_data)
-{
- g_module_close (value);
- g_free (key);
+ g_slice_free (GladeWidgetGroup, group);
}
+
-/**
- * glade_catalog_modules_close:
- *
- * Close every opened module.
- *
- */
-void
-glade_catalog_modules_close ()
-{
- if (modules == NULL) return;
-
- g_hash_table_foreach (modules, catalog_module_close, NULL);
- g_hash_table_destroy (modules);
- modules = NULL;
-}
diff --git a/gladeui/glade-catalog.h b/gladeui/glade-catalog.h
index b708291f..c8caf81d 100644
--- a/gladeui/glade-catalog.h
+++ b/gladeui/glade-catalog.h
@@ -2,6 +2,7 @@
/*
* Copyright (C) 2001 Ximian, Inc.
* Copyright (C) 2004 Imendio AB
+ * Copyright (C) 2007 The GNOME Foundation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -21,46 +22,41 @@
#ifndef __GLADE_CATALOG_H__
#define __GLADE_CATALOG_H__
+#include <glib.h>
+
G_BEGIN_DECLS
-#define GLADE_CATALOG(c) ((GladeCatalog *) c)
+#define GLADE_CATALOG(c) ((GladeCatalog *) c)
#define GLADE_IS_CATALOG(c) (c != NULL)
-#define GLADE_WIDGET_GROUP(x) ((GladeWidgetGroup *) x)
-
-typedef struct _GladeCatalog GladeCatalog;
-typedef struct _GladeWidgetGroup GladeWidgetGroup;
-
+typedef struct _GladeCatalog GladeCatalog;
+#define GLADE_WIDGET_GROUP(g) ((GladeWidgetGroup *) g)
+#define GLADE_IS_WIDGET_GROUP(g) (g != NULL)
-GList * glade_catalog_load_all (void);
+typedef struct _GladeWidgetGroup GladeWidgetGroup;
-const gchar * glade_catalog_get_name (GladeCatalog *catalog);
+const GList *glade_catalog_load_all (void);
+const gchar *glade_catalog_get_name (GladeCatalog *catalog);
-GList * glade_catalog_get_widget_groups (GladeCatalog *catalog);
+GList *glade_catalog_get_widget_groups (GladeCatalog *catalog);
-GList * glade_catalog_get_adaptors (GladeCatalog *catalog);
+GList *glade_catalog_get_adaptors (GladeCatalog *catalog);
+gboolean glade_catalog_is_loaded (const gchar *name);
-void glade_catalog_free (GladeCatalog *catalog);
+void glade_catalog_destroy_all (void);
-const gchar * glade_widget_group_get_name (GladeWidgetGroup *group);
+const gchar *glade_widget_group_get_name (GladeWidgetGroup *group);
-const gchar * glade_widget_group_get_title (GladeWidgetGroup *group);
+const gchar *glade_widget_group_get_title (GladeWidgetGroup *group);
gboolean glade_widget_group_get_expanded (GladeWidgetGroup *group);
-GList * glade_widget_group_get_adaptors (GladeWidgetGroup *group);
-
-
-void glade_widget_group_free (GladeWidgetGroup *group);
-
-gboolean glade_catalog_is_loaded (const gchar *name);
-
-void glade_catalog_modules_close (void);
+const GList *glade_widget_group_get_adaptors (GladeWidgetGroup *group);
G_END_DECLS
diff --git a/gladeui/glade-palette.c b/gladeui/glade-palette.c
index f8f3e8fc..05207488 100644
--- a/gladeui/glade-palette.c
+++ b/gladeui/glade-palette.c
@@ -484,7 +484,7 @@ glade_palette_new_item_group (GladePalette *palette, GladeWidgetGroup *group)
box = glade_palette_box_new ();
/* Go through all the widget classes in this catalog. */
- for (l = glade_widget_group_get_adaptors (group); l; l = l->next)
+ for (l = (GList *) glade_widget_group_get_adaptors (group); l; l = l->next)
{
GladeWidgetAdaptor *adaptor = GLADE_WIDGET_ADAPTOR (l->data);