Tizen 2.1 base
[apps/home/call-setting.git] / src / cst-waiting.c
1 /*
2  * Copyright 2012  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 <Elementary.h>
18
19 #include "cst-common-string.h"
20 #include "cst-call-setting.h"
21
22 #include "cst-waiting.h"
23 #include "cst-widget.h"
24 #include "cst-common.h"
25 #include "cst-tapi-request.h"
26 #include "cst-util.h"
27
28 static void __cst_set_genlist_item_styles(void);
29 static void __cst_destroy_genlist_item_styles(void);
30 static void __cst_on_update_cw_state(int call_type, int flavour,
31                                                                          Eina_Bool cw_state, char *number, int error, int req_action, void *data);
32 static char *__cst_gl_label_get_cw(void *data, Evas_Object *obj, const char *part);
33 static Evas_Object *__cst_gl_icon_get_cw(void *data, Evas_Object *obj, const char *part);
34 static void __cst_gl_del_cw(void *data, Evas_Object *obj);
35
36 static Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
37 static Evas_Object *waiting_gl = NULL;
38
39 static CstGlItemDisplayInfo_t list_call_waiting[] = {
40         {1, CST_STR_CALL_WAITING, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, NULL},
41
42         {1, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
43 };
44
45 static void __cst_set_genlist_item_styles(void)
46 {
47         ENTER(__cst_set_genlist_item_styles);
48
49         if (!itc_1text_1icon) {
50                 itc_1text_1icon = elm_genlist_item_class_new();
51         }
52
53         itc_1text_1icon->item_style = "dialogue/1text.1icon";
54         itc_1text_1icon->func.text_get = __cst_gl_label_get_cw;
55         itc_1text_1icon->func.content_get = __cst_gl_icon_get_cw;
56         itc_1text_1icon->func.state_get = NULL;
57         itc_1text_1icon->func.del = __cst_gl_del_cw;
58 }
59
60 static void __cst_destroy_genlist_item_styles(void)
61 {
62         ENTER(__cst_destroy_genlist_item_styles);
63
64         if (itc_1text_1icon) {
65                 elm_genlist_item_class_free(itc_1text_1icon);
66                 itc_1text_1icon = NULL;
67         }
68 }
69
70 static void __cst_on_update_cw_state(int call_type, int flavour,
71                                                                          Eina_Bool cw_state, char *number, int error, int req_action, void *data)
72 {
73         ENTER(__cst_on_update_cw_state);
74         ret_if(NULL == data);
75         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
76         ret_if(NULL == item_data->ugd);
77         CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
78         ret_if(NULL == item_data->gl_item);
79         DBG("req_action=%d(0: Activate, 1:Deactivate, 2:Query)", req_action);
80         DBG("cw_state=%d(0: off, 1:on), error=%d", cw_state, error);
81
82         if (error == CST_ERROR_NONE) {
83                 if (cw_state == EINA_TRUE) {
84                         ugd->cw_state = CST_SS_STATE_ON;
85                 } else {
86                         ugd->cw_state = CST_SS_STATE_OFF;
87                 }
88                 elm_genlist_item_update(item_data->gl_item);
89         } else {
90                 ugd->cw_state = CST_SS_STATE_OFF;
91                 elm_genlist_item_update(item_data->gl_item);
92                 if (req_action != CST_ACTION_QUERY) {
93                         ugd->popup = (Evas_Object *)_cst_create_error_popup(ugd->nf, error);
94                         evas_object_show(ugd->popup);
95                 } else {
96                         ugd->cw_state = CST_SS_STATE_OFF;
97                         elm_genlist_item_update(item_data->gl_item);
98                         elm_object_item_disabled_set(item_data->gl_item, EINA_TRUE);
99                 }
100         }
101 }
102
103 static void __cst_gl_sel_cw(void *data, Evas_Object *obj, void *event_info)
104 {
105         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
106         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
107         CstGlItemData_t *item_data = (CstGlItemData_t *)elm_object_item_data_get(it);
108         CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
109
110         if (ugd->cw_state == CST_SS_STATE_PROGRESS) {
111                 return;
112         }
113
114         Eina_Bool check_state = elm_check_state_get(item_data->eo_check);
115
116         int action = check_state ? CST_ACTION_DEACTIVATE : CST_ACTION_ACTIVATE;
117         ugd->cw_state = CST_SS_STATE_PROGRESS;
118         elm_genlist_item_update(item_data->gl_item);
119         _cst_add_ss_request(&ugd->req_queue, action,
120                                                 CST_CALLTYPE_ALL, CST_SSTYPE_CW, NULL,
121                                                 __cst_on_update_cw_state, item_data, -1, ugd);
122 }
123
124 static void __cst_on_changed_cw_check(void *data, Evas_Object *obj, void *event_info)
125 {
126         ret_if(data == NULL);
127         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
128         CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
129         int check_state = elm_check_state_get(obj);
130
131         if (elm_object_item_disabled_get(item_data->gl_item) == EINA_TRUE) {
132                 elm_check_state_set(obj, EINA_FALSE);
133                 return;
134         }
135
136         int action = check_state ? CST_ACTION_ACTIVATE : CST_ACTION_DEACTIVATE;
137         ugd->cw_state = CST_SS_STATE_PROGRESS;
138         elm_genlist_item_update(item_data->gl_item);
139         _cst_add_ss_request(&ugd->req_queue, action,
140                                                 CST_CALLTYPE_ALL, CST_SSTYPE_CW, NULL,
141                                                 __cst_on_update_cw_state, item_data, -1, ugd);
142
143 }
144
145 static char *__cst_gl_label_get_cw(void *data, Evas_Object *obj, const char *part)
146 {
147         retv_if(NULL == data, NULL);
148         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
149
150         if ((strcmp(part, "elm.text") == 0) ||
151                         (strcmp(part, "elm.text.1") == 0)) {
152                 if (list_call_waiting[item_data->index].str_id != -1) {
153                         return strdup(T_(list_call_waiting[item_data->index].str_id));
154                 }
155         }
156         return NULL;
157 }
158
159 static Evas_Object *__cst_gl_icon_get_cw(void *data, Evas_Object *obj, const char *part)
160 {
161         retv_if(NULL == data, NULL);
162         Evas_Object *icon = NULL;
163         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
164         CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
165         Eina_Bool check_state = EINA_FALSE;
166
167         if (!strcmp(part, "elm.icon")) {
168                 switch (ugd->cw_state) {
169                 case CST_SS_STATE_ON:
170                 case CST_SS_STATE_OFF:
171                         if (ugd->cw_state == CST_SS_STATE_ON) {
172                                 check_state = EINA_TRUE;
173                         }
174                         item_data->eo_check = icon = _cst_create_onoff_button(obj, check_state,
175                                                                                  __cst_on_changed_cw_check, item_data);
176                         break;
177                 case CST_SS_STATE_PROGRESS:
178                         icon = _cst_create_progressbar(obj);
179                         break;
180                 default:
181                         return NULL;
182                 }
183         }
184         return icon;
185 }
186
187 static void __cst_gl_del_cw(void *data, Evas_Object *obj)
188 {
189         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
190         if (item_data) {
191                 free(item_data);
192         }
193         return;
194 }
195
196 static Evas_Object *__cst_create_genlist_cw(void *data)
197 {
198         ENTER(__cst_create_genlist_cw);
199         retv_if(NULL == data, NULL);
200         CstUgData_t *ugd = (CstUgData_t *)data;
201         int index = 0;
202         Evas_Object *genlist;
203         CstGlItemData_t *item_data;
204
205         genlist = elm_genlist_add(ugd->nf);
206
207         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
208         _cst_create_genlist_separator(genlist, EINA_FALSE);
209         for (index = 0; list_call_waiting[index].style != CST_GL_ITEM_NONE; ++index) {
210                 item_data = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
211                 retv_if(NULL == item_data, NULL);
212                 item_data->index = index;
213                 item_data->ugd = ugd;
214
215                 if (list_call_waiting[index].style == CST_GL_ITEM_1TEXT_ONOFF_PROGRESS) {
216                         item_data->gl_item = elm_genlist_item_append(genlist, itc_1text_1icon,
217                                                                  (void *)item_data, NULL, list_call_waiting[index].flags,
218                                                                  __cst_gl_sel_cw, item_data);
219                         ugd->cw_state = CST_SS_STATE_PROGRESS;
220                         _cst_add_ss_request(&ugd->req_queue, CST_ACTION_QUERY,
221                                                                 CST_CALLTYPE_ALL, CST_SSTYPE_CW, NULL,
222                                                                 __cst_on_update_cw_state, item_data, -1, ugd);
223                 } else {
224                         DBG("No style");
225                         free(item_data);
226                         item_data = NULL;
227                         return NULL;
228                 }
229         }
230         _cst_create_genlist_separator_no_line(genlist);
231
232         return genlist;
233 }
234
235 static void __cst_on_click_cw_back_button(void *data, Evas_Object *obj, void *event_info)
236 {
237         ENTER(__cst_on_click_cw_back_button);
238         retm_if(data == NULL, "NULL UgData");
239
240         CstUgData_t *ugd = (CstUgData_t *)data;
241         _cst_cancel_all_ss_request(ugd);
242
243         ugd->back_button = _cst_get_navifr_prev_btn(ugd->nf);
244
245         _cst_destroy_call_waiting();
246 }
247
248 void _cst_on_click_call_waiting(void *data, Evas *evas, Evas_Object *obj, void *event_info)
249 {
250         ENTER(_cst_on_click_call_waiting);
251         CstUgData_t *ugd = (CstUgData_t *)data;
252         Evas_Object *back_btn = NULL;
253         Evas_Object *layout;
254         Elm_Object_Item *navi_it;
255
256         if (_cst_check_flight_mode()) {
257                 ugd->popup = _cst_create_error_popup(ugd->nf,
258                                                                                          CST_ERROR_CHANGE_FLIGHT_MODE);
259                 evas_object_show(ugd->popup);
260                 return;
261         }
262
263         if (!_cst_check_sim_status()) {
264                 ugd->popup = _cst_create_error_popup(ugd->nf,
265                                                                                          CST_ERROR_INSERT_SIM_CARD);
266                 evas_object_show(ugd->popup);
267                 return;
268         }
269
270         __cst_set_genlist_item_styles();
271
272         waiting_gl = __cst_create_genlist_cw(ugd);
273
274         /*Create layout */
275         layout = elm_layout_add(ugd->nf);
276         elm_layout_file_set(layout, EDJ_NAME, "toolbar");
277         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
278         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
279         elm_object_part_content_set(layout, "elm.swallow.contents", waiting_gl);
280         navi_it = elm_naviframe_item_push(ugd->nf, T_(CST_STR_CALL_WAITING),
281                                                                           back_btn, NULL, layout, NULL);
282         back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
283         evas_object_smart_callback_add(back_btn, "clicked",
284                                                                    __cst_on_click_cw_back_button, ugd);
285 }
286
287 void _cst_destroy_call_waiting(void)
288 {
289         ENTER(_cst_destroy_call_waiting);
290
291         __cst_destroy_genlist_item_styles();
292
293         if (waiting_gl != NULL) {
294                 elm_genlist_clear(waiting_gl);
295                 evas_object_del(waiting_gl);
296                 waiting_gl = NULL;
297         }
298 }
299