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>
25 #include "AppCommon.h"
26 #include "ExtNameInfo.h"
29 #include "ManagerUsb.h"
32 #include "InputHandler.h"
37 #include "FbBaseView.h"
40 #include "SourceCtxPopup.h"
41 #include "SortCtxPopup.h"
44 #include <LayoutMgr.h>
45 #include <BaseLayout.h>
46 #include "FbBaseLayout.h"
48 #define TOTAL_GROUP_BTNS 4
49 #define TOTAL_TOP_BTNS 2
50 #define TOTAL_UPDATE_CALLBACKS 2
51 #define PARAM_URI "uri"
52 #define PARAM_SOURCE "source"
58 const char *icon_path;
66 const char *source_arg[] = {
72 const char *linked_app[] = {
74 N_("org.tizen.gallery-tv-ref"),
75 N_("org.tizen.video-player-tv-ref"),
76 N_("org.tizen.music-player-tv-ref"),
83 Evas_Object *eoBtnGroup[TOTAL_GROUP_BTNS];
84 Evas_Object *eoSelectedBtnGroup;//Evas_Object *c_grpbtn;
85 Evas_Object *eoBtnSource;
86 Evas_Object *eoBtnSort;
92 CLayoutMgr *pLayoutMgr;
93 CFbBaseLayout *pFbBaseLayout;
98 memset(eoBtnGroup, 0, sizeof(eoBtnGroup));
99 pHandlerBase = new CHandlerBase(this);
100 for (a = 0; a < TOTAL_TOP_BTNS; a++)
101 pHandlerButton[a] = new CHandlerButton(this);
102 for (a = 0; a < TOTAL_GROUP_BTNS; a++){
103 pHandlerGroup[a] = new CHandlerGroup(this);
106 virtual ~SFbBaseView() {
110 for (a = 0; a < TOTAL_TOP_BTNS; a++)
111 delete pHandlerButton[a];
112 for (a = 0; a < TOTAL_GROUP_BTNS; a++)
113 delete pHandlerGroup[a];
116 class CHandlerBase : public CListenerMgr, public IKeyDownListener {
120 CHandlerBase(SFbBaseView *ins) : IKeyDownListener(this) { m = ins; }
122 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
123 if (!strcmp(ev->keyname, KEY_EXIT))
125 else if (!strcmp(ev->keyname, KEY_ENTER)) {
126 if (elm_object_focus_get(m->eoSelectedBtnGroup)) {
127 m->pFbBaseLayout->SetFocus(EINA_TRUE);
133 class CHandlerButton : public CListenerMgr, protected IKeyDownListener, IMouseMoveListener, IMouseClickedListener {
137 static void sm_CbCtxPopupSelected(void* cookie, CCtxPopup* instance, const char* text)
139 SFbBaseView* m = (SFbBaseView*)cookie;
143 _DBG(" instance->Type(): %d", instance->Type());
144 switch (instance->Type()) {
145 case CCtxPopup::TOPBTN_SORT:
146 elm_object_text_set(m->eoBtnSort, text);
147 m->pFbBaseLayout->Update(true);
150 case CCtxPopup::TOPBTN_SOURCE:
151 elm_object_text_set(m->eoBtnSource, text);
152 m->pFbBaseLayout->Update(false);
161 CHandlerButton(SFbBaseView *ins) : IKeyDownListener(this), IMouseMoveListener(this), IMouseClickedListener(this) { m = ins; }
163 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
164 if (!strcmp(ev->keyname, KEY_BACK))
165 elm_object_focus_set(m->eoSelectedBtnGroup, EINA_TRUE);
167 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
168 if (!elm_object_focus_get(obj))
169 elm_object_focus_set(obj, EINA_TRUE);
171 virtual void OnMouseClicked(int id, Evas_Object *obj) {
172 CSourceCtxPopup::SCallback cb;
174 cb.onSelected = sm_CbCtxPopupSelected;
176 if (obj == m->eoBtnSource) {
177 CSourceCtxPopup* pCtxPopup = new CSourceCtxPopup;
178 m->pCtxPopup = pCtxPopup;
179 pCtxPopup->Create(m->eoBase, &cb);
181 else if (obj == m->eoBtnSort) {
182 CSortCtxPopup* pCtxPopup = new CSortCtxPopup;
183 m->pCtxPopup = pCtxPopup;
184 pCtxPopup->Create(m->eoBase, &cb);
187 } *pHandlerButton[TOTAL_TOP_BTNS];
189 class CHandlerGroup : public CListenerMgr, IMouseMoveListener, IKeyDownListener, IMouseClickedListener {
193 CHandlerGroup(SFbBaseView *ins) :
194 IMouseMoveListener(this),
195 IKeyDownListener(this),
196 IMouseClickedListener(this) { m = ins; }
198 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
199 if (!elm_object_focus_get(obj))
200 elm_object_focus_set(obj, EINA_TRUE);
202 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
203 if (!strcmp(ev->keyname, KEY_BACK))
206 virtual void OnMouseClicked(int id, Evas_Object *obj) {
207 if (m->eoSelectedBtnGroup == obj)
210 elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_UNSELECTED, "");
211 m->eoSelectedBtnGroup = obj;
212 elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_SELECTED, "");
214 m->pFbBaseLayout->Update(false);
216 } *pHandlerGroup[TOTAL_GROUP_BTNS];
221 Evas_Object *_add_button(Evas_Object *box)
228 button = elm_button_add(box);
232 evas_object_size_hint_weight_set(button,
233 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
234 evas_object_show(button);
239 void CFbBaseView::UpdateEmptyFocusSequence(void)
244 for (i = 0; i < TOTAL_GROUP_BTNS; i++)
245 elm_object_focus_next_object_set(m->eoBtnGroup[i], m->eoBtnSort, ELM_FOCUS_RIGHT);
247 elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL], m->eoBtnSort, ELM_FOCUS_UP);
248 elm_object_focus_next_object_set(m->eoBtnSort, m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
249 elm_object_focus_next_object_set(m->eoBtnSource, m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
251 if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_ALL]) {
252 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_FILE_MESSAGE));
253 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_FILE_MESSAGE_SUB));
255 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_PHOTO]) {
256 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_PHOTO_MESSAGE));
257 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_PHOTO_MESSAGE_SUB));
259 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_VIDEO]) {
260 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_VIDEO_MESSAGE));
261 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_VIDEO_MESSAGE_SUB));
263 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_MUSIC]) {
264 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_MUSIC_MESSAGE));
265 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_MUSIC_MESSAGE_SUB));
269 void CFbBaseView::UnsetFocus(void)
271 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
274 void CFbBaseView::CbLinkApp(int type, int source_type, char *path)
279 args = bundle_create();
281 _ERR("unable to create bundle");
285 bundle_add(args, PARAM_SOURCE, source_arg[source_type]);
286 bundle_add(args, PARAM_URI, path);
288 r = aul_launch_app(linked_app[type], args);
292 _ERR(" Unable to launch linked app");
299 void CFbBaseView::UpdatedGrid(void)
303 for (i = 0; i < TOTAL_GROUP_BTNS; i++)
304 elm_object_focus_next_object_set(m->eoBtnGroup[i],
305 m->pFbBaseLayout->Grid(), ELM_FOCUS_RIGHT);
307 elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL],
308 m->eoBtnSort, ELM_FOCUS_UP);
309 elm_object_focus_next_object_set(m->eoBtnSort,
310 m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_LEFT);
311 elm_object_focus_next_object_set(m->eoBtnSort,
312 m->pFbBaseLayout->Grid(), ELM_FOCUS_DOWN);
313 elm_object_focus_next_object_set(m->eoBtnSource,
314 m->pFbBaseLayout->Grid(), ELM_FOCUS_DOWN);
316 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, "");
317 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, "");
320 void CFbBaseView::t_CreateTopSession(void)
325 struct _btn_info btninfo[TOTAL_TOP_BTNS];
326 btninfo[TOPBTN_SOURCE].style = FBR_STYLE_SOURCE_BTN;
327 btninfo[TOPBTN_SOURCE].part = FBR_PART_SOURCE_HOVERSEL;
329 btninfo[TOPBTN_SORT].style = FBR_STYLE_SORT_BTN;
330 btninfo[TOPBTN_SORT].part = FBR_PART_SORT_HOVERSEL;
332 elm_object_part_text_set(m->eoBase, FBR_PART_TITLE,
335 for (i = 0; i < TOTAL_TOP_BTNS; i++) {
336 btn = _add_button(m->eoBase);
338 _ERR(" Adding btn failed ");
342 elm_object_style_set(btn, btninfo[i].style);
343 elm_object_part_content_set(m->eoBase, btninfo[i].part, btn);
345 m->pHandlerButton[i]->Connect(btn);
347 if (i == TOPBTN_SOURCE)
348 m->eoBtnSource = btn;
349 else if (i == TOPBTN_SORT)
353 elm_object_text_set(m->eoBtnSource, _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
354 elm_object_text_set(m->eoBtnSort, _(CSortCtxPopup::SortText(CInfo::SortType())));
357 void CFbBaseView::t_CreateLeftSession(void)
360 Evas_Object *box, *ic;
362 char buf[MAX_LENGTH];
363 static struct _btn_info btninfo[TOTAL_GROUP_BTNS];
364 btninfo[E_GRP_ALL].txt = N_("ALL");
365 btninfo[E_GRP_ALL].icon_path = FBR_IMAGE_GRPBTN_ALL;
366 btninfo[E_GRP_PHOTO].txt = N_("PHOTO");
367 btninfo[E_GRP_PHOTO].icon_path = FBR_IMAGE_GRPBTN_PHOTO;
368 btninfo[E_GRP_VIDEO].txt = N_("VIDEO");
369 btninfo[E_GRP_VIDEO].icon_path = FBR_IMAGE_GRPBTN_VIDEO;
370 btninfo[E_GRP_MUSIC].txt = N_("MUSIC");
371 btninfo[E_GRP_MUSIC].icon_path = FBR_IMAGE_GRPBTN_MUSIC;
373 box = elm_box_add(m->eoBase);
376 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
377 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
378 evas_object_show(box);
380 for (i = 0; i < TOTAL_GROUP_BTNS; i++) {
381 m->eoBtnGroup[i] = _add_button(box);
382 if (!m->eoBtnGroup[i]) {
383 _ERR(" failed to add button to box ");
387 elm_box_pack_end(box, m->eoBtnGroup[i]);
388 elm_object_style_set(m->eoBtnGroup[i], FBR_STYLE_GROUPBTN);
389 elm_object_text_set(m->eoBtnGroup[i], _(btninfo[i].txt));
391 m->pHandlerGroup[i]->Connect(m->eoBtnGroup[i]);
392 ic = elm_image_add(m->eoBtnGroup[i]);
397 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
398 btninfo[i].icon_path);
399 elm_image_file_set(ic, buf, NULL);
400 elm_object_part_content_set(m->eoBtnGroup[i],
401 FBR_PART_ELM_SWALLOWICON, ic);
405 t_SetSelectedGroupButton(m->eoBtnGroup[E_GRP_ALL]);
408 elm_object_signal_emit(m->eoBtnGroup[E_GRP_ALL],
409 FBR_SIGNAL_GROUP_SELECTED, "");
410 elm_object_focus_set(m->eoBtnGroup[E_GRP_ALL], EINA_TRUE);
411 elm_object_part_content_set(m->eoBase, FBR_PART_GROUPBTN_BOX, box);
414 void CFbBaseView::t_CreateFullView(void)
416 t_CreateTopSession();
417 t_CreateLeftSession();
418 _DBG("UpdateLayout");
419 m->pFbBaseLayout->Update(false);
422 void CFbBaseView::t_SetSelectedGroupButton(Evas_Object* obj)
424 m->eoSelectedBtnGroup = obj;
428 for (a = 0; a < TOTAL_GROUP_BTNS; a++) {
429 if (m->eoBtnGroup[a] == obj)
432 CInfo::SetGroupIndex(idx);
435 Evas_Object* CFbBaseView::t_SelectedGroupButton(void)
437 return m->eoSelectedBtnGroup;
440 void CFbBaseView::t_OnShow(void)
444 evas_object_show(m->eoBase);
446 CBaseView::t_OnShow();
449 void CFbBaseView::t_OnUpdate(void *data)
452 m->pFbBaseLayout->Action();
455 void CFbBaseView::t_OnHide(void)
457 evas_object_hide(m->eoBase);
459 CBaseView::t_OnHide();
462 bool CFbBaseView::Create(void *data)
466 Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
467 Evas_Object *eoBase = NULL;
469 int source_type = E_ALL;
472 _CHECK(m = new SFbBaseView)
473 _CHECK(eoBase = elm_layout_add(eoWin))
474 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_BASE_VIEW))
476 evas_object_size_hint_weight_set(eoBase, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
477 elm_win_resize_object_add(eoWin, eoBase);
479 /* get the source_type using 'data' string */
483 int arrsize = ARRAY_SIZE(source_arg);
484 for (i = 0; i < arrsize; i++) {
485 if (source_arg[i] && !strcmp(source_arg[i], (const char*)data)) {
490 if (source_type < E_ALL || source_type > E_USB)
492 CInfo::SetSourceType(source_type);
497 _CHECK(m->pLayoutMgr = new CLayoutMgr)
498 _CHECK(m->pLayoutMgr->Create(eoBase, NULL))
499 _CHECK(m->pFbBaseLayout = new CFbBaseLayout(FB_BASE_LAYOUT))
500 _CHECK(m->pFbBaseLayout->Create(m->pLayoutMgr, NULL))
501 _CHECK(m->pLayoutMgr->AddLayout(m->pFbBaseLayout))
502 _CHECK(CUsbConnectionListener::Create())
506 _CHECK_FAIL{ CUsbConnectionListener::Destroy(); }
507 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbBaseLayout); }
508 _CHECK_FAIL{ m->pFbBaseLayout->Destroy(); }
509 _CHECK_FAIL{ delete m->pFbBaseLayout; m->pFbBaseLayout = NULL; }
510 _CHECK_FAIL{ m->pLayoutMgr->Destroy(); }
511 _CHECK_FAIL{ delete m->pLayoutMgr; m->pLayoutMgr = NULL; }
512 _CHECK_FAIL{ /* elm_layout_file_set*/ }
513 _CHECK_FAIL{ evas_object_del(eoBase); }
514 _CHECK_FAIL{ delete m; m = NULL; }
515 } _CREATE_END_AND_CATCH{ return false; }
518 // original create grid
519 m->pLayoutMgr->Show(FB_BASE_LAYOUT);
520 CInfo::SetSortType(0/*CSort::SORT_NAME_AZ*/);
521 evas_object_data_set(eoBase, BASE_VIEW_DATA, this);
523 elm_object_focus_allow_set(eoBase, EINA_FALSE);
524 m->pHandlerBase->Connect(eoBase);
525 CBaseView::Create(NULL);
529 void CFbBaseView::Destroy(void)
533 CBaseView::Destroy();
534 CUsbConnectionListener::Destroy();
536 m->pLayoutMgr->RemoveLayout(m->pFbBaseLayout);
537 m->pFbBaseLayout->Destroy();
538 delete m->pFbBaseLayout;
540 m->pLayoutMgr->Destroy();
541 delete m->pLayoutMgr;
543 evas_object_del(m->eoBase);
550 Evas_Object* CFbBaseView::Base(void)
558 void CFbBaseView::OnConnect(void)
560 m->pPopup = new CPopup;
563 if (!m->pPopup->Create(m->eoBase)) {
569 if (CInfo::SourceType() == E_USB) {
570 if (!FlagConnected()) {
571 CInfo::SetSourceType(E_ALL);
572 elm_object_text_set(m->eoBtnSource,
573 _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
579 void CFbBaseView::OnUpdated(const SEntity *entity)
581 m->pPopup->Destroy();
586 m->pCtxPopup->Destroy();
590 if (CInfo::SourceType() != E_TV) {
591 m->pFbBaseLayout->Update(false);
592 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);