|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 address selection. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CPbk2AddressSelect.h> |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2SelectFieldDlg.h" |
|
23 #include "MPbk2ControlKeyObserver.h" |
|
24 #include <MPbk2ContactNameFormatter.h> |
|
25 #include <CPbk2FieldPropertyArray.h> |
|
26 #include <TPbk2AddressSelectParams.h> |
|
27 #include <MPbk2ApplicationServices.h> |
|
28 #include <MPbk2ApplicationServices2.h> |
|
29 #include <CPbk2ServiceManager.h> |
|
30 #include <MPbk2AppUi.h> |
|
31 #include <Pbk2UIControls.rsg> |
|
32 #include <CPbk2ApplicationServices.h> |
|
33 #include <TPbk2StoreContactAnalyzer.h> |
|
34 |
|
35 // Virtual Phonebook |
|
36 #include <CVPbkFieldFilter.h> |
|
37 #include <MVPbkStoreContactField.h> |
|
38 #include <MVPbkStoreContact.h> |
|
39 #include <CVPbkFieldTypeSelector.h> |
|
40 #include <MVPbkContactFieldData.h> |
|
41 #include <MVPbkStoreContactFieldCollection.h> |
|
42 #include <CVPbkContactManager.h> |
|
43 #include <CVPbkDefaultAttribute.h> |
|
44 #include <MVPbkFieldType.h> |
|
45 #include <TVPbkFieldVersitProperty.h> |
|
46 |
|
47 // System includes |
|
48 #include <avkon.hrh> |
|
49 #include <aknnotewrappers.h> |
|
50 #include <StringLoader.h> |
|
51 |
|
52 //SpSettings |
|
53 #include <spsettings.h> |
|
54 #include <spentry.h> |
|
55 #include <spproperty.h> |
|
56 |
|
57 /// Unnamed namespace for local definitions |
|
58 namespace { |
|
59 |
|
60 #ifdef _DEBUG |
|
61 enum TPanicCode |
|
62 { |
|
63 EPanicPostCond_Constructor = 1, |
|
64 EPanicPreCond_ExecuteLD |
|
65 }; |
|
66 |
|
67 static void Panic(TPanicCode aReason) |
|
68 { |
|
69 _LIT(KPanicText, "CPbk2AddressSelect"); |
|
70 User::Panic(KPanicText, aReason); |
|
71 } |
|
72 #endif // _DEBUG |
|
73 |
|
74 #define KOneVOIPServiceAvailable 1 |
|
75 |
|
76 const TInt KFirstField = 0; |
|
77 const TInt KDefaultTitleFormat = MPbk2ContactNameFormatter::EUseSeparator; |
|
78 |
|
79 /** |
|
80 * Returns index of given field in store contact field collection. |
|
81 * |
|
82 * @param aCollection Store contact field collection. |
|
83 * @param aField Store contact field to search for. |
|
84 * @return Index of the given field. |
|
85 */ |
|
86 inline TInt IndexOfField( |
|
87 const MVPbkStoreContactFieldCollection& aCollection, |
|
88 const MVPbkStoreContactField& aField ) |
|
89 { |
|
90 TInt ret = KErrNotFound; |
|
91 const TInt count = aCollection.FieldCount(); |
|
92 |
|
93 for ( TInt i = 0; i < count; ++i ) |
|
94 { |
|
95 MVPbkStoreContactField* field = aCollection.FieldAtLC( i ); |
|
96 if ( aField.IsSame( *field ) ) |
|
97 { |
|
98 ret = i; |
|
99 CleanupStack::PopAndDestroy(); // field |
|
100 break; |
|
101 } |
|
102 CleanupStack::PopAndDestroy(); // field |
|
103 } |
|
104 |
|
105 return ret; |
|
106 } |
|
107 |
|
108 } /// namespace |
|
109 |
|
110 // MODULE DATA STRUCTURES |
|
111 |
|
112 /** |
|
113 * Special field selection dialog class for CPbk2AddressSelect. |
|
114 * The main purpose of this class is to |
|
115 * get #include of MPbk2ControlKeyObserver |
|
116 * away from public header CPbk2AddressSelect.h. |
|
117 */ |
|
118 NONSHARABLE_CLASS(CPbk2AddressSelect::CSelectFieldDlg) : |
|
119 public CPbk2SelectFieldDlg, |
|
120 private MPbk2ControlKeyObserver |
|
121 { |
|
122 public: // Construction |
|
123 |
|
124 /** |
|
125 * Constructor. |
|
126 * |
|
127 * @param aParent Parent. |
|
128 */ |
|
129 CSelectFieldDlg( CPbk2AddressSelect& aParent ) : |
|
130 iParent( aParent ) |
|
131 { |
|
132 SetObserver( this ); |
|
133 } |
|
134 |
|
135 private: // From MPbk2ControlKeyObserver |
|
136 TKeyResponse Pbk2ControlKeyEventL |
|
137 ( const TKeyEvent& aKeyEvent, TEventCode aType ); |
|
138 |
|
139 private: // Data |
|
140 /// Ref: Parent |
|
141 CPbk2AddressSelect& iParent; |
|
142 }; |
|
143 |
|
144 |
|
145 // -------------------------------------------------------------------------- |
|
146 // CPbk2AddressSelect::CSelectFieldDlg::Pbk2ControlKeyEventL |
|
147 // -------------------------------------------------------------------------- |
|
148 // |
|
149 TKeyResponse CPbk2AddressSelect::CSelectFieldDlg::Pbk2ControlKeyEventL |
|
150 ( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
151 { |
|
152 // Forward call to virtual function in CPbk2AddressSelect interface |
|
153 return iParent.Pbk2ControlKeyEventL( aKeyEvent,aType ); |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 // CPbk2AddressSelect::CPbk2AddressSelect |
|
158 // -------------------------------------------------------------------------- |
|
159 // |
|
160 CPbk2AddressSelect::CPbk2AddressSelect( |
|
161 TPbk2AddressSelectParams& aParams, |
|
162 const TArray<MVPbkStoreContact*>* aStoreContactsArray, |
|
163 const TArray<CPbk2PresenceIconInfo*>* aPresenceIconsArray ): |
|
164 iParams( aParams ), |
|
165 iStoreContactsArray( aStoreContactsArray ), |
|
166 iPresenceIconsArray( aPresenceIconsArray ) |
|
167 { |
|
168 __ASSERT_DEBUG |
|
169 ( !iFieldDlg && !iDestroyedPtr, |
|
170 Panic( EPanicPostCond_Constructor ) ); |
|
171 } |
|
172 |
|
173 // -------------------------------------------------------------------------- |
|
174 // CPbk2AddressSelect::~CPbk2AddressSelect |
|
175 // -------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C CPbk2AddressSelect::~CPbk2AddressSelect() |
|
178 { |
|
179 // Tell ExecuteLD this object is already destroyed |
|
180 if (iDestroyedPtr) |
|
181 { |
|
182 *iDestroyedPtr = ETrue; |
|
183 } |
|
184 |
|
185 // Set eliminator pointer to NULL |
|
186 if ( iSelfPtr ) |
|
187 { |
|
188 *iSelfPtr = NULL; |
|
189 } |
|
190 |
|
191 delete iFieldDlg; |
|
192 delete iFieldFilter; |
|
193 delete iFieldTypeSelector; |
|
194 iFieldFilterArray.ResetAndDestroy(); |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------- |
|
198 // CPbk2AddressSelect::NewL |
|
199 // -------------------------------------------------------------------------- |
|
200 // |
|
201 EXPORT_C CPbk2AddressSelect* CPbk2AddressSelect::NewL |
|
202 ( TPbk2AddressSelectParams& aParams ) |
|
203 { |
|
204 CPbk2AddressSelect* self = new ( ELeave ) CPbk2AddressSelect( |
|
205 aParams, NULL, NULL ); |
|
206 CleanupStack::PushL( self ); |
|
207 self->ConstructL( NULL ); |
|
208 CleanupStack::Pop( self ); |
|
209 return self; |
|
210 } |
|
211 |
|
212 // -------------------------------------------------------------------------- |
|
213 // CPbk2AddressSelect::NewL |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C CPbk2AddressSelect* CPbk2AddressSelect::NewL |
|
217 ( TPbk2AddressSelectParams& aParams, |
|
218 CVPbkFieldTypeSelector& aFieldTypeSelector, |
|
219 const TArray<MVPbkStoreContact*>* aStoreContactsArray, |
|
220 const TArray<CPbk2PresenceIconInfo*>* aPresenceIconsArray ) |
|
221 { |
|
222 CPbk2AddressSelect* self = new ( ELeave ) CPbk2AddressSelect( aParams, |
|
223 aStoreContactsArray, aPresenceIconsArray ); |
|
224 CleanupStack::PushL( self ); |
|
225 self->ConstructL( &aFieldTypeSelector ); |
|
226 CleanupStack::Pop( self ); |
|
227 return self; |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CPbk2AddressSelect::ConstructL |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 void CPbk2AddressSelect::ConstructL( |
|
235 CVPbkFieldTypeSelector* aFieldTypeSelector ) |
|
236 { |
|
237 // Read the resource referenced in address select resource struct |
|
238 const TInt fieldTypeSelectorRes = iParams.iResReader.ReadInt32(); |
|
239 TResourceReader selectorReader; |
|
240 CCoeEnv::Static()->CreateResourceReaderLC |
|
241 ( selectorReader, fieldTypeSelectorRes ); |
|
242 if ( aFieldTypeSelector == NULL ) |
|
243 { |
|
244 // Give that resource reader to the field type selector |
|
245 iFieldTypeSelector = CVPbkFieldTypeSelector::NewL |
|
246 ( selectorReader, iParams.iContactManager.FieldTypes() ); |
|
247 } |
|
248 else |
|
249 { |
|
250 iFieldTypeSelector = CVPbkFieldTypeSelector::NewL( |
|
251 *aFieldTypeSelector ); |
|
252 } |
|
253 CleanupStack::PopAndDestroy(); // selectorReader |
|
254 |
|
255 iNoAddressesForNamePromptResource = iParams.iResReader.ReadInt32(); |
|
256 iNoAddressesPromptResource = iParams.iResReader.ReadInt32(); |
|
257 iSoftKeyResource = iParams.iResReader.ReadInt32(); |
|
258 |
|
259 const CVPbkFieldFilter::TConfig config |
|
260 ( const_cast<MVPbkStoreContactFieldCollection&> |
|
261 ( iParams.iContact.Fields() ), |
|
262 iFieldTypeSelector, NULL ); |
|
263 |
|
264 iFieldFilter = CVPbkFieldFilter::NewL( config ); |
|
265 |
|
266 if ( iStoreContactsArray != NULL && iStoreContactsArray->Count() != 0 ) |
|
267 { |
|
268 TInt count = iStoreContactsArray->Count(); |
|
269 for ( TInt i = 0; i < count; i++ ) |
|
270 { |
|
271 const CVPbkFieldFilter::TConfig conf |
|
272 ( const_cast<MVPbkStoreContactFieldCollection&> |
|
273 ( iStoreContactsArray->operator[](i)->Fields() ), |
|
274 iFieldTypeSelector, NULL ); |
|
275 CVPbkFieldFilter* fieldFilter = CVPbkFieldFilter::NewL( conf ); |
|
276 CleanupStack::PushL( fieldFilter ); |
|
277 iFieldFilterArray.AppendL( fieldFilter ); |
|
278 CleanupStack::Pop(); //fieldfilter |
|
279 } |
|
280 } |
|
281 |
|
282 CPbk2ApplicationServices* appServices = |
|
283 CPbk2ApplicationServices::InstanceLC(); |
|
284 iAttributeManager = |
|
285 &appServices->ContactManager().ContactAttributeManagerL(); |
|
286 CleanupStack::PopAndDestroy(); // appServices |
|
287 } |
|
288 |
|
289 // -------------------------------------------------------------------------- |
|
290 // CPbk2AddressSelect::ExecuteLD |
|
291 // -------------------------------------------------------------------------- |
|
292 // |
|
293 EXPORT_C MVPbkStoreContactField* CPbk2AddressSelect::ExecuteLD() |
|
294 { |
|
295 __ASSERT_DEBUG( !iFieldDlg, Panic( EPanicPreCond_ExecuteLD ) ); |
|
296 |
|
297 // "D" function semantics |
|
298 CleanupStack::PushL( this ); |
|
299 TBool thisDestroyed = EFalse; |
|
300 // Ensure that thisDestroyed will be ETrue if this object is destroyed. |
|
301 // See in destructor how this is done. |
|
302 iDestroyedPtr = &thisDestroyed; |
|
303 |
|
304 SelectFieldL(); |
|
305 |
|
306 MVPbkStoreContactField* returnedField = NULL; |
|
307 if ( iSelectedField ) |
|
308 { |
|
309 // We cannot return iSelectedField directly since if its NULL, |
|
310 // it's value changes to 0xdedede before it is returned. |
|
311 // Therefore we must test iSelectedField before assigning it |
|
312 // to returnedField. |
|
313 returnedField = iSelectedField; |
|
314 } |
|
315 |
|
316 if ( thisDestroyed ) |
|
317 { |
|
318 // This object has already been destroyed |
|
319 CleanupStack::Pop( this ); |
|
320 returnedField = NULL; |
|
321 } |
|
322 else |
|
323 { |
|
324 CleanupStack::PopAndDestroy( this ); |
|
325 } |
|
326 |
|
327 return returnedField; |
|
328 } |
|
329 |
|
330 // -------------------------------------------------------------------------- |
|
331 // CPbk2AddressSelect::AttemptExitL |
|
332 // -------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C void CPbk2AddressSelect::AttemptExitL( TBool aAccept ) |
|
335 { |
|
336 if ( iFieldDlg ) |
|
337 { |
|
338 iFieldDlg->AttemptExitL( aAccept ); |
|
339 } |
|
340 } |
|
341 |
|
342 // -------------------------------------------------------------------------- |
|
343 // CPbk2AddressSelect::Pbk2ControlKeyEventL |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 EXPORT_C TKeyResponse CPbk2AddressSelect::Pbk2ControlKeyEventL |
|
347 ( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
348 { |
|
349 TKeyResponse ret = EKeyWasNotConsumed; |
|
350 |
|
351 if ( aType == EEventKey && aKeyEvent.iCode == EKeyPhoneSend ) |
|
352 { |
|
353 // Event is Send key, tell field selection dialog to accept |
|
354 // current selection |
|
355 AttemptExitL( ETrue ); |
|
356 ret = EKeyWasConsumed; |
|
357 } |
|
358 |
|
359 return ret; |
|
360 } |
|
361 |
|
362 // -------------------------------------------------------------------------- |
|
363 // CPbk2AddressSelect::SetCba |
|
364 // -------------------------------------------------------------------------- |
|
365 // |
|
366 EXPORT_C void CPbk2AddressSelect::SetCba( TInt aCbaResourceId ) |
|
367 { |
|
368 iSoftKeyResource = aCbaResourceId; |
|
369 } |
|
370 |
|
371 // -------------------------------------------------------------------------- |
|
372 // CPbk2AddressSelect::RequestExitL |
|
373 // -------------------------------------------------------------------------- |
|
374 // |
|
375 void CPbk2AddressSelect::RequestExitL( TInt aCommandId ) |
|
376 { |
|
377 if ( aCommandId == EEikBidCancel ) |
|
378 { |
|
379 AttemptExitL( EFalse ); |
|
380 } |
|
381 else if ( aCommandId == EEikBidOk ) |
|
382 { |
|
383 AttemptExitL( ETrue ); |
|
384 } |
|
385 } |
|
386 |
|
387 // -------------------------------------------------------------------------- |
|
388 // CPbk2AddressSelect::ForceExit |
|
389 // -------------------------------------------------------------------------- |
|
390 // |
|
391 void CPbk2AddressSelect::ForceExit() |
|
392 { |
|
393 TRAPD( err, AttemptExitL( EFalse ) ); |
|
394 if ( err != KErrNone ) |
|
395 { |
|
396 // If not nicely then use the force |
|
397 delete this; |
|
398 } |
|
399 } |
|
400 |
|
401 // -------------------------------------------------------------------------- |
|
402 // CPbk2AddressSelect::ResetWhenDestroyed |
|
403 // -------------------------------------------------------------------------- |
|
404 // |
|
405 void CPbk2AddressSelect::ResetWhenDestroyed( |
|
406 MPbk2DialogEliminator** aSelfPtr ) |
|
407 { |
|
408 iSelfPtr = aSelfPtr; |
|
409 } |
|
410 |
|
411 // -------------------------------------------------------------------------- |
|
412 // CPbk2AddressSelect::AddressField |
|
413 // Returns true if aField is an applicable address field. |
|
414 // -------------------------------------------------------------------------- |
|
415 // |
|
416 TBool CPbk2AddressSelect::AddressField |
|
417 ( const MVPbkStoreContactField& aField ) const |
|
418 { |
|
419 TBool ret = EFalse; |
|
420 |
|
421 // Return true if field belongs to the selector |
|
422 ret = ( iFieldFilter->FindField( aField ) == |
|
423 KErrNotFound ) ? EFalse : ETrue; |
|
424 |
|
425 return ret; |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // CPbk2AddressSelect::NoAddressesL |
|
430 // Called if there are no applicable address fields in a contact passed |
|
431 // to ExecuteLD. |
|
432 // -------------------------------------------------------------------------- |
|
433 // |
|
434 void CPbk2AddressSelect::NoAddressesL |
|
435 ( TPbk2AddressSelectParams aParams ) const |
|
436 { |
|
437 if ( !aParams.iSuppressWarnings ) |
|
438 { |
|
439 HBufC* prompt = NULL; |
|
440 HBufC* name = aParams.iNameFormatter.GetContactTitleOrNullL |
|
441 ( iParams.iContact.Fields(), KDefaultTitleFormat ); |
|
442 |
|
443 if ( name ) |
|
444 { |
|
445 CleanupStack::PushL(name); |
|
446 prompt = StringLoader::LoadL |
|
447 ( iNoAddressesForNamePromptResource, *name ); |
|
448 CleanupStack::PopAndDestroy(); // name |
|
449 } |
|
450 else |
|
451 { |
|
452 prompt = StringLoader::LoadL( iNoAddressesPromptResource ); |
|
453 } |
|
454 |
|
455 if ( prompt ) |
|
456 { |
|
457 CleanupStack::PushL( prompt ); |
|
458 // This is a waiting dialog because the address select might be |
|
459 // used from the application server and the information note will |
|
460 // disappear if the application server closes before the |
|
461 // note timeout has expired, thus causing blinking |
|
462 CAknInformationNote* noteDlg = |
|
463 new ( ELeave ) CAknInformationNote( ETrue ); |
|
464 noteDlg->ExecuteLD( *prompt ); |
|
465 CleanupStack::PopAndDestroy(); // prompt |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 // -------------------------------------------------------------------------- |
|
471 // CPbk2AddressSelect::SelectFieldL |
|
472 // -------------------------------------------------------------------------- |
|
473 // |
|
474 inline void CPbk2AddressSelect::SelectFieldL() |
|
475 { |
|
476 // If currently focused field is an applicable field |
|
477 if ( iParams.iFocusedField && AddressField( *iParams.iFocusedField ) ) |
|
478 { |
|
479 // Applicable field was focused -> return field |
|
480 SetSelectedFieldL( iParams.iFocusedField ); |
|
481 } |
|
482 else |
|
483 { |
|
484 TBool found = EFalse; |
|
485 // Focus is in on some other field, first check default field |
|
486 if ( iParams.iDefaultPriorities && |
|
487 iParams.iUseDefaultDirectly && |
|
488 iParams.iDefaultPriorities->Count() > 0 ) |
|
489 { |
|
490 found = SelectFromDefaultFieldsL(); |
|
491 } |
|
492 |
|
493 if ( !found ) |
|
494 { |
|
495 // No direct call to focused or default number, we have to |
|
496 // select from applicable fields |
|
497 SelectFromApplicableFieldsL(); |
|
498 } |
|
499 } |
|
500 } |
|
501 |
|
502 // -------------------------------------------------------------------------- |
|
503 // CPbk2AddressSelect::SelectFromApplicableFieldsL |
|
504 // -------------------------------------------------------------------------- |
|
505 // |
|
506 inline void CPbk2AddressSelect::SelectFromApplicableFieldsL() |
|
507 { |
|
508 TInt indexOfDefault = IndexOfDefaultFieldL(); |
|
509 TInt fieldCount = iFieldFilter->FieldCount(); |
|
510 |
|
511 // check also addiotnal contacts |
|
512 if ( iFieldFilterArray.Count() > 0 ) |
|
513 { |
|
514 TInt count = iFieldFilterArray.Count(); |
|
515 for ( TInt i = 0; i < count; i++ ) |
|
516 { |
|
517 fieldCount += iFieldFilterArray[i]->FieldCount(); |
|
518 } |
|
519 } |
|
520 |
|
521 // Different actions for different number of applicable fields found |
|
522 if ( fieldCount == 0 ) |
|
523 { |
|
524 // No applicable addresses found |
|
525 NoAddressesL( iParams ); |
|
526 } |
|
527 else if ( fieldCount == 1 && !iParams.iQueryAlways ) |
|
528 { |
|
529 // Exactly one applicable address found, just return it |
|
530 if ( iFieldFilter->FieldCount() != 0 ) |
|
531 { |
|
532 SetSelectedFieldL( &iFieldFilter->FieldAt( KFirstField ) ); |
|
533 } |
|
534 else |
|
535 { |
|
536 SetSelectedFieldL( &iFieldFilterArray[0]->FieldAt( KFirstField ) ); |
|
537 } |
|
538 } |
|
539 else if (fieldCount > 1 || iParams.iQueryAlways ) |
|
540 { |
|
541 HBufC* title = LoadDialogTitleL(); |
|
542 |
|
543 // Run the address selection dialog |
|
544 CleanupStack::PushL( title ); |
|
545 iFieldDlg = new ( ELeave ) CSelectFieldDlg( *this ); |
|
546 iFieldDlg->ResetWhenDestroyed( &iFieldDlg ); |
|
547 const MVPbkStoreContactField* field = NULL; |
|
548 field = iFieldDlg->ExecuteLCD |
|
549 ( *iFieldFilter, |
|
550 iFieldFilterArray, |
|
551 iPresenceIconsArray, |
|
552 iParams.iContactManager, |
|
553 iParams.iFieldPropertyArray, |
|
554 iSoftKeyResource, |
|
555 iParams.iCommMethod, |
|
556 *title, |
|
557 indexOfDefault ); |
|
558 |
|
559 SetSelectedFieldL( field ); |
|
560 |
|
561 CleanupStack::PopAndDestroy( 2 ); // field, title |
|
562 } |
|
563 } |
|
564 |
|
565 // -------------------------------------------------------------------------- |
|
566 // CPbk2AddressSelect::IndexOfDefaultFieldL |
|
567 // -------------------------------------------------------------------------- |
|
568 // |
|
569 inline TInt CPbk2AddressSelect::IndexOfDefaultFieldL() |
|
570 { |
|
571 TInt ret = KErrNotFound; |
|
572 |
|
573 const MVPbkStoreContactField* field = FindDefaultFieldLC(); |
|
574 if ( field ) |
|
575 { |
|
576 ret = iFieldFilter->FindField( *field ); |
|
577 } |
|
578 CleanupStack::PopAndDestroy(); // field |
|
579 |
|
580 return ret; |
|
581 } |
|
582 |
|
583 // -------------------------------------------------------------------------- |
|
584 // CPbk2AddressSelect::SelectFromDefaultFieldsL |
|
585 // -------------------------------------------------------------------------- |
|
586 // |
|
587 inline TBool CPbk2AddressSelect::SelectFromDefaultFieldsL() |
|
588 { |
|
589 TBool found = EFalse; |
|
590 |
|
591 const MVPbkStoreContactField* field = FindDefaultFieldLC(); |
|
592 if ( field ) |
|
593 { |
|
594 SetSelectedFieldL( field ); |
|
595 found = ETrue; |
|
596 } |
|
597 CleanupStack::PopAndDestroy(); // field |
|
598 |
|
599 return found; |
|
600 } |
|
601 |
|
602 // -------------------------------------------------------------------------- |
|
603 // CPbk2AddressSelect::FindDefaultFieldLC |
|
604 // -------------------------------------------------------------------------- |
|
605 // |
|
606 MVPbkStoreContactField* CPbk2AddressSelect::FindDefaultFieldLC() |
|
607 { |
|
608 MVPbkStoreContactField* ret = NULL; |
|
609 |
|
610 // Go through the default priorities array, and |
|
611 // check does a specific default exist |
|
612 if ( iParams.iDefaultPriorities ) |
|
613 { |
|
614 const TInt defaultCount = iParams.iDefaultPriorities->Count(); |
|
615 |
|
616 for (TInt i=0; i<defaultCount; ++i) |
|
617 { |
|
618 TVPbkDefaultType defaultType = |
|
619 (TVPbkDefaultType) iParams.iDefaultPriorities->At(i); |
|
620 |
|
621 // Create an attribute prototype out of the attribute identifier |
|
622 CVPbkDefaultAttribute* attr = |
|
623 CVPbkDefaultAttribute::NewL( defaultType ); |
|
624 CleanupStack::PushL( attr ); |
|
625 |
|
626 if ( iAttributeManager->HasContactAttributeL |
|
627 ( *attr, iParams.iContact ) ) |
|
628 { |
|
629 const MVPbkStoreContactFieldCollection& fields = |
|
630 iParams.iContact.Fields(); |
|
631 |
|
632 // Get the field with attribute |
|
633 const TInt fieldCount = fields.FieldCount(); |
|
634 for ( TInt j = 0; j < fieldCount; ++j ) |
|
635 { |
|
636 if ( iAttributeManager->HasFieldAttributeL |
|
637 ( *attr, fields.FieldAt( j ) ) ) |
|
638 { |
|
639 ret = fields.FieldAtLC( j ); |
|
640 CleanupStack::Pop(); // ret |
|
641 break; |
|
642 } |
|
643 } |
|
644 } |
|
645 |
|
646 CleanupStack::PopAndDestroy( attr ); |
|
647 } |
|
648 } |
|
649 |
|
650 CleanupDeletePushL( ret ); |
|
651 return ret; |
|
652 } |
|
653 |
|
654 // -------------------------------------------------------------------------- |
|
655 // CPbk2AddressSelect::SetSelectedFieldL |
|
656 // -------------------------------------------------------------------------- |
|
657 // |
|
658 inline void CPbk2AddressSelect::SetSelectedFieldL |
|
659 ( const MVPbkStoreContactField* aField ) |
|
660 { |
|
661 if ( aField ) |
|
662 { |
|
663 const MVPbkStoreContactFieldCollection& fields = |
|
664 iParams.iContact.Fields(); |
|
665 TInt index = IndexOfField( fields, *aField ); |
|
666 if ( index >= 0 ) |
|
667 { |
|
668 // field from main contact |
|
669 iSelectedField = fields.FieldAtLC( index ); |
|
670 CleanupStack::Pop(); |
|
671 } |
|
672 else if ( iStoreContactsArray != NULL && |
|
673 iStoreContactsArray->Count() > 0 ) |
|
674 { |
|
675 // field from additional contact |
|
676 TInt count = iStoreContactsArray->Count(); |
|
677 for( TInt i = 0; i < count; i++ ) |
|
678 { |
|
679 const MVPbkStoreContactFieldCollection& xspFields = |
|
680 iStoreContactsArray->operator[](i)->Fields(); |
|
681 index = IndexOfField( xspFields, *aField ); |
|
682 if ( index >= 0 ) |
|
683 { |
|
684 iSelectedField = xspFields.FieldAtLC( index ); |
|
685 CleanupStack::Pop(); |
|
686 break; |
|
687 } |
|
688 } |
|
689 } |
|
690 } |
|
691 } |
|
692 |
|
693 // -------------------------------------------------------------------------- |
|
694 // CPbk2AddressSelect::LoadDialogTitleL |
|
695 // -------------------------------------------------------------------------- |
|
696 // |
|
697 inline HBufC* CPbk2AddressSelect::LoadDialogTitleL() |
|
698 { |
|
699 HBufC* title = NULL; |
|
700 switch( iParams.iCommMethod ) |
|
701 { |
|
702 case VPbkFieldTypeSelectorFactory::EVoiceCallSelector: |
|
703 { |
|
704 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_CALL ); |
|
705 break; |
|
706 } |
|
707 case VPbkFieldTypeSelectorFactory::EUniEditorSelector: |
|
708 { |
|
709 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_MESSAGE ); |
|
710 break; |
|
711 } |
|
712 case VPbkFieldTypeSelectorFactory::EEmailEditorSelector: |
|
713 { |
|
714 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_EMAIL ); |
|
715 break; |
|
716 } |
|
717 case VPbkFieldTypeSelectorFactory::EInstantMessagingSelector: |
|
718 { |
|
719 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_CHAT ); |
|
720 break; |
|
721 } |
|
722 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector: |
|
723 { |
|
724 title = GetVOIPDialogTitleL(); |
|
725 break; |
|
726 } |
|
727 case VPbkFieldTypeSelectorFactory::EURLSelector: |
|
728 { |
|
729 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_URL ); |
|
730 break; |
|
731 } |
|
732 case VPbkFieldTypeSelectorFactory::EVideoCallSelector: |
|
733 { |
|
734 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_VIDEO_CALL ); |
|
735 break; |
|
736 } |
|
737 case VPbkFieldTypeSelectorFactory::EFindOnMapSelector: |
|
738 { |
|
739 if ( AreGeoFieldsForAddressesL() ) |
|
740 { |
|
741 title = StringLoader::LoadL( R_QTN_CCA_POPUP_SHOW_ON_MAP ); |
|
742 } |
|
743 else |
|
744 { |
|
745 title = StringLoader::LoadL( R_QTN_CCA_POPUP_FIND_ON_MAP ); |
|
746 } |
|
747 break; |
|
748 } |
|
749 case VPbkFieldTypeSelectorFactory::EAssignFromMapSelector: |
|
750 { |
|
751 title = StringLoader::LoadL( R_QTN_CCA_POPUP_ASSIGN_FROM_MAP ); |
|
752 break; |
|
753 } |
|
754 case VPbkFieldTypeSelectorFactory::EPocSelector: |
|
755 { |
|
756 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_PUSH_TO_TALK ); |
|
757 break; |
|
758 } |
|
759 default: |
|
760 { |
|
761 HBufC* entryTitle = iParams.iNameFormatter.GetContactTitleL |
|
762 ( iParams.iContact.Fields(), KDefaultTitleFormat ); |
|
763 CleanupStack::PushL( entryTitle ); |
|
764 |
|
765 if ( iParams.iTitleResId ) |
|
766 { |
|
767 if ( iParams.iIncludeContactNameInPrompt ) |
|
768 { |
|
769 title = StringLoader::LoadL |
|
770 ( iParams.iTitleResId, *entryTitle ); |
|
771 } |
|
772 else |
|
773 { |
|
774 title = StringLoader::LoadL |
|
775 ( iParams.iTitleResId ); |
|
776 } |
|
777 CleanupStack::PopAndDestroy( entryTitle ); |
|
778 } |
|
779 else |
|
780 { |
|
781 title = entryTitle; // takes ownership of entryTitle |
|
782 CleanupStack::Pop( entryTitle ); |
|
783 entryTitle = NULL; |
|
784 } |
|
785 break; |
|
786 } |
|
787 } |
|
788 |
|
789 return title; |
|
790 } |
|
791 |
|
792 // -------------------------------------------------------------------------- |
|
793 // CPbk2AddressSelect::AreGeoFieldsForAddressesL |
|
794 // -------------------------------------------------------------------------- |
|
795 // |
|
796 TBool CPbk2AddressSelect::AreGeoFieldsForAddressesL() |
|
797 { |
|
798 TBool result = EFalse; |
|
799 TBool generalAddress = ETrue; |
|
800 TBool homeAddress = ETrue; |
|
801 TBool workAddress = ETrue; |
|
802 TInt startIndex = 0; |
|
803 |
|
804 TPbk2StoreContactAnalyzer analyzer( iParams.iContactManager, NULL ); |
|
805 |
|
806 TInt countFields = iParams.iContact.Fields().FieldCount(); |
|
807 for ( TInt i = 0; i < countFields; i++ ) |
|
808 { |
|
809 const MVPbkStoreContactField& field = |
|
810 iParams.iContact.Fields().FieldAt( i ); |
|
811 TInt countProps = |
|
812 field.BestMatchingFieldType()->VersitProperties().Count(); |
|
813 TArray<TVPbkFieldVersitProperty> props = |
|
814 field.BestMatchingFieldType()->VersitProperties(); |
|
815 for ( TInt ii = 0; ii < countProps; ii++ ) |
|
816 { |
|
817 if ( props[ ii ].Name() == EVPbkVersitNameADR ) |
|
818 { |
|
819 if ( props[ ii ].Parameters().Contains( |
|
820 EVPbkVersitParamHOME ) ) |
|
821 { |
|
822 homeAddress = EFalse; |
|
823 } |
|
824 else if ( props[ ii ].Parameters().Contains( |
|
825 EVPbkVersitParamWORK ) ) |
|
826 { |
|
827 workAddress = EFalse; |
|
828 } |
|
829 else |
|
830 { |
|
831 generalAddress = EFalse; |
|
832 } |
|
833 } |
|
834 } |
|
835 } |
|
836 |
|
837 if ( !homeAddress ) |
|
838 { |
|
839 if ( analyzer.HasFieldL( R_PHONEBOOK2_HOME_GEO_SELECTOR, |
|
840 startIndex, &iParams.iContact ) != KErrNotFound ) |
|
841 { |
|
842 homeAddress = ETrue; |
|
843 } |
|
844 } |
|
845 if ( !workAddress ) |
|
846 { |
|
847 if ( analyzer.HasFieldL( R_PHONEBOOK2_WORK_GEO_SELECTOR, |
|
848 startIndex, &iParams.iContact ) != KErrNotFound ) |
|
849 { |
|
850 workAddress = ETrue; |
|
851 } |
|
852 } |
|
853 if ( !generalAddress ) |
|
854 { |
|
855 if ( analyzer.HasFieldL( R_PHONEBOOK2_GENERAL_GEO_SELECTOR, |
|
856 startIndex, &iParams.iContact ) != KErrNotFound ) |
|
857 { |
|
858 generalAddress = ETrue; |
|
859 } |
|
860 } |
|
861 |
|
862 if ( generalAddress && homeAddress && workAddress ) |
|
863 { |
|
864 result = ETrue; |
|
865 } |
|
866 else |
|
867 { |
|
868 result = EFalse; |
|
869 } |
|
870 |
|
871 return result; |
|
872 } |
|
873 |
|
874 // -------------------------------------------------------------------------- |
|
875 // CPbk2AddressSelect::GetVOIPDialogTitleL |
|
876 // -------------------------------------------------------------------------- |
|
877 // |
|
878 inline HBufC* CPbk2AddressSelect::GetVOIPDialogTitleL() |
|
879 { |
|
880 //Usecase : If we have only one voip service, the voip(Internet Call) |
|
881 //dialog title must be "ServiceName" appended with "call:". |
|
882 //eg : If we have a service named SKYPE installed in the Phone |
|
883 //and if SKYPE supports VOIP, dialog title should be |
|
884 //"SKYPE call:". |
|
885 //If we have more than one voip service, then the VOIP dialog title must be |
|
886 //should be R_QTN_PHOB_TITLE_POPUP_VOIP_CALL |
|
887 //as defined in the rss |
|
888 |
|
889 //Check whether we have more than one voip service configured |
|
890 //in the Phone |
|
891 HBufC* title (NULL); |
|
892 TPtrC tempTitle; |
|
893 RIdArray idArray; |
|
894 CleanupClosePushL(idArray); |
|
895 CSPSettings* settings = CSPSettings::NewLC(); |
|
896 TInt numServSupportInternetCall (0); //Num of Service that support InternetCall |
|
897 TServiceId serviceId (0); //Stores the last found Service Id of VOIP Service |
|
898 TInt findResult = settings->FindServiceIdsL(idArray); |
|
899 if ( findResult == KErrNone ) |
|
900 { |
|
901 for (TInt i = 0; i < idArray.Count(); ++i) |
|
902 { |
|
903 TBool supported( EFalse ); |
|
904 CSPEntry* entry = CSPEntry::NewLC(); |
|
905 TServiceId id = idArray[i]; |
|
906 User::LeaveIfError( settings->FindEntryL(id, *entry) ); |
|
907 const CSPProperty* property = NULL; |
|
908 |
|
909 //Mandatory Settings for VOIP |
|
910 if (entry->GetProperty(property, EPropertyServiceAttributeMask) == KErrNone) |
|
911 { |
|
912 TInt value = 0; |
|
913 property->GetValue(value); |
|
914 if ( value & ESupportsInternetCall ) |
|
915 { |
|
916 serviceId = id; |
|
917 numServSupportInternetCall++; |
|
918 } |
|
919 } |
|
920 CleanupStack::PopAndDestroy(); // entry |
|
921 } |
|
922 CleanupStack::PopAndDestroy(2); // settings, idArray |
|
923 |
|
924 if ( KOneVOIPServiceAvailable == numServSupportInternetCall ) |
|
925 { |
|
926 // get the XSP ServiceName |
|
927 // CPbk2ServiceManager stores all the brandinfo |
|
928 // related to the services configured to the phone |
|
929 // use this to show uniform icon & name throughout PhoneBook |
|
930 MPbk2ApplicationServices2* servicesExtension = |
|
931 reinterpret_cast<MPbk2ApplicationServices2*> |
|
932 ( Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
933 MPbk2ApplicationServicesExtension( |
|
934 KMPbk2ApplicationServicesExtension2Uid ) ); |
|
935 CPbk2ServiceManager& servMan = servicesExtension->ServiceManager(); |
|
936 const CPbk2ServiceManager::RServicesArray& services = servMan.Services(); |
|
937 for ( TInt i = 0; i < services.Count(); i++ ) |
|
938 { |
|
939 const CPbk2ServiceManager::TService& service = services[i]; |
|
940 //Found the appropriate service info |
|
941 if ( service.iServiceId == serviceId ) |
|
942 { |
|
943 tempTitle.Set( service.iDisplayName ); |
|
944 break; |
|
945 } |
|
946 } |
|
947 } |
|
948 } |
|
949 if ( tempTitle.Length() ) |
|
950 { |
|
951 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_VOIP_CALL_SINGLE_SERVICE, |
|
952 tempTitle); |
|
953 } |
|
954 else |
|
955 { |
|
956 title = StringLoader::LoadL( R_QTN_PHOB_TITLE_POPUP_VOIP_CALL ); |
|
957 } |
|
958 |
|
959 return title; |
|
960 } |
|
961 |
|
962 // End of File |