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 : %d\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 : %d\n", x);\
39 static struct _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 */
55 Ecore_Timer *volume_timer_popup_timer_get(void)
57 return s_info.popup_timer;
60 Ecore_Timer *volume_timer_slider_timer_get(void)
62 return s_info.slider_timer;
65 Ecore_Timer *volume_timer_su_timer_get(void)
67 return s_info.su_timer;
70 Ecore_Timer *volume_timer_sd_timer_get(void)
72 return s_info.sd_timer;
75 static Eina_Bool _timer_popup_cb(void *data)
77 if(VOLUME_ERROR_OK != volume_control_close())
79 _E("Failed to close volume");
81 if(VOLUME_ERROR_OK != volume_control_cache_flush())
83 _E("Failed to flush cache");
86 return ECORE_CALLBACK_CANCEL;
89 static Eina_Bool _timer_slider_cb(void *data)
91 Evas_Object *slider = volume_view_slider_get();
93 s_info.slider_timer = NULL;
94 return ECORE_CALLBACK_CANCEL;
99 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
100 _D("sound status : %d", sound);
103 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
104 _D("vibration : %d", vibration);
107 //sound_type_e sound_type = volume_sound_sound_manager_type_get();
108 sound_type_e sound_type = volume_control_sound_type_at_show_get();
109 _D("sound type at show : %d", sound_type);
111 val = elm_slider_value_get(slider);
113 _D("slider value : %d", (int)val);
116 if(sound_type != SOUND_TYPE_MEDIA){
117 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
118 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
120 volume_sound_is_vibration_set(EINA_FALSE);
122 if(VOLUME_ERROR_OK != volume_view_icon_set()) {
123 _E("Failed to set icon");
128 if(sound_type != SOUND_TYPE_MEDIA) {
129 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
132 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
133 volume_sound_vib_play();
136 elm_slider_value_set(slider, 0);
137 volume_sound_level_set(sound_type, 1);
140 return ECORE_CALLBACK_RENEW;
143 static Eina_Bool _timer_short_up_cb(void *data)
145 Evas_Object *win = volume_view_win_get();
148 _E("Window is NULL");
149 return ECORE_CALLBACK_CANCEL;
152 sound_type_e sound_type = volume_control_sound_type_at_show_get();
153 _D("sound type at show : %d", sound_type);
155 if(!evas_object_visible_get(win) && sound_type == SOUND_TYPE_RINGTONE)
157 _E("Window is hidden");
158 return ECORE_CALLBACK_CANCEL;
161 if(volume_view_is_slider_touching_get())
163 return ECORE_CALLBACK_RENEW;
166 ecore_timer_interval_set(s_info.su_timer, 0.1);
167 volume_timer_del(TYPE_TIMER_SLIDER);
169 int sound_step = volume_sound_step_get();
170 _D("sound step : %d", sound_step);
172 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
173 _D("sound status : %d", sound);
175 int val = volume_sound_level_get(sound_type);
178 _E("Failed to get volume level");
179 return ECORE_CALLBACK_CANCEL;
181 _D("sound value : %d", val);
183 if(val == sound_step)
185 _D("already sound value : %d", sound_step);
186 return ECORE_CALLBACK_RENEW;
189 if(!sound && sound_type == SOUND_TYPE_NOTIFICATION){
190 _D("Do not adjust the noti type in no sound.");
191 return ECORE_CALLBACK_RENEW;
194 if(!sound && sound_type == SOUND_TYPE_RINGTONE)
196 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
197 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
200 if(volume_sound_level_set(sound_type, val+1 > sound_step ? sound_step : val+1))
202 _D("[SAFETY_SOUND] release timer");
203 volume_timer_add(3.0, TYPE_TIMER_POPUP);
206 return ECORE_CALLBACK_RENEW;
209 static Eina_Bool _timer_short_down_cb(void *data)
211 Evas_Object *win = volume_view_win_get();
214 _E("Window is NULL");
215 return ECORE_CALLBACK_CANCEL;
218 sound_type_e sound_type = volume_control_sound_type_at_show_get();
219 _D("sound type at show : %d", sound_type);
221 if(!evas_object_visible_get(win) && sound_type == SOUND_TYPE_RINGTONE)
223 _E("Window is hidden");;
224 return ECORE_CALLBACK_CANCEL;
227 if(volume_view_is_slider_touching_get())
229 return ECORE_CALLBACK_RENEW;
232 ecore_timer_interval_set(s_info.sd_timer, 0.1);
233 volume_timer_del(TYPE_TIMER_SLIDER);
235 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
236 _D("sound status : %d", sound);
238 int val = volume_sound_level_get(sound_type);
241 _E("Failed to get volume level");
242 return ECORE_CALLBACK_CANCEL;
245 if(!sound && sound_type == SOUND_TYPE_NOTIFICATION){
246 _D("Do not adjust the noti type in no sound.");
247 return ECORE_CALLBACK_RENEW;
249 _D("sound value : %d", val);
253 if(sound && sound_type == SOUND_TYPE_RINGTONE)
255 _D("Set sound status to vibration in long press");
256 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
257 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
258 volume_sound_vib_play();
263 _D("already sound value : 0");
264 return ECORE_CALLBACK_RENEW;
267 if(sound || sound_type != SOUND_TYPE_RINGTONE)
269 volume_sound_level_set(sound_type, val-1 <= 0 ? 0 : val-1);
272 return ECORE_CALLBACK_RENEW;
275 void volume_timer_add(double time, volume_timer_type type)
277 if(type == TYPE_TIMER_POPUP)
279 ADD_TIMER(s_info.popup_timer, time, _timer_popup_cb, NULL);
281 else if(type == TYPE_TIMER_SLIDER)
283 ADD_TIMER(s_info.slider_timer, time, _timer_slider_cb, NULL);
285 else if(type == TYPE_TIMER_SD)
287 ADD_TIMER(s_info.sd_timer, time, _timer_short_down_cb, NULL);
289 else if(type == TYPE_TIMER_SU)
291 ADD_TIMER(s_info.su_timer, time, _timer_short_up_cb, NULL);
295 _E("Failed to get type : type error(%d)", type);
300 void volume_timer_del(volume_timer_type type)
302 if(type == TYPE_TIMER_POPUP)
304 DEL_TIMER(s_info.popup_timer);
306 else if(type == TYPE_TIMER_SLIDER)
308 DEL_TIMER(s_info.slider_timer);
310 else if(type == TYPE_TIMER_SD)
312 DEL_TIMER(s_info.sd_timer);
314 else if(type == TYPE_TIMER_SU)
316 DEL_TIMER(s_info.su_timer);
320 _E("Failed to get type : type error(%d)", type);