Add privilege
[apps/core/preloaded/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 #ifdef HAVE_X
27         .longpress_threshold = SYSTEM_SETTINGS_TAP_AND_HOLD_DELAY_SHORT,
28 #else
29         .longpress_threshold = 0,
30 #endif
31 };
32
33 static void _conf_longpress_threshold_cb(system_settings_key_e key, void *user_data)
34 {
35 #ifdef HAVE_X
36         int delay = SYSTEM_SETTINGS_TAP_AND_HOLD_DELAY_SHORT; /* default 0.5 sec */
37 #else
38         int delay = 0.5;
39 #endif
40
41 #ifdef HAVE_X
42         if (SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY == key)
43 #endif
44         {
45 #ifdef HAVE_X
46                 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY, &delay) != 0) {
47                         ERR("Failed to get tap and hold delay");
48                         return;
49                 }
50 #endif
51                 if (s_configuration_info.longpress_threshold != delay) {
52                         s_configuration_info.longpress_threshold = delay;
53                 }
54
55                 DBG("Current tap and hold delay : [%d] msec", delay);
56         }
57 }
58
59 HAPI void quickpanel_conf_init(void *data)
60 {
61 #ifdef HAVE_X
62         if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY,
63                         &s_configuration_info.longpress_threshold) != 0) {
64                 ERR("Failed to get tap and hold delay");
65         }
66
67         if (system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY,
68                         _conf_longpress_threshold_cb, NULL) != 0) {
69                 ERR("Failed to set tap and hold delay changed callback");
70         }
71 #endif
72 }
73
74 HAPI void quickpanel_conf_fini(void *data)
75 {
76 #ifdef HAVE_X
77    if (system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_TAP_AND_HOLD_DELAY) != 0) {
78                 ERR("Failed to unset tab and hold delay changed callback");
79         }
80 #endif
81 }
82
83 HAPI double quickpanel_conf_longpress_time_get(void)
84 {
85    return (double)(s_configuration_info.longpress_threshold)/(double)1000.0;
86 }