|
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 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CFSMailSoundHandler::DriveStateChangedL( TBool /*aState*/ ) |
|
42 { |
|
43 //causes a reload of soundpayer |
|
44 iState->ProfileChanged(); |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CFSMailSoundHandler* CFSMailSoundHandler::NewL( |
|
52 MFSNotificationHandlerMgr& aOwner ) |
|
53 { |
|
54 FUNC_LOG; |
|
55 CFSMailSoundHandler* self = |
|
56 new( ELeave ) CFSMailSoundHandler( aOwner ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CFSMailSoundHandler::ConstructL() |
|
68 { |
|
69 FUNC_LOG; |
|
70 |
|
71 SetObserving( ETrue ); |
|
72 |
|
73 iProfileEngine = CreateProfileEngineL(); |
|
74 iHandler = CProfileChangeNotifyHandler::NewL( this ); |
|
75 iMsgToneSubscriber = CPSSubscriber::NewL( |
|
76 *this, KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit ); |
|
77 iDriveObserver = CDriveObserver::NewL( *this ); |
|
78 |
|
79 // After sound state initialization iState is valid pointer until |
|
80 // CEmailSoundState::Uninitialize is called in the destructor. |
|
81 CEmailSoundState::InitializeL( this ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CFSMailSoundHandler::CFSMailSoundHandler( |
|
89 MFSNotificationHandlerMgr& aOwner ) : |
|
90 CFSNotificationHandlerBase( aOwner ) |
|
91 { |
|
92 FUNC_LOG; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CFSMailSoundHandler::~CFSMailSoundHandler() |
|
100 { |
|
101 FUNC_LOG; |
|
102 if ( iProfileEngine ) |
|
103 { |
|
104 iProfileEngine->Release(); |
|
105 iProfileEngine = NULL; |
|
106 } |
|
107 delete iHandler; |
|
108 ReleaseAudioPlayer(); |
|
109 delete iDriveObserver; |
|
110 delete iMsgToneSubscriber; |
|
111 CEmailSoundState::Uninitialize( iState ); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // HandleEvent is implemented also here because we need to check the |
|
116 // Home Screen status. |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CFSMailSoundHandler::HandleEventL( |
|
120 TFSMailEvent aEvent, |
|
121 TFSMailMsgId aMailbox, |
|
122 TAny* aParam1, |
|
123 TAny* aParam2, |
|
124 TAny* aParam3 ) |
|
125 { |
|
126 FUNC_LOG; |
|
127 // assumption: base class handles event only if it is TFSEventNewMail |
|
128 CFSNotificationHandlerBase::HandleEventL( aEvent, |
|
129 aMailbox, |
|
130 aParam1, |
|
131 aParam2, |
|
132 aParam3 ); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CFSMailSoundHandler::SetState( CEmailSoundState* aNewState ) |
|
140 { |
|
141 FUNC_LOG; |
|
142 INFO_1( "email sound state => %d", (TInt) aNewState ) |
|
143 iState = aNewState; |
|
144 #ifdef __HANDLER_TEST |
|
145 // for module testing |
|
146 if ( iTesterReqStatus ) { |
|
147 TRequestStatus*& status = iTesterReqStatus; |
|
148 User::RequestComplete( status, KErrNone ); |
|
149 iTesterReqStatus = NULL; |
|
150 } |
|
151 #endif |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Returns audio player utility |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 CMdaAudioPlayerUtility* CFSMailSoundHandler::AudioPlayer() |
|
159 { |
|
160 return iAudioPlayer; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CFSMailSoundHandler::HandleActiveProfileChangeL - Callback from end of |
|
165 // play from Audio player. |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CFSMailSoundHandler::HandleActiveProfileEventL( TProfileEvent /*aPE*/, TInt /*aId*/ ) |
|
169 { |
|
170 FUNC_LOG; |
|
171 // iState should never be null |
|
172 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
173 iState->ProfileChanged(); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CFSMailSoundHandler::MapcInitComplete - Callback from audio player |
|
178 // initialization. |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CFSMailSoundHandler::MapcInitComplete( |
|
182 TInt aError, |
|
183 const TTimeIntervalMicroSeconds& /*aInterval*/) |
|
184 { |
|
185 FUNC_LOG; |
|
186 // iState should never be null |
|
187 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
188 if ( aError ) |
|
189 { |
|
190 delete iAudioPlayer; |
|
191 iAudioPlayer = NULL; |
|
192 iState->AudioInitFailed(); |
|
193 } |
|
194 else |
|
195 { |
|
196 iState->AudioInitCompleted(); |
|
197 } |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // CFSMailSoundHandler::MapcPlayComplete - Callback from end of play from |
|
202 // Audio player. |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CFSMailSoundHandler::MapcPlayComplete( TInt /*aError*/ ) |
|
206 { |
|
207 FUNC_LOG; |
|
208 // iState should never be null |
|
209 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
210 // error is ignored because there's no corrective action, next play |
|
211 // request triggers re-initialization of tone. |
|
212 iState->AudioPlayCompleted(); |
|
213 iMsgToneSubscriber->Cancel(); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // CFSMailSoundHandler::RecreateAudioPlayerL |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void CFSMailSoundHandler::RecreateAudioPlayerL() |
|
221 { |
|
222 FUNC_LOG; |
|
223 delete iAudioPlayer; |
|
224 iAudioPlayer = NULL; |
|
225 |
|
226 MProfile* profile = iProfileEngine->ActiveProfileL(); |
|
227 CleanupReleasePushL( *profile ); |
|
228 |
|
229 if ( IsBeepOnceSetL( *profile ) ) |
|
230 { |
|
231 // create audio player based on hard coded sequence |
|
232 // (Platform does not offer any "play platform-wide beep" service) |
|
233 iAudioPlayer = CMdaAudioPlayerUtility::NewDesPlayerReadOnlyL( |
|
234 KEmailBeepSequence(), |
|
235 *this, |
|
236 KAudioPriorityRecvMsg, |
|
237 static_cast<TMdaPriorityPreference>( KAudioPrefNewSMS ) ); |
|
238 } |
|
239 else |
|
240 { |
|
241 // Otherwise loading tone from file |
|
242 TFileName fileToPlay = profile->ProfileExtraTones().EmailAlertTone(); |
|
243 |
|
244 RFs fs; |
|
245 TInt err = fs.Connect(); |
|
246 |
|
247 if ( err == KErrNone ) |
|
248 { |
|
249 TChar chr = fileToPlay[0]; |
|
250 TInt drive; |
|
251 fs.CharToDrive( chr, drive ); |
|
252 |
|
253 //we'll observe any drive where the tone is just because |
|
254 //the drive letter of the memory card can |
|
255 //vary from product to product. |
|
256 iDriveObserver->SetDriveL( (TDriveNumber)drive ); |
|
257 |
|
258 iDriveObserver->WaitForChange(); |
|
259 |
|
260 //test does the file exist |
|
261 if ( !BaflUtils::FileExists( fs, fileToPlay ) ) |
|
262 { |
|
263 //if the file set in profile does not exist, we use default |
|
264 fileToPlay.Zero(); |
|
265 fileToPlay.Append( KDefaultEmailTone ); |
|
266 } |
|
267 |
|
268 fs.Close(); |
|
269 } |
|
270 |
|
271 iAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
272 fileToPlay, |
|
273 *this, |
|
274 KAudioPriorityRecvMsg, |
|
275 static_cast<TMdaPriorityPreference>( KAudioPrefNewSMS ) ); |
|
276 } |
|
277 CleanupStack::PopAndDestroy( profile ); // profile |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // Deletes audio player utility |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void CFSMailSoundHandler::ReleaseAudioPlayer() |
|
285 { |
|
286 FUNC_LOG; |
|
287 delete iAudioPlayer; |
|
288 iAudioPlayer = NULL; |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // Returns profile engine |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 MProfileEngine& CFSMailSoundHandler::ProfileEngine() const |
|
296 { |
|
297 return *iProfileEngine; |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // Playes 'new email' tone |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CFSMailSoundHandler::TurnNotificationOn() |
|
305 { |
|
306 FUNC_LOG; |
|
307 // iState should never be null |
|
308 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
309 iMsgToneSubscriber->Subscribe(); |
|
310 iState->PlayTone(); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // Stops playback |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CFSMailSoundHandler::TurnNotificationOff() |
|
318 { |
|
319 FUNC_LOG; |
|
320 // iState should never be null |
|
321 __ASSERT_ALWAYS( iState, Panic ( ECmailHandlerPluginPanicNullState ) ); |
|
322 iState->StopTone(); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // IsBeepOnceSetL |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 TBool CFSMailSoundHandler::IsBeepOnceSetL( const MProfile& aProfile ) const |
|
330 { |
|
331 FUNC_LOG; |
|
332 // default to false |
|
333 TBool ret = EFalse; |
|
334 |
|
335 // get tone settings |
|
336 const TProfileToneSettings& toneSettings = aProfile.ProfileTones().ToneSettings(); |
|
337 |
|
338 // if beep-once is set, set return value to ETrue |
|
339 if( toneSettings.iRingingType == EProfileRingingTypeBeepOnce ) |
|
340 { |
|
341 ret = ETrue; |
|
342 } |
|
343 |
|
344 return ret; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // HandlePropertyChangedL |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CFSMailSoundHandler::HandlePropertyChangedL( const TUid& aCategory, TInt aKey ) |
|
352 { |
|
353 FUNC_LOG; |
|
354 TInt state( 0 ); |
|
355 |
|
356 // |
|
357 // Handling the event of user pressing a key while "msg received" -tone is playing |
|
358 // |
|
359 if ( aCategory == KPSUidCoreApplicationUIs && aKey == KCoreAppUIsMessageToneQuit ) |
|
360 { |
|
361 RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, state ); |
|
362 INFO_1("KCoreAppUIsMessageToneQuit == %d" , state ); |
|
363 if ( state == ECoreAppUIsStopTonePlaying ) |
|
364 { |
|
365 iState->StopTone(); |
|
366 iMsgToneSubscriber->Cancel(); |
|
367 } |
|
368 } |
|
369 |
|
370 // |
|
371 // Handling the event of <other PubSub event can be added here> |
|
372 // |
|
373 } |