From 5d08cbad2dd0b9c01abcbb47a127b29d381b6a58 Mon Sep 17 00:00:00 2001 From: "shashank.p" Date: Fri, 4 Mar 2016 15:41:02 -0800 Subject: [PATCH] genlist: add elm_genlist_filtered_items_count API Summary: This API will return the number of items that have passed the filter at a given point of time. If the API is called before "filter,done" callback comes, it may or may not give the filtered count for the complete genlist. Test Plan: Updated Genlist_filter example to print the output from filtered_count_get API in "filter,done" callback. Reviewers: SanghyeonLee, shilpasingh, cedric Reviewed By: cedric Subscribers: buds Differential Revision: https://phab.enlightenment.org/D3725 Signed-off-by: Cedric BAIL --- legacy/elementary/src/bin/test_genlist.c | 6 +++--- legacy/elementary/src/lib/elm_genlist.c | 6 ++++++ legacy/elementary/src/lib/elm_genlist.eo | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/legacy/elementary/src/bin/test_genlist.c b/legacy/elementary/src/bin/test_genlist.c index 483199d61e..0c25669e21 100644 --- a/legacy/elementary/src/bin/test_genlist.c +++ b/legacy/elementary/src/bin/test_genlist.c @@ -5025,11 +5025,11 @@ gl_filter_get(void *data, Evas_Object *obj EINA_UNUSED, void *key) } static void -_gl_filter_finished_cb(void *data EINA_UNUSED, +_gl_filter_finished_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - printf("Filter finished\n"); + printf("Filter finished, filtered items count is %d\n", elm_genlist_filtered_items_count((Evas_Object *)data)); } void @@ -5117,7 +5117,7 @@ test_genlist_filter(void *data EINA_UNUSED, evas_object_smart_callback_add(gl, "activated", _gl_focus_item_cb, "activated"); evas_object_smart_callback_add(gl, "highlighted", _gl_focus_item_cb, "highlighted"); evas_object_smart_callback_add(gl, "unhighlighted", _gl_focus_item_cb, "unhighlighted"); - evas_object_smart_callback_add(gl, "filter,done", _gl_filter_finished_cb, NULL); + evas_object_smart_callback_add(gl, "filter,done", _gl_filter_finished_cb, gl); evas_object_event_callback_add(gl, EVAS_CALLBACK_KEY_DOWN, _gl_focus_key_down_cb, NULL); itc = elm_genlist_item_class_new(); diff --git a/legacy/elementary/src/lib/elm_genlist.c b/legacy/elementary/src/lib/elm_genlist.c index 5447e72d49..ebb31f2c23 100644 --- a/legacy/elementary/src/lib/elm_genlist.c +++ b/legacy/elementary/src/lib/elm_genlist.c @@ -7652,6 +7652,12 @@ _elm_genlist_filter_iterator_new(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd) return &iter->iterator; } +EOLIAN static unsigned int +_elm_genlist_filtered_items_count(const Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd) +{ + return sd->filtered_count; +} + EOLIAN static void _elm_genlist_longpress_timeout_set(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd, double timeout) { diff --git a/legacy/elementary/src/lib/elm_genlist.eo b/legacy/elementary/src/lib/elm_genlist.eo index 5ab6266cee..f3a0d09274 100644 --- a/legacy/elementary/src/lib/elm_genlist.eo +++ b/legacy/elementary/src/lib/elm_genlist.eo @@ -423,6 +423,16 @@ class Elm.Genlist (Elm.Layout, Elm.Interface_Scrollable, Evas.Clickable_Interfac ]] return: free(own(iterator *), eina_iterator_free); [[Iterator on genlist]] } + filtered_items_count @const { + [[Return how many items have passed the filter currently. + + This behaviour is O(1) and may or may not return the + filtered count for complete genlist based on the timing + of the call. To get complete count, call after "filter,done" + callback + ]] + return: uint; + } items_count @const { [[Return how many items are currently in a list.