Index: configure.in
===================================================================
RCS file: /cvs/gnome/glade3/configure.in,v
retrieving revision 1.31
diff -p -u -r1.31 configure.in
--- configure.in	25 Oct 2004 17:39:34 -0000	1.31
+++ configure.in	28 Oct 2004 10:41:36 -0000
@@ -33,7 +33,7 @@ AM_GLIB_GNU_GETTEXT
 dnl ================================================================
 dnl Start of pkg-config checks
 dnl ================================================================
-PKG_CHECK_MODULES(GLADE, gtk+-2.0 >= 2.4.0  libxml-2.0 >= 2.4.0)
+PKG_CHECK_MODULES(GLADE, gtk+-2.0 >= 2.4.0 libglade-2.0 >= 2.4.0 libxml-2.0 >= 2.4.0)
 GLADE_LIBS="${GLADE_LIBS}"
 AC_SUBST(GLADE_LIBS)
 AC_SUBST(GLADE_CFLAGS)
Index: src/glade-project.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-project.c,v
retrieving revision 1.55
diff -p -u -r1.55 glade-project.c
--- src/glade-project.c	26 Oct 2004 17:40:07 -0000	1.55
+++ src/glade-project.c	28 Oct 2004 10:41:36 -0000
@@ -43,6 +43,7 @@ static void glade_project_class_init (Gl
 static void glade_project_init (GladeProject *project);
 static void glade_project_finalize (GObject *object);
 static void glade_project_dispose (GObject *object);
+static GladeInterface *glade_project_export (const GladeProject *project);
 
 enum
 {
@@ -776,6 +777,7 @@ glade_project_new_from_node (GladeXmlNod
 GladeProject *
 glade_project_open (const gchar *path)
 {
+#if 1
 	GladeXmlContext *context;
 	GladeXmlDoc *doc;
 	GladeProject *project;
@@ -786,6 +788,16 @@ glade_project_open (const gchar *path)
 	doc = glade_xml_context_get_doc (context);
 	project = glade_project_new_from_node (glade_xml_doc_get_root (doc));
 	glade_xml_context_free (context);
+#else
+	GladeProject *project;
+	GladeInterface *interface;
+	
+	interface = glade_parser_parse_file (path, NULL);
+	if (interface)
+		return NULL;
+	
+	glade_interface_destroy (interface);
+#endif
 
 	if (project) {
 		project->path = g_strdup_printf ("%s", path);
@@ -809,6 +821,18 @@ glade_project_open (const gchar *path)
 gboolean
 glade_project_save (GladeProject *project, const gchar *path)
 {
+#if 1
+	GladeInterface *interface;
+
+	interface = glade_project_export (project);
+	if (!interface)
+	{
+		g_warning ("Could not export glade document\n");
+		return FALSE;
+	}
+	glade_interface_dump (interface, path);
+	glade_interface_destroy (interface);
+#else
 	GladeXmlContext *context;
 	GladeXmlNode *root;
 	GladeXmlDoc *xml_doc;
@@ -833,6 +857,7 @@ glade_project_save (GladeProject *projec
 
 	if (ret < 0)
 		return FALSE;
+#endif
 
 	if (path != project->path) {
 		g_free (project->path);
@@ -857,3 +882,52 @@ glade_project_get_tooltips (GladeProject
 {
 	return project->tooltips;
 }
+
+/**
+ * glade_project_export:
+ * @project: a #GladeProject
+ * 
+ * Returns:
+ */
+static GladeInterface *
+glade_project_export (const GladeProject *project)
+{
+	GladeInterface *interface;
+	GList *list;
+
+	interface = g_new0 (GladeInterface, 1);
+	interface->names = g_hash_table_new (g_str_hash, g_str_equal);
+	interface->strings = g_hash_table_new_full (g_str_hash,
+						    g_str_equal,
+						    (GDestroyNotify)g_free,
+						    NULL);
+
+	for (list = project->widgets; list; list = list->next)
+	{
+		GladeWidget *widget;
+		GladeWidgetInfo *info;
+
+		widget = glade_widget_get_from_gtk_widget (list->data);
+
+		/* 
+		 * Append toplevel widgets. Each widget then takes
+		 * care of appending its children.
+		 */
+		if (g_type_is_a
+		    (widget->widget_class->type, GTK_TYPE_WINDOW))
+		{
+			info = glade_widget_export (widget, interface);
+			if (!info)
+				return NULL;
+
+			interface->n_toplevels++;
+			interface->toplevels = g_renew (GladeWidgetInfo *,
+							interface->toplevels,
+							interface->n_toplevels);
+			interface->toplevels[interface->n_toplevels - 1] =
+								info;
+		}
+	}
+
+	return interface;
+}
Index: src/glade-property.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-property.c,v
retrieving revision 1.52
diff -p -u -r1.52 glade-property.c
--- src/glade-property.c	26 Oct 2004 17:40:07 -0000	1.52
+++ src/glade-property.c	28 Oct 2004 10:41:36 -0000
@@ -299,3 +299,74 @@ glade_property_write (GladeXmlContext *c
 
 	return node;
 }
+
+/**
+ * glade_property_export:
+ * @context: a #GladeXmlContext
+ * @property: a #GladeProperty:
+ *
+ * TODO: write me
+ *
+ * Returns:
+ */
+gboolean
+glade_property_export (GArray *props, GladeProperty *property, GladeInterface *interface)
+{
+	GladePropInfo info = { 0 };
+	gchar *tmp;
+	gchar *default_str = NULL;
+
+	if (!property->enabled)
+		return FALSE;
+
+	if (!glade_property_class_is_visible (property->class, glade_widget_get_class (property->widget)))
+		return FALSE;
+
+	/* we should change each '-' by '_' on the name of the property 
+         * (<property name="...">) */
+	tmp = g_strdup (property->class->id);
+	if (!tmp)
+		return FALSE;
+	glade_util_replace (tmp, '-', '_');
+
+	/* put the name="..." part on the <property ...> tag */
+	info.name = alloc_propname(interface, tmp);
+ 	/*if (state->translate_prop && state->content->str[0] != '\0') {
+	    if (state->context_prop) 
+		info.value = alloc_string(state->interface,
+					  g_strip_context(state->content->str,
+							   dgettext(state->domain, state->content->str)));
+	    else
+		info.value = alloc_string(state->interface,
+					  dgettext(state->domain, state->content->str));
+ 	} else {
+ 	    info.value = alloc_string(state->interface, state->content->str);
+  	}*/
+	g_free (tmp);
+
+	/* convert the value of this property to a string, and put it between
+	 * the opening and the closing of the property tag */
+	tmp = glade_property_class_make_string_from_gvalue (property->class,
+							    property->value);
+	if (!tmp)
+		return FALSE;
+
+	if (property->class->def)
+	{
+		default_str = glade_property_class_make_string_from_gvalue (property->class,
+									    property->class->def);
+		if (default_str && strcmp (tmp, default_str) == 0)
+		{
+			g_free (tmp);
+			g_free (default_str);
+			return FALSE;
+		}
+	}
+
+	info.value = alloc_string(interface, tmp);
+	g_array_append_val (props, info);
+	g_free (tmp);
+	g_free (default_str);
+
+	return TRUE;
+}
Index: src/glade-property.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-property.h,v
retrieving revision 1.28
diff -p -u -r1.28 glade-property.h
--- src/glade-property.h	10 May 2004 17:30:56 -0000	1.28
+++ src/glade-property.h	28 Oct 2004 10:41:36 -0000
@@ -48,6 +48,9 @@ void glade_property_set (GladeProperty *
 
 GladeXmlNode *glade_property_write (GladeXmlContext *context, GladeProperty *property);
 
+gboolean glade_property_export (GArray *props, GladeProperty *property,
+                                GladeInterface *interface);
+
 
 G_END_DECLS
 
Index: src/glade-signal.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-signal.c,v
retrieving revision 1.9
diff -p -u -r1.9 glade-signal.c
--- src/glade-signal.c	4 Oct 2004 15:45:22 -0000	1.9
+++ src/glade-signal.c	28 Oct 2004 10:41:36 -0000
@@ -147,3 +147,22 @@ glade_signal_new_from_node (GladeXmlNode
 
 	return signal;
 }
+
+/**
+ * glade_signal_export:
+ * @info:
+ * @signal:
+ * @interface:
+ *
+ * Returns:
+ */
+gboolean
+glade_signal_export (GladeSignalInfo *info, GladeSignal *signal,
+		     GladeInterface *interface)
+{
+	info->name = alloc_string(interface, signal->name);
+	info->handler = alloc_string(interface, signal->name);
+	info->after = signal->after;
+
+	return TRUE;
+}
Index: src/glade-signal.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-signal.h,v
retrieving revision 1.7
diff -p -u -r1.7 glade-signal.h
--- src/glade-signal.h	21 Apr 2004 21:03:40 -0000	1.7
+++ src/glade-signal.h	28 Oct 2004 10:41:36 -0000
@@ -28,6 +28,8 @@ GladeXmlNode *glade_signal_write (GladeX
 
 GladeSignal *glade_signal_new_from_node (GladeXmlNode *node);
 
+gboolean glade_signal_export (GladeSignalInfo *info, GladeSignal *signal,
+			      GladeInterface *interface);
 
 G_END_DECLS
 
Index: src/glade-types.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-types.h,v
retrieving revision 1.9
diff -p -u -r1.9 glade-types.h
--- src/glade-types.h	5 Nov 2003 08:56:56 -0000	1.9
+++ src/glade-types.h	28 Oct 2004 10:41:36 -0000
@@ -35,5 +35,6 @@ typedef struct _GladeXmlContext GladeXml
 typedef struct _GladeXmlNode    GladeXmlNode;
 typedef struct _GladeXmlDoc     GladeXmlDoc;
 
+#include <glade/glade-parser.h>
 
 #endif /* __GLADE_TYPES_H__ */
Index: src/glade-widget.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget.c,v
retrieving revision 1.118
diff -p -u -r1.118 glade-widget.c
--- src/glade-widget.c	26 Oct 2004 17:40:07 -0000	1.118
+++ src/glade-widget.c	28 Oct 2004 10:41:36 -0000
@@ -1822,3 +1822,153 @@ glade_widget_read (GladeProject *project
 	glade_widget_debug (widget);
 	return widget;
 }
+
+
+typedef struct _ExportSignalsContext
+{
+	GladeInterface *interface;
+	GArray *signals;
+} ExportSignalsContext;
+
+static void
+glade_widget_export_signals (gpointer key, gpointer value, gpointer user_data)
+{
+	ExportSignalsContext *export_signals_context;
+	size_t i;
+
+	export_signals_context = (ExportSignalsContext *) user_data;
+	GPtrArray *signals = (GPtrArray *) value;
+	for (i = 0; i < signals->len; i++)
+	{
+		GladeSignal *signal = g_ptr_array_index (signals, i);
+		GladeSignalInfo signalinfo;
+
+		glade_signal_export (&signalinfo, signal,
+				     export_signals_context->interface);
+		g_array_append_val (export_signals_context->signals, 
+				    signalinfo);
+	}
+}
+
+gboolean
+glade_widget_export_child (GArray *children, GtkWidget *gtk_widget, GladeInterface *interface)
+{
+	GladeChildInfo info = { 0 };
+	GladeWidget *child_widget;
+	GList *list;
+	GArray *props;
+
+	if (GLADE_IS_PLACEHOLDER (gtk_widget)) {
+		/*child = glade_xml_node_new (context, GLADE_XML_TAG_PLACEHOLDER);
+		glade_xml_node_append_child (child_tag, child);*/
+		return TRUE;
+	}
+
+	child_widget = glade_widget_get_from_gtk_widget (gtk_widget);
+	if (!child_widget)
+		return FALSE;
+
+	if (child_widget->internal)
+		info.internal_child = alloc_string(interface, child_widget->internal);
+
+	info.child = glade_widget_export (child_widget, interface);
+	if (!info.child)
+	{
+		g_warning ("Failed to export child widget");
+		return FALSE;
+	}
+
+	/* Append the packing properties */
+	if (child_widget->packing_properties != NULL) {
+		list = child_widget->packing_properties;
+		props = g_array_new (FALSE, FALSE,
+				     sizeof (GladePropInfo));
+		for (; list; list = list->next) {
+			GladeProperty *property;
+
+			property = list->data;
+			g_assert (property->class->packing == TRUE);
+			glade_property_export (props, property, interface);
+		}
+		info.properties = (GladePropInfo *) props->data;
+		info.n_properties = props->len;
+		g_array_free(props, FALSE);
+	}
+	g_array_append_val (children, info);
+
+	return TRUE;
+}
+
+/**
+ * glade_widget_export:
+ * @widget: a #GladeWidget
+ * @interface: a #GladeInterface
+ *
+ * TODO: write me
+ *
+ * Returns: 
+ */
+GladeWidgetInfo*
+glade_widget_export (GladeWidget *widget, GladeInterface *interface)
+{
+	ExportSignalsContext export_signals_context;
+	GladeWidgetInfo *info;
+	GArray *props, *children;
+	GList *list;
+
+	g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
+
+	info = g_new0 (GladeWidgetInfo, 1);
+
+	info->classname = alloc_string (interface, widget->widget_class->name);
+	info->name = alloc_string (interface, widget->name);
+
+	/* Write the properties */
+	list = widget->properties;
+	props = g_array_new (FALSE, FALSE,
+			     sizeof (GladePropInfo));
+	for (; list; list = list->next)
+	{
+		GladeProperty *property = list->data;
+		if (property->class->packing)
+			continue;
+
+		glade_property_export (props, property, interface);
+	}
+	info->properties = (GladePropInfo *) props->data;
+	info->n_properties = props->len;
+	g_array_free(props, FALSE);
+
+	/* Signals */
+	export_signals_context.interface = interface;
+	export_signals_context.signals = g_array_new (FALSE, FALSE,
+	                                              sizeof (GladeSignalInfo));
+	g_hash_table_foreach (widget->signals,
+			      glade_widget_export_signals,
+			      &export_signals_context);
+	info->signals = (GladeSignalInfo *)
+				export_signals_context.signals->data;
+	info->n_signals = export_signals_context.signals->len;
+	g_array_free (export_signals_context.signals, FALSE);
+
+	/* Children */
+	if (GTK_IS_CONTAINER (widget->widget)) {
+		list = glade_util_container_get_all_children (GTK_CONTAINER (widget->widget));
+		children = g_array_new (FALSE, FALSE,
+	                                sizeof (GladeChildInfo));
+		for (; list; list = list->next) {
+			GtkWidget *child_widget;
+			child_widget = GTK_WIDGET (list->data);
+			glade_widget_export_child (children,
+						   child_widget,
+						   interface);
+	 	}
+		info->children = (GladeChildInfo *) children->data;
+		info->n_children = children->len;
+		g_array_free (children, FALSE);
+	}
+
+	g_hash_table_insert(interface->names, info->name, info);
+
+	return info;
+}
Index: src/glade-widget.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget.h,v
retrieving revision 1.35
diff -p -u -r1.35 glade-widget.h
--- src/glade-widget.h	22 Oct 2004 16:19:39 -0000	1.35
+++ src/glade-widget.h	28 Oct 2004 10:41:36 -0000
@@ -103,6 +103,7 @@ GPtrArray *		glade_widget_list_signal_ha
 /* serialization */
 GladeXmlNode *		glade_widget_write			(GladeWidget *widget, GladeXmlContext *context);
 GladeWidget *		glade_widget_read			(GladeProject *project, GladeXmlNode *node);
+GladeWidgetInfo*	glade_widget_export			(GladeWidget *widget, GladeInterface *interface);
 
 /* helper functions */
 #define			glade_widget_get_from_gtk_widget(w)	g_object_get_data (G_OBJECT (w), "GladeWidgetDataTag")
Index: src/glade-xml-utils.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-xml-utils.c,v
retrieving revision 1.22
diff -p -u -r1.22 glade-xml-utils.c
--- src/glade-xml-utils.c	6 Oct 2004 18:32:46 -0000	1.22
+++ src/glade-xml-utils.c	28 Oct 2004 10:41:37 -0000
@@ -704,3 +704,37 @@ glade_xml_doc_get_root (GladeXmlDoc *doc
 
 	return (GladeXmlNode *)node;
 }
+
+gchar *
+alloc_string(GladeInterface *interface, const gchar *string)
+{
+    gchar *s;
+
+    s = g_hash_table_lookup(interface->strings, string);
+    if (!s)
+	{
+		s = g_strdup(string);
+		g_hash_table_insert(interface->strings, s, s);
+    }
+
+    return s;
+}
+
+gchar *
+alloc_propname(GladeInterface *interface, const gchar *string)
+{
+    static GString *norm_str;
+    gint i;
+
+    if (!norm_str)
+	norm_str = g_string_new_len(NULL, 64);
+
+    /* assign the string to norm_str */
+    g_string_assign(norm_str, string);
+    /* convert all dashes to underscores */
+    for (i = 0; i < norm_str->len; i++)
+	if (norm_str->str[i] == '-')
+	    norm_str->str[i] = '_';
+
+    return alloc_string(interface, norm_str->str);
+}
Index: src/glade-xml-utils.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-xml-utils.h,v
retrieving revision 1.12
diff -p -u -r1.12 glade-xml-utils.h
--- src/glade-xml-utils.h	28 Nov 2003 12:05:59 -0000	1.12
+++ src/glade-xml-utils.h	28 Oct 2004 10:41:37 -0000
@@ -67,6 +67,9 @@ GladeXmlContext * glade_xml_context_new_
 						   const gchar *root_name);
 GladeXmlDoc *     glade_xml_context_get_doc (GladeXmlContext *context);
 
+gchar *		alloc_string(GladeInterface *interface, const gchar *string);
+gchar *		alloc_propname(GladeInterface *interface, const gchar *string);
+
 
 G_END_DECLS
 
