Copy on DnD / Import Fixes - Patch



Tonight I was in the mood to organize stuff, and felt compelled to clean
up ~/Photos, reimport everything, and tag everything for real. Up until
tonight I've just used F-Spot more or less to offload photos from my
camera.

I have close to a thousand photos taken a few years back on a really
cheap digital camera that have never seen F-Spot. This camera was so
pathetic it apparently didn't even stick a time stamp in EXIF. Luckily
the mtimes on these photos are at least relatively accurate. 

Attached is a patch that accomplishes/fixes a few things with importing
and DnD:

1. Importing the photos with no EXIF timestamps with the "copy" option
reads the photo for metadata _after_ the copy - this hoses the mtimes,
and leaves me with a thousand photos "taken" today. This is fixed by
passing both the new/destination and old/source path (which can be
identical if a copy was not performed) to PhotoStore.Create. It will
parse the data from the old/source path and do everything else on the
new/dest path. Makes me happy ;)

2. Respect the DragAction for DnD files from Nautilus to F-Spot for
importing. If you effectively DnD with the Gdk.DragAction.Copy flag, the
photos will be copied and imported. If you drag with
Gdk.DragAction.Move, they will not be copied. 

This modifies the default behavior: DnD with no key modifiers will copy
and import. You have to hold "Shift" and DnD to not copy. Since this
changes the current default behavior, maybe this needs to be discussed.
I think it's sane however since the Move/Copy is set from Nautilus, and
is how Nautilus itself works. (The previous functionality of this I
think is *incorrect*. I always assumed F-Spot copied my photos when I
had the copy modifier set for the drag.

3. Finally, a little teeny bug fix. When performing any kind of DnD
import, F-Spot would crash after the import because it was trying to
update the label on the import progress dialog. I assume this was
introduced recently as it didn't used to happen. Was just a little null
ref.

So now I'm happy and organized and can actually find photos now :)

Best,
Aaron

? f-spot-copy-on-dnd.diff
? src/copy-on-dnd.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/f-spot/ChangeLog,v
retrieving revision 1.1155
diff -u -r1.1155 ChangeLog
--- ChangeLog	2 Dec 2005 14:55:50 -0000	1.1155
+++ ChangeLog	3 Dec 2005 05:09:24 -0000
@@ -1,3 +1,26 @@
+2005-12-02  Aaron Bockover  <aaron aaronbock net>
+
+	* src/PhotoStore.cs (Create): Accept a new/destination path and an
+	orignal/source path; create the file based on the original path and
+	perform all other actions based on the new path; this forces metadata
+	parsing to be done on the original path, meaning mtime will be used from
+	the orginal and not the copy as date/time in case the photo lacks
+	EXIF date/time information
+
+	* src/FileImportBackend.cs (Step): if photo is to be copied and imported, 
+	pass both the original and the new path to PhotoStore.Create
+	
+	* src/ImportCommand.cs: Added two overloaded ImportFromPaths methods that
+	will preserve existing calls but also allow a 'copy' boolean to be passed;
+	for preserved calls, the default copy value is false
+
+	* src/MainWindow.cs: Added a 'copy' parameter to ImportUriList; set
+	copy option to true if DnD drag action contains the DragAction.Copy flag
+
+	* src/ImportCommand.cs (DoImport):  guard against a NullReferenceException
+	before setting progress_bar.Text; if the import was invoked from DnD,
+	progress_bar won't exist
+
 2005-12-02  Larry Ewing  <lewing novell com>
 
 	* configure.in: update the version checks bump the package
Index: src/FileImportBackend.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/FileImportBackend.cs,v
retrieving revision 1.27
diff -u -r1.27 FileImportBackend.cs
--- src/FileImportBackend.cs	1 Sep 2005 10:01:52 -0000	1.27
+++ src/FileImportBackend.cs	3 Dec 2005 05:09:25 -0000
@@ -140,12 +140,12 @@
 		try {
 			if (copy) {
 				string dest = ChooseLocation (path);
-				
 				System.IO.File.Copy (path, dest);
+				photo = store.Create (dest, path, out thumbnail);
 				path = dest;
+			} else {
+                photo = store.Create (path, out thumbnail);
 			}
-			
-			photo = store.Create (path, out thumbnail);
 			
 			if (tags != null) {
 				foreach (Tag t in tags) {
Index: src/ImportCommand.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/ImportCommand.cs,v
retrieving revision 1.42
diff -u -r1.42 ImportCommand.cs
--- src/ImportCommand.cs	2 Dec 2005 00:27:43 -0000	1.42
+++ src/ImportCommand.cs	3 Dec 2005 05:09:26 -0000
@@ -515,7 +515,8 @@
 		if (cancelled)
 			return 0;
 		else {
-			progress_bar.Text = Mono.Posix.Catalog.GetString ("Done Loading");
+			if (progress_bar != null)
+				progress_bar.Text = Mono.Posix.Catalog.GetString ("Done Loading");
 			AllowFinish = true;
 			return total;
 		}
@@ -781,10 +782,20 @@
 		return ImportFromPaths (store, paths, null);
 	}
 
+    public int ImportFromPaths (PhotoStore store, string [] paths, bool copy)
+    {
+        return ImportFromPaths (store, paths, null, copy);
+    }
+
 	public int ImportFromPaths (PhotoStore store, string [] paths, Tag [] tags)
 	{
+		return ImportFromPaths (store, paths, tags, false);
+	}
+	
+	public int ImportFromPaths (PhotoStore store, string [] paths, Tag [] tags, bool copy)
+	{
 		collection = new FSpot.PhotoList (new Photo [0]);
-		return DoImport (new FileImportBackend (store, paths, false, true, tags));
+		return DoImport (new FileImportBackend (store, paths, copy, true, tags));
 	}
 	
 #if TEST_IMPORT_COMMAND
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.245
diff -u -r1.245 MainWindow.cs
--- src/MainWindow.cs	1 Dec 2005 23:52:59 -0000	1.245
+++ src/MainWindow.cs	3 Dec 2005 05:09:29 -0000
@@ -908,10 +908,10 @@
 		}
 	}
 
-	public void ImportUriList (UriList list) 
+	public void ImportUriList (UriList list, bool copy) 
 	{
 		ImportCommand command = new ImportCommand (main_window);
-		if (command.ImportFromPaths (db.Photos, list.ToLocalPaths ()) > 0) {
+		if (command.ImportFromPaths (db.Photos, list.ToLocalPaths (), copy) > 0) {
 			UpdateQuery ();
 		}
 	}
@@ -956,7 +956,7 @@
 				return;
 
 			UriList list = new UriList (args.SelectionData);
-			ImportUriList (list);
+			ImportUriList (list, (args.Context.Action & Gdk.DragAction.Copy) != 0);
 			break;
 		}
 
Index: src/PhotoStore.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/PhotoStore.cs,v
retrieving revision 1.72
diff -u -r1.72 PhotoStore.cs
--- src/PhotoStore.cs	2 Nov 2005 08:33:15 -0000	1.72
+++ src/PhotoStore.cs	3 Dec 2005 05:09:30 -0000
@@ -590,9 +590,15 @@
 		command.Dispose ();
 	}
 
+
 	public Photo Create (string path, out Pixbuf thumbnail)
 	{
-		FSpot.ImageFile img = FSpot.ImageFile.Create (path);
+		return Create (path, path, out thumbnail);
+	}
+
+	public Photo Create (string newPath, string origPath, out Pixbuf thumbnail)
+	{
+		FSpot.ImageFile img = FSpot.ImageFile.Create (origPath);
 		uint unix_time = DbUtils.UnixTimeFromDateTime (img.Date);
 		string description = img.Description != null ? img.Description : "";
 		SqliteCommand command = new SqliteCommand ();
@@ -602,8 +608,8 @@
 						     "directory_path, name, description, default_version_id) " +
 						     "       VALUES ({0}, '{1}', '{2}', '{3}', {4})                                       ",
 						     unix_time,
-						     SqlString (System.IO.Path.GetDirectoryName (path)),
-						     SqlString (System.IO.Path.GetFileName (path)),
+						     SqlString (System.IO.Path.GetDirectoryName (newPath)),
+						     SqlString (System.IO.Path.GetFileName (newPath)),
 						     SqlString (description),
 						     Photo.OriginalVersionId);
 
@@ -611,11 +617,11 @@
 		command.Dispose ();
 
 		uint id = (uint) Connection.LastInsertRowId;
-		Photo photo = new Photo (id, unix_time, path);
+		Photo photo = new Photo (id, unix_time, newPath);
 		AddToCache (photo);
 		photo.Loaded = true;
 
-		thumbnail = GenerateThumbnail (path);
+		thumbnail = GenerateThumbnail (newPath);
 		return photo;
 	}
 


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