glade3 r1755 - in branches/builder: . gladeui



Author: tvb
Date: Tue Apr  1 18:28:27 2008
New Revision: 1755
URL: http://svn.gnome.org/viewvc/glade3?rev=1755&view=rev

Log:

	* gladeui/glade-widget.[ch], gladeui/glade-widget-adaptor.c,
	  gladeui/glade-property.[ch]: Implemented loading of packing
	  properties and normal properties.



Modified:
   branches/builder/ChangeLog
   branches/builder/gladeui/glade-property.c
   branches/builder/gladeui/glade-property.h
   branches/builder/gladeui/glade-widget-adaptor.c
   branches/builder/gladeui/glade-widget.c
   branches/builder/gladeui/glade-xml-utils.c
   branches/builder/gladeui/glade-xml-utils.h

Modified: branches/builder/gladeui/glade-property.c
==============================================================================
--- branches/builder/gladeui/glade-property.c	(original)
+++ branches/builder/gladeui/glade-property.c	Tue Apr  1 18:28:27 2008
@@ -694,123 +694,17 @@
 /*******************************************************************************
                         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 @@
 
 	return gvalue;
 }
-
 #endif // LOADING_WAS_IMPLEMENTED
 
+
 /*******************************************************************************
                                      API
  *******************************************************************************/
@@ -1326,16 +1220,13 @@
 	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 @@
 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, NULL);
+	g_return_val_if_fail (node != NULL, NULL);
+
+	g_print ("glade_property_read for property '%s', nodename %s\n", 
+		 pclass->id, glade_xml_node_get_name (node));
 
-	g_return_val_if_fail (pclass != NULL, FALSE);
-	g_return_val_if_fail (info != NULL, FALSE);
+	/* 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;
 
-	if (pclass->packing)
+	for (prop = glade_xml_node_get_children (node); 
+	     prop; prop = glade_xml_node_next (prop))
 	{
-		ret = glade_property_read_packing 
-			(property, pclass, project, (GladeChildInfo *)info, free_value);
-	}
-	else switch (pclass->type)
-	{
-	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

Modified: branches/builder/gladeui/glade-property.h
==============================================================================
--- branches/builder/gladeui/glade-property.h	(original)
+++ branches/builder/gladeui/glade-property.h	Tue Apr  1 18:28:27 2008
@@ -144,7 +144,7 @@
 GValue                 *glade_property_read                  (GladeProperty      *property,
 							      GladePropertyClass *pclass,
 							      GladeProject       *project,
-							      gpointer            info,
+							      GladeXmlNode       *node,
 							      gboolean            free_value);
 
 /* XXX gboolean                glade_property_write                 (GladeProperty      *property,  */

Modified: branches/builder/gladeui/glade-widget-adaptor.c
==============================================================================
--- branches/builder/gladeui/glade-widget-adaptor.c	(original)
+++ branches/builder/gladeui/glade-widget-adaptor.c	Tue Apr  1 18:28:27 2008
@@ -763,6 +763,7 @@
 					 GladeWidget        *widget,
 					 GladeXmlNode       *node)
 {
+	GList *props;
 	/* XXX Here were looking at a GladeWidget object built with native
 	 * defaults
 	 */
@@ -771,8 +772,16 @@
 	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 */
 
 }

Modified: branches/builder/gladeui/glade-widget.c
==============================================================================
--- branches/builder/gladeui/glade-widget.c	(original)
+++ branches/builder/gladeui/glade-widget.c	Tue Apr  1 18:28:27 2008
@@ -3871,9 +3871,9 @@
 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 @@
 						   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 = 

Modified: branches/builder/gladeui/glade-xml-utils.c
==============================================================================
--- branches/builder/gladeui/glade-xml-utils.c	(original)
+++ branches/builder/gladeui/glade-xml-utils.c	Tue Apr  1 18:28:27 2008
@@ -232,7 +232,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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);

Modified: branches/builder/gladeui/glade-xml-utils.h
==============================================================================
--- branches/builder/gladeui/glade-xml-utils.h	(original)
+++ branches/builder/gladeui/glade-xml-utils.h	Tue Apr  1 18:28:27 2008
@@ -92,6 +92,8 @@
 #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"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]