static void zak_form_element_dispose (GObject *gobject);
static void zak_form_element_finalize (GObject *gobject);
+static GPtrArray *zak_form_element_get_messages (ZakFormElement *element);
+
typedef struct
{
gchar *value;
GPtrArray *pa_filters;
GPtrArray *pa_validators;
+ GPtrArray *pa_messages;
} ZakFormElementPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormElement, zak_form_element, G_TYPE_OBJECT)
object_class->get_property = zak_form_element_get_property;
object_class->dispose = zak_form_element_dispose;
object_class->finalize = zak_form_element_finalize;
+
+ class->get_messages = zak_form_element_get_messages;
}
static void
priv->value = NULL;
priv->pa_filters = NULL;
priv->pa_validators = NULL;
+ priv->pa_messages = NULL;
}
/**
zak_form_element_filter (element);
+ if (priv->pa_messages != NULL)
+ {
+ g_ptr_array_unref (priv->pa_messages);
+ priv->pa_messages = NULL;
+ }
+
if (priv->pa_validators != NULL)
{
value = zak_form_element_get_value (element);
for (i = 0; i < priv->pa_validators->len; i++)
{
- if (!zak_form_element_validator_validate ((ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i),
- value))
+ ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
+ if (!zak_form_element_validator_validate (validator, value))
{
+ if (priv->pa_messages == NULL)
+ {
+ priv->pa_messages = g_ptr_array_new ();
+ }
+ g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (zak_form_element_validator_get_message (validator)));
+
ret = FALSE;
}
}
GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
parent_class->finalize (gobject);
}
+
+static GPtrArray
+*zak_form_element_get_messages (ZakFormElement *element)
+{
+ ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element);
+
+ return priv->pa_messages;
+}
struct _ZakFormElementClass
{
GObjectClass parent_class;
+
+ GPtrArray *(*get_messages) (ZakFormElement *element);
};
#include "formelementvalidator.h"
+enum
+ {
+ PROP_0,
+ PROP_MESSAGE
+ };
+
static void zak_form_element_validator_class_init (ZakFormElementValidatorClass *class);
static void zak_form_element_validator_init (ZakFormElementValidator *zak_form_element_validator);
typedef struct
{
- gpointer nothing;
+ gchar *message;
} ZakFormElementValidatorPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormElementValidator, zak_form_element_validator, G_TYPE_OBJECT)
object_class->get_property = zak_form_element_validator_get_property;
object_class->dispose = zak_form_element_validator_dispose;
object_class->finalize = zak_form_element_validator_finalize;
+
+ g_object_class_install_property (object_class, PROP_MESSAGE,
+ g_param_spec_string ("message",
+ "Message",
+ "Message",
+ "Invalid value",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
return ret;
}
+/**
+ * zak_form_element_validator_set_message:
+ * @validator:
+ * @message:
+ *
+ */
+void
+zak_form_element_validator_set_message (ZakFormElementValidator *validator,
+ const gchar *message)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ priv->message = g_strdup (message);
+}
+
+/**
+ * zak_form_element_validator_get_message:
+ * @validator:
+ *
+ * Returns:
+ */
+gchar
+*zak_form_element_validator_get_message (ZakFormElementValidator *validator)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ return g_strdup (priv->message);
+}
+
/* PRIVATE */
static void
zak_form_element_validator_set_property (GObject *object,
switch (property_id)
{
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_MESSAGE:
+ zak_form_element_validator_set_message (zak_form_element_validator, g_value_dup_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
switch (property_id)
{
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_MESSAGE:
+ g_value_set_string (value, zak_form_element_validator_get_message (zak_form_element_validator));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
gboolean zak_form_element_validator_validate (ZakFormElementValidator *self, const gchar *value);
+void zak_form_element_validator_set_message (ZakFormElementValidator *validator,
+ const gchar *message);
+gchar *zak_form_element_validator_get_message (ZakFormElementValidator *validator);
+
G_END_DECLS
#include <glib-object.h>
-#include <formelementvalidator.h>
+#include "formelementvalidator.h"
G_BEGIN_DECLS
#include <glib-object.h>
-#include <formelementvalidator.h>
+#include "formelementvalidator.h"
G_BEGIN_DECLS