mmsengine/genutils/src/mmsgenutils.cpp
changeset 23 238255e8b033
parent 0 72b543305e3a
child 47 5b14749788d7
child 60 7fdbb852d323
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
    26 
    26 
    27 // INCLUDE FILES
    27 // INCLUDE FILES
    28 #include <barsc.h>               // resource file
    28 #include <barsc.h>               // resource file
    29 #include <bautils.h>
    29 #include <bautils.h>
    30 #include <miutpars.h>            // e-mail utilities
    30 #include <miutpars.h>            // e-mail utilities
    31 
    31 #include "cimconvertcharconv.h"
       
    32 #include "cimconvertheader.h"
    32 #include <miutconv.h>            // CharConv 
    33 #include <miutconv.h>            // CharConv 
    33 #include <flogger.h>
    34 #include <flogger.h>
    34 #include <e32svr.h>
    35 #include <e32svr.h>
    35 #include <e32base.h>
    36 #include <e32base.h>
    36 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    37 #include <imcvcodc.h>
    37 #include <imcvcodc.h>
    38 #else
       
    39 #include <imcvcodc.h>
       
    40 #include <cimconvertheader.h>
       
    41 #endif
       
    42 #include <f32file.h>                 
    38 #include <f32file.h>                 
    43 #include <UiklafInternalCRKeys.h>
    39 #include <UiklafInternalCRKeys.h>
    44 #include <telconfigcrkeys.h>
    40 // #include <telconfigcrkeys.h>
    45 #include <centralrepository.h>
    41 #include <centralrepository.h>
    46 #include <CoreApplicationUIsSDKCRKeys.h>
    42 #include <CoreApplicationUIsSDKCRKeys.h>
    47 #include <data_caging_path_literals.hrh>
    43 #include <data_caging_path_literals.hrh>
    48 
    44 
    49 #include <MVPbkContactStore.h>
    45 
    50 #include <MVPbkContactStoreProperties.h>
    46 #include "telconfigcrkeys.h"
    51 #include <MVPbkContactLink.h>
       
    52 #include <CPbk2StoreConfiguration.h>   // Contact store configuration
       
    53 #include <contactmatcher.h> // contact match wrapper
       
    54 #include <CVPbkPhoneNumberMatchStrategy.h>
       
    55 #include <CVPbkContactLinkArray.h>
       
    56 #include <CVPbkFieldTypeRefsList.h>
       
    57 #include <TVPbkFieldVersitProperty.h>
       
    58 #include <VPbkFieldType.hrh>
       
    59 #include <MVPbkStoreContactFieldCollection.h>
       
    60 #include <MVPbkStoreContact.h>
       
    61 #include <CVPbkContactStoreUriArray.h>
       
    62 #include <VPbkContactStoreUris.h>
       
    63 #include <TVPbkContactStoreUriPtr.h>
       
    64 #include "mmsgenutils.h"
    47 #include "mmsgenutils.h"
    65 #include "MmsEnginePrivateCRKeys.h"
    48 #include "MmsEnginePrivateCRKeys.h"
    66 
    49 
    67 // EXTERNAL DATA STRUCTURES
    50 // EXTERNAL DATA STRUCTURES
    68 
    51 
    69 // EXTERNAL FUNCTION PROTOTYPES  
    52 // EXTERNAL FUNCTION PROTOTYPES  
    70 
    53 
    71 // CONSTANTS
    54 // CONSTANTS
       
    55 
       
    56 #ifdef _DEBUG
    72 const TInt KLogBufferLength = 256;
    57 const TInt KLogBufferLength = 256;
    73 #ifdef _DEBUG
       
    74 _LIT( KLogDir, "mmsc" );
    58 _LIT( KLogDir, "mmsc" );
    75 _LIT( KLogFile, "mmsc.txt" );
    59 _LIT( KLogFile, "mmsc.txt" );
    76 #endif
    60 #endif
    77 const TUint KMinAliasMaxLength = 14;
    61 
    78 const TUint KExtraSpaceForConversion10 = 10;
    62 const TUint KExtraSpaceForConversion10 = 10;
    79 const TUint KExtraSpaceForConversion30 = 30;
    63 const TUint KExtraSpaceForConversion30 = 30;
    80 
    64 
    81 const TInt KErrMultipleMatchFound = KErrGeneral;
    65 
    82 // MACROS
    66 // MACROS
    83 
    67 
    84 // LOCAL CONSTANTS AND MACROS
    68 // LOCAL CONSTANTS AND MACROS
    85 
    69 
    86 // MODULE DATA STRUCTURES
    70 // MODULE DATA STRUCTURES
   433 // ---------------------------------------------------------
   417 // ---------------------------------------------------------
   434 // TMmsGenUtils::GetAlias
   418 // TMmsGenUtils::GetAlias
   435 // ---------------------------------------------------------
   419 // ---------------------------------------------------------
   436 //
   420 //
   437 EXPORT_C TInt TMmsGenUtils::GetAlias( 
   421 EXPORT_C TInt TMmsGenUtils::GetAlias( 
   438     const TDesC& aAddress,
   422     const TDesC& /*aAddress*/,
   439     TDes& aAlias,
   423     TDes& /*aAlias*/,
   440     TInt aMaxLength,
   424     TInt /*aMaxLength*/,
   441     RFs& aFs )
   425     RFs& /*aFs*/ )
   442     {
   426     {
   443     TInt err = KErrNone;
   427     return KErrNone;
   444     TRAP( err, DoGetAliasL( aFs, aAddress, aAlias, aMaxLength ) );
       
   445     if ( err == KErrNotFound )
       
   446         {
       
   447         err = KErrNone;
       
   448         }
       
   449     return err;
       
   450     }
   428     }
   451 
   429 
   452     
   430     
   453 // ---------------------------------------------------------
   431 // ---------------------------------------------------------
   454 // TMmsGenUtils::GetAliasForAllL
   432 // TMmsGenUtils::GetAliasForAllL
   457 // addresses. This significantly reduces processing time 
   435 // addresses. This significantly reduces processing time 
   458 // when executing "Create Reply to all" with a lot of addresses
   436 // when executing "Create Reply to all" with a lot of addresses
   459 // ---------------------------------------------------------
   437 // ---------------------------------------------------------
   460 // 
   438 // 
   461 EXPORT_C void TMmsGenUtils::GetAliasForAllL(
   439 EXPORT_C void TMmsGenUtils::GetAliasForAllL(
   462     const CDesCArray& aAddress,
   440     const CDesCArray& /*aAddress*/,
   463     CDesCArray& aAlias,
   441     CDesCArray& /*aAlias*/,
   464     TInt aMaxLength,
   442     TInt /*aMaxLength*/,
   465     RFs& aFs )
   443     RFs& /*aFs*/ )
   466     {
   444     {
   467     
   445     
   468     if ( aMaxLength <= 0 )
   446   
   469         {
       
   470         User::Leave( KErrArgument );
       
   471         }
       
   472     
       
   473     TUint stack = 0;
       
   474 
       
   475     //Let's find the number of digits to match
       
   476     TInt digitsToMatch = DigitsToMatch();
       
   477     TInt err = KErrNone;
       
   478     
       
   479     // Use contact wrapper to open all databases
       
   480     CContactMatcher* contactMatcher = OpenAllStoresL( aFs );
       
   481     CleanupStack::PushL( contactMatcher );
       
   482     stack++;
       
   483     
       
   484     HBufC* helpBuffer = HBufC::NewL( aMaxLength );
       
   485     CleanupStack::PushL( helpBuffer );
       
   486     stack++; 
       
   487        
       
   488     TPtr pHelpBuffer = helpBuffer->Des();   
       
   489    
       
   490     for ( TInt i = 0; i < aAddress.MdcaCount(); i++  )
       
   491         {  
       
   492         // We trap these one by one in order to be able
       
   493         // to continue to next match in case of error (not found)
       
   494         
       
   495         // make sure the alias is empty if nothing found
       
   496         pHelpBuffer.Zero();
       
   497         
       
   498     	TRAP( err, DoGetAliasL( 
       
   499             aAddress.MdcaPoint(i), 
       
   500     	    pHelpBuffer, 
       
   501     	    aMaxLength, 
       
   502     	    *contactMatcher, 
       
   503     	    digitsToMatch ) );
       
   504 
       
   505         // if alias is not found, we'll have an empty buffer
       
   506         // We have to insert it anyway to keep the indexes correct
       
   507         // as we have two parallel arrays
       
   508         aAlias.InsertL( i, pHelpBuffer );
       
   509         }
       
   510         
       
   511     // closing is best effort only.    
       
   512     TRAP_IGNORE( contactMatcher->CloseStoresL() );
       
   513     CleanupStack::PopAndDestroy( stack, contactMatcher );  //contactMatcher, helpBuffer   
       
   514     
       
   515     }
   447     }
   516 
   448 
   517 // ---------------------------------------------------------
   449 // ---------------------------------------------------------
   518 // TMmsGenUtils::GenerateAddress
   450 // TMmsGenUtils::GenerateAddress
   519 // ---------------------------------------------------------
   451 // ---------------------------------------------------------
   802 // ---------------------------------------------------------
   734 // ---------------------------------------------------------
   803 // TMmsGenUtils::DoGetAliasL
   735 // TMmsGenUtils::DoGetAliasL
   804 // ---------------------------------------------------------
   736 // ---------------------------------------------------------
   805 //
   737 //
   806 void TMmsGenUtils::DoGetAliasL(
   738 void TMmsGenUtils::DoGetAliasL(
   807     RFs& aFs,
   739     RFs& /*aFs*/,
   808     const TDesC& aAddress, 
   740     const TDesC& /*aAddress*/, 
   809     TDes& aAlias, 
   741     TDes& /*aAlias*/, 
   810     TInt aMaxLength )
   742     TInt /*aMaxLength*/ )
   811     {
   743     {
   812     
   744   
   813     //Let's find the number of digits to match
       
   814     TInt digitsToMatch = DigitsToMatch();
       
   815  
       
   816     // We have only one address and one alias to put into the array
       
   817     CDesCArray* aliasArray = new ( ELeave )CDesCArrayFlat( 1 );
       
   818     CleanupStack::PushL( aliasArray ); 
       
   819 
       
   820     CDesCArray* realAddressArray = new ( ELeave )CDesCArrayFlat( 1 );
       
   821     CleanupStack::PushL( realAddressArray ); 
       
   822 
       
   823     realAddressArray->InsertL( 0, aAddress );
       
   824     
       
   825     // GetAliasForAllL opens contact matcher
       
   826     GetAliasForAllL( *realAddressArray, *aliasArray, aMaxLength, aFs );
       
   827     
       
   828     TInt size = aliasArray->MdcaCount();
       
   829     
       
   830     if ( size > 0 )
       
   831         {
       
   832         // only one item in our array
       
   833         aAlias.Copy( aliasArray->MdcaPoint( 0 ).Left( Min( aMaxLength, aAlias.MaxLength() ) ) );
       
   834         }
       
   835     
       
   836     CleanupStack::PopAndDestroy( realAddressArray );
       
   837     CleanupStack::PopAndDestroy( aliasArray );
       
   838     
       
   839     return;
       
   840     
       
   841     }
   745     }
   842 
   746 
   843 
   747 
   844 // ---------------------------------------------------------
   748 // ---------------------------------------------------------
   845 // TMmsGenUtils::DoGetAliasL
   749 // TMmsGenUtils::DoGetAliasL
   846 // ---------------------------------------------------------
   750 // ---------------------------------------------------------
   847 //
   751 //
   848 void TMmsGenUtils::DoGetAliasL(
   752 void TMmsGenUtils::DoGetAliasL(
   849     const TDesC& aAddress, 
   753     const TDesC& /*aAddress*/, 
   850     TDes& aAlias, 
   754     TDes& /*aAlias*/, 
   851     TInt aMaxLength,
   755     TInt /*aMaxLength*/,
   852     CContactMatcher& aContactMatcher,
   756     CContactMatcher& /*aContactMatcher*/,
   853     TInt aDigitsToMatch  )
   757     TInt /*aDigitsToMatch*/  )
   854     {
   758     {
   855     // It appears that with the new phonebook system with multiple phonebooks,
       
   856     // TContactItemId type id cannot be extracted.
       
   857     // The result contains MVPbkContactLink type objects.
       
   858     
       
   859     // The given descriptor has to be at least 14 in length
       
   860     // (otherwise this method would leave later)
       
   861     if( aAlias.MaxLength() < KMinAliasMaxLength )
       
   862         {
       
   863         User::Leave( KErrBadDescriptor );
       
   864         }
       
   865     
       
   866     // These should be inline with each other, but if necessary,
       
   867     // size down aMaxLength.
       
   868     // aMaxLength, however, can be smaller than the buffer
       
   869     if ( aMaxLength > aAlias.MaxLength() )
       
   870         {
       
   871         aMaxLength = aAlias.MaxLength();
       
   872         }
       
   873 
       
   874     if ( aMaxLength > 0 )
       
   875         {
       
   876         // set length of alias to 0
       
   877         // this can be used to determine if alias was found
       
   878         // contact id not needed or used
       
   879         aAlias.Zero();
       
   880         }
       
   881 
       
   882     // Convert to real address just in case. The address should be pure already,
       
   883     // but we are just being paranoid...
       
   884     
       
   885     TPtrC realAddress;
       
   886     realAddress.Set( PureAddress( aAddress, KSepaOpen, KSepaClose ) );
       
   887     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewL();
       
   888     CleanupStack::PushL( linkArray );
       
   889     
       
   890     // Check if the address is phone number or EMail address
       
   891     if ( IsValidMMSPhoneAddress( realAddress, ETrue ) )
       
   892         {
       
   893         // Lookup the telephone number in the contact database
       
   894         // For numbers shorter than 7 digits, only exact matches are returned
       
   895         
       
   896         aContactMatcher.MatchPhoneNumberL( realAddress, aDigitsToMatch, 
       
   897 	        CVPbkPhoneNumberMatchStrategy::EVPbkMatchFlagsNone, *linkArray );
       
   898 
       
   899         // If more than one matches have been found,
       
   900         // the first one will be used.
       
   901         }
       
   902     else if ( IsValidEmailAddress( realAddress ) )
       
   903         {
       
   904         // Try to match with EMail address
       
   905                 
       
   906         TVPbkFieldVersitProperty prop;
       
   907         CVPbkFieldTypeRefsList* fieldTypes = CVPbkFieldTypeRefsList::NewL();
       
   908         CleanupStack::PushL( fieldTypes );
       
   909         
       
   910         const MVPbkFieldTypeList& fieldTypeList = aContactMatcher.FieldTypes();
       
   911         const MVPbkFieldType* foundType = NULL;
       
   912 
       
   913         prop.SetName( EVPbkVersitNameEMAIL );
       
   914 /*        
       
   915         // Remove code because matching matches properies, too.
       
   916         // We don't care about properties.
       
   917         
       
   918         // The phonebook should provide a function that allows mathcing name only
       
   919         foundType = fieldTypeList.FindMatch( prop, 0 );     
       
   920          
       
   921         if ( foundType )
       
   922             {
       
   923             fieldTypes->AppendL( *foundType );   
       
   924             }
       
   925 */
       
   926            
       
   927         // The field type matching does not work because it tries to match
       
   928         // parameters we are not interested in.
       
   929         // We try to generate a list that has all entries with versit type EMAIL
       
   930         
       
   931         TInt i;
       
   932         for ( i = 0; i < fieldTypeList.FieldTypeCount(); i++ )
       
   933             {
       
   934             foundType = &(fieldTypeList.FieldTypeAt( i ));
       
   935             if ( foundType->VersitProperties().Count() > 0
       
   936                 && foundType->VersitProperties()[0].Name() == prop.Name() )
       
   937                 {
       
   938                 fieldTypes->AppendL( *foundType );
       
   939                 }
       
   940             }
       
   941         
       
   942      
       
   943         // Here we stop at first match - email addresses should be unique
       
   944 		aContactMatcher.MatchDataL( realAddress, *fieldTypes, *linkArray );
       
   945 		CleanupStack::PopAndDestroy( fieldTypes );    
       
   946         }
       
   947     else
       
   948         {
       
   949         User::Leave( KErrNotFound );
       
   950         }
       
   951 
       
   952     TInt nameIndex = 0; //correct index if only one match is found
       
   953     if( linkArray->Count() == 0 )
       
   954         {
       
   955         Log( _L( "No match found" ) );
       
   956         User::Leave( KErrNotFound );        
       
   957         }
       
   958     else if( linkArray->Count() > 1 )
       
   959         {
       
   960         //Multiple matches found. Get the current store single match index if any.
       
   961         nameIndex = GetCurrentStoreIndexL( *linkArray );
       
   962         if( nameIndex == KErrMultipleMatchFound )
       
   963             {
       
   964             /* No unique match in current store, Hence show the name only if all the matches have 
       
   965              * identical names
       
   966              */
       
   967             if( ShowContactNameL( linkArray, nameIndex, aContactMatcher) == EFalse)
       
   968                 {
       
   969                 Log( _L( "No (Perfect) match found" ) );
       
   970                 User::Leave( KErrMultipleMatchFound );
       
   971                 }
       
   972             }
       
   973         }        
       
   974     
       
   975     // if not interested in alias, skip this
       
   976     if ( aMaxLength > 0 )
       
   977         {
       
   978         HBufC* alias = GetContactNameL( linkArray->At(nameIndex), aContactMatcher );
       
   979         if ( alias && alias->Des().Length() > 0 )
       
   980             {
       
   981             aAlias.Copy( alias->Des().Left( aMaxLength ) );
       
   982             }
       
   983         else
       
   984             {
       
   985             aAlias.Copy( TPtrC() );
       
   986             }
       
   987         delete alias;
       
   988         alias = NULL;
       
   989         // end of part skipped if not interested in alias
       
   990         }
       
   991 
       
   992     linkArray->ResetAndDestroy();
       
   993     CleanupStack::PopAndDestroy( linkArray );
       
   994     }
   759     }
   995 
   760 
   996 // ---------------------------------------------------------
   761 // ---------------------------------------------------------
   997 // TMmsGenUtils::ConvertEscapesFromUri
   762 // TMmsGenUtils::ConvertEscapesFromUri
   998 // ---------------------------------------------------------
   763 // ---------------------------------------------------------
  1426     
  1191     
  1427 // ---------------------------------------------------------
  1192 // ---------------------------------------------------------
  1428 // TMmsGenUtils::OpenAllStoresL
  1193 // TMmsGenUtils::OpenAllStoresL
  1429 //
  1194 //
  1430 // ---------------------------------------------------------
  1195 // ---------------------------------------------------------
  1431 CContactMatcher* TMmsGenUtils::OpenAllStoresL( RFs& aFs )
  1196 CContactMatcher* TMmsGenUtils::OpenAllStoresL( RFs& /*aFs*/ )
  1432     {
  1197     {
  1433     // Use contact wrapper to open all databases
  1198     // Use contact wrapper to open all databases
  1434     CContactMatcher* contactMatcher = CContactMatcher::NewL( &aFs );
  1199   /*  CContactMatcher* contactMatcher = CContactMatcher::NewL( &aFs );
  1435     CleanupStack::PushL( contactMatcher );
  1200     CleanupStack::PushL( contactMatcher );
  1436     
  1201     
  1437     contactMatcher->OpenDefaultMatchStoresL();    
  1202     contactMatcher->OpenDefaultMatchStoresL();    
  1438     
  1203     
  1439     CleanupStack::Pop( contactMatcher );
  1204     CleanupStack::Pop( contactMatcher );
  1440     return contactMatcher;
  1205     return contactMatcher;*/
       
  1206     return NULL;
  1441     }
  1207     }
  1442 
  1208 
  1443 // -----------------------------------------------------------------------------
  1209 // -----------------------------------------------------------------------------
  1444 // TMmsGenUtils::GetContactNameL
  1210 // TMmsGenUtils::GetContactNameL
  1445 // -----------------------------------------------------------------------------
  1211 // -----------------------------------------------------------------------------
  1446 //
  1212 //
  1447 HBufC* TMmsGenUtils::GetContactNameL(
  1213 HBufC* TMmsGenUtils::GetContactNameL(
  1448         const MVPbkContactLink& aContactLink,
  1214         const MVPbkContactLink& /*aContactLink*/,
  1449         CContactMatcher &aContactMatcher)
  1215         CContactMatcher& /*aContactMatcher*/)
  1450     {
  1216     {
  1451     Log(_L( "- TMmsGenUtils::GetContactNameL  -> start" ) );
  1217   
  1452     MVPbkStoreContact* tempContact;
  1218     return NULL;
  1453     aContactMatcher.GetStoreContactL(aContactLink, &tempContact);
       
  1454     tempContact->PushL();
       
  1455     
       
  1456     MVPbkStoreContactFieldCollection& coll = tempContact->Fields();
       
  1457     HBufC* nameBuff = aContactMatcher.GetNameL( coll );
       
  1458     
       
  1459     CleanupStack::PopAndDestroy(tempContact); // tempContact
       
  1460     
       
  1461     Log( _L( "- TMmsGenUtils::GetContactNameL <- end" ) );
       
  1462     return nameBuff;
       
  1463     }
  1219     }
  1464 
  1220 
  1465 // -----------------------------------------------------------------------------
  1221 // -----------------------------------------------------------------------------
  1466 // TMmsGenUtils::GetContactNameInLowerCaseL
  1222 // TMmsGenUtils::GetContactNameInLowerCaseL
  1467 // -----------------------------------------------------------------------------
  1223 // -----------------------------------------------------------------------------
  1485 // -----------------------------------------------------------------------------
  1241 // -----------------------------------------------------------------------------
  1486 // TMmsGenUtils::ShowContactNameL
  1242 // TMmsGenUtils::ShowContactNameL
  1487 // -----------------------------------------------------------------------------
  1243 // -----------------------------------------------------------------------------
  1488 //
  1244 //
  1489 TBool TMmsGenUtils::ShowContactNameL(
  1245 TBool TMmsGenUtils::ShowContactNameL(
  1490         CVPbkContactLinkArray* aLinkArray,
  1246         CVPbkContactLinkArray* /*aLinkArray*/,
  1491         TInt &aNameIndex,
  1247         TInt& /*aNameIndex*/,
  1492         CContactMatcher &aContactMatcher)
  1248         CContactMatcher& /*aContactMatcher*/)
  1493     {
  1249     {
  1494     Log( _L("- TMmsGenUtils::ShowContactName -> start") );
  1250     return 0;
  1495     Log( _L("Contact Match statistics to follow..." ) );
       
  1496     Log( _L("Match count: %d"), aLinkArray->Count() );
       
  1497     /* TODO:: compare the names upto standard
       
  1498      * 1. if all the names are same - display the name 
       
  1499      *    eg: "abcdef xyz" && "abcdef xyz"
       
  1500      * 2. find min name legth among all,(if ONLY Part-match is needed )
       
  1501      *    if this length is > standard length and matches upto standard length - display the larger name.
       
  1502      *    eg: abcdef xyz123,  abcdef xyz12, abcdef xyz and std length is 10,
       
  1503      *        since match upto 10 chars is fine, display abcdef xyz123
       
  1504      * 3. in any other case do not show name
       
  1505      *    eg: abcdef xyz , abcde xyz
       
  1506      *        abcdef xyz , abcdef xy
       
  1507      *        abcdef xyz , abcde
       
  1508      */
       
  1509     TInt i, minLength = 999, maxLength = 0, length = 0, maxLengthIndex = 0, stdLength = 14;
       
  1510     TBool retVal = ETrue ;
       
  1511     
       
  1512     for( i = 0 ; i < aLinkArray->Count(); i++ )
       
  1513         {
       
  1514         HBufC* alias = GetContactNameL( aLinkArray->At(i), aContactMatcher );
       
  1515         Log( _L(":-> %s" ), alias->Des().PtrZ());
       
  1516         length = alias->Des().Length();
       
  1517         if(minLength > length)
       
  1518             {
       
  1519             minLength = length;
       
  1520             }
       
  1521         if(maxLength < length)
       
  1522             {
       
  1523             maxLength = length;
       
  1524             maxLengthIndex = i;
       
  1525             }
       
  1526         delete alias;
       
  1527         alias = NULL;
       
  1528         }
       
  1529     
       
  1530     Log( _L( "Contact Lengths: Std Length  : %d\n MinLength   : %d\n MaxLength   : %d\n MaxLen index: %d" ),
       
  1531             stdLength,
       
  1532             minLength,
       
  1533             maxLength,
       
  1534             maxLengthIndex);
       
  1535     
       
  1536     if(minLength != maxLength)
       
  1537         {
       
  1538         //complete length match not possible
       
  1539         retVal = EFalse;
       
  1540         
       
  1541         /* NOTE:
       
  1542          * Uncomment below code if partial length(upto stdLength) match is sufficient, 
       
  1543          * ensure stdLength is correct
       
  1544          */
       
  1545         /*
       
  1546         if(minLength < stdLength)
       
  1547             {
       
  1548             retVal = EFalse;
       
  1549             }
       
  1550         */
       
  1551         }
       
  1552     
       
  1553     if( retVal )
       
  1554         {
       
  1555         TInt ret;
       
  1556         HBufC* longestName = GetContactNameInLowerCaseL( aLinkArray->At(maxLengthIndex), aContactMatcher );
       
  1557         Log( _L( "Longest name:-> %s" ), longestName->Des().PtrZ());
       
  1558         for ( i = 0; i < aLinkArray->Count() && retVal; i++ )
       
  1559             {
       
  1560             HBufC* nameI = GetContactNameInLowerCaseL( aLinkArray->At(i), aContactMatcher );
       
  1561             Log( _L( "compared with -> %s" ), nameI->Des().PtrZ());
       
  1562             ret = longestName->Find(nameI->Des());
       
  1563             if(ret == KErrNotFound || ret != 0)
       
  1564                 {
       
  1565                 Log( _L( "Part/Full Match error/offset: %d" ), ret);
       
  1566                 retVal = EFalse;
       
  1567                 }
       
  1568             delete nameI;
       
  1569             nameI = NULL;
       
  1570            }
       
  1571         delete longestName;
       
  1572         longestName = NULL;
       
  1573         }
       
  1574 
       
  1575     aNameIndex = maxLengthIndex;
       
  1576 
       
  1577     Log( _L( "Final Match result : %d\n Final Match index  : %d" ), retVal, maxLengthIndex);
       
  1578     Log( _L( "- TMmsGenUtils::ShowContactName <- end" ) );
       
  1579     
       
  1580     return retVal;
       
  1581     }
  1251     }
  1582     
  1252     
  1583 // -----------------------------------------------------------------------------
  1253 // -----------------------------------------------------------------------------
  1584 // TMmsGenUtils::GetCurrentStoreIndexL
  1254 // TMmsGenUtils::GetCurrentStoreIndexL
  1585 // -----------------------------------------------------------------------------
  1255 // -----------------------------------------------------------------------------
  1586 //
  1256 //
  1587 TInt TMmsGenUtils::GetCurrentStoreIndexL( CVPbkContactLinkArray& aLinkArray )
  1257 TInt TMmsGenUtils::GetCurrentStoreIndexL( CVPbkContactLinkArray& /*aLinkArray*/ )
  1588     {
  1258     {
  1589     TInt curStoreIndex( KErrMultipleMatchFound );
  1259   
  1590     TInt curStoreMatchCount = 0;
  1260 	return 0;
  1591     RArray<TInt> otherStoreMatchIndices;
       
  1592     CleanupClosePushL( otherStoreMatchIndices );
       
  1593     
       
  1594     //Get the current configured contact store array(s)
       
  1595     CPbk2StoreConfiguration* storeConfiguration = CPbk2StoreConfiguration::NewL();
       
  1596     CleanupStack::PushL( storeConfiguration );
       
  1597     CVPbkContactStoreUriArray* currStoreArray = storeConfiguration->CurrentConfigurationL();
       
  1598     CleanupStack::PopAndDestroy(storeConfiguration);
       
  1599 
       
  1600     if ( currStoreArray )
       
  1601         {
       
  1602         /* Contact's store is compared against user selected stores.
       
  1603          * If contact is from such store, found index is incremented
       
  1604          * else, other store contact indices are populated into array for further use
       
  1605          */
       
  1606         for ( TInt i = 0; i < aLinkArray.Count(); i++ )
       
  1607             {
       
  1608             TVPbkContactStoreUriPtr uri = aLinkArray.At(i).ContactStore().StoreProperties().Uri();
       
  1609             if ( currStoreArray->IsIncluded( uri ) )
       
  1610                 {
       
  1611                 // Set index to found contact and increment the count.
       
  1612                 curStoreIndex = i;
       
  1613                 curStoreMatchCount++;
       
  1614                 }
       
  1615             else
       
  1616                 {
       
  1617                 otherStoreMatchIndices.AppendL(i);
       
  1618                 }
       
  1619             }
       
  1620         
       
  1621         delete currStoreArray;    
       
  1622         if ( curStoreMatchCount > 1)
       
  1623             {
       
  1624             /* Multiple matches found from current user selected store(s) 
       
  1625              * Delete match from other stores in aLinkArray. New aLinkArray should only contain 
       
  1626              * current store contact matches, so that next level pruning can be done(e.g, names can be 
       
  1627              * compared and displayed if they are identical).
       
  1628              */
       
  1629             for(TInt i = otherStoreMatchIndices.Count() - 1; i >= 0; i--)
       
  1630                 {
       
  1631                 aLinkArray.Delete( otherStoreMatchIndices[i] );
       
  1632                 }
       
  1633             curStoreIndex = KErrMultipleMatchFound;
       
  1634             }
       
  1635         }
       
  1636     CleanupStack::PopAndDestroy( &otherStoreMatchIndices );
       
  1637     return curStoreIndex;
       
  1638     }
  1261     }
  1639 
  1262 
  1640 // ================= OTHER EXPORTED FUNCTIONS ==============
  1263 // ================= OTHER EXPORTED FUNCTIONS ==============
  1641 
  1264 
  1642 //  End of File  
  1265 //  End of File