74 { |
74 { |
75 PRINT ( _L("Enter CPcsAlgorithm1::ConstructL") ); |
75 PRINT ( _L("Enter CPcsAlgorithm1::ConstructL") ); |
76 |
76 |
77 iCacheStatus = ECachingNotStarted; // Starting status |
77 iCacheStatus = ECachingNotStarted; // Starting status |
78 iCacheError = KErrNone; // No error |
78 iCacheError = KErrNone; // No error |
79 iCacheCount = 0; // No data |
|
80 |
79 |
81 iPluginLauncher = CIdle::NewL( CActive::EPriorityStandard ); |
80 iPluginLauncher = CIdle::NewL( CActive::EPriorityStandard ); |
82 |
81 |
83 // Define cache status property used to inform clients about the caching status. |
82 // Define cache status property used to inform clients about the caching status. |
84 TInt err = RProperty::Define(KCStatus,0, RProperty::EInt); |
83 TInt err = RProperty::Define(KCStatus,0, RProperty::EInt); |
231 PRINT1 ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: Query modified (0=not, 1=yes): %d"), queryModified ); |
230 PRINT1 ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: Query modified (0=not, 1=yes): %d"), queryModified ); |
232 |
231 |
233 PRINT ( _L("End CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
232 PRINT ( _L("End CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
234 |
233 |
235 return queryModified; |
234 return queryModified; |
236 } |
235 } |
237 |
236 |
238 // ---------------------------------------------------------------------------- |
237 // ---------------------------------------------------------------------------- |
239 // CPcsAlgorithm1::PerformSearchL |
238 // CPcsAlgorithm1::PerformSearchL |
240 // Search function for cache |
239 // Search function for cache |
241 // ---------------------------------------------------------------------------- |
240 // ---------------------------------------------------------------------------- |
242 void CPcsAlgorithm1::PerformSearchL(const CPsSettings& aSettings, |
241 void CPcsAlgorithm1::PerformSearchL(const CPsSettings& aSettings, |
243 CPsQuery& aQuery, |
242 CPsQuery& aQuery, |
244 RPointerArray<CPsClientData>& aSearchResults, |
243 RPointerArray<CPsClientData>& aSearchResults, |
245 RPointerArray<CPsPattern>& aSearchSeqs) |
244 RPointerArray<CPsPattern>& aSearchSeqs) |
246 { |
245 { |
247 PRINT ( _L("Enter CPcsAlgorithm1::PerformSearchL") ); |
246 PRINT ( _L("Enter CPcsAlgorithm1::PerformSearchL") ); |
248 |
247 |
249 __LATENCY_MARK ( _L("CPcsAlgorithm1::PerformSearchL") ); |
248 __LATENCY_MARK ( _L("CPcsAlgorithm1::PerformSearchL") ); |
250 |
249 |
321 } |
320 } |
322 } |
321 } |
323 // ------------------------------------------------------------------------ |
322 // ------------------------------------------------------------------------ |
324 |
323 |
325 // ------------------ Write result objects to the stream ------------------ |
324 // ------------------ Write result objects to the stream ------------------ |
326 // Truncate the result set if required |
325 // Truncate the result set if required |
327 TInt numToDisplay = aSettings.MaxResults(); |
326 TInt maxNumToDisplay = aSettings.MaxResults(); |
328 TInt resultSet = tempSearchResults.Count(); |
327 TInt resultSetCount = tempSearchResults.Count(); |
329 |
328 TInt numToDisplay = 0; |
330 if( resultSet > numToDisplay && numToDisplay != -1) |
329 if ( maxNumToDisplay == -1 ) |
331 { |
330 { |
332 // Copy the top N contents from tempSearchResults to the results stream |
331 numToDisplay = resultSetCount; |
333 for(int i = 0; i < numToDisplay; i++) |
332 } |
334 { |
333 else |
335 aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
334 { |
336 } |
335 numToDisplay = Min( maxNumToDisplay, resultSetCount ); |
337 } |
336 } |
338 else |
337 |
339 { |
338 // Copy desired number of results from tempSearchResults to the results stream |
340 // Copy all the contents from tempSearchResults to the results stream |
339 for (TInt i = 0; i < numToDisplay; i++) |
341 for(TInt i = 0; i < resultSet; i++) |
340 { |
342 { |
341 aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
343 aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
342 } |
344 } |
|
345 } |
|
346 // ------------------------------------------------------------------------ |
343 // ------------------------------------------------------------------------ |
347 |
344 |
348 // Cleanup local results array |
345 // Cleanup local results array |
349 CleanupStack::PopAndDestroy( &tempSearchResultsMod ); // Close, don't destroy |
346 CleanupStack::PopAndDestroy( &tempSearchResultsMod ); // Close, don't destroy |
350 CleanupStack::PopAndDestroy( &tempSearchResultsIni ); // Close, don't destroy |
347 CleanupStack::PopAndDestroy( &tempSearchResultsIni ); // Close, don't destroy |
402 * We have to remove from aMatchLocation the occurrence that has a shorter match length. |
399 * We have to remove from aMatchLocation the occurrence that has a shorter match length. |
403 * We have to remove the match ("Nik" in this case) even from aMatchSet if there is not |
400 * We have to remove the match ("Nik" in this case) even from aMatchSet if there is not |
404 * any other match for it than the one in "Nik0". |
401 * any other match for it than the one in "Nik0". |
405 */ |
402 */ |
406 |
403 |
407 // --- Remove items from aMatchLocation --- |
404 // --- Remove duplicate items from aMatchLocation --- |
408 TInt i = 0; |
405 TInt i = 0; |
409 TBool incrementFirstCursor; |
406 TBool incrementFirstCursor; |
410 while ( i < aMatchLocation.Count() ) |
407 while ( i < aMatchLocation.Count() ) |
411 { |
408 { |
412 incrementFirstCursor = ETrue; |
409 incrementFirstCursor = ETrue; |
477 } |
474 } |
478 CleanupStack::PopAndDestroy( dataUpper ); |
475 CleanupStack::PopAndDestroy( dataUpper ); |
479 // ------------------------------------------------------------------------ |
476 // ------------------------------------------------------------------------ |
480 |
477 |
481 // Sort match set |
478 // Sort match set |
482 iHelper->SortSearchSeqsL(aMatchSet); |
479 iHelper->SortSearchSeqsL(aMatchSet); |
483 |
480 |
484 PRINTQUERY ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aQuery ); |
481 PRINTQUERY ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aQuery ); |
485 PRINT1 ( _L("CPcsAlgorithm1::SearchInputL: Final: Search Data: %S"), &aData ); |
482 PRINT1 ( _L("CPcsAlgorithm1::SearchInputL: Final: Search Data: %S"), &aData ); |
486 PRINTMATCHSET ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchSet ); |
483 PRINTMATCHSET ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchSet ); |
487 PRINTMATCHLOC ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchLocation ); |
484 PRINTMATCHLOC ( _L("CPcsAlgorithm1::SearchInputL: Final: "), aMatchLocation ); |
488 |
485 |
489 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::SearchInputL") ); |
486 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::SearchInputL") ); |
490 |
487 |
491 PRINT ( _L("End CPcsAlgorithm1::SearchInputL") ); |
488 PRINT ( _L("End CPcsAlgorithm1::SearchInputL") ); |
492 } |
489 } |
493 |
490 |
494 // ---------------------------------------------------------------------------- |
491 // ---------------------------------------------------------------------------- |
495 // CPcsAlgorithm1::SearchMatchStringL |
492 // CPcsAlgorithm1::SearchMatchStringL |
496 // Search function for input string, result also as string |
493 // Search function for input string, result also as string |
550 CleanupClosePushL( contactsInGroup ); |
547 CleanupClosePushL( contactsInGroup ); |
551 RArray<TInt> groupIdArray; |
548 RArray<TInt> groupIdArray; |
552 CleanupClosePushL( groupIdArray ); |
549 CleanupClosePushL( groupIdArray ); |
553 |
550 |
554 // Create a new settings instance |
551 // Create a new settings instance |
555 CPsSettings *tempSettings = aSettings.CloneL(); |
552 CPsSettings* tempSettings = aSettings.CloneL(); |
556 CleanupStack::PushL( tempSettings ); |
553 CleanupStack::PushL( tempSettings ); |
557 |
554 |
558 TBool isGroupSearch = IsGroupSearchL(*tempSettings, groupIdArray); |
555 TBool isGroupSearch = IsGroupSearchL(*tempSettings, groupIdArray); |
559 |
556 |
560 if ( isGroupSearch ) |
557 if ( isGroupSearch ) |
625 void CPcsAlgorithm1::DoSearchInputL(CPsQuery& aQuery, |
622 void CPcsAlgorithm1::DoSearchInputL(CPsQuery& aQuery, |
626 const TDesC& aData, |
623 const TDesC& aData, |
627 RPointerArray<TDesC>& aMatchSet, |
624 RPointerArray<TDesC>& aMatchSet, |
628 RArray<TPsMatchLocation>& aMatchLocation ) |
625 RArray<TPsMatchLocation>& aMatchLocation ) |
629 { |
626 { |
630 |
|
631 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchInputL") ); |
627 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchInputL") ); |
632 |
628 |
633 TInt queryWords = iMultiSearchHelper->CountMultiQueryWordsL(aQuery); |
629 TInt queryWords = iMultiSearchHelper->CountMultiQueryWordsL(aQuery); |
634 |
630 |
635 // No query |
631 // No query |
638 PRINT ( _L("CPcsAlgorithm1::DoSearchInputL: Query received is empty") ); |
634 PRINT ( _L("CPcsAlgorithm1::DoSearchInputL: Query received is empty") ); |
639 return; |
635 return; |
640 } |
636 } |
641 |
637 |
642 RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
638 RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
|
639 CleanupResetAndDestroyPushL( queryList ); |
643 |
640 |
644 PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchInputL: "), queryList ); |
641 PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchInputL: "), queryList ); |
645 |
642 |
646 if ( queryList.Count() == 1 ) // Single query |
643 if ( queryList.Count() == 1 ) // Single query |
647 { |
644 { |
659 aMatchSet, |
656 aMatchSet, |
660 aMatchLocation); |
657 aMatchLocation); |
661 } |
658 } |
662 |
659 |
663 // Delete all the query elements |
660 // Delete all the query elements |
664 queryList.ResetAndDestroy(); |
661 CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
665 |
662 |
666 PRINT ( _L("End CPcsAlgorithm1::DoSearchInputL") ); |
663 PRINT ( _L("End CPcsAlgorithm1::DoSearchInputL") ); |
667 } |
664 } |
668 |
665 |
669 // ---------------------------------------------------------------------------- |
666 // ---------------------------------------------------------------------------- |
670 // CPcsAlgorithm1::AddData |
667 // CPcsAlgorithm1::AddData |
671 // Add a data element to the pool |
668 // Add a data element to the pool |
672 // ---------------------------------------------------------------------------- |
669 // ---------------------------------------------------------------------------- |
673 void CPcsAlgorithm1::AddData(TDesC& aDataStore, CPsData* aData) |
670 void CPcsAlgorithm1::AddData(TDesC& aDataStore, CPsData* aData) |
760 if ( index != -1 ) |
757 if ( index != -1 ) |
761 { |
758 { |
762 // Already exists |
759 // Already exists |
763 return; |
760 return; |
764 } |
761 } |
765 |
762 |
766 // Create a new cache |
763 // Create a new cache |
767 CPcsCache* cache = NULL; |
764 CPcsCache* cache = NULL; |
768 TRAPD(err, cache = CPcsCache::NewL(aDataStore, *iKeyMap, iCacheCount)); |
765 TRAPD(err, cache = CPcsCache::NewL(aDataStore, *iKeyMap, (TUint8) iPcsCache.Count())); |
769 if ( err != KErrNone ) |
766 if ( err != KErrNone ) |
770 { |
767 { |
771 SetCachingError(aDataStore, err); |
768 SetCachingError(aDataStore, err); |
772 return; |
769 return; |
773 } |
770 } |
774 |
|
775 // Increment the cachecount |
|
776 iCacheCount++; |
|
777 |
771 |
778 RArray<TInt> dataFields; |
772 RArray<TInt> dataFields; |
779 TRAP(err, iPsDataPluginInterface->GetSupportedDataFieldsL(cache->GetURI(), dataFields)); |
773 TRAP(err, iPsDataPluginInterface->GetSupportedDataFieldsL(cache->GetURI(), dataFields)); |
780 if ( err != KErrNone ) |
774 if ( err != KErrNone ) |
781 { |
775 { |
784 } |
778 } |
785 cache->SetDataFields(dataFields); |
779 cache->SetDataFields(dataFields); |
786 |
780 |
787 // Check if sort order is persisted already |
781 // Check if sort order is persisted already |
788 RArray<TInt> sortOrder; |
782 RArray<TInt> sortOrder; |
789 TRAP(err, ReadSortOrderFromCenRepL(*(cache->GetUri()), sortOrder)); |
783 TRAP(err, ReadSortOrderFromCenRepL(cache->GetURI(), sortOrder)); |
790 if ( err != KErrNone ) |
784 if ( err != KErrNone ) |
791 { |
785 { |
792 SetCachingError(aDataStore, err); |
786 SetCachingError(aDataStore, err); |
793 return; |
787 return; |
794 } |
788 } |
866 if ( ! found ) |
859 if ( ! found ) |
867 { |
860 { |
868 User::Leave(KErrNotFound); |
861 User::Leave(KErrNotFound); |
869 } |
862 } |
870 |
863 |
871 return *(iPcsCache[i]->GetUri()); |
864 return iPcsCache[i]->GetURI(); |
872 } |
865 } |
873 |
866 |
874 // ---------------------------------------------------------------------------- |
867 // ---------------------------------------------------------------------------- |
875 // CPcsAlgorithm1::FindStoreUri |
868 // CPcsAlgorithm1::FindStoreUri |
876 // Checks if this store exists |
869 // Checks if this store exists |
877 // ---------------------------------------------------------------------------- |
870 // ---------------------------------------------------------------------------- |
878 TInt CPcsAlgorithm1::FindStoreUri ( const TDesC& aDataStore ) |
871 TInt CPcsAlgorithm1::FindStoreUri ( const TDesC& aDataStore ) |
879 { |
872 { |
880 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
873 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
881 { |
874 { |
882 if ( aDataStore.CompareC(*(iPcsCache[i]->GetUri())) == 0 ) |
875 if ( aDataStore.CompareC(iPcsCache[i]->GetURI()) == 0 ) |
883 { |
876 { |
884 return i; |
877 return i; |
885 } |
878 } |
886 } |
879 } |
887 |
880 |
953 void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError) |
946 void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError) |
954 { |
947 { |
955 PRINT2 ( _L("SetCachingError::URI %S ERROR %d"), &aDataStore, aError ); |
948 PRINT2 ( _L("SetCachingError::URI %S ERROR %d"), &aDataStore, aError ); |
956 |
949 |
957 iCacheError = aError; |
950 iCacheError = aError; |
958 RProperty::Set( KCStatus,1,iCacheError ); |
951 RProperty::Set( KCStatus, 1, iCacheError ); |
959 } |
952 } |
960 |
953 |
961 // ---------------------------------------------------------------------------- |
954 // ---------------------------------------------------------------------------- |
962 // CPcsAlgorithm1::GetAllContentsL |
955 // CPcsAlgorithm1::GetAllContentsL |
963 // Returns all the contents of a store |
956 // Returns all the contents of a store |
1155 TInt arrayIndex = -1; |
1148 TInt arrayIndex = -1; |
1156 |
1149 |
1157 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1150 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1158 { |
1151 { |
1159 // If search in a group uri, use contacts db |
1152 // If search in a group uri, use contacts db |
1160 TBuf<255> cntdb(KVPbkDefaultCntDbURI); |
1153 arrayIndex = GetCacheIndex(KVPbkDefaultCntDbURI); |
1161 arrayIndex = GetCacheIndex(cntdb); |
|
1162 } |
1154 } |
1163 else |
1155 else |
1164 { |
1156 { |
1165 arrayIndex = GetCacheIndex(aURI); |
1157 arrayIndex = GetCacheIndex(aURI); |
1166 } |
1158 } |
1184 void CPcsAlgorithm1::GetSortOrderL ( TDesC& aURI, |
1176 void CPcsAlgorithm1::GetSortOrderL ( TDesC& aURI, |
1185 RArray<TInt>& aDataOrder ) |
1177 RArray<TInt>& aDataOrder ) |
1186 { |
1178 { |
1187 PRINT ( _L("End CPcsAlgorithm1::GetSortOrderL") ); |
1179 PRINT ( _L("End CPcsAlgorithm1::GetSortOrderL") ); |
1188 |
1180 |
1189 TInt arrayIndex = -1; |
1181 TInt arrayIndex = -1; |
1190 |
1182 |
1191 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1183 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1192 { |
1184 { |
1193 // If search in a group uri, use contacts db |
1185 // If search in a group uri, use contacts db |
1194 TBuf<255> cntdb(KVPbkDefaultCntDbURI); |
1186 TBuf<255> cntdb(KVPbkDefaultCntDbURI); |
1195 arrayIndex = GetCacheIndex(cntdb); |
1187 arrayIndex = GetCacheIndex(cntdb); |
1196 } |
1188 } |
1197 else |
1189 else |
1198 { |
1190 { |
1199 arrayIndex = GetCacheIndex(aURI); |
1191 arrayIndex = GetCacheIndex(aURI); |
1200 } |
1192 } |
1201 |
1193 |
1202 if ( arrayIndex < 0 ) return; |
1194 if ( arrayIndex < 0 ) return; |
1203 |
1195 |
1221 PRINT ( _L("Enter CPcsAlgorithm1::ChangeSortOrderL.") ); |
1213 PRINT ( _L("Enter CPcsAlgorithm1::ChangeSortOrderL.") ); |
1222 |
1214 |
1223 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change received.") ); |
1215 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change received.") ); |
1224 PRINT1 ( _L("URI = %S"), &aURI ); |
1216 PRINT1 ( _L("URI = %S"), &aURI ); |
1225 |
1217 |
1226 // If URI is search in a group URI return |
1218 // If URI is search in a group URI return |
1227 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1219 if ( CPcsAlgorithm1Utils::IsGroupUri(aURI) ) |
1228 { |
1220 { |
1229 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change not supported.") ); |
1221 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Sort order change not supported.") ); |
1230 return; |
1222 return; |
1231 } |
1223 } |
1245 RArray<TInt> mySortOrder; |
1237 RArray<TInt> mySortOrder; |
1246 cache->GetSortOrder(mySortOrder); |
1238 cache->GetSortOrder(mySortOrder); |
1247 |
1239 |
1248 if ( aSortOrder.Count() == mySortOrder.Count() ) |
1240 if ( aSortOrder.Count() == mySortOrder.Count() ) |
1249 { |
1241 { |
1250 TBool same = ETrue; |
1242 TBool same = ETrue; |
1251 for ( TInt i = 0; i < mySortOrder.Count(); i++ ) |
1243 for ( TInt i = 0; i < mySortOrder.Count(); i++ ) |
1252 { |
1244 { |
1253 if ( mySortOrder[i] != aSortOrder[i] ) |
1245 if ( mySortOrder[i] != aSortOrder[i] ) |
1254 { |
1246 { |
1255 same = EFalse; |
1247 same = EFalse; |
1256 break; |
1248 break; |
1257 } |
1249 } |
1258 } |
1250 } |
1259 |
1251 |
1260 if ( same ) |
1252 if ( same ) |
1261 { |
1253 { |
1262 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Same sort order received. Ignoring ...") ); |
1254 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. Same sort order received. Ignoring ...") ); |
1263 PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL.") ); |
1255 PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL.") ); |
1264 mySortOrder.Reset(); |
1256 mySortOrder.Reset(); |
1265 return; |
1257 return; |
1266 } |
1258 } |
1267 } |
1259 } |
1268 |
1260 |
1269 mySortOrder.Reset(); |
1261 mySortOrder.Reset(); |
1270 |
1262 |
1271 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. New sort order received. Refreshing ...") ); |
1263 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL. New sort order received. Refreshing ...") ); |
1282 { |
1274 { |
1283 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL() Set Caching Error ") ); |
1275 PRINT ( _L("CPcsAlgorithm1::ChangeSortOrderL() Set Caching Error ") ); |
1284 SetCachingError(aURI, err); |
1276 SetCachingError(aURI, err); |
1285 UpdateCachingStatus(aURI,ECachingCompleteWithErrors); |
1277 UpdateCachingStatus(aURI,ECachingCompleteWithErrors); |
1286 return; |
1278 return; |
1287 } |
1279 } |
1288 |
1280 |
1289 PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL.") ); |
1281 PRINT ( _L("End CPcsAlgorithm1::ChangeSortOrderL.") ); |
1290 } |
1282 } |
1291 |
1283 |
1292 // --------------------------------------------------------------------------------- |
1284 // --------------------------------------------------------------------------------- |