[store] Removed item list index store and group item append method changed
authorYun ilkook <ilkook.yun@samsung.com>
Thu, 18 Aug 2011 05:37:28 +0000 (14:37 +0900)
committerYun ilkook <ilkook.yun@samsung.com>
Thu, 18 Aug 2011 05:37:28 +0000 (14:37 +0900)
Change-Id: Ic3b476a8ae43c4697d2a286c35f4cfbb73da3c8d

src/lib/elm_store.c

index 1589a5f..2f56835 100644 (file)
@@ -28,8 +28,7 @@
 #define ELM_STORE_FILESYSTEM_MAGIC 0x3f89ea57
 #define ELM_STORE_DBSYSTEM_MAGIC   0x3f89ea58
 #define ELM_STORE_ITEM_MAGIC       0x5afe8c1d
-#define CACHE_COUNT                127
-#define SCREEN_ITEM_COUNT    10
+#define CACHE_COUNT                128
 
 struct _Elm_Store
 {
@@ -44,13 +43,9 @@ struct _Elm_Store
    Eina_List     *realized;
    int            realized_count;
    int            cache_max;
-   int            start_fetch_index;
-   int            end_fetch_index;
    int            item_count;
-   int            total_item_count;
-   int            block_count;
    int            type;
-   Eina_List     *header_items;
+   Eina_List     *always_fetched;
    struct {
         struct {
              Elm_Store_Item_List_Cb     func;
@@ -79,7 +74,6 @@ struct _Elm_Store
    } cb;
    Eina_Bool      sorted : 1;
    Eina_Bool      fetch_thread : 1;
-   Eina_Bool      multi_load : 1;
    Eina_Bool      live : 1;
 };
 
@@ -94,6 +88,8 @@ struct _Elm_Store_Item
    const Elm_Store_Item_Mapping *mapping;
    void                         *data;
    Elm_Store_Item_Info          *item_info;
+   Elm_Genlist_Item             *first_item;
+   Elm_Genlist_Item             *last_item;
    LK(lock);
    Eina_Bool                     live : 1;
    Eina_Bool                     was_live : 1;
@@ -132,15 +128,10 @@ typedef enum
 
 static Elm_Genlist_Item_Class _store_item_class;
 
-static char *_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part);
-static Evas_Object *_item_icon_get(void *data, Evas_Object *obj, const char *part);
-static void _item_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__);
-static void _store_free(Elm_Store *st);
-static void _item_free(Elm_Store_Item *sti);
+static void _item_del(void *data, Evas_Object *obj __UNUSED__);
 static void _item_realized(void *data, Evas_Object *obj __UNUSED__, void *event_info);
 static void _item_unrealized(void *data, Evas_Object *obj __UNUSED__, void *event_info);
 static void _genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__);
-static Elm_Store_Item *_item_unfetch(Elm_Store *st, int index);
 
 static void
 _store_cache_trim(Elm_Store *st)
@@ -642,7 +633,6 @@ elm_store_free(Elm_Store *st)
      }
    else
      {
-        st->live = EINA_FALSE;
         if (st->genlist)
           {
              evas_object_event_callback_del_full(st->genlist, EVAS_CALLBACK_DEL, _genlist_del, st);
@@ -651,52 +641,21 @@ elm_store_free(Elm_Store *st)
              elm_genlist_clear(st->genlist);
              st->genlist = NULL;
           }
-        Eina_List *l;
-        Eina_List *l_next;
-        Eina_List *header_list;
-
-        EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+        while (st->always_fetched)
           {
-             if (header_list)
+             Elm_Store_Item *sti = eina_list_data_get(st->always_fetched);
+             Eina_List *find = NULL;
+             find = eina_list_data_find_list(st->always_fetched, sti);
+             if (find)
                {
-                  Eina_List *in_l;
-                  Eina_List *in_l_next;
-                  Elm_Store_Item *sti;
-                  EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, sti)
-                    {
-                       if(sti)
-                         {
-                            if (st->fetch_thread && sti->fetch_th)
-                              {
-                                 ecore_thread_cancel(sti->fetch_th);
-                                 sti->fetch_th = NULL;
-                              }
-                            if (st->cb.unfetch.func)
-                              {
-                                 LKL(sti->lock);
-                                 sti->fetched = EINA_FALSE;
-                                 LKU(sti->lock);
-                                 if (st->cb.unfetch.func)
-                                   st->cb.unfetch.func(st->cb.unfetch.data, sti, sti->item_info);
-                                 LKL(sti->lock);
-                                 sti->data = NULL;
-                                 LKU(sti->lock);
-                              }
-                            if (st->cb.item_free.func)
-                              {
-                                 st->cb.item_free.func(st->cb.item_free.data, sti->item_info);
-                                 LKL(sti->lock);
-                                 sti->item_info = NULL;
-                                 LKU(sti->lock);
-                              }
-                            LKD(sti->lock);
-                         }
-                    }
-                  st->header_items = eina_list_remove(st->header_items, header_list);
-                  header_list = eina_list_free(header_list);
+                  st->always_fetched = eina_list_remove_list(st->always_fetched, find);
+                  _item_del(sti,NULL);
                }
           }
-        st->header_items = eina_list_free(st->header_items);
+        st->always_fetched = eina_list_free(st->always_fetched);
+        st->realized = eina_list_free(st->realized);
+        if (st->free) st->free(st);
+        st->live = EINA_FALSE;
      }
    free(st);
 }
@@ -735,7 +694,6 @@ elm_store_target_genlist_set(Elm_Store *st, Evas_Object *obj)
         evas_object_smart_callback_add(st->genlist, "realized", _item_realized, st);
         evas_object_smart_callback_add(st->genlist, "unrealized", _item_unrealized, st);
         evas_object_event_callback_add(st->genlist, EVAS_CALLBACK_DEL, _genlist_del, st);
-        st->block_count = elm_genlist_block_count_get(st->genlist);
      }
    elm_genlist_clear(st->genlist);
 }
@@ -888,14 +846,172 @@ elm_store_item_filesystem_path_get(const Elm_Store_Item *item)
 
 // TODO: BEGIN -DBsystem store
 
+static const Elm_Store_Item_Mapping *
+_item_mapping_find(Elm_Store_Item *sti, const char *part)
+{
+   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return NULL;
+   const Elm_Store_Item_Mapping *m;
+
+   if (!sti->item_info) return NULL;
+
+   for (m = sti->item_info->mapping; m; m++)
+     {
+        if (m->type == ELM_STORE_ITEM_MAPPING_NONE) break;
+        if (!strcmp(part, m->part)) return m;
+     }
+   return NULL;
+}
+
+static char *
+_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
+{
+   Elm_Store_Item *sti = data;
+   Elm_Store *st = sti->store;
+   if (st->live)
+     {
+        LKL(sti->lock);
+        if (sti->data)
+          {
+             const char *s = "";
+             const Elm_Store_Item_Mapping *m = _item_mapping_find(sti, part);
+             if (m)
+               {
+                  switch (m->type)
+                    {
+                     case ELM_STORE_ITEM_MAPPING_LABEL:
+                        s = *(char **)(((unsigned char *)sti->data) + m->offset);
+                        break;
+
+                     case ELM_STORE_ITEM_MAPPING_CUSTOM:
+                        if (m->details.custom.func)
+                          s = m->details.custom.func(sti->data, sti, part);
+                        break;
+
+                     default:
+                        break;
+                    }
+                  if (s)
+                    {
+                       LKU(sti->lock);
+                       return strdup(s);
+                    }
+                  else
+                    {
+                       LKU(sti->lock);
+                       return NULL;
+                    }
+               }
+          }
+        else
+          {
+             const char *s = "";
+             const Elm_Store_Item_Mapping *m = _item_mapping_find(sti, part);
+             if (m->type == ELM_STORE_ITEM_MAPPING_CUSTOM)
+               {
+                  if (m->details.custom.func)
+                    s = m->details.custom.func(NULL, sti, part);
+
+                  if (s)
+                    {
+                       LKU(sti->lock);
+                       return strdup(s);
+                    }
+                  else
+                    {
+                       LKU(sti->lock);
+                       return NULL;
+                    }
+               }
+             LKU(sti->lock);
+             return NULL;
+             /*
+                if (!strcmp(part, "elm.text.1"))
+                {
+                LKU(sti->lock);
+             //                           elm_genlist_item_display_only_set(sti->item, EINA_TRUE);
+             return strdup("Loading..");
+             }
+              */
+          }
+        LKU(sti->lock);
+     }
+   return NULL;
+}
+
+static Evas_Object *
+_item_icon_get(void *data, Evas_Object *obj, const char *part)
+{
+   Elm_Store_Item *sti = data;
+   Elm_Store *st = sti->store;
+
+   if (st->live && sti->item)
+     {
+        LKL(sti->lock);
+        if (sti->data)
+          {
+             const Elm_Store_Item_Mapping *m = _item_mapping_find(sti, part);
+             if (m)
+               {
+                  Evas_Object *ic = NULL;
+                  const char *s = NULL;
+
+                  switch (m->type)
+                    {
+                     case ELM_STORE_ITEM_MAPPING_ICON:
+                        ic = elm_icon_add(obj);
+                        s = *(char **)(((unsigned char *)sti->data) + m->offset);
+                        elm_icon_order_lookup_set(ic, m->details.icon.lookup_order);
+                        evas_object_size_hint_aspect_set(ic,
+                                                         EVAS_ASPECT_CONTROL_VERTICAL,
+                                                         m->details.icon.w,
+                                                         m->details.icon.h);
+                        elm_icon_smooth_set(ic, m->details.icon.smooth);
+                        elm_icon_no_scale_set(ic, m->details.icon.no_scale);
+                        elm_icon_scale_set(ic,
+                                           m->details.icon.scale_up,
+                                           m->details.icon.scale_down);
+
+                        if (s)
+                          {
+                             if (m->details.icon.standard_name)
+                               elm_icon_standard_set(ic, s);
+                             else
+                               elm_icon_file_set(ic, s, NULL);
+                          }
+                        break;
+
+                     case ELM_STORE_ITEM_MAPPING_PHOTO:
+                        ic = elm_icon_add(obj);
+                        s = *(char **)(((unsigned char *)sti->data) + m->offset);
+                        elm_photo_size_set(ic, m->details.photo.size);
+                        if (s)
+                          elm_photo_file_set(ic, s);
+                        break;
+
+                     case ELM_STORE_ITEM_MAPPING_CUSTOM:
+                        if (m->details.custom.func)
+                          ic = m->details.custom.func(sti->data, sti, part);
+                        break;
+
+                     default:
+                        break;
+                    }
+                  LKU(sti->lock);
+                  return ic;
+               }
+          }
+        LKU(sti->lock);
+     }
+   return NULL;
+}
+
 static Elm_Store *
 _store_init(size_t size)
 {
    Elm_Store *st = calloc(1, size);
-   if (!st) return NULL;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(st, NULL);
 
    eina_magic_string_set(ELM_STORE_MAGIC, "Elm_Store");
-   eina_magic_string_set(ELM_STORE_FILESYSTEM_MAGIC, "Elm_Store_Filesystem");
    eina_magic_string_set(ELM_STORE_ITEM_MAGIC, "Elm_Store_Item");
    eina_magic_string_set(ELM_STORE_DBSYSTEM_MAGIC, "Elm_Store_DBsystem");
 
@@ -907,11 +1023,7 @@ _store_init(size_t size)
 
    EINA_MAGIC_SET(st, ELM_STORE_MAGIC);
    st->cache_max = CACHE_COUNT;
-   st->start_fetch_index = 0;
-   st->end_fetch_index = 0;
    st->live = EINA_TRUE;
-   st->multi_load = EINA_FALSE;
-   st->total_item_count = 0;
    st->fetch_thread = EINA_FALSE;
    st->type = 1;
    return st;
@@ -922,11 +1034,16 @@ _store_init(size_t size)
 static void
 _genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
 {
-   EINA_SAFETY_ON_NULL_RETURN(data);
    Elm_Store *st = data;
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
 
-   elm_store_free(st);
+   st->genlist = NULL;
+   if (st->list_th)
+     {
+        ecore_thread_cancel(st->list_th);
+        st->list_th = NULL;
+     }
+   st->realized = eina_list_free(st->realized);
 }
 
 static void
@@ -935,12 +1052,21 @@ _store_fetch_do(void *data, Ecore_Thread *th __UNUSED__)
    Elm_Store_Item *sti = data;
 
    LKL(sti->lock);
-   if (!sti->fetched)
+   if (sti->data)
      {
         LKU(sti->lock);
-        sti->store->cb.fetch.func(sti->store->cb.fetch.data, sti, sti->item_info);
-        LKL(sti->lock);
-        sti->fetched = EINA_TRUE;
+        return;
+     }
+   if (!sti->fetched)
+     {
+        if (sti->item_info != NULL)
+          {
+             LKU(sti->lock);
+             if (sti->store->cb.fetch.func)
+               sti->store->cb.fetch.func(sti->store->cb.fetch.data, sti, sti->item_info);
+             LKL(sti->lock);
+             sti->fetched = EINA_TRUE;
+          }
      }
    LKU(sti->lock);
 }
@@ -950,7 +1076,7 @@ _store_fetch_end(void *data, Ecore_Thread *th)
 {
    Elm_Store_Item *sti = data;
    LKL(sti->lock);
-   if(sti->data) elm_genlist_item_update(sti->item);
+   if (sti->data) elm_genlist_item_update(sti->item);
    LKU(sti->lock);
    if (th == sti->fetch_th) sti->fetch_th = NULL;
 }
@@ -961,453 +1087,261 @@ _store_fetch_cancel(void *data, Ecore_Thread *th)
    Elm_Store_Item *sti = data;
    LKL(sti->lock);
    if (th == sti->fetch_th) sti->fetch_th = NULL;
-   if(sti->data) elm_genlist_item_update(sti->item);
+   //   if(sti->data) elm_genlist_item_update(sti->item);
    LKU(sti->lock);
 }
 
-static Elm_Store_Item *
-_item_fetch(Elm_Store *st, int index)
+static void
+_item_eval(void *data)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(st,NULL);
-   Elm_Store_Item *sti;
+   Elm_Store_Item *sti = data;
+   if (!sti) return;
+   Elm_Store *st = sti->store;
 
-   int in_index = 0;
-   Eina_List *l;
-   Eina_List *l_next;
-   Eina_List *header_list;
-   if (st->live)
+   if (sti->fetched == EINA_FALSE)
      {
-        EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+        if (st->fetch_thread && !sti->fetch_th)
           {
-             if(header_list)
+             sti->fetch_th = ecore_thread_run(_store_fetch_do, _store_fetch_end, _store_fetch_cancel, sti);
+          }
+        else if (!st->fetch_thread)
+          {
+             _store_fetch_do(sti,NULL);
+             _store_fetch_end(sti,NULL);
+          }
+     }
+   else
+     {
+        LKL(sti->lock);
+        if (!sti->fetched)
+          {
+             LKU(sti->lock);
+             if (sti->fetch_th)
                {
-                  if ((in_index + eina_list_count(header_list)) > index)
-                    {
-                       sti = eina_list_nth(header_list, index - in_index);
-                       if(sti)
-                         {
-                            if (st->cb.fetch.func)
-                              {
-                                 LKL(sti->lock);
-                                 if (st->fetch_thread)
-                                   {
-                                      if (!sti->fetch_th)
-                                        {
-                                           sti->fetch_th = ecore_thread_run(_store_fetch_do,
-                                                                            _store_fetch_end,
-                                                                            _store_fetch_cancel,
-                                                                            sti);
-                                        }
-                                   }
-                                 else
-                                   {
-                                      LKU(sti->lock);
-                                      st->cb.fetch.func(st->cb.fetch.data, sti, sti->item_info);
-                                      LKL(sti->lock);
-                                      sti->fetched = EINA_TRUE;
-                                      if(sti->data) elm_genlist_item_update(sti->item);
-                                   }
-                                 LKU(sti->lock);
-                              }
-                            return sti;
-                         }
-                       else
-                         {
-                            return NULL;
-                         }
-                    }
-                  else
-                    {
-                       in_index = in_index + eina_list_count(header_list);
-                    }
+                  ecore_thread_cancel(sti->fetch_th);
+                  sti->fetch_th = NULL;
                }
+             LKL(sti->lock);
           }
+        sti->fetched = EINA_FALSE;
+        LKU(sti->lock);
+        if (st->cb.unfetch.func)
+          st->cb.unfetch.func(st->cb.unfetch.data, sti, sti->item_info);
+        LKL(sti->lock);
+        sti->data = NULL;
+        LKU(sti->lock);
      }
-   return NULL;
 }
 
-static Elm_Store_Item *
-_item_unfetch(Elm_Store *st, int index)
+static void
+_item_realize(Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(st,NULL);
-
-   int in_index = 0;
-   Elm_Store_Item *sti;
-   Eina_List *l;
-   Eina_List *l_next;
-   Eina_List *header_list;
-
+   Elm_Store *st = sti->store;
+   sti->eval_job = NULL;
    if (st->live)
      {
-        EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+        Eina_List *find = NULL;
+        find = eina_list_data_find_list(st->always_fetched, sti);
+        if (find) return;
+
+        find = eina_list_data_find_list(st->realized,sti);
+        if (find)
+          {
+             Elm_Store_Item *realized_sti = NULL;
+             realized_sti = eina_list_data_get(find);
+             st->realized = eina_list_remove_list(st->realized, find);
+             _item_eval(realized_sti);
+          }
+        if (st->realized)
           {
-             if(header_list)
+             if ((int)eina_list_count(st->realized) == st->cache_max)
                {
-                  if ((in_index + eina_list_count(header_list)) > index)
-                    {
-                       sti = eina_list_nth(header_list, index - in_index);
-                       if(sti)
-                         {
-                            if (st->cb.unfetch.func)
-                              {
-                                 LKL(sti->lock);
-                                 if (sti->fetch_th)
-                                   {
-                                      LKU(sti->lock);
-                                      ecore_thread_cancel(sti->fetch_th);
-                                      sti->fetch_th = NULL;
-                                      LKL(sti->lock);
-                                   }
-                                 LKU(sti->lock);
-                                 st->cb.unfetch.func(st->cb.unfetch.data, sti, sti->item_info);
-                                 LKL(sti->lock);
-                                 sti->fetched = EINA_FALSE;
-                                 LKU(sti->lock);
-                              }
-                            return sti;
-                         }
-                       else
-                         {
-                            return NULL;
-                         }
-                    }
-                  else
-                    {
-                       in_index = in_index + eina_list_count(header_list);
-                    }
+                  Elm_Store_Item *realized_sti = NULL;
+                  Eina_List *last = eina_list_last(st->realized);
+                  realized_sti = eina_list_data_get(last);
+                  st->realized = eina_list_remove_list(st->realized, last);
+                  _item_eval(realized_sti);
                }
           }
+        st->realized = eina_list_prepend(st->realized, sti);
+        _item_eval(sti);
      }
-   return NULL;
 }
 
-static const Elm_Store_Item_Mapping *
-_item_mapping_find(Elm_Store_Item *sti, const char *part)
+static void
+_item_job_add(Elm_Store_Item *sti)
 {
-   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return NULL;
-   const Elm_Store_Item_Mapping *m;
-
-   if(!sti->item_info)
-     {
-        return NULL;
-     }
-
-   for (m = sti->item_info->mapping; m; m++)
-     {
-        if (m->type == ELM_STORE_ITEM_MAPPING_NONE) break;
-        if (!strcmp(part, m->part)) return m;
-     }
-   return NULL;
+   if (sti->eval_job) ecore_job_del(sti->eval_job);
+   sti->eval_job = ecore_job_add(_item_realize, sti);
 }
 
 static void
-_item_realize(Elm_Store_Item *sti)
+_item_fetch(Elm_Store_Item *sti)
 {
-   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
    Elm_Store *st = sti->store;
-   if (sti->store->live)
-     {
-        int index = elm_store_item_index_get(sti);
 
-        if (index != -1)
+   if (st->live)
+     {
+        LKL(sti->lock);
+        if (!sti->fetched)
           {
-             if ((st->start_fetch_index <= index) && (index <= (st->start_fetch_index + st->cache_max)))
-               {
-                  if (sti->fetched)
-                    {
-                       _item_unfetch(st, index);
-                    }
-                  _item_fetch(st, index);
-
-                  if(st->end_fetch_index < index)
-                    {
-                       st->end_fetch_index = index;
-                    }
-               }
-             else if (st->start_fetch_index > index)
-               {
-                  int diff = st->start_fetch_index - index;
-                  int loop;
-                  for (loop = 1; loop <= diff; loop++)
-                    {
-                       _item_unfetch(st, st->end_fetch_index);
-                       st->end_fetch_index--;
-                       _item_fetch(sti->store, (st->start_fetch_index - loop));
-                    }
-                  st->start_fetch_index = index;
-               }
-             else if (index > st->end_fetch_index)
+             LKU(sti->lock);
+             if (sti->fetch_th)
                {
-                  int diff = index - st->end_fetch_index;
-                  int loop;
-                  for (loop = 1; loop <= diff; loop++)
-                    {
-                       _item_unfetch(st, st->start_fetch_index);
-                       st->start_fetch_index++;
-                       _item_fetch(st, (st->end_fetch_index + loop));
-                    }
-                  st->end_fetch_index = index;
+                  ecore_thread_cancel(sti->fetch_th);
+                  sti->fetch_th = NULL;
                }
+             LKL(sti->lock);
           }
-        else
+        if (sti->item_info != NULL)
           {
-             return;
+             LKU(sti->lock);
+             if (sti->store->cb.fetch.func)
+               sti->store->cb.fetch.func(sti->store->cb.fetch.data, sti, sti->item_info);
+             LKL(sti->lock);
+             sti->fetched = EINA_TRUE;
           }
+        LKU(sti->lock);
      }
 }
 
-static char *
-_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
+static void
+_item_unfetch(Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(data, strdup(""));
-   Elm_Store_Item *sti = data;
-   EINA_SAFETY_ON_NULL_RETURN_VAL(sti,NULL);
+   EINA_SAFETY_ON_NULL_RETURN(sti);
+   Elm_Store *st = sti->store;
 
-   if (sti->store->live)
+   if (st->live)
      {
-        if (sti->item)
+        LKL(sti->lock);
+        if (!sti->fetched)
           {
-             if (!sti->data)
+             LKU(sti->lock);
+             if (sti->fetch_th)
                {
-                  _item_realize(sti);
+                  ecore_thread_cancel(sti->fetch_th);
+                  sti->fetch_th = NULL;
                }
-
              LKL(sti->lock);
-             if (sti->data)
-               {
-                  const char *s = "";
-                  const Elm_Store_Item_Mapping *m = _item_mapping_find(sti, part);
-                  if (m)
-                    {
-                       switch (m->type)
-                         {
-                          case ELM_STORE_ITEM_MAPPING_LABEL:
-                             s = *(char **)(((unsigned char *)sti->data) + m->offset);
-                             break;
-
-                          case ELM_STORE_ITEM_MAPPING_CUSTOM:
-                             if (m->details.custom.func)
-                               s = m->details.custom.func(sti->data, sti, part);
-                             break;
-
-                          default:
-                             break;
-                         }
-                       if (s)
-                         {
-                            LKU(sti->lock);
-                            return strdup(s);
-                         }
-                       else
-                         {
-                            LKU(sti->lock);
-                            return NULL;
-                         }
-                    }
-               }
-             LKU(sti->lock);
           }
+        sti->fetched = EINA_FALSE;
+        LKU(sti->lock);
+        if (st->cb.unfetch.func)
+          st->cb.unfetch.func(st->cb.unfetch.data, sti, sti->item_info);
+        LKL(sti->lock);
+        sti->data = NULL;
+        LKU(sti->lock);
      }
-   return NULL;
 }
 
-static Evas_Object *
-_item_icon_get(void *data, Evas_Object *obj, const char *part)
+static void
+_item_realized(void *data , Evas_Object *obj __UNUSED__, void *event_info)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(data,NULL);
-   Elm_Store_Item *sti = data;
-   EINA_SAFETY_ON_NULL_RETURN_VAL(sti,NULL);
+   Elm_Store *st = data;
+   if (!st) return;
+   Elm_Genlist_Item *gli = event_info;
+   Elm_Store_Item *sti = elm_genlist_item_data_get(gli);
+   if (!sti) return;
 
-   if (sti->store->live)
+   if (st->live && sti->item)
      {
-        if (sti->item)
-          {
-             if (!sti->data)
-               {
-                  _item_realize(sti);
-               }
-
-             LKL(sti->lock);
-             if (sti->data)
-               {
-                  const Elm_Store_Item_Mapping *m = _item_mapping_find(sti, part);
-                  if (m)
-                    {
-                       Evas_Object *ic = NULL;
-                       const char *s = NULL;
-
-                       switch (m->type)
-                         {
-                          case ELM_STORE_ITEM_MAPPING_ICON:
-                             ic = elm_icon_add(obj);
-                             s = *(char **)(((unsigned char *)sti->data) + m->offset);
-                             elm_icon_order_lookup_set(ic, m->details.icon.lookup_order);
-                             evas_object_size_hint_aspect_set(ic,
-                                                              EVAS_ASPECT_CONTROL_VERTICAL,
-                                                              m->details.icon.w,
-                                                              m->details.icon.h);
-                             elm_icon_smooth_set(ic, m->details.icon.smooth);
-                             elm_icon_no_scale_set(ic, m->details.icon.no_scale);
-                             elm_icon_scale_set(ic,
-                                                m->details.icon.scale_up,
-                                                m->details.icon.scale_down);
-
-                             if (s)
-                               {
-                                  if (m->details.icon.standard_name)
-                                    elm_icon_standard_set(ic, s);
-                                  else
-                                    elm_icon_file_set(ic, s, NULL);
-                               }
-                             break;
-
-                          case ELM_STORE_ITEM_MAPPING_PHOTO:
-                             ic = elm_icon_add(obj);
-                             s = *(char **)(((unsigned char *)sti->data) + m->offset);
-                             elm_photo_size_set(ic, m->details.photo.size);
-                             if (s)
-                               elm_photo_file_set(ic, s);
-                             break;
-
-                          case ELM_STORE_ITEM_MAPPING_CUSTOM:
-                             if (m->details.custom.func)
-                               ic = m->details.custom.func(sti->data, sti, part);
-                             break;
-
-                          default:
-                             break;
-                         }
-                       LKU(sti->lock);
-                       return ic;
-                    }
-               }
-             LKU(sti->lock);
-          }
+        if (!sti->data) _item_job_add(sti);
      }
-   return NULL;
+   // TODO:
 }
 
 static void
-_item_realized(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
-{
-   /*   EINA_SAFETY_ON_NULL_RETURN(data);
-        EINA_SAFETY_ON_NULL_RETURN(event_info);
-        Elm_Store *st = data;
-        Elm_Genlist_Item *gli = event_info;
-        Elm_Store_Item *sti = elm_genlist_item_data_get(gli);
-
-        EINA_SAFETY_ON_NULL_RETURN(sti);
-
-        int index = elm_store_item_index_get(sti);
-
-        if (st->fetch_thread)
-        {
-        if ((st->start_fetch_index <= index) && (index <= st->end_fetch_index))
-        {
-        int middle_index = sti->store->start_fetch_index + (sti->store->cache_max) / 2;
-
-        if ((middle_index < index) && (sti->store->end_fetch_index < sti->store->total_item_count))
-        {
-        int diff = index - middle_index;
-        int loop;
-        for (loop = 0; loop < diff; loop++)
-        {
-        _item_unfetch(st, sti->store->start_fetch_index);
-        sti->store->start_fetch_index++;
-        _item_fetch(st, (sti->store->end_fetch_index + 1));
-        sti->store->end_fetch_index++;
-        }
-        }
-        else if ((middle_index > index) && (sti->store->start_fetch_index > 0))
-        {
-        int diff = st->current_top_index - index;
-        int loop;
-        for (loop = 0; loop < diff; loop++)
-        {
-        _item_unfetch(st, sti->store->end_fetch_index);
-        sti->store->end_fetch_index--;
-        _item_fetch(st, (sti->store->start_fetch_index - 1));
-        sti->store->start_fetch_index--;
-        }
-        }
-        else {
-        if ((!sti->fetched))
-        {
-        _item_fetch(st, index);
-        }
-        }
-        }
-        }
-
-        if ((st->current_top_index > index))
-        {
-        st->current_top_index = index;
-        }
-        else if ((st->current_top_index + SCREEN_ITEM_COUNT) < index)
-        {
-        st->current_top_index = st->current_top_index + (index - (st->current_top_index + SCREEN_ITEM_COUNT));
-        }
-    */
-   // TODO:
+_item_unrealized(void *data , Evas_Object *obj __UNUSED__, void *event_info)
+{
+   Elm_Store *st = data;
+   if (!st) return;
+   Elm_Genlist_Item *gli = event_info;
+   Elm_Store_Item *sti = elm_genlist_item_data_get(gli);
+   if (!sti) return;
+
+   if (st->live && sti->item)
+     {
+        if (sti->eval_job)
+          {
+             ecore_job_del(sti->eval_job);
+             sti->eval_job = NULL;
+          }
+     }
 }
 
 static void
-_item_unrealized(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+_item_free(Elm_Store_Item *sti)
 {
-   /*   EINA_SAFETY_ON_NULL_RETURN(data);
-        EINA_SAFETY_ON_NULL_RETURN(event_info);
-        Elm_Genlist_Item *gli = event_info;
-        Elm_Store_Item *sti = elm_genlist_item_data_get(gli);
-        EINA_SAFETY_ON_NULL_RETURN(sti);*/
+   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
+   Elm_Store *st = sti->store;
+   LKL(sti->lock);
+   if (st->live && st->cb.item_free.func && sti->item_info)
+     {
+        LKU(sti->lock);
+        st->cb.item_free.func(st->cb.item_free.data, sti->item_info);
+        LKL(sti->lock);
+        sti->item_info = NULL;
+     }
+   LKU(sti->lock);
+   LKD(sti->lock);
+   free(sti);
 }
 
 static void
 _item_del(void *data, Evas_Object *obj __UNUSED__)
 {
-   EINA_SAFETY_ON_NULL_RETURN(data);
    Elm_Store_Item *sti = data;
-   EINA_SAFETY_ON_NULL_RETURN(sti);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
-   elm_store_item_del(sti);
+   Elm_Store *st = sti->store;
+
+   if (sti->eval_job)
+     {
+        ecore_job_del(sti->eval_job);
+        sti->eval_job = NULL;
+     }
+
+   Eina_List *find = NULL;
+   find = eina_list_data_find_list(st->always_fetched, sti);
+   if (find) return;
+
+   find = eina_list_data_find_list(st->realized,sti);
+   if (find)
+     {
+        Elm_Store_Item *realized_sti = NULL;
+        realized_sti = eina_list_data_get(find);
+        st->realized = eina_list_remove_list(st->realized, find);
+     }
+   if (sti->data) _item_unfetch(sti);
+   if (st->item.free) st->item.free(sti);
 }
 
 static void
-_list_do(void *data, Ecore_Thread *th __UNUSED__)
+_list_do(void *data, Ecore_Thread *th)
 {
-   EINA_SAFETY_ON_NULL_RETURN(data);
    Elm_Store *st = data;
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
 
-   if (st->multi_load == EINA_TRUE)
+   Elm_Store_Item_Info *item_info;
+   Eina_Bool ok = EINA_FALSE;
+   int loop;
+   for (loop = 0; loop < st->item_count; loop++)
      {
-        Elm_Store_Item_Info *item_info;
-        Eina_Bool ok = EINA_FALSE;
-        int loop;
-        for (loop = 0; loop < st->item_count; loop++)
-          {
-             item_info = calloc(1, sizeof(Elm_Store_Item_Info));
-             if (!item_info) return;
-             item_info->index = loop;
+        item_info = calloc(1, sizeof(Elm_Store_Item_Info));
+        if (!item_info) return;
+        item_info->index = loop;
 
-             if (st->cb.list.func)
-               {
-                  ok = st->cb.list.func(st->cb.list.data, item_info);
-               }
-             if (ok) ecore_thread_feedback(th, item_info);
-             else free(item_info);
-             if (ecore_thread_check(th)) break;
-          }
+        if (st->cb.list.func) ok = st->cb.list.func(st->cb.list.data, item_info);
+        if (ok) ecore_thread_feedback(th, item_info);
+        else free(item_info);
+        if (ecore_thread_check(th)) break;
      }
 }
 
 static void
 _list_update(void *data, Ecore_Thread *th __UNUSED__, void *msg)
 {
-   EINA_SAFETY_ON_NULL_RETURN(data);
-   EINA_SAFETY_ON_NULL_RETURN(msg);
    Elm_Store *st = data;
    Elm_Store_Item_Info *info = msg;
-
    elm_store_item_add(st, info);
 }
 
@@ -1426,128 +1360,47 @@ _list_cancel(void *data, Ecore_Thread *th)
 }
 
 static void
-_item_select_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
-{
-   EINA_SAFETY_ON_NULL_RETURN(event_info);
-
-   const Elm_Genlist_Item *it = (Elm_Genlist_Item *)event_info;
-   Elm_Store_Item *sti = elm_genlist_item_data_get(it);
-   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
-
-   if (sti->store->cb.item_select.func)
-     {
-        sti->store->cb.item_select.func(sti->store->cb.item_select.data, sti);
-     }
-}
-
-static void
 _group_item_append(Elm_Store_Item *sti, Elm_Genlist_Item_Class *itc)
 {
-   EINA_SAFETY_ON_NULL_RETURN(sti);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
    Elm_Store *st = sti->store;
    if (st->live)
      {
-        if (st->header_items)
+        if (st->always_fetched)
           {
-             Eina_Bool header_add = EINA_TRUE;
-             Eina_List *l;
-             Eina_List *l_next;
-             Eina_List *header_list;
-
-             EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
-               {
-                  if(header_list)
-                    {
-                       Elm_Store_Item *item = eina_list_nth(header_list, 0);
-                       if(item && item->item_info)
-                         {
-                            if (item->item_info->group_index == sti->item_info->group_index)
-                              {
-                                 header_add = EINA_FALSE;
-                                 break;
-                              }
-                         }
-                    }
-               }
-             if (header_add)
+             Eina_Bool group_existed = EINA_FALSE;
+             const Eina_List *l = st->always_fetched;
+             Elm_Store_Item *group_sti = eina_list_data_get(l);
+             while (!group_existed && group_sti)
                {
-                  Eina_List *new_header_list = NULL;
-                  sti->item_info->index = 0;
-                  new_header_list = eina_list_append(new_header_list, sti);
-                  st->total_item_count++;
-
-                  Eina_Bool last_header = EINA_TRUE;
-                  Eina_List *l;
-                  Eina_List *l_next;
-                  Eina_List *header_list;
-
-                  EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+                  if (group_sti->item_info->group_index == sti->item_info->group_index)
                     {
-                       if (header_list)
-                         {
-                            Elm_Store_Item *group_sti = eina_list_nth(header_list, 0);
-                            if(group_sti && group_sti->item_info)
-                              {
-                                 if(group_sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP)
-                                   {
-                                      int sort;
-                                      if (st->cb.item_sort.func)
-                                        {
-                                           sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, group_sti->item_info);
-
-                                           if(sort == ELM_STORE_ITEM_SORT_LOW)
-                                             {
-                                                st->header_items = eina_list_prepend_relative(st->header_items, new_header_list, header_list);
-                                                sti->item = elm_genlist_item_insert_before(st->genlist,
-                                                                                           itc,
-                                                                                           sti,
-                                                                                           NULL,
-                                                                                           group_sti->item,
-                                                                                           ELM_GENLIST_ITEM_GROUP,
-                                                                                           NULL,
-                                                                                           NULL);
-                                                last_header = EINA_FALSE;
-                                                break;
-                                             }
-                                        }
-                                      else
-                                        {
-                                           break;
-                                        }
-                                   }
-                              }
-                         }
+                       group_existed = EINA_TRUE;
+                       break;
                     }
-                  if (last_header)
+                  else
                     {
-                       st->header_items = eina_list_append(st->header_items, new_header_list);
-                       sti->item = elm_genlist_item_append(st->genlist,
-                                                           itc,
-                                                           sti,
-                                                           NULL,
-                                                           ELM_GENLIST_ITEM_GROUP,
-                                                           NULL,
-                                                           NULL);
+                       l = eina_list_next(l);
+                       group_sti = eina_list_data_get(l);
                     }
-                  elm_store_item_update(sti);
                }
+             if (group_existed) return; //Already existed the group item
           }
-        else
+        st->always_fetched = eina_list_append(st->always_fetched, sti);
+        sti->realized = EINA_FALSE;
+        if (sti->data) _item_unfetch(sti);
+        _item_fetch(sti);
+
+        if (sti->item_info->group_index == -1)
           {
-             Eina_List *header_list = NULL;
-             sti->item_info->index = 0;
-             header_list = eina_list_append(header_list, sti);
-             st->total_item_count++;
-             st->header_items = eina_list_append(st->header_items, header_list);
              sti->item = elm_genlist_item_append(st->genlist,
                                                  itc,
                                                  sti,
                                                  NULL,
-                                                 ELM_GENLIST_ITEM_GROUP,
-                                                 NULL,
-                                                 NULL);
-             elm_store_item_update(sti);
+                                                 ELM_GENLIST_ITEM_NONE,
+                                                 (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                 (void *)sti->store->cb.item_select.data);
+             return;
           }
      }
 }
@@ -1555,409 +1408,293 @@ _group_item_append(Elm_Store_Item *sti, Elm_Genlist_Item_Class *itc)
 static void
 _normal_item_append(Elm_Store_Item *sti, Elm_Genlist_Item_Class *itc)
 {
-   EINA_SAFETY_ON_NULL_RETURN(sti);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
    Elm_Store *st = sti->store;
-   if (st->live)
+   if (st->live && sti->item_info)
      {
-        if (sti->item_info->rec_item == EINA_TRUE)
+        Eina_Bool need_update = EINA_FALSE;
+        Eina_Bool group_existed = EINA_FALSE;
+        const Eina_List *l;
+
+        if (st->always_fetched)
           {
-             if (sti->item_info->group_index == sti->item_info->pre_group_index)
+             if (sti->item_info->rec_item == EINA_TRUE)
                {
-                  Eina_List *l;
-                  Eina_List *l_next;
-                  Eina_List *header_list;
-
-                  EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+                  if (sti->item_info->group_index != sti->item_info->pre_group_index)
                     {
-                       if(header_list)
+                       if (sti->item_info->group_index < sti->item_info->pre_group_index)
                          {
-                            Elm_Store_Item *header_item = eina_list_nth(header_list, 0);
-                            if(header_item && header_item->item_info)
+                            Eina_Bool pre_group_existed = EINA_FALSE;
+                            l = st->always_fetched;
+                            Elm_Store_Item *pre_group_sti = eina_list_data_get(l);
+                            while (!pre_group_existed && pre_group_sti)
                               {
-                                 if (header_item->item_info->group_index == sti->item_info->group_index)
+                                 if (pre_group_sti->item_info->pre_group_index == sti->item_info->pre_group_index)
                                    {
-                                      Eina_List *in_l;
-                                      Eina_List *in_l_next;
-                                      Elm_Store_Item *item;
-
-                                      EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, item)
+                                      pre_group_existed = EINA_TRUE;
+                                      break;
+                                   }
+                                 else
+                                   {
+                                      l = eina_list_next(l);
+                                      pre_group_sti = eina_list_data_get(l);
+                                   }
+                              }
+                            if (pre_group_sti && pre_group_sti->realized) // already added the header item to the genlist
+                              {
+                                 Eina_Bool deleted = EINA_FALSE;
+                                 Eina_Bool last_item = EINA_FALSE;
+                                 Elm_Genlist_Item *comp_item = pre_group_sti->first_item;
+                                 while (!deleted && comp_item)
+                                   {
+                                      Elm_Store_Item *comp_sti = elm_genlist_item_data_get(comp_item);
+                                      if (comp_sti)
                                         {
-                                           if(item)
+                                           int sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_sti->item_info);
+                                           if(sort == ELM_STORE_ITEM_SORT_SAME)
                                              {
-                                                int sort;
-                                                if (st->cb.item_sort.func)
-                                                  {
-                                                     sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, item->item_info);
-
-                                                     if(sort == ELM_STORE_ITEM_SORT_SAME)
-                                                       {
-                                                          elm_store_item_update(item);
-                                                       }
-                                                  }
-                                                else
-                                                  {
-                                                     break;
-                                                  }
+                                                elm_store_item_del(comp_sti);
+                                                deleted = EINA_TRUE;
+                                                break;
+                                             }
+                                        }
+                                      if (last_item) break;
+                                      else comp_item = elm_genlist_item_next_get(comp_item);
 
+                                      if (comp_item == pre_group_sti->last_item) last_item = EINA_TRUE;
+                                   }
+                                 if (!deleted) printf(" The item does not existed in the pre group of genlist \n");
+                              }
+                            else //Pre group item does not existed in the always fetched list or the genlist
+                              {
+                                 Eina_Bool deleted = EINA_FALSE;
+                                 Elm_Genlist_Item *comp_item = elm_genlist_first_item_get(st->genlist);
+                                 while (!deleted && comp_item)
+                                   {
+                                      Elm_Store_Item *comp_sti = elm_genlist_item_data_get(comp_item);
+                                      if (comp_sti && sti->item_info->item_type == comp_sti->item_info->item_type)
+                                        {
+                                           int sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_sti->item_info);
+                                           if (sort == ELM_STORE_ITEM_SORT_SAME)
+                                             {
+                                                elm_store_item_del(comp_sti);
+                                                deleted = EINA_TRUE;
+                                                break;
                                              }
                                         }
+                                      comp_item = elm_genlist_item_next_get(comp_item);
                                    }
+                                 if (!deleted) printf(" The item does not existed in the genlist \n");
                               }
                          }
+                       else
+                         {
+                            sti->item_info->group_index = sti->item_info->pre_group_index;
+                            need_update = EINA_TRUE;
+                         }
                     }
+                  else         need_update = EINA_TRUE;
                }
-             else
+             l = st->always_fetched;
+             Elm_Store_Item *group_sti = eina_list_data_get(l);
+             while (!group_existed && group_sti) // Search the group item of a normal item in the always_fetched list
                {
-                  Eina_List *l;
-                  Eina_List *l_next;
-                  Eina_List *header_list;
-
-                  EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+                  if (group_sti->item_info->group_index == sti->item_info->group_index)
+                    {
+                       group_existed = EINA_TRUE;
+                       break;
+                    }
+                  else
+                    {
+                       l = eina_list_next(l);
+                       group_sti = eina_list_data_get(l);
+                    }
+               }
+             if (group_sti)
+               {
+                  if (group_sti->realized) // already added the header item to the genlist
                     {
-                       if(header_list)
+                       Eina_Bool added = EINA_FALSE;
+                       Elm_Genlist_Item *comp_item = group_sti->first_item;
+                       while (!added && comp_item)
                          {
-                            Elm_Store_Item *header_item = eina_list_nth(header_list, 0);
-                            if(header_item && header_item->item_info)
+                            Elm_Store_Item *comp_sti = elm_genlist_item_data_get(comp_item);
+                            if (comp_sti)
                               {
-                                 if (header_item->item_info->group_index == sti->item_info->pre_group_index)
+                                 int sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_sti->item_info);
+                                 if (sort == ELM_STORE_ITEM_SORT_SAME)
                                    {
-                                      Eina_Bool removed = EINA_FALSE;
-                                      Eina_List *in_l;
-                                      Eina_List *in_l_next;
-                                      Elm_Store_Item *remove_item;
-
-                                      EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, remove_item)
-                                        {
-                                           if(remove_item)
-                                             {
-                                                if (removed == EINA_TRUE)
-                                                  {
-                                                     remove_item->item_info->index--;
-                                                  }
-                                                else
-                                                  {
-                                                     int sort;
-                                                     if (st->cb.item_sort.func)
-                                                       {
-                                                          sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, remove_item->item_info);
-
-                                                          if(sort == ELM_STORE_ITEM_SORT_SAME)
-                                                            {
-                                                               if (remove_item->fetched)
-                                                                 {
-                                                                    int index = elm_store_item_index_get(remove_item);
-                                                                    if (index != -1)
-                                                                      {
-                                                                         _item_unfetch(st, index);
-                                                                      }
-                                                                 }
-                                                               if (st->cb.item_free.func)
-                                                                 {
-                                                                    st->cb.item_free.func(st->cb.item_free.data, remove_item->item_info);
-                                                                    remove_item->item_info = NULL;
-                                                                 }
-
-                                                               if (eina_list_count(header_list) == 1)
-                                                                 {
-                                                                    st->header_items = eina_list_remove(st->header_items, header_list);
-                                                                    header_list = eina_list_free(header_list);
-                                                                    st->total_item_count--;
-                                                                    LKD(remove_item->lock);
-                                                                    elm_genlist_item_del(remove_item->item);
-                                                                    free(remove_item);
-                                                                    break;
-                                                                 }
-                                                               else
-                                                                 {
-                                                                    header_list = eina_list_remove(header_list, remove_item);
-                                                                    st->total_item_count--;
-                                                                    LKD(remove_item->lock);
-                                                                    elm_genlist_item_del(remove_item->item);
-                                                                    free(remove_item);
-                                                                 }
-
-                                                               if(eina_list_count(header_list) == 1)
-                                                                 {
-                                                                    Elm_Store_Item *t_sti = eina_list_nth(header_list, 0);
-                                                                    if(t_sti && t_sti->item_info)
-                                                                      {
-                                                                         if (t_sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP)
-                                                                           {
-                                                                              if (t_sti->fetched)
-                                                                                {
-                                                                                   int index = elm_store_item_index_get(t_sti);
-                                                                                   if (index != -1)
-                                                                                     {
-                                                                                        _item_unfetch(st, index);
-                                                                                     }
-                                                                                   else
-                                                                                     {
-                                                                                        break;
-                                                                                     }
-                                                                                }
-
-                                                                              if (st->cb.item_free.func)
-                                                                                {
-                                                                                   st->cb.item_free.func(st->cb.item_free.data, t_sti->item_info);
-                                                                                   t_sti->item_info = NULL;
-                                                                                }
-                                                                              st->header_items = eina_list_remove(st->header_items, header_list);
-                                                                              header_list = eina_list_free(header_list);
-                                                                              st->total_item_count--;
-                                                                              LKD(t_sti->lock);
-                                                                              elm_genlist_item_del(t_sti->item);
-                                                                              free(t_sti);
-                                                                           }
-                                                                      }
-                                                                 }
-                                                               removed = EINA_TRUE;
-                                                            }
-                                                       }
-                                                  }
-                                             }
-                                        }
+                                      if (need_update == EINA_TRUE) elm_store_item_update(comp_sti);
+                                      else added = EINA_TRUE;
+                                      break;
                                    }
-                                 else if (header_item->item_info->group_index == sti->item_info->group_index)
+                                 else if (sort == ELM_STORE_ITEM_SORT_LOW)
                                    {
-                                      Eina_Bool last_add = EINA_TRUE;
-                                      Eina_List *in_l;
-                                      Eina_List *in_l_next;
-                                      Elm_Store_Item *comp_item;
+                                      sti->item = elm_genlist_item_insert_before(st->genlist,
+                                                                                 itc,
+                                                                                 sti,
+                                                                                 group_sti->item,
+                                                                                 comp_item,
+                                                                                 ELM_GENLIST_ITEM_NONE,
+                                                                                 (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                                                 (void *)sti->store->cb.item_select.data);
+
+                                      if (comp_item == group_sti->first_item) group_sti->first_item = sti->item;
+                                      added = EINA_TRUE;
+                                      break;
+                                   }
 
-                                      EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, comp_item)
-                                        {
-                                           if(comp_item)
-                                             {
-                                                if(last_add == EINA_FALSE)
-                                                  {
-                                                     comp_item->item_info->index++;
-                                                  }
-                                                else
-                                                  {
-                                                     int sort;
-                                                     if (st->cb.item_sort.func)
-                                                       {
-                                                          sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_item->item_info);
-
-                                                          if(sort == ELM_STORE_ITEM_SORT_LOW)
-                                                            {
-                                                               sti->item_info->index = comp_item->item_info->index;
-                                                               comp_item->item_info->index++;
-                                                               header_list = eina_list_prepend_relative(header_list, sti, comp_item);
-                                                               l->data = header_list;
-                                                               st->total_item_count++;
-                                                               sti->item = elm_genlist_item_insert_before(st->genlist,
-                                                                                                          itc,
-                                                                                                          sti,
-                                                                                                          header_item->item,
-                                                                                                          comp_item->item,
-                                                                                                          ELM_GENLIST_ITEM_NONE,
-                                                                                                          (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                                          (void *)sti->store->cb.item_select.data);
-                                                               last_add = EINA_FALSE;
-                                                            }
-                                                       }
-                                                     else
-                                                       {
-                                                          Elm_Store_Item *last_sti = eina_list_nth(header_list, eina_list_count(header_list) - 1);
-                                                          sti->item_info->index = eina_list_count(header_list);
-                                                          header_list = eina_list_append(header_list, sti);
-                                                          st->total_item_count++;
-                                                          sti->item = elm_genlist_item_insert_after(st->genlist,
-                                                                                                    itc,
-                                                                                                    sti,
-                                                                                                    header_item->item,
-                                                                                                    last_sti->item,
-                                                                                                    ELM_GENLIST_ITEM_NONE,
-                                                                                                    (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                                    (void *)sti->store->cb.item_select.data);
-                                                          last_add = EINA_FALSE;
-                                                       }
-                                                  }
-                                             }
-                                        }
-                                      if(last_add)
-                                        {
-                                           Elm_Store_Item *last_sti = eina_list_nth(header_list, eina_list_count(header_list) - 1);
-                                           sti->item_info->index = eina_list_count(header_list);
-                                           header_list = eina_list_append(header_list, sti);
-                                           st->total_item_count++;
-                                           sti->item = elm_genlist_item_insert_after(st->genlist,
-                                                                                     itc,
-                                                                                     sti,
-                                                                                     header_item->item,
-                                                                                     last_sti->item,
-                                                                                     ELM_GENLIST_ITEM_NONE,
-                                                                                     (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                     (void *)sti->store->cb.item_select.data);
-                                           elm_store_item_update(sti);
-                                        }
-                                      if(last_add == EINA_FALSE)
-                                        {
-                                           elm_store_item_update(sti);
-                                        }
+                                 if (comp_item == group_sti->last_item) //To add the item in to the last of its group
+                                   {
+                                      need_update = EINA_FALSE;
+                                      break;
+                                   }
+                              }
+                            comp_item = elm_genlist_item_next_get(comp_item);
+                         }
+                       if (!added && !need_update)
+                         {
+                            Elm_Genlist_Item *last_item = group_sti->last_item;
+                            if (last_item)
+                              {
+                                 sti->item = elm_genlist_item_insert_after(st->genlist,
+                                                                           itc,
+                                                                           sti,
+                                                                           group_sti->item,
+                                                                           last_item,
+                                                                           ELM_GENLIST_ITEM_NONE,
+                                                                           (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                                           (void *)sti->store->cb.item_select.data);
+                                 group_sti->last_item = sti->item;
+                              }
+                            else printf(" Group item have no last item. so can not add a item to the genlist \n");
+                         }
+                    }
+                  else // To add the header item in genlist, and compare with other header items along with callback func
+                    {
+                       Eina_Bool added = EINA_FALSE;
+                       l = st->always_fetched;
+                       Elm_Store_Item *comp_group_sti = eina_list_data_get(l);
+                       while (!added && comp_group_sti)
+                         {
+                            if (comp_group_sti != group_sti && comp_group_sti->realized)
+                              {
+                                 // Compare with group items
+                                 int sort = st->cb.item_sort.func(st->cb.item_sort.data, group_sti->item_info, comp_group_sti->item_info);
+                                 if(sort == ELM_STORE_ITEM_SORT_LOW)
+                                   {
+                                      group_sti->item = elm_genlist_item_insert_before(st->genlist,
+                                                                                       group_sti->item_info->item_class,
+                                                                                       group_sti,
+                                                                                       NULL,
+                                                                                       comp_group_sti->item,
+                                                                                       ELM_GENLIST_ITEM_GROUP,
+                                                                                       NULL, NULL);
+
+                                      group_sti->realized = EINA_TRUE;
+                                      sti->item = elm_genlist_item_insert_after(st->genlist,
+                                                                                itc,
+                                                                                sti,
+                                                                                group_sti->item,
+                                                                                group_sti->item,
+                                                                                ELM_GENLIST_ITEM_NONE,
+                                                                                (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                                                (void *)sti->store->cb.item_select.data);
+
+                                      group_sti->first_item = sti->item;
+                                      group_sti->last_item = sti->item;
+                                      added = EINA_TRUE;
+                                      break;
                                    }
                               }
+                            l = eina_list_next(l);
+                            comp_group_sti = eina_list_data_get(l);
+                         }
+                       if (!comp_group_sti) // First item append in the genlist
+                         {
+                            group_sti->item = elm_genlist_item_append(st->genlist,
+                                                                      group_sti->item_info->item_class,
+                                                                      group_sti,
+                                                                      NULL,
+                                                                      ELM_GENLIST_ITEM_GROUP,
+                                                                      NULL, NULL);
+
+                            group_sti->realized = EINA_TRUE;
+                            sti->item = elm_genlist_item_append(st->genlist,
+                                                                itc,
+                                                                sti,
+                                                                group_sti->item,
+                                                                ELM_GENLIST_ITEM_NONE,
+                                                                (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                                (void *)sti->store->cb.item_select.data);
+
+                            group_sti->first_item = sti->item;
+                            group_sti->last_item = sti->item;
                          }
                     }
                }
           }
-        else
+        if (!group_existed) // No exist the group item of normal item, so it added without group.
           {
-             if (st->header_items)
+             Eina_Bool added = EINA_FALSE;
+             Elm_Genlist_Item *comp_item = elm_genlist_first_item_get(st->genlist);
+             while (!added && comp_item)
                {
-                  Eina_Bool normal_add = EINA_TRUE;
-                  Eina_List *l;
-                  Eina_List *l_next;
-                  Eina_List *header_list;
-
-                  EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+                  Elm_Store_Item *comp_sti = elm_genlist_item_data_get(comp_item);
+                  if (comp_sti)
                     {
-                       if (header_list)
+                       if (sti->item_info->item_type == comp_sti->item_info->item_type)
                          {
-                            Elm_Store_Item *header_item = eina_list_nth(header_list, 0);
-
-                            if(header_item && header_item->item_info)
+                            int sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_sti->item_info);
+                            if (sort == ELM_STORE_ITEM_SORT_SAME)
                               {
-                                 if (header_item->item_info->group_index == sti->item_info->group_index)
+                                 if (sti->item_info->rec_item == EINA_TRUE)
                                    {
-                                      Eina_List *in_l;
-                                      Eina_List *in_l_next;
-                                      Elm_Store_Item *comp_item;
-
-                                      EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, comp_item)
-                                        {
-                                           if (comp_item )
-                                             {
-                                                if(normal_add == EINA_FALSE)
-                                                  {
-                                                     comp_item->item_info->index++;
-                                                  }
-                                                else
-                                                  {
-                                                     int sort;
-                                                     if (st->cb.item_sort.func)
-                                                       {
-                                                          sort = st->cb.item_sort.func(st->cb.item_sort.data, sti->item_info, comp_item->item_info);
-
-                                                          if(sort == ELM_STORE_ITEM_SORT_LOW)
-                                                            {
-                                                               sti->item_info->index = comp_item->item_info->index;
-                                                               comp_item->item_info->index++;
-                                                               header_list = eina_list_prepend_relative(header_list, sti, comp_item);
-                                                               l->data = header_list;
-                                                               st->total_item_count++;
-                                                               sti->item = elm_genlist_item_insert_before(st->genlist,
-                                                                                                          itc,
-                                                                                                          sti,
-                                                                                                          header_item->item,
-                                                                                                          comp_item->item,
-                                                                                                          ELM_GENLIST_ITEM_NONE,
-                                                                                                          (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                                          (void *)sti->store->cb.item_select.data);
-                                                               normal_add = EINA_FALSE;
-                                                            }
-                                                       }
-                                                     else
-                                                       {
-                                                          Elm_Store_Item *last_sti = eina_list_nth(header_list, eina_list_count(header_list) - 1);
-                                                          sti->item_info->index = eina_list_count(header_list);
-                                                          header_list = eina_list_append(header_list, sti);
-                                                          st->total_item_count++;
-                                                          sti->item = elm_genlist_item_insert_after(st->genlist,
-                                                                                                    itc,
-                                                                                                    sti,
-                                                                                                    header_item->item,
-                                                                                                    last_sti->item,
-                                                                                                    ELM_GENLIST_ITEM_NONE,
-                                                                                                    (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                                    (void *)sti->store->cb.item_select.data);
-                                                          normal_add = EINA_FALSE;
-                                                       }
-                                                  }
-                                             }
-                                        }
-                                      if(normal_add)
-                                        {
-                                           Elm_Store_Item *last_sti = eina_list_nth(header_list, eina_list_count(header_list) - 1);
-                                           sti->item_info->index = eina_list_count(header_list);
-                                           header_list = eina_list_append(header_list, sti);
-                                           st->total_item_count++;
-                                           sti->item = elm_genlist_item_insert_after(st->genlist,
-                                                                                     itc,
-                                                                                     sti,
-                                                                                     header_item->item,
-                                                                                     last_sti->item,
-                                                                                     ELM_GENLIST_ITEM_NONE,
-                                                                                     (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                                                     (void *)sti->store->cb.item_select.data);
-                                           normal_add = EINA_FALSE;
-                                        }
-                                      if(normal_add == EINA_FALSE)
-                                        {
-                                           elm_store_item_update(sti);
-                                           break;
-                                        }
+                                      elm_store_item_update(comp_sti);
+                                      need_update = EINA_TRUE;
                                    }
+                                 else added = EINA_TRUE;
+                                 break;
+                              }
+                            else if (sort == ELM_STORE_ITEM_SORT_LOW)
+                              {
+                                 sti->item = elm_genlist_item_insert_before(st->genlist,
+                                                                            itc,
+                                                                            sti,
+                                                                            NULL,
+                                                                            comp_item,
+                                                                            ELM_GENLIST_ITEM_NONE,
+                                                                            (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                                            (void *)sti->store->cb.item_select.data);
+
+                                 added = EINA_TRUE;
+                                 break;
                               }
                          }
                     }
-                  if (normal_add)
-                    {
-                       Eina_List *new_header_list = NULL;
-                       sti->item_info->index = 0;
-                       new_header_list = eina_list_append(new_header_list, sti);
-                       st->total_item_count++;
-                       st->header_items = eina_list_append(st->header_items, new_header_list);
-                       sti->item = elm_genlist_item_append(st->genlist,
-                                                           itc,
-                                                           sti,
-                                                           NULL,
-                                                           ELM_GENLIST_ITEM_NONE,
-                                                           (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                           (void *)sti->store->cb.item_select.data);
-                       elm_store_item_update(sti);
-                    }
+                  comp_item = elm_genlist_item_next_get(comp_item);
+                  if (comp_item == NULL) need_update = EINA_FALSE;
                }
-             else
+             if (!added && !need_update)
                {
-                  if (st->live)
-                    {
-                       Eina_List *new_header_list = NULL;
-                       sti->item_info->index = 0;
-                       new_header_list = eina_list_append(new_header_list, sti);
-                       st->total_item_count++;
-                       st->header_items = eina_list_append(st->header_items, new_header_list);
-                       sti->item = elm_genlist_item_append(st->genlist,
-                                                           itc,
-                                                           sti,
-                                                           NULL,
-                                                           ELM_GENLIST_ITEM_NONE,
-                                                           (Evas_Smart_Cb)sti->store->cb.item_select.func,
-                                                           (void *)sti->store->cb.item_select.data);
-                       elm_store_item_update(sti);
-                    }
+                  sti->item = elm_genlist_item_append(st->genlist,
+                                                      itc,
+                                                      sti,
+                                                      NULL,
+                                                      ELM_GENLIST_ITEM_NONE,
+                                                      (Evas_Smart_Cb)sti->store->cb.item_select.func,
+                                                      (void *)sti->store->cb.item_select.data);
                }
           }
      }
 }
 
 static void
-_item_free(Elm_Store_Item *sti)
-{
-   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
-   elm_store_item_del(sti);
-}
-
-static void
 _store_free(Elm_Store *st)
 {
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-
    Elm_Store_DBsystem *std = (Elm_Store_DBsystem *)st;
-   eina_stringshare_del(std->p_db);
-   elm_store_free(st);
+   if(std->p_db) eina_stringshare_del(std->p_db);
 }
 
 /**
@@ -1990,18 +1727,8 @@ elm_store_dbsystem_new(void)
 EAPI void
 elm_store_item_count_set(Elm_Store *st, int count)
 {
-   EINA_SAFETY_ON_NULL_RETURN(st);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-
    st->item_count = count;
-   if (count > 0)
-     {
-        st->multi_load = EINA_TRUE;
-     }
-   else
-     {
-        st->multi_load = EINA_FALSE;
-     }
 }
 
 
@@ -2017,9 +1744,7 @@ elm_store_item_count_set(Elm_Store *st, int count)
 EAPI void
 elm_store_item_select_func_set(Elm_Store *st, Elm_Store_Item_Select_Cb func, const void *data)
 {
-   EINA_SAFETY_ON_NULL_RETURN(st);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-
    st->cb.item_select.func = func;
    st->cb.item_select.data = (void *)data;
 }
@@ -2036,9 +1761,7 @@ elm_store_item_select_func_set(Elm_Store *st, Elm_Store_Item_Select_Cb func, con
 EAPI void
 elm_store_item_sort_func_set(Elm_Store *st, Elm_Store_Item_Sort_Cb func, const void *data)
 {
-   EINA_SAFETY_ON_NULL_RETURN(st);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-
    st->cb.item_sort.func = func;
    st->cb.item_sort.data = (void *)data;
 }
@@ -2055,9 +1778,7 @@ elm_store_item_sort_func_set(Elm_Store *st, Elm_Store_Item_Sort_Cb func, const v
 EAPI void
 elm_store_item_free_func_set(Elm_Store *st, Elm_Store_Item_Free_Cb func, const void *data)
 {
-   EINA_SAFETY_ON_NULL_RETURN(st);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
-
    st->cb.item_free.func = func;
    st->cb.item_free.data = (void *)data;
 }
@@ -2073,58 +1794,26 @@ elm_store_item_free_func_set(Elm_Store *st, Elm_Store_Item_Free_Cb func, const v
 EAPI int
 elm_store_item_index_get(const Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(sti, -1);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return -1;
    Elm_Store *st = sti->store;
 
    if (st->live)
      {
         int index = 0;
-        Eina_List *l;
-        Eina_List *l_next;
-        Eina_List *header_list;
-
-        EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+        if (st->genlist)
           {
-             if (header_list)
+             Elm_Genlist_Item *gen_item = elm_genlist_first_item_get(st->genlist);
+             while (gen_item)
                {
-                  Elm_Store_Item *temp_sti = eina_list_nth(header_list, 0);
-                  if(temp_sti && temp_sti->item_info && sti->item_info)
-                    {
-                       if (sti->item_info->group_index == temp_sti->item_info->group_index)
-                         {
-                            Eina_List *in_l;
-                            Eina_List *in_l_next;
-                            Elm_Store_Item *comp_item;
-
-                            EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, comp_item)
-                              {
-                                 if(comp_item)
-                                   {
-                                      if (comp_item->item_info->index == sti->item_info->index)
-                                        {
-                                           return index;
-                                        }
-                                      else
-                                        {
-                                           index++;
-                                        }
-                                   }
-                              }
-                         }
-                       else
-                         {
-                            index = index + eina_list_count(header_list);
-                         }
-                    }
+                  Elm_Store_Item *item = elm_genlist_item_data_get(gen_item);
+                  if (item == sti) return index;
+                  gen_item = elm_genlist_item_next_get(gen_item);
+                  index++;
                }
           }
-        return -1;
-     }
-   else
-     {
-        return -1;
+        else return -1;
      }
+   else return -1;
 }
 
 /**
@@ -2138,68 +1827,26 @@ elm_store_item_index_get(const Elm_Store_Item *sti)
 EAPI int
 elm_store_item_data_index_get(const Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(sti, -1);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return -1;
    Elm_Store *st = sti->store;
 
    if (st->live)
      {
-        if (sti->item_info->item_type == ELM_GENLIST_ITEM_NONE)
+        int index = 0;
+        Elm_Genlist_Item *gen_item = elm_genlist_first_item_get(st->genlist);
+        while (gen_item)
           {
-             int index = 0;
-             int group_item_count = 0;
-             Eina_List *l;
-             Eina_List *l_next;
-             Eina_List *header_list;
-
-             EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+             Elm_Store_Item *item = elm_genlist_item_data_get(gen_item);
+             if (item && item->item_info->item_type != ELM_GENLIST_ITEM_GROUP)
                {
-                  if (header_list)
-                    {
-                       Elm_Store_Item *temp_sti = eina_list_nth(header_list, 0);
-                       if(temp_sti && temp_sti->item_info && sti->item_info)
-                         {
-
-                            if(temp_sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP)
-                              {
-                                 group_item_count++;
-                              }
-
-                            if (temp_sti->item_info->group_index == sti->item_info->group_index)
-                              {
-                                 Eina_List *in_l;
-                                 Eina_List *in_l_next;
-                                 Elm_Store_Item *comp_item;
-
-                                 EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, comp_item)
-                                   {
-                                      if(comp_item)
-                                        {
-                                           if (comp_item->item_info->index == sti->item_info->index)
-                                             {
-                                                return (index - group_item_count);
-                                             }
-                                           else
-                                             {
-                                                index++;
-                                             }
-                                        }
-                                   }
-                              }
-                         }
-                       else
-                         {
-                            index = index + eina_list_count(header_list);
-                         }
-                    }
+                  if(item == sti) return index;
+                  index++;
                }
+             gen_item = elm_genlist_item_next_get(gen_item);
           }
         return -1;
      }
-   else
-     {
-        return -1;
-     }
+   else return -1;
 }
 
 /**
@@ -2235,15 +1882,17 @@ elm_store_dbsystem_db_set(Elm_Store *store, void *p_db)
    Elm_Store_DBsystem *std = (Elm_Store_DBsystem *)store;
    if (!EINA_MAGIC_CHECK(store, ELM_STORE_MAGIC)) return;
    if (!EINA_MAGIC_CHECK(std, ELM_STORE_DBSYSTEM_MAGIC)) return;
-
-   std->p_db = p_db;
-
    if (store->list_th)
      {
         ecore_thread_cancel(store->list_th);
         store->list_th = NULL;
      }
-   store->list_th = ecore_thread_feedback_run(_list_do, _list_update, _list_end, _list_cancel, store, EINA_TRUE);
+   std->p_db = p_db;
+   store->list_th = ecore_thread_feedback_run(_list_do,
+                                              _list_update,
+                                              _list_end,
+                                              _list_cancel,
+                                              store, EINA_TRUE);
 }
 
 /**
@@ -2258,7 +1907,6 @@ elm_store_dbsystem_db_set(Elm_Store *store, void *p_db)
 EAPI Elm_Store_Item *
 elm_store_item_add(Elm_Store *st, Elm_Store_Item_Info *info)
 {
-   EINA_SAFETY_ON_NULL_RETURN_VAL(st, NULL);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return NULL;
    EINA_SAFETY_ON_NULL_RETURN_VAL(info, NULL);
    Elm_Store_Item *sti;
@@ -2266,10 +1914,8 @@ elm_store_item_add(Elm_Store *st, Elm_Store_Item_Info *info)
 
    sti = calloc(1, sizeof(Elm_Store_Item));
    if (!sti) return NULL;
-
    LKI(sti->lock);
    EINA_MAGIC_SET(sti, ELM_STORE_ITEM_MAGIC);
-
    sti->store = st;
    sti->item_info = info;
    sti->fetched = EINA_FALSE;
@@ -2281,25 +1927,16 @@ elm_store_item_add(Elm_Store *st, Elm_Store_Item_Info *info)
         itc->func.label_get = (GenlistItemLabelGetFunc)_item_label_get;
         itc->func.icon_get = (GenlistItemIconGetFunc)_item_icon_get;
         itc->func.state_get = NULL;
-        itc->func.del = NULL;
+        itc->func.del = (GenlistItemDelFunc)_item_del;
      }
 
    if (st->live)
      {
-        if (sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP)
-          {
-             _group_item_append(sti, itc);
-          }
-        else
-          {
-             _normal_item_append(sti, itc);
-          }
+        if (sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP) _group_item_append(sti, itc);
+        else _normal_item_append(sti, itc);
         return sti;
      }
-   else
-     {
-        return NULL;
-     }
+   else return NULL;
 }
 
 /**
@@ -2312,35 +1949,16 @@ elm_store_item_add(Elm_Store *st, Elm_Store_Item_Info *info)
 EAPI void
 elm_store_visible_items_update(Elm_Store *st)
 {
-   EINA_SAFETY_ON_NULL_RETURN(st);
    if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
 
    Eina_List *realized_list = elm_genlist_realized_items_get(st->genlist);
-   if(realized_list)
+   Elm_Genlist_Item *item = eina_list_data_get(realized_list);
+   while (item)
      {
-        Eina_List *l;
-        Elm_Genlist_Item *it;
-        EINA_LIST_FOREACH(realized_list, l, it)
-          {
-             if(it)
-               {
-                  Elm_Store_Item *realized_sti = elm_genlist_item_data_get(it);
-                  int index = elm_store_item_index_get(realized_sti);
-                  if (index != -1)
-                    {
-                       if(realized_sti->fetched)
-                         {
-                            _item_unfetch(st, index);
-                         }
-                       _item_fetch(st, index);
-                       if (realized_sti->data) elm_genlist_item_update(realized_sti->item);
-                    }
-                  else
-                    {
-                       return;
-                    }
-               }
-          }
+        Elm_Store_Item *realized_sti = elm_genlist_item_data_get(item);
+        elm_store_item_update(realized_sti);
+        realized_list = eina_list_next(realized_list);
+        item = eina_list_data_get(realized_list);
      }
 }
 
@@ -2354,38 +1972,20 @@ elm_store_visible_items_update(Elm_Store *st)
 EAPI void
 elm_store_item_update(Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN(sti);
-   if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
    Elm_Store *st = sti->store;
 
-   int index = elm_store_item_index_get(sti);
-   if (index != -1)
+   Eina_List *find = NULL;
+   find = eina_list_data_find_list(st->always_fetched, sti);
+   if (find)
      {
-        if ((st->start_fetch_index <= index) && (index <= (st->start_fetch_index + st->cache_max)))
-          {
-             if (sti->fetched)
-               {
-                  _item_unfetch(st, index);
-               }
-             _item_fetch(st, index);
-
-             if(st->end_fetch_index < (st->total_item_count-1))
-               {
-                  if( (st->end_fetch_index - st->cache_max) == st->start_fetch_index)
-                    {
-                       _item_unfetch(st, (st->total_item_count-1));
-                    }
-                  else
-                    {
-                       st->end_fetch_index = (st->total_item_count-1);
-                    }
-               }
-             if(sti->data) elm_genlist_item_update(sti->item);
-          }
+        if (sti->data) _item_unfetch(sti);
+        _item_fetch(sti);
+        if (sti->realized) elm_genlist_item_update(sti->item);
      }
    else
      {
-        return;
+        find = eina_list_data_find_list(st->realized,sti);
+        if (find)      _item_realize(sti);
      }
 }
 
@@ -2399,121 +1999,55 @@ elm_store_item_update(Elm_Store_Item *sti)
 EAPI void
 elm_store_item_del(Elm_Store_Item *sti)
 {
-   EINA_SAFETY_ON_NULL_RETURN(sti);
    if (!EINA_MAGIC_CHECK(sti, ELM_STORE_ITEM_MAGIC)) return;
    Elm_Store *st = sti->store;
 
-   Eina_List *l;
-   Eina_List*l_next;
-   Eina_List *header_list;
-
    if (st->live)
      {
-        EINA_LIST_FOREACH_SAFE(st->header_items, l, l_next, header_list)
+        Eina_List *find = NULL;
+        find = eina_list_data_find_list(st->always_fetched, sti);
+        if (find) st->always_fetched = eina_list_remove_list(st->always_fetched, find);
+
+        Eina_Bool deleted = EINA_FALSE;
+        Elm_Genlist_Item *comp_item = elm_genlist_first_item_get(st->genlist);
+        while (!deleted && comp_item)
           {
-             if (header_list)
+             Elm_Store_Item *comp_sti = elm_genlist_item_data_get(comp_item);
+             if (comp_sti && (sti == comp_sti))
                {
-                  Elm_Store_Item *header_item = eina_list_nth(header_list, 0);
-                  if(header_item && header_item->item_info && sti->item_info)
+                  Elm_Genlist_Item *group_item = elm_genlist_item_parent_get(comp_item);
+                  if (group_item)
                     {
-
-                       if (header_item->item_info->group_index == sti->item_info->group_index)
+                       Elm_Store_Item *group_sti = elm_genlist_item_data_get(group_item);
+                       if (group_sti)
                          {
-                            Eina_Bool removed = EINA_FALSE;
-                            Eina_List *in_l;
-                            Eina_List *in_l_next;
-                            Elm_Store_Item *remove_sti;
-                            EINA_LIST_FOREACH_SAFE(header_list, in_l, in_l_next, remove_sti)
+                            if ((group_sti->first_item == comp_item) && (group_sti->last_item == comp_item))
                               {
-                                 if(remove_sti)
-                                   {
-                                      if (removed == EINA_TRUE)
-                                        {
-                                           remove_sti->item_info->index--;
-                                        }
-                                      else
-                                        {
-                                           if (remove_sti->item_info->index == sti->item_info->index)
-                                             {
-                                                if (remove_sti->fetched)
-                                                  {
-                                                     int index = elm_store_item_index_get(remove_sti);
-                                                     if (index != -1)
-                                                       {
-                                                          _item_unfetch(st, index);
-                                                       }
-                                                     else
-                                                       {
-                                                          return;
-                                                       }
-                                                  }
-                                                if (st->cb.item_free.func)
-                                                  {
-                                                     st->cb.item_free.func(st->cb.item_free.data, remove_sti->item_info);
-                                                     remove_sti->item_info = NULL;
-                                                  }
-
-                                                if (eina_list_count(header_list) == 1)
-                                                  {
-                                                     st->header_items = eina_list_remove(st->header_items, header_list);
-                                                     header_list = eina_list_free(header_list);
-                                                     st->total_item_count--;
-                                                     LKD(remove_sti->lock);
-                                                     elm_genlist_item_del(remove_sti->item);
-                                                     free(remove_sti);
-                                                     return;
-                                                  }
-                                                else
-                                                  {
-                                                     header_list = eina_list_remove(header_list, remove_sti);
-                                                     st->total_item_count--;
-                                                     LKD(remove_sti->lock);
-                                                     elm_genlist_item_del(remove_sti->item);
-                                                     free(remove_sti);
-                                                  }
-
-                                                if (eina_list_count(header_list) == 1)
-                                                  {
-                                                     Elm_Store_Item *t_sti = eina_list_nth(header_list, 0);
-                                                     if(t_sti && t_sti->item_info)
-                                                       {
-                                                          if (t_sti->item_info->item_type == ELM_GENLIST_ITEM_GROUP)
-                                                            {
-                                                               if (t_sti->fetched)
-                                                                 {
-                                                                    int index = elm_store_item_index_get(t_sti);
-                                                                    if (index != -1)
-                                                                      {
-                                                                         _item_unfetch(st, index);
-                                                                      }
-                                                                    else
-                                                                      {
-                                                                         return;
-                                                                      }
-                                                                 }
-                                                               if (st->cb.item_free.func)
-                                                                 {
-                                                                    st->cb.item_free.func(st->cb.item_free.data, t_sti->item_info);
-                                                                    t_sti->item_info = NULL;
-                                                                 }
-                                                               st->header_items = eina_list_remove(st->header_items, header_list);
-                                                               header_list = eina_list_free(header_list);
-                                                               st->total_item_count--;
-                                                               LKD(t_sti->lock);
-                                                               elm_genlist_item_del(t_sti->item);
-                                                               free(t_sti);
-                                                            }
-                                                       }
-                                                  }
-                                                removed = EINA_TRUE;
-                                             }
-                                        }
-                                   }
+                                 group_sti->realized = EINA_FALSE;
+                                 group_sti->first_item = NULL;
+                                 group_sti->last_item = NULL;
+                                 elm_genlist_item_del(group_item);
+                              }
+                            else if ((group_sti->first_item == comp_item) && (group_sti->last_item != comp_item))
+                              {
+                                 Elm_Genlist_Item *next_item = elm_genlist_item_next_get(comp_item);
+                                 group_sti->first_item = next_item;
+                              }
+                            else if ((group_sti->first_item != comp_item) && (group_sti->last_item == comp_item))
+                              {
+                                 Elm_Genlist_Item *prev_item = elm_genlist_item_prev_get(comp_item);
+                                 group_sti->last_item = prev_item;
                               }
                          }
                     }
+                  elm_genlist_item_del(comp_sti->item);
+                  deleted = EINA_TRUE;
+                  break;
                }
+             comp_item = elm_genlist_item_next_get(comp_item);
           }
+
+        if(!deleted) printf(" Not deleted because it does not existed in the genlist \n");
      }
 }