phonebookengines/VirtualPhonebook/VPbkCntModel/inc/CFieldFactory.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  The virtual phonebook field factory
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CFIELDFACTORY_H
       
    21 #define CFIELDFACTORY_H
       
    22 
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <MVPbkFieldType.h>
       
    27 #include <VPbkFieldType.hrh>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CContactItem;
       
    31 class CContactItemField;
       
    32 class TVPbkFieldVersitProperty;
       
    33 class RFs;
       
    34 
       
    35 namespace VPbkCntModel {
       
    36 
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CFieldTypeMap;
       
    40 
       
    41 // CLASS DECLARATIONS
       
    42 
       
    43 /**
       
    44  * Virtual Phonebook field type -> Contact Model field factory.
       
    45  */
       
    46 NONSHARABLE_CLASS(CFieldFactory) : public CBase,
       
    47                                    public MVPbkFieldTypeList
       
    48     {
       
    49     public:  // Constructor and destructor
       
    50         /**
       
    51          * Creates a new instance of this class.
       
    52          *
       
    53          * @param aFieldTypeMap     field type mapper.
       
    54          * @param aSystemTemplate   Contact Database system template. This
       
    55          *                          object takes ownership of the system
       
    56          *                          template unless this function leaves.
       
    57          * @param aMasterFieldTypeList  Master field type list from CVPbkContactManager.
       
    58          * @return a new instance of this class.
       
    59          */
       
    60         static CFieldFactory* NewL( const CFieldTypeMap& aFieldTypeMap, 
       
    61                                    CContactItem* aSystemTemplate, 
       
    62                                    const MVPbkFieldTypeList& aMasterFieldTypeList,
       
    63                                    RFs& aFs );
       
    64 
       
    65         /**
       
    66          * Destructor.
       
    67          */
       
    68         ~CFieldFactory();
       
    69 
       
    70     public:  // New functions
       
    71         /**
       
    72          * Creates and returns a new Contact Model field based on Virtual 
       
    73          * Phonebook generic field type. 
       
    74          *
       
    75          * A field definition that matches the field type is searched from the
       
    76          * system template that was passed as a construction parameter to this
       
    77          * object.
       
    78          *
       
    79          * @param aFieldType    type of the field to create.  
       
    80          * @return  a new Contact Model field. Caller takes ownership of the 
       
    81          *          returned object. May return NULL if the field type is not
       
    82          *          supported by Contact Model.
       
    83          */
       
    84         CContactItemField* CreateFieldLC( const MVPbkFieldType& aFieldType ) const;
       
    85 
       
    86         /**
       
    87          * Finds and returns matching Contact Model system template field base on 
       
    88          * Virtual Phonebook generic field type.
       
    89          *
       
    90          * @param aFieldType    type of the field to match.
       
    91          * @return Matching Contact Model field if found, NULL otherwise.
       
    92          */
       
    93         const CContactItemField* FindField( const MVPbkFieldType& aFieldType ) const;
       
    94 
       
    95     public: // From MVPbkFieldTypeList
       
    96         TInt FieldTypeCount() const;
       
    97         const MVPbkFieldType& FieldTypeAt( TInt aIndex ) const;
       
    98         TBool ContainsSame( const MVPbkFieldType& aFieldType ) const;
       
    99         TInt MaxMatchPriority() const;
       
   100         const MVPbkFieldType* FindMatch(
       
   101             const TVPbkFieldVersitProperty& aMatchProperty,
       
   102             TInt aMatchPriority) const;
       
   103         const MVPbkFieldType* FindMatch( 
       
   104             TVPbkNonVersitFieldType aNonVersitType ) const;
       
   105         const MVPbkFieldType* Find( TInt aFieldTypeResId ) const;
       
   106 
       
   107     private: // Data types
       
   108         class TFieldAndTypeTuple;
       
   109         
       
   110     private:  // Constructors
       
   111         CFieldFactory();
       
   112         void ConstructL(const CFieldTypeMap& aFieldTypeMap, 
       
   113             const CContactItem& aSystemTemplate,
       
   114             const MVPbkFieldTypeList& aMasterFieldTypeList,
       
   115             RFs& aFs );
       
   116         void InsertInMasterFieldTypeOrderL( TFieldAndTypeTuple& aMapping,
       
   117             const MVPbkFieldTypeList& aMasterFieldTypeList );
       
   118         TInt IndexOfTypeInMasterList( const MVPbkFieldType& aType,
       
   119             const MVPbkFieldTypeList& aMasterFieldTypeList );
       
   120         void DoInsertMappingTupleL(
       
   121             const MVPbkFieldTypeList& aMasterFieldTypeList,
       
   122             const CFieldTypeMap& aFieldTypeMap,
       
   123             const CContactItemField& field);
       
   124 
       
   125     private:  // Data
       
   126         //Own: field and type mapping array
       
   127         RArray<TFieldAndTypeTuple> iFieldAndTypeMapping;
       
   128         ///Own: System template instance. Owned by this object.
       
   129         CContactItem* iSystemTemplate;
       
   130         ///Own: max match priority
       
   131         TInt iMaxMatchPriority;
       
   132         ///Own: non system template fields
       
   133         RPointerArray<const CContactItemField> iNonSystemTemplateFields;
       
   134     };
       
   135 
       
   136 }  // namespace VPbkCntModel
       
   137 
       
   138 #endif  // CFIELDFACTORY_H
       
   139 
       
   140 //End of file