[f-spot/rubenv-gsoc-2009: 59/86] Track Pipeline where it should: in EditorState.



commit 79d312f755b183baa1e2e7f15969c75e1c03c354
Author: Ruben Vermeersch <ruben savanne be>
Date:   Mon Aug 10 16:12:37 2009 +0200

    Track Pipeline where it should: in EditorState.
    
    This fixes a pile of bugs. Also makes sure the preview is updated on
    initialization and that pipelines are committed.

 src/Editors/ColorEditor.cs           |    2 +-
 src/Editors/CropEditor.cs            |    2 +-
 src/Editors/Editor.cs                |   40 ++++++++++++++++++++++++---------
 src/Editors/RedEyeEditor.cs          |    2 +-
 src/Editors/RepeatableEditor.cs      |   29 +++++++++++++++++-------
 src/Editors/RepeatableEditorState.cs |   29 ++++++++++++++++++++++++
 src/Editors/SoftFocusEditor.cs       |    2 +-
 src/Editors/TiltEditor.cs            |    2 +-
 src/Makefile.am                      |    1 +
 src/Widgets/EditorPage.cs            |    2 +-
 10 files changed, 85 insertions(+), 26 deletions(-)
---
diff --git a/src/Editors/ColorEditor.cs b/src/Editors/ColorEditor.cs
index 290e73b..92ccfcd 100644
--- a/src/Editors/ColorEditor.cs
+++ b/src/Editors/ColorEditor.cs
@@ -41,7 +41,7 @@ namespace FSpot.Editors {
 			ApplyLabel = Catalog.GetString ("Adjust");
 		}
 
-		public override Widget ConfigurationWidget () {
+		protected override Widget CreateConfigurationWidget () {
 			xml = new Glade.XML (null, "f-spot.glade", "color_editor_prefs", "f-spot");
 			xml.Autoconnect (this);
 			AttachInterface ();
diff --git a/src/Editors/CropEditor.cs b/src/Editors/CropEditor.cs
index 03d26d1..341b026 100644
--- a/src/Editors/CropEditor.cs
+++ b/src/Editors/CropEditor.cs
@@ -68,7 +68,7 @@ namespace FSpot.Editors {
 			}
 		}
 
-		public override Widget ConfigurationWidget () {
+		protected override Widget CreateConfigurationWidget () {
 			VBox vbox = new VBox ();
 
 			Label info = new Label (Catalog.GetString ("Select the area that needs cropping."));
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index 345a934..ddd485d 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -123,17 +123,18 @@ namespace FSpot.Editors {
 
 			int done = 0;
 			foreach (Photo photo in State.Items) {
-				Pixbuf input;
+				Pixbuf input, edited = null;
 				Cms.Profile input_profile;
 				LoadPhoto (photo, out input, out input_profile);
 
-				Pixbuf edited = Process (input, input_profile);
-				input.Dispose ();
-
-				bool create_version = photo.DefaultVersion.IsProtected;
-				photo.SaveVersion (edited, create_version);
-				photo.Changes.DataChanged = true;
-				App.Instance.Database.Photos.Commit (photo);
+				try {
+					edited = Process (input, input_profile);
+					SaveEditedPhoto (photo, edited);
+				} finally {
+					input.Dispose ();
+					if (edited != null)
+						edited.Dispose ();
+				}
 
 				done++;
 				if (ProcessingStep != null) {
@@ -144,6 +145,14 @@ namespace FSpot.Editors {
 			Reset ();
 		}
 
+		protected virtual void SaveEditedPhoto (Photo photo, Pixbuf pixbuf)
+		{
+			bool create_version = photo.DefaultVersion.IsProtected;
+			photo.SaveVersion (pixbuf, create_version);
+			photo.Changes.DataChanged = true;
+			Core.Database.Photos.Commit (photo);
+		}
+
 		protected abstract Pixbuf Process (Pixbuf input, Cms.Profile input_profile);
 
 		protected virtual Pixbuf ProcessFast (Pixbuf input, Cms.Profile input_profile) {
@@ -250,7 +259,7 @@ namespace FSpot.Editors {
 			Reset ();
 		}
 
-		private void Reset () {
+		protected virtual void Reset () {
 			preview_needed = false;
 			while (preview_thread != null)
 				preview_thread.Join ();
@@ -264,14 +273,23 @@ namespace FSpot.Editors {
 			State = null;
 		}
 
+		public Widget ConfigurationWidget {
+			get {
+				Widget widget = CreateConfigurationWidget ();
+				UpdatePreview ();
+				return widget;
+			}
+		}
+
 		// Can be overriden to provide a specific configuration widget.
 		// Returning null means no configuration widget.
-		public virtual Widget ConfigurationWidget () {
+		protected virtual Widget CreateConfigurationWidget () {
 			return null;
 		}
 
 
-		public virtual EditorState CreateState () {
+		public virtual EditorState CreateState ()
+		{
 			return new EditorState ();
 		}
 
diff --git a/src/Editors/RedEyeEditor.cs b/src/Editors/RedEyeEditor.cs
index 9da7a1d..399785a 100644
--- a/src/Editors/RedEyeEditor.cs
+++ b/src/Editors/RedEyeEditor.cs
@@ -21,7 +21,7 @@ namespace FSpot.Editors {
 			ApplyLabel = Catalog.GetString ("Fix!");
 		}
 
-		public override Widget ConfigurationWidget () {
+		protected override Widget CreateConfigurationWidget () {
 			return new Label(Catalog.GetString ("Select the eyes you wish to fix."));
 		}
 
diff --git a/src/Editors/RepeatableEditor.cs b/src/Editors/RepeatableEditor.cs
index ac6b711..f528e69 100644
--- a/src/Editors/RepeatableEditor.cs
+++ b/src/Editors/RepeatableEditor.cs
@@ -13,19 +13,20 @@ using FSpot.Editors.Processing;
 
 namespace FSpot.Editors {
 	public abstract class RepeatableEditor : Editor {
-		protected Pipeline Pipeline { get; private set; }
 
-		public RepeatableEditor (string label, string icon_name)
-				: base (label, icon_name)
-		{
+		Pipeline pipeline;
+		protected Pipeline Pipeline {
+			get {
+				return (State as RepeatableEditorState).Pipeline;
+			}
+			set {
+				(State as RepeatableEditorState).Pipeline = value;
+			}
 		}
 
-		sealed public override void Initialize (EditorState state)
+		public RepeatableEditor (string label, string icon_name)
+				: base (label, icon_name)
 		{
-			base.Initialize (state);
-
-			if (State.Items.Length > 0)
-				Pipeline = new Pipeline (State.Items [0] as Photo);
 		}
 
 		sealed protected override Pixbuf Process (Pixbuf input, Cms.Profile input_profile)
@@ -48,5 +49,15 @@ namespace FSpot.Editors {
 		// appropriate values, chosen in the configuration widget.
 		protected abstract void SetupPipeline ();
 
+		sealed protected override void SaveEditedPhoto (Photo photo, Pixbuf pixbuf)
+		{
+			Pipeline.Save ();
+			base.SaveEditedPhoto (photo, pixbuf);
+		}
+
+		public override EditorState CreateState ()
+		{
+			return new RepeatableEditorState ();
+		}
 	}
 }
diff --git a/src/Editors/RepeatableEditorState.cs b/src/Editors/RepeatableEditorState.cs
new file mode 100644
index 0000000..249f293
--- /dev/null
+++ b/src/Editors/RepeatableEditorState.cs
@@ -0,0 +1,29 @@
+//
+// FSpot.Editors.RepeatableEditorState.cs
+//
+// Author(s)
+// 	Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details.
+//
+
+using Gdk;
+using FSpot.Widgets;
+using FSpot.Editors.Processing;
+
+namespace FSpot.Editors {
+	public class RepeatableEditorState : EditorState {
+		// The processing pipeline
+		Pipeline pipeline;
+		public Pipeline Pipeline {
+			get {
+				if (pipeline == null)
+					pipeline = new Pipeline (Items [0] as Photo);
+				return pipeline;
+			}
+			set {
+				pipeline = value;
+			}
+		}
+	}
+}
diff --git a/src/Editors/SoftFocusEditor.cs b/src/Editors/SoftFocusEditor.cs
index 8f63796..a214532 100644
--- a/src/Editors/SoftFocusEditor.cs
+++ b/src/Editors/SoftFocusEditor.cs
@@ -35,7 +35,7 @@ namespace FSpot.Editors
 			HasSettings = true;
 		}
 
-		public override Widget ConfigurationWidget ()
+		protected override Widget CreateConfigurationWidget ()
 		{
 			scale = new HScale (0, 1, .01);
 			scale.Value = 0.5;
diff --git a/src/Editors/TiltEditor.cs b/src/Editors/TiltEditor.cs
index f14d817..8ee3d56 100644
--- a/src/Editors/TiltEditor.cs
+++ b/src/Editors/TiltEditor.cs
@@ -32,7 +32,7 @@ namespace FSpot.Editors
 			HasSettings = true;
         }
 
-		public override Widget ConfigurationWidget ()
+		protected override Widget CreateConfigurationWidget ()
 		{
 			scale = new HScale (-45, 45, 1);
 			scale.Value = 0.0;
diff --git a/src/Makefile.am b/src/Makefile.am
index c5aa53b..24ce080 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -195,6 +195,7 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Editors/Processing/Step.cs		\
 	$(srcdir)/Editors/RedEyeEditor.cs		\
 	$(srcdir)/Editors/RepeatableEditor.cs		\
+	$(srcdir)/Editors/RepeatableEditorState.cs		\
 	$(srcdir)/Editors/SepiaEditor.cs		\
 	$(srcdir)/Editors/SoftFocusEditor.cs		\
 	$(srcdir)/Editors/TiltEditor.cs		\
diff --git a/src/Widgets/EditorPage.cs b/src/Widgets/EditorPage.cs
index ee15799..e19a8e5 100644
--- a/src/Widgets/EditorPage.cs
+++ b/src/Widgets/EditorPage.cs
@@ -242,7 +242,7 @@ namespace FSpot.Widgets {
 			vbox.PackStart (label, false, false, 5);
 
 			// Optional config widget
-			Widget config = editor.ConfigurationWidget ();
+			Widget config = editor.ConfigurationWidget;
 			if (config != null) {
 				vbox.PackStart (config, false, false, 0);
 			}



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