[f-spot/rubenv-gsoc-2009: 53/86] Split out Editor, add initial RepeatableEditor.



commit f26ab9f3ffee874c1fba42a630bad83931adb12e
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Aug 4 18:30:32 2009 +0200

    Split out Editor, add initial RepeatableEditor.

 src/Editors/Editor.cs                     |   73 ++++++++---------------------
 src/Editors/EditorNode.cs                 |   22 +++++++++
 src/Editors/EditorState.cs                |   34 +++++++++++++
 src/Editors/Processing/ColorAdjustStep.cs |    4 ++
 src/Editors/Processing/Pipeline.cs        |   27 +++++++++--
 src/Editors/Processing/SettingStore.cs    |    2 +-
 src/Editors/Processing/Step.cs            |    2 +
 src/Editors/RepeatableEditor.cs           |   43 +++++++++++++++++
 src/Makefile.am                           |   17 ++++---
 9 files changed, 158 insertions(+), 66 deletions(-)
---
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index f41998c..d57f514 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -1,11 +1,11 @@
-/*
- * Editor.cs
- *
- * Author(s)
- * 	Ruben Vermeersch <ruben savanne be>
- *
- * This is free software. See COPYING for details.
- */
+//
+// FSpot.Editors.Editor.cs
+//
+// Author(s)
+// 	Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details.
+//
 
 using FSpot;
 using FSpot.Utils;
@@ -15,43 +15,11 @@ using FSpot.Loaders;
 using Gdk;
 using Gtk;
 
-using Mono.Addins;
 using Mono.Unix;
 
 using System;
 
 namespace FSpot.Editors {
-	[ExtensionNode ("Editor")]
-	public class EditorNode : ExtensionNode {
-		[NodeAttribute (Required=true)]
-		protected string editor_type;
-
-		public Editor GetEditor () {
-			return (Editor) Addin.CreateInstance (editor_type);
-		}
-	}
-
-	public class EditorState {
-		// The area selected by the user.
-		public Rectangle Selection { get; set; }
-
-		// The images selected by the user.
-		public IBrowsableItem [] Items { get; set; }
-
-		// The view, into which images are shown (null if we are in the browse view).
-		public PhotoImageView PhotoImageView { get; set; }
-
-		// Has a portion of the image been selected?
-		public bool HasSelection {
-			get { return Selection != Rectangle.Zero; }
-		}
-
-		// Is the user in browse mode?
-		public bool InBrowseMode {
-			get { return PhotoImageView == null; }
-		}
-	}
-
 	// This is the base class from which all editors inherit.
 	public abstract class Editor {
 		public delegate void ProcessingStartedHandler (string name, int count);
@@ -62,6 +30,11 @@ namespace FSpot.Editors {
 		public event ProcessingStepHandler ProcessingStep;
 		public event ProcessingFinishedHandler ProcessingFinished;
 
+		// Whether the user needs to select a part of the image before it can be applied.
+		public bool NeedsSelection { get; protected set; }
+		public bool CanHandleMultiple { get; protected set; }
+		public bool HasSettings { get; protected set; }
+
 		// Contains the current selection, the items being edited, ...
 		private EditorState state;
 		public EditorState State {
@@ -78,10 +51,6 @@ namespace FSpot.Editors {
 			get { return state != null; }
 		}
 
-
-		// Whether the user needs to select a part of the image before it can be applied.
-		public bool NeedsSelection = false;
-
 		// A tool can be applied if it doesn't need a selection, or if it has one.
 		public bool CanBeApplied {
 			get {
@@ -90,14 +59,7 @@ namespace FSpot.Editors {
 			}
 		}
 
-		private bool can_handle_multiple = false;
-		public bool CanHandleMultiple {
-			get { return can_handle_multiple; }
-			protected set { can_handle_multiple = value; }
-		}
-
-
-		protected void LoadPhoto (Photo photo, out Pixbuf photo_pixbuf, out Cms.Profile photo_profile) {
+		protected virtual void LoadPhoto (Photo photo, out Pixbuf photo_pixbuf, out Cms.Profile photo_profile) {
 			// FIXME: We might get this value from the PhotoImageView.
 			using (ImageFile img = ImageFile.Create (photo.DefaultVersion.Uri)) {
 				if (State.PhotoImageView != null) {
@@ -129,6 +91,12 @@ namespace FSpot.Editors {
 		public Editor (string label, string icon_name) {
 			Label = label;
 			IconName = icon_name;
+
+			// Default values for capabilities, these need to be set in
+			// the subclass constructor.
+			CanHandleMultiple = false;
+			NeedsSelection = false;
+			HasSettings = false;
 		}
 
 		// Apply the editor's action to a photo.
@@ -179,7 +147,6 @@ namespace FSpot.Editors {
 			return Process (input, input_profile);
 		}
 
-		public bool HasSettings { get; protected set; }
 		Pixbuf Original { get; set; }
 		Pixbuf Preview { get; set; }
 
diff --git a/src/Editors/EditorNode.cs b/src/Editors/EditorNode.cs
new file mode 100644
index 0000000..b51b306
--- /dev/null
+++ b/src/Editors/EditorNode.cs
@@ -0,0 +1,22 @@
+//
+// FSpot.Editors.EditorNode.cs
+//
+// Author(s)
+// 	Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details.
+//
+
+using Mono.Addins;
+
+namespace FSpot.Editors {
+	[ExtensionNode ("Editor")]
+	public class EditorNode : ExtensionNode {
+		[NodeAttribute (Required=true)]
+		protected string editor_type;
+
+		public Editor GetEditor () {
+			return (Editor) Addin.CreateInstance (editor_type);
+		}
+	}
+}
diff --git a/src/Editors/EditorState.cs b/src/Editors/EditorState.cs
new file mode 100644
index 0000000..db38ee4
--- /dev/null
+++ b/src/Editors/EditorState.cs
@@ -0,0 +1,34 @@
+//
+// FSpot.Editors.EditorState.cs
+//
+// Author(s)
+// 	Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details.
+//
+
+using Gdk;
+using FSpot.Widgets;
+
+namespace FSpot.Editors {
+	public class EditorState {
+		// The area selected by the user.
+		public Rectangle Selection { get; set; }
+
+		// The images selected by the user.
+		public IBrowsableItem [] Items { get; set; }
+
+		// The view, into which images are shown (null if we are in the browse view).
+		public PhotoImageView PhotoImageView { get; set; }
+
+		// Has a portion of the image been selected?
+		public bool HasSelection {
+			get { return Selection != Rectangle.Zero; }
+		}
+
+		// Is the user in browse mode?
+		public bool InBrowseMode {
+			get { return PhotoImageView == null; }
+		}
+	}
+}
diff --git a/src/Editors/Processing/ColorAdjustStep.cs b/src/Editors/Processing/ColorAdjustStep.cs
index ea58ffe..5ddeff2 100644
--- a/src/Editors/Processing/ColorAdjustStep.cs
+++ b/src/Editors/Processing/ColorAdjustStep.cs
@@ -18,6 +18,10 @@ namespace FSpot.Editors.Processing {
 			Pipeline.AddStep (150, new ColorAdjustStep ());
 		}
 
+		public string Name {
+			get { return "ColorAdjust"; }
+		}
+
 		public void Process (Pipeline pipeline, Pixbuf input, out Pixbuf output)
 		{
 			output = input.ShallowCopy ();
diff --git a/src/Editors/Processing/Pipeline.cs b/src/Editors/Processing/Pipeline.cs
index b156eae..2438516 100644
--- a/src/Editors/Processing/Pipeline.cs
+++ b/src/Editors/Processing/Pipeline.cs
@@ -13,7 +13,7 @@ using System;
 using System.Collections.Generic;
 
 namespace FSpot.Editors.Processing {
-	public class Pipeline
+	public class Pipeline : IDisposable
 	{
 #region Step registration
 		static SortedList<uint, Step> Steps { get; set; }
@@ -42,8 +42,23 @@ namespace FSpot.Editors.Processing {
 			}
 		}
 
+		~Pipeline ()
+		{
+			Dispose ();
+		}
+
+		public void Dispose ()
+		{
+			if (Output != null) {
+				Output.Dispose ();
+				Output = null;
+			}
+
+		}
+
 #region Processing
 		public Pixbuf Input { get; set; }
+		public Cms.Profile InputProfile { get; set; }
 		public Pixbuf Output { get; private set; }
 
 		public void Process ()
@@ -62,13 +77,14 @@ namespace FSpot.Editors.Processing {
 #region Settings
 		Dictionary<string, Setting> Settings { get; set; }
 
-		public void Set (string key, bool val)
+		public void Set (Step step, string key, bool val)
 		{
-			Set (key, val ? "1" : "0");
+			Set (step, key, val ? "1" : "0");
 		}
 
-		public void Set (string key, string val)
+		public void Set (Step step, string key, string val)
 		{
+			key = step.Name + ":" + key;
 			if (Settings.ContainsKey (key)) {
 				Settings [key].Value = val;
 			} else {
@@ -76,8 +92,9 @@ namespace FSpot.Editors.Processing {
 			}
 		}
 
-		public Setting Get (string key)
+		public Setting Get (Step step, string key)
 		{
+			key = step.Name + ":" + key;
 			Setting setting;
 			if (!Settings.TryGetValue (key, out setting))
 				setting = new Setting (Photo.Id, Photo.DefaultVersionId, key, null);
diff --git a/src/Editors/Processing/SettingStore.cs b/src/Editors/Processing/SettingStore.cs
index e0a4002..5f44f19 100644
--- a/src/Editors/Processing/SettingStore.cs
+++ b/src/Editors/Processing/SettingStore.cs
@@ -77,7 +77,7 @@ namespace FSpot.Editors.Processing {
 		public override void Commit (Setting setting)
 		{
 			if (setting.Id == 0) {
-				uint id = (uint) Database.Execute (
+				Database.ExecuteNonQuery (
 						new DbCommand (
 							"INSERT INTO processing_settings (photo_id, version_id, key, value) " +
 							"VALUES (:photo_id, :version_id, :key, :value)",
diff --git a/src/Editors/Processing/Step.cs b/src/Editors/Processing/Step.cs
index c68bbe2..9b65318 100644
--- a/src/Editors/Processing/Step.cs
+++ b/src/Editors/Processing/Step.cs
@@ -12,6 +12,8 @@ using Gdk;
 namespace FSpot.Editors.Processing {
 	public interface Step
 	{
+		string Name { get; }
+
 		void Process (Pipeline pipeline, Pixbuf input, out Pixbuf output);
 	}
 }
diff --git a/src/Editors/RepeatableEditor.cs b/src/Editors/RepeatableEditor.cs
new file mode 100644
index 0000000..d078c47
--- /dev/null
+++ b/src/Editors/RepeatableEditor.cs
@@ -0,0 +1,43 @@
+//
+// FSpot.Editors.RepeatableEditor.cs
+//
+// Author(s)
+// 	Ruben Vermeersch <ruben savanne be>
+//
+// This is free software. See COPYING for details.
+//
+
+using Gdk;
+using FSpot.Utils;
+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)
+		{
+
+		}
+
+		// When this is called, the pipeline should be filled with the
+		// appropriate values, chosen in the configuration widget.
+		protected abstract void SetupPipeline ();
+
+		sealed protected override Pixbuf Process (Pixbuf input, Cms.Profile input_profile)
+		{
+			Pipeline.Input = input;
+			Pipeline.InputProfile = input_profile;
+			Pipeline.Process ();
+			return Pipeline.Output.ShallowCopy ();
+		}
+
+		sealed protected override void LoadPhoto (Photo photo, out Pixbuf photo_pixbuf, out Cms.Profile photo_profile)
+		{
+			base.LoadPhoto (photo, out photo_pixbuf, out photo_profile);
+			Pipeline = new Pipeline (photo);
+			SetupPipeline ();
+		}
+	}
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index f02c0fc..b235eb4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -183,20 +183,23 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Db.cs				\
 	$(srcdir)/DependentListStore.cs		\
 	$(srcdir)/DragDropTargets.cs				\
-	$(srcdir)/Editors/Editor.cs		\
 	$(srcdir)/Editors/AutoStretchEditor.cs		\
-	$(srcdir)/Editors/CropEditor.cs		\
 	$(srcdir)/Editors/ColorEditor.cs		\
+	$(srcdir)/Editors/CropEditor.cs		\
 	$(srcdir)/Editors/DesaturateEditor.cs		\
-	$(srcdir)/Editors/RedEyeEditor.cs		\
-	$(srcdir)/Editors/SepiaEditor.cs		\
-	$(srcdir)/Editors/SoftFocusEditor.cs		\
-	$(srcdir)/Editors/TiltEditor.cs		\
+	$(srcdir)/Editors/Editor.cs		\
+	$(srcdir)/Editors/EditorNode.cs		\
+	$(srcdir)/Editors/EditorState.cs		\
+	$(srcdir)/Editors/Processing/ColorAdjustStep.cs		\
 	$(srcdir)/Editors/Processing/Pipeline.cs		\
 	$(srcdir)/Editors/Processing/Setting.cs		\
 	$(srcdir)/Editors/Processing/SettingStore.cs		\
 	$(srcdir)/Editors/Processing/Step.cs		\
-	$(srcdir)/Editors/Processing/ColorAdjustStep.cs		\
+	$(srcdir)/Editors/RedEyeEditor.cs		\
+	$(srcdir)/Editors/RepeatableEditor.cs		\
+	$(srcdir)/Editors/SepiaEditor.cs		\
+	$(srcdir)/Editors/SoftFocusEditor.cs		\
+	$(srcdir)/Editors/TiltEditor.cs		\
 	$(srcdir)/ExportStore.cs		\
 	$(srcdir)/Extensions/ExportMenuItemNode.cs	\
 	$(srcdir)/Extensions/IExporter.cs	\



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