From 1e7c5a450c28cca5cd7b9ae3fee501e6b3d6e34e Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 5 Dec 2015 11:56:42 +0100 Subject: [PATCH] Added ZakFormForm::is_changed and ::set_as_original. --- src/form.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ src/form.h | 3 +++ src/formelement.c | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/form.c b/src/form.c index e02ee79..9afc9a6 100644 --- a/src/form.c +++ b/src/form.c @@ -409,6 +409,30 @@ zak_form_form_clear (ZakFormForm *zakform) } } +/** + * zak_form_form_set_as_original: + * @zakform: a #ZakFormForm object. + * + */ +void +zak_form_form_set_as_original (ZakFormForm *zakform) +{ + guint i; + + ZakFormFormPrivate *priv; + + g_return_if_fail (ZAK_FORM_IS_FORM (zakform)); + + priv = zak_form_form_get_instance_private (zakform); + + for (i = 0; i < priv->ar_elements->len; i++) + { + ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (priv->ar_elements, i); + + zak_form_element_set_as_original_value (element); + } +} + /** * zak_form_form_is_valid: * @zakform: @@ -440,6 +464,38 @@ zak_form_form_is_valid (ZakFormForm *zakform) return ret; } +/** + * zak_form_form_is_changed: + * @zakform: + * + * Returns: + */ +gboolean +zak_form_form_is_changed (ZakFormForm *zakform) +{ + guint i; + + gboolean ret; + + ZakFormFormPrivate *priv; + + priv = zak_form_form_get_instance_private (zakform); + + ret = FALSE; + + for (i = 0; i < priv->ar_elements->len; i++) + { + ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (priv->ar_elements, i); + if (zak_form_element_is_changed (element)) + { + ret = TRUE; + break; + } + } + + return ret; +} + /** * zak_form_form_load: * @zakform: diff --git a/src/form.h b/src/form.h index 41569d9..dc3d329 100644 --- a/src/form.h +++ b/src/form.h @@ -51,7 +51,10 @@ gboolean zak_form_form_add_element (ZakFormForm *zakform, ZakFormElement *elemen void zak_form_form_clear (ZakFormForm *zakform); +void zak_form_form_set_as_original (ZakFormForm *zakform); + gboolean zak_form_form_is_valid (ZakFormForm *zakform); +gboolean zak_form_form_is_changed (ZakFormForm *zakform); gboolean zak_form_form_load (ZakFormForm *zakform, ZakFormIProvider *provider); gboolean zak_form_form_insert (ZakFormForm *zakform, ZakFormIProvider *provider); diff --git a/src/formelement.c b/src/formelement.c index ae41842..604577f 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -505,7 +505,7 @@ zak_form_element_set_as_original_value (ZakFormElement *element) gboolean zak_form_element_is_changed (ZakFormElement *element) { - return (g_strcmp0 (zak_form_element_get_original_value (element), zak_form_element_get_value (element)) == 0); + return (g_strcmp0 (zak_form_element_get_original_value (element), zak_form_element_get_value (element)) != 0); } /** -- 2.49.0