2012/08/21: tizen 2.0 beta
[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://www.tizenopensource.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 #include <vconf.h>
19 #include "cst-common.h"
20 #include "cst-common-string.h"
21 #include "cst-widget.h"
22 #include "cst-call-setting.h"
23
24 #include "cst-prefix-dial.h"
25 #include "cst-prefix-dial-ime.h"
26 #include "cst-delete-list.h"
27 #include "cst-util.h"
28
29  void _cst_set_prefix_dialling_list(int index, char *number)
30 {
31         ENTER(_cst_set_prefix_dialling_list);
32
33         ret_if(number == NULL);
34         switch (index) {
35         case CST_ITEM_1:
36                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR,
37                         number);
38                 break;
39         case CST_ITEM_2:
40                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR,
41                         number);
42                 break;
43         case CST_ITEM_3:
44                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR,
45                         number);
46                 break;
47         case CST_ITEM_4:
48                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR,
49                         number);
50                 break;
51         case CST_ITEM_5:
52                 _cst_vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR,
53                         number);
54                 break;
55         default:
56                 DBG("Error set prefix dialling list");
57                 break;
58         }
59 }
60
61 char *_cst_get_prefix_dialling_list(int index)
62 {
63         ENTER(_cst_get_prefix_dialling_list);
64         char *number = NULL;
65
66         switch (index) {
67         case CST_ITEM_1:
68                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR);
69                 break;
70         case CST_ITEM_2:
71                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR);
72                 break;
73         case CST_ITEM_3:
74                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR);
75                 break;
76         case CST_ITEM_4:
77                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR);
78                 break;
79         case CST_ITEM_5:
80                 number = _cst_vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR);
81                 break;
82         }
83         retv_if(NULL == number, NULL);
84         return number;
85 }
86
87 static void __cst_click_prefix_dial_save(void *data,
88                 Evas_Object *obj,
89                 void *event_info)
90 {
91         ENTER(__cst_click_prefix_dial_save);
92         ret_if(!data);
93
94         CstUgData_t *ugd = (CstUgData_t *)data;
95         const char *number = elm_entry_entry_get(ugd->dg_entry);
96         Ecore_IMF_Context *imf_context = elm_entry_imf_context_get(ugd->dg_entry);
97
98         if (imf_context) {
99                 ecore_imf_context_input_panel_event_callback_del (imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _cst_prefix_dialling_input_panel_event_callback);
100         }
101
102         DBG("number : %s ", number);
103         if (0 == strlen(number)) {
104                 if (0 == strlen(_cst_get_prefix_dialling_list(CST_ITEM_1))) {
105                         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, EINA_FALSE);
106                 }
107         } else {
108                 _cst_set_prefix_dialling_list(CST_ITEM_1, (char *)number);
109         }
110         elm_naviframe_item_pop(ugd->nf);
111 }
112
113 static void __cst_create_prefix_dialling_ime(Evas_Object *parent, void *data)
114 {
115         ENTER(__cst_create_prefix_dialling_ime);
116         ret_if(!data);
117         CstUgData_t *ugd = (CstUgData_t *)data;
118         Evas_Object *eo;
119         Elm_Object_Item *navi_it;
120         Evas_Object *btn;
121
122         ugd->popup = NULL;
123         eo = _cst_create_prefix_dialling_ime(ugd->nf, NULL, ugd);
124         evas_object_show(eo);
125
126         _cst_remove_naviframe(ugd->nf);
127
128         btn = elm_button_add(ugd->nf);
129         navi_it = elm_naviframe_item_push(ugd->nf, T_(CST_STR_AUTO_AREA_CODE),
130                 btn, NULL, eo, "1line");
131         elm_object_style_set(btn, "naviframe/back_btn/default");
132
133         evas_object_smart_callback_add(btn, "clicked",
134                 __cst_click_prefix_dial_save, ugd);
135 }
136
137 void _cst_on_click_prefix_dialling(void *data, Evas *evas, Evas_Object *obj, void *event_info)
138 {
139         ENTER(_cst_on_click_prefix_dialling);
140         ret_if(NULL == data);
141         CstUgData_t *ugd = (CstUgData_t *)data;
142         __cst_create_prefix_dialling_ime(ugd->nf, ugd);
143 }
144
145 void _cst_prefix_dialling_input_panel_event_callback(void *data, Ecore_IMF_Context *imf_context, int value)
146 {
147         ENTER(_cst_prefix_dialling_input_panel_event_callback);
148         ret_if(!data);
149         CstUgData_t *ugd = (CstUgData_t *)data;
150
151         Elm_Object_Item *top_it = elm_naviframe_top_item_get(ugd->nf);
152
153         Evas_Object *btn = elm_object_item_part_content_get(top_it, "prev_btn");
154         evas_object_del(btn);
155         btn = elm_button_add(ugd->nf);
156         elm_object_style_set(btn, "naviframe/back_btn/default");
157         evas_object_smart_callback_add(btn, "clicked",
158                 __cst_click_prefix_dial_save, ugd);
159
160         if(value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
161
162                 DBG("ECORE_IMF_INPUT_PANEL_STATE_SHOW");
163                 elm_object_item_part_content_set(top_it, "title_right_btn", btn);
164
165         } else if(value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
166                 DBG("ECORE_IMF_INPUT_PANEL_STATE_HIDE");
167                 elm_object_item_part_content_set(top_it, "title_right_btn", NULL);
168                 elm_object_item_part_content_set(top_it, "prev_btn", btn);
169         }
170 }
171