summaryrefslogtreecommitdiff
path: root/legacy/elementary/src/edje_externals/elm_fileselector_button.c
diff options
context:
space:
mode:
authorGustavo Lima Chaves <glima@profusion.mobi>2010-04-08 20:36:37 +0000
committerGustavo Lima Chaves <glima@profusion.mobi>2010-04-08 20:36:37 +0000
commit23b65bc2de7838f48447d56ce5c4e2b718952b91 (patch)
tree7b51950dbdb4a3aaf2a04c6a47faa44c203175e5 /legacy/elementary/src/edje_externals/elm_fileselector_button.c
parent7c413d98dd6d4f2b25548e4ffeb589cad48be596 (diff)
Welcome a new Elementary widget: file selector button.
This is an elm button extended to launch a file selector on click and to callback_call registered funcs when selection is completed. Many uses may arise from it, but as a fresh 1st example here comes the first (primitive, but cool) video player in edje: externals { external: "emotion"; external: "elm"; } collections { group { name: "main"; parts { part { name: "video"; type: EXTERNAL; source: "emotion"; description { state: "default" 0; rel1 { offset: 10 10; } rel2 { offset: -11 -61; } params { choice: "engine" "gstreamer"; } } } part { name: "play"; type: RECT; description { state: "default" 0; color: 0 255 0 128; rel1 { relative: 0 1; offset: 10 -51; } rel2 { relative: 0.3 1; offset: -6 -11; } } } part { name: "pause"; type: RECT; description { state: "default" 0; color: 255 0 0 128; rel1 { relative: 0.3 1; offset: 5 -51; } rel2 { relative: 0.6 1; offset: -6 -11; } } } part { name: "file_sel_btn"; type: EXTERNAL; source: "elm/fileselector_button"; description { state: "default" 0; rel1 { relative: 0.6 1; offset: 5 -51; } rel2 { offset: -11 -11; } params { string: "label" "open file"; string: "icon" "file"; } } } programs { program { signal: "mouse,clicked,1"; source: "play"; after: "do_play"; } program { name: "do_play"; action: PARAM_SET "video" "play" "1"; } program { signal: "mouse,clicked,1"; source: "pause"; action: PARAM_SET "video" "play" "0"; } program { signal: "file,chosen"; source: "file_sel_btn"; action: PARAM_COPY "file_sel_btn" "path" "video" "file"; after: "do_play"; } } } } } Enjoy. I've seen bugs on the fileselector itself wrt to list selection logic. I'll dig into then soon. SVN revision: 47846
Diffstat (limited to 'legacy/elementary/src/edje_externals/elm_fileselector_button.c')
-rw-r--r--legacy/elementary/src/edje_externals/elm_fileselector_button.c244
1 files changed, 244 insertions, 0 deletions
diff --git a/legacy/elementary/src/edje_externals/elm_fileselector_button.c b/legacy/elementary/src/edje_externals/elm_fileselector_button.c
new file mode 100644
index 0000000..bfa0650
--- /dev/null
+++ b/legacy/elementary/src/edje_externals/elm_fileselector_button.c
@@ -0,0 +1,244 @@
1#include "private.h"
2
3typedef struct _Elm_Params_fileselector_button
4{
5 Elm_Params base;
6 Evas_Object *icon;
7
8 struct {
9 const char *path;
10 Eina_Bool is_save:1;
11 Eina_Bool is_save_set:1;
12 Eina_Bool folder_only:1;
13 Eina_Bool folder_only_set:1;
14 Eina_Bool expandable:1;
15 Eina_Bool expandable_set:1;
16 Eina_Bool inwin_mode:1;
17 Eina_Bool inwin_mode_set:1;
18 } fs;
19} Elm_Params_fileselector_button;
20
21static void
22external_fileselector_button_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
23{
24 const Elm_Params_fileselector_button *p;
25
26 if (to_params) p = to_params;
27 else if (from_params) p = from_params;
28 else return;
29
30 if (p->base.label)
31 elm_fileselector_button_label_set(obj, p->base.label);
32 if (p->icon) elm_fileselector_button_icon_set(obj, p->icon);
33 if (p->fs.path) elm_fileselector_button_selected_set(obj, p->fs.path);
34 if (p->fs.is_save_set)
35 elm_fileselector_button_is_save_set(obj, p->fs.is_save);
36 if (p->fs.folder_only_set)
37 elm_fileselector_button_folder_only_set(obj, p->fs.folder_only);
38 if (p->fs.expandable_set)
39 elm_fileselector_button_expandable_set(obj, p->fs.expandable);
40 if (p->fs.inwin_mode_set)
41 elm_fileselector_button_inwin_mode_set(obj, p->fs.inwin_mode);
42}
43
44static Eina_Bool
45external_fileselector_button_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
46{
47 if (!strcmp(param->name, "label"))
48 {
49 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
50 {
51 elm_fileselector_button_label_set(obj, param->s);
52 return EINA_TRUE;
53 }
54 }
55 else if (!strcmp(param->name, "icon"))
56 {
57 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
58 {
59 Evas_Object *icon = external_common_param_icon_get(obj, param);
60 if (icon)
61 {
62 elm_fileselector_button_icon_set(obj, icon);
63 return EINA_TRUE;
64 }
65 }
66 }
67 else if (!strcmp(param->name, "path"))
68 {
69 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
70 {
71 elm_fileselector_button_selected_set(obj, param->s);
72 return EINA_TRUE;
73 }
74 }
75 else if (!strcmp(param->name, "save"))
76 {
77 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
78 {
79 elm_fileselector_button_is_save_set(obj, param->i);
80 return EINA_TRUE;
81 }
82 }
83 else if (!strcmp(param->name, "folder only"))
84 {
85 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
86 {
87 elm_fileselector_button_folder_only_set(obj, param->i);
88 return EINA_TRUE;
89 }
90 }
91 else if (!strcmp(param->name, "expandable"))
92 {
93 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
94 {
95 elm_fileselector_button_expandable_set(obj, param->i);
96 return EINA_TRUE;
97 }
98 }
99 else if (!strcmp(param->name, "inwin mode"))
100 {
101 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
102 {
103 elm_fileselector_button_inwin_mode_set(obj, param->i);
104 return EINA_TRUE;
105 }
106 }
107
108 ERR("unknown parameter '%s' of type '%s'",
109 param->name, edje_external_param_type_str(param->type));
110
111 return EINA_FALSE;
112}
113
114static Eina_Bool
115external_fileselector_button_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
116{
117 if (!strcmp(param->name, "label"))
118 {
119 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
120 {
121 param->s = elm_fileselector_button_label_get(obj);
122 return EINA_TRUE;
123 }
124 }
125 else if (!strcmp(param->name, "icon"))
126 {
127 /* not easy to get icon name back from live object */
128 return EINA_FALSE;
129 }
130 else if (!strcmp(param->name, "path"))
131 {
132 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
133 {
134 param->s = elm_fileselector_button_selected_get(obj);
135 return EINA_TRUE;
136 }
137 }
138 else if (!strcmp(param->name, "save"))
139 {
140 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
141 {
142 param->i = elm_fileselector_button_is_save_get(obj);
143 return EINA_TRUE;
144 }
145 }
146 else if (!strcmp(param->name, "folder only"))
147 {
148 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
149 {
150 param->i = elm_fileselector_button_folder_only_get(obj);
151 return EINA_TRUE;
152 }
153 }
154 else if (!strcmp(param->name, "expandable"))
155 {
156 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
157 {
158 param->i = elm_fileselector_button_expandable_get(obj);
159 return EINA_TRUE;
160 }
161 }
162 else if (!strcmp(param->name, "inwin mode"))
163 {
164 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
165 {
166 param->i = elm_fileselector_button_inwin_mode_get(obj);
167 return EINA_TRUE;
168 }
169 }
170
171 ERR("unknown parameter '%s' of type '%s'",
172 param->name, edje_external_param_type_str(param->type));
173
174 return EINA_FALSE;
175}
176
177static void *
178external_fileselector_button_params_parse(void *data, Evas_Object *obj, const Eina_List *params)
179{
180 Elm_Params_fileselector_button *mem;
181 Edje_External_Param *param;
182 const Eina_List *l;
183
184 mem = external_common_params_parse(Elm_Params_fileselector_button,
185 data, obj, params);
186 if (!mem)
187 return NULL;
188
189 external_common_icon_param_parse(&mem->icon, obj, params);
190
191 EINA_LIST_FOREACH(params, l, param)
192 {
193 if (!strcmp(param->name, "path"))
194 mem->fs.path = eina_stringshare_add(param->s);
195 else if (!strcmp(param->name, "save"))
196 {
197 mem->fs.is_save = !!param->i;
198 mem->fs.is_save_set = EINA_TRUE;
199 }
200 else if (!strcmp(param->name, "folder only"))
201 {
202 mem->fs.folder_only = !!param->i;
203 mem->fs.folder_only_set = EINA_TRUE;
204 }
205 else if (!strcmp(param->name, "expandable"))
206 {
207 mem->fs.expandable = !!param->i;
208 mem->fs.expandable_set = EINA_TRUE;
209 }
210 else if (!strcmp(param->name, "inwin mode"))
211 {
212 mem->fs.inwin_mode = !!param->i;
213 mem->fs.inwin_mode_set = EINA_TRUE;
214 }
215 }
216
217 return mem;
218}
219
220 static void
221external_fileselector_button_params_free(void *params)
222{
223 Elm_Params_fileselector_button *mem = params;
224
225 if (mem->icon)
226 evas_object_del(mem->icon);
227 if (mem->fs.path)
228 eina_stringshare_del(mem->fs.path);
229 external_common_params_free(params);
230}
231
232static Edje_External_Param_Info external_fileselector_button_params[] = {
233 DEFINE_EXTERNAL_COMMON_PARAMS,
234 EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
235 EDJE_EXTERNAL_PARAM_INFO_STRING("path"),
236 EDJE_EXTERNAL_PARAM_INFO_BOOL("save"),
237 EDJE_EXTERNAL_PARAM_INFO_BOOL("folder only"),
238 EDJE_EXTERNAL_PARAM_INFO_BOOL("expandable"),
239 EDJE_EXTERNAL_PARAM_INFO_BOOL("inwin mode"),
240 EDJE_EXTERNAL_PARAM_INFO_SENTINEL
241};
242
243DEFINE_EXTERNAL_ICON_ADD(fileselector_button, "fileselector_button");
244DEFINE_EXTERNAL_TYPE_SIMPLE(fileselector_button, "File Selector Button");