gthumb r2229 - in trunk: . libgthumb src



Author: mjc
Date: Tue Jan 29 14:12:50 2008
New Revision: 2229
URL: http://svn.gnome.org/viewvc/gthumb?rev=2229&view=rev

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

        * libgthumb/file-data.c: (file_data_dup):
        * libgthumb/file-data.h:
        * libgthumb/gth-exif-utils.c: (get_exif_time),
        (get_exif_time_or_mtime), (get_metadata_string_from_fd),
        (update_metadata):
        * libgthumb/gth-exif-utils.h:
        * libgthumb/gth-filter.c: (gth_test_match):
        * libgthumb/gth-sort-utils.c: (gth_sort_by_exiftime_then_name):
        * src/catalog-png-exporter.c: (image_loader_done):
        * src/catalog-web-exporter.c: (gth_parsed_doc_print):
        * src/dlg-change-date.c: (exif_time_available), (ok_clicked):
        * src/dlg-comment.c: (get_requested_time),
        (date_optionmenu_changed_cb), (dlg_comment_update):
        * src/dlg-photo-importer.c: (save_image):
        * src/dlg-rename-series.c: (get_image_date):
        * src/dlg-scripts.c: (get_date_strings):
        * src/gth-browser.c: (window_update_statusbar_image_info):
        * src/gth-exif-data-viewer.c: (gth_exif_data_viewer_update):
        * src/gth-fullscreen.c: (get_file_info):
        * src/gth-viewer.c: (viewer_update_statusbar_image_info):

        Hid the metadata caching from most functions. Eliminated the 
        file_data_insert_metadata function, which explicity loaded
        metadata. This is now done automatically by
        get_metadata_string_from_fd. Added two convenience functions,
        get_exif_time (fd) and get_exif_time_or_mtime (fd), which
        also auto-load the metadata cache.



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-filter.c
   trunk/libgthumb/gth-sort-utils.c
   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/dlg-scripts.c
   trunk/src/gth-browser.c
   trunk/src/gth-exif-data-viewer.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	Tue Jan 29 14:12:50 2008
@@ -159,7 +159,7 @@
 	fd->ctime = source->ctime;
 	fd->mtime = source->mtime;
 	fd->exif_data_loaded = FALSE;
-	fd->exif_time = 0;
+	fd->exif_time = (time_t) 0;
 	fd->metadata = NULL;
 	fd->error = source->error;
 	fd->thumb_loaded = source->thumb_loaded;
@@ -325,19 +325,6 @@
 }
 
 void
-file_data_insert_metadata (FileData *fd)
-{
-	g_return_if_fail (fd != NULL);
-
-	if (fd->exif_data_loaded == TRUE)
-		return;
-
-	fd->metadata = update_metadata (fd->metadata, fd->path, fd->mime_type);
-	fd->exif_time = get_metadata_time_from_fd (fd);
-	fd->exif_data_loaded = TRUE;
-}
-
-void
 file_data_update_comment (FileData *fd)
 {
 	g_return_if_fail (fd != NULL);

Modified: trunk/libgthumb/file-data.h
==============================================================================
--- trunk/libgthumb/file-data.h	(original)
+++ trunk/libgthumb/file-data.h	Tue Jan 29 14:12:50 2008
@@ -41,7 +41,9 @@
 	time_t              ctime;
 	time_t              mtime;
 	guint               exif_data_loaded : 1;
-	time_t		    exif_time;
+	time_t		    exif_time;	       /* Do not access this directly. Use
+						  get_exif_time (fd) instead. This is
+						  a cache variable. */
 	guint               error : 1;         /* Whether an error occurred loading
 					        * this file. */
 	guint               thumb_loaded : 1;  /* Whether we have a thumb of this
@@ -73,7 +75,6 @@
 void         file_data_update_all          (FileData         *fd,
 					    gboolean          fast_mime_type);				    
 void         file_data_load_comment_data   (FileData         *fd);
-void         file_data_insert_metadata     (FileData         *fd);
 void         file_data_update_comment      (FileData         *fd);
 
 GList*       file_data_list_from_uri_list  (GList            *list);

Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c	(original)
+++ trunk/libgthumb/gth-exif-utils.c	Tue Jan 29 14:12:50 2008
@@ -46,7 +46,10 @@
         "Xmp.exif.DateTimeDigitized",
         "Exif.Image.DateTime",
         "Xmp.exif.DateTime",
+	"Xmp.xmp.CreateDate",
         "Xmp.photoshop.DateCreated",
+	"Xmp.xmp.ModifyDate",
+	"Xmp.xmp.MetadataDate",
 	NULL };
 
 const char *_EXPTIME_TAG_NAMES[] = {
@@ -130,6 +133,7 @@
 	return new_exif_data;
 }
 
+
 time_t
 exif_string_to_time_t (char *string) 
 {
@@ -176,6 +180,29 @@
 
 
 time_t
+get_exif_time (FileData *fd)
+{
+	/* we cache the exif_time in fd for quicker sorting */
+	update_metadata (fd);
+	return fd->exif_time;
+}
+
+
+time_t
+get_exif_time_or_mtime (FileData *fd) {
+	time_t result;
+
+	update_metadata (fd);
+	result = fd->exif_time;
+
+	if (result == (time_t) 0)
+		result = fd->mtime;
+
+	return result;
+}
+
+
+time_t
 get_metadata_time_from_fd (FileData *fd)
 {
 	char   *date = NULL;
@@ -196,6 +223,8 @@
 	int     i;
 	char   *string = NULL;
 
+	update_metadata (fd);
+
 	for (i = 0; (tagnames[i] != NULL) && (string == NULL); i++) {
 		GList *search_result = g_list_find_custom (fd->metadata, tagnames[i], (GCompareFunc) metadata_search);
 		if (search_result != NULL) {
@@ -205,8 +234,6 @@
 		}
 	}
 		
-	/* Assuming the string will be freed when the caller is
-	 * done with it */
 	return string;
 }
 
@@ -643,22 +670,25 @@
 }
 
 
-GList * 
-update_metadata (GList *metadata, const char *uri, const char *mime_type) 
+void
+update_metadata (FileData *fd) 
 { 
         char  *local_file = NULL; 
 	
-        if (uri == NULL) 
-                return metadata; 
+	/* Have we already read in the metadata? */
+	if (fd->exif_data_loaded == TRUE)
+		return;
 
-        if (mime_type_is_image (mime_type)) 
-                metadata = gth_read_exiv2 (uri, metadata); 
-	else if (mime_type_is_video (mime_type))
- 		metadata = gth_read_gstreamer (uri, metadata);
+        if (mime_type_is_image (fd->mime_type)) 
+                fd->metadata = gth_read_exiv2 (fd->path, fd->metadata); 
+	else if (mime_type_is_video (fd->mime_type))
+ 		fd->metadata = gth_read_gstreamer (fd->path, fd->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; 
+        fd->metadata = g_list_sort (fd->metadata, (GCompareFunc) sort_by_tag_name); 
+ 	fd->exif_data_loaded = TRUE;
+	fd->exif_time = get_metadata_time_from_fd (fd);
+
+        return; 
 }

Modified: trunk/libgthumb/gth-exif-utils.h
==============================================================================
--- trunk/libgthumb/gth-exif-utils.h	(original)
+++ trunk/libgthumb/gth-exif-utils.h	Tue Jan 29 14:12:50 2008
@@ -114,7 +114,5 @@
 				  	   GthTransform  transform);
 GList *       gth_read_exiv2		  (const char   *filename,
 					   GList        *metadata);
-GList *       update_metadata		  (GList 	*metadata, 
-					   const char 	*uri,
-					   const char 	*mime_type);
+void          update_metadata		  (FileData	*fd);
 #endif /* EXIF_UTILS_H */

Modified: trunk/libgthumb/gth-filter.c
==============================================================================
--- trunk/libgthumb/gth-filter.c	(original)
+++ trunk/libgthumb/gth-filter.c	Tue Jan 29 14:12:50 2008
@@ -342,11 +342,7 @@
 		break;
 
 	case GTH_TEST_SCOPE_DATE:
-		file_data_insert_metadata (fdata);
-		if (fdata->exif_time != 0)
-			result = test_date (test, fdata->exif_time);
-		else
-			result = test_date (test, fdata->mtime);
+		result = test_date (test, get_exif_time_or_mtime (fdata));
 		break;
 
 	case GTH_TEST_SCOPE_WIDTH:

Modified: trunk/libgthumb/gth-sort-utils.c
==============================================================================
--- trunk/libgthumb/gth-sort-utils.c	(original)
+++ trunk/libgthumb/gth-sort-utils.c	Tue Jan 29 14:12:50 2008
@@ -93,28 +93,8 @@
 {
 	time_t time1, time2;
 
-	/* To reduce file accesses, the exif time is only recorded in the
-	   FileData structures when absolutely required, rather than when
-	   generating file lists. This reduces wait times when browsing
-	   in other sort modes. */
-
-	/* Update the exif DateTime tags in memory if they haven't been
-	   read yet, or if the file has changed. */
-
-	file_data_insert_metadata (fd1);
-	file_data_insert_metadata (fd2);
-
-	time1 = fd1->exif_time;
-	time2 = fd2->exif_time;
-
-	/* If no exif times are present, use the file mtimes. This is 
-	   important for sorting video files in a sane way. */
-
-	if (time1 == (time_t) 0)
-		time1 = fd1->mtime;
-
-        if (time2 == (time_t) 0)
-		time2 = fd2->mtime;
+	time1 = get_exif_time_or_mtime (fd1);
+	time2 = get_exif_time_or_mtime (fd2);
 
 	if (time1 < time2) return -1;
 	if (time1 > time2) return 1;

Modified: trunk/src/catalog-png-exporter.c
==============================================================================
--- trunk/src/catalog-png-exporter.c	(original)
+++ trunk/src/catalog-png-exporter.c	Tue Jan 29 14:12:50 2008
@@ -1451,8 +1451,7 @@
 
 	/* time in exif tag, if present */
 
-	file_data_insert_metadata (idata->file);
-	idata->exif_time = idata->file->exif_time;
+	idata->exif_time = get_exif_time (idata->file);
 
 	/* 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	Tue Jan 29 14:12:50 2008
@@ -1751,7 +1751,6 @@
 		case GTH_TAG_EXIF_EXPOSURE_TIME:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file, 
 							    TAG_NAME_SETS[EXPTIME_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
@@ -1760,7 +1759,6 @@
 		case GTH_TAG_EXIF_EXPOSURE_MODE:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 							    TAG_NAME_SETS[EXPMODE_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
@@ -1769,7 +1767,6 @@
 		case GTH_TAG_EXIF_FLASH:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 					     		    TAG_NAME_SETS[FLASH_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
@@ -1778,7 +1775,6 @@
 		case GTH_TAG_EXIF_SHUTTER_SPEED:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 							    TAG_NAME_SETS[SHUTTERSPEED_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
@@ -1787,7 +1783,6 @@
 		case GTH_TAG_EXIF_APERTURE_VALUE:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 							    TAG_NAME_SETS[APERTURE_TAG_NAMES]); 
 			write_markup_escape_line (line, fout);
@@ -1796,7 +1791,6 @@
 		case GTH_TAG_EXIF_FOCAL_LENGTH:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 					     		    TAG_NAME_SETS[FOCAL_TAG_NAMES]);
 			write_markup_escape_line (line, fout);
@@ -1810,8 +1804,7 @@
 				struct tm *tp;
 				char s[100];
 
-				file_data_insert_metadata (idata->src_file);
-				t = idata->src_file->exif_time;
+				t = get_exif_time (idata->src_file);
 				if (t != 0) {
 					tp = localtime (&t);
 					strftime (s, 99, DATE_FORMAT, tp);
@@ -1827,7 +1820,6 @@
 		case GTH_TAG_EXIF_CAMERA_MODEL:
 			idx = get_image_idx (tag, ce);
 			idata = g_list_nth (ce->file_list, idx)->data;
-			file_data_insert_metadata (idata->src_file);
 			line = get_metadata_string_from_fd (idata->src_file,
 							    TAG_NAME_SETS[MAKE_TAG_NAMES]);
 			write_markup_escape_line (line, fout);

Modified: trunk/src/dlg-change-date.c
==============================================================================
--- trunk/src/dlg-change-date.c	(original)
+++ trunk/src/dlg-change-date.c	Tue Jan 29 14:12:50 2008
@@ -90,9 +90,7 @@
 
 	fd = data->file_list->data;
 
-	file_data_insert_metadata (fd);
-
-	return (fd->exif_time != 0);
+	return (get_exif_time (fd) != 0);
 }
 
 
@@ -124,8 +122,7 @@
 			mtime = get_file_ctime (fdata->path);
 			comment_time = mtime;
 		} else if (is_active (data->cd_exif_radiobutton)) {
-			file_data_insert_metadata (fdata);
-			mtime = fdata->exif_time;
+			mtime = get_exif_time (fdata);
 			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	Tue Jan 29 14:12:50 2008
@@ -154,8 +154,7 @@
 		t = time (NULL);
 		break;
 	case EXIF_DATE:
-		file_data_insert_metadata (file);
-		t = file->exif_time;
+		t = get_exif_time (file);
 		break;
 	case LAST_MODIFIED_DATE:
 		t = file->mtime;
@@ -321,9 +320,8 @@
 					  file->mtime);
 		break;
 	case EXIF_DATE:
-		file_data_insert_metadata (file);
 		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit),
-					  file->exif_time);
+					  get_exif_time (file));
 		break;
 	}
 	
@@ -483,8 +481,7 @@
 		FileData *file;
 		file = file_data_new (scan->data, NULL);
                 file_data_update_all (file, FALSE);
-                file_data_insert_metadata (file);
-		if (file->exif_time) {
+		if (get_exif_time (file)) {
 			data->have_exif_data = TRUE;
 			break;
 		}

Modified: trunk/src/dlg-photo-importer.c
==============================================================================
--- trunk/src/dlg-photo-importer.c	(original)
+++ trunk/src/dlg-photo-importer.c	Tue Jan 29 14:12:50 2008
@@ -1338,13 +1338,7 @@
 			/* Name a subfolder based on the exif date */
                         file = file_data_new (local_path, NULL);
                         file_data_update_all (file, FALSE);
-			file_data_insert_metadata (file);
-			exif_date = file->exif_time;
-
-			/* Use the file mtime if no exif date if present */
-			if (exif_date == (time_t) 0)
-				exif_date = file->mtime;
-
+			exif_date = get_exif_time_or_mtime (file);
 			file_data_unref (file);
 
 

Modified: trunk/src/dlg-rename-series.c
==============================================================================
--- trunk/src/dlg-rename-series.c	(original)
+++ trunk/src/dlg-rename-series.c	Tue Jan 29 14:12:50 2008
@@ -268,12 +268,7 @@
 	struct tm *ltime;
 	char      *stime;
 
-	file_data_insert_metadata (fd);
-	mtime = fd->exif_time;
-
-	if (mtime == 0)
-		mtime = get_file_mtime (fd->path);
-
+	mtime = get_exif_time_or_mtime (fd);
 	ltime = localtime (&mtime);
 
 	stime = g_new (char, 50 + 1);

Modified: trunk/src/dlg-scripts.c
==============================================================================
--- trunk/src/dlg-scripts.c	(original)
+++ trunk/src/dlg-scripts.c	Tue Jan 29 14:12:50 2008
@@ -244,12 +244,7 @@
 			const gint date_str_replacement_size = date_str->len + 128;
 
 			FileData* fd = file_data_new_from_local_path (filename);
-			file_data_insert_metadata (fd);
-
-			time_t exif_time = fd->exif_time;
-			if (!exif_time)
-				exif_time = fd->mtime;
-
+			time_t exif_time = get_exif_time_or_mtime (fd);
 			file_data_unref(fd);
 
 			gchar date_str_replacement[date_str_replacement_size];

Modified: trunk/src/gth-browser.c
==============================================================================
--- trunk/src/gth-browser.c	(original)
+++ trunk/src/gth-browser.c	Tue Jan 29 14:12:50 2008
@@ -475,11 +475,7 @@
 		height = 0;
 	}
 
-	file_data_insert_metadata (priv->image);
-	timer = priv->image->exif_time;
-
-	if (timer == 0)
-		timer = priv->image->mtime;
+	timer = get_exif_time_or_mtime (priv->image);
 	tm = localtime (&timer);
 	strftime (time_txt, 50, _("%d %B %Y, %H:%M"), tm);
 	utf8_time_txt = g_locale_to_utf8 (time_txt, -1, 0, 0, 0);

Modified: trunk/src/gth-exif-data-viewer.c
==============================================================================
--- trunk/src/gth-exif-data-viewer.c	(original)
+++ trunk/src/gth-exif-data-viewer.c	Tue Jan 29 14:12:50 2008
@@ -443,7 +443,7 @@
 		update_file_info (edv);
 
         /* Now read metadata, if it isn't already loaded */
-	file_data_insert_metadata (file_data);
+	update_metadata (file_data);
 
 	/* Display the data */
         g_list_foreach (file_data->metadata, (GFunc) add_to_display, edv);

Modified: trunk/src/gth-fullscreen.c
==============================================================================
--- trunk/src/gth-fullscreen.c	(original)
+++ trunk/src/gth-fullscreen.c	Tue Jan 29 14:12:50 2008
@@ -877,11 +877,7 @@
 	zoom = (int) (image_viewer->zoom_level * 100.0);
 
 	FileData *current_file = fullscreen->priv->current->data;
-	file_data_insert_metadata (current_file);
-	timer = current_file->exif_time;
-
-	if (timer == 0)
-		timer = get_file_mtime (image_filename);
+	timer = get_exif_time_or_mtime (current_file);
 	tm = localtime (&timer);
 	strftime (time_txt, 50, _("%d %B %Y, %H:%M"), tm);
 	utf8_time_txt = g_locale_to_utf8 (time_txt, -1, 0, 0, 0);

Modified: trunk/src/gth-viewer.c
==============================================================================
--- trunk/src/gth-viewer.c	(original)
+++ trunk/src/gth-viewer.c	Tue Jan 29 14:12:50 2008
@@ -606,11 +606,7 @@
 		height = 0;
 	}
 
-	file_data_insert_metadata (priv->image);
-	timer = priv->image->exif_time;
-
-	if (timer == 0)
-		timer = priv->image->mtime;
+	get_exif_time_or_mtime (priv->image);
 	tm = localtime (&timer);
 	strftime (time_txt, 50, _("%d %B %Y, %H:%M"), tm);
 	utf8_time_txt = g_locale_to_utf8 (time_txt, -1, 0, 0, 0);



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