93 { |
93 { |
94 User::LeaveIfError(err); |
94 User::LeaveIfError(err); |
95 } |
95 } |
96 |
96 |
97 // Initialize key map and pti engine |
97 // Initialize key map and pti engine |
98 //keyMap = CPcsKeyMap::NewL(); |
98 //iKeyMap = CPcsKeyMap::NewL(); |
99 TInt keyMapErr = KErrNone; |
99 TInt keyMapErr = KErrNone; |
100 TRAP( keyMapErr, iKeyMap = CPcsKeyMap::NewL()); |
100 TRAP( keyMapErr, iKeyMap = CPcsKeyMap::NewL()); |
101 if ( keyMapErr != KErrNone ) |
101 if ( keyMapErr != KErrNone ) |
102 { |
102 { |
103 PRINT ( _L("**********************************************.")); |
103 PRINT ( _L("**********************************************.")); |
104 PRINT1 ( _L("CPcsAlgorithm1::ConstructL() KeyMap construction error. The keymap crashed with error code %d."),keyMapErr ); |
104 PRINT1( _L("CPcsAlgorithm1::ConstructL() KeyMap construction error. The keymap crashed with error code %d."),keyMapErr ); |
105 PRINT ( _L("Please check the keypad/language for which keymap got crashed.") ); |
105 PRINT ( _L("Please check the keypad/language for which keymap got crashed.") ); |
106 PRINT ( _L("**********************************************.")); |
106 PRINT ( _L("**********************************************.")); |
|
107 User::Leave( keyMapErr ); // we can't go on without a key map; constructing cache needs it |
107 } |
108 } |
108 |
109 |
109 // Initialize helpers |
110 // Initialize helpers |
110 iHelper = CPcsAlgorithm1Helper::NewL(this); |
111 iHelper = CPcsAlgorithm1Helper::NewL(this); |
111 iMultiSearchHelper = CPcsAlgorithm1MultiSearchHelper::NewL(this); |
112 iMultiSearchHelper = CPcsAlgorithm1MultiSearchHelper::NewL(this); |
183 PRINT ( _L("End CPcsAlgorithm1::RemoveSpacesL") ); |
184 PRINT ( _L("End CPcsAlgorithm1::RemoveSpacesL") ); |
184 } |
185 } |
185 |
186 |
186 // ---------------------------------------------------------------------------- |
187 // ---------------------------------------------------------------------------- |
187 // CPcsAlgorithm1::ReplaceZeroWithSpaceL |
188 // CPcsAlgorithm1::ReplaceZeroWithSpaceL |
188 // Replace all '0's in a search query with " "s |
189 // Replace all "0"s in a search query with " "s if those characters are on |
|
190 // the same key. |
189 // ---------------------------------------------------------------------------- |
191 // ---------------------------------------------------------------------------- |
190 TBool CPcsAlgorithm1::ReplaceZeroWithSpaceL(CPsQuery& aQuery) |
192 TBool CPcsAlgorithm1::ReplaceZeroWithSpaceL(CPsQuery& aQuery) |
191 { |
193 { |
192 PRINT ( _L("Enter CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
194 PRINT ( _L("Enter CPcsAlgorithm1::ReplaceZeroWithSpaceL") ); |
193 |
195 |
194 //PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (BEFORE): "), aQuery ); |
196 //PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (BEFORE): "), aQuery ); |
195 |
197 |
196 TBool queryModified = EFalse; |
198 TBool queryModified = EFalse; |
197 |
199 |
198 if (iKeyMap->GetSpaceAndZeroOnSameKey()) |
200 /* In phones like E52 and E55, where the "0" and the " " characters are on |
199 { |
201 * the same key, the "0"s have to be considered as possible separators. |
200 /* In phones like E52 and E55, where the "0" and the " " characters are on |
202 * |
201 * the same key, then the "0"s EItut have to be considered as possible |
203 * In phones like N97 and E72, where the "0" and the " " characters are on |
202 * separators. |
204 * different keys, the "0"s must not be considered as possible separators. |
203 */ |
205 */ |
204 |
206 |
205 // Skip initial "0"s, they are not replaced into spaces |
207 // Skip initial "0"s, they are not replaced into spaces |
206 TInt skipIndex = 0; |
208 TInt skipIndex = 0; |
207 while ( (skipIndex < aQuery.Count()) && |
209 while ( (skipIndex < aQuery.Count()) && |
208 (aQuery.GetItemAtL(skipIndex).Character().GetNumericValue() == 0) ) |
210 (aQuery.GetItemAtL(skipIndex).Character().GetNumericValue() == 0) ) |
|
211 { |
|
212 skipIndex++; |
|
213 } |
|
214 |
|
215 // Replace remaining "0"s into spaces in case they are entered with a keyboard |
|
216 // that has "0" and " " on the same key. |
|
217 for ( TInt index = skipIndex; index < aQuery.Count(); index++ ) |
|
218 { |
|
219 CPsQueryItem& item = aQuery.GetItemAtL(index); |
|
220 |
|
221 if ( iKeyMap->GetSpaceAndZeroOnSameKey( item.Mode() ) && |
|
222 item.Character().GetNumericValue() == 0 ) |
209 { |
223 { |
210 skipIndex++; |
224 item.SetCharacter(KSpace); |
|
225 queryModified = ETrue; |
211 } |
226 } |
212 |
|
213 // Replace remaining EItut "0"s into spaces |
|
214 TChar space(KSpace); |
|
215 for ( TInt index = skipIndex; index < aQuery.Count(); index++ ) |
|
216 { |
|
217 CPsQueryItem& item = aQuery.GetItemAtL(index); |
|
218 |
|
219 if ( item.Character().GetNumericValue() == 0 && |
|
220 item.Mode() == EItut ) |
|
221 { |
|
222 item.SetCharacter(space); |
|
223 queryModified = ETrue; |
|
224 } |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 /* In phones like N97 and E72, where the "0" and the " " characters are on |
|
230 * a different key, then the "0" EItut does not have to be considered as a |
|
231 * possible separator. |
|
232 */ |
|
233 |
|
234 PRINT ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: \"0\" and \" \" are on different keys, not attepting to replace") ); |
|
235 } |
227 } |
236 |
228 |
237 //PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (AFTER): "), aQuery ); |
229 //PRINTQUERY ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL (AFTER): "), aQuery ); |
238 |
230 |
239 PRINT1 ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: Query modified (0=not, 1=yes): %d"), queryModified ); |
231 PRINT1 ( _L("CPcsAlgorithm1::ReplaceZeroWithSpaceL: Query modified (0=not, 1=yes): %d"), queryModified ); |
254 { |
246 { |
255 PRINT ( _L("Enter CPcsAlgorithm1::PerformSearchL") ); |
247 PRINT ( _L("Enter CPcsAlgorithm1::PerformSearchL") ); |
256 |
248 |
257 __LATENCY_MARK ( _L("CPcsAlgorithm1::PerformSearchL") ); |
249 __LATENCY_MARK ( _L("CPcsAlgorithm1::PerformSearchL") ); |
258 |
250 |
259 RPointerArray<CPsQuery> query; |
|
260 |
|
261 // Local arrays to hold the search results |
251 // Local arrays to hold the search results |
262 RPointerArray<CPsData> tempSearchResults; |
252 RPointerArray<CPsData> tempSearchResults; |
|
253 CleanupClosePushL( tempSearchResults ); |
263 RPointerArray<CPsData> tempSearchResultsIni; |
254 RPointerArray<CPsData> tempSearchResultsIni; |
|
255 CleanupClosePushL( tempSearchResultsIni ); |
264 RPointerArray<CPsData> tempSearchResultsMod; |
256 RPointerArray<CPsData> tempSearchResultsMod; |
|
257 CleanupClosePushL( tempSearchResultsMod ); |
265 |
258 |
266 // ----------------------- Perform the basic search ----------------------- |
259 // ----------------------- Perform the basic search ----------------------- |
267 /* Even before replacing zeroes with spaces the query can have multiple words |
260 /* Even before replacing zeroes with spaces the query can have multiple words |
268 * Some phones support infact double keyboards with possibility to type a space in qwerty mode |
261 * Some phones support infact double keyboards with possibility to type a space in qwerty mode |
269 * A space in qwerty mode can even be typed disabling temporarily PCS |
262 * A space in qwerty mode can even be typed disabling temporarily PCS |
343 } |
336 } |
344 } |
337 } |
345 else |
338 else |
346 { |
339 { |
347 // Copy all the contents from tempSearchResults to the results stream |
340 // Copy all the contents from tempSearchResults to the results stream |
348 for(int i = 0; i < resultSet; i++) |
341 for(TInt i = 0; i < resultSet; i++) |
349 { |
342 { |
350 aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
343 aSearchResults.Append(WriteClientDataL(*(tempSearchResults[i]))); |
351 } |
344 } |
352 } |
345 } |
353 // ------------------------------------------------------------------------ |
346 // ------------------------------------------------------------------------ |
354 |
347 |
355 // Cleanup local results array |
348 // Cleanup local results array |
356 tempSearchResults.Reset(); // Don't destroy |
349 CleanupStack::PopAndDestroy( &tempSearchResultsMod ); // Close, don't destroy |
357 tempSearchResultsIni.Reset(); // Don't destroy |
350 CleanupStack::PopAndDestroy( &tempSearchResultsIni ); // Close, don't destroy |
358 tempSearchResultsMod.Reset(); // Don't destroy |
351 CleanupStack::PopAndDestroy( &tempSearchResults ); // Close, don't destroy |
359 |
352 |
360 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::PerformSearchL") ); |
353 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::PerformSearchL") ); |
361 |
354 |
362 PRINT ( _L("End CPcsAlgorithm1::PerformSearchL") ); |
355 PRINT ( _L("End CPcsAlgorithm1::PerformSearchL") ); |
363 } |
356 } |
543 // CPcsAlgorithm1::DoSearchL |
536 // CPcsAlgorithm1::DoSearchL |
544 // Search function helper |
537 // Search function helper |
545 // ---------------------------------------------------------------------------- |
538 // ---------------------------------------------------------------------------- |
546 void CPcsAlgorithm1::DoSearchL(const CPsSettings& aSettings, |
539 void CPcsAlgorithm1::DoSearchL(const CPsSettings& aSettings, |
547 CPsQuery& aQuery, |
540 CPsQuery& aQuery, |
548 RPointerArray<CPsData>& searchResults, |
541 RPointerArray<CPsData>& aSearchResults, |
549 RPointerArray<CPsPattern>& searchSeqs ) |
542 RPointerArray<CPsPattern>& aSearchSeqs ) |
550 { |
543 { |
551 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchL") ); |
544 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchL") ); |
552 |
545 |
553 __LATENCY_MARK ( _L("CPcsAlgorithm1::DoSearchL") ); |
546 __LATENCY_MARK ( _L("CPcsAlgorithm1::DoSearchL") ); |
554 |
547 |
555 // -(0)----------------- Check if group search is required --------------- |
548 // -(0)----------------- Check if group search is required --------------- |
556 RArray<TInt> contactsInGroup; |
549 RArray<TInt> contactsInGroup; |
|
550 CleanupClosePushL( contactsInGroup ); |
557 RArray<TInt> groupIdArray; |
551 RArray<TInt> groupIdArray; |
|
552 CleanupClosePushL( groupIdArray ); |
558 |
553 |
559 // Create a new settings instance |
554 // Create a new settings instance |
560 CPsSettings *tempSettings = aSettings.CloneL(); |
555 CPsSettings *tempSettings = aSettings.CloneL(); |
|
556 CleanupStack::PushL( tempSettings ); |
561 |
557 |
562 TBool isGroupSearch = IsGroupSearchL(*tempSettings, groupIdArray); |
558 TBool isGroupSearch = IsGroupSearchL(*tempSettings, groupIdArray); |
563 |
559 |
564 if ( isGroupSearch ) |
560 if ( isGroupSearch ) |
565 { |
561 { |
568 |
564 |
569 // List of contacts in this group |
565 // List of contacts in this group |
570 GetContactsInGroupL ( groupIdArray[0], contactsInGroup ); |
566 GetContactsInGroupL ( groupIdArray[0], contactsInGroup ); |
571 } |
567 } |
572 |
568 |
573 groupIdArray.Close(); |
|
574 |
|
575 // ----------------------------------------------------------------------- |
569 // ----------------------------------------------------------------------- |
576 |
570 |
577 // Extract query list. |
571 // Extract query list. |
578 RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
572 RPointerArray<CPsQuery> queryList = iMultiSearchHelper->MultiQueryL(aQuery); |
|
573 CleanupResetAndDestroyPushL( queryList ); |
579 PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchL: "), queryList ); |
574 PRINTQUERYLIST ( _L("CPcsAlgorithm1::DoSearchL: "), queryList ); |
580 |
575 |
581 // (1)-------------------- No query return all contacts ------------------- |
576 // (1)-------------------- No query return all contacts ------------------- |
582 if ( queryList.Count() == 0 ) |
577 if ( queryList.Count() == 0 ) |
583 { |
578 { |
584 GetAllContentsL(*tempSettings, searchResults); |
579 GetAllContentsL(*tempSettings, aSearchResults); |
585 |
580 |
586 if ( isGroupSearch ) |
581 if ( isGroupSearch ) |
587 { |
582 { |
588 FilterSearchResultsForGroupsL ( contactsInGroup, searchResults ); |
583 FilterSearchResultsForGroupsL( contactsInGroup, aSearchResults ); |
589 } |
584 } |
590 } |
585 } |
591 // ------------------------------------------------------------------------ |
586 // ------------------------------------------------------------------------ |
592 |
587 |
593 // (2)-------------------- Perform a single query search ------------------ |
588 // (2)-------------------- Perform a single query search ------------------ |
594 else if ( queryList.Count() == 1 ) // single qwery |
589 else if ( queryList.Count() == 1 ) // single query |
595 { |
590 { |
596 PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Single. Performing a SingleSearch") ); |
591 PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Single. Performing a SingleSearch") ); |
597 |
592 |
598 iHelper->SearchSingleL(*tempSettings, *queryList[0], isGroupSearch, |
593 iHelper->SearchSingleL(*tempSettings, *queryList[0], isGroupSearch, |
599 contactsInGroup, searchResults, searchSeqs); |
594 contactsInGroup, aSearchResults, aSearchSeqs); |
600 } |
595 } |
601 // ------------------------------------------------------------------------ |
596 // ------------------------------------------------------------------------ |
602 |
597 |
603 // (3)-------------------- Perform a multi query search ------------------- |
598 // (3)-------------------- Perform a multi query search ------------------- |
604 else // multiple query |
599 else // multiple query |
605 { |
600 { |
606 PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Multiple. Performing a MultiSearch") ); |
601 PRINT ( _L("CPcsAlgorithm1::DoSearchL: Query received is Multiple. Performing a MultiSearch") ); |
607 |
602 |
608 // Search results |
603 // Search results |
609 iMultiSearchHelper->SearchMultiL(*tempSettings, queryList, isGroupSearch, |
604 iMultiSearchHelper->SearchMultiL(*tempSettings, queryList, isGroupSearch, |
610 contactsInGroup, searchResults, searchSeqs); |
605 contactsInGroup, aSearchResults, aSearchSeqs); |
611 } |
606 } |
612 // ------------------------------------------------------------------------- |
607 // ------------------------------------------------------------------------- |
613 |
608 |
614 // Cleanup |
609 // Cleanup |
615 delete tempSettings; |
610 |
616 tempSettings = NULL; |
611 CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
617 |
612 CleanupStack::PopAndDestroy( tempSettings ); |
618 groupIdArray.Close(); |
613 CleanupStack::PopAndDestroy( &groupIdArray ); // Close |
619 contactsInGroup.Close(); |
614 CleanupStack::PopAndDestroy( &contactsInGroup ); // Close |
620 queryList.ResetAndDestroy(); |
|
621 |
615 |
622 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::DoSearchL") ); |
616 __LATENCY_MARKEND ( _L("CPcsAlgorithm1::DoSearchL") ); |
623 |
617 |
624 PRINT ( _L("End CPcsAlgorithm1::DoSearchL") ); |
618 PRINT ( _L("End CPcsAlgorithm1::DoSearchL") ); |
625 } |
619 } |
627 // ---------------------------------------------------------------------------- |
621 // ---------------------------------------------------------------------------- |
628 // CPcsAlgorithm1::DoSearchInputL |
622 // CPcsAlgorithm1::DoSearchInputL |
629 // Search function helper |
623 // Search function helper |
630 // ---------------------------------------------------------------------------- |
624 // ---------------------------------------------------------------------------- |
631 void CPcsAlgorithm1::DoSearchInputL(CPsQuery& aQuery, |
625 void CPcsAlgorithm1::DoSearchInputL(CPsQuery& aQuery, |
632 TDesC& aData, |
626 const TDesC& aData, |
633 RPointerArray<TDesC>& aMatchSet, |
627 RPointerArray<TDesC>& aMatchSet, |
634 RArray<TPsMatchLocation>& aMatchLocation ) |
628 RArray<TPsMatchLocation>& aMatchLocation ) |
635 { |
629 { |
636 |
630 |
637 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchInputL") ); |
631 PRINT ( _L("Enter CPcsAlgorithm1::DoSearchInputL") ); |
734 |
728 |
735 if(dataStoreIndex < 0) return; |
729 if(dataStoreIndex < 0) return; |
736 |
730 |
737 CPcsCache* cache = iPcsCache[dataStoreIndex]; |
731 CPcsCache* cache = iPcsCache[dataStoreIndex]; |
738 |
732 |
739 TRAPD(err, cache->RemoveAllFromCacheL()); |
733 cache->RemoveAllFromCache(); |
740 |
|
741 if ( err != KErrNone ) |
|
742 { |
|
743 SetCachingError(aDataStore, err); |
|
744 } |
|
745 } |
734 } |
746 |
735 |
747 // ---------------------------------------------------------------------------- |
736 // ---------------------------------------------------------------------------- |
748 // CPcsAlgorithm1::GetCacheIndex |
737 // CPcsAlgorithm1::GetCacheIndex |
749 // Return the cache index for a data store |
738 // Return the cache index for a data store |
750 // ---------------------------------------------------------------------------- |
739 // ---------------------------------------------------------------------------- |
751 TInt CPcsAlgorithm1::GetCacheIndex(TDesC& aDataStore) |
740 TInt CPcsAlgorithm1::GetCacheIndex(const TDesC& aDataStore) |
752 { |
741 { |
753 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
742 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
754 { |
743 { |
755 CPcsCache* cache = iPcsCache[i]; |
744 CPcsCache* cache = iPcsCache[i]; |
756 |
745 |
779 TRAPD(err, cache = CPcsCache::NewL(aDataStore, *iKeyMap, iCacheCount)); |
768 TRAPD(err, cache = CPcsCache::NewL(aDataStore, *iKeyMap, iCacheCount)); |
780 if ( err != KErrNone ) |
769 if ( err != KErrNone ) |
781 { |
770 { |
782 SetCachingError(aDataStore, err); |
771 SetCachingError(aDataStore, err); |
783 return; |
772 return; |
784 } |
773 } |
785 |
774 |
786 // Increment the cachecount |
775 // Increment the cachecount |
787 iCacheCount++; |
776 iCacheCount++; |
788 |
777 |
789 RArray<TInt> dataFields; |
778 RArray<TInt> dataFields; |
790 TRAP(err, iPsDataPluginInterface->GetSupportedDataFieldsL(cache->GetURI(), dataFields)); |
779 TRAP(err, iPsDataPluginInterface->GetSupportedDataFieldsL(cache->GetURI(), dataFields)); |
791 if ( err != KErrNone ) |
780 if ( err != KErrNone ) |
792 { |
781 { |
793 SetCachingError(aDataStore, err); |
782 SetCachingError(aDataStore, err); |
794 return; |
783 return; |
795 } |
784 } |
884 |
873 |
885 // ---------------------------------------------------------------------------- |
874 // ---------------------------------------------------------------------------- |
886 // CPcsAlgorithm1::FindStoreUri |
875 // CPcsAlgorithm1::FindStoreUri |
887 // Checks if this store exists |
876 // Checks if this store exists |
888 // ---------------------------------------------------------------------------- |
877 // ---------------------------------------------------------------------------- |
889 TInt CPcsAlgorithm1::FindStoreUri ( TDesC& aDataStore ) |
878 TInt CPcsAlgorithm1::FindStoreUri ( const TDesC& aDataStore ) |
890 { |
879 { |
891 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
880 for ( int i = 0; i < iPcsCache.Count(); i++ ) |
892 { |
881 { |
893 if ( aDataStore.CompareC(*(iPcsCache[i]->GetUri())) == 0 ) |
882 if ( aDataStore.CompareC(*(iPcsCache[i]->GetUri())) == 0 ) |
894 { |
883 { |
959 |
948 |
960 // ---------------------------------------------------------------------------- |
949 // ---------------------------------------------------------------------------- |
961 // CPcsAlgorithm1::SetCachingError |
950 // CPcsAlgorithm1::SetCachingError |
962 // Updates cachinge error |
951 // Updates cachinge error |
963 // ---------------------------------------------------------------------------- |
952 // ---------------------------------------------------------------------------- |
964 void CPcsAlgorithm1::SetCachingError(TDesC& aDataStore, TInt aError) |
953 void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError) |
965 { |
954 { |
966 TBuf<KBufferMaxLen> store; |
955 PRINT2 ( _L("SetCachingError::URI %S ERROR %d"), &aDataStore, aError ); |
967 store.Copy(aDataStore); |
|
968 PRINT2 ( _L("SetCachingError::URI %S ERROR %d"), &store, aError ); |
|
969 |
956 |
970 iCacheError = aError; |
957 iCacheError = aError; |
971 RProperty::Set(KCStatus,1,iCacheError ); |
958 RProperty::Set( KCStatus,1,iCacheError ); |
972 } |
959 } |
973 |
960 |
974 // ---------------------------------------------------------------------------- |
961 // ---------------------------------------------------------------------------- |
975 // CPcsAlgorithm1::GetAllContentsL |
962 // CPcsAlgorithm1::GetAllContentsL |
976 // Returns all the contents of a store |
963 // Returns all the contents of a store |
980 { |
967 { |
981 __LATENCY_MARK ( _L("CPcsAlgorithm1::GetAllContentsL") ); |
968 __LATENCY_MARK ( _L("CPcsAlgorithm1::GetAllContentsL") ); |
982 |
969 |
983 PRINT ( _L("Enter CPcsAlgorithm1::GetAllContentsL") ); |
970 PRINT ( _L("Enter CPcsAlgorithm1::GetAllContentsL") ); |
984 |
971 |
985 // Get the data stores |
|
986 RPointerArray<TDesC> aDataStores; |
|
987 aSettings.SearchUrisL(aDataStores); |
|
988 |
|
989 // To hold array of results from different data stores |
972 // To hold array of results from different data stores |
990 typedef RPointerArray<CPsData> CPSDATA_R_PTR_ARRAY; |
973 typedef RPointerArray<CPsData> CPSDATA_R_PTR_ARRAY; |
991 RPointerArray<CPSDATA_R_PTR_ARRAY> iSearchResultsArr; |
974 RPointerArray<CPSDATA_R_PTR_ARRAY> searchResultsArr; |
992 |
975 CleanupResetAndDestroyPushL( searchResultsArr ); |
|
976 // TODO: Here's still a potential memory leak if a leave happens. The child |
|
977 // arrays of searchResultsArr are not Reset in that case. The CPsData objects |
|
978 // may leak as well. Handling this safely is somewhat complicated because some of |
|
979 // the CPsData objects may already be transferred to ownership of aResults array |
|
980 // at the time the leave happens, and those items must not be deleted. |
|
981 |
|
982 // Get the data stores |
|
983 RPointerArray<TDesC> dataStores; |
|
984 CleanupResetAndDestroyPushL( dataStores ); |
|
985 aSettings.SearchUrisL(dataStores); |
|
986 |
993 // Get all contacts for each data store |
987 // Get all contacts for each data store |
994 for ( int dsIndex = 0; |
988 for ( TInt dsIndex = 0; |
995 dsIndex < aDataStores.Count(); |
989 dsIndex < dataStores.Count(); |
996 dsIndex++ ) |
990 dsIndex++ ) |
997 { |
991 { |
998 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData>(); |
992 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData>(); |
999 iSearchResultsArr.Append(temp); |
993 searchResultsArr.Append(temp); |
1000 |
994 |
1001 TInt arrayIndex = GetCacheIndex(*(aDataStores[dsIndex])); |
995 TInt arrayIndex = GetCacheIndex(*(dataStores[dsIndex])); |
1002 |
996 |
1003 if ( arrayIndex < 0 ) continue; |
997 if ( arrayIndex < 0 ) continue; |
1004 |
998 |
1005 CPcsCache* cache = GetCache(arrayIndex); |
999 CPcsCache* cache = GetCache(arrayIndex); |
1006 |
1000 |
1007 cache->GetAllContentsL(*(iSearchResultsArr[dsIndex])); |
1001 cache->GetAllContentsL(*(searchResultsArr[dsIndex])); |
1008 } |
1002 } |
1009 |
1003 |
1010 aDataStores.ResetAndDestroy(); |
1004 CleanupStack::PopAndDestroy( &dataStores ); // ResetAndDestroy |
1011 |
1005 |
1012 // Merge the results from different data stores |
1006 // Merge the results from different data stores |
1013 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(iSearchResultsArr, |
1007 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(searchResultsArr, |
1014 aResults); |
1008 aResults); |
1015 |
1009 |
1016 // Cleanup the local arrays |
1010 // Cleanup the local arrays |
1017 for(TInt i = 0; i < iSearchResultsArr.Count(); i++) |
1011 for(TInt i = 0; i < searchResultsArr.Count(); i++) |
1018 { |
1012 { |
1019 iSearchResultsArr[i]->Reset(); |
1013 searchResultsArr[i]->Reset(); |
1020 delete iSearchResultsArr[i]; |
1014 } |
1021 iSearchResultsArr[i] = NULL; |
1015 CleanupStack::PopAndDestroy( &searchResultsArr ); // ResetAndDestroy |
1022 } |
|
1023 |
|
1024 iSearchResultsArr.Reset(); |
|
1025 |
1016 |
1026 PRINT1 ( _L("Number of results = %d"), aResults.Count() ); |
1017 PRINT1 ( _L("Number of results = %d"), aResults.Count() ); |
1027 |
1018 |
1028 PRINT ( _L("End CPcsAlgorithm1::GetAllContentsL") ); |
1019 PRINT ( _L("End CPcsAlgorithm1::GetAllContentsL") ); |
1029 |
1020 |
1042 // Get the groupIds in the seach settings |
1033 // Get the groupIds in the seach settings |
1043 aSettings.GetGroupIdsL(aGroupIdArray); |
1034 aSettings.GetGroupIdsL(aGroupIdArray); |
1044 |
1035 |
1045 // Get the current URIs defined in settings |
1036 // Get the current URIs defined in settings |
1046 RPointerArray<TDesC> searchUris; |
1037 RPointerArray<TDesC> searchUris; |
|
1038 CleanupResetAndDestroyPushL( searchUris ); |
1047 aSettings.SearchUrisL(searchUris); |
1039 aSettings.SearchUrisL(searchUris); |
1048 |
1040 |
1049 if ( aGroupIdArray.Count() && (searchUris.Count() > aGroupIdArray.Count() ) ) |
1041 if ( aGroupIdArray.Count() && (searchUris.Count() > aGroupIdArray.Count() ) ) |
1050 { |
1042 { |
1051 // There is an error, either there are more than one groups |
1043 // There is an error, either there are more than one groups |
1052 // or the settings contain a combination of group/non-group Uris |
1044 // or the settings contain a combination of group/non-group Uris |
1053 searchUris.ResetAndDestroy(); |
|
1054 aGroupIdArray.Close(); |
1045 aGroupIdArray.Close(); |
1055 User::Leave(KErrArgument); |
1046 User::Leave(KErrArgument); |
1056 } |
1047 } |
1057 |
1048 |
1058 searchUris.ResetAndDestroy(); |
1049 CleanupStack::PopAndDestroy( &searchUris ); // ResetAndDestroy |
1059 |
1050 |
1060 PRINT ( _L("End CPcsAlgorithm1::IsGroupSearchL") ); |
1051 PRINT ( _L("End CPcsAlgorithm1::IsGroupSearchL") ); |
1061 |
1052 |
1062 if ( aGroupIdArray.Count() == 1 ) |
1053 if ( aGroupIdArray.Count() == 1 ) |
1063 return ETrue; |
1054 return ETrue; |
1067 |
1058 |
1068 // ---------------------------------------------------------------------------- |
1059 // ---------------------------------------------------------------------------- |
1069 // CPcsAlgorithm1::ReplaceGroupsUriL |
1060 // CPcsAlgorithm1::ReplaceGroupsUriL |
1070 // Replace groups uri to contacts uri |
1061 // Replace groups uri to contacts uri |
1071 // ---------------------------------------------------------------------------- |
1062 // ---------------------------------------------------------------------------- |
1072 void CPcsAlgorithm1::ReplaceGroupsUriL ( CPsSettings& aSettings ) |
1063 void CPcsAlgorithm1::ReplaceGroupsUriL( CPsSettings& aSettings ) |
1073 { |
1064 { |
1074 RPointerArray<TDesC> uri; |
1065 RPointerArray<TDesC> uri; |
|
1066 CleanupResetAndDestroyPushL( uri ); |
1075 |
1067 |
1076 // Set contacts db uri |
1068 // Set contacts db uri |
1077 HBufC* cntdb = HBufC::NewL(KBufferMaxLen); |
1069 HBufC* cntdb = KVPbkDefaultCntDbURI().AllocLC(); |
1078 cntdb->Des().Copy(KVPbkDefaultCntDbURI); |
1070 uri.AppendL(cntdb); |
1079 uri.Append(cntdb); |
1071 CleanupStack::Pop( cntdb ); // ownership transferred |
1080 aSettings.SetSearchUrisL(uri); |
1072 aSettings.SetSearchUrisL(uri); |
1081 |
1073 |
1082 // Cleanup |
1074 // Cleanup |
1083 uri.ResetAndDestroy(); |
1075 CleanupStack::PopAndDestroy( &uri ); // ResetAndDestroy |
1084 } |
1076 } |
1085 |
1077 |
1086 // ---------------------------------------------------------------------------- |
1078 // ---------------------------------------------------------------------------- |
1087 // CPcsAlgorithm1::FilterSearchResultsForGroupsL |
1079 // CPcsAlgorithm1::FilterSearchResultsForGroupsL |
1088 // Filters the results that belong to a group |
1080 // Filters the results that belong to a group |
1117 |
1109 |
1118 // ---------------------------------------------------------------------------- |
1110 // ---------------------------------------------------------------------------- |
1119 // CPcsAlgorithm1::GetContactsInGroupL |
1111 // CPcsAlgorithm1::GetContactsInGroupL |
1120 // Recover contacts that belong to a group |
1112 // Recover contacts that belong to a group |
1121 // ---------------------------------------------------------------------------- |
1113 // ---------------------------------------------------------------------------- |
1122 void CPcsAlgorithm1::GetContactsInGroupL ( TInt aGroupId, |
1114 void CPcsAlgorithm1::GetContactsInGroupL( TInt aGroupId, |
1123 RArray<TInt>& aGroupContactIds ) |
1115 RArray<TInt>& aGroupContactIds ) |
1124 { |
1116 { |
1125 // Clear results array |
1117 // Clear results array |
1126 aGroupContactIds.Reset(); |
1118 aGroupContactIds.Reset(); |
1127 |
1119 |
1128 // Groups URI |
1120 // Cache Index for group database |
1129 HBufC* groupURI = HBufC::NewL(50); |
1121 TInt cacheIndex = GetCacheIndex(KVPbkDefaultGrpDbURI); |
1130 groupURI->Des().Copy(KVPbkDefaultGrpDbURI); |
|
1131 |
|
1132 // Cache Index |
|
1133 TInt cacheIndex = GetCacheIndex(*groupURI); |
|
1134 |
|
1135 // Cleanup |
|
1136 delete groupURI; |
|
1137 groupURI = NULL; |
|
1138 |
1122 |
1139 // Get the groups contact ids |
1123 // Get the groups contact ids |
1140 if ( cacheIndex != -1 ) |
1124 if ( cacheIndex != -1 ) |
1141 { |
1125 { |
1142 RPointerArray<CPsData> groups; |
1126 RPointerArray<CPsData> groups; |
|
1127 CleanupClosePushL( groups ); |
1143 |
1128 |
1144 // Get all groups |
1129 // Get all groups |
1145 iPcsCache[cacheIndex]->GetAllContentsL(groups); |
1130 iPcsCache[cacheIndex]->GetAllContentsL(groups); |
1146 |
1131 |
1147 // Get all contacts in group |
1132 // Get all contacts in group |
1306 |
1291 |
1307 // --------------------------------------------------------------------------------- |
1292 // --------------------------------------------------------------------------------- |
1308 // Read the persisted sort order from the central repository |
1293 // Read the persisted sort order from the central repository |
1309 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
1294 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
1310 // --------------------------------------------------------------------------------- |
1295 // --------------------------------------------------------------------------------- |
1311 void CPcsAlgorithm1::ReadSortOrderFromCenRepL(TDesC& aURI, |
1296 void CPcsAlgorithm1::ReadSortOrderFromCenRepL(const TDesC& aURI, |
1312 RArray<TInt>& aSortOrder) |
1297 RArray<TInt>& aSortOrder) |
1313 { |
1298 { |
1314 PRINT ( _L("Enter CPcsAlgorithm1::ReadSortOrderFromCenRepL.") ); |
1299 PRINT ( _L("Enter CPcsAlgorithm1::ReadSortOrderFromCenRepL.") ); |
1315 |
1300 |
1316 aSortOrder.Reset(); |
1301 aSortOrder.Reset(); |
1372 |
1357 |
1373 // --------------------------------------------------------------------------------- |
1358 // --------------------------------------------------------------------------------- |
1374 // Write the sort order into the central repository |
1359 // Write the sort order into the central repository |
1375 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
1360 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited) |
1376 // --------------------------------------------------------------------------------- |
1361 // --------------------------------------------------------------------------------- |
1377 void CPcsAlgorithm1::WriteSortOrderToCenRepL(TDesC& aURI, |
1362 void CPcsAlgorithm1::WriteSortOrderToCenRepL(const TDesC& aURI, |
1378 RArray<TInt>& aSortOrder) |
1363 RArray<TInt>& aSortOrder) |
1379 { |
1364 { |
1380 PRINT ( _L("Enter CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
1365 PRINT ( _L("Enter CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
1381 |
1366 |
1382 CRepository *repository = CRepository::NewL( KCRUidPSSortOrder ); |
1367 CRepository *repository = CRepository::NewLC( KCRUidPSSortOrder ); |
1383 |
1368 |
1384 // Check if there an entry for this URI in cenrep |
1369 // Check if there an entry for this URI in cenrep |
1385 TBuf<KCRMaxLen> str; |
1370 TBuf<KCRMaxLen> str; |
1386 TInt keyIndex = -1; |
1371 TInt keyIndex = -1; |
1387 |
1372 |
1442 PRINT ( _L("CPcsAlgorithm1::WriteSortOrderToCenRepL. Persist limit violated.") ); |
1427 PRINT ( _L("CPcsAlgorithm1::WriteSortOrderToCenRepL. Persist limit violated.") ); |
1443 return; |
1428 return; |
1444 } |
1429 } |
1445 |
1430 |
1446 // Persist the sort order |
1431 // Persist the sort order |
1447 HBufC* str1 = HBufC::NewL(KCRMaxLen); |
1432 HBufC* str1 = HBufC::NewLC(KCRMaxLen); |
1448 TPtr ptr(str1->Des()); |
1433 TPtr ptr(str1->Des()); |
1449 |
1434 |
1450 // Append the URI |
1435 // Append the URI |
1451 ptr.Append(aURI); |
1436 ptr.Append(aURI); |
1452 ptr.Append(KSpace); |
1437 ptr.Append(KSpace); |
1453 |
1438 |
1454 // Append the sort order fields |
1439 // Append the sort order fields |
1455 for ( int j = 0; j < aSortOrder.Count(); j++ ) |
1440 for ( TInt j = 0; j < aSortOrder.Count(); j++ ) |
1456 { |
1441 { |
1457 ptr.AppendNum(aSortOrder[j]); |
1442 ptr.AppendNum(aSortOrder[j]); |
1458 ptr.Append(KSpace); |
1443 ptr.Append(KSpace); |
1459 } |
1444 } |
1460 |
1445 |
1461 // Write to persistent store |
1446 // Write to persistent store |
1462 TInt err = repository->Set(keyIndex, ptr); |
1447 TInt err = repository->Set(keyIndex, ptr); |
1463 |
1448 |
1464 User::LeaveIfError(err); |
1449 User::LeaveIfError(err); |
1465 |
1450 |
1466 delete str1; |
1451 CleanupStack::PopAndDestroy( str1 ); |
1467 |
1452 |
1468 delete repository; |
1453 CleanupStack::PopAndDestroy( repository ); |
1469 |
1454 |
1470 PRINT ( _L("End CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
1455 PRINT ( _L("End CPcsAlgorithm1::WriteSortOrderToCenRepL.") ); |
1471 } |
1456 } |
1472 |
1457 |
1473 // --------------------------------------------------------------------------------- |
1458 // --------------------------------------------------------------------------------- |
1528 // and storing it in CPcsCache. Refer CPcsAlgorithm1Utils::CompareDataBySortOrderL |
1513 // and storing it in CPcsCache. Refer CPcsAlgorithm1Utils::CompareDataBySortOrderL |
1529 // to see how this is being used. |
1514 // to see how this is being used. |
1530 User::LeaveIfError( Dll::SetTls(&iPcsCache) ); |
1515 User::LeaveIfError( Dll::SetTls(&iPcsCache) ); |
1531 |
1516 |
1532 // Initialize cache |
1517 // Initialize cache |
1533 RPointerArray<TDesC> dataStores; |
1518 RPointerArray<TDesC> dataStores; |
|
1519 CleanupClosePushL( dataStores ); |
1534 |
1520 |
1535 iPsDataPluginInterface->GetAllSupportedDataStoresL(dataStores); |
1521 iPsDataPluginInterface->GetAllSupportedDataStoresL(dataStores); |
1536 |
1522 |
1537 for ( int dIndex = 0; dIndex < dataStores.Count(); dIndex++ ) |
1523 for ( TInt dIndex = 0; dIndex < dataStores.Count(); dIndex++ ) |
1538 { |
1524 { |
1539 AddDataStore(*(dataStores[dIndex])); |
1525 AddDataStore(*(dataStores[dIndex])); |
1540 } |
1526 } |
1541 dataStores.Reset(); |
1527 |
|
1528 CleanupStack::PopAndDestroy( &dataStores ); // Close |
1542 } |
1529 } |
1543 // End of file |
1530 // End of file |
1544 |
1531 |