author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:15:33 +0300 | |
branch | RCL_3 |
changeset 85 | 38bb213f60ba |
parent 63 | f4a778e096c2 |
permissions | -rw-r--r-- |
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: Predictive Contact Search Algorithm 1 main class |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDES |
|
20 |
#include "CPcsAlgorithm1.h" |
|
21 |
#include "CPcsAlgorithm1Helper.h" |
|
22 |
#include "CPcsAlgorithm1MultiSearchHelper.h" |
|
23 |
#include "CPcsAlgorithm1Utils.h" |
|
24 |
#include "CPcsDebug.h" |
|
25 |
#include "CPcsCache.h" |
|
26 |
#include "CPcsKeyMap.h" |
|
27 |
#include "CPsData.h" |
|
28 |
#include "CWords.h" |
|
29 |
#include "CPsQuery.h" |
|
30 |
#include "CPsDataPluginInterface.h" |
|
31 |
#include "CPcsDefs.h" |
|
32 |
||
33 |
const TText KSpace = ' '; |
|
34 |
||
35 |
||
36 |
// ============================== MEMBER FUNCTIONS ============================ |
|
37 |
||
38 |
// ---------------------------------------------------------------------------- |
|
39 |
// CPcsAlgorithm1::NewL |
|
40 |
// Two Phase Construction |
|
41 |
// ---------------------------------------------------------------------------- |
|
42 |
CPcsAlgorithm1* CPcsAlgorithm1::NewL() |
|
43 |
{ |
|
44 |
PRINT ( _L("Enter CPcsAlgorithm1::NewL") ); |
|
45 |
||
46 |
CPcsAlgorithm1* self = new ( ELeave ) CPcsAlgorithm1(); |
|
47 |
CleanupStack::PushL( self ); |
|
48 |
self->ConstructL(); |
|
49 |
CleanupStack::Pop( self ); |
|
50 |
||
51 |
PRINT ( _L("End CPcsAlgorithm1::NewL") ); |
|
52 |
||
53 |
return self; |
|
54 |
} |
|
55 |
||
56 |
// ---------------------------------------------------------------------------- |
|
57 |
// CPcsAlgorithm1::CPcsAlgorithm1 |
|
58 |
// Two Phase Construction |
|
59 |
// ---------------------------------------------------------------------------- |
|
60 |
CPcsAlgorithm1::CPcsAlgorithm1() |
|
61 |
{ |
|
62 |
PRINT ( _L("Enter CPcsAlgorithm1::CPcsAlgorithm1") ); |
|
63 |
PRINT ( _L("End CPcsAlgorithm1::CPcsAlgorithm1") ); |
|
64 |
} |
|
65 |
||
66 |
// ---------------------------------------------------------------------------- |
|
67 |
// CPcsAlgorithm1::ConstructL |
|
68 |
// Two Phase Construction |
|
69 |
// ---------------------------------------------------------------------------- |
|
70 |
void CPcsAlgorithm1::ConstructL() |
|
71 |
{ |
|
72 |
PRINT ( _L("Enter CPcsAlgorithm1::ConstructL") ); |
|
73 |
||
74 |
iCacheStatus = ECachingNotStarted; // Starting status |
|
75 |
iCacheError = KErrNone; // No error |
|
76 |
||
77 |
iPluginLauncher = CIdle::NewL( CActive::EPriorityStandard ); |
|
78 |
||
79 |
// Define cache status property used to inform clients about the caching status. |
|
80 |
DefinePropertyL( EPsKeyCacheStatus ); |
|
81 |
||
82 |
// Define cache error property used to inform client about the errors. |
|
83 |
DefinePropertyL( EPsKeyCacheError ); |
|
84 |
||
85 |
// Define properties for notifying about cache updates |
|
86 |
DefinePropertyL( EPsKeyContactRemovedCounter ); |
|
87 |
DefinePropertyL( EPsKeyContactModifiedCounter ); |
|
88 |
DefinePropertyL( EPsKeyContactAddedCounter ); |
|
89 |
||
90 |
// Initialize key map and pti engine |
|
91 |
TInt keyMapErr = KErrNone; |
|
92 |
TRAP( keyMapErr, iKeyMap = CPcsKeyMap::NewL() ); |
|
93 |
if ( keyMapErr != KErrNone ) |
|
94 |
{ |
|
95 |
PRINT ( _L("**********************************************.")); |
|
96 |
PRINT1( _L("CPcsAlgorithm1::ConstructL() KeyMap construction error. The keymap crashed with error code %d."),keyMapErr ); |
|
97 |
PRINT ( _L("Please check the keypad/language for which keymap got crashed.") ); |
|
98 |
PRINT ( _L("**********************************************.")); |
|
99 |
User::Leave( keyMapErr ); // we can't go on without a key map; constructing cache needs it |
|
100 |
} |
|
101 |
||
102 |
// Initialize helpers |
|
103 |
iHelper = CPcsAlgorithm1Helper::NewL(this); |
|
104 |
iMultiSearchHelper = CPcsAlgorithm1MultiSearchHelper::NewL(this); |
|
105 |
||
106 |
if(!iPluginLauncher->IsActive()) |
|
107 |
{ |
|
108 |
iPluginLauncher->Start(TCallBack(CPcsAlgorithm1::DoLaunchPluginsL, this)); |
|
109 |
} |
|
110 |
||
111 |
PRINT ( _L("End CPcsAlgorithm1::ConstructL") ); |
|
112 |
} |
|
113 |
||
114 |
// ---------------------------------------------------------------------------- |
|
115 |
// CPcsAlgorithm1::~CPcsAlgorithm1 |
|
116 |
// Destructor |
|
117 |
// ---------------------------------------------------------------------------- |
|
118 |
CPcsAlgorithm1::~CPcsAlgorithm1() |
|
119 |
{ |
|
120 |
PRINT ( _L("Enter CPcsAlgorithm1::~CPcsAlgorithm1") ); |
|
121 |
||
122 |
// Clear TLS |
|
123 |
Dll::SetTls(NULL); |
|
124 |
||
125 |
// Cleanup cache |
|
126 |
iPcsCache.ResetAndDestroy(); |
|
127 |
||
128 |
// Cleanup adapters interface and key handling |
|
129 |
delete iKeyMap; |
|
130 |
delete iPsDataPluginInterface; |
|
131 |
||
132 |
// Cleanup helpers |
|
133 |
delete iHelper; |
|
134 |
delete iMultiSearchHelper; |
|
135 |
||
136 |
delete iPluginLauncher; |
|
137 |
||
138 |
PRINT ( _L("End CPcsAlgorithm1::~CPcsAlgorithm1") ); |
|
139 |
} |
|
140 |
||
141 |
// ---------------------------------------------------------------------------- |
|
142 |
// CPcsAlgorithm1::DefinePropertyL |
|
143 |
// Define a P&S property with given key under the internal category |
|
144 |
// UID of PCS. Leave if definition fails for any other reason than |
|
145 |
// key already existing. |
|
146 |
// ---------------------------------------------------------------------------- |
|
147 |
void CPcsAlgorithm1::DefinePropertyL( TPcsInternalKeyCacheStatus aPsKey ) |
|
148 |
{ |
|
149 |
TInt err = RProperty::Define( KPcsInternalUidCacheStatus, |
|
150 |
aPsKey, |
|
151 |
RProperty::EInt ); |
|
152 |
if ( err != KErrAlreadyExists ) |
|
153 |
{ |
|
154 |
User::LeaveIfError(err); |
|
155 |
} |
|
156 |
} |
|
157 |
||
158 |
// ---------------------------------------------------------------------------- |
|
159 |
// CPcsAlgorithm1::RemoveSpacesL |
|
160 |
// Remove leading and trailing spaces of search query |
|
161 |
// ---------------------------------------------------------------------------- |
|
162 |
void CPcsAlgorithm1::RemoveSpacesL(CPsQuery& aQuery) |
|
163 |
{ |
|
164 |
PRINT ( _L("Enter CPcsAlgorithm1::RemoveSpacesL") ); |
|
165 |
||
166 |
//PRINTQUERY ( _L("CPcsAlgorithm1::RemoveSpacesL (BEFORE): "), aQuery ); |
|
167 |
||
168 |
// Remove all leading " " |
|
169 |
while ( aQuery.Count() > 0 ) |
|
170 |
{ |
|
171 |
CPsQueryItem& item = aQuery.GetItemAtL(0); // First |
|
172 |
if ( !item.Character().IsSpace() ) |
|
173 |
{ |
|
174 |
break; |
|
175 |
} |
|
176 |
aQuery.Remove(0); |
|
177 |
} |
|
178 |
||
179 |
// Remove all trailing " " |
|
180 |
while ( aQuery.Count() > 0 ) |
|
181 |
{ |
|
182 |
CPsQueryItem& item = aQuery.GetItemAtL(aQuery.Count()-1); // Last |
|
183 |
if ( !item.Character().IsSpace() ) |
|
184 |
{ |
|
185 |
break; |
|
186 |
} |
|
187 |
aQuery.Remove(aQuery.Count()-1); |
|
188 |
} |
|
189 |
||
190 |
//PRINTQUERY ( _L("CPcsAlgorithm1::RemoveSpacesL (AFTER): "), aQuery ); |
|
191 |
||
192 |
PRINT ( _L("End CPcsAlgorithm1::RemoveSpacesL") ); |
|
193 |
} |
|
194 |
||
195 |
// ---------------------------------------------------------------------------- |
|
196 |
// CPcsAlgorithm1::ReplaceZeroWithSpaceL |
|
197 |
// Replace all "0"s in a search query with " "s if those characters are on |
|
198 |
// the same key. |
|
199 |
// ---------------------------------------------------------------------------- |
|
200 |
TBool CPcsAlgorithm1::ReplaceZeroWithSpaceL(CPsQuery& aQuery) |
|
201 |
{ |
|
202 |
PRINT ( _L("Enter CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
|
203 |
||
204 |
//PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (BEFORE): "), aQuery ); |
|
205 |
||
206 |
TBool queryModified = EFalse; |
|
207 |
||
208 |
/* In phones like E52 and E55, where the "0" and the " " characters are on |
|
209 |
* the same key, the "0"s have to be considered as possible separators. |
|
210 |
* |
|
211 |
* In phones like N97 and E72, where the "0" and the " " characters are on |
|
212 |
* different keys, the "0"s must not be considered as possible separators. |
|
213 |
*/ |
|
214 |
||
215 |
// Skip initial "0"s, they are not replaced into spaces |
|
216 |
TInt skipIndex = 0; |
|
217 |
while ( (skipIndex < aQuery.Count()) && |
|
218 |
(aQuery.GetItemAtL(skipIndex).Character().GetNumericValue() == 0) ) |
|
219 |
{ |
|
220 |
skipIndex++; |
|
221 |
} |
|
222 |
||
223 |
// Replace remaining "0"s into spaces in case they are entered with a keyboard |
|
224 |
// that has "0" and " " on the same key. |
|
225 |
for ( TInt index = skipIndex; index < aQuery.Count(); index++ ) |
|
226 |
{ |
|
227 |
CPsQueryItem& item = aQuery.GetItemAtL(index); |
|
228 |
||
229 |
if ( iKeyMap->GetSpaceAndZeroOnSameKey( item.Mode() ) && |
|
230 |
item.Character().GetNumericValue() == 0 ) |
|
231 |
{ |
|
232 |
item.SetCharacter(KSpace); |
|
233 |
queryModified = ETrue; |
|
234 |
} |
|
235 |
} |
|
236 |
||
237 |
//PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (AFTER): "), aQuery ); |
|
238 |
||
239 |
PRINT1 ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: Query modified (0=not, 1=yes): %d"), queryModified ); |
|
240 |
||
241 |
PRINT ( _L("End CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
|
242 |
||
243 |
return queryModified; |
|
244 |
} |
|
245 |
||
246 |
// ---------------------------------------------------------------------------- |
|
247 |
// CPcsAlgorithm1::PerformSearchL |
|
248 |
// Search function for cache |
|
249 |
// ---------------------------------------------------------------------------- |
|
250 |
void CPcsAlgorithm1::PerformSearchL(const CPsSettings& aSettings, |
|
251 |
CPsQuery& aQuery, |
|
252 |
RPointerArray<CPsClientData>& aSearchResults, |
|
253 |
RPointerArray<CPsPattern>& aSearchSeqs) |
|
254 |
{ |
|
255 |
PRINT ( _L("Enter CPcsAlgorithm1::PerformSearchL") ); |
|
256 |
||
257 |
__LATENCY_MARK ( _L("CPcsAlgorithm1::PerformSearchL") ); |
|
258 |
||
259 |
// Check aSettings |
|
260 |
RPointerArray<TDesC> searchUris; |
|
261 |
CleanupResetAndDestroyPushL( searchUris ); |
|
262 |
aSettings.SearchUrisL(searchUris); |
|
263 |
||
264 |
if ( searchUris.Count() <= 0) |
|
265 |
{ |
|
266 |
PRINT ( _L("searchUris.Count() <= 0, Leave from CPcsAlgorithm1::PerformSearchL") ); |
|
267 |
User::Leave(KErrArgument); |
|
268 |
} |
|
269 |
CleanupStack::PopAndDestroy( &searchUris ); // ResetAndDestroy |
|
270 |
||
271 |
// Local arrays to hold the search results |
|
272 |
RPointerArray<CPsData> tempSearchResults; |
|
273 |
CleanupClosePushL( tempSearchResults ); |
|
274 |
RPointerArray<CPsData> tempSearchResultsIni; |
|
275 |
CleanupClosePushL( tempSearchResultsIni ); |
|
276 |
RPointerArray<CPsData> tempSearchResultsMod; |
|
277 |
CleanupClosePushL( tempSearchResultsMod ); |
|
278 |
||
279 |
// ----------------------- Perform the basic search ----------------------- |
|
280 |
/* Even before replacing zeroes with spaces the query can have multiple words |
|
281 |
* Some phones support infact double keyboards with possibility to type a space in qwerty mode |
|
282 |
* A space in qwerty mode can even be typed disabling temporarily PCS |
|
283 |
*/ |
|
284 |
RemoveSpacesL(aQuery); |
|
285 |
PRINTQUERY ( _L("CPcsAlgorithm1::PerformSearchL: 1st search query: "), aQuery ); |
|
286 |
DoSearchL(aSettings, aQuery, tempSearchResultsIni, aSearchSeqs ); |
|
287 |
// ------------------------------------------------------------------------ |
|
288 |
||
289 |
// ---- Perform new search after "0" replacement if query is not empty ---- |
|
290 |
/* Examples: |
|
291 |
* - If the original search string is "Abc0" then we will search again with "Abc". |
|
292 |
* - If the original search string is "00" then we will not search again. |
|
293 |
* - If the original search string is "00Zxc" then we will search again with "Zxc". |
|
294 |
*/ |
|
295 |
TBool isQueryModified = ReplaceZeroWithSpaceL(aQuery); |
|
296 |
RemoveSpacesL(aQuery); |
|
297 |
if ( isQueryModified && (aQuery.Count() > 0) ) |
|
298 |
{ |
|
299 |
PRINTQUERY ( _L("CPcsAlgorithm1::PerformSearchL: 2nd search query: "), aQuery ); |
|
300 |
DoSearchL(aSettings, aQuery, tempSearchResultsMod, aSearchSeqs ); |
|
301 |
} |
|
302 |
// ------------------------------------------------------------------------ |
|
303 |
||
304 |
// ------------------ Merge and sort the search results ------------------- |
|
305 |
if ( tempSearchResultsIni.Count() + tempSearchResultsMod.Count() > 0) |
|
306 |
{ |
|
307 |
// Sort rule |
|
308 |
TLinearOrder<CPsData> rule( CPcsAlgorithm1Utils::CompareDataBySortOrderL ); |
|
309 |
||
310 |
// Avoid duplicates and add new results |
|
311 |
TIdentityRelation<CPsData> identityRule(CPsData::CompareById); |
|
312 |
||
313 |
for ( TInt i = 0; i < tempSearchResultsIni.Count(); i++ ) |
|
314 |
{ |
|
315 |
if ( tempSearchResults.Find( tempSearchResultsIni[i],identityRule ) == KErrNotFound ) |
|
316 |
{ |
|
317 |
if (aSettings.GetSortType() == EAlphabetical) |
|
318 |
{ |
|
319 |
tempSearchResults.InsertInOrderAllowRepeats(tempSearchResultsIni[i], rule); |
|
320 |
} |
|
321 |
else |
|
322 |
{ |
|
323 |
tempSearchResults.AppendL(tempSearchResultsIni[i]); |
|
324 |
} |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
for ( TInt i = 0; i < tempSearchResultsMod.Count(); i++ ) |
|
329 |
{ |
|
330 |
if ( tempSearchResults.Find( tempSearchResultsMod[i],identityRule ) == KErrNotFound ) |
|
331 |
{ |
|
332 |
if (aSettings.GetSortType() == EAlphabetical) |
|
333 |
{ |
|
334 |
tempSearchResults.InsertInOrderAllowRepeats(tempSearchResultsMod[i], rule); |
|
335 |
} |
|
336 |
else |
|
337 |
{ |
|
338 |
tempSearchResults.AppendL(tempSearchResultsMod[i]); |
|
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
// ------------------------------------------------------------------------ |
|
344 |
||
345 |
// ------------------ Write result objects to the stream ------------------ |
|
346 |
// Truncate the result set if required |
|
347 |
TInt maxNumToDisplay = aSettings.MaxResults(); |
|
348 |
TInt resultSetCount = tempSearchResults.Count(); |
|
349 |
TInt numToDisplay = 0; |
|
350 |
if ( maxNumToDisplay == -1 ) |
|
351 |
{ |
|
352 |
numToDisplay = resultSetCount; |
|
353 |
} |
|
354 |
else |
|
355 |
{ |
|
356 |
numToDisplay = Min( maxNumToDisplay, resultSetCount ); |
|
357 |
} |
|
358 |
||
359 |
// Copy desired number of results from tempSearchResults to the results stream |
|
360 |
for (TInt i = 0; i < numToDisplay; i++) |
|
361 |
{ |
|
362 |
aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
|
363 |
} |
|
364 |
// ------------------------------------------------------------------------ |
|
365 |
||
366 |
// Cleanup local results array |
|
367 |
CleanupStack::PopAndDestroy( &tempSearchResultsMod ); // Close, don't destroy |
|
368 |
CleanupStack::PopAndDestroy( &tempSearchResultsIni ); // Close, don't destroy |
|
369 |
CleanupStack::PopAndDestroy( &tempSearchResults ); // Close, don't destroy |
|
370 |
||
371 |
__LATENCY_MARKEND ( _L("CPcsAlgorithm1::PerformSearchL") ); |
|
372 |
||
373 |
PRINT ( _L("End CPcsAlgorithm1::PerformSearchL") ); |
|
374 |
} |
|
375 |
||
376 |
// ---------------------------------------------------------------------------- |
|
377 |
// CPcsAlgorithm1::SearchInputL |
|
378 |
// Search function for input string |
|
379 |
// ---------------------------------------------------------------------------- |
|
380 |
void CPcsAlgorithm1::SearchInputL(CPsQuery& aQuery, |
|
381 |
TDesC& aData, |
|
382 |
RPointerArray<TDesC>& aMatchSet, |
|
383 |
RArray<TPsMatchLocation>& aMatchLocation ) |
|
384 |
{ |
|
385 |
PRINT ( _L("Enter CPcsAlgorithm1::SearchInputL") ); |
|
386 |
||
387 |
__LATENCY_MARK ( _L("CPcsAlgorithm1::SearchInputL") ); |
|
388 |
||
389 |
// ----------------------- Perform the basic search ----------------------- |
|
390 |
/* Even before replacing zeroes with spaces the query can have multiple words |
|
391 |
* Some phones support infact double keyboards with possibility to type a space in qwerty mode |
|
392 |
* A space in qwerty mode can even be typed disabling temporarily PCS |
|
393 |
*/ |
|
394 |
RemoveSpacesL(aQuery); |
|
395 |
DoSearchInputL(aQuery, aData, aMatchSet, aMatchLocation); |
|
396 |
PRINTQUERY ( _L("CPcsAlgorithm1::SearchInputL: 1st search: "), aQuery ); |
|
397 |
PRINT1 ( _L("CPcsAlgorithm1::SearchInputL: 1st search: Search Data: %S"), &aData ); |
|
398 |
PRINTMATCHSET ( _L("CPcsAlgorithm1::SearchInputL: 1st search: "), aMatchSet ); |
|
399 |
PRINTMATCHLOC ( _L("CPcsAlgorithm1::SearchInputL: 1st search: "), aMatchLocation ); |
|
400 |
// ------------------------------------------------------------------------ |
|
401 |
||
402 |
// ---- Perform new search after "0" replacement if query is not empty ---- |
|
403 |
/* Examples: |
|
404 |
* - If the original search string is "Abc0" then we will search again with "Abc". |
|
405 |
* - If the original search string is "00" then we will not search again. |
|
406 |
*/ |
|
407 |
TBool isQueryModified = ReplaceZeroWithSpaceL(aQuery); |
|
408 |
RemoveSpacesL(aQuery); |
|
409 |
if ( isQueryModified && (aQuery.Count() > 0) ) |
|
410 |
{ |
|
411 |
DoSearchInputL(aQuery, aData, aMatchSet, aMatchLocation); |
|
412 |
PRINTQUERY ( _L("CPcsAlgorithm1::SearchInputL: 2nd search: "), aQuery ); |
|
413 |
PRINT1 ( _L("CPcsAlgorithm1::SearchInputL: 2nd search: Search Data: %S"), &aData ); |
|
414 |
PRINTMATCHSET ( _L("CPcsAlgorithm1::SearchInputL: 2nd search: "), aMatchSet ); |
|
415 |
PRINTMATCHLOC ( _L("CPcsAlgorithm1::SearchInputL: 2nd search: "), aMatchLocation ); |
|
416 |
} |
|
417 |
/* In cases like we have a contact "Nik0 Abc" and the search query is "Nik0" we do: |
|
418 |
* - a 1st search with "Nik0" that matches "Nik0" (4 chars) of "Nik0 Abc", |
|
419 |
* - a 2nd search with "Nik" that matches "Nik" (3 chars) of "Nik0 Abc". |
|
420 |
* We have to remove from aMatchLocation the occurrence that has a shorter match length. |
|
421 |
* We have to remove the match ("Nik" in this case) even from aMatchSet if there is not |
|
422 |
* any other match for it than the one in "Nik0". |
|
423 |
*/ |
|
424 |
||
425 |
// --- Remove duplicate items from aMatchLocation --- |
|
426 |
TInt i = 0; |
|
427 |
TBool incrementFirstCursor; |
|
428 |
while ( i < aMatchLocation.Count() ) |
|
429 |
{ |
|
430 |
incrementFirstCursor = ETrue; |
|
431 |
TInt j = i+1; |
|
432 |
while ( j < aMatchLocation.Count() ) |
|
433 |
{ |
|
434 |
if (aMatchLocation[j].index == aMatchLocation[i].index) |
|
435 |
{ |
|
436 |
// Remove match location item with smallest length if 2 items have same index |
|
437 |
if ( aMatchLocation[j].length <= aMatchLocation[i].length ) |
|
438 |
{ |
|
439 |
aMatchLocation.Remove(j); |
|
440 |
continue; // Do not increment j |
|
441 |
} |
|
442 |
else |
|
443 |
{ |
|
444 |
aMatchLocation.Remove(i); |
|
445 |
incrementFirstCursor = EFalse; // Do not increment i |
|
446 |
break; |
|
447 |
} |
|
448 |
} |
|
449 |
j++; |
|
450 |
} |
|
451 |
if ( incrementFirstCursor ) |
|
452 |
{ |
|
453 |
i++; |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
// --- Remove duplicate items from aMatchSet --- |
|
458 |
HBufC* dataUpper = HBufC::NewLC(aData.Length()); |
|
459 |
dataUpper->Des().Copy(aData); |
|
460 |
dataUpper->Des().UpperCase(); // Get uppercase, as aMatchSet is in upper case |
|
461 |
||
462 |
TInt k = 0; |
|
463 |
while ( k < aMatchSet.Count() ) |
|
464 |
{ |
|
465 |
TBool keepMatch = EFalse; |
|
466 |
TInt startCursor = -1; |
|
467 |
||
468 |
TInt offsetCursor; |
|
469 |
while ( KErrNotFound != (offsetCursor = dataUpper->Mid(startCursor + 1).Find(*aMatchSet[k])) ) |
|
470 |
{ |
|
471 |
// startCursor = index of match item *aMatchSet[k] into search string aData |
|
472 |
startCursor = offsetCursor + startCursor + 1; |
|
473 |
for ( TInt i = 0; i < aMatchLocation.Count(); i++ ) |
|
474 |
{ |
|
475 |
// If match item was found in the location list, then keep it |
|
476 |
if ( (aMatchLocation[i].index == startCursor) && |
|
477 |
(aMatchLocation[i].length == aMatchSet[k]->Length()) ) |
|
478 |
{ |
|
479 |
keepMatch = ETrue; |
|
480 |
break; |
|
481 |
} |
|
482 |
} |
|
483 |
} |
|
484 |
||
485 |
if ( keepMatch ) |
|
486 |
{ |
|
487 |
k++; |
|
488 |
} |
|
489 |
else |
|
490 |
{ |
|
491 |
aMatchSet.Remove(k); // Do not increment k |
|
492 |
} |
|
493 |
// --- Remove items End --- |
|
494 |
||
495 |
} |
|
496 |
CleanupStack::PopAndDestroy( dataUpper ); |
|
497 |
// ------------------------------------------------------------------------ |
|
498 |
||
499 |
// Sort match set |
|
500 |
iHelper->SortSearchSeqsL(aMatchSet); |
|
501 |
||
502 |
PRINTQUERY ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aQuery ); |
|
503 |
PRINT1 ( _L("CPcsAlgorithm1::SearchInputL: Final: Search Data: %S"), &aData ); |
|
504 |
PRINTMATCHSET ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchSet ); |
|
505 |
PRINTMATCHLOC ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchLocation ); |
|
506 |
||
507 |
__LATENCY_MARKEND ( _L("CPcsAlgorithm1::SearchInputL") ); |
|
508 |
||
509 |
PRINT ( _L("End CPcsAlgorithm1::SearchInputL") ); |
|
510 |
} |
|
511 |
||
512 |
// ---------------------------------------------------------------------------- |
|
513 |
// CPcsAlgorithm1::SearchMatchStringL |
|
514 |
// Search function for input string, result also as string |
|
515 |
// ---------------------------------------------------------------------------- |
|
516 |
void CPcsAlgorithm1::SearchMatchStringL( CPsQuery& aSearchQuery, |
|
517 |
TDesC& aSearchData, |
|
518 |
TDes& aMatch ) |
|
519 |
{ |
|
520 |
PRINT ( _L("Enter CPcsAlgorithm1::SearchMatchStringL") ); |
|
521 |
||
522 |
__LATENCY_MARK ( _L("CPcsAlgorithm1::SearchMatchStringL") ); |
|
523 |
||
524 |
// ---------------------- Perform the initial search ---------------------- |
|
525 |
iMultiSearchHelper->LookupMatchL( aSearchQuery, aSearchData, aMatch ); |
|
526 |
PRINTQUERY ( _L("CPcsAlgorithm1::SearchMatchStringL: 1st search: "), aSearchQuery ); |
|
527 |
PRINT1 ( _L("CPcsAlgorithm1::SearchMatchStringL: 1st search: Search Data: %S"), &aSearchData ); |
|
528 |
PRINT1 ( _L("CPcsAlgorithm1::SearchMatchStringL: 1st search: Result: %S"), &aMatch ); |
|
529 |
// ------------------------------------------------------------------------ |
|
530 |
||
531 |
// ---- Perform new search after "0" replacement if query is not empty ---- |
|
532 |
/* Examples: |
|
533 |
* - If the original search string is "Abc0" then we will search again with "Abc". |
|
534 |
* - If the original search string is "00" then we will not search again. |
|
535 |
*/ |
|
536 |
if ( aMatch.Length() <= 0 ) |
|
537 |
{ |
|
538 |
TBool isQueryModified = ReplaceZeroWithSpaceL(aSearchQuery); |
|
539 |
if ( isQueryModified && (aSearchQuery.Count() > 0) ) |
|
540 |
{ |
|
541 |
iMultiSearchHelper->LookupMatchL( aSearchQuery, aSearchData, aMatch ); |
|
542 |
PRINTQUERY ( _L("CPcsAlgorithm1::SearchMatchStringL: 2nd search: "), aSearchQuery ); |
|
543 |
PRINT1 ( _L("CPcsAlgorithm1::SearchMatchStringL: 2nd search: Search Data: %S"), &aSearchData ); |
|
544 |
PRINT1 ( _L("CPcsAlgorithm1::SearchMatchStringL: 2nd search: Result: %S"), &aMatch ); |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
__LATENCY_MARKEND ( _L("CPcsAlgorithm1::SearchMatchStringL") ); |
|
549 |
||
550 |
PRINT ( _L("End CPcsAlgorithm1::SearchMatchStringL") ); |
|
551 |
} |
|
552 |
||
553 |
// ---------------------------------------------------------------------------- |
|
554 |
// CPcsAlgorithm1::DoSearchL |
|
555 |
// Search function helper |
|
556 |
// ---------------------------------------------------------------------------- |
|
557 |
void CPcsAlgorithm1::DoSearchL( const CPsSettings& aSettings, |
|
558 |
CPsQuery& aQuery, |
|
559 |
RPointerArray<CPsData>& aSearchResults, |
|
560 |
RPointerArray<CPsPattern>& aSearchSeqs ) |
|
561 |
{ |
|
562 |
PRINT ( _L("Enter CPcsAlgorithm1::DoSearchL") ); |
|
563 |
||
564 |
__LATENCY_MARK ( _L("CPcsAlgorithm1::DoSearchL") ); |
|
565 |
||
566 |
// (0)------------------ Check if group search is required --------------- |
|
567 |
RArray<TInt> contactsInGroup; |
|
568 |
CleanupClosePushL( contactsInGroup ); |
|
569 |
RArray<TInt> groupIdArray; |
|
570 |
CleanupClosePushL( groupIdArray ); |
|
571 |
||
572 |
// Create a new settings instance |
|
573 |
CPsSettings* tempSettings = aSettings.CloneL(); |
|
574 |
CleanupStack::PushL( tempSettings ); |
|
575 |
||
576 |
TBool isGroupSearch = IsGroupSearchL(*tempSettings, groupIdArray); |
|
577 |
||
578 |
if ( isGroupSearch ) |
|
579 |
{ |
|
580 |
// Replace groups URI with contacts DB URI in new search settings |
|
581 |
ReplaceGroupsUriL(*tempSettings); |
|
582 |
||
583 |
// List of contacts in this group |
|
584 |
GetContactsInGroupL ( groupIdArray[0], contactsInGroup ); |
|
585 |
} |
|
586 |
||
587 |
// ----------------------------------------------------------------------- |
|
588 |
||
589 |
// Extract query list. |
|
590 |
RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
|
591 |
CleanupResetAndDestroyPushL( queryList ); |
|
592 |
PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchL: "), queryList ); |
|
593 |
||
594 |
// (1)-------------------- No query return all contacts ------------------- |
|
595 |
if ( queryList.Count() == 0 ) |
|
596 |
{ |
|
597 |
GetAllContentsL(*tempSettings, aSearchResults); |
|
598 |
||
599 |
if ( isGroupSearch ) |
|
600 |
{ |
|
601 |
FilterSearchResultsForGroupsL( contactsInGroup, aSearchResults ); |
|
602 |
} |
|
603 |
} |
|
604 |
// ------------------------------------------------------------------------ |
|
605 |
||
606 |
// (2)-------------------- Perform a single query search ------------------ |
|
607 |
else if ( queryList.Count() == 1 ) // single query |
|
608 |
{ |
|
609 |
PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Single. Performing a SingleSearch") ); |
|
610 |
||
611 |
iHelper->SearchSingleL(*tempSettings, *queryList[0], isGroupSearch, |
|
612 |
contactsInGroup, aSearchResults, aSearchSeqs); |
|
613 |
} |
|
614 |
// ------------------------------------------------------------------------ |
|
615 |
||
616 |
// (3)-------------------- Perform a multi query search ------------------- |
|
617 |
else // multiple query |
|
618 |
{ |
|
619 |
PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Multiple. Performing a MultiSearch") ); |
|
620 |
||
621 |
// Search results |
|
622 |
iMultiSearchHelper->SearchMultiL(*tempSettings, queryList, isGroupSearch, |
|
623 |
contactsInGroup, aSearchResults, aSearchSeqs); |
|
624 |
} |
|
625 |
// ------------------------------------------------------------------------- |
|
626 |
||
627 |
// Cleanup |
|
628 |
||
629 |
CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
|
630 |
CleanupStack::PopAndDestroy( tempSettings ); |
|
631 |
CleanupStack::PopAndDestroy( &groupIdArray ); // Close |
|
632 |
CleanupStack::PopAndDestroy( &contactsInGroup ); // Close |
|
633 |
||
634 |
__LATENCY_MARKEND ( _L("CPcsAlgorithm1::DoSearchL") ); |
|
635 |
||
636 |
PRINT ( _L("End CPcsAlgorithm1::DoSearchL") ); |
|
637 |
} |
|
638 |
||
639 |
// ---------------------------------------------------------------------------- |
|
640 |
// CPcsAlgorithm1::DoSearchInputL |
|
641 |
// Search function helper |
|
642 |
// ---------------------------------------------------------------------------- |
|
643 |
void CPcsAlgorithm1::DoSearchInputL( CPsQuery& aQuery, |
|
644 |
const TDesC& aData, |
|
645 |
RPointerArray<TDesC>& aMatchSet, |
|
646 |
RArray<TPsMatchLocation>& aMatchLocation ) |
|
647 |
{ |
|
648 |
PRINT ( _L("Enter CPcsAlgorithm1::DoSearchInputL") ); |
|
649 |
||
650 |
TInt queryWords = iMultiSearchHelper->CountMultiQueryWordsL(aQuery); |
|
651 |
||
652 |
// No query |
|
653 |
if ( queryWords == 0 ) |
|
654 |
{ |
|
655 |
PRINT ( _L("CPcsAlgorithm1::DoSearchInputL: Query received is empty") ); |
|
656 |
return; |
|
657 |
} |
|
658 |
||
659 |
RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
|
660 |
CleanupResetAndDestroyPushL( queryList ); |
|
661 |
||
662 |
PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchInputL: "), queryList ); |
|
663 |
||
664 |
if ( queryList.Count() == 1 ) // Single query |
|
665 |
{ |
|
666 |
PRINT ( _L("CPcsAlgorithm1::DoSearchInputL: Query received is single. Performing a single search.") ); |
|
667 |
iHelper->SearchMatchSeqL(aQuery, |
|
668 |
aData, |
|
669 |
aMatchSet, |
|
670 |
aMatchLocation); |
|
671 |
} |
|
672 |
else // multiple query |
|
673 |
{ |
|
674 |
PRINT ( _L("CPcsAlgorithm1::DoSearchInputL: Query received is Multiple. Performing a MultiSearch") ); |
|
675 |
iMultiSearchHelper->SearchMatchSeqMultiL(queryList, |
|
676 |
aData, |
|
677 |
aMatchSet, |
|
678 |
aMatchLocation); |
|
679 |
} |
|
680 |
||
681 |
// Delete all the query elements |
|
682 |
CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
|
683 |
||
684 |
PRINT ( _L("End CPcsAlgorithm1::DoSearchInputL") ); |
|
685 |
} |
|
686 |
||
687 |
// ---------------------------------------------------------------------------- |
|
688 |
// CPcsAlgorithm1::AddData |
|
689 |
// Add a data element to the pool |
|
690 |
// ---------------------------------------------------------------------------- |
|
691 |
void CPcsAlgorithm1::AddData(TDesC& aDataStore, CPsData* aData) |
|
692 |
{ |
|
693 |
TInt arrayIndex = GetCacheIndex(aDataStore); |
|
694 |
||
695 |
if ( arrayIndex < 0 ) return; |
|
696 |
||
697 |
CPcsCache* cache = iPcsCache[arrayIndex]; |
|
698 |
||
699 |
// Fill the data store index |
|
700 |
TInt dataStoreIndex = FindStoreUri(aDataStore); |
|
701 |
if ( dataStoreIndex >= 0 ) |
|
702 |
{ |
|
703 |
aData->SetUriId(dataStoreIndex); |
|
704 |
} |
|
705 |
else |
|
706 |
{ |
|
707 |
PRINT(_L("CPcsAlgorithm1::AddData: Unknown data store")); |
|
708 |
return; |
|
709 |
} |
|
710 |
||
711 |
TRAPD(err, cache->AddToCacheL(*aData)); |
|
712 |
||
713 |
if ( err != KErrNone ) |
|
714 |
{ |
|
715 |
SetCachingError(aDataStore, err); |
|
716 |
} |
|
717 |
} |
|
718 |
||
719 |
// ---------------------------------------------------------------------------- |
|
720 |
// CPcsAlgorithm1::RemoveData |
|
721 |
// Remove a data element from the pool |
|
722 |
// ---------------------------------------------------------------------------- |
|
723 |
void CPcsAlgorithm1::RemoveData(TDesC& aDataStore, TInt aItemId) |
|
724 |
{ |
|
725 |
TInt arrayIndex = GetCacheIndex(aDataStore); |
|
726 |
||
727 |
if ( arrayIndex < 0 ) return; |
|
728 |
||
729 |
CPcsCache* cache = iPcsCache[arrayIndex]; |
|
730 |
||
731 |
TRAPD(err, cache->RemoveFromCacheL(aItemId)); |
|
732 |
||
733 |
if ( err != KErrNone ) |
|
734 |
{ |
|
735 |
SetCachingError(aDataStore, err); |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
// --------------------------------------------------------------------- |
|
740 |
// CPcsAlgorithm1::RemoveAll |
|
741 |
// Remove all the contacts from a datastore |
|
742 |
// --------------------------------------------------------------------- |
|
743 |
void CPcsAlgorithm1::RemoveAll(TDesC& aDataStore) |
|
744 |
{ |
|
745 |
TInt dataStoreIndex = GetCacheIndex(aDataStore); |
|
746 |
||
747 |
if(dataStoreIndex < 0) return; |
|
748 |
||
749 |
CPcsCache* cache = iPcsCache[dataStoreIndex]; |
|
750 |
||
751 |
cache->RemoveAllFromCache(); |
|
752 |
} |
|
753 |
||
754 |
// ---------------------------------------------------------------------------- |
|
755 |
// CPcsAlgorithm1::GetCacheIndex |
|
756 |
// Return the cache index for a data store |
|
757 |
// ---------------------------------------------------------------------------- |
|
758 |
TInt CPcsAlgorithm1::GetCacheIndex(const TDesC& aDataStore) |
|
759 |
{ |
|
760 |
for ( int i = 0; i < iPcsCache.Count(); i++ ) |
|
761 |
{ |
|
762 |
CPcsCache* cache = iPcsCache[i]; |
|
763 |
||
764 |
if ( cache->GetURI().CompareC(aDataStore) == 0 ) return i; |
|
765 |
} |
|
766 |
||
767 |
return KErrNotFound; |
|
768 |
} |
|
769 |
||
770 |
// ---------------------------------------------------------------------------- |
|
771 |
// CPcsAlgorithm1::AddDataStore |
|
772 |
// Adds a new store |
|
773 |
// ---------------------------------------------------------------------------- |
|
774 |
void CPcsAlgorithm1::AddDataStore(TDesC& aDataStore) |
|
775 |
{ |
|
776 |
// Check if the datastore cache already exists |
|
777 |
TInt index = GetCacheIndex(aDataStore); |
|
778 |
if ( index != KErrNotFound ) |
|
779 |
{ |
|
780 |
// Already exists |
|
781 |
return; |
|
782 |
} |
|
783 |
||
784 |
// Create a new cache |
|
785 |
CPcsCache* cache = NULL; |
|
786 |
TRAPD(err, cache = CPcsCache::NewL(aDataStore, *iKeyMap, (TUint8) iPcsCache.Count())); |
|
787 |
if ( err != KErrNone ) |
|
788 |
{ |
|
789 |
SetCachingError(aDataStore, err); |
|
790 |
return; |
|
791 |
} |
|
792 |
||
793 |
RArray<TInt> dataFields; |
|
794 |
TRAP(err, iPsDataPluginInterface->GetSupportedDataFieldsL(cache->GetURI(), dataFields)); |
|
795 |
if ( err != KErrNone ) |
|
796 |
{ |
|
797 |
SetCachingError(aDataStore, err); |
|
798 |
return; |
|
799 |
} |
|
800 |
cache->SetDataFields(dataFields); |
|
801 |
||
802 |
// Check if sort order is persisted already |
|
803 |
RArray<TInt> sortOrder; |
|
804 |
TRAP(err, ReadSortOrderFromCenRepL(cache->GetURI(), sortOrder)); |
|
805 |
if ( err != KErrNone ) |
|
806 |
{ |
|
807 |
SetCachingError(aDataStore, err); |
|
808 |
return; |
|
809 |
} |
|
810 |
||
811 |
if ( sortOrder.Count() == 0 ) |
|
812 |
{ |
|
813 |
cache->SetSortOrder(dataFields); // Initial sort order |
|
814 |
} |
|
815 |
else |
|
816 |
{ |
|
817 |
cache->SetSortOrder(sortOrder); // Persisted sort order |
|
818 |
} |
|
819 |
||
820 |
sortOrder.Close(); |
|
821 |
dataFields.Close(); |
|
822 |
||
823 |
iPcsCache.Append(cache); |
|
824 |
||
825 |
TRAP(err, iPsDataPluginInterface->RequestForDataL(aDataStore)); |
|
826 |
if ( err != KErrNone ) |
|
827 |
{ |
|
828 |
PRINT ( _L("CPcsAlgorithm1::AddDataStore() Set Caching Error ") ); |
|
829 |
SetCachingError(aDataStore, err); |
|
830 |
UpdateCachingStatus(aDataStore,ECachingCompleteWithErrors); |
|
831 |
return; |
|
832 |
} |
|
833 |
} |
|
834 |
||
835 |
// ---------------------------------------------------------------------------- |
|
836 |
// CPcsAlgorithm1::RemoveDataStore |
|
837 |
// Removes an existing data store |
|
838 |
// ---------------------------------------------------------------------------- |
|
839 |
void CPcsAlgorithm1::RemoveDataStore(TDesC& aDataStore) |
|
840 |
{ |
|
841 |
for ( int i = 0; i < iPcsCache.Count(); i++ ) |
|
842 |
{ |
|
843 |
CPcsCache* cache = iPcsCache[i]; |
|
844 |
||
845 |
if ( cache->GetURI().CompareC(aDataStore) == 0 ) |
|
846 |
{ |
|
847 |
delete iPcsCache[i]; |
|
848 |
iPcsCache.Remove(i); |
|
849 |
} |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
// ---------------------------------------------------------------------------- |
|
854 |
// CPcsAlgorithm1::IsLanguageSupportedL |
|
855 |
// Returns ETrue if this language is supported |
|
856 |
// ---------------------------------------------------------------------------- |
|
857 |
TBool CPcsAlgorithm1::IsLanguageSupportedL(TUint32 aLang) |
|
858 |
{ |
|
859 |
return iKeyMap->IsLanguageSupported(aLang); |
|
860 |
} |
|
861 |
||
862 |
// ---------------------------------------------------------------------------- |
|
863 |
// CPcsAlgorithm1::GetUriForIdL |
|
864 |
// Get the URI string for this internal id |
|
865 |
// ---------------------------------------------------------------------------- |
|
866 |
const TDesC& CPcsAlgorithm1::GetUriForIdL(TUint8 aUriId) |
|
867 |
{ |
|
868 |
TBool found = EFalse; |
|
869 |
TInt i = 0; |
|
870 |
||
871 |
for ( i = 0; i < iPcsCache.Count(); i++ ) |
|
872 |
{ |
|
873 |
if ( iPcsCache[i]->GetUriId() == aUriId ) |
|
874 |
{ |
|
875 |
found = ETrue; |
|
876 |
break; |
|
877 |
} |
|
878 |
} |
|
879 |
||
880 |
if ( ! found ) |
|
881 |
{ |
|
882 |
User::Leave(KErrNotFound); |
|
883 |
} |
|
884 |
||
885 |
return iPcsCache[i]->GetURI(); |
|
886 |
} |
|
887 |
||
888 |
// ---------------------------------------------------------------------------- |
|
889 |
// CPcsAlgorithm1::FindStoreUri |
|
890 |
// Checks if this store exists |
|
891 |
// ---------------------------------------------------------------------------- |
|
892 |
TInt CPcsAlgorithm1::FindStoreUri ( const TDesC& aDataStore ) |
|
893 |
{ |
|
894 |
for ( TInt i = 0; i < iPcsCache.Count(); i++ ) |
|
895 |
{ |
|
896 |
if ( aDataStore.CompareC(iPcsCache[i]->GetURI()) == 0 ) |
|
897 |
{ |
|
898 |
return i; |
|
899 |
} |
|
900 |
} |
|
901 |
||
902 |
return KErrNotFound; |
|
903 |
} |
|
904 |
||
905 |
// ---------------------------------------------------------------------------- |
|
906 |
// CPcsAlgorithm1::UpdateCachingStatus |
|
907 |
// Update caching status |
|
908 |
// ---------------------------------------------------------------------------- |
|
909 |
void CPcsAlgorithm1::UpdateCachingStatus(TDesC& aDataStore, TInt aStatus) |
|
910 |
{ |
|
911 |
PRINT ( _L("Enter CPcsAlgorithm1::UpdateCachingStatus") ); |
|
912 |
PRINT2 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Request received for URI=%S with status=%d"), |
|
913 |
&aDataStore, aStatus ); |
|
914 |
||
915 |
// Handle data store update events |
|
916 |
if ( aStatus == ECacheUpdateContactRemoved || |
|
917 |
aStatus == ECacheUpdateContactModified || |
|
918 |
aStatus == ECacheUpdateContactAdded ) |
|
919 |
{ |
|
920 |
HandleCacheUpdated( static_cast<TCachingStatus>(aStatus) ); |
|
921 |
return; |
|
922 |
} |
|
923 |
||
924 |
// If not a cache update event, then this event is related to the initial |
|
925 |
// cache construction. |
|
926 |
||
927 |
// Check if any error occurred and update the cache error |
|
928 |
if ( aStatus < 0 ) |
|
929 |
{ |
|
930 |
SetCachingError(aDataStore, aStatus); |
|
931 |
} |
|
932 |
else |
|
933 |
{ |
|
934 |
TInt index = FindStoreUri(aDataStore); |
|
935 |
iPcsCache[index]->UpdateCacheStatus(aStatus); |
|
936 |
} |
|
937 |
||
938 |
TCachingStatus status = ECachingNotStarted; |
|
939 |
TUint countNotStarted = 0; |
|
940 |
TUint countInProgress = 0; |
|
941 |
TUint countCompleted = 0; |
|
942 |
TUint countCompletedWithErrors = 0; |
|
943 |
TInt cacheCount = iPcsCache.Count(); |
|
944 |
for ( TInt i = 0; i < cacheCount; i++ ) |
|
945 |
{ |
|
946 |
PRINT3 ( _L("CPcsAlgorithm1::UpdateCachingStatus: URI[%d]=%S, cache status=%d"), |
|
947 |
i, &iPcsCache[i]->GetURI(), iPcsCache[i]->GetCacheStatus() ); |
|
948 |
||
949 |
switch ( iPcsCache[i]->GetCacheStatus() ) |
|
950 |
{ |
|
951 |
case ECachingNotStarted: |
|
952 |
{ |
|
953 |
countNotStarted++; |
|
954 |
break; |
|
955 |
} |
|
956 |
case ECachingInProgress: |
|
957 |
{ |
|
958 |
countInProgress++; |
|
959 |
break; |
|
960 |
} |
|
961 |
case ECachingComplete: |
|
962 |
{ |
|
963 |
countCompleted++; |
|
964 |
break; |
|
965 |
} |
|
966 |
case ECachingCompleteWithErrors: |
|
967 |
{ |
|
968 |
countCompletedWithErrors++; |
|
969 |
break; |
|
970 |
} |
|
971 |
default: |
|
972 |
{ |
|
973 |
// Default completed state |
|
974 |
countCompleted++; |
|
975 |
break; |
|
976 |
} |
|
977 |
} |
|
978 |
} |
|
979 |
||
980 |
// Calculate cumulative status according to single caches statuses |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
981 |
if ( countCompleted == cacheCount ) |
63 | 982 |
{ |
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
983 |
// If all caching are finished, set status to ECachingComplete or |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
984 |
// ECachingCompleteWithErrors according to iCacheError |
63 | 985 |
status = ( iCacheError == KErrNone ) ? ECachingComplete : ECachingCompleteWithErrors; |
986 |
} |
|
987 |
else if ( countInProgress > 0 ) |
|
988 |
{ |
|
989 |
// Else if at least one caching is in progress, |
|
990 |
// set status to ECachingInProgress |
|
991 |
status = ECachingInProgress; |
|
992 |
} |
|
993 |
else if ( countCompletedWithErrors > 0 ) |
|
994 |
{ |
|
995 |
// Else if at least one caching is completed with errors, |
|
996 |
//set status to ECachingCompleteWithErrors |
|
997 |
status = ECachingCompleteWithErrors; |
|
998 |
} |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
999 |
else if ( countCompleted > 0 && ( countCompleted + countNotStarted ) == cacheCount ) |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1000 |
{ |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1001 |
// Else if at least one caching is finished |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1002 |
// set status to ECachingComplete or ECachingCompleteWithErrors |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1003 |
// according to iCacheError |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1004 |
status = ( iCacheError == KErrNone ) ? ECachingComplete : ECachingCompleteWithErrors; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
1005 |
} |
63 | 1006 |
else |
1007 |
{ |
|
1008 |
// countNotStarted == cacheCount |
|
1009 |
// status is set to default ECachingNotStarted |
|
1010 |
} |
|
1011 |
||
1012 |
PRINT1 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Cumulative caching status is %d"), |
|
1013 |
status ); |
|
1014 |
||
1015 |
// Check if status changed |
|
1016 |
if ( status != iCacheStatus ) |
|
1017 |
{ |
|
1018 |
PRINT2 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Cumulative caching changed: %d -> %d"), |
|
1019 |
iCacheStatus, status ); |
|
1020 |
||
1021 |
iCacheStatus = status; |
|
1022 |
RProperty::Set(KPcsInternalUidCacheStatus, EPsKeyCacheStatus, iCacheStatus ); |
|
1023 |
} |
|
1024 |
||
1025 |
PRINT( _L("End CPcsAlgorithm1::UpdateCachingStatus") ); |
|
1026 |
} |
|
1027 |
||
1028 |
// ---------------------------------------------------------------------------- |
|
1029 |
// CPcsAlgorithm1::SetCachingError |
|
1030 |
// Updates cachinge error |
|
1031 |
// ---------------------------------------------------------------------------- |
|
1032 |
void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError) |
|
1033 |
{ |
|
1034 |
PRINT2 ( _L("CPcsAlgorithm1::SetCachingError: URI=%S, ERROR=%d"), &aDataStore, aError ); |
|
1035 |
||
1036 |
iCacheError = aError; |
|
1037 |
RProperty::Set( KPcsInternalUidCacheStatus, EPsKeyCacheError, iCacheError ); |
|
1038 |
} |
|
1039 |
||
1040 |
// ---------------------------------------------------------------------------- |
|
1041 |
// CPcsAlgorithm1::GetAllContentsL |
|
1042 |
// Returns all the contents of a store |
|
1043 |
// ---------------------------------------------------------------------------- |
|
1044 |
void CPcsAlgorithm1::GetAllContentsL ( const CPsSettings& aSettings, |
|
1045 |
RPointerArray<CPsData>& aResults ) |
|
1046 |
{ |
|
1047 |
__LATENCY_MARK ( _L("CPcsAlgorithm1::GetAllContentsL") ); |
|
1048 |
||
1049 |
PRINT ( _L("Enter CPcsAlgorithm1::GetAllContentsL") ); |
|
1050 |
||
1051 |
// To hold array of results from different data stores |
|
1052 |
typedef RPointerArray<CPsData> CPSDATA_R_PTR_ARRAY; |
|
1053 |
RPointerArray<CPSDATA_R_PTR_ARRAY> searchResultsArr; |
|
1054 |
CleanupResetAndDestroyPushL( searchResultsArr ); |
|
1055 |
// TODO: Here's still a potential memory leak if a leave happens. The child |
|
1056 |
// arrays of searchResultsArr are not Reset in that case. The CPsData objects |
|
1057 |
// may leak as well. Handling this safely is somewhat complicated because some of |
|
1058 |
// the CPsData objects may already be transferred to ownership of aResults array |
|
1059 |
// at the time the leave happens, and those items must not be deleted. |
|
1060 |
||
1061 |
// Get the data stores |
|
1062 |
RPointerArray<TDesC> dataStores; |
|
1063 |
CleanupResetAndDestroyPushL( dataStores ); |
|
1064 |
aSettings.SearchUrisL(dataStores); |
|
1065 |
||
1066 |
// Get all contacts for each data store |
|
1067 |
for ( TInt dsIndex = 0; |
|
1068 |
dsIndex < dataStores.Count(); |
|
1069 |
dsIndex++ ) |
|
1070 |
{ |
|
1071 |
RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData>(); |
|
1072 |
searchResultsArr.Append(temp); |
|
1073 |
||
1074 |
TInt arrayIndex = GetCacheIndex(*(dataStores[dsIndex])); |
|
1075 |
||
1076 |
if ( arrayIndex < 0 ) continue; |
|
1077 |
||
1078 |
CPcsCache* cache = GetCache(arrayIndex); |
|
1079 |
||
1080 |
cache->GetAllContentsL(*(searchResultsArr[dsIndex])); |
|
1081 |
} |
|
1082 |
||
1083 |
CleanupStack::PopAndDestroy( &dataStores ); // ResetAndDestroy |
|
1084 |
||
1085 |
// Merge the results from different data stores |
|
1086 |
CPcsAlgorithm1Utils::FormCompleteSearchResultsL(searchResultsArr, |
|
1087 |
aResults); |
|
1088 |
||
1089 |
// Cleanup the local arrays |
|
1090 |
for(TInt i = 0; i < searchResultsArr.Count(); i++) |
|
1091 |
{ |
|
1092 |
searchResultsArr[i]->Reset(); |
|
1093 |
} |
|
1094 |
CleanupStack::PopAndDestroy( &searchResultsArr ); // ResetAndDestroy |
|
1095 |
||
1096 |
PRINT1 ( _L("Number of results = %d"), aResults.Count() ); |
|
1097 |
||
1098 |
PRINT ( _L("End CPcsAlgorithm1::GetAllContentsL") ); |
|
1099 |
||
1100 |
__LATENCY_MARKEND ( _L("CPcsAlgorithm1::GetAllContentsL") ); |
|
1101 |
} |
|
1102 |
||
1103 |
// ---------------------------------------------------------------------------- |
|
1104 |
// CPcsAlgorithm1::IsGroupSearchL |
|
1105 |
// Checks if a group search is required |
|
1106 |
// ---------------------------------------------------------------------------- |
|
1107 |
TBool CPcsAlgorithm1::IsGroupSearchL ( CPsSettings& aSettings, |
|
1108 |
RArray<TInt>& aGroupIdArray ) |
|
1109 |
{ |
|
1110 |
PRINT ( _L("Enter CPcsAlgorithm1::IsGroupSearchL") ); |
|
1111 |
||
1112 |
// Get the groupIds in the seach settings |
|
1113 |
aSettings.GetGroupIdsL(aGroupIdArray); |
|
1114 |
||
1115 |
// Get the current URIs defined in settings |
|
1116 |
RPointerArray<TDesC> searchUris; |
|
1117 |
CleanupResetAndDestroyPushL( searchUris ); |
|
1118 |
aSettings.SearchUrisL(searchUris); |
|
1119 |
||
1120 |
if ( aGroupIdArray.Count() && (searchUris.Count() > aGroupIdArray.Count() ) ) |
|
1121 |
{ |
|
1122 |
// There is an error, either there are more than one groups |
|
1123 |
// or the settings contain a combination of group/non-group Uris |
|
1124 |
aGroupIdArray.Close(); |
|
1125 |
User::Leave(KErrArgument); |
|
1126 |
} |
|
1127 |
||
1128 |
CleanupStack::PopAndDestroy( &searchUris ); // ResetAndDestroy |
|
1129 |
||
1130 |
PRINT ( _L("End CPcsAlgorithm1::IsGroupSearchL") ); |
|
1131 |
||
1132 |
if ( aGroupIdArray.Count() == 1 ) |
|
1133 |
return ETrue; |
|
1134 |
||
1135 |
return EFalse; |
|
1136 |
} |
|
1137 |
||
1138 |
// ---------------------------------------------------------------------------- |
|
1139 |
// CPcsAlgorithm1::ReplaceGroupsUriL |
|
1140 |
// Replace groups uri to contacts uri |
|
1141 |
// ---------------------------------------------------------------------------- |
|
1142 |
void CPcsAlgorithm1::ReplaceGroupsUriL( CPsSettings& aSettings ) |
|
1143 |
{ |
|
1144 |
RPointerArray<TDesC> uri; |
|
1145 |
CleanupResetAndDestroyPushL( uri ); |
|
1146 |
||
1147 |
// Set contacts db uri |
|
1148 |
HBufC* cntdb = KVPbkDefaultCntDbURI().AllocLC(); |
|
1149 |
uri.AppendL(cntdb); |
|
1150 |
CleanupStack::Pop( cntdb ); // ownership transferred |
|
1151 |
aSettings.SetSearchUrisL(uri); |
|
1152 |
||
1153 |
// Cleanup |
|
1154 |
CleanupStack::PopAndDestroy( &uri ); // ResetAndDestroy |
|
1155 |
} |
|
1156 |
||
1157 |
// ---------------------------------------------------------------------------- |
|
1158 |
// CPcsAlgorithm1::FilterSearchResultsForGroupsL |
|
1159 |
// Filters the results that belong to a group |
|
1160 |
// ---------------------------------------------------------------------------- |
|
1161 |
void CPcsAlgorithm1::FilterSearchResultsForGroupsL(RArray<TInt>& contactsInGroup, |
|
1162 |
RPointerArray<CPsData>& aSearchResults) |
|
1163 |
{ |
|
1164 |
PRINT ( _L("Enter CPcsAlgorithm1::FilterSearchResultsForGroupsL") ); |
|
1165 |
||
1166 |
// for each search result |
|
1167 |
// Note: aSearchResults.Count() is to be checked everytime, |
|
1168 |
// since the elements are being removed dynamically. |
|
1169 |
for ( TInt j = 0 ; j < aSearchResults.Count(); j++ ) |
|
1170 |
{ |
|
1171 |
TBool includeResult = EFalse; |
|
1172 |
||
1173 |
if ( contactsInGroup.Find(aSearchResults[j]->Id()) != KErrNotFound ) |
|
1174 |
{ |
|
1175 |
includeResult = ETrue; |
|
1176 |
} |
|
1177 |
||
1178 |
if ( includeResult == EFalse ) |
|
1179 |
{ |
|
1180 |
aSearchResults.Remove(j); |
|
1181 |
j--; // j is decremented, since that object is removed |
|
1182 |
} |
|
1183 |
} |
|
1184 |
||
1185 |
PRINT ( _L("End CPcsAlgorithm1::FilterSearchResultsForGroupsL") ); |
|
1186 |
} |
|
1187 |
||
1188 |
||
1189 |
// ---------------------------------------------------------------------------- |
|
1190 |
// CPcsAlgorithm1::GetContactsInGroupL |
|
1191 |
// Recover contacts that belong to a group |
|
1192 |
// ---------------------------------------------------------------------------- |
|
1193 |
void CPcsAlgorithm1::GetContactsInGroupL( TInt aGroupId, |
|
1194 |
RArray<TInt>& aGroupContactIds ) |
|
1195 |
{ |
|
1196 |
// Clear results array |
|
1197 |
aGroupContactIds.Reset(); |
|
1198 |
||
1199 |
// Cache Index for group database |
|
1200 |
TInt cacheIndex = GetCacheIndex(KVPbkDefaultGrpDbURI); |
|
1201 |
||
1202 |
// Get the groups contact ids |
|
1203 |
if ( cacheIndex != -1 ) |
|
1204 |
{ |
|
1205 |
RPointerArray<CPsData> groups; |
|
1206 |
CleanupClosePushL( groups ); |
|
1207 |
||
1208 |
// Get all groups |
|
1209 |
iPcsCache[cacheIndex]->GetAllContentsL(groups); |
|
1210 |
||
1211 |
// Get all contacts in group |
|
1212 |
for ( TInt i = 0; i < groups.Count(); i++ ) |
|
1213 |
{ |
|
1214 |
if ( groups[i]->Id() == aGroupId ) |
|
1215 |
{ |
|
1216 |
groups[i]->IntDataExt(aGroupContactIds); // All contacts in group |
|
1217 |
break; |
|
1218 |
} |
|
1219 |
} |
|
1220 |
||
1221 |
CleanupStack::PopAndDestroy( &groups ); // Close |
|
1222 |
} |
|
1223 |
} |
|
1224 |
||
1225 |
// ---------------------------------------------------------------------------- |
|
1226 |
// CPcsAlgorithm1::GetDataOrderL |
|
1227 |
// |
|
1228 |
// ---------------------------------------------------------------------------- |
|
1229 |
void CPcsAlgorithm1::GetDataOrderL ( TDesC& aURI, |
|
1230 |
RArray<TInt>& aDataOrder ) |
|
1231 |
{ |
|
1232 |
PRINT ( _L("End CPcsAlgorithm1::GetDataOrderL") ); |
|
1233 |
||
1234 |
TInt arrayIndex = KErrNotFound; |
|
1235 |
||
1236 |
if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
|
1237 |
{ |
|
1238 |
// If search in a group uri, use contacts db |
|
1239 |
arrayIndex = GetCacheIndex(KVPbkDefaultCntDbURI); |
|
1240 |
} |
|
1241 |
else |
|
1242 |
{ |
|
1243 |
arrayIndex = GetCacheIndex(aURI); |
|
1244 |
} |
|
1245 |
||
1246 |
if ( arrayIndex < 0 ) return; |
|
1247 |
||
1248 |
CPcsCache* cache = iPcsCache[arrayIndex]; |
|
1249 |
||
1250 |
aDataOrder.Reset(); |
|
1251 |
||
1252 |
// Get the data fields for this cache |
|
1253 |
cache->GetDataFields(aDataOrder); |
|
1254 |
||
1255 |
PRINT ( _L("End CPcsAlgorithm1::GetDataOrderL") ); |
|
1256 |
} |
|
1257 |
||
1258 |
// ---------------------------------------------------------------------------- |
|
1259 |
// CPcsAlgorithm1::GetSortOrderL |
|
1260 |
// |
|
1261 |
// ---------------------------------------------------------------------------- |
|
1262 |
void CPcsAlgorithm1::GetSortOrderL ( TDesC& aURI, |
|
1263 |
RArray<TInt>& aDataOrder ) |
|
1264 |
{ |
|
1265 |
PRINT ( _L("End CPcsAlgorithm1::GetSortOrderL") ); |
|
1266 |
||
1267 |
TInt arrayIndex = KErrNotFound; |
|
1268 |
||
1269 |
if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
|
1270 |
{ |
|
1271 |
// If search in a group uri, use contacts db |
|
1272 |
arrayIndex = GetCacheIndex(KVPbkDefaultCntDbURI); |
|
1273 |
} |
|
1274 |
else |
|
1275 |
{ |
|
1276 |
arrayIndex = GetCacheIndex(aURI); |
|
1277 |
} |
|
1278 |
||
1279 |
if ( arrayIndex < 0 ) return; |
|
1280 |
||
1281 |
CPcsCache* cache = iPcsCache[arrayIndex]; |
|
1282 |
||
1283 |
aDataOrder.Reset(); |
|
1284 |
||
1285 |
// Get the data fields for this cache |
|
1286 |
cache->GetSortOrder(aDataOrder); |
|
1287 |
||
1288 |
PRINT ( _L("End CPcsAlgorithm1::GetSortOrderL") ); |
|
1289 |
} |
|
1290 |
||
1291 |
// ---------------------------------------------------------------------------- |
|
1292 |
// CPcsAlgorithm1::ChangeSortOrderL |
|
1293 |
// |
|
1294 |
// ---------------------------------------------------------------------------- |
|
1295 |
void CPcsAlgorithm1::ChangeSortOrderL ( TDesC& aURI, |
|
1296 |
RArray<TInt>& aSortOrder ) |
|
1297 |
{ |
|
1298 |
PRINT ( _L("Enter CPcsAlgorithm1::ChangeSortOrderL") ); |
|
1299 |
||
1300 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change received.") ); |
|
1301 |
PRINT1 ( _L("CPcsAlgorithm1::ChangeSortOrderL. URI = %S"), &aURI ); |
|
1302 |
||
1303 |
// If URI is search in a group URI return |
|
1304 |
if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
|
1305 |
{ |
|
1306 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change not supported.") ); |
|
1307 |
return; |
|
1308 |
} |
|
1309 |
||
1310 |
// Check if a cache exists |
|
1311 |
TInt arrayIndex = GetCacheIndex(aURI); |
|
1312 |
if ( arrayIndex < 0 ) |
|
1313 |
{ |
|
1314 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Cache for URI doesn't exist.") ); |
|
1315 |
return; |
|
1316 |
} |
|
1317 |
||
1318 |
// Cache instance for this URI |
|
1319 |
CPcsCache* cache = iPcsCache[arrayIndex]; |
|
1320 |
||
1321 |
// Check if received sort order is same as before |
|
1322 |
RArray<TInt> mySortOrder; |
|
1323 |
cache->GetSortOrder(mySortOrder); |
|
1324 |
||
1325 |
if ( aSortOrder.Count() == mySortOrder.Count() ) |
|
1326 |
{ |
|
1327 |
TBool same = ETrue; |
|
1328 |
for ( TInt i = 0; i < mySortOrder.Count(); i++ ) |
|
1329 |
{ |
|
1330 |
if ( mySortOrder[i] != aSortOrder[i] ) |
|
1331 |
{ |
|
1332 |
same = EFalse; |
|
1333 |
break; |
|
1334 |
} |
|
1335 |
} |
|
1336 |
||
1337 |
if ( same ) |
|
1338 |
{ |
|
1339 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Same sort order received. Ignoring ...") ); |
|
1340 |
PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL.") ); |
|
1341 |
mySortOrder.Reset(); |
|
1342 |
return; |
|
1343 |
} |
|
1344 |
} |
|
1345 |
||
1346 |
mySortOrder.Reset(); |
|
1347 |
||
1348 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. New sort order received. Refreshing ...") ); |
|
1349 |
// Set the new sort order on the cache |
|
1350 |
cache->SetSortOrder(aSortOrder); |
|
1351 |
||
1352 |
// Persist the changes in sort order |
|
1353 |
WriteSortOrderToCenRepL(aURI, aSortOrder); |
|
1354 |
||
1355 |
// Resort data |
|
1356 |
TInt err = KErrNone; |
|
1357 |
TRAP(err, cache->ResortdataInPoolsL()); |
|
1358 |
if ( err != KErrNone ) |
|
1359 |
{ |
|
1360 |
PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL() Set Caching Error ") ); |
|
1361 |
SetCachingError(aURI, err); |
|
1362 |
UpdateCachingStatus(aURI,ECachingCompleteWithErrors); |
|
1363 |
return; |
|
1364 |
} |
|
1365 |
||
1366 |
PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL") ); |
|
1367 |
} |
|
1368 |
||
1369 |
// ---------------------------------------------------------------------------- |
|
1370 |
// CPcsAlgorithm1::GetAdaptiveGridL |
|
1371 |
// |
|
1372 |
// ---------------------------------------------------------------------------- |
|
1373 |
void CPcsAlgorithm1::GetAdaptiveGridL( const MDesCArray& aURIs, |
|
1374 |
const TBool aCompanyName, |
|
1375 |
TDes& aAdaptiveGrid ) |
|
1376 |
{ |
|
1377 |
PRINT ( _L("Enter CPcsAlgorithm1::GetAdaptiveGridL") ); |
|
1378 |
||
1379 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Request of Adaptive Grid for %d URI(s)"), |
|
1380 |
aURIs.MdcaCount() ); |
|
1381 |
||
1382 |
if ( iCacheStatus != ECachingComplete ) |
|
1383 |
{ |
|
1384 |
PRINT ( _L("CPcsAlgorithm1::GetAdaptiveGridL: PCS Caching is not ready, returning empty Adaptive Grid") ); |
|
1385 |
aAdaptiveGrid.Zero(); |
|
1386 |
} |
|
1387 |
else |
|
1388 |
{ |
|
1389 |
GetAdaptiveGridFromCacheL( aURIs, aCompanyName, aAdaptiveGrid ); |
|
1390 |
} |
|
1391 |
||
1392 |
PRINT ( _L("End CPcsAlgorithm1::GetAdaptiveGridL") ); |
|
1393 |
} |
|
1394 |
||
1395 |
// ---------------------------------------------------------------------------- |
|
1396 |
// CPcsAlgorithm1::GetAdaptiveGridFromCacheL |
|
1397 |
// |
|
1398 |
// ---------------------------------------------------------------------------- |
|
1399 |
void CPcsAlgorithm1::GetAdaptiveGridFromCacheL( const MDesCArray& aURIs, |
|
1400 |
const TBool aCompanyName, |
|
1401 |
TDes& aAdaptiveGrid ) |
|
1402 |
{ |
|
1403 |
PRINT ( _L("Enter CPcsAlgorithm1::GetAdaptiveGridFromCacheL") ); |
|
1404 |
||
1405 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Request of Adaptive Grid for %d URI(s)"), |
|
1406 |
aURIs.MdcaCount() ); |
|
1407 |
||
1408 |
RArray<TInt> cacheIds; |
|
1409 |
CleanupClosePushL( cacheIds ); |
|
1410 |
||
1411 |
// Create the list of the cache indexes that will form the Adaptive Grid |
|
1412 |
for ( TInt i=0; i < aURIs.MdcaCount(); i++ ) |
|
1413 |
{ |
|
1414 |
TPtrC16 uri = aURIs.MdcaPoint(i); |
|
1415 |
||
1416 |
// If URI is a group URI skip it |
|
1417 |
if ( CPcsAlgorithm1Utils::IsGroupUri( uri ) ) |
|
1418 |
{ |
|
1419 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid for URI \"%S\" is not supported. Skipping"), |
|
1420 |
&uri ); |
|
1421 |
continue; |
|
1422 |
} |
|
1423 |
||
1424 |
TInt cacheIndex = GetCacheIndex( uri ); |
|
1425 |
if ( cacheIndex == KErrNotFound ) |
|
1426 |
{ |
|
1427 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Cache for URI \"%S\" doesn't exist"), |
|
1428 |
&uri ); |
|
1429 |
continue; |
|
1430 |
} |
|
1431 |
||
1432 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Cache for URI \"%S\" will be used to form the Adaptive Grid"), |
|
1433 |
&uri ); |
|
1434 |
||
1435 |
cacheIds.AppendL( cacheIndex ); |
|
1436 |
} |
|
1437 |
||
1438 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Number of caches that will be used to form the grid is %d"), |
|
1439 |
cacheIds.Count( ) ); |
|
1440 |
||
1441 |
// Create the Adaptive Grid from the cache(s) |
|
1442 |
if ( cacheIds.Count() == 1 ) // No merge if we have only one cache |
|
1443 |
{ |
|
1444 |
// Cache instance for this URI |
|
1445 |
CPcsCache* cache = iPcsCache[cacheIds[0]]; |
|
1446 |
||
1447 |
// Get the Adaptive Grid |
|
1448 |
cache->GetAdaptiveGridL( aCompanyName, aAdaptiveGrid ); |
|
1449 |
||
1450 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid: \"%S\" (No merge was needed)"), |
|
1451 |
&aAdaptiveGrid ); |
|
1452 |
} |
|
1453 |
else if ( cacheIds.Count() > 1 ) // Merge if we have more than one cache |
|
1454 |
{ |
|
1455 |
RArray<TChar> gridAll; |
|
1456 |
CleanupClosePushL( gridAll ); |
|
1457 |
TUint gridSize = 0; |
|
1458 |
||
1459 |
HBufC16* gridOne = HBufC::NewLC(KPsAdaptiveGridStringMaxLen); |
|
1460 |
TPtr16 gridOnePtr( gridOne->Des( )); |
|
1461 |
||
1462 |
TLinearOrder<TChar> rule( CPcsAlgorithm1Utils::CompareByCharacter ); |
|
1463 |
||
1464 |
// Loop through the caches that form the Adaptive Grid |
|
1465 |
for ( TUint i=0; |
|
1466 |
gridSize < KPsAdaptiveGridStringMaxLen && i < cacheIds.Count(); |
|
1467 |
i++ ) |
|
1468 |
{ |
|
1469 |
// Cache instance for this URI |
|
1470 |
CPcsCache* cache = iPcsCache[cacheIds[i]]; |
|
1471 |
||
1472 |
// Get the Adaptive Grid |
|
1473 |
gridOnePtr.Zero(); |
|
1474 |
cache->GetAdaptiveGridL( aCompanyName, gridOnePtr ); |
|
1475 |
||
1476 |
PRINT2 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid for cache \"%S\" is \"%S\""), |
|
1477 |
&cache->GetURI(), &gridOnePtr ); |
|
1478 |
||
1479 |
// Loop through the characters of the Adaptive Grid for the cache |
|
1480 |
for ( TUint j=0; |
|
1481 |
gridSize < KPsAdaptiveGridStringMaxLen && j < gridOnePtr.Length(); |
|
1482 |
j++ ) |
|
1483 |
{ |
|
1484 |
if ( i == 0 ) // Grid from one cache is already ordered with no repetitions |
|
1485 |
{ |
|
1486 |
gridAll.Append( gridOnePtr[j]); |
|
1487 |
} |
|
1488 |
else // Grids from more caches can have repeated characters |
|
1489 |
{ |
|
1490 |
gridAll.InsertInOrder( gridOnePtr[j], rule ); // No repeats !!! |
|
1491 |
} |
|
1492 |
gridSize++; |
|
1493 |
} |
|
1494 |
} |
|
1495 |
||
1496 |
// Form the Adaptive Grid to be returned |
|
1497 |
aAdaptiveGrid.Zero(); |
|
1498 |
for ( TUint i=0; i < gridAll.Count(); i++ ) |
|
1499 |
{ |
|
1500 |
aAdaptiveGrid.Append( gridAll[i] ); |
|
1501 |
} |
|
1502 |
||
1503 |
PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid: \"%S\" (Merge was done)"), |
|
1504 |
&aAdaptiveGrid ); |
|
1505 |
||
1506 |
CleanupStack::PopAndDestroy( gridOne ); |
|
1507 |
CleanupStack::PopAndDestroy( &gridAll ); // Close |
|
1508 |
} |
|
1509 |
||
1510 |
CleanupStack::PopAndDestroy( &cacheIds ); // Close |
|
1511 |
||
1512 |
PRINT ( _L("End CPcsAlgorithm1::GetAdaptiveGridFromCacheL") ); |
|
1513 |
} |
|
1514 |
||
1515 |
// --------------------------------------------------------------------------------- |
|
1516 |
// Read the persisted sort order from the central repository |
|
1517 |
// Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
|
1518 |
// --------------------------------------------------------------------------------- |
|
1519 |
void CPcsAlgorithm1::ReadSortOrderFromCenRepL(const TDesC& aURI, |
|
1520 |
RArray<TInt>& aSortOrder) |
|
1521 |
{ |
|
1522 |
PRINT ( _L("Enter CPcsAlgorithm1::ReadSortOrderFromCenRepL.") ); |
|
1523 |
||
1524 |
aSortOrder.Reset(); |
|
1525 |
||
1526 |
CRepository *repository = CRepository::NewL( KCRUidPSSortOrder ); |
|
1527 |
||
1528 |
// Read the sort order from cenrep |
|
1529 |
TBuf<KCRMaxLen> str; |
|
1530 |
||
1531 |
for ( TInt i(KCenrepFieldsStartKey); |
|
1532 |
i < KCenrepFieldsStartKey + KCenrepNumberOfFieldsCount; |
|
1533 |
i++ ) |
|
1534 |
{ |
|
1535 |
TInt err = repository->Get( i, str ); |
|
1536 |
||
1537 |
if ( KErrNone != err ) |
|
1538 |
{ |
|
1539 |
break; |
|
1540 |
} |
|
1541 |
||
1542 |
if (str != KNullDesC) |
|
1543 |
{ |
|
1544 |
TLex lex(str); |
|
1545 |
||
1546 |
// Extract the URI |
|
1547 |
TPtrC token = lex.NextToken(); |
|
1548 |
||
1549 |
if ( aURI.Compare(token) == 0 ) |
|
1550 |
{ |
|
1551 |
// Extract the sort order |
|
1552 |
token.Set(lex.NextToken()); |
|
1553 |
||
1554 |
while ( token.Length() != 0 ) |
|
1555 |
{ |
|
1556 |
TLex lex1(token); |
|
1557 |
||
1558 |
TInt intVal; |
|
1559 |
TInt err = lex1.Val(intVal); |
|
1560 |
||
1561 |
if ( KErrNone == err ) |
|
1562 |
{ |
|
1563 |
aSortOrder.Append(intVal); |
|
1564 |
} |
|
1565 |
||
1566 |
// Next token |
|
1567 |
token.Set(lex.NextToken()); |
|
1568 |
} |
|
1569 |
||
1570 |
break; |
|
1571 |
} |
|
1572 |
} |
|
1573 |
||
1574 |
} |
|
1575 |
||
1576 |
delete repository; |
|
1577 |
||
1578 |
PRINT ( _L("End CPcsAlgorithm1::ReadSortOrderFromCenRepL.") ); |
|
1579 |
} |
|
1580 |
||
1581 |
// --------------------------------------------------------------------------------- |
|
1582 |
// Write the sort order into the central repository |
|
1583 |
// Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
|
1584 |
// --------------------------------------------------------------------------------- |
|
1585 |
void CPcsAlgorithm1::WriteSortOrderToCenRepL(const TDesC& aURI, |
|
1586 |
RArray<TInt>& aSortOrder) |
|
1587 |
{ |
|
1588 |
PRINT ( _L("Enter CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
|
1589 |
||
1590 |
CRepository *repository = CRepository::NewLC( KCRUidPSSortOrder ); |
|
1591 |
||
1592 |
// Check if there an entry for this URI in cenrep |
|
1593 |
TBuf<KCRMaxLen> str; |
|
1594 |
TInt keyIndex = -1; |
|
1595 |
||
1596 |
for ( TInt i(KCenrepFieldsStartKey); |
|
1597 |
i < KCenrepFieldsStartKey + KCenrepNumberOfFieldsCount; |
|
1598 |
i++ ) |
|
1599 |
{ |
|
1600 |
TInt err = repository->Get( i, str ); |
|
1601 |
||
1602 |
if ( KErrNone != err ) |
|
1603 |
{ |
|
1604 |
PRINT ( _L("CPcsAlgorithm1::WriteSortOrderToCenRepL. cenrep error.") ); |
|
1605 |
return; |
|
1606 |
} |
|
1607 |
||
1608 |
if (str != KNullDesC) |
|
1609 |
{ |
|
1610 |
TLex lex(str); |
|
1611 |
||
1612 |
// Extract the URI |
|
1613 |
TPtrC token = lex.NextToken(); |
|
1614 |
||
1615 |
if ( aURI.Compare(token) == 0 ) |
|
1616 |
{ |
|
1617 |
keyIndex = i; // i has the key index for this URI |
|
1618 |
break; |
|
1619 |
} |
|
1620 |
} |
|
1621 |
} |
|
1622 |
||
1623 |
// No entry for this URI in cenrep |
|
1624 |
// Find the next free location in cenrep |
|
1625 |
if ( keyIndex == -1 ) |
|
1626 |
{ |
|
1627 |
// Find the next free key index |
|
1628 |
for ( TInt i(KCenrepFieldsStartKey); |
|
1629 |
i < KCenrepFieldsStartKey + KCenrepNumberOfFieldsCount; |
|
1630 |
i++ ) |
|
1631 |
{ |
|
1632 |
TInt err = repository->Get( i, str ); |
|
1633 |
||
1634 |
if ( KErrNone != err ) |
|
1635 |
{ |
|
1636 |
PRINT ( _L("CPcsAlgorithm1::WriteSortOrderToCenRepL. cenrep error.") ); |
|
1637 |
return; |
|
1638 |
} |
|
1639 |
||
1640 |
if (str == KNullDesC) |
|
1641 |
{ |
|
1642 |
keyIndex = i; // i has the next free location |
|
1643 |
break; |
|
1644 |
} |
|
1645 |
} |
|
1646 |
} |
|
1647 |
||
1648 |
if ( keyIndex == -1 ) |
|
1649 |
{ |
|
1650 |
PRINT ( _L("CPcsAlgorithm1::WriteSortOrderToCenRepL. Persist limit violated.") ); |
|
1651 |
return; |
|
1652 |
} |
|
1653 |
||
1654 |
// Persist the sort order |
|
1655 |
HBufC* str1 = HBufC::NewLC(KCRMaxLen); |
|
1656 |
TPtr ptr(str1->Des()); |
|
1657 |
||
1658 |
// Append the URI |
|
1659 |
ptr.Append(aURI); |
|
1660 |
ptr.Append(KSpace); |
|
1661 |
||
1662 |
// Append the sort order fields |
|
1663 |
for ( TInt j = 0; j < aSortOrder.Count(); j++ ) |
|
1664 |
{ |
|
1665 |
ptr.AppendNum(aSortOrder[j]); |
|
1666 |
ptr.Append(KSpace); |
|
1667 |
} |
|
1668 |
||
1669 |
// Write to persistent store |
|
1670 |
TInt err = repository->Set(keyIndex, ptr); |
|
1671 |
||
1672 |
User::LeaveIfError(err); |
|
1673 |
||
1674 |
CleanupStack::PopAndDestroy( str1 ); |
|
1675 |
||
1676 |
CleanupStack::PopAndDestroy( repository ); |
|
1677 |
||
1678 |
PRINT ( _L("End CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
|
1679 |
} |
|
1680 |
||
1681 |
// --------------------------------------------------------------------------------- |
|
1682 |
// WriteClientDataL. |
|
1683 |
// Write the content required by client |
|
1684 |
// --------------------------------------------------------------------------------- |
|
1685 |
CPsClientData* CPcsAlgorithm1::WriteClientDataL( CPsData& aPsData ) |
|
1686 |
{ |
|
1687 |
CPsClientData* clientData = CPsClientData::NewL(); |
|
1688 |
CleanupStack::PushL(clientData); |
|
1689 |
||
1690 |
// set Id |
|
1691 |
clientData->SetId(aPsData.Id()); |
|
1692 |
||
1693 |
// set Uri |
|
1694 |
clientData->SetUriL(GetUriForIdL(aPsData.UriId())); |
|
1695 |
||
1696 |
// set pointer to the each data element |
|
1697 |
for(TInt i = 0; i < aPsData.DataElementCount(); i++) |
|
1698 |
{ |
|
1699 |
clientData->SetDataL(i, *(aPsData.Data(i))); |
|
1700 |
} |
|
1701 |
||
1702 |
// set data extension |
|
1703 |
clientData->SetDataExtensionL(aPsData.DataExtension()); |
|
1704 |
||
1705 |
// Set the Field match |
|
1706 |
clientData->SetFieldMatch(aPsData.DataMatch()) ; |
|
1707 |
CleanupStack::Pop(clientData); |
|
1708 |
||
1709 |
return clientData; |
|
1710 |
} |
|
1711 |
||
1712 |
// --------------------------------------------------------------------------------- |
|
1713 |
// HandleCacheUpdated. |
|
1714 |
// --------------------------------------------------------------------------------- |
|
1715 |
void CPcsAlgorithm1::HandleCacheUpdated( TCachingStatus aStatus ) |
|
1716 |
{ |
|
1717 |
TInt psKey( KErrNotFound ); |
|
1718 |
||
1719 |
switch ( aStatus ) |
|
1720 |
{ |
|
1721 |
case ECacheUpdateContactRemoved: |
|
1722 |
psKey = EPsKeyContactRemovedCounter; |
|
1723 |
break; |
|
1724 |
||
1725 |
case ECacheUpdateContactModified: |
|
1726 |
psKey = EPsKeyContactModifiedCounter; |
|
1727 |
break; |
|
1728 |
||
1729 |
case ECacheUpdateContactAdded: |
|
1730 |
psKey = EPsKeyContactAddedCounter; |
|
1731 |
break; |
|
1732 |
||
1733 |
default: |
|
1734 |
break; |
|
1735 |
} |
|
1736 |
||
1737 |
if ( psKey != KErrNotFound ) |
|
1738 |
{ |
|
1739 |
// Increment the related counter in P&S by one to signal the clients about |
|
1740 |
// the cache update. |
|
1741 |
TInt counter( KErrNotFound ); |
|
1742 |
TInt err = RProperty::Get( KPcsInternalUidCacheStatus, psKey, counter ); |
|
1743 |
if ( !err ) |
|
1744 |
{ |
|
1745 |
counter++; |
|
1746 |
RProperty::Set( KPcsInternalUidCacheStatus, psKey, counter ); |
|
1747 |
} |
|
1748 |
} |
|
1749 |
} |
|
1750 |
||
1751 |
// --------------------------------------------------------------------------------- |
|
1752 |
// DoLaunchPluginsL. |
|
1753 |
// launch plugins by idle |
|
1754 |
// --------------------------------------------------------------------------------- |
|
1755 |
TInt CPcsAlgorithm1::DoLaunchPluginsL(TAny* aPtr) |
|
1756 |
{ |
|
1757 |
CPcsAlgorithm1* ptr = (CPcsAlgorithm1*) aPtr; |
|
1758 |
ptr->DoLaunchPluginsL(); |
|
1759 |
return EFalse; |
|
1760 |
} |
|
1761 |
||
1762 |
// --------------------------------------------------------------------------------- |
|
1763 |
// DoLaunchPluginsL. |
|
1764 |
// lauch plugins |
|
1765 |
// --------------------------------------------------------------------------------- |
|
1766 |
void CPcsAlgorithm1::DoLaunchPluginsL() |
|
1767 |
{ |
|
1768 |
// Initialize available data adapters |
|
1769 |
iPsDataPluginInterface = CPsDataPluginInterface::NewL(this, this); |
|
1770 |
iPsDataPluginInterface->InstantiateAllPlugInsL(); |
|
1771 |
||
1772 |
// Store the cache list in TLS |
|
1773 |
// Required to support sort order changes in a memory efficient way |
|
1774 |
// This avoids storing sort order information in the CPsData element |
|
1775 |
// and storing it in CPcsCache. Refer CPcsAlgorithm1Utils::CompareDataBySortOrderL |
|
1776 |
// to see how this is being used. |
|
1777 |
User::LeaveIfError( Dll::SetTls(&iPcsCache) ); |
|
1778 |
||
1779 |
// Initialize cache |
|
1780 |
RPointerArray<TDesC> dataStores; |
|
1781 |
CleanupClosePushL( dataStores ); |
|
1782 |
||
1783 |
iPsDataPluginInterface->GetAllSupportedDataStoresL(dataStores); |
|
1784 |
||
1785 |
for ( TInt dIndex = 0; dIndex < dataStores.Count(); dIndex++ ) |
|
1786 |
{ |
|
1787 |
AddDataStore(*(dataStores[dIndex])); |
|
1788 |
} |
|
1789 |
||
1790 |
CleanupStack::PopAndDestroy( &dataStores ); // Close |
|
1791 |
} |
|
1792 |
||
1793 |
// End of file |
|
1794 |