2005-10-18 16:03:36 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "e.h"
|
|
|
|
|
|
|
|
static char *_e_thumb_file_id(char *file);
|
|
|
|
|
|
|
|
static char *thumb_path = NULL;
|
|
|
|
|
|
|
|
int
|
|
|
|
e_thumb_init(void)
|
|
|
|
{
|
|
|
|
char *homedir;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
homedir = e_user_homedir_get();
|
|
|
|
if (homedir)
|
|
|
|
{
|
|
|
|
snprintf(path, sizeof(path), "%s/.e/e/fileman/thumbnails", homedir);
|
|
|
|
if (!ecore_file_exists(path))
|
|
|
|
ecore_file_mkpath(path);
|
|
|
|
thumb_path = strdup(path);
|
|
|
|
free(homedir);
|
|
|
|
}
|
|
|
|
else return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
e_thumb_shutdown(void)
|
|
|
|
{
|
2005-10-19 05:17:42 -07:00
|
|
|
E_FREE(thumb_path);
|
2005-10-18 16:03:36 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* return dir where thumbs are saved */
|
2005-10-18 16:03:36 -07:00
|
|
|
char *
|
|
|
|
e_thumb_dir_get(void)
|
|
|
|
{
|
|
|
|
return strdup(thumb_path);
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* return hashed path of thumb */
|
2005-10-18 16:03:36 -07:00
|
|
|
char *
|
|
|
|
e_thumb_file_get(char *file)
|
|
|
|
{
|
|
|
|
char *id;
|
|
|
|
char thumb[PATH_MAX];
|
|
|
|
|
|
|
|
id = _e_thumb_file_id(file);
|
2005-10-20 06:08:51 -07:00
|
|
|
if(!id) { return NULL; }
|
2005-10-18 16:03:36 -07:00
|
|
|
snprintf(thumb, sizeof(thumb), "%s/%s", thumb_path, id);
|
|
|
|
free(id);
|
|
|
|
return strdup(thumb);
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* check wether a file has a saved thumb */
|
2005-10-18 16:03:36 -07:00
|
|
|
int
|
|
|
|
e_thumb_exists(char *file)
|
|
|
|
{
|
|
|
|
char *thumb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
thumb = e_thumb_file_get(file);
|
|
|
|
ret = ecore_file_exists(thumb);
|
|
|
|
free(thumb);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* create and save a thumb to disk */
|
2005-10-18 16:03:36 -07:00
|
|
|
int
|
|
|
|
e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
|
|
|
|
{
|
|
|
|
Eet_File *ef;
|
|
|
|
char *thumbpath;
|
|
|
|
Evas_Object *im;
|
|
|
|
const int *data;
|
2005-10-20 08:07:45 -07:00
|
|
|
int size, iw, ih, ww, hh;
|
2005-10-18 16:03:36 -07:00
|
|
|
Ecore_Evas *buf;
|
|
|
|
Evas *evasbuf;
|
2005-10-20 08:07:45 -07:00
|
|
|
int alpha;
|
2005-10-18 16:03:36 -07:00
|
|
|
|
|
|
|
thumbpath = e_thumb_file_get(file);
|
2005-10-20 08:07:45 -07:00
|
|
|
if (!thumbpath)
|
|
|
|
{
|
|
|
|
free(thumbpath);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-21 02:25:23 -07:00
|
|
|
buf = ecore_evas_buffer_new(1, 1);
|
2005-10-18 16:03:36 -07:00
|
|
|
evasbuf = ecore_evas_get(buf);
|
|
|
|
im = evas_object_image_add(evasbuf);
|
|
|
|
evas_object_image_file_set(im, file, NULL);
|
2005-10-20 08:07:45 -07:00
|
|
|
iw = 0; ih = 0;
|
|
|
|
evas_object_image_size_get(im, &iw, &ih);
|
|
|
|
alpha = evas_object_image_alpha_get(im);
|
2005-10-21 02:25:23 -07:00
|
|
|
if ((iw > 0) && (ih > 0))
|
2005-10-20 08:07:45 -07:00
|
|
|
{
|
2005-10-21 02:25:23 -07:00
|
|
|
ef = eet_open(thumbpath, EET_FILE_MODE_WRITE);
|
|
|
|
if (!ef)
|
|
|
|
{
|
|
|
|
free(thumbpath);
|
|
|
|
evas_object_del(im);
|
|
|
|
ecore_evas_free(buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(thumbpath);
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-21 02:25:23 -07:00
|
|
|
ww = w;
|
|
|
|
hh = (w * ih) / iw;
|
|
|
|
if (hh > h)
|
|
|
|
{
|
|
|
|
hh = h;
|
|
|
|
ww = (h * iw) / ih;
|
|
|
|
}
|
|
|
|
ecore_evas_resize(buf, ww, hh);
|
|
|
|
evas_object_image_fill_set(im, 0, 0, ww, hh);
|
|
|
|
evas_object_resize(im, ww, hh);
|
|
|
|
evas_object_show(im);
|
|
|
|
data = ecore_evas_buffer_pixels_get(buf);
|
|
|
|
|
|
|
|
eet_write(ef, "/thumbnail/orig_path", file, strlen(file), 1);
|
|
|
|
if ((size = eet_data_image_write(ef, "/thumbnail/data",
|
|
|
|
(void *)data, ww, hh, alpha,
|
|
|
|
0, 91, 1)) <= 0)
|
|
|
|
{
|
|
|
|
evas_object_del(im);
|
|
|
|
ecore_evas_free(buf);
|
|
|
|
eet_close(ef);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eet_close(ef);
|
|
|
|
}
|
2005-10-20 08:07:45 -07:00
|
|
|
evas_object_del(im);
|
2005-10-18 16:03:36 -07:00
|
|
|
ecore_evas_free(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* get evas object containing image of the thumb */
|
2005-10-18 16:03:36 -07:00
|
|
|
Evas_Object *
|
|
|
|
e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord height)
|
|
|
|
{
|
|
|
|
Eet_File *ef;
|
|
|
|
char *thumb, *ext;
|
|
|
|
Evas_Object *im = NULL;
|
|
|
|
void *data;
|
|
|
|
unsigned int w, h;
|
|
|
|
int a, c, q, l;
|
|
|
|
|
|
|
|
#define DEF_THUMB_RETURN im = evas_object_rectangle_add(evas); \
|
|
|
|
evas_object_color_set(im, 255, 255, 255, 255); \
|
|
|
|
evas_object_resize(im, width, height); \
|
|
|
|
return im
|
|
|
|
|
|
|
|
/* eap thumbnailer */
|
|
|
|
ext = strrchr(file, '.');
|
|
|
|
if(ext)
|
|
|
|
{
|
|
|
|
if(!strcasecmp(ext, ".eap"))
|
|
|
|
{
|
|
|
|
E_App *app;
|
|
|
|
|
|
|
|
app = e_app_new(file, 0);
|
|
|
|
|
|
|
|
if(!app)
|
|
|
|
{
|
|
|
|
DEF_THUMB_RETURN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
im = edje_object_add(evas);
|
|
|
|
edje_object_file_set(im, file, "icon");
|
|
|
|
e_object_unref(E_OBJECT(app));
|
|
|
|
return im;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* saved thumb */
|
|
|
|
/* TODO: add ability to fetch thumbs from freedesktop dirs */
|
|
|
|
if (!e_thumb_exists(file))
|
2005-10-20 08:07:45 -07:00
|
|
|
{
|
|
|
|
if (!e_thumb_create(file, width, height))
|
|
|
|
{
|
|
|
|
DEF_THUMB_RETURN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
thumb = e_thumb_file_get(file);
|
2005-10-20 08:07:45 -07:00
|
|
|
if (!thumb)
|
|
|
|
{
|
|
|
|
DEF_THUMB_RETURN;
|
|
|
|
}
|
2005-10-18 16:03:36 -07:00
|
|
|
|
|
|
|
ef = eet_open(thumb, EET_FILE_MODE_READ);
|
|
|
|
if (!ef)
|
2005-10-20 08:07:45 -07:00
|
|
|
{
|
|
|
|
eet_close(ef);
|
|
|
|
free(thumb);
|
|
|
|
DEF_THUMB_RETURN;
|
|
|
|
}
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-20 08:07:45 -07:00
|
|
|
im = e_icon_add(evas);
|
|
|
|
e_icon_file_key_set(im, thumb, "/thumbnail/data");
|
|
|
|
e_icon_fill_inside_set(im, 1);
|
|
|
|
free(thumb);
|
2005-10-20 20:35:14 -07:00
|
|
|
eet_close(ef);
|
2005-10-18 16:03:36 -07:00
|
|
|
return im;
|
|
|
|
}
|
|
|
|
|
2005-10-20 06:08:51 -07:00
|
|
|
/* return hash for a file */
|
2005-10-18 16:03:36 -07:00
|
|
|
static char *
|
|
|
|
_e_thumb_file_id(char *file)
|
|
|
|
{
|
2005-10-20 08:07:45 -07:00
|
|
|
char s[256], *sp;
|
2005-10-18 16:03:36 -07:00
|
|
|
const char *chmap =
|
2005-10-20 08:07:45 -07:00
|
|
|
"0123456789abcdef"
|
|
|
|
"ghijklmnopqrstuv"
|
|
|
|
"wxyz`~!@#$%^&*()"
|
|
|
|
"[];',.{}<>?-=_+|";
|
|
|
|
unsigned int id[6], i;
|
2005-10-18 16:03:36 -07:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(file, &st) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
id[0] = (int)st.st_ino;
|
|
|
|
id[1] = (int)st.st_dev;
|
2005-10-20 08:07:45 -07:00
|
|
|
id[2] = (int)(st.st_size & 0xffffffff);
|
|
|
|
id[3] = (int)((st.st_size >> 32) & 0xffffffff);
|
|
|
|
id[4] = (int)(st.st_mtime & 0xffffffff);
|
|
|
|
id[5] = (int)((st.st_mtime >> 32) & 0xffffffff);
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-20 08:07:45 -07:00
|
|
|
sp = s;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
unsigned int t, tt;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
t = id[i];
|
|
|
|
j = 32;
|
|
|
|
while (j > 0)
|
|
|
|
{
|
|
|
|
tt = t & ((1 << 6) - 1);
|
|
|
|
*sp = chmap[tt];
|
|
|
|
t >>= 6;
|
|
|
|
j -= 6;
|
|
|
|
sp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*sp = 0;
|
2005-10-18 16:03:36 -07:00
|
|
|
return strdup(s);
|
|
|
|
}
|