256c7f63a92b3dbccf70189799a294127467d7b5
[profile/tv/apps/native/filebrowser.git] / src / views / BaseView / FbBaseView.cpp
1 /*
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <Elementary.h>
18 #include <Eina.h>
19 #include <Ecore.h>
20 #include <aul.h>
21 #include "i18n.h"
22 #include "define.h"
23
24 #include "AppCommon.h"
25 #include "ExtNameInfo.h"
26 #include "common.h"
27 #include "dbg.h"
28 #include <MediaContentDbListener.h>
29 #include <UsbConnectionListener.h>
30 #include "Popup.h"
31 #include "InputHandler.h"
32
33 #include <CtxPopup.h>
34
35 #include <BaseView.h>
36 #include "FbBaseView.h"
37 #include "Info.h"
38
39 #include "SourceCtxPopup.h"
40 #include "SortCtxPopup.h"
41
42 #include <ViewMgr.h>
43 #include <LayoutMgr.h>
44 #include <BaseLayout.h>
45 #include "FbAllLayout.h"
46 #include "FbPhotoLayout.h"
47 #include "FbVideoLayout.h"
48 #include "FbMusicLayout.h"
49
50 #define TOTAL_GROUP_BTNS        4
51 #define TOTAL_TOP_BTNS          2
52 #define TOTAL_UPDATE_CALLBACKS  2
53 #define PARAM_URI               "uri"
54 #define PARAM_SOURCE            "source"
55
56 struct _btn_info {
57         const char *txt;
58         const char *part;
59         const char *style;
60         const char *icon_path;
61 };
62
63 enum topbtns {
64         TOPBTN_SOURCE,
65         TOPBTN_SORT,
66 };
67
68 enum layoutId {
69         ALL_LAYOUT,
70         PHOTO_LAYOUT,
71         VIDEO_LAYOUT,
72         MUSIC_LAYOUT
73 };
74
75 const char *source_arg[] = {
76         "all",
77         "tv",
78         "pUsb"
79 };
80
81 const char *linked_app[] = {
82         N_(""),
83         N_("org.tizen.gallery-tv-ref"),
84         N_("org.tizen.video-player-tv-ref"),
85         N_("org.tizen.music-player-tv-ref"),
86         N_(""),
87 };
88
89 const char* _get_layout_id(int curLayoutId){
90         switch(curLayoutId)
91         {
92                 case ALL_LAYOUT:
93                         return FB_ALL_LAYOUT;
94                 case PHOTO_LAYOUT:
95                         return FB_PHOTO_LAYOUT;
96                 case VIDEO_LAYOUT:
97                         return FB_VIDEO_LAYOUT;
98                 case MUSIC_LAYOUT:
99                         return FB_MUSIC_LAYOUT;
100         }
101         return FB_ALL_LAYOUT; // default
102 }
103
104 struct SFbBaseView {
105         Evas_Object *eoWin;
106         Evas_Object *eoBase;
107         Evas_Object *eoBtnGroup[TOTAL_GROUP_BTNS];
108         Evas_Object *eoSelectedBtnGroup;//Evas_Object *c_grpbtn;
109         Evas_Object *eoBtnSource;
110         Evas_Object *eoBtnSort;
111
112         CCtxPopup   *pCtxPopup;
113         CPopup      *pPopup;
114
115         CLayoutMgr     *pLayoutMgr;
116
117         int            curLayoutId;
118         CFbAllLayout   *pFbAllLayout;
119         CFbPhotoLayout *pFbPhotoLayout;
120         CFbVideoLayout *pFbVideoLayout;
121         CFbMusicLayout *pFbMusicLayout;
122
123         SFbBaseView() {
124                 int a;
125
126                 memset(eoBtnGroup, 0, sizeof(eoBtnGroup));
127                 pHandlerBase = new CHandlerBase(this);
128                 for (a = 0; a < TOTAL_TOP_BTNS; a++)
129                         pHandlerButton[a] = new CHandlerButton(this);
130                 for (a = 0; a < TOTAL_GROUP_BTNS; a++){
131                         pHandlerGroup[a] = new CHandlerGroup(this);
132                 }
133         }
134         virtual ~SFbBaseView() {
135                 int a;
136
137                 delete pHandlerBase;
138                 for (a = 0; a < TOTAL_TOP_BTNS; a++)
139                         delete pHandlerButton[a];
140                 for (a = 0; a < TOTAL_GROUP_BTNS; a++)
141                         delete pHandlerGroup[a];
142         }
143         
144         class CHandlerBase : public CListenerMgr, public IKeyDownListener {
145                 SFbBaseView *m;
146
147         public:
148                 CHandlerBase(SFbBaseView *ins) : IKeyDownListener(this) { m = ins; }
149
150                 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
151                         _DBG("m->curLayoutId = %d",m->curLayoutId);
152                         if (!strcmp(ev->keyname, KEY_EXIT))
153                                 elm_exit();
154                         else if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
155                                 if (elm_object_focus_get(m->eoSelectedBtnGroup)) {
156                                         switch(m->curLayoutId)
157                                         {
158                                                 case ALL_LAYOUT:
159                                                         m->pFbAllLayout->SetFocus(EINA_TRUE);
160                                                         break;
161                                                 case PHOTO_LAYOUT:
162                                                         m->pFbPhotoLayout->SetFocus(EINA_TRUE);
163                                                         break;
164                                                 case VIDEO_LAYOUT:
165                                                         m->pFbVideoLayout->SetFocus(EINA_TRUE);
166                                                         break;
167                                                 case MUSIC_LAYOUT:
168                                                         m->pFbMusicLayout->SetFocus(EINA_TRUE);
169                                                         break;
170                                         }
171                                 }
172                         }
173                 }
174         } *pHandlerBase;
175
176         class CHandlerButton : public CListenerMgr, protected IKeyDownListener, IMouseMoveListener, IMouseClickedListener {
177         private:
178                 SFbBaseView *m;
179         private:
180                 static void sm_CbCtxPopupSelected(void* cookie, CCtxPopup* instance, const char* text)
181                 {
182                         SFbBaseView* m = (SFbBaseView*)cookie;
183                         if (!m)
184                                 return;
185
186                         _DBG(" instance->Type(): %d", instance->Type());
187                         switch (instance->Type()) {
188                         case CCtxPopup::TOPBTN_SORT:
189                                 elm_object_text_set(m->eoBtnSort, text);
190                                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
191                                 break;
192
193                         case CCtxPopup::TOPBTN_SOURCE:
194                                 elm_object_text_set(m->eoBtnSource, text);
195                                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
196                                 break;
197
198                         default:
199                                 break;
200                         }
201                 }
202
203         public:
204                 CHandlerButton(SFbBaseView *ins) : IKeyDownListener(this), IMouseMoveListener(this), IMouseClickedListener(this) { m = ins; }
205
206                 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
207                         _DBG("id = %d", id);
208                         if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
209                                 elm_object_focus_set(m->eoSelectedBtnGroup, EINA_TRUE);
210                 }
211                 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
212                         _DBG("id = %d", id);
213                         if (!elm_object_focus_get(obj))
214                                 elm_object_focus_set(obj, EINA_TRUE);
215                 }
216                 virtual void OnMouseClicked(int id, Evas_Object *obj) {
217                         _DBG("id = %d", id);
218                         CSourceCtxPopup::SCallback cb;
219                         cb.cookie = m;
220                         cb.onSelected = sm_CbCtxPopupSelected;
221
222                         if (obj == m->eoBtnSource) {
223                                 CSourceCtxPopup* pCtxPopup = new CSourceCtxPopup;
224                                 m->pCtxPopup = pCtxPopup;
225                                 pCtxPopup->Create(m->eoBase, &cb);
226                         }
227                         else if (obj == m->eoBtnSort) {
228                                 CSortCtxPopup* pCtxPopup = new CSortCtxPopup;
229                                 m->pCtxPopup = pCtxPopup;
230                                 pCtxPopup->Create(m->eoBase, &cb);
231                         }
232                 }
233         } *pHandlerButton[TOTAL_TOP_BTNS];
234
235         class CHandlerGroup : public CListenerMgr, IMouseMoveListener, IKeyDownListener, IMouseClickedListener {
236         private:
237                 SFbBaseView *m;
238         public:
239                 CHandlerGroup(SFbBaseView *ins) :
240                         IMouseMoveListener(this),
241                         IKeyDownListener(this),
242                         IMouseClickedListener(this) { m = ins; }
243
244                 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
245                         _DBG("id = %d", id);
246                         if (!elm_object_focus_get(obj))
247                                 elm_object_focus_set(obj, EINA_TRUE);
248                 }
249                 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
250                         _DBG("id = %d", id);
251                         if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
252                                 elm_exit();
253                 }
254                 virtual void OnMouseClicked(int id, Evas_Object *obj) {
255                         if (m->eoSelectedBtnGroup == obj)
256                                 return;
257
258                         elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_UNSELECTED, "");
259                         m->eoSelectedBtnGroup = obj;
260                         elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_SELECTED, "");
261
262                         switch(id)
263                         {
264                                 case E_GRP_ALL:
265                                         m->curLayoutId = ALL_LAYOUT;
266                                         break;
267                                 case E_GRP_PHOTO:
268                                         m->curLayoutId = PHOTO_LAYOUT;
269                                         break;
270                                 case E_GRP_VIDEO:
271                                         m->curLayoutId = VIDEO_LAYOUT;
272                                         break;
273                                 case E_GRP_MUSIC:
274                                         m->curLayoutId = MUSIC_LAYOUT;
275                                         break;
276                                 default:
277                                         _ERR("Fix it: it can not make it , MouseClicked");
278                                         m->curLayoutId = ALL_LAYOUT; // default
279                                         break;
280                         }
281                         _DBG("id = %d, m->curLayoutId = %d", id, m->curLayoutId);
282                         m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
283                 }
284         } *pHandlerGroup[TOTAL_GROUP_BTNS];
285 };
286
287
288 Evas_Object *_add_button(Evas_Object *box)
289 {
290         Evas_Object *button;
291
292         if (!box)
293                 return NULL;
294
295         button = elm_button_add(box);
296         if (!button)
297                 return NULL;
298
299         evas_object_size_hint_weight_set(button,
300                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
301         evas_object_show(button);
302
303         return button;
304 }
305
306 void CFbBaseView::UpdateEmptyFocusSequence(void)
307 {
308         int i;
309         _DBG("");
310
311         for (i = 0; i < TOTAL_GROUP_BTNS; i++)
312                 elm_object_focus_next_object_set(m->eoBtnGroup[i], m->eoBtnSort, ELM_FOCUS_RIGHT);
313
314         elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL], m->eoBtnSort,              ELM_FOCUS_UP);
315         elm_object_focus_next_object_set(m->eoBtnSort,              m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
316         elm_object_focus_next_object_set(m->eoBtnSource,               m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
317
318         if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_ALL]) {
319                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_FILE_MESSAGE));
320                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_FILE_MESSAGE_SUB));
321         }
322         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_PHOTO]) {
323                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_PHOTO_MESSAGE));
324                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_PHOTO_MESSAGE_SUB));
325         }
326         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_VIDEO]) {
327                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_VIDEO_MESSAGE));
328                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_VIDEO_MESSAGE_SUB));
329         }
330         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_MUSIC]) {
331                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_MUSIC_MESSAGE));
332                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_MUSIC_MESSAGE_SUB));
333         }
334 }
335
336 void CFbBaseView::UnsetFocus(void)
337 {
338         elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
339 }
340
341 void CFbBaseView::CbLinkApp(int type, int source_type, char *path)
342 {
343         bundle *args;
344         int r;
345
346         args = bundle_create();
347         if (!args) {
348                 _ERR("unable to create bundle");
349                 return;
350         }
351
352         bundle_add(args, PARAM_SOURCE, source_arg[source_type]);
353         bundle_add(args, PARAM_URI, path);
354
355         r = aul_launch_app(linked_app[type], args);
356         if (args)
357                 bundle_free(args);
358         if (r < 0) {
359                 _ERR(" Unable to launch linked app");
360                 return;
361         }
362
363         return;
364 }
365
366 void CFbBaseView::UpdatedGrid(void)
367 {
368 #if 0 // It will be removed at soon.
369         int i;
370
371         for (i = 0; i < TOTAL_GROUP_BTNS; i++)
372                 elm_object_focus_next_object_set(m->eoBtnGroup[i],
373                 m->pFbAllLayout->Grid(), ELM_FOCUS_RIGHT);
374
375         elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL],
376                 m->eoBtnSort, ELM_FOCUS_UP);
377         elm_object_focus_next_object_set(m->eoBtnSort,
378                 m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_LEFT);
379         elm_object_focus_next_object_set(m->eoBtnSort,
380                 m->pFbAllLayout->Grid(), ELM_FOCUS_DOWN);
381         elm_object_focus_next_object_set(m->eoBtnSource,
382                 m->pFbAllLayout->Grid(), ELM_FOCUS_DOWN);
383
384 #endif
385         elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, "");
386         elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, "");
387 }
388
389 void CFbBaseView::t_CreateTopSession(void)
390 {
391         _DBG();
392         int i;
393         Evas_Object *btn;
394         struct _btn_info btninfo[TOTAL_TOP_BTNS];
395         btninfo[TOPBTN_SOURCE].style = FBR_STYLE_SOURCE_BTN;
396         btninfo[TOPBTN_SOURCE].part  = FBR_PART_SOURCE_HOVERSEL;
397         
398         btninfo[TOPBTN_SORT].style = FBR_STYLE_SORT_BTN;
399         btninfo[TOPBTN_SORT].part  = FBR_PART_SORT_HOVERSEL;
400
401         elm_object_part_text_set(m->eoBase, FBR_PART_TITLE,
402                 _(FBR_TEXT_TITLE));
403
404         for (i = 0; i < TOTAL_TOP_BTNS; i++) {
405                 btn = _add_button(m->eoBase);
406                 if (!btn) {
407                         _ERR(" Adding btn failed ");
408                         return;
409                 }
410
411                 elm_object_style_set(btn, btninfo[i].style);
412                 elm_object_part_content_set(m->eoBase, btninfo[i].part, btn);
413
414                 m->pHandlerButton[i]->Connect(btn);
415
416                 if (i == TOPBTN_SOURCE)
417                         m->eoBtnSource = btn;
418                 else if (i == TOPBTN_SORT)
419                         m->eoBtnSort = btn;
420         }
421
422         elm_object_text_set(m->eoBtnSource, _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
423         elm_object_text_set(m->eoBtnSort, _(CSortCtxPopup::SortText(CInfo::SortType())));
424 }
425
426 void CFbBaseView::t_CreateLeftSession(void)
427 {
428         _DBG();
429         Evas_Object *box, *ic;
430         int i;
431         char buf[MAX_LENGTH];
432         static struct _btn_info btninfo[TOTAL_GROUP_BTNS];
433         btninfo[E_GRP_ALL].txt = N_("ALL");
434         btninfo[E_GRP_ALL].icon_path = FBR_IMAGE_GRPBTN_ALL;
435         btninfo[E_GRP_PHOTO].txt = N_("PHOTO");
436         btninfo[E_GRP_PHOTO].icon_path = FBR_IMAGE_GRPBTN_PHOTO;
437         btninfo[E_GRP_VIDEO].txt = N_("VIDEO");
438         btninfo[E_GRP_VIDEO].icon_path = FBR_IMAGE_GRPBTN_VIDEO;
439         btninfo[E_GRP_MUSIC].txt = N_("MUSIC");
440         btninfo[E_GRP_MUSIC].icon_path = FBR_IMAGE_GRPBTN_MUSIC;
441
442         box = elm_box_add(m->eoBase);
443         if (!box)
444                 return;
445         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
446         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
447         evas_object_show(box);
448
449         for (i = 0; i < TOTAL_GROUP_BTNS; i++) {
450                 m->eoBtnGroup[i] = _add_button(box);
451                 if (!m->eoBtnGroup[i]) {
452                         _ERR(" failed to add button to box ");
453                         continue;
454                 }
455
456                 elm_box_pack_end(box, m->eoBtnGroup[i]);
457                 elm_object_style_set(m->eoBtnGroup[i], FBR_STYLE_GROUPBTN);
458                 elm_object_text_set(m->eoBtnGroup[i], _(btninfo[i].txt));
459                 
460                 m->pHandlerGroup[i]->Connect(m->eoBtnGroup[i], i);
461
462                 ic = elm_image_add(m->eoBtnGroup[i]);
463                 if (!ic)
464                         continue;
465                 _DBG("");
466
467                 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
468                         btninfo[i].icon_path);
469                 elm_image_file_set(ic, buf, NULL);
470                 elm_object_part_content_set(m->eoBtnGroup[i],
471                         FBR_PART_ELM_SWALLOWICON, ic);
472         }
473         _DBG("");
474
475         t_SetSelectedGroupButton(m->eoBtnGroup[E_GRP_ALL]);
476         _DBG("");
477
478         elm_object_signal_emit(m->eoBtnGroup[E_GRP_ALL],
479                 FBR_SIGNAL_GROUP_SELECTED, "");
480         elm_object_focus_set(m->eoBtnGroup[E_GRP_ALL], EINA_TRUE);
481         elm_object_part_content_set(m->eoBase, FBR_PART_GROUPBTN_BOX, box);
482 }
483
484 void CFbBaseView::t_CreateFullView(void)
485 {
486         _DBG();
487         t_CreateTopSession();
488         t_CreateLeftSession();
489         m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
490 }
491
492 void CFbBaseView::t_SetSelectedGroupButton(Evas_Object* obj)
493 {
494         m->eoSelectedBtnGroup = obj;
495         int idx = -1;
496
497         int a;
498         for (a = 0; a < TOTAL_GROUP_BTNS; a++) {
499                 if (m->eoBtnGroup[a] == obj)
500                         idx = a;
501         }
502         CInfo::SetGroupIndex(idx);
503 }
504
505 Evas_Object* CFbBaseView::t_SelectedGroupButton(void)
506 {
507         return m->eoSelectedBtnGroup;
508 }
509
510 void CFbBaseView::t_OnShow(void)
511 {
512         _DBG();
513
514         evas_object_show(m->eoBase);
515
516         CBaseView::t_OnShow();
517 }
518
519 void CFbBaseView::t_OnUpdate(void *data)
520 {
521         switch(m->curLayoutId)
522         {
523                 case ALL_LAYOUT:
524                         m->pFbAllLayout->Action();
525                         break;
526                 case PHOTO_LAYOUT:
527                         m->pFbPhotoLayout->Action();
528                         break;
529                 case VIDEO_LAYOUT:
530                         m->pFbVideoLayout->Action();
531                         break;
532                 case MUSIC_LAYOUT:
533                         m->pFbMusicLayout->Action();
534                         break;
535         }
536 }
537
538 void CFbBaseView::t_OnHide(void)
539 {
540         evas_object_hide(m->eoBase);
541
542         CBaseView::t_OnHide();
543 }
544
545 bool CFbBaseView::Create(void *data)
546 {
547         ASSERT(!m);
548
549         Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
550         Evas_Object *eoBase = NULL;
551
552         int source_type = E_ALL;
553
554         _CREATE_BEGIN{
555                 _CHECK(m = new SFbBaseView)
556                 _CHECK(eoBase = elm_layout_add(eoWin))
557                 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_BASE_VIEW))
558                 _COMMAND{
559                         evas_object_size_hint_weight_set(eoBase, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
560                         elm_win_resize_object_add(eoWin, eoBase);
561
562                         /* get the source_type using 'data' string */
563                         if (data) {
564                                 // Find Index
565                                 int i;
566                                 int arrsize = ARRAY_SIZE(source_arg);
567                                 for (i = 0; i < arrsize; i++) {
568                                         if (source_arg[i] && !strcmp(source_arg[i], (const char*)data)) {
569                                                 source_type = i;
570                                                 break;
571                                         }
572                                 }
573                                 if (source_type < E_ALL || source_type > E_USB)
574                                         source_type = E_ALL;
575                                 CInfo::SetSourceType(source_type);
576                                 m->eoWin = eoWin;
577                                 m->eoBase = eoBase;
578                         }
579                 }
580                 _CHECK(m->pLayoutMgr = new CLayoutMgr)
581                 _CHECK(m->pLayoutMgr->Create(eoBase, NULL))
582                 _CHECK(m->pFbAllLayout = new CFbAllLayout(FB_ALL_LAYOUT))
583                 _CHECK(m->pFbPhotoLayout = new CFbPhotoLayout(FB_PHOTO_LAYOUT))
584                 _CHECK(m->pFbVideoLayout = new CFbVideoLayout(FB_VIDEO_LAYOUT))
585                 _CHECK(m->pFbMusicLayout = new CFbMusicLayout(FB_MUSIC_LAYOUT))
586                 _CHECK(m->pFbAllLayout->Create(m->pLayoutMgr, NULL))
587                 _CHECK(m->pFbPhotoLayout->Create(m->pLayoutMgr, NULL))
588                 _CHECK(m->pFbVideoLayout->Create(m->pLayoutMgr, NULL))
589                 _CHECK(m->pFbMusicLayout->Create(m->pLayoutMgr, NULL))
590                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbAllLayout))
591                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbPhotoLayout))
592                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbVideoLayout))
593                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbMusicLayout))
594                 _CHECK(CUsbConnectionListener::Create())
595                 _CHECK(CMediaContentDbUpdateListener::Create())
596
597                 _WHEN_SUCCESS{}
598
599                 _CHECK_FAIL{ CMediaContentDbUpdateListener::Destroy(); }
600                 _CHECK_FAIL{ CUsbConnectionListener::Destroy(); }
601                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbMusicLayout); }
602                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbVideoLayout); }
603                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbPhotoLayout); }
604                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbAllLayout); }
605                 _CHECK_FAIL{ m->pFbMusicLayout->Destroy(); }
606                 _CHECK_FAIL{ m->pFbVideoLayout->Destroy(); }
607                 _CHECK_FAIL{ m->pFbPhotoLayout->Destroy(); }
608                 _CHECK_FAIL{ m->pFbAllLayout->Destroy(); }
609                 _CHECK_FAIL{ delete m->pFbMusicLayout; m->pFbMusicLayout = NULL; }
610                 _CHECK_FAIL{ delete m->pFbVideoLayout; m->pFbVideoLayout = NULL; }
611                 _CHECK_FAIL{ delete m->pFbPhotoLayout; m->pFbPhotoLayout = NULL; }
612                 _CHECK_FAIL{ delete m->pFbAllLayout; m->pFbAllLayout = NULL; }
613                 _CHECK_FAIL{ m->pLayoutMgr->Destroy(); }
614                 _CHECK_FAIL{ delete m->pLayoutMgr; m->pLayoutMgr = NULL; }
615                 _CHECK_FAIL{ /* elm_layout_file_set*/ }
616                 _CHECK_FAIL{ evas_object_del(eoBase); }
617                 _CHECK_FAIL{ delete m; m = NULL; }
618         } _CREATE_END_AND_CATCH{ return false; }
619
620
621         // original create grid
622         CInfo::SetSortType(0/*CSort::SORT_NAME_AZ*/);
623         evas_object_data_set(eoBase, BASE_VIEW_DATA, this);
624         m->curLayoutId = ALL_LAYOUT;    
625         _DBG("curLayoutId = %s", _get_layout_id(m->curLayoutId));
626         t_CreateFullView();
627         elm_object_focus_allow_set(eoBase, EINA_FALSE);
628         m->pHandlerBase->Connect(eoBase);
629         CBaseView::Create(NULL);
630         return true;
631 }
632
633 void CFbBaseView::Destroy(void)
634 {
635         ASSERT(m);
636
637         CBaseView::Destroy();
638         CMediaContentDbUpdateListener::Destroy();
639         CUsbConnectionListener::Destroy();
640
641         m->pLayoutMgr->RemoveLayout(m->pFbMusicLayout);
642         m->pFbMusicLayout->Destroy();
643         delete m->pFbMusicLayout;
644         
645         m->pLayoutMgr->RemoveLayout(m->pFbVideoLayout);
646         m->pFbVideoLayout->Destroy();
647         delete m->pFbVideoLayout;
648
649         m->pLayoutMgr->RemoveLayout(m->pFbPhotoLayout);
650         m->pFbPhotoLayout->Destroy();
651         delete m->pFbPhotoLayout;
652
653         m->pLayoutMgr->RemoveLayout(m->pFbAllLayout);
654         m->pFbAllLayout->Destroy();
655         delete m->pFbAllLayout;
656
657         m->pLayoutMgr->Destroy();
658         delete m->pLayoutMgr;
659
660         evas_object_del(m->eoBase);
661
662         delete m;
663         m = NULL;
664 }
665
666
667 Evas_Object* CFbBaseView::Base(void)
668 {
669         ASSERT(m);
670
671         return m->eoBase;
672 }
673
674
675 void CFbBaseView::OnConnect(void)
676 {
677         m->pPopup = new CPopup;
678         if (!m->pPopup)
679                 return;
680         if (!m->pPopup->Create(m->eoBase)) {
681                 delete m->pPopup;
682                 m->pPopup = NULL;
683                 return;
684         }
685
686         if (CInfo::SourceType() == E_USB) {
687                 if (!FlagConnected()) {
688                         CInfo::SetSourceType(E_ALL);
689                         elm_object_text_set(m->eoBtnSource,
690                                 _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
691                 }
692         }
693 }
694
695
696 void CFbBaseView::OnUpdated(const SEntity *entity)
697 {
698         _DBG();
699         m->pPopup->Destroy();
700         delete m->pPopup;
701         m->pPopup = NULL;
702
703         if (m->pCtxPopup) {
704                 m->pCtxPopup->Destroy();
705                 delete m->pCtxPopup;
706                 m->pCtxPopup = NULL;
707         }
708         if (CInfo::SourceType() != E_TV) {
709                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
710                 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
711         }
712 }
713