Tizen 2.1 base
[apps/home/call-setting.git] / src / cst-prefix-dial.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 #ifdef _CALL_SET_AUTO_AREA_CODE_SUPPORT
18
19 #include <Elementary.h>
20 #include <vconf.h>
21 #include "cst-common.h"
22 #include "cst-common-string.h"
23 #include "cst-widget.h"
24 #include "cst-call-setting.h"
25
26 #include "cst-prefix-dial.h"
27 #include "cst-prefix-dial-ime.h"
28 #include "cst-delete-list.h"
29 #include "cst-util.h"
30
31 static gboolean keypad_enabled = EINA_FALSE;
32 static Evas_Object *ec_item[3];
33 static Evas_Object *prefixdialling_gl = NULL;
34
35 static void __cst_on_click_sound_eq_back_button(void *data, Evas_Object *obj, void *event_info);
36
37 static void __cst_on_click_sound_eq_back_button(void *data, Evas_Object *obj, void *event_info)
38 {
39         ENTER(__cst_on_click_sound_eq_back_button);
40
41         _cst_destroy_prefix_dialling();
42 }
43
44 void _cst_set_prefix_dialling_list(int index, char *number)
45 {
46         ENTER(_cst_set_prefix_dialling_list);
47
48         ret_if(number == NULL);
49         switch (index) {
50         case CST_ITEM_1:
51                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR,
52                                                    number);
53                 break;
54         case CST_ITEM_2:
55                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR,
56                                                    number);
57                 break;
58         case CST_ITEM_3:
59                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR,
60                                                    number);
61                 break;
62         case CST_ITEM_4:
63                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR,
64                                                    number);
65                 break;
66         case CST_ITEM_5:
67                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR,
68                                                    number);
69                 break;
70         default:
71                 DBG("Error set prefix dialling list");
72                 break;
73         }
74 }
75
76 char *_cst_get_prefix_dialling_list(int index)
77 {
78         ENTER(_cst_get_prefix_dialling_list);
79         char *number = NULL;
80
81         switch (index) {
82         case CST_ITEM_1:
83                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR);
84                 break;
85         case CST_ITEM_2:
86                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR);
87                 break;
88         case CST_ITEM_3:
89                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR);
90                 break;
91         case CST_ITEM_4:
92                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR);
93                 break;
94         case CST_ITEM_5:
95                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR);
96                 break;
97         }
98         retv_if(NULL == number, NULL);
99         return number;
100 }
101
102 static void __cst_click_prefix_dial_save(void *data,
103                 Evas_Object *obj,
104                 void *event_info)
105 {
106         ENTER(__cst_click_prefix_dial_save);
107         ret_if(!data);
108
109         CstUgData_t *ugd = (CstUgData_t *)data;
110         const char *number = elm_entry_entry_get(ugd->dg_entry);
111         Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(ugd->dg_entry);
112
113         if (imf_context) {
114                 ecore_imf_context_input_panel_event_callback_del(imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _cst_prefix_dialling_input_panel_event_callback);
115                 ecore_imf_context_input_panel_enabled_set(imf_context, EINA_FALSE);
116         }
117
118         DBG("number : %s ", number);
119         if (0 == strlen(number)) {
120                 if (0 == strlen(_cst_get_prefix_dialling_list(CST_ITEM_1))) {
121                         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, EINA_FALSE);
122                 }
123                 /*Evas_Object *error;
124
125                 DBG("No new number");
126                 error = _cst_create_error_popup(ugd->nf,
127                         CST_ERROR_ENTER_NUMBER);
128                 ugd->popup = error;
129                 evas_object_show(error);
130                 return;*/
131         } else {
132                 _cst_set_prefix_dialling_list(CST_ITEM_1, (char *)number);
133         }
134
135         keypad_enabled = EINA_FALSE;
136
137         evas_object_smart_callback_del(obj, "clicked",
138                                                                    __cst_click_prefix_dial_save);
139
140         evas_object_smart_callback_del(ugd->dg_entry, "changed", _cst_call_prefix_dialling_entry_changed_cb);
141         evas_object_smart_callback_del(ugd->dg_entry, "preedit,changed", _cst_call_prefix_dialling_entry_changed_cb);
142
143         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, EINA_TRUE);
144
145 /*      ecore_timer_add(CST_NAVIFRAME_ITEM_POP_TIMER, _cst_naviframe_item_pop_cb, ugd);
146 */
147         _cst_naviframe_item_pop_cb(ugd);
148 }
149
150 static void __cst_click_prefix_dial_cancel(void *data,
151                 Evas_Object *obj,
152                 void *event_info)
153 {
154         ENTER(__cst_click_prefix_dial_cancel);
155         ret_if(!data);
156
157         CstUgData_t *ugd = (CstUgData_t *)data;
158         Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(ugd->dg_entry);
159
160         if (imf_context) {
161                 ecore_imf_context_input_panel_event_callback_del(imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _cst_prefix_dialling_input_panel_event_callback);
162                 ecore_imf_context_input_panel_enabled_set(imf_context, EINA_FALSE);
163         }
164
165         keypad_enabled = EINA_FALSE;
166
167         evas_object_smart_callback_del(obj, "clicked",
168                                                                    __cst_click_prefix_dial_cancel);
169
170         evas_object_smart_callback_del(ugd->dg_entry, "changed", _cst_call_prefix_dialling_entry_changed_cb);
171         evas_object_smart_callback_del(ugd->dg_entry, "preedit,changed", _cst_call_prefix_dialling_entry_changed_cb);
172
173 /*      ecore_timer_add(CST_NAVIFRAME_ITEM_POP_TIMER, _cst_naviframe_item_pop_cb, ugd);
174 */
175         _cst_naviframe_item_pop_cb(ugd);
176 }
177
178 static void __cst_create_prefix_dialling_ime(Evas_Object *parent, void *data)
179 {
180         ENTER(__cst_create_prefix_dialling_ime);
181         ret_if(!data);
182         CstUgData_t *ugd = (CstUgData_t *)data;
183         Evas_Object *back_btn = NULL;
184         Elm_Object_Item *navi_it;
185
186         ugd->popup = NULL;
187         prefixdialling_gl = _cst_create_prefix_dialling_ime(ugd->nf, NULL, ugd);
188         evas_object_show(prefixdialling_gl);
189
190         _cst_remove_naviframe(ugd->nf);
191
192         navi_it = elm_naviframe_item_push(ugd->nf, T_(CST_STR_AUTO_AREA_CODE),
193                                                                           NULL, NULL, prefixdialling_gl, NULL);
194
195         back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
196         evas_object_smart_callback_add(back_btn, "clicked", __cst_on_click_sound_eq_back_button, ugd);
197
198         LEAVE();
199 }
200
201 void _cst_on_click_prefix_dialling(void *data, Evas *evas, Evas_Object *obj, void *event_info)
202 {
203         ENTER(_cst_on_click_prefix_dialling);
204         ret_if(NULL == data);
205         CstUgData_t *ugd = (CstUgData_t *)data;
206         __cst_create_prefix_dialling_ime(ugd->nf, ugd);
207 }
208
209 void _cst_prefix_dialling_input_panel_event_callback(void *data, Ecore_IMF_Context *imf_context, int value)
210 {
211         ENTER(_cst_prefix_dialling_input_panel_event_callback);
212         ret_if(!data);
213         CstUgData_t *ugd = (CstUgData_t *)data;
214         Evas_Object *btn;
215         const char *entry_input = NULL;
216
217         Elm_Object_Item *top_it = elm_naviframe_top_item_get(ugd->nf);
218
219         if (value == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW) {
220                 return;
221         }
222
223         if (EINA_FALSE == keypad_enabled) {
224                 DBG("keypad_enabled = %d", keypad_enabled);
225                 keypad_enabled = EINA_TRUE;
226
227                 if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
228                         return;
229                 }
230         }
231
232         entry_input = elm_entry_entry_get(ugd->dg_entry);
233         if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
234
235                 DBG("ECORE_IMF_INPUT_PANEL_STATE_SHOW");
236
237                 elm_object_item_part_content_set(top_it, "toolbar_button1", NULL);
238                 elm_object_item_part_content_set(top_it, "toolbar_button2", NULL);
239
240                 btn = _cst_create_title_btn(ugd->nf, (char *)T_(CST_STR_CANCEL),
241                                                                         __cst_click_prefix_dial_cancel, (void *)ugd);
242                 elm_object_item_part_content_set(top_it, "title_right_btn", btn);
243
244                 btn = _cst_create_title_btn(ugd->nf, (char *)T_(CST_STR_SAVE),
245                                                                         __cst_click_prefix_dial_save, (void *)ugd);
246                 elm_object_item_part_content_set(top_it, "title_left_btn", btn);
247
248                 if (entry_input && strlen(entry_input) > 0) {
249                         elm_object_disabled_set(btn, EINA_FALSE);
250                 } else {
251                         elm_object_disabled_set(btn, EINA_TRUE);
252                 }
253         } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
254                 DBG("ECORE_IMF_INPUT_PANEL_STATE_HIDE");
255                 elm_object_item_part_content_set(top_it, "title_right_btn", NULL);
256                 elm_object_item_part_content_set(top_it, "title_left_btn", NULL);
257                 _cst_create_navi_control_bar(ugd->nf,
258                                                                                         (char *)T_(CST_STR_SAVE), NULL,
259                                                                                         __cst_click_prefix_dial_save,
260                                                                                         (char *)T_(CST_STR_CANCEL), NULL,
261                                                                                         __cst_click_prefix_dial_cancel,
262                                                                                         (void *)ugd, top_it,
263                                                                                         ec_item);
264
265                 if (entry_input && strlen(entry_input) > 0) {
266                         elm_object_disabled_set(ec_item[0], EINA_FALSE);
267                 } else {
268                         elm_object_disabled_set(ec_item[0], EINA_TRUE);
269                 }
270         }
271 }
272
273 void _cst_call_prefix_dialling_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
274 {
275         ENTER(_cst_call_prefix_dialling_entry_changed_cb);
276         ret_if(!data);
277         CstUgData_t *ugd = (CstUgData_t *)data;
278         Evas_Object *btn = NULL;
279         const char *entry_input = NULL;
280
281         Elm_Object_Item *top_it = elm_naviframe_top_item_get(ugd->nf);
282         ret_if(!top_it);
283
284         entry_input = elm_entry_entry_get(ugd->dg_entry);
285         if ((btn = elm_object_item_part_content_get(top_it, "title_left_btn")) != NULL) {
286                 if (entry_input && strlen(entry_input) > 0) {
287                         elm_object_disabled_set(btn, EINA_FALSE);
288                 } else {
289                         elm_object_disabled_set(btn, EINA_TRUE);
290                 }
291         } else {
292                 if (entry_input && strlen(entry_input) > 0) {
293                         elm_object_disabled_set(ec_item[0], EINA_FALSE);
294                 } else {
295                         elm_object_disabled_set(ec_item[0], EINA_TRUE);
296                 }
297         }
298 }
299
300 void _cst_destroy_prefix_dialling(void)
301 {
302         ENTER(_cst_destroy_prefix_dialling);
303
304         if (prefixdialling_gl != NULL) {
305                 elm_genlist_clear(prefixdialling_gl);
306                 evas_object_del(prefixdialling_gl);
307                 prefixdialling_gl = NULL;
308         }
309 }
310
311 #endif  /* _CALL_SET_AUTO_AREA_CODE_SUPPORT */