|
1 /* |
|
2 * Copyright (c) 2005-2007 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 * This class is the container class of the CStartupTone. |
|
16 * Is used to play startup tone. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <Profile.hrh> |
|
23 #include <centralrepository.h> |
|
24 #include <StartupDomainCRKeys.h> |
|
25 #include <ProfileEngineSDKCRKeys.h> |
|
26 #include "StartupTone.h" |
|
27 #include "StartupAppUi.h" |
|
28 #include "AudioPreference.h" |
|
29 |
|
30 #define MIN_VOLUME 0 |
|
31 #define MAX_VOLUME 10 |
|
32 |
|
33 //=============================== MEMBER FUNCTIONS ============================ |
|
34 // --------------------------------------------------------- |
|
35 // Constructor & destructor |
|
36 // EPOC two phased constructor |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 CStartupTone::CStartupTone( CStartupAppUi* aStartupAppUi ) : |
|
40 iTone( NULL ), |
|
41 iAudioReady( EFalse ), |
|
42 iPlaying( EFalse ), |
|
43 iStartupAppUi( aStartupAppUi ), |
|
44 iHiddenReset (EFalse ), |
|
45 iStartupWaitingForTone ( EFalse ) |
|
46 { |
|
47 } |
|
48 |
|
49 CStartupTone::~CStartupTone() |
|
50 { |
|
51 TRACES("CStartupTone::~CStartupTone()"); |
|
52 |
|
53 if (iTone) |
|
54 { |
|
55 if (iPlaying) |
|
56 { |
|
57 TRACES("CStartupTone::~CStartupTone(): Still playing. Stop it!"); |
|
58 iTone->Stop(); |
|
59 } |
|
60 delete iTone; |
|
61 iTone = NULL; |
|
62 TRACES("CStartupTone::~CStartupTone(): iTone deleted"); |
|
63 } |
|
64 TRACES("CStartupTone::~CStartupTone(): End"); |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------- |
|
68 // CStartupTone::NewL( CStartupAppUi* aStartupAppUi ) |
|
69 // ---------------------------------------------------- |
|
70 CStartupTone* CStartupTone::NewL( CStartupAppUi* aStartupAppUi, TToneType aToneType ) |
|
71 { |
|
72 TRACES("CStartupTone::NewL()"); |
|
73 CStartupTone* self = new (ELeave) CStartupTone( aStartupAppUi ); |
|
74 |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(aToneType); |
|
77 CleanupStack::Pop(); // self |
|
78 |
|
79 TRACES("CStartupTone::NewL(): End"); |
|
80 return self; |
|
81 } |
|
82 |
|
83 void CStartupTone::ConstructL(TToneType aToneType) |
|
84 { |
|
85 TRACES("CStartupTone::ConstructL()"); |
|
86 // Check tone volume |
|
87 iVolume = GetRingingToneVolumeL(); |
|
88 // Check if hidden reset |
|
89 iHiddenReset = iStartupAppUi->HiddenReset(); |
|
90 |
|
91 iToneType = aToneType; |
|
92 |
|
93 if ((!iHiddenReset) && (iVolume)) |
|
94 { |
|
95 TPath tonePath; |
|
96 TRACES("CStartupTone::ConstructL(): Get tone path from CenRep"); |
|
97 |
|
98 CRepository* repository(NULL); |
|
99 |
|
100 TRAPD( err, repository = CRepository::NewL( KCRUidStartupConf ) ); |
|
101 if ( err != KErrNone ) |
|
102 { |
|
103 TRACES("CStartupTone::ConstructL(): End, ERROR: Failed to get startup tone path"); |
|
104 return; |
|
105 } |
|
106 if (iToneType == EStartupTone) |
|
107 { |
|
108 TRACES("CStartupTone::ConstructL(): Tone type EStartupTone"); |
|
109 err = repository->Get( KStartupTonePath, tonePath ); |
|
110 } |
|
111 else |
|
112 { |
|
113 TRACES("CStartupTone::ConstructL(): Tone type EStartupOpTone"); |
|
114 err = repository->Get( KStartupOperatorTonePath, tonePath ); |
|
115 } |
|
116 delete repository; |
|
117 |
|
118 TRACES2("CStartupTone::ConstructL(): Get tone to play. err = %d, Path = '%S'", err, &tonePath ); |
|
119 |
|
120 RFs fs; |
|
121 err = fs.Connect(); |
|
122 TFindFile findExe(fs); |
|
123 err = findExe.FindByPath( tonePath, NULL ); |
|
124 fs.Close(); |
|
125 if (err != KErrNone) |
|
126 { |
|
127 TRACES1("CStartupTone::ConstructL(): Tone to play: Cannot find tone. err = %d", err); |
|
128 } |
|
129 else |
|
130 { |
|
131 TRACES("CStartupTone::ConstructL(): Tone found"); |
|
132 iTone = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
133 tonePath, |
|
134 *this, KAudioPriorityPhonePower, |
|
135 TMdaPriorityPreference( KAudioPrefDefaultTone)); |
|
136 } |
|
137 } |
|
138 } |
|
139 // --------------------------------------------------------- |
|
140 // void CStartupTone::Play() |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 |
|
144 TInt CStartupTone::Play() |
|
145 { |
|
146 TRACES("CStartupTone::Play()"); |
|
147 TRACES1("CStartupTone::Play(): Tone type: %d", iToneType); |
|
148 if (iAudioReady && !iHiddenReset && iVolume && iTone) |
|
149 { |
|
150 TRACES("CStartupTone::Play(): Audio ready. Play tone"); |
|
151 iVolume = Max( MIN_VOLUME, Min( iVolume, MAX_VOLUME ) ); |
|
152 iTone->SetVolume(iVolume); |
|
153 iTone->Play(); |
|
154 iPlaying = ETrue; |
|
155 TRACES("CStartupTone::Play(): End, return KErrNone"); |
|
156 return KErrNone; |
|
157 } |
|
158 else |
|
159 { |
|
160 TRACES("CStartupTone::Play(): Audio not ready, hidden reset, volume null or tone is not initialized. Unable to play tone."); |
|
161 TRACES1("CStartupTone::Play(): Audio ready: %d",iAudioReady); |
|
162 TRACES1("CStartupTone::Play(): Hidden reset: %d",iHiddenReset); |
|
163 TRACES1("CStartupTone::Play(): Volume: %d",iVolume); |
|
164 TRACES1("CStartupTone::Play(): Tone: %d",iTone); |
|
165 TRACES("CStartupTone::Play(): End, return KErrNotReady"); |
|
166 return KErrNotReady; |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // void CStartupTone::Stop() |
|
172 // --------------------------------------------------------- |
|
173 // |
|
174 |
|
175 void CStartupTone::Stop() |
|
176 { |
|
177 TRACES("CStartupTone::Stop()"); |
|
178 if (iTone) |
|
179 { |
|
180 TRACES("CStartupTone::Stop(): Stop the tone"); |
|
181 iPlaying=EFalse; |
|
182 iTone->Stop(); |
|
183 iToneType = EStartupNoTone; |
|
184 MapcPlayComplete(KErrNone); |
|
185 } |
|
186 TRACES("CStartupTone::Stop(): End"); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CStartupTone::ToneFound() |
|
191 // --------------------------------------------------------- |
|
192 // |
|
193 TBool CStartupTone::ToneFound() |
|
194 { |
|
195 TBool status(EFalse); |
|
196 if(iTone) |
|
197 status = ETrue; |
|
198 return status; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CStartupTone::AudioReady() |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 TBool CStartupTone::AudioReady() |
|
206 { |
|
207 return iAudioReady; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // void CStartupTone::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
212 // --------------------------------------------------------- |
|
213 // |
|
214 void CStartupTone::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
215 { |
|
216 TRACES("CStartupTone::MapcInitComplete()"); |
|
217 if (aError == KErrNone) |
|
218 { |
|
219 TRACES("CStartupTone::MapcInitComplete(): Ready to play startup tone"); |
|
220 iAudioReady = ETrue; |
|
221 } |
|
222 else |
|
223 { |
|
224 TRACES("CStartupTone::MapcInitComplete(): Unable to play startup tone"); |
|
225 } |
|
226 TRACES("CStartupTone::MapcInitComplete(): End"); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------- |
|
230 // void CStartupTone::MapcPlayComplete(TInt /*aError*/) |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CStartupTone::MapcPlayComplete(TInt /*aError*/) |
|
234 { |
|
235 TRACES("StartupTone::MapcPlayComplete()"); |
|
236 iPlaying=EFalse; |
|
237 if (iStartupWaitingForTone) |
|
238 { |
|
239 TRACES("StartupTone::MapcPlayComplete(): Startup waiting "); |
|
240 TRAPD(err, iStartupAppUi->ContinueStartupAfterToneL(iToneType)); |
|
241 if (err != KErrNone) |
|
242 { |
|
243 TRACES1("CStartupTone::MapcPlayComplete(): ContinueStartupAfterToneL() leaves, err = %d", err ); |
|
244 } |
|
245 } |
|
246 TRACES("StartupTone::MapcPlayComplete(): End"); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------- |
|
250 // TBool CStartupTone::Playing() |
|
251 // --------------------------------------------------------- |
|
252 // |
|
253 TBool CStartupTone::Playing() |
|
254 { |
|
255 TRACES1("StartupTone::Playing(): Return %d", iPlaying ); |
|
256 return iPlaying; |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------- |
|
260 // void CStartupTone::StartupWaiting() |
|
261 // --------------------------------------------------------- |
|
262 // |
|
263 void CStartupTone::StartupWaiting(TBool aValue) |
|
264 { |
|
265 TRACES1("StartupTone::StartupWaiting(): aValue == %d", aValue); |
|
266 iStartupWaitingForTone = aValue; |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------------- |
|
270 // CStartupTone::GetRingingToneVolumeL |
|
271 // Startup tone volume is always 4 but when ringing type is |
|
272 // silent or ringing volume is 0 or 1 startup tone is silent. |
|
273 // ---------------------------------------------------------- |
|
274 // |
|
275 TInt CStartupTone::GetRingingToneVolumeL() |
|
276 { |
|
277 TRACES("StartupTone::GetRingingToneVolumeL()"); |
|
278 |
|
279 TInt retval(0); |
|
280 TInt ringingType(EProfileRingingTypeSilent); |
|
281 TInt ringingVol(0); |
|
282 |
|
283 CRepository* repository(NULL); |
|
284 |
|
285 TRAPD( err, repository = CRepository::NewL( KCRUidProfileEngine ) ); |
|
286 if ( err != KErrNone ) |
|
287 { |
|
288 TRACES("StartupTone::GetRingingToneVolumeL(): End, ERROR, Cannot connect to CenRep"); |
|
289 return 0; |
|
290 } |
|
291 |
|
292 User::LeaveIfError( repository->Get( KProEngActiveRingingVolume, ringingVol )); |
|
293 User::LeaveIfError( repository->Get( KProEngActiveRingingType, ringingType )); |
|
294 delete repository; |
|
295 |
|
296 TRACES1("StartupTone::GetRingingToneVolumeL(): Ringing tone volume = %d", ringingVol); |
|
297 TRACES1("StartupTone::GetRingingToneVolumeL(): Ringing type = %d", ringingType); |
|
298 |
|
299 if ((ringingType != EProfileRingingTypeSilent) && |
|
300 (ringingVol != 0) && |
|
301 (ringingVol != EProfileRingingVolumeLevel1)) |
|
302 { |
|
303 TRACES("StartupTone::GetRingingToneVolumeL(): Get startup tone volume"); |
|
304 TInt defaultRingingVol; |
|
305 CRepository* repository(NULL); |
|
306 |
|
307 TRAPD( err, repository = CRepository::NewL( KCRUidStartupConf ) ); |
|
308 if ( err != KErrNone ) |
|
309 { |
|
310 return 0; |
|
311 } |
|
312 |
|
313 User::LeaveIfError( repository->Get( KStartupToneVolume, defaultRingingVol )); |
|
314 delete repository; |
|
315 |
|
316 ringingVol = defaultRingingVol; |
|
317 retval = ringingVol; |
|
318 } |
|
319 |
|
320 TRACES1("StartupTone::GetRingingToneVolumeL(): End, return %d", retval); |
|
321 return retval; |
|
322 } |
|
323 |
|
324 // End of File |