|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class to handle email sound playing. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include <ProfileEngineDomainCRKeys.h> |
|
20 #include <AudioPreference.h> |
|
21 #include <MProfileEngine.h> |
|
22 #include <MProfile.h> |
|
23 #include <MProfileTones.h> |
|
24 #include <MProfileExtraTones.h> |
|
25 #include <TProfileToneSettings.h> |
|
26 #include <CProfileChangeNotifyHandler.h> |
|
27 #include <bautils.h> |
|
28 #include <coreapplicationuisdomainpskeys.h> |
|
29 |
|
30 #include "emailsoundhandler.h" |
|
31 #include "emailsoundstates.h" |
|
32 #include "cmailhandlerpluginpanic.h" |
|
33 |
|
34 _LIT( KDefaultEmailTone, "z:\\data\\sounds\\digital\\Message 1.aac"); |
|
35 _LIT8( KEmailBeepSequence, "\x2\x4a\x3a\x51\x9\x95\x95\xc0\x4\x0\xb\x1c\x41\x8d\x51\xa8\x0\x0" ); |
|
36 _LIT( KProfileSilentTone, "Z:\\resource\\No_Sound.wav" ); |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CFSMailSoundHandler::DriveStateChangedL(TBool /*aState*/) |
|
43 { |
|
44 //causes a reload of soundpayer |
|
45 iState->ProfileChanged(); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CFSMailSoundHandler* CFSMailSoundHandler::NewL( |
|
53 MFSNotificationHandlerMgr& aOwner ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 CFSMailSoundHandler* self = |
|
57 new( ELeave ) CFSMailSoundHandler( aOwner ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 void CFSMailSoundHandler::ConstructL() |
|
69 { |
|
70 FUNC_LOG; |
|
71 CFSNotificationHandlerBase::ConstructL(); |
|
72 |
|
73 SetObserving(ETrue); |
|
74 |
|
75 iProfileEngine = CreateProfileEngineL(); |
|
76 iHandler = CProfileChangeNotifyHandler::NewL( this ); |
|
77 iMsgToneSubscriber = CPSSubscriber::NewL( |
|
78 *this, KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit ); |
|
79 iDriveObserver = CDriveObserver::NewL( *this ); |
|
80 |
|
81 // After sound state initialization iState is valid pointer until |
|
82 // CEmailSoundState::Uninitialize is called in the destructor. |
|
83 CEmailSoundState::InitializeL(this); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CFSMailSoundHandler::CFSMailSoundHandler( MFSNotificationHandlerMgr& aOwner ) |
|
91 : CFSNotificationHandlerBase(aOwner) |
|
92 { |
|
93 FUNC_LOG; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CFSMailSoundHandler::~CFSMailSoundHandler() |
|
101 { |
|
102 FUNC_LOG; |
|
103 if (iProfileEngine) |
|
104 { |
|
105 iProfileEngine->Release(); |
|
106 iProfileEngine = NULL; |
|
107 } |
|
108 delete iHandler; |
|
109 ReleaseAudioPlayer(); |
|
110 delete iDriveObserver; |
|
111 delete iMsgToneSubscriber; |
|
112 CEmailSoundState::Uninitialize(iState); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // HandleEvent is implemented also here because we need to check the |
|
117 // Home Screen status. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CFSMailSoundHandler::HandleEventL(TFSMailEvent aEvent, |
|
121 TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2, TAny* aParam3) |
|
122 { |
|
123 FUNC_LOG; |
|
124 // assumption: base class handles event only if it is TFSEventNewMail |
|
125 CFSNotificationHandlerBase::HandleEventL( aEvent, |
|
126 aMailbox, |
|
127 aParam1, |
|
128 aParam2, |
|
129 aParam3 ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CFSMailSoundHandler::SetState(CEmailSoundState* aNewState) |
|
137 { |
|
138 FUNC_LOG; |
|
139 INFO_1( "email sound state => %d", (TInt) aNewState ) |
|
140 iState = aNewState; |
|
141 #ifdef __HANDLER_TEST |
|
142 // for module testing |
|
143 if ( iTesterReqStatus ) |
|
144 { |
|
145 TRequestStatus*& status = iTesterReqStatus; |
|
146 User::RequestComplete( status, KErrNone ); |
|
147 iTesterReqStatus = NULL; |
|
148 } |
|
149 #endif |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // Returns audio player utility |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 CMdaAudioPlayerUtility* CFSMailSoundHandler::AudioPlayer() |
|
157 { |
|
158 return iAudioPlayer; |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CFSMailSoundHandler::HandleActiveProfileChangeL - Callback from end of |
|
163 // play from Audio player. |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CFSMailSoundHandler::HandleActiveProfileEventL(TProfileEvent /*aPE*/, |
|
167 TInt /*aId*/ ) |
|
168 { |
|
169 FUNC_LOG; |
|
170 // iState should never be null |
|
171 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
172 iState->ProfileChanged(); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CFSMailSoundHandler::MapcInitComplete - Callback from audio player |
|
177 // initialization. |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CFSMailSoundHandler::MapcInitComplete( |
|
181 TInt aError, |
|
182 const TTimeIntervalMicroSeconds& /*aInterval*/) |
|
183 { |
|
184 FUNC_LOG; |
|
185 // iState should never be null |
|
186 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
187 if ( aError ) |
|
188 { |
|
189 delete iAudioPlayer; |
|
190 iAudioPlayer = NULL; |
|
191 iState->AudioInitFailed(); |
|
192 } |
|
193 else |
|
194 { |
|
195 iState->AudioInitCompleted(); |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CFSMailSoundHandler::MapcPlayComplete - Callback from end of play from |
|
201 // Audio player. |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CFSMailSoundHandler::MapcPlayComplete(TInt /*aError*/) |
|
205 { |
|
206 FUNC_LOG; |
|
207 // iState should never be null |
|
208 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
209 // error is ignored because there's no corrective action, next play |
|
210 // request triggers re-initialization of tone. |
|
211 iState->AudioPlayCompleted(); |
|
212 iMsgToneSubscriber->Cancel(); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CFSMailSoundHandler::RecreateAudioPlayerL |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CFSMailSoundHandler::RecreateAudioPlayerL() |
|
220 { |
|
221 FUNC_LOG; |
|
222 delete iAudioPlayer; |
|
223 iAudioPlayer = NULL; |
|
224 |
|
225 MProfile* profile = iProfileEngine->ActiveProfileL(); |
|
226 CleanupReleasePushL(*profile); |
|
227 |
|
228 TBool vibraEnabled = profile->ProfileTones().ToneSettings().iVibratingAlert; |
|
229 TBool mailVibraEnabled = vibraEnabled & profile->ProfileTones().ToneSettings().iEmailVibratingAlert; |
|
230 |
|
231 TInt preference = KAudioPrefNewSpecialMessage; |
|
232 if ( !mailVibraEnabled ) |
|
233 { |
|
234 preference = KAudioPrefNewEmail; // Used in TB.92 only! In 10.X adaptation will manage vibra setting itself. |
|
235 } |
|
236 |
|
237 if (IsBeepOnceSetL(*profile)) |
|
238 { |
|
239 |
|
240 // create audio player based on hard coded sequence |
|
241 // (Platform does not offer any "play platform-wide beep" service) |
|
242 iAudioPlayer = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL( |
|
243 KEmailBeepSequence(), |
|
244 *this, |
|
245 KAudioPriorityRecvMsg, |
|
246 preference ); |
|
247 } |
|
248 else |
|
249 { |
|
250 // Otherwise loading tone from file |
|
251 TFileName fileToPlay = profile->ProfileExtraTones().EmailAlertTone(); |
|
252 |
|
253 if ( (fileToPlay.Compare(KProfileSilentTone) == 0) && |
|
254 (!vibraEnabled) ) |
|
255 { |
|
256 // Play the silent tone with KAudioPrefNewSpecialMessage |
|
257 // in order to avoid the distortion |
|
258 // KAudioPrefNewSpecialMessage does not play vibra if KProfileSilentTone is played |
|
259 preference = KAudioPrefNewSpecialMessage; |
|
260 } |
|
261 RFs fs; |
|
262 TInt err = fs.Connect(); |
|
263 CleanupClosePushL( fs ); |
|
264 |
|
265 if ( err == KErrNone ) |
|
266 { |
|
267 TChar chr = fileToPlay[0]; |
|
268 TInt drive; |
|
269 fs.CharToDrive( chr, drive ); |
|
270 |
|
271 //we'll observe any drive where the tone is just because |
|
272 //the drive letter of the memory card can |
|
273 //vary from product to product. |
|
274 iDriveObserver->SetDriveL( (TDriveNumber)drive ); |
|
275 |
|
276 iDriveObserver->WaitForChange(); |
|
277 |
|
278 //test does the file exist |
|
279 if ( !BaflUtils::FileExists( fs, fileToPlay ) ) |
|
280 { |
|
281 //if the file set in profile does not exist, we use default |
|
282 fileToPlay.Zero(); |
|
283 fileToPlay.Append( KDefaultEmailTone ); |
|
284 } |
|
285 |
|
286 CleanupStack::PopAndDestroy( &fs ); |
|
287 } |
|
288 |
|
289 iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
290 fileToPlay, |
|
291 *this, |
|
292 KAudioPriorityRecvMsg, |
|
293 static_cast<TMdaPriorityPreference>( preference ) ); |
|
294 } |
|
295 CleanupStack::PopAndDestroy( profile ); |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // Deletes audio player utility |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CFSMailSoundHandler::ReleaseAudioPlayer() |
|
303 { |
|
304 FUNC_LOG; |
|
305 delete iAudioPlayer; |
|
306 iAudioPlayer = NULL; |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // Returns profile engine |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 MProfileEngine& CFSMailSoundHandler::ProfileEngine() const |
|
314 { |
|
315 return *iProfileEngine; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // Playes 'new email' tone |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CFSMailSoundHandler::TurnNotificationOn() |
|
323 { |
|
324 FUNC_LOG; |
|
325 // iState should never be null |
|
326 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
327 iMsgToneSubscriber->Subscribe(); |
|
328 iState->PlayTone(); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // Stops playback |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void CFSMailSoundHandler::TurnNotificationOff() |
|
336 { |
|
337 FUNC_LOG; |
|
338 // iState should never be null |
|
339 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
340 iState->StopTone(); |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // IsBeepOnceSetL |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 TBool CFSMailSoundHandler::IsBeepOnceSetL(const MProfile& aProfile) const |
|
348 { |
|
349 FUNC_LOG; |
|
350 // default to false |
|
351 TBool ret = EFalse; |
|
352 |
|
353 // get tone settings |
|
354 const TProfileToneSettings& toneSettings = aProfile.ProfileTones().ToneSettings(); |
|
355 |
|
356 // if beep-once is set, set return value to ETrue |
|
357 if (toneSettings.iRingingType == EProfileRingingTypeBeepOnce) |
|
358 { |
|
359 ret = ETrue; |
|
360 } |
|
361 |
|
362 return ret; |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // HandlePropertyChangedL |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 void CFSMailSoundHandler::HandlePropertyChangedL( const TUid& aCategory, TInt aKey ) |
|
370 { |
|
371 FUNC_LOG; |
|
372 TInt state(0); |
|
373 |
|
374 // |
|
375 // Handling the event of user pressing a key while "msg received" -tone is playing |
|
376 // |
|
377 if ( aCategory == KPSUidCoreApplicationUIs && aKey == KCoreAppUIsMessageToneQuit ) |
|
378 { |
|
379 RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, state ); |
|
380 INFO_1("KCoreAppUIsMessageToneQuit == %d" , state ); |
|
381 if (state == ECoreAppUIsStopTonePlaying) |
|
382 { |
|
383 iState->StopTone(); |
|
384 iMsgToneSubscriber->Cancel(); |
|
385 } |
|
386 } |
|
387 |
|
388 // |
|
389 // Handling the event of <other PubSub event can be added here> |
|
390 // |
|
391 } |