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