2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
17 #include "alarm_fwk_vconf.h"
18 #include "alarm_view_edit.h"
19 #include "alarm_subview_type.h"
21 /**********************************************************************
22 ******************define, struct ,typedef, union, enum, global val *************************************
23 ***********************************************************************/
26 typedef struct _noti_callback {
28 void (*noti_func) (keynode_t *, void *);
32 /**********************************************************************
33 ******************Local function declear, extern function declear*************************************
34 ***********************************************************************/
35 static int alarm_vconfkey_alarm_off_cb(void *data);
36 static int alarm_vconfkey_alarm_snooze_on_cb(void *data);
37 static void alarm_vconfkey_update_cb(keynode_t *, void *);
38 static void alarm_vconfkey_delete_cb(keynode_t * key, void *data);
39 static void alarm_vconfkey_idle_lock_cb(keynode_t * key, void *data);
40 static void alarm_vconfkey_volume_type_alarm_cb(keynode_t * key, void *data);
41 static void alarm_vconfkey_timezone_cb(keynode_t * node, void *data);
42 static void alarm_time_changed_cb(void *data);
43 /**********************************************************************
44 ******************Global val , static global val*************************************
45 ***********************************************************************/
46 #define ALARM_NOTI_MAX 5
47 static noti_callback s_notis[ALARM_NOTI_MAX] = {
48 {VCONFKEY_ALARM_UPDATE, alarm_vconfkey_update_cb},
49 {VCONFKEY_ALARM_DELETE, alarm_vconfkey_delete_cb},
50 {VCONFKEY_IDLE_LOCK_STATE, alarm_vconfkey_idle_lock_cb},
51 {VCONF_KEY_VOLUME_TYPE_ALARM, alarm_vconfkey_volume_type_alarm_cb},
52 {VCONFKEY_SETAPPL_TIMEZONE_INT, alarm_vconfkey_timezone_cb},
55 /**********************************************************************
56 ******************Local function ref*************************************
57 ***********************************************************************/
61 * This function is used to handle vconf key: VCONFKEY_ALARM_UPDATE, value: VCONFKEY_ALARM_OFF
62 * @param data[in] pointer to data
63 * @return when success, return SUCCESS or FAILED if error
66 static int alarm_vconfkey_alarm_off_cb(void *data)
68 struct appdata *ad = (struct appdata *)data;
69 if (IS_EQUAL(ad->page, PAGE_ALARM_GENLIST)) {
70 //update the alarm genlist
71 alarm_view_genlist.update(data);
74 ad->alarm->alarm_mgr_id = -1;
75 ad->alarm->enable = EINA_FALSE;
81 * This function is used to handle vconf key: VCONFKEY_ALARM_UPDATE, value: VCONFKEY_ALARM_SNOOZE_ON
82 * @param data[in] pointer to data
83 * @return when success, return SUCCESS or FAILED if error
86 static int alarm_vconfkey_alarm_snooze_on_cb(void *data)
88 struct appdata *ad = (struct appdata *)data;
89 if (IS_EQUAL(ad->page, PAGE_ALARM_GENLIST)) {
90 //update the alarm genlist
91 alarm_view_genlist.update(data);
98 * This function is used to handle vconf key: VCONFKEY_ALARM_UPDATE
99 * @param data[in] pointer to data
103 static void alarm_vconfkey_update_cb(keynode_t * key, void *data)
105 int alarm_update_value = vconf_keynode_get_int(key);
107 switch (alarm_update_value) {
108 case VCONFKEY_ALARM_OFF:
109 alarm_vconfkey_alarm_off_cb(data);
111 case VCONFKEY_ALARM_SNOOZE_ON:
112 alarm_vconfkey_alarm_snooze_on_cb(data);
115 CLK_ERR("error alarm_update_value");
123 * This function is used to handle vconf key: VCONFKEY_ALARM_DELETE
124 * @param data[in] pointer to data
128 static void alarm_vconfkey_delete_cb(keynode_t * key, void *data)
130 int alarm_delete_id = vconf_keynode_get_int(key);
131 struct appdata *ad = (struct appdata *)data;
134 alarm_genlist_name_array_del(alarm_delete_id);
135 if (IS_EQUAL(ad->page, PAGE_ALARM_GENLIST)) {
136 alarm_view_genlist.update(data);
143 * This function is used to handle vconf key: VCONFKEY_IDLE_LOCK_STATE
144 * @param data[in] pointer to data
148 static void alarm_vconfkey_idle_lock_cb(keynode_t * key, void *data)
150 int lock_state = vconf_keynode_get_int(key);
151 struct appdata *ad = (struct appdata *)data;
153 if (IS_EQUAL(lock_state, VCONFKEY_IDLE_LOCK) &&
154 IS_EQUAL(ad->page, PAGE_ALARM_SETTING)) {
155 alarm_setting_stop_sound(ad);
156 alarm_type_stop_sound(ad);
162 static void alarm_vconfkey_volume_type_alarm_cb(keynode_t * key, void *data)
164 int value = vconf_keynode_get_int(key);
165 struct appdata *ad = (struct appdata *)data;
166 setting_view *view = ad->view_setting;
168 if (IS_EQUAL(ad->page, PAGE_ALARM_SETTING)) {
169 if (!elm_object_item_disabled_get(view->item_volume)) {
170 elm_slider_value_set(view->eo_volume_slider, value);
176 static void alarm_vconfkey_timezone_cb(keynode_t * node, void *data)
179 alarm_time_changed_cb(data);
182 #define _TOUCH_VCONFKEY_TYPE_INT(key, value) \
184 if (vconf_get_int(key, &value) != SUCCESS) {\
185 vconf_set_int(key, 0);\
190 static void _alarm_noti_touch()
195 for (index = 0; index < ALARM_NOTI_MAX; index++) {
196 _TOUCH_VCONFKEY_TYPE_INT(s_notis[index].setting_key, iValue)
200 static int _alarm_region_changed_cb(void *data)
202 retvm_if(!data, FAILED, "data");
203 alarm_time_changed_cb(data);
207 static void alarm_setting_time_changed_cb(void *data)
210 alarm_time_changed_cb(data);
213 static void alarm_time_changed_cb(void *data)
216 struct appdata *ad = (struct appdata *)data;
217 ret_if(!ad->is_alarm);
219 clk_timezone_update();
220 vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &ad->time_format);
221 if (IS_EQUAL(ad->page, PAGE_ALARM_GENLIST)) {
222 alarm_view_genlist.update(data);
223 } else if (IS_EQUAL(ad->page, PAGE_ALARM_DELETE)) {
224 alarm_view_delete.update(data);
225 } else if (IS_EQUAL(ad->page, PAGE_ALARM_SETTING)) {
226 alarm_view_setting.update(data);
230 /**********************************************************************
231 ******************Global function ref*************************************
232 ***********************************************************************/
236 * This function is used to init noti of vconf
237 * @param data[in] pointer to data
238 * @return when success, return SUCCESS or FAILED if error
241 int alarm_noti_init(void *data)
243 //temp handle to protect
246 struct appdata *ad = (struct appdata *)data;
248 appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE,
249 _alarm_region_changed_cb, data);
250 alarm_heynoti_init(ad);
251 for (i = 0; i < ALARM_NOTI_MAX; i++) {
253 vconf_notify_key_changed(s_notis[i].setting_key,
254 s_notis[i].noti_func, ad)) {
263 * This function is used to fini noti of vconf
268 void alarm_noti_fini()
271 for (i = 0; i < ALARM_NOTI_MAX; i++) {
272 vconf_ignore_key_changed(s_notis[i].setting_key,
273 s_notis[i].noti_func);
275 alarm_heynoti_fini();
278 int alarm_heynoti_init(void *data)
284 retv_if(fd < 0, FAILED);
286 ret = heynoti_subscribe(fd, "setting_time_changed",
287 alarm_setting_time_changed_cb, data);
288 if (SUCCESS != ret) {
289 CLK_ERR("heynoti_subscribe");
293 ret = heynoti_attach_handler(fd);
294 if (SUCCESS != ret) {
295 CLK_ERR("heynoti_attach_handler");
301 if (SUCCESS != ret) {
302 heynoti_detach_handler(fd);
303 heynoti_unsubscribe(fd, "setting_time_changed",
304 alarm_setting_time_changed_cb);
310 void alarm_heynoti_fini()
315 heynoti_detach_handler(fd);
316 heynoti_unsubscribe(fd, "setting_time_changed",
317 alarm_setting_time_changed_cb);