Re: Import patch



Bengt Thuree wrote:

I guess I have done something bad...

Whoops --- no, I did something bad - I let one file from my slideshow interval patch sneak into this file. You can just undo the changes to PreferenceDialog.cs and it should be fine...

Here's a new patch with that diff removed...

Many apologies... I regened the patch at the last minute and didn't check it carefully enough... I guess I should have tried building it against a clean copy to be sure...

Warren
diff -ur clean/f-spot-0.1.11/src/FileImportBackend.cs f-spot-0.1.11/src/FileImportBackend.cs
--- clean/f-spot-0.1.11/src/FileImportBackend.cs	2006-03-12 22:49:25.000000000 -0500
+++ f-spot-0.1.11/src/FileImportBackend.cs	2006-04-20 19:00:17.000000000 -0400
@@ -3,6 +3,8 @@
 using Gnome;
 using System.Collections;
 using System;
+using FSpot.Xmp;
+using FSpot;
 
 public class ImportException : System.Exception {
 	public ImportException (string msg) : base (msg)
@@ -142,8 +144,9 @@
 
 		// FIXME Need to get the EXIF info etc.
 		string path = (string) file_paths [this.count];
-		
+		string origPath = (string) file_paths [this.count];
 		try {
+						
 			if (copy) {
 				string dest = ChooseLocation (path);
 				System.IO.File.Copy (path, dest);
@@ -152,6 +155,36 @@
 			} else {
                 photo = store.Create (path, out thumbnail);
 			}
+
+			// check for Xmp headers in the jpeg file itself
+			try {
+				JpegFile jpegfile = new JpegFile(path);
+				JpegHeader jpegheader = jpegfile.Header;
+				XmpFile xmpfile = jpegheader.GetXmp();
+				if (xmpfile != null) {
+					string [] tagNames = xmpfile.Store.GetTagNames();
+					foreach (string tagName in tagNames) {
+						Tag t = store.GetTagByName(tagName);
+						photo.AddTag(t);
+					}
+					store.Commit(photo);
+				}
+			} catch (System.Exception e) {
+				System.Console.WriteLine ("Error reading XMP headers for {0}\n{1}", path, e.ToString ());
+			}
+
+			
+			// check for an xmp "sidecar" file
+			if (System.IO.File.Exists(origPath + ".xmp")) {
+				XmpFile sidecar = new XmpFile(System.IO.File.OpenRead(origPath + ".xmp"));
+				string [] tagNames = sidecar.Store.GetTagNames();
+				foreach (string tagName in tagNames) {
+					System.Console.WriteLine("adding tag for: " + tagName);
+					Tag t = store.GetTagByName(tagName);
+					photo.AddTag(t);
+				}
+				store.Commit(photo);
+			}
 			
 			if (tags != null) {
 				foreach (Tag t in tags) {
diff -ur clean/f-spot-0.1.11/src/MetadataStore.cs f-spot-0.1.11/src/MetadataStore.cs
--- clean/f-spot-0.1.11/src/MetadataStore.cs	2006-02-11 13:02:14.000000000 -0500
+++ f-spot-0.1.11/src/MetadataStore.cs	2006-04-20 18:38:56.000000000 -0400
@@ -189,6 +189,39 @@
 			}
 		}
 
+
+		// Note that this is a very incomplete implementation.  It currently returns an array
+		// containing all strings that appear in an RDF:Bag structure in the xmp file
+		// This will not work in general, but it does provide an easy way to import existing tags.
+		// 
+		// TODO: Implement proper XMP/RDF parsing here to only look for bags inside a dc:subject node
+		
+		public string []  GetTagNames() 
+		{
+			System.Collections.ArrayList tags = new System.Collections.ArrayList();
+			bool savingTags = false;
+			foreach (SemWeb.Statement stmt in this) {
+				if (stmt.Object.ToString() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag";) {
+					savingTags = true;
+					continue;
+				}
+				if (savingTags) {
+					if (stmt.Object.ToString() == "_") {
+						savingTags = false;
+						continue;
+					}
+					string tag = stmt.Object.ToString();
+					// SemWeb puts quotes around the strings it returns, 
+					// so we need to remove them
+					if (tag.StartsWith("\"") && tag.EndsWith("\"")) {
+						tag = tag.Substring(1,tag.Length-2);
+					}
+					tags.Add(tag);
+				}
+			}
+			return  (string []) tags.ToArray (typeof (string));
+		}
+
 		public void Dump ()
 		{
 			foreach (SemWeb.Statement stmt in this) {
diff -ur clean/f-spot-0.1.11/src/PhotoStore.cs f-spot-0.1.11/src/PhotoStore.cs
--- clean/f-spot-0.1.11/src/PhotoStore.cs	2006-03-07 12:54:54.000000000 -0500
+++ f-spot-0.1.11/src/PhotoStore.cs	2006-04-20 18:47:18.000000000 -0400
@@ -635,6 +635,20 @@
 			   Thumbnail.PathForUri (new_uri, ThumbnailSize.Large));
 	}
 
+	// Lookup a tag by name --- needed for importing tags
+	// If the requested tag doesn't exist, a new top-level tag
+	// is created and returned.
+	
+	public Tag GetTagByName (string name) {
+	
+		Tag tag = tag_store.GetTagByName(name);
+		
+		if (tag == null) {
+			tag = tag_store.CreateCategory(null,name);
+		}
+		return tag;
+	}
+
 
 	// Constructor
 


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