]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunto SolipaZakFormElementValidatorPiva.
authorAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 09:51:09 +0000 (11:51 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 09:51:09 +0000 (11:51 +0200)
src/Makefile.am
src/formelementvalidatorpiva.c [new file with mode: 0644]
src/formelementvalidatorpiva.h [new file with mode: 0644]
src/libsolipa.h

index 031097f533583cefbb36f722277a0308dc8921d0..a5a99f1c3c659218328c9ae4d60f354481f325e8 100644 (file)
@@ -46,6 +46,7 @@ lib_LTLIBRARIES = libsolipa.la \
 libsolipa_la_SOURCES = solipa.c \
                        allegato.c \
                        formelementvalidatorcodfisc.c \
+                       formelementvalidatorpiva.c \
                        log.c \
                        progresswindow.c \
                        utils.c \
@@ -58,6 +59,7 @@ libsolipa_include_HEADERS = libsolipa.h \
                             solipa.h \
                             allegato.h \
                             formelementvalidatorcodfisc.h \
+                            formelementvalidatorpiva.h \
                             log.h \
                             progresswindow.h \
                             utils.h \
diff --git a/src/formelementvalidatorpiva.c b/src/formelementvalidatorpiva.c
new file mode 100644 (file)
index 0000000..9d082c0
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2017 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include <libzakutils/libzakutils.h>
+
+#include "utils.h"
+#include "formelementvalidatorpiva.h"
+
+enum
+       {
+               PROP_0,
+               PROP_EMPTY_GOOD
+       };
+
+static void solipa_zak_form_element_validator_piva_class_init (SolipaZakFormElementValidatorPivaClass *class);
+static void solipa_zak_form_element_validator_piva_init (SolipaZakFormElementValidatorPiva *solipa_zak_form_element);
+
+static void solipa_zak_form_element_validator_piva_set_property (GObject *object,
+                                                                    guint property_id,
+                                                                    const GValue *value,
+                                                                    GParamSpec *pspec);
+static void solipa_zak_form_element_validator_piva_get_property (GObject *object,
+                                                                    guint property_id,
+                                                                    GValue *value,
+                                                                    GParamSpec *pspec);
+
+static void solipa_zak_form_element_validator_piva_dispose (GObject *gobject);
+static void solipa_zak_form_element_validator_piva_finalize (GObject *gobject);
+
+static gboolean solipa_zak_form_element_validator_piva_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
+static gboolean solipa_zak_form_element_validator_piva_validate (ZakFormElementValidator *validator_piva, const gchar *value);
+
+struct _SolipaZakFormElementValidatorPiva
+{
+       ZakFormElementValidator parent_instance;
+
+       /* Other members, including private data. */
+};
+
+#define SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SOLIPA_ZAK_FORM_TYPE_ELEMENT_VALIDATOR_PIVA, SolipaZakFormElementValidatorPivaPrivate))
+
+typedef struct _SolipaZakFormElementValidatorPivaPrivate SolipaZakFormElementValidatorPivaPrivate;
+struct _SolipaZakFormElementValidatorPivaPrivate
+       {
+               gboolean empty_good;
+       };
+
+G_DEFINE_TYPE (SolipaZakFormElementValidatorPiva, solipa_zak_form_element_validator_piva, ZAK_FORM_TYPE_ELEMENT_VALIDATOR)
+
+static void
+solipa_zak_form_element_validator_piva_class_init (SolipaZakFormElementValidatorPivaClass *class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (class);
+       ZakFormElementValidatorClass *parent_class = ZAK_FORM_ELEMENT_VALIDATOR_CLASS (class);
+
+       object_class->set_property = solipa_zak_form_element_validator_piva_set_property;
+       object_class->get_property = solipa_zak_form_element_validator_piva_get_property;
+       object_class->dispose = solipa_zak_form_element_validator_piva_dispose;
+       object_class->finalize = solipa_zak_form_element_validator_piva_finalize;
+
+       parent_class->xml_parsing = solipa_zak_form_element_validator_piva_xml_parsing;
+       parent_class->validate = solipa_zak_form_element_validator_piva_validate;
+
+       g_type_class_add_private (object_class, sizeof (SolipaZakFormElementValidatorPivaPrivate));
+
+       g_object_class_install_property (object_class, PROP_EMPTY_GOOD,
+                                        g_param_spec_boolean ("empty-good",
+                                                              "Empty good",
+                                                              "Empty good",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+solipa_zak_form_element_validator_piva_init (SolipaZakFormElementValidatorPiva *solipa_zak_form_element)
+{
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (solipa_zak_form_element);
+}
+
+/**
+ * solipa_zak_form_element_validator_piva_new:
+ *
+ * Returns: the newly created #SolipaZakFormElementValidatorPiva object.
+ */
+SolipaZakFormElementValidatorPiva
+*solipa_zak_form_element_validator_piva_new ()
+{
+       SolipaZakFormElementValidatorPiva *solipa_zak_form_element_validator_piva;
+
+       solipa_zak_form_element_validator_piva = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA (g_object_new (solipa_zak_form_element_validator_piva_get_type (), NULL));
+
+       return solipa_zak_form_element_validator_piva;
+}
+
+/**
+ * solipa_zak_form_element_validator_piva_xml_parsing:
+ * @validator:
+ * @xnode:
+ *
+ */
+static gboolean
+solipa_zak_form_element_validator_piva_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
+{
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       priv->empty_good = zak_utils_string_to_boolean ((gchar *)xmlNodeGetContent (xnode));
+
+       return TRUE;
+}
+
+/**
+ * solipa_zak_form_element_validator_piva_set_empty_good:
+ * @validator:
+ * @empty_good
+ *
+ */
+void
+solipa_zak_form_element_validator_piva_set_empty_good (SolipaZakFormElementValidatorPiva *validator, gboolean empty_good)
+{
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       priv->empty_good = empty_good;
+}
+
+/**
+ * solipa_zak_form_element_validator_piva_get_empty_good:
+ * @validator:
+ *
+ * Returns:
+ */
+gboolean
+solipa_zak_form_element_validator_piva_get_empty_good (SolipaZakFormElementValidatorPiva *validator)
+{
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       return priv->empty_good;
+}
+
+/* PRIVATE */
+static void
+solipa_zak_form_element_validator_piva_set_property (GObject *object,
+                                                        guint property_id,
+                                                        const GValue *value,
+                                                        GParamSpec *pspec)
+{
+       SolipaZakFormElementValidatorPiva *validator = (SolipaZakFormElementValidatorPiva *)object;
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       switch (property_id)
+               {
+               case PROP_EMPTY_GOOD:
+                       solipa_zak_form_element_validator_piva_set_empty_good (validator, g_value_get_boolean (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+solipa_zak_form_element_validator_piva_get_property (GObject *object,
+                                                        guint property_id,
+                                                        GValue *value,
+                                                        GParamSpec *pspec)
+{
+       SolipaZakFormElementValidatorPiva *validator = (SolipaZakFormElementValidatorPiva *)object;
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       switch (property_id)
+               {
+               case PROP_EMPTY_GOOD:
+                       g_value_set_boolean (value, solipa_zak_form_element_validator_piva_get_empty_good (validator));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+solipa_zak_form_element_validator_piva_dispose (GObject *gobject)
+{
+       SolipaZakFormElementValidatorPiva *validator = (SolipaZakFormElementValidatorPiva *)gobject;
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->dispose (gobject);
+}
+
+static void
+solipa_zak_form_element_validator_piva_finalize (GObject *gobject)
+{
+       SolipaZakFormElementValidatorPiva *validator = (SolipaZakFormElementValidatorPiva *)gobject;
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->finalize (gobject);
+}
+
+static gboolean
+solipa_zak_form_element_validator_piva_validate (ZakFormElementValidator *validator,
+                                                    const gchar *value)
+{
+       SolipaZakFormElementValidatorPivaPrivate *priv = SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_GET_PRIVATE (validator);
+
+       g_return_val_if_fail (value != NULL, FALSE);
+
+       return solipa_chk_partita_iva (value, priv->empty_good);
+}
diff --git a/src/formelementvalidatorpiva.h b/src/formelementvalidatorpiva.h
new file mode 100644 (file)
index 0000000..66b7b28
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_H__
+#define __SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_H__
+
+
+#include <glib-object.h>
+
+#include <libxml/tree.h>
+
+#include <libzakform/libzakform.h>
+
+
+G_BEGIN_DECLS
+
+
+#define SOLIPA_ZAK_FORM_TYPE_ELEMENT_VALIDATOR_PIVA solipa_zak_form_element_validator_piva_get_type ()
+G_DECLARE_FINAL_TYPE (SolipaZakFormElementValidatorPiva, solipa_zak_form_element_validator_piva, SOLIPA_ZAK_FORM, ELEMENT_VALIDATOR_PIVA, ZakFormElementValidator)
+
+SolipaZakFormElementValidatorPiva *solipa_zak_form_element_validator_piva_new (void);
+
+void solipa_zak_form_element_validator_piva_set_empty_good (SolipaZakFormElementValidatorPiva *validator, gboolean empty_godd);
+gboolean solipa_zak_form_element_validator_piva_get_empty_good (SolipaZakFormElementValidatorPiva *validator);
+
+
+G_END_DECLS
+
+
+#endif /* __SOLIPA_ZAK_FORM_ELEMENT_VALIDATOR_PIVA_H__ */
index 9b941d9a52492547a6d483a131699dfa0afeb040..2e001fb4edbae667adbb8aa87abc4c90809a9283 100644 (file)
@@ -23,6 +23,7 @@
 #include <libsolipa/allegato.h>
 #include <libsolipa/ctpl.h>
 #include <libsolipa/formelementvalidatorcodfisc.h>
+#include <libsolipa/formelementvalidatorpiva.h>
 #include <libsolipa/log.h>
 #include <libsolipa/mail.h>
 #include <libsolipa/mailui.h>