nsxiv83bdf67
First things for thumbnail caching
+34 −0
2 files changed
| @@ -18,6 +18,9 @@ | |||
| 18 | 18 | ||
| 19 | 19 | #include <stdlib.h> | |
| 20 | 20 | #include <string.h> | |
| 21 | + | #include <sys/types.h> | |
| 22 | + | #include <sys/stat.h> | |
| 23 | + | #include <unistd.h> | |
| 21 | 24 | ||
| 22 | 25 | #include "config.h" | |
| 23 | 26 | #include "thumbs.h" | |
| @@ -26,6 +29,9 @@ | |||
| 26 | 29 | extern Imlib_Image *im_invalid; | |
| 27 | 30 | const int thumb_dim = THUMB_SIZE + 10; | |
| 28 | 31 | ||
| 32 | + | int tns_cache_enabled(); | |
| 33 | + | void tns_cache_write(thumb_t*, Bool); | |
| 34 | + | ||
| 29 | 35 | void tns_init(tns_t *tns, int cnt) { | |
| 30 | 36 | if (!tns) | |
| 31 | 37 | return; | |
| @@ -39,12 +45,17 @@ void tns_init(tns_t *tns, int cnt) { | |||
| 39 | 45 | ||
| 40 | 46 | void tns_free(tns_t *tns, win_t *win) { | |
| 41 | 47 | int i; | |
| 48 | + | Bool cache; | |
| 42 | 49 | ||
| 43 | 50 | if (!tns || !tns->thumbs) | |
| 44 | 51 | return; | |
| 45 | 52 | ||
| 53 | + | cache = tns_cache_enabled(); | |
| 54 | + | ||
| 46 | 55 | for (i = 0; i < tns->cnt; ++i) { | |
| 47 | 56 | if (tns->thumbs[i].im) { | |
| 57 | + | if (cache) | |
| 58 | + | tns_cache_write(&tns->thumbs[i], False); | |
| 48 | 59 | imlib_context_set_image(tns->thumbs[i].im); | |
| 49 | 60 | imlib_free_image(); | |
| 50 | 61 | } | |
| @@ -84,10 +95,12 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 84 | 95 | h = imlib_image_get_height(); | |
| 85 | 96 | ||
| 86 | 97 | if (im) { | |
| 98 | + | t->filename = filename; | |
| 87 | 99 | zw = (float) THUMB_SIZE / (float) w; | |
| 88 | 100 | zh = (float) THUMB_SIZE / (float) h; | |
| 89 | 101 | z = MIN(zw, zh); | |
| 90 | 102 | } else { | |
| 103 | + | t->filename = NULL; | |
| 91 | 104 | z = 1.0; | |
| 92 | 105 | } | |
| 93 | 106 | ||
| @@ -278,3 +291,23 @@ int tns_translate(tns_t *tns, int x, int y) { | |||
| 278 | 291 | ||
| 279 | 292 | return -1; | |
| 280 | 293 | } | |
| 294 | + | ||
| 295 | + | int tns_cache_enabled() { | |
| 296 | + | int len, ret = 0; | |
| 297 | + | char *cpath, *homedir; | |
| 298 | + | struct stat stats; | |
| 299 | + | ||
| 300 | + | if ((homedir = getenv("HOME"))) { | |
| 301 | + | len = strlen(homedir) + 10; | |
| 302 | + | cpath = (char*) s_malloc(len * sizeof(char)); | |
| 303 | + | snprintf(cpath, len, "%s/.sxiv", homedir); | |
| 304 | + | ret = !stat(cpath, &stats) && S_ISDIR(stats.st_mode) && | |
| 305 | + | !access(cpath, W_OK); | |
| 306 | + | free(cpath); | |
| 307 | + | } | |
| 308 | + | ||
| 309 | + | return ret; | |
| 310 | + | } | |
| 311 | + | ||
| 312 | + | void tns_cache_write(thumb_t *t, Bool force) { | |
| 313 | + | } | |
| @@ -32,6 +32,7 @@ typedef enum { | |||
| 32 | 32 | ||
| 33 | 33 | typedef struct { | |
| 34 | 34 | Imlib_Image *im; | |
| 35 | + | const char *filename; | |
| 35 | 36 | int x; | |
| 36 | 37 | int y; | |
| 37 | 38 | int w; | |