changeset 2434:ddba21e66364

Search on exif date Additional search parameter to search using exif date. The implementation is rather crude. It would be better to have a drop-down box so that other date formats could be also used - e.g. DateTimeDigitized Note: if a file does not have an exif date, it will default to 01 January 1970
author Colin Clark <cclark@mcb.net>
date Mon, 23 Jan 2017 17:40:40 +0000
parents 40e75fe44eac
children eccb275b0175
files src/filedata.h src/search.c
diffstat 2 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.h	Wed Jan 18 13:57:37 2017 +0000
+++ b/src/filedata.h	Mon Jan 23 17:40:40 2017 +0000
@@ -161,5 +161,6 @@
 gboolean file_data_register_real_time_monitor(FileData *fd);
 gboolean file_data_unregister_real_time_monitor(FileData *fd);
 
+void read_exif_time_data(FileData *file);
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/search.c	Wed Jan 18 13:57:37 2017 +0000
+++ b/src/search.c	Mon Jan 23 17:40:40 2017 +0000
@@ -160,6 +160,7 @@
 	GList *search_keyword_list;
 	gchar *search_comment;
 	gboolean   search_comment_match_case;
+	gboolean   search_date_exif;
 
 	MatchType search_type;
 
@@ -1653,6 +1654,7 @@
 	gint width = 0;
 	gint height = 0;
 	gint sim = 0;
+	time_t file_date;
 
 	if (!sd->search_file_list) return FALSE;
 
@@ -1729,11 +1731,21 @@
 		tested = TRUE;
 		match = FALSE;
 
+		if (sd->search_date_exif)
+			{
+			read_exif_time_data(fd);
+			file_date = fd->exifdate;
+			}
+		else
+			{
+			file_date = fd->date;
+			}
+
 		if (sd->match_date == SEARCH_MATCH_EQUAL)
 			{
 			struct tm *lt;
 
-			lt = localtime(&fd->date);
+			lt = localtime(&file_date);
 			match = (lt &&
 				 lt->tm_year == sd->search_date_y - 1900 &&
 				 lt->tm_mon == sd->search_date_m - 1 &&
@@ -1741,11 +1753,11 @@
 			}
 		else if (sd->match_date == SEARCH_MATCH_UNDER)
 			{
-			match = (fd->date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y));
+			match = (file_date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y));
 			}
 		else if (sd->match_date == SEARCH_MATCH_OVER)
 			{
-			match = (fd->date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1);
+			match = (file_date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1);
 			}
 		else if (sd->match_date == SEARCH_MATCH_BETWEEN)
 			{
@@ -1760,7 +1772,7 @@
 				{
 				a += 60 * 60 * 24 - 1;
 				}
-			match = MATCH_IS_BETWEEN(fd->date, a, b);
+			match = MATCH_IS_BETWEEN(file_date, a, b);
 			}
 		}
 
@@ -2688,6 +2700,8 @@
 	date_selection_time_set(sd->date_sel_end, time(NULL));
 	gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0);
 	gtk_widget_show(sd->date_sel_end);
+	pref_checkbox_new_int(hbox, _("Exif date"),
+				sd->search_date_exif, &sd->search_date_exif);
 
 	/* Search for image dimensions */
 	hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions,