]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added property 'as-empty-string' to ZakFormElementValidatorNotempty.
authorAndrea Zagli <azagli@libero.it>
Sun, 29 Jan 2017 10:34:04 +0000 (11:34 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 29 Jan 2017 10:34:04 +0000 (11:34 +0100)
src/formelementvalidatornotempty.c
src/formelementvalidatornotempty.h

index 91de8078291f00c7254c2eaf81f1f9b98133b8c0..a3ef4e277bbc01d79391c3b6fdf112560ed4535c 100644 (file)
 #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;
                }
 }
 
index c6c4a2eb498002b984e0436cd115abcdb0ab4f55..5a6b662c45606144bed11ac8eda7d7ef2c0b4178 100644 (file)
@@ -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