2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org
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.
19 #include "quickpanel-ui.h"
21 static player_h g_sound_player;
22 static Ecore_Timer *g_sound_player_timer;
24 static void _quickpanel_player_free_job_cb(void *data)
26 player_h sound_player = data;
27 player_state_e state = PLAYER_STATE_NONE;
29 retif(sound_player == NULL, , "invalid parameter");
31 if (player_get_state(sound_player, &state) == PLAYER_ERROR_NONE) {
33 INFO("the state of sound player %d", state);
35 if (state == PLAYER_STATE_PLAYING) {
36 player_stop(sound_player);
37 player_unprepare(sound_player);
39 if (state == PLAYER_STATE_READY) {
40 player_unprepare(sound_player);
43 player_destroy(sound_player);
46 static void _quickpanel_player_free(player_h *sound_player)
48 retif(sound_player == NULL, , "invalid parameter");
49 retif(*sound_player == NULL, , "invalid parameter");
51 ecore_job_add(_quickpanel_player_free_job_cb, *sound_player);
56 _quickpanel_player_del_timeout_timer(void)
58 if (g_sound_player_timer) {
59 ecore_timer_del(g_sound_player_timer);
60 g_sound_player_timer = NULL;
64 static Eina_Bool _quickpanel_player_timeout_cb(void *data)
66 g_sound_player_timer = NULL;
68 retif(data == NULL, ECORE_CALLBACK_CANCEL, "invalid parameter");
69 player_h *sound_player = data;
71 _quickpanel_player_free(sound_player);
72 g_sound_player_timer = NULL;
74 return ECORE_CALLBACK_CANCEL;
78 _quickpanel_player_completed_cb(void *user_data)
80 retif(user_data == NULL, , "invalid parameter");
81 player_h *sound_player = user_data;
83 _quickpanel_player_del_timeout_timer();
84 _quickpanel_player_free(sound_player);
88 _quickpanel_player_interrupted_cb(player_interrupted_code_e code, void *user_data)
90 retif(user_data == NULL, , "invalid parameter");
91 player_h *sound_player = user_data;
93 _quickpanel_player_del_timeout_timer();
94 _quickpanel_player_free(sound_player);
98 _quickpanel_player_error_cb(int error_code, void *user_data)
100 retif(user_data == NULL, , "invalid parameter");
101 player_h *sound_player = user_data;
103 _quickpanel_player_del_timeout_timer();
104 _quickpanel_player_free(sound_player);
107 HAPI void quickpanel_player_play(sound_type_e sound_type, const char *sound_file)
109 player_h *sound_player = &g_sound_player;
111 int ret = PLAYER_ERROR_NONE;
112 player_state_e state = PLAYER_STATE_NONE;
114 _quickpanel_player_del_timeout_timer();
116 if (*sound_player != NULL) {
117 _quickpanel_player_free(sound_player);
120 ret = player_create(sound_player);
121 if (ret != PLAYER_ERROR_NONE) {
122 ERR("creating the player handle failed[%d]", ret);
123 player_destroy(*sound_player);
126 ret = player_set_sound_type(*sound_player, sound_type);
127 if (ret != PLAYER_ERROR_NONE) {
128 ERR("player_set_sound_type() ERR: %x!!!!", ret);
129 _quickpanel_player_free(sound_player);
133 player_get_state(*sound_player, &state);
134 if (state > PLAYER_STATE_READY) {
135 _quickpanel_player_free(sound_player);
139 ret = player_set_uri(*sound_player, sound_file);
140 if (ret != PLAYER_ERROR_NONE) {
141 ERR("set attribute---profile_uri[%d]", ret);
142 _quickpanel_player_free(sound_player);
146 ret = player_prepare(*sound_player);
147 if (ret != PLAYER_ERROR_NONE) {
148 ERR("realizing the player handle failed[%d]", ret);
149 _quickpanel_player_free(sound_player);
153 player_get_state(*sound_player, &state);
154 if (state != PLAYER_STATE_READY) {
155 ERR("state of player is invalid %d", state);
156 _quickpanel_player_free(sound_player);
160 /* register callback */
161 ret = player_set_completed_cb(*sound_player, _quickpanel_player_completed_cb, sound_player);
162 if (ret != PLAYER_ERROR_NONE) {
163 ERR("player_set_completed_cb() ERR: %x!!!!", ret);
164 _quickpanel_player_free(sound_player);
168 ret = player_set_interrupted_cb(*sound_player, _quickpanel_player_interrupted_cb, sound_player);
169 if (ret != PLAYER_ERROR_NONE) {
170 _quickpanel_player_free(sound_player);
174 ret = player_set_error_cb(*sound_player, _quickpanel_player_error_cb, sound_player);
175 if (ret != PLAYER_ERROR_NONE) {
176 _quickpanel_player_free(sound_player);
180 ret = player_start(*sound_player);
181 if (ret != PLAYER_ERROR_NONE) { /* if directly return retor.. */
182 ERR("player_start [%d]", ret);
183 _quickpanel_player_free(sound_player);
187 g_sound_player_timer = ecore_timer_add(QP_PLAY_DURATION_LIMIT,
188 _quickpanel_player_timeout_cb, sound_player);
191 HAPI void quickpanel_player_stop(void)
193 _quickpanel_player_del_timeout_timer();
195 if (g_sound_player != NULL) {
196 _quickpanel_player_free(&g_sound_player);
200 HAPI int quickpanel_is_sound_enabled(void)
204 #ifdef VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS
205 int snd_disabled_status = 0;
207 vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TURN_OFF_ALL_SOUNDS, &snd_disabled_status);
208 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status);
210 if (snd_disabled_status == 0 && snd_status == 1) {
214 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status);
216 if (snd_status == 1) {
224 HAPI int quickpanel_is_vib_enabled(void)
228 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vib_status);
236 HAPI void quickpanel_play_feedback(void)
238 int snd_enabled = quickpanel_is_sound_enabled();
239 int vib_enabled = quickpanel_is_vib_enabled();
241 if (snd_enabled == 1) {
242 feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TOUCH_TAP);
243 } else if (vib_enabled == 1) {
244 feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_TOUCH_TAP);
248 HAPI int quickpanel_set_mute_toggle(void)
252 if (quickpanel_is_sound_enabled() == 1 ||
253 quickpanel_is_vib_enabled() == 1) {
254 ret = vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 0);
255 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
257 ret = vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, 0);
258 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
262 ret = vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, 1);
263 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
265 ret = vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, 0);
266 msgif(ret != 0, "failed to set VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");