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.

2971 lines
87 KiB

#include "ephoto.h"
#define ZOOM_MAX 512
#define ZOOM_MIN 128
#define ZOOM_STEP 32
#define TODO_ITEM_MIN_BATCH 5
#define FILESEP "file://"
#define FILESEP_LEN sizeof(FILESEP) - 1
#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 *panes;
Evas_Object *table;
Evas_Object *gridbox;
Evas_Object *grid;
Evas_Object *original_grid;
Evas_Object *nolabel;
Evas_Object *infolabel;
Evas_Object *fsel;
Evas_Object *leftbox;
Evas_Object *direntry;
Evas_Object *search;
Evas_Object *hover;
Elm_Object_Item *dir_current;
Elm_Object_Item *last_sel;
Ephoto_Sort sort;
Eio_File *ls;
Ecore_File_Monitor *monitor;
Eina_List *cut_items;
Eina_List *copy_items;
Eina_List *handlers;
Eina_List *todo_items;
Eina_List *entries;
Eina_List *searchentries;
Ecore_Job *change_dir_job;
Ecore_Timer *click_timer;
Eina_Bool thumbs_only;
Eina_Bool dirs_only;
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;
static Elm_Genlist_Item_Class _ephoto_dir_class;
/*Main Callbacks*/
static void _ephoto_show_slideshow(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
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_panes_unpress(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static void _ephoto_panes_double_clicked(void *data, 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);
/*File Pane Functions*/
static void _ephoto_dir_hide_folders(void *data, Evas_Object *obj,
void *event_info);
static void _ephoto_dir_show_folders(void *data, Evas_Object *obj,
void *event_info);
/*Thumb Pane Functions*/
static void _ephoto_thumb_update_info_label(Ephoto_Thumb_Browser *tb);
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);
/*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);
}
item = elm_genlist_first_item_get(tb->fsel);
while (item)
{
file = elm_object_item_data_get(item);
paths = eina_list_append(paths, strdup(file->path));
item = elm_genlist_item_next_get(item);
}
if (eina_list_count(paths) <= 0)
return;
ephoto_file_empty_trash(tb->ephoto, paths);
}
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 Eina_Bool
_drop_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it,
Elm_Selection_Data *ev, int xposret EINA_UNUSED, int yposret EINA_UNUSED)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_TRUE);
Ephoto_Entry *entry = elm_object_item_data_get(it);
const char *path = entry->path;
Eina_List *files = NULL;
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
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)
{
files = eina_list_append(files, s);
s = _drag_data_extract(&dd);
}
free(dd);
if (tb->ephoto->config->move_drop)
ephoto_file_move(tb->ephoto, files, path);
else
ephoto_file_copy(tb->ephoto, files, path);
if (tb->dir_current)
elm_genlist_item_selected_set(tb->dir_current, EINA_TRUE);
return EINA_TRUE;
}
static Elm_Object_Item *
_drop_item_getcb(Evas_Object *obj, Evas_Coord x, Evas_Coord y,
int *xposret EINA_UNUSED, int *yposret)
{
Elm_Object_Item *gli;
gli = elm_genlist_at_xy_item_get(obj, x, y, yposret);
return gli;
}
static void
_drop_enter(void *data, Evas_Object *obj EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
if (tb->dragging)
elm_object_cursor_set(tb->main, ELM_CURSOR_TARGET);
}
static void
_drop_leave(void *data, Evas_Object *obj EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
if (tb->dragging)
{
elm_object_cursor_set(tb->main, ELM_CURSOR_HAND2);
if (tb->dir_current)
elm_genlist_item_selected_set(tb->dir_current, EINA_TRUE);
}
}
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)
{
elm_genlist_item_selected_set(it, EINA_TRUE);
}
static Eina_Bool
_5s_timeout_gone(void *data)
{
elm_drag_cancel(data);
_5s_timeout = NULL;
return ECORE_CALLBACK_CANCEL;
}
static void
_dnd_drag_start(void *data EINA_UNUSED, Evas_Object *obj)
{
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
if (_5s_cancel)
_5s_timeout = ecore_timer_add(5.0, _5s_timeout_gone, obj);
elm_object_cursor_set(tb->main, ELM_CURSOR_HAND2);
tb->dragging = 1;
}
static void
_dnd_drag_done(void *data EINA_UNUSED, 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;
}
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);
evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
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)
{
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;
}
/*File Pane Callbacks*/
static void
_on_list_expand_req(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
Elm_Object_Item *it = event_info;
ecore_job_del(tb->change_dir_job);
tb->change_dir_job = NULL;
ecore_timer_del(tb->click_timer);
tb->click_timer = NULL;
elm_genlist_item_expanded_set(it, EINA_TRUE);
}
static void
_on_list_contract_req(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
Elm_Object_Item *it = event_info;
ecore_job_del(tb->change_dir_job);
tb->change_dir_job = NULL;
ecore_timer_del(tb->click_timer);
tb->click_timer = NULL;
elm_genlist_item_expanded_set(it, EINA_FALSE);
}
static void
_on_list_expanded(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
Elm_Object_Item *it = event_info;
Ephoto_Entry *entry;
const char *path;
entry = elm_object_item_data_get(it);
path = entry->path;
tb->dirs_only = 0;
if (!strcmp(path, tb->ephoto->config->directory))
tb->dirs_only = 1;
else
tb->dirs_only = 0;
tb->thumbs_only = 0;
ephoto_directory_set(tb->ephoto, path, it, tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_on_list_contracted(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
Elm_Object_Item *it = event_info;
Ephoto_Entry *entry;
const char *path;
entry = elm_object_item_data_get(it);
path = entry->path;
elm_genlist_item_subitems_clear(it);
if (!strcmp(path, tb->ephoto->config->directory))
return;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, path, NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto,
tb->ephoto->config->directory);
}
static void
_dir_job(void *data)
{
Elm_Object_Item *it = data;
Ephoto_Thumb_Browser *tb = evas_object_data_get(it, "thumb_browser");
Ephoto_Entry *entry;
const char *path;
entry = elm_object_item_data_get(it);
path = entry->path;
tb->change_dir_job = NULL;
tb->thumbs_only = 1;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, path, NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_wait_job(void *data)
{
Elm_Object_Item *it = data;
Ephoto_Thumb_Browser *tb = evas_object_data_get(it, "thumb_browser");
if (tb->change_dir_job)
ecore_job_del(tb->change_dir_job);
tb->change_dir_job = ecore_job_add(_dir_job, it);
}
static void
_on_list_selected(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
Elm_Object_Item *it = event_info;
evas_object_data_set(it, "thumb_browser", tb);
if (!tb->dragging)
{
tb->dir_current = it;
ecore_job_add(_wait_job, it);
}
}
static char *
_dir_item_text_get(void *data, Evas_Object *obj EINA_UNUSED,
const char *part EINA_UNUSED)
{
Ephoto_Entry *e = data;
return strdup(e->label);
}
static Evas_Object *
_dir_item_icon_get(void *data EINA_UNUSED, Evas_Object *obj,
const char *part)
{
if (!strcmp(part, "elm.swallow.end"))
return NULL;
Evas_Object *ic = elm_icon_add(obj);
elm_icon_order_lookup_set(ic, ELM_ICON_LOOKUP_FDO_THEME);
elm_icon_standard_set(ic, "folder");
return ic;
}
static void
_dir_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
Ephoto_Entry *e = data;
if (!e->no_delete)
ephoto_entry_free(e->ephoto, e);
}
static Eina_Bool
_check_for_subdirs(Ephoto_Entry *entry)
{
Eina_Iterator *ls = eina_file_direct_ls(entry->path);
Eina_File_Direct_Info *info;
if (!ls)
return EINA_FALSE;
EINA_ITERATOR_FOREACH(ls, info)
{
if (info->type == EINA_FILE_DIR)
{
eina_iterator_free(ls);
return EINA_TRUE;
}
}
eina_iterator_free(ls);
return EINA_FALSE;
}
static void
_dir_go_home(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
elm_genlist_clear(tb->fsel);
tb->thumbs_only = 0;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, getenv("HOME"), NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
ephoto_thumb_browser_top_dir_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_dir_go_up(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
if (strcmp(tb->ephoto->config->directory, "/"))
{
char path[PATH_MAX];
Elm_Object_Item *it, *next;
Ephoto_Entry *e;
snprintf(path, PATH_MAX, "%s", tb->ephoto->config->directory);
it = elm_genlist_first_item_get(tb->fsel);
while (it)
{
e = elm_object_item_data_get(it);
if (!strcmp(e->path, path))
{
if (e->parent)
{
elm_genlist_item_expanded_set(e->parent, EINA_FALSE);
return;
}
}
next = elm_genlist_item_next_get(it);
it = next;
}
elm_genlist_clear(tb->fsel);
tb->thumbs_only = 0;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, ecore_file_dir_get(path), NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
ephoto_thumb_browser_top_dir_set(tb->ephoto,
tb->ephoto->config->directory);
}
}
static void
_dir_go_trash(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Thumb_Browser *tb = data;
char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
if (!ecore_file_exists(path))
ecore_file_mkpath(path);
elm_genlist_clear(tb->fsel);
tb->thumbs_only = 0;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, path, NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, _("Trash"));
ephoto_thumb_browser_top_dir_set(tb->ephoto, tb->ephoto->config->directory);
}
static void
_dir_go_entry(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
const char *dir;
Ephoto_Thumb_Browser *tb = data;
dir = elm_object_text_get(tb->direntry);
if (ecore_file_is_dir(dir))
{
elm_genlist_clear(tb->fsel);
tb->thumbs_only = 0;
tb->dirs_only = 0;
ephoto_directory_set(tb->ephoto, dir, NULL,
tb->dirs_only, tb->thumbs_only);
ephoto_title_set(tb->ephoto, tb->ephoto->config->directory);
ephoto_thumb_browser_top_dir_set(tb->ephoto,
tb->ephoto->config->directory);
}
}