3a98993a7271a18b55738b62a1458d794c82cdcf
[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, public IKeyUpListener{
145                 SFbBaseView *m;
146
147         public:
148                 CHandlerBase(SFbBaseView *ins) : IKeyDownListener(this), IKeyUpListener(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                 }
155                 virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
156                 {
157                         _DBG("m->curLayoutId = %d",m->curLayoutId);
158                         if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
159                                 if (elm_object_focus_get(m->eoSelectedBtnGroup)) {
160                                         switch(m->curLayoutId)
161                                         {
162                                                 case ALL_LAYOUT:
163                                                         m->pFbAllLayout->SetFocus(EINA_TRUE);
164                                                         break;
165                                                 case PHOTO_LAYOUT:
166                                                         m->pFbPhotoLayout->SetFocus(EINA_TRUE);
167                                                         break;
168                                                 case VIDEO_LAYOUT:
169                                                         m->pFbVideoLayout->SetFocus(EINA_TRUE);
170                                                         break;
171                                                 case MUSIC_LAYOUT:
172                                                         m->pFbMusicLayout->SetFocus(EINA_TRUE);
173                                                         break;
174                                         }
175                                 }
176                         }
177
178                 }
179         } *pHandlerBase;
180
181         class CHandlerButton : public CListenerMgr, protected IKeyDownListener, IMouseMoveListener, IMouseClickedListener {
182         private:
183                 SFbBaseView *m;
184         private:
185                 static void sm_CbCtxPopupSelected(void* cookie, CCtxPopup* instance, const char* text)
186                 {
187                         SFbBaseView* m = (SFbBaseView*)cookie;
188                         if (!m)
189                                 return;
190
191                         _DBG(" instance->Type(): %d", instance->Type());
192                         switch (instance->Type()) {
193                         case CCtxPopup::TOPBTN_SORT:
194                                 elm_object_text_set(m->eoBtnSort, text);
195                                 switch(m->curLayoutId)
196                                 {
197                                         case ALL_LAYOUT:
198                                                 m->pFbAllLayout->SetUpdateFlag(true);
199                                                 break;
200                                         case PHOTO_LAYOUT:
201                                                 m->pFbPhotoLayout->SetUpdateFlag(true);
202                                                 break;
203                                         case VIDEO_LAYOUT:
204                                                 m->pFbVideoLayout->SetUpdateFlag(true);
205                                                 break;
206                                         case MUSIC_LAYOUT:
207                                                 m->pFbMusicLayout->SetUpdateFlag(true);
208                                                 break;
209                                 }
210                                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
211                                 break;
212
213                         case CCtxPopup::TOPBTN_SOURCE:
214                                 elm_object_text_set(m->eoBtnSource, text);
215                                 switch(m->curLayoutId)
216                                 {
217                                         case ALL_LAYOUT:
218                                                 m->pFbAllLayout->SetUpdateFlag(true);
219                                                 break;
220                                         case PHOTO_LAYOUT:
221                                                 m->pFbPhotoLayout->SetUpdateFlag(true);
222                                                 break;
223                                         case VIDEO_LAYOUT:
224                                                 m->pFbVideoLayout->SetUpdateFlag(true);
225                                                 break;
226                                         case MUSIC_LAYOUT:
227                                                 m->pFbMusicLayout->SetUpdateFlag(true);
228                                                 break;
229                                 }
230                                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
231                                 break;
232
233                         default:
234                                 break;
235                         }
236                 }
237
238         public:
239                 CHandlerButton(SFbBaseView *ins) : IKeyDownListener(this), IMouseMoveListener(this), IMouseClickedListener(this) { m = ins; }
240
241                 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
242                         _DBG("id = %d", id);
243                         if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
244                                 elm_object_focus_set(m->eoSelectedBtnGroup, EINA_TRUE);
245                 }
246                 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
247                         _DBG("id = %d", id);
248                         if (!elm_object_focus_get(obj))
249                                 elm_object_focus_set(obj, EINA_TRUE);
250                 }
251                 virtual void OnMouseClicked(int id, Evas_Object *obj) {
252                         _DBG("id = %d", id);
253                         CSourceCtxPopup::SCallback cb;
254                         cb.cookie = m;
255                         cb.onSelected = sm_CbCtxPopupSelected;
256
257                         if (obj == m->eoBtnSource) {
258                                 CSourceCtxPopup* pCtxPopup = new CSourceCtxPopup;
259                                 m->pCtxPopup = pCtxPopup;
260                                 pCtxPopup->Create(m->eoBase, &cb);
261                         }
262                         else if (obj == m->eoBtnSort) {
263                                 CSortCtxPopup* pCtxPopup = new CSortCtxPopup;
264                                 m->pCtxPopup = pCtxPopup;
265                                 pCtxPopup->Create(m->eoBase, &cb);
266                         }
267                 }
268         } *pHandlerButton[TOTAL_TOP_BTNS];
269
270         class CHandlerGroup : public CListenerMgr, IMouseMoveListener, IKeyDownListener, IMouseClickedListener {
271         private:
272                 SFbBaseView *m;
273         public:
274                 CHandlerGroup(SFbBaseView *ins) :
275                         IMouseMoveListener(this),
276                         IKeyDownListener(this),
277                         IMouseClickedListener(this) { m = ins; }
278
279                 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
280                         _DBG("id = %d", id);
281                         if (!elm_object_focus_get(obj))
282                                 elm_object_focus_set(obj, EINA_TRUE);
283                 }
284                 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
285                         _DBG("id = %d", id);
286                         if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
287                                 elm_exit();
288                 }
289                 virtual void OnMouseClicked(int id, Evas_Object *obj) {
290                         if (m->eoSelectedBtnGroup == obj)
291                                 return;
292
293                         elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_UNSELECTED, "");
294                         m->eoSelectedBtnGroup = obj;
295                         elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_SELECTED, "");
296
297                         switch(id)
298                         {
299                                 case E_GRP_ALL:
300                                         m->curLayoutId = ALL_LAYOUT;
301                                         break;
302                                 case E_GRP_PHOTO:
303                                         m->curLayoutId = PHOTO_LAYOUT;
304                                         break;
305                                 case E_GRP_VIDEO:
306                                         m->curLayoutId = VIDEO_LAYOUT;
307                                         break;
308                                 case E_GRP_MUSIC:
309                                         m->curLayoutId = MUSIC_LAYOUT;
310                                         break;
311                                 default:
312                                         _ERR("Fix it: it can not make it , MouseClicked");
313                                         m->curLayoutId = ALL_LAYOUT; // default
314                                         break;
315                         }
316                         _DBG("id = %d, m->curLayoutId = %d", id, m->curLayoutId);
317                         m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
318                 }
319         } *pHandlerGroup[TOTAL_GROUP_BTNS];
320 };
321
322
323 Evas_Object *_add_button(Evas_Object *box)
324 {
325         Evas_Object *button;
326
327         if (!box)
328                 return NULL;
329
330         button = elm_button_add(box);
331         if (!button)
332                 return NULL;
333
334         evas_object_size_hint_weight_set(button,
335                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
336         evas_object_show(button);
337
338         return button;
339 }
340
341 void CFbBaseView::UpdateEmptyFocusSequence(void)
342 {
343         _DBG("");
344
345         if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_ALL]) {
346                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_FILE_MESSAGE));
347                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_FILE_MESSAGE_SUB));
348         }
349         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_PHOTO]) {
350                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_PHOTO_MESSAGE));
351                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_PHOTO_MESSAGE_SUB));
352         }
353         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_VIDEO]) {
354                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_VIDEO_MESSAGE));
355                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_VIDEO_MESSAGE_SUB));
356         }
357         else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_MUSIC]) {
358                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT,     _(NO_MUSIC_MESSAGE));
359                 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_MUSIC_MESSAGE_SUB));
360         }
361 }
362
363 void CFbBaseView::UnsetFocus(void)
364 {
365         elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
366 }
367
368 void CFbBaseView::CbLinkApp(int type, int source_type, char *path)
369 {
370         bundle *args;
371         int r;
372
373         args = bundle_create();
374         if (!args) {
375                 _ERR("unable to create bundle");
376                 return;
377         }
378
379         bundle_add(args, PARAM_SOURCE, source_arg[source_type]);
380         bundle_add(args, PARAM_URI, path);
381
382         r = aul_launch_app(linked_app[type], args);
383         if (args)
384                 bundle_free(args);
385         if (r < 0) {
386                 _ERR(" Unable to launch linked app");
387                 return;
388         }
389
390         return;
391 }
392
393 void CFbBaseView::UpdatedGrid(void)
394 {
395         elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, "");
396         elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, "");
397 }
398
399 void CFbBaseView::t_CreateTopSession(void)
400 {
401         _DBG();
402         int i;
403         Evas_Object *btn;
404         struct _btn_info btninfo[TOTAL_TOP_BTNS];
405         btninfo[TOPBTN_SOURCE].style = FBR_STYLE_SOURCE_BTN;
406         btninfo[TOPBTN_SOURCE].part  = FBR_PART_SOURCE_HOVERSEL;
407
408         btninfo[TOPBTN_SORT].style = FBR_STYLE_SORT_BTN;
409         btninfo[TOPBTN_SORT].part  = FBR_PART_SORT_HOVERSEL;
410
411         elm_object_part_text_set(m->eoBase, FBR_PART_TITLE,
412                 _(FBR_TEXT_TITLE));
413
414         for (i = 0; i < TOTAL_TOP_BTNS; i++) {
415                 btn = _add_button(m->eoBase);
416                 if (!btn) {
417                         _ERR(" Adding btn failed ");
418                         return;
419                 }
420
421                 elm_object_style_set(btn, btninfo[i].style);
422                 elm_object_part_content_set(m->eoBase, btninfo[i].part, btn);
423
424                 m->pHandlerButton[i]->Connect(btn);
425
426                 if (i == TOPBTN_SOURCE)
427                         m->eoBtnSource = btn;
428                 else if (i == TOPBTN_SORT)
429                         m->eoBtnSort = btn;
430         }
431
432         elm_object_text_set(m->eoBtnSource, _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
433         elm_object_text_set(m->eoBtnSort, _(CSortCtxPopup::SortText(CInfo::SortType())));
434 }
435
436 void CFbBaseView::t_CreateLeftSession(void)
437 {
438         _DBG();
439         Evas_Object *box, *ic;
440         int i;
441         char buf[MAX_LENGTH];
442         static struct _btn_info btninfo[TOTAL_GROUP_BTNS];
443         btninfo[E_GRP_ALL].txt = N_("ALL");
444         btninfo[E_GRP_ALL].icon_path = FBR_IMAGE_GRPBTN_ALL;
445         btninfo[E_GRP_PHOTO].txt = N_("PHOTO");
446         btninfo[E_GRP_PHOTO].icon_path = FBR_IMAGE_GRPBTN_PHOTO;
447         btninfo[E_GRP_VIDEO].txt = N_("VIDEO");
448         btninfo[E_GRP_VIDEO].icon_path = FBR_IMAGE_GRPBTN_VIDEO;
449         btninfo[E_GRP_MUSIC].txt = N_("MUSIC");
450         btninfo[E_GRP_MUSIC].icon_path = FBR_IMAGE_GRPBTN_MUSIC;
451
452         box = elm_box_add(m->eoBase);
453         if (!box)
454                 return;
455         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
456         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
457         evas_object_show(box);
458
459         for (i = 0; i < TOTAL_GROUP_BTNS; i++) {
460                 m->eoBtnGroup[i] = _add_button(box);
461                 if (!m->eoBtnGroup[i]) {
462                         _ERR(" failed to add button to box ");
463                         continue;
464                 }
465
466                 elm_box_pack_end(box, m->eoBtnGroup[i]);
467                 elm_object_style_set(m->eoBtnGroup[i], FBR_STYLE_GROUPBTN);
468                 elm_object_text_set(m->eoBtnGroup[i], _(btninfo[i].txt));
469
470                 m->pHandlerGroup[i]->Connect(m->eoBtnGroup[i], i);
471
472                 ic = elm_image_add(m->eoBtnGroup[i]);
473                 if (!ic)
474                         continue;
475
476                 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
477                         btninfo[i].icon_path);
478                 elm_image_file_set(ic, buf, NULL);
479                 elm_object_part_content_set(m->eoBtnGroup[i],
480                         FBR_PART_ELM_SWALLOWICON, ic);
481         }
482
483         t_SetSelectedGroupButton(m->eoBtnGroup[E_GRP_ALL]);
484
485         elm_object_signal_emit(m->eoBtnGroup[E_GRP_ALL], FBR_SIGNAL_GROUP_SELECTED, "");
486         elm_object_focus_set(m->eoBtnGroup[E_GRP_ALL], EINA_TRUE);
487         elm_object_part_content_set(m->eoBase, FBR_PART_GROUPBTN_BOX, box);
488
489         elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL], m->eoBtnGroup[E_GRP_MUSIC], ELM_FOCUS_UP);
490         elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_MUSIC], m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
491 }
492
493 void CFbBaseView::t_CreateFullView(void)
494 {
495         _DBG();
496         t_CreateTopSession();
497         t_CreateLeftSession();
498         m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
499 }
500
501 void CFbBaseView::t_SetSelectedGroupButton(Evas_Object* obj)
502 {
503
504         for (int a = 0; a < TOTAL_GROUP_BTNS; a++) {
505                 if (m->eoBtnGroup[a] == obj)
506                 {
507                         m->eoSelectedBtnGroup = obj;
508                         CInfo::SetGroupIndex(a);
509                         break;
510                 }
511         }
512 }
513
514 Evas_Object* CFbBaseView::t_SelectedGroupButton(void)
515 {
516         return m->eoSelectedBtnGroup;
517 }
518
519 void CFbBaseView::t_OnShow(void)
520 {
521         _DBG();
522
523         evas_object_show(m->eoBase);
524
525         CBaseView::t_OnShow();
526 }
527
528 void CFbBaseView::t_OnUpdate(void *data)
529 {
530         switch(m->curLayoutId)
531         {
532                 case ALL_LAYOUT:
533                         m->pFbAllLayout->Action();
534                         break;
535                 case PHOTO_LAYOUT:
536                         m->pFbPhotoLayout->Action();
537                         break;
538                 case VIDEO_LAYOUT:
539                         m->pFbVideoLayout->Action();
540                         break;
541                 case MUSIC_LAYOUT:
542                         m->pFbMusicLayout->Action();
543                         break;
544         }
545 }
546
547 void CFbBaseView::t_OnHide(void)
548 {
549         evas_object_hide(m->eoBase);
550
551         CBaseView::t_OnHide();
552 }
553
554 bool CFbBaseView::Create(void *data)
555 {
556         ASSERT(!m);
557
558         Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
559         Evas_Object *eoBase = NULL;
560
561         int source_type = E_ALL;
562
563         _CREATE_BEGIN{
564                 _CHECK(m = new SFbBaseView)
565                 _CHECK(eoBase = elm_layout_add(eoWin))
566                 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_BASE_VIEW))
567                 _COMMAND{
568                         evas_object_size_hint_weight_set(eoBase, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
569                         elm_win_resize_object_add(eoWin, eoBase);
570
571                         /* get the source_type using 'data' string */
572                         if (data) {
573                                 // Find Index
574                                 int i;
575                                 int arrsize = ARRAY_SIZE(source_arg);
576                                 for (i = 0; i < arrsize; i++) {
577                                         if (source_arg[i] && !strcmp(source_arg[i], (const char*)data)) {
578                                                 source_type = i;
579                                                 break;
580                                         }
581                                 }
582                                 if (source_type < E_ALL || source_type > E_USB)
583                                         source_type = E_ALL;
584                                 CInfo::SetSourceType(source_type);
585                                 m->eoWin = eoWin;
586                                 m->eoBase = eoBase;
587                         }
588                 }
589                 _CHECK(m->pLayoutMgr = new CLayoutMgr)
590                 _CHECK(m->pLayoutMgr->Create(eoBase, NULL))
591                 _CHECK(m->pFbAllLayout = new CFbAllLayout(FB_ALL_LAYOUT))
592                 _CHECK(m->pFbPhotoLayout = new CFbPhotoLayout(FB_PHOTO_LAYOUT))
593                 _CHECK(m->pFbVideoLayout = new CFbVideoLayout(FB_VIDEO_LAYOUT))
594                 _CHECK(m->pFbMusicLayout = new CFbMusicLayout(FB_MUSIC_LAYOUT))
595                 _CHECK(m->pFbAllLayout->Create(m->pLayoutMgr, NULL))
596                 _CHECK(m->pFbPhotoLayout->Create(m->pLayoutMgr, NULL))
597                 _CHECK(m->pFbVideoLayout->Create(m->pLayoutMgr, NULL))
598                 _CHECK(m->pFbMusicLayout->Create(m->pLayoutMgr, NULL))
599                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbAllLayout))
600                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbPhotoLayout))
601                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbVideoLayout))
602                 _CHECK(m->pLayoutMgr->AddLayout(m->pFbMusicLayout))
603                 _COMMAND{
604                         if(!CUsbConnectionListener::Create())
605                                 _ERR("Fail to create CUsbConnectionListener()");
606                         if(!CMediaContentDbUpdateListener::Create())
607                                 _ERR("Fail to create CMediaContentDbUpdateListener()");
608                 }
609                 _WHEN_SUCCESS{}
610
611                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbMusicLayout); }
612                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbVideoLayout); }
613                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbPhotoLayout); }
614                 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbAllLayout); }
615                 _CHECK_FAIL{ m->pFbMusicLayout->Destroy(); }
616                 _CHECK_FAIL{ m->pFbVideoLayout->Destroy(); }
617                 _CHECK_FAIL{ m->pFbPhotoLayout->Destroy(); }
618                 _CHECK_FAIL{ m->pFbAllLayout->Destroy(); }
619                 _CHECK_FAIL{ delete m->pFbMusicLayout; m->pFbMusicLayout = NULL; }
620                 _CHECK_FAIL{ delete m->pFbVideoLayout; m->pFbVideoLayout = NULL; }
621                 _CHECK_FAIL{ delete m->pFbPhotoLayout; m->pFbPhotoLayout = NULL; }
622                 _CHECK_FAIL{ delete m->pFbAllLayout; m->pFbAllLayout = NULL; }
623                 _CHECK_FAIL{ m->pLayoutMgr->Destroy(); }
624                 _CHECK_FAIL{ delete m->pLayoutMgr; m->pLayoutMgr = NULL; }
625                 _CHECK_FAIL{ /* elm_layout_file_set*/ }
626                 _CHECK_FAIL{ evas_object_del(eoBase); }
627                 _CHECK_FAIL{ delete m; m = NULL; }
628         } _CREATE_END_AND_CATCH{ return false; }
629
630
631         // original create grid
632         CInfo::SetSortType(0/*CSort::SORT_NAME_AZ*/);
633         evas_object_data_set(eoBase, BASE_VIEW_DATA, this);
634         m->curLayoutId = ALL_LAYOUT;
635         _DBG("curLayoutId = %s", _get_layout_id(m->curLayoutId));
636         t_CreateFullView();
637         elm_object_focus_allow_set(eoBase, EINA_FALSE);
638         m->pHandlerBase->Connect(eoBase);
639         CBaseView::Create(NULL);
640         return true;
641 }
642
643 void CFbBaseView::Destroy(void)
644 {
645         ASSERT(m);
646
647         CBaseView::Destroy();
648
649         if(CMediaContentDbUpdateListener::FlagCreate())
650                 CMediaContentDbUpdateListener::Destroy();
651         if(CUsbConnectionListener::FlagCreate())
652                 CUsbConnectionListener::Destroy();
653
654         m->pLayoutMgr->RemoveLayout(m->pFbMusicLayout);
655         m->pFbMusicLayout->Destroy();
656         delete m->pFbMusicLayout;
657
658         m->pLayoutMgr->RemoveLayout(m->pFbVideoLayout);
659         m->pFbVideoLayout->Destroy();
660         delete m->pFbVideoLayout;
661
662         m->pLayoutMgr->RemoveLayout(m->pFbPhotoLayout);
663         m->pFbPhotoLayout->Destroy();
664         delete m->pFbPhotoLayout;
665
666         m->pLayoutMgr->RemoveLayout(m->pFbAllLayout);
667         m->pFbAllLayout->Destroy();
668         delete m->pFbAllLayout;
669
670         m->pLayoutMgr->Destroy();
671         delete m->pLayoutMgr;
672
673         evas_object_del(m->eoBase);
674
675         delete m;
676         m = NULL;
677 }
678
679
680 Evas_Object* CFbBaseView::Base(void)
681 {
682         ASSERT(m);
683
684         return m->eoBase;
685 }
686
687
688 void CFbBaseView::OnStatusChanged(SUsbHostDeviceStatus status)
689 {
690         if(status == USB_HOST_DEV_CONNECTED) {
691                 m->pPopup = new CPopup;
692                 if (!m->pPopup)
693                         return;
694                 if (!m->pPopup->Create(m->eoBase)) {
695                         delete m->pPopup;
696                         m->pPopup = NULL;
697                         return;
698                 }
699
700                 if (CInfo::SourceType() == E_USB) {
701                         if (!FlagConnected()) {
702                                 CInfo::SetSourceType(E_ALL);
703                                 elm_object_text_set(m->eoBtnSource,
704                                                 _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
705                         }
706                 }
707         }
708         /* FIXME: should add disconnected flow */
709 }
710
711
712 void CFbBaseView::OnUpdated(const SEntity *entity)
713 {
714         _DBG();
715         m->pPopup->Destroy();
716         delete m->pPopup;
717         m->pPopup = NULL;
718
719         if (m->pCtxPopup) {
720                 m->pCtxPopup->Destroy();
721                 delete m->pCtxPopup;
722                 m->pCtxPopup = NULL;
723         }
724         if (CInfo::SourceType() != E_TV) {
725                 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
726                 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
727         }
728 }
729