[gthumb/ext] added ability to sort by digitalization date



commit df3653958eb7d40581b8a9179a0707dc1d2989d8
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Sep 22 12:41:58 2009 +0200

    added ability to sort by digitalization date
    
    [bug #594163]

 extensions/exiv2/main.c |   38 +++++++++++++++++++++++++++++++++++
 gthumb/glib-utils.c     |    4 ++-
 gthumb/gth-file-data.c  |   50 ++++++++++++++++++++++++++++++++++++++++++++++-
 gthumb/gth-file-data.h  |    2 +
 4 files changed, 92 insertions(+), 2 deletions(-)
---
diff --git a/extensions/exiv2/main.c b/extensions/exiv2/main.c
index bb96292..ad3d744 100644
--- a/extensions/exiv2/main.c
+++ b/extensions/exiv2/main.c
@@ -188,15 +188,53 @@ exiv2_jpeg_tran_cb (void         **out_buffer,
 }
 
 
+
+
+
+static int
+gth_file_data_cmp_date_time_original (GthFileData *a,
+				      GthFileData *b)
+{
+	GTimeVal *pta, *ptb;
+	GTimeVal  ta, tb;
+
+	pta = NULL;
+	if (gth_file_data_get_digitalization_time (a, &ta))
+		pta = &ta;
+	if (pta == NULL)
+		pta = gth_file_data_get_modification_time (a);
+
+	ptb = NULL;
+	if (gth_file_data_get_digitalization_time (b, &tb))
+		ptb = &tb;
+	if (ptb == NULL)
+		ptb = gth_file_data_get_modification_time (b);
+
+	return _g_time_val_cmp (pta, ptb);
+}
+
+
+GthFileDataSort exiv2_sort_types[] = {
+	{ "exif::photo::datetimeoriginal", N_("photo digitalization"),
+	  "Exif::Photo::DateTimeOriginal,Exif::Photo::DateTimeDigitized",
+	  gth_file_data_cmp_date_time_original }
+};
+
+
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
+	int i;
+
 	gth_main_register_metadata_category (exiv2_metadata_category);
 	gth_main_register_metadata_info_v (exiv2_metadata_info);
 	gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_EXIV2);
 	gth_hook_add_callback ("save-pixbuf", 10, G_CALLBACK (exiv2_write_metadata), NULL);
 	if (gth_hook_present ("jpegtran-after"))
 		gth_hook_add_callback ("jpegtran-after", 10, G_CALLBACK (exiv2_jpeg_tran_cb), NULL);
+
+	for (i = 0; i < G_N_ELEMENTS (exiv2_sort_types); i++)
+		gth_main_register_sort_type (&exiv2_sort_types[i]);
 }
 
 
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index 3e5d8ea..077b6d0 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -363,9 +363,11 @@ _g_time_val_from_exif_date (const char *exif_date,
 	struct tm tm;
 	long   val;
 
-	g_return_val_if_fail (exif_date != NULL, FALSE);
 	g_return_val_if_fail (time_ != NULL, FALSE);
 
+	if (exif_date == NULL)
+		return FALSE;
+
 	while (g_ascii_isspace (*exif_date))
 		exif_date++;
 
diff --git a/gthumb/gth-file-data.c b/gthumb/gth-file-data.c
index a3ba5e0..054ab2e 100644
--- a/gthumb/gth-file-data.c
+++ b/gthumb/gth-file-data.c
@@ -32,7 +32,8 @@
 #define GTH_FILE_DATA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_FILE_DATA, GthFileDataPrivate))
 
 struct _GthFileDataPrivate {
-	GTimeVal  mtime;
+	GTimeVal  mtime;   /* modification time */
+	GTimeVal  dtime;   /* digitalization time */
 	char     *sort_key;
 };
 
@@ -68,6 +69,7 @@ static void
 gth_file_data_instance_init (GthFileData *self)
 {
 	self->priv = GTH_FILE_DATA_GET_PRIVATE (self);
+	self->priv->dtime.tv_sec = 0;
 }
 
 
@@ -197,6 +199,8 @@ gth_file_data_set_info (GthFileData *self,
 		self->info = info;
 	else
 		self->info = g_file_info_new ();
+
+	self->priv->dtime.tv_sec = 0;
 }
 
 
@@ -260,6 +264,48 @@ gth_file_data_get_modification_time (GthFileData *self)
 }
 
 
+static const char *try_digitalization_tag[] = {
+	"Exif::Photo::DateTimeOriginal",
+	"Xmp::exif::DateTimeOriginal",
+	"Exif::Photo::DateTimeDigitized",
+	"Xmp::exif::DateTimeDigitized",
+	"Xmp::xmp::CreateDate",
+	"Xmp::photoshop::DateCreated",
+	"Xmp::xmp::ModifyDate",
+	"Xmp::xmp::MetadataDate",
+	NULL
+};
+
+
+gboolean
+gth_file_data_get_digitalization_time (GthFileData *self,
+				       GTimeVal    *_time)
+{
+	int i;
+
+	if (self->priv->dtime.tv_sec != 0) {
+		*_time = self->priv->dtime;
+		return TRUE;
+	}
+
+	for (i = 0; try_digitalization_tag[i] != NULL; i++) {
+		GthMetadata *m;
+
+		m = (GthMetadata *) g_file_info_get_attribute_object (self->info, try_digitalization_tag[i]);
+		if (m == NULL)
+			continue;
+
+		if (! _g_time_val_from_exif_date (gth_metadata_get_raw (m), &self->priv->dtime))
+			continue;
+
+		*_time = self->priv->dtime;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+
 gboolean
 gth_file_data_is_readable (GthFileData *self)
 {
@@ -280,6 +326,8 @@ gth_file_data_update_info (GthFileData *fd,
 
 	if (fd->info == NULL)
 		fd->info = g_file_info_new ();
+
+	fd->priv->dtime.tv_sec = 0;
 }
 
 
diff --git a/gthumb/gth-file-data.h b/gthumb/gth-file-data.h
index 52e170e..a55bafd 100644
--- a/gthumb/gth-file-data.h
+++ b/gthumb/gth-file-data.h
@@ -83,6 +83,8 @@ const char *  gth_file_data_get_mime_type           (GthFileData    *self);
 const char *  gth_file_data_get_filename_sort_key   (GthFileData    *self);
 time_t        gth_file_data_get_mtime               (GthFileData    *self);
 GTimeVal *    gth_file_data_get_modification_time   (GthFileData    *self);
+gboolean      gth_file_data_get_digitalization_time (GthFileData    *self,
+				                     GTimeVal       *_time);
 gboolean      gth_file_data_is_readable             (GthFileData    *self);
 void          gth_file_data_update_info             (GthFileData    *self,
 						     const char     *attributes);



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