Mercurial > hg > forks > geeqie
changeset 1946:a2cded8d3e90
Cleanup Exif Date sorting patch.
Fix a memleak, and move a part of the code from set_exif_time_data() to read_exif_time_data()
author | Laurent Monin <geeqie@norz.org> |
---|---|
date | Thu, 23 Dec 2010 01:56:47 +0100 |
parents | 184f58cf9e30 |
children | a40854a0b58c |
files | src/filedata.c |
diffstat | 1 files changed, 44 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/filedata.c Thu Dec 23 00:38:40 2010 +0100 +++ b/src/filedata.c Thu Dec 23 01:56:47 2010 +0100 @@ -400,7 +400,8 @@ return ret; } -void init_exif_time_data(GList *files) { +void init_exif_time_data(GList *files) +{ FileData *file; DEBUG_1("%s init_exif_time_data: ...", get_exec_time()); while (files) @@ -414,47 +415,52 @@ } } -void set_exif_time_data(GList *files) { - gchar *tmp; - uint year, month, day, hour, min, sec; - struct tm time_str; - FileData *file; +void read_exif_time_data(FileData *file) +{ + if (file->exifdate > 0) + { + DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path); + return; + } + + file->exif = exif_read_fd(file); + + if (file->exif) + { + gchar *tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal"); + DEBUG_2("%s set_exif_time_data: reading %p %s", get_exec_time(), file, file->path); + + if (tmp) + { + struct tm time_str; + uint year, month, day, hour, min, sec; + + sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec); + time_str.tm_year = year - 1900; + time_str.tm_mon = month - 1; + time_str.tm_mday = day; + time_str.tm_hour = hour; + time_str.tm_min = min; + time_str.tm_sec = sec; + time_str.tm_isdst = 0; + + file->exifdate = mktime(&time_str); + g_free(tmp); + } + } +} + +void set_exif_time_data(GList *files) +{ DEBUG_1("%s set_exif_time_data: ...", get_exec_time()); + while (files) { - file = files->data; - - if (file->exifdate > 0) - { - files = files->next; - DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path); - continue; - } - - DEBUG_1("%s set_exif_time_data: Getting exiftime for %s", get_exec_time(), file->path); - - file->exif = exif_read_fd(file); - - if (file->exif) - { - tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal"); - if (tmp) - { - sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec); - time_str.tm_year = year - 1900; - time_str.tm_mon = month - 1; - time_str.tm_mday = day; - time_str.tm_hour = hour; - time_str.tm_min = min; - time_str.tm_sec = sec; - time_str.tm_isdst = 0; - - file->exifdate = mktime(&time_str); - } - } + FileData *file = files->data; + + read_exif_time_data(file); files = files->next; } - } FileData *file_data_new_no_grouping(const gchar *path_utf8) @@ -1065,6 +1071,7 @@ g_free(pathl); if (dirs) *dirs = dlist; + if (files) { g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, NULL);