Index: src/FileImportBackend.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/FileImportBackend.cs,v
retrieving revision 1.33
diff -u -r1.33 FileImportBackend.cs
--- src/FileImportBackend.cs	14 May 2006 23:01:15 -0000	1.33
+++ src/FileImportBackend.cs	20 May 2006 00:53:27 -0000
@@ -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)
@@ -172,7 +174,7 @@
 
 		// 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, directories);
@@ -181,6 +183,48 @@
 				path = dest;
 			} 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"));
+
+				// if we find a photoshop:Headline node than put it's content in the description field.
+				foreach (SemWeb.Statement stmt in sidecar.Store) {
+					if (stmt.Predicate.ToString() == "http://ns.adobe.com/photoshop/1.0/Headline") {	
+						string description = stmt.Object.ToString();
+						// SemWeb puts quotes around the strings it returns, 
+						// so we need to remove them
+						if (description.StartsWith("\"") && description.EndsWith("\"")) {
+							description = description.Substring(1,description.Length-2);
+						}
+						photo.Description = description;
+					}
+				}
+				
+				string [] tagNames = sidecar.Store.GetTagNames();
+				foreach (string tagName in tagNames) {
+					Tag t = store.GetTagByName(tagName);
+					photo.AddTag(t);
+				}
+				store.Commit(photo);
 			}
 			
 			if (tags != null) {
Index: src/MetadataStore.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MetadataStore.cs,v
retrieving revision 1.18
diff -u -r1.18 MetadataStore.cs
--- src/MetadataStore.cs	11 Feb 2006 18:02:14 -0000	1.18
+++ src/MetadataStore.cs	20 May 2006 00:53:27 -0000
@@ -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) {
Index: src/PhotoStore.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/PhotoStore.cs,v
retrieving revision 1.95
diff -u -r1.95 PhotoStore.cs
--- src/PhotoStore.cs	23 Mar 2006 03:17:30 -0000	1.95
+++ src/PhotoStore.cs	20 May 2006 00:53:28 -0000
@@ -641,6 +641,23 @@
 			   Thumbnail.PathForUri (new_uri, ThumbnailSize.Large));
 	}
 
+	// Lookup a tag by name --- needed for importing tags
+	// If the requested tag doesn't exist, a new Category inside
+	// the top level category "Imported Tags" is created and returned.
+	// if "Imported Tags" doesn't exist, it is created.
+	
+	public Tag GetTagByName (string name) {
+		Tag tag = tag_store.GetTagByName(name);
+		if (tag == null) {
+			Category importedTags = (Category)tag_store.GetTagByName("Imported Tags");
+			if (importedTags == null) {
+				importedTags = tag_store.CreateCategory(null,"Imported Tags");
+			}
+			tag = tag_store.CreateCategory(importedTags,name);
+		}
+		return tag;
+	}
+
 
 	// Constructor
 
