1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/* Eye Of Gnome - EXIF Utilities
*
* Copyright (C) 2006-2007 The Free Software Foundation
*
* Author: Lucas Rocha <lucasr@gnome.org>
* Author: Claudio Saavedra <csaavedra@alumnos.utalca.cl>
* Author: Felix Riemann <felix@hsgheli.de>
*
* Based on code by:
* - Jens Finke <jens@gnome.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STRPTIME
#define _XOPEN_SOURCE
#endif
#include <time.h>
#include "eog-exif-util.h"
#include <string.h>
#include <glib/gi18n.h>
#define DATE_BUF_SIZE 200
#ifdef HAVE_STRPTIME
static gchar *
eog_exif_util_format_date_with_strptime (const gchar *date)
{
gchar *new_date = NULL;
gchar tmp_date[DATE_BUF_SIZE];
gchar *p;
gsize dlen;
struct tm tm;
memset (&tm, '\0', sizeof (tm));
p = strptime (date, "%Y:%m:%d %T", &tm);
if (p == date + strlen (date)) {
/* 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);
new_date = g_strndup (tmp_date, dlen);
}
return new_date;
}
#else
static gchar *
eog_exif_util_format_date_by_hand (const gchar *date)
{
int year, month, day, hour, minutes, seconds;
int result;
gchar *new_date = NULL;
result = sscanf (date, "%d:%d:%d %d:%d:%d",
&year, &month, &day, &hour, &minutes, &seconds);
if (result < 3 || !g_date_valid_dmy (day, month, year)) {
return NULL;
} else {
gchar tmp_date[DATE_BUF_SIZE];
gsize dlen;
time_t secs;
struct tm tm;
memset (&tm, '\0', sizeof (tm));
tm.tm_mday = day;
tm.tm_mon = month-1;
tm.tm_year = year-1900;
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);
}
if (dlen == 0)
return NULL;
else
new_date = g_strndup (tmp_date, dlen);
}
return new_date;
}
#endif /* HAVE_STRPTIME */
gchar *
eog_exif_util_format_date (const gchar *date)
{
gchar *new_date;
#ifdef HAVE_STRPTIME
new_date = eog_exif_util_format_date_with_strptime (date);
#else
new_date = eog_exif_util_format_date_by_hand (date);
#endif /* HAVE_STRPTIME */
return new_date;
}
const gchar *
eog_exif_util_get_value (ExifData *exif_data, gint tag_id, gchar *buffer, guint buf_size)
{
ExifEntry *exif_entry;
const gchar *exif_value;
exif_entry = exif_data_get_entry (exif_data, tag_id);
buffer[0] = 0;
exif_value = exif_entry_get_value (exif_entry, buffer, buf_size);
return exif_value;
}
|