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_user.h"
29 #define MESSAGE_POPUP_CONTENT "Can not add users more than 8.<br>If you want to add another user, delete one of users"
31 enum input_handler_type {
32 INPUT_HANDLER_TYPE_BASE,
33 INPUT_HANDLER_TYPE_EO,
34 INPUT_HANDLER_TYPE_BUTTON
45 struct _bar_item *foc;
51 struct datamgr_item *di;
55 static void _focused(int id, void *data, Evas_Object *obj,
56 Elm_Object_Item *item)
61 if (id != INPUT_HANDLER_TYPE_EO)
68 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
71 static void _unfocused(int id, void *data, Evas_Object *obj,
72 Elm_Object_Item *item)
74 if (id != INPUT_HANDLER_TYPE_EO)
77 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
80 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
81 Evas_Event_Key_Down *ev);
83 static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
84 Evas_Event_Mouse_Down *ev);
86 static input_handler handler = {
88 .unfocused = _unfocused,
89 .key_down = _key_down,
90 .mouse_down = _mouse_down
93 static void _add_popup(struct _priv *priv)
95 Evas_Object *popup, *btn;
97 popup = utils_add_popup(priv->base, MESSAGE_ADD_USER,
98 MESSAGE_POPUP_CONTENT);
100 _ERR("failed to add popup");
104 btn = utils_add_button(popup, MESSAGE_OK, PART_POPUP_BUTTON_1);
106 _ERR("failed to add button");
107 evas_object_del(popup);
110 inputmgr_add_callback(btn, INPUT_HANDLER_TYPE_BUTTON, &handler, popup);
111 elm_object_focus_set(btn, EINA_TRUE);
114 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
115 Evas_Event_Key_Down *ev)
120 _ERR("Invalid argument");
125 case INPUT_HANDLER_TYPE_BUTTON:
126 if (!strcmp(ev->keyname, KEY_ENTER) ||
127 !strcmp(ev->keyname, KEY_ENTER_REMOTE) ||
128 !strcmp(ev->keyname, KEY_BACK) ||
129 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
130 inputmgr_remove_callback(obj, &handler);
131 evas_object_del(data);
134 case INPUT_HANDLER_TYPE_BASE:
136 if (!strcmp(ev->keyname, KEY_ENTER) ||
137 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
138 if ((priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
139 && (eina_list_count(priv->list)
140 >= MAX_USER_COUNT)) {
145 viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
147 datamgr_select_item(priv->dm, priv->foc->di);
148 } else if (!strcmp(ev->keyname, KEY_BACK) ||
149 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
151 } else if (!strcmp(ev->keyname, KEY_DOWN)) {
152 if (priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
155 viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
157 viewmgr_push_view(VIEW_USER_EDIT);
165 static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
166 Evas_Event_Mouse_Down *ev)
171 _ERR("Invalid argument");
176 case INPUT_HANDLER_TYPE_BASE:
178 if ((priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
179 && (eina_list_count(priv->list)
180 >= MAX_USER_COUNT)) {
185 viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
187 datamgr_select_item(priv->dm, priv->foc->di);
189 case INPUT_HANDLER_TYPE_BUTTON:
190 inputmgr_remove_callback(obj, &handler);
191 evas_object_del(data);
198 static Evas_Object *_create(Evas_Object *win, void *data)
205 _ERR("Invalid argument");
209 priv = calloc(1, sizeof(*priv));
211 _ERR("failed to calloc priv");
215 dm = datamgr_init(datamgr_user_get_dclass(), VIEW_USER);
217 _ERR("failed to initialize datamgr");
222 base = utils_add_layout(win, GRP_USER, false, NULL);
224 _ERR("failed to create base");
229 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
231 elm_win_resize_object_add(win, base);
237 viewmgr_set_view_data(VIEW_USER, priv);
238 viewmgr_add_view(view_user_edit_get_vclass(), dm);
239 inputmgr_add_callback(base, INPUT_HANDLER_TYPE_BASE, &handler, priv);
244 static struct _bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
245 struct datamgr_item *di)
247 struct _bar_item *bi;
248 Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
250 bi = calloc(1, sizeof(*bi));
252 _ERR("failed to calloc bar item");
257 eo = utils_add_layout(box, GRP_USER_ITEM, true, NULL);
259 _ERR("failed to add layout");
263 lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE,
264 PART_BAR_ITEM_TITLE);
268 focus_lbl = utils_add_label(eo, di->title,
269 STYLE_LABEL_TITLE_FOCUS,
270 PART_BAR_ITEM_TITLE_FOCUS);
274 eo = utils_add_layout(box, GRP_BAR_ITEM, true, NULL);
276 _ERR("failed to add layout");
282 ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
286 focus_ic = utils_add_icon(eo,
287 utils_get_focus_icon_from_icon(di->focus_icon),
288 PART_BAR_ITEM_ICON_FOCUS);
292 bg = utils_add_bg(eo, COLOR_DEFAULT_R, COLOR_DEFAULT_G, COLOR_DEFAULT_B,
293 COLOR_DEFAULT_A, PART_BAR_ITEM_BG);
297 inputmgr_add_callback(eo, INPUT_HANDLER_TYPE_EO, &handler, bi);
298 elm_box_pack_end(box, eo);
299 evas_object_show(eo);
307 _ERR("failed to add home item");
314 static void _add_user(struct _priv *priv)
317 Evas_Object *scr, *box;
318 struct _bar_item *bi;
319 struct datamgr_item *di;
321 scr = utils_add_scroller(priv->base);
323 _ERR("failed to add scroller");
327 box = utils_add_box(scr, true);
329 _ERR("failed to add box");
330 evas_object_del(scr);
333 elm_object_content_set(scr, box);
334 elm_object_part_content_set(priv->base, PART_USER_BAR, scr);
335 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
338 list = datamgr_get_items(priv->dm);
340 _ERR("failed to load list");
341 evas_object_del(scr);
345 EINA_LIST_FOREACH(list, l, di) {
346 bi = _pack_bar_item(priv, box, di);
350 priv->list = eina_list_append(priv->list, bi);
357 static void _show(void *data)
362 _ERR("Invalid argument");
368 evas_object_show(priv->base);
373 priv->foc = eina_list_data_get(priv->list);
375 elm_object_focus_set(priv->foc->eo, EINA_TRUE);
378 static void _unload_user(struct _priv *priv)
380 struct _bar_item *bi;
382 EINA_LIST_FREE(priv->list, bi) {
383 inputmgr_remove_callback(bi->eo, &handler);
384 evas_object_del(bi->eo);
388 elm_box_clear(priv->box);
389 evas_object_del(priv->scr);
396 static void _hide(void *data)
401 _ERR("Invalid argument");
409 evas_object_hide(priv->base);
412 static void _destroy(void *data)
417 _ERR("Invalid argument");
425 viewmgr_remove_view(VIEW_USER_EDIT);
426 datamgr_fini(priv->dm);
427 inputmgr_remove_callback(priv->base, &handler);
428 evas_object_del(priv->base);
432 static view_class vclass = {
433 .view_id = VIEW_USER,
440 view_class *view_user_get_vclass(void)