Refactored ZakFormValidator::xml_parsing.
typedef ZakFormElementValidator *(* FormElementValidatorConstructorFunc) (void);
typedef gboolean (* FormElementValidatorXmlParsingFunc) (ZakFormElementValidator *, xmlNodePtr);
typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void);
-typedef gboolean (* FormValidatorXmlParsingFunc) (ZakFormValidator *, xmlNodePtr, GPtrArray *);
static void zak_form_form_class_init (ZakFormFormClass *class);
static void zak_form_form_init (ZakFormForm *zak_form_form);
FormElementXmlParsingFunc element_xml_parsing;
FormValidatorConstructorFunc validator_constructor;
- FormValidatorXmlParsingFunc validator_xml_parsing;
xmlXPathContextPtr xpcontext;
xmlXPathObjectPtr xpresult;
validator = validator_constructor ();
zak_form_form_add_validator (zakform, validator);
- if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
- g_strconcat (type, "_xml_parsing", NULL),
- (gpointer *)&validator_xml_parsing))
- {
- if (validator_xml_parsing != NULL)
- {
- validator_xml_parsing (validator, xnodeset->nodeTab[y], priv->ar_elements);
- }
- }
+ zak_form_validator_xml_parsing (validator, xnodeset->nodeTab[y], priv->ar_elements);
break;
}
enum
{
PROP_0,
+ PROP_ID,
PROP_ENABLED,
PROP_MESSAGE
};
static void zak_form_validator_init (ZakFormValidator *zak_form_validator);
static void zak_form_validator_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
static void zak_form_validator_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
static void zak_form_validator_dispose (GObject *gobject);
static void zak_form_validator_finalize (GObject *gobject);
typedef struct
{
+ gchar *id;
gboolean enabled;
gchar *message;
} ZakFormValidatorPrivate;
object_class->dispose = zak_form_validator_dispose;
object_class->finalize = zak_form_validator_finalize;
+ g_object_class_install_property (object_class, PROP_ID,
+ g_param_spec_string ("id",
+ "Id",
+ "Id",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property (object_class, PROP_ENABLED,
- g_param_spec_boolean ("enabled",
- "Enabled",
- "Enabled",
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "Enabled",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_MESSAGE,
- g_param_spec_string ("message",
- "Message",
- "Message",
- _("Invalid value"),
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_string ("message",
+ "Message",
+ "Message",
+ _("Invalid value"),
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (zak_form_validator);
}
+/**
+ * zak_form_validator_xml_parsing:
+ * @validator:
+ * @xnode:
+ * @ar_elements:
+ *
+ * Retuns:
+ */
+gboolean
+zak_form_validator_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements)
+{
+ gboolean ret;
+
+ gchar *prop;
+
+ g_return_val_if_fail (ZAK_FORM_IS_VALIDATOR (validator), FALSE);
+
+ ret = TRUE;
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"id");
+ if (prop != NULL)
+ {
+ zak_form_validator_set_id (validator, prop);
+ g_free (prop);
+ }
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"message");
+ if (prop != NULL)
+ {
+ zak_form_validator_set_message (validator, prop);
+ g_free (prop);
+ }
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"disabled");
+ if (prop != NULL)
+ {
+ zak_form_validator_set_enabled (validator, FALSE);
+ g_free (prop);
+ }
+
+ if (ZAK_FORM_VALIDATOR_GET_CLASS (validator)->xml_parsing != NULL)
+ {
+ ret = ZAK_FORM_VALIDATOR_GET_CLASS (validator)->xml_parsing (validator, xnode, ar_elements);
+ }
+
+ return ret;
+}
+
+/**
+ * zak_form_validator_set_id:
+ * @validator:
+ * @id:
+ *
+ */
+void
+zak_form_validator_set_id (ZakFormValidator *validator,
+ const gchar *id)
+{
+ ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
+
+ if (id == NULL)
+ {
+ priv->id = g_strdup ("");
+ }
+ else
+ {
+ priv->id = g_strdup (id);
+ }
+}
+
+/**
+ * zak_form_validator_get_id:
+ * @validator:
+ *
+ * Returns:
+ */
+gchar
+*zak_form_validator_get_id (ZakFormValidator *validator)
+{
+ ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
+
+ return g_strdup (priv->id);
+}
+
+
gboolean
zak_form_validator_validate (ZakFormValidator *self)
{
*/
void
zak_form_validator_set_message (ZakFormValidator *validator,
- const gchar *message)
+ const gchar *message)
{
ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
{
ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
- return g_strdup (priv->message);
+ return g_strdup (priv->message);
}
/**
switch (property_id)
{
+ case PROP_ID:
+ zak_form_validator_set_id (zak_form_validator, g_value_dup_string (value));
+ break;
+
case PROP_ENABLED:
zak_form_validator_set_enabled (zak_form_validator, g_value_get_boolean (value));
break;
switch (property_id)
{
+ case PROP_ID:
+ g_value_set_string (value, zak_form_validator_get_id (zak_form_validator));
+ break;
+
case PROP_ENABLED:
g_value_set_boolean (value, zak_form_validator_get_enabled (zak_form_validator));
break;
#include <glib-object.h>
+#include <libxml/xpath.h>
+
G_BEGIN_DECLS
{
GObjectClass parent_class;
+ gboolean (*xml_parsing) (ZakFormValidator *self, xmlNode *xnode, GPtrArray *ar_elements);
gboolean (*validate) (ZakFormValidator *self);
};
+gboolean zak_form_validator_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements);
+
+gchar *zak_form_validator_get_id (ZakFormValidator *validator);
+void zak_form_validator_set_id (ZakFormValidator *validator, const gchar *id);
+
gboolean zak_form_validator_validate (ZakFormValidator *self);
void zak_form_validator_set_message (ZakFormValidator *validator,
- const gchar *message);
+ const gchar *message);
gchar *zak_form_validator_get_message (ZakFormValidator *validator);
gboolean zak_form_validator_get_enabled (ZakFormValidator *validator);
static void zak_form_validator_compare_dispose (GObject *gobject);
static void zak_form_validator_compare_finalize (GObject *gobject);
+static gboolean zak_form_validator_compare_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements);
static gboolean zak_form_validator_compare_validate (ZakFormValidator *validator_notempty);
struct _ZakFormValidatorCompare
object_class->dispose = zak_form_validator_compare_dispose;
object_class->finalize = zak_form_validator_compare_finalize;
+ parent_class->xml_parsing = zak_form_validator_compare_xml_parsing;
parent_class->validate = zak_form_validator_compare_validate;
g_type_class_add_private (object_class, sizeof (ZakFormValidatorComparePrivate));
* @ar_elements:
*
*/
-gboolean
+static gboolean
zak_form_validator_compare_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements)
{
gchar *prop;
/*
- * Copyright (C) 2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2016-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
G_DECLARE_FINAL_TYPE (ZakFormValidatorCompare, zak_form_validator_compare, ZAK_FORM, VALIDATOR_COMPARE, ZakFormValidator)
ZakFormValidatorCompare *zak_form_validator_compare_new (void);
-gboolean zak_form_validator_compare_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements);
G_END_DECLS
/*
- * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-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
static void zak_form_validator_compare_date_dispose (GObject *gobject);
static void zak_form_validator_compare_date_finalize (GObject *gobject);
+static gboolean zak_form_validator_compare_date_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements);
static gboolean zak_form_validator_compare_date_validate (ZakFormValidator *validator_notempty);
struct _ZakFormValidatorCompareDate
object_class->dispose = zak_form_validator_compare_date_dispose;
object_class->finalize = zak_form_validator_compare_date_finalize;
+ parent_class->xml_parsing = zak_form_validator_compare_date_xml_parsing;
parent_class->validate = zak_form_validator_compare_date_validate;
g_type_class_add_private (object_class, sizeof (ZakFormValidatorCompareDatePrivate));
* @ar_elements:
*
*/
-gboolean
+static gboolean
zak_form_validator_compare_date_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements)
{
gchar *prop;
/* PRIVATE */
static void
zak_form_validator_compare_date_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
ZakFormValidatorCompareDate *validator = (ZakFormValidatorCompareDate *)object;
ZakFormValidatorCompareDatePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_DATE_GET_PRIVATE (validator);
static void
zak_form_validator_compare_date_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
ZakFormValidatorCompareDate *validator = (ZakFormValidatorCompareDate *)object;
ZakFormValidatorCompareDatePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_DATE_GET_PRIVATE (validator);
/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-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
G_DECLARE_FINAL_TYPE (ZakFormValidatorCompareDate, zak_form_validator_compare_date, ZAK_FORM, VALIDATOR_COMPARE_DATE, ZakFormValidator)
ZakFormValidatorCompareDate *zak_form_validator_compare_date_new (void);
-gboolean zak_form_validator_compare_date_xml_parsing (ZakFormValidator *validator, xmlNode *xnode, GPtrArray *ar_elements);
G_END_DECLS