diff options
author | David Walter Seikel | 2014-05-04 04:03:42 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-05-04 04:03:42 +1000 |
commit | 5f1d624c5cf8b44133a7f7ce9cfe2bc24bed3b4d (patch) | |
tree | b927d731ef10b488d6a2b847fc97336c9796cb2a /src/extantz | |
parent | Notes about callbacks. (diff) | |
download | SledjHamr-5f1d624c5cf8b44133a7f7ce9cfe2bc24bed3b4d.zip SledjHamr-5f1d624c5cf8b44133a7f7ce9cfe2bc24bed3b4d.tar.gz SledjHamr-5f1d624c5cf8b44133a7f7ce9cfe2bc24bed3b4d.tar.bz2 SledjHamr-5f1d624c5cf8b44133a7f7ce9cfe2bc24bed3b4d.tar.xz |
Add a file selector.
Diffstat (limited to 'src/extantz')
-rwxr-xr-x | src/extantz/build.lua | 4 | ||||
-rw-r--r-- | src/extantz/extantz.c | 10 | ||||
-rw-r--r-- | src/extantz/extantz.h | 1 | ||||
-rw-r--r-- | src/extantz/files.c | 274 |
4 files changed, 287 insertions, 2 deletions
diff --git a/src/extantz/build.lua b/src/extantz/build.lua index 75b210f..8a02b55 100755 --- a/src/extantz/build.lua +++ b/src/extantz/build.lua | |||
@@ -17,10 +17,10 @@ CFLAGS = CFLAGS .. ' -I../../libraries/irrlicht-1.8.1/include -I/usr/X11R6/inc | |||
17 | LDFLAGS = LDFLAGS .. ' -L../../libraries/irrlicht-1.8.1/lib/Linux' | 17 | LDFLAGS = LDFLAGS .. ' -L../../libraries/irrlicht-1.8.1/lib/Linux' |
18 | libs = libs .. ' -lIrrlicht -lGL -lbz2' | 18 | libs = libs .. ' -lIrrlicht -lGL -lbz2' |
19 | 19 | ||
20 | removeFiles(dir, {'../../extantz', 'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', 'gears.o', 'ephysics_demo.o', 'camera.o', 'Evas_3D_demo.o', 'fangWin.o', 'chat.o', 'woMan.o', '../../media/extantz.edj'}) | 20 | removeFiles(dir, {'../../extantz', 'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', 'gears.o', 'ephysics_demo.o', 'camera.o', 'Evas_3D_demo.o', 'fangWin.o', 'chat.o', 'files.o', 'woMan.o', '../../media/extantz.edj'}) |
21 | 21 | ||
22 | runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../media/extantz.edj') | 22 | runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../media/extantz.edj') |
23 | runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) | 23 | runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) |
24 | runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) | 24 | runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) |
25 | runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) | 25 | runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) |
26 | compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'Evas_3D_demo', 'fangWin', 'chat', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o') | 26 | compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'Evas_3D_demo', 'fangWin', 'chat', 'files', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o') |
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 4ad752e..1d37ade 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c | |||
@@ -330,6 +330,15 @@ EAPI_MAIN int elm_main(int argc, char **argv) | |||
330 | char buf[PATH_MAX]; | 330 | char buf[PATH_MAX]; |
331 | // Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. | 331 | // Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. |
332 | 332 | ||
333 | /* Set the locale according to the system pref. | ||
334 | * If you don't do so the file selector will order the files list in | ||
335 | * a case sensitive manner | ||
336 | */ | ||
337 | setlocale(LC_ALL, ""); | ||
338 | |||
339 | elm_need_ethumb(); | ||
340 | elm_need_efreet(); | ||
341 | |||
333 | HamrTime(elm_main, "extantz"); | 342 | HamrTime(elm_main, "extantz"); |
334 | fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get()); | 343 | fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get()); |
335 | fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get()); | 344 | fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get()); |
@@ -403,6 +412,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) | |||
403 | // overlay_add(&ourGlobals); | 412 | // overlay_add(&ourGlobals); |
404 | woMan_add(&ourGlobals); | 413 | woMan_add(&ourGlobals); |
405 | chat_add(&ourGlobals); | 414 | chat_add(&ourGlobals); |
415 | files_add(&ourGlobals); | ||
406 | 416 | ||
407 | // Gotta do this after adding the windows, otherwise the menu renders under the window. | 417 | // Gotta do this after adding the windows, otherwise the menu renders under the window. |
408 | // This sucks, gotta redefine this menu each time we create a new window? | 418 | // This sucks, gotta redefine this menu each time we create a new window? |
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index 3c671bb..1cc76cd 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h | |||
@@ -251,6 +251,7 @@ void fang_win_complete(globals *ourGlobals, Evas_Object *win, int x, int y, int | |||
251 | void overlay_add(globals *ourGlobals); | 251 | void overlay_add(globals *ourGlobals); |
252 | 252 | ||
253 | void chat_add(globals *ourGlobals); | 253 | void chat_add(globals *ourGlobals); |
254 | void files_add(globals *ourGlobals); | ||
254 | void woMan_add(globals *ourGlobals); | 255 | void woMan_add(globals *ourGlobals); |
255 | 256 | ||
256 | 257 | ||
diff --git a/src/extantz/files.c b/src/extantz/files.c new file mode 100644 index 0000000..7cfc5c0 --- /dev/null +++ b/src/extantz/files.c | |||
@@ -0,0 +1,274 @@ | |||
1 | #include "extantz.h" | ||
2 | |||
3 | |||
4 | static void my_fileselector_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
5 | { | ||
6 | /* event_info conatin the full path of the selected file | ||
7 | * or NULL if none is selected or cancel is pressed */ | ||
8 | const char *selected = event_info; | ||
9 | |||
10 | if (selected) | ||
11 | printf("Selected file: %s\n", selected); | ||
12 | else | ||
13 | evas_object_del(data); /* delete the test window */ | ||
14 | } | ||
15 | |||
16 | static void my_fileselector_selected(void *data EINA_UNUSED, Evas_Object *obj, void *event_info) | ||
17 | { | ||
18 | /* event_info conatin the full path of the selected file */ | ||
19 | const char *selected = event_info; | ||
20 | printf("Selected file: %s\n", selected); | ||
21 | |||
22 | /* or you can query the selection */ | ||
23 | if (elm_fileselector_multi_select_get(obj)) | ||
24 | { | ||
25 | const Eina_List *li; | ||
26 | const Eina_List *paths = elm_fileselector_selected_paths_get(obj); | ||
27 | char *path; | ||
28 | printf("All selected files are:\n"); | ||
29 | EINA_LIST_FOREACH(paths, li, path) | ||
30 | printf(" %s\n", path); | ||
31 | } | ||
32 | else | ||
33 | printf("or: %s\n", elm_fileselector_selected_get(obj)); | ||
34 | } | ||
35 | |||
36 | static void _popup_close_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
37 | { | ||
38 | evas_object_del(data); | ||
39 | } | ||
40 | |||
41 | static void my_fileselector_invalid(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
42 | { | ||
43 | Evas_Object *popup; | ||
44 | Evas_Object *btn; | ||
45 | char error_msg[256]; | ||
46 | |||
47 | snprintf(error_msg, 256, "No such file or directory: %s", (char *)event_info); | ||
48 | |||
49 | popup = elm_popup_add(data); | ||
50 | elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR); | ||
51 | elm_object_part_text_set(popup, "title,text", "Error"); | ||
52 | elm_object_text_set(popup, error_msg); | ||
53 | |||
54 | btn = elm_button_add(popup); | ||
55 | elm_object_text_set(btn, "OK"); | ||
56 | elm_object_part_content_set(popup, "button1", btn); | ||
57 | evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup); | ||
58 | |||
59 | evas_object_show(popup); | ||
60 | } | ||
61 | |||
62 | static void my_fileselector_activated(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) | ||
63 | { | ||
64 | printf("Activated file: %s\n", (char *)event_info); | ||
65 | } | ||
66 | |||
67 | static void _expandable_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
68 | { | ||
69 | Evas_Object *fs = data; | ||
70 | |||
71 | if (elm_fileselector_expandable_get(fs)) | ||
72 | elm_fileselector_expandable_set(fs, EINA_FALSE); | ||
73 | else | ||
74 | elm_fileselector_expandable_set(fs, EINA_TRUE); | ||
75 | } | ||
76 | |||
77 | static void _hidden_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
78 | { | ||
79 | Evas_Object *fs = data; | ||
80 | if (elm_fileselector_hidden_visible_get(fs)) | ||
81 | elm_fileselector_hidden_visible_set(fs, EINA_FALSE); | ||
82 | else | ||
83 | elm_fileselector_hidden_visible_set(fs, EINA_TRUE); | ||
84 | } | ||
85 | |||
86 | static void _mode_changed_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) | ||
87 | { | ||
88 | Evas_Object *fs = data; | ||
89 | Elm_Fileselector_Mode mode; | ||
90 | |||
91 | mode = (elm_fileselector_mode_get(fs) + 1) % ELM_FILESELECTOR_LAST; | ||
92 | elm_radio_value_set(obj, mode); | ||
93 | elm_fileselector_mode_set(data, mode); | ||
94 | } | ||
95 | |||
96 | static void _sort_selected_cb(void *data, Evas_Object *obj, void *event_info) | ||
97 | { | ||
98 | Evas_Object *fs = evas_object_data_get(obj, "fileselector"); | ||
99 | const char *selected = elm_object_item_text_get(event_info); | ||
100 | |||
101 | elm_object_text_set(obj, selected); | ||
102 | elm_fileselector_sort_method_set(fs, (Elm_Fileselector_Sort)data); | ||
103 | } | ||
104 | |||
105 | static void _tiny_icon_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
106 | { | ||
107 | Evas_Object *fs = data; | ||
108 | Evas_Coord w, h; | ||
109 | |||
110 | elm_fileselector_thumbnail_size_get(fs, &w, &h); | ||
111 | elm_fileselector_thumbnail_size_set(fs, 16, 16); | ||
112 | } | ||
113 | |||
114 | static void _small_icon_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
115 | { | ||
116 | Evas_Object *fs = data; | ||
117 | Evas_Coord w, h; | ||
118 | |||
119 | elm_fileselector_thumbnail_size_get(fs, &w, &h); | ||
120 | elm_fileselector_thumbnail_size_set(fs, 32, 32); | ||
121 | } | ||
122 | |||
123 | static void _middle_icon_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
124 | { | ||
125 | Evas_Object *fs = data; | ||
126 | Evas_Coord w, h; | ||
127 | |||
128 | elm_fileselector_thumbnail_size_get(fs, &w, &h); | ||
129 | elm_fileselector_thumbnail_size_set(fs, 64, 64); | ||
130 | } | ||
131 | |||
132 | static void _big_icon_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
133 | { | ||
134 | Evas_Object *fs = data; | ||
135 | Evas_Coord w, h; | ||
136 | |||
137 | elm_fileselector_thumbnail_size_get(fs, &w, &h); | ||
138 | elm_fileselector_thumbnail_size_set(fs, 128, 128); | ||
139 | } | ||
140 | |||
141 | static Eina_Bool _all_filter(const char *path EINA_UNUSED, Eina_Bool dir EINA_UNUSED, void *data EINA_UNUSED) | ||
142 | { | ||
143 | return EINA_TRUE; | ||
144 | } | ||
145 | |||
146 | static Eina_Bool _edje_filter(const char *path, Eina_Bool dir, void *data EINA_UNUSED) | ||
147 | { | ||
148 | if (dir) return EINA_TRUE; | ||
149 | |||
150 | if (eina_str_has_extension(path, ".edc") || | ||
151 | eina_str_has_extension(path, ".edj")) | ||
152 | return EINA_TRUE; | ||
153 | return EINA_FALSE; | ||
154 | } | ||
155 | |||
156 | void files_add(globals *ourGlobals) | ||
157 | { | ||
158 | Evas_Object *win, *bx, *vbox, *fs, *bt, *rd = NULL, *rdg = NULL, *hoversel; | ||
159 | |||
160 | win = fang_win_add(ourGlobals); | ||
161 | |||
162 | bx = eo_add(ELM_OBJ_BOX_CLASS, win); | ||
163 | eo_do(bx, | ||
164 | elm_obj_box_homogeneous_set(EINA_FALSE), | ||
165 | evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), | ||
166 | evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) | ||
167 | ); | ||
168 | elm_win_resize_object_add(win, bx); | ||
169 | |||
170 | fs = eo_add(ELM_OBJ_FILESELECTOR_CLASS, bx); | ||
171 | eo_do(fs, | ||
172 | evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), | ||
173 | evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), | ||
174 | evas_obj_visibility_set(EINA_TRUE) | ||
175 | ); | ||
176 | elm_box_pack_end(bx, fs); | ||
177 | |||
178 | /* disnable the fs file name entry */ | ||
179 | elm_fileselector_is_save_set(fs, EINA_FALSE); | ||
180 | /* make the file list a tree with dir expandable in place */ | ||
181 | elm_fileselector_expandable_set(fs, EINA_FALSE); | ||
182 | /* start the fileselector in the home dir */ | ||
183 | elm_fileselector_path_set(fs, getenv("HOME")); | ||
184 | elm_fileselector_folder_only_set(fs, EINA_FALSE); | ||
185 | elm_fileselector_buttons_ok_cancel_set(fs, EINA_TRUE); | ||
186 | elm_fileselector_multi_select_set(fs, EINA_TRUE); | ||
187 | |||
188 | /* add filesters */ | ||
189 | elm_fileselector_custom_filter_append(fs, _all_filter, NULL, "all files"); | ||
190 | elm_fileselector_custom_filter_append(fs, _edje_filter, NULL, "edje files"); | ||
191 | elm_fileselector_mime_types_filter_append(fs, "image/*", "image files"); | ||
192 | elm_fileselector_mime_types_filter_append(fs, "text/*", "text files"); | ||
193 | |||
194 | evas_object_smart_callback_add(fs, "done", my_fileselector_done, win); | ||
195 | evas_object_smart_callback_add(fs, "selected", my_fileselector_selected, win); | ||
196 | evas_object_smart_callback_add(fs, "selected,invalid", my_fileselector_invalid, win); | ||
197 | evas_object_smart_callback_add(fs, "activated", my_fileselector_activated, win); | ||
198 | |||
199 | eo_unref(fs); | ||
200 | |||
201 | vbox = eo_add(ELM_OBJ_BOX_CLASS, win); | ||
202 | eo_do(vbox, | ||
203 | elm_obj_box_homogeneous_set(EINA_FALSE), | ||
204 | elm_obj_box_horizontal_set(EINA_TRUE), | ||
205 | evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) | ||
206 | ); | ||
207 | |||
208 | bt = elm_check_add(vbox); | ||
209 | elm_object_text_set(bt, "tree"); | ||
210 | elm_check_state_set(bt, elm_fileselector_expandable_get(fs)); | ||
211 | evas_object_smart_callback_add(bt, "changed", _expandable_clicked, fs); | ||
212 | elm_box_pack_end(vbox, bt); | ||
213 | evas_object_show(bt); | ||
214 | |||
215 | bt = elm_check_add(vbox); | ||
216 | elm_object_text_set(bt, "hidden"); | ||
217 | elm_check_state_set(bt, elm_fileselector_hidden_visible_get(fs)); | ||
218 | evas_object_smart_callback_add(bt, "changed", _hidden_clicked, fs); | ||
219 | elm_box_pack_end(vbox, bt); | ||
220 | evas_object_show(bt); | ||
221 | |||
222 | rdg = rd = elm_radio_add(vbox); | ||
223 | elm_radio_state_value_set(rd, ELM_FILESELECTOR_LIST); | ||
224 | elm_object_text_set(rd, "list"); | ||
225 | elm_box_pack_end(vbox, rd); | ||
226 | evas_object_show(rd); | ||
227 | evas_object_smart_callback_add(rd, "changed", _mode_changed_cb, fs); | ||
228 | |||
229 | rd = elm_radio_add(vbox); | ||
230 | elm_radio_group_add(rd, rdg); | ||
231 | elm_radio_state_value_set(rd, ELM_FILESELECTOR_GRID); | ||
232 | elm_object_text_set(rd, "grid"); | ||
233 | elm_box_pack_end(vbox, rd); | ||
234 | evas_object_show(rd); | ||
235 | evas_object_smart_callback_add(rd, "changed", _mode_changed_cb, fs); | ||
236 | |||
237 | |||
238 | hoversel = elm_hoversel_add(vbox); | ||
239 | elm_hoversel_hover_parent_set(hoversel, win); | ||
240 | evas_object_data_set(hoversel, "fileselector", fs); | ||
241 | elm_object_text_set(hoversel, "sorting"); | ||
242 | |||
243 | elm_hoversel_item_add(hoversel, "name(asc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_FILENAME_ASC); | ||
244 | elm_hoversel_item_add(hoversel, "name(desc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_FILENAME_DESC); | ||
245 | elm_hoversel_item_add(hoversel, "type(asc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_TYPE_ASC); | ||
246 | elm_hoversel_item_add(hoversel, "type(desc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_TYPE_DESC); | ||
247 | elm_hoversel_item_add(hoversel, "size(asc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_SIZE_ASC); | ||
248 | elm_hoversel_item_add(hoversel, "size(desc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_SIZE_DESC); | ||
249 | elm_hoversel_item_add(hoversel, "time(asc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_MODIFIED_ASC); | ||
250 | elm_hoversel_item_add(hoversel, "time(desc)", NULL, ELM_ICON_NONE, _sort_selected_cb, (const void *) ELM_FILESELECTOR_SORT_BY_MODIFIED_DESC); | ||
251 | |||
252 | elm_box_pack_end(vbox, hoversel); | ||
253 | evas_object_show(hoversel); | ||
254 | |||
255 | hoversel = elm_hoversel_add(vbox); | ||
256 | elm_hoversel_hover_parent_set(hoversel, win); | ||
257 | evas_object_data_set(hoversel, "fileselector", fs); | ||
258 | elm_object_text_set(hoversel, "size"); | ||
259 | |||
260 | elm_hoversel_item_add(hoversel, "tiny", NULL, ELM_ICON_NONE, _tiny_icon_clicked, fs); | ||
261 | elm_hoversel_item_add(hoversel, "small", NULL, ELM_ICON_NONE, _small_icon_clicked, fs); | ||
262 | elm_hoversel_item_add(hoversel, "medium", NULL, ELM_ICON_NONE, _middle_icon_clicked, fs); | ||
263 | elm_hoversel_item_add(hoversel, "big", NULL, ELM_ICON_NONE, _big_icon_clicked, fs); | ||
264 | |||
265 | elm_box_pack_end(vbox, hoversel); | ||
266 | evas_object_show(hoversel); | ||
267 | |||
268 | elm_box_pack_end(bx, vbox); | ||
269 | evas_object_show(vbox); | ||
270 | evas_object_show(bx); | ||
271 | eo_unref(bx); | ||
272 | |||
273 | fang_win_complete(ourGlobals, win, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 350, 500); | ||
274 | } | ||