|
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: Contacts Model store view contact implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CViewContact.h" |
|
21 #include <cntviewbase.h> |
|
22 #include <cntitem.h> |
|
23 |
|
24 #include <VPbkError.h> |
|
25 #include <MVPbkContactObserver.h> |
|
26 #include <MVPbkFieldType.h> |
|
27 |
|
28 #include "CContact.h" |
|
29 #include "CContactView.h" |
|
30 #include "CGroupMembersView.h" |
|
31 #include "CContactStore.h" |
|
32 #include "CContactLink.h" |
|
33 #include "CFieldTypeMap.h" |
|
34 |
|
35 namespace VPbkCntModel { |
|
36 |
|
37 // -------------------------------------------------------------------------- |
|
38 // TViewContactTextFieldData::TViewContactTextFieldData |
|
39 // -------------------------------------------------------------------------- |
|
40 // |
|
41 TViewContactTextFieldData::TViewContactTextFieldData(const TDesC& aTextData) : |
|
42 iTextData(aTextData) |
|
43 { |
|
44 } |
|
45 |
|
46 // -------------------------------------------------------------------------- |
|
47 // TViewContactTextFieldData::SetTextData |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 inline void TViewContactTextFieldData::SetTextData(const TDesC& aTextData) |
|
51 { |
|
52 iTextData.Set(aTextData); |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------------- |
|
56 // TViewContactTextFieldData::IsEmpty |
|
57 // -------------------------------------------------------------------------- |
|
58 // |
|
59 TBool TViewContactTextFieldData::IsEmpty() const |
|
60 { |
|
61 return iTextData.Length() == 0; |
|
62 } |
|
63 |
|
64 // -------------------------------------------------------------------------- |
|
65 // TViewContactTextFieldData::CopyL |
|
66 // -------------------------------------------------------------------------- |
|
67 // |
|
68 void TViewContactTextFieldData::CopyL(const MVPbkContactFieldData& /*aFieldData*/) |
|
69 { |
|
70 /// Do nothing |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // TViewContactTextFieldData::Text |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 TPtrC TViewContactTextFieldData::Text() const |
|
78 { |
|
79 return iTextData; |
|
80 } |
|
81 |
|
82 // -------------------------------------------------------------------------- |
|
83 // TViewContactTextFieldData::SetTextL |
|
84 // -------------------------------------------------------------------------- |
|
85 // |
|
86 void TViewContactTextFieldData::SetTextL(const TDesC& /* aText */) |
|
87 { |
|
88 /// Do nothing |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------- |
|
92 // TViewContactTextFieldData::MaxLength |
|
93 // -------------------------------------------------------------------------- |
|
94 // |
|
95 TInt TViewContactTextFieldData::MaxLength() const |
|
96 { |
|
97 return KVPbkUnlimitedFieldLength; |
|
98 } |
|
99 |
|
100 // -------------------------------------------------------------------------- |
|
101 // TViewContactField::TViewContactField |
|
102 // -------------------------------------------------------------------------- |
|
103 // |
|
104 TViewContactField::TViewContactField( CViewContact& aParentContact, |
|
105 const TDesC& aFieldData, const MVPbkFieldType& aFieldType, |
|
106 TInt aFieldIndex ) |
|
107 : iParentContact(aParentContact), |
|
108 iFieldData(aFieldData), |
|
109 iFieldType(&aFieldType), |
|
110 iFieldIndex(aFieldIndex) |
|
111 { |
|
112 } |
|
113 |
|
114 // -------------------------------------------------------------------------- |
|
115 // TViewContactField::TViewContactField |
|
116 // -------------------------------------------------------------------------- |
|
117 // |
|
118 inline void TViewContactField::SetFieldData(const TDesC& aFieldData) |
|
119 { |
|
120 iFieldData.SetTextData(aFieldData); |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // TViewContactField::ParentContact |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 MVPbkBaseContact& TViewContactField::ParentContact() const |
|
128 { |
|
129 return iParentContact; |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // TViewContactField::MatchFieldType |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 const MVPbkFieldType* TViewContactField::MatchFieldType(TInt /* aMatchPriority */) const |
|
137 { |
|
138 return iFieldType; |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // TViewContactField::BestMatchingFieldType |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 const MVPbkFieldType* TViewContactField::BestMatchingFieldType() const |
|
146 { |
|
147 return iFieldType; |
|
148 } |
|
149 |
|
150 // -------------------------------------------------------------------------- |
|
151 // TViewContactField::FieldData |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 const MVPbkContactFieldData& TViewContactField::FieldData() const |
|
155 { |
|
156 return iFieldData; |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // TViewContactField::IsSame |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 TBool TViewContactField::IsSame( const MVPbkBaseContactField& aOther ) const |
|
164 { |
|
165 // View contact fields don't have unique |
|
166 // id. Fields are same if the parent view contact is same instance |
|
167 // and field indexes are the same |
|
168 if (&aOther.ParentContact() == &iParentContact) |
|
169 { |
|
170 return iFieldIndex == |
|
171 static_cast<const TViewContactField&>( aOther ).iFieldIndex; |
|
172 } |
|
173 |
|
174 return EFalse; |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CViewContactFieldCollection::CViewContactFieldCollection |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 CViewContactFieldCollection::CViewContactFieldCollection |
|
182 (CViewContact& aParentContact) : |
|
183 iParentContact(aParentContact) |
|
184 { |
|
185 } |
|
186 |
|
187 // -------------------------------------------------------------------------- |
|
188 // CViewContactFieldCollection::CViewContactFieldCollection |
|
189 // -------------------------------------------------------------------------- |
|
190 // |
|
191 CViewContactFieldCollection::~CViewContactFieldCollection() |
|
192 { |
|
193 iFields.Close(); |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CViewContactFieldCollection::SetFieldsData |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 void CViewContactFieldCollection::SetFieldsData( |
|
201 const ::CViewContact& aViewContact ) |
|
202 { |
|
203 const TInt count = aViewContact.FieldCount(); |
|
204 for (TInt i = 0; i < count; ++i) |
|
205 { |
|
206 iFields[i].SetFieldData(aViewContact.Field(i)); |
|
207 } |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CViewContactFieldCollection::SetTypeListL |
|
212 // -------------------------------------------------------------------------- |
|
213 // |
|
214 void CViewContactFieldCollection::SetTypeListL( |
|
215 const MVPbkFieldTypeList& aFieldTypes ) |
|
216 { |
|
217 iFields.Reset(); |
|
218 const TInt count = aFieldTypes.FieldTypeCount(); |
|
219 for (TInt i = 0; i < count; ++i) |
|
220 { |
|
221 User::LeaveIfError(iFields.Append(TViewContactField(iParentContact, |
|
222 KNullDesC, aFieldTypes.FieldTypeAt(i), iFields.Count() ))); |
|
223 } |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------- |
|
227 // CViewContactFieldCollection::ParentContact |
|
228 // -------------------------------------------------------------------------- |
|
229 // |
|
230 MVPbkBaseContact& CViewContactFieldCollection::ParentContact() const |
|
231 { |
|
232 return iParentContact; |
|
233 } |
|
234 |
|
235 // -------------------------------------------------------------------------- |
|
236 // CViewContactFieldCollection::FieldCount |
|
237 // -------------------------------------------------------------------------- |
|
238 // |
|
239 TInt CViewContactFieldCollection::FieldCount() const |
|
240 { |
|
241 return iFields.Count(); |
|
242 } |
|
243 |
|
244 // -------------------------------------------------------------------------- |
|
245 // CViewContactFieldCollection::FieldAt |
|
246 // -------------------------------------------------------------------------- |
|
247 // |
|
248 const MVPbkBaseContactField& CViewContactFieldCollection::FieldAt(TInt aIndex) const |
|
249 { |
|
250 return iFields[aIndex]; |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CViewContact::CViewContact |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 #pragma warning(push) |
|
258 #pragma warning(disable : 4355) // this used in base member initializer list |
|
259 CViewContact::CViewContact(CViewBase& aParentView) : |
|
260 iParentView(aParentView), |
|
261 iViewContact(NULL), |
|
262 iFieldCollection(*this) |
|
263 { |
|
264 } |
|
265 #pragma warning(pop) |
|
266 |
|
267 // -------------------------------------------------------------------------- |
|
268 // CViewContact::NewL |
|
269 // -------------------------------------------------------------------------- |
|
270 // |
|
271 CViewContact* CViewContact::NewL |
|
272 (CViewBase& aParentView, const MVPbkFieldTypeList& aFieldTypes) |
|
273 { |
|
274 CViewContact* self = new(ELeave) CViewContact(aParentView); |
|
275 CleanupStack::PushL(self); |
|
276 self->SetTypeListL(aFieldTypes); |
|
277 CleanupStack::Pop(self); |
|
278 return self; |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CViewContact::SetTypeListL |
|
283 // -------------------------------------------------------------------------- |
|
284 // |
|
285 void CViewContact::SetTypeListL(const MVPbkFieldTypeList& aFieldTypes) |
|
286 { |
|
287 iFieldCollection.SetTypeListL(aFieldTypes); |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CViewContact::SetViewContact |
|
292 // -------------------------------------------------------------------------- |
|
293 // |
|
294 void CViewContact::SetViewContact(const ::CViewContact& aViewContact) |
|
295 { |
|
296 iViewContact = &aViewContact; |
|
297 iFieldCollection.SetFieldsData(aViewContact); |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CViewContact::View |
|
302 // -------------------------------------------------------------------------- |
|
303 // |
|
304 CViewBase& CViewContact::View() const |
|
305 { |
|
306 return iParentView; |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CViewContact::Id |
|
311 // -------------------------------------------------------------------------- |
|
312 // |
|
313 TContactItemId CViewContact::Id() const |
|
314 { |
|
315 return iViewContact->Id(); |
|
316 } |
|
317 |
|
318 // -------------------------------------------------------------------------- |
|
319 // CViewContact::NativeContact |
|
320 // -------------------------------------------------------------------------- |
|
321 // |
|
322 const ::CViewContact* CViewContact::NativeContact() const |
|
323 { |
|
324 return iViewContact; |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------- |
|
328 // CViewContact::Fields |
|
329 // -------------------------------------------------------------------------- |
|
330 // |
|
331 const MVPbkBaseContactFieldCollection& CViewContact::Fields() const |
|
332 { |
|
333 return iFieldCollection; |
|
334 } |
|
335 |
|
336 // -------------------------------------------------------------------------- |
|
337 // CViewContact::IsSame |
|
338 // -------------------------------------------------------------------------- |
|
339 // |
|
340 TBool CViewContact::IsSame(const MVPbkStoreContact& aOtherContact) const |
|
341 { |
|
342 if (iViewContact && &iParentView.ContactStore() |
|
343 == &aOtherContact.ContactStore()) |
|
344 { |
|
345 return (iViewContact->Id() == |
|
346 static_cast<const CContact&>(aOtherContact). |
|
347 NativeContact()->Id()); |
|
348 } |
|
349 return EFalse; |
|
350 } |
|
351 |
|
352 // -------------------------------------------------------------------------- |
|
353 // CViewContact::IsSame |
|
354 // -------------------------------------------------------------------------- |
|
355 // |
|
356 TBool CViewContact::IsSame(const MVPbkViewContact& aOtherContact) const |
|
357 { |
|
358 return aOtherContact.IsSame(*this, &iParentView.ContactStore()); |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CViewContact::CreateLinkLC |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 MVPbkContactLink* CViewContact::CreateLinkLC() const |
|
366 { |
|
367 return iParentView.Store().CreateLinkLC(iViewContact->Id()); |
|
368 } |
|
369 |
|
370 // -------------------------------------------------------------------------- |
|
371 // CViewContact::ReadL |
|
372 // -------------------------------------------------------------------------- |
|
373 // |
|
374 void CViewContact::ReadL(MVPbkContactObserver& aObserver) const |
|
375 { |
|
376 iParentView.Store().ReadContactL(iViewContact->Id(), aObserver); |
|
377 } |
|
378 |
|
379 // -------------------------------------------------------------------------- |
|
380 // CViewContact::ReadAndLockL |
|
381 // -------------------------------------------------------------------------- |
|
382 // |
|
383 void CViewContact::ReadAndLockL(MVPbkContactObserver& aObserver) const |
|
384 { |
|
385 iParentView.Store().ReadAndLockContactL(iViewContact->Id(), aObserver); |
|
386 } |
|
387 |
|
388 // -------------------------------------------------------------------------- |
|
389 // CViewContact::Expandable |
|
390 // -------------------------------------------------------------------------- |
|
391 // |
|
392 MVPbkExpandable* CViewContact::Expandable() const |
|
393 { |
|
394 MVPbkExpandable* result = NULL; |
|
395 |
|
396 if (iViewContact->ContactType() == ::CViewContact::EGroup) |
|
397 { |
|
398 result = const_cast<CViewContact*>(this); |
|
399 } |
|
400 |
|
401 return result; |
|
402 } |
|
403 |
|
404 // -------------------------------------------------------------------------- |
|
405 // CViewContact::DeleteL |
|
406 // -------------------------------------------------------------------------- |
|
407 // |
|
408 void CViewContact::DeleteL(MVPbkContactObserver& aObserver) const |
|
409 { |
|
410 iParentView.Store().DeleteContactL(iViewContact->Id(), aObserver); |
|
411 } |
|
412 |
|
413 // -------------------------------------------------------------------------- |
|
414 // CViewContact::MatchContactStore |
|
415 // -------------------------------------------------------------------------- |
|
416 // |
|
417 TBool CViewContact::MatchContactStore(const TDesC& aContactStoreUri) const |
|
418 { |
|
419 return iParentView.MatchContactStore(aContactStoreUri); |
|
420 } |
|
421 |
|
422 // -------------------------------------------------------------------------- |
|
423 // CViewContact::MatchContactStoreDomain |
|
424 // -------------------------------------------------------------------------- |
|
425 // |
|
426 TBool CViewContact::MatchContactStoreDomain |
|
427 (const TDesC& aContactStoreDomain) const |
|
428 { |
|
429 return iParentView.MatchContactStoreDomain(aContactStoreDomain); |
|
430 } |
|
431 |
|
432 // -------------------------------------------------------------------------- |
|
433 // CViewContact::CreateBookmarkLC |
|
434 // -------------------------------------------------------------------------- |
|
435 // |
|
436 MVPbkContactBookmark* CViewContact::CreateBookmarkLC() const |
|
437 { |
|
438 return iParentView.Store().CreateBookmarkLC(iViewContact->Id()); |
|
439 } |
|
440 |
|
441 // -------------------------------------------------------------------------- |
|
442 // CViewContact::ParentView |
|
443 // -------------------------------------------------------------------------- |
|
444 // |
|
445 MVPbkContactViewBase& CViewContact::ParentView() const |
|
446 { |
|
447 return iParentView; |
|
448 } |
|
449 |
|
450 // -------------------------------------------------------------------------- |
|
451 // CViewContact::IsSame |
|
452 // -------------------------------------------------------------------------- |
|
453 // |
|
454 TBool CViewContact::IsSame( |
|
455 const MVPbkViewContact& aOtherContact, |
|
456 const MVPbkContactStore* aContactStore) const |
|
457 { |
|
458 if (iViewContact && &iParentView.ContactStore() == aContactStore) |
|
459 { |
|
460 return (iViewContact->Id() == |
|
461 static_cast<const CViewContact&>(aOtherContact).Id()); |
|
462 } |
|
463 return EFalse; |
|
464 } |
|
465 |
|
466 // -------------------------------------------------------------------------- |
|
467 // CViewContact::IsSame |
|
468 // -------------------------------------------------------------------------- |
|
469 // |
|
470 TBool CViewContact::IsSame( |
|
471 const MVPbkStoreContact& aOtherContact, |
|
472 const MVPbkContactStore* aContactStore) const |
|
473 { |
|
474 if (iViewContact && &iParentView.ContactStore() == aContactStore) |
|
475 { |
|
476 return (iViewContact->Id() == |
|
477 static_cast<const CContact&>(aOtherContact). |
|
478 NativeContact()->Id()); |
|
479 } |
|
480 return EFalse; |
|
481 } |
|
482 |
|
483 // -------------------------------------------------------------------------- |
|
484 // CViewContact::ExpandLC |
|
485 // -------------------------------------------------------------------------- |
|
486 // |
|
487 MVPbkContactViewBase* CViewContact::ExpandLC( |
|
488 MVPbkContactViewObserver& aObserver, |
|
489 const MVPbkFieldTypeList& aSortOrder) const |
|
490 { |
|
491 return CGroupMembersView::NewLC(iParentView.Store(), |
|
492 iViewContact->Id(), aObserver, aSortOrder); |
|
493 } |
|
494 |
|
495 // -------------------------------------------------------------------------- |
|
496 // CViewContact::BaseContactExtension |
|
497 // -------------------------------------------------------------------------- |
|
498 // |
|
499 TAny* CViewContact::BaseContactExtension( TUid aExtensionUid ) |
|
500 { |
|
501 if( aExtensionUid == KVPbkBaseContactExtension2Uid ) |
|
502 return static_cast<MVPbkBaseContact2*>( this ); |
|
503 return NULL; |
|
504 } |
|
505 |
|
506 // -------------------------------------------------------------------------- |
|
507 // CViewContact::IsOwnContact |
|
508 // -------------------------------------------------------------------------- |
|
509 // |
|
510 TBool CViewContact::IsOwnContact( TInt& aError ) const |
|
511 { |
|
512 aError = KErrNone; |
|
513 return ( iViewContact->ContactTypeUid() == KUidContactOwnCard ); |
|
514 } |
|
515 |
|
516 } // namespace VPbkCntModel |
|
517 |
|
518 // End of File |