From: Andrea Zagli Date: Mon, 16 May 2016 14:52:15 +0000 (+0200) Subject: Added function ZakCgiFormElement::bind (closes #1021). X-Git-Tag: v0.1.0~3^2~3 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=c1fa8836980c38046c8d67d9703bda98e95830b2;p=libzakcgi Added function ZakCgiFormElement::bind (closes #1021). --- diff --git a/src/form.c b/src/form.c index 6b9852d..03c584a 100644 --- a/src/form.c +++ b/src/form.c @@ -138,7 +138,6 @@ zak_cgi_form_bind (ZakCgiForm *zakcgiform) guint i; GValue *gval; - gchar *value; ZakCgiFormPrivate *priv; @@ -154,8 +153,7 @@ zak_cgi_form_bind (ZakCgiForm *zakcgiform) gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, zak_cgi_form_element_get_id (element)); if (gval != NULL) { - value = zak_form_element_unformat (ZAK_FORM_ELEMENT (element), g_value_get_string (gval)); - zak_form_element_set_value (ZAK_FORM_ELEMENT (element), value); + zak_cgi_form_element_bind (element, g_value_get_string (gval)); } } } diff --git a/src/formelement.c b/src/formelement.c index f2f07fb..6e079be 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -50,6 +50,8 @@ static void zak_cgi_form_element_get_property (GObject *object, static void zak_cgi_form_element_dispose (GObject *gobject); static void zak_cgi_form_element_finalize (GObject *gobject); +static gchar *zak_cgi_form_element_get_value (ZakCgiFormElement *element); +static gboolean zak_cgi_form_element_set_value (ZakCgiFormElement *element, const gchar *value); static void zak_cgi_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode); #define ZAK_CGI_FORM_ELEMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT, ZakCgiFormElementPrivate)) @@ -60,6 +62,7 @@ struct _ZakCgiFormElementPrivate gchar *id; GHashTable *ht_attrs; GHashTable *ht_label_attrs; + gchar *value; }; G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, ZAK_FORM_TYPE_ELEMENT) @@ -68,6 +71,7 @@ static void zak_cgi_form_element_class_init (ZakCgiFormElementClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + ZakFormElementClass *elem_class = ZAK_FORM_ELEMENT_CLASS (class); object_class->set_property = zak_cgi_form_element_set_property; object_class->get_property = zak_cgi_form_element_get_property; @@ -76,6 +80,9 @@ zak_cgi_form_element_class_init (ZakCgiFormElementClass *class) class->xml_parsing = zak_cgi_form_element_xml_parsing; + elem_class->get_value = zak_cgi_form_element_get_value; + elem_class->set_value = zak_cgi_form_element_set_value; + g_type_class_add_private (object_class, sizeof (ZakCgiFormElementPrivate)); class->construct = zak_cgi_form_element_construct; @@ -132,6 +139,22 @@ zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, zak_form_element_set_long_name (ZAK_FORM_ELEMENT (element), label); } +/** + * zak_cgi_form_element_bind: + * @element: + * @value: + * + */ +void +zak_cgi_form_element_bind (ZakCgiFormElement *element, const gchar *value) +{ + ZakCgiFormElementPrivate *priv; + + priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); + + priv->value = g_strdup (value); +} + /** * zak_cgi_form_element_render: * @element: @@ -250,6 +273,32 @@ static GHashTable return priv->ht_attrs; } +static gchar +*zak_cgi_form_element_get_value (ZakCgiFormElement *element) +{ + gchar *ret; + + ZakCgiFormElementPrivate *priv; + + priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); + + ret = g_strdup (priv->value); + + return ret; +} + +static gboolean +zak_cgi_form_element_set_value (ZakCgiFormElement *element, const gchar *value) +{ + ZakCgiFormElementPrivate *priv; + + priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); + + priv->value = g_strdup (value); + + return TRUE; +} + static void zak_cgi_form_element_set_property (GObject *object, guint property_id, diff --git a/src/formelement.h b/src/formelement.h index 804021c..50d5822 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -50,6 +50,8 @@ gchar *zak_cgi_form_element_get_id (ZakCgiFormElement *element); void zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, ...); +void zak_cgi_form_element_bind (ZakCgiFormElement *element, const gchar *value); + gchar *zak_cgi_form_element_render (ZakCgiFormElement *element);