From 0cb2950ba336d6c291a1dc086ad2f3138f37e132 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 10 Feb 2013 16:25:29 +0100 Subject: Support theme-defined thumbnail for protected albums --- src/items.c | 81 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 22 deletions(-) (limited to 'src/items.c') 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 @@ -275,6 +260,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 */ @@ -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); } /* -- cgit v1.2.3