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"
31 #include "GengridItemClass.h"
32 #include "InputHandler.h"
36 #include <InputHandler.h>
38 #include "FbContextView.h"
41 #define GENGRID_ITEM_SIZE_W (263 + 20)
42 #define GENGRID_ITEM_SIZE_H (359 + 20)
45 static Elm_Object_Item *_find_item_by_id(Eina_List *list, char *fid)
52 EINA_LIST_FOREACH(list, l, obj) {
53 pItemInfo = (SItemInfo *)obj;
54 id = pItemInfo->pInfo->Id();
55 if (id && !strcmp(id, fid))
56 return pItemInfo->item;
62 static SItemInfo *_find_item_info(Eina_List *list, Elm_Object_Item *item)
68 EINA_LIST_FOREACH(list, l, obj) {
69 pItemInfo = (SItemInfo*)obj;
70 if (pItemInfo->item == item)
79 CMediadata *pMediadata;
86 Eina_List *elItemInfo;
88 CFileGrid::SCallback callback;
91 SItemInfo *ctxt_itinfo;
92 SItemInfo *handle_itinfo;
96 CGengridItemClass *pGengridItemClass;
99 memset(this, 0, sizeof(SFileGrid));
104 void CFileGrid::sm_CbRealized(void *data, Evas_Object *obj, void *event_info)
107 if (!data || !obj || !event_info)
110 elm_object_item_signal_callback_add((Elm_Object_Item*)event_info,
111 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
112 sm_CbSelectItem, data);
115 void CFileGrid::sm_CbUnrealized(void *data, Evas_Object *obj, void *event_info)
118 if (!data || !obj || !event_info)
121 elm_object_item_signal_callback_del((Elm_Object_Item*)event_info,
122 FBR_SIGNAL_BTN_CLICKED, FBR_BASE_VIEW,
126 void CFileGrid::Action(void)
128 m->handle_itinfo = m->ctxt_itinfo;
130 m_DeleteContextView();
133 void CFileGrid::m_DeleteContextView(void)
135 if(CViewMgr::GetInstance()->CheckTop(FBR_CONTEXT_VIEW))
136 CViewMgr::GetInstance()->PopView();
139 void CFileGrid::sm_CbSelectItem(void *data, Elm_Object_Item *it, const char *emission, const char *source)
141 CFileGrid* root = (CFileGrid*)data;
142 SItemInfo *pItemInfo;
147 pItemInfo = _find_item_info(root->m->elItemInfo, it);
149 _ERR(" no item info found ");
153 root->m->handle_itinfo = pItemInfo;
154 root->m_HandleSelection();
157 void CFileGrid::m_HandleSelection(void)
162 SItemInfo *pItemInfo = m->handle_itinfo;
167 type = pItemInfo->pInfo->Type();
168 if (type == E_GRP_FOLDER) {
173 id = pItemInfo->pInfo->Id();
181 elm_object_tree_focus_allow_set(m->eoBase, EINA_FALSE);
182 t_Update(m->fid, false);//_update_filegrid(m, m->fid, false);
183 elm_object_tree_focus_allow_set(m->eoBase, EINA_TRUE);
184 elm_object_focus_set(m->eoGrid, EINA_TRUE);
187 path = pItemInfo->pInfo->Path();
191 if (m->callback.cbLinkApp)
192 m->callback.cbLinkApp(m->callback.cookie, type, CInfo::SourceType(), path);
193 elm_gengrid_item_selected_set(pItemInfo->item, EINA_FALSE);
197 void CFileGrid::m_GetMediaList(char *fid)
200 ret = m->pMediadata->GetMediaList(fid, CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
202 _ERR(" Fetching all list from file failed ");
207 void CFileGrid::m_GetFolderList(void)
210 ret = m->pMediadata->GetFolderList(CInfo::GroupIndex(), CInfo::SourceType(), &m->elFile);
212 _ERR(" Fetching all list from file failed ");
217 void CFileGrid::t_CreateFileGrid(void)
221 grid = elm_gengrid_add(m->eoBase);
224 evas_object_size_hint_weight_set(grid,
225 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
226 elm_gengrid_align_set(grid, 0, 0);
227 elm_object_part_content_set(m->eoBase, FBR_PART_MEDIA_GRID, grid);
232 evas_object_smart_callback_add(grid, FBR_SIGNAL_REALIZED, sm_CbRealized, this);
233 evas_object_smart_callback_add(grid, FBR_SIGNAL_UNREALIZED, sm_CbUnrealized, this);
234 elm_gengrid_item_size_set(grid,
235 elm_config_scale_get() * GENGRID_ITEM_SIZE_W,
236 elm_config_scale_get() * GENGRID_ITEM_SIZE_H);
240 m->pGengridItemClass = new CGengridItemClass;
241 if (!m->pGengridItemClass->Create()) {
242 delete m->pGengridItemClass;
243 m->pGengridItemClass = NULL;
244 evas_object_del(grid);
245 _ERR(" elm_genlist_item_class_new failed ");
249 evas_object_show(grid);
253 void CFileGrid::t_Empty(bool sort_flag)
256 elm_gengrid_clear(m->eoGrid);
257 evas_object_del(m->eoGrid);
261 if (m->pGengridItemClass)
263 m->pGengridItemClass->Destroy();
264 delete m->pGengridItemClass;
265 m->pGengridItemClass = NULL;
268 if (sort_flag == false) {
269 eina_list_free(m->elFile);
273 m->elItemInfo = NULL;
274 if (m->callback.cbUpdateEmptyFocusSequence)
275 m->callback.cbUpdateEmptyFocusSequence(m->callback.cookie);
279 void CFileGrid::t_Update(char *fid, bool sort_flag)
281 _DBG("fid: %s, sort_flag: %d", fid, sort_flag);
285 if (sort_flag == false) {
292 const char* sortType;
293 switch(CInfo::SortType())
296 sortType = SORT_BY_NAME_AZ;
299 sortType = SORT_BY_NAME_ZA;
302 sortType = SORT_BY_DATE_ASC;
305 sortType = SORT_BY_DATE_DES;
308 sortType = SORT_BY_SIZE_ASC;
311 sortType = SORT_BY_SIZE_DES;
314 _DBG("Fix your code : sortType is invalid");
315 sortType = SORT_BY_NAME_AZ;
318 m->elFile = CSort::Sort(m->elFile, sortType);
328 void CFileGrid::t_Fill(void)
332 SItemInfo *pItemInfo;
336 _DBG("grid: %x, flist: %x", m->eoGrid, m->elFile);
337 if (!m->eoGrid || !m->elFile)
340 ts = eina_list_count(m->elFile);
341 _DBG("count: %d", ts);
347 EINA_LIST_FOREACH(m->elFile, l, obj) {
348 pInfo = (CExtNameInfo*)obj;
349 pItemInfo = (SItemInfo *)calloc(1, sizeof(SItemInfo));
355 pItemInfo->pInfo = pInfo;
356 pItemInfo->item = elm_gengrid_item_append(m->eoGrid, m->pGengridItemClass->Handle(), pItemInfo, NULL, m);
357 m->elItemInfo = eina_list_append(m->elItemInfo, pItemInfo);
360 if (m->callback.cbUpdatedGrid)
361 m->callback.cbUpdatedGrid(m->callback.cookie);
365 bool CFileGrid::Create(Evas_Object* win, Evas_Object *base, const SCallback *cb)
371 _CHECK(m = new SFileGrid)
372 _CHECK(m->pMediadata = new CMediadata )
373 _CHECK(m->pMediadata->Create())
377 _CHECK_FAIL{ m->pMediadata->Destroy(); }
378 _CHECK_FAIL{ delete m->pMediadata; }
379 _CHECK_FAIL{ delete m; m = NULL; }
380 } _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) {
438 SItemInfo *pItemInfo;
440 if (strcmp(ev->keyname, KEY_BACK) == 0) {
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_MENU) == 0) {
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->ctxt_itinfo = pItemInfo;
464 CViewMgr::GetInstance()->PushView(FBR_CONTEXT_VIEW, pItemInfo->pInfo);
469 void CFileGrid::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
471 Elm_Object_Item *item;
476 item = elm_gengrid_at_xy_item_get(obj, ev->cur.canvas.x,
477 ev->cur.canvas.y, NULL, NULL);
481 elm_object_item_focus_set(item, EINA_TRUE);