phonebookengines/VirtualPhonebook/VPbkVCardEng/inc/CVPbkVCardImporter.h
changeset 0 e686773b3f54
child 9 0d28c1c5b6dd
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:  Importing the CParserProperty field from CParserVCard to 
       
    15 *                contact field.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CVPBKVCARDIMPORTER_H
       
    21 #define CVPBKVCARDIMPORTER_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <s32mem.h>
       
    26 #include "MVPbkImportOperationImpl.h"
       
    27 #include <MVPbkContactFieldCopyObserver.h>
       
    28 #include <s32strm.h>
       
    29 #include <MVPbkContactStoreObserver.h>
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class MVPbkStoreContact;
       
    33 class MVPbkContactStore;
       
    34 class CVPbkVCardData;
       
    35 class CParserProperty;
       
    36 class CVPbkVCardContactFieldData;
       
    37 class TVersitDateTime;
       
    38 class CParserVCard;
       
    39 class CVPbkVCardAttributeHandler;
       
    40 class CVPbkVCardContactFieldIterator;
       
    41 class CVPbkVCardPropertyParser;
       
    42 class MVPbkContactCopyPolicy;
       
    43 
       
    44 // CLASS DECLARATIONS
       
    45 /**
       
    46  * Class is importing the CParserProperty field from CParserVCard to 
       
    47  * contact field.
       
    48  */
       
    49 NONSHARABLE_CLASS( CVPbkVCardImporter ): 
       
    50         public CActive,
       
    51         public MVPbkImportOperationImpl,
       
    52         private MVPbkContactFieldCopyObserver,
       
    53         private MVPbkContactFieldsCopyObserver,
       
    54         public MVPbkContactStoreObserver
       
    55     {
       
    56     public:
       
    57         static CVPbkVCardImporter* NewL(
       
    58             RPointerArray<MVPbkStoreContact>& aImportedContacts,
       
    59             RReadStream& aSourceStream,
       
    60             MVPbkContactStore& aTargetStore, 
       
    61             CVPbkVCardData& aData );
       
    62             
       
    63         ~CVPbkVCardImporter();
       
    64             
       
    65     public: // From MVPbkImportOperationImpl
       
    66         void StartL();
       
    67         void SetObserver( MVPbkImportOperationObserver& aObserver );
       
    68         TBool IsOwncard();
       
    69         
       
    70     public:
       
    71         //return true, if X-CATEGORIES field is present in Vcard
       
    72         TBool IsGroupcard();
       
    73         //return, X-CATEGORIES field Value
       
    74         TPtr  GetGroupcardvalue();
       
    75         
       
    76     private: // From MVPbkContactFieldCopyObserver
       
    77         void FieldAddedToContact(
       
    78                 MVPbkContactOperationBase& aOperation);
       
    79         void FieldAddingFailed(
       
    80                 MVPbkContactOperationBase& aOperation, 
       
    81                 TInt aError);
       
    82                 
       
    83     private: // From MVPbkContactFieldsCopyObserver
       
    84         void FieldsCopiedToContact(
       
    85                 MVPbkContactOperationBase& aOperation);
       
    86         void FieldsCopyFailed(
       
    87                 MVPbkContactOperationBase& aOperation, 
       
    88                 TInt aError);
       
    89 
       
    90     public: // from MVPbkContactStoreObserver
       
    91         void StoreReady(MVPbkContactStore& aContactStore);
       
    92         void StoreUnavailable(
       
    93         		MVPbkContactStore& aContactStore, 
       
    94         		TInt aReason);
       
    95         void HandleStoreEventL(
       
    96                 MVPbkContactStore& aContactStore, 
       
    97                 TVPbkContactStoreEvent aStoreEvent);
       
    98                 
       
    99     protected: // CActive
       
   100         void RunL();
       
   101         TInt RunError( TInt aError );
       
   102         void DoCancel();        
       
   103                 
       
   104     private: // types
       
   105        enum TState
       
   106             {
       
   107             EParseNext,
       
   108             ESaveField,
       
   109             ESaveContact,
       
   110             EStop
       
   111             };        
       
   112 
       
   113     private:
       
   114         CVPbkVCardImporter( 
       
   115                 RPointerArray<MVPbkStoreContact>& aImportedContacts,
       
   116                 MVPbkContactStore& aTargetStore, 
       
   117                 CVPbkVCardData& aData );
       
   118         void ConstructL(RReadStream& aSourceStream);
       
   119             
       
   120         void IssueRequest();
       
   121         CParserProperty* NextProperty();
       
   122         void ParseNextL();
       
   123         TInt FindContactFieldL( 
       
   124                 MVPbkStoreContact* aContact, 
       
   125                 TInt aFieldTypeResId );
       
   126         void SaveFieldL();
       
   127         TBool SaveDataL( CVPbkVCardContactFieldData& aData );
       
   128         void SaveL( 
       
   129             CVPbkVCardContactFieldData& aData, const TVersitDateTime& aValue );
       
   130         void SaveL( 
       
   131             CVPbkVCardContactFieldData& aData, const TDesC& aValue );
       
   132         void SaveL( 
       
   133             CVPbkVCardContactFieldData& aData, const TDesC8& aValue );
       
   134         void SaveContactL();
       
   135         void HandleFailedFieldAdditionL( TInt aError );
       
   136         void RemoveEmptyFieldsAndContacts();
       
   137         void CopyContactTitlesL();
       
   138         void ContinueCopyingToNewContactL();
       
   139         void HandleError( TInt aError );  
       
   140         void StartAsync( TState aNextState );
       
   141 
       
   142     private:
       
   143         /// Own: vcard parser
       
   144         CParserVCard* iParser;
       
   145         /// Own: contact attribute handler
       
   146         CVPbkVCardAttributeHandler* iAttributeHandler;
       
   147         /// Own: vcard field iterator
       
   148         CVPbkVCardContactFieldIterator* iContactFieldIterator;
       
   149         /// Own: current contact
       
   150         MVPbkStoreContact* iCurContact;
       
   151         /// Own: vcard property parser
       
   152         CVPbkVCardPropertyParser* iPropertyParser;
       
   153         /// Ref: reference to client's imported contacts array
       
   154         RPointerArray<MVPbkStoreContact>& iImportedContacts;
       
   155         /// Ref: target store
       
   156         MVPbkContactStore& iTargetStore;
       
   157         /// Ref: vcard engine data
       
   158         CVPbkVCardData& iData;
       
   159         /// Ref: observer interface
       
   160         MVPbkImportOperationObserver* iObserver;
       
   161         /// Own: parser's property array loop index
       
   162         TInt iArrayElementIndex;
       
   163         /// Own: save field operation
       
   164         MVPbkContactOperationBase* iAddFieldOperation;
       
   165         /// Ref: copy policy
       
   166         MVPbkContactCopyPolicy* iCopyPolicy;
       
   167         /// Own: import process state
       
   168         TState iState;
       
   169         // Own: Buffer to hold copy of VCard data to be imported 
       
   170         HBufC8* iStreamBuffer;
       
   171         // Own: Stream of VCard data to be imported 
       
   172         RDesReadStream iSourceStream;
       
   173         TBool iOwnCard;
       
   174         TBool iGroupCard;
       
   175         //Own: X-CATEGORIES field Value
       
   176         HBufC16* iGroupCardValue;
       
   177         /// Ref: cntmodel store
       
   178         MVPbkContactStore* iCntModelStore;
       
   179         /// Own: cntmodel store contact for getting contact title
       
   180         MVPbkStoreContact* iCntContact;
       
   181         /// Own: save cntmodel contact field operation
       
   182         MVPbkContactOperationBase* iAddCntContactFieldOperation;
       
   183         /// Ref: Copy cntmodel contact field operation
       
   184         MVPbkContactCopyPolicy* iCntCopyPolicy;
       
   185         /// Own: allow being overwriten
       
   186         RArray<TInt> iErasableFields;
       
   187     };
       
   188 
       
   189 #endif // CVPBKVCARDIMPORTER_H
       
   190 // End of file