diff options
Diffstat (limited to 'libraries/elementary/src/bin/test_fileselector_button.c')
-rw-r--r-- | libraries/elementary/src/bin/test_fileselector_button.c | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/libraries/elementary/src/bin/test_fileselector_button.c b/libraries/elementary/src/bin/test_fileselector_button.c new file mode 100644 index 0000000..969983a --- /dev/null +++ b/libraries/elementary/src/bin/test_fileselector_button.c | |||
@@ -0,0 +1,247 @@ | |||
1 | #include "test.h" | ||
2 | #ifdef HAVE_CONFIG_H | ||
3 | # include "elementary_config.h" | ||
4 | #endif | ||
5 | |||
6 | #include <Elementary.h> | ||
7 | #ifndef ELM_LIB_QUICKLAUNCH | ||
8 | struct _api_data | ||
9 | { | ||
10 | unsigned int state; /* What state we are testing */ | ||
11 | Evas_Object *box; /* Additional data defined by test */ | ||
12 | Eina_Bool free_data; /* free data on close */ | ||
13 | }; | ||
14 | typedef struct _api_data api_data; | ||
15 | enum _api_state | ||
16 | { | ||
17 | ICON_UNSET, | ||
18 | WINDOW_TITLE_SET, | ||
19 | API_STATE_LAST | ||
20 | }; | ||
21 | typedef enum _api_state api_state; | ||
22 | |||
23 | static void | ||
24 | set_api_state(api_data *api) | ||
25 | { | ||
26 | const Eina_List *items = elm_box_children_get(api->box); | ||
27 | if (!eina_list_count(items)) | ||
28 | return; | ||
29 | |||
30 | /* Get first item of list of vbox children */ | ||
31 | Evas_Object *fs_bt = eina_list_nth(items, 0); | ||
32 | |||
33 | /* use elm_box_children_get() to get list of children */ | ||
34 | switch(api->state) | ||
35 | { /* Put all api-changes under switch */ | ||
36 | case ICON_UNSET: | ||
37 | elm_object_part_content_unset(fs_bt, NULL); | ||
38 | break; | ||
39 | |||
40 | case WINDOW_TITLE_SET: | ||
41 | elm_fileselector_button_window_title_set(fs_bt, "Custom title from API"); | ||
42 | break; | ||
43 | |||
44 | case API_STATE_LAST: | ||
45 | |||
46 | break; | ||
47 | default: | ||
48 | return; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | static void | ||
53 | _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__) | ||
54 | { /* Will add here a SWITCH command containing code to modify test-object */ | ||
55 | /* in accordance a->state value. */ | ||
56 | api_data *a = data; | ||
57 | char str[128]; | ||
58 | |||
59 | printf("clicked event on API Button: api_state=<%d>\n", a->state); | ||
60 | set_api_state(a); | ||
61 | a->state++; | ||
62 | sprintf(str, "Next API function (%u)", a->state); | ||
63 | elm_object_text_set(obj, str); | ||
64 | elm_object_disabled_set(obj, a->state == API_STATE_LAST); | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | create_dir_struct(void) | ||
69 | { | ||
70 | FILE *fp; | ||
71 | mkdir("/tmp/test_fs_bt", S_IRWXU); | ||
72 | fp = fopen("/tmp/test_fs_bt/a_file.txt", "w"); | ||
73 | if (fp) fclose(fp); | ||
74 | fp = fopen("/tmp/test_fs_bt/k_file.txt", "w"); | ||
75 | if (fp) fclose(fp); | ||
76 | fp = fopen("/tmp/test_fs_bt/m_file.txt", "w"); | ||
77 | if (fp) fclose(fp); | ||
78 | |||
79 | mkdir("/tmp/test_fs_bt/a_subdir", S_IRWXU); | ||
80 | fp = fopen("/tmp/test_fs_bt/a_subdir/d_sub_file.txt", "w"); | ||
81 | if (fp) fclose(fp); | ||
82 | fp = fopen("/tmp/test_fs_bt/a_subdir/j_sub_file.txt", "w"); | ||
83 | if (fp) fclose(fp); | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | _file_chosen(void *data, | ||
88 | Evas_Object *obj __UNUSED__, | ||
89 | void *event_info) | ||
90 | { | ||
91 | Evas_Object *entry = data; | ||
92 | const char *file = event_info; | ||
93 | if (file) | ||
94 | { | ||
95 | elm_object_text_set(entry, file); | ||
96 | printf("File chosen: %s\n", file); | ||
97 | } | ||
98 | else | ||
99 | printf("File selection canceled.\n"); | ||
100 | } | ||
101 | |||
102 | static void | ||
103 | _inwin_mode_toggle(void *data, | ||
104 | Evas_Object *obj __UNUSED__, | ||
105 | void *event_info __UNUSED__) | ||
106 | { | ||
107 | Evas_Object *fs_bt = data; | ||
108 | Eina_Bool value = elm_fileselector_button_inwin_mode_get(fs_bt); | ||
109 | elm_fileselector_button_inwin_mode_set(fs_bt, !value); | ||
110 | printf("Inwin mode set to: %s\n", value ? "false" : "true"); | ||
111 | } | ||
112 | |||
113 | static void | ||
114 | _current_sel_toggle(void *data, | ||
115 | Evas_Object *obj __UNUSED__, | ||
116 | void *event_info __UNUSED__) | ||
117 | { | ||
118 | Evas_Object *fs_bt = data; | ||
119 | Eina_Bool value = elm_fileselector_button_is_save_get(fs_bt); | ||
120 | elm_fileselector_button_is_save_set(fs_bt, !value); | ||
121 | printf("Current selection editable entry set to: %s\n", | ||
122 | value ? "false" : "true"); | ||
123 | } | ||
124 | |||
125 | static void | ||
126 | _folder_only_toggle(void *data, | ||
127 | Evas_Object *obj __UNUSED__, | ||
128 | void *event_info __UNUSED__) | ||
129 | { | ||
130 | Evas_Object *fs_bt = data; | ||
131 | Eina_Bool value = elm_fileselector_button_folder_only_get(fs_bt); | ||
132 | elm_fileselector_button_folder_only_set(fs_bt, !value); | ||
133 | printf("Folder only flag set to: %s\n", value ? "false" : "true"); | ||
134 | } | ||
135 | |||
136 | static void | ||
137 | _expandable_toggle(void *data, | ||
138 | Evas_Object *obj __UNUSED__, | ||
139 | void *event_info __UNUSED__) | ||
140 | { | ||
141 | Evas_Object *fs_bt = data; | ||
142 | Eina_Bool value = elm_fileselector_button_expandable_get(fs_bt); | ||
143 | elm_fileselector_button_expandable_set(fs_bt, !value); | ||
144 | printf("Expandable flag set to: %s\n", value ? "false" : "true"); | ||
145 | } | ||
146 | |||
147 | static void | ||
148 | _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
149 | { | ||
150 | free(data); | ||
151 | } | ||
152 | |||
153 | void | ||
154 | test_fileselector_button(void *data __UNUSED__, | ||
155 | Evas_Object *obj __UNUSED__, | ||
156 | void *event_info __UNUSED__) | ||
157 | { | ||
158 | Evas_Object *win, *vbox, *hbox, *ic, *bt, *fs_bt, *en, *lb, *bxx; | ||
159 | api_data *api = calloc(1, sizeof(api_data)); | ||
160 | |||
161 | win = elm_win_util_standard_add("fileselector-button", "File Selector Button"); | ||
162 | elm_win_autodel_set(win, EINA_TRUE); | ||
163 | evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api); | ||
164 | |||
165 | bxx = elm_box_add(win); | ||
166 | elm_win_resize_object_add(win, bxx); | ||
167 | evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
168 | evas_object_show(bxx); | ||
169 | |||
170 | vbox = elm_box_add(win); | ||
171 | api->box = vbox; | ||
172 | evas_object_show(vbox); | ||
173 | |||
174 | bt = elm_button_add(win); | ||
175 | elm_object_text_set(bt, "Next API function"); | ||
176 | evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api); | ||
177 | elm_box_pack_end(bxx, bt); | ||
178 | elm_object_disabled_set(bt, api->state == API_STATE_LAST); | ||
179 | evas_object_show(bt); | ||
180 | |||
181 | elm_box_pack_end(bxx, vbox); | ||
182 | |||
183 | create_dir_struct(); /* Create a dir struct in /tmp */ | ||
184 | /* file selector button */ | ||
185 | ic = elm_icon_add(win); | ||
186 | elm_icon_standard_set(ic, "file"); | ||
187 | evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); | ||
188 | fs_bt = elm_fileselector_button_add(win); | ||
189 | elm_object_text_set(fs_bt, "Select a file"); | ||
190 | elm_object_part_content_set(fs_bt, "icon", ic); | ||
191 | elm_fileselector_button_path_set(fs_bt, "/tmp/test_fs_bt"); | ||
192 | |||
193 | elm_box_pack_end(vbox, fs_bt); | ||
194 | evas_object_show(fs_bt); | ||
195 | evas_object_show(ic); | ||
196 | |||
197 | /* attribute setting buttons */ | ||
198 | hbox = elm_box_add(win); | ||
199 | elm_box_horizontal_set(hbox, EINA_TRUE); | ||
200 | elm_box_pack_end(vbox, hbox); | ||
201 | evas_object_show(hbox); | ||
202 | |||
203 | bt = elm_check_add(win); | ||
204 | elm_object_style_set(bt, "toggle"); | ||
205 | elm_object_text_set(bt, "current selection text entry"); | ||
206 | evas_object_smart_callback_add(bt, "changed", _current_sel_toggle, fs_bt); | ||
207 | elm_box_pack_end(hbox, bt); | ||
208 | evas_object_show(bt); | ||
209 | |||
210 | bt = elm_check_add(win); | ||
211 | elm_object_style_set(bt, "toggle"); | ||
212 | elm_object_text_set(bt, "Inwin mode"); | ||
213 | elm_check_state_set (bt, EINA_TRUE); | ||
214 | evas_object_smart_callback_add(bt, "changed", _inwin_mode_toggle, fs_bt); | ||
215 | elm_box_pack_end(hbox, bt); | ||
216 | evas_object_show(bt); | ||
217 | |||
218 | bt = elm_check_add(win); | ||
219 | elm_object_style_set(bt, "toggle"); | ||
220 | elm_object_text_set(bt, "Folder only mode"); | ||
221 | evas_object_smart_callback_add(bt, "changed", _folder_only_toggle, fs_bt); | ||
222 | elm_box_pack_end(hbox, bt); | ||
223 | evas_object_show(bt); | ||
224 | |||
225 | bt = elm_check_add(win); | ||
226 | elm_object_style_set(bt, "toggle"); | ||
227 | elm_object_text_set(bt, "Expandable mode"); | ||
228 | evas_object_smart_callback_add(bt, "changed", _expandable_toggle, fs_bt); | ||
229 | elm_box_pack_end(hbox, bt); | ||
230 | evas_object_show(bt); | ||
231 | |||
232 | lb = elm_label_add(win); | ||
233 | elm_object_text_set(lb, "Last selection:"); | ||
234 | elm_box_pack_end(vbox, lb); | ||
235 | evas_object_show(lb); | ||
236 | |||
237 | en = elm_entry_add(win); | ||
238 | elm_entry_line_wrap_set(en, ELM_WRAP_NONE); | ||
239 | elm_entry_editable_set(en, EINA_FALSE); | ||
240 | evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, en); | ||
241 | elm_box_pack_end(vbox, en); | ||
242 | evas_object_show(en); | ||
243 | |||
244 | evas_object_resize(win, 400, 400); | ||
245 | evas_object_show(win); | ||
246 | } | ||
247 | #endif | ||