--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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__ */