Revert a wrong commit. Un-wanted files are committed together.
[framework/uifw/elementary.git] / src / bin / test_fileselector_button.c
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, *bg, *vbox, *hbox, *ic, *bt, *fs_bt, *en, *lb, *bxx;
159    api_data *api = calloc(1, sizeof(api_data));
160
161    win = elm_win_add(NULL, "fileselector-button", ELM_WIN_BASIC);
162    elm_win_title_set(win, "File Selector Button");
163    elm_win_autodel_set(win, EINA_TRUE);
164    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
165
166    bg = elm_bg_add(win);
167    elm_win_resize_object_add(win, bg);
168    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169    evas_object_show(bg);
170
171    bxx = elm_box_add(win);
172    elm_win_resize_object_add(win, bxx);
173    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174    evas_object_show(bxx);
175
176    vbox = elm_box_add(win);
177    api->box = vbox;
178    evas_object_show(vbox);
179
180    bt = elm_button_add(win);
181    elm_object_text_set(bt, "Next API function");
182    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
183    elm_box_pack_end(bxx, bt);
184    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
185    evas_object_show(bt);
186
187    elm_box_pack_end(bxx, vbox);
188
189    create_dir_struct(); /* Create a dir struct in /tmp */
190    /* file selector button */
191    ic = elm_icon_add(win);
192    elm_icon_standard_set(ic, "file");
193    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
194    fs_bt = elm_fileselector_button_add(win);
195    elm_object_text_set(fs_bt, "Select a file");
196    elm_object_part_content_set(fs_bt, "icon", ic);
197    elm_fileselector_button_path_set(fs_bt, "/tmp/test_fs_bt");
198
199    elm_box_pack_end(vbox, fs_bt);
200    evas_object_show(fs_bt);
201    evas_object_show(ic);
202
203    /* attribute setting buttons */
204    hbox = elm_box_add(win);
205    elm_box_horizontal_set(hbox, EINA_TRUE);
206    elm_box_pack_end(vbox, hbox);
207    evas_object_show(hbox);
208
209    bt = elm_check_add(win);
210    elm_object_style_set(bt, "toggle");
211    elm_object_text_set(bt, "current selection text entry");
212    evas_object_smart_callback_add(bt, "changed", _current_sel_toggle, fs_bt);
213    elm_box_pack_end(hbox, bt);
214    evas_object_show(bt);
215
216    bt = elm_check_add(win);
217    elm_object_style_set(bt, "toggle");
218    elm_object_text_set(bt, "Inwin mode");
219    elm_check_state_set (bt, EINA_TRUE);
220    evas_object_smart_callback_add(bt, "changed", _inwin_mode_toggle, fs_bt);
221    elm_box_pack_end(hbox, bt);
222    evas_object_show(bt);
223
224    bt = elm_check_add(win);
225    elm_object_style_set(bt, "toggle");
226    elm_object_text_set(bt, "Folder only mode");
227    evas_object_smart_callback_add(bt, "changed", _folder_only_toggle, fs_bt);
228    elm_box_pack_end(hbox, bt);
229    evas_object_show(bt);
230
231    bt = elm_check_add(win);
232    elm_object_style_set(bt, "toggle");
233    elm_object_text_set(bt, "Expandable mode");
234    evas_object_smart_callback_add(bt, "changed", _expandable_toggle, fs_bt);
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    en = elm_entry_add(win);
244    elm_entry_line_wrap_set(en, ELM_WRAP_NONE);
245    elm_entry_editable_set(en, EINA_FALSE);
246    evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, en);
247    elm_box_pack_end(vbox, en);
248    evas_object_show(en);
249
250    evas_object_resize(win, 400, 400);
251    evas_object_show(win);
252 }
253 #endif