[eog] EogExifUtil: Allow freeform formatting of date strings



commit 93129f1faf5dd6573ae91122ec08b70be5bf25b6
Author: Felix Riemann <friemann gnome org>
Date:   Wed Jan 7 21:59:13 2015 +0100

    EogExifUtil: Allow freeform formatting of date strings

 src/eog-exif-util.c |   55 ++++++++++++++++++++++++++++++++++++--------------
 src/eog-exif-util.h |    4 +++
 2 files changed, 43 insertions(+), 16 deletions(-)
---
diff --git a/src/eog-exif-util.c b/src/eog-exif-util.c
index 24ab5d5..1695872 100644
--- a/src/eog-exif-util.c
+++ b/src/eog-exif-util.c
@@ -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;
 }
@@ -217,6 +213,33 @@ eog_exif_util_set_label_text (GtkLabel *label,
 }
 
 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)
 {
diff --git a/src/eog-exif-util.h b/src/eog-exif-util.h
index 4e4d1c0..5f54a8b 100644
--- a/src/eog-exif-util.h
+++ b/src/eog-exif-util.h
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]