summaryrefslogtreecommitdiff
path: root/items.c
diff options
context:
space:
mode:
Diffstat (limited to 'items.c')
-rw-r--r--items.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/items.c b/items.c
index 2c7b094..91eee63 100644
--- a/items.c
+++ b/items.c
@@ -1,16 +1,16 @@
/* Cataract - Static web photo gallery generator
* Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -30,9 +30,9 @@
/*
- * parse_album_xml: XML parser for gallery index.xml files
- */
-gboolean
+ * parse_album_xml: XML parser for gallery index.xml files
+ */
+gboolean
parse_album_xml (const char *filename, TAlbum *index)
{
TXMLFile *xml;
@@ -41,13 +41,13 @@ parse_album_xml (const char *filename, TAlbum *index)
int i;
char *s;
TIndexItem *item;
-
+
xml = xml_parser_load (filename);
if (xml == NULL)
return FALSE;
-
+
/* Initialize data struct */
- if (index == NULL)
+ if (index == NULL)
index = malloc (sizeof (TAlbum));
memset (index, 0, sizeof (TAlbum));
@@ -60,7 +60,7 @@ parse_album_xml (const char *filename, TAlbum *index)
#endif
if (strcmp (gallery_type, "index") == 0)
index->type = GALLERY_TYPE_INDEX;
- else
+ else
if (strcmp (gallery_type, "album") == 0)
index->type = GALLERY_TYPE_ALBUM;
else {
@@ -68,67 +68,70 @@ parse_album_xml (const char *filename, TAlbum *index)
free (index);
return FALSE;
}
-
+
/* Section General */
index->ID = xml_file_get_node_value (xml, "/gallery/general/ID/text()");
index->title = xml_file_get_node_value (xml, "/gallery/general/title/text()");
index->desc = xml_file_get_node_value (xml, "/gallery/general/description/text()");
-
+
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);
index->portrait_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "portrait_w", 0);
index->portrait_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "portrait_h", 0);
+ 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");
index->items = g_ptr_array_new();
-
+
for (i = 0; i < count; i++)
{
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)
+ if (index->type == GALLERY_TYPE_INDEX)
item->path = xml_file_get_node_attribute (xml, s, "path");
- else
+ 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");
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);
-
+
s = g_strdup_printf ("/gallery/items/item[%d]/thumbnail", i + 1);
item->thumbnail = xml_file_get_node_attribute (xml, s, "src");
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);
- if (item->path || item->preview)
+ if (item->path || item->preview)
{
- g_ptr_array_add (index->items, item);
- }
+ g_ptr_array_add (index->items, item);
+ }
else
{
fprintf (stderr, "%s: No image src specified, skipping!\n", filename);
free (item);
}
}
-
+
xml_parser_close (xml);
-
+
/* Print the items */
#ifdef __DEBUG_ALL__
printf ("ID = '%s'\ntitle = '%s'\ndescription = '%s'\n", index->ID, index->title, index->desc);
@@ -138,18 +141,18 @@ parse_album_xml (const char *filename, TAlbum *index)
i, item->path, item->title, item->title_description, item->thumbnail);
}
#endif
- return TRUE;
+ return TRUE;
}
/*
* free_album_data: free allocated album data
*/
-void
+void
free_album_data (TAlbum *album)
{
if (album) {
- if (album->ID)
+ if (album->ID)
free (album->ID);
if (album->title)
free (album->title);
@@ -157,12 +160,14 @@ free_album_data (TAlbum *album)
free (album->desc);
if (album->base_dir)
free (album->base_dir);
-
+ if (album->border_style)
+ free (album->border_style);
+
if (album->items) {
if (album->items->len > 0) {
TIndexItem *item;
int i;
-
+
for (i = 0; i < album->items->len; i++) {
item = g_ptr_array_index (album->items, i);
if (item != NULL) {
@@ -176,31 +181,33 @@ free_album_data (TAlbum *album)
free (item->thumbnail);
if (item->preview)
free (item->preview);
+ if (item->border_style)
+ free (item->border_style);
free (item);
}
}
}
- g_ptr_array_free (album->items, TRUE);
+ g_ptr_array_free (album->items, TRUE);
}
free (album);
- album = NULL;
+ album = NULL;
}
}
/*
- * get_gallery_objects_count: retrieve number of items in specified album
- */
-int
+ * get_gallery_objects_count: retrieve number of items in specified album
+ */
+int
get_album_objects_count (const char *filename)
{
TXMLFile *xml;
int count;
-
+
xml = xml_parser_load (filename);
if (xml == NULL)
return 0;
-
+
count = xml_file_node_get_children_count (xml, "/gallery/items/item");
xml_parser_close (xml);