Re: reimport files as new version



Hi all,

here's a patch I cooked some month ago (but never published in bgo) that
solves a big part of this issue.
I updated it to latest CVS and polished it a bit.
Now, you can drag a photo (or some photos) on another to reparent as
version.

note:
- work only if the extensions matches !
- need a confirmation dialog

I'll try to find some time this evening to update it 

best regards

stephane


On Mon, 2006-11-06 at 21:57 +0100, Anders Bo Rasmussen wrote:
> I take pictures in raw+jpeg. Since f-spot doesn't handle to versions of
> the same picture, I import the jpeg and place the raws in a
> subdirectory. Then I use f-spot to select the picture I want to work on,
> export the pictures as text to a textfile, and make some search/replace
> and now I have a list of the raws. Then I go into Bibble and process
> them as I want. Bibble is really nice, but doesn't interface very well
> with other programs. I place the files in a new directory, and the files
> get the same name as the orignal jpeg. 
> 
> Is there any smart way I can reimport them into f-spot as a new version
> to the original jpeg? It should be the selected version. My naming of
> photos are done so I will never get two photos with the same name.
> 
> 
> Regards 
> 
>   Anders
> _______________________________________________
> F-spot-list mailing list
> F-spot-list gnome org
> http://mail.gnome.org/mailman/listinfo/f-spot-list
> 
-- 
Stephane Delcroix
stephane delcroix org
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.323
diff -u -p -r1.323 MainWindow.cs
--- src/MainWindow.cs	5 Nov 2006 18:57:22 -0000	1.323
+++ src/MainWindow.cs	7 Nov 2006 16:40:38 -0000
@@ -155,6 +155,7 @@ public class MainWindow {
 	};
 
 	private static TargetEntry [] icon_dest_target_table = new TargetEntry [] {
+		new TargetEntry ("application/x-fspot-photos", 0, (uint) TargetType.PhotoList),
 		new TargetEntry ("application/x-fspot-tags", 0, (uint) TargetType.TagList),
 		new TargetEntry ("text/uri-list", 0, (uint) TargetType.UriList),
 	};
@@ -1159,6 +1160,20 @@ public class MainWindow {
 
 			UriList list = new UriList (args.SelectionData);
 			ImportUriList (list, (args.Context.Action & Gdk.DragAction.Copy) != 0);
+			break;
+		case (uint)TargetType.PhotoList:
+			int p_item = icon_view.CellAtPosition (args.X + (int) icon_view.Hadjustment.Value, 
+							     args.Y + (int) icon_view.Vadjustment.Value);
+
+Console.WriteLine ("Trying to re-parent images...");
+			if (p_item >= 0)
+			{
+				PhotoVersionCommands.Reparent cmd = new PhotoVersionCommands.Reparent ();
+				
+				cmd.Execute (db.Photos, SelectedPhotos(), query.Photos [p_item], GetToplevel (null));
+				UpdateQuery ();
+			}
+	
 			break;
 		}
 
Index: src/PhotoStore.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/PhotoStore.cs,v
retrieving revision 1.102
diff -u -p -r1.102 PhotoStore.cs
--- src/PhotoStore.cs	30 Oct 2006 09:35:34 -0000	1.102
+++ src/PhotoStore.cs	7 Nov 2006 16:40:40 -0000
@@ -253,9 +253,13 @@ public class Photo : DbItem, IComparable
 
 	private string GetPathForVersionName (string version_name)
 	{
-		string name_without_extension = System.IO.Path.GetFileNameWithoutExtension (name);
 		string extension = System.IO.Path.GetExtension (name);
+		return GetPathForVersionName (version_name, extension);
+	}
 
+	private string GetPathForVersionName (string version_name, string extension)
+	{
+		string name_without_extension = System.IO.Path.GetFileNameWithoutExtension (name);
 		return System.IO.Path.Combine (directory_path,  name_without_extension 
 					       + " (" + version_name + ")" + extension);
 	}
@@ -357,6 +361,29 @@ public class Photo : DbItem, IComparable
 		version_names [highest_version_id] = name;
 
 		return highest_version_id;
+	}
+
+	public uint CreateVersionFromFile (uint base_version_id, string file_path)
+	{
+		int num = 1;
+		while (true) {
+			string name = Mono.Posix.Catalog.GetPluralString ("Reparented", "Reparented ({0})", num);
+			name = String.Format (name, num);
+			string extension = System.IO.Path.GetExtension (file_path);
+			string new_path = GetPathForVersionName (name, extension);
+			if (! VersionNameExists (name) && ! File.Exists (new_path)) {
+Console.WriteLine("Copying {0} to {1}",file_path, new_path);
+				File.Copy (file_path, new_path);
+				FSpot.ThumbnailGenerator.Create (new_path).Dispose ();
+				if (version_names == null)
+					version_names = new Hashtable ();
+				highest_version_id ++;
+				version_names [highest_version_id] = name;
+
+				return highest_version_id;
+			}
+		num++;
+		}
 	}
 
 	public uint CreateDefaultModifiedVersion (uint base_version_id, bool create_file)
Index: src/PhotoVersionCommands.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/PhotoVersionCommands.cs,v
retrieving revision 1.9
diff -u -p -r1.9 PhotoVersionCommands.cs
--- src/PhotoVersionCommands.cs	12 Feb 2006 15:44:25 -0000	1.9
+++ src/PhotoVersionCommands.cs	7 Nov 2006 16:40:41 -0000
@@ -205,4 +205,33 @@ public class PhotoVersionCommands {
 			return true;
 		}
 	}
+
+	// Reparenting a photo as version of another one
+	
+	public class Reparent {
+		public bool Execute (PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
+		{
+			foreach (Photo photo in photos) {
+				foreach (uint version_id in photo.VersionIds) {
+					try {
+						new_parent.DefaultVersionId = new_parent.CreateVersionFromFile (new_parent.DefaultVersionId,
+										photo.GetVersionPath (version_id));
+						store.Commit (new_parent);
+					} catch (Exception e) {
+						Console.WriteLine(e);	
+					}
+				}
+				foreach (uint version_id in photo.VersionIds) {
+					try {
+						photo.DeleteVersion (version_id, true);
+					} catch (Exception e) {
+						Console.WriteLine(e);
+					}
+				}
+				store.Commit (photo);
+				MainWindow.Toplevel.Database.Photos.Remove (photos);
+			}
+			return true;
+		}
+	}
 }


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