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>
24 #include "AppCommon.h"
25 #include "ExtNameInfo.h"
28 #include <MediaContentDbListener.h>
29 #include <UsbConnectionListener.h>
31 #include "InputHandler.h"
36 #include "FbBaseView.h"
39 #include "SourceCtxPopup.h"
40 #include "SortCtxPopup.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"
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"
60 const char *icon_path;
75 const char *source_arg[] = {
81 const char *linked_app[] = {
83 N_("org.tizen.gallery-tv-ref"),
84 N_("org.tizen.video-player-tv-ref"),
85 N_("org.tizen.music-player-tv-ref"),
89 const char* _get_layout_id(int curLayoutId){
95 return FB_PHOTO_LAYOUT;
97 return FB_VIDEO_LAYOUT;
99 return FB_MUSIC_LAYOUT;
101 return FB_ALL_LAYOUT; // default
107 Evas_Object *eoBtnGroup[TOTAL_GROUP_BTNS];
108 Evas_Object *eoSelectedBtnGroup;//Evas_Object *c_grpbtn;
109 Evas_Object *eoBtnSource;
110 Evas_Object *eoBtnSort;
112 CCtxPopup *pCtxPopup;
115 CLayoutMgr *pLayoutMgr;
118 CFbAllLayout *pFbAllLayout;
119 CFbPhotoLayout *pFbPhotoLayout;
120 CFbVideoLayout *pFbVideoLayout;
121 CFbMusicLayout *pFbMusicLayout;
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);
134 virtual ~SFbBaseView() {
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];
144 class CHandlerBase : public CListenerMgr, public IKeyDownListener {
148 CHandlerBase(SFbBaseView *ins) : IKeyDownListener(this) { m = ins; }
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))
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)
159 m->pFbAllLayout->SetFocus(EINA_TRUE);
162 m->pFbPhotoLayout->SetFocus(EINA_TRUE);
165 m->pFbVideoLayout->SetFocus(EINA_TRUE);
168 m->pFbMusicLayout->SetFocus(EINA_TRUE);
176 class CHandlerButton : public CListenerMgr, protected IKeyDownListener, IMouseMoveListener, IMouseClickedListener {
180 static void sm_CbCtxPopupSelected(void* cookie, CCtxPopup* instance, const char* text)
182 SFbBaseView* m = (SFbBaseView*)cookie;
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));
193 case CCtxPopup::TOPBTN_SOURCE:
194 elm_object_text_set(m->eoBtnSource, text);
195 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
204 CHandlerButton(SFbBaseView *ins) : IKeyDownListener(this), IMouseMoveListener(this), IMouseClickedListener(this) { m = ins; }
206 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
208 if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
209 elm_object_focus_set(m->eoSelectedBtnGroup, EINA_TRUE);
211 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
213 if (!elm_object_focus_get(obj))
214 elm_object_focus_set(obj, EINA_TRUE);
216 virtual void OnMouseClicked(int id, Evas_Object *obj) {
218 CSourceCtxPopup::SCallback cb;
220 cb.onSelected = sm_CbCtxPopupSelected;
222 if (obj == m->eoBtnSource) {
223 CSourceCtxPopup* pCtxPopup = new CSourceCtxPopup;
224 m->pCtxPopup = pCtxPopup;
225 pCtxPopup->Create(m->eoBase, &cb);
227 else if (obj == m->eoBtnSort) {
228 CSortCtxPopup* pCtxPopup = new CSortCtxPopup;
229 m->pCtxPopup = pCtxPopup;
230 pCtxPopup->Create(m->eoBase, &cb);
233 } *pHandlerButton[TOTAL_TOP_BTNS];
235 class CHandlerGroup : public CListenerMgr, IMouseMoveListener, IKeyDownListener, IMouseClickedListener {
239 CHandlerGroup(SFbBaseView *ins) :
240 IMouseMoveListener(this),
241 IKeyDownListener(this),
242 IMouseClickedListener(this) { m = ins; }
244 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
246 if (!elm_object_focus_get(obj))
247 elm_object_focus_set(obj, EINA_TRUE);
249 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
251 if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
254 virtual void OnMouseClicked(int id, Evas_Object *obj) {
255 if (m->eoSelectedBtnGroup == obj)
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, "");
265 m->curLayoutId = ALL_LAYOUT;
268 m->curLayoutId = PHOTO_LAYOUT;
271 m->curLayoutId = VIDEO_LAYOUT;
274 m->curLayoutId = MUSIC_LAYOUT;
277 _ERR("Fix it: it can not make it , MouseClicked");
278 m->curLayoutId = ALL_LAYOUT; // default
281 _DBG("id = %d, m->curLayoutId = %d", id, m->curLayoutId);
282 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
284 } *pHandlerGroup[TOTAL_GROUP_BTNS];
288 Evas_Object *_add_button(Evas_Object *box)
295 button = elm_button_add(box);
299 evas_object_size_hint_weight_set(button,
300 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
301 evas_object_show(button);
306 void CFbBaseView::UpdateEmptyFocusSequence(void)
311 for (i = 0; i < TOTAL_GROUP_BTNS; i++)
312 elm_object_focus_next_object_set(m->eoBtnGroup[i], m->eoBtnSort, ELM_FOCUS_RIGHT);
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);
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));
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));
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));
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));
336 void CFbBaseView::UnsetFocus(void)
338 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
341 void CFbBaseView::CbLinkApp(int type, int source_type, char *path)
346 args = bundle_create();
348 _ERR("unable to create bundle");
352 bundle_add(args, PARAM_SOURCE, source_arg[source_type]);
353 bundle_add(args, PARAM_URI, path);
355 r = aul_launch_app(linked_app[type], args);
359 _ERR(" Unable to launch linked app");
366 void CFbBaseView::UpdatedGrid(void)
368 #if 0 // It will be removed at soon.
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);
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);
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, "");
389 void CFbBaseView::t_CreateTopSession(void)
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;
398 btninfo[TOPBTN_SORT].style = FBR_STYLE_SORT_BTN;
399 btninfo[TOPBTN_SORT].part = FBR_PART_SORT_HOVERSEL;
401 elm_object_part_text_set(m->eoBase, FBR_PART_TITLE,
404 for (i = 0; i < TOTAL_TOP_BTNS; i++) {
405 btn = _add_button(m->eoBase);
407 _ERR(" Adding btn failed ");
411 elm_object_style_set(btn, btninfo[i].style);
412 elm_object_part_content_set(m->eoBase, btninfo[i].part, btn);
414 m->pHandlerButton[i]->Connect(btn);
416 if (i == TOPBTN_SOURCE)
417 m->eoBtnSource = btn;
418 else if (i == TOPBTN_SORT)
422 elm_object_text_set(m->eoBtnSource, _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
423 elm_object_text_set(m->eoBtnSort, _(CSortCtxPopup::SortText(CInfo::SortType())));
426 void CFbBaseView::t_CreateLeftSession(void)
429 Evas_Object *box, *ic;
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;
442 box = elm_box_add(m->eoBase);
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);
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 ");
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));
460 m->pHandlerGroup[i]->Connect(m->eoBtnGroup[i], i);
462 ic = elm_image_add(m->eoBtnGroup[i]);
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);
475 t_SetSelectedGroupButton(m->eoBtnGroup[E_GRP_ALL]);
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);
484 void CFbBaseView::t_CreateFullView(void)
487 t_CreateTopSession();
488 t_CreateLeftSession();
489 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
492 void CFbBaseView::t_SetSelectedGroupButton(Evas_Object* obj)
494 m->eoSelectedBtnGroup = obj;
498 for (a = 0; a < TOTAL_GROUP_BTNS; a++) {
499 if (m->eoBtnGroup[a] == obj)
502 CInfo::SetGroupIndex(idx);
505 Evas_Object* CFbBaseView::t_SelectedGroupButton(void)
507 return m->eoSelectedBtnGroup;
510 void CFbBaseView::t_OnShow(void)
514 evas_object_show(m->eoBase);
516 CBaseView::t_OnShow();
519 void CFbBaseView::t_OnUpdate(void *data)
521 switch(m->curLayoutId)
524 m->pFbAllLayout->Action();
527 m->pFbPhotoLayout->Action();
530 m->pFbVideoLayout->Action();
533 m->pFbMusicLayout->Action();
538 void CFbBaseView::t_OnHide(void)
540 evas_object_hide(m->eoBase);
542 CBaseView::t_OnHide();
545 bool CFbBaseView::Create(void *data)
549 Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
550 Evas_Object *eoBase = NULL;
552 int source_type = E_ALL;
555 _CHECK(m = new SFbBaseView)
556 _CHECK(eoBase = elm_layout_add(eoWin))
557 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_BASE_VIEW))
559 evas_object_size_hint_weight_set(eoBase, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
560 elm_win_resize_object_add(eoWin, eoBase);
562 /* get the source_type using 'data' string */
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)) {
573 if (source_type < E_ALL || source_type > E_USB)
575 CInfo::SetSourceType(source_type);
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())
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; }
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));
627 elm_object_focus_allow_set(eoBase, EINA_FALSE);
628 m->pHandlerBase->Connect(eoBase);
629 CBaseView::Create(NULL);
633 void CFbBaseView::Destroy(void)
637 CBaseView::Destroy();
638 CMediaContentDbUpdateListener::Destroy();
639 CUsbConnectionListener::Destroy();
641 m->pLayoutMgr->RemoveLayout(m->pFbMusicLayout);
642 m->pFbMusicLayout->Destroy();
643 delete m->pFbMusicLayout;
645 m->pLayoutMgr->RemoveLayout(m->pFbVideoLayout);
646 m->pFbVideoLayout->Destroy();
647 delete m->pFbVideoLayout;
649 m->pLayoutMgr->RemoveLayout(m->pFbPhotoLayout);
650 m->pFbPhotoLayout->Destroy();
651 delete m->pFbPhotoLayout;
653 m->pLayoutMgr->RemoveLayout(m->pFbAllLayout);
654 m->pFbAllLayout->Destroy();
655 delete m->pFbAllLayout;
657 m->pLayoutMgr->Destroy();
658 delete m->pLayoutMgr;
660 evas_object_del(m->eoBase);
667 Evas_Object* CFbBaseView::Base(void)
675 void CFbBaseView::OnConnect(void)
677 m->pPopup = new CPopup;
680 if (!m->pPopup->Create(m->eoBase)) {
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())));
696 void CFbBaseView::OnUpdated(const SEntity *entity)
699 m->pPopup->Destroy();
704 m->pCtxPopup->Destroy();
708 if (CInfo::SourceType() != E_TV) {
709 m->pLayoutMgr->Show(_get_layout_id(m->curLayoutId));
710 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);