# libzakformcgi italian translation
-# Copyright (C) 2017 Andrea Zagli
+# Copyright (C) 2017-2020 Andrea Zagli
# This file is distributed under the same license as the libzakform package.
# Andrea Zagli <azagli@libero.it>, 2017.
#
msgstr ""
"Project-Id-Version: libzakformcgi 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-05-13 15:50+0200\n"
+"POT-Creation-Date: 2021-01-02 10:20+0100\n"
"PO-Revision-Date: 2017-05-16 12:44+0200\n"
"Last-Translator: Andrea Zagli <azagli@libero.it>\n"
"Language-Team: Italian <tp@lists.linux.it>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: ../src/formelementfile.c:411
+#: ../src/form.c:207
+msgid "Element without id."
+msgstr "Elemento senza id"
+
+#: ../src/formelementvalidatorfile.c:330
#, c-format
-msgid "The size of «%s» must be greater than %d."
-msgstr "La dimensione di «%s» deve essere superiore a %d."
+msgid "The size must be greater than %d."
+msgstr "La dimensione deve essere superiore a %d."
-#: ../src/formelementfile.c:419
+#: ../src/formelementvalidatorfile.c:338
#, c-format
-msgid "The size of «%s» cannot be greater than %d."
-msgstr "La dimensione di «%s» non può essere superiore a %d."
+msgid "The size cannot be greater than %d."
+msgstr "La dimensione non può essere superiore a %d."
-#: ../src/formelementfile.c:447
+#: ../src/formelementvalidatorfile.c:379
#, c-format
-msgid "The file for field «%s» must be of type «%s»."
-msgstr "Il file per «%s» deve essere del tipo «%s»."
+msgid "The file must be of type «%s»."
+msgstr "Il file deve essere del tipo «%s»."
-#: ../src/formelementfile.c:466
+#: ../src/formelementvalidatorfile.c:388
#, c-format
-msgid "The field «%s» cannot be empty."
-msgstr "Il campo «%s» non può essere vuoto."
+msgid "The field cannot be empty."
+msgstr "Il campo non può essere vuoto."
#include <libzakcgi/libzakcgi.h>
#include "formelementfile.h"
+#include "formelementvalidatorfile.h"
static void zak_form_cgi_form_element_file_class_init (ZakFormCgiFormElementFileClass *class);
static void zak_form_cgi_form_element_file_init (ZakFormCgiFormElementFile *zak_form_cgi_form_element_file);
typedef struct _ZakFormCgiFormElementFilePrivate ZakFormCgiFormElementFilePrivate;
struct _ZakFormCgiFormElementFilePrivate
{
- guint size_min;
- guint size_max;
- gchar *mime_type;
- gchar *mime_type_message;
+ ZakFormElementValidator *validator_file;
};
G_DEFINE_TYPE_WITH_PRIVATE (ZakFormCgiFormElementFile, zak_form_cgi_form_element_file, ZAK_FORM_CGI_TYPE_FORM_ELEMENT)
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (zak_form_cgi_form_element_file);
- priv->size_min = 0;
- priv->size_max = 0;
- priv->mime_type = NULL;
- priv->mime_type_message = NULL;
+ priv->validator_file = (ZakFormElementValidator *)zak_form_cgi_form_element_validator_file_new ();
+
+ zak_form_element_validator_set_id (ZAK_FORM_ELEMENT_VALIDATOR (priv->validator_file), "{default}");
+
+ zak_form_element_add_validator (ZAK_FORM_ELEMENT (zak_form_cgi_form_element_file), ZAK_FORM_ELEMENT_VALIDATOR (priv->validator_file));
}
/**
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- priv->size_min = min;
+ zak_form_cgi_form_element_validator_file_set_size_min (priv->validator_file, min);
}
guint
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- return priv->size_min;
+ return zak_form_cgi_form_element_validator_file_get_size_min (priv->validator_file);
}
void
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- priv->size_max = max;
+ zak_form_cgi_form_element_validator_file_set_size_max (priv->validator_file, max);
}
guint
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- return priv->size_max;
+ return zak_form_cgi_form_element_validator_file_get_size_max (priv->validator_file);
}
void
zak_form_cgi_form_element_file_set_size_range (ZakFormElement *element, guint min, guint max)
{
- zak_form_cgi_form_element_file_set_size_min (element, min);
- zak_form_cgi_form_element_file_set_size_max (element, max);
+ ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
+
+ zak_form_cgi_form_element_validator_file_set_size_min (priv->validator_file, min);
+ zak_form_cgi_form_element_validator_file_set_size_min (priv->validator_file, max);
}
void
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- if (priv->mime_type != NULL)
- {
- g_free (priv->mime_type);
- priv->mime_type = NULL;
- }
-
- if (mime_type != NULL)
- {
- priv->mime_type = g_strdup (mime_type);
- }
+ zak_form_cgi_form_element_validator_file_set_mime_type (priv->validator_file, mime_type);
}
gchar
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- if (priv->mime_type == NULL)
- {
- return NULL;
- }
- else
- {
- return g_strdup (priv->mime_type);
- }
+ return zak_form_cgi_form_element_validator_file_get_mime_type (priv->validator_file);
}
void
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- if (priv->mime_type_message != NULL)
- {
- g_free (priv->mime_type_message);
- priv->mime_type_message = NULL;
- }
-
- if (mime_type_message != NULL)
- {
- priv->mime_type_message = g_strdup (mime_type_message);
- }
+ zak_form_cgi_form_element_validator_file_set_mime_type_message (priv->validator_file, mime_type_message);
}
gchar
{
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- if (priv->mime_type_message == NULL)
- {
- return NULL;
- }
- else
- {
- return g_strdup (priv->mime_type_message);
- }
+ return zak_form_cgi_form_element_validator_file_get_mime_type_message (priv->validator_file);
}
static gchar
static gboolean
zak_form_cgi_form_element_file_after_validating (ZakFormElement *element, GPtrArray *ar_messages)
{
- gboolean ret;
-
- ZakCgiFile *cgi_file;
-
ZakFormCgiFormElementFilePrivate *priv = zak_form_cgi_form_element_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_FILE (element));
- ret = FALSE;
-
- if (priv->size_min > 0
- || priv->size_max > 0
- || priv->mime_type != NULL)
- {
- cgi_file = (ZakCgiFile *)g_value_get_boxed (zak_form_element_get_value_gvalue (element));
- if (cgi_file != NULL
- && cgi_file->content != NULL
- && cgi_file->name != NULL
- && g_strcmp0 (cgi_file->name, "") != 0)
- {
- if (priv->size_min > 0
- && cgi_file->size < priv->size_min)
- {
- g_ptr_array_add (ar_messages, g_strdup_printf (_("The size of «%s» must be greater than %d."),
- zak_form_element_get_long_name (element),
- priv->size_min));
- ret = TRUE;
- }
- if (priv->size_max > 0
- && cgi_file->size > priv->size_max)
- {
- g_ptr_array_add (ar_messages, g_strdup_printf (_("The size of «%s» cannot be greater than %d."),
- zak_form_element_get_long_name (element),
- priv->size_max));
- ret = TRUE;
- }
- if (priv->mime_type != NULL)
- {
- gchar **splitted;
- guint l;
- guint i;
- gboolean found;
- gchar *mime;
-
- found = FALSE;
-
- mime = g_content_type_get_mime_type (cgi_file->content_type);
-
- if (mime == NULL)
- {
- mime = g_strdup (cgi_file->content_type);
- }
-
- splitted = g_strsplit (priv->mime_type, "|", -1);
- l = g_strv_length (splitted);
- for (i = 0; i < l; i++)
- {
- if (g_strcmp0 (mime, splitted[i]) == 0)
- {
- found = TRUE;
- break;
- }
- }
- g_strfreev (splitted);
-
- if (mime != NULL)
- {
- g_free (mime);
- }
-
- if (!found)
- {
- g_ptr_array_add (ar_messages, g_strdup_printf (_("The file for field «%s» must be of type «%s»."),
- zak_form_element_get_long_name (element),
- priv->mime_type_message != NULL ? priv->mime_type_message : priv->mime_type));
- ret = TRUE;
- }
- }
- }
- else if (priv->size_min > 0)
- {
- g_ptr_array_add (ar_messages, g_strdup_printf (_("The field «%s» cannot be empty."),
- zak_form_element_get_long_name (element)));
- ret = TRUE;
- }
- }
-
- return ret;
+ return zak_form_element_validator_validate (priv->validator_file,
+ zak_form_element_get_value_gvalue (element));
}
--- /dev/null
+/*
+ * Copyright (C) 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include <libzakcgi/libzakcgi.h>
+#include "formelementvalidatorfile.h"
+
+enum
+ {
+ PROP_0
+ };
+
+static void zak_form_cgi_form_element_validator_file_class_init (ZakFormCgiFormElementValidatorFileClass *class);
+static void zak_form_cgi_form_element_validator_file_init (ZakFormCgiFormElementValidatorFile *zak_form_element);
+
+static void zak_form_cgi_form_element_validator_file_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void zak_form_cgi_form_element_validator_file_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void zak_form_cgi_form_element_validator_file_dispose (GObject *gobject);
+static void zak_form_cgi_form_element_validator_file_finalize (GObject *gobject);
+
+static gboolean zak_form_cgi_form_element_validator_file_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
+static gboolean zak_form_cgi_form_element_validator_file_validate (ZakFormElementValidator *validator_file, GValue *value);
+static void zak_form_cgi_form_element_validator_file_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version);
+
+struct _ZakFormCgiFormElementValidatorFile
+{
+ ZakFormElementValidator parent_instance;
+
+ /* Other members, including private data. */
+};
+
+typedef struct _ZakFormCgiFormElementValidatorFilePrivate ZakFormCgiFormElementValidatorFilePrivate;
+struct _ZakFormCgiFormElementValidatorFilePrivate
+ {
+ guint size_min;
+ guint size_max;
+ gchar *mime_type;
+ gchar *mime_type_message;
+ };
+
+G_DEFINE_TYPE_WITH_PRIVATE (ZakFormCgiFormElementValidatorFile, zak_form_cgi_form_element_validator_file, ZAK_FORM_TYPE_ELEMENT_VALIDATOR)
+
+static void
+zak_form_cgi_form_element_validator_file_class_init (ZakFormCgiFormElementValidatorFileClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ ZakFormElementValidatorClass *parent_class = ZAK_FORM_ELEMENT_VALIDATOR_CLASS (class);
+
+ object_class->set_property = zak_form_cgi_form_element_validator_file_set_property;
+ object_class->get_property = zak_form_cgi_form_element_validator_file_get_property;
+ object_class->dispose = zak_form_cgi_form_element_validator_file_dispose;
+ object_class->finalize = zak_form_cgi_form_element_validator_file_finalize;
+
+ parent_class->xml_parsing = zak_form_cgi_form_element_validator_file_xml_parsing;
+ parent_class->validate = zak_form_cgi_form_element_validator_file_validate;
+ parent_class->get_xml = zak_form_cgi_form_element_validator_file_get_xml;
+}
+
+static void
+zak_form_cgi_form_element_validator_file_init (ZakFormCgiFormElementValidatorFile *zak_form_element)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (zak_form_element);
+
+ priv->size_min = 0;
+ priv->size_max = 0;
+ priv->mime_type = NULL;
+ priv->mime_type_message = NULL;
+}
+
+/**
+ * zak_form_cgi_form_element_validator_file_new:
+ *
+ * Returns: the newly created #ZakFormCgiFormElementValidatorFile object.
+ */
+ZakFormCgiFormElementValidatorFile
+*zak_form_cgi_form_element_validator_file_new ()
+{
+ ZakFormCgiFormElementValidatorFile *zak_form_cgi_form_element_validator_file;
+
+ zak_form_cgi_form_element_validator_file = ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (g_object_new (zak_form_cgi_form_element_validator_file_get_type (), NULL));
+
+ return zak_form_cgi_form_element_validator_file;
+}
+
+/**
+ * zak_form_cgi_form_element_validator_file_xml_parsing:
+ * @validator:
+ * @xnode:
+ *
+ */
+static gboolean
+zak_form_cgi_form_element_validator_file_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ if (xmlStrcmp (xnode->name, (const xmlChar *)"size-min") == 0)
+ {
+ zak_form_cgi_form_element_validator_file_set_size_min (validator, strtol ((gchar *)xmlNodeGetContent (xnode), NULL, 10));
+ }
+ else if (xmlStrcmp (xnode->name, (const xmlChar *)"size-max") == 0)
+ {
+ zak_form_cgi_form_element_validator_file_set_size_max (validator, strtol ((gchar *)xmlNodeGetContent (xnode), NULL, 10));
+ }
+ else if (xmlStrcmp (xnode->name, (const xmlChar *)"mime-type") == 0)
+ {
+ zak_form_cgi_form_element_validator_file_set_mime_type (validator, (gchar *)xmlNodeGetContent (xnode));
+ zak_form_cgi_form_element_validator_file_set_mime_type_message (validator, (gchar *)xmlGetProp (xnode, (const xmlChar *)"message"));
+ }
+
+ return TRUE;
+}
+
+void
+zak_form_cgi_form_element_validator_file_set_size_min (ZakFormElementValidator *validator, guint min)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ priv->size_min = min;
+}
+
+guint
+zak_form_cgi_form_element_validator_file_get_size_min (ZakFormElementValidator *validator)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ return priv->size_min;
+}
+
+void
+zak_form_cgi_form_element_validator_file_set_size_max (ZakFormElementValidator *validator, guint max)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ priv->size_max = max;
+}
+
+guint
+zak_form_cgi_form_element_validator_file_get_size_max (ZakFormElementValidator *validator)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ return priv->size_max;
+}
+
+void
+zak_form_cgi_form_element_validator_file_set_size_range (ZakFormElementValidator *validator, guint min, guint max)
+{
+ zak_form_cgi_form_element_validator_file_set_size_min (validator, min);
+ zak_form_cgi_form_element_validator_file_set_size_max (validator, max);
+}
+
+void
+zak_form_cgi_form_element_validator_file_set_mime_type (ZakFormElementValidator *validator, const gchar *mime_type)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ if (priv->mime_type != NULL)
+ {
+ g_free (priv->mime_type);
+ priv->mime_type = NULL;
+ }
+
+ if (mime_type != NULL)
+ {
+ priv->mime_type = g_strdup (mime_type);
+ }
+}
+
+gchar
+*zak_form_cgi_form_element_validator_file_get_mime_type (ZakFormElementValidator *validator)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ if (priv->mime_type == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ return g_strdup (priv->mime_type);
+ }
+}
+
+void
+zak_form_cgi_form_element_validator_file_set_mime_type_message (ZakFormElementValidator *validator, const gchar *mime_type_message)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ if (priv->mime_type_message != NULL)
+ {
+ g_free (priv->mime_type_message);
+ priv->mime_type_message = NULL;
+ }
+
+ if (mime_type_message != NULL)
+ {
+ priv->mime_type_message = g_strdup (mime_type_message);
+ }
+}
+
+gchar
+*zak_form_cgi_form_element_validator_file_get_mime_type_message (ZakFormElementValidator *validator)
+{
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ if (priv->mime_type_message == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ return g_strdup (priv->mime_type_message);
+ }
+}
+
+/* PRIVATE */
+static void
+zak_form_cgi_form_element_validator_file_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ZakFormCgiFormElementValidatorFile *validator = (ZakFormCgiFormElementValidatorFile *)object;
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (validator);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+zak_form_cgi_form_element_validator_file_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ZakFormCgiFormElementValidatorFile *validator = (ZakFormCgiFormElementValidatorFile *)object;
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (validator);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+zak_form_cgi_form_element_validator_file_dispose (GObject *gobject)
+{
+ ZakFormCgiFormElementValidatorFile *validator = (ZakFormCgiFormElementValidatorFile *)gobject;
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (validator);
+
+
+
+ GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+ parent_class->dispose (gobject);
+}
+
+static void
+zak_form_cgi_form_element_validator_file_finalize (GObject *gobject)
+{
+ ZakFormCgiFormElementValidatorFile *validator = (ZakFormCgiFormElementValidatorFile *)gobject;
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (validator);
+
+
+
+ GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+ parent_class->finalize (gobject);
+}
+
+static gboolean
+zak_form_cgi_form_element_validator_file_validate (ZakFormElementValidator *validator,
+ GValue *value)
+{
+ gboolean ret;
+
+ ZakCgiFile *cgi_file;
+
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator));
+
+ g_return_val_if_fail (value != NULL, FALSE);
+
+ ret = TRUE;
+
+ if (priv->size_min > 0
+ || priv->size_max > 0
+ || priv->mime_type != NULL)
+ {
+ cgi_file = (ZakCgiFile *)g_value_get_boxed (value);
+ if (cgi_file != NULL
+ && cgi_file->content != NULL
+ && cgi_file->name != NULL
+ && g_strcmp0 (cgi_file->name, "") != 0)
+ {
+ if (priv->size_min > 0
+ && cgi_file->size < priv->size_min)
+ {
+ zak_form_element_validator_set_message (validator,
+ g_strdup_printf (_("The size must be greater than %d."),
+ priv->size_min));
+ ret = FALSE;
+ }
+ if (priv->size_max > 0
+ && cgi_file->size > priv->size_max)
+ {
+ zak_form_element_validator_set_message (validator,
+ g_strdup_printf (_("The size cannot be greater than %d."),
+ priv->size_max));
+ ret = FALSE;
+ }
+ if (priv->mime_type != NULL)
+ {
+ gchar **splitted;
+ guint l;
+ guint i;
+ gboolean found;
+ gchar *mime;
+
+ found = FALSE;
+
+ mime = g_content_type_get_mime_type (cgi_file->content_type);
+
+ if (mime == NULL)
+ {
+ mime = g_strdup (cgi_file->content_type);
+ }
+
+ splitted = g_strsplit (priv->mime_type, "|", -1);
+ l = g_strv_length (splitted);
+ for (i = 0; i < l; i++)
+ {
+ if (g_strcmp0 (mime, splitted[i]) == 0)
+ {
+ found = TRUE;
+ break;
+ }
+ }
+ g_strfreev (splitted);
+
+ if (mime != NULL)
+ {
+ g_free (mime);
+ }
+
+ if (!found)
+ {
+ zak_form_element_validator_set_message (validator,
+ g_strdup_printf (_("The file must be of type «%s»."),
+ priv->mime_type_message != NULL ? priv->mime_type_message : priv->mime_type));
+ ret = FALSE;
+ }
+ }
+ }
+ else if (priv->size_min > 0)
+ {
+ zak_form_element_validator_set_message (validator,
+ g_strdup_printf (_("The field cannot be empty.")));
+ ret = FALSE;
+ }
+ }
+
+ return ret;
+}
+
+static void
+zak_form_cgi_form_element_validator_file_get_xml (ZakFormElementValidator *validator, xmlNode *xnode, const gchar *version)
+{
+ ZakFormCgiFormElementValidatorFile *validator_file = ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE (validator);
+ ZakFormCgiFormElementValidatorFilePrivate *priv = zak_form_cgi_form_element_validator_file_get_instance_private (validator_file);
+
+ xmlSetProp (xnode, (const xmlChar *)"type", (const xmlChar *)"zak_form_cgi_form_element_validator_file");
+
+ xmlSetProp (xnode, (const xmlChar *)"size-min", (const xmlChar *)g_strdup_printf ("%d", zak_form_cgi_form_element_validator_file_get_size_min (validator)));
+ xmlSetProp (xnode, (const xmlChar *)"size-max", (const xmlChar *)g_strdup_printf ("%d", zak_form_cgi_form_element_validator_file_get_size_max (validator)));
+ xmlSetProp (xnode, (const xmlChar *)"mime-type", (const xmlChar *)zak_form_cgi_form_element_validator_file_get_mime_type (validator));
+}
--- /dev/null
+/*
+ * Copyright (C) 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE_H__
+#define __ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE_H__
+
+
+#include <glib-object.h>
+
+#include <libxml/tree.h>
+
+#include <libzakform/libzakform.h>
+
+
+G_BEGIN_DECLS
+
+
+#define ZAK_FORM_TYPE_ELEMENT_VALIDATOR_FILE zak_form_cgi_form_element_validator_file_get_type ()
+G_DECLARE_FINAL_TYPE (ZakFormCgiFormElementValidatorFile, zak_form_cgi_form_element_validator_file, ZAK_FORM_CGI_FORM, ELEMENT_VALIDATOR_FILE, ZakFormElementValidator)
+
+ZakFormCgiFormElementValidatorFile *zak_form_cgi_form_element_validator_file_new (void);
+
+void zak_form_cgi_form_element_validator_file_set_size_min (ZakFormElementValidator *validator, guint min);
+guint zak_form_cgi_form_element_validator_file_get_size_min (ZakFormElementValidator *validator);
+
+void zak_form_cgi_form_element_validator_file_set_size_max (ZakFormElementValidator *validator, guint max);
+guint zak_form_cgi_form_element_validator_file_get_size_max (ZakFormElementValidator *validator);
+
+void zak_form_cgi_form_element_validator_file_set_size_range (ZakFormElementValidator *validator, guint min, guint max);
+
+void zak_form_cgi_form_element_validator_file_set_mime_type (ZakFormElementValidator *validator, const gchar *mime_type);
+gchar *zak_form_cgi_form_element_validator_file_get_mime_type (ZakFormElementValidator *validator);
+
+void zak_form_cgi_form_element_validator_file_set_mime_type_message (ZakFormElementValidator *validator, const gchar *mime_type_message);
+gchar *zak_form_cgi_form_element_validator_file_get_mime_type_message (ZakFormElementValidator *validator);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_FORM_CGI_FORM_ELEMENT_VALIDATOR_FILE_H__ */