phonebookui/Phonebook2/CommandsExtension/src/CPbk2SendContactCmd.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 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 iSelectedContacts;
       
   373     delete iConverter;
       
   374     delete iVCardSender;
       
   375     delete iVCardEngine;
       
   376     iStoreContacts.ResetAndDestroy();
       
   377     iStoreContacts.Close();
       
   378     delete iRetrieveOperation;
       
   379     delete iDecorator;
       
   380     delete iCntIterator;
       
   381     delete iSendUi;
       
   382     Release( iAppServices );
       
   383     }
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CPbk2SendContactCmd::NewL
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 CPbk2SendContactCmd* CPbk2SendContactCmd::NewL
       
   390     (MPbk2ContactUiControl& aUiControl)
       
   391     {
       
   392     CPbk2SendContactCmd* self = new (ELeave)CPbk2SendContactCmd(aUiControl);
       
   393     CleanupStack::PushL(self);
       
   394     self->ConstructL();
       
   395     CleanupStack::Pop(self);
       
   396     return self;
       
   397     }
       
   398 
       
   399 // --------------------------------------------------------------------------
       
   400 // CPbk2SendContactCmd::ConstructL
       
   401 // --------------------------------------------------------------------------
       
   402 //
       
   403 void CPbk2SendContactCmd::ConstructL()
       
   404     {
       
   405     PBK2_DEBUG_PRINT
       
   406         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ConstructL(0x%x)"), this);
       
   407     CActiveScheduler::Add(this);
       
   408     CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL
       
   409         ( CCoeEnv::Static()->FsSession() );
       
   410     CleanupStack::PushL( driveSpaceCheck );
       
   411     // check FFS situation
       
   412     driveSpaceCheck->DriveSpaceCheckL();
       
   413     CleanupStack::PopAndDestroy( driveSpaceCheck );
       
   414     iEikEnv = CEikonEnv::Static();
       
   415     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   416     iVCardEngine = CVPbkVCardEng::NewL( iAppServices->ContactManager() );
       
   417     iConverter = CPbk2vCardConverter::NewL(
       
   418         iEikEnv->FsSession(),
       
   419         iAppServices->ContactManager(),
       
   420         *iVCardEngine,
       
   421         iAppServices->NameFormatter() );
       
   422     iVCardSender = CVCardSender::NewL(CActive::EPriorityIdle);
       
   423     iSendUi = CSendUi::NewL();
       
   424 
       
   425     if( iUiControl )
       
   426         {
       
   427         // Use iterator to make sure that OOM situation does not occur
       
   428         // if multiple contacts selected.
       
   429         iCntIterator = iUiControl->SelectedContactsIteratorL();
       
   430         if ( !iCntIterator )
       
   431             {
       
   432             // If no iterator, there is no selected contacts.
       
   433             // Only one contact is returned.
       
   434             iSelectedContacts = iUiControl->SelectedContactsOrFocusedContactL();
       
   435             }
       
   436         iFocusedField = iUiControl->FocusedField();
       
   437         iUiControl->RegisterCommand( this );
       
   438         }
       
   439     PBK2_DEBUG_PRINT
       
   440         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ConstructL, end"));
       
   441     }
       
   442 
       
   443 // --------------------------------------------------------------------------
       
   444 // CPbk2SendContactCmd::ExecuteLD
       
   445 // --------------------------------------------------------------------------
       
   446 //
       
   447 void CPbk2SendContactCmd::ExecuteLD()
       
   448     {
       
   449     PBK2_DEBUG_PRINT
       
   450         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ExecuteLD(0x%x)"), this);
       
   451 
       
   452     CleanupStack::PushL(this);
       
   453 
       
   454     iCurrentContactLinkIndex = 0;
       
   455     iState = EShowingSendQuery;
       
   456     IssueRequest();
       
   457 
       
   458     CleanupStack::Pop(this);
       
   459     PBK2_DEBUG_PRINT
       
   460         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::ExecuteLD, end"), this);
       
   461     }
       
   462 
       
   463 // --------------------------------------------------------------------------
       
   464 // CPbk2SendContactCmd::AddObserver
       
   465 // --------------------------------------------------------------------------
       
   466 //
       
   467 void CPbk2SendContactCmd::AddObserver(MPbk2CommandObserver& aObserver)
       
   468     {
       
   469     iCommandObserver = &aObserver;
       
   470     }
       
   471 
       
   472 // --------------------------------------------------------------------------
       
   473 // CPbk2SendContactCmd::ResetUiControl
       
   474 // --------------------------------------------------------------------------
       
   475 //
       
   476 void CPbk2SendContactCmd::ResetUiControl(
       
   477         MPbk2ContactUiControl& aUiControl)
       
   478     {
       
   479     if (iUiControl == & aUiControl)
       
   480         {
       
   481         iUiControl = NULL;
       
   482         }
       
   483     }
       
   484 
       
   485 // --------------------------------------------------------------------------
       
   486 // CPbk2SendContactCmd::RunL
       
   487 // --------------------------------------------------------------------------
       
   488 //
       
   489 void CPbk2SendContactCmd::RunL()
       
   490     {
       
   491     switch (iState)
       
   492         {
       
   493         case EShowingSendQuery:
       
   494             {
       
   495             iMtmUid = ShowSendQueryL();
       
   496             if (iMtmUid == KNullUid)
       
   497                 {
       
   498                 iState = ECancelling;
       
   499                 }
       
   500             else
       
   501                 {
       
   502                 iState = ERetrievingContact;
       
   503                 }
       
   504             IssueRequest();
       
   505             break;
       
   506             }
       
   507 
       
   508         case ERetrievingContact:
       
   509             {
       
   510             if ( iSelectedContacts )
       
   511                 {
       
   512                 __ASSERT_DEBUG( iSelectedContacts->Count() >
       
   513                         iCurrentContactLinkIndex, Panic( ERunL_OOB ) );
       
   514                 RetrieveContactL(iSelectedContacts->At
       
   515                     (iCurrentContactLinkIndex));
       
   516                 }
       
   517             else
       
   518                 {
       
   519                 iState = ESelectingSentData;
       
   520                 IssueRequest();
       
   521                 }
       
   522             break;
       
   523             }
       
   524 
       
   525         case ESelectingSentData:
       
   526             {
       
   527             TInt selection(ESendAllData);
       
   528             if ( iSelectedContacts )
       
   529                 {
       
   530                 // If there is only one contact or launched in info view
       
   531                 // do the data selection
       
   532                 selection = SelectSentDataL();
       
   533                 }
       
   534             ConvertContactL(selection);
       
   535             break;
       
   536             }
       
   537 
       
   538         case EStopping:
       
   539             {
       
   540             ProcessDone(KErrNone);
       
   541             break;
       
   542             }
       
   543 
       
   544         case ECancelling:
       
   545             {
       
   546             ProcessDone( KErrCancel );
       
   547             break;
       
   548             }
       
   549         }
       
   550     }
       
   551 
       
   552 // --------------------------------------------------------------------------
       
   553 // CPbk2SendContactCmd::RunError
       
   554 // --------------------------------------------------------------------------
       
   555 //
       
   556 TInt CPbk2SendContactCmd::RunError(TInt aError)
       
   557     {
       
   558     return FilterErrors(aError);
       
   559     }
       
   560 
       
   561 // --------------------------------------------------------------------------
       
   562 // CPbk2SendContactCmd::DoCancel
       
   563 // --------------------------------------------------------------------------
       
   564 //
       
   565 void CPbk2SendContactCmd::DoCancel()
       
   566     {
       
   567     delete iRetrieveOperation;
       
   568     iRetrieveOperation = NULL;
       
   569     }
       
   570 
       
   571 // --------------------------------------------------------------------------
       
   572 // CPbk2SendContactCmd::ConversionDone
       
   573 // --------------------------------------------------------------------------
       
   574 //
       
   575 void CPbk2SendContactCmd::ConversionDone( TInt PBK2_DEBUG_ONLY( aCount ) )
       
   576     {
       
   577     PBK2_DEBUG_PRINT
       
   578         ( PBK2_DEBUG_STRING( "CPbk2SendContactCmd::ConversionDone(0x%x)" ),
       
   579         this );
       
   580 
       
   581     __ASSERT_DEBUG( iStoreContacts.Count() == aCount,
       
   582         Panic( EPanicLogic_ConversionDone ) );
       
   583 
       
   584     // Decorator will call processdismissed which will continue
       
   585     // contact send
       
   586     iDecorator->ProcessStopped();
       
   587 
       
   588     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   589         ( "CPbk2SendContactCmd::ConversionDone(0x%x), end" ), this );
       
   590 
       
   591     }
       
   592 
       
   593 // --------------------------------------------------------------------------
       
   594 // CPbk2SendContactCmd::ConversionError
       
   595 // --------------------------------------------------------------------------
       
   596 //
       
   597 void CPbk2SendContactCmd::ConversionError(TInt aError)
       
   598     {
       
   599     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   600         ("CPbk2SendContactCmd::ConversionError(%d)"), aError);
       
   601 
       
   602     // Report the failure to the user
       
   603     CCoeEnv::Static()->HandleError( aError );
       
   604 
       
   605     // iDecorator calls processdismissed
       
   606     iDecorator->ProcessStopped();
       
   607     iState = EStopping;
       
   608 
       
   609     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   610         ("CPbk2SendContactCmd::ConversionError(0x%x), end"), this);
       
   611     }
       
   612 
       
   613 // --------------------------------------------------------------------------
       
   614 // CPbk2SendContactCmd::VPbkSingleContactOperationComplete
       
   615 // --------------------------------------------------------------------------
       
   616 //
       
   617 void CPbk2SendContactCmd::VPbkSingleContactOperationComplete(
       
   618     MVPbkContactOperationBase& aOperation, MVPbkStoreContact* aContact)
       
   619     {
       
   620     if (&aOperation == iRetrieveOperation)
       
   621         {
       
   622         delete iRetrieveOperation;
       
   623         iRetrieveOperation = NULL;
       
   624 
       
   625         // We now have a store contact
       
   626         TInt error = iStoreContacts.Append(aContact);
       
   627         if ( error == KErrNone )
       
   628             {
       
   629             ++iCurrentContactLinkIndex;
       
   630             if (iSelectedContacts->Count() == iCurrentContactLinkIndex)
       
   631                 {
       
   632                 iCurrentContactLinkIndex = 0;
       
   633                 iState = ESelectingSentData;
       
   634                 }
       
   635             else
       
   636                 {
       
   637                 iState = ERetrievingContact;
       
   638                 }
       
   639 
       
   640             IssueRequest();
       
   641             }
       
   642         else
       
   643             {
       
   644             ProcessDone( error );
       
   645             }
       
   646         }
       
   647     else
       
   648         {
       
   649         IssueStopRequest();
       
   650         }
       
   651     }
       
   652 
       
   653 // --------------------------------------------------------------------------
       
   654 // CPbk2SendContactCmd::VPbkSingleContactOperationFailed
       
   655 // --------------------------------------------------------------------------
       
   656 //
       
   657 void CPbk2SendContactCmd::VPbkSingleContactOperationFailed(
       
   658         MVPbkContactOperationBase& aOperation, TInt aError)
       
   659     {
       
   660     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   661       ("CPbk2SendContactCmd::VPbkSingleContactOperationFailed (%d)"), aError);
       
   662     if (&aOperation == iRetrieveOperation)
       
   663         {
       
   664         delete iRetrieveOperation;
       
   665         iRetrieveOperation = NULL;
       
   666 
       
   667         // We cannot get the contact, so we have to
       
   668         // fail. We cannot continue, since this operation
       
   669         // was executed only in case of one contact.
       
   670         ProcessDone(aError);
       
   671         }
       
   672     }
       
   673 
       
   674 // --------------------------------------------------------------------------
       
   675 // CPbk2SendContactCmd::SendvCardsLD
       
   676 // --------------------------------------------------------------------------
       
   677 //
       
   678 void CPbk2SendContactCmd::SendvCardsLD()
       
   679     {
       
   680     PBK2_DEBUG_PRINT
       
   681         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::SendvCardsLD(0x%x)"), this);
       
   682     // Relinquish ownership, iVCardSender takes care of it self
       
   683     iVCardSender = NULL;
       
   684 
       
   685     CMessageData* messageData = CMessageData::NewL();
       
   686     CleanupStack::PushL( messageData );
       
   687 
       
   688     if (iConverter->FileNames().MdcaCount() > 0 &&
       
   689         !iUnderDestruction)
       
   690         {
       
   691         TSendingCapabilities caps;
       
   692         User::LeaveIfError(
       
   693                 iSendUi->ServiceCapabilitiesL( iMtmUid, caps ) );
       
   694         if (caps.iFlags & TSendingCapabilities::ESupportsAttachments)
       
   695             {
       
   696             // Not sending through SMS, just pass the attachments
       
   697             __ASSERT_DEBUG(iConverter->FileNames().MdcaCount()>=1,
       
   698                 Panic(EPanicPreCond_SendvCardsL));
       
   699 
       
   700             //Fill message data
       
   701             const TInt count( iConverter->FileNames().MdcaCount());
       
   702             for( TInt i( 0 ); i < count; ++i )
       
   703                 {
       
   704                 messageData->AppendAttachmentHandleL(
       
   705                         iConverter->AttachmentFileArray().FileHandleAt( i ) );
       
   706                 }
       
   707             SendMsgUsingSendUI(messageData);
       
   708             }
       
   709         else if (caps.iFlags & TSendingCapabilities::ESupportsBodyText)
       
   710             {
       
   711             PBK2_DEBUG_PRINT
       
   712                 (PBK2_DEBUG_STRING("SendvCardsLD, KSenduiMtmSmsUid"));
       
   713             // Sending through SMS -> there should be only one vCard
       
   714             // attachment. Package the attachment to a rich text object and
       
   715             // send it as the message body.
       
   716             __ASSERT_DEBUG(iConverter->FileNames().MdcaCount()==1,
       
   717                 Panic(EPanicPreCond_SendvCardsL));
       
   718 
       
   719             // Copy the one and only attachment into a rich text object
       
   720             CRichText* msgBody = CreateRichTextFromFileLC
       
   721                 (*iEikEnv, iConverter->FileNames().MdcaPoint(0));
       
   722 
       
   723             messageData->SetBodyTextL( msgBody );
       
   724             SendMsgUsingSendUI(messageData);
       
   725 
       
   726             CleanupStack::PopAndDestroy(msgBody);
       
   727             }
       
   728         else
       
   729             {
       
   730             User::Leave( KErrNotSupported );
       
   731             }
       
   732         }
       
   733 
       
   734     CleanupStack::PopAndDestroy(); //messageData
       
   735 
       
   736     ProcessDone(KErrNone);
       
   737         PBK2_DEBUG_PRINT
       
   738         (PBK2_DEBUG_STRING("CPbk2SendContactCmd::SendvCardsLD, end"), this);
       
   739     }
       
   740 
       
   741 // --------------------------------------------------------------------------
       
   742 // CPbk2SendContactCmd::SendvCardsLD
       
   743 // --------------------------------------------------------------------------
       
   744 //
       
   745 TInt CPbk2SendContactCmd::SendvCardsLD(TAny* aThis)
       
   746     {
       
   747     __ASSERT_DEBUG( aThis, Panic(EPanicPreCond_ErrArgument) );
       
   748 
       
   749     CPbk2SendContactCmd* self = static_cast<CPbk2SendContactCmd*>(aThis);
       
   750     self->SendvCardsLD();
       
   751 
       
   752     return EFalse;
       
   753     }
       
   754 
       
   755 // --------------------------------------------------------------------------
       
   756 // CPbk2SendContactCmd::AnyThumbnailsL
       
   757 // --------------------------------------------------------------------------
       
   758 //
       
   759 TBool CPbk2SendContactCmd::AnyThumbnailsL() const
       
   760     {
       
   761     TInt cntCount(iStoreContacts.Count());
       
   762 
       
   763     for (TInt i=0; i < cntCount; ++i)
       
   764         {
       
   765         MVPbkStoreContact* contact = (iStoreContacts)[i];
       
   766         const MVPbkBaseContactField* field =
       
   767             Pbk2SendCmdUtils::FindFieldL(
       
   768                 *contact,
       
   769                 R_THUMBNAIL_FIELD_TYPE,
       
   770                 iAppServices->ContactManager().FieldTypes());
       
   771 
       
   772         if (field)
       
   773             {
       
   774             // We can exit the loop as soon as a thumbnail
       
   775             // is found
       
   776             return ETrue;
       
   777             }
       
   778         }
       
   779     return EFalse;
       
   780     }
       
   781 
       
   782 #if 0
       
   783 // --------------------------------------------------------------------------
       
   784 // CPbk2SendContactCmd::SelectionListL
       
   785 // --------------------------------------------------------------------------
       
   786 //
       
   787 TInt CPbk2SendContactCmd::SelectionListL() const
       
   788     {
       
   789     TInt ret( KNoMenu );
       
   790     TBool supportsFieldType( ETrue );
       
   791     TBool nameOrPropertyField( EFalse );
       
   792 
       
   793     // Check is the sending media SMS and does the contact
       
   794     // have a thumbnail
       
   795     TBool smsAndThumbnail( EFalse );
       
   796     if ( ( iMtmUid == KSenduiMtmSmsUid ) && AnyThumbnailsL() )
       
   797         {
       
   798         smsAndThumbnail = ETrue;
       
   799         }
       
   800 
       
   801     // If focused field is supplied, the command object was
       
   802     // launched from contact info view and that requires
       
   803     // we have to check is the field supported by vCard spec
       
   804     if ( iFocusedField )
       
   805         {
       
   806         if ( iAppServices && ( !iVCardEngine->SupportsFieldType(
       
   807                 *Pbk2SendCmdUtils::FieldType(
       
   808                     *iFocusedField,
       
   809                         iAppServices->ContactManager().FieldTypes() ) ) ) )
       
   810             {
       
   811             supportsFieldType = EFalse;
       
   812             }
       
   813         }
       
   814 
       
   815     // Now check the cases when the menu needs to be shown
       
   816     // There are two main branches depending on which view
       
   817     // this command object was launched from
       
   818     if ( iFocusedField )
       
   819         {
       
   820         // Command object was launched from contact info view.
       
   821 
       
   822         if ( !smsAndThumbnail )
       
   823             {
       
   824             // When there is no thumbnail involved the selection
       
   825             // menu is shown only if we are over vCard supported
       
   826             // field and the focus is not in the name or property field.
       
   827             nameOrPropertyField = IsNameOrPropertyField( *iFocusedField );
       
   828             if ( supportsFieldType && !nameOrPropertyField )
       
   829                 {
       
   830                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS;
       
   831                 }
       
   832             }
       
   833         else
       
   834             {
       
   835             // Thumbnail is involved, the selection menu depends
       
   836             // on whether we are over vCard supported field or not
       
   837             if ( supportsFieldType )
       
   838                 {
       
   839                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL;
       
   840                 }
       
   841             else
       
   842                 {
       
   843                 ret = R_PBK2_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL_NO_FIELD;
       
   844                 }
       
   845             }
       
   846         }
       
   847     else
       
   848         {
       
   849         // Command object was launched from contact list view,
       
   850         // the menu is shown only in case there is thumbnail
       
   851         // involded and the sending media is SMS
       
   852         if ( smsAndThumbnail )
       
   853             {
       
   854             ret = R_PHONEBOOK2_SEND_OPTIONS;
       
   855             }
       
   856         }
       
   857 
       
   858     return ret;
       
   859     }
       
   860 #endif
       
   861 
       
   862 #if 1
       
   863 // --------------------------------------------------------------------------
       
   864 // CPbk2SendContactCmd::SelectionListL
       
   865 // --------------------------------------------------------------------------
       
   866 //
       
   867 TInt CPbk2SendContactCmd::SelectionListL() const
       
   868     {
       
   869     TInt ret( KNoMenu );
       
   870 
       
   871     // Show the query if contact has a thumbnail.
       
   872     if ( AnyThumbnailsL() )
       
   873         {
       
   874         ret = R_PHONEBOOK2_SEND_OPTIONS;
       
   875         }
       
   876 
       
   877     return ret;
       
   878     }
       
   879 #endif
       
   880 
       
   881 // --------------------------------------------------------------------------
       
   882 // CPbk2SendContactCmd::MapSelection
       
   883 // --------------------------------------------------------------------------
       
   884 //
       
   885 void CPbk2SendContactCmd::MapSelection(TInt& aSelection, TInt aShownMenu)
       
   886     {
       
   887     for (TInt i = 0; SelectionMapping[i].iResId != ESelectionLast; ++i)
       
   888         {
       
   889         if (SelectionMapping[i].iResId == aShownMenu)
       
   890             {
       
   891             TInt selection(KErrNotFound);
       
   892             switch(aSelection)
       
   893                 {
       
   894                 case 0:
       
   895                     {
       
   896                     selection = SelectionMapping[i].iStSelection;
       
   897                     break;
       
   898                     }
       
   899                 case 1:
       
   900                     {
       
   901                     selection = SelectionMapping[i].iNdSelection;
       
   902                     break;
       
   903                     }
       
   904                 case 2:
       
   905                     {
       
   906                     selection = SelectionMapping[i].iRdSelection;
       
   907                     break;
       
   908                     }
       
   909                 default:
       
   910                     {
       
   911                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   912                     }
       
   913                 }
       
   914 
       
   915             if (selection == ECancel)
       
   916                 {
       
   917                 __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   918                 }
       
   919 
       
   920             aSelection = selection;
       
   921             return;
       
   922             }
       
   923         }
       
   924     }
       
   925 
       
   926 // --------------------------------------------------------------------------
       
   927 // CPbk2SendContactCmd::SelectSentDataL
       
   928 // --------------------------------------------------------------------------
       
   929 //
       
   930 TInt CPbk2SendContactCmd::SelectSentDataL()
       
   931     {
       
   932     TInt selectionIndex(ESendAllData);
       
   933 
       
   934     // Get the resource id of the menu to be shown
       
   935     TInt resourceId = SelectionListL();
       
   936 
       
   937     if (resourceId)
       
   938         {
       
   939         // Create a list box
       
   940         CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>
       
   941             (EikControlFactory::CreateByTypeL
       
   942             (EAknCtSinglePopupMenuListBox).iControl);
       
   943         CleanupStack::PushL(listBox);
       
   944 
       
   945         // Create a popup list
       
   946         CAknPopupList* popupList = CAknPopupList::NewL
       
   947             (listBox, R_AVKON_SOFTKEYS_OK_CANCEL__OK,
       
   948             AknPopupLayouts::EMenuGraphicWindow);
       
   949         CleanupStack::PushL(popupList);
       
   950 
       
   951         HBufC* headingText= CCoeEnv::Static()->AllocReadResourceLC
       
   952             (R_PBK2_BUSINESSCARD_SEND_HEADING);
       
   953         popupList->SetTitleL(*headingText);
       
   954         CleanupStack::PopAndDestroy(); // headingText
       
   955 
       
   956         // Init list box
       
   957         listBox->SetContainerWindowL(*popupList);
       
   958 
       
   959         TResourceReader resReader;
       
   960         CCoeEnv::Static()->CreateResourceReaderLC(resReader, resourceId);
       
   961         listBox->ConstructFromResourceL(resReader);
       
   962         CleanupStack::PopAndDestroy();  // resReader
       
   963 
       
   964         listBox->CreateScrollBarFrameL(ETrue);
       
   965         listBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   966             (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   967 
       
   968         CleanupStack::Pop(); // popupList
       
   969 
       
   970         // Show popuplist dialog
       
   971         TInt res = popupList->ExecuteLD();
       
   972         if (res)
       
   973             {
       
   974             selectionIndex = listBox->CurrentItemIndex();
       
   975 
       
   976             // We have to remap the selection index since
       
   977             // several different listbox configurations
       
   978             MapSelection(selectionIndex, resourceId);
       
   979             }
       
   980         else
       
   981             {
       
   982             selectionIndex = ECancel;
       
   983             }
       
   984         CleanupStack::PopAndDestroy(); // listBox
       
   985         }
       
   986 
       
   987     return selectionIndex;
       
   988     }
       
   989 
       
   990 // --------------------------------------------------------------------------
       
   991 // CPbk2SendContactCmd::ShowSendQueryL
       
   992 // --------------------------------------------------------------------------
       
   993 //
       
   994 TUid CPbk2SendContactCmd::ShowSendQueryL()
       
   995     {
       
   996     /// Sending  params
       
   997     TPbk2SendingParams params = CreateParamsLC();
       
   998 
       
   999     TUid uid = iSendUi->ShowSendQueryL( NULL, params.iCapabilities, params.iMtmFilter );
       
  1000 
       
  1001     CleanupStack::PopAndDestroy(); // mtmfilter
       
  1002     return uid;
       
  1003     }
       
  1004 
       
  1005 // --------------------------------------------------------------------------
       
  1006 // CPbk2SendContactCmd::ProcessDone
       
  1007 // --------------------------------------------------------------------------
       
  1008 //
       
  1009 void CPbk2SendContactCmd::ProcessDone(TInt aCancelCode)
       
  1010     {
       
  1011     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1012         ("CPbk2SendContactCmd::ProcessDone (%d)"), aCancelCode);
       
  1013     if ( aCancelCode != KErrCancel && iUiControl )
       
  1014         {
       
  1015         // Ignore possible errors in clearing find box contents in release
       
  1016         // builds; just assert in debug builds. Showing an error here might
       
  1017         // signal to the user that there was some problem in the send contact
       
  1018         // command completion.
       
  1019         TInt err( KErrNone );
       
  1020         TRAP( err, iUiControl->ResetFindL() );
       
  1021         __ASSERT_DEBUG( err == KErrNone, Panic( EResetFindResult ) );
       
  1022 
       
  1023         iUiControl->UpdateAfterCommandExecution();
       
  1024         }
       
  1025 
       
  1026     if ( iCommandObserver )
       
  1027         {
       
  1028         // Notify command owner that the command has finished
       
  1029         iCommandObserver->CommandFinished(*this);
       
  1030         }
       
  1031     }
       
  1032 
       
  1033 // --------------------------------------------------------------------------
       
  1034 // CPbk2SendContactCmd::ProcessDismissed
       
  1035 // --------------------------------------------------------------------------
       
  1036 //
       
  1037 void CPbk2SendContactCmd::ProcessDismissed( TInt aCancelCode )
       
  1038     {
       
  1039     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1040         ("CPbk2SendContactCmd::ProcessDismissed (%d)"), aCancelCode);
       
  1041     if (aCancelCode == EAknSoftkeyCancel)
       
  1042         {
       
  1043         ProcessDone( KErrCancel );
       
  1044         }
       
  1045     else if ( iState == EStopping )
       
  1046         {
       
  1047         IssueStopRequest();
       
  1048         }
       
  1049     else
       
  1050         {
       
  1051         // Cancel first any outstanding requests
       
  1052         iVCardSender->Cancel();
       
  1053         iVCardSender->Start( TCallBack( &CPbk2SendContactCmd::SendvCardsLD,
       
  1054             this ) );
       
  1055         }
       
  1056     }
       
  1057 
       
  1058 // --------------------------------------------------------------------------
       
  1059 // CPbk2SendContactCmd::CreateParamsLC
       
  1060 // --------------------------------------------------------------------------
       
  1061 //
       
  1062 TPbk2SendingParams CPbk2SendContactCmd::CreateParamsLC()
       
  1063     {
       
  1064     // Construct the MTM filter
       
  1065     CArrayFixFlat<TUid>* mtmFilter =
       
  1066         new(ELeave) CArrayFixFlat<TUid>(KGranularity);
       
  1067     CleanupStack::PushL(mtmFilter);
       
  1068 
       
  1069     mtmFilter->AppendL(KSenduiMtmPostcardUid);    // hide postcard
       
  1070     mtmFilter->AppendL( KSenduiMtmAudioMessageUid ); // hide audio message
       
  1071     mtmFilter->AppendL( KMmsDirectUpload ); // hide upload
       
  1072 
       
  1073     // Check must we disable SMS menuitem
       
  1074     if ( iSendUi->CanSendBioMessage( KMsgBioUidVCard ) )
       
  1075         {
       
  1076         mtmFilter->AppendL(KSenduiMtmSmsUid);   // hide SMS
       
  1077         }
       
  1078 
       
  1079     // If there are items more than one, hide items
       
  1080     if ( IsMoreThanOneContact() )
       
  1081         {
       
  1082         mtmFilter->AppendL(KSenduiMtmSmsUid);   // hide SMS
       
  1083         }
       
  1084     else if (!FeatureManager::FeatureSupported(KFeatureIdMMS))
       
  1085         {
       
  1086         // Hide MMS if not supported
       
  1087         mtmFilter->AppendL(KSenduiMtmMmsUid);
       
  1088         }
       
  1089 
       
  1090     // Hide Email if not supported
       
  1091     if (!FeatureManager::FeatureSupported(KFeatureIdEmailUi))
       
  1092         {
       
  1093         mtmFilter->AppendL(KSenduiMtmSmtpUid);
       
  1094         mtmFilter->AppendL(KSenduiMtmImap4Uid);
       
  1095         mtmFilter->AppendL(KSenduiMtmPop3Uid);
       
  1096         mtmFilter->AppendL(KSenduiMtmSyncMLEmailUid);
       
  1097         }
       
  1098 
       
  1099     TSendingCapabilities capabilities = TSendingCapabilities();
       
  1100     capabilities.iFlags = TSendingCapabilities::ESupportsBioSending;
       
  1101     capabilities.iFlags |= TSendingCapabilities::ESupportsAttachments;
       
  1102     return TPbk2SendingParams( mtmFilter, capabilities );
       
  1103     }
       
  1104 
       
  1105 // --------------------------------------------------------------------------
       
  1106 // CPbk2SendContactCmd::ConvertContactL
       
  1107 // --------------------------------------------------------------------------
       
  1108 //
       
  1109 void CPbk2SendContactCmd::ConvertContactL(TInt aSelectionIndex)
       
  1110     {
       
  1111     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1112         ("CPbk2SendContactCmd::ConvertContactL(0x%x)"), this);
       
  1113 
       
  1114     delete iDecorator;
       
  1115     iDecorator = NULL;
       
  1116 
       
  1117     if (aSelectionIndex != ECancel)
       
  1118         {
       
  1119         // Start wait note if user continues. If it cancels then don't
       
  1120         // create decorator because it causes a panic in CActive destructor
       
  1121         // of this instance.
       
  1122         iDecorator = Pbk2ProcessDecoratorFactory::CreateWaitNoteDecoratorL(
       
  1123                 R_QTN_SM_WAIT_BUSINESS_CARD, ETrue );
       
  1124         iDecorator->SetObserver( *this );
       
  1125         // wait note doesn't care about amount
       
  1126         iDecorator->ProcessStartedL( 0 );
       
  1127 
       
  1128         if ( iFocusedField )
       
  1129             {
       
  1130             iConverter->ConvertContactL(
       
  1131                 iStoreContacts.Array(), iFocusedField,
       
  1132                 aSelectionIndex, *this);
       
  1133             }
       
  1134         else if ( iCntIterator )
       
  1135             {
       
  1136             iConverter->ConvertContactsL(
       
  1137                 *iCntIterator, aSelectionIndex, *this );
       
  1138             }
       
  1139         else
       
  1140             {
       
  1141             // iContacts validity is checked in function entry
       
  1142             iConverter->ConvertContactsL(
       
  1143                 iStoreContacts.Array(), aSelectionIndex, *this);
       
  1144             }
       
  1145         }
       
  1146     else
       
  1147         {
       
  1148         IssueStopRequest();
       
  1149         }
       
  1150 
       
  1151     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1152         ("CPbk2SendContactCmd::ConvertContactL(0x%x), end"), this);
       
  1153     }
       
  1154 
       
  1155 // --------------------------------------------------------------------------
       
  1156 // CPbk2SendContactCmd::RetrieveContactL
       
  1157 // --------------------------------------------------------------------------
       
  1158 //
       
  1159 void CPbk2SendContactCmd::RetrieveContactL(const MVPbkContactLink& aLink)
       
  1160     {
       
  1161     iRetrieveOperation = iAppServices->ContactManager().
       
  1162             RetrieveContactL(aLink, *this);
       
  1163     }
       
  1164 
       
  1165 // --------------------------------------------------------------------------
       
  1166 // CPbk2SendContactCmd::FilterErrors
       
  1167 // --------------------------------------------------------------------------
       
  1168 //
       
  1169 TInt CPbk2SendContactCmd::FilterErrors(TInt aErrorCode)
       
  1170     {
       
  1171     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1172         ("CPbk2SendContactCmd::FilterErrors(%d) start"), aErrorCode);
       
  1173 
       
  1174     TInt result = aErrorCode;
       
  1175     switch (aErrorCode)
       
  1176         {
       
  1177         case KErrNotFound:  // FALLTHROUGH
       
  1178         case KErrInUse:     // FALLTHROUGH
       
  1179             {
       
  1180             // Ignore these errors
       
  1181             // KErrNotFound means that somebody got the contact first
       
  1182             // KErrInUse means that the contact is open
       
  1183             result = KErrNone;
       
  1184             break;
       
  1185             }
       
  1186 
       
  1187         default:  // Something more serious happened -> give up
       
  1188             {
       
  1189             Cancel();
       
  1190             ProcessDone(aErrorCode);
       
  1191             break;
       
  1192             }
       
  1193         }
       
  1194 
       
  1195     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1196         ("CPbk2SendContactCmd::FilterErrors(%d) end"), result);
       
  1197 
       
  1198     return result;
       
  1199     }
       
  1200 
       
  1201 // --------------------------------------------------------------------------
       
  1202 // CPbk2SendContactCmd::IssueRequest
       
  1203 // --------------------------------------------------------------------------
       
  1204 //
       
  1205 void CPbk2SendContactCmd::IssueRequest()
       
  1206     {
       
  1207     TRequestStatus* status = &iStatus;
       
  1208     User::RequestComplete(status, KErrNone);
       
  1209     SetActive();
       
  1210     }
       
  1211 
       
  1212 // --------------------------------------------------------------------------
       
  1213 // CPbk2SendContactCmd::IssueStopRequest
       
  1214 // --------------------------------------------------------------------------
       
  1215 //
       
  1216 void CPbk2SendContactCmd::IssueStopRequest()
       
  1217     {
       
  1218     iState = EStopping;
       
  1219     if (!IsActive())
       
  1220         {
       
  1221         IssueRequest();
       
  1222         }
       
  1223     }
       
  1224 
       
  1225 // --------------------------------------------------------------------------
       
  1226 // CPbk2SendContactCmd::SendMsgUsingSendUI
       
  1227 // --------------------------------------------------------------------------
       
  1228 //
       
  1229 void CPbk2SendContactCmd::SendMsgUsingSendUI(CMessageData* aMsgData)
       
  1230     {
       
  1231     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1232         ("CPbk2SendContactCmd::SendMsgUsingSendUI(0x%x), start"), this);
       
  1233 
       
  1234     // Send the message using Send Ui
       
  1235     TRAPD(error, iSendUi->CreateAndSendMessageL( iMtmUid, aMsgData, KMsgBioUidVCard));
       
  1236 
       
  1237     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1238         ("CPbk2SendContactCmd::SendMsgUsingSendUI(%d), error"), error);
       
  1239 
       
  1240     if (error != KErrNone)
       
  1241         {
       
  1242         FilterErrors(error);
       
  1243         }
       
  1244     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
  1245         ("CPbk2SendContactCmd::SendMsgUsingSendUI(0x%x), end"), this);
       
  1246     }
       
  1247 
       
  1248 // --------------------------------------------------------------------------
       
  1249 // CPbk2SendContactCmd::IsMoreThanOneContact
       
  1250 // --------------------------------------------------------------------------
       
  1251 //
       
  1252 TBool CPbk2SendContactCmd::IsMoreThanOneContact()
       
  1253     {
       
  1254     TBool result = EFalse;
       
  1255     if ( iCntIterator )
       
  1256         {
       
  1257         result = ETrue;
       
  1258         }
       
  1259     return result;
       
  1260     }
       
  1261 
       
  1262 // End of File