From 895513e06150927cf5db6600ca164bdae15d4d75 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 7 Mar 2009 15:12:50 +0100 Subject: Support for extra (enclosed) files in albums [code] --- sample/src/index.xml | 5 +++++ src/generators.c | 41 +++++++++++++++++++++++++++++++++++++---- src/items.c | 8 ++++++++ src/items.h | 1 + 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/sample/src/index.xml b/sample/src/index.xml index 80f6145..07881d5 100644 --- a/sample/src/index.xml +++ b/sample/src/index.xml @@ -45,5 +45,10 @@ ahoj! xx]]> + + Extra files + Supplemental files distributed within the album + + diff --git a/src/generators.c b/src/generators.c index b4bdf9c..e07a880 100644 --- a/src/generators.c +++ b/src/generators.c @@ -33,6 +33,8 @@ #include "generators-replace-table.h" +#define DEFAULT_DATA_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH + /* * generate_image: auxiliary function for write_html_album * - img_src and thumb should be freed afterwards @@ -890,6 +892,7 @@ build_tree (TGallerySetup *setup, char *imgname; gboolean res; int i; + char **extra; printf ("*** Entering directory '%s'\n", src_tree); #ifdef __DEBUG_ALL__ @@ -902,7 +905,7 @@ build_tree (TGallerySetup *setup, return FALSE; } if (access (dst_dir, R_OK | W_OK | X_OK)) { - if (g_mkdir_with_parents (dst_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (dst_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error creating destination directory: %s\n", strerror (errno)); return FALSE; } @@ -951,7 +954,7 @@ build_tree (TGallerySetup *setup, /* Prepare target thumbnail directory */ thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); if (access (thumb_dir, R_OK | W_OK | X_OK)) - if (g_mkdir_with_parents (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (thumb_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); free_album_data (items); @@ -966,12 +969,12 @@ build_tree (TGallerySetup *setup, 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)) - if (g_mkdir_with_parents (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_big_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target preview directory: %s\n", strerror (errno)); res = FALSE; } if (access (img_orig_dir, R_OK | W_OK | X_OK)) - if (g_mkdir_with_parents (img_orig_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_orig_dir, DEFAULT_DATA_DIR_MODE)) { fprintf (stderr, "error making target full size directory: %s\n", strerror (errno)); res = FALSE; } @@ -1058,6 +1061,36 @@ build_tree (TGallerySetup *setup, } } + /* Copy extra files */ + if (items->extra_files && g_strv_length (items->extra_files) > 0) { + extra = items->extra_files; + while (*extra) { + s1 = g_strstrip (*extra); + if (strlen (s1) > 0) { + /* First create target directory if it doesn't exist */ + s2 = g_strconcat (dst_dir, "/", s1, NULL); + s3 = g_path_get_dirname (s2); + g_free (s2); + if (g_mkdir_with_parents (s3, DEFAULT_DATA_DIR_MODE)) { + fprintf (stderr, "error making target extra directory '%s': %s\n", s3, strerror (errno)); + g_free (s3); + continue; + } + g_free (s3); + + /* Copy the file */ + if (setup->verbose) printf ("Copying extra file '%s' ...", s1); + s2 = g_strconcat (src_tree, "/", s1, NULL); + s3 = g_strconcat (dst_dir, "/", s1, NULL); + copy_file (s2, s3); + g_free (s2); + g_free (s3); + if (setup->verbose) printf (" done.\n"); + } + extra++; + } + } + printf ("*** Leaving directory '%s'\n", src_tree); free_album_data (items); diff --git a/src/items.c b/src/items.c index 986fd6c..5cce7c3 100644 --- a/src/items.c +++ b/src/items.c @@ -75,6 +75,12 @@ parse_album_xml (const char *filename, TAlbum *index) index->title = xml_file_get_node_value (xml, "/gallery/general/title/text()"); index->desc = xml_file_get_node_value (xml, "/gallery/general/description/text()"); index->footnote = xml_file_get_node_value (xml, "/gallery/general/footnote/text()"); + s = xml_file_get_node_value (xml, "/gallery/general/extra_files/text()"); + if (s) { + index->extra_files = g_strsplit (s, "\n", -1); + free (s); + } + index->quality = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "quality", -1); index->landscape_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_w", 0); @@ -237,6 +243,8 @@ free_album_data (TAlbum *album) free (album->meta_description); if (album->meta_keywords) free (album->meta_keywords); + if (album->extra_files) + g_strfreev (album->extra_files); if (album->items) { if (album->items->len > 0) { diff --git a/src/items.h b/src/items.h index 9fd6822..0b053b9 100644 --- a/src/items.h +++ b/src/items.h @@ -53,6 +53,7 @@ typedef struct { char *meta_keywords; gboolean nofullsize; gboolean fullsize; + char **extra_files; } TAlbum; typedef struct { -- cgit v1.2.3