summaryrefslogtreecommitdiff
path: root/src/items.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/items.c')
-rw-r--r--src/items.c109
1 files changed, 84 insertions, 25 deletions
diff --git a/src/items.c b/src/items.c
index 2434c77..d720415 100644
--- a/src/items.c
+++ b/src/items.c
@@ -131,6 +131,7 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
return NULL;
index = g_malloc0 (sizeof (TAlbum));
+ index->properties = properties_table_new ();
/* Retrieve gallery type */
gallery_type = xml_file_get_node_attribute (xml, "/gallery", "type");
@@ -160,36 +161,35 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
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);
- 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);
+ prop_xml_attr_long (index->properties, PROP_QUALITY, xml, "/gallery/general/images", "quality");
+ prop_xml_attr_long (index->properties, PROP_LANDSCAPE_W, xml, "/gallery/general/images", "landscape_w");
+ prop_xml_attr_long (index->properties, PROP_LANDSCAPE_H, xml, "/gallery/general/images", "landscape_h");
+ prop_xml_attr_long (index->properties, PROP_PORTRAIT_W, xml, "/gallery/general/images", "portrait_w");
+ prop_xml_attr_long (index->properties, PROP_PORTRAIT_H, xml, "/gallery/general/images", "portrait_h");
- index->border_style = xml_file_get_node_attribute (xml, "/gallery/general/border", "style");
+ prop_xml_attr (index->properties, PROP_BORDER_STYLE, xml, "/gallery/general/border", "style");
index->meta_author = xml_file_get_node_value (xml, "/gallery/general/meta/author/text()");
index->meta_description = xml_file_get_node_value (xml, "/gallery/general/meta/description/text()");
index->meta_keywords = xml_file_get_node_value (xml, "/gallery/general/meta/keywords/text()");
s = xml_file_get_node_attribute (xml, "/gallery/general/metadata/timezone", "shift");
if (s != NULL) {
- index->metadata_tz_shift = parse_timezone_string (s);
+ properties_table_add_int (index->properties, PROP_METADATA_TZ_SHIFT, parse_timezone_string (s));
g_free (s);
}
- index->metadata_override_datetime = (time_t) -1;
s = xml_file_get_node_attribute (xml, "/gallery/general/metadata/override", "date");
if (s != NULL) {
- index->metadata_override_datetime = parse_datetime_string (s);
+ properties_table_add_double (index->properties, PROP_METADATA_OVERRIDE_DATETIME, parse_datetime_string (s));
g_free (s);
}
- index->metadata_override_aperture = xml_file_get_node_attribute_double (xml, "/gallery/general/metadata/override", "aperture", -1);
- index->metadata_override_focal_length = xml_file_get_node_attribute_double (xml, "/gallery/general/metadata/override", "focal_length", -1);
+ prop_xml_attr_double (index->properties, PROP_METADATA_OVERRIDE_APERTURE, xml, "/gallery/general/metadata/override", "aperture");
+ prop_xml_attr_double (index->properties, PROP_METADATA_OVERRIDE_FOCAL_LENGTH, xml, "/gallery/general/metadata/override", "focal_length");
/* TODO: add support for lens name */
s = xml_file_get_node_attribute (xml, "/gallery/general/thumbnail", "crop");
if (s != NULL) {
- index->thumbnail_crop_hint = parse_thumbnail_crop_hint (s);
+ properties_table_add_int (index->properties, PROP_THUMB_CROP_HINT, parse_thumbnail_crop_hint (s));
g_free (s);
}
@@ -253,6 +253,7 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
continue;
item = g_malloc0 (sizeof (TIndexItem));
+ item->properties = properties_table_new ();
if (strcmp (node_name, "item") == 0) {
item->type = INDEX_ITEM_TYPE_PICTURE;
@@ -263,10 +264,10 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
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");
+ prop_xml_attr_long (item->properties, PROP_QUALITY, xml, s, "quality");
+ prop_xml_attr_long (item->properties, PROP_WIDTH, xml, s, "width");
+ prop_xml_attr_long (item->properties, PROP_HEIGHT, xml, s, "height");
+ prop_xml_attr (item->properties, PROP_BORDER_STYLE, xml, s, "border");
if (index->type == GALLERY_TYPE_ALBUM)
item->thumbnail = xml_file_get_node_attribute (xml, s, "thumbnail");
g_free (s);
@@ -325,19 +326,18 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
s2 = xml_file_get_node_attribute (xml, s, "shift");
g_free (s);
if (s2 != NULL) {
- item->metadata_tz_shift = parse_timezone_string (s2);
+ properties_table_add_int (item->properties, PROP_METADATA_TZ_SHIFT, parse_timezone_string (s2));
g_free (s2);
}
- item->metadata_override_datetime = (time_t) -1;
s = g_strdup_printf ("/gallery/items/*[%d]/metadata/override", i + 1);
s2 = xml_file_get_node_attribute (xml, s, "date");
if (s2 != NULL) {
- item->metadata_override_datetime = parse_datetime_string (s2);
+ properties_table_add_double (item->properties, PROP_METADATA_OVERRIDE_DATETIME, parse_datetime_string (s2));
g_free (s2);
}
- item->metadata_override_aperture = xml_file_get_node_attribute_double (xml, s, "aperture", -1);
- item->metadata_override_focal_length = xml_file_get_node_attribute_double (xml, s, "focal_length", -1);
+ prop_xml_attr_double (item->properties, PROP_METADATA_OVERRIDE_APERTURE, xml, s, "aperture");
+ prop_xml_attr_double (item->properties, PROP_METADATA_OVERRIDE_FOCAL_LENGTH, xml, s, "focal_length");
/* TODO: add support for lens name */
g_free (s);
@@ -345,7 +345,7 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info)
s2 = xml_file_get_node_attribute (xml, s, "crop");
g_free (s);
if (s2 != NULL) {
- item->thumbnail_crop_hint = parse_thumbnail_crop_hint (s2);
+ properties_table_add_int (item->properties, PROP_THUMB_CROP_HINT, parse_thumbnail_crop_hint (s2));
g_free (s2);
}
@@ -408,8 +408,8 @@ dup_index_item (TIndexItem *item)
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);
+ i->properties = properties_table_dup (item->properties);
return i;
}
@@ -426,8 +426,8 @@ free_index_item (TIndexItem *item)
g_free (item->title_description);
g_free (item->thumbnail);
g_free (item->preview);
- g_free (item->border_style);
g_free (item->metadata_external_exif);
+ properties_table_free (item->properties);
g_free (item);
}
}
@@ -443,7 +443,6 @@ free_album_data (TAlbum *album)
g_free (album->title);
g_free (album->desc);
g_free (album->footnote);
- g_free (album->border_style);
g_free (album->meta_author);
g_free (album->meta_description);
g_free (album->meta_keywords);
@@ -456,6 +455,7 @@ free_album_data (TAlbum *album)
g_ptr_array_foreach (album->items, (GFunc) free_index_item, NULL);
g_ptr_array_free (album->items, TRUE);
}
+ properties_table_free (album->properties);
g_free (album);
}
}
@@ -565,3 +565,62 @@ free_path_info (TPathInfo *path_info)
g_free (path_info);
}
}
+
+
+/*
+ * get_prop_*: retrieve attribute value from properties tables, with item taking priority, using items otherwise or falling back to default if not set anywhere
+ */
+gchar *
+get_prop_string (TAlbum *items, TIndexItem *item, PropertyName name, const gchar *_default)
+{
+ const gchar *s = NULL;
+
+ if (item)
+ s = properties_table_get_string (item->properties, name);
+ if (!s && items)
+ s = properties_table_get_string (items->properties, name);
+
+ return g_strdup (s ? s : _default);
+}
+
+long int
+get_prop_int (TAlbum *items, TIndexItem *item, PropertyName name, const long int _default)
+{
+ long int i = _default;
+ gboolean res = FALSE;
+
+ if (item)
+ res = properties_table_get_int (item->properties, name, &i);
+ if (!res && items)
+ res = properties_table_get_int (items->properties, name, &i);
+
+ return i;
+}
+
+gboolean
+get_prop_bool (TAlbum *items, TIndexItem *item, PropertyName name, const gboolean _default)
+{
+ gboolean b = _default;
+ gboolean res = FALSE;
+
+ if (item)
+ res = properties_table_get_bool (item->properties, name, &b);
+ if (!res && items)
+ res = properties_table_get_bool (items->properties, name, &b);
+
+ return b;
+}
+
+double
+get_prop_double (TAlbum *items, TIndexItem *item, PropertyName name, const double _default)
+{
+ double d = _default;
+ gboolean res = FALSE;
+
+ if (item)
+ res = properties_table_get_double (item->properties, name, &d);
+ if (!res && items)
+ res = properties_table_get_double (items->properties, name, &d);
+
+ return d;
+}