2 * Simple Elementary's <b>file selector widget</b> example,
3 * illustrating its usage and API.
5 * See stdout/stderr for output. Compile with:
8 * gcc -g file selector_example.c -o file selector_example `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
28 const char *selected = event_info;
29 /* event_info contains the full path of the selected file or NULL
30 * if none is selected (or cancel is pressed) */
32 printf("We're done! Selected file is: %s\n",
33 selected ? selected : "*none!*");
35 _on_done(NULL, NULL, NULL);
40 _fs_selected(void *data,
44 const char *selected = event_info;
45 /* event_info contains the full path of the selected file */
47 printf("There's been a selection: %s\n", selected);
51 _is_save_clicked(void *data,
55 Evas_Object *fs = data;
56 Eina_Bool old_val = elm_fileselector_is_save_get(fs);
58 printf("%s text entry with selected item's name\n",
59 old_val ? "Disabling" : "Enabling");
61 elm_fileselector_is_save_set(fs, !old_val);
65 _folder_only_clicked(void *data,
69 Evas_Object *fs = data;
70 Eina_Bool old_val = elm_fileselector_folder_only_get(fs);
72 printf("%s folder-only mode\n",
73 old_val ? "Disabling" : "Enabling");
75 elm_fileselector_folder_only_set(fs, !old_val);
79 _expandable_clicked(void *data,
83 Evas_Object *fs = data;
84 Eina_Bool old_val = elm_fileselector_expandable_get(fs);
86 printf("%s tree-view mode\n",
87 old_val ? "Disabling" : "Enabling");
89 elm_fileselector_expandable_set(fs, !old_val);
93 _sel_get_clicked(void *data,
97 Evas_Object *fs = data;
98 printf("Current selection is: %s\n", elm_fileselector_selected_get(fs));
102 _path_get_clicked(void *data,
106 Evas_Object *fs = data;
107 printf("Current selection's directory path is: %s\n",
108 elm_fileselector_path_get(fs));
115 Evas_Object *win, *fs, *bg, *vbox, *buttons_bx, *bt, *sep, *bx;
117 /* Set the locale according to the system pref. If you dont do so
118 * the file selector will order the files list in a case sensitive
121 setlocale(LC_ALL, "");
123 elm_need_ethumb(); /* let's have thumbnails of images on grid view */
125 win = elm_win_add(NULL, "fileselector", ELM_WIN_BASIC);
126 elm_win_title_set(win, "File Selector Example");
127 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
129 bg = elm_bg_add(win);
130 elm_win_resize_object_add(win, bg);
131 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 evas_object_show(bg);
134 bx = elm_box_add(win);
135 elm_win_resize_object_add(win, bx);
136 elm_box_horizontal_set(bx, EINA_TRUE);
137 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138 /* evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL); */
139 evas_object_show(bx);
141 vbox = elm_box_add(win);
142 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
144 evas_object_show(vbox);
145 elm_box_pack_end(bx, vbox);
147 /* first file selector, in list mode */
148 fs = elm_fileselector_add(win);
149 /* enable the fs file name entry */
150 elm_fileselector_is_save_set(fs, EINA_TRUE);
151 /* custom list view */
152 elm_fileselector_expandable_set(fs, EINA_FALSE);
153 /* start the fileselector in the /tmp/ dir */
154 elm_fileselector_path_set(fs, "/tmp");
156 evas_object_size_hint_weight_set(fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
157 evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
158 elm_box_pack_end(vbox, fs);
159 evas_object_show(fs);
161 /* the 'done' cb is called when the user presses ok/cancel */
162 evas_object_smart_callback_add(fs, "done", _fs_done, win);
163 /* the 'selected' cb is called when the user clicks on a file/dir */
164 evas_object_smart_callback_add(fs, "selected", _fs_selected, win);
167 sep = elm_separator_add(win);
168 elm_separator_horizontal_set(sep, EINA_TRUE);
169 elm_box_pack_end(vbox, sep);
170 evas_object_show(sep);
172 buttons_bx = elm_box_add(win);
173 elm_box_horizontal_set(buttons_bx, EINA_TRUE);
174 elm_box_pack_end(vbox, buttons_bx);
175 evas_object_show(buttons_bx);
177 bt = elm_check_add(win);
178 elm_object_text_set(bt, "editable selection");
179 elm_check_state_set(bt, elm_fileselector_is_save_get(fs));
180 evas_object_smart_callback_add(bt, "changed", _is_save_clicked, fs);
181 elm_box_pack_end(buttons_bx, bt);
182 evas_object_show(bt);
184 bt = elm_check_add(win);
185 elm_object_text_set(bt, "folders only");
186 elm_check_state_set(bt, elm_fileselector_folder_only_get(fs));
187 evas_object_smart_callback_add(bt, "changed", _folder_only_clicked, fs);
188 elm_box_pack_end(buttons_bx, bt);
189 evas_object_show(bt);
191 bt = elm_check_add(win);
192 elm_object_text_set(bt, "expandable");
193 elm_check_state_set(bt, elm_fileselector_expandable_get(fs));
194 evas_object_smart_callback_add(bt, "changed", _expandable_clicked, fs);
195 elm_box_pack_end(buttons_bx, bt);
196 evas_object_show(bt);
198 buttons_bx = elm_box_add(win);
199 elm_box_horizontal_set(buttons_bx, EINA_TRUE);
200 elm_box_pack_end(vbox, buttons_bx);
201 evas_object_show(buttons_bx);
203 bt = elm_button_add(win);
204 elm_object_text_set(bt, "Print selection");
205 evas_object_smart_callback_add(bt, "clicked", _sel_get_clicked, fs);
206 elm_box_pack_end(buttons_bx, bt);
207 evas_object_show(bt);
209 bt = elm_button_add(win);
210 elm_object_text_set(bt, "Print path");
211 evas_object_smart_callback_add(bt, "clicked", _path_get_clicked, fs);
212 elm_box_pack_end(buttons_bx, bt);
213 evas_object_show(bt);
215 sep = elm_separator_add(win);
216 elm_separator_horizontal_set(sep, EINA_FALSE);
217 elm_box_pack_end(bx, sep);
218 evas_object_show(sep);
220 /* second file selector, now with grid view */
221 fs = elm_fileselector_add(win);
222 elm_fileselector_is_save_set(fs, EINA_TRUE);
223 elm_fileselector_mode_set(fs, ELM_FILESELECTOR_GRID);
224 elm_fileselector_buttons_ok_cancel_set(fs, EINA_FALSE);
225 elm_fileselector_path_set(fs, "/tmp");
227 evas_object_size_hint_weight_set(fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
228 evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
229 elm_box_pack_end(bx, fs);
230 evas_object_show(fs);
232 evas_object_resize(win, 800, 600);
233 evas_object_show(win);