]> saetta.ns0.it Git - zakform/cgi/commitdiff
Added funcitons ZakFormCgiFormElementRadio::get_option[s].
authorAndrea Zagli <azagli@libero.it>
Sat, 24 Apr 2021 07:20:24 +0000 (09:20 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 24 Apr 2021 07:20:24 +0000 (09:20 +0200)
src/formelementradio.c
src/formelementradio.h

index 8e7935150e40508c583b45e3d2673201b23092f8..7009fd1444ce80891e37f104f4303e55957e2bff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2020 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2017-2021 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
@@ -51,12 +51,6 @@ struct _ZakFormCgiFormElementRadioPrivate
 
 G_DEFINE_TYPE_WITH_PRIVATE (ZakFormCgiFormElementRadio, zak_form_cgi_form_element_radio, ZAK_FORM_CGI_TYPE_FORM_ELEMENT)
 
-typedef struct
-       {
-               gchar *value;
-               gchar *content;
-       } Option;
-
 static void
 zak_form_cgi_form_element_radio_class_init (ZakFormCgiFormElementRadioClass *klass)
 {
@@ -189,7 +183,7 @@ zak_form_cgi_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr
                                                {
                                                        if (xmlStrcmp (xnode->name, (const xmlChar *)"option") == 0)
                                                                {
-                                                                       Option *opt = g_new0 (Option, 1);
+                                                                       ZakFormCgiFormElementRadioOption *opt = g_new0 (ZakFormCgiFormElementRadioOption, 1);
 
                                                                        opt->value = (gchar *)xmlGetProp (xnode, (const xmlChar *)"value");
                                                                        opt->content = (gchar *)xmlGetProp (xnode, (const xmlChar *)"content");
@@ -250,7 +244,7 @@ gchar
                        g_free (attr_class);
                }
 
-       Option *opt = (Option *)g_ptr_array_index (priv->ar_options, idx);
+       ZakFormCgiFormElementRadioOption *opt = (ZakFormCgiFormElementRadioOption *)g_ptr_array_index (priv->ar_options, idx);
 
        ht_attrs_option = g_hash_table_new (g_str_hash, g_str_equal);
        zak_utils_ghashtable_copy (ht_attrs, ht_attrs_option);
@@ -347,6 +341,54 @@ static gchar
        return ret_value;
 }
 
+GPtrArray
+*zak_form_cgi_form_element_radio_get_options (ZakFormCgiFormElement *element)
+{
+       GPtrArray *ret;
+       guint i;
+       ZakFormCgiFormElementRadioOption *opt;
+
+       ZakFormCgiFormElementRadioPrivate *priv = zak_form_cgi_form_element_radio_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_RADIO (element));
+
+       ret = g_ptr_array_new ();
+
+       for (i = 0; i < priv->ar_options->len; i++)
+               {
+                       ZakFormCgiFormElementRadioOption *new_opt;
+
+                       opt = (ZakFormCgiFormElementRadioOption *)g_ptr_array_index (priv->ar_options, i);
+
+                       new_opt = g_new0 (ZakFormCgiFormElementRadioOption, 1);
+                       new_opt->value = g_strdup (opt->value);
+                       new_opt->content = g_strdup (opt->content);
+
+                       g_ptr_array_add (ret, new_opt);
+               }
+
+       return ret;
+
+}
+
+ZakFormCgiFormElementRadioOption
+*zak_form_cgi_form_element_radio_get_option (ZakFormCgiFormElement *element, guint idx)
+{
+       ZakFormCgiFormElementRadioOption *ret;
+       ZakFormCgiFormElementRadioOption *opt;
+
+       ZakFormCgiFormElementRadioPrivate *priv = zak_form_cgi_form_element_radio_get_instance_private (ZAK_FORM_CGI_FORM_ELEMENT_RADIO (element));
+
+       ret = g_new0 (ZakFormCgiFormElementRadioOption, 1);
+
+       opt = (ZakFormCgiFormElementRadioOption *)g_ptr_array_index (priv->ar_options, idx);
+       if (opt != NULL)
+               {
+                       ret->value = g_strdup (opt->value);
+                       ret->content = g_strdup (opt->content);
+               }
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 zak_form_cgi_form_element_radio_set_property (GObject *object,
index d39a8c62325cdda3e346ffd20d4a7a265ea9143d..cfccdf50c1b26c1a94b92869c47a73268ca0e64e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2020 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2017-2021 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
@@ -63,6 +63,15 @@ void zak_form_cgi_form_element_radio_xml_parsing (ZakFormElement *element, xmlNo
 
 gchar *zak_form_cgi_form_element_radio_render_single (ZakFormCgiFormElement *element, guint idx);
 
+typedef struct
+       {
+               gchar *value;
+               gchar *content;
+       } ZakFormCgiFormElementRadioOption;
+
+GPtrArray *zak_form_cgi_form_element_radio_get_options (ZakFormCgiFormElement *element);
+ZakFormCgiFormElementRadioOption *zak_form_cgi_form_element_radio_get_option (ZakFormCgiFormElement *element, guint idx);
+
 
 G_END_DECLS