From 9f5e90f136dad1524f69a1461eed995a7d00e3de Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 1 May 2017 10:02:25 +0200 Subject: [PATCH] Added commons functions ZakForm::get_compare_type_from_string and ::get_compare_type_stringify. --- po/POTFILES.in | 8 +++ po/it.po | 76 +++++++++++++++-------------- src/commons.c | 89 ++++++++++++++++++++++++++++++++++ src/commons.h | 12 +++++ src/formelementvalidatordate.c | 26 +++++----- src/formvalidatorcompare.c | 80 +++++++----------------------- src/formvalidatorcomparedate.c | 79 ++++++++---------------------- 7 files changed, 200 insertions(+), 170 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index d2e4f2c..44c1ff8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/po/it.po b/po/it.po index d0b87e4..aa1eb2a 100644 --- 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 , 2015-2016. +# Andrea Zagli , 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 \n" "Language-Team: Italian \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»" diff --git a/src/commons.c b/src/commons.c index fd49ad0..f1f604e 100644 --- a/src/commons.c +++ b/src/commons.c @@ -28,6 +28,95 @@ #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: diff --git a/src/commons.h b/src/commons.h index 9312c57..18e0b66 100644 --- a/src/commons.h +++ b/src/commons.h @@ -27,6 +27,18 @@ 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); diff --git a/src/formelementvalidatordate.c b/src/formelementvalidatordate.c index b10bc94..072ab4e 100644 --- a/src/formelementvalidatordate.c +++ b/src/formelementvalidatordate.c @@ -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; diff --git a/src/formvalidatorcompare.c b/src/formvalidatorcompare.c index edaf6f2..c18b2de 100644 --- a/src/formvalidatorcompare.c +++ b/src/formvalidatorcompare.c @@ -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); diff --git a/src/formvalidatorcomparedate.c b/src/formvalidatorcomparedate.c index b7df370..2205a80 100644 --- a/src/formvalidatorcomparedate.c +++ b/src/formvalidatorcomparedate.c @@ -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); -- 2.49.0