[gthumb: 20/57] [webalbums] added support for special codes in header and footer
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 20/57] [webalbums] added support for special codes in header and footer
- Date: Sun, 20 Jun 2010 16:23:26 +0000 (UTC)
commit a7eba6c2ea355875d9e6870c377f6994250d2f45
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Jun 10 19:10:48 2010 +0200
[webalbums] added support for special codes in header and footer
extensions/rename_series/dlg-rename-series.c | 3 -
extensions/webalbums/gth-web-exporter.c | 95 +++++++++++++++-----------
gthumb/glib-utils.c | 3 +
3 files changed, 59 insertions(+), 42 deletions(-)
---
diff --git a/extensions/rename_series/dlg-rename-series.c b/extensions/rename_series/dlg-rename-series.c
index 5faa83e..1df6af7 100644
--- a/extensions/rename_series/dlg-rename-series.c
+++ b/extensions/rename_series/dlg-rename-series.c
@@ -275,9 +275,6 @@ template_eval_cb (const GMatchInfo *info,
a = g_regex_split (re, match, 0);
if (g_strv_length (a) >= 2)
format = g_strstrip (a[1]);
- if ((format == NULL) || (*format == '\0'))
- format = "%Y-%m-%d";
-
r = _g_time_val_strftime (&timeval, format);
g_strfreev (a);
diff --git a/extensions/webalbums/gth-web-exporter.c b/extensions/webalbums/gth-web-exporter.c
index f905195..a1d8c4c 100644
--- a/extensions/webalbums/gth-web-exporter.c
+++ b/extensions/webalbums/gth-web-exporter.c
@@ -850,54 +850,71 @@ get_current_language (void)
/* FIXME: add support for date formats */
-static char *
-get_header_footer_text (const char *utf8_text)
+
+static gboolean
+header_footer_eval_cb (const GMatchInfo *match_info,
+ GString *result,
+ gpointer user_data)
{
- const char *s;
- GString *r;
- char *r_str;
+ GthWebExporter *self = user_data;
+ char *r = NULL;
+ char *match;
- if (utf8_text == NULL)
- return NULL;
+ match = g_match_info_fetch (match_info, 0);
+ if (strcmp (match, "%P") == 0) {
+ r = g_strdup_printf ("%d", self->priv->page + 1);
+ }
+ else if (strcmp (match, "%N") == 0) {
+ r = g_strdup_printf ("%d", self->priv->n_pages);
+ }
+ if (strncmp (match, "%D", 2) == 0) {
+ GTimeVal timeval;
+ GRegex *re;
+ char **a;
+ char *format = NULL;
- if (g_utf8_strchr (utf8_text, -1, '%') == NULL)
- return g_strdup (utf8_text);
+ g_get_current_time (&timeval);
- r = g_string_new (NULL);
- for (s = utf8_text; *s != 0; s = g_utf8_next_char (s)) {
- gunichar ch = g_utf8_get_char (s);
+ /* Get the date format */
- if (ch == '%') {
- s = g_utf8_next_char (s);
+ re = g_regex_new ("%[A-Z]\\{([^}]+)\\}", 0, 0, NULL);
+ a = g_regex_split (re, match, 0);
+ if (g_strv_length (a) >= 2)
+ format = g_strstrip (a[1]);
+ r = _g_time_val_strftime (&timeval, format);
- if (*s == 0) {
- g_string_append_unichar (r, ch);
- break;
- }
+ g_strfreev (a);
+ g_regex_unref (re);
+ }
- ch = g_utf8_get_char (s);
- switch (ch) {
- char *t;
+ if (r != NULL)
+ g_string_append (result, r);
- case '%':
- g_string_append (r, "%");
- break;
+ g_free (r);
+ g_free (match);
- case 'd':
- t = get_current_date ();
- g_string_append (r, t);
- g_free (t);
- break;
- }
- }
- else
- g_string_append_unichar (r, ch);
- }
+ return FALSE;
+}
+
+
+static char *
+get_header_footer_text (GthWebExporter *self,
+ const char *utf8_text)
+{
+ GRegex *re;
+ char *new_text;
+
+ if (utf8_text == NULL)
+ return NULL;
+
+ if (g_utf8_strchr (utf8_text, -1, '%') == NULL)
+ return g_strdup (utf8_text);
- r_str = r->str;
- g_string_free (r, FALSE);
+ re = g_regex_new ("%[PND](\\{[^}]+\\})?", 0, 0, NULL);
+ new_text = g_regex_replace_eval (re, utf8_text, -1, 0, 0, header_footer_eval_cb, self, NULL);
+ g_regex_unref (re);
- return r_str;
+ return new_text;
}
@@ -955,12 +972,12 @@ gth_parsed_doc_print (GList *document,
switch (tag->type) {
case GTH_TAG_HEADER:
- line = get_header_footer_text (self->priv->header);
+ line = get_header_footer_text (self, self->priv->header);
write_markup_escape_line (ostream, line, error);
break;
case GTH_TAG_FOOTER:
- line = get_header_footer_text (self->priv->footer);
+ line = get_header_footer_text (self, self->priv->footer);
write_markup_escape_line (ostream, line, error);
break;
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index 9c20f2f..eb5c88a 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -534,6 +534,9 @@ _g_time_val_strftime (GTimeVal *time_,
time_t secs;
struct tm *tm;
+ if ((format == NULL) || (*format == '\0'))
+ format = "%Y-%m-%d";
+
secs = time_->tv_sec;
tm = localtime (&secs);
return struct_tm_strftime (tm, format);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]