diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-02-28 15:29:50 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-02-28 15:29:50 +0100 |
| commit | d9d50c1f90c623c94cdb3437b8ef925fd1e88881 (patch) | |
| tree | 7e95fde2385e0da3a3cbb0ee5f6253cd6b47af59 | |
| parent | d8c88d35f8f609110ac1871c1df7a83fd719ff7d (diff) | |
| download | cataract-d9d50c1f90c623c94cdb3437b8ef925fd1e88881.tar.xz | |
Support path holes (non-direct path jumps)
| -rw-r--r-- | src/gallery-utils.c | 21 | ||||
| -rw-r--r-- | src/gallery-utils.h | 5 | ||||
| -rw-r--r-- | src/generators.c | 33 |
3 files changed, 52 insertions, 7 deletions
diff --git a/src/gallery-utils.c b/src/gallery-utils.c index 2b74b9b..b7593fe 100644 --- a/src/gallery-utils.c +++ b/src/gallery-utils.c @@ -265,3 +265,24 @@ remove_tags (char **str, const char *tag_begin, const char *tag_end) } *str = src; } + +/* + * count_dir_levels: returns number of path elements + */ +int +count_dir_levels (const char* path) +{ + int i; + int level; + + if (path == NULL || strlen (path) == 0) + return 0; + + level = 1; + for (i = strlen (path) - 1; i > 0; i--) { + if (G_IS_DIR_SEPARATOR (*(path + i)) && i > 0 && i < strlen (path)) + level++; + } + + return level; +} diff --git a/src/gallery-utils.h b/src/gallery-utils.h index 53c82c0..7972b39 100644 --- a/src/gallery-utils.h +++ b/src/gallery-utils.h @@ -51,3 +51,8 @@ void fix_entities (char **str); * - returns newly allocated string */ void remove_tags (char **str, const char *tag_begin, const char *tag_end); + +/* + * count_dir_levels: returns number of path elements + */ +int count_dir_levels (const char* path); diff --git a/src/generators.c b/src/generators.c index f311388..b4bdf9c 100644 --- a/src/generators.c +++ b/src/generators.c @@ -288,15 +288,24 @@ write_html_album (TGallerySetup *setup, replace_table_add_key (global_replace_table, "DESCRIPTION", items->desc); replace_table_add_key (global_replace_table, "FOOTNOTE", items->footnote); replace_table_add_key (global_replace_table, "FOOTER", setup->footer); - s1 = setup->use_inpage_links ? g_strdup_printf ("../index.html#i%d", items->parent_item_index + 1) : g_strdup ("../index.html"); - replace_table_add_key (global_replace_table, "GO_UP_LINK", s1); - g_free (s1); /* Navigation bar */ s1 = g_strdup (items->ID); old_parent_item_index = items->parent_item_index + 1; parent = items->parent_index; level = 1; + if (parent) { + tmp_item = g_ptr_array_index (parent->items, old_parent_item_index - 1); + if (tmp_item && tmp_item->path && strlen (tmp_item->path) > 0) + level += count_dir_levels (tmp_item->path) - 1; + } + /* Go Up string */ + s3 = make_string ("../", level); + s2 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup (""); + replace_table_add_key_printf (global_replace_table, "GO_UP_LINK", "%sindex.html%s", s3, s2); + g_free (s2); + free (s3); + while (parent) { s3 = make_string ("../", level); s4 = g_strdup (parent->ID); @@ -310,6 +319,11 @@ write_html_album (TGallerySetup *setup, old_parent_item_index = parent->parent_item_index + 1; parent = parent->parent_index; level++; + if (parent) { + tmp_item = g_ptr_array_index (parent->items, old_parent_item_index - 1); + if (tmp_item && tmp_item->path && strlen (tmp_item->path) > 0) + level += count_dir_levels (tmp_item->path) - 1; + } } replace_table_add_key (global_replace_table, "NAV_BAR", s1); g_free (s1); @@ -715,6 +729,11 @@ write_html_image (TGallerySetup *setup, old_parent_item_index = parent->parent_item_index + 1; parent = parent->parent_index; level++; + if (parent) { + tmp_item = g_ptr_array_index (parent->items, old_parent_item_index - 1); + if (tmp_item && tmp_item->path && strlen (tmp_item->path) > 0) + level += count_dir_levels (tmp_item->path) - 1; + } } replace_table_add_key (replace_table, "NAV_BAR", s1); g_free (s1); @@ -883,7 +902,7 @@ build_tree (TGallerySetup *setup, return FALSE; } if (access (dst_dir, R_OK | W_OK | X_OK)) { - if (mkdir (dst_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (dst_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error creating destination directory: %s\n", strerror (errno)); return FALSE; } @@ -932,7 +951,7 @@ build_tree (TGallerySetup *setup, /* Prepare target thumbnail directory */ thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); if (access (thumb_dir, R_OK | W_OK | X_OK)) - if (mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); free_album_data (items); @@ -947,12 +966,12 @@ build_tree (TGallerySetup *setup, img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); if (access (img_big_dir, R_OK | W_OK | X_OK)) - if (mkdir (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target preview directory: %s\n", strerror (errno)); res = FALSE; } if (access (img_orig_dir, R_OK | W_OK | X_OK)) - if (mkdir (img_orig_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + if (g_mkdir_with_parents (img_orig_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target full size directory: %s\n", strerror (errno)); res = FALSE; } |
