Commit 68308571 authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

o manage all GModules with a hash table. o added

* src/glade-catalog.[ch]:
  o manage all GModules with a hash table.
  o added glade_catalog_modules_close()

* src/glade-app.c:
  o call glade_catalog_modules_close() when the app finalize.
  o removed unnecesary headers.
* src/glade-gnome.c: fixed some warnings.

* src/glade-utils.c: slight optimization in function
  glade_util_get_type_from_name (), check if type is already registered.

* src/glade.h: removed unneeded #ifdef GLADE_H check.

* src/glade-widget-adaptor.[ch]:
  o removed module member from GladeWidgetAdaptorPriv since now we keep
    all the openned modules inside glade-catalog.c
  o added glade_abort_if_derived_adaptors_exist().
parent 8d0cbc8e
2006-11-09 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* src/glade-catalog.[ch]:
o manage all GModules with a hash table.
o added glade_catalog_modules_close()
* src/glade-app.c:
o call glade_catalog_modules_close() when the app finalize.
o removed unnecesary headers.
* src/glade-gnome.c: fixed some warnings.
* src/glade-utils.c: slight optimization in function
glade_util_get_type_from_name (), check if type is already registered.
* src/glade.h: removed unneeded #ifdef GLADE_H check.
* src/glade-widget-adaptor.[ch]:
o removed module member from GladeWidgetAdaptorPriv since now we keep
all the openned modules inside glade-catalog.c
o added glade_abort_if_derived_adaptors_exist().
2006-10-27 Tristan Van Berkom <tvb@gnome.org>
* NEWS: Rolling 3.1.0
......
......@@ -30,22 +30,10 @@
#include <glib/gi18n-lib.h>
#include "glade.h"
#include "glade-palette.h"
#include "glade-editor.h"
#include "glade-clipboard.h"
#include "glade-clipboard-view.h"
#include "glade-widget.h"
#include "glade-property.h"
#include "glade-property-class.h"
#include "glade-project.h"
#include "glade-project-view.h"
#include "glade-placeholder.h"
#include "glade-command.h"
#include "glade-debug.h"
#include "glade-utils.h"
#include "glade-cursor.h"
#include "glade-catalog.h"
#include "glade-app.h"
#include "glade-paths.h"
#include "glade-fixed.h"
......@@ -168,6 +156,7 @@ glade_app_finalize (GObject *app)
g_free (glade_locale_dir);
g_free (glade_icon_dir);
#endif
glade_catalog_modules_close ();
g_free (GLADE_APP (app)->priv);
if (parent_class->finalize)
......@@ -755,7 +744,7 @@ glade_app_get_project_by_path (const gchar *project_path)
GList *l;
gchar *canonical_path;
if (project_path == NULL) return FALSE;
if (project_path == NULL) return NULL;
app = glade_app_get ();
......
......@@ -254,11 +254,35 @@ catalog_sort (GList *catalogs)
return sorted;
}
static GHashTable *modules = NULL;
static GModule *
catalog_load_library (GladeCatalog *catalog)
{
GModule *module;
if (modules == NULL)
modules = g_hash_table_new (g_str_hash, g_str_equal);
if (catalog->library == NULL) return NULL;
if ((module = g_hash_table_lookup (modules, catalog->library)))
return module;
if ((module = glade_util_load_library (catalog->library)))
g_hash_table_insert (modules, g_strdup (catalog->library), module);
else
g_warning ("Failed to load external library '%s'",
catalog->library);
return module;
}
static gboolean
catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node)
{
GladeXmlNode *node;
GModule *module = catalog_load_library (catalog);
node = glade_xml_node_get_children (widgets_node);
for (; node; node = glade_xml_node_next (node))
......@@ -271,7 +295,7 @@ catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node)
continue;
adaptor = glade_widget_adaptor_from_catalog
(node, catalog->name, catalog->library,
(node, catalog->name, module,
catalog->domain ? catalog->domain : catalog->library,
catalog->book);
......@@ -531,3 +555,27 @@ glade_catalog_is_loaded (const gchar *name)
return TRUE;
return FALSE;
}
static void
catalog_module_close (gpointer key, gpointer value, gpointer user_data)
{
g_module_close (value);
g_free (key);
}
/**
* 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;
}
......@@ -61,6 +61,9 @@ void glade_widget_group_free (GladeWidgetGroup *group);
LIBGLADEUI_API
gboolean glade_catalog_is_loaded (const gchar *name);
LIBGLADEUI_API
void glade_catalog_modules_close (void);
G_END_DECLS
#endif /* __GLADE_CATALOG_H__ */
......@@ -517,8 +517,8 @@ glade_gnome_druid_set_child_property (GladeWidgetAdaptor *adaptor,
/* Chain Up */
GWA_GET_CLASS
(GTK_TYPE_CONTAINER)->child_set_property (adaptor,
GTK_CONTAINER (container),
GTK_WIDGET (child),
container,
child,
property_name,
value);
}
......@@ -541,8 +541,8 @@ glade_gnome_druid_get_child_property (GladeWidgetAdaptor *adaptor,
/* Chain Up */
GWA_GET_CLASS
(GTK_TYPE_CONTAINER)->child_get_property (adaptor,
GTK_CONTAINER (container),
GTK_WIDGET (child),
container,
child,
property_name,
value);
}
......
......@@ -139,8 +139,9 @@ glade_util_get_type_from_name (const gchar *name)
GType (*get_type) ();
GType type = 0;
gchar *func_name;
if ((func_name = glade_util_compose_get_type_func (name)) != NULL)
if ((type = g_type_from_name (name)) == 0 &&
(func_name = glade_util_compose_get_type_func (name)) != NULL)
{
if (!allsymbols)
......@@ -151,17 +152,17 @@ glade_util_get_type_from_name (const gchar *name)
{
g_assert (get_type);
type = get_type ();
} else {
}
else
{
g_warning (_("We could not find the symbol \"%s\""),
func_name);
}
g_free (func_name);
}
if (type == 0) {
g_warning(_("Could not get the type from \"%s"),
name);
}
if (type == 0)
g_warning(_("Could not get the type from \"%s\""), name);
return type;
}
......
......@@ -55,13 +55,6 @@ struct _GladeWidgetAdaptorPriv {
GdkCursor *cursor; /* a cursor for inserting widgets */
GModule *module; /* Module with the (optional) special functions
* needed for placeholder_replace, post_create_function
* and the set & get functions of the properties
* of this class.
*/
gchar *special_child_type; /* Special case code for children that
* are special children (like notebook tab
* widgets for example).
......@@ -301,6 +294,36 @@ gwa_gtype_hash (gconstpointer v)
return *(const GType*) v;
}
static gboolean
glade_widget_adaptor_hash_find (gpointer key, gpointer value, gpointer user_data)
{
GladeWidgetAdaptor *adaptor = value;
GType *type = user_data;
if (g_type_is_a (adaptor->type, *type))
{
*type = adaptor->type;
return TRUE;
}
return FALSE;
}
static void
glade_abort_if_derived_adaptors_exist (GType type)
{
if (adaptor_hash)
{
GType retval = type;
g_hash_table_find (adaptor_hash,
glade_widget_adaptor_hash_find,
&retval);
if (retval != type)
g_error (_("A derived adaptor (%s) of %s already exist!"),
g_type_name (retval), g_type_name (type));
}
}
/*******************************************************************************
Base Object Implementation detail
......@@ -539,6 +562,8 @@ glade_widget_adaptor_constructor (GType type,
GladeWidgetAdaptor *adaptor;
GObject *ret_obj;
glade_abort_if_derived_adaptors_exist (type);
ret_obj = G_OBJECT_CLASS (parent_class)->constructor
(type, n_construct_properties, construct_properties);
......@@ -608,11 +633,6 @@ glade_widget_adaptor_finalize (GObject *object)
if (adaptor->priv->special_child_type)
g_free (adaptor->priv->special_child_type);
if (adaptor->priv->module)
if (!g_module_close (adaptor->priv->module))
g_warning ("Module error while finalizing adaptor %s (%s)\n",
adaptor->name, g_module_error());
if (adaptor->priv->cursor != NULL)
gdk_cursor_unref (adaptor->priv->cursor);
......@@ -1047,6 +1067,7 @@ gwa_set_packing_defaults_from_node (GladeWidgetAdaptor *adaptor,
static void
gwa_update_properties_from_node (GladeWidgetAdaptor *adaptor,
GladeXmlNode *node,
GModule *module,
GList **properties,
const gchar *domain)
{
......@@ -1093,7 +1114,7 @@ gwa_update_properties_from_node (GladeWidgetAdaptor *adaptor,
}
if ((updated = glade_property_class_update_from_node
(child, adaptor->priv->module, adaptor->type,
(child, module, adaptor->type,
&property_class, domain)) == FALSE)
{
g_warning ("failed to update %s property of %s from xml",
......@@ -1114,47 +1135,48 @@ gwa_update_properties_from_node (GladeWidgetAdaptor *adaptor,
static gboolean
gwa_extend_with_node (GladeWidgetAdaptor *adaptor,
GladeXmlNode *node,
GModule *module,
const gchar *domain)
{
GladeWidgetAdaptorClass *adaptor_class =
GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor);
GladeXmlNode *child;
if (adaptor->priv->module)
if (module)
{
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_POST_CREATE_FUNCTION,
(gpointer *)&adaptor_class->post_create);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_GET_INTERNAL_CHILD_FUNCTION,
(gpointer *)&adaptor_class->get_internal_child);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_LAUNCH_EDITOR_FUNCTION,
(gpointer *)&adaptor_class->launch_editor);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_ADD_CHILD_FUNCTION,
(gpointer *)&adaptor_class->add);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_REMOVE_CHILD_FUNCTION,
(gpointer *)&adaptor_class->remove);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_GET_CHILDREN_FUNCTION,
(gpointer *)&adaptor_class->get_children);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_CHILD_SET_PROP_FUNCTION,
(gpointer *)&adaptor_class->child_set_property);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_CHILD_GET_PROP_FUNCTION,
(gpointer *)&adaptor_class->child_get_property);
glade_xml_load_sym_from_node (node, adaptor->priv->module,
glade_xml_load_sym_from_node (node, module,
GLADE_TAG_REPLACE_CHILD_FUNCTION,
(gpointer *)&adaptor_class->replace_child);
......@@ -1174,12 +1196,12 @@ gwa_extend_with_node (GladeWidgetAdaptor *adaptor,
if ((child =
glade_xml_search_child (node, GLADE_TAG_PROPERTIES)) != NULL)
gwa_update_properties_from_node
(adaptor, child, &adaptor->properties, domain);
(adaptor, child, module, &adaptor->properties, domain);
if ((child =
glade_xml_search_child (node, GLADE_TAG_PACKING_PROPERTIES)) != NULL)
gwa_update_properties_from_node
(adaptor, child, &adaptor->packing_props, domain);
(adaptor, child, module, &adaptor->packing_props, domain);
if ((child =
glade_xml_search_child (node, GLADE_TAG_PACKING_DEFAULTS)) != NULL)
......@@ -1206,13 +1228,12 @@ gwa_extend_with_node (GladeWidgetAdaptor *adaptor,
GladeWidgetAdaptor *
glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
const gchar *catname,
const gchar *library,
GModule *module,
const gchar *domain,
const gchar *book)
{
GladeWidgetAdaptor *adaptor = NULL;
gchar *name, *generic_name;
GModule *module = NULL;
GType object_type, adaptor_type, parent_type;
if (!glade_xml_node_verify (class_node, GLADE_TAG_GLADE_WIDGET_CLASS))
......@@ -1226,18 +1247,6 @@ glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
(class_node, GLADE_TAG_NAME, NULL)) == NULL)
return NULL;
if (library)
{
module = glade_util_load_library (library);
if (!module)
{
g_warning ("Failed to load external library '%s'",
library);
g_free (name);
return NULL;
}
}
if ((object_type = glade_util_get_type_from_name (name)) == 0)
{
g_warning ("Failed to load the GType for '%s'", name);
......@@ -1261,8 +1270,6 @@ glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
NULL);
if (generic_name)
g_free (generic_name);
adaptor->priv->module = module;
if ((adaptor->title = glade_xml_get_property_string_required
(class_node, GLADE_TAG_TITLE,
......@@ -1299,7 +1306,7 @@ glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
if (book)
adaptor->priv->book = g_strdup (book);
gwa_extend_with_node (adaptor, class_node, domain);
gwa_extend_with_node (adaptor, class_node, module, domain);
/* Set default weight on properties */
for (parent_type = adaptor->type;
......@@ -1313,9 +1320,6 @@ glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
glade_widget_adaptor_register (adaptor);
return adaptor;
}
/**
......
......@@ -311,7 +311,7 @@ GType glade_widget_adaptor_get_type (void) G_GNUC_CONST;
LIBGLADEUI_API
GladeWidgetAdaptor *glade_widget_adaptor_from_catalog (GladeXmlNode *class_node,
const gchar *catname,
const gchar *library,
GModule *module,
const gchar *domain,
const gchar *book);
LIBGLADEUI_API
......
......@@ -22,10 +22,6 @@
# define LIBGLADEUI_API extern
#endif
#ifdef GLADE_H
# error libglade included with libgladeui is not compatible
#endif
/* Circular header dependancie are fixed here with forward
* declarations.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment