gthumb r2202 - in trunk: . libgthumb src



Author: mjc
Date: Sun Jan 20 19:59:00 2008
New Revision: 2202
URL: http://svn.gnome.org/viewvc/gthumb?rev=2202&view=rev

Log:
2008-01-20  Michael J. Chudobiak  <mjc svn gnome org>

        * libgthumb/file-data.c: (file_data_new), (file_data_dup),
        (file_data_unref), (file_data_load_exif_data):
        * libgthumb/file-data.h:
        * libgthumb/gth-exif-utils.c: (metadata_search),
        (get_metadata_time), (have_exif_time), (dup_metadata),
        (update_metadata):
        * libgthumb/gth-exif-utils.h:
        * libgthumb/gth-gstreamer-utils.c: (gth_read_gstreamer):
        * libgthumb/gth-gstreamer-utils.h:
        * src/catalog-png-exporter.c: (image_loader_done):
        * src/catalog-web-exporter.c: (gth_parsed_doc_print),
        (image_loader_done):
        * src/dlg-change-date.c: (exif_time_available), (ok_clicked):
        * src/dlg-comment.c: (get_requested_time),
        (date_optionmenu_changed_cb):
        * src/dlg-photo-importer.c: (save_image):
        * src/dlg-rename-series.c: (get_image_date):
        * src/gth-browser.c: (window_update_statusbar_image_info):
        * src/gth-fullscreen.c: (get_file_info):
        * src/gth-viewer.c: (viewer_update_statusbar_image_info):
        First step towards adding metadata to the FileData structure.
        Metadata is loaded on an as-needed basis. Tweaked version of Natan's
        ghop patch. 
         http://code.google.com/p/google-highly-open-participation-gnome/issues/detail?id=99.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/file-data.c
   trunk/libgthumb/file-data.h
   trunk/libgthumb/gth-exif-utils.c
   trunk/libgthumb/gth-exif-utils.h
   trunk/libgthumb/gth-gstreamer-utils.c
   trunk/libgthumb/gth-gstreamer-utils.h
   trunk/src/catalog-png-exporter.c
   trunk/src/catalog-web-exporter.c
   trunk/src/dlg-change-date.c
   trunk/src/dlg-comment.c
   trunk/src/dlg-photo-importer.c
   trunk/src/dlg-rename-series.c
   trunk/src/gth-browser.c
   trunk/src/gth-fullscreen.c
   trunk/src/gth-viewer.c

Modified: trunk/libgthumb/file-data.c
==============================================================================
--- trunk/libgthumb/file-data.c	(original)
+++ trunk/libgthumb/file-data.c	Sun Jan 20 19:59:00 2008
@@ -82,6 +82,7 @@
 
 	fd->exif_data_loaded = FALSE;
 	fd->exif_time = 0;
+	fd->metadata = NULL;
 
 	fd->error = FALSE;
 	fd->thumb_loaded = FALSE;
@@ -136,6 +137,7 @@
 	fd->mtime = source->mtime;
 	fd->exif_data_loaded = source->exif_data_loaded;
 	fd->exif_time = source->exif_time;
+	fd->metadata = dup_metadata (source->metadata);
 	fd->error = source->error;
 	fd->thumb_loaded = source->thumb_loaded;
 	fd->thumb_created = source->thumb_created;
@@ -145,7 +147,6 @@
 	return fd;
 }
 
-
 void
 file_data_unref (FileData *fd)
 {
@@ -160,6 +161,8 @@
 		if (fd->comment_data != NULL)
 			comment_data_free (fd->comment_data);
 		g_free (fd->comment);
+		if (fd->metadata != NULL)
+			free_metadata (fd->metadata);
 		g_free (fd);
 	}
 }
@@ -283,7 +286,6 @@
 	file_data_update (fd);
 }
 
-
 void
 file_data_load_comment_data (FileData *fd)
 {
@@ -294,7 +296,6 @@
 	fd->comment_data = comments_load_comment (fd->path, FALSE);
 }
 
-
 void
 file_data_load_exif_data (FileData *fd)
 {
@@ -302,13 +303,14 @@
 
 	if (fd->exif_data_loaded)
 		return;
-		
-	fd->exif_time = get_metadata_time (fd->mime_type, fd->path);
-
+	
+	fd->metadata = update_metadata (fd->metadata, fd->path, fd->mime_type);
+	
+	fd->exif_time = get_metadata_time (fd->mime_type, fd->path, fd->metadata);
+	
 	fd->exif_data_loaded = TRUE;
 }
 
-
 void
 file_data_update_comment (FileData *fd)
 {

Modified: trunk/libgthumb/file-data.h
==============================================================================
--- trunk/libgthumb/file-data.h	(original)
+++ trunk/libgthumb/file-data.h	Sun Jan 20 19:59:00 2008
@@ -51,6 +51,8 @@
 
 	char               *comment;
 	CommentData        *comment_data;
+	
+	GList              *metadata;
 } FileData;
 
 #define GTH_TYPE_FILE_DATA (file_data_get_type ())

Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c	(original)
+++ trunk/libgthumb/gth-exif-utils.c	Sun Jan 20 19:59:00 2008
@@ -21,6 +21,7 @@
  */
 
 #include <config.h>
+#include <stdio.h>
 #include <locale.h>
 #include <string.h>
 #include <stdlib.h>
@@ -243,19 +244,64 @@
         return time;
 }
 
+const char *DATE_TAG_NAMES[] = {
+								"DateTimeOriginal",
+								"exif.DateTimeOriginal",
+								"DateTimeDigitized",
+								"exif.DateTimeDigitized"
+								"DateTime",
+								"exif.DateTime",
+								"photoshop.DateCreated"
+								};
+
+gint
+metadata_search (GthMetadata *a,
+			char *b)
+{
+	return strcmp (a->display_name, b);
+}
 
 time_t
 get_metadata_time (const char *mime_type, 
-		   const char *uri)
+		   const char *uri,
+		   GList *md)
 {
 	if (mime_type == NULL)
 		mime_type = get_mime_type (uri);
 
 	if (mime_type_is (mime_type, "image/jpeg"))
-		return get_exif_time (uri);
+	{
+		gboolean loaded_metadata = FALSE;
+		if (md == NULL)
+		{
+			md = update_metadata (NULL, uri, mime_type);
+			loaded_metadata = TRUE;
+		}
+		
+		int i;
+		int len = (sizeof (DATE_TAG_NAMES) / sizeof (DATE_TAG_NAMES[0])) + 1;
+		char *date = NULL;
+		for (i = 0; i < len && date == NULL; i++)
+		{			
+			GList *search_result = g_list_find_custom (md, DATE_TAG_NAMES[i], (GCompareFunc)metadata_search);
+			if (search_result != NULL)
+			{
+				GthMetadata *md_entry = search_result->data;
+				date = g_strdup(md_entry->value);
+			}
+		}
+		
+		if (loaded_metadata)
+			free_metadata(md);
+		
+		if (date != NULL)
+			return exif_string_to_time_t (date);
+		
+		else return (time_t) 0;
+	}
 
-        if (mime_type_is_video (mime_type))
-                return get_mplayer_time (uri);
+	if (mime_type_is_video (mime_type))
+    	return get_mplayer_time (uri);
 
 	return (time_t) 0;
 }
@@ -312,7 +358,7 @@
 gboolean 
 have_exif_time (const char *uri)
 {
-	return get_metadata_time (NULL, uri) != (time_t)0;
+	return get_metadata_time (NULL, uri, NULL) != (time_t)0;
 }
 
 
@@ -726,6 +772,31 @@
 	g_list_free (metadata);
 }
 
+GList * dup_metadata (GList *source_list)
+{	
+	if (source_list == NULL)
+		return NULL;
+	
+	GList *new_list = NULL;
+	
+	while (source_list)
+	{
+		GthMetadata *source_entry = source_list->data;
+		GthMetadata *new_entry = g_new0 (GthMetadata, 1);
+		
+		new_entry->writeable_path = g_strdup (source_entry->writeable_path);
+		new_entry->display_name = g_strdup (source_entry->display_name);
+		new_entry->value = g_strdup (source_entry->value);
+		new_entry->category = source_entry->category;
+		new_entry->position = source_entry->position;
+		
+		new_list = g_list_prepend (new_list, new_entry);
+		
+		source_list = source_list->next;
+	}
+		
+	return g_list_reverse (new_list);
+}
 
 GList * read_exiv2_file (const char *uri, GList *metadata);
 GList * read_exiv2_sidecar (const char *uri, GList *metadata);
@@ -777,7 +848,7 @@
 
 
 GList * 
-update_metadata (GList *metadata, char *uri, const char *mime_type) 
+update_metadata (GList *metadata, const char *uri, const char *mime_type) 
 { 
         char  *local_file = NULL; 
 	
@@ -786,13 +857,12 @@
 
         if (mime_type_is_image (mime_type)) 
                 metadata = gth_read_exiv2 (uri, metadata); 
- 	else if ( mime_type_is_audio (mime_type) || mime_type_is_video (mime_type)) 
-                metadata = gth_read_gstreamer (uri, metadata); 
+	else if ( mime_type_is_audio (mime_type) || mime_type_is_video (mime_type))
+ 		metadata = gth_read_gstreamer (uri, metadata);
  
         /* Sort alphabetically by tag name. The "position" value will 
            override this sorting, if position is non-zero. */ 
         metadata = g_list_sort (metadata, (GCompareFunc) sort_by_tag_name); 
  
         return metadata; 
-} 
-
+}

Modified: trunk/libgthumb/gth-exif-utils.h
==============================================================================
--- trunk/libgthumb/gth-exif-utils.h	(original)
+++ trunk/libgthumb/gth-exif-utils.h	Sun Jan 20 19:59:00 2008
@@ -75,8 +75,9 @@
 ExifData     *gth_exif_data_new_from_uri  (const char   *path);
 char *        get_exif_tag                (const char   *filename,
 				           ExifTag       etag);
-time_t        get_metadata_time           (const char   *mime_type,
-					   const char   *filename);
+time_t        get_metadata_time           (const char *mime_type,
+					   const char *uri,
+					   GList *md);
 char *        get_exif_aperture_value     (const char   *filename);
 gboolean      have_exif_time              (const char   *filename);
 const char   *get_exif_entry_value        (ExifEntry    *entry);
@@ -99,6 +100,7 @@
 					   GList        *metadata);
 void          free_metadata               (GList        *metadata);
 GList *       update_metadata		  (GList 	*metadata, 
-					   char 	*uri,
+					   const char 	*uri,
 					   const char 	*mime_type);
+GList * dup_metadata (GList *source_list);
 #endif /* EXIF_UTILS_H */

Modified: trunk/libgthumb/gth-gstreamer-utils.c
==============================================================================
--- trunk/libgthumb/gth-gstreamer-utils.c	(original)
+++ trunk/libgthumb/gth-gstreamer-utils.c	Sun Jan 20 19:59:00 2008
@@ -692,7 +692,7 @@
 
 
 GList *
-gth_read_gstreamer (gchar *uri, GList *metadata)
+gth_read_gstreamer (const gchar *uri, GList *metadata)
 {
 #ifdef HAVE_GSTREAMER	
 	MetadataExtractor *extractor;

Modified: trunk/libgthumb/gth-gstreamer-utils.h
==============================================================================
--- trunk/libgthumb/gth-gstreamer-utils.h	(original)
+++ trunk/libgthumb/gth-gstreamer-utils.h	Sun Jan 20 19:59:00 2008
@@ -21,6 +21,6 @@
 #ifndef GST_UTILS_H
 #define GST_UTILS_H
 
-GList *gth_read_gstreamer (gchar *uri, GList *metadata);
+GList *gth_read_gstreamer (const gchar *uri, GList *metadata);
 
 #endif /* GST_UTILS_H */

Modified: trunk/src/catalog-png-exporter.c
==============================================================================
--- trunk/src/catalog-png-exporter.c	(original)
+++ trunk/src/catalog-png-exporter.c	Sun Jan 20 19:59:00 2008
@@ -1451,7 +1451,7 @@
 
 	/* time in exif tag, if present */
 
-	idata->exif_time = get_metadata_time (NULL, idata->file->path);
+	idata->exif_time = get_metadata_time (NULL, idata->file->path, NULL);
 
 	/* thumbnail. */
 	idata->thumb = pixbuf = image_loader_get_pixbuf (iloader);

Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c	(original)
+++ trunk/src/catalog-web-exporter.c	Sun Jan 20 19:59:00 2008
@@ -1806,7 +1806,7 @@
 				struct tm *tp;
 				char s[100];
 
-				t = get_metadata_time (NULL, idata->src_file->path);
+				t = get_metadata_time (NULL, idata->src_file->path, NULL);
 				if (t != 0) {
 					tp = localtime (&t);
 					strftime (s, 99, DATE_FORMAT, tp);
@@ -2678,7 +2678,7 @@
 
 	/**/
 
-	idata->exif_time = get_metadata_time (idata->src_file->mime_type, idata->src_file->path);
+	idata->exif_time = get_metadata_time (idata->src_file->mime_type, idata->src_file->path, NULL);
 
 	/* save the image */
 

Modified: trunk/src/dlg-change-date.c
==============================================================================
--- trunk/src/dlg-change-date.c	(original)
+++ trunk/src/dlg-change-date.c	Sun Jan 20 19:59:00 2008
@@ -90,7 +90,7 @@
 
 	fd = data->file_list->data;
 
-	return get_metadata_time (fd->mime_type, fd->path) != 0;
+	return get_metadata_time (fd->mime_type, fd->path, fd->metadata) != 0;
 }
 
 
@@ -122,7 +122,7 @@
 			mtime = get_file_ctime (fdata->path);
 			comment_time = mtime;
 		} else if (is_active (data->cd_exif_radiobutton)) {
-			mtime = get_metadata_time (fdata->mime_type, fdata->path);
+			mtime = get_metadata_time (fdata->mime_type, fdata->path, fdata->metadata);
 			comment_time = mtime;
 		} else if (is_active (data->cd_adjust_timezone_radiobutton)) {
 			time_t tz;

Modified: trunk/src/dlg-comment.c
==============================================================================
--- trunk/src/dlg-comment.c	(original)
+++ trunk/src/dlg-comment.c	Sun Jan 20 19:59:00 2008
@@ -149,7 +149,7 @@
 		t = time (NULL);
 		break;
 	case EXIF_DATE:
-		t = get_metadata_time (NULL, filename);
+		t = get_metadata_time (NULL, filename, NULL);
 		break;
 	case LAST_MODIFIED_DATE:
 		t = get_file_mtime (filename);
@@ -309,7 +309,7 @@
 		break;
 	case EXIF_DATE:
 		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit),
-					  get_metadata_time (NULL, first_image));
+					  get_metadata_time (NULL, first_image, NULL));
 		break;
 	}
 }

Modified: trunk/src/dlg-photo-importer.c
==============================================================================
--- trunk/src/dlg-photo-importer.c	(original)
+++ trunk/src/dlg-photo-importer.c	Sun Jan 20 19:59:00 2008
@@ -1335,7 +1335,7 @@
 			char *dest_folder;
 			
 			/* Name a subfolder based on the exif date */
-			exif_date = get_metadata_time (NULL, local_path);
+			exif_date = get_metadata_time (NULL, local_path, NULL);
 
 			/* Use the file mtime if no exif date if present */
 			if (exif_date == (time_t) 0)

Modified: trunk/src/dlg-rename-series.c
==============================================================================
--- trunk/src/dlg-rename-series.c	(original)
+++ trunk/src/dlg-rename-series.c	Sun Jan 20 19:59:00 2008
@@ -268,7 +268,7 @@
 	struct tm *ltime;
 	char      *stime;
 
-	mtime = get_metadata_time (NULL, filename);
+	mtime = get_metadata_time (NULL, filename, NULL);
 
 	if (mtime == 0)
 		mtime = get_file_mtime (filename);

Modified: trunk/src/gth-browser.c
==============================================================================
--- trunk/src/gth-browser.c	(original)
+++ trunk/src/gth-browser.c	Sun Jan 20 19:59:00 2008
@@ -476,7 +476,7 @@
 		height = 0;
 	}
 
-	timer = get_metadata_time (NULL, priv->image->path);
+	timer = get_metadata_time (NULL, priv->image->path, NULL);
 	if (timer == 0)
 		timer = priv->image->mtime;
 	tm = localtime (&timer);

Modified: trunk/src/gth-fullscreen.c
==============================================================================
--- trunk/src/gth-fullscreen.c	(original)
+++ trunk/src/gth-fullscreen.c	Sun Jan 20 19:59:00 2008
@@ -876,7 +876,7 @@
 
 	zoom = (int) (image_viewer->zoom_level * 100.0);
 
-	timer = get_metadata_time (NULL, image_filename);
+	timer = get_metadata_time (NULL, image_filename, NULL);
 	if (timer == 0)
 		timer = get_file_mtime (image_filename);
 	tm = localtime (&timer);

Modified: trunk/src/gth-viewer.c
==============================================================================
--- trunk/src/gth-viewer.c	(original)
+++ trunk/src/gth-viewer.c	Sun Jan 20 19:59:00 2008
@@ -606,7 +606,7 @@
 		height = 0;
 	}
 
-	timer = get_metadata_time (NULL, priv->image->path);
+	timer = get_metadata_time (NULL, priv->image->path, NULL);
 	if (timer == 0)
 		timer = priv->image->mtime;
 	tm = localtime (&timer);



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