From 29381f9e70d122ea4d89d71ea97f42253c528211 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 7 May 2017 15:21:39 +0200 Subject: jpeg-utils: Allow custom datetime format The default locale datetime format string may not suit everyone, this adds possibility to specify custom format. The format string should be syntactically conforming to strftime(3). --- sample/src/setup.xml | 6 ++++++ src/generators.c | 2 ++ src/jpeg-utils.cpp | 4 ++-- src/jpeg-utils.h | 1 + src/setup.c | 2 ++ src/setup.h | 1 + 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sample/src/setup.xml b/sample/src/setup.xml index 54bfb5b..f36b01b 100644 --- a/sample/src/setup.xml +++ b/sample/src/setup.xml @@ -72,6 +72,12 @@ And the second line. John Doe + + + + + + diff --git a/src/generators.c b/src/generators.c index ed525cf..5ab5765 100644 --- a/src/generators.c +++ b/src/generators.c @@ -320,6 +320,8 @@ metadata_apply_overrides (ExifData *exif_data, exif_data->thumbnail_crop_hint = get_prop_int (items, item, PROP_THUMB_CROP_HINT, CROP_HINT_UNDEFINED); exif_data->shave_amount = get_prop_int (items, item, PROP_SHAVE_AMOUNT, 0); + + exif_data->datetime_format = setup->datetime_format; } static char * diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index e9e1e65..61aeebd 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -289,7 +289,7 @@ get_exif_data_fixed (ExifData *exif, const gchar *key) if (exif->override_datetime != (time_t) -1) { tt = (struct tm *) g_malloc0 (sizeof (struct tm)); localtime_r (&exif->override_datetime, tt); - if (strftime (&conv[0], sizeof (conv), "%c", tt)) + if (strftime (&conv[0], sizeof (conv), exif->datetime_format ? exif->datetime_format : "%c", tt)) res = g_strdup (&conv[0]); } @@ -297,7 +297,7 @@ get_exif_data_fixed (ExifData *exif, const gchar *key) tt = parse_exif_date (val); if (tt) { shift_time (tt, exif->timezone_shift); - if (strftime (&conv[0], sizeof (conv), "%c", tt)) + if (strftime (&conv[0], sizeof (conv), exif->datetime_format ? exif->datetime_format : "%c", tt)) res = g_strdup (&conv[0]); } } diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h index b4ead79..767320a 100644 --- a/src/jpeg-utils.h +++ b/src/jpeg-utils.h @@ -58,6 +58,7 @@ typedef struct { double override_focal_length; gchar *override_artist_name; gchar *external_exif_data; + const gchar *datetime_format; TCropStyle thumbnail_crop_style; TCropHint thumbnail_crop_hint; int shave_amount; diff --git a/src/setup.c b/src/setup.c index cf23044..85c7326 100644 --- a/src/setup.c +++ b/src/setup.c @@ -113,6 +113,7 @@ parse_setup_xml (const gchar *filename) setup->site_title = xml_file_get_node_attribute (xml, "/gallery_setup/meta/site", "title"); setup->add_copyright = xml_file_get_node_value (xml, "/gallery_setup/meta/add_copyright/text()"); setup->meta_artist_name = xml_file_get_node_value (xml, "/gallery_setup/meta/artist_name/text()"); + setup->datetime_format = xml_file_get_node_attribute (xml, "/gallery_setup/meta/datetime", "format"); setup->favicon_file = xml_file_get_node_value (xml, "/gallery_setup/meta/favicon/text()"); setup->favicon_type = xml_file_get_node_attribute (xml, "/gallery_setup/meta/favicon", "type"); @@ -685,6 +686,7 @@ free_setup_data (TGallerySetup *setup) g_free (setup->site_title); g_free (setup->add_copyright); g_free (setup->meta_artist_name); + g_free (setup->datetime_format); g_free (setup->favicon_file); g_free (setup->favicon_type); g_free (setup->feed_filename); diff --git a/src/setup.h b/src/setup.h index 730c035..009566a 100644 --- a/src/setup.h +++ b/src/setup.h @@ -74,6 +74,7 @@ typedef struct { gchar *site_title; gchar *add_copyright; gchar *meta_artist_name; + gchar *datetime_format; gchar *favicon_file; gchar *favicon_type; -- cgit v1.2.3