Skip to content

Commit 1e96c9d

Browse files
fxriraveit65
authored andcommitted
EomExifUtil: Allow freeform formatting of date strings
origin commit: https://gitlab.gnome.org/GNOME/eog/commit/93129f1
1 parent 9b4890e commit 1e96c9d

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/eom-exif-util.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ _calculate_wday_yday (struct tm *tm)
9797

9898
#ifdef HAVE_STRPTIME
9999
static gchar *
100-
eom_exif_util_format_date_with_strptime (const gchar *date)
100+
eom_exif_util_format_date_with_strptime (const gchar *date, const gchar* format)
101101
{
102102
static GOnce strptime_updates_wday = G_ONCE_INIT;
103103
gchar *new_date = NULL;
@@ -119,15 +119,15 @@ eom_exif_util_format_date_with_strptime (const gchar *date)
119119
_calculate_wday_yday (&tm);
120120

121121
/* A strftime-formatted string, to display the date the image was taken. */
122-
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y %X"), &tm);
122+
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), format, &tm);
123123
new_date = g_strndup (tmp_date, dlen);
124124
}
125125

126126
return new_date;
127127
}
128128
#else
129129
static gchar *
130-
eom_exif_util_format_date_by_hand (const gchar *date)
130+
eom_exif_util_format_date_by_hand (const gchar *date, const gchar* format)
131131
{
132132
int year, month, day, hour, minutes, seconds;
133133
int result;
@@ -141,7 +141,6 @@ eom_exif_util_format_date_by_hand (const gchar *date)
141141
} else {
142142
gchar tmp_date[DATE_BUF_SIZE];
143143
gsize dlen;
144-
time_t secs;
145144
struct tm tm;
146145

147146
memset (&tm, '\0', sizeof (tm));
@@ -151,16 +150,10 @@ eom_exif_util_format_date_by_hand (const gchar *date)
151150
// Calculate tm.tm_wday
152151
_calculate_wday_yday (&tm);
153152

154-
if (result < 5) {
155-
/* A strftime-formatted string, to display the date the image was taken, for the case we don't have the time. */
156-
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y"), &tm);
157-
} else {
158-
tm.tm_sec = result < 6 ? 0 : seconds;
159-
tm.tm_min = minutes;
160-
tm.tm_hour = hour;
161-
/* A strftime-formatted string, to display the date the image was taken. */
162-
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), _("%a, %d %B %Y %X"), &tm);
163-
}
153+
tm.tm_sec = result < 6 ? 0 : seconds;
154+
tm.tm_min = result < 5 ? 0 : minutes;
155+
tm.tm_hour = result < 4 ? 0 : hour;
156+
dlen = strftime (tmp_date, DATE_BUF_SIZE * sizeof(gchar), format, &tm);
164157

165158
if (dlen == 0)
166159
return NULL;
@@ -186,9 +179,10 @@ eom_exif_util_format_date (const gchar *date)
186179
{
187180
gchar *new_date;
188181
#ifdef HAVE_STRPTIME
189-
new_date = eom_exif_util_format_date_with_strptime (date);
182+
/* A strftime-formatted string, to display the date the image was taken. */
183+
new_date = eom_exif_util_format_date_with_strptime (date, _("%a, %d %B %Y %X"));
190184
#else
191-
new_date = eom_exif_util_format_date_by_hand (date);
185+
new_date = eom_exif_util_format_date_by_hand (date, _("%a, %d %B %Y %X"));
192186
#endif /* HAVE_STRPTIME */
193187
return new_date;
194188
}
@@ -218,6 +212,33 @@ eom_exif_util_set_label_text (GtkLabel *label,
218212
g_free (label_text);
219213
}
220214

215+
void
216+
eom_exif_util_format_datetime_label (GtkLabel *label, EomExifData *exif_data,
217+
gint tag_id, const gchar *format)
218+
{
219+
gchar exif_buffer[512];
220+
const gchar *buf_ptr;
221+
gchar *label_text = NULL;
222+
223+
g_return_if_fail (GTK_IS_LABEL (label));
224+
g_warn_if_fail (tag_id == EXIF_TAG_DATE_TIME_ORIGINAL);
225+
226+
if (exif_data) {
227+
buf_ptr = eom_exif_data_get_value (exif_data, tag_id,
228+
exif_buffer, 512);
229+
230+
if (tag_id == EXIF_TAG_DATE_TIME_ORIGINAL && buf_ptr)
231+
#ifdef HAVE_STRPTIME
232+
label_text = eom_exif_util_format_date_with_strptime (buf_ptr, format);
233+
#else
234+
label_text = eom_exif_util_format_date_by_hand (buf_ptr, format);
235+
#endif /* HAVE_STRPTIME */
236+
}
237+
238+
gtk_label_set_text (label, label_text);
239+
g_free (label_text);
240+
}
241+
221242
void
222243
eom_exif_util_set_focal_length_label_text (GtkLabel *label,
223244
EomExifData *exif_data)

src/eom-exif-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ G_BEGIN_DECLS
3737
#define EOM_TYPE_EXIF_DATA eom_exif_data_get_type()
3838

3939
gchar *eom_exif_util_format_date (const gchar *date);
40+
void eom_exif_util_format_datetime_label (GtkLabel *label,
41+
ExifData *exif_data,
42+
gint tag_id,
43+
const gchar *format);
4044
void eom_exif_util_set_label_text (GtkLabel *label,
4145
ExifData *exif_data,
4246
gint tag_id);

0 commit comments

Comments
 (0)