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.
17 #include <Elementary.h>
22 #include <AppCommon.h>
26 #include "Mediadata.h"
27 #include "GengridItemClass.h"
30 #include "FbContextView.h"
33 #define GENGRID_ITEM_SIZE_W (263 + 20)
34 #define GENGRID_ITEM_SIZE_H (359 + 20)
37 static Elm_Object_Item *_find_item_by_id(Eina_List *list, char *fid)
44 EINA_LIST_FOREACH(list, l, obj) {
45 pItemInfo = (SItemInfo *)obj;
46 id = pItemInfo->pInfo->Id();
47 if (id && !strcmp(id, fid))
48 return pItemInfo->item;
54 static SItemInfo *_find_item_info(Eina_List *list, Elm_Object_Item *item)
60 EINA_LIST_FOREACH(list, l, obj) {
61 pItemInfo = (SItemInfo*)obj;
62 if (pItemInfo->item == item)
71 CMediadata *pMediadata;
78 Eina_List *elItemInfo;
80 CFileGrid::SCallback callback;
83 SItemInfo *ctxt_itinfo;
84 SItemInfo *handle_itinfo;
88 CGengridItemClass *pGengridItemClass;
91 memset(this, 0, sizeof(SFileGrid));
96 void CFileGrid::sm_CbRealized(void *data, Evas_Object *obj, void *event_info)
99 if (!data || !obj || !event_info)
102 elm_object_item_signal_callback_add((Elm_Object_Item*)event_info,
103 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
104 sm_CbSelectItem, data);
107 void CFileGrid::sm_CbUnrealized(void *data, Evas_Object *obj, void *event_info)
110 if (!data || !obj || !event_info)
113 elm_object_item_signal_callback_del((Elm_Object_Item*)event_info,
114 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
118 void CFileGrid::Action(void)
121 m->handle_itinfo = m->ctxt_itinfo;
123 m_DeleteContextView();
126 void CFileGrid::m_DeleteContextView(void)
128 if(CViewMgr::GetInstance()->CheckTop(FBR_CONTEXT_VIEW))
129 CViewMgr::GetInstance()->PopView();
132 void CFileGrid::sm_CbSelectItem(void *data, Elm_Object_Item *it, const char *emission, const char *source)
135 CFileGrid* root = (CFileGrid*)data;
136 SItemInfo *pItemInfo;
141 pItemInfo = _find_item_info(root->m->elItemInfo, it);
143 _ERR(" no item info found ");
147 root->m->handle_itinfo = pItemInfo;
148 root->m_HandleSelection();
151 void CFileGrid::m_HandleSelection(void)
156 SItemInfo *pItemInfo = m->handle_itinfo;
161 type = pItemInfo->pInfo->Type();
162 if (type == E_GRP_FOLDER) {
167 id = pItemInfo->pInfo->Id();
175 elm_object_tree_focus_allow_set(m->eoBase, EINA_FALSE);
176 t_Update(m->fid, false);//_update_filegrid(m, m->fid, false);
177 elm_object_tree_focus_allow_set(m->eoBase, EINA_TRUE);
178 elm_object_focus_set(m->eoGrid, EINA_TRUE);
181 path = pItemInfo->pInfo->Path();
185 if (m->callback.cbLinkApp)
186 m->callback.cbLinkApp(m->callback.cookie, type, CInfo::SourceType(), path);
187 elm_gengrid_item_selected_set(pItemInfo->item, EINA_FALSE);
191 void CFileGrid::m_GetMediaList(char *fid)
194 ret = m->pMediadata->GetMediaList(fid, CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
196 _ERR(" Fetching all list from file failed ");
201 void CFileGrid::m_GetFolderList(void)
204 ret = m->pMediadata->GetFolderList(CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
206 _ERR(" Fetching all list from file failed ");
211 void CFileGrid::t_CreateFileGrid(void)
215 grid = elm_gengrid_add(m->eoBase);
218 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 elm_gengrid_align_set(grid, 0, 0);
220 elm_object_part_content_set(m->eoBase, FBR_PART_MEDIA_GRID, grid);
224 evas_object_smart_callback_add(grid, FBR_SIGNAL_REALIZED, sm_CbRealized, this);
225 evas_object_smart_callback_add(grid, FBR_SIGNAL_UNREALIZED, sm_CbUnrealized, this);
226 elm_gengrid_item_size_set(grid, elm_config_scale_get() * GENGRID_ITEM_SIZE_W, elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
230 m->pGengridItemClass = new CGengridItemClass;
231 if (!m->pGengridItemClass->Create()) {
232 delete m->pGengridItemClass;
233 m->pGengridItemClass = NULL;
234 evas_object_del(grid);
235 _ERR(" elm_genlist_item_class_new failed ");
239 evas_object_show(grid);
243 void CFileGrid::t_Empty(bool sort_flag)
246 elm_gengrid_clear(m->eoGrid);
247 evas_object_del(m->eoGrid);
251 if (m->pGengridItemClass)
253 m->pGengridItemClass->Destroy();
254 delete m->pGengridItemClass;
255 m->pGengridItemClass = NULL;
258 if (sort_flag == false && m->elFile != NULL) {
259 eina_list_free(m->elFile);
263 m->elItemInfo = NULL;
264 if (m->callback.cbUpdateEmptyFocusSequence)
265 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
269 void CFileGrid::t_Update(char *fid, bool sort_flag)
271 _DBG("fid: %s, sort_flag: %d", fid, sort_flag);
273 elm_gengrid_clear(m->eoGrid);
274 if (sort_flag == false && m->elFile != NULL) {
275 eina_list_free(m->elFile);
279 m->elItemInfo = NULL;
280 if (m->callback.cbUpdateEmptyFocusSequence)
281 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
283 if (sort_flag == false) {
290 const char* sortType;
291 switch(CInfo::SortType())
294 sortType = SORT_BY_NAME_AZ;
297 sortType = SORT_BY_NAME_ZA;
300 sortType = SORT_BY_DATE_ASC;
303 sortType = SORT_BY_DATE_DES;
306 sortType = SORT_BY_SIZE_ASC;
309 sortType = SORT_BY_SIZE_DES;
312 _DBG("Fix your code : sortType is invalid");
313 sortType = SORT_BY_NAME_AZ;
317 m->elFile = CSortMgr::Sort(m->elFile, sortType);
327 void CFileGrid::t_Fill(void)
331 SItemInfo *pItemInfo;
335 _DBG("grid: %x, flist: %x", m->eoGrid, m->elFile);
336 if (!m->eoGrid || !m->elFile)
339 ts = eina_list_count(m->elFile);
340 _DBG("count: %d", ts);
345 EINA_LIST_FOREACH(m->elFile, l, obj) {
346 pInfo = (CExtNameInfo*)obj;
347 pItemInfo = (SItemInfo *)calloc(1, sizeof(SItemInfo));
349 _DBG("Fail to allocate memory!!!!!!");
353 pItemInfo->pInfo = pInfo;
354 pItemInfo->item = elm_gengrid_item_append(m->eoGrid, m->pGengridItemClass->Handle(), pItemInfo, NULL, m);
355 m->elItemInfo = eina_list_append(m->elItemInfo, pItemInfo);
358 if (m->callback.cbUpdatedGrid)
359 m->callback.cbUpdatedGrid(m->callback.cookie);
363 bool CFileGrid::Create(Evas_Object* win, Evas_Object *base, const SCallback *cb)
369 _CHECK(m = new SFileGrid)
370 _CHECK(m->pMediadata = new CMediadata )
371 _CHECK(m->pMediadata->Create())
380 _CHECK_FAIL{ m->pMediadata->Destroy(); }
381 _CHECK_FAIL{ delete m->pMediadata; }
382 _CHECK_FAIL{ delete m; m = NULL; }
383 } _CREATE_END_AND_CATCH{ return false; }
390 void CFileGrid::Destroy(void)
396 m_DeleteContextView();
400 m->pMediadata->Destroy();
401 delete m->pMediadata;
407 void CFileGrid::Update(bool sort_flag)
412 if (sort_flag == true) {
415 t_Update(fid, sort_flag);
419 void CFileGrid::SetFocus(Eina_Bool flag)
423 elm_object_focus_set(m->eoGrid, flag);
427 Evas_Object* CFileGrid::Grid(void)
435 void CFileGrid::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) {
437 SItemInfo *pItemInfo;
440 _DBG("%s", ev->keyname);
442 if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
444 if (m->callback.cbUnsetFocus)
445 m->callback.cbUnsetFocus(m->callback.cookie);
448 t_Update(NULL, false);
449 it = _find_item_by_id(m->elItemInfo, m->fid);
450 elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_IN);
451 elm_object_item_focus_set(it, EINA_TRUE);
454 else if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
455 it = elm_object_focused_item_get(obj);
457 _ERR(" unable to get focused item ");
460 pItemInfo = _find_item_info(m->elItemInfo, it);
464 m->handle_itinfo = pItemInfo;
467 else if (!strcmp(ev->keyname, KEY_MENU) || !strcmp(ev->keyname, KEY_MENU_REMOTE)) {
468 it = elm_object_focused_item_get(obj);
470 _ERR(" unable to get focused item ");
473 pItemInfo = _find_item_info(m->elItemInfo, it);
477 m->ctxt_itinfo = pItemInfo;
479 CViewMgr::GetInstance()->PushView(FBR_CONTEXT_VIEW, pItemInfo->pInfo);
484 void CFileGrid::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
486 Elm_Object_Item *item;
491 item = elm_gengrid_at_xy_item_get(obj, ev->cur.canvas.x,
492 ev->cur.canvas.y, NULL, NULL);
496 elm_object_item_focus_set(item, EINA_TRUE);