]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added commons functions ZakForm::get_compare_type_from_string and ::get_compare_type_...
authorAndrea Zagli <azagli@libero.it>
Mon, 1 May 2017 08:02:25 +0000 (10:02 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 1 May 2017 08:02:25 +0000 (10:02 +0200)
po/POTFILES.in
po/it.po
src/commons.c
src/commons.h
src/formelementvalidatordate.c
src/formvalidatorcompare.c
src/formvalidatorcomparedate.c

index d2e4f2c8e173e3aed481a7f4a5644596b033938a..44c1ff83891a0ec51f142f2507ea3e54f74d5b3e 100644 (file)
@@ -1,7 +1,15 @@
 # List of source files which contain translatable strings.
+src/commons.c
 src/form.c
 src/formelement.c
+src/formelementfilter.c
+src/formelementfilterluc.c
+src/formelementfiltertrim.c
 src/formelementvalidator.c
+src/formelementvalidatordate.c
+src/formelementvalidatornotempty.c
+src/formelementvalidatorregex.c
+src/formiprovider.c
 src/formvalidator.c
 src/formvalidatorcompare.c
 src/formvalidatorcomparedate.c
index d0b87e43e5cad8e0cca22302747716d526dcb85d..aa1eb2ab683289efd01f8a0b11c36d4ecf0b389f 100644 (file)
--- a/po/it.po
+++ b/po/it.po
@@ -1,13 +1,13 @@
 # libzakform italian translation
-# Copyright (C) 2015-2016 Andrea Zagli
+# Copyright (C) 2015-2017 Andrea Zagli
 # This file is distributed under the same license as the libzakform package.
-# Andrea Zagli <azagli@libero.it>, 2015-2016.
+# Andrea Zagli <azagli@libero.it>, 2015-2017.
 #
 msgid ""
 msgstr ""
 "Project-Id-Version: libzakform 0.0.1\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2016-01-02 17:48+0100\n"
+"POT-Creation-Date: 2017-05-01 09:58+0200\n"
 "PO-Revision-Date: 2016-01-02 12:44+0200\n"
 "Last-Translator: Andrea Zagli <azagli@libero.it>\n"
 "Language-Team: Italian <tp@lists.linux.it>\n"
@@ -17,66 +17,70 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
-#: ../src/form.c:336
+#: ../src/commons.c:89
+msgid "lesser than"
+msgstr "minore di"
+
+#: ../src/commons.c:93
+msgid "lesser or equal to"
+msgstr "minore o uguale a"
+
+#: ../src/commons.c:97
+msgid "equal to"
+msgstr "uguale a"
+
+#: ../src/commons.c:101
+msgid "different from"
+msgstr "diverso da"
+
+#: ../src/commons.c:105
+msgid "greater than"
+msgstr "maggiore di"
+
+#: ../src/commons.c:109
+msgid "greater or equal to"
+msgstr "maggiore o uguale a"
+
+#: ../src/commons.c:113
+msgid "NOT SUPPORTED"
+msgstr "NON SUPPORTATO"
+
+#: ../src/form.c:383
 #, c-format
 msgid "Unknown element type «%s»."
 msgstr "Tipo elemento «%s» sconosciuto."
 
-#: ../src/form.c:380
+#: ../src/form.c:428
 msgid "The file is not a valid ZakForm definition file."
 msgstr "Il file non è un file di definizione valido di ZakForm."
 
-#: ../src/form.c:832
+#: ../src/form.c:998
 msgid "Unable to load module of myself"
 msgstr "Impossibile caricare i moduli di me stesso"
 
-#: ../src/form.c:862
+#: ../src/form.c:1028
 #, c-format
 msgid "Unable to load %s: %s."
 msgstr "Impossibile caricare %s: %s."
 
-#: ../src/form.c:870
+#: ../src/form.c:1036
 #, c-format
 msgid "Unable to open modules dir: %s."
 msgstr "Impossibile aprire la directory dei moduli: %s."
 
-#: ../src/form.c:871
+#: ../src/form.c:1037
 msgid "no details"
 msgstr "nessun dettaglio"
 
-#: ../src/form.c:876
+#: ../src/form.c:1042
 msgid "Modules not supported by this operating system."
 msgstr "I moduli non sono supportati in questo sistema operativo"
 
-#: ../src/formelementvalidator.c:67
+#: ../src/formelementvalidator.c:87 ../src/formvalidator.c:87
 msgid "Invalid value"
 msgstr "Valore non valido"
 
-#: ../src/formvalidatorcomparedate.c:107
-msgid "lesser than"
-msgstr "minore di"
-
-#: ../src/formvalidatorcomparedate.c:108
-msgid "lesser or equal to"
-msgstr "minore o uguale a"
-
-#: ../src/formvalidatorcomparedate.c:109
-msgid "equal to"
-msgstr "uguale a"
-
-#: ../src/formvalidatorcomparedate.c:110
-msgid "different from"
-msgstr "diverso da"
-
-#: ../src/formvalidatorcomparedate.c:111
-msgid "greater than"
-msgstr "maggiore di"
-
-#: ../src/formvalidatorcomparedate.c:112
-msgid "greater or equal to"
-msgstr "maggiore o uguale a"
-
-#: ../src/formvalidatorcomparedate.c:318
+#: ../src/formvalidatorcompare.c:253 ../src/formvalidatorcomparedate.c:266
 #, c-format
 msgid "«%s» must be %s «%s»"
 msgstr "«%s» deve essere %s «%s»"
index fd49ad0f38b2d958b104131527bed5b7c973e004..f1f604e6a3ae6f5fa0c6625287536bed0540276c 100644 (file)
 
 #include "commons.h"
 
+
+/**
+ * zak_form_get_compare_type_from_string:
+ * @str:
+ *
+ * Returns: the #ZakFormCompareType from @str.
+ */
+ZakFormCompareType
+zak_form_get_compare_type_from_string (const gchar *str)
+{
+       ZakFormCompareType ret;
+
+       if (g_strcmp0 (str, "lt") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_LESSER;
+               }
+       else if (g_strcmp0 (str, "let") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL;
+               }
+       else if (g_strcmp0 (str, "e") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_EQUAL;
+               }
+       else if (g_strcmp0 (str, "ne") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_NOT_EQUAL;
+               }
+       else if (g_strcmp0 (str, "gt") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_GREATER;
+               }
+       else if (g_strcmp0 (str, "get") == 0)
+               {
+                       ret = ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL;
+               }
+       else
+               {
+                       g_warning ("Compare type «%s» not supported.", str);
+               }
+
+       return ret;
+}
+
+/**
+ * zak_form_get_compare_type_stringify:
+ * @type:
+ *
+ * Returns: the stringify version of #ZakFormCompareType.
+ */
+const gchar
+*zak_form_get_compare_type_stringify (ZakFormCompareType type)
+{
+       const gchar *ret;
+
+       switch (type)
+               {
+               case ZAK_FORM_COMPARE_TYPE_LESSER:
+                       ret = _("lesser than");
+                       break;
+
+               case ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL:
+                       ret = _("lesser or equal to");
+                       break;
+
+               case ZAK_FORM_COMPARE_TYPE_EQUAL:
+                       ret = _("equal to");
+                       break;
+
+               case ZAK_FORM_COMPARE_TYPE_NOT_EQUAL:
+                       ret = _("different from");
+                       break;
+
+               case ZAK_FORM_COMPARE_TYPE_GREATER:
+                       ret = _("greater than");
+                       break;
+
+               case ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL:
+                       ret =  _("greater or equal to");
+                       break;
+
+               default:
+                       ret = _("NOT SUPPORTED");
+                       break;
+               }
+
+       return ret;
+}
+
 /**
  * zak_form_get_element_by_id:
  * @ar_elements:
index 9312c5751b6701ecb8d529aa2e72fb17fca11edd..18e0b66572c239fef06bdae19c335944b7b9959c 100644 (file)
 
 G_BEGIN_DECLS
 
+typedef enum
+       {
+               ZAK_FORM_COMPARE_TYPE_LESSER,
+               ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL,
+               ZAK_FORM_COMPARE_TYPE_EQUAL,
+               ZAK_FORM_COMPARE_TYPE_NOT_EQUAL,
+               ZAK_FORM_COMPARE_TYPE_GREATER,
+               ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL
+       } ZakFormCompareType;
+
+ZakFormCompareType zak_form_get_compare_type_from_string (const gchar *str);
+const gchar *zak_form_get_compare_type_stringify (ZakFormCompareType type);
 
 ZakFormElement *zak_form_get_element_by_id (GPtrArray *ar_elements, const gchar *id);
 
index b10bc94450e11bc18b53549084831085d4d66f91..072ab4e7184270868db1b90e2330b36355f3bf5f 100644 (file)
@@ -29,13 +29,13 @@ static void zak_form_element_validator_date_class_init (ZakFormElementValidatorD
 static void zak_form_element_validator_date_init (ZakFormElementValidatorDate *zak_form_element);
 
 static void zak_form_element_validator_date_set_property (GObject *object,
-                               guint property_id,
-                               const GValue *value,
-                               GParamSpec *pspec);
+                                                          guint property_id,
+                                                          const GValue *value,
+                                                          GParamSpec *pspec);
 static void zak_form_element_validator_date_get_property (GObject *object,
-                               guint property_id,
-                               GValue *value,
-                               GParamSpec *pspec);
+                                                          guint property_id,
+                                                          GValue *value,
+                                                          GParamSpec *pspec);
 
 static void zak_form_element_validator_date_dispose (GObject *gobject);
 static void zak_form_element_validator_date_finalize (GObject *gobject);
@@ -150,9 +150,9 @@ zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator,
 /* PRIVATE */
 static void
 zak_form_element_validator_date_set_property (GObject *object,
-                   guint property_id,
-                   const GValue *value,
-                   GParamSpec *pspec)
+                                              guint property_id,
+                                              const GValue *value,
+                                              GParamSpec *pspec)
 {
        ZakFormElementValidatorDate *zak_form_element = (ZakFormElementValidatorDate *)object;
        ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (zak_form_element);
@@ -167,9 +167,9 @@ zak_form_element_validator_date_set_property (GObject *object,
 
 static void
 zak_form_element_validator_date_get_property (GObject *object,
-                   guint property_id,
-                   GValue *value,
-                   GParamSpec *pspec)
+                                              guint property_id,
+                                              GValue *value,
+                                              GParamSpec *pspec)
 {
        ZakFormElementValidatorDate *zak_form_element = (ZakFormElementValidatorDate *)object;
        ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (zak_form_element);
@@ -208,7 +208,7 @@ zak_form_element_validator_date_finalize (GObject *gobject)
 
 static gboolean
 zak_form_element_validator_date_validate (ZakFormElementValidator *validator_date,
-                                                                                 const gchar *value)
+                                          const gchar *value)
 {
        gboolean ret;
        gchar *_value;
index edaf6f2be4e76afe4176b8cffb6632a1bbb60754..c18b2de8c2623b2d9fac2713b094fe4bcc930894 100644 (file)
@@ -55,18 +55,6 @@ struct _ZakFormValidatorCompare
 
 #define ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_VALIDATOR_COMPARE, ZakFormValidatorComparePrivate))
 
-enum
-       {
-               LESSER,
-               LESSER_EQUAL,
-               EQUAL,
-               NOT_EQUAL,
-               GREATER,
-               GREATER_EQUAL
-       };
-
-static gchar *msgs[6];
-
 typedef struct _ZakFormValidatorComparePrivate ZakFormValidatorComparePrivate;
 struct _ZakFormValidatorComparePrivate
        {
@@ -102,13 +90,6 @@ zak_form_validator_compare_init (ZakFormValidatorCompare *validator)
 
        priv->v1 = NULL;
        priv->v2 = NULL;
-
-       msgs[0] = _("lesser than");
-       msgs[1] = _("lesser or equal to");
-       msgs[2] = _("equal to");
-       msgs[3] = _("different from");
-       msgs[4] = _("greater than");
-       msgs[5] = _("greater or equal to");
 }
 
 /**
@@ -141,34 +122,7 @@ zak_form_validator_compare_xml_parsing (ZakFormValidator *validator, xmlNode *xn
        ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
 
        prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type_comp");
-       if (g_strcmp0 (prop, "lt") == 0)
-               {
-                       priv->type = LESSER;
-               }
-       else if (g_strcmp0 (prop, "let") == 0)
-               {
-                       priv->type = LESSER_EQUAL;
-               }
-       else if (g_strcmp0 (prop, "e") == 0)
-               {
-                       priv->type = EQUAL;
-               }
-       else if (g_strcmp0 (prop, "ne") == 0)
-               {
-                       priv->type = NOT_EQUAL;
-               }
-       else if (g_strcmp0 (prop, "gt") == 0)
-               {
-                       priv->type = GREATER;
-               }
-       else if (g_strcmp0 (prop, "get") == 0)
-               {
-                       priv->type = GREATER_EQUAL;
-               }
-       else
-               {
-                       g_warning ("Validator compare: compare type «%s» not supported.", prop);
-               }
+       priv->type = zak_form_get_compare_type_from_string (prop);
        g_free (prop);
 
        prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element1");
@@ -193,9 +147,9 @@ zak_form_validator_compare_xml_parsing (ZakFormValidator *validator, xmlNode *xn
 /* PRIVATE */
 static void
 zak_form_validator_compare_set_property (GObject *object,
-                   guint property_id,
-                   const GValue *value,
-                   GParamSpec *pspec)
+                                         guint property_id,
+                                         const GValue *value,
+                                         GParamSpec *pspec)
 {
        ZakFormValidatorCompare *validator = (ZakFormValidatorCompare *)object;
        ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
@@ -210,9 +164,9 @@ zak_form_validator_compare_set_property (GObject *object,
 
 static void
 zak_form_validator_compare_get_property (GObject *object,
-                   guint property_id,
-                   GValue *value,
-                   GParamSpec *pspec)
+                                         guint property_id,
+                                         GValue *value,
+                                         GParamSpec *pspec)
 {
        ZakFormValidatorCompare *validator = (ZakFormValidatorCompare *)object;
        ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
@@ -277,28 +231,28 @@ zak_form_validator_compare_validate (ZakFormValidator *validator)
                        comp = g_strcmp0 (gc1, gc2);
                        if (comp < 0)
                                {
-                                       ret = (priv->type == LESSER
-                                              || priv->type == LESSER_EQUAL
-                                              || priv->type == NOT_EQUAL);
+                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_LESSER
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
                                }
                        else if (comp == 0)
                                {
-                                       ret = (priv->type == LESSER_EQUAL
-                                              || priv->type == EQUAL
-                                              || priv->type == GREATER_EQUAL);
+                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_EQUAL
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL);
                                }
                        else if (comp > 0)
                                {
-                                       ret = (priv->type == GREATER
-                                              || priv->type == GREATER_EQUAL
-                                              || priv->type == NOT_EQUAL);
+                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_GREATER
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL
+                                              || priv->type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
                                };
 
                        if (!ret)
                                {
                                        msg = g_strdup_printf (_("«%s» must be %s «%s»"),
                                                               zak_form_element_get_long_name (priv->v1),
-                                                              msgs[priv->type],
+                                                              zak_form_get_compare_type_stringify (priv->type),
                                                               zak_form_element_get_long_name (priv->v2));
                                        zak_form_validator_set_message (validator, msg);
                                        g_free (msg);
index b7df370b4b84a03f68676e0c9645153057cea920..2205a805942ba10061c6fa487ac15abc37e656be 100644 (file)
@@ -55,18 +55,6 @@ struct _ZakFormValidatorCompareDate
 
 #define ZAK_FORM_VALIDATOR_COMPARE_DATE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_VALIDATOR_COMPARE_DATE, ZakFormValidatorCompareDatePrivate))
 
-enum
-       {
-               LESSER,
-               LESSER_EQUAL,
-               EQUAL,
-               NOT_EQUAL,
-               GREATER,
-               GREATER_EQUAL
-       };
-
-static gchar *msgs[6];
-
 typedef struct _ZakFormValidatorCompareDatePrivate ZakFormValidatorCompareDatePrivate;
 struct _ZakFormValidatorCompareDatePrivate
        {
@@ -105,13 +93,6 @@ zak_form_validator_compare_date_init (ZakFormValidatorCompareDate *validator)
 
        priv->v1 = NULL;
        priv->v2 = NULL;
-
-       msgs[0] = _("lesser than");
-       msgs[1] = _("lesser or equal to");
-       msgs[2] = _("equal to");
-       msgs[3] = _("different from");
-       msgs[4] = _("greater than");
-       msgs[5] = _("greater or equal to");
 }
 
 /**
@@ -143,43 +124,25 @@ zak_form_validator_compare_date_xml_parsing (ZakFormValidator *validator, xmlNod
 
        ZakFormValidatorCompareDatePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_DATE_GET_PRIVATE (validator);
 
-       prop = xmlGetProp (xnode, (const xmlChar *)"type_comp");
-       if (g_strcmp0 (prop, "lt") == 0)
-               {
-                       priv->type = LESSER;
-               }
-       else if (g_strcmp0 (prop, "let") == 0)
-               {
-                       priv->type = LESSER_EQUAL;
-               }
-       else if (g_strcmp0 (prop, "e") == 0)
-               {
-                       priv->type = EQUAL;
-               }
-       else if (g_strcmp0 (prop, "ne") == 0)
-               {
-                       priv->type = NOT_EQUAL;
-               }
-       else if (g_strcmp0 (prop, "gt") == 0)
-               {
-                       priv->type = GREATER;
-               }
-       else if (g_strcmp0 (prop, "get") == 0)
-               {
-                       priv->type = GREATER_EQUAL;
-               }
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type_comp");
+       priv->type = zak_form_get_compare_type_from_string (prop);
+       g_free (prop);
 
-       prop = xmlGetProp (xnode, (const xmlChar *)"element1");
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element1");
        priv->v1 = zak_form_get_element_by_id (ar_elements, prop);
+       g_free (prop);
 
-       prop = xmlGetProp (xnode, (const xmlChar *)"element2");
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element2");
        priv->v2 = zak_form_get_element_by_id (ar_elements, prop);
+       g_free (prop);
 
-       prop = xmlGetProp (xnode, (const xmlChar *)"format1");
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"format1");
        priv->format1 = g_strdup (prop);
+       g_free (prop);
 
-       prop = xmlGetProp (xnode, (const xmlChar *)"format2");
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"format2");
        priv->format2 = g_strdup (prop);
+       g_free (prop);
 
        return TRUE;
 }
@@ -279,21 +242,21 @@ zak_form_validator_compare_date_validate (ZakFormValidator *validator)
                                        switch (comp)
                                                {
                                                case -1:
-                                                       ret = (priv->type == LESSER
-                                                              || priv->type == LESSER_EQUAL
-                                                              || priv->type == NOT_EQUAL);
+                                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_LESSER
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
                                                        break;
 
                                                case 0:
-                                                       ret = (priv->type == LESSER_EQUAL
-                                                              || priv->type == EQUAL
-                                                              || priv->type == GREATER_EQUAL);
+                                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_EQUAL
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL);
                                                        break;
 
                                                case 1:
-                                                       ret = (priv->type == GREATER
-                                                              || priv->type == GREATER_EQUAL
-                                                              || priv->type == NOT_EQUAL);
+                                                       ret = (priv->type == ZAK_FORM_COMPARE_TYPE_GREATER
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL
+                                                              || priv->type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
                                                        break;
                                                };
                                }
@@ -302,7 +265,7 @@ zak_form_validator_compare_date_validate (ZakFormValidator *validator)
                                {
                                        msg = g_strdup_printf (_("«%s» must be %s «%s»"),
                                                               zak_form_element_get_long_name (priv->v1),
-                                                              msgs[priv->type],
+                                                              zak_form_get_compare_type_stringify (priv->type),
                                                               zak_form_element_get_long_name (priv->v2));
                                        zak_form_validator_set_message (validator, msg);
                                        g_free (msg);