Krolyxon
Commit 83bdf67

Branches

Refs →

nsxiv83bdf67

First things for thumbnail caching

Author
Bert
Date
2011-04-07 01:26 +0200
Parent
9fcf2c8
Commit
83bdf67d51c3f7ae996886c56556afe2a7f462e3

+34 −0

2 files changed

  1. M thumbs.c +33 −0
  2. M thumbs.h +1 −0
M thumbs.c View
@@ -18,6 +18,9 @@
1818
1919 #include <stdlib.h>
2020 #include <string.h>
21+#include <sys/types.h>
22+#include <sys/stat.h>
23+#include <unistd.h>
2124
2225 #include "config.h"
2326 #include "thumbs.h"
@@ -26,6 +29,9 @@
2629 extern Imlib_Image *im_invalid;
2730 const int thumb_dim = THUMB_SIZE + 10;
2831
32+int tns_cache_enabled();
33+void tns_cache_write(thumb_t*, Bool);
34+
2935 void tns_init(tns_t *tns, int cnt) {
3036 if (!tns)
3137 return;
@@ -39,12 +45,17 @@ void tns_init(tns_t *tns, int cnt) {
3945
4046 void tns_free(tns_t *tns, win_t *win) {
4147 int i;
48+ Bool cache;
4249
4350 if (!tns || !tns->thumbs)
4451 return;
4552
53+ cache = tns_cache_enabled();
54+
4655 for (i = 0; i < tns->cnt; ++i) {
4756 if (tns->thumbs[i].im) {
57+ if (cache)
58+ tns_cache_write(&tns->thumbs[i], False);
4859 imlib_context_set_image(tns->thumbs[i].im);
4960 imlib_free_image();
5061 }
@@ -84,10 +95,12 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
8495 h = imlib_image_get_height();
8596
8697 if (im) {
98+ t->filename = filename;
8799 zw = (float) THUMB_SIZE / (float) w;
88100 zh = (float) THUMB_SIZE / (float) h;
89101 z = MIN(zw, zh);
90102 } else {
103+ t->filename = NULL;
91104 z = 1.0;
92105 }
93106
@@ -278,3 +291,23 @@ int tns_translate(tns_t *tns, int x, int y) {
278291
279292 return -1;
280293 }
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+}
M thumbs.h View
@@ -32,6 +32,7 @@ typedef enum {
3232
3333 typedef struct {
3434 Imlib_Image *im;
35+ const char *filename;
3536 int x;
3637 int y;
3738 int w;