Tizen 2.1 base
[apps/core/preloaded/sat-ui.git] / src / select-item-view.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include "stdlib.h"
19 #include <string.h>
20 #include <appcore-efl.h>
21 #include <TelSat.h>
22 #include <Elementary.h>
23 #include "sat-ui-debug.h"
24 #include "select-item-view.h"
25 #include "sat-ui.h"
26 #include "sat-ui-icon.h"
27 #include "winset.h"
28 #include "tel-request.h"
29 #include <libintl.h>
30 #include "common_string.h"
31
32
33 static void __sat_ui_select_item_destory_object(void *data,Evas *evas, Evas_Object *obj, void *event_info)
34 {
35         evas_object_data_del(obj, "app_data");
36         evas_object_data_del(obj, "tapi_data");
37 }
38
39 static void _gl_sel(void *data, Evas_Object *obj, void *event_info)
40 {
41         int index;
42         Evas_Object *waiting_bar;
43
44
45         unsigned char selected_item_id;
46
47         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
48         SatUiAppData_t *ad;
49         TelSatSelectItemInd_t *select_item_info;
50
51         ad = (SatUiAppData_t *)evas_object_data_get(obj, "app_data");
52         select_item_info = (TelSatSelectItemInd_t *)evas_object_data_get(obj, "tapi_data");
53
54         if (item) {
55                 index = (int)elm_object_item_data_get(item);
56                 selected_item_id = select_item_info->menuItem[index].itemId;
57
58                 send_ui_user_confirm(select_item_info->commandId,
59                                                         TAPI_SAT_CMD_TYPE_SELECT_ITEM,
60                                                         TAPI_SAT_USER_CONFIRM_YES,
61                                                         sizeof(unsigned char),
62                                                         &selected_item_id, ad);
63         }
64                 waiting_bar =  create_waiting_notify(ad->content);
65                 ad->waiting_bar = waiting_bar;
66                 if (ad->timer) {
67                         ecore_timer_del(ad->timer);
68                         ad->timer = NULL;
69                 }
70 }
71
72
73 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
74 {
75         int index = (int) data;
76         SatUiAppData_t *ad;
77         TelSatSelectItemInd_t *select_item_info;
78         char *stripped_str;
79
80         ad = (SatUiAppData_t *)evas_object_data_get(obj, "app_data");
81         retv_if(NULL == ad, NULL);
82         select_item_info = (TelSatSelectItemInd_t *)evas_object_data_get(obj, "tapi_data");
83         if (select_item_info->iconIdList.bIsPresent == true &&
84                 select_item_info->iconIdList.iconListQualifier == TAPI_SAT_ICON_QUALI_SELF_EXPLANATORY)
85                 return NULL;
86         else {
87                 stripped_str = strip_control_char((char *)select_item_info->menuItem[index].text);
88                 return stripped_str;
89         }
90 }
91
92 static void on_clicked_help_button(void *data, Evas_Object *obj, void *event_info)
93 {
94         int index = (int) data;
95         TelSatSelectItemInd_t *select_item_info;
96         SatUiAppData_t *ad;
97
98         ad = (SatUiAppData_t *)evas_object_data_get(obj, "app_data");
99         ret_if(NULL == ad);
100         select_item_info = (TelSatSelectItemInd_t *)evas_object_data_get(obj, "tapi_data");
101         ret_if(NULL == select_item_info);
102         send_ui_user_confirm(select_item_info->commandId,
103                                         TAPI_SAT_CMD_TYPE_SELECT_ITEM,
104                                         TAPI_SAT_USER_CONFIRM_HELP_INFO,
105                                         sizeof(unsigned char),
106                                         &(select_item_info->menuItem[index].itemId), ad);
107 }
108
109 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
110 {
111         Evas_Object *btn;
112         SatUiAppData_t *ad;
113         TelSatSelectItemInd_t *select_item_info;
114
115         ad = (SatUiAppData_t *)evas_object_data_get(obj, "app_data");
116         select_item_info = (TelSatSelectItemInd_t *)evas_object_data_get(obj, "tapi_data");
117         retv_if(NULL == ad, NULL);
118
119         if ((!strcmp(part, "elm.icon"))
120                 || (!strcmp(part, "elm.icon.2"))) {
121                 if (select_item_info->bIsHelpInfoAvailable == true) {
122                         btn = elm_button_add(ad->content);
123                         elm_object_style_set(btn, "info");
124                         evas_object_smart_callback_add(btn, "clicked", on_clicked_help_button, data);
125                         evas_object_event_callback_add(btn, EVAS_CALLBACK_DEL, __sat_ui_select_item_destory_object, NULL);
126                         evas_object_data_set(btn, "app_data",(void *)ad);
127                         evas_object_data_set(btn, "tapi_data",(void *)select_item_info);
128                         evas_object_propagate_events_set(btn, EINA_FALSE);
129                         return btn;
130                 }
131         } else if (!strcmp(part, "elm.icon.1")) {
132                 if (select_item_info->iconIdList.bIsPresent == true) {
133                         return NULL;
134                 }
135         }
136         return NULL;
137 }
138
139 static void on_clicked_back_btn( void *data, Evas_Object* obj, void* event_info )
140 {
141    SatUiAppData_t *ad = (SatUiAppData_t *)data;
142     send_ui_user_confirm(ad->cmd_id, TAPI_SAT_CMD_TYPE_SELECT_ITEM, TAPI_SAT_USER_CONFIRM_NO_OR_CANCEL, 0, NULL, ad);
143     if (ad->timer) {
144                 ecore_timer_del(ad->timer);
145                 ad->timer = NULL;
146     }
147 }
148
149
150 static Eina_Bool on_timer_expired(void *data)
151 {
152         SatUiAppData_t *ad = (SatUiAppData_t *)data;
153         if (ad->timer == NULL) {
154                 DBG("Cancel timout w/o user_confirm");
155         }else{
156                 send_ui_user_confirm(ad->cmd_id, TAPI_SAT_CMD_TYPE_SELECT_ITEM, TAPI_SAT_USER_CONFIRM_TIMEOUT, 0, NULL, ad);
157                 ad->timer = NULL;
158         }
159
160         return ECORE_CALLBACK_CANCEL;
161 }
162
163 int draw_content_select_item(Evas_Object *content, void *tapi_data, void *data)
164 {
165         retv_if(NULL == content, -1);
166         retv_if(NULL == tapi_data, -1);
167         retv_if(NULL == data, -1);
168
169         SatUiAppData_t *ad = (SatUiAppData_t *)data;
170         TelSatSelectItemInd_t *select_item_info = (TelSatSelectItemInd_t *)tapi_data;
171         Evas_Object *l_button;
172         Evas_Object *box;
173         Evas_Object *image;
174         Evas_Object *genlist;
175
176         int index;
177         l_button  = elm_button_add(ad->nf);
178         elm_object_style_set(l_button, "naviframe/end_btn/default");
179         evas_object_smart_callback_add(l_button, "clicked", on_clicked_back_btn, ad);
180         elm_object_item_part_content_set(ad->navi_it, "prev_btn", l_button);
181         ad->back_btn = l_button;
182
183         if (select_item_info->text.stringLen > 0) {
184                 elm_object_item_text_set(ad->navi_it, (char *)select_item_info->text.string);
185         }
186
187         box = elm_box_add(ad->nf);
188         elm_box_horizontal_set(box, EINA_FALSE);
189         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
190         evas_object_show(box);
191
192         if (select_item_info->iconId.bIsPresent == true) {
193                 DBG(" Select item text: %s", (char *)select_item_info->text.string);
194
195                 image = convert_iconinfo_to_evas_object((void *)ad, &select_item_info->iconId.iconInfo);
196
197                 if (select_item_info->iconId.iconQualifier == TAPI_SAT_ICON_QUALI_SELF_EXPLANATORY) {
198                         elm_object_item_text_set(ad->navi_it, " ");
199
200                 }
201                 evas_object_size_hint_align_set(image, 0,0);
202                 evas_object_show(image);
203                 elm_box_pack_end(box, image);
204         }
205
206         /* Select Item List */
207         ad->itc_text_icon->func.text_get = _gl_text_get;
208         ad->itc_text_icon->func.content_get = _gl_content_get;
209
210         if (select_item_info->iconIdList.bIsPresent == true) {
211                 ad->itc_text_icon->item_style= "1text.2icon";
212         } else {
213                 ad->itc_text_icon->item_style = "1text.1icon";
214         }
215
216         genlist = elm_genlist_add(content);
217         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
218         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
219         evas_object_show(genlist);
220         evas_object_data_set(genlist, "app_data",(void *)ad);
221         evas_object_data_set(genlist, "tapi_data",(void *)select_item_info);
222         evas_object_event_callback_add(genlist, EVAS_CALLBACK_DEL, __sat_ui_select_item_destory_object, NULL);
223
224         for (index = 0; index < select_item_info->menuItemCount; index++) {
225                 elm_genlist_item_append(
226                                 genlist,
227                                 ad->itc_text_icon,
228                                 (void *) index,
229                                 NULL,
230                                 ELM_GENLIST_ITEM_NONE,
231                                 _gl_sel,
232                                 NULL
233                 );
234         }
235
236         elm_box_pack_end(box, genlist);
237         elm_object_part_content_set(content, "body", box);
238         ad->timer = ecore_timer_add(SELECT_MENU_DURATION, on_timer_expired, ad);
239
240         return 0;
241 }
242
243