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>
22 #include "AppCommon.h"
23 #include "InputHandler.h"
26 #include "ExtNameInfo.h"
29 #include "FbContextView.h"
30 #include "Dummy/DummyContent.h"
32 //#define _GET_PRIV(o) evas_object_data_get(o, "CTMDATA");
33 //#define _SET_PRIV(o, data) evas_object_data_set(o, "CTMDATA", data);
35 #define FBR_TEXT_SIZE N_("Size")
36 #define FBR_TEXT_FORMAT N_("Format")
37 #define FBR_TEXT_OPEN N_("OPEN")
38 #define FBR_TEXT_LINK N_("Other linkable apps")
39 #define FBR_TEXT_REL N_("Other apps for this type")
41 #define TOTAL_CONTEXT_BTNS 5
42 #define TABLE_MAX_COL 2
43 #define MIN_LABEL_WIDTH 103
44 #define FBR_CTXT_BTN_WPAD 26
45 #define FBR_CTXT_TABLE_WPAD 14
46 #define FBR_CTXT_TABLE_HPAD 14
52 Evas_Object *eoBtnOpen;
53 Evas_Object *rel_first[TABLE_MAX_COL];
54 Evas_Object *rel_last[TABLE_MAX_COL];
55 Evas_Object *link_first[TABLE_MAX_COL];
56 Evas_Object *link_last[TABLE_MAX_COL];
60 CDummyContent content;
67 for (a = 0; a < TABLE_MAX_COL; a++) {
74 pHandlerButton = new SContextView::CHandlerButton(this);
77 delete pHandlerButton;
80 class CHandlerButton : public CListenerMgr, IMouseMoveListener, IMouseUpListener, IKeyUpListener {
83 CHandlerButton(SContextView *ins) : IMouseMoveListener(this), IMouseUpListener(this), IKeyUpListener(this) { m = ins; }
85 virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev) {
86 if (!elm_object_focus_get(obj))
87 elm_object_focus_set(obj, EINA_TRUE);
89 virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) {
91 if (m->eoBtnOpen == obj) {
93 if (strcmp(ev->keyname, KEY_ENTER) && strcmp(ev->keyname, KEY_ENTER_REMOTE))
96 CViewMgr::GetInstance()->UpdateView(FBR_BASE_VIEW, NULL);
100 if (strcmp(ev->keyname, KEY_ENTER) && strcmp(ev->keyname, KEY_ENTER_REMOTE))
103 elm_object_signal_emit(obj, FBR_SIGNAL_CONTENT_CLICKED, FBR_CONTEXT_VIEW);
106 virtual void OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev) {
108 if (m->eoBtnOpen == obj) {
109 CViewMgr::GetInstance()->UpdateView(FBR_BASE_VIEW, NULL);
112 elm_object_signal_emit(obj, FBR_SIGNAL_CONTENT_CLICKED, FBR_CONTEXT_VIEW);
119 extern const char *typestr[];
122 void CContextView::_lbl_start_slide(Evas_Object *lbl)
124 elm_label_ellipsis_set(lbl, EINA_FALSE);
125 elm_label_slide_mode_set(lbl, ELM_LABEL_SLIDE_MODE_AUTO);
126 elm_label_slide_go(lbl);
129 void CContextView::_btn_focused(void *data, Evas_Object *obj, void *ev)
135 elm_object_signal_emit(obj, FBR_SIGNAL_FOCUSED, FBR_CONTEXT_VIEW);
139 void CContextView::_btn_unfocused(void *data, Evas_Object *obj, void *ev)
145 elm_object_signal_emit(obj, FBR_SIGNAL_UNFOCUSED, FBR_CONTEXT_VIEW);
149 bool CContextView::_add_btn_label(Evas_Object *btn, const char *txt)
152 char buf[MAX_LENGTH];
157 lbl = elm_label_add(btn);
159 _ERR("elm_label_add failed.");
163 snprintf(buf, sizeof(buf),
164 "<align=center><color=#FFFFFFFF>"
166 "<font_size=21>%s</font_size>"
167 "</font></color></align>", FONT_STYLE_MEDIUM, _(txt));
168 elm_object_text_set(lbl, buf);
169 elm_label_line_wrap_set(lbl, ELM_WRAP_WORD);
170 evas_object_size_hint_min_set(lbl, MIN_LABEL_WIDTH, 0);
171 elm_object_part_content_set(btn, FBR_PART_CTXT_BTNTEXT, lbl);
176 bool CContextView::_add_btn_icon(Evas_Object *btn, const char *icon)
179 char buf[MAX_LENGTH];
184 img = elm_image_add(btn);
186 _ERR("elm_image_add failed.");
190 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, icon);
191 elm_image_file_set(img, buf, NULL);
192 elm_object_part_content_set(btn, FBR_PART_CTXT_BTNICON, img);
197 bool CContextView::_add_btn_info(Evas_Object *btn, const char *icon, const char *txt)
199 if (!btn || !icon || !txt)
202 if (!_add_btn_icon(btn, icon))
205 if (!_add_btn_label(btn, txt))
212 Evas_Object *CContextView::_add_btnbox(Evas_Object *eoBase)
219 box = elm_box_add(eoBase);
221 _ERR(" elm_box_add failed ");
225 elm_box_horizontal_set(box, EINA_TRUE);
226 elm_box_padding_set(box, FBR_CTXT_BTN_WPAD, 0);
227 elm_box_align_set(box, 0, 0.5);
228 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
234 bool CContextView::_get_context_details(CExtNameInfo *pInfo, char **path, char **title, char *subtitle, char *subtitle2)
236 char buf[MAX_LENGTH];
244 *title = pInfo->Name();
245 *path = pInfo->ThumbnailPath();
246 size = pInfo->Size();
248 size_mb = (double)size / (1024 * 1024); /* Convert to MB */
250 snprintf(buf, sizeof(buf), "%s : %f MB", _(FBR_TEXT_SIZE), size_mb);
251 strcpy(subtitle, buf);
253 type = pInfo->Type();
254 snprintf(buf, sizeof(buf), "%s : %s", _(FBR_TEXT_FORMAT), _(typestr[type]));
255 strcpy(subtitle2, buf);
260 Evas_Object *CContextView::_add_rltv_ctnt(Evas_Object *obj, const char *name, const char *icon)
262 Evas_Object *ly, *img;
263 char buf[MAX_LENGTH];
266 _ERR("Invalid argument.");
270 ly = elm_layout_add(obj);
272 _ERR("elm_layout_add failed.");
276 elm_layout_file_set(ly, EDJEFILE, FBR_CONTEXT_APP);
277 evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279 img = elm_image_add(ly);
281 _ERR("elm_image_add failed.");
286 if (!icon || !strcmp(icon, EMPTY_STR)) {
287 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, FBR_IMAGE_DEFAULT_APP);
288 elm_image_file_set(img, buf, NULL);
289 elm_image_no_scale_set(img, EINA_TRUE);
291 elm_image_file_set(img, icon, NULL);
292 elm_image_aspect_fixed_set(img, EINA_FALSE);
295 elm_object_part_content_set(ly, FBR_PART_CTXT_RELCTNT_ICON, img);
296 elm_object_part_text_set(ly, FBR_PART_CTXT_RELCTNT_NAME, name);
297 elm_object_focus_allow_set(ly, EINA_TRUE);
303 Evas_Object *CContextView::_add_scroller(Evas_Object *eoBase)
305 Evas_Object *scroller;
308 _ERR("Invalid argument.");
312 scroller = elm_scroller_add(eoBase);
314 _ERR("elm_scroller_add failed.");
318 evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND,
320 evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL,
326 Evas_Object *CContextView::_add_table(Evas_Object *eoBase)
331 _ERR("Invalid argument.");
335 table = elm_table_add(eoBase);
337 _ERR("elm_table_add failed.");
341 elm_table_homogeneous_set(table, EINA_TRUE);
342 elm_table_padding_set(table,
343 FBR_CTXT_TABLE_WPAD * elm_config_scale_get(),
344 FBR_CTXT_TABLE_HPAD * elm_config_scale_get());
345 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
346 evas_object_show(table);
352 Evas_Object *CContextView::_get_icon(Evas_Object *obj, CExtNameInfo *finfo)
357 path = finfo->Path();
361 icon = elm_icon_add(obj);
366 elm_icon_thumb_set(icon, path, NULL);
367 elm_image_aspect_fixed_set(icon, EINA_FALSE);
373 void CContextView::_set_default_thumb(Evas_Object *img, int type)
375 char buf[MAX_LENGTH];
382 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
387 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
388 FBR_IMAGE_DEFAULT_VIDEO);
392 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
393 FBR_IMAGE_DEFAULT_MUSIC);
397 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
398 FBR_IMAGE_DEFAULT_OTHER);
402 elm_image_file_set(img, buf, NULL);
403 elm_image_no_scale_set(img, EINA_TRUE);
407 Evas_Object *CContextView::_create_lbl(Evas_Object *ly, char *title)
411 char buf[MAX_LENGTH];
416 lbl = elm_label_add(ly);
421 elm_object_style_set(lbl, FBR_STYLE_LABEL);
422 elm_label_ellipsis_set(lbl, EINA_TRUE);
423 s = edje_object_data_get(elm_layout_edje_get(ly),
424 FBR_DATA_TITLE_WIDTH);
426 elm_label_wrap_width_set(lbl, atoi(s));
428 _ERR("No title width exist");
430 snprintf(buf, sizeof(buf),
431 "<align=left><color=#FFFFFFFF>"
433 "<font_size=36>%s</font_size>"
434 "</font></color></align>", FONT_STYLE_BOLD, _(title));
435 elm_object_text_set(lbl, buf);
436 elm_label_slide_speed_set(lbl, FBR_TITLE_SLIDE_SPEED);
443 void CContextView::m_SetBtnDownFocus(Evas_Object *btn)
447 if (!m->link_first[0] && !m->rel_first[0]) {
448 elm_object_focus_next_object_set(btn, btn,
453 if (m->link_first[0])
454 elm_object_focus_next_object_set(btn, m->link_first[0],
457 elm_object_focus_next_object_set(btn, m->rel_first[0],
462 void CContextView::m_SetLayoutFocusOrder(Evas_Object *btn)
469 if (m->link_first[0]) {
470 elm_object_focus_next_object_set(m->link_first[0], btn,
472 elm_object_focus_next_object_set(m->link_first[0],
473 m->rel_first[0], ELM_FOCUS_DOWN);
474 elm_object_focus_next_object_set(m->link_first[1], btn,
476 elm_object_focus_next_object_set(m->link_first[1],
477 m->rel_first[0], ELM_FOCUS_DOWN);
480 for (i = 0; i < TABLE_MAX_COL; i++) {
481 if (!m->rel_first[i])
484 obj = m->rel_first[i];
485 if (m->link_first[0])
486 elm_object_focus_next_object_set(obj, m->link_first[0],
489 elm_object_focus_next_object_set(obj, btn,
495 Evas_Object *CContextView::m_AddButton(Evas_Object *eoBase)
501 btn = elm_layout_add(eoBase);
503 _ERR("elm_layout_add failed.");
507 evas_object_size_hint_weight_set(btn,
508 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
509 evas_object_size_hint_align_set(btn, 0.0, 0.5);
511 elm_layout_file_set(btn, EDJEFILE, FBR_CONTEXT_BTN);
512 elm_object_focus_allow_set(btn, EINA_TRUE);
513 elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP);
514 elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT);
515 elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_RIGHT);
517 evas_object_smart_callback_add(btn, FBR_SIGNAL_FOCUSED, _btn_focused, NULL);
518 evas_object_smart_callback_add(btn, FBR_SIGNAL_UNFOCUSED, _btn_unfocused, NULL);
520 evas_object_show(btn);
521 elm_object_focus_set(btn, EINA_TRUE);
527 bool CContextView::m_AddTableContents(Evas_Object *table, Eina_List *list, enum content_app_type type)
534 CDummyContent::SRelativeContent *rctnt;
540 EINA_LIST_FOREACH(list, l, obj) {
541 rctnt = (CDummyContent::SRelativeContent *)obj;
542 ly = _add_rltv_ctnt(table, rctnt->title, rctnt->imgpath);
545 //_SET_PRIV(ly, rctnt);
546 elm_table_pack(table, ly, col, row, 1, 1);
547 evas_object_show(ly);
549 evas_object_smart_callback_add(ly, FBR_SIGNAL_FOCUSED, _btn_focused, NULL);
550 evas_object_smart_callback_add(ly, FBR_SIGNAL_UNFOCUSED, _btn_unfocused, NULL);
552 m->pHandlerButton->Connect(ly);
555 if (type == APP_LINKED)
556 m->link_first[col] = ly;
558 m->rel_first[col] = ly;
562 elm_object_focus_next_object_set(ly, ly, ELM_FOCUS_LEFT);
563 else if (col == TABLE_MAX_COL - 1)
564 elm_object_focus_next_object_set(ly, ly, ELM_FOCUS_RIGHT);
566 if (type == APP_LINKED)
567 m->link_last[col] = ly;
569 m->rel_last[col] = ly;
572 if (col >= TABLE_MAX_COL) {
582 bool CContextView::m_CreateContentApps(Eina_List *list, enum content_app_type type)
587 Evas_Object *scroller, *table;
590 scroller = _add_scroller(m->eoBase);
592 _ERR("_add_scroller failed.");
596 table = _add_table(scroller);
598 _ERR("_add_table failed.");
599 evas_object_del(scroller);
603 r = m_AddTableContents(table, list, type);
605 _ERR("m_AddTableContents failed.");
606 evas_object_del(scroller);
610 elm_object_content_set(scroller, table);
612 if (type == APP_LINKED)
613 elm_object_part_content_set(m->eoBase, FBR_PART_CTXT_LINK_AREA,
616 elm_object_part_content_set(m->eoBase, FBR_PART_CTXT_REL_AREA,
623 bool CContextView::m_CreateBtnsPart(void)
625 Evas_Object *btn, *box;
626 box = _add_btnbox(m->eoBase);
630 btn = m_AddButton(box);
632 evas_object_del(box);
635 if (!_add_btn_info(btn, FBR_IMAGE_CTXT_OPEN, FBR_TEXT_OPEN)) {
636 evas_object_del(box);
640 m_SetBtnDownFocus(btn);
641 m_SetLayoutFocusOrder(btn);
642 elm_box_pack_end(box, btn);
645 m->pHandlerButton->Connect(m->eoBtnOpen);
647 elm_object_part_content_set(m->eoBase, FBR_PART_CTXT_BTNAREA, box);
653 bool CContextView::m_CreateInfoPart(void)
655 Evas_Object *img = NULL;
658 char subtitle[MAX_LENGTH];
659 char subtitle2[MAX_LENGTH];
662 Eina_List *rltvlist = NULL;
663 Eina_List *linkapplist = NULL;
665 Evas_Object *lbl = NULL;
667 if (!_get_context_details(m->finfo, &path, &title, subtitle, subtitle2))
670 type = m->finfo->Type();
672 if (type == E_GRP_PHOTO) {
673 img = _get_icon(m->eoBase, m->finfo);
677 img = elm_image_add(m->eoBase);
680 _set_default_thumb(img, type);
683 img = elm_image_add(m->eoBase);
686 elm_image_file_set(img, path, NULL);
687 elm_image_aspect_fixed_set(img, EINA_FALSE);
690 elm_object_part_content_set(m->eoBase, FBR_PART_CTXT_ICON, img);
692 lbl = _create_lbl(m->eoBase, title);
694 elm_object_part_content_set(m->eoBase, FBR_PART_CTXT_TITLE, lbl);
695 _lbl_start_slide(lbl);
698 elm_object_part_text_set(m->eoBase, FBR_PART_CTXT_SUBTITLE, subtitle);
699 elm_object_part_text_set(m->eoBase, FBR_PART_CTXT_SUBTITLE2, subtitle2);
701 elm_object_part_text_set(m->eoBase, FBR_PART_CTXT_LINK_TEXT, _(FBR_TEXT_LINK));
702 linkapplist = CDummyContent::ListLinkApp(type);
704 m_CreateContentApps(linkapplist, APP_LINKED);
706 elm_object_part_text_set(m->eoBase, FBR_PART_CTXT_REL_TEXT, _(FBR_TEXT_REL));
707 rltvlist = CDummyContent::ListRelative(type);
709 m_CreateContentApps(rltvlist, APP_OTHER);
717 void CContextView::sm_CbKeyPressed(void *dt, Evas *e, Evas_Object *obj, void *ei)
720 Evas_Event_Key_Down *ev;
725 ev = (Evas_Event_Key_Down *)ei;
727 if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE))
729 CViewMgr::GetInstance()->PopView();
731 else if (!strcmp(ev->keyname, KEY_EXIT))
735 void CContextView::t_OnShow(void)
737 evas_object_show(m->eoBase);
740 void CContextView::t_OnHide(void)
742 evas_object_hide(m->eoBase);
745 bool CContextView::Create(void *data)
749 Evas_Object *eoBase = NULL;
750 Evas_Object *eoWin = CViewMgr::GetInstance()->Window();
754 _CHECK(m = new SContextView)
755 _CHECK(eoBase = elm_layout_add(eoWin))
756 _CHECK(elm_layout_file_set(eoBase, EDJEFILE, FBR_CONTEXT_VIEW))
757 _COMMAND{ m->eoWin = eoWin; m->eoBase = eoBase; m->finfo = (CExtNameInfo*)data; }
758 _CHECK(m_CreateInfoPart())
759 _CHECK(m_CreateBtnsPart())
762 evas_object_event_callback_add(eoBase, EVAS_CALLBACK_KEY_DOWN, sm_CbKeyPressed, m);
765 _CHECK_FAIL{ /* m_CreateBtnsPart */ }
766 _CHECK_FAIL{ /* m_CreateInfoPart */ }
768 _CHECK_FAIL{ evas_object_del(eoBase); }
769 _CHECK_FAIL{ delete m; m = NULL; }
770 } _CREATE_END_AND_CATCH{ return false; }
775 void CContextView::Destroy(void)
779 evas_object_del(m->eoBase);
784 Evas_Object* CContextView::Base(void)