]> saetta.ns0.it Git - libgtkform/commitdiff
Started plugins implementation.
authorAndrea Zagli <azagli@libero.it>
Sat, 26 Jun 2010 16:04:45 +0000 (18:04 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 26 Jun 2010 16:04:45 +0000 (18:04 +0200)
configure.ac
libgtkform.pc.in
src/Makefile.am
src/form.c

index a5ee871f9f48d42febdf4c177e875d852f787732..c0dc168cde1fe4bf5f162e9cfff625e124ae1f82 100644 (file)
@@ -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])
 
index 4e513fa1434dfeefa437706f4cd0811094da5696..42b9efe1d414a9360e71d525eb4790ab5b36de08 100644 (file)
@@ -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).
index 6b39fa35655714465dd3dd07f35f7f26c8ab0a90..a097863fe99cd88f45a7579df7a4d2a79de33b00 100644 (file)
@@ -1,7 +1,8 @@
 LIBS = $(GTKFORM_LIBS)
 
 AM_CPPFLAGS = $(GTKFORM_CFLAGS) \
-              -DLOCALEDIR=\"$(localedir)\"
+              -DLOCALEDIR=\"$(localedir)\" \
+              -DMODULESDIR=\""$(libdir)/$(PACKAGE)/modules"\"
 
 lib_LTLIBRARIES = libgtkform.la
 
index 0753e0594d77a3d90ba004a3ffc3672c1a7e7a69..10e81ee776369c73ba7bf94093d50598840696b3 100644 (file)
@@ -26,6 +26,7 @@
 #include <libxml/xpath.h>
 
 #include <glib/gi18n-lib.h>
+#include <gmodule.h>
 #include <gtk/gtk.h>
 
 #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);
+               }
+}