predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsCache.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Holds the contact information in memory. It maintains a 
       
    15 *                master array of all contacts. It also has 10 pools corresponding
       
    16 *                to each key id in the keyboard. Based on numeric key char of 
       
    17 *                first char of firstname/ lastname a contact is added to one of the
       
    18 *                pools. Implements MDataStoreObserver interface functions to
       
    19 *                add/ remove contacts.
       
    20 *
       
    21 */
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include <MVPbkContactLink.h>
       
    26 #include <vpbkeng.rsg>
       
    27 #include "CPcsDefs.h"
       
    28 #include "CPsData.h"
       
    29 #include "CPcsCache.h"
       
    30 #include "CPcsDebug.h"
       
    31 #include "CWords.h"
       
    32 #include "CPcsAlgorithm1Utils.h"
       
    33 #include "CPcsAdaptiveGridItem.h"
       
    34 
       
    35 // ============================== MEMBER FUNCTIONS ============================
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CPcsCache::NewL
       
    39 // Two Phase Construction
       
    40 // ----------------------------------------------------------------------------
       
    41 CPcsCache* CPcsCache::NewL(const TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId)
       
    42 {
       
    43     PRINT ( _L("Enter CPcsCache::NewL") );
       
    44     
       
    45 	CPcsCache* instance= new ( ELeave ) CPcsCache();
       
    46 
       
    47 	CleanupStack::PushL( instance );
       
    48 
       
    49 	instance->ConstructL(aURI, aKeyMap, aUriId);
       
    50 
       
    51 	CleanupStack::Pop( instance );
       
    52 
       
    53     PRINT ( _L("End CPcsCache::NewL") );
       
    54 
       
    55 	return instance;    
       
    56 } 
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CPcsCache::CPcsCache
       
    60 // Constructor
       
    61 // ----------------------------------------------------------------------------
       
    62 CPcsCache::CPcsCache()
       
    63 {
       
    64     PRINT ( _L("Enter CPcsCache::CPcsCache") );
       
    65     PRINT ( _L("End CPcsCache::CPcsCache") );
       
    66 }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CPcsCache::ConstructL
       
    70 // 2nd Phase Constructor
       
    71 // ----------------------------------------------------------------------------
       
    72 void CPcsCache::ConstructL(const TDesC& aURI, CPcsKeyMap& aKeyMap, TUint8 aUriId)
       
    73 {
       
    74     PRINT ( _L("Enter CPcsCache::ConstructL") );
       
    75 
       
    76     PRINT2 ( _L("CPcsCache::ConstructL: aURI=%S, aUriId=%d"), &aURI, aUriId);
       
    77     
       
    78     iURI = aURI.AllocL();
       
    79     iUriId = aUriId;
       
    80     //Update the caching status for this cache
       
    81     iCacheStatus = ECachingNotStarted;
       
    82     
       
    83     iKeyMap = &aKeyMap;        
       
    84 
       
    85     // Populate iKeyArr
       
    86     for(TInt i= 0; i <aKeyMap.PoolCount();i++ )
       
    87         {
       
    88         RPointerArray<CPcsPoolElement> *keyMap = new (ELeave) RPointerArray<CPcsPoolElement>(1);
       
    89         iKeyArr.InsertL(keyMap,i);
       
    90         }
       
    91 
       
    92     // Adaptive Grid map
       
    93     if ( iURI->Compare( KVPbkDefaultCntDbURI ) == 0
       
    94             || iURI->Compare( KVPbkSimGlobalAdnURI ) == 0
       
    95             || iURI->Compare( KVPbkSimGlobalFdnURI ) == 0 
       
    96             || iURI->Compare( KVPbkSimGlobalSdnURI ) == 0
       
    97             || iURI->Compare( KVPbkDefaultGrpDbURI ) == 0 )
       
    98         {
       
    99         iAdaptiveGridMap = CPcsAdaptiveGrid::NewL();
       
   100         }
       
   101     
       
   102     PRINT ( _L("End CPcsCache::ConstructL") );
       
   103 }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CPcsCache::~CPcsCache
       
   107 // Destructor
       
   108 // ----------------------------------------------------------------------------
       
   109 CPcsCache::~CPcsCache()
       
   110 {
       
   111     PRINT ( _L("Enter CPcsCache::~CPcsCache") );
       
   112 
       
   113     delete iURI;
       
   114 
       
   115     RemoveAllFromCache(); // cleans up iMasterPool and iCacheInfo
       
   116    
       
   117     iKeyArr.ResetAndDestroy();
       
   118     iDataFields.Reset();
       
   119     iSortOrder.Reset();
       
   120     iIndexOrder.Reset();
       
   121     iMasterPoolBackup.Close();
       
   122 
       
   123     delete iAdaptiveGridMap;
       
   124 
       
   125     PRINT ( _L("End CPcsCache::~CPcsCache") );
       
   126 }
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // CPcsCache::GetContactsForKeyL
       
   130 // Get list of pool elements specific to a pool
       
   131 // ----------------------------------------------------------------------------     
       
   132 void CPcsCache::GetContactsForKeyL(TInt aKeyId, RPointerArray<CPcsPoolElement>& aData)
       
   133     {
       
   134     PRINT ( _L("Enter CPcsCache::GetContactsForKeyL") );
       
   135     CleanupClosePushL( aData );
       
   136     if ( aKeyId >= 0 && aKeyId < iKeyArr.Count() )
       
   137         {
       
   138         const RPointerArray<CPcsPoolElement>& arr = *iKeyArr[aKeyId];
       
   139         for ( TInt i = 0; i < arr.Count(); i++ )
       
   140             {
       
   141             aData.AppendL(arr[i]);
       
   142             }
       
   143         }
       
   144     CleanupStack::Pop();
       
   145     PRINT ( _L("End CPcsCache::GetContactsForKeyL") );
       
   146     }
       
   147 
       
   148 // ----------------------------------------------------------------------------
       
   149 // CPcsCache::GetAllContentsL
       
   150 // Get all data elements in this cache
       
   151 // ----------------------------------------------------------------------------     
       
   152 void CPcsCache::GetAllContentsL(RPointerArray<CPsData>& aData)
       
   153 {
       
   154     PRINT ( _L("Enter CPcsCache::GetAllContentsL") );
       
   155     CleanupClosePushL( aData );	
       
   156 	for ( TInt i = 0; i < iMasterPool.Count(); i++ )
       
   157 	{
       
   158         aData.AppendL(iMasterPool[i]);
       
   159 	}
       
   160 	CleanupStack::Pop();
       
   161 	PRINT ( _L("End CPcsCache::GetAllContentsL") );
       
   162 }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CPcsCache::AddToPool
       
   166 // Adds a contact to cache
       
   167 // ----------------------------------------------------------------------------
       
   168 void CPcsCache::AddToPoolL(TUint64& aPoolMap, CPsData& aData)
       
   169 {
       
   170     // Temp hash to remember the location of pool elements
       
   171     // First TInt  = Pool 
       
   172     // Second TInt = Location in the pool
       
   173     // Required for memory optimization so that more than one pool
       
   174     // element doesn't get added for the same data
       
   175     RHashMap<TInt, TInt> elementHash;
       
   176     CleanupClosePushL( elementHash );
       
   177     TLinearOrder<CPcsPoolElement> rule( CPcsPoolElement::CompareByData );
       
   178 
       
   179     TBool unnamed = ETrue;
       
   180     // Parse thru each data element
       
   181     for ( TInt dataIndex = 0; dataIndex < aData.DataElementCount(); dataIndex++ )
       
   182     {
       
   183         HBufC* dataStr = aData.Data(dataIndex);
       
   184 
       
   185         // Find store all the pool IDs where this contact should be
       
   186 		RArray<TUint> poolIds;
       
   187 		CleanupClosePushL( poolIds );
       
   188 		
       
   189 		// Recover the first character
       
   190 		if ( dataStr && dataStr->Length() != 0 )
       
   191 		{
       
   192 		    // Split the data into words
       
   193 		    CWords* words = CWords::NewLC(*dataStr);
       
   194 
       
   195 		    // Store the first numeric key for each word
       
   196 		    for ( TInt i = 0; i < words->MdcaCount(); i++ )
       
   197 		    {
       
   198 		    	TChar firstChar = (words->MdcaPoint(i))[0];
       
   199 		    	
       
   200 		    	// Pool ID according to ITU-T mappings
       
   201 		    	if ( iKeyMap->IsItutPredictiveAvailable() )
       
   202 		    	    {
       
   203                     TInt itutPoolId = iKeyMap->PoolIdForCharacter(firstChar, EPredictiveItuT);
       
   204                     if ( itutPoolId != KErrNotFound )
       
   205                         {
       
   206                         poolIds.Append(itutPoolId);
       
   207                         }
       
   208 		    	    }
       
   209 		    	
       
   210 		    	// Pool ID according to QWERTY mappings
       
   211                 if ( iKeyMap->IsQwertyPredictiveAvailable() )
       
   212                     {
       
   213                     TInt qwertyPoolId = iKeyMap->PoolIdForCharacter(firstChar, EPredictiveQwerty);
       
   214                     if ( qwertyPoolId != KErrNotFound )
       
   215                         {
       
   216                         poolIds.Append(qwertyPoolId);
       
   217                         }
       
   218                     }
       
   219 
       
   220 #ifdef _DEBUG 
       
   221                 PRINT2 ( _L("CPcsCache::AddToPoolL: iURI=\"%S\", iUriId=%d"), &*iURI, iUriId );
       
   222                 TPtrC16 ptr = words->MdcaPoint(i); 
       
   223                 PRINT5 ( _L("CPcsCache::AddToPoolL: Data[%d]=\"%S\", word=\"%S\", firstChar='%c', Match=%d" ),
       
   224                          dataIndex, &*dataStr, &(ptr), (TUint) firstChar, aData.IsDataMatch(dataIndex) );
       
   225 #endif // _DEBUG
       
   226 
       
   227                 if ( iAdaptiveGridMap )
       
   228                 	{
       
   229 					// Set the 1st char of the word for the Adaptive Grid or
       
   230 					// increment the reference counter
       
   231 					TUint selector = GridItemSelector( dataIndex, unnamed );
       
   232 					iAdaptiveGridMap->IncrementRefCounterL( firstChar, selector );
       
   233                 	}
       
   234 		    }
       
   235 		    
       
   236 		    CleanupStack::PopAndDestroy(words); 
       
   237 		}
       
   238 		
       
   239 		for ( TInt poolIdIndex = 0; poolIdIndex < poolIds.Count(); poolIdIndex++ )
       
   240 		{
       
   241             TUint poolId = poolIds[poolIdIndex];
       
   242 		    CPcsPoolElement* element = NULL;
       
   243 		    
       
   244 		    // Check if an element already exists in the pool for this data
       
   245 		    TInt* loc = NULL;
       
   246 		    loc = elementHash.Find(poolId);
       
   247 		    if ( loc != NULL )
       
   248 		    {
       
   249 		        // Exists. Then recover ...
       
   250 		        const RPointerArray<CPcsPoolElement>& tmpKeyMap = *(iKeyArr[poolId]);
       
   251 		    	element = tmpKeyMap[*loc];
       
   252 		    }
       
   253 		
       
   254 			if ( element == NULL ) // Pool element doesn't exist. Create new ...
       
   255 			{
       
   256 		        element = CPcsPoolElement::NewL(aData);
       
   257 		        CleanupStack::PushL( element );
       
   258 		    	element->ClearDataMatchAttribute();
       
   259 				element->SetDataMatch(dataIndex);
       
   260 				
       
   261 				// Insert to pool
       
   262 				iKeyArr[poolId]->InsertInOrderAllowRepeatsL(element, rule);
       
   263 				CleanupStack::Pop( element ); // ownership transferred
       
   264 				TInt index = iKeyArr[poolId]->FindInOrderL(element, rule);
       
   265 				
       
   266 				// Set the bit for this pool
       
   267 				SetPoolMap(aPoolMap, poolId);
       
   268 				
       
   269 				// Store the array index in the temp hash
       
   270 				elementHash.InsertL(poolId, index);
       
   271 	        }
       
   272 	        else // Pool element exists. Just alter the data match attribute
       
   273 	        {
       
   274 	        	element->SetDataMatch(dataIndex);
       
   275 	        	
       
   276 	            // Set the bit for this pool
       
   277 				SetPoolMap(aPoolMap, poolId);
       
   278 	        }
       
   279 			
       
   280 		} // for 2 loop
       
   281 		
       
   282 		CleanupStack::PopAndDestroy( &poolIds );
       
   283 		
       
   284     } // for 1 loop
       
   285 
       
   286     CleanupStack::PopAndDestroy( &elementHash );
       
   287 }
       
   288 
       
   289 // ---------------------------------------------------------------------
       
   290 // CPcsCache::AddToCacheL
       
   291 // 
       
   292 // ---------------------------------------------------------------------
       
   293 void CPcsCache::AddToCacheL( CPsData& aData )
       
   294 {
       
   295     // Protect against duplicate items getting added
       
   296     if ( iCacheInfo.Find(aData.Id()) != NULL )
       
   297     {
       
   298         return;
       
   299     }
       
   300     
       
   301     // Include this element in the pool
       
   302     TUint64 poolMap = 0;
       
   303     AddToPoolL(poolMap, aData);
       
   304     iCacheInfo.InsertL(aData.Id(), poolMap);
       
   305 
       
   306     // Include this element in master pool
       
   307     TLinearOrder<CPsData> rule( CPcsAlgorithm1Utils::CompareDataBySortOrderL );
       
   308     
       
   309     iMasterPool.InsertInOrderAllowRepeatsL(&aData, rule);
       
   310 }
       
   311 
       
   312 // ---------------------------------------------------------------------
       
   313 // CPcsCache::RemoveContactL
       
   314 // 
       
   315 // ---------------------------------------------------------------------
       
   316 void CPcsCache::RemoveFromCacheL( TInt aItemId )
       
   317 {
       
   318     CPsData* data = NULL;
       
   319     
       
   320     TUint64* poolMap = iCacheInfo.Find(aItemId);
       
   321     
       
   322     if ( poolMap == NULL )
       
   323     {
       
   324     	return;
       
   325     }
       
   326     
       
   327     // Remove this element from pools
       
   328     for ( TInt keyIndex = 0; keyIndex < iKeyArr.Count(); keyIndex++ )
       
   329     {
       
   330         TBool present = GetPoolMap(*poolMap, keyIndex); 
       
   331 
       
   332         if ( !present )
       
   333         {
       
   334         	continue;
       
   335         }
       
   336         
       
   337         TInt arrayIndex = 0;
       
   338         TInt arrayCount = iKeyArr[keyIndex]->Count();
       
   339         while ( arrayIndex < arrayCount )
       
   340         {
       
   341             CPcsPoolElement* element = (*(iKeyArr[keyIndex]))[arrayIndex];
       
   342             if ( element->GetPsData()->Id() == aItemId )
       
   343             {
       
   344                 data = element->GetPsData();
       
   345                 delete element;
       
   346                 iKeyArr[keyIndex]->Remove(arrayIndex);
       
   347                 arrayCount--;
       
   348             }
       
   349             else
       
   350             {
       
   351                 arrayIndex++;
       
   352             }
       
   353         }
       
   354     }
       
   355 
       
   356     // Remove this element from master pool
       
   357     TInt arrayIndex = 0;
       
   358     TInt arrayCount = iMasterPool.Count();
       
   359     while ( arrayIndex < arrayCount )
       
   360     {
       
   361         if ( iMasterPool[arrayIndex]->Id() == aItemId )
       
   362         {
       
   363             iMasterPool.Remove(arrayIndex);
       
   364             arrayCount--;
       
   365         }
       
   366         else
       
   367         {
       
   368             arrayIndex++;
       
   369         }
       
   370     }
       
   371     
       
   372     if ( iAdaptiveGridMap && data )
       
   373     {
       
   374         TBool unnamed = ETrue;
       
   375         // Parse thru each data element
       
   376         for ( TInt dataIndex = 0; dataIndex < data->DataElementCount(); dataIndex++ )
       
   377         {
       
   378             HBufC* dataStr = data->Data(dataIndex);
       
   379     
       
   380             // Recover the first character
       
   381             if ( dataStr && dataStr->Length() != 0 )
       
   382             {
       
   383                 // Split the data into words
       
   384                 CWords* words = CWords::NewLC(*dataStr);
       
   385     
       
   386                 // Store the first numeric key for each word
       
   387                 for ( TInt i = 0; i < words->MdcaCount(); i++ )
       
   388                 {
       
   389                     TChar firstChar = (words->MdcaPoint(i))[0];
       
   390     
       
   391 #ifdef _DEBUG
       
   392                     PRINT2 ( _L("CPcsCache::RemoveFromCacheL: iURI=\"%S\", iUriId=%d"), &*iURI, iUriId );
       
   393                     TPtrC16 ptr = words->MdcaPoint(i); 
       
   394                     PRINT5 ( _L("CPcsCache::RemoveFromCacheL: Data[%d]=\"%S\", word=\"%S\", firstChar='%c', Match=%d" ),
       
   395                              dataIndex, &*dataStr, &(ptr), (TUint) firstChar, data->IsDataMatch(dataIndex) );
       
   396 #endif // _DEBUG   
       
   397                     // Decrement the reference counter of the 1st char of the word for the Adaptive Grid or
       
   398                     // delete the Adaptive Grid item if there are no references to it anymore
       
   399                     TUint selector = GridItemSelector( dataIndex, unnamed );
       
   400                     iAdaptiveGridMap->DecrementRefCounter( firstChar, selector );
       
   401                 }
       
   402                 CleanupStack::PopAndDestroy( words ); 
       
   403             }
       
   404         }
       
   405     }
       
   406 
       
   407     // Delete data 
       
   408     delete data;
       
   409     data = NULL;
       
   410 
       
   411     // Clear up cache information
       
   412     iCacheInfo.Remove(aItemId);
       
   413 }
       
   414 
       
   415 // ---------------------------------------------------------------------
       
   416 // CPcsCache::RemoveAllFromCache
       
   417 // 
       
   418 // ---------------------------------------------------------------------
       
   419 void CPcsCache::RemoveAllFromCache()
       
   420 {
       
   421     PRINT ( _L("Enter CPcsCache::RemoveAllFromCache") );
       
   422     
       
   423     for ( TInt i = 0; i < iKeyArr.Count(); i++ )
       
   424         {
       
   425         iKeyArr[i]->ResetAndDestroy();
       
   426         }
       
   427 	
       
   428 	iMasterPool.ResetAndDestroy();
       
   429 	iCacheInfo.Close();
       
   430 
       
   431 	if ( iAdaptiveGridMap )
       
   432 	    {
       
   433 	    iAdaptiveGridMap->Reset();
       
   434 	    }
       
   435 	
       
   436 	PRINT ( _L("End CPcsCache::RemoveAllFromCache") );
       
   437 }
       
   438 
       
   439 // ---------------------------------------------------------------------
       
   440 // CPcsCache::GetAdaptiveGridL
       
   441 // 
       
   442 // ---------------------------------------------------------------------
       
   443 void CPcsCache::GetAdaptiveGridL( const TBool aCompanyName, TDes& aAdaptiveGrid )
       
   444 {
       
   445     PRINT ( _L("Enter CPcsCache::GetAdaptiveGridL") );
       
   446     
       
   447     if ( iAdaptiveGridMap )
       
   448         {
       
   449         iAdaptiveGridMap->GetAdaptiveGrid( aCompanyName, aAdaptiveGrid );
       
   450         }
       
   451     
       
   452     PRINT ( _L("End CPcsCache::GetAdaptiveGridL") );
       
   453 }
       
   454 
       
   455 // ---------------------------------------------------------------------
       
   456 // CPcsCache::SetPoolMap
       
   457 // 
       
   458 // ---------------------------------------------------------------------
       
   459 void CPcsCache::SetPoolMap(TUint64& aPoolMap, TInt aArrayIndex)
       
   460 {
       
   461     __ASSERT_DEBUG( aArrayIndex < 64, User::Panic(_L("CPcsCache"), KErrOverflow ) );
       
   462 
       
   463     /* Some platforms do not support 64 bits shift operations.
       
   464      * Split to two 32 bits operations.
       
   465      */
       
   466     
       
   467     TUint32 poolMapH = I64HIGH(aPoolMap);
       
   468     TUint32 poolMapL = I64LOW(aPoolMap);
       
   469     
       
   470     TUint32 valH = 0;
       
   471     TUint32 valL = 0;
       
   472     if (aArrayIndex < 32)
       
   473         {
       
   474         valL = 1 << aArrayIndex;
       
   475         }
       
   476     else
       
   477         {
       
   478         valH = 1 << (aArrayIndex-32);
       
   479         }
       
   480 
       
   481     poolMapH |= valH;
       
   482     poolMapL |= valL;
       
   483     
       
   484     aPoolMap = MAKE_TUINT64(poolMapH, poolMapL);
       
   485 }
       
   486 
       
   487 // ---------------------------------------------------------------------
       
   488 // CPcsCache::GetPoolMap
       
   489 // 
       
   490 // ---------------------------------------------------------------------
       
   491 TBool CPcsCache::GetPoolMap(TUint64& aPoolMap, TInt aArrayIndex)
       
   492 {
       
   493     __ASSERT_DEBUG( aArrayIndex < 64, User::Panic(_L("CPcsCache"), KErrOverflow ) );
       
   494 
       
   495     /* Some platforms do not support 64 bits shift operations.
       
   496      * Split to two 32 bits operations.
       
   497      */
       
   498 
       
   499     TUint32 poolMapH = I64HIGH(aPoolMap);
       
   500     TUint32 poolMapL = I64LOW(aPoolMap);
       
   501     
       
   502     TUint32 valH = 0;
       
   503     TUint32 valL = 0;
       
   504     if (aArrayIndex < 32)
       
   505         {
       
   506         valL = 1 << aArrayIndex;
       
   507         }
       
   508     else
       
   509         {
       
   510         valH = 1 << (aArrayIndex-32);
       
   511         }
       
   512 
       
   513     TBool ret = (poolMapH & valH) || (poolMapL & valL);
       
   514 
       
   515     return (ret);
       
   516 }
       
   517 
       
   518 // ---------------------------------------------------------------------
       
   519 // CPcsCache::GetURI
       
   520 // 
       
   521 // ---------------------------------------------------------------------
       
   522 TDesC& CPcsCache::GetURI()
       
   523 {
       
   524 	return (*iURI);
       
   525 }
       
   526 
       
   527 // ---------------------------------------------------------------------
       
   528 // CPcsCache::SetDataFields
       
   529 // 
       
   530 // ---------------------------------------------------------------------
       
   531 void CPcsCache::SetDataFields(RArray<TInt>& aDataFields)
       
   532 {
       
   533 	for (TInt i(0); i < aDataFields.Count(); i++)
       
   534 	{
       
   535 		iDataFields.Append(aDataFields[i]);
       
   536 	}
       
   537 }
       
   538 
       
   539 // ---------------------------------------------------------------------
       
   540 // CPcsCache::GetDataFields
       
   541 // 
       
   542 // ---------------------------------------------------------------------
       
   543 void CPcsCache::GetDataFields(RArray<TInt>& aDataFields)
       
   544 {
       
   545 	for (TInt i(0); i < iDataFields.Count(); i++)
       
   546 	{
       
   547 		aDataFields.Append(iDataFields[i]);
       
   548 	}
       
   549 }
       
   550 
       
   551 // ---------------------------------------------------------------------
       
   552 // CPcsCache::UpdateCacheStatus
       
   553 // 
       
   554 // ---------------------------------------------------------------------
       
   555 void CPcsCache::UpdateCacheStatus(TInt aStatus)
       
   556 {
       
   557 	iCacheStatus = aStatus;
       
   558 }
       
   559 
       
   560 // ---------------------------------------------------------------------
       
   561 // CPcsCache::GetCacheStatus
       
   562 // 
       
   563 // ---------------------------------------------------------------------
       
   564 TInt CPcsCache::GetCacheStatus()
       
   565 {
       
   566 	return iCacheStatus;
       
   567 }
       
   568 
       
   569 // ---------------------------------------------------------------------
       
   570 // CPcsCache::GetUriId
       
   571 // 
       
   572 // ---------------------------------------------------------------------
       
   573 TUint8 CPcsCache::GetUriId()
       
   574 {
       
   575 	return iUriId;
       
   576 }
       
   577 
       
   578 // ---------------------------------------------------------------------
       
   579 // CPcsCache::SetSortOrder
       
   580 // 
       
   581 // ---------------------------------------------------------------------
       
   582 void CPcsCache::SetSortOrder(RArray<TInt>& aSortOrder)
       
   583 {
       
   584     PRINT ( _L("Enter CPcsCache::SetSortOrder") );    
       
   585     
       
   586     iSortOrder.Reset();
       
   587     
       
   588 	for (TInt i(0); i < aSortOrder.Count(); i++)
       
   589 	{
       
   590 		iSortOrder.Append(aSortOrder[i]);
       
   591 	}
       
   592 	
       
   593 	ComputeIndexOrder();
       
   594 	
       
   595 	PRINT ( _L("End CPcsCache::SetSortOrder") );
       
   596 }
       
   597 
       
   598 // ---------------------------------------------------------------------
       
   599 // CPcsCache::GetSortOrder
       
   600 // 
       
   601 // ---------------------------------------------------------------------
       
   602 void CPcsCache::GetSortOrder(RArray<TInt>& aSortOrder)
       
   603 {
       
   604     aSortOrder.Reset();
       
   605     
       
   606 	for (TInt i(0); i < iSortOrder.Count(); i++)
       
   607 	{
       
   608 		aSortOrder.Append(iSortOrder[i]);
       
   609 	}	
       
   610 }
       
   611 
       
   612 // ---------------------------------------------------------------------
       
   613 // CPcsCache::GetIndexOrder
       
   614 // 
       
   615 // ---------------------------------------------------------------------
       
   616 void CPcsCache::GetIndexOrder(RArray<TInt>& aIndexOrder)
       
   617 {   
       
   618     aIndexOrder.Reset();
       
   619     
       
   620 	for (TInt i(0); i < iIndexOrder.Count(); i++)
       
   621 	{
       
   622 		aIndexOrder.Append(iIndexOrder[i]);
       
   623 	}	
       
   624 }
       
   625 
       
   626 // ---------------------------------------------------------------------
       
   627 // CPcsCache::ComputeIndexOrder
       
   628 // 
       
   629 // ---------------------------------------------------------------------
       
   630 void CPcsCache::ComputeIndexOrder()
       
   631 {   
       
   632     iIndexOrder.Reset();
       
   633     
       
   634 	for ( TInt i = 0; i < iSortOrder.Count(); i++ )
       
   635 	{
       
   636 		for ( TInt j = 0; j < iDataFields.Count(); j++ )
       
   637 		{
       
   638 			if ( iSortOrder[i] == iDataFields[j] )
       
   639 			{
       
   640 				iIndexOrder.Append(j);
       
   641 				break;
       
   642 			}
       
   643 		}
       
   644 	}
       
   645 }
       
   646 
       
   647 // ---------------------------------------------------------------------
       
   648 // CPcsCache::ResortdataInPools
       
   649 // 
       
   650 // ---------------------------------------------------------------------
       
   651 void CPcsCache::ResortdataInPoolsL()
       
   652     {
       
   653     // Copy iMasterPool data into iMasterPoolBackup
       
   654     for (TInt i = 0; i < iMasterPool.Count(); i++ )
       
   655         {
       
   656         iMasterPoolBackup.Append( iMasterPool[i] );
       
   657         }
       
   658 
       
   659     // Now reset the key array
       
   660     for (TInt i = 0; i < iKeyArr.Count(); i++ )
       
   661         {
       
   662         iKeyArr[i]->ResetAndDestroy();
       
   663         }
       
   664     iMasterPool.Reset();
       
   665     iCacheInfo.Close();
       
   666     if ( iAdaptiveGridMap )
       
   667         {
       
   668         iAdaptiveGridMap->Reset();
       
   669         }
       
   670     
       
   671     // Now add data again from the iMasterPoolBackup
       
   672     for (TInt i = 0; i < iMasterPoolBackup.Count(); i++ )
       
   673         {
       
   674         CPsData* temp = iMasterPoolBackup[i];
       
   675         AddToCacheL( *temp );
       
   676         }
       
   677     iMasterPoolBackup.Reset();
       
   678     }
       
   679 
       
   680 // ---------------------------------------------------------------------
       
   681 // CPcsCache::GridItemSelectorL
       
   682 // 
       
   683 // ---------------------------------------------------------------------
       
   684 TUint CPcsCache::GridItemSelector( TInt aIndex, TBool& aUnnamed )
       
   685     {
       
   686     __ASSERT_ALWAYS( iDataFields.Count() > aIndex, User::Panic(_L("CPcsCache"), KErrArgument ) );
       
   687 
       
   688     if ( iDataFields[aIndex] == R_VPBK_FIELD_TYPE_LASTNAME || iDataFields[aIndex] == R_VPBK_FIELD_TYPE_FIRSTNAME )
       
   689         {
       
   690         aUnnamed = EFalse;
       
   691         return CPcsAdaptiveGridItem::EFirstNameLastName;
       
   692         }
       
   693     else if ( iDataFields[aIndex] == R_VPBK_FIELD_TYPE_COMPANYNAME && !aUnnamed )
       
   694         {
       
   695         return CPcsAdaptiveGridItem::ECompanyName;
       
   696         }
       
   697     else if ( iDataFields[aIndex] == R_VPBK_FIELD_TYPE_COMPANYNAME )
       
   698         {
       
   699         return CPcsAdaptiveGridItem::EUnnamedCompanyName;
       
   700         }
       
   701     else
       
   702         {
       
   703         return CPcsAdaptiveGridItem::ENumberCounters;
       
   704         }
       
   705     }
       
   706 
       
   707 // End of file