]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added ZakFormForm::is_changed and ::set_as_original.
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Dec 2015 10:56:42 +0000 (11:56 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Dec 2015 10:56:42 +0000 (11:56 +0100)
src/form.c
src/form.h
src/formelement.c

index e02ee79cf61db33a7c553a97d03783028b43d32a..9afc9a6f7d537066cc79d8dd78fa692717c77ce2 100644 (file)
@@ -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:
index 41569d9ab9d0e643ef7e77894244849ddb1a53df..dc3d3291336b7e43355ee51f345637044624895b 100644 (file)
@@ -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);
index ae418428e22cfa9ff45ef0ca43d21c1ec78ec6e9..604577f5d8d3e26f679f4b7d00bc7013ed4da5d0 100644 (file)
@@ -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);
 }
 
 /**