update layout when gallery view is shown 18/39618/2
authorJehun Lim <jehun.lim@samsung.com>
Tue, 19 May 2015 12:17:21 +0000 (21:17 +0900)
committerJehun Lim <jehun.lim@samsung.com>
Wed, 20 May 2015 11:12:10 +0000 (20:12 +0900)
Change-Id: I9b2cd5286625a265da648471d48b3371c4333dcb
Signed-off-by: Jehun Lim <jehun.lim@samsung.com>
include/view/gallery-view/gallery_view.h
include/view/gallery-view/layout_all.h
include/view/gallery-view/layout_events.h
include/view/gallery-view/layout_folder.h
src/main.cpp
src/view/gallery-view/gallery_view.cpp
src/view/gallery-view/layout_all.cpp
src/view/gallery-view/layout_events.cpp
src/view/gallery-view/layout_folder.cpp

index 8e2f735..115dabe 100644 (file)
@@ -72,17 +72,20 @@ private:
 protected:
        virtual void t_OnShow(void);
        virtual void t_OnHide(void);
+       virtual void t_OnUpdate(void *data);
        virtual void t_OnPause(void);
        virtual void t_OnResume(void);
 
 private:
-       static void sm_CbLayoutShown(void *cookie, CBaseLayout *pBaseLayout);
        static void sm_CbAllLayoutFocus(void *cookie);
        static void sm_CbAllLayoutSort(void *cookie, int sort);
        static void sm_CbAllLayoutHide(void *cookie);
        static void sm_CbGetSignalFromLayout(void *cookie, int sig);
        static Eina_List *sm_CbGetMediaList(void *cookie);
 
+       static void sm_CbLayoutShown(void *cookie, CBaseLayout *pBaseLayout);
+       void m_OnLayoutShown(const char *id);
+
        static void sm_CbCtxPopupSelected(void *cookie, CContextPopup *instance, const char *text);
        void m_OnCtxPopupSelected(CContextPopup *instance, const char *text);
 
@@ -100,6 +103,7 @@ private:
        void m_DrawContentArea(int ltype);
 
        void m_FocusLayout(void);
+       void m_UpdateLayout(void);
        void m_SortLayout(void);
        void m_SourceChange(void);
 
index c19d6a0..437e22e 100644 (file)
@@ -50,10 +50,16 @@ private:
        void m_SendResultToApp(const char *filepath);
        void m_CreateCtxtMenu(void);
 
+       Elm_Object_Item *m_FindCurrentItem(void);
+
        Eina_List *m_SortList(void);
 
+       void m_AddGridItemCallback(Elm_Object_Item *it);
+       void m_DelGridItemCallback(Elm_Object_Item *it);
+
        Evas_Object *m_DrawGengrid(Evas_Object *layout);
        bool m_DrawGengridItems(void);
+       void m_UpdateGengridItems(void);
 
 public:
        CAllLayout(const char *pLayoutId) : CBaseLayout(pLayoutId),
index f52e3dd..f93bc19 100644 (file)
@@ -51,8 +51,14 @@ private:
        int m_GetEventCount(Eina_List *event_list);
        int m_GetMediaCount(Eina_List *media_list, int type);
 
+       void m_AddGridItemCallback(Elm_Object_Item *it);
+       void m_DelGridItemCallback(Elm_Object_Item *it);
+
        Evas_Object *m_DrawGengrid(Evas_Object *layout);
        bool m_DrawGengridItems(void);
+       void m_UpdateGengridItems(void);
+
+       Elm_Object_Item *m_FindCurrentItem(void);
 
        Eina_List *m_SortList(void);
 
index 877487a..6660db7 100644 (file)
@@ -51,6 +51,8 @@ private:
        Evas_Object *m_DrawGengrid(Evas_Object *layout);
        bool m_DrawGengridItems(void);
 
+       Elm_Object_Item *m_FindCurrentItem(void);
+
        Eina_List *m_SortList(void);
 
 public:
index 5dadb04..c230a69 100644 (file)
@@ -86,7 +86,7 @@ private:
 private:
        static void sm_CbPushView(void *cookie,
                        CBaseView *pHideView, CBaseView *pShowView);
-       static void sm_CbPopview(void *cookie,
+       static void sm_CbPopView(void *cookie,
                        const char *szDestroyViewId, CBaseView *pShowView);
 
        void m_GetData(void);
@@ -133,6 +133,15 @@ void CGalleryApp::sm_CbPushView(void *cookie,
        }
 }
 
+void CGalleryApp::sm_CbPopView(void *cookie,
+               const char *szDestroyViewId, CBaseView *pShowView)
+{
+       const char *viewId = pShowView->ViewId();
+
+       if (!strcmp(viewId, VIEW_GALLERY))
+               CViewMgr::GetInstance()->UpdateView(viewId, NULL);
+}
+
 void CGalleryApp::m_GetData(void)
 {
        char *view;
@@ -337,7 +346,7 @@ bool CGalleryApp::OnCreate(void)
        CViewMgr::SCallback cb;
        cb.cookie     = this;
        cb.cbPushView = sm_CbPushView;
-       cb.cbPopView  = NULL;
+       cb.cbPopView  = sm_CbPopView;
        m->pViewMgr->AddCallback(&cb);
 
        CSortMgr::Initialize();
index c58b2eb..4c95170 100644 (file)
@@ -216,6 +216,27 @@ void CGalleryView::m_OnCtxPopupSelected(CContextPopup *instance, const char *tex
        }
 }
 
+void CGalleryView::m_UpdateLayout(void)
+{
+       m->ld->sort = m->sort_type;
+
+       switch (m->current_layout) {
+       case E_LAYOUT_ALL:
+               m->pAllLayout->Update(m->ld);
+               break;
+       case E_LAYOUT_EVENTS:
+               m->pEventLayout->Update(m->ld);
+               break;
+       case E_LAYOUT_FOLDER:
+               m->pFolderLayout->Update(m->ld);
+               break;
+       default:
+               break;
+       }
+
+       m->ld->modified = EINA_FALSE;
+}
+
 void CGalleryView::m_SortLayout(void)
 {
        switch (m->current_layout) {
@@ -460,21 +481,25 @@ void CGalleryView::sm_CbAllLayoutHide(void *cookie)
 
 void CGalleryView::sm_CbLayoutShown(void *cookie, CBaseLayout *pBaseLayout)
 {
-       const char *id;
-       SGalleryView *m;
+       CGalleryView *root = (CGalleryView *)cookie;
 
-       m = (SGalleryView *)cookie;
+       if (root)
+               root->m_OnLayoutShown(pBaseLayout->LayoutId());
+}
 
-       if (!m->ld->modified)
+void CGalleryView::m_OnLayoutShown(const char *id)
+{
+       if (!id)
                return;
 
-       id = pBaseLayout->LayoutId();
        if (!strcmp(id, LAYOUT_ALL))
-               m->pAllLayout->Update(m->ld);
+               m->current_layout = E_LAYOUT_ALL;
        else if (!strcmp(id, LAYOUT_EVENT))
-               m->pEventLayout->Update(m->ld);
+               m->current_layout = E_LAYOUT_EVENTS;
        else if (!strcmp(id, LAYOUT_FOLDER))
-               m->pFolderLayout->Update(m->ld);
+               m->current_layout = E_LAYOUT_FOLDER;
+
+       m_UpdateLayout();
 }
 
 Eina_List *CGalleryView::sm_CbGetMediaList(void *cookie)
@@ -533,7 +558,6 @@ bool CGalleryView::Create(void *data, Evas_Object *eoBase)
        m->pEventLayout = new CEventLayout(LAYOUT_EVENT);
        m->pEventLayout->Create(m->pLayoutMgr, m->ld);
        m->pEventLayout->SetFocusCallback(sm_CbAllLayoutFocus, m);
-       m->pEventLayout->SetSortCallback(sm_CbAllLayoutSort, m);
        m->pEventLayout->SetSendSigCallback(sm_CbGetSignalFromLayout, m);
        m->pEventLayout->SetMediaListCallback(sm_CbGetMediaList, m);
        m->pLayoutMgr->AddLayout(m->pEventLayout);
@@ -541,12 +565,11 @@ bool CGalleryView::Create(void *data, Evas_Object *eoBase)
        m->pFolderLayout = new CFolderLayout(LAYOUT_FOLDER);
        m->pFolderLayout->Create(m->pLayoutMgr, m->ld);
        m->pFolderLayout->SetFocusCallback(sm_CbAllLayoutFocus, m);
-       m->pFolderLayout->SetSortCallback(sm_CbAllLayoutSort, m);
        m->pFolderLayout->SetSendSigCallback(sm_CbGetSignalFromLayout, m);
        m->pFolderLayout->SetMediaListCallback(sm_CbGetMediaList, m);
        m->pLayoutMgr->AddLayout(m->pFolderLayout);
 
-       m->pLayoutMgr->RegisterCallback(CLayoutMgr::CONDITION_LAYOUT_SHOW_NOTIFY, sm_CbLayoutShown, m);
+       m->pLayoutMgr->RegisterCallback(CLayoutMgr::CONDITION_LAYOUT_SHOW_NOTIFY, sm_CbLayoutShown, this);
 
        if (!elm_layout_file_set(base, EDJEFILE, GRP_GALLERY_VIEW))
                goto error;
@@ -662,6 +685,13 @@ void CGalleryView::t_OnHide(void)
        t_OnPause();
 }
 
+void CGalleryView::t_OnUpdate(void *data)
+{
+       ASSERT(m);
+
+       m_UpdateLayout();
+}
+
 void CGalleryView::t_OnPause(void)
 {
        ASSERT(m);
index 99fe22a..366ac55 100644 (file)
@@ -46,6 +46,7 @@ struct SAllLayout {
 
        Evas_Object *grid;
        Elm_Object_Item *current_item;
+       CMediaInfo *current_info;
 
        struct arg_list *arglist;
        Eina_List *media_list;
@@ -272,8 +273,6 @@ void CAllLayout::m_OnGridActivated(Elm_Object_Item *it,
                }
        }
 
-       m->current_item = it;
-
        elm_gengrid_item_selected_set(it, EINA_FALSE);
 }
 
@@ -292,6 +291,29 @@ void CAllLayout::m_OnGridItemFocused(Elm_Object_Item *it,
                return;
 
        m->current_item = (Elm_Object_Item *)it;
+       m->current_info = (CMediaInfo *)elm_object_item_data_get(it);
+}
+
+void CAllLayout::m_AddGridItemCallback(Elm_Object_Item *it)
+{
+       if (!it)
+               return;
+
+       elm_object_item_signal_callback_add(it, "item_clicked",
+                       "edc", sm_CbGridActivated, this);
+       elm_object_item_signal_callback_add(it, "item_focused",
+                       "edc", sm_CbGridItemFocused, this);
+}
+
+void CAllLayout::m_DelGridItemCallback(Elm_Object_Item *it)
+{
+       if (!it)
+               return;
+
+       elm_object_item_signal_callback_del(it, "item_clicked",
+                       "edc", sm_CbGridActivated);
+       elm_object_item_signal_callback_del(it, "item_focused",
+                       "edc", sm_CbGridItemFocused);
 }
 
 Evas_Object *CAllLayout::m_DrawGengrid(Evas_Object *layout)
@@ -374,9 +396,56 @@ bool CAllLayout::m_DrawGengridItems(void)
                        util_get_media_count(m->media_list, MEDIA_CONTENT_TYPE_VIDEO));
        elm_object_part_text_set(Layout(), PART_VIDEOCOUNT, buf);
 
+       m->current_item = m_FindCurrentItem();
+
        return true;
 }
 
+void CAllLayout::m_UpdateGengridItems(void)
+{
+       Eina_List *realized_list, *l;
+       Elm_Object_Item *it;
+       void *obj;
+
+       realized_list = elm_gengrid_realized_items_get(m->grid);
+
+       EINA_LIST_FOREACH(realized_list, l, obj) {
+               it = (Elm_Object_Item *)obj;
+
+               m_DelGridItemCallback(it);
+
+               elm_gengrid_item_update(it);
+               m_AddGridItemCallback(it);
+       }
+}
+
+Elm_Object_Item *CAllLayout::m_FindCurrentItem(void)
+{
+       CMediaInfo *minfo;
+       Elm_Object_Item *first_item;
+       Elm_Object_Item *item;
+
+       first_item = elm_gengrid_first_item_get(m->grid);
+
+       if (!m->current_info)
+               return first_item;
+
+       minfo = NULL;
+       for (item = first_item; item; item = elm_gengrid_item_next_get(item)) {
+               minfo = (CMediaInfo *)elm_object_item_data_get(item);
+               if (!minfo)
+                       continue;
+
+               if (!strcmp(minfo->Name(), m->current_info->Name()))
+                       break;
+       }
+
+       if (!item)
+               item = first_item;
+
+       return item;
+}
+
 Eina_List *CAllLayout::m_SortList(void)
 {
        Eina_List *list;
@@ -445,41 +514,47 @@ void CAllLayout::Update(struct layout_data *ld)
 {
        ASSERT(m);
 
-       m->arglist = ld->arglist;
-       m->sort = ld->sort;
-       m->media_list = eina_list_clone(ld->media_list);
-       m->media_list = m_SortList();
+       if (ld->modified) {
+               if (!ld->media_list) {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, _(TEXT_NOCONTENTAREA1));
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, _(TEXT_NOCONTENTAREA2));
 
-       if (!ld->media_list) {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1,
-                       _(TEXT_NOCONTENTAREA1));
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2,
-                       _(TEXT_NOCONTENTAREA2));
+                       return;
+               } else {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, "");
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, "");
+               }
 
-               return;
-       } else {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1, "");
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2, "");
-       }
+               if (ld->path) {
+                       elm_object_part_text_set(Layout(),
+                               PART_CATEGORY_TITLE, ld->path);
+                       free(ld->path);
+                       ld->path = NULL;
+               } else {
+                       elm_object_part_text_set(Layout(),
+                               PART_CATEGORY_TITLE, "");
+               }
 
-       if (!m_DrawGengridItems())
-               return;
+               m->arglist = ld->arglist;
+               m->sort = ld->sort;
+               m->media_list = eina_list_clone(ld->media_list);
+               m->media_list = m_SortList();
+               m->current_info = NULL;
 
-       if (ld->path) {
-               elm_object_part_text_set(Layout(),
-                       PART_CATEGORY_TITLE, ld->path);
-               free(ld->path);
-               ld->path = NULL;
+               m_DrawGengridItems();
        } else {
-               elm_object_part_text_set(Layout(),
-                       PART_CATEGORY_TITLE, "");
-       }
+               if (ld->sort != m->sort) {
+                       m->sort = ld->sort;
+                       m->media_list = m_SortList();
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
+                       m_DrawGengridItems();
+               } else
+                       m_UpdateGengridItems();
+       }
 }
 
 void CAllLayout::SetHideCallback(void(*cb)(void *cookie), void *cookie)
@@ -558,8 +633,6 @@ bool CAllLayout::Create(CLayoutMgr *lmgr, void *data)
 
        elm_object_part_content_set(layout, PART_CONTENTAREA, m->grid);
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
-
        if (ld->path) {
                buf = ld->path;
                elm_object_part_text_set(layout,
@@ -634,7 +707,6 @@ void CAllLayout::OnSKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_SKey_D
                                m->Sigcb->cb(m->Sigcb->cookie, E_RETURN);
                                break;
                        case E_LAYOUT_EVENTS:
-                               m->ld->modified = EINA_FALSE;
                                m->pLayoutMgr->Show(layout_type[E_LAYOUT_EVENTS]);
 
                                pEventLayout = (CEventLayout *)m->pLayoutMgr->Layout();
@@ -642,7 +714,6 @@ void CAllLayout::OnSKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_SKey_D
 
                                break;
                        case E_LAYOUT_FOLDER:
-                               m->ld->modified = EINA_FALSE;
                                m->pLayoutMgr->Show(layout_type[E_LAYOUT_FOLDER]);
 
                                pFolderLayout = (CFolderLayout *)m->pLayoutMgr->Layout();
@@ -687,10 +758,7 @@ void CAllLayout::OnRealized(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
        switch (id) {
        case ALL_GRID:
-               elm_object_item_signal_callback_add(item, "item_clicked",
-                       "edc", sm_CbGridActivated, this);
-               elm_object_item_signal_callback_add(item, "item_focused",
-                       "edc", sm_CbGridItemFocused, this);
+               m_AddGridItemCallback(item);
                break;
        default:
                break;
@@ -701,10 +769,7 @@ void CAllLayout::OnUnrealized(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
        switch (id) {
        case ALL_GRID:
-               elm_object_item_signal_callback_del(item, "item_clicked",
-                       "edc", sm_CbGridActivated);
-               elm_object_item_signal_callback_del(item, "item_focused",
-                       "edc", sm_CbGridItemFocused);
+               m_DelGridItemCallback(item);
                break;
        default:
                break;
index 1b2cb77..543a9d6 100644 (file)
@@ -34,11 +34,6 @@ struct SFocusCallbackPair {
        void *cookie;
 };
 
-struct SSortCallbackPair {
-       void (*cb)(void *cookie, int sort);
-       void *cookie;
-};
-
 struct SSigCallbackPair {
        void(*cb)(void *cookie, int sig);
        void *cookie;
@@ -54,21 +49,19 @@ struct SEventLayout {
 
        Evas_Object *grid;
        Elm_Object_Item *current_item;
+       CEventInfo *current_info;
 
-       struct arg_list *arglist;
        Eina_List *media_list;
        Eina_List *event_list;
        int sort;
 
        Eina_Bool direct_launch;
-       Eina_Bool layout_2ndview;
 
        struct layout_data *ld;
 
        CLayoutMgr *pLayoutMgr;
 
        SFocusCallbackPair *FocusCb;
-       SSortCallbackPair *SortCb;
        SSigCallbackPair *SigCb;
        SMediaCallbackPair *MediaCb;
 };
@@ -256,18 +249,14 @@ void CEventLayout::m_OnGridActivated(Elm_Object_Item *it,
                snprintf(buf, sizeof(buf), "< %s", einfo->Name());
 
                m->ld->media_list = einfo->MediaList();
-               m->ld->arglist = m->arglist;
                m->ld->path = strdup(buf);
                m->ld->sort = m->sort;
                m->ld->prev_layout = E_LAYOUT_EVENTS;
                m->ld->modified = EINA_TRUE;
 
                m->pLayoutMgr->Show(layout_type[E_LAYOUT_ALL]);
-               m->layout_2ndview = EINA_TRUE;
 
                m->FocusCb->cb(m->FocusCb->cookie);
-
-               m->current_item = it;
        }
 
        elm_gengrid_item_selected_set(it, EINA_FALSE);
@@ -288,6 +277,29 @@ void CEventLayout::m_OnGridItemFocused(Elm_Object_Item *it,
                return;
 
        m->current_item = (Elm_Object_Item *)it;
+       m->current_info = (CEventInfo *)elm_object_item_data_get(it);
+}
+
+void CEventLayout::m_AddGridItemCallback(Elm_Object_Item *it)
+{
+       if (!it)
+               return;
+
+       elm_object_item_signal_callback_add(it, "item_clicked",
+                       "edc", sm_CbGridActivated, this);
+       elm_object_item_signal_callback_add(it, "item_focused",
+                       "edc", sm_CbGridItemFocused, this);
+}
+
+void CEventLayout::m_DelGridItemCallback(Elm_Object_Item *it)
+{
+       if (!it)
+               return;
+
+       elm_object_item_signal_callback_del(it, "item_clicked",
+                       "edc", sm_CbGridActivated);
+       elm_object_item_signal_callback_del(it, "item_focused",
+                       "edc", sm_CbGridItemFocused);
 }
 
 int CEventLayout::m_GetEventCount(Eina_List *event_list)
@@ -422,6 +434,8 @@ bool CEventLayout::m_DrawGengridItems(void)
                        MEDIA_CONTENT_TYPE_VIDEO));
        elm_object_part_text_set(Layout(), PART_VIDEOCOUNT, buf);
 
+       m->current_item = m_FindCurrentItem();
+
        return true;
 
 error:
@@ -430,6 +444,51 @@ error:
        return false;
 }
 
+void CEventLayout::m_UpdateGengridItems(void)
+{
+       Eina_List *realized_list, *l;
+       Elm_Object_Item *it;
+       void *obj;
+
+       realized_list = elm_gengrid_realized_items_get(m->grid);
+
+       EINA_LIST_FOREACH(realized_list, l, obj) {
+               it = (Elm_Object_Item *)obj;
+
+               m_DelGridItemCallback(it);
+
+               elm_gengrid_item_update(it);
+               m_AddGridItemCallback(it);
+       }
+}
+
+Elm_Object_Item *CEventLayout::m_FindCurrentItem(void)
+{
+       CEventInfo *einfo;
+       Elm_Object_Item *first_item;
+       Elm_Object_Item *item;
+
+       first_item = elm_gengrid_first_item_get(m->grid);
+
+       if (!m->current_info)
+               return first_item;
+
+       einfo = NULL;
+       for (item = first_item; item; item = elm_gengrid_item_next_get(item)) {
+               einfo = (CEventInfo *)elm_object_item_data_get(item);
+               if (!einfo)
+                       continue;
+
+               if (!strcmp(einfo->Name(), m->current_info->Name()))
+                       break;
+       }
+
+       if (!item)
+               item = first_item;
+
+       return item;
+}
+
 Eina_List *CEventLayout::m_SortList(void)
 {
        Eina_List *list;
@@ -491,11 +550,6 @@ void CEventLayout::Focus(void)
 {
        ASSERT(m);
 
-       if (m->layout_2ndview) {
-               m->FocusCb->cb(m->FocusCb->cookie);
-               return;
-       }
-
        elm_object_focus_set(m->grid, EINA_TRUE);
        elm_object_item_focus_set(m->current_item, EINA_TRUE);
 }
@@ -506,11 +560,6 @@ void CEventLayout::Sort(int sort)
 
        m->sort = sort;
 
-       if (m->layout_2ndview) {
-               m->SortCb->cb(m->FocusCb->cookie, sort);
-               return;
-       }
-
        m->event_list = m_SortList();
        m_DrawGengridItems();
 }
@@ -524,31 +573,36 @@ void CEventLayout::Update(struct layout_data *ld)
                return;
        }
 
-       m->arglist = ld->arglist;
-       m->sort = ld->sort;
-       m->event_list = eina_list_clone(ld->media_list);
-       m->event_list = m_SortList();
+       if (ld->modified) {
+               if (!ld->media_list) {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, _(TEXT_NOCONTENTAREA1));
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, _(TEXT_NOCONTENTAREA2));
 
-       if (!ld->media_list) {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1,
-                       _(TEXT_NOCONTENTAREA1));
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2,
-                       _(TEXT_NOCONTENTAREA2));
+                       return;
+               } else {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, "");
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, "");
+               }
 
-               return;
-       } else {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1, "");
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2, "");
-       }
+               m->sort = ld->sort;
+               m->event_list = eina_list_clone(ld->media_list);
+               m->event_list = m_SortList();
+               m->current_info = NULL;
 
-       if (!m_DrawGengridItems())
-               return;
+               m_DrawGengridItems();
+       } else {
+               if (ld->sort != m->sort) {
+                       m->sort = ld->sort;
+                       m->event_list = m_SortList();
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
+                       m_DrawGengridItems();
+               } else
+                       m_UpdateGengridItems();
+       }
 }
 
 void CEventLayout::SetFocusCallback(void (*cb)(void *cookie), void *cookie)
@@ -565,20 +619,6 @@ void CEventLayout::SetFocusCallback(void (*cb)(void *cookie), void *cookie)
        m->FocusCb = fcb;
 }
 
-void CEventLayout::SetSortCallback(void (*cb)(void *cookie, int sort), void *cookie)
-{
-       ASSERT(m);
-
-       SSortCallbackPair *scb = new SSortCallbackPair;
-       if (!scb)
-               return;
-
-       scb->cb = cb;
-       scb->cookie = cookie;
-
-       m->SortCb = scb;
-}
-
 void CEventLayout::SetSendSigCallback(void (*cb)(void *cookie, int sig), void *cookie)
 {
        ASSERT(m);
@@ -642,7 +682,6 @@ bool CEventLayout::Create(CLayoutMgr *lmgr, void *data)
        ld = (struct layout_data *)data;
 
        m->pLayoutMgr = lmgr;
-       m->arglist = ld->arglist;
        m->sort = ld->sort;
        m->event_list = eina_list_clone(ld->media_list);
        m->event_list = m_SortList();
@@ -656,8 +695,6 @@ bool CEventLayout::Create(CLayoutMgr *lmgr, void *data)
 
        elm_object_part_content_set(layout, PART_CONTENTAREA, m->grid);
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
-
        CBaseLayout::Create(layout);
 
        return true;
@@ -696,8 +733,6 @@ void CEventLayout::t_OnShow(void)
 
        elm_object_tree_focus_allow_set(Layout(), EINA_TRUE);
        elm_object_part_content_set(m->base, PART_CONTENTAREA, Layout());
-
-       m->layout_2ndview = EINA_FALSE;
 }
 
 void CEventLayout::t_OnHide(void)
@@ -754,10 +789,7 @@ void CEventLayout::OnRealized(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
        switch (id) {
        case EVENT_GRID:
-               elm_object_item_signal_callback_add(item, "item_clicked",
-                       "edc", sm_CbGridActivated, this);
-               elm_object_item_signal_callback_add(item, "item_focused",
-                       "edc", sm_CbGridItemFocused, this);
+               m_AddGridItemCallback(item);
                break;
        default:
                break;
@@ -768,10 +800,7 @@ void CEventLayout::OnUnrealized(int id, Evas_Object *obj, Elm_Object_Item *item)
 {
        switch (id) {
        case EVENT_GRID:
-               elm_object_item_signal_callback_del(item, "item_clicked",
-                       "edc", sm_CbGridActivated);
-               elm_object_item_signal_callback_del(item, "item_focused",
-                       "edc", sm_CbGridItemFocused);
+               m_DelGridItemCallback(item);
                break;
        default:
                break;
index 785b444..eeb28d4 100644 (file)
@@ -32,11 +32,6 @@ struct SFocusCallbackPair {
        void *cookie;
 };
 
-struct SSortCallbackPair {
-       void (*cb)(void *cookie, int sort);
-       void *cookie;
-};
-
 struct SSigCallbackPair {
        void(*cb)(void *cookie, int sig);
        void *cookie;
@@ -52,46 +47,19 @@ struct SFolderLayout{
 
        Evas_Object *grid;
        Elm_Object_Item *current_item;
+       CFolderInfo *current_info;
 
-       struct arg_list *arglist;
        Eina_List *folder_list;
        Eina_List *media_list;
        int sort;
 
-       Eina_Bool layout_2ndview;
-
        struct layout_data *ld;
 
        CLayoutMgr *pLayoutMgr;
 
        SFocusCallbackPair *FocusCb;
-       SSortCallbackPair *SortCb;
        SSigCallbackPair *Sigcb;
        SMediaCallbackPair *MediaCb;
-
-       SFolderLayout() {
-               base = NULL;
-               grid = NULL;
-               current_item = NULL;
-
-               arglist = NULL;
-               folder_list = NULL;
-               media_list = NULL;
-               sort = 0;
-
-               layout_2ndview = EINA_FALSE;
-
-               ld = NULL;
-
-               pLayoutMgr = NULL;
-
-               FocusCb = NULL;
-               SortCb = NULL;
-               Sigcb = NULL;
-               MediaCb = NULL;
-       }
-
-       ~SFolderLayout() {}
 };
 
 char *CFolderLayout::sm_CbGridTextGet(void *data, Evas_Object *obj, const char *part)
@@ -175,19 +143,15 @@ void CFolderLayout::m_OnGridActivated(Elm_Object_Item *it,
        snprintf(buf, sizeof(buf), "< %s", finfo->Name());
 
        m->ld->media_list = finfo->MediaList();
-       m->ld->arglist = m->arglist;
        m->ld->path = strdup(buf);
        m->ld->sort = m->sort;
        m->ld->prev_layout = E_LAYOUT_FOLDER;
        m->ld->modified = EINA_TRUE;
 
        m->pLayoutMgr->Show(layout_type[E_LAYOUT_ALL]);
-       m->layout_2ndview = EINA_TRUE;
 
        m->FocusCb->cb(m->FocusCb->cookie);
 
-       m->current_item = it;
-
        elm_gengrid_item_selected_set(it, EINA_FALSE);
 }
 
@@ -206,6 +170,7 @@ void CFolderLayout::m_OnGridItemFocused(Elm_Object_Item *it,
                return;
 
        m->current_item = (Elm_Object_Item *)it;
+       m->current_info = (CFolderInfo *)elm_object_item_data_get(it);
 }
 
 int CFolderLayout::m_GetMediaCount(Eina_List *list, int type)
@@ -305,9 +270,38 @@ bool CFolderLayout::m_DrawGengridItems(void)
                        MEDIA_CONTENT_TYPE_VIDEO));
        elm_object_part_text_set(Layout(), PART_VIDEOCOUNT, buf);
 
+       m->current_item = m_FindCurrentItem();
+
        return true;
 }
 
+Elm_Object_Item *CFolderLayout::m_FindCurrentItem(void)
+{
+       CFolderInfo *finfo;
+       Elm_Object_Item *first_item;
+       Elm_Object_Item *item;
+
+       first_item = elm_gengrid_first_item_get(m->grid);
+
+       if (!m->current_info)
+               return first_item;
+
+       finfo = NULL;
+       for (item = first_item; item; item = elm_gengrid_item_next_get(item)) {
+               finfo = (CFolderInfo *)elm_object_item_data_get(item);
+               if (!finfo)
+                       continue;
+
+               if (!strcmp(finfo->Name(), m->current_info->Name()))
+                       break;
+       }
+
+       if (!item)
+               item = first_item;
+
+       return item;
+}
+
 Eina_List *CFolderLayout::m_SortList(void)
 {
        Eina_List *list;
@@ -329,11 +323,6 @@ void CFolderLayout::Focus(void)
 {
        ASSERT(m);
 
-       if (m->layout_2ndview) {
-               m->FocusCb->cb(m->FocusCb->cookie);
-               return;
-       }
-
        elm_object_focus_set(m->grid, EINA_TRUE);
        elm_object_item_focus_set(m->current_item, EINA_TRUE);
 }
@@ -344,11 +333,6 @@ void CFolderLayout::Sort(int sort)
 
        m->sort = sort;
 
-       if (m->layout_2ndview) {
-               m->SortCb->cb(m->FocusCb->cookie, sort);
-               return;
-       }
-
        m->folder_list = m_SortList();
        m_DrawGengridItems();
 }
@@ -357,30 +341,34 @@ void CFolderLayout::Update(struct layout_data *ld)
 {
        ASSERT(m);
 
-       m->arglist = ld->arglist;
-       m->sort = ld->sort;
-       m->folder_list = eina_list_clone(ld->media_list);
-       m->folder_list = m_SortList();
+       if (ld->modified) {
+               if (!ld->media_list) {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, _(TEXT_NOCONTENTAREA1));
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, _(TEXT_NOCONTENTAREA2));
+                       return;
+               } else {
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA1, "");
+                       elm_object_part_text_set(Layout(),
+                               PART_NOCONTENTAREA2, "");
+               }
 
-       if (!ld->media_list) {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1,
-                       _(TEXT_NOCONTENTAREA1));
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2,
-                       _(TEXT_NOCONTENTAREA2));
-               return;
-       } else {
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA1, "");
-               elm_object_part_text_set(Layout(),
-                       PART_NOCONTENTAREA2, "");
-       }
+               m->sort = ld->sort;
+               m->folder_list = eina_list_clone(ld->media_list);
+               m->folder_list = m_SortList();
+               m->current_info = NULL;
 
-       if (!m_DrawGengridItems())
-               return;
+               m_DrawGengridItems();
+       } else {
+               if (ld->sort != m->sort) {
+                       m->sort = ld->sort;
+                       m->folder_list = m_SortList();
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
+                       m_DrawGengridItems();
+               }
+       }
 }
 
 void CFolderLayout::SetFocusCallback(void (*cb)(void *cookie), void *cookie)
@@ -397,20 +385,6 @@ void CFolderLayout::SetFocusCallback(void (*cb)(void *cookie), void *cookie)
        m->FocusCb = fcb;
 }
 
-void CFolderLayout::SetSortCallback(void (*cb)(void *cookie, int sort), void *cookie)
-{
-       ASSERT(m);
-
-       SSortCallbackPair *scb = new SSortCallbackPair;
-       if (!scb)
-               return;
-
-       scb->cb = cb;
-       scb->cookie = cookie;
-
-       m->SortCb = scb;
-}
-
 void CFolderLayout::SetSendSigCallback(void(*cb)(void *cookie, int sig), void *cookie)
 {
        ASSERT(m);
@@ -452,6 +426,8 @@ bool CFolderLayout::Create(CLayoutMgr *lmgr, void *data)
        if (!m)
                return false;
 
+       memset(m, 0, sizeof(*m));
+
        m->base = lmgr->Base();
        if (!m->base) {
                delete m;
@@ -472,7 +448,6 @@ bool CFolderLayout::Create(CLayoutMgr *lmgr, void *data)
        ld = (struct layout_data *)data;
 
        m->pLayoutMgr = lmgr;
-       m->arglist = ld->arglist;
        m->sort = ld->sort;
        m->folder_list = eina_list_clone(ld->media_list);
        m->folder_list = m_SortList();
@@ -486,8 +461,6 @@ bool CFolderLayout::Create(CLayoutMgr *lmgr, void *data)
 
        elm_object_part_content_set(layout, PART_CONTENTAREA, m->grid);
 
-       m->current_item = elm_gengrid_first_item_get(m->grid);
-
        CBaseLayout::Create(layout);
 
        return true;
@@ -526,8 +499,6 @@ void CFolderLayout::t_OnShow(void)
 
        elm_object_tree_focus_allow_set(Layout(), EINA_TRUE);
        elm_object_part_content_set(m->base, PART_CONTENTAREA, Layout());
-
-       m->layout_2ndview = EINA_FALSE;
 }
 
 void CFolderLayout::t_OnHide(void)