phonebookengines/VirtualPhonebook/VPbkSimStore/src/CSupportedFieldTypes.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A vpbk field type list that contains sim supported types
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CSupportedFieldTypes.h"
       
    22 
       
    23 #include "CFieldTypeMappings.h"
       
    24 #include <TVPbkSimStoreProperty.h>
       
    25 
       
    26 namespace VPbkSimStore {
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSupportedFieldTypes::CSupportedFieldTypes
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CSupportedFieldTypes::CSupportedFieldTypes()
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CSupportedFieldTypes::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CSupportedFieldTypes::ConstructL( 
       
    46     const CFieldTypeMappings& aFieldTypeMappings,
       
    47     TVPbkGsmStoreProperty& aSimStoreProperty,
       
    48     TVPbkUSimStoreProperty* aUSimStoreProperty )
       
    49     {
       
    50     // SIM supports always the name field
       
    51     const MVPbkFieldType* vpbkType = aFieldTypeMappings.Match( EVPbkSimName );
       
    52     iSupportedTypes.AppendL( vpbkType );
       
    53     // SIM supports always one number field
       
    54     vpbkType = aFieldTypeMappings.Match( EVPbkSimGsmNumber );
       
    55     const MVPbkFieldType* vpbkGsmType = vpbkType;
       
    56     iSupportedTypes.AppendL( vpbkType );
       
    57     // USIM can support additional numbers
       
    58     if ( aSimStoreProperty.iCaps & VPbkSimStoreImpl::KAdditionalNumUsed )
       
    59         {
       
    60         if( aUSimStoreProperty )
       
    61             {
       
    62             for( TInt i = 1; i <= aUSimStoreProperty->iMaxNumOfAnrs; i ++ )
       
    63                 {
       
    64                 TVPbkSimCntFieldType type;
       
    65                 switch( i )
       
    66                     {
       
    67                     case 1:  // first additional number field type 
       
    68                         type = EVPbkSimAdditionalNumber1;
       
    69                         break;
       
    70                     case 2: // second additional number field type
       
    71                         type = EVPbkSimAdditionalNumber2;
       
    72                         break;
       
    73                     case 3: // third additional number field type
       
    74                         type = EVPbkSimAdditionalNumber3;
       
    75                         break;
       
    76                     default: // four and so on 
       
    77                         type = EVPbkSimAdditionalNumberLast;
       
    78                         break;
       
    79                     }
       
    80                 vpbkType = aFieldTypeMappings.Match( type );
       
    81                 if( !( vpbkGsmType->IsSame( *vpbkType ) ) )   // if not the same as GSM type.
       
    82                     {
       
    83                     iSupportedTypes.AppendL( vpbkType );
       
    84                     }
       
    85                 }
       
    86             }
       
    87         else
       
    88             {
       
    89             vpbkType = aFieldTypeMappings.Match( EVPbkSimAdditionalNumber );
       
    90             // Check if the VPbk type is different than the type for
       
    91             // already added EVPbkSimGsmNumber
       
    92             if ( iSupportedTypes.Find( vpbkType ) == KErrNotFound )
       
    93                 {
       
    94                 iSupportedTypes.AppendL( vpbkType );
       
    95                 }
       
    96             }
       
    97         }
       
    98     if ( aSimStoreProperty.iCaps & VPbkSimStoreImpl::KSecondNameUsed )
       
    99         {
       
   100 		// Second name field of the USIM is used for nick name in 
       
   101         // non-Japanese variants
       
   102 		vpbkType = aFieldTypeMappings.Match( EVPbkSimNickName );    
       
   103         iSupportedTypes.AppendL( vpbkType );
       
   104         }
       
   105     if ( aSimStoreProperty.iCaps & VPbkSimStoreImpl::KEmailAddressUsed )
       
   106         {
       
   107         vpbkType = aFieldTypeMappings.Match( EVPbkSimEMailAddress );
       
   108         iSupportedTypes.AppendL( vpbkType );
       
   109         }
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSupportedFieldTypes::NewL
       
   114 // Two-phased constructor.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CSupportedFieldTypes* CSupportedFieldTypes::NewL(
       
   118     const CFieldTypeMappings& aFieldTypeMappings,
       
   119     TVPbkGsmStoreProperty& aSimStoreProperty )
       
   120     {
       
   121     CSupportedFieldTypes* self = new( ELeave ) CSupportedFieldTypes;
       
   122     CleanupStack::PushL( self );
       
   123     self->ConstructL( aFieldTypeMappings, aSimStoreProperty );
       
   124     CleanupStack::Pop( self );
       
   125     return self;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CSupportedFieldTypes::NewL
       
   130 // Two-phased constructor.
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 CSupportedFieldTypes* CSupportedFieldTypes::NewL(
       
   134     const CFieldTypeMappings& aFieldTypeMappings,
       
   135     TVPbkGsmStoreProperty& aSimStoreProperty,
       
   136     TVPbkUSimStoreProperty& aUSimStoreProperty )  
       
   137     {
       
   138     CSupportedFieldTypes* self = new( ELeave ) CSupportedFieldTypes;
       
   139     CleanupStack::PushL( self );
       
   140     self->ConstructL( aFieldTypeMappings, aSimStoreProperty, &aUSimStoreProperty );  
       
   141     CleanupStack::Pop( self );
       
   142     return self;
       
   143     }
       
   144 
       
   145 // Destructor
       
   146 CSupportedFieldTypes::~CSupportedFieldTypes()
       
   147     {    
       
   148     iSupportedTypes.Close();
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CSupportedFieldTypes::FieldTypeCount
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TInt CSupportedFieldTypes::FieldTypeCount() const
       
   156     {
       
   157     return iSupportedTypes.Count();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSupportedFieldTypes::FieldTypeAt
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 const MVPbkFieldType& CSupportedFieldTypes::FieldTypeAt( TInt aIndex ) const
       
   165     {
       
   166     return *iSupportedTypes[aIndex];
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CSupportedFieldTypes::FieldTypeAt
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TBool CSupportedFieldTypes::ContainsSame( 
       
   174     const MVPbkFieldType& aFieldType ) const
       
   175     {
       
   176     TInt count = iSupportedTypes.Count();
       
   177     for ( TInt i = 0; i < count; ++i )
       
   178         {
       
   179         if ( iSupportedTypes[i] == &aFieldType )
       
   180             {
       
   181             return ETrue;
       
   182             }
       
   183         }
       
   184     return EFalse;
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CSupportedFieldTypes::FieldTypeAt
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 TInt CSupportedFieldTypes::MaxMatchPriority() const
       
   192     {
       
   193     // SIM contacts have max 1 versit property
       
   194     const TInt simTypeMaxPriority = 1;
       
   195     return simTypeMaxPriority;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CSupportedFieldTypes::FindMatch
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 const MVPbkFieldType* CSupportedFieldTypes::FindMatch( 
       
   203     const TVPbkFieldVersitProperty& aMatchProperty,
       
   204     TInt aMatchPriority ) const
       
   205     {
       
   206     TInt count = iSupportedTypes.Count();
       
   207     for ( TInt i = 0; i < count; ++i )
       
   208         {
       
   209         if ( iSupportedTypes[i]->Matches( aMatchProperty, aMatchPriority ) )
       
   210             {
       
   211             return iSupportedTypes[i];
       
   212             }
       
   213         }
       
   214     return NULL;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CSupportedFieldTypes::FindMatch
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 const MVPbkFieldType* CSupportedFieldTypes::FindMatch( 
       
   222     TVPbkNonVersitFieldType aNonVersitType ) const
       
   223     {
       
   224     TInt count = iSupportedTypes.Count();
       
   225     for ( TInt i = 0; i < count; ++i )
       
   226         {
       
   227         if ( iSupportedTypes[i]->NonVersitType() == aNonVersitType )
       
   228             {
       
   229             return iSupportedTypes[i];
       
   230             }
       
   231         }
       
   232     return NULL;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CSupportedFieldTypes::Find
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 const MVPbkFieldType* CSupportedFieldTypes::Find(
       
   240         TInt aFieldTypeResId) const
       
   241     {
       
   242     const MVPbkFieldType* fieldType = NULL;
       
   243     for (TInt i = 0; i < iSupportedTypes.Count(); ++i)
       
   244         {
       
   245         if (iSupportedTypes[i]->FieldTypeResId() == aFieldTypeResId)
       
   246             {
       
   247             fieldType = iSupportedTypes[i];
       
   248             break;
       
   249             }
       
   250         }
       
   251     return fieldType;
       
   252     }
       
   253 
       
   254 } // namespace VPbkSimStore
       
   255 
       
   256 //  End of File