|
1 /* |
|
2 * Copyright (c) 2002-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: The contact manager for accessing different stores. |
|
15 * Initialization: a client gives an array of store URIs (Virtual |
|
16 * offers some URIs, see VPbkStoreUriLiterals.h) when creating |
|
17 * a manager. The client uses store list to open all stores. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 // INCLUDES |
|
23 #include "CVPbkContactManager.h" |
|
24 |
|
25 // Virtual Phonebook |
|
26 #include "CVPbkFieldType.h" |
|
27 #include "CVPbkFieldTypeList.h" |
|
28 #include "CVPbkContactStoreDomainList.h" |
|
29 #include "CVPbkCompositeContactView.h" |
|
30 #include "CVPbkCopyContactsOperation.h" |
|
31 #include "CVPbkFoldingContactView.h" |
|
32 #include "CVPbkContactAttributeManager.h" |
|
33 #include "MVPbkContactStoreLoader.h" |
|
34 #include "VPbkCompositeContactViewFactory.h" |
|
35 |
|
36 #include <MVPbkContactStore.h> |
|
37 #include <MVPbkContactStoreProperties.h> |
|
38 #include <MVPbkContactLink.h> |
|
39 #include <MVPbkStoreContact.h> |
|
40 #include <CVPbkContactViewDefinition.h> |
|
41 #include <MVPbkContactView.h> |
|
42 #include <MVPbkContactOperation.h> |
|
43 #include <VPbkEng.rsg> |
|
44 #include <VPbkDataCaging.hrh> |
|
45 #include <CVPbkContactLinkArray.h> |
|
46 #include <CVPbkContactStoreUriArray.h> |
|
47 #include <CVPbkContactCopier.h> |
|
48 #include <MVPbkContactOperationFactory.h> |
|
49 #include <MVPbkContactOperationFactory2.h> |
|
50 // System includes |
|
51 #include <s32buf.h> |
|
52 #include <s32mem.h> |
|
53 #include <barsc.h> |
|
54 #include <bautils.h> |
|
55 #include <barsread.h> |
|
56 #include <ecom/ecom.h> |
|
57 #include <RLocalizedResourceFile.h> |
|
58 |
|
59 #ifdef _DEBUG |
|
60 namespace { |
|
61 enum TPanic |
|
62 { |
|
63 EPreCond_CreateContactViewLC, |
|
64 EUnknownViewType_CreateContactViewLC, |
|
65 ENo_Factory_Extension_FindL |
|
66 }; |
|
67 |
|
68 void Panic( TPanic aPanic ) |
|
69 { |
|
70 _LIT(KPanicCat, "CVPbkContactManager"); |
|
71 User::Panic( KPanicCat, aPanic ); |
|
72 } |
|
73 } |
|
74 #endif // _DEBUG |
|
75 |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // IsPlaceHolderCompositeView |
|
79 // Returns ETrue if aViewDefinition is a composite that has no children |
|
80 // -------------------------------------------------------------------------- |
|
81 // |
|
82 TBool IsPlaceHolderCompositeView( |
|
83 const CVPbkContactViewDefinition& aViewDefinition ) |
|
84 { |
|
85 return ( aViewDefinition.Type() == EVPbkCompositeView && |
|
86 aViewDefinition.SubViewCount() == 0 ); |
|
87 } |
|
88 |
|
89 /** |
|
90 * A loader class that uses CVPbkContactManager for loading stores |
|
91 */ |
|
92 NONSHARABLE_CLASS(CVPbkContactManager::CContactStoreLoader) |
|
93 : public CBase, |
|
94 public MVPbkContactStoreLoader |
|
95 { |
|
96 public: |
|
97 CContactStoreLoader( CVPbkContactManager& aContactManager ); |
|
98 |
|
99 // From base class MVPbkContactStoreLoader |
|
100 MVPbkContactStoreList& ContactStoreListL() const; |
|
101 void LoadContactStoreL( const TVPbkContactStoreUriPtr& aURI ); |
|
102 |
|
103 private: |
|
104 CVPbkContactManager& iContactManager; |
|
105 }; |
|
106 |
|
107 CVPbkContactManager::CContactStoreLoader::CContactStoreLoader( |
|
108 CVPbkContactManager& aContactManager ) |
|
109 : iContactManager( aContactManager ) |
|
110 { |
|
111 } |
|
112 |
|
113 MVPbkContactStoreList& |
|
114 CVPbkContactManager::CContactStoreLoader::ContactStoreListL() const |
|
115 { |
|
116 return iContactManager.ContactStoresL(); |
|
117 } |
|
118 |
|
119 void CVPbkContactManager::CContactStoreLoader::LoadContactStoreL( |
|
120 const TVPbkContactStoreUriPtr& aURI ) |
|
121 { |
|
122 iContactManager.LoadContactStoreL( aURI ); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CVPbkContactManager::CVPbkContactManager |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 inline CVPbkContactManager::CVPbkContactManager( TSecurityInfo aSecurityInfo, RFs* aFs) |
|
130 : iSecurityInfo( aSecurityInfo ) |
|
131 { |
|
132 if (aFs) |
|
133 { |
|
134 iFs = *aFs; |
|
135 } |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------- |
|
139 // CVPbkContactManager::~CVPbkContactManager |
|
140 // -------------------------------------------------------------------------- |
|
141 // |
|
142 CVPbkContactManager::~CVPbkContactManager() |
|
143 { |
|
144 delete iStoreLoader; |
|
145 delete iAttributeManager; |
|
146 delete iContactStoreDomains; |
|
147 delete iFieldTypes; |
|
148 iOwnFs.Close(); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CVPbkContactManager::NewL |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C CVPbkContactManager* CVPbkContactManager::NewL( |
|
156 const CVPbkContactStoreUriArray& aURIList, |
|
157 RFs* aFs /*= NULL*/) |
|
158 { |
|
159 TSecurityInfo secInfo; |
|
160 secInfo.SetToCurrentInfo(); |
|
161 CVPbkContactManager* self = new(ELeave) CVPbkContactManager( secInfo, aFs); |
|
162 CleanupStack::PushL(self); |
|
163 self->ConstructL(aURIList); |
|
164 CleanupStack::Pop(self); |
|
165 return self; |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 // CVPbkContactManager::NewL |
|
170 // -------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C CVPbkContactManager* CVPbkContactManager::NewL( |
|
173 TSecurityInfo aSecurityInfo, |
|
174 const CVPbkContactStoreUriArray& aURIList, |
|
175 RFs* aFs /*= NULL*/) |
|
176 { |
|
177 CVPbkContactManager* self = new(ELeave) CVPbkContactManager( aSecurityInfo, aFs); |
|
178 CleanupStack::PushL(self); |
|
179 self->ConstructL(aURIList); |
|
180 CleanupStack::Pop(self); |
|
181 return self; |
|
182 } |
|
183 |
|
184 // -------------------------------------------------------------------------- |
|
185 // CVPbkContactManager::ConstructL |
|
186 // -------------------------------------------------------------------------- |
|
187 // |
|
188 inline void CVPbkContactManager::ConstructL |
|
189 (const CVPbkContactStoreUriArray& aURIList) |
|
190 { |
|
191 if (iFs.Handle() == KNullHandle) |
|
192 { |
|
193 User::LeaveIfError(iOwnFs.Connect()); |
|
194 iFs = iOwnFs; |
|
195 } |
|
196 |
|
197 VPbkEngUtils::RLocalizedResourceFile resFile; |
|
198 resFile.OpenLC( iFs, KVPbkRomFileDrive, |
|
199 KDC_RESOURCE_FILES_DIR, KVPbkDefResFileName ); |
|
200 HBufC8* fieldTypesBuf = resFile.AllocReadLC(R_VPBK_GLOBAL_FIELD_TYPES); |
|
201 TResourceReader resReader; |
|
202 resReader.SetBuffer(fieldTypesBuf); |
|
203 iFieldTypes = CVPbkFieldTypeList::NewL(resFile, resReader); |
|
204 CleanupStack::PopAndDestroy(2, &resFile); |
|
205 |
|
206 iContactStoreDomains = |
|
207 CVPbkContactStoreDomainList::NewL( aURIList, *iFieldTypes, iSecurityInfo ); |
|
208 |
|
209 iStoreLoader = new( ELeave ) CContactStoreLoader( *this ); |
|
210 } |
|
211 |
|
212 // -------------------------------------------------------------------------- |
|
213 // CVPbkContactManager::FieldTypes |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C const MVPbkFieldTypeList& CVPbkContactManager::FieldTypes() const |
|
217 { |
|
218 return *iFieldTypes; |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CVPbkContactManager::ContactStoresL |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C MVPbkContactStoreList& CVPbkContactManager::ContactStoresL() |
|
226 { |
|
227 return *iContactStoreDomains; |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CVPbkContactManager::LoadContactStoreL |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C void CVPbkContactManager::LoadContactStoreL |
|
235 (const TVPbkContactStoreUriPtr& aURI) |
|
236 { |
|
237 if (!iContactStoreDomains->Find(aURI)) |
|
238 { |
|
239 CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC(); |
|
240 uriList->AppendL(aURI); |
|
241 |
|
242 iContactStoreDomains->LoadPluginStoreDomainsL( *uriList, *iFieldTypes, |
|
243 iSecurityInfo ); |
|
244 |
|
245 CleanupStack::PopAndDestroy(); // uriList |
|
246 } |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // CVPbkContactManager::ContactAttributeManagerL |
|
251 // -------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C MVPbkContactAttributeManager& |
|
254 CVPbkContactManager::ContactAttributeManagerL() |
|
255 { |
|
256 if (!iAttributeManager) |
|
257 { |
|
258 iAttributeManager = CVPbkContactAttributeManager::NewL(*this); |
|
259 } |
|
260 |
|
261 return *iAttributeManager; |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CVPbkContactManager::CreateContactViewLC |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 EXPORT_C MVPbkContactViewBase* CVPbkContactManager::CreateContactViewLC( |
|
269 MVPbkContactViewObserver& aObserver, |
|
270 const CVPbkContactViewDefinition& aViewDefinition, |
|
271 const MVPbkFieldTypeList& aSortOrder) const |
|
272 { |
|
273 MVPbkContactViewBase* result = NULL; |
|
274 |
|
275 switch ( aViewDefinition.Type() ) |
|
276 { |
|
277 case EVPbkContactsView: // FALLTHROUGH |
|
278 case EVPbkGroupsView: |
|
279 { |
|
280 // Create a leaf view from the store plug-in. |
|
281 MVPbkContactStore* store = FindStore( aViewDefinition.Uri() ); |
|
282 if ( !store ) |
|
283 { |
|
284 User::Leave( KErrNotFound ); |
|
285 } |
|
286 result = store->CreateViewLC( aViewDefinition, aObserver, |
|
287 aSortOrder ); |
|
288 break; |
|
289 } |
|
290 case EVPbkFoldingView: |
|
291 { |
|
292 // Create a folding view. Folding view can then |
|
293 // be expanded to its subviews. |
|
294 result = CVPbkFoldingContactView::NewLC( aObserver, |
|
295 aViewDefinition, *this, aSortOrder ); |
|
296 break; |
|
297 } |
|
298 case EVPbkCompositeView: |
|
299 { |
|
300 result = CreateOptimizedCompositeViewLC( aObserver, |
|
301 aViewDefinition, aSortOrder ); |
|
302 break; |
|
303 } |
|
304 default: |
|
305 { |
|
306 __ASSERT_DEBUG( EFalse, Panic ( EUnknownViewType_CreateContactViewLC )); |
|
307 CleanupStack::PushL( result ); // LC semantics |
|
308 break; |
|
309 } |
|
310 } |
|
311 return result; |
|
312 } |
|
313 |
|
314 // -------------------------------------------------------------------------- |
|
315 // CVPbkContactManager::RetrieveContactL |
|
316 // -------------------------------------------------------------------------- |
|
317 // |
|
318 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::RetrieveContactL( |
|
319 const MVPbkContactLink& aLink, |
|
320 MVPbkSingleContactOperationObserver& aObserver) const |
|
321 { |
|
322 MVPbkContactOperation* operation = |
|
323 iContactStoreDomains->CreateContactRetrieverL( aLink, aObserver ); |
|
324 |
|
325 if (operation) |
|
326 { |
|
327 CleanupDeletePushL(operation); |
|
328 operation->StartL(); |
|
329 CleanupStack::Pop(); // operation |
|
330 } |
|
331 |
|
332 return operation; |
|
333 } |
|
334 |
|
335 // -------------------------------------------------------------------------- |
|
336 // CVPbkContactManager::CreateLinksLC |
|
337 // -------------------------------------------------------------------------- |
|
338 // |
|
339 EXPORT_C MVPbkContactLinkArray* CVPbkContactManager::CreateLinksLC( |
|
340 const TDesC8& aPackedLinks) const |
|
341 { |
|
342 RDesReadStream readStream( aPackedLinks ); |
|
343 readStream.PushL(); |
|
344 CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC( |
|
345 readStream, *iStoreLoader ); |
|
346 CleanupStack::Pop( linkArray ); |
|
347 CleanupStack::PopAndDestroy( &readStream ); |
|
348 CleanupStack::PushL( linkArray ); |
|
349 return linkArray; |
|
350 } |
|
351 |
|
352 // -------------------------------------------------------------------------- |
|
353 // CVPbkContactManager::CreateLinksLC |
|
354 // -------------------------------------------------------------------------- |
|
355 // |
|
356 EXPORT_C MVPbkContactLinkArray* CVPbkContactManager::CreateLinksLC( |
|
357 RReadStream& aStream) const |
|
358 { |
|
359 CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC( |
|
360 aStream, *iStoreLoader ); |
|
361 return linkArray; |
|
362 } |
|
363 |
|
364 // -------------------------------------------------------------------------- |
|
365 // CVPbkContactManager::DeleteContactsL |
|
366 // -------------------------------------------------------------------------- |
|
367 // |
|
368 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::DeleteContactsL( |
|
369 const MVPbkContactLinkArray& aContactLinks, |
|
370 MVPbkBatchOperationObserver& aObserver) |
|
371 { |
|
372 MVPbkContactOperation* operation = |
|
373 iContactStoreDomains->CreateDeleteContactsOperationL( |
|
374 aContactLinks, aObserver); |
|
375 |
|
376 if (operation) |
|
377 { |
|
378 CleanupDeletePushL(operation); |
|
379 operation->StartL(); |
|
380 CleanupStack::Pop(); // operation |
|
381 } |
|
382 |
|
383 return operation; |
|
384 } |
|
385 |
|
386 // -------------------------------------------------------------------------- |
|
387 // CVPbkContactManager::CommitContactsL |
|
388 // -------------------------------------------------------------------------- |
|
389 // |
|
390 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::CommitContactsL( |
|
391 const TArray<MVPbkStoreContact*>& aContacts, |
|
392 MVPbkBatchOperationObserver& aObserver) |
|
393 { |
|
394 MVPbkContactOperation* operation = |
|
395 iContactStoreDomains->CreateCommitContactsOperationL( |
|
396 aContacts, aObserver); |
|
397 |
|
398 if (operation) |
|
399 { |
|
400 CleanupDeletePushL(operation); |
|
401 operation->StartL(); |
|
402 CleanupStack::Pop(); // operation |
|
403 } |
|
404 |
|
405 return operation; |
|
406 } |
|
407 |
|
408 // -------------------------------------------------------------------------- |
|
409 // CVPbkContactManager::CopyContactsL |
|
410 // -------------------------------------------------------------------------- |
|
411 // |
|
412 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::CopyContactsL( |
|
413 const MVPbkContactLinkArray& aContactLinks, |
|
414 MVPbkContactStore* aTargetStore, |
|
415 MVPbkBatchOperationObserver& aObserver) |
|
416 { |
|
417 MVPbkContactOperation* operation = CVPbkCopyContactsOperation::NewLC( |
|
418 CVPbkContactCopier::EVPbkSimpleContactCopy, |
|
419 *this, |
|
420 aContactLinks, |
|
421 aTargetStore, |
|
422 NULL, |
|
423 aObserver); |
|
424 operation->StartL(); |
|
425 CleanupStack::Pop(); // operation |
|
426 return operation; |
|
427 } |
|
428 |
|
429 // -------------------------------------------------------------------------- |
|
430 // CVPbkContactManager::MatchPhoneNumberL |
|
431 // -------------------------------------------------------------------------- |
|
432 // |
|
433 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::MatchPhoneNumberL( |
|
434 const TDesC& aPhoneNumber, |
|
435 TInt aMaxMatchDigits, |
|
436 MVPbkContactFindObserver& aObserver) |
|
437 { |
|
438 MVPbkContactOperation* operation = |
|
439 iContactStoreDomains->CreateMatchPhoneNumberOperationL( |
|
440 aPhoneNumber, aMaxMatchDigits, aObserver); |
|
441 |
|
442 if (operation) |
|
443 { |
|
444 CleanupDeletePushL(operation); |
|
445 operation->StartL(); |
|
446 CleanupStack::Pop(); // operation |
|
447 } |
|
448 |
|
449 return operation; |
|
450 } |
|
451 |
|
452 // -------------------------------------------------------------------------- |
|
453 // CVPbkContactManager::FindL |
|
454 // -------------------------------------------------------------------------- |
|
455 // |
|
456 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::FindL( |
|
457 const TDesC& aSearchString, |
|
458 const MVPbkFieldTypeList& aFieldTypes, |
|
459 MVPbkContactFindObserver& aObserver) |
|
460 { |
|
461 MVPbkContactOperation* operation = |
|
462 (static_cast<MVPbkContactOperationFactory*>(iContactStoreDomains))->CreateFindOperationL( |
|
463 aSearchString, aFieldTypes, aObserver); |
|
464 |
|
465 if (operation) |
|
466 { |
|
467 CleanupDeletePushL(operation); |
|
468 operation->StartL(); |
|
469 CleanupStack::Pop(); // operation |
|
470 } |
|
471 |
|
472 return operation; |
|
473 } |
|
474 |
|
475 // -------------------------------------------------------------------------- |
|
476 // CVPbkContactManager::FindL |
|
477 // -------------------------------------------------------------------------- |
|
478 // |
|
479 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::FindL( |
|
480 const MDesC16Array& aSearchStrings, |
|
481 const MVPbkFieldTypeList& aFieldTypes, |
|
482 MVPbkContactFindFromStoresObserver& aObserver, |
|
483 const TCallBack& aWordParserCallBack ) |
|
484 { |
|
485 MVPbkContactOperation* operation = |
|
486 (static_cast<MVPbkContactOperationFactory*>(iContactStoreDomains))->CreateFindOperationL( |
|
487 aSearchStrings, aFieldTypes, aObserver, aWordParserCallBack ); |
|
488 if (operation) |
|
489 { |
|
490 CleanupDeletePushL(operation); |
|
491 operation->StartL(); |
|
492 CleanupStack::Pop(); // operation |
|
493 } |
|
494 |
|
495 return operation; |
|
496 } |
|
497 |
|
498 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::FindL( |
|
499 const MDesC16Array& aSearchStrings, |
|
500 const MVPbkFieldTypeList& aFieldTypes, |
|
501 MVPbkContactFindFromStoresObserver& aObserver, |
|
502 const TCallBack& aWordParserCallBack, const CDesC16ArrayFlat& aStoreEntriesArray ) |
|
503 { |
|
504 MVPbkContactOperation* operation = NULL; |
|
505 |
|
506 MVPbkContactOperationFactory2* factoryExtension = reinterpret_cast<MVPbkContactOperationFactory2*> |
|
507 (iContactStoreDomains->ContactOperationFactoryExtension(KMVPbkContactOperationFactory2Uid) ); |
|
508 |
|
509 // Safeguard to avoid factory extension initialization. It is a programming error if |
|
510 // factory extension does not exist. |
|
511 __ASSERT_DEBUG(factoryExtension, Panic( ENo_Factory_Extension_FindL ) ); |
|
512 |
|
513 operation = |
|
514 factoryExtension->CreateFindOperationL( |
|
515 aSearchStrings, aFieldTypes, aObserver, aWordParserCallBack ,aStoreEntriesArray ); |
|
516 |
|
517 if (operation) |
|
518 { |
|
519 CleanupDeletePushL(operation); |
|
520 operation->StartL(); |
|
521 CleanupStack::Pop(); // operation |
|
522 } |
|
523 |
|
524 |
|
525 return operation; |
|
526 } |
|
527 |
|
528 // -------------------------------------------------------------------------- |
|
529 // CVPbkContactManager::CompressStoresL |
|
530 // -------------------------------------------------------------------------- |
|
531 // |
|
532 EXPORT_C MVPbkContactOperationBase* CVPbkContactManager::CompressStoresL( |
|
533 MVPbkBatchOperationObserver& aObserver) |
|
534 { |
|
535 MVPbkContactOperation* operation = |
|
536 iContactStoreDomains->CreateCompressStoresOperationL(aObserver); |
|
537 |
|
538 if (operation) |
|
539 { |
|
540 CleanupDeletePushL(operation); |
|
541 operation->StartL(); |
|
542 CleanupStack::Pop(); // operation |
|
543 } |
|
544 |
|
545 return operation; |
|
546 } |
|
547 |
|
548 // -------------------------------------------------------------------------- |
|
549 // CVPbkContactManager::FsSession |
|
550 // -------------------------------------------------------------------------- |
|
551 // |
|
552 EXPORT_C RFs& CVPbkContactManager::FsSession() |
|
553 { |
|
554 return iFs; |
|
555 } |
|
556 |
|
557 // -------------------------------------------------------------------------- |
|
558 // CVPbkContactManager::FindStore |
|
559 // -------------------------------------------------------------------------- |
|
560 // |
|
561 MVPbkContactStore* CVPbkContactManager::FindStore |
|
562 ( const TVPbkContactStoreUriPtr& aURI ) const |
|
563 { |
|
564 const TInt count = iContactStoreDomains->Count(); |
|
565 for (TInt i = 0; i < count; ++i) |
|
566 { |
|
567 MVPbkContactStore& store = iContactStoreDomains->At(i); |
|
568 if (store.StoreProperties().Uri().Compare(aURI, |
|
569 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0) |
|
570 { |
|
571 return &store; |
|
572 } |
|
573 } |
|
574 return NULL; |
|
575 } |
|
576 |
|
577 // -------------------------------------------------------------------------- |
|
578 // CVPbkContactManager::CreateOptimizedCompositeViewLC |
|
579 // -------------------------------------------------------------------------- |
|
580 // |
|
581 MVPbkContactViewBase* CVPbkContactManager::CreateOptimizedCompositeViewLC( |
|
582 MVPbkContactViewObserver& aObserver, |
|
583 const CVPbkContactViewDefinition& aViewDefinition, |
|
584 const MVPbkFieldTypeList& aSortOrder) const |
|
585 { |
|
586 // First the placeholder composites must be reduced from the count |
|
587 // so that the actual number of subviews are known. |
|
588 TInt subViewCount = aViewDefinition.SubViewCount(); |
|
589 TInt actualSubViewCount = subViewCount; |
|
590 for ( TInt i = 0; i < subViewCount; ++i ) |
|
591 { |
|
592 if ( IsPlaceHolderCompositeView( aViewDefinition.SubViewAt( i ) ) ) |
|
593 { |
|
594 --actualSubViewCount; |
|
595 } |
|
596 } |
|
597 |
|
598 MVPbkContactViewBase* result = NULL; |
|
599 const TInt oneSubview = 1; |
|
600 if ( actualSubViewCount == oneSubview ) |
|
601 { |
|
602 // Create the one subview directly using aObserver. |
|
603 // Loop must be used to ignore placeholders. |
|
604 for ( TInt i = 0; i < subViewCount && !result; ++i ) |
|
605 { |
|
606 result = CreateContactViewLC( aObserver, |
|
607 aViewDefinition.SubViewAt( i ), aSortOrder ); |
|
608 if ( !result ) |
|
609 { |
|
610 CleanupStack::Pop( result ); |
|
611 } |
|
612 } |
|
613 } |
|
614 else |
|
615 { |
|
616 // many subviews |
|
617 result = CreateCompositeViewLC( aObserver, aViewDefinition, |
|
618 aSortOrder ); |
|
619 } |
|
620 return result; |
|
621 } |
|
622 |
|
623 // -------------------------------------------------------------------------- |
|
624 // CVPbkContactManager::CreateCompositeViewLC |
|
625 // -------------------------------------------------------------------------- |
|
626 // |
|
627 MVPbkContactViewBase* CVPbkContactManager::CreateCompositeViewLC( |
|
628 MVPbkContactViewObserver& aObserver, |
|
629 const CVPbkContactViewDefinition& aViewDefinition, |
|
630 const MVPbkFieldTypeList& aSortOrder) const |
|
631 { |
|
632 MVPbkContactViewBase* result = NULL; |
|
633 const TInt subViewCount = aViewDefinition.SubViewCount(); |
|
634 const TInt noSubviews = 0; |
|
635 |
|
636 if ( subViewCount == noSubviews ) |
|
637 { |
|
638 // The view is used as a placeholder. |
|
639 // lets not create anything there |
|
640 CleanupStack::PushL( result ); // LC semantics |
|
641 } |
|
642 else |
|
643 { |
|
644 // Create a composite and its subviews |
|
645 CVPbkCompositeContactView* compositeView = |
|
646 VPbkCompositeContactViewFactory::CreateViewLC( |
|
647 aObserver, aViewDefinition.SortPolicy(), |
|
648 aSortOrder, *iFieldTypes, const_cast<RFs&>(iFs) ); |
|
649 |
|
650 compositeView->SetViewId(aViewDefinition.Id()); |
|
651 for ( TInt i = 0; i < subViewCount; ++i ) |
|
652 { |
|
653 const CVPbkContactViewDefinition& subViewDef = |
|
654 aViewDefinition.SubViewAt(i); |
|
655 if ( aViewDefinition.SortPolicy() == EVPbkSortedContactView && |
|
656 subViewDef.SortPolicy() == EVPbkUnsortedContactView ) |
|
657 { |
|
658 // It's not possible to use unsorted subviews. |
|
659 // All subviews must be sorted so that they can be merged |
|
660 User::Leave(KErrArgument); |
|
661 } |
|
662 MVPbkContactViewBase* subView = CreateContactViewLC( |
|
663 *compositeView, subViewDef, aSortOrder ); |
|
664 if (subView) |
|
665 { |
|
666 compositeView->AddSubViewL(subView, subViewDef.Id()); |
|
667 if ( subView->Type() == EVPbkCompositeView ) |
|
668 { |
|
669 // Composite creates another composite as its |
|
670 // subview. The view can be safely casted because |
|
671 // CVPbkCompositeContactView is VPbkEng internal |
|
672 // and EVPbkCompositeView type view is always |
|
673 // derived from CVPbkCompositeContactView. |
|
674 static_cast<CVPbkCompositeContactView*>( |
|
675 subView )->ApplyInternalCompositePolicyL(); |
|
676 } |
|
677 } |
|
678 CleanupStack::Pop(); // subView |
|
679 } |
|
680 result = compositeView; |
|
681 } |
|
682 return result; |
|
683 } |
|
684 // End of File |