diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2010-10-08 17:02:47 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2010-10-08 17:02:47 +0200 |
| commit | 10c6b1f0978710cf5a9f309b6fdcaef922f9b07f (patch) | |
| tree | 00679d479d9554f91f5d3beb4f4e709705ba55df /src/items.c | |
| parent | 5fc53d25a171fbd85ee09c9fc771580350d689c8 (diff) | |
| download | cataract-10c6b1f0978710cf5a9f309b6fdcaef922f9b07f.tar.xz | |
Add basic Atom feed writer
Diffstat (limited to 'src/items.c')
| -rw-r--r-- | src/items.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/src/items.c b/src/items.c index 730908e..4a6f7ea 100644 --- a/src/items.c +++ b/src/items.c @@ -27,8 +27,35 @@ #include "items.h" #include "xml-parser.h" #include "gallery-utils.h" +#include "atom-writer.h" +static gchar * +get_album_path (TAlbum *items) +{ + TIndexItem *parent_item; + TAlbum *parent; + int old_parent_item_index; + gchar *path; + gchar *s; + + path = NULL; + parent = items->parent_index; + old_parent_item_index = items->parent_item_index; + while (parent) { + parent_item = g_ptr_array_index (parent->items, old_parent_item_index); + if (! parent_item) + break; + s = g_strdup_printf ("/%s%s", parent_item->path, path ? path : ""); + g_free (path); + path = s; + old_parent_item_index = parent->parent_item_index; + parent = parent->parent_index; + } + + return path ? path : g_strdup ("/"); +} + /* * parse_album_xml: XML parser for gallery index.xml files @@ -43,16 +70,12 @@ parse_album_xml (const gchar *filename, TAlbum *index) gchar *s, *s2; gchar *node_name; TIndexItem *item; + TAtomFeedItem *feed_item; xml = xml_parser_load (filename); if (xml == NULL) return FALSE; - /* Initialize data struct */ - if (index == NULL) - index = g_malloc0 (sizeof (TAlbum)); - memset (index, 0, sizeof (TAlbum)); - index->base_dir = g_path_get_dirname (filename); /* Retrieve gallery type */ @@ -81,7 +104,6 @@ parse_album_xml (const gchar *filename, TAlbum *index) g_free (s); } - index->quality = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "quality", -1); index->landscape_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_w", 0); index->landscape_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_h", 0); @@ -96,6 +118,38 @@ parse_album_xml (const gchar *filename, TAlbum *index) index->nofullsize = xml_file_get_node_present (xml, "/gallery/general/nofullsize"); index->fullsize = xml_file_get_node_present (xml, "/gallery/general/fullsize"); + /* News records */ + if (news_feed) { + count = xml_file_node_get_children_count (xml, "/gallery/general/news"); + for (i = 0; i < count; i++) { + feed_item = atom_writer_add_item (news_feed); + s = g_strdup_printf ("/gallery/general/news[%d]", i + 1); + + s2 = xml_file_get_node_attribute (xml, s, "title"); + atom_feed_item_set_title (feed_item, s2); + g_free (s2); + + s2 = xml_file_get_node_attribute (xml, s, "timestamp"); + atom_feed_item_set_date (feed_item, s2); + g_free (s2); + + s2 = xml_file_get_node_attribute (xml, s, "type"); + atom_feed_item_set_summary_type (feed_item, s2); + g_free (s2); + g_free (s); + + s = g_strdup_printf ("/gallery/general/news[%d]/text()", i + 1); + s2 = xml_file_get_node_value (xml, s); + atom_feed_item_set_summary (feed_item, s2); + g_free (s2); + + s = get_album_path (index); + atom_feed_item_set_path (feed_item, s); + g_free (s); + } + + } + /* Section Items */ count = xml_file_node_get_children_count (xml, "/gallery/items/*"); index->items = g_ptr_array_new(); |
