diff options
Diffstat (limited to 'src/setup.c')
| -rw-r--r-- | src/setup.c | 110 |
1 files changed, 108 insertions, 2 deletions
diff --git a/src/setup.c b/src/setup.c index 21ee839..bb69993 100644 --- a/src/setup.c +++ b/src/setup.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <errno.h> #include <unistd.h> +#include <math.h> #include <glib.h> #include <glib/gstdio.h> @@ -85,6 +86,7 @@ parse_setup_xml (const gchar *filename) setup = g_malloc0 (sizeof (TGallerySetup)); setup->setup_xml_path = g_strdup (filename); + setup->version = nearbyint (xml_file_get_node_attribute_double (xml, "/gallery_setup", "version", -1) * 100); /* design section */ setup->design_setup_file = xml_file_get_node_value (xml, "/gallery_setup/design/setup_file/text()"); @@ -132,6 +134,13 @@ parse_setup_xml (const gchar *filename) /* footer section */ setup->footer = xml_file_get_node_value (xml, "/gallery_setup/footer/text()"); + /* legacy mode */ + if (SETUP_IS_LEGACY (setup)) { + setup->design_setup_file = xml_file_get_node_value (xml, "/gallery_setup/templates/path/text()"); + setup->supplemental_files_use_common_root = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/templates/support_files_use_common_root", "value", FALSE); + setup->location_base_url = xml_file_get_node_value (xml, "/gallery_setup/feed/base_url/text()"); + } + xml_parser_free (xml); return setup; } @@ -158,6 +167,7 @@ parse_design_setup_xml (const gchar *filename) return NULL; design = g_malloc0 (sizeof (TGalleryDesign)); + design->version = nearbyint (xml_file_get_node_attribute_double (xml, "/design_setup", "version", -1) * 100); s2 = xml_file_get_node_value (xml, "/design_setup/supplemental_files/text()"); if (s2) { @@ -266,6 +276,90 @@ parse_design_setup_xml (const gchar *filename) return design; } +/* + * makeup_legacy_design: create design using legacy setup.xml file + */ +TGalleryDesign * +makeup_legacy_design (const gchar *filename) +{ + TXMLFile *xml; + gchar *s; + TGalleryDesign *design; + TImageSize *image_size; + TGalleryDesignTheme *theme; + int i; + const gchar * image_sizes[3] = { "thumbnail", "preview", "original" }; + + xml = xml_parser_load (filename); + if (xml == NULL) + return NULL; + + design = g_malloc0 (sizeof (TGalleryDesign)); + + s = xml_file_get_node_value (xml, "/gallery_setup/templates/template_files/text()"); + if (s) { + design->supplemental_files = g_strsplit (s, "\n", -1); + g_free (s); + } + + /* image_sizes section */ + for (i = 0; i < G_N_ELEMENTS (image_sizes); i++) { + image_size = g_malloc0 (sizeof (TImageSize)); + image_size->name = g_strdup (image_sizes[i]); + s = g_strdup_printf ("/gallery_setup/images/%s", image_sizes[i]); + image_size->landscape_width = xml_file_get_node_attribute_long (xml, s, "landscape_w", 0); + image_size->landscape_height = xml_file_get_node_attribute_long (xml, s, "landscape_h", 0); + image_size->portrait_width = xml_file_get_node_attribute_long (xml, s, "portrait_w", 0); + image_size->portrait_height = xml_file_get_node_attribute_long (xml, s, "portrait_h", 0); + image_size->square_size = xml_file_get_node_attribute_long (xml, s, "square", 0); + image_size->quality = xml_file_get_node_attribute_long (xml, s, "quality", -1); + image_size->no_resize = (i == G_N_ELEMENTS (image_sizes) - 1); + g_free (s); + design->image_sizes = g_list_append (design->image_sizes, image_size); + } + + /* theme section */ + theme = g_malloc0 (sizeof (TGalleryDesignTheme)); + theme->enabled = TRUE; + + theme->index_template = xml_file_get_node_value (xml, "/gallery_setup/templates/index/text()"); + if (g_strcmp0 (theme->index_template, "template-index.tmpl") == 0) { + g_free (theme->index_template); + 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->album_template = xml_file_get_node_value (xml, "/gallery_setup/templates/album/text()"); + if (g_strcmp0 (theme->album_template, "template-album.tmpl") == 0) { + g_free (theme->album_template); + theme->album_template = g_strdup ("template_album.html"); + } + 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_protected_thumbnail = NULL; + + theme->picture_template = xml_file_get_node_value (xml, "/gallery_setup/templates/photo/text()"); + if (g_strcmp0 (theme->picture_template, "template-view_photo.tmpl") == 0) { + g_free (theme->picture_template); + theme->picture_template = g_strdup ("template_picture.html"); + } + theme->picture_filename = g_strdup ("%s.html"); + theme->picture_image_size = g_strdup (image_sizes[1]); + + theme->defines = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + if (xml_file_get_node_attribute_boolean (xml, "/gallery_setup/navigation/show_go_up", "value", TRUE)) + g_hash_table_replace (theme->defines, g_strdup ("SHOW_GO_UP"), g_strdup ("")); + if (xml_file_get_node_attribute_boolean (xml, "/gallery_setup/navigation/show_exif_table", "value", TRUE)) + g_hash_table_replace (theme->defines, g_strdup ("SHOW_EXIF_TABLE"), g_strdup ("")); + s = xml_file_get_node_attribute (xml, "/gallery_setup/images/border", "style"); + g_hash_table_replace (theme->defines, g_strdup ("BORDER_STYLE"), s ? s : g_strdup ("border_single")); + + design->themes = g_list_append (design->themes, theme); + + xml_parser_free (xml); + return design; +} + static gboolean lookup_image_size (TGalleryDesign *design, const gchar *image_size_name) @@ -304,6 +398,12 @@ validate_design_setup (TGalleryDesign *design) GList *l; TGalleryDesignTheme *theme; + /* check for version match */ + if (! SETUP_IS_NATIVE (design)) { + fprintf (stderr, "design validation error: version mismatch\n"); + return FALSE; + } + /* validate sizes */ if (g_list_length (design->image_sizes) == 0) { fprintf (stderr, "design validation error: no image size defined\n"); @@ -348,12 +448,18 @@ find_design_directory (TGallerySetup *setup) gchar *pth = NULL; if (IS_DIR_SEP (*setup->design_setup_file)) { - pth = g_path_get_dirname (setup->design_setup_file); + if (SETUP_IS_LEGACY (setup)) + pth = g_strdup (setup->design_setup_file); + else + pth = g_path_get_dirname (setup->design_setup_file); if (g_access (pth, R_OK) == 0) return pth; } else { base_dir = g_path_get_dirname (setup->setup_xml_path); - base_design_dir = g_path_get_dirname (setup->design_setup_file); + if (SETUP_IS_LEGACY (setup)) + base_design_dir = g_strdup (setup->design_setup_file); + else + base_design_dir = g_path_get_dirname (setup->design_setup_file); pth = g_build_path (G_DIR_SEPARATOR_S, base_dir, base_design_dir, NULL); g_free (base_dir); g_free (base_design_dir); |
