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 = (char *) 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");
187 data = (struct _sysclk_data *) priv;
189 value = (char *) 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");
232 data = (struct _sysclk_data *) priv;
234 value = (char *) 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;
277 data = (struct _sysclk_data *) priv;
279 _set_selected_value(data, obj);
281 value = (char *) 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 = (struct settingitem *) 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;
341 data = (struct _sysclk_data *) priv;
342 ev = (Evas_Event_Key_Down *) ei;
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;
369 const char *disp, *value;
372 if (!data || !list || !data->ctxpopup || !selval) {
373 _ERR("invalid arguments.");
379 box = utils_add_box(cp);
381 _ERR("utils add box to ctxpopup failed.");
385 elm_object_content_set(cp, box);
387 array = eina_array_new(1);
389 _ERR("eina array new failed.");
390 evas_object_del(box);
395 EINA_LIST_FOREACH(list, iter, obj) {
396 li = (struct listitem *) obj;
397 disp = listitem_get_display_name(li);
399 _ERR("display name of list item is null.");
403 btn = utils_add_btn(box, (char *) CTXPOPUPBTN_STYLE, disp, EINA_TRUE);
405 _ERR("utils add button failed.");
409 value = listitem_get_value(li);
411 _ERR("value of this list item is null.");
415 if (!strncmp(selval, value, strlen(selval))) {
416 elm_object_signal_emit(btn,
417 CTXPOPUPBTN_BUTTON_HIGHLIGHT,
418 CTXPOPUPBTN_BUTTON_SOURCE);
422 evas_object_data_set(btn, ITEMID, value);
424 evas_object_smart_callback_add(btn, SIG_FOCUSED,
425 _subitem_focusin_cb, data);
426 evas_object_smart_callback_add(btn, SIG_UNFOCUSED,
427 _subitem_focusout_cb, data);
428 evas_object_smart_callback_add(btn, SIG_CLICKED,
429 _subitem_clicked_cb, data);
430 evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN,
431 _subitem_keypress_cb, data);
433 elm_box_pack_end(box, btn);
434 eina_array_push(array, btn);
437 elm_object_focus_set(btn, EINA_TRUE);
449 EINA_ARRAY_ITER_NEXT(array, j, obj, aiter) {
450 del_btn = (Evas_Object *) obj;
452 evas_object_del(del_btn);
455 evas_object_del(box);
456 eina_array_free(array);
462 * Create system clock sublist view.
464 * @param[in]: data : the user data.
466 * @return: 0 - Success, -1 - Fail.
468 static int _draw_sysclk_sublist(struct _sysclk_data *data)
470 Evas_Object *ctxpopup;
472 struct settingview_data *vdata;
473 struct obj_geometry_data *ogd;
475 int xpos, ypos, height, count, r;
478 if (!data || !data->ctxpopup || !data->ogd || !data->vdata) {
479 _ERR("Invalid argument\n");
483 ctxpopup = data->ctxpopup;
488 itlist = _get_item_list(vdata, &count);
490 _ERR("Get item list failed");
496 selval = _get_selected_value(data);
498 _ERR("Get selected value failed");
502 if (count > MAX_ITEMS) {
503 _ERR("system clock sublist is too many.");
507 r = _add_sysclk_sublist_item(data, itlist, selval);
509 _ERR("add system clock sublist items failed.");
513 if (ogd->width <= 0) {
514 _ERR("width of object is less than 0.");
518 ratio = (ogd->width - LEFT_OFFSET) / ogd->width;
519 xpos = ogd->x + ogd->width * ratio;
522 height = data->count * ITEM_HEIGHT;
524 if (ypos > WIN_HEIGHT)
525 ypos = ypos - height;
527 evas_object_move(ctxpopup, xpos * ELM_SCALE, ypos * ELM_SCALE);
529 utils_set_focus_directions(data->array, data->count);
531 provider_release_list_value(selval);
536 provider_release_list_value(selval);
541 * Evas_Smart_Cb type callback for handling ctxpopup dismissed event.
543 * @param[in]: priv : the user data.
544 * @param[in]: obj : the corresponding object which the dismissed event occurred.
545 * @param[in]: ev : event info.
549 static void _ctxpopup_dismissed(void *priv, Evas_Object *obj,
552 struct _sysclk_data *data;
557 data = (struct _sysclk_data *) priv;
561 settingmgr_view_pop(data->mgr);
565 * Create all the UI components of system clock sublist view.
567 * @param[in]: mgr : view manager of settings views.
568 * @param[in]: view : data of view.
569 * @param[in]: prev : the user data.
571 * @return: the base layout of system clock view or null
574 static Evas_Object *_create(struct setting_mgr *mgr,
575 struct settingview_data *view, void *prev)
578 Evas_Object *ctxpopup;
580 struct _sysclk_data *data;
581 struct evas_obj_data *ugd;
582 struct obj_geometry_data *ogd;
584 if (!mgr || !view || !prev) {
585 _ERR("Invalid argument!\n");
589 ugd = (struct evas_obj_data *) prev;
590 ogd = (struct obj_geometry_data *) evas_object_data_get(ugd->cur_btn, DATA_ID);
592 win = settingmgr_get_win(mgr);
594 _ERR("settingmgr get window failed.");
598 data = (struct _sysclk_data *) calloc(1, sizeof(*data));
600 _ERR("Unable to allocate memory.");
606 base = elm_layout_add(win);
612 elm_layout_file_set(base, EDJ_FILE, SUBLIST_VIEW_PAGE);
614 ctxpopup = utils_add_ctxpopup(win, (char *) SUBLIST_CTXPOPUP_STYLE1);
616 _ERR("Fail to add ctxpopup");
617 evas_object_del(base);
622 evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED,
623 _ctxpopup_dismissed, data);
628 data->ctxpopup = ctxpopup;
632 evas_object_data_set(base, DATA_ID, data);
634 if (_draw_sysclk_sublist(data) == -1) {
635 _ERR("Error in drawing items function\n");
636 evas_object_del(base);
637 evas_object_del(ctxpopup);
646 * Show the system clock view.
648 * @param[in]: base : the base layout of system clock view.
652 static void _show(Evas_Object *base)
654 struct _sysclk_data *data;
657 _ERR("Invalid argument\n");
661 data = (struct _sysclk_data *) evas_object_data_get(base, DATA_ID);
663 _ERR("Get sublist data failed\n");
667 evas_object_show(data->ctxpopup);
668 evas_object_show(base);
672 * Destroy the system clock view.
674 * @param[in]: base : the base layout of system clock view.
678 static void _destroy(Evas_Object *base)
680 struct _sysclk_data *data;
685 data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID);
687 _ERR("Invalid arguments");
688 evas_object_del(data->ctxpopup);
689 evas_object_del(base);
694 eina_array_free(data->array);
698 evas_object_del(data->ctxpopup);
699 evas_object_del(base);
702 viewdata_release(data->vdata);
708 * Hide the system clock view.
710 * @param[in]: base : the base layout of system clock view.
714 static void _hide(Evas_Object *base)
716 struct _sysclk_data *data;
721 data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID);
723 _ERR("Invalid arguments");
727 evas_object_hide(base);
728 evas_object_hide(data->ctxpopup);
732 * Refresh Manual/Auto text of system clock item.
734 * @param[in]: base : the base layout of system clock view.
738 static void _refresh(Evas_Object *base)
740 struct _sysclk_data *data;
743 _ERR("the base of system clock is null.");
747 data = (struct _sysclk_data *)evas_object_data_get(base, DATA_ID);
749 _ERR("data get failed. DATA_ID: %s", DATA_ID);
757 * view class of system clock view.
759 static struct setting_class _vclass = {
760 VCLASS_TITLE_SYSTEM_CLOCK,
776 * Return view class of system clock view.
780 * @return: the view class of system clock view.
782 struct setting_class *view_system_clock_get_vclass(void)