|
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: This class gives interface to play IM message alert. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cimalertmanager.h" |
|
20 #include "imalertdebugprint.h" |
|
21 #include "mimalertmanagerobserver.h" |
|
22 #include "mimalertnotifierinterface.h" |
|
23 #include "imalertnotifierfactory.h" |
|
24 |
|
25 #include <MProfileEngine.h> |
|
26 #include <pathinfo.h> |
|
27 #include <mda/common/resource.h> |
|
28 #include <AudioPreference.h> |
|
29 #include <bautils.h> |
|
30 #include <hwrmvibrasdkcrkeys.h> |
|
31 #include <coreapplicationuisdomainpskeys.h> |
|
32 #include <ProfileEngineSDKCRKeys.h> |
|
33 #include <MProfileTones.h> |
|
34 #include <TProfileToneSettings.h> |
|
35 #include <MProfile.h> |
|
36 #include <hwrmvibra.h> |
|
37 |
|
38 //to get message tone file |
|
39 #include <cvimpstsettingsstore.h> |
|
40 |
|
41 |
|
42 // CONSTANTS |
|
43 const TInt KMinVolumeLevel( 1 ); |
|
44 const TInt KMaxVolumeLevel( 10 ); |
|
45 const TInt KToneInterval( 1000000 ); // 1 second pause between tones |
|
46 |
|
47 _LIT( KChatRngMimeType, "application/vnd.nokia.ringing-tone" ); |
|
48 _LIT( KBeepOnceSound, "beep.rng" ); |
|
49 _LIT( KProfileSilentTone, "No_Sound.wav" ); |
|
50 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CIMAlertManager::CIMAlertManager |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CIMAlertManager::CIMAlertManager() |
|
61 : iAudioPlayerStatus( EAudioPlayerNotCreated ), |
|
62 iTonePlayerStatus( EAudioPlayerNotCreated ), |
|
63 iIsPlayingDefaultIMSound( EFalse ) |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CIMAlertManager::ConstructL |
|
69 // (other items were commented in a header). |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 |
|
73 void CIMAlertManager::ConstructL() |
|
74 { |
|
75 CHAT_DP_FUNC_ENTER("ConstructL"); |
|
76 iProfileApi = CreateProfileEngineL(); |
|
77 |
|
78 User::LeaveIfError( iFs.Connect() ); |
|
79 |
|
80 CHAT_DP_TXT("CMdaAudioPlayerUtility::NewL()" ); |
|
81 |
|
82 iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this ); |
|
83 iAudioPlayerStatus = EAudioPlayerReady; |
|
84 |
|
85 CHAT_DP_TXT("CMdaAudioToneUtility::NewL()" ); |
|
86 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
87 iTonePlayerStatus = EAudioPlayerReady; |
|
88 |
|
89 iProfilesRepository = CRepository::NewL( KCRUidProfileEngine ); |
|
90 iVibraRepository = CRepository::NewL( KCRUidVibraCtrl ); |
|
91 |
|
92 // Get initial settings from active profile |
|
93 iRingingVolumeNotifyHandler = CCenRepNotifyHandler::NewL( *this, |
|
94 *iProfilesRepository, |
|
95 CCenRepNotifyHandler::EIntKey, |
|
96 KProEngActiveRingingVolume ); |
|
97 iRingingVolumeNotifyHandler->StartListeningL(); |
|
98 |
|
99 |
|
100 iRingingTypeNotifyHandler = CCenRepNotifyHandler::NewL( *this, |
|
101 *iProfilesRepository, |
|
102 CCenRepNotifyHandler::EIntKey, |
|
103 KProEngActiveRingingType ); |
|
104 iRingingTypeNotifyHandler->StartListeningL(); |
|
105 |
|
106 |
|
107 iVibraNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iVibraRepository, |
|
108 CCenRepNotifyHandler::EIntKey, |
|
109 KVibraCtrlProfileVibraEnabled ); |
|
110 iVibraNotifyHandler->StartListeningL(); |
|
111 |
|
112 User::LeaveIfError( iProfilesRepository->Get( KProEngActiveRingingVolume, |
|
113 iRingingVolume ) ); |
|
114 |
|
115 User::LeaveIfError( iVibraRepository->Get( KVibraCtrlProfileVibraEnabled, |
|
116 iVibra ) ); |
|
117 |
|
118 User::LeaveIfError( iApaSession.Connect() ); |
|
119 |
|
120 // register for changes in message Tone quitting |
|
121 iNotifierAPI = IMAlertNotifierFactory::CreateNotifierL( this ); |
|
122 iNotifierAPI->ListenKeyChanges( MIMAlertNotifierInterface::EMSGToneQuitKey ); |
|
123 |
|
124 iToneFileName = HBufC::NewL( KMaxPath ); |
|
125 |
|
126 // Get path to beep once ringing tone, first check simple sound folder. |
|
127 TFileName beepFile = PathInfo::RomRootPath(); |
|
128 beepFile.Append( PathInfo::SimpleSoundsPath() ); |
|
129 beepFile.Append( KBeepOnceSound ); |
|
130 RFile file; |
|
131 TInt openErr = file.Open( iFs, beepFile, EFileRead ); |
|
132 file.Close(); |
|
133 |
|
134 if ( openErr == KErrNotFound || openErr == KErrPathNotFound ) |
|
135 { |
|
136 // Check digital sounds folder |
|
137 beepFile.Zero(); |
|
138 beepFile.Append( PathInfo::RomRootPath() ); |
|
139 beepFile.Append( PathInfo::DigitalSoundsPath() ); |
|
140 beepFile.Append( KBeepOnceSound ); |
|
141 openErr = file.Open( iFs, beepFile, EFileRead ); |
|
142 file.Close(); |
|
143 } |
|
144 |
|
145 CHAT_DP( D_PLAIN_LIT( "CIMAlertManager::ConstructL() openErr = %d" ), openErr ); |
|
146 |
|
147 if ( openErr == KErrNone ) |
|
148 { |
|
149 iBeepRingingTone = beepFile.AllocL(); |
|
150 TPtrC ptr = iBeepRingingTone->Des(); |
|
151 CHAT_DP( D_PLAIN_LIT( "CIMAlertManager::ConstructL() iBeepRingingTone = %S" ), &ptr ); |
|
152 } |
|
153 else |
|
154 { |
|
155 HandleError( openErr ); |
|
156 } |
|
157 |
|
158 // get active ringing type, change events come to us later... |
|
159 iActiveProfile = iProfileApi->ActiveProfileL(); |
|
160 const MProfileTones& profileTones = iActiveProfile->ProfileTones(); |
|
161 const TProfileToneSettings& profileSettings = profileTones.ToneSettings(); |
|
162 iRingingType = profileSettings.iRingingType; |
|
163 iActiveProfile->Release(); |
|
164 iActiveProfile = NULL; // prevent further usage |
|
165 // after this, active ringing type changes are notified via the cenrep |
|
166 // notify handler callback through HandleNotifyInt |
|
167 |
|
168 // TRAP to catch leaves, leaves with KErrNotSupported if vibra |
|
169 // is not supported |
|
170 TRAPD( err, iVibrator = CHWRMVibra::NewL() ); |
|
171 if ( err == KErrNotSupported ) |
|
172 { |
|
173 // Make sure it's NULL |
|
174 iVibrator = NULL; |
|
175 } |
|
176 else |
|
177 { |
|
178 // Leave with other errors e.g. KErrNoMemory |
|
179 User::LeaveIfError( err ); |
|
180 } |
|
181 iSettingsStore = CVIMPSTSettingsStore::NewL(); |
|
182 CHAT_DP_FUNC_DONE("ConstructL"); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CIMAlertManager::NewL |
|
187 // (other items were commented in a header). |
|
188 // --------------------------------------------------------- |
|
189 EXPORT_C CIMAlertManager* CIMAlertManager::NewL() |
|
190 { |
|
191 CIMAlertManager* self = new( ELeave ) CIMAlertManager(); |
|
192 |
|
193 CleanupStack::PushL( self ); |
|
194 self->ConstructL(); |
|
195 CleanupStack::Pop( self ); |
|
196 |
|
197 return self; |
|
198 } |
|
199 |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CIMAlertManager::~CIMAlertManager |
|
203 // (other items were commented in a header). |
|
204 // --------------------------------------------------------- |
|
205 CIMAlertManager::~CIMAlertManager() |
|
206 { |
|
207 CHAT_DP_FUNC_ENTER("~CIMAlertManager"); |
|
208 Stop(); // Stops possible playback |
|
209 |
|
210 if ( iActiveProfile ) |
|
211 { |
|
212 iActiveProfile->Release(); |
|
213 iActiveProfile = NULL; // prevent further usage |
|
214 } |
|
215 |
|
216 if ( iProfileApi ) |
|
217 { |
|
218 iProfileApi->Release(); |
|
219 iProfileApi = NULL; |
|
220 } |
|
221 |
|
222 if ( iVibraNotifyHandler ) |
|
223 { |
|
224 iVibraNotifyHandler->StopListening(); |
|
225 delete iVibraNotifyHandler; |
|
226 iVibraNotifyHandler = NULL; |
|
227 } |
|
228 |
|
229 if ( iRingingTypeNotifyHandler ) |
|
230 { |
|
231 iRingingTypeNotifyHandler->StopListening(); |
|
232 delete iRingingTypeNotifyHandler; |
|
233 iRingingTypeNotifyHandler = NULL; |
|
234 } |
|
235 |
|
236 |
|
237 if ( iRingingVolumeNotifyHandler ) |
|
238 { |
|
239 iRingingVolumeNotifyHandler->StopListening(); |
|
240 delete iRingingVolumeNotifyHandler; |
|
241 iRingingVolumeNotifyHandler = NULL; |
|
242 } |
|
243 if(iProfilesRepository) |
|
244 { |
|
245 delete iProfilesRepository; |
|
246 iProfilesRepository = NULL; |
|
247 } |
|
248 if(iVibraRepository) |
|
249 { |
|
250 delete iVibraRepository; |
|
251 iVibraRepository = NULL; |
|
252 } |
|
253 |
|
254 iApaSession.Close(); |
|
255 |
|
256 if(iNotifierAPI) |
|
257 { |
|
258 delete iNotifierAPI; |
|
259 iNotifierAPI = NULL; |
|
260 } |
|
261 |
|
262 if(iAudioPlayer) |
|
263 { |
|
264 CHAT_DP_TXT( "delete CMdaAudioPlayerUtility" ); |
|
265 iAudioPlayer->Close(); |
|
266 delete iAudioPlayer; |
|
267 iAudioPlayer = NULL; |
|
268 } |
|
269 if(iTonePlayer) |
|
270 { |
|
271 CHAT_DP_TXT( "delete CMdaAudioToneUtility" ); |
|
272 delete iTonePlayer; |
|
273 iTonePlayer = NULL; |
|
274 } |
|
275 |
|
276 iObservers.Close(); |
|
277 |
|
278 if(iToneFileName) |
|
279 { |
|
280 delete iToneFileName; |
|
281 iToneFileName = NULL; |
|
282 } |
|
283 |
|
284 if(iVibrator) |
|
285 { |
|
286 delete iVibrator; |
|
287 iVibrator = NULL; |
|
288 } |
|
289 |
|
290 if(iBeepRingingTone) |
|
291 { |
|
292 delete iBeepRingingTone; |
|
293 iBeepRingingTone = NULL; |
|
294 } |
|
295 |
|
296 iFs.Close(); |
|
297 |
|
298 if(iSettingsStore) |
|
299 { |
|
300 delete iSettingsStore; |
|
301 iSettingsStore = NULL; |
|
302 } |
|
303 |
|
304 CHAT_DP_FUNC_DONE("~CIMAlertManager"); |
|
305 } |
|
306 |
|
307 |
|
308 // --------------------------------------------------------- |
|
309 // CIMAlertManager::Play |
|
310 // (other items were commented in a header). |
|
311 // --------------------------------------------------------- |
|
312 // |
|
313 EXPORT_C void CIMAlertManager::PlayL(TUint32 aServiceId) |
|
314 { |
|
315 CHAT_DP_FUNC_ENTER("Play"); |
|
316 TInt emergencyCallOngoing(0); |
|
317 TInt err = RProperty::Get( KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, emergencyCallOngoing ); |
|
318 |
|
319 if( !emergencyCallOngoing ) |
|
320 { |
|
321 Stop(); |
|
322 TRAPD( err, DoPlayL(aServiceId) ); |
|
323 if( err ) |
|
324 { |
|
325 HandleError( err ); |
|
326 } |
|
327 } |
|
328 CHAT_DP_FUNC_DONE("Play"); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // CIMAlertManager::DoPlayL |
|
333 // (other items were commented in a header). |
|
334 // --------------------------------------------------------- |
|
335 // |
|
336 EXPORT_C void CIMAlertManager::DoPlayL(TUint32 aServiceId) |
|
337 { |
|
338 CHAT_DP_FUNC_ENTER("DoPlayL"); |
|
339 |
|
340 TBuf<KMaxPath> toneFileName; |
|
341 |
|
342 // check if we're silent or not |
|
343 iActiveProfile = iProfileApi->ActiveProfileL(); |
|
344 TBool isSilent = iActiveProfile->IsSilent(); |
|
345 iActiveProfile->Release(); |
|
346 iActiveProfile = NULL; // prevent further usage |
|
347 |
|
348 // vibrate, if it's allowed |
|
349 CHWRMVibra::TVibraModeState vibraModeState = iVibrator->VibraSettings(); |
|
350 CHWRMVibra::TVibraStatus vibraStatus = iVibrator->VibraStatus(); |
|
351 |
|
352 // TODO: Find from Nikhil what the behaviour should be if Vibra is already |
|
353 // on and you get a new message. Aare you supposed to truncate the existing |
|
354 // vibration and start afresh or let the existing vibration continue? |
|
355 if ( vibraModeState == CHWRMVibra::EVibraModeON && |
|
356 vibraStatus == CHWRMVibra::EVibraStatusStopped ) |
|
357 { |
|
358 iVibrator->StartVibraL( KIMVibraDuration ); |
|
359 } |
|
360 |
|
361 // sound ordering: |
|
362 // silent: get out. |
|
363 // beep once: beep, and if ok, exit. |
|
364 // if beep failed, or not active: try to play sound |
|
365 // for this server. |
|
366 // if it failed, play default sound. |
|
367 |
|
368 if ( isSilent ) |
|
369 { |
|
370 // Silent profile, get out. |
|
371 CHAT_DP_TXT( "DoPlayL - Returning" ); |
|
372 return; |
|
373 } |
|
374 |
|
375 TInt err = KErrNone; |
|
376 |
|
377 if ( iRingingType == EProfileRingingTypeBeepOnce && iBeepRingingTone ) |
|
378 { |
|
379 // Play beep.rng |
|
380 TRAP( err, ProcessFileL( *iBeepRingingTone ) ); |
|
381 } |
|
382 |
|
383 if ( err != KErrNone || iRingingType != EProfileRingingTypeBeepOnce ) |
|
384 { |
|
385 err = KErrNone; |
|
386 |
|
387 // Beep once not active, or beep once failed. |
|
388 // Try to play the sound set for this server |
|
389 TBuf<KMaxPath> toneFileName; |
|
390 GetToneFileNameL( toneFileName, aServiceId ); |
|
391 TParsePtr parsedPtr( toneFileName ); |
|
392 |
|
393 CHAT_DP( D_CHAT_LIT(" file = [%S] "),&toneFileName); |
|
394 |
|
395 // If alert tone OFF, don't play anything |
|
396 if( parsedPtr.NameAndExt().Compare( KProfileSilentTone ) != 0 ) |
|
397 { |
|
398 // Not OFF |
|
399 TRAP( err, ProcessFileL( toneFileName ) ); |
|
400 } |
|
401 } |
|
402 |
|
403 // Not ringing once, but left |
|
404 User::LeaveIfError( err ); |
|
405 |
|
406 CHAT_DP_FUNC_DONE("DoPlayL"); |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------- |
|
410 // CIMAlertManager::Stop |
|
411 // (other items were commented in a header). |
|
412 // --------------------------------------------------------- |
|
413 // |
|
414 EXPORT_C void CIMAlertManager::Stop() |
|
415 { |
|
416 CHAT_DP_FUNC_ENTER("Stop"); |
|
417 |
|
418 if( iAudioPlayerStatus == EAudioPlayerPlaying ) |
|
419 { |
|
420 CHAT_DP_TXT( |
|
421 "Audio player is playing. CMdaAudioPlayerUtility::Stop()" ); |
|
422 iAudioPlayer->Stop(); |
|
423 iAudioPlayer->Close(); |
|
424 iAudioPlayerStatus = EAudioPlayerReady; |
|
425 } |
|
426 |
|
427 if( iTonePlayerStatus == EAudioPlayerPlaying ) |
|
428 { |
|
429 CHAT_DP_TXT( |
|
430 "Tone player is playing. CMdaAudioToneUtility::CancelPlay()" ); |
|
431 iTonePlayer->CancelPlay(); |
|
432 iTonePlayerStatus = EAudioPlayerReady; |
|
433 } |
|
434 |
|
435 CHAT_DP_FUNC_DONE("Stop"); |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------- |
|
439 // CIMAlertManager::SetVolume |
|
440 // Set the volume at which the sound is played |
|
441 // (other items were commented in a header). |
|
442 // --------------------------------------------------------- |
|
443 // |
|
444 EXPORT_C void CIMAlertManager::SetVolume( TInt aVolume ) |
|
445 { |
|
446 iRingingVolumeNotifyHandler->StopListening(); |
|
447 iRingingVolume = aVolume; |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------- |
|
451 // CIMAlertManager::SetRingingType |
|
452 // Sets the ringing type how the sound is played |
|
453 // (other items were commented in a header). |
|
454 // --------------------------------------------------------- |
|
455 // |
|
456 EXPORT_C void CIMAlertManager::SetRingingType( TProfileRingingType aRingingType ) |
|
457 { |
|
458 if(iRingingTypeNotifyHandler) |
|
459 { |
|
460 iRingingTypeNotifyHandler->StopListening(); |
|
461 iRingingType = aRingingType; |
|
462 } |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------- |
|
466 // CIMAlertManager::SetVibra |
|
467 // Sets the vibrating alert on or off |
|
468 // (other items were commented in a header). |
|
469 // --------------------------------------------------------- |
|
470 // |
|
471 EXPORT_C void CIMAlertManager::SetVibra( TBool aVibra ) |
|
472 { |
|
473 if(iVibraNotifyHandler) |
|
474 { |
|
475 iVibraNotifyHandler->StopListening(); |
|
476 iVibra = aVibra; |
|
477 } |
|
478 } |
|
479 |
|
480 // --------------------------------------------------------- |
|
481 // CIMAlertManager::AddObserverL |
|
482 // (other items were commented in a header). |
|
483 // --------------------------------------------------------- |
|
484 // |
|
485 EXPORT_C void CIMAlertManager::AddObserverL( const MIMAlertManagerObserver* aObserver ) |
|
486 { |
|
487 // make sure that aObserver does not get appended in release mode also. |
|
488 if( aObserver ) |
|
489 { |
|
490 User::LeaveIfError( iObservers.Append( aObserver ) ); |
|
491 } |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------- |
|
495 // CIMAlertManager::RemoveObserver |
|
496 // (other items were commented in a header). |
|
497 // --------------------------------------------------------- |
|
498 // |
|
499 EXPORT_C void CIMAlertManager::RemoveObserver( const MIMAlertManagerObserver* aObserver ) |
|
500 { |
|
501 TInt index( iObservers.Find( aObserver ) ); |
|
502 |
|
503 if( index != KErrNotFound ) |
|
504 { |
|
505 iObservers.Remove( index ); |
|
506 } |
|
507 } |
|
508 |
|
509 // --------------------------------------------------------- |
|
510 // CIMAlertManager::ProcessFileL |
|
511 // If filename is defined, prepare the audioplayer. |
|
512 // (other items were commented in a header). |
|
513 // --------------------------------------------------------- |
|
514 // |
|
515 void CIMAlertManager::ProcessFileL( const TDesC& aFileName ) |
|
516 { |
|
517 CHAT_DP_FUNC_ENTER("ProcessFileL"); |
|
518 |
|
519 TFileName *fileName = new (ELeave) TFileName(); |
|
520 CleanupStack::PushL( fileName ); |
|
521 |
|
522 // if filename is empty, use default sound |
|
523 if ( aFileName.Length() == 0 ) |
|
524 { |
|
525 return; |
|
526 } |
|
527 else |
|
528 { |
|
529 *fileName = aFileName; |
|
530 } |
|
531 |
|
532 TPtr filePtr( NULL, 0 ); |
|
533 if( !BaflUtils::FileExists( iFs, *fileName ) ) |
|
534 { |
|
535 CHAT_DP( D_CHAT_LIT( "File does not exist ( %S )" ), &(*fileName) ); |
|
536 User::Leave( KErrNotFound ); |
|
537 } |
|
538 |
|
539 Stop(); // Stops possible playback |
|
540 |
|
541 TUid dummyUid( KNullUid ); |
|
542 TDataType dataType; |
|
543 |
|
544 User::LeaveIfError( iApaSession.AppForDocument( *fileName, dummyUid, |
|
545 dataType ) ); |
|
546 |
|
547 if( dataType.Des().CompareF( KChatRngMimeType ) == 0 ) |
|
548 { |
|
549 // making sure that another initializing is not already ongoing |
|
550 if( iTonePlayerStatus == EAudioPlayerReady ) |
|
551 { |
|
552 CHAT_DP( D_CHAT_LIT( |
|
553 "CMdaAudioToneUtility::PrepareToPlayFileSequence( %S )" ), |
|
554 &(*fileName)); |
|
555 iTonePlayerStatus = EAudioPlayerInitializing; |
|
556 iTonePlayer->PrepareToPlayFileSequence( *fileName ); |
|
557 } |
|
558 } |
|
559 else |
|
560 { |
|
561 // making sure that another initializing is not already ongoing |
|
562 if( iAudioPlayerStatus == EAudioPlayerReady ) |
|
563 { |
|
564 CHAT_DP( D_CHAT_LIT( |
|
565 "FileList - CMdaAudioPlayerUtility::OpenFileL( %S )" ), |
|
566 &(*fileName)); |
|
567 iAudioPlayerStatus = EAudioPlayerInitializing; |
|
568 TRAPD( err, iAudioPlayer->OpenFileL( *fileName ) ); |
|
569 CHAT_DP( D_CHAT_LIT( |
|
570 "FileList - CMdaAudioPlayerUtility::OpenFileL err = %d" ), |
|
571 err ); |
|
572 if( err ) |
|
573 { |
|
574 iAudioPlayerStatus = EAudioPlayerReady; |
|
575 User::Leave( err ); |
|
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 CleanupStack::PopAndDestroy( fileName ); |
|
581 CHAT_DP_FUNC_DONE("ProcessFileL"); |
|
582 } |
|
583 |
|
584 // --------------------------------------------------------- |
|
585 // CIMAlertManager::DoSetRingingType |
|
586 // When audioplayer is ready, set its ringing type |
|
587 // (other items were commented in a header). |
|
588 // --------------------------------------------------------- |
|
589 // |
|
590 |
|
591 void CIMAlertManager::DoSetRingingType( TInt aRingingType ) |
|
592 { |
|
593 if( iAudioPlayerStatus == EAudioPlayerInitialized ) |
|
594 { |
|
595 switch( aRingingType ) |
|
596 { |
|
597 // Fall through |
|
598 case EProfileRingingTypeRingingOnce: |
|
599 { |
|
600 iAudioPlayer->SetRepeats( 0, |
|
601 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
602 break; |
|
603 } |
|
604 case EProfileRingingTypeBeepOnce: |
|
605 { |
|
606 iAudioPlayer->SetRepeats( 0, |
|
607 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
608 break; |
|
609 } |
|
610 default: |
|
611 { |
|
612 break; |
|
613 } |
|
614 } |
|
615 } |
|
616 else if( iTonePlayerStatus == EAudioPlayerInitialized ) |
|
617 { |
|
618 switch( aRingingType ) |
|
619 { |
|
620 // Fall through |
|
621 case EProfileRingingTypeRingingOnce: |
|
622 { |
|
623 iTonePlayer->SetRepeats( 0, |
|
624 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
625 break; |
|
626 } |
|
627 case EProfileRingingTypeBeepOnce: |
|
628 { |
|
629 iTonePlayer->SetRepeats( 0, |
|
630 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
631 break; |
|
632 } |
|
633 default: |
|
634 { |
|
635 break; |
|
636 } |
|
637 } |
|
638 } |
|
639 } |
|
640 |
|
641 // --------------------------------------------------------- |
|
642 // CIMAlertManager::ConvertVolume |
|
643 // Convert volume to the scale used by hardware. |
|
644 // E.g. Profiles lets user select volume 1-10, but hw's scale is normally 1-9. |
|
645 // (other items were commented in a header). |
|
646 // --------------------------------------------------------- |
|
647 // |
|
648 TInt CIMAlertManager::ConvertVolume( TInt aVolume ) |
|
649 { |
|
650 TInt result( 0 ); |
|
651 // if ringing type is "silent" then volume |
|
652 // is zero |
|
653 if( iRingingType != EProfileRingingTypeSilent ) |
|
654 { |
|
655 if ( iAudioPlayerStatus == EAudioPlayerInitialized || |
|
656 iAudioPlayerStatus == EAudioPlayerPlaying ) |
|
657 { |
|
658 result = iAudioPlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
659 if ( aVolume == KMinVolumeLevel && result == 0 ) |
|
660 { |
|
661 result = 1; |
|
662 } |
|
663 } |
|
664 else if( iTonePlayerStatus == EAudioPlayerInitialized || |
|
665 iTonePlayerStatus == EAudioPlayerPlaying ) |
|
666 { |
|
667 result = iTonePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
668 if ( aVolume == KMinVolumeLevel && result == 0 ) |
|
669 { |
|
670 result = 1; |
|
671 } |
|
672 } |
|
673 } |
|
674 return result; |
|
675 } |
|
676 |
|
677 // --------------------------------------------------------- |
|
678 // CIMAlertManager::HandleError |
|
679 // Notifies all observers that playing is completed |
|
680 // (other items were commented in a header). |
|
681 // --------------------------------------------------------- |
|
682 // |
|
683 void CIMAlertManager::HandleError( TInt aError ) |
|
684 { |
|
685 if ( ( aError == KErrNoMemory ) || |
|
686 ( aError == KErrDiskFull ) ) |
|
687 { |
|
688 CActiveScheduler::Current()->Error( aError ); |
|
689 } |
|
690 } |
|
691 |
|
692 // --------------------------------------------------------- |
|
693 // CIMAlertManager::GetToneFileNameL |
|
694 // (other items were commented in a header). |
|
695 // --------------------------------------------------------- |
|
696 // |
|
697 void CIMAlertManager::GetToneFileNameL( TDes& aToneFileName ,TUint32 aServiceId) |
|
698 { |
|
699 RBuf buffer; |
|
700 buffer.CreateL( RProperty::KMaxPropertySize ); |
|
701 CleanupClosePushL( buffer ); |
|
702 iSettingsStore->GetL(aServiceId, EServiceToneFileName, buffer); |
|
703 aToneFileName.Copy( buffer ); |
|
704 CleanupStack::PopAndDestroy(); //buffer |
|
705 } |
|
706 |
|
707 // --------------------------------------------------------- |
|
708 // CIMAlertManager::MapcInitComplete |
|
709 // This method is called when the audioplayer initialisation is ready. |
|
710 // If file format is supported, start playing the sound file. |
|
711 // (other items were commented in a header). |
|
712 // --------------------------------------------------------- |
|
713 // |
|
714 void CIMAlertManager::MapcInitComplete( |
|
715 TInt aError, const TTimeIntervalMicroSeconds& /* aDuration */ ) |
|
716 { |
|
717 CHAT_DP( D_CHAT_LIT( |
|
718 "MMdaAudioPlayerCallback::MapcInitComplete() callback, error == %d" ), |
|
719 aError); |
|
720 |
|
721 if ( !aError && iAudioPlayerStatus == EAudioPlayerInitializing ) |
|
722 { |
|
723 iAudioPlayerStatus = EAudioPlayerInitialized; |
|
724 // currently IM messages supports only this ringing type |
|
725 // ringing once |
|
726 DoSetRingingType( EProfileRingingTypeRingingOnce ); |
|
727 CHAT_DP( D_CHAT_LIT("CMdaAudioPlayerUtility::SetVolume( %d )" ), |
|
728 iRingingVolume); |
|
729 |
|
730 iAudioPlayer->SetVolume( ConvertVolume( iRingingVolume ) ); |
|
731 |
|
732 // TODO: please check the value KAudioPrefNewSpecialMessage. |
|
733 // WHy does it have this particular value? What is the rationale. |
|
734 // |
|
735 CHAT_DP( D_CHAT_LIT("CMdaAudioPlayerUtility::SetPriority( %d, %d )" ), |
|
736 KAudioPriorityRecvMsg, |
|
737 TMdaPriorityPreference( KAudioPrefNewSpecialMessage ) ); |
|
738 |
|
739 iAudioPlayer->SetPriority( KAudioPriorityRecvMsg, |
|
740 TMdaPriorityPreference( KAudioPrefNewSpecialMessage ) ); |
|
741 |
|
742 CHAT_DP_TXT("CMdaAudioPlayerUtility::Play()" ); |
|
743 iAudioPlayer->Play(); |
|
744 iAudioPlayerStatus = EAudioPlayerPlaying; |
|
745 iNotifierAPI->SetInt( MIMAlertNotifierInterface::EMSGToneQuitKey, |
|
746 ECoreAppUIsTonePlaying ); |
|
747 } |
|
748 else |
|
749 { |
|
750 Stop(); |
|
751 iAudioPlayerStatus = EAudioPlayerReady; |
|
752 if( ( ( aError == KErrNotSupported ) || ( aError == KErrCorrupt ) )) |
|
753 { |
|
754 return; |
|
755 } |
|
756 else |
|
757 { |
|
758 HandleError( aError ); |
|
759 iIsPlayingDefaultIMSound = EFalse; |
|
760 } |
|
761 } |
|
762 } |
|
763 |
|
764 // --------------------------------------------------------- |
|
765 // CIMAlertManager::MapcPlayComplete |
|
766 // This method is called when the audioplayer has finished playing a sound |
|
767 // (other items were commented in a header). |
|
768 // --------------------------------------------------------- |
|
769 // |
|
770 void CIMAlertManager::MapcPlayComplete( TInt aError ) |
|
771 { |
|
772 CHAT_DP( D_CHAT_LIT( |
|
773 "MMdaAudioPlayerCallback::MapcPlayComplete() callback, error == %d" ), |
|
774 aError); |
|
775 iNotifierAPI->SetInt( MIMAlertNotifierInterface::EMSGToneQuitKey, ECoreAppUIsTonePlayingUninitialized ); |
|
776 iAudioPlayer->Close(); |
|
777 iAudioPlayerStatus = EAudioPlayerReady; |
|
778 |
|
779 if( ( ( aError == KErrNotSupported ) || ( aError == KErrCorrupt ) ) ) |
|
780 { |
|
781 return; |
|
782 } |
|
783 else |
|
784 { |
|
785 HandleError( aError ); |
|
786 iIsPlayingDefaultIMSound = EFalse; |
|
787 } |
|
788 } |
|
789 |
|
790 // --------------------------------------------------------- |
|
791 // CIMAlertManager::HandleKeyChange |
|
792 // This method receives notifications from the shared data server |
|
793 // (other items were commented in a header). |
|
794 // --------------------------------------------------------- |
|
795 // |
|
796 void CIMAlertManager::HandleKeyChange( TUpdatedKey& aUpdatedValues ) |
|
797 { |
|
798 CHAT_DP_FUNC_ENTER("HandleKeyChange"); |
|
799 |
|
800 // If we have an event which changes the key value to |
|
801 // ECoreAppUIsStopTonePlaying -> stop playing. |
|
802 if( aUpdatedValues.iValue == ECoreAppUIsStopTonePlaying ) |
|
803 { |
|
804 // Message tone should be stopped |
|
805 CHAT_DP_TXT( "**stop playing!**" ); |
|
806 Stop(); |
|
807 } |
|
808 |
|
809 CHAT_DP_FUNC_DONE("HandleKeyChange"); |
|
810 } |
|
811 |
|
812 // --------------------------------------------------------- |
|
813 // CIMAlertManager::HandleNotifyInt |
|
814 // (other items were commented in a header). |
|
815 // --------------------------------------------------------- |
|
816 void CIMAlertManager::HandleNotifyInt( TUint32 aId, TInt aNewValue ) |
|
817 { |
|
818 CHAT_DP_FUNC_ENTER("HandleNotifyL"); |
|
819 CHAT_DP( D_CHAT_LIT("aKey == %d" ), aId); |
|
820 CHAT_DP( D_CHAT_LIT("aValue == %d" ), aNewValue); |
|
821 |
|
822 |
|
823 if ( aId == KProEngActiveRingingVolume ) // Ringing volume has changed |
|
824 { |
|
825 iRingingVolume = aNewValue; |
|
826 } |
|
827 else if ( aId == KProEngActiveRingingType ) // Ringing type has changed |
|
828 { |
|
829 iRingingType = aNewValue; |
|
830 } |
|
831 |
|
832 if ( aId == KVibraCtrlProfileVibraEnabled ) // Vibra setting has changed |
|
833 { |
|
834 iVibra = aNewValue; |
|
835 } |
|
836 |
|
837 CHAT_DP_FUNC_DONE("HandleNotifyL"); |
|
838 } |
|
839 |
|
840 // --------------------------------------------------------- |
|
841 // CIMAlertManager::MatoPrepareComplete |
|
842 // (other items were commented in a header). |
|
843 // --------------------------------------------------------- |
|
844 // |
|
845 void CIMAlertManager::MatoPrepareComplete( TInt aError ) |
|
846 { |
|
847 CHAT_DP( D_CHAT_LIT( |
|
848 "MMdaAudioToneObserver::MatoPrepareComplete() callback, error == %d" ), |
|
849 aError); |
|
850 |
|
851 if ( !aError && iTonePlayerStatus == EAudioPlayerInitializing ) |
|
852 { |
|
853 iTonePlayerStatus = EAudioPlayerInitialized; |
|
854 // TODO: confirm with UI spec/Nikhil if only this ringing type is |
|
855 // supported. If not in writing, get an entry into the UI spec done. |
|
856 // TODO: where is this requirement specified? |
|
857 |
|
858 // currently IM messages supports only this ringing type |
|
859 // ringing once |
|
860 DoSetRingingType( EProfileRingingTypeRingingOnce ); |
|
861 CHAT_DP( D_CHAT_LIT("CMdaAudioToneUtility::SetVolume( %d )" ), |
|
862 ConvertVolume( iRingingVolume )); |
|
863 iTonePlayer->SetVolume( ConvertVolume( iRingingVolume ) ); |
|
864 |
|
865 |
|
866 CHAT_DP( D_CHAT_LIT("CMdaAudioToneUtility::SetPriority( %d, %d )" ), |
|
867 KAudioPriorityRecvMsg, |
|
868 TMdaPriorityPreference( KAudioPrefNewSpecialMessage ) ); |
|
869 |
|
870 iTonePlayer->SetPriority( KAudioPriorityRecvMsg, |
|
871 TMdaPriorityPreference( KAudioPrefNewSpecialMessage ) ); |
|
872 |
|
873 CHAT_DP_TXT("CMdaAudioToneUtility::Play()" ); |
|
874 iTonePlayer->Play(); |
|
875 iTonePlayerStatus = EAudioPlayerPlaying; |
|
876 iNotifierAPI->SetInt( MIMAlertNotifierInterface::EMSGToneQuitKey, |
|
877 ECoreAppUIsTonePlaying ); |
|
878 } |
|
879 else |
|
880 { |
|
881 Stop(); |
|
882 iTonePlayerStatus = EAudioPlayerReady; |
|
883 |
|
884 if( ( ( aError == KErrNotSupported ) || ( aError == KErrCorrupt ) ) ) |
|
885 { |
|
886 return; |
|
887 } |
|
888 else |
|
889 { |
|
890 HandleError( aError ); |
|
891 iIsPlayingDefaultIMSound = EFalse; |
|
892 } |
|
893 } |
|
894 } |
|
895 |
|
896 // --------------------------------------------------------- |
|
897 // CIMAlertManager::MatoPlayComplete |
|
898 // (other items were commented in a header). |
|
899 // --------------------------------------------------------- |
|
900 // |
|
901 void CIMAlertManager::MatoPlayComplete( TInt aError ) |
|
902 { |
|
903 CHAT_DP( D_CHAT_LIT( |
|
904 "MMdaAudioToneObserver::MatoPlayComplete() callback, error == %d" ), |
|
905 aError); |
|
906 iNotifierAPI->SetInt( MIMAlertNotifierInterface::EMSGToneQuitKey, ECoreAppUIsTonePlayingUninitialized ); |
|
907 iTonePlayerStatus = EAudioPlayerReady; |
|
908 |
|
909 if( ( ( aError == KErrNotSupported ) || ( aError == KErrCorrupt ) ) ) |
|
910 { |
|
911 return ; |
|
912 } |
|
913 else |
|
914 { |
|
915 HandleError( aError ); |
|
916 iIsPlayingDefaultIMSound = EFalse; |
|
917 } |
|
918 } |
|
919 |
|
920 // End of File |