meetingrequest/mrgui/src/cesmrcontactmenuhandler.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Implementation of class CESMRContactMenuHandler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "cesmrcontactmenuhandler.h"
       
    21 #include "cesmrcontactmenuurlhandler.h"
       
    22 #include "cesmrcontactmenuattachmenthandler.h"
       
    23 
       
    24 #include <CVPbkContactManager.h>
       
    25 #include <CVPbkContactLinkArray.h>
       
    26 #include <MVPbkContactStoreList.h>
       
    27 #include <MVPbkContactStore.h>
       
    28 #include <MVPbkContactStoreProperties.h>
       
    29 #include <MVPbkStoreContact.h>
       
    30 #include <MVPbkFieldType.h>
       
    31 #include <MVPbkContactOperationBase.h>
       
    32 #include <MVPbkContactFieldTextData.h>
       
    33 #include <TVPbkFieldVersitProperty.h>
       
    34 #include <CVPbkFieldTypeRefsList.h>
       
    35 
       
    36 #include "cfsccontactactionservice.h"
       
    37 #include "cfsccontactactionmenu.h"
       
    38 #include "tfsccontactactionqueryresult.h"
       
    39 #include "tfsccontactactionvisibility.h"
       
    40 #include "mfsccontactaction.h"
       
    41 #include "mfsccontactactionmenumodel.h"
       
    42 #include "cesmrattachmentinfo.h"
       
    43 
       
    44 #include <CVPbkFieldTypeIterator.h>
       
    45 #include <CVPbkFieldTypeSelector.h>
       
    46 #include <VPbkEng.rsg>
       
    47 
       
    48 #include <esmrgui.rsg>
       
    49 #include "esmrcommands.h"
       
    50 
       
    51 #include <eikenv.h>
       
    52 #include <eikmenup.h>
       
    53 #include <commonphoneparser.h>
       
    54 
       
    55 /// Unnamed namespace for local definitions
       
    56 namespace{ // codescanner::namespace
       
    57 
       
    58 const TInt KGranularity( 8 );
       
    59 
       
    60 }//namespace
       
    61 
       
    62 // ======== MEMBER FUNCTIONS ========
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CESMRContactMenuHandler::CESMRContactMenuHandler( )
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CESMRContactMenuHandler::CESMRContactMenuHandler( 
       
    69 		CESMRContactManagerHandler& aContactManagerHandler ):
       
    70     iContactManagerHandler( aContactManagerHandler ), 
       
    71     iContactActionList( KGranularity )
       
    72     {
       
    73     FUNC_LOG;
       
    74     //do nothing
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CESMRContactMenuHandler::NewL( )
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CESMRContactMenuHandler* CESMRContactMenuHandler::NewL( 
       
    82 		CESMRContactManagerHandler& aContactManagerHandler )
       
    83     {
       
    84     FUNC_LOG;
       
    85     CESMRContactMenuHandler* self = new (ELeave) CESMRContactMenuHandler( 
       
    86 													aContactManagerHandler );
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CESMRContactMenuHandler::ConstructL( )
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CESMRContactMenuHandler::ConstructL( )
       
    98     {
       
    99     FUNC_LOG;
       
   100     
       
   101     CVPbkContactManager& contactManager =
       
   102             iContactManagerHandler.GetContactManager();
       
   103     
       
   104     iContactActionService = CFscContactActionService::NewL( contactManager );
       
   105     iContactActionMenu = CFscContactActionMenu::NewL( 
       
   106             *iContactActionService, EFscContactActionMenuModeNormal, ETrue );
       
   107 
       
   108     iContactMenuUrlHandler
       
   109             = CESMRContactMenuUrlHandler::NewL( *iContactActionMenu );
       
   110 
       
   111 	// <cmail>
       
   112     iContactMenuAttachmentHandler
       
   113             = CESMRContactMenuAttachmentHandler::NewL( *iContactActionMenu );
       
   114 	// </cmail>
       
   115 
       
   116     if ( iContactManagerHandler.IsReady() )
       
   117         {
       
   118         iContactManagerReady = ETrue;
       
   119         }
       
   120     else
       
   121         {
       
   122         iContactManagerHandler.AddObserverL ( this );
       
   123         }
       
   124     
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CESMRContactMenuHandler::~CESMRContactMenuHandler( )
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CESMRContactMenuHandler::~CESMRContactMenuHandler( )
       
   132     {
       
   133     FUNC_LOG;
       
   134     iStoreContactList.ResetAndDestroy();
       
   135     delete iFindResultsArray;
       
   136     delete iContactMenuUrlHandler;    
       
   137     delete iContactMenuAttachmentHandler;    
       
   138     delete iContactOperationBase;
       
   139     delete iContactActionMenu;
       
   140     delete iContactActionService;
       
   141     delete iValue;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CESMRContactMenuHandler::OptionsMenuAvailable( )
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 TBool CESMRContactMenuHandler::OptionsMenuAvailable( )
       
   149     {
       
   150     FUNC_LOG;
       
   151     return iOptionsMenuReady || 
       
   152 		   iContactMenuUrlHandler->OptionsMenuAvailable( ) ||
       
   153 		   iContactMenuAttachmentHandler->OptionsMenuAvailable();
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CESMRContactMenuHandler::InitOptionsMenuL
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CESMRContactMenuHandler::InitOptionsMenuL( 
       
   161 		CEikMenuPane* aActionMenuPane )
       
   162     {
       
   163     FUNC_LOG;
       
   164     switch ( iValueType )
       
   165         {
       
   166         case EValueTypeEmail: // Fall through
       
   167         case EValueTypePhoneNumber:
       
   168             {
       
   169             // Add actions to options / actions submenu
       
   170             const TInt count(iContactActionList.Count());
       
   171             for ( TInt i = 0; i < count; ++i )
       
   172                 {
       
   173                 CEikMenuPaneItem::SData data;
       
   174                 data.iFlags = 0;
       
   175                 data.iCascadeId = 0;
       
   176                 data.iCommandId = EESMRCmdActionMenuFirst + i;
       
   177                 data.iText = iContactActionList[i].iAction->ActionMenuText();
       
   178                 aActionMenuPane->AddMenuItemL( data );
       
   179 
       
   180                 aActionMenuPane->SetItemDimmed( 
       
   181                 		data.iCommandId,
       
   182                         iContactActionList[i].iOptionsMenuVisibility.iVisibility
       
   183                         == TFscContactActionVisibility::EFscActionDimmed );
       
   184                 }
       
   185             break;
       
   186             }
       
   187         case EValueTypeURL:
       
   188             {
       
   189             iContactMenuUrlHandler->InitOptionsMenuL( aActionMenuPane );
       
   190             break;
       
   191             }        
       
   192         case EValueTypeAttachment:
       
   193             {
       
   194             iContactMenuAttachmentHandler->InitOptionsMenuL( aActionMenuPane );
       
   195             break;
       
   196             }     
       
   197         default:
       
   198             {
       
   199             break;
       
   200             }
       
   201         }
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CESMRContactMenuHandler::ExecuteOptionsMenuL
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CESMRContactMenuHandler::ExecuteOptionsMenuL( TInt aCommand )
       
   209     {
       
   210     FUNC_LOG;
       
   211     switch ( iValueType )
       
   212         {
       
   213         case EValueTypeEmail: // Fall through
       
   214         case EValueTypePhoneNumber:
       
   215             {
       
   216             TInt index = aCommand - EESMRCmdActionMenuFirst;
       
   217             if ( index >= 0 && index < iContactActionList.Count() )
       
   218                 {
       
   219                 TUid uid = iContactActionList[index].iAction->Uid();
       
   220                 iContactActionService->ExecuteL( uid, this );
       
   221                 }
       
   222             break;
       
   223             }
       
   224         case EValueTypeURL:
       
   225             {
       
   226             iContactMenuUrlHandler->ExecuteOptionsMenuL( aCommand );
       
   227             break;
       
   228             }
       
   229         default:
       
   230             {
       
   231             break;
       
   232             }
       
   233         }
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CESMRContactMenuHandler::Reset( )
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C void CESMRContactMenuHandler::Reset( )
       
   241     {
       
   242     FUNC_LOG;
       
   243     delete iContactOperationBase;
       
   244     iContactOperationBase = NULL;
       
   245 
       
   246     delete iFindResultsArray;
       
   247     iFindResultsArray = NULL;
       
   248 
       
   249     iContactMenuUrlHandler->Reset();
       
   250     iContactMenuAttachmentHandler->Reset();
       
   251     
       
   252     iContactActionMenu->Model().RemoveAll();
       
   253     
       
   254     delete iValue;
       
   255     iValue = NULL;
       
   256     
       
   257     iContactActionList.Reset();
       
   258     iStoreContactList.ResetAndDestroy();
       
   259     iActionMenuReady = EFalse;
       
   260     iOptionsMenuReady = EFalse;
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CESMRContactMenuHandler::SetValueL
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CESMRContactMenuHandler::SetValueL(
       
   268         const TDesC& aValue, TValueType aValueType )
       
   269     {
       
   270     FUNC_LOG;
       
   271     Reset();
       
   272 
       
   273     if ( aValueType == EValueTypeURL )
       
   274         {
       
   275         iContactMenuUrlHandler->SetUrlL( aValue );
       
   276         iValueType = aValueType;
       
   277         }
       
   278     else if( aValueType == EValueTypeAttachment )
       
   279         {
       
   280         iContactMenuAttachmentHandler->InitActionMenuL();
       
   281         iValueType = aValueType;
       
   282         }
       
   283     else
       
   284         {
       
   285         iValue = aValue.AllocL();
       
   286         iValueType = aValueType;
       
   287         if ( iContactManagerReady )
       
   288             {
       
   289             SearchContactL();
       
   290             }
       
   291         }
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CESMRContactMenuHandler::SetAttachmentInfoL
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 EXPORT_C void CESMRContactMenuHandler::SetAttachmentInfoL(
       
   299         CESMRAttachmentInfo* aAttachmentInfo )
       
   300     {
       
   301     FUNC_LOG;
       
   302 
       
   303     iContactMenuAttachmentHandler->SetAttachmentInfo( aAttachmentInfo );
       
   304     SetValueL( KNullDesC, EValueTypeAttachment );
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CESMRContactMenuHandler::SetCommandObserver()
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 EXPORT_C void CESMRContactMenuHandler::SetCommandObserver(
       
   312             MEikCommandObserver* aCommandObserver )
       
   313     {
       
   314     FUNC_LOG;
       
   315     iCommandObserver = aCommandObserver;
       
   316     
       
   317     if ( iValueType == EValueTypeAttachment )
       
   318         {
       
   319         iContactMenuAttachmentHandler->SetCommandObserver( aCommandObserver );
       
   320         }
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CESMRContactMenuHandler::ShowActionMenuL( )
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 EXPORT_C void CESMRContactMenuHandler::ShowActionMenuL( )
       
   328     {
       
   329     FUNC_LOG;
       
   330     if ( iValueType == EValueTypeURL )
       
   331         {
       
   332         iContactMenuUrlHandler->ShowActionMenuL();
       
   333         }
       
   334     else if ( iValueType == EValueTypeAttachment )
       
   335         {
       
   336         iContactMenuAttachmentHandler->ShowActionMenuL();
       
   337         }
       
   338     else if ( iActionMenuReady )
       
   339         {
       
   340         iContactActionMenu->ExecuteL( );
       
   341         }
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // CESMRContactMenuHandler::VerifyContactDetailsL
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CESMRContactMenuHandler::VerifyContactDetailsL()
       
   349     {
       
   350     FUNC_LOG;
       
   351     if ( iFindResultsArrayIndex < iFindResultsArray->Count() )
       
   352         {
       
   353         CVPbkContactManager& contactManager =
       
   354                 iContactManagerHandler.GetContactManager();
       
   355 
       
   356         iContactOperationBase =
       
   357             contactManager.RetrieveContactL( 
       
   358             		iFindResultsArray->At( iFindResultsArrayIndex ), 
       
   359             		*this );
       
   360         }
       
   361     else
       
   362         {
       
   363         delete iFindResultsArray;
       
   364         iFindResultsArray = NULL;
       
   365 
       
   366         if ( iStoreContactList.Count() > 0 )
       
   367             {
       
   368             iContactActionService->SetContactSetL( iStoreContactList );
       
   369             iContactActionService->QueryActionsL( this );
       
   370             }
       
   371         else
       
   372             {
       
   373             CreateContactL ( );
       
   374             }
       
   375         }
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // CESMRContactMenuHandler::ContactManagerReady( )
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 void CESMRContactMenuHandler::ContactManagerReady( )
       
   383     {
       
   384     FUNC_LOG;
       
   385     iContactManagerReady = ETrue;
       
   386     iContactManagerHandler.RemoveObserver( this );
       
   387     if ( iValue )
       
   388         {
       
   389         TRAP_IGNORE( SearchContactL() );
       
   390         }
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CESMRContactMenuHandler::VPbkSingleContactOperationComplete
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CESMRContactMenuHandler::VPbkSingleContactOperationComplete(
       
   398         MVPbkContactOperationBase& /*aOperation*/,
       
   399         MVPbkStoreContact* aContact )
       
   400     {
       
   401     FUNC_LOG;
       
   402     delete iContactOperationBase;
       
   403     iContactOperationBase = NULL;
       
   404 
       
   405     MVPbkStoreContactFieldCollection& fieldCollection =
       
   406         aContact->Fields();
       
   407 
       
   408     TBool valueMatchFound = EFalse;
       
   409     const TInt count(fieldCollection.FieldCount());
       
   410     for ( TInt i = 0; valueMatchFound == EFalse && i < count; ++i )
       
   411         {
       
   412         MVPbkStoreContactField& contactField = fieldCollection.FieldAt( i );
       
   413         MVPbkContactFieldData& fieldData = contactField.FieldData();
       
   414         if ( fieldData.DataType() == EVPbkFieldStorageTypeText )
       
   415             {
       
   416             MVPbkContactFieldTextData& fieldTextData =
       
   417                 MVPbkContactFieldTextData::Cast( fieldData );
       
   418 
       
   419             if ( fieldTextData.Text().CompareF( *iValue ) == 0 )
       
   420                 {
       
   421                 valueMatchFound = ETrue;
       
   422                 }
       
   423             }
       
   424         }
       
   425 
       
   426     if ( valueMatchFound )
       
   427         {
       
   428         TRAP_IGNORE( iStoreContactList.AppendL( aContact ) );
       
   429         }
       
   430     else
       
   431         {
       
   432         delete aContact;
       
   433         }
       
   434 
       
   435     ++iFindResultsArrayIndex;
       
   436     TRAPD( err, VerifyContactDetailsL() );
       
   437     if ( err != KErrNone )
       
   438         {
       
   439         Reset();
       
   440         }
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // CESMRContactMenuHandler::VPbkSingleContactOperationFailed
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 void CESMRContactMenuHandler::VPbkSingleContactOperationFailed(
       
   448         MVPbkContactOperationBase& /*aOperation*/,
       
   449         TInt /*aError*/ )
       
   450     {
       
   451     FUNC_LOG;
       
   452     delete iContactOperationBase;
       
   453     iContactOperationBase = NULL;
       
   454 
       
   455     ++iFindResultsArrayIndex;
       
   456     TRAPD( err, VerifyContactDetailsL() );
       
   457     if ( err != KErrNone )
       
   458         {
       
   459         Reset();
       
   460         }
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 // CESMRContactMenuHandler::FindCompleteL
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 void CESMRContactMenuHandler::FindCompleteL( MVPbkContactLinkArray* aResults )
       
   468     {
       
   469     FUNC_LOG;
       
   470     delete iContactOperationBase;
       
   471     iContactOperationBase = NULL;
       
   472 
       
   473     iStoreContactList.ResetAndDestroy();
       
   474     iFindResultsArray = aResults;
       
   475     iFindResultsArrayIndex = 0;
       
   476 
       
   477     VerifyContactDetailsL();
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // CESMRContactMenuHandler::FindFailed
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 void CESMRContactMenuHandler::FindFailed( TInt /*aError*/)
       
   485     {
       
   486     FUNC_LOG;
       
   487     delete iContactOperationBase;
       
   488     iContactOperationBase = NULL;
       
   489 
       
   490     Reset ( );
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CESMRContactMenuHandler::QueryActionsComplete( )
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CESMRContactMenuHandler::QueryActionsComplete( )
       
   498     {
       
   499     FUNC_LOG;
       
   500     const CFscContactActionList& actionList =
       
   501             iContactActionService->QueryResults();
       
   502 
       
   503     // Add visible actions to local contact action list for
       
   504     // options menu / actions.
       
   505     const TInt count(actionList.Count());
       
   506     for ( TInt i = 0; i < count; ++i )
       
   507         {
       
   508         TFscContactActionVisibility::TVisibility visibility =
       
   509                 actionList[i].iOptionsMenuVisibility.iVisibility;
       
   510         if ( visibility == TFscContactActionVisibility::EFscActionVisible ||
       
   511              visibility == TFscContactActionVisibility::EFscActionDimmed )
       
   512             {
       
   513             TRAP_IGNORE( iContactActionList.AppendL( actionList.At(i) ) );
       
   514             }
       
   515         }
       
   516 
       
   517     const TInt count2(iContactActionList.Count());
       
   518     for ( TInt i = 0; i < count2; ++i )
       
   519         {
       
   520         iContactActionList[i].iPriority = -iContactActionList[i].iPriority;
       
   521         }
       
   522 
       
   523     // Sort local list of actions by priority.
       
   524     TKeyArrayFix sortKey( _FOFF( TFscContactActionQueryResult, // codescanner::foff
       
   525                                  iPriority ),
       
   526                           ECmpTInt);
       
   527     iContactActionList.Sort( sortKey );
       
   528 
       
   529     // Enable options menu / actions if there are actions available.
       
   530     iOptionsMenuReady = iContactActionList.Count() > 0;
       
   531 
       
   532     // Initialize contact action menu and enable it.
       
   533     TRAPD( error, iContactActionMenu->Model().AddPreQueriedCasItemsL ( ) );
       
   534     if ( error != KErrNone )
       
   535         {
       
   536         iActionMenuReady = EFalse;
       
   537         }
       
   538     else
       
   539         {
       
   540         iActionMenuReady = ETrue;
       
   541         }
       
   542     }
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // CESMRContactMenuHandler::QueryActionsFailed
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 void CESMRContactMenuHandler::QueryActionsFailed( TInt /*aError*/)
       
   549     {
       
   550     FUNC_LOG;
       
   551     Reset();
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // CESMRContactMenuHandler::ExecuteComplete( )
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CESMRContactMenuHandler::ExecuteComplete( )
       
   559     {
       
   560     FUNC_LOG;
       
   561     // Do nothing
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CESMRContactMenuHandler::ExecuteFailed
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 void CESMRContactMenuHandler::ExecuteFailed( TInt /*aError*/)
       
   569     {
       
   570     FUNC_LOG;
       
   571     // Do nothing
       
   572     }
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 // CESMRContactMenuHandler::SearchContactL( )
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 void CESMRContactMenuHandler::SearchContactL( )
       
   579     {
       
   580     FUNC_LOG;
       
   581     // Cancel ongoing search if one exists.
       
   582     if ( iContactOperationBase )
       
   583         {
       
   584         delete iContactOperationBase;
       
   585         iContactOperationBase = NULL;
       
   586         }
       
   587 
       
   588     CVPbkContactManager& contactManager =
       
   589             iContactManagerHandler.GetContactManager();
       
   590 
       
   591     switch ( iValueType )
       
   592         {
       
   593         case EValueTypeEmail:
       
   594             {
       
   595             const MVPbkFieldTypeList& fieldTypeList = 
       
   596 							contactManager.FieldTypes();
       
   597 
       
   598             CVPbkFieldTypeRefsList* fieldTypeRefsList =
       
   599                     CVPbkFieldTypeRefsList::NewL();
       
   600             CleanupStack::PushL( fieldTypeRefsList );
       
   601 
       
   602             // Search for all email fields.
       
   603             const TInt count(fieldTypeList.FieldTypeCount());
       
   604             for ( TInt i = 0; i < count; ++i )
       
   605                 {
       
   606                 const MVPbkFieldType& fieldType = 
       
   607 					fieldTypeList.FieldTypeAt( i );
       
   608                 TArray<TVPbkFieldVersitProperty> versitProperties =
       
   609                         fieldType.VersitProperties();
       
   610 
       
   611                 const TInt count2(versitProperties.Count());
       
   612                 for ( TInt ii=0; ii < count2; ++ii )
       
   613                     {
       
   614                     if ( versitProperties[ii].Name() == EVPbkVersitNameEMAIL )
       
   615                         {
       
   616                         fieldTypeRefsList->AppendL( fieldType );
       
   617                         break;
       
   618                         }
       
   619                     }
       
   620                 }
       
   621 
       
   622             // Initiate find operation, returns to FindCompleteL.
       
   623             iContactOperationBase = contactManager.FindL( *iValue,
       
   624                     *fieldTypeRefsList, *this );
       
   625 
       
   626             CleanupStack::PopAndDestroy ( fieldTypeRefsList );
       
   627             break;
       
   628             }
       
   629         case EValueTypePhoneNumber:
       
   630             {
       
   631             if ( CommonPhoneParser::IsValidPhoneNumber( *iValue,
       
   632                     CommonPhoneParser::EPlainPhoneNumber ) )
       
   633                 {
       
   634                 // Initiate find operation, returns to FindCompleteL.
       
   635                 const MVPbkFieldTypeList& fieldTypeList = 
       
   636 											contactManager.FieldTypes();
       
   637 
       
   638                 CVPbkFieldTypeRefsList* fieldTypeRefsList =
       
   639                         CVPbkFieldTypeRefsList::NewL();
       
   640                 CleanupStack::PushL( fieldTypeRefsList );
       
   641 
       
   642                 // Search for all email fields.
       
   643                 const TInt count(fieldTypeList.FieldTypeCount());
       
   644                 for ( TInt i = 0; i < count; ++i )
       
   645                     {
       
   646                     const MVPbkFieldType& fieldType = 
       
   647 											fieldTypeList.FieldTypeAt( i );
       
   648                     TArray<TVPbkFieldVersitProperty> versitProperties =
       
   649                             fieldType.VersitProperties();
       
   650 
       
   651                     const TInt count2(versitProperties.Count());
       
   652                     for ( TInt ii=0; ii < count2; ++ii )
       
   653                         {
       
   654                         if ( versitProperties[ii].Name() == EVPbkVersitNameTEL )
       
   655                             {
       
   656                             fieldTypeRefsList->AppendL( fieldType );
       
   657                             break;
       
   658                             }
       
   659                         }
       
   660                     }
       
   661                 // Initiate find operation, returns to FindCompleteL.
       
   662                 iContactOperationBase = contactManager.FindL( *iValue,
       
   663                         *fieldTypeRefsList, *this );
       
   664 
       
   665                 CleanupStack::PopAndDestroy ( fieldTypeRefsList );
       
   666                 }
       
   667             else
       
   668                 {
       
   669                 CreateContactL();
       
   670                 }
       
   671             break;
       
   672             }
       
   673         default:
       
   674             {
       
   675             // Disable contact action handler.
       
   676             Reset();
       
   677             break;
       
   678             }
       
   679         }
       
   680     }
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // CESMRContactMenuHandler::CreateContactL( )
       
   684 // ---------------------------------------------------------------------------
       
   685 //
       
   686 void CESMRContactMenuHandler::CreateContactL( )
       
   687     {
       
   688     FUNC_LOG;
       
   689     CVPbkContactManager& contactManager =
       
   690             iContactManagerHandler.GetContactManager();
       
   691 
       
   692     const MVPbkFieldTypeList& fieldTypeList = contactManager.FieldTypes();
       
   693     const MVPbkFieldType* fieldType= NULL;
       
   694 
       
   695     // Try to find appropriate field type.
       
   696     switch ( iValueType )
       
   697         {
       
   698         case EValueTypeEmail:
       
   699             {
       
   700             fieldType = fieldTypeList.Find ( R_VPBK_FIELD_TYPE_EMAILGEN );
       
   701             break;
       
   702             }
       
   703         case EValueTypePhoneNumber:
       
   704             {
       
   705             fieldType = fieldTypeList.Find ( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN );
       
   706             break;
       
   707             }
       
   708         default:
       
   709             {
       
   710             break;
       
   711             }
       
   712         }
       
   713 
       
   714     // If field type was found.
       
   715     if ( fieldType )
       
   716         {
       
   717         // Create temporary store contact.
       
   718         MVPbkContactStore& store = LocalContactStoreL();
       
   719         MVPbkStoreContact* storeContact = store.CreateNewContactLC();
       
   720         iStoreContactList.AppendL( storeContact );
       
   721         CleanupStack::Pop(); // codescanner::cleanup
       
   722 
       
   723         // Add link value to field.
       
   724         MVPbkStoreContactField* field =
       
   725                 storeContact->CreateFieldLC ( *fieldType );
       
   726         MVPbkContactFieldTextData::Cast(field->FieldData()).SetTextL(*iValue);
       
   727         storeContact->AddFieldL( field );
       
   728         CleanupStack::Pop( field );
       
   729 
       
   730         // Add link value to first name too.
       
   731         // Otherwise t.ex send multimedia shows contact as 'unnamed'.
       
   732         fieldType = fieldTypeList.Find( R_VPBK_FIELD_TYPE_FIRSTNAME );
       
   733         if ( fieldType )
       
   734             {
       
   735             field = storeContact->CreateFieldLC( *fieldType );
       
   736             MVPbkContactFieldTextData::Cast( 
       
   737             		field->FieldData() ).SetTextL( *iValue );
       
   738             storeContact->AddFieldL( field );
       
   739             CleanupStack::Pop( field );
       
   740             }
       
   741 
       
   742         // Set contact set for contact action service.
       
   743         iContactActionService->SetContactSetL( iStoreContactList );
       
   744         // Initiate query actions, returns to QueryActionsComplete.
       
   745         iContactActionService->QueryActionsL( this );
       
   746         }
       
   747     }
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // CESMRContactMenuHandler::LocalContactStoreL( )
       
   751 // ---------------------------------------------------------------------------
       
   752 //
       
   753 MVPbkContactStore& CESMRContactMenuHandler::LocalContactStoreL( )
       
   754     {
       
   755     FUNC_LOG;
       
   756     CVPbkContactManager& contactManager =
       
   757             iContactManagerHandler.GetContactManager();
       
   758 
       
   759     // Search for local contact store.
       
   760     MVPbkContactStoreList& storeList = contactManager.ContactStoresL();
       
   761     const TInt count(storeList.Count());
       
   762     for ( TInt i = 0; i< count; ++i )
       
   763         {
       
   764         MVPbkContactStore& store = storeList.At( i );
       
   765         if ( store.StoreProperties().Local() )
       
   766             {
       
   767             return store;
       
   768             }
       
   769         }
       
   770     // Leave if not found.
       
   771     User::Leave ( KErrNotFound );
       
   772     // Disables warning.
       
   773     MVPbkContactStore* null = NULL;
       
   774     return *null;
       
   775     }
       
   776 
       
   777 // EOF
       
   778