[f-spot/rubenv-gsoc-2009: 41/86] Correctly signal errors with null and load through ImageLoader.



commit 93a5c9b7941f8470bf7624cefb34a6cde6f212e1
Author: Ruben Vermeersch <ruben savanne be>
Date:   Thu Jul 30 13:17:27 2009 +0200

    Correctly signal errors with null and load through ImageLoader.

 src/FileImportBackend.cs                         |    2 +-
 src/ImageLoaderThread.cs                         |   49 +++-------
 src/Loaders/GdkImageLoader.cs                    |   24 ++---
 src/Loaders/ImageLoaderItemExtensions.cs         |   16 +++
 src/Loaders/LibrawImageLoader.cs                 |   13 ++-
 src/MainWindow.cs                                |    2 +-
 src/Makefile.am                                  |    2 +-
 src/PhotoLoader.cs                               |    3 +-
 src/ThumbnailGenerator.cs                        |    8 ++
 src/Widgets/Filmstrip.cs                         |    3 +-
 src/Widgets/IconView.cs                          |   19 ++--
 src/{PixbufCache.cs => Widgets/IconViewCache.cs} |  107 ++++++++++------------
 12 files changed, 122 insertions(+), 126 deletions(-)
---
diff --git a/src/FileImportBackend.cs b/src/FileImportBackend.cs
index e06c010..831622a 100644
--- a/src/FileImportBackend.cs
+++ b/src/FileImportBackend.cs
@@ -316,7 +316,7 @@ public class FileImportBackend : ImportBackend {
 
 		foreach (ImportInfo info in import_info) {
 			if (info.PhotoId != 0) 
-				FSpot.ThumbnailGenerator.Default.Request (store.Get (info.PhotoId).DefaultVersion.Uri, 0, 256, 256);
+				FSpot.ThumbnailGenerator.Default.Request (store.Get (info.PhotoId).DefaultVersion.Uri, 0, ImageLoaderItem.Thumbnail);
 		}
 
 		import_info = null;
diff --git a/src/ImageLoaderThread.cs b/src/ImageLoaderThread.cs
index 148c7da..4f667b2 100644
--- a/src/ImageLoaderThread.cs
+++ b/src/ImageLoaderThread.cs
@@ -4,6 +4,7 @@
  * Author(s):
  *	Ettore Perazzoli <ettore perazzoli org>
  *	Larry Ewing <lewing novell com>
+ *	Ruben Vermeersch <ruben savanne be>
  *
  * This is free software. See COPYING for details
  */
@@ -15,6 +16,7 @@ using System.Threading;
 using System;
 
 using FSpot.Utils;
+using FSpot.Loaders;
 
 public class ImageLoaderThread {
 
@@ -29,17 +31,16 @@ public class ImageLoaderThread {
 
 		/* The pixbuf obtained from the operation.  */
 		public Pixbuf result;
+		public PixbufOrientation result_orientation;
 
-		/* the maximium size both must be greater than zero if either is */
-		public int width;
-		public int height;
+		/* The requested item. */
+		public ImageLoaderItem item;
 
-		public RequestItem (Uri uri, int order, int width, int height) {
+		public RequestItem (Uri uri, int order, ImageLoaderItem item) {
 			this.uri = uri;
 			this.order = order;
-			this.width = width;
-			this.height = height;
-			if ((width <= 0 && height > 0) || (height <= 0 && width > 0))
+			this.item = item;
+			if (item.Multiple ())
 				throw new System.Exception ("Invalid arguments");
 		}
 	}
@@ -119,15 +120,10 @@ public class ImageLoaderThread {
 			t.Abort ();
 	}
 
-	public void Request (Uri uri, int order)
-	{
-		Request (uri, order, 0, 0);
-	}
-
-	public virtual void Request (Uri uri, int order, int width, int height)
+	public virtual void Request (Uri uri, int order, ImageLoaderItem item)
 	{
 		lock (queue) {
-			if (InsertRequest (uri, order, width, height))
+			if (InsertRequest (uri, order, item))
 				Monitor.Pulse (queue);
 		}
 	}
@@ -147,30 +143,17 @@ public class ImageLoaderThread {
 
 	protected virtual void ProcessRequest (RequestItem request)
 	{
-		Pixbuf orig_image;
-		try {
-			using (FSpot.ImageFile img = FSpot.ImageFile.Create (request.uri)) {
-				if (request.width > 0) {
-					orig_image = img.Load (request.width, request.height);
-				} else {
-					orig_image = img.Load ();
-				}
-			}
-		} catch (GLib.GException e){
-			System.Console.WriteLine (e.ToString ());
-			return;		
+		using (IImageLoader loader = ImageLoader.Create (request.uri)) {
+			loader.Load (request.item);
+			request.result = loader.Pixbuf (request.item);
+			request.result_orientation = loader.PixbufOrientation (request.item);
 		}
-		
-		if (orig_image == null)
-			return;
-		
-		request.result = orig_image;
 	}
 
 	/* Insert the request in the queue, return TRUE if the queue actually grew.
 	   NOTE: Lock the queue before calling.  */
 
-	private bool InsertRequest (Uri uri, int order, int width, int height)
+	private bool InsertRequest (Uri uri, int order, ImageLoaderItem item)
 	{
 		/* Check if this is the same as the request currently being processed.  */
 		lock(processed_requests) {
@@ -191,7 +174,7 @@ public class ImageLoaderThread {
 		}
 
 		/* New request, just put it on the queue with the right order.  */
-		RequestItem new_request = new RequestItem (uri, order, width, height);
+		RequestItem new_request = new RequestItem (uri, order, item);
 
 		queue.Add (new_request);
 
diff --git a/src/Loaders/GdkImageLoader.cs b/src/Loaders/GdkImageLoader.cs
index 2cf01b7..7110a8f 100644
--- a/src/Loaders/GdkImageLoader.cs
+++ b/src/Loaders/GdkImageLoader.cs
@@ -28,14 +28,13 @@ namespace FSpot.Loaders {
 
 		Pixbuf thumbnail;
 		public Pixbuf Thumbnail {
-			get { return thumbnail.ShallowCopy (); }
+			get { return thumbnail == null ? null : thumbnail.ShallowCopy (); }
 			private set { thumbnail = value; }
 		}
 		public PixbufOrientation ThumbnailOrientation { get; private set; }
 
-		Pixbuf error = null;
 		public Pixbuf Large {
-			get { return error == null ? Pixbuf.ShallowCopy () : error.ShallowCopy (); }
+			get { return Pixbuf == null ? null : Pixbuf.ShallowCopy (); }
 		}
 		public PixbufOrientation LargeOrientation { get; private set; }
 
@@ -88,10 +87,6 @@ namespace FSpot.Loaders {
 				thumbnail.Dispose ();
 				thumbnail = null;
 			}
-			if (error != null) {
-				error.Dispose ();
-				error = null;
-			}
 			base.Dispose ();
 		}
 
@@ -187,8 +182,9 @@ namespace FSpot.Loaders {
 			// for the next call to generate it (see the loop in DoLoad).
 			if (!ThumbnailFactory.ThumbnailExists (uri)) {
 				if (ItemsCompleted.Contains (ImageLoaderItem.Large)) {
-					using (Pixbuf scaled = PixbufUtils.ScaleToMaxSize (Pixbuf, 256, 256, false))
-						ThumbnailFactory.SaveThumbnail (scaled, uri);
+					if (Pixbuf != null)
+						using (Pixbuf scaled = PixbufUtils.ScaleToMaxSize (Pixbuf, 256, 256, false))
+							ThumbnailFactory.SaveThumbnail (scaled, uri);
 				} else {
 					ItemsRequested |= ImageLoaderItem.Large;
 					return;
@@ -197,11 +193,11 @@ namespace FSpot.Loaders {
 
 			Thumbnail = ThumbnailFactory.LoadThumbnail (uri);
 			ThumbnailOrientation = PixbufOrientation.TopLeft;
-			if (Thumbnail == null)
-				throw new Exception ("Null thumbnail returned");
 
-			SignalAreaPrepared (ImageLoaderItem.Thumbnail);
-			SignalAreaUpdated (ImageLoaderItem.Thumbnail, new Rectangle (0, 0, thumbnail.Width, thumbnail.Height));
+			if (thumbnail != null) {
+				SignalAreaPrepared (ImageLoaderItem.Thumbnail);
+				SignalAreaUpdated (ImageLoaderItem.Thumbnail, new Rectangle (0, 0, thumbnail.Width, thumbnail.Height));
+			}
 			SignalItemCompleted (ImageLoaderItem.Thumbnail);
 		}
 
@@ -216,8 +212,6 @@ namespace FSpot.Loaders {
 					LargeOrientation = image_file.Orientation;
 				}
 			} catch (GLib.GException) {
-				error = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot-question-mark", 256, (Gtk.IconLookupFlags)0);
-				LargeOrientation = PixbufOrientation.TopLeft;
 				SignalItemCompleted (ImageLoaderItem.Large | ImageLoaderItem.Full);
 				return;
 			}
diff --git a/src/Loaders/ImageLoaderItemExtensions.cs b/src/Loaders/ImageLoaderItemExtensions.cs
index 860684c..f888d3c 100644
--- a/src/Loaders/ImageLoaderItemExtensions.cs
+++ b/src/Loaders/ImageLoaderItemExtensions.cs
@@ -26,5 +26,21 @@ namespace FSpot.Loaders {
 				return ImageLoaderItem.Thumbnail;
 			return ImageLoaderItem.None;
 		}
+
+		public static ImageLoaderItem Smallest (this ImageLoaderItem items)
+		{
+			if (items.Contains (ImageLoaderItem.Thumbnail))
+				return ImageLoaderItem.Thumbnail;
+			if (items.Contains (ImageLoaderItem.Large))
+				return ImageLoaderItem.Large;
+			if (items.Contains (ImageLoaderItem.Full))
+				return ImageLoaderItem.Full;
+			return ImageLoaderItem.None;
+		}
+
+		public static bool Multiple (this ImageLoaderItem item)
+		{
+			return item.Largest () != item.Smallest ();
+		}
 	}
 }
diff --git a/src/Loaders/LibrawImageLoader.cs b/src/Loaders/LibrawImageLoader.cs
index 7a82137..99d2fdd 100644
--- a/src/Loaders/LibrawImageLoader.cs
+++ b/src/Loaders/LibrawImageLoader.cs
@@ -153,8 +153,9 @@ namespace FSpot.Loaders {
 			// for the next call to generate it (see the loop in DoLoad).
 			if (!ThumbnailFactory.ThumbnailExists (uri)) {
 				if (ItemsCompleted.Contains (ImageLoaderItem.Large)) {
-					using (Pixbuf scaled = PixbufUtils.ScaleToMaxSize (large, 256, 256, false))
-						ThumbnailFactory.SaveThumbnail (scaled, uri);
+					if (large != null)
+						using (Pixbuf scaled = PixbufUtils.ScaleToMaxSize (large, 256, 256, false))
+							ThumbnailFactory.SaveThumbnail (scaled, uri);
 				} else {
 					ItemsRequested |= ImageLoaderItem.Large;
 					return;
@@ -163,11 +164,11 @@ namespace FSpot.Loaders {
 
 			Thumbnail = ThumbnailFactory.LoadThumbnail (uri);
 			ThumbnailOrientation = PixbufOrientation.TopLeft;
-			if (Thumbnail == null)
-				throw new Exception ("Null thumbnail returned");
 
-			SignalAreaPrepared (ImageLoaderItem.Thumbnail);
-			SignalAreaUpdated (ImageLoaderItem.Thumbnail, new Rectangle (0, 0, Thumbnail.Width, Thumbnail.Height));
+			if (thumbnail != null) {
+				SignalAreaPrepared (ImageLoaderItem.Thumbnail);
+				SignalAreaUpdated (ImageLoaderItem.Thumbnail, new Rectangle (0, 0, thumbnail.Width, thumbnail.Height));
+			}
 			SignalItemCompleted (ImageLoaderItem.Thumbnail);
 		}
 
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index af253a1..3e30e8b 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -1080,7 +1080,7 @@ namespace FSpot
 	
 				bool use_icon = false;;
 				while (len-- > 0) {
-					FSpot.PixbufCache.CacheEntry entry = icon_view.Cache.Lookup (photos [len].DefaultVersion.Uri);
+					IconViewCache.CacheEntry entry = icon_view.Cache.Lookup (photos [len].DefaultVersion.Uri);
 	
 					Pixbuf thumbnail = null;
 					if (entry != null) {
diff --git a/src/Makefile.am b/src/Makefile.am
index 13d18c2..c3148c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -250,7 +250,6 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/PhotoVersionCommands.cs	\
 	$(srcdir)/PhotoVersionMenu.cs		\
 	$(srcdir)/PhotoView.cs			\
-	$(srcdir)/PixbufCache.cs		\
 	$(srcdir)/PixbufUtils.cs		\
 	$(srcdir)/Preferences.cs 		\
 	$(srcdir)/PrintOperation.cs		\
@@ -315,6 +314,7 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Widgets/IEffect.cs		\
 	$(srcdir)/Widgets/ITransition.cs	\
 	$(srcdir)/Widgets/IconView.cs		\
+	$(srcdir)/Widgets/IconViewCache.cs		\
 	$(srcdir)/Widgets/ImageDisplay.cs	\
 	$(srcdir)/Widgets/ImageInfo.cs		\
 	$(srcdir)/Widgets/InfoBox.cs		\
diff --git a/src/PhotoLoader.cs b/src/PhotoLoader.cs
index 82b5156..31c4a88 100644
--- a/src/PhotoLoader.cs
+++ b/src/PhotoLoader.cs
@@ -1,6 +1,7 @@
 using System;
 
 using FSpot.Platform;
+using FSpot.Loaders;
 using FSpot.Utils;
 
 namespace FSpot {
@@ -46,7 +47,7 @@ namespace FSpot {
 			using (Gdk.Pixbuf thumbnail = ThumbnailCache.Default.GetThumbnailForUri (uri)) {
 				if (pixbuf != null && thumbnail != null && !ThumbnailFactory.ThumbnailIsValid (thumbnail, uri)) {
 					Log.Debug ("regenerating thumbnail for {0}", uri);
-					FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
+					FSpot.ThumbnailGenerator.Default.Request (uri, 0, ImageLoaderItem.Thumbnail);
 				}
 			}
 			return pixbuf;
diff --git a/src/ThumbnailGenerator.cs b/src/ThumbnailGenerator.cs
index c0a5ce1..385e3f1 100644
--- a/src/ThumbnailGenerator.cs
+++ b/src/ThumbnailGenerator.cs
@@ -80,6 +80,14 @@ namespace FSpot {
 				
 		}
 
+		public override void Request (Uri uri, int order, ImageLoaderItem item)
+		{
+			if (ThumbnailFactory.ThumbnailExists (uri) && ThumbnailFactory.ThumbnailIsRecent (uri))
+				return;
+
+			base.Request (uri, order, item);
+		}
+
 		protected override void ProcessRequest (RequestItem request)
 		{
 			try {
diff --git a/src/Widgets/Filmstrip.cs b/src/Widgets/Filmstrip.cs
index b2cbe00..1125c3b 100644
--- a/src/Widgets/Filmstrip.cs
+++ b/src/Widgets/Filmstrip.cs
@@ -19,6 +19,7 @@ using Gdk;
 
 using FSpot.Utils;
 using FSpot.Platform;
+using FSpot.Loaders;
 using FSpot.Bling;
 
 namespace FSpot.Widgets
@@ -622,7 +623,7 @@ namespace FSpot.Widgets
 
 			if (current == null) {
 				try {
-					ThumbnailGenerator.Default.Request ((selection.Collection [i]).DefaultVersion.Uri, 0, 256, 256);
+					ThumbnailGenerator.Default.Request ((selection.Collection [i]).DefaultVersion.Uri, 0, ImageLoaderItem.Thumbnail);
 
 					if (SquaredThumbs) {
 						using (Pixbuf p = ThumbnailFactory.LoadThumbnail (uri)) {
diff --git a/src/Widgets/IconView.cs b/src/Widgets/IconView.cs
index 679e607..fea466c 100644
--- a/src/Widgets/IconView.cs
+++ b/src/Widgets/IconView.cs
@@ -17,6 +17,7 @@ using System.Collections;
 using System.IO;
 using FSpot.Platform;
 using FSpot.Utils;
+using FSpot.Loaders;
 
 namespace FSpot.Widgets
 {
@@ -33,7 +34,7 @@ namespace FSpot.Widgets
 	public class IconView : Gtk.Layout {
 
 		// Public properties.
-		FSpot.PixbufCache cache;
+		IconViewCache cache;
 
 		/* preserve the scroll postion when possible */
 		private bool scroll;
@@ -93,7 +94,7 @@ namespace FSpot.Widgets
 			}
 		}
 
-		public FSpot.PixbufCache Cache {
+		public IconViewCache Cache {
 			get {
 				return cache;
 			}
@@ -220,7 +221,7 @@ namespace FSpot.Widgets
 
 		protected IconView () : base (null, null)
 		{
-			cache = new FSpot.PixbufCache ();
+			cache = new IconViewCache ();
 			cache.OnPixbufLoaded += HandlePixbufLoaded;
 
 			ScrollAdjustmentsSet += new ScrollAdjustmentsSetHandler (HandleScrollAdjustmentsSet);
@@ -856,7 +857,7 @@ namespace FSpot.Widgets
 
 			FSpot.IBrowsableItem photo = collection [thumbnail_num];
 
-			FSpot.PixbufCache.CacheEntry entry = cache.Lookup (photo.DefaultVersion.Uri);
+			IconViewCache.CacheEntry entry = cache.Lookup (photo.DefaultVersion.Uri);
 			if (entry == null)
 				cache.Request (photo.DefaultVersion.Uri, thumbnail_num, ThumbnailWidth, ThumbnailHeight);
 			else
@@ -900,7 +901,7 @@ namespace FSpot.Widgets
 
 				if (Math.Abs (region.Width - thumbnail.Width) > 1
 					&& Math.Abs (region.Height - thumbnail.Height) > 1)
-				cache.Reload (entry, thumbnail_num, thumbnail.Width, thumbnail.Height);
+				cache.Reload (entry, thumbnail_num, ThumbnailWidth, ThumbnailHeight);
 
 				region = Gdk.Rectangle.Inflate (region, expansion, expansion);
 				Pixbuf temp_thumbnail;
@@ -1270,7 +1271,7 @@ namespace FSpot.Widgets
 			int i;
 
 			FSpot.IBrowsableItem photo;
-			FSpot.PixbufCache.CacheEntry entry;
+			IconViewCache.CacheEntry entry;
 
 			// Preload the cache with images aroud the expose area
 			// FIXME the preload need to be tuned to the Cache size but this is a resonable start
@@ -1388,7 +1389,7 @@ namespace FSpot.Widgets
 			Scroll ();
 		}
 
-		private void HandlePixbufLoaded (FSpot.PixbufCache cache, FSpot.PixbufCache.CacheEntry entry)
+		private void HandlePixbufLoaded (IconViewCache cache, IconViewCache.CacheEntry entry)
 		{
 			Gdk.Pixbuf result = entry.ShallowCopyPixbuf ();
 			int order = (int) entry.Data;
@@ -1397,13 +1398,13 @@ namespace FSpot.Widgets
 				System.Uri uri = collection [order].DefaultVersion.Uri;
 
 				if (result == null && !ThumbnailFactory.ThumbnailExists (uri))
-					FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
+					FSpot.ThumbnailGenerator.Default.Request (uri, 0, ImageLoaderItem.Thumbnail);
 
 				if (result == null)
 					return;
 
 				if (!ThumbnailFactory.ThumbnailIsValid (result, uri))
-					FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
+					FSpot.ThumbnailGenerator.Default.Request (uri, 0, ImageLoaderItem.Thumbnail);
 			}
 
 			if (result == null)
diff --git a/src/PixbufCache.cs b/src/Widgets/IconViewCache.cs
similarity index 85%
rename from src/PixbufCache.cs
rename to src/Widgets/IconViewCache.cs
index 99ec5cc..cb247fe 100644
--- a/src/PixbufCache.cs
+++ b/src/Widgets/IconViewCache.cs
@@ -1,5 +1,5 @@
 /*
- * FSpot.PixbufCache.cs
+ * FSpot.Widgets.IconViewCache.cs
  *
  * Author(s):
  * 	Larry Ewing <lewing novell com>
@@ -13,9 +13,10 @@ using System.Threading;
 
 using FSpot.Utils;
 using FSpot.Platform;
+using FSpot.Loaders;
 
-namespace FSpot {
-	public class PixbufCache {
+namespace FSpot.Widgets {
+	public class IconViewCache {
 		Hashtable items;
 		ArrayList items_mru;
 		int total_size;
@@ -23,33 +24,33 @@ namespace FSpot {
 
 		private Thread worker;
 
-		public delegate void PixbufLoadedHandler (PixbufCache cache, CacheEntry entry);
+		public delegate void PixbufLoadedHandler (IconViewCache cache, CacheEntry entry);
 		public event PixbufLoadedHandler OnPixbufLoaded;
-		
-		public PixbufCache ()
+
+		public IconViewCache ()
 		{
 			items = new Hashtable ();
 			items_mru = new ArrayList ();
-			
+
 			worker = new Thread (new ThreadStart (WorkerTask));
 			worker.Start ();
 
 			ThumbnailGenerator.Default.OnPixbufLoaded += HandleThumbnailLoaded;
 		}
-		
+
 		public void HandleThumbnailLoaded (ImageLoaderThread loader, Uri uri, int order, Gdk.Pixbuf result)
 		{
 			if (result != null)
 				Reload (uri);
 		}
 
-		public void Request (Uri uri, object closure, int width, int height)
+		public void Request (Uri uri, object closure, int max_width, int max_height)
 		{
 			lock (items) {
 				CacheEntry entry = items[uri] as CacheEntry;
 
 				if (entry == null) {
-					entry = new CacheEntry (this, uri, closure, width, height);
+					entry = new CacheEntry (this, uri, closure, max_width, max_height);
 					items [uri] = entry;
 					items_mru.Add (entry);
 				} else {
@@ -76,14 +77,14 @@ namespace FSpot {
 				entry.SetPixbufExtended (pixbuf, true);
 			}
 		}
-		
-		public void Reload (CacheEntry entry, object data, int width, int height)
+
+		public void Reload (CacheEntry entry, object data, int max_width, int max_height)
 		{
 			lock (items) {
 				lock (entry) {
 					entry.Reload = true;
-					entry.Width = width;
-					entry.Height = height;
+					entry.MaxWidth = max_width;
+					entry.MaxHeight = max_height;
 					entry.Data = data;
 				}
 				Monitor.Pulse (items);
@@ -114,7 +115,7 @@ namespace FSpot {
 				//System.Console.WriteLine ("Hit major limit ({0}) out of {1}",
 				//			  total_size, max_size);
 				return null;
-			} 
+			}
 			while (i-- > 0) {
 				entry = (CacheEntry) items_mru [i];
 				lock (entry) {
@@ -123,13 +124,13 @@ namespace FSpot {
 						return entry;
 					}
 
-					//if the depth of the queue is so large that we've reached double our limit 
+					//if the depth of the queue is so large that we've reached double our limit
 					//break out of here and let the queue shrink.
 					if (entry.Pixbuf != null)
 						size += entry.Size;
 
 					if (size > max_size * 2) {
-						//System.Console.WriteLine ("Hit limit ({0},{1}) out of {2}", 
+						//System.Console.WriteLine ("Hit limit ({0},{1}) out of {2}",
 						//			  size, total_size,max_size);
 						return null;
 					}
@@ -137,7 +138,7 @@ namespace FSpot {
 			}
 			return null;
 		}
-		
+
 		private bool ShrinkIfNeeded ()
 		{
 			int num = 0;
@@ -147,14 +148,14 @@ namespace FSpot {
 				entry.Dispose ();
 			}
 			if (num > 0) {
-				//System.Console.WriteLine ("removing {0} out of {3}  ({1} > {2})", 
+				//System.Console.WriteLine ("removing {0} out of {3}  ({1} > {2})",
 				//			  num, total_size, max_size, items_mru.Count);
 				items_mru.RemoveRange (0, num);
 				return true;
 			}
 			return false;
 		}
-		
+
 		private void WorkerTask ()
 		{
 			CacheEntry current = null;
@@ -179,20 +180,23 @@ namespace FSpot {
 				}
 			}
 		}
-		
+
 		protected virtual void ProcessRequest (CacheEntry entry)
 		{
 			Gdk.Pixbuf loaded = null;
 			try {
-				loaded = ThumbnailFactory.LoadThumbnail (entry.Uri);
+				using (IImageLoader loader = ImageLoader.Create (entry.Uri)) {
+					loader.Load (ImageLoaderItem.Thumbnail);
+					loaded = loader.Thumbnail;
+				}
 				this.Update (entry, loaded);
 			} catch (GLib.GException){
 				if (loaded != null)
 					loaded.Dispose ();
-				return;		
+				return;
 			}
 		}
-		
+
 		private void QueueLast (CacheEntry entry)
 		{
 			Gtk.Application.Invoke (delegate (object obj, System.EventArgs args) {
@@ -200,7 +204,7 @@ namespace FSpot {
 					OnPixbufLoaded (this, entry);
 			});
 		}
-		
+
 		private void MoveForward (CacheEntry entry)
 		{
 #if true
@@ -217,10 +221,10 @@ namespace FSpot {
 			throw new System.Exception ("move forward failed");
 #else
 			items_mru.Remove (entry);
-			items_mru.Add (entry);	
+			items_mru.Add (entry);
 #endif
 		}
-		       
+
 
 		private CacheEntry ULookup (Uri uri)
 		{
@@ -258,17 +262,15 @@ namespace FSpot {
 		public class CacheEntry : System.IDisposable {
 			private Gdk.Pixbuf pixbuf;
 			private Uri uri;
-			private int width;
-			private int height;
 			private object data;
 			private bool reload;
-			private PixbufCache cache;
-			
-			public CacheEntry (PixbufCache cache, Uri uri, object closure, int width, int height)
+			private IconViewCache cache;
+
+			public CacheEntry (IconViewCache cache, Uri uri, object closure, int max_width, int max_height)
 			{
 				this.uri = uri;
-				this.width = width;
-				this.height = height;
+				this.MaxHeight = max_height;
+				this.MaxWidth = max_width;
 				this.data = closure;
 				this.Reload = true;
 				this.cache = cache;
@@ -284,15 +286,8 @@ namespace FSpot {
 				get { return uri; }
 			}
 
-			public int Width {
-				get { return width; }
-				set { width = value; }
-			}
-
-			public int Height {
-				get { return height; }
-				set { height = value; }
-			}
+			public int MaxHeight { get; set; }
+			public int MaxWidth { get; set; }
 
 			public object Data {
 				get {
@@ -306,11 +301,11 @@ namespace FSpot {
 					}
 				}
 			}
-			
+
 			public bool IsDisposed {
 				get { return uri == null; }
 			}
-			
+
 			public void SetPixbufExtended (Gdk.Pixbuf value, bool ignore_undead)
 			{
 				lock (this) {
@@ -320,18 +315,14 @@ namespace FSpot {
 						} else {
 							throw new System.Exception ("I don't want to be undead");
 						}
-					}							
+					}
 
 					Gdk.Pixbuf old = this.Pixbuf;
 					cache.total_size -= this.Size;
 					this.pixbuf = value;
-					if (pixbuf != null) {
-						this.width = pixbuf.Width;
-						this.height = pixbuf.Height;
-					}
 					cache.total_size += this.Size;
 					this.Reload = false;
-					
+
 					if (old != null)
 						old.Dispose ();
 				}
@@ -344,7 +335,7 @@ namespace FSpot {
 					}
 				}
 			}
-			
+
 			public Gdk.Pixbuf ShallowCopyPixbuf ()
 			{
 				lock (this) {
@@ -353,17 +344,17 @@ namespace FSpot {
 
 					if (pixbuf == null)
 						return null;
-					
+
 					return pixbuf.ShallowCopy ();
 				}
 			}
-			
+
 			~CacheEntry ()
 			{
 				if (!IsDisposed)
 					this.Dispose ();
 			}
-			
+
 			public void Dispose ()
 			{
 				lock (this) {
@@ -372,7 +363,7 @@ namespace FSpot {
 
 					if (this.pixbuf != null) {
 						this.pixbuf.Dispose ();
-						
+
 					}
 					this.pixbuf = null;
 					this.cache = null;
@@ -380,10 +371,10 @@ namespace FSpot {
 				}
 				System.GC.SuppressFinalize (this);
 			}
-			
+
 			public int Size {
 				get {
-					return width * height * 3;
+					return pixbuf == null ? 0 : pixbuf.Width * pixbuf.Height * 3;
 				}
 			}
 		}



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