|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * CFLDPlayerBase is used to play sound files. It takes into account |
|
16 * the current volume and ringing type settings. |
|
17 * |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 // CLASS HEADER |
|
23 #include "CFLDPlayerBase.h" |
|
24 |
|
25 // INTERNAL INCLUDES |
|
26 #include "ProfileEngineInternalCRKeys.h" |
|
27 |
|
28 // EXTERNAL INCLUDES |
|
29 #include <aknnotewrappers.h> // CAknErrorNote |
|
30 #include <StringLoader.h> |
|
31 #include <FileList.rsg> |
|
32 #include <centralrepository.h> |
|
33 #include <hwrmvibrasdkcrkeys.h> |
|
34 #include <e32property.h> |
|
35 #include <ctsydomainpskeys.h> |
|
36 |
|
37 // CONSTANTS |
|
38 namespace |
|
39 { |
|
40 const TInt KMinVolumeLevel( 1 ); |
|
41 const TInt KMaxVolumeLevel( 10 ); |
|
42 } |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // Destructor |
|
47 CFLDPlayerBase::~CFLDPlayerBase() |
|
48 { |
|
49 CCoeEnv::Static()->RemoveForegroundObserver( *this ); |
|
50 |
|
51 iApaSession.Close(); |
|
52 |
|
53 if( iVibraNotifyHandler ) |
|
54 { |
|
55 iVibraNotifyHandler->StopListening(); |
|
56 } |
|
57 |
|
58 if( iTypeNotifyHandler ) |
|
59 { |
|
60 iTypeNotifyHandler->StopListening(); |
|
61 } |
|
62 |
|
63 if( iVolumeNotifyHandler ) |
|
64 { |
|
65 iVolumeNotifyHandler->StopListening(); |
|
66 } |
|
67 |
|
68 delete iVibraNotifyHandler; |
|
69 delete iTypeNotifyHandler; |
|
70 delete iVolumeNotifyHandler; |
|
71 |
|
72 delete iSession; |
|
73 delete iVibraSession; |
|
74 |
|
75 delete iErrorMessage; |
|
76 iErrorMessage = NULL; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CFLDPlayerBase::CFLDPlayerBase |
|
81 // C++ constructor can NOT contain any code, that might leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CFLDPlayerBase::CFLDPlayerBase( TBool aShowErrorMsgs ) |
|
85 : i3dEffects( ETrue ), |
|
86 iShowErrorMsgs( aShowErrorMsgs ) |
|
87 { |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CFLDPlayerBase::BaseConstructL |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CFLDPlayerBase::BaseConstructL() |
|
96 { |
|
97 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
98 |
|
99 coeEnv->AddForegroundObserverL( *this ); |
|
100 |
|
101 // Read a text string from resource file |
|
102 if ( iShowErrorMsgs ) |
|
103 { |
|
104 iErrorMessage = StringLoader::LoadL( R_FLD_QTN_FILE_FORMAT_ERROR ); |
|
105 } |
|
106 |
|
107 // Get initial settings from active profile |
|
108 // init cenrep connection |
|
109 iSession = CRepository::NewL(KCRUidProfileEngine); |
|
110 iVibraSession = CRepository::NewL(KCRUidVibraCtrl); |
|
111 |
|
112 iVolumeNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
113 *iSession, |
|
114 CCenRepNotifyHandler::EIntKey, |
|
115 KProEngActiveRingingVolume); |
|
116 |
|
117 iTypeNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
118 *iSession, |
|
119 CCenRepNotifyHandler::EIntKey, |
|
120 KProEngActiveRingingType); |
|
121 |
|
122 iVibraNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
123 *iVibraSession, |
|
124 CCenRepNotifyHandler::EIntKey, |
|
125 KVibraCtrlProfileVibraEnabled); |
|
126 |
|
127 |
|
128 User::LeaveIfError( iSession->Get( KProEngActiveRingingVolume, iRingingVolume ) ); |
|
129 User::LeaveIfError( iSession->Get( KProEngActiveRingingType, iRingingType ) ); |
|
130 User::LeaveIfError( iVibraSession->Get( KVibraCtrlProfileVibraEnabled, iVibra ) ); |
|
131 |
|
132 User::LeaveIfError( iSession->Get( KProEngDefaultRingingTone, iDefaultTone ) ); |
|
133 |
|
134 iVolumeNotifyHandler->StartListeningL(); |
|
135 iTypeNotifyHandler->StartListeningL(); |
|
136 iVibraNotifyHandler->StartListeningL(); |
|
137 |
|
138 User::LeaveIfError( iApaSession.Connect() ); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CFLDPlayerBase::SetVolume() |
|
143 // (other items were commented in a header). |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CFLDPlayerBase::SetVolume( TInt aVolume ) |
|
147 { |
|
148 iRingingVolume = aVolume; |
|
149 |
|
150 // CCenrepNotifyHandler doesn't allow to stop only iVolumeNotifyHandler |
|
151 // but we must stop all the handlers in correct order |
|
152 if( iVibraNotifyHandler ) |
|
153 { |
|
154 iVibraNotifyHandler->StopListening(); |
|
155 } |
|
156 |
|
157 if( iTypeNotifyHandler ) |
|
158 { |
|
159 iTypeNotifyHandler->StopListening(); |
|
160 } |
|
161 |
|
162 if( iVolumeNotifyHandler ) |
|
163 { |
|
164 iVolumeNotifyHandler->StopListening(); |
|
165 delete iVolumeNotifyHandler; |
|
166 iVolumeNotifyHandler = NULL; |
|
167 } |
|
168 |
|
169 // Start handlers again which were stopped |
|
170 // No possibility to handle leave here any way |
|
171 if( iTypeNotifyHandler ) |
|
172 { |
|
173 TRAP_IGNORE( iTypeNotifyHandler->StartListeningL() ); |
|
174 } |
|
175 if( iVibraNotifyHandler ) |
|
176 { |
|
177 TRAP_IGNORE( iVibraNotifyHandler->StartListeningL() ); |
|
178 } |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CFLDPlayerBase::SetRingingType() |
|
183 // (other items were commented in a header). |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CFLDPlayerBase::SetRingingType( TInt aRingingType ) |
|
187 { |
|
188 iRingingType = aRingingType; |
|
189 if( iVibraNotifyHandler ) |
|
190 { |
|
191 iVibraNotifyHandler->StopListening(); |
|
192 } |
|
193 |
|
194 if( iTypeNotifyHandler ) |
|
195 { |
|
196 iTypeNotifyHandler->StopListening(); |
|
197 delete iTypeNotifyHandler; |
|
198 iTypeNotifyHandler = NULL; |
|
199 } |
|
200 |
|
201 if( iVolumeNotifyHandler ) |
|
202 { |
|
203 iVolumeNotifyHandler->StopListening(); |
|
204 } |
|
205 |
|
206 if( iVolumeNotifyHandler ) |
|
207 { |
|
208 TRAP_IGNORE( iVolumeNotifyHandler->StartListeningL() ); |
|
209 } |
|
210 |
|
211 if( iVibraNotifyHandler ) |
|
212 { |
|
213 TRAP_IGNORE( iVibraNotifyHandler->StartListeningL() ); |
|
214 } |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CFLDPlayerBase::SetVibra() |
|
219 // (other items were commented in a header). |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CFLDPlayerBase::SetVibra( TBool aVibra ) |
|
223 { |
|
224 iVibra = aVibra; |
|
225 if( iVibraNotifyHandler ) |
|
226 { |
|
227 iVibraNotifyHandler->StopListening(); |
|
228 delete iVibraNotifyHandler; |
|
229 iVibraNotifyHandler = NULL; |
|
230 } |
|
231 |
|
232 if( iTypeNotifyHandler ) |
|
233 { |
|
234 iTypeNotifyHandler->StopListening(); |
|
235 } |
|
236 |
|
237 if( iVolumeNotifyHandler ) |
|
238 { |
|
239 iVolumeNotifyHandler->StopListening(); |
|
240 } |
|
241 |
|
242 if( iVolumeNotifyHandler ) |
|
243 { |
|
244 TRAP_IGNORE( iVolumeNotifyHandler->StartListeningL() ); |
|
245 } |
|
246 if( iTypeNotifyHandler ) |
|
247 { |
|
248 TRAP_IGNORE( iTypeNotifyHandler->StartListeningL() ); |
|
249 } |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CFLDPlayerBase::Set3dEffects() |
|
254 // (other items were commented in a header). |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CFLDPlayerBase::Set3dEffects( TBool a3dEffects ) |
|
258 { |
|
259 i3dEffects = a3dEffects; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CFLDPlayerBase::BaseConvertVolume() |
|
264 // (other items were commented in a header). |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 TInt CFLDPlayerBase::BaseConvertVolume( TInt aVolume, TInt aMaxVolume ) |
|
268 { |
|
269 TInt result( aMaxVolume * aVolume / KMaxVolumeLevel ); |
|
270 // if user has selected minimum volume level |
|
271 // set HW volume 1 |
|
272 if ( aVolume == KMinVolumeLevel && result == 0 ) |
|
273 { |
|
274 result = 1; |
|
275 } |
|
276 |
|
277 return result; |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CFLDPlayerBase::DisplayErrorNoteL() |
|
282 // (other items were commented in a header). |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CFLDPlayerBase::DisplayErrorNoteL() |
|
286 { |
|
287 if( iShowErrorMsgs ) |
|
288 { |
|
289 CAknErrorNote* note = new( ELeave ) CAknErrorNote( ETrue ); |
|
290 note->ExecuteLD( *iErrorMessage ); |
|
291 } |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CFLDPlayerBase::DataType() |
|
296 // (other items were commented in a header). |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CFLDPlayerBase::DataType( const TDesC& aFileName, TDataType& aDataType ) |
|
300 { |
|
301 TUid dummyUid( KNullUid ); |
|
302 return iApaSession.AppForDocument( aFileName, dummyUid, aDataType ); |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CFLDPlayerBase::HandleNotifyInt() |
|
307 // (other items were commented in a header). |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 void CFLDPlayerBase::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
311 { |
|
312 |
|
313 if ( aId == KProEngActiveRingingVolume ) |
|
314 { |
|
315 iRingingVolume = aNewValue; |
|
316 } |
|
317 else if ( aId == KProEngActiveRingingType ) |
|
318 { |
|
319 iRingingType = aNewValue; |
|
320 } |
|
321 else if ( aId == KVibraCtrlProfileVibraEnabled ) |
|
322 { |
|
323 iVibra = aNewValue; |
|
324 } |
|
325 |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CFLDPlayerBase::HandleLosingForeground() |
|
330 // (other items were commented in a header). |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CFLDPlayerBase::HandleLosingForeground() |
|
334 { |
|
335 iFocusLost = ETrue; |
|
336 Cancel(); |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CFLDPlayerBase::HandleGainingForeground() |
|
341 // (other items were commented in a header). |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 void CFLDPlayerBase::HandleGainingForeground() |
|
345 { |
|
346 iFocusLost = EFalse; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CFLDPlayerBase::IsCallOngoing() |
|
351 // (other items were commented in a header). |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 TBool CFLDPlayerBase::IsCallOngoing() const |
|
355 { |
|
356 // Get call status |
|
357 TBool res = EFalse; |
|
358 TInt err = KErrNone; |
|
359 TInt callState = EPSCTsyCallStateUninitialized; |
|
360 |
|
361 err = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState ); |
|
362 if( !err && |
|
363 ( callState != EPSCTsyCallStateUninitialized && |
|
364 callState != EPSCTsyCallStateNone && |
|
365 callState != EPSCTsyCallStateDisconnecting ) ) |
|
366 { |
|
367 // There was call ongoing |
|
368 res = ETrue; |
|
369 } |
|
370 |
|
371 return res; |
|
372 } |
|
373 |
|
374 |
|
375 // End of File |
|
376 |