From: Andrea Zagli Date: Sat, 28 Jan 2017 10:53:57 +0000 (+0100) Subject: Added functions ZakFormElement::get_validators and ::get_element_validators_by_type... X-Git-Tag: v0.1.0~5 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b047746cc3d2af59d6b50c6708940d1767744b0d;p=zakform%2Flibzakform Added functions ZakFormElement::get_validators and ::get_element_validators_by_type (closes #1103). --- diff --git a/src/formelement.c b/src/formelement.c index 52efa66..ccf762a 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -261,7 +261,7 @@ zak_form_element_filter (ZakFormElement *element) * zak_form_element_get_filters: * @zakform: * - * Returns: a #GPtrArray with the list of ZakFormElement's in the form. + * Returns: a #GPtrArray with the list of ZakFormElementFilter's in the form element. */ GPtrArray *zak_form_element_get_filters (ZakFormElement *element) @@ -1116,6 +1116,50 @@ GPtrArray return priv->pa_messages; } +/** + * zak_form_element_get_validators: + * @zakform: + * + * Returns: a #GPtrArray with the list of ZakFormElementValidator's in the form element. + */ +GPtrArray +*zak_form_element_get_validators(ZakFormElement *element) +{ + ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element); + + return priv->pa_validators; +} + +/** + * zak_form_element_get_validators_by_type: + * @element: + * @type: + * + * Returns: a #GPtrArray with the list of ZakFormElementValidator's in the form element filtered by @type. + */ +GPtrArray +*zak_form_element_get_validators_by_type (ZakFormElement *element, GType type) +{ + GPtrArray *ar; + ZakFormElementFilter *filter; + + guint i; + + ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element); + + ar = g_ptr_array_new (); + for (i = 0; i < priv->pa_validators->len; i++) + { + filter = (ZakFormElementFilter *)g_ptr_array_index (priv->pa_validators, i); + if (G_OBJECT_TYPE (filter) == type) + { + g_ptr_array_add (ar, filter); + } + } + + return ar; +} + /* PRIVATE */ static void zak_form_element_set_property (GObject *object, diff --git a/src/formelement.h b/src/formelement.h index ebf9df8..4803533 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -103,6 +103,10 @@ void zak_form_element_add_validator (ZakFormElement *element, ZakFormElementVali gboolean zak_form_element_is_valid (ZakFormElement *element); GPtrArray *zak_form_element_get_messages (ZakFormElement *element); +GPtrArray *zak_form_element_get_validators (ZakFormElement *element); +GPtrArray *zak_form_element_get_validators_by_type (ZakFormElement *element, GType type); + + G_END_DECLS diff --git a/src/formelementvalidatordate.c b/src/formelementvalidatordate.c index 2546c61..df7d0f5 100644 --- a/src/formelementvalidatordate.c +++ b/src/formelementvalidatordate.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 @@ -49,7 +49,7 @@ struct _ZakFormElementValidatorDate /* Other members, including private data. */ }; -#define ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_TYPE_FORM_ELEMENT_VALIDATOR_DATE, ZakFormElementValidatorDatePrivate)) +#define ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_ELEMENT_VALIDATOR_DATE, ZakFormElementValidatorDatePrivate)) typedef struct _ZakFormElementValidatorDatePrivate ZakFormElementValidatorDatePrivate; struct _ZakFormElementValidatorDatePrivate diff --git a/src/formelementvalidatordate.h b/src/formelementvalidatordate.h index accea52..13b5f38 100644 --- a/src/formelementvalidatordate.h +++ b/src/formelementvalidatordate.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 @@ -30,7 +30,7 @@ G_BEGIN_DECLS -#define ZAK_TYPE_FORM_ELEMENT_VALIDATOR_DATE zak_form_element_validator_date_get_type () +#define ZAK_FORM_TYPE_ELEMENT_VALIDATOR_DATE zak_form_element_validator_date_get_type () G_DECLARE_FINAL_TYPE (ZakFormElementValidatorDate, zak_form_element_validator_date, ZAK_FORM, ELEMENT_VALIDATOR_DATE, ZakFormElementValidator) ZakFormElementValidatorDate *zak_form_element_validator_date_new (void); diff --git a/src/formelementvalidatornotempty.c b/src/formelementvalidatornotempty.c index 1de3f30..91de807 100644 --- a/src/formelementvalidatornotempty.c +++ b/src/formelementvalidatornotempty.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 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 @@ -47,7 +47,7 @@ struct _ZakFormElementValidatorNotempty /* Other members, including private data. */ }; -#define ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_TYPE_FORM_ELEMENT_VALIDATOR_NOTEMPTY, ZakFormElementValidatorNotemptyPrivate)) +#define ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_ELEMENT_VALIDATOR_NOTEMPTY, ZakFormElementValidatorNotemptyPrivate)) typedef struct _ZakFormElementValidatorNotemptyPrivate ZakFormElementValidatorNotemptyPrivate; struct _ZakFormElementValidatorNotemptyPrivate diff --git a/src/formelementvalidatornotempty.h b/src/formelementvalidatornotempty.h index b4885bf..c6c4a2e 100644 --- a/src/formelementvalidatornotempty.h +++ b/src/formelementvalidatornotempty.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 @@ -30,7 +30,7 @@ G_BEGIN_DECLS -#define ZAK_TYPE_FORM_ELEMENT_VALIDATOR_NOTEMPTY zak_form_element_validator_notempty_get_type () +#define ZAK_FORM_TYPE_ELEMENT_VALIDATOR_NOTEMPTY zak_form_element_validator_notempty_get_type () G_DECLARE_FINAL_TYPE (ZakFormElementValidatorNotempty, zak_form_element_validator_notempty, ZAK_FORM, ELEMENT_VALIDATOR_NOTEMPTY, ZakFormElementValidator) ZakFormElementValidatorNotempty *zak_form_element_validator_notempty_new (void); diff --git a/src/formelementvalidatorregex.c b/src/formelementvalidatorregex.c index cd92203..a0d5b2b 100644 --- a/src/formelementvalidatorregex.c +++ b/src/formelementvalidatorregex.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 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 @@ -53,7 +53,7 @@ struct _ZakFormElementValidatorRegex /* Other members, including private data. */ }; -#define ZAK_FORM_ELEMENT_VALIDATOR_REGEX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_TYPE_FORM_ELEMENT_VALIDATOR_REGEX, ZakFormElementValidatorRegexPrivate)) +#define ZAK_FORM_ELEMENT_VALIDATOR_REGEX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_ELEMENT_VALIDATOR_REGEX, ZakFormElementValidatorRegexPrivate)) typedef struct _ZakFormElementValidatorRegexPrivate ZakFormElementValidatorRegexPrivate; struct _ZakFormElementValidatorRegexPrivate diff --git a/src/formelementvalidatorregex.h b/src/formelementvalidatorregex.h index 3ed9948..4bb8b42 100644 --- a/src/formelementvalidatorregex.h +++ b/src/formelementvalidatorregex.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 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 @@ -30,7 +30,7 @@ G_BEGIN_DECLS -#define ZAK_TYPE_FORM_ELEMENT_VALIDATOR_REGEX zak_form_element_validator_regex_get_type () +#define ZAK_FORM_TYPE_ELEMENT_VALIDATOR_REGEX zak_form_element_validator_regex_get_type () G_DECLARE_FINAL_TYPE (ZakFormElementValidatorRegex, zak_form_element_validator_regex, ZAK_FORM, ELEMENT_VALIDATOR_REGEX, ZakFormElementValidator) ZakFormElementValidatorRegex *zak_form_element_validator_regex_new (void);