phonebookui/Phonebook2/UIControls/src/CPbk2FieldListBoxModel.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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     
       
   475     if ( analyzer.IsFieldTypeIncludedL( aField, R_PHONEBOOK2_PHONENUMBER_SELECTOR )
       
   476             || analyzer.IsFieldTypeIncludedL ( aField, R_PHONEBOOK2_EMAIL_SELECTOR )
       
   477             || analyzer.IsFieldTypeIncludedL( aField, R_PHONEBOOK2_SIP_SELECTOR )
       
   478             || analyzer.IsFieldTypeIncludedL( aField, R_PHONEBOOK2_IMPP_SELECTOR ) )
       
   479         {
       
   480         iTextClipper->ClipFromBeginning( aColumnText, aIndex, aColumnIndex );
       
   481         }
       
   482     }
       
   483 
       
   484 // --------------------------------------------------------------------------
       
   485 // CPbk2FieldListBoxModel::AppendFieldLabelL
       
   486 // Appends field label. Removes any listbox separator characters.
       
   487 // --------------------------------------------------------------------------
       
   488 //
       
   489 inline void CPbk2FieldListBoxModel::AppendFieldLabelL
       
   490         ( const CPbk2PresentationContactField& aField,
       
   491         CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf )
       
   492     {
       
   493     aColumnBuf.Set( ExpandColumnBufferL( aField.FieldLabel().Length() ) );
       
   494     aColumnBuf.Zero();
       
   495     Pbk2PresentationUtils::AppendAndReplaceChars
       
   496         ( aColumnBuf, aField.FieldLabel(),
       
   497         KCharsToReplace, KReplacementChars );
       
   498     // Replace characters that can not be displayed correctly
       
   499     Pbk2PresentationUtils::ReplaceNonGraphicCharacters
       
   500         ( aColumnBuf, ' ' );
       
   501     aRow.AppendColumnL( aColumnBuf );
       
   502     }
       
   503 
       
   504 // --------------------------------------------------------------------------
       
   505 // CPbk2FieldListBoxModel::AppendAddressFieldLabelL
       
   506 // Appends field label. Removes any listbox separator characters.
       
   507 // --------------------------------------------------------------------------
       
   508 //
       
   509 inline void CPbk2FieldListBoxModel::AppendAddressFieldLabelL
       
   510         ( const CPbk2PresentationContactField& aField,
       
   511         CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf )
       
   512     {
       
   513     aColumnBuf.Set( ExpandColumnBufferL( aField.FieldLabel().Length() ) );
       
   514     aColumnBuf.Zero();
       
   515     TBool address = EFalse;
       
   516 
       
   517     const TInt countProperties =
       
   518         aField.FieldProperty().FieldType().VersitProperties().Count();
       
   519     TArray<TVPbkFieldVersitProperty> props =
       
   520         aField.FieldProperty().FieldType().VersitProperties();
       
   521     for ( TInt i = 0; i < countProperties; ++i )
       
   522         {
       
   523         if ( props[ i ].Name() == EVPbkVersitNameADR
       
   524         		&& props[ i ].Parameters().Contains( EVPbkVersitParamHOME ) )
       
   525         	{
       
   526         	HBufC* label =
       
   527         	    StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_HOME );
       
   528         	Pbk2PresentationUtils::AppendAndReplaceChars
       
   529         	    ( aColumnBuf, *label,
       
   530         	    KCharsToReplace, KReplacementChars );
       
   531         	CleanupStack::PopAndDestroy( label );
       
   532         	address = ETrue;
       
   533         	}
       
   534         else if ( props[ i ].Name() == EVPbkVersitNameADR
       
   535         		&& props[ i ].Parameters().Contains( EVPbkVersitParamWORK ) )
       
   536         	{
       
   537         	HBufC* label =
       
   538         	    StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_WORK );
       
   539         	Pbk2PresentationUtils::AppendAndReplaceChars
       
   540         	    ( aColumnBuf, *label,
       
   541         	    KCharsToReplace, KReplacementChars );
       
   542         	CleanupStack::PopAndDestroy( label );
       
   543         	address = ETrue;
       
   544         	}
       
   545         else if ( props[ i ].Name() == EVPbkVersitNameADR
       
   546         		&& !( props[ i ].Parameters().Contains( EVPbkVersitParamHOME ) )
       
   547         		&& !( props[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) )
       
   548         	{
       
   549         	HBufC* label = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS );
       
   550         	Pbk2PresentationUtils::AppendAndReplaceChars
       
   551         	    ( aColumnBuf, *label,
       
   552         	    KCharsToReplace, KReplacementChars );
       
   553         	CleanupStack::PopAndDestroy( label );
       
   554         	address = ETrue;
       
   555         	}
       
   556         }
       
   557 
       
   558     // Replace characters that can not be displayed correctly
       
   559     Pbk2PresentationUtils::ReplaceNonGraphicCharacters
       
   560         ( aColumnBuf, ' ' );
       
   561     aRow.AppendColumnL( aColumnBuf );
       
   562     }
       
   563 
       
   564 // --------------------------------------------------------------------------
       
   565 // CPbk2FieldListBoxModel::AppendFieldContentL
       
   566 // Appends field content.
       
   567 // --------------------------------------------------------------------------
       
   568 //
       
   569 inline void CPbk2FieldListBoxModel::AppendFieldContentL
       
   570         ( const CPbk2PresentationContactField& aField,
       
   571         const MVPbkFieldType& aFieldType,
       
   572         CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf )
       
   573     {
       
   574     TPtrC fieldText( iFieldFormatter->FormatFieldContentL
       
   575         ( aField, aFieldType ) );
       
   576     aColumnBuf.Set( ExpandColumnBufferL( fieldText.Length() ) );
       
   577     aColumnBuf.Zero();
       
   578     Pbk2PresentationUtils::AppendAndReplaceChars
       
   579         ( aColumnBuf, fieldText, KCharsToReplace, KReplacementChars );
       
   580     // Replace characters that can not be displayed correctly
       
   581     Pbk2PresentationUtils::ReplaceNonGraphicCharacters
       
   582         (aColumnBuf, ' ');
       
   583     aRow.AppendColumnL( aColumnBuf );
       
   584     }
       
   585 
       
   586 // --------------------------------------------------------------------------
       
   587 // CPbk2FieldListBoxModel::AppendAddressFieldContentL
       
   588 // Appends field content.
       
   589 // --------------------------------------------------------------------------
       
   590 //
       
   591 inline void CPbk2FieldListBoxModel::AppendAddressFieldContentL
       
   592         ( const CPbk2PresentationContactField& aField,
       
   593         CPbk2FieldListBoxRow& aRow, TPtr& aColumnBuf )
       
   594     {
       
   595     TPbk2FieldGroupId address = EPbk2FieldGroupIdNone;
       
   596     const TInt countFieldProps =
       
   597         aField.FieldProperty().FieldType().VersitProperties().Count();
       
   598     TArray<TVPbkFieldVersitProperty> fieldProps =
       
   599         aField.FieldProperty().FieldType().VersitProperties();
       
   600     for ( TInt i = 0; i < countFieldProps; ++i )
       
   601     	{
       
   602     	if ( fieldProps[ i ].Name() == EVPbkVersitNameADR )
       
   603     		{
       
   604     		if ( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamHOME ) )
       
   605     			{
       
   606     			address = EPbk2FieldGroupIdHomeAddress;
       
   607     			}
       
   608     		else if ( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamWORK ) )
       
   609     			{
       
   610     			address = EPbk2FieldGroupIdCompanyAddress;
       
   611     			}
       
   612     		else if ( !( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamHOME ) )
       
   613     				&& !( fieldProps[ i ].Parameters().Contains( EVPbkVersitParamWORK ) ) )
       
   614     			{
       
   615     			address = EPbk2FieldGroupIdPostalAddress;
       
   616     			}
       
   617     		}
       
   618     	}
       
   619     if ( address )
       
   620     	{
       
   621     	RBuf text;
       
   622     	Pbk2AddressTools::GetAddressShortPreviewLC(
       
   623     		static_cast<MVPbkStoreContact&>(
       
   624     			aField.ParentContact() ), address, text );
       
   625     	HBufC* buffer = HBufC::NewLC( text.Length() );
       
   626     	TPtr textFormatted ( buffer->Des() );
       
   627     	Pbk2PresentationUtils::AppendWithNewlineTranslationL
       
   628     	    ( textFormatted, text );
       
   629     	aColumnBuf.Set( ExpandColumnBufferL( textFormatted.Length() ) );
       
   630     	aColumnBuf.Zero();
       
   631     	Pbk2PresentationUtils::AppendAndReplaceChars
       
   632     	    ( aColumnBuf, textFormatted, KCharsToReplace, KReplacementChars );
       
   633     	CleanupStack::PopAndDestroy( buffer );
       
   634     	CleanupStack::PopAndDestroy( &text );	// text
       
   635     	// Replace characters that can not be displayed correctly
       
   636     	Pbk2PresentationUtils::ReplaceNonGraphicCharacters
       
   637     	    (aColumnBuf, ' ');
       
   638     	aRow.AppendColumnL( aColumnBuf );
       
   639     	}
       
   640     }
       
   641 
       
   642 // --------------------------------------------------------------------------
       
   643 // CPbk2FieldListBoxModel::AppendIconsToBeginningL
       
   644 // Adds icons to the beginning.
       
   645 // --------------------------------------------------------------------------
       
   646 //
       
   647 inline void CPbk2FieldListBoxModel::AppendIconsToBeginningL
       
   648         ( const CPbk2PresentationContactField& aField,
       
   649           const MVPbkFieldType& aFieldType,
       
   650           CPbk2FieldListBoxRow& aRow, TParams& aParams )
       
   651     {
       
   652     // Format icon index
       
   653     TBuf<KMaxFormattedTIntLength> iconText; 
       
   654     
       
   655     // appened presence icon for xSP field
       
   656     TInt iconIndex = KErrNotFound;
       
   657     if ( iPresenceIconsPos != NULL && 
       
   658          aFieldType.FieldTypeResId() == R_VPBK_FIELD_TYPE_IMPP )
       
   659         {
       
   660         TPtrC fieldText( iFieldFormatter->FormatFieldContentL
       
   661             ( aField, aFieldType ) );
       
   662         TInt count = iPresenceIconsPos->Count();
       
   663         for ( TInt i = 0; i < count && iconIndex == KErrNotFound; i++ )
       
   664             {
       
   665 				if ( !(fieldText.CompareF( iPresenceIconsPos->operator[](i).
       
   666                           iServiceName ) ))
       
   667                 {
       
   668                 iconIndex = aParams.iIconArray.FindIcon(
       
   669                      iPresenceIconsPos->operator[](i).iIconId );
       
   670                 }
       
   671             }
       
   672         }
       
   673     
       
   674     if ( iconIndex == KErrNotFound )
       
   675         {
       
   676         iconIndex = aParams.iIconArray.FindIcon(
       
   677             aField.FieldProperty().IconId() );
       
   678         }
       
   679     if ( iconIndex == KErrNotFound )
       
   680         {
       
   681         iconIndex = aParams.iIconArray.FindIcon( iParams.iDefaultIconId );
       
   682         }
       
   683 
       
   684     iconText.Num( iconIndex );
       
   685     aRow.AppendColumnL( iconText );
       
   686     }
       
   687 
       
   688 // --------------------------------------------------------------------------
       
   689 // CPbk2FieldListBoxModel::AppendAddressIconsToBeginningL
       
   690 // Adds icons to the beginning.
       
   691 // --------------------------------------------------------------------------
       
   692 //
       
   693 inline void CPbk2FieldListBoxModel::AppendAddressIconsToBeginningL
       
   694         ( const CPbk2PresentationContactField& aField,
       
   695           CPbk2FieldListBoxRow& aRow, TParams& aParams )
       
   696     {
       
   697     // Format icon index
       
   698     TBuf<KMaxFormattedTIntLength> iconText; 
       
   699     TInt iconIndex = KErrNotFound;
       
   700     
       
   701     if ( IsGeoFieldForAddressL( aField ) )
       
   702         {
       
   703         iconIndex = aParams.iIconArray.FindIcon(
       
   704             TPbk2AppIconId( EPbk2qgn_prop_locev_map ) );
       
   705         }
       
   706     else
       
   707     	{
       
   708         iconIndex = aParams.iIconArray.FindIcon(
       
   709     	    TPbk2AppIconId( EPbk2qgn_prop_pb_no_valid_lm ) );
       
   710     	}
       
   711 
       
   712     iconText.Num( iconIndex );
       
   713     aRow.AppendColumnL( iconText );
       
   714     }
       
   715 
       
   716 // --------------------------------------------------------------------------
       
   717 // CPbk2FieldListBoxModel::IsGeoFieldForAddressL
       
   718 // Checks if address is validated.
       
   719 // --------------------------------------------------------------------------
       
   720 //
       
   721 inline TBool CPbk2FieldListBoxModel::IsGeoFieldForAddressL
       
   722         ( const CPbk2PresentationContactField& aField )
       
   723     {
       
   724     TBool result = EFalse;
       
   725     TInt startIndex = 0;
       
   726 
       
   727     TPbk2StoreContactAnalyzer analyzer( iParams.iContactManager, NULL );
       
   728     if ( analyzer.IsFieldTypeIncludedL(
       
   729         	aField, R_PHONEBOOK2_HOME_ADDRESS_SELECTOR ) )
       
   730     	{
       
   731     	if ( analyzer.HasFieldL( R_PHONEBOOK2_HOME_GEO_SELECTOR,
       
   732     			startIndex,
       
   733     			&iParams.iFields.ParentStoreContact() ) != KErrNotFound )
       
   734     		{
       
   735     		result = ETrue;
       
   736     		}
       
   737     	}
       
   738     else if ( analyzer.IsFieldTypeIncludedL(
       
   739         	aField, R_PHONEBOOK2_WORK_ADDRESS_SELECTOR ) )
       
   740     	{
       
   741     	if ( analyzer.HasFieldL( R_PHONEBOOK2_WORK_GEO_SELECTOR,
       
   742     			startIndex,
       
   743     	    	&iParams.iFields.ParentStoreContact() ) != KErrNotFound )
       
   744     	    {
       
   745     	    result = ETrue;
       
   746     	    }
       
   747     	}
       
   748     else if ( analyzer.IsFieldTypeIncludedL(
       
   749         	aField, R_PHONEBOOK2_GENERAL_ADDRESS_SELECTOR ) )
       
   750     	{
       
   751     	if ( analyzer.HasFieldL( R_PHONEBOOK2_GENERAL_GEO_SELECTOR,
       
   752     			startIndex,
       
   753     	    	&iParams.iFields.ParentStoreContact() ) != KErrNotFound )
       
   754     	    {
       
   755     	    result = ETrue;
       
   756     	    }
       
   757     	}
       
   758 
       
   759     return result;
       
   760     }
       
   761 
       
   762 // --------------------------------------------------------------------------
       
   763 // CPbk2FieldListBoxModel::AppendIconsToEndL
       
   764 // Adds additional icons to the end.
       
   765 // --------------------------------------------------------------------------
       
   766 //
       
   767 inline void CPbk2FieldListBoxModel::AppendIconsToEndL
       
   768         ( const CPbk2PresentationContactField& aField,
       
   769           CPbk2FieldListBoxRow& aRow, TParams& aParams )
       
   770     {
       
   771     if ( aParams.iFieldAnalyzer )
       
   772         {
       
   773         // Check and add speed dial icon
       
   774         if ( aParams.iFieldAnalyzer->HasSpeedDialL( aField.StoreField() ) )
       
   775             {
       
   776             TBuf<KMaxFormattedTIntLength> iconText;
       
   777             iconText.Num( aParams.iIconArray.
       
   778                 FindIcon( TPbk2AppIconId( EPbk2qgn_indi_qdial_add ) ) );
       
   779             aRow.AppendColumnL( iconText );
       
   780             }
       
   781         }
       
   782     }
       
   783 
       
   784 // --------------------------------------------------------------------------
       
   785 // CPbk2FieldListBoxModel::DuplicatesExist
       
   786 // Checks if row with the same content already exists.
       
   787 // --------------------------------------------------------------------------
       
   788 //
       
   789 inline TBool CPbk2FieldListBoxModel::DuplicatesExist(
       
   790     TPtrC aContent )
       
   791     {
       
   792     TBool ret = EFalse;
       
   793     TInt rowsCount = iRows.Count();
       
   794     for (TInt i = 0; i < rowsCount && !ret; i++ )
       
   795         {            
       
   796         if ( iRows[i]->At( EContentColumn ).CompareF( aContent ) == 0 )
       
   797             {
       
   798             ret = ETrue;
       
   799             }
       
   800         }
       
   801 
       
   802     return ret;
       
   803     }
       
   804 
       
   805 // --------------------------------------------------------------------------
       
   806 // CPbk2FieldListBoxModel::DuplicatesAddressExist
       
   807 // Checks if row with the same content already exists.
       
   808 // --------------------------------------------------------------------------
       
   809 //
       
   810 inline TBool CPbk2FieldListBoxModel::DuplicatesAddressExist(
       
   811     TPtrC aContent, TInt aIndex )
       
   812     {
       
   813     TBool ret = EFalse;
       
   814     TInt rowsCount = iRows.Count();
       
   815     for( TInt i = 0; i < rowsCount && !ret; i++ )
       
   816         {
       
   817         if ( aIndex < iRows[i]->ColumnCount() )
       
   818             {
       
   819             if ( iRows[i]->At( aIndex ).CompareF( aContent ) == 0 )
       
   820                 {
       
   821                 ret = ETrue;
       
   822                 }
       
   823             }
       
   824         }
       
   825     
       
   826     return ret;
       
   827     }
       
   828 
       
   829 //  End of File