-SUBDIRS = src tests
+SUBDIRS = po src tests
ACLOCAL_AMFLAGS = -I m4
AC_PROG_LIBTOOL
AC_PROG_RANLIB
+IT_PROG_INTLTOOL
+
+dnl ******************************
+dnl Translations
+dnl ******************************
+GETTEXT_PACKAGE=libzakformcgi
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",
+ [The prefix for our gettext translation domains.])
+AM_GLIB_GNU_GETTEXT
+
# Checks for libraries.
PKG_CHECK_MODULES(ZAKFORMCGI, [glib-2.0 >= 2.36
- gobject-2.0 >= 2.36
- gio-2.0 >= 2.36
- gio-unix-2.0 >= 2.36
- libzakcgi
- libzakform >= 0.0.1
- libzakformini])
+ gobject-2.0 >= 2.36
+ gio-2.0 >= 2.36
+ gio-unix-2.0 >= 2.36
+ libzakcgi
+ libzakform >= 0.0.1
+ libzakformini])
AC_SUBST(ZAKFORMCGI_CFLAGS)
AC_SUBST(ZAKFORMCGI_LIBS)
AC_CONFIG_FILES([
libzakformcgi.pc
Makefile
+ po/Makefile.in
src/Makefile
tests/Makefile
])
--- /dev/null
+# List of source files which contain translatable strings.
+src/formelementfile.c
--- /dev/null
+# libzakformcgi italian translation
+# Copyright (C) 2017 Andrea Zagli
+# This file is distributed under the same license as the libzakform package.
+# Andrea Zagli <azagli@libero.it>, 2017.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: libzakformcgi 0.0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-05-13 15:50+0200\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"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: ../src/formelementfile.c:411
+#, c-format
+msgid "The size of «%s» must be greater than %d."
+msgstr "La dimensione di «%s» deve essere superiore a %d."
+
+#: ../src/formelementfile.c:419
+#, c-format
+msgid "The size of «%s» cannot be greater than %d."
+msgstr "La dimensione di «%s» non può essere superiore a %d."
+
+#: ../src/formelementfile.c:447
+#, c-format
+msgid "The file for field «%s» must be of type «%s»."
+msgstr "Il file per «%s» deve essere del tipo «%s»."
+
+#: ../src/formelementfile.c:466
+#, c-format
+msgid "The field «%s» cannot be empty."
+msgstr "Il campo «%s» non può essere vuoto."
LIBS = $(ZAKFORMCGI_LIBS)
AM_CPPFLAGS = $(ZAKFORMCGI_CFLAGS) \
+ -DLOCALEDIR=\"$(localedir)\" \
-DG_LOG_DOMAIN=\"ZakFormCGI\"
lib_LTLIBRARIES = libzakformcgi.la
libzakformcgi_la_SOURCES = commons.c \
- form.c \
- formelement.c \
- formelementcheck.c \
- formelementemail.c \
- formelementfile.c \
- formelementhidden.c \
- formelementpassword.c \
- formelementradio.c \
- formelementselect.c \
- formelementstring.c \
- formelementtext.c \
- formelementtextarea.c \
- formelementsubmit.c
+ form.c \
+ formelement.c \
+ formelementcheck.c \
+ formelementemail.c \
+ formelementfile.c \
+ formelementhidden.c \
+ formelementpassword.c \
+ formelementradio.c \
+ formelementselect.c \
+ formelementstring.c \
+ formelementtext.c \
+ formelementtextarea.c \
+ formelementsubmit.c
libzakformcgi_la_LDFLAGS = -no-undefined
#include <config.h>
#endif
+#include <glib/gi18n-lib.h>
+
#include "form.h"
#include "formelementstring.h"
static void zak_form_cgi_form_init (ZakFormCgiForm *zak_form_cgi_form);
static void zak_form_cgi_form_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
static void zak_form_cgi_form_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
static void zak_form_cgi_form_dispose (GObject *gobject);
static void zak_form_cgi_form_finalize (GObject *gobject);
G_DEFINE_TYPE (ZakFormCgiForm, zak_form_cgi_form, ZAK_FORM_TYPE_FORM)
+#ifdef G_OS_WIN32
+static HMODULE backend_dll = NULL;
+
+BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+ DWORD fdwReason,
+ LPVOID lpReserved)
+{
+ switch (fdwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ backend_dll = (HMODULE) hinstDLL;
+ break;
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+#endif
+
static void
zak_form_cgi_form_class_init (ZakFormCgiFormClass *class)
{
ZakFormCgiForm
*zak_form_cgi_form_new (ZakCgiMain *zakcgimain, ...)
{
+ gchar *localedir;
+
ZakFormCgiForm *zak_form_cgi_form;
ZakFormCgiFormPrivate *priv;
va_list ap;
+#ifdef G_OS_WIN32
+
+ gchar *moddir;
+ gchar *p;
+
+ moddir = g_win32_get_package_installation_directory_of_module (backend_dll);
+
+ p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR));
+ if (p != NULL
+ && (g_ascii_strcasecmp (p + 1, "src") == 0
+ || g_ascii_strcasecmp (p + 1, ".libs") == 0))
+ {
+ localedir = g_strdup (LOCALEDIR);
+ }
+ else
+ {
+ localedir = g_build_filename (moddir, "share", "locale", NULL);
+ }
+
+ g_free (moddir);
+
+#else
+
+ localedir = g_strdup (LOCALEDIR);
+
+#endif
+
+ bindtextdomain (GETTEXT_PACKAGE, localedir);
+ textdomain (GETTEXT_PACKAGE);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
zak_form_cgi_form = ZAK_FORM_CGI_FORM (g_object_new (zak_form_cgi_form_get_type (), NULL));
priv = ZAK_FORM_CGI_FORM_GET_PRIVATE (zak_form_cgi_form);
#include <config.h>
#endif
+#include <glib/gi18n-lib.h>
+
#include <libzakcgi/libzakcgi.h>
#include "formelementfile.h"
guint size_min;
guint size_max;
gchar *mime_type;
+ gchar *mime_type_message;
};
G_DEFINE_TYPE (ZakFormCgiFormElementFile, zak_form_cgi_form_element_file, ZAK_FORM_CGI_TYPE_FORM_ELEMENT)
priv->size_min = 0;
priv->size_max = 0;
priv->mime_type = NULL;
+ priv->mime_type_message = NULL;
}
/**
else if (xmlStrcmp (cur->name, (const xmlChar *)"zak-cgi-mime-type") == 0)
{
zak_form_cgi_form_element_file_set_mime_type (element, (gchar *)xmlNodeGetContent (cur));
+ zak_form_cgi_form_element_file_set_mime_type_message (element, (gchar *)xmlGetProp (cur, (const xmlChar *)"message"));
}
else
{
- g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+ g_hash_table_replace (ht_attrs, g_strdup ((gchar *)cur->name), (gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
}
}
+void
+zak_form_cgi_form_element_file_set_mime_type_message (ZakFormElement *element, const gchar *mime_type_message)
+{
+ ZakFormCgiFormElementFilePrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_FILE_GET_PRIVATE (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);
+ }
+}
+
+gchar
+*zak_form_cgi_form_element_file_get_mime_type_message (ZakFormElement *element)
+{
+ ZakFormCgiFormElementFilePrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_FILE_GET_PRIVATE (element);
+
+ if (priv->mime_type_message == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ return g_strdup (priv->mime_type_message);
+ }
+}
+
static gchar
*zak_form_cgi_form_element_file_render (ZakFormCgiFormElement *element)
{
{
gboolean ret;
+ ZakCgiFile *cgi_file;
+
ZakFormCgiFormElementFilePrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_FILE_GET_PRIVATE (element);
ret = FALSE;
|| priv->size_max > 0
|| priv->mime_type != NULL)
{
- if (priv->size_min > 0)
+ 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;
+ }
+ }
}
- if (priv->size_max > 0)
+ else if (priv->size_min > 0)
{
-
- }
- if (priv->mime_type != NULL)
- {
-
+ g_ptr_array_add (ar_messages, g_strdup_printf (_("The field «%s» cannot be empty."),
+ zak_form_element_get_long_name (element)));
+ ret = TRUE;
}
}
void zak_form_cgi_form_element_file_set_mime_type (ZakFormElement *element, const gchar *mime_type);
gchar *zak_form_cgi_form_element_file_get_mime_type (ZakFormElement *element);
+void zak_form_cgi_form_element_file_set_mime_type_message (ZakFormElement *element, const gchar *mime_type_message);
+gchar *zak_form_cgi_form_element_file_get_mime_type_message (ZakFormElement *element);
+
G_END_DECLS