summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/src/setup.xml2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cgg.c24
-rw-r--r--src/setup.c110
-rw-r--r--src/setup.h11
-rw-r--r--templates/default.xml2
6 files changed, 142 insertions, 9 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index b240c4a..327659d 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<gallery_setup>
+<gallery_setup version="2.0">
<design>
<!-- path to the design setup xml file -->
<setup_file>../../templates/default.xml</setup_file>
diff --git a/src/Makefile.am b/src/Makefile.am
index 9bd3448..0553245 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,6 @@ cgg_SOURCES = \
xml-parser.h \
$(NULL)
-cgg_LDADD = $(LIBS_LIBS)
+cgg_LDADD = $(LIBS_LIBS) -lm
EXTRA_DIST = cgg-dirgen
diff --git a/src/cgg.c b/src/cgg.c
index 2891f6f..ea493ac 100644
--- a/src/cgg.c
+++ b/src/cgg.c
@@ -151,11 +151,23 @@ main (int argc, char* argv[])
fprintf (stderr, "error: could not parse gallery settings file\n");
return -2;
}
- setup->design = parse_design_setup_xml (setup->design_setup_file);
- if (! setup->design) {
- fprintf (stderr, "error: could not parse design setup file\n");
- return -6;
+
+ if (SETUP_IS_LEGACY (setup)) {
+ /* Design legacy mode */
+ setup->design = makeup_legacy_design (setup->setup_xml_path);
+ if (! setup->design) {
+ fprintf (stderr, "error: could not parse design from legacy setup file\n");
+ return -6;
+ }
+ } else {
+ /* Design native mode */
+ setup->design = parse_design_setup_xml (setup->design_setup_file);
+ if (! setup->design) {
+ fprintf (stderr, "error: could not parse design setup file\n");
+ return -6;
+ }
}
+
if (! validate_design_setup (setup->design))
return -7;
@@ -174,6 +186,10 @@ main (int argc, char* argv[])
if (verbose) {
printf ("cgg v%s [%s]\n\n", VERSION, APP_BUILD_DATE);
printf ("Using setup file \"%s\"\n", setup->setup_xml_path);
+ if (SETUP_IS_NEWER (setup))
+ printf ("WARNING: Reported setup.xml version is greater than current cgg engine, consider upgrading or expect random issues\n");
+ if (SETUP_IS_LEGACY (setup))
+ printf ("WARNING: Parsing setup.xml in legacy mode\n");
}
/* Setup number of threads */
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);
diff --git a/src/setup.h b/src/setup.h
index 1fe6a53..7ce2cd1 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
#define TARGET_IMAGE_DIR_PREFIX "_"
#define SETUP_XML "setup.xml"
+#define SETUP_NATIVE_VERSION 200 /* 2.0 */
/* forward declaration */
@@ -46,6 +47,7 @@ typedef struct {
gboolean override_nofullsize;
gboolean strip_unused_tags;
gchar *setup_xml_path;
+ gint version;
TGalleryDesign *design;
@@ -118,12 +120,16 @@ typedef struct {
} TGalleryDesignTheme;
struct TGalleryDesign {
+ gint version;
GList *image_sizes;
GList *themes;
gchar **supplemental_files;
};
+#define SETUP_IS_LEGACY(s) s->version < SETUP_NATIVE_VERSION
+#define SETUP_IS_NATIVE(s) s->version == SETUP_NATIVE_VERSION
+#define SETUP_IS_NEWER(s) s->version > SETUP_NATIVE_VERSION
/*
* find_setup_xml: try to find setup.xml in standard paths
@@ -141,6 +147,11 @@ TGallerySetup * parse_setup_xml (const gchar *filename);
TGalleryDesign * parse_design_setup_xml (const gchar *filename);
/*
+ * makeup_legacy_design: create design using legacy setup.xml file
+ */
+TGalleryDesign * makeup_legacy_design (const gchar *filename);
+
+/*
* validate_design_setup: validate design.xml file setup
*/
gboolean validate_design_setup (TGalleryDesign *design);
diff --git a/templates/default.xml b/templates/default.xml
index 7c37b97..4bbbb6c 100644
--- a/templates/default.xml
+++ b/templates/default.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<design_setup>
+<design_setup version="2.0">
<!-- image size definitions -->
<image_sizes>