From c261763c76fb15c1509ee6b88035b604222edc21 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 26 Dec 2008 22:58:15 +0100 Subject: Add support for album and index separators --- generators.c | 207 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 134 insertions(+), 73 deletions(-) (limited to 'generators.c') diff --git a/generators.c b/generators.c index 904d407..0a1585c 100644 --- a/generators.c +++ b/generators.c @@ -193,21 +193,25 @@ write_html_album (TGallerySetup *setup, char *buffer; char *buf_img_list_landscape; char *buf_img_list_portrait; + char *buf_img_separator; char *buf_go_up_string; gboolean in_img_list; gboolean in_img_list_landscape; gboolean in_img_list_portrait; + gboolean in_img_separator; gboolean in_go_up_string; char *b; char *s1, *s2, *s3, *s4; TAlbum *parent; TIndexItem *item; + TIndexItem *tmp_item; int level; gboolean res; int i; unsigned long img_w, img_h; char *img_src; char *thumb; + unsigned int real_total_items; fin = fopen (template_src, "r"); @@ -225,13 +229,23 @@ write_html_album (TGallerySetup *setup, buffer = malloc (BUFFER_SIZE); buf_img_list_landscape = malloc (BUFFER_SIZE); buf_img_list_portrait = malloc (BUFFER_SIZE); + buf_img_separator = malloc (BUFFER_SIZE); buf_go_up_string = malloc (BUFFER_SIZE); in_img_list = FALSE; in_img_list_landscape = FALSE; in_img_list_portrait = FALSE; + in_img_separator = FALSE; in_go_up_string = FALSE; res = TRUE; + /* Get number of real pictures in the list */ + real_total_items = 0; + for (i = 0; i < items->items->len; i++) { + tmp_item = g_ptr_array_index (items->items, i); + if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE) + real_total_items++; + } + /* Read through the template and replace placeholders with real data */ while (! feof (fin)) { @@ -264,6 +278,16 @@ write_html_album (TGallerySetup *setup, free (b); continue; } + if (in_img_list && (strstr (buffer, ""))) { + in_img_separator = TRUE; + free (b); + continue; + } + if (in_img_list && (strstr (buffer, ""))) { + in_img_separator = FALSE; + free (b); + continue; + } if (in_img_list && in_img_list_landscape) { buf_img_list_landscape = strncat (buf_img_list_landscape, b, BUFFER_SIZE - strlen (buf_img_list_landscape) - 2); free (b); @@ -274,6 +298,11 @@ write_html_album (TGallerySetup *setup, free (b); continue; } + if (in_img_list && in_img_separator) { + buf_img_separator = strncat (buf_img_separator, b, BUFFER_SIZE - strlen (buf_img_separator) - 2); + free (b); + continue; + } if (strstr (buffer, "")) { memset (buf_go_up_string, 0, BUFFER_SIZE); @@ -348,7 +377,7 @@ write_html_album (TGallerySetup *setup, g_free (s1); } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", items->items->len); + s1 = g_strdup_printf ("%d", real_total_items); str_replace (&b, "", s1, NULL); g_free (s1); } @@ -377,9 +406,11 @@ write_html_album (TGallerySetup *setup, if (strstr (buffer, "")) { memset (buf_img_list_landscape, 0, BUFFER_SIZE); memset (buf_img_list_portrait, 0, BUFFER_SIZE); + memset (buf_img_separator, 0, BUFFER_SIZE); in_img_list = TRUE; in_img_list_landscape = FALSE; in_img_list_portrait = FALSE; + in_img_separator = FALSE; free (b); continue; } @@ -404,51 +435,64 @@ write_html_album (TGallerySetup *setup, img_h = 0; img_src = NULL; thumb = NULL; - generate_image (setup, items, item, dst, &img_w, &img_h, &img_src, &thumb); - /* Process HTML box code */ - if ((img_w / img_h) >= 1) - s1 = strdup (buf_img_list_landscape); - else - s1 = strdup (buf_img_list_portrait); - - if (strstr (s1, "")) { - s2 = g_strconcat (item->path, "/index.html", NULL); - str_replace (&s1, "", s2, NULL); - g_free (s2); - } - if (strstr (s1, "")) { - s2 = g_strconcat (img_src, ".html", NULL); - str_replace (&s1, "", s2, NULL); - g_free (s2); - } - if (strstr (s1, "") && item->title) { - s2 = g_strdup (item->title); - fix_entities (&s2); - str_replace (&s1, "", s2, NULL); - g_free (s2); - } - if (strstr (s1, "") && item->title_description) { - s2 = g_strdup (item->title_description); - fix_entities (&s2); - str_replace (&s1, "", s2, NULL); - g_free (s2); - } - if (strstr(s1, "")) { - s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL); - s2 = g_strdup_printf ("%d", get_album_objects_count(s3)); - str_replace (&s1, "", s2, NULL); - g_free (s2); - g_free (s3); - } - if (strstr (s1, "")) { - s2 = g_strconcat (THUMBNAIL_DIR, "/", thumb, NULL); - str_replace (&s1, "", s2, NULL); - g_free (s2); + switch (item->type) { + case INDEX_ITEM_TYPE_PICTURE: + generate_image (setup, items, item, dst, &img_w, &img_h, &img_src, &thumb); + /* Process HTML box code */ + if ((img_w / img_h) >= 1) + s1 = strdup (buf_img_list_landscape); + else + s1 = strdup (buf_img_list_portrait); + + if (strstr (s1, "")) { + s2 = g_strconcat (item->path, "/index.html", NULL); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr (s1, "")) { + s2 = g_strconcat (img_src, ".html", NULL); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr (s1, "") && item->title) { + s2 = g_strdup (item->title); + fix_entities (&s2); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr (s1, "") && item->title_description) { + s2 = g_strdup (item->title_description); + fix_entities (&s2); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr(s1, "")) { + s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL); + s2 = g_strdup_printf ("%d", get_album_objects_count(s3)); + str_replace (&s1, "", s2, NULL); + g_free (s2); + g_free (s3); + } + if (strstr (s1, "")) { + s2 = g_strconcat (THUMBNAIL_DIR, "/", thumb, NULL); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr (s1, "")) + str_replace (&s1, "", img_src, NULL); + break; + + case INDEX_ITEM_TYPE_SEPARATOR: + s1 = strdup (buf_img_separator); + if (strstr (s1, "") && item->title) { + s2 = g_strdup (item->title); + fix_entities (&s2); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + break; } - if (strstr (s1, "")) - str_replace (&s1, "", img_src, NULL); - #ifdef __DEBUG_ALL__ printf("***** %s ******\n", s1); @@ -485,6 +529,7 @@ write_html_album (TGallerySetup *setup, free (buffer); free (buf_img_list_landscape); free (buf_img_list_portrait); + free (buf_img_separator); free (buf_go_up_string); return res; } @@ -518,9 +563,10 @@ write_html_image (TGallerySetup *setup, gboolean in_img_fullsize_link; TExifData *exif; unsigned long img_big_w, img_big_h, img_orig_w, img_orig_h; - unsigned int item_index; + unsigned int item_index, real_item_index, real_total_items; TIndexItem *previous_item; TIndexItem *next_item; + TIndexItem *tmp_item; TAlbum *parent; int i; char *s1, *s2, *s3, *s4; @@ -565,19 +611,30 @@ write_html_image (TGallerySetup *setup, /* Get our index in the album */ item_index = 0; - for (i = 0; i < parent_items->items->len; i++) - if (g_ptr_array_index (parent_items->items, i) == item) { - item_index = i + 1; - break; + real_item_index = 0; + real_total_items = 0; + for (i = 0; i < parent_items->items->len; i++) { + tmp_item = g_ptr_array_index (parent_items->items, i); + if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE) { + if (! item_index) real_item_index++; + real_total_items++; } + if (tmp_item == item) + item_index = i + 1; + } /* Get previous and next items */ previous_item = NULL; next_item = NULL; - if (item_index > 1) - previous_item = g_ptr_array_index (parent_items->items, item_index - 2); - if (item_index < parent_items->items->len) - next_item = g_ptr_array_index (parent_items->items, item_index); + + for (i = item_index - 2; i >= 0 && (previous_item == NULL || previous_item->type != INDEX_ITEM_TYPE_PICTURE); i--) + previous_item = g_ptr_array_index (parent_items->items, i); + if (previous_item && previous_item->type != INDEX_ITEM_TYPE_PICTURE) + previous_item = NULL; + for (i = item_index; item_index < parent_items->items->len && (next_item == NULL || next_item->type != INDEX_ITEM_TYPE_PICTURE); i++) + next_item = g_ptr_array_index (parent_items->items, i); + if (next_item && next_item->type != INDEX_ITEM_TYPE_PICTURE) + next_item = NULL; /* Read through the template and replace placeholders with real data */ @@ -624,12 +681,12 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", parent_items->items->len); + s1 = g_strdup_printf ("%d", real_total_items); str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", item_index); + s1 = g_strdup_printf ("%d", real_item_index); str_replace(&b, "", s1, NULL); g_free (s1); } @@ -912,7 +969,7 @@ build_tree (TGallerySetup *setup, /* Prepare target preview and orig directories */ if (items->type == GALLERY_TYPE_ALBUM) { - res = TRUE; + res = TRUE; img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); if (access (img_big_dir, R_OK | W_OK | X_OK)) @@ -966,11 +1023,13 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "build_tree: error getting item %d\n", i); continue; } - s1 = g_strconcat (src_tree, "/", item->path, "/", NULL); - s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL); - build_tree (setup, s1, s2, items); - g_free (s1); - g_free (s2); + if (item->type == INDEX_ITEM_TYPE_PICTURE) { + s1 = g_strconcat (src_tree, "/", item->path, "/", NULL); + s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL); + build_tree (setup, s1, s2, items); + g_free (s1); + g_free (s2); + } } } } @@ -985,18 +1044,20 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "build_tree: error getting item %d\n", i); continue; } - 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 && 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"); + if (item->type == INDEX_ITEM_TYPE_PICTURE) { + 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 && 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"); + } } } } -- cgit v1.2.3