[gthumb: 50/57] [webalbums] made the theme syntax more poweful
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 50/57] [webalbums] made the theme syntax more poweful
- Date: Sun, 20 Jun 2010 16:25:57 +0000 (UTC)
commit 8a925be2b2cb11fbcc1397e9d2c2331781611e7f
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Jun 20 10:58:09 2010 +0200
[webalbums] made the theme syntax more poweful
Added for_each in range loop; Added ability to specify a printf like list of arguments to the translate function; Added ability the create squared thumbnails.
extensions/webalbums/albumtheme-private.c | 55 +++++
extensions/webalbums/albumtheme-private.h | 22 ++
extensions/webalbums/albumtheme.l | 41 ++--
extensions/webalbums/albumtheme.y | 133 +++++++++---
.../data/albumthemes/Classic/image.gthtml | 2 +-
.../data/albumthemes/Classic/thumbnail.gthtml | 2 +-
.../data/albumthemes/ClassicClips/image.gthtml | 2 +-
.../data/albumthemes/ClassicClips/thumbnail.gthtml | 2 +-
.../data/albumthemes/NeatRound/image.gthtml | 2 +-
.../data/albumthemes/NeatRound/thumbnail.gthtml | 3 +-
extensions/webalbums/data/ui/web-album-exporter.ui | 5 +-
extensions/webalbums/gth-web-exporter.c | 221 ++++++++++++++++++-
extensions/webalbums/gth-web-exporter.h | 1 +
13 files changed, 421 insertions(+), 70 deletions(-)
---
diff --git a/extensions/webalbums/albumtheme-private.c b/extensions/webalbums/albumtheme-private.c
index 7e15058..aa8b0e7 100644
--- a/extensions/webalbums/albumtheme-private.c
+++ b/extensions/webalbums/albumtheme-private.c
@@ -533,6 +533,17 @@ gth_expr_eval (GthExpr *e)
}
+void
+gth_expr_list_unref (GList *list)
+{
+ GList *scan;
+
+ for (scan = list; scan; scan = scan->next)
+ gth_expr_unref ((GthExpr *) scan->data);
+ g_list_free (list);
+}
+
+
/* GthAttribute */
@@ -665,6 +676,43 @@ gth_loop_add_document (GthLoop *loop,
}
+/* GthRangeLoop */
+
+
+GthLoop *
+gth_range_loop_new (void)
+{
+ GthLoop *loop;
+
+ loop = (GthLoop *) g_new0 (GthRangeLoop, 1);
+ loop->type = GTH_TAG_FOR_EACH_IN_RANGE;
+
+ return loop;
+}
+
+
+void
+gth_range_loop_free (GthRangeLoop *loop)
+{
+ g_free (loop->iterator);
+ gth_expr_unref (loop->first_value);
+ gth_expr_unref (loop->last_value);
+ gth_loop_free (GTH_LOOP (loop));
+}
+
+
+void
+gth_range_loop_set_range (GthRangeLoop *loop,
+ const char *iterator,
+ GthExpr *first_value,
+ GthExpr *last_value)
+{
+ loop->iterator = g_strdup (iterator);
+ loop->first_value = gth_expr_ref (first_value);
+ loop->last_value = gth_expr_ref (last_value);
+}
+
+
/* GthTag */
@@ -748,6 +796,9 @@ gth_tag_free (GthTag *tag)
{
gth_loop_free (tag->value.loop);
}
+ else if (tag->type == GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION) {
+ gth_range_loop_free (GTH_RANGE_LOOP (tag->value.loop));
+ }
else {
g_list_foreach (tag->value.attributes,
(GFunc) gth_attribute_free,
@@ -824,6 +875,8 @@ gth_tag_get_type_from_name (const char *tag_name)
return GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION;
else if (g_str_equal (tag_name, "for_each_image_caption"))
return GTH_TAG_FOR_EACH_IMAGE_CAPTION;
+ else if (g_str_equal (tag_name, "for_each_in_range"))
+ return GTH_TAG_FOR_EACH_IN_RANGE;
else if (g_str_equal (tag_name, "item_attribute"))
return GTH_TAG_ITEM_ATTRIBUTE;
@@ -860,6 +913,8 @@ gth_tag_get_name_from_type (GthTagType tag_type)
"eval",
"if",
"for_each_thumbnail_caption",
+ "for_each_image_caption",
+ "for_each_in_range",
"item_attribute"
};
diff --git a/extensions/webalbums/albumtheme-private.h b/extensions/webalbums/albumtheme-private.h
index 55e0a91..fb851c1 100644
--- a/extensions/webalbums/albumtheme-private.h
+++ b/extensions/webalbums/albumtheme-private.h
@@ -132,6 +132,7 @@ void gth_expr_set_get_var_value_func (GthExpr *e,
gpointer data);
void gth_expr_print (GthExpr *e);
int gth_expr_eval (GthExpr *e);
+void gth_expr_list_unref (GList *list);
/* GthAttribute */
@@ -197,6 +198,7 @@ typedef enum {
GTH_TAG_IF,
GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION,
GTH_TAG_FOR_EACH_IMAGE_CAPTION,
+ GTH_TAG_FOR_EACH_IN_RANGE,
GTH_TAG_ITEM_ATTRIBUTE,
GTH_TAG_INVALID
} GthTagType;
@@ -206,12 +208,32 @@ typedef struct {
GList *document; /* GthTag list */
} GthLoop;
+#define GTH_LOOP(x) ((GthLoop *)(x))
+
GthLoop * gth_loop_new (GthTagType loop_type);
void gth_loop_free (GthLoop *loop);
GthTagType gth_loop_get_type (GthLoop *loop);
void gth_loop_add_document (GthLoop *loop,
GList *document);
+/* GthRangeLopp */
+
+typedef struct {
+ GthLoop parent;
+ char *iterator;
+ GthExpr *first_value;
+ GthExpr *last_value;
+} GthRangeLoop;
+
+#define GTH_RANGE_LOOP(x) ((GthRangeLoop *)(x))
+
+GthLoop * gth_range_loop_new (void);
+void gth_range_loop_free (GthRangeLoop *loop);
+void gth_range_loop_set_range (GthRangeLoop *loop,
+ const char *iterator,
+ GthExpr *first_value,
+ GthExpr *last_value);
+
/* GthTag */
typedef struct {
diff --git a/extensions/webalbums/albumtheme.l b/extensions/webalbums/albumtheme.l
index 128b9f4..9de414a 100644
--- a/extensions/webalbums/albumtheme.l
+++ b/extensions/webalbums/albumtheme.l
@@ -66,22 +66,20 @@ string [^']*
BEGIN (ATTRIBUTES);
return SET_VAR;
}
-"<% for_each_thumbnail_caption" {
- BEGIN (ATTRIBUTES);
- yylval.ivalue = GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION;
+"<% for_each" {
+ BEGIN (CONDITION);
+ yylval.ivalue = GTH_TAG_FOR_EACH_IN_RANGE;
return FOR_EACH;
}
-"<% for_each_image_caption" {
- BEGIN (ATTRIBUTES);
- yylval.ivalue = GTH_TAG_FOR_EACH_IMAGE_CAPTION;
- return FOR_EACH;
- }
"<%=" {
BEGIN (FUNCTION);
return PRINT;
}
<FUNCTION>{attribute_name} {
- BEGIN (ATTRIBUTES);
+ if (g_str_equal (yytext, "eval") || g_str_equal (yytext, "translate"))
+ BEGIN (CONDITION);
+ else
+ BEGIN (ATTRIBUTES);
yylval.text = g_strdup (yytext);
return FUNCTION_NAME;
}
@@ -117,14 +115,6 @@ string [^']*
<ATTRIBUTES>"=" {
return '=';
}
-<QUOTE,CONDITION>{number} {
- yylval.ivalue = atoi (yytext);
- return NUMBER;
- }
-<QUOTE,CONDITION>{name} {
- yylval.text = g_strdup (yytext);
- return VARIABLE;
- }
<QUOTE,CONDITION>"=" {
return '=';
}
@@ -157,6 +147,9 @@ string [^']*
<QUOTE,CONDITION>")" {
return ')';
}
+<QUOTE,CONDITION>"," {
+ return ',';
+ }
<QUOTE,CONDITION>"&&" {
yylval.ivalue = GTH_OP_AND;
return BOOL_OP;
@@ -181,6 +174,20 @@ string [^']*
yylval.ivalue = GTH_OP_CMP_GE;
return COMPARE;
}
+<QUOTE,CONDITION>".." {
+ return RANGE;
+ }
+<QUOTE,CONDITION>"in" {
+ return IN;
+ }
+<QUOTE,CONDITION>{number} {
+ yylval.ivalue = atoi (yytext);
+ return NUMBER;
+ }
+<QUOTE,CONDITION>{name} {
+ yylval.text = g_strdup (yytext);
+ return VARIABLE;
+ }
<ATTRIBUTES,QUOTE,CONDITION>[ \t\n] {
/* Eat spaces inside tag. */
}
diff --git a/extensions/webalbums/albumtheme.y b/extensions/webalbums/albumtheme.y
index f790bda..069189b 100644
--- a/extensions/webalbums/albumtheme.y
+++ b/extensions/webalbums/albumtheme.y
@@ -53,20 +53,22 @@ int gth_albumtheme_yywrap (void);
%token <ivalue> SET_VAR
%token <text> HTML
-%type <list> document
-%type <tag> tag_command
-%type <tag> tag_print
-%type <loop> tag_loop
-%type <cond> tag_if
-%type <cond> tag_else_if
-%type <cond> opt_tag_else
-%type <list> opt_tag_else_if
-%type <list> attribute_list
-%type <attribute> attribute
-%type <expr> expr
+%type <list> document
+%type <tag> tag_command
+%type <tag> tag_print
+%type <loop> tag_loop
+%type <cond> tag_if
+%type <cond> tag_else_if
+%type <cond> opt_tag_else
+%type <list> opt_tag_else_if
+%type <list> attribute_list
+%type <attribute> attribute
+%type <list> expr_list
+%type <expr> expr
%left <ivalue> BOOL_OP
%left <ivalue> COMPARE
+%left RANGE IN
%left '+' '-' '*' '/' '!' ','
%right UNARY_OP
@@ -126,13 +128,33 @@ document : HTML document {
}
;
-tag_loop : FOR_EACH END_TAG {
- $$ = gth_loop_new ($1);
- };
+tag_loop : FOR_EACH VARIABLE END_TAG {
+ if (g_str_equal ($2, "thumbnail_caption")) {
+ $$ = gth_loop_new (GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION);
+ }
+ else if (g_str_equal ($2, "image_caption")) {
+ $$ = gth_loop_new (GTH_TAG_FOR_EACH_IMAGE_CAPTION);
+ }
+ else {
+ yyerror ("Wrong iterator: '%s', expected 'thumbnail_caption' or 'image_caption'", $2);
+ YYERROR;
+ }
+ }
+
+ | FOR_EACH VARIABLE IN expr RANGE expr END_TAG {
+ $$ = gth_range_loop_new ();
+ gth_range_loop_set_range (GTH_RANGE_LOOP ($$), $2, $4, $6);
+
+ g_free ($2);
+ gth_expr_unref ($4);
+ gth_expr_unref ($6);
+ }
+ ;
tag_if : IF expr END_TAG {
$$ = gth_condition_new ($2);
}
+
| IF '"' expr '"' END_TAG {
$$ = gth_condition_new ($3);
}
@@ -151,6 +173,7 @@ opt_tag_else_if : tag_else_if document opt_tag_else_if {
tag_else_if : ELSE_IF expr END_TAG {
$$ = gth_condition_new ($2);
}
+
| ELSE_IF '"' expr '"' END_TAG {
$$ = gth_condition_new ($3);
}
@@ -182,16 +205,52 @@ tag_end : END END_TAG
tag_command : SET_VAR attribute_list END_TAG {
$$ = gth_tag_new (GTH_TAG_SET_VAR, $2);
}
+ ;
-tag_print : PRINT FUNCTION_NAME '\'' QUOTED_STRING '\'' END_TAG {
- if (gth_tag_get_type_from_name ($2) == GTH_TAG_TRANSLATE) {
- GList *arg_list;
-
- arg_list = g_list_append (NULL, gth_attribute_new_string ("text", $4));
+tag_print : PRINT FUNCTION_NAME expr_list END_TAG {
+ if (gth_tag_get_type_from_name ($2) == GTH_TAG_EVAL) {
+ GthExpr *e;
+ GList *arg_list;
+
+ if ($3 == NULL) {
+ yyerror ("Missing argument for function 'eval', expected expression");
+ YYERROR;
+ }
+
+ e = $3->data;
+ arg_list = g_list_append (NULL, gth_attribute_new_expression ("expr", e));
+ $$ = gth_tag_new (GTH_TAG_EVAL, arg_list);
+
+ gth_expr_list_unref ($3);
+ }
+ else if (gth_tag_get_type_from_name ($2) == GTH_TAG_TRANSLATE) {
+ GList *arg_list = NULL;
+ GList *scan;
+
+ for (scan = $3; scan; scan = scan->next) {
+ GthExpr *e = scan->data;
+
+ if (scan == $3) {
+ GthCell *cell;
+
+ cell = gth_expr_get (e);
+ if (cell->type != GTH_CELL_TYPE_STRING) {
+ yyerror ("Wrong argument type: %d, expected string", cell->type);
+ YYERROR;
+ }
+ arg_list = g_list_append (arg_list, gth_attribute_new_string ("text", cell->value.string->str));
+
+ continue;
+ }
+
+ arg_list = g_list_append (arg_list, gth_attribute_new_expression ("expr", e));
+ }
$$ = gth_tag_new (GTH_TAG_TRANSLATE, arg_list);
+
+ gth_expr_list_unref ($3);
}
else {
- yyerror ("Wrong function: '%s', expected 'translate'", $2);
+ yyerror ("Wrong function: '%s', expected 'eval' or 'translate'", $2);
YYERROR;
}
}
@@ -234,6 +293,19 @@ attribute : ATTRIBUTE_NAME '=' '"' expr '"' {
}
;
+expr_list : expr ',' expr_list {
+ $$ = g_list_prepend ($3, $1);
+ }
+
+ | expr {
+ $$ = g_list_prepend (NULL, $1);
+ }
+
+ | /* empty */ {
+ $$ = NULL;
+ }
+ ;
+
expr : '(' expr ')' {
$$ = $2;
}
@@ -330,21 +402,18 @@ expr : '(' expr ')' {
$$ = $2;
}
- | expr ',' expr {
- GthExpr *e = gth_expr_new ();
- gth_expr_push_expr (e, $1);
- gth_expr_push_expr (e, $3);
- gth_expr_unref ($1);
- gth_expr_unref ($3);
- $$ = e;
- }
-
- | VARIABLE '(' expr ')' %prec UNARY_OP { /* function call */
+ | VARIABLE '(' expr_list ')' %prec UNARY_OP { /* function call */
GthExpr *e = gth_expr_new ();
gth_expr_push_var (e, $1);
if ($3 != NULL) {
- gth_expr_push_expr (e, $3);
- gth_expr_unref ($3);
+ GList *scan;
+
+ for (scan = $3; scan; scan = scan->next) {
+ GthExpr *arg = scan->data;
+ gth_expr_push_expr (e, arg);
+ gth_expr_unref (arg);
+ }
+ g_list_free ($3);
}
g_free ($1);
$$ = e;
diff --git a/extensions/webalbums/data/albumthemes/Classic/image.gthtml b/extensions/webalbums/data/albumthemes/Classic/image.gthtml
index 3bf5bfc..b919b08 100644
--- a/extensions/webalbums/data/albumthemes/Classic/image.gthtml
+++ b/extensions/webalbums/data/albumthemes/Classic/image.gthtml
@@ -66,7 +66,7 @@
<% end %>
</div>
- <% for_each_image_caption %>
+ <% for_each image_caption %>
<% if first_item %>
<dl class="caption-container">
<% end %>
diff --git a/extensions/webalbums/data/albumthemes/Classic/thumbnail.gthtml b/extensions/webalbums/data/albumthemes/Classic/thumbnail.gthtml
index ca52fab..036be64 100644
--- a/extensions/webalbums/data/albumthemes/Classic/thumbnail.gthtml
+++ b/extensions/webalbums/data/albumthemes/Classic/thumbnail.gthtml
@@ -16,7 +16,7 @@
</div>
</div>
- <% for_each_thumbnail_caption %>
+ <% for_each thumbnail_caption %>
<% if first_item %>
<div class="caption-container">
<% end %>
diff --git a/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml b/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
index b8b55de..a9f9e37 100644
--- a/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
+++ b/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
@@ -66,7 +66,7 @@
<% end %>
</div>
- <% for_each_image_caption %>
+ <% for_each image_caption %>
<% if first_item %>
<dl class="caption-container">
<% end %>
diff --git a/extensions/webalbums/data/albumthemes/ClassicClips/thumbnail.gthtml b/extensions/webalbums/data/albumthemes/ClassicClips/thumbnail.gthtml
index ca52fab..036be64 100644
--- a/extensions/webalbums/data/albumthemes/ClassicClips/thumbnail.gthtml
+++ b/extensions/webalbums/data/albumthemes/ClassicClips/thumbnail.gthtml
@@ -16,7 +16,7 @@
</div>
</div>
- <% for_each_thumbnail_caption %>
+ <% for_each thumbnail_caption %>
<% if first_item %>
<div class="caption-container">
<% end %>
diff --git a/extensions/webalbums/data/albumthemes/NeatRound/image.gthtml b/extensions/webalbums/data/albumthemes/NeatRound/image.gthtml
index 6559262..ef19859 100644
--- a/extensions/webalbums/data/albumthemes/NeatRound/image.gthtml
+++ b/extensions/webalbums/data/albumthemes/NeatRound/image.gthtml
@@ -66,7 +66,7 @@
<% end %>
</div>
- <% for_each_image_caption %>
+ <% for_each image_caption %>
<% if first_item %>
<dl class="caption-container">
<% end %>
diff --git a/extensions/webalbums/data/albumthemes/NeatRound/thumbnail.gthtml b/extensions/webalbums/data/albumthemes/NeatRound/thumbnail.gthtml
index 7c59d8c..e1b48de 100644
--- a/extensions/webalbums/data/albumthemes/NeatRound/thumbnail.gthtml
+++ b/extensions/webalbums/data/albumthemes/NeatRound/thumbnail.gthtml
@@ -16,7 +16,7 @@
</div>
</div> <!-- thumbnail-container -->
- <% for_each_thumbnail_caption %>
+ <% for_each thumbnail_caption %>
<% if first_item %>
<div class="caption-container">
<% end %>
@@ -30,5 +30,4 @@
<% end %>
<% end %>
- <div style="clear: both"></div>
</div> <!-- thumbnail-caption-container -->
diff --git a/extensions/webalbums/data/ui/web-album-exporter.ui b/extensions/webalbums/data/ui/web-album-exporter.ui
index e744c50..fb2c18a 100644
--- a/extensions/webalbums/data/ui/web-album-exporter.ui
+++ b/extensions/webalbums/data/ui/web-album-exporter.ui
@@ -300,8 +300,8 @@
<child>
<object class="GtkFileChooserButton" id="destination_filechooserbutton">
<property name="visible">True</property>
- <property name="local_only">False</property>
<property name="action">select-folder</property>
+ <property name="local_only">False</property>
<property name="title" translatable="yes">Choose destination folder</property>
</object>
<packing>
@@ -426,7 +426,8 @@
<property name="left_padding">12</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow4">
- <property name="height_request">145</property>
+ <property name="width_request">453</property>
+ <property name="height_request">272</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
diff --git a/extensions/webalbums/gth-web-exporter.c b/extensions/webalbums/gth-web-exporter.c
index e9828eb..e9960ee 100644
--- a/extensions/webalbums/gth-web-exporter.c
+++ b/extensions/webalbums/gth-web-exporter.c
@@ -113,6 +113,8 @@ typedef struct {
int item_index;
GthFileData *item;
char *attribute;
+ char *iterator;
+ int iterator_value;
} LoopInfo;
@@ -142,6 +144,7 @@ struct _GthWebExporterPrivate {
int columns_per_page;
int rows_per_page;
gboolean adapt_to_width;
+ gboolean squared_thumbnails;
int thumb_width;
int thumb_height;
int preview_max_width;
@@ -184,6 +187,7 @@ loop_info_new (void)
info->last_item = FALSE;
info->item = NULL;
info->attribute = NULL;
+ info->iterator = NULL;
return info;
}
@@ -205,6 +209,7 @@ loop_info_unref (LoopInfo *info)
return;
_g_object_unref (info->item);
g_free (info->attribute);
+ g_free (info->iterator);
g_free (info);
}
@@ -399,6 +404,7 @@ get_var_value (GthExpr *expr,
attribute_id = cell->value.string->str;
result = _g_file_attributes_matches_any (attribute_id, self->priv->image_attributes);
+ *index += 1;
return result;
}
@@ -406,6 +412,9 @@ get_var_value (GthExpr *expr,
return 0;
}
+ else if ((self->priv->loop_info != NULL) && g_str_equal (var_name, self->priv->loop_info->iterator))
+ return self->priv->loop_info->iterator_value;
+
g_warning ("[GetVarValue] Unknown variable name: %s", var_name);
return 0;
@@ -434,6 +443,7 @@ gth_tag_get_idx (GthTag *tag,
|| (tag->type == GTH_TAG_IF)
|| (tag->type == GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION)
|| (tag->type == GTH_TAG_FOR_EACH_IMAGE_CAPTION)
+ || (tag->type == GTH_TAG_FOR_EACH_IN_RANGE)
|| (tag->type == GTH_TAG_INVALID))
{
return 0;
@@ -538,6 +548,91 @@ gth_tag_get_attribute_string (GthWebExporter *self,
}
+/* -- gth_tag_translate_get_string -- */
+
+
+typedef struct {
+ GthWebExporter *self;
+ GthTag *tag;
+ GList *attribute_p;
+ GError **error;
+} TranslateData;
+
+
+static gboolean
+translate_eval_cb (const GMatchInfo *info,
+ GString *res,
+ gpointer data)
+{
+ TranslateData *translate_data = data;
+ GthAttribute *attribute;
+ char *match;
+
+ if (translate_data->attribute_p == NULL) {
+ *translate_data->error = g_error_new_literal (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, _("Malformed command"));
+ return TRUE;
+ }
+
+ attribute = translate_data->attribute_p->data;
+ match = g_match_info_fetch (info, 0);
+ if (strcmp (match, "%s") == 0) {
+ if (attribute->type == GTH_ATTRIBUTE_STRING) {
+ g_string_append (res, attribute->value.string);
+ translate_data->attribute_p = translate_data->attribute_p->next;
+ }
+ else
+ *translate_data->error = g_error_new_literal (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, _("Malformed command"));
+ }
+ else if (strcmp (match, "%d") == 0) {
+ if (attribute->type == GTH_ATTRIBUTE_EXPR) {
+ g_string_append_printf (res, "%d", expression_value (translate_data->self, attribute->value.expr));
+ translate_data->attribute_p = translate_data->attribute_p->next;
+ }
+ else
+ *translate_data->error = g_error_new_literal (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, _("Malformed command"));
+ }
+
+ g_free (match);
+
+ return (*translate_data->error != NULL);
+}
+
+
+static char *
+gth_tag_translate_get_string (GthWebExporter *self,
+ GthTag *tag)
+{
+ TranslateData *translate_data;
+ GRegex *re;
+ GError *error = NULL;
+ char *result;
+
+ if (tag->value.attributes == NULL)
+ return NULL;
+
+ if (tag->value.attributes->next == NULL)
+ return g_strdup (_(gth_tag_get_attribute_string (self, tag, "text")));
+
+ translate_data = g_new0 (TranslateData, 1);
+ translate_data->self = self;
+ translate_data->tag = tag;
+ translate_data->attribute_p = tag->value.attributes->next;
+ translate_data->error = &error;
+
+ re = g_regex_new ("%d|%s", 0, 0, NULL);
+ result = g_regex_replace_eval (re, _(gth_tag_get_attribute_string (self, tag, "text")), -1, 0, 0, translate_eval_cb, translate_data, &error);
+ if (error != NULL) {
+ result = g_strdup (error->message);
+ g_clear_error (&error);
+ }
+
+ g_regex_unref (re);
+ g_free (translate_data);
+
+ return result;
+}
+
+
static int
get_page_idx_from_image_idx (GthWebExporter *self,
int image_idx)
@@ -1113,7 +1208,7 @@ gth_parsed_doc_print (GthWebExporter *self,
else
class_attr = g_strdup ("");
- max_length = gth_tag_get_attribute_int (self, tag, "max_length");
+ max_length = gth_tag_get_attribute_int (self, tag, "max_size");
if (max_length > 0)
scale_keeping_ratio (&image_width,
&image_height,
@@ -1430,11 +1525,7 @@ gth_parsed_doc_print (GthWebExporter *self,
idata = g_list_nth (self->priv->file_list, idx)->data;
self->priv->eval_image = idata;
- if (tag->type == GTH_TAG_FOR_EACH_THUMBNAIL_CAPTION)
- attributes = g_strsplit (self->priv->thumbnail_caption, ",", -1);
- else
- attributes = g_strsplit (self->priv->image_attributes, ",", -1);
-
+ attributes = g_strsplit (self->priv->thumbnail_caption, ",", -1);
n_attributes = g_strv_length (attributes);
first_non_empty = -1;
last_non_empty = -1;
@@ -1566,6 +1657,35 @@ gth_parsed_doc_print (GthWebExporter *self,
}
break;
+ case GTH_TAG_FOR_EACH_IN_RANGE:
+ {
+ LoopInfo *inner_loop_info;
+ int i;
+ int first_value;
+ int last_value;
+
+ first_value = expression_value (self, GTH_RANGE_LOOP (tag)->first_value);
+ last_value = expression_value (self, GTH_RANGE_LOOP (tag)->last_value);
+ inner_loop_info = loop_info_new ();
+ inner_loop_info->iterator = g_strdup (GTH_RANGE_LOOP (tag)->iterator);
+ for (i = first_value; i <= last_value; i++) {
+ inner_loop_info->first_item = (i == first_value);
+ inner_loop_info->last_item = (i == last_value);
+ inner_loop_info->iterator_value = i;
+
+ gth_parsed_doc_print (self,
+ tag->value.loop->document,
+ GTH_TEMPLATE_TYPE_FRAGMENT,
+ inner_loop_info,
+ relative_to,
+ ostream,
+ error);
+ }
+
+ loop_info_unref (inner_loop_info);
+ }
+ break;
+
case GTH_TAG_ITEM_ATTRIBUTE:
if ((loop_info != NULL) && (loop_info->item != NULL)) {
GthMetadataInfo *metadata_info;
@@ -1601,7 +1721,7 @@ gth_parsed_doc_print (GthWebExporter *self,
break;
case GTH_TAG_TRANSLATE:
- line = g_strdup (_(gth_tag_get_attribute_string (self, tag, "text")));
+ line = gth_tag_translate_get_string (self, tag);
write_markup_escape_line (ostream, line, error);
break;
@@ -2337,6 +2457,46 @@ pixbuf_scale (const GdkPixbuf *src,
}
+static GdkPixbuf *
+create_squared_thumbnail (GdkPixbuf *p,
+ int size,
+ GdkInterpType interp_type)
+{
+ int w, h, tw, th;
+ GdkPixbuf *p1;
+ int x, y;
+ GdkPixbuf *p2;
+
+ w = gdk_pixbuf_get_width (p);
+ h = gdk_pixbuf_get_height (p);
+
+ if ((w < size) && (h < size))
+ return gdk_pixbuf_copy (p);
+
+ if (w > h) {
+ th = size;
+ tw = (int) (((double) w / h) * th);
+ }
+ else {
+ tw = size;
+ th = (int) (((double) h / w) * tw);
+ }
+
+ p1 = pixbuf_scale (p, tw, th, interp_type);
+
+ if ((tw == size) && (th == size))
+ return p1;
+
+ x = (tw - size) / 2;
+ y = (th - size) / 2;
+ p2 = gdk_pixbuf_new_subpixbuf (p1, x, y, size, size);
+
+ g_object_unref (p1);
+
+ return p2;
+}
+
+
static void
image_loader_ready_cb (GthImageLoader *iloader,
GError *error,
@@ -2416,16 +2576,48 @@ image_loader_ready_cb (GthImageLoader *iloader,
int w = gdk_pixbuf_get_width (pixbuf);
int h = gdk_pixbuf_get_height (pixbuf);
- if (scale_keeping_ratio (&w, &h,
- self->priv->thumb_width,
- self->priv->thumb_height,
- FALSE))
+ if (self->priv->squared_thumbnails) {
+ GdkPixbuf *squared;
+
+ squared = create_squared_thumbnail (idata->thumb, self->priv->thumb_width, GDK_INTERP_BILINEAR);
+ g_object_unref (idata->thumb);
+ idata->thumb = squared;
+ }
+ else if (scale_keeping_ratio (&w, &h,
+ self->priv->thumb_width,
+ self->priv->thumb_height,
+ FALSE))
{
GdkPixbuf *scaled;
scaled = pixbuf_scale (pixbuf, w, h, GDK_INTERP_BILINEAR);
g_object_unref (idata->thumb);
idata->thumb = scaled;
+
+ if (self->priv->squared_thumbnails) {
+ GdkPixbuf *squared;
+ int src_x;
+ int src_y;
+
+ src_x = (self->priv->thumb_width - gdk_pixbuf_get_width (idata->thumb)) / 2;
+ src_y = (self->priv->thumb_height - gdk_pixbuf_get_height (idata->thumb)) / 2;
+
+ g_print ("[%d, %d] => (%d, %d)[%d, %d]",
+ gdk_pixbuf_get_width (idata->thumb),
+ gdk_pixbuf_get_height (idata->thumb),
+ src_x,
+ src_y,
+ self->priv->thumb_width,
+ self->priv->thumb_height);
+
+ squared = gdk_pixbuf_new_subpixbuf (idata->thumb,
+ src_x,
+ src_y,
+ self->priv->thumb_width,
+ self->priv->thumb_height);
+ g_object_unref (idata->thumb);
+ idata->thumb = squared;
+ }
}
}
@@ -2634,7 +2826,10 @@ parse_theme_files (GthWebExporter *self)
height = gth_tag_get_attribute_int (self, tag, "thumbnail_height");
if ((width != 0) && (height != 0)) {
debug (DEBUG_INFO, "thumbnail --> %dx%d", width, height);
- gth_web_exporter_set_thumb_size (self, width, height);
+ gth_web_exporter_set_thumb_size (self,
+ gth_tag_get_attribute_int (self, tag, "squared"),
+ width,
+ height);
continue;
}
@@ -3156,11 +3351,13 @@ gth_web_exporter_set_adapt_to_width (GthWebExporter *self,
void
gth_web_exporter_set_thumb_size (GthWebExporter *self,
+ gboolean squared,
int width,
int height)
{
g_return_if_fail (GTH_IS_WEB_EXPORTER (self));
+ self->priv->squared_thumbnails = squared;
self->priv->thumb_width = width;
self->priv->thumb_height = height;
}
diff --git a/extensions/webalbums/gth-web-exporter.h b/extensions/webalbums/gth-web-exporter.h
index ece5cf2..7bde406 100644
--- a/extensions/webalbums/gth-web-exporter.h
+++ b/extensions/webalbums/gth-web-exporter.h
@@ -84,6 +84,7 @@ void gth_web_exporter_set_columns (GthWebExporter *self,
void gth_web_exporter_set_adapt_to_width (GthWebExporter *self,
gboolean value);
void gth_web_exporter_set_thumb_size (GthWebExporter *self,
+ gboolean squared,
int width,
int height);
void gth_web_exporter_set_preview_size (GthWebExporter *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]