From 9293ab5f76a4724a91f78b30745a23115b1bca81 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 29 Jan 2017 11:34:04 +0100 Subject: [PATCH] Added property 'as-empty-string' to ZakFormElementValidatorNotempty. --- src/formelementvalidatornotempty.c | 74 ++++++++++++++++++++++++++---- src/formelementvalidatornotempty.h | 4 ++ 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/formelementvalidatornotempty.c b/src/formelementvalidatornotempty.c index 91de807..a3ef4e2 100644 --- a/src/formelementvalidatornotempty.c +++ b/src/formelementvalidatornotempty.c @@ -23,6 +23,12 @@ #include "formelementvalidator.h" #include "formelementvalidatornotempty.h" +enum + { + PROP_0, + PROP_AS_EMPTY_STRING + }; + static void zak_form_element_validator_notempty_class_init (ZakFormElementValidatorNotemptyClass *class); static void zak_form_element_validator_notempty_init (ZakFormElementValidatorNotempty *zak_form_element); @@ -71,14 +77,19 @@ zak_form_element_validator_notempty_class_init (ZakFormElementValidatorNotemptyC parent_class->validate = zak_form_element_validator_notempty_validate; g_type_class_add_private (object_class, sizeof (ZakFormElementValidatorNotemptyPrivate)); + + g_object_class_install_property (object_class, PROP_AS_EMPTY_STRING, + g_param_spec_string ("as-empty-string", + "As empty string", + "As empty string", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); } static void zak_form_element_validator_notempty_init (ZakFormElementValidatorNotempty *zak_form_element) { ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (zak_form_element); - - priv->as_empty_string = g_strdup (""); } /** @@ -116,6 +127,45 @@ zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *valida return TRUE; } +/** + * zak_form_element_validator_notempty_set_as_empty_string: + * @validator: + * @as_empty_string: + * + */ +void +zak_form_element_validator_notempty_set_as_empty_string (ZakFormElementValidatorNotempty *validator, const gchar *as_empty_string) +{ + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); + + if (priv->as_empty_string != NULL) + { + g_free (priv->as_empty_string); + } + if (as_empty_string == NULL) + { + priv->as_empty_string = g_strdup (""); + } + else + { + priv->as_empty_string = g_strdup (as_empty_string); + } +} + +/** + * zak_form_element_validator_notempty_get_as_empty_string: + * @validator: + * + * Returns: + */ +gchar +*zak_form_element_validator_notempty_get_as_empty_string (ZakFormElementValidatorNotempty *validator) +{ + ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator); + + return g_strdup (priv->as_empty_string); +} + /* PRIVATE */ static void zak_form_element_validator_notempty_set_property (GObject *object, @@ -128,9 +178,13 @@ zak_form_element_validator_notempty_set_property (GObject *object, switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; + case PROP_AS_EMPTY_STRING: + zak_form_element_validator_notempty_set_as_empty_string (validator, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } } @@ -145,9 +199,13 @@ zak_form_element_validator_notempty_get_property (GObject *object, switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; + case PROP_AS_EMPTY_STRING: + g_value_set_string (value, zak_form_element_validator_notempty_get_as_empty_string (validator)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } } diff --git a/src/formelementvalidatornotempty.h b/src/formelementvalidatornotempty.h index c6c4a2e..5a6b662 100644 --- a/src/formelementvalidatornotempty.h +++ b/src/formelementvalidatornotempty.h @@ -34,8 +34,12 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (ZakFormElementValidatorNotempty, zak_form_element_validator_notempty, ZAK_FORM, ELEMENT_VALIDATOR_NOTEMPTY, ZakFormElementValidator) ZakFormElementValidatorNotempty *zak_form_element_validator_notempty_new (void); + gboolean zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode); +void zak_form_element_validator_notempty_set_as_empty_string (ZakFormElementValidatorNotempty *validator, const gchar *as_empty_string); +gchar *zak_form_element_validator_notempty_get_as_empty_string (ZakFormElementValidatorNotempty *validator); + G_END_DECLS -- 2.49.0