summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <jpu@src.gnome.org>2006-09-20 19:18:29 +0000
committerJuan Pablo Ugarte <jpu@src.gnome.org>2006-09-20 19:18:29 +0000
commit034ed1e44486cbf3b6827bad22fb77d92ffd444d (patch)
tree6f3189260cfc609722ee09674606897bd737bff5
parent78602aad6e74bd0be1100aa7af6ce26d1f83a6fc (diff)
downloadglade-034ed1e44486cbf3b6827bad22fb77d92ffd444d.tar.gz
src/glade-project.c reworked glade_project_update_comment() update every
* src/glade-project.c reworked glade_project_update_comment() update every line generated by glade (not just the first one)
-rw-r--r--ChangeLog5
-rw-r--r--src/glade-project.c55
2 files changed, 39 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 3cf75443..38196827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-20 Juan Pablo Ugarte <juanpablougarte@gmail.com>
+
+ * src/glade-project.c reworked glade_project_update_comment()
+ update every line generated by glade (not just the first one)
+
2006-09-19 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* src/glade-parser.[ch]:
diff --git a/src/glade-project.c b/src/glade-project.c
index f3884959..59148dc2 100644
--- a/src/glade-project.c
+++ b/src/glade-project.c
@@ -1326,41 +1326,54 @@ glade_project_required_libs (GladeProject *project)
return required;
}
-static void
-glade_project_update_comment (GladeProject *project)
+#define GLADE_XML_COMMENT "Generated with "PACKAGE_NAME
+
+static gchar *
+glade_project_make_comment ()
{
time_t now = time (NULL);
- GString *comment = g_string_new ("");
- gchar *tmp, *tail;
+ gchar *comment;
+ comment = g_strdup_printf (GLADE_XML_COMMENT" "PACKAGE_VERSION" on %sby %s@%s",
+ ctime (&now), g_get_user_name (), g_get_host_name ());
+ glade_util_replace (comment, '\n', ' ');
- 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', ' ');
+ return comment;
+}
+static void
+glade_project_update_comment (GladeProject *project)
+{
+ gchar **lines, **l, *comment = NULL;
+
/* If project has no comment -> add the new one */
if (project->comment == NULL)
{
- project->comment = comment->str;
- g_string_free (comment, FALSE);
+ project->comment = glade_project_make_comment ();
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)
+ for (lines = l = g_strsplit (project->comment, "\n", 0); *l; l++)
{
- /* The first line was generated by glade -> updating... */
- tail = strchr (project->comment, '\n');
- if (tail && strlen (tail)) g_string_append (comment, tail);
+ gchar *start;
+ /* Ignore leading spaces */
+ for (start = *l; *start && g_ascii_isspace (*start); start++);
+
+ if (g_str_has_prefix (start, GLADE_XML_COMMENT))
+ {
+ /* This line was generated by glade -> updating... */
+ g_free (*l);
+ *l = comment = glade_project_make_comment ();
+ }
+ }
+
+ if (comment)
+ {
g_free (project->comment);
- project->comment = comment->str;
- g_string_free (comment, FALSE);
+ project->comment = g_strjoinv ("\n", lines);
}
- else
- /* Commnet not generated by glade -> wont update */
- g_string_free (comment, TRUE);
+
+ g_strfreev (lines);
}
/**