|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Implementation of the CProEngToneHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProEngToneHandler.h" |
|
22 #include <bautils.h> // BaflUtils |
|
23 #include <AknGlobalNote.h> // CAknGlobalNote |
|
24 #include <barsread.h> // TResourceReader |
|
25 #include <barsc.h> // RResourceFile |
|
26 #include <e32const.h> // KKilo |
|
27 #include "CProEngMediaVariation.h" |
|
28 #include <centralrepository.h> |
|
29 #include <ProfileEngineDomainCRKeys.h> // KProEngRingingToneMaxSize |
|
30 #include <ProfileEng.hrh> |
|
31 |
|
32 namespace |
|
33 { |
|
34 // CONSTANTS |
|
35 _LIT( KProEngROMDriveLetter, "Z:" ); |
|
36 // The filename of the resource file |
|
37 _LIT( KProEngResourceFileName, "Z:ProEngWrapper.RSC" ); |
|
38 } |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CProEngToneHandler::CProEngToneHandler |
|
44 // C++ default constructor can NOT contain any code, that might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CProEngToneHandler::CProEngToneHandler() |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CProEngToneHandler::ConstructL |
|
53 // Symbian 2nd phase constructor can leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CProEngToneHandler::ConstructL() |
|
57 { |
|
58 DrmConstructL(); |
|
59 User::LeaveIfError( iFs.Connect() ); |
|
60 iMediaVariation = CProEngMediaVariation::NewL(); |
|
61 GetMaxToneFileSizeL( iToneFileSizeLimitKB ); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CProEngToneHandler::NewLC |
|
66 // Two-phased constructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CProEngToneHandler* CProEngToneHandler::NewLC() |
|
70 { |
|
71 CProEngToneHandler* self = new( ELeave ) CProEngToneHandler(); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CProEngToneHandler::NewL |
|
79 // Two-phased constructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CProEngToneHandler* CProEngToneHandler::NewL() |
|
83 { |
|
84 CProEngToneHandler* self = CProEngToneHandler::NewLC(); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // Destructor |
|
90 CProEngToneHandler::~CProEngToneHandler() |
|
91 { |
|
92 delete iMediaVariation; |
|
93 iFs.Close(); |
|
94 ReleaseDrm(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CProEngToneHandler::CheckToneFileL |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt CProEngToneHandler::CheckToneFileL( const TDesC& aFileName, TInt aToneType ) |
|
102 { |
|
103 // Check the file which is tried to set as ringing or alert tone. |
|
104 TInt returnValue( DoCheckToneFileL( aFileName, aToneType ) ); |
|
105 if( returnValue != KErrNone ) |
|
106 { |
|
107 return returnValue; |
|
108 } |
|
109 |
|
110 if( IsProtected( aFileName ) && CanSetAutomated( aFileName ) ) |
|
111 { |
|
112 // If the file in question is unactivated protected content, |
|
113 // ask user if he/she wants to activate it. |
|
114 if( AskAutomated( aFileName ) == KErrCancel ) |
|
115 { |
|
116 // User doesn't want to activate unactivated protected content. |
|
117 return KErrCancel; |
|
118 } |
|
119 } |
|
120 |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CProEngToneHandler::HandleAutomatedContentL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CProEngToneHandler::HandleAutomatedContent( TProfileSettingId aSettingId, |
|
129 const TDesC& aFileName, |
|
130 const TDesC& aOldFileName) |
|
131 |
|
132 { |
|
133 // Register file as automated content |
|
134 TInt err( SetAutomated( aSettingId, aFileName ) ); |
|
135 if( !err ) |
|
136 { |
|
137 // Remove the old tone from the automated content list |
|
138 RemoveAutomated( aOldFileName ); |
|
139 } |
|
140 |
|
141 return err; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CProEngToneHandler::DoCheckToneFileL |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CProEngToneHandler::DoCheckToneFileL( const TDesC& aFileName, TInt aToneType ) |
|
149 { |
|
150 if( aFileName.Length() == 0 ) |
|
151 { |
|
152 // The filename is empty, ok. |
|
153 // It will be changed to "No_sound.wav" when writing to Profiles Engine. |
|
154 return KErrNone; |
|
155 } |
|
156 |
|
157 if( !BaflUtils::FileExists( iFs, aFileName ) ) |
|
158 { |
|
159 // The file does not exist. No good (start the dance). |
|
160 return KErrNotFound; |
|
161 } |
|
162 |
|
163 // The file exists. Check its data (MIME) type. |
|
164 TBuf< KMaxDataTypeLength > dataType; |
|
165 iMediaVariation->GetDataTypeL( aFileName, dataType ); |
|
166 |
|
167 if( !iMediaVariation->IsSupported( dataType ) ) |
|
168 { |
|
169 return KErrNotSupported; |
|
170 } |
|
171 |
|
172 |
|
173 // File size check for ringing tones 1&2 |
|
174 if (aToneType == EProfileSettingIdRingingTone || |
|
175 aToneType == EProfileSettingIdRingingTone2) |
|
176 { |
|
177 if (KErrNone != CheckFileSizeLimit( aFileName )) |
|
178 { |
|
179 return KErrTooBig; |
|
180 } |
|
181 } |
|
182 |
|
183 // The file is a sound file. Can it be found on ROM |
|
184 if( aFileName.Left( KProEngROMDriveLetter().Length() ). |
|
185 CompareF( KProEngROMDriveLetter ) == 0 ) |
|
186 { |
|
187 // Tone files on ROM are always valid |
|
188 return KErrNone; |
|
189 } |
|
190 |
|
191 TInt result( KErrNone ); |
|
192 if( IsProtected( aFileName ) ) |
|
193 { |
|
194 if( !iMediaVariation->IsAllowedProtected( dataType ) ) |
|
195 { |
|
196 return KErrArgument; |
|
197 } |
|
198 |
|
199 result = CheckProtectedFileL( aFileName ); |
|
200 |
|
201 } |
|
202 else if( !iMediaVariation->IsAllowedUnProtected( dataType ) ) |
|
203 { |
|
204 result = KErrPermissionDenied; |
|
205 } |
|
206 return result; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CProEngToneHandler::ShowErrorNoteL |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CProEngToneHandler::ShowErrorNoteL( TInt aResourceId ) |
|
214 { |
|
215 TParse* fp = new(ELeave) TParse(); |
|
216 fp->Set(KProEngResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL); |
|
217 TFileName localizedFileName( fp->FullName() ); |
|
218 delete fp; |
|
219 |
|
220 BaflUtils::NearestLanguageFile( iFs, localizedFileName ); |
|
221 |
|
222 RResourceFile resourceFile; |
|
223 resourceFile.OpenL( iFs, localizedFileName ); |
|
224 CleanupClosePushL( resourceFile ); |
|
225 resourceFile.ConfirmSignatureL(); |
|
226 |
|
227 HBufC8* resBuf = resourceFile.AllocReadLC( aResourceId ); |
|
228 TResourceReader reader; |
|
229 reader.SetBuffer( resBuf ); |
|
230 TPtrC errorText( reader.ReadTPtrC() ); |
|
231 |
|
232 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
233 note->ShowNoteL( EAknGlobalInformationNote, errorText ); |
|
234 |
|
235 CleanupStack::PopAndDestroy( 3, &resourceFile ); |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CProEngToneHandler::CheckFileSizeLimitL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CProEngToneHandler::CheckFileSizeLimit( const TDesC& aFileName ) const |
|
244 { |
|
245 TInt error = KErrNone; |
|
246 |
|
247 if ( iToneFileSizeLimitKB ) |
|
248 { |
|
249 if ( CheckToneFileSize( aFileName, iToneFileSizeLimitKB ) != KErrNone ) |
|
250 { |
|
251 error = KErrTooBig; |
|
252 } |
|
253 } |
|
254 |
|
255 return error; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CProEngToneHandler::GetMaxToneFileSizeL |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CProEngToneHandler::GetMaxToneFileSizeL( TInt& aMaxSizeKB ) const |
|
263 { |
|
264 CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine ); |
|
265 TInt error = cenrep->Get( KProEngRingingToneMaxSize, aMaxSizeKB ); |
|
266 delete cenrep; |
|
267 |
|
268 if ( error != KErrNone ) |
|
269 { |
|
270 aMaxSizeKB = 0; |
|
271 } |
|
272 if ( aMaxSizeKB < 0 ) |
|
273 { |
|
274 aMaxSizeKB = 0; |
|
275 } |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CProEngToneHandler::CheckToneFileSizeL |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 TInt CProEngToneHandler::CheckToneFileSize( const TDesC& aFile, |
|
283 TInt aSizeLimitKB ) const |
|
284 { |
|
285 // Get file size |
|
286 TInt size = 0; |
|
287 TInt error = KErrNone; |
|
288 |
|
289 TEntry entry; |
|
290 error = iFs.Entry( aFile, entry ); |
|
291 if ( !error ) |
|
292 { |
|
293 size = entry.iSize; |
|
294 } |
|
295 |
|
296 // Check |
|
297 aSizeLimitKB *= KKilo; |
|
298 if ( aSizeLimitKB && size > aSizeLimitKB ) |
|
299 { |
|
300 error = KErrTooBig; |
|
301 } |
|
302 |
|
303 return error; |
|
304 } |
|
305 |
|
306 // End of File |