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