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