diff --git a/src/lib/efl/Efl_Model_Common.h b/src/lib/efl/Efl_Model_Common.h index 5c565c64ab..b4b5690917 100644 --- a/src/lib/efl/Efl_Model_Common.h +++ b/src/lib/efl/Efl_Model_Common.h @@ -20,15 +20,11 @@ EAPI extern Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT; /**< @since 1.19 */ */ struct _Efl_Model_Children_Event { - Eo *child; /**< child, for child_add */ /** * index is a hint and is intended * to provide a way for applications * to control/know children relative * positions through listings. - * - * NOTE: If listing is performed asynchronously - * exact order may not be guaranteed. */ unsigned int index; }; @@ -42,20 +38,6 @@ typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event; EAPI int efl_model_init(void); -/** - * @brief Slices a list - * - * If the @p start and @p count are 0, a new accessor of the entire list is returned - * - * @param list The list to get the slice - * @param start The nth element to start the slice - * @param count The number of elements - * @return The accessor to the sliced elements or @c NULL if error - * - * @since 1.17 - */ -EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) EINA_ARG_NONNULL(1); - /** * @brief Notifies a property changed event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED @@ -65,7 +47,9 @@ EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsign * * @since 1.17 */ -EAPI void efl_model_property_changed_notify(Efl_Model *model, const char *property); +EAPI void _efl_model_properties_changed_internal(const Efl_Model *model, ...); + +#define efl_model_properties_changed(Model, ...) _efl_model_properties_changed_internal(Model, ##__VA_ARGS__, NULL) /** * @brief Notifies a property invalidated event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED @@ -107,4 +91,34 @@ EAPI Eina_Value_Struct_Desc *efl_model_value_struct_description_new(unsigned int */ EAPI void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc); + +static inline Eina_Value +efl_model_list_value_get(Eina_List *childrens, + unsigned int start, + unsigned int count) +{ + Eina_Value v = EINA_VALUE_EMPTY; + Eina_List *l; + Eo *child; + + eina_value_array_setup(&v, EINA_VALUE_TYPE_OBJECT, eina_list_count(childrens)); + + EINA_LIST_FOREACH(childrens, l, child) + { + if (start != 0) + { + start--; + continue; + } + if (count == 0) + continue; + count--; + + eina_value_array_append(&v, child); + } + + return v; +} + + #endif diff --git a/src/lib/efl/interfaces/efl_model.eo b/src/lib/efl/interfaces/efl_model.eo index 06477f9fdf..2fae595baa 100644 --- a/src/lib/efl/interfaces/efl_model.eo +++ b/src/lib/efl/interfaces/efl_model.eo @@ -22,50 +22,50 @@ interface Efl.Model () @since 1.14 ]] - } - values { - properties: const(array); [[Array of current properties]] + } + values { + properties: array; [[Array of current properties]] } } - property_set { - [[Set a property value of a given property name. + @property property { + set { + [[Set a property value of a given property name. - The caller must ensure to call at least efl_model_prop_list - before being able to see/set properties. This function sets - a new property value into given property name. Once the - operation is completed the concrete implementation should - raise EFL_MODEL_EVENT_PROPERTIES_CHANGED event in order to - notify listeners of the new value of the property. + The caller must ensure to call at least efl_model_prop_list + before being able to see/set properties. This function sets + a new property value into given property name. Once the + operation is completed the concrete implementation should + raise EFL_MODEL_EVENT_PROPERTIES_CHANGED event in order to + notify listeners of the new value of the property. - If the model doesn't have the property then there are two - possibilities, either raise an error or create the new - property in model + If the model doesn't have the property then there are two + possibilities, either raise an error or create the new + property in model - See @.property_get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED + See @.property.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED - @since 1.14 - ]] - params { - @in property: string; [[Property name]] - @in value: const(any_value_ptr); [[New value]] + @since 1.14 + ]] + return: ptr(Eina.Future); [[Return an error in case the property could not be set, the value that was set otherwise.]] } - return: future; [[Future returning the recorded value or error]] - } - property_get { - [[Retrieve the value of a given property name. + get { + [[Retrieve the value of a given property name. - At this point the caller is free to get values from properties. - The event EFL_MODEL_EVENT_PROPERTIES_CHANGED may be raised to - notify listeners of the property/value. + At this point the caller is free to get values from properties. + The event EFL_MODEL_EVENT_PROPERTIES_CHANGED may be raised to + notify listeners of the property/value. - See @.properties.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED + See @.properties.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED - @since 1.14 - ]] - params { - @in property: string; [[Property name]] + @since 1.14 + ]] + } + keys { + property: string; [[Property name]] + } + values { + value: any_value_ptr; [[Property value]] } - return: future; [[Future of the value that was got]] } children_slice_get { [[Get children slice OR full range. @@ -89,7 +89,7 @@ interface Efl.Model () Optionally the user can call children_count_get to know the number of children so a valid range can be known in advance. - See @.children_count_get + See @.children_count.get @since 1.14 ]] @@ -98,10 +98,11 @@ interface Efl.Model () @in count: uint; [[Range size. If count is 0, start is ignored.]] } - return: future >; [[Future of the children]] + return: ptr(Eina.Future); [[Array of childrens]] } - children_count_get { - [[Get children count. + @property children_count { + get { + [[Get children count. When efl_model_load is completed efl_model_coildren_count_get can be used to get the number of children. children_count_get @@ -112,8 +113,11 @@ interface Efl.Model () See also @.children_slice_get. @since 1.14 - ]] - return: future; [[Future of the children count]] + ]] + } + values { + count: uint; [[Current known children count]] + } } child_add { [[Add a new child. @@ -147,8 +151,8 @@ interface Efl.Model () properties,changed: Efl.Model_Property_Event; [[Event dispatched when properties list is available.]] - child,added: Efl.Object; [[Event dispatched when new child is added.]] - child,removed: Efl.Object; [[Event dispatched when child is removed.]] + child,added; [[Event dispatched when new child is added.]] + child,removed; [[Event dispatched when child is removed.]] children,count,changed; [[Event dispatched when children count is finished.]] } } diff --git a/src/lib/efl/interfaces/efl_model_common.c b/src/lib/efl/interfaces/efl_model_common.c index 6bf825819f..dabc388338 100644 --- a/src/lib/efl/interfaces/efl_model_common.c +++ b/src/lib/efl/interfaces/efl_model_common.c @@ -54,56 +54,28 @@ efl_model_init(void) return EINA_TRUE; } -EAPI Eina_Accessor* -efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) -{ - if (!list) return NULL; - - if ((start == 0) && (count == 0)) /* this is full data */ - { - /* - * children_accessor will be set to NULL by - * eina_list_accessor_new if the later fails. - */ - return eina_list_accessor_new(list); - } - - Eo *child; - Eina_List *l, *ln, *lr = NULL; - ln = eina_list_nth_list(list, (start)); - if (!ln) - { - return NULL; - } - - EINA_LIST_FOREACH(ln, l, child) - { - efl_ref(child); - lr = eina_list_append(lr, child); - if (eina_list_count(lr) == count) - break; - } - - if (!lr) return NULL; - - // This may leak the children Eina_List. - return eina_list_accessor_new(lr); -} - EAPI void -efl_model_property_changed_notify(Efl_Model *model, const char *property) +_efl_model_properties_changed_internal(const Efl_Model *model, ...) { - Eina_Array *changed_properties = eina_array_new(1); - EINA_SAFETY_ON_NULL_RETURN(changed_properties); + Efl_Model_Property_Event ev = { 0 }; + Eina_Array *properties = eina_array_new(1); + const char *property; + va_list args; - Eina_Bool ret = eina_array_push(changed_properties, property); - EINA_SAFETY_ON_FALSE_GOTO(ret, on_error); + va_start(args, model); - Efl_Model_Property_Event evt = {.changed_properties = changed_properties}; - efl_event_callback_call(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &evt); + while ((property = (const char*) va_arg(args, const char*))) + { + eina_array_push(properties, property); + } -on_error: - eina_array_free(changed_properties); + va_end(args); + + ev.changed_properties = properties; + + efl_event_callback_call((Efl_Model *) model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &ev); + + eina_array_free(properties); } EAPI void