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 void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
318 Evas_Event_Key_Down *ev)
321 _ERR("Invalid argument");
325 if (!strcmp(ev->keyname, KEY_DOWN)) {
326 viewmgr_push_view(VIEW_RECENT);
327 } else if (!strcmp(ev->keyname, KEY_UP)) {
328 /* It should be implemented later */
329 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
330 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
331 /* It should be implemented later */
332 } else if (!strcmp(ev->keyname, KEY_BACK) ||
333 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
334 /* It should be implemented later */
338 static input_handler base_handler = {
339 .key_down = _key_down
342 static Evas_Object *_create(Evas_Object *win, void *data)
349 _ERR("Invalid argument");
353 priv = calloc(1, sizeof(*priv));
355 _ERR("failed to calloc priv");
359 dm = datamgr_init(datamgr_home_get_dclass(), VIEW_HOME);
361 _ERR("failed to initialize datamgr");
366 base =_add_layout(win, GRP_HOME, false);
368 _ERR("failed to create base");
373 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
374 elm_win_resize_object_add(win, base);
380 if (!_add_home(priv, base)) {
381 _ERR("failed to load home");
383 evas_object_del(base);
388 viewmgr_set_view_data(VIEW_HOME, priv);
389 inputmgr_add_callback(base, 0, &base_handler, priv);
394 static void _show(void *data)
399 _ERR("Invalid argument");
405 evas_object_show(priv->base);
406 elm_object_signal_emit(priv->base, SIG_SHOW_NAVIGATION, SRC_PROG);
409 priv->foc = eina_list_data_get(priv->list);
410 elm_object_focus_set(priv->foc->eo, EINA_TRUE);
413 static void _hide(void *data)
418 _ERR("Invalid argument");
424 evas_object_hide(priv->base);
427 static void _destroy(void *data)
433 _ERR("Invalid argument");
439 EINA_LIST_FREE(priv->list, bi) {
440 inputmgr_remove_callback(bi->eo, &eo_handler);
441 evas_object_del(bi->eo);
445 datamgr_fini(priv->dm);
446 inputmgr_remove_callback(priv->base, &base_handler);
447 evas_object_del(priv->base);
453 static view_class vclass = {
454 .view_id = VIEW_HOME,
461 view_class *view_home_get_vclass(void)