3 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <Elementary.h>
19 #include <app_debug.h>
25 #include "data_home.h"
41 struct datamgr_item *di;
45 static bool _add_navigations(Evas_Object *base)
50 _ERR("Invalid argument");
54 ly = utils_add_layout(base, GRP_HOME_DOWN_ARROW, true,
55 PART_HOME_DOWN_ARROW);
57 _ERR("failed to add layout");
64 static void _focused(int id, void *data, Evas_Object *obj,
65 Elm_Object_Item *item)
71 _ERR("Invalid argument");
79 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
82 static void _unfocused(int id, void *data, Evas_Object *obj,
83 Elm_Object_Item *item)
85 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
88 static input_handler eo_handler = {
90 .unfocused = _unfocused
93 static struct bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
94 struct datamgr_item *di)
97 Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
99 if (!priv || !box || !di) {
100 _ERR("Invalid argument");
104 bi = calloc(1, sizeof(*bi));
106 _ERR("failed to calloc bar item");
110 eo = utils_add_layout(box, GRP_HOME_ITEM, true, NULL);
112 _ERR("failed to add layout");
117 ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
121 focus_ic = utils_add_icon(eo, di->focus_icon, PART_BAR_ITEM_ICON_FOCUS);
125 lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE,
126 PART_BAR_ITEM_TITLE);
130 focus_lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE_FOCUS,
131 PART_BAR_ITEM_TITLE_FOCUS);
135 bg = utils_add_bg(eo, COLOR_DEFAULT_R, COLOR_DEFAULT_G, COLOR_DEFAULT_B,
136 COLOR_DEFAULT_A, PART_BAR_ITEM_BG);
140 inputmgr_add_callback(eo, 0, &eo_handler, bi);
141 elm_box_pack_end(box, eo);
142 evas_object_show(eo);
150 _ERR("failed to add home item");
157 static bool _add_home_menu(struct _priv *priv, Evas_Object *base)
160 Evas_Object *scr, *box;
162 struct datamgr_item *di;
164 if (!priv || !base) {
165 _ERR("Invalid argument");
169 scr = utils_add_scroller(base);
171 _ERR("failed to add scroller");
175 box = utils_add_box(scr, true);
177 _ERR("failed to add box");
178 evas_object_del(scr);
181 elm_object_content_set(scr, box);
182 elm_object_part_content_set(base, PART_HOME_MENU_BAR, scr);
184 list = datamgr_get_items(priv->dm);
186 _ERR("failed to load list");
187 evas_object_del(scr);
191 EINA_LIST_FOREACH(list, l, di) {
192 bi = _pack_bar_item(priv, box, di);
196 priv->list = eina_list_append(priv->list, bi);
202 static bool _add_home(struct _priv *priv, Evas_Object *base)
204 if (!priv || !base) {
205 _ERR("Invalid argument");
209 if (!_add_navigations(base)) {
210 _ERR("failed to add navigations");
214 if (!_add_home_menu(priv, base)) {
215 _ERR("failed to add menu");
222 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
223 Evas_Event_Key_Down *ev)
228 _ERR("Invalid argument");
234 if (!strcmp(ev->keyname, KEY_DOWN)) {
235 viewmgr_push_view(VIEW_RECENT);
236 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
237 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
238 datamgr_select_item(priv->dm, priv->foc->di);
239 } else if (!strcmp(ev->keyname, KEY_BACK) ||
240 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
241 /* It should be implemented later */
245 static input_handler base_handler = {
246 .key_down = _key_down
249 static Evas_Object *_create(Evas_Object *win, void *data)
256 _ERR("Invalid argument");
260 priv = calloc(1, sizeof(*priv));
262 _ERR("failed to calloc priv");
266 dm = datamgr_init(datamgr_home_get_dclass(), VIEW_HOME);
268 _ERR("failed to initialize datamgr");
273 base = utils_add_layout(win, GRP_HOME, false, NULL);
275 _ERR("failed to create base");
280 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
282 elm_win_resize_object_add(win, base);
288 if (!_add_home(priv, base)) {
289 _ERR("failed to load home");
291 evas_object_del(base);
296 viewmgr_set_view_data(VIEW_HOME, priv);
297 inputmgr_add_callback(base, 0, &base_handler, priv);
302 static void _show(void *data)
307 _ERR("Invalid argument");
313 evas_object_show(priv->base);
314 elm_object_signal_emit(priv->base, SIG_SHOW_NAVIGATION, SRC_PROG);
317 priv->foc = eina_list_data_get(priv->list);
318 elm_object_focus_set(priv->foc->eo, EINA_TRUE);
321 static void _hide(void *data)
326 _ERR("Invalid argument");
332 elm_object_signal_emit(priv->base, SIG_HIDE_NAVIGATION, SRC_PROG);
333 evas_object_hide(priv->base);
336 static void _destroy(void *data)
342 _ERR("Invalid argument");
348 EINA_LIST_FREE(priv->list, bi) {
349 inputmgr_remove_callback(bi->eo, &eo_handler);
350 evas_object_del(bi->eo);
354 datamgr_fini(priv->dm);
355 inputmgr_remove_callback(priv->base, &base_handler);
356 evas_object_del(priv->base);
362 static view_class vclass = {
363 .view_id = VIEW_HOME,
370 view_class *view_home_get_vclass(void)