[f-spot/mipmapped-loading: 3/12] Start adding a simple task-based photo loader.



commit 10f49adf94fb528992e95f0c37519c9f3b79aed0
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sun Jun 20 01:46:37 2010 +0200

    Start adding a simple task-based photo loader.

 src/Core/App.cs                   |   13 +++++++++++++
 src/Core/IBrowsableItemVersion.cs |    5 +----
 src/Core/ILoadable.cs             |    9 +++++++++
 src/Core/Makefile.am              |    1 +
 src/Loaders/IPhotoLoader.cs       |   15 +++++++++++++++
 src/Loaders/PhotoLoaderCache.cs   |   28 ++++++++++++++++++++++++++++
 src/Loaders/XdgThumbnailLoader.cs |   29 +++++++++++++++++++++++++++++
 src/Makefile.am                   |    3 +++
 8 files changed, 99 insertions(+), 4 deletions(-)
---
diff --git a/src/Core/App.cs b/src/Core/App.cs
index 93318f4..035d11b 100644
--- a/src/Core/App.cs
+++ b/src/Core/App.cs
@@ -21,6 +21,8 @@ using Mono.Unix;
 
 using Hyena;
 
+using FSpot.Loaders;
+
 namespace FSpot
 {
 	public class App : Unique.App
@@ -79,6 +81,16 @@ namespace FSpot
 			}
 		}
 
+		public PhotoLoaderCache Loaders {
+			get {
+				lock (sync_handle) {
+					if (loader_cache == null)
+						loader_cache = new PhotoLoaderCache ();
+				}
+				return loader_cache;
+			}
+		}
+
 		public void Import (string path)
 		{
 			if (IsRunning) {
@@ -162,6 +174,7 @@ namespace FSpot
 		List<Gtk.Window> toplevels;
 		MainWindow organizer;
 		Db db;
+		PhotoLoaderCache loader_cache;
 
 		App (): base ("org.gnome.FSpot.Core", null,
 				  "Import", Command.Import,
diff --git a/src/Core/IBrowsableItemVersion.cs b/src/Core/IBrowsableItemVersion.cs
index 345172a..eec8682 100644
--- a/src/Core/IBrowsableItemVersion.cs
+++ b/src/Core/IBrowsableItemVersion.cs
@@ -2,15 +2,12 @@ using Hyena;
 
 namespace FSpot
 {
-    public interface IBrowsableItemVersion {
+    public interface IBrowsableItemVersion : ILoadable {
         string Name { get; }
         bool IsProtected { get; }
         SafeUri BaseUri { get; }
         string Filename { get; }
 
-        // For convenience
-        SafeUri Uri { get; set; }
-
 		string ImportMD5 { get; }
     }
 }
diff --git a/src/Core/ILoadable.cs b/src/Core/ILoadable.cs
new file mode 100644
index 0000000..aa1ef74
--- /dev/null
+++ b/src/Core/ILoadable.cs
@@ -0,0 +1,9 @@
+using Hyena;
+
+namespace FSpot
+{
+	public interface ILoadable
+	{
+		SafeUri Uri { get; set; }
+	}
+}
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 1409421..49b7583 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -19,6 +19,7 @@ SOURCES = \
 	IBrowsableItemVersion.cs \
 	IBrowsableItemVersionable.cs \
 	IBrowsableCollection.cs \
+	ILoadable.cs \
 	PhotoChanges.cs \
 	PhotosChanges.cs \
 	Roll.cs \
diff --git a/src/Loaders/IPhotoLoader.cs b/src/Loaders/IPhotoLoader.cs
new file mode 100644
index 0000000..f6d6bd7
--- /dev/null
+++ b/src/Loaders/IPhotoLoader.cs
@@ -0,0 +1,15 @@
+using Gdk;
+using FSpot.Tasks;
+
+namespace FSpot.Loaders
+{
+	public interface IPhotoLoader
+	{
+		/// <summary>
+		///    Used to remove all cached data when a file is delete.
+		/// </summary>
+		void ClearCache ();
+
+		Task<Pixbuf> FindBestPreview (int width, int height);
+	}
+}
diff --git a/src/Loaders/PhotoLoaderCache.cs b/src/Loaders/PhotoLoaderCache.cs
new file mode 100644
index 0000000..ab9e5b3
--- /dev/null
+++ b/src/Loaders/PhotoLoaderCache.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+
+namespace FSpot.Loaders
+{
+    public class PhotoLoaderCache
+    {
+        Dictionary<string, WeakReference> Loaders = new Dictionary<string, WeakReference>();
+
+        public IPhotoLoader RequestLoader (ILoadable photo)
+        {
+            var key = photo.Uri.ToString ();
+            WeakReference reference = null;
+            IPhotoLoader loader = null;
+
+            if (Loaders.TryGetValue (key, out reference)) {
+                loader = reference.Target as IPhotoLoader;
+            }
+
+            if (loader == null) {
+                loader = new XdgThumbnailLoader (photo);
+                Loaders[key] = new WeakReference (loader);
+            }
+
+            return loader;
+        }
+    }
+}
diff --git a/src/Loaders/XdgThumbnailLoader.cs b/src/Loaders/XdgThumbnailLoader.cs
new file mode 100644
index 0000000..65aa7b7
--- /dev/null
+++ b/src/Loaders/XdgThumbnailLoader.cs
@@ -0,0 +1,29 @@
+using Gdk;
+using FSpot.Tasks;
+using FSpot.Utils;
+
+namespace FSpot.Loaders
+{
+	public class XdgThumbnailLoader : IPhotoLoader
+	{
+        ILoadable Loadable { get; set; }
+
+		public XdgThumbnailLoader (ILoadable loadable)
+		{
+			Loadable = loadable;
+		}
+
+		public void ClearCache ()
+		{
+			XdgThumbnailSpec.RemoveThumbnail (Loadable.Uri);
+		}
+
+		public Task<Pixbuf> FindBestPreview (int width, int height)
+		{
+			return new QueuedTask<Pixbuf> (() => {
+				var size = (width > 128 || height > 128) ? ThumbnailSize.Large : ThumbnailSize.Normal;
+				return XdgThumbnailSpec.LoadThumbnail (Loadable.Uri, size);
+			});
+		}
+	}
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index bdc1037..5c8c4e4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,7 +75,10 @@ SOURCES = \
 	Loaders/AreaUpdatedEventArgs.cs \
 	Loaders/ImageLoader.cs \
 	Loaders/IImageLoader.cs \
+	Loaders/IPhotoLoader.cs \
 	Loaders/GdkImageLoader.cs \
+	Loaders/PhotoLoaderCache.cs \
+	Loaders/XdgThumbnailLoader.cs \
 	ImageLoaderThread.cs \
 	Import/ImportController.cs \
 	Import/ImportSource.cs \



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