1 /* |
|
2 * Copyright (c) 2009 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: Listbox model for MyCard details list |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <TPbk2StoreContactAnalyzer.h> |
|
19 #include <Pbk2UIControls.rsg> |
|
20 #include <Pbk2PresentationUtils.h> |
|
21 #include <CPbk2PresentationContact.h> |
|
22 #include <CPbk2PresentationContactField.h> |
|
23 #include <CPbk2PresentationContactFieldCollection.h> |
|
24 #include <CPbk2IconArray.h> |
|
25 #include <MPbk2FieldProperty.h> |
|
26 |
|
27 #include <CVPbkContactManager.h> |
|
28 #include <MVPbkFieldType.h> |
|
29 #include <MVPbkContactFieldTextData.h> |
|
30 #include <MVPbkContactFieldUriData.h> |
|
31 #include <MVPbkContactFieldDateTimeData.h> |
|
32 #include <MVPbkContactFieldData.h> |
|
33 #include <VPbkUtils.h> |
|
34 #include <VPbkEng.rsg> |
|
35 |
|
36 #include <aknlists.h> |
|
37 #include <avkon.rsg> |
|
38 |
|
39 #include "ccappmycardcommon.h" |
|
40 #include "ccappmycardlistboxmodel.h" |
|
41 #include "ccappmycardlistboxrow.h" |
|
42 #include <ccappmycardpluginrsc.rsg> |
|
43 |
|
44 |
|
45 /// Granularity of the row array |
|
46 const TInt KRowArrayGranularity = 4; |
|
47 |
|
48 /// Initial buffer size for temporary text buffers |
|
49 const TInt KBufferSize = 256; |
|
50 |
|
51 /// Disallowed characters in column text |
|
52 _LIT( KCharsToReplace, "\t" ); |
|
53 |
|
54 /// Replacement character for invalid or graphical column characters |
|
55 _LIT( KReplacementChars, " " ); |
|
56 const TText KReplacedChars = ' '; |
|
57 |
|
58 /// Content colum index |
|
59 const TInt KContentColumnIndex = 2; |
|
60 |
|
61 /// Column separator |
|
62 const TText KColumnSeparator = '\t'; |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CCCAppMyCardListBoxModel::NewL |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CCCAppMyCardListBoxModel* CCCAppMyCardListBoxModel::NewL(CCCAppMyCard& aMyCard, |
|
70 CCoeEnv& aCoeEnv, CEikListBox& aListBox, CPbk2IconArray& aIconArray) |
|
71 { |
|
72 CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardListBoxModel::NewL()") ); |
|
73 |
|
74 CCCAppMyCardListBoxModel* self = new (ELeave) CCCAppMyCardListBoxModel( |
|
75 aMyCard, aCoeEnv, aListBox, aIconArray); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(self); |
|
79 |
|
80 CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardListBoxModel::NewL()") ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CCCAppMyCardListBoxModel::~CCCAppMyCardListBoxModel |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CCCAppMyCardListBoxModel::~CCCAppMyCardListBoxModel() |
|
89 { |
|
90 CCA_DP(KMyCardLogFile, |
|
91 CCA_L("->CCCAppMyCardListBoxModel::~CCCAppMyCardListBoxModel()") ); |
|
92 |
|
93 iRows.ResetAndDestroy(); |
|
94 delete iLineBuf; |
|
95 delete iColumnBuf; |
|
96 iInxToPresentationIdx.Close(); |
|
97 |
|
98 CCA_DP(KMyCardLogFile, |
|
99 CCA_L("<-CCCAppMyCardListBoxModel::~CCCAppMyCardListBoxModel()") ); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CCCAppMyCardListBoxModel::CCCAppMyCardListBoxModel |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CCCAppMyCardListBoxModel::CCCAppMyCardListBoxModel( |
|
107 CCCAppMyCard& aMyCard, |
|
108 CCoeEnv& aCoeEnv, |
|
109 CEikListBox& aListBox, |
|
110 CPbk2IconArray& aIconArray ) : |
|
111 iCoeEnv(aCoeEnv), |
|
112 iMyCard(aMyCard), |
|
113 iListBox(aListBox), |
|
114 iIconArray(aIconArray), |
|
115 iRows(KRowArrayGranularity) |
|
116 { |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CCCAppMyCardListBoxModel::ConstructL |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CCCAppMyCardListBoxModel::ConstructL() |
|
124 { |
|
125 iLineBuf = HBufC::NewL(KBufferSize); |
|
126 iColumnBuf = HBufC::NewL(KBufferSize); |
|
127 |
|
128 iMyCard.AddObserverL(this); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CCCAppMyCardListBoxModel::MyCardEventL |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CCCAppMyCardListBoxModel::MyCardEventL(TEvent aEvent) |
|
136 { |
|
137 if( aEvent == MMyCardObserver::EEventContactLoaded) |
|
138 { |
|
139 CCA_DP( KMyCardLogFile, |
|
140 CCA_L("->CCCAppMyCardListBoxModel::MyCardEventL EEventContactLoaded") ); |
|
141 |
|
142 iPresentationContact = &iMyCard.PresentationContactL(); |
|
143 AddDataL(); |
|
144 } |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CCCAppMyCardListBoxModel::MdcaCount |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CCCAppMyCardListBoxModel::MdcaCount() const |
|
152 { |
|
153 return iRows.Count(); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CCCAppMyCardListBoxModel::MdcaPoint |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TPtrC CCCAppMyCardListBoxModel::MdcaPoint(TInt aIndex) const |
|
161 { |
|
162 TPtr rowText( iLineBuf->Des() ); |
|
163 rowText.Zero(); |
|
164 |
|
165 const CCCAppMyCardListBoxRow& row = *iRows[aIndex]; |
|
166 const TInt columnCount = row.ColumnCount(); |
|
167 TInt fieldCount = iPresentationContact->PresentationFields().FieldCount(); |
|
168 |
|
169 for( TInt index = 0; index < columnCount; ++index ) |
|
170 { |
|
171 TPtr columnText( iColumnBuf->Des() ); |
|
172 columnText.Copy( row.At(index) ); |
|
173 |
|
174 // Clip the column if required |
|
175 if( index == KContentColumnIndex && |
|
176 row.IsClipRequired() && |
|
177 aIndex < fieldCount ) |
|
178 { |
|
179 ClipFromBeginning( columnText, aIndex, index ); |
|
180 } |
|
181 |
|
182 // Append the column and separator to the formatted row |
|
183 rowText.Append( columnText ); |
|
184 rowText.Append( KColumnSeparator ); |
|
185 } |
|
186 |
|
187 return rowText; |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CCCAppMyCardListBoxModel::FieldIndex |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 TInt CCCAppMyCardListBoxModel::FieldIndex( TInt aIndex ) |
|
195 { |
|
196 TInt* index = iInxToPresentationIdx.Find( aIndex ); |
|
197 |
|
198 if( index && *index >= 0 ) |
|
199 { |
|
200 return iPresentationContact->PresentationFields().StoreIndexOfField( *index ); |
|
201 } |
|
202 return KErrNotFound; |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CCCAppMyCardListBoxModel::AddDataL |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 void CCCAppMyCardListBoxModel::AddDataL() |
|
210 { |
|
211 CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardListBoxModel::AddDataL()") ); |
|
212 |
|
213 iRows.ResetAndDestroy(); |
|
214 iInxToPresentationIdx.Close(); |
|
215 |
|
216 TInt listIdx = -1; |
|
217 |
|
218 TInt fieldCount = iPresentationContact->PresentationFields().FieldCount(); |
|
219 for (TInt index = 0; index < fieldCount; index++) |
|
220 { |
|
221 CPbk2PresentationContactField& field = |
|
222 iPresentationContact->PresentationFields().At(index); |
|
223 |
|
224 // Get master field type list and match field's type against it |
|
225 const MVPbkFieldType* fieldType = VPbkUtils::MatchFieldType( |
|
226 iMyCard.ContactManager().FieldTypes(), field ); |
|
227 |
|
228 if( field.IsEditable() && fieldType && !IsHiddenField(fieldType) ) |
|
229 { |
|
230 HBufC* label = GetLabelLC( field ); |
|
231 |
|
232 if( label->Length() ) |
|
233 { |
|
234 CCCAppMyCardListBoxRow* row = |
|
235 CCCAppMyCardListBoxRow::NewL(); |
|
236 CleanupStack::PushL(row); |
|
237 |
|
238 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
239 |
|
240 // Add icon |
|
241 TBuf<20> buffer; // 20 should be enough for icon index |
|
242 TInt iconIndex = iIconArray.FindIcon( |
|
243 field.FieldProperty().IconId() ); |
|
244 if( iconIndex != KErrNotFound) |
|
245 { |
|
246 buffer.AppendNum(iconIndex); |
|
247 } |
|
248 row->AppendColumnL(buffer); |
|
249 |
|
250 // add label. |
|
251 row->AppendColumnL(*label); |
|
252 |
|
253 // Add current index to Presentation Contact index array |
|
254 // to estimate the text is needed to clip or not. |
|
255 iInxToPresentationIdx.InsertL(++listIdx, index); |
|
256 |
|
257 // add field content. |
|
258 switch (fieldData.DataType() ) |
|
259 { |
|
260 case EVPbkFieldStorageTypeText: |
|
261 { |
|
262 HandleTextTypeFieldL(index, fieldData, row); |
|
263 break; |
|
264 } |
|
265 case EVPbkFieldStorageTypeDateTime: |
|
266 { |
|
267 HandleDateTimeTypeFieldL(fieldData, row); |
|
268 break; |
|
269 } |
|
270 case EVPbkFieldStorageTypeUri: |
|
271 { |
|
272 HandleUriTypeFieldL(index, fieldData, row); |
|
273 break; |
|
274 } |
|
275 } |
|
276 |
|
277 // Expand row formatting buffer if required |
|
278 ExpandBuffersL(row); |
|
279 |
|
280 // Add the row if data ok to show to user. |
|
281 iRows.AppendL(row); |
|
282 CleanupStack::Pop(row); |
|
283 } |
|
284 |
|
285 CleanupStack::PopAndDestroy(label); |
|
286 } |
|
287 } // for |
|
288 |
|
289 iListBox.HandleItemAdditionL(); |
|
290 |
|
291 CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardListBoxModel::AddDataL()") ); |
|
292 } |
|
293 |
|
294 // -------------------------------------------------------------------------- |
|
295 // CCCAppMyCardListBoxModel::IsHiddenField |
|
296 // -------------------------------------------------------------------------- |
|
297 // |
|
298 TBool CCCAppMyCardListBoxModel::IsHiddenField(const MVPbkFieldType* aFieldType) |
|
299 { |
|
300 TInt resId = aFieldType->FieldTypeResId(); |
|
301 return ( resId == R_VPBK_FIELD_TYPE_SYNCCLASS || |
|
302 resId == R_VPBK_FIELD_TYPE_CALLEROBJIMG ); |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CCCAppMyCardListBoxModel::FieldAtLC |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 MVPbkBaseContactField* CCCAppMyCardListBoxModel::FieldAtLC(TInt aIndex) |
|
310 { |
|
311 TInt *presentationIdx = iInxToPresentationIdx.Find(aIndex); |
|
312 |
|
313 if( !presentationIdx) |
|
314 { |
|
315 return NULL; |
|
316 } |
|
317 |
|
318 TInt index = iPresentationContact->PresentationFields().StoreIndexOfField( |
|
319 *presentationIdx); |
|
320 |
|
321 if( index != KErrNotFound) |
|
322 { |
|
323 // Use FieldAtLC to avoid the unvalidity of the field after new |
|
324 // FieldAt call. |
|
325 return iMyCard.StoreContact().Fields().FieldAtLC(index); |
|
326 } |
|
327 |
|
328 return NULL; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // CCCAppMyCardListBoxModel::IsFieldTypeL |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TBool CCCAppMyCardListBoxModel::IsFieldTypeL( |
|
336 TInt aIndex, TInt aSelectorResId ) |
|
337 { |
|
338 TBool ret = EFalse; |
|
339 MVPbkBaseContactField* field = FieldAtLC(aIndex); |
|
340 |
|
341 if( field ) |
|
342 { |
|
343 TPbk2StoreContactAnalyzer analyzer( iMyCard.ContactManager(), NULL ); |
|
344 ret = analyzer.IsFieldTypeIncludedL( *field, aSelectorResId ); |
|
345 CleanupStack::PopAndDestroy(field); |
|
346 } |
|
347 |
|
348 return ret; |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // CCCAppMyCardListBoxModel::HandleTextTypeFieldL |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CCCAppMyCardListBoxModel::HandleTextTypeFieldL( |
|
356 TInt aIndex, |
|
357 const MVPbkContactFieldData& aFieldData, |
|
358 CCCAppMyCardListBoxRow* aRow ) |
|
359 { |
|
360 const TDesC& fieldText = MVPbkContactFieldTextData::Cast(aFieldData).Text(); |
|
361 |
|
362 // Check if clipping is required |
|
363 if( IsFieldTypeL( aIndex, R_MYCARD_CLIP_FIELD_SELECTOR ) ) |
|
364 { |
|
365 aRow->SetClipRequired( ETrue ); |
|
366 } |
|
367 |
|
368 TPtr columnBuf( iColumnBuf->Des() ); |
|
369 columnBuf.Set( ExpandColumnBufferL( fieldText.Length() ) ); |
|
370 columnBuf.Zero(); |
|
371 |
|
372 // replace listbox separator characters. |
|
373 Pbk2PresentationUtils::AppendAndReplaceChars( columnBuf, fieldText, |
|
374 KCharsToReplace, KReplacementChars ); |
|
375 |
|
376 // Replace characters that can not be displayed correctly. |
|
377 Pbk2PresentationUtils::ReplaceNonGraphicCharacters( columnBuf, KReplacedChars ); |
|
378 |
|
379 aRow->AppendColumnL( columnBuf ); |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // CCCAppMyCardListBoxModel::HandleDateTimeTypeFieldL |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 void CCCAppMyCardListBoxModel::HandleDateTimeTypeFieldL( |
|
387 const MVPbkContactFieldData& aFieldData, CCCAppMyCardListBoxRow* aRow) |
|
388 { |
|
389 const MVPbkContactFieldDateTimeData& date = |
|
390 MVPbkContactFieldDateTimeData::Cast(aFieldData); |
|
391 |
|
392 HBufC* dateFormat = |
|
393 iCoeEnv.AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
394 |
|
395 TLocale locale; |
|
396 TBuf<64> dateBuffer; |
|
397 TTime time( date.DateTime() ); |
|
398 time.FormatL( dateBuffer, *dateFormat, locale ); |
|
399 CleanupStack::PopAndDestroy( dateFormat ); |
|
400 |
|
401 aRow->AppendColumnL( dateBuffer ); |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // CCCAppMyCardListBoxModel::HandleUriTypeFieldL |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CCCAppMyCardListBoxModel::HandleUriTypeFieldL(TInt aIndex, |
|
409 const MVPbkContactFieldData& aFieldData, CCCAppMyCardListBoxRow* aRow) |
|
410 { |
|
411 TBool isXspField = IsFieldTypeL( aIndex, R_MYCARD_CLIP_FIELD_SELECTOR ); |
|
412 if ( isXspField ) |
|
413 { |
|
414 aRow->SetClipRequired( ETrue ); |
|
415 } |
|
416 |
|
417 const MVPbkContactFieldUriData& uri = |
|
418 MVPbkContactFieldUriData::Cast( aFieldData ); |
|
419 |
|
420 HBufC* tempBuf = uri.Text().AllocLC(); |
|
421 TPtr text = tempBuf->Des(); |
|
422 // Replace characters that can not be displayed correctly. |
|
423 Pbk2PresentationUtils::ReplaceNonGraphicCharacters( text, KReplacedChars ); |
|
424 |
|
425 aRow->AppendColumnL( text ); |
|
426 CleanupStack::PopAndDestroy( tempBuf ); |
|
427 } |
|
428 |
|
429 // -------------------------------------------------------------------------- |
|
430 // CCCAppMyCardListBoxModel::ClipFromBeginning |
|
431 // -------------------------------------------------------------------------- |
|
432 // |
|
433 TBool CCCAppMyCardListBoxModel::ClipFromBeginning(TDes& aBuffer, |
|
434 TInt aItemIndex, TInt aSubCellNumber) const |
|
435 { |
|
436 // TODO: This could be better. Model should not care about the |
|
437 // type of the listbox. |
|
438 CAknFormDoubleGraphicStyleListBox* listbox = |
|
439 static_cast<CAknFormDoubleGraphicStyleListBox*> (&iListBox); |
|
440 |
|
441 return AknTextUtils::ClipToFit( aBuffer, AknTextUtils::EClipFromBeginning, |
|
442 listbox, aItemIndex, aSubCellNumber ); |
|
443 } |
|
444 |
|
445 // -------------------------------------------------------------------------- |
|
446 // CCCAppMyCardListBoxModel::ExpandBuffersL |
|
447 // -------------------------------------------------------------------------- |
|
448 // |
|
449 void CCCAppMyCardListBoxModel::ExpandBuffersL(CCCAppMyCardListBoxRow* aRow) |
|
450 { |
|
451 // Row formatting buffer |
|
452 const TInt rowLength = aRow->TotalLength() + aRow->ColumnCount(); // for separator characters |
|
453 |
|
454 if( rowLength > iLineBuf->Des().MaxLength() ) |
|
455 { |
|
456 iLineBuf = iLineBuf->ReAllocL(rowLength); |
|
457 } |
|
458 |
|
459 ExpandColumnBufferL( aRow->MaxColumnLength() ); |
|
460 } |
|
461 |
|
462 // -------------------------------------------------------------------------- |
|
463 // CCCAppMyCardListBoxModel::ExpandColumnBufferL |
|
464 // -------------------------------------------------------------------------- |
|
465 // |
|
466 TPtr CCCAppMyCardListBoxModel::ExpandColumnBufferL(TInt aRequiredLength) |
|
467 { |
|
468 if( aRequiredLength > iColumnBuf->Des().MaxLength() ) |
|
469 { |
|
470 iColumnBuf = iColumnBuf->ReAllocL(aRequiredLength); |
|
471 } |
|
472 |
|
473 return iColumnBuf->Des(); |
|
474 } |
|
475 |
|
476 // -------------------------------------------------------------------------- |
|
477 // CCCAppMyCardListBoxModel::GetLabelLC |
|
478 // -------------------------------------------------------------------------- |
|
479 // |
|
480 HBufC* CCCAppMyCardListBoxModel::GetLabelLC( |
|
481 const CPbk2PresentationContactField& aField) |
|
482 { |
|
483 TPtr columnBuf( iColumnBuf->Des() ); |
|
484 columnBuf.Set( ExpandColumnBufferL(aField.FieldLabel().Length() ) ); |
|
485 columnBuf.Zero(); |
|
486 |
|
487 // replace listbox separator characters. |
|
488 Pbk2PresentationUtils::AppendAndReplaceChars( columnBuf, |
|
489 aField.FieldLabel(), KCharsToReplace, KReplacementChars ); |
|
490 |
|
491 // Replace characters that can not be displayed correctly |
|
492 Pbk2PresentationUtils::ReplaceNonGraphicCharacters( |
|
493 columnBuf, KReplacedChars ); |
|
494 |
|
495 HBufC* data = HBufC::NewLC( columnBuf.Length() ); |
|
496 data->Des().Append( columnBuf ); |
|
497 |
|
498 return data; |
|
499 } |
|
500 |
|
501 // End of File |
|