Tizen 2.1 base
[apps/home/call-setting.git] / src / cst-status-tone.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 #include <Elementary.h>
18 #include <vconf.h>
19 #include "cst-common.h"
20 #include "cst-common-string.h"
21 #include "cst-status-tone.h"
22 #include "cst-widget.h"
23 #include "cst-util.h"
24
25 static void __cst_set_gl_item_styles_call_status_tone(void);
26 static void __cst_destroy_genlist_item_styles(void);
27 static void __cst_click_call_status_tone_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info);
28 static void __cst_on_click_call_status_tone_back_button(void *data, Evas_Object *obj, void *event_info);
29
30 static Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
31 static Elm_Genlist_Item_Class *itc_help = NULL;
32 static Evas_Object *callstatustone_gl = NULL;
33
34 static CstGlItemDisplayInfo_t list_call_status_tone[] = {
35         {1, CST_STR_CALL_CONNECT_TONE, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF, __cst_click_call_status_tone_onoff},
36         {1, CST_STR_THERE_WILL_BE_WEHN_LINE_IS_CONNECTED, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_HELP_TEXT, NULL},
37         {1, CST_STR_MINUTE_REMINDER, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF, __cst_click_call_status_tone_onoff},
38         {1, CST_STR_THERE_WILL_BE_EVERY_A_MINUTE, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_HELP_TEXT, NULL},
39         {1, CST_STR_CALL_END_TONE, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_1TEXT_ONOFF, __cst_click_call_status_tone_onoff},
40         {1, CST_STR_THERE_WILL_BE_WEHN_LINE_IS_DISCONNECTED, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_HELP_TEXT, NULL},
41         {1, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
42 };
43
44 static void __cst_destroy_genlist_item_styles(void)
45 {
46         ENTER(__cst_destroy_genlist_item_styles);
47
48         if (itc_1text_1icon) {
49                 elm_genlist_item_class_free(itc_1text_1icon);
50                 itc_1text_1icon = NULL;
51         }
52         if (itc_help) {
53                 elm_genlist_item_class_free(itc_help);
54                 itc_help = NULL;
55         }
56 }
57
58 static void __cst_on_click_call_status_tone_back_button(void *data, Evas_Object *obj, void *event_info)
59 {
60         ENTER(__cst_on_click_call_status_tone_back_button);
61
62         _cst_destroy_call_status_tone();
63 }
64
65 static void __cst_click_call_status_tone_onoff(void *data, Evas *evas, Evas_Object *obj, void *event_info)
66 {
67         ret_if(NULL == data);
68         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
69         Eina_Bool check_state = elm_check_state_get(item_data->eo_check);
70
71         if (CST_STR_CALL_CONNECT_TONE == list_call_status_tone[item_data->index].str_id) {
72                 _cst_vconf_set_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, !check_state);
73         } else if (CST_STR_MINUTE_REMINDER == list_call_status_tone[item_data->index].str_id) {
74                 _cst_vconf_set_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, !check_state);
75         } else if (CST_STR_CALL_END_TONE == list_call_status_tone[item_data->index].str_id) {
76                 _cst_vconf_set_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, !check_state);
77         }
78         elm_genlist_item_update(item_data->gl_item);
79 }
80
81 static void __cst_changed_call_connect_tone(void *data, Evas_Object *obj, void *event_info)
82 {
83         Eina_Bool check_state;
84         check_state = elm_check_state_get(obj);
85         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, check_state);
86 }
87
88 static void __cst_changed_minute_minder(void *data, Evas_Object *obj, void *event_info)
89 {
90         Eina_Bool check_state;
91         check_state = elm_check_state_get(obj);
92
93         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, check_state);
94 }
95
96 static void __cst_changed_call_end_tone(void *data, Evas_Object *obj, void *event_info)
97 {
98         Eina_Bool check_state;
99         check_state = elm_check_state_get(obj);
100
101         _cst_vconf_set_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, check_state);
102 }
103
104 static char *__cst_gl_label_get_call_status_tone(void *data, Evas_Object *obj, const char *part)
105 {
106         retv_if(NULL == data, NULL);
107         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
108
109         if (!strcmp(part, "elm.text") ||
110                         !strcmp(part, "elm.text.1") ||
111                         !strcmp(part, "elm.text.2")) {
112                 if (list_call_status_tone[item_data->index].str_id != -1) {
113                         return strdup(T_(list_call_status_tone[item_data->index].str_id));
114                 }
115         }
116         return NULL;
117 }
118
119 static Evas_Object *__cst_gl_icon_get_call_status_tone(void *data, Evas_Object *obj, const char *part)
120 {
121         retv_if(NULL == data, NULL);
122         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
123
124         if (!strcmp(part, "elm.icon")) {
125                 int value = 0;
126                 if (CST_STR_CALL_CONNECT_TONE == list_call_status_tone[item_data->index].str_id) {
127                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &value);
128                         item_data->eo_check = _cst_create_onoff_button(obj, value,
129                                                                   __cst_changed_call_connect_tone, item_data);
130                 } else if (CST_STR_MINUTE_REMINDER == list_call_status_tone[item_data->index].str_id) {
131                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &value);
132                         item_data->eo_check = _cst_create_onoff_button(obj, value,
133                                                                   __cst_changed_minute_minder, item_data);
134                 } else if (CST_STR_CALL_END_TONE == list_call_status_tone[item_data->index].str_id) {
135                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &value);
136                         item_data->eo_check = _cst_create_onoff_button(obj, value,
137                                                                   __cst_changed_call_end_tone, item_data);
138                 }
139                 return item_data->eo_check;
140         }
141         return NULL;
142 }
143
144 static void __cst_gl_del_call_status_tone(void *data, Evas_Object *obj)
145 {
146         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
147         if (item_data) {
148                 free(item_data);
149         }
150         return;
151 }
152
153 static void __cst_gl_sel_call_status_tone(void *data, Evas_Object *obj, void *event_info)
154 {
155         ENTER(__cst_gl_sel_call_status_tone);
156         ret_if(data == NULL);
157         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
158         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
159
160         if (list_call_status_tone[item_data->index].func) {
161                 list_call_status_tone[item_data->index].func((void *)item_data, NULL, obj, event_info);
162         }
163         return;
164 }
165
166 static void __cst_set_gl_item_styles_call_status_tone(void)
167 {
168         ENTER(__cst_set_gl_item_styles_call_status_tone);
169         if (!itc_1text_1icon) {
170                 itc_1text_1icon = elm_genlist_item_class_new();
171         }
172         if (!itc_help) {
173                 itc_help = elm_genlist_item_class_new();
174         }
175
176         itc_1text_1icon->item_style = "dialogue/1text.1icon";
177         itc_1text_1icon->func.text_get = __cst_gl_label_get_call_status_tone;
178         itc_1text_1icon->func.content_get = __cst_gl_icon_get_call_status_tone;
179         itc_1text_1icon->func.state_get = NULL;
180         itc_1text_1icon->func.del = __cst_gl_del_call_status_tone;
181
182         itc_help->item_style = "multiline/1text";
183         itc_help->func.text_get = __cst_gl_label_get_call_status_tone;
184         itc_help->func.content_get = NULL;
185         itc_help->func.state_get = NULL;
186         itc_help->func.del = __cst_gl_del_call_status_tone;
187 }
188
189 static Evas_Object *__cst_create_call_status_tone_genlist(void *data)
190 {
191         ENTER(__cst_create_call_status_tone_genlist);
192         retv_if(NULL == data, NULL);
193         CstUgData_t *ugd = (CstUgData_t *)data;
194         int index = 0;
195         Evas_Object *genlist;
196         Elm_Object_Item *item;
197         CstGlItemData_t *item_data;
198
199         genlist = elm_genlist_add(ugd->nf);
200
201         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
202         _cst_create_genlist_separator(genlist, EINA_FALSE);
203         for (index = 0; list_call_status_tone[index].style != CST_GL_ITEM_NONE; ++index) {
204                 item_data = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
205                 retv_if(NULL == item_data, NULL);
206
207                 item_data->index = index;
208                 item_data->ugd = ugd;
209                 if (list_call_status_tone[index].style == CST_GL_ITEM_1TEXT_ONOFF) {
210                         _cst_create_genlist_underline(genlist);
211                         item = elm_genlist_item_append(genlist, itc_1text_1icon,
212                                                                                    (void *)item_data, NULL, list_call_status_tone[index].flags,
213                                                                                    __cst_gl_sel_call_status_tone, item_data);
214                 } else if (list_call_status_tone[index].style == CST_GL_ITEM_HELP_TEXT) {
215                         item = elm_genlist_item_append(genlist, itc_help,
216                                                                                    (void *)item_data, NULL, list_call_status_tone[index].flags,
217                                                                                    NULL, NULL);
218                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
219                         _cst_create_genlist_separator_no_line(genlist);
220                 } else {
221                         DBG("No style");
222                         free(item_data);
223                         item_data = NULL;
224                         return NULL;
225                 }
226                 item_data->gl_item = item;
227         }
228         _cst_create_genlist_separator_no_line(genlist);
229
230         return genlist;
231 }
232
233 static void __cst_create_call_status_tone(Evas_Object *parent, void *data)
234 {
235         ENTER(__cst_create_call_status_tone);
236         CstUgData_t *ugd = data;
237         Evas_Object *back_btn = NULL;
238         Elm_Object_Item *navi_it;
239         ret_if(ugd == NULL);
240
241         __cst_set_gl_item_styles_call_status_tone();
242         callstatustone_gl = __cst_create_call_status_tone_genlist(ugd);
243
244         navi_it = elm_naviframe_item_push(ugd->nf, T_(CST_STR_CALL_STATUS_TONES), NULL, NULL, callstatustone_gl, NULL);
245
246         back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
247         evas_object_smart_callback_add(back_btn, "clicked", __cst_on_click_call_status_tone_back_button, ugd);
248 }
249
250 void _cst_on_click_call_status_tone(void *data, Evas *evas, Evas_Object *obj, void *event_info)
251 {
252         ENTER(_cst_on_click_call_status_tone);
253         ret_if(NULL == data);
254         CstUgData_t *ugd = (CstUgData_t *)data;
255         __cst_create_call_status_tone(ugd->nf, ugd);
256 }
257
258 void _cst_destroy_call_status_tone(void)
259 {
260         ENTER(_cst_destroy_call_status_tone);
261
262         __cst_destroy_genlist_item_styles();
263
264         if (callstatustone_gl != NULL) {
265                 elm_genlist_clear(callstatustone_gl);
266                 evas_object_del(callstatustone_gl);
267                 callstatustone_gl = NULL;
268         }
269 }
270