31 #include "emailsoundstates.h" |
31 #include "emailsoundstates.h" |
32 #include "cmailhandlerpluginpanic.h" |
32 #include "cmailhandlerpluginpanic.h" |
33 |
33 |
34 _LIT( KDefaultEmailTone, "z:\\data\\sounds\\digital\\Message 1.aac"); |
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" ); |
35 _LIT8( KEmailBeepSequence, "\x2\x4a\x3a\x51\x9\x95\x95\xc0\x4\x0\xb\x1c\x41\x8d\x51\xa8\x0\x0" ); |
36 |
36 _LIT( KProfileSilentTone, "Z:\\resource\\No_Sound.wav" ); |
37 // --------------------------------------------------------------------------- |
37 |
38 // |
38 // --------------------------------------------------------------------------- |
39 // --------------------------------------------------------------------------- |
39 // |
40 // |
40 // --------------------------------------------------------------------------- |
41 void CFSMailSoundHandler::DriveStateChangedL( TBool /*aState*/ ) |
41 // |
|
42 void CFSMailSoundHandler::DriveStateChangedL(TBool /*aState*/) |
42 { |
43 { |
43 //causes a reload of soundpayer |
44 //causes a reload of soundpayer |
44 iState->ProfileChanged(); |
45 iState->ProfileChanged(); |
45 } |
46 } |
46 |
47 |
54 FUNC_LOG; |
55 FUNC_LOG; |
55 CFSMailSoundHandler* self = |
56 CFSMailSoundHandler* self = |
56 new( ELeave ) CFSMailSoundHandler( aOwner ); |
57 new( ELeave ) CFSMailSoundHandler( aOwner ); |
57 CleanupStack::PushL( self ); |
58 CleanupStack::PushL( self ); |
58 self->ConstructL(); |
59 self->ConstructL(); |
59 CleanupStack::Pop( self ); |
60 CleanupStack::Pop(self); |
60 return self; |
61 return self; |
61 } |
62 } |
62 |
63 |
63 // --------------------------------------------------------------------------- |
64 // --------------------------------------------------------------------------- |
64 // |
65 // |
65 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
66 // |
67 // |
67 void CFSMailSoundHandler::ConstructL() |
68 void CFSMailSoundHandler::ConstructL() |
68 { |
69 { |
69 FUNC_LOG; |
70 FUNC_LOG; |
70 |
71 |
71 SetObserving( ETrue ); |
72 SetObserving(ETrue); |
72 |
73 |
73 iProfileEngine = CreateProfileEngineL(); |
74 iProfileEngine = CreateProfileEngineL(); |
74 iHandler = CProfileChangeNotifyHandler::NewL( this ); |
75 iHandler = CProfileChangeNotifyHandler::NewL( this ); |
75 iMsgToneSubscriber = CPSSubscriber::NewL( |
76 iMsgToneSubscriber = CPSSubscriber::NewL( |
76 *this, KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit ); |
77 *this, KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit ); |
77 iDriveObserver = CDriveObserver::NewL( *this ); |
78 iDriveObserver = CDriveObserver::NewL( *this ); |
78 |
79 |
79 // After sound state initialization iState is valid pointer until |
80 // After sound state initialization iState is valid pointer until |
80 // CEmailSoundState::Uninitialize is called in the destructor. |
81 // CEmailSoundState::Uninitialize is called in the destructor. |
81 CEmailSoundState::InitializeL( this ); |
82 CEmailSoundState::InitializeL(this); |
82 } |
83 } |
83 |
84 |
84 // --------------------------------------------------------------------------- |
85 // --------------------------------------------------------------------------- |
85 // |
86 // |
86 // --------------------------------------------------------------------------- |
87 // --------------------------------------------------------------------------- |
87 // |
88 // |
88 CFSMailSoundHandler::CFSMailSoundHandler( |
89 CFSMailSoundHandler::CFSMailSoundHandler( MFSNotificationHandlerMgr& aOwner ) |
89 MFSNotificationHandlerMgr& aOwner ) : |
90 : CFSNotificationHandlerBase(aOwner) |
90 CFSNotificationHandlerBase( aOwner ) |
|
91 { |
91 { |
92 FUNC_LOG; |
92 FUNC_LOG; |
93 } |
93 } |
94 |
94 |
95 // --------------------------------------------------------------------------- |
95 // --------------------------------------------------------------------------- |
96 // |
96 // |
97 // --------------------------------------------------------------------------- |
97 // --------------------------------------------------------------------------- |
98 // |
98 // |
99 CFSMailSoundHandler::~CFSMailSoundHandler() |
99 CFSMailSoundHandler::~CFSMailSoundHandler() |
100 { |
100 { |
101 FUNC_LOG; |
101 FUNC_LOG; |
102 if ( iProfileEngine ) |
102 if (iProfileEngine) |
103 { |
103 { |
104 iProfileEngine->Release(); |
104 iProfileEngine->Release(); |
105 iProfileEngine = NULL; |
105 iProfileEngine = NULL; |
106 } |
106 } |
107 delete iHandler; |
107 delete iHandler; |
108 ReleaseAudioPlayer(); |
108 ReleaseAudioPlayer(); |
109 delete iDriveObserver; |
109 delete iDriveObserver; |
110 delete iMsgToneSubscriber; |
110 delete iMsgToneSubscriber; |
111 CEmailSoundState::Uninitialize( iState ); |
111 CEmailSoundState::Uninitialize(iState); |
112 } |
112 } |
113 |
113 |
114 // --------------------------------------------------------------------------- |
114 // --------------------------------------------------------------------------- |
115 // HandleEvent is implemented also here because we need to check the |
115 // HandleEvent is implemented also here because we need to check the |
116 // Home Screen status. |
116 // Home Screen status. |
117 // --------------------------------------------------------------------------- |
117 // --------------------------------------------------------------------------- |
118 // |
118 // |
119 void CFSMailSoundHandler::HandleEventL( |
119 void CFSMailSoundHandler::HandleEventL(TFSMailEvent aEvent, |
120 TFSMailEvent aEvent, |
120 TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2, TAny* aParam3) |
121 TFSMailMsgId aMailbox, |
|
122 TAny* aParam1, |
|
123 TAny* aParam2, |
|
124 TAny* aParam3 ) |
|
125 { |
121 { |
126 FUNC_LOG; |
122 FUNC_LOG; |
127 // assumption: base class handles event only if it is TFSEventNewMail |
123 // assumption: base class handles event only if it is TFSEventNewMail |
128 CFSNotificationHandlerBase::HandleEventL( aEvent, |
124 CFSNotificationHandlerBase::HandleEventL( aEvent, |
129 aMailbox, |
125 aMailbox, |
134 |
130 |
135 // --------------------------------------------------------------------------- |
131 // --------------------------------------------------------------------------- |
136 // |
132 // |
137 // --------------------------------------------------------------------------- |
133 // --------------------------------------------------------------------------- |
138 // |
134 // |
139 void CFSMailSoundHandler::SetState( CEmailSoundState* aNewState ) |
135 void CFSMailSoundHandler::SetState(CEmailSoundState* aNewState) |
140 { |
136 { |
141 FUNC_LOG; |
137 FUNC_LOG; |
142 INFO_1( "email sound state => %d", (TInt) aNewState ) |
138 INFO_1( "email sound state => %d", (TInt) aNewState ) |
143 iState = aNewState; |
139 iState = aNewState; |
144 #ifdef __HANDLER_TEST |
140 #ifdef __HANDLER_TEST |
145 // for module testing |
141 // for module testing |
146 if ( iTesterReqStatus ) { |
142 if ( iTesterReqStatus ) |
|
143 { |
147 TRequestStatus*& status = iTesterReqStatus; |
144 TRequestStatus*& status = iTesterReqStatus; |
148 User::RequestComplete( status, KErrNone ); |
145 User::RequestComplete( status, KErrNone ); |
149 iTesterReqStatus = NULL; |
146 iTesterReqStatus = NULL; |
150 } |
147 } |
151 #endif |
148 #endif |
152 } |
149 } |
153 |
150 |
154 // --------------------------------------------------------------------------- |
151 // --------------------------------------------------------------------------- |
155 // Returns audio player utility |
152 // Returns audio player utility |
156 // --------------------------------------------------------------------------- |
153 // --------------------------------------------------------------------------- |
157 // |
154 // |
158 CMdaAudioPlayerUtility* CFSMailSoundHandler::AudioPlayer() |
155 CMdaAudioPlayerUtility* CFSMailSoundHandler::AudioPlayer() |
163 // --------------------------------------------------------------------------- |
160 // --------------------------------------------------------------------------- |
164 // CFSMailSoundHandler::HandleActiveProfileChangeL - Callback from end of |
161 // CFSMailSoundHandler::HandleActiveProfileChangeL - Callback from end of |
165 // play from Audio player. |
162 // play from Audio player. |
166 // --------------------------------------------------------------------------- |
163 // --------------------------------------------------------------------------- |
167 // |
164 // |
168 void CFSMailSoundHandler::HandleActiveProfileEventL( TProfileEvent /*aPE*/, TInt /*aId*/ ) |
165 void CFSMailSoundHandler::HandleActiveProfileEventL(TProfileEvent /*aPE*/, |
169 { |
166 TInt /*aId*/ ) |
170 FUNC_LOG; |
167 { |
|
168 FUNC_LOG; |
171 // iState should never be null |
169 // iState should never be null |
172 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
170 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
173 iState->ProfileChanged(); |
171 iState->ProfileChanged(); |
174 } |
172 } |
175 |
173 |
200 // --------------------------------------------------------------------------- |
198 // --------------------------------------------------------------------------- |
201 // CFSMailSoundHandler::MapcPlayComplete - Callback from end of play from |
199 // CFSMailSoundHandler::MapcPlayComplete - Callback from end of play from |
202 // Audio player. |
200 // Audio player. |
203 // --------------------------------------------------------------------------- |
201 // --------------------------------------------------------------------------- |
204 // |
202 // |
205 void CFSMailSoundHandler::MapcPlayComplete( TInt /*aError*/ ) |
203 void CFSMailSoundHandler::MapcPlayComplete(TInt /*aError*/) |
206 { |
204 { |
207 FUNC_LOG; |
205 FUNC_LOG; |
208 // iState should never be null |
206 // iState should never be null |
209 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
207 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
210 // error is ignored because there's no corrective action, next play |
208 // error is ignored because there's no corrective action, next play |
220 void CFSMailSoundHandler::RecreateAudioPlayerL() |
218 void CFSMailSoundHandler::RecreateAudioPlayerL() |
221 { |
219 { |
222 FUNC_LOG; |
220 FUNC_LOG; |
223 delete iAudioPlayer; |
221 delete iAudioPlayer; |
224 iAudioPlayer = NULL; |
222 iAudioPlayer = NULL; |
225 |
223 |
226 MProfile* profile = iProfileEngine->ActiveProfileL(); |
224 MProfile* profile = iProfileEngine->ActiveProfileL(); |
227 CleanupReleasePushL( *profile ); |
225 CleanupReleasePushL(*profile); |
228 |
226 |
229 TBool vibraEnabled = profile->ProfileTones().ToneSettings().iEmailVibratingAlert; |
227 TBool vibraEnabled = profile->ProfileTones().ToneSettings().iVibratingAlert; |
230 |
228 TBool mailVibraEnabled = vibraEnabled & profile->ProfileTones().ToneSettings().iEmailVibratingAlert; |
231 |
229 |
232 TInt preference = KAudioPrefNewSpecialMessage; |
230 TInt preference = KAudioPrefNewSpecialMessage; |
233 if ( !vibraEnabled ) |
231 if ( !mailVibraEnabled ) |
234 { |
232 { |
235 preference = EMdaPriorityPreferenceTimeAndQuality; |
233 preference = EMdaPriorityPreferenceQuality; |
236 } |
234 } |
237 |
235 |
238 if ( IsBeepOnceSetL( *profile ) ) |
236 if (IsBeepOnceSetL(*profile)) |
239 { |
237 { |
240 |
238 |
241 |
|
242 // create audio player based on hard coded sequence |
239 // create audio player based on hard coded sequence |
243 // (Platform does not offer any "play platform-wide beep" service) |
240 // (Platform does not offer any "play platform-wide beep" service) |
244 iAudioPlayer = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL( |
241 iAudioPlayer = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL( |
245 KEmailBeepSequence(), |
242 KEmailBeepSequence(), |
246 *this, |
243 *this, |
274 //if the file set in profile does not exist, we use default |
280 //if the file set in profile does not exist, we use default |
275 fileToPlay.Zero(); |
281 fileToPlay.Zero(); |
276 fileToPlay.Append( KDefaultEmailTone ); |
282 fileToPlay.Append( KDefaultEmailTone ); |
277 } |
283 } |
278 |
284 |
279 fs.Close(); |
285 CleanupStack::PopAndDestroy( &fs ); |
280 } |
286 } |
281 |
287 |
282 iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
288 iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
283 fileToPlay, |
289 fileToPlay, |
284 *this, |
290 *this, |
285 KAudioPriorityRecvMsg, |
291 KAudioPriorityRecvMsg, |
286 static_cast<TMdaPriorityPreference>( preference ) ); |
292 static_cast<TMdaPriorityPreference>( preference ) ); |
287 } |
293 } |
288 CleanupStack::PopAndDestroy( profile ); // profile |
294 CleanupStack::PopAndDestroy( profile ); |
289 } |
295 } |
290 |
296 |
291 // --------------------------------------------------------------------------- |
297 // --------------------------------------------------------------------------- |
292 // Deletes audio player utility |
298 // Deletes audio player utility |
293 // --------------------------------------------------------------------------- |
299 // --------------------------------------------------------------------------- |
335 |
341 |
336 // --------------------------------------------------------------------------- |
342 // --------------------------------------------------------------------------- |
337 // IsBeepOnceSetL |
343 // IsBeepOnceSetL |
338 // --------------------------------------------------------------------------- |
344 // --------------------------------------------------------------------------- |
339 // |
345 // |
340 TBool CFSMailSoundHandler::IsBeepOnceSetL( const MProfile& aProfile ) const |
346 TBool CFSMailSoundHandler::IsBeepOnceSetL(const MProfile& aProfile) const |
341 { |
347 { |
342 FUNC_LOG; |
348 FUNC_LOG; |
343 // default to false |
349 // default to false |
344 TBool ret = EFalse; |
350 TBool ret = EFalse; |
345 |
351 |
346 // get tone settings |
352 // get tone settings |
347 const TProfileToneSettings& toneSettings = aProfile.ProfileTones().ToneSettings(); |
353 const TProfileToneSettings& toneSettings = aProfile.ProfileTones().ToneSettings(); |
348 |
354 |
349 // if beep-once is set, set return value to ETrue |
355 // if beep-once is set, set return value to ETrue |
350 if( toneSettings.iRingingType == EProfileRingingTypeBeepOnce ) |
356 if (toneSettings.iRingingType == EProfileRingingTypeBeepOnce) |
351 { |
357 { |
352 ret = ETrue; |
358 ret = ETrue; |
353 } |
359 } |
354 |
360 |
355 return ret; |
361 return ret; |
356 } |
362 } |
357 |
363 |
358 // --------------------------------------------------------------------------- |
364 // --------------------------------------------------------------------------- |
359 // HandlePropertyChangedL |
365 // HandlePropertyChangedL |
360 // --------------------------------------------------------------------------- |
366 // --------------------------------------------------------------------------- |
361 // |
367 // |
362 void CFSMailSoundHandler::HandlePropertyChangedL( const TUid& aCategory, TInt aKey ) |
368 void CFSMailSoundHandler::HandlePropertyChangedL( const TUid& aCategory, TInt aKey ) |
363 { |
369 { |
364 FUNC_LOG; |
370 FUNC_LOG; |
365 TInt state( 0 ); |
371 TInt state(0); |
366 |
372 |
367 // |
373 // |
368 // Handling the event of user pressing a key while "msg received" -tone is playing |
374 // Handling the event of user pressing a key while "msg received" -tone is playing |
369 // |
375 // |
370 if ( aCategory == KPSUidCoreApplicationUIs && aKey == KCoreAppUIsMessageToneQuit ) |
376 if ( aCategory == KPSUidCoreApplicationUIs && aKey == KCoreAppUIsMessageToneQuit ) |
371 { |
377 { |
372 RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, state ); |
378 RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, state ); |
373 INFO_1("KCoreAppUIsMessageToneQuit == %d" , state ); |
379 INFO_1("KCoreAppUIsMessageToneQuit == %d" , state ); |
374 if ( state == ECoreAppUIsStopTonePlaying ) |
380 if (state == ECoreAppUIsStopTonePlaying) |
375 { |
381 { |
376 iState->StopTone(); |
382 iState->StopTone(); |
377 iMsgToneSubscriber->Cancel(); |
383 iMsgToneSubscriber->Cancel(); |
378 } |
384 } |
379 } |
385 } |