profilesapplication/Profiles/ProfileAiwProvider/src/CProfileAiwProvider.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Profile Aiw service provider.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //	CLASS HEADER
       
    20 #include "CProfileAiwProvider.h"
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "CProfileEngineHandler.h"
       
    24 #include "CPapPopupList.h"
       
    25 
       
    26 //	EXTERNAL INCLUDES
       
    27 #include <AiwMenu.h>	// For CAiwMenuPane
       
    28 #include <AiwCommon.hrh> // For KAiwCmdAssign
       
    29 #include <AiwCommon.h> // For MAiwNotifyCallback
       
    30 #include <barsread.h>	// For TResourceReader
       
    31 #include <profileaiwproviderresource.rsg> // For resource texts
       
    32 #include <data_caging_path_literals.hrh>
       
    33 #include <coemain.h> // CCoeEnv
       
    34 #include <ConeResLoader.h> // RConeResourceLoader
       
    35 #include <StringLoader.h>
       
    36 #include <aknnotewrappers.h> // For CAknInformationNote
       
    37 #include <aknlists.h>	// For CAknSingleGraphicPopupMenuStyleListBox
       
    38 #include <cprofiletonehandler.h>
       
    39 #include <MProfilesNamesArray.h>
       
    40 #include <MProfileName.h>
       
    41 #include <MProfileEngineExtended.h>
       
    42 #include <MProfileExtended.h>
       
    43 #include <ProfileEngineDomainCRKeys.h>
       
    44 #include <ProfileEng.hrh>	// For PROFILES_MAX_NAME_LENGTH
       
    45 #include <eikfutil.h>	// For EikFileUtils
       
    46 #include <centralrepository.h>
       
    47 #include <featmgr.h>
       
    48 #include <pathinfo.h>
       
    49 #include <driveinfo.h>
       
    50 
       
    51 #ifdef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
    52 #include <drmutility.h>
       
    53 #include <drmagents.h>
       
    54 #endif
       
    55 
       
    56 
       
    57 //	CONSTANTS
       
    58 namespace
       
    59 	{
       
    60 	_LIT( KProfileAiwProviderResourceFileName, "z:ProfileAiwProviderResource.rsc" );
       
    61 	// Allowed MIME types
       
    62 	_LIT( KAudioCommonMimeType, "audio/*");
       
    63 	_LIT( KAudioRngMimeType,    "application/vnd.nokia.ringing-tone" );
       
    64 #ifdef RD_VIDEO_AS_RINGING_TONE	
       
    65 	_LIT( KVideoCommonMimeType, "video/*");
       
    66 	_LIT( KRMVideoMimeType, "application/vnd.rn-realmedia" );
       
    67 	_LIT( KRMVideoMimeType2, "application/x-pn-realmedia" );
       
    68 	_LIT( KSDPVideoMimeType, "application/sdp" );
       
    69 #endif	
       
    70 	// Granularities
       
    71 	const TInt KArrayGranularity( 3 );
       
    72 	// List item format
       
    73 	_LIT( KProfileAIWProviderIconAndTab, "1\t");
       
    74 	// Maximum profile name length
       
    75 	const TInt KProfileAiwProviderMaxNameLength( PROFILES_MAX_NAME_LENGTH );
       
    76 	}
       
    77 
       
    78 // ============================ MEMBER FUNCTIONS ===============================
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CProfileAiwProvider::NewL
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CProfileAiwProvider* CProfileAiwProvider::NewL()
       
    86     {
       
    87     CProfileAiwProvider* self = new(ELeave) CProfileAiwProvider;
       
    88     CleanupStack::PushL(self);
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop(self);
       
    91     return self;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CProfileAiwProvider::CProfileAiwProvider
       
    96 // C++ default constructor can NOT contain any code, that might leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CProfileAiwProvider::CProfileAiwProvider()
       
   100     {
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CProfileAiwProvider::ConstructL
       
   105 // Symbian 2nd phase constructor can leave.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CProfileAiwProvider::ConstructL()
       
   109     {
       
   110     FeatureManager::InitializeLibL();
       
   111     TParse* fp = new(ELeave) TParse();
       
   112 	fp->Set(KProfileAiwProviderResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   113 	TFileName resourceFileName( fp->FullName() );
       
   114 	delete fp;
       
   115 
       
   116     // Get language of resource file
       
   117     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFileName );
       
   118     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( resourceFileName );
       
   119     iProfileToneHandler = CProfileToneHandler::NewL();
       
   120     // Move this to PopulateListBox()
       
   121     //iEngineHandler = CProfileEngineHandler::NewL();
       
   122 
       
   123     TResourceReader reader;
       
   124     CCoeEnv::Static()->CreateResourceReaderLC( reader,
       
   125                                                R_PROFILEAIWPROVIDER_MENU );
       
   126     // load strings from resource
       
   127 	iWMAErrorText = StringLoader::LoadL(
       
   128         R_PROFILEAIWPROVIDER_TEXT_NOT_ALLOWED );
       
   129 	iMP4ErrorText = StringLoader::LoadL(
       
   130         R_PROFILEAIWPROVIDER_INFO_TONE_DRM_PROTECTED );
       
   131 	iUnprotectedErrorText = StringLoader::LoadL(
       
   132         R_PROFILEAIWPROVIDER_INFO_TONE_NO_DRM );
       
   133 	iNotSupportedErrorText = StringLoader::LoadL(
       
   134         R_PROFILEAIWPROVIDER_INFO_MIME_TYPE_NOT_SUPPORTED );
       
   135 	iPopupTitle = StringLoader::LoadL(
       
   136         R_PROFILEAIWPROVIDER_QUERY_SELECT_PROFILES );
       
   137 	iChangedProfilesText = StringLoader::LoadL(
       
   138         R_PROFILEAIWPROVIDER_CONFIRM_RINGTONE_CHANGED );
       
   139     iCopiedAndChangedText = StringLoader::LoadL(
       
   140         R_PROFILEAIWPROVIDER_CONFIRM_RINGTONE_COPIED );
       
   141 
       
   142     // Read the maximum limit for the size of a tone file:
       
   143 	CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
       
   144 	CleanupStack::PushL( cenrep );
       
   145     User::LeaveIfError( cenrep->Get( KProEngRingingToneMaxSize, iMaxSize ) );
       
   146 	CleanupStack::PopAndDestroy( cenrep );
       
   147 	iSizeErrorText = StringLoader::LoadL(
       
   148         R_PROFILEAIWPROVIDER_TONE_MAXSIZE_ERROR, iMaxSize );
       
   149 
       
   150 	CleanupStack::PopAndDestroy(); // reader
       
   151 	}
       
   152 
       
   153 // Destructor
       
   154 CProfileAiwProvider::~CProfileAiwProvider()
       
   155     {
       
   156     delete iIndexToIdArray;
       
   157 	delete iWMAErrorText;
       
   158 	delete iMP4ErrorText;
       
   159 	delete iUnprotectedErrorText;
       
   160 	delete iNotSupportedErrorText;
       
   161 	delete iPopupTitle;
       
   162 	delete iChangedProfilesText;
       
   163 	delete iSizeErrorText;
       
   164 	delete iCopiedAndChangedText;
       
   165 
       
   166 	delete iProfileToneHandler;
       
   167 	delete iEngineHandler;
       
   168     CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
   169     FeatureManager::UnInitializeLib();
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CProfileAiwProvider::InitialiseL
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CProfileAiwProvider::InitialiseL( MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   178                                        const RCriteriaArray& /*aInterest*/ )
       
   179     {
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CProfileAiwProvider::HandleServiceCmdL
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CProfileAiwProvider::HandleServiceCmdL( const TInt& aCmdId,
       
   188                                              const CAiwGenericParamList& aInParamList,
       
   189                                              CAiwGenericParamList& /*aOutParamList*/,
       
   190                                              TUint aCmdOptions,
       
   191                                              const MAiwNotifyCallback* aCallback )
       
   192     {
       
   193      // Cope with the design problems of AIW framework
       
   194     iConstNotifyCallback = const_cast<MAiwNotifyCallback*> (aCallback);
       
   195 
       
   196 	if( aCmdOptions & KAiwOptCancel )
       
   197 		{
       
   198 		if( iPopup )
       
   199 			{
       
   200 			iPopup->CancelPopup();
       
   201 		    iPopup = NULL;
       
   202 			}
       
   203 		return;
       
   204 		}
       
   205 
       
   206   	if( aCmdId == KAiwCmdAssign )
       
   207     	{
       
   208         // Retrieve filename and file MIME type from AIW param list
       
   209 		TPtrC fileName =
       
   210 			GetAiwParamAsDescriptor(aInParamList, EGenericParamFile);
       
   211 
       
   212 		TPtrC mimeTypeString =
       
   213 			GetAiwParamAsDescriptor(aInParamList, EGenericParamMIMEType);
       
   214 
       
   215 		// Leave, if there were not given all the required parameters
       
   216 		if ((fileName == KNullDesC) || (mimeTypeString == KNullDesC))
       
   217 			{
       
   218 			return;
       
   219 			}
       
   220 
       
   221 		if( !CheckMimeTypeL( mimeTypeString ) )
       
   222 			{
       
   223 			// Not supported format
       
   224             ShowErrorNoteL( *iNotSupportedErrorText );
       
   225 			}
       
   226 		else if( IsFileWMDRMProtectedL( fileName ) )
       
   227 			{
       
   228 			ShowErrorNoteL( *iMP4ErrorText );
       
   229 			}
       
   230         else if( !IsToneFileSizeOkL( fileName ) )
       
   231             {
       
   232 			// Too big file
       
   233             ShowErrorNoteL( *iSizeErrorText );
       
   234             }
       
   235 		else
       
   236 			{
       
   237 			LaunchL( *iPopupTitle, fileName );
       
   238 			}
       
   239 		}
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CProfileAiwProvider::PerformProfileChangeL
       
   244 // (other items were commented in a header).
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CProfileAiwProvider::PerformProfileChangeL(
       
   248  const TDesC& aFileName, const TBool& aChangeAllProfiles ) const
       
   249 	{
       
   250 	TInt count( iSelectionArray->Count() );
       
   251 	TInt err( KErrNone );
       
   252 	TInt r( KErrNone );
       
   253 
       
   254 	// Check location of the tone and copy if needed
       
   255 	TFileName target;
       
   256 	TBool remote = CopyIfRemoteL( aFileName, target );
       
   257 
       
   258 	if( aChangeAllProfiles )
       
   259 		{
       
   260 		if( remote )
       
   261 			{
       
   262 			TRAP( r, err = iProfileToneHandler->SetToneForAllProfilesL(
       
   263 		    	EProfileRingingToneSetting, target ) );
       
   264 			}
       
   265 		else
       
   266 			{
       
   267 			TRAP( r, err = iProfileToneHandler->SetToneForAllProfilesL(
       
   268 	        	EProfileRingingToneSetting, aFileName ) );
       
   269 			}
       
   270 		}
       
   271 	else
       
   272 		{
       
   273         TInt profileId( 0 );
       
   274 		for( TInt index(0); index < count; index++ )
       
   275 			{
       
   276 			profileId = iIndexToIdArray->At( iSelectionArray->At( index ) );
       
   277 			
       
   278             if( remote )
       
   279                 {
       
   280                 // The first time set the tone, use SetProfileToneL to check the file
       
   281                 if ( index == 0 )
       
   282                     {
       
   283 
       
   284                     TRAP( r, err = iProfileToneHandler->SetProfileToneL( 
       
   285                        profileId, EProfileRingingToneSetting, target ) );
       
   286                     }
       
   287                 // the file has been checked at first time, use SetProfileToneL to
       
   288                 // avoid repeat check.
       
   289                 else
       
   290                     {
       
   291                     TRAP( r, err = iProfileToneHandler->SetProfileToneNotCheckL(
       
   292                         profileId, EProfileRingingToneSetting, target ) );
       
   293                     }
       
   294                 }
       
   295             else
       
   296                 {
       
   297                 // The first time set the tone, use SetProfileToneL to check the file
       
   298                 if ( index == 0 )
       
   299                     {
       
   300                     TRAP( r, err = iProfileToneHandler->SetProfileToneL( profileId,
       
   301                         EProfileRingingToneSetting, aFileName ) );
       
   302                     }
       
   303                 // the file has been checked at first time, use SetProfileToneL to
       
   304                 // avoid repeat check.
       
   305                 else
       
   306                     {
       
   307                     TRAP( r, err = iProfileToneHandler->SetProfileToneNotCheckL( 
       
   308                         profileId, EProfileRingingToneSetting, aFileName ) );                    
       
   309                     }
       
   310                     				
       
   311                 }
       
   312 
       
   313             // KErrNotFound is checked for the unlikely case in which the user
       
   314             // has first popped up the list of profiles and then switched to
       
   315             // Profiles App and deleted a profile or more, and finally completed
       
   316             // this "assigned to ringing tone" operation
       
   317             if( r == KErrNotFound )
       
   318                 {
       
   319                 r = KErrNone;
       
   320                 }
       
   321             // The case r == KErrAccessDenied needn't be checked since only
       
   322             // those profiles that are modifiable are included in the list in
       
   323             // PopulateListBoxL() below
       
   324             if( r != KErrNone || err != KErrNone )
       
   325                 {
       
   326                 // no use to go on with other profiles if the tone can not be
       
   327                 // assigned as an alert tone:
       
   328                 break;
       
   329                 }
       
   330 			}
       
   331 		}
       
   332 
       
   333 	if( r == KErrPermissionDenied )
       
   334 		{
       
   335 		// Unprotected DRM tone case
       
   336         ShowErrorNoteL( *iUnprotectedErrorText );
       
   337 		}
       
   338 	else if( r == KErrArgument )
       
   339 		{
       
   340 		// WMA case
       
   341         ShowErrorNoteL( *iWMAErrorText );
       
   342 		}
       
   343 	else if( r != KErrNone )
       
   344 		{
       
   345 		User::Leave( r );
       
   346 		}
       
   347 
       
   348 	if ( err == KErrArgument )
       
   349     	{
       
   350     	// MP4 case
       
   351         ShowErrorNoteL( *iMP4ErrorText );
       
   352         }
       
   353 
       
   354 	if( ( err == KErrNone ) && ( r == KErrNone )  && ( count > 0 ) )
       
   355 		{
       
   356 	   	CAknConfirmationNote* note = new( ELeave ) CAknConfirmationNote( EFalse );
       
   357 	   	if( remote )
       
   358 	   		{
       
   359 	    	note->ExecuteLD( iCopiedAndChangedText->Des() );
       
   360 	   		}
       
   361 	   	else
       
   362 	   		{
       
   363 	    	note->ExecuteLD( iChangedProfilesText->Des() );
       
   364 	   		}
       
   365    		}
       
   366 	}
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CProfileAiwProvider::LaunchL
       
   370 // (other items were commented in a header).
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CProfileAiwProvider::LaunchL( const TDesC& aPopupTitle,
       
   374                                    const TDesC& aFileName )
       
   375 	{
       
   376 	// create listbox
       
   377  	// list item string format: "0\tLabel" where 0 is an index to icon array
       
   378     CEikFormattedCellListBox* listBox =
       
   379       new ( ELeave ) CAknSingleGraphicPopupMenuStyleListBox;
       
   380 	CleanupStack::PushL( listBox );
       
   381 
       
   382     // create popup
       
   383     CPapPopupList* popup = CPapPopupList::NewL( listBox,
       
   384     	R_AVKON_SOFTKEYS_OK_CANCEL__UNMARK );
       
   385  	CleanupStack::PushL( popup );
       
   386  	popup->SetTitleL( aPopupTitle );
       
   387 
       
   388 #ifdef RD_SCALABLE_UI_V2
       
   389 	if( AknLayoutUtils::PenEnabled() )
       
   390 		{
       
   391 		listBox->ConstructL( popup, EAknListBoxStylusMultiselectionList );
       
   392 		}
       
   393 	else
       
   394 		{
       
   395 		listBox->ConstructL( popup, EAknListBoxMultiselectionList );
       
   396 		}
       
   397 #else
       
   398 	listBox->ConstructL( popup, EAknListBoxMultiselectionList );
       
   399 #endif
       
   400 
       
   401 	listBox->CreateScrollBarFrameL(ETrue);
       
   402 	listBox->ScrollBarFrame()->
       
   403 		SetScrollBarVisibilityL(
       
   404 		 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   405 
       
   406 	popup->SetIconsL();
       
   407 
       
   408 	// create model
       
   409     CDesCArrayFlat* items = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   410 
       
   411 	// populate model
       
   412 	CleanupStack::PushL(items);
       
   413 	CProfileAiwProvider::PopulateListBoxL( items );
       
   414 	CleanupStack::Pop(items);
       
   415 
       
   416 	CTextListBoxModel* model = listBox->Model();
       
   417     model->SetItemTextArray(items);
       
   418 
       
   419 	// set all items as selected
       
   420 	TInt count( listBox->Model()->NumberOfItems() );
       
   421 	for( TInt index( 0 ); index < count; index++ )
       
   422 		{
       
   423 		listBox->View()->SelectItemL( index );
       
   424 		}
       
   425 
       
   426 	TBool changeAllProfiles( EFalse );
       
   427 
       
   428     // launch popup
       
   429     iPopup = popup;
       
   430     TInt res = popup->ExecuteLD();
       
   431    	// No leaving functions allowed between executeLD and CleanupStack::Pop().
       
   432     CleanupStack::Pop( popup );
       
   433     iPopup = NULL;
       
   434 
       
   435     if( res )
       
   436     	{
       
   437     	iSelectionArray = listBox->View()->SelectionIndexes();
       
   438     	if( count == iSelectionArray->Count() )
       
   439     		{
       
   440     		// User has selected to change all profiles
       
   441     		changeAllProfiles = ETrue;
       
   442     		}
       
   443 	   	CProfileAiwProvider::PerformProfileChangeL( aFileName, changeAllProfiles );
       
   444     	}
       
   445     CleanupStack::PopAndDestroy(); // listBox
       
   446 	}
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CProfileAiwProvider::PopulateListBoxL
       
   450 // (other items were commented in a header).
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 void CProfileAiwProvider::PopulateListBoxL( CDesCArrayFlat* aItems )
       
   454 	{
       
   455 	// iEngineHandler must be instantiated each time to make sure
       
   456 	// profile list is up to date
       
   457 	delete iEngineHandler;
       
   458 	iEngineHandler = NULL;
       
   459     iEngineHandler = CProfileEngineHandler::NewL();
       
   460 	
       
   461 	MProfilesNamesArray* array = iEngineHandler->IdArray();
       
   462 	MProfileEngineExtended* engine = iEngineHandler->Engine();
       
   463 
       
   464     // Create the mapping array so that the IDs can be mapped to Profile IDs
       
   465     // after the selection has been made
       
   466     // Delete it first in case we're called several times (in the same instance)
       
   467     delete iIndexToIdArray;
       
   468     iIndexToIdArray = NULL;
       
   469     iIndexToIdArray = new ( ELeave ) CArrayFixFlat<TInt>( array->MdcaCount() );
       
   470 
       
   471 	// Add items
       
   472     TInt count( array->MdcaCount() );
       
   473 	TBuf<PROFILES_MAX_NAME_LENGTH + 3> name; // + 3 for icon and tab characters
       
   474 	for( TInt index( 0 ); index < count; index++ )
       
   475     	{
       
   476         const MProfileName* profileName = array->ProfileName( index );
       
   477         if( !profileName ) 
       
   478             {
       
   479             continue;
       
   480             }
       
   481 
       
   482         TInt profileId( profileName->Id() );
       
   483         // Only the profiles which modifiable flag of ringing tone item is
       
   484         // enabled should be included in the list. In Off-line profile case also
       
   485         // VoIP and WLAN must be supported (otherwise there wouldn't be need for
       
   486         // ringing tone in Off-line profile)
       
   487         if( ( profileId != EProfileOffLineId ) ||
       
   488             ( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) &&
       
   489               FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ) ) )
       
   490             {
       
   491             MProfileExtended* profile( engine->ProfileLC( profileId ) );
       
   492             TUint32 modFlags( profile->ModifiableFlags() );
       
   493             CleanupStack::PopAndDestroy(); // profile
       
   494             // Only the profiles which ringing tone item is modifiable should
       
   495             // be included in the list
       
   496             if( modFlags & EProfileFlagRingingTone )
       
   497                 {
       
   498                 name.Copy( KProfileAIWProviderIconAndTab );
       
   499                 TBuf< KProfileAiwProviderMaxNameLength >
       
   500                     tmpName( array->MdcaPoint( index ) );
       
   501                 AknTextUtils::ReplaceCharacters( tmpName,
       
   502                                                  KAknReplaceListControlChars,
       
   503                                                  TChar( ' ' ) );
       
   504                 name.Append( tmpName );
       
   505                 aItems->AppendL( name );
       
   506                 iIndexToIdArray->AppendL( profileId );
       
   507                 }
       
   508             }
       
   509         }
       
   510     iIndexToIdArray->Compress();
       
   511 	}
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CProfileAiwProvider::InitializeMenuPaneL
       
   515 // (other items were commented in a header).
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CProfileAiwProvider::InitializeMenuPaneL( CAiwMenuPane& aMenuPane,
       
   519                                              TInt aIndex,
       
   520                                              TInt /*aCascadeId*/,
       
   521                                              const CAiwGenericParamList& aInParamList )
       
   522     {
       
   523     TResourceReader reader;
       
   524     CCoeEnv::Static()->CreateResourceReaderLC( reader,
       
   525                                                R_PROFILEAIWPROVIDER_MENU );
       
   526 
       
   527  	// Retrieve filename and file MIME type from AIW param list
       
   528 	TPtrC mimeTypeString = CProfileAiwProvider::GetAiwParamAsDescriptor
       
   529 		(aInParamList, EGenericParamMIMEType);
       
   530 
       
   531 	if( CProfileAiwProvider::CheckMimeTypeL( mimeTypeString ) )
       
   532 		{
       
   533 		// Only add menuitem if MIME type is valid
       
   534 		aMenuPane.AddMenuItemsL( reader, KAiwCmdAssign, aIndex );
       
   535 		}
       
   536 
       
   537     CleanupStack::PopAndDestroy(); // reader
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CProfileAiwProvider::HandleMenuCmdL
       
   542 // (other items were commented in a header).
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 void CProfileAiwProvider::HandleMenuCmdL( TInt aMenuCmdId,
       
   546                                         const CAiwGenericParamList& aInParamList,
       
   547                                         CAiwGenericParamList& aOutParamList,
       
   548                                         TUint aCmdOptions,
       
   549                                         const MAiwNotifyCallback* aCallback )
       
   550     {
       
   551     // Route to HandleServiceCmdL
       
   552     HandleServiceCmdL(aMenuCmdId, aInParamList,
       
   553         aOutParamList, aCmdOptions, aCallback);
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CProfileAiwProvider::GetAiwParamAsDescriptor
       
   558 // (other items were commented in a header).
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 TPtrC CProfileAiwProvider::GetAiwParamAsDescriptor(
       
   562 		const CAiwGenericParamList& aParamList,
       
   563 		TGenericParamId aParamType)
       
   564 	{
       
   565 	TInt index = 0;
       
   566 	const TAiwGenericParam* genericParam = NULL;
       
   567     genericParam = aParamList.FindFirst(
       
   568         index,
       
   569         aParamType,
       
   570         EVariantTypeDesC);
       
   571 
       
   572     if (index >= 0 && genericParam)
       
   573         {
       
   574         // Get the data
       
   575         return genericParam->Value().AsDes();
       
   576         }
       
   577 	else
       
   578     	{
       
   579 		return KNullDesC();
       
   580     	}
       
   581 	}
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CProfileAiwProvider::CheckMimeTypeL
       
   585 // (other items were commented in a header).
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 TBool CProfileAiwProvider::CheckMimeTypeL(const TDesC& aMimeTypeString)
       
   589     {
       
   590     if( ( aMimeTypeString.MatchF( KAudioCommonMimeType ) == 0 ) ||
       
   591 		( aMimeTypeString.CompareF( KAudioRngMimeType ) == 0 ) )
       
   592     	{
       
   593     	iIsVideo = EFalse;
       
   594     	return ETrue;
       
   595     	}
       
   596 
       
   597 #ifdef RD_VIDEO_AS_RINGING_TONE	
       
   598     if( aMimeTypeString.MatchF( KVideoCommonMimeType ) == 0 ||
       
   599 		aMimeTypeString.CompareF( KRMVideoMimeType ) == 0 ||
       
   600 		aMimeTypeString.CompareF( KRMVideoMimeType2 ) == 0 ||
       
   601 		aMimeTypeString.CompareF( KSDPVideoMimeType ) == 0 )
       
   602         {
       
   603         iIsVideo = ETrue;
       
   604 		return ETrue;
       
   605         }
       
   606 #endif
       
   607 
       
   608 	return EFalse;
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CProfileAiwProvider::IsToneFileSizeOkL
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 TBool CProfileAiwProvider::IsToneFileSizeOkL( const TDesC& aFile )
       
   616     {
       
   617     if( !iMaxSize )
       
   618         { // no limit set -> every tone will be ok (what comes to size):
       
   619         return ETrue;
       
   620         }
       
   621 
       
   622     // Get file size
       
   623     TInt size = 0;
       
   624     TBool result( ETrue );
       
   625 
       
   626     TEntry entry;
       
   627     if ( CCoeEnv::Static()->FsSession().Entry( aFile, entry ) == KErrNone )
       
   628         {
       
   629         size = entry.iSize;        
       
   630         }
       
   631 
       
   632 	// Check. NOTE: now if file size couldn't be determined, check fails.
       
   633 	if ( size > (iMaxSize*KKilo) )
       
   634 		{
       
   635         result = EFalse;
       
   636 		}
       
   637 
       
   638     return result;
       
   639     }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CProfileAiwProvider::ShowErrorNoteL
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 void CProfileAiwProvider::ShowErrorNoteL( const TDesC& aErrorText ) const
       
   646     {
       
   647     CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse );
       
   648     note->ExecuteLD( aErrorText );
       
   649     }
       
   650 
       
   651 
       
   652 // -----------------------------------------------------------------------------
       
   653 // CProfileAiwProvider::CopyIfRemoteL
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 TBool CProfileAiwProvider::CopyIfRemoteL( const TDesC& aFileName, TFileName& aTarget ) const
       
   657     {
       
   658     TBool remote( EFalse );
       
   659 	TParsePtrC parsedName( aFileName );
       
   660 	RFs& fsSession( CCoeEnv::Static()->FsSession() );
       
   661     TDriveUnit driveUnit( parsedName.Drive() );
       
   662 	TUint driveStatus( 0 );
       
   663 
       
   664 	DriveInfo::GetDriveStatus( fsSession, driveUnit, driveStatus );
       
   665 	remote = ( ( driveStatus & DriveInfo::EDriveRemote ) == DriveInfo::EDriveRemote );
       
   666 
       
   667 	if( remote )
       
   668 		{
       
   669 		// If the tone is on a remote drive, it must be copied
       
   670 		aTarget.Insert( 0, parsedName.NameAndExt() );
       
   671 		if( iIsVideo )
       
   672 			{
       
   673 			aTarget.Insert( 0, PathInfo::VideosPath() );
       
   674 			}
       
   675 		else
       
   676 			{
       
   677 			aTarget.Insert( 0, PathInfo::SoundsPath() );
       
   678 			}
       
   679 		aTarget.Insert( 0, PathInfo::PhoneMemoryRootPath() );
       
   680 		User::LeaveIfError( EikFileUtils::CopyFile( aFileName, aTarget ) );
       
   681 		}
       
   682 
       
   683 	return remote;
       
   684     }
       
   685 
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 //
       
   689 // Functions related to WMDRM protection check
       
   690 //
       
   691 // -----------------------------------------------------------------------------
       
   692 
       
   693 #ifndef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   694 
       
   695 // Some magic constants
       
   696 static const TInt KMinContentLength( 16 );
       
   697 //_LIT8( KContentProtectionType, "DRM" );
       
   698 _LIT8( KASFHeaderObject, "75B22630668E11CFA6D900AA0062CE6C" );
       
   699 _LIT8( KWrmHeader, "W\0R\0M\0H\0E\0A\0D\0E\0R\0" );
       
   700 
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // FormatGUID
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 LOCAL_C void FormatGUID( TDes8& aGUID )
       
   707     {
       
   708     TBuf8<16> copyGUID( aGUID );
       
   709     TInt i;
       
   710     for( i = 0; i < 4; i++ )
       
   711         {
       
   712         copyGUID[i] = aGUID[3-i];
       
   713         }
       
   714     for( i = 4; i < 6; i++ )
       
   715         {
       
   716         copyGUID[i] = aGUID[9 - i];
       
   717         }
       
   718     for( i = 6; i < 8; i++ )
       
   719         {
       
   720         copyGUID[i] = aGUID[13 - i];
       
   721         }
       
   722     for( i = 8; i < 16 ; i++ )
       
   723         {
       
   724         copyGUID[i] = aGUID[i];
       
   725         }
       
   726     aGUID.Delete( 0, 32 );
       
   727     for( i = 0; i <16; i++ )
       
   728         {
       
   729         aGUID.AppendNumFixedWidthUC( copyGUID[i], EHex, 2 );
       
   730         }
       
   731     }
       
   732 
       
   733 // -----------------------------------------------------------------------------
       
   734 // ConvertToInt64
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 LOCAL_C TInt64 ConvertToInt64( TDesC8& aDes )
       
   738     {
       
   739     TInt64 num = 0;
       
   740     TInt i;
       
   741     for( i = 7 ; i >= 0; i-- )
       
   742         {
       
   743         num <<= 8;
       
   744         num |= aDes[i];
       
   745         }
       
   746     return num;
       
   747     }
       
   748 
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // IsProtectedWmDrmL
       
   752 // returns ETrue, if file is protected WMDRM file
       
   753 //         EFalse if file is not protected WMDRM file
       
   754 // Leaves with KErrUnderflow if file has too little data to decide
       
   755 //         whether WmDrm or not
       
   756 //         may also leave with other system wide error code
       
   757 // -----------------------------------------------------------------------------
       
   758 //
       
   759 LOCAL_C TBool IsProtectedWmDrmL( RFile& aFileHandle )
       
   760     {
       
   761     TInt r( KErrNone );
       
   762     HBufC8* buffer( NULL );
       
   763     TInt pos( 0 );
       
   764     RFile file;
       
   765     TBuf8< 32 > header;
       
   766 
       
   767     TInt64 headerSize( 0 );
       
   768     TBool isProtectedWmDrm( EFalse );
       
   769     TPtr8 headerPtr( NULL, 0 );
       
   770 
       
   771     // Leave if given handle is invalid
       
   772     if( !aFileHandle.SubSessionHandle() )
       
   773         {
       
   774         User::Leave( KErrBadHandle );
       
   775         }
       
   776 
       
   777     User::LeaveIfError( file.Duplicate( aFileHandle ) );
       
   778     CleanupClosePushL( file );
       
   779 
       
   780     User::LeaveIfError( file.Seek( ESeekStart, pos ) );
       
   781 
       
   782     // Check if the file is an ASF file
       
   783     // : Check on runtime wether WM DRM is supporeted or not
       
   784 
       
   785     User::LeaveIfError( file.Read( 0, header, KMinContentLength ) );
       
   786     if( header.Length() < KMinContentLength )
       
   787         {
       
   788         User::Leave( KErrUnderflow );
       
   789         }
       
   790 
       
   791     FormatGUID( header );
       
   792 
       
   793     if( header == KASFHeaderObject )
       
   794         {
       
   795         // It's ASF, check still whether it's WM DRM protected or not
       
   796         file.Read( header,8 );
       
   797         headerSize = ConvertToInt64( header );
       
   798         if( headerSize <= 30 )
       
   799             {
       
   800             User::Leave( KErrUnderflow );
       
   801             }
       
   802         if ( headerSize > ( ( KMaxTInt32 / 2 ) - 1 ) )
       
   803             {
       
   804             User::Leave( KErrOverflow );
       
   805             }
       
   806         buffer = HBufC8::NewLC( headerSize );
       
   807 
       
   808         headerPtr.Set( buffer->Des() );
       
   809         User::LeaveIfError( file.Read( headerPtr, headerSize - 24 ) );
       
   810 
       
   811         r = headerPtr.Find( KWrmHeader );
       
   812         if ( KErrNotFound != r )
       
   813             {
       
   814             isProtectedWmDrm = ETrue;
       
   815             }
       
   816         CleanupStack::PopAndDestroy( buffer ); // buffer
       
   817         }
       
   818         CleanupStack::PopAndDestroy(); // file
       
   819 
       
   820     return isProtectedWmDrm;
       
   821     }
       
   822 
       
   823 #endif // RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CProfileAiwProvider::IsFileWMDRMProtectedL
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 TBool CProfileAiwProvider::IsFileWMDRMProtectedL( const TDesC& aFileName ) const
       
   830 	{
       
   831 	TBool res = EFalse;
       
   832 	RFs& fsSession( CCoeEnv::Static()->FsSession() );
       
   833 	RFile hFile;
       
   834 
       
   835 	TInt err = hFile.Open( fsSession, aFileName, 
       
   836 						EFileRead | EFileStream | EFileShareReadersOnly );
       
   837 	if( err == KErrInUse )
       
   838 		{
       
   839 		err = hFile.Open( fsSession, aFileName, 
       
   840 						EFileRead | EFileStream | EFileShareAny );
       
   841 		}
       
   842 	if( err != KErrNone )
       
   843 		{
       
   844 		User::Leave( err );
       
   845 		}
       
   846 	CleanupClosePushL( hFile );
       
   847 
       
   848 #ifdef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   849 	TPtrC agent( KNullDesC );
       
   850 	DRM::CDrmUtility* drmUtil( DRM::CDrmUtility::NewLC() );
       
   851 	drmUtil->GetAgentL( hFile, agent );
       
   852 	if( agent.Compare( DRM::KDrmWMAgentName ) == 0 )
       
   853 		{
       
   854 		res = ETrue;
       
   855 		}
       
   856 	CleanupStack::PopAndDestroy( drmUtil );
       
   857 #else
       
   858 	res = IsProtectedWmDrmL( hFile );
       
   859 #endif
       
   860 
       
   861 	CleanupStack::PopAndDestroy( &hFile );
       
   862 	return res;
       
   863 	}
       
   864 
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 // End of Functions related to WMDRM protection check
       
   869 //
       
   870 // -----------------------------------------------------------------------------
       
   871 
       
   872 
       
   873 // End of File