From e8d1acd8f74a190b5fbb5c023f2acff35faab4f0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 22 Apr 2017 10:55:36 +0200 Subject: [PATCH] Refactored ZakFormElementFilter::xml_parsing. --- src/form.c | 14 ++-------- src/formelement.c | 2 +- src/formelementfilter.c | 53 +++++++++++++++++++++++++------------ src/formelementfilter.h | 4 +++ src/formelementfilterluc.c | 20 +++++++------- src/formelementfilterluc.h | 3 +-- src/formelementfiltertrim.c | 22 ++++++++------- src/formelementfiltertrim.h | 3 +-- 8 files changed, 68 insertions(+), 53 deletions(-) diff --git a/src/form.c b/src/form.c index c58bbeb..c14a235 100644 --- a/src/form.c +++ b/src/form.c @@ -38,7 +38,6 @@ typedef gboolean (* FormElementXmlParsingFunc) (ZakFormElement *, xmlNodePtr); typedef GObject *(* FormElementExtensionConstructorFunc) (void); typedef gboolean (* FormElementExtensionXmlParsingFunc) (GObject *, xmlNodePtr); typedef ZakFormElementFilter *(* FormElementFilterConstructorFunc) (void); -typedef gboolean (* FormElementFilterXmlParsingFunc) (ZakFormElementFilter *, xmlNodePtr); typedef ZakFormElementValidator *(* FormElementValidatorConstructorFunc) (void); typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void); @@ -167,7 +166,6 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element FormElementExtensionConstructorFunc extension_constructor; FormElementExtensionXmlParsingFunc extension_xml_parsing; FormElementFilterConstructorFunc filter_constructor; - FormElementFilterXmlParsingFunc filter_xml_parsing; FormElementValidatorConstructorFunc validator_constructor; gboolean to_unlink; @@ -233,15 +231,7 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element filter = filter_constructor (); zak_form_element_add_filter (element, filter); - if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i), - g_strconcat (type, "_xml_parsing", NULL), - (gpointer *)&filter_xml_parsing)) - { - if (filter_xml_parsing != NULL) - { - filter_xml_parsing (filter, xnode); - } - } + zak_form_element_filter_xml_parsing (filter, xnode); break; } @@ -254,7 +244,7 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element to_unlink = TRUE; } - else if (xmlStrcmp (xnode->name, (const xmlChar *)"validator") == 0) + else if (xmlStrcmp (xnode->name, (const xmlChar *)"validator") == 0) { type = xmlGetProp (xnode, (const xmlChar *)"type"); diff --git a/src/formelement.c b/src/formelement.c index bac1f7e..f94eb62 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -304,7 +304,7 @@ zak_form_element_filter (ZakFormElement *element) value = zak_form_element_get_value (element); val = zak_form_element_filter_filter ((ZakFormElementFilter *)g_ptr_array_index (priv->pa_filters, i), - value); + value); zak_form_element_set_value (element, val); } } diff --git a/src/formelementfilter.c b/src/formelementfilter.c index fe3ce9a..3439ac9 100644 --- a/src/formelementfilter.c +++ b/src/formelementfilter.c @@ -32,13 +32,13 @@ static void zak_form_element_filter_class_init (ZakFormElementFilterClass *class static void zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter); static void zak_form_element_filter_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_filter_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); + guint property_id, + GValue *value, + GParamSpec *pspec); static void zak_form_element_filter_dispose (GObject *gobject); static void zak_form_element_filter_finalize (GObject *gobject); @@ -61,11 +61,11 @@ zak_form_element_filter_class_init (ZakFormElementFilterClass *class) object_class->finalize = zak_form_element_filter_finalize; 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)); } static void @@ -74,6 +74,25 @@ zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter) ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter); } +gboolean +zak_form_element_filter_xml_parsing (ZakFormElementFilter *self, xmlNode *xnode) +{ + gboolean ret; + + g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_FILTER (self), FALSE); + + if (ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing!= NULL) + { + ret = ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing (self, xnode); + } + else + { + ret = FALSE; + } + + return ret; +} + gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value) { @@ -125,9 +144,9 @@ zak_form_element_filter_set_enabled (ZakFormElementFilter *filter, gboolean enab /* PRIVATE */ static void zak_form_element_filter_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) + guint property_id, + const GValue *value, + GParamSpec *pspec) { ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object; ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter); @@ -146,9 +165,9 @@ zak_form_element_filter_set_property (GObject *object, static void zak_form_element_filter_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) + guint property_id, + GValue *value, + GParamSpec *pspec) { ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object; ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter); diff --git a/src/formelementfilter.h b/src/formelementfilter.h index 1dffefb..8ae7f3c 100644 --- a/src/formelementfilter.h +++ b/src/formelementfilter.h @@ -21,6 +21,8 @@ #include +#include + G_BEGIN_DECLS @@ -32,9 +34,11 @@ struct _ZakFormElementFilterClass { GObjectClass parent_cleass; + gboolean (*xml_parsing) (ZakFormElementFilter *filter, xmlNode *xnode); gchar *(*filter) (ZakFormElementFilter *self, const gchar *value); }; +gboolean zak_form_element_filter_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value); gboolean zak_form_element_filter_get_enabled (ZakFormElementFilter *filter); diff --git a/src/formelementfilterluc.c b/src/formelementfilterluc.c index 543043a..ee9d928 100644 --- a/src/formelementfilterluc.c +++ b/src/formelementfilterluc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,6 +42,7 @@ static void zak_form_element_filter_luc_get_property (GObject *object, static void zak_form_element_filter_luc_dispose (GObject *gobject); static void zak_form_element_filter_luc_finalize (GObject *gobject); +static gboolean zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); static gchar *zak_form_element_filter_luc_filter (ZakFormElementFilter *filter_luc, const gchar *value); enum @@ -79,6 +80,7 @@ zak_form_element_filter_luc_class_init (ZakFormElementFilterLucClass *class) object_class->dispose = zak_form_element_filter_luc_dispose; object_class->finalize = zak_form_element_filter_luc_finalize; + parent_class->xml_parsing = zak_form_element_filter_luc_xml_parsing; parent_class->filter = zak_form_element_filter_luc_filter; g_type_class_add_private (object_class, sizeof (ZakFormElementFilterLucPrivate)); @@ -111,7 +113,7 @@ ZakFormElementFilterLuc * @xnode: * */ -gboolean +static gboolean zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode) { gchar *content; @@ -138,9 +140,9 @@ zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode * /* PRIVATE */ static void zak_form_element_filter_luc_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) + guint property_id, + const GValue *value, + GParamSpec *pspec) { ZakFormElementFilterLuc *zak_form_element = (ZakFormElementFilterLuc *)object; ZakFormElementFilterLucPrivate *priv = ZAK_FORM_ELEMENT_FILTER_LUC_GET_PRIVATE (zak_form_element); @@ -155,9 +157,9 @@ zak_form_element_filter_luc_set_property (GObject *object, static void zak_form_element_filter_luc_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) + guint property_id, + GValue *value, + GParamSpec *pspec) { ZakFormElementFilterLuc *zak_form_element = (ZakFormElementFilterLuc *)object; ZakFormElementFilterLucPrivate *priv = ZAK_FORM_ELEMENT_FILTER_LUC_GET_PRIVATE (zak_form_element); @@ -196,7 +198,7 @@ zak_form_element_filter_luc_finalize (GObject *gobject) static gchar *zak_form_element_filter_luc_filter (ZakFormElementFilter *filter_luc, - const gchar *value) + const gchar *value) { gchar *ret; gchar *_value; diff --git a/src/formelementfilterluc.h b/src/formelementfilterluc.h index eb00250..6710a15 100644 --- a/src/formelementfilterluc.h +++ b/src/formelementfilterluc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,7 +34,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (ZakFormElementFilterLuc, zak_form_element_filter_luc, ZAK_FORM, ELEMENT_FILTER_LUC, ZakFormElementFilter) ZakFormElementFilterLuc *zak_form_element_filter_luc_new (void); -gboolean zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); G_END_DECLS diff --git a/src/formelementfiltertrim.c b/src/formelementfiltertrim.c index 6acafbd..1a891a8 100644 --- a/src/formelementfiltertrim.c +++ b/src/formelementfiltertrim.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,17 +27,18 @@ static void zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimCla static void zak_form_element_filter_trim_init (ZakFormElementFilterTrim *zak_form_element); static void zak_form_element_filter_trim_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_filter_trim_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); + guint property_id, + GValue *value, + GParamSpec *pspec); static void zak_form_element_filter_trim_dispose (GObject *gobject); static void zak_form_element_filter_trim_finalize (GObject *gobject); +static gboolean zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); static gchar *zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim, const gchar *value); struct _ZakFormElementFilterTrim @@ -68,6 +69,7 @@ zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimClass *class) object_class->dispose = zak_form_element_filter_trim_dispose; object_class->finalize = zak_form_element_filter_trim_finalize; + parent_class->xml_parsing = zak_form_element_filter_trim_xml_parsing; parent_class->filter = zak_form_element_filter_trim_filter; g_type_class_add_private (object_class, sizeof (ZakFormElementFilterTrimPrivate)); @@ -100,7 +102,7 @@ ZakFormElementFilterTrim * @xnode: * */ -gboolean +static gboolean zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode) { /* nothing to do */ @@ -172,7 +174,7 @@ zak_form_element_filter_trim_finalize (GObject *gobject) static gchar *zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim, - const gchar *value) + const gchar *value) { gchar *ret; gchar *_value; @@ -181,7 +183,7 @@ static gchar _value = g_strdup (value); - ret = g_strdup (g_strstrip (_value)); + ret = g_strdup (g_strstrip (_value)); return ret; } diff --git a/src/formelementfiltertrim.h b/src/formelementfiltertrim.h index d74e0bf..aa50296 100644 --- a/src/formelementfiltertrim.h +++ b/src/formelementfiltertrim.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,7 +34,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (ZakFormElementFilterTrim, zak_form_element_filter_trim, ZAK_FORM, ELEMENT_FILTER_TRIM, ZakFormElementFilter) ZakFormElementFilterTrim *zak_form_element_filter_trim_new (void); -gboolean zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); G_END_DECLS -- 2.49.0