Krolyxon
Commit f93f4d8

Branches

Refs →

nsxivf93f4d8

Write cache file for thumbnail directly after creating it

Author
Bert
Date
2011-04-07 16:17 +0200
Parent
1d0f51f
Commit
f93f4d887cb17fe4d7e702cbf71a4f10b851b32f

+12 −10

2 files changed

  1. M thumbs.c +11 −9
  2. M util.c +1 −1
M thumbs.c View
@@ -47,17 +47,12 @@ void tns_init(tns_t *tns, int cnt) {
4747
4848 void tns_free(tns_t *tns, win_t *win) {
4949 int i;
50− Bool cache;
5150
5251 if (!tns || !tns->thumbs)
5352 return;
5453
55− cache = tns_cache_enabled();
56−
5754 for (i = 0; i < tns->cnt; ++i) {
5855 if (tns->thumbs[i].im) {
59− if (cache)
60− tns_cache_write(&tns->thumbs[i], False);
6156 imlib_context_set_image(tns->thumbs[i].im);
6257 imlib_free_image();
6358 }
@@ -69,6 +64,7 @@ void tns_free(tns_t *tns, win_t *win) {
6964
7065 void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
7166 int w, h;
67+ int use_cache, cached = 0;
7268 float z, zw, zh;
7369 thumb_t *t;
7470 Imlib_Image *im;
@@ -88,8 +84,12 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
8884 imlib_free_image();
8985 }
9086
91− if ((tns_cache_enabled() && (im = tns_cache_load(filename))) ||
92− (im = imlib_load_image(filename)))
87+ if ((use_cache = tns_cache_enabled())) {
88+ if ((im = tns_cache_load(filename)))
89+ cached = 1;
90+ }
91+
92+ if (cached || (im = imlib_load_image(filename)))
9393 imlib_context_set_image(im);
9494 else
9595 imlib_context_set_image(im_invalid);
@@ -115,6 +115,8 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
115115 die("could not allocate memory");
116116 if (im)
117117 imlib_free_image_and_decache();
118+ if (use_cache && !cached)
119+ tns_cache_write(t, False);
118120
119121 tns->dirty = 1;
120122 }
@@ -334,7 +336,7 @@ char* tns_cache_filename(const char *filename) {
334336 }
335337
336338 len = strlen(abspath);
337− for (i = 1; i < len; ++i) {
339+ for (i = 0; i < len; ++i) {
338340 if (abspath[i] == '/')
339341 abspath[i] = '%';
340342 }
@@ -392,7 +394,7 @@ void tns_cache_write(thumb_t *t, Bool force) {
392394 imlib_save_image_with_error_return(cfile, &err);
393395
394396 if (err) {
395− warn("could not cache thumbnail:", t->filename);
397+ warn("could not cache thumbnail: %s", t->filename);
396398 } else {
397399 TIMESPEC_TO_TIMEVAL(&times[0], &fstats.st_atim);
398400 TIMESPEC_TO_TIMEVAL(&times[1], &fstats.st_mtim);
M util.c View
@@ -123,7 +123,7 @@ char* absolute_path(const char *filename) {
123123 twd = (char*) s_realloc(twd, len);
124124 }
125125 if (chdir(cwd))
126− die("could not revert to working directory");
126+ die("could not revert to prior working directory");
127127 if (!s)
128128 goto error;
129129 dir = twd;