author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 68 | 9da50d567e3c |
parent 63 | f4a778e096c2 |
child 85 | 38bb213f60ba |
permissions | -rw-r--r-- |
63 | 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: Contact model class for MyCard |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <TPbk2StoreContactAnalyzer.h> |
|
68
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
19 |
#include <pbk2uicontrols.rsg> |
63 | 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 |
#include <MPbk2ClipListBoxText.h> |
|
27 |
#include <f32file.h> |
|
28 |
||
29 |
#include <CVPbkContactManager.h> |
|
30 |
#include <MVPbkContactLink.h> |
|
31 |
#include <MVPbkFieldType.h> |
|
32 |
#include <MVPbkContactFieldTextData.h> |
|
33 |
#include <MVPbkContactFieldUriData.h> |
|
34 |
#include <MVPbkContactFieldDateTimeData.h> |
|
35 |
#include <MVPbkContactFieldBinaryData.h> |
|
36 |
#include <MVPbkContactFieldData.h> |
|
37 |
#include <VPbkUtils.h> |
|
68
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
38 |
#include <vpbkeng.rsg> |
63 | 39 |
|
40 |
#include <aknlists.h> |
|
41 |
#include <avkon.rsg> |
|
42 |
||
43 |
#include "spbcontactdatamodelprivate.h" |
|
44 |
#include "spbcontactdatamodelrow.h" |
|
45 |
||
46 |
/// CONSTANTS |
|
47 |
namespace { |
|
48 |
||
49 |
/// Granularity of the row array |
|
50 |
const TInt KRowArrayGranularity = 4; |
|
51 |
||
52 |
/// Initial buffer size for temporary text buffers |
|
53 |
const TInt KBufferSize = 256; |
|
54 |
||
55 |
/// Disallowed characters in column text |
|
56 |
_LIT( KCharsToReplace, "\t" ); |
|
57 |
||
58 |
/// Replacement character for invalid or graphical column characters |
|
59 |
_LIT( KReplacementChars, " " ); |
|
60 |
const TText KReplacedChars = ' '; |
|
61 |
||
62 |
/// Content colum index |
|
63 |
const TInt KContentColumnIndex = 2; |
|
64 |
||
65 |
/// Column separator |
|
66 |
const TText KColumnSeparator = '\t'; |
|
67 |
||
68 |
}; |
|
69 |
||
70 |
// --------------------------------------------------------------------------- |
|
71 |
// CSpbContactDataModelPrivate::NewL |
|
72 |
// --------------------------------------------------------------------------- |
|
73 |
// |
|
74 |
CSpbContactDataModelPrivate* CSpbContactDataModelPrivate::NewL( |
|
75 |
CVPbkContactManager& aCntManager, |
|
76 |
CCoeEnv& aCoeEnv, |
|
77 |
TInt aFieldTypeSelectorRes, |
|
78 |
MPbk2ClipListBoxText* aClip ) |
|
79 |
{ |
|
80 |
CSpbContactDataModelPrivate* self = new (ELeave) CSpbContactDataModelPrivate( |
|
81 |
aCntManager, aCoeEnv, aFieldTypeSelectorRes, aClip ); |
|
82 |
CleanupStack::PushL(self); |
|
83 |
self->ConstructL(); |
|
84 |
CleanupStack::Pop(self); |
|
85 |
return self; |
|
86 |
} |
|
87 |
||
88 |
// --------------------------------------------------------------------------- |
|
89 |
// CSpbContactDataModelPrivate::~CSpbContactDataModelPrivate |
|
90 |
// --------------------------------------------------------------------------- |
|
91 |
// |
|
92 |
CSpbContactDataModelPrivate::~CSpbContactDataModelPrivate() |
|
93 |
{ |
|
94 |
iRows.ResetAndDestroy(); |
|
95 |
delete iLineBuf; |
|
96 |
delete iColumnBuf; |
|
97 |
iListIndxToPresentationIndx.Reset(); |
|
98 |
delete iImageBuffer; |
|
99 |
delete iImageFileName; |
|
100 |
delete iLastName; |
|
101 |
delete iFirstName; |
|
102 |
delete iContactLink; |
|
103 |
} |
|
104 |
||
105 |
// --------------------------------------------------------------------------- |
|
106 |
// CSpbContactDataModelPrivate::CSpbContactDataModelPrivate |
|
107 |
// --------------------------------------------------------------------------- |
|
108 |
// |
|
109 |
CSpbContactDataModelPrivate::CSpbContactDataModelPrivate( |
|
110 |
CVPbkContactManager& aCntManager, |
|
111 |
CCoeEnv& aCoeEnv, |
|
112 |
TInt aFieldTypeSelectorRes, |
|
113 |
MPbk2ClipListBoxText* aClip ) : |
|
114 |
iCoeEnv(aCoeEnv), |
|
115 |
iCntManager(aCntManager), |
|
116 |
iClip(aClip), |
|
117 |
iRows(KRowArrayGranularity), |
|
118 |
iFieldTypeRes(aFieldTypeSelectorRes) |
|
119 |
{ |
|
120 |
} |
|
121 |
||
122 |
// --------------------------------------------------------------------------- |
|
123 |
// CSpbContactDataModelPrivate::ConstructL |
|
124 |
// --------------------------------------------------------------------------- |
|
125 |
// |
|
126 |
void CSpbContactDataModelPrivate::ConstructL() |
|
127 |
{ |
|
128 |
iLineBuf = HBufC::NewL(KBufferSize); |
|
129 |
iColumnBuf = HBufC::NewL(KBufferSize); |
|
130 |
} |
|
131 |
||
132 |
// --------------------------------------------------------------------------- |
|
133 |
// CSpbContactDataModelPrivate::MdcaCount |
|
134 |
// --------------------------------------------------------------------------- |
|
135 |
// |
|
136 |
TInt CSpbContactDataModelPrivate::MdcaCount() const |
|
137 |
{ |
|
138 |
return iRows.Count(); |
|
139 |
} |
|
140 |
||
141 |
// --------------------------------------------------------------------------- |
|
142 |
// CSpbContactDataModelPrivate::MdcaPoint |
|
143 |
// --------------------------------------------------------------------------- |
|
144 |
// |
|
145 |
TPtrC CSpbContactDataModelPrivate::MdcaPoint(TInt aIndex) const |
|
146 |
{ |
|
147 |
TPtr rowText( iLineBuf->Des() ); |
|
148 |
rowText.Zero(); |
|
149 |
||
150 |
const CSpbContactDataModelRow& row = *iRows[aIndex]; |
|
151 |
const TInt columnCount = row.ColumnCount(); |
|
152 |
||
153 |
for( TInt index = 0; index < columnCount; ++index ) |
|
154 |
{ |
|
155 |
TPtr columnText( iColumnBuf->Des() ); |
|
156 |
columnText.Copy( row.At(index) ); |
|
157 |
||
158 |
// Clip the column if required |
|
159 |
if( index == KContentColumnIndex && |
|
160 |
row.IsClipRequired() && |
|
161 |
iClip ) |
|
162 |
{ |
|
163 |
iClip->ClipFromBeginning( columnText, aIndex, index ); |
|
164 |
} |
|
165 |
||
166 |
// Append the column and separator to the formatted row |
|
167 |
rowText.Append( columnText ); |
|
168 |
rowText.Append( KColumnSeparator ); |
|
169 |
} |
|
170 |
||
171 |
return rowText; |
|
172 |
} |
|
173 |
||
174 |
// --------------------------------------------------------------------------- |
|
175 |
// CSpbContactDataModelPrivate::PresentationFieldIndex |
|
176 |
// --------------------------------------------------------------------------- |
|
177 |
// |
|
178 |
TInt CSpbContactDataModelPrivate::PresentationFieldIndex( TInt aListIndex ) |
|
179 |
{ |
|
180 |
return iListIndxToPresentationIndx[ aListIndex ]; |
|
181 |
} |
|
182 |
||
183 |
// --------------------------------------------------------------------------- |
|
184 |
// CSpbContactDataModelPrivate::ListIndex |
|
185 |
// --------------------------------------------------------------------------- |
|
186 |
// |
|
187 |
TInt CSpbContactDataModelPrivate::ListIndex( TInt aPresentationIndex ) |
|
188 |
{ |
|
189 |
return iListIndxToPresentationIndx.Find( aPresentationIndex ); |
|
190 |
} |
|
191 |
||
192 |
// -------------------------------------------------------------------------- |
|
193 |
// CSpbContactDataModelPrivate::ExternalizeL |
|
194 |
// -------------------------------------------------------------------------- |
|
195 |
// |
|
196 |
void CSpbContactDataModelPrivate::ExternalizeL( RWriteStream& aStream ) const |
|
197 |
{ |
|
198 |
// write rows |
|
199 |
const TInt rowCount = iRows.Count(); |
|
200 |
aStream.WriteInt32L( rowCount ); |
|
201 |
for( TInt i = 0; i < rowCount; ++i ) |
|
202 |
{ |
|
203 |
iRows[i]->ExternalizeL( aStream ); |
|
204 |
} |
|
205 |
||
206 |
// write field indexes |
|
207 |
const TInt indxCount = iListIndxToPresentationIndx.Count(); |
|
208 |
aStream.WriteInt32L( indxCount ); |
|
209 |
for( TInt i = 0; i < indxCount; ++i ) |
|
210 |
{ |
|
211 |
aStream.WriteInt32L( iListIndxToPresentationIndx[i] ); |
|
212 |
} |
|
213 |
||
214 |
// write other data |
|
215 |
ExternalizeDataL( aStream, Text( CSpbContactDataModel::ETextFirstName ) ); |
|
216 |
ExternalizeDataL( aStream, Text( CSpbContactDataModel::ETextLastName ) ); |
|
217 |
ExternalizeDataL( aStream, Text( CSpbContactDataModel::ETextImageFileName ) ); |
|
218 |
ExternalizeDataL( aStream, Data( CSpbContactDataModel::EDataImageContent ) ); |
|
219 |
||
220 |
if( iContactLink ) |
|
221 |
{ |
|
222 |
aStream.WriteInt8L( ETrue ); |
|
223 |
HBufC8* link = iContactLink->PackLC(); |
|
224 |
aStream.WriteL( *link ); |
|
225 |
CleanupStack::PopAndDestroy( link ); |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
aStream.WriteInt8L( EFalse ); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
// -------------------------------------------------------------------------- |
|
234 |
// CSpbContactDataModelPrivate::InternalizeL |
|
235 |
// -------------------------------------------------------------------------- |
|
236 |
// |
|
237 |
void CSpbContactDataModelPrivate::InternalizeL( RReadStream& aStream ) |
|
238 |
{ |
|
239 |
Reset(); |
|
240 |
||
241 |
// read rows |
|
242 |
const TInt count = aStream.ReadInt32L(); |
|
243 |
for( TInt i = 0; i < count; ++i ) |
|
244 |
{ |
|
245 |
CSpbContactDataModelRow* row = CSpbContactDataModelRow::NewL(); |
|
246 |
CleanupStack::PushL( row ); |
|
247 |
row->InternalizeL( aStream ); |
|
248 |
iRows.AppendL( row ); |
|
249 |
CleanupStack::Pop( row ); |
|
250 |
ExpandBuffersL( row ); |
|
251 |
} |
|
252 |
||
253 |
// read field indexes |
|
254 |
const TInt indxCount = aStream.ReadInt32L(); |
|
255 |
for( TInt i = 0; i < indxCount; ++i ) |
|
256 |
{ |
|
257 |
iListIndxToPresentationIndx.AppendL( aStream.ReadInt32L() ); |
|
258 |
} |
|
259 |
||
260 |
// read other data |
|
261 |
InternalizeDataL( aStream, iFirstName ); |
|
262 |
InternalizeDataL( aStream, iLastName ); |
|
263 |
InternalizeDataL( aStream, iImageFileName ); |
|
264 |
InternalizeDataL( aStream, iImageBuffer ); |
|
265 |
||
266 |
// read contact link if provided |
|
267 |
if( aStream.ReadInt8L() ) |
|
268 |
{ |
|
269 |
CVPbkContactLinkArray* links = |
|
270 |
CVPbkContactLinkArray::NewLC( aStream, iCntManager.ContactStoresL() ); |
|
271 |
if( links->Count() ) |
|
272 |
{ |
|
273 |
// only first link used |
|
274 |
delete iContactLink; |
|
275 |
iContactLink = NULL; |
|
276 |
iContactLink = links->At( 0 ).CloneLC(); |
|
277 |
CleanupStack::Pop(); // link |
|
278 |
} |
|
279 |
CleanupStack::PopAndDestroy( links ); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
// -------------------------------------------------------------------------- |
|
284 |
// CSpbContactDataModelPrivate::SetDataL |
|
285 |
// -------------------------------------------------------------------------- |
|
286 |
// |
|
287 |
void CSpbContactDataModelPrivate::SetDataL( |
|
288 |
const CPbk2PresentationContact& aContact, |
|
289 |
const CPbk2IconArray* aIconArray ) |
|
290 |
{ |
|
291 |
Reset(); |
|
292 |
||
293 |
// save link |
|
294 |
MVPbkContactLink* link = aContact.CreateLinkLC(); |
|
295 |
delete iContactLink; |
|
296 |
iContactLink = link; |
|
297 |
CleanupStack::Pop(); // link |
|
298 |
||
299 |
const CPbk2PresentationContactFieldCollection& fields = |
|
300 |
aContact.PresentationFields(); |
|
301 |
const TInt fieldCount = fields.FieldCount(); |
|
302 |
const TInt count1 = fields.ParentStoreContact().Fields().FieldCount(); |
|
303 |
for (TInt index = 0; index < fieldCount; index++) |
|
304 |
{ |
|
305 |
CPbk2PresentationContactField& field = fields.At(index); |
|
306 |
const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
307 |
||
308 |
// Get master field type list and match field's type against it |
|
309 |
const MVPbkFieldType* fieldType = VPbkUtils::MatchFieldType( |
|
310 |
iCntManager.FieldTypes(), field ); |
|
311 |
TInt typeRes = fieldType->FieldTypeResId(); |
|
312 |
||
313 |
// Handle special field types |
|
314 |
switch( typeRes ) |
|
315 |
{ |
|
316 |
case R_VPBK_FIELD_TYPE_THUMBNAILPIC: |
|
317 |
{ |
|
318 |
delete iImageBuffer; |
|
319 |
iImageBuffer = NULL; |
|
320 |
iImageBuffer = MVPbkContactFieldBinaryData::Cast(fieldData).BinaryData().AllocL(); |
|
321 |
break; |
|
322 |
} |
|
323 |
case R_VPBK_FIELD_TYPE_CALLEROBJIMG: |
|
324 |
{ |
|
325 |
delete iImageFileName; |
|
326 |
iImageFileName = NULL; |
|
327 |
iImageFileName = MVPbkContactFieldTextData::Cast(fieldData).Text().AllocL(); |
|
328 |
break; |
|
329 |
} |
|
330 |
case R_VPBK_FIELD_TYPE_FIRSTNAME: |
|
331 |
{ |
|
332 |
delete iFirstName; |
|
333 |
iFirstName = NULL; |
|
334 |
iFirstName = MVPbkContactFieldTextData::Cast(fieldData).Text().AllocL(); |
|
335 |
break; |
|
336 |
} |
|
337 |
case R_VPBK_FIELD_TYPE_LASTNAME: |
|
338 |
{ |
|
339 |
delete iLastName; |
|
340 |
iLastName = NULL; |
|
341 |
iLastName = MVPbkContactFieldTextData::Cast(fieldData).Text().AllocL(); |
|
342 |
break; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
// Handle details list fields |
|
347 |
if( field.IsEditable() && fieldType && !IsHiddenField(fieldType) ) |
|
348 |
{ |
|
349 |
HBufC* label = GetLabelLC( field ); |
|
350 |
||
351 |
if( label->Length() ) |
|
352 |
{ |
|
353 |
CSpbContactDataModelRow* row = |
|
354 |
CSpbContactDataModelRow::NewL(); |
|
355 |
CleanupStack::PushL(row); |
|
356 |
||
357 |
// Add icon |
|
358 |
TBuf<20> buffer; // 20 should be enough for icon index |
|
359 |
const TPbk2IconId& icon = field.FieldProperty().IconId(); |
|
360 |
if( aIconArray ) |
|
361 |
{ |
|
362 |
TInt iconIndex = aIconArray->FindIcon( icon ); |
|
363 |
if( iconIndex != KErrNotFound) |
|
364 |
{ |
|
365 |
buffer.AppendNum(iconIndex); |
|
366 |
} |
|
367 |
} |
|
368 |
row->SetIcon( icon ); |
|
369 |
row->AppendColumnL(buffer); |
|
370 |
||
371 |
// add label. |
|
372 |
row->AppendColumnL(*label); |
|
373 |
||
374 |
// Add current index to Presentation Contact index array |
|
375 |
iListIndxToPresentationIndx.AppendL( index ); |
|
376 |
||
377 |
// add field content. |
|
378 |
switch (fieldData.DataType() ) |
|
379 |
{ |
|
380 |
case EVPbkFieldStorageTypeText: |
|
381 |
{ |
|
382 |
HandleTextTypeFieldL( *fieldType, fieldData, row); |
|
383 |
break; |
|
384 |
} |
|
385 |
case EVPbkFieldStorageTypeDateTime: |
|
386 |
{ |
|
387 |
HandleDateTimeTypeFieldL(fieldData, row); |
|
388 |
break; |
|
389 |
} |
|
390 |
case EVPbkFieldStorageTypeUri: |
|
391 |
{ |
|
392 |
HandleUriTypeFieldL( *fieldType, fieldData, row); |
|
393 |
break; |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
// Expand row formatting buffer if required |
|
398 |
ExpandBuffersL(row); |
|
399 |
||
400 |
// Add the row if data ok to show to user. |
|
401 |
iRows.AppendL(row); |
|
402 |
CleanupStack::Pop(row); |
|
403 |
} |
|
404 |
||
405 |
CleanupStack::PopAndDestroy(label); |
|
406 |
} |
|
407 |
} // for |
|
408 |
} |
|
409 |
||
410 |
// -------------------------------------------------------------------------- |
|
411 |
// CSpbContactDataModelPrivate::ContactLink |
|
412 |
// -------------------------------------------------------------------------- |
|
413 |
// |
|
414 |
MVPbkContactLink* CSpbContactDataModelPrivate::ContactLink() |
|
415 |
{ |
|
416 |
return iContactLink; |
|
417 |
} |
|
418 |
||
419 |
// -------------------------------------------------------------------------- |
|
420 |
// CSpbContactDataModelPrivate::IsEmpty |
|
421 |
// -------------------------------------------------------------------------- |
|
422 |
// |
|
423 |
TBool CSpbContactDataModelPrivate::IsEmpty() |
|
424 |
{ |
|
425 |
return !iImageBuffer && !iImageFileName && |
|
426 |
!iFirstName && !iLastName && iRows.Count() == 0; |
|
427 |
} |
|
428 |
||
429 |
// -------------------------------------------------------------------------- |
|
430 |
// CSpbContactDataModelPrivate::IsHiddenField |
|
431 |
// -------------------------------------------------------------------------- |
|
432 |
// |
|
433 |
TBool CSpbContactDataModelPrivate::IsHiddenField(const MVPbkFieldType* aFieldType) |
|
434 |
{ |
|
435 |
TInt resId = aFieldType->FieldTypeResId(); |
|
436 |
return ( resId == R_VPBK_FIELD_TYPE_SYNCCLASS ); |
|
437 |
} |
|
438 |
||
439 |
// --------------------------------------------------------------------------- |
|
440 |
// CSpbContactDataModelPrivate::IsFieldTypeL |
|
441 |
// --------------------------------------------------------------------------- |
|
442 |
// |
|
443 |
TBool CSpbContactDataModelPrivate::IsFieldTypeL( |
|
444 |
const MVPbkFieldType& aFieldType, TInt aSelectorResId ) |
|
445 |
{ |
|
446 |
TPbk2StoreContactAnalyzer analyzer( iCntManager, NULL ); |
|
447 |
return analyzer.IsFieldTypeIncludedL( aFieldType, aSelectorResId ); |
|
448 |
} |
|
449 |
||
450 |
// --------------------------------------------------------------------------- |
|
451 |
// CSpbContactDataModelPrivate::HandleTextTypeFieldL |
|
452 |
// --------------------------------------------------------------------------- |
|
453 |
// |
|
454 |
void CSpbContactDataModelPrivate::HandleTextTypeFieldL( |
|
455 |
const MVPbkFieldType& aFieldType, |
|
456 |
const MVPbkContactFieldData& aFieldData, |
|
457 |
CSpbContactDataModelRow* aRow ) |
|
458 |
{ |
|
459 |
// Check if clipping is required |
|
460 |
if( IsFieldTypeL( aFieldType, iFieldTypeRes ) ) |
|
461 |
{ |
|
462 |
aRow->SetClipRequired( ETrue ); |
|
463 |
} |
|
464 |
||
465 |
TPtrC fieldText = MVPbkContactFieldTextData::Cast(aFieldData).Text(); |
|
466 |
TInt resId = aFieldType.FieldTypeResId(); |
|
467 |
HBufC* defaultText = NULL; |
|
468 |
if( resId == R_VPBK_FIELD_TYPE_CALLEROBJIMG ) |
|
469 |
{ |
|
470 |
RFs& fs = iCoeEnv.FsSession(); |
|
471 |
TEntry entry; |
|
472 |
if ( fs.Entry( fieldText, entry) == KErrNone ) |
|
473 |
{ |
|
474 |
// get image name |
|
475 |
TParse parse; |
|
476 |
parse.Set(fieldText, NULL, NULL); |
|
477 |
fieldText.Set(parse.Name()); |
|
478 |
||
479 |
} |
|
480 |
else |
|
481 |
{ |
|
482 |
// use default image name |
|
483 |
defaultText = iCoeEnv.AllocReadResourceLC( R_QTN_PHOB_FIELD_THUMBNAIL ); |
|
484 |
fieldText.Set( defaultText->Des() ); |
|
485 |
} |
|
486 |
} |
|
487 |
TPtr columnBuf( ExpandColumnBufferL( fieldText.Length() ) ); |
|
488 |
columnBuf.Zero(); |
|
489 |
||
490 |
// replace listbox separator characters. |
|
491 |
Pbk2PresentationUtils::AppendAndReplaceChars( columnBuf, fieldText, |
|
492 |
KCharsToReplace, KReplacementChars ); |
|
493 |
if( defaultText ) |
|
494 |
{ |
|
495 |
CleanupStack::PopAndDestroy( defaultText ); |
|
496 |
} |
|
497 |
// Replace characters that can not be displayed correctly. |
|
498 |
Pbk2PresentationUtils::ReplaceNonGraphicCharacters( columnBuf, KReplacedChars ); |
|
499 |
||
500 |
aRow->AppendColumnL( columnBuf ); |
|
501 |
} |
|
502 |
||
503 |
// --------------------------------------------------------------------------- |
|
504 |
// CSpbContactDataModelPrivate::HandleDateTimeTypeFieldL |
|
505 |
// --------------------------------------------------------------------------- |
|
506 |
// |
|
507 |
void CSpbContactDataModelPrivate::HandleDateTimeTypeFieldL( |
|
508 |
const MVPbkContactFieldData& aFieldData, CSpbContactDataModelRow* aRow) |
|
509 |
{ |
|
510 |
const MVPbkContactFieldDateTimeData& date = |
|
511 |
MVPbkContactFieldDateTimeData::Cast(aFieldData); |
|
512 |
||
513 |
HBufC* dateFormat = |
|
514 |
iCoeEnv.AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
515 |
||
516 |
TLocale locale; |
|
517 |
TBuf<64> dateBuffer; |
|
518 |
TTime time( date.DateTime() ); |
|
519 |
time.FormatL( dateBuffer, *dateFormat, locale ); |
|
520 |
CleanupStack::PopAndDestroy( dateFormat ); |
|
521 |
||
522 |
aRow->AppendColumnL( dateBuffer ); |
|
523 |
} |
|
524 |
||
525 |
// --------------------------------------------------------------------------- |
|
526 |
// CSpbContactDataModelPrivate::HandleUriTypeFieldL |
|
527 |
// --------------------------------------------------------------------------- |
|
528 |
// |
|
529 |
void CSpbContactDataModelPrivate::HandleUriTypeFieldL( |
|
530 |
const MVPbkFieldType& aFieldType, |
|
531 |
const MVPbkContactFieldData& aFieldData, CSpbContactDataModelRow* aRow) |
|
532 |
{ |
|
533 |
if ( IsFieldTypeL( aFieldType, iFieldTypeRes ) ) |
|
534 |
{ |
|
535 |
aRow->SetClipRequired( ETrue ); |
|
536 |
} |
|
537 |
||
538 |
TPtrC uri = MVPbkContactFieldUriData::Cast( aFieldData ).Text(); |
|
539 |
TPtr columnBuf( ExpandColumnBufferL( uri.Length() ) ); |
|
540 |
columnBuf.Copy( uri ); |
|
541 |
||
542 |
// Replace characters that can not be displayed correctly. |
|
543 |
Pbk2PresentationUtils::ReplaceNonGraphicCharacters( columnBuf, KReplacedChars ); |
|
544 |
||
545 |
aRow->AppendColumnL( columnBuf ); |
|
546 |
} |
|
547 |
||
548 |
// -------------------------------------------------------------------------- |
|
549 |
// CSpbContactDataModelPrivate::ExpandBuffersL |
|
550 |
// -------------------------------------------------------------------------- |
|
551 |
// |
|
552 |
void CSpbContactDataModelPrivate::ExpandBuffersL(CSpbContactDataModelRow* aRow) |
|
553 |
{ |
|
554 |
// Row formatting buffer |
|
555 |
const TInt rowLength = aRow->TotalLength() + aRow->ColumnCount(); // for separator characters |
|
556 |
||
557 |
if( rowLength > iLineBuf->Des().MaxLength() ) |
|
558 |
{ |
|
559 |
iLineBuf = iLineBuf->ReAllocL(rowLength); |
|
560 |
} |
|
561 |
||
562 |
ExpandColumnBufferL( aRow->MaxColumnLength() ); |
|
563 |
} |
|
564 |
||
565 |
// -------------------------------------------------------------------------- |
|
566 |
// CSpbContactDataModelPrivate::ExpandColumnBufferL |
|
567 |
// -------------------------------------------------------------------------- |
|
568 |
// |
|
569 |
TPtr CSpbContactDataModelPrivate::ExpandColumnBufferL(TInt aRequiredLength) |
|
570 |
{ |
|
571 |
if( aRequiredLength > iColumnBuf->Des().MaxLength() ) |
|
572 |
{ |
|
573 |
iColumnBuf = iColumnBuf->ReAllocL(aRequiredLength); |
|
574 |
} |
|
575 |
||
576 |
return iColumnBuf->Des(); |
|
577 |
} |
|
578 |
||
579 |
// -------------------------------------------------------------------------- |
|
580 |
// CSpbContactDataModelPrivate::Reset |
|
581 |
// -------------------------------------------------------------------------- |
|
582 |
// |
|
583 |
void CSpbContactDataModelPrivate::Reset() |
|
584 |
{ |
|
585 |
iRows.ResetAndDestroy(); |
|
586 |
iListIndxToPresentationIndx.Reset(); |
|
587 |
||
588 |
delete iImageBuffer; |
|
589 |
iImageBuffer = NULL; |
|
590 |
delete iImageFileName; |
|
591 |
iImageFileName = NULL; |
|
592 |
delete iLastName; |
|
593 |
iLastName = NULL; |
|
594 |
delete iFirstName; |
|
595 |
iFirstName = NULL; |
|
596 |
delete iContactLink; |
|
597 |
iContactLink = NULL; |
|
598 |
} |
|
599 |
||
600 |
// -------------------------------------------------------------------------- |
|
601 |
// CSpbContactDataModelPrivate::Text |
|
602 |
// -------------------------------------------------------------------------- |
|
603 |
// |
|
604 |
TPtrC CSpbContactDataModelPrivate::Text( |
|
605 |
CSpbContactDataModel::TTextTypes aType ) const |
|
606 |
{ |
|
607 |
switch( aType ) |
|
608 |
{ |
|
609 |
case CSpbContactDataModel::ETextImageFileName: |
|
610 |
{ |
|
611 |
return iImageFileName ? *iImageFileName : KNullDesC(); |
|
612 |
} |
|
613 |
case CSpbContactDataModel::ETextFirstName: |
|
614 |
{ |
|
615 |
return iFirstName ? *iFirstName : KNullDesC(); |
|
616 |
} |
|
617 |
case CSpbContactDataModel::ETextLastName: |
|
618 |
{ |
|
619 |
return iLastName ? *iLastName : KNullDesC(); |
|
620 |
} |
|
621 |
} |
|
622 |
return KNullDesC(); |
|
623 |
} |
|
624 |
||
625 |
// -------------------------------------------------------------------------- |
|
626 |
// CSpbContactDataModelPrivate::Data |
|
627 |
// -------------------------------------------------------------------------- |
|
628 |
// |
|
629 |
TPtrC8 CSpbContactDataModelPrivate::Data( |
|
630 |
CSpbContactDataModel::TBinaryTypes aType ) const |
|
631 |
{ |
|
632 |
switch( aType ) |
|
633 |
{ |
|
634 |
case CSpbContactDataModel::EDataImageContent: |
|
635 |
{ |
|
636 |
return iImageBuffer ? *iImageBuffer : KNullDesC8(); |
|
637 |
} |
|
638 |
} |
|
639 |
return KNullDesC8(); |
|
640 |
} |
|
641 |
||
642 |
// -------------------------------------------------------------------------- |
|
643 |
// CSpbContactDataModelPrivate::UpdateIconsL |
|
644 |
// -------------------------------------------------------------------------- |
|
645 |
// |
|
646 |
void CSpbContactDataModelPrivate::UpdateIconsL( const CPbk2IconArray& aIconArray ) |
|
647 |
{ |
|
648 |
// locate and set icon indexes for new icon array |
|
649 |
const TInt count = iRows.Count(); |
|
650 |
for( TInt i = 0; i < count; ++i ) |
|
651 |
{ |
|
652 |
// find and set icon indexes according to current icon array |
|
653 |
CSpbContactDataModelRow* row = iRows[i]; |
|
654 |
if( row->ColumnCount() ) |
|
655 |
{ |
|
656 |
TInt index = aIconArray.FindIcon( row->Icon() ); |
|
657 |
if( index != KErrNotFound ) |
|
658 |
{ |
|
659 |
TBuf<20> buf; |
|
660 |
buf.Num( index ); |
|
661 |
row->ReplaceColumnL( 0, buf ); |
|
662 |
} |
|
663 |
} |
|
664 |
} |
|
665 |
} |
|
666 |
||
667 |
// -------------------------------------------------------------------------- |
|
668 |
// CSpbContactDataModelPrivate::SetClipListBoxText |
|
669 |
// -------------------------------------------------------------------------- |
|
670 |
// |
|
671 |
void CSpbContactDataModelPrivate::SetClipListBoxText( MPbk2ClipListBoxText* aClip ) |
|
672 |
{ |
|
673 |
iClip = aClip; |
|
674 |
} |
|
675 |
||
676 |
// -------------------------------------------------------------------------- |
|
677 |
// CSpbContactDataModelPrivate::GetLabelLC |
|
678 |
// -------------------------------------------------------------------------- |
|
679 |
// |
|
680 |
HBufC* CSpbContactDataModelPrivate::GetLabelLC( |
|
681 |
const CPbk2PresentationContactField& aField) |
|
682 |
{ |
|
683 |
TPtr columnBuf( ExpandColumnBufferL( aField.FieldLabel().Length() ) ); |
|
684 |
columnBuf.Zero(); |
|
685 |
||
686 |
// replace listbox separator characters. |
|
687 |
Pbk2PresentationUtils::AppendAndReplaceChars( columnBuf, |
|
688 |
aField.FieldLabel(), KCharsToReplace, KReplacementChars ); |
|
689 |
||
690 |
// Replace characters that can not be displayed correctly |
|
691 |
Pbk2PresentationUtils::ReplaceNonGraphicCharacters( |
|
692 |
columnBuf, KReplacedChars ); |
|
693 |
||
694 |
HBufC* data = HBufC::NewLC( columnBuf.Length() ); |
|
695 |
data->Des().Append( columnBuf ); |
|
696 |
||
697 |
return data; |
|
698 |
} |
|
699 |
||
700 |
// -------------------------------------------------------------------------- |
|
701 |
// CSpbContactDataModelPrivate::ExternalizeDataL |
|
702 |
// -------------------------------------------------------------------------- |
|
703 |
// |
|
704 |
void CSpbContactDataModelPrivate::ExternalizeDataL( |
|
705 |
RWriteStream& aStream, const TDesC8& aData ) const |
|
706 |
{ |
|
707 |
const TInt length = aData.Length(); |
|
708 |
aStream.WriteInt32L( length ); |
|
709 |
if( length ) |
|
710 |
{ |
|
711 |
aStream.WriteL( aData, length ); |
|
712 |
} |
|
713 |
} |
|
714 |
||
715 |
// -------------------------------------------------------------------------- |
|
716 |
// CSpbContactDataModelPrivate::ExternalizeDataL |
|
717 |
// -------------------------------------------------------------------------- |
|
718 |
// |
|
719 |
void CSpbContactDataModelPrivate::ExternalizeDataL( |
|
720 |
RWriteStream& aStream, const TDesC16& aData ) const |
|
721 |
{ |
|
722 |
const TInt length = aData.Length(); |
|
723 |
aStream.WriteInt32L( length ); |
|
724 |
if( length ) |
|
725 |
{ |
|
726 |
aStream.WriteL( aData, length ); |
|
727 |
} |
|
728 |
} |
|
729 |
||
730 |
// -------------------------------------------------------------------------- |
|
731 |
// CSpbContactDataModelPrivate::InternalizeDataL |
|
732 |
// -------------------------------------------------------------------------- |
|
733 |
// |
|
734 |
void CSpbContactDataModelPrivate::InternalizeDataL( RReadStream& aStream, HBufC8*& aData ) |
|
735 |
{ |
|
736 |
const TInt length = aStream.ReadInt32L(); |
|
737 |
HBufC8* buf = NULL; |
|
738 |
if( length ) |
|
739 |
{ |
|
740 |
buf = HBufC8::NewLC( length ); |
|
741 |
TPtr8 ptr( buf->Des() ); |
|
742 |
aStream.ReadL( ptr, length ); |
|
743 |
CleanupStack::Pop( buf ); |
|
744 |
} |
|
745 |
delete aData; |
|
746 |
aData = buf; |
|
747 |
} |
|
748 |
||
749 |
// -------------------------------------------------------------------------- |
|
750 |
// CSpbContactDataModelPrivate::InternalizeDataL |
|
751 |
// -------------------------------------------------------------------------- |
|
752 |
// |
|
753 |
void CSpbContactDataModelPrivate::InternalizeDataL( RReadStream& aStream, HBufC16*& aData ) |
|
754 |
{ |
|
755 |
const TInt length = aStream.ReadInt32L(); |
|
756 |
HBufC16* buf = NULL; |
|
757 |
if( length ) |
|
758 |
{ |
|
759 |
buf = HBufC16::NewLC( length ); |
|
760 |
TPtr16 ptr( buf->Des() ); |
|
761 |
aStream.ReadL( ptr, length ); |
|
762 |
CleanupStack::Pop( buf ); |
|
763 |
} |
|
764 |
delete aData; |
|
765 |
aData = buf; |
|
766 |
} |
|
767 |
||
768 |
// End of File |