summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2015-03-19 19:08:14 -0300
committerLarry Jr <larry.olj@gmail.com>2015-03-19 19:08:14 -0300
commit056d9ad1fa7ed57ee85f5ae5b387763f10dcd11c (patch)
tree34080f564e0f40f4696c6a5d62cc833967b23d6d
parentb2494ef738f3ad8b1bd12a258ba8867cd574eef1 (diff)
elmview: refactory do new emodel api
-rw-r--r--src/examples/filemvc.c5
-rw-r--r--src/lib/elm_view_form.c78
-rw-r--r--src/lib/elm_view_list.c29
3 files changed, 62 insertions, 50 deletions
diff --git a/src/examples/filemvc.c b/src/examples/filemvc.c
index 580845275..254e8db71 100644
--- a/src/examples/filemvc.c
+++ b/src/examples/filemvc.c
@@ -59,16 +59,15 @@ _tree_selected_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *d
59 printf("TREE selected model\n"); 59 printf("TREE selected model\n");
60 Emodel_Test_Filemvc_Data *priv = data; 60 Emodel_Test_Filemvc_Data *priv = data;
61 Eo *child = event_info; 61 Eo *child = event_info;
62 Eina_Value vpath; 62 const Eina_Value *vpath;
63 Eo *model; 63 Eo *model;
64 char *path; 64 char *path;
65 65
66 eo_do(child, emodel_property_get("path", &vpath)); 66 eo_do(child, emodel_property_get("path", &vpath));
67 eina_value_get(&vpath, &path); 67 eina_value_get(vpath, &path);
68 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(path)); 68 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(path));
69 eo_do(model, emodel_load()); 69 eo_do(model, emodel_load());
70 eo_do(priv->fileview, elm_view_list_model_set(model)); 70 eo_do(priv->fileview, elm_view_list_model_set(model));
71 eina_value_flush(&vpath);
72// eo_unref(model); 71// eo_unref(model);
73 return EINA_TRUE; 72 return EINA_TRUE;
74} 73}
diff --git a/src/lib/elm_view_form.c b/src/lib/elm_view_form.c
index f08c00e8b..347c7173f 100644
--- a/src/lib/elm_view_form.c
+++ b/src/lib/elm_view_form.c
@@ -21,7 +21,7 @@ typedef struct _Elm_View_Form_Widget Elm_View_Form_Widget;
21 * @brief Local-use callbacks 21 * @brief Local-use callbacks
22 */ 22 */
23typedef void (*Elm_View_Form_Event_Cb)(Elm_View_Form_Widget *, Elm_View_Form_Data *, Evas_Object *); 23typedef void (*Elm_View_Form_Event_Cb)(Elm_View_Form_Widget *, Elm_View_Form_Data *, Evas_Object *);
24typedef void (*Elm_View_Form_Widget_Object_Set_Cb)(Eo *, Evas_Object *, Eina_Value *, const char *); 24typedef void (*Elm_View_Form_Widget_Object_Set_Cb)(Eo *, Evas_Object *, const Eina_Value *, const char *);
25 25
26struct _Elm_View_Form_Widget 26struct _Elm_View_Form_Widget
27{ 27{
@@ -42,25 +42,31 @@ static Eina_Bool
42_emodel_properties_change_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 42_emodel_properties_change_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
43{ 43{
44 const Emodel_Property_Event *evt = event_info; 44 const Emodel_Property_Event *evt = event_info;
45 const Eina_Value *value;
46 const char *prop;
47 unsigned int i;
45 Elm_View_Form_Data *priv = data; 48 Elm_View_Form_Data *priv = data;
46 Eina_Value value;
47 Eina_List *l = NULL; 49 Eina_List *l = NULL;
48 Elm_View_Form_Widget *w = NULL; 50 Elm_View_Form_Widget *w = NULL;
51 Eina_Array_Iterator it;
49 52
50 EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EINA_TRUE); 53 EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EINA_TRUE);
51 EINA_SAFETY_ON_NULL_RETURN_VAL(evt, EINA_TRUE); 54 EINA_SAFETY_ON_NULL_RETURN_VAL(evt, EINA_TRUE);
52 55
53 if (evt->changed_properties && eina_value_type_get(evt->changed_properties) == EINA_VALUE_TYPE_STRUCT) 56 if (!evt->changed_properties)
57 return EINA_TRUE;
58
59 //update all widgets with this property
60 EINA_LIST_FOREACH(priv->l, l, w)
54 { 61 {
55 //update all widgets with this property 62 EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
56 EINA_LIST_FOREACH(priv->l, l, w) 63 {
57 { 64 if (!strcmp(w->widget_propname, prop))
58 if (eina_value_struct_value_get(evt->changed_properties, w->widget_propname, &value) == EINA_TRUE)
59 { 65 {
60 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, &value, w->widget_propname); 66 eo_do(priv->model_obj, emodel_property_get(prop, &value));
61 eina_value_flush(&value); 67 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, value, w->widget_propname);
62 } 68 }
63 } 69 }
64 } 70 }
65 71
66 return EINA_TRUE; 72 return EINA_TRUE;
@@ -69,15 +75,14 @@ _emodel_properties_change_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Des
69static void 75static void
70_update_model_properties(Elm_View_Form_Data *priv) 76_update_model_properties(Elm_View_Form_Data *priv)
71{ 77{
72 Eina_Value value; 78 const Eina_Value *value;
73 Eina_List *l; 79 Eina_List *l;
74 Elm_View_Form_Widget *w; 80 Elm_View_Form_Widget *w;
75 //update all widgets property 81 //update all widgets property
76 EINA_LIST_FOREACH(priv->l, l, w) 82 EINA_LIST_FOREACH(priv->l, l, w)
77 { 83 {
78 eo_do(priv->model_obj, emodel_property_get(w->widget_propname, &value)); 84 eo_do(priv->model_obj, emodel_property_get(w->widget_propname, &value));
79 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, &value, w->widget_propname); 85 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, value, w->widget_propname);
80 eina_value_flush(&value);
81 } 86 }
82} 87}
83 88
@@ -86,12 +91,20 @@ _update_model_properties(Elm_View_Form_Data *priv)
86 * Works, so far, for widget(s): Entry, Label 91 * Works, so far, for widget(s): Entry, Label
87 */ 92 */
88static void 93static void
89_elm_evas_object_text_set_cb(Eo *obj EINA_UNUSED, Evas_Object *widget, Eina_Value *value, const char *propname EINA_UNUSED) 94_elm_evas_object_text_set_cb(Eo *obj EINA_UNUSED, Evas_Object *widget, const Eina_Value *value, const char *propname EINA_UNUSED)
90{ 95{
91 char *text = eina_value_to_string(value); 96 const char *c_text = NULL;
92 const char *c_text = elm_object_text_get(widget); 97 char *text = NULL;
98
99 EINA_SAFETY_ON_NULL_RETURN(value);
100 EINA_SAFETY_ON_NULL_RETURN(widget);
101
102 text = eina_value_to_string(value);
93 EINA_SAFETY_ON_NULL_RETURN(text); 103 EINA_SAFETY_ON_NULL_RETURN(text);
94 104
105 c_text = elm_object_text_get(widget);
106 EINA_SAFETY_ON_NULL_RETURN(c_text);
107
95 if (strcmp(text, c_text) != 0) 108 if (strcmp(text, c_text) != 0)
96 { 109 {
97 elm_object_text_set(widget, text); 110 elm_object_text_set(widget, text);
@@ -100,14 +113,18 @@ _elm_evas_object_text_set_cb(Eo *obj EINA_UNUSED, Evas_Object *widget, Eina_Valu
100} 113}
101 114
102static void 115static void
103_elm_evas_object_thumb_set_cb(Eo *obj EINA_UNUSED, Evas_Object *thumb, Eina_Value *value, const char *propname EINA_UNUSED) 116_elm_evas_object_thumb_set_cb(Eo *obj EINA_UNUSED, Evas_Object *thumb, const Eina_Value *value, const char *propname EINA_UNUSED)
104{ 117{
105 char *filename = eina_value_to_string(value); 118 char *filename = NULL;
106 EINA_SAFETY_ON_NULL_RETURN(filename);
107 EINA_SAFETY_ON_TRUE_RETURN(strlen(filename) >= PATH_MAX);
108 119
109 elm_thumb_file_set(thumb, filename, NULL); 120 EINA_SAFETY_ON_NULL_RETURN(value);
110 elm_thumb_reload(thumb); 121 filename = eina_value_to_string(value);
122 EINA_SAFETY_ON_NULL_RETURN(filename);
123 if (strlen(filename) < PATH_MAX)
124 {
125 elm_thumb_file_set(thumb, filename, NULL);
126 elm_thumb_reload(thumb);
127 }
111 free(filename); 128 free(filename);
112} 129}
113 130
@@ -133,7 +150,7 @@ _elm_evas_object_text_changed_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o
133 EINA_SAFETY_ON_NULL_RETURN(w); 150 EINA_SAFETY_ON_NULL_RETURN(w);
134 eina_value_setup(&value, EINA_VALUE_TYPE_STRING); 151 eina_value_setup(&value, EINA_VALUE_TYPE_STRING);
135 eina_value_set(&value, elm_object_text_get(obj)); 152 eina_value_set(&value, elm_object_text_get(obj));
136 eo_do(priv->model_obj, emodel_property_set(w->widget_propname, value)); 153 eo_do(priv->model_obj, emodel_property_set(w->widget_propname, &value));
137 eina_value_flush(&value); 154 eina_value_flush(&value);
138} 155}
139/** 156/**
@@ -144,7 +161,7 @@ _elm_evas_object_text_changed_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o
144static Eina_Bool 161static Eina_Bool
145_elm_view_widget_add(Elm_View_Form_Data *priv, const char *propname, Evas_Object *widget_obj) 162_elm_view_widget_add(Elm_View_Form_Data *priv, const char *propname, Evas_Object *widget_obj)
146{ 163{
147 Eina_Value value; 164 const Eina_Value *value = NULL;
148 Elm_View_Form_Widget *w = calloc(1, sizeof(Elm_View_Form_Widget)); 165 Elm_View_Form_Widget *w = calloc(1, sizeof(Elm_View_Form_Widget));
149 EINA_SAFETY_ON_NULL_RETURN_VAL(w, EINA_FALSE); 166 EINA_SAFETY_ON_NULL_RETURN_VAL(w, EINA_FALSE);
150 167
@@ -171,10 +188,10 @@ _elm_view_widget_add(Elm_View_Form_Data *priv, const char *propname, Evas_Object
171 EINA_SAFETY_ON_NULL_RETURN_VAL(NULL, EINA_FALSE); 188 EINA_SAFETY_ON_NULL_RETURN_VAL(NULL, EINA_FALSE);
172 } 189 }
173 190
174 if (eo_do(priv->model_obj, emodel_property_get(propname, &value)) == EINA_TRUE) 191 eo_do(priv->model_obj, emodel_property_get(propname, &value));
192 if (value)
175 { 193 {
176 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, &value, w->widget_propname); 194 w->widget_obj_set_cb(priv->model_obj, w->widget_obj, value, w->widget_propname);
177 eina_value_flush(&value);
178 } 195 }
179 196
180 return EINA_TRUE; 197 return EINA_TRUE;
@@ -199,16 +216,11 @@ _elm_view_form_constructor(Eo *obj EINA_UNUSED, Elm_View_Form_Data *_pd, Eo *mod
199 } 216 }
200} 217}
201 218
202static void
203_elm_view_form_eo_base_constructor(Eo *obj, Elm_View_Form_Data *_pd EINA_UNUSED)
204{
205}
206
207/** 219/**
208 * @brief destructor 220 * @brief destructor
209 */ 221 */
210static void 222static void
211_elm_view_form_eo_base_destructor(Eo *obj EINA_UNUSED, Elm_View_Form_Data *priv) 223_elm_view_form_eo_base_destructor(Eo *obj, Elm_View_Form_Data *priv)
212{ 224{
213 Elm_View_Form_Widget *w = NULL; 225 Elm_View_Form_Widget *w = NULL;
214 EINA_LIST_FREE(priv->l, w) 226 EINA_LIST_FREE(priv->l, w)
diff --git a/src/lib/elm_view_list.c b/src/lib/elm_view_list.c
index 56b5df07b..8f78651b2 100644
--- a/src/lib/elm_view_list.c
+++ b/src/lib/elm_view_list.c
@@ -79,8 +79,7 @@ _item_del(void *data, Evas_Object *obj EINA_UNUSED)
79static Evas_Object * 79static Evas_Object *
80_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 80_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
81{ 81{
82 //XXX: Add a Custon content function?? 82 const Eina_Value *value = NULL;
83 Eina_Value value;
84 const Eina_Value_Type *vtype; 83 const Eina_Value_Type *vtype;
85 Evas_Object *content = NULL; 84 Evas_Object *content = NULL;
86 View_List_ItemData *idata = data; 85 View_List_ItemData *idata = data;
@@ -91,13 +90,15 @@ _item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
91 const char *prop = eina_hash_find(priv->prop_con, part); 90 const char *prop = eina_hash_find(priv->prop_con, part);
92 if (prop == NULL) prop = part; 91 if (prop == NULL) prop = part;
93 92
94 eina_value_setup(&value, EINA_VALUE_TYPE_STRING);
95 eo_do(idata->model, emodel_property_get(prop, &value)); 93 eo_do(idata->model, emodel_property_get(prop, &value));
96 vtype = eina_value_type_get(&value); 94 if (value == NULL)
95 return content;
96
97 vtype = eina_value_type_get(value);
97 if (vtype == EINA_VALUE_TYPE_STRING || vtype == EINA_VALUE_TYPE_STRINGSHARE) 98 if (vtype == EINA_VALUE_TYPE_STRING || vtype == EINA_VALUE_TYPE_STRINGSHARE)
98 { 99 {
99 char *content_s; 100 char *content_s = NULL;
100 eina_value_get(&value, &content_s); 101 content_s = eina_value_to_string(value);
101 content = elm_icon_add(obj); 102 content = elm_icon_add(obj);
102 if (elm_icon_standard_set(content, content_s)) 103 if (elm_icon_standard_set(content, content_s))
103 { 104 {
@@ -108,19 +109,20 @@ _item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
108 evas_object_del(content); 109 evas_object_del(content);
109 content = NULL; 110 content = NULL;
110 } 111 }
111 } else 112 free(content_s);
112 if (vtype == EINA_VALUE_TYPE_BLOB) 113 }
114 else if (vtype == EINA_VALUE_TYPE_BLOB)
113 { 115 {
114 Eina_Value_Blob out; 116 Eina_Value_Blob out;
115 eina_value_get(&value, &out); 117 eina_value_get(value, &out);
116 if (out.memory != NULL) 118 if (out.memory != NULL)
117 { 119 {
118 content = elm_image_add(obj); 120 content = elm_image_add(obj);
119 121
122 //XXX: need copy memory??
120 elm_image_memfile_set(content, out.memory, out.size, NULL, NULL); 123 elm_image_memfile_set(content, out.memory, out.size, NULL, NULL);
121 } 124 }
122 } 125 }
123 eina_value_flush(&value);
124 126
125 return content; 127 return content;
126} 128}
@@ -128,7 +130,7 @@ _item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
128static char * 130static char *
129_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 131_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
130{ 132{
131 Eina_Value value; 133 const Eina_Value *value = NULL;
132 char *text = NULL; 134 char *text = NULL;
133 View_List_ItemData *idata = data; 135 View_List_ItemData *idata = data;
134 136
@@ -140,10 +142,9 @@ _item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
140 const char *prop = eina_hash_find(priv->prop_con, part); 142 const char *prop = eina_hash_find(priv->prop_con, part);
141 if (prop == NULL) prop = part; 143 if (prop == NULL) prop = part;
142 144
143 eina_value_setup(&value, EINA_VALUE_TYPE_STRING);
144 eo_do(idata->model, emodel_property_get(prop, &value)); 145 eo_do(idata->model, emodel_property_get(prop, &value));
145 text = eina_value_to_string(&value); 146 if (value)
146 eina_value_flush(&value); 147 text = eina_value_to_string(value);
147 148
148 return text; 149 return text;
149} 150}