Commit 93129f1f authored by Felix Riemann's avatar Felix Riemann
Browse files

EogExifUtil: Allow freeform formatting of date strings

parent 2e5b0655
......@@ -55,6 +55,7 @@ typedef ExifData EogExifData;
/* Define EogExifData type */
G_DEFINE_BOXED_TYPE(EogExifData, eog_exif_data, eog_exif_data_copy, eog_exif_data_free)
#ifdef HAVE_STRPTIME
static gpointer
_check_strptime_updates_wday (gpointer data)
{
......@@ -65,6 +66,7 @@ _check_strptime_updates_wday (gpointer data)
/* Check if tm.tm_wday is set to Wednesday (3) now */
return GBOOLEAN_TO_POINTER (tm.tm_wday == 3);
}
#endif
/**
* _calculate_wday_yday:
......@@ -95,7 +97,7 @@ _calculate_wday_yday (struct tm *tm)
#ifdef HAVE_STRPTIME
static gchar *
eog_exif_util_format_date_with_strptime (const gchar *date)
eog_exif_util_format_date_with_strptime (const gchar *date, const gchar* format)
{
static GOnce strptime_updates_wday = G_ONCE_INIT;
gchar *new_date = NULL;
......@@ -117,7 +119,7 @@ eog_exif_util_format_date_with_strptime (const gchar *date)
_calculate_wday_yday (&tm);
/* A strftime-formatted string, to display the date the image was taken. */
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y %X"), &tm);
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), format, &tm);
new_date = g_strndup (tmp_date, dlen);
}
......@@ -125,7 +127,7 @@ eog_exif_util_format_date_with_strptime (const gchar *date)
}
#else
static gchar *
eog_exif_util_format_date_by_hand (const gchar *date)
eog_exif_util_format_date_by_hand (const gchar *date, const gchar* format)
{
int year, month, day, hour, minutes, seconds;
int result;
......@@ -139,7 +141,6 @@ eog_exif_util_format_date_by_hand (const gchar *date)
} else {
gchar tmp_date[DATE_BUF_SIZE];
gsize dlen;
time_t secs;
struct tm tm;
memset (&tm, '\0', sizeof (tm));
......@@ -149,16 +150,10 @@ eog_exif_util_format_date_by_hand (const gchar *date)
// Calculate tm.tm_wday
_calculate_wday_yday (&tm);
if (result < 5) {
/* A strftime-formatted string, to display the date the image was taken, for the case we don't have the time. */
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y"), &tm);
} else {
tm.tm_sec = result < 6 ? 0 : seconds;
tm.tm_min = minutes;
tm.tm_hour = hour;
/* A strftime-formatted string, to display the date the image was taken. */
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y %X"), &tm);
}
tm.tm_sec = result < 6 ? 0 : seconds;
tm.tm_min = result < 5 ? 0 : minutes;
tm.tm_hour = result < 4 ? 0 : hour;
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), format, &tm);
if (dlen == 0)
return NULL;
......@@ -184,9 +179,10 @@ eog_exif_util_format_date (const gchar *date)
{
gchar *new_date;
#ifdef HAVE_STRPTIME
new_date = eog_exif_util_format_date_with_strptime (date);
/* A strftime-formatted string, to display the date the image was taken. */
new_date = eog_exif_util_format_date_with_strptime (date, _("%a, %d %B %Y %X"));
#else
new_date = eog_exif_util_format_date_by_hand (date);
new_date = eog_exif_util_format_date_by_hand (date, _("%a, %d %B %Y %X"));
#endif /* HAVE_STRPTIME */
return new_date;
}
......@@ -216,6 +212,33 @@ eog_exif_util_set_label_text (GtkLabel *label,
g_free (label_text);
}
void
eog_exif_util_format_datetime_label (GtkLabel *label, EogExifData *exif_data,
gint tag_id, const gchar *format)
{
gchar exif_buffer[512];
const gchar *buf_ptr;
gchar *label_text = NULL;
g_return_if_fail (GTK_IS_LABEL (label));
g_warn_if_fail (tag_id == EXIF_TAG_DATE_TIME_ORIGINAL);
if (exif_data) {
buf_ptr = eog_exif_data_get_value (exif_data, tag_id,
exif_buffer, 512);
if (tag_id == EXIF_TAG_DATE_TIME_ORIGINAL && buf_ptr)
#ifdef HAVE_STRPTIME
label_text = eog_exif_util_format_date_with_strptime (buf_ptr, format);
#else
label_text = eog_exif_util_format_date_by_hand (buf_ptr, format);
#endif /* HAVE_STRPTIME */
}
gtk_label_set_text (label, label_text);
g_free (label_text);
}
void
eog_exif_util_set_focal_length_label_text (GtkLabel *label,
EogExifData *exif_data)
......
......@@ -37,6 +37,10 @@ G_BEGIN_DECLS
#define EOG_TYPE_EXIF_DATA eog_exif_data_get_type ()
gchar *eog_exif_util_format_date (const gchar *date);
void eog_exif_util_format_datetime_label (GtkLabel *label,
ExifData *exif_data,
gint tag_id,
const gchar *format);
void eog_exif_util_set_label_text (GtkLabel *label,
ExifData *exif_data,
gint tag_id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment