phonebookui/Phonebook2/CommandsExtension/inc/CPbk2vCardConverter.h
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 vCard converter.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPBK2VCARDCONVERTER_H
       
    20 #define CPBK2VCARDCONVERTER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include "MPbk2vCardConverterObserver.h"
       
    24 #include <s32file.h>    // RFileWriteStream
       
    25 #include <MVPbkSingleContactOperationObserver.h>
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CVPbkContactManager;
       
    29 class MVPbkStoreContact;
       
    30 class MVPbkBaseContactField;
       
    31 class CVPbkVCardEng;
       
    32 class CPbk2AttachmentFile;
       
    33 class CPbk2AttachmentFileArray;
       
    34 class MDesC16Array;
       
    35 class MPbk2ContactNameFormatter;
       
    36 class MPbk2ContactLinkIterator;
       
    37 
       
    38 // DATA DECLARATION
       
    39 
       
    40 /**
       
    41  * Represents the different 'sending selected detail' menu selections.
       
    42  */
       
    43 enum TPbk2SendvCardChoiceItemEnumerations
       
    44     {
       
    45     ESendCurrentItem = 0,
       
    46     ESendAllData,
       
    47     ESendAllDataWithoutPicture,
       
    48     ECancel
       
    49     };
       
    50 
       
    51 // CLASS DECLARATION
       
    52 /**
       
    53  * Phonebook 2 vCard converter.
       
    54  * Responsible for converting contacts to vCards..
       
    55  */
       
    56 NONSHARABLE_CLASS(CPbk2vCardConverter) :
       
    57         public CActive,
       
    58         public MVPbkSingleContactOperationObserver
       
    59     {
       
    60     public: // Construction and destruction
       
    61 
       
    62         /**
       
    63          * Creates a new instance of this class.
       
    64          *
       
    65          * @param aFs               File server handle.
       
    66          * @param aEngine           Virtual Phonebook contact manager.
       
    67          * @param aVCardEngine      Business card engine.
       
    68          * @param aNameFormatter    Contact name formatter.
       
    69          * @return A new instance of this class
       
    70          */
       
    71         static CPbk2vCardConverter* NewL(
       
    72                 RFs& aFs,
       
    73                 CVPbkContactManager& aEngine,
       
    74                 CVPbkVCardEng& aVCardEngine,
       
    75                 MPbk2ContactNameFormatter& aNameFormatter );
       
    76 
       
    77         /**
       
    78          * Destructor.
       
    79          */
       
    80         ~CPbk2vCardConverter();
       
    81 
       
    82     public: // Interface
       
    83 
       
    84         /**
       
    85          * Initializes this process to convert given contact to a vCard file.
       
    86          *
       
    87          * @param aContacts     Contact to convert.
       
    88          * @param aField        Focused field of the contact (can be null).
       
    89          * @param aDataToSend   The data to send mapped into
       
    90          *                      TPbk2SendvCardChoiceItemEnumerations.
       
    91          * @param aObserver     Observer.
       
    92          */
       
    93         void ConvertContactL(
       
    94                 const TArray<MVPbkStoreContact*> aContacts,
       
    95                 const MVPbkBaseContactField* aField,
       
    96                 TInt aDataToSend,
       
    97                 MPbk2vCardConverterObserver& aObserver );
       
    98 
       
    99         /**
       
   100          * Initializes this process to convert given contacts to vCard files.
       
   101          *
       
   102          * @param aContacts     Contacts to convert.
       
   103          * @param aDataToSend   The data to send mapped into
       
   104          *                      TPbk2SendvCardChoiceItemEnumerations.
       
   105          * @param aObserver     Observer.
       
   106          */
       
   107         void ConvertContactsL(
       
   108                 const TArray<MVPbkStoreContact*> aContacts,
       
   109                 TInt aDataToSend,
       
   110                 MPbk2vCardConverterObserver& aObserver );
       
   111 
       
   112         /**
       
   113          * Initializes this process to convert given contacts to vCard files.
       
   114          *
       
   115          * @param aIterator     Contact link iterator.
       
   116          * @param aDataToSend   The data to send mapped into
       
   117          *                      TPbk2SendvCardChoiceItemEnumerations.
       
   118          * @param aObserver     Observer.
       
   119          */
       
   120         void ConvertContactsL(
       
   121                 MPbk2ContactLinkIterator& aIterator,
       
   122                 TInt aDataToSend,
       
   123                 MPbk2vCardConverterObserver& aObserver );
       
   124 
       
   125         /**
       
   126          * Returns the created vCard file names when the process is finished.
       
   127          *
       
   128          * @return  vCard file names.
       
   129          */
       
   130         MDesC16Array& FileNames() const;
       
   131 
       
   132         /**
       
   133          * Resets the process and destroys any results generated.
       
   134          */
       
   135         void Reset();
       
   136 
       
   137         /**
       
   138          * Returns attachment file array.
       
   139          *
       
   140          * @return  Attachment file array.
       
   141          */
       
   142         CPbk2AttachmentFileArray& AttachmentFileArray();
       
   143 
       
   144     private: // From CActive
       
   145         void RunL();
       
   146         void DoCancel();
       
   147         TInt RunError(
       
   148                 TInt aError );
       
   149 
       
   150     private: // From MVPbkSingleContactOperationObserver
       
   151         void VPbkSingleContactOperationComplete(
       
   152                 MVPbkContactOperationBase& aOperation,
       
   153                 MVPbkStoreContact* aContact );
       
   154         void VPbkSingleContactOperationFailed(
       
   155                 MVPbkContactOperationBase& aOperation,
       
   156                 TInt aError );
       
   157 
       
   158     private: // Implementation
       
   159         CPbk2vCardConverter(
       
   160                 RFs& aFs,
       
   161                 CVPbkContactManager& aEngine,
       
   162                 CVPbkVCardEng& aBCardEngine,
       
   163                 MPbk2ContactNameFormatter& aNameFormatter );
       
   164         void ConstructL();
       
   165         void CreatevCardFileL(
       
   166                 MVPbkStoreContact* aContact );
       
   167         MVPbkStoreContact* PrepareContactL(
       
   168                 MVPbkStoreContact* aContact );
       
   169         void FillTemporaryContactL(
       
   170                 MVPbkStoreContact& aDestContact,
       
   171                 const MVPbkStoreContact& aSourceContact,
       
   172                 const MVPbkBaseContactField& aSourceField ) const;
       
   173         void AddFieldToContactL(
       
   174                 MVPbkStoreContact& aDestItem,
       
   175                 const MVPbkBaseContactField& aSourceField ) const;
       
   176         void Start();
       
   177         void HandleNextContactL(
       
   178                 MVPbkStoreContact* aContact );
       
   179         void IssueRequest();
       
   180         void FinalizeVCardExport();
       
   181 
       
   182     private: // Data
       
   183         /// Ref: Open file server session
       
   184         RFs& iFs;
       
   185         /// Ref: Virtual Phonebook contact manager
       
   186         CVPbkContactManager& iEngine;
       
   187         /// Ref: Business card engine
       
   188         CVPbkVCardEng& iVCardEngine;
       
   189         /// Own: Array of vCard files
       
   190         CPbk2AttachmentFileArray* iVcardFiles;
       
   191         /// Own: Contacts to convert
       
   192         RPointerArray<MVPbkStoreContact> iContacts;
       
   193         /// Ref: Contact name formatter
       
   194         MPbk2ContactNameFormatter& iNameFormatter;
       
   195         /// Ref: The field to send, can be null
       
   196         const MVPbkBaseContactField* iField;
       
   197         /// Own: The data to send
       
   198         /// (mapped into TPbk2SendvCardChoiceItemEnumerations)
       
   199         TInt iDataToSend;
       
   200         /// Ref: Observer
       
   201         MPbk2vCardConverterObserver* iObserver;
       
   202         /// Own: Contact operation handle
       
   203         MVPbkContactOperationBase* iContactOperation;
       
   204         /// Own: Temp contact with fields to be sended
       
   205         MVPbkStoreContact* iVCardContact;
       
   206         /// Own: vCard file
       
   207         CPbk2AttachmentFile* iVCardFile;
       
   208         /// Own: File stream for vCard file writing
       
   209         RFileWriteStream iFileWriteStream;
       
   210         /// Own: Index of currently converted contact
       
   211         TInt iOpIndex;
       
   212         /// Own: Flag indicating is this field level operation
       
   213         TBool iFieldLevelOperation;
       
   214         /// Own: Flag indicating that the file writer has tried next drive
       
   215         TBool iNextDriveTried;
       
   216         /// Ref: Reference to selected contacts' iterator
       
   217         MPbk2ContactLinkIterator* iIterator;
       
   218         /// Own: Contact retrieve operation
       
   219         MVPbkContactOperationBase* iRetrieveOperation;
       
   220     };
       
   221 
       
   222 #endif // CPBK2VCARDCONVERTER_H
       
   223 
       
   224 // End of File