Tizen 2.0 Release
[apps/home/settings.git] / setting-powersaving / src / setting-powersaving-customed.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-customed.h>
19
20 static int setting_powersaving_customed_create(void *cb);
21 static int setting_powersaving_customed_destroy(void *cb);
22 static int setting_powersaving_customed_update(void *cb);
23 static int setting_powersaving_customed_cleanup(void *cb);
24
25 setting_view setting_view_powersaving_customed = {
26         .create = setting_powersaving_customed_create,
27         .destroy = setting_powersaving_customed_destroy,
28         .update = setting_powersaving_customed_update,
29         .cleanup = setting_powersaving_customed_cleanup,
30 };
31
32 /* ***************************************************
33  *
34  *basic func
35  *
36  ***************************************************/
37
38 static int setting_powersaving_customed_create(void *cb)
39 {
40         SETTING_TRACE_BEGIN;
41         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
42
43         SettingPowersavingUG *ad = (SettingPowersavingUG *) cb;
44
45         Evas_Object *scroller = NULL;
46
47         /* add basic layout */
48         setting_push_layout_navi_bar_genlist(ad->win_main_layout,
49                                              ad->win_get,
50                                              _(KeyStr_Powersaving_Customed),
51                                              _("IDS_COM_BODY_BACK"),
52                                              NULL,
53                                              setting_powersaving_customed_click_softkey_cancel_cb,
54                                              NULL, ad, &scroller, ad->navi_bar);
55         Elm_Object_Item *item = NULL;
56         /*  add separator */
57         item = elm_genlist_item_append(scroller, &itc_seperator,
58                                        NULL, NULL,
59                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
60         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
61         char *str_value = NULL;
62 #if SUPPORT_UI0_3
63         setting_enable_expandable_genlist(scroller, ad, setting_powersaving_ug_exp_cb,NULL);
64         str_value = get_pa_powersaving_at_str();
65         ad->data_saving_at =
66             setting_create_Gendial_exp_parent_field(scroller,
67                                                     &itc_2text_3_parent,
68                                                     NULL, NULL,
69                                                     SWALLOW_Type_INVALID,
70                                                     KeyStr_Powersaving_AT,
71                                                     str_value);
72
73         if (ad->data_saving_at) {
74                 ad->data_saving_at->int_slp_setting_binded =
75                     INT_SLP_SETTING_POWERSAVING_AT;
76         } else {
77                 SETTING_TRACE_ERROR("ad->data_back is NULL");
78         }
79         __BACK_POINTER_SET(ad->data_saving_at);
80         G_FREE(str_value);
81 #endif
82         setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
83                                          ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
84                                          NULL, NULL, 0,
85                                          "Turn off each settings when it is not in use.",
86                                          NULL, NULL);
87         elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL), 
88                                          ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
89
90         int ret;
91         int value = 1;
92         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_WIFI, &value);
93         if (0 != ret) {
94                 SETTING_TRACE_ERROR("Failed to get vconf value");
95         }
96
97
98         ad->data_wifi_off = setting_create_Gendial_field_def(scroller,
99                                                              &itc_1text_1icon_2,
100                                                              setting_powersaving_customed_mouse_up_Gendial_list_cb,
101                                                              ad,
102                                                              SWALLOW_Type_1CHECK,
103                                                              NULL, NULL, value,
104                                                              KeyStr_WIFI_Off,
105                                                              NULL,
106                                                              setting_powersaving_customed_use_chk_btn_cb);
107         if (ad->data_wifi_off) {
108                 __BACK_POINTER_SET(ad->data_wifi_off);
109                 ad->data_wifi_off->userdata = ad;
110         } else {
111                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
112         }
113
114         value = 1;
115         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BT, &value);
116         if (0 != ret) {
117                 SETTING_TRACE_ERROR("Failed to get vconf value");
118         }
119
120         ad->data_bt_off = setting_create_Gendial_field_def(scroller,
121                                                            &itc_1text_1icon_2,
122                                                            setting_powersaving_customed_mouse_up_Gendial_list_cb,
123                                                            ad,
124                                                            SWALLOW_Type_1CHECK,
125                                                            NULL, NULL, value,
126                                                            KeyStr_BT_Off, NULL,
127                                                            setting_powersaving_customed_use_chk_btn_cb);
128         if (ad->data_bt_off) {
129                 __BACK_POINTER_SET(ad->data_bt_off);
130                 ad->data_bt_off->userdata = ad;
131         } else {
132                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
133         }
134
135         value = 1;
136         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_GPS, &value);
137         if (0 != ret) {
138                 SETTING_TRACE_ERROR("Failed to get vconf value");
139         }
140
141         ad->data_gps_off = setting_create_Gendial_field_def(scroller,
142                                                             &itc_1text_1icon_2,
143                                                             setting_powersaving_customed_mouse_up_Gendial_list_cb,
144                                                             ad,
145                                                             SWALLOW_Type_1CHECK,
146                                                             NULL, NULL, value,
147                                                             KeyStr_GPS_Off,
148                                                             NULL,
149                                                             setting_powersaving_customed_use_chk_btn_cb);
150         if (ad->data_gps_off) {
151                 __BACK_POINTER_SET(ad->data_gps_off);
152                 ad->data_gps_off->userdata = ad;
153         } else {
154                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
155         }
156         value = 1;
157         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DATASYNC, &value);
158         if (0 != ret) {
159                 SETTING_TRACE_ERROR("Failed to get vconf value");
160         }
161
162         ad->data_sync_off = setting_create_Gendial_field_def(scroller,
163                                                              &itc_1text_1icon_2,
164                                                              setting_powersaving_customed_mouse_up_Gendial_list_cb,
165                                                              ad,
166                                                              SWALLOW_Type_1CHECK,
167                                                              NULL, NULL, value,
168                                                              KeyStr_SYNC_Off,
169                                                              NULL,
170                                                              setting_powersaving_customed_use_chk_btn_cb);
171         if (ad->data_sync_off) {
172                 __BACK_POINTER_SET(ad->data_sync_off);
173                 ad->data_sync_off->userdata = ad;
174         } else {
175                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
176         }
177
178         value = 1;
179         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_HOTSPOT, &value);
180         if (0 != ret) {
181                 SETTING_TRACE_ERROR("Failed to get vconf value");
182         }
183
184         ad->data_hotspot_off = setting_create_Gendial_field_def(scroller,
185                                                              &itc_1text_1icon_2,
186                                                              setting_powersaving_customed_mouse_up_Gendial_list_cb,
187                                                              ad,
188                                                              SWALLOW_Type_1CHECK,
189                                                              NULL, NULL, value,
190                                                              KeyStr_HOTSPOT_Off,
191                                                              NULL,
192                                                              setting_powersaving_customed_use_chk_btn_cb);
193         if (ad->data_hotspot_off) {
194                 __BACK_POINTER_SET(ad->data_hotspot_off);
195                 ad->data_hotspot_off->userdata = ad;
196         } else {
197                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
198         }
199
200         /*  add separator */
201         item = elm_genlist_item_append(scroller, &itc_seperator,
202                                        NULL, NULL,
203                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
204         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
205
206         /* ADJUST BRIGHTNESS */
207         int adjust_value;
208         value = 1;
209         ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BRT_STATUS, &value);
210         if (0 != ret) {
211                 SETTING_TRACE_ERROR("Failed to get vconf value");
212         }
213         adjust_value = value;
214
215         ad->data_adjust_bright = setting_create_Gendial_field_def(scroller,
216                                                              &itc_1text_1icon,
217                                                              setting_powersaving_customed_mouse_up_Gendial_list_cb,
218                                                              ad,
219                                                              SWALLOW_Type_1TOGGLE,
220                                                              NULL, NULL, value,
221                                                              KeyStr_Adjust_Bright,
222                                                              NULL,
223                                                              setting_powersaving_customed_use_chk_btn_cb);
224         if (ad->data_adjust_bright) {
225                 __BACK_POINTER_SET(ad->data_adjust_bright);
226                 ad->data_adjust_bright->userdata = ad;
227         } else {
228                 SETTING_TRACE_ERROR("ad->data_use_tilt is NULL");
229         }
230
231
232         /* BRIGHTNESS */
233         str_value = setting_powersaving_ug_get_brightness_str();
234         ad->data_brightness =
235             setting_create_Gendial_field_def(scroller, &itc_2text_3,
236                                              setting_powersaving_customed_mouse_up_Gendial_list_cb,
237                                              ad, SWALLOW_Type_INVALID, NULL,
238                                              NULL, 0, KeyStr_Brightness,
239                                              str_value, NULL);
240         if (ad->data_brightness) {
241                 ad->data_brightness->userdata = ad;
242                 __BACK_POINTER_SET(ad->data_screen_timeout);
243         } else {
244                 SETTING_TRACE_ERROR("ad->data_br is NULL");
245         }
246         G_FREE(str_value);
247
248
249         /*  add separator */
250         item = elm_genlist_item_append(scroller, &itc_seperator,
251                                        NULL, NULL,
252                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
253         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
254
255
256         /* BACKLIGHT */
257         str_value = get_pa_screen_timeout_str();
258         ad->data_screen_timeout =
259             setting_create_Gendial_exp_parent_field(scroller,
260                                                     &itc_2text_3_parent,
261                                                     NULL, NULL,
262                                                     SWALLOW_Type_INVALID,
263                                                     KeyStr_Screen_Timeout,
264                                                     str_value);
265
266         if (ad->data_screen_timeout) {
267                 ad->data_screen_timeout->int_slp_setting_binded =
268                     INT_SLP_SETTING_POWERSAVING_SCREEN_TIMEOUT;
269         } else {
270                 SETTING_TRACE_ERROR("ad->data_back is NULL");
271         }
272         __BACK_POINTER_SET(ad->data_screen_timeout);
273         G_FREE(str_value);
274
275         if (!adjust_value && ad->data_brightness) {
276                 setting_disable_genlist_item(ad->data_brightness->item);
277         }
278
279         setting_view_powersaving_customed.is_create = 1;
280
281         return SETTING_RETURN_SUCCESS;
282 }
283
284 static int setting_powersaving_customed_destroy(void *cb)
285 {
286         SETTING_TRACE_BEGIN;
287         /* error check */
288         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
289
290         SettingPowersavingUG *ad = (SettingPowersavingUG *) cb;
291         if (ad->popup) {
292                 evas_object_del(ad->popup);
293                 ad->popup = NULL;
294         }
295
296         elm_naviframe_item_pop(ad->navi_bar);
297
298         setting_view_powersaving_customed.is_create = 0;
299         return SETTING_RETURN_SUCCESS;
300 }
301
302 static int setting_powersaving_customed_update(void *cb)
303 {
304         SETTING_TRACE_BEGIN;
305         /* error check */
306         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
307         SettingPowersavingUG *ad = (SettingPowersavingUG *) cb;
308         if (ad->data_brightness)
309         {
310                 ad->data_brightness->sub_desc = setting_powersaving_ug_get_brightness_str();
311                 elm_object_item_data_set(ad->data_brightness->item, ad->data_brightness);
312                 elm_genlist_item_update(ad->data_brightness->item);
313         }
314         return SETTING_RETURN_SUCCESS;
315
316 }
317
318 static int setting_powersaving_customed_cleanup(void *cb)
319 {
320         SETTING_TRACE_BEGIN;
321         /* error check */
322         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
323         setting_powersaving_customed_destroy(cb);
324
325         return SETTING_RETURN_SUCCESS;
326 }
327
328 /* ***************************************************
329  *
330  *general func
331  *
332  ***************************************************/
333
334 /* ***************************************************
335  *
336  *call back func
337  *
338  ***************************************************/
339
340 static void
341 setting_powersaving_customed_click_softkey_cancel_cb(void *data,
342                                                      Evas_Object *obj,
343                                                      void *event_info)
344 {
345         SETTING_TRACE_BEGIN;
346         /* error check */
347         retm_if(data == NULL, "Data parameter is NULL");
348         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
349
350         setting_view_change(&setting_view_powersaving_customed,
351                             &setting_view_powersaving_main, ad);
352
353 }
354
355 static void setting_powersaving_customed_mouse_up_Gendial_list_cb(void *data,
356                                                                   Evas_Object *
357                                                                   obj, void
358                                                                   *event_info)
359 {
360         /* error check */
361         setting_retm_if(data == NULL, "Data parameter is NULL");
362
363         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
364         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
365         elm_genlist_item_selected_set(item, 0);
366         Setting_GenGroupItem_Data *list_item =
367             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
368
369         SettingPowersavingUG *ad = (SettingPowersavingUG *) data;
370
371         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
372
373         if (!safeStrCmp(KeyStr_Brightness, list_item->keyStr)) {
374                 setting_view_change(&setting_view_powersaving_customed,
375                                     &setting_view_powersaving_brightness, ad);
376                 return;
377         }
378
379         const char *vconf = NULL;
380         if (!safeStrCmp(KeyStr_WIFI_Off, list_item->keyStr)) {
381                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_WIFI;
382         } else if (!safeStrCmp(KeyStr_BT_Off, list_item->keyStr)) {
383                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BT;
384         } else if (!safeStrCmp(KeyStr_GPS_Off, list_item->keyStr)) {
385                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_GPS;
386         } else if (!safeStrCmp(KeyStr_SYNC_Off, list_item->keyStr)) {
387                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DATASYNC;
388         } else if (!safeStrCmp(KeyStr_HOTSPOT_Off, list_item->keyStr)) {
389                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_HOTSPOT;
390         } else if (!safeStrCmp(KeyStr_Adjust_Bright, list_item->keyStr)) {
391                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BRT_STATUS;
392         }
393         int old_status = elm_check_state_get(list_item->eo_check);
394         int ret = vconf_set_bool(vconf, !old_status);
395         setting_retm_if(0 != ret, "Failed to set vconf [%s]", vconf);
396         /* new status */
397         list_item->chk_status = !old_status;
398         elm_check_state_set(list_item->eo_check, list_item->chk_status);
399         if (!safeStrCmp(KeyStr_Adjust_Bright, list_item->keyStr) && ad->data_brightness) {
400                 if (0 == list_item->chk_status) {
401                         setting_disable_genlist_item(ad->data_brightness->item);
402                 } else {
403                         setting_enable_genlist_item(ad->data_brightness->item);
404                 }
405         }
406
407         return;
408 }
409
410 static void
411 setting_powersaving_customed_use_chk_btn_cb(void *data, Evas_Object *obj,
412                                             void *event_info)
413 {
414         SETTING_TRACE_BEGIN;
415         /* error check */
416         retm_if(data == NULL, "Data parameter is NULL");
417         Setting_GenGroupItem_Data *list_item =
418             (Setting_GenGroupItem_Data *) data;
419         SettingPowersavingUG *ad = list_item->userdata;
420
421         list_item->chk_status = elm_check_state_get(obj); /*  for genlist update status */
422
423         const char *vconf = NULL;
424         if (!safeStrCmp(KeyStr_WIFI_Off, list_item->keyStr)) {
425                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_WIFI;
426         } else if (!safeStrCmp(KeyStr_BT_Off, list_item->keyStr)) {
427                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BT;
428         } else if (!safeStrCmp(KeyStr_GPS_Off, list_item->keyStr)) {
429                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_GPS;
430         } else if (!safeStrCmp(KeyStr_SYNC_Off, list_item->keyStr)) {
431                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_DATASYNC;
432         } else if (!safeStrCmp(KeyStr_HOTSPOT_Off, list_item->keyStr)) {
433                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_HOTSPOT;
434         } else if (!safeStrCmp(KeyStr_Adjust_Bright, list_item->keyStr)) {
435                 vconf = VCONFKEY_SETAPPL_PWRSV_CUSTMODE_BRT_STATUS;
436         }
437
438         int err = vconf_set_bool(vconf, list_item->chk_status);
439         if (0 != err) { /* rollback */
440                 SETTING_TRACE_ERROR("Set vconf Failed");
441                 list_item->chk_status = !list_item->chk_status;
442                 elm_check_state_set(obj, list_item->chk_status);
443         }
444         if (!safeStrCmp(KeyStr_Adjust_Bright, list_item->keyStr) && ad->data_brightness) {
445                 if (0 == list_item->chk_status) {
446                         setting_disable_genlist_item(ad->data_brightness->item);
447                 } else {
448                         setting_enable_genlist_item(ad->data_brightness->item);
449                 }
450         }
451
452         return;
453 }