998d3b9890218ca929099f11559dd20510011957
[framework/uifw/elementary.git] / src / lib / elc_fileselector.c
1 /*
2  * TODO:
3  *  - child elements focusing support
4  *  - user defined icon/label cb
5  *  - show/hide/add buttons ???
6  *  - show/hide hidden files
7  *  - double click to choose a file
8  *  - multi-selection
9  *  - make variable/function names that are sensible
10  *  - Filter support
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #endif
16
17 #ifdef HAVE_EIO
18 # include <Eio.h>
19 #endif
20
21 #include <Elementary.h>
22 #include "elm_priv.h"
23
24 typedef struct _Widget_Data Widget_Data;
25
26 struct _Widget_Data
27 {
28    EINA_REFCOUNT;
29
30    Evas_Object *edje;
31    Evas_Object *filename_entry;
32    Evas_Object *path_entry;
33    Evas_Object *files_list;
34    Evas_Object *files_grid;
35    Evas_Object *up_button;
36    Evas_Object *home_button;
37
38    Evas_Object *ok_button;
39    Evas_Object *cancel_button;
40
41    const char  *path;
42    const char  *selection;
43    Ecore_Idler *sel_idler;
44
45    const char  *path_separator;
46
47 #ifdef HAVE_EIO
48    Eio_File    *current;
49 #endif
50
51    Elm_Fileselector_Mode mode;
52
53    Eina_Bool    only_folder : 1;
54    Eina_Bool    expand : 1;
55 };
56
57 struct sel_data
58 {
59    Evas_Object *fs;
60    const char  *path;
61 };
62
63 typedef struct _Widget_Request Widget_Request;
64 struct _Widget_Request
65 {
66    Widget_Data *wd;
67    Elm_Object_Item *parent;
68
69    Evas_Object *obj;
70    const char *path;
71    Eina_Bool first : 1;
72 };
73
74 typedef enum {
75   ELM_DIRECTORY = 0,
76   ELM_FILE_IMAGE = 1,
77   ELM_FILE_UNKNOW = 2,
78   ELM_FILE_LAST
79 } Elm_Fileselector_Type;
80
81 <<<<<<< HEAD
82 static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
83   { "default", { NULL, NULL, NULL, NULL } },
84   { "default", { NULL, NULL, NULL, NULL } },
85   { "default", { NULL, NULL, NULL, NULL } }
86 };
87 static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
88   { "default", { NULL, NULL, NULL, NULL } },
89   { "default", { NULL, NULL, NULL, NULL } },
90   { "default", { NULL, NULL, NULL, NULL } }
91 };
92 =======
93 static Elm_Genlist_Item_Class *list_itc[ELM_FILE_LAST];
94 static Elm_Gengrid_Item_Class *grid_itc[ELM_FILE_LAST];
95 >>>>>>> remotes/origin/upstream
96
97 static const char *widtype = NULL;
98
99 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
100 static const char SIG_DONE[] = "done";
101 static const char SIG_SELECTED[] = "selected";
102 static const Evas_Smart_Cb_Description _signals[] = {
103    {SIG_DIRECTORY_OPEN, "s"},
104    {SIG_DONE, "s"},
105    {SIG_SELECTED, "s"},
106    {NULL, NULL}
107 };
108
109 static void _populate(Evas_Object      *obj,
110                       const char       *path,
111                       Elm_Object_Item  *parent);
112 static void _do_anchors(Evas_Object *obj,
113                         const char  *path);
114
115 /***  ELEMENTARY WIDGET  ***/
116 static void
117 _widget_data_free(Widget_Data *wd)
118 {
119    if (wd->path) eina_stringshare_del(wd->path);
120    if (wd->selection) eina_stringshare_del(wd->selection);
121    if (wd->sel_idler)
122      {
123         void *sd;
124
125         sd = ecore_idler_del(wd->sel_idler);
126         free(sd);
127      }
128    free(wd);
129 }
130
131 static void
132 _del_hook(Evas_Object *obj)
133 {
134    Widget_Data *wd;
135 <<<<<<< HEAD
136 =======
137    int i;
138 >>>>>>> remotes/origin/upstream
139
140    wd = elm_widget_data_get(obj);
141    if (!wd) return;
142
143 <<<<<<< HEAD
144 =======
145    for (i = 0; i < ELM_FILE_LAST; ++i)
146      {
147         elm_genlist_item_class_free(list_itc[i]);
148         elm_gengrid_item_class_free(grid_itc[i]);
149      }
150
151 >>>>>>> remotes/origin/upstream
152 #ifdef HAVE_EIO
153    if (wd->current)
154      eio_file_cancel(wd->current);
155 #endif
156
157    wd->files_list = NULL;
158    wd->files_grid = NULL;
159
160    EINA_REFCOUNT_UNREF(wd)
161      _widget_data_free(wd);
162 }
163
164 static void
165 _sizing_eval(Evas_Object *obj)
166 {
167    Widget_Data *wd = elm_widget_data_get(obj);
168    Evas_Coord minw = -1, minh = -1;
169    if (!wd) return;
170    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
171    edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
172    evas_object_size_hint_min_set(obj, minw, minh);
173 }
174
175 static void
176 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
177 {
178    Widget_Data *wd = elm_widget_data_get(obj);
179    if (!wd) return;
180    elm_widget_mirrored_set(wd->cancel_button, rtl);
181    elm_widget_mirrored_set(wd->ok_button, rtl);
182    elm_widget_mirrored_set(wd->files_list, rtl);
183    elm_widget_mirrored_set(wd->up_button, rtl);
184    elm_widget_mirrored_set(wd->home_button, rtl);
185    edje_object_mirrored_set(wd->edje, rtl);
186 }
187
188 static void
189 _theme_hook(Evas_Object *obj)
190 {
191    Widget_Data *wd = elm_widget_data_get(obj);
192    const char *style = elm_widget_style_get(obj);
193    const char *data;
194    char buf[1024];
195
196    if (!wd) return;
197    _elm_widget_mirrored_reload(obj);
198
199    _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
200
201    if (elm_object_disabled_get(obj))
202      edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
203
204    data = edje_object_data_get(wd->edje, "path_separator");
205    if (data)
206      wd->path_separator = data;
207    else
208      wd->path_separator = "/";
209
210    if (!style) style = "default";
211    snprintf(buf, sizeof(buf), "fileselector/%s", style);
212
213 #define SWALLOW(part_name, object_ptn)                                \
214   if (object_ptn)                                                     \
215     {                                                                 \
216        elm_widget_style_set(object_ptn, buf);                         \
217        if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
218          evas_object_show(object_ptn);                                \
219        else                                                           \
220          evas_object_hide(object_ptn);                                \
221     }
222    SWALLOW("elm.swallow.up", wd->up_button);
223    SWALLOW("elm.swallow.home", wd->home_button);
224
225    if (wd->mode == ELM_FILESELECTOR_LIST)
226      {
227         if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
228                                      wd->files_list))
229           {
230              evas_object_show(wd->files_list);
231              evas_object_hide(wd->files_grid);
232           }
233         else
234           evas_object_hide(wd->files_list);
235      }
236    else
237      {
238         if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
239                                      wd->files_grid))
240           {
241              evas_object_show(wd->files_grid);
242              evas_object_hide(wd->files_list);
243           }
244         else
245           evas_object_hide(wd->files_grid);
246      }
247
248    SWALLOW("elm.swallow.filename", wd->filename_entry);
249    SWALLOW("elm.swallow.path", wd->path_entry);
250
251    snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
252    SWALLOW("elm.swallow.cancel", wd->cancel_button);
253    SWALLOW("elm.swallow.ok", wd->ok_button);
254 #undef SWALLOW
255
256    edje_object_message_signal_process(wd->edje);
257    _mirrored_set(obj, elm_widget_mirrored_get(obj));
258    edje_object_scale_set
259      (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
260    _sizing_eval(obj);
261 }
262
263 /***  GENLIST "MODEL"  ***/
264 static char *
265 _itc_text_get(void              *data,
266                Evas_Object *obj   __UNUSED__,
267                const char *source __UNUSED__)
268 {
269    return strdup(ecore_file_file_get(data)); /* NOTE this will be
270                                               * free() by the
271                                               * caller */
272 }
273
274 static Evas_Object *
275 _itc_icon_folder_get(void        *data __UNUSED__,
276                      Evas_Object *obj,
277                      const char  *source)
278 {
279    Evas_Object *ic;
280
281    if (strcmp(source, "elm.swallow.icon")) return NULL;
282
283    ic = elm_icon_add(obj);
284    elm_icon_standard_set(ic, "folder");
285
286    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
287                                     1, 1);
288    return ic;
289 }
290
291 static Evas_Object *
292 _itc_icon_image_get(void        *data,
293                     Evas_Object *obj,
294                     const char  *source)
295 {
296    const char *filename = data;
297    Evas_Object *ic;
298
299    if (strcmp(source, "elm.swallow.icon")) return NULL;
300
301    ic = elm_icon_add(obj);
302    elm_icon_standard_set(ic, "image");
303    elm_icon_thumb_set(ic, filename, NULL);
304
305    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
306                                     1, 1);
307    return ic;
308 }
309
310 static Evas_Object *
311 _itc_icon_file_get(void        *data __UNUSED__,
312                    Evas_Object *obj,
313                    const char  *source)
314 {
315    Evas_Object *ic;
316
317    if (strcmp(source, "elm.swallow.icon")) return NULL;
318
319    ic = elm_icon_add(obj);
320    elm_icon_standard_set(ic, "file");
321
322    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
323                                     1, 1);
324    return ic;
325 }
326
327 static Eina_Bool
328 _itc_state_get(void *data         __UNUSED__,
329                Evas_Object *obj   __UNUSED__,
330                const char *source __UNUSED__)
331 {
332    return EINA_FALSE;
333 }
334
335 static void
336 _itc_del(void            *data,
337          Evas_Object *obj __UNUSED__)
338 {
339    eina_stringshare_del(data);
340 }
341
342 static void
343 _expand_done(void            *data,
344              Evas_Object *obj __UNUSED__,
345              void            *event_info)
346 {
347    Elm_Object_Item *it = event_info;
348    const char *path = elm_object_item_data_get(it);
349    _populate(data, path, it);
350 }
351
352 static void
353 _contract_done(void *data       __UNUSED__,
354                Evas_Object *obj __UNUSED__,
355                void            *event_info)
356 {
357    Elm_Object_Item *it = event_info;
358    elm_genlist_item_subitems_clear(it);
359 }
360
361 static void
362 _expand_req(void *data       __UNUSED__,
363             Evas_Object *obj __UNUSED__,
364             void            *event_info)
365 {
366    Elm_Object_Item *it = event_info;
367    elm_genlist_item_expanded_set(it, EINA_TRUE);
368 }
369
370 static void
371 _contract_req(void *data       __UNUSED__,
372               Evas_Object *obj __UNUSED__,
373               void            *event_info)
374 {
375    Elm_Object_Item *it = event_info;
376    elm_genlist_item_expanded_set(it, EINA_FALSE);
377 }
378
379 /***  PRIVATES  ***/
380 static Eina_Bool
381 _sel_do(void *data)
382 {
383    struct sel_data *sd;
384    const char *path;
385    Widget_Data *wd;
386    const char *p;
387
388    sd = data;
389    wd = elm_widget_data_get(sd->fs);
390    path = sd->path;
391
392    if ((!wd->only_folder) && ecore_file_is_dir(path))
393      {
394         if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
395           {
396              _do_anchors(sd->fs, path);
397              elm_object_text_set(wd->filename_entry, "");
398           }
399         else
400           {
401              /* keep a ref to path 'couse it will be destroyed by _populate */
402              p = eina_stringshare_add(path);
403              _populate(sd->fs, p, NULL);
404              eina_stringshare_del(p);
405           }
406         goto end;
407      }
408    else /* navigating through folders only or file is not a dir. */
409      {
410         if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
411           _do_anchors(sd->fs, path);
412         else if (wd->only_folder)
413           {
414              /* keep a ref to path 'couse it will be destroyed by _populate */
415              p = eina_stringshare_add(path);
416              _populate(sd->fs, p, NULL);
417              eina_stringshare_del(p);
418           }
419         elm_object_text_set(wd->filename_entry,
420                                      ecore_file_file_get(path));
421      }
422
423    evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
424
425 end:
426    wd->sel_idler = NULL;
427    free(sd);
428    return ECORE_CALLBACK_CANCEL;
429 }
430
431 static void
432 _sel(void            *data,
433      Evas_Object *obj __UNUSED__,
434      void            *event_info)
435 {
436    struct sel_data *sd;
437    Widget_Data *wd;
438    void *old_sd;
439    char *dir;
440 <<<<<<< HEAD
441 =======
442    //This event_info could be a list or gengrid item
443    Elm_Object_Item *it = event_info;
444 >>>>>>> remotes/origin/upstream
445
446    wd = elm_widget_data_get(data);
447    if (!wd) return;
448
449    sd = malloc(sizeof(*sd));
450    sd->fs = data;
451 <<<<<<< HEAD
452    sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
453        elm_object_item_data_get(event_info) :
454        elm_gengrid_item_data_get(event_info);
455 =======
456    sd->path = elm_object_item_data_get(it);
457 >>>>>>> remotes/origin/upstream
458
459    if (!sd->path)
460      {
461         eina_stringshare_replace(&wd->path, "");
462         goto end;
463      }
464
465    dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
466    if (dir)
467      {
468         eina_stringshare_replace(&wd->path, dir);
469         free(dir);
470      }
471    else
472      {
473         eina_stringshare_replace(&wd->path, "");
474      }
475
476 end:
477    if (wd->sel_idler)
478      {
479         old_sd = ecore_idler_del(wd->sel_idler);
480         free(old_sd);
481      }
482    wd->sel_idler = ecore_idler_add(_sel_do, sd);
483 }
484
485 static void
486 _up(void            *data,
487     Evas_Object *obj __UNUSED__,
488     void *event_info __UNUSED__)
489 {
490    Evas_Object *fs = data;
491    char *parent;
492
493    Widget_Data *wd = elm_widget_data_get(fs);
494    if (!wd) return;
495    parent = ecore_file_dir_get(wd->path);
496    _populate(fs, parent, NULL);
497    free(parent);
498 }
499
500 static void
501 _home(void            *data,
502       Evas_Object *obj __UNUSED__,
503       void *event_info __UNUSED__)
504 {
505    Evas_Object *fs = data;
506    _populate(fs, getenv("HOME"), NULL);
507 }
508
509 static void
510 _ok(void            *data,
511     Evas_Object *obj __UNUSED__,
512     void *event_info __UNUSED__)
513 {
514    Evas_Object *fs = data;
515    evas_object_smart_callback_call(fs, SIG_DONE,
516                                    (void *)elm_fileselector_selected_get(fs));
517 }
518
519 static void
520 _canc(void            *data,
521       Evas_Object *obj __UNUSED__,
522       void *event_info __UNUSED__)
523 {
524    Evas_Object *fs = data;
525    evas_object_smart_callback_call(fs, SIG_DONE, NULL);
526 }
527
528 static void
529 _anchor_clicked(void            *data,
530                 Evas_Object *obj __UNUSED__,
531                 void            *event_info)
532 {
533    Evas_Object *fs = data;
534    Widget_Data *wd = elm_widget_data_get(fs);
535    Elm_Entry_Anchor_Info *info = event_info;
536    const char *p;
537    if (!wd) return;
538    // keep a ref to path 'couse it will be destroyed by _populate
539    p = eina_stringshare_add(info->name);
540    _populate(fs, p, NULL);
541    evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
542    eina_stringshare_del(p);
543 }
544
545 static void
546 _do_anchors(Evas_Object *obj,
547             const char  *path)
548 {
549    Widget_Data *wd = elm_widget_data_get(obj);
550    char **tok, buf[PATH_MAX * 3];
551    int i, j;
552    if (!wd) return;
553    buf[0] = '\0';
554    tok = eina_str_split(path, "/", 0);
555    eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
556    for (i = 0; tok[i]; i++)
557      {
558         if ((!tok[i]) || (!tok[i][0])) continue;
559         eina_strlcat(buf, wd->path_separator, sizeof(buf));
560         eina_strlcat(buf, "<a href=", sizeof(buf));
561         for (j = 0; j <= i; j++)
562           {
563              if (strlen(tok[j]) < 1) continue;
564              eina_strlcat(buf, "/", sizeof(buf));
565              eina_strlcat(buf, tok[j], sizeof(buf));
566           }
567         eina_strlcat(buf, ">", sizeof(buf));
568         eina_strlcat(buf, tok[i], sizeof(buf));
569         eina_strlcat(buf, "</a>", sizeof(buf));
570      }
571    free(tok[0]);
572    free(tok);
573
574    elm_object_text_set(wd->path_entry, buf);
575 }
576
577 #ifdef HAVE_EIO
578 static Eina_Bool
579 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
580 {
581    const char *filename;
582
583    if (info->path[info->name_start] == '.')
584      return EINA_FALSE;
585
586    filename = eina_stringshare_add(info->path);
587    eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
588
589    if (info->type == EINA_FILE_DIR)
590      {
591 <<<<<<< HEAD
592         eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
593         eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
594 =======
595         eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_DIRECTORY], NULL);
596         eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_DIRECTORY], NULL);
597 >>>>>>> remotes/origin/upstream
598      }
599    else
600      {
601         if (evas_object_image_extension_can_load_get(info->path + info->name_start))
602           {
603 <<<<<<< HEAD
604              eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
605              eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
606           }
607         else
608           {
609              eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
610              eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
611 =======
612              eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_FILE_IMAGE], NULL);
613              eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_IMAGE], NULL);
614           }
615         else
616           {
617              eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_FILE_UNKNOW], NULL);
618              eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_UNKNOW], NULL);
619 >>>>>>> remotes/origin/upstream
620           }
621      }
622
623    return EINA_TRUE;
624 }
625
626 static int
627 _file_grid_cmp(const void *a, const void *b)
628 {
629 <<<<<<< HEAD
630    const Elm_Gengrid_Item *ga = a;
631    const Elm_Gengrid_Item *gb = b;
632    const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
633    const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
634
635    if (ca == &grid_itc[ELM_DIRECTORY])
636      {
637         if (cb != &grid_itc[ELM_DIRECTORY])
638           return -1;
639      }
640    else if (cb == &grid_itc[ELM_DIRECTORY])
641 =======
642    const Elm_Object_Item *ga = a;
643    const Elm_Object_Item *gb = b;
644    const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
645    const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
646
647    if (ca == grid_itc[ELM_DIRECTORY])
648      {
649         if (cb != grid_itc[ELM_DIRECTORY])
650           return -1;
651      }
652    else if (cb == grid_itc[ELM_DIRECTORY])
653 >>>>>>> remotes/origin/upstream
654      {
655         return 1;
656      }
657
658 <<<<<<< HEAD
659    return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
660 =======
661    return strcoll(elm_object_item_data_get(ga), elm_object_item_data_get(gb));
662 >>>>>>> remotes/origin/upstream
663 }
664
665 static int
666 _file_list_cmp(const void *a, const void *b)
667 {
668    const Elm_Object_Item *la = a;
669    const Elm_Object_Item *lb = b;
670    const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
671    const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
672
673 <<<<<<< HEAD
674    if (ca == &list_itc[ELM_DIRECTORY])
675      {
676         if (cb != &list_itc[ELM_DIRECTORY])
677           return -1;
678      }
679    else if (cb == &list_itc[ELM_DIRECTORY])
680 =======
681    if (ca == list_itc[ELM_DIRECTORY])
682      {
683         if (cb != list_itc[ELM_DIRECTORY])
684           return -1;
685      }
686    else if (cb == list_itc[ELM_DIRECTORY])
687 >>>>>>> remotes/origin/upstream
688      {
689         return 1;
690      }
691
692    return strcoll(elm_object_item_data_get(la), elm_object_item_data_get(lb));
693 }
694
695 static void
696 _signal_first(Widget_Request *wr)
697 {
698    if (!wr->first) return ;
699    evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
700    if (!wr->parent)
701      {
702         elm_genlist_clear(wr->wd->files_list);
703         elm_gengrid_clear(wr->wd->files_grid);
704         eina_stringshare_replace(&wr->wd->path, wr->path);
705         _do_anchors(wr->obj, wr->path);
706      }
707
708    if (wr->wd->filename_entry) elm_object_text_set(wr->wd->filename_entry, "");
709
710    wr->first = EINA_FALSE;
711 }
712
713 static void
714 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
715 {
716    Widget_Request *wr = data;
717
718    if (eio_file_check(handler))
719      return ;
720    if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
721      {
722         eio_file_cancel(handler);
723         return ;
724      }
725
726    _signal_first(wr);
727
728    if (wr->wd->mode == ELM_FILESELECTOR_LIST)
729      {
730 <<<<<<< HEAD
731         Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == &list_itc[ELM_DIRECTORY]);
732
733         elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
734                                               eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
735                                               wr->parent, wr->wd->expand && is_dir ? ELM_GENLIST_ITEM_SUBITEMS : ELM_GENLIST_ITEM_NONE,
736                                               _file_list_cmp, NULL, NULL);
737      }
738    else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
739      elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
740 =======
741         Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == list_itc[ELM_DIRECTORY]);
742
743         elm_genlist_item_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
744                                        eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
745                                        wr->parent, wr->wd->expand && is_dir ? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE,
746                                        _file_list_cmp, NULL, NULL);
747      }
748    else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
749      elm_gengrid_item_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
750 >>>>>>> remotes/origin/upstream
751                                            eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
752                                            _file_grid_cmp, NULL, NULL);
753 }
754
755 static void
756 _widget_request_cleanup(Widget_Request *wr)
757 {
758    EINA_REFCOUNT_UNREF(wr->wd)
759      _widget_data_free(wr->wd);
760
761    eina_stringshare_del(wr->path);
762    free(wr);
763 }
764
765 static void
766 _done_cb(void *data, Eio_File *handler __UNUSED__)
767 {
768    Widget_Request *wr = data;
769
770    _signal_first(wr);
771
772    wr->wd->current = NULL;
773    _widget_request_cleanup(wr);
774 }
775
776 static void
777 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
778 {
779    Widget_Request *wr = data;
780
781    if (wr->wd->current == handler)
782      wr->wd->current = NULL;
783    _widget_request_cleanup(wr);
784 }
785
786 #endif
787
788 static void
789 _populate(Evas_Object      *obj,
790           const char       *path,
791           Elm_Object_Item  *parent)
792 {
793    Widget_Data *wd = elm_widget_data_get(obj);
794 #ifdef HAVE_EIO
795    Widget_Request *wr;
796 #else
797    Eina_File_Direct_Info *file;
798    Eina_Iterator *it;
799    const char *real;
800    Eina_List *files = NULL, *dirs = NULL;
801 #endif
802
803    if (!wd) return;
804 #ifndef HAVE_EIO
805    if (!ecore_file_is_dir(path)) return ;
806    it = eina_file_stat_ls(path);
807    if (!it) return ;
808    evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
809    if (!parent)
810      {
811         elm_genlist_clear(wd->files_list);
812         elm_gengrid_clear(wd->files_grid);
813         eina_stringshare_replace(&wd->path, path);
814         _do_anchors(obj, path);
815      }
816
817    if (wd->filename_entry) elm_object_text_set(wd->filename_entry, "");
818    EINA_ITERATOR_FOREACH(it, file)
819      {
820         const char *filename;
821
822         if (file->path[file->name_start] == '.')
823           continue ;
824
825         filename = eina_stringshare_add(file->path);
826         if (file->type == EINA_FILE_DIR)
827           dirs = eina_list_append(dirs, filename);
828         else if (!wd->only_folder)
829           files = eina_list_append(files, filename);
830      }
831    eina_iterator_free(it);
832
833    files = eina_list_sort(files, eina_list_count(files),
834                           EINA_COMPARE_CB(strcoll));
835    dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
836    EINA_LIST_FREE(dirs, real)
837      {
838         if (wd->mode == ELM_FILESELECTOR_LIST)
839 <<<<<<< HEAD
840           elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
841                                   real, /* item data */
842                                   parent,
843                                   wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
844                                   ELM_GENLIST_ITEM_NONE,
845                                   NULL, NULL);
846         else if (wd->mode == ELM_FILESELECTOR_GRID)
847           elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
848 =======
849           elm_genlist_item_append(wd->files_list, list_itc[ELM_DIRECTORY],
850                                   real, /* item data */
851                                   parent,
852                                   wd->expand ? ELM_GENLIST_ITEM_TREE :
853                                   ELM_GENLIST_ITEM_NONE,
854                                   NULL, NULL);
855         else if (wd->mode == ELM_FILESELECTOR_GRID)
856           elm_gengrid_item_append(wd->files_grid, grid_itc[ELM_DIRECTORY],
857 >>>>>>> remotes/origin/upstream
858                                   real, /* item data */
859                                   NULL, NULL);
860      }
861
862    EINA_LIST_FREE(files, real)
863      {
864         Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
865           ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
866
867         if (wd->mode == ELM_FILESELECTOR_LIST)
868 <<<<<<< HEAD
869           elm_genlist_item_append(wd->files_list, &list_itc[type],
870 =======
871           elm_genlist_item_append(wd->files_list, list_itc[type],
872 >>>>>>> remotes/origin/upstream
873                                   real, /* item data */
874                                   parent, ELM_GENLIST_ITEM_NONE,
875                                   NULL, NULL);
876         else if (wd->mode == ELM_FILESELECTOR_GRID)
877 <<<<<<< HEAD
878           elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
879 =======
880           elm_gengrid_item_append(wd->files_grid, grid_itc[type],
881 >>>>>>> remotes/origin/upstream
882                                   real, /* item data */
883                                   NULL, NULL);
884      }
885 #else
886 <<<<<<< HEAD
887 =======
888    if (wd->expand && wd->current) return ;
889 >>>>>>> remotes/origin/upstream
890    if (wd->current)
891      eio_file_cancel(wd->current);
892    wr = malloc(sizeof (Widget_Request));
893    if (!wr) return ;
894    wr->wd = wd;
895    EINA_REFCOUNT_REF(wr->wd);
896    wr->parent = parent; /* FIXME: should we refcount the parent ? */
897    wr->obj = obj;
898    wr->path = eina_stringshare_add(path);
899    wr->first = EINA_TRUE;
900
901    wd->current = eio_file_stat_ls(path,
902                                   _filter_cb,
903                                   _main_cb,
904                                   _done_cb,
905                                   _error_cb,
906                                   wr);
907 #endif
908 }
909
910 /***  API  ***/
911
912 EAPI Evas_Object *
913 elm_fileselector_add(Evas_Object *parent)
914 {
915    Evas *e;
916    Evas_Object *obj, *ic, *bt, *li, *en, *grid;
917    Widget_Data *wd;
918    unsigned int i;
919    int s;
920
921    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
922
923    EINA_REFCOUNT_INIT(wd);
924
925    ELM_SET_WIDTYPE(widtype, "fileselector");
926    elm_widget_type_set(obj, "fileselector");
927    elm_widget_sub_object_add(parent, obj);
928    elm_widget_data_set(obj, wd);
929    elm_widget_del_hook_set(obj, _del_hook);
930    elm_widget_theme_hook_set(obj, _theme_hook);
931    elm_widget_can_focus_set(obj, EINA_FALSE);
932
933    wd->expand = !!_elm_config->fileselector_expand_enable;
934
935    wd->edje = edje_object_add(e);
936    _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
937    elm_widget_resize_object_set(obj, wd->edje);
938
939    // up btn
940    ic = elm_icon_add(parent);
941    elm_icon_standard_set(ic, "arrow_up");
942    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
943    bt = elm_button_add(parent);
944    elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
945    elm_object_part_content_set(bt, "icon", ic);
946    elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Up"));
947    evas_object_size_hint_align_set(bt, 0.0, 0.0);
948
949    evas_object_smart_callback_add(bt, "clicked", _up, obj);
950
951    elm_widget_sub_object_add(obj, bt);
952    wd->up_button = bt;
953
954    // home btn
955    ic = elm_icon_add(parent);
956    elm_icon_standard_set(ic, "home");
957    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
958    bt = elm_button_add(parent);
959    elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
960    elm_object_part_content_set(bt, "icon", ic);
961    elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Home"));
962    evas_object_size_hint_align_set(bt, 0.0, 0.0);
963
964    evas_object_smart_callback_add(bt, "clicked", _home, obj);
965
966    elm_widget_sub_object_add(obj, bt);
967    wd->home_button = bt;
968
969 <<<<<<< HEAD
970    list_itc[ELM_DIRECTORY].func.content_get = grid_itc[ELM_DIRECTORY].func.content_get = _itc_icon_folder_get;
971    list_itc[ELM_FILE_IMAGE].func.content_get = grid_itc[ELM_FILE_IMAGE].func.content_get = _itc_icon_image_get;
972    list_itc[ELM_FILE_UNKNOW].func.content_get = grid_itc[ELM_FILE_UNKNOW].func.content_get = _itc_icon_file_get;
973
974    for (i = 0; i < ELM_FILE_LAST; ++i)
975      {
976         list_itc[i].func.text_get = grid_itc[i].func.text_get = _itc_text_get;
977         list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
978         list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
979      }
980
981 =======
982    for (i = 0; i < ELM_FILE_LAST; ++i)
983      {
984         list_itc[i] = elm_genlist_item_class_new();
985         grid_itc[i] = elm_gengrid_item_class_new();
986
987         list_itc[i]->item_style = "default";
988         list_itc[i]->func.text_get = grid_itc[i]->func.text_get = _itc_text_get;
989         list_itc[i]->func.state_get = grid_itc[i]->func.state_get = _itc_state_get;
990         list_itc[i]->func.del = grid_itc[i]->func.del = _itc_del;
991      }
992
993    list_itc[ELM_DIRECTORY]->func.content_get =
994      grid_itc[ELM_DIRECTORY]->func.content_get = _itc_icon_folder_get;
995    list_itc[ELM_FILE_IMAGE]->func.content_get =
996      grid_itc[ELM_FILE_IMAGE]->func.content_get = _itc_icon_image_get;
997    list_itc[ELM_FILE_UNKNOW]->func.content_get =
998      grid_itc[ELM_FILE_UNKNOW]->func.content_get = _itc_icon_file_get;
999
1000 >>>>>>> remotes/origin/upstream
1001    li = elm_genlist_add(parent);
1002    elm_widget_mirrored_automatic_set(li, EINA_FALSE);
1003    evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
1004    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1005    evas_object_size_hint_min_set(li, 100, 100);
1006
1007    grid = elm_gengrid_add(parent);
1008    elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
1009    evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
1010    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1011
1012 <<<<<<< HEAD
1013    s = elm_finger_size_get() * 2;
1014 =======
1015    // XXX: will fail for dynamic finger size changing
1016    s = _elm_config->finger_size * 2;
1017 >>>>>>> remotes/origin/upstream
1018    elm_gengrid_item_size_set(grid, s, s);
1019    elm_gengrid_align_set(grid, 0.0, 0.0);
1020
1021    evas_object_smart_callback_add(li, "selected", _sel, obj);
1022    evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
1023    evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
1024    evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
1025    evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
1026
1027    evas_object_smart_callback_add(grid, "selected", _sel, obj);
1028
1029    elm_widget_sub_object_add(obj, li);
1030    elm_widget_sub_object_add(obj, grid);
1031    wd->files_list = li;
1032    wd->files_grid = grid;
1033
1034    // path entry
1035    en = elm_entry_add(parent);
1036    elm_entry_scrollable_set(en, EINA_TRUE);
1037    elm_widget_mirrored_automatic_set(en, EINA_FALSE);
1038    elm_entry_editable_set(en, EINA_FALSE);
1039    elm_entry_single_line_set(en, EINA_TRUE);
1040    elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
1041    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1042    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
1043
1044    evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
1045
1046    elm_widget_sub_object_add(obj, en);
1047    wd->path_entry = en;
1048
1049    // filename entry
1050    en = elm_entry_add(parent);
1051    elm_entry_scrollable_set(en, EINA_TRUE);
1052    elm_widget_mirrored_automatic_set(en, EINA_FALSE);
1053    elm_entry_editable_set(en, EINA_TRUE);
1054    elm_entry_single_line_set(en, EINA_TRUE);
1055    elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
1056    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1057    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
1058
1059    elm_widget_sub_object_add(obj, en);
1060    wd->filename_entry = en;
1061
1062    elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
1063    elm_fileselector_is_save_set(obj, EINA_FALSE);
1064
1065    _theme_hook(obj);
1066
1067    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1068    return obj;
1069 }
1070
1071 EAPI void
1072 elm_fileselector_is_save_set(Evas_Object *obj,
1073                              Eina_Bool    is_save)
1074 {
1075    ELM_CHECK_WIDTYPE(obj, widtype);
1076    Widget_Data *wd = elm_widget_data_get(obj);
1077    if (!wd) return;
1078
1079    elm_object_disabled_set(wd->filename_entry, !is_save);
1080
1081    if (is_save)
1082      edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
1083    else
1084      edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
1085 }
1086
1087 EAPI Eina_Bool
1088 elm_fileselector_is_save_get(const Evas_Object *obj)
1089 {
1090    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1091    Widget_Data *wd = elm_widget_data_get(obj);
1092    if (!wd) return EINA_FALSE;
1093 <<<<<<< HEAD
1094    return elm_object_disabled_get(wd->filename_entry);
1095 =======
1096    return !elm_object_disabled_get(wd->filename_entry);
1097 >>>>>>> remotes/origin/upstream
1098 }
1099
1100 EAPI void
1101 elm_fileselector_folder_only_set(Evas_Object *obj,
1102                                  Eina_Bool    only)
1103 {
1104    ELM_CHECK_WIDTYPE(obj, widtype);
1105    Widget_Data *wd = elm_widget_data_get(obj);
1106    if (!wd) return;
1107    if (wd->only_folder == only) return;
1108    wd->only_folder = !!only;
1109    if (wd->path) _populate(obj, wd->path, NULL);
1110 }
1111
1112 EAPI Eina_Bool
1113 elm_fileselector_folder_only_get(const Evas_Object *obj)
1114 {
1115    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1116    Widget_Data *wd = elm_widget_data_get(obj);
1117    if (!wd) return EINA_FALSE;
1118    return wd->only_folder;
1119 }
1120
1121 EAPI void
1122 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1123                                        Eina_Bool    visible)
1124 {
1125    ELM_CHECK_WIDTYPE(obj, widtype);
1126    Widget_Data *wd = elm_widget_data_get(obj);
1127    Evas_Object *bt;
1128    if (!wd) return;
1129
1130    if (visible)
1131      {
1132         // cancel btn
1133         bt = elm_button_add(obj);
1134         elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1135         elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Cancel"));
1136
1137         evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1138
1139         elm_widget_sub_object_add(obj, bt);
1140         wd->cancel_button = bt;
1141
1142         // ok btn
1143         bt = elm_button_add(obj);
1144         elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1145         elm_object_domain_translatable_text_set(bt, PACKAGE, N_("OK"));
1146
1147         evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1148
1149         elm_widget_sub_object_add(obj, bt);
1150         wd->ok_button = bt;
1151
1152         _theme_hook(obj);
1153      }
1154    else
1155      {
1156         evas_object_del(wd->cancel_button);
1157         wd->cancel_button = NULL;
1158         evas_object_del(wd->ok_button);
1159         wd->ok_button = NULL;
1160      }
1161 }
1162
1163 EAPI Eina_Bool
1164 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1165 {
1166    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1167    Widget_Data *wd = elm_widget_data_get(obj);
1168    if (!wd) return EINA_FALSE;
1169    return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1170 }
1171
1172 EAPI void
1173 elm_fileselector_expandable_set(Evas_Object *obj,
1174                                 Eina_Bool    expand)
1175 {
1176    ELM_CHECK_WIDTYPE(obj, widtype);
1177    Widget_Data *wd;
1178
1179    wd = elm_widget_data_get(obj);
1180    if (!wd) return;
1181
1182    wd->expand = !!expand;
1183
1184    if (wd->path) _populate(obj, wd->path, NULL);
1185 }
1186
1187 EAPI Eina_Bool
1188 elm_fileselector_expandable_get(const Evas_Object *obj)
1189 {
1190    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1191    Widget_Data *wd = elm_widget_data_get(obj);
1192    if (!wd) return EINA_FALSE;
1193    return wd->expand;
1194 }
1195
1196 EAPI void
1197 elm_fileselector_path_set(Evas_Object *obj,
1198 <<<<<<< HEAD
1199                           const char  *path)
1200 {
1201    ELM_CHECK_WIDTYPE(obj, widtype);
1202    _populate(obj, path, NULL);
1203 =======
1204                           const char  *_path)
1205 {
1206    ELM_CHECK_WIDTYPE(obj, widtype);
1207    char *path;
1208    path = ecore_file_realpath(_path);
1209    _populate(obj, path, NULL);
1210    free(path);
1211 >>>>>>> remotes/origin/upstream
1212 }
1213
1214 EAPI const char *
1215 elm_fileselector_path_get(const Evas_Object *obj)
1216 {
1217    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1218    Widget_Data *wd = elm_widget_data_get(obj);
1219    if (!wd) return NULL;
1220    return wd->path;
1221 }
1222
1223 EAPI void
1224 elm_fileselector_mode_set(Evas_Object          *obj,
1225                           Elm_Fileselector_Mode mode)
1226 {
1227    ELM_CHECK_WIDTYPE(obj, widtype);
1228
1229    Widget_Data *wd = elm_widget_data_get(obj);
1230    if (!wd) return;
1231
1232    if (mode == wd->mode) return;
1233
1234    if (mode == ELM_FILESELECTOR_LIST)
1235      {
1236         if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1237                                      wd->files_list))
1238           {
1239              evas_object_show(wd->files_list);
1240              evas_object_hide(wd->files_grid);
1241           }
1242         else
1243           evas_object_hide(wd->files_list);
1244      }
1245    else
1246      {
1247         if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1248                                      wd->files_grid))
1249           {
1250              evas_object_show(wd->files_grid);
1251              evas_object_hide(wd->files_list);
1252           }
1253         else
1254           evas_object_hide(wd->files_grid);
1255      }
1256
1257    wd->mode = mode;
1258
1259    _populate(obj, wd->path, NULL);
1260 }
1261
1262 EAPI Elm_Fileselector_Mode
1263 elm_fileselector_mode_get(const Evas_Object *obj)
1264 {
1265    ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1266
1267    Widget_Data *wd = elm_widget_data_get(obj);
1268    if (!wd) return ELM_FILESELECTOR_LAST;
1269
1270    return wd->mode;
1271 }
1272
1273 EAPI const char *
1274 elm_fileselector_selected_get(const Evas_Object *obj)
1275 {
1276    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1277    Widget_Data *wd = elm_widget_data_get(obj);
1278    if (!wd) return NULL;
1279
1280    if (wd->filename_entry)
1281      {
1282         const char *name;
1283         char buf[PATH_MAX];
1284         char *dir;
1285
1286         dir = wd->only_folder ? ecore_file_dir_get(wd->path) : strdup(wd->path);
1287         name = elm_object_text_get(wd->filename_entry);
1288         snprintf(buf, sizeof(buf), "%s/%s",
1289                  dir, name);
1290         if (wd->only_folder && !ecore_file_is_dir(buf))
1291           eina_stringshare_replace(&wd->selection, ecore_file_dir_get(buf));
1292         else
1293           eina_stringshare_replace(&wd->selection, buf);
1294         if (dir) free(dir);
1295         return wd->selection;
1296      }
1297
1298    if (wd->mode == ELM_FILESELECTOR_LIST)
1299      {
1300 <<<<<<< HEAD
1301         Elm_Object_Item *it;
1302         it = elm_genlist_selected_item_get(wd->files_list);
1303         if (it) return elm_genlist_item_data_get(it);
1304      }
1305    else
1306      {
1307         Elm_Object_Item *it;
1308         it = elm_gengrid_selected_item_get(wd->files_grid);
1309         if (it) return elm_object_item_data_get(it);
1310 =======
1311         Elm_Object_Item *gl_it = elm_genlist_selected_item_get(wd->files_list);
1312         if (gl_it) return elm_object_item_data_get(gl_it);
1313      }
1314    else
1315      {
1316         Elm_Object_Item *gg_it = elm_gengrid_selected_item_get(wd->files_grid);
1317         if (gg_it) return elm_object_item_data_get(gg_it);
1318 >>>>>>> remotes/origin/upstream
1319      }
1320
1321    return wd->path;
1322 }
1323
1324 EAPI Eina_Bool
1325 elm_fileselector_selected_set(Evas_Object *obj,
1326 <<<<<<< HEAD
1327                               const char  *path)
1328 =======
1329                               const char  *_path)
1330 >>>>>>> remotes/origin/upstream
1331 {
1332    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1333    Widget_Data *wd = elm_widget_data_get(obj);
1334    if (!wd) return EINA_FALSE;
1335
1336 <<<<<<< HEAD
1337 =======
1338    Eina_Bool ret = EINA_TRUE;
1339    char *path;
1340    path = ecore_file_realpath(_path);
1341
1342 >>>>>>> remotes/origin/upstream
1343    if (ecore_file_is_dir(path))
1344      _populate(obj, path, NULL);
1345    else
1346      {
1347         if (!ecore_file_exists(path))
1348 <<<<<<< HEAD
1349           return EINA_FALSE;
1350 =======
1351           {
1352              ret = EINA_FALSE;
1353              goto clean_up;
1354           }
1355 >>>>>>> remotes/origin/upstream
1356
1357         _populate(obj, ecore_file_dir_get(path), NULL);
1358         if (wd->filename_entry)
1359           {
1360              elm_object_text_set(wd->filename_entry,
1361                                           ecore_file_file_get(path));
1362              eina_stringshare_replace(&wd->selection, path);
1363           }
1364      }
1365
1366 <<<<<<< HEAD
1367    return EINA_TRUE;
1368 =======
1369 clean_up:
1370    free(path);
1371    return ret;
1372 >>>>>>> remotes/origin/upstream
1373 }
1374