summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2011-01-23 10:56:14 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2011-01-23 10:56:14 +0100
commit7df97fbe8fa93141e7922a95f5ce0f9254bf41ab (patch)
tree84c519692470b7a597f72acc2614d9d85bfa8ff6 /src
parentbb58d822fb517f4a7a242994bbda3693255b2c74 (diff)
downloadcataract-7df97fbe8fa93141e7922a95f5ce0f9254bf41ab.tar.xz
Consolidate paths in a separate struct
This will allow us to pass detailed path info to worker methods. Each path info instance is bound to a currently processed album and directory. Possibly move to struct TItems in the future.
Diffstat (limited to 'src')
-rw-r--r--src/cgg.c10
-rw-r--r--src/generators.c38
-rw-r--r--src/generators.h6
-rw-r--r--src/items.c26
-rw-r--r--src/items.h11
-rw-r--r--src/job-manager.c56
-rw-r--r--src/job-manager.h3
7 files changed, 91 insertions, 59 deletions
diff --git a/src/cgg.c b/src/cgg.c
index c158dfd..f295077 100644
--- a/src/cgg.c
+++ b/src/cgg.c
@@ -108,6 +108,7 @@ main (int argc, char* argv[])
time_t time_start = time (NULL);
time_t time_stop;
gchar *s;
+ TPathInfo *path_info;
/*
* this initialize the library and check potential ABI mismatches
@@ -169,7 +170,14 @@ main (int argc, char* argv[])
setup->verbose = verbose;
setup->update_mode = update;
setup->override_nofullsize = fullsize;
- build_tree (setup, source_dir, dst_dir, NULL, -1, jobs);
+
+ path_info = g_malloc0 (sizeof (TPathInfo));
+ path_info->source_root = g_strdup (source_dir);
+ path_info->src_dir = g_strdup (source_dir);
+ path_info->dest_root = g_strdup (dst_dir);
+ path_info->dest_dir = g_strdup (dst_dir);
+ build_tree (setup, path_info, NULL, -1, jobs);
+ free_path_info (path_info);
/* Write feeds */
if (news_feed) {
diff --git a/src/generators.c b/src/generators.c
index 2cea20a..2329953 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -108,7 +108,7 @@ generate_image (TGallerySetup *setup,
TAlbum *items,
TIndexItem *item,
unsigned int item_index,
- const gchar *dst_dir,
+ TPathInfo *path_info,
gboolean update_when_necessary,
gboolean *thumb_portrait)
{
@@ -133,26 +133,26 @@ generate_image (TGallerySetup *setup,
if (items->type == GALLERY_TYPE_INDEX) {
if (item->thumbnail == NULL || strlen (item->thumbnail) == 0)
return FALSE;
- img_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL);
- thumb_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL);
+ img_src_full = g_strconcat (path_info->src_dir, "/", item->thumbnail, NULL);
+ thumb_src_full = g_strconcat (path_info->src_dir, "/", item->thumbnail, NULL);
}
else
if (items->type == GALLERY_TYPE_ALBUM) {
s1 = (item->path == NULL && item->preview) ? item->preview : item->path;
thumb_src_full = (item->thumbnail) ? item->thumbnail : s1;
- img_src_full = g_strconcat (items->base_dir, "/", s1, NULL);
- thumb_src_full = g_strconcat (items->base_dir, "/", thumb_src_full, NULL);
+ img_src_full = g_strconcat (path_info->src_dir, "/", s1, NULL);
+ thumb_src_full = g_strconcat (path_info->src_dir, "/", thumb_src_full, NULL);
}
/* Make paths */
s1 = item_get_thumbnail_src (setup, items, item, item_index);
- thumb_dst = g_strconcat (dst_dir, "/", setup->thumbnail_dir, "/", s1, NULL);
+ thumb_dst = g_strconcat (path_info->dest_dir, "/", setup->thumbnail_dir, "/", s1, NULL);
g_free (s1);
s1 = item_get_img_src (setup, items, item);
- big_dst = g_strconcat (dst_dir, "/", setup->img_big_dir, "/", s1, NULL);
+ big_dst = g_strconcat (path_info->dest_dir, "/", setup->img_big_dir, "/", s1, NULL);
if (item->force_fullsize || setup->override_nofullsize || (items->fullsize && ! item->force_nofullsize) ||
(! item->force_nofullsize && ! items->nofullsize && ! setup->nofullsize))
- orig_dst = g_strconcat (dst_dir, "/", setup->img_orig_dir, "/", s1, NULL);
+ orig_dst = g_strconcat (path_info->dest_dir, "/", setup->img_orig_dir, "/", s1, NULL);
res = (! update_when_necessary) || needs_update (thumb_src_full, thumb_dst) ||
(items->type == GALLERY_TYPE_ALBUM && (needs_update (img_src_full, big_dst) || (orig_dst && needs_update (img_src_full, orig_dst))));
g_free (s1);
@@ -220,7 +220,7 @@ generate_image (TGallerySetup *setup,
else
{
/* Copy the preview (big) image provided */
- big_src = g_strconcat (items->base_dir, "/", item->preview, NULL);
+ big_src = g_strconcat (path_info->src_dir, "/", item->preview, NULL);
if (! copy_file (big_src, big_dst))
log_error ("generate_image: error copying preview image %s\n", big_src);
g_free (big_src);
@@ -259,6 +259,7 @@ generate_image (TGallerySetup *setup,
*/
gboolean
write_html_album (TGallerySetup *setup,
+ TPathInfo *path_info,
const gchar *template_src,
const gchar *dst,
TAlbum *items)
@@ -475,10 +476,8 @@ write_html_album (TGallerySetup *setup,
s3 = item_get_thumbnail_src (setup, items, item, i);
if (s3 != NULL) {
replace_table_add_key_printf (local_replace_table, "IMG_THUMBNAIL", "%s/%s", setup->thumbnail_dir, s3);
- s5 = g_path_get_dirname (dst);
- s4 = g_build_filename (s5, setup->thumbnail_dir, s3, NULL);
+ s4 = g_build_filename (path_info->dest_dir, setup->thumbnail_dir, s3, NULL);
get_image_sizes (s4, &img_thumb_w, &img_thumb_h);
- g_free (s5);
g_free (s4);
replace_table_add_key_int (local_replace_table, "IMG_SIZE_THUMB_W", img_thumb_w);
replace_table_add_key_int (local_replace_table, "IMG_SIZE_THUMB_H", img_thumb_h);
@@ -488,7 +487,7 @@ write_html_album (TGallerySetup *setup,
replace_table_add_key (local_replace_table, "IMG_DESCRIPTION", item->title_description);
replace_table_add_key_printf (local_replace_table, "IMG_LIST_ID", "i%d", i + 1);
if (items->type == GALLERY_TYPE_INDEX) {
- s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL);
+ s3 = g_strconcat (path_info->src_dir, "/", item->path, "/index.xml", NULL);
replace_table_add_key_int (local_replace_table, "ALBUM_NUM_ITEMS", get_album_objects_count (s3));
g_free (s3);
}
@@ -545,7 +544,6 @@ write_html_album (TGallerySetup *setup,
* write_html_image: process single image template file
*
* template_src = template file of the album/index
- * original_img = source image file (original full-size) to get EXIF data from
* dst = save generated file as
* item = data for the current item
* parent_items = array of items in the album, to determine our position and make links to previous/next image
@@ -553,8 +551,8 @@ write_html_album (TGallerySetup *setup,
*/
gboolean
write_html_image (TGallerySetup *setup,
+ TPathInfo *path_info,
const gchar *template_src,
- const gchar *original_img,
const gchar *dst,
TIndexItem *item,
TAlbum *parent_items)
@@ -635,14 +633,14 @@ write_html_image (TGallerySetup *setup,
preload_imgname = g_strconcat (setup->img_big_dir, "/", s1, NULL);
g_free (s1);
}
- s1 = g_path_get_dirname (dst);
- big_dst = g_strconcat (s1, "/", setup->img_big_dir, "/", imgname, NULL);
- orig_dst = g_strconcat (s1, "/", setup->img_orig_dir, "/", imgname, NULL);
- g_free (s1);
+ big_dst = g_strconcat (path_info->dest_dir, "/", setup->img_big_dir, "/", imgname, NULL);
+ orig_dst = g_strconcat (path_info->dest_dir, "/", setup->img_orig_dir, "/", imgname, NULL);
res = TRUE;
/* Get EXIF data from the original image */
- exif = get_exif (original_img);
+ s1 = g_strconcat (path_info->src_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL);
+ exif = get_exif (s1);
+ g_free (s1);
if (exif == NULL)
log_error ("write_html_image: error getting exif data from file \"%s\"\n", orig_dst);
diff --git a/src/generators.h b/src/generators.h
index a890eb8..9e9c55e 100644
--- a/src/generators.h
+++ b/src/generators.h
@@ -36,7 +36,7 @@ gboolean generate_image (TGallerySetup *setup,
TAlbum *items,
TIndexItem *item,
unsigned int item_index,
- const gchar *dst_dir,
+ TPathInfo *path_info,
gboolean update_when_necessary,
gboolean *thumb_portrait);
@@ -49,6 +49,7 @@ gboolean generate_image (TGallerySetup *setup,
*
*/
gboolean write_html_album (TGallerySetup *setup,
+ TPathInfo *path_info,
const gchar *template_src,
const gchar *dst,
TAlbum *items);
@@ -57,15 +58,14 @@ gboolean write_html_album (TGallerySetup *setup,
* write_html_image: process single image template file
*
* template_src = template file of the album/index
- * original_img = source image file (original full-size) to get EXIF data from
* dst = save generated file as
* item = data for the current item
* parent_items = array of items in the album, to determine our position and make links to previous/next image
*
*/
gboolean write_html_image (TGallerySetup *setup,
+ TPathInfo *path_info,
const gchar *template_src,
- const gchar *original_img,
const gchar *dst,
TIndexItem *item,
TAlbum *parent_items);
diff --git a/src/items.c b/src/items.c
index 06864dd..4012980 100644
--- a/src/items.c
+++ b/src/items.c
@@ -81,6 +81,7 @@ parse_album_xml (const gchar *filename)
int i;
gchar *s, *s2;
gchar *node_name;
+ gchar *base_dir;
TIndexItem *item;
TAtomFeedItem *feed_item;
TAlbum *index;
@@ -90,7 +91,6 @@ parse_album_xml (const gchar *filename)
return NULL;
index = g_malloc0 (sizeof (TAlbum));
- index->base_dir = g_path_get_dirname (filename);
/* Retrieve gallery type */
gallery_type = xml_file_get_node_attribute (xml, "/gallery", "type");
@@ -107,6 +107,8 @@ parse_album_xml (const gchar *filename)
}
g_free (gallery_type);
+ base_dir = g_path_get_dirname (filename);
+
/* Section General */
index->ID = xml_file_get_node_value (xml, "/gallery/general/ID/text()");
index->title = xml_file_get_node_value (xml, "/gallery/general/title/text()");
@@ -225,14 +227,14 @@ parse_album_xml (const gchar *filename)
/* Retrieve title and description from linked album if not defined here */
if (index->type == GALLERY_TYPE_INDEX &&
item->title == NULL && item->title_description == NULL) {
- s = g_strconcat (index->base_dir, "/", item->path, "/index.xml", NULL);
+ s = g_strconcat (base_dir, "/", item->path, "/index.xml", NULL);
get_album_titles (s, &item->title, &item->title_description, NULL);
g_free (s);
}
/* Retrieve thumbnail from linked album if not defined here */
if (index->type == GALLERY_TYPE_INDEX && item->thumbnail == NULL) {
- s = g_strconcat (index->base_dir, "/", item->path, "/index.xml", NULL);
+ s = g_strconcat (base_dir, "/", item->path, "/index.xml", NULL);
s2 = NULL;
get_album_titles (s, NULL, NULL, &s2);
if (s2) {
@@ -280,6 +282,8 @@ parse_album_xml (const gchar *filename)
}
xml_parser_free (xml);
+ g_free (base_dir);
+
return index;
}
@@ -295,7 +299,6 @@ free_album_data (TAlbum *album)
g_free (album->title);
g_free (album->desc);
g_free (album->footnote);
- g_free (album->base_dir);
g_free (album->border_style);
g_free (album->meta_author);
g_free (album->meta_description);
@@ -357,3 +360,18 @@ get_album_titles (const gchar *filename, gchar **title, gchar **description, gch
xml_parser_free (xml);
}
+
+/*
+ * free_path_info: free allocated pathinfo data
+ */
+void
+free_path_info (TPathInfo *path_info)
+{
+ if (path_info) {
+ g_free (path_info->source_root);
+ g_free (path_info->dest_root);
+ g_free (path_info->src_dir);
+ g_free (path_info->dest_dir);
+ g_free (path_info);
+ }
+}
diff --git a/src/items.h b/src/items.h
index f1f13c9..491a8b3 100644
--- a/src/items.h
+++ b/src/items.h
@@ -41,7 +41,6 @@ typedef struct {
gchar *desc;
gchar *footnote;
GPtrArray *items;
- gchar *base_dir;
void *parent_index; /* pointer to the parent TAlbum structure */
int parent_item_index; /* item index in the parent album */
int quality;
@@ -78,6 +77,12 @@ typedef struct {
gboolean gen_portrait; /* thumbnail orientation, don't use for original image orientation */
} TIndexItem;
+typedef struct {
+ gchar *source_root;
+ gchar *dest_root;
+ gchar *src_dir;
+ gchar *dest_dir;
+} TPathInfo;
/*
@@ -100,6 +105,10 @@ int get_album_objects_count (const gchar *filename);
*/
void get_album_titles (const gchar *filename, gchar **title, gchar **description, gchar **thumbnail);
+/*
+ * free_path_info: free allocated pathinfo data
+ */
+void free_path_info (TPathInfo *path_info);
G_END_DECLS
diff --git a/src/job-manager.c b/src/job-manager.c
index c4a77e4..11beebb 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -41,7 +41,7 @@ typedef struct {
TGallerySetup *setup;
TAlbum *items;
GList *job_items;
- const gchar *dst_dir;
+ TPathInfo *path_info;
gboolean force_update;
int total_items;
} TJob;
@@ -113,7 +113,7 @@ thread_func (gpointer data)
{
TIndexItem *item;
gchar *imgname;
- gchar *s1, *s2, *s3;
+ gchar *s1, *s3;
TJob *job = data;
gboolean updated;
GList *l;
@@ -139,7 +139,7 @@ thread_func (gpointer data)
/* actually do some work */
if (item != NULL && job_item != NULL) {
imgname = g_path_get_basename ((item->path == NULL && item->preview) ? item->preview : item->path);
- updated = generate_image (job->setup, job->items, item, job_item->real_index, job->dst_dir, ! job->force_update, &job_item->gen_thumb_portrait);
+ updated = generate_image (job->setup, job->items, item, job_item->real_index, job->path_info, ! job->force_update, &job_item->gen_thumb_portrait);
if (updated && job->setup->verbose) {
G_LOCK (items_print);
@@ -149,11 +149,9 @@ thread_func (gpointer data)
if (updated && job->items->type == GALLERY_TYPE_ALBUM) {
s1 = g_strconcat (job->setup->real_templates_dir, "/", job->setup->template_photo, NULL);
- s2 = g_strconcat (job->items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL);
- s3 = g_strconcat (job->dst_dir, "/", imgname, GET_EXT (job->setup->index_file_name), NULL);
- write_html_image (job->setup, s1, s2, s3, item, job->items);
+ s3 = g_strconcat (job->path_info->dest_dir, "/", imgname, GET_EXT (job->setup->index_file_name), NULL);
+ write_html_image (job->setup, job->path_info, s1, s3, item, job->items);
g_free (s1);
- g_free (s2);
g_free (s3);
}
g_free (imgname);
@@ -175,8 +173,7 @@ thread_func (gpointer data)
*/
gboolean
build_tree (TGallerySetup *setup,
- const gchar *src_tree,
- const gchar *dst_dir,
+ TPathInfo *path_info,
TAlbum *parent_index,
int parent_item_index,
int jobs)
@@ -200,24 +197,25 @@ build_tree (TGallerySetup *setup,
TJobItem *job_item;
GList *job_items;
GList *l;
+ TPathInfo *child_path_info;
- printf ("Processing directory \"%s\"\n", src_tree);
+ printf ("Processing directory \"%s\"\n", path_info->src_dir);
stats_dirs_inc ();
/* Check access permissions */
- if (access (src_tree, R_OK)) {
+ if (access (path_info->src_dir, R_OK)) {
log_error ("error accessing source directory: %s\n", strerror (errno));
return FALSE;
}
- if (access (dst_dir, R_OK | W_OK | X_OK)) {
- if (g_mkdir_with_parents (dst_dir, DEFAULT_DATA_DIR_MODE)) {
+ if (access (path_info->dest_dir, R_OK | W_OK | X_OK)) {
+ if (g_mkdir_with_parents (path_info->dest_dir, DEFAULT_DATA_DIR_MODE)) {
log_error ("error creating destination directory: %s\n", strerror (errno));
return FALSE;
}
}
/* Check the index file */
- idx_file = g_strconcat (src_tree, "/index.xml", NULL);
+ idx_file = g_strconcat (path_info->src_dir, "/index.xml", NULL);
if (access (idx_file, R_OK)) {
log_error ("error accessing index file '%s': %s\n", idx_file, strerror (errno));
g_free (idx_file);
@@ -235,20 +233,20 @@ build_tree (TGallerySetup *setup,
items->parent_item_index = parent_item_index;
/* Check if update is necessary */
- dst_album_file = g_strconcat (dst_dir, "/", setup->index_file_name, NULL);
+ dst_album_file = g_strconcat (path_info->dest_dir, "/", setup->index_file_name, NULL);
force_update = (! setup->update_mode || needs_update (idx_file, dst_album_file));
g_free (idx_file);
/* Copy support files */
if (! setup->support_files_use_common_root || parent_index == NULL) {
/* copy only if we're in root level or old-style is active */
- mirror_files (setup, setup->template_files, setup->real_templates_dir, dst_dir, " Copying template files: ");
+ mirror_files (setup, setup->template_files, setup->real_templates_dir, path_info->dest_dir, " Copying template files: ");
/* favicon */
if (setup->favicon_file && strlen (setup->favicon_file) > 0) {
s3 = g_path_get_dirname (setup->setup_xml_path);
s1 = g_strconcat (s3, "/", setup->favicon_file, NULL);
- s2 = g_strconcat (dst_dir, "/", setup->favicon_file, NULL);
+ s2 = g_strconcat (path_info->dest_dir, "/", setup->favicon_file, NULL);
if (! setup->update_mode || needs_update (s1, s2)) {
if (setup->verbose) printf (" Copying favicon: %s\n", setup->favicon_file);
copy_file (s1, s2);
@@ -260,7 +258,7 @@ build_tree (TGallerySetup *setup,
}
/* Prepare target thumbnail directory */
- thumb_dir = g_strconcat (dst_dir, "/", setup->thumbnail_dir, NULL);
+ thumb_dir = g_strconcat (path_info->dest_dir, "/", setup->thumbnail_dir, NULL);
if (access (thumb_dir, R_OK | W_OK | X_OK))
if (g_mkdir_with_parents (thumb_dir, DEFAULT_DATA_DIR_MODE)) {
log_error ("error making target thumbnail directory: %s\n", strerror (errno));
@@ -275,8 +273,8 @@ build_tree (TGallerySetup *setup,
if (items->type == GALLERY_TYPE_ALBUM)
{
res = TRUE;
- img_big_dir = g_strconcat (dst_dir, "/", setup->img_big_dir, NULL);
- img_orig_dir = g_strconcat (dst_dir, "/", setup->img_orig_dir, NULL);
+ img_big_dir = g_strconcat (path_info->dest_dir, "/", setup->img_big_dir, NULL);
+ img_orig_dir = g_strconcat (path_info->dest_dir, "/", setup->img_orig_dir, NULL);
if (access (img_big_dir, R_OK | W_OK | X_OK))
if (g_mkdir_with_parents (img_big_dir, DEFAULT_DATA_DIR_MODE)) {
log_error ("error making target preview directory: %s\n", strerror (errno));
@@ -300,7 +298,7 @@ build_tree (TGallerySetup *setup,
job = g_malloc0 (sizeof (TJob));
job->items = items;
job->setup = setup;
- job->dst_dir = dst_dir;
+ job->path_info = path_info;
job->force_update = force_update;
job->total_items = 0;
@@ -378,7 +376,7 @@ build_tree (TGallerySetup *setup,
if (setup->verbose) printf (" Writing %s\n", setup->index_file_name);
s1 = g_strconcat (setup->real_templates_dir, template, NULL);
- res = write_html_album (setup, s1, dst_album_file, items);
+ res = write_html_album (setup, path_info, s1, dst_album_file, items);
g_free (s1);
g_free (template);
if (! res) {
@@ -400,18 +398,20 @@ build_tree (TGallerySetup *setup,
continue;
}
if (item->type == INDEX_ITEM_TYPE_PICTURE) {
- s1 = g_strconcat (src_tree, "/", item->path, "/", NULL);
- s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL);
- build_tree (setup, s1, s2, items, i, jobs);
- g_free (s1);
- g_free (s2);
+ child_path_info = g_malloc0 (sizeof (TPathInfo));
+ child_path_info->source_root = g_strdup (path_info->source_root);
+ child_path_info->dest_root = g_strdup (path_info->dest_root);
+ child_path_info->src_dir = g_build_path (G_DIR_SEPARATOR_S, path_info->src_dir, item->path, NULL);
+ child_path_info->dest_dir = g_build_path (G_DIR_SEPARATOR_S, path_info->dest_dir, item->path, NULL);
+ build_tree (setup, child_path_info, items, i, jobs);
+ free_path_info (child_path_info);
}
}
}
}
/* Copy extra files */
- mirror_files (setup, items->extra_files, src_tree, dst_dir, " Copying extra files: ");
+ mirror_files (setup, items->extra_files, path_info->src_dir, path_info->dest_dir, " Copying extra files: ");
free_album_data (items);
return TRUE;
diff --git a/src/job-manager.h b/src/job-manager.h
index 2a0c3ff..58a0cb3 100644
--- a/src/job-manager.h
+++ b/src/job-manager.h
@@ -35,8 +35,7 @@ G_BEGIN_DECLS
*
*/
gboolean build_tree (TGallerySetup *setup,
- const gchar *src_tree,
- const gchar *dst_dir,
+ TPathInfo *path_info,
TAlbum *parent_index,
int parent_item_index,
int jobs);