profilesservices/MediaFileList/Src/mediafilevariation.cpp
changeset 68 13e71d907dc3
parent 0 8c5d936e5675
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
       
     1 /*
       
     2 * Copyright (c) 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:   Variation functionality class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "mediafilevariation.h"
       
    23 
       
    24 #include <centralrepository.h>
       
    25 #include <apmstd.h> // for KMaxDataTypeLength
       
    26 #include <ProfileEngineDomainCRKeys.h>
       
    27 
       
    28 
       
    29 
       
    30 /******************************************************************************
       
    31  * class CMediaFileDialogVariation
       
    32  ******************************************************************************/
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CMediaFileDialogVariation::NewL
       
    37 //
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CMediaFileDialogVariation* CMediaFileDialogVariation::NewL()
       
    41     {
       
    42     CMediaFileDialogVariation* self = new ( ELeave ) CMediaFileDialogVariation( 0 );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMediaFileDialogVariation::~CMediaFileDialogVariation
       
    52 //
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMediaFileDialogVariation::~CMediaFileDialogVariation()
       
    56     {
       
    57     iBlockedTones.Close();
       
    58     iBlockedUnprotectedTones.Close();
       
    59     iBlockedProtectedTones.Close();
       
    60     iBlockedDemoPlayTones.Close();
       
    61     iExcludedTones.Close();
       
    62     iMimeBuf.Close();
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMediaFileDialogVariation::CMediaFileDialogVariation
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CMediaFileDialogVariation::CMediaFileDialogVariation( TInt aFeatureBitMask )
       
    72     : iFeatureBitMask( aFeatureBitMask )
       
    73     {
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMediaFileDialogVariation::ConstructL
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMediaFileDialogVariation::ConstructL()
       
    83     {
       
    84     _LIT( KSpace, " " );
       
    85     
       
    86     CRepository* cenrep = CRepository::NewL( KCRUidProfilesLV );
       
    87     CleanupStack::PushL( cenrep );
       
    88     
       
    89     User::LeaveIfError( cenrep->Get( KProfilesLVFlags, iFeatureBitMask ) );
       
    90     ReadListKeyL( *cenrep, KProEngBlockedTones, iBlockedTones );
       
    91     ReadListKeyL( *cenrep, KProEngBlockedUnprotectedTones,
       
    92                   iBlockedUnprotectedTones );
       
    93     ReadListKeyL( *cenrep, KProEngBlockedProtectedTones,
       
    94                   iBlockedProtectedTones );
       
    95     ReadListKeyL( *cenrep, KProEngBlockedDemoPlayTones,
       
    96                   iBlockedDemoPlayTones );
       
    97     ReadListKeyL( *cenrep, KProEngExcludedTones,
       
    98                   iExcludedTones );
       
    99     
       
   100     CleanupStack::PopAndDestroy( cenrep );
       
   101     
       
   102     iMimeBuf.CreateL( KMaxDataTypeLength + KSpace().Length() );
       
   103     }
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMediaFileDialogVariation::IsFeatureSupported
       
   108 //
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TBool CMediaFileDialogVariation::IsFeatureSupported( TInt aLocalFeatureId )
       
   112     {
       
   113     return iFeatureBitMask & aLocalFeatureId;
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CProfilesLocalFeatures::IsBlockedType
       
   119 //
       
   120 // (other items were commented in a header).
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TBool CMediaFileDialogVariation::IsBlockedType( const TDesC& aMimeType )
       
   124     {
       
   125     return ContainsMimeType( iBlockedTones, aMimeType );
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMediaFileDialogVariation::IsBlockedUnprotectedType
       
   131 //
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CMediaFileDialogVariation::IsBlockedUnprotectedType(
       
   135         const TDesC& aMimeType )
       
   136     {
       
   137     return ContainsMimeType( iBlockedUnprotectedTones, aMimeType );
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMediaFileDialogVariation::IsBlockedProtectedType
       
   143 //
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TBool CMediaFileDialogVariation::IsBlockedProtectedType( const TDesC& aMimeType )
       
   147     {
       
   148     return ContainsMimeType( iBlockedProtectedTones, aMimeType );
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CMediaFileDialogVariation::IsBlockedDemoPlayType
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CMediaFileDialogVariation::IsBlockedDemoPlayType( const TDesC& aMimeType )
       
   158     {
       
   159     return ContainsMimeType( iBlockedDemoPlayTones, aMimeType );
       
   160     }
       
   161 
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CMediaFileDialogVariation::IsExcludedType
       
   165 //
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TBool CMediaFileDialogVariation::IsExcludedType( const TDesC& aMimeType )
       
   169     {
       
   170     return ContainsMimeType( iExcludedTones, aMimeType );
       
   171     }
       
   172 
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CMediaFileDialogVariation::ReadListKeyL
       
   176 //
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CMediaFileDialogVariation::ReadListKeyL( CRepository& aCenRep,
       
   180                                               TUint32 aKey, RBuf& aValue )
       
   181     {
       
   182     _LIT( KSpace, " " );
       
   183     
       
   184     TBuf<1> tmp; // one char to get length of actual value
       
   185     TInt realLen = 0;
       
   186     TInt err = aCenRep.Get( aKey, tmp, realLen );
       
   187     if ( err == KErrOverflow )
       
   188         {
       
   189         // prepare list of blocked MIME types
       
   190         aValue.CreateL( realLen + KSpace().Length() );
       
   191         User::LeaveIfError( aCenRep.Get( aKey, aValue ) );
       
   192         aValue.Append( KSpace );
       
   193         }
       
   194     else
       
   195         {
       
   196         User::LeaveIfError( err );
       
   197         }
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CMediaFileDialogVariation::ContainsMimeTypeL
       
   203 //
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 TBool CMediaFileDialogVariation::ContainsMimeType( const TDesC& aList,
       
   207                                                    const TDesC& aMimeType )
       
   208     {
       
   209     _LIT( KSpace, " " );
       
   210     
       
   211     if( aList.Length() == 0 )
       
   212         {
       
   213         return EFalse;
       
   214         }
       
   215 
       
   216     iMimeBuf.Copy( aMimeType );
       
   217     // FindF() would find "audio/3gpp" in "audio/3gpp2" without
       
   218     // the added space.
       
   219     iMimeBuf.Append( KSpace );
       
   220     
       
   221     if ( aList.FindF( iMimeBuf ) == KErrNotFound )
       
   222         {
       
   223         // aMimeType was not in blocked list
       
   224         return EFalse;
       
   225         }
       
   226     
       
   227     return ETrue;
       
   228     }
       
   229 
       
   230 
       
   231 
       
   232 //  End of File