]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added property id to ZakFormElementFilter (closes #1102).
authorAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 09:09:07 +0000 (11:09 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 09:09:07 +0000 (11:09 +0200)
Added function ZakFormElement::get_filter_by_id.

src/formelement.c
src/formelement.h
src/formelementfilter.c
src/formelementfilter.h

index f94eb62f56f2e6e2330210f925c61ed09967c378..ce68b320f3270b6cc0c2e31d10f52fc764dc2677 100644 (file)
@@ -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;
-
-
 }
 
 /**
index bf15098231231c2f0634961b19869e5d7b76ff9f..9a29bad0cd39d0e63a3851bd74e75d5b1be0089b 100644 (file)
@@ -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);
index 3439ac97f85e6bc0c88bfa941596aaf1e2237849..43e58239eb65742f939d4ba6c10026bc50717e33 100644 (file)
@@ -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;
index 8ae7f3c767b14064eb30083cf5186bbcf4464122..468c74aed183588fd474a023bc5335571d11532e 100644 (file)
@@ -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);