phonebookui/Phonebook2/CommandsExtension/src/CPbk2SendContactCmd.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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 send contact command.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2SendContactCmd.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "Pbk2SendCmdUtils.h"
       
    23 #include "CPbk2vCardConverter.h"
       
    24 #include <MPbk2CommandObserver.h>
       
    25 #include <Pbk2Commands.rsg>
       
    26 #include <Pbk2CmdExtRes.rsg>
       
    27 #include <Pbk2ProcessDecoratorFactory.h>
       
    28 #include <MPbk2ProcessDecorator.h>
       
    29 #include <MPbk2ContactLinkIterator.h>
       
    30 #include <CPbk2AttachmentFile.h>
       
    31 #include <CPbk2DriveSpaceCheck.h>
       
    32 #include <CPbk2AppUiBase.h>
       
    33 #include <CPbk2ApplicationServices.h>
       
    34 
       
    35 // Virtual Phonebook
       
    36 #include <CVPbkContactManager.h>
       
    37 #include <CVPbkContactLinkArray.h>
       
    38 #include <CVPbkVCardEng.h>
       
    39 #include <MVPbkContactOperationBase.h>
       
    40 #include <MPbk2ContactUiControl.h>
       
    41 #include <MVPbkStoreContactFieldCollection.h>
       
    42 #include <MVPbkStoreContact.h>
       
    43 #include <MVPbkFieldType.h>
       
    44 #include <TVPbkFieldTypeMapping.h>
       
    45 #include <VPbkEng.rsg>
       
    46 
       
    47 // System includes
       
    48 #include <txtrich.h>
       
    49 #include <barsread.h>
       
    50 #include <AknWaitDialog.h>
       
    51 #include <sendui.h>
       
    52 #include <TSendingCapabilities.h>
       
    53 #include <MsgBioUids.h>
       
    54 #include <SendUiConsts.h>
       
    55 #include <eikenv.h>
       
    56 #include <CMessageData.h>
       
    57 #include <eikclb.h>
       
    58 #include <aknPopup.h>
       
    59 #include <featmgr.h>
       
    60 
       
    61 // Debugging headers
       
    62 #include <Pbk2Debug.h>
       
    63 
       
    64 /// Unnamed namespace for local definitions
       
    65 namespace {
       
    66 
       
    67 const TUint KNoMenu = 0;
       
    68 const TInt KGranularity( 4 );
       
    69 
       
    70 struct TPbk2SelectionMapping
       
    71     {
       
    72     /// Maps to first selection
       
    73     TPbk2SendvCardChoiceItemEnumerations iStSelection;
       
    74     /// Maps to second selection
       
    75     TPbk2SendvCardChoiceItemEnumerations iNdSelection;
       
    76     /// Maps to third selection
       
    77     TPbk2SendvCardChoiceItemEnumerations iRdSelection;
       
    78     //// Resource id
       
    79     TInt iResId;
       
    80     };
       
    81 
       
    82 enum TSelection
       
    83     {
       
    84     ESelectionLast = -1
       
    85     };
       
    86 
       
    87 /// Maps listbox index selections to 'sending selected detail'
       
    88 /// menu selections If command not supported selection is ECancel.
       
    89 static const TPbk2SelectionMapping SelectionMapping[] =
       
    90     {
       
    91     {ESendCurrentItem, ESendAllData, ECancel,
       
    92         R_PBK2_CONTACTINFO_SEND_OPTIONS},
       
    93     {ESendCurrentItem, ESendAllDataWithoutPicture, ESendAllData,
       
    94         R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL},
       
    95     {ESendAllDataWithoutPicture, ESendAllData, ECancel,
       
    96         R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL_NO_FIELD},
       
    97     {ESendAllDataWithoutPicture, ESendAllData, ECancel,
       
    98         R_PHONEBOOK2_SEND_OPTIONS},
       
    99     {ECancel, ECancel, ECancel, ESelectionLast}
       
   100     };
       
   101 
       
   102 
       
   103 /// Represents the different listbox index selections.
       
   104 enum TPbk2ListBoxSelections
       
   105     {
       
   106     EFirstSelection = 0,
       
   107     ESecondSelection,
       
   108     EThirdSelection
       
   109     };
       
   110 
       
   111 #if 0 // Not used in ECE
       
   112 /**
       
   113     Function checks if the focused field is one of these fields.
       
   114 
       
   115     - Prefix
       
   116     - Suffix
       
   117     - Firstname
       
   118     JAPANESE.PRONOUNCIATION{
       
   119     - FirstnameReading
       
   120     }JAPANESE.PRONOUNCIATION
       
   121     - Middle name
       
   122     - Lastname
       
   123     JAPANESE.PRONOUNCIATION{
       
   124     - Last name Reading
       
   125     }JAPANESE.PRONOUNCIATION
       
   126     - Ringing tone
       
   127     CALL.OBJECT.DISPLAY{
       
   128     - Image
       
   129     }CALL.OBJECT.DISPLAY
       
   130     CALL.OBJECT.DISPLAY{
       
   131     - Text for call
       
   132     }CALL.OBJECT.DISPLAY
       
   133     - Synchronization
       
   134 */
       
   135 TBool IsNameOrPropertyField( const MVPbkBaseContactField& aField )
       
   136     {
       
   137     TBool res ( EFalse );
       
   138     const MVPbkFieldType* fieldType = aField.BestMatchingFieldType();
       
   139     if ( fieldType )
       
   140         {
       
   141         TInt resId( fieldType->FieldTypeResId() );
       
   142         if ( resId == R_VPBK_FIELD_TYPE_PREFIX ||
       
   143             resId == R_VPBK_FIELD_TYPE_SUFFIX ||
       
   144             resId == R_VPBK_FIELD_TYPE_FIRSTNAME ||
       
   145             resId == R_VPBK_FIELD_TYPE_FIRSTNAMEREADING ||
       
   146             resId == R_VPBK_FIELD_TYPE_MIDDLENAME ||
       
   147             resId == R_VPBK_FIELD_TYPE_LASTNAME ||
       
   148             resId == R_VPBK_FIELD_TYPE_LASTNAMEREADING ||
       
   149             resId == R_VPBK_FIELD_TYPE_RINGTONE ||
       
   150             resId == R_VPBK_FIELD_TYPE_CALLEROBJIMG ||
       
   151             resId == R_VPBK_FIELD_TYPE_CALLEROBJTEXT ||
       
   152             resId == R_VPBK_FIELD_TYPE_SYNCCLASS )
       
   153             {
       
   154             res = ETrue;
       
   155             }
       
   156         }
       
   157     return res;
       
   158     }
       
   159 #endif // 0
       
   160 
       
   161 #ifdef _DEBUG
       
   162 
       
   163 enum TPanicCode
       
   164     {
       
   165     EPanicPreCond_SendvCardsL = 1,
       
   166     EPanicLogic_CmdSendContactDataL,
       
   167     EPanicLogic_MapSelection,
       
   168     EPanicLogic_ConversionDone,
       
   169     EPanicLogic_ReadFileTypeL,
       
   170     ERunL_OOB,
       
   171     EPanicPreCond_ErrArgument,
       
   172     EResetFindResult
       
   173     };
       
   174 
       
   175 void Panic(TPanicCode aReason)
       
   176     {
       
   177     _LIT(KPanicText, "CPbk2SendContactCmd");
       
   178     User::Panic(KPanicText,aReason);
       
   179     }
       
   180 
       
   181 #endif // _DEBUG
       
   182 
       
   183 
       
   184 /**
       
   185  * Helper class for sending the vCard(s) in async callback.
       
   186  */
       
   187 NONSHARABLE_CLASS(CVCardSender) : public CIdle
       
   188     {
       
   189     public: // Constructor
       
   190 
       
   191         /**
       
   192          * Creates a new instance of this object.
       
   193          *
       
   194          * @param aPriority     Desired priority.
       
   195          */
       
   196         static CVCardSender* NewL(
       
   197                 TInt aPriority );
       
   198 
       
   199     private: // From CIdle
       
   200         void RunL();
       
   201         TInt RunError(
       
   202                 TInt aError );
       
   203 
       
   204     private: // Implementation
       
   205         CVCardSender(
       
   206                 TInt aPriority );
       
   207     };
       
   208 
       
   209 // --------------------------------------------------------------------------
       
   210 // CVCardSender::CVCardSender
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 inline CVCardSender::CVCardSender( TInt aPriority ):
       
   214         CIdle( aPriority )
       
   215     {
       
   216     CActiveScheduler::Add( this );
       
   217     }
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CVCardSender::NewL
       
   221 // --------------------------------------------------------------------------
       
   222 //
       
   223 CVCardSender* CVCardSender::NewL( TInt aPriority )
       
   224     {
       
   225     return new ( ELeave ) CVCardSender( aPriority );
       
   226     }
       
   227 
       
   228 // --------------------------------------------------------------------------
       
   229 // CVCardSender::RunL
       
   230 // --------------------------------------------------------------------------
       
   231 //
       
   232 void CVCardSender::RunL()
       
   233     {
       
   234     CIdle::RunL();
       
   235     // Destroy self.
       
   236     // If RunL (the callback) leaves RunError will handle the deletion.
       
   237     delete this;
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------
       
   241 // CVCardSender::RunError
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 TInt CVCardSender::RunError( TInt aError)
       
   245     {
       
   246     delete this;
       
   247     // Forward all errors to the active scheduler
       
   248     return aError;
       
   249     }
       
   250 
       
   251 /**
       
   252  * Creates a rich text object and packages contents of a file to it.
       
   253  * The file's data is not converted in any way except that characters
       
   254  * are widened to 16 bits.
       
   255  *
       
   256  * @param aEikEnv       EIKON environment.
       
   257  * @param aFileName     Name of the file to convert.
       
   258  * @return  A new rich text object with file's contents.
       
   259  *          The returned object is also left on top of the cleanup stack.
       
   260  */
       
   261 CRichText* CreateRichTextFromFileLC
       
   262         (CEikonEnv& aEikEnv, const TDesC& aFileName)
       
   263     {
       
   264     PBK2_DEBUG_PRINT
       
   265         (PBK2_DEBUG_STRING("CreateRichTextFromFileLC (%S)"), &aFileName);
       
   266     // Common allocation granularity and buffer size for rich text and
       
   267     // file reading
       
   268     const TInt KBufSize = CEditableText::EDefaultTextGranularity;
       
   269 
       
   270     // Create a rich text object with default formatting
       
   271     CRichText* richText = CRichText::NewL(
       
   272         aEikEnv.SystemParaFormatLayerL(),
       
   273         aEikEnv.SystemCharFormatLayerL(),
       
   274         CEditableText::ESegmentedStorage,
       
   275         KBufSize  // Allocation granularity
       
   276         );
       
   277     CleanupStack::PushL(richText);
       
   278 
       
   279     // Open the file for reading
       
   280     RFile file;
       
   281     User::LeaveIfError(file.Open
       
   282         (aEikEnv.FsSession(), aFileName,
       
   283         EFileRead|EFileStream|EFileShareReadersOnly));
       
   284     CleanupClosePushL(file);
       
   285 
       
   286     // Create two buffers: 8-bit for reading from file and 16-bit for
       
   287     // converting to 16-bit format
       
   288     HBufC8* buf8 = HBufC8::NewLC(KBufSize);
       
   289     TPtr8 ptr8 = buf8->Des();
       
   290     HBufC16* buf16 = HBufC16::NewLC(ptr8.MaxLength());
       
   291     TPtr16 ptr16 = buf16->Des();
       
   292 
       
   293     // Read, convert and append to rich text until the file ends
       
   294     for (TInt err = file.Read(ptr8);
       
   295         ptr8.Length() > 0;
       
   296         err = file.Read(ptr8))
       
   297         {
       
   298         User::LeaveIfError(err);
       
   299         ptr16.Copy(ptr8);
       
   300         richText->InsertL(richText->DocumentLength(), ptr16);
       
   301         }
       
   302 
       
   303     // Cleanup and return
       
   304     CleanupStack::PopAndDestroy(3);  // buf16, buf8, file
       
   305     PBK2_DEBUG_PRINT
       
   306         (PBK2_DEBUG_STRING("CreateRichTextFromFileLC, end"));
       
   307     return richText;
       
   308     }
       
   309 
       
   310 }  /// namespace
       
   311 
       
   312 /**
       
   313  * Sending parameters.
       
   314  */
       
   315 class TPbk2SendingParams
       
   316     {
       
   317     public: // Construction and destruction
       
   318 
       
   319         /**
       
   320          * Constructor.
       
   321          *
       
   322          * @param aMtmFilter    MTM filter
       
   323          * @param aCapabilities Sending capabilities.
       
   324          */
       
   325         TPbk2SendingParams(
       
   326                 CArrayFixFlat<TUid>* aMtmFilter,
       
   327                 TSendingCapabilities aCapabilities );
       
   328 
       
   329     public: // Data
       
   330         /// Ref: MTM filter
       
   331         CArrayFixFlat<TUid>* iMtmFilter;
       
   332         /// Own: Sending capabilities
       
   333         TSendingCapabilities iCapabilities;
       
   334     };
       
   335 
       
   336 // --------------------------------------------------------------------------
       
   337 // TPbk2SendingParams::TPbk2SendingParams
       
   338 // --------------------------------------------------------------------------
       
   339 //
       
   340 inline TPbk2SendingParams::TPbk2SendingParams
       
   341             ( CArrayFixFlat<TUid>* aMtmFilter,
       
   342               TSendingCapabilities aCapabilities ) :
       
   343                 iMtmFilter( aMtmFilter ), iCapabilities( aCapabilities )
       
   344     {
       
   345     }
       
   346 
       
   347 // --------------------------------------------------------------------------
       
   348 // CPbk2SendContactCmd::CPbk2SendContactCmd
       
   349 // --------------------------------------------------------------------------
       
   350 //
       
   351 inline CPbk2SendContactCmd::CPbk2SendContactCmd(
       
   352         MPbk2ContactUiControl& aUiControl ) :
       
   353     CActive(EPriorityIdle),
       
   354     iUiControl(&aUiControl)
       
   355     {
       
   356     }
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CPbk2SendContactCmd::~CPbk2SendContactCmd
       
   360 // --------------------------------------------------------------------------
       
   361 //
       
   362 CPbk2SendContactCmd::~CPbk2SendContactCmd()
       
   363     {
       
   364     PBK2_DEBUG_PRINT
       
   365         (PBK2_DEBUG_STRING("CPbk2SendContactCmd, destructor (0x%x)"), this);
       
   366     Cancel();
       
   367     if( iUiControl )
       
   368         {
       
   369         iUiControl->RegisterCommand( NULL );
       
   370         }
       
   371 
       
   372     delete iWaiter;
       
   373     delete iSelectedContacts;
       
   374     delete iConverter;
       
   375     delete iVCardSender;
       
   376     delete iVCardEngine;
       
   377     iStoreContacts.ResetAndDestroy();
       
   378     iStoreContacts.Close();
       
   379     delete iRetrieveOperation;
       
   380     delete iDecorator;
       
   381     delete iCntIterator;
       
   382     delete iSendUi;
       
   383     Release( iAppServices );
       
   384     }
       
   385 
       
   386 // --------------------------------------------------------------------------
       
   387 // CPbk2SendContactCmd::NewL
       
   388 // --------------------------------------------------------------------------
       
   389 //
       
   390 CPbk2SendContactCmd* CPbk2SendContactCmd::NewL
       
   391     (MPbk2ContactUiControl& aUiControl)
       
   392     {
       
   393     CPbk2SendContactCmd* self = new (ELeave)CPbk2SendContactCmd(aUiControl);
       
   394     CleanupStack::PushL(self);
       
   395     self->ConstructL();
       
   396     CleanupStack::Pop(self);
       
   397     return self;
       
   398     }
       
   399 
       
   400 // --------------------------------------------------------------------------
       
   401 // CPbk2SendContactCmd::ConstructL
       
   402 // --------------------------------------------------------------------------
       
   403 //
       
   404 void CPbk2SendContactCmd::ConstructL()
       
   405     {
       
   406     PBK2_DEBUG_PRINT
       
   407         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ConstructL(0x%x)"), this);
       
   408     CActiveScheduler::Add(this);
       
   409     CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL
       
   410         ( CCoeEnv::Static()->FsSession() );
       
   411     CleanupStack::PushL( driveSpaceCheck );
       
   412     // check FFS situation
       
   413     driveSpaceCheck->DriveSpaceCheckL();
       
   414     CleanupStack::PopAndDestroy( driveSpaceCheck );
       
   415     iEikEnv = CEikonEnv::Static();
       
   416     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   417     iVCardEngine = CVPbkVCardEng::NewL( iAppServices->ContactManager() );
       
   418     iConverter = CPbk2vCardConverter::NewL(
       
   419         iEikEnv->FsSession(),
       
   420         iAppServices->ContactManager(),
       
   421         *iVCardEngine,
       
   422         iAppServices->NameFormatter() );
       
   423     iVCardSender = CVCardSender::NewL(CActive::EPriorityIdle);
       
   424     iSendUi = CSendUi::NewL();
       
   425 
       
   426     if( iUiControl )
       
   427         {
       
   428         // Use iterator to make sure that OOM situation does not occur
       
   429         // if multiple contacts selected.
       
   430         iCntIterator = iUiControl->SelectedContactsIteratorL();
       
   431         if ( !iCntIterator )
       
   432             {
       
   433             // If no iterator, there is no selected contacts.
       
   434             // Only one contact is returned.
       
   435             iSelectedContacts = iUiControl->SelectedContactsOrFocusedContactL();
       
   436             }
       
   437         iFocusedField = iUiControl->FocusedField();
       
   438         iUiControl->RegisterCommand( this );
       
   439         }
       
   440     PBK2_DEBUG_PRINT
       
   441         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ConstructL, end"));
       
   442     }
       
   443 
       
   444 // --------------------------------------------------------------------------
       
   445 // CPbk2SendContactCmd::ExecuteLD
       
   446 // --------------------------------------------------------------------------
       
   447 //
       
   448 void CPbk2SendContactCmd::ExecuteLD()
       
   449     {
       
   450     PBK2_DEBUG_PRINT
       
   451         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ExecuteLD(0x%x)"), this);
       
   452 
       
   453     CleanupStack::PushL(this);
       
   454 
       
   455     iCurrentContactLinkIndex = 0;
       
   456     iState = EShowingSendQuery;
       
   457     IssueRequest();
       
   458 
       
   459     CleanupStack::Pop(this);
       
   460     PBK2_DEBUG_PRINT
       
   461         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ExecuteLD, end"), this);
       
   462     }
       
   463 
       
   464 // --------------------------------------------------------------------------
       
   465 // CPbk2SendContactCmd::AddObserver
       
   466 // --------------------------------------------------------------------------
       
   467 //
       
   468 void CPbk2SendContactCmd::AddObserver(MPbk2CommandObserver& aObserver)
       
   469     {
       
   470     iCommandObserver = &aObserver;
       
   471     }
       
   472 
       
   473 // --------------------------------------------------------------------------
       
   474 // CPbk2SendContactCmd::ResetUiControl
       
   475 // --------------------------------------------------------------------------
       
   476 //
       
   477 void CPbk2SendContactCmd::ResetUiControl(
       
   478         MPbk2ContactUiControl& aUiControl)
       
   479     {
       
   480     if (iUiControl == & aUiControl)
       
   481         {
       
   482         iUiControl = NULL;
       
   483         }
       
   484     }
       
   485 
       
   486 // --------------------------------------------------------------------------
       
   487 // CPbk2SendContactCmd::RunL
       
   488 // --------------------------------------------------------------------------
       
   489 //
       
   490 void CPbk2SendContactCmd::RunL()
       
   491     {
       
   492     switch (iState)
       
   493         {
       
   494         case EShowingSendQuery:
       
   495             {
       
   496             iMtmUid = ShowSendQueryL();
       
   497             if (iMtmUid == KNullUid)
       
   498                 {
       
   499                 iState = ECancelling;
       
   500                 }
       
   501             else
       
   502                 {
       
   503                 iState = ERetrievingContact;
       
   504                 }
       
   505             IssueRequest();
       
   506             break;
       
   507             }
       
   508 
       
   509         case ERetrievingContact:
       
   510             {
       
   511             if ( iSelectedContacts )
       
   512                 {
       
   513                 __ASSERT_DEBUG( iSelectedContacts->Count() >
       
   514                         iCurrentContactLinkIndex, Panic( ERunL_OOB ) );
       
   515                 RetrieveContactL(iSelectedContacts->At
       
   516                     (iCurrentContactLinkIndex));
       
   517                 }
       
   518             else
       
   519                 {
       
   520                 iState = ESelectingSentData;
       
   521                 IssueRequest();
       
   522                 }
       
   523             break;
       
   524             }
       
   525 
       
   526         case ESelectingSentData:
       
   527             {
       
   528             TInt selection(ESendAllData);
       
   529             if ( iSelectedContacts )
       
   530                 {
       
   531                 // If there is only one contact or launched in info view
       
   532                 // do the data selection
       
   533                 selection = SelectSentDataL();
       
   534                 }
       
   535             ConvertContactL(selection);
       
   536             break;
       
   537             }
       
   538 
       
   539         case EStopping:
       
   540             {
       
   541             ProcessDone(KErrNone);
       
   542             break;
       
   543             }
       
   544 
       
   545         case ECancelling:
       
   546             {
       
   547             ProcessDone( KErrCancel );
       
   548             break;
       
   549             }
       
   550         case EReleaseResource:
       
   551             {
       
   552             CPbk2AttachmentFileArray& fileArray = iConverter->AttachmentFileArray();
       
   553             TInt count = fileArray.Count();
       
   554             TInt deleteIndex = count -1;
       
   555             CPbk2AttachmentFile * file = fileArray.At(deleteIndex);
       
   556             fileArray.Delete(deleteIndex);
       
   557             delete file;
       
   558             
       
   559             if ( count > 1) 
       
   560             {
       
   561               IssueRequest();
       
   562             }
       
   563             else
       
   564             {
       
   565               iWaiter->AsyncStop();
       
   566             }
       
   567             break;
       
   568             }
       
   569         }
       
   570     }
       
   571 
       
   572 // --------------------------------------------------------------------------
       
   573 // CPbk2SendContactCmd::RunError
       
   574 // --------------------------------------------------------------------------
       
   575 //
       
   576 TInt CPbk2SendContactCmd::RunError(TInt aError)
       
   577     {
       
   578     if( iWaiter && iWaiter->IsStarted() )
       
   579         iWaiter->AsyncStop();
       
   580     
       
   581     return FilterErrors(aError);
       
   582     }
       
   583 
       
   584 // --------------------------------------------------------------------------
       
   585 // CPbk2SendContactCmd::DoCancel
       
   586 // --------------------------------------------------------------------------
       
   587 //
       
   588 void CPbk2SendContactCmd::DoCancel()
       
   589     {
       
   590     if( iWaiter && iWaiter->IsStarted() )
       
   591         iWaiter->AsyncStop();
       
   592     
       
   593     delete iRetrieveOperation;
       
   594     iRetrieveOperation = NULL;
       
   595     }
       
   596 
       
   597 // --------------------------------------------------------------------------
       
   598 // CPbk2SendContactCmd::ConversionDone
       
   599 // --------------------------------------------------------------------------
       
   600 //
       
   601 void CPbk2SendContactCmd::ConversionDone( TInt PBK2_DEBUG_ONLY( aCount ) )
       
   602     {
       
   603     PBK2_DEBUG_PRINT
       
   604         ( PBK2_DEBUG_STRING( "CPbk2SendContactCmd::ConversionDone(0x%x)" ),
       
   605         this );
       
   606 
       
   607     __ASSERT_DEBUG( iStoreContacts.Count() == aCount,
       
   608         Panic( EPanicLogic_ConversionDone ) );
       
   609 
       
   610     // Decorator will call processdismissed which will continue
       
   611     // contact send
       
   612     iDecorator->ProcessStopped();
       
   613 
       
   614     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   615         ( "CPbk2SendContactCmd::ConversionDone(0x%x), end" ), this );
       
   616 
       
   617     }
       
   618 
       
   619 // --------------------------------------------------------------------------
       
   620 // CPbk2SendContactCmd::ConversionError
       
   621 // --------------------------------------------------------------------------
       
   622 //
       
   623 void CPbk2SendContactCmd::ConversionError(TInt aError)
       
   624     {
       
   625     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   626         ("CPbk2SendContactCmd::ConversionError(%d)"), aError);
       
   627 
       
   628     // Report the failure to the user
       
   629     CCoeEnv::Static()->HandleError( aError );
       
   630 
       
   631     // iDecorator calls processdismissed
       
   632     iDecorator->ProcessStopped();
       
   633     iState = EStopping;
       
   634 
       
   635     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   636         ("CPbk2SendContactCmd::ConversionError(0x%x), end"), this);
       
   637     }
       
   638 
       
   639 // --------------------------------------------------------------------------
       
   640 // CPbk2SendContactCmd::VPbkSingleContactOperationComplete
       
   641 // --------------------------------------------------------------------------
       
   642 //
       
   643 void CPbk2SendContactCmd::VPbkSingleContactOperationComplete(
       
   644     MVPbkContactOperationBase& aOperation, MVPbkStoreContact* aContact)
       
   645     {
       
   646     if (&aOperation == iRetrieveOperation)
       
   647         {
       
   648         delete iRetrieveOperation;
       
   649         iRetrieveOperation = NULL;
       
   650 
       
   651         // We now have a store contact
       
   652         TInt error = iStoreContacts.Append(aContact);
       
   653         if ( error == KErrNone )
       
   654             {
       
   655             ++iCurrentContactLinkIndex;
       
   656             if (iSelectedContacts->Count() == iCurrentContactLinkIndex)
       
   657                 {
       
   658                 iCurrentContactLinkIndex = 0;
       
   659                 iState = ESelectingSentData;
       
   660                 }
       
   661             else
       
   662                 {
       
   663                 iState = ERetrievingContact;
       
   664                 }
       
   665 
       
   666             IssueRequest();
       
   667             }
       
   668         else
       
   669             {
       
   670             ProcessDone( error );
       
   671             }
       
   672         }
       
   673     else
       
   674         {
       
   675         IssueStopRequest();
       
   676         }
       
   677     }
       
   678 
       
   679 // --------------------------------------------------------------------------
       
   680 // CPbk2SendContactCmd::VPbkSingleContactOperationFailed
       
   681 // --------------------------------------------------------------------------
       
   682 //
       
   683 void CPbk2SendContactCmd::VPbkSingleContactOperationFailed(
       
   684         MVPbkContactOperationBase& aOperation, TInt aError)
       
   685     {
       
   686     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   687       ("CPbk2SendContactCmd::VPbkSingleContactOperationFailed (%d)"), aError);
       
   688     if (&aOperation == iRetrieveOperation)
       
   689         {
       
   690         delete iRetrieveOperation;
       
   691         iRetrieveOperation = NULL;
       
   692 
       
   693         // We cannot get the contact, so we have to
       
   694         // fail. We cannot continue, since this operation
       
   695         // was executed only in case of one contact.
       
   696         ProcessDone(aError);
       
   697         }
       
   698     }
       
   699 
       
   700 // --------------------------------------------------------------------------
       
   701 // CPbk2SendContactCmd::SendvCardsLD
       
   702 // --------------------------------------------------------------------------
       
   703 //
       
   704 void CPbk2SendContactCmd::SendvCardsLD()
       
   705     {
       
   706     PBK2_DEBUG_PRINT
       
   707         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::SendvCardsLD(0x%x)"), this);
       
   708     // Relinquish ownership, iVCardSender takes care of it self
       
   709     iVCardSender = NULL;
       
   710 
       
   711     CMessageData* messageData = CMessageData::NewL();
       
   712     CleanupStack::PushL( messageData );
       
   713 
       
   714     if (iConverter->FileNames().MdcaCount() > 0 &&
       
   715         !iUnderDestruction)
       
   716         {
       
   717         TSendingCapabilities caps;
       
   718         User::LeaveIfError(
       
   719                 iSendUi->ServiceCapabilitiesL( iMtmUid, caps ) );
       
   720         if (caps.iFlags & TSendingCapabilities::ESupportsAttachments)
       
   721             {
       
   722             // Not sending through SMS, just pass the attachments
       
   723             __ASSERT_DEBUG(iConverter->FileNames().MdcaCount()>=1,
       
   724                 Panic(EPanicPreCond_SendvCardsL));
       
   725 
       
   726             //Fill message data
       
   727             const TInt count( iConverter->FileNames().MdcaCount());
       
   728             for( TInt i( 0 ); i < count; ++i )
       
   729                 {
       
   730                 messageData->AppendAttachmentHandleL(
       
   731                         iConverter->AttachmentFileArray().FileHandleAt( i ) );
       
   732                 }
       
   733             SendMsgUsingSendUI(messageData);
       
   734             }
       
   735         else if (caps.iFlags & TSendingCapabilities::ESupportsBodyText)
       
   736             {
       
   737             PBK2_DEBUG_PRINT
       
   738                 (PBK2_DEBUG_STRING("SendvCardsLD, KSenduiMtmSmsUid"));
       
   739             // Sending through SMS -> there should be only one vCard
       
   740             // attachment. Package the attachment to a rich text object and
       
   741             // send it as the message body.
       
   742             __ASSERT_DEBUG(iConverter->FileNames().MdcaCount()==1,
       
   743                 Panic(EPanicPreCond_SendvCardsL));
       
   744 
       
   745             // Copy the one and only attachment into a rich text object
       
   746             CRichText* msgBody = CreateRichTextFromFileLC
       
   747                 (*iEikEnv, iConverter->FileNames().MdcaPoint(0));
       
   748 
       
   749             messageData->SetBodyTextL( msgBody );
       
   750             SendMsgUsingSendUI(messageData);
       
   751 
       
   752             CleanupStack::PopAndDestroy(msgBody);
       
   753             }
       
   754         else
       
   755             {
       
   756             User::Leave( KErrNotSupported );
       
   757             }
       
   758         }
       
   759 
       
   760     CleanupStack::PopAndDestroy(); //messageData
       
   761 
       
   762     ProcessDone(KErrNone);
       
   763         PBK2_DEBUG_PRINT
       
   764         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::SendvCardsLD, end"), this);
       
   765     }
       
   766 
       
   767 // --------------------------------------------------------------------------
       
   768 // CPbk2SendContactCmd::SendvCardsLD
       
   769 // --------------------------------------------------------------------------
       
   770 //
       
   771 TInt CPbk2SendContactCmd::SendvCardsLD(TAny* aThis)
       
   772     {
       
   773     __ASSERT_DEBUG( aThis, Panic(EPanicPreCond_ErrArgument) );
       
   774 
       
   775     CPbk2SendContactCmd* self = static_cast<CPbk2SendContactCmd*>(aThis);
       
   776     self->SendvCardsLD();
       
   777 
       
   778     return EFalse;
       
   779     }
       
   780 
       
   781 // --------------------------------------------------------------------------
       
   782 // CPbk2SendContactCmd::AnyThumbnailsL
       
   783 // --------------------------------------------------------------------------
       
   784 //
       
   785 TBool CPbk2SendContactCmd::AnyThumbnailsL() const
       
   786     {
       
   787     TInt cntCount(iStoreContacts.Count());
       
   788 
       
   789     for (TInt i=0; i < cntCount; ++i)
       
   790         {
       
   791         MVPbkStoreContact* contact = (iStoreContacts)[i];
       
   792         const MVPbkBaseContactField* field =
       
   793             Pbk2SendCmdUtils::FindFieldL(
       
   794                 *contact,
       
   795                 R_THUMBNAIL_FIELD_TYPE,
       
   796                 iAppServices->ContactManager().FieldTypes());
       
   797 
       
   798         if (field)
       
   799             {
       
   800             // We can exit the loop as soon as a thumbnail
       
   801             // is found
       
   802             return ETrue;
       
   803             }
       
   804         }
       
   805     return EFalse;
       
   806     }
       
   807 
       
   808 #if 0
       
   809 // --------------------------------------------------------------------------
       
   810 // CPbk2SendContactCmd::SelectionListL
       
   811 // --------------------------------------------------------------------------
       
   812 //
       
   813 TInt CPbk2SendContactCmd::SelectionListL() const
       
   814     {
       
   815     TInt ret( KNoMenu );
       
   816     TBool supportsFieldType( ETrue );
       
   817     TBool nameOrPropertyField( EFalse );
       
   818 
       
   819     // Check is the sending media SMS and does the contact
       
   820     // have a thumbnail
       
   821     TBool smsAndThumbnail( EFalse );
       
   822     if ( ( iMtmUid == KSenduiMtmSmsUid ) && AnyThumbnailsL() )
       
   823         {
       
   824         smsAndThumbnail = ETrue;
       
   825         }
       
   826 
       
   827     // If focused field is supplied, the command object was
       
   828     // launched from contact info view and that requires
       
   829     // we have to check is the field supported by vCard spec
       
   830     if ( iFocusedField )
       
   831         {
       
   832         if ( iAppServices && ( !iVCardEngine->SupportsFieldType(
       
   833                 *Pbk2SendCmdUtils::FieldType(
       
   834                     *iFocusedField,
       
   835                         iAppServices->ContactManager().FieldTypes() ) ) ) )
       
   836             {
       
   837             supportsFieldType = EFalse;
       
   838             }
       
   839         }
       
   840 
       
   841     // Now check the cases when the menu needs to be shown
       
   842     // There are two main branches depending on which view
       
   843     // this command object was launched from
       
   844     if ( iFocusedField )
       
   845         {
       
   846         // Command object was launched from contact info view.
       
   847 
       
   848         if ( !smsAndThumbnail )
       
   849             {
       
   850             // When there is no thumbnail involved the selection
       
   851             // menu is shown only if we are over vCard supported
       
   852             // field and the focus is not in the name or property field.
       
   853             nameOrPropertyField = IsNameOrPropertyField( *iFocusedField );
       
   854             if ( supportsFieldType && !nameOrPropertyField )
       
   855                 {
       
   856                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS;
       
   857                 }
       
   858             }
       
   859         else
       
   860             {
       
   861             // Thumbnail is involved, the selection menu depends
       
   862             // on whether we are over vCard supported field or not
       
   863             if ( supportsFieldType )
       
   864                 {
       
   865                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL;
       
   866                 }
       
   867             else
       
   868                 {
       
   869                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL_NO_FIELD;
       
   870                 }
       
   871             }
       
   872         }
       
   873     else
       
   874         {
       
   875         // Command object was launched from contact list view,
       
   876         // the menu is shown only in case there is thumbnail
       
   877         // involded and the sending media is SMS
       
   878         if ( smsAndThumbnail )
       
   879             {
       
   880             ret = R_PHONEBOOK2_SEND_OPTIONS;
       
   881             }
       
   882         }
       
   883 
       
   884     return ret;
       
   885     }
       
   886 #endif
       
   887 
       
   888 #if 1
       
   889 // --------------------------------------------------------------------------
       
   890 // CPbk2SendContactCmd::SelectionListL
       
   891 // --------------------------------------------------------------------------
       
   892 //
       
   893 TInt CPbk2SendContactCmd::SelectionListL() const
       
   894     {
       
   895     TInt ret( KNoMenu );
       
   896 
       
   897     // Show the query if contact has a thumbnail.
       
   898     if ( AnyThumbnailsL() )
       
   899         {
       
   900         ret = R_PHONEBOOK2_SEND_OPTIONS;
       
   901         }
       
   902 
       
   903     return ret;
       
   904     }
       
   905 #endif
       
   906 
       
   907 // --------------------------------------------------------------------------
       
   908 // CPbk2SendContactCmd::MapSelection
       
   909 // --------------------------------------------------------------------------
       
   910 //
       
   911 void CPbk2SendContactCmd::MapSelection(TInt& aSelection, TInt aShownMenu)
       
   912     {
       
   913     for (TInt i = 0; SelectionMapping[i].iResId != ESelectionLast; ++i)
       
   914         {
       
   915         if (SelectionMapping[i].iResId == aShownMenu)
       
   916             {
       
   917             TInt selection(KErrNotFound);
       
   918             switch(aSelection)
       
   919                 {
       
   920                 case 0:
       
   921                     {
       
   922                     selection = SelectionMapping[i].iStSelection;
       
   923                     break;
       
   924                     }
       
   925                 case 1:
       
   926                     {
       
   927                     selection = SelectionMapping[i].iNdSelection;
       
   928                     break;
       
   929                     }
       
   930                 case 2:
       
   931                     {
       
   932                     selection = SelectionMapping[i].iRdSelection;
       
   933                     break;
       
   934                     }
       
   935                 default:
       
   936                     {
       
   937                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   938                     }
       
   939                 }
       
   940 
       
   941             if (selection == ECancel)
       
   942                 {
       
   943                 __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   944                 }
       
   945 
       
   946             aSelection = selection;
       
   947             return;
       
   948             }
       
   949         }
       
   950     }
       
   951 
       
   952 // --------------------------------------------------------------------------
       
   953 // CPbk2SendContactCmd::SelectSentDataL
       
   954 // --------------------------------------------------------------------------
       
   955 //
       
   956 TInt CPbk2SendContactCmd::SelectSentDataL()
       
   957     {
       
   958     TInt selectionIndex(ESendAllData);
       
   959 
       
   960     // Get the resource id of the menu to be shown
       
   961     TInt resourceId = SelectionListL();
       
   962 
       
   963     if (resourceId)
       
   964         {
       
   965         // Create a list box
       
   966         CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>
       
   967             (EikControlFactory::CreateByTypeL
       
   968             (EAknCtSinglePopupMenuListBox).iControl);
       
   969         CleanupStack::PushL(listBox);
       
   970 
       
   971         // Create a popup list
       
   972         CAknPopupList* popupList = CAknPopupList::NewL
       
   973             (listBox, R_AVKON_SOFTKEYS_OK_CANCEL__OK,
       
   974             AknPopupLayouts::EMenuGraphicWindow);
       
   975         CleanupStack::PushL(popupList);
       
   976 
       
   977         HBufC* headingText= CCoeEnv::Static()->AllocReadResourceLC
       
   978             (R_PBK2_BUSINESSCARD_SEND_HEADING);
       
   979         popupList->SetTitleL(*headingText);
       
   980         CleanupStack::PopAndDestroy(); // headingText
       
   981 
       
   982         // Init list box
       
   983         listBox->SetContainerWindowL(*popupList);
       
   984 
       
   985         TResourceReader resReader;
       
   986         CCoeEnv::Static()->CreateResourceReaderLC(resReader, resourceId);
       
   987         listBox->ConstructFromResourceL(resReader);
       
   988         CleanupStack::PopAndDestroy();  // resReader
       
   989 
       
   990         listBox->CreateScrollBarFrameL(ETrue);
       
   991         listBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   992             (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   993 
       
   994         CleanupStack::Pop(); // popupList
       
   995 
       
   996         // Show popuplist dialog
       
   997         TInt res = popupList->ExecuteLD();
       
   998         if (res)
       
   999             {
       
  1000             selectionIndex = listBox->CurrentItemIndex();
       
  1001 
       
  1002             // We have to remap the selection index since
       
  1003             // several different listbox configurations
       
  1004             MapSelection(selectionIndex, resourceId);
       
  1005             }
       
  1006         else
       
  1007             {
       
  1008             selectionIndex = ECancel;
       
  1009             }
       
  1010         CleanupStack::PopAndDestroy(); // listBox
       
  1011         }
       
  1012 
       
  1013     return selectionIndex;
       
  1014     }
       
  1015 
       
  1016 // --------------------------------------------------------------------------
       
  1017 // CPbk2SendContactCmd::ShowSendQueryL
       
  1018 // --------------------------------------------------------------------------
       
  1019 //
       
  1020 TUid CPbk2SendContactCmd::ShowSendQueryL()
       
  1021     {
       
  1022     /// Sending  params
       
  1023     TPbk2SendingParams params = CreateParamsLC();
       
  1024 
       
  1025     TUid uid = iSendUi->ShowSendQueryL( NULL, params.iCapabilities, params.iMtmFilter );
       
  1026 
       
  1027     CleanupStack::PopAndDestroy(); // mtmfilter
       
  1028     return uid;
       
  1029     }
       
  1030 
       
  1031 // --------------------------------------------------------------------------
       
  1032 // CPbk2SendContactCmd::ProcessDone
       
  1033 // --------------------------------------------------------------------------
       
  1034 //
       
  1035 void CPbk2SendContactCmd::ProcessDone(TInt aCancelCode)
       
  1036     {
       
  1037     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1038         ("CPbk2SendContactCmd::ProcessDone (%d)"), aCancelCode);
       
  1039     if ( aCancelCode != KErrCancel && iUiControl )
       
  1040         {
       
  1041         // Ignore possible errors in clearing find box contents in release
       
  1042         // builds; just assert in debug builds. Showing an error here might
       
  1043         // signal to the user that there was some problem in the send contact
       
  1044         // command completion.
       
  1045         TInt err( KErrNone );
       
  1046         TRAP( err, iUiControl->ResetFindL() );
       
  1047         __ASSERT_DEBUG( err == KErrNone, Panic( EResetFindResult ) );
       
  1048 
       
  1049         iUiControl->UpdateAfterCommandExecution();
       
  1050         }
       
  1051 
       
  1052     if ( iCommandObserver )
       
  1053         {
       
  1054         // Notify command owner that the command has finished
       
  1055         iCommandObserver->CommandFinished(*this);
       
  1056         }
       
  1057     }
       
  1058 
       
  1059 // --------------------------------------------------------------------------
       
  1060 // CPbk2SendContactCmd::ProcessDismissed
       
  1061 // --------------------------------------------------------------------------
       
  1062 //
       
  1063 void CPbk2SendContactCmd::ProcessDismissed( TInt aCancelCode )
       
  1064     {
       
  1065     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1066         ("CPbk2SendContactCmd::ProcessDismissed (%d)"), aCancelCode);
       
  1067     if (aCancelCode == EAknSoftkeyCancel)
       
  1068         {
       
  1069         ProcessDone( KErrCancel );
       
  1070         }
       
  1071     else if ( iState == EStopping )
       
  1072         {
       
  1073         IssueStopRequest();
       
  1074         }
       
  1075     else
       
  1076         {
       
  1077         // Cancel first any outstanding requests
       
  1078         iVCardSender->Cancel();
       
  1079         iVCardSender->Start( TCallBack( &CPbk2SendContactCmd::SendvCardsLD,
       
  1080             this ) );
       
  1081         }
       
  1082     }
       
  1083 
       
  1084 // --------------------------------------------------------------------------
       
  1085 // CPbk2SendContactCmd::CreateParamsLC
       
  1086 // --------------------------------------------------------------------------
       
  1087 //
       
  1088 TPbk2SendingParams CPbk2SendContactCmd::CreateParamsLC()
       
  1089     {
       
  1090     // Construct the MTM filter
       
  1091     CArrayFixFlat<TUid>* mtmFilter =
       
  1092         new(ELeave) CArrayFixFlat<TUid>(KGranularity);
       
  1093     CleanupStack::PushL(mtmFilter);
       
  1094 
       
  1095     mtmFilter->AppendL(KSenduiMtmPostcardUid);    // hide postcard
       
  1096     mtmFilter->AppendL( KSenduiMtmAudioMessageUid ); // hide audio message
       
  1097     mtmFilter->AppendL( KMmsDirectUpload ); // hide upload
       
  1098 
       
  1099     // Check must we disable SMS menuitem
       
  1100     if ( iSendUi->CanSendBioMessage( KMsgBioUidVCard ) )
       
  1101         {
       
  1102         mtmFilter->AppendL(KSenduiMtmSmsUid);   // hide SMS
       
  1103         }
       
  1104 
       
  1105     // If there are items more than one, hide items
       
  1106     if ( IsMoreThanOneContact() )
       
  1107         {
       
  1108         mtmFilter->AppendL(KSenduiMtmSmsUid);   // hide SMS
       
  1109         }
       
  1110     else if (!FeatureManager::FeatureSupported(KFeatureIdMMS))
       
  1111         {
       
  1112         // Hide MMS if not supported
       
  1113         mtmFilter->AppendL(KSenduiMtmMmsUid);
       
  1114         }
       
  1115 
       
  1116     // Hide Email if not supported
       
  1117     if (!FeatureManager::FeatureSupported(KFeatureIdEmailUi))
       
  1118         {
       
  1119         mtmFilter->AppendL(KSenduiMtmSmtpUid);
       
  1120         mtmFilter->AppendL(KSenduiMtmImap4Uid);
       
  1121         mtmFilter->AppendL(KSenduiMtmPop3Uid);
       
  1122         mtmFilter->AppendL(KSenduiMtmSyncMLEmailUid);
       
  1123         }
       
  1124 
       
  1125     TSendingCapabilities capabilities = TSendingCapabilities();
       
  1126     capabilities.iFlags = TSendingCapabilities::ESupportsBioSending;
       
  1127     capabilities.iFlags |= TSendingCapabilities::ESupportsAttachments;
       
  1128     return TPbk2SendingParams( mtmFilter, capabilities );
       
  1129     }
       
  1130 
       
  1131 // --------------------------------------------------------------------------
       
  1132 // CPbk2SendContactCmd::ConvertContactL
       
  1133 // --------------------------------------------------------------------------
       
  1134 //
       
  1135 void CPbk2SendContactCmd::ConvertContactL(TInt aSelectionIndex)
       
  1136     {
       
  1137     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1138         ("CPbk2SendContactCmd::ConvertContactL(0x%x)"), this);
       
  1139 
       
  1140     delete iDecorator;
       
  1141     iDecorator = NULL;
       
  1142 
       
  1143     if (aSelectionIndex != ECancel)
       
  1144         {
       
  1145         // Start wait note if user continues. If it cancels then don't
       
  1146         // create decorator because it causes a panic in CActive destructor
       
  1147         // of this instance.
       
  1148         iDecorator = Pbk2ProcessDecoratorFactory::CreateWaitNoteDecoratorL(
       
  1149                 R_QTN_SM_WAIT_BUSINESS_CARD, ETrue );
       
  1150         iDecorator->SetObserver( *this );
       
  1151         // wait note doesn't care about amount
       
  1152         iDecorator->ProcessStartedL( 0 );
       
  1153 
       
  1154         if ( iFocusedField )
       
  1155             {
       
  1156             iConverter->ConvertContactL(
       
  1157                 iStoreContacts.Array(), iFocusedField,
       
  1158                 aSelectionIndex, *this);
       
  1159             }
       
  1160         else if ( iCntIterator )
       
  1161             {
       
  1162             iConverter->ConvertContactsL(
       
  1163                 *iCntIterator, aSelectionIndex, *this );
       
  1164             }
       
  1165         else
       
  1166             {
       
  1167             // iContacts validity is checked in function entry
       
  1168             iConverter->ConvertContactsL(
       
  1169                 iStoreContacts.Array(), aSelectionIndex, *this);
       
  1170             }
       
  1171         }
       
  1172     else
       
  1173         {
       
  1174         IssueStopRequest();
       
  1175         }
       
  1176 
       
  1177     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1178         ("CPbk2SendContactCmd::ConvertContactL(0x%x), end"), this);
       
  1179     }
       
  1180 
       
  1181 // --------------------------------------------------------------------------
       
  1182 // CPbk2SendContactCmd::RetrieveContactL
       
  1183 // --------------------------------------------------------------------------
       
  1184 //
       
  1185 void CPbk2SendContactCmd::RetrieveContactL(const MVPbkContactLink& aLink)
       
  1186     {
       
  1187     iRetrieveOperation = iAppServices->ContactManager().
       
  1188             RetrieveContactL(aLink, *this);
       
  1189     }
       
  1190 
       
  1191 // --------------------------------------------------------------------------
       
  1192 // CPbk2SendContactCmd::FilterErrors
       
  1193 // --------------------------------------------------------------------------
       
  1194 //
       
  1195 TInt CPbk2SendContactCmd::FilterErrors(TInt aErrorCode)
       
  1196     {
       
  1197     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1198         ("CPbk2SendContactCmd::FilterErrors(%d) start"), aErrorCode);
       
  1199 
       
  1200     TInt result = aErrorCode;
       
  1201     switch (aErrorCode)
       
  1202         {
       
  1203         case KErrNotFound:  // FALLTHROUGH
       
  1204         case KErrInUse:     // FALLTHROUGH
       
  1205             {
       
  1206             // Ignore these errors
       
  1207             // KErrNotFound means that somebody got the contact first
       
  1208             // KErrInUse means that the contact is open
       
  1209             result = KErrNone;
       
  1210             break;
       
  1211             }
       
  1212 
       
  1213         default:  // Something more serious happened -> give up
       
  1214             {
       
  1215             Cancel();
       
  1216             ProcessDone(aErrorCode);
       
  1217             break;
       
  1218             }
       
  1219         }
       
  1220 
       
  1221     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1222         ("CPbk2SendContactCmd::FilterErrors(%d) end"), result);
       
  1223 
       
  1224     return result;
       
  1225     }
       
  1226 
       
  1227 // --------------------------------------------------------------------------
       
  1228 // CPbk2SendContactCmd::IssueRequest
       
  1229 // --------------------------------------------------------------------------
       
  1230 //
       
  1231 void CPbk2SendContactCmd::IssueRequest()
       
  1232     {
       
  1233     TRequestStatus* status = &iStatus;
       
  1234     User::RequestComplete(status, KErrNone);
       
  1235     SetActive();
       
  1236     }
       
  1237 
       
  1238 // --------------------------------------------------------------------------
       
  1239 // CPbk2SendContactCmd::IssueStopRequest
       
  1240 // --------------------------------------------------------------------------
       
  1241 //
       
  1242 void CPbk2SendContactCmd::IssueStopRequest()
       
  1243     {
       
  1244     iState = EStopping;
       
  1245     if (!IsActive())
       
  1246         {
       
  1247         IssueRequest();
       
  1248         }
       
  1249     }
       
  1250 
       
  1251 // --------------------------------------------------------------------------
       
  1252 // CPbk2SendContactCmd::SendMsgUsingSendUI
       
  1253 // --------------------------------------------------------------------------
       
  1254 //
       
  1255 void CPbk2SendContactCmd::SendMsgUsingSendUI(CMessageData* aMsgData)
       
  1256     {
       
  1257     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1258         ("CPbk2SendContactCmd::SendMsgUsingSendUI(0x%x), start"), this);
       
  1259 
       
  1260     // Send the message using Send Ui
       
  1261     TRAPD(error, iSendUi->CreateAndSendMessageL( iMtmUid, aMsgData, KMsgBioUidVCard));
       
  1262 
       
  1263     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1264         ("CPbk2SendContactCmd::SendMsgUsingSendUI(%d), error"), error);
       
  1265 
       
  1266     if (error != KErrNone)
       
  1267         {
       
  1268         FilterErrors(error);
       
  1269         }
       
  1270     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1271         ("CPbk2SendContactCmd::SendMsgUsingSendUI(0x%x), end"), this);
       
  1272     }
       
  1273 
       
  1274 // --------------------------------------------------------------------------
       
  1275 // CPbk2SendContactCmd::IsMoreThanOneContact
       
  1276 // --------------------------------------------------------------------------
       
  1277 //
       
  1278 TBool CPbk2SendContactCmd::IsMoreThanOneContact()
       
  1279     {
       
  1280     TBool result = EFalse;
       
  1281     if ( iCntIterator )
       
  1282         {
       
  1283         result = ETrue;
       
  1284         }
       
  1285     return result;
       
  1286     }
       
  1287 
       
  1288 // --------------------------------------------------------------------------
       
  1289 // CPbk2SendContactCmd::CommandExtension
       
  1290 // --------------------------------------------------------------------------
       
  1291 //
       
  1292 TAny* CPbk2SendContactCmd::CommandExtension(TUid aExtensionUid )
       
  1293     {
       
  1294      if( aExtensionUid == TUid::Uid(MPbk2ResourceReleaseUID) )
       
  1295         {
       
  1296         return static_cast<MPbk2ResourceRelease *>(this);
       
  1297         }
       
  1298      else
       
  1299         {
       
  1300         return NULL;
       
  1301         }
       
  1302     }
       
  1303 
       
  1304 // --------------------------------------------------------------------------
       
  1305 // CPbk2SendContactCmd::ReleaseResource
       
  1306 // --------------------------------------------------------------------------
       
  1307 //
       
  1308 void CPbk2SendContactCmd::ReleaseResource()
       
  1309     {
       
  1310     Cancel();
       
  1311     if (iConverter)
       
  1312         {
       
  1313         iConverter->Cancel();
       
  1314         CPbk2AttachmentFileArray& fileArray = iConverter->AttachmentFileArray();        
       
  1315         if (fileArray.Count() > 0)
       
  1316             {
       
  1317             if ( !iWaiter )
       
  1318                 {
       
  1319                 TInt err( KErrNone );
       
  1320                 TRAP( err,iWaiter = new (ELeave) CActiveSchedulerWait());
       
  1321                 if ( err != KErrNone )
       
  1322                     {
       
  1323                     fileArray.ResetAndDestroy();
       
  1324                     return;
       
  1325                     }
       
  1326                  }
       
  1327             
       
  1328               iState = EReleaseResource;
       
  1329               IssueRequest();         
       
  1330               iWaiter->Start();
       
  1331             }
       
  1332        }
       
  1333     }
       
  1334 
       
  1335 // End of File