phonebookui/Phonebook/App/src/CPbkSendContactCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *           Provides phonebook send contacts command object methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkSendContactCmd.h"
       
    22 #include "CPbkvCardConverter.h"
       
    23 #include "CPbkAppGlobals.h"
       
    24 
       
    25 #include <BCardEng.h>
       
    26 #include <CPbkFieldInfo.h>
       
    27 #include <Phonebook.rsg>
       
    28 #include <CPbkContactEngine.h>
       
    29 #include <CPbkProgressNoteWrapper.h>
       
    30 #include <CPbkConstants.h>
       
    31 #include <CPbkContactItem.h>
       
    32 
       
    33 #include <AknNoteWrappers.h>
       
    34 #include <eikclb.h>         // CEikListBox
       
    35 #include <sendui.h>         // Send UI API
       
    36 #include <SendUiMtmUids.h>  // Send UI MTM uid's
       
    37 #include <MsgBioUids.h>
       
    38 #include <txtrich.h>        // CRichText
       
    39 #include <barsread.h>       // TResourceReader
       
    40 #include <CMessageData.h>
       
    41 #include <PbkUID.h>
       
    42 #include <MenuFilteringFlags.h>
       
    43 #include <SendUiConsts.h>   // Postcard Uid
       
    44 #include <MPbkCommandObserver.h>
       
    45 
       
    46 #include <pbkdebug.h>
       
    47 
       
    48 /// Unnamed namespace for local definitions
       
    49 namespace {
       
    50 
       
    51 const TUint KNoMenu = 0;
       
    52 
       
    53 /**
       
    54  * Represents the different listbox index selections.
       
    55  */
       
    56 enum TPbkListBoxSelections
       
    57     {
       
    58     EFirstSelection = 0,
       
    59     ESecondSelection,
       
    60     EThirdSelection
       
    61     };
       
    62 
       
    63 
       
    64 // LOCAL DEBUG CODE
       
    65 #ifdef _DEBUG
       
    66 enum TPanicCode
       
    67     {
       
    68 	EPanicPreCond_SendvCardsL = 1,
       
    69     EPanicLogic_CmdSendContactDataL,
       
    70     EPanicLogic_MapSelection
       
    71     };
       
    72 
       
    73 void Panic(TPanicCode aReason)
       
    74     {
       
    75     _LIT(KPanicText, "CPbkSendContactCmd");
       
    76     User::Panic(KPanicText,aReason);
       
    77     }
       
    78 #endif // _DEBUG
       
    79 
       
    80 // ==================== LOCAL FUNCTIONS ====================
       
    81 
       
    82 /**
       
    83  * Creates a rich text object and packages contents of a file to it. The file's
       
    84  * data is not converted in any way except that characters are widened to 16 
       
    85  * bits.
       
    86  *
       
    87  * @param aEikEnv   EIKON environment.
       
    88  * @param aFileName name of the file to convert.
       
    89  * @return  a new rich text object with file's contents. The returned object is
       
    90  *          also left on top of the cleanup stack.
       
    91  */
       
    92 CRichText* CreateRichTextFromFileLC
       
    93     (CEikonEnv& aEikEnv, const TDesC& aFileName);
       
    94 
       
    95 /**
       
    96  * Helper class for sending the vCard(s) in async callback.
       
    97  */
       
    98 class CVCardSender : public CIdle
       
    99 	{
       
   100 	public:  // Constructors
       
   101 		/*
       
   102 		 * Creates a new instance of this object.
       
   103 		 * @param aPriority desired priority
       
   104 		 */
       
   105 		static CVCardSender* NewL(TInt aPriority);
       
   106 
       
   107 	private:  // from CIdle
       
   108 		void RunL();
       
   109 		TInt RunError(TInt aError);
       
   110 
       
   111 	private:
       
   112 		/*
       
   113 		 * Constructor.
       
   114 		 * @param aPriority desired priority
       
   115 		 */
       
   116 		CVCardSender(TInt aPriority);
       
   117 	};
       
   118 
       
   119 
       
   120 inline CVCardSender::CVCardSender(TInt aPriority) 
       
   121 	: CIdle(aPriority) 
       
   122 	{
       
   123 	CActiveScheduler::Add(this);
       
   124 	}
       
   125 
       
   126 CVCardSender* CVCardSender::NewL(TInt aPriority)
       
   127 	{
       
   128 	return new(ELeave) CVCardSender(aPriority);
       
   129 	}
       
   130 
       
   131 void CVCardSender::RunL()
       
   132 	{
       
   133 	CIdle::RunL();
       
   134     // Destroy self. 
       
   135     // If RunL (the callback) leaves RunError will handle the deletion.
       
   136 	delete this;
       
   137 	}
       
   138 
       
   139 TInt CVCardSender::RunError(TInt aError)
       
   140 	{
       
   141 	delete this;
       
   142     // Forward all errors to the active scheduler
       
   143 	return aError;
       
   144 	}
       
   145 
       
   146 
       
   147 
       
   148 CRichText* CreateRichTextFromFileLC
       
   149         (CEikonEnv& aEikEnv, const TDesC& aFileName)
       
   150     {
       
   151     // Common allocation granularity and buffer size for rich text and
       
   152     // file reading
       
   153     const TInt KBufSize = CEditableText::EDefaultTextGranularity;
       
   154 
       
   155     // Create a rich text object with default formatting
       
   156     CRichText* richText = CRichText::NewL(
       
   157         aEikEnv.SystemParaFormatLayerL(), 
       
   158         aEikEnv.SystemCharFormatLayerL(),
       
   159         CEditableText::ESegmentedStorage,
       
   160         KBufSize  // Allocation granularity
       
   161         );
       
   162     CleanupStack::PushL(richText);
       
   163 
       
   164     // Open the file for reading
       
   165     RFile file;
       
   166     User::LeaveIfError(file.Open
       
   167         (aEikEnv.FsSession(), aFileName, 
       
   168         EFileRead|EFileStream|EFileShareReadersOnly));
       
   169     CleanupClosePushL(file);
       
   170 
       
   171     // Create two buffers: 8-bit for reading from file and 16-bit for
       
   172     // converting to 16-bit format
       
   173     HBufC8* buf8 = HBufC8::NewLC(KBufSize);
       
   174     TPtr8 ptr8 = buf8->Des();
       
   175     HBufC16* buf16 = HBufC16::NewLC(ptr8.MaxLength());
       
   176     TPtr16 ptr16 = buf16->Des();
       
   177 
       
   178     // Read, convert and append to rich text until the file ends
       
   179     for (TInt err = file.Read(ptr8); 
       
   180         ptr8.Length() > 0; 
       
   181         err = file.Read(ptr8))
       
   182         {
       
   183         User::LeaveIfError(err);
       
   184         ptr16.Copy(ptr8);
       
   185         richText->InsertL(richText->DocumentLength(), ptr16);
       
   186         }
       
   187 
       
   188     // Cleanup and return
       
   189     CleanupStack::PopAndDestroy(3);  // buf16, buf8, file
       
   190     return richText;
       
   191     }
       
   192 
       
   193 }  // namespace
       
   194 
       
   195 
       
   196 // ================= MEMBER FUNCTIONS =======================
       
   197 inline CPbkSendContactCmd::CPbkSendContactCmd(
       
   198         TPbkSendingParams aParams,
       
   199         CPbkContactEngine& aEngine,
       
   200         TContactItemId aContactId,
       
   201         const CContactIdArray* aContacts,
       
   202         TPbkContactItemField* aField
       
   203         ) :
       
   204             iEngine( aEngine ),            
       
   205             iParams( aParams ),            
       
   206 			iContactId( aContactId ),
       
   207             iContacts( aContacts ),
       
   208             iField( aField )
       
   209 	{  
       
   210     PBK_DEBUG_PRINT
       
   211         (PBK_DEBUG_STRING("CPbkSendContactCmd::CPbkSendContactCmd(0x%x)"), this);
       
   212     }
       
   213 
       
   214 void CPbkSendContactCmd::ConstructL
       
   215         (CBCardEngine& aBCardEng)
       
   216     {
       
   217     iEikEnv = CEikonEnv::Static();
       
   218     iConverter = CPbkvCardConverter::NewL(iEikEnv->FsSession(),
       
   219 		iEngine, aBCardEng);
       
   220 	iVcardSender = CVCardSender::NewL(CActive::EPriorityIdle);
       
   221     iWaitNoteWrapper = CPbkProgressNoteWrapper::NewL();
       
   222     }
       
   223 
       
   224 /**
       
   225  * Static constructor. 
       
   226  */
       
   227 CPbkSendContactCmd* CPbkSendContactCmd::NewL
       
   228         (TPbkSendingParams aParams,
       
   229         CPbkContactEngine& aEngine, CBCardEngine& aBCardEng,
       
   230         TContactItemId aContactId,
       
   231         TPbkContactItemField* aField)
       
   232     {
       
   233     CPbkSendContactCmd* self = new(ELeave)
       
   234         CPbkSendContactCmd(aParams,aEngine, aContactId, NULL, aField);
       
   235     CleanupStack::PushL(self);
       
   236     self->ConstructL(aBCardEng);
       
   237     CleanupStack::Pop(); // self
       
   238     return self;
       
   239     }
       
   240 
       
   241 /**
       
   242  * Static constructor (variation for multiple contacts).
       
   243  */
       
   244 CPbkSendContactCmd* CPbkSendContactCmd::NewL
       
   245 	    (TPbkSendingParams aParams,
       
   246 	    CPbkContactEngine& aEngine, CBCardEngine& aBCardEng,
       
   247 		const CContactIdArray& aContacts)
       
   248     {
       
   249     CPbkSendContactCmd* self = new(ELeave)
       
   250 		CPbkSendContactCmd(aParams, aEngine, KNullContactId, &aContacts, NULL);
       
   251     CleanupStack::PushL(self);
       
   252     self->ConstructL(aBCardEng);
       
   253     CleanupStack::Pop(); // self
       
   254     return self;
       
   255     }
       
   256 
       
   257 /**
       
   258  * Destructor.
       
   259  */
       
   260 CPbkSendContactCmd::~CPbkSendContactCmd()
       
   261     {
       
   262     PBK_DEBUG_PRINT
       
   263         (PBK_DEBUG_STRING("CPbkSendContactCmd::~CPbkSendContactCmd(0x%x)"), this);
       
   264 
       
   265     iUnderDestruction = ETrue;
       
   266     delete iWaitNoteWrapper;
       
   267     delete iConverter;
       
   268 	delete iVcardSender;
       
   269     }
       
   270 
       
   271 void CPbkSendContactCmd::ExecuteLD()
       
   272     {
       
   273     PBK_DEBUG_PRINT
       
   274         (PBK_DEBUG_STRING("CPbkSendContactCmd::ExecuteLD(0x%x)"), this);
       
   275 
       
   276 	CleanupStack::PushL(this);
       
   277 	
       
   278 	iMtmUid = ShowSendQueryL();
       
   279 	
       
   280     if ( ( iContactId == KNullContactId && 
       
   281           ( !iContacts || iContacts->Count()==0 ) ) ||
       
   282          iMtmUid == KNullUid )
       
   283         {
       
   284         CleanupStack::PopAndDestroy();
       
   285         return;
       
   286         }
       
   287     
       
   288     TInt selectionIndex(ESendAllData);
       
   289 
       
   290     // Ask the user to select the contact data to be send, if needed
       
   291     selectionIndex = SelectSentDataL();
       
   292 
       
   293     if (selectionIndex != ECancel)
       
   294         {
       
   295 	    if (iContactId != KNullContactId)
       
   296 		    {
       
   297 		    iConverter->ConvertContactL(iContactId, iField, selectionIndex);
       
   298 		    }
       
   299 	    else
       
   300 		    {
       
   301             // iContacts validity is checked in function entry
       
   302 		    iConverter->ConvertContactsL(*iContacts, selectionIndex);
       
   303 		    }
       
   304 	
       
   305         // Then send contact(s)
       
   306         CPbkWaitNoteWrapperBase::TNoteParams noteParams;
       
   307         noteParams.iObserver = this;
       
   308 	    // ProcessFinished will be called when execution is finished.
       
   309         iWaitNoteWrapper->ExecuteL
       
   310             (*iConverter, R_QTN_SM_WAIT_BUSINESS_CARD, noteParams);
       
   311         
       
   312     	if ( iObserver )
       
   313             {
       
   314             iObserver->CommandFinished( *this );
       
   315             }
       
   316 
       
   317         CleanupStack::Pop(); // this
       
   318 
       
   319 	    // The promised self destruction will happen in SendvCardsL,
       
   320 	    // which is called by ProcessFinished
       
   321         }
       
   322     else
       
   323         {
       
   324         // User canceled the sending, exit
       
   325         CleanupStack::PopAndDestroy();
       
   326         }
       
   327     }
       
   328 
       
   329 
       
   330 /**
       
   331  * Send the vCards from an idle callback to get standard active scheduler 
       
   332  * error handling. This is especially important to handle special leave
       
   333  * code KLeaveExit which is propagated by SendUi in case the 'Exit" is 
       
   334  *  picked from the message editor's menu.
       
   335  */
       
   336 void CPbkSendContactCmd::ProcessFinished(MPbkBackgroundProcess& /*aProcess*/)
       
   337     {
       
   338     PBK_DEBUG_PRINT
       
   339         (PBK_DEBUG_STRING("CPbkSendContactCmd::ProcessFinished(0x%x)"), this);
       
   340         
       
   341     // Cancel before usage of active object.
       
   342     iVcardSender->Cancel();
       
   343     iVcardSender->Start(TCallBack(&CPbkSendContactCmd::SendvCardsLD, this));
       
   344     }
       
   345 
       
   346 /**
       
   347  * Sends prepared vCard files using send UI.
       
   348  */
       
   349 void CPbkSendContactCmd::SendvCardsLD()
       
   350     {
       
   351     // Relinquish ownership, iVcardSender takes care of it self
       
   352 	iVcardSender = NULL;
       
   353 
       
   354 	CleanupStack::PushL(this);
       
   355     CMessageData* messageData = CMessageData::NewL();
       
   356     CleanupStack::PushL( messageData );
       
   357 
       
   358     if (iConverter->FileNames().MdcaCount() > 0 &&
       
   359 		!iUnderDestruction)
       
   360         {
       
   361 		// Get globals (does not take ownership)
       
   362         CPbkAppGlobals* globals = CPbkAppGlobals::InstanceL();              
       
   363 
       
   364 		if (iMtmUid == KSenduiMtmSmsUid)
       
   365 			{
       
   366 			// Sending through SMS -> there should be only one vCard
       
   367 			// attachment. Package the attachment to a rich text object and
       
   368 			// send it as the message body.
       
   369 			__ASSERT_DEBUG(iConverter->FileNames().MdcaCount()==1, 
       
   370 				Panic(EPanicPreCond_SendvCardsL));
       
   371 
       
   372 			// Copy the one and only attachment into a rich text object
       
   373 			CRichText* msgBody = CreateRichTextFromFileLC
       
   374 				(*iEikEnv, iConverter->FileNames().MdcaPoint(0));
       
   375 
       
   376             messageData->SetBodyTextL( msgBody );
       
   377 
       
   378 			// Send the message using Send Ui
       
   379 			globals->SendUiL()->CreateAndSendMessageL(
       
   380 				iMtmUid, messageData, KMsgBioUidVCard );
       
   381 
       
   382 			CleanupStack::PopAndDestroy(msgBody);
       
   383 			}
       
   384 		else
       
   385 			{
       
   386 			// Not sending through SMS, just pass the attachments
       
   387 			__ASSERT_DEBUG(iConverter->FileNames().MdcaCount()>=1, 
       
   388 				Panic(EPanicPreCond_SendvCardsL));
       
   389 
       
   390             //Fill message data
       
   391             const TInt count( iConverter->FileNames().MdcaCount());
       
   392             for( TInt i( 0 ); i < count; ++i )
       
   393                 {
       
   394                 messageData->AppendAttachmentL( 
       
   395                         iConverter->FileNames().MdcaPoint( i ) );
       
   396                 }
       
   397 
       
   398 			// Send the message using Send Ui
       
   399 			globals->SendUiL()->CreateAndSendMessageL(
       
   400 				iMtmUid, messageData, KMsgBioUidVCard );            
       
   401 			}
       
   402         }
       
   403 
       
   404     // Destroy itself as promised
       
   405 	CleanupStack::PopAndDestroy(2); //this, messageData		
       
   406     }
       
   407 
       
   408 TInt CPbkSendContactCmd::SendvCardsLD(TAny* aThis)
       
   409     {
       
   410 	CPbkSendContactCmd* self = static_cast<CPbkSendContactCmd*>(aThis);
       
   411 	self->SendvCardsLD();
       
   412 
       
   413     return EFalse;
       
   414     }
       
   415 
       
   416 
       
   417 /**
       
   418  * If necessary, shows a popup selection list from which the
       
   419  * the user selects what details are sent in a vCard.
       
   420  * @return user selection mapped into TPbkChoiceItemEnumerations
       
   421  */
       
   422 
       
   423 TInt CPbkSendContactCmd::SelectSentDataL()
       
   424     {
       
   425     TInt selectionIndex(ESendAllData);
       
   426 
       
   427     // Get the resource id of the menu to be shown
       
   428     TInt resourceId = SelectionListL();
       
   429 
       
   430     if (resourceId)
       
   431         {
       
   432         // Create a list box
       
   433         CEikColumnListBox* listBox = static_cast<CEikColumnListBox*>
       
   434 		    (EikControlFactory::CreateByTypeL
       
   435 		    (EAknCtSinglePopupMenuListBox).iControl);
       
   436         CleanupStack::PushL(listBox);
       
   437 
       
   438         // Create a popup list
       
   439         CAknPopupList* popupList = CAknPopupList::NewL
       
   440 		    (listBox, R_AVKON_SOFTKEYS_OK_CANCEL,
       
   441             AknPopupLayouts::EMenuGraphicWindow);
       
   442         CleanupStack::PushL(popupList);
       
   443 
       
   444         HBufC* headingText= CCoeEnv::Static()->AllocReadResourceLC
       
   445 		    (R_PBK_BUSINESSCARD_SEND_HEADING);
       
   446 	    popupList->SetTitleL(*headingText);
       
   447         CleanupStack::PopAndDestroy(); // headingText
       
   448 
       
   449         // Init list box
       
   450         listBox->SetContainerWindowL(*popupList);
       
   451 
       
   452         TResourceReader resReader;
       
   453         CCoeEnv::Static()->CreateResourceReaderLC(resReader, resourceId);
       
   454         listBox->ConstructFromResourceL(resReader);
       
   455         CleanupStack::PopAndDestroy();  // resReader
       
   456 
       
   457 	    listBox->CreateScrollBarFrameL(ETrue);
       
   458 	    listBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   459 		    (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   460 
       
   461         CleanupStack::Pop(); // popupList
       
   462 
       
   463         // Show popuplist dialog
       
   464         TInt res = popupList->ExecuteLD();
       
   465         if (res)
       
   466             {
       
   467             selectionIndex = listBox->CurrentItemIndex();
       
   468 
       
   469             // We have to remap the selection index since
       
   470             // several different listbox configurations
       
   471             MapSelection(selectionIndex, resourceId);
       
   472             }
       
   473         else
       
   474             {
       
   475             selectionIndex = ECancel;
       
   476             }
       
   477         CleanupStack::PopAndDestroy(); // listBox
       
   478         }
       
   479 
       
   480     return selectionIndex;
       
   481     }
       
   482 
       
   483 
       
   484 /**
       
   485  * Decides what selection list to show the user.
       
   486  * @return resource id of the menu to show
       
   487  */
       
   488 TInt CPbkSendContactCmd::SelectionListL() const
       
   489     {
       
   490     TInt ret(KNoMenu);
       
   491     TBool supportsFieldType(ETrue);
       
   492 
       
   493     // Check is the 'send selected fields' feature enabled
       
   494     TBool sendSelectedFeatureEnabled(iEngine.Constants()->
       
   495         LocallyVariatedFeatureEnabled(EPbkLVSendSelectedContactFields));
       
   496 
       
   497     // Check is the sending media SMS and does the contact
       
   498     // have a thumbnail
       
   499     TBool smsAndThumbnail(EFalse);
       
   500     if ((AnyThumbnailsL()) && (IsSmsMtmL()))
       
   501         {
       
   502         smsAndThumbnail = ETrue;
       
   503         }
       
   504 
       
   505     // If focused field is supplied, the command object was
       
   506     // launched from contact info view and that requires
       
   507     // we have to check is the field supported by vCard spec
       
   508     if (iField)
       
   509         {
       
   510         CBCardEngine& bcardEng = CPbkAppGlobals::InstanceL()->BCardEngL(iEngine);
       
   511         if (!bcardEng.SupportsFieldType(iField->FieldInfo().FieldId()))
       
   512             {
       
   513             supportsFieldType = EFalse;
       
   514             }
       
   515         }
       
   516 
       
   517     // Now check the cases when the menu needs to be shown
       
   518     if (sendSelectedFeatureEnabled)
       
   519         {
       
   520         // There are two main branches depending on which view
       
   521         // this command object was launched from
       
   522         if (iField)
       
   523             {
       
   524             // Command object was launched from contact info view.
       
   525 
       
   526             if (!smsAndThumbnail)
       
   527                 {
       
   528                 // When there is no thumbnail involved the selection
       
   529                 // menu is shown only if we are over vCard supported
       
   530                 // field
       
   531                 if (supportsFieldType)
       
   532                     {
       
   533                     ret = R_PBK_CONTACTINFO_SEND_OPTIONS;
       
   534                     }
       
   535                 }
       
   536             else
       
   537                 {
       
   538                 // Thumbnail is involved, the selection menu depends
       
   539                 // on whether we are over vCard supported field or not
       
   540                 if (supportsFieldType)
       
   541                     {
       
   542                     ret = R_PBK_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL;
       
   543                     }
       
   544                 else
       
   545                     {
       
   546                     ret = R_PBK_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL_NO_FIELD;
       
   547                     }
       
   548                 }
       
   549             }
       
   550         else
       
   551             {
       
   552             // Command object was launched from contact list view,
       
   553             // the menu is shown only in case there is thumbnail
       
   554             // involded and the sending media is SMS
       
   555             if (smsAndThumbnail)
       
   556                 {
       
   557                 ret = R_PHONEBOOK_SEND_OPTIONS;
       
   558                 }
       
   559             }
       
   560         }
       
   561     else
       
   562         {
       
   563         // If the 'send selected fields' is disabled, the menu
       
   564         // needs to be shown only if the user is in contact info
       
   565         // view and over a vCard supported field
       
   566         if ((iField) && (supportsFieldType))
       
   567             {
       
   568             ret = R_PBK_CONTACTINFO_SEND_OPTIONS;
       
   569             }
       
   570         }
       
   571     return ret;
       
   572     }
       
   573 
       
   574 
       
   575 /**
       
   576  * Maps selection index to choice item TPbkChoiceItemEnumerations.
       
   577  * @param aSelection goes in as a selection index made by user in
       
   578  *      the selection list, when exiting contains the selection value
       
   579  *      mapped to TPbkChoiceItemEnumerations
       
   580  * @param aShownMenu what menu was shown to the user (resource id)
       
   581  */
       
   582 void CPbkSendContactCmd::MapSelection(TInt& aSelection,
       
   583         TInt aShownMenu)
       
   584     {
       
   585     switch (aShownMenu)
       
   586         {
       
   587         case R_PBK_CONTACTINFO_SEND_OPTIONS:
       
   588             //'send item data'
       
   589             //'send all data'
       
   590             {
       
   591             switch (aSelection)
       
   592                 {
       
   593                 case EFirstSelection:
       
   594                     {
       
   595                     aSelection = ESendCurrentItem;
       
   596                     break;
       
   597                     }
       
   598 
       
   599                 case ESecondSelection:
       
   600                     {
       
   601                     aSelection = ESendAllData;
       
   602                     break;
       
   603                     }
       
   604 
       
   605                 default:
       
   606                     {
       
   607                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   608                     break;
       
   609                     }
       
   610                 }
       
   611             break;
       
   612             }
       
   613 
       
   614         case R_PBK_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL:
       
   615             //'send item data'
       
   616             //'send detail without image'
       
   617             //'send detail with image'
       
   618             {
       
   619             switch (aSelection)
       
   620                 {
       
   621                 case EFirstSelection:
       
   622                     {
       
   623                     aSelection = ESendCurrentItem;
       
   624                     break;
       
   625                     }
       
   626 
       
   627                 case ESecondSelection:
       
   628                     {
       
   629                     aSelection = ESendAllDataWithoutPicture;
       
   630                     break;
       
   631                     }
       
   632 
       
   633                 case EThirdSelection:
       
   634                     {
       
   635                     aSelection = ESendAllData;
       
   636                     break;
       
   637                     }
       
   638 
       
   639                 default:
       
   640                     {
       
   641                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   642                     break;
       
   643                     }
       
   644                 }
       
   645             break;
       
   646             }
       
   647 
       
   648         case R_PBK_CONTACTINFO_SEND_OPTIONS_SMS_THUMBNAIL_NO_FIELD:
       
   649             //'send detail without image'
       
   650             //'send detail with image'
       
   651             {
       
   652             switch (aSelection)
       
   653                 {
       
   654                 case EFirstSelection:
       
   655                     {
       
   656                     aSelection = ESendAllDataWithoutPicture;
       
   657                     break;
       
   658                     }
       
   659 
       
   660                 case ESecondSelection:
       
   661                     {
       
   662                     aSelection = ESendAllData;
       
   663                     break;
       
   664                     }
       
   665 
       
   666                 default:
       
   667                     {
       
   668                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   669                     break;
       
   670                     }
       
   671                 }
       
   672             break;
       
   673             }
       
   674 
       
   675         case R_PHONEBOOK_SEND_OPTIONS:
       
   676             //'send without image'
       
   677             //'send with image'
       
   678             {
       
   679             switch (aSelection)
       
   680                 {
       
   681                 case EFirstSelection:
       
   682                     {
       
   683                     aSelection = ESendAllDataWithoutPicture;
       
   684                     break;
       
   685                     }
       
   686 
       
   687                 case ESecondSelection:
       
   688                     {
       
   689                     aSelection = ESendAllData;
       
   690                     break;
       
   691                     }
       
   692 
       
   693                 default:
       
   694                     {
       
   695                     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   696                     break;
       
   697                     }
       
   698                 }
       
   699             break;
       
   700             }
       
   701         
       
   702         default:
       
   703             {
       
   704             __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_MapSelection));
       
   705             break;
       
   706             }
       
   707         }
       
   708     }
       
   709 
       
   710 
       
   711 /**
       
   712  * Checks are there any thumbnails in the contact set.
       
   713  * @return ETrue if there was even one thumbnail, EFalse otherwise
       
   714  */
       
   715 TBool CPbkSendContactCmd::AnyThumbnailsL() const
       
   716     {
       
   717     TBool ret(EFalse);
       
   718     if (iContactId != KNullContactId)
       
   719         {
       
   720         CPbkContactItem* contact = iEngine.ReadContactLC(iContactId);
       
   721         ret = HasThumbnail(*contact);
       
   722         CleanupStack::PopAndDestroy(contact);
       
   723         }
       
   724 	else if (iContacts && iContacts->Count() > 0)
       
   725 		{
       
   726         for (TInt i=0; i < iContacts->Count(); ++i)
       
   727             {
       
   728             CPbkContactItem* contact = iEngine.ReadContactLC((*iContacts)[i]);
       
   729             ret = HasThumbnail(*contact);
       
   730             CleanupStack::PopAndDestroy(contact);
       
   731             if (ret)
       
   732                 {
       
   733                 // We can exit the loop as soon as a thumbnail
       
   734                 // is found
       
   735                 break;
       
   736                 }
       
   737             }
       
   738 		}
       
   739 
       
   740     return ret;
       
   741     }
       
   742 
       
   743 
       
   744 /**
       
   745  * Checks does aItem have a thumbnail.
       
   746  * @return ETrue if the contact has a thumbnail, EFalse otherwise
       
   747  */
       
   748 TBool CPbkSendContactCmd::HasThumbnail(CPbkContactItem& aItem) const
       
   749     {
       
   750     const TPbkContactItemField* field =
       
   751         aItem.FindField(EPbkFieldIdThumbnailImage);
       
   752     return (field && !field->IsEmptyOrAllSpaces());
       
   753     }
       
   754 
       
   755 /**
       
   756  * Checks is the selected sending media SMS.
       
   757  * @return ETrue if SMS is the sending media, EFalse otherwise
       
   758  */
       
   759 TBool CPbkSendContactCmd::IsSmsMtmL() const
       
   760     {
       
   761     TBool ret(EFalse);
       
   762     if ( iMtmUid == KSenduiMtmSmsUid )
       
   763         {
       
   764         ret = ETrue;
       
   765         }
       
   766     return ret;
       
   767     }
       
   768 
       
   769 TUid CPbkSendContactCmd::ShowSendQueryL()
       
   770     {
       
   771 	return CPbkAppGlobals::InstanceL()->SendUiL()
       
   772 		->ShowSendQueryL( NULL, iParams.iCapabilities, iParams.iMtmFilter );
       
   773     }    
       
   774 
       
   775 void CPbkSendContactCmd::AddObserver( MPbkCommandObserver& aObserver )
       
   776     {
       
   777     iObserver = &aObserver;
       
   778     }
       
   779 
       
   780 
       
   781 //  End of File