phonebookui/Phonebook2/CommandsExtension/src/CPbk2vCardConverter.cpp
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
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 #include "CPbk2vCardConverter.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "Pbk2SendCmdUtils.h"
       
    23 #include <CPbk2AttachmentFile.h>
       
    24 #include <Pbk2Commands.rsg>
       
    25 #include <Pbk2CmdExtRes.rsg>
       
    26 #include <MPbk2ContactLinkIterator.h>
       
    27 
       
    28 // Virtual Phonebook
       
    29 #include <CVPbkVCardEng.h>
       
    30 #include <MVPbkStoreContact.h>
       
    31 #include <MPbk2ContactNameFormatter.h>
       
    32 #include <MVPbkContactOperationBase.h>
       
    33 #include <MVPbkContactStore.h>
       
    34 #include <MVPbkContactFieldData.h>
       
    35 #include <CVPbkContactManager.h>
       
    36 #include <MVPbkFieldType.h>
       
    37 #include <TVPbkFieldTypeMapping.h>
       
    38 #include <MVPbkContactFieldTextData.h>
       
    39 #include <MVPbkContactFieldDateTimeData.h>
       
    40 #include <MVPbkContactFieldBinaryData.h>
       
    41 #include <MVPbkContactFieldUriData.h>
       
    42 #include <MVPbkContactLink.h>
       
    43 
       
    44 // System includes
       
    45 #include <barsread.h>
       
    46 #include <coemain.h>
       
    47 
       
    48 // Debugging headers
       
    49 #include <Pbk2Debug.h>
       
    50 
       
    51 /// Unnamed namespace for local functions
       
    52 namespace {
       
    53 
       
    54 // CONSTANTS
       
    55 _LIT(KPbk2vCardFileExtension, ".vcf");
       
    56 
       
    57 // LOCAL FUNCTIONS
       
    58 
       
    59 
       
    60 /**
       
    61  * Creates an empty vCard file from the given contact.
       
    62  *
       
    63  * @param aFs               File server session handle.
       
    64  * @param aContact          The contact.
       
    65  * @param aNameFormatter    Contact name formatter.
       
    66  * @return  Created vCard file.
       
    67  */
       
    68 
       
    69 CPbk2AttachmentFile* CreateEmptyvCardFileL
       
    70         ( RFs& aFs, const MVPbkStoreContact& aContact,
       
    71           MPbk2ContactNameFormatter& aNameFormatter )
       
    72     {
       
    73     // Create the file name using contact's name
       
    74     HBufC* name = aNameFormatter.GetContactTitleL
       
    75         ( aContact.Fields(),
       
    76           MPbk2ContactNameFormatter::EPreserveLeadingSpaces );
       
    77     CleanupStack::PushL(name);
       
    78     HBufC* fileNameBuf = HBufC::NewLC(
       
    79         name->Length() + KPbk2vCardFileExtension().Length());
       
    80     TPtr fileName = fileNameBuf->Des();
       
    81     fileName = *name;
       
    82     fileName.Append(KPbk2vCardFileExtension);
       
    83 
       
    84     // Create attachment file object
       
    85     CPbk2AttachmentFile* result = CPbk2AttachmentFile::NewL
       
    86         (fileName, aFs, EFileWrite|EFileStream|EFileShareExclusive);
       
    87 
       
    88     CleanupStack::PopAndDestroy(2);  // fileNameBuf, name
       
    89     return result;
       
    90     }
       
    91 
       
    92 #ifdef _DEBUG
       
    93 enum TPanicCode
       
    94     {
       
    95     EPanicLogic_AddFieldToContactL = 1,
       
    96     EPanicInvalidStorageType,
       
    97     EPanicPostCond_PrepareContactL
       
    98     };
       
    99 
       
   100 void Panic(TPanicCode aReason)
       
   101     {
       
   102     _LIT(KPanicText, "CPbk2vCardConverter");
       
   103     User::Panic(KPanicText,aReason);
       
   104     }
       
   105 #endif // _DEBUG
       
   106 
       
   107 
       
   108 }  /// namespace
       
   109 
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2vCardConverter::CPbk2vCardConverter
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 inline CPbk2vCardConverter::CPbk2vCardConverter
       
   116         (RFs& aFs, CVPbkContactManager& aEngine, CVPbkVCardEng& aVCardEngine,
       
   117         MPbk2ContactNameFormatter& aNameFormatter) :
       
   118             CActive(EPriorityIdle),
       
   119             iFs(aFs), iEngine(aEngine), iVCardEngine(aVCardEngine),
       
   120             iNameFormatter(aNameFormatter), iField(NULL),
       
   121             iObserver(NULL), iOpIndex(0), iFieldLevelOperation(EFalse),
       
   122             iNextDriveTried(EFalse)
       
   123     {
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // CPbk2vCardConverter::~CPbk2vCardConverter
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 CPbk2vCardConverter::~CPbk2vCardConverter()
       
   131     {
       
   132     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   133         ("CPbk2vCardConverter, destructor (0x%x)"), this);
       
   134     Cancel();
       
   135     if (iVcardFiles)
       
   136         {
       
   137         iVcardFiles->ResetAndDestroy();
       
   138         delete iVcardFiles;
       
   139         }
       
   140     delete iVCardFile;
       
   141     delete iVCardContact;
       
   142     iFileWriteStream.Close();
       
   143     delete iContactOperation;
       
   144     iContacts.Reset(); // iContacts does not own its items
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CPbk2vCardConverter::ConstructL
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 inline void CPbk2vCardConverter::ConstructL()
       
   152     {
       
   153     CActiveScheduler::Add(this);
       
   154     iVcardFiles = new(ELeave) CPbk2AttachmentFileArray(1);
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2vCardConverter::CPbk2vCardConverter
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 CPbk2vCardConverter* CPbk2vCardConverter::NewL
       
   162         ( RFs& aFs, CVPbkContactManager& aEngine,
       
   163           CVPbkVCardEng& aVCardEngine,
       
   164           MPbk2ContactNameFormatter& aNameFormatter )
       
   165     {
       
   166     CPbk2vCardConverter* self = new(ELeave) CPbk2vCardConverter
       
   167         ( aFs,aEngine,aVCardEngine, aNameFormatter );
       
   168     CleanupStack::PushL(self);
       
   169     self->ConstructL();
       
   170     CleanupStack::Pop(self);
       
   171     return self;
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // CPbk2vCardConverter::ConvertContactL
       
   176 // --------------------------------------------------------------------------
       
   177 //
       
   178 void CPbk2vCardConverter::ConvertContactL
       
   179         ( const TArray<MVPbkStoreContact*> aContacts,
       
   180           const MVPbkBaseContactField* aField, TInt aDataToSend,
       
   181           MPbk2vCardConverterObserver& aObserver )
       
   182     {
       
   183     iField = aField;
       
   184     iFieldLevelOperation = ETrue;
       
   185     ConvertContactsL(aContacts, aDataToSend, aObserver);
       
   186     }
       
   187 
       
   188 // --------------------------------------------------------------------------
       
   189 // CPbk2vCardConverter::ConvertContactsL
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 void CPbk2vCardConverter::ConvertContactsL
       
   193         ( const TArray<MVPbkStoreContact*> aContacts,
       
   194           TInt aDataToSend, MPbk2vCardConverterObserver& aObserver )
       
   195     {
       
   196     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   197         ("CPbk2vCardConverter::ConvertContactsL(0x%x)"), this);
       
   198     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   199         ("CPbk2vCardConverter::ConvertContactsL, Contacts Count=%d"), 
       
   200         aContacts.Count());
       
   201     Reset();
       
   202     iObserver = &aObserver;
       
   203     iDataToSend = aDataToSend;
       
   204     for (TInt i = 0; i < aContacts.Count(); ++i)
       
   205         {
       
   206         iContacts.AppendL(aContacts[i]);
       
   207         }
       
   208 
       
   209     Start();
       
   210     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   211         ("CPbk2vCardConverter::ConvertContactsL, end (0x%x)"), this);
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CPbk2vCardConverter::ConvertContactsL
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 void CPbk2vCardConverter::ConvertContactsL
       
   219         ( MPbk2ContactLinkIterator& aIterator, TInt aDataToSend,
       
   220           MPbk2vCardConverterObserver& aObserver )
       
   221     {
       
   222     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   223         ("CPbk2vCardConverter::ConvertContactsL, dataToSend=%d"), aDataToSend);
       
   224     Reset();
       
   225     iObserver = &aObserver;
       
   226     iDataToSend = aDataToSend;
       
   227     iIterator = &aIterator;
       
   228     Start();
       
   229     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   230         ("CPbk2vCardConverter::ConvertContactsL, end (0x%x)"), this);
       
   231     }
       
   232 
       
   233 
       
   234 // --------------------------------------------------------------------------
       
   235 // CPbk2vCardConverter::FileNames
       
   236 // --------------------------------------------------------------------------
       
   237 //
       
   238 MDesC16Array& CPbk2vCardConverter::FileNames() const
       
   239     {
       
   240     return ( *iVcardFiles );
       
   241     }
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // CPbk2vCardConverter::Reset
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 void CPbk2vCardConverter::Reset()
       
   248     {
       
   249     iIterator = NULL;
       
   250     iVcardFiles->ResetAndDestroy();
       
   251     iDataToSend = ESendAllData;
       
   252     if (!iFieldLevelOperation)
       
   253         {
       
   254         iField = NULL;
       
   255         }
       
   256     }
       
   257 
       
   258 // --------------------------------------------------------------------------
       
   259 // CPbk2vCardConverter::AttachmentFileArray
       
   260 // --------------------------------------------------------------------------
       
   261 //
       
   262 CPbk2AttachmentFileArray& CPbk2vCardConverter::AttachmentFileArray()
       
   263     {
       
   264     return *iVcardFiles;
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CPbk2vCardConverter::RunL
       
   269 // --------------------------------------------------------------------------
       
   270 //
       
   271 void CPbk2vCardConverter::RunL()
       
   272     {
       
   273     if ( iIterator && iIterator->HasNext() )
       
   274         {
       
   275         HandleNextContactL( NULL );
       
   276         }
       
   277     else if (iOpIndex < iContacts.Count())
       
   278         {
       
   279         HandleNextContactL( iContacts[iOpIndex] );
       
   280         ++iOpIndex;
       
   281         }
       
   282     else
       
   283         {
       
   284         iObserver->ConversionDone(iOpIndex);
       
   285         }
       
   286     }
       
   287 
       
   288 // --------------------------------------------------------------------------
       
   289 // CPbk2vCardConverter::DoCancel
       
   290 // --------------------------------------------------------------------------
       
   291 //
       
   292 void CPbk2vCardConverter::DoCancel()
       
   293     {
       
   294     // Do nothing
       
   295     }
       
   296 
       
   297 // --------------------------------------------------------------------------
       
   298 // CPbk2vCardConverter::RunError
       
   299 // --------------------------------------------------------------------------
       
   300 //
       
   301 TInt CPbk2vCardConverter::RunError(TInt aError)
       
   302     {
       
   303     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   304         ("CPbk2vCardConverter::RunError=%d"), aError);
       
   305     Reset();
       
   306     iObserver->ConversionError(aError);
       
   307     return aError;
       
   308     }
       
   309 
       
   310 // --------------------------------------------------------------------------
       
   311 // CPbk2vCardConverter::VPbkSingleContactOperationComplete
       
   312 // --------------------------------------------------------------------------
       
   313 //
       
   314 void CPbk2vCardConverter::VPbkSingleContactOperationComplete
       
   315         ( MVPbkContactOperationBase& /*aOperation*/ ,
       
   316           MVPbkStoreContact* aContact )
       
   317     {
       
   318     if ( iRetrieveOperation )
       
   319         {
       
   320         delete iRetrieveOperation;
       
   321         iRetrieveOperation = NULL;
       
   322         TRAPD( err, HandleNextContactL( aContact ) );
       
   323         delete aContact;
       
   324         aContact = NULL;
       
   325         if ( err != KErrNone )
       
   326             {
       
   327             CCoeEnv::Static()->HandleError( err );        
       
   328             }
       
   329         }
       
   330     else
       
   331         {
       
   332         delete iContactOperation;
       
   333         iContactOperation = NULL;
       
   334 
       
   335         // Delete temp contact
       
   336         delete iVCardContact;
       
   337         iVCardContact = NULL;
       
   338 
       
   339         FinalizeVCardExport();
       
   340 
       
   341         IssueRequest();
       
   342         }
       
   343     }
       
   344 
       
   345 // --------------------------------------------------------------------------
       
   346 // CPbk2vCardConverter::VPbkSingleContactOperationFailed
       
   347 // --------------------------------------------------------------------------
       
   348 //
       
   349 void CPbk2vCardConverter::VPbkSingleContactOperationFailed
       
   350         ( MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   351     {
       
   352     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   353       ("CPbk2vCardConverter::VPbkSingleContactOperationFailed (0x%x)"), this);
       
   354     if ( iRetrieveOperation )
       
   355         {
       
   356         delete iRetrieveOperation;
       
   357         iRetrieveOperation = NULL;
       
   358         }
       
   359     else
       
   360         {
       
   361         delete iContactOperation;
       
   362         iContactOperation = NULL;
       
   363 
       
   364         iFileWriteStream.Close();
       
   365 
       
   366         if ( iNextDriveTried )
       
   367             {
       
   368             delete iVCardFile;
       
   369             iVCardFile = NULL;
       
   370 			RunError( aError );
       
   371             }
       
   372         else
       
   373             {
       
   374             TRAPD( err, 
       
   375  	        	{
       
   376 				// Try to switch next drive if previous failed
       
   377                iVCardFile->SwitchDriveL();
       
   378                iFileWriteStream.Attach( iVCardFile->File() );
       
   379                iContactOperation = iVCardEngine.ExportVCardL
       
   380                     ( iFileWriteStream, *iVCardContact, *this );
       
   381                 }); // TRAPD
       
   382                 
       
   383             if ( err != KErrNone )
       
   384            		{
       
   385             	RunError( aError );
       
   386             	}
       
   387             	
       
   388             iNextDriveTried = ETrue;
       
   389             }
       
   390         }
       
   391     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   392         ("CPbk2vCardConverter::VPbkSingleContactOperationFailed, end"), this);
       
   393     }
       
   394 
       
   395 // --------------------------------------------------------------------------
       
   396 // CPbk2vCardConverter::CreatevCardFileL
       
   397 // Creates a file containing vCard of aContact and attaches the file to
       
   398 // internal list of files.
       
   399 // --------------------------------------------------------------------------
       
   400 //
       
   401 void CPbk2vCardConverter::CreatevCardFileL(MVPbkStoreContact* aContact)
       
   402     {
       
   403     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   404         ("CPbk2vCardConverter::CreatevCardFileL (0x%x)"), this);
       
   405         
       
   406     // Check first, is the contact item empty
       
   407     // If the contact is not empty, file it so it gets sent
       
   408     if (!Pbk2SendCmdUtils::IsContactEmpty(aContact))
       
   409         {
       
   410         iVCardFile = CreateEmptyvCardFileL(iFs, *aContact, iNameFormatter);
       
   411         // Create temp handle, so that iVCardFile stays valid until we close
       
   412         // it. Stream will take care of closing tempHandle when closing stream
       
   413         RFile tempHandle;
       
   414         tempHandle.Duplicate( iVCardFile->File() );
       
   415         iFileWriteStream.Attach( tempHandle );
       
   416 
       
   417         iContactOperation =
       
   418             iVCardEngine.ExportVCardL(iFileWriteStream, *aContact, *this);
       
   419         }
       
   420     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   421         ("CPbk2vCardConverter::CreatevCardFileL, end (0x%x)"), this);
       
   422     }
       
   423 
       
   424 // --------------------------------------------------------------------------
       
   425 // CPbk2vCardConverter::PrepareContactL
       
   426 // --------------------------------------------------------------------------
       
   427 //
       
   428 MVPbkStoreContact* CPbk2vCardConverter::PrepareContactL
       
   429         ( MVPbkStoreContact* aContact )
       
   430     {
       
   431     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   432         ("CPbk2vCardConverter::PrepareContactL (0x%x)"), this);
       
   433     MVPbkStoreContact* vCardContact = NULL;
       
   434     // Create a temporary contact
       
   435     vCardContact = aContact->ParentStore().CreateNewContactLC();
       
   436     // Copy currently focused field's data to a dummy contact
       
   437     FillTemporaryContactL(*vCardContact, *aContact, *iField);
       
   438 
       
   439     __ASSERT_DEBUG(vCardContact, Panic(EPanicPostCond_PrepareContactL));
       
   440 
       
   441     CleanupStack::Pop(); // vCardContact
       
   442     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   443         ("CPbk2vCardConverter::PrepareContactL, end (0x%x)"), this);
       
   444     return vCardContact;
       
   445     }
       
   446 
       
   447 // --------------------------------------------------------------------------
       
   448 // CPbk2vCardConverter::FillTemporaryContactL
       
   449 // --------------------------------------------------------------------------
       
   450 //
       
   451 void CPbk2vCardConverter::FillTemporaryContactL
       
   452         ( MVPbkStoreContact& aDestItem,
       
   453           const MVPbkStoreContact& aSourceItem,
       
   454           const MVPbkBaseContactField& aDataField ) const
       
   455     {
       
   456     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   457         ("CPbk2vCardConverter::FillTemporaryContactL (0x%x)"), this);
       
   458     if (iDataToSend == ESendAllData)
       
   459         {
       
   460         TInt fieldCount = aSourceItem.Fields().FieldCount();
       
   461         PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   462         ("CPbk2vCardConverter::FillTemporaryContactL, fieldCount=%d"), 
       
   463         fieldCount);
       
   464         
       
   465         const MVPbkStoreContactFieldCollection& fieldSet =
       
   466             aSourceItem.Fields();
       
   467         for (TInt i=0; i < fieldCount; ++i)
       
   468             {
       
   469             const MVPbkStoreContactField& field = fieldSet.FieldAt(i);
       
   470             AddFieldToContactL(aDestItem, field);
       
   471             }
       
   472         }
       
   473     else if (iDataToSend == ESendAllDataWithoutPicture)
       
   474         {
       
   475         TInt fieldCount = aSourceItem.Fields().FieldCount();
       
   476         const MVPbkStoreContactFieldCollection& fieldSet =
       
   477             aSourceItem.Fields();
       
   478         const MVPbkFieldType& thumbnailFieldType =
       
   479                 Pbk2SendCmdUtils::ReadFieldTypeFromResL(
       
   480                     R_THUMBNAIL_FIELD_TYPE, iEngine.FieldTypes());            
       
   481         const MVPbkFieldType& imageFieldType =
       
   482                     Pbk2SendCmdUtils::ReadFieldTypeFromResL(
       
   483                         R_IMAGE_FIELD_TYPE, iEngine.FieldTypes());                    
       
   484         for (TInt i=0; i < fieldCount; ++i)
       
   485             {
       
   486             const MVPbkStoreContactField& field = fieldSet.FieldAt(i);
       
   487             // Do not add thumbnail or image            
       
   488             if (!Pbk2SendCmdUtils::IsFieldMatching(
       
   489                     field, thumbnailFieldType, iEngine.FieldTypes()) &&
       
   490                 !Pbk2SendCmdUtils::IsFieldMatching(
       
   491                         field, imageFieldType, iEngine.FieldTypes()))
       
   492                 {                                
       
   493                 AddFieldToContactL(aDestItem, field);
       
   494                 }
       
   495             }
       
   496         }
       
   497     else // ESendCurrentItem
       
   498         {
       
   499         // Actual single data field
       
   500         AddFieldToContactL(aDestItem, aDataField);
       
   501 
       
   502         // According to specification lastname & firstname
       
   503         // (when existing) must be added when sending single item
       
   504         const MVPbkBaseContactField* lastName =
       
   505             Pbk2SendCmdUtils::FindFieldL(
       
   506                 aSourceItem, R_LNAME_FIELD_TYPE, iEngine.FieldTypes());
       
   507         if (lastName)
       
   508             {
       
   509             if (!lastName->FieldData().IsEmpty())
       
   510                 {
       
   511                 AddFieldToContactL(aDestItem, *lastName);
       
   512                 }
       
   513             }
       
   514 
       
   515         const MVPbkBaseContactField* firstName =
       
   516             Pbk2SendCmdUtils::FindFieldL(
       
   517                 aSourceItem, R_FNAME_FIELD_TYPE, iEngine.FieldTypes());
       
   518         if (firstName)
       
   519             {
       
   520             if (!firstName->FieldData().IsEmpty())
       
   521                 {
       
   522                 AddFieldToContactL(aDestItem, *firstName);
       
   523                 }
       
   524             }
       
   525         }
       
   526     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   527        ("CPbk2vCardConverter::FillTemporaryContactL, end (0x%x)"), this);
       
   528     }
       
   529 
       
   530 // --------------------------------------------------------------------------
       
   531 // CPbk2vCardConverter::AddFieldToContactL
       
   532 // --------------------------------------------------------------------------
       
   533 //
       
   534 void CPbk2vCardConverter::AddFieldToContactL
       
   535         ( MVPbkStoreContact& aDestItem,
       
   536           const MVPbkBaseContactField& aSourceField ) const
       
   537     {
       
   538     const MVPbkFieldType* fieldType = aSourceField.BestMatchingFieldType();
       
   539     if ( fieldType )
       
   540         {
       
   541         MVPbkStoreContactField* dstField =
       
   542             aDestItem.CreateFieldLC( *fieldType );
       
   543 
       
   544         __ASSERT_DEBUG( dstField, Panic( EPanicLogic_AddFieldToContactL ) );
       
   545 
       
   546         switch (dstField->FieldData().DataType())
       
   547             {
       
   548             case EVPbkFieldStorageTypeText:
       
   549                 {
       
   550                 TPtrC data = MVPbkContactFieldTextData::Cast(
       
   551                                 aSourceField.FieldData()).Text();
       
   552                 MVPbkContactFieldTextData::Cast(dstField->FieldData())
       
   553                     .SetTextL(data);
       
   554                 break;
       
   555                 }
       
   556             case EVPbkFieldStorageTypeUri:
       
   557                 {
       
   558                 TPtrC data = MVPbkContactFieldUriData::Cast(
       
   559                                 aSourceField.FieldData()).Uri();
       
   560                 MVPbkContactFieldUriData::Cast(dstField->FieldData())
       
   561                     .SetUriL(data);
       
   562                 break;
       
   563                 }
       
   564             case EVPbkFieldStorageTypeDateTime:
       
   565                 {
       
   566                 TTime time = MVPbkContactFieldDateTimeData::Cast(
       
   567                                 aSourceField.FieldData()).DateTime();
       
   568                 MVPbkContactFieldDateTimeData::Cast(dstField->FieldData())
       
   569                     .SetDateTime(time);
       
   570                 break;
       
   571                 }
       
   572             case EVPbkFieldStorageTypeBinary:
       
   573                 {
       
   574                 TPtrC8 data = MVPbkContactFieldBinaryData::Cast(
       
   575                     aSourceField.FieldData()).BinaryData();
       
   576                 MVPbkContactFieldBinaryData::Cast(dstField->FieldData())
       
   577                     .SetBinaryDataL(data);
       
   578                 break;
       
   579                 }
       
   580             default:
       
   581                 {
       
   582                 __ASSERT_DEBUG(EFalse, Panic(EPanicInvalidStorageType));
       
   583                 break;
       
   584                 }
       
   585             }
       
   586         aDestItem.AddFieldL(dstField);
       
   587         CleanupStack::Pop();
       
   588         }
       
   589     }
       
   590 
       
   591 // --------------------------------------------------------------------------
       
   592 // CPbk2vCardConverter::Start
       
   593 // --------------------------------------------------------------------------
       
   594 //
       
   595 void CPbk2vCardConverter::Start()
       
   596     {
       
   597     iOpIndex = 0;
       
   598     IssueRequest();
       
   599     }
       
   600 
       
   601 // --------------------------------------------------------------------------
       
   602 // CPbk2vCardConverter::HandleNextContactL
       
   603 // --------------------------------------------------------------------------
       
   604 //
       
   605 void CPbk2vCardConverter::HandleNextContactL( MVPbkStoreContact* aContact )
       
   606     {
       
   607     if ( aContact )
       
   608         {
       
   609         if (iVCardContact)
       
   610             {
       
   611             delete iVCardContact;
       
   612             iVCardContact = NULL;
       
   613             }
       
   614         iVCardContact = PrepareContactL(aContact);
       
   615         CreatevCardFileL(iVCardContact);
       
   616         }
       
   617     else
       
   618         {
       
   619         MVPbkContactLink* link = iIterator->NextL();
       
   620         CleanupDeletePushL( link );
       
   621         iRetrieveOperation = iEngine.RetrieveContactL( *link, *this );
       
   622         CleanupStack::PopAndDestroy(); // link
       
   623         }
       
   624     }
       
   625 
       
   626 // --------------------------------------------------------------------------
       
   627 // CPbk2vCardConverter::IssueRequest
       
   628 // --------------------------------------------------------------------------
       
   629 //
       
   630 void CPbk2vCardConverter::IssueRequest()
       
   631     {
       
   632     TRequestStatus* status = &iStatus;
       
   633     User::RequestComplete(status, KErrNone);
       
   634     SetActive();
       
   635     }
       
   636 
       
   637 // --------------------------------------------------------------------------
       
   638 // CPbk2vCardConverter::FinalizeVCardExport
       
   639 // --------------------------------------------------------------------------
       
   640 //
       
   641 void CPbk2vCardConverter::FinalizeVCardExport()
       
   642     {
       
   643    	PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   644         ("CPbk2vCardConverter::FinalizeVCardExport (0x%x)"), this);
       
   645     TRAPD( err, 
       
   646         {
       
   647         // commit stream after exportvcard has completed
       
   648         iFileWriteStream.CommitL();
       
   649         iFileWriteStream.Close();
       
   650         iVcardFiles->AppendL(iVCardFile); // Takes ownership
       
   651         iVCardFile = NULL;
       
   652         }); //TRAPD
       
   653         
       
   654     if ( err != KErrNone )
       
   655         {
       
   656         RunError( err );
       
   657         }
       
   658             
       
   659     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   660         ("CPbk2vCardConverter::FinalizeVCardExport, end (0x%x)"), this);
       
   661     }
       
   662 
       
   663 //  End of File