23
|
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: A helper interface to be used by S60 applications for
|
|
15 |
* setting ringing and alert tones for different profiles.
|
|
16 |
* Registers DRM protected tones as automated content
|
|
17 |
* and removes old content from automated content list.
|
|
18 |
* Shows a content activation query if necessary.
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
// CLASS HEADER
|
|
25 |
#include "cprofiletonehandler.h"
|
|
26 |
|
|
27 |
// INTERNAL INCLUDES
|
|
28 |
#include "ProfileMmfInfoUtility.h"
|
|
29 |
|
|
30 |
// EXTERNAL INCLUDES
|
|
31 |
#include <centralrepository.h>
|
|
32 |
#include <ProfileEngineDomainCRKeys.h> // KProEngRingingToneMaxSize
|
|
33 |
#include <bautils.h> // BaflUtils
|
|
34 |
#include <apgcli.h> // RApaLsSession
|
|
35 |
#include <coemain.h> // CCoeEnv
|
|
36 |
#include <aknnotewrappers.h> // CAknInformationNote
|
|
37 |
#include <ConeResLoader.h> // RConeResourceLoader
|
|
38 |
#include <StringLoader.h>
|
|
39 |
#include <MProfileEngineExtended.h>
|
|
40 |
#include <MProfilesLocalFeatures.h>
|
|
41 |
#include <MProfileExtended.h>
|
|
42 |
#include <MProfileSetExtraTones.h>
|
|
43 |
#include <MProfileSetTones.h>
|
|
44 |
#include <MProfileExtraTones.h>
|
|
45 |
#include <MProfileTones.h>
|
|
46 |
#include <MProfilesNamesArray.h>
|
|
47 |
#include <MProfileName.h>
|
|
48 |
#include <MProfileUtilitySingleton.h>
|
|
49 |
#include <profilesettingsview.rsg>
|
|
50 |
#include <AknGlobalNote.h>
|
|
51 |
#include <f32file.h>
|
|
52 |
|
|
53 |
namespace
|
|
54 |
{
|
|
55 |
// CONSTANTS
|
|
56 |
_LIT( KProfileSilentTone, "Z:No_Sound.wav" );
|
|
57 |
_LIT( KProfileAudioMimeType, "audio" );
|
|
58 |
_LIT( KProfileRngMimeType, "application/vnd.nokia.ringing-tone" );
|
|
59 |
|
|
60 |
_LIT( KProfileCommonVideoType, "video/*" );
|
|
61 |
_LIT( KProfileRMVideoMimeType, "application/vnd.rn-realmedia" );
|
|
62 |
_LIT( KProfileRMVideoMimeType2, "application/x-pn-realmedia" );
|
|
63 |
_LIT( KProfileSDPVideoMimeType, "application/sdp" );
|
|
64 |
_LIT( KProfilePlainTextType, "text/plain" );
|
|
65 |
// The filename of the resource file
|
|
66 |
_LIT( KProfileResourceFileName, "Z:ProfileSettingsView.RSC" );
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
72 |
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
// CProfileToneHandler::CProfileToneHandler
|
|
75 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
CProfileToneHandler::CProfileToneHandler()
|
|
79 |
{
|
|
80 |
}
|
|
81 |
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
// CProfileToneHandler::ConstructL
|
|
84 |
// Symbian 2nd phase constructor can leave.
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CProfileToneHandler::ConstructL()
|
|
88 |
{
|
|
89 |
DrmConstructL();
|
|
90 |
GetMaxToneFileSizeL();
|
|
91 |
User::LeaveIfError( iFs.Connect() );
|
|
92 |
iProfileEngine = CreateProfileEngineExtendedL( &iFs );
|
|
93 |
// NB. Singleton must be released in the destructor:
|
|
94 |
iProfilesFeatures = &( ProfileUtilityInstanceL().ProfilesLocalFeatures() );
|
|
95 |
|
|
96 |
User::LeaveIfError( iSSSettings.Open() );
|
|
97 |
iSSSettings.Get( ESSSettingsAls, iAlternateLineSetting ); // ignore errors
|
|
98 |
iSSSettings.Register( ESSSettingsAls, *this ); // ignore errors
|
|
99 |
}
|
|
100 |
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
// CProfileToneHandler::NewLC
|
|
103 |
// Two-phased constructor.
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
EXPORT_C CProfileToneHandler* CProfileToneHandler::NewLC()
|
|
107 |
{
|
|
108 |
CProfileToneHandler* self = new( ELeave ) CProfileToneHandler();
|
|
109 |
CleanupStack::PushL( self );
|
|
110 |
self->ConstructL();
|
|
111 |
return self;
|
|
112 |
}
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
// CProfileToneHandler::NewL
|
|
116 |
// Two-phased constructor.
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
EXPORT_C CProfileToneHandler* CProfileToneHandler::NewL()
|
|
120 |
{
|
|
121 |
CProfileToneHandler* self = CProfileToneHandler::NewLC();
|
|
122 |
CleanupStack::Pop( self );
|
|
123 |
return self;
|
|
124 |
}
|
|
125 |
|
|
126 |
// Destructor
|
|
127 |
CProfileToneHandler::~CProfileToneHandler()
|
|
128 |
{
|
|
129 |
iSSSettings.Close();
|
|
130 |
iFs.Close();
|
|
131 |
if( iProfileEngine )
|
|
132 |
{
|
|
133 |
iProfileEngine->Release();
|
|
134 |
}
|
|
135 |
|
|
136 |
if ( iProfilesFeatures )
|
|
137 |
{
|
|
138 |
ReleaseProfileUtility();
|
|
139 |
}
|
|
140 |
|
|
141 |
ReleaseDrm();
|
|
142 |
}
|
|
143 |
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
// CProfileToneHandler::SetActiveProfileRingingToneL
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
EXPORT_C TInt CProfileToneHandler::SetActiveProfileRingingToneL(
|
|
149 |
const TDesC& aFileName )
|
|
150 |
{
|
|
151 |
// Find out the ID of the active profile
|
|
152 |
TInt activeProfileId(
|
|
153 |
User::LeaveIfError( iProfileEngine->ActiveProfileId() ) );
|
|
154 |
|
|
155 |
return SetProfileToneL(
|
|
156 |
activeProfileId, EProfileRingingToneSetting, aFileName );
|
|
157 |
}
|
|
158 |
|
|
159 |
// -----------------------------------------------------------------------------
|
|
160 |
// CProfileToneHandler::SetProfileToneL
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
EXPORT_C TInt CProfileToneHandler::SetProfileToneL( TInt aProfileId,
|
|
164 |
TProfileTones aToneSetting, const TDesC& aFileName )
|
|
165 |
{
|
|
166 |
// Check the file which is tried to set as ringing or alert tone.
|
|
167 |
TInt returnValue( CheckFileL( aFileName ) );
|
|
168 |
returnValue = CheckResultAndProtectionL( returnValue, aFileName );
|
|
169 |
if( returnValue != KErrNone )
|
|
170 |
{
|
|
171 |
return returnValue;
|
|
172 |
}
|
|
173 |
|
|
174 |
DoSetProfileToneL( aProfileId, aToneSetting, aFileName );
|
|
175 |
return KErrNone;
|
|
176 |
}
|
|
177 |
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
// CProfileToneHandler::SetProfileToneNotCheckL
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
EXPORT_C TInt CProfileToneHandler::SetProfileToneNotCheckL( TInt aProfileId,
|
|
183 |
TProfileTones aToneSetting, const TDesC& aFileName )
|
|
184 |
{
|
|
185 |
DoSetProfileToneL( aProfileId, aToneSetting, aFileName );
|
|
186 |
return KErrNone;
|
|
187 |
}
|
|
188 |
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
// CProfileToneHandler::SetToneForAllProfilesL
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
EXPORT_C TInt CProfileToneHandler::SetToneForAllProfilesL(
|
|
194 |
TProfileTones aToneSetting, const TDesC& aFileName )
|
|
195 |
{
|
|
196 |
// Check the file which is tried to set as ringing or alert tone.
|
|
197 |
TInt returnValue( CheckFileL( aFileName ) );
|
|
198 |
returnValue = CheckResultAndProtectionL( returnValue, aFileName );
|
|
199 |
if( returnValue != KErrNone )
|
|
200 |
{
|
|
201 |
return returnValue;
|
|
202 |
}
|
|
203 |
|
|
204 |
const MProfilesNamesArray* idArray = iProfileEngine->ProfilesNamesArrayLC();
|
|
205 |
TInt arrayCount( idArray->MdcaCount() );
|
|
206 |
TInt arrayIndex( 0 );
|
|
207 |
TInt profileId( 0 );
|
|
208 |
TInt activeId( iProfileEngine->ActiveProfileId() );
|
|
209 |
|
|
210 |
// Go through profiles and update tone
|
|
211 |
while( arrayIndex < arrayCount )
|
|
212 |
{
|
|
213 |
profileId = idArray->ProfileName( arrayIndex )->Id();
|
|
214 |
// Updating of the active profile will be done last to make sure that
|
|
215 |
// UI gets the new value of the ringing tone if settings view is active
|
|
216 |
// and it is containing settings of another than active profile
|
|
217 |
if( profileId != activeId )
|
|
218 |
{
|
|
219 |
TRAPD(r, DoSetProfileToneL( profileId, aToneSetting, aFileName ));
|
|
220 |
// Filter situation when profile is not allowed to be changed
|
|
221 |
// e.g. Drive-profile
|
|
222 |
if( ( r != KErrNone ) && ( r != KErrAccessDenied ) )
|
|
223 |
{
|
|
224 |
User::Leave( r );
|
|
225 |
}
|
|
226 |
}
|
|
227 |
arrayIndex++;
|
|
228 |
}
|
|
229 |
CleanupStack::PopAndDestroy(); // idArray
|
|
230 |
|
|
231 |
// Update the active profile:
|
|
232 |
TRAPD(r, DoSetProfileToneL( activeId, aToneSetting, aFileName ));
|
|
233 |
// Filter situation when profile is not allowed to be changed
|
|
234 |
// e.g. Drive-profile
|
|
235 |
if( ( r != KErrNone ) && ( r != KErrAccessDenied ) )
|
|
236 |
{
|
|
237 |
User::Leave( r );
|
|
238 |
}
|
|
239 |
|
|
240 |
return KErrNone;
|
|
241 |
}
|
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
// CProfileToneHandler::PhoneSettingChanged
|
|
245 |
// Callback method inherited from MSSSettingsObserver for getting events if
|
|
246 |
// Alternate Line Service status changes.
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
void CProfileToneHandler::PhoneSettingChanged(
|
|
250 |
TSSSettingsSetting aSetting, TInt aNewValue )
|
|
251 |
{
|
|
252 |
if( aSetting == ESSSettingsAls )
|
|
253 |
{
|
|
254 |
iAlternateLineSetting = aNewValue;
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
// CProfileToneHandler::DoSetProfileToneL
|
|
260 |
// -----------------------------------------------------------------------------
|
|
261 |
//
|
|
262 |
void CProfileToneHandler::DoSetProfileToneL( TInt aProfileId,
|
|
263 |
TProfileTones aToneSetting, const TDesC& aFileName )
|
|
264 |
{
|
|
265 |
// Read the settings of the profile in question
|
|
266 |
MProfileExtended* profile = iProfileEngine->ProfileLC( aProfileId );
|
|
267 |
|
|
268 |
// Get the old tone in order to remove it from the automated content list
|
|
269 |
TFileName oldTone( ReadToneL( *profile, aToneSetting ) );
|
|
270 |
|
|
271 |
TFileName fileName( aFileName );
|
|
272 |
if( fileName.Length() == 0 )
|
|
273 |
{
|
|
274 |
// If no filename is given, replace it with "No_sound.wav". This way
|
|
275 |
// it's possible to e.g. play vibra during incoming call.
|
|
276 |
TParse* fp = new(ELeave) TParse();
|
|
277 |
fp->Set(KProfileSilentTone, &KDC_RESOURCE_FILES_DIR, NULL);
|
|
278 |
fileName.Copy( fp->FullName() );
|
|
279 |
delete fp;
|
|
280 |
}
|
|
281 |
|
|
282 |
// Replace the old tone with the new tone
|
|
283 |
SetToneL( *profile, aToneSetting, fileName );
|
|
284 |
|
|
285 |
// Commit changes. Write the new settings to the Profiles Engine
|
|
286 |
iProfileEngine->CommitChangeL( *profile );
|
|
287 |
|
|
288 |
// Register file as automated content
|
|
289 |
TInt err( SetAutomated( aToneSetting, fileName ) );
|
|
290 |
if( err == KErrNone )
|
|
291 |
{
|
|
292 |
// Remove old tone from the automated content list
|
|
293 |
RemoveAutomated( oldTone );
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
// Put the old tone back into Profiles:
|
|
298 |
TRAP_IGNORE(
|
|
299 |
SetToneL( *profile, aToneSetting, oldTone );
|
|
300 |
iProfileEngine->CommitChangeL( *profile );
|
|
301 |
);
|
|
302 |
}
|
|
303 |
|
|
304 |
CleanupStack::PopAndDestroy(); // profile
|
|
305 |
User::LeaveIfError( err );
|
|
306 |
}
|
|
307 |
|
|
308 |
// -----------------------------------------------------------------------------
|
|
309 |
// CProfileToneHandler::SetToneL
|
|
310 |
// -----------------------------------------------------------------------------
|
|
311 |
//
|
|
312 |
void CProfileToneHandler::SetToneL( MProfileExtended& aProfile,
|
|
313 |
TProfileTones aToneSetting, const TDesC& aFileName )
|
|
314 |
{
|
|
315 |
MProfileSetExtraTones& setExtraTones = aProfile.ProfileSetExtraTones();
|
|
316 |
MProfileSetTones& setTones = aProfile.ProfileSetTones();
|
|
317 |
|
|
318 |
switch( aToneSetting )
|
|
319 |
{
|
|
320 |
case EProfileRingingToneSetting:
|
|
321 |
{
|
|
322 |
if( iAlternateLineSetting == ESSSettingsAlsAlternate )
|
|
323 |
{
|
|
324 |
// Alternate Line Service is supported and alternate line is
|
|
325 |
// selected. Set as ringing tone for line 2.
|
|
326 |
setTones.SetRingingTone2L( aFileName );
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
// Alternate Line Service is not supported or primary line is
|
|
331 |
// selected. Set as ringing tone for line 1.
|
|
332 |
setTones.SetRingingTone1L( aFileName );
|
|
333 |
}
|
|
334 |
break;
|
|
335 |
}
|
|
336 |
case EProfileVideoCallToneSetting:
|
|
337 |
{
|
|
338 |
setExtraTones.SetVideoCallRingingToneL( aFileName );
|
|
339 |
break;
|
|
340 |
}
|
|
341 |
case EProfileMessageAlertToneSetting:
|
|
342 |
{
|
|
343 |
setTones.SetMessageAlertToneL( aFileName );
|
|
344 |
break;
|
|
345 |
}
|
|
346 |
case EProfileInstantMessageAlertToneSetting:
|
|
347 |
{
|
|
348 |
setExtraTones.SetIMMessageAlertToneL( aFileName );
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
case EProfileEmailAlertToneSetting:
|
|
352 |
{
|
|
353 |
setExtraTones.SetEmailAlertToneL( aFileName );
|
|
354 |
break;
|
|
355 |
}
|
|
356 |
default:
|
|
357 |
{
|
|
358 |
User::Leave( KErrArgument );
|
|
359 |
break;
|
|
360 |
}
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
// -----------------------------------------------------------------------------
|
|
365 |
// CProfileToneHandler::ReadToneL
|
|
366 |
// -----------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
const TDesC& CProfileToneHandler::ReadToneL( const MProfileExtended& aProfile,
|
|
369 |
TProfileTones aToneSetting ) const
|
|
370 |
{
|
|
371 |
const MProfileExtraTones& extraTones = aProfile.ProfileExtraTones();
|
|
372 |
const MProfileTones& tones = aProfile.ProfileTones();
|
|
373 |
|
|
374 |
switch( aToneSetting )
|
|
375 |
{
|
|
376 |
case EProfileRingingToneSetting:
|
|
377 |
{
|
|
378 |
if( iAlternateLineSetting == ESSSettingsAlsAlternate )
|
|
379 |
{
|
|
380 |
// Alternate Line Service is supported and alternate line is
|
|
381 |
// selected.
|
|
382 |
return tones.RingingTone2();
|
|
383 |
}
|
|
384 |
else
|
|
385 |
{
|
|
386 |
// Alternate Line Service is not supported or primary line is
|
|
387 |
// selected.
|
|
388 |
return tones.RingingTone1();
|
|
389 |
}
|
|
390 |
}
|
|
391 |
case EProfileVideoCallToneSetting:
|
|
392 |
{
|
|
393 |
return extraTones.VideoCallRingingTone();
|
|
394 |
}
|
|
395 |
case EProfileMessageAlertToneSetting:
|
|
396 |
{
|
|
397 |
return tones.MessageAlertTone();
|
|
398 |
}
|
|
399 |
case EProfileInstantMessageAlertToneSetting:
|
|
400 |
{
|
|
401 |
return extraTones.IMMessageAlertTone();
|
|
402 |
}
|
|
403 |
case EProfileEmailAlertToneSetting:
|
|
404 |
{
|
|
405 |
return extraTones.EmailAlertTone();
|
|
406 |
}
|
|
407 |
default:
|
|
408 |
{
|
|
409 |
User::Leave( KErrArgument );
|
|
410 |
break;
|
|
411 |
}
|
|
412 |
}
|
|
413 |
return KNullDesC;
|
|
414 |
}
|
|
415 |
|
|
416 |
// -----------------------------------------------------------------------------
|
|
417 |
// CProfileToneHandler::CheckFileL
|
|
418 |
// -----------------------------------------------------------------------------
|
|
419 |
//
|
|
420 |
TInt CProfileToneHandler::CheckFileL( const TDesC& aFileName )
|
|
421 |
{
|
|
422 |
if( aFileName.Length() == 0 )
|
|
423 |
{
|
|
424 |
// The filename is empty, ok.
|
|
425 |
// It will be changed to "No_sound.wav" when writing to Profiles Engine.
|
|
426 |
return KErrNone;
|
|
427 |
}
|
|
428 |
|
|
429 |
if( !BaflUtils::FileExists( iFs, aFileName ) )
|
|
430 |
{
|
|
431 |
// The file does not exist. No good (start the dance).
|
|
432 |
return KErrNotFound;
|
|
433 |
}
|
|
434 |
|
|
435 |
TBool isAudio( EFalse );
|
|
436 |
TBool isVideo( EFalse );
|
|
437 |
|
|
438 |
// The file exists. Check its data (MIME) type.
|
|
439 |
TBuf<KMaxDataTypeLength> dataType( DataTypeL( aFileName ) );
|
|
440 |
if( ( dataType.Left( KProfileAudioMimeType()
|
|
441 |
.Length() ).CompareF( KProfileAudioMimeType ) == 0 ) ||
|
|
442 |
( dataType.CompareF( KProfileRngMimeType ) == 0 ) )
|
|
443 |
{
|
|
444 |
isAudio = ETrue;
|
|
445 |
}
|
|
446 |
|
|
447 |
if( dataType.MatchF( KProfileCommonVideoType ) == 0 ||
|
|
448 |
dataType.CompareF( KProfileRMVideoMimeType ) == 0 ||
|
|
449 |
dataType.CompareF( KProfileRMVideoMimeType2 ) == 0 ||
|
|
450 |
dataType.CompareF( KProfileSDPVideoMimeType ) == 0 )
|
|
451 |
{
|
|
452 |
#ifdef RD_VIDEO_AS_RINGING_TONE
|
|
453 |
isVideo = ETrue;
|
|
454 |
#else
|
|
455 |
isVideo = EFalse;
|
|
456 |
#endif
|
|
457 |
}
|
|
458 |
|
|
459 |
if( (!isAudio) && (!isVideo) && (dataType.CompareF(KProfilePlainTextType) != 0) )
|
|
460 |
{
|
|
461 |
// The data type does not start with "audio" or video and it's not RNG file.
|
|
462 |
return KErrNotSupported;
|
|
463 |
}
|
|
464 |
|
|
465 |
// Check whether file is supported by MMF
|
|
466 |
TBuf8<KMaxDataTypeLength> tempDataType;
|
|
467 |
tempDataType.Copy( dataType );
|
|
468 |
if (!ProfileMmfInfoUtility::IsMimeTypeSupportedL(tempDataType)
|
|
469 |
&& !ProfileMmfInfoUtility::IsHeaderDataSupportedL(aFileName))
|
|
470 |
{
|
|
471 |
// File is not supported by MMF
|
|
472 |
return KErrNotSupported;
|
|
473 |
}
|
|
474 |
|
|
475 |
// Operator requirement. Check if the tones of this data type are blocked:
|
|
476 |
if( iProfilesFeatures->IsBlockedType( dataType ) ||
|
|
477 |
iProfilesFeatures->IsExcludedType( dataType ) )
|
|
478 |
{
|
|
479 |
User::Leave( KErrArgument );
|
|
480 |
}
|
|
481 |
|
|
482 |
// Check if the tone is WMDRM protected
|
|
483 |
if( IsFileWMDRMProtectedL( aFileName ) )
|
|
484 |
{
|
|
485 |
return KErrPermissionDenied;
|
|
486 |
}
|
|
487 |
|
|
488 |
TInt result( KErrNone );
|
|
489 |
if( IsProtected( aFileName ) )
|
|
490 |
{
|
|
491 |
// In certain variants tones of certain MIME-types are not allowed as
|
|
492 |
// alert tones if they are DRM-protected, check if this is one:
|
|
493 |
if( iProfilesFeatures->IsBlockedProtectedType( dataType ) )
|
|
494 |
{
|
|
495 |
return KErrArgument;
|
|
496 |
}
|
|
497 |
result = CheckProtectedFileL( aFileName );
|
|
498 |
}
|
|
499 |
else
|
|
500 |
{
|
|
501 |
result = iProfilesFeatures->IsBlockedUnprotectedType( dataType ) ?
|
|
502 |
KErrPermissionDenied : KErrNone;
|
|
503 |
}
|
|
504 |
return result;
|
|
505 |
}
|
|
506 |
|
|
507 |
// -----------------------------------------------------------------------------
|
|
508 |
// CProfileToneHandler::CheckResultAndProtectionL
|
|
509 |
// Find out the mime type of the file
|
|
510 |
// -----------------------------------------------------------------------------
|
|
511 |
//
|
|
512 |
TInt CProfileToneHandler::CheckResultAndProtectionL( TInt aResult,
|
|
513 |
const TDesC& aFileName )
|
|
514 |
{
|
|
515 |
if( aResult == KErrPermissionDenied || aResult == KErrNotSupported ||
|
|
516 |
aResult == KErrNotFound )
|
|
517 |
{
|
|
518 |
User::Leave( aResult );
|
|
519 |
}
|
|
520 |
else if( aResult != KErrNone )
|
|
521 |
{
|
|
522 |
return aResult;
|
|
523 |
}
|
|
524 |
|
|
525 |
// If tone file size is limited,
|
|
526 |
// check if this file's size exceeds this limit.
|
|
527 |
if ( iMaxSizeKB )
|
|
528 |
{
|
|
529 |
if ( CheckToneFileSizeL( aFileName, iMaxSizeKB ) != KErrNone )
|
|
530 |
{
|
|
531 |
ShowSizeErrorNoteL( iMaxSizeKB );
|
|
532 |
return KErrTooBig;
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
if( IsProtected( aFileName ) )
|
|
537 |
{
|
|
538 |
if( !CanSetAutomated( aFileName ) )
|
|
539 |
{
|
|
540 |
// DRM v2 content should be caught here
|
|
541 |
ShowErrorNoteL( R_PROFILE_TEXT_DRM_PREV_RIGHTS_SET );
|
|
542 |
return KErrGeneral;
|
|
543 |
}
|
|
544 |
|
|
545 |
// If the file in question is unactivated protected content,
|
|
546 |
// ask user if he/she wants to activate it.
|
|
547 |
if( AskAutomated( aFileName ) == KErrCancel )
|
|
548 |
{
|
|
549 |
// User doesn't want to activate unactivated protected content.
|
|
550 |
return KErrCancel;
|
|
551 |
}
|
|
552 |
}
|
|
553 |
return KErrNone;
|
|
554 |
}
|
|
555 |
|
|
556 |
// -----------------------------------------------------------------------------
|
|
557 |
// CProfileToneHandler::DataType
|
|
558 |
// Find out the mime type of the file
|
|
559 |
// -----------------------------------------------------------------------------
|
|
560 |
//
|
|
561 |
TBuf<KMaxDataTypeLength> CProfileToneHandler::DataTypeL(
|
|
562 |
const TDesC& aFileName ) const
|
|
563 |
{
|
|
564 |
RApaLsSession apaLsSession;
|
|
565 |
User::LeaveIfError( apaLsSession.Connect() );
|
|
566 |
CleanupClosePushL( apaLsSession );
|
|
567 |
|
|
568 |
TUid dummyUid = { 0 }; // instantiate as zero
|
|
569 |
TDataType dataType( dummyUid );
|
|
570 |
User::LeaveIfError(
|
|
571 |
apaLsSession.AppForDocument( aFileName, dummyUid, dataType ) );
|
|
572 |
|
|
573 |
CleanupStack::PopAndDestroy(); // apaLsSession.Close()
|
|
574 |
return dataType.Des();
|
|
575 |
}
|
|
576 |
|
|
577 |
// -----------------------------------------------------------------------------
|
|
578 |
// CProfileToneHandler::ShowErrorNoteL
|
|
579 |
// -----------------------------------------------------------------------------
|
|
580 |
//
|
|
581 |
void CProfileToneHandler::ShowErrorNoteL( TInt aResourceId ) const
|
|
582 |
{
|
|
583 |
CCoeEnv* coeEnv = CCoeEnv::Static();
|
|
584 |
RConeResourceLoader resourceLoader( *coeEnv );
|
|
585 |
CleanupClosePushL( resourceLoader );
|
|
586 |
|
|
587 |
TParse* fp = new(ELeave) TParse();
|
|
588 |
fp->Set(KProfileResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL);
|
|
589 |
TFileName localizedFileName( fp->FullName() );
|
|
590 |
delete fp;
|
|
591 |
|
|
592 |
resourceLoader.OpenL( localizedFileName );
|
|
593 |
|
|
594 |
HBufC* errorText = StringLoader::LoadLC( aResourceId );
|
|
595 |
CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse );
|
|
596 |
note->ExecuteLD( *errorText );
|
|
597 |
|
|
598 |
// errorText
|
|
599 |
CleanupStack::PopAndDestroy( errorText );
|
|
600 |
// resourceLoader
|
|
601 |
CleanupStack::PopAndDestroy( );
|
|
602 |
}
|
|
603 |
|
|
604 |
// -----------------------------------------------------------------------------
|
|
605 |
// CProfileToneHandler::ShowSizeErrorNoteL
|
|
606 |
// -----------------------------------------------------------------------------
|
|
607 |
//
|
|
608 |
void CProfileToneHandler::ShowSizeErrorNoteL( TInt aSizeLimitKB )
|
|
609 |
{
|
|
610 |
CCoeEnv* coeEnv = CCoeEnv::Static();
|
|
611 |
RConeResourceLoader resourceLoader( *coeEnv );
|
|
612 |
CleanupClosePushL( resourceLoader );
|
|
613 |
|
|
614 |
TParse* fp = new(ELeave) TParse();
|
|
615 |
CleanupStack::PushL( fp );
|
|
616 |
fp->Set( KProfileResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL);
|
|
617 |
|
|
618 |
TFileName* fileName = new( ELeave ) TFileName();
|
|
619 |
fileName->Copy( fp->FullName() );
|
|
620 |
CleanupStack::PushL( fileName );
|
|
621 |
resourceLoader.OpenL( *fileName );
|
|
622 |
CleanupStack::PopAndDestroy( fileName );
|
|
623 |
|
|
624 |
HBufC* errorText = StringLoader::LoadLC( R_PROFILE_TEXT_TONE_MAXSIZE_ERROR, aSizeLimitKB );
|
|
625 |
CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse );
|
|
626 |
note->ExecuteLD( *errorText );
|
|
627 |
|
|
628 |
CleanupStack::PopAndDestroy( errorText );
|
|
629 |
CleanupStack::PopAndDestroy( fp );
|
|
630 |
CleanupStack::PopAndDestroy( &resourceLoader );
|
|
631 |
}
|
|
632 |
|
|
633 |
// -----------------------------------------------------------------------------
|
|
634 |
// CProfileToneHandler::GetMaxToneFileSizeL
|
|
635 |
// -----------------------------------------------------------------------------
|
|
636 |
//
|
|
637 |
void CProfileToneHandler::GetMaxToneFileSizeL()
|
|
638 |
{
|
|
639 |
CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
|
|
640 |
CleanupStack::PushL( cenrep );
|
|
641 |
TInt error = cenrep->Get( KProEngRingingToneMaxSize, iMaxSizeKB );
|
|
642 |
CleanupStack::PopAndDestroy( cenrep );
|
|
643 |
if ( error != KErrNone )
|
|
644 |
{
|
|
645 |
iMaxSizeKB = 0;
|
|
646 |
}
|
|
647 |
if ( iMaxSizeKB < 0 )
|
|
648 |
{
|
|
649 |
iMaxSizeKB = 0;
|
|
650 |
}
|
|
651 |
}
|
|
652 |
|
|
653 |
// -----------------------------------------------------------------------------
|
|
654 |
// CProfileToneHandler::CheckToneFileSizeL
|
|
655 |
// -----------------------------------------------------------------------------
|
|
656 |
//
|
|
657 |
TInt CProfileToneHandler::CheckToneFileSizeL( const TDesC& aFile,
|
|
658 |
TInt aSizeLimitKB )
|
|
659 |
{
|
|
660 |
// Get file size
|
|
661 |
TInt size = 0;
|
|
662 |
TInt error = KErrNone;
|
|
663 |
|
|
664 |
TEntry entry;
|
|
665 |
if ( iFs.Entry( aFile, entry ) == KErrNone )
|
|
666 |
{
|
|
667 |
size = entry.iSize;
|
|
668 |
}
|
|
669 |
|
|
670 |
// Check. NOTE: now if file size couldn't be determined, check fails.
|
|
671 |
aSizeLimitKB *= KKilo;
|
|
672 |
if ( aSizeLimitKB && size > aSizeLimitKB )
|
|
673 |
{
|
|
674 |
error = KErrTooBig;
|
|
675 |
}
|
|
676 |
|
|
677 |
return error;
|
|
678 |
}
|
|
679 |
|
|
680 |
|
|
681 |
// End of File
|