fixed thumbnail loader for the new raw preview interface
authorVladimir Nadvornik <nadvornik@suse.cz>
Fri, 29 Aug 2008 09:38:10 +0000 (09:38 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Fri, 29 Aug 2008 09:38:10 +0000 (09:38 +0000)
src/image-load.c
src/image-load.h
src/thumb.c
src/thumb_standard.c

index 2dbf97a..3154fec 100644 (file)
 #include <sys/mman.h>
 
 
-static const gchar *image_loader_path(ImageLoader *il)
-{
-       if (il->fd)
-               return il->fd->path;
-       return il->path;
-}
-
 static void image_loader_sync_pixbuf(ImageLoader *il)
 {
        GdkPixbuf *pb;
@@ -198,7 +191,7 @@ static void image_loader_error(ImageLoader *il)
 {
        image_loader_stop(il);
 
-       DEBUG_1("pixbuf_loader reported load error for: %s", image_loader_path(il));
+       DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path);
 
        if (il->func_error) il->func_error(il, il->data_error);
 }
@@ -319,7 +312,7 @@ static gint image_loader_setup(ImageLoader *il)
                if (il->mapped_file)
                        {
                        il->preview = TRUE;
-                       DEBUG_1("Raw file %s contains embedded image", image_loader_path(il));
+                       DEBUG_1("Raw file %s contains embedded image", il->fd->path);
                        }
                exif_free_fd(il->fd, exif);
                }
@@ -330,7 +323,7 @@ static gint image_loader_setup(ImageLoader *il)
                /* normal file */
                gint load_fd;
        
-               pathl = path_from_utf8(image_loader_path(il));
+               pathl = path_from_utf8(il->fd->path);
                load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
                g_free(pathl);
                if (load_fd == -1) return FALSE;
@@ -369,15 +362,14 @@ static gint image_loader_setup(ImageLoader *il)
        return image_loader_begin(il);
 }
 
-static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path)
+ImageLoader *image_loader_new(FileData *fd)
 {
        ImageLoader *il;
 
-       if (!fd && !path) return NULL;
+       if (!fd) return NULL;
 
        il = g_new0(ImageLoader, 1);
-       if (fd) il->fd = file_data_ref(fd);
-       if (path) il->path = g_strdup(path);
+       il->fd = file_data_ref(fd);
        il->pixbuf = NULL;
        il->idle_id = -1;
        il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
@@ -400,16 +392,6 @@ static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path)
        return il;
 }
 
-ImageLoader *image_loader_new(FileData *fd)
-{
-       return image_loader_new_real(fd, NULL);
-}
-
-ImageLoader *image_loader_new_from_path(const gchar *path)
-{
-       return image_loader_new_real(NULL, path);
-}
-
 void image_loader_free(ImageLoader *il)
 {
        if (!il) return;
@@ -417,8 +399,7 @@ void image_loader_free(ImageLoader *il)
        image_loader_stop(il);
        if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
        if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
-       if (il->fd) file_data_unref(il->fd);
-       if (il->path) g_free(il->path);
+       file_data_unref(il->fd);
        DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
        g_free(il);
 }
@@ -518,7 +499,7 @@ gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpoint
 {
        if (!il) return FALSE;
 
-       if (!image_loader_path(il)) return FALSE;
+       if (!il->fd) return FALSE;
 
        image_loader_set_done_func(il, func_done, data_done);
 
index 2439a0e..effdcbd 100644 (file)
@@ -17,8 +17,6 @@
 
 ImageLoader *image_loader_new(FileData *fd);
 
-/* we don't want full FileData for thumbnails */
-ImageLoader *image_loader_new_from_path(const gchar *path);
 void image_loader_free(ImageLoader *il);
 
 void image_loader_set_area_ready_func(ImageLoader *il,
index 5642353..778d415 100644 (file)
@@ -355,6 +355,7 @@ gint thumb_loader_start(ThumbLoader *tl, FileData *fd)
                                        {
                                        DEBUG_1("Broken image mark found:%s", cache_path);
                                        g_free(cache_path);
+                                       thumb_loader_set_fallback(tl);
                                        return FALSE;
                                        }
 
index 7258bc7..c6ab9ab 100644 (file)
@@ -65,7 +65,8 @@
 
 
 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data);
-static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path);
+static gint thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd);
+static gint thumb_loader_std_setup_path(ThumbLoaderStd *tl, const gchar *path);
 
 
 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height)
@@ -519,7 +520,7 @@ static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
                if (!tl->thumb_path_local)
                        {
                        tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
-                       if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path))
+                       if (isfile(tl->thumb_path) && thumb_loader_std_setup_path(tl, tl->thumb_path))
                                {
                                tl->thumb_path_local = TRUE;
                                return TRUE;
@@ -529,7 +530,7 @@ static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
                        tl->thumb_path = NULL;
                        }
 
-               if (thumb_loader_std_setup(tl, tl->fd->path)) return TRUE;
+               if (thumb_loader_std_setup(tl, tl->fd)) return TRUE;
                }
 
        thumb_loader_std_save(tl, NULL);
@@ -601,9 +602,9 @@ static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpoin
        if (tl->func_progress) tl->func_progress(tl, tl->data);
 }
 
-static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path)
+static gint thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd)
 {
-       tl->il = image_loader_new_from_path(path);
+       tl->il = image_loader_new(fd);
 
        if (options->thumbnails.fast)
                {
@@ -635,6 +636,14 @@ static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path)
        return FALSE;
 }
 
+static gint thumb_loader_std_setup_path(ThumbLoaderStd *tl, const gchar *path)
+{
+       FileData *fd = file_data_new_simple(path);
+       gint ret = thumb_loader_std_setup(tl, fd);
+       file_data_unref(fd);
+       return ret;
+}
+
 /*
  * Note: Currently local_cache only specifies where to save a _new_ thumb, if
  *       a valid existing thumb is found anywhere the local thumb will not be created.
@@ -687,7 +696,7 @@ gint thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd)
                tl->thumb_path_local = FALSE;
 
                found = isfile(tl->thumb_path);
-               if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;
+               if (found && thumb_loader_std_setup_path(tl, tl->thumb_path)) return TRUE;
 
                if (thumb_loader_std_fail_check(tl) ||
                    !thumb_loader_std_next_source(tl, found))
@@ -698,7 +707,7 @@ gint thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd)
                return TRUE;
                }
 
-       if (!thumb_loader_std_setup(tl, tl->fd->path))
+       if (!thumb_loader_std_setup(tl, tl->fd))
                {
                thumb_loader_std_save(tl, NULL);
                thumb_loader_std_set_fallback(tl);
@@ -868,7 +877,7 @@ ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gi
        tv->func_valid = func_valid;
        tv->data = data;
 
-       if (!thumb_loader_std_setup(tv->tl, thumb_path))
+       if (!thumb_loader_std_setup_path(tv->tl, thumb_path))
                {
                tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv);
                }