From: Andrea Zagli Date: Sat, 26 Jun 2010 16:04:45 +0000 (+0200) Subject: Started plugins implementation. X-Git-Tag: 0.3.0~10 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=af4162b84bec1c018ab5db02d958aa5e785f7c33;p=libgtkform Started plugins implementation. --- diff --git a/configure.ac b/configure.ac index a5ee871..c0dc168 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libgtkform], [0.1.0], [azagli@libero.it]) +AC_INIT([libgtkform], [0.2.0], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/form.c]) AC_CONFIG_HEADER([config.h]) diff --git a/libgtkform.pc.in b/libgtkform.pc.in index 4e513fa..42b9efe 100644 --- a/libgtkform.pc.in +++ b/libgtkform.pc.in @@ -2,6 +2,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ +modulesdir=@libdir@/@PACKAGE@/modules Name: @PACKAGE_NAME@ Description: Class to more easly manage Gtk+ forms binded to db (or not). diff --git a/src/Makefile.am b/src/Makefile.am index 6b39fa3..a097863 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,8 @@ LIBS = $(GTKFORM_LIBS) AM_CPPFLAGS = $(GTKFORM_CFLAGS) \ - -DLOCALEDIR=\"$(localedir)\" + -DLOCALEDIR=\"$(localedir)\" \ + -DMODULESDIR=\""$(libdir)/$(PACKAGE)/modules"\" lib_LTLIBRARIES = libgtkform.la diff --git a/src/form.c b/src/form.c index 0753e05..10e81ee 100644 --- a/src/form.c +++ b/src/form.c @@ -26,6 +26,7 @@ #include #include +#include #include #include "form.h" @@ -53,6 +54,8 @@ enum PROP_QUOTE }; +typedef GtkFormWidget *(* FormWidgetConstructorFunc) (void); + static void gtk_form_class_init (GtkFormClass *class); static void gtk_form_init (GtkForm *form); @@ -68,6 +71,8 @@ static void gtk_form_get_property (GObject *object, 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; @@ -79,6 +84,8 @@ struct _GtkFormPrivate GSList *fields; GtkFormKey *key; gchar quote; + + GList *modules; }; G_DEFINE_TYPE (GtkForm, gtk_form, G_TYPE_OBJECT) @@ -132,12 +139,29 @@ gtk_form_init (GtkForm *form) 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; } /** @@ -261,7 +285,31 @@ GtkForm } 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) @@ -1451,3 +1499,37 @@ gtk_form_show_check_error_dialog (GtkFormWidget *fwidget, GtkWidget *parent_wind 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); + } +}