diff options
| -rw-r--r-- | generators.c | 46 | ||||
| -rw-r--r-- | items.c | 18 | ||||
| -rw-r--r-- | sample/src/CIAF_1/index.xml | 12 | ||||
| -rw-r--r-- | sample/src/index.xml | 2 |
4 files changed, 54 insertions, 24 deletions
diff --git a/generators.c b/generators.c index a3abe24..3639309 100644 --- a/generators.c +++ b/generators.c @@ -54,12 +54,12 @@ generate_image (TGallerySetup *setup, *img_src = item->thumbnail; if (items->type == GALLERY_TYPE_INDEX) - *img_src = item->thumbnail; + *img_src = item->thumbnail; else - if (items->type == GALLERY_TYPE_ALBUM) - *img_src = item->path; - - img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); + if (items->type == GALLERY_TYPE_ALBUM) + *img_src = (item->path == NULL && item->preview) ? item->preview : item->path; + + img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); get_image_sizes (img_src_full, img_w, img_h); if ((img_w > 0) && (img_h > 0)) { @@ -90,8 +90,10 @@ generate_image (TGallerySetup *setup, if (items->type == GALLERY_TYPE_ALBUM) { s1 = g_path_get_dirname (dst); - big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", *img_src, NULL); + s2 = g_path_get_basename (*img_src); + big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", s2, NULL); g_free (s1); + g_free (s2); if (item->preview == NULL) { /* No preview image supplied, generate it from original */ @@ -453,6 +455,7 @@ write_html_image (TGallerySetup *setup, TAlbum *parent; int i; char *s1, *s2, *s3; + char *imgname; char *b; gboolean res; int level; @@ -472,8 +475,9 @@ write_html_image (TGallerySetup *setup, buffer = malloc (BUFFER_SIZE); s1 = g_path_get_dirname (dst); - big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", item->path, NULL); - orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", item->path, NULL); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", imgname, NULL); + orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", imgname, NULL); g_free (s1); buf_img_fullsize_link = malloc (BUFFER_SIZE); memset (buf_img_fullsize_link, 0, BUFFER_SIZE); @@ -538,7 +542,7 @@ write_html_image (TGallerySetup *setup, /* Simple placeholders */ if (strstr (b, "<!-- $(FILE_NAME) -->")) - str_replace (&b, "<!-- $(FILE_NAME) -->", item->path); + str_replace (&b, "<!-- $(FILE_NAME) -->", imgname); if (strstr (b, "<!-- $(TITLE) -->") && item->title) str_replace (&b, "<!-- $(TITLE) -->", item->title); if (strstr (b, "<!-- $(DESCRIPTION) -->") && item->title_description) @@ -554,7 +558,7 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(NAV_BAR) -->")) { - s1 = g_strconcat (item->title, " (", item->path, ")", NULL); + s1 = g_strconcat (item->title, " (", imgname, ")", NULL); parent = parent_items; level = 0; while (parent) { @@ -570,12 +574,12 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(IMG_SRC_BIG) -->")) { - s1 = g_strconcat (IMG_BIG_DIR, "/", item->path, NULL); + s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL); str_replace (&b, "<!-- $(IMG_SRC_BIG) -->", s1); g_free (s1); } if (strstr(b, "<!-- $(IMG_SRC_FULL) -->")) { - s1 = g_strconcat (IMG_ORIG_DIR, "/", item->path, NULL); + s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL); str_replace (&b, "<!-- $(IMG_SRC_FULL) -->", s1); g_free (s1); } @@ -654,18 +658,22 @@ write_html_image (TGallerySetup *setup, if (strstr (b, "<!-- $(LINK_NEXT) -->")) { if (next_item) { - s1 = g_strconcat (next_item->path, ".html", NULL); + s2 = (next_item->path == NULL && next_item->preview) ? g_path_get_basename (next_item->preview) : g_strdup (next_item->path); + s1 = g_strconcat (s2, ".html", NULL); str_replace (&b, "<!-- $(LINK_NEXT) -->", s1); g_free (s1); + g_free (s2); } else str_replace (&b, "<!-- $(LINK_NEXT) -->", "index.html"); } if (strstr(b, "<!-- $(LINK_PREV) -->")) { if (previous_item) { - s1 = g_strconcat (previous_item->path, ".html", NULL); + s2 = (previous_item->path == NULL && previous_item->preview) ? g_path_get_basename (previous_item->preview) : g_strdup (previous_item->path); + s1 = g_strconcat (s2, ".html", NULL); str_replace (&b, "<!-- $(LINK_PREV) -->", s1); g_free (s1); + g_free (s2); } else str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html"); @@ -689,6 +697,7 @@ write_html_image (TGallerySetup *setup, free (big_dst); free (orig_dst); free (buf_img_fullsize_link); + g_free (imgname); free_exif_data (exif); return res; } @@ -716,6 +725,7 @@ build_tree (TGallerySetup *setup, char *img_big_dir; char *img_orig_dir; char *template; + char *imgname; gboolean res; int i; @@ -861,14 +871,16 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "build_tree: error getting item %d\n", i); continue; } - if (setup->verbose) printf ("Writing '%s.html' ...", item->path); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + if (setup->verbose) printf ("Writing '%s.html' ...", imgname); s1 = g_strconcat (setup->real_templates_dir, "/", setup->template_photo, NULL); - s2 = g_strconcat (items->base_dir, "/", item->path, NULL); - s3 = g_strconcat (dst_dir, "/", item->path, ".html", NULL); + s2 = g_strconcat (items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL); + s3 = g_strconcat (dst_dir, "/", imgname, ".html", NULL); res = write_html_image (setup, s1, s2, s3, item, items); g_free (s1); g_free (s2); g_free (s3); + g_free (imgname); if (! res ) continue; if (setup->verbose) printf (" done.\n"); } @@ -113,20 +113,28 @@ parse_album_xml (const char *filename, TAlbum *index) g_free (s); s = g_strdup_printf ("/gallery/items/item[%d]/nofullsize", i + 1); - item->nofullsize = xml_file_get_node_present (xml, s); + item->nofullsize = (xml_file_get_node_present (xml, s) || item->path == NULL); g_free (s); - g_ptr_array_add (index->items, item); + if (item->path || item->preview) + { + g_ptr_array_add (index->items, item); + } + else + { + fprintf (stderr, "%s: No image src specified, skipping!\n", filename); + free (item); + } } xml_parser_close (xml); /* Print the items */ #ifdef __DEBUG_ALL__ - printf("ID = '%s'\ntitle = '%s'\ndescription = '%s'\n", index->ID, index->title, index->desc); + printf ("ID = '%s'\ntitle = '%s'\ndescription = '%s'\n", index->ID, index->title, index->desc); for (i = 0; i < index->items->len; i++) { - TIndexItem *item = g_ptr_array_index(index->items, i); - printf("item %d: path = '%s', title = '%s', title_description = '%s', thumbnail = '%s'\n", + TIndexItem *item = g_ptr_array_index (index->items, i); + printf ("item %d: path = '%s', title = '%s', title_description = '%s', thumbnail = '%s'\n", i, item->path, item->title, item->title_description, item->thumbnail); } #endif diff --git a/sample/src/CIAF_1/index.xml b/sample/src/CIAF_1/index.xml index 9d619f5..788fc95 100644 --- a/sample/src/CIAF_1/index.xml +++ b/sample/src/CIAF_1/index.xml @@ -26,7 +26,17 @@ <item src="img_6802c.jpg" preview="preview/img_6802.jpg"> <nofullsize /> <title>Photo title</title> - <title_description>This photo doesn't contain link to original image, though it's still needed for EXIF data extraction.</title_description> + <title_description>This photo doesn't contain link to original image, but src parameter is specified.</title_description> + </item> + + <item preview="preview/img_6802d.jpg"> + <title>Photo title</title> + <title_description>This photo doesn't contain link to original image nor the src parameter, EXIF data are extracted from the preview image.</title_description> + </item> + + <item> + <title>Invalid item</title> + <title_description>Invalid item (no src specified), will be skipped.</title_description> </item> <item src="img_6850.jpg" quality="20"> diff --git a/sample/src/index.xml b/sample/src/index.xml index fb91c93..ba88e57 100644 --- a/sample/src/index.xml +++ b/sample/src/index.xml @@ -3,7 +3,7 @@ <general> <ID>CGG Sample gallery root</ID> <title>Welcome to sample gallery for Cataract Gallery Generator!</title> - <description><