2 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vconf-keys.h>
21 #include "_util_log.h"
27 #define DEL_TIMER(x) \
29 _D("DELTIMER x : %p\n", x);\
33 #define ADD_TIMER(x, time, _timer_cb, data) \
34 if(x != NULL) DEL_TIMER(x); \
35 x = ecore_timer_add(time, _timer_cb, data);\
36 _D("ADDTIMER x : %p\n", x);\
39 struct _timer_s_info {
40 Ecore_Timer *popup_timer; /* pop-up timer */
41 Ecore_Timer *slider_timer; /* slider timer */
42 Ecore_Timer *su_timer; /* short up timer */
43 Ecore_Timer *sd_timer; /* short down timer */
44 Ecore_Timer *lu_timer; /* long up timer */
45 Ecore_Timer *ld_timer; /* long down timer */
46 Ecore_Timer *bt_timer; /* long down timer */
49 static struct _timer_s_info timer_info = {
59 static Eina_Bool _timer_short_down_cb(void *data);
60 static Eina_Bool _timer_short_up_cb(void *data);
61 static Eina_Bool _timer_slider_cb(void *data);
62 static Eina_Bool _timer_popup_cb(void *data);
63 static Eina_Bool _timer_bt_cb(void *data);
65 Ecore_Timer *volume_timer_bt_timer_get(void)
67 return timer_info.bt_timer;
70 Ecore_Timer *volume_timer_popup_timer_get(void)
72 return timer_info.popup_timer;
75 Ecore_Timer *volume_timer_slider_timer_get(void)
77 return timer_info.slider_timer;
80 Ecore_Timer *volume_timer_su_timer_get(void)
82 return timer_info.su_timer;
85 Ecore_Timer *volume_timer_sd_timer_get(void)
87 return timer_info.sd_timer;
90 void volume_timer_add(double time, volume_timer_type type)
92 _D("VOLUME TIMER ADD");
93 if (type == TYPE_TIMER_POPUP) {
94 ADD_TIMER(timer_info.popup_timer, time, _timer_popup_cb, NULL);
95 } else if (type == TYPE_TIMER_SLIDER) {
96 ADD_TIMER(timer_info.slider_timer, time, _timer_slider_cb, NULL);
97 } else if (type == TYPE_TIMER_SD) {
98 ADD_TIMER(timer_info.sd_timer, time, _timer_short_down_cb, NULL);
99 } else if (type == TYPE_TIMER_SU) {
100 ADD_TIMER(timer_info.su_timer, time, _timer_short_up_cb, NULL);
101 } else if (type == TYPE_TIMER_BT) {
102 ADD_TIMER(timer_info.bt_timer, time, _timer_bt_cb, NULL);
104 _E("Failed to get type : type error(%d)", type);
109 void volume_timer_del(volume_timer_type type)
111 if (type == TYPE_TIMER_POPUP) {
112 DEL_TIMER(timer_info.popup_timer);
113 } else if (type == TYPE_TIMER_SLIDER) {
114 DEL_TIMER(timer_info.slider_timer);
115 } else if (type == TYPE_TIMER_SD) {
116 DEL_TIMER(timer_info.sd_timer);
117 } else if (type == TYPE_TIMER_SU) {
118 DEL_TIMER(timer_info.su_timer);
119 } else if (type == TYPE_TIMER_BT) {
120 DEL_TIMER(timer_info.bt_timer);
122 _E("Failed to get type : type error(%d)", type);
127 static Eina_Bool _timer_bt_cb(void *data)
129 if (VOLUME_ERROR_OK != volume_control_close_bt_display())
130 _E("Failed to close volume");
131 if (VOLUME_ERROR_OK != volume_control_cache_flush())
132 _E("Failed to flush cache");
134 return ECORE_CALLBACK_CANCEL;
137 static Eina_Bool _timer_popup_cb(void *data)
139 if (VOLUME_ERROR_OK != volume_control_hide_view())
140 _E("Failed to close volume");
141 if (VOLUME_ERROR_OK != volume_control_cache_flush())
142 _E("Failed to flush cache");
144 return ECORE_CALLBACK_CANCEL;
147 static Eina_Bool _timer_slider_cb(void *data)
149 Evas_Object *slider = volume_view_slider_get();
150 if (slider == NULL) {
151 timer_info.slider_timer = NULL;
152 return ECORE_CALLBACK_CANCEL;
157 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
158 _D("sound status : %d", sound);
161 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
162 _D("vibration : %d", vibration);
165 sound_type_e sound_type = volume_control_get_sound_type_at_show();
166 _D("sound type at show : %d", sound_type);
168 val = elm_slider_value_get(slider);
170 _D("slider value : %d", (int)val);
173 if (sound_type != SOUND_TYPE_MEDIA) {
174 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
175 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
177 volume_sound_is_vibration_set(EINA_FALSE);
180 if (sound_type != SOUND_TYPE_MEDIA) {
181 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
184 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
185 volume_sound_vib_play();
188 elm_slider_value_set(slider, 0);
189 volume_sound_level_set(sound_type, 1);
192 return ECORE_CALLBACK_RENEW;
195 static Eina_Bool _timer_short_up_cb(void *data)
197 _D("volume is in LongPress");
198 Evas_Object *win = volume_view_win_get();
200 _E("Window is NULL");
201 return ECORE_CALLBACK_CANCEL;
204 sound_type_e sound_type = volume_control_get_sound_type_at_show();
205 _D("sound type at show : %d", sound_type);
207 if (!evas_object_visible_get(win) && sound_type == SOUND_TYPE_RINGTONE) {
208 _E("Window is hidden");
209 return ECORE_CALLBACK_CANCEL;
212 if (volume_view_is_slider_touching_get())
213 return ECORE_CALLBACK_RENEW;
215 ecore_timer_interval_set(timer_info.su_timer, 0.1);
216 volume_timer_del(TYPE_TIMER_SLIDER);
218 int sound_step = volume_sound_step_get();
219 _D("sound step : %d", sound_step);
221 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
222 _D("sound status : %d", sound);
224 int val = volume_sound_level_get(sound_type);
226 _E("Failed to get volume level");
227 return ECORE_CALLBACK_CANCEL;
229 _D("sound value : %d", val);
231 if (val == sound_step) {
232 _D("already sound value : %d", sound_step);
233 return ECORE_CALLBACK_RENEW;
236 if (!sound && sound_type == SOUND_TYPE_NOTIFICATION) {
237 _D("Do not adjust the noti type in no sound.");
238 return ECORE_CALLBACK_RENEW;
241 if (!sound && sound_type == SOUND_TYPE_RINGTONE) {
242 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
243 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
246 if (volume_sound_level_set(sound_type, val+1 > sound_step ? sound_step : val+1)) {
247 _D("[SAFETY_SOUND] release timer");
248 volume_timer_add(3.0, TYPE_TIMER_POPUP);
250 val = volume_sound_level_get(sound_type);
252 return ECORE_CALLBACK_RENEW;
255 static Eina_Bool _timer_short_down_cb(void *data)
257 Evas_Object *win = volume_view_win_get();
259 _E("Window is NULL");
260 return ECORE_CALLBACK_CANCEL;
263 sound_type_e sound_type = volume_control_get_sound_type_at_show();
264 _D("sound type at show : %d", sound_type);
266 if (!evas_object_visible_get(win) && sound_type == SOUND_TYPE_RINGTONE) {
267 _E("Window is hidden");;
268 return ECORE_CALLBACK_CANCEL;
271 if (volume_view_is_slider_touching_get())
272 return ECORE_CALLBACK_RENEW;
274 ecore_timer_interval_set(timer_info.sd_timer, 0.1);
275 volume_timer_del(TYPE_TIMER_SLIDER);
277 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
278 _D("sound status : %d", sound);
280 int val = volume_sound_level_get(sound_type);
282 _E("Failed to get volume level");
283 return ECORE_CALLBACK_CANCEL;
286 if (!sound && sound_type == SOUND_TYPE_NOTIFICATION) {
287 _D("Do not adjust the noti type in no sound.");
288 return ECORE_CALLBACK_RENEW;
290 _D("sound value : %d", val);
293 if (sound && sound_type == SOUND_TYPE_RINGTONE) {
294 _D("Set sound status to vibration in long press");
295 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
296 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
297 volume_sound_vib_play();
300 _D("already sound value : 0");
301 return ECORE_CALLBACK_RENEW;
304 if (sound || sound_type != SOUND_TYPE_RINGTONE)
305 volume_sound_level_set(sound_type, val-1 <= 0 ? 0 : val-1);
307 return ECORE_CALLBACK_RENEW;