|
1 /* |
|
2 * Copyright (c) 2005-2006 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: CViewContact implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "viewcontact.h" |
|
21 #include "contactstore.h" |
|
22 #include "contactview.h" |
|
23 #include "contactlink.h" |
|
24 #include "fieldtypemappings.h" |
|
25 |
|
26 // Contact |
|
27 #include "contact.h" |
|
28 #include "ldapcontact.h" |
|
29 #include "ldapcontactfield.h" |
|
30 |
|
31 #include <mvpbkstorecontact.h> |
|
32 #include <tvpbkfieldversitproperty.h> |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // LDAP Store namespace |
|
36 // ----------------------------------------------------------------------------- |
|
37 namespace LDAPStore { |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // TViewContactFieldData class |
|
41 // ----------------------------------------------------------------------------- |
|
42 // TViewContactFieldData::TViewContactFieldData |
|
43 // C++ default constructor can NOT contain any code, that |
|
44 // might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TViewContactFieldData::TViewContactFieldData(const TDesC& aData) |
|
48 : iData(aData) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // TViewContactFieldData::IsEmpty |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TBool TViewContactFieldData::IsEmpty() const |
|
57 { |
|
58 return iData.Length() == 0; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // TViewContactFieldData::CopyL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void TViewContactFieldData::CopyL(const MVPbkContactFieldData& /*aFieldData*/) |
|
66 { |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // TViewContactFieldData::Text |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 TPtrC TViewContactFieldData::Text() const |
|
74 { |
|
75 return iData; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // TViewContactFieldData::SetTextL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void TViewContactFieldData::SetTextL(const TDesC& aText) |
|
83 { |
|
84 iData.Set(aText); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // TViewContactFieldData::MaxLength |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 TInt TViewContactFieldData::MaxLength() const |
|
92 { |
|
93 return iData.Length(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // TViewContactField class |
|
98 // ----------------------------------------------------------------------------- |
|
99 // TViewContactField::TViewContactField |
|
100 // C++ default constructor can NOT contain any code, that |
|
101 // might leave. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 TViewContactField::TViewContactField(CViewContact& aParentContact, |
|
105 const MVPbkFieldType& aFieldType,const TDesC& aData) |
|
106 : iParentContact(aParentContact), |
|
107 iFieldType(aFieldType), |
|
108 iFieldData(aData) |
|
109 { |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // TViewContactField::FieldData |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TViewContactFieldData& TViewContactField::FieldData() |
|
117 { |
|
118 return iFieldData; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // TViewContactField::ParentContact |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 MVPbkBaseContact& TViewContactField::ParentContact() const |
|
126 { |
|
127 return iParentContact; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // TViewContactField::MatchFieldType |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 const MVPbkFieldType* TViewContactField::MatchFieldType( |
|
135 TInt /*aMatchPriority*/ ) const |
|
136 { |
|
137 return &iFieldType; |
|
138 } |
|
139 // ----------------------------------------------------------------------------- |
|
140 // TViewContactField::MatchFieldType |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 const MVPbkFieldType* TViewContactField::BestMatchingFieldType() const |
|
144 { |
|
145 return &iFieldType; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // TViewContactField::FieldData |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 const MVPbkContactFieldData& TViewContactField::FieldData() const |
|
153 { |
|
154 return iFieldData; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // TViewContactField::IsSame |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 TBool TViewContactField::IsSame(const MVPbkBaseContactField& aOther) const |
|
162 { |
|
163 if (&aOther.ParentContact() == &ParentContact() && |
|
164 &aOther.FieldData() == &FieldData()) |
|
165 { |
|
166 return ETrue; |
|
167 } |
|
168 return EFalse; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CViewContactFieldCollection class |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CViewContactFieldCollection::CViewContactFieldCollection |
|
175 // C++ default constructor can NOT contain any code, that might leave. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 CViewContactFieldCollection::CViewContactFieldCollection( |
|
179 CViewContact& aParentContact) : |
|
180 iParentContact(aParentContact) |
|
181 { |
|
182 } |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CViewContactFieldCollection::~CViewContactFieldCollection |
|
185 // CViewContactFieldCollection Destructor |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 CViewContactFieldCollection::~CViewContactFieldCollection() |
|
189 { |
|
190 iFields.Close(); |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CViewContactFieldCollection::ResetFields |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CViewContactFieldCollection::ResetFields() |
|
198 { |
|
199 iFields.Reset(); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CViewContactFieldCollection::AppendFieldL |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CViewContactFieldCollection::AppendFieldL(TViewContactField& aNewField) |
|
207 { |
|
208 iFields.AppendL(aNewField); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CViewContactFieldCollection::ParentContact |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 MVPbkBaseContact& CViewContactFieldCollection::ParentContact() const |
|
216 { |
|
217 return iParentContact; |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CViewContactFieldCollection::FieldCount |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TInt CViewContactFieldCollection::FieldCount() const |
|
225 { |
|
226 return iFields.Count(); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CViewContactFieldCollection::FieldAt |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 const MVPbkBaseContactField& CViewContactFieldCollection::FieldAt(TInt aIndex) const |
|
234 { |
|
235 return iFields[aIndex]; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CViewContact class |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CViewContact::CViewContact |
|
242 // C++ default constructor can NOT contain any code, that might leave. |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 CViewContact::CViewContact(CContactView& aView, |
|
246 const MVPbkFieldTypeList& aSortOrder) |
|
247 : iView(aView),iFieldCollection(*this), iSortOrder(aSortOrder) |
|
248 { |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CViewContact::ConstructL |
|
253 // CViewContact constructor for performing 2nd stage construction |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CViewContact::ConstructL() |
|
257 { |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CViewContact::NewLC |
|
262 // CViewContact two-phased constructor. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 CViewContact* CViewContact::NewLC(CContactView& aView, |
|
266 const MVPbkFieldTypeList& aSortOrder) |
|
267 { |
|
268 CViewContact* self = new (ELeave)CViewContact(aView,aSortOrder); |
|
269 CleanupStack::PushL(self); |
|
270 self->ConstructL(); |
|
271 return self; |
|
272 } |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CViewContact::NewL |
|
275 // CViewContact two-phased constructor. |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 CViewContact* CViewContact::NewL(CContactView& aView, |
|
279 const MVPbkFieldTypeList& aSortOrder) |
|
280 { |
|
281 CViewContact* self = CViewContact::NewLC(aView,aSortOrder); |
|
282 CleanupStack::Pop(self); |
|
283 return self; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CViewContact::~CViewContact |
|
288 // CViewContact Destructor |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 CViewContact::~CViewContact() |
|
292 { |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CViewContact public methods |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CViewContact::ContactIndex |
|
299 // Return contact index |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TInt CViewContact::ContactIndex() const |
|
303 { |
|
304 return iContactIndex; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CViewContact::ContactView |
|
309 // Return contact view of this view contact, got it |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 CContactView& CViewContact::ContactView() const |
|
313 { |
|
314 return iView; |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CViewContact::SetContactViewContact |
|
319 // Set contact view contact |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void CViewContact::SetContactViewContact(CContact& aContact) |
|
323 { |
|
324 // Clear all fields |
|
325 iFieldCollection.ResetFields(); |
|
326 |
|
327 // Field mappings |
|
328 CFieldTypeMappings& map = iView.Store().FieldTypeMappings(); |
|
329 // Contact inside contact |
|
330 CLDAPContact& contact = aContact.LDAPContact(); |
|
331 |
|
332 // Sort order field count |
|
333 TInt count = iSortOrder.FieldTypeCount(); |
|
334 // Contact field count |
|
335 TInt field_count = contact.FieldCount(); |
|
336 |
|
337 // Find name field |
|
338 for (TInt loop = 0;loop < count;loop++) |
|
339 { |
|
340 // Field type |
|
341 const MVPbkFieldType& type = iSortOrder.FieldTypeAt(loop); |
|
342 // Contact field |
|
343 CLDAPContactField* fp = NULL; |
|
344 |
|
345 // Find match |
|
346 for (TInt next = 0; next < field_count;next++) |
|
347 { |
|
348 // LDAP Field |
|
349 fp = contact.FieldAt(next); |
|
350 // Virtual phonebook type |
|
351 const MVPbkFieldType* vpbk_type = map.Match(fp->Type()); |
|
352 if (vpbk_type && vpbk_type == &type) |
|
353 break; |
|
354 // Clear field |
|
355 fp = NULL; |
|
356 } |
|
357 |
|
358 // Found one |
|
359 if (fp) |
|
360 { |
|
361 // With data |
|
362 TViewContactField field(*this,type,fp->Data()); |
|
363 iFieldCollection.AppendFieldL(field); |
|
364 } |
|
365 else |
|
366 { |
|
367 // Empty field |
|
368 TViewContactField field(*this,type,KNullDesC); |
|
369 iFieldCollection.AppendFieldL(field); |
|
370 } |
|
371 } // End of loop over sort order fields |
|
372 iContactIndex = aContact.Index(); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CViewContact::SetFoldingViewContact |
|
377 // Set folding view contact |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CViewContact::SetFoldingViewContact(TPtrC aName) |
|
381 { |
|
382 // Clear all fields |
|
383 iFieldCollection.ResetFields(); |
|
384 |
|
385 // Field count |
|
386 TInt count = iSortOrder.FieldTypeCount(); |
|
387 // Found name |
|
388 TBool found = EFalse; |
|
389 // Find name field |
|
390 for (TInt loop = 0;loop < count;loop++) |
|
391 { |
|
392 // Field type |
|
393 const MVPbkFieldType& type = iSortOrder.FieldTypeAt(loop); |
|
394 // Properties |
|
395 TArray<TVPbkFieldVersitProperty> props = type.VersitProperties(); |
|
396 for (TInt next = 0; next < props.Count();next++) |
|
397 { |
|
398 // This property name |
|
399 if (props[next].Name() == EVPbkVersitNameN) |
|
400 { |
|
401 // Any name can hold the name |
|
402 TViewContactField field(*this,type,aName); |
|
403 iFieldCollection.AppendFieldL(field); |
|
404 found = ETrue; |
|
405 break; |
|
406 } |
|
407 } // End of loop over properties |
|
408 |
|
409 // Found one |
|
410 if (found) |
|
411 { |
|
412 break; |
|
413 } |
|
414 } // End of loop over fields |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // MVPbkBaseContact implementation |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CViewContact::Fields |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 const MVPbkBaseContactFieldCollection& CViewContact::Fields() const |
|
424 { |
|
425 return iFieldCollection; |
|
426 } |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CViewContact::IsSame |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 TBool CViewContact::IsSame(const MVPbkStoreContact& aContact) const |
|
433 { |
|
434 // From same store |
|
435 if (&iView.ContactStore() == &aContact.ContactStore()) |
|
436 { |
|
437 // Store folding view |
|
438 if (iView.Type() == EVPbkFoldingView) |
|
439 { |
|
440 return ETrue; |
|
441 } |
|
442 else |
|
443 { |
|
444 // Cast to contact |
|
445 const CContact& contact = static_cast<const CContact&>(aContact); |
|
446 return (iContactIndex == contact.Index()); |
|
447 } |
|
448 } |
|
449 return EFalse; |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CViewContact::IsSame |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 TBool CViewContact::IsSame(const MVPbkViewContact& aOtherContact) const |
|
457 { |
|
458 return aOtherContact.IsSame(*this,&iView.ContactStore()); |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // CViewContact::CreateLinkLC |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 MVPbkContactLink* CViewContact::CreateLinkLC() const |
|
466 { |
|
467 return CContactLink::NewLC(iView.Store(),iContactIndex); |
|
468 } |
|
469 |
|
470 // ----------------------------------------------------------------------------- |
|
471 // CViewContact::DeleteL |
|
472 // ----------------------------------------------------------------------------- |
|
473 // |
|
474 void CViewContact::DeleteL(MVPbkContactObserver& /* aObserver */) const |
|
475 { |
|
476 // Cannot delete, read only |
|
477 User::Leave(KErrAccessDenied); |
|
478 } |
|
479 |
|
480 // ----------------------------------------------------------------------------- |
|
481 // CViewContact::MatchContactStore |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 TBool CViewContact::MatchContactStore(const TDesC& aContactStoreUri) const |
|
485 { |
|
486 return iView.MatchContactStore(aContactStoreUri); |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CViewContact::MatchContactStoreDomain |
|
491 // ----------------------------------------------------------------------------- |
|
492 // |
|
493 TBool CViewContact::MatchContactStoreDomain(const TDesC& aContactStoreDomain) const |
|
494 { |
|
495 return iView.MatchContactStoreDomain(aContactStoreDomain); |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CViewContact::CreateBookmarkLC |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 MVPbkContactBookmark* CViewContact::CreateBookmarkLC() const |
|
503 { |
|
504 return iView.CreateBookmarkLC(iContactIndex); |
|
505 } |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // MVPbkViewContact implementation |
|
509 // ----------------------------------------------------------------------------- |
|
510 // CViewContact::ParentView |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 MVPbkContactViewBase& CViewContact::ParentView() const |
|
514 { |
|
515 return iView; |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CViewContact::Read |
|
520 // ----------------------------------------------------------------------------- |
|
521 // |
|
522 void CViewContact::ReadL(MVPbkContactObserver& /* aObserver */) const |
|
523 { |
|
524 // No implementation required - never called |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CViewContact::ReadAndLockL |
|
529 // ----------------------------------------------------------------------------- |
|
530 // |
|
531 void CViewContact::ReadAndLockL(MVPbkContactObserver& /* aObserver */) const |
|
532 { |
|
533 // Cannot lock, read only |
|
534 User::Leave(KErrAccessDenied); |
|
535 } |
|
536 |
|
537 // ----------------------------------------------------------------------------- |
|
538 // CViewContact::Expandable |
|
539 // ----------------------------------------------------------------------------- |
|
540 // |
|
541 MVPbkExpandable* CViewContact::Expandable() const |
|
542 { |
|
543 // Folding view is expandale |
|
544 if (iView.Type() == EVPbkFoldingView) |
|
545 { |
|
546 return const_cast<CViewContact*>(this); |
|
547 } |
|
548 return NULL; |
|
549 } |
|
550 |
|
551 // ----------------------------------------------------------------------------- |
|
552 // CViewContact::IsSame |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 TBool CViewContact::IsSame( |
|
556 const MVPbkViewContact& aOtherContact, |
|
557 const MVPbkContactStore* aContactStore |
|
558 ) const |
|
559 { |
|
560 // From same store |
|
561 if (&iView.ContactStore() == aContactStore) |
|
562 { |
|
563 // Store folding view |
|
564 if (iView.Type() == EVPbkFoldingView) |
|
565 { |
|
566 return ETrue; |
|
567 } |
|
568 else |
|
569 { |
|
570 // Check contact |
|
571 return IsSame(aOtherContact); |
|
572 } |
|
573 } |
|
574 return EFalse; |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CViewContact::IsSame |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 TBool CViewContact::IsSame( |
|
582 const MVPbkStoreContact& aOtherContact, |
|
583 const MVPbkContactStore* aContactStore |
|
584 ) const |
|
585 { |
|
586 // From same store |
|
587 if (&iView.ContactStore() == aContactStore) |
|
588 { |
|
589 // Store folding view |
|
590 if (iView.Type() == EVPbkFoldingView) |
|
591 { |
|
592 return ETrue; |
|
593 } |
|
594 else |
|
595 { |
|
596 // Check contact |
|
597 return IsSame(aOtherContact); |
|
598 } |
|
599 } |
|
600 return EFalse; |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CViewContact::ExpandLC |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 MVPbkContactViewBase* CViewContact::ExpandLC( |
|
608 MVPbkContactViewObserver& aObserver, |
|
609 const MVPbkFieldTypeList& aSortOrder |
|
610 ) const |
|
611 { |
|
612 return CContactView::NewLC(aObserver,iView.Store(),aSortOrder,EVPbkContactsView); |
|
613 } |
|
614 |
|
615 } // End of namespace LDAPStore |
|
616 // ----------------------------------------------------------------------------- |
|
617 // End of File |
|
618 // ----------------------------------------------------------------------------- |