Skip to content

Commit

Permalink
use FileData in thumb_loader
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Jun 15, 2008
1 parent 0d80d51 commit f59f132
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/cache_maint.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static gint cache_manager_render_file(CleanData *cd)
cache_manager_render_thumb_done_cb,
NULL, cd);
thumb_loader_set_cache((ThumbLoader *)cd->tl, TRUE, cd->local, TRUE);
success = thumb_loader_start((ThumbLoader *)cd->tl, fd->path);
success = thumb_loader_start((ThumbLoader *)cd->tl, fd);
if (success)
{
gtk_entry_set_text(GTK_ENTRY(cd->progress), fd->path);
Expand Down
2 changes: 1 addition & 1 deletion src/collect-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void collection_load_thumb_step(CollectionData *cd)
cd);

/* start it */
if (!thumb_loader_start(cd->thumb_loader, ci->fd->path))
if (!thumb_loader_start(cd->thumb_loader, ci->fd))
{
/* error, handle it, do next */
DEBUG_1("error loading thumb for %s", ci->fd->path);
Expand Down
2 changes: 1 addition & 1 deletion src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ static void dupe_thumb_step(DupeWindow *dw)
dw);

/* start it */
if (!thumb_loader_start(dw->thumb_loader, di->fd->path))
if (!thumb_loader_start(dw->thumb_loader, di->fd))
{
/* error, handle it, do next */
DEBUG_1("error loading thumb for %s", di->fd->path);
Expand Down
2 changes: 1 addition & 1 deletion src/pan-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static gint pan_queue_step(PanWindow *pw)
pan_queue_thumb_done_cb,
NULL, pw);

if (thumb_loader_start(pw->tl, pi->fd->path)) return FALSE;
if (thumb_loader_start(pw->tl, pi->fd)) return FALSE;

thumb_loader_free(pw->tl);
pw->tl = NULL;
Expand Down
5 changes: 1 addition & 4 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,6 @@ static void search_result_thumb_do(SearchData *sd)
if (!sd->thumb_loader || !sd->thumb_fd) return;
fd = sd->thumb_fd;

if (fd->pixbuf) g_object_unref(fd->pixbuf);
fd->pixbuf = thumb_loader_get_pixbuf(sd->thumb_loader, TRUE);

search_result_thumb_set(sd, fd, NULL);
}

Expand Down Expand Up @@ -795,7 +792,7 @@ static void search_result_thumb_step(SearchData *sd)
search_result_thumb_done_cb,
NULL,
sd);
if (!thumb_loader_start(sd->thumb_loader, mfd->fd->path))
if (!thumb_loader_start(sd->thumb_loader, mfd->fd))
{
search_result_thumb_do(sd);
search_result_thumb_step(sd);
Expand Down
84 changes: 47 additions & 37 deletions src/thumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


static void thumb_loader_error_cb(ImageLoader *il, gpointer data);
static void thumb_loader_setup(ThumbLoader *tl, gchar *path);
static void thumb_loader_setup(ThumbLoader *tl, const gchar *path);

static gint normalize_thumb(gint *width, gint *height, gint max_w, gint max_h);
static GdkPixbuf *get_xv_thumbnail(gchar *thumb_filename, gint max_w, gint max_h);
Expand All @@ -43,29 +43,29 @@ static gint thumb_loader_save_to_cache(ThumbLoader *tl)
gint success = FALSE;
mode_t mode = 0755;

if (!tl || !tl->pixbuf) return FALSE;
if (!tl || !tl->fd || !tl->fd->pixbuf) return FALSE;

cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->path, FALSE, &mode);
cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->fd->path, FALSE, &mode);

if (cache_ensure_dir_exists(cache_dir, mode))
{
gchar *cache_path;
gchar *pathl;
gchar *name = g_strconcat(filename_from_path(tl->path), GQ_CACHE_EXT_THUMB, NULL);
gchar *name = g_strconcat(filename_from_path(tl->fd->path), GQ_CACHE_EXT_THUMB, NULL);

cache_path = g_build_filename(cache_dir, name, NULL);
g_free(name);

DEBUG_1("Saving thumb: %s", cache_path);

pathl = path_from_utf8(cache_path);
success = pixbuf_to_file_as_png(tl->pixbuf, pathl);
success = pixbuf_to_file_as_png(tl->fd->pixbuf, pathl);
if (success)
{
struct utimbuf ut;
/* set thumb time to that of source file */

ut.actime = ut.modtime = filetime(tl->path);
ut.actime = ut.modtime = filetime(tl->fd->path);
if (ut.modtime > 0)
{
utime(pathl, &ut);
Expand Down Expand Up @@ -93,14 +93,14 @@ static gint thumb_loader_mark_failure(ThumbLoader *tl)

if (!tl) return FALSE;

cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->path, FALSE, &mode);
cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->fd->path, FALSE, &mode);

if (cache_ensure_dir_exists(cache_dir, mode))
{
gchar *cache_path;
gchar *pathl;
FILE *f;
gchar *name = g_strconcat(filename_from_path(tl->path), GQ_CACHE_EXT_THUMB, NULL);
gchar *name = g_strconcat(filename_from_path(tl->fd->path), GQ_CACHE_EXT_THUMB, NULL);

cache_path = g_build_filename(cache_dir, name, NULL);
g_free(name);
Expand All @@ -115,7 +115,7 @@ static gint thumb_loader_mark_failure(ThumbLoader *tl)

fclose(f);

ut.actime = ut.modtime = filetime(tl->path);
ut.actime = ut.modtime = filetime(tl->fd->path);
if (ut.modtime > 0)
{
utime(pathl, &ut);
Expand Down Expand Up @@ -148,12 +148,12 @@ static void thumb_loader_done_cb(ImageLoader *il, gpointer data)
gint pw, ph;
gint save;

DEBUG_1("thumb done: %s", tl->path);
DEBUG_1("thumb done: %s", tl->fd->path);

pixbuf = image_loader_get_pixbuf(tl->il);
if (!pixbuf)
{
DEBUG_1("...but no pixbuf: %s", tl->path);
DEBUG_1("...but no pixbuf: %s", tl->fd->path);
thumb_loader_error_cb(tl->il, tl);
return;
}
Expand All @@ -164,17 +164,17 @@ static void thumb_loader_done_cb(ImageLoader *il, gpointer data)
if (tl->cache_hit && pw != tl->max_w && ph != tl->max_h)
{
/* requested thumbnail size may have changed, load original */
DEBUG_1("thumbnail size mismatch, regenerating: %s", tl->path);
DEBUG_1("thumbnail size mismatch, regenerating: %s", tl->fd->path);
tl->cache_hit = FALSE;

thumb_loader_setup(tl, tl->path);
thumb_loader_setup(tl, tl->fd->path);

if (!image_loader_start(tl->il, thumb_loader_done_cb, tl))
{
image_loader_free(tl->il);
tl->il = NULL;

DEBUG_1("regeneration failure: %s", tl->path);
DEBUG_1("regeneration failure: %s", tl->fd->path);
thumb_loader_error_cb(tl->il, tl);
}
return;
Expand All @@ -198,14 +198,22 @@ static void thumb_loader_done_cb(ImageLoader *il, gpointer data)
w = (double)h / ph * pw;
if (w < 1) w = 1;
}

tl->pixbuf = gdk_pixbuf_scale_simple(pixbuf, w, h, (GdkInterpType)options->thumbnails.quality);

if (tl->fd)
{
if (tl->fd->pixbuf) g_object_unref(tl->fd->pixbuf);
tl->fd->pixbuf = gdk_pixbuf_scale_simple(pixbuf, w, h, (GdkInterpType)options->thumbnails.quality);
}
save = TRUE;
}
else
{
tl->pixbuf = pixbuf;
gdk_pixbuf_ref(tl->pixbuf);
if (tl->fd)
{
if (tl->fd->pixbuf) g_object_unref(tl->fd->pixbuf);
tl->fd->pixbuf = pixbuf;
gdk_pixbuf_ref(tl->fd->pixbuf);
}
save = il->shrunk;
}

Expand All @@ -229,7 +237,7 @@ static void thumb_loader_error_cb(ImageLoader *il, gpointer data)
return;
}

DEBUG_1("thumb error: %s", tl->path);
DEBUG_1("thumb error: %s", tl->fd->path);

image_loader_free(tl->il);
tl->il = NULL;
Expand All @@ -253,10 +261,12 @@ static void thumb_loader_delay_done(ThumbLoader *tl)
if (tl->idle_done_id == -1) tl->idle_done_id = g_idle_add(thumb_loader_done_delay_cb, tl);
}

static void thumb_loader_setup(ThumbLoader *tl, gchar *path)
static void thumb_loader_setup(ThumbLoader *tl, const gchar *path)
{
FileData *fd = file_data_new_simple(path);
image_loader_free(tl->il);
tl->il = image_loader_new(file_data_new_simple(path));
tl->il = image_loader_new(fd);
file_data_unref(fd);

if (options->thumbnails.fast)
{
Expand Down Expand Up @@ -311,30 +321,30 @@ void thumb_loader_set_cache(ThumbLoader *tl, gint enable_cache, gint local, gint
}


gint thumb_loader_start(ThumbLoader *tl, const gchar *path)
gint thumb_loader_start(ThumbLoader *tl, FileData *fd)
{
gchar *cache_path = NULL;

if (!tl) return FALSE;

if (tl->standard_loader)
{
return thumb_loader_std_start((ThumbLoaderStd *)tl, path);
return thumb_loader_std_start((ThumbLoaderStd *)tl, fd);
}

if (!tl->path && !path) return FALSE;
if (!tl->fd && !fd) return FALSE;

if (!tl->path) tl->path = g_strdup(path);
if (!tl->fd) tl->fd = file_data_ref(fd);

if (tl->cache_enable)
{
cache_path = cache_find_location(CACHE_TYPE_THUMB, tl->path);
cache_path = cache_find_location(CACHE_TYPE_THUMB, tl->fd->path);

if (cache_path)
{
if (cache_time_valid(cache_path, tl->path))
if (cache_time_valid(cache_path, tl->fd->path))
{
DEBUG_1("Found in cache:%s", tl->path);
DEBUG_1("Found in cache:%s", tl->fd->path);

if (filesize(cache_path) == 0)
{
Expand All @@ -355,8 +365,9 @@ gint thumb_loader_start(ThumbLoader *tl, const gchar *path)

if (!cache_path && options->thumbnails.use_xvpics)
{
tl->pixbuf = get_xv_thumbnail(tl->path, tl->max_w, tl->max_h);
if (tl->pixbuf)
if (tl->fd->pixbuf) g_object_unref(tl->fd->pixbuf);
tl->fd->pixbuf = get_xv_thumbnail(tl->fd->path, tl->max_w, tl->max_h);
if (tl->fd->pixbuf)
{
thumb_loader_delay_done(tl);
return TRUE;
Expand All @@ -371,7 +382,7 @@ gint thumb_loader_start(ThumbLoader *tl, const gchar *path)
}
else
{
thumb_loader_setup(tl, tl->path);
thumb_loader_setup(tl, tl->fd->path);
}

if (!image_loader_start(tl->il, thumb_loader_done_cb, tl))
Expand All @@ -382,7 +393,7 @@ gint thumb_loader_start(ThumbLoader *tl, const gchar *path)
tl->cache_hit = FALSE;
log_printf("%s", _("Thumbnail image in cache failed to load, trying to recreate.\n"));

thumb_loader_setup(tl, tl->path);
thumb_loader_setup(tl, tl->fd->path);
if (image_loader_start(tl->il, thumb_loader_done_cb, tl)) return TRUE;
}
/* mark failed thumbnail in cache with 0 byte file */
Expand Down Expand Up @@ -419,9 +430,9 @@ GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl, gint with_fallback)
return thumb_loader_std_get_pixbuf((ThumbLoaderStd *)tl, with_fallback);
}

if (tl && tl->pixbuf)
if (tl && tl->fd && tl->fd->pixbuf)
{
pixbuf = tl->pixbuf;
pixbuf = tl->fd->pixbuf;
g_object_ref(pixbuf);
}
else if (with_fallback)
Expand Down Expand Up @@ -471,7 +482,7 @@ ThumbLoader *thumb_loader_new(gint width, gint height)

tl = g_new0(ThumbLoader, 1);
tl->standard_loader = FALSE;
tl->path = NULL;
tl->fd = NULL;
tl->cache_enable = options->thumbnails.enable_caching;
tl->cache_hit = FALSE;
tl->percent_done = 0.0;
Expand All @@ -495,9 +506,8 @@ void thumb_loader_free(ThumbLoader *tl)
return;
}

if (tl->pixbuf) gdk_pixbuf_unref(tl->pixbuf);
image_loader_free(tl->il);
g_free(tl->path);
file_data_unref(tl->fd);

if (tl->idle_done_id != -1) g_source_remove(tl->idle_done_id);

Expand Down
2 changes: 1 addition & 1 deletion src/thumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void thumb_loader_set_callbacks(ThumbLoader *tl,
gpointer data);
void thumb_loader_set_cache(ThumbLoader *tl, gint enable_cache, gint local, gint retry_failed);

gint thumb_loader_start(ThumbLoader *tl, const gchar *path);
gint thumb_loader_start(ThumbLoader *tl, FileData *fd);
void thumb_loader_free(ThumbLoader *tl);

GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl, gint with_fallback);
Expand Down
Loading

0 comments on commit f59f132

Please sign in to comment.