f-spot r4542 - in trunk: . src src/Core src/Platform src/Platform/Gnome src/Widgets
- From: sdelcroix svn gnome org
- To: svn-commits-list gnome org
- Subject: f-spot r4542 - in trunk: . src src/Core src/Platform src/Platform/Gnome src/Widgets
- Date: Tue, 28 Oct 2008 13:56:28 +0000 (UTC)
Author: sdelcroix
Date: Tue Oct 28 13:56:28 2008
New Revision: 4542
URL: http://svn.gnome.org/viewvc/f-spot?rev=4542&view=rev
Log:
2008-10-21 Stephane Delcroix <sdelcroix novell com>
* src/Makefile.am:
* src/Platform/Gnome/ThumbnailFactory.cs: move all the Gnome.Thumbnail*
code in this factory class, and abstract the API to be suitable for
other platforms
* src/AsyncPixbufLoader.cs:
* src/Core/Photo.cs:
* src/MainWindow.cs:
* src/PhotoLoader.cs:
* src/PhotoVersionCommand.cs:
* src/PixbufCache.cs:
* src/ThumbnailCache.cs:
* src/ThumbnailGenerator.cs:
* src/Widgets/EditorPage.cs:
* src/Widges/FilmStrip.cs:
* src/Widgets/IconView.cs: use the new ThumbnailFactory instead of the Gnome
one.
Added:
trunk/src/Platform/
trunk/src/Platform/Gnome/
trunk/src/Platform/Gnome/GnomeThumbnailFactory.cs
trunk/src/Platform/Gnome/ThumbnailFactory.cs
Modified:
trunk/ChangeLog
trunk/src/.gitignore
trunk/src/AsyncPixbufLoader.cs
trunk/src/Core/Photo.cs
trunk/src/MainWindow.cs
trunk/src/Makefile.am
trunk/src/PhotoLoader.cs
trunk/src/PhotoStore.cs
trunk/src/PhotoVersionCommands.cs
trunk/src/PixbufCache.cs
trunk/src/ThumbnailCache.cs
trunk/src/ThumbnailGenerator.cs
trunk/src/Widgets/EditorPage.cs
trunk/src/Widgets/Filmstrip.cs
trunk/src/Widgets/IconView.cs
Modified: trunk/src/.gitignore
==============================================================================
--- trunk/src/.gitignore (original)
+++ trunk/src/.gitignore Tue Oct 28 13:56:28 2008
@@ -13,6 +13,8 @@
/FSpot.Utils.dll.mdb
/FSpot.Widgets.dll
/FSpot.Widgets.dll.mdb
+/FSpot.Platform.dll
+/FSpot.Platform.dll.mdb
/Makefile
/Makefile.in
/f-spot
Modified: trunk/src/AsyncPixbufLoader.cs
==============================================================================
--- trunk/src/AsyncPixbufLoader.cs (original)
+++ trunk/src/AsyncPixbufLoader.cs Tue Oct 28 13:56:28 2008
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Runtime.Remoting.Messaging;
+using FSpot.Platform;
+using FSpot.Utils;
namespace FSpot {
public delegate void AreaUpdatedHandler (object sender, AreaUpdatedArgs area);
@@ -118,7 +120,7 @@
try {
PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation (PixbufOrientation.TopLeft);
- thumb = new Gdk.Pixbuf (ThumbnailGenerator.ThumbnailPath (uri));
+ thumb = ThumbnailFactory.LoadThumbnail (uri);
thumb = PixbufUtils.TransformOrientation (thumb, thumb_orientation);
if (FSpot.ColorManagement.IsEnabled && !thumb.HasAlpha) {
@@ -130,9 +132,8 @@
else
FSpot.ColorManagement.PhotoImageView.Transform = null;
} catch (System.Exception e) {
- //FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);
if (!(e is GLib.GException))
- System.Console.WriteLine (e.ToString ());
+ Log.DebugException (e);
}
System.IO.Stream nstream = img.PixbufStream ();
@@ -395,7 +396,7 @@
Gdk.InterpType.Bilinear, 0xff);
if (thumb != null)
- if (!ThumbnailGenerator.ThumbnailIsValid (thumb, uri))
+ if (!ThumbnailFactory.ThumbnailIsValid (thumb, uri))
FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
area_prepared = true;
Modified: trunk/src/Core/Photo.cs
==============================================================================
--- trunk/src/Core/Photo.cs (original)
+++ trunk/src/Core/Photo.cs Tue Oct 28 13:56:28 2008
@@ -17,6 +17,7 @@
using Mono.Unix;
using FSpot.Utils;
+using FSpot.Platform;
namespace FSpot
{
@@ -396,12 +397,10 @@
}
try {
- string thumb_path = ThumbnailGenerator.ThumbnailPath (uri);
- System.IO.File.Delete (thumb_path);
- } catch (System.Exception) {
+ ThumbnailFactory.DeleteThumbnail (uri);
+ } catch {
//ignore an error here we don't really care.
}
- PhotoStore.DeleteThumbnail (uri);
}
Versions.Remove (version_id);
Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs (original)
+++ trunk/src/MainWindow.cs Tue Oct 28 13:56:28 2008
@@ -1252,8 +1252,7 @@
bool use_icon = false;;
while (len-- > 0) {
- string thumbnail_path = FSpot.ThumbnailGenerator.ThumbnailPath (photos [len].DefaultVersionUri);
- FSpot.PixbufCache.CacheEntry entry = icon_view.Cache.Lookup (thumbnail_path);
+ FSpot.PixbufCache.CacheEntry entry = icon_view.Cache.Lookup (photos [len].DefaultVersionUri);
Pixbuf thumbnail = null;
if (entry != null) {
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Tue Oct 28 13:56:28 2008
@@ -76,6 +76,9 @@
$(srcdir)/Widgets/SaneTreeView.cs \
$(srcdir)/Widgets/ScrolledView.cs
+PLATFORM_CSDISTFILES = \
+ $(srcdir)/Platform/Gnome/ThumbnailFactory.cs
+
F_SPOT_CSDISTFILES = \
$(srcdir)/AsyncPixbufLoader.cs \
$(srcdir)/BlockProcessor.cs \
@@ -311,6 +314,11 @@
-r:FSpot.Core.dll \
-r:FSpot.Utils.dll
+PLATFORM_ASSEMBLIES = \
+ -pkg:gnome-sharp-2.0 \
+ -pkg:gtk-sharp-2.0 \
+ -r:FSpot.Utils.dll
+
F_SPOT_ASSEMBLIES = \
$(LINK_DBUS) \
$(LINK_GPHOTO2) \
@@ -332,6 +340,7 @@
-r:FSpot.Utils.dll \
-r:FSpot.JobScheduler.dll \
-r:FSpot.Widgets.dll \
+ -r:FSpot.Platform.dll \
-r:Cms.dll \
$(NUNIT_PKG) \
$(GCONF_PKG) \
@@ -364,7 +373,8 @@
FSpot.Query.dll \
FSpot.Core.dll \
FSpot.JobScheduler.dll \
- FSpot.Widgets.dll
+ FSpot.Widgets.dll \
+ FSpot.Platform.dll
bin_SCRIPTS = f-spot
@@ -381,6 +391,8 @@
WIDGETS_CSFILES = $(WIDGETS_CSDISTFILES)
+PLATFORM_CSFILES = $(PLATFORM_CSDISTFILES)
+
F_SPOT_CSFILES = $(F_SPOT_CSDISTFILES) \
AssemblyInfo.cs
@@ -408,7 +420,11 @@
@echo -e "\n*** Compiling $@"
$(CSC_LIB) -out:$@ $(EXTRAFLAGS) $(WIDGETS_CSFILES) $(WIDGETS_ASSEMBLIES)
-f-spot.exe: $(F_SPOT_CSFILES) FSpot.Utils.dll FSpot.Core.dll FSpot.Query.dll FSpot.JobScheduler.dll FSpot.Widgets.dll Cms.dll $(F_SPOT_RESOURCES)
+FSpot.Platform.dll: $(PLATFORM_CSFILES) FSpot.Utils.dll
+ @echo -e "\n*** Compiling $@"
+ $(CSC_LIB) -out:$@ $(EXTRAFLAGS) $(PLATFORM_CSFILES) $(PLATFORM_ASSEMBLIES)
+
+f-spot.exe: $(F_SPOT_CSFILES) FSpot.Utils.dll FSpot.Core.dll FSpot.Query.dll FSpot.JobScheduler.dll FSpot.Widgets.dll Cms.dll FSpot.Platform.dll $(F_SPOT_RESOURCES)
@echo -e "\n*** Compiling $@"
$(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(UNSAFE) $(NOWARN) $(NUNIT_DEFINES) $(F_SPOT_CSFILES) $(F_SPOT_ASSEMBLIES) $(RESOURCES)
Modified: trunk/src/PhotoLoader.cs
==============================================================================
--- trunk/src/PhotoLoader.cs (original)
+++ trunk/src/PhotoLoader.cs Tue Oct 28 13:56:28 2008
@@ -1,3 +1,6 @@
+using System;
+
+using FSpot.Platform;
using FSpot.Utils;
namespace FSpot {
@@ -37,11 +40,7 @@
return ValidateThumbnail (item.DefaultVersionUri, pixbuf);
}
- static public bool ThumbnailIsValid (System.Uri uri, Gdk.Pixbuf thumbnail)
- {
- return FSpot.ThumbnailGenerator.ThumbnailIsValid (thumbnail, uri);
- }
-
+ [Obsolete ("Use ValidateThumbnail (uri, Pixbuf) instead")]
static public Gdk.Pixbuf ValidateThumbnail (string photo_path, Gdk.Pixbuf pixbuf)
{
System.Uri uri = UriUtils.PathToFileUri (photo_path);
@@ -50,22 +49,12 @@
static public Gdk.Pixbuf ValidateThumbnail (System.Uri uri, Gdk.Pixbuf pixbuf)
{
- string thumbnail_path = Gnome.Thumbnail.PathForUri (uri.ToString (),
- Gnome.ThumbnailSize.Large);
-
- Gdk.Pixbuf thumbnail = ThumbnailCache.Default.GetThumbnailForPath (thumbnail_path);
-
- if (pixbuf != null && thumbnail != null) {
- if (!ThumbnailIsValid (uri, thumbnail)) {
+ using (Gdk.Pixbuf thumbnail = ThumbnailCache.Default.GetThumbnailForUri (uri)) {
+ if (pixbuf != null && thumbnail != null && !ThumbnailFactory.ThumbnailIsValid (thumbnail, uri)) {
Log.DebugFormat ("regenerating thumbnail for {0}", uri);
FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
}
-
}
-
- if (thumbnail != null)
- thumbnail.Dispose ();
-
return pixbuf;
}
Modified: trunk/src/PhotoStore.cs
==============================================================================
--- trunk/src/PhotoStore.cs (original)
+++ trunk/src/PhotoStore.cs Tue Oct 28 13:56:28 2008
@@ -24,6 +24,7 @@
using FSpot;
using FSpot.Query;
using FSpot.Utils;
+using FSpot.Platform;
using Banshee.Database;
@@ -39,8 +40,6 @@
}
}
- public static Gnome.ThumbnailFactory ThumbnailFactory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
-
// FIXME this is a hack. Since we don't have Gnome.ThumbnailFactory.SaveThumbnail() in
// GTK#, and generate them by ourselves directly with Gdk.Pixbuf, we have to make sure here
// that the "large" thumbnail directory exists.
@@ -57,14 +56,14 @@
// Generates the thumbnail, returns the Pixbuf, and also stores it as a side effect
//
- public static Pixbuf GenerateThumbnail (System.Uri uri)
+ private static Pixbuf GenerateThumbnail (System.Uri uri)
{
using (FSpot.ImageFile img = FSpot.ImageFile.Create (uri)) {
return GenerateThumbnail (uri, img);
}
}
- public static Pixbuf GenerateThumbnail (System.Uri uri, ImageFile img)
+ private static Pixbuf GenerateThumbnail (System.Uri uri, ImageFile img)
{
Pixbuf thumbnail = null;
@@ -77,29 +76,21 @@
}
// Save embedded thumbnails in a silightly invalid way so that we know to regnerate them later.
- if (thumbnail != null) {
- PixbufUtils.SaveAtomic (thumbnail, FSpot.ThumbnailGenerator.ThumbnailPath (uri),
- "png", new string [] { null} , new string [] { null});
+ if (thumbnail != null)
//FIXME with gio, set it to uri time minus a few sec
- System.IO.File.SetLastWriteTime (FSpot.ThumbnailGenerator.ThumbnailPath (uri), new DateTime (1980, 1, 1));
- } else
+ ThumbnailFactory.SaveThumbnail (thumbnail, uri, new DateTime (1980, 1, 1));
+ else
thumbnail = FSpot.ThumbnailGenerator.Create (uri);
return thumbnail;
}
- public static void DeleteThumbnail (System.Uri uri)
- {
- string path = Gnome.Thumbnail.PathForUri (uri.ToString (), Gnome.ThumbnailSize.Large);
- if (System.IO.File.Exists (path))
- System.IO.File.Delete (path);
- }
- public static void MoveThumbnail (string old_path, string new_path)
- {
- System.IO.File.Move (ThumbnailGenerator.ThumbnailPath (UriUtils.PathToFileUri (old_path)),
- ThumbnailGenerator.ThumbnailPath(UriUtils.PathToFileUri (new_path)));
- }
+// public static void MoveThumbnail (string old_path, string new_path)
+// {
+// System.IO.File.Move (ThumbnailGenerator.ThumbnailPath (UriUtils.PathToFileUri (old_path)),
+// ThumbnailGenerator.ThumbnailPath(UriUtils.PathToFileUri (new_path)));
+// }
// Constructor
Modified: trunk/src/PhotoVersionCommands.cs
==============================================================================
--- trunk/src/PhotoVersionCommands.cs (original)
+++ trunk/src/PhotoVersionCommands.cs Tue Oct 28 13:56:28 2008
@@ -3,6 +3,7 @@
using System;
using Mono.Unix;
using FSpot;
+using FSpot.Utils;
using FSpot.UI.Dialog;
public class PhotoVersionCommands
@@ -149,7 +150,7 @@
photo.DeleteVersion (photo.DefaultVersionId);
store.Commit (photo);
} catch (Exception e) {
- // FIXME show error dialog.
+ Log.DebugException (e);
string msg = Catalog.GetString ("Could not delete a version");
string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
e.Message, photo.Name);
Modified: trunk/src/PixbufCache.cs
==============================================================================
--- trunk/src/PixbufCache.cs (original)
+++ trunk/src/PixbufCache.cs Tue Oct 28 13:56:28 2008
@@ -11,6 +11,8 @@
using System.Collections;
using System.Threading;
+using FSpot.Platform;
+
namespace FSpot {
public class PixbufCache {
Hashtable items;
@@ -36,20 +38,18 @@
public void HandleThumbnailLoaded (PixbufLoader loader, Uri uri, int order, Gdk.Pixbuf result)
{
- string thumb_path = ThumbnailGenerator.ThumbnailPath (uri);
-
if (result != null)
- Reload (thumb_path);
+ Reload (uri);
}
-
- public void Request (string path, object closure, int width, int height)
+
+ public void Request (Uri uri, object closure, int width, int height)
{
lock (items) {
- CacheEntry entry = items[path] as CacheEntry;
+ CacheEntry entry = items[uri] as CacheEntry;
if (entry == null) {
- entry = new CacheEntry (this, path, closure, width, height);
- items [path] = entry;
+ entry = new CacheEntry (this, uri, closure, width, height);
+ items [uri] = entry;
items_mru.Add (entry);
} else {
MoveForward (entry);
@@ -57,22 +57,17 @@
}
Monitor.Pulse (items);
}
-#if GSD_2_24
- if (!System.IO.File.Exists (path))
- return;
- Utils.Unix.Touch (path);
-#endif
}
- public void Update (string path, Gdk.Pixbuf pixbuf)
- {
- lock (items) {
- CacheEntry entry = (CacheEntry) items [path];
- if (entry != null) {
- entry.SetPixbufExtended (pixbuf, true);
- }
- }
- }
+// public void Update (Uri uri, Gdk.Pixbuf pixbuf)
+// {
+// lock (items) {
+// CacheEntry entry = (CacheEntry) items [uri];
+// if (entry != null) {
+// entry.SetPixbufExtended (pixbuf, true);
+// }
+// }
+// }
public void Update (CacheEntry entry, Gdk.Pixbuf pixbuf)
{
@@ -94,12 +89,12 @@
}
}
- public void Reload (string path)
+ public void Reload (Uri uri)
{
CacheEntry entry;
lock (items) {
- entry = (CacheEntry) items [path];
+ entry = (CacheEntry) items [uri];
if (entry != null) {
lock (entry) {
entry.Reload = true;
@@ -147,7 +142,7 @@
int num = 0;
while ((items_mru.Count - num) > 10 && total_size > max_size) {
CacheEntry entry = (CacheEntry) items_mru [num++];
- items.Remove (entry.Path);
+ items.Remove (entry.Uri);
entry.Dispose ();
}
if (num > 0) {
@@ -188,7 +183,7 @@
{
Gdk.Pixbuf loaded = null;
try {
- loaded = new Gdk.Pixbuf (entry.Path);
+ loaded = ThumbnailFactory.LoadThumbnail (entry.Uri);
this.Update (entry, loaded);
} catch (GLib.GException){
if (loaded != null)
@@ -200,7 +195,7 @@
private void QueueLast (CacheEntry entry)
{
Gtk.Application.Invoke (delegate (object obj, System.EventArgs args) {
- if (entry.Path != null && OnPixbufLoaded != null)
+ if (entry.Uri != null && OnPixbufLoaded != null)
OnPixbufLoaded (this, entry);
});
}
@@ -226,51 +221,51 @@
}
- private CacheEntry ULookup (string path)
+ private CacheEntry ULookup (Uri uri)
{
- CacheEntry entry = (CacheEntry) items [path];
+ CacheEntry entry = (CacheEntry) items [uri];
if (entry != null) {
MoveForward (entry);
}
return (CacheEntry) entry;
}
- public CacheEntry Lookup (string path)
+ public CacheEntry Lookup (Uri uri)
{
lock (items) {
- return ULookup (path);
+ return ULookup (uri);
}
}
- public void Remove (string path)
+ private void URemove (Uri uri)
{
- lock (items) {
- URemove (path);
+ CacheEntry entry = (CacheEntry) items [uri];
+ if (entry != null) {
+ items.Remove (uri);
+ items_mru.Remove (entry);
+ entry.Dispose ();
}
}
- private void URemove (string path)
+ public void Remove (Uri uri)
{
- CacheEntry entry = (CacheEntry) items [path];
- if (entry != null) {
- items.Remove (path);
- items_mru.Remove (entry);
- entry.Dispose ();
+ lock (items) {
+ URemove (uri);
}
}
public class CacheEntry : System.IDisposable {
private Gdk.Pixbuf pixbuf;
- private string path;
+ private Uri uri;
private int width;
private int height;
private object data;
private bool reload;
private PixbufCache cache;
- public CacheEntry (PixbufCache cache, string path, object closure, int width, int height)
+ public CacheEntry (PixbufCache cache, Uri uri, object closure, int width, int height)
{
- this.path = path;
+ this.uri = uri;
this.width = width;
this.height = height;
this.data = closure;
@@ -284,8 +279,8 @@
set { reload = value; }
}
- public string Path {
- get { return path; }
+ public Uri Uri {
+ get { return uri; }
}
public int Width {
@@ -312,7 +307,7 @@
}
public bool IsDisposed {
- get { return path == null; }
+ get { return uri == null; }
}
public void SetPixbufExtended (Gdk.Pixbuf value, bool ignore_undead)
@@ -380,7 +375,7 @@
}
this.pixbuf = null;
this.cache = null;
- this.path = null;
+ this.uri = null;
}
System.GC.SuppressFinalize (this);
}
Added: trunk/src/Platform/Gnome/GnomeThumbnailFactory.cs
==============================================================================
--- (empty file)
+++ trunk/src/Platform/Gnome/GnomeThumbnailFactory.cs Tue Oct 28 13:56:28 2008
@@ -0,0 +1,141 @@
+/*
+ * FSpot.Platform.GnomeThumnailFactory.cs
+ *
+ * Author(s):
+ * Stephane Delcroix <stephane delcroix org>
+ *
+ * Copyright 2008 Novell, Inc
+ *
+ * This is free software, See COPYING for details
+ */
+
+using System;
+using FSpot.Utils;
+using Gdk;
+
+namespace FSpot.Platform
+{
+ public class ThumbnailFactory
+ {
+ static Gnome.ThumbnailFactory gnome_thumbnail_factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
+
+ public static void SaveThumbnail (Pixbuf pixbuf, Uri image_uri)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (image_uri.ToString ());
+ DateTime mtime = vfs.Mtime;
+ SaveThumbnail (pixbuf, image_uri, mtime);
+ }
+
+ public static void SaveThumbnail (Pixbuf pixbuf, Uri image_uri, DateTime original_mtime)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ gnome_thumbnail_factory.SaveThumbnail (pixbuf, UriUtils.UriToStringEscaped (image_uri), original_mtime);
+ }
+
+ public static void DeleteThumbnail (Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+ try {
+ if (System.IO.File.Exists (PathForUri (image_uri)))
+ System.IO.File.Delete (PathForUri (image_uri));
+ } catch (Exception e) {
+ Log.DebugException (e);
+ }
+ }
+
+ public static void MoveThumbnail (Uri from_uri, Uri to_uri)
+ {
+ if (from_uri == null)
+ throw new ArgumentNullException ("from_uri");
+ if (to_uri == null)
+ throw new ArgumentNullException ("to_uri");
+ System.IO.File.Move (PathForUri (from_uri), PathForUri (to_uri));
+ }
+
+ public static bool ThumbnailIsValid (Pixbuf pixbuf, Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ try {
+ Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (image_uri.ToString ());
+ DateTime mtime = vfs.Mtime;
+ return ThumbnailIsValid (pixbuf, image_uri, mtime);
+ } catch (System.IO.FileNotFoundException) {
+ // If the original file is not on disk, the thumbnail is as valid as it's going to get
+ return true;
+ } catch (System.Exception e) {
+ Log.DebugException (e);
+ return false;
+ }
+ }
+
+ public static bool ThumbnailIsValid (Pixbuf pixbuf, Uri image_uri, DateTime mtime)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ try {
+ return Gnome.Thumbnail.IsValid (pixbuf, UriUtils.UriToStringEscaped (image_uri), mtime);
+ } catch (System.IO.FileNotFoundException) {
+ // If the original file is not on disk, the thumbnail is as valid as it's going to get
+ return true;
+ } catch (System.Exception e) {
+ System.Console.WriteLine (e);
+ return false;
+ }
+ }
+
+ public static Pixbuf LoadThumbnail (Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+#if GSD_2_24
+ if (System.IO.File.Exists (PathForUri (image_uri)))
+ Utils.Unix.Touch (PathForUri (image_uri));
+#endif
+ try {
+ return new Pixbuf (PathForUri (image_uri));
+ } catch {
+ return null;
+ }
+ }
+
+ public static Pixbuf LoadThumbnail (Uri image_uri, int dest_width, int dest_height)
+ {
+ using (Pixbuf p = LoadThumbnail (image_uri)) {
+ return Gnome.Thumbnail.ScaleDownPixbuf (p, dest_width, dest_height);
+ }
+ }
+
+ public static bool ThumbnailExists (Uri image_uri)
+ {
+ return System.IO.File.Exists (PathForUri (image_uri));
+ }
+
+ public static bool ThumbnailIsRecent (Uri image_uri)
+ {
+ if (!image_uri.IsFile)
+ Log.Debug ("FIXME: compute timestamp on non file uri too");
+
+ return image_uri.IsFile && System.IO.File.Exists (PathForUri (image_uri)) && System.IO.File.GetLastWriteTime (PathForUri (image_uri)) >= System.IO.File.GetLastWriteTime (image_uri.AbsolutePath);
+ }
+
+ static string PathForUri (Uri uri)
+ {
+ return Gnome.Thumbnail.PathForUri (UriUtils.UriToStringEscaped (uri), Gnome.ThumbnailSize.Large);
+ }
+ }
+}
Added: trunk/src/Platform/Gnome/ThumbnailFactory.cs
==============================================================================
--- (empty file)
+++ trunk/src/Platform/Gnome/ThumbnailFactory.cs Tue Oct 28 13:56:28 2008
@@ -0,0 +1,141 @@
+/*
+ * FSpot.Platform.Gnome.ThumnailFactory.cs
+ *
+ * Author(s):
+ * Stephane Delcroix <stephane delcroix org>
+ *
+ * Copyright 2008 Novell, Inc
+ *
+ * This is free software, See COPYING for details
+ */
+
+using System;
+using FSpot.Utils;
+using Gdk;
+
+namespace FSpot.Platform
+{
+ public class ThumbnailFactory
+ {
+ static Gnome.ThumbnailFactory gnome_thumbnail_factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
+
+ public static void SaveThumbnail (Pixbuf pixbuf, Uri image_uri)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (image_uri.ToString ());
+ DateTime mtime = vfs.Mtime;
+ SaveThumbnail (pixbuf, image_uri, mtime);
+ }
+
+ public static void SaveThumbnail (Pixbuf pixbuf, Uri image_uri, DateTime original_mtime)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ gnome_thumbnail_factory.SaveThumbnail (pixbuf, UriUtils.UriToStringEscaped (image_uri), original_mtime);
+ }
+
+ public static void DeleteThumbnail (Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+ try {
+ if (System.IO.File.Exists (PathForUri (image_uri)))
+ System.IO.File.Delete (PathForUri (image_uri));
+ } catch (Exception e) {
+ Log.DebugException (e);
+ }
+ }
+
+ public static void MoveThumbnail (Uri from_uri, Uri to_uri)
+ {
+ if (from_uri == null)
+ throw new ArgumentNullException ("from_uri");
+ if (to_uri == null)
+ throw new ArgumentNullException ("to_uri");
+ System.IO.File.Move (PathForUri (from_uri), PathForUri (to_uri));
+ }
+
+ public static bool ThumbnailIsValid (Pixbuf pixbuf, Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ try {
+ Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (image_uri.ToString ());
+ DateTime mtime = vfs.Mtime;
+ return ThumbnailIsValid (pixbuf, image_uri, mtime);
+ } catch (System.IO.FileNotFoundException) {
+ // If the original file is not on disk, the thumbnail is as valid as it's going to get
+ return true;
+ } catch (System.Exception e) {
+ Log.DebugException (e);
+ return false;
+ }
+ }
+
+ public static bool ThumbnailIsValid (Pixbuf pixbuf, Uri image_uri, DateTime mtime)
+ {
+ if (pixbuf == null)
+ throw new ArgumentNullException ("pixbuf");
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+
+ try {
+ return Gnome.Thumbnail.IsValid (pixbuf, UriUtils.UriToStringEscaped (image_uri), mtime);
+ } catch (System.IO.FileNotFoundException) {
+ // If the original file is not on disk, the thumbnail is as valid as it's going to get
+ return true;
+ } catch (System.Exception e) {
+ System.Console.WriteLine (e);
+ return false;
+ }
+ }
+
+ public static Pixbuf LoadThumbnail (Uri image_uri)
+ {
+ if (image_uri == null)
+ throw new ArgumentNullException ("image_uri");
+#if GSD_2_24
+ if (System.IO.File.Exists (PathForUri (image_uri)))
+ Utils.Unix.Touch (PathForUri (image_uri));
+#endif
+ try {
+ return new Pixbuf (PathForUri (image_uri));
+ } catch {
+ return null;
+ }
+ }
+
+ public static Pixbuf LoadThumbnail (Uri image_uri, int dest_width, int dest_height)
+ {
+ using (Pixbuf p = LoadThumbnail (image_uri)) {
+ return Gnome.Thumbnail.ScaleDownPixbuf (p, dest_width, dest_height);
+ }
+ }
+
+ public static bool ThumbnailExists (Uri image_uri)
+ {
+ return System.IO.File.Exists (PathForUri (image_uri));
+ }
+
+ public static bool ThumbnailIsRecent (Uri image_uri)
+ {
+ if (!image_uri.IsFile)
+ Log.Debug ("FIXME: compute timestamp on non file uri too");
+
+ return image_uri.IsFile && System.IO.File.Exists (PathForUri (image_uri)) && System.IO.File.GetLastWriteTime (PathForUri (image_uri)) >= System.IO.File.GetLastWriteTime (image_uri.AbsolutePath);
+ }
+
+ static string PathForUri (Uri uri)
+ {
+ return Gnome.Thumbnail.PathForUri (UriUtils.UriToStringEscaped (uri), Gnome.ThumbnailSize.Large);
+ }
+ }
+}
Modified: trunk/src/ThumbnailCache.cs
==============================================================================
--- trunk/src/ThumbnailCache.cs (original)
+++ trunk/src/ThumbnailCache.cs Tue Oct 28 13:56:28 2008
@@ -22,8 +22,8 @@
// Types.
private class Thumbnail {
- // Path of the image on the disk.
- public string path;
+ // Uri of the image source
+ public Uri uri;
// The uncompressed thumbnail.
public Pixbuf pixbuf;
@@ -55,27 +55,27 @@
}
}
- public void AddThumbnail (string path, Pixbuf pixbuf)
+ public void AddThumbnail (Uri uri, Pixbuf pixbuf)
{
Thumbnail thumbnail = new Thumbnail ();
- thumbnail.path = path;
+ thumbnail.uri = uri;
thumbnail.pixbuf = pixbuf;
- RemoveThumbnailForPath (path);
+ RemoveThumbnailForUri (uri);
pixbuf_mru.Insert (0, thumbnail);
- pixbuf_hash.Add (path, thumbnail);
+ pixbuf_hash.Add (uri, thumbnail);
MaybeExpunge ();
}
- public Pixbuf GetThumbnailForPath (string path)
+ public Pixbuf GetThumbnailForUri (Uri uri)
{
- if (! pixbuf_hash.ContainsKey (path))
+ if (! pixbuf_hash.ContainsKey (uri))
return null;
- Thumbnail item = pixbuf_hash [path] as Thumbnail;
+ Thumbnail item = pixbuf_hash [uri] as Thumbnail;
pixbuf_mru.Remove (item);
pixbuf_mru.Insert (0, item);
@@ -83,14 +83,14 @@
return PixbufUtils.ShallowCopy (item.pixbuf);
}
- public void RemoveThumbnailForPath (string path)
+ public void RemoveThumbnailForUri (Uri uri)
{
- if (! pixbuf_hash.ContainsKey (path))
+ if (! pixbuf_hash.ContainsKey (uri))
return;
- Thumbnail item = pixbuf_hash [path] as Thumbnail;
+ Thumbnail item = pixbuf_hash [uri] as Thumbnail;
- pixbuf_hash.Remove (path);
+ pixbuf_hash.Remove (uri);
pixbuf_mru.Remove (item);
item.pixbuf.Dispose ();
@@ -100,7 +100,7 @@
{
foreach (object item in pixbuf_mru) {
Thumbnail thumb = item as Thumbnail;
- pixbuf_hash.Remove (thumb.path);
+ pixbuf_hash.Remove (thumb.uri);
thumb.pixbuf.Dispose ();
}
pixbuf_mru.Clear ();
@@ -112,7 +112,7 @@
Log.DebugFormat ("Finalizer called on {0}. Should be Disposed", GetType ());
foreach (object item in pixbuf_mru) {
Thumbnail thumb = item as Thumbnail;
- pixbuf_hash.Remove (thumb.path);
+ pixbuf_hash.Remove (thumb.uri);
thumb.pixbuf.Dispose ();
}
pixbuf_mru.Clear ();
@@ -125,7 +125,7 @@
while (pixbuf_mru.Count > max_count) {
Thumbnail thumbnail = pixbuf_mru [pixbuf_mru.Count - 1] as Thumbnail;
- pixbuf_hash.Remove (thumbnail.path);
+ pixbuf_hash.Remove (thumbnail.uri);
pixbuf_mru.RemoveAt (pixbuf_mru.Count - 1);
thumbnail.pixbuf.Dispose ();
Modified: trunk/src/ThumbnailGenerator.cs
==============================================================================
--- trunk/src/ThumbnailGenerator.cs (original)
+++ trunk/src/ThumbnailGenerator.cs Tue Oct 28 13:56:28 2008
@@ -10,10 +10,11 @@
using System;
using System.IO;
using FSpot.Utils;
+using FSpot.Platform;
namespace FSpot {
public class ThumbnailGenerator : PixbufLoader {
- private static Gnome.ThumbnailFactory factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
+
static public ThumbnailGenerator Default = new ThumbnailGenerator ();
public const string ThumbMTime = "tEXt::Thumb::MTime";
@@ -21,6 +22,7 @@
public const string ThumbImageWidth = "tEXt::Thumb::Image::Width";
public const string ThumbImageHeight = "tEXt::Thumb::Image::Height";
+ [Obsolete ("Use Create (Uri) instead")]
public static Gdk.Pixbuf Create (string path)
{
return Create (UriUtils.PathToFileUri (path));
@@ -29,75 +31,39 @@
public static Gdk.Pixbuf Create (Uri uri)
{
try {
+ Gdk.Pixbuf thumb;
+
using (ImageFile img = ImageFile.Create (uri)) {
- Gdk.Pixbuf thumb = img.Load (256, 256);
+ thumb = img.Load (256, 256);
+ }
- if (thumb != null)
- Save (thumb, uri);
- return thumb;
+ if (thumb == null)
+ return null;
+
+ try { //Setting the thumb options
+ Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (UriUtils.UriToStringEscaped (uri));
+ DateTime mtime = vfs.Mtime;
+
+ PixbufUtils.SetOption (thumb, ThumbUri, UriUtils.UriToStringEscaped (uri));
+ PixbufUtils.SetOption (thumb, ThumbMTime, ((uint)GLib.Marshaller.DateTimeTotime_t (mtime)).ToString ());
+ } catch (System.Exception e) {
+ Log.Exception (e);
}
- } catch {
+
+ Save (thumb, uri);
+ return thumb;
+ } catch (Exception e) {
+ Log.Exception (e);
return null;
}
}
- public static bool ThumbnailIsValid (Gdk.Pixbuf thumbnail, System.Uri uri)
- {
- bool valid = false;
-
- try {
- Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (uri.ToString ());
- DateTime mtime = vfs.Mtime;
- valid = Gnome.Thumbnail.IsValid (thumbnail, UriUtils.UriToStringEscaped (uri), mtime);
- } catch (System.IO.FileNotFoundException) {
- // If the original file is not on disk, the thumbnail is as valid as it's going to get
- valid = true;
- } catch (System.Exception e) {
- System.Console.WriteLine (e);
- valid = false;
- }
-
- return valid;
- }
-
- public static string ThumbnailPath (System.Uri uri)
+ private static void Save (Gdk.Pixbuf image, Uri uri)
{
- string large_path = Gnome.Thumbnail.PathForUri (UriUtils.UriToStringEscaped (uri), Gnome.ThumbnailSize.Large);
- return large_path;
- }
-
- [Obsolete ("Use ThumbnailPath (System.Uri) instead")]
- public static string ThumbnailPath (string path)
- {
- return ThumbnailPath (UriUtils.PathToFileUri (path));
- }
-
- public static void Save (Gdk.Pixbuf image, Uri dest)
- {
- string uri = UriUtils.UriToStringEscaped (dest);
- System.DateTime mtime = DateTime.Now;
-
- // Use Gnome.Vfs
- try {
- Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (uri);
- mtime = vfs.Mtime;
-
- PixbufUtils.SetOption (image, ThumbUri, uri);
- PixbufUtils.SetOption (image, ThumbMTime,
- ((uint)GLib.Marshaller.DateTimeTotime_t (mtime)).ToString ());
- } catch (System.Exception e) {
- Console.WriteLine (e);
- }
-
- //System.Console.WriteLine ("saving uri \"{0}\" mtime \"{1}\"",
- // image.GetOption ("tEXt::Thumb::URI"),
- // image.GetOption ("tEXt::Thumb::MTime"));
-
- string large_path = ThumbnailPath (uri);
try {
- ThumbnailCache.Default.RemoveThumbnailForPath (large_path);
+ ThumbnailCache.Default.RemoveThumbnailForUri (uri);
} finally {
- factory.SaveThumbnail (image, uri, mtime);
+ ThumbnailFactory.SaveThumbnail (image, uri);
}
}
@@ -114,10 +80,7 @@
public override void Request (Uri uri, int order, int width, int height)
{
- if (!uri.IsFile)
- Log.Debug ("FIXME: compute timestamp on non file uri too");
- if (uri.IsFile && System.IO.File.Exists (ThumbnailPath (uri))
- && System.IO.File.GetLastWriteTime (ThumbnailPath (uri)) >= System.IO.File.GetLastWriteTime (uri.AbsolutePath))
+ if (ThumbnailFactory.ThumbnailExists (uri) && ThumbnailFactory.ThumbnailIsRecent (uri))
return;
base.Request (uri, order, width, height);
Modified: trunk/src/Widgets/EditorPage.cs
==============================================================================
--- trunk/src/Widgets/EditorPage.cs (original)
+++ trunk/src/Widgets/EditorPage.cs Tue Oct 28 13:56:28 2008
@@ -216,6 +216,7 @@
try {
editor.Apply ();
} catch (Exception e) {
+ Log.DebugException (e);
string msg = Catalog.GetPluralString ("Error saving adjusted photo", "Error saving adjusted photos",
editor.State.Items.Length);
string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Note that you have to develop RAW files into JPEG before you can edit them."),
Modified: trunk/src/Widgets/Filmstrip.cs
==============================================================================
--- trunk/src/Widgets/Filmstrip.cs (original)
+++ trunk/src/Widgets/Filmstrip.cs Tue Oct 28 13:56:28 2008
@@ -18,6 +18,7 @@
using Gdk;
using FSpot.Utils;
+using FSpot.Platform;
namespace FSpot.Widgets
{
@@ -309,7 +310,7 @@
}
FSpot.BrowsablePointer selection;
- DisposableCache<string, Pixbuf> thumb_cache;
+ DisposableCache<Uri, Pixbuf> thumb_cache;
public Filmstrip (FSpot.BrowsablePointer selection) : this (selection, true)
{
@@ -323,7 +324,7 @@
this.selection.Collection.Changed += HandleCollectionChanged;
this.selection.Collection.ItemsChanged += HandleCollectionItemsChanged;
this.squared_thumbs = squared_thumbs;
- thumb_cache = new DisposableCache<string, Pixbuf> (30);
+ thumb_cache = new DisposableCache<Uri, Pixbuf> (30);
ThumbnailGenerator.Default.OnPixbufLoaded += HandlePixbufLoaded;
}
@@ -492,14 +493,14 @@
if (!args.Changes.DataChanged)
return;
foreach (int item in args.Items)
- thumb_cache.TryRemove (FSpot.ThumbnailGenerator.ThumbnailPath ((selection.Collection [item]).DefaultVersionUri));
+ thumb_cache.TryRemove ((selection.Collection [item]).DefaultVersionUri);
//FIXME call QueueDrawArea
QueueDraw ();
}
void HandlePixbufLoaded (PixbufLoader pl, Uri uri, int order, Pixbuf p) {
- if (!thumb_cache.Contains (FSpot.ThumbnailGenerator.ThumbnailPath (uri))) {
+ if (!thumb_cache.Contains (uri)) {
return;
}
@@ -534,13 +535,11 @@
protected virtual Pixbuf GetPixbuf (int i, bool highlighted)
{
- string thumb_path;
Pixbuf current;
+ Uri uri = (selection.Collection [i]).DefaultVersionUri;
try {
- thumb_path = FSpot.ThumbnailGenerator.ThumbnailPath ((selection.Collection [i]).DefaultVersionUri);
- current = PixbufUtils.ShallowCopy (thumb_cache.Get (thumb_path));
+ current = PixbufUtils.ShallowCopy (thumb_cache.Get (uri));
} catch (IndexOutOfRangeException) {
- thumb_path = null;
current = null;
}
@@ -549,18 +548,19 @@
ThumbnailGenerator.Default.Request ((selection.Collection [i]).DefaultVersionUri, 0, 256, 256);
if (SquaredThumbs) {
- current = new Pixbuf (thumb_path);
- current = PixbufUtils.IconFromPixbuf (current, ThumbSize);
+ using (Pixbuf p = ThumbnailFactory.LoadThumbnail (uri)) {
+ current = PixbufUtils.IconFromPixbuf (p, ThumbSize);
+ }
} else
- current = new Pixbuf (thumb_path, -1, ThumbSize);
- thumb_cache.Add (thumb_path, current);
+ current = ThumbnailFactory.LoadThumbnail (uri, -1, ThumbSize);
+ thumb_cache.Add (uri, current);
} catch {
try {
current = FSpot.Global.IconTheme.LoadIcon ("gtk-missing-image", ThumbSize, (Gtk.IconLookupFlags)0);
} catch {
current = null;
}
- thumb_cache.Add (thumb_path, null);
+ thumb_cache.Add (uri, null);
}
}
Modified: trunk/src/Widgets/IconView.cs
==============================================================================
--- trunk/src/Widgets/IconView.cs (original)
+++ trunk/src/Widgets/IconView.cs Tue Oct 28 13:56:28 2008
@@ -15,6 +15,7 @@
using System.Reflection;
using System.Collections;
using System.IO;
+using FSpot.Platform;
namespace FSpot.Widgets
{
@@ -564,8 +565,7 @@
public void UpdateThumbnail (int thumbnail_num)
{
FSpot.IBrowsableItem photo = collection [thumbnail_num];
- string thumbnail_path = FSpot.ThumbnailGenerator.ThumbnailPath (photo.DefaultVersionUri);
- cache.Remove (thumbnail_path);
+ cache.Remove (photo.DefaultVersionUri);
InvalidateCell (thumbnail_num);
}
@@ -772,11 +772,10 @@
return;
FSpot.IBrowsableItem photo = collection [thumbnail_num];
- string thumbnail_path = FSpot.ThumbnailGenerator.ThumbnailPath (photo.DefaultVersionUri);
- FSpot.PixbufCache.CacheEntry entry = cache.Lookup (thumbnail_path);
+ FSpot.PixbufCache.CacheEntry entry = cache.Lookup (photo.DefaultVersionUri);
if (entry == null)
- cache.Request (thumbnail_path, thumbnail_num, ThumbnailWidth, ThumbnailHeight);
+ cache.Request (photo.DefaultVersionUri, thumbnail_num, ThumbnailWidth, ThumbnailHeight);
else
entry.Data = thumbnail_num;
@@ -1157,7 +1156,6 @@
FSpot.IBrowsableItem photo;
FSpot.PixbufCache.CacheEntry entry;
- string thumbnail_path;
// 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
@@ -1179,19 +1177,17 @@
int cell = back ? ecell - i - 1 : scell + mid + i;
photo = collection [cell];
- thumbnail_path = FSpot.ThumbnailGenerator.ThumbnailPath (photo.DefaultVersionUri);
- entry = cache.Lookup (thumbnail_path);
+ entry = cache.Lookup (photo.DefaultVersionUri);
if (entry == null)
- cache.Request (thumbnail_path, cell, ThumbnailWidth, ThumbnailHeight);
+ cache.Request (photo.DefaultVersionUri, cell, ThumbnailWidth, ThumbnailHeight);
cell = back ? scell + i : scell + mid - i - 1;
photo = collection [cell];
- thumbnail_path = FSpot.ThumbnailGenerator.ThumbnailPath (photo.DefaultVersionUri);
- entry = cache.Lookup (thumbnail_path);
+ entry = cache.Lookup (photo.DefaultVersionUri);
if (entry == null)
- cache.Request (thumbnail_path, cell, ThumbnailWidth, ThumbnailHeight);
+ cache.Request (photo.DefaultVersionUri, cell, ThumbnailWidth, ThumbnailHeight);
}
}
@@ -1285,13 +1281,13 @@
if (order >= 0 && order < collection.Count) {
System.Uri uri = collection [order].DefaultVersionUri;
- if (result == null && !System.IO.File.Exists (FSpot.ThumbnailGenerator.ThumbnailPath (uri)))
+ if (result == null && !ThumbnailFactory.ThumbnailExists (uri))
FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
if (result == null)
return;
- if (!FSpot.PhotoLoader.ThumbnailIsValid (uri, result))
+ if (!ThumbnailFactory.ThumbnailIsValid (result, uri))
FSpot.ThumbnailGenerator.Default.Request (uri, 0, 256, 256);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]