summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <jpu@src.gnome.org>2006-09-19 23:26:00 +0000
committerJuan Pablo Ugarte <jpu@src.gnome.org>2006-09-19 23:26:00 +0000
commit78602aad6e74bd0be1100aa7af6ce26d1f83a6fc (patch)
tree468132eb17b95cb8e4c5eb11438fcd14915a9f6b
parent68f51c5bfdeaacaa71793d78a86c40c3e644ab0a (diff)
downloadglade-78602aad6e74bd0be1100aa7af6ce26d1f83a6fc.tar.gz
o Removed function glade_interface_add_comment() o Added new member
* src/glade-parser.[ch]: o Removed function glade_interface_add_comment() o Added new member comment to GladeInterface. * src/glade-project.[ch]: fixed Bug 342889 "Put some comment telling about glade-3 in glade files" o Added new function glade_project_update_comment(). o Added new member comment to GladeProject.
-rw-r--r--ChangeLog11
-rw-r--r--src/glade-parser.c43
-rw-r--r--src/glade-parser.h2
-rw-r--r--src/glade-project.c45
-rw-r--r--src/glade-project.h4
5 files changed, 78 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 02cdef7d..3cf75443 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-09-19 Juan Pablo Ugarte <juanpablougarte@gmail.com>
+
+ * src/glade-parser.[ch]:
+ o Removed function glade_interface_add_comment()
+ o Added new member comment to GladeInterface.
+
+ * src/glade-project.[ch]: fixed Bug 342889
+ "Put some comment telling about glade-3 in glade files"
+ o Added new function glade_project_update_comment().
+ o Added new member comment to GladeProject.
+
2006-09-18 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* src/glade-property-class.[ch]:
diff --git a/src/glade-parser.c b/src/glade-parser.c
index 25cd60a1..6a9fa038 100644
--- a/src/glade-parser.c
+++ b/src/glade-parser.c
@@ -459,6 +459,13 @@ glade_parser_end_document(GladeParseState *state)
}
static void
+glade_parser_comment (GladeParseState *state, const xmlChar *comment)
+{
+ if (state->state == PARSER_START)
+ state->interface->comment = g_strdup (CAST_BAD (comment));
+}
+
+static void
glade_parser_start_element(GladeParseState *state,
const xmlChar *name, const xmlChar **attrs)
{
@@ -1083,7 +1090,7 @@ static xmlSAXHandler glade_parser = {
(charactersSAXFunc)glade_parser_characters, /* characters */
0, /* ignorableWhitespace */
0, /* processingInstruction */
- (commentSAXFunc)0, /* comment */
+ (commentSAXFunc)glade_parser_comment, /* comment */
(warningSAXFunc)glade_parser_warning, /* warning */
(errorSAXFunc)glade_parser_error, /* error */
(fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
@@ -1153,6 +1160,8 @@ glade_interface_destroy(GladeInterface *interface)
* of the strings. */
g_hash_table_destroy(interface->strings);
+ g_free (interface->comment);
+
g_free(interface);
}
@@ -1545,35 +1554,11 @@ dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
xmlNodeAddContent(widget, BAD_CAST(" "));
}
-static void
-glade_interface_add_comment (xmlDoc *doc)
-{
- time_t now = time (NULL);
- xmlNode *comment;
- gchar *str;
-
- str = g_strdup_printf (_(" Generated with %s\n"
- "\tVersion: %s\n"
- "\tDate: %s"
- "\tUser: %s\n"
- "\tHost: %s\n"),
- PACKAGE_NAME,
- PACKAGE_VERSION,
- ctime (&now),
- g_get_user_name (),
- g_get_host_name ());
-
- comment = xmlNewComment(BAD_CAST (str));
- xmlDocSetRootElement(doc, comment);
-
- g_free (str);
-}
-
static xmlDoc *
glade_interface_make_doc (GladeInterface *interface)
{
xmlDoc *doc;
- xmlNode *root;
+ xmlNode *root, *comment;
gint i;
doc = xmlNewDoc(BAD_CAST("1.0"));
@@ -1581,7 +1566,11 @@ glade_interface_make_doc (GladeInterface *interface)
xmlCreateIntSubset(doc, BAD_CAST("glade-interface"),
NULL, BAD_CAST("glade-2.0.dtd"));
- glade_interface_add_comment (doc);
+ if (interface->comment)
+ {
+ comment = xmlNewComment(BAD_CAST (interface->comment));
+ xmlDocSetRootElement(doc, comment);
+ }
root = xmlNewNode(NULL, BAD_CAST("glade-interface"));
xmlDocSetRootElement(doc, root);
diff --git a/src/glade-parser.h b/src/glade-parser.h
index 264db21c..75eee2ff 100644
--- a/src/glade-parser.h
+++ b/src/glade-parser.h
@@ -124,6 +124,8 @@ struct _GladeInterface {
GHashTable *names;
GHashTable *strings;
+
+ gchar *comment;
};
/* the actual functions ... */
diff --git a/src/glade-project.c b/src/glade-project.c
index d51dc428..f3884959 100644
--- a/src/glade-project.c
+++ b/src/glade-project.c
@@ -145,6 +145,7 @@ glade_project_finalize (GObject *object)
g_free (project->name);
g_free (project->path);
+ g_free (project->comment);
if (project->untitled_number > 0)
glade_project_release_untitled_number (project->untitled_number);
@@ -1325,6 +1326,43 @@ glade_project_required_libs (GladeProject *project)
return required;
}
+static void
+glade_project_update_comment (GladeProject *project)
+{
+ time_t now = time (NULL);
+ GString *comment = g_string_new ("");
+ gchar *tmp, *tail;
+
+ g_string_printf (comment, _("Generated with %s %s on %sby %s@%s"),
+ PACKAGE_NAME, PACKAGE_VERSION, ctime (&now),
+ g_get_user_name (), g_get_host_name ());
+ glade_util_replace (comment->str, '\n', ' ');
+
+ /* If project has no comment -> add the new one */
+ if (project->comment == NULL)
+ {
+ project->comment = comment->str;
+ g_string_free (comment, FALSE);
+ return;
+ }
+
+ /* Compare the start of the first line */
+ tmp = strstr (comment->str, PACKAGE_VERSION);
+ if (tmp && strncmp (project->comment, comment->str, tmp - comment->str) == 0)
+ {
+ /* The first line was generated by glade -> updating... */
+ tail = strchr (project->comment, '\n');
+ if (tail && strlen (tail)) g_string_append (comment, tail);
+
+ g_free (project->comment);
+ project->comment = comment->str;
+ g_string_free (comment, FALSE);
+ }
+ else
+ /* Commnet not generated by glade -> wont update */
+ g_string_free (comment, TRUE);
+}
+
/**
* glade_project_write:
* @project: a #GladeProject
@@ -1382,6 +1420,9 @@ glade_project_write (GladeProject *project)
g_list_free (tops);
+ glade_project_update_comment (project);
+ interface->comment = g_strdup (project->comment);
+
return interface;
}
@@ -1435,6 +1476,10 @@ glade_project_new_from_interface (GladeInterface *interface, const gchar *path)
project->objects = NULL;
project->loading = TRUE;
+ /* keep a comment */
+ if (interface->comment)
+ project->comment = g_strdup (interface->comment);
+
for (i = 0; i < interface->n_toplevels; ++i)
{
widget = glade_widget_read ((gpointer)project, interface->toplevels[i]);
diff --git a/src/glade-project.h b/src/glade-project.h
index be817504..17cfa902 100644
--- a/src/glade-project.h
+++ b/src/glade-project.h
@@ -63,6 +63,10 @@ struct _GladeProject
GtkAccelGroup *accel_group;
GHashTable *resources; /* resource filenames & thier associated properties */
+
+ gchar *comment; /* XML comment, Glade will preserve whatever comment was
+ * in file, so users can delete or change it.
+ */
};
struct _GladeProjectClass