EAPI Evas_Object *elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item) EINA_ARG_NONNULL(1);
EAPI void elm_gengrid_item_del(Elm_Gengrid_Item *item) EINA_ARG_NONNULL(1);
EAPI void elm_gengrid_item_update(Elm_Gengrid_Item *item) EINA_ARG_NONNULL(1);
+ EAPI const Elm_Gengrid_Item_Class *elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item) EINA_ARG_NONNULL(1);
+ EAPI void elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item, const Elm_Gengrid_Item_Class *gic) EINA_ARG_NONNULL(1, 2);
EAPI void *elm_gengrid_item_data_get(const Elm_Gengrid_Item *item) EINA_ARG_NONNULL(1);
EAPI void elm_gengrid_item_data_set(Elm_Gengrid_Item *item, const void *data) EINA_ARG_NONNULL(1);
EAPI void elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item, unsigned int *x, unsigned int *y) EINA_ARG_NONNULL(1);
EAPI Elm_Gengrid_Item *elm_gengrid_item_insert_before(Evas_Object *obj, const Elm_Gengrid_Item_Class *gic, const void *data, Elm_Gengrid_Item *relative, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1);
EAPI Elm_Gengrid_Item *elm_gengrid_item_insert_after(Evas_Object *obj, const Elm_Gengrid_Item_Class *gic, const void *data, Elm_Gengrid_Item *relative, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1);
EAPI Elm_Gengrid_Item *elm_gengrid_item_sorted_insert(Evas_Object *obj, const Elm_Gengrid_Item_Class *gic, const void *data, Eina_Compare_Cb comp, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1);
+ EAPI Elm_Gengrid_Item *elm_gengrid_item_direct_sorted_insert(Evas_Object *obj, const Elm_Gengrid_Item_Class *gic, const void *data, Eina_Compare_Cb comp, Evas_Smart_Cb func, const void *func_data);
/* smart callbacks called:
*
* selected - User has selected an item.
EAPI Elm_Genlist_Item *elm_genlist_item_prepend(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1);
EAPI Elm_Genlist_Item *elm_genlist_item_insert_before(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item *before, Elm_Genlist_Item_Flags flags, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1, 5);
EAPI Elm_Genlist_Item *elm_genlist_item_insert_after(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item *after, Elm_Genlist_Item_Flags flags, Evas_Smart_Cb func, const void *func_data) EINA_ARG_NONNULL(1, 5);
-EAPI Elm_Genlist_Item *elm_genlist_item_sorted_insert(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Eina_Compare_Cb comp, Evas_Smart_Cb func,const void *func_data);
+ EAPI Elm_Genlist_Item *elm_genlist_item_sorted_insert(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Eina_Compare_Cb comp, Evas_Smart_Cb func,const void *func_data);
+ EAPI Elm_Genlist_Item *elm_genlist_item_direct_sorted_insert(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Genlist_Item *parent, Elm_Genlist_Item_Flags flags, Eina_Compare_Cb comp, Evas_Smart_Cb func, const void *func_data);
/* operations to retrieve existing items */
EAPI Elm_Genlist_Item *elm_genlist_selected_item_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
EAPI const Eina_List *elm_genlist_selected_items_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
EAPI const Evas_Object *elm_genlist_item_object_get(const Elm_Genlist_Item *it) EINA_ARG_NONNULL(1);
EAPI void elm_genlist_item_update(Elm_Genlist_Item *item) EINA_ARG_NONNULL(1);
EAPI void elm_genlist_item_item_class_update(Elm_Genlist_Item *it, const Elm_Genlist_Item_Class *itc) EINA_ARG_NONNULL(1, 2);
+ EAPI const Elm_Genlist_Item_Class *elm_genlist_item_item_class_get(const Elm_Genlist_Item *it) EINA_ARG_NONNULL(1);
EAPI void elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item, const char *text) EINA_ARG_NONNULL(1);
EAPI void elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb) EINA_ARG_NONNULL(1);
EAPI void elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item) EINA_ARG_NONNULL(1);
#include <Elementary.h>
#include "elm_priv.h"
+#ifdef HAVE_EIO
+# include <Eio.h>
+#endif
+
typedef struct _Widget_Data Widget_Data;
struct _Widget_Data
{
+ EINA_REFCOUNT;
+
Evas_Object *edje;
Evas_Object *filename_entry;
Evas_Object *path_entry;
const char *path_separator;
+#ifdef HAVE_EIO
+ Eio_File *current;
+#endif
+
Elm_Fileselector_Mode mode;
Eina_Bool only_folder : 1;
const char *path;
};
-Elm_Genlist_Item_Class list_itc;
-Elm_Gengrid_Item_Class grid_itc;
+typedef struct _Widget_Request Widget_Request;
+struct _Widget_Request
+{
+ Widget_Data *wd;
+ Elm_Genlist_Item *parent;
+
+ Evas_Object *obj;
+ const char *path;
+ Eina_Bool first : 1;
+};
+
+typedef enum {
+ ELM_DIRECTORY = 0,
+ ELM_FILE_IMAGE = 1,
+ ELM_FILE_UNKNOW = 2,
+ ELM_FILE_LAST
+} Elm_Fileselector_Type;
+
+static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
+ { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
+ { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
+ { "default", { NULL, NULL, NULL, NULL, NULL }, NULL }
+};
+static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
+ { "default", { NULL, NULL, NULL, NULL } },
+ { "default", { NULL, NULL, NULL, NULL } },
+ { "default", { NULL, NULL, NULL, NULL } }
+};
static const char *widtype = NULL;
/*** ELEMENTARY WIDGET ***/
static void
-_del_hook(Evas_Object *obj)
+_widget_data_free(Widget_Data *wd)
{
- Widget_Data *wd;
- void *sd;
-
- wd = elm_widget_data_get(obj);
- if (!wd) return;
-
if (wd->path) eina_stringshare_del(wd->path);
if (wd->selection) eina_stringshare_del(wd->selection);
if (wd->sel_idler)
{
+ void *sd;
+
sd = ecore_idler_del(wd->sel_idler);
free(sd);
}
}
static void
+_del_hook(Evas_Object *obj)
+{
+ Widget_Data *wd;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ eio_file_cancel(wd->current);
+
+ wd->files_list = NULL;
+ wd->files_grid = NULL;
+
+ EINA_REFCOUNT_UNREF(wd)
+ _widget_data_free(wd);
+}
+
+static void
_sizing_eval(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
}
static Evas_Object *
-_itc_icon_get(void *data,
- Evas_Object *obj,
- const char *source)
+_itc_icon_folder_get(void *data __UNUSED__,
+ Evas_Object *obj,
+ const char *source)
{
Evas_Object *ic;
- if (!strcmp(source, "elm.swallow.icon"))
- {
- const char *filename = data;
+ if (strcmp(source, "elm.swallow.icon")) return NULL;
- ic = elm_icon_add(obj);
- if (ecore_file_is_dir((char *)data))
- elm_icon_standard_set(ic, "folder");
- else
- {
- if (evas_object_image_extension_can_load_fast_get(filename))
- {
- elm_icon_standard_set(ic, "image");
- elm_icon_thumb_set(ic, filename, NULL);
- }
- else
- {
- elm_icon_standard_set(ic, "file");
- }
- }
+ ic = elm_icon_add(obj);
+ elm_icon_standard_set(ic, "folder");
- evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
- 1, 1);
- evas_object_show(ic);
- return ic;
- }
- return NULL;
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
+ 1, 1);
+ return ic;
+}
+
+static Evas_Object *
+_itc_icon_image_get(void *data,
+ Evas_Object *obj,
+ const char *source)
+{
+ const char *filename = data;
+ Evas_Object *ic;
+
+ if (strcmp(source, "elm.swallow.icon")) return NULL;
+
+ ic = elm_icon_add(obj);
+ elm_icon_standard_set(ic, "image");
+ elm_icon_thumb_set(ic, filename, NULL);
+
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
+ 1, 1);
+ return ic;
+}
+
+static Evas_Object *
+_itc_icon_file_get(void *data __UNUSED__,
+ Evas_Object *obj,
+ const char *source)
+{
+ Evas_Object *ic;
+
+ if (strcmp(source, "elm.swallow.icon")) return NULL;
+
+ ic = elm_icon_add(obj);
+ elm_icon_standard_set(ic, "file");
+
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
+ 1, 1);
+ return ic;
}
static Eina_Bool
elm_entry_entry_set(wd->path_entry, buf);
}
+#ifdef HAVE_EIO
+static Eina_Bool
+_filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
+{
+ const char *filename;
+
+ if (info->path[info->name_start] == '.')
+ return EINA_FALSE;
+
+ filename = eina_stringshare_add(info->path);
+ eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
+
+ if (info->type == EINA_FILE_DIR)
+ {
+ eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
+ eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
+ }
+ else
+ {
+ if (evas_object_image_extension_can_load_get(info->path + info->name_start))
+ {
+ eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
+ eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
+ }
+ else
+ {
+ eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
+ eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
+ }
+ }
+
+ return EINA_TRUE;
+}
+
+static int
+_file_grid_cmp(const void *a, const void *b)
+{
+ const Elm_Gengrid_Item *ga = a;
+ const Elm_Gengrid_Item *gb = b;
+ const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
+ const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
+
+ if (ca == &grid_itc[ELM_DIRECTORY])
+ {
+ if (cb != &grid_itc[ELM_DIRECTORY])
+ return -1;
+ }
+
+ return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
+}
+
+static int
+_file_list_cmp(const void *a, const void *b)
+{
+ const Elm_Genlist_Item *la = a;
+ const Elm_Genlist_Item *lb = b;
+ const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
+ const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
+
+ if (ca == &list_itc[ELM_DIRECTORY])
+ {
+ if (cb != &list_itc[ELM_DIRECTORY])
+ return -1;
+ }
+
+ return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
+}
+
+static void
+_signal_first(Widget_Request *wr)
+{
+ if (!wr->first) return ;
+ evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
+ if (!wr->parent)
+ {
+ elm_genlist_clear(wr->wd->files_list);
+ elm_gengrid_clear(wr->wd->files_grid);
+ eina_stringshare_replace(&wr->wd->path, wr->path);
+ _do_anchors(wr->obj, wr->path);
+ }
+
+ if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
+
+ wr->first = EINA_FALSE;
+}
+
+static void
+_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
+{
+ Widget_Request *wr = data;
+
+ if (eio_file_check(handler))
+ return ;
+ if (!wr->wd->files_list || !wr->wd->files_grid) return ;
+
+ _signal_first(wr);
+
+ if (wr->wd->mode == ELM_FILESELECTOR_LIST)
+ elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
+ eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
+ wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
+ else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
+ elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
+ eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
+ _file_grid_cmp, NULL, NULL);
+}
+
+static void
+_widget_request_cleanup(Widget_Request *wr)
+{
+ EINA_REFCOUNT_UNREF(wr->wd)
+ _widget_data_free(wr->wd);
+
+ eina_stringshare_del(wr->path);
+ free(wr);
+}
+
+static void
+_done_cb(void *data, Eio_File *handler __UNUSED__)
+{
+ Widget_Request *wr = data;
+
+ _signal_first(wr);
+
+ wr->wd->current = NULL;
+ _widget_request_cleanup(wr);
+}
+
+static void
+_error_cb(void *data, Eio_File *handler, int error __UNUSED__)
+{
+ Widget_Request *wr = data;
+
+ if (wr->wd->current == handler)
+ wr->wd->current = NULL;
+ _widget_request_cleanup(wr);
+}
+
+#endif
+
static void
_populate(Evas_Object *obj,
const char *path,
Elm_Genlist_Item *parent)
{
Widget_Data *wd = elm_widget_data_get(obj);
+#ifdef HAVE_EIO
+ Widget_Request *wr;
+#else
Eina_File_Direct_Info *file;
Eina_Iterator *it;
const char *real;
Eina_List *files = NULL, *dirs = NULL;
+#endif
- if ((!wd) || (!ecore_file_is_dir(path))) return;
+ if (!wd) return;
+#ifndef HAVE_EIO
+ if (!ecore_file_is_dir(path)) return ;
it = eina_file_stat_ls(path);
if (!it) return ;
evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
EINA_LIST_FREE(dirs, real)
{
if (wd->mode == ELM_FILESELECTOR_LIST)
- elm_genlist_item_append(wd->files_list, &list_itc,
+ elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
real, /* item data */
parent,
wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
ELM_GENLIST_ITEM_NONE,
NULL, NULL);
else if (wd->mode == ELM_FILESELECTOR_GRID)
- elm_gengrid_item_append(wd->files_grid, &grid_itc,
+ elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
real, /* item data */
NULL, NULL);
}
EINA_LIST_FREE(files, real)
{
+ Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
+ ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
+
if (wd->mode == ELM_FILESELECTOR_LIST)
- elm_genlist_item_append(wd->files_list, &list_itc,
+ elm_genlist_item_append(wd->files_list, &list_itc[type],
real, /* item data */
parent, ELM_GENLIST_ITEM_NONE,
NULL, NULL);
else if (wd->mode == ELM_FILESELECTOR_GRID)
- elm_gengrid_item_append(wd->files_grid, &grid_itc,
+ elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
real, /* item data */
NULL, NULL);
}
+#else
+ if (wd->current)
+ eio_file_cancel(wd->current);
+ wr = malloc(sizeof (Widget_Request));
+ if (!wr) return ;
+ wr->wd = wd;
+ EINA_REFCOUNT_REF(wr->wd);
+ wr->parent = parent; /* FIXME: should we refcount the parent ? */
+ wr->obj = obj;
+ wr->path = eina_stringshare_add(path);
+ wr->first = EINA_TRUE;
+
+ wd->current = eio_file_stat_ls(path,
+ _filter_cb,
+ _main_cb,
+ _done_cb,
+ _error_cb,
+ wr);
+#endif
}
/*** API ***/
Evas *e;
Evas_Object *obj, *ic, *bt, *li, *en, *grid;
Widget_Data *wd;
+ unsigned int i;
int s;
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
+ EINA_REFCOUNT_INIT(wd);
+
ELM_SET_WIDTYPE(widtype, "fileselector");
elm_widget_type_set(obj, "fileselector");
elm_widget_sub_object_add(parent, obj);
elm_widget_sub_object_add(obj, bt);
wd->home_button = bt;
- list_itc.item_style = grid_itc.item_style = "default";
- list_itc.func.label_get = grid_itc.func.label_get = _itc_label_get;
- list_itc.func.icon_get = grid_itc.func.icon_get = _itc_icon_get;
- list_itc.func.state_get = grid_itc.func.state_get = _itc_state_get;
- list_itc.func.del = grid_itc.func.del = _itc_del;
+ list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
+ list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
+ list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
+
+ for (i = 0; i < ELM_FILE_LAST; ++i)
+ {
+ list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
+ list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
+ list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
+ }
li = elm_genlist_add(parent);
elm_widget_mirrored_automatic_set(li, EINA_FALSE);