gthumb r2461 - in trunk: . libgthumb src



Author: mjc
Date: Sun Dec 21 01:56:04 2008
New Revision: 2461
URL: http://svn.gnome.org/viewvc/gthumb?rev=2461&view=rev

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

        * libgthumb/dlg-save-image.c: (save_image):
        * libgthumb/pixbuf-utils.c: (_gdk_pixbuf_savev),
        (_gdk_pixbuf_save):
        * libgthumb/pixbuf-utils.h:
        * src/catalog-web-exporter.c: (save_thumbnail_cb),
        (save_image_preview_cb), (save_resized_image_cb):
        * src/dlg-convert.c: (save_image_and_remove_original):
        * src/gth-batch-op.c: (pixbuf_op_done_cb):
        * src/rotation-utils.c: (apply_transformation_generic):
        When saving a file, specify the original file from which metadata 
        should be copied. The previous commit had a flaw where if you saved
        a pixbuf to overwrite already-existing file, the metadata from the
        existing file was copied into the new file. This commit fixes that.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/dlg-save-image.c
   trunk/libgthumb/pixbuf-utils.c
   trunk/libgthumb/pixbuf-utils.h
   trunk/src/catalog-web-exporter.c
   trunk/src/dlg-convert.c
   trunk/src/gth-batch-op.c
   trunk/src/rotation-utils.c

Modified: trunk/libgthumb/dlg-save-image.c
==============================================================================
--- trunk/libgthumb/dlg-save-image.c	(original)
+++ trunk/libgthumb/dlg-save-image.c	Sun Dec 21 01:56:04 2008
@@ -117,7 +117,7 @@
 			local_file = get_cache_filename_from_uri (file->path);
 			if (_gdk_pixbuf_savev (pixbuf,
 					       local_file,
-					       data->metadata,
+					       local_file,
 					       image_type,
 					       keys, values,
 					       &error))

Modified: trunk/libgthumb/pixbuf-utils.c
==============================================================================
--- trunk/libgthumb/pixbuf-utils.c	(original)
+++ trunk/libgthumb/pixbuf-utils.c	Sun Dec 21 01:56:04 2008
@@ -1196,14 +1196,14 @@
 gboolean
 _gdk_pixbuf_savev (GdkPixbuf    *pixbuf,
 		   const char   *local_file,
-		   GList	*metadata,
+		   const char   *original_local_file,
 		   const char   *type,
 		   char        **keys,
 		   char        **values,
 		   GError      **error)
 {
-	char     *temp_backup;
-	char     *temp_dir;
+	char     *temp_backup = NULL;
+	char     *temp_dir = NULL;
 	char     *ext;
 
 	gboolean  is_overwrite;
@@ -1216,18 +1216,18 @@
 
 	is_overwrite = FALSE;
 
-        temp_dir = get_temp_dir_name ();
-        if (temp_dir != NULL) {
-		is_overwrite = path_exists (local_file);
-		if (is_overwrite) {
-			ext = g_strdup_printf (".%s",get_filename_extension (local_file));
-			temp_backup = get_temp_file_name (temp_dir, ext);
-			g_free (ext);
-			/* Make a backup copy first to preserve original metadata in its original
-			 * fully-typed form. Use the string copies in the metadata glist as a 
-			 * fallback - but exiv2 soemtimes gets the typing wrong,
-			 * causing no metadata to be saved. */
-			file_copy (local_file, temp_backup);
+	/* Make a backup copy of original file if the source and destination
+	 * are the same, so that we can copy the metadata. */
+	if (original_local_file != NULL) {
+		if (!strcmp (local_file, original_local_file)) {
+		        temp_dir = get_temp_dir_name ();
+        		if (temp_dir != NULL) {
+				is_overwrite = TRUE;
+				ext = g_strdup_printf (".%s",get_filename_extension (local_file));
+				temp_backup = get_temp_file_name (temp_dir, ext);
+				g_free (ext);
+				file_copy (local_file, temp_backup);
+			}
 		}
 	}
 
@@ -1256,16 +1256,13 @@
 					   error);
 
 	if (result == TRUE) {
-		metadata = simple_add_metadata (metadata, "Exif.Image.Orientation", "1");
-		if (is_overwrite)
-			update_and_save_metadata (temp_backup, local_file, metadata);
-		else
-			update_and_save_metadata (local_file, local_file, metadata);
-	}
-
-	if (is_overwrite) {
-		file_unlink (temp_backup);
-		local_dir_remove_recursive (temp_dir);
+		if (is_overwrite) {
+			update_and_save_metadatum (temp_backup, local_file, "Exif.Image.Orientation", "1");
+			file_unlink (temp_backup);
+			local_dir_remove_recursive (temp_dir);
+		} else {
+			update_and_save_metadatum (original_local_file, local_file, "Exif.Image.Orientation", "1");
+		}
 	}
 
 	g_free (temp_backup);
@@ -1314,7 +1311,7 @@
 gboolean
 _gdk_pixbuf_save (GdkPixbuf    *pixbuf,
 		  const char   *local_file,
-		  GList	       *metadata,
+		  const char   *original_local_file,
 		  const char   *type,
 		  GError      **error,
 		  ...)
@@ -1333,7 +1330,7 @@
 	collect_save_options (args, &keys, &values);
 	va_end (args);
 
-	result = _gdk_pixbuf_savev (pixbuf, local_file, metadata, type,
+	result = _gdk_pixbuf_savev (pixbuf, local_file, original_local_file, type,
 				    keys, values, error);
 
 	g_strfreev (keys);

Modified: trunk/libgthumb/pixbuf-utils.h
==============================================================================
--- trunk/libgthumb/pixbuf-utils.h	(original)
+++ trunk/libgthumb/pixbuf-utils.h	Sun Dec 21 01:56:04 2008
@@ -47,13 +47,13 @@
 					       GthTransform     transform);
 gboolean   _gdk_pixbuf_save                   (GdkPixbuf       *pixbuf,
 					       const char      *filename,
-					       GList	       *metadata,
+					       const char      *original_local_file,
 					       const char      *type,
 					       GError         **error,
 					       ...);
 gboolean   _gdk_pixbuf_savev                  (GdkPixbuf       *pixbuf,
 					       const char      *filename,
-					       GList           *metadata,
+					       const char      *original_local_file,
 					       const char      *type,
 					       char           **keys,
 					       char           **values,

Modified: trunk/src/catalog-web-exporter.c
==============================================================================
--- trunk/src/catalog-web-exporter.c	(original)
+++ trunk/src/catalog-web-exporter.c	Sun Dec 21 01:56:04 2008
@@ -2333,7 +2333,9 @@
 		
 	if (idata->thumb != NULL) {
 		GFile *file;
+		GFile *src_local_gfile = g_file_new_for_uri (idata->src_file->path);
 		char  *local_file;
+		char  *src_local_file;
 
 		g_signal_emit (G_OBJECT (ce),
 			       catalog_web_exporter_signals[WEB_EXPORTER_PROGRESS],
@@ -2344,17 +2346,20 @@
 					   idata, 
 					   ce->target_tmp_dir);
 		local_file = gfile_get_path (file);
+		src_local_file = gfile_get_path (src_local_gfile);
 		
 		debug (DEBUG_INFO, "save thumbnail: %s", local_file);
 
 		_gdk_pixbuf_save (idata->thumb,
 				  local_file,
-				  idata->src_file->metadata,
+				  src_local_file,
 				  "jpeg",
 				  NULL, NULL); 
 
 		g_object_unref (file);
+		g_object_unref (src_local_gfile);
 		g_free (local_file);
+		g_free (src_local_file);
 		
 		g_object_unref (idata->thumb);
 		idata->thumb = NULL;
@@ -2592,25 +2597,28 @@
 
 		if ((! idata->no_preview) && (idata->preview != NULL)) {
 			GFile *file;
+			GFile *src_local_gfile = g_file_new_for_uri (idata->src_file->path);
 			char  *local_file;
-			
+			char  *src_local_file;
+
 			file = get_preview_file (ce, 
 						 idata, 
 						 ce->target_tmp_dir);
 			local_file = gfile_get_path (file);
+			src_local_file = gfile_get_path (src_local_gfile);
 
 			debug (DEBUG_INFO, "saving preview: %s", local_file);
 
-			update_metadata (idata->src_file);
-
 			_gdk_pixbuf_save (idata->preview,
 					  local_file,
-					  idata->src_file->metadata,
+					  src_local_file,
 					  "jpeg",
 					  NULL, NULL);
 			 
 			g_free (local_file);
+			g_free (src_local_file);
 			g_object_unref (file);
+			g_object_unref (src_local_file);
 		}
 	}
 
@@ -2635,8 +2643,10 @@
 
 		if (ce->copy_images && (idata->image != NULL)) {
 			GFile *file;
+			GFile *src_local_gfile = g_file_new_for_uri (idata->src_file->path);
 			char  *image_uri;
 			char  *local_file; 
+			char  *src_local_file;
 
 			exporter_set_info (ce, _("Saving images"));
 			
@@ -2645,22 +2655,23 @@
 					       ce->target_tmp_dir);
 			image_uri = gfile_get_uri (file);
 			local_file = gfile_get_path (file);
-			
-			debug (DEBUG_INFO, "saving image: %s", local_file);
+			src_local_file = gfile_get_path (src_local_gfile);
 
-			update_metadata (idata->src_file);
+			debug (DEBUG_INFO, "saving image: %s", local_file);
 
 			if (_gdk_pixbuf_save (idata->image,
 					      local_file,
-					      idata->src_file->metadata,
+					      src_local_file,
 					      "jpeg",
 					      NULL, NULL)) {
 				idata->src_file->size = get_file_size (image_uri);
 			} 
 			
 			g_free (local_file);
+			g_free (src_local_file);
 			g_free (image_uri);
 			g_object_unref (file);
+			g_object_unref (src_local_gfile);
 		}
 	}
 

Modified: trunk/src/dlg-convert.c
==============================================================================
--- trunk/src/dlg-convert.c	(original)
+++ trunk/src/dlg-convert.c	Sun Dec 21 01:56:04 2008
@@ -43,6 +43,7 @@
 #include "jpegutils/jpegtran.h"
 #include "pixbuf-utils.h"
 #include "file-utils.h"
+#include "gfile-utils.h"
 #include "dlg-save-image.h"
 #include "gth-exif-utils.h"
 
@@ -246,19 +247,23 @@
 {
 	GError   *error = NULL;
 	char     *local_file;
+	char     *old_local_file;
 	FileData *fd;
 	FileData *fd_old;
-			
+	GFile    *old_local_gfile;
+
 	if (path_is_file (data->new_path))
 		file_unlink (data->new_path);
 
 	fd_old = (FileData*) data->current_image->data;
-	update_metadata (fd_old);
+	old_local_gfile = g_file_new_for_uri (fd_old->path);
+	old_local_file = gfile_get_path (old_local_gfile);
+	g_object_unref (old_local_gfile);
 
 	local_file = get_cache_filename_from_uri (data->new_path);
 	if (! _gdk_pixbuf_savev (data->pixbuf,
 			         local_file,
-				 fd_old->metadata,
+				 old_local_file,
 			         data->image_type,
 			         data->keys,
 			         data->values,
@@ -270,11 +275,13 @@
 		return;
 	}
 	g_free (local_file);
+	g_free (old_local_file);
 	file_data_unref (fd_old);
 	
 	fd = file_data_new (data->new_path, NULL);
 	update_file_from_cache (fd, save_image_and_remove_original_step2, data);
 	file_data_unref (fd);
+
 }
 
 

Modified: trunk/src/gth-batch-op.c
==============================================================================
--- trunk/src/gth-batch-op.c	(original)
+++ trunk/src/gth-batch-op.c	Sun Dec 21 01:56:04 2008
@@ -29,6 +29,7 @@
 
 #include "file-data.h"
 #include "file-utils.h"
+#include "gfile-utils.h"
 #include "gconf-utils.h"
 #include "glib-utils.h"
 #include "gthumb-marshal.h"
@@ -465,6 +466,8 @@
 	FileData *fd;
 	FileData *fd_old;
 	char     *local_file;
+	char     *old_local_file;
+	GFile    *old_local_gfile;
 	
 	if (! completed) {
 		notify_termination (bop);
@@ -472,12 +475,14 @@
 	}
 
 	fd_old = (FileData*) PD(bop)->current_image->data;
-	update_metadata (fd_old);
+	old_local_gfile = g_file_new_for_uri (fd_old->path);
+        old_local_file = gfile_get_path (old_local_gfile);
+        g_object_unref (old_local_gfile);
 
 	local_file = get_cache_filename_from_uri (PD(bop)->new_path);
 	if (! _gdk_pixbuf_savev (pixop->dest,
 			         local_file,
-				 fd_old->metadata,
+				 old_local_file,
 			         PD(bop)->image_type,
 			         PD(bop)->keys,
 			         PD(bop)->values,
@@ -489,6 +494,7 @@
 		return;
 	}
 	g_free (local_file);
+	g_free (old_local_file);
 	file_data_unref (fd_old);
 	
 	fd = file_data_new (PD(bop)->new_path, NULL);

Modified: trunk/src/rotation-utils.c
==============================================================================
--- trunk/src/rotation-utils.c	(original)
+++ trunk/src/rotation-utils.c	Sun Dec 21 01:56:04 2008
@@ -265,10 +265,9 @@
 		image_type = file->mime_type + 6;
 		local_file = get_cache_filename_from_uri (file->path);
 	
-		update_metadata (file);	
 		success = _gdk_pixbuf_save (transformed_pixbuf,
 					    local_file,
-					    file->metadata,
+					    local_file,
 					    image_type,
 					    error,
 					    NULL);



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