ed27f5fc17fb98e6ad847f75880ed7449b48eb47
[apps/home/clock.git] / stopwatch / src / stopwatch_vconf.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   * 
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   * 
8   *     http://www.tizenopensource.org/license
9   * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include "stopwatch_vconf.h"
18 #include "stopwatch_util.h"
19 /**********************************************************************
20 ******************define, struct ,typedef, union, enum, global val *************************************
21 ***********************************************************************/
22
23 //
24 typedef struct _noti_callback {
25         char *setting_key;
26         void (*noti_func) (keynode_t *, void *);
27 } noti_callback;
28 /**********************************************************************
29 ******************Local function declear, extern function declear*************************************
30 ***********************************************************************/
31 static void stw_idle_lockstate_change_cb(keynode_t *key, void *data);
32
33 /**********************************************************************
34 ******************Global val , static global val*************************************
35 ***********************************************************************/
36 #define STW_NOTI_MAX            1
37 static noti_callback s_notis[STW_NOTI_MAX] = {
38         {VCONFKEY_IDLE_LOCK_STATE, *stw_idle_lockstate_change_cb},
39 };
40
41 /**********************************************************************
42 ******************Local function ref*************************************
43 ***********************************************************************/
44
45 /**
46  * Debug function: to set LCD power off principle when VCONFKEY_IDLE_LOCK_STATE is changed
47  * This function requires data and key which indicates the key to be listened
48  *
49  * stopwatch_idle_lockstate_change_cb()
50  * @param[in] key           Pointer to indicate the screen lock state. If it is unlocked, this callback will be called
51  * @param[in] data          Pointer to user data, which is not necessary here.
52  *
53  * @return      void
54  */
55 static void stw_idle_lockstate_change_cb(keynode_t *key, void *data)
56 {
57         ret_if(!data);
58         int lock_state = vconf_keynode_get_int(key);
59         // to check screen lock state
60         if (!lock_state) {
61                 // to set LCD power off effect
62                 stw_util_pm_state_set(EINA_TRUE);
63         }
64 }
65
66 /**********************************************************************
67 ******************Global function ref*************************************
68 ***********************************************************************/
69
70 /**
71 * send
72 * This function is  used to init noti of vconf
73 * @param           data[in]           pointer to data
74 * @return          when success, return SUCCESS  or FAILED if error
75 * @exception
76 */
77 int stw_noti_init(void *data)
78 {
79         //set cb
80         struct appdata *ad = (struct appdata *)data;
81         int i = 0;
82         for (i = 0; i < STW_NOTI_MAX; i++) {
83                 if (0 !=
84                     vconf_notify_key_changed(s_notis[i].setting_key,
85                                              s_notis[i].noti_func, ad)) {
86                         return FAILED;
87                 }
88         }
89         return SUCCESS;
90 }
91
92 /**
93 * send
94 * This function is  used to fini noti of vconf
95 * @param           void
96 * @return          void
97 * @exception
98 */
99 void stw_noti_fini()
100 {
101         int i;
102         for (i = 0; i < STW_NOTI_MAX; i++) {
103                 vconf_ignore_key_changed(s_notis[i].setting_key,
104                                          s_notis[i].noti_func);
105         }
106 }