[gthumb: 28/57] [webalbums] added a generic image_attribute_available function



commit be12c7a1d9b3fa53e1594f759b294f58f593ce26
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Jun 14 21:20:19 2010 +0200

    [webalbums] added a generic image_attribute_available function
    
    added support for function calls in the template syntax, and
    added a image_attribute_available function to test the
    availability of an attribute.

 extensions/webalbums/albumtheme-private.c          |   27 +++++-----
 extensions/webalbums/albumtheme-private.h          |    1 +
 extensions/webalbums/albumtheme.l                  |    6 +-
 extensions/webalbums/albumtheme.y                  |   27 ++++++++++
 .../data/albumthemes/ClassicClips/image.gthtml     |    6 ++
 .../data/albumthemes/ClassicClips/layout.css       |    4 +-
 extensions/webalbums/gth-web-exporter.c            |   55 +++++++++++--------
 7 files changed, 85 insertions(+), 41 deletions(-)
---
diff --git a/extensions/webalbums/albumtheme-private.c b/extensions/webalbums/albumtheme-private.c
index 1d9dbc1..54d96f9 100644
--- a/extensions/webalbums/albumtheme-private.c
+++ b/extensions/webalbums/albumtheme-private.c
@@ -365,29 +365,30 @@ gth_expr_print (GthExpr *e)
 {
 	int i;
 
-	for (i = 0; i < gth_expr_get_top (e); i++) {
-		GthCell *cell = gth_expr_get_pos (e, i + 1);
+	for (i = 1; i <= gth_expr_get_top (e); i++) {
+		GthCell *cell = gth_expr_get_pos (e, i);
 
 		switch (cell->type) {
 		case GTH_CELL_TYPE_VAR:
-			printf ("VAR: %s (%d)\n",
-				cell->value.var,
-				e->get_var_value_func (e,
-						       &i,
-						       cell->value.var,
-						       e->get_var_value_data));
+			/*g_print ("VAR: %s (%d)\n",
+				 cell->value.var,
+				 e->get_var_value_func (e,
+						        &i,
+						        cell->value.var,
+						        e->get_var_value_data));*/
+			g_print ("(%d) VAR: %s\n", i, cell->value.var);
 			break;
 
 		case GTH_CELL_TYPE_STRING:
-			g_print ("STRING: %s\n", cell->value.string->str);
+			g_print ("(%d) STRING: %s\n", i, cell->value.string->str);
 			break;
 
 		case GTH_CELL_TYPE_INTEGER:
-			printf ("NUM: %d\n", cell->value.integer);
+			printf ("(%d) NUM: %d\n", i, cell->value.integer);
 			break;
 
 		case GTH_CELL_TYPE_OP:
-			printf ("OP: %s\n", op_name[cell->value.op]);
+			printf ("(%d) OP: %s\n", i, op_name[cell->value.op]);
 			break;
 		}
 	}
@@ -403,8 +404,8 @@ gth_expr_eval (GthExpr *e)
 
 	mem = gth_mem_new (MEM_SIZE);
 
-	for (i = 0; i < gth_expr_get_top (e); i++) {
-		GthCell *cell = gth_expr_get_pos (e, i + 1);
+	for (i = 1; i <= gth_expr_get_top (e); i++) {
+		GthCell *cell = gth_expr_get_pos (e, i);
 		int      a, b, c;
 
 		switch (cell->type) {
diff --git a/extensions/webalbums/albumtheme-private.h b/extensions/webalbums/albumtheme-private.h
index e723496..8475630 100644
--- a/extensions/webalbums/albumtheme-private.h
+++ b/extensions/webalbums/albumtheme-private.h
@@ -127,6 +127,7 @@ int       gth_expr_get_top                (GthExpr            *e);
 void      gth_expr_set_get_var_value_func (GthExpr            *e,
 					   GthGetVarValueFunc  f,
 					   gpointer            data);
+void      gth_expr_print                  (GthExpr            *e);
 int       gth_expr_eval                   (GthExpr            *e);
 
 /* GthVar */
diff --git a/extensions/webalbums/albumtheme.l b/extensions/webalbums/albumtheme.l
index 1d31b42..e7d4612 100644
--- a/extensions/webalbums/albumtheme.l
+++ b/extensions/webalbums/albumtheme.l
@@ -39,7 +39,7 @@ static int before_string = 0; /* the start condition before entering in STRING *
 
 number           [0-9]+
 attribute_name   [a-zA-Z_][a-zA-Z_0-9:\.-]*
-name             [a-zA-Z_][^'" \t\n]*
+name             [a-zA-Z_][a-zA-Z_0-9:\.]*
 string           [^']*
 
 %x FUNCTION ATTRIBUTES CONDITION QUOTE STRING
@@ -85,7 +85,7 @@ string           [^']*
 					yylval.text = g_strdup (yytext);
 					return FUNCTION_NAME;
 				}
-<ATTRIBUTES>"'"			{
+<ATTRIBUTES,QUOTE,CONDITION>"'"	{
 					before_string = YY_START;
 					BEGIN (STRING);
 					return '\'';
@@ -106,7 +106,7 @@ string           [^']*
 					BEGIN (ATTRIBUTES);
 					return '"';
 				}
-<ATTRIBUTES,QUOTE,CONDITION>"%>"	{
+<ATTRIBUTES,CONDITION>"%>"	{
 					BEGIN (INITIAL);
 					return END_TAG;
 				}
diff --git a/extensions/webalbums/albumtheme.y b/extensions/webalbums/albumtheme.y
index e0fba3f..68c7847 100644
--- a/extensions/webalbums/albumtheme.y
+++ b/extensions/webalbums/albumtheme.y
@@ -294,6 +294,26 @@ 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 ')' {
+			GthExpr *e = gth_expr_new ();
+			gth_expr_push_var (e, $1);
+			if ($3 != NULL) {
+				gth_expr_push_expr (e, $3);
+				gth_expr_unref ($3);
+			}
+			g_free ($1);
+			$$ = e;
+		}
+
 		| VARIABLE {
 			GthExpr *e = gth_expr_new ();
 			gth_expr_push_var (e, $1);
@@ -301,6 +321,13 @@ expr		: '(' expr ')' {
 			$$ = e;
 		}
 
+		| '\'' QUOTED_STRING '\'' {
+			GthExpr *e = gth_expr_new ();
+			gth_expr_push_string (e, $2);
+			g_free ($2);
+			$$ = e;
+		}
+
 		| NUMBER {
 			GthExpr *e = gth_expr_new ();
 			gth_expr_push_integer (e, $1);
diff --git a/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml b/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
index 8cf76aa..cba0050 100644
--- a/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
+++ b/extensions/webalbums/data/albumthemes/ClassicClips/image.gthtml
@@ -77,6 +77,12 @@
         <% end %>
       <% end %>
 
+      <% if image_attribute_available('general::description') %>
+      <div class="image-comment">
+        <%= image_attribute id="general::description" %>
+      </div>
+      <% end %>
+
     </div>    
   </div>
   <div id="footer">
diff --git a/extensions/webalbums/data/albumthemes/ClassicClips/layout.css b/extensions/webalbums/data/albumthemes/ClassicClips/layout.css
index 355f6c4..d9d6d9d 100644
--- a/extensions/webalbums/data/albumthemes/ClassicClips/layout.css
+++ b/extensions/webalbums/data/albumthemes/ClassicClips/layout.css
@@ -125,12 +125,12 @@ div.image-comment {
 	display: block;
 	margin: 15px 15px 0 0;
 	padding: 3px;
-	text-align: center;	
+	text-align: left;
 	font-size: 10px;
 	font-family: sans;
 	overflow: auto;
 	width: 300px;
-	border: 1px solid #aaa;
+	border: 0px solid #aaa;
 }
 
 dl.caption-container {
diff --git a/extensions/webalbums/gth-web-exporter.c b/extensions/webalbums/gth-web-exporter.c
index 7939949..9daf2c4 100644
--- a/extensions/webalbums/gth-web-exporter.c
+++ b/extensions/webalbums/gth-web-exporter.c
@@ -365,14 +365,23 @@ get_var_value (GthExpr    *expr,
 	else if (g_str_equal (var_name, "image_attribute_available")) {
 		GthCell *cell;
 
-		*index += 1;
-		cell = gth_expr_get_pos (expr, *index);
-		if (cell->type == GTH_CELL_TYPE_STRING) {
+		cell = gth_expr_get_pos (expr, (*index) + 1);
+		if ((cell != NULL) && (cell->type == GTH_CELL_TYPE_STRING)) {
 			const char *attribute_id;
+			char       *value;
+			int         result;
 
 			attribute_id = cell->value.string->str;
-			/* TODO */
+			value = gth_file_data_get_attribute_as_string (self->priv->eval_image->file_data, attribute_id);
+			result = (value != NULL);
+			*index += 1;
+
+			g_free (value);
+
+			return result;
 		}
+		else
+			return 0;
 	}
 
 	/* FIXME: use a generic function to get an attribute visibility */
@@ -467,6 +476,15 @@ gth_tag_get_idx (GthTag         *tag,
 	GList *scan;
 	int    retval = default_value;
 
+	if ((tag->type == GTH_TAG_HTML)
+	    || (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_INVALID))
+	{
+		return 0;
+	}
+
 	for (scan = tag->value.arg_list; scan; scan = scan->next) {
 		GthVar *var = scan->data;
 
@@ -655,20 +673,15 @@ write_markup_escape_locale_line (GFileOutputStream  *ostream,
 static char *
 get_image_attribute (GthWebExporter    *self,
 		     GthTag            *tag,
-		     const char        *attribute)
+		     const char        *attribute,
+		     ImageData         *image_data)
 {
-	int        image_idx;
-	ImageData *image_data;
-	char      *value;
-	int        max_size;
-	char      *line = NULL;
-
-	image_idx = get_image_idx (tag, self);
-	image_data = g_list_nth (self->priv->file_list, image_idx)->data;
-	self->priv->eval_image = image_data;
+	char *value;
+	int   max_size;
+	char *line = NULL;
 
 	/* FIXME */
-	value = g_file_info_get_attribute_as_string (image_data->file_data->info, attribute);
+	value = gth_file_data_get_attribute_as_string (image_data->file_data, attribute);
 	if (value == NULL)
 		return NULL;
 
@@ -1195,7 +1208,7 @@ gth_parsed_doc_print (GthWebExporter      *self,
 			idata = g_list_nth (self->priv->file_list, idx)->data;
 			id = gth_tag_get_str (self, tag, "id");
 			if (id != NULL) {
-				line = get_image_attribute (self, tag, id);
+				line = get_image_attribute (self, tag, id, idata);
 				write_line (ostream, line, error);
 			}
 			break;
@@ -1299,26 +1312,22 @@ gth_parsed_doc_print (GthWebExporter      *self,
 
 			/* FIXME
 		case GTH_TAG_COMMENT:
-			line = get_image_attribute (self, tag, "general::title");
+			line = get_image_attribute (self, tag, "general::title", image_data);
 			write_markup_escape_line (ostream, line, error);
 			break;
 
 		case GTH_TAG_PLACE:
-			line = get_image_attribute (self, tag, "general::location");
+			line = get_image_attribute (self, tag, "general::location", image_data);
 			write_markup_escape_line (ostream, line, error);
 			break;
 
 		case GTH_TAG_DATE_TIME:
-			line = get_image_attribute (self, tag, "general::datetime");
+			line = get_image_attribute (self, tag, "general::datetime", image_data);
 			write_markup_escape_line (ostream, line, error);
 			break;
 			*/
 
 			/* FIXME
-			idx = get_image_idx (tag, self);
-			idata = g_list_nth (self->priv->file_list, idx)->data;
-			self->priv->eval_image = idata;
-
 			if (idata->date_time == NULL)
 				break;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]