[f-spot/mipmapped-loading: 3/3] 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: 3/3] Start adding a simple task-based photo loader.
- Date: Sat, 19 Jun 2010 23:48:03 +0000 (UTC)
commit b1e826882d590ee0d37e0d1f17bbe056a59d9874
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 c5aafe2..50a51d1 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -18,6 +18,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..bc08677
--- /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 724096b..3e3af73 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -77,7 +77,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]