]> saetta.ns0.it Git - libzakcgi/commitdiff
Form: saved element attributes as hash table.
authorAndrea Zagli <azagli@libero.it>
Mon, 24 Aug 2015 16:59:44 +0000 (18:59 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 24 Aug 2015 16:59:44 +0000 (18:59 +0200)
src/formelement.c
src/formelement.h
src/formelementtext.c
src/main.c

index eb6d03cd9db220ec87d5aa48bc8b8e0d2a803e01..647e587ddaaec8c187fb9ce8e6cf3d1a4b11ff0e 100644 (file)
@@ -50,7 +50,9 @@ static void zak_cgi_form_element_finalize (GObject *gobject);
 typedef struct _ZakCgiFormElementPrivate ZakCgiFormElementPrivate;
 struct _ZakCgiFormElementPrivate
        {
+               gchar *id;
                gchar *validation_regex;
+               GHashTable *ht_attrs;
        };
 
 G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, G_TYPE_OBJECT)
@@ -81,26 +83,67 @@ zak_cgi_form_element_init (ZakCgiFormElement *zak_cgi_form_element)
        ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element);
 
        priv->validation_regex = NULL;
+       priv->ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
 /**
  * zak_cgi_form_element_new:
+ * @id:
  * @validation_regex:
+ * @...:
  *
  * Returns: the newly created #ZakCgiFormElement object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_new (const gchar *validation_regex)
+*zak_cgi_form_element_new (const gchar *id,
+                                                  const gchar *validation_regex,
+                                                  ...)
 {
+       va_list ap;
+
        ZakCgiFormElement *zak_cgi_form_element;
        ZakCgiFormElementPrivate *priv;
 
+       gchar *attr;
+       gchar *attr_value;
+
+       g_return_val_if_fail (id != NULL, NULL);
+
        zak_cgi_form_element = ZAK_CGI_FORM_ELEMENT (g_object_new (zak_cgi_form_element_get_type (), NULL));
 
        priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element);
 
+       priv->id = g_strdup (id);
+
        zak_cgi_form_element_set_validation_regex (zak_cgi_form_element, validation_regex);
 
+       va_start (ap, validation_regex);
+       do
+               {
+                       attr = va_arg (ap, gchar *);
+                       if (attr != NULL)
+                               {
+                                       attr_value = va_arg (ap, gchar *);
+                                       if (attr_value != NULL)
+                                               {
+                                                       g_hash_table_insert (priv->ht_attrs, g_strdup (attr), g_strdup (attr_value));
+                                               }
+                                       else
+                                               {
+                                                       break;
+                                               }
+                               }
+                       else
+                               {
+                                       break;
+                               }
+               } while (TRUE);
+
+       if (g_hash_table_lookup (priv->ht_attrs, "name") == NULL)
+               {
+                       g_hash_table_insert (priv->ht_attrs, "name", g_strdup (id));
+               }
+
        return zak_cgi_form_element;
 }
 
index ac4e18c8f5270fd592f1f236b4030c290133c74c..e2ec6eebc04b8844bdb52def17c968185475ae8b 100644 (file)
@@ -54,7 +54,7 @@ struct _ZakCgiFormElementClass
 
 GType zak_cgi_form_element_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_new (const gchar *validation_regex);
+ZakCgiFormElement *zak_cgi_form_element_new (const  gchar *id, const gchar *validation_regex, ...);
 
 void zak_cgi_form_element_set_validation_regex (ZakCgiFormElement *element, const gchar *validation_regex);
 gchar *zak_cgi_form_element_get_validation_regex (ZakCgiFormElement *element);
index eacc3df9bd04e7ee70d18ec2b2764f56c71fd3ae..0476b27a74925dab8e6c56452515a1d21383a887 100644 (file)
@@ -46,7 +46,7 @@ struct _ZakCgiFormElementTextPrivate
        {
        };
 
-G_DEFINE_TYPE (ZakCgiFormElementText, zak_cgi_form_element_text, G_TYPE_OBJECT)
+G_DEFINE_TYPE (ZakCgiFormElementText, zak_cgi_form_element_text, ZAK_CGI_TYPE_FORM_ELEMENT)
 
 static void
 zak_cgi_form_element_text_class_init (ZakCgiFormElementTextClass *class)
index 00655483cc4946f073a715009902eaa9afacf6db..8d64bd96bdeea8dab0b7430ead47260735edc4be 100644 (file)
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <locale.h>
 
 #include <syslog.h>
 
+#include <glib/gprintf.h>
 #include <gio/gunixinputstream.h>
 
 #include "main.h"