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_user.h"
25 #include "view_user_edit.h"
26 #include "data_user.h"
38 struct _bar_item *foc;
44 struct datamgr_item *di;
48 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
49 Evas_Event_Key_Down *ev)
54 _ERR("Invalid argument");
60 if (!strcmp(ev->keyname, KEY_ENTER) ||
61 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
62 viewmgr_update_view(VIEW_USER_EDIT, 0, NULL);
63 datamgr_select_item(priv->dm, priv->foc->di);
64 } else if (!strcmp(ev->keyname, KEY_BACK) ||
65 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
67 } else if (!strcmp(ev->keyname, KEY_DOWN)) {
68 if (priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
71 viewmgr_update_view(VIEW_USER_EDIT, 0, priv->foc->di);
72 viewmgr_push_view(VIEW_USER_EDIT);
76 static input_handler base_handler = {
80 static Evas_Object *_create(Evas_Object *win, void *data)
87 _ERR("Invalid argument");
91 priv = calloc(1, sizeof(*priv));
93 _ERR("failed to calloc priv");
97 dm = datamgr_init(datamgr_user_get_dclass(), VIEW_USER);
99 _ERR("failed to initialize datamgr");
104 base = utils_add_layout(win, GRP_USER, false, NULL);
106 _ERR("failed to create base");
111 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
113 elm_win_resize_object_add(win, base);
119 viewmgr_set_view_data(VIEW_USER, priv);
120 viewmgr_add_view(view_user_edit_get_vclass(), dm);
121 inputmgr_add_callback(base, 0, &base_handler, priv);
126 static void _focused(int id, void *data, Evas_Object *obj,
127 Elm_Object_Item *item)
130 struct _bar_item *bi;
133 _ERR("Invalid argument");
141 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
144 static void _unfocused(int id, void *data, Evas_Object *obj,
145 Elm_Object_Item *item)
147 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
150 static input_handler eo_handler = {
152 .unfocused = _unfocused
155 static struct _bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
156 struct datamgr_item *di)
158 struct _bar_item *bi;
159 Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
161 bi = calloc(1, sizeof(*bi));
163 _ERR("failed to calloc bar item");
168 eo = utils_add_layout(box, GRP_USER_ITEM, true, NULL);
170 _ERR("failed to add layout");
174 lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE,
175 PART_BAR_ITEM_TITLE);
179 focus_lbl = utils_add_label(eo, di->title,
180 STYLE_LABEL_TITLE_FOCUS,
181 PART_BAR_ITEM_TITLE_FOCUS);
185 eo = utils_add_layout(box, GRP_BAR_ITEM, true, NULL);
187 _ERR("failed to add layout");
193 ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
197 focus_ic = utils_add_icon(eo,
198 utils_get_focus_icon_from_icon(di->focus_icon),
199 PART_BAR_ITEM_ICON_FOCUS);
203 bg = utils_add_bg(eo, COLOR_DEFAULT_R, COLOR_DEFAULT_G, COLOR_DEFAULT_B,
204 COLOR_DEFAULT_A, PART_BAR_ITEM_BG);
208 inputmgr_add_callback(eo, 0, &eo_handler, bi);
209 elm_box_pack_end(box, eo);
210 evas_object_show(eo);
218 _ERR("failed to add home item");
225 static void _add_user(struct _priv *priv)
228 Evas_Object *scr, *box;
229 struct _bar_item *bi;
230 struct datamgr_item *di;
232 scr = utils_add_scroller(priv->base);
234 _ERR("failed to add scroller");
238 box = utils_add_box(scr, true);
240 _ERR("failed to add box");
241 evas_object_del(scr);
244 elm_object_content_set(scr, box);
245 elm_object_part_content_set(priv->base, PART_USER_BAR, scr);
246 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
249 list = datamgr_get_items(priv->dm);
251 _ERR("failed to load list");
252 evas_object_del(scr);
256 EINA_LIST_FOREACH(list, l, di) {
257 bi = _pack_bar_item(priv, box, di);
261 priv->list = eina_list_append(priv->list, bi);
268 static void _show(void *data)
273 _ERR("Invalid argument");
279 evas_object_show(priv->base);
284 priv->foc = eina_list_data_get(priv->list);
286 elm_object_focus_set(priv->foc->eo, EINA_TRUE);
289 static void _unload_user(struct _priv *priv)
291 struct _bar_item *bi;
293 EINA_LIST_FREE(priv->list, bi) {
294 inputmgr_remove_callback(bi->eo, &eo_handler);
295 evas_object_del(bi->eo);
299 elm_box_clear(priv->box);
300 evas_object_del(priv->scr);
307 static void _hide(void *data)
312 _ERR("Invalid argument");
320 evas_object_hide(priv->base);
323 static void _destroy(void *data)
328 _ERR("Invalid argument");
336 viewmgr_remove_view(VIEW_USER_EDIT);
337 datamgr_fini(priv->dm);
338 inputmgr_remove_callback(priv->base, &base_handler);
339 evas_object_del(priv->base);
343 static view_class vclass = {
344 .view_id = VIEW_USER,
351 view_class *view_user_get_vclass(void)