[f-spot] Rename Delay to DelayedOperation, move into FSpot.Utils.



commit c383623b9f3d36bec5c62da27fa0093e1c500e1a
Author: Ruben Vermeersch <ruben savanne be>
Date:   Fri Aug 13 18:16:22 2010 +0200

    Rename Delay to DelayedOperation, move into FSpot.Utils.

 .../MainApp/FSpot.UI.Dialog/EditTagIconDialog.cs   |    2 +-
 .../FSpot.UI.Dialog/ThreadProgressDialog.cs        |    6 +-
 src/Clients/MainApp/FSpot.Widgets/InfoBox.cs       |    8 +-
 src/Clients/MainApp/FSpot.Widgets/Loupe.cs         |    4 +-
 .../MainApp/FSpot.Widgets/MetadataDisplay.cs       |    5 +-
 src/Clients/MainApp/FSpot.Widgets/SlideShow.cs     |    5 +-
 src/Clients/MainApp/FSpot/ControlOverlay.cs        |   12 ++--
 src/Clients/MainApp/FSpot/FullScreenView.cs        |    4 +-
 src/Clients/MainApp/FSpot/GroupSelector.cs         |   12 ++--
 src/Clients/MainApp/FSpot/PhotoView.cs             |    4 +-
 src/Core/FSpot.Core/FSpot.Core.csproj              |    4 +-
 src/Core/FSpot.Core/FSpot.Core/Delay.cs            |   94 --------------------
 src/Core/FSpot.Core/Makefile.am                    |    1 -
 src/Core/FSpot.Gui/FSpot.Widgets/ScrolledView.cs   |    6 +-
 src/Core/FSpot.Utils/FSpot.Utils.csproj            |    1 +
 .../FSpot.Utils/FSpot.Utils/DelayedOperation.cs    |   93 +++++++++++++++++++
 src/Core/FSpot.Utils/Makefile.am                   |    1 +
 17 files changed, 133 insertions(+), 129 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.UI.Dialog/EditTagIconDialog.cs b/src/Clients/MainApp/FSpot.UI.Dialog/EditTagIconDialog.cs
index 402fdc4..2582902 100644
--- a/src/Clients/MainApp/FSpot.UI.Dialog/EditTagIconDialog.cs
+++ b/src/Clients/MainApp/FSpot.UI.Dialog/EditTagIconDialog.cs
@@ -110,7 +110,7 @@ namespace FSpot.UI.Dialog
 
 			image_view.Show ();
 
-			Delay fill_delay = new Delay (FillIconView);
+			DelayedOperation fill_delay = new DelayedOperation (FillIconView);
 			fill_delay.Start ();
 		}
 
diff --git a/src/Clients/MainApp/FSpot.UI.Dialog/ThreadProgressDialog.cs b/src/Clients/MainApp/FSpot.UI.Dialog/ThreadProgressDialog.cs
index 50eb318..556cb93 100644
--- a/src/Clients/MainApp/FSpot.UI.Dialog/ThreadProgressDialog.cs
+++ b/src/Clients/MainApp/FSpot.UI.Dialog/ThreadProgressDialog.cs
@@ -16,11 +16,11 @@ using System.Collections.Generic;
 
 using Gtk;
 
-using FSpot.Core;
+using FSpot.Utils;
 
 namespace FSpot.UI.Dialog {
 	public class ThreadProgressDialog : Gtk.Dialog {
-		Delay delay;
+		DelayedOperation delay;
 
 		Gtk.ProgressBar progress_bar;
 		Gtk.Label message_label;
@@ -65,7 +65,7 @@ namespace FSpot.UI.Dialog {
 			button_label = Gtk.Stock.Cancel;
 			button = (Gtk.Button) AddButton (button_label, (int)Gtk.ResponseType.Cancel);
 
-			delay = new Delay (new GLib.IdleHandler (HandleUpdate));
+			delay = new DelayedOperation (new GLib.IdleHandler (HandleUpdate));
 
 			Response += HandleResponse;
 			Destroyed += HandleDestroy;
diff --git a/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs b/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
index 60311d4..25b85a6 100644
--- a/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
@@ -31,7 +31,7 @@ using Hyena;
 namespace FSpot.Widgets
 {
 	public class InfoBox : VBox {
-		Delay update_delay;
+		DelayedOperation update_delay;
 
 		private IPhoto [] photos = new IPhoto [0];
 		public IPhoto [] Photos {
@@ -86,7 +86,7 @@ namespace FSpot.Widgets
 		private Gtk.Image histogram_image;
 		private Histogram histogram;
 
-		private Delay histogram_delay;
+		private DelayedOperation histogram_delay;
 
 		// Context switching (toggles visibility).
 		public event EventHandler ContextChanged;
@@ -798,10 +798,10 @@ namespace FSpot.Widgets
 
 			SetupWidgets ();
 
-			update_delay = new Delay (Update);
+			update_delay = new DelayedOperation (Update);
 			update_delay.Start ();
 
-			histogram_delay = new Delay (DelayedUpdateHistogram);
+			histogram_delay = new DelayedOperation (DelayedUpdateHistogram);
 
 			BorderWidth = 2;
 			Hide ();
diff --git a/src/Clients/MainApp/FSpot.Widgets/Loupe.cs b/src/Clients/MainApp/FSpot.Widgets/Loupe.cs
index 417e09e..eee0b61 100644
--- a/src/Clients/MainApp/FSpot.Widgets/Loupe.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/Loupe.cs
@@ -303,7 +303,7 @@ namespace FSpot.Widgets {
 
 		bool dragging = false;
 		bool rotate = false;
-		Delay drag;
+		DelayedOperation drag;
 		Gdk.Point pos;
 		double start_angle = 0;
 		Gdk.Point root_pos;
@@ -485,7 +485,7 @@ namespace FSpot.Widgets {
 			MotionNotifyEvent += HandleMotionNotifyEvent;
 			KeyPressEvent += HandleKeyPressEvent;
 
-			drag = new Delay (20, new GLib.IdleHandler (DragUpdate));
+			drag = new DelayedOperation (20, new GLib.IdleHandler (DragUpdate));
 
 			// Update the cursor appropriate to indicate dragability/dragging
 			bool inside = false, pressed = false;
diff --git a/src/Clients/MainApp/FSpot.Widgets/MetadataDisplay.cs b/src/Clients/MainApp/FSpot.Widgets/MetadataDisplay.cs
index 13a9f5b..db85436 100644
--- a/src/Clients/MainApp/FSpot.Widgets/MetadataDisplay.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/MetadataDisplay.cs
@@ -17,6 +17,7 @@ using Gtk;
 using Mono.Unix;
 
 using FSpot.Core;
+using FSpot.Utils;
 using FSpot.Extensions;
 using FSpot.Imaging;
 
@@ -37,7 +38,7 @@ namespace FSpot.Widgets {
 	}
 
 	public class MetadataDisplayWidget : ScrolledWindow {
-		Delay update_delay;
+		DelayedOperation update_delay;
 
 		/* 	This VBox only contains exif-data,
 			so it is seperated from other information */
@@ -112,7 +113,7 @@ namespace FSpot.Widgets {
 			main_vbox.PackStart (expander, false, false, 6);
 			expander.ShowAll ();
 
-			update_delay = new Delay (Update);
+			update_delay = new DelayedOperation (Update);
 			update_delay.Start ();
 		}
 
diff --git a/src/Clients/MainApp/FSpot.Widgets/SlideShow.cs b/src/Clients/MainApp/FSpot.Widgets/SlideShow.cs
index cf751bf..2507019 100644
--- a/src/Clients/MainApp/FSpot.Widgets/SlideShow.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/SlideShow.cs
@@ -18,6 +18,7 @@ using FSpot.Bling;
 using FSpot.Extensions;
 using FSpot.Imaging;
 using FSpot.Transitions;
+using FSpot.Utils;
 
 namespace FSpot.Widgets
 {
@@ -46,7 +47,7 @@ namespace FSpot.Widgets
 				transitions.Add (transition.Transition);
 			}
 
-			flip = new Delay (interval_ms, delegate {item.MoveNext (true); return true;});
+			flip = new DelayedOperation (interval_ms, delegate {item.MoveNext (true); return true;});
 			animation = new DoubleAnimation (0, 1, new TimeSpan (0, 0, 2), HandleProgressChanged, GLib.Priority.Default);
 
 			if (init) {
@@ -71,7 +72,7 @@ namespace FSpot.Widgets
 		}
 
 		DoubleAnimation animation;
-		Delay flip;
+		DelayedOperation flip;
 		public void Start ()
 		{
 			running = true;
diff --git a/src/Clients/MainApp/FSpot/ControlOverlay.cs b/src/Clients/MainApp/FSpot/ControlOverlay.cs
index 0e8fd77..3501473 100644
--- a/src/Clients/MainApp/FSpot/ControlOverlay.cs
+++ b/src/Clients/MainApp/FSpot/ControlOverlay.cs
@@ -24,9 +24,9 @@ namespace FSpot {
 		bool composited;
 		VisibilityType visibility;
 		int round = 12;
-		Delay hide;
-		Delay fade;
-		Delay dismiss;
+		DelayedOperation hide;
+		DelayedOperation fade;
+		DelayedOperation dismiss;
 		bool auto_hide = true;
 		double x_align = 0.5;
 		double y_align = 1.0;
@@ -100,9 +100,9 @@ namespace FSpot {
 			host_toplevel.SizeAllocated += HandleHostSizeAllocated;
 
 			AddEvents ((int) (Gdk.EventMask.PointerMotionMask));
-			hide = new Delay (2000, HideControls);
-			fade = new Delay (40, FadeToTarget);
-			dismiss = new Delay (2000, delegate { /* do nothing */ return false; });
+			hide = new DelayedOperation (2000, HideControls);
+			fade = new DelayedOperation (40, FadeToTarget);
+			dismiss = new DelayedOperation (2000, delegate { /* do nothing */ return false; });
 		}
 
 		protected override void OnDestroyed ()
diff --git a/src/Clients/MainApp/FSpot/FullScreenView.cs b/src/Clients/MainApp/FSpot/FullScreenView.cs
index 9b66b7d..4bdbcfd 100644
--- a/src/Clients/MainApp/FSpot/FullScreenView.cs
+++ b/src/Clients/MainApp/FSpot/FullScreenView.cs
@@ -27,7 +27,7 @@ namespace FSpot {
 		private SlideShow display;
 		private ToolButton play_pause_button;
 		private ToggleToolButton info_button;
-		private Delay hide_cursor_delay;
+		private DelayedOperation hide_cursor_delay;
 
 		ActionGroup actions;
 		const string ExitFullScreen = "ExitFullScreen";
@@ -171,7 +171,7 @@ namespace FSpot {
 				view.Item.Changed += HandleItemChanged;
 				view.GrabFocus ();
 
-				hide_cursor_delay = new Delay (3000, new GLib.IdleHandler (HideCursor));
+				hide_cursor_delay = new DelayedOperation (3000, new GLib.IdleHandler (HideCursor));
 				hide_cursor_delay.Start ();
 
 				controls = new ControlOverlay (this);
diff --git a/src/Clients/MainApp/FSpot/GroupSelector.cs b/src/Clients/MainApp/FSpot/GroupSelector.cs
index b8fca11..423cacf 100644
--- a/src/Clients/MainApp/FSpot/GroupSelector.cs
+++ b/src/Clients/MainApp/FSpot/GroupSelector.cs
@@ -22,8 +22,8 @@ namespace FSpot {
 
 		private Gtk.Button left;
 		private Gtk.Button right;
-		private Delay left_delay;
-		private Delay right_delay;
+		private DelayedOperation left_delay;
+		private DelayedOperation right_delay;
 
 		private Gdk.Window event_window;
 
@@ -533,7 +533,7 @@ namespace FSpot {
 
 		public abstract class Manipulator {
 			protected GroupSelector selector;
-			protected Delay timer;
+			protected DelayedOperation timer;
 			public bool Dragging;
 			public bool UpdateGlass;
 			public bool GlassUpdating;
@@ -542,7 +542,7 @@ namespace FSpot {
 			public Manipulator (GroupSelector selector)
 			{
 				this.selector = selector;
-				timer = new Delay (50, new GLib.IdleHandler (DragTimeout));
+				timer = new DelayedOperation (50, new GLib.IdleHandler (DragTimeout));
 			}
 
 			protected int drag_offset;
@@ -1124,7 +1124,7 @@ namespace FSpot {
 			//left.Clicked += HandleScrollLeft;
 			left.Pressed += HandleLeftPressed;
 			left.ButtonReleaseEvent += HandleScrollReleaseEvent;
-			left_delay = new Delay (50, new GLib.IdleHandler (HandleScrollLeft));
+			left_delay = new DelayedOperation (50, new GLib.IdleHandler (HandleScrollLeft));
 
 			right = new Gtk.Button ();
 			//right.Add (new Gtk.Image (Gtk.Stock.GoForward, Gtk.IconSize.Button));
@@ -1132,7 +1132,7 @@ namespace FSpot {
 			right.Relief = Gtk.ReliefStyle.None;
 			right.Pressed += HandleRightPressed;
 			right.ButtonReleaseEvent += HandleScrollReleaseEvent;
-			right_delay = new Delay (50, new GLib.IdleHandler (HandleScrollRight));
+			right_delay = new DelayedOperation (50, new GLib.IdleHandler (HandleScrollRight));
 			//right.Clicked += HandleScrollRight;
 
 			this.Put (left, 0, 0);
diff --git a/src/Clients/MainApp/FSpot/PhotoView.cs b/src/Clients/MainApp/FSpot/PhotoView.cs
index 1c91377..8557024 100644
--- a/src/Clients/MainApp/FSpot/PhotoView.cs
+++ b/src/Clients/MainApp/FSpot/PhotoView.cs
@@ -26,7 +26,7 @@ using FSpot.UI.Dialog;
 
 namespace FSpot {
 	public class PhotoView : EventBox {
-		Delay commit_delay;
+		DelayedOperation commit_delay;
 
 		private PhotoImageView photo_view;
 		private ScrolledWindow photo_view_scrolled;
@@ -288,7 +288,7 @@ namespace FSpot {
 		{
 			this.query = query;
 
-			commit_delay = new Delay (1000, new GLib.IdleHandler (CommitPendingChanges));
+			commit_delay = new DelayedOperation (1000, new GLib.IdleHandler (CommitPendingChanges));
 			this.Destroyed += HandleDestroy;
 
 			Name = "ImageContainer";
diff --git a/src/Core/FSpot.Core/FSpot.Core.csproj b/src/Core/FSpot.Core/FSpot.Core.csproj
index c7e6e24..f7c385a 100644
--- a/src/Core/FSpot.Core/FSpot.Core.csproj
+++ b/src/Core/FSpot.Core/FSpot.Core.csproj
@@ -28,7 +28,6 @@
     <Compile Include="FSpot.Core\BrowsablePointerChangedEventArgs.cs" />
     <Compile Include="FSpot.Core\Category.cs" />
     <Compile Include="FSpot.Core\DbItem.cs" />
-    <Compile Include="FSpot.Core\Delay.cs" />
     <Compile Include="FSpot.Core\Tag.cs" />
     <Compile Include="FSpot.Core\Global.cs" />
     <Compile Include="FSpot.Core\FileBrowsableItem.cs" />
@@ -90,4 +89,7 @@
       <LogicalName>FSpot.Core.addins</LogicalName>
     </EmbeddedResource>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="FSpot.Core\" />
+  </ItemGroup>
 </Project>
diff --git a/src/Core/FSpot.Core/Makefile.am b/src/Core/FSpot.Core/Makefile.am
index c68f775..5cd5cf0 100644
--- a/src/Core/FSpot.Core/Makefile.am
+++ b/src/Core/FSpot.Core/Makefile.am
@@ -10,7 +10,6 @@ SOURCES =  \
 	FSpot.Core/Category.cs \
 	FSpot.Core/DbItem.cs \
 	FSpot.Core/Defines.cs \
-	FSpot.Core/Delay.cs \
 	FSpot.Core/FileBrowsableItem.cs \
 	FSpot.Core/Global.cs \
 	FSpot.Core/IBrowsableCollection.cs \
diff --git a/src/Core/FSpot.Gui/FSpot.Widgets/ScrolledView.cs b/src/Core/FSpot.Gui/FSpot.Widgets/ScrolledView.cs
index 71c38ea..d7717e0 100644
--- a/src/Core/FSpot.Gui/FSpot.Widgets/ScrolledView.cs
+++ b/src/Core/FSpot.Gui/FSpot.Widgets/ScrolledView.cs
@@ -1,12 +1,12 @@
 using System;
 using Gtk;
-using FSpot.Core;
+using FSpot.Utils;
 
 namespace FSpot.Widgets {
 	public class ScrolledView : Fixed {
 		private EventBox ebox;
 		private ScrolledWindow scroll;
-		private Delay hide;
+		private DelayedOperation hide;
 
 		public ScrolledView (IntPtr raw) : base (raw) {}
 
@@ -20,7 +20,7 @@ namespace FSpot.Widgets {
 			this.Put (ebox, 0, 0);
 			ebox.ShowAll ();
 			
-			hide = new Delay (2000, new GLib.IdleHandler (HideControls));
+			hide = new DelayedOperation (2000, new GLib.IdleHandler (HideControls));
 			this.Destroyed += HandleDestroyed;
 		}
 
diff --git a/src/Core/FSpot.Utils/FSpot.Utils.csproj b/src/Core/FSpot.Utils/FSpot.Utils.csproj
index 4f804f0..23552af 100644
--- a/src/Core/FSpot.Utils/FSpot.Utils.csproj
+++ b/src/Core/FSpot.Utils/FSpot.Utils.csproj
@@ -57,6 +57,7 @@
     <Compile Include="FSpot.Utils\UriList.cs" />
     <Compile Include="FSpot.Utils\Vector.cs" />
     <Compile Include="FSpot.Utils\MemorySurface.cs" />
+    <Compile Include="FSpot.Utils\DelayedOperation.cs" />
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>
diff --git a/src/Core/FSpot.Utils/FSpot.Utils/DelayedOperation.cs b/src/Core/FSpot.Utils/FSpot.Utils/DelayedOperation.cs
new file mode 100644
index 0000000..bc9cc4b
--- /dev/null
+++ b/src/Core/FSpot.Utils/FSpot.Utils/DelayedOperation.cs
@@ -0,0 +1,93 @@
+/*
+ * Delay.cs
+ *
+ * Copyright 2007 Novell Inc.
+ *
+ * Author
+ *   Larry Ewing <lewing novell com>
+ *
+ * See COPYING for license information.
+ *
+ */
+
+using System;
+
+namespace FSpot.Utils
+{
+    public class DelayedOperation
+    {
+        object syncHandle = new object ();
+
+        public DelayedOperation (uint interval, GLib.IdleHandler op)
+        {
+            this.op = op;
+            this.interval = interval;
+        }
+
+        public DelayedOperation (GLib.IdleHandler op)
+        {
+            this.op = op;
+        }
+
+        uint source;
+        uint interval;
+
+        private GLib.IdleHandler op;
+
+        private bool HandleOperation ()
+        {
+            lock (syncHandle) {
+                bool runagain = op ();
+                if (!runagain)
+                    source = 0;
+                
+                return runagain;
+            }
+        }
+
+        public void Start ()
+        {
+            lock (syncHandle) {
+                if (this.IsPending)
+                    return;
+                
+                if (interval != 0)
+                    source = GLib.Timeout.Add (interval, new GLib.TimeoutHandler (HandleOperation));
+                else
+                    source = GLib.Idle.Add (new GLib.IdleHandler (HandleOperation));
+            }
+        }
+
+        public bool IsPending {
+            get { return source != 0; }
+        }
+
+        public void Connect (Gtk.Object obj)
+        {
+            if (obj == null)
+                throw new ArgumentNullException ("obj");
+            obj.Destroyed += HandleDestroy;
+        }
+
+        private void HandleDestroy (object sender, System.EventArgs args)
+        {
+            this.Stop ();
+        }
+
+        public void Stop ()
+        {
+            lock (syncHandle) {
+                if (this.IsPending) {
+                    GLib.Source.Remove (source);
+                    source = 0;
+                }
+            }
+        }
+
+        public void Restart ()
+        {
+            Stop ();
+            Start ();
+        }
+    }
+}
diff --git a/src/Core/FSpot.Utils/Makefile.am b/src/Core/FSpot.Utils/Makefile.am
index 94c50e4..ae5bcaf 100644
--- a/src/Core/FSpot.Utils/Makefile.am
+++ b/src/Core/FSpot.Utils/Makefile.am
@@ -6,6 +6,7 @@ SOURCES =  \
 	FSpot.Utils/Cache.cs \
 	FSpot.Utils/CairoUtils.cs \
 	FSpot.Utils/ConsoleCrayon.cs \
+	FSpot.Utils/DelayedOperation.cs \
 	FSpot.Utils/FileExtensions.cs \
 	FSpot.Utils/GdkUtils.cs \
 	FSpot.Utils/GIOTagLibFileAbstraction.cs \



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