ee54353a24756c22f291b2c18b08fee9e61c3e65
[apps/home/quickpanel.git] / daemon / service / configuration.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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
18
19 #include <system_settings.h>
20 #include "common.h"
21 #include "configuration.h"
22
23 static struct _s_configuration_info {
24         int longpress_threshold;
25 } s_configuration_info = {
26         .longpress_threshold = SYSTEM_SETTINGS_TAP_AND_HOLD_DELAY_SHORT,
27 };
28
29 static void _conf_longpress_threshold_cb(system_settings_key_e key, void *user_data)
30 {
31         int delay = SYSTEM_SETTINGS_TAP_AND_HOLD_DELAY_SHORT; /* default 0.5 sec */
32
33         if (SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY == key) {
34                 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY, &delay) != 0) {
35                         ERR("Failed to get tap and hold delay");
36                         return;
37                 }
38                 if (s_configuration_info.longpress_threshold != delay) {
39                         s_configuration_info.longpress_threshold = delay;
40                 }
41
42                 DBG("Current tap and hold delay : [%d] msec", delay);
43         }
44 }
45
46 void quickpanel_service_conf_init(void *data) {
47
48         if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY,
49                         &s_configuration_info.longpress_threshold) != 0) {
50                 ERR("Failed to get tap and hold delay");
51         }
52
53         if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY,
54                         _conf_longpress_threshold_cb, NULL) != 0) {
55                 ERR("Failed to set tap and hold delay changed callback");
56         }
57 }
58
59 void quickpanel_service_conf_fini(void *data) {
60    if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY) != 0) {
61                 ERR("Failed to unset tab and hold delay changed callback");
62         }
63 }
64
65 double quickpanel_service_conf_longpress_time_get(void) {
66    return (double)(s_configuration_info.longpress_threshold)/(double)1000.0;
67 }