Write cache file for thumbnail directly after creating it

This commit is contained in:
Bert 2011-04-07 16:17:10 +02:00
parent 1d0f51f95a
commit f93f4d887c
2 changed files with 12 additions and 10 deletions

View file

@ -47,17 +47,12 @@ void tns_init(tns_t *tns, int cnt) {
void tns_free(tns_t *tns, win_t *win) { void tns_free(tns_t *tns, win_t *win) {
int i; int i;
Bool cache;
if (!tns || !tns->thumbs) if (!tns || !tns->thumbs)
return; return;
cache = tns_cache_enabled();
for (i = 0; i < tns->cnt; ++i) { for (i = 0; i < tns->cnt; ++i) {
if (tns->thumbs[i].im) { if (tns->thumbs[i].im) {
if (cache)
tns_cache_write(&tns->thumbs[i], False);
imlib_context_set_image(tns->thumbs[i].im); imlib_context_set_image(tns->thumbs[i].im);
imlib_free_image(); imlib_free_image();
} }
@ -69,6 +64,7 @@ void tns_free(tns_t *tns, win_t *win) {
void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
int w, h; int w, h;
int use_cache, cached = 0;
float z, zw, zh; float z, zw, zh;
thumb_t *t; thumb_t *t;
Imlib_Image *im; Imlib_Image *im;
@ -88,8 +84,12 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
imlib_free_image(); imlib_free_image();
} }
if ((tns_cache_enabled() && (im = tns_cache_load(filename))) || if ((use_cache = tns_cache_enabled())) {
(im = imlib_load_image(filename))) if ((im = tns_cache_load(filename)))
cached = 1;
}
if (cached || (im = imlib_load_image(filename)))
imlib_context_set_image(im); imlib_context_set_image(im);
else else
imlib_context_set_image(im_invalid); imlib_context_set_image(im_invalid);
@ -115,6 +115,8 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
die("could not allocate memory"); die("could not allocate memory");
if (im) if (im)
imlib_free_image_and_decache(); imlib_free_image_and_decache();
if (use_cache && !cached)
tns_cache_write(t, False);
tns->dirty = 1; tns->dirty = 1;
} }
@ -334,7 +336,7 @@ char* tns_cache_filename(const char *filename) {
} }
len = strlen(abspath); len = strlen(abspath);
for (i = 1; i < len; ++i) { for (i = 0; i < len; ++i) {
if (abspath[i] == '/') if (abspath[i] == '/')
abspath[i] = '%'; abspath[i] = '%';
} }
@ -392,7 +394,7 @@ void tns_cache_write(thumb_t *t, Bool force) {
imlib_save_image_with_error_return(cfile, &err); imlib_save_image_with_error_return(cfile, &err);
if (err) { if (err) {
warn("could not cache thumbnail:", t->filename); warn("could not cache thumbnail: %s", t->filename);
} else { } else {
TIMESPEC_TO_TIMEVAL(&times[0], &fstats.st_atim); TIMESPEC_TO_TIMEVAL(&times[0], &fstats.st_atim);
TIMESPEC_TO_TIMEVAL(&times[1], &fstats.st_mtim); TIMESPEC_TO_TIMEVAL(&times[1], &fstats.st_mtim);

2
util.c
View file

@ -123,7 +123,7 @@ char* absolute_path(const char *filename) {
twd = (char*) s_realloc(twd, len); twd = (char*) s_realloc(twd, len);
} }
if (chdir(cwd)) if (chdir(cwd))
die("could not revert to working directory"); die("could not revert to prior working directory");
if (!s) if (!s)
goto error; goto error;
dir = twd; dir = twd;