summaryrefslogtreecommitdiff
path: root/items.c
diff options
context:
space:
mode:
Diffstat (limited to 'items.c')
-rw-r--r--items.c102
1 files changed, 65 insertions, 37 deletions
diff --git a/items.c b/items.c
index 527a5c4..2af0692 100644
--- a/items.c
+++ b/items.c
@@ -40,6 +40,7 @@ parse_album_xml (const char *filename, TAlbum *index)
int count;
int i;
char *s;
+ char *node_name;
TIndexItem *item;
xml = xml_parser_load (filename);
@@ -84,7 +85,10 @@ parse_album_xml (const char *filename, TAlbum *index)
index->border_style = xml_file_get_node_attribute (xml, "/gallery/general/border", "style");
/* Section Items */
- count = xml_file_node_get_children_count (xml, "/gallery/items/item");
+ count = xml_file_node_get_children_count (xml, "/gallery/items/*");
+ #ifdef __DEBUG_ALL__
+ printf("parse_album_xml: items count = %d\n", count);
+ #endif
index->items = g_ptr_array_new();
for (i = 0; i < count; i++)
@@ -92,47 +96,71 @@ parse_album_xml (const char *filename, TAlbum *index)
item = malloc (sizeof (TIndexItem));
memset (item, 0, sizeof (TIndexItem));
- s = g_strdup_printf ("/gallery/items/item[%d]", i + 1);
- if (index->type == GALLERY_TYPE_INDEX)
- item->path = xml_file_get_node_attribute (xml, s, "path");
- else
- item->path = xml_file_get_node_attribute (xml, s, "src");
- item->preview = xml_file_get_node_attribute (xml, s, "preview");
- item->quality = xml_file_get_node_attribute_long (xml, s, "quality", -1);
- item->width = xml_file_get_node_attribute_long (xml, s, "width", 0);
- item->height = xml_file_get_node_attribute_long (xml, s, "height", 0);
- item->border_style = xml_file_get_node_attribute (xml, s, "border");
- if (index->type == GALLERY_TYPE_ALBUM)
- item->thumbnail = xml_file_get_node_attribute (xml, s, "thumbnail");
- g_free (s);
-
- s = g_strdup_printf ("/gallery/items/item[%d]/title/text()", i + 1);
- item->title = xml_file_get_node_value (xml, s);
- g_free (s);
-
- s = g_strdup_printf ("/gallery/items/item[%d]/title_description/text()", i + 1);
- item->title_description = xml_file_get_node_value (xml, s);
- g_free (s);
-
- if (index->type == GALLERY_TYPE_INDEX) {
- s = g_strdup_printf ("/gallery/items/item[%d]/thumbnail", i + 1);
- item->thumbnail = xml_file_get_node_attribute (xml, s, "src");
+ s = g_strdup_printf ("/gallery/items/*[%d]", i + 1);
+ node_name = xml_file_get_node_name (xml, s);
+ if (! node_name) continue;
+ #ifdef __DEBUG_ALL__
+ printf("parse_album_xml: item[%d] = '%s'\n", i + 1, node_name);
+ #endif
+
+ if (strcmp (node_name, "item") == 0) {
+ item->type = INDEX_ITEM_TYPE_PICTURE;
+ if (index->type == GALLERY_TYPE_INDEX)
+ item->path = xml_file_get_node_attribute (xml, s, "path");
+ else
+ item->path = xml_file_get_node_attribute (xml, s, "src");
+ item->preview = xml_file_get_node_attribute (xml, s, "preview");
+ item->quality = xml_file_get_node_attribute_long (xml, s, "quality", -1);
+ item->width = xml_file_get_node_attribute_long (xml, s, "width", 0);
+ item->height = xml_file_get_node_attribute_long (xml, s, "height", 0);
+ item->border_style = xml_file_get_node_attribute (xml, s, "border");
+ if (index->type == GALLERY_TYPE_ALBUM)
+ item->thumbnail = xml_file_get_node_attribute (xml, s, "thumbnail");
g_free (s);
- }
- s = g_strdup_printf ("/gallery/items/item[%d]/nofullsize", i + 1);
- item->nofullsize = (xml_file_get_node_present (xml, s) || item->path == NULL);
- g_free (s);
+ s = g_strdup_printf ("/gallery/items/*[%d]/title/text()", i + 1);
+ item->title = xml_file_get_node_value (xml, s);
+ g_free (s);
+
+ s = g_strdup_printf ("/gallery/items/*[%d]/title_description/text()", i + 1);
+ item->title_description = xml_file_get_node_value (xml, s);
+ g_free (s);
- if (item->path || item->preview)
- {
- g_ptr_array_add (index->items, item);
+ if (index->type == GALLERY_TYPE_INDEX) {
+ s = g_strdup_printf ("/gallery/items/*[%d]/thumbnail", i + 1);
+ item->thumbnail = xml_file_get_node_attribute (xml, s, "src");
+ g_free (s);
}
+
+ s = g_strdup_printf ("/gallery/items/*[%d]/nofullsize", i + 1);
+ item->nofullsize = (xml_file_get_node_present (xml, s) || item->path == NULL);
+ g_free (s);
+
+ if (item->path || item->preview)
+ {
+ g_ptr_array_add (index->items, item);
+ }
+ else
+ {
+ fprintf (stderr, "%s: No image src specified, skipping!\n", filename);
+ free (item);
+ }
+ }
else
- {
- fprintf (stderr, "%s: No image src specified, skipping!\n", filename);
- free (item);
- }
+ if (strcmp (node_name, "separator") == 0) {
+ item->type = INDEX_ITEM_TYPE_SEPARATOR;
+
+ s = g_strdup_printf ("/gallery/items/*[%d]/text()", i + 1);
+ item->title = xml_file_get_node_value (xml, s);
+ g_free (s);
+
+ g_ptr_array_add (index->items, item);
+ }
+ else {
+ /* Free the item if nobody cares */
+ free (item);
+ }
+ free (node_name);
}
xml_parser_close (xml);