Krolyxon
Commit e49d38d

Branches

Refs →

nsxive49d38d

Fixed wrong thumbnail-to-file mappings caused by file deletions

Author
Bert Münnich
Date
2014-08-16 22:21 +0200
Parent
e267dc7
Commit
e49d38d6f947b11570627b7354641e03f9200cef

+24 −22

4 files changed

  1. M commands.c +3 −3
  2. M main.c +4 −4
  3. M thumbs.c +14 −12
  4. M thumbs.h +3 −3
M commands.c View
@@ -77,7 +77,7 @@ bool cg_switch_mode(arg_t a)
7777 {
7878 if (mode == MODE_IMAGE) {
7979 if (tns.thumbs == NULL)
80− tns_init(&tns, filecnt, &win, &fileidx);
80+ tns_init(&tns, files, filecnt, &fileidx, &win);
8181 img_close(&img, false);
8282 reset_timeout(reset_cursor);
8383 if (img.ss.on) {
@@ -130,7 +130,7 @@ bool cg_reload_image(arg_t a)
130130 load_image(fileidx);
131131 } else {
132132 win_set_cursor(&win, CURSOR_WATCH);
133− if (!tns_load(&tns, fileidx, &files[fileidx], true)) {
133+ if (!tns_load(&tns, fileidx, true)) {
134134 remove_file(fileidx, false);
135135 tns.dirty = true;
136136 }
@@ -456,7 +456,7 @@ bool ct_move_sel(arg_t a)
456456 bool ct_reload_all(arg_t a)
457457 {
458458 tns_free(&tns);
459− tns_init(&tns, filecnt, &win, &fileidx);
459+ tns_init(&tns, files, filecnt, &fileidx, &win);
460460 return false;
461461 }
462462
M main.c View
@@ -679,7 +679,7 @@ void run(void)
679679 /* load thumbnails */
680680 reload = tns.loadnext != tns.cnt;
681681 set_timeout(redraw, TO_REDRAW_THUMBS, false);
682− if (tns_load(&tns, tns.loadnext, &files[tns.loadnext], reload)) {
682+ if (tns_load(&tns, tns.loadnext, reload)) {
683683 if (!reload)
684684 tns.cnt++;
685685 } else {
@@ -783,7 +783,7 @@ int main(int argc, char **argv)
783783 parse_options(argc, argv);
784784
785785 if (options->clean_cache) {
786− tns_init(&tns, 0, NULL, NULL);
786+ tns_init(&tns, NULL, 0, NULL, NULL);
787787 tns_clean_cache(&tns);
788788 exit(EXIT_SUCCESS);
789789 }
@@ -876,8 +876,8 @@ int main(int argc, char **argv)
876876
877877 if (options->thumb_mode) {
878878 mode = MODE_THUMB;
879− tns_init(&tns, filecnt, &win, &fileidx);
880− while (!tns_load(&tns, 0, &files[0], false))
879+ tns_init(&tns, files, filecnt, &fileidx, &win);
880+ while (!tns_load(&tns, 0, false))
881881 remove_file(0, false);
882882 tns.cnt = 1;
883883 } else {
M thumbs.c View
@@ -75,7 +75,7 @@ Imlib_Image tns_cache_load(const char *filepath)
7575 return im;
7676 }
7777
78−void tns_cache_write(thumb_t *t, bool force)
78+void tns_cache_write(thumb_t *t, const fileinfo_t *file, bool force)
7979 {
8080 char *cfile, *dirend;
8181 struct stat cstats, fstats;
@@ -84,12 +84,12 @@ void tns_cache_write(thumb_t *t, bool force)
8484
8585 if (t == NULL || t->im == NULL)
8686 return;
87− if (t->file == NULL || t->file->name == NULL || t->file->path == NULL)
87+ if (file == NULL || file->name == NULL || file->path == NULL)
8888 return;
89− if (stat(t->file->path, &fstats) < 0)
89+ if (stat(file->path, &fstats) < 0)
9090 return;
9191
92− if ((cfile = tns_cache_filepath(t->file->path)) != NULL) {
92+ if ((cfile = tns_cache_filepath(file->path)) != NULL) {
9393 if (force || stat(cfile, &cstats) < 0 ||
9494 cstats.st_mtime != fstats.st_mtime)
9595 {
@@ -150,7 +150,7 @@ void tns_clean_cache(tns_t *tns)
150150 }
151151
152152
153−void tns_init(tns_t *tns, int cnt, win_t *win, int *sel)
153+void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win)
154154 {
155155 int len;
156156 const char *homedir, *dsuffix = "";
@@ -164,6 +164,7 @@ void tns_init(tns_t *tns, int cnt, win_t *win, int *sel)
164164 } else {
165165 tns->thumbs = NULL;
166166 }
167+ tns->files = files;
167168 tns->cap = cnt;
168169 tns->cnt = tns->loadnext = tns->first = 0;
169170 tns->sel = sel;
@@ -209,23 +210,24 @@ void tns_free(tns_t *tns)
209210 }
210211 }
211212
212−bool tns_load(tns_t *tns, int n, const fileinfo_t *file, bool force)
213+bool tns_load(tns_t *tns, int n, bool force)
213214 {
214215 int w, h;
215216 bool cache_hit = false;
216217 float z, zw, zh;
217218 thumb_t *t;
218219 Imlib_Image im = NULL;
220+ const fileinfo_t *file;
219221
220222 if (tns == NULL || tns->thumbs == NULL)
221223 return false;
222− if (file == NULL || file->name == NULL || file->path == NULL)
223− return false;
224224 if (n < 0 || n >= tns->cap)
225225 return false;
226+ file = &tns->files[n];
227+ if (file->name == NULL || file->path == NULL)
228+ return false;
226229
227230 t = &tns->thumbs[n];
228− t->file = file;
229231
230232 if (t->im != NULL) {
231233 imlib_context_set_image(t->im);
@@ -322,7 +324,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, bool force)
322324 imlib_free_image_and_decache();
323325
324326 if (!cache_hit)
325− tns_cache_write(t, true);
327+ tns_cache_write(t, file, true);
326328
327329 t->loaded = true;
328330 tns->dirty = true;
@@ -398,7 +400,7 @@ void tns_render(tns_t *tns)
398400 imlib_context_set_image(t->im);
399401 imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
400402 t->x, t->y, t->w, t->h);
401− if (t->file->marked)
403+ if (tns->files[tns->first + i].marked)
402404 tns_mark(tns, tns->first + i, true);
403405 if ((i + 1) % tns->cols == 0) {
404406 x = tns->x;
@@ -460,7 +462,7 @@ void tns_highlight(tns_t *tns, int n, bool hl)
460462 win_draw_rect(win, win->buf.pm, t->x - 3, t->y - 3, t->w + 6, t->h + 6,
461463 false, 2, col);
462464
463− if (!hl && t->file->marked)
465+ if (!hl && tns->files[n].marked)
464466 tns_mark(tns, n, true);
465467 }
466468 }
M thumbs.h View
@@ -26,7 +26,6 @@
2626 #include "window.h"
2727
2828 typedef struct {
29− const fileinfo_t *file;
3029 Imlib_Image im;
3130 int w;
3231 int h;
@@ -36,6 +35,7 @@ typedef struct {
3635 } thumb_t;
3736
3837 typedef struct {
38+ const fileinfo_t *files;
3939 thumb_t *thumbs;
4040 int cap;
4141 int cnt;
@@ -54,10 +54,10 @@ typedef struct {
5454
5555 void tns_clean_cache(tns_t*);
5656
57−void tns_init(tns_t*, int, win_t*, int*);
57+void tns_init(tns_t*, const fileinfo_t*, int, int*, win_t*);
5858 void tns_free(tns_t*);
5959
60−bool tns_load(tns_t*, int, const fileinfo_t*, bool);
60+bool tns_load(tns_t*, int, bool);
6161
6262 void tns_render(tns_t*);
6363 void tns_mark(tns_t*, int, bool);