2012/08/21: tizen 2.0 beta
[apps/home/call-setting.git] / src / cst-prefix-dial-ime.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
20 #include "cst-common.h"
21 #include "cst-common-string.h"
22 #include "cst-widget.h"
23 #include "cst-util.h"
24 #include "cst-prefix-dial.h"
25
26 static Elm_Genlist_Item_Class *itc_ime = NULL;
27 static Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
28
29 static void __cst_on_click_prefix_dialling_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info);
30 static CstGlItemDisplayInfo_t list_dep1_prefix_dialling[] = {
31         {1, CST_STR_AUTO_AREA_CODE, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF, __cst_on_click_prefix_dialling_onoff},
32         {1, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
33 };
34
35 static void __cst_on_click_prefix_dialling_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info)
36 {
37         ENTER(__cst_on_click_prefix_dialling_onoff);
38         ret_if(NULL == data);
39         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
40         CstUgData_t *ugd = item_data->ugd;
41         Eina_Bool check_state = elm_check_state_get(item_data->eo_check);
42         if (CST_STR_AUTO_AREA_CODE == list_dep1_prefix_dialling[item_data->index].str_id) {
43                 _cst_vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, !check_state);
44                 if (ugd->prefix_gl_list_item != NULL) {
45                         Ecore_IMF_Context *imf_context;
46                         imf_context = elm_entry_imf_context_get(ugd->dg_entry);
47                         elm_object_item_disabled_set(ugd->prefix_gl_list_item, check_state);
48                         ecore_imf_context_input_panel_enabled_set(imf_context, !(check_state));
49                 }
50
51         }
52         elm_genlist_item_update(item_data->gl_item);
53 }
54
55 static void __cst_on_changed_enable_prefix_dialling_check(void *data, Evas_Object *obj, void *event_info)
56 {
57         ENTER(__cst_on_changed_enable_prefix_dialling_check);
58         ret_if(NULL == data);
59         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
60         CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
61         Eina_Bool check_state;
62         check_state = elm_check_state_get(obj);
63
64         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, check_state);
65         if (ugd->prefix_gl_list_item != NULL) {
66                 Ecore_IMF_Context *imf_context;
67                 imf_context = elm_entry_imf_context_get(ugd->dg_entry);
68                 elm_object_item_disabled_set(ugd->prefix_gl_list_item, !(check_state));
69                 ecore_imf_context_input_panel_enabled_set(imf_context, check_state);
70         }
71 }
72
73 static Evas_Object *__cst_gl_icon_get_prefix_dailling(void *data, Evas_Object *obj, const char *part)
74 {
75         ENTER(__cst_gl_icon_get_prefix_dailling);
76         retv_if(NULL == data, NULL);
77         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
78
79         if (!strcmp(part, "elm.icon")) {
80                 if (CST_STR_AUTO_AREA_CODE == list_dep1_prefix_dialling[item_data->index].str_id) {
81                         int value = 0;
82                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, &value);
83                         item_data->eo_check = _cst_create_onoff_button(obj, value,
84                                 __cst_on_changed_enable_prefix_dialling_check, item_data);
85                 }
86                 return item_data->eo_check;
87         }
88         return NULL;
89 }
90
91 static char *__cst_gl_label_get_prefix_dailling(void *data, Evas_Object *obj, const char *part)
92 {
93         retv_if(NULL == data, NULL);
94         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
95
96         if (!strcmp(part, "elm.text") || !strcmp(part, "elm.text.1")) {
97                 if (list_dep1_prefix_dialling[item_data->index].str_id != -1)
98                         return strdup(T_(list_dep1_prefix_dialling[item_data->index].str_id));
99         }
100         return NULL;
101 }
102
103 static void __cst_gl_del_prefix_dailling(void *data, Evas_Object *obj)
104 {
105         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
106         if (item_data) {
107                 if (item_data->label)
108                         free(item_data->label);
109                 free(item_data);
110         }
111
112         return;
113 }
114
115 static void __cst_gl_sel_prefix_dailling(void *data, Evas_Object *obj, void *event_info)
116 {
117         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
118         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
119         CstGlItemData_t *item_data = (CstGlItemData_t *)elm_object_item_data_get(item);
120
121         if (list_dep1_prefix_dialling[item_data->index].func)
122                 list_dep1_prefix_dialling[item_data->index].func(item_data, NULL, obj, event_info);
123         return;
124 }
125
126 static Evas_Object *__cst_gl_icon_get_prefix_dialling_ime(void *data, Evas_Object *obj, const char *part)
127 {
128         retv_if(data == NULL, NULL);
129         CstUgData_t *ugd = (CstUgData_t *)data;
130
131         if (!strcmp(part, "elm.icon")) {
132                 char *buf = _cst_get_prefix_dialling_list(CST_ITEM_1);
133                 return _cst_create_ime_editfield(ugd, obj, CST_IME_PREFIX_DIAL, buf);
134         }
135
136         return NULL;
137 }
138
139 static Evas_Object *__cst_create_prefix_dialling_ime_genlist(CstUgData_t *ugd)
140 {
141         ENTER(__cst_create_prefix_dialling_ime_genlist);
142         Evas_Object *genlist;
143
144         genlist = elm_genlist_add(ugd->nf);
145         elm_object_style_set(genlist, "dialogue");
146
147         _cst_create_genlist_separator(genlist, EINA_FALSE);
148         CstGlItemData_t *item_data = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
149         retv_if(item_data == NULL, NULL);
150         item_data->index = 0;
151         item_data->ugd = ugd;
152
153         item_data->gl_item = elm_genlist_item_append(genlist, itc_1text_1icon,
154                                         (void *)item_data, NULL, list_dep1_prefix_dialling[0].flags,
155                                         __cst_gl_sel_prefix_dailling, ugd);
156
157         ugd->prefix_gl_list_item = elm_genlist_item_append(genlist, itc_ime,
158                 (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE,
159                 NULL, NULL);
160
161         int value = 0;
162         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, &value);
163         elm_object_item_disabled_set(ugd->prefix_gl_list_item, !(value));
164         return genlist;
165 }
166
167 static void __cst_set_genlist_item_styles(void)
168 {
169         ENTER(__cst_set_genlist_item_styles);
170
171         if (!itc_ime)
172                 itc_ime = elm_genlist_item_class_new();
173         if (!itc_1text_1icon)
174                 itc_1text_1icon = elm_genlist_item_class_new();
175
176         itc_ime->item_style = "1icon";
177         itc_ime->func.text_get = NULL;
178         itc_ime->func.content_get = __cst_gl_icon_get_prefix_dialling_ime;
179         itc_ime->func.state_get = NULL;
180         itc_ime->func.del = NULL;
181
182         itc_1text_1icon->item_style = "dialogue/1text.1icon";
183         itc_1text_1icon->func.text_get = __cst_gl_label_get_prefix_dailling;
184         itc_1text_1icon->func.content_get = __cst_gl_icon_get_prefix_dailling;
185         itc_1text_1icon->func.state_get = NULL;
186         itc_1text_1icon->func.del = __cst_gl_del_prefix_dailling;
187 }
188
189 Evas_Object *_cst_create_prefix_dialling_ime(Evas_Object *parent, char *edit_string, void *data)
190 {
191         ENTER(_cst_create_prefix_dialling_ime);
192         retv_if(NULL == data, NULL);
193         CstUgData_t *ugd = (CstUgData_t *)data;
194
195         __cst_set_genlist_item_styles();
196         Evas_Object *genlist = __cst_create_prefix_dialling_ime_genlist(ugd);
197         return genlist;
198 }
199