#include <libxml/xpath.h>
#include <glib/gi18n-lib.h>
+#include <gmodule.h>
#include <gtk/gtk.h>
#include "form.h"
PROP_QUOTE
};
+typedef GtkFormWidget *(* FormWidgetConstructorFunc) (void);
+
static void gtk_form_class_init (GtkFormClass *class);
static void gtk_form_init (GtkForm *form);
static void gtk_form_show_check_error_dialog (GtkFormWidget *fwidget,
GtkWidget *parent_window);
+static void gtk_form_load_modules (GtkForm *form);
+
#define GTK_FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_FORM, GtkFormPrivate))
typedef struct _GtkFormPrivate GtkFormPrivate;
GSList *fields;
GtkFormKey *key;
gchar quote;
+
+ GList *modules;
};
G_DEFINE_TYPE (GtkForm, gtk_form, G_TYPE_OBJECT)
GtkForm
*gtk_form_new ()
{
+ GtkForm *form;
+
+ form = GTK_FORM (g_object_new (gtk_form_get_type (), NULL));
+ if (form == NULL)
+ {
+ return NULL;
+ }
+
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
textdomain (GETTEXT_PACKAGE);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- return GTK_FORM (g_object_new (gtk_form_get_type (), NULL));
+ if (g_module_supported ())
+ {
+ gtk_form_load_modules (form);
+ }
+ else
+ {
+ g_warning (_("Modules not supported from this operating system."));
+ }
+
+ return form;
}
/**
}
else
{
- g_warning (_("Unknown type «%s»."), type);
+ /* trying in modules */
+ GList *modules;
+ FormWidgetConstructorFunc widget_constructor;
+
+ modules = g_list_first (priv->modules);
+ while (modules != NULL)
+ {
+ if (g_module_symbol ((GModule *)modules->data,
+ g_strconcat ("gtk_form_widget_", type, "_new", NULL),
+ (gpointer *)&widget_constructor))
+ {
+ if (widget_constructor != NULL)
+ {
+ widget = widget_constructor ();
+ break;
+ }
+ }
+
+ modules = g_list_next (modules);
+ }
+
+ if (widget == NULL)
+ {
+ g_warning (_("Unknown type «%s»."), type);
+ }
}
if (widget != NULL)
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
+
+static void
+gtk_form_load_modules (GtkForm *form)
+{
+ GDir *dir;
+ GError *error;
+
+ GModule *module;
+ const gchar *filename;
+
+ GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+
+ /* for each file in MODULESDIR */
+ error = NULL;
+ dir = g_dir_open (MODULESDIR, 0, &error);
+ if (dir != NULL)
+ {
+ while ((filename = g_dir_read_name (dir)) != NULL)
+ {
+ /* trying to open the module */
+ module = g_module_open (filename, G_MODULE_BIND_LAZY);
+ if (module != NULL)
+ {
+ priv->modules = g_list_append (priv->modules, (gpointer)module);
+ }
+ }
+
+ g_dir_close (dir);
+ }
+ else
+ {
+ g_warning (_("Unable to open modules dir: %s."), error->message);
+ }
+}