summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-02-01 14:59:00 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-05-01 10:39:01 -0700
commit90e0190161cbceae20b9693848b788f16e6d7104 (patch)
tree4a1ff408397305e88e55531c2cc25140acd215a3 /src
parent756f4cee0e32cb662c4728f64b83b31b5c3f4107 (diff)
elementary: migrate Elm.View.Form to use Efl.Model new interface.
Elm.View.Form is not done and require more work to be released.
Diffstat (limited to 'src')
-rw-r--r--src/lib/elementary/elm_view_form.c263
-rw-r--r--src/lib/elementary/elm_view_form.eo1
2 files changed, 20 insertions, 244 deletions
diff --git a/src/lib/elementary/elm_view_form.c b/src/lib/elementary/elm_view_form.c
index 3055339659..4969310f9b 100644
--- a/src/lib/elementary/elm_view_form.c
+++ b/src/lib/elementary/elm_view_form.c
@@ -25,264 +25,52 @@ typedef struct _Elm_View_Form_Promise Elm_View_Form_Promise;
25/** 25/**
26 * @brief Local-use callbacks 26 * @brief Local-use callbacks
27 */ 27 */
28typedef void (*Elm_View_Form_Event_Cb)(Elm_View_Form_Widget *, Elm_View_Form_Data *, Evas_Object *);
29typedef void (*Elm_View_Form_Widget_Object_Set_Cb)(Evas_Object *, const Eina_Value *, const char *);
30
31struct _Elm_View_Form_Widget
32{
33 Eina_Stringshare *widget_propname;
34 Evas_Object *widget_obj;
35 Elm_View_Form_Event_Cb widget_obj_value_update_cb;
36 Elm_View_Form_Widget_Object_Set_Cb widget_obj_set_cb;
37};
38
39struct _Elm_View_Form_Data 28struct _Elm_View_Form_Data
40{ 29{
41 Eo *model_obj; 30 Eo *model;
42 Eina_List *widgets; 31 Eina_List *links; // List of linked object
43}; 32};
44 33
45struct _Elm_View_Form_Promise
46{
47 Elm_View_Form_Data *priv;
48 Eina_Stringshare *property_name;
49};
50
51
52static void
53_efl_promise_then_widget(void* data, Efl_Event const* event)
54{
55 Elm_View_Form_Widget *w = data;
56 Efl_Future_Event_Success* info = event->info;
57 Eina_Value *value = info->value;
58 w->widget_obj_set_cb(w->widget_obj, value, w->widget_propname);
59}
60
61static void 34static void
62_efl_promise_error_widget(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED) 35_link_dying(void* data, Efl_Event const* event)
63{ 36{
64}
65
66static void
67_efl_model_promise_then_cb(void* data, Efl_Event const* event)
68{
69 Elm_View_Form_Promise *p = data;
70 Eina_Value *value = ((Efl_Future_Event_Success*)event->info)->value;
71 Elm_View_Form_Data *priv = p->priv;
72 Elm_View_Form_Widget *w = NULL;
73 Eina_List *l = NULL;
74
75 EINA_SAFETY_ON_NULL_RETURN(p);
76
77 EINA_LIST_FOREACH(priv->widgets, l, w)
78 {
79 if (!strcmp(w->widget_propname, p->property_name))
80 {
81 w->widget_obj_set_cb(w->widget_obj, value, w->widget_propname);
82 }
83 }
84
85 eina_stringshare_del(p->property_name);
86 free(p);
87}
88
89static void
90_efl_model_promise_error_cb(void* data, Efl_Event const* event EINA_UNUSED)
91{
92 Elm_View_Form_Promise *p = data;
93 EINA_SAFETY_ON_NULL_RETURN(p);
94
95 eina_stringshare_del(p->property_name);
96 free(p);
97}
98
99static void
100_efl_model_properties_change_cb(void *data, const Efl_Event *event)
101{
102 const Efl_Model_Property_Event *evt = event->info;
103 const char *prop;
104 unsigned int i;
105 Elm_View_Form_Data *priv = data; 37 Elm_View_Form_Data *priv = data;
106 Elm_View_Form_Promise *p = NULL;
107 Eina_Array_Iterator it;
108
109 EINA_SAFETY_ON_NULL_RETURN(priv);
110 EINA_SAFETY_ON_NULL_RETURN(evt);
111 38
112 if (!evt->changed_properties) 39 priv->links = eina_list_remove(priv->links, event->object);
113 return;
114
115 //update all widgets with this property
116 EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
117 {
118 p = calloc(1, sizeof(Elm_View_Form_Promise));
119 p->property_name = eina_stringshare_add(prop);
120 p->priv = priv;
121 efl_future_then(efl_model_property_get(priv->model_obj, prop),
122 &_efl_model_promise_then_cb,
123 &_efl_model_promise_error_cb, NULL, p);
124 }
125} 40}
126 41
127static void
128_update_model_properties(Elm_View_Form_Data *priv)
129{
130 Eina_List *l;
131 Elm_View_Form_Widget *w;
132 //update all widgets property
133 if (priv->model_obj == NULL)
134 return;
135
136 EINA_LIST_FOREACH(priv->widgets, l, w)
137 {
138 efl_future_then(efl_model_property_get(priv->model_obj, w->widget_propname),
139 &_efl_promise_then_widget, &_efl_promise_error_widget, NULL, w);
140 }
141}
142
143/**
144 * @brief Set widget.
145 * Works, so far, for widget(s): Entry, Label
146 */
147static void
148_elm_evas_object_text_set_cb(Evas_Object *widget, const Eina_Value *value, const char *propname EINA_UNUSED)
149{
150 const char *c_text = NULL;
151 char *text = NULL;
152
153 EINA_SAFETY_ON_NULL_RETURN(value);
154 EINA_SAFETY_ON_NULL_RETURN(widget);
155
156 text = eina_value_to_string(value);
157 EINA_SAFETY_ON_NULL_RETURN(text);
158
159 c_text = elm_object_text_get(widget);
160 EINA_SAFETY_ON_NULL_RETURN(c_text);
161
162 if (strcmp(text, c_text) != 0)
163 {
164 elm_object_text_set(widget, text);
165 }
166 free(text);
167}
168
169static void
170_elm_evas_object_thumb_set_cb(Evas_Object *thumb, const Eina_Value *value, const char *propname EINA_UNUSED)
171{
172 char *filename = NULL;
173
174 EINA_SAFETY_ON_NULL_RETURN(value);
175 filename = eina_value_to_string(value);
176 EINA_SAFETY_ON_NULL_RETURN(filename);
177 if (strlen(filename) < PATH_MAX)
178 {
179 elm_thumb_file_set(thumb, filename, NULL);
180 elm_thumb_reload(thumb);
181 }
182 free(filename);
183}
184
185/**
186 * @brief Evas object callback implementation.
187 * Updates Widget's value if not the same object
188 * and the widget itself.
189 */
190static void
191_elm_evas_object_text_changed_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
192{
193 Eina_Value value;
194 Eina_List *l;
195 Elm_View_Form_Data *priv = (Elm_View_Form_Data *)data;
196 Elm_View_Form_Widget *w = NULL;
197
198 EINA_LIST_FOREACH(priv->widgets, l, w)
199 {
200 if (w->widget_obj == obj)
201 break;
202 }
203
204 EINA_SAFETY_ON_NULL_RETURN(w);
205 eina_value_setup(&value, EINA_VALUE_TYPE_STRING);
206 eina_value_set(&value, elm_object_text_get(obj));
207 efl_model_property_set(priv->model_obj, w->widget_propname, &value);
208 eina_value_flush(&value);
209}
210/** 42/**
211 * @brief Add new widget object. 43 * @brief Add new widget object.
212 * Adds new widget object on the list 44 * Adds new widget object on the list
213 * and perform initial setup. 45 * and perform initial setup.
214 */ 46 */
215static Eina_Bool 47static Eina_Bool
216_elm_view_widget_add(Elm_View_Form_Data *priv, const char *propname, Evas_Object *widget_obj) 48_elm_view_widget_add(Elm_View_Form_Data *priv, const char *property, Evas_Object *link)
217{ 49{
218 Efl_Future *future = NULL; 50 if (!efl_isa(link, EFL_UI_MODEL_CONNECT_INTERFACE)) return EINA_FALSE;
219 Elm_View_Form_Widget *w = calloc(1, sizeof(Elm_View_Form_Widget)); 51 if (!property) property = "default";
220 EINA_SAFETY_ON_NULL_RETURN_VAL(w, EINA_FALSE);
221 52
222 w->widget_propname = eina_stringshare_add(propname); 53 efl_ui_view_model_set(link, priv->model);
223 w->widget_obj = widget_obj; 54 efl_ui_model_connect(link, "default", property);
224 priv->widgets = eina_list_append(priv->widgets, w); 55 efl_event_callback_add(link, EFL_EVENT_DEL, _link_dying, priv);
225 56
226 if(efl_isa(widget_obj, ELM_ENTRY_CLASS)) 57 priv->links = eina_list_append(priv->links, link);
227 {
228 w->widget_obj_set_cb = _elm_evas_object_text_set_cb;
229 evas_object_event_callback_add(w->widget_obj, EVAS_CALLBACK_KEY_DOWN, _elm_evas_object_text_changed_cb, priv);
230 }
231 else if(efl_isa(widget_obj, ELM_LABEL_CLASS))
232 {
233 w->widget_obj_set_cb = _elm_evas_object_text_set_cb;
234 }
235 else if(efl_isa(widget_obj, ELM_THUMB_CLASS))
236 {
237 w->widget_obj_set_cb = _elm_evas_object_thumb_set_cb;
238 }
239 else
240 {
241 // Widget yet not supported
242 EINA_SAFETY_ON_NULL_RETURN_VAL(NULL, EINA_FALSE);
243 }
244 58
245 if (priv->model_obj != NULL)
246 {
247 future = efl_model_property_get(priv->model_obj, w->widget_propname);
248 efl_future_then(future, &_efl_promise_then_widget,
249 &_efl_promise_error_widget, NULL, priv);
250 }
251 return EINA_TRUE; 59 return EINA_TRUE;
252} 60}
253/** 61/**
254 * Helper functions - End 62 * Helper functions - End
255 */ 63 */
256 64
257
258/**
259 * @brief constructor
260 */
261static Efl_Object*
262_elm_view_form_efl_object_constructor(Eo *obj EINA_UNUSED, Elm_View_Form_Data *_pd)
263{
264 Elm_View_Form_Data *priv = (Elm_View_Form_Data *)_pd;
265 priv->model_obj = NULL;
266
267 efl_constructor(efl_super(obj, MY_CLASS));
268
269 return obj;
270}
271
272/** 65/**
273 * @brief destructor 66 * @brief destructor
274 */ 67 */
275static void 68static void
276_elm_view_form_efl_object_destructor(Eo *obj, Elm_View_Form_Data *priv) 69_elm_view_form_efl_object_destructor(Eo *obj, Elm_View_Form_Data *priv)
277{ 70{
278 Elm_View_Form_Widget *w = NULL; 71 priv->links = eina_list_free(priv->links);
279 EINA_LIST_FREE(priv->widgets, w) 72 efl_unref(priv->model);
280 { 73 priv->model = NULL;
281 eina_stringshare_del(w->widget_propname);
282 free(w);
283 w = NULL;
284 }
285 priv->widgets = NULL;
286 74
287 efl_destructor(efl_super(obj, MY_CLASS)); 75 efl_destructor(efl_super(obj, MY_CLASS));
288} 76}
@@ -291,32 +79,21 @@ _elm_view_form_efl_object_destructor(Eo *obj, Elm_View_Form_Data *priv)
291static void 79static void
292_elm_view_form_model_set(Eo *obj EINA_UNUSED, Elm_View_Form_Data *priv, Eo *model) 80_elm_view_form_model_set(Eo *obj EINA_UNUSED, Elm_View_Form_Data *priv, Eo *model)
293{ 81{
294 if (priv->model_obj != NULL) 82 Efl_Object *link;
295 { 83 Eina_List *l;
296 efl_event_callback_del(priv->model_obj, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _efl_model_properties_change_cb, priv);
297 efl_unref(priv->model_obj);
298 }
299 84
300 priv->model_obj = model; 85 efl_replace(&priv->model, model);
301 86
302 if (priv->model_obj != NULL) 87 EINA_LIST_FOREACH(priv->links, l, link)
303 { 88 efl_ui_view_model_set(link, priv->model);
304 efl_ref(priv->model_obj);
305 efl_event_callback_add(priv->model_obj, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _efl_model_properties_change_cb, priv);
306 _update_model_properties(priv);
307 }
308} 89}
309 90
310static void 91static void
311_elm_view_form_widget_add(Eo *obj EINA_UNUSED, Elm_View_Form_Data *priv, const char *propname, Evas_Object *evas) 92_elm_view_form_widget_add(Eo *obj EINA_UNUSED, Elm_View_Form_Data *priv, const char *propname, Evas_Object *evas)
312{ 93{
313 Eina_Bool status;
314
315 EINA_SAFETY_ON_NULL_RETURN(evas); 94 EINA_SAFETY_ON_NULL_RETURN(evas);
316 EINA_SAFETY_ON_NULL_RETURN(propname);
317 95
318 status = _elm_view_widget_add(priv, propname, evas); 96 _elm_view_widget_add(priv, propname, evas);
319 EINA_SAFETY_ON_FALSE_RETURN(status);
320} 97}
321 98
322#include "elm_view_form.eo.c" 99#include "elm_view_form.eo.c"
diff --git a/src/lib/elementary/elm_view_form.eo b/src/lib/elementary/elm_view_form.eo
index 1045653613..bdc4183fd7 100644
--- a/src/lib/elementary/elm_view_form.eo
+++ b/src/lib/elementary/elm_view_form.eo
@@ -24,7 +24,6 @@ class Elm.View.Form (Efl.Object)
24 } 24 }
25 implements { 25 implements {
26 Efl.Object.destructor; 26 Efl.Object.destructor;
27 Efl.Object.constructor;
28 } 27 }
29 constructors { 28 constructors {
30 .model_set; 29 .model_set;