aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/fileselector_button_example.c
blob: 2a1929d0ee69a8fd7af794b9d9d9394e506fea7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
 * Simple Elementary's <b>file selector button widget</b> example,
 * illustrating its usage and API.
 *
 * See stdout/stderr for output. Compile with:
 *
 * @verbatim
 * gcc -g file selector_button_example.c -o file selector_button_example `pkg-config --cflags --libs elementary`
 * @endverbatim
 */

#include <Elementary.h>

static void /* hook on the sole smart callback */
_file_chosen(void            *data,
             Evas_Object *obj,
             void            *event_info)
{
   Evas_Object *entry = data;
   const char *file = event_info;
   if (file)
     {
        elm_object_text_set(entry, file);
        printf("File chosen: %s\n", file);
     }
   else
     printf("File selection canceled.\n");
}

/* toggle inwin mode */
static void
_inwin_mode_toggle(void            *data,
                   Evas_Object *obj,
                   void *event_info)
{
   Evas_Object *fs_bt = data;
   Eina_Bool old_val = elm_fileselector_button_inwin_mode_get(fs_bt);

   elm_fileselector_button_inwin_mode_set(fs_bt, !old_val);
   printf("Inwin mode set to: %s\n", old_val ? "false" : "true");
}

static void
_current_sel_toggle(void            *data,
                    Evas_Object *obj,
                    void *event_info)
{
   Evas_Object *fs_bt = data;
   Eina_Bool old_val = elm_fileselector_is_save_get(fs_bt);
   elm_fileselector_is_save_set(fs_bt, !old_val);

   printf("%s text entry with selected item's name\n",
          old_val ? "Disabling" : "Enabling");
}

static void
_folder_only_toggle(void            *data,
                    Evas_Object *obj,
                    void *event_info)
{
   Evas_Object *fs_bt = data;
   Eina_Bool old_val = elm_fileselector_folder_only_get(fs_bt);
   elm_fileselector_folder_only_set(fs_bt, !old_val);

   printf("Folder only mode set to: %s\n", old_val ? "false" : "true");
}

static void
_expandable_toggle(void            *data,
                   Evas_Object *obj,
                   void *event_info)
{
   Evas_Object *fs_bt = data;
   Eina_Bool old_val = elm_fileselector_expandable_get(fs_bt);
   elm_fileselector_expandable_set(fs_bt, !old_val);

   printf("Expandable folders mode set to: %s\n", old_val ? "false" : "true");
}

EAPI_MAIN int
elm_main(int    argc,
         char **argv)
{
   Evas_Object *win, *vbox, *hbox, *ic, *ck, *fs_bt, *en, *lb, *sep;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add("fileselector-button", "File Selector Button Example");
   elm_win_autodel_set(win, EINA_TRUE);

   vbox = elm_box_add(win);
   evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, vbox);
   evas_object_show(vbox);

   ic = elm_icon_add(win);
   elm_icon_standard_set(ic, "file");
   evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);

   /* file selector button */
   fs_bt = elm_fileselector_button_add(win);
   elm_fileselector_path_set(fs_bt, "/tmp");
   elm_object_text_set(fs_bt, "Select a file");
   elm_object_part_content_set(fs_bt, "icon", ic);

   elm_box_pack_end(vbox, fs_bt);
   evas_object_show(fs_bt);
   evas_object_show(ic);

   /* attribute setting knobs */
   sep = elm_separator_add(win);
   elm_separator_horizontal_set(sep, EINA_TRUE);
   elm_box_pack_end(vbox, sep);
   evas_object_show(sep);

   hbox = elm_box_add(win);
   elm_box_horizontal_set(hbox, EINA_TRUE);
   elm_box_pack_end(vbox, hbox);
   evas_object_show(hbox);

   ck = elm_check_add(win);
   elm_object_text_set(ck, "editable selection");
   elm_check_state_set(ck, elm_fileselector_is_save_get(fs_bt));
   evas_object_smart_callback_add(ck, "changed", _current_sel_toggle, fs_bt);
   elm_box_pack_end(hbox, ck);
   evas_object_show(ck);

   ck = elm_check_add(win);
   elm_object_text_set(ck, "\"inwin\" mode");
   elm_check_state_set(ck, elm_fileselector_button_inwin_mode_get(fs_bt));
   evas_object_smart_callback_add(ck, "changed", _inwin_mode_toggle, fs_bt);
   elm_box_pack_end(hbox, ck);
   evas_object_show(ck);

   ck = elm_check_add(win);
   elm_object_text_set(ck, "folders only");
   elm_check_state_set(ck, elm_fileselector_folder_only_get(fs_bt));
   evas_object_smart_callback_add(ck, "changed", _folder_only_toggle, fs_bt);
   elm_box_pack_end(hbox, ck);
   evas_object_show(ck);

   ck = elm_check_add(win);
   elm_object_text_set(ck, "expandable");
   elm_check_state_set(ck, elm_fileselector_expandable_get(fs_bt));
   evas_object_smart_callback_add(ck, "changed", _expandable_toggle, fs_bt);
   elm_box_pack_end(hbox, ck);
   evas_object_show(ck);

   lb = elm_label_add(win);
   elm_object_text_set(lb, "Last selection:");
   elm_box_pack_end(vbox, lb);
   evas_object_show(lb);

   en = elm_entry_add(win);
   elm_entry_line_wrap_set(en, EINA_FALSE);
   elm_entry_editable_set(en, EINA_FALSE);
   evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, en);
   elm_box_pack_end(vbox, en);
   evas_object_show(en);

   evas_object_resize(win, 400, 400);
   evas_object_show(win);

   elm_run();

   return 0;
}
ELM_MAIN()