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>
24 #include "view_home.h"
25 #include "data_home.h"
43 static inline Evas_Object *_add_layout(Evas_Object *base, const char *group,
48 if (!base || !group) {
49 _ERR("Invalid argument");
53 ly = elm_layout_add(base);
55 _ERR("failed to add layout");
58 elm_layout_file_set(ly, EDJEFILE, group);
60 elm_object_focus_allow_set(ly, EINA_TRUE);
66 static inline Evas_Object *_add_icon(Evas_Object *eo, const char *file, const char *part)
70 if (!eo || !file || !part) {
71 _ERR("Invalid argument");
75 ic = elm_icon_add(eo);
77 _ERR("failed to add icon");
81 elm_image_file_set(ic, file, NULL);
82 elm_object_part_content_set(eo, part, ic);
87 static inline Evas_Object *_add_label(Evas_Object *eo, char *name,
88 const char *style, const char *part)
93 if (!eo || !name || !style || !part) {
94 _ERR("Invalid argument");
98 lbl = elm_label_add(eo);
100 _ERR("failed to add label");
103 elm_object_style_set(lbl, style);
104 s = edje_object_data_get(elm_layout_edje_get(eo), TITLE_WIDTH);
106 elm_label_wrap_width_set(lbl, atoi(s));
107 elm_object_text_set(lbl, name);
108 elm_object_part_content_set(eo, part, lbl);
113 static inline Evas_Object *_add_bg(Evas_Object *eo, const char *part)
118 _ERR("Invalid argument");
122 bg = evas_object_rectangle_add(evas_object_evas_get(eo));
124 _ERR("failed to add label");
128 evas_object_color_set(bg, COLOR_DEFAULT_R, COLOR_DEFAULT_G,
129 COLOR_DEFAULT_B, COLOR_DEFAULT_A);
130 elm_object_part_content_set(eo, part, bg);
135 static bool _add_navigations(Evas_Object *base)
140 _ERR("Invalid argument");
144 ly = _add_layout(base, GRP_HOME_DOWN_ARROW, true);
146 _ERR("failed to add layout");
149 elm_object_part_content_set(base, PART_HOME_DOWN_ARROW, ly);
151 ly = _add_layout(base, GRP_HOME_UP_ARROW, true);
153 _ERR("failed to add layout");
156 elm_object_part_content_set(base, PART_HOME_UP_ARROW, ly);
161 static void _focused(int id, void *data, Evas_Object *obj, Elm_Object_Item *item)
167 _ERR("Invalid argument");
175 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
178 static void _unfocused(int id, void *data, Evas_Object *obj, Elm_Object_Item *item)
180 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
183 static input_handler eo_handler = {
185 .unfocused = _unfocused
188 static struct bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
189 struct datamgr_item *di)
192 Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
194 if (!priv || !box || !di) {
195 _ERR("Invalid argument");
199 bi = calloc(1, sizeof(*bi));
201 _ERR("failed to calloc bar item");
205 eo = _add_layout(box, GRP_HOME_ITEM, true);
207 _ERR("failed to add layout");
212 ic = _add_icon(eo, di->icon, PART_HOME_ITEM_ICON);
216 focus_ic = _add_icon(eo, di->focus_icon, PART_HOME_ITEM_ICON_FOCUS);
220 lbl = _add_label(eo, di->title, STYLE_LABEL_TITLE, PART_HOME_ITEM_TITLE);
224 focus_lbl = _add_label(eo, di->title, STYLE_LABEL_TITLE_FOCUS,
225 PART_HOME_ITEM_TITLE_FOCUS);
229 bg = _add_bg(eo, PART_HOME_ITEM_BG);
233 inputmgr_add_callback(eo, 0, &eo_handler, bi);
234 elm_box_pack_end(box, eo);
241 _ERR("failed to add home item");
248 static bool _add_home_menu(struct _priv *priv, Evas_Object *base)
251 Evas_Object *scr, *box;
253 struct datamgr_item *di;
255 if (!priv || !base) {
256 _ERR("Invalid argument");
260 scr = elm_scroller_add(base);
262 _ERR("failed to add scroller");
265 elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF,
266 ELM_SCROLLER_POLICY_OFF);
268 box = elm_box_add(scr);
270 _ERR("failed to add box");
271 evas_object_del(scr);
274 evas_object_show(box);
275 elm_object_content_set(scr, box);
276 elm_object_part_content_set(base, PART_HOME_MENU_BAR, scr);
277 elm_box_horizontal_set(box, EINA_TRUE);
279 list = datamgr_get_items(priv->dm);
281 _ERR("failed to load list");
282 evas_object_del(scr);
286 EINA_LIST_FOREACH(list, l, di) {
287 bi = _pack_bar_item(priv, box, di);
291 priv->list = eina_list_append(priv->list, bi);
297 static bool _add_home(struct _priv *priv, Evas_Object *base)
299 if (!priv || !base) {
300 _ERR("Invalid argument");
304 if (!_add_navigations(base)) {
305 _ERR("failed to add navigations");
309 if (!_add_home_menu(priv, base)) {
310 _ERR("failed to add menu");
317 static Evas_Object *_create(Evas_Object *win, void *data)
324 _ERR("Invalid argument");
328 priv = calloc(1, sizeof(*priv));
330 _ERR("failed to calloc priv");
334 dm = datamgr_init(datamgr_home_get_dclass(), VIEW_HOME);
336 _ERR("failed to initialize datamgr");
341 base =_add_layout(win, GRP_HOME, false);
343 _ERR("failed to create base");
348 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
349 elm_win_resize_object_add(win, base);
355 if (!_add_home(priv, base)) {
356 _ERR("failed to load home");
358 evas_object_del(base);
363 viewmgr_set_view_data(VIEW_HOME, priv);
368 static void _show(void *data)
373 _ERR("Invalid argument");
379 evas_object_show(priv->base);
380 elm_object_signal_emit(priv->base, SIG_SHOW_NAVIGATION, SRC_PROG);
383 priv->foc = eina_list_data_get(priv->list);
384 elm_object_focus_set(priv->foc->eo, EINA_TRUE);
387 static void _hide(void *data)
392 _ERR("Invalid argument");
398 evas_object_hide(priv->base);
401 static void _destroy(void *data)
407 _ERR("Invalid argument");
413 EINA_LIST_FREE(priv->list, bi) {
414 inputmgr_remove_callback(bi->eo, &eo_handler);
415 evas_object_del(bi->eo);
419 datamgr_fini(priv->dm);
420 evas_object_del(priv->base);
426 static view_class vclass = {
427 .view_id = VIEW_HOME,
434 view_class *view_home_get_vclass(void)