Fix bugs
[profile/tv/apps/native/filebrowser.git] / src / views / BaseView / FileGrid.cpp
index 18a40b3..191302b 100644 (file)
 #include <Elementary.h>
 #include <Eina.h>
 #include <Ecore.h>
-#include <utilX.h>
 #include <aul.h>
 #include "dbg.h"
 #include "i18n.h"
-#include "define.h" 
+#include "define.h"
 #include "common.h"
 
 #include <AppCommon.h>
 #include "Mediadata.h"
 #include "ExtNameInfo.h"
-#include "SortName.h"
+#include <SortMgr.h>
 #include "GengridItemClass.h"
 #include "InputHandler.h"
 #include "FileGrid.h"
@@ -125,6 +124,7 @@ void CFileGrid::sm_CbUnrealized(void *data, Evas_Object *obj, void *event_info)
 
 void CFileGrid::Action(void)
 {
+       _DBG();
        m->handle_itinfo = m->ctxt_itinfo;
        m_HandleSelection();
        m_DeleteContextView();
@@ -138,6 +138,7 @@ void CFileGrid::m_DeleteContextView(void)
 
 void CFileGrid::sm_CbSelectItem(void *data, Elm_Object_Item *it, const char *emission, const char *source)
 {
+       _DBG();
        CFileGrid* root = (CFileGrid*)data;
        SItemInfo *pItemInfo;
 
@@ -221,19 +222,15 @@ void CFileGrid::t_CreateFileGrid(void)
        grid = elm_gengrid_add(m->eoBase);
        if (!grid)
                return;
-       evas_object_size_hint_weight_set(grid,
-               EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        elm_gengrid_align_set(grid, 0, 0);
        elm_object_part_content_set(m->eoBase, FBR_PART_MEDIA_GRID, grid);
 
-
        Connect(grid);
 
        evas_object_smart_callback_add(grid, FBR_SIGNAL_REALIZED,      sm_CbRealized, this);
        evas_object_smart_callback_add(grid, FBR_SIGNAL_UNREALIZED,    sm_CbUnrealized, this);
-       elm_gengrid_item_size_set(grid,
-               elm_config_scale_get() * GENGRID_ITEM_SIZE_W,
-               elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
+       elm_gengrid_item_size_set(grid, elm_config_scale_get() * GENGRID_ITEM_SIZE_W, elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
 
        m->eoGrid = grid;
 
@@ -245,7 +242,7 @@ void CFileGrid::t_CreateFileGrid(void)
                _ERR(" elm_genlist_item_class_new failed ");
                return;
        }
-       
+
        evas_object_show(grid);
 }
 
@@ -265,7 +262,7 @@ void CFileGrid::t_Empty(bool sort_flag)
                m->pGengridItemClass = NULL;
        }
 
-       if (sort_flag == false) {
+       if (sort_flag == false && m->elFile != NULL) {
                eina_list_free(m->elFile);
                m->elFile = NULL;
        }
@@ -279,8 +276,16 @@ void CFileGrid::t_Empty(bool sort_flag)
 void CFileGrid::t_Update(char *fid, bool sort_flag)
 {
        _DBG("fid: %s, sort_flag: %d", fid, sort_flag);
-       t_Empty(sort_flag);
-       t_CreateFileGrid();
+
+       elm_gengrid_clear(m->eoGrid);
+       if (sort_flag == false && m->elFile != NULL) {
+               eina_list_free(m->elFile);
+               m->elFile = NULL;
+       }
+
+       m->elItemInfo = NULL;
+       if (m->callback.cbUpdateEmptyFocusSequence)
+               m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
 
        if (sort_flag == false) {
                if (fid)
@@ -288,7 +293,35 @@ void CFileGrid::t_Update(char *fid, bool sort_flag)
                else
                        m_GetFolderList();
        }
-       m->elFile = CSortName::Sort(m->elFile, (CSortName::ESort)CInfo::SortType());
+       
+       const char* sortType;
+       switch(CInfo::SortType())
+       {
+               case 0:
+                       sortType = SORT_BY_NAME_AZ;
+                       break;
+               case 1:
+                       sortType = SORT_BY_NAME_ZA;
+                       break;
+               case 2:
+                       sortType = SORT_BY_DATE_ASC;
+                       break;
+               case 3:
+                       sortType = SORT_BY_DATE_DES;
+                       break;
+               case 4:
+                       sortType = SORT_BY_SIZE_ASC;
+                       break;
+               case 5:
+                       sortType = SORT_BY_SIZE_DES;
+                       break;
+               default:
+                       _DBG("Fix your code : sortType is invalid");
+                       sortType = SORT_BY_NAME_AZ;
+                       break;
+       }
+
+       m->elFile = CSortMgr::Sort(m->elFile, sortType);
        t_Fill();
 
        if (fid)    // folder
@@ -313,7 +346,6 @@ void CFileGrid::t_Fill(void)
        ts = eina_list_count(m->elFile);
        _DBG("count: %d", ts);
        if (ts == 0) {
-               t_Empty(false);
                return;
        }
 
@@ -321,7 +353,7 @@ void CFileGrid::t_Fill(void)
                pInfo = (CExtNameInfo*)obj;
                pItemInfo = (SItemInfo *)calloc(1, sizeof(SItemInfo));
                if (!pItemInfo) {
-                       t_Empty(false);
+                       _DBG("Fail to allocate memory!!!!!!");
                        return;
                }
 
@@ -345,16 +377,18 @@ bool CFileGrid::Create(Evas_Object* win, Evas_Object *base, const SCallback *cb)
                _CHECK(m->pMediadata = new CMediadata )
                _CHECK(m->pMediadata->Create())
 
-               _WHEN_SUCCESS{}
+               _WHEN_SUCCESS{
+                       m->eoWin    = win;
+                       m->eoBase   = base;
+                       m->callback = *cb;
+                       t_CreateFileGrid();
+               }
 
                _CHECK_FAIL{ m->pMediadata->Destroy(); }
                _CHECK_FAIL{ delete m->pMediadata; }
                _CHECK_FAIL{ delete m; m = NULL; }
        } _CREATE_END_AND_CATCH{ return false; }
 
-       m->eoWin    = win;
-       m->eoBase   = base;
-       m->callback = *cb;
 
        return true;
 }
@@ -406,11 +440,13 @@ Evas_Object* CFileGrid::Grid(void)
 
 
 void CFileGrid::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) {
-       _DBG();
        Elm_Object_Item *it;
        SItemInfo *pItemInfo;
 
-       if (strcmp(ev->keyname, KEY_BACK) == 0) {
+       if(ev->keyname)
+               _DBG("%s", ev->keyname);
+
+       if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
                if (m->depth == 0) {
                        if (m->callback.cbUnsetFocus)
                                m->callback.cbUnsetFocus(m->callback.cookie);
@@ -422,7 +458,20 @@ void CFileGrid::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev
                        elm_object_item_focus_set(it, EINA_TRUE);
                }
        }
-       else if (strcmp(ev->keyname, KEY_MENU) == 0) {
+       else if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+               it = elm_object_focused_item_get(obj);
+               if (!it) {
+                       _ERR(" unable to get focused item ");
+                       return;
+               }
+               pItemInfo = _find_item_info(m->elItemInfo, it);
+               if (!pItemInfo)
+                       return;
+
+               m->handle_itinfo = pItemInfo;
+               m_HandleSelection();
+       }
+       else if (!strcmp(ev->keyname, KEY_MENU) || !strcmp(ev->keyname, KEY_MENU_REMOTE)) {
                it = elm_object_focused_item_get(obj);
                if (!it) {
                        _ERR(" unable to get focused item ");