/*
- * Copyright (C) 2016-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2016-2020 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <libzakutils/libzakutils.h>
#include "commons.h"
-#include "form.h"
#include "formvalidator.h"
#include "formvalidatorcompare.h"
ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type_comp");
- priv->type = zak_form_get_compare_type_from_string (prop);
+ zak_form_validator_compare_set_compare_type ((ZakFormValidatorCompare *)validator, prop);
g_free (prop);
prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element1");
- priv->v1 = zak_form_form_get_element_by_id ((ZakFormForm *)form, prop);
+ zak_form_validator_compare_set_element1 ((ZakFormValidatorCompare *)validator, (ZakFormForm *)form, prop);
+ g_free (prop);
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element2");
+ zak_form_validator_compare_set_element2 ((ZakFormValidatorCompare *)validator, (ZakFormForm *)form, prop);
+ g_free (prop);
+
+ return TRUE;
+}
+
+/**
+ * zak_form_validator_compare_set_compare_type:
+ * @validator:
+ * @type:
+ *
+ * Sets the validator compare type.
+ */
+void
+zak_form_validator_compare_set_compare_type (ZakFormValidatorCompare *validator, const gchar *type)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ priv->type = zak_form_get_compare_type_from_string (type);
+}
+
+/**
+ * zak_form_validator_compare_get_compare_type:
+ * @validator:
+ *
+ * Returns: the validator compare type.
+ */
+const gchar
+*zak_form_validator_compare_get_compare_type (ZakFormValidatorCompare *validator)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ zak_form_get_compare_type_stringify (priv->type);
+}
+
+/**
+ * zak_form_validator_compare_set_element1:
+ * @validator:
+ * @element1:
+ *
+ * Sets the validator element1.
+ */
+void
+zak_form_validator_compare_set_element1 (ZakFormValidatorCompare *validator, ZakFormForm *form, const gchar *element1)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ priv->v1 = zak_form_form_get_element_by_id (form, element1);
if (!ZAK_FORM_IS_ELEMENT (priv->v1))
{
- g_warning ("Validator compare: element1 isn't a ZakFormElement.");
+ g_warning ("Validator compare: element «%s» isn't a ZakFormElement.", element1);
}
- g_free (prop);
+}
- prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element2");
- priv->v2 = zak_form_form_get_element_by_id ((ZakFormForm *)form, prop);
+/**
+ * zak_form_validator_compare_get_element1:
+ * @validator:
+ *
+ * Returns: the validator element1 name.
+ */
+const gchar
+*zak_form_validator_compare_get_element1 (ZakFormValidatorCompare *validator)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ if (ZAK_FORM_IS_ELEMENT (priv->v2))
+ {
+ return zak_form_element_get_name (priv->v2);
+ }
+ else
+ {
+ return "";
+ }
+}
+
+/**
+ * zak_form_validator_compare_set_element2:
+ * @validator:
+ * @element2:
+ *
+ * Sets the validator element2.
+ */
+void
+zak_form_validator_compare_set_element2 (ZakFormValidatorCompare *validator, ZakFormForm *form, const gchar *element2)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ priv->v1 = zak_form_form_get_element_by_id (form, element2);
if (!ZAK_FORM_IS_ELEMENT (priv->v2))
{
- g_warning ("Validator compare: element2 isn't a ZakFormElement.");
+ g_warning ("Validator compare: element «%s» isn't a ZakFormElement.", element2);
}
- g_free (prop);
+}
- return TRUE;
+/**
+ * zak_form_validator_compare_get_element2:
+ * @validator:
+ *
+ * Returns: the validator element2 name.
+ */
+const gchar
+*zak_form_validator_compare_get_element2 (ZakFormValidatorCompare *validator)
+{
+ ZakFormValidatorComparePrivate *priv = ZAK_FORM_VALIDATOR_COMPARE_GET_PRIVATE (validator);
+
+ if (ZAK_FORM_IS_ELEMENT (priv->v2))
+ {
+ return zak_form_element_get_name (priv->v2);
+ }
+ else
+ {
+ return "";
+ }
}
/* PRIVATE */
/*
- * Copyright (C) 2016-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2016-2020 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <libxml/tree.h>
+#include "form.h"
#include "formvalidator.h"
ZakFormValidatorCompare *zak_form_validator_compare_new (void);
+void zak_form_validator_compare_set_compare_type (ZakFormValidatorCompare *validator, const gchar *type);
+const gchar *zak_form_validator_compare_get_compare_type (ZakFormValidatorCompare *validator);
+
+void zak_form_validator_compare_set_element1 (ZakFormValidatorCompare *validator, ZakFormForm *form, const gchar *element1);
+const gchar *zak_form_validator_compare_get_element1 (ZakFormValidatorCompare *validator);
+
+void zak_form_validator_compare_set_element2 (ZakFormValidatorCompare *validator, ZakFormForm *form, const gchar *element2);
+const gchar *zak_form_validator_compare_get_element2 (ZakFormValidatorCompare *validator);
G_END_DECLS