Commit 7342e79c authored by Joaquín Cuenca Abela's avatar Joaquín Cuenca Abela
Browse files

read the name of the plugin to be used by each catalog and pass it to the

	* src/glade-catalog.c: read the name of the plugin to be used by each
	catalog and pass it to the constructor of glade-widget-class.  Also
	if a specific class has a specific plugin name to be used, use it instead
	of the generic of the whole catalog.
	* src/glade-gtk.c: remove the "static" from the functions that should
	be exported, and remove the "temp hack" that was used to load the
	address of the functions, as it's no more needed.
	* src/glade-property-class.c: remove glade_property_class_get_{get,set}_function
	and use g_module_symbol instead.
	* src/glade-widget-class.c: use g_module_symbol instead of the previous {get,set}
	functions.  Remove unused functions.  Rename glade_widget_class_new_from_name2
	to glade_widget_class_new as it's the only constructor.  Use the plugin
	name that glade-widget-class passed to the constructor and load it.
	* src/glade-widget-class.h: add a GModule* by GladeWidgetClass.
	* src/glade-widget.c: remove the #include <glade-gtk.h>
	* widgets/gtk-additional.xml: add the name of the plugin ("gtk") for all the
	widgets on gtk-additional.
	* widgets/gtk-base.xml: ditto
	* widgets/gtkwidget.xml: remove the "name" tag, as it's not need.
	* widgets/gtkwindow.xml: change glade_gtk_widget_{get,set}_tooltip by "ignore",
	as that's what these functions do.
parent 8f8dd5f0
2003-10-04 Joaquin Cuenca Abela <e98cuenc@yahoo.com>
* src/glade-catalog.c: read the name of the plugin to be used by each
catalog and pass it to the constructor of glade-widget-class. Also
if a specific class has a specific plugin name to be used, use it instead
of the generic of the whole catalog.
* src/glade-gtk.c: remove the "static" from the functions that should
be exported, and remove the "temp hack" that was used to load the
address of the functions, as it's no more needed.
* src/glade-property-class.c: remove glade_property_class_get_{get,set}_function
and use g_module_symbol instead.
* src/glade-widget-class.c: use g_module_symbol instead of the previous {get,set}
functions. Remove unused functions. Rename glade_widget_class_new_from_name2
to glade_widget_class_new as it's the only constructor. Use the plugin
name that glade-widget-class passed to the constructor and load it.
* src/glade-widget-class.h: add a GModule* by GladeWidgetClass.
* src/glade-widget.c: remove the #include <glade-gtk.h>
* widgets/gtk-additional.xml: add the name of the plugin ("gtk") for all the
widgets on gtk-additional.
* widgets/gtk-base.xml: ditto
* widgets/gtkwidget.xml: remove the "name" tag, as it's not need.
* widgets/gtkwindow.xml: change glade_gtk_widget_{get,set}_tooltip by "ignore",
as that's what these functions do.
2003-09-02 Paolo Borelli <pborelli@katamail.com>
* src/glade.h: add the internal child tag.
......
......@@ -15,4 +15,5 @@
#undef PIXMAPS_DIR
#undef WIDGETS_DIR
#undef CATALOGS_DIR
#undef MODULES_DIR
#undef GETTEXT_PACKAGE
......@@ -2,7 +2,8 @@
#define CONFIG_H__
#define PIXMAPS_DIR "./pixmaps"
#define CATALOGS_DIR "./catalog"
#define CATALOGS_DIR "./catalog"
#define WIDGETS_DIR "./widgets"
#define MODULES_DIR "./modules"
#endif
......@@ -12,13 +12,14 @@ AC_PROG_INTLTOOL([0.11])
GNOME_COMMON_INIT
GNOME_PLATFORM_GNOME_2(yes, force)
AM_PROG_LIBTOOL
AC_ISC_POSIX
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL
AC_CHECK_HEADERS(os2.h)
dnl ================================================================
......@@ -77,9 +78,19 @@ else
catalogsdir="${prefix}/${DATADIRNAME}/${PACKAGE}-${VERSION}/catalogs"
fi
dnl ================================================================
dnl MODULES
dnl ================================================================
if test "x${libdir}" = "xNONE"; then
modulesdir="${ac_default_libdir}/${PACKAGE}"
else
modulesdir="${libdir}/${PACKAGE}"
fi
AC_SUBST(pixmapsdir)
AC_SUBST(widgetsdir)
AC_SUBST(catalogsdir)
AC_SUBST(modulesdir)
AC_OUTPUT([
Makefile
......
......@@ -3,6 +3,12 @@ SUBDIRS=
bin_PROGRAMS = glade-3
gladegtk_LTLIBRARIES = libgladegtk.la
gladegtkdir = $(modulesdir)
libgladegtk_la_SOURCES = glade-gtk.c
libgladegtk_la_LDFLAGS = -module -avoid-version
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
......@@ -13,6 +19,7 @@ INCLUDES = \
-DGLADE_ICONDIR=\""$(datadir)/pixmaps"\" \
-DGLADE_LOCALSTATEDIR=\""$(localstatedir)"\" \
-DGLADE_LOCALEDIR=\""$(datadir)/locale"\" \
-DMODULES_DIR=\""@modulesdir@"\" \
-DG_LOG_DOMAIN=\"Glade\"
CFLAGS = -g -O2 -Wall
......@@ -39,7 +46,6 @@ glade_3_SOURCES = \
glade-catalog.c \
glade-choice.c \
glade-editor.c \
glade-gtk.c \
glade-utils.c \
glade-signal.c \
glade-signal-editor.c \
......@@ -69,7 +75,6 @@ noinst_HEADERS = \
glade-property-class.h \
glade-popup.h \
glade-choice.h \
glade-gtk.h \
glade-catalog.h \
glade-utils.h \
glade-signal.h \
......
......@@ -37,7 +37,6 @@
#define GLADE_TAG_PALETTE "GladePalette"
static GList *glade_catalog_list = NULL; /* A list of GladeCatalog items */
static GList *widget_class_list = NULL; /* A list of all the GladeWidgetClass objects loaded */
GList *
......@@ -80,12 +79,14 @@ glade_catalog_load (const char *base_catalog_filename)
char *generic_name = NULL;
char *catalog_filename = NULL;
char *base_filename = NULL;
char *partial_library = NULL;
char *base_library = NULL;
GList *last_widget_class = NULL;
catalog_filename = g_strdup_printf ("%s%c%s", CATALOGS_DIR, G_DIR_SEPARATOR, base_catalog_filename);
if (catalog_filename == NULL)
{
g_critical ("Not enough memory.");
g_critical (_("Not enough memory."));
goto lblError;
}
......@@ -93,7 +94,7 @@ glade_catalog_load (const char *base_catalog_filename)
context = glade_xml_context_new_from_path (catalog_filename, NULL, GLADE_TAG_CATALOG);
if (context == NULL)
{
g_warning ("Impossible to open the catalog [%s].", catalog_filename);
g_warning (_("Impossible to open the catalog [%s]."), catalog_filename);
goto lblError;
}
......@@ -104,7 +105,7 @@ glade_catalog_load (const char *base_catalog_filename)
catalog = g_new0 (GladeCatalog, 1);
if (catalog == NULL)
{
g_critical ("Not enough memory.");
g_critical (_("Not enough memory."));
goto lblError;
}
......@@ -115,14 +116,29 @@ glade_catalog_load (const char *base_catalog_filename)
if (!glade_xml_node_verify (root, GLADE_TAG_CATALOG))
{
g_warning ("The root node of [%s] has a name different from %s.", catalog_filename, GLADE_TAG_CATALOG);
g_warning (_("The root node of [%s] has a name different from %s."), catalog_filename, GLADE_TAG_CATALOG);
goto lblError;
}
/* get the library to be used by this catalog (if any) */
partial_library = glade_xml_get_property_string (root, "library");
if (partial_library && *partial_library)
{
base_library = g_strdup_printf ("libglade%s", partial_library);
if (!base_library)
{
g_critical (_("Not enough memory."));
goto lblError;
}
}
/* build all the GladeWidgetClass'es associated with this catalog */
widget_node = glade_xml_node_get_children (root);
for (; widget_node != NULL; widget_node = glade_xml_node_next (widget_node))
{
char *partial_widget_class_library = NULL;
char *base_widget_class_library = NULL;
if (!glade_xml_node_verify (widget_node, GLADE_TAG_GLADE_WIDGET))
continue;
......@@ -130,10 +146,23 @@ glade_catalog_load (const char *base_catalog_filename)
if (name == NULL)
continue;
/* get the specific library to the widget class, if any */
partial_widget_class_library = glade_xml_get_property_string (widget_node, "library");
if (partial_widget_class_library && *partial_widget_class_library)
{
base_widget_class_library = g_strdup_printf ("libglade%s", partial_widget_class_library);
if (!base_widget_class_library)
{
g_critical (_("Not enough memory."));
continue;
}
}
generic_name = glade_xml_get_property_string (widget_node, "generic_name");
base_filename = glade_xml_get_property_string (widget_node, "filename");
widget_class = glade_widget_class_new_from_name2 (name, generic_name, base_filename);
widget_class = glade_widget_class_new (name, generic_name, base_filename,
base_widget_class_library ? base_widget_class_library : base_library);
if (widget_class)
{
last_widget_class = g_list_append (last_widget_class, widget_class);
......@@ -147,6 +176,8 @@ glade_catalog_load (const char *base_catalog_filename)
g_free (name);
g_free (generic_name);
g_free (base_filename);
g_free (partial_widget_class_library);
g_free (base_widget_class_library);
}
glade_xml_context_free (context);
......@@ -157,6 +188,8 @@ lblError:
glade_xml_context_free (context);
g_free (catalog_filename);
g_free (catalog);
g_free (partial_library);
g_free (base_library);
return NULL;
}
......
......@@ -34,7 +34,7 @@
#include "glade-command.h"
static void
void
glade_gtk_entry_set_text (GObject *object, GValue *value)
{
GtkEditable *editable = GTK_EDITABLE (object);
......@@ -54,7 +54,7 @@ glade_gtk_entry_set_text (GObject *object, GValue *value)
gtk_editable_set_position (editable, pos);
}
static void
void
glade_gtk_entry_get_text (GObject *object, GValue *value)
{
GtkEntry *entry = GTK_ENTRY (object);
......@@ -68,7 +68,7 @@ glade_gtk_entry_get_text (GObject *object, GValue *value)
g_value_set_string (value, text);
}
static void
void
glade_gtk_option_menu_set_items (GObject *object, GValue *value)
{
GtkOptionMenu *option_menu;
......@@ -107,7 +107,7 @@ glade_gtk_option_menu_set_items (GObject *object, GValue *value)
}
static void
void
glade_gtk_progress_bar_set_format (GObject *object, GValue *value)
{
GtkProgressBar *bar;
......@@ -119,7 +119,7 @@ glade_gtk_progress_bar_set_format (GObject *object, GValue *value)
gtk_progress_set_format_string (GTK_PROGRESS (bar), format);
}
static void
void
glade_gtk_spin_button_set_max (GObject *object, GValue *value)
{
GtkAdjustment *adjustment;
......@@ -131,7 +131,7 @@ glade_gtk_spin_button_set_max (GObject *object, GValue *value)
}
static void
void
glade_gtk_spin_button_set_min (GObject *object, GValue *value)
{
GtkAdjustment *adjustment;
......@@ -142,7 +142,7 @@ glade_gtk_spin_button_set_min (GObject *object, GValue *value)
gtk_adjustment_changed (adjustment);
}
static void
void
glade_gtk_spin_button_set_step_increment (GObject *object, GValue *value)
{
GtkAdjustment *adjustment;
......@@ -153,7 +153,7 @@ glade_gtk_spin_button_set_step_increment (GObject *object, GValue *value)
gtk_adjustment_changed (adjustment);
}
static void
void
glade_gtk_spin_button_set_page_increment (GObject *object, GValue *value)
{
GtkAdjustment *adjustment;
......@@ -164,7 +164,7 @@ glade_gtk_spin_button_set_page_increment (GObject *object, GValue *value)
gtk_adjustment_changed (adjustment);
}
static void
void
glade_gtk_spin_button_set_page_size (GObject *object, GValue *value)
{
GtkAdjustment *adjustment;
......@@ -176,7 +176,7 @@ glade_gtk_spin_button_set_page_size (GObject *object, GValue *value)
}
static void
void
glade_gtk_box_get_size (GObject *object, GValue *value)
{
GtkBox *box;
......@@ -189,7 +189,7 @@ glade_gtk_box_get_size (GObject *object, GValue *value)
g_value_set_int (value, g_list_length (box->children));
}
static void
void
glade_gtk_box_set_size (GObject *object, GValue *value)
{
GladeWidget *widget;
......@@ -238,7 +238,7 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
g_object_set_data (object, "glade_nb_placeholders", GINT_TO_POINTER (new_size));
}
static void
void
glade_gtk_notebook_get_n_pages (GObject *object, GValue *value)
{
GtkNotebook *notebook;
......@@ -251,7 +251,7 @@ glade_gtk_notebook_get_n_pages (GObject *object, GValue *value)
g_value_set_int (value, g_list_length (notebook->children));
}
static void
void
glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
{
GladeWidget *widget;
......@@ -310,7 +310,7 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
#if 0
/* This code is working but i don't think we need it. Chema */
static void
void
glade_gtk_table_get_n_rows (GObject *object, GValue *value)
{
GtkTable *table;
......@@ -323,7 +323,7 @@ glade_gtk_table_get_n_rows (GObject *object, GValue *value)
g_value_set_int (value, table->nrows);
}
static void
void
glade_gtk_table_get_n_columns (GObject *object, GValue *value)
{
GtkTable *table;
......@@ -337,7 +337,7 @@ glade_gtk_table_get_n_columns (GObject *object, GValue *value)
}
#endif
static void
void
glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows)
{
GladeWidget *widget;
......@@ -408,19 +408,19 @@ glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows)
g_object_set_data (object, "glade_nb_placeholders", GINT_TO_POINTER (new_size * (for_rows ? table->ncols : table->nrows)));
}
static void
void
glade_gtk_table_set_n_rows (GObject *object, GValue *value)
{
glade_gtk_table_set_n_common (object, value, TRUE);
}
static void
void
glade_gtk_table_set_n_columns (GObject *object, GValue *value)
{
glade_gtk_table_set_n_common (object, value, FALSE);
}
static void
void
glade_gtk_button_set_stock (GObject *object, GValue *value)
{
GladeWidget *glade_widget;
......@@ -486,14 +486,19 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
}
}
static void
void
empty (GObject *object, GValue *value)
{
}
void
ignore (GObject *object, GValue *value)
{
}
/* ------------------------------------ Post Create functions ------------------------------ */
static void
void
glade_gtk_window_post_create (GObject *object, GValue *not_used)
{
GtkWindow *window = GTK_WINDOW (object);
......@@ -503,7 +508,7 @@ glade_gtk_window_post_create (GObject *object, GValue *not_used)
gtk_window_set_default_size (window, 440, 250);
}
static void
void
glade_gtk_dialog_post_create (GObject *object, GValue *not_used)
{
GtkDialog *dialog = GTK_DIALOG (object);
......@@ -513,7 +518,7 @@ glade_gtk_dialog_post_create (GObject *object, GValue *not_used)
gtk_window_set_default_size (GTK_WINDOW (dialog), 320, 260);
}
static void
void
glade_gtk_message_dialog_post_create (GObject *object, GValue *not_used)
{
GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
......@@ -523,7 +528,7 @@ glade_gtk_message_dialog_post_create (GObject *object, GValue *not_used)
gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 115);
}
static void
void
glade_gtk_check_button_post_create (GObject *object, GValue *not_used)
{
GtkCheckButton *button = GTK_CHECK_BUTTON (object);
......@@ -538,7 +543,7 @@ glade_gtk_check_button_post_create (GObject *object, GValue *not_used)
}
static void
void
glade_gtk_table_post_create (GObject *object, GValue *value)
{
GtkTable *table = GTK_TABLE (object);
......@@ -561,94 +566,3 @@ glade_gtk_table_post_create (GObject *object, GValue *value)
}
}
/* ================ Temp hack =================== */
/* We have this table, but what we should do is use gmodule for this,
* however this requires that we link with libtool cause right now
* we are loosing the symbols. Chema
*/
typedef struct _GladeGtkFunction GladeGtkFunction;
struct _GladeGtkFunction {
const gchar *name;
void (* function) (GObject *object, GValue *value);
};
#define GLADE_NEW_FUNCTION(name) {#name, name}
#define GLADE_NEW_EMPTY_FUNCTION(name) {#name, empty}
GladeGtkFunction functions [] = {
GLADE_NEW_FUNCTION(glade_gtk_entry_get_text),
GLADE_NEW_FUNCTION(glade_gtk_box_get_size),
GLADE_NEW_EMPTY_FUNCTION(glade_gtk_widget_get_tooltip),
GLADE_NEW_FUNCTION(glade_gtk_button_set_stock),
#if 0
GLADE_NEW_FUNCTION(glade_gtk_table_get_n_rows),
GLADE_NEW_FUNCTION(glade_gtk_table_get_n_columns),
#endif
GLADE_NEW_FUNCTION(glade_gtk_table_set_n_rows),
GLADE_NEW_FUNCTION(glade_gtk_table_set_n_columns),
GLADE_NEW_FUNCTION(glade_gtk_entry_set_text),
GLADE_NEW_FUNCTION(glade_gtk_option_menu_set_items),
GLADE_NEW_FUNCTION(glade_gtk_progress_bar_set_format),
GLADE_NEW_FUNCTION(glade_gtk_box_set_size),
GLADE_NEW_EMPTY_FUNCTION(glade_gtk_widget_set_tooltip),
GLADE_NEW_EMPTY_FUNCTION(ignore), /* For example for gtkwindow::modal, we want to ignore the set */
GLADE_NEW_FUNCTION(glade_gtk_notebook_get_n_pages),
GLADE_NEW_FUNCTION(glade_gtk_notebook_set_n_pages),
GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_max),
GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_min),
GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_step_increment),
GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_page_increment),
GLADE_NEW_FUNCTION(glade_gtk_spin_button_set_page_size),
GLADE_NEW_FUNCTION(glade_gtk_check_button_post_create),
GLADE_NEW_FUNCTION(glade_gtk_window_post_create),
GLADE_NEW_FUNCTION(glade_gtk_dialog_post_create),
GLADE_NEW_FUNCTION(glade_gtk_message_dialog_post_create),
GLADE_NEW_FUNCTION(glade_gtk_table_post_create)
};
#undef GLADE_NEW_FUNCTION
#undef GLADE_NEW_EMPTY_FUNCTION
gpointer
glade_gtk_get_function (const gchar *name)
{
gint num;
gint i;
num = sizeof (functions) / sizeof (GladeGtkFunction);
for (i = 0; i < num; i++) {
if (strcmp (name, functions[i].name) == 0)
break;
}
if (i == num) {
g_warning ("Could not find the function %s\n",
name);
return NULL;
}
return functions[i].function;
}
gboolean
glade_gtk_get_set_function_hack (GladePropertyClass *class, const gchar *name)
{
class->set_function = glade_gtk_get_function (name);
return TRUE;
}
gboolean
glade_gtk_get_get_function_hack (GladePropertyClass *class, const gchar *name)
{
class->get_function = glade_gtk_get_function (name);
return TRUE;
}
......@@ -35,7 +35,6 @@
#include "glade-parameter.h"
#include "glade-property.h"
#include "glade-property-class.h"
#include "glade-gtk.h"
#include "glade-debug.h"
#if 0
......@@ -842,39 +841,6 @@ glade_property_class_load_from_param_spec (const gchar *name,
}
#endif
static gboolean
glade_property_class_get_get_function (GladePropertyClass *class, const gchar *function_name)
{
return glade_gtk_get_get_function_hack (class, function_name);
}
static gboolean
glade_property_class_get_set_function (GladePropertyClass *class, const gchar *function_name)
{
static GModule *allsymbols;
/* This is not working ... So add a temp hack */
return glade_gtk_get_set_function_hack (class, function_name);
g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (class), FALSE);
g_return_val_if_fail (class->set_function == NULL, FALSE);
g_return_val_if_fail (function_name != NULL, FALSE);
if (!allsymbols)
allsymbols = g_module_open (NULL, 0);
if (!g_module_symbol (allsymbols, function_name,
(gpointer) &class->set_function)) {
g_warning (_("We could not find the symbol \"%s\" while trying to load \"%s\""),
function_name, class->name);
return FALSE;
}
g_assert (class->set_function);
return TRUE;
}
static GList *
glade_xml_read_list (GladeXmlNode *node, const gchar *list_tag, const gchar *item_tag)
{
......@@ -1006,6 +972,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
*property_class = pproperty_class;
}
else {
#if 0
/* If the property is an object Load it */
if (pproperty_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
child = glade_xml_search_child_required (node, GLADE_TAG_GLADE_WIDGET_CLASS);
......@@ -1017,6 +984,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
pproperty_class->child = glade_widget_class_new_from_node (child);
}
#endif
pproperty_class->def = glade_property_class_get_default (node, pproperty_class);
glade_property_class_free (*property_class);
......@@ -1056,20 +1024,41 @@ glade_property_class_update_from_node (GladeXmlNode *node,
/* If this property can't be set with g_object_set, get the workarround
* function
*/
/* I use here a g_warning to signal these errors instead of a dialog box, as if there is one
* of this kind of errors, there will probably a lot of them, and we don't want to inflict
* the user the pain of plenty of dialog boxes. Ideally, we should collect these errors,
* and show all of them at the end of the load processus. */
child = glade_xml_search_child (node, GLADE_TAG_SET_FUNCTION);
if (child != NULL) {
gchar * content = glade_xml_get_content (child);
glade_property_class_get_set_function (pproperty_class, content);
g_free (content);
gchar *symbol_name = glade_xml_get_content (child);
if (!widget_class->module)
g_warning (_("The property [%s] of the widget's class [%s] needs a special \"set\" function, but there is no library associated to this widget's class."),
pproperty_class->name, widget_class->name);
if (!g_module_symbol (widget_class->module, symbol_name, (gpointer *) &pproperty_class->set_function))
g_warning (_("Unable to get the \"set\" function [%s] of the property [%s] of the widget's class [%s] from the module [%s]: %s"),
symbol_name, pproperty_class->name, widget_class->name, g_module_name (widget_class->module), g_module_error ());
g_free (symbol_name);
}
/* If this property can't be get with g_object_get, get the workarround
* function
*/
child = glade_xml_search_child (node, GLADE_TAG_GET_FUNCTION);
if (child != NULL) {
gchar * content = glade_xml_get_content (child);
glade_property_class_get_get_function (pproperty_class, content);
g_free (content);
gchar *symbol_name = glade_xml_get_content (child);
if (!widget_class->module)
g_warning (_("The property [%s] of the widget's class [%s] needs a special \"get\" function, but there is no library associated to this widget's class."),
pproperty_class->name, widget_class->name);
if (!g_module_symbol(widget_class->module, symbol_name, (gpointer *) &pproperty_class->get_function))