summaryrefslogtreecommitdiff
path: root/src/setup.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2015-02-01 16:23:30 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2015-02-01 16:23:30 +0100
commitb2d0c4ea27c3885d69c9067b579a075a65ff3834 (patch)
tree0d2ac06f9c32babe69a5b88e8c8604e2f5b4ba91 /src/setup.c
parent97919e37642b851af85c37f751284fd62bd74019 (diff)
downloadcataract-b2d0c4ea27c3885d69c9067b579a075a65ff3834.tar.xz
theming: Introduce image size fallback mode
This changes image size handling a little bit. An optional <fallback size="xxx" /> tag tells the generator to use different image size when an image for the current image size has not been supplied from the album XML file. This is effectively used for the legacy <nofullsize> tag fallback. More generally this is useful for templates showing additional image sizes. Also saves space as images not having the custom size supplied are not generated from the source image.
Diffstat (limited to 'src/setup.c')
-rw-r--r--src/setup.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/setup.c b/src/setup.c
index 9cdf7d5..f0a6f3d 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -233,8 +233,8 @@ parse_design_setup_xml (const gchar *filename)
image_size->quality = xml_file_get_node_attribute_long_with_default (xml, s, "value", -1);
g_free (s);
- s = g_strdup_printf ("/design_setup/image_sizes/size[%d]/no_resize", i + 1);
- image_size->no_resize = xml_file_get_node_present (xml, s);
+ s = g_strdup_printf ("/design_setup/image_sizes/size[%d]/fallback", i + 1);
+ image_size->fallback_size = xml_file_get_node_attribute (xml, s, "size");
g_free (s);
}
@@ -434,8 +434,10 @@ gboolean
validate_design_setup (TGallerySetup *setup)
{
GList *l;
- TImageSize *image_size;
+ TImageSize *image_size, *isi;
TGalleryDesignTheme *theme;
+ GHashTable *fallback_history;
+ gboolean res;
/* check for version match */
if (! SETUP_IS_NATIVE (setup->design)) {
@@ -460,6 +462,28 @@ validate_design_setup (TGallerySetup *setup)
fprintf (stderr, "design validation warning: image size %s defined with zero sized element\n", image_size->name);
continue;
}
+ if (image_size->fallback_size != NULL && lookup_image_size_for_name (setup, image_size->fallback_size) == NULL) {
+ fprintf (stderr, "design validation error: specified \"%s\" fallback image size not found\n", image_size->fallback_size);
+ return FALSE;
+ }
+ if (image_size->fallback_size != NULL) {
+ fallback_history = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ isi = image_size;
+ res = TRUE;
+ while (isi != NULL) {
+ if (g_hash_table_lookup (fallback_history, isi->name)) {
+ res = FALSE;
+ break;
+ }
+ g_hash_table_insert (fallback_history, g_strdup (isi->name), (gpointer) 0x1);
+ isi = lookup_image_size_for_name (setup, isi->fallback_size);
+ }
+ g_hash_table_unref (fallback_history);
+ if (! res) {
+ fprintf (stderr, "design validation error: the fallback path for the \"%s\" image size leads to an endless loop\n", image_size->name);
+ return FALSE;
+ }
+ }
}
/* validate themes */
@@ -577,6 +601,7 @@ free_image_size_data (TImageSize *image_size)
if (image_size) {
g_free (image_size->name);
g_free (image_size->tagname);
+ g_free (image_size->fallback_size);
g_free (image_size);
}
}