catalog-web-exporter.c 53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  GThumb
 *
 *  Copyright (C) 2003 Free Software Foundation, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <libgnome/libgnome.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libgnomevfs/gnome-vfs-directory.h>
#include "catalog-web-exporter.h"
#include "comments.h"
#include "file-utils.h"
36
#include "gth-exif-utils.h"
37 38 39 40 41 42 43 44 45 46
#include "dlg-file-utils.h"
#include "gthumb-init.h"
#include "gthumb-marshal.h"
#include "gtk-utils.h"
#include "pixbuf-utils.h"
#include "thumb-loader.h"
#include "image-loader.h"
#include "glib-utils.h"
#include "albumtheme-private.h"

47 48 49
#define DATE_FORMAT _("%d %B %Y, %H:%M")


Paolo Bacchilega's avatar
Paolo Bacchilega committed
50 51 52 53 54
typedef enum {
	GTH_VISIBILITY_ALWAYS = 0,
	GTH_VISIBILITY_INDEX,
	GTH_VISIBILITY_IMAGE
} GthTagVisibility;
55 56

enum {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
57 58 59 60
	WEB_EXPORTER_DONE,
	WEB_EXPORTER_PROGRESS,
	WEB_EXPORTER_INFO,
	WEB_EXPORTER_START_COPYING,
61 62 63 64 65 66 67 68 69 70 71 72
	LAST_SIGNAL
};

extern int yyparse (void);

static GObjectClass *parent_class = NULL;
static guint         catalog_web_exporter_signals[LAST_SIGNAL] = { 0 };
extern FILE         *yyin;

#define DEFAULT_THUMB_SIZE 100
#define DEFAULT_INDEX_FILE "index.html"
#define SAVING_TIMEOUT 5
73

74

75
struct _ImageData {
76
	char             *comment;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
77 78
	char             *src_filename;
	char             *dest_filename;
79 80
	GnomeVFSFileSize  file_size;
	time_t            file_time;
81
	GdkPixbuf        *image;
82
	int               image_width, image_height;
83
	GdkPixbuf        *thumb;
84 85 86
	int               thumb_width, thumb_height;
	GdkPixbuf        *preview;
	int               preview_width, preview_height;
87
	gboolean          caption_set;
88
	gboolean          no_preview;
89
};
90 91 92 93

#define IMAGE_DATA(x) ((ImageData*)(x))


Paolo Bacchilega's avatar
Paolo Bacchilega committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
static char *
zero_padded (int n)
{
	static char  s[1024];
	char        *t;

	sprintf (s, "%3d", n);
	for (t = s; (t != NULL) && (*t != 0); t++)
		if (*t == ' ')
			*t = '0';

	return s;
}


static int img_counter = 0;


112
static ImageData *
Paolo Bacchilega's avatar
Paolo Bacchilega committed
113
image_data_new (const char *filename)
114 115 116 117 118 119 120 121 122 123 124
{
	ImageData   *idata;
	CommentData *cdata;

	idata = g_new (ImageData, 1);

	cdata = comments_load_comment (filename);
	idata->comment = comments_get_comment_as_string (cdata, "&nbsp;<BR>", "&nbsp;<BR>");
	if (cdata != NULL)
		comment_data_free (cdata);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
125 126 127 128 129
	idata->src_filename = g_strdup (filename);
	idata->dest_filename = g_strconcat ("img", 
					    zero_padded (img_counter++), 
					    ".jpeg", 
					    NULL);
130
	idata->file_size = 0;
131

132
	idata->image = NULL;
133 134 135
	idata->image_width = 0;
	idata->image_height = 0;

136 137 138 139 140 141 142 143
	idata->thumb = NULL;
	idata->thumb_width = 0;
	idata->thumb_height = 0;

	idata->preview = NULL;
	idata->preview_width = 0;
	idata->preview_height = 0;

144
	idata->caption_set = FALSE;
145
	idata->no_preview = FALSE;
146 147 148 149 150 151 152 153 154

	return idata;
}


static void
image_data_free (ImageData *idata)
{
	g_free (idata->comment);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
155 156
	g_free (idata->src_filename);
	g_free (idata->dest_filename);
157

158 159 160
	if (idata->image != NULL)
		g_object_unref (idata->image);
	if (idata->thumb != NULL)
161
		g_object_unref (idata->thumb);
162 163
	if (idata->preview != NULL)
		g_object_unref (idata->preview);
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

	g_free (idata);
}


static void
free_parsed_docs (CatalogWebExporter *ce)
{
	if (ce->index_parsed == NULL) {
		gth_parsed_doc_free (ce->index_parsed);
		ce->index_parsed = NULL;
	}

	if (ce->thumbnail_parsed == NULL) {
		gth_parsed_doc_free (ce->thumbnail_parsed);
		ce->thumbnail_parsed = NULL;
	}

	if (ce->image_parsed == NULL) {
		gth_parsed_doc_free (ce->image_parsed);
		ce->image_parsed = NULL;
	}
}


static void 
catalog_web_exporter_finalize (GObject *object)
{
	CatalogWebExporter *ce;

	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (object));
  
	ce = CATALOG_WEB_EXPORTER (object);

198 199 200 201 202
	g_free (ce->header);
	ce->header = NULL;

	g_free (ce->footer);
	ce->footer = NULL;
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

	g_free (ce->style);
	ce->style = NULL;

	g_free (ce->location);
	ce->location = NULL;

	g_free (ce->tmp_location);
	ce->tmp_location = NULL;

	g_free (ce->index_file);
	ce->index_file = NULL;

	g_free (ce->info);
	ce->info = NULL;

	if (ce->file_list != NULL) {
		g_list_foreach (ce->file_list, (GFunc) image_data_free, NULL);
		g_list_free (ce->file_list);
		ce->file_list = NULL;
	}

	if (ce->album_files != NULL) {
		g_list_foreach (ce->album_files, (GFunc) g_free, NULL);
		g_list_free (ce->album_files);
		ce->album_files = NULL;
	}

231 232 233
	if (ce->iloader != NULL) {
		g_object_unref (ce->iloader);
		ce->iloader = NULL;
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	}

	free_parsed_docs (ce);

	/* Chain up */
	G_OBJECT_CLASS (parent_class)->finalize (object);
}


static void
catalog_web_exporter_class_init (CatalogWebExporterClass *class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (class);

	parent_class = g_type_class_peek_parent (class);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
250 251
	catalog_web_exporter_signals[WEB_EXPORTER_DONE] =
		g_signal_new ("web_exporter_done",
252 253
			      G_TYPE_FROM_CLASS (class),
			      G_SIGNAL_RUN_LAST,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
254
			      G_STRUCT_OFFSET (CatalogWebExporterClass, web_exporter_done),
255 256 257 258 259
			      NULL, NULL,
			      gthumb_marshal_VOID__VOID,
			      G_TYPE_NONE, 
			      0);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
260 261
	catalog_web_exporter_signals[WEB_EXPORTER_PROGRESS] =
		g_signal_new ("web_exporter_progress",
262 263
			      G_TYPE_FROM_CLASS (class),
			      G_SIGNAL_RUN_LAST,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
264
			      G_STRUCT_OFFSET (CatalogWebExporterClass, web_exporter_progress),
265 266 267 268 269
			      NULL, NULL,
			      gthumb_marshal_VOID__FLOAT,
			      G_TYPE_NONE, 
			      1, G_TYPE_FLOAT);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
270 271
	catalog_web_exporter_signals[WEB_EXPORTER_INFO] =
		g_signal_new ("web_exporter_info",
272 273
			      G_TYPE_FROM_CLASS (class),
			      G_SIGNAL_RUN_LAST,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
274
			      G_STRUCT_OFFSET (CatalogWebExporterClass, web_exporter_info),
275 276 277 278 279
			      NULL, NULL,
			      gthumb_marshal_VOID__STRING,
			      G_TYPE_NONE, 
			      1, G_TYPE_STRING);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
280 281
	catalog_web_exporter_signals[WEB_EXPORTER_START_COPYING] =
		g_signal_new ("web_exporter_start_copying",
282 283
			      G_TYPE_FROM_CLASS (class),
			      G_SIGNAL_RUN_LAST,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
284
			      G_STRUCT_OFFSET (CatalogWebExporterClass, web_exporter_start_copying),
285 286 287 288 289 290 291 292 293 294 295 296
			      NULL, NULL,
			      gthumb_marshal_VOID__VOID,
			      G_TYPE_NONE, 
			      0);

	object_class->finalize = catalog_web_exporter_finalize;
}


static void
catalog_web_exporter_init (CatalogWebExporter *ce)
{
297 298
	ce->header = NULL;
	ce->footer = NULL;
299 300 301 302 303 304
	ce->style = NULL;
	ce->tmp_location = NULL;
	ce->location = NULL;
	ce->index_file = g_strdup (DEFAULT_INDEX_FILE);
	ce->file_list = NULL;
	ce->album_files = NULL;
305
	ce->iloader = NULL;
306 307 308

	ce->thumb_width = DEFAULT_THUMB_SIZE;
	ce->thumb_height = DEFAULT_THUMB_SIZE;
309

310
	ce->copy_images = FALSE;
311
	ce->resize_images = FALSE;
312 313
	ce->resize_max_width = 0;
	ce->resize_max_height = 0;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
314

315 316 317
	ce->preview_max_width = 0;
	ce->preview_max_height = 0;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
318 319
	ce->index_caption_mask = GTH_CAPTION_IMAGE_DIM | GTH_CAPTION_FILE_SIZE;
	ce->image_caption_mask = GTH_CAPTION_COMMENT | GTH_CAPTION_EXIF_DATE_TIME;
320 321 322 323 324 325 326 327 328 329 330
}


GType
catalog_web_exporter_get_type ()
{
	static guint type = 0;

	if (! type) {
		GTypeInfo type_info = {
			sizeof (CatalogWebExporterClass),
Paolo Bacchilega's avatar
Paolo Bacchilega committed
331 332 333 334 335 336 337 338
			NULL,
			NULL,
			(GClassInitFunc) catalog_web_exporter_class_init,
			NULL,
			NULL,
			sizeof (CatalogWebExporter),
			0,
			(GInstanceInitFunc) catalog_web_exporter_init
339 340 341
                };

                type = g_type_register_static (G_TYPE_OBJECT,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
342 343 344
					       "CatalogWebExporter",
					       &type_info,
					       0);
345 346
        }

Paolo Bacchilega's avatar
Paolo Bacchilega committed
347
	return type;
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
}


CatalogWebExporter *
catalog_web_exporter_new (GThumbWindow *window,
			  GList        *file_list)
{
	CatalogWebExporter *ce;
	GList              *scan;

	g_return_val_if_fail (window != NULL, NULL);

	ce = CATALOG_WEB_EXPORTER (g_object_new (CATALOG_WEB_EXPORTER_TYPE, NULL));

	ce->window = window;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
364
	img_counter = 0;
365
	for (scan = file_list; scan; scan = scan->next) {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
366 367
		const char *filename = (char*) scan->data;
		ImageData  *idata = image_data_new (filename);
368 369 370 371 372 373 374 375 376
		ce->file_list = g_list_prepend (ce->file_list, idata);
	}
	ce->file_list = g_list_reverse (ce->file_list);

	return ce;
}


void
377 378
catalog_web_exporter_set_header (CatalogWebExporter *ce,
				 const char         *header)
379 380
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
381 382 383 384 385 386 387 388 389 390 391 392
	g_free (ce->header);
	ce->header = g_strdup (header);
}


void
catalog_web_exporter_set_footer (CatalogWebExporter *ce,
				 const char         *footer)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	g_free (ce->footer);
	ce->footer = g_strdup (footer);
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
}


void
catalog_web_exporter_set_style (CatalogWebExporter *ce,
				const char         *style)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	g_free (ce->style);
	ce->style = g_strdup (style);
}


void
catalog_web_exporter_set_location (CatalogWebExporter *ce,
				   const char         *location)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	g_free (ce->location);
	ce->location = g_strdup (location);
}


void
catalog_web_exporter_set_index_file (CatalogWebExporter *ce,
				     const char         *index_file)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	g_free (ce->index_file);
	ce->index_file = g_strdup (index_file);
}


void
catalog_web_exporter_set_copy_images (CatalogWebExporter *ce,
				      gboolean            copy)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->copy_images = copy;
}


435 436 437 438 439 440 441 442 443 444 445
void
catalog_web_exporter_set_resize_images (CatalogWebExporter *ce,
					gboolean            resize,
					int                 max_width,
					int                 max_height)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->resize_images = resize;
	if (resize) {
		ce->resize_max_width = max_width;
		ce->resize_max_height = max_height;
446 447 448
	} else {
		ce->resize_max_width = 0;
		ce->resize_max_height = 0;
449 450 451 452
	}
}


453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
void
catalog_web_exporter_set_sorted (CatalogWebExporter *ce,
				 GthSortMethod       method,
				 GtkSortType         sort_type)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->sort_method = method;
	ce->sort_type = sort_type;
}


void
catalog_web_exporter_set_row_col (CatalogWebExporter *ce,
				  int                 rows,
				  int                 cols)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->page_rows = rows;
	ce->page_cols = cols;
}


void
catalog_web_exporter_set_thumb_size (CatalogWebExporter *ce,
				     int                 width,
				     int                 height)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->thumb_width = width;
	ce->thumb_height = height;
}


486 487 488 489 490 491 492
void
catalog_web_exporter_set_preview_size (CatalogWebExporter *ce,
				       int                 width,
				       int                 height)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));

493 494 495 496
	if (ce->copy_images 
	    && ce->resize_images 
	    && (ce->resize_max_width > 0) 
	    && (ce->resize_max_height > 0)) {
497 498 499 500 501 502 503 504 505 506 507
		if (width > ce->resize_max_width) 
			width = ce->resize_max_width;
		if (height > ce->resize_max_height) 
			height = ce->resize_max_height;
	}

	ce->preview_max_width = width;
	ce->preview_max_height = height;
}


508
void
Paolo Bacchilega's avatar
Paolo Bacchilega committed
509 510
catalog_web_exporter_set_image_caption (CatalogWebExporter *ce,
					GthCaptionFields    caption)
511 512
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
Paolo Bacchilega's avatar
Paolo Bacchilega committed
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
	ce->image_caption_mask = caption;
}


guint16
catalog_web_exporter_get_image_caption (CatalogWebExporter *ce)
{
	return ce->image_caption_mask;
}


void
catalog_web_exporter_set_index_caption (CatalogWebExporter *ce,
					GthCaptionFields    caption)
{
	g_return_if_fail (IS_CATALOG_WEB_EXPORTER (ce));
	ce->index_caption_mask = caption;
}


guint16
catalog_web_exporter_get_index_caption (CatalogWebExporter *ce)
{
	return ce->index_caption_mask;
537 538 539 540 541 542 543 544 545 546 547
}


static int
comp_func_name (gconstpointer a, gconstpointer b)
{
	ImageData *data_a, *data_b;

	data_a = IMAGE_DATA (a);
	data_b = IMAGE_DATA (b);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
548 549
	return strcasecmp (file_name_from_path (data_a->src_filename), 
			   file_name_from_path (data_b->src_filename));
550 551 552 553 554 555 556 557 558 559 560
}


static int
comp_func_path (gconstpointer a, gconstpointer b)
{
	ImageData *data_a, *data_b;

	data_a = IMAGE_DATA (a);
	data_b = IMAGE_DATA (b);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
561
	return strcasecmp (data_a->src_filename, data_b->src_filename);
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
}


static int
comp_func_time (gconstpointer a, gconstpointer b)
{
	ImageData *data_a, *data_b;

	data_a = IMAGE_DATA (a);
	data_b = IMAGE_DATA (b);

	if (data_a->file_time == data_b->file_time)
		return 0;
	else if (data_a->file_time > data_b->file_time)
		return 1;
	else
		return -1;
}


static int
comp_func_size (gconstpointer a, gconstpointer b)
{
	ImageData *data_a, *data_b;

	data_a = IMAGE_DATA (a);
	data_b = IMAGE_DATA (b);

	if (data_a->file_size == data_b->file_size)
		return 0;
	else if (data_a->file_size > data_b->file_size)
		return 1;
	else
		return -1;
}


static int
comp_func_none (gconstpointer a, gconstpointer b)
{
	return 0;
}


static GCompareFunc
get_sortfunc (CatalogWebExporter *ce)
{
	GCompareFunc func;

	switch (ce->sort_method) {
	case GTH_SORT_METHOD_BY_NAME:
		func = comp_func_name;
		break;
	case GTH_SORT_METHOD_BY_TIME:
		func = comp_func_time;
		break;
	case GTH_SORT_METHOD_BY_SIZE:
		func = comp_func_size;
		break;
	case GTH_SORT_METHOD_BY_PATH:
		func = comp_func_path;
		break;
	case GTH_SORT_METHOD_NONE:
		func = comp_func_none;
		break;
	default:
		func = comp_func_none;
		break;
	}

	return func;
}


static int
get_var_value (const char *var_name,
	       gpointer    data)
{
	CatalogWebExporter *ce = data;

	if (strcmp (var_name, "image_idx") == 0)
		return ce->image + 1;
	else if (strcmp (var_name, "images") == 0)
		return ce->n_images;
	else if (strcmp (var_name, "page_idx") == 0)
		return ce->page + 1;
	else if (strcmp (var_name, "pages") == 0)
		return ce->n_pages;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
650 651 652 653 654 655 656
	else if (strcmp (var_name, "index") == 0)
		return GTH_VISIBILITY_INDEX;
	else if (strcmp (var_name, "image") == 0)
		return GTH_VISIBILITY_IMAGE;
	else if (strcmp (var_name, "always") == 0)
		return GTH_VISIBILITY_ALWAYS;

657 658 659 660 661 662 663 664 665 666 667 668 669
	else if (strcmp (var_name, "image_width") == 0)
		return ce->eval_image->image_width;
	else if (strcmp (var_name, "image_height") == 0)
		return ce->eval_image->image_height;
	else if (strcmp (var_name, "preview_width") == 0)
		return ce->eval_image->preview_width;
	else if (strcmp (var_name, "preview_height") == 0)
		return ce->eval_image->preview_height;
	else if (strcmp (var_name, "thumb_width") == 0)
		return ce->eval_image->thumb_width;
	else if (strcmp (var_name, "thumb_height") == 0)
		return ce->eval_image->thumb_height;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
	else if (strcmp (var_name, "image_dim_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_IMAGE_DIM;
	else if (strcmp (var_name, "file_name_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_FILE_NAME;
 	else if (strcmp (var_name, "file_path_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_FILE_PATH;
	else if (strcmp (var_name, "file_size_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_FILE_SIZE;
	else if (strcmp (var_name, "comment_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_COMMENT;
	else if (strcmp (var_name, "exif_date_time_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_DATE_TIME;
	else if (strcmp (var_name, "exif_exposure_time_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_EXPOSURE_TIME;
	else if (strcmp (var_name, "exif_exposure_mode_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_EXPOSURE_MODE;
	else if (strcmp (var_name, "exif_flash_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_FLASH;
	else if (strcmp (var_name, "exif_shutter_speed_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_SHUTTER_SPEED;
	else if (strcmp (var_name, "exif_aperture_value_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_APERTURE_VALUE;
	else if (strcmp (var_name, "exif_focal_length_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_FOCAL_LENGTH;
	else if (strcmp (var_name, "exif_camera_model_visibility_index") == 0)
		return ce->index_caption_mask & GTH_CAPTION_EXIF_CAMERA_MODEL;

	else if (strcmp (var_name, "image_dim_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_IMAGE_DIM;
	else if (strcmp (var_name, "file_name_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_FILE_NAME;
 	else if (strcmp (var_name, "file_path_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_FILE_PATH;
	else if (strcmp (var_name, "file_size_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_FILE_SIZE;
	else if (strcmp (var_name, "comment_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_COMMENT;
	else if (strcmp (var_name, "exif_date_time_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_DATE_TIME;
	else if (strcmp (var_name, "exif_exposure_time_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_EXPOSURE_TIME;
	else if (strcmp (var_name, "exif_exposure_mode_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_EXPOSURE_MODE;
	else if (strcmp (var_name, "exif_flash_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_FLASH;
	else if (strcmp (var_name, "exif_shutter_speed_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_SHUTTER_SPEED;
	else if (strcmp (var_name, "exif_aperture_value_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_APERTURE_VALUE;
	else if (strcmp (var_name, "exif_focal_length_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_FOCAL_LENGTH;
	else if (strcmp (var_name, "exif_camera_model_visibility_image") == 0)
		return ce->image_caption_mask & GTH_CAPTION_EXIF_CAMERA_MODEL;
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751

	g_warning ("[GetVarValue] Unknown variable name: %s", var_name);
	
	return 0;
}


static int
expression_value (CatalogWebExporter *ce,
		  GthExpr            *expr)
{
	gth_expr_set_get_var_value_func (expr, get_var_value, ce);
	return gth_expr_eval (expr);
}


static int
gth_tag_get_idx (GthTag             *tag, 
		 CatalogWebExporter *ce,
		 int                 default_value,
		 int                 max_value)
{
	GList *scan;
	int    retval = default_value;

	for (scan = tag->value.arg_list; scan; scan = scan->next) {
		GthVar *var = scan->data;

		if (strcmp (var->name, "idx_relative") == 0) {
752
			retval = default_value + expression_value (ce, var->value.expr);
753 754 755
			break;

		} else if (strcmp (var->name, "idx") == 0) {
756
			retval = expression_value (ce, var->value.expr) - 1;
757 758 759 760
			break;
		}
	}

Paolo Bacchilega's avatar
Paolo Bacchilega committed
761
	retval = MIN (retval, max_value);
762 763 764 765 766 767 768 769 770 771
	retval = MAX (retval, 0);

	return retval;
}


static int
get_image_idx (GthTag             *tag,
	       CatalogWebExporter *ce)
{
Paolo Bacchilega's avatar
Paolo Bacchilega committed
772
	return gth_tag_get_idx (tag, ce, ce->image, ce->n_images - 1);	
773 774 775 776 777 778 779
}


static int
get_page_idx (GthTag             *tag,
	      CatalogWebExporter *ce)
{
Paolo Bacchilega's avatar
Paolo Bacchilega committed
780
	return gth_tag_get_idx (tag, ce, ce->page, ce->n_pages - 1);	
781 782 783 784 785 786 787 788 789 790 791 792 793
}


static int
gth_tag_get_var (CatalogWebExporter *ce,
		 GthTag             *tag, 
		 const char         *var_name)
{
	GList *scan;

	for (scan = tag->value.arg_list; scan; scan = scan->next) {
		GthVar *var = scan->data;
		if (strcmp (var->name, var_name) == 0) 
794
			return expression_value (ce, var->value.expr);
795 796 797 798 799 800
	}

	return 0;
}


801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
static const char *
gth_tag_get_str (CatalogWebExporter *ce,
		 GthTag             *tag,
		 const char         *var_name)
{
	GList *scan;

	for (scan = tag->value.arg_list; scan; scan = scan->next) {
		GthVar *var = scan->data;
		if (strcmp (var->name, var_name) == 0) {
			GthCell *cell = gth_expr_get(var->value.expr);
			if (cell->type == GTH_CELL_TYPE_VAR)
				return cell->value.var;
		}
	}

	return NULL;
}


821 822 823 824 825 826 827 828 829 830 831 832 833
static int
get_page_idx_from_image_idx (CatalogWebExporter *ce,
			     int                 image_idx)
{
	return image_idx / (ce->page_rows * ce->page_cols);
}


static void
write_line (const char *line, FILE *fout) 
{
	if (line == NULL)
		return;
834 835
	if (*line == 0)
		return;
836 837 838 839
	fwrite (line, sizeof (char), strlen (line), fout);
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
840 841
static void
write_locale_line (const char *line, FILE *fout) 
842
{
Paolo Bacchilega's avatar
Paolo Bacchilega committed
843 844 845 846 847 848 849 850 851 852
	char *utf8_line;

	if (line == NULL)
		return;
	if (*line == 0)
		return;

	utf8_line = g_locale_to_utf8 (line, -1, 0, 0, 0);
	write_line (utf8_line, fout);
	g_free (utf8_line);
853 854 855
}


856
static char *
Paolo Bacchilega's avatar
Paolo Bacchilega committed
857 858 859
get_thumbnail_filename (CatalogWebExporter *ce,
			ImageData          *idata,
			const char         *location)
860
{
Paolo Bacchilega's avatar
Paolo Bacchilega committed
861 862 863
	return g_strconcat ((location ? location : ""),
			    (location ? "/" : ""),
			    file_name_from_path (idata->dest_filename), 
864
			    ".small", 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
865 866
			    ".jpeg",
			    NULL);
867 868 869
}


870 871
static char *
get_image_filename (CatalogWebExporter *ce,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
872 873
		    ImageData          *idata,
		    const char         *location)
874
{
Paolo Bacchilega's avatar
Paolo Bacchilega committed
875 876
	char *filename;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
877 878 879 880
	if (ce->copy_images)
		filename = g_strconcat ((location ? location : ""),
					(location ? "/" : ""),
					file_name_from_path (idata->dest_filename),
881
					NULL);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
882 883
	else
		filename = g_strdup (idata->src_filename);
884
	
Paolo Bacchilega's avatar
Paolo Bacchilega committed
885 886 887 888
	return filename;
}


889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
static char *
get_preview_filename (CatalogWebExporter *ce,
		      ImageData          *idata,
		      const char         *location)
{
	if (idata->no_preview)
		return get_image_filename (ce, idata, location);
	else
		return g_strconcat ((location ? location : ""),
				    (location ? "/" : ""),
				    file_name_from_path (idata->dest_filename), 
				    ".medium", 
				    ".jpeg",
				    NULL);
}


static char*
get_current_date (void)
{
	time_t     t;
	struct tm *tp;
	char       s[100];

	t = time (NULL);
	tp = localtime (&t);
	strftime (s, 99, DATE_FORMAT, tp);

	return g_locale_to_utf8 (s, -1, 0, 0, 0);
}


static char *
get_hf_text (const char *utf8_text)
{
	const char *s;
	GString    *r;
	char       *r_str;

	if (utf8_text == NULL)
		return NULL;

	if (g_utf8_strchr (utf8_text,  -1, '%') == NULL)
		return g_strdup (utf8_text);

	r = g_string_new (NULL);
	for (s = utf8_text; *s != 0; s = g_utf8_next_char (s)) {
		gunichar ch = g_utf8_get_char (s);

		if (ch == '%') {
			s = g_utf8_next_char (s);

			if (*s == 0) {
				g_string_append_unichar (r, ch);
				break;
			}

			ch = g_utf8_get_char (s);			
			switch (ch) {
				char *t;

			case '%':
				g_string_append (r, "%");
				break;

			case 'd':
				t = get_current_date ();
				g_string_append (r, t);
				g_free (t);
				break;
			}
		} else
			g_string_append_unichar (r, ch);
	}

	r_str = r->str;
	g_string_free (r, FALSE);

	return r_str;
}


971
static void
972
gth_parsed_doc_print (GList              *document,
973 974 975 976 977 978
		      CatalogWebExporter *ce,
		      FILE               *fout,
		      gboolean            allow_table)
{
	GList *scan;

979
	for (scan = document; scan; scan = scan->next) {
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
		GthTag     *tag = scan->data;
		ImageData  *idata;
		char       *line = NULL;
		char       *image_src, *image_src_relative;
		char       *escaped_path;
		int         idx;
		int         image_width;
		int         image_height;
		int         max_size;
		int         r, c;
		int         value;
		const char *class;
		char       *class_attr;
		char       *filename;
		GList      *scan;

996 997

		switch (tag->type) {
998 999 1000 1001 1002 1003 1004 1005
		case GTH_TAG_HEADER:
			line = get_hf_text (ce->header);
			write_line (line, fout);
			break;

		case GTH_TAG_FOOTER:
			line = get_hf_text (ce->footer);
			write_line (line, fout);
1006 1007 1008 1009
			break;

		case GTH_TAG_IMAGE:
			idx = get_image_idx (tag, ce);
1010
			idata = g_list_nth (ce->file_list, idx)->data;
1011
			ce->eval_image = idata;
1012 1013

			if (gth_tag_get_var (ce, tag, "thumbnail") != 0) {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1014
				image_src = get_thumbnail_filename (ce, idata, ce->location);
1015 1016 1017 1018 1019 1020
				image_width = idata->thumb_width;
				image_height = idata->thumb_height;
			} else if (gth_tag_get_var (ce, tag, "preview") != 0) {
				image_src = get_preview_filename (ce, idata, ce->location);
				image_width = idata->preview_width;
				image_height = idata->preview_height;
1021
			} else {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1022
				image_src = get_image_filename (ce, idata, ce->location);
1023 1024
				image_width = idata->image_width;
				image_height = idata->image_height;
1025 1026
			}

1027 1028 1029 1030 1031
			class = gth_tag_get_str (ce, tag, "class");
			if (class)
				class_attr = g_strdup_printf (" class=\"%s\"", class);
			else
				class_attr = g_strdup ("");
1032

1033
			max_size = gth_tag_get_var (ce, tag, "max_size");
1034 1035 1036 1037 1038
			if (max_size > 0) 
				scale_keepping_ratio (&image_width,
						      &image_height,
						      max_size,
						      max_size);
1039

1040 1041
			image_src_relative = get_path_relative_to_dir (image_src, 
								       ce->location);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1042
			escaped_path = escape_uri (image_src_relative);
1043

1044
			line = g_strdup_printf ("<img src=\"%s\" alt=\"\" width=\"%d\" height=\"%d\"%s>",
1045
						escaped_path,
1046 1047
						image_width,
						image_height,
1048 1049
						class_attr);
			g_free (class_attr);
1050 1051
			g_free (image_src);
			g_free (image_src_relative);
1052
			g_free (escaped_path);
1053 1054 1055 1056 1057
			write_line (line, fout);
			break;

		case GTH_TAG_IMAGE_LINK:
			idx = get_image_idx (tag, ce);
1058
			idata = g_list_nth (ce->file_list, idx)->data;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1059
			line = g_strconcat (file_name_from_path (idata->dest_filename), 
1060 1061
					    ".html",
					    NULL);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1062
			escaped_path = escape_uri (line);
1063 1064 1065
			g_free (line);
			line = escaped_path;

1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
			write_line (line, fout);
			break;

		case GTH_TAG_IMAGE_IDX:
			line = g_strdup_printf ("%d", get_image_idx (tag, ce) + 1);
			write_line (line, fout);
			break;

		case GTH_TAG_IMAGE_DIM:
			idx = get_image_idx (tag, ce);
1076
			idata = g_list_nth (ce->file_list, idx)->data;
1077
			line = g_strdup_printf ("%dx%d",
1078 1079
						idata->image_width,
						idata->image_height);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
			write_line (line, fout);
			break;

		case GTH_TAG_IMAGES:
			line = g_strdup_printf ("%d", ce->n_images);
			write_line (line, fout);
			break;

		case GTH_TAG_FILENAME:
			idx = get_image_idx (tag, ce);
1090
			idata = g_list_nth (ce->file_list, idx)->data;
1091
			ce->eval_image = idata;
1092 1093

			if (gth_tag_get_var (ce, tag, "with_path") != 0) {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1094
				line = get_image_filename (ce, idata, ce->location);
1095 1096

			} else if (gth_tag_get_var (ce, tag, "with_relative_path") != 0) {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1097
				char *path = get_image_filename (ce, idata, ce->location);
1098 1099 1100
				line = get_path_relative_to_dir (path, ce->location);
				g_free (path);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1101 1102 1103 1104 1105
			} else {
				char *path = get_image_filename (ce, idata, ce->location);
				line = g_strdup (file_name_from_path (path));
				g_free (path);
			}
1106

1107 1108 1109
			if  (gth_tag_get_var (ce, tag, "utf8") != 0) 
				write_locale_line (line, fout);
			else {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1110
				escaped_path = escape_uri (line);
1111 1112 1113 1114 1115
				g_free (line);
				line = escaped_path;
				write_line (line, fout);
			}

1116 1117 1118 1119
			break;

		case GTH_TAG_FILEPATH:
			idx = get_image_idx (tag, ce);
1120
			idata = g_list_nth (ce->file_list, idx)->data;
1121
			ce->eval_image = idata;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1122
			filename = get_image_filename (ce, idata, ce->location);
1123 1124 1125 1126 1127 1128 1129 1130
			if (gth_tag_get_var (ce, tag, "relative_path") != 0) {
				char *tmp;
				tmp = get_path_relative_to_dir (filename, ce->location);
				g_free (filename);
				filename = tmp;
			}
			line = remove_level_from_path (filename);
			g_free (filename);
1131 1132 1133 1134

			if  (gth_tag_get_var (ce, tag, "utf8") != 0) 
				write_locale_line (line, fout);
			else {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1135
				escaped_path = escape_uri (line);
1136 1137 1138 1139 1140
				g_free (line);
				line = escaped_path;
				write_line (line, fout);
			}
	
1141 1142 1143 1144
			break;

		case GTH_TAG_FILESIZE:
			idx = get_image_idx (tag, ce);
1145 1146
			idata = g_list_nth (ce->file_list, idx)->data;
			line = gnome_vfs_format_file_size_for_display (idata->file_size);
1147 1148 1149 1150 1151
			write_line (line, fout);
			break;

		case GTH_TAG_COMMENT:
			idx = get_image_idx (tag, ce);
1152
			idata = g_list_nth (ce->file_list, idx)->data;
1153
			ce->eval_image = idata;
1154
			
1155
			if (idata->comment == NULL)
1156 1157 1158 1159
				break;

			max_size = gth_tag_get_var (ce, tag, "max_size");
			if (max_size <= 0)
1160
				line = g_strdup (idata->comment);
1161
			else {
1162 1163
				char *comment = g_strndup (idata->comment, max_size);
				if (strlen (comment) < strlen (idata->comment))
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
					line = g_strconcat (comment, "...", NULL);
				else
					line = g_strdup (comment);
				g_free (comment);
			}

			write_line (line, fout);
			break;

		case GTH_TAG_PAGE_LINK:
			if (gth_tag_get_var (ce, tag, "image_idx") != 0) {
				int image_idx;
				image_idx = get_image_idx (tag, ce);
				idx = get_page_idx_from_image_idx (ce, image_idx);
			} else 
				idx = get_page_idx (tag, ce);

			if (idx == 0)
				line = g_strdup (ce->index_file);
			else
				line = g_strconcat ("page",
						    zero_padded (idx + 1),
						    ".html",
						    NULL);
			write_line (line, fout);
			break;

		case GTH_TAG_PAGE_IDX:
			line = g_strdup_printf ("%d", get_page_idx (tag, ce) + 1);
			write_line (line, fout);
			break;

		case GTH_TAG_PAGES:
			line = g_strdup_printf ("%d", ce->n_pages);
			write_line (line, fout);
			break;

		case GTH_TAG_TABLE:
			if (! allow_table)
				break;

			for (r = 0; r < ce->page_rows; r++) {
1206
				write_line ("  <tr>\n", fout);
1207 1208
				for (c = 0; c < ce->page_cols; c++) {
					if (ce->image < ce->n_images) {
1209
						write_line ("    <td>\n", fout);
1210 1211 1212 1213 1214 1215
						gth_parsed_doc_print (ce->thumbnail_parsed, 
								      ce, 
								      fout, 
								      FALSE);
						write_line ("    </td>\n", fout);
						ce->image++;
1216 1217
					} else {
						char *line;
1218
						line = g_strdup_printf ("    <td width=%d height=%d>\n", ce->thumb_width, ce->thumb_height);
1219 1220 1221 1222
						write_line (line, fout);
						g_free (line);
						write_line ("    &nbsp;\n", fout);
						write_line ("    </td>\n", fout);
1223 1224 1225 1226 1227 1228 1229
					} 
				}
				write_line ("  </tr>\n", fout);
			}
			break;

		case GTH_TAG_DATE:
1230 1231
			line = get_current_date ();
			write_line (line, fout);
1232 1233
			break;

1234 1235
		case GTH_TAG_HTML:
			write_line (tag->value.html, fout);
1236 1237
			break;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1238 1239 1240 1241
		case GTH_TAG_EXIF_EXPOSURE_TIME:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1242
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1243 1244 1245 1246 1247 1248 1249 1250 1251
					     EXIF_TAG_EXPOSURE_TIME);
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_EXPOSURE_MODE:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1252
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1253 1254 1255 1256 1257 1258 1259 1260 1261
					     EXIF_TAG_EXPOSURE_MODE);
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_FLASH:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1262
			line = get_exif_tag (idata->src_filename, EXIF_TAG_FLASH);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1263 1264 1265 1266 1267 1268 1269 1270
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_SHUTTER_SPEED:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1271
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1272 1273 1274 1275 1276 1277 1278 1279 1280
					     EXIF_TAG_SHUTTER_SPEED_VALUE);
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_APERTURE_VALUE:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1281
			line = get_exif_aperture_value (idata->src_filename);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1282 1283 1284 1285 1286 1287 1288 1289
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_FOCAL_LENGTH:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1290
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
					     EXIF_TAG_FOCAL_LENGTH);
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_DATE_TIME:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
			{
				time_t     t;
				struct tm *tp;
				char s[100];

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1305
				t = get_exif_time (idata->src_filename);
1306 1307 1308 1309 1310 1311 1312 1313
				if (t != 0) {
					tp = localtime (&t);
					strftime (s, 99, DATE_FORMAT, tp);
					line = g_locale_to_utf8 (s, -1, 0, 0, 0);
					write_line (line, fout);
				} else
					write_line ("-", fout);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1314 1315 1316 1317 1318 1319 1320 1321
			}
#endif /* HAVE_LIBEXIF */
			break;

		case GTH_TAG_EXIF_CAMERA_MODEL:
			idx = get_image_idx (tag, ce);
			idata = g_list_nth (ce->file_list, idx)->data;
#ifdef HAVE_LIBEXIF
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1322
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1323 1324 1325 1326 1327 1328
					     EXIF_TAG_MAKE);
			write_line (line, fout);
			g_free (line);

			write_line (" ", fout);

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1329
			line = get_exif_tag (idata->src_filename, 
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1330 1331 1332 1333 1334
					     EXIF_TAG_MODEL);
			write_line (line, fout);
#endif /* HAVE_LIBEXIF */
			break;

Paolo Bacchilega's avatar