summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-12-30 00:45:45 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-12-30 00:45:45 +0100
commit6323cb7f767ba77458384cb35d27315df9af0cb4 (patch)
tree6d9b33509bbe8993c450fc0a91fbcc1f0f4ac571
parent9d50015682975f1f70e22b4814fe7bf200c60679 (diff)
downloadcataract-6323cb7f767ba77458384cb35d27315df9af0cb4.tar.xz
Retrieve titles and thumbnail from linked album if not defined in index
Fix mem leak
-rw-r--r--generators.c2
-rw-r--r--items.c51
-rw-r--r--items.h4
-rw-r--r--sample/src/index.xml2
l---------sample/src/inheritance/img_6802xxx.jpg1
-rw-r--r--sample/src/inheritance/index.xml17
-rw-r--r--setup.c1
7 files changed, 75 insertions, 3 deletions
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, "<!-- $(ALBUM_NUM_ITEMS) -->")) {
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, "<!-- $(ALBUM_NUM_ITEMS) -->", 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 @@
<title_description>hidden</title_description>
</item>
+ <item path="inheritance"></item>
+
</items>
</gallery>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<gallery type="album">
+ <general>
+ <ID>non-inherited ID</ID>
+ <title>Inherited title</title>
+ <description> <![CDATA[
+ Inherited description.
+ <br/>
+ Line 2
+ ]]>
+ </description>
+ </general>
+
+ <items>
+ <item src="img_6802xxx.jpg"></item>
+ </items>
+</gallery>
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);