diff --git a/ChangeLog b/ChangeLog
index c414d76..eb06a03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-07-03 Markus Lindqvist <markus.lindqvist@iki.fi>
+
+	* src/FileImportBackend.cs: Copy XMP also (if exists) when importing images
+
 2009-04-03  Stephane Delcroix  <sdelcroix@novell.com>
 
 	* src/main.cs: Add a Log handler for GLib-GObject critical warnings
diff --git a/src/FileImportBackend.cs b/src/FileImportBackend.cs
index 194072b..2058cea 100644
--- a/src/FileImportBackend.cs
+++ b/src/FileImportBackend.cs
@@ -33,6 +33,7 @@ public class FileImportBackend : ImportBackend {
 
 	ArrayList import_info;
 	Stack directories;
+	Stack xmp_files;
 
 	private class ImportInfo {
 		string original_path;
@@ -115,6 +116,7 @@ public class FileImportBackend : ImportBackend {
 		}	
 
 		directories = new Stack ();
+		xmp_files = new Stack();
 		xmptags = new XmpTagsImporter (store, tag_store);
 
 		roll = rolls.Create ();
@@ -192,6 +194,43 @@ public class FileImportBackend : ImportBackend {
 		
 		return dest;
 	}
+		
+	private string GetXmpFilenameWithoutExtension (string uri)
+	{
+		return Path.GetFileNameWithoutExtension(uri) + ".xmp";
+	}
+	
+	private string GetXmpFilenameWithExtension (string uri)
+	{
+		return uri + ".xmp";
+	}
+	
+	private void CopySidecarFiles (ImportInfo info, string destination)
+	{
+		string xmp_filename = null;
+
+		/* There's two different naming conventions for XMP's.
+		 * 1. DSC_1100.CR2.xmp
+		 * 2. DSC_1100.xmp */
+		if (File.Exists (GetXmpFilenameWithoutExtension (info.OriginalPath))) {
+			xmp_filename = GetXmpFilenameWithoutExtension (info.OriginalPath);
+		}
+		else if (File.Exists (GetXmpFilenameWithExtension (info.OriginalPath))) {
+			xmp_filename = GetXmpFilenameWithExtension (info.OriginalPath);
+		}
+
+		if (xmp_filename == null)
+			return;
+
+		try {
+			string target_filename = Path.Combine (Path.GetDirectoryName (destination),
+													Path.GetFileName (destination))
+													+ ".xmp";
+			System.IO.File.Copy (xmp_filename, target_filename, false);
+			xmp_files.Push (target_filename);
+		} catch (IOException) {
+		}
+	}
 
 	public override bool Step (out StepStatusInfo status_info)
 	{
@@ -227,6 +266,7 @@ public class FileImportBackend : ImportBackend {
 				 	is_duplicate = true;
 			} else {
 				System.IO.File.Copy (info.OriginalPath, destination);
+				CopySidecarFiles(info, destination);
 				info.DestinationPath = destination;
 
 				if (detect_duplicates)
@@ -235,7 +275,6 @@ public class FileImportBackend : ImportBackend {
 				if (photo == null)
 				{
 					photo = store.Create (info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail);
-				 	
 
 					try {
 						File.SetAttributes (destination, File.GetAttributes (info.DestinationPath) & ~FileAttributes.ReadOnly);
@@ -333,6 +372,9 @@ public class FileImportBackend : ImportBackend {
 				if (info.Exists && info.GetFiles().Length == 0 && info.GetDirectories().Length == 0)
 					info.Delete ();
 			}
+			
+			foreach(string xmp_file in xmp_files)
+				File.Delete(xmp_file);
 		}
 		// Clean up just created tags
 		xmptags.Cancel();

