From 6323cb7f767ba77458384cb35d27315df9af0cb4 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Tue, 30 Dec 2008 00:45:45 +0100 Subject: Retrieve titles and thumbnail from linked album if not defined in index Fix mem leak --- generators.c | 2 +- items.c | 51 ++++++++++++++++++++++++++++++++-- items.h | 4 +++ sample/src/index.xml | 2 ++ sample/src/inheritance/img_6802xxx.jpg | 1 + sample/src/inheritance/index.xml | 17 ++++++++++++ setup.c | 1 + 7 files changed, 75 insertions(+), 3 deletions(-) create mode 120000 sample/src/inheritance/img_6802xxx.jpg create mode 100644 sample/src/inheritance/index.xml diff --git a/generators.c b/generators.c index 28a6770..f2aaa31 100644 --- a/generators.c +++ b/generators.c @@ -478,7 +478,7 @@ write_html_album (TGallerySetup *setup, } if (strstr(s1, "")) { s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL); - s2 = g_strdup_printf ("%d", get_album_objects_count(s3)); + s2 = g_strdup_printf ("%d", get_album_objects_count (s3)); str_replace (&s1, "", s2, NULL); g_free (s2); g_free (s3); diff --git a/items.c b/items.c index cf2d90f..97202f2 100644 --- a/items.c +++ b/items.c @@ -39,7 +39,7 @@ parse_album_xml (const char *filename, TAlbum *index) char *gallery_type; int count; int i; - char *s; + char *s, *s2; char *node_name; TIndexItem *item; @@ -140,6 +140,26 @@ parse_album_xml (const char *filename, TAlbum *index) item->hidden = (xml_file_get_node_present (xml, s)); g_free (s); + /* 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); + 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); + s2 = NULL; + get_album_titles (s, NULL, NULL, &s2); + if (s2) { + item->thumbnail = g_strconcat (item->path, "/", s2, NULL); + g_free (s2); + } + g_free (s); + } + if (item->path || item->preview) { g_ptr_array_add (index->items, item); @@ -245,7 +265,7 @@ get_album_objects_count (const char *filename) xml = xml_parser_load (filename); if (xml == NULL) - return 0; + return 0; count = xml_file_node_get_children_count (xml, "/gallery/items/item"); xml_parser_close (xml); @@ -255,3 +275,30 @@ get_album_objects_count (const char *filename) #endif return count; } + +/* + * get_album_titles: retrieve title, description and first thumbnail from specified album + */ +void +get_album_titles (const char *filename, char **title, char **description, char **thumbnail) +{ + TXMLFile *xml; + + xml = xml_parser_load (filename); + if (xml == NULL) + return; + + if (title) + *title = xml_file_get_node_value (xml, "/gallery/general/title/text()"); + if (description) + *description = xml_file_get_node_value (xml, "/gallery/general/description/text()"); + if (thumbnail) { + *thumbnail = xml_file_get_node_attribute (xml, "/gallery/items/item[1]/thumbnail", "src"); + if (! *thumbnail) + *thumbnail = xml_file_get_node_attribute (xml, "/gallery/items/item[1]", "src"); + if (! *thumbnail) + *thumbnail = xml_file_get_node_attribute (xml, "/gallery/items/item[1]", "preview"); + } + + xml_parser_close (xml); +} diff --git a/items.h b/items.h index 3c3286f..528d71e 100644 --- a/items.h +++ b/items.h @@ -81,5 +81,9 @@ void free_album_data (TAlbum *index); */ int get_album_objects_count (const char *filename); +/* + * get_album_titles: retrieve title, description and first thumbnail from specified album + */ +void get_album_titles (const char *filename, char **title, char **description, char **thumbnail); #endif /* __ITEMS_H__ */ diff --git a/sample/src/index.xml b/sample/src/index.xml index eecca3f..79a90c1 100644 --- a/sample/src/index.xml +++ b/sample/src/index.xml @@ -38,5 +38,7 @@ hidden + + diff --git a/sample/src/inheritance/img_6802xxx.jpg b/sample/src/inheritance/img_6802xxx.jpg new file mode 120000 index 0000000..9f4b2f7 --- /dev/null +++ b/sample/src/inheritance/img_6802xxx.jpg @@ -0,0 +1 @@ +../CIAF_1/img_6802.jpg \ No newline at end of file diff --git a/sample/src/inheritance/index.xml b/sample/src/inheritance/index.xml new file mode 100644 index 0000000..8e838e1 --- /dev/null +++ b/sample/src/inheritance/index.xml @@ -0,0 +1,17 @@ + + + + non-inherited ID + Inherited title + + Line 2 + ]]> + + + + + + + diff --git a/setup.c b/setup.c index 8df399c..5ad4bb3 100644 --- a/setup.c +++ b/setup.c @@ -115,6 +115,7 @@ parse_setup_xml (const char *filename, TGallerySetup *setup) setup->meta_keywords = xml_file_get_node_value (xml, "/gallery_setup/meta/keywords/text()"); s = xml_file_get_node_attribute (xml, "/gallery_setup/images/preload", "value"); setup->preload = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ + if (s) g_free (s); xml_parser_close (xml); -- cgit v1.2.3