diff options
Diffstat (limited to 'src/setup.c')
| -rw-r--r-- | src/setup.c | 136 |
1 files changed, 95 insertions, 41 deletions
diff --git a/src/setup.c b/src/setup.c index e0741c5..637a1b3 100644 --- a/src/setup.c +++ b/src/setup.c @@ -82,7 +82,6 @@ TGallerySetup * parse_setup_xml (const gchar *filename) { TXMLFile *xml; - gchar *s; TGallerySetup *setup; xml = xml_parser_load (filename); @@ -106,13 +105,6 @@ parse_setup_xml (const gchar *filename) setup->nofullsize = xml_file_get_node_present (xml, "/gallery_setup/images/nofullsize"); setup->autorotate = xml_file_get_node_attribute_boolean_with_default (xml, "/gallery_setup/images/autorotate", "value", TRUE); - s = xml_file_get_node_attribute (xml, "/gallery_setup/images/squared_thumbnails", "type"); - if (s && g_ascii_strcasecmp (s, "simple") == 0) - setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_SIMPLE; - else - setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_NONE; - g_free (s); - /* meta section */ setup->meta_author = xml_file_get_node_value (xml, "/gallery_setup/meta/author/text()"); setup->meta_author_email = xml_file_get_node_value (xml, "/gallery_setup/meta/author_email/text()"); @@ -184,11 +176,33 @@ parse_design_setup_xml (const gchar *filename) /* image_sizes section */ count = xml_file_node_get_children_count (xml, "/design_setup/image_sizes/size"); for (i = 0; i < count; i++) { + s = g_strdup_printf ("/design_setup/image_sizes/size[%d]", i + 1); + s2 = xml_file_get_node_attribute (xml, s, "name"); + if (s2 == NULL || strlen (s2) == 0) { + fprintf (stderr, "design setup error: image size #%d defined with no name, ignoring\n", i + 1); + g_free (s); + g_free (s2); + continue; + } + image_size = g_malloc0 (sizeof (TImageSize)); design->image_sizes = g_list_append (design->image_sizes, image_size); - s = g_strdup_printf ("/design_setup/image_sizes/size[%d]", i + 1); - image_size->name = xml_file_get_node_attribute (xml, s, "name"); + image_size->name = s2; + s2 = xml_file_get_node_attribute (xml, s, "type"); + if (s2 && g_ascii_strcasecmp (s2, "thumbnail") == 0) + image_size->is_thumbnail = TRUE; + g_free (s2); + if (image_size->is_thumbnail) { + s2 = xml_file_get_node_attribute (xml, s, "style"); + if (s2 && g_ascii_strcasecmp (s2, "squared") == 0) + image_size->squared_thumb = TRUE; + g_free (s2); + } + 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); g_free (s); s = g_strdup_printf ("/design_setup/image_sizes/size[%d]/landscape", i + 1); @@ -231,6 +245,9 @@ parse_design_setup_xml (const gchar *filename) s = g_strdup_printf ("/design_setup/theme[%d]/index/target_filename/text()", i + 1); theme->index_filename = xml_file_get_node_value_with_default (xml, s, DEFAULT_INDEX_FILENAME); g_free (s); + s = g_strdup_printf ("/design_setup/theme[%d]/index/thumbnail_size/text()", i + 1); + theme->index_thumb_size = xml_file_get_node_value (xml, s); + g_free (s); s = g_strdup_printf ("/design_setup/theme[%d]/album/template/text()", i + 1); theme->album_template = xml_file_get_node_value (xml, s); @@ -241,6 +258,9 @@ parse_design_setup_xml (const gchar *filename) s = g_strdup_printf ("/design_setup/theme[%d]/album/picture_size/text()", i + 1); theme->album_image_size = xml_file_get_node_value (xml, s); g_free (s); + s = g_strdup_printf ("/design_setup/theme[%d]/album/thumbnail_size/text()", i + 1); + theme->album_thumb_size = xml_file_get_node_value (xml, s); + g_free (s); s = g_strdup_printf ("/design_setup/theme[%d]/album/protected_thumbnail/text()", i + 1); theme->album_protected_thumbnail = xml_file_get_node_value (xml, s); g_free (s); @@ -292,6 +312,7 @@ makeup_legacy_design (const gchar *filename) TGalleryDesign *design; TImageSize *image_size; TGalleryDesignTheme *theme; + gboolean squared_thumbs; int i; const gchar * image_sizes[3] = { "thumbnail", "preview", "original" }; @@ -307,6 +328,12 @@ makeup_legacy_design (const gchar *filename) g_free (s); } + squared_thumbs = FALSE; + s = xml_file_get_node_attribute (xml, "/gallery_setup/images/squared_thumbnails", "type"); + if (s && g_ascii_strcasecmp (s, "simple") == 0) + squared_thumbs = TRUE; + g_free (s); + /* image_sizes section */ for (i = 0; i < G_N_ELEMENTS (image_sizes); i++) { image_size = g_malloc0 (sizeof (TImageSize)); @@ -318,7 +345,9 @@ makeup_legacy_design (const gchar *filename) image_size->portrait_height = xml_file_get_node_attribute_long_with_default (xml, s, "portrait_h", 0); image_size->square_size = xml_file_get_node_attribute_long_with_default (xml, s, "square", 0); image_size->quality = xml_file_get_node_attribute_long_with_default (xml, s, "quality", -1); - image_size->no_resize = (i == G_N_ELEMENTS (image_sizes) - 1); + image_size->no_resize = (i != 0); + image_size->is_thumbnail = (i == 0); + image_size->squared_thumb = (i == 0) && squared_thumbs; g_free (s); design->image_sizes = g_list_append (design->image_sizes, image_size); } @@ -333,6 +362,7 @@ makeup_legacy_design (const gchar *filename) theme->index_template = g_strdup ("template_index.html"); } theme->index_filename = xml_file_get_node_value_with_default (xml, "/gallery_setup/templates/index_file/text()", DEFAULT_INDEX_FILENAME); + theme->index_thumb_size = g_strdup (image_sizes[0]); theme->album_template = xml_file_get_node_value (xml, "/gallery_setup/templates/album/text()"); if (g_strcmp0 (theme->album_template, "template-album.tmpl") == 0) { @@ -341,6 +371,7 @@ makeup_legacy_design (const gchar *filename) } theme->album_filename = xml_file_get_node_value_with_default (xml, "/gallery_setup/templates/index_file/text()", DEFAULT_INDEX_FILENAME); theme->album_image_size = g_strdup (image_sizes[1]); + theme->album_thumb_size = g_strdup (image_sizes[0]); theme->album_protected_thumbnail = NULL; theme->picture_template = xml_file_get_node_value (xml, "/gallery_setup/templates/photo/text()"); @@ -365,69 +396,68 @@ makeup_legacy_design (const gchar *filename) return design; } - -static gboolean -lookup_image_size (TGalleryDesign *design, const gchar *image_size_name) +/* + * lookup_image_size_for_name: looks up an image size record for given image size name + */ +TImageSize * +lookup_image_size_for_name (TGallerySetup *setup, const gchar *name) { GList *l; TImageSize *image_size; - g_return_val_if_fail (image_size_name != NULL, FALSE); - g_return_val_if_fail (strlen (image_size_name) > 0, FALSE); - - for (l = g_list_first (design->image_sizes); l; l = g_list_next (l)) { + for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) { image_size = l->data; g_assert (image_size != NULL); - if (image_size->name == NULL || strlen (image_size->name) == 0) { - fprintf (stderr, "design validation warning: image size %p defined with no name\n", image_size); - continue; - } - if (image_size->landscape_width <= 0 || image_size->landscape_height <= 0 || - image_size->portrait_width <= 0 || image_size->portrait_height <= 0) { - fprintf (stderr, "design validation warning: image size %s defined with zero sized element\n", image_size->name); - continue; - } - if (g_ascii_strcasecmp (image_size_name, image_size->name) == 0) - return TRUE; + if (g_ascii_strcasecmp (name, image_size->name) == 0) + return image_size; } - - return FALSE; + return NULL; } /* * validate_design_setup: validate design.xml file setup */ gboolean -validate_design_setup (TGalleryDesign *design) +validate_design_setup (TGallerySetup *setup) { GList *l; + TImageSize *image_size; TGalleryDesignTheme *theme; /* check for version match */ - if (! SETUP_IS_NATIVE (design)) { + if (! SETUP_IS_NATIVE (setup->design)) { fprintf (stderr, "design validation error: version mismatch\n"); return FALSE; } /* validate sizes */ - if (g_list_length (design->image_sizes) == 0) { + if (g_list_length (setup->design->image_sizes) == 0) { fprintf (stderr, "design validation error: no image size defined\n"); return FALSE; } - if (! lookup_image_size (design, "original")) { - fprintf (stderr, "design validation error: mandatory \"original\" image size not defined\n"); - return FALSE; + if (lookup_image_size_for_name (setup, "original") == NULL) { + fprintf (stderr, "design validation error: mandatory \"original\" image size not defined\n"); + return FALSE; + } + for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) { + image_size = l->data; + g_assert (image_size != NULL); + if (image_size->landscape_width <= 0 || image_size->landscape_height <= 0 || + image_size->portrait_width <= 0 || image_size->portrait_height <= 0) { + fprintf (stderr, "design validation warning: image size %s defined with zero sized element\n", image_size->name); + continue; } + } /* validate themes */ - if (g_list_length (design->themes) == 0) { + if (g_list_length (setup->design->themes) == 0) { fprintf (stderr, "design validation error: no theme defined\n"); return FALSE; } - for (l = g_list_first (design->themes); l; l = g_list_next (l)) { + for (l = g_list_first (setup->design->themes); l; l = g_list_next (l)) { theme = l->data; g_assert (theme != NULL); - if (theme->album_image_size && ! lookup_image_size (design, theme->album_image_size)) { + if (theme->album_image_size && lookup_image_size_for_name (setup, theme->album_image_size) == NULL) { fprintf (stderr, "design validation error: theme-defined image size '%s' not found\n", theme->album_image_size); return FALSE; } @@ -435,10 +465,32 @@ validate_design_setup (TGalleryDesign *design) fprintf (stderr, "design validation error: theme does not define mandatory picture size argument\n"); return FALSE; } - if (! lookup_image_size (design, theme->picture_image_size)) { + if (lookup_image_size_for_name (setup, theme->picture_image_size) == NULL) { fprintf (stderr, "design validation error: theme-defined image size '%s' not found\n", theme->picture_image_size); return FALSE; } + if (theme->album_thumb_size) { + image_size = lookup_image_size_for_name (setup, theme->album_thumb_size); + if (image_size == NULL) { + fprintf (stderr, "design validation error: referenced thumbnail image size '%s' not found\n", theme->album_thumb_size); + return FALSE; + } + if (! image_size->is_thumbnail) { + fprintf (stderr, "design validation error: referenced thumbnail image size '%s' is not of type \"thumbnail\"\n", theme->album_thumb_size); + return FALSE; + } + } + if (theme->index_thumb_size) { + image_size = lookup_image_size_for_name (setup, theme->index_thumb_size); + if (image_size == NULL) { + fprintf (stderr, "design validation error: referenced thumbnail image size '%s' not found\n", theme->index_thumb_size); + return FALSE; + } + if (! image_size->is_thumbnail) { + fprintf (stderr, "design validation error: referenced thumbnail image size '%s' is not of type \"thumbnail\"\n", theme->index_thumb_size); + return FALSE; + } + } } return TRUE; @@ -525,9 +577,11 @@ free_design_theme_data (TGalleryDesignTheme *theme) if (theme) { g_free (theme->index_template); g_free (theme->index_filename); + g_free (theme->index_thumb_size); g_free (theme->album_template); g_free (theme->album_filename); g_free (theme->album_image_size); + g_free (theme->album_thumb_size); g_free (theme->album_protected_thumbnail); g_free (theme->picture_template); g_free (theme->picture_filename); |
