tizen 2.3 release
[apps/home/settings.git] / setting-ledindicator / src / setting-ledindicator-main.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-ledindicator-main.h>
22
23 static void setting_ledindicator_main_mouse_up_Gendial_list_cb(void *data, Evas_Object * obj, void *event_info);
24 static Eina_Bool setting_ledindicator_main_click_softkey_back_cb(void *data, Elm_Object_Item *item);
25
26 static int setting_ledindicator_main_create(void *cb);
27 static int setting_ledindicator_main_destroy(void *cb);
28 static int setting_ledindicator_main_update(void *cb);
29 static int setting_ledindicator_main_cleanup(void *cb);
30 setting_view setting_view_ledindicator_main = {
31         .create = setting_ledindicator_main_create,
32         .destroy = setting_ledindicator_main_destroy,
33         .update = setting_ledindicator_main_update,
34         .cleanup = setting_ledindicator_main_cleanup,
35 };
36
37 static void __setting_ledindicator_main_vconf_change_cb(keynode_t *key, void *data)
38 {
39         SETTING_TRACE_BEGIN;
40         setting_retm_if(NULL == key, "key is NULL");
41         setting_retm_if(NULL == data, "data is NULL");
42         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *)data;
43
44         int status = vconf_keynode_get_bool(key);
45         char *vconf_name = vconf_keynode_get_name(key);
46         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING)) {
47
48                 if (ad->charging) {
49                         setting_update_gl_item_chk_status(ad->charging, status);
50                 }
51         }else if(!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT)){
52                 if(ad->low_batt){
53                         setting_update_gl_item_chk_status(ad->low_batt,status);
54                 }
55         }else if(!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS)){
56                 if(ad->notifications){
57                         setting_update_gl_item_chk_status(ad->notifications, status);
58                 }
59                 if(ad->voice_rec && ad->voice_rec->item) {
60                         if(status){
61                                 setting_enable_genlist_item(ad->voice_rec->item);
62                         }else{
63                                 setting_disable_genlist_item(ad->voice_rec->item);
64                         }
65                 }
66         }else if(!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC)){
67                 if(ad->voice_rec){
68                         setting_update_gl_item_chk_status(ad->voice_rec, status);
69                 }
70         }else {
71                 SETTING_TRACE_ERROR("vconf_name is error");
72         }
73 }
74
75 /* ***************************************************
76 **
77 ** basic func
78 **
79 ** **************************************************/
80 static int setting_ledindicator_main_create(void *cb)
81 {
82         SETTING_TRACE_BEGIN;
83         //error check
84         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
85
86         int value;                      /* vconf result */
87         int ret = 0;
88         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) cb;
89
90         Evas_Object *scroller = NULL;
91         ad->ly_main =
92             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
93                                                    ad->win_get,
94                                                    "IDS_ST_BODY_LED_INDICATOR", _("IDS_COM_BODY_BACK"),
95                                                    NULL,
96                                                    (setting_call_back_func)setting_ledindicator_main_click_softkey_back_cb,
97                                                    NULL, ad, &scroller,
98                                                    &(ad->navi_bar));
99
100         Elm_Object_Item *item = NULL;;
101         item =
102             elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
103                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
104         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
105         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING,__setting_ledindicator_main_vconf_change_cb, ad);
106         if (ret != 0) {
107                 SETTING_TRACE_ERROR("call vconf_notify_key_changed failed");
108         }
109         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT,__setting_ledindicator_main_vconf_change_cb, ad);
110         if (ret != 0) {
111                 SETTING_TRACE_ERROR("call vconf_notify_key_changed failed");
112         }
113         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS,__setting_ledindicator_main_vconf_change_cb, ad);
114         if (ret != 0) {
115                 SETTING_TRACE_ERROR("call vconf_notify_key_changed failed");
116         }
117         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC,__setting_ledindicator_main_vconf_change_cb, ad);
118         if (ret != 0) {
119                 SETTING_TRACE_ERROR("call vconf_notify_key_changed failed");
120         }
121
122         // charging - ON/OFF
123         ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING, &value);
124         if (ret != 0) {
125                 SETTING_TRACE_ERROR("get vconf failed");
126                 value = 1;
127         }
128         ad->charging =
129             setting_create_Gendial_field_def(scroller, &itc_1text_1icon,
130                                              setting_ledindicator_main_mouse_up_Gendial_list_cb,
131                                              ad, SWALLOW_Type_1TOGGLE, NULL,
132                                              NULL, value, KeyStr_Charging,
133                                              NULL, setting_ledindicator_main_chk_btn_cb);
134         if (ad->charging) {
135                 ad->charging->userdata = ad;
136         }
137
138         ADD_GL_HELP(scroller, KeyStr_Charging_Desc);
139
140         // Low battery - ON/OFF
141         ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT, &value);
142         if (ret != 0) {
143                 SETTING_TRACE_ERROR("get vconf failed");
144                 value = 1;
145         }
146         ad->low_batt =
147             setting_create_Gendial_field_def(scroller, &itc_1text_1icon,
148                                              setting_ledindicator_main_mouse_up_Gendial_list_cb,
149                                              ad, SWALLOW_Type_1TOGGLE, NULL,
150                                              NULL, value, KeyStr_LowBattery,
151                                              NULL, setting_ledindicator_main_chk_btn_cb);
152         if (ad->low_batt) {
153                 ad->low_batt->userdata = ad;
154         }
155
156         ADD_GL_HELP(scroller, KeyStr_LowBattery_Desc);
157
158         // Notifications - ON/OFF
159         ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS, &value);
160         if (ret != 0) {
161                 SETTING_TRACE_ERROR("get vconf failed");
162                 value = 1;
163         }
164         int noti_val = value;
165         ad->notifications =
166             setting_create_Gendial_field_def(scroller, &itc_1text_1icon,
167                                              setting_ledindicator_main_mouse_up_Gendial_list_cb,
168                                              ad, SWALLOW_Type_1TOGGLE, NULL,
169                                              NULL, value, KeyStr_Notifications,
170                                              NULL, setting_ledindicator_main_chk_btn_cb);
171         if (ad->notifications){
172                 ad->notifications->userdata = ad;
173         }
174
175         ADD_GL_HELP(scroller, KeyStr_Notifications_Desc);
176
177         // Voice recording - ON/OFF
178         ret = vconf_get_bool(VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC, &value);
179         if (ret != 0) {
180                 SETTING_TRACE_ERROR("get vconf failed");
181                 value = 1;
182         }
183         ad->voice_rec =
184             setting_create_Gendial_field_def(scroller, &itc_1text_1icon,
185                                              setting_ledindicator_main_mouse_up_Gendial_list_cb,
186                                              ad, SWALLOW_Type_1TOGGLE, NULL,
187                                              NULL, value, KeyStr_VoiceRecording,
188                                              NULL, setting_ledindicator_main_chk_btn_cb);
189         if (ad->voice_rec)
190         {
191                 ad->voice_rec->userdata = ad;
192                 if(!noti_val) {
193                         setting_disable_genlist_item(ad->voice_rec->item);
194                 }
195         }
196
197         ADD_GL_HELP(scroller, KeyStr_VoiceRecording_Desc);
198
199         setting_view_ledindicator_main.is_create = 1;
200
201         return SETTING_RETURN_SUCCESS;
202 }
203
204 static int setting_ledindicator_main_destroy(void *cb)
205 {
206         SETTING_TRACE_BEGIN;
207         //error check
208         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
209
210         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) cb;
211         int ret = 0;
212         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING,
213                         __setting_ledindicator_main_vconf_change_cb);
214         if (ret != 0) {
215                 SETTING_TRACE_ERROR("call vconf_ignore_key_changed failed");
216         }
217         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT,
218                         __setting_ledindicator_main_vconf_change_cb);
219         if (ret != 0) {
220                 SETTING_TRACE_ERROR("call vconf_ignore_key_changed failed");
221         }
222         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC,
223                         __setting_ledindicator_main_vconf_change_cb);
224         if (ret != 0) {
225                 SETTING_TRACE_ERROR("call vconf_ignore_key_changed failed");
226         }
227         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS,
228                         __setting_ledindicator_main_vconf_change_cb);
229         if (ret != 0) {
230                 SETTING_TRACE_ERROR("call vconf_ignore_key_changed failed");
231         }
232
233         if (ad->ly_main != NULL) {
234                 evas_object_del(ad->ly_main);
235                 //if(ad->back_dialData) FREE(ad->back_dialData);
236                 setting_view_ledindicator_main.is_create = 0;
237         }
238
239         return SETTING_RETURN_SUCCESS;
240 }
241
242 static int setting_ledindicator_main_update(void *cb)
243 {
244         SETTING_TRACE_BEGIN;
245         //error check
246         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
247
248         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) cb;
249
250         if (ad->ly_main != NULL) {
251                 evas_object_show(ad->ly_main);
252         }
253
254         return SETTING_RETURN_SUCCESS;
255 }
256
257 static int setting_ledindicator_main_cleanup(void *cb)
258 {
259         SETTING_TRACE_BEGIN;
260         //error check
261         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
262
263         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) cb;
264
265         if (ad->ly_main != NULL) {
266                 //      evas_object_hide(ad->ly_main);
267         }
268
269         return SETTING_RETURN_SUCCESS;
270 }
271
272 /* ***************************************************
273  **
274  ** general func
275  **
276  ** **************************************************/
277 static void __chk_btn_change_set(void *data, Setting_GenGroupItem_Data *list_item)
278 {
279         SETTING_TRACE_BEGIN;
280         setting_retm_if(!data || !list_item, "!data || !list_item");
281         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) data;
282         const char *vconf_key = NULL;
283
284         SETTING_TRACE("list_item->keyStr:%s, list_item->chk_status:%d", list_item->keyStr, list_item->chk_status);
285         if (!safeStrCmp(KeyStr_Charging, list_item->keyStr)) {
286                 vconf_key = VCONFKEY_SETAPPL_LED_INDICATOR_CHARGING;
287         } else if (!safeStrCmp(KeyStr_LowBattery, list_item->keyStr)) {
288                 vconf_key = VCONFKEY_SETAPPL_LED_INDICATOR_LOW_BATT;
289         } else if (!safeStrCmp(KeyStr_Notifications, list_item->keyStr)) {
290                 vconf_key = VCONFKEY_SETAPPL_LED_INDICATOR_NOTIFICATIONS;
291                 if(list_item->chk_status) {
292                         setting_enable_genlist_item(ad->voice_rec->item);
293                 }else {
294                         setting_disable_genlist_item(ad->voice_rec->item);
295                 }
296         } else if (!safeStrCmp(KeyStr_VoiceRecording, list_item->keyStr)) {
297                 vconf_key = VCONFKEY_SETAPPL_LED_INDICATOR_VOICE_REC;
298         } else {
299                 return;
300         }
301
302         int ret = vconf_set_bool(vconf_key, list_item->chk_status);
303         SETTING_TRACE("ret:%d", ret);
304 }
305
306 static void
307 setting_ledindicator_main_mouse_up_Gendial_list_cb(void *data, Evas_Object * obj, void *event_info)
308 {
309         //error check
310         setting_retm_if(data == NULL, "Data parameter is NULL");
311
312         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
313         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
314         elm_genlist_item_selected_set(item, 0);
315         Setting_GenGroupItem_Data *list_item =  (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
316
317         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) data;
318         setting_update_gl_item_chk_status(list_item, !list_item->chk_status);
319         __chk_btn_change_set(ad, list_item);
320 }
321
322 static void
323 setting_ledindicator_main_chk_btn_cb(void *data, Evas_Object * obj, void *event_info)
324 {
325         SETTING_TRACE_BEGIN;
326         //error check
327         retm_if(data == NULL, "Data parameter is NULL");
328         SettingLedIndicatorUG *ad = NULL;
329
330         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
331         ad = list_item->userdata;
332         list_item->chk_status = elm_check_state_get(obj);       // for genlist update status
333         __chk_btn_change_set(ad, list_item);
334 }
335
336 static Eina_Bool
337 setting_ledindicator_main_click_softkey_back_cb(void *data, Elm_Object_Item *item)
338 {
339         SETTING_TRACE_BEGIN;
340         //error check
341         setting_retvm_if(data == NULL, EINA_TRUE,
342                         "[Setting > Drivingmode] Data parameter is NULL");
343
344         SettingLedIndicatorUG *ad = (SettingLedIndicatorUG *) data;
345
346         //Send destroy request
347         ug_destroy_me(ad->ug);
348         SETTING_TRACE_END;
349         //return EINA_TRUE;
350         return EINA_FALSE;
351 }
352