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