summaryrefslogtreecommitdiff
path: root/src/items.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2013-03-10 19:08:58 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2013-03-10 19:08:58 +0100
commit13459096ccf173a4251b4e1ad6fdebaf61b33afd (patch)
treec0f1176a93586bcae4d16bb6cb540967dff2cffa /src/items.c
parent6468dd6da3764498fcabbf99603f50974f26c2c6 (diff)
downloadcataract-13459096ccf173a4251b4e1ad6fdebaf61b33afd.tar.xz
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.
Diffstat (limited to 'src/items.c')
-rw-r--r--src/items.c52
1 files changed, 50 insertions, 2 deletions
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
@@ -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 {