The elm_toolbar_iteams_count have to return only the number of manually added items.
[framework/uifw/elementary.git] / src / examples / fileselector_example.c
1 /**
2  * Simple Elementary's <b>file selector 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_example.c -o file selector_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 /* 'done' cb */
23 static void
24 _fs_done(void        *data,
25          Evas_Object *obj,
26          void        *event_info)
27 {
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) */
31
32    printf("We're done! Selected file is: %s\n",
33           selected ? selected : "*none!*");
34
35    _on_done(NULL, NULL, NULL);
36 }
37
38 /* 'selected' cb */
39 static void
40 _fs_selected(void        *data,
41              Evas_Object *obj,
42              void        *event_info)
43 {
44    const char *selected = event_info;
45    /* event_info contains the full path of the selected file */
46
47    printf("There's been a selection: %s\n", selected);
48 }
49
50 static void
51 _is_save_clicked(void        *data,
52                  Evas_Object *obj,
53                  void        *event_info)
54 {
55    Evas_Object *fs = data;
56    Eina_Bool old_val = elm_fileselector_is_save_get(fs);
57
58    printf("%s text entry with selected item's name\n",
59           old_val ? "Disabling" : "Enabling");
60
61    elm_fileselector_is_save_set(fs, !old_val);
62 }
63
64 static void
65 _folder_only_clicked(void        *data,
66                      Evas_Object *obj,
67                      void        *event_info)
68 {
69    Evas_Object *fs = data;
70    Eina_Bool old_val = elm_fileselector_folder_only_get(fs);
71
72    printf("%s folder-only mode\n",
73           old_val ? "Disabling" : "Enabling");
74
75    elm_fileselector_folder_only_set(fs, !old_val);
76 }
77
78 static void
79 _expandable_clicked(void        *data,
80                     Evas_Object *obj,
81                     void        *event_info)
82 {
83    Evas_Object *fs = data;
84    Eina_Bool old_val = elm_fileselector_expandable_get(fs);
85
86    printf("%s tree-view mode\n",
87           old_val ? "Disabling" : "Enabling");
88
89    elm_fileselector_expandable_set(fs, !old_val);
90 }
91
92 static void
93 _sel_get_clicked(void        *data,
94                  Evas_Object *obj,
95                  void        *event_info)
96 {
97    Evas_Object *fs = data;
98    printf("Current selection is: %s\n", elm_fileselector_selected_get(fs));
99 }
100
101 static void
102 _path_get_clicked(void        *data,
103                   Evas_Object *obj,
104                   void        *event_info)
105 {
106    Evas_Object *fs = data;
107    printf("Current selection's directory path is: %s\n",
108           elm_fileselector_path_get(fs));
109 }
110
111 EAPI_MAIN int
112 elm_main(int    argc,
113          char **argv)
114 {
115     Evas_Object *win, *fs, *bg, *vbox, *buttons_bx, *bt, *sep, *bx;
116
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
119     * manner
120     */
121    setlocale(LC_ALL, "");
122
123    elm_need_ethumb(); /* let's have thumbnails of images on grid view */
124
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);
128
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);
133
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);
140
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);
146
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");
155
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);
160
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);
165
166    /* test buttons */
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);
171
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);
176
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);
183
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);
190
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);
197
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);
202
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);
208
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);
214
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);
219
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");
226
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);
231
232    evas_object_resize(win, 800, 600);
233    evas_object_show(win);
234
235    elm_run();
236    elm_shutdown();
237
238    return 0;
239 }
240 ELM_MAIN()