2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
17 #include <Elementary.h>
19 #include "cst-common-string.h"
20 #include "cst-call-setting.h"
22 #include "cst-barring.h"
23 #include "cst-barring-ime.h"
24 #include "cst-widget.h"
25 #include "cst-common.h"
26 #include "cst-tapi-request.h"
29 static void __cst_on_click_cb_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info);
31 static Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
33 static CstGlItemDisplayInfo_t list_call_barring[] = {
34 {1, CST_STR_CALL_ALL_OUTGOING_CALLS, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, __cst_on_click_cb_onoff},
35 {1, CST_STR_INTL_CALLS, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, __cst_on_click_cb_onoff},
36 {1, CST_STR_CALL_INTL_EXCEPT_HOME, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, __cst_on_click_cb_onoff},
37 {1, CST_STR_ALL_INCOMING_CALLS, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, __cst_on_click_cb_onoff},
38 {1, CST_STR_CALL_INCOMING_WHEN_ROAMING, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, __cst_on_click_cb_onoff},
40 {1, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
43 static void __cst_on_click_cb_back_button(void *data, Evas_Object *obj, void *event_info)
45 ENTER(__cst_on_click_cb_back_button);
46 retm_if(data == NULL, "NULL UgData");
48 CstUgData_t *ugd = (CstUgData_t *)data;
49 _cst_cancel_all_ss_request(ugd);
51 ugd->back_button = _cst_get_navifr_prev_btn(ugd->nf);
54 static void __cst_disable_cb_glitem(CstGlItemData_t *item_data)
56 ENTER(__cst_disable_cb_glitem);
57 CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
58 ugd->cb_state[item_data->index] = CST_SS_STATE_OFF;
59 elm_genlist_item_update(item_data->gl_item);
60 elm_object_item_disabled_set(item_data->gl_item, EINA_TRUE);
63 static int __cst_update_cb_state(int call_type, int cb_flavour,
64 Eina_Bool cb_state, char *number,
65 int error, int req_action, void *data)
67 retv_if(NULL == data, -1);
68 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
69 CstUgData_t *ugd = item_data->ugd;
70 DBG("call_type=%d (0:voice 1:video)", call_type);
71 DBG("cb_flavour=%d (6:BAOC 7:BAOIC 8:BAOIC exc home 9:BAIC 10:BAIC roaming)", cb_flavour);
72 DBG("cb_state=%d (1:on 0:off), error=%d", cb_state, error);
73 DBG("req_action=%d(0: Activate, 1:Deactivate, 2:Query)", req_action);
74 retv_if((call_type != ugd->call_type && call_type != CST_CALLTYPE_ALL), -1);
76 if (error == CST_ERROR_NONE) {
77 if (cb_state == EINA_TRUE)
78 ugd->cb_state[item_data->index] = CST_SS_STATE_ON;
80 ugd->cb_state[item_data->index] = CST_SS_STATE_OFF;
81 elm_genlist_item_update(item_data->gl_item);
83 if (req_action != CST_ACTION_QUERY) {
84 if (error != CST_ERROR_SERVICE_UNAVAILABLE &&
85 error != CST_ERROR_REJECTED_BY_NETWORK &&
86 error != CST_ERROR_UNKNOWN) {
87 if (req_action == CST_ACTION_DEACTIVATE)
88 ugd->cb_state[item_data->index] = CST_SS_STATE_ON;
90 ugd->cb_state[item_data->index] = CST_SS_STATE_OFF;
92 ugd->cb_state[item_data->index] = CST_SS_STATE_OFF;
94 elm_genlist_item_update(item_data->gl_item);
95 ugd->popup = (Evas_Object *)_cst_create_error_popup(ugd->nf, error);
96 evas_object_show(ugd->popup);
98 __cst_disable_cb_glitem(item_data);
103 static void __cst_query_cb_status(CstGlItemData_t *item_data)
105 ENTER(__cst_query_cb_status);
106 ret_if(NULL == item_data);
107 CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
110 ugd->original_state = EINA_FALSE;
111 switch (item_data->index) {
113 cb_flavour = CST_SSTYPE_CB_OC;
114 DBG("CST_SSTYPE_CB_OC");
117 cb_flavour = CST_SSTYPE_CB_OIC;
118 DBG("CST_SSTYPE_CB_OIC");
121 cb_flavour = CST_SSTYPE_CB_OICEH;
122 DBG("CST_SSTYPE_CB_OICEH");
125 cb_flavour = CST_SSTYPE_CB_IC;
126 DBG("CST_SSTYPE_CB_IC");
129 cb_flavour = CST_SSTYPE_CB_ICR;
130 DBG("CST_SSTYPE_CB_ICR");
137 _cst_add_ss_request(&ugd->req_queue,
138 CST_ACTION_QUERY, ugd->call_type, cb_flavour,
139 NULL, __cst_update_cb_state, item_data, -1, ugd);
142 static void __cst_on_click_cb_ime_done_btn(void *data, Evas_Object *obj, void *event_info)
144 ENTER(__cst_on_click_cb_ime_done_btn);
147 CallSettingSSReq_t *req = (CallSettingSSReq_t *)data;
149 CstGlItemData_t *item_data = (CstGlItemData_t *)req->data;
150 CstUgData_t *ugd = item_data->ugd;
152 char buffer[CST_MAX_PHONE_NUMBER_LEN];
154 if (_cst_get_cb_input_password(buffer, ugd) > 0) {
155 ugd->cb_state[item_data->index] = CST_SS_STATE_PROGRESS;
156 elm_genlist_item_update(item_data->gl_item);
158 DBG("activate CB pwd=%s", buffer);
159 snprintf(req->number, CST_MAX_PHONE_NUMBER_LEN, "%s", buffer);
160 _cst_add_ss_request(&ugd->req_queue,
161 req->action, req->call_type, req->flavour,
162 req->number, __cst_update_cb_state, item_data, -1, ugd);
164 memset(ugd->c_item, 0, sizeof(ugd->c_item));
165 elm_naviframe_item_pop(ugd->nf);
166 ugd->back_button = _cst_get_navifr_prev_btn(ugd->nf);
170 static void __cst_on_click_cb_ime_cancel_btn(void *data, Evas_Object *obj, void *event_info)
172 ENTER(__cst_on_click_cb_ime_cancel_btn);
175 CallSettingSSReq_t *req = (CallSettingSSReq_t *)data;
176 CstGlItemData_t *item_data = (CstGlItemData_t *)req->data;
177 CstUgData_t *ugd = item_data->ugd;
179 DBG("original state : %d", req->original_state);
180 if (req->original_state == CST_SS_STATE_ON)
181 ugd->cb_state[item_data->index] = CST_SS_STATE_ON;
183 ugd->cb_state[item_data->index] = CST_SS_STATE_OFF;
184 elm_genlist_item_update(item_data->gl_item);
186 memset(ugd->c_item, 0, sizeof(ugd->c_item));
187 elm_naviframe_item_pop(ugd->nf);
188 ugd->back_button = _cst_get_navifr_prev_btn(ugd->nf);
193 static char *__cst_gl_label_get_cb(void *data, Evas_Object *obj, const char *part)
195 retv_if(NULL == data, NULL);
196 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
198 if (strcmp(part, "elm.text") == 0) {
199 if (list_call_barring[item_data->index].str_id != -1)
200 return strdup(T_(list_call_barring[item_data->index].str_id));
205 static void __cst_gl_del_cb(void *data, Evas_Object *obj)
207 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
213 static void __cst_update_change_cb_req(CstGlItemData_t *item_data, Eina_Bool req_state)
215 ret_if(item_data == NULL);
218 CallSettingSSReq_t *req = NULL;
219 CstUgData_t *ugd = item_data->ugd;
220 Elm_Object_Item *navi_it;
223 req = (CallSettingSSReq_t *)calloc(1, sizeof(CallSettingSSReq_t));
227 req->data = item_data;
228 req->call_type = ugd->call_type;
231 DBG("req_state = %d", req_state);
232 switch (item_data->index) {
234 req->flavour = CST_SSTYPE_CB_OC;
235 DBG("CST_SSTYPE_CB_OC");
238 req->flavour = CST_SSTYPE_CB_OIC;
239 DBG("CST_SSTYPE_CB_OIC");
242 req->flavour = CST_SSTYPE_CB_OICEH;
243 DBG("CST_SSTYPE_CB_OICEH");
246 req->flavour = CST_SSTYPE_CB_IC;
247 DBG("CST_SSTYPE_CB_IC");
250 req->flavour = CST_SSTYPE_CB_ICR;
251 DBG("CST_SSTYPE_CB_ICR");
258 ugd->original_state = !req_state;
259 if (req_state == EINA_TRUE) {
260 req->original_state = CST_SS_STATE_OFF;
261 req->action = CST_ACTION_ACTIVATE;
263 req->original_state = CST_SS_STATE_ON;
264 req->action = CST_ACTION_DEACTIVATE;
267 eo = _cst_create_cb_ime(ugd->nf, NULL, ugd);
268 _cst_remove_naviframe(ugd->nf);
269 navi_it = elm_naviframe_item_push(ugd->nf,
270 T_(CST_STR_PASSWORD), NULL, NULL, eo, "1line");
272 btn = _cst_create_title_btn(ugd->nf, (char *)T_(CST_STR_CANCEL),
273 __cst_on_click_cb_ime_cancel_btn, (void *)req);
274 elm_object_item_part_content_set(navi_it, "title_right_btn", btn);
276 btn = _cst_create_title_btn(ugd->nf, (char *)T_(CST_STR_DONE),
277 __cst_on_click_cb_ime_done_btn, (void *)req);
278 elm_object_item_part_content_set(navi_it, "title_left_btn", btn);
279 elm_object_disabled_set(btn, EINA_TRUE);
282 static void __cst_on_click_cb_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info)
284 ret_if(NULL == data);
285 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
286 CstUgData_t *ugd = item_data->ugd;
287 if (ugd->cb_state[item_data->index] == CST_SS_STATE_PROGRESS)
290 Eina_Bool check_state = elm_check_state_get(item_data->eo_check);
292 __cst_update_change_cb_req(item_data, !check_state);
293 elm_genlist_item_update(item_data->gl_item);
296 static void __cst_gl_sel_cb(void *data, Evas_Object *obj, void *event_info)
298 ret_if(data == NULL);
299 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
300 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
301 if (list_call_barring[item_data->index].func)
302 list_call_barring[item_data->index].func((void *)item_data, NULL, obj, event_info);
306 static void __cst_on_changed_cb_check(void *data, Evas_Object *obj, void *event_info)
308 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
309 Eina_Bool check_state = elm_check_state_get(obj);
311 if (elm_object_item_disabled_get(item_data->gl_item) == EINA_TRUE) {
312 elm_check_state_set(obj, EINA_FALSE);
316 __cst_update_change_cb_req(item_data, check_state);
319 static Evas_Object *__cst_gl_icon_get_cb(void *data, Evas_Object *obj, const char *part)
321 retv_if(NULL == data, NULL);
322 Evas_Object *icon = NULL;
323 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
324 CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
325 Eina_Bool check_state = EINA_FALSE;
327 if (!strcmp(part, "elm.icon")) {
328 switch (ugd->cb_state[item_data->index]) {
329 case CST_SS_STATE_ON:
330 case CST_SS_STATE_OFF:
331 DBG("ugd->cb_state : %d(%d)",
332 ugd->cb_state[item_data->index], item_data->index);
333 if (ugd->cb_state[item_data->index] == CST_SS_STATE_ON)
334 check_state = EINA_TRUE;
335 item_data->eo_check = icon = _cst_create_onoff_button(obj, check_state,
336 __cst_on_changed_cb_check, item_data);
338 case CST_SS_STATE_PROGRESS:
339 icon = _cst_create_progressbar(obj);
348 static Evas_Object *__cst_create_genlist_cb(void *data)
350 ENTER(__cst_create_genlist_cb);
351 retv_if(NULL == data, NULL);
352 CstUgData_t *ugd = (CstUgData_t *)data;
354 Evas_Object *genlist;
355 CstGlItemData_t *item_data;
357 if (!itc_1text_1icon)
358 itc_1text_1icon = elm_genlist_item_class_new();
360 itc_1text_1icon->item_style = "dialogue/1text.1icon";
361 itc_1text_1icon->func.text_get = __cst_gl_label_get_cb;
362 itc_1text_1icon->func.content_get = __cst_gl_icon_get_cb;
363 itc_1text_1icon->func.state_get = NULL;
364 itc_1text_1icon->func.del = __cst_gl_del_cb;
366 genlist = elm_genlist_add(ugd->nf);
367 elm_object_style_set(genlist, "dialogue");
369 _cst_create_genlist_separator(genlist, EINA_FALSE);
370 for (index = 0; list_call_barring[index].style != CST_GL_ITEM_NONE; ++index) {
371 item_data = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
372 retv_if(item_data == NULL, NULL);
373 item_data->index = index;
374 item_data->ugd = ugd;
375 if (list_call_barring[index].style == CST_GL_ITEM_1TEXT_ONOFF_PROGRESS) {
376 ugd->cb_state[index] = CST_SS_STATE_PROGRESS;
377 item_data->gl_item = elm_genlist_item_append(genlist, itc_1text_1icon,
378 (void *)item_data, NULL, list_call_barring[index].flags,
379 __cst_gl_sel_cb, item_data);
380 __cst_query_cb_status(item_data);
388 _cst_create_genlist_separator_no_line(genlist);
393 void _cst_on_click_call_barring(void *data, Evas *evas, Evas_Object *obj, void *event_info)
395 ENTER(_cst_on_click_call_barring);
396 ret_if(NULL == data);
397 CstUgData_t *ugd = (CstUgData_t *)data;
398 Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *)event_info;
399 Evas_Object *layout = NULL, *back_btn = NULL;
400 Elm_Object_Item *navi_it;
402 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) {
406 if (_cst_check_flight_mode()) {
407 ugd->popup = _cst_create_error_popup(ugd->nf,
408 CST_ERROR_CHANGE_FLIGHT_MODE);
409 evas_object_show(ugd->popup);
413 if (!_cst_check_sim_status()) {
414 ugd->popup = _cst_create_error_popup(ugd->nf,
415 CST_ERROR_INSERT_SIM_CARD);
416 evas_object_show(ugd->popup);
420 ugd->call_type = CST_CALLTYPE_VOICE;
423 Evas_Object *genlist = __cst_create_genlist_cb(ugd);
425 layout = elm_layout_add(ugd->nf);
426 elm_layout_file_set(layout, EDJ_NAME, "toolbar");
427 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
428 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
429 elm_object_part_content_set(layout, "elm.swallow.contents", genlist);
430 navi_it = elm_naviframe_item_push(ugd->nf, T_(CST_STR_CALL_BARRING),
431 NULL, NULL, layout, "1line");
432 back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
433 evas_object_smart_callback_add(back_btn, "clicked",
434 __cst_on_click_cb_back_button, ugd);