[f-spot/mipmapped-loading: 8/11] Convert Filmstrip to the tasks framework.



commit d11f043aabe679a690b146e4360c8af114c758d5
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sun Jun 20 17:29:42 2010 +0200

    Convert Filmstrip to the tasks framework.

 src/Core/App.cs          |    2 +
 src/Utils/PixbufUtils.cs |    2 +-
 src/Widgets/Filmstrip.cs |   62 ++++++++++++++++++++--------------------------
 3 files changed, 30 insertions(+), 36 deletions(-)
---
diff --git a/src/Core/App.cs b/src/Core/App.cs
index 035d11b..871f147 100644
--- a/src/Core/App.cs
+++ b/src/Core/App.cs
@@ -21,6 +21,7 @@ using Mono.Unix;
 
 using Hyena;
 
+using FSpot.Tasks;
 using FSpot.Loaders;
 
 namespace FSpot
@@ -366,6 +367,7 @@ namespace FSpot
 				Banshee.Kernel.Scheduler.Dispose ();
 				Database.Dispose ();
 				ImageLoaderThread.CleanAll ();
+				WorkerThreadTaskScheduler.Instance.Finish ();
 				Gtk.Application.Quit ();
 				System.Environment.Exit (0);
 			}
diff --git a/src/Utils/PixbufUtils.cs b/src/Utils/PixbufUtils.cs
index ad611ef..54f6b6b 100644
--- a/src/Utils/PixbufUtils.cs
+++ b/src/Utils/PixbufUtils.cs
@@ -190,7 +190,7 @@ namespace FSpot.Utils
 			return dest;
 		}
 
-		public static Pixbuf ShallowCopy (Pixbuf pixbuf)
+		public static Pixbuf ShallowCopy (this Pixbuf pixbuf)
 		{
 			if (pixbuf == null)
 				return null;
diff --git a/src/Widgets/Filmstrip.cs b/src/Widgets/Filmstrip.cs
index dbe6c0b..46448d1 100644
--- a/src/Widgets/Filmstrip.cs
+++ b/src/Widgets/Filmstrip.cs
@@ -20,6 +20,7 @@ using Gdk;
 using FSpot.Utils;
 using FSpot.Platform;
 using FSpot.Bling;
+using FSpot.Tasks;
 using Hyena;
 
 namespace FSpot.Widgets
@@ -307,7 +308,6 @@ namespace FSpot.Widgets
 			this.selection.Collection.ItemsChanged += HandleCollectionItemsChanged;
 			this.squared_thumbs = squared_thumbs;
 			thumb_cache = new DisposableCache<SafeUri, Pixbuf> (30);
-			ThumbnailLoader.Default.OnPixbufLoaded += HandlePixbufLoaded;
 
 			animation = new DoubleAnimation (0, 0, TimeSpan.FromSeconds (1.5), SetPositionCore, new CubicEase (EasingMode.EaseOut));
 		}
@@ -548,18 +548,6 @@ namespace FSpot.Widgets
 			QueueDraw ();
 		}
 
-		void HandlePixbufLoaded (ImageLoaderThread pl, ImageLoaderThread.RequestItem item) {
-			if (!thumb_cache.Contains (item.Uri)) {
-				return;
-			}
-			
-			//FIXME use QueueDrawArea
-			//FIXME only invalidate if displayed
-			QueueDraw ();
-			
-
-		}
-		
 		protected override bool OnPopupMenu ()
 		{
 			DrawOrientationMenu (null);
@@ -610,32 +598,37 @@ namespace FSpot.Widgets
 			return GetPixbuf (i, false);
 		}
 
- 		protected virtual Pixbuf GetPixbuf (int i, bool highlighted)
+		protected virtual Pixbuf GetPixbuf (int i, bool highlighted)
 		{
-			Pixbuf current;
+			Pixbuf current = null;
 			SafeUri uri = (selection.Collection [i]).DefaultVersion.Uri;
-			try {
-				current = PixbufUtils.ShallowCopy (thumb_cache.Get (uri));
-			} catch (IndexOutOfRangeException) {
-				current = null;
-			}
+			if (!thumb_cache.Contains (uri)) {
+				current = FSpot.Global.IconTheme.LoadIcon ("gtk-missing-image", ThumbSize, (Gtk.IconLookupFlags)0);
 
-			if (current == null) {
-                var pixbuf = XdgThumbnailSpec.LoadThumbnail (uri, ThumbnailSize.Large, null);
-                if (pixbuf == null) {
-					ThumbnailLoader.Default.Request (uri, ThumbnailSize.Large, 0);
-                    current = FSpot.Global.IconTheme.LoadIcon ("gtk-missing-image", ThumbSize, (Gtk.IconLookupFlags)0);
-                } else {
+				var loader = App.Instance.Loaders.RequestLoader ((selection.Collection [i]).DefaultVersion);
+				var preview_task = loader.FindBestPreview (ThumbSize, ThumbSize);
+				var task = new WorkerThreadTask<bool> (() => {
+					Pixbuf pixbuf = preview_task.Result;
 					if (SquaredThumbs) {
-                        current = PixbufUtils.IconFromPixbuf (pixbuf, ThumbSize);
-                    } else {
-                        current = pixbuf.ScaleSimple (ThumbSize, ThumbSize, InterpType.Nearest);
-                    }
-                    pixbuf.Dispose ();
-					thumb_cache.Add (uri, current);
-                }
+					current = PixbufUtils.IconFromPixbuf (pixbuf, ThumbSize);
+					} else {
+					current = pixbuf.ScaleSimple (ThumbSize, ThumbSize, InterpType.Bilinear);
+					}
+					pixbuf.Dispose ();
+
+					ThreadAssist.ProxyToMain (() => {
+						thumb_cache.Add (uri, current);
+						QueueDraw ();
+						});
+					return false;
+				}) {
+					Priority = TaskPriority.Interactive
+				};
+				preview_task.ContinueWith (task);
+			} else {
+				current = thumb_cache.Get (uri).ShallowCopy ();
 			}
-			
+
 			//FIXME: we might end up leaking a pixbuf here
 			Cms.Profile screen_profile;
 			if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile)) { 
@@ -689,7 +682,6 @@ namespace FSpot.Widgets
 				this.selection.Changed -= HandlePointerChanged;
 				this.selection.Collection.Changed -= HandleCollectionChanged;
 				this.selection.Collection.ItemsChanged -= HandleCollectionItemsChanged;
-				ThumbnailLoader.Default.OnPixbufLoaded -= HandlePixbufLoaded;
 				if (background_pixbuf != null)
 					background_pixbuf.Dispose ();
 				if (background_tile != null)



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