aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2016-07-01 21:13:09 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2016-07-05 14:13:03 -0300
commit7cff7432ccefe75aadf42de515460a0e28252025 (patch)
treeac35023024a33b649e78939eaea7b8c45b24cae3
parentelementary: add example layout_model_connect (diff)
downloadefl-7cff7432ccefe75aadf42de515460a0e28252025.tar.gz
elementary: add model connect in efl_ui_image
-rw-r--r--src/lib/elementary/efl_ui_image.c110
-rw-r--r--src/lib/elementary/efl_ui_image.eo6
-rw-r--r--src/lib/elementary/efl_ui_widget_image.h2
3 files changed, 117 insertions, 1 deletions
diff --git a/src/lib/elementary/efl_ui_image.c b/src/lib/elementary/efl_ui_image.c
index 252b5740fc..789ee29f3b 100644
--- a/src/lib/elementary/efl_ui_image.c
+++ b/src/lib/elementary/efl_ui_image.c
@@ -39,6 +39,7 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
static Eina_Bool _key_action_activate(Evas_Object *obj, const char *params);
static Eina_Bool _efl_ui_image_smart_internal_file_set(Eo *obj, Efl_Ui_Image_Data *sd, const char *file, const Eina_File *f, const char *key);
static void _efl_ui_image_sizing_eval(Eo *obj);
+static void _efl_ui_image_model_properties_changed_cb(void *data, const Eo_Event *event);
static const Elm_Action key_actions[] = {
{"activate", _key_action_activate},
@@ -632,6 +633,14 @@ _efl_ui_image_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Image_Data *sd)
sd->async.th = NULL;
}
+ if (sd->model)
+ {
+ eo_event_callback_del(sd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
+ _efl_ui_image_model_properties_changed_cb, obj);
+ eo_unref(sd->model);
+ sd->model = NULL;
+ }
+
_async_open_data_free(sd->async.done);
_async_open_data_free(sd->async.todo);
eina_stringshare_del(sd->async.file);
@@ -1693,6 +1702,107 @@ _efl_ui_image_icon_get(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
return sd->stdicon;
}
+static void
+_prop_promise_error_cb(void* data EINA_UNUSED, Eina_Error err EINA_UNUSED)
+{
+
+}
+
+static void
+_prop_promise_then_cb(void* data, void* v)
+{
+ Eo *obj = data;
+ Eina_Value *value = v;
+ char *text;
+
+ const Eina_Value_Type *vtype = eina_value_type_get(value);
+
+ if (vtype == EINA_VALUE_TYPE_STRING || vtype == EINA_VALUE_TYPE_STRINGSHARE)
+ {
+ eina_value_get(value, &text);
+ elm_image_file_set(obj, text, NULL);
+ }
+ else
+ {
+ text = eina_value_to_string(value);
+ elm_image_file_set(obj, text, NULL);
+ free(text);
+ }
+}
+
+static void
+_efl_ui_image_model_properties_changed_cb(void *data, const Eo_Event *event)
+{
+ Efl_Model_Property_Event *evt = event->info;
+ Eina_Array_Iterator it;
+ const char *prop;
+ unsigned int i;
+
+ EFL_UI_IMAGE_DATA_GET(data, pd);
+
+ if (!evt->changed_properties)
+ return;
+
+ if (pd->model && pd->prop_con)
+ {
+ EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
+ {
+ if (!strcmp(pd->prop_con, prop))
+ {
+ Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
+ eina_promise_then(promise, &_prop_promise_then_cb, &_prop_promise_error_cb, data);
+ return;
+ }
+ }
+ }
+}
+
+EOLIAN static void
+_efl_ui_image_efl_ui_view_model_set(Eo *obj, Efl_Ui_Image_Data *pd, Efl_Model *model)
+{
+ if (pd->model)
+ {
+ eo_event_callback_del(pd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
+ _efl_ui_image_model_properties_changed_cb, obj);
+ eo_unref(pd->model);
+ pd->model = NULL;
+ }
+
+ if (model)
+ {
+ pd->model = model;
+ eo_ref(pd->model);
+ eo_event_callback_add(pd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
+ _efl_ui_image_model_properties_changed_cb, obj);
+ }
+
+ if (pd->prop_con && pd->model)
+ {
+ Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
+ eina_promise_then(promise, &_prop_promise_then_cb,
+ &_prop_promise_error_cb, obj);
+ }
+}
+
+EOLIAN static Efl_Model *
+_efl_ui_image_efl_ui_view_model_get(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
+{
+ return pd->model;
+}
+
+EOLIAN static void
+_efl_ui_image_efl_ui_model_connect_connect(Eo *obj, Efl_Ui_Image_Data *pd, const char *name EINA_UNUSED, const char *property)
+{
+ eina_stringshare_replace(&pd->prop_con, property);
+
+ if (pd->model && pd->prop_con)
+ {
+ Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
+ eina_promise_then(promise, &_prop_promise_then_cb,
+ &_prop_promise_error_cb, obj);
+ }
+}
+
EAPI void
elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
{
diff --git a/src/lib/elementary/efl_ui_image.eo b/src/lib/elementary/efl_ui_image.eo
index 9cb7229675..f3919c1d1d 100644
--- a/src/lib/elementary/efl_ui_image.eo
+++ b/src/lib/elementary/efl_ui_image.eo
@@ -45,7 +45,8 @@ struct Efl.Ui.Image.Error
class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
Efl.File, Efl.Image, Efl.Image.Load, Efl.Player, Efl.Gfx.View,
Elm.Interface.Atspi_Image, Elm.Interface.Atspi_Widget_Action,
- Edje.Object, Efl.Orientation, Efl.Flipable)
+ Edje.Object, Efl.Orientation, Efl.Flipable,
+ Efl.Ui.View, Efl.Ui.Model.Connect)
{
event_prefix: efl_ui_image;
methods {
@@ -165,6 +166,9 @@ class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
Efl.Canvas.Group.group_resize;
Efl.Ui.Draggable.drag_target.set;
Efl.Ui.Draggable.drag_target.get;
+ Efl.Ui.Model.Connect.connect;
+ Efl.Ui.View.model.set;
+ Efl.Ui.View.model.get;
Elm.Widget.theme_apply;
Elm.Widget.event;
Elm.Interface.Atspi_Image.extents.get;
diff --git a/src/lib/elementary/efl_ui_widget_image.h b/src/lib/elementary/efl_ui_widget_image.h
index 64f7b9715c..778412ee85 100644
--- a/src/lib/elementary/efl_ui_widget_image.h
+++ b/src/lib/elementary/efl_ui_widget_image.h
@@ -78,6 +78,8 @@ struct _Efl_Ui_Image_Data
const char *stdicon;
+ Efl_Model *model;
+ Eina_Stringshare *prop_con;
struct {
int requested_size;