[f-spot/mipmapped-loading: 2/12] Start adding a simple task-based photo loader.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/mipmapped-loading: 2/12] Start adding a simple task-based photo loader.
- Date: Thu, 8 Jul 2010 19:03:16 +0000 (UTC)
commit 2757243c769c4b88295d0c85b9a5764f9c4da280
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/Loaders/IPhotoLoader.cs | 15 +++++++++++++++
src/Loaders/PhotoLoaderCache.cs | 28 ++++++++++++++++++++++++++++
src/Loaders/XdgThumbnailLoader.cs | 29 +++++++++++++++++++++++++++++
src/Makefile.am | 3 +++
5 files changed, 88 insertions(+), 0 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/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 89618db..685899e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,7 +74,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]