|
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 field list box model. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2FieldListBoxModel.h" |
|
22 #include <StringLoader.h> |
|
23 |
|
24 // Phonebook 2 |
|
25 #include "MPbk2ClipListBoxText.h" |
|
26 #include "MPbk2FieldAnalyzer.h" |
|
27 #include "CPbk2FieldFormatter.h" |
|
28 #include "MPbk2ContactFieldDynamicProperties.h" |
|
29 #include "CPbk2ContactFieldDynamicProperties.h" |
|
30 #include <CPbk2IconArray.h> |
|
31 #include <Pbk2PresentationUtils.h> |
|
32 #include <CPbk2PresentationContactField.h> |
|
33 #include <CPbk2PresentationContactFieldCollection.h> |
|
34 #include <MPbk2FieldPropertyArray.h> |
|
35 #include <MPbk2FieldProperty.h> |
|
36 #include <TPbk2StoreContactAnalyzer.h> |
|
37 #include <Pbk2UIControls.rsg> |
|
38 #include "Pbk2AddressTools.h" |
|
39 |
|
40 // Virtual Phonebook |
|
41 #include <MVPbkFieldType.h> |
|
42 #include <TVPbkFieldVersitProperty.h> |
|
43 #include <MVPbkContactFieldData.h> |
|
44 #include <MVPbkContactStore.h> |
|
45 #include <CVPbkContactManager.h> |
|
46 #include <MVPbkContactFieldData.h> |
|
47 #include <VPbkUtils.h> |
|
48 #include <VPbkEng.rsg> |
|
49 #include <MVPbkStoreContact.h> |
|
50 |
|
51 /// Unnamed namespace for local definitions |
|
52 namespace { |
|
53 |
|
54 _LIT( KCharsToReplace, "\t" ); |
|
55 _LIT( KReplacementChars, " " ); |
|
56 const TInt KMaxFormattedTIntLength( 15 ); |
|
57 const TInt KInitialBufferLength( 128 ); |
|
58 const TInt KGranularity( 8 ); |
|
59 |
|
60 } /// namespace |
|
61 |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2FieldListBoxRow::CPbk2FieldListBoxRow |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 inline CPbk2FieldListBoxRow::CPbk2FieldListBoxRow() |
|
68 { |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CPbk2FieldListBoxRow::~CPbk2FieldListBoxRow |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CPbk2FieldListBoxRow::~CPbk2FieldListBoxRow() |
|
76 { |
|
77 iColumns.ResetAndDestroy(); |
|
78 } |
|
79 |
|
80 // -------------------------------------------------------------------------- |
|
81 // CPbk2FieldListBoxRow::NewL |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 CPbk2FieldListBoxRow* CPbk2FieldListBoxRow::NewL() |
|
85 { |
|
86 return new( ELeave ) CPbk2FieldListBoxRow; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2FieldListBoxRow::ColumnCount |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 TInt CPbk2FieldListBoxRow::ColumnCount() const |
|
94 { |
|
95 return iColumns.Count(); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2FieldListBoxRow::At |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 TPtrC CPbk2FieldListBoxRow::At( TInt aColumnIndex ) const |
|
103 { |
|
104 return *iColumns[aColumnIndex]; |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CPbk2FieldListBoxRow::AppendColumnL |
|
109 // -------------------------------------------------------------------------- |
|
110 // |
|
111 void CPbk2FieldListBoxRow::AppendColumnL( const TDesC& aColumnText ) |
|
112 { |
|
113 HBufC* buf = aColumnText.AllocLC(); |
|
114 User::LeaveIfError( iColumns.Append( buf ) ); |
|
115 CleanupStack::Pop( buf ); |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPbk2FieldListBoxRow::TotalLength |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 TInt CPbk2FieldListBoxRow::TotalLength() const |
|
123 { |
|
124 TInt result = 0; |
|
125 const TInt count = iColumns.Count(); |
|
126 for (TInt i = 0; i < count; ++i) |
|
127 { |
|
128 result += At(i).Length(); |
|
129 } |
|
130 return result; |
|
131 } |
|
132 |
|
133 // -------------------------------------------------------------------------- |
|
134 // CPbk2FieldListBoxRow::MaxColumnLength |
|
135 // -------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CPbk2FieldListBoxRow::MaxColumnLength() const |
|
138 { |
|
139 TInt result = 0; |
|
140 const TInt count = iColumns.Count(); |
|
141 for (TInt i = 0; i < count; ++i) |
|
142 { |
|
143 result = Max(result, At(i).Length()); |
|
144 } |
|
145 return result; |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CPbk2FieldListBoxModel::CPbk2FieldListBoxModel |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 inline CPbk2FieldListBoxModel::CPbk2FieldListBoxModel( TParams& aParams, |
|
153 const TArray<CPbk2PresentationContactFieldCollection*>* |
|
154 aFieldCollectionArray, |
|
155 const TArray<TPresenceIconPosInIconArray>* aPresenceIconsPos ): |
|
156 iRows( KGranularity ), |
|
157 iParams( aParams ), |
|
158 iFieldCollectionArray( aFieldCollectionArray ), |
|
159 iPresenceIconsPos( aPresenceIconsPos ) |
|
160 { |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CPbk2FieldListBoxModel::~CPbk2FieldListBoxModel |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 CPbk2FieldListBoxModel::~CPbk2FieldListBoxModel() |
|
168 { |
|
169 iRows.ResetAndDestroy(); |
|
170 delete iColumnBuf; |
|
171 delete iLineBuf; |
|
172 delete iFieldFormatter; |
|
173 delete iDynamicProperties; |
|
174 iDuplicatesArray.Reset(); |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CPbk2FieldListBoxModel::NewL |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 CPbk2FieldListBoxModel* CPbk2FieldListBoxModel::NewL |
|
182 ( TParams& aParams, |
|
183 const TArray<CPbk2PresentationContactFieldCollection*>* |
|
184 aFieldCollectionArray, |
|
185 const TArray<TPresenceIconPosInIconArray>* aPresenceIconsPos ) |
|
186 { |
|
187 CPbk2FieldListBoxModel* self = new ( ELeave ) |
|
188 CPbk2FieldListBoxModel( aParams, aFieldCollectionArray, |
|
189 aPresenceIconsPos ); |
|
190 CleanupStack::PushL( self ); |
|
191 self->ConstructL( aParams ); |
|
192 CleanupStack::Pop( self ); |
|
193 return self; |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CPbk2FieldListBoxModel::ConstructL |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 void CPbk2FieldListBoxModel::ConstructL |
|
201 ( TParams& aParams ) |
|
202 { |
|
203 iFieldFormatter = CPbk2FieldFormatter::NewL |
|
204 ( aParams.iFieldProperties, aParams.iContactManager.FieldTypes() ); |
|
205 iFieldFormatter->SetTimeFormatL( aParams.iTimeFormat ); |
|
206 iLineBuf = HBufC::NewL( KInitialBufferLength ); |
|
207 iColumnBuf = HBufC::NewL( KInitialBufferLength ); |
|
208 iDynamicProperties = aParams.iDynamicProperties; |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CPbk2FieldListBoxModel::AppendRowL |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 void CPbk2FieldListBoxModel::AppendRowL( CPbk2FieldListBoxRow* aLine ) |
|
216 { |
|
217 ExpandBuffersL( *aLine ); |
|
218 iRows.AppendL( aLine ); |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CPbk2FieldListBoxModel::SetClipper |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 void CPbk2FieldListBoxModel::SetClipper |
|
226 ( MPbk2ClipListBoxText& aTextClipper ) |
|
227 { |
|
228 this->iTextClipper = &aTextClipper; |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CPbk2FieldListBoxModel::FormatFieldsL |
|
233 // -------------------------------------------------------------------------- |
|
234 // |
|
235 void CPbk2FieldListBoxModel::FormatFieldsL() |
|
236 { |
|
237 // Format all the fields and add lines to iTextArray |
|
238 const TInt fieldCount = iParams.iFields.FieldCount(); |
|
239 for ( TInt i=0; i < fieldCount; ++i ) |
|
240 { |
|
241 FormatFieldL( iParams.iFields.At(i), iParams ); |
|
242 } |
|
243 |
|
244 // Do the same for xSP contacts, if there are any |
|
245 if ( iFieldCollectionArray != NULL && iFieldCollectionArray->Count() > 0 ) |
|
246 { |
|
247 TInt contactsCount = iFieldCollectionArray->Count(); |
|
248 for ( TInt j = 0; j < contactsCount; j++ ) |
|
249 { |
|
250 TInt xspFieldCount = iFieldCollectionArray->operator[](j)-> |
|
251 FieldCount(); |
|
252 for ( TInt k = 0; k < xspFieldCount; k++ ) |
|
253 { |
|
254 FormatFieldL( iFieldCollectionArray->operator[](j)->At(k), |
|
255 iParams ); |
|
256 } |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 // -------------------------------------------------------------------------- |
|
262 // CPbk2FieldListBoxModel::GetModelIndex |
|
263 // -------------------------------------------------------------------------- |
|
264 // |
|
265 TInt CPbk2FieldListBoxModel::GetModelIndex( TInt aListboxIndex ) |
|
266 { |
|
267 TInt retIndex = aListboxIndex; |
|
268 TInt count = iDuplicatesArray.Count(); |
|
269 for ( TInt i = 0; i < count; i++ ) |
|
270 { |
|
271 if ( iDuplicatesArray[i] < aListboxIndex ) |
|
272 { |
|
273 retIndex++; |
|
274 } |
|
275 } |
|
276 return retIndex; |
|
277 } |
|
278 |
|
279 // -------------------------------------------------------------------------- |
|
280 // CPbk2FieldListBoxModel::MdcaCount |
|
281 // -------------------------------------------------------------------------- |
|
282 // |
|
283 TInt CPbk2FieldListBoxModel::MdcaCount() const |
|
284 { |
|
285 return iRows.Count(); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CPbk2FieldListBoxModel::MdcaPoint |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 TPtrC16 CPbk2FieldListBoxModel::MdcaPoint( TInt aIndex ) const |
|
293 { |
|
294 const TText KSeparator = '\t'; |
|
295 TPtr rowText( iLineBuf->Des() ); |
|
296 rowText.Zero(); |
|
297 |
|
298 const CPbk2FieldListBoxRow& row = *iRows[aIndex]; |
|
299 const TInt columnCount = row.ColumnCount(); |
|
300 for ( TInt columnIndex = 0; columnIndex < columnCount; ++columnIndex ) |
|
301 { |
|
302 TPtr columnText( iColumnBuf->Des() ); |
|
303 columnText.Copy( row.At( columnIndex ) ); |
|
304 |
|
305 // Clip the column if required |
|
306 if ( iTextClipper && columnIndex == EContentColumn && |
|
307 aIndex < iParams.iFields.FieldCount() ) |
|
308 { |
|
309 ClipText( iParams.iFields.At( aIndex ), aIndex, |
|
310 columnText, columnIndex ); |
|
311 } |
|
312 |
|
313 // Append the column and separator to the formatted row |
|
314 rowText.Append( columnText ); |
|
315 rowText.Append( KSeparator ); |
|
316 } |
|
317 |
|
318 return rowText; |
|
319 } |
|
320 |
|
321 // -------------------------------------------------------------------------- |
|
322 // CPbk2FieldListBoxModel::FormatFieldL |
|
323 // -------------------------------------------------------------------------- |
|
324 // |
|
325 void CPbk2FieldListBoxModel::FormatFieldL |
|
326 ( const CPbk2PresentationContactField& aField, TParams& aParams ) |
|
327 { |
|
328 // Figure out whether the field should be shown |
|
329 const MPbk2FieldAnalyzer* fieldAnalyzer = aParams.iFieldAnalyzer; |
|
330 const MPbk2ContactFieldDynamicProperties* dynamicProps |
|
331 = iDynamicProperties; |
|
332 |
|
333 TBool showField = ETrue; |
|
334 if ( fieldAnalyzer && fieldAnalyzer->IsHiddenField( aField ) || |
|
335 dynamicProps && dynamicProps->IsHiddenField( aField ) ) |
|
336 { |
|
337 showField = EFalse; |
|
338 } |
|
339 |
|
340 if (iParams.iCommMethod == VPbkFieldTypeSelectorFactory::EVOIPCallSelector && |
|
341 showField && fieldAnalyzer ) |
|
342 { |
|
343 const TInt voipFlag = fieldAnalyzer->VoipSupportL( iParams.iFields ); |
|
344 TInt resId = aField.BestMatchingFieldType()->FieldTypeResId(); |
|
345 if ( !fieldAnalyzer->IsFieldVoipCapable( resId, voipFlag ) ) |
|
346 { |
|
347 showField = EFalse; |
|
348 } |
|
349 } |
|
350 |
|
351 if ( showField ) |
|
352 { |
|
353 // Get master field type list and match field's type against it |
|
354 const MVPbkFieldTypeList* masterFieldTypeList = |
|
355 &iParams.iContactManager.FieldTypes(); |
|
356 |
|
357 const MVPbkFieldType* fieldType = |
|
358 VPbkUtils::MatchFieldType( *masterFieldTypeList, aField ); |
|
359 |
|
360 TPbk2StoreContactAnalyzer analyzer( iParams.iContactManager, NULL ); |
|
361 if ( analyzer.IsFieldTypeIncludedL( |
|
362 aField, R_PHONEBOOK2_ADDRESS_SELECTOR ) ) |
|
363 { |
|
364 FormatAddressFieldL( aField, aParams ); |
|
365 } |
|
366 else |
|
367 { |
|
368 CPbk2FieldListBoxRow* row = CPbk2FieldListBoxRow::NewL(); |
|
369 CleanupStack::PushL(row); |
|
370 TPtr columnBuf(iColumnBuf->Des()); |
|
371 AppendIconsToBeginningL(aField, *fieldType, *row, aParams); |
|
372 AppendFieldLabelL(aField, *row, columnBuf); |
|
373 AppendFieldContentL(aField, *fieldType, *row, columnBuf); |
|
374 AppendIconsToEndL(aField, *row, aParams); |
|
375 |
|
376 // Expand row formatting buffer if required |
|
377 ExpandBuffersL(*row); |
|
378 |
|
379 // Add the row |
|
380 // If the content of field is equal to other rows and need to be duplicated, |
|
381 // duplicate it |
|
382 if ( aParams.iFieldContentNeedToBeDuplicated && |
|
383 DuplicatesExist( columnBuf ) ) |
|
384 { |
|
385 CleanupStack::PopAndDestroy(row); |
|
386 iDuplicatesArray.AppendL( iRows.Count() - 1 ); // position of |
|
387 // the duplicate |
|
388 } |
|
389 else |
|
390 { |
|
391 iRows.AppendL(row); |
|
392 CleanupStack::Pop(row); |
|
393 } |
|
394 } |
|
395 } |
|
396 } |
|
397 |
|
398 // -------------------------------------------------------------------------- |
|
399 // CPbk2FieldListBoxModel::FormatAddressFieldL |
|
400 // -------------------------------------------------------------------------- |
|
401 // |
|
402 void CPbk2FieldListBoxModel::FormatAddressFieldL |
|
403 ( const CPbk2PresentationContactField& aField, TParams& aParams ) |
|
404 { |
|
405 CPbk2FieldListBoxRow* row = CPbk2FieldListBoxRow::NewL(); |
|
406 CleanupStack::PushL(row); |
|
407 |
|
408 TPtr columnBuf(iColumnBuf->Des()); |
|
409 AppendAddressIconsToBeginningL(aField, *row, aParams); |
|
410 AppendAddressFieldLabelL(aField, *row, columnBuf); |
|
411 TBool duplicates = DuplicatesAddressExist( columnBuf, row->ColumnCount() - 1 ); |
|
412 AppendAddressFieldContentL(aField, *row, columnBuf); |
|
413 |
|
414 // Expand row formatting buffer if required |
|
415 ExpandBuffersL(*row); |
|
416 |
|
417 // Add the row |
|
418 if ( !duplicates ) |
|
419 { |
|
420 iRows.AppendL(row); |
|
421 CleanupStack::Pop(row); |
|
422 } |
|
423 else |
|
424 { |
|
425 CleanupStack::PopAndDestroy(row); |
|
426 iDuplicatesArray.AppendL( iRows.Count() - 1 ); // position of |
|
427 // the duplicate |
|
428 } |
|
429 } |
|
430 |
|
431 // -------------------------------------------------------------------------- |
|
432 // CPbk2FieldListBoxModel::ExpandBuffersL |
|
433 // -------------------------------------------------------------------------- |
|
434 // |
|
435 void CPbk2FieldListBoxModel::ExpandBuffersL |
|
436 ( const CPbk2FieldListBoxRow& aRow ) |
|
437 { |
|
438 // Row formatting buffer |
|
439 const TInt rowLength = aRow.TotalLength() |
|
440 + aRow.ColumnCount(); // for separator characters |
|
441 |
|
442 if (rowLength > iLineBuf->Des().MaxLength()) |
|
443 { |
|
444 iLineBuf = iLineBuf->ReAllocL( rowLength ); |
|
445 } |
|
446 |
|
447 ExpandColumnBufferL( aRow.MaxColumnLength() ); |
|
448 } |
|
449 |
|
450 // -------------------------------------------------------------------------- |
|
451 // CPbk2FieldListBoxModel::ExpandColumnBufferL |
|
452 // -------------------------------------------------------------------------- |
|
453 // |
|
454 TPtr CPbk2FieldListBoxModel::ExpandColumnBufferL |
|
455 ( TInt aRequiredLength ) |
|
456 { |
|
457 if ( aRequiredLength > iColumnBuf->Des().MaxLength() ) |
|
458 { |
|
459 iColumnBuf = iColumnBuf->ReAllocL( aRequiredLength ); |
|
460 } |
|
461 return ( iColumnBuf->Des() ); |
|
462 } |
|
463 |
|
464 // -------------------------------------------------------------------------- |
|
465 // CPbk2FieldListBoxModel::ClipText |
|
466 // Clip text from beginning if field is numeric field or e-mail field. |
|
467 // -------------------------------------------------------------------------- |
|
468 // |
|
469 inline void CPbk2FieldListBoxModel::ClipText |
|
470 ( const CPbk2PresentationContactField& aField, TInt aIndex, |
|
471 TPtr& aColumnText, TInt aColumnIndex ) const |
|
472 { |
|
473 TPbk2StoreContactAnalyzer analyzer( iParams.iContactManager, NULL ); |
|
474 TBool clip = analyzer.IsFieldTypeIncludedL |
|
475 ( aField, R_PHONEBOOK2_PHONENUMBER_SELECTOR ); |
|
476 |
|
477 if ( !clip ) |
|
478 { |
|
479 clip = analyzer.IsFieldTypeIncludedL |
|
480 ( aField, R_PHONEBOOK2_EMAIL_SELECTOR ); |
|
481 } |
|
482 |
|
483 // Clip if required |
|
484 if ( clip ) |
|
485 { |
|
486 iTextClipper->ClipFromBeginning |
|
487 ( aColumnText, aIndex, aColumnIndex ); |
|
488 } |
|
489 } |
|
490 |
|
491 // -------------------------------------------------------------------------- |
|
492 // CPbk2FieldListBoxModel::AppendFieldLabelL |
|
493 // Appends field label. Removes any listbox separator characters. |
|
494 // -------------------------------------------------------------------------- |
|
495 // |
|
496 inline void CPbk2FieldListBoxModel::AppendFieldLabelL |
|
497 ( const CPbk2PresentationContactField& aField, |
|
498 CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf ) |
|
499 { |
|
500 aColumnBuf.Set( ExpandColumnBufferL( aField.FieldLabel().Length() ) ); |
|
501 aColumnBuf.Zero(); |
|
502 Pbk2PresentationUtils::AppendAndReplaceChars |
|
503 ( aColumnBuf, aField.FieldLabel(), |
|
504 KCharsToReplace, KReplacementChars ); |
|
505 // Replace characters that can not be displayed correctly |
|
506 Pbk2PresentationUtils::ReplaceNonGraphicCharacters |
|
507 ( aColumnBuf, ' ' ); |
|
508 aRow.AppendColumnL( aColumnBuf ); |
|
509 } |
|
510 |
|
511 // -------------------------------------------------------------------------- |
|
512 // CPbk2FieldListBoxModel::AppendAddressFieldLabelL |
|
513 // Appends field label. Removes any listbox separator characters. |
|
514 // -------------------------------------------------------------------------- |
|
515 // |
|
516 inline void CPbk2FieldListBoxModel::AppendAddressFieldLabelL |
|
517 ( const CPbk2PresentationContactField& aField, |
|
518 CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf ) |
|
519 { |
|
520 aColumnBuf.Set( ExpandColumnBufferL( aField.FieldLabel().Length() ) ); |
|
521 aColumnBuf.Zero(); |
|
522 TBool address = EFalse; |
|
523 |
|
524 const TInt countProperties = |
|
525 aField.FieldProperty().FieldType().VersitProperties().Count(); |
|
526 TArray<TVPbkFieldVersitProperty> props = |
|
527 aField.FieldProperty().FieldType().VersitProperties(); |
|
528 for ( TInt i = 0; i < countProperties; ++i ) |
|
529 { |
|
530 if ( props[ i ].Name() == EVPbkVersitNameADR |
|
531 && props[ i ].Parameters().Contains( EVPbkVersitParamHOME ) ) |
|
532 { |
|
533 HBufC* label = |
|
534 StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_HOME ); |
|
535 Pbk2PresentationUtils::AppendAndReplaceChars |
|
536 ( aColumnBuf, *label, |
|
537 KCharsToReplace, KReplacementChars ); |
|
538 CleanupStack::PopAndDestroy( label ); |
|
539 address = ETrue; |
|
540 } |
|
541 else if ( props[ i ].Name() == EVPbkVersitNameADR |
|
542 && props[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) |
|
543 { |
|
544 HBufC* label = |
|
545 StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_WORK ); |
|
546 Pbk2PresentationUtils::AppendAndReplaceChars |
|
547 ( aColumnBuf, *label, |
|
548 KCharsToReplace, KReplacementChars ); |
|
549 CleanupStack::PopAndDestroy( label ); |
|
550 address = ETrue; |
|
551 } |
|
552 else if ( props[ i ].Name() == EVPbkVersitNameADR |
|
553 && !( props[ i ].Parameters().Contains( EVPbkVersitParamHOME ) ) |
|
554 && !( props[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) ) |
|
555 { |
|
556 HBufC* label = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS ); |
|
557 Pbk2PresentationUtils::AppendAndReplaceChars |
|
558 ( aColumnBuf, *label, |
|
559 KCharsToReplace, KReplacementChars ); |
|
560 CleanupStack::PopAndDestroy( label ); |
|
561 address = ETrue; |
|
562 } |
|
563 } |
|
564 |
|
565 // Replace characters that can not be displayed correctly |
|
566 Pbk2PresentationUtils::ReplaceNonGraphicCharacters |
|
567 ( aColumnBuf, ' ' ); |
|
568 aRow.AppendColumnL( aColumnBuf ); |
|
569 } |
|
570 |
|
571 // -------------------------------------------------------------------------- |
|
572 // CPbk2FieldListBoxModel::AppendFieldContentL |
|
573 // Appends field content. |
|
574 // -------------------------------------------------------------------------- |
|
575 // |
|
576 inline void CPbk2FieldListBoxModel::AppendFieldContentL |
|
577 ( const CPbk2PresentationContactField& aField, |
|
578 const MVPbkFieldType& aFieldType, |
|
579 CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf ) |
|
580 { |
|
581 TPtrC fieldText( iFieldFormatter->FormatFieldContentL |
|
582 ( aField, aFieldType ) ); |
|
583 aColumnBuf.Set( ExpandColumnBufferL( fieldText.Length() ) ); |
|
584 aColumnBuf.Zero(); |
|
585 Pbk2PresentationUtils::AppendAndReplaceChars |
|
586 ( aColumnBuf, fieldText, KCharsToReplace, KReplacementChars ); |
|
587 // Replace characters that can not be displayed correctly |
|
588 Pbk2PresentationUtils::ReplaceNonGraphicCharacters |
|
589 (aColumnBuf, ' '); |
|
590 aRow.AppendColumnL( aColumnBuf ); |
|
591 } |
|
592 |
|
593 // -------------------------------------------------------------------------- |
|
594 // CPbk2FieldListBoxModel::AppendAddressFieldContentL |
|
595 // Appends field content. |
|
596 // -------------------------------------------------------------------------- |
|
597 // |
|
598 inline void CPbk2FieldListBoxModel::AppendAddressFieldContentL |
|
599 ( const CPbk2PresentationContactField& aField, |
|
600 CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf ) |
|
601 { |
|
602 TPbk2FieldGroupId address = EPbk2FieldGroupIdNone; |
|
603 const TInt countFieldProps = |
|
604 aField.FieldProperty().FieldType().VersitProperties().Count(); |
|
605 TArray<TVPbkFieldVersitProperty> fieldProps = |
|
606 aField.FieldProperty().FieldType().VersitProperties(); |
|
607 for ( TInt i = 0; i < countFieldProps; ++i ) |
|
608 { |
|
609 if ( fieldProps[ i ].Name() == EVPbkVersitNameADR ) |
|
610 { |
|
611 if ( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamHOME ) ) |
|
612 { |
|
613 address = EPbk2FieldGroupIdHomeAddress; |
|
614 } |
|
615 else if ( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) |
|
616 { |
|
617 address = EPbk2FieldGroupIdCompanyAddress; |
|
618 } |
|
619 else if ( !( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamHOME ) ) |
|
620 && !( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) ) |
|
621 { |
|
622 address = EPbk2FieldGroupIdPostalAddress; |
|
623 } |
|
624 } |
|
625 } |
|
626 if ( address ) |
|
627 { |
|
628 RBuf text; |
|
629 Pbk2AddressTools::GetAddressShortPreviewLC( |
|
630 static_cast<MVPbkStoreContact&>( |
|
631 aField.ParentContact() ), address, text ); |
|
632 HBufC* buffer = HBufC::NewLC( text.Length() ); |
|
633 TPtr textFormatted ( buffer->Des() ); |
|
634 Pbk2PresentationUtils::AppendWithNewlineTranslationL |
|
635 ( textFormatted, text ); |
|
636 aColumnBuf.Set( ExpandColumnBufferL( textFormatted.Length() ) ); |
|
637 aColumnBuf.Zero(); |
|
638 Pbk2PresentationUtils::AppendAndReplaceChars |
|
639 ( aColumnBuf, textFormatted, KCharsToReplace, KReplacementChars ); |
|
640 CleanupStack::PopAndDestroy( buffer ); |
|
641 CleanupStack::PopAndDestroy( &text ); // text |
|
642 // Replace characters that can not be displayed correctly |
|
643 Pbk2PresentationUtils::ReplaceNonGraphicCharacters |
|
644 (aColumnBuf, ' '); |
|
645 aRow.AppendColumnL( aColumnBuf ); |
|
646 } |
|
647 } |
|
648 |
|
649 // -------------------------------------------------------------------------- |
|
650 // CPbk2FieldListBoxModel::AppendIconsToBeginningL |
|
651 // Adds icons to the beginning. |
|
652 // -------------------------------------------------------------------------- |
|
653 // |
|
654 inline void CPbk2FieldListBoxModel::AppendIconsToBeginningL |
|
655 ( const CPbk2PresentationContactField& aField, |
|
656 const MVPbkFieldType& aFieldType, |
|
657 CPbk2FieldListBoxRow& aRow, TParams& aParams ) |
|
658 { |
|
659 // Format icon index |
|
660 TBuf<KMaxFormattedTIntLength> iconText; |
|
661 |
|
662 // appened presence icon for xSP field |
|
663 TInt iconIndex = KErrNotFound; |
|
664 if ( iPresenceIconsPos != NULL && |
|
665 aFieldType.FieldTypeResId() == R_VPBK_FIELD_TYPE_IMPP ) |
|
666 { |
|
667 TPtrC fieldText( iFieldFormatter->FormatFieldContentL |
|
668 ( aField, aFieldType ) ); |
|
669 TInt count = iPresenceIconsPos->Count(); |
|
670 for ( TInt i = 0; i < count && iconIndex == KErrNotFound; i++ ) |
|
671 { |
|
672 if ( !(fieldText.CompareF( iPresenceIconsPos->operator[](i). |
|
673 iServiceName ) )) |
|
674 { |
|
675 iconIndex = aParams.iIconArray.FindIcon( |
|
676 iPresenceIconsPos->operator[](i).iIconId ); |
|
677 } |
|
678 } |
|
679 } |
|
680 |
|
681 if ( iconIndex == KErrNotFound ) |
|
682 { |
|
683 iconIndex = aParams.iIconArray.FindIcon( |
|
684 aField.FieldProperty().IconId() ); |
|
685 } |
|
686 if ( iconIndex == KErrNotFound ) |
|
687 { |
|
688 iconIndex = aParams.iIconArray.FindIcon( iParams.iDefaultIconId ); |
|
689 } |
|
690 |
|
691 iconText.Num( iconIndex ); |
|
692 aRow.AppendColumnL( iconText ); |
|
693 } |
|
694 |
|
695 // -------------------------------------------------------------------------- |
|
696 // CPbk2FieldListBoxModel::AppendAddressIconsToBeginningL |
|
697 // Adds icons to the beginning. |
|
698 // -------------------------------------------------------------------------- |
|
699 // |
|
700 inline void CPbk2FieldListBoxModel::AppendAddressIconsToBeginningL |
|
701 ( const CPbk2PresentationContactField& aField, |
|
702 CPbk2FieldListBoxRow& aRow, TParams& aParams ) |
|
703 { |
|
704 // Format icon index |
|
705 TBuf<KMaxFormattedTIntLength> iconText; |
|
706 TInt iconIndex = KErrNotFound; |
|
707 |
|
708 if ( IsGeoFieldForAddressL( aField ) ) |
|
709 { |
|
710 iconIndex = aParams.iIconArray.FindIcon( |
|
711 TPbk2AppIconId( EPbk2qgn_prop_locev_map ) ); |
|
712 } |
|
713 else |
|
714 { |
|
715 iconIndex = aParams.iIconArray.FindIcon( |
|
716 TPbk2AppIconId( EPbk2qgn_prop_pb_no_valid_lm ) ); |
|
717 } |
|
718 |
|
719 iconText.Num( iconIndex ); |
|
720 aRow.AppendColumnL( iconText ); |
|
721 } |
|
722 |
|
723 // -------------------------------------------------------------------------- |
|
724 // CPbk2FieldListBoxModel::IsGeoFieldForAddressL |
|
725 // Checks if address is validated. |
|
726 // -------------------------------------------------------------------------- |
|
727 // |
|
728 inline TBool CPbk2FieldListBoxModel::IsGeoFieldForAddressL |
|
729 ( const CPbk2PresentationContactField& aField ) |
|
730 { |
|
731 TBool result = EFalse; |
|
732 TInt startIndex = 0; |
|
733 |
|
734 TPbk2StoreContactAnalyzer analyzer( iParams.iContactManager, NULL ); |
|
735 if ( analyzer.IsFieldTypeIncludedL( |
|
736 aField, R_PHONEBOOK2_HOME_ADDRESS_SELECTOR ) ) |
|
737 { |
|
738 if ( analyzer.HasFieldL( R_PHONEBOOK2_HOME_GEO_SELECTOR, |
|
739 startIndex, |
|
740 &iParams.iFields.ParentStoreContact() ) != KErrNotFound ) |
|
741 { |
|
742 result = ETrue; |
|
743 } |
|
744 } |
|
745 else if ( analyzer.IsFieldTypeIncludedL( |
|
746 aField, R_PHONEBOOK2_WORK_ADDRESS_SELECTOR ) ) |
|
747 { |
|
748 if ( analyzer.HasFieldL( R_PHONEBOOK2_WORK_GEO_SELECTOR, |
|
749 startIndex, |
|
750 &iParams.iFields.ParentStoreContact() ) != KErrNotFound ) |
|
751 { |
|
752 result = ETrue; |
|
753 } |
|
754 } |
|
755 else if ( analyzer.IsFieldTypeIncludedL( |
|
756 aField, R_PHONEBOOK2_GENERAL_ADDRESS_SELECTOR ) ) |
|
757 { |
|
758 if ( analyzer.HasFieldL( R_PHONEBOOK2_GENERAL_GEO_SELECTOR, |
|
759 startIndex, |
|
760 &iParams.iFields.ParentStoreContact() ) != KErrNotFound ) |
|
761 { |
|
762 result = ETrue; |
|
763 } |
|
764 } |
|
765 |
|
766 return result; |
|
767 } |
|
768 |
|
769 // -------------------------------------------------------------------------- |
|
770 // CPbk2FieldListBoxModel::AppendIconsToEndL |
|
771 // Adds additional icons to the end. |
|
772 // -------------------------------------------------------------------------- |
|
773 // |
|
774 inline void CPbk2FieldListBoxModel::AppendIconsToEndL |
|
775 ( const CPbk2PresentationContactField& aField, |
|
776 CPbk2FieldListBoxRow& aRow, TParams& aParams ) |
|
777 { |
|
778 if ( aParams.iFieldAnalyzer ) |
|
779 { |
|
780 // Check and add speed dial icon |
|
781 if ( aParams.iFieldAnalyzer->HasSpeedDialL( aField.StoreField() ) ) |
|
782 { |
|
783 TBuf<KMaxFormattedTIntLength> iconText; |
|
784 iconText.Num( aParams.iIconArray. |
|
785 FindIcon( TPbk2AppIconId( EPbk2qgn_indi_qdial_add ) ) ); |
|
786 aRow.AppendColumnL( iconText ); |
|
787 } |
|
788 } |
|
789 } |
|
790 |
|
791 // -------------------------------------------------------------------------- |
|
792 // CPbk2FieldListBoxModel::DuplicatesExist |
|
793 // Checks if row with the same content already exists. |
|
794 // -------------------------------------------------------------------------- |
|
795 // |
|
796 inline TBool CPbk2FieldListBoxModel::DuplicatesExist( |
|
797 TPtrC aContent ) |
|
798 { |
|
799 TBool ret = EFalse; |
|
800 TInt rowsCount = iRows.Count(); |
|
801 for( TInt i = 0; i < rowsCount && !ret; i++ ) |
|
802 { |
|
803 TInt columnsCount = iRows[i]->ColumnCount(); |
|
804 for( TInt j = 0; j < columnsCount && !ret; j++ ) |
|
805 { |
|
806 if ( iRows[i]->At(j).CompareF( aContent ) == 0 ) |
|
807 { |
|
808 ret = ETrue; |
|
809 } |
|
810 } |
|
811 } |
|
812 |
|
813 return ret; |
|
814 } |
|
815 |
|
816 // -------------------------------------------------------------------------- |
|
817 // CPbk2FieldListBoxModel::DuplicatesAddressExist |
|
818 // Checks if row with the same content already exists. |
|
819 // -------------------------------------------------------------------------- |
|
820 // |
|
821 inline TBool CPbk2FieldListBoxModel::DuplicatesAddressExist( |
|
822 TPtrC aContent, TInt aIndex ) |
|
823 { |
|
824 TBool ret = EFalse; |
|
825 TInt rowsCount = iRows.Count(); |
|
826 for( TInt i = 0; i < rowsCount && !ret; i++ ) |
|
827 { |
|
828 if ( aIndex < iRows[i]->ColumnCount() ) |
|
829 { |
|
830 if ( iRows[i]->At( aIndex ).CompareF( aContent ) == 0 ) |
|
831 { |
|
832 ret = ETrue; |
|
833 } |
|
834 } |
|
835 } |
|
836 |
|
837 return ret; |
|
838 } |
|
839 |
|
840 // End of File |