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://floralicense.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-waiting.h"
23 #include "cst-widget.h"
24 #include "cst-common.h"
25 #include "cst-tapi-request.h"
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);
36 static Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
37 static Evas_Object *waiting_gl = NULL;
39 static CstGlItemDisplayInfo_t list_call_waiting[] = {
40 {1, CST_STR_CALL_WAITING, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF_PROGRESS, NULL},
42 {1, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
45 static void __cst_set_genlist_item_styles(void)
47 ENTER(__cst_set_genlist_item_styles);
49 if (!itc_1text_1icon) {
50 itc_1text_1icon = elm_genlist_item_class_new();
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;
60 static void __cst_destroy_genlist_item_styles(void)
62 ENTER(__cst_destroy_genlist_item_styles);
64 if (itc_1text_1icon) {
65 elm_genlist_item_class_free(itc_1text_1icon);
66 itc_1text_1icon = NULL;
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)
73 ENTER(__cst_on_update_cw_state);
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);
82 if (error == CST_ERROR_NONE) {
83 if (cw_state == EINA_TRUE) {
84 ugd->cw_state = CST_SS_STATE_ON;
86 ugd->cw_state = CST_SS_STATE_OFF;
88 elm_genlist_item_update(item_data->gl_item);
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);
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);
103 static void __cst_gl_sel_cw(void *data, Evas_Object *obj, void *event_info)
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;
110 if (ugd->cw_state == CST_SS_STATE_PROGRESS) {
114 Eina_Bool check_state = elm_check_state_get(item_data->eo_check);
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);
124 static void __cst_on_changed_cw_check(void *data, Evas_Object *obj, void *event_info)
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);
131 if (elm_object_item_disabled_get(item_data->gl_item) == EINA_TRUE) {
132 elm_check_state_set(obj, EINA_FALSE);
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);
145 static char *__cst_gl_label_get_cw(void *data, Evas_Object *obj, const char *part)
147 retv_if(NULL == data, NULL);
148 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
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));
159 static Evas_Object *__cst_gl_icon_get_cw(void *data, Evas_Object *obj, const char *part)
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;
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;
174 item_data->eo_check = icon = _cst_create_onoff_button(obj, check_state,
175 __cst_on_changed_cw_check, item_data);
177 case CST_SS_STATE_PROGRESS:
178 icon = _cst_create_progressbar(obj);
187 static void __cst_gl_del_cw(void *data, Evas_Object *obj)
189 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
196 static Evas_Object *__cst_create_genlist_cw(void *data)
198 ENTER(__cst_create_genlist_cw);
199 retv_if(NULL == data, NULL);
200 CstUgData_t *ugd = (CstUgData_t *)data;
202 Evas_Object *genlist;
203 CstGlItemData_t *item_data;
205 genlist = elm_genlist_add(ugd->nf);
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;
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);
230 _cst_create_genlist_separator_no_line(genlist);
235 static void __cst_on_click_cw_back_button(void *data, Evas_Object *obj, void *event_info)
237 ENTER(__cst_on_click_cw_back_button);
238 retm_if(data == NULL, "NULL UgData");
240 CstUgData_t *ugd = (CstUgData_t *)data;
241 _cst_cancel_all_ss_request(ugd);
243 ugd->back_button = _cst_get_navifr_prev_btn(ugd->nf);
245 _cst_destroy_call_waiting();
248 void _cst_on_click_call_waiting(void *data, Evas *evas, Evas_Object *obj, void *event_info)
250 ENTER(_cst_on_click_call_waiting);
251 CstUgData_t *ugd = (CstUgData_t *)data;
252 Evas_Object *back_btn = NULL;
254 Elm_Object_Item *navi_it;
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);
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);
270 __cst_set_genlist_item_styles();
272 waiting_gl = __cst_create_genlist_cw(ugd);
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);
287 void _cst_destroy_call_waiting(void)
289 ENTER(_cst_destroy_call_waiting);
291 __cst_destroy_genlist_item_styles();
293 if (waiting_gl != NULL) {
294 elm_genlist_clear(waiting_gl);
295 evas_object_del(waiting_gl);