priv->to_load = TRUE;
priv->to_save = TRUE;
- priv->pa_filters = NULL;
- priv->pa_validators = NULL;
+ priv->pa_filters = g_ptr_array_new ();
+ priv->pa_validators = g_ptr_array_new ();
priv->pa_messages = NULL;
}
priv = zak_form_element_get_instance_private (element);
- if (priv->pa_filters == NULL)
- {
- priv->pa_filters = g_ptr_array_new ();
- }
-
g_ptr_array_add (priv->pa_filters, filter);
}
priv = zak_form_element_get_instance_private (element);
- if (priv->pa_filters == NULL)
- {
- return;
- }
-
for (i = 0; i < priv->pa_filters->len; i++)
{
gchar *value;
priv = zak_form_element_get_instance_private (element);
- if (priv->pa_validators == NULL)
- {
- priv->pa_validators = g_ptr_array_new ();
- }
-
g_ptr_array_add (priv->pa_validators, validator);
}
priv->pa_messages = NULL;
}
- if (priv->pa_validators != NULL)
- {
- value = zak_form_element_get_value (element);
+ value = zak_form_element_get_value (element);
- for (i = 0; i < priv->pa_validators->len; i++)
+ for (i = 0; i < priv->pa_validators->len; i++)
+ {
+ ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
+ if (!zak_form_element_validator_validate (validator, 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)
{
- 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;
+ 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;
}
}
/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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 "formelementfilter.h"
+enum
+ {
+ PROP_0,
+ PROP_ENABLED
+ };
+
static void zak_form_element_filter_class_init (ZakFormElementFilterClass *class);
static void zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter);
typedef struct
{
- gpointer nothing;
+ gboolean enabled;
} ZakFormElementFilterPrivate;
-G_DEFINE_ABSTRACT_TYPE (ZakFormElementFilter, zak_form_element_filter, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormElementFilter, zak_form_element_filter, G_TYPE_OBJECT)
static void
zak_form_element_filter_class_init (ZakFormElementFilterClass *class)
object_class->get_property = zak_form_element_filter_get_property;
object_class->dispose = zak_form_element_filter_dispose;
object_class->finalize = zak_form_element_filter_finalize;
+
+ g_object_class_install_property (object_class, PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "Enabled",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_FILTER (self), g_strdup (""));
- if (ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->filter != NULL)
+ if (zak_form_element_filter_get_enabled (self)
+ && ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->filter != NULL)
{
ret = ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->filter (self, value);
}
else
{
- ret = g_strdup ("");
+ ret = g_strdup (value);
}
+
return ret;
}
+/**
+ * zak_form_element_filter_get_enabled:
+ * @filter:
+ *
+ * Returns: whether @filter is enabled.
+ */
+gboolean
+zak_form_element_filter_get_enabled (ZakFormElementFilter *filter)
+{
+ ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (filter);
+
+ return priv->enabled;
+}
+
+/**
+ * zak_form_element_filter_set_enabled:
+ * @filter:
+ * @enabled:
+ *
+ */
+void
+zak_form_element_filter_set_enabled (ZakFormElementFilter *filter, gboolean enabled)
+{
+ ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (filter);
+
+ priv->enabled = enabled;
+}
+
/* PRIVATE */
static void
zak_form_element_filter_set_property (GObject *object,
switch (property_id)
{
+ case PROP_ENABLED:
+ zak_form_element_filter_set_enabled (zak_form_element_filter, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
switch (property_id)
{
+ case PROP_ENABLED:
+ g_value_set_boolean (value, zak_form_element_filter_get_enabled (zak_form_element_filter));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value);
+gboolean zak_form_element_filter_get_enabled (ZakFormElementFilter *filter);
+void zak_form_element_filter_set_enabled (ZakFormElementFilter *filter, gboolean enabled);
+
G_END_DECLS
/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
enum
{
PROP_0,
+ PROP_ENABLED,
PROP_MESSAGE
};
typedef struct
{
- gchar *message;
+ gboolean enabled;
+ gchar *message;
} ZakFormElementValidatorPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormElementValidator, zak_form_element_validator, G_TYPE_OBJECT)
object_class->dispose = zak_form_element_validator_dispose;
object_class->finalize = zak_form_element_validator_finalize;
+ g_object_class_install_property (object_class, PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "Enabled",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property (object_class, PROP_MESSAGE,
- g_param_spec_string ("message",
- "Message",
- "Message",
- _("Invalid value"),
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_string ("message",
+ "Message",
+ "Message",
+ _("Invalid value"),
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_VALIDATOR (self), FALSE);
ret = TRUE;
- if (ZAK_FORM_ELEMENT_VALIDATOR_GET_CLASS (self)->validate != NULL)
+ if (zak_form_element_validator_get_enabled (self)
+ && ZAK_FORM_ELEMENT_VALIDATOR_GET_CLASS (self)->validate != NULL)
{
ret = ZAK_FORM_ELEMENT_VALIDATOR_GET_CLASS (self)->validate (self, value);
}
return g_strdup (priv->message);
}
+/**
+ * zak_form_element_validator_get_enabled:
+ * @validator:
+ *
+ * Returns: whether @validator is enabled.
+ */
+gboolean
+zak_form_element_validator_get_enabled (ZakFormElementValidator *validator)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ return priv->enabled;
+}
+
+/**
+ * zak_form_element_validator_set_enabled:
+ * @validator:
+ * @enabled:
+ *
+ */
+void
+zak_form_element_validator_set_enabled (ZakFormElementValidator *validator, gboolean enabled)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ priv->enabled = enabled;
+}
+
/* PRIVATE */
static void
zak_form_element_validator_set_property (GObject *object,
switch (property_id)
{
+ case PROP_ENABLED:
+ zak_form_element_validator_set_enabled (zak_form_element_validator, g_value_get_boolean (value));
+ break;
+
case PROP_MESSAGE:
- zak_form_element_validator_set_message (zak_form_element_validator, g_value_dup_string (value));
+ zak_form_element_validator_set_message (zak_form_element_validator, g_value_dup_string (value));
break;
default:
switch (property_id)
{
+ case PROP_ENABLED:
+ g_value_set_boolean (value, zak_form_element_validator_get_enabled (zak_form_element_validator));
+ break;
+
case PROP_MESSAGE:
g_value_set_string (value, zak_form_element_validator_get_message (zak_form_element_validator));
break;
/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
const gchar *message);
gchar *zak_form_element_validator_get_message (ZakFormElementValidator *validator);
+gboolean zak_form_element_validator_get_enabled (ZakFormElementValidator *validator);
+void zak_form_element_validator_set_enabled (ZakFormElementValidator *validator, gboolean enabled);
+
G_END_DECLS
/*
- * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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 <config.h>
#endif
+#include <glib/gi18n-lib.h>
+
#include "formvalidator.h"
enum
{
PROP_0,
+ PROP_ENABLED,
PROP_MESSAGE
};
typedef struct
{
- gchar *message;
+ gboolean enabled;
+ gchar *message;
} ZakFormValidatorPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormValidator, zak_form_validator, G_TYPE_OBJECT)
object_class->dispose = zak_form_validator_dispose;
object_class->finalize = zak_form_validator_finalize;
+ g_object_class_install_property (object_class, PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "Enabled",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
g_object_class_install_property (object_class, PROP_MESSAGE,
- g_param_spec_string ("message",
- "Message",
- "Message",
- "Invalid value",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_string ("message",
+ "Message",
+ "Message",
+ _("Invalid value"),
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
g_return_val_if_fail (ZAK_FORM_IS_VALIDATOR (self), FALSE);
ret = TRUE;
- if (ZAK_FORM_VALIDATOR_GET_CLASS (self)->validate != NULL)
+ if (zak_form_validator_get_enabled (self)
+ && ZAK_FORM_VALIDATOR_GET_CLASS (self)->validate != NULL)
{
ret = ZAK_FORM_VALIDATOR_GET_CLASS (self)->validate (self);
}
return g_strdup (priv->message);
}
+/**
+ * zak_form_validator_get_enabled:
+ * @validator:
+ *
+ * Returns: whether @validator is enabled.
+ */
+gboolean
+zak_form_validator_get_enabled (ZakFormValidator *validator)
+{
+ ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
+
+ return priv->enabled;
+}
+
+/**
+ * zak_form_validator_set_enabled:
+ * @validator:
+ * @enabled:
+ *
+ */
+void
+zak_form_validator_set_enabled (ZakFormValidator *validator, gboolean enabled)
+{
+ ZakFormValidatorPrivate *priv = zak_form_validator_get_instance_private (validator);
+
+ priv->enabled = enabled;
+}
+
/* PRIVATE */
static void
zak_form_validator_set_property (GObject *object,
switch (property_id)
{
+ case PROP_ENABLED:
+ zak_form_validator_set_enabled (zak_form_validator, g_value_get_boolean (value));
+ break;
+
case PROP_MESSAGE:
zak_form_validator_set_message (zak_form_validator, g_value_dup_string (value));
break;
switch (property_id)
{
+ case PROP_ENABLED:
+ g_value_set_boolean (value, zak_form_validator_get_enabled (zak_form_validator));
+ break;
+
case PROP_MESSAGE:
g_value_set_string (value, zak_form_validator_get_message (zak_form_validator));
break;
/*
- * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
const gchar *message);
gchar *zak_form_validator_get_message (ZakFormValidator *validator);
+gboolean zak_form_validator_get_enabled (ZakFormValidator *validator);
+void zak_form_validator_set_enabled (ZakFormValidator *validator, gboolean enabled);
G_END_DECLS