2010-07-01 11:49:22 -07:00
|
|
|
#include "ephoto.h"
|
|
|
|
|
2010-10-10 11:57:48 -07:00
|
|
|
#define ZOOM_MAX 512
|
|
|
|
#define ZOOM_MIN 128
|
|
|
|
#define ZOOM_STEP 32
|
2010-10-03 02:50:00 -07:00
|
|
|
|
2010-10-13 15:28:23 -07:00
|
|
|
#define TODO_ITEM_MIN_BATCH 16
|
|
|
|
|
2010-10-08 11:51:19 -07:00
|
|
|
#define PARENT_DIR "Up"
|
2010-10-03 02:50:00 -07:00
|
|
|
|
2010-09-13 09:40:33 -07:00
|
|
|
typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser;
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
struct _Ephoto_Thumb_Browser
|
|
|
|
{
|
2010-10-09 18:13:53 -07:00
|
|
|
Ephoto *ephoto;
|
2010-10-09 12:13:35 -07:00
|
|
|
Evas_Object *layout;
|
|
|
|
Evas_Object *edje;
|
2010-10-13 19:37:37 -07:00
|
|
|
Evas_Object *fsel;
|
2010-10-09 12:13:35 -07:00
|
|
|
Evas_Object *grid;
|
2010-10-12 15:54:20 -07:00
|
|
|
Evas_Object *toolbar;
|
2010-10-09 12:13:35 -07:00
|
|
|
Eio_File *ls;
|
2010-10-13 15:28:23 -07:00
|
|
|
Eina_List *todo_items;
|
2010-10-12 15:54:20 -07:00
|
|
|
struct {
|
|
|
|
Elm_Toolbar_Item *zoom_in;
|
|
|
|
Elm_Toolbar_Item *zoom_out;
|
|
|
|
Elm_Toolbar_Item *view_flow;
|
|
|
|
Elm_Toolbar_Item *slideshow;
|
|
|
|
} action;
|
2010-10-10 18:10:27 -07:00
|
|
|
struct {
|
|
|
|
const char *path;
|
|
|
|
void (*cb)(void *data, Ephoto_Entry *entry);
|
|
|
|
const void *data;
|
|
|
|
} pending;
|
2010-10-09 18:13:53 -07:00
|
|
|
struct {
|
|
|
|
Ecore_Job *change_dir;
|
|
|
|
} job;
|
2010-10-13 15:28:23 -07:00
|
|
|
struct {
|
|
|
|
Ecore_Animator *todo_items;
|
|
|
|
} animator;
|
2010-10-12 22:06:18 -07:00
|
|
|
Eina_Bool layout_deleted : 1;
|
2010-10-09 12:13:35 -07:00
|
|
|
};
|
|
|
|
|
2010-10-13 15:28:23 -07:00
|
|
|
static void
|
|
|
|
_todo_items_free(Ephoto_Thumb_Browser *tb)
|
|
|
|
{
|
|
|
|
eina_list_free(tb->todo_items);
|
|
|
|
tb->todo_items = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-11 20:40:14 -07:00
|
|
|
static Ephoto_Entry *
|
|
|
|
_first_file_entry_find(Ephoto_Thumb_Browser *tb)
|
|
|
|
{
|
|
|
|
const Eina_List *l;
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
EINA_LIST_FOREACH(tb->ephoto->entries, l, entry)
|
|
|
|
if (!entry->is_dir) return entry;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
static char *
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_thumb_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
Ephoto_Entry *e = data;
|
|
|
|
return strdup(e->label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
|
|
|
_ephoto_thumb_dir_icon_get(void *data, Evas_Object *obj, const char *part)
|
|
|
|
{
|
|
|
|
Ephoto_Entry *e = data;
|
|
|
|
const char *f;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (strncmp(part, "elm.swallow.icon.", sizeof("elm.swallow.icon.") - 1) != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n = atoi(part + sizeof("elm.swallow.icon.") - 1);
|
|
|
|
if (n < 1)
|
|
|
|
return NULL;
|
|
|
|
n--;
|
|
|
|
|
|
|
|
f = eina_list_nth(e->dir_files, n);
|
|
|
|
if (f)
|
2010-10-09 18:13:53 -07:00
|
|
|
return ephoto_thumb_add(e->ephoto, obj, f);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
|
|
|
if (e->dir_files_checked)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return ephoto_directory_thumb_add(obj, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_thumb_dir_state_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
Ephoto_Entry *e = data;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (strcmp(part, "have_files") == 0)
|
|
|
|
return !!e->dir_files;
|
|
|
|
|
|
|
|
if (strncmp(part, "have_file.", sizeof("have_file.") - 1) != 0)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
n = atoi(part + sizeof("have_file.") - 1);
|
|
|
|
if (n < 1)
|
|
|
|
return EINA_FALSE;
|
2010-10-11 21:58:04 -07:00
|
|
|
return n <= (int)eina_list_count(e->dir_files);
|
2010-10-09 12:13:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_thumb_file_icon_get(void *data, Evas_Object *obj, const char *part __UNUSED__)
|
2010-09-13 09:40:33 -07:00
|
|
|
{
|
2010-10-09 12:13:35 -07:00
|
|
|
Ephoto_Entry *e = data;
|
2010-10-09 18:13:53 -07:00
|
|
|
return ephoto_thumb_add(e->ephoto, obj, e->path);
|
2010-10-09 12:13:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_thumb_item_del(void *data, Evas_Object *obj __UNUSED__)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
Ephoto_Entry *e = data;
|
|
|
|
e->item = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Elm_Gengrid_Item_Class _ephoto_thumb_dir_class = {
|
|
|
|
"dir",
|
|
|
|
{
|
|
|
|
_ephoto_thumb_item_label_get,
|
|
|
|
_ephoto_thumb_dir_icon_get,
|
|
|
|
_ephoto_thumb_dir_state_get,
|
|
|
|
_ephoto_thumb_item_del
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Elm_Gengrid_Item_Class _ephoto_thumb_up_class = {
|
|
|
|
"up",
|
|
|
|
{
|
|
|
|
_ephoto_thumb_item_label_get,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_ephoto_thumb_item_del
|
|
|
|
}
|
2010-09-13 09:40:33 -07:00
|
|
|
};
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
static const Elm_Gengrid_Item_Class _ephoto_thumb_file_class = {
|
|
|
|
"file",
|
|
|
|
{
|
|
|
|
_ephoto_thumb_item_label_get,
|
|
|
|
_ephoto_thumb_file_icon_get,
|
|
|
|
NULL,
|
|
|
|
_ephoto_thumb_item_del
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-10 19:54:49 -07:00
|
|
|
static int
|
|
|
|
_entry_cmp(const void *pa, const void *pb)
|
|
|
|
{
|
|
|
|
const Ephoto_Entry *a = pa, *b = pb;
|
|
|
|
if (a->is_dir == b->is_dir)
|
|
|
|
return strcoll(a->basename, b->basename);
|
|
|
|
else if (a->is_dir)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
static void
|
2010-10-13 15:28:23 -07:00
|
|
|
_entry_item_add(Ephoto_Thumb_Browser *tb, Ephoto_Entry *e)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
const Elm_Gengrid_Item_Class *ic;
|
|
|
|
|
2010-10-13 15:28:23 -07:00
|
|
|
DBG("populate add '%s'", e->path);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
|
|
|
if (e->is_dir) ic = &_ephoto_thumb_dir_class;
|
|
|
|
else ic = &_ephoto_thumb_file_class;
|
|
|
|
|
2010-10-10 19:54:49 -07:00
|
|
|
if (!tb->ephoto->entries)
|
|
|
|
{
|
|
|
|
e->item = elm_gengrid_item_append(tb->grid, ic, e, NULL, NULL);
|
|
|
|
tb->ephoto->entries = eina_list_append(tb->ephoto->entries, e);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int near_cmp;
|
|
|
|
Ephoto_Entry *near_entry;
|
|
|
|
Elm_Gengrid_Item *near_item;
|
|
|
|
Eina_List *near_node = eina_list_search_sorted_near_list
|
|
|
|
(tb->ephoto->entries, _entry_cmp, e, &near_cmp);
|
|
|
|
|
|
|
|
near_entry = near_node->data;
|
|
|
|
near_item = near_entry->item;
|
|
|
|
if (near_cmp < 0)
|
|
|
|
{
|
|
|
|
e->item = elm_gengrid_item_insert_after
|
|
|
|
(tb->grid, ic, e, near_item, NULL, NULL);
|
|
|
|
tb->ephoto->entries = eina_list_append_relative_list
|
|
|
|
(tb->ephoto->entries, e, near_node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->item = elm_gengrid_item_insert_before
|
|
|
|
(tb->grid, ic, e, near_item, NULL, NULL);
|
|
|
|
tb->ephoto->entries = eina_list_prepend_relative_list
|
|
|
|
(tb->ephoto->entries, e, near_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
if (!e->item)
|
|
|
|
{
|
2010-10-13 15:28:23 -07:00
|
|
|
ERR("could not add item to grid: path '%s'", e->path);
|
2010-10-09 12:13:35 -07:00
|
|
|
ephoto_entry_free(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-10 18:10:27 -07:00
|
|
|
if (tb->pending.path == e->path)
|
|
|
|
{
|
|
|
|
tb->pending.cb((void*)tb->pending.data, e);
|
|
|
|
tb->pending.cb = NULL;
|
|
|
|
tb->pending.data = NULL;
|
|
|
|
eina_stringshare_replace(&tb->pending.path, NULL);
|
|
|
|
}
|
2010-10-09 12:13:35 -07:00
|
|
|
}
|
|
|
|
|
2010-10-13 15:32:41 -07:00
|
|
|
static void
|
|
|
|
_up_item_add_if_required(Ephoto_Thumb_Browser *tb)
|
|
|
|
{
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
char *parent_dir;
|
|
|
|
|
|
|
|
if ((elm_gengrid_first_item_get(tb->grid)) ||
|
|
|
|
(strcmp(tb->ephoto->config->directory, "/") == 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent_dir = ecore_file_dir_get(tb->ephoto->config->directory);
|
|
|
|
if (!parent_dir) return;
|
|
|
|
|
|
|
|
entry = ephoto_entry_new(tb->ephoto, parent_dir, PARENT_DIR);
|
|
|
|
free(parent_dir);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(entry);
|
|
|
|
entry->is_up = EINA_TRUE;
|
|
|
|
entry->is_dir = EINA_TRUE;
|
|
|
|
entry->item = elm_gengrid_item_append
|
|
|
|
(tb->grid, &_ephoto_thumb_up_class, entry, NULL, NULL);
|
|
|
|
/* does not go into entries as it is always the first - no sort! */
|
|
|
|
}
|
|
|
|
|
2010-10-13 15:28:23 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_todo_items_process(void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Edje_Message_Int msg;
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
|
|
|
|
if ((tb->ls) && (eina_list_count(tb->todo_items) < TODO_ITEM_MIN_BATCH))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
2010-10-13 15:32:41 -07:00
|
|
|
_up_item_add_if_required(tb);
|
2010-10-13 15:28:23 -07:00
|
|
|
|
|
|
|
tb->animator.todo_items = NULL;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(tb->todo_items, entry)
|
|
|
|
_entry_item_add(tb, entry);
|
|
|
|
|
|
|
|
msg.val = eina_list_count(tb->ephoto->entries);
|
|
|
|
edje_object_message_send(tb->edje, EDJE_MESSAGE_INT, 1, &msg);
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ephoto_populate_main(void *data, const Eina_File_Direct_Info *info)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Ephoto_Entry *e;
|
|
|
|
|
|
|
|
e = ephoto_entry_new(tb->ephoto, info->path, info->path + info->name_start);
|
|
|
|
if (info->dirent->d_type == DT_DIR) e->is_dir = EINA_TRUE;
|
|
|
|
else if (info->dirent->d_type == DT_REG) e->is_dir = EINA_FALSE;
|
|
|
|
else e->is_dir = !_ephoto_eina_file_direct_info_image_useful(info);
|
|
|
|
|
|
|
|
tb->todo_items = eina_list_append(tb->todo_items, e);
|
|
|
|
|
|
|
|
if (!tb->animator.todo_items)
|
|
|
|
tb->animator.todo_items = ecore_animator_add(_todo_items_process, tb);
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
static Eina_Bool
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_populate_filter(void *data __UNUSED__, const Eina_File_Direct_Info *info)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
const char *bname = info->path + info->name_start;
|
|
|
|
|
|
|
|
if (bname[0] == '.') return EINA_FALSE;
|
|
|
|
if (info->dirent->d_type == DT_DIR) return EINA_TRUE;
|
|
|
|
if (info->dirent->d_type == DT_UNKNOWN)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if ((stat(info->path, &st) == 0) && (S_ISDIR(st.st_mode)))
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _ephoto_eina_file_direct_info_image_useful(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ephoto_populate_end(void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
tb->ls = NULL;
|
2010-10-12 22:06:18 -07:00
|
|
|
|
|
|
|
if (tb->layout_deleted)
|
|
|
|
{
|
|
|
|
free(tb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-13 15:32:41 -07:00
|
|
|
if (!tb->animator.todo_items) _up_item_add_if_required(tb);
|
|
|
|
|
2010-10-10 18:10:27 -07:00
|
|
|
if (tb->pending.cb)
|
|
|
|
{
|
|
|
|
tb->pending.cb((void*)tb->pending.data, NULL);
|
|
|
|
tb->pending.cb = NULL;
|
|
|
|
}
|
|
|
|
tb->pending.data = NULL;
|
|
|
|
eina_stringshare_replace(&tb->pending.path, NULL);
|
|
|
|
edje_object_signal_emit(tb->edje, "populate,stop", "ephoto");
|
2010-10-09 12:13:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ephoto_populate_error(int error, void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
if (error) ERR("could not populate: %s", strerror(error));
|
|
|
|
edje_object_signal_emit(tb->edje, "populate,error", "ephoto");
|
2010-10-10 18:10:27 -07:00
|
|
|
_ephoto_populate_end(tb);
|
2010-10-09 12:13:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ephoto_populate_entries(Ephoto_Thumb_Browser *tb)
|
|
|
|
{
|
2010-10-12 20:24:22 -07:00
|
|
|
/* Edje_External_Param param; */
|
2010-10-09 18:13:53 -07:00
|
|
|
DBG("populate from '%s'", tb->ephoto->config->directory);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
2010-10-12 20:24:22 -07:00
|
|
|
evas_object_smart_callback_call(tb->layout, "changed,directory", NULL);
|
|
|
|
|
2010-10-13 15:28:23 -07:00
|
|
|
_todo_items_free(tb);
|
2010-10-09 12:13:35 -07:00
|
|
|
elm_gengrid_clear(tb->grid);
|
2010-10-09 18:13:53 -07:00
|
|
|
ephoto_entries_free(tb->ephoto);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
2010-10-13 19:37:37 -07:00
|
|
|
elm_fileselector_entry_path_set(tb->fsel, tb->ephoto->config->directory);
|
2010-10-09 18:13:53 -07:00
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
edje_object_signal_emit(tb->edje, "populate,start", "ephoto");
|
2010-10-09 18:13:53 -07:00
|
|
|
tb->ls = eio_file_direct_ls(tb->ephoto->config->directory,
|
2010-10-09 12:13:35 -07:00
|
|
|
_ephoto_populate_filter,
|
|
|
|
_ephoto_populate_main,
|
|
|
|
_ephoto_populate_end,
|
|
|
|
_ephoto_populate_error,
|
|
|
|
tb);
|
|
|
|
}
|
|
|
|
|
2010-10-09 18:13:53 -07:00
|
|
|
static void
|
|
|
|
_ephoto_thumb_change_dir(void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
tb->job.change_dir = NULL;
|
|
|
|
_ephoto_populate_entries(tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-11 21:58:04 -07:00
|
|
|
_ephoto_thumb_selected(void *data, Evas_Object *o __UNUSED__, void *event_info)
|
2010-10-09 18:13:53 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Elm_Gengrid_Item *it = event_info;
|
|
|
|
Ephoto_Entry *e = elm_gengrid_item_data_get(it);
|
|
|
|
|
2010-10-10 18:10:27 -07:00
|
|
|
elm_gengrid_item_selected_set(it, EINA_FALSE);
|
|
|
|
|
2010-10-09 18:13:53 -07:00
|
|
|
if (e->is_dir)
|
|
|
|
ephoto_thumb_browser_directory_set(tb->layout, e->path);
|
|
|
|
else
|
|
|
|
evas_object_smart_callback_call(tb->layout, "view", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-13 19:37:37 -07:00
|
|
|
_changed_dir(void *data, Evas_Object *o __UNUSED__, void *event_info)
|
2010-10-09 18:13:53 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-10-13 19:37:37 -07:00
|
|
|
const char *path = event_info;
|
2010-10-20 05:08:39 -07:00
|
|
|
if (!path) return;
|
2010-10-13 19:37:37 -07:00
|
|
|
ephoto_thumb_browser_directory_set(tb->layout, path);
|
|
|
|
}
|
2010-10-09 18:13:53 -07:00
|
|
|
|
2010-10-13 19:37:37 -07:00
|
|
|
static void
|
|
|
|
_changed_dir_text(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
const char *path = elm_fileselector_entry_path_get(tb->fsel);
|
|
|
|
if (ecore_file_is_dir(path))
|
|
|
|
ephoto_thumb_browser_directory_set(tb->layout, path);
|
2010-10-09 18:13:53 -07:00
|
|
|
}
|
|
|
|
|
2010-10-10 11:57:48 -07:00
|
|
|
static void
|
|
|
|
_zoom_set(Ephoto_Thumb_Browser *tb, int zoom)
|
|
|
|
{
|
|
|
|
if (zoom > ZOOM_MAX) zoom = ZOOM_MAX;
|
|
|
|
else if (zoom < ZOOM_MIN) zoom = ZOOM_MIN;
|
|
|
|
|
|
|
|
ephoto_thumb_size_set(tb->ephoto, zoom);
|
|
|
|
elm_gengrid_item_size_set(tb->grid, zoom, zoom);
|
|
|
|
|
2010-10-12 15:54:20 -07:00
|
|
|
elm_toolbar_item_disabled_set(tb->action.zoom_out, zoom == ZOOM_MIN);
|
|
|
|
elm_toolbar_item_disabled_set(tb->action.zoom_in, zoom == ZOOM_MAX);
|
2010-10-10 11:57:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-12 15:54:20 -07:00
|
|
|
_zoom_in(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
2010-10-10 11:57:48 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-10-26 03:34:07 -07:00
|
|
|
elm_toolbar_item_selected_set(tb->action.zoom_in, EINA_FALSE);
|
2010-10-10 11:57:48 -07:00
|
|
|
_zoom_set(tb, tb->ephoto->config->thumb_size + ZOOM_STEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-12 15:54:20 -07:00
|
|
|
_zoom_out(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
2010-10-10 11:57:48 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-10-26 03:34:07 -07:00
|
|
|
elm_toolbar_item_selected_set(tb->action.zoom_out, EINA_FALSE);
|
2010-10-10 11:57:48 -07:00
|
|
|
_zoom_set(tb, tb->ephoto->config->thumb_size - ZOOM_STEP);
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:54:20 -07:00
|
|
|
static void
|
|
|
|
_view_flow(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid);
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
|
2010-10-26 03:34:07 -07:00
|
|
|
elm_toolbar_item_selected_set(tb->action.view_flow, EINA_FALSE);
|
2010-10-12 15:54:20 -07:00
|
|
|
|
|
|
|
if (it) entry = elm_gengrid_item_data_get(it);
|
|
|
|
else entry = _first_file_entry_find(tb);
|
|
|
|
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->is_dir)
|
|
|
|
ephoto_thumb_browser_directory_set(tb->layout, entry->path);
|
|
|
|
else
|
|
|
|
evas_object_smart_callback_call(tb->layout, "view", entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_slideshow(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid);
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
|
2010-10-26 03:34:07 -07:00
|
|
|
elm_toolbar_item_selected_set(tb->action.slideshow, EINA_FALSE);
|
2010-10-12 15:54:20 -07:00
|
|
|
|
|
|
|
if (it) entry = elm_gengrid_item_data_get(it);
|
|
|
|
else entry = _first_file_entry_find(tb);
|
|
|
|
|
|
|
|
if (!entry) return;
|
|
|
|
evas_object_smart_callback_call(tb->layout, "slideshow", entry);
|
|
|
|
}
|
|
|
|
|
2010-10-11 20:40:14 -07:00
|
|
|
static void
|
2010-10-11 21:58:04 -07:00
|
|
|
_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
|
2010-10-11 20:40:14 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
2010-10-12 10:26:23 -07:00
|
|
|
Eina_Bool alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
|
2010-10-11 20:40:14 -07:00
|
|
|
const char *k = ev->keyname;
|
|
|
|
|
2010-10-12 10:26:23 -07:00
|
|
|
if (alt)
|
|
|
|
{
|
|
|
|
if (!strcmp(k, "Up"))
|
|
|
|
{
|
2010-10-12 22:21:45 -07:00
|
|
|
if (strcmp(tb->ephoto->config->directory, "/") != 0)
|
|
|
|
{
|
|
|
|
char *parent = ecore_file_dir_get
|
|
|
|
(tb->ephoto->config->directory);
|
|
|
|
if (parent)
|
|
|
|
ephoto_thumb_browser_directory_set(tb->layout, parent);
|
|
|
|
free(parent);
|
|
|
|
}
|
2010-10-12 10:26:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-11 20:40:14 -07:00
|
|
|
if (!strcmp(k, "F5"))
|
|
|
|
{
|
|
|
|
Elm_Gengrid_Item *it = elm_gengrid_selected_item_get(tb->grid);
|
|
|
|
Ephoto_Entry *entry;
|
|
|
|
if (it) entry = elm_gengrid_item_data_get(it);
|
|
|
|
else entry = _first_file_entry_find(tb);
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
evas_object_smart_callback_call(tb->layout, "slideshow", entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
static void
|
2010-10-11 21:58:04 -07:00
|
|
|
_layout_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = data;
|
2010-10-13 15:28:23 -07:00
|
|
|
|
|
|
|
_todo_items_free(tb);
|
|
|
|
|
2010-10-12 22:06:18 -07:00
|
|
|
if (tb->pending.cb)
|
|
|
|
{
|
|
|
|
tb->pending.cb((void*)tb->pending.data, NULL);
|
|
|
|
tb->pending.cb = NULL;
|
|
|
|
tb->pending.data = NULL;
|
|
|
|
}
|
|
|
|
eina_stringshare_replace(&tb->pending.path, NULL);
|
|
|
|
if (tb->job.change_dir)
|
|
|
|
{
|
|
|
|
ecore_job_del(tb->job.change_dir);
|
|
|
|
tb->job.change_dir = NULL;
|
|
|
|
}
|
2010-10-13 15:28:23 -07:00
|
|
|
if (tb->animator.todo_items)
|
|
|
|
{
|
|
|
|
ecore_animator_del(tb->animator.todo_items);
|
|
|
|
tb->animator.todo_items = NULL;
|
|
|
|
}
|
2010-10-12 22:06:18 -07:00
|
|
|
if (tb->ls)
|
|
|
|
{
|
|
|
|
tb->layout_deleted = EINA_TRUE;
|
|
|
|
eio_file_cancel(tb->ls);
|
|
|
|
return;
|
|
|
|
}
|
2010-10-09 12:13:35 -07:00
|
|
|
free(tb);
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:54:20 -07:00
|
|
|
static Elm_Toolbar_Item *
|
2010-10-15 10:54:28 -07:00
|
|
|
_toolbar_item_add(Ephoto_Thumb_Browser *tb, const char *icon, const char *label, int priority, Evas_Smart_Cb cb)
|
2010-10-12 15:54:20 -07:00
|
|
|
{
|
2010-10-26 03:34:07 -07:00
|
|
|
Elm_Toolbar_Item *item = elm_toolbar_item_append(tb->toolbar, icon, label,
|
|
|
|
cb, tb);
|
2010-10-15 10:54:28 -07:00
|
|
|
elm_toolbar_item_priority_set(item, priority);
|
|
|
|
return item;
|
2010-10-12 15:54:20 -07:00
|
|
|
}
|
|
|
|
|
2010-10-09 12:13:35 -07:00
|
|
|
Evas_Object *
|
2010-10-09 18:13:53 -07:00
|
|
|
ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
|
|
|
Evas_Object *layout = elm_layout_add(parent);
|
|
|
|
Ephoto_Thumb_Browser *tb;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL);
|
|
|
|
|
|
|
|
tb = calloc(1, sizeof(Ephoto_Thumb_Browser));
|
|
|
|
EINA_SAFETY_ON_NULL_GOTO(tb, error);
|
2010-10-09 18:13:53 -07:00
|
|
|
tb->ephoto = ephoto;
|
2010-10-09 12:13:35 -07:00
|
|
|
tb->layout = layout;
|
2010-10-09 18:13:53 -07:00
|
|
|
tb->edje = elm_layout_edje_get(layout);
|
2010-10-09 12:13:35 -07:00
|
|
|
evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, _layout_del, tb);
|
2010-10-11 20:40:14 -07:00
|
|
|
evas_object_event_callback_add
|
|
|
|
(layout, EVAS_CALLBACK_KEY_DOWN, _key_down, tb);
|
2010-10-09 18:13:53 -07:00
|
|
|
evas_object_data_set(layout, "thumb_browser", tb);
|
2010-10-12 15:54:20 -07:00
|
|
|
|
|
|
|
if (!elm_layout_theme_set
|
2010-10-13 19:37:37 -07:00
|
|
|
(layout, "layout", "application", "toolbar-vbox"))
|
2010-10-12 15:54:20 -07:00
|
|
|
{
|
2010-10-13 19:37:37 -07:00
|
|
|
ERR("could not load style 'toolbar-vbox' from theme");
|
2010-10-12 15:54:20 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
tb->toolbar = edje_object_part_external_object_get
|
|
|
|
(tb->edje, "elm.external.toolbar");
|
|
|
|
if (!tb->toolbar)
|
2010-10-09 12:13:35 -07:00
|
|
|
{
|
2010-10-12 15:54:20 -07:00
|
|
|
ERR("no toolbar in layout!");
|
2010-10-09 12:13:35 -07:00
|
|
|
goto error;
|
|
|
|
}
|
2010-10-12 15:54:20 -07:00
|
|
|
elm_toolbar_homogenous_set(tb->toolbar, EINA_FALSE);
|
2010-10-15 10:54:28 -07:00
|
|
|
elm_toolbar_mode_shrink_set(tb->toolbar, ELM_TOOLBAR_SHRINK_MENU);
|
|
|
|
elm_toolbar_menu_parent_set(tb->toolbar, parent);
|
2010-10-12 15:54:20 -07:00
|
|
|
|
|
|
|
tb->action.slideshow = _toolbar_item_add
|
2010-10-15 10:54:28 -07:00
|
|
|
(tb, "media-playback-start", "Slideshow", 100, _slideshow);
|
2010-10-12 15:54:20 -07:00
|
|
|
tb->action.zoom_in = _toolbar_item_add
|
2010-10-15 10:54:28 -07:00
|
|
|
(tb, "zoom-in", "Zoom In", 50, _zoom_in);
|
2010-10-12 15:54:20 -07:00
|
|
|
tb->action.zoom_out = _toolbar_item_add
|
2010-10-15 10:54:28 -07:00
|
|
|
(tb, "zoom-out", "Zoom Out", 50, _zoom_out);
|
2010-10-12 15:54:20 -07:00
|
|
|
tb->action.view_flow = _toolbar_item_add
|
2010-10-15 10:54:28 -07:00
|
|
|
(tb, "image", "Larger", 50, _view_flow);
|
2010-10-12 15:54:20 -07:00
|
|
|
|
2010-10-13 19:37:37 -07:00
|
|
|
tb->fsel = elm_fileselector_entry_add(layout);
|
|
|
|
EINA_SAFETY_ON_NULL_GOTO(tb->fsel, error);
|
|
|
|
evas_object_size_hint_weight_set(tb->fsel, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(tb->fsel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_fileselector_entry_button_label_set(tb->fsel, "Choose...");
|
|
|
|
elm_fileselector_entry_folder_only_set(tb->fsel, EINA_TRUE);
|
|
|
|
evas_object_smart_callback_add
|
|
|
|
(tb->fsel, "file,chosen", _changed_dir, tb);
|
|
|
|
evas_object_smart_callback_add
|
|
|
|
(tb->fsel, "activated", _changed_dir_text, tb);
|
|
|
|
|
|
|
|
evas_object_show(tb->fsel);
|
|
|
|
elm_layout_box_append(layout, "elm.box.content", tb->fsel);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
|
|
|
tb->grid = elm_gengrid_add(layout);
|
|
|
|
EINA_SAFETY_ON_NULL_GOTO(tb->grid, error);
|
2010-10-13 19:37:37 -07:00
|
|
|
evas_object_size_hint_weight_set
|
|
|
|
(tb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(tb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
2010-10-09 12:13:35 -07:00
|
|
|
elm_object_style_set(tb->grid, "ephoto");
|
|
|
|
|
|
|
|
elm_gengrid_align_set(tb->grid, 0.5, 0.5);
|
|
|
|
elm_gengrid_bounce_set(tb->grid, EINA_FALSE, EINA_TRUE);
|
|
|
|
evas_object_size_hint_align_set
|
|
|
|
(tb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_size_hint_weight_set
|
|
|
|
(tb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
|
|
|
|
evas_object_smart_callback_add
|
|
|
|
(tb->grid, "selected", _ephoto_thumb_selected, tb);
|
|
|
|
|
2010-10-10 11:57:48 -07:00
|
|
|
_zoom_set(tb, tb->ephoto->config->thumb_size);
|
|
|
|
|
2010-10-13 19:37:37 -07:00
|
|
|
evas_object_show(tb->grid);
|
|
|
|
elm_layout_box_append(tb->layout, "elm.box.content", tb->grid);
|
2010-10-09 12:13:35 -07:00
|
|
|
|
|
|
|
return layout;
|
|
|
|
|
|
|
|
error:
|
|
|
|
evas_object_del(layout);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-09 18:13:53 -07:00
|
|
|
void
|
|
|
|
ephoto_thumb_browser_directory_set(Evas_Object *obj, const char *path)
|
2010-09-29 10:34:35 -07:00
|
|
|
{
|
2010-10-09 18:13:53 -07:00
|
|
|
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(tb);
|
2010-09-29 10:34:35 -07:00
|
|
|
|
2010-10-10 18:10:27 -07:00
|
|
|
eina_stringshare_replace(&tb->pending.path, NULL);
|
|
|
|
tb->pending.cb = NULL;
|
|
|
|
tb->pending.data = NULL;
|
|
|
|
|
|
|
|
ephoto_title_set(tb->ephoto, path);
|
|
|
|
|
2010-10-09 18:13:53 -07:00
|
|
|
eina_stringshare_replace(&tb->ephoto->config->directory, path);
|
|
|
|
if (tb->job.change_dir) ecore_job_del(tb->job.change_dir);
|
|
|
|
tb->job.change_dir = ecore_job_add(_ephoto_thumb_change_dir, tb);
|
2010-09-29 10:34:35 -07:00
|
|
|
}
|
2010-10-10 18:10:27 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
ephoto_thumb_browser_path_pending_set(Evas_Object *obj, const char *path, void (*cb)(void *data, Ephoto_Entry *entry), const void *data)
|
|
|
|
{
|
|
|
|
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(tb);
|
|
|
|
eina_stringshare_replace(&tb->pending.path, path);
|
|
|
|
tb->pending.cb = cb;
|
|
|
|
tb->pending.data = data;
|
|
|
|
}
|