fix for applying wayland (removing X)
[apps/home/settings.git] / setting-powersaving / src / setting-powersaving-main.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <setting-powersaving-main.h>
19 #include <devman.h>
20
21 static int setting_powersaving_main_create(void *cb);
22 static int setting_powersaving_main_destroy(void *cb);
23 static int setting_powersaving_main_update(void *cb);
24 static int setting_powersaving_main_cleanup(void *cb);
25 static void setting_powersaving_view_disable(void *data, bool disable);
26
27 setting_view setting_view_powersaving_main = {
28         .create = setting_powersaving_main_create,
29         .destroy = setting_powersaving_main_destroy,
30         .update = setting_powersaving_main_update,
31         .cleanup = setting_powersaving_main_cleanup,
32 };
33
34 static void __setting_powersaving_main_vconf_change_cb(keynode_t *key, void *data)
35 {
36         SETTING_TRACE_BEGIN;
37         setting_retm_if(NULL == key, "key is NULL");
38         setting_retm_if(NULL == data, "data is NULL");
39         SettingPowersavingUG *ad = (SettingPowersavingUG *)data;
40
41         int status = vconf_keynode_get_bool(key);
42         char *vconf_name = vconf_keynode_get_name(key);
43
44         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS)) {
45                 SETTING_TRACE("status:%d", status);
46                 setting_powersaving_view_disable(ad, !status);
47                 ad->data_powersaving_active->chk_status = status;
48                 elm_check_state_set(ad->data_powersaving_active->eo_check, ad->data_powersaving_active->chk_status);
49                 int ret = 0;
50                 if (status) {//powersaving is on
51                         int pwrsv_vib = 0;
52                         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &pwrsv_vib);
53                         setting_retm_if(ret != 0, "get vconf failed");
54                         if (pwrsv_vib){
55                                 //touch feedback virbration
56                                 int value = 0;
57                                 ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
58                                 setting_retm_if(ret != 0, "get vconf failed");
59                                 ret = vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
60                                 setting_retm_if(ret != 0, "set vconf failed");
61                                 ret = vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
62                                 setting_retm_if(ret != 0, "set vconf failed");
63                         }
64                 } else {//powersaving is off
65                         //touch feedback virbration
66                         int value = 0;
67                         ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
68                         setting_retm_if(ret != 0, "get vconf failed");
69                         ret = vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
70                         setting_retm_if(ret != 0, "set vconf failed");
71                 }
72
73         } else {
74                 SETTING_TRACE_ERROR("vconf_name is wrong");
75         }
76 }
77
78
79 /* ***************************************************
80  *
81  *basic func
82  *
83  ***************************************************/
84 static int setting_powersaving_main_create(void *cb)
85 {
86         SETTING_TRACE_BEGIN;
87         /* error check */
88         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
89
90         SettingPowersavingUG *ad = (SettingPowersavingUG *) cb;
91         Evas_Object *scroller = NULL;
92
93         /* add basic layout */
94         ad->ly_main =
95             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
96                                                    ad->win_get,
97                                                    _(KeyStr_Powersaving),
98                                                    _("IDS_COM_BODY_BACK"), NULL,
99                                                    setting_powersaving_main_click_softkey_back_cb,
100                                                    NULL, ad, &scroller,
101                                                    &(ad->navi_bar));
102         Elm_Object_Item *item = NULL;;
103         /*  add separator */
104         item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
105                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
106         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
107
108         /* Powersaving Mode Activation */
109         int ret;
110         int value = 1;
111         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &value);
112         if (0 != ret) {
113                 SETTING_TRACE_ERROR("Failed to get vconf value");
114         }
115         int active_value = value;
116
117         ad->data_powersaving_active = setting_create_Gendial_field_def(scroller,
118                                                                        &itc_1text_1icon,
119                                                                        setting_powersaving_main_mouse_up_Gendial_list_cb,
120                                                                        ad,
121                                                                        SWALLOW_Type_1TOGGLE,
122                                                                        NULL,
123                                                                        NULL,
124                                                                        value,
125                                                                        KeyStr_Powersaving_Mode,
126                                                                        NULL,
127                                                                        setting_powersaving_main_motion_active_chk_btn_cb);
128         if (ad->data_powersaving_active) {
129                 __BACK_POINTER_SET(ad->data_powersaving_active);
130                 ad->data_powersaving_active->userdata = ad;
131         } else {
132                 SETTING_TRACE_ERROR("ad->data_powersaving_active is NULL");
133         }
134 #if SUPPORT_UI0_4
135         (void)setting_create_Gendial_field_titleItem(scroller,
136                                                      &itc_group_item,
137                                                      KeyStr_PS_SETTINGS,
138                                                      NULL);
139         //A.
140         value = 0;
141         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &value);
142         if (0 != ret) {
143                 SETTING_TRACE_ERROR("Failed to get vconf value");
144         }
145         ad->data_cpu_ps = setting_create_Gendial_field_def(scroller,
146                                                        &itc_1text_1icon,
147                                                        setting_powersaving_main_mouse_up_Gendial_list_cb,
148                                                        ad,
149                                                        SWALLOW_Type_1TOGGLE,
150                                                        NULL,
151                                                        NULL,
152                                                        value,
153                                                        KeyStr_CPU_PS,
154                                                        NULL,
155                                                        setting_powersaving_main_motion_active_chk_btn_cb);
156         if (ad->data_cpu_ps) {
157                 __BACK_POINTER_SET(ad->data_cpu_ps);
158                 ad->data_cpu_ps->userdata = ad;
159         }
160
161         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
162                                          ad,
163                                          SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
164                                          NULL, NULL, 0,
165                                          KeyStr_CPU_PS_DSC, NULL,
166                                          NULL);
167         elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL), 
168                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
169
170 #if DISABLED_CODE
171         //B.
172         value = 0;
173         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, &value);
174         if (0 != ret) {
175                 SETTING_TRACE_ERROR("Failed to get vconf value");
176         }
177         ad->data_display_ps = setting_create_Gendial_field_def(scroller,
178                                                        &itc_1text_1icon,
179                                                        setting_powersaving_main_mouse_up_Gendial_list_cb,
180                                                        ad,
181                                                        SWALLOW_Type_1TOGGLE,
182                                                        NULL,
183                                                        NULL,
184                                                        value,
185                                                        KeyStr_DISPLAY_PS,
186                                                        NULL,
187                                                        setting_powersaving_main_motion_active_chk_btn_cb);
188         if (ad->data_display_ps) {
189                 __BACK_POINTER_SET(ad->data_display_ps);
190                 ad->data_display_ps->userdata = ad;
191         }
192
193         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
194                                          ad,
195                                          SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
196                                          NULL, NULL, 0,
197                                          KeyStr_DISPLAY_PS_DSC, NULL,
198                                          NULL);
199         elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL), 
200                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
201         //C.
202         value = 0;
203         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BG_COLOR, &value);
204         if (0 != ret) {
205                 SETTING_TRACE_ERROR("Failed to get vconf value");
206         }
207         ad->data_bg_color = setting_create_Gendial_field_def(scroller,
208                                                        &itc_1text_1icon,
209                                                        setting_powersaving_main_mouse_up_Gendial_list_cb,
210                                                        ad,
211                                                        SWALLOW_Type_1TOGGLE,
212                                                        NULL,
213                                                        NULL,
214                                                        value,
215                                                        KeyStr_BG_COLOR,
216                                                        NULL,
217                                                        setting_powersaving_main_motion_active_chk_btn_cb);
218         if (ad->data_bg_color) {
219                 __BACK_POINTER_SET(ad->data_bg_color);
220                 ad->data_bg_color->userdata = ad;
221         }
222
223         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
224                                          ad,
225                                          SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
226                                          NULL, NULL, 0,
227                                          KeyStr_BG_COLOR_DSC, NULL,
228                                          NULL);
229         elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL), 
230                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
231 #endif
232
233         //D.
234         value = 0;
235         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &value);
236         if (0 != ret) {
237                 SETTING_TRACE_ERROR("Failed to get vconf value");
238         }
239         ad->data_screen_vib = setting_create_Gendial_field_def(scroller,
240                                                        &itc_1text_1icon,
241                                                        setting_powersaving_main_mouse_up_Gendial_list_cb,
242                                                        ad,
243                                                        SWALLOW_Type_1TOGGLE,
244                                                        NULL,
245                                                        NULL,
246                                                        value,
247                                                        KeyStr_SCREEN_VIB,
248                                                        NULL,
249                                                        setting_powersaving_main_motion_active_chk_btn_cb);
250         if (ad->data_screen_vib) {
251                 __BACK_POINTER_SET(ad->data_screen_vib);
252                 ad->data_screen_vib->userdata = ad;
253         }
254
255         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
256                                          ad,
257                                          SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
258                                          NULL, NULL, 0,
259                                          KeyStr_SCREEN_VIB_DSC, NULL,
260                                          NULL);
261         /****Powersaving Tips*/
262         (void)setting_create_Gendial_field_titleItem(scroller,
263                                                      &itc_group_item,
264                                                      KeyStr_Powersaving_Tips,
265                                                      NULL);
266
267         /****Customed Setting*/
268         ad->data_powersaving_about =
269             setting_create_Gendial_field_def(scroller, &itc_1text,
270                                              setting_powersaving_main_mouse_up_Gendial_list_cb,
271                                              ad, SWALLOW_Type_INVALID, NULL,
272                                              NULL, 0, KeyStr_Powersaving_About,
273                                              NULL, NULL);
274         __BACK_POINTER_SET(ad->data_powersaving_about);
275
276         item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
277                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
278         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
279
280         setting_powersaving_view_disable(ad, !active_value);
281 #else
282 #if SUPPORT_UI0_3
283         /****Powersaving Mode description*/
284         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
285                                          ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
286                                          NULL, NULL, 0,
287                                          KeyStr_Powersaving_Mode_DSC, NULL,
288                                          NULL);
289         elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL), 
290                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
291         /****customed Setting Mode active*/
292         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_STATUS, &value);
293         if (0 != ret) {
294                 SETTING_TRACE_ERROR("Failed to get vconf value");
295         }
296         bool customed_flag = (bool) value;
297         ad->data_customed_active = setting_create_Gendial_field_def(scroller,
298                                                 &itc_1text_1icon,
299                                                 setting_powersaving_main_mouse_up_Gendial_list_cb,
300                                                 ad,
301                                                 SWALLOW_Type_1TOGGLE,
302                                                 NULL, NULL,
303                                                 value,
304                                                 KeyStr_Powersaving_Customed_Mode,
305                                                 NULL,
306                                                 setting_powersaving_main_motion_active_chk_btn_cb);
307         if (ad->data_customed_active) {
308                 __BACK_POINTER_SET(ad->data_customed_active);
309                 ad->data_customed_active->userdata = ad;
310         } else {
311                 SETTING_TRACE_ERROR("ad->data_powersaving_active is NULL");
312         }
313 #else
314         setting_enable_expandable_genlist(scroller, ad, setting_powersaving_ug_exp_cb,NULL);
315         char *str_value = get_pa_powersaving_at_str();
316         ad->data_saving_at =
317             setting_create_Gendial_exp_parent_field(scroller,
318                                                     &itc_2text_3_parent,
319                                                     NULL, NULL,
320                                                     SWALLOW_Type_INVALID,
321                                                     KeyStr_Powersaving_AT,
322                                                     str_value);
323
324         if (ad->data_saving_at) {
325                 ad->data_saving_at->int_slp_setting_binded =
326                     INT_SLP_SETTING_POWERSAVING_AT;
327         } else {
328                 SETTING_TRACE_ERROR("ad->data_back is NULL");
329         }
330         __BACK_POINTER_SET(ad->data_saving_at);
331         G_FREE(str_value);
332 #endif
333         /****Customed Setting*/
334         ad->data_customed_setting =
335             setting_create_Gendial_field_def(scroller, &itc_1text,
336                                              setting_powersaving_main_mouse_up_Gendial_list_cb,
337                                              ad, SWALLOW_Type_INVALID, NULL,
338                                              NULL, 0,
339                                              KeyStr_Powersaving_Customed, NULL,
340                                              NULL);
341         __BACK_POINTER_SET(ad->data_customed_setting);
342
343         /* Powersaving and battery level Description */
344         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
345                                          ad,
346                                          SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
347                                          NULL, NULL, 0,
348                                          KeyStr_Powersaving_Level_DSC, NULL,
349                                          NULL);
350
351         /****Powersaving Tips*/
352         (void)setting_create_Gendial_field_titleItem(scroller,
353                                                      &itc_group_item,
354                                                      KeyStr_Powersaving_Tips,
355                                                      NULL);
356
357         /****Customed Setting*/
358         ad->data_powersaving_about =
359             setting_create_Gendial_field_def(scroller, &itc_1text,
360                                              setting_powersaving_main_mouse_up_Gendial_list_cb,
361                                              ad, SWALLOW_Type_INVALID, NULL,
362                                              NULL, 0, KeyStr_Powersaving_About,
363                                              NULL, NULL);
364         __BACK_POINTER_SET(ad->data_powersaving_about);
365 #if SUPPORT_UI0_3
366         if (!customed_flag && ad->data_customed_setting) {
367                 setting_disable_genlist_item(ad->data_customed_setting->item);
368         }
369 #else
370         if (!active_value)
371         {
372                 if (ad->data_saving_at) {
373                         setting_disable_genlist_item(ad->data_saving_at->item);
374                 }
375
376                 if (ad->data_customed_setting) {
377                         setting_disable_genlist_item(ad->data_customed_setting->item);
378                 }
379         }
380 #endif
381 #endif
382
383         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
384                         __setting_powersaving_main_vconf_change_cb, ad);
385         if (ret != 0) {
386                 SETTING_TRACE_ERROR("call vconf_notify_key_changed failed");
387         }
388
389         setting_view_powersaving_main.is_create = 1;
390         return SETTING_RETURN_SUCCESS;
391 }
392
393
394 static int setting_powersaving_main_destroy(void *cb)
395 {
396         SETTING_TRACE_BEGIN;
397         /* error check */
398         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
399
400         SettingPowersavingUG *ad = (SettingPowersavingUG *) cb;
401
402         int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
403                         __setting_powersaving_main_vconf_change_cb);
404         if (ret != 0) {
405                 SETTING_TRACE_ERROR("call vconf_ignore_key_changed failed");
406         }
407
408         if (ad->ly_main != NULL) {
409                 evas_object_del(ad->ly_main);
410                 setting_view_powersaving_main.is_create = 0;
411         }
412
413         return SETTING_RETURN_SUCCESS;
414 }
415
416 static int setting_powersaving_main_update(void *cb)
417 {
418         SETTING_TRACE_BEGIN;
419         /* error check */
420         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
421         return SETTING_RETURN_SUCCESS;
422 }
423
424 static int setting_powersaving_main_cleanup(void *cb)
425 {
426         SETTING_TRACE_BEGIN;
427         /* error check */
428         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
429         return SETTING_RETURN_SUCCESS;
430 }
431
432 /* ***************************************************
433  *
434  *general func
435  *
436  ***************************************************/
437 static void
438 __powersaving_on_resp_cb(void *data, Evas_Object *obj, void *event_info)
439 {
440         SETTING_TRACE_BEGIN;
441         setting_retm_if(NULL == data, "NULL == data");
442         int response_type = btn_type(obj);
443         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
444         if (POPUP_RESPONSE_OK == response_type) {       //need set vconf
445                 if (ad->data_powersaving_active) {
446                         int err =
447                                 vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
448                                                 ad->data_powersaving_active->chk_status);
449                         if (0 != err) { //if set failed, need rollback
450                                 SETTING_TRACE_ERROR("Set vconf Failed");
451                                 ad->data_powersaving_active->chk_status =
452                                         !ad->data_powersaving_active->chk_status;
453                                 elm_check_state_set(ad->
454                                                 data_powersaving_active->
455                                                 eo_check,
456                                                 ad->
457                                                 data_powersaving_active->
458                                                 chk_status);
459                                 return;
460                         }
461                         if (ad->data_powersaving_active->chk_status) {//powersaving is on
462                                 int pwrsv_vib = 0;
463                                 vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &pwrsv_vib);
464                                 if (pwrsv_vib){
465                                         //touch feedback virbration
466                                         int value = 0;
467                                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
468                                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
469                                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
470                                 }
471                         } else {//powersaving is off
472                                 //touch feedback virbration
473                                 int value = 0;
474                                 vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
475                                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
476                         }
477
478                         if (ad->popup_chk && elm_check_state_get(ad->popup_chk)) {
479                                 (void)
480                                         vconf_set_bool
481                                         (VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS_REMINDER,
482                                          FALSE);
483                         }
484                 }
485         } else if (POPUP_RESPONSE_CANCEL == response_type) {    //need rollback
486                 if (ad->data_powersaving_active) {
487                         ad->data_powersaving_active->chk_status =
488                             !ad->data_powersaving_active->chk_status;
489                         elm_check_state_set(ad->data_powersaving_active->
490                                             eo_check,
491                                             ad->data_powersaving_active->
492                                             chk_status);
493                         if (ad->data_saving_at) {
494                                 setting_disable_genlist_item(ad->data_saving_at->item);
495                         }
496                         if (ad->data_customed_setting) {
497                                 setting_disable_genlist_item(ad->data_customed_setting->item);
498                         }
499                         if (ad->data_cpu_ps) {
500                                 setting_disable_genlist_item(ad->data_cpu_ps->item);
501                         }
502                         if (ad->data_display_ps) {
503                                 setting_disable_genlist_item(ad->data_display_ps->item);
504                         }
505                         if (ad->data_bg_color) {
506                                 setting_disable_genlist_item(ad->data_bg_color->item);
507                         }
508                         if (ad->data_screen_vib) {
509                                 setting_disable_genlist_item(ad->data_screen_vib->item);
510                         }
511                 }
512         }
513
514         evas_object_del(ad->popup);
515         ad->popup = NULL;
516         ad->popup_chk = NULL;
517 }
518
519 static void
520 setting_powersaving_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
521                                                   void *event_info)
522 {
523         SETTING_TRACE_BEGIN;
524         /* error check */
525         setting_retm_if(data == NULL, "Data parameter is NULL");
526
527         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
528         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
529         elm_genlist_item_selected_set(item, 0);
530         Setting_GenGroupItem_Data *list_item =
531             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
532
533         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
534
535         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
536
537         if (!safeStrCmp(KeyStr_Powersaving_Mode, list_item->keyStr)) {
538                 list_item->chk_status =
539                     !elm_check_state_get(list_item->eo_check);
540                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
541
542                 setting_powersaving_view_disable(ad, !list_item->chk_status);
543
544                 int reminder_flag = TRUE;
545                 int ret =
546                     vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS_REMINDER,
547                                    &reminder_flag);
548                 if (0 != ret) {
549                         SETTING_TRACE_ERROR("Failed to get vconf value");
550                 }
551                 SETTING_TRACE("reminder_flag:%d", reminder_flag);
552                 if (list_item->chk_status && reminder_flag) {
553                         ad->popup =
554                             setting_create_popup_with_image_check(ad, ad->win_get,
555                                                             NULL,
556                                                             _(POWERSAVING_REMINDER), NULL,NULL,
557                                                             _(NEVER_SHOW_AGAIN),
558                                                             &(ad->popup_chk),
559                                                             __powersaving_on_resp_cb,
560                                                             0,
561                                                             2, _("IDS_COM_SK_OK"),
562                                                             _("IDS_COM_SK_CANCEL"));
563                         return;
564                 }
565                 ret =
566                     vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, list_item->chk_status);
567                 if (0 != ret) { /* rollback */
568                         SETTING_TRACE_ERROR("Set vconf Failed");
569                         list_item->chk_status = !list_item->chk_status;
570                         elm_check_state_set(list_item->eo_check,
571                                             list_item->chk_status);
572                         return;
573                 }
574                 if (list_item->chk_status) {//powersaving is on
575                         int pwrsv_vib = 0;
576                         vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &pwrsv_vib);
577                         if (pwrsv_vib){
578                                 //touch feedback virbration
579                                 int value = 0;
580                                 vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
581                                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
582                                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
583                         }
584                 } else {//powersaving is off
585                         //touch feedback virbration
586                         int value = 0;
587                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
588                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
589                 }
590
591         }
592         else if (!safeStrCmp(KeyStr_Powersaving_Customed_Mode, list_item->keyStr)) {
593                 int old_status = elm_check_state_get(list_item->eo_check);
594                 int ret = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_STATUS, !old_status);
595                 setting_retm_if(0 != ret, "Failed to set vconf [%s]",
596                         VCONFKEY_SETAPPL_PWRSV_CUSTMODE_STATUS);
597                 /* new status */
598                 list_item->chk_status = !old_status;
599                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
600                 if (0 == list_item->chk_status) {
601                         //not active
602                         if (ad->data_customed_setting) {
603                                 setting_disable_genlist_item(ad->data_customed_setting->item);
604                                 }
605                 } else {
606                         //Powersavings actived
607                         if (ad->data_customed_setting) {
608                                 setting_enable_genlist_item(ad->data_customed_setting->item);
609                         }
610                 }
611         }
612         else if (!safeStrCmp(KeyStr_Powersaving_Customed, list_item->keyStr)) {
613                 setting_view_change(&setting_view_powersaving_main,
614                                     &setting_view_powersaving_customed, ad);
615         } else if (!safeStrCmp(KeyStr_Powersaving_About, list_item->keyStr)) {
616                 setting_view_change(&setting_view_powersaving_main,
617                                     &setting_view_powersaving_about, ad);
618         }
619         else if(!safeStrCmp(KeyStr_CPU_PS, list_item->keyStr))
620         {
621                 list_item->chk_status =
622                     !elm_check_state_get(list_item->eo_check);
623                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
624                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, list_item->chk_status);
625                 if (0 != err) {
626                         /* rollback */
627                         SETTING_TRACE_ERROR("Set vconf Failed");
628                         list_item->chk_status = !list_item->chk_status;
629                         elm_check_state_set(obj, list_item->chk_status);
630                         return;
631                 }
632         }
633         else if(!safeStrCmp(KeyStr_DISPLAY_PS, list_item->keyStr))
634         {
635                 list_item->chk_status =
636                     !elm_check_state_get(list_item->eo_check);
637                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
638                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, list_item->chk_status);
639                 if (0 != err) {
640                         /* rollback */
641                         SETTING_TRACE_ERROR("Set vconf Failed");
642                         list_item->chk_status = !list_item->chk_status;
643                         elm_check_state_set(obj, list_item->chk_status);
644                         return;
645                 }
646         }
647         else if(!safeStrCmp(KeyStr_BG_COLOR, list_item->keyStr))
648         {
649                 list_item->chk_status =
650                     !elm_check_state_get(list_item->eo_check);
651                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
652                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BG_COLOR, list_item->chk_status);
653                 if (0 != err) {
654                         /* rollback */
655                         SETTING_TRACE_ERROR("Set vconf Failed");
656                         list_item->chk_status = !list_item->chk_status;
657                         elm_check_state_set(obj, list_item->chk_status);
658                         return;
659                 }
660         }
661         else if(!safeStrCmp(KeyStr_SCREEN_VIB, list_item->keyStr))
662         {
663                 list_item->chk_status =
664                     !elm_check_state_get(list_item->eo_check);
665                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
666                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, list_item->chk_status);
667                 if (0 != err) {
668                         /* rollback */
669                         SETTING_TRACE_ERROR("Set vconf Failed");
670                         list_item->chk_status = !list_item->chk_status;
671                         elm_check_state_set(obj, list_item->chk_status);
672                         return;
673                 }
674
675                 //take it into effect
676                 int value = 0;
677                 if (list_item->chk_status){
678                         //touch feedback virbration
679                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
680                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
681                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
682                 } else {
683                         //touch feedback virbration
684                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
685                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
686                 }
687         }
688 }
689
690 static void __setting_powersaving_main_popup_rsp_cb(void *data, Evas_Object *obj, void *event_info)
691 {
692         SETTING_TRACE_BEGIN;
693         setting_retm_if(data == NULL, "Data parameter is NULL");
694         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
695
696         if (obj) {
697                 evas_object_del(obj);
698                 obj = NULL;
699         }
700         ad->popup = NULL;
701
702         int ret = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, 0);
703         setting_retm_if(0 != ret, "Failed to set vconf value");
704 }
705
706 static void
707 setting_powersaving_main_click_softkey_back_cb(void *data, Evas_Object *obj,
708                                                void *event_info)
709 {
710         SETTING_TRACE_BEGIN;
711         /* error check */
712         setting_retm_if(data == NULL, "[Setting > Powersaving] Data parameter is NULL");
713         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
714
715         int ret = 0;
716         int value = 0;
717         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &value);
718         setting_retm_if(0 != ret, "Failed to get vconf value");
719
720         if (value) {
721                 int sub_item_value = 0;
722
723                 /* check VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU */
724                 ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &sub_item_value);
725                 setting_retm_if(0 != ret, "Failed to get vconf value");
726                 if (sub_item_value) {
727                         ug_destroy_me(ad->ug);
728                         return;
729                 }
730
731                 /* check VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY */
732                 ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, &sub_item_value);
733                 setting_retm_if(0 != ret, "Failed to get vconf value");
734                 if (sub_item_value) {
735                         ug_destroy_me(ad->ug);
736                         return;
737                 }
738
739                 /* check VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BG_COLOR */
740                 ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BG_COLOR, &sub_item_value);
741                 setting_retm_if(0 != ret, "Failed to get vconf value");
742                 if (sub_item_value) {
743                         ug_destroy_me(ad->ug);
744                         return;
745                 }
746
747                 /* check VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB */
748                 ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &sub_item_value);
749                 setting_retm_if(0 != ret, "Failed to get vconf value");
750                 if (sub_item_value) {
751                         ug_destroy_me(ad->ug);
752                         return;
753                 }
754
755                 if (ad->popup) {
756                         evas_object_del(ad->popup);
757                         ad->popup = NULL;
758                 }
759                 ad->popup = setting_create_popup_without_btn(ad, ad->win_get, NULL, _(SETTING_POWERSAVING_ALL_SUB_ITEMS_OFF),
760                                      __setting_powersaving_main_popup_rsp_cb, POPUP_INTERVAL, TRUE, TRUE);
761         } else {
762                 /* Send destroy request */
763                 ug_destroy_me(ad->ug);
764         }
765 }
766
767 static void
768 setting_powersaving_main_motion_active_chk_btn_cb(void *data, Evas_Object *obj,
769                                                   void *event_info)
770 {
771         SETTING_TRACE_BEGIN;
772         /* error check */
773         retm_if(data == NULL, "Data parameter is NULL");
774         Setting_GenGroupItem_Data *list_item =
775             (Setting_GenGroupItem_Data *) data;
776         SettingPowersavingUG *ad = list_item->userdata;
777         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
778         if (!safeStrCmp(KeyStr_Powersaving_Mode, list_item->keyStr)) {
779                 setting_powersaving_view_disable(ad, !list_item->chk_status);
780                 int reminder_flag = TRUE;
781                 int ret =
782                     vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS_REMINDER,
783                                    &reminder_flag);
784                 if (0 != ret) {
785                         SETTING_TRACE_ERROR("Failed to get vconf value");
786                 }
787                 SETTING_TRACE("reminder_flag:%d", reminder_flag);
788                 if (list_item->chk_status && reminder_flag) {
789                         ad->popup =
790                             setting_create_popup_with_image_check(ad, ad->win_get,
791                                                             NULL,
792                                                             _(POWERSAVING_REMINDER), NULL,NULL,
793                                                             _(NEVER_SHOW_AGAIN),
794                                                             &(ad->popup_chk),
795                                                             __powersaving_on_resp_cb,
796                                                             0,
797                                                             2, _("IDS_COM_SK_OK"),
798                                                             _("IDS_COM_SK_CANCEL"));
799                         return;
800                 }
801
802                 ret =
803                     vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS,
804                                    list_item->chk_status);
805                 if (0 != ret) { /* rollback */
806                         SETTING_TRACE_ERROR("Set vconf Failed");
807                         list_item->chk_status = !list_item->chk_status;
808                         elm_check_state_set(obj, list_item->chk_status);
809                         return;
810                 }
811                 if (list_item->chk_status) {//powersaving is on
812                         int pwrsv_vib = 0;
813                         vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, &pwrsv_vib);
814                         if (pwrsv_vib){
815                                 //touch feedback virbration
816                                 int value = 0;
817                                 vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
818                                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
819                                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
820                         }
821                 } else {//powersaving is off
822                         //touch feedback virbration
823                         int value = 0;
824                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
825                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
826                 }
827         }
828         else if(!safeStrCmp(KeyStr_Powersaving_Customed_Mode, list_item->keyStr))
829         {
830                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_STATUS,
831                         list_item->chk_status);
832                 if (0 != err) {
833                         /* rollback */
834                         SETTING_TRACE_ERROR("Set vconf Failed");
835                         list_item->chk_status = !list_item->chk_status;
836                         elm_check_state_set(obj, list_item->chk_status);
837                         return;
838                 }
839                 if (0 == list_item->chk_status) {
840                         //not active
841                         if (ad->data_customed_setting)
842                         {
843                                 setting_disable_genlist_item(ad->data_customed_setting->item);
844                         }
845                 } else {
846                         //Powersavings actived
847                         if (ad->data_customed_setting) {
848                                 setting_enable_genlist_item(ad->data_customed_setting->item);
849                         }
850                 }
851         }
852         else if(!safeStrCmp(KeyStr_CPU_PS, list_item->keyStr))
853         {
854                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, list_item->chk_status);
855                 if (0 != err) {
856                         /* rollback */
857                         SETTING_TRACE_ERROR("Set vconf Failed");
858                         list_item->chk_status = !list_item->chk_status;
859                         elm_check_state_set(obj, list_item->chk_status);
860                         return;
861                 }
862         }
863         else if(!safeStrCmp(KeyStr_DISPLAY_PS, list_item->keyStr))
864         {
865                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DISPLAY, list_item->chk_status);
866                 if (0 != err) {
867                         /* rollback */
868                         SETTING_TRACE_ERROR("Set vconf Failed");
869                         list_item->chk_status = !list_item->chk_status;
870                         elm_check_state_set(obj, list_item->chk_status);
871                         return;
872                 }
873         }
874         else if(!safeStrCmp(KeyStr_BG_COLOR, list_item->keyStr))
875         {
876                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BG_COLOR, list_item->chk_status);
877                 if (0 != err) {
878                         /* rollback */
879                         SETTING_TRACE_ERROR("Set vconf Failed");
880                         list_item->chk_status = !list_item->chk_status;
881                         elm_check_state_set(obj, list_item->chk_status);
882                         return;
883                 }
884                 if (list_item->chk_status)
885                 {
886                         // do nothing
887                 }
888         }
889         else if(!safeStrCmp(KeyStr_SCREEN_VIB, list_item->keyStr))
890         {
891                 int err = vconf_set_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_SCREEN_VIB, list_item->chk_status);
892                 if (0 != err) {
893                         /* rollback */
894                         SETTING_TRACE_ERROR("Set vconf Failed");
895                         list_item->chk_status = !list_item->chk_status;
896                         elm_check_state_set(obj, list_item->chk_status);
897                         return;
898                 }
899
900                 //take it into effect
901                 int value = 0;
902                 if (list_item->chk_status){
903                         //touch feedback virbration
904                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &value);
905                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, value);//backup
906                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, 0);
907                 } else {
908                         //touch feedback virbration
909                         vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_BAK_INT, &value);
910                         vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
911                 }
912         }
913
914
915         return;
916 }
917 static void setting_powersaving_view_disable(void *data, bool disable)
918 {
919         SETTING_TRACE_BEGIN;
920         /* error check */
921         ret_if(data == NULL);
922         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
923         if (disable)
924         {
925                 if (ad->data_cpu_ps) setting_disable_genlist_item(ad->data_cpu_ps->item);
926                 if (ad->data_display_ps) setting_disable_genlist_item(ad->data_display_ps->item);
927                 if (ad->data_bg_color) setting_disable_genlist_item(ad->data_bg_color->item);
928                 if (ad->data_screen_vib) setting_disable_genlist_item(ad->data_screen_vib->item);
929         }
930         else
931         {
932                 if (ad->data_cpu_ps) setting_enable_genlist_item(ad->data_cpu_ps->item);
933                 if (ad->data_display_ps) setting_enable_genlist_item(ad->data_display_ps->item);
934                 if (ad->data_bg_color) setting_enable_genlist_item(ad->data_bg_color->item);
935                 if (ad->data_screen_vib) setting_enable_genlist_item(ad->data_screen_vib->item);
936         }
937 }
938