summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/src/setup.xml10
-rw-r--r--src/generators.c98
-rw-r--r--src/setup.c19
-rw-r--r--src/setup.h3
4 files changed, 57 insertions, 73 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index 12bef08..e456a3c 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -11,9 +11,13 @@
<!-- photo: single photo page -->
<photo>template-view_photo.tmpl</photo>
- <!-- mandatory files used in templates -->
- <styles>styles.css</styles>
- <scripts>scripts-general.js</scripts>
+ <!-- support files for selected theme (templates) -->
+ <!-- should include all used CSS styles, images, scripts... -->
+ <!-- subdirectories are allowed and will be mirrored to destination -->
+ <template_files><![CDATA[
+ styles.css
+ scripts-general.js
+ ]]></template_files>
</templates>
<images>
diff --git a/src/generators.c b/src/generators.c
index 992370a..66ade6c 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -882,6 +882,44 @@ write_html_image (TGallerySetup *setup,
}
+
+static void
+mirror_files (TGallerySetup *setup, char **files, const char *src_tree, const char *dst_dir, const char *label)
+{
+ char **extra;
+ char *s1, *s2, *s3;
+
+ if (files && g_strv_length (files) > 0) {
+ extra = files;
+ if (setup->verbose) printf ("%s", label);
+ 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 (" %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);
+ }
+ extra++;
+ }
+ if (setup->verbose) printf ("\n");
+ }
+}
+
/*
* build_tree: generate complete gallery tree based on source xml files
*
@@ -908,7 +946,6 @@ build_tree (TGallerySetup *setup,
char *imgname;
gboolean res;
int i;
- char **extra;
printf ("*** Entering directory '%s'\n", src_tree);
#ifdef __DEBUG_ALL__
@@ -948,36 +985,8 @@ build_tree (TGallerySetup *setup,
items->parent_index = parent_index;
items->parent_item_index = parent_item_index;
-
/* Copy support files */
- if (setup->verbose) printf ("Writing '%s' ...", setup->styles);
- s1 = g_strconcat (setup->real_templates_dir, "/", setup->styles, NULL);
- s2 = g_strconcat (dst_dir, "/", setup->styles, NULL);
- copy_file (s1, s2);
- g_free (s1);
- g_free (s2);
- if (setup->verbose) printf (" done.\n");
-
- if (setup->verbose) printf ("Writing '%s' ...", setup->scripts);
- s1 = g_strconcat (setup->real_templates_dir, "/", setup->scripts, NULL);
- s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL);
- copy_file (s1, s2);
- g_free (s1);
- g_free (s2);
- if (setup->verbose) printf (" done.\n");
-
- if (setup->favicon_file && strlen (setup->favicon_file) > 0) {
- if (setup->verbose) printf ("Writing '%s' ...", setup->favicon_file);
- s3 = g_path_get_dirname (setup->setup_xml_path);
- s1 = g_strconcat (s3, "/", setup->favicon_file, NULL);
- s2 = g_strconcat (dst_dir, "/", setup->favicon_file, NULL);
- copy_file (s1, s2);
- g_free (s1);
- g_free (s2);
- g_free (s3);
- if (setup->verbose) printf (" done.\n");
- }
-
+ mirror_files (setup, setup->template_files, setup->real_templates_dir, dst_dir, "Copying template files: ");
/* Prepare target thumbnail directory */
thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL);
@@ -1090,34 +1099,7 @@ 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++;
- }
- }
+ mirror_files (setup, items->extra_files, src_tree, dst_dir, "Copying extra files: ");
printf ("*** Leaving directory '%s'\n", src_tree);
free_album_data (items);
diff --git a/src/setup.c b/src/setup.c
index 31bd5ca..68c32b5 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -92,8 +92,12 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
setup->template_index = xml_file_get_node_value (xml, "/gallery_setup/templates/index/text()");
setup->template_album = xml_file_get_node_value (xml, "/gallery_setup/templates/album/text()");
setup->template_photo = xml_file_get_node_value (xml, "/gallery_setup/templates/photo/text()");
- setup->styles = xml_file_get_node_value (xml, "/gallery_setup/templates/styles/text()");
- setup->scripts = xml_file_get_node_value (xml, "/gallery_setup/templates/scripts/text()");
+ s = xml_file_get_node_value (xml, "/gallery_setup/templates/template_files/text()");
+ if (s) {
+ setup->template_files = g_strsplit (s, "\n", -1);
+ free (s);
+ }
+
setup->thumbnail_landscape_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_w", 0);
setup->thumbnail_landscape_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_h", 0);
setup->thumbnail_portrait_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "portrait_w", 0);
@@ -141,8 +145,6 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
printf("setup: template_index = '%s'\n", setup->template_index);
printf("setup: template_album = '%s'\n", setup->template_album);
printf("setup: template_photo = '%s'\n", setup->template_photo);
- printf("setup: styles = '%s'\n", setup->styles);
- printf("setup: scripts = '%s'\n", setup->scripts);
printf("setup: thumbnail_quality = %d\n", setup->thumbnail_quality);
printf("setup: thumbnail_landscape_width = %ld\n", setup->thumbnail_landscape_width);
printf("setup: thumbnail_landscape_height = %ld\n", setup->thumbnail_landscape_height);
@@ -184,8 +186,7 @@ int
test_tmpl_files (const char *dir, TGallerySetup *setup)
{
return test_tmpl_access (dir, setup->template_album) | test_tmpl_access (dir, setup->template_photo) |
- test_tmpl_access (dir, setup->template_index) | test_tmpl_access (dir, setup->styles) |
- test_tmpl_access (dir, setup->scripts);
+ test_tmpl_access (dir, setup->template_index);
}
/*
@@ -245,10 +246,8 @@ free_setup_data (TGallerySetup *setup)
free (setup->template_album);
if (setup->template_photo)
free (setup->template_photo);
- if (setup->styles)
- free (setup->styles);
- if (setup->scripts)
- free (setup->scripts);
+ if (setup->template_files)
+ g_strfreev (setup->template_files);
if (setup->footer)
free (setup->footer);
if (setup->meta_author)
diff --git a/src/setup.h b/src/setup.h
index cba4278..3d2e7cc 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -42,8 +42,7 @@ typedef struct {
char *template_index;
char *template_album;
char *template_photo;
- char *styles;
- char *scripts;
+ char **template_files;
char *footer;
char *meta_author;