summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tvb@src.gnome.org>2008-04-01 17:28:27 +0000
committerTristan Van Berkom <tvb@src.gnome.org>2008-04-01 17:28:27 +0000
commit431d89ffc1d850045eb24bfd05b73783e6183381 (patch)
treee71b5d55a78e5e213581ce44e6d58104ab1d9788
parentc9f234fa07ea3c2616aa147844710da321e5ef6d (diff)
downloadglade-431d89ffc1d850045eb24bfd05b73783e6183381.tar.gz
Implemented loading of packing properties and normal properties.
* gladeui/glade-widget.[ch], gladeui/glade-widget-adaptor.c, gladeui/glade-property.[ch]: Implemented loading of packing properties and normal properties. svn path=/branches/builder/; revision=1755
-rw-r--r--ChangeLog4
-rw-r--r--gladeui/glade-property.c264
-rw-r--r--gladeui/glade-property.h2
-rw-r--r--gladeui/glade-widget-adaptor.c13
-rw-r--r--gladeui/glade-widget.c31
-rw-r--r--gladeui/glade-xml-utils.c16
-rw-r--r--gladeui/glade-xml-utils.h2
7 files changed, 162 insertions, 170 deletions
diff --git a/ChangeLog b/ChangeLog
index a1f1d874..45ae1805 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@
or packing properties - but internal children and placeholders
are loaded correctly.
+ * gladeui/glade-widget.[ch], gladeui/glade-widget-adaptor.c,
+ gladeui/glade-property.[ch]: Implemented loading of packing
+ properties and normal properties.
+
2008-03-30 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-parser.[ch]
diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c
index be381beb..6ebe9222 100644
--- a/gladeui/glade-property.c
+++ b/gladeui/glade-property.c
@@ -694,123 +694,17 @@ glade_property_get_type (void)
/*******************************************************************************
GladeInterface Parsing code
*******************************************************************************/
-#if LOADING_WAS_IMPLEMENTED
static GValue *
-glade_property_read_packing (GladeProperty *property,
- GladePropertyClass *pclass,
- GladeProject *project,
- GladeChildInfo *info,
- gboolean free_value)
+glade_property_real_read (GladeProperty *property,
+ GladePropertyClass *pclass,
+ GladeProject *project,
+ GladeXmlNode *node,
+ gboolean free_value)
{
- GValue *gvalue = NULL;
- gint i;
- gchar *id;
-
- for (i = 0; i < info->n_properties; ++i)
- {
- GladePropInfo *pinfo = info->properties + i;
-
- id = glade_util_read_prop_name (pinfo->name);
-
- if (!strcmp (id, pclass->id))
- {
- gvalue = glade_property_class_make_gvalue_from_string
- (pclass, pinfo->value, project);
-
- if (property)
- {
- glade_property_i18n_set_translatable
- (property, pinfo->translatable);
- glade_property_i18n_set_has_context
- (property, pinfo->has_context);
- glade_property_i18n_set_comment
- (property, pinfo->comment);
-
- property->enabled = TRUE;
-
- GLADE_PROPERTY_GET_KLASS (property)->set_value
- (property, gvalue);
- }
-
- if (free_value)
- {
- g_value_unset (gvalue);
- g_free (gvalue);
- }
-
- g_free (id);
- break;
- }
- g_free (id);
- }
- return gvalue;
}
-static GValue *
-glade_property_read_normal (GladeProperty *property,
- GladePropertyClass *pclass,
- GladeProject *project,
- GladeWidgetInfo *info,
- gboolean free_value)
-{
- GValue *gvalue = NULL;
- gint i;
- gchar *id;
-
- for (i = 0; i < info->n_properties; ++i)
- {
- GladePropInfo *pinfo = info->properties + i;
-
- id = glade_util_read_prop_name (pinfo->name);
-
- if (!strcmp (id, pclass->id))
- {
- if (property && glade_property_class_is_object (pclass))
- {
- /* we must synchronize this directly after loading this project
- * (i.e. lookup the actual objects after they've been parsed and
- * are present).
- */
- g_object_set_data_full (G_OBJECT (property),
- "glade-loaded-object",
- g_strdup (pinfo->value), g_free);
- }
- else
- {
- gvalue = glade_property_class_make_gvalue_from_string
- (pclass, pinfo->value, project);
-
- if (property)
- GLADE_PROPERTY_GET_KLASS
- (property)->set_value (property, gvalue);
-
- if (free_value)
- {
- g_value_unset (gvalue);
- g_free (gvalue);
- }
- }
-
- if (property)
- {
- glade_property_i18n_set_translatable
- (property, pinfo->translatable);
- glade_property_i18n_set_has_context
- (property, pinfo->has_context);
- glade_property_i18n_set_comment
- (property, pinfo->comment);
-
- property->enabled = TRUE;
- }
-
- g_free (id);
- break;
- }
- g_free (id);
- }
- return gvalue;
-}
+#if LOADING_WAS_IMPLEMENTED
static GValue *
glade_property_read_atk_prop (GladeProperty *property,
@@ -993,9 +887,9 @@ glade_property_read_accel_prop (GladeProperty *property,
return gvalue;
}
-
#endif // LOADING_WAS_IMPLEMENTED
+
/*******************************************************************************
API
*******************************************************************************/
@@ -1326,16 +1220,13 @@ glade_property_load (GladeProperty *property)
GLADE_PROPERTY_GET_KLASS (property)->load (property);
}
-
-#if LOADING_WAS_IMPLEMENTED
-
/**
* glade_property_read:
* @property: a #GladeProperty or #NULL
* @pclass: the #GladePropertyClass
* @project: the #GladeProject
- * @info: a #GladeWidgetInfo struct or a #GladeChildInfo struct if
- * a packing property is passed.
+ * @node: the #GladeXmlNode to read, will either be a <widget>
+ * node or a <child> node for packing properties.
* @free_value: Whether the return value should be freed after applying
* it to the property or if it should be returned in tact.
*
@@ -1351,49 +1242,120 @@ GValue *
glade_property_read (GladeProperty *property,
GladePropertyClass *pclass,
GladeProject *project,
- gpointer info,
+ GladeXmlNode *node,
gboolean free_value)
{
- GValue *ret = NULL;
+ GladeXmlNode *prop;
+ GValue *gvalue = NULL;
+ gchar *id, *name, *value;
- g_return_val_if_fail (pclass != NULL, FALSE);
- g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (pclass != NULL, NULL);
+ g_return_val_if_fail (node != NULL, NULL);
- if (pclass->packing)
- {
- ret = glade_property_read_packing
- (property, pclass, project, (GladeChildInfo *)info, free_value);
- }
- else switch (pclass->type)
+ g_print ("glade_property_read for property '%s', nodename %s\n",
+ pclass->id, glade_xml_node_get_name (node));
+
+ /* This code should work the same for <packing> and <widget> */
+ if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_PACKING) ||
+ glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET)))
+ return NULL;
+
+ for (prop = glade_xml_node_get_children (node);
+ prop; prop = glade_xml_node_next (prop))
{
- case GPC_NORMAL:
- ret = glade_property_read_normal
- (property, pclass, project, (GladeWidgetInfo *)info, free_value);
- break;
- case GPC_ATK_PROPERTY:
- ret = glade_property_read_atk_prop
- (property, pclass, project, (GladeWidgetInfo *)info, free_value);
- break;
- case GPC_ATK_RELATION:
- ret = glade_property_read_atk_relation
- (property, pclass, project, (GladeWidgetInfo *)info);
- break;
- case GPC_ATK_ACTION:
- ret = glade_property_read_atk_action
- (property, pclass, project, (GladeWidgetInfo *)info, free_value);
- break;
- case GPC_ACCEL_PROPERTY:
- ret = glade_property_read_accel_prop
- (property, pclass, project, (GladeWidgetInfo *)info, free_value);
- break;
- default:
- break;
+
+ if (!glade_xml_node_verify_silent (prop, GLADE_XML_TAG_PROPERTY))
+ continue;
+
+ if (!(name = glade_xml_get_property_string_required
+ (prop, GLADE_XML_TAG_NAME, NULL)))
+ continue;
+
+ /* Make sure we are working with dashes and
+ * not underscores ...
+ */
+ id = glade_util_read_prop_name (name);
+ g_free (name);
+
+ if (!strcmp (id, pclass->id))
+ {
+ if (!(value = glade_xml_get_content (prop)))
+ {
+ /* XXX should be glade_xml_get_content_required()... */
+ g_free (id);
+ break;
+ }
+
+
+ if (property && glade_property_class_is_object (pclass))
+ {
+ /* we must synchronize this directly after loading this project
+ * (i.e. lookup the actual objects after they've been parsed and
+ * are present).
+ */
+ g_object_set_data_full (G_OBJECT (property),
+ "glade-loaded-object",
+ g_strdup (value), g_free);
+ }
+ else
+ {
+ gvalue = glade_property_class_make_gvalue_from_string
+ (pclass, value, project);
+
+ if (property)
+ {
+ GLADE_PROPERTY_GET_KLASS
+ (property)->set_value (property, gvalue);
+ }
+
+ if (free_value)
+ {
+ g_value_unset (gvalue);
+ g_free (gvalue);
+ gvalue = NULL;
+ }
+
+ /* If an optional property is specified in the
+ * glade file, its enabled
+ */
+ property->enabled = TRUE;
+ }
+
+ if (property)
+ {
+ gint translatable, has_context;
+ gchar *comment;
+
+ translatable = glade_xml_get_property_int
+ (prop, GLADE_TAG_TRANSLATABLE, FALSE);
+ has_context = glade_xml_get_property_int
+ (prop, GLADE_TAG_HAS_CONTEXT, FALSE);
+ comment = glade_xml_get_property_string
+ (prop, GLADE_TAG_COMMENT);
+
+ glade_property_i18n_set_translatable
+ (property, translatable);
+ glade_property_i18n_set_has_context
+ (property, has_context);
+ glade_property_i18n_set_comment
+ (property, comment);
+
+ g_free (comment);
+ }
+
+ g_free (value);
+ g_free (id);
+ break;
+ }
+ g_free (id);
}
- return ret;
+ return gvalue;
}
+#if LOADING_WAS_IMPLEMENTED
+
/**
* glade_property_write:
* @property: a #GladeProperty
diff --git a/gladeui/glade-property.h b/gladeui/glade-property.h
index 5e81a932..ab75ee57 100644
--- a/gladeui/glade-property.h
+++ b/gladeui/glade-property.h
@@ -144,7 +144,7 @@ void glade_property_load (GladeProperty
GValue *glade_property_read (GladeProperty *property,
GladePropertyClass *pclass,
GladeProject *project,
- gpointer info,
+ GladeXmlNode *node,
gboolean free_value);
/* XXX gboolean glade_property_write (GladeProperty *property, */
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index f867c0bd..bc201588 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -763,6 +763,7 @@ glade_widget_adaptor_object_read_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlNode *node)
{
+ GList *props;
/* XXX Here were looking at a GladeWidget object built with native
* defaults
*/
@@ -771,8 +772,16 @@ glade_widget_adaptor_object_read_widget (GladeWidgetAdaptor *adaptor,
g_print ("reading widget '%s' of class '%s'\n",
widget->name, adaptor->name);
-
-
+ /* Get the packing properties */
+ for (props = widget->properties;
+ props; props = props->next)
+ {
+ GladeProperty *property = props->data;
+ glade_property_read
+ (property, property->klass,
+ widget->project, node, TRUE);
+ }
+
/* then all the signals */
}
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 32ab829e..f8721f44 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -3871,9 +3871,9 @@ static void
glade_widget_read_children (GladeWidget *widget,
GladeXmlNode *node)
{
- GladeXmlNode *child, *widget_node;
- GladeWidget *child_widget;
-
+ GladeXmlNode *child, *widget_node, *packing_node;
+ GladeWidget *child_widget;
+ GList *packing;
/*
* Deal with children...
*/
@@ -3900,12 +3900,27 @@ glade_widget_read_children (GladeWidget *widget,
widget_node,
internal_name);
- if (child_widget && !internal_name)
- glade_widget_adaptor_add
- (widget->adaptor,
- widget->object,
- child_widget->object);
+ if (child_widget)
+ {
+ if (!internal_name)
+ glade_widget_add_child (widget, child_widget, FALSE);
+
+ if ((packing_node =
+ glade_xml_search_child
+ (child, GLADE_XML_TAG_PACKING)) != NULL)
+ {
+ /* Get the packing properties */
+ for (packing = child_widget->packing_properties;
+ packing; packing = packing->next)
+ {
+ GladeProperty *property = packing->data;
+ glade_property_read
+ (property, property->klass,
+ loading_project, packing_node, TRUE);
+ }
+ }
+ }
} else {
GObject *palaceholder =
diff --git a/gladeui/glade-xml-utils.c b/gladeui/glade-xml-utils.c
index 5ff4b40a..a2246383 100644
--- a/gladeui/glade-xml-utils.c
+++ b/gladeui/glade-xml-utils.c
@@ -232,7 +232,7 @@ glade_xml_get_value_int_required (GladeXmlNode *node, const gchar *name, gint *
ret = glade_xml_get_value_int (node, name, val);
if (ret == FALSE)
- g_warning ("The file did not contained the required value \"%s\"\n"
+ g_warning ("The file did not contain the required value \"%s\"\n"
"Under the \"%s\" tag.", name, glade_xml_node_get_name (node));
return ret;
@@ -425,10 +425,10 @@ glade_xml_get_value_string_required (GladeXmlNode *node_in,
if (value == NULL)
{
if (xtra == NULL)
- g_warning ("The file did not contained the required value \"%s\"\n"
+ g_warning ("The file did not contain the required value \"%s\"\n"
"Under the \"%s\" tag.", name, node->name);
else
- g_warning ("The file did not contained the required value \"%s\"\n"
+ g_warning ("The file did not contain the required value \"%s\"\n"
"Under the \"%s\" tag (%s).", name, node->name, xtra);
}
@@ -464,10 +464,10 @@ glade_xml_get_property_string_required (GladeXmlNode *node_in,
if (value == NULL)
{
if (xtra == NULL)
- g_warning ("The file did not contained the required property \"%s\"\n"
+ g_warning ("The file did not contain the required property \"%s\"\n"
"Under the \"%s\" tag.", name, node->name);
else
- g_warning ("The file did not contained the required property \"%s\"\n"
+ g_warning ("The file did not contain the required property \"%s\"\n"
"Under the \"%s\" tag (%s).", name, node->name, xtra);
}
return value;
@@ -514,7 +514,7 @@ glade_xml_search_child_required (GladeXmlNode *node, const gchar* name)
child = glade_xml_search_child (node, name);
if (child == NULL)
- g_warning ("The file did not contained the required tag \"%s\"\n"
+ g_warning ("The file did not contain the required tag \"%s\"\n"
"Under the \"%s\" node.", name, glade_xml_node_get_name (node));
return child;
@@ -579,7 +579,7 @@ glade_xml_context_new_from_path (const gchar *full_path,
name_space = xmlSearchNsByHref (doc, doc->children, BAD_CAST(nspace));
if (name_space == NULL && nspace != NULL)
{
- g_warning ("The file did not contained the expected name space\n"
+ g_warning ("The file did not contain the expected name space\n"
"Expected \"%s\" [%s]",
nspace, full_path);
xmlFreeDoc (doc);
@@ -589,7 +589,7 @@ glade_xml_context_new_from_path (const gchar *full_path,
root = xmlDocGetRootElement(doc);
if ((root->name == NULL) || (xmlStrcmp (root->name, BAD_CAST(root_name)) !=0 ))
{
- g_warning ("The file did not contained the expected root name\n"
+ g_warning ("The file did not contain the expected root name\n"
"Expected \"%s\", actual : \"%s\" [%s]",
root_name, root->name, full_path);
xmlFreeDoc (doc);
diff --git a/gladeui/glade-xml-utils.h b/gladeui/glade-xml-utils.h
index 638b1ec6..b61d6cd9 100644
--- a/gladeui/glade-xml-utils.h
+++ b/gladeui/glade-xml-utils.h
@@ -92,6 +92,8 @@ typedef struct _GladeXmlDoc GladeXmlDoc;
#define GLADE_TAG_KEY "key"
#define GLADE_TAG_VALUE "value"
#define GLADE_TAG_TRANSLATABLE "translatable"
+#define GLADE_TAG_HAS_CONTEXT "context"
+#define GLADE_TAG_COMMENT "comments"
#define GLADE_TAG_PACKING_DEFAULTS "packing-defaults"
#define GLADE_TAG_PARENT_CLASS "parent-class"
#define GLADE_TAG_CHILD_PROPERTY "child-property"