profilesapplication/Profiles/ProfileApp/SettingsViewSrc/ProfileMmfInfoUtility.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     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 wrapper interface around MMF (Multimedia Framework) to get
       
    15 *                information about MIME-types supported by MMF.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // CLASS HEADER
       
    22 #include    "ProfileMmfInfoUtility.h"
       
    23 
       
    24 // INTERNAL INCLUDES
       
    25 
       
    26 // EXTERNAL INCLUDES
       
    27 #include <e32std.h>
       
    28 #include <badesca.h>
       
    29 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    30 #include <caf/caf.h>
       
    31 namespace
       
    32 	{
       
    33 	// CONSTANTS
       
    34 	_LIT8( KProfileRngMimeType,    "application/vnd.nokia.ringing-tone" );
       
    35 	//_LIT8( KProfilePlainTextType,  "text/plain" );
       
    36     }
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CProfileMmfInfoUtility::IsMimeTypeSupported
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 TBool ProfileMmfInfoUtility::IsMimeTypeSupportedL( const TDesC8& aMimeType )
       
    45     {
       
    46 
       
    47     //if( aMimeType.CompareF( KProfilePlainTextType ) == 0 )
       
    48     //    {
       
    49     //    return EFalse;
       
    50     //    }
       
    51 
       
    52     if( aMimeType.CompareF( KProfileRngMimeType ) == 0 )
       
    53         {
       
    54         return ETrue;
       
    55         }
       
    56 
       
    57     TBool result( EFalse );
       
    58 
       
    59 	CMMFFormatSelectionParameters* formatPrms =
       
    60         CMMFFormatSelectionParameters::NewLC();
       
    61 	CMMFControllerPluginSelectionParameters* controllerPrms =
       
    62         CMMFControllerPluginSelectionParameters::NewLC();
       
    63 
       
    64     // Empty format parameters means: "get all the supported formats"
       
    65     controllerPrms->SetRequiredPlayFormatSupportL( *formatPrms );
       
    66     RMMFControllerImplInfoArray cntrlArray;
       
    67     controllerPrms->ListImplementationsL( cntrlArray );
       
    68 
       
    69     for( TInt i( cntrlArray.Count() - 1 ); i >= 0 && !result; --i )
       
    70         {
       
    71         const RMMFFormatImplInfoArray&
       
    72             infoArray( cntrlArray[i]->PlayFormats() );
       
    73 
       
    74         for( TInt j( infoArray.Count() - 1 ); j >= 0; --j )
       
    75             {
       
    76             if( infoArray[j]->SupportsMimeType( aMimeType ) )
       
    77                 {
       
    78                 result = ETrue;
       
    79                 break;
       
    80                 }
       
    81             }
       
    82         }
       
    83 	
       
    84 	cntrlArray.ResetAndDestroy();
       
    85 	cntrlArray.Close();
       
    86     CleanupStack::PopAndDestroy( 2, formatPrms );
       
    87 
       
    88     return result;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CProfileMmfInfoUtility::IsHeaderDataSupportedL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 TBool ProfileMmfInfoUtility::IsHeaderDataSupportedL( const TDesC& aFileName )
       
    96 	{
       
    97 	TBool result( EFalse );
       
    98 	//the max header length is 256 bytes
       
    99 	const TInt KMaxHeaderLength( 256 );
       
   100 	HBufC8* header = HBufC8::NewLC( KMaxHeaderLength );
       
   101 	TPtr8 headerPtr = header->Des();
       
   102 	GetFileHeaderDataL( aFileName, headerPtr, KMaxHeaderLength );
       
   103 	CMMFFormatSelectionParameters* formatPrms =
       
   104 			CMMFFormatSelectionParameters::NewLC();
       
   105 	CMMFControllerPluginSelectionParameters* controllerPrms =
       
   106 			CMMFControllerPluginSelectionParameters::NewLC();
       
   107 
       
   108 	// Empty format parameters means: "get all the supported formats"
       
   109 	controllerPrms->SetRequiredPlayFormatSupportL( *formatPrms );
       
   110 	RMMFControllerImplInfoArray cntrlArray;
       
   111 	controllerPrms->ListImplementationsL( cntrlArray );
       
   112 
       
   113 	for ( TInt i( cntrlArray.Count() - 1 ); i >= 0 && !result; --i )
       
   114 		{
       
   115 		const RMMFFormatImplInfoArray& infoArray( cntrlArray[i]->PlayFormats() );
       
   116 
       
   117 		for ( TInt j(infoArray.Count() - 1); j >= 0; --j )
       
   118 			{
       
   119 			if ( infoArray[j]->SupportsHeaderDataL( *header ) )
       
   120 				{
       
   121 				result = ETrue;
       
   122 				break;
       
   123 				}
       
   124 			}
       
   125 		}
       
   126 
       
   127 	cntrlArray.ResetAndDestroy();
       
   128 	cntrlArray.Close();
       
   129 	CleanupStack::PopAndDestroy( 3, header );//controllerPrms, formatPrms and header
       
   130 
       
   131 	return result;
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CProfileMmfInfoUtility::GetFileHeaderDataL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void ProfileMmfInfoUtility::GetFileHeaderDataL( const TDesC& aFileName,
       
   139 		TDes8& aHeaderData, TInt aMaxHeaderLength )
       
   140 	{
       
   141 	TInt error = KErrNone;
       
   142 	using namespace ContentAccess;
       
   143 	TVirtualPathPtr path( aFileName, ContentAccess::KDefaultContentObject );
       
   144 	CData* data = CData::NewLC( path, EContentShareReadWrite );
       
   145 	TInt size = 0;
       
   146 	data->DataSizeL( size );
       
   147 	if ( size > 0 )
       
   148 		{
       
   149 		if ( size > aMaxHeaderLength )
       
   150 			size = aMaxHeaderLength;
       
   151 		TInt pos = 0;
       
   152 		error = data->Seek( ESeekStart, pos );
       
   153 		error = data->Read( aHeaderData, size );
       
   154 		}
       
   155 	CleanupStack::PopAndDestroy(); // data
       
   156 	}
       
   157 
       
   158 //  End of File
       
   159