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 "ManagerUsb.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 "FbBaseLayout.h"
47 #define TOTAL_GROUP_BTNS 4
48 #define TOTAL_TOP_BTNS 2
49 #define TOTAL_UPDATE_CALLBACKS 2
50 #define PARAM_URI "uri"
51 #define PARAM_SOURCE "source"
57 const char *icon_path;
65 const char *source_arg[] = {
71 const char *linked_app[] = {
73 N_("org.tizen.gallery-tv-ref"),
74 N_("org.tizen.video-player-tv-ref"),
75 N_("org.tizen.music-player-tv-ref"),
82 Evas_Object *eoBtnGroup[TOTAL_GROUP_BTNS];
83 Evas_Object *eoSelectedBtnGroup;//Evas_Object *c_grpbtn;
84 Evas_Object *eoBtnSource;
85 Evas_Object *eoBtnSort;
91 CLayoutMgr *pLayoutMgr;
92 CFbBaseLayout *pFbBaseLayout;
97 memset(eoBtnGroup, 0, sizeof(eoBtnGroup));
98 pHandlerBase = new CHandlerBase(this);
99 for (a = 0; a < TOTAL_TOP_BTNS; a++)
100 pHandlerButton[a] = new CHandlerButton(this);
101 for (a = 0; a < TOTAL_GROUP_BTNS; a++){
102 pHandlerGroup[a] = new CHandlerGroup(this);
105 virtual ~SFbBaseView() {
109 for (a = 0; a < TOTAL_TOP_BTNS; a++)
110 delete pHandlerButton[a];
111 for (a = 0; a < TOTAL_GROUP_BTNS; a++)
112 delete pHandlerGroup[a];
115 class CHandlerBase : public CListenerMgr, public IKeyDownListener {
119 CHandlerBase(SFbBaseView *ins) : IKeyDownListener(this) { m = ins; }
121 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
122 if (!strcmp(ev->keyname, KEY_EXIT))
124 else if (!strcmp(ev->keyname, KEY_ENTER)) {
125 if (elm_object_focus_get(m->eoSelectedBtnGroup)) {
126 m->pFbBaseLayout->SetFocus(EINA_TRUE);
132 class CHandlerButton : public CListenerMgr, protected IKeyDownListener, IMouseMoveListener, IMouseClickedListener {
136 static void sm_CbCtxPopupSelected(void* cookie, CCtxPopup* instance, const char* text)
138 SFbBaseView* m = (SFbBaseView*)cookie;
142 _DBG(" instance->Type(): %d", instance->Type());
143 switch (instance->Type()) {
144 case CCtxPopup::TOPBTN_SORT:
145 elm_object_text_set(m->eoBtnSort, text);
146 m->pFbBaseLayout->Update(true);
149 case CCtxPopup::TOPBTN_SOURCE:
150 elm_object_text_set(m->eoBtnSource, text);
151 m->pFbBaseLayout->Update(false);
160 CHandlerButton(SFbBaseView *ins) : IKeyDownListener(this), IMouseMoveListener(this), IMouseClickedListener(this) { m = ins; }
162 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
163 if (!strcmp(ev->keyname, KEY_BACK))
164 elm_object_focus_set(m->eoSelectedBtnGroup, EINA_TRUE);
166 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
167 if (!elm_object_focus_get(obj))
168 elm_object_focus_set(obj, EINA_TRUE);
170 virtual void OnMouseClicked(int id, Evas_Object *obj) {
171 CSourceCtxPopup::SCallback cb;
173 cb.onSelected = sm_CbCtxPopupSelected;
175 if (obj == m->eoBtnSource) {
176 CSourceCtxPopup* pCtxPopup = new CSourceCtxPopup;
177 m->pCtxPopup = pCtxPopup;
178 pCtxPopup->Create(m->eoBase, &cb);
180 else if (obj == m->eoBtnSort) {
181 CSortCtxPopup* pCtxPopup = new CSortCtxPopup;
182 m->pCtxPopup = pCtxPopup;
183 pCtxPopup->Create(m->eoBase, &cb);
186 } *pHandlerButton[TOTAL_TOP_BTNS];
188 class CHandlerGroup : public CListenerMgr, IMouseMoveListener, IKeyDownListener, IMouseClickedListener {
192 CHandlerGroup(SFbBaseView *ins) :
193 IMouseMoveListener(this),
194 IKeyDownListener(this),
195 IMouseClickedListener(this) { m = ins; }
197 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
198 if (!elm_object_focus_get(obj))
199 elm_object_focus_set(obj, EINA_TRUE);
201 virtual void OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) {
202 if (!strcmp(ev->keyname, KEY_BACK))
205 virtual void OnMouseClicked(int id, Evas_Object *obj) {
206 if (m->eoSelectedBtnGroup == obj)
209 elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_UNSELECTED, "");
210 m->eoSelectedBtnGroup = obj;
211 elm_object_signal_emit(m->eoSelectedBtnGroup, FBR_SIGNAL_GROUP_SELECTED, "");
213 m->pFbBaseLayout->Update(false);
215 } *pHandlerGroup[TOTAL_GROUP_BTNS];
220 Evas_Object *_add_button(Evas_Object *box)
227 button = elm_button_add(box);
231 evas_object_size_hint_weight_set(button,
232 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
233 evas_object_show(button);
238 void CFbBaseView::UpdateEmptyFocusSequence(void)
243 for (i = 0; i < TOTAL_GROUP_BTNS; i++)
244 elm_object_focus_next_object_set(m->eoBtnGroup[i], m->eoBtnSort, ELM_FOCUS_RIGHT);
246 elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL], m->eoBtnSort, ELM_FOCUS_UP);
247 elm_object_focus_next_object_set(m->eoBtnSort, m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
248 elm_object_focus_next_object_set(m->eoBtnSource, m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_DOWN);
250 if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_ALL]) {
251 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_FILE_MESSAGE));
252 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_FILE_MESSAGE_SUB));
254 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_PHOTO]) {
255 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_PHOTO_MESSAGE));
256 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_PHOTO_MESSAGE_SUB));
258 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_VIDEO]) {
259 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_VIDEO_MESSAGE));
260 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_VIDEO_MESSAGE_SUB));
262 else if (t_SelectedGroupButton() == m->eoBtnGroup[E_GRP_MUSIC]) {
263 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, _(NO_MUSIC_MESSAGE));
264 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, _(NO_MUSIC_MESSAGE_SUB));
268 void CFbBaseView::UnsetFocus(void)
270 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);
273 void CFbBaseView::CbLinkApp(int type, int source_type, char *path)
278 args = bundle_create();
280 _ERR("unable to create bundle");
284 bundle_add(args, PARAM_SOURCE, source_arg[source_type]);
285 bundle_add(args, PARAM_URI, path);
287 r = aul_launch_app(linked_app[type], args);
291 _ERR(" Unable to launch linked app");
298 void CFbBaseView::UpdatedGrid(void)
302 for (i = 0; i < TOTAL_GROUP_BTNS; i++)
303 elm_object_focus_next_object_set(m->eoBtnGroup[i],
304 m->pFbBaseLayout->Grid(), ELM_FOCUS_RIGHT);
306 elm_object_focus_next_object_set(m->eoBtnGroup[E_GRP_ALL],
307 m->eoBtnSort, ELM_FOCUS_UP);
308 elm_object_focus_next_object_set(m->eoBtnSort,
309 m->eoBtnGroup[E_GRP_ALL], ELM_FOCUS_LEFT);
310 elm_object_focus_next_object_set(m->eoBtnSort,
311 m->pFbBaseLayout->Grid(), ELM_FOCUS_DOWN);
312 elm_object_focus_next_object_set(m->eoBtnSource,
313 m->pFbBaseLayout->Grid(), ELM_FOCUS_DOWN);
315 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT, "");
316 elm_object_part_text_set(m->eoBase, FBR_PART_NO_CONTENT_SUB, "");
319 void CFbBaseView::t_CreateTopSession(void)
324 struct _btn_info btninfo[TOTAL_TOP_BTNS];
325 btninfo[TOPBTN_SOURCE].style = FBR_STYLE_SOURCE_BTN;
326 btninfo[TOPBTN_SOURCE].part = FBR_PART_SOURCE_HOVERSEL;
328 btninfo[TOPBTN_SORT].style = FBR_STYLE_SORT_BTN;
329 btninfo[TOPBTN_SORT].part = FBR_PART_SORT_HOVERSEL;
331 elm_object_part_text_set(m->eoBase, FBR_PART_TITLE,
334 for (i = 0; i < TOTAL_TOP_BTNS; i++) {
335 btn = _add_button(m->eoBase);
337 _ERR(" Adding btn failed ");
341 elm_object_style_set(btn, btninfo[i].style);
342 elm_object_part_content_set(m->eoBase, btninfo[i].part, btn);
344 m->pHandlerButton[i]->Connect(btn);
346 if (i == TOPBTN_SOURCE)
347 m->eoBtnSource = btn;
348 else if (i == TOPBTN_SORT)
352 elm_object_text_set(m->eoBtnSource, _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
353 elm_object_text_set(m->eoBtnSort, _(CSortCtxPopup::SortText(CInfo::SortType())));
356 void CFbBaseView::t_CreateLeftSession(void)
359 Evas_Object *box, *ic;
361 char buf[MAX_LENGTH];
362 static struct _btn_info btninfo[TOTAL_GROUP_BTNS];
363 btninfo[E_GRP_ALL].txt = N_("ALL");
364 btninfo[E_GRP_ALL].icon_path = FBR_IMAGE_GRPBTN_ALL;
365 btninfo[E_GRP_PHOTO].txt = N_("PHOTO");
366 btninfo[E_GRP_PHOTO].icon_path = FBR_IMAGE_GRPBTN_PHOTO;
367 btninfo[E_GRP_VIDEO].txt = N_("VIDEO");
368 btninfo[E_GRP_VIDEO].icon_path = FBR_IMAGE_GRPBTN_VIDEO;
369 btninfo[E_GRP_MUSIC].txt = N_("MUSIC");
370 btninfo[E_GRP_MUSIC].icon_path = FBR_IMAGE_GRPBTN_MUSIC;
372 box = elm_box_add(m->eoBase);
375 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
376 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
377 evas_object_show(box);
379 for (i = 0; i < TOTAL_GROUP_BTNS; i++) {
380 m->eoBtnGroup[i] = _add_button(box);
381 if (!m->eoBtnGroup[i]) {
382 _ERR(" failed to add button to box ");
386 elm_box_pack_end(box, m->eoBtnGroup[i]);
387 elm_object_style_set(m->eoBtnGroup[i], FBR_STYLE_GROUPBTN);
388 elm_object_text_set(m->eoBtnGroup[i], _(btninfo[i].txt));
390 m->pHandlerGroup[i]->Connect(m->eoBtnGroup[i]);
391 ic = elm_image_add(m->eoBtnGroup[i]);
396 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
397 btninfo[i].icon_path);
398 elm_image_file_set(ic, buf, NULL);
399 elm_object_part_content_set(m->eoBtnGroup[i],
400 FBR_PART_ELM_SWALLOWICON, ic);
404 t_SetSelectedGroupButton(m->eoBtnGroup[E_GRP_ALL]);
407 elm_object_signal_emit(m->eoBtnGroup[E_GRP_ALL],
408 FBR_SIGNAL_GROUP_SELECTED, "");
409 elm_object_focus_set(m->eoBtnGroup[E_GRP_ALL], EINA_TRUE);
410 elm_object_part_content_set(m->eoBase, FBR_PART_GROUPBTN_BOX, box);
413 void CFbBaseView::t_CreateFullView(void)
415 t_CreateTopSession();
416 t_CreateLeftSession();
417 _DBG("UpdateLayout");
418 m->pFbBaseLayout->Update(false);
421 void CFbBaseView::t_SetSelectedGroupButton(Evas_Object* obj)
423 m->eoSelectedBtnGroup = obj;
427 for (a = 0; a < TOTAL_GROUP_BTNS; a++) {
428 if (m->eoBtnGroup[a] == obj)
431 CInfo::SetGroupIndex(idx);
434 Evas_Object* CFbBaseView::t_SelectedGroupButton(void)
436 return m->eoSelectedBtnGroup;
439 void CFbBaseView::t_OnShow(void)
443 evas_object_show(m->eoBase);
445 CBaseView::t_OnShow();
448 void CFbBaseView::t_OnUpdate(void *data)
451 m->pFbBaseLayout->Action();
454 void CFbBaseView::t_OnHide(void)
456 evas_object_hide(m->eoBase);
458 CBaseView::t_OnHide();
461 bool CFbBaseView::Create(void *data)
465 Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
466 Evas_Object *eoBase = NULL;
468 int source_type = E_ALL;
471 _CHECK(m = new SFbBaseView)
472 _CHECK(eoBase = elm_layout_add(eoWin))
473 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_BASE_VIEW))
475 evas_object_size_hint_weight_set(eoBase, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
476 elm_win_resize_object_add(eoWin, eoBase);
478 /* get the source_type using 'data' string */
482 int arrsize = ARRAY_SIZE(source_arg);
483 for (i = 0; i < arrsize; i++) {
484 if (source_arg[i] && !strcmp(source_arg[i], (const char*)data)) {
489 if (source_type < E_ALL || source_type > E_USB)
491 CInfo::SetSourceType(source_type);
496 _CHECK(m->pLayoutMgr = new CLayoutMgr)
497 _CHECK(m->pLayoutMgr->Create(eoBase, NULL))
498 _CHECK(m->pFbBaseLayout = new CFbBaseLayout(FB_BASE_LAYOUT))
499 _CHECK(m->pFbBaseLayout->Create(m->pLayoutMgr, NULL))
500 _CHECK(m->pLayoutMgr->AddLayout(m->pFbBaseLayout))
501 _CHECK(CUsbConnectionListener::Create())
505 _CHECK_FAIL{ CUsbConnectionListener::Destroy(); }
506 _CHECK_FAIL{ m->pLayoutMgr->RemoveLayout(m->pFbBaseLayout); }
507 _CHECK_FAIL{ m->pFbBaseLayout->Destroy(); }
508 _CHECK_FAIL{ delete m->pFbBaseLayout; m->pFbBaseLayout = NULL; }
509 _CHECK_FAIL{ m->pLayoutMgr->Destroy(); }
510 _CHECK_FAIL{ delete m->pLayoutMgr; m->pLayoutMgr = NULL; }
511 _CHECK_FAIL{ /* elm_layout_file_set*/ }
512 _CHECK_FAIL{ evas_object_del(eoBase); }
513 _CHECK_FAIL{ delete m; m = NULL; }
514 } _CREATE_END_AND_CATCH{ return false; }
517 // original create grid
518 m->pLayoutMgr->Show(FB_BASE_LAYOUT);
519 CInfo::SetSortType(0/*CSort::SORT_NAME_AZ*/);
520 evas_object_data_set(eoBase, BASE_VIEW_DATA, this);
522 elm_object_focus_allow_set(eoBase, EINA_FALSE);
523 m->pHandlerBase->Connect(eoBase);
524 CBaseView::Create(NULL);
528 void CFbBaseView::Destroy(void)
532 CBaseView::Destroy();
533 CUsbConnectionListener::Destroy();
535 m->pLayoutMgr->RemoveLayout(m->pFbBaseLayout);
536 m->pFbBaseLayout->Destroy();
537 delete m->pFbBaseLayout;
539 m->pLayoutMgr->Destroy();
540 delete m->pLayoutMgr;
542 evas_object_del(m->eoBase);
549 Evas_Object* CFbBaseView::Base(void)
557 void CFbBaseView::OnConnect(void)
559 m->pPopup = new CPopup;
562 if (!m->pPopup->Create(m->eoBase)) {
568 if (CInfo::SourceType() == E_USB) {
569 if (!FlagConnected()) {
570 CInfo::SetSourceType(E_ALL);
571 elm_object_text_set(m->eoBtnSource,
572 _(CSourceCtxPopup::SourceText(CInfo::SourceType())));
578 void CFbBaseView::OnUpdated(const SEntity *entity)
580 m->pPopup->Destroy();
585 m->pCtxPopup->Destroy();
589 if (CInfo::SourceType() != E_TV) {
590 m->pFbBaseLayout->Update(false);
591 elm_object_focus_set(t_SelectedGroupButton(), EINA_TRUE);