From: Andrea Zagli Date: Sat, 22 Apr 2017 09:09:07 +0000 (+0200) Subject: Added property id to ZakFormElementFilter (closes #1102). X-Git-Tag: v0.1.0~1^2~21 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=ca884aabd12866b7347991a6ed23b7061f77c033;p=zakform%2Flibzakform Added property id to ZakFormElementFilter (closes #1102). Added function ZakFormElement::get_filter_by_id. --- diff --git a/src/formelement.c b/src/formelement.c index f94eb62..ce68b32 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -323,6 +323,35 @@ GPtrArray return priv->pa_filters; } +/** + * zak_form_element_get_filter_by_id: + * @element: + * @id: + * + */ +ZakFormElementFilter +*zak_form_element_get_filter_by_id (ZakFormElement *element, const gchar *id) +{ + ZakFormElementFilter *filter; + + guint i; + + ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element); + + filter = NULL; + + for (i = 0; i < priv->pa_filters->len; i++) + { + if (g_strcmp0 (zak_form_element_filter_get_id ((ZakFormElementFilter *)g_ptr_array_index (priv->pa_filters, i)), id) == 0) + { + filter = (ZakFormElementFilter *)g_ptr_array_index (priv->pa_filters, i); + break; + } + } + + return filter; +} + /** * zak_form_element_get_filters_by_type: * @element: @@ -1127,8 +1156,6 @@ ZakFormElementValidator } return validator; - - } /** diff --git a/src/formelement.h b/src/formelement.h index bf15098..9a29bad 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -102,6 +102,7 @@ void zak_form_element_add_filter (ZakFormElement *element, ZakFormElementFilter void zak_form_element_filter (ZakFormElement *element); GPtrArray *zak_form_element_get_filters (ZakFormElement *element); +ZakFormElementFilter *zak_form_element_get_filter_by_id (ZakFormElement *element, const gchar *id); GPtrArray *zak_form_element_get_filters_by_type (ZakFormElement *element, GType type); void zak_form_element_add_validator (ZakFormElement *element, ZakFormElementValidator *validator); diff --git a/src/formelementfilter.c b/src/formelementfilter.c index 3439ac9..43e5823 100644 --- a/src/formelementfilter.c +++ b/src/formelementfilter.c @@ -25,6 +25,7 @@ enum { PROP_0, + PROP_ID, PROP_ENABLED }; @@ -45,6 +46,7 @@ static void zak_form_element_filter_finalize (GObject *gobject); typedef struct { + gchar *id; gboolean enabled; } ZakFormElementFilterPrivate; @@ -60,6 +62,13 @@ zak_form_element_filter_class_init (ZakFormElementFilterClass *class) object_class->dispose = zak_form_element_filter_dispose; object_class->finalize = zak_form_element_filter_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", @@ -79,8 +88,17 @@ zak_form_element_filter_xml_parsing (ZakFormElementFilter *self, xmlNode *xnode) { gboolean ret; + gchar *prop; + g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_FILTER (self), FALSE); + prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"id"); + if (prop != NULL) + { + zak_form_element_filter_set_id (self, prop); + g_free (prop); + } + if (ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing!= NULL) { ret = ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing (self, xnode); @@ -93,6 +111,42 @@ zak_form_element_filter_xml_parsing (ZakFormElementFilter *self, xmlNode *xnode) return ret; } +/** + * zak_form_element_filter_set_id: + * @filter: + * @id: + * + */ +void +zak_form_element_filter_set_id (ZakFormElementFilter *filter, + const gchar *id) +{ + ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (filter); + + if (id == NULL) + { + priv->id = g_strdup (""); + } + else + { + priv->id = g_strdup (id); + } +} + +/** + * zak_form_element_filter_get_id: + * @filter: + * + * Returns: + */ +gchar +*zak_form_element_filter_get_id (ZakFormElementFilter *filter) +{ + ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (filter); + + return g_strdup (priv->id); +} + gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value) { @@ -153,6 +207,10 @@ zak_form_element_filter_set_property (GObject *object, switch (property_id) { + case PROP_ID: + zak_form_element_filter_set_id (zak_form_element_filter, g_value_get_string (value)); + break; + case PROP_ENABLED: zak_form_element_filter_set_enabled (zak_form_element_filter, g_value_get_boolean (value)); break; @@ -174,6 +232,10 @@ zak_form_element_filter_get_property (GObject *object, switch (property_id) { + case PROP_ID: + g_value_set_string (value, zak_form_element_filter_get_id (zak_form_element_filter)); + break; + case PROP_ENABLED: g_value_set_boolean (value, zak_form_element_filter_get_enabled (zak_form_element_filter)); break; diff --git a/src/formelementfilter.h b/src/formelementfilter.h index 8ae7f3c..468c74a 100644 --- a/src/formelementfilter.h +++ b/src/formelementfilter.h @@ -41,6 +41,10 @@ struct _ZakFormElementFilterClass gboolean zak_form_element_filter_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode); gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value); +void zak_form_element_filter_set_id (ZakFormElementFilter *filter, + const gchar *id); +gchar *zak_form_element_filter_get_id (ZakFormElementFilter *filter); + gboolean zak_form_element_filter_get_enabled (ZakFormElementFilter *filter); void zak_form_element_filter_set_enabled (ZakFormElementFilter *filter, gboolean enabled);