phonebookui/Phonebook2/Presentation/src/TPbk2StoreContactAnalyzer.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 store contact analyzer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "TPbk2StoreContactAnalyzer.h"
       
    20 
       
    21 // Virtual Phonebook
       
    22 #include <CVPbkContactManager.h>
       
    23 #include <CVPbkFieldTypeSelector.h>
       
    24 #include <MVPbkStoreContactFieldCollection.h>
       
    25 #include <MVPbkStoreContact.h>
       
    26 #include <MVPbkContactStore.h>
       
    27 #include <MVPbkFieldType.h>
       
    28 #include <MVPbkContactStoreProperties.h>
       
    29 #include <VPbkUtils.h>
       
    30 
       
    31 // System includes
       
    32 #include <barsread.h>
       
    33 #include <coemain.h>
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // TPbk2StoreContactAnalyzer::TPbk2StoreContactAnalyzer
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C TPbk2StoreContactAnalyzer::TPbk2StoreContactAnalyzer
       
    40         ( const CVPbkContactManager& aContactManager,
       
    41         const MVPbkStoreContact* aContact ) :
       
    42             iContactManager( aContactManager ),
       
    43             iContact( aContact )
       
    44     {
       
    45     }
       
    46 
       
    47 // --------------------------------------------------------------------------
       
    48 // TPbk2StoreContactAnalyzer::HasFieldL
       
    49 // --------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C TInt TPbk2StoreContactAnalyzer::HasFieldL
       
    52         ( TInt aResId, TInt aStartIndex/* = 0*/,
       
    53         const MVPbkStoreContact* aContact/* = NULL*/ ) const
       
    54     {
       
    55     TInt ret = KErrNotFound;
       
    56     const MVPbkStoreContact* tempContact = iContact;
       
    57 
       
    58     if ( aContact )
       
    59         {
       
    60         tempContact = aContact;
       
    61         }
       
    62 
       
    63     // Check that there is contact to analyze
       
    64     if ( tempContact )
       
    65         {
       
    66         // Read the contact field selector from resource
       
    67         MVPbkContactFieldSelector* fieldTypeSelector =
       
    68             static_cast<MVPbkContactFieldSelector*>
       
    69                 ( CreateFieldTypeSelectorLC( aResId ) );
       
    70 
       
    71         // Check if the specified field is included to contact
       
    72         const MVPbkStoreContactFieldCollection& fields =
       
    73             tempContact->Fields();
       
    74         ret = IsFieldIncluded( fields, aStartIndex, *fieldTypeSelector );
       
    75         CleanupStack::PopAndDestroy(); // fieldTypeSelector;
       
    76         }
       
    77 
       
    78     return ret;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // TPbk2StoreContactAnalyzer::IsFieldTypeSupportedL
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C TBool TPbk2StoreContactAnalyzer::IsFieldTypeSupportedL
       
    86         ( TInt aResId, const MVPbkStoreContact* aContact /*= NULL*/ ) const
       
    87     {
       
    88     TBool ret = EFalse;
       
    89     const MVPbkStoreContact* tempContact = iContact;
       
    90 
       
    91     if (aContact)
       
    92         {
       
    93         tempContact = aContact;
       
    94         }
       
    95 
       
    96     // Check that there is contact to analyze
       
    97     if ( tempContact )
       
    98         {
       
    99         // Read the field type selector from resource
       
   100         MVPbkFieldTypeSelector* fieldTypeSelector =
       
   101             static_cast<MVPbkFieldTypeSelector*>
       
   102                 ( CreateFieldTypeSelectorLC( aResId ) );
       
   103 
       
   104         // Check if the specified field type is supported by contact
       
   105         const MVPbkFieldTypeList& fieldTypes =
       
   106             tempContact->ParentStore().StoreProperties().SupportedFields();
       
   107         ret = IsFieldTypeIncluded( fieldTypes, *fieldTypeSelector );
       
   108         CleanupStack::PopAndDestroy(); // fieldTypeSelector;
       
   109         }
       
   110 
       
   111     return ret;
       
   112     }
       
   113 
       
   114 // --------------------------------------------------------------------------
       
   115 // TPbk2StoreContactAnalyzer::IsFieldTypeIncludedL
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C TBool TPbk2StoreContactAnalyzer::IsFieldTypeIncludedL
       
   119         ( const MVPbkFieldType& aFieldType, TInt aResId ) const
       
   120     {
       
   121     CVPbkFieldTypeSelector* selector = CreateFieldTypeSelectorLC( aResId );
       
   122     TBool ret = selector->IsFieldTypeIncluded( aFieldType );
       
   123     CleanupStack::PopAndDestroy( selector );
       
   124     return ret;
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // TPbk2StoreContactAnalyzer::IsFieldTypeIncludedL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TBool TPbk2StoreContactAnalyzer::IsFieldTypeIncludedL
       
   132         ( const MVPbkBaseContactField& aField, TInt aResId ) const
       
   133     {
       
   134     TBool ret = EFalse;
       
   135 
       
   136     // Get the field type
       
   137     const MVPbkFieldType* fieldType =
       
   138         VPbkUtils::MatchFieldType( iContactManager.FieldTypes(), aField );
       
   139 
       
   140     if ( fieldType != NULL)
       
   141         {
       
   142         CVPbkFieldTypeSelector* selector = CreateFieldTypeSelectorLC( aResId );
       
   143         ret = selector->IsFieldTypeIncluded( *fieldType );
       
   144         CleanupStack::PopAndDestroy( selector );
       
   145         }
       
   146 
       
   147     return ret;
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // TPbk2StoreContactAnalyzer::IsFieldIncluded
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 TInt TPbk2StoreContactAnalyzer::IsFieldIncluded
       
   155         (const MVPbkBaseContactFieldCollection& aFields,
       
   156         TInt aStartIndex,
       
   157         const MVPbkContactFieldSelector& aFieldTypeSelector) const
       
   158     {
       
   159     TInt ret( KErrNotFound );
       
   160     TInt fieldCount( aFields.FieldCount() );
       
   161 
       
   162     for ( TInt i = aStartIndex; i < fieldCount && ret == KErrNotFound; ++i )
       
   163         {
       
   164         const MVPbkBaseContactField& field = aFields.FieldAt( i );
       
   165         if ( aFieldTypeSelector.IsFieldIncluded( field ) )
       
   166             {
       
   167             ret = i;
       
   168             }
       
   169         }
       
   170 
       
   171     return ret;
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // TPbk2StoreContactAnalyzer::IsFieldTypeIncluded
       
   176 // --------------------------------------------------------------------------
       
   177 //
       
   178 TBool TPbk2StoreContactAnalyzer::IsFieldTypeIncluded
       
   179         ( const MVPbkFieldTypeList& aFieldTypes,
       
   180         const MVPbkFieldTypeSelector& aFieldTypeSelector ) const
       
   181     {
       
   182     TBool ret( EFalse );
       
   183     TInt fieldTypeCount( aFieldTypes.FieldTypeCount() );
       
   184 
       
   185     for ( TInt i = 0; i < fieldTypeCount && !ret; ++i )
       
   186         {
       
   187         const MVPbkFieldType& fieldType = aFieldTypes.FieldTypeAt( i );
       
   188         if ( aFieldTypeSelector.IsFieldTypeIncluded( fieldType ) )
       
   189             {
       
   190             ret = ETrue;
       
   191             }
       
   192         }
       
   193 
       
   194     return ret;
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // TPbk2StoreContactAnalyzer::CreateFieldTypeSelectorLC
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 CVPbkFieldTypeSelector* TPbk2StoreContactAnalyzer::CreateFieldTypeSelectorLC
       
   202         ( TInt aResId ) const
       
   203     {
       
   204     TResourceReader resReader;
       
   205     CCoeEnv::Static()->CreateResourceReaderLC( resReader, aResId );
       
   206 
       
   207     CVPbkFieldTypeSelector* fieldTypeSelector = CVPbkFieldTypeSelector::NewL
       
   208         ( resReader, iContactManager.FieldTypes() );
       
   209 
       
   210     CleanupStack::PopAndDestroy(); // resReader
       
   211     CleanupStack::PushL( fieldTypeSelector );
       
   212     return fieldTypeSelector;
       
   213     }
       
   214 
       
   215 // End of File