Tizen 2.1 base
[framework/uifw/elementary.git] / src / examples / fileselector_entry_example.c
1 /**
2  * Simple Elementary's <b>file selector entry widget</b> example,
3  * illustrating its usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g file selector_entry_example.c -o file selector_entry_example `pkg-config --cflags --libs elementary`
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13
14 static void
15 _on_done(void        *data,
16          Evas_Object *obj,
17          void        *event_info)
18 {
19    elm_exit();
20 }
21
22 /* hook on the file,chosen smart callback */
23 static void
24 _file_chosen(void        *data,
25              Evas_Object *obj,
26              void        *event_info)
27 {
28    const char *file = event_info;
29
30    if (file)
31      printf("File chosen: %s\n", file);
32    else
33      printf("File selection canceled.\n");
34 }
35
36 /* toggle inwin mode */
37 static void
38 _inwin_mode_toggle(void        *data,
39                    Evas_Object *obj,
40                    void        *event_info)
41 {
42    Evas_Object *fs_entry = data;
43    Eina_Bool old_val = elm_fileselector_entry_inwin_mode_get(fs_entry);
44
45    elm_fileselector_entry_inwin_mode_set(fs_entry, !old_val);
46    printf("Inwin mode set to: %s\n", old_val ? "false" : "true");
47 }
48
49 static void
50 _current_sel_toggle(void        *data,
51                     Evas_Object *obj,
52                     void        *event_info)
53 {
54    Evas_Object *fs_entry = data;
55    Eina_Bool old_val = elm_fileselector_entry_is_save_get(fs_entry);
56    elm_fileselector_entry_is_save_set(fs_entry, !old_val);
57
58    printf("%s text entry with selected item's name\n",
59           old_val ? "Disabling" : "Enabling");
60 }
61
62 static void
63 _folder_only_toggle(void        *data,
64                     Evas_Object *obj,
65                     void        *event_info)
66 {
67    Evas_Object *fs_entry = data;
68    Eina_Bool old_val = elm_fileselector_entry_folder_only_get(fs_entry);
69    elm_fileselector_entry_folder_only_set(fs_entry, !old_val);
70
71    printf("Folder only mode set to: %s\n", old_val ? "false" : "true");
72 }
73
74 static void
75 _expandable_toggle(void        *data,
76                    Evas_Object *obj,
77                    void        *event_info)
78 {
79    Evas_Object *fs_entry = data;
80    Eina_Bool old_val = elm_fileselector_entry_expandable_get(fs_entry);
81    elm_fileselector_entry_expandable_set(fs_entry, !old_val);
82
83    printf("Expandable folders mode set to: %s\n", old_val ? "false" : "true");
84 }
85
86 EAPI_MAIN int
87 elm_main(int    argc,
88          char **argv)
89 {
90    Evas_Object *win, *bg, *vbox, *hbox, *ic, *ck, *fs_entry, *sep;
91
92    win = elm_win_add(NULL, "fileselector-entry", ELM_WIN_BASIC);
93    elm_win_title_set(win, "File Selector Entry Example");
94    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
95
96    bg = elm_bg_add(win);
97    elm_win_resize_object_add(win, bg);
98    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99    evas_object_show(bg);
100
101    vbox = elm_box_add(win);
102    elm_win_resize_object_add(win, vbox);
103    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104    evas_object_show(vbox);
105
106    ic = elm_icon_add(win);
107    elm_icon_standard_set(ic, "file");
108    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
109
110    /* file selector entry */
111    fs_entry = elm_fileselector_entry_add(win);
112    evas_object_size_hint_align_set(fs_entry, EVAS_HINT_FILL, 0);
113    elm_fileselector_entry_path_set(fs_entry, "/tmp");
114    elm_object_text_set(fs_entry, "Select a file");
115    elm_object_part_content_set(fs_entry, "button icon", ic);
116
117    elm_box_pack_end(vbox, fs_entry);
118    evas_object_show(fs_entry);
119    evas_object_show(ic);
120
121    /* attribute setting knobs */
122    sep = elm_separator_add(win);
123    elm_separator_horizontal_set(sep, EINA_TRUE);
124    elm_box_pack_end(vbox, sep);
125    evas_object_show(sep);
126
127    hbox = elm_box_add(win);
128    elm_box_horizontal_set(hbox, EINA_TRUE);
129    elm_box_pack_end(vbox, hbox);
130    evas_object_show(hbox);
131
132    ck = elm_check_add(win);
133    elm_object_text_set(ck, "editable selection");
134    elm_check_state_set(ck, elm_fileselector_entry_is_save_get(fs_entry));
135    evas_object_smart_callback_add(ck, "changed", _current_sel_toggle, fs_entry);
136    elm_box_pack_end(hbox, ck);
137    evas_object_show(ck);
138
139    ck = elm_check_add(win);
140    elm_object_text_set(ck, "\"inwin\" mode");
141    elm_check_state_set(ck, elm_fileselector_entry_inwin_mode_get(fs_entry));
142    evas_object_smart_callback_add(ck, "changed", _inwin_mode_toggle, fs_entry);
143    elm_box_pack_end(hbox, ck);
144    evas_object_show(ck);
145
146    ck = elm_check_add(win);
147    elm_object_text_set(ck, "folders only");
148    elm_check_state_set(ck, elm_fileselector_entry_folder_only_get(fs_entry));
149    evas_object_smart_callback_add(ck, "changed", _folder_only_toggle, fs_entry);
150    elm_box_pack_end(hbox, ck);
151    evas_object_show(ck);
152
153    ck = elm_check_add(win);
154    elm_object_text_set(ck, "expandable");
155    elm_check_state_set(ck, elm_fileselector_entry_expandable_get(fs_entry));
156    evas_object_smart_callback_add(ck, "changed", _expandable_toggle, fs_entry);
157    elm_box_pack_end(hbox, ck);
158    evas_object_show(ck);
159
160    evas_object_smart_callback_add(fs_entry, "file,chosen", _file_chosen, NULL);
161
162    evas_object_resize(win, 400, 400);
163    evas_object_show(win);
164
165    elm_run();
166    elm_shutdown();
167
168    return 0;
169 }
170 ELM_MAIN()