From 9a0f9dbd09ded9f628be499868e019b9dd5fa3b2 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 26 Nov 2015 20:16:00 +0100 Subject: [PATCH] Added ZakFormGtkFormElement::xml_parsing. --- src/formelement.c | 80 +++++++++++++++++++++++++++++++++++++-- src/formelement.h | 5 +++ src/formelementcheck.c | 14 +++++++ src/formelementcheck.h | 2 + src/formelemententry.c | 14 +++++++ src/formelemententry.h | 2 + src/formelementlabel.c | 14 +++++++ src/formelementlabel.h | 2 + src/formelementradio.c | 4 +- src/formelementspin.c | 14 +++++++ src/formelementspin.h | 2 + src/formelementtextview.c | 14 +++++++ src/formelementtextview.h | 2 + 13 files changed, 165 insertions(+), 4 deletions(-) diff --git a/src/formelement.c b/src/formelement.c index 997bc95..88a26a3 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -25,6 +25,7 @@ enum { PROP_0, + PROP_GTKBUILDER, PROP_WIDGET, PROP_NAME, PROP_LABEL @@ -51,11 +52,14 @@ static void zak_form_gtk_form_element_set_visible (ZakFormGtkFormElement *elemen static gboolean zak_form_gtk_form_element_get_editable (ZakFormGtkFormElement *element); static void zak_form_gtk_form_element_set_editable (ZakFormGtkFormElement *element, gboolean visible); +static void zak_form_gtk_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode); + #define ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT, ZakFormGtkFormElementPrivate)) typedef struct _ZakFormGtkFormElementPrivate ZakFormGtkFormElementPrivate; struct _ZakFormGtkFormElementPrivate { + GtkBuilder *builder; GtkWidget *widget; gchar *name; @@ -75,6 +79,8 @@ zak_form_gtk_form_element_class_init (ZakFormGtkFormElementClass *class) object_class->dispose = zak_form_gtk_form_element_dispose; object_class->finalize = zak_form_gtk_form_element_finalize; + class->xml_parsing = zak_form_gtk_form_element_xml_parsing; + parent_class->get_visible = zak_form_gtk_form_element_get_visible; parent_class->set_visible = zak_form_gtk_form_element_set_visible; parent_class->get_editable = zak_form_gtk_form_element_get_editable; @@ -82,6 +88,13 @@ zak_form_gtk_form_element_class_init (ZakFormGtkFormElementClass *class) g_type_class_add_private (object_class, sizeof (ZakFormGtkFormElementPrivate)); + g_object_class_install_property (object_class, PROP_GTKBUILDER, + g_param_spec_object ("gtkbuilder", + "GtkBuilder", + "GtkBuilder", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_WIDGET, g_param_spec_object ("widget", "Widget", @@ -109,11 +122,43 @@ zak_form_gtk_form_element_init (ZakFormGtkFormElement *zak_form_gtk_form_element { ZakFormGtkFormElementPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (zak_form_gtk_form_element); + priv->builder = NULL; priv->widget = NULL; priv->name = NULL; priv->label = NULL; } +/** + * zak_form_gtk_form_element_set_gtkbuilder: + * @element: + * @gtkbuilder: + * + */ +void +zak_form_gtk_form_element_set_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder) +{ + ZakFormGtkFormElementPrivate *priv; + + priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (element); + + priv->builder = gtkbuilder; +} + +/** + * zak_form_gtk_form_element_get_gtkbuilder: + * @element: + * + */ +GtkBuilder +*zak_form_gtk_form_element_get_gtkbuilder (ZakFormGtkFormElement *element) +{ + ZakFormGtkFormElementPrivate *priv; + + priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (element); + + return priv->builder; +} + /** * zak_form_gtk_form_element_widget_set_from_gtkbuilder: * @element: @@ -137,12 +182,14 @@ zak_form_gtk_form_element_widget_set_from_gtkbuilder (ZakFormGtkFormElement *ele priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (element); + priv->builder = gtkbuilder; + ret = FALSE; w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, widget_name)); - if (w != NULL) + if (w != NULL + && GTK_IS_WIDGET (w)) { - priv->widget = g_object_ref (w); - priv->name = g_strdup (widget_name); + zak_form_gtk_form_element_set_widget (element, w, widget_name); ret = TRUE; } else @@ -252,6 +299,10 @@ zak_form_gtk_form_element_set_property (GObject *object, switch (property_id) { + case PROP_GTKBUILDER: + zak_form_gtk_form_element_set_gtkbuilder (zak_form_gtk_form_element, (GtkBuilder *)g_value_get_object (value)); + break; + case PROP_LABEL: zak_form_gtk_form_element_set_label (zak_form_gtk_form_element, (GtkWidget *)g_value_get_object (value)); break; @@ -273,6 +324,10 @@ zak_form_gtk_form_element_get_property (GObject *object, switch (property_id) { + case PROP_GTKBUILDER: + g_value_set_object (value, (gpointer)zak_form_gtk_form_element_get_gtkbuilder (zak_form_gtk_form_element)); + break; + case PROP_LABEL: g_value_set_object (value, (gpointer)zak_form_gtk_form_element_get_label (zak_form_gtk_form_element)); break; @@ -343,3 +398,22 @@ zak_form_gtk_form_element_set_editable (ZakFormGtkFormElement *element, gboolean gtk_widget_set_sensitive (priv->widget, editable); } + +static void +zak_form_gtk_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode) +{ + xmlNode *cur; + + ZakFormGtkFormElementPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE ((ZakFormGtkFormElement *)element); + + cur = xmlnode->children; + while (cur != NULL) + { + if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0) + { + zak_form_gtk_form_element_widget_set_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element), priv->builder, (gchar *)xmlNodeGetContent (cur)); + } + + cur = cur->next; + } +} diff --git a/src/formelement.h b/src/formelement.h index 9b59849..a9c88c0 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -39,9 +39,14 @@ G_DECLARE_DERIVABLE_TYPE (ZakFormGtkFormElement, zak_form_gtk_form_element, ZAK_ struct _ZakFormGtkFormElementClass { ZakFormElementClass parent_class; + + void (*xml_parsing) (ZakFormElement *element, xmlNode *xmlnode); }; +void zak_form_gtk_form_element_set_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder); +GtkBuilder *zak_form_gtk_form_element_get_gtkbuilder (ZakFormGtkFormElement *element); + gboolean zak_form_gtk_form_element_widget_set_from_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder, const gchar *widget_name); diff --git a/src/formelementcheck.c b/src/formelementcheck.c index 884ca7d..b345f89 100644 --- a/src/formelementcheck.c +++ b/src/formelementcheck.c @@ -89,6 +89,20 @@ ZakFormGtkFormElement return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_check); } +/** + * zak_form_gtk_form_element_check_xml_parsing: + * @element: + * @xmlnode: + * + */ +gboolean +zak_form_gtk_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) +{ + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_check_parent_class)->xml_parsing (element, xmlnode); + + return TRUE; +} + /* PRIVATE */ static void zak_form_gtk_form_element_check_set_property (GObject *object, diff --git a/src/formelementcheck.h b/src/formelementcheck.h index 48a80f4..0bca3f8 100644 --- a/src/formelementcheck.h +++ b/src/formelementcheck.h @@ -53,6 +53,8 @@ GType zak_form_gtk_form_element_check_get_type (void); ZakFormGtkFormElement *zak_form_gtk_form_element_check_new (void); +gboolean zak_form_gtk_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); + G_END_DECLS diff --git a/src/formelemententry.c b/src/formelemententry.c index b89987f..09d133f 100644 --- a/src/formelemententry.c +++ b/src/formelemententry.c @@ -89,6 +89,20 @@ ZakFormGtkFormElement return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_entry); } +/** + * zak_form_gtk_form_element_entry_xml_parsing: + * @element: + * @xmlnode: + * + */ +gboolean +zak_form_gtk_form_element_entry_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) +{ + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_entry_parent_class)->xml_parsing (element, xmlnode); + + return TRUE; +} + /* PRIVATE */ static void zak_form_gtk_form_element_entry_set_property (GObject *object, diff --git a/src/formelemententry.h b/src/formelemententry.h index 22ea0e8..0b3484f 100644 --- a/src/formelemententry.h +++ b/src/formelemententry.h @@ -53,6 +53,8 @@ GType zak_form_gtk_form_element_entry_get_type (void); ZakFormGtkFormElement *zak_form_gtk_form_element_entry_new (void); +gboolean zak_form_gtk_form_element_entry_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); + G_END_DECLS diff --git a/src/formelementlabel.c b/src/formelementlabel.c index f8ddc41..7947fb8 100644 --- a/src/formelementlabel.c +++ b/src/formelementlabel.c @@ -89,6 +89,20 @@ ZakFormGtkFormElement return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_label); } +/** + * zak_form_gtk_form_element_label_xml_parsing: + * @element: + * @xmlnode: + * + */ +gboolean +zak_form_gtk_form_element_label_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) +{ + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_label_parent_class)->xml_parsing (element, xmlnode); + + return TRUE; +} + /* PRIVATE */ static void zak_form_gtk_form_element_label_set_property (GObject *object, diff --git a/src/formelementlabel.h b/src/formelementlabel.h index 602c51a..102f879 100644 --- a/src/formelementlabel.h +++ b/src/formelementlabel.h @@ -53,6 +53,8 @@ GType zak_form_gtk_form_element_label_get_type (void); ZakFormGtkFormElement *zak_form_gtk_form_element_label_new (void); +gboolean zak_form_gtk_form_element_label_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); + G_END_DECLS diff --git a/src/formelementradio.c b/src/formelementradio.c index 7204db9..eeea2ad 100644 --- a/src/formelementradio.c +++ b/src/formelementradio.c @@ -113,12 +113,14 @@ zak_form_gtk_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr { xmlNode *cur; + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_radio_parent_class)->xml_parsing (element, xmlnode); + cur = xmlnode->children; while (cur != NULL) { if (xmlStrcmp (cur->name, (const xmlChar *)"return-value") == 0) { - zak_form_gtk_form_element_radio_set_return_value (element, (gchar *)xmlNodeGetContent (cur)); + zak_form_gtk_form_element_radio_set_return_value (ZAK_FORM_GTK_FORM_ELEMENT_RADIO (element), (gchar *)xmlNodeGetContent (cur)); } cur = cur->next; diff --git a/src/formelementspin.c b/src/formelementspin.c index 654e8b8..2762eb0 100644 --- a/src/formelementspin.c +++ b/src/formelementspin.c @@ -89,6 +89,20 @@ ZakFormGtkFormElement return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_spin); } +/** + * zak_form_gtk_form_element_spin_xml_parsing: + * @element: + * @xmlnode: + * + */ +gboolean +zak_form_gtk_form_element_spin_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) +{ + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_spin_parent_class)->xml_parsing (element, xmlnode); + + return TRUE; +} + /* PRIVATE */ static void zak_form_gtk_form_element_spin_set_property (GObject *object, diff --git a/src/formelementspin.h b/src/formelementspin.h index d258784..13c5c7a 100644 --- a/src/formelementspin.h +++ b/src/formelementspin.h @@ -53,6 +53,8 @@ GType zak_form_gtk_form_element_spin_get_type (void); ZakFormGtkFormElement *zak_form_gtk_form_element_spin_new (void); +gboolean zak_form_gtk_form_element_spin_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); + G_END_DECLS diff --git a/src/formelementtextview.c b/src/formelementtextview.c index 09db12f..63b0172 100644 --- a/src/formelementtextview.c +++ b/src/formelementtextview.c @@ -89,6 +89,20 @@ ZakFormGtkFormElement return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_textview); } +/** + * zak_form_gtk_form_element_textview_xml_parsing: + * @element: + * @xmlnode: + * + */ +gboolean +zak_form_gtk_form_element_textview_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) +{ + ZAK_FORM_GTK_FORM_ELEMENT_CLASS (zak_form_gtk_form_element_textview_parent_class)->xml_parsing (element, xmlnode); + + return TRUE; +} + /* PRIVATE */ static void zak_form_gtk_form_element_textview_set_property (GObject *object, diff --git a/src/formelementtextview.h b/src/formelementtextview.h index dd4a16b..8163880 100644 --- a/src/formelementtextview.h +++ b/src/formelementtextview.h @@ -53,6 +53,8 @@ GType zak_form_gtk_form_element_textview_get_type (void); ZakFormGtkFormElement *zak_form_gtk_form_element_textview_new (void); +gboolean zak_form_gtk_form_element_textview_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); + G_END_DECLS -- 2.49.0