forked from enlightenment/efl
ecore: remove Efl.Container_Model_Item.
This also enable to create a tree of Container_Model instead of just one level. Reviewed-by: Vitor Sousa da Silva <vitorsousa@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D8046
This commit is contained in:
parent
c3ed0791a6
commit
3971106c1a
|
@ -45,7 +45,6 @@ ecore_eolian_files_public = \
|
||||||
lib/ecore/efl_loop_model.eo \
|
lib/ecore/efl_loop_model.eo \
|
||||||
lib/ecore/efl_generic_model.eo \
|
lib/ecore/efl_generic_model.eo \
|
||||||
lib/ecore/efl_container_model.eo \
|
lib/ecore/efl_container_model.eo \
|
||||||
lib/ecore/efl_container_model_item.eo \
|
|
||||||
lib/ecore/efl_boolean_model.eo \
|
lib/ecore/efl_boolean_model.eo \
|
||||||
lib/ecore/efl_select_model.eo \
|
lib/ecore/efl_select_model.eo \
|
||||||
lib/ecore/efl_composite_model.eo \
|
lib/ecore/efl_composite_model.eo \
|
||||||
|
@ -135,8 +134,6 @@ lib/ecore/efl_io_buffered_stream.c \
|
||||||
lib/ecore/efl_loop_model.c \
|
lib/ecore/efl_loop_model.c \
|
||||||
lib/ecore/efl_generic_model.c \
|
lib/ecore/efl_generic_model.c \
|
||||||
lib/ecore/efl_container_model.c \
|
lib/ecore/efl_container_model.c \
|
||||||
lib/ecore/efl_container_model_item.c \
|
|
||||||
lib/ecore/efl_container_model_private.h \
|
|
||||||
lib/ecore/efl_composite_model.c \
|
lib/ecore/efl_composite_model.c \
|
||||||
lib/ecore/efl_boolean_model.c \
|
lib/ecore/efl_boolean_model.c \
|
||||||
lib/ecore/efl_select_model.c \
|
lib/ecore/efl_select_model.c \
|
||||||
|
|
|
@ -116,7 +116,6 @@ EAPI Eo *efl_main_loop_get(void);
|
||||||
#include "efl_loop_model.eo.h"
|
#include "efl_loop_model.eo.h"
|
||||||
#include "efl_generic_model.eo.h"
|
#include "efl_generic_model.eo.h"
|
||||||
#include "efl_container_model.eo.h"
|
#include "efl_container_model.eo.h"
|
||||||
#include "efl_container_model_item.eo.h"
|
|
||||||
#include "efl_composite_model.eo.h"
|
#include "efl_composite_model.eo.h"
|
||||||
#include "efl_boolean_model.eo.h"
|
#include "efl_boolean_model.eo.h"
|
||||||
#include "efl_select_model.eo.h"
|
#include "efl_select_model.eo.h"
|
||||||
|
|
|
@ -8,59 +8,44 @@
|
||||||
#include <Ecore.h>
|
#include <Ecore.h>
|
||||||
|
|
||||||
#include "ecore_internal.h"
|
#include "ecore_internal.h"
|
||||||
|
#include "efl_composite_model_private.h"
|
||||||
|
|
||||||
#include "efl_container_model_private.h"
|
typedef struct _Efl_Container_Property_Data Efl_Container_Property_Data;
|
||||||
|
typedef struct _Efl_Container_Model_Data Efl_Container_Model_Data;
|
||||||
|
|
||||||
#define MY_CLASS EFL_CONTAINER_MODEL_CLASS
|
struct _Efl_Container_Property_Data
|
||||||
|
|
||||||
void *
|
|
||||||
_value_copy_alloc(void *v, const Eina_Value_Type *type)
|
|
||||||
{
|
{
|
||||||
if (!v)
|
Eina_Stringshare *name;
|
||||||
return v;
|
|
||||||
|
|
||||||
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
const Eina_Value_Type *type;
|
||||||
return (void*) eina_stringshare_ref(v);
|
Eina_Array *values;
|
||||||
else if (type == EINA_VALUE_TYPE_STRING)
|
};
|
||||||
return (void*) strdup(v);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
void *ret = malloc(type->value_size);
|
|
||||||
memcpy(ret, v, type->value_size);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
struct _Efl_Container_Model_Data
|
||||||
_value_free(void *v, const Eina_Value_Type *type)
|
|
||||||
{
|
{
|
||||||
if (!v)
|
Efl_Container_Model_Data *parent;
|
||||||
return;
|
|
||||||
|
|
||||||
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
Eina_Hash *properties; // All properties value for children
|
||||||
return eina_stringshare_del(v);
|
unsigned int children_count;
|
||||||
else
|
};
|
||||||
free(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_values_free(Eina_Array *values, const Eina_Value_Type *type)
|
_property_values_free(Eina_Array *values)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
Eina_Value *v;
|
||||||
void *v;
|
|
||||||
Eina_Array_Iterator it;
|
while ((v = eina_array_pop(values)))
|
||||||
EINA_ARRAY_ITER_NEXT(values, i, v, it)
|
eina_value_free(v);
|
||||||
{
|
|
||||||
_value_free(v, type);
|
|
||||||
}
|
|
||||||
eina_array_free(values);
|
eina_array_free(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_property_data_free_cb(void *data)
|
_property_data_free_cb(void *data)
|
||||||
{
|
{
|
||||||
Child_Property_Data *cpd = data;
|
Efl_Container_Property_Data *cpd = data;
|
||||||
_values_free(cpd->values, cpd->type);
|
|
||||||
|
eina_stringshare_del(cpd->name);
|
||||||
|
_property_values_free(cpd->values);
|
||||||
free(cpd);
|
free(cpd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,33 +53,38 @@ static Efl_Object *
|
||||||
_efl_container_model_efl_object_constructor(Eo *obj,
|
_efl_container_model_efl_object_constructor(Eo *obj,
|
||||||
Efl_Container_Model_Data *sd)
|
Efl_Container_Model_Data *sd)
|
||||||
{
|
{
|
||||||
obj = efl_constructor(efl_super(obj, MY_CLASS));
|
Eo *parent;
|
||||||
if (!obj)
|
|
||||||
return NULL;
|
obj = efl_constructor(efl_super(obj, EFL_CONTAINER_MODEL_CLASS));
|
||||||
|
if (!obj) return NULL;
|
||||||
|
|
||||||
|
parent = efl_parent_get(obj);
|
||||||
|
if (efl_isa(parent, EFL_CONTAINER_MODEL_CLASS))
|
||||||
|
sd->parent = efl_data_scope_get(parent, EFL_CONTAINER_MODEL_CLASS);
|
||||||
|
|
||||||
sd->obj = obj;
|
|
||||||
sd->properties = eina_hash_stringshared_new(_property_data_free_cb);
|
sd->properties = eina_hash_stringshared_new(_property_data_free_cb);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Efl_Object *
|
||||||
|
_efl_container_model_efl_object_finalize(Eo *obj, Efl_Container_Model_Data *sd EINA_UNUSED)
|
||||||
|
{
|
||||||
|
if (!efl_ui_view_model_get(obj))
|
||||||
|
{
|
||||||
|
// Add a dummy object as source if there isn't any to allow using this class without source.
|
||||||
|
efl_ui_view_model_set(obj, efl_add(EFL_GENERIC_MODEL_CLASS, obj));
|
||||||
|
}
|
||||||
|
return efl_finalize(efl_super(obj, EFL_CONTAINER_MODEL_CLASS));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_efl_container_model_efl_object_destructor(Eo *obj,
|
_efl_container_model_efl_object_destructor(Eo *obj,
|
||||||
Efl_Container_Model_Data *sd)
|
Efl_Container_Model_Data *sd)
|
||||||
{
|
{
|
||||||
Eina_Stringshare *key;
|
|
||||||
Eina_Iterator *it;
|
|
||||||
|
|
||||||
eina_list_free(sd->childrens);
|
|
||||||
|
|
||||||
it = eina_hash_iterator_key_new(sd->properties);
|
|
||||||
EINA_ITERATOR_FOREACH(it, key)
|
|
||||||
eina_stringshare_del(key);
|
|
||||||
eina_iterator_free(it);
|
|
||||||
|
|
||||||
eina_hash_free(sd->properties);
|
eina_hash_free(sd->properties);
|
||||||
|
|
||||||
efl_destructor(efl_super(obj, MY_CLASS));
|
efl_destructor(efl_super(obj, EFL_CONTAINER_MODEL_CLASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Eina_Value_Type *
|
static const Eina_Value_Type *
|
||||||
|
@ -102,7 +92,7 @@ _efl_container_model_child_property_value_type_get(Eo *obj EINA_UNUSED,
|
||||||
Efl_Container_Model_Data *sd,
|
Efl_Container_Model_Data *sd,
|
||||||
const char *property)
|
const char *property)
|
||||||
{
|
{
|
||||||
Child_Property_Data *cpd;
|
Efl_Container_Property_Data *cpd;
|
||||||
Eina_Stringshare *key;
|
Eina_Stringshare *key;
|
||||||
|
|
||||||
key = eina_stringshare_add(property);
|
key = eina_stringshare_add(property);
|
||||||
|
@ -113,22 +103,6 @@ _efl_container_model_child_property_value_type_get(Eo *obj EINA_UNUSED,
|
||||||
return cpd->type;
|
return cpd->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Iterator *
|
|
||||||
_efl_container_model_child_property_values_get(Eo *obj EINA_UNUSED,
|
|
||||||
Efl_Container_Model_Data *sd,
|
|
||||||
const char *property)
|
|
||||||
{
|
|
||||||
Child_Property_Data *cpd;
|
|
||||||
Eina_Stringshare *key;
|
|
||||||
|
|
||||||
key = eina_stringshare_add(property);
|
|
||||||
cpd = eina_hash_find(sd->properties, key);
|
|
||||||
eina_stringshare_del(key);
|
|
||||||
|
|
||||||
if (!cpd) return NULL;
|
|
||||||
return eina_array_iterator_new(cpd->values);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_efl_container_model_child_property_add(Eo *obj,
|
_efl_container_model_child_property_add(Eo *obj,
|
||||||
Efl_Container_Model_Data *sd,
|
Efl_Container_Model_Data *sd,
|
||||||
|
@ -137,9 +111,9 @@ _efl_container_model_child_property_add(Eo *obj,
|
||||||
Eina_Iterator *values)
|
Eina_Iterator *values)
|
||||||
{
|
{
|
||||||
Eina_Array *arr = NULL;
|
Eina_Array *arr = NULL;
|
||||||
void *data = NULL;
|
void *original;
|
||||||
Child_Property_Data *cpd = NULL;
|
Efl_Container_Property_Data *cpd = NULL;
|
||||||
unsigned int i, in_count, children_count;
|
unsigned int i;
|
||||||
Eina_Error err = EFL_MODEL_ERROR_INCORRECT_VALUE;
|
Eina_Error err = EFL_MODEL_ERROR_INCORRECT_VALUE;
|
||||||
|
|
||||||
name = eina_stringshare_add(name);
|
name = eina_stringshare_add(name);
|
||||||
|
@ -154,15 +128,24 @@ _efl_container_model_child_property_add(Eo *obj,
|
||||||
arr = eina_array_new(4);
|
arr = eina_array_new(4);
|
||||||
if (!arr) goto on_error;
|
if (!arr) goto on_error;
|
||||||
|
|
||||||
EINA_ITERATOR_FOREACH(values, data)
|
EINA_ITERATOR_FOREACH(values, original)
|
||||||
{
|
{
|
||||||
void *new_data = _value_copy_alloc(data, type);
|
Eina_Value *copy = eina_value_new(type);
|
||||||
if ((data && !new_data) || !eina_array_push(arr, new_data))
|
Eina_Bool r;
|
||||||
|
|
||||||
|
if (type == EINA_VALUE_TYPE_STRINGSHARE ||
|
||||||
|
type == EINA_VALUE_TYPE_STRING)
|
||||||
|
r = eina_value_set(copy, original);
|
||||||
|
else
|
||||||
|
r = eina_value_pset(copy, original);
|
||||||
|
|
||||||
|
if (!r)
|
||||||
{
|
{
|
||||||
if (new_data)
|
eina_value_free(copy);
|
||||||
_value_free(new_data, type);
|
copy = eina_value_error_new(EINA_ERROR_VALUE_FAILED);
|
||||||
goto on_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eina_array_push(arr, copy);
|
||||||
}
|
}
|
||||||
eina_iterator_free(values);
|
eina_iterator_free(values);
|
||||||
|
|
||||||
|
@ -171,10 +154,11 @@ _efl_container_model_child_property_add(Eo *obj,
|
||||||
cpd = eina_hash_find(sd->properties, name);
|
cpd = eina_hash_find(sd->properties, name);
|
||||||
if (!cpd)
|
if (!cpd)
|
||||||
{
|
{
|
||||||
cpd = calloc(1, sizeof(Child_Property_Data));
|
cpd = calloc(1, sizeof(Efl_Container_Property_Data));
|
||||||
if (!cpd)
|
if (!cpd)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
|
cpd->name = eina_stringshare_ref(name);
|
||||||
cpd->type = type;
|
cpd->type = type;
|
||||||
cpd->values = arr;
|
cpd->values = arr;
|
||||||
|
|
||||||
|
@ -183,100 +167,147 @@ _efl_container_model_child_property_add(Eo *obj,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
eina_stringshare_del(name);
|
_property_values_free(cpd->values);
|
||||||
_values_free(cpd->values, cpd->type);
|
|
||||||
|
|
||||||
cpd->type = type;
|
cpd->type = type;
|
||||||
cpd->values = arr;
|
cpd->values = arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_count = eina_array_count(arr);
|
for (i = sd->children_count; i < eina_array_count(arr); ++i)
|
||||||
children_count = eina_list_count(sd->childrens);
|
|
||||||
|
|
||||||
for (i = children_count; i < in_count; ++i)
|
|
||||||
{
|
{
|
||||||
Efl_Model_Children_Event cevt = { 0 };
|
Efl_Model_Children_Event cevt = { 0 };
|
||||||
Efl_Model *child;
|
|
||||||
|
|
||||||
child = efl_add(EFL_CONTAINER_MODEL_ITEM_CLASS, obj,
|
|
||||||
efl_container_model_item_define(efl_added, sd, i));
|
|
||||||
sd->childrens = eina_list_append(sd->childrens, child);
|
|
||||||
|
|
||||||
cevt.index = i;
|
cevt.index = i;
|
||||||
|
|
||||||
efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILD_ADDED, &cevt);
|
efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILD_ADDED, &cevt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_count > children_count)
|
if (eina_array_count(arr) > sd->children_count)
|
||||||
efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, NULL);
|
{
|
||||||
|
sd->children_count = eina_array_count(arr);
|
||||||
|
efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
eina_stringshare_del(name);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
eina_stringshare_del(name);
|
eina_stringshare_del(name);
|
||||||
|
|
||||||
if (cpd) free(cpd);
|
if (cpd) free(cpd);
|
||||||
if (arr)
|
if (arr) _property_values_free(arr);
|
||||||
_values_free(arr, type);
|
|
||||||
eina_error_set(err);
|
eina_error_set(err);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Iterator *
|
static Eina_Iterator *
|
||||||
_efl_container_model_efl_model_properties_get(const Eo *obj EINA_UNUSED, Efl_Container_Model_Data *sd)
|
_efl_container_model_efl_model_properties_get(const Eo *obj EINA_UNUSED,
|
||||||
|
Efl_Container_Model_Data *sd)
|
||||||
{
|
{
|
||||||
return eina_hash_iterator_key_new(sd->properties);
|
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props,
|
||||||
|
obj, EFL_CONTAINER_MODEL_CLASS,
|
||||||
|
eina_hash_iterator_key_new(sd->parent->properties));
|
||||||
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Future *
|
static Eina_Future *
|
||||||
_efl_container_model_efl_model_property_set(Eo *obj,
|
_efl_container_model_efl_model_property_set(Eo *obj,
|
||||||
Efl_Container_Model_Data *pd EINA_UNUSED,
|
Efl_Container_Model_Data *pd,
|
||||||
const char *property EINA_UNUSED,
|
const char *property,
|
||||||
Eina_Value *value EINA_UNUSED)
|
Eina_Value *value)
|
||||||
{
|
{
|
||||||
return efl_loop_future_rejected(obj,
|
if (pd->parent)
|
||||||
EFL_MODEL_ERROR_NOT_FOUND);
|
{
|
||||||
|
Efl_Container_Property_Data *cpd;
|
||||||
|
Eina_Stringshare *name;
|
||||||
|
unsigned int index;
|
||||||
|
Eina_Value r = EINA_VALUE_EMPTY;
|
||||||
|
|
||||||
|
name = eina_stringshare_add(property);
|
||||||
|
cpd = eina_hash_find(pd->parent->properties, name);
|
||||||
|
eina_stringshare_del(name);
|
||||||
|
|
||||||
|
// Check if this is a property of this object
|
||||||
|
if (!cpd) goto not_mine;
|
||||||
|
// Check if we can get the expected type for this property
|
||||||
|
if (!cpd->values)
|
||||||
|
return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
|
||||||
|
|
||||||
|
index = efl_composite_model_index_get(obj);
|
||||||
|
|
||||||
|
// Try converting the type before touching any data inside the Model
|
||||||
|
if (eina_value_type_get(value) != cpd->type)
|
||||||
|
{
|
||||||
|
eina_value_setup(&r, cpd->type);
|
||||||
|
|
||||||
|
if (!eina_value_convert(value, &r))
|
||||||
|
return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eina_value_copy(&r, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand the array to have enough space for this value if it wasn't already the case
|
||||||
|
while (index >= eina_array_count(cpd->values))
|
||||||
|
eina_array_push(cpd->values, eina_value_error_new(EFL_MODEL_ERROR_INCORRECT_VALUE));
|
||||||
|
|
||||||
|
// Clean the previous value and introduce the new one
|
||||||
|
eina_value_free(eina_array_data_get(cpd->values, index));
|
||||||
|
// Same type as the expected type, we can just replace the value
|
||||||
|
eina_array_data_set(cpd->values, index, eina_value_dup(&r));
|
||||||
|
|
||||||
|
eina_value_free(value);
|
||||||
|
return efl_loop_future_resolved(obj, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
not_mine:
|
||||||
|
return efl_model_property_set(efl_super(obj, EFL_CONTAINER_MODEL_CLASS), property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Value *
|
static Eina_Value *
|
||||||
_efl_container_model_efl_model_property_get(const Eo *obj EINA_UNUSED,
|
_efl_container_model_efl_model_property_get(const Eo *obj,
|
||||||
Efl_Container_Model_Data *pd EINA_UNUSED,
|
Efl_Container_Model_Data *pd,
|
||||||
const char *property EINA_UNUSED)
|
const char *property)
|
||||||
{
|
{
|
||||||
return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
|
if (pd->parent)
|
||||||
}
|
{
|
||||||
|
Efl_Container_Property_Data *cpd;
|
||||||
|
Eina_Stringshare *name;
|
||||||
|
Eina_Value *copy;
|
||||||
|
unsigned int index;
|
||||||
|
|
||||||
static Eina_Future *
|
name = eina_stringshare_add(property);
|
||||||
_efl_container_model_efl_model_children_slice_get(Eo *obj,
|
cpd = eina_hash_find(pd->parent->properties, name);
|
||||||
Efl_Container_Model_Data *sd,
|
eina_stringshare_del(name);
|
||||||
unsigned int start,
|
|
||||||
unsigned int count)
|
|
||||||
{
|
|
||||||
Eina_Value v;
|
|
||||||
|
|
||||||
v = efl_model_list_value_get(sd->childrens, start, count);
|
// Check if this is a property of this object
|
||||||
return efl_loop_future_resolved(obj, v);
|
if (!cpd) goto not_mine;
|
||||||
|
// Check if we can get the expected type for this property
|
||||||
|
if (!cpd->values) return eina_value_error_new(EFL_MODEL_ERROR_INCORRECT_VALUE);
|
||||||
|
|
||||||
|
index = efl_composite_model_index_get(obj);
|
||||||
|
|
||||||
|
if (index >= eina_array_count(cpd->values))
|
||||||
|
return eina_value_error_new(EFL_MODEL_ERROR_INCORRECT_VALUE);
|
||||||
|
|
||||||
|
copy = eina_value_dup(eina_array_data_get(cpd->values, index));
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
not_mine:
|
||||||
|
return efl_model_property_get(efl_super(obj, EFL_CONTAINER_MODEL_CLASS), property);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
_efl_container_model_efl_model_children_count_get(const Eo *obj EINA_UNUSED, Efl_Container_Model_Data *sd)
|
_efl_container_model_efl_model_children_count_get(const Eo *obj EINA_UNUSED, Efl_Container_Model_Data *sd)
|
||||||
{
|
{
|
||||||
return eina_list_count(sd->childrens);
|
unsigned int pcount;
|
||||||
}
|
|
||||||
|
|
||||||
static Eo *
|
pcount = efl_model_children_count_get(efl_super(obj, EFL_CONTAINER_MODEL_CLASS));
|
||||||
_efl_container_model_efl_model_child_add(Eo *obj EINA_UNUSED, Efl_Container_Model_Data *sd EINA_UNUSED)
|
|
||||||
{
|
|
||||||
EINA_LOG_WARN("child_add not supported by Efl.Model.Container");
|
|
||||||
eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
|
|
||||||
|
|
||||||
return NULL;
|
return pcount > sd->children_count ? pcount : sd->children_count;
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_efl_container_model_efl_model_child_del(Eo *obj EINA_UNUSED, Efl_Container_Model_Data *sd EINA_UNUSED, Eo *child EINA_UNUSED)
|
|
||||||
{
|
|
||||||
EINA_LOG_WARN("child_del not supported by Efl.Model.Container");
|
|
||||||
eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "efl_container_model.eo.c"
|
#include "efl_container_model.eo.c"
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import eina_types;
|
import eina_types;
|
||||||
|
|
||||||
class @beta Efl.Container_Model extends Efl.Loop_Model
|
class @beta Efl.Container_Model extends Efl.Composite_Model
|
||||||
{
|
{
|
||||||
[[
|
[[
|
||||||
Class used to create data models from Eina containers.
|
Class used to create data models from Eina containers.
|
||||||
|
|
||||||
Each container supplied represents a series of property values, each item
|
Each container supplied represents a series of property values, each item
|
||||||
being the property value for a child object (@Efl.Container_Model_Item).
|
being the property value for a child object.
|
||||||
|
|
||||||
The data in the given containers are copied and stored internally.
|
The data in the given containers are copied and stored internally.
|
||||||
|
|
||||||
|
@ -21,14 +21,6 @@ class @beta Efl.Container_Model extends Efl.Loop_Model
|
||||||
}
|
}
|
||||||
return: ptr(const(Eina.Value_Type)); [[Property type]]
|
return: ptr(const(Eina.Value_Type)); [[Property type]]
|
||||||
}
|
}
|
||||||
child_property_values_get {
|
|
||||||
[[Gets the values for the given property.]]
|
|
||||||
params {
|
|
||||||
name: string; [[Property name]]
|
|
||||||
}
|
|
||||||
return: iterator<void_ptr> @owned @warn_unused;
|
|
||||||
[[The currently wrapped values]]
|
|
||||||
}
|
|
||||||
child_property_add {
|
child_property_add {
|
||||||
[[Adds the given property to child objects and supply the values.
|
[[Adds the given property to child objects and supply the values.
|
||||||
|
|
||||||
|
@ -48,12 +40,10 @@ class @beta Efl.Container_Model extends Efl.Loop_Model
|
||||||
}
|
}
|
||||||
implements {
|
implements {
|
||||||
Efl.Object.constructor;
|
Efl.Object.constructor;
|
||||||
|
Efl.Object.finalize;
|
||||||
Efl.Object.destructor;
|
Efl.Object.destructor;
|
||||||
Efl.Model.properties { get; }
|
Efl.Model.properties { get; }
|
||||||
Efl.Model.property { set; get; }
|
Efl.Model.property { set; get; }
|
||||||
Efl.Model.child_add;
|
|
||||||
Efl.Model.child_del;
|
|
||||||
Efl.Model.children_slice_get;
|
|
||||||
Efl.Model.children_count { get; }
|
Efl.Model.children_count { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,164 +0,0 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <Efl.h>
|
|
||||||
#include <Ecore.h>
|
|
||||||
|
|
||||||
#include "efl_container_model_private.h"
|
|
||||||
|
|
||||||
#define MY_CLASS EFL_CONTAINER_MODEL_ITEM_CLASS
|
|
||||||
|
|
||||||
static void
|
|
||||||
_efl_container_model_item_define(Eo *obj EINA_UNUSED, Efl_Container_Model_Item_Data *sd, void *parent_data, unsigned int index)
|
|
||||||
{
|
|
||||||
sd->parent_data = parent_data;
|
|
||||||
sd->index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
EOLIAN static void
|
|
||||||
_efl_container_model_item_efl_object_invalidate(Eo *obj, Efl_Container_Model_Item_Data *sd)
|
|
||||||
{
|
|
||||||
efl_invalidate(efl_super(obj, MY_CLASS));
|
|
||||||
|
|
||||||
sd->parent_data = NULL;
|
|
||||||
sd->index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Iterator *
|
|
||||||
_efl_container_model_item_efl_model_properties_get(const Eo *obj EINA_UNUSED, Efl_Container_Model_Item_Data *sd)
|
|
||||||
{
|
|
||||||
// FIXME: Not to sure here, shouldn't we extend a child of the parent actually ?
|
|
||||||
return efl_model_properties_get(sd->parent_data->obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Efl_Object *
|
|
||||||
_efl_container_model_item_efl_object_finalize(Eo *obj, Efl_Container_Model_Item_Data *pd)
|
|
||||||
{
|
|
||||||
if (!pd->parent_data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Future *
|
|
||||||
_efl_container_model_item_efl_model_property_set(Eo *obj,
|
|
||||||
Efl_Container_Model_Item_Data *sd,
|
|
||||||
const char *property, Eina_Value *value)
|
|
||||||
{
|
|
||||||
Eina_Stringshare *name;
|
|
||||||
Child_Property_Data *cpd;
|
|
||||||
Eina_Value v = EINA_VALUE_EMPTY;
|
|
||||||
void *data, *new_data;
|
|
||||||
|
|
||||||
|
|
||||||
name = eina_stringshare_add(property);
|
|
||||||
cpd = eina_hash_find(sd->parent_data->properties, name);
|
|
||||||
eina_stringshare_del(name);
|
|
||||||
|
|
||||||
if (!cpd || !cpd->values ||
|
|
||||||
sd->index >= eina_array_count_get(cpd->values))
|
|
||||||
return efl_loop_future_rejected(obj,
|
|
||||||
EFL_MODEL_ERROR_NOT_FOUND);
|
|
||||||
|
|
||||||
eina_value_setup(&v,cpd->type);
|
|
||||||
if (!eina_value_convert(value, &v))
|
|
||||||
return efl_loop_future_rejected(obj,
|
|
||||||
EFL_MODEL_ERROR_INCORRECT_VALUE);
|
|
||||||
|
|
||||||
// FIXME: This is trying to optimize and avoid the use of Eina_Value,
|
|
||||||
// but this put restriction on the type that can be stored in this container.
|
|
||||||
data = calloc(1, cpd->type->value_size);
|
|
||||||
if (!data || !eina_value_pget(&v, data))
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
new_data = _value_copy_alloc(data, cpd->type);
|
|
||||||
|
|
||||||
_value_free(eina_array_data_get(cpd->values, sd->index), cpd->type);
|
|
||||||
|
|
||||||
eina_array_data_set(cpd->values, sd->index, new_data);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
return efl_loop_future_resolved(obj, v);
|
|
||||||
|
|
||||||
on_error:
|
|
||||||
eina_value_flush(&v);
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
return efl_loop_future_rejected(obj,
|
|
||||||
EFL_MODEL_ERROR_UNKNOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Value *
|
|
||||||
_efl_container_model_item_efl_model_property_get(const Eo *obj EINA_UNUSED,
|
|
||||||
Efl_Container_Model_Item_Data *sd,
|
|
||||||
const char *property)
|
|
||||||
{
|
|
||||||
Eina_Stringshare *name;
|
|
||||||
Child_Property_Data *cpd;
|
|
||||||
Eina_Value *value;
|
|
||||||
void *data;
|
|
||||||
Eina_Bool r = EINA_FALSE;
|
|
||||||
|
|
||||||
name = eina_stringshare_add(property);
|
|
||||||
cpd = eina_hash_find(sd->parent_data->properties, name);
|
|
||||||
eina_stringshare_del(name);
|
|
||||||
|
|
||||||
if (!cpd || !cpd->values ||
|
|
||||||
sd->index >= eina_array_count_get(cpd->values))
|
|
||||||
return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
|
|
||||||
|
|
||||||
data = eina_array_data_get(cpd->values, sd->index);
|
|
||||||
|
|
||||||
value = eina_value_new(cpd->type);
|
|
||||||
if (cpd->type == EINA_VALUE_TYPE_STRINGSHARE ||
|
|
||||||
cpd->type == EINA_VALUE_TYPE_STRING)
|
|
||||||
r = eina_value_set(value, data);
|
|
||||||
else
|
|
||||||
r = eina_value_pset(value, data);
|
|
||||||
|
|
||||||
if (!r)
|
|
||||||
{
|
|
||||||
eina_value_free(value);
|
|
||||||
value = eina_value_error_new(EFL_MODEL_ERROR_UNKNOWN);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
EOLIAN static Eina_Future *
|
|
||||||
_efl_container_model_item_efl_model_children_slice_get(Eo *obj,
|
|
||||||
Efl_Container_Model_Item_Data *sd EINA_UNUSED,
|
|
||||||
unsigned int start EINA_UNUSED,
|
|
||||||
unsigned int count EINA_UNUSED)
|
|
||||||
{
|
|
||||||
return efl_loop_future_resolved(obj, EINA_VALUE_EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
EOLIAN static unsigned int
|
|
||||||
_efl_container_model_item_efl_model_children_count_get(const Eo *obj EINA_UNUSED,
|
|
||||||
Efl_Container_Model_Item_Data *sd EINA_UNUSED)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EOLIAN static Eo *
|
|
||||||
_efl_container_model_item_efl_model_child_add(Eo *obj EINA_UNUSED,
|
|
||||||
Efl_Container_Model_Item_Data *sd EINA_UNUSED)
|
|
||||||
{
|
|
||||||
EINA_LOG_WARN("child_add not supported by Efl.Model.Container.Item");
|
|
||||||
eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
EOLIAN static void
|
|
||||||
_efl_container_model_item_efl_model_child_del(Eo *obj EINA_UNUSED,
|
|
||||||
Efl_Container_Model_Item_Data *sd EINA_UNUSED,
|
|
||||||
Eo *child EINA_UNUSED)
|
|
||||||
{
|
|
||||||
EINA_LOG_WARN("child_del not supported by Efl.Model.Container.Item");
|
|
||||||
eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "efl_container_model_item.eo.c"
|
|
|
@ -1,34 +0,0 @@
|
||||||
class @beta Efl.Container_Model_Item extends Efl.Object implements Efl.Model
|
|
||||||
{
|
|
||||||
[[
|
|
||||||
Used as a child of @Efl.Container_Model.
|
|
||||||
|
|
||||||
Provides the @Efl.Model API for elements of @Efl.Container_Model.
|
|
||||||
Should not be used in another context, so do not manually create objects
|
|
||||||
of this class.
|
|
||||||
]]
|
|
||||||
methods {
|
|
||||||
define {
|
|
||||||
[[Defines @Efl.Container_Model_Item internal data.]]
|
|
||||||
params {
|
|
||||||
parent_data: void_ptr; [[Pointer to the private data of the
|
|
||||||
@Efl.Container_Model parent object.]]
|
|
||||||
index: uint; [[Index of this item within the @Efl.Container_Model
|
|
||||||
children.]]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
implements {
|
|
||||||
Efl.Object.finalize;
|
|
||||||
Efl.Model.properties { get; }
|
|
||||||
Efl.Model.property { set; get; }
|
|
||||||
Efl.Model.child_add;
|
|
||||||
Efl.Model.child_del;
|
|
||||||
Efl.Model.children_slice_get;
|
|
||||||
Efl.Model.children_count { get; }
|
|
||||||
Efl.Object.invalidate;
|
|
||||||
}
|
|
||||||
constructors {
|
|
||||||
.define;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
#ifndef EFL_CONTAINER_MODEL_PRIVATE_H__
|
|
||||||
#define EFL_CONTAINER_MODEL_PRIVATE_H__
|
|
||||||
|
|
||||||
typedef struct _Child_Property_Data Child_Property_Data;
|
|
||||||
struct _Child_Property_Data
|
|
||||||
{
|
|
||||||
const Eina_Value_Type *type;
|
|
||||||
Eina_Array *values;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _Efl_Container_Model_Data Efl_Container_Model_Data;
|
|
||||||
struct _Efl_Container_Model_Data
|
|
||||||
{
|
|
||||||
Eo *obj;
|
|
||||||
|
|
||||||
Eina_Hash *properties;
|
|
||||||
|
|
||||||
Eina_List *childrens;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _Efl_Container_Model_Item_Data Efl_Container_Model_Item_Data;
|
|
||||||
struct _Efl_Container_Model_Item_Data
|
|
||||||
{
|
|
||||||
Efl_Container_Model_Data *parent_data;
|
|
||||||
unsigned int index;
|
|
||||||
};
|
|
||||||
|
|
||||||
void *_value_copy_alloc(void *v, const Eina_Value_Type *type);
|
|
||||||
|
|
||||||
void _value_free(void *v, const Eina_Value_Type *type);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -70,7 +70,6 @@ pub_eo_files = [
|
||||||
'efl_loop_model.eo',
|
'efl_loop_model.eo',
|
||||||
'efl_generic_model.eo',
|
'efl_generic_model.eo',
|
||||||
'efl_container_model.eo',
|
'efl_container_model.eo',
|
||||||
'efl_container_model_item.eo',
|
|
||||||
'efl_boolean_model.eo',
|
'efl_boolean_model.eo',
|
||||||
'efl_select_model.eo',
|
'efl_select_model.eo',
|
||||||
'efl_composite_model.eo',
|
'efl_composite_model.eo',
|
||||||
|
@ -150,8 +149,6 @@ ecore_src = [
|
||||||
'efl_loop_model.c',
|
'efl_loop_model.c',
|
||||||
'efl_generic_model.c',
|
'efl_generic_model.c',
|
||||||
'efl_container_model.c',
|
'efl_container_model.c',
|
||||||
'efl_container_model_item.c',
|
|
||||||
'efl_container_model_private.h',
|
|
||||||
'efl_composite_model.c',
|
'efl_composite_model.c',
|
||||||
'efl_boolean_model.c',
|
'efl_boolean_model.c',
|
||||||
'efl_select_model.c',
|
'efl_select_model.c',
|
||||||
|
|
Loading…
Reference in New Issue