From c43dfb815a4951b8248f4f0e98babe4f80204f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 3 Apr 2015 13:14:53 +0200 Subject: Imported Upstream version 0.22.0 --- src/ThumbnailCache.vala | 64 +++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'src/ThumbnailCache.vala') diff --git a/src/ThumbnailCache.vala b/src/ThumbnailCache.vala index c24087c..6408a1a 100644 --- a/src/ThumbnailCache.vala +++ b/src/ThumbnailCache.vala @@ -1,4 +1,4 @@ -/* Copyright 2009-2014 Yorba Foundation +/* Copyright 2009-2015 Yorba Foundation * * This software is licensed under the GNU LGPL (version 2.1 or later). * See the COPYING file in this distribution. @@ -86,6 +86,7 @@ public class ThumbnailCache : Object { public Gdk.Pixbuf scaled = null; public Error err = null; public bool fetched = false; + public bool replace = false; public AsyncFetchJob(ThumbnailCache cache, string thumbnail_name, ThumbnailSource source, Gdk.Pixbuf? prefetched, Dimensions dim, @@ -131,38 +132,33 @@ public class ThumbnailCache : Object { // scale if specified scaled = dim.has_area() ? resize_pixbuf(unscaled, dim, interp) : unscaled; } catch (Error err) { - // Is the problem that the thumbnail couldn't be read? If so, it's recoverable; - // we'll just create it and leave this.err as null if creation works. if (err is FileError) { try { - Photo photo = source as Photo; - Video video = source as Video; - - if (photo != null) { - unscaled = photo.get_pixbuf(Scaling.for_best_fit(dim.width, true)); - photo.notify_altered(new Alteration("image","thumbnail")); - return; - } - - if (video != null) { - unscaled = video.create_thumbnail(dim.width); - scaled = resize_pixbuf(unscaled, dim, interp); - cache.save_thumbnail(cache.get_source_cached_file(source), - unscaled, source); - replace(source, cache.size, unscaled); - return; - } - - } catch (Error e) { - // Creating the thumbnail failed; tell the rest of the app. - this.err = e; - return; + generate_thumbnail(); + } catch (Error generr) { + // save thumbnail generation error, not original, for processing in callback + err = generr; } + } else { + // save error for processing in callback + this.err = err; } - - // ...the original error wasn't from reading the file, but something else; - // tell the rest of the app. - this.err = err; + } + } + + private void generate_thumbnail() throws Error { + Photo? photo = source as Photo; + if (photo != null) { + unscaled = photo.get_pixbuf(Scaling.for_best_fit(dim.width, true)); + } else { + Video? video = source as Video; + if (video != null) + unscaled = video.create_thumbnail(dim.width); + } + + if (unscaled != null) { + scaled = resize_pixbuf(unscaled, dim, interp); + replace = true; } } } @@ -420,6 +416,16 @@ public class ThumbnailCache : Object { private static void async_fetch_completion_callback(BackgroundJob background_job) { AsyncFetchJob job = (AsyncFetchJob) background_job; + // Is the problem that the thumbnail couldn't be read? If so, it's recoverable; + // we'll just create it and leave this.err as null if creation works. + if (job.replace && job.unscaled != null) { + try { + replace(job.source, job.cache.size, job.unscaled); + } catch (Error err) { + job.err = err; + } + } + if (job.unscaled != null) { if (job.fetched) { // only store in cache if fetched, not pre-fetched -- cgit v1.2.3