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