diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2013-02-10 16:25:29 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2013-02-10 16:25:29 +0100 |
| commit | 0cb2950ba336d6c291a1dc086ad2f3138f37e132 (patch) | |
| tree | 799d0b2b419eb07ad6c598b4f5234001ac6e0c21 /src | |
| parent | 939408e9c730ceb43d9bfd49056b5eb26f081b26 (diff) | |
| download | cataract-0cb2950ba336d6c291a1dc086ad2f3138f37e132.tar.xz | |
Support theme-defined thumbnail for protected albums
Diffstat (limited to 'src')
| -rw-r--r-- | src/generators.c | 37 | ||||
| -rw-r--r-- | src/items.c | 81 | ||||
| -rw-r--r-- | src/items.h | 14 | ||||
| -rw-r--r-- | src/setup.c | 4 | ||||
| -rw-r--r-- | src/setup.h | 1 |
5 files changed, 102 insertions, 35 deletions
diff --git a/src/generators.c b/src/generators.c index ac641d4..2b0928b 100644 --- a/src/generators.c +++ b/src/generators.c @@ -274,6 +274,7 @@ write_html_album (TGallerySetup *setup, FILE *fout; gchar *line; gchar *block; + gchar *templates_path; gchar *s1, *s2, *s3, *s4, *s5; TAlbum *parent; TIndexItem *item; @@ -284,6 +285,8 @@ write_html_album (TGallerySetup *setup, int i; unsigned int real_total_items; unsigned long img_thumb_w, img_thumb_h; + int album_objects_count; + gboolean album_protected; ReplaceTable *global_replace_table; ReplaceTable *local_replace_table; BlockParser *block_parser; @@ -379,9 +382,8 @@ write_html_album (TGallerySetup *setup, g_free (s1); /* Supportfiles path */ - s1 = make_string ("../", level - 1); - replace_table_add_key (global_replace_table, "TEMPLATES_PATH", setup->supplemental_files_use_common_root ? s1 : ""); - g_free (s1); + templates_path = setup->supplemental_files_use_common_root ? make_string ("../", level - 1) : g_strdup (""); + replace_table_add_key (global_replace_table, "TEMPLATES_PATH", templates_path); /* META tags */ s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"%s v%s\" />\n", APP_NAME_FULL, VERSION); @@ -462,7 +464,6 @@ write_html_album (TGallerySetup *setup, continue; } - /* Generate images (preview, original, thumbnail) */ local_replace_table = replace_table_new (); replace_table_set_defines (local_replace_table, defines); s1 = NULL; @@ -471,8 +472,27 @@ write_html_album (TGallerySetup *setup, case INDEX_ITEM_TYPE_PICTURE: /* Skip HTML code generation if it's a hidden item */ if (! item->hidden) { + album_protected = FALSE; + album_objects_count = 0; + if (items->type == GALLERY_TYPE_INDEX) { + s3 = g_build_filename (path_info->src_dir, item->path, "index.xml", NULL); + /* FIXME: doing additional I/O, port to global item tree */ + get_album_info (s3, &album_objects_count, &album_protected); + g_free (s3); + replace_table_add_key_int (local_replace_table, "ALBUM_NUM_ITEMS", album_objects_count); + replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, get_index_filename (items, theme, path_info, item)); + } + img_thumb_w = img_thumb_h = 0; - get_image_paths (setup, items, item, i, path_info, thumb_image_size, NULL, &s2, &s3); + if (album_protected && theme->album_protected_thumbnail != NULL) { + /* expecting both global and theme supplemental files are in place at this moment */ + s2 = g_build_filename (path_info->dest_dir, templates_path, theme->album_protected_thumbnail, NULL); + s3 = g_strconcat (templates_path, theme->album_protected_thumbnail, NULL); + } + else { + get_image_paths (setup, items, item, i, path_info, thumb_image_size, NULL, &s2, &s3); + } + if (s2 != NULL) get_image_sizes (s2, &img_thumb_w, &img_thumb_h, setup->autorotate); @@ -499,12 +519,6 @@ write_html_album (TGallerySetup *setup, replace_table_add_key (local_replace_table, "IMG_TITLE", item->title); 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_build_filename (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)); - replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, get_index_filename (items, theme, path_info, item)); - g_free (s3); - } } break; @@ -553,6 +567,7 @@ write_html_album (TGallerySetup *setup, g_hash_table_destroy (defines); replace_table_free (global_replace_table); block_parser_free (block_parser); + g_free (templates_path); return res; } diff --git a/src/items.c b/src/items.c index 8692b65..a0c2534 100644 --- a/src/items.c +++ b/src/items.c @@ -30,21 +30,6 @@ #include "atom-writer.h" - -static void -free_album_item (TIndexItem *item) -{ - g_free (item->path); - g_free (item->title); - g_free (item->title_description); - g_free (item->thumbnail); - g_free (item->preview); - g_free (item->border_style); - g_free (item->metadata_external_exif); - g_free (item); -} - - /* * parse_album_xml: XML parser for gallery index.xml files */ @@ -238,7 +223,7 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info) g_ptr_array_add (index->items, item); } else { log_error ("%s: No image src specified, skipping!\n", filename); - free_album_item (item); + free_index_item (item); } } else @@ -276,6 +261,48 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info) /* + * dup_index_item: duplicates the item structure or returns NULL if item == NULL + */ +TIndexItem * +dup_index_item (TIndexItem *item) +{ + TIndexItem *i; + + if (item == NULL) + return NULL; + + i = g_malloc0 (sizeof (TIndexItem)); + memcpy (i, item, sizeof (TIndexItem)); + i->path = g_strdup (item->path); + i->title = g_strdup (item->title); + i->title_description = g_strdup (item->title_description); + i->thumbnail = g_strdup (item->thumbnail); + i->preview = g_strdup (item->preview); + i->border_style = g_strdup (item->border_style); + i->metadata_external_exif = g_strdup (item->metadata_external_exif); + + return i; +} + +/* + * free_index_item: frees all memory used by item + */ +void +free_index_item (TIndexItem *item) +{ + if (item != NULL) { + g_free (item->path); + g_free (item->title); + g_free (item->title_description); + g_free (item->thumbnail); + g_free (item->preview); + g_free (item->border_style); + g_free (item->metadata_external_exif); + g_free (item); + } +} + +/* * free_album_data: free allocated album data */ void @@ -296,7 +323,7 @@ free_album_data (TAlbum *album) g_strfreev (album->extra_files); if (album->items) { - g_ptr_array_foreach (album->items, (GFunc) free_album_item, NULL); + g_ptr_array_foreach (album->items, (GFunc) free_index_item, NULL); g_ptr_array_free (album->items, TRUE); } g_free (album); @@ -305,23 +332,33 @@ free_album_data (TAlbum *album) /* - * get_gallery_objects_count: retrieve number of items in specified album + * get_album_info: retrieve number of items and protected status in the specified album */ -int -get_album_objects_count (const gchar *filename) +void +get_album_info (const gchar *filename, int *objects_count, gboolean *protected) { TXMLFile *xml; int count, hidden; + if (objects_count) + *objects_count = 0; + if (protected) + *protected = FALSE; + xml = xml_parser_load (filename); if (xml == NULL) - return 0; + return; count = xml_file_node_get_children_count (xml, "/gallery/items/item"); hidden = xml_file_node_get_children_count (xml, "/gallery/items/item/hidden"); + if (objects_count) + *objects_count = count - hidden; + if (protected) + *protected = xml_file_get_node_present (xml, "/gallery/general/auth/username") && + xml_file_get_node_present (xml, "/gallery/general/auth/password"); + xml_parser_free (xml); - return (count - hidden); } /* diff --git a/src/items.h b/src/items.h index 5b350b9..15baeae 100644 --- a/src/items.h +++ b/src/items.h @@ -109,9 +109,9 @@ TAlbum * parse_album_xml (const gchar *filename, TPathInfo *path_info); void free_album_data (TAlbum *index); /* - * get_album_objects_count: retrieve number of items in specified album + * get_album_info: retrieve number of items and protected status in the specified album */ -int get_album_objects_count (const gchar *filename); +void get_album_info (const gchar *filename, int *objects_count, gboolean *protected); /* * get_album_titles: retrieve title, description and first thumbnail from specified album @@ -128,6 +128,16 @@ TGalleryType get_child_gallery_type (const gchar *filename); */ void free_path_info (TPathInfo *path_info); +/* + * dup_index_item: duplicates the item structure or returns NULL if item == NULL + */ +TIndexItem *dup_index_item (TIndexItem *item); + +/* + * free_index_item: frees all memory used by item + */ +void free_index_item (TIndexItem *item); + G_END_DECLS #endif /* __CGG__ITEMS_H__ */ diff --git a/src/setup.c b/src/setup.c index c78b15f..e4df0dd 100644 --- a/src/setup.c +++ b/src/setup.c @@ -224,6 +224,9 @@ parse_design_setup_xml (const gchar *filename) s = g_strdup_printf ("/design_setup/theme[%d]/album/picture_size/text()", i + 1); theme->album_image_size = xml_file_get_node_value (xml, s); g_free (s); + s = g_strdup_printf ("/design_setup/theme[%d]/album/protected_thumbnail/text()", i + 1); + theme->album_protected_thumbnail = xml_file_get_node_value (xml, s); + g_free (s); s = g_strdup_printf ("/design_setup/theme[%d]/picture/template/text()", i + 1); theme->picture_template = xml_file_get_node_value (xml, s); @@ -408,6 +411,7 @@ free_design_theme_data (TGalleryDesignTheme *theme) g_free (theme->album_template); g_free (theme->album_filename); g_free (theme->album_image_size); + g_free (theme->album_protected_thumbnail); g_free (theme->picture_template); g_free (theme->picture_filename); g_free (theme->picture_image_size); diff --git a/src/setup.h b/src/setup.h index c34d861..daf8453 100644 --- a/src/setup.h +++ b/src/setup.h @@ -106,6 +106,7 @@ typedef struct { gchar *album_template; gchar *album_filename; gchar *album_image_size; + gchar *album_protected_thumbnail; gchar *picture_template; gchar *picture_filename; gchar *picture_image_size; |
