Added signals ZakFormElement before and after validating.
authorAndrea Zagli <azagli@libero.it>
Sun, 30 Apr 2017 09:17:54 +0000 (11:17 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 30 Apr 2017 09:17:54 +0000 (11:17 +0200)
.gitignore
configure.ac
src/Makefile.am
src/formelement.c
src/formelement.h
src/zakform_marshal.list [new file with mode: 0644]

index 8129d065c7f857c37bb7f0e653878e9baf5e5522..6fce3bf6af947f368c13f7d1aee5914b08a9b248 100644 (file)
@@ -50,3 +50,4 @@ intltool-*
 Rules-quot
 *.exe
 *.csv
+src/*marshal*.[ch]
\ No newline at end of file
index d86c09bcb00823b39e63acddd2f4d23c7f3d33d0..1f2bffefd0392ba1dbe39cb356e6241fa575d8d7 100644 (file)
@@ -32,6 +32,11 @@ AC_PROG_RANLIB
 GTK_DOC_CHECK(1.0)
 IT_PROG_INTLTOOL
 
+dnl ******************************
+dnl glib-genmarshal
+dnl ******************************
+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+
 dnl ******************************
 dnl Translations
 dnl ******************************
index 1947bbcc74fe875704f082a384d09718f36204b9..022e7ffc2b2fa74d62a8e7aa783c04b374b1904b 100644 (file)
@@ -7,8 +7,15 @@ AM_CPPFLAGS = $(ZAKFORM_CFLAGS) \
 
 lib_LTLIBRARIES = libzakform.la
 
+zakformmarshal.c: zakformmarshal.h zakform_marshal.list $(GLIB_GENMARSHAL)
+       $(GLIB_GENMARSHAL) $(srcdir)/zakform_marshal.list --body --prefix=_zak_form_marshal > $(srcdir)/$@
+
+zakformmarshal.h: zakform_marshal.list $(GLIB_GENMARSHAL)
+       $(GLIB_GENMARSHAL) $(srcdir)/zakform_marshal.list --header --prefix=_zak_form_marshal > $(srcdir)/$@
+
 libzakform_la_SOURCES = \
                         commons.c \
+                        zakformmarshal.c \
                         form.c \
                         formelement.c \
                         formelementfilter.c \
@@ -28,6 +35,7 @@ libzakform_la_LDFLAGS = -no-undefined
 libzakform_include_HEADERS = \
                              libzakform.h \
                              commons.h \
+                             zakformmarshal.h \
                              form.h \
                              formelement.h \
                              formelementfilter.h \
index ce68b320f3270b6cc0c2e31d10f52fc764dc2677..aa4bf6d514dd0c2440c257870d9de2c23ddb95e2 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <libzakutils/libzakutils.h>
 
+#include "zakformmarshal.h"
 #include "formelement.h"
 
 enum
@@ -150,10 +151,10 @@ zak_form_element_class_init (ZakFormElementClass *class)
 
        g_object_class_install_property (object_class, PROP_FORMAT,
                                         g_param_spec_boxed ("format",
-                                                                                                                "Format",
-                                                                                                                "Format",
-                                                                                                                G_TYPE_HASH_TABLE,
-                                                                                                                G_PARAM_READWRITE));
+                                                            "Format",
+                                                            "Format",
+                                                            G_TYPE_HASH_TABLE,
+                                                            G_PARAM_READWRITE));
 
        g_object_class_install_property (object_class, PROP_VISIBLE,
                                         g_param_spec_boolean ("visible",
@@ -182,6 +183,36 @@ zak_form_element_class_init (ZakFormElementClass *class)
                                                               "To save",
                                                               TRUE,
                                                               G_PARAM_READWRITE));
+
+       /**
+        * ZakFormElement::before_validating:
+        * @element:
+        *
+        */
+       class->before_validating_signal_id = g_signal_new ("before-validating",
+                                                          G_TYPE_FROM_CLASS (object_class),
+                                                          G_SIGNAL_RUN_LAST,
+                                                          0,
+                                                          NULL,
+                                                          NULL,
+                                                          _zak_form_marshal_BOOLEAN__POINTER,
+                                                          G_TYPE_BOOLEAN,
+                                                          1, G_TYPE_POINTER);
+
+       /**
+        * ZakFormElement::after_validating:
+        * @element:
+        *
+        */
+       class->after_validating_signal_id = g_signal_new ("after-validating",
+                                                         G_TYPE_FROM_CLASS (object_class),
+                                                         G_SIGNAL_RUN_LAST,
+                                                         0,
+                                                         NULL,
+                                                         NULL,
+                                                         _zak_form_marshal_BOOLEAN__POINTER,
+                                                         G_TYPE_BOOLEAN,
+                                                         1, G_TYPE_POINTER);
 }
 
 static void
@@ -1167,15 +1198,19 @@ gboolean
 zak_form_element_is_valid (ZakFormElement *element)
 {
        gboolean ret;
+       gboolean ret_callback;
 
        gchar *value;
        guint i;
 
        ZakFormElementPrivate *priv;
 
+       ZakFormElementClass *klass = ZAK_FORM_ELEMENT_GET_CLASS (element);
+
        priv = zak_form_element_get_instance_private (element);
 
        ret = TRUE;
+       ret_callback = FALSE;
 
        zak_form_element_filter (element);
 
@@ -1185,6 +1220,15 @@ zak_form_element_is_valid (ZakFormElement *element)
                        priv->pa_messages = NULL;
                }
 
+       priv->pa_messages = g_ptr_array_new ();
+
+       /* signal before_validating */
+       g_signal_emit (element, klass->before_validating_signal_id, 0, (gpointer)priv->pa_messages, &ret_callback);
+       if (ret_callback)
+               {
+                       ret = FALSE;
+               }
+
        value = zak_form_element_get_value (element);
 
        for (i = 0; i < priv->pa_validators->len; i++)
@@ -1192,16 +1236,19 @@ zak_form_element_is_valid (ZakFormElement *element)
                        ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
                        if (!zak_form_element_validator_validate (validator, value))
                                {
-                                       if (priv->pa_messages == NULL)
-                                               {
-                                                       priv->pa_messages = g_ptr_array_new ();
-                                               }
                                        g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (zak_form_element_validator_get_message (validator)));
 
                                        ret = FALSE;
                                }
                }
 
+       /* signal after_validating */
+       g_signal_emit (element, klass->after_validating_signal_id, 0, (gpointer)priv->pa_messages, &ret_callback);
+       if (ret_callback)
+               {
+                       ret = FALSE;
+               }
+
        return ret;
 }
 
@@ -1430,27 +1477,27 @@ zak_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode)
                {
                        to_unlink = FALSE;
 
-                   if (xmlStrcmp (cur->name, (const xmlChar *)"name") == 0)
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"name") == 0)
                                {
                                        zak_form_element_set_name (element, (const gchar *)xmlNodeGetContent (cur));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"is-key") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"is-key") == 0)
                                {
                                        zak_form_element_set_is_key (element, xmlStrEqual ((const gchar *)xmlNodeGetContent (cur), "TRUE"));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"type") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"type") == 0)
                                {
                                        zak_form_element_set_provider_type (element, (const gchar *)xmlNodeGetContent (cur));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"default-value") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"default-value") == 0)
                                {
                                        zak_form_element_set_default_value (element, (const gchar *)xmlNodeGetContent (cur));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"format") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"format") == 0)
                                {
                                        GHashTable *ht;
 
@@ -1471,22 +1518,22 @@ zak_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode)
                                        g_hash_table_unref (ht);
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"visible") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"visible") == 0)
                                {
                                        zak_form_element_set_visible (element, xmlStrEqual ((const gchar *)xmlNodeGetContent (cur), "TRUE"));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"editable") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"editable") == 0)
                                {
                                        zak_form_element_set_editable (element, xmlStrEqual ((const gchar *)xmlNodeGetContent (cur), "TRUE"));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"to-load") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"to-load") == 0)
                                {
                                        zak_form_element_set_to_load (element, xmlStrEqual ((const gchar *)xmlNodeGetContent (cur), "TRUE"));
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (cur->name, (const xmlChar *)"to-save") == 0)
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"to-save") == 0)
                                {
                                        zak_form_element_set_to_save (element, xmlStrEqual ((const gchar *)xmlNodeGetContent (cur), "TRUE"));
                                        to_unlink = TRUE;
index 22acdef1c2f54aee1895ba97c5c88e5826a15be8..dc2408290ec8330d53eecd6a6ad52e473139e144 100644 (file)
@@ -48,6 +48,9 @@ struct _ZakFormElementClass
 
                void (*set_editable) (ZakFormElement *element, gboolean editable);
                gboolean (*get_editable) (ZakFormElement *element);
+
+               guint before_validating_signal_id;
+               guint after_validating_signal_id;
        };
 
 void zak_form_element_set_name (ZakFormElement *element, const gchar *name);
diff --git a/src/zakform_marshal.list b/src/zakform_marshal.list
new file mode 100644 (file)
index 0000000..92c9338
--- /dev/null
@@ -0,0 +1 @@
+BOOLEAN:POINTER