Merge remote-tracking branch 'remotes/origin/upstream'
[framework/uifw/elementary.git] / src / bin / test_eio.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #include <Eio.h>
6 #include <sys/times.h>
7
8 #ifndef ELM_LIB_QUICKLAUNCH
9
10 static Elm_Genlist_Item_Class it_eio;
11
12 static clock_t st_time;
13 static clock_t en_time;
14 static struct tms st_cpu;
15 static struct tms en_cpu;
16
17 static void _sel_file(void *data, Evas_Object *obj, void *event_info);
18 static Eina_Bool _ls_filter_cb(void *data, Eio_File *handler, const char *file);
19 static void _ls_main_cb(void *data, Eio_File *handler, const char *file);
20 static void _ls_done_cb(void *data, Eio_File *handler);
21 static void _ls_error_cb(void *data, Eio_File *handler, int error);
22 static void _file_chosen(void *data, Evas_Object *obj, void *event_info);
23 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
24 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
25 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
26 static void _gl_del(void *data, Evas_Object *obj);
27 static void _test_eio_clear(void *data, Evas_Object *obj, void *event);
28
29 static void
30 _sel_file(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
31 {
32 }
33
34 static Eina_Bool
35 _ls_filter_cb(void *data __UNUSED__, Eio_File *handler __UNUSED__, const char *file __UNUSED__)
36 {
37   return EINA_TRUE;
38 }
39
40 <<<<<<< HEAD
41 =======
42 static int
43 _compare_cb(const void *data1, const void *data2)
44 {
45    Elm_Object_Item *it = (Elm_Object_Item *)data1;
46    Elm_Object_Item *it2 = (Elm_Object_Item *)data2;
47    return strcoll(elm_object_item_data_get(it),
48                   elm_object_item_data_get(it2));
49 }
50
51 >>>>>>> remotes/origin/upstream
52 static void
53 _ls_main_cb(void *data, Eio_File *handler __UNUSED__, const char *file)
54 {
55    elm_genlist_item_sorted_insert(data,
56                                   &it_eio,
57                                   eina_stringshare_add(file),
58                                   NULL,
59                                   ELM_GENLIST_ITEM_NONE,
60 <<<<<<< HEAD
61                                   (Eina_Compare_Cb) strcoll,
62 =======
63                                   _compare_cb,
64 >>>>>>> remotes/origin/upstream
65                                   _sel_file,
66                                   NULL);
67 }
68
69 static void
70 _ls_done_cb(void *data __UNUSED__, Eio_File *handler __UNUSED__)
71 {
72    en_time = times(&en_cpu);
73    fprintf(stderr, "ls done\n");
74    fprintf(stderr, "Real Time: %.jd, User Time: %.jd, System Time: %.jd\n",
75            (intmax_t)(en_time - st_time),
76            (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
77            (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
78 }
79
80 static void
81 _ls_error_cb(void *data __UNUSED__, Eio_File *handler __UNUSED__, int error)
82 {
83    fprintf(stderr, "error: [%s]\n", strerror(error));
84 }
85
86 static void
87 _file_chosen(void *data, Evas_Object *obj __UNUSED__, void *event_info)
88 {
89    const char *file = event_info;
90    if (file)
91      {
92         st_time = times(&st_cpu);
93         eio_file_ls(file,
94                     _ls_filter_cb,
95                     _ls_main_cb,
96                     _ls_done_cb,
97                     _ls_error_cb,
98                     data);
99      }
100 }
101
102 static char *
103 _gl_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
104 {
105    char buf[PATH_MAX];
106    snprintf(buf, sizeof(buf), "Item # %s", (char*)data);
107    return strdup(buf);
108 }
109
110 static Evas_Object *
111 _gl_content_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
112 {
113    return NULL;
114 }
115
116 static Eina_Bool
117 _gl_state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
118 {
119    return EINA_FALSE;
120 }
121
122 static void
123 _gl_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
124 {
125 }
126
127 static void
128 _test_eio_clear(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
129 {
130    elm_genlist_clear(data);
131 }
132
133 void
134 test_eio(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
135 {
136    Evas_Object *win, *bg, *vbox, *hbox, *ic, *bt, *fs_bt, *gl;
137
138    it_eio.item_style     = "default";
139    it_eio.func.text_get = _gl_text_get;
140    it_eio.func.content_get  = _gl_content_get;
141    it_eio.func.state_get = _gl_state_get;
142    it_eio.func.del       = _gl_del;
143
144    win = elm_win_add(NULL, "fileselector-button", ELM_WIN_BASIC);
145    elm_win_title_set(win, "File Selector Button");
146    elm_win_autodel_set(win, EINA_TRUE);
147
148    bg = elm_bg_add(win);
149    elm_win_resize_object_add(win, bg);
150    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
151    evas_object_show(bg);
152
153    vbox = elm_box_add(win);
154    elm_win_resize_object_add(win, vbox);
155    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
156    evas_object_show(vbox);
157
158    gl = elm_genlist_add(win);
159    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
160    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
161    elm_box_pack_end(vbox, gl);
162    evas_object_show(gl);
163
164    /* file selector button */
165    hbox = elm_box_add(win);
166    elm_box_horizontal_set(hbox, EINA_TRUE);
167    ic = elm_icon_add(win);
168    elm_icon_standard_set(ic, "file");
169    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
170    fs_bt = elm_fileselector_button_add(win);
171    elm_object_text_set(fs_bt, "Select a dir");
172    elm_object_part_content_set(fs_bt, "icon", ic);
173    elm_fileselector_button_inwin_mode_set(fs_bt, EINA_TRUE);
174    elm_fileselector_button_folder_only_set(fs_bt, EINA_TRUE);
175
176    elm_box_pack_end(hbox, fs_bt);
177    elm_box_pack_end(vbox, hbox);
178    evas_object_show(fs_bt);
179    evas_object_show(ic);
180
181    /* attribute setting buttons */
182    bt = elm_button_add(win);
183    elm_object_text_set(bt, "clear");
184    evas_object_smart_callback_add(bt, "clicked", _test_eio_clear, gl);
185    elm_box_pack_end(hbox, bt);
186    evas_object_show(bt);
187    evas_object_show(hbox);
188
189    evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, gl);
190
191    evas_object_resize(win, 300, 500);
192    evas_object_show(win);
193 }
194
195 #endif