From 13459096ccf173a4251b4e1ad6fdebaf61b33afd Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 10 Mar 2013 19:08:58 +0100 Subject: Add support for specifying custom date This essentially means faking the datetime, e.g. when you want to mask original picture date. This commit also changes little bit of datetime conversion, hopefully fixing DST issues. Needs more testing. --- src/items.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'src/items.c') diff --git a/src/items.c b/src/items.c index 6ac7e56..85f0a26 100644 --- a/src/items.c +++ b/src/items.c @@ -15,9 +15,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#define _XOPEN_SOURCE 600 #include #include #include +#include #include #include @@ -53,6 +55,36 @@ parse_timezone_string (const gchar *str) return hour * 60 + min; } +static time_t +parse_datetime_string (const gchar *str) +{ + struct tm tm; + char *res; + time_t rt; + + memset (&tm, 0, sizeof (struct tm)); + + res = strptime (str, "%Y-%m-%d %H:%M:%S", &tm); + if (res == NULL || *res != '\0') { + res = strptime (str, "%Y:%m:%d %H:%M:%S", &tm); + if (res == NULL || *res != '\0') { + res = strptime (str, "%Y-%m-%dT%H:%M:%S", &tm); + if (res == NULL || res < str + 19) { + log_error ("Invalid datetime string \"%s\", ignoring.\n", str); + return (time_t) -1; + } + } + } + + /* EXIF datetime carries no DST information while mktime() will correct + * the tm_isdst field resulting in unnecessary +- 1 hour shift. */ + rt = mktime (&tm); + if (tm.tm_isdst) + rt -= 60*60; + + return rt; +} + /* * parse_album_xml: XML parser for gallery index.xml files @@ -118,8 +150,15 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info) s = xml_file_get_node_attribute (xml, "/gallery/general/metadata/timezone", "shift"); if (s != NULL) { - index->metadata_tz_shift = parse_timezone_string (s2); - g_free (s2); + index->metadata_tz_shift = parse_timezone_string (s); + g_free (s); + } + + index->metadata_fake_datetime = (time_t) -1; + s = xml_file_get_node_attribute (xml, "/gallery/general/metadata/fake", "date"); + if (s != NULL) { + index->metadata_fake_datetime = parse_datetime_string (s); + g_free (s); } @@ -258,6 +297,15 @@ parse_album_xml (const gchar *filename, TPathInfo *path_info) g_free (s2); } + item->metadata_fake_datetime = (time_t) -1; + s = g_strdup_printf ("/gallery/items/*[%d]/metadata/fake", i + 1); + s2 = xml_file_get_node_attribute (xml, s, "date"); + g_free (s); + if (s2 != NULL) { + item->metadata_fake_datetime = parse_datetime_string (s2); + g_free (s2); + } + if (item->path || item->preview) { g_ptr_array_add (index->items, item); } else { -- cgit v1.2.3