2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "data_wrapper.h"
25 #include "settings_provider.h"
26 #include "view_system_clock.h"
28 #define DATA_ID "system_clock_data"
30 #define ITEM_HEIGHT 82
31 #define POS_ADJUST (39 * 2)
32 #define ITEMID "itemdata"
36 #define SUBLIST_WIDTH 310.0
37 #define LEFT_MARGIN 70.0
38 #define LEFT_OFFSET (SUBLIST_WIDTH + LEFT_MARGIN)
40 #define SIG_DISMISSED "dismissed"
41 #define SIG_FOCUSED "focused"
42 #define SIG_UNFOCUSED "unfocused"
43 #define SIG_CLICKED "clicked"
48 Evas_Object *ctxpopup;
54 struct settingview_data *vdata;
55 struct setting_mgr *mgr;
57 struct evas_obj_data ugd;
58 struct obj_geometry_data *ogd;
61 static void _destroy(Evas_Object *base);
62 static void _hide(Evas_Object *base);
65 * Exit system clock sublist view.
67 * @param[in]: data : the user data of system clock sublist view.
71 static void _exit_view(struct _sysclk_data *data)
73 if (!data || !data->base)
78 settingmgr_view_pop(data->mgr);
84 * @param[in]: vdata : view data.
85 * @param[out]: count : number of item.
87 * @return: eina list containing items or null if error occurred.
89 static Eina_List *_get_item_list(struct settingview_data *vdata, int *count)
93 if (!vdata || !count) {
94 _ERR("Invalid arguments");
98 list = settingitem_get_data_list(viewdata_get_parentitem(vdata));
104 *count = eina_list_count(list);
110 * Get selected value: Manual or Auto.
112 * @param[in]: data : the user data of system clock sublist view.
114 * @return: the selected value or null if error occurred.
116 static char *_get_selected_value(struct _sysclk_data *data)
118 struct settingitem *item;
120 if (!data || !data->vdata) {
121 _ERR("Invalid argument");
125 item = viewdata_get_parentitem(data->vdata);
127 _ERR("Get item failed");
131 return provider_get_list_value(item);
135 * Set selected value: Manual or Auto.
137 * @param[in]: data : the user data of system clock sublist view.
138 * @param[in]: obj : the selected object.
142 static void _set_selected_value(struct _sysclk_data *data, Evas_Object *obj)
144 struct settingitem *item;
148 if (!data || !data->vdata || !obj) {
149 _ERR("Invalid argument");
153 item = viewdata_get_parentitem(data->vdata);
155 _ERR("Get item failed");
159 selval = evas_object_data_get(obj, ITEMID);
161 ret = provider_set_list_value(item, selval);
163 _ERR("Set list value failed");
168 * Evas_Smart_Cb type callback for handling foucs in event.
170 * @param[in]: priv : the user data.
171 * @param[in]: obj : the corresponding object which the foucs in event occurred.
172 * @param[in]: ev : event info.
176 static void _subitem_focusin_cb(void *priv, Evas_Object *obj, void *ev)
178 struct _sysclk_data *data;
183 _ERR("Invalid arguments\n");
189 value = evas_object_data_get(obj, ITEMID);
191 _ERR("Get value from btn failed\n");
195 selval = _get_selected_value(data);
197 _ERR("_get_selected_value failed\n");
201 if (!strncmp(selval, value, strlen(selval))) {
202 elm_object_signal_emit(obj, CTXPOPUPBTN_ICON_FOCUSED,
203 CTXPOPUPBTN_ICON_SOURCE);
206 elm_object_signal_emit(obj, CTXPOPUPBTN_BUTTON_FOCUSED,
207 CTXPOPUPBTN_BUTTON_SOURCE);
209 provider_release_list_value(selval);
213 * Evas_Smart_Cb type callback for handling focus out event.
215 * @param[in]: priv : the user data.
216 * @param[in]: obj : the corresponding object which the focus out event occurred.
217 * @param[in]: ev : event info.
221 static void _subitem_focusout_cb(void *priv, Evas_Object *obj, void *ev)
223 struct _sysclk_data *data;
228 _ERR("Invalid arguments\n");
234 value = evas_object_data_get(obj, ITEMID);
236 _ERR("Get value from btn failed\n");
240 selval = _get_selected_value(data);
242 _ERR("_get_selected_value failed\n");
246 if (!strncmp(selval, value, strlen(selval)))
247 elm_object_signal_emit(obj, CTXPOPUPBTN_BUTTON_HIGHLIGHT,
248 CTXPOPUPBTN_BUTTON_SOURCE);
250 elm_object_signal_emit(obj, CTXPOPUPBTN_BUTTON_UNFOCUSED,
251 CTXPOPUPBTN_BUTTON_SOURCE);
253 provider_release_list_value(selval);
257 * Evas_Smart_Cb type callback for handling click event.
259 * @param[in]: priv : the user data.
260 * @param[in]: obj : the corresponding object which the click event occurred.
261 * @param[in]: ev : event info.
265 static void _subitem_clicked_cb(void *priv, Evas_Object *obj, void *ev)
267 struct _sysclk_data *data;
268 struct settingitem *item;
279 _set_selected_value(data, obj);
281 value = evas_object_data_get(obj, ITEMID);
283 _ERR("get value from obj failed. DATA_ID: %s", ITEMID);
287 if (!strncmp(value, MANUAL, BUF_SIZE)) {
290 list = viewdata_get_childitems_list(data->vdata);
292 _ERR("list of clock is null.");
296 item = eina_list_nth(list, CLOCK_ITEM);
298 _ERR("there is no clock_mode item in list.");
302 id = settingitem_get_id(item);
304 _ERR("get item id failed.");
308 name = settingitem_get_display_name(item);
310 _ERR("get display_name failed.");
314 data->ugd.display_name = name;
316 settingmgr_view_push(data->mgr, id, (void *)&data->ugd);
323 * Evas_Object_Event_Cb type callback for handling key press event.
325 * @param[in]: priv : the user data.
326 * @param[in]: e : the evas canvas.
327 * @param[in]: obj : the corresponding object which the key press event occurred.
328 * @param[in]: ei : event info.
332 static void _subitem_keypress_cb(void *priv, Evas *e,
333 Evas_Object *obj, void *ei)
335 Evas_Event_Key_Down *ev;
336 struct _sysclk_data *data;
347 if (!strncmp(ev->keyname, KEY_BACK, BUF_SIZE) || !strncmp(ev->keyname, KEY_BACK_REMOTE, BUF_SIZE))
352 * Create system clock sublist items.
354 * @param[in]: data : the user data.
355 * @param[in]: list : the eina list containing items.
356 * @param[in]: selval : the current selected value of item.
358 * @return: 0 - Success, -1 - Fail.
360 static int _add_sysclk_sublist_item(struct _sysclk_data *data,
361 Eina_List *list, const char *selval)
363 Evas_Object *box, *cp, *btn, *del_btn;
365 Eina_Array_Iterator aiter;
368 const char *disp, *value;
371 if (!data || !list || !data->ctxpopup || !selval) {
372 _ERR("invalid arguments.");
378 box = utils_add_box(cp);
380 _ERR("utils add box to ctxpopup failed.");
384 elm_object_content_set(cp, box);
386 array = eina_array_new(1);
388 _ERR("eina array new failed.");
389 evas_object_del(box);
394 EINA_LIST_FOREACH(list, iter, li) {
395 disp = listitem_get_display_name(li);
397 _ERR("display name of list item is null.");
401 btn = utils_add_btn(box, CTXPOPUPBTN_STYLE, disp, EINA_TRUE);
403 _ERR("utils add button failed.");
407 value = listitem_get_value(li);
409 _ERR("value of this list item is null.");
413 if (!strncmp(selval, value, strlen(selval))) {
414 elm_object_signal_emit(btn,
415 CTXPOPUPBTN_BUTTON_HIGHLIGHT,
416 CTXPOPUPBTN_BUTTON_SOURCE);
420 evas_object_data_set(btn, ITEMID, value);
422 evas_object_smart_callback_add(btn, SIG_FOCUSED,
423 _subitem_focusin_cb, data);
424 evas_object_smart_callback_add(btn, SIG_UNFOCUSED,
425 _subitem_focusout_cb, data);
426 evas_object_smart_callback_add(btn, SIG_CLICKED,
427 _subitem_clicked_cb, data);
428 evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN,
429 _subitem_keypress_cb, data);
431 elm_box_pack_end(box, btn);
432 eina_array_push(array, btn);
435 elm_object_focus_set(btn, EINA_TRUE);
447 EINA_ARRAY_ITER_NEXT(array, j, del_btn, aiter) {
449 evas_object_del(del_btn);
452 evas_object_del(box);
453 eina_array_free(array);
459 * Create system clock sublist view.
461 * @param[in]: data : the user data.
463 * @return: 0 - Success, -1 - Fail.
465 static int _draw_sysclk_sublist(struct _sysclk_data *data)
467 Evas_Object *ctxpopup;
469 struct settingview_data *vdata;
470 struct obj_geometry_data *ogd;
472 int xpos, ypos, height, count, r;
475 if (!data || !data->ctxpopup || !data->ogd || !data->vdata) {
476 _ERR("Invalid argument\n");
480 ctxpopup = data->ctxpopup;
485 itlist = _get_item_list(vdata, &count);
487 _ERR("Get item list failed");
493 selval = _get_selected_value(data);
495 _ERR("Get selected value failed");
499 if (count > MAX_ITEMS) {
500 _ERR("system clock sublist is too many.");
504 r = _add_sysclk_sublist_item(data, itlist, selval);
506 _ERR("add system clock sublist items failed.");
510 if (ogd->width <= 0) {
511 _ERR("width of object is less than 0.");
515 ratio = (ogd->width - LEFT_OFFSET) / ogd->width;
516 xpos = ogd->x + ogd->width * ratio;
519 height = data->count * ITEM_HEIGHT;
521 if (ypos > WIN_HEIGHT)
522 ypos = ypos - height;
524 evas_object_move(ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE);
526 utils_set_focus_directions(data->array, data->count);
528 provider_release_list_value(selval);
533 provider_release_list_value(selval);
538 * Evas_Smart_Cb type callback for handling ctxpopup dismissed event.
540 * @param[in]: priv : the user data.
541 * @param[in]: obj : the corresponding object which the dismissed event occurred.
542 * @param[in]: ev : event info.
546 static void _ctxpopup_dismissed(void *priv, Evas_Object *obj,
549 struct _sysclk_data *data;
558 settingmgr_view_pop(data->mgr);
562 * Create all the UI components of system clock sublist view.
564 * @param[in]: mgr : view manager of settings views.
565 * @param[in]: view : data of view.
566 * @param[in]: prev : the user data.
568 * @return: the base layout of system clock view or null
571 static Evas_Object *_create(struct setting_mgr *mgr,
572 struct settingview_data *view, void *prev)
575 Evas_Object *ctxpopup;
577 struct _sysclk_data *data;
578 struct evas_obj_data *ugd;
579 struct obj_geometry_data *ogd;
581 if (!mgr || !view || !prev) {
582 _ERR("Invalid argument!\n");
587 ogd = evas_object_data_get(ugd->cur_btn, DATA_ID);
589 win = settingmgr_get_win(mgr);
591 _ERR("settingmgr get window failed.");
595 data = calloc(1, sizeof(*data));
597 _ERR("Unable to allocate memory.");
603 base = elm_layout_add(win);
609 elm_layout_file_set(base, EDJ_FILE, SUBLIST_VIEW_PAGE);
611 ctxpopup = utils_add_ctxpopup(win, SUBLIST_CTXPOPUP_STYLE1);
613 _ERR("Fail to add ctxpopup");
614 evas_object_del(base);
619 evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED,
620 _ctxpopup_dismissed, data);
625 data->ctxpopup = ctxpopup;
629 evas_object_data_set(base, DATA_ID, data);
631 if (_draw_sysclk_sublist(data) == -1) {
632 _ERR("Error in drawing items function\n");
633 evas_object_del(base);
634 evas_object_del(ctxpopup);
643 * Show the system clock view.
645 * @param[in]: base : the base layout of system clock view.
649 static void _show(Evas_Object *base)
651 struct _sysclk_data *data;
654 _ERR("Invalid argument\n");
658 data = evas_object_data_get(base, DATA_ID);
660 _ERR("Get sublist data failed\n");
664 evas_object_show(data->ctxpopup);
665 evas_object_show(base);
669 * Destroy the system clock view.
671 * @param[in]: base : the base layout of system clock view.
675 static void _destroy(Evas_Object *base)
677 struct _sysclk_data *data;
682 data = evas_object_data_get(base, DATA_ID);
684 _ERR("Invalid arguments");
685 evas_object_del(data->ctxpopup);
686 evas_object_del(base);
691 eina_array_free(data->array);
695 evas_object_del(data->ctxpopup);
696 evas_object_del(base);
699 viewdata_release(data->vdata);
705 * Hide the system clock view.
707 * @param[in]: base : the base layout of system clock view.
711 static void _hide(Evas_Object *base)
713 struct _sysclk_data *data;
718 data = evas_object_data_get(base, DATA_ID);
720 _ERR("Invalid arguments");
724 evas_object_hide(base);
725 evas_object_hide(data->ctxpopup);
729 * Refresh Manual/Auto text of system clock item.
731 * @param[in]: base : the base layout of system clock view.
735 static void _refresh(Evas_Object *base)
737 struct _sysclk_data *data;
740 _ERR("the base of system clock is null.");
744 data = evas_object_data_get(base, DATA_ID);
746 _ERR("data get failed. DATA_ID: %s", DATA_ID);
754 * view class of system clock view.
756 static struct setting_class _vclass = {
757 .title = VCLASS_TITLE_SYSTEM_CLOCK,
767 * Return view class of system clock view.
771 * @return: the view class of system clock view.
773 struct setting_class *view_system_clock_get_vclass(void)