|
1 /* |
|
2 * Copyright (c) 2002 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: Alias name matching functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "MsgCheckNames.h" |
|
22 |
|
23 #include <eiklbv.h> |
|
24 #include <aknlistquerydialog.h> |
|
25 #include <CPbkContactEngine.h> // CPbkContactEngine |
|
26 #include <CPbkIdleFinder.h> // CPbkIdleFinder |
|
27 #include <CPbkContactItem.h> // Phonebook Contact |
|
28 #include <cntdef.h> //CheckNames |
|
29 #include <CPbkSmsAddressSelect.h> //CheckNames |
|
30 #include <CPbkEmailAddressSelect.h> //CheckNames |
|
31 #include <CPbkMmsAddressSelect.h> //CheckNames |
|
32 #include <MsgAddressControl.h> // CMsgRecipientArray/CheckNames |
|
33 |
|
34 #include <MsgEditorAppUi.rsg> // resource identifiers |
|
35 |
|
36 #include <VPbkContactStoreUris.h> |
|
37 #include <TVPbkFieldVersitProperty.h> |
|
38 #include <MVPbkContactFieldTextData.h> |
|
39 #include <MVPbkStoreContact.h> |
|
40 #include <RVPbkContactFieldDefaultPriorities.h> |
|
41 #include <TVPbkContactStoreUriPtr.h> |
|
42 #include <CPbk2StoreConfiguration.h> |
|
43 #include <MVPbkContactLink.h> |
|
44 #include <CVPbkFieldTypeRefsList.h> |
|
45 #include <CVPbkContactStoreUriArray.h> |
|
46 |
|
47 #include <CVPbkFieldTypeSelector.h> |
|
48 #include <VPbkContactViewFilterBuilder.h> |
|
49 #include <AiwContactSelectionDataTypes.h> |
|
50 |
|
51 #include <TVPbkWordParserCallbackParam.h> |
|
52 #include <AiwContactSelectionDataTypes.h> |
|
53 #include <RVPbkContactFieldDefaultPriorities.h> |
|
54 |
|
55 #include <featmgr.h> |
|
56 |
|
57 // MACROS |
|
58 _LIT( KItemStart, "1\t" ); //For creation of checkbox list |
|
59 |
|
60 const TUint KLatinCharEnd = 0xFF; |
|
61 |
|
62 _LIT( KPanicText, "Check names -panic" ); |
|
63 |
|
64 |
|
65 // ============================= LOCAL FUNCTIONS =============================== |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // FindWordSplitterL |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 TInt FindWordSplitterL( TAny* aParams ) |
|
72 { |
|
73 TVPbkWordParserCallbackParam* parser = |
|
74 static_cast<TVPbkWordParserCallbackParam*>( aParams ); |
|
75 |
|
76 const TText* ptr = parser->iStringToParse->Ptr(); |
|
77 const TText* end = ptr + parser->iStringToParse->Length(); |
|
78 |
|
79 const TText* startOfWord=NULL; |
|
80 FOREVER |
|
81 { |
|
82 if ( ptr==end || TChar(*ptr).IsSpace() ) |
|
83 { |
|
84 if ( startOfWord ) |
|
85 { |
|
86 TPtrC addWord( startOfWord,ptr - startOfWord ); |
|
87 parser->iWordArray->AppendL( addWord ); |
|
88 startOfWord = NULL; |
|
89 } |
|
90 if ( ptr == end ) |
|
91 { |
|
92 break; |
|
93 } |
|
94 } |
|
95 else if ( !startOfWord ) |
|
96 { |
|
97 startOfWord = ptr; |
|
98 } |
|
99 ptr++; |
|
100 } |
|
101 return( KErrNone ); |
|
102 } |
|
103 |
|
104 |
|
105 |
|
106 // ============================ MEMBER FUNCTIONS =============================== |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CMsgCheckNames::CMsgCheckNames |
|
110 // |
|
111 // C++ default constructor can NOT contain any code, that |
|
112 // might leave. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CMsgCheckNames::CMsgCheckNames() |
|
116 { |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CMsgCheckNames::ConstructL |
|
121 // |
|
122 // Symbian 2nd phase constructor can leave. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CMsgCheckNames::ConstructL() |
|
126 { |
|
127 iFoundContacts = CVPbkContactLinkArray::NewL(); |
|
128 |
|
129 iStoreConfiguration = CPbk2StoreConfiguration::NewL(); |
|
130 |
|
131 CVPbkContactStoreUriArray* storeArray = iStoreConfiguration->SearchStoreConfigurationL(); |
|
132 CleanupStack::PushL( storeArray ); |
|
133 |
|
134 iCommonUtils = CContactMatcher::NewL( &CCoeEnv::Static()->FsSession() );//parameter for RFs& |
|
135 iCommonUtils->OpenStoreL( *storeArray ); |
|
136 iServiceHandler = CAiwServiceHandler::NewL(); |
|
137 iServiceHandler->AttachL ( R_CHECKNAMES_FETCH_INTEREST ); |
|
138 |
|
139 iStoreConfiguration->AddObserverL( *this ); |
|
140 |
|
141 CleanupStack::PopAndDestroy( storeArray ); |
|
142 |
|
143 FeatureManager::InitializeLibL(); |
|
144 |
|
145 if ( FeatureManager::FeatureSupported( KFeatureIdChinese ) ) |
|
146 { |
|
147 iUseAdvancedMatch = ETrue; |
|
148 } |
|
149 |
|
150 FeatureManager::UnInitializeLib(); |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CMsgCheckNames::NewL |
|
156 // |
|
157 // Two-phased constructor. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C CMsgCheckNames* CMsgCheckNames::NewL() |
|
161 { |
|
162 CMsgCheckNames* self = CMsgCheckNames::NewLC(); |
|
163 CleanupStack::Pop( self ); |
|
164 |
|
165 return self; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CMsgCheckNames::NewLC |
|
170 // |
|
171 // Factory method |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C CMsgCheckNames* CMsgCheckNames::NewLC() |
|
175 { |
|
176 CMsgCheckNames* self = new (ELeave) CMsgCheckNames(); |
|
177 CleanupStack::PushL(self); |
|
178 |
|
179 self->ConstructL(); |
|
180 |
|
181 return self; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CMsgCheckNames::~CMsgCheckNames |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C CMsgCheckNames::~CMsgCheckNames() |
|
189 { |
|
190 delete iFoundContacts; |
|
191 delete iCommonUtils; |
|
192 |
|
193 if ( iWait.IsStarted() ) |
|
194 { |
|
195 iWait.AsyncStop(); |
|
196 } |
|
197 |
|
198 delete iServiceHandler; |
|
199 delete iStoreConfiguration; |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CMsgCheckNames::FindAndCheckByNameL |
|
204 // |
|
205 // Finds the contact items that match the given search string, checks if they |
|
206 // are valid and if there are more than one valid matches shows them in a dialog |
|
207 // where user can select one or more of the contacts. If shudown flag is set |
|
208 // leaves with KLeaveExit code to make the application to shutdown |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C TBool CMsgCheckNames::FindAndCheckByNameL( const TDesC& aText, |
|
212 TMsgAddressSelectType aAddressSelectType, |
|
213 CMsgRecipientArray& aRecipientArray, |
|
214 TInt aIndex ) |
|
215 { |
|
216 TBool returnValue = EFalse; |
|
217 |
|
218 TAiwAddressSelectType addressType = ConvertToPbk2Type( aAddressSelectType ); |
|
219 |
|
220 CVPbkFieldTypeRefsList* fieldTypes = CVPbkFieldTypeRefsList::NewL(); |
|
221 CleanupStack::PushL( fieldTypes ); |
|
222 |
|
223 DefineSearchFieldsL( *fieldTypes ); |
|
224 |
|
225 iFoundContacts->ResetAndDestroy(); |
|
226 |
|
227 //search the given string from the fields |
|
228 CDesCArray* wordArray = SplitFindStringL( aText ); |
|
229 CleanupStack::PushL( wordArray ); |
|
230 TCallBack findParser( FindWordSplitterL ); |
|
231 |
|
232 iCommonUtils->MatchDataL( *wordArray, *fieldTypes, *iFoundContacts, findParser ); |
|
233 |
|
234 CleanupStack::PopAndDestroy( wordArray ); |
|
235 |
|
236 // If simple matching did not find any result and advanced flag is |
|
237 // on perform advanced matching. |
|
238 if ( iUseAdvancedMatch && |
|
239 iFoundContacts && |
|
240 iFoundContacts->Count() == 0 && |
|
241 UseAdvancedMatch( aText ) ) |
|
242 { |
|
243 PerformAdvancedMatchL( aText, fieldTypes ); |
|
244 } |
|
245 |
|
246 TInt contactAmount = iFoundContacts->Count(); |
|
247 |
|
248 // Offer the user a list of matching contacts |
|
249 if ( contactAmount > 1 ) |
|
250 { |
|
251 CDesCArray* items = new ( ELeave ) CDesCArrayFlat(4); |
|
252 CleanupStack::PushL( items ); |
|
253 |
|
254 CVPbkContactLinkArray* helperArray = CVPbkContactLinkArray::NewL(); |
|
255 CleanupStack::PushL( helperArray ); |
|
256 |
|
257 //go through every contact, search the names for them and insert into items array |
|
258 for ( TInt i = 0; i<contactAmount; i++ ) |
|
259 { |
|
260 MVPbkStoreContact* storeContact = NULL; |
|
261 iCommonUtils->GetStoreContactL( iFoundContacts->At(i), &storeContact ); |
|
262 storeContact->PushL(); |
|
263 |
|
264 if ( KErrNotFound != iCommonUtils->ContactHasFieldOfTypeL( addressType, *storeContact ) ) |
|
265 { |
|
266 MVPbkStoreContactFieldCollection& fieldCollection = storeContact->Fields(); |
|
267 |
|
268 HBufC* contactName = iCommonUtils->GetNameL( fieldCollection ); |
|
269 if ( contactName ) |
|
270 { |
|
271 contactName = contactName->ReAllocL( contactName->Des().Length()+2 ); |
|
272 CleanupStack::PushL( contactName ); |
|
273 |
|
274 TPtr contactNamePtr = contactName->Des(); |
|
275 |
|
276 /* |
|
277 * Fix the split contact name issue::ECYU-7FPC93. |
|
278 * Replace any enter-key characters with space characters. |
|
279 * Start |
|
280 */ |
|
281 |
|
282 TInt enterKeyPos; |
|
283 TChar enterChar( CEditableText::EParagraphDelimiter ); |
|
284 TChar spaceChar( CEditableText::ESpace ); |
|
285 TInt nameLength = contactNamePtr.Length(); |
|
286 |
|
287 enterKeyPos = contactNamePtr.Locate(enterChar); |
|
288 while( enterKeyPos != KErrNotFound && enterKeyPos < nameLength ) |
|
289 { |
|
290 contactNamePtr[enterKeyPos] = spaceChar; |
|
291 enterKeyPos = contactNamePtr.Locate(enterChar); |
|
292 } |
|
293 // Fix: End |
|
294 // We need to add the checkbox |
|
295 contactNamePtr.Insert( 0, KItemStart ); |
|
296 |
|
297 // Pay attention to the order of the items |
|
298 TInt pos = items->InsertIsqAllowDuplicatesL( contactNamePtr, ECmpCollated ); |
|
299 CleanupStack::PopAndDestroy( contactName ); |
|
300 |
|
301 const MVPbkContactLink& preservedLink = iFoundContacts->At( i ); |
|
302 |
|
303 MVPbkContactLink* link = preservedLink.CloneLC(); |
|
304 helperArray->InsertL( link, pos ); |
|
305 |
|
306 CleanupStack::Pop(); |
|
307 } |
|
308 } |
|
309 |
|
310 CleanupStack::PopAndDestroy( storeContact ); |
|
311 } |
|
312 |
|
313 iFoundContacts->ResetAndDestroy(); |
|
314 |
|
315 if ( items->Count() ) |
|
316 { |
|
317 CListBoxView::CSelectionIndexArray* matchingRecipients = |
|
318 new ( ELeave ) CArrayFixFlat<TInt>( contactAmount ); |
|
319 CleanupStack::PushL( matchingRecipients ); |
|
320 |
|
321 CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( matchingRecipients ); |
|
322 dlg->PrepareLC( R_MEB_CHECKNAMES_QUERY ); |
|
323 dlg->SetItemTextArray( items ); |
|
324 dlg->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
325 |
|
326 if ( dlg->RunLD() ) |
|
327 { |
|
328 // We must now read which one / ones of the contacts the user selected |
|
329 const TInt recipientCount = matchingRecipients->Count(); |
|
330 MVPbkContactLink* link = NULL; |
|
331 |
|
332 for ( TInt i = 0; i < recipientCount; ++i ) |
|
333 { |
|
334 // Copying entries |
|
335 link = helperArray->At( matchingRecipients->At( i ) ).CloneLC(); |
|
336 |
|
337 // Inserts entry, shifts original items |
|
338 iFoundContacts->InsertL( link, i ); |
|
339 CleanupStack::Pop(); |
|
340 } |
|
341 } |
|
342 CleanupStack::PopAndDestroy(); // matchingRecipients |
|
343 } |
|
344 CleanupStack::PopAndDestroy( 2, items);//helperArray |
|
345 } |
|
346 |
|
347 CleanupStack::PopAndDestroy( fieldTypes ); // fieldtypes |
|
348 |
|
349 if ( iFoundContacts->Count() > 0 ) |
|
350 { |
|
351 ExecuteSingleItemFetchL( |
|
352 TAiwSingleItemSelectionDataV1().SetAddressSelectType( addressType ) ); |
|
353 |
|
354 CAknInputBlock* inputBlock = CAknInputBlock::NewCancelHandlerLC( this ); |
|
355 |
|
356 iWait.Start(); // Make this whole op look like synchronous |
|
357 |
|
358 CleanupStack::PopAndDestroy( inputBlock ); |
|
359 |
|
360 if ( iShutdown ) |
|
361 { |
|
362 User::Leave( KLeaveExit ); |
|
363 } |
|
364 |
|
365 if ( iFoundContacts->Count() > 0 )//the process might have been cancelled |
|
366 { |
|
367 PutContactsToArrayL( aRecipientArray, aIndex ); |
|
368 returnValue = ETrue; |
|
369 } |
|
370 } |
|
371 |
|
372 //return false if no contacts |
|
373 return returnValue; |
|
374 } |
|
375 |
|
376 // ---------------------------------------------------------------------------- |
|
377 // CMsgCheckNames::FetchRecipientsL |
|
378 // |
|
379 // Fetches the recipients, and searches the address from the selected recipients |
|
380 // Starts input blocker to "eat" all key press events to editor during |
|
381 // phonebook operations. If shudown flag is set leaves with KLeaveExit code |
|
382 // to make the application to shutdown |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 EXPORT_C void CMsgCheckNames::FetchRecipientsL( CMsgRecipientArray& aRecipientList, |
|
386 TMsgAddressSelectType aAddressSelectType ) |
|
387 { |
|
388 TAiwAddressSelectType addressType = ConvertToPbk2Type( aAddressSelectType ); |
|
389 |
|
390 // Construct empty filter |
|
391 CVPbkFieldTypeSelector* contactViewFilter = |
|
392 CVPbkFieldTypeSelector::NewL( iCommonUtils->FieldTypes() ); |
|
393 CleanupStack::PushL( contactViewFilter ); |
|
394 |
|
395 // Append the filter object with suitable criteria |
|
396 if ( addressType == EAiwEMailSelect ) |
|
397 { |
|
398 VPbkContactViewFilterBuilder::BuildContactViewFilterL( *contactViewFilter, |
|
399 EVPbkContactViewFilterEmail, |
|
400 iCommonUtils->GetContactManager() ); |
|
401 } |
|
402 |
|
403 else if ( addressType == EAiwMMSSelect ) |
|
404 { |
|
405 VPbkContactViewFilterBuilder::BuildContactViewFilterL( *contactViewFilter, |
|
406 EVPbkContactViewFilterPhoneNumber, |
|
407 iCommonUtils->GetContactManager() ); |
|
408 |
|
409 VPbkContactViewFilterBuilder::BuildContactViewFilterL( *contactViewFilter, |
|
410 EVPbkContactViewFilterEmail, |
|
411 iCommonUtils->GetContactManager() ); |
|
412 } |
|
413 |
|
414 else |
|
415 { |
|
416 VPbkContactViewFilterBuilder::BuildContactViewFilterL( *contactViewFilter, |
|
417 EVPbkContactViewFilterPhoneNumber, |
|
418 iCommonUtils->GetContactManager() ); |
|
419 } |
|
420 |
|
421 iFoundContacts->ResetAndDestroy(); |
|
422 |
|
423 TAiwMultipleItemSelectionDataV1 selectionData; |
|
424 selectionData.SetFetchFilter( contactViewFilter ); |
|
425 selectionData.SetAddressSelectType( addressType ); |
|
426 |
|
427 ExecuteMultipleItemFetchL( selectionData ); |
|
428 |
|
429 CleanupStack::PopAndDestroy( contactViewFilter ); |
|
430 |
|
431 CAknInputBlock* inputBlock = CAknInputBlock::NewCancelHandlerLC( this ); |
|
432 |
|
433 iWait.Start(); |
|
434 |
|
435 if ( iFoundContacts->Count() > 0 ) |
|
436 { |
|
437 // The process might have been cancelled in which case there |
|
438 // will not be any contacts. |
|
439 PutContactsToArrayL( aRecipientList, -1 ); |
|
440 } |
|
441 |
|
442 CleanupStack::PopAndDestroy( inputBlock ); |
|
443 |
|
444 if ( iShutdown ) |
|
445 { |
|
446 User::Leave( KLeaveExit ); |
|
447 } |
|
448 } |
|
449 |
|
450 // ---------------------------------------------------------------------------- |
|
451 // CMsgCheckNames::FetchRecipientsL |
|
452 // |
|
453 // Fetches the recipients. If shudown flag is set leaves with KLeaveExit code |
|
454 // to make the application to shutdown |
|
455 // ---------------------------------------------------------------------------- |
|
456 // |
|
457 EXPORT_C void CMsgCheckNames::FetchRecipientsL( CVPbkContactLinkArray& aContactLinkArray, |
|
458 TMsgAddressSelectType /*aAddressSelectType*/ ) |
|
459 { |
|
460 ExecuteMultipleEntryFetchL( TAiwMultipleEntrySelectionDataV2().SetFetchFilter( NULL ).SetFlags( 0 ) ); |
|
461 |
|
462 CAknInputBlock* inputBlock = CAknInputBlock::NewCancelHandlerLC( this ); |
|
463 |
|
464 iWait.Start(); // Wait for the user to check off the names. |
|
465 |
|
466 CleanupStack::PopAndDestroy( inputBlock ); |
|
467 |
|
468 if ( iShutdown ) |
|
469 { |
|
470 User::Leave( KLeaveExit ); |
|
471 } |
|
472 |
|
473 if ( iFoundContacts->Count() ) |
|
474 { |
|
475 for ( TInt n = 0; n < iFoundContacts->Count(); n++ ) |
|
476 { |
|
477 aContactLinkArray.AppendL( iFoundContacts->At( n ).CloneLC() ); |
|
478 CleanupStack::Pop(); // Cloned link. |
|
479 } |
|
480 } |
|
481 } |
|
482 |
|
483 // ---------------------------------------------------- |
|
484 // CMsgCheckNames::GetAlias |
|
485 // ---------------------------------------------------- |
|
486 // |
|
487 |
|
488 EXPORT_C void CMsgCheckNames::GetAliasL(const TDesC& aNumber,TDes& aAlias,TInt aMaxLength) |
|
489 { |
|
490 // Match contacts to the from address |
|
491 CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC(); |
|
492 iCommonUtils->MatchPhoneNumberL(aNumber,7,CVPbkPhoneNumberMatchStrategy::EVPbkStopOnFirstMatchFlag,*linkArray ); |
|
493 TInt tmpcnt = linkArray->Count(); |
|
494 if ( linkArray->Count() > 0 ) |
|
495 { |
|
496 MVPbkStoreContact* contact; |
|
497 iCommonUtils->GetStoreContactL(linkArray->At(0), &contact); |
|
498 contact->PushL(); |
|
499 |
|
500 MVPbkStoreContactFieldCollection& coll = contact->Fields(); |
|
501 HBufC* alias = iCommonUtils->GetNameL( coll ); |
|
502 |
|
503 if ( alias ) |
|
504 { |
|
505 if ( alias->Length() > aMaxLength ) |
|
506 { |
|
507 aAlias = alias->Left( aMaxLength ); |
|
508 } |
|
509 else |
|
510 { |
|
511 aAlias = *alias; |
|
512 } |
|
513 delete alias; |
|
514 alias = NULL; |
|
515 } |
|
516 CleanupStack::PopAndDestroy( contact ); // contact |
|
517 } |
|
518 else |
|
519 { |
|
520 aAlias = KNullDesC(); |
|
521 } |
|
522 CleanupStack::PopAndDestroy( 1); // linkArray, , |
|
523 } |
|
524 |
|
525 // ---------------------------------------------------------------------------- |
|
526 // CMsgCheckNames::HandleNotifyL |
|
527 // ---------------------------------------------------------------------------- |
|
528 // |
|
529 TInt CMsgCheckNames::HandleNotifyL( TInt aCmdId, |
|
530 TInt aEventId, |
|
531 CAiwGenericParamList& aEventParamList, |
|
532 const CAiwGenericParamList& /*aInParamList*/ ) |
|
533 { |
|
534 // the trapd is to enable stopping the iWait in case of a leave |
|
535 // trapping a lot of code to make future extensions easier |
|
536 __ASSERT_ALWAYS( iFoundContacts, User::Panic(KPanicText,0) ); |
|
537 |
|
538 TInt retVal = KErrNone; |
|
539 |
|
540 TRAPD( err, |
|
541 { |
|
542 iFoundContacts->ResetAndDestroy(); |
|
543 if ( aEventId == KAiwEventCompleted ) |
|
544 { |
|
545 TInt index = 0; |
|
546 const TAiwGenericParam* param = |
|
547 aEventParamList.FindFirst( index, EGenericParamContactLinkArray ); |
|
548 if ( param ) |
|
549 { |
|
550 TPtrC8 contactLinks = param->Value().AsData(); |
|
551 if ( contactLinks.Length() ) // If the event was cancelled |
|
552 { |
|
553 CVPbkContactLinkArray* links = |
|
554 CVPbkContactLinkArray::NewLC( contactLinks, |
|
555 iCommonUtils->GetContactStoresL() ); |
|
556 CleanupStack::Pop(); //links |
|
557 |
|
558 // Replace iFoundContacts |
|
559 delete iFoundContacts; |
|
560 iFoundContacts = links; |
|
561 } |
|
562 else |
|
563 { |
|
564 retVal = KErrArgument; |
|
565 } |
|
566 } |
|
567 else |
|
568 { |
|
569 retVal = KErrArgument; |
|
570 } |
|
571 } |
|
572 else if ( aEventId == KAiwEventOutParamCheck ) |
|
573 { |
|
574 if ( aCmdId == KAiwCmdSelect ) |
|
575 { |
|
576 retVal = 1;//this value going back to aiw-component to inform param to be ok |
|
577 } |
|
578 } |
|
579 |
|
580 else |
|
581 { |
|
582 retVal = KErrCompletion; |
|
583 } |
|
584 |
|
585 if ( retVal != 1 && iWait.IsStarted() ) |
|
586 { |
|
587 iWait.AsyncStop(); |
|
588 } |
|
589 } ); |
|
590 |
|
591 if ( err != KErrNone ) |
|
592 { |
|
593 if ( iWait.IsStarted() ) |
|
594 { |
|
595 iWait.AsyncStop(); |
|
596 } |
|
597 User::Leave( err ); |
|
598 } |
|
599 |
|
600 return retVal; |
|
601 } |
|
602 |
|
603 |
|
604 // ---------------------------------------------------- |
|
605 // CMsgCheckNames::ExecuteMultipleEntryFetchL |
|
606 // |
|
607 // Uses aiw to fetch contact(s) from vpbk |
|
608 // ---------------------------------------------------- |
|
609 // |
|
610 void CMsgCheckNames::ExecuteMultipleEntryFetchL( TAiwMultipleEntrySelectionDataV2 aData ) |
|
611 { |
|
612 CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
613 inParamList.AppendL( TAiwGenericParam( |
|
614 EGenericParamContactSelectionData, |
|
615 TAiwVariant( TAiwMultipleEntrySelectionDataV2Pckg( aData ) ) ) ); |
|
616 |
|
617 iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, |
|
618 inParamList, |
|
619 iServiceHandler->OutParamListL(), |
|
620 0, |
|
621 this ); |
|
622 } |
|
623 |
|
624 // ---------------------------------------------------------------------------- |
|
625 // CMsgCheckNames::ExecuteSingleItemFetchL |
|
626 // ---------------------------------------------------------------------------- |
|
627 // |
|
628 void CMsgCheckNames::ExecuteSingleItemFetchL( TAiwSingleItemSelectionDataV1 aData ) |
|
629 { |
|
630 RVPbkContactFieldDefaultPriorities defaultPriorities; |
|
631 CleanupClosePushL( defaultPriorities ); |
|
632 |
|
633 SetDefaultPrioritiesL( aData.AddressSelectType(), defaultPriorities ); |
|
634 |
|
635 aData.SetDefaultPriorities( defaultPriorities ); |
|
636 |
|
637 CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
638 inParamList.AppendL( TAiwGenericParam( |
|
639 EGenericParamContactSelectionData, |
|
640 TAiwVariant( TAiwSingleItemSelectionDataV1Pckg( aData ) ) ) ); |
|
641 |
|
642 // the validity of iFoundContacts is checkeck by the calling function |
|
643 HBufC8* packedLinks = iFoundContacts->PackLC(); |
|
644 |
|
645 inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray, |
|
646 TAiwVariant( *packedLinks ) ) ); |
|
647 |
|
648 iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, |
|
649 inParamList, |
|
650 iServiceHandler->OutParamListL(), |
|
651 0, |
|
652 this ); |
|
653 CleanupStack::PopAndDestroy( 2, &defaultPriorities ); |
|
654 } |
|
655 |
|
656 // ---------------------------------------------------------------------------- |
|
657 // CMsgCheckNames::ExecuteMultipleItemFetchL |
|
658 // ---------------------------------------------------------------------------- |
|
659 // |
|
660 void CMsgCheckNames::ExecuteMultipleItemFetchL( TAiwMultipleItemSelectionDataV1& aData ) |
|
661 { |
|
662 RVPbkContactFieldDefaultPriorities defaultPriorities; |
|
663 CleanupClosePushL( defaultPriorities ); |
|
664 |
|
665 SetDefaultPrioritiesL( aData.AddressSelectType(), defaultPriorities ); |
|
666 |
|
667 aData.SetDefaultPriorities( defaultPriorities ); |
|
668 |
|
669 CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
670 inParamList.AppendL( TAiwGenericParam( |
|
671 EGenericParamContactSelectionData, |
|
672 TAiwVariant( TAiwMultipleItemSelectionDataV1Pckg( aData ) ) ) ); |
|
673 |
|
674 // the validity of iFoundContacts is checkeck by the calling function |
|
675 HBufC8* packedLinks = iFoundContacts->PackLC(); |
|
676 |
|
677 inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray, |
|
678 TAiwVariant( *packedLinks ) ) ); |
|
679 |
|
680 iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, |
|
681 inParamList, |
|
682 iServiceHandler->OutParamListL(), |
|
683 0, |
|
684 this ); |
|
685 CleanupStack::PopAndDestroy( 2, &defaultPriorities ); |
|
686 } |
|
687 |
|
688 // ---------------------------------------------------------------------------- |
|
689 // CMsgCheckNames::PutContactsToArrayL |
|
690 // ---------------------------------------------------------------------------- |
|
691 // |
|
692 void CMsgCheckNames::PutContactsToArrayL( CMsgRecipientArray& aRecipientArray, TInt aIndex ) |
|
693 { |
|
694 __ASSERT_ALWAYS( iFoundContacts, User::Panic(KPanicText,0) ); |
|
695 //delete the original entry, if there was one |
|
696 if ( aIndex > -1 && |
|
697 aIndex < aRecipientArray.Count() ) |
|
698 { |
|
699 delete aRecipientArray.At( aIndex ); |
|
700 aRecipientArray.Delete( aIndex ); |
|
701 } |
|
702 else |
|
703 { |
|
704 aIndex = 0; |
|
705 } |
|
706 |
|
707 MVPbkStoreContact* storeContact = NULL; |
|
708 MVPbkStoreContactField* selectedField = NULL; |
|
709 TInt recipientsNotHandled = iFoundContacts->Count(); |
|
710 |
|
711 for ( TInt i = 0; recipientsNotHandled > i; i++ ) |
|
712 { |
|
713 const MVPbkContactLink& changedContactLink = iFoundContacts->At( i ); |
|
714 iCommonUtils->GetStoreContactL( changedContactLink, &storeContact ); |
|
715 storeContact->PushL(); |
|
716 MVPbkStoreContactFieldCollection& fieldCollection = storeContact->Fields(); |
|
717 |
|
718 selectedField = fieldCollection.RetrieveField( iFoundContacts->At(i) ); |
|
719 |
|
720 if ( selectedField )//gets the selected field and writes it to the reciItem |
|
721 { |
|
722 CMsgRecipientItem* reciItem = CMsgRecipientItem::NewLC( KNullDesC, KNullDesC ); |
|
723 |
|
724 // Set field data |
|
725 const MVPbkContactFieldTextData* textData = |
|
726 &MVPbkContactFieldTextData::Cast( selectedField->FieldData() ); |
|
727 |
|
728 reciItem->SetAddressL( textData->Text() ); |
|
729 |
|
730 HBufC* contactName = iCommonUtils->GetNameL( fieldCollection ); |
|
731 if ( contactName ) |
|
732 { |
|
733 reciItem->SetNameL( contactName->Des() ); |
|
734 delete contactName; |
|
735 } |
|
736 |
|
737 reciItem->SetContactLink( &changedContactLink ); |
|
738 aRecipientArray.InsertL( aIndex, reciItem ); |
|
739 |
|
740 CleanupStack::Pop( reciItem ); |
|
741 aIndex++; |
|
742 } |
|
743 CleanupStack::PopAndDestroy( storeContact ); |
|
744 } |
|
745 } |
|
746 |
|
747 // ----------------------------------------------------------------------------- |
|
748 // CMsgCheckNames::SplitFindStringL |
|
749 // |
|
750 // Divides search string into several pieces if it includes spaces. |
|
751 // ----------------------------------------------------------------------------- |
|
752 // |
|
753 CDesCArray* CMsgCheckNames::SplitFindStringL(const TDesC& aFindString) |
|
754 { |
|
755 CDesCArray* wordArray = new ( ELeave ) CDesCArrayFlat( 10 ); |
|
756 CleanupStack::PushL( wordArray ); |
|
757 |
|
758 TVPbkWordParserCallbackParam parser( &aFindString, wordArray ); |
|
759 FindWordSplitterL( &parser ); |
|
760 |
|
761 CleanupStack::Pop(); // wordArray |
|
762 return parser.iWordArray; |
|
763 } |
|
764 |
|
765 // ----------------------------------------------------------------------------- |
|
766 // CMsgCheckNames::IdleFindCallback |
|
767 // |
|
768 // Asynchronous find observer callback. |
|
769 // ----------------------------------------------------------------------------- |
|
770 // |
|
771 void CMsgCheckNames::IdleFindCallback() |
|
772 { |
|
773 } |
|
774 |
|
775 // ----------------------------------------------------------------------------- |
|
776 // CMsgCheckNames::DefineSearchFieldsL |
|
777 // |
|
778 // Defines that from which fiels the data is searched from |
|
779 // ----------------------------------------------------------------------------- |
|
780 // |
|
781 void CMsgCheckNames::DefineSearchFieldsL( CVPbkFieldTypeRefsList& aOwnList ) |
|
782 { |
|
783 const MVPbkFieldTypeList& refList = iCommonUtils->FieldTypes(); |
|
784 TVPbkFieldVersitProperty prop; |
|
785 prop.SetName( EVPbkVersitNameN ); |
|
786 prop.SetSubField( EVPbkVersitSubFieldFamilyName ); |
|
787 const MVPbkFieldType* foundType = refList.FindMatch( prop, 0 ); |
|
788 |
|
789 if ( foundType ) |
|
790 { |
|
791 aOwnList.AppendL( *foundType ); |
|
792 } |
|
793 |
|
794 prop.SetSubField( EVPbkVersitSubFieldGivenName ); |
|
795 |
|
796 foundType = refList.FindMatch( prop, 0 ); |
|
797 if ( foundType ) |
|
798 { |
|
799 aOwnList.AppendL( *foundType ); |
|
800 } |
|
801 |
|
802 prop.SetName( EVPbkVersitNameORG ); |
|
803 prop.SetSubField( EVPbkVersitSubFieldOrgName ); |
|
804 |
|
805 foundType = refList.FindMatch( prop, 0 ); |
|
806 if ( foundType ) |
|
807 { |
|
808 aOwnList.AppendL( *foundType ); |
|
809 } |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CMsgCheckNames::ConvertToPbk2Type |
|
814 // |
|
815 // Defines that from which fiels the data is searched from |
|
816 // ----------------------------------------------------------------------------- |
|
817 // |
|
818 TAiwAddressSelectType CMsgCheckNames::ConvertToPbk2Type( |
|
819 TMsgAddressSelectType aAddressSelectType ) |
|
820 |
|
821 { |
|
822 TAiwAddressSelectType addressType = EAiwPhoneNumberSelect; |
|
823 |
|
824 switch ( aAddressSelectType ) |
|
825 { |
|
826 case EMsgTypeSms: |
|
827 { |
|
828 addressType = EAiwPhoneNumberSelect; |
|
829 break; |
|
830 } |
|
831 case EMsgTypeMms: |
|
832 { |
|
833 addressType = EAiwMMSSelect; |
|
834 break; |
|
835 } |
|
836 case EMsgTypeMail: |
|
837 { |
|
838 addressType = EAiwEMailSelect; |
|
839 break; |
|
840 } |
|
841 case EMsgTypeAll: |
|
842 { |
|
843 addressType = EAiwAllItemsSelect; |
|
844 break; |
|
845 } |
|
846 default: |
|
847 { |
|
848 addressType = EAiwPhoneNumberSelect; |
|
849 break; |
|
850 } |
|
851 } |
|
852 |
|
853 return addressType; |
|
854 } |
|
855 |
|
856 // ----------------------------------------------------------------------------- |
|
857 // CMsgCheckNames::SetDefaultPrioritiesL |
|
858 // ----------------------------------------------------------------------------- |
|
859 // |
|
860 void CMsgCheckNames::SetDefaultPrioritiesL( TAiwAddressSelectType aAddressType, |
|
861 RVPbkContactFieldDefaultPriorities& aPriorities ) const |
|
862 { |
|
863 switch ( aAddressType ) |
|
864 { |
|
865 case EAiwMMSSelect: |
|
866 { |
|
867 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeMms ) ); |
|
868 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeSms ) ); |
|
869 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeEmailOverSms ) ); |
|
870 break; |
|
871 } |
|
872 case EAiwPhoneNumberSelect: |
|
873 { |
|
874 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeSms ) ); |
|
875 break; |
|
876 } |
|
877 case EAiwEMailSelect: |
|
878 { |
|
879 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeEmail ) ); |
|
880 break; |
|
881 } |
|
882 case EAiwAllItemsSelect: |
|
883 { |
|
884 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeMms ) ); |
|
885 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeSms ) ); |
|
886 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeEmail ) ); |
|
887 User::LeaveIfError( aPriorities.Append( EVPbkDefaultTypeEmailOverSms ) ); |
|
888 break; |
|
889 } |
|
890 default: |
|
891 { |
|
892 break; |
|
893 } |
|
894 } |
|
895 } |
|
896 |
|
897 // ----------------------------------------------------------------------------- |
|
898 // CMsgCheckNames::UseAdvancedMatch |
|
899 // |
|
900 // If string does not contain spaces and contains only non-latin characters |
|
901 // perform matching advanced match algorithm. |
|
902 // ----------------------------------------------------------------------------- |
|
903 // |
|
904 TBool CMsgCheckNames::UseAdvancedMatch( const TDesC& aFindString ) |
|
905 { |
|
906 TBool containsSpace( EFalse ); |
|
907 TBool nonLatinString( ETrue ); |
|
908 |
|
909 for ( TInt current = 0; current < aFindString.Length(); current++ ) |
|
910 { |
|
911 TUint currentChar( aFindString[current] ); |
|
912 if ( TChar( currentChar ).IsSpace() ) |
|
913 { |
|
914 containsSpace = ETrue; |
|
915 } |
|
916 |
|
917 if ( currentChar < KLatinCharEnd ) |
|
918 { |
|
919 nonLatinString = EFalse; |
|
920 break; |
|
921 } |
|
922 } |
|
923 |
|
924 return !containsSpace && nonLatinString; |
|
925 } |
|
926 |
|
927 // ----------------------------------------------------------------------------- |
|
928 // CMsgCheckNames::PerformAdvancedMatchL |
|
929 // |
|
930 // Perform matching by trying to set space between every character. |
|
931 // This is done because in written chinese it is common to write contact names without spaces and |
|
932 // symbian's contact DB requires search text as a word list. |
|
933 // ----------------------------------------------------------------------------- |
|
934 // |
|
935 void CMsgCheckNames::PerformAdvancedMatchL( const TDesC& aFindString, |
|
936 CVPbkFieldTypeRefsList* aFieldTypes ) |
|
937 { |
|
938 HBufC* firstBuffer = HBufC::NewLC( aFindString.Length() ); |
|
939 HBufC* secondBuffer = HBufC::NewLC( aFindString.Length() ); |
|
940 |
|
941 TPtr firstBufferPtr = firstBuffer->Des(); |
|
942 TPtr secondBufferPtr = secondBuffer->Des(); |
|
943 |
|
944 CDesCArray* wordArray = new( ELeave ) CDesCArrayFlat( 2 ); |
|
945 CleanupStack::PushL( wordArray ); |
|
946 |
|
947 TCallBack findParser( FindWordSplitterL ); |
|
948 |
|
949 TInt count( Min( aFindString.Length(), 4) ); |
|
950 |
|
951 for ( TInt index = 1; index < count; index++ ) |
|
952 { |
|
953 firstBufferPtr.Insert( 0, aFindString.Mid( 0, index ) ); |
|
954 secondBufferPtr.Insert( 0, aFindString.Mid( index, |
|
955 aFindString.Length() - index ) ); |
|
956 |
|
957 wordArray->AppendL( firstBufferPtr ); |
|
958 wordArray->AppendL( secondBufferPtr ); |
|
959 |
|
960 iCommonUtils->MatchDataL( *wordArray, |
|
961 *aFieldTypes, |
|
962 *iFoundContacts, |
|
963 findParser ); |
|
964 |
|
965 wordArray->Reset(); |
|
966 |
|
967 if ( iFoundContacts->Count() != 0 ) |
|
968 { |
|
969 break; |
|
970 } |
|
971 |
|
972 firstBufferPtr.Zero(); |
|
973 secondBufferPtr.Zero(); |
|
974 } |
|
975 |
|
976 CleanupStack::PopAndDestroy( wordArray ); |
|
977 |
|
978 CleanupStack::PopAndDestroy( secondBuffer ); |
|
979 CleanupStack::PopAndDestroy( firstBuffer ); |
|
980 } |
|
981 |
|
982 // ----------------------------------------------------------------------------- |
|
983 // CMsgCheckNames::AknInputBlockCancel |
|
984 // |
|
985 // Cancels the AIW service and sets the shutdown flag. This is needed since |
|
986 // we must wait for the AIW service to notify us about the cancel before |
|
987 // application can be shutdown. Otherwise AIW service might try to use |
|
988 // freed resources. |
|
989 // ----------------------------------------------------------------------------- |
|
990 // |
|
991 void CMsgCheckNames::AknInputBlockCancel() |
|
992 { |
|
993 if ( iWait.IsStarted() ) |
|
994 { |
|
995 TRAPD( error, iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, |
|
996 iServiceHandler->InParamListL(), |
|
997 iServiceHandler->OutParamListL(), |
|
998 KAiwOptCancel, |
|
999 this ) ); |
|
1000 if ( error == KErrNone ) |
|
1001 { |
|
1002 iShutdown = ETrue; |
|
1003 } |
|
1004 } |
|
1005 } |
|
1006 |
|
1007 // --------------------------------------------------------- |
|
1008 // CMsgCheckNames::CleanupResetAndDestroy |
|
1009 // --------------------------------------------------------- |
|
1010 // |
|
1011 void CMsgCheckNames::CleanupResetAndDestroy( TAny* aMatchedRecips ) |
|
1012 { |
|
1013 CMsgRecipientArray* matches = NULL; |
|
1014 |
|
1015 matches = STATIC_CAST( CMsgRecipientArray*, aMatchedRecips ); |
|
1016 matches->ResetAndDestroy(); |
|
1017 |
|
1018 delete matches; |
|
1019 matches = NULL; |
|
1020 } |
|
1021 |
|
1022 // --------------------------------------------------------- |
|
1023 // CMsgCheckNames::ConfigurationChanged |
|
1024 // --------------------------------------------------------- |
|
1025 // |
|
1026 void CMsgCheckNames::ConfigurationChanged() |
|
1027 { |
|
1028 } |
|
1029 |
|
1030 // --------------------------------------------------------- |
|
1031 // CMsgCheckNames::ConfigurationChangedComplete |
|
1032 // --------------------------------------------------------- |
|
1033 // |
|
1034 void CMsgCheckNames::ConfigurationChangedComplete() |
|
1035 { |
|
1036 TRAP_IGNORE( DoConfigurationChangedCompleteL() ); |
|
1037 } |
|
1038 |
|
1039 // --------------------------------------------------------- |
|
1040 // CMsgCheckNames::DoConfigurationChangedCompleteL |
|
1041 // |
|
1042 // If store configuration has changed (i.e. used memories (phone, SIM etc.)). |
|
1043 // open the currently selected stores. |
|
1044 // --------------------------------------------------------- |
|
1045 // |
|
1046 void CMsgCheckNames::DoConfigurationChangedCompleteL() |
|
1047 { |
|
1048 CVPbkContactStoreUriArray* storeArray = iStoreConfiguration->SearchStoreConfigurationL(); |
|
1049 CleanupStack::PushL( storeArray ); |
|
1050 |
|
1051 iCommonUtils->CloseStoresL(); |
|
1052 iCommonUtils->OpenStoreL( *storeArray ); |
|
1053 |
|
1054 CleanupStack::PopAndDestroy( storeArray ); |
|
1055 } |
|
1056 |
|
1057 // End of File |