phoneengine/contacthandling/src/cpecontactmatch.cpp
changeset 0 5f000ab63145
child 22 94dc1107e8b2
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  This module contains the implementation of CPEContactMatch class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cpecontacthandling.h"
       
    21 #include "cpecontactmatch.h"
       
    22 #include <cphonecntfactory.h>
       
    23 #include <cphcntmatcher.h>
       
    24 #include <cphcntspeeddialmonitor.h>
       
    25 #include <cphcntthumbnailloader.h>
       
    26 #include <mpeclientinformation.h>
       
    27 #include <mpedatastore.h>
       
    28 #include <mphcntmatch.h>
       
    29 #include <mphcntthumbnailloaderobserver.h>
       
    30 #include <pepanic.pan>
       
    31 #include <pevirtualengine.h>
       
    32 #include <talogger.h>
       
    33 #include <telmatchingextension.h>
       
    34 #include <spsettings.h>
       
    35 #include <spdefinitions.h>
       
    36 #include <spproperty.h>
       
    37 #include <spentry.h>
       
    38 #include "cpecontactextensionwrapper.h"
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 // Space - used as a separator between concatenated first and last name
       
    43 _LIT( KPESpace," ");
       
    44 
       
    45 
       
    46 // Contact group array granularity
       
    47 const TInt KPEContactGroupArrayGranularity = 5;
       
    48 // Minimum value of meanigful digits
       
    49 const TInt KMinValueOfMeaningfulDigits = 4;
       
    50 // Maximum value of meanigful digits
       
    51 const TInt KMaxValueOfMeaningfulDigits = 20;
       
    52 
       
    53 
       
    54 // ================= MEMBER FUNCTIONS =======================
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CPEContactMatch::NewL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CPEContactMatch* CPEContactMatch::NewL(
       
    61         CPEContactHandling& aOwner,
       
    62         MPEDataStore& aDataStore
       
    63         )
       
    64     {
       
    65     CPEContactMatch* self = 
       
    66         new ( ELeave ) CPEContactMatch( aOwner, aDataStore );
       
    67 
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     CleanupStack::Pop( self );
       
    71 
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Destructor
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CPEContactMatch::~CPEContactMatch()
       
    80     {
       
    81     delete iSpeedDialCommand;
       
    82     if ( iContactThumbnailLoader && iThumbnailId )
       
    83         {
       
    84       	iContactThumbnailLoader->Cancel( iThumbnailId );
       
    85         }
       
    86     delete iThumbnailImage;
       
    87     delete iContactThumbnailLoader;
       
    88     delete iContactMatcher;
       
    89     delete iContactFactory;
       
    90     
       
    91     iPlugins.ResetAndDestroy();
       
    92     REComSession::FinalClose();
       
    93     iLibrary.Close();
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CPEContactMatch::CreateSingleItemFetchL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CPhCntSingleItemFetch* CPEContactMatch::CreateSingleItemFetchL()
       
   101     {
       
   102     return iContactFactory->CreateSingleItemFetchL();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CPEContactMatch::CreateContactIdL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CPhCntContactId* CPEContactMatch::CreateContactIdL( const TDesC8& aContactId )
       
   110     {  
       
   111     return iContactFactory->CreateContactIdL( aContactId );
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CPEContactMatch::CreateContactIdL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CPhCntContactId* CPEContactMatch::CreateContactIdL(
       
   119     TContactItemId aContactId )
       
   120     {  
       
   121     return iContactFactory->CreateContactIdL( aContactId );
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CPEContactMatch::CPEContactMatch
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CPEContactMatch::CPEContactMatch(
       
   129         CPEContactHandling& aOwner,
       
   130         MPEDataStore& aDataStore )
       
   131         : iOwner( aOwner ), iDataStore( aDataStore )
       
   132     {
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CPEContactMatch::ConstructL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CPEContactMatch::ConstructL()
       
   140     {
       
   141     //Mandatory services for providing contact match functionality
       
   142     TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > RLibrary::Load" );
       
   143     iContactFactory = CreateCntFactoryL();
       
   144     TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > CPhCntFactory::CreateContactMatcherL" );
       
   145     iContactMatcher = iContactFactory->CreateContactMatcherL();
       
   146 
       
   147     //Secondary services that may be enabled on demand
       
   148     ConstructThumbnailLoaderL();
       
   149     ConstructSpeedDialCommandL();
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CPEContactMatch::ConstructThumbnailLoaderL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CPEContactMatch::ConstructThumbnailLoaderL()
       
   157     {
       
   158     if ( !iContactThumbnailLoader )
       
   159         {
       
   160         TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > CPhCntFactory::CreateThumbnailLoaderL" );
       
   161         iContactThumbnailLoader = iContactFactory->CreateThumbnailLoaderL( *this );
       
   162         }
       
   163     else
       
   164         {
       
   165         TEFLOGSTRING( KTAERROR,
       
   166             "CNT CPECONTACTMATCH::CONSTRUCTTHUMBNAILLOADERL ! ALREADY EXISTS" );
       
   167         }
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPEContactMatch::ConstructSpeedDialCommandL
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CPEContactMatch::ConstructSpeedDialCommandL()
       
   175     {
       
   176     if ( !iSpeedDialCommand )
       
   177         {
       
   178         TEFLOGSTRING( KTAOBJECT, "CNT CPEContactMatch::ConstructL > CPhCntFactory::CreateSpeedDialMonitorL" );
       
   179         iSpeedDialCommand = iContactFactory->CreateSpeedDialMonitorL();
       
   180         }
       
   181     else
       
   182         {
       
   183         TEFLOGSTRING( KTAERROR,
       
   184             "CNT CPECONTACTMATCH::CONSTRUCTSPEEDDIALCOMMANDL ! ALREADY EXISTS" );
       
   185         }
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CPEContactMatch::MatchWithContactIdL
       
   190 // Synchronous method for finding contact data specified 
       
   191 // with aContactId.
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CPEContactMatch::MatchWithContactIdL(
       
   195         const TInt aCallId
       
   196         )
       
   197 
       
   198     {
       
   199     TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL" );
       
   200     MPhCntMatch* match( NULL );
       
   201     CPhCntContactId* contactId = NULL;
       
   202     contactId = CreateContactIdL( iDataStore.CallClientInformation( aCallId ).ContactLink() );
       
   203     CleanupStack::PushL( contactId );
       
   204     if ( iDataStore.CallType( aCallId ) == EPECallTypeVoIP )
       
   205         {
       
   206         if ( contactId && contactId->IsValid() )
       
   207             {
       
   208             TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL > CPhCntMatcher::MatchVoipNumber" );
       
   209             // Get contact based on contact id.
       
   210             iContactMatcher->MatchVoipNumber( match, 
       
   211                                               *contactId );
       
   212             }
       
   213         else
       
   214             {
       
   215             User::Leave( KErrArgument );
       
   216             }
       
   217         }
       
   218     else
       
   219         {
       
   220         if ( contactId && contactId->IsValid() )
       
   221             {
       
   222             TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL > CPhCntMatcher::MatchNumber" );
       
   223 	        iContactMatcher->MatchNumber( match, 
       
   224 	                                      iDataStore.RemotePhoneNumber( aCallId ),
       
   225 	                                      *contactId );
       
   226             }
       
   227         else
       
   228             {
       
   229             User::Leave( KErrArgument );
       
   230             }
       
   231         }
       
   232 
       
   233     if ( match != NULL )
       
   234         {
       
   235         TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL, Contact match found" );
       
   236         CopyContactFieldsDataL( *match, aCallId );
       
   237 
       
   238         if ( match->HasThumbnailImage() )
       
   239             {
       
   240             TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithContactIdL, Thumbnail image found" );
       
   241             // Start loading thumbnail for this contact
       
   242             // Error code may be ignored since this is not a critical function
       
   243             iDataStore.SetHasCallerThumbnail( ETrue, aCallId );
       
   244             LoadThumbnail( iDataStore.ContactId( aCallId ), aCallId );
       
   245             }
       
   246         match->Release();
       
   247         match = NULL;
       
   248         }
       
   249     CleanupStack::PopAndDestroy( contactId ); //contactId 
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CPEContactMatch::MatchWithNumberL
       
   254 // Synchronous method for finding contact data specified with phone number.
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CPEContactMatch::MatchWithNumberL(
       
   258         const TInt aCallId
       
   259         )
       
   260     {
       
   261     MPhCntMatch* match( NULL );
       
   262     RBuf remoteParty;
       
   263     remoteParty.CleanupClosePushL();
       
   264 
       
   265     if ( iDataStore.CallType( aCallId ) == EPECallTypeVoIP )
       
   266         {
       
   267         TEFLOGSTRING2( KTAINT, "CNT CPEContactMatch::MatchWithNumberL > CPhCntMatcher::MatchVoipNumber, call id: %d", aCallId );
       
   268         MatchWithVoipAdressL( aCallId, match, remoteParty );
       
   269         
       
   270         }
       
   271     else
       
   272         {
       
   273         TPEPhoneNumber remoteNumber = iDataStore.RemotePhoneNumber( aCallId );
       
   274         
       
   275         TEFLOGSTRING3( KTAINT, "CNT CPEContactMatch::MatchWithNumberL > CPhCntMatcher::MatchNumber, number: %S, call id: %d",
       
   276             &remoteNumber, aCallId );
       
   277         iContactMatcher->MatchNumber( match, remoteNumber );
       
   278         }
       
   279 
       
   280     if ( match != NULL )
       
   281         {
       
   282         TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithNumberL, Contact match found" );
       
   283         CopyContactFieldsDataL( *match, aCallId );
       
   284 
       
   285         if ( match->HasThumbnailImage() )
       
   286             {
       
   287             TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithNumberL, Thumbnail image found" );
       
   288             // Start loading thumbnail for this contact
       
   289             // Error code may be ignored since this is not a critical function
       
   290             iDataStore.SetHasCallerThumbnail( ETrue, aCallId );
       
   291             LoadThumbnail( iDataStore.ContactId( aCallId ), aCallId );
       
   292             }
       
   293         match->Release();
       
   294         match = NULL;
       
   295         }
       
   296     else if ( 0 < remoteParty.Length() )
       
   297         {
       
   298         TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::MatchWithNumberL, Set plugins remote name" );
       
   299         // Match not found, set plugins remote party name.
       
   300         // Make sure that length of the remote name is not too long.
       
   301         iDataStore.SetRemoteName( remoteParty.Left( 
       
   302                                     Min( KCntMaxTextFieldLength, remoteParty.Length() ) ), 
       
   303                                   aCallId );
       
   304         }
       
   305 
       
   306     CleanupStack::PopAndDestroy( &remoteParty );
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CPEContactMatch::LoadThumbnail
       
   311 // ---------------------------------------------------------
       
   312 //
       
   313 TInt CPEContactMatch::LoadThumbnail(
       
   314         const CPhCntContactId& aContactId,
       
   315         const TInt aCallId )
       
   316     {
       
   317     // use call id for identifying which thumbnail is loaded
       
   318     // Increment it because zero is invalid value for the id
       
   319     TInt thumbnailId = aCallId + 1;
       
   320     iThumbnailId =
       
   321         reinterpret_cast< CPhCntThumbnailLoader::TThumbnailId > ( thumbnailId );
       
   322 
       
   323     TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::LoadThumbnail > CPhCntThumbnailLoader::Load" );
       
   324     return iContactThumbnailLoader->Load( iThumbnailId, aContactId );
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CPEContactMatch::MpctloThumbnailLoaded
       
   329 // ---------------------------------------------------------
       
   330 //
       
   331 void CPEContactMatch::MpctloThumbnailLoaded(
       
   332         CPhCntThumbnailLoader::TThumbnailId aId,
       
   333         TInt aResult, 
       
   334         CFbsBitmap* aBitmap )
       
   335     {
       
   336     // Operation complete
       
   337     // Reset id to indicate that no thumbnail loading is in progress
       
   338     iThumbnailId = KPhCntThumbnailNullId;
       
   339 
       
   340     if ( aResult == KErrNone )
       
   341         {
       
   342         iThumbnailImage = aBitmap;
       
   343 
       
   344         // Decrement call id, see LoadThumbnail() for reason
       
   345         TInt thumbnailId = ( reinterpret_cast< TInt >( aId ) ) - 1;
       
   346 
       
   347         iOwner.SendMessage( MEngineMonitor::EPEMessageThumbnailLoadingCompleted, thumbnailId );
       
   348         }
       
   349     else
       
   350         {
       
   351         TEFLOGSTRING( KTAERROR,
       
   352             "CNT CPECONTACTMATCH::MPCTLOTHUMBNAILLOADED ! ERROR LOADING THUMBNAIL" );
       
   353         iOwner.SendErrorMessage( aResult );
       
   354         }
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------
       
   358 // CPEContactMatch::ContactThumbnail
       
   359 // Returns contact thumbnail image, NULL if not found
       
   360 // ---------------------------------------------------------
       
   361 //
       
   362 CFbsBitmap* CPEContactMatch::ContactThumbnail()
       
   363     {
       
   364     if ( !iThumbnailImage )
       
   365         {
       
   366         return NULL;
       
   367         }
       
   368     CFbsBitmap* returnedThumbnailImage( iThumbnailImage );
       
   369     iThumbnailImage = NULL; // Ownership is passed to caller
       
   370 
       
   371     return returnedThumbnailImage;
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CPEContactMatch::CopyContactFieldsDataL
       
   376 // Copies contact information to remote info struct
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CPEContactMatch::CopyContactFieldsDataL(
       
   380         const MPhCntMatch& aMatch,
       
   381         const TInt aCallId
       
   382         )
       
   383     {
       
   384     TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL: start" );
       
   385 
       
   386     // Set ringing tone's filename
       
   387     iDataStore.SetPersonalRingingTone( aMatch.PersonalRingingTone(), aCallId );
       
   388 
       
   389     // Set name
       
   390     // The following logic determines if one of the languages that require
       
   391     // swapping of first/last name order is selected and performs the operation.
       
   392     HBufC* lastname( NULL );
       
   393     HBufC* firstname( NULL );
       
   394 
       
   395     if ( aMatch.LastName().Length() > 0 )
       
   396         {
       
   397         TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, alloc last name" );
       
   398         lastname = aMatch.LastName().Alloc();
       
   399         }
       
   400     if ( aMatch.FirstName().Length() > 0 )
       
   401         {
       
   402         TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, alloc first name" );
       
   403         firstname = aMatch.FirstName().Alloc();
       
   404         }
       
   405 
       
   406     if ( ( lastname ) && ( firstname ) )
       
   407         {
       
   408         //Swap name order, if required by the current language setting
       
   409         const TLanguage language = User::Language();
       
   410     
       
   411         for ( TInt index = 0; index < KPENumberOfSwappedLanguages; index++ )
       
   412             {
       
   413             if ( KPESwappedLanguages[index] == language )
       
   414                 {
       
   415                 HBufC* tempfirstname( firstname );
       
   416                 firstname = lastname;
       
   417                 lastname = tempfirstname;
       
   418                 break;
       
   419                 }
       
   420             }
       
   421         }
       
   422 
       
   423     TPEContactName finalName;
       
   424     // Parse name by concatenating lastname and firstname
       
   425     if ( firstname )
       
   426         {
       
   427         finalName = *firstname;
       
   428         if ( finalName.Length() < KCntMaxTextFieldLength && lastname )
       
   429             {
       
   430             TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with space" );
       
   431             finalName.Append( KPESpace );
       
   432             }
       
   433         delete firstname;
       
   434         firstname = NULL;
       
   435         }
       
   436     if ( lastname )
       
   437         {
       
   438         if ( finalName.Length() < KCntMaxTextFieldLength )
       
   439             {
       
   440             // Check how long last name can be added to the iName string. 
       
   441             TInt lastNameMaxLength = KCntMaxTextFieldLength - finalName.Length();
       
   442             if ( lastname->Length() > lastNameMaxLength )
       
   443                 {
       
   444                 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with part of last name" );
       
   445                 // Cut extra chars from the string.
       
   446                 finalName.Append( lastname->Left( lastNameMaxLength ) );          
       
   447                 }
       
   448             else 
       
   449                 {
       
   450                 TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL, append with last name" );
       
   451                 finalName.Append( *lastname );
       
   452                 }
       
   453             }
       
   454         delete lastname;
       
   455         lastname = NULL;
       
   456         }
       
   457         
       
   458     // Replace paragraph separator with space character
       
   459     const TText ps(0x2029);
       
   460 
       
   461     while ( finalName.Locate( ps ) != KErrNotFound )
       
   462         {
       
   463         finalName[ finalName.Locate( ps )] = ' ';
       
   464         }
       
   465 
       
   466     iDataStore.SetRemoteName( finalName, aCallId );
       
   467 
       
   468     iDataStore.SetRemoteTextToSpeechText( aMatch.TextToSpeechTextL(), aCallId );
       
   469 
       
   470     if ( aMatch.Number().Length() > 0 )
       
   471         {
       
   472         iDataStore.SetRemotePhoneNumber( aMatch.Number(), aCallId );    
       
   473         }   
       
   474 
       
   475     TInt phcntfinderNumberType = aMatch.NumberType();
       
   476             
       
   477     switch ( phcntfinderNumberType )
       
   478         {
       
   479         case MPhCntMatch::EMobileNumber:
       
   480             iDataStore.SetRemotePhoneNumberType( EPEMobileNumber, aCallId );
       
   481             break;
       
   482         case MPhCntMatch::EStandardNumber:
       
   483             iDataStore.SetRemotePhoneNumberType( EPETelephoneNumber, aCallId );
       
   484             break;
       
   485         case MPhCntMatch::EFaxNumber:
       
   486             iDataStore.SetRemotePhoneNumberType( EPEFaxNumber, aCallId );
       
   487             break;
       
   488         case MPhCntMatch::EPagerNumber:
       
   489             iDataStore.SetRemotePhoneNumberType( EPEPager, aCallId );
       
   490             break;
       
   491         case MPhCntMatch::EVoipNumber:
       
   492             iDataStore.SetRemotePhoneNumberType( EPEVoipNumber, aCallId );
       
   493             break;
       
   494         case MPhCntMatch::EVideoNumber:
       
   495             iDataStore.SetRemotePhoneNumberType( EPEVideoNumber, aCallId );
       
   496             break;        
       
   497         case MPhCntMatch::EAssistantNumber:
       
   498             iDataStore.SetRemotePhoneNumberType( EPEAssistantNumber, aCallId );
       
   499             break;        
       
   500         case MPhCntMatch::ECarNumber:
       
   501             iDataStore.SetRemotePhoneNumberType( EPECarNumber, aCallId );
       
   502             break;        
       
   503         case MPhCntMatch::EHomeNumber:
       
   504             iDataStore.SetRemotePhoneNumberType( EPEHomeNumber, aCallId );
       
   505             break;        
       
   506         case MPhCntMatch::EWorkNumber:
       
   507             iDataStore.SetRemotePhoneNumberType( EPEWorkNumber, aCallId );
       
   508             break;        
       
   509         case MPhCntMatch::ENone: // fall through
       
   510         default:
       
   511             iDataStore.SetRemotePhoneNumberType( EPEUnknownNumber, aCallId );
       
   512             break;
       
   513         }
       
   514 
       
   515     // Replace paragraph separator with space character
       
   516     TPEContactName companyName;
       
   517     companyName = aMatch.CompanyName();
       
   518     while ( companyName.Locate( ps ) != KErrNotFound )
       
   519         {
       
   520         companyName[ companyName.Locate( ps )] = ' ';
       
   521         }
       
   522     // Set Company name
       
   523     iDataStore.SetRemoteCompanyName( companyName, aCallId );
       
   524 
       
   525     // Set Call text
       
   526     iDataStore.SetCallerText( aMatch.CallText(), aCallId );
       
   527 
       
   528     // Set Call image
       
   529     iDataStore.SetCallerImage( aMatch.CallImage(), aCallId );
       
   530     
       
   531     // Set Contact ID
       
   532     iDataStore.SetContactId( aMatch.ContactId()->CloneL(), aCallId );
       
   533 
       
   534     CArrayFixFlat< TContactItemId >* groupList
       
   535         = new ( ELeave ) CArrayFixFlat< TContactItemId >
       
   536         ( KPEContactGroupArrayGranularity );
       
   537  
       
   538     TArray<TContactItemId> alertFor = iDataStore.AlertForGroup();
       
   539     const TInt groupLength = alertFor.Count();
       
   540     for ( TInt i = 0; i < groupLength; i++ ) 
       
   541         {
       
   542         groupList->AppendL( alertFor[ i ] );
       
   543         }
       
   544    
       
   545     if ( aMatch.BelongsToGroups( *groupList ) )
       
   546         {
       
   547         // Convert array type here to ease further handling
       
   548         TArray<TContactItemId> list = groupList->Array();
       
   549         // Set group information
       
   550         iDataStore.SetContactGroups( list, aCallId );
       
   551         }
       
   552     delete groupList;
       
   553     groupList = NULL;
       
   554     
       
   555     // Set dtmf array
       
   556     iDataStore.SetPredefinedDtmfStrings( aMatch.AllDtmfNumbers(), aCallId );
       
   557     TEFLOGSTRING( KTAINT, "CNT CPEContactMatch::CopyContactFieldsDataL: complete" );  
       
   558     }
       
   559 
       
   560 // -----------------------------------------------------------------------------
       
   561 // CPEContactMatch::GetSpeedDialLocationL
       
   562 // Get's phone number from given location.
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 void CPEContactMatch::GetSpeedDialLocationL( 
       
   566     TInt aLocationIndex, 
       
   567     TPEPhoneNumber& aNumber )
       
   568     {
       
   569     iSpeedDialCommand->GetSpeedDialFieldL( aLocationIndex, aNumber);
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------
       
   573 // CPEContactMatch::ResolveImplementationUidL
       
   574 // -----------------------------------------------------------
       
   575 //
       
   576 TUid CPEContactMatch::ResolveServicesImplementationUidL( TUint32 aServiceId )
       
   577     {
       
   578     TEFLOGSTRING2( KTAINT, "CNT CPEContactMatch::ResolveService > aServiceId: %d", aServiceId );   
       
   579     TUid implUid = {0};
       
   580     
       
   581     CSPEntry* entry = CSPEntry::NewLC();
       
   582     CSPSettings* spSettings = CSPSettings::NewLC(); 
       
   583     
       
   584     User::LeaveIfError(
       
   585         spSettings->FindEntryL( aServiceId, *entry ) ); 
       
   586 
       
   587     CleanupStack::PopAndDestroy( spSettings ); 
       
   588 
       
   589     const CSPProperty* property = NULL;
       
   590     User::LeaveIfError( entry->GetProperty( property, EPropertyCLIPluginId ) );
       
   591     
       
   592     if ( property ) 
       
   593         {
       
   594         TInt temp(0);
       
   595         User::LeaveIfError( property->GetValue( temp ) );
       
   596         implUid.iUid = temp;
       
   597         }
       
   598     else
       
   599         {
       
   600         User::Leave( KErrNotFound );
       
   601         }
       
   602 
       
   603     CleanupStack::PopAndDestroy( entry );
       
   604     return implUid;
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------
       
   608 // CPEContactMatch::MatchWithVoipAdressL
       
   609 // -----------------------------------------------------------
       
   610 //
       
   611 void CPEContactMatch::MatchWithVoipAdressL( 
       
   612     const TInt aCallId, 
       
   613     MPhCntMatch*& aMatch, 
       
   614     RBuf& aRemotePartyName )
       
   615     {
       
   616     TEFLOGSTRING2( KTAINT, 
       
   617         "CNT CPEContactMatch::MatchWithVoipAdressL, CALL ID: %d", aCallId )
       
   618     
       
   619     aRemotePartyName.Close();
       
   620     TRAPD( result, MatchWithVoipAddressUsingExtensionL( 
       
   621         aCallId, aMatch, aRemotePartyName ) );
       
   622     if ( KErrNone != result )
       
   623         {
       
   624         TEFLOGSTRING2( KTAINT, 
       
   625             "CNT CPEContactMatch::MatchWithVoipAdressL > PLUGIN ERR: %d", result )
       
   626             
       
   627         // Some error happened while using extension plugin.
       
   628         // -> Default matching is used.
       
   629             
       
   630         // Try to find store uris that should be opened before contact match.    
       
   631         CDesCArray* storeUris = NULL; 
       
   632         TRAP_IGNORE( storeUris = StoreUrisForServiceL( 
       
   633                 iDataStore.ServiceId( aCallId )) );
       
   634         
       
   635         TPEPhoneNumber remoteNumber = iDataStore.RemotePhoneNumber( aCallId );
       
   636         iContactMatcher->MatchVoipNumber( 
       
   637             aMatch, remoteNumber, ETrue, storeUris, remoteNumber.Length() );
       
   638         
       
   639         delete storeUris;
       
   640         }
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------
       
   644 // CPEContactMatch::StoreUrisForServiceL
       
   645 // -----------------------------------------------------------
       
   646 //
       
   647 CDesCArray* CPEContactMatch::StoreUrisForServiceL( TUint aServiceId )
       
   648     {	
       
   649     CDesCArray* storeUris = new ( ELeave ) CDesC16ArrayFlat( 1 );
       
   650     CleanupStack::PushL( storeUris );
       
   651     
       
   652     // Get contact store id from Service Table
       
   653     // KSPMaxDesLength from spdefinitions.h
       
   654     HBufC* cntStoreId = HBufC::NewLC( KSPMaxDesLength );
       
   655     CSPSettings* spSettings = CSPSettings::NewLC(); 
       
   656     CSPProperty* property = CSPProperty::NewLC();
       
   657     User::LeaveIfError( spSettings->FindPropertyL( 
       
   658             TServiceId( aServiceId ), 
       
   659             EPropertyContactStoreId, 
       
   660             *property ) );                        
       
   661           
       
   662     TPtr storeUri( cntStoreId->Des() );
       
   663     User::LeaveIfError( property->GetValue( storeUri ) );   
       
   664 
       
   665     storeUris->AppendL( storeUri );
       
   666 
       
   667     CleanupStack::PopAndDestroy( property );
       
   668     CleanupStack::PopAndDestroy( spSettings );     
       
   669     CleanupStack::PopAndDestroy( cntStoreId );
       
   670     CleanupStack::Pop( storeUris );
       
   671 
       
   672     return storeUris;
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------
       
   676 // CPEContactMatch::MatchWithVoipAddressUsingExtensionL
       
   677 // -----------------------------------------------------------
       
   678 //
       
   679 void CPEContactMatch::MatchWithVoipAddressUsingExtensionL( TInt aCallId, 
       
   680         MPhCntMatch*& aMatch, RBuf& aRemotePartyName )
       
   681     {
       
   682     // Create and initialize extension plugin.
       
   683     TUint32 serviceId = iDataStore.ServiceId( aCallId );
       
   684     CTelMatchingExtension& plugin = MatchingExtensionL( serviceId );
       
   685     TPEPhoneNumber remoteNumber = iDataStore.RemotePhoneNumber( aCallId );
       
   686     plugin.InitializeL( serviceId, remoteNumber );
       
   687     
       
   688     // Get service specific parameters from the plugin.
       
   689     User::LeaveIfError( plugin.GetRemotePartyName( aRemotePartyName ) );
       
   690     
       
   691     RBuf parsedAddress;
       
   692     CleanupClosePushL( parsedAddress );
       
   693     TInt digitsformatching( 0 );
       
   694     User::LeaveIfError( plugin.GetAddressForMatching( parsedAddress, digitsformatching ) );
       
   695 
       
   696     CDesCArray* array = new ( ELeave ) CDesC16ArrayFlat( 1 );
       
   697     CleanupStack::PushL( array );
       
   698     User::LeaveIfError( plugin.GetContactStoreUris( *array ) );
       
   699     
       
   700     TEFLOGSTRING2( KTAINT, "CNT Extension Plugin > remoteParty: %S", &aRemotePartyName )
       
   701     TEFLOGSTRING3( KTAINT, "CNT Extension Plugin > parsedAddress: %S , digits: %d",
       
   702         &parsedAddress, digitsformatching )
       
   703     TEFLOGSTRING2( KTAINT, "CNT Extension Plugin > array count: %d", array->MdcaCount() )
       
   704     
       
   705     // Digits for matching. Supported range is between 4-20.
       
   706     // If not valid value use whole address length for matching.
       
   707     digitsformatching = ( digitsformatching < KMinValueOfMeaningfulDigits || 
       
   708                           digitsformatching > KMaxValueOfMeaningfulDigits ) ? 
       
   709                           parsedAddress.Length() : digitsformatching;
       
   710     
       
   711     // Use service specific parameters for matching.
       
   712     TEFLOGSTRING3( KTAINT, "CNT MatchWithVoipAddressUsingExtensionL >\
       
   713         CPhCntMatcher::MatchVoipNumber, NUMBER: %S, CALL ID: %d",
       
   714         &remoteNumber, aCallId )
       
   715     iContactMatcher->MatchVoipNumber( aMatch, 
       
   716         parsedAddress.Left( Min( parsedAddress.Length(), KPEPhoneNumberMaxLength ) ), 
       
   717         ETrue, array, digitsformatching );                                       
       
   718     
       
   719     CleanupStack::PopAndDestroy( array );
       
   720     CleanupStack::PopAndDestroy( &parsedAddress );
       
   721     }
       
   722 
       
   723 
       
   724 // -----------------------------------------------------------
       
   725 // CPEContactMatch::MatchingExtensionL
       
   726 // -----------------------------------------------------------
       
   727 //
       
   728 CTelMatchingExtension& CPEContactMatch::MatchingExtensionL( TUint aServiceId )
       
   729     {
       
   730     TUid pluginUid = ResolveServicesImplementationUidL( aServiceId );
       
   731     
       
   732     CPEContactExtensionWrapper* wrapper = NULL;
       
   733     TInt pluginInd = 
       
   734         iPlugins.Find( pluginUid, CPEContactExtensionWrapper::MatchByUid );
       
   735     if ( KErrNotFound == pluginInd )
       
   736         {
       
   737         wrapper = CPEContactExtensionWrapper::NewLC( pluginUid );
       
   738         iPlugins.AppendL( wrapper );
       
   739         CleanupStack::Pop( wrapper );
       
   740         }
       
   741     else
       
   742         {
       
   743         wrapper = iPlugins[pluginInd];
       
   744         }
       
   745     
       
   746     __ASSERT_ALWAYS( NULL != wrapper, User::Leave( KErrNotFound ) );
       
   747     return *wrapper;
       
   748     }
       
   749 
       
   750 //  End of File