f-spot r3926 - in trunk: . extensions extensions/DevelopInUFraw src src/Extensions



Author: rubenv
Date: Sun May 18 09:51:53 2008
New Revision: 3926
URL: http://svn.gnome.org/viewvc/f-spot?rev=3926&view=rev

Log:
2008-05-18  Ruben Vermeersch  <ruben savanne be>

	* src/Extensions/PhotoSelectionCondition.cs: Added. Allows addins to
	conditionally show up, depending on how much photos are selected.

	* src/FSpot.addin.xml: Add the condition.

	* src/Makefile.am: Add PhotoSelectionCondition.cs.

	* DevelopInUFraw/DevelopInUFRaw.addin.xml: Bump version, add Batch option,
	only show when multiple photos are selected.

	* DevelopInUFraw/DevelopInUFRaw.cs: Abstract the DevelopInUFraw class, add
	one for developing in the GUI and another one for batch develops which
	shows a progress bar.


Added:
   trunk/src/Extensions/PhotoSelectionCondition.cs
Modified:
   trunk/ChangeLog
   trunk/extensions/ChangeLog
   trunk/extensions/DevelopInUFraw/DevelopInUFRaw.addin.xml
   trunk/extensions/DevelopInUFraw/DevelopInUFRaw.cs
   trunk/src/FSpot.addin.xml
   trunk/src/Makefile.am
   trunk/src/PhotoPopup.cs

Modified: trunk/extensions/DevelopInUFraw/DevelopInUFRaw.addin.xml
==============================================================================
--- trunk/extensions/DevelopInUFraw/DevelopInUFRaw.addin.xml	(original)
+++ trunk/extensions/DevelopInUFraw/DevelopInUFRaw.addin.xml	Sun May 18 09:51:53 2008
@@ -1,6 +1,6 @@
 <Addin namespace="FSpot"
 	id="DevelopInUFraw"
-	version="0.4.3.1"
+	version="0.4.3.2"
 	name="DevelopInUFRaw"
 	description="Develop the image in UFRaw, saves the result as a new version\n\nNote: Require ufraw 0.13 or CVS version newer than 2007-09-06 !!!"
 	author="Stephane Delcroix"
@@ -11,6 +11,9 @@
 	</Dependencies>
 	<Extension path = "/FSpot/Menus/PhotoPopup">
 		<Command id = "DevelopInUFRaw" _label = "Develop in UFRaw" command_type = "DevelopInUFRawExtension.DevelopInUFRaw" insertbefore="OpenWith"/>
+		<Condition id="PhotoSelection" selection="multiple">
+			<Command id = "DevelopInUFRawBatch" _label = "Batch Develop" command_type = "DevelopInUFRawExtension.DevelopInUFRawBatch" insertbefore="OpenWith"/>
+		</Condition>
 	</Extension>
 </Addin>
 

Modified: trunk/extensions/DevelopInUFraw/DevelopInUFRaw.cs
==============================================================================
--- trunk/extensions/DevelopInUFraw/DevelopInUFRaw.cs	(original)
+++ trunk/extensions/DevelopInUFraw/DevelopInUFRaw.cs	Sun May 18 09:51:53 2008
@@ -16,51 +16,100 @@
 
 namespace DevelopInUFRawExtension
 {
-	public class DevelopInUFRaw: ICommand
-	{
-		public void Run (object o, EventArgs e)
+	// GUI Version
+	public class DevelopInUFRaw : AbstractDevelopInUFRaw {
+		public DevelopInUFRaw() : base("ufraw")
+		{
+		}
+
+		public override void Run (object o, EventArgs e)
 		{
 			Console.WriteLine ("EXECUTING DEVELOP IN UFRAW EXTENSION");
 			
 			foreach (Photo p in MainWindow.Toplevel.SelectedPhotos ()) {
-				PhotoVersion raw = p.GetVersion (Photo.OriginalVersionId) as PhotoVersion;
-				if (!ImageFile.IsRaw (raw.Uri.AbsolutePath)) {
-					Console.WriteLine ("The Original version of this image is not a (supported) RAW file");
-					continue;
-				}
+				DevelopPhoto (p);
+			}	
+		}
+	}
 
-				string name = GetVersionName (p);
-				System.Uri developed = GetUriForVersionName (p, name);
-				string idfile = "";
+	// Batch Version
+	public class DevelopInUFRawBatch : AbstractDevelopInUFRaw {
+		public DevelopInUFRawBatch() : base("ufraw-batch")
+		{
+		}
 
-				if (new Gnome.Vfs.Uri (Path.ChangeExtension (raw.Uri.ToString (), ".ufraw")).Exists) {
-					// We found an ID file, use that instead of the raw file
-					idfile = "--conf=" + Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw");
+		public override void Run (object o, EventArgs e)
+		{
+			ProgressDialog pdialog = new ProgressDialog(Catalog.GetString ("Developing photos"),
+														ProgressDialog.CancelButtonType.Cancel,
+														MainWindow.Toplevel.SelectedPhotos ().Length,
+														MainWindow.Toplevel.Window);
+			Console.WriteLine ("EXECUTING DEVELOP IN UFRAW EXTENSION");
+			
+			foreach (Photo p in MainWindow.Toplevel.SelectedPhotos ()) {
+				bool cancelled = pdialog.Update(String.Format(Catalog.GetString ("Developing {0}"), p.Name));
+				if (cancelled) {
+					break;
 				}
 
-				string args = String.Format("--overwrite --create-id=also --compression=98 --out-type=jpeg {0} --output={1} {2}", 
-					idfile,
-					CheapEscape (developed.LocalPath),
-					CheapEscape (raw.Uri.ToString ()));
-				Console.WriteLine ("ufraw " + args);
-
-				System.Diagnostics.Process ufraw = System.Diagnostics.Process.Start ("ufraw", args); 
-				ufraw.WaitForExit ();
-				if (!(new Gnome.Vfs.Uri (developed.ToString ())).Exists) {
-					Console.WriteLine ("UFraw didn't ended well. Check that you have UFRaw 0.13 (or CVS newer than 2007-09-06). Or did you simply clicked on Cancel ?");
-					continue;
-				}
+				DevelopPhoto (p);
+			}	
+			pdialog.Destroy();
+		}
+	}
+
+	// Abstract version, contains shared functionality
+	public abstract class AbstractDevelopInUFRaw : ICommand
+	{
+		// The executable used for developing RAWs
+		private string executable;
+
+		public AbstractDevelopInUFRaw(string executable) 
+		{
+			this.executable = executable;
+		}
+
+		public abstract void Run (object o, EventArgs e);
 
-				if (new Gnome.Vfs.Uri (Path.ChangeExtension (developed.ToString (), ".ufraw")).Exists) {
-					if (new Gnome.Vfs.Uri (Path.ChangeExtension (raw.Uri.ToString (), ".ufraw")).Exists) {
-						File.Delete (Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw"));
-					}
-					File.Move (Path.ChangeExtension (developed.LocalPath, ".ufraw"), Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw"));
+		protected void DevelopPhoto (Photo p)
+		{
+			PhotoVersion raw = p.GetVersion (Photo.OriginalVersionId) as PhotoVersion;
+			if (!ImageFile.IsRaw (raw.Uri.AbsolutePath)) {
+				Console.WriteLine ("The Original version of this image is not a (supported) RAW file");
+				return;
+			}
+
+			string name = GetVersionName (p);
+			System.Uri developed = GetUriForVersionName (p, name);
+			string idfile = "";
+
+			if (new Gnome.Vfs.Uri (Path.ChangeExtension (raw.Uri.ToString (), ".ufraw")).Exists) {
+				// We found an ID file, use that instead of the raw file
+				idfile = "--conf=" + Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw");
+			}
+
+			string args = String.Format("--overwrite --create-id=also --compression=98 --out-type=jpeg {0} --output={1} {2}", 
+				idfile,
+				CheapEscape (developed.LocalPath),
+				CheapEscape (raw.Uri.ToString ()));
+			Console.WriteLine (executable+" " + args);
+
+			System.Diagnostics.Process ufraw = System.Diagnostics.Process.Start (executable, args); 
+			ufraw.WaitForExit ();
+			if (!(new Gnome.Vfs.Uri (developed.ToString ())).Exists) {
+				Console.WriteLine ("UFraw didn't ended well. Check that you have UFRaw 0.13 (or CVS newer than 2007-09-06). Or did you simply clicked on Cancel ?");
+				return;
+			}
+
+			if (new Gnome.Vfs.Uri (Path.ChangeExtension (developed.ToString (), ".ufraw")).Exists) {
+				if (new Gnome.Vfs.Uri (Path.ChangeExtension (raw.Uri.ToString (), ".ufraw")).Exists) {
+					File.Delete (Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw"));
 				}
+				File.Move (Path.ChangeExtension (developed.LocalPath, ".ufraw"), Path.ChangeExtension (raw.Uri.LocalPath, ".ufraw"));
+			}
 
-				p.DefaultVersionId = p.AddVersion (developed, name, true);
-				Core.Database.Photos.Commit (p);
-			}	
+			p.DefaultVersionId = p.AddVersion (developed, name, true);
+			Core.Database.Photos.Commit (p);
 		}
 
 		private static string GetVersionName (Photo p)

Added: trunk/src/Extensions/PhotoSelectionCondition.cs
==============================================================================
--- (empty file)
+++ trunk/src/Extensions/PhotoSelectionCondition.cs	Sun May 18 09:51:53 2008
@@ -0,0 +1,47 @@
+/*
+ * FSpot.Extensions.PhotoSelectionCondition.cs
+ *
+ * Author(s)
+ * 	Ruben Vermeersch  <ruben savanne be>
+ *
+ * This is free software. See COPYING for details.
+ *
+ */
+
+using Mono.Addins;
+
+namespace FSpot.Extensions
+{
+	// Defines a selection condition, which determines the number of photos 
+	// selected.
+	//
+	// There are two valid values for the "selection" attribute, which 
+	// should be added to the Condition tag.
+	//   - single: One photo is selected
+	//   - multiple: Multiple photos are selected
+	public class PhotoSelectionCondition : ConditionType
+	{
+		public PhotoSelectionCondition()
+		{
+			MainWindow.Toplevel.Selection.Changed += delegate {
+				NotifyChanged ();
+			};
+		}
+
+		public override bool Evaluate (NodeElement conditionNode)
+		{
+			int count = MainWindow.Toplevel.Selection.Count;
+			string val = conditionNode.GetAttribute ("selection");
+			if (val.Length > 0) {
+				foreach (string selection in val.Split(',')) {
+					if (selection == "multiple" && count > 1) {
+						return true;
+					} else if (selection == "single" && count == 1) {
+						return true;
+					}
+				}
+			}
+			return false;
+		}
+	}
+}

Modified: trunk/src/FSpot.addin.xml
==============================================================================
--- trunk/src/FSpot.addin.xml	(original)
+++ trunk/src/FSpot.addin.xml	Sun May 18 09:51:53 2008
@@ -24,6 +24,8 @@
 		<Menu id = "PhotoPopup" />
 	</Extension>
 
+    <ConditionType id="PhotoSelection" type="FSpot.Extensions.PhotoSelectionCondition" />
+
 	<Extension path = "/FSpot/Menus/PhotoPopup">
 		<Command id = "CopyLocation" _label = "Copy Photo Locat_ion" command_type = "FSpot.Extensions.CopyLocation" />
 		<MenuSeparator id = "Separator1" />

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sun May 18 09:51:53 2008
@@ -72,6 +72,7 @@
 	$(srcdir)/Extensions/OpenWithMenu.cs	\
 	$(srcdir)/Extensions/CommandMenuItemNode.cs	\
 	$(srcdir)/Extensions/ComplexMenuItemNode.cs	\
+	$(srcdir)/Extensions/PhotoSelectionCondition.cs	\
 	$(srcdir)/Extensions/PopupCommands.cs	\
 	$(srcdir)/Fader.cs			\
 	$(srcdir)/FileImportBackend.cs		\

Modified: trunk/src/PhotoPopup.cs
==============================================================================
--- trunk/src/PhotoPopup.cs	(original)
+++ trunk/src/PhotoPopup.cs	Sun May 18 09:51:53 2008
@@ -26,8 +26,9 @@
 
 		public PhotoPopup () : base ()
 		{
-			foreach (MenuNode node in AddinManager.GetExtensionNodes ("/FSpot/Menus/PhotoPopup"))
+			foreach (MenuNode node in AddinManager.GetExtensionNodes ("/FSpot/Menus/PhotoPopup")) {
 				Append (node.GetMenuItem ());
+			}
 			ShowAll ();
 		}
 
@@ -38,10 +39,10 @@
 
 		public void Activate (Widget toplevel, Gdk.EventButton eb) 
 		{
-	                if (eb != null)
-        	                Popup (null, null, null, eb.Button, eb.Time);
-                	else 
-                        	Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
+			if (eb != null)
+				Popup (null, null, null, eb.Button, eb.Time);
+			else 
+				Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
 		}
 
 	}



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