phonebookengines/VirtualPhonebook/VPbkVCardEng/src/CVPbkVCardContactFieldIterator.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Iterates contact field's fieldtype and data parsed from 
       
    15 *                CParserProperty.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CVPbkVCardContactFieldIterator.h"
       
    20 #include "CVPbkVCardData.h"
       
    21 #include "TVPbkVCardDataConverter.h"
       
    22 
       
    23 #include <TVPbkFieldVersitProperty.h>
       
    24 #include <MVPbkFieldType.h>
       
    25 
       
    26 CVPbkVCardContactFieldIterator* CVPbkVCardContactFieldIterator::NewLC( 
       
    27     CParserProperty& aProperty, CVPbkVCardData& aData )
       
    28     {
       
    29     CVPbkVCardContactFieldIterator* self = 
       
    30         new ( ELeave ) CVPbkVCardContactFieldIterator( aProperty, aData );
       
    31     CleanupStack::PushL( self );
       
    32     return self;
       
    33     }
       
    34  
       
    35 CVPbkVCardContactFieldIterator::CVPbkVCardContactFieldIterator( 
       
    36     CParserProperty& aProperty, CVPbkVCardData& aData )
       
    37 : iProperty ( aProperty ), iData( aData ), iCursor( -1 )
       
    38     {    
       
    39     }
       
    40     
       
    41 CVPbkVCardContactFieldIterator::~CVPbkVCardContactFieldIterator()
       
    42     {
       
    43     iFieldTypes.Close();
       
    44     iVCardFieldTypes.Close();
       
    45     iVCardSubFieldTypes.Close();
       
    46     }
       
    47     
       
    48 void CVPbkVCardContactFieldIterator::AppendVersitProperty( 
       
    49         TVPbkFieldVersitProperty aVersitProperty )
       
    50     {
       
    51     const MVPbkFieldType* fieldType = MatchFieldType( aVersitProperty );
       
    52     if ( fieldType )
       
    53         {
       
    54         iFieldTypes.Append( fieldType );
       
    55         iVCardFieldTypes.Append( aVersitProperty.Name() );
       
    56         iVCardSubFieldTypes.Append( aVersitProperty.SubField() );
       
    57         }
       
    58     }
       
    59     
       
    60 void CVPbkVCardContactFieldIterator::AppendAttribute( MVPbkContactAttribute* aAttribute )
       
    61     {
       
    62     iAttribute = aAttribute;
       
    63     }    
       
    64     
       
    65 const MVPbkFieldType* CVPbkVCardContactFieldIterator::MatchFieldType
       
    66     ( TVPbkFieldVersitProperty& aProperty )
       
    67     {
       
    68     TInt maxMatchPriority = iData.SupportedFieldTypes().MaxMatchPriority();
       
    69     const MVPbkFieldType* fieldType = NULL;
       
    70     for ( TInt i = 0; i <= maxMatchPriority; ++i )
       
    71         {
       
    72         fieldType = iData.SupportedFieldTypes().FindMatch( aProperty, i );
       
    73         if ( fieldType )
       
    74             {
       
    75             break;
       
    76             }
       
    77         }
       
    78     return fieldType;    
       
    79     }
       
    80     
       
    81 TBool CVPbkVCardContactFieldIterator::HasNext()
       
    82     {
       
    83     TBool hasNext( EFalse );
       
    84     if ( ( iFieldTypes.Count() - 1 ) > iCursor )
       
    85         {
       
    86         hasNext = ETrue;
       
    87         }
       
    88     return hasNext;
       
    89     }
       
    90     
       
    91 CVPbkVCardContactFieldData* CVPbkVCardContactFieldIterator::NextLC()
       
    92     {    
       
    93     ++iCursor;    
       
    94     return CurrentLC();
       
    95     }
       
    96  
       
    97 CVPbkVCardContactFieldData* CVPbkVCardContactFieldIterator::CurrentLC()
       
    98     {
       
    99     TVPbkVCardDataConverter converter;
       
   100     CVPbkVCardContactFieldData* data = 
       
   101         converter.CreateDataLC( iProperty, iFieldTypes, iAttribute, iCursor );    
       
   102     return data;
       
   103     }
       
   104 
       
   105 TInt CVPbkVCardContactFieldIterator::FindVCardFieldL( 
       
   106         TVPbkFieldTypeName aVCardFieldType, 
       
   107         TVPbkSubFieldType aVCardSubFieldType )
       
   108     {
       
   109     TInt id = KErrNotFound;
       
   110     for ( TInt i=0; i<iVCardFieldTypes.Count(); i++ )
       
   111         {
       
   112         if ( iVCardFieldTypes[i] == aVCardFieldType &&
       
   113              iVCardSubFieldTypes[i] == aVCardSubFieldType )
       
   114             {
       
   115             id = iFieldTypes[i]->FieldTypeResId();
       
   116             break;
       
   117             }
       
   118         }
       
   119     return id;
       
   120     }
       
   121     
       
   122 // End of file