|
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: A phonebook2 presentation level contact field |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2PresentationContactField.h" |
|
22 #include "CPbk2PresentationContactFieldTextData.h" |
|
23 |
|
24 |
|
25 #include <MVPbkContactStore.h> |
|
26 #include <MVPbkContactStoreProperties.h> |
|
27 #include <MVPbkContactFieldTextData.h> |
|
28 #include <MVPbkContactFieldBinaryData.h> |
|
29 #include <MPbk2FieldProperty.h> |
|
30 #include <TVPbkFieldVersitProperty.h> |
|
31 #include <MVPbkContactFieldUriData.h> |
|
32 #include <MVPbkFieldType.h> |
|
33 |
|
34 namespace{ |
|
35 |
|
36 const TInt KStaticLength = 35; |
|
37 |
|
38 } // namespace |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS ============================ |
|
41 |
|
42 // -------------------------------------------------------------------------- |
|
43 // CPbk2PresentationContactField::CPbk2PresentationContactField |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CPbk2PresentationContactField::CPbk2PresentationContactField( |
|
49 const MPbk2FieldProperty& aFieldProperty, |
|
50 MVPbkStoreContact& aParentContact) |
|
51 : iFieldProperty(aFieldProperty), |
|
52 iParentContact(aParentContact), |
|
53 iDynamicVisibility( ETrue ) |
|
54 { |
|
55 } |
|
56 |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CPbk2PresentationContactField::~CPbk2PresentationContactField |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CPbk2PresentationContactField::~CPbk2PresentationContactField() |
|
63 { |
|
64 delete iData; |
|
65 delete iStoreField; |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CPbk2PresentationContactField::NewL |
|
70 // Two-phased constructor. |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C CPbk2PresentationContactField* CPbk2PresentationContactField::NewL |
|
74 (const MPbk2FieldProperty& aFieldProperty, |
|
75 const MVPbkStoreContactField& aStoreField, |
|
76 MVPbkStoreContact& aParentContact) |
|
77 { |
|
78 CPbk2PresentationContactField* self = |
|
79 NewLC(aFieldProperty, aStoreField, aParentContact); |
|
80 CleanupStack::Pop(self); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // CPbk2PresentationContactField::NewLC |
|
86 // Two-phased constructor. |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CPbk2PresentationContactField* CPbk2PresentationContactField::NewLC |
|
90 (const MPbk2FieldProperty& aFieldProperty, |
|
91 const MVPbkStoreContactField& aStoreField, |
|
92 MVPbkStoreContact& aParentContact) |
|
93 { |
|
94 CPbk2PresentationContactField* self = |
|
95 new(ELeave) CPbk2PresentationContactField(aFieldProperty, |
|
96 aParentContact); |
|
97 CleanupStack::PushL(self); |
|
98 self->ConstructL(aStoreField); |
|
99 return self; |
|
100 } |
|
101 |
|
102 // -------------------------------------------------------------------------- |
|
103 // CPbk2PresentationContactField::ConstructL |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 void CPbk2PresentationContactField::ConstructL |
|
107 (const MVPbkStoreContactField& aStoreField) |
|
108 { |
|
109 // Make a permanent copy from the field reference |
|
110 iStoreField = aStoreField.CloneLC(); |
|
111 CleanupStack::Pop(); // iStoreField |
|
112 |
|
113 if ( FieldData().DataType() == EVPbkFieldStorageTypeText ) |
|
114 { |
|
115 MVPbkContactFieldTextData& textData = |
|
116 MVPbkContactFieldTextData::Cast( iStoreField->FieldData() ); |
|
117 iData = |
|
118 CPbk2PresentationContactFieldTextData::NewL( |
|
119 textData, iFieldProperty, MaxDataLength() ); |
|
120 } |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CPbk2PresentationContactField::MaxDataLength |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C TInt CPbk2PresentationContactField::MaxDataLength() const |
|
128 { |
|
129 TInt maxLength = KVPbkUnlimitedFieldLength; |
|
130 TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType(); |
|
131 switch (dataType) |
|
132 { |
|
133 case EVPbkFieldStorageTypeText: |
|
134 { |
|
135 const MVPbkContactFieldTextData& textData = |
|
136 MVPbkContactFieldTextData::Cast(iStoreField->FieldData()); |
|
137 maxLength = textData.MaxLength(); |
|
138 break; |
|
139 } |
|
140 case EVPbkFieldStorageTypeBinary: |
|
141 { |
|
142 const MVPbkContactFieldBinaryData& binaryData = |
|
143 MVPbkContactFieldBinaryData::Cast(iStoreField->FieldData()); |
|
144 maxLength = binaryData.MaxLength(); |
|
145 break; |
|
146 } |
|
147 case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH |
|
148 default: |
|
149 { |
|
150 // Do nothing |
|
151 break; |
|
152 } |
|
153 } |
|
154 |
|
155 TInt staticMaxLength = iFieldProperty.MaxLength(); |
|
156 if (maxLength == KVPbkUnlimitedFieldLength) |
|
157 { |
|
158 maxLength = staticMaxLength; |
|
159 } |
|
160 else |
|
161 { |
|
162 maxLength = Min(staticMaxLength, maxLength); |
|
163 } |
|
164 return maxLength; |
|
165 } |
|
166 |
|
167 // -------------------------------------------------------------------------- |
|
168 // CPbk2PresentationContactField::IsEmpty |
|
169 // -------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C TBool CPbk2PresentationContactField::IsEmpty() const |
|
172 { |
|
173 return iStoreField->FieldData().IsEmpty(); |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CPbk2PresentationContactField::IsEditable |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TBool CPbk2PresentationContactField::IsEditable() const |
|
181 { |
|
182 return !(iFieldProperty.Flags() & KPbk2FieldFlagDisableEdit); |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CPbk2PresentationContactField::IsRemovable |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C TBool CPbk2PresentationContactField::IsRemovable() const |
|
190 { |
|
191 return !(iFieldProperty.Flags() & KPbk2FieldFlagCanNotBeRemoved); |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // CPbk2PresentationContactField::IsVisibleInDetailsView |
|
196 // -------------------------------------------------------------------------- |
|
197 // |
|
198 EXPORT_C TBool CPbk2PresentationContactField::IsVisibleInDetailsView() const |
|
199 { |
|
200 return !(iFieldProperty.Flags() & KPbk2FieldFlagHideFromDetailsView); |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPbk2PresentationContactField::SetDynamicVisibility |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C void CPbk2PresentationContactField::SetDynamicVisibility( |
|
208 TBool aVisibility ) |
|
209 { |
|
210 iDynamicVisibility = aVisibility; |
|
211 } |
|
212 |
|
213 // -------------------------------------------------------------------------- |
|
214 // CPbk2PresentationContactField::SetDynamicVisibility |
|
215 // -------------------------------------------------------------------------- |
|
216 // |
|
217 EXPORT_C TBool CPbk2PresentationContactField::DynamicVisibility() |
|
218 { |
|
219 return iDynamicVisibility; |
|
220 } |
|
221 |
|
222 // -------------------------------------------------------------------------- |
|
223 // CPbk2PresentationContactField::ParentObject |
|
224 // -------------------------------------------------------------------------- |
|
225 // |
|
226 MVPbkObjectHierarchy& CPbk2PresentationContactField::ParentObject() const |
|
227 { |
|
228 return iStoreField->ParentObject(); |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CPbk2PresentationContactField::ParentContact |
|
233 // -------------------------------------------------------------------------- |
|
234 // |
|
235 MVPbkBaseContact& CPbk2PresentationContactField::ParentContact() const |
|
236 { |
|
237 return iStoreField->ParentContact(); |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CPbk2PresentationContactField::ParentContact |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 const MVPbkFieldType* CPbk2PresentationContactField::MatchFieldType( |
|
245 TInt aMatchPriority) const |
|
246 { |
|
247 return iStoreField->MatchFieldType(aMatchPriority); |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // CPbk2PresentationContactField::BestMatchingFieldType |
|
252 // -------------------------------------------------------------------------- |
|
253 // |
|
254 const MVPbkFieldType* |
|
255 CPbk2PresentationContactField::BestMatchingFieldType() const |
|
256 { |
|
257 return iStoreField->BestMatchingFieldType(); |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CPbk2PresentationContactField::FieldData |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 const MVPbkContactFieldData& CPbk2PresentationContactField::FieldData() const |
|
265 { |
|
266 |
|
267 TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType(); |
|
268 switch (dataType) |
|
269 { |
|
270 case EVPbkFieldStorageTypeText: |
|
271 { |
|
272 if ( iData ) |
|
273 { |
|
274 return *iData; |
|
275 } |
|
276 else |
|
277 { |
|
278 return iStoreField->FieldData(); |
|
279 } |
|
280 } |
|
281 case EVPbkFieldStorageTypeBinary: // FALLTHROUGH |
|
282 case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH |
|
283 default: |
|
284 { |
|
285 return iStoreField->FieldData(); |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CPbk2PresentationContactField::IsSame |
|
292 // -------------------------------------------------------------------------- |
|
293 // |
|
294 TBool CPbk2PresentationContactField::IsSame( |
|
295 const MVPbkBaseContactField& aOther) const |
|
296 { |
|
297 const CPbk2PresentationContactField* field = |
|
298 dynamic_cast<const CPbk2PresentationContactField*>(&aOther); |
|
299 if (field) |
|
300 { |
|
301 return iStoreField->IsSame(*field->iStoreField); |
|
302 } |
|
303 return iStoreField->IsSame(aOther); |
|
304 } |
|
305 |
|
306 // -------------------------------------------------------------------------- |
|
307 // CPbk2PresentationContactField::SupportsLabel |
|
308 // -------------------------------------------------------------------------- |
|
309 // |
|
310 TBool CPbk2PresentationContactField::SupportsLabel() const |
|
311 { |
|
312 TVPbkFieldVersitProperty prop; |
|
313 prop.SetName(EVPbkVersitNameIMPP); |
|
314 if (iStoreField->BestMatchingFieldType()->Matches(prop, 0)) |
|
315 { |
|
316 return EFalse; |
|
317 } |
|
318 return iStoreField->SupportsLabel(); |
|
319 } |
|
320 |
|
321 // -------------------------------------------------------------------------- |
|
322 // CPbk2PresentationContactField::FieldLabel |
|
323 // -------------------------------------------------------------------------- |
|
324 // |
|
325 TPtrC CPbk2PresentationContactField::FieldLabel() const |
|
326 { |
|
327 if (iStoreField->ContactStore().StoreProperties().SupportsFieldLabels() |
|
328 && iStoreField->FieldLabel() != KNullDesC) |
|
329 { |
|
330 return iStoreField->FieldLabel(); |
|
331 } |
|
332 else if (iFieldProperty.DefaultLabel() == KNullDesC) |
|
333 { |
|
334 TVPbkFieldVersitProperty prop; |
|
335 prop.SetName(EVPbkVersitNameIMPP); |
|
336 if (iStoreField->BestMatchingFieldType()->Matches(prop, 0)) |
|
337 { |
|
338 return (MVPbkContactFieldUriData::Cast(iStoreField->FieldData())). |
|
339 Scheme(); |
|
340 } |
|
341 } |
|
342 return iFieldProperty.DefaultLabel(); |
|
343 } |
|
344 |
|
345 // -------------------------------------------------------------------------- |
|
346 // CPbk2PresentationContactField::SetFieldLabelL |
|
347 // -------------------------------------------------------------------------- |
|
348 // |
|
349 void CPbk2PresentationContactField::SetFieldLabelL(const TDesC& aText) |
|
350 { |
|
351 iStoreField->SetFieldLabelL(aText); |
|
352 } |
|
353 |
|
354 // -------------------------------------------------------------------------- |
|
355 // CPbk2PresentationContactField::MaxLabelLength |
|
356 // -------------------------------------------------------------------------- |
|
357 // |
|
358 TInt CPbk2PresentationContactField::MaxLabelLength() const |
|
359 { |
|
360 TInt storeLength = iStoreField->MaxLabelLength(); |
|
361 if (storeLength == KVPbkUnlimitedLabelLength) |
|
362 { |
|
363 return KStaticLength; |
|
364 } |
|
365 else |
|
366 { |
|
367 return Min(KStaticLength, storeLength); |
|
368 } |
|
369 } |
|
370 |
|
371 // -------------------------------------------------------------------------- |
|
372 // CPbk2PresentationContactField::FieldData |
|
373 // -------------------------------------------------------------------------- |
|
374 // |
|
375 MVPbkContactFieldData& CPbk2PresentationContactField::FieldData() |
|
376 { |
|
377 TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType(); |
|
378 switch (dataType) |
|
379 { |
|
380 case EVPbkFieldStorageTypeText: |
|
381 { |
|
382 if ( iData ) |
|
383 { |
|
384 return *iData; |
|
385 } |
|
386 else |
|
387 { |
|
388 return iStoreField->FieldData(); |
|
389 } |
|
390 } |
|
391 case EVPbkFieldStorageTypeBinary: // FALLTHROUGH |
|
392 case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH |
|
393 default: |
|
394 { |
|
395 return iStoreField->FieldData(); |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 // -------------------------------------------------------------------------- |
|
401 // CPbk2PresentationContactField::CloneLC |
|
402 // -------------------------------------------------------------------------- |
|
403 // |
|
404 MVPbkStoreContactField* CPbk2PresentationContactField::CloneLC() const |
|
405 { |
|
406 CPbk2PresentationContactField* copy = CPbk2PresentationContactField::NewLC |
|
407 (iFieldProperty, *iStoreField,iParentContact); |
|
408 return copy; |
|
409 } |
|
410 |
|
411 // -------------------------------------------------------------------------- |
|
412 // CPbk2PresentationContactField::CreateLinkLC |
|
413 // -------------------------------------------------------------------------- |
|
414 // |
|
415 MVPbkContactLink* CPbk2PresentationContactField::CreateLinkLC() const |
|
416 { |
|
417 return iStoreField->CreateLinkLC(); |
|
418 } |
|
419 |
|
420 // End of File |