From: Andrea Zagli <azagli@libero.it>
Date: Wed, 26 Aug 2015 15:54:44 +0000 (+0200)
Subject: Added ZakCgiFormElementSubmit.
X-Git-Tag: v0.1.0~3^2~47
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=9a1c11a6195088b77f93baa7581cc49dc8b1f5c3;p=libzakcgi

Added ZakCgiFormElementSubmit.
---

diff --git a/src/Makefile.am b/src/Makefile.am
index 5450e9c..cdf95be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ libzakcgi_la_SOURCES = commons.c \
                        form.c \
                        formelement.c \
                        formelementtext.c \
+                       formelementsubmit.c \
                        main.c \
                        session.c \
                        tag.c \
@@ -22,6 +23,7 @@ libzakcgi_include_HEADERS = \
                             form.h \
                             formelement.h \
                             formelementtext.h \
+                            formelementsubmit.h \
                             main.h \
                             session.h \
                             tag.h \
diff --git a/src/formelementsubmit.c b/src/formelementsubmit.c
new file mode 100644
index 0000000..20db957
--- /dev/null
+++ b/src/formelementsubmit.c
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2015 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 <syslog.h>
+
+#include "commons.h"
+#include "tag.h"
+#include "formelementsubmit.h"
+
+static void zak_cgi_form_element_submit_class_init (ZakCgiFormElementSubmitClass *class);
+static void zak_cgi_form_element_submit_init (ZakCgiFormElementSubmit *zak_cgi_form_element_submit);
+
+static gchar *zak_cgi_form_element_submit_render (ZakCgiFormElement *element);
+
+static gboolean zak_cgi_form_element_submit_is_valid (ZakCgiFormElement *element);
+
+static void zak_cgi_form_element_submit_set_property (GObject *object,
+                               guint property_id,
+                               const GValue *value,
+                               GParamSpec *pspec);
+static void zak_cgi_form_element_submit_get_property (GObject *object,
+                               guint property_id,
+                               GValue *value,
+                               GParamSpec *pspec);
+
+static void zak_cgi_form_element_submit_dispose (GObject *gobject);
+static void zak_cgi_form_element_submit_finalize (GObject *gobject);
+
+#define ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitPrivate))
+
+typedef struct _ZakCgiFormElementSubmitPrivate ZakCgiFormElementSubmitPrivate;
+struct _ZakCgiFormElementSubmitPrivate
+	{
+		gpointer empty;
+	};
+
+G_DEFINE_TYPE (ZakCgiFormElementSubmit, zak_cgi_form_element_submit, ZAK_CGI_TYPE_FORM_ELEMENT)
+
+static void
+zak_cgi_form_element_submit_class_init (ZakCgiFormElementSubmitClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass);
+
+	object_class->set_property = zak_cgi_form_element_submit_set_property;
+	object_class->get_property = zak_cgi_form_element_submit_get_property;
+	object_class->dispose = zak_cgi_form_element_submit_dispose;
+	object_class->finalize = zak_cgi_form_element_submit_finalize;
+
+	elem_class->render = zak_cgi_form_element_submit_render;
+	elem_class->is_valid = zak_cgi_form_element_submit_is_valid;
+
+	g_type_class_add_private (object_class, sizeof (ZakCgiFormElementSubmitPrivate));
+}
+
+static void
+zak_cgi_form_element_submit_init (ZakCgiFormElementSubmit *zak_cgi_form_element_submit)
+{
+	ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit);
+
+}
+
+/**
+ * zak_cgi_form_element_submit_new:
+ * @id:
+ * @validation_regex:
+ * @...:
+ *
+ * Returns: the newly created #ZakCgiFormElementSubmit object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_submit_new (const gchar *id,
+								const gchar *validation_regex,
+								...)
+{
+	va_list ap;
+
+	ZakCgiFormElementSubmit *zak_cgi_form_element_submit;
+
+	zak_cgi_form_element_submit = ZAK_CGI_FORM_ELEMENT_SUBMIT (g_object_new (zak_cgi_form_element_submit_get_type (), NULL));
+
+	va_start (ap, validation_regex);
+
+	ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit),
+																					id,
+																					validation_regex,
+																					zak_cgi_commons_valist_to_ghashtable (ap));
+
+	return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit);
+}
+
+static gchar
+*zak_cgi_form_element_submit_render (ZakCgiFormElement *element)
+{
+	gchar *ret;
+
+	GHashTable *ht_attrs;
+
+	ZakCgiFormElementClass *klass;
+
+	klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_CLASS (ZAK_CGI_FORM_ELEMENT_SUBMIT (element)));
+
+	ht_attrs = klass->get_ht_attrs (element);
+
+	ret = zak_cgi_tag_submit_ht (zak_cgi_form_element_get_id (element), ht_attrs);
+
+	return ret;
+}
+
+static gboolean
+zak_cgi_form_element_submit_is_valid (ZakCgiFormElement *element)
+{
+	gboolean ret;
+
+
+	return ret;
+}
+
+/* PRIVATE */
+static void
+zak_cgi_form_element_submit_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+	ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)object;
+	ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit);
+
+	switch (property_id)
+		{
+			default:
+				G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+				break;
+		}
+}
+
+static void
+zak_cgi_form_element_submit_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+	ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)object;
+	ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit);
+
+	switch (property_id)
+		{
+			default:
+				G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+				break;
+		}
+}
+
+static void
+zak_cgi_form_element_submit_dispose (GObject *gobject)
+{
+	ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)gobject;
+	ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit);
+
+
+
+	GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+	parent_class->dispose (gobject);
+}
+
+static void
+zak_cgi_form_element_submit_finalize (GObject *gobject)
+{
+	ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)gobject;
+	ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit);
+
+
+
+	GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+	parent_class->finalize (gobject);
+}
diff --git a/src/formelementsubmit.h b/src/formelementsubmit.h
new file mode 100644
index 0000000..c9ce80a
--- /dev/null
+++ b/src/formelementsubmit.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 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_CGI_FORM_ELEMENT_SUBMIT_H__
+#define __ZAK_CGI_FORM_ELEMENT_SUBMIT_H__
+
+
+#include <glib-object.h>
+
+#include "formelement.h"
+
+
+G_BEGIN_DECLS
+
+
+#define ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT                 (zak_cgi_form_element_submit_get_type ())
+#define ZAK_CGI_FORM_ELEMENT_SUBMIT(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmit))
+#define ZAK_CGI_FORM_ELEMENT_SUBMIT_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitClass))
+#define ZAK_CGI_IS_FORM_ELEMENT_SUBMIT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT))
+#define ZAK_CGI_IS_FORM_ELEMENT_SUBMIT_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT))
+#define ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitClass))
+
+typedef struct _ZakCgiFormElementSubmit ZakCgiFormElementSubmit;
+typedef struct _ZakCgiFormElementSubmitClass ZakCgiFormElementSubmitClass;
+
+struct _ZakCgiFormElementSubmit
+	{
+		ZakCgiFormElement parent_instance;
+	};
+
+struct _ZakCgiFormElementSubmitClass
+	{
+		ZakCgiFormElementClass parent_class;
+	};
+
+
+GType zak_cgi_form_element_submit_get_type (void);
+
+ZakCgiFormElement *zak_cgi_form_element_submit_new (const gchar *id, const gchar *validation_regex, ...);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_CGI_FORM_ELEMENT_SUBMIT_H__ */
diff --git a/tests/form.c b/tests/form.c
index 9e1f484..ed3a85c 100644
--- a/tests/form.c
+++ b/tests/form.c
@@ -19,6 +19,7 @@
 #include <form.h>
 #include <formelement.h>
 #include <formelementtext.h>
+#include <formelementsubmit.h>
 
 int
 main (int argc, char *argv[])
@@ -37,6 +38,9 @@ main (int argc, char *argv[])
 	element = zak_cgi_form_element_text_new ("first", "aaa", NULL);
 	zak_cgi_form_add_element (form, element);
 
+	element = zak_cgi_form_element_submit_new ("submit", "aaa", NULL);
+	zak_cgi_form_add_element (form, element);
+
 	g_string_append (str, zak_cgi_form_render (form));
 
 	zak_cgi_main_out (NULL, str->str);