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>
26 #include <AppCommon.h>
27 #include "Mediadata.h"
28 #include "ExtNameInfo.h"
30 #include "GengridItemClass.h"
31 #include "InputHandler.h"
35 #include <InputHandler.h>
37 #include "FbContextView.h"
40 #define GENGRID_ITEM_SIZE_W (263 + 20)
41 #define GENGRID_ITEM_SIZE_H (359 + 20)
44 static Elm_Object_Item *_find_item_by_id(Eina_List *list, char *fid)
51 EINA_LIST_FOREACH(list, l, obj) {
52 pItemInfo = (SItemInfo *)obj;
53 id = pItemInfo->pInfo->Id();
54 if (id && !strcmp(id, fid))
55 return pItemInfo->item;
61 static SItemInfo *_find_item_info(Eina_List *list, Elm_Object_Item *item)
67 EINA_LIST_FOREACH(list, l, obj) {
68 pItemInfo = (SItemInfo*)obj;
69 if (pItemInfo->item == item)
78 CMediadata *pMediadata;
85 Eina_List *elItemInfo;
87 CFileGrid::SCallback callback;
90 SItemInfo *ctxt_itinfo;
91 SItemInfo *handle_itinfo;
95 CGengridItemClass *pGengridItemClass;
98 memset(this, 0, sizeof(SFileGrid));
103 void CFileGrid::sm_CbRealized(void *data, Evas_Object *obj, void *event_info)
106 if (!data || !obj || !event_info)
109 elm_object_item_signal_callback_add((Elm_Object_Item*)event_info,
110 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
111 sm_CbSelectItem, data);
114 void CFileGrid::sm_CbUnrealized(void *data, Evas_Object *obj, void *event_info)
117 if (!data || !obj || !event_info)
120 elm_object_item_signal_callback_del((Elm_Object_Item*)event_info,
121 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
125 void CFileGrid::Action(void)
127 m->handle_itinfo = m->ctxt_itinfo;
129 m_DeleteContextView();
132 void CFileGrid::m_DeleteContextView(void)
134 if(CViewMgr::GetInstance()->CheckTop(FBR_CONTEXT_VIEW))
135 CViewMgr::GetInstance()->PopView();
138 void CFileGrid::sm_CbSelectItem(void *data, Elm_Object_Item *it, const char *emission, const char *source)
140 CFileGrid* root = (CFileGrid*)data;
141 SItemInfo *pItemInfo;
146 pItemInfo = _find_item_info(root->m->elItemInfo, it);
148 _ERR(" no item info found ");
152 root->m->handle_itinfo = pItemInfo;
153 root->m_HandleSelection();
156 void CFileGrid::m_HandleSelection(void)
161 SItemInfo *pItemInfo = m->handle_itinfo;
166 type = pItemInfo->pInfo->Type();
167 if (type == E_GRP_FOLDER) {
172 id = pItemInfo->pInfo->Id();
180 elm_object_tree_focus_allow_set(m->eoBase, EINA_FALSE);
181 t_Update(m->fid, false);//_update_filegrid(m, m->fid, false);
182 elm_object_tree_focus_allow_set(m->eoBase, EINA_TRUE);
183 elm_object_focus_set(m->eoGrid, EINA_TRUE);
186 path = pItemInfo->pInfo->Path();
190 if (m->callback.cbLinkApp)
191 m->callback.cbLinkApp(m->callback.cookie, type, CInfo::SourceType(), path);
192 elm_gengrid_item_selected_set(pItemInfo->item, EINA_FALSE);
196 void CFileGrid::m_GetMediaList(char *fid)
199 ret = m->pMediadata->GetMediaList(fid, CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
201 _ERR(" Fetching all list from file failed ");
206 void CFileGrid::m_GetFolderList(void)
209 ret = m->pMediadata->GetFolderList(CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
211 _ERR(" Fetching all list from file failed ");
216 void CFileGrid::t_CreateFileGrid(void)
220 grid = elm_gengrid_add(m->eoBase);
223 evas_object_size_hint_weight_set(grid,
224 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
225 elm_gengrid_align_set(grid, 0, 0);
226 elm_object_part_content_set(m->eoBase, FBR_PART_MEDIA_GRID, grid);
231 evas_object_smart_callback_add(grid, FBR_SIGNAL_REALIZED, sm_CbRealized, this);
232 evas_object_smart_callback_add(grid, FBR_SIGNAL_UNREALIZED, sm_CbUnrealized, this);
233 elm_gengrid_item_size_set(grid,
234 elm_config_scale_get() * GENGRID_ITEM_SIZE_W,
235 elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
239 m->pGengridItemClass = new CGengridItemClass;
240 if (!m->pGengridItemClass->Create()) {
241 delete m->pGengridItemClass;
242 m->pGengridItemClass = NULL;
243 evas_object_del(grid);
244 _ERR(" elm_genlist_item_class_new failed ");
248 evas_object_show(grid);
252 void CFileGrid::t_Empty(bool sort_flag)
255 elm_gengrid_clear(m->eoGrid);
256 evas_object_del(m->eoGrid);
260 if (m->pGengridItemClass)
262 m->pGengridItemClass->Destroy();
263 delete m->pGengridItemClass;
264 m->pGengridItemClass = NULL;
267 if (sort_flag == false) {
268 eina_list_free(m->elFile);
272 m->elItemInfo = NULL;
273 if (m->callback.cbUpdateEmptyFocusSequence)
274 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
278 void CFileGrid::t_Update(char *fid, bool sort_flag)
280 _DBG("fid: %s, sort_flag: %d", fid, sort_flag);
284 if (sort_flag == false) {
290 m->elFile = CSortName::Sort(m->elFile, (CSortName::ESort)CInfo::SortType());
300 void CFileGrid::t_Fill(void)
304 SItemInfo *pItemInfo;
308 _DBG("grid: %x, flist: %x", m->eoGrid, m->elFile);
309 if (!m->eoGrid || !m->elFile)
312 ts = eina_list_count(m->elFile);
313 _DBG("count: %d", ts);
319 EINA_LIST_FOREACH(m->elFile, l, obj) {
320 pInfo = (CExtNameInfo*)obj;
321 pItemInfo = (SItemInfo *)calloc(1, sizeof(SItemInfo));
327 pItemInfo->pInfo = pInfo;
328 pItemInfo->item = elm_gengrid_item_append(m->eoGrid, m->pGengridItemClass->Handle(), pItemInfo, NULL, m);
329 m->elItemInfo = eina_list_append(m->elItemInfo, pItemInfo);
332 if (m->callback.cbUpdatedGrid)
333 m->callback.cbUpdatedGrid(m->callback.cookie);
337 bool CFileGrid::Create(Evas_Object* win, Evas_Object *base, const SCallback *cb)
343 _CHECK(m = new SFileGrid)
344 _CHECK(m->pMediadata = new CMediadata )
345 _CHECK(m->pMediadata->Create())
349 _CHECK_FAIL{ m->pMediadata->Destroy(); }
350 _CHECK_FAIL{ delete m->pMediadata; }
351 _CHECK_FAIL{ delete m; m = NULL; }
352 } _CREATE_END_AND_CATCH{ return false; }
362 void CFileGrid::Destroy(void)
368 m_DeleteContextView();
372 m->pMediadata->Destroy();
373 delete m->pMediadata;
379 void CFileGrid::Update(bool sort_flag)
384 if (sort_flag == true) {
387 t_Update(fid, sort_flag);
391 void CFileGrid::SetFocus(Eina_Bool flag)
395 elm_object_focus_set(m->eoGrid, flag);
399 Evas_Object* CFileGrid::Grid(void)
407 void CFileGrid::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) {
410 SItemInfo *pItemInfo;
412 if (strcmp(ev->keyname, KEY_BACK) == 0) {
414 if (m->callback.cbUnsetFocus)
415 m->callback.cbUnsetFocus(m->callback.cookie);
418 t_Update(NULL, false);
419 it = _find_item_by_id(m->elItemInfo, m->fid);
420 elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_IN);
421 elm_object_item_focus_set(it, EINA_TRUE);
424 else if (strcmp(ev->keyname, KEY_MENU) == 0) {
425 it = elm_object_focused_item_get(obj);
427 _ERR(" unable to get focused item ");
430 pItemInfo = _find_item_info(m->elItemInfo, it);
434 m->ctxt_itinfo = pItemInfo;
436 CViewMgr::GetInstance()->PushView(FBR_CONTEXT_VIEW, pItemInfo->pInfo);
441 void CFileGrid::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
443 Elm_Object_Item *item;
448 item = elm_gengrid_at_xy_item_get(obj, ev->cur.canvas.x,
449 ev->cur.canvas.y, NULL, NULL);
453 elm_object_item_focus_set(item, EINA_TRUE);