1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #ifdef HAVE_SYS_TIMES_H
6 # include <sys/times.h>
7 #endif
8
9 #ifdef _WIN32
10 # ifndef WIN32_LEAN_AND_MEAN
11 # define WIN32_LEAN_AND_MEAN
12 # endif
13 # include <windows.h>
14 # undef WIN32_LEAN_AND_MEAN
15 #endif
16
17 #include <Eio.h>
18
19 #include <Elementary.h>
20
21 static Elm_Genlist_Item_Class it_eio;
22
23 #ifdef _WIN32
24 ULONGLONG st_time_kernel;
25 ULONGLONG st_time_user;
26 ULONGLONG en_time_kernel;
27 ULONGLONG en_time_user;
28 #else
29 static clock_t st_time;
30 static clock_t en_time;
31 static struct tms st_cpu;
32 static struct tms en_cpu;
33 #endif
34
35 static void _sel_file(void *data, Evas_Object *obj, void *event_info);
36 static Eina_Bool _ls_filter_cb(void *data, Eio_File *handler, const char *file);
37 static void _ls_main_cb(void *data, Eio_File *handler, const char *file);
38 static void _ls_done_cb(void *data, Eio_File *handler);
39 static void _ls_error_cb(void *data, Eio_File *handler, int error);
40 static void _file_chosen(void *data, Evas_Object *obj, void *event_info);
41 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
42 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
43 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
44 static void _gl_del(void *data, Evas_Object *obj);
45 static void _test_eio_clear(void *data, Evas_Object *obj, void *event);
46
47 static void
_sel_file(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)48 _sel_file(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
49 {
50 }
51
52 static Eina_Bool
_ls_filter_cb(void * data EINA_UNUSED,Eio_File * handler EINA_UNUSED,const char * file EINA_UNUSED)53 _ls_filter_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file EINA_UNUSED)
54 {
55 return EINA_TRUE;
56 }
57
58 static int
_compare_cb(const void * data1,const void * data2)59 _compare_cb(const void *data1, const void *data2)
60 {
61 Elm_Object_Item *it = (Elm_Object_Item *)data1;
62 Elm_Object_Item *it2 = (Elm_Object_Item *)data2;
63 return strcoll(elm_object_item_data_get(it),
64 elm_object_item_data_get(it2));
65 }
66
67 static void
_ls_main_cb(void * data,Eio_File * handler EINA_UNUSED,const char * file)68 _ls_main_cb(void *data, Eio_File *handler EINA_UNUSED, const char *file)
69 {
70 elm_genlist_item_sorted_insert(data,
71 &it_eio,
72 eina_stringshare_add(file),
73 NULL,
74 ELM_GENLIST_ITEM_NONE,
75 _compare_cb,
76 _sel_file,
77 NULL);
78 }
79
80 static void
_ls_done_cb(void * data EINA_UNUSED,Eio_File * handler EINA_UNUSED)81 _ls_done_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED)
82 {
83 #ifdef _WIN32
84 FILETIME tc;
85 FILETIME te;
86 FILETIME tk;
87 FILETIME tu;
88 ULARGE_INTEGER time_kernel;
89 ULARGE_INTEGER time_user;
90
91 if (!GetProcessTimes(GetCurrentProcess(),
92 &tc, &te, &tk, &tu))
93 return;
94
95 time_kernel.u.LowPart = tk.dwLowDateTime;
96 time_kernel.u.HighPart = tk.dwHighDateTime;
97 en_time_kernel = time_kernel.QuadPart;
98
99 time_user.u.LowPart = tu.dwLowDateTime;
100 time_user.u.HighPart = tu.dwHighDateTime;
101 en_time_user = time_user.QuadPart;
102
103 fprintf(stderr, "ls done\n");
104 fprintf(stderr, "Kernel Time: %lld, User Time: %lld",
105 (en_time_kernel - st_time_kernel),
106 (en_time_user - st_time_user));
107 #else
108 en_time = times(&en_cpu);
109 fprintf(stderr, "ls done\n");
110 fprintf(stderr, "Real Time: %.jd, User Time: %.jd, System Time: %.jd\n",
111 (intmax_t)(en_time - st_time),
112 (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
113 (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
114 #endif
115 }
116
117 static void
_ls_error_cb(void * data EINA_UNUSED,Eio_File * handler EINA_UNUSED,int error)118 _ls_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
119 {
120 fprintf(stderr, "error: [%s]\n", strerror(error));
121 }
122
123 static void
_file_chosen(void * data,Evas_Object * obj EINA_UNUSED,void * event_info)124 _file_chosen(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
125 {
126 const char *file = event_info;
127 if (file)
128 {
129 #ifdef _WIN32
130 FILETIME tc;
131 FILETIME te;
132 FILETIME tk;
133 FILETIME tu;
134 ULARGE_INTEGER time_kernel;
135 ULARGE_INTEGER time_user;
136
137 if (!GetProcessTimes(GetCurrentProcess(),
138 &tc, &te, &tk, &tu))
139 return;
140
141 time_kernel.u.LowPart = tk.dwLowDateTime;
142 time_kernel.u.HighPart = tk.dwHighDateTime;
143 st_time_kernel = time_kernel.QuadPart;
144
145 time_user.u.LowPart = tu.dwLowDateTime;
146 time_user.u.HighPart = tu.dwHighDateTime;
147 st_time_user = time_user.QuadPart;
148 #else
149 st_time = times(&st_cpu);
150 #endif
151 eio_file_ls(file,
152 _ls_filter_cb,
153 _ls_main_cb,
154 _ls_done_cb,
155 _ls_error_cb,
156 data);
157 }
158 }
159
160 static char *
_gl_text_get(void * data,Evas_Object * obj EINA_UNUSED,const char * part EINA_UNUSED)161 _gl_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
162 {
163 char buf[PATH_MAX];
164 snprintf(buf, sizeof(buf), "Item # %s", (char*)data);
165 return strdup(buf);
166 }
167
168 static Evas_Object *
_gl_content_get(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * part EINA_UNUSED)169 _gl_content_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
170 {
171 return NULL;
172 }
173
174 static Eina_Bool
_gl_state_get(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,const char * part EINA_UNUSED)175 _gl_state_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
176 {
177 return EINA_FALSE;
178 }
179
180 static void
_gl_del(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED)181 _gl_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
182 {
183 }
184
185 static void
_test_eio_clear(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)186 _test_eio_clear(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
187 {
188 elm_genlist_clear(data);
189 }
190
191 void
test_eio(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)192 test_eio(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
193 {
194 Evas_Object *win, *vbox, *hbox, *ic, *bt, *fs_bt, *gl;
195
196 it_eio.item_style = "default";
197 it_eio.func.text_get = _gl_text_get;
198 it_eio.func.content_get = _gl_content_get;
199 it_eio.func.state_get = _gl_state_get;
200 it_eio.func.del = _gl_del;
201
202 win = elm_win_util_standard_add("fileselector-button", "File Selector Button");
203 elm_win_autodel_set(win, EINA_TRUE);
204
205 vbox = elm_box_add(win);
206 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
207 elm_win_resize_object_add(win, vbox);
208 evas_object_show(vbox);
209
210 gl = elm_genlist_add(win);
211 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
212 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
213 elm_box_pack_end(vbox, gl);
214 evas_object_show(gl);
215
216 /* file selector button */
217 hbox = elm_box_add(win);
218 elm_box_horizontal_set(hbox, EINA_TRUE);
219 ic = elm_icon_add(win);
220 elm_icon_standard_set(ic, "file");
221 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
222 fs_bt = elm_fileselector_button_add(win);
223 elm_object_text_set(fs_bt, "Select a dir");
224 elm_object_part_content_set(fs_bt, "icon", ic);
225 elm_fileselector_button_inwin_mode_set(fs_bt, EINA_TRUE);
226 elm_fileselector_folder_only_set(fs_bt, EINA_TRUE);
227
228 elm_box_pack_end(hbox, fs_bt);
229 elm_box_pack_end(vbox, hbox);
230 evas_object_show(fs_bt);
231 evas_object_show(ic);
232
233 /* attribute setting buttons */
234 bt = elm_button_add(win);
235 elm_object_text_set(bt, "clear");
236 evas_object_smart_callback_add(bt, "clicked", _test_eio_clear, gl);
237 elm_box_pack_end(hbox, bt);
238 evas_object_show(bt);
239 evas_object_show(hbox);
240
241 evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, gl);
242
243 evas_object_resize(win, 300, 500);
244 evas_object_show(win);
245 }
246