From 5e6801a0a12dbd725628363f3a59e5c5b0436c7a Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 28 Jan 2017 10:59:00 +0100 Subject: [PATCH] Added function ZakFormForm::get_validators and ::get_validators_by_type (refs #1103). --- src/form.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/form.h | 2 ++ src/libzakform.h | 4 +++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/form.c b/src/form.c index f9d2c81..65d27d8 100644 --- a/src/form.c +++ b/src/form.c @@ -573,6 +573,50 @@ zak_form_form_add_validator (ZakFormForm *zakform, ZakFormValidator *validator) return ret; } +/** + * zak_form_form_get_validators: + * @zakform: + * + * Returns: a #GPtrArray with the list of ZakFormValidator's in the form. + */ +GPtrArray +*zak_form_form_get_validators (ZakFormForm *zakform) +{ + ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); + + return priv->ar_validators; +} + +/** + * zak_form_form_get_validators_by_type: + * @zakform: + * @type: + * + * Returns: a #GPtrArray with the list of ZakFormValidator's in the form filtered by @type. + */ +GPtrArray +*zak_form_form_get_validators_by_type (ZakFormForm *zakform, GType type) +{ + GPtrArray *ar; + ZakFormValidator *validator; + + guint i; + + ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); + + ar = g_ptr_array_new (); + for (i = 0; i < priv->ar_validators->len; i++) + { + validator = (ZakFormValidator *)g_ptr_array_index (priv->ar_validators, i); + if (G_OBJECT_TYPE (validator) == type) + { + g_ptr_array_add (ar, validator); + } + } + + return ar; +} + /** * zak_form_form_clear: * @zakform: a #ZakFormForm object. diff --git a/src/form.h b/src/form.h index 88c4cfd..33b65ea 100644 --- a/src/form.h +++ b/src/form.h @@ -54,6 +54,8 @@ GPtrArray *zak_form_form_get_elements (ZakFormForm *zakform); GPtrArray *zak_form_form_get_elements_by_type (ZakFormForm *zakform, GType type); gboolean zak_form_form_add_validator (ZakFormForm *zakform, ZakFormValidator *validator); +GPtrArray *zak_form_form_get_validators (ZakFormForm *zakform); +GPtrArray *zak_form_form_get_validators_by_type (ZakFormForm *zakform, GType type); void zak_form_form_clear (ZakFormForm *zakform); diff --git a/src/libzakform.h b/src/libzakform.h index b5aaf41..e3ba88a 100644 --- a/src/libzakform.h +++ b/src/libzakform.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 @@ -36,6 +36,8 @@ #include #include +#include +#include #endif /* __LIBZAKFORM_H__ */ -- 2.49.0