summaryrefslogtreecommitdiff
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
parent132f8f1f375ae8bf376c5b46f04fc67e7986c7d2 (diff)
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[] = {
39static Eina_Bool _key_action_activate(Evas_Object *obj, const char *params); 39static Eina_Bool _key_action_activate(Evas_Object *obj, const char *params);
40static 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); 40static 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);
41static void _efl_ui_image_sizing_eval(Eo *obj); 41static void _efl_ui_image_sizing_eval(Eo *obj);
42static void _efl_ui_image_model_properties_changed_cb(void *data, const Eo_Event *event);
42 43
43static const Elm_Action key_actions[] = { 44static const Elm_Action key_actions[] = {
44 {"activate", _key_action_activate}, 45 {"activate", _key_action_activate},
@@ -632,6 +633,14 @@ _efl_ui_image_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Image_Data *sd)
632 sd->async.th = NULL; 633 sd->async.th = NULL;
633 } 634 }
634 635
636 if (sd->model)
637 {
638 eo_event_callback_del(sd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
639 _efl_ui_image_model_properties_changed_cb, obj);
640 eo_unref(sd->model);
641 sd->model = NULL;
642 }
643
635 _async_open_data_free(sd->async.done); 644 _async_open_data_free(sd->async.done);
636 _async_open_data_free(sd->async.todo); 645 _async_open_data_free(sd->async.todo);
637 eina_stringshare_del(sd->async.file); 646 eina_stringshare_del(sd->async.file);
@@ -1693,6 +1702,107 @@ _efl_ui_image_icon_get(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1693 return sd->stdicon; 1702 return sd->stdicon;
1694} 1703}
1695 1704
1705static void
1706_prop_promise_error_cb(void* data EINA_UNUSED, Eina_Error err EINA_UNUSED)
1707{
1708
1709}
1710
1711static void
1712_prop_promise_then_cb(void* data, void* v)
1713{
1714 Eo *obj = data;
1715 Eina_Value *value = v;
1716 char *text;
1717
1718 const Eina_Value_Type *vtype = eina_value_type_get(value);
1719
1720 if (vtype == EINA_VALUE_TYPE_STRING || vtype == EINA_VALUE_TYPE_STRINGSHARE)
1721 {
1722 eina_value_get(value, &text);
1723 elm_image_file_set(obj, text, NULL);
1724 }
1725 else
1726 {
1727 text = eina_value_to_string(value);
1728 elm_image_file_set(obj, text, NULL);
1729 free(text);
1730 }
1731}
1732
1733static void
1734_efl_ui_image_model_properties_changed_cb(void *data, const Eo_Event *event)
1735{
1736 Efl_Model_Property_Event *evt = event->info;
1737 Eina_Array_Iterator it;
1738 const char *prop;
1739 unsigned int i;
1740
1741 EFL_UI_IMAGE_DATA_GET(data, pd);
1742
1743 if (!evt->changed_properties)
1744 return;
1745
1746 if (pd->model && pd->prop_con)
1747 {
1748 EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
1749 {
1750 if (!strcmp(pd->prop_con, prop))
1751 {
1752 Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
1753 eina_promise_then(promise, &_prop_promise_then_cb, &_prop_promise_error_cb, data);
1754 return;
1755 }
1756 }
1757 }
1758}
1759
1760EOLIAN static void
1761_efl_ui_image_efl_ui_view_model_set(Eo *obj, Efl_Ui_Image_Data *pd, Efl_Model *model)
1762{
1763 if (pd->model)
1764 {
1765 eo_event_callback_del(pd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
1766 _efl_ui_image_model_properties_changed_cb, obj);
1767 eo_unref(pd->model);
1768 pd->model = NULL;
1769 }
1770
1771 if (model)
1772 {
1773 pd->model = model;
1774 eo_ref(pd->model);
1775 eo_event_callback_add(pd->model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
1776 _efl_ui_image_model_properties_changed_cb, obj);
1777 }
1778
1779 if (pd->prop_con && pd->model)
1780 {
1781 Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
1782 eina_promise_then(promise, &_prop_promise_then_cb,
1783 &_prop_promise_error_cb, obj);
1784 }
1785}
1786
1787EOLIAN static Efl_Model *
1788_efl_ui_image_efl_ui_view_model_get(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1789{
1790 return pd->model;
1791}
1792
1793EOLIAN static void
1794_efl_ui_image_efl_ui_model_connect_connect(Eo *obj, Efl_Ui_Image_Data *pd, const char *name EINA_UNUSED, const char *property)
1795{
1796 eina_stringshare_replace(&pd->prop_con, property);
1797
1798 if (pd->model && pd->prop_con)
1799 {
1800 Eina_Promise *promise = efl_model_property_get(pd->model, pd->prop_con);
1801 eina_promise_then(promise, &_prop_promise_then_cb,
1802 &_prop_promise_error_cb, obj);
1803 }
1804}
1805
1696EAPI void 1806EAPI void
1697elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth) 1807elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
1698{ 1808{
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
45class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable, 45class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
46 Efl.File, Efl.Image, Efl.Image.Load, Efl.Player, Efl.Gfx.View, 46 Efl.File, Efl.Image, Efl.Image.Load, Efl.Player, Efl.Gfx.View,
47 Elm.Interface.Atspi_Image, Elm.Interface.Atspi_Widget_Action, 47 Elm.Interface.Atspi_Image, Elm.Interface.Atspi_Widget_Action,
48 Edje.Object, Efl.Orientation, Efl.Flipable) 48 Edje.Object, Efl.Orientation, Efl.Flipable,
49 Efl.Ui.View, Efl.Ui.Model.Connect)
49{ 50{
50 event_prefix: efl_ui_image; 51 event_prefix: efl_ui_image;
51 methods { 52 methods {
@@ -165,6 +166,9 @@ class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
165 Efl.Canvas.Group.group_resize; 166 Efl.Canvas.Group.group_resize;
166 Efl.Ui.Draggable.drag_target.set; 167 Efl.Ui.Draggable.drag_target.set;
167 Efl.Ui.Draggable.drag_target.get; 168 Efl.Ui.Draggable.drag_target.get;
169 Efl.Ui.Model.Connect.connect;
170 Efl.Ui.View.model.set;
171 Efl.Ui.View.model.get;
168 Elm.Widget.theme_apply; 172 Elm.Widget.theme_apply;
169 Elm.Widget.event; 173 Elm.Widget.event;
170 Elm.Interface.Atspi_Image.extents.get; 174 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
78 78
79 const char *stdicon; 79 const char *stdicon;
80 80
81 Efl_Model *model;
82 Eina_Stringshare *prop_con;
81 83
82 struct { 84 struct {
83 int requested_size; 85 int requested_size;