mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cdescriptionutility.cpp
branchRCL_3
changeset 9 bee149131e4b
child 17 780c925249c1
equal deleted inserted replaced
4:d45095c2f4f3 9:bee149131e4b
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mtp/cmtptypeinterdependentpropdesc.h>
       
    19 #include <mtp/cmtptypeobjectpropdesc.h>
       
    20 #include <mtp/cmtptypestring.h>
       
    21 
       
    22 #include "cdescriptionutility.h"
       
    23 #include "tobjectdescription.h"
       
    24 
       
    25 #include "mmmtpdplogger.h"
       
    26 
       
    27 
       
    28 _LIT( KMtpObjDescObjFileName,
       
    29     "[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 7}\\.[[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 2}]?" );
       
    30 // RegEx is [a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~][a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~ ]{0, 7}\.[[a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~][a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~ ]{0, 2}]?
       
    31 
       
    32 EXPORT_C CDescriptionUtility::CDescriptionUtility()
       
    33     {
       
    34     // Do nothing
       
    35     }
       
    36 
       
    37 EXPORT_C CDescriptionUtility::~CDescriptionUtility()
       
    38     {
       
    39     // Do nothing
       
    40     }
       
    41 
       
    42 EXPORT_C CMTPTypeObjectPropDesc* CDescriptionUtility::NewCommonObjectPropertyL( TUint16 aPropCode )
       
    43     {
       
    44     CMTPTypeObjectPropDesc* propertyDesc = NULL;
       
    45 
       
    46     switch ( aPropCode )
       
    47         {
       
    48         case EMTPObjectPropCodeStorageID:
       
    49         case EMTPObjectPropCodeObjectFormat:
       
    50         case EMTPObjectPropCodeObjectSize:
       
    51         case EMTPObjectPropCodeParentObject:
       
    52         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
    53         case EMTPObjectPropCodeName:
       
    54         case EMTPObjectPropCodeDateAdded:
       
    55             propertyDesc = CMTPTypeObjectPropDesc::NewL( aPropCode );
       
    56             break;
       
    57 
       
    58             // Protection Status (m)
       
    59         case EMTPObjectPropCodeProtectionStatus:
       
    60             propertyDesc = NewProtectionStatusPropDescL();
       
    61             break;
       
    62 
       
    63             // FileName
       
    64         case EMTPObjectPropCodeObjectFileName:
       
    65             propertyDesc = NewFileNamePropDescL();
       
    66             break;
       
    67 
       
    68             // Consumable (m)
       
    69         case EMTPObjectPropCodeNonConsumable:
       
    70             propertyDesc = NewNonConsumablePropDescL();
       
    71             break;
       
    72 
       
    73         case EMTPObjectPropCodeDateModified: // Date Modified
       
    74         case EMTPObjectPropCodeDateCreated: // Date Created
       
    75             {
       
    76             CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
    77             propertyInfo.iDataType = EMTPTypeString;
       
    78             propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EDateTimeForm;
       
    79             propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly;
       
    80             propertyDesc = CMTPTypeObjectPropDesc::NewL( aPropCode,
       
    81                 propertyInfo,
       
    82                 NULL );
       
    83             }
       
    84             break;
       
    85 
       
    86         default:
       
    87             break;
       
    88         }
       
    89     return propertyDesc;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CDescriptionUtility::NewRangeFormDescriptionL
       
    94 //
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C CMTPTypeObjectPropDesc* CDescriptionUtility::NewRangeFormDescriptionL( TUint16 aPropertyCode,
       
    98     TUint32 aMinValue,
       
    99     TUint32 aMaxValue,
       
   100     TUint32 aStepValue,
       
   101     TBool aIsReadOnly )
       
   102     {
       
   103     PRINT1( _L( "MM MTP => CDescriptionUtility::NewRangeFormDescriptionL, aPropertyCode = 0x%x" ),
       
   104         aPropertyCode );
       
   105     CMTPTypeObjectPropDescRangeForm* form =
       
   106         CMTPTypeObjectPropDescRangeForm::NewLC( EMTPTypeUINT32 ); // + form
       
   107 
       
   108     // Set expected values
       
   109     form->SetUint32L( CMTPTypeObjectPropDescRangeForm::EMinimumValue, aMinValue );
       
   110     form->SetUint32L( CMTPTypeObjectPropDescRangeForm::EMaximumValue, aMaxValue );
       
   111     form->SetUint32L( CMTPTypeObjectPropDescRangeForm::EStepSize, aStepValue );
       
   112 
       
   113     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
   114     propertyInfo.iDataType = EMTPTypeUINT32;
       
   115     propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::ERangeForm;
       
   116     propertyInfo.iGetSet = !aIsReadOnly;
       
   117 
       
   118     CMTPTypeObjectPropDesc* propertyDesc = CMTPTypeObjectPropDesc::NewL( aPropertyCode,
       
   119         propertyInfo,
       
   120         form );    // + propertyDesc
       
   121 
       
   122     CleanupStack::PopAndDestroy( form ); // - form
       
   123     PRINT( _L( "MM MTP <= CDescriptionUtility::NewRangeFormDescriptionL" ) );
       
   124 
       
   125     return propertyDesc;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CDescriptionUtility::GetGroupCode
       
   130 // Get MTPTypeObjectPropDesc according to property code
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TUint32 CDescriptionUtility::GetGroupCode( TUint32 aPropCode )
       
   134     {
       
   135     TInt count = sizeof( KPropGroupMapTable ) / sizeof( KPropGroupMapTable[0] );
       
   136     // TODO: if need to refine the search approach to improve performance
       
   137     for( TInt i = 0; i < count; i++ )
       
   138         {
       
   139         if ( aPropCode == KPropGroupMapTable[i].iPropCode )
       
   140             return KPropGroupMapTable[i].iGroupCode;
       
   141         }
       
   142     return EGroupCodeNotDefined;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CDescriptionUtility::NewProtectionStatusPropDescL
       
   147 // New MTPTypeObjectPropDesc protection status
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 CMTPTypeObjectPropDesc* CDescriptionUtility::NewProtectionStatusPropDescL()
       
   151     {
       
   152     PRINT( _L( "MM MTP => CDescriptionUtility::NewProtectionStatusPropDescL" ) );
       
   153 
       
   154     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   155         CMTPTypeObjectPropDescEnumerationForm::NewLC( EMTPTypeUINT16 ); // + expectedForm
       
   156 
       
   157     TUint16 values[] =
       
   158         {
       
   159         EMTPProtectionNoProtection,
       
   160         EMTPProtectionReadOnly
       
   161         };
       
   162 
       
   163     TInt numValues = sizeof ( values ) / sizeof ( values[0] ) ;
       
   164     for ( TInt i = 0; i < numValues; i++ )
       
   165         {
       
   166         TMTPTypeUint16 data( values[i] );
       
   167         expectedForm->AppendSupportedValueL( data );
       
   168         }
       
   169 
       
   170     CMTPTypeObjectPropDesc* propertyDesc  = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeProtectionStatus, *expectedForm );
       
   171     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   172 
       
   173     PRINT( _L( "MM MTP <= CDescriptionUtility::NewProtectionStatusPropDescL" ) );
       
   174     return propertyDesc;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CDescriptionUtility::NewFileNamePropDescL
       
   179 // Get MTPTypeObjectPropDesc New file name
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 CMTPTypeObjectPropDesc* CDescriptionUtility::NewFileNamePropDescL()
       
   183     {
       
   184     PRINT( _L( "MM MTP => CDescriptionUtility::NewFileNamePropDescL" ) );
       
   185     CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form
       
   186 
       
   187     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName,
       
   188         CMTPTypeObjectPropDesc::ERegularExpressionForm,
       
   189         form );
       
   190 
       
   191     CleanupStack::PopAndDestroy( form ); // - form
       
   192     PRINT( _L( "MM MTP <= CDescriptionUtility::NewFileNamePropDescL" ) );
       
   193     return ret;
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CDescriptionUtility::NewFileNamePropDescL
       
   198 // Get MTPTypeObjectPropDesc New file name
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CMTPTypeObjectPropDesc* CDescriptionUtility::NewNonConsumablePropDescL()
       
   202     {
       
   203     PRINT( _L( "MM MTP => CDescriptionUtility::NewNonConsumablePropDescL" ) );
       
   204     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   205         CMTPTypeObjectPropDescEnumerationForm::NewLC( EMTPTypeUINT8 ); // + expectedForm
       
   206     TUint8 values[] =
       
   207         {
       
   208         EMTPConsumable,
       
   209         EMTPNonConsumable
       
   210         };
       
   211 
       
   212     TInt numValues = sizeof ( values ) / sizeof ( values[0] );
       
   213     for ( TInt i = 0; i < numValues; i++ )
       
   214         {
       
   215         TMTPTypeUint8 data( values[i] );
       
   216         expectedForm->AppendSupportedValueL( data );
       
   217         }
       
   218 
       
   219     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeNonConsumable,
       
   220         CMTPTypeObjectPropDesc::EEnumerationForm,
       
   221         expectedForm );
       
   222     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   223 
       
   224     PRINT( _L( "MM MTP <= CDescriptionUtility::NewNonConsumablePropDescL" ) );
       
   225     return ret;
       
   226     }
       
   227 
       
   228 // end of file