summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChema Celorio <chema@celorio.com>2001-07-22 07:24:51 +0000
committerJose Maria Celorio <chema@src.gnome.org>2001-07-22 07:24:51 +0000
commit550709b27904032300ef7c2973c358be8627b537 (patch)
tree307e0c5f8bb2459141992e650c7dada2081c2d70
parenta0477ad8cddce598ee78f5bd097909b0be18a963 (diff)
downloadglade-550709b27904032300ef7c2973c358be8627b537.tar.gz
implement, new file.
2001-07-22 Chema Celorio <chema@celorio.com> * src/glade-utils.c (glade_util_path_is_writable): implement, new file. * src/glade-property.c (glade_property_write): implement. * src/glade-widget.c (glade_widget_write): add content. * src/glade-xml-utils.c (glade_xml_set_value): fix a lot of the broken issues. Don't confuse properties for node content. Use GladeXmlNode as API entry. Lots of small new functions, lots of cleanup.
-rw-r--r--AUTHORS3
-rw-r--r--ChangeLog12
-rw-r--r--TODO11
-rw-r--r--src/Makefile.am2
-rw-r--r--src/glade-catalog.c24
-rw-r--r--src/glade-choice.c10
-rw-r--r--src/glade-choice.h2
-rw-r--r--src/glade-parameter.c16
-rw-r--r--src/glade-parameter.h2
-rw-r--r--src/glade-project-ui.c44
-rw-r--r--src/glade-project-ui.h1
-rw-r--r--src/glade-project-view.c2
-rw-r--r--src/glade-project.c94
-rw-r--r--src/glade-property-class.c36
-rw-r--r--src/glade-property-class.h2
-rw-r--r--src/glade-property.c13
-rw-r--r--src/glade-property.h3
-rw-r--r--src/glade-utils.c34
-rw-r--r--src/glade-utils.h19
-rw-r--r--src/glade-widget-class.c12
-rw-r--r--src/glade-widget-class.h4
-rw-r--r--src/glade-widget.c31
-rw-r--r--src/glade-widget.h3
-rw-r--r--src/glade-xml-utils.c349
-rw-r--r--src/glade-xml-utils.h96
-rw-r--r--src/glade.h11
26 files changed, 648 insertions, 188 deletions
diff --git a/AUTHORS b/AUTHORS
index de5408fe..e667852b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,6 +2,5 @@ Chema Celorio <chema@ximian.com>
Thanks to :
Michal Palczewski <mpalczew@u.washington.edu> - Widget tree window
-Neil Mock <mock_nt0@yahoo.com> - XML saving
Archit Baweja <bighead@crosswinds.net> - New widgets, _get_type
-Shane Butler <shane_b@operamail.com> - Glade Widget signals \ No newline at end of file
+Shane Butler <shane_b@operamail.com> - Glade Widget signals editor \ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
index a043e60e..ef4a61b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-07-22 Chema Celorio <chema@celorio.com>
+
+ * src/glade-utils.c (glade_util_path_is_writable): implement, new file.
+
+ * src/glade-property.c (glade_property_write): implement.
+
+ * src/glade-widget.c (glade_widget_write): add content.
+
+ * src/glade-xml-utils.c (glade_xml_set_value): fix a lot of the broken issues.
+ Don't confuse properties for node content. Use GladeXmlNode as API entry.
+ Lots of small new functions, lots of cleanup.
+
2001-07-21 Chema Celorio <chema@celorio.com>
* src/glade-project.c (glade_project_save): impl.
diff --git a/TODO b/TODO
index e9f0050d..bda2ee02 100644
--- a/TODO
+++ b/TODO
@@ -11,22 +11,17 @@ plus :
TODO
====
-TAKEN ITEMS (someone is already working on)
------------
-- File loading and saving
-- Common part of the editor
-
OPEN ITEMS [PLease let me know before starting working on any of this]
----------
- Implement glade_widget_delete inside glade-widget.c, delete can already
be called from the popup menu.
- Implement the popup menu option "Select", it needs to create submenus for
-every parent widget and a "Select" option inside it. Inside glade-popup.c
+ every parent widget and a "Select" option inside it. Inside glade-popup.c
- Implement file opened history feature.
- Implement gtk stock buttons.
- gtklabels can't be selected. This looks like a fun thing and maybe tricky
-to fix. I am guessing that gtklabeles don't like the idea of disabling
-double buffering because of pango, but this is just a guess.
+ to fix. I am guessing that gtklabeles don't like the idea of disabling
+ double buffering because of pango, but this is just a guess.
- Implement show clipboard (blocks on copy/cut)
- Implement the menu bar widget and the menu editor.
- Implement the glade-property type "File". For example to be used with a pixmap
diff --git a/src/Makefile.am b/src/Makefile.am
index 07e36350..19bb2031 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,7 @@ glade2_SOURCES = \
glade-choice.c \
glade-editor.c \
glade-gtk.c \
+ glade-utils.c \
glade-signal-editor.c
noinst_HEADERS = \
@@ -63,4 +64,5 @@ noinst_HEADERS = \
glade-choice.h \
glade-gtk.h \
glade-catalog.h \
+ glade-utils.h \
glade-xml-utils.h
diff --git a/src/glade-catalog.c b/src/glade-catalog.c
index 0d2ada83..1e2f2c2f 100644
--- a/src/glade-catalog.c
+++ b/src/glade-catalog.c
@@ -42,9 +42,9 @@ glade_catalog_new (void)
}
static GList *
-glade_catalog_load_names_from_node (XmlParseContext *context, xmlNodePtr node)
+glade_catalog_load_names_from_node (GladeXmlContext *context, GladeXmlNode *node)
{
- xmlNodePtr child;
+ GladeXmlNode *child;
GList *list;
gchar *name;
@@ -52,7 +52,7 @@ glade_catalog_load_names_from_node (XmlParseContext *context, xmlNodePtr node)
return NULL;
list = NULL;
- child = node->children;
+ child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
if (!glade_xml_node_verify (child, GLADE_TAG_GLADE_WIDGET))
@@ -61,7 +61,7 @@ glade_catalog_load_names_from_node (XmlParseContext *context, xmlNodePtr node)
if (name == NULL)
return NULL;
list = g_list_prepend (list, name);
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
@@ -72,13 +72,15 @@ glade_catalog_load_names_from_node (XmlParseContext *context, xmlNodePtr node)
static void
glade_catalog_load_names_from_file (GladeCatalog *catalog, const gchar *file_name)
{
- XmlParseContext *context;
-
- context = glade_xml_parse_context_new_from_path (file_name, NULL, GLADE_TAG_CATALOG);
- if (context == NULL) return;
- catalog->names = glade_catalog_load_names_from_node (context, context->doc->children);
- glade_xml_parse_context_free (context);
-
+ GladeXmlContext *context;
+ GladeXmlNode *root;
+
+ context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_CATALOG);
+ if (context == NULL)
+ return;
+ root = glade_xml_doc_get_root (context->doc);
+ catalog->names = glade_catalog_load_names_from_node (context, root);
+ glade_xml_context_free (context);
}
static GladeCatalog *
diff --git a/src/glade-choice.c b/src/glade-choice.c
index bbb36cb9..8fe3e024 100644
--- a/src/glade-choice.c
+++ b/src/glade-choice.c
@@ -119,7 +119,7 @@ glade_string_from_string (const gchar *string)
}
static GladeChoice *
-glade_choice_new_from_node (xmlNodePtr node)
+glade_choice_new_from_node (GladeXmlNode *node)
{
GladeChoice *choice;
@@ -142,17 +142,17 @@ glade_choice_new_from_node (xmlNodePtr node)
}
GList *
-glade_choice_list_new_from_node (xmlNodePtr node)
+glade_choice_list_new_from_node (GladeXmlNode *node)
{
+ GladeXmlNode *child;
GladeChoice *choice;
- xmlNodePtr child;
GList *list;
if (!glade_xml_node_verify (node, GLADE_TAG_CHOICES))
return NULL;
list = NULL;
- child = node->children;
+ child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
@@ -162,7 +162,7 @@ glade_choice_list_new_from_node (xmlNodePtr node)
if (choice == NULL)
return NULL;
list = g_list_prepend (list, choice);
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
diff --git a/src/glade-choice.h b/src/glade-choice.h
index cde437e6..deb99433 100644
--- a/src/glade-choice.h
+++ b/src/glade-choice.h
@@ -51,7 +51,7 @@ struct _GladeChoice {
GladeChoice * glade_choice_new (void);
-GList * glade_choice_list_new_from_node (xmlNodePtr node);
+GList * glade_choice_list_new_from_node (GladeXmlNode *node);
G_END_DECLS
diff --git a/src/glade-parameter.c b/src/glade-parameter.c
index 44cc3031..520e03b4 100644
--- a/src/glade-parameter.c
+++ b/src/glade-parameter.c
@@ -124,7 +124,7 @@ glade_parameter_new (void)
}
static GladeParameter *
-glade_parameter_new_from_node (xmlNodePtr node)
+glade_parameter_new_from_node (GladeXmlNode *node)
{
GladeParameter *parameter;
@@ -132,8 +132,8 @@ glade_parameter_new_from_node (xmlNodePtr node)
return NULL;
parameter = glade_parameter_new ();
- parameter->key = glade_xml_get_value_string_required (node, GLADE_TAG_KEY, NULL);
- parameter->value = glade_xml_get_value_string_required (node, GLADE_TAG_VALUE, NULL);
+ parameter->key = glade_xml_get_property_string_required (node, GLADE_TAG_KEY, NULL);
+ parameter->value = glade_xml_get_property_string_required (node, GLADE_TAG_VALUE, NULL);
if (!parameter->key || !parameter->value)
return NULL;
@@ -158,10 +158,10 @@ glade_parameter_list_find_by_key (GList *list, const gchar *key)
GList *
-glade_parameter_list_new_from_node (GList *list, xmlNodePtr node)
+glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node)
{
GladeParameter *parameter;
- xmlNodePtr child;
+ GladeXmlNode *child;
GList *findme;
if (!glade_xml_node_verify (node, GLADE_TAG_PARAMETERS))
@@ -170,7 +170,7 @@ glade_parameter_list_new_from_node (GList *list, xmlNodePtr node)
if (child == NULL)
return NULL;
- child = node->children;
+ child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
@@ -187,11 +187,11 @@ glade_parameter_list_new_from_node (GList *list, xmlNodePtr node)
if (findme) {
glade_parameter_free (findme->data);
findme->data = parameter;
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_prepend (list, parameter);
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
diff --git a/src/glade-parameter.h b/src/glade-parameter.h
index 545e8f29..548ab8ee 100644
--- a/src/glade-parameter.h
+++ b/src/glade-parameter.h
@@ -39,7 +39,7 @@ void glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean
void glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value);
-GList * glade_parameter_list_new_from_node (GList *list, xmlNodePtr node);
+GList * glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node);
/* Convenience functions */
GtkAdjustment * glade_parameter_adjustment_new (GList *parameters);
diff --git a/src/glade-project-ui.c b/src/glade-project-ui.c
index 3acc546c..ad3e44f8 100644
--- a/src/glade-project-ui.c
+++ b/src/glade-project-ui.c
@@ -28,26 +28,31 @@
#define GLADE_SELECTOR_FILENAME "GladeFileSelectorFilename"
static gint
-glade_project_ui_delete_event_cb (GtkWidget *widget, GdkEventAny *event)
-{
- gtk_main_quit ();
-
- return TRUE;
-}
-
-static gint
-glade_project_ui_cancel_clicked (GtkWidget *button, gpointer not_used)
+glade_project_ui_delete_event_cb (GtkWidget *selector, GdkEventAny *event)
{
gtk_main_quit ();
+ gtk_object_set_user_data (GTK_OBJECT (selector), NULL);
+
return TRUE;
}
static gint
-glade_project_ui_ok_clicked (GtkWidget *button, gpointer not_used)
+glade_project_ui_selector_clicked (GtkWidget *button, GtkWidget *selector)
{
+ g_return_val_if_fail (GTK_IS_FILE_SELECTION (selector), FALSE);
+
+ if (button == GTK_FILE_SELECTION (selector)->ok_button) {
+ const gchar *file;
+ file = gtk_file_selection_get_filename (GTK_FILE_SELECTION (selector));
+ gtk_object_set_user_data (GTK_OBJECT (selector), g_strdup (file));
+ } else
+ gtk_object_set_user_data (GTK_OBJECT (selector), NULL);
+
gtk_main_quit ();
+ gtk_widget_hide (selector);
+
return TRUE;
}
@@ -62,14 +67,14 @@ glade_project_ui_save_get_name (GladeProject *project)
gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(selector)->ok_button),
"clicked",
- GTK_SIGNAL_FUNC (glade_project_ui_ok_clicked),
- NULL);
+ GTK_SIGNAL_FUNC (glade_project_ui_selector_clicked),
+ selector);
gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(selector)->cancel_button),
"clicked",
- GTK_SIGNAL_FUNC (glade_project_ui_cancel_clicked),
- NULL);
+ GTK_SIGNAL_FUNC (glade_project_ui_selector_clicked),
+ selector);
- gtk_signal_connect( GTK_OBJECT(selector), "delete_event",
+ gtk_signal_connect (GTK_OBJECT(selector), "delete_event",
GTK_SIGNAL_FUNC (glade_project_ui_delete_event_cb),
NULL);
@@ -77,8 +82,15 @@ glade_project_ui_save_get_name (GladeProject *project)
gtk_main ();
- return g_strdup ("Foo.xml");
+ return gtk_object_get_user_data (GTK_OBJECT (selector));
}
+void
+glade_project_ui_warn (GladeProject *project, const gchar *warning)
+{
+ /* This are warnings to the users, use a nice dialog and stuff */
+
+ g_warning (warning);
+}
diff --git a/src/glade-project-ui.h b/src/glade-project-ui.h
index 47a1a886..513ff0fd 100644
--- a/src/glade-project-ui.h
+++ b/src/glade-project-ui.h
@@ -5,6 +5,7 @@
G_BEGIN_DECLS
gchar * glade_project_ui_save_get_name (GladeProject *project);
+void glade_project_ui_warn (GladeProject *project, const gchar *warning);
G_END_DECLS
diff --git a/src/glade-project-view.c b/src/glade-project-view.c
index d844800c..927670f0 100644
--- a/src/glade-project-view.c
+++ b/src/glade-project-view.c
@@ -193,7 +193,7 @@ glade_project_view_populate_model (GtkTreeStore *model,
list = project->widgets;
for (; list != NULL; list = list->next) {
widget = list->data;
- if (GLADE_WIDGET_TOPLEVEL (widget))
+ if (GLADE_WIDGET_IS_TOPLEVEL (widget))
toplevels = g_list_append (toplevels, widget);
}
diff --git a/src/glade-project.c b/src/glade-project.c
index 91153e6c..c7d82f63 100644
--- a/src/glade-project.c
+++ b/src/glade-project.c
@@ -28,6 +28,9 @@
#include "glade-project-ui.h"
#include "glade-project-window.h"
#include "glade-widget.h"
+#include "glade-widget-class.h"
+#include "glade-xml-utils.h"
+#include "glade-widget.h"
static void glade_project_class_init (GladeProjectClass * klass);
static void glade_project_init (GladeProject *project);
@@ -334,6 +337,61 @@ glade_project_selection_set (GladeWidget *widget,
/**
+ * glade_project_write_widgets:
+ * @context:
+ * @node:
+ *
+ * Give a project it appends to @node all the toplevel widgets. Each widget is responsible
+ * for appending it's childrens
+ *
+ * Return Value: FALSE on error, TRUE otherwise
+ **/
+static gboolean
+glade_project_write_widgets (const GladeProject *project, GladeXmlContext *context, GladeXmlNode *node)
+{
+ GladeXmlNode *child;
+ GladeWidget *widget;
+ GList *list;
+
+ list = project->widgets;
+ for (; list != NULL; list = list->next) {
+ widget = list->data;
+ if (GLADE_WIDGET_IS_TOPLEVEL (widget)) {
+ child = glade_widget_write (context, widget);
+ if (child != NULL)
+ glade_xml_append_child (node, child);
+ else
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ * glade_project_write:
+ * @project:
+ *
+ * Retrns the root node of a newly created xml representation of the project and its contents
+ *
+ * Return Value:
+ **/
+static GladeXmlNode *
+glade_project_write (GladeXmlContext *context, const GladeProject *project)
+{
+ GladeXmlNode *node;
+
+ node = glade_xml_node_new (context, GLADE_XML_TAG_PROJECT);
+ if (node == NULL)
+ return NULL;
+
+ if (!glade_project_write_widgets (project, context, node))
+ return NULL;
+
+ return node;
+}
+
+/**
* glade_project_save_to_file:
* @project:
* @file_name:
@@ -342,11 +400,35 @@ glade_project_selection_set (GladeWidget *widget,
*
* Return Value: TRUE on success, FALSE otherwise
**/
-gboolean
+static gboolean
glade_project_save_to_file (GladeProject *project,
- const gchar *file_name)
+ const gchar * full_path)
{
- g_print ("Save %s to %s\n", project->name, file_name);
+ GladeXmlContext *context;
+ GladeXmlNode *root;
+ GladeXmlDoc *xml_doc;
+ gboolean ret;
+
+ if (!glade_util_path_is_writable (full_path))
+ return FALSE;
+
+ xml_doc = glade_xml_doc_new ();
+ if (xml_doc == NULL) {
+ g_warning ("Could not create xml document\n");
+ return FALSE;
+ }
+ context = glade_xml_context_new (xml_doc, NULL);
+ root = glade_project_write (context, project);
+ glade_xml_context_destroy (context);
+ if (root == NULL)
+ return FALSE;
+
+ glade_xml_doc_set_root (xml_doc, root);
+ ret = glade_xml_doc_save (xml_doc, full_path);
+ glade_xml_doc_free (xml_doc);
+
+ if (ret < 0)
+ return FALSE;
return TRUE;
}
@@ -369,10 +451,10 @@ glade_project_save (GladeProject *project)
if (project->path == NULL)
project->path = glade_project_ui_save_get_name (project);
- if (project->path == NULL)
+ if (!glade_project_save_to_file (project, project->path)) {
+ glade_project_ui_warn (project, _("Invalid file name"));
return FALSE;
-
- glade_project_save_to_file (project, project->path);
+ }
return TRUE;
}
diff --git a/src/glade-property-class.c b/src/glade-property-class.c
index 582f2ce3..d327dbe5 100644
--- a/src/glade-property-class.c
+++ b/src/glade-property-class.c
@@ -98,7 +98,7 @@ glade_property_query_new (void)
static GladePropertyQuery *
-glade_query_new_from_node (xmlNodePtr node)
+glade_query_new_from_node (GladeXmlNode *node)
{
GladePropertyQuery *query;
@@ -377,10 +377,10 @@ glade_property_get_parameters_choice (GParamSpec *spec,
static GList *
glade_property_class_get_parameters_from_spec (GParamSpec *spec,
GladePropertyClass *class,
- xmlNodePtr node)
+ GladeXmlNode *node)
{
GList *parameters = NULL;
- xmlNodePtr child;
+ GladeXmlNode *child;
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
@@ -421,7 +421,7 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
static GladePropertyClass *
glade_property_class_new_from_param_spec (const gchar *name,
GladeWidgetClass *widget_class,
- xmlNodePtr node)
+ GladeXmlNode *node)
{
GladePropertyClass *class;
GParamSpec *spec;
@@ -488,9 +488,9 @@ glade_property_class_get_set_function (GladePropertyClass *class, const gchar *f
}
static GList *
-glade_xml_read_list (xmlNodePtr node, const gchar *list_tag, const gchar *item_tag)
+glade_xml_read_list (GladeXmlNode *node, const gchar *list_tag, const gchar *item_tag)
{
- xmlNodePtr child;
+ GladeXmlNode *child;
GList *list = NULL;
gchar *item;
@@ -498,7 +498,7 @@ glade_xml_read_list (xmlNodePtr node, const gchar *list_tag, const gchar *item_t
if (child == NULL)
return NULL;
- child = child->children;
+ child = glade_xml_node_get_children (child);
while (child != NULL) {
skip_text (child);
@@ -507,7 +507,7 @@ glade_xml_read_list (xmlNodePtr node, const gchar *list_tag, const gchar *item_t
item = glade_xml_get_content (child);
if (item != NULL)
list = g_list_prepend (list, item);
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
@@ -517,10 +517,10 @@ glade_xml_read_list (xmlNodePtr node, const gchar *list_tag, const gchar *item_t
static GladePropertyClass *
-glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_class)
+glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget_class)
{
GladePropertyClass *property_class;
- xmlNodePtr child;
+ GladeXmlNode *child;
gchar *type;
gchar *id;
gchar *name;
@@ -528,7 +528,7 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
if (!glade_xml_node_verify (node, GLADE_TAG_PROPERTY))
return NULL;
- id = glade_xml_get_value_string_required (node, GLADE_TAG_ID, widget_class->name);
+ id = glade_xml_get_property_string_required (node, GLADE_TAG_ID, widget_class->name);
if (id == NULL)
return NULL;
@@ -537,9 +537,7 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
* We can have a property like ... ParamSpec="TRUE">
* Or a child like <ParamSpec/>, but this will be deprecated
*/
- child = glade_xml_search_child (node, GLADE_TAG_PARAM_SPEC);
- if (child ||
- glade_xml_get_boolean (node, GLADE_TAG_PARAM_SPEC)) {
+ if (glade_xml_property_get_boolean (node, GLADE_TAG_PARAM_SPEC)) {
property_class = glade_property_class_new_from_param_spec (id, widget_class, node);
g_free (id);
if (property_class == NULL)
@@ -548,7 +546,7 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
}
- name = glade_xml_get_value_string_required (node, GLADE_TAG_NAME, widget_class->name);
+ name = glade_xml_get_property_string_required (node, GLADE_TAG_NAME, widget_class->name);
if (name == NULL)
return NULL;
@@ -622,17 +620,17 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
}
GList *
-glade_property_class_list_new_from_node (xmlNodePtr node, GladeWidgetClass *class)
+glade_property_class_list_new_from_node (GladeXmlNode *node, GladeWidgetClass *class)
{
GladePropertyClass *property_class;
- xmlNodePtr child;
+ GladeXmlNode *child;
GList *list;
if (!glade_xml_node_verify (node, GLADE_TAG_PROPERTIES))
return NULL;
list = NULL;
- child = node->children;
+ child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
@@ -641,7 +639,7 @@ glade_property_class_list_new_from_node (xmlNodePtr node, GladeWidgetClass *clas
property_class = glade_property_class_new_from_node (child, class);
if (property_class != NULL)
list = g_list_prepend (list, property_class);
- child = child->next;
+ child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
diff --git a/src/glade-property-class.h b/src/glade-property-class.h
index bdea6fb0..10c289bf 100644
--- a/src/glade-property-class.h
+++ b/src/glade-property-class.h
@@ -170,7 +170,7 @@ struct _GladePropertyClass {
GtkWidget * glade_property_class_create_label (GladePropertyClass *pclass);
GtkWidget * glade_property_class_create_input (GladePropertyClass *pclass);
-GList * glade_property_class_list_new_from_node (xmlNodePtr node, GladeWidgetClass *class);
+GList * glade_property_class_list_new_from_node (GladeXmlNode * node, GladeWidgetClass *class);
GParamSpec * glade_property_class_find_spec (GladeWidgetClass *class, const gchar *name);
diff --git a/src/glade-property.c b/src/glade-property.c
index eea74229..b3522f49 100644
--- a/src/glade-property.c
+++ b/src/glade-property.c
@@ -479,3 +479,16 @@ glade_property_query_result_destroy (GladePropertyQueryResult *result)
g_free (result);
}
+
+GladeXmlNode *
+glade_property_write (GladeXmlContext *context, GladeProperty *property)
+{
+ GladeXmlNode *node;
+
+ node = glade_xml_node_new (context, GLADE_XML_TAG_PROPERTY);
+ glade_xml_node_set_property_string (node, GLADE_XML_TAG_NAME, property->class->id);
+ glade_xml_set_content (node, property->value);
+
+ return node;
+}
+
diff --git a/src/glade-property.h b/src/glade-property.h
index 689430ed..8d517247 100644
--- a/src/glade-property.h
+++ b/src/glade-property.h
@@ -86,6 +86,9 @@ void glade_property_query_result_set_int (GladePropertyQueryResult *result,
const gchar *key,
gint value);
+/* XML i/o */
+GladeXmlNode * glade_property_write (GladeXmlContext *context, GladeProperty *property);
+
G_END_DECLS
diff --git a/src/glade-utils.c b/src/glade-utils.c
new file mode 100644
index 00000000..334efd79
--- /dev/null
+++ b/src/glade-utils.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Chema Celorio <chema@celorio.com>
+ */
+
+
+#include "glade.h"
+
+
+
+gboolean
+glade_util_path_is_writable (const gchar *full_path)
+{
+ glade_implement_me (NULL);
+
+ return TRUE;
+}
diff --git a/src/glade-utils.h b/src/glade-utils.h
new file mode 100644
index 00000000..903ee3a8
--- /dev/null
+++ b/src/glade-utils.h
@@ -0,0 +1,19 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef __GLADE_UTILS_H__
+#define __GLADE_UTILS_H__
+
+G_BEGIN_DECLS
+
+/* Function is a GNU extension */
+#ifndef __GNUC__
+#define __FUNCTION__ ""
+#endif
+
+#define glade_implement_me(m) g_print ("Implement me : %s %d %s\n", __FILE__, __LINE__, __FUNCTION__);
+
+gboolean glade_util_path_is_writable (const gchar *full_path);
+
+
+G_END_DECLS
+
+#endif /* __GLADE_UTILS_H__ */
diff --git a/src/glade-widget-class.c b/src/glade-widget-class.c
index d948fe7d..af9bd6e4 100644
--- a/src/glade-widget-class.c
+++ b/src/glade-widget-class.c
@@ -198,10 +198,10 @@ glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function
}
GladeWidgetClass *
-glade_widget_class_new_from_node (xmlNodePtr node)
+glade_widget_class_new_from_node (GladeXmlNode *node)
{
GladeWidgetClass *class;
- xmlNodePtr child;
+ GladeXmlNode *child;
gchar *init_function_name;
if (!glade_xml_node_verify (node, GLADE_TAG_GLADE_WIDGET_CLASS))
@@ -283,17 +283,17 @@ glade_widget_class_create_pixmap (GladeWidgetClass *class)
GladeWidgetClass *
glade_widget_class_new_from_name (const gchar *name)
{
- XmlParseContext *context;
+ GladeXmlContext *context;
GladeWidgetClass *class;
gchar *file_name;
file_name = g_strconcat (WIDGETS_DIR, "/", name, ".xml", NULL);
- context = glade_xml_parse_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS);
+ context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS);
if (context == NULL)
return NULL;
- class = glade_widget_class_new_from_node (context->doc->children);
- glade_xml_parse_context_free (context);
+ class = glade_widget_class_new_from_node (glade_xml_context_get_root (context));
+ glade_xml_context_free (context);
if (!glade_widget_class_create_pixmap (class))
return NULL;
diff --git a/src/glade-widget-class.h b/src/glade-widget-class.h
index 675cdbc0..797934ed 100644
--- a/src/glade-widget-class.h
+++ b/src/glade-widget-class.h
@@ -13,7 +13,7 @@ typedef enum {
#define GLADE_IS_WIDGET_CLASS(gwc) (gwc != NULL)
#define GLADE_WIDGET_FLAGS(gw) ((GLADE_WIDGET(gw)->class)->flags)
-#define GLADE_WIDGET_TOPLEVEL(gw) ((GLADE_WIDGET_FLAGS(gw) & GLADE_TOPLEVEL) != 0)
+#define GLADE_WIDGET_IS_TOPLEVEL(gw) ((GLADE_WIDGET_FLAGS(gw) & GLADE_TOPLEVEL) != 0)
#define GLADE_WIDGET_ADD_PLACEHOLDER(gw) ((GLADE_WIDGET_FLAGS(gw) & GLADE_ADD_PLACEHOLDER) != 0)
#define GLADE_WIDGET_CLASS_FLAGS(gwc) ((GLADE_WIDGET_CLASS(gwc)->flags))
@@ -70,7 +70,7 @@ struct _GladeWidgetClassSignal {
};
GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name);
-GladeWidgetClass * glade_widget_class_new_from_node (xmlNodePtr node);
+GladeWidgetClass * glade_widget_class_new_from_node (GladeXmlNode *node);
GladeWidgetClass * glade_widget_class_get_by_name (const gchar *name);
const gchar * glade_widget_class_get_name (GladeWidgetClass *class);
diff --git a/src/glade-widget.c b/src/glade-widget.c
index 895aafb5..816b84b7 100644
--- a/src/glade-widget.c
+++ b/src/glade-widget.c
@@ -814,3 +814,34 @@ glade_widget_new_from_class_name (const gchar *name,
}
+
+GladeXmlNode *
+glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
+{
+ GladeProperty *property;
+ GladeXmlNode *node;
+ GladeXmlNode *child;
+ GList *list;
+
+ g_return_val_if_fail (GLADE_XML_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
+
+ node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET);
+
+ glade_xml_node_set_property_string (node, GLADE_XML_TAG_CLASS, widget->class->name);
+ glade_xml_node_set_property_string (node, GLADE_XML_TAG_ID, widget->name);
+
+ list = widget->properties;
+ for (; list != NULL; list = list->next) {
+ property = list->data;
+ child = glade_property_write (context, property);
+ if (child == NULL)
+ return NULL;
+ glade_xml_append_child (node, child);
+ }
+
+
+ return node;
+}
+
+
diff --git a/src/glade-widget.h b/src/glade-widget.h
index 41c7533b..4d280e8d 100644
--- a/src/glade-widget.h
+++ b/src/glade-widget.h
@@ -89,6 +89,9 @@ void glade_widget_delete (GladeWidget *widget);
GladeWidget * glade_widget_get_from_gtk_widget (GtkWidget *widget);
+/* Xml saving & reading */
+GladeXmlNode * glade_widget_write (GladeXmlContext *context, GladeWidget *widget);
+
G_END_DECLS
diff --git a/src/glade-xml-utils.c b/src/glade-xml-utils.c
index 601f7471..f0578f62 100644
--- a/src/glade-xml-utils.c
+++ b/src/glade-xml-utils.c
@@ -19,10 +19,10 @@
* the content of a child.
*/
void
-glade_xml_set_value (xmlNodePtr node, const char *name, const char *val)
+glade_xml_set_value (GladeXmlNode *node_in, const char *name, const char *val)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
char *ret;
- xmlNodePtr child;
ret = xmlGetProp (node, name);
if (ret != NULL){
@@ -30,21 +30,13 @@ glade_xml_set_value (xmlNodePtr node, const char *name, const char *val)
xmlSetProp (node, name, val);
return;
}
- child = node->children;
- while (child != NULL){
- if (!strcmp (child->name, name)){
- xmlNodeSetContent (child, val);
- return;
- }
- child = child->next;
- }
- xmlSetProp (node, name, val);
}
gchar *
-glade_xml_get_content (xmlNodePtr node)
+glade_xml_get_content (GladeXmlNode *node_in)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
gchar *ret;
char *val;
@@ -55,6 +47,14 @@ glade_xml_get_content (xmlNodePtr node)
return ret;
}
+void
+glade_xml_set_content (GladeXmlNode *node_in, const gchar *content)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ xmlNodeSetContent(node, content);
+}
+
/*
* Get a value for a node either carried as an attibute or as
* the content of a child.
@@ -69,13 +69,6 @@ glade_xml_get_value (xmlNodePtr node, const char *name)
char *ret, *val;
xmlNodePtr child;
- val = (char *) xmlGetProp (node, name);
- if (val != NULL) {
- ret = g_strdup (val);
- xmlFree (val);
- return ret;
- }
-
child = node->children;
while (child != NULL) {
@@ -96,11 +89,11 @@ glade_xml_get_value (xmlNodePtr node, const char *name)
return NULL;
}
-
-
gboolean
-glade_xml_node_verify (xmlNodePtr node, const gchar *name)
+glade_xml_node_verify (GladeXmlNode *node_in, const gchar *name)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
g_return_val_if_fail (node != NULL, FALSE);
if (strcmp (node->name, name) != 0) {
@@ -117,8 +110,9 @@ glade_xml_node_verify (xmlNodePtr node, const gchar *name)
* the content of a child.
*/
gboolean
-glade_xml_get_value_int (xmlNodePtr node, const char *name, int *val)
+glade_xml_get_value_int (GladeXmlNode *node_in, const char *name, int *val)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
char *ret;
int i;
int res;
@@ -147,7 +141,7 @@ glade_xml_get_value_int (xmlNodePtr node, const char *name, int *val)
* Return Value:
**/
gboolean
-glade_xml_get_value_int_required (xmlNodePtr node, const char *name, int *val)
+glade_xml_get_value_int_required (GladeXmlNode *node, const char *name, int *val)
{
gboolean ret;
@@ -155,7 +149,7 @@ glade_xml_get_value_int_required (xmlNodePtr node, const char *name, int *val)
if (ret == FALSE)
g_warning ("The file did not contained the required value \"%s\"\n"
- "Under the \"%s\" tag.", name, node->name);
+ "Under the \"%s\" tag.", name, glade_xml_node_get_name (node));
return ret;
}
@@ -166,11 +160,37 @@ glade_xml_get_value_int_required (xmlNodePtr node, const char *name, int *val)
* the content of a child.
*/
gchar *
-glade_xml_get_value_string (xmlNodePtr node, const char *name)
+glade_xml_get_value_string (GladeXmlNode *node_in, const char *name)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
return glade_xml_get_value (node, name);
}
+static char *
+glade_xml_get_property (xmlNodePtr node, const char *name)
+{
+ char *ret, *val;
+
+ val = (char *) xmlGetProp (node, name);
+ if (val != NULL) {
+ ret = g_strdup (val);
+ xmlFree (val);
+ return ret;
+ }
+
+ return NULL;
+}
+
+
+static void
+glade_xml_set_property (xmlNodePtr node, const char *name, const char *value)
+{
+ if (value != NULL) {
+ xmlSetProp (node, name, value);
+ }
+}
+
+
#define GLADE_TAG_TRUE "True"
#define GLADE_TAG_FALSE "False"
#define GLADE_TAG_TRUE2 "TRUE"
@@ -180,8 +200,9 @@ glade_xml_get_value_string (xmlNodePtr node, const char *name)
* the content of a child.
*/
gboolean
-glade_xml_get_boolean (xmlNodePtr node, const char *name)
+glade_xml_get_boolean (GladeXmlNode *node_in, const char *name)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
gchar * value;
gboolean ret = FALSE;
@@ -204,14 +225,48 @@ glade_xml_get_boolean (xmlNodePtr node, const char *name)
return ret;
}
+
+/*
+ * Get a String value for a node either carried as an attibute or as
+ * the content of a child.
+ */
+gboolean
+glade_xml_property_get_boolean (GladeXmlNode *node_in, const char *name)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+ gchar * value;
+ gboolean ret = FALSE;
+
+ value = glade_xml_get_property (node, name);
+ if (value == NULL)
+ return FALSE;
+
+ if (strcmp (value, GLADE_TAG_FALSE) == 0)
+ ret = FALSE;
+ else if (strcmp (value, GLADE_TAG_FALSE2) == 0)
+ ret = FALSE;
+ else if (strcmp (value, GLADE_TAG_TRUE) == 0)
+ ret = TRUE;
+ else if (strcmp (value, GLADE_TAG_TRUE2) == 0)
+ ret = TRUE;
+ else
+ g_warning ("Boolean tag unrecognized *%s*\n", value);
+
+ g_free (value);
+
+ return ret;
+}
+
+
#undef GLADE_TAG_TRUE
#undef GLADE_TAG_FALSE
#undef GLADE_TAG_TRUE2
#undef GLADE_TAG_FALSE2
gchar *
-glade_xml_get_value_string_required (xmlNodePtr node, const char *name, const char *xtra)
+glade_xml_get_value_string_required (GladeXmlNode *node_in, const char *name, const char *xtra)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
gchar *value = glade_xml_get_value (node, name);
if (value == NULL) {
@@ -225,20 +280,55 @@ glade_xml_get_value_string_required (xmlNodePtr node, const char *name, const ch
return value;
}
+gchar *
+glade_xml_get_property_string (GladeXmlNode *node_in, const gchar *name)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ return glade_xml_get_property (node, name);
+}
+
+void
+glade_xml_node_set_property_string (GladeXmlNode *node_in, const gchar *name, const gchar *string)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ glade_xml_set_property (node, name, string);
+}
+
+
+gchar *
+glade_xml_get_property_string_required (GladeXmlNode *node_in, const char *name, const char *xtra)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+ gchar *value = glade_xml_get_property_string (node_in, name);
+
+ if (value == NULL) {
+ if (xtra == NULL)
+ g_warning ("The file did not contained 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"
+ "Under the \"%s\" tag (%s).", name, node->name, xtra);
+ }
+ return value;
+}
+
/*
* Search a child by name,
*/
-xmlNodePtr
-glade_xml_search_child (xmlNodePtr node, const char *name)
+GladeXmlNode *
+glade_xml_search_child (GladeXmlNode *node_in, const char *name)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
xmlNodePtr child;
child = node->children;
while (child != NULL){
if (!strcmp (child->name, name))
- return child;
+ return (GladeXmlNode *)child;
child = child->next;
}
@@ -255,16 +345,16 @@ glade_xml_search_child (xmlNodePtr node, const char *name)
*
* Return Value:
**/
-xmlNodePtr
-glade_xml_search_child_required (xmlNodePtr tree, const gchar* name)
+GladeXmlNode *
+glade_xml_search_child_required (GladeXmlNode *node, const gchar* name)
{
- xmlNodePtr child;
+ GladeXmlNode *child;
- child = glade_xml_search_child (tree, name);
+ child = glade_xml_search_child (node, name);
if (child == NULL)
g_warning ("The file did not contained the required tag \"%s\"\n"
- "Under the \"%s\" node.", name, tree->name);
+ "Under the \"%s\" node.", name, glade_xml_node_get_name (node));
return child;
}
@@ -274,10 +364,10 @@ glade_xml_search_child_required (xmlNodePtr tree, const gchar* name)
static void
-glade_xml_utils_new_hash_item_from_node (xmlNodePtr tree,
- gchar **key_,
- gchar **value_,
- const gchar *hash_type)
+glade_xml_utils_new_hash_item_from_node (xmlNodePtr node,
+ gchar **key_,
+ gchar **value_,
+ const gchar *hash_type)
{
gchar *key;
gchar *value;
@@ -285,8 +375,8 @@ glade_xml_utils_new_hash_item_from_node (xmlNodePtr tree,
*key_ = NULL;
*value_ = NULL;
- key = g_strdup (tree->name);
- value = xmlNodeGetContent(tree);
+ key = g_strdup (node->name);
+ value = xmlNodeGetContent (node);
*key_ = key;
*value_ = value;
@@ -296,30 +386,27 @@ glade_xml_utils_new_hash_item_from_node (xmlNodePtr tree,
}
GHashTable *
-glade_xml_utils_new_hash_from_node (xmlNodePtr tree_, const gchar *hash_type)
+glade_xml_utils_new_hash_from_node (GladeXmlNode *node_in, const gchar *hash_type)
{
+ xmlNodePtr node = (xmlNodePtr) node_in;
GHashTable *hash;
- xmlNodePtr node;
- xmlNodePtr tree;
gchar *key;
gchar *value;
- g_return_val_if_fail (tree_ != NULL, NULL);
+ g_return_val_if_fail (node != NULL, NULL);
g_return_val_if_fail (hash_type != NULL, NULL);
- tree = tree_;
-
- if (!glade_xml_node_verify (tree, hash_type))
+ if (!glade_xml_node_verify (node_in, hash_type))
return NULL;
hash = g_hash_table_new (g_str_hash, g_str_equal);
/* This is not an error, since the hash can be empty */
- if (tree->children == NULL)
+ if (node->children == NULL)
return hash;
- node = tree->children;
+ node = node->children;
while (node != NULL) {
- skip_text (node);
+ skip_text_libxml (node);
glade_xml_utils_new_hash_item_from_node (node, &key, &value, hash_type);
if ((key == NULL) || (value == NULL))
return NULL;
@@ -330,19 +417,19 @@ glade_xml_utils_new_hash_from_node (xmlNodePtr tree_, const gchar *hash_type)
return hash;
}
-
+#if 0
static void
glade_xml_utils_hash_item_write (gpointer key_in, gpointer value_in, gpointer data)
{
- xmlNodePtr item;
- xmlNodePtr node;
+ GladeXmlNode *item;
+ GladeXmlNode *node;
gchar *key;
gchar *value;
key = (gchar *) key_in;
value = (gchar *) value_in;
- node = (xmlNodePtr) data;
-
+ node = (GladeXmlNode *) data;
+
item = xmlNewChild (node, NULL, key, value);
if (item == NULL)
@@ -350,15 +437,15 @@ glade_xml_utils_hash_item_write (gpointer key_in, gpointer value_in, gpointer da
key, value);
}
-xmlNodePtr
-glade_xml_utils_hash_write (XmlParseContext *context, GHashTable *hash, const gchar *name)
+GladeXmlNode *
+glade_xml_utils_hash_write (GladeXmlContext *context, GHashTable *hash, const gchar *name)
{
- xmlNodePtr node;
+ GladeXmlNode *node;
g_return_val_if_fail (context != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
- node = xmlNewDocNode (context->doc, context->ns, name, NULL);
+ node = glade_xml_node_new (context, name)
g_hash_table_foreach (hash,
glade_xml_utils_hash_item_write,
@@ -366,15 +453,16 @@ glade_xml_utils_hash_write (XmlParseContext *context, GHashTable *hash, const gc
return node;
}
+#endif
/* --------------------------- Parse Context ----------------------------*/
-XmlParseContext *
-glade_xml_parse_context_new (xmlDocPtr doc,
- xmlNsPtr ns)
+GladeXmlContext *
+glade_xml_context_new (GladeXmlDoc *doc,
+ xmlNsPtr ns)
{
- XmlParseContext *context = g_new0 (XmlParseContext, 1);
-
+ GladeXmlContext *context = g_new0 (GladeXmlContext, 1);
+
context->doc = doc;
context->ns = ns;
@@ -382,19 +470,19 @@ glade_xml_parse_context_new (xmlDocPtr doc,
}
void
-glade_xml_parse_context_destroy (XmlParseContext *context)
+glade_xml_context_destroy (GladeXmlContext *context)
{
g_return_if_fail (context != NULL);
g_free (context);
}
-XmlParseContext *
-glade_xml_parse_context_new_from_path (const gchar *full_path,
+GladeXmlContext *
+glade_xml_context_new_from_path (const gchar *full_path,
const gchar *nspace,
const gchar *root_name)
{
- XmlParseContext *context;
+ GladeXmlContext *context;
xmlDocPtr doc;
xmlNsPtr name_space;
@@ -430,20 +518,127 @@ glade_xml_parse_context_new_from_path (const gchar *full_path,
return FALSE;
}
- context = glade_xml_parse_context_new (doc, name_space);
+ context = glade_xml_context_new ((GladeXmlDoc *)doc, name_space);
return context;
}
-gboolean
-glade_xml_parse_context_free (XmlParseContext *context)
+/**
+ * glade_xml_context_free:
+ * @context:
+ *
+ * Similar to glade_xml_context_destroy but it also frees the document set in the context
+ **/
+void
+glade_xml_context_free (GladeXmlContext *context)
{
- g_return_val_if_fail (context != NULL, FALSE);
+ g_return_if_fail (context != NULL);
+ if (context->doc)
+ xmlFreeDoc ((xmlDocPtr) context->doc);
+ context->doc = NULL;
+
+ g_free (context);
+}
- xmlFreeDoc (context->doc);
- glade_xml_parse_context_destroy (context);
- return TRUE;
+void
+glade_xml_append_child (GladeXmlNode *node_in, GladeXmlNode *child_in)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+ xmlNodePtr child = (xmlNodePtr) child_in;
+
+ g_return_if_fail (node != NULL);
+ g_return_if_fail (child != NULL);
+
+ xmlAddChild (node, child);
+}
+
+GladeXmlNode *
+glade_xml_node_new (GladeXmlContext *context, const gchar *name)
+{
+ g_return_val_if_fail (context != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ return (GladeXmlNode *) xmlNewDocNode ((xmlDocPtr) context->doc, context->ns, name, NULL);
}
+
+GladeXmlNode *
+glade_xml_context_get_root (GladeXmlContext *context)
+{
+ xmlNodePtr node;
+
+ node = ((xmlDocPtr)(context->doc))->children;
+
+ return (GladeXmlNode *)node;
+}
+
+GladeXmlNode *
+glade_xml_node_get_children (GladeXmlNode *node_in)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ return (GladeXmlNode *)node->children;
+}
+
+GladeXmlNode *
+glade_xml_node_next (GladeXmlNode *node_in)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ return (GladeXmlNode *)node->next;
+}
+
+const gchar *
+glade_xml_node_get_name (GladeXmlNode *node_in)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+
+ return node->name;
+}
+
+
+GladeXmlDoc *
+glade_xml_doc_new (void)
+{
+ xmlDocPtr xml_doc = xmlNewDoc ("1.0");
+
+ return (GladeXmlDoc *)xml_doc;
+}
+
+
+void
+glade_xml_doc_set_root (GladeXmlDoc *doc_in, GladeXmlNode *node_in)
+{
+ xmlNodePtr node = (xmlNodePtr) node_in;
+ xmlDocPtr doc = (xmlDocPtr) doc_in;
+
+ xmlDocSetRootElement (doc, node);
+}
+
+gint
+glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path)
+{
+ xmlDocPtr doc = (xmlDocPtr) doc_in;
+
+ return xmlSaveFile (full_path, doc);
+}
+
+void
+glade_xml_doc_free (GladeXmlDoc *doc_in)
+{
+ xmlDocPtr doc = (xmlDocPtr) doc_in;
+
+ xmlFreeDoc (doc);
+}
+
+GladeXmlNode *
+glade_xml_doc_get_root (GladeXmlDoc *doc)
+{
+ xmlNodePtr node;
+
+ node = ((xmlDocPtr)(doc))->children;
+
+ return (GladeXmlNode *)node;
+}
diff --git a/src/glade-xml-utils.h b/src/glade-xml-utils.h
index 9ca33cb7..862ee87c 100644
--- a/src/glade-xml-utils.h
+++ b/src/glade-xml-utils.h
@@ -1,60 +1,108 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* TODO : s/glade_xml_get_/glade_xml_node_get/g */
#ifndef __GLADE_XML_UTILS_H__
#define __GLADE_XML_UTILS_H__
+
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlmemory.h>
+#include "glade-node.h"
G_BEGIN_DECLS
-typedef struct _XmlParseContext XmlParseContext;
+#define GLADE_XML_CONTEXT(c) ((GladeXmlContext *)c)
+#define GLADE_XML_IS_CONTEXT(c) (c != NULL)
+
+typedef struct _GladeXmlContext GladeXmlContext;
+typedef struct _GladeXmlNode GladeXmlNode;
+typedef struct _GladeXmlDoc GladeXmlDoc;
+
+struct _GladeXmlNode
+{
+ xmlNode node;
+};
+struct _GladeXmlDoc
+{
+ xmlDoc doc;
+};
-struct _XmlParseContext {
- xmlDocPtr doc;
+struct _GladeXmlContext {
+ GladeXmlDoc *doc;
xmlNsPtr ns;
};
+/* This is used inside for loops so that we skip xml comments <!-- i am a comment ->
+ * also to skip whitespace bettween nodes
+ */
#define skip_text(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
(strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
- node = ((xmlNodePtr)node)->next; continue ; };
+ node = (GladeXmlNode *)((xmlNodePtr)node)->next; continue ; };
+#define skip_text_libxml(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
+ (strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
+ node = ((xmlNodePtr)node)->next; continue ; };
-gchar * glade_xml_get_content (xmlNodePtr node); /* Get the content of the node */
-gboolean glade_xml_get_value_int (xmlNodePtr node, const char *name, int *val);
-gboolean glade_xml_get_value_int_required (xmlNodePtr node, const char *name, int *val);
+gchar * glade_xml_get_content (GladeXmlNode * node); /* Get the content of the node */
+void glade_xml_set_content (GladeXmlNode *node_in, const gchar *content);
-gchar * glade_xml_get_value_string (xmlNodePtr node, const char *name);
-gchar * glade_xml_get_value_string_required (xmlNodePtr node,
+gboolean glade_xml_get_value_int (GladeXmlNode * node, const char *name, int *val);
+gboolean glade_xml_get_value_int_required (GladeXmlNode * node, const char *name, int *val);
+
+gchar * glade_xml_get_value_string (GladeXmlNode * node, const char *name);
+gchar * glade_xml_get_value_string_required (GladeXmlNode * node,
const char *name,
const char *xtra_info);
-gboolean glade_xml_get_boolean (xmlNodePtr node, const char *name);
+gboolean glade_xml_get_boolean (GladeXmlNode * node, const char *name);
+
+GladeXmlNode * glade_xml_search_child (GladeXmlNode * node, const char *name);
+GladeXmlNode * glade_xml_search_child_required (GladeXmlNode * tree, const gchar* name);
-xmlNodePtr glade_xml_search_child (xmlNodePtr node, const char *name);
-xmlNodePtr glade_xml_search_child_required (xmlNodePtr tree, const gchar* name);
+gboolean glade_xml_node_verify (GladeXmlNode * node, const gchar *name);
-gboolean glade_xml_node_verify (xmlNodePtr node, const gchar *name);
+void glade_xml_set_value (GladeXmlNode * node, const char *name, const char *val);
-void glade_xml_set_value (xmlNodePtr node, const char *name, const char *val);
+/* Properties */
+gchar * glade_xml_get_property_string_required (GladeXmlNode *node_in, const char *name, const char *xtra);
+gchar * glade_xml_get_property_string (GladeXmlNode *node_in, const gchar *name);
+gboolean glade_xml_property_get_boolean (GladeXmlNode *node_in, const char *name);
+void glade_xml_node_set_property_string (GladeXmlNode *node_in, const gchar *name, const gchar *string);
/* Parse Context */
-XmlParseContext * glade_xml_parse_context_new (xmlDocPtr doc, xmlNsPtr name_space);
-void glade_xml_parse_context_destroy (XmlParseContext *context);
+GladeXmlContext * glade_xml_context_new (GladeXmlDoc *doc, xmlNsPtr name_space);
+void glade_xml_context_destroy (GladeXmlContext *context);
+void glade_xml_context_free (GladeXmlContext *context);
+GladeXmlContext * glade_xml_context_new_from_path (const gchar *full_path,
+ const gchar *nspace,
+ const gchar *root_name);
+GladeXmlNode * glade_xml_context_get_root (GladeXmlContext *context);
-gboolean glade_xml_parse_context_free (XmlParseContext *context);
-XmlParseContext * glade_xml_parse_context_new_from_path (const gchar *full_path,
- const gchar *nspace,
- const gchar *root_name);
+void glade_xml_append_child (GladeXmlNode * node, GladeXmlNode * child);
/* Hash */
-GHashTable * glade_xml_utils_new_hash_from_node (xmlNodePtr tree, const gchar *hash_type);
+GHashTable * glade_xml_utils_new_hash_from_node (GladeXmlNode * tree, const gchar *hash_type);
+
+GladeXmlNode * glade_xml_utils_hash_write (GladeXmlContext *context,
+ GHashTable *hash,
+ const gchar *name);
+
+/* Node operations */
+GladeXmlNode * glade_xml_node_new (GladeXmlContext *context, const gchar *name);
+GladeXmlNode * glade_xml_node_get_children (GladeXmlNode *node);
+GladeXmlNode * glade_xml_node_next (GladeXmlNode *node_in);
+
+const gchar * glade_xml_node_get_name (GladeXmlNode *node_in);
-xmlNodePtr glade_xml_utils_hash_write (XmlParseContext *context,
- GHashTable *hash,
- const gchar *name);
+/* Document Operatons */
+GladeXmlNode * glade_xml_doc_get_root (GladeXmlDoc *doc);
+GladeXmlDoc * glade_xml_doc_new (void);
+void glade_xml_doc_set_root (GladeXmlDoc *doc, GladeXmlNode *node);
+gint glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path);
+void glade_xml_doc_free (GladeXmlDoc *doc_in);
G_END_DECLS
diff --git a/src/glade.h b/src/glade.h
index b2459a86..f7c93820 100644
--- a/src/glade.h
+++ b/src/glade.h
@@ -7,6 +7,7 @@ gchar * _ (gchar * name);
#endif
#include "glade-types.h"
+#include "glade-utils.h"
#include "glade-xml-utils.h"
#define GLADE_PATH_SEP_STR "/"
@@ -57,3 +58,13 @@ gchar * _ (gchar * name);
#define GLADE_TAG_GLADE_WIDGET "GladeWidget"
#define GLADE_WIDGET_DATA_TAG "GladeWidgetDataTag"
+
+#define GLADE_XML_TAG_PROJECT "glade-interface"
+#define GLADE_XML_TAG_WIDGET "widget"
+#define GLADE_XML_TAG_PROPERTY "property"
+#define GLADE_XML_TAG_CLASS "class"
+#define GLADE_XML_TAG_ID "id"
+#define GLADE_XML_TAG_SIGNAL "signal"
+#define GLADE_XML_TAG_HANDLER "handler"
+#define GLADE_XML_TAG_NAME "name"
+#define GLADE_XML_TAG_CHILD "child"