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