upload codes for TIZEN 2.0
[apps/home/clock.git] / src / clock_vconf.c
1 /*
2 *
3 * Copyright 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://www.tizenopensource.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 <vconf.h>
19
20 #include "clock.h"
21 #include "clock_vconf.h"
22
23 /**
24  * Load vconf setting from vconf module,
25  * And save such information to data
26  *
27  * @param[out]  data   Pointer to the application data structure,
28  *                     which used for store vconf setting
29  *
30  * @return     EINA_FALSE if load failed
31  *             EINA_TRUE if load successfully.
32  */
33 Eina_Bool clock_vconf_load_history_conf(void *data)
34 {
35         CLK_FUN_BEG();
36         if (!data) {
37                 return EINA_FALSE;
38         }
39
40         struct appdata *ad = (struct appdata *)data;
41         int app_id = 0;
42         int ref = -1;
43
44         // read history view id from vconf module
45         ref = vconf_get_int(VCONF_CLOCK_APPLICATION_ID, &app_id);
46
47         if (0 == ref && app_id >= 1 && app_id <= 4) {
48                 ad->history_view_id = app_id;
49                 CLK_INFO("\n\n\t <<<<<<<<<<<< application_id = %d\n", app_id);
50         } else {
51                 // if there is no history information, set default value to 1
52                 ad->history_view_id = 1;
53         }
54
55         CLK_FUN_END();
56         return EINA_TRUE;
57 }
58
59 /**
60  * Save the system setting which read from app data structure,
61  * And save such information into vconf setting
62  *
63  * @param[in]  data   Pointer to the application data structure,
64  *                    which used for read setting used for store
65  *
66  * @return     EINA_FALSE if save failed
67  *             EINA_TRUE if save successfully.
68  */
69 Eina_Bool clock_vconf_set_history_conf(void *data)
70 {
71         CLK_FUN_BEG();
72         if (!data) {
73                 return EINA_FALSE;
74         }
75
76         struct appdata *ad = (struct appdata *)data;
77
78         int app_id = ad->current_view_id;
79         // set current view id to vconf sets
80         if (vconf_set_int(VCONF_CLOCK_APPLICATION_ID, app_id)) {
81                 CLK_INFO
82                     ("\n\n\t <<<<<<<<<<<< clock_vconf_set_history_app_name FAIL\n");
83                 return EINA_FALSE;
84         } else {
85                 CLK_INFO
86                     ("\n\n\t <<<<<<<<<<<< clock_vconf_set_history_app_name OK\n");
87                 // sync
88                 vconf_sync_key(VCONF_CLOCK_APPLICATION_ID);
89         }
90
91         CLK_FUN_END();
92         return EINA_TRUE;
93 }
94
95 /**
96  * Check battery state for judging if battery low.
97  *
98  * @return     EINA_FALSE if battery low
99  *             EINA_TRUE if not
100  */
101 Eina_Bool clock_vconf_check_battery_low()
102 {
103         CLK_FUN_BEG();
104         int low_status = -1;
105
106         if (!vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &low_status)) {
107                 CLK_INFO("\n\tbattery status low = %d\n", low_status);
108                 if (low_status <= VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
109                         CLK_FUN_END();
110                         return EINA_TRUE;
111                 }
112         }
113         CLK_FUN_END();
114         return EINA_FALSE;
115 }