Index: src/RotateCommand.cs
===================================================================
--- src/RotateCommand.cs	(revisione 3552)
+++ src/RotateCommand.cs	(copia locale)
@@ -40,17 +40,25 @@
 	public class RotateOperation : Operation {
 		IBrowsableItem item;
 		RotateDirection direction;
-		int version_index;
+		bool create_new;
 		bool done;
 
 		public RotateOperation (IBrowsableItem item, RotateDirection direction)
 		{
 			this.item = item;
 			this.direction = direction;
-			version_index = 0;
+			this.create_new = (bool) Preferences.Get (Preferences.METADATA_EMBED_IN_IMAGE);
 			done = false;
 		}
 
+		public RotateOperation (IBrowsableItem item, RotateDirection direction, bool create_new)
+		{
+			this.item = item;
+			this.direction = direction;
+			this.create_new = false;
+			done = false;
+		}
+
 		private static void RotateCoefficients (string original_path, RotateDirection direction)
 		{
 			string temporary_path = original_path + ".tmp";	// FIXME make it unique
@@ -120,15 +128,23 @@
 			if (done)
 				return false;
 
-			if (item is Photo) {
+			if (item is Photo && create_new) {
+				uint rotated_version = 0;
 				Photo p = (Photo) item;
-
-				original_path = p.GetVersionPath (p.VersionIds [version_index++]);
-				done = (version_index >= p.VersionIds.Length);
-			} else {
-				original_path = item.DefaultVersionUri.LocalPath;
-				done = true;
+				//If we already have a "Rotated" version delete it (if we're not rotating itself!)
+				if (p.VersionNameExists (Catalog.GetString ("Rotated"))) {
+					foreach (uint vid in p.VersionIds) {
+						if (p.GetVersion (vid).Name == Catalog.GetString ("Rotated") && vid != p.DefaultVersionId) {
+							p.DeleteVersion(vid);
+							break;
+						}
+					}
+				}
+				rotated_version = p.CreateVersion (Catalog.GetString ("Rotated"), p.DefaultVersionId, true);
+				p.DefaultVersionId = rotated_version;
 			}
+			original_path = item.DefaultVersionUri.LocalPath;
+			done = true;
 
 			if ((File.GetAttributes(original_path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
 				throw new RotateException ("Unable to rotate readonly file", original_path);
Index: ChangeLog
===================================================================
--- ChangeLog	(revisione 3552)
+++ ChangeLog	(copia locale)
@@ -1,3 +1,13 @@
+2008-01-16  Lorenzo Milesi <maxxer@yetopen.it>
+
+	* src/RotateCommand.cs: create a new version on rotate if metadata
+	write is enabled. Fix bgo#301819.
+
+2008-01-16  Lorenzo Milesi <maxxer@yetopen.it>
+
+	* src/RotateCommand.cs: rotate only default version of photo. Fix
+	bgo#505125.
+
 2008-01-16  Stephane Delcroix  <sdelcroix@novell.com>
 
 	* src/main.cs: minor fixes.
