summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/setup.c37
-rw-r--r--src/xml-parser.c10
-rw-r--r--src/xml-parser.h1
3 files changed, 26 insertions, 22 deletions
diff --git a/src/setup.c b/src/setup.c
index 21ae26d..6cc9ed6 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -49,7 +49,7 @@ find_setup_xml ()
setup = NULL;
cwd = g_get_current_dir ();
- pth = g_strconcat (cwd, "/", SETUP_XML, NULL);
+ pth = g_build_filename (cwd, SETUP_XML, NULL);
g_free (cwd);
if (g_access (pth, R_OK) == 0)
@@ -57,14 +57,14 @@ find_setup_xml ()
g_free (pth);
if (! setup) {
- pth = g_strconcat (g_getenv ("HOME"), "/.cgg/", SETUP_XML, NULL);
+ pth = g_build_filename (g_getenv ("HOME"), ".cgg", SETUP_XML, NULL);
if (g_access (pth, R_OK) == 0)
setup = parse_setup_xml (pth);
g_free (pth);
}
if (! setup) {
- pth = g_strconcat (DATADIR, "/cgg/", SETUP_XML, NULL);
+ pth = g_build_filename (DATADIR, "cgg", SETUP_XML, NULL);
if (g_access (pth, R_OK) == 0)
setup = parse_setup_xml (pth);
g_free (pth);
@@ -88,7 +88,6 @@ parse_setup_xml (const gchar *filename)
if (xml == NULL)
return NULL;
- /* initialize data struct */
setup = g_malloc0 (sizeof (TGallerySetup));
setup->setup_xml_path = g_strdup (filename);
@@ -102,22 +101,16 @@ parse_setup_xml (const gchar *filename)
g_free (s);
}
setup->support_files_use_common_root = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/templates/support_files_use_common_root", "value", FALSE);
- setup->index_file_name = xml_file_get_node_value (xml, "/gallery_setup/templates/index_file/text()");
- if (setup->index_file_name == NULL || strlen (setup->index_file_name) == 0)
- setup->index_file_name = g_strdup (DEFAULT_INDEX_FILENAME);
-
- setup->thumbnail_dir = xml_file_get_node_value (xml, "/gallery_setup/images/thumbnail_dir/text()");
- if (setup->thumbnail_dir == NULL || strlen (setup->thumbnail_dir) == 0)
- setup->thumbnail_dir = g_strdup (DEFAULT_THUMBNAIL_DIR);
- setup->img_big_dir = xml_file_get_node_value (xml, "/gallery_setup/images/preview_dir/text()");
- if (setup->img_big_dir == NULL || strlen (setup->img_big_dir) == 0)
- setup->img_big_dir = g_strdup (DEFAULT_IMG_BIG_DIR);
- setup->img_orig_dir = xml_file_get_node_value (xml, "/gallery_setup/images/original_dir/text()");
- if (setup->img_orig_dir == NULL || strlen (setup->img_orig_dir) == 0)
- setup->img_orig_dir = g_strdup (DEFAULT_IMG_ORIG_DIR);
- setup->thumbnail_name_format = xml_file_get_node_value (xml, "/gallery_setup/images/thumbnail_name_format/text()");
- if (setup->thumbnail_name_format == NULL || strlen (setup->thumbnail_name_format) == 0 || strstr (setup->thumbnail_name_format, "%s") == NULL)
+ setup->index_file_name = xml_file_get_node_value_with_default (xml, "/gallery_setup/templates/index_file/text()", DEFAULT_INDEX_FILENAME);
+
+ setup->thumbnail_dir = xml_file_get_node_value_with_default (xml, "/gallery_setup/images/thumbnail_dir/text()", DEFAULT_THUMBNAIL_DIR);
+ setup->img_big_dir = xml_file_get_node_value_with_default (xml, "/gallery_setup/images/preview_dir/text()", DEFAULT_IMG_BIG_DIR);
+ setup->img_orig_dir = xml_file_get_node_value_with_default (xml, "/gallery_setup/images/original_dir/text()", DEFAULT_IMG_ORIG_DIR);
+ setup->thumbnail_name_format = xml_file_get_node_value_with_default (xml, "/gallery_setup/images/thumbnail_name_format/text()", DEFAULT_THUMBNAIL_NAME_FORMAT);
+ if (strstr (setup->thumbnail_name_format, "%s") == NULL) {
+ g_free (setup->thumbnail_name_format);
setup->thumbnail_name_format = g_strdup (DEFAULT_THUMBNAIL_NAME_FORMAT);
+ }
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);
@@ -177,7 +170,7 @@ test_tmpl_access (const gchar *dir, const gchar *path)
gchar *s;
int b;
- s = g_strconcat (dir, "/", path, NULL);
+ s = g_build_filename (dir, path, NULL);
b = access (s, R_OK);
g_free (s);
return b;
@@ -203,10 +196,10 @@ find_templates_directory (TGallerySetup *setup)
if (IS_DIR_SEP (*setup->templates_path)) {
if (! test_tmpl_files (setup->templates_path, setup))
- return g_strdup (setup->templates_path);
+ return g_strdup (setup->templates_path);
} else {
base_dir = g_path_get_dirname (setup->setup_xml_path);
- pth = g_strconcat (base_dir, "/", setup->templates_path, NULL);
+ pth = g_build_path (G_DIR_SEPARATOR_S, base_dir, setup->templates_path, NULL);
g_free (base_dir);
if (! test_tmpl_files (pth, setup))
diff --git a/src/xml-parser.c b/src/xml-parser.c
index 3eae5b1..84cc204 100644
--- a/src/xml-parser.c
+++ b/src/xml-parser.c
@@ -152,6 +152,16 @@ xml_file_get_node_value (TXMLFile *file, const gchar *x_path)
return val;
}
+gchar *
+xml_file_get_node_value_with_default (TXMLFile *file, const gchar *x_path, const gchar *_default)
+{
+ gchar *s;
+
+ s = xml_file_get_node_value (file, x_path);
+
+ return s ? s : g_strdup (_default);
+}
+
/*
* xml_file_get_node_attribute: retrieve attribute value from XPath node
diff --git a/src/xml-parser.h b/src/xml-parser.h
index 77900e6..f6f6c7c 100644
--- a/src/xml-parser.h
+++ b/src/xml-parser.h
@@ -53,6 +53,7 @@ gchar * xml_file_get_node_name (TXMLFile *file, const gchar *x_path);
* - otherwise please use [0], [1] etc. quantificators
*/
gchar * xml_file_get_node_value (TXMLFile *file, const gchar *x_path);
+gchar * xml_file_get_node_value_with_default (TXMLFile *file, const gchar *x_path, const gchar *_default);
/*
* xml_file_get_node_attribute: retrieve attribute value from XPath node