2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <AppCommon.h>
24 #include "Mediadata.h"
25 #include "GengridItemClass.h"
28 #include "FbContextView.h"
31 #define GENGRID_ITEM_SIZE_W (263 + 20)
32 #define GENGRID_ITEM_SIZE_H (359 + 20)
35 static Elm_Object_Item *_find_item_by_id(Eina_List *list, char *fid)
42 EINA_LIST_FOREACH(list, l, obj) {
43 pItemInfo = (SItemInfo *)obj;
44 id = pItemInfo->pInfo->Id();
45 if (id && !strcmp(id, fid))
46 return pItemInfo->item;
52 static SItemInfo *_find_item_info(Eina_List *list, Elm_Object_Item *item)
58 EINA_LIST_FOREACH(list, l, obj) {
59 pItemInfo = (SItemInfo*)obj;
60 if (pItemInfo->item == item)
69 CMediadata *pMediadata;
76 Eina_List *elItemInfo;
78 CFileGrid::SCallback callback;
81 SItemInfo *ctxt_itinfo;
82 SItemInfo *handle_itinfo;
86 CGengridItemClass *pGengridItemClass;
89 memset(this, 0, sizeof(SFileGrid));
94 void CFileGrid::sm_CbRealized(void *data, Evas_Object *obj, void *event_info)
97 if (!data || !obj || !event_info)
100 elm_object_item_signal_callback_add((Elm_Object_Item*)event_info,
101 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
102 sm_CbSelectItem, data);
105 void CFileGrid::sm_CbUnrealized(void *data, Evas_Object *obj, void *event_info)
108 if (!data || !obj || !event_info)
111 elm_object_item_signal_callback_del((Elm_Object_Item*)event_info,
112 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
116 void CFileGrid::Action(void)
119 m->handle_itinfo = m->ctxt_itinfo;
121 m_DeleteContextView();
124 void CFileGrid::m_DeleteContextView(void)
126 if(CViewMgr::GetInstance()->CheckTop(FBR_CONTEXT_VIEW))
127 CViewMgr::GetInstance()->PopView();
130 void CFileGrid::sm_CbSelectItem(void *data, Elm_Object_Item *it, const char *emission, const char *source)
133 CFileGrid* root = (CFileGrid*)data;
134 SItemInfo *pItemInfo;
139 pItemInfo = _find_item_info(root->m->elItemInfo, it);
141 _ERR(" no item info found ");
145 root->m->handle_itinfo = pItemInfo;
146 root->m_HandleSelection();
149 void CFileGrid::m_HandleSelection(void)
154 SItemInfo *pItemInfo = m->handle_itinfo;
159 type = pItemInfo->pInfo->Type();
160 if (type == E_GRP_FOLDER) {
165 id = pItemInfo->pInfo->Id();
173 elm_object_tree_focus_allow_set(m->eoBase, EINA_FALSE);
174 t_Update(m->fid, false);//_update_filegrid(m, m->fid, false);
175 elm_object_tree_focus_allow_set(m->eoBase, EINA_TRUE);
176 elm_object_focus_set(m->eoGrid, EINA_TRUE);
179 path = pItemInfo->pInfo->Path();
183 if (m->callback.cbLinkApp)
184 m->callback.cbLinkApp(m->callback.cookie, type, CInfo::SourceType(), path);
185 elm_gengrid_item_selected_set(pItemInfo->item, EINA_FALSE);
189 void CFileGrid::m_GetMediaList(char *fid)
192 ret = m->pMediadata->GetMediaList(fid, CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
194 _ERR(" Fetching all list from file failed ");
199 void CFileGrid::m_GetFolderList(void)
202 ret = m->pMediadata->GetFolderList(CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
204 _ERR(" Fetching all list from file failed ");
209 void CFileGrid::t_CreateFileGrid(void)
213 grid = elm_gengrid_add(m->eoBase);
216 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217 elm_gengrid_align_set(grid, 0, 0);
218 elm_object_part_content_set(m->eoBase, FBR_PART_MEDIA_GRID, grid);
222 evas_object_smart_callback_add(grid, FBR_SIGNAL_REALIZED, sm_CbRealized, this);
223 evas_object_smart_callback_add(grid, FBR_SIGNAL_UNREALIZED, sm_CbUnrealized, this);
224 elm_gengrid_item_size_set(grid, elm_config_scale_get() * GENGRID_ITEM_SIZE_W, elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
228 m->pGengridItemClass = new CGengridItemClass;
229 if (!m->pGengridItemClass->Create()) {
230 delete m->pGengridItemClass;
231 m->pGengridItemClass = NULL;
232 evas_object_del(grid);
233 _ERR(" elm_genlist_item_class_new failed ");
237 evas_object_show(grid);
241 void CFileGrid::t_Empty(bool sort_flag)
244 elm_gengrid_clear(m->eoGrid);
245 evas_object_del(m->eoGrid);
249 if (m->pGengridItemClass)
251 m->pGengridItemClass->Destroy();
252 delete m->pGengridItemClass;
253 m->pGengridItemClass = NULL;
256 if (sort_flag == false && m->elFile != NULL) {
257 eina_list_free(m->elFile);
261 m->elItemInfo = NULL;
262 if (m->callback.cbUpdateEmptyFocusSequence)
263 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
267 void CFileGrid::t_Update(char *fid, bool sort_flag)
269 _DBG("fid: %s, sort_flag: %d", fid, sort_flag);
271 elm_gengrid_clear(m->eoGrid);
272 if (sort_flag == false && m->elFile != NULL) {
273 eina_list_free(m->elFile);
277 m->elItemInfo = NULL;
278 if (m->callback.cbUpdateEmptyFocusSequence)
279 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
281 if (sort_flag == false) {
288 const char* sortType;
289 switch(CInfo::SortType())
292 sortType = SORT_BY_NAME_AZ;
295 sortType = SORT_BY_NAME_ZA;
298 sortType = SORT_BY_DATE_ASC;
301 sortType = SORT_BY_DATE_DES;
304 sortType = SORT_BY_SIZE_ASC;
307 sortType = SORT_BY_SIZE_DES;
310 _DBG("Fix your code : sortType is invalid");
311 sortType = SORT_BY_NAME_AZ;
315 m->elFile = CSortMgr::Sort(m->elFile, sortType);
325 void CFileGrid::t_Fill(void)
329 SItemInfo *pItemInfo;
333 _DBG("grid: %x, flist: %x", m->eoGrid, m->elFile);
334 if (!m->eoGrid || !m->elFile)
337 ts = eina_list_count(m->elFile);
338 _DBG("count: %d", ts);
343 EINA_LIST_FOREACH(m->elFile, l, obj) {
344 pInfo = (CExtNameInfo*)obj;
345 pItemInfo = (SItemInfo *)calloc(1, sizeof(SItemInfo));
347 _DBG("Fail to allocate memory!!!!!!");
351 pItemInfo->pInfo = pInfo;
352 pItemInfo->item = elm_gengrid_item_append(m->eoGrid, m->pGengridItemClass->Handle(), pItemInfo, NULL, m);
353 m->elItemInfo = eina_list_append(m->elItemInfo, pItemInfo);
356 if (m->callback.cbUpdatedGrid)
357 m->callback.cbUpdatedGrid(m->callback.cookie);
361 bool CFileGrid::Create(Evas_Object* win, Evas_Object *base, const SCallback *cb)
367 _CHECK(m = new SFileGrid)
368 _CHECK(m->pMediadata = new CMediadata )
369 _CHECK(m->pMediadata->Create())
378 _CHECK_FAIL{ m->pMediadata->Destroy(); }
379 _CHECK_FAIL{ delete m->pMediadata; }
380 _CHECK_FAIL{ delete m; m = NULL; }
381 } _CREATE_END_AND_CATCH{ return false; }
388 void CFileGrid::Destroy(void)
394 m_DeleteContextView();
398 m->pMediadata->Destroy();
399 delete m->pMediadata;
405 void CFileGrid::Update(bool sort_flag)
410 if (sort_flag == true) {
413 t_Update(fid, sort_flag);
417 void CFileGrid::SetFocus(Eina_Bool flag)
421 elm_object_focus_set(m->eoGrid, flag);
425 Evas_Object* CFileGrid::Grid(void)
433 void CFileGrid::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) {
435 SItemInfo *pItemInfo;
438 _DBG("%s", ev->keyname);
440 if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
442 if (m->callback.cbUnsetFocus)
443 m->callback.cbUnsetFocus(m->callback.cookie);
446 t_Update(NULL, false);
447 it = _find_item_by_id(m->elItemInfo, m->fid);
448 elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_IN);
449 elm_object_item_focus_set(it, EINA_TRUE);
452 else if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
453 it = elm_object_focused_item_get(obj);
455 _ERR(" unable to get focused item ");
458 pItemInfo = _find_item_info(m->elItemInfo, it);
462 m->handle_itinfo = pItemInfo;
465 else if (!strcmp(ev->keyname, KEY_MENU) || !strcmp(ev->keyname, KEY_MENU_REMOTE)) {
466 it = elm_object_focused_item_get(obj);
468 _ERR(" unable to get focused item ");
471 pItemInfo = _find_item_info(m->elItemInfo, it);
475 m->ctxt_itinfo = pItemInfo;
477 CViewMgr::GetInstance()->PushView(FBR_CONTEXT_VIEW, pItemInfo->pInfo);
482 void CFileGrid::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
484 Elm_Object_Item *item;
489 item = elm_gengrid_at_xy_item_get(obj, ev->cur.canvas.x,
490 ev->cur.canvas.y, NULL, NULL);
494 elm_object_item_focus_set(item, EINA_TRUE);