2005-10-18 16:03:36 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "e.h"
|
|
|
|
|
2005-10-21 02:52:46 -07:00
|
|
|
#ifdef EFM_DEBUG
|
|
|
|
# define D(x) do {printf(__FILE__ ":%d: ", __LINE__); printf x; fflush(stdout);} while (0)
|
|
|
|
#else
|
|
|
|
# define D(x) ((void) 0)
|
|
|
|
#endif
|
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
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)
|
2005-10-23 08:18:47 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2005-10-18 16:03:36 -07:00
|
|
|
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-23 08:18:47 -07:00
|
|
|
const char *
|
2005-10-18 16:03:36 -07:00
|
|
|
e_thumb_dir_get(void)
|
|
|
|
{
|
2005-10-23 08:18:47 -07:00
|
|
|
return thumb_path;
|
2005-10-18 16:03:36 -07:00
|
|
|
}
|
|
|
|
|
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-23 08:18:47 -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-21 02:52:46 -07:00
|
|
|
/* return true if the saved thumb exists OR if its an eap */
|
2005-10-18 16:03:36 -07:00
|
|
|
int
|
|
|
|
e_thumb_exists(char *file)
|
|
|
|
{
|
|
|
|
char *thumb;
|
2005-10-21 02:52:46 -07:00
|
|
|
char *ext;
|
2005-10-23 08:18:47 -07:00
|
|
|
|
2005-10-21 02:52:46 -07:00
|
|
|
ext = strrchr(file, '.');
|
2005-10-23 08:18:47 -07:00
|
|
|
if ((ext) && (!strcasecmp(ext, ".eap")))
|
|
|
|
return 1;
|
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
thumb = e_thumb_file_get(file);
|
2005-10-23 08:18:47 -07:00
|
|
|
if (ecore_file_exists(thumb))
|
|
|
|
{
|
|
|
|
free(thumb);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-21 02:52:46 -07:00
|
|
|
return 0;
|
2005-10-18 16:03:36 -07:00
|
|
|
}
|
|
|
|
|
2005-10-22 10:02:37 -07:00
|
|
|
int *
|
|
|
|
_e_thumb_image_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf)
|
|
|
|
{
|
|
|
|
Evas *evasbuf;
|
2005-10-23 08:07:56 -07:00
|
|
|
int iw, ih;
|
2005-10-22 10:02:37 -07:00
|
|
|
|
|
|
|
*buf = ecore_evas_buffer_new(1, 1);
|
|
|
|
evasbuf = ecore_evas_get(*buf);
|
|
|
|
*im = evas_object_image_add(evasbuf);
|
|
|
|
evas_object_image_file_set(*im, file, NULL);
|
|
|
|
iw = 0; ih = 0;
|
|
|
|
evas_object_image_size_get(*im, &iw, &ih);
|
2005-10-23 08:07:56 -07:00
|
|
|
*alpha = evas_object_image_alpha_get(*im);
|
2005-10-22 10:02:37 -07:00
|
|
|
if ((iw > 0) && (ih > 0))
|
2005-10-23 08:18:47 -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_move(*im, 0, 0);
|
|
|
|
evas_object_show(*im);
|
|
|
|
|
2005-10-31 01:31:05 -08:00
|
|
|
return (int *)ecore_evas_buffer_pixels_get(*buf);
|
2005-10-23 08:18:47 -07:00
|
|
|
}
|
2005-10-22 10:02:37 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* thumbnail an e17 background and return pixel data */
|
2005-10-31 01:31:05 -08:00
|
|
|
const int *
|
2005-10-22 10:02:37 -07:00
|
|
|
_e_thumb_ebg_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf)
|
|
|
|
{
|
|
|
|
Evas *evasbuf;
|
|
|
|
Evas_Object *wallpaper;
|
2005-10-31 01:31:05 -08:00
|
|
|
const int *pixels;
|
2005-10-22 10:02:37 -07:00
|
|
|
|
|
|
|
*ww = 640;
|
|
|
|
*hh = 480;
|
|
|
|
*alpha = 0;
|
|
|
|
|
|
|
|
w = 640;
|
|
|
|
h = 480;
|
|
|
|
|
|
|
|
*buf = ecore_evas_buffer_new(w, h);
|
|
|
|
evasbuf = ecore_evas_get(*buf);
|
|
|
|
|
|
|
|
wallpaper = edje_object_add(evasbuf);
|
|
|
|
|
|
|
|
edje_object_file_set(wallpaper, file, "desktop/background");
|
|
|
|
|
|
|
|
/* wallpaper */
|
|
|
|
evas_object_move(wallpaper, 0, 0);
|
|
|
|
evas_object_resize(wallpaper, w, h);
|
|
|
|
|
|
|
|
evas_object_show(wallpaper);
|
|
|
|
|
|
|
|
pixels = ecore_evas_buffer_pixels_get(*buf);
|
|
|
|
|
|
|
|
evas_object_del(wallpaper);
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* thumbnail an e17 theme and return pixel data */
|
2005-10-31 01:31:05 -08:00
|
|
|
const int *
|
2005-10-22 10:02:37 -07:00
|
|
|
_e_thumb_etheme_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, int *alpha, Evas_Object **im, Ecore_Evas **buf)
|
|
|
|
{
|
|
|
|
Evas *evasbuf;
|
|
|
|
Evas_Object *wallpaper, *window, *clock, *start, **pager;
|
2005-10-31 01:31:05 -08:00
|
|
|
const int *pixels;
|
2005-10-22 10:02:37 -07:00
|
|
|
|
|
|
|
*ww = 640;
|
|
|
|
*hh = 480;
|
|
|
|
*alpha = 0;
|
|
|
|
|
|
|
|
w = 640;
|
|
|
|
h = 480;
|
|
|
|
|
|
|
|
*buf = ecore_evas_buffer_new(w, h);
|
|
|
|
evasbuf = ecore_evas_get(*buf);
|
|
|
|
|
|
|
|
wallpaper = edje_object_add(evasbuf);
|
|
|
|
window = edje_object_add(evasbuf);
|
|
|
|
clock = edje_object_add(evasbuf);
|
|
|
|
start = edje_object_add(evasbuf);
|
|
|
|
pager = E_NEW(Evas_Object*, 3);
|
|
|
|
pager[0] = edje_object_add(evasbuf);
|
|
|
|
pager[1] = edje_object_add(evasbuf);
|
|
|
|
pager[2] = edje_object_add(evasbuf);
|
|
|
|
|
|
|
|
edje_object_file_set(wallpaper, file, "desktop/background");
|
|
|
|
edje_object_file_set(window, file, "widgets/border/default/border");
|
|
|
|
edje_object_file_set(clock, file, "modules/clock/main");
|
|
|
|
edje_object_file_set(clock, file, "modules/clock/main");
|
|
|
|
edje_object_file_set(start, file, "modules/start/main");
|
|
|
|
edje_object_file_set(pager[0], file, "modules/pager/main");
|
|
|
|
edje_object_file_set(pager[1], file, "modules/pager/desk");
|
|
|
|
edje_object_file_set(pager[2], file, "modules/pager/window");
|
|
|
|
edje_object_part_text_set(window, "title_text", file);
|
|
|
|
edje_object_part_swallow(pager[0], "items", pager[1]);
|
|
|
|
edje_object_part_swallow(pager[1], "items", pager[2]);
|
|
|
|
|
|
|
|
/* wallpaper */
|
|
|
|
evas_object_move(wallpaper, 0, 0);
|
|
|
|
evas_object_resize(wallpaper, w, h);
|
|
|
|
/* main window */
|
|
|
|
evas_object_move(window, (w * 0.1), (h * 0.05));
|
|
|
|
evas_object_resize(window, w * 0.8, h * 0.75);
|
|
|
|
/* clock */
|
|
|
|
evas_object_move(clock, (w * 0.9), (h * 0.9));
|
|
|
|
evas_object_resize(clock, w * 0.1, h * 0.1);
|
|
|
|
/* start */
|
|
|
|
evas_object_move(start, (w * 0.9), (h * 0.9));
|
|
|
|
evas_object_resize(start, w * 0.1, h * 0.1);
|
|
|
|
/* pager */
|
|
|
|
evas_object_move(pager[0], (w * 0.3), (h * 0.9));
|
|
|
|
evas_object_resize(pager[0], w * 0.1, h * 0.1);
|
|
|
|
|
|
|
|
evas_object_show(wallpaper);
|
|
|
|
evas_object_show(window);
|
|
|
|
evas_object_show(clock);
|
|
|
|
evas_object_show(start);
|
|
|
|
evas_object_show(pager[0]);
|
|
|
|
evas_object_show(pager[1]);
|
|
|
|
evas_object_show(pager[2]);
|
|
|
|
|
|
|
|
pixels = ecore_evas_buffer_pixels_get(*buf);
|
|
|
|
|
|
|
|
evas_object_del(wallpaper);
|
|
|
|
evas_object_del(window);
|
|
|
|
evas_object_del(clock);
|
|
|
|
evas_object_del(start);
|
|
|
|
evas_object_del(pager[0]);
|
|
|
|
evas_object_del(pager[1]);
|
|
|
|
evas_object_del(pager[2]);
|
|
|
|
free(pager);
|
|
|
|
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
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;
|
2005-10-21 02:52:46 -07:00
|
|
|
char *thumbpath, *ext;
|
2005-10-18 16:03:36 -07:00
|
|
|
Evas_Object *im;
|
|
|
|
const int *data;
|
2005-10-23 08:07:56 -07:00
|
|
|
int size, ww, hh;
|
2005-10-18 16:03:36 -07:00
|
|
|
Ecore_Evas *buf;
|
2005-10-20 08:07:45 -07:00
|
|
|
int alpha;
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-21 02:52:46 -07:00
|
|
|
ext = strrchr(file, '.');
|
2005-10-23 08:18:47 -07:00
|
|
|
if ((ext) && (!strcasecmp(ext, ".eap")))
|
|
|
|
return 1;
|
2005-10-21 02:52:46 -07:00
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
thumbpath = e_thumb_file_get(file);
|
2005-10-20 08:07:45 -07:00
|
|
|
if (!thumbpath)
|
2005-10-23 08:18:47 -07:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ext)
|
2005-10-20 08:07:45 -07:00
|
|
|
{
|
2005-10-23 08:18:47 -07:00
|
|
|
if(!strcasecmp(ext, ".edj"))
|
|
|
|
{
|
|
|
|
/* for now, this function does both the bg and theme previews */
|
|
|
|
data = _e_thumb_etheme_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
|
2005-10-20 08:07:45 -07:00
|
|
|
}
|
2005-10-22 10:02:37 -07:00
|
|
|
else
|
|
|
|
data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
|
|
|
|
|
|
|
|
if (data)
|
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-23 08:18:47 -07:00
|
|
|
|
2005-10-21 02:25:23 -07:00
|
|
|
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 *
|
2005-11-03 19:33:23 -08:00
|
|
|
e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord height, int shrink)
|
2005-10-18 16:03:36 -07:00
|
|
|
{
|
|
|
|
Eet_File *ef;
|
|
|
|
char *thumb, *ext;
|
|
|
|
Evas_Object *im = NULL;
|
2005-10-23 08:07:56 -07:00
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
#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
|
|
|
|
|
2005-10-21 02:52:46 -07:00
|
|
|
D(("e_thumb_evas_object_get: (%s)\n", file));
|
|
|
|
|
2005-10-18 16:03:36 -07:00
|
|
|
/* eap thumbnailer */
|
|
|
|
ext = strrchr(file, '.');
|
2005-10-23 08:18:47 -07:00
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(ext, ".eap"))
|
|
|
|
{
|
|
|
|
E_App *app;
|
2005-10-21 02:52:46 -07:00
|
|
|
|
2005-10-23 08:18:47 -07:00
|
|
|
D(("e_thumb_evas_object_get: eap found\n"));
|
|
|
|
app = e_app_new(file, 0);
|
|
|
|
D(("e_thumb_evas_object_get: eap loaded\n"));
|
|
|
|
if (!app)
|
|
|
|
{
|
|
|
|
D(("e_thumb_evas_object_get: invalid eap\n"));
|
|
|
|
DEF_THUMB_RETURN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
D(("e_thumb_evas_object_get: creating eap thumb\n"));
|
2005-11-03 19:33:23 -08:00
|
|
|
im = e_icon_add(evas);
|
|
|
|
e_icon_file_edje_set(im, file, "icon");
|
2005-10-23 08:18:47 -07:00
|
|
|
e_object_unref(E_OBJECT(app));
|
|
|
|
D(("e_thumb_evas_object_get: returning eap thumb\n"));
|
|
|
|
return im;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-18 16:03:36 -07:00
|
|
|
|
|
|
|
/* 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");
|
2005-11-04 09:02:42 -08:00
|
|
|
if (shrink)
|
2005-11-03 19:33:23 -08:00
|
|
|
{
|
|
|
|
Evas_Coord sw, sh;
|
2005-11-04 09:02:42 -08:00
|
|
|
|
2005-11-03 19:33:23 -08:00
|
|
|
e_icon_size_get(im, &sw, &sh);
|
|
|
|
evas_object_resize(im, sw, sh);
|
|
|
|
}
|
2005-10-20 08:07:45 -07:00
|
|
|
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`~!@#$%^&*()"
|
|
|
|
"[];',.{}<>?-=_+|";
|
2005-10-23 08:07:56 -07:00
|
|
|
unsigned int id[4], i;
|
2005-10-18 16:03:36 -07:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(file, &st) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2005-10-23 08:07:56 -07:00
|
|
|
id[0] = st.st_ino;
|
|
|
|
id[1] = st.st_dev;
|
|
|
|
id[2] = (st.st_size & 0xffffffff);
|
|
|
|
id[3] = (st.st_mtime & 0xffffffff);
|
2005-10-18 16:03:36 -07:00
|
|
|
|
2005-10-20 08:07:45 -07:00
|
|
|
sp = s;
|
2005-10-23 08:07:56 -07:00
|
|
|
for (i = 0; i < 4; i++)
|
2005-10-20 08:07:45 -07:00
|
|
|
{
|
|
|
|
unsigned int t, tt;
|
|
|
|
int j;
|
2005-10-23 08:18:47 -07:00
|
|
|
|
2005-10-20 08:07:45 -07:00
|
|
|
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);
|
|
|
|
}
|