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