ed9cc7a495b59ec7d3a58d7d1bf94e11a308221a
[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                 return strdup(T_(list_call_status_tone[item_data->index].str_id));
85         } else
86                 return NULL;
87 }
88
89 static Evas_Object *__cst_gl_icon_get_call_status_tone(void *data, Evas_Object *obj, const char *part)
90 {
91         retv_if(NULL == data, NULL);
92         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
93
94         if (!strcmp(part, "elm.icon")) {
95                 int value = 0;
96                 if (CST_STR_CALL_CONNECT_TONE == list_call_status_tone[item_data->index].str_id) {
97                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &value);
98                         item_data->eo_check = _cst_create_onoff_button(obj, value,
99                                 __cst_changed_call_connect_tone, item_data);
100                 } else if (CST_STR_MINUTE_REMINDER == list_call_status_tone[item_data->index].str_id) {
101                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &value);
102                         item_data->eo_check = _cst_create_onoff_button(obj, value,
103                                 __cst_changed_minute_minder, item_data);
104                 } else if (CST_STR_CALL_END_TONE == list_call_status_tone[item_data->index].str_id) {
105                         _cst_vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &value);
106                         item_data->eo_check = _cst_create_onoff_button(obj, value,
107                                 __cst_changed_call_end_tone, item_data);
108                 }
109                 return item_data->eo_check;
110         }
111         return NULL;
112 }
113
114 static void __cst_gl_del_call_status_tone(void *data, Evas_Object *obj)
115 {
116         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
117         if(item_data)
118                 free(item_data);
119         return;
120 }
121
122 static void __cst_gl_sel_call_status_tone(void *data, Evas_Object *obj, void *event_info)
123 {
124         ENTER(__cst_gl_sel_call_status_tone);
125         ret_if(data == NULL);
126         CstGlItemData_t *item_data = (CstGlItemData_t *)data;
127         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
128
129         if (list_call_status_tone[item_data->index].func)
130                 list_call_status_tone[item_data->index].func((void *)item_data, NULL, obj, event_info);
131         return;
132 }
133
134 static void __cst_set_gl_item_styles_call_status_tone(void)
135 {
136         ENTER(__cst_set_gl_item_styles_call_status_tone);
137
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         _cst_create_genlist_seperator(genlist, EINA_FALSE);
170                 
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                 ret_if(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;
192                 }
193                 item_data->gl_item = item;
194         }
195
196         return genlist;
197 }
198
199 static void __cst_create_call_status_tone(Evas_Object *parent, void *data)
200 {
201         ENTER(__cst_create_call_status_tone);
202         Evas_Object *genlist;
203         CstUgData_t *ugd = data;
204         ret_if(ugd == NULL);
205
206         __cst_set_gl_item_styles_call_status_tone();
207         genlist = __cst_create_call_status_tone_genlist(ugd);
208
209         elm_naviframe_item_push(ugd->nf, T_(CST_STR_CALL_STATUS_TONES),
210                 NULL, NULL, genlist, NULL);
211 }
212
213 void _cst_on_click_call_status_tone(void *data, Evas *evas, Evas_Object *obj, void *event_info)
214 {
215         ENTER(_cst_on_click_call_status_tone);
216         ret_if(NULL == data);
217         CstUgData_t *ugd = (CstUgData_t *)data;
218         __cst_create_call_status_tone(ugd->nf, ugd);
219 }