You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2212 lines
67 KiB

#include "ephoto.h"
#define ZOOM_MAX 512
#define ZOOM_MIN 128
#define ZOOM_STEP 32
#define FILESEP "file://"
#define FILESEP_LEN sizeof(FILESEP) - 1
#define TODO_ITEM_MIN_BATCH 5
#define DRAG_TIMEOUT 0.3
#define ANIM_TIME 0.2
static Eina_Bool _5s_cancel = EINA_FALSE;
static Ecore_Timer *_5s_timeout = NULL;
typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser;
struct _Ephoto_Thumb_Browser
{
Ephoto *ephoto;
Evas_Object *main;
Evas_Object *table;
Evas_Object *gridbox;
Evas_Object *grid;
Evas_Object *original_grid;
Evas_Object *nolabel;
Evas_Object *search;
Evas_Object *menu;
Evas_Object *hover;
Elm_Object_Item *similarity;
Elm_Object_Item *last_sel;
Ephoto_Sort sort;
Eio_File *ls;
Eina_Bool dirs_only;
Eina_Bool thumbs_only;
Eina_List *cut_items;
Eina_List *copy_items;
Eina_List *handlers;
Eina_List *todo_items;
Eina_List *entries;
Eina_List *searchentries;
double totsize;
double totsize_old;
int totimages;
int totimages_old;
Eina_Bool dragging;
Eina_Bool searching;
Eina_Bool processing;
struct
{
Ecore_Animator *todo_items;
int count;
int processed;
} animator;
Eina_Bool main_deleted : 1;
};
/*Item Classes*/
static Elm_Gengrid_Item_Class _ephoto_thumb_file_class;
/*Main Callbacks*/
static void _ephoto_show_settings(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static void _ephoto_main_key_down(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static void _ephoto_main_del(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
/*Thumb Pane Functions*/
static void _ephoto_thumb_activated(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info);
static void _ephoto_thumb_zoom_set(Ephoto_Thumb_Browser *tb, int zoom);
static void _ephoto_thumb_search_go(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static void _ephoto_thumb_search_cancel(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static void _ephoto_thumb_search_start(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static char *_drag_data_extract(char **drag_data);
/*Common Callbacks*/
static void
_menu_dismissed_cb(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
evas_object_del(obj);
elm_object_focus_set(tb->main, EINA_TRUE);
}
static void
_menu_empty_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Eina_List *paths = NULL;
Elm_Object_Item *item;
Ephoto_Entry *file;
item = elm_gengrid_first_item_get(tb->grid);
while (item)
{
file = elm_object_item_data_get(item);
paths = eina_list_append(paths, strdup(file->path));
item = elm_gengrid_item_next_get(item);
}
if (eina_list_count(paths) <= 0)
return;
ephoto_file_empty_trash(tb->ephoto, paths);
}
static Eina_Bool
_5s_timeout_gone(void *data)
{
elm_drag_cancel(data);
_5s_timeout = NULL;
return ECORE_CALLBACK_CANCEL;
}
static Eina_Bool
_drop_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it EINA_UNUSED,
Elm_Selection_Data *ev, int xposret EINA_UNUSED, int yposret EINA_UNUSED)
{
Eina_List *files = NULL;
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
const char *path = tb->ephoto->config->directory;
char *dir;
if (!ev->data)
return EINA_FALSE;
if (ev->len <= 0)
return EINA_FALSE;
if (!path)
return EINA_FALSE;
char *dd = strdup(ev->data);
if (!dd)
return EINA_FALSE;
char *s = _drag_data_extract(&dd);
while (s)
{
dir = ecore_file_dir_get(s);
if (!strcmp(path, dir))
{
free(dir);
break;
}
if (evas_object_image_extension_can_load_get(basename(s)))
files = eina_list_append(files, s);
free(dir);
s = _drag_data_extract(&dd);
}
free(dd);
if (eina_list_count(files) <= 0)
return EINA_TRUE;
if (tb->ephoto->config->move_drop)
ephoto_file_move(tb->ephoto, files, path);
else
ephoto_file_copy(tb->ephoto, files, path);
return EINA_TRUE;
}
static Elm_Object_Item *
_drop_item_getcb(Evas_Object *obj EINA_UNUSED, Evas_Coord x EINA_UNUSED,
Evas_Coord y EINA_UNUSED, int *xposret EINA_UNUSED,
int *yposret EINA_UNUSED)
{
return NULL;
}
static void
_drop_enter(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
return;
}
static void
_drop_leave(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
return;
}
static void
_drop_pos(void *data EINA_UNUSED, Evas_Object *cont EINA_UNUSED,
Elm_Object_Item *it EINA_UNUSED, Evas_Coord x EINA_UNUSED,
Evas_Coord y EINA_UNUSED, int xposret EINA_UNUSED,
int yposret EINA_UNUSED, Elm_Xdnd_Action action EINA_UNUSED)
{
return;
}
static char *
_drag_data_extract(char **drag_data)
{
char *uri = NULL;
if (!drag_data)
return uri;
char *p = *drag_data;
if (!p)
return uri;
char *s = strstr(p, FILESEP);
if (s)
p += FILESEP_LEN;
s = strchr(p, '\n');
uri = p;
if (s)
{
if (s - p > 0)
{
char *s1 = s - 1;
if (s1[0] == '\r')
s1[0] = '\0';
else
{
char *s2 = s + 1;
if (s2[0] == '\r')
{
s[0] = '\0';
s++;
}
else
s[0] = '\0';
}
}
else
s[0] = '\0';
s++;
}
else
p = NULL;
*drag_data = s;
return uri;
}
static void
_dnd_drag_start(void *data EINA_UNUSED, Evas_Object *obj)
{
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
if (tb->ephoto->state != EPHOTO_STATE_THUMB)
{
elm_drag_cancel(tb->grid);
return;
}
if (_5s_cancel)
_5s_timeout = ecore_timer_loop_add(5.0, _5s_timeout_gone, obj);
elm_object_cursor_set(tb->main, ELM_CURSOR_HAND2);
ephoto_show_folders(tb->ephoto, EINA_FALSE);
tb->dragging = 1;
}
static void
_dnd_drag_done(void *data, Evas_Object *obj,
Eina_Bool doaccept EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
if (_5s_cancel)
{
ecore_timer_del(_5s_timeout);
_5s_timeout = NULL;
}
if (eina_list_count(data))
eina_list_free(data);
elm_object_cursor_unset(tb->main);
tb->dragging = 0;
return;
}
static const char *
_dnd_drag_data_build(Eina_List **items)
{
const char *drag_data = NULL;
if (*items)
{
Eina_List *l;
Elm_Object_Item *it;
Ephoto_Entry *e;
unsigned int len = 0;
EINA_LIST_FOREACH(*items, l, it)
{
e = elm_object_item_data_get(it);
if (e->path)
len += strlen(e->path);
}
drag_data =
malloc(len + eina_list_count(*items) * (FILESEP_LEN + 1) + 1);
strcpy((char *)drag_data, "");
EINA_LIST_FOREACH(*items, l, it)
{
e = elm_object_item_data_get(it);
if (e->path)
{
strcat((char *)drag_data, FILESEP);
strcat((char *)drag_data, e->path);
strcat((char *)drag_data, "\n");
}
}
}
return drag_data;
}
static Evas_Object *
_dnd_create_icon(void *data, Evas_Object *win, Evas_Coord *xoff,
Evas_Coord *yoff)
{
Evas_Object *icon = NULL;
Evas_Object *o = elm_object_item_part_content_get(data, "elm.swallow.icon");
if (o)
{
int xm, ym, w = 30, h = 30;
const char *f;
const char *g;
elm_image_file_get(o, &f, &g);
evas_pointer_canvas_xy_get(evas_object_evas_get(o), &xm, &ym);
if (xoff)
*xoff = xm - (w / 2);
if (yoff)
*yoff = ym - (h / 2);
icon = elm_icon_add(win);
elm_image_file_set(icon, f, g);
EPHOTO_EXPAND(icon);
EPHOTO_FILL(icon);
if (xoff && yoff)
evas_object_move(icon, *xoff, *yoff);
evas_object_resize(icon, w, h);
}
return icon;
}
static const char *
_dnd_get_drag_data(Evas_Object *obj, Elm_Object_Item *it, Eina_List **items)
{
const char *drag_data = NULL;
*items = eina_list_clone(elm_gengrid_selected_items_get(obj));
if (it)
{
if (!elm_gengrid_item_selected_get(it))
*items = eina_list_append(*items, it);
}
drag_data = _dnd_drag_data_build(items);
return drag_data;
}
static Elm_Object_Item *
_dnd_item_get(Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *xposret,
int *yposret)
{
Elm_Object_Item *item;
item = elm_gengrid_at_xy_item_get(obj, x, y, xposret, yposret);
return item;
}
static Eina_Bool
_dnd_item_data_get(Evas_Object *obj, Elm_Object_Item *it,
Elm_Drag_User_Info *info)
{
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
if (tb->ephoto->state != EPHOTO_STATE_THUMB)
{
elm_drag_cancel(tb->grid);
return EINA_FALSE;
}
info->format = ELM_SEL_FORMAT_TARGETS;
info->createicon = _dnd_create_icon;
info->createdata = it;
info->dragstart = _dnd_drag_start;
info->icons = NULL;
info->dragdone = _dnd_drag_done;
info->data = _dnd_get_drag_data(obj, it, (Eina_List **)&info->donecbdata);
info->acceptdata = info->donecbdata;
if (info->data)
return EINA_TRUE;
else
return EINA_FALSE;
}
/*Thumb Pane Callbacks*/
static char *
_thumb_item_text_get(void *data, Evas_Object *obj EINA_UNUSED,
const char *part EINA_UNUSED)
{
Ephoto_Entry *e = data;
EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
if (!e->label)
return NULL;
return strdup(e->label);
}
static Evas_Object *
_thumb_file_icon_get(void *data, Evas_Object *obj,
const char *part)
{
Ephoto_Entry *e = data;
Evas_Object *thumb = NULL;
if (strcmp(part, "elm.swallow.icon"))
return NULL;
if (e)
{
thumb = ephoto_thumb_add(e->ephoto, obj, e);
evas_object_show(thumb);
}
return thumb;
}
static void
_thumb_item_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
/*The entry is already freed when changing directories*/
}
static int
_entry_cmp_grid_alpha_asc(const void *pa, const void *pb)
{
const Ephoto_Entry *a, *b;
a = elm_object_item_data_get(pa);
b = elm_object_item_data_get(pb);
return strcasecmp(a->basename, b->basename);
}
static int
_entry_cmp_grid_alpha_desc(const void *pa, const void *pb)
{
const Ephoto_Entry *a, *b;
int i;
a = elm_object_item_data_get(pa);
b = elm_object_item_data_get(pb);
i = strcasecmp(a->basename, b->basename);
if (i < 0)
i = 1;
else if (i > 0)
i = -1;
return i;
}
static int
_entry_cmp_grid_mod_asc(const void *pa, const void *pb)
{
const Ephoto_Entry *a, *b;
long long moda, modb;
a = elm_object_item_data_get(pa);
b = elm_object_item_data_get(pb);
moda = ecore_file_mod_time(a->path);
modb = ecore_file_mod_time(b->path);
if (moda < modb)
return -1;
else if (moda > modb)
return 1;
else
return strcasecmp(a->basename, b->basename);
}
static int
_entry_cmp_grid_mod_desc(const void *pa, const void *pb)
{
const Ephoto_Entry *a, *b;
long long moda, modb;
a = elm_object_item_data_get(pa);
b = elm_object_item_data_get(pb);
moda = ecore_file_mod_time(a->path);
modb = ecore_file_mod_time(b->path);
if (moda < modb)
return 1;
else if (moda > modb)
return -1;
else
{
int i;
i = strcasecmp(a->basename, b->basename);
if (i < 0)
i = 1;
else if (i > 0)
i = -1;
return i;
}
}
static int
_entry_cmp_grid_similarity(const void *pa, const void *pb)
{
const Ephoto_Entry *a, *b;
a = elm_object_item_data_get(pa);
b = elm_object_item_data_get(pb);
if (!a->sort_id || !b->sort_id)
return 0;
else
return strcmp(a->sort_id, b->sort_id);
}
static void
_sort_alpha_asc(void *data, Evas_Object *obj,
void *event_data EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Evas_Object *ic;
tb->sort = EPHOTO_SORT_ALPHABETICAL_ASCENDING;
tb->ephoto->sort = tb->sort;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "view-sort-ascending");
elm_object_part_content_set(obj, "icon", ic);
evas_object_show(ic);
ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
NULL, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_sort_alpha_desc(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Evas_Object *ic;
tb->sort = EPHOTO_SORT_ALPHABETICAL_DESCENDING;
tb->ephoto->sort = tb->sort;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "view-sort-descending");
elm_object_part_content_set(obj, "icon", ic);
evas_object_show(ic);
ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
NULL, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_sort_mod_asc(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Evas_Object *ic;
tb->sort = EPHOTO_SORT_MODTIME_ASCENDING;
tb->ephoto->sort = tb->sort;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "view-sort-ascending");
elm_object_part_content_set(obj, "icon", ic);
evas_object_show(ic);
ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
NULL, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_sort_mod_desc(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Evas_Object *ic;
tb->sort = EPHOTO_SORT_MODTIME_DESCENDING;
tb->ephoto->sort = tb->sort;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "view-sort-descending");
elm_object_part_content_set(obj, "icon", ic);
evas_object_show(ic);
ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
NULL, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_sort_similarity(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
Evas_Object *ic;
tb->sort = EPHOTO_SORT_SIMILARITY;
tb->ephoto->sort = EPHOTO_SORT_SIMILARITY;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "view-sort-ascending");
elm_object_part_content_set(obj, "icon", ic);
evas_object_show(ic);
ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
NULL, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_zoom_in(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
int zoom = tb->ephoto->config->thumb_size + ZOOM_STEP;
_ephoto_thumb_zoom_set(tb, zoom);
}
static void