phonebookui/Phonebook2/UIControls/src/cpbk2contactviewdoublelistboxmodel.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2009-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:  Phonebook 2 contact view double list box model.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <featmgr/featmgr.h>
       
    21 #include <MVPbkViewContact.h>
       
    22 
       
    23 #include "MPbk2ClipListBoxText.h"
       
    24 #include "cpbk2contactviewdoublelistboxmodel.h"
       
    25 #include "CPbk2ThumbnailManager.h"
       
    26 #include "Pbk2PresentationUtils.h"
       
    27 #include "pbk2contactuicontroldoublelistboxextension.h"
       
    28 #include "pbk2contactviewdoublelistboxdataelement.h"
       
    29 #include "Pbk2Debug.h"
       
    30 
       
    31 #include <MPbk2ContactNameFormatter2.h>
       
    32 #include <MPbk2ContactNameFormatter.h>
       
    33 #include <MPbk2ContactUiControlExtension.h>
       
    34 #include <CPbk2ContactIconsUtils.h>
       
    35 #include <CPbk2IconArray.h>
       
    36 #include <Pbk2InternalUID.h>
       
    37 
       
    38 //Virtual phonebook
       
    39 #include <MVPbkContactViewBase.h>
       
    40 #include <MVPbkViewContact.h>
       
    41 #include <MVPbkContactLink.h>
       
    42 #include <MVPbkContactViewBase.h>
       
    43 
       
    44 // CONSTANTS
       
    45 namespace {
       
    46 // Character used to replace invalid characters for UI
       
    47 const TText KGraphicReplaceCharacter    = ' ';
       
    48 
       
    49 // Character used to separate listbox columns
       
    50 const TText KListColumnSeparator        = '\t';
       
    51 
       
    52 // Index of contact name column
       
    53 const TInt KNameColumn                  = 1;
       
    54 
       
    55 // Index of secondary text column
       
    56 const TInt KSecondaryTextColumn         = 2;
       
    57 
       
    58 // Default formating used for contacts
       
    59 const TInt KDefaultListFormatting =
       
    60         MPbk2ContactNameFormatter::EUseSeparator |
       
    61         MPbk2ContactNameFormatter::EPreserveLeadingSpaces;
       
    62 
       
    63 // iBuffer max size is EMaxListBoxText = 256
       
    64 // -> max length for name data is 100 and max lenght for status data is 100
       
    65 // rest 56 are reserved for icon data
       
    66 const TInt KMaxTxtLength = 100;
       
    67 }
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel(
       
    74     CPbk2ContactViewListBoxModel::TParams& aParams,
       
    75     CPbk2ThumbnailManager& aThumbManager ) :
       
    76     CPbk2ContactViewListBoxModel( aParams ),
       
    77     iThumbManager( aThumbManager )
       
    78     {
       
    79     TAny* object = aParams.iUiExtension->ContactUiControlExtensionExtension
       
    80             ( TUid::Uid( KPbk2ContactUiControlExtensionExtensionUID ) );
       
    81     iDoubleListExtensionPoint =
       
    82             static_cast<MPbk2ContactUiControlDoubleListboxExtension*>( object );
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 // CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel()
       
    90     {
       
    91     }
       
    92 
       
    93 // --------------------------------------------------------------------------
       
    94 // CPbk2ContactViewDoubleListBoxModel::NewL
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 CPbk2ContactViewDoubleListBoxModel* CPbk2ContactViewDoubleListBoxModel::NewL(
       
    98     CPbk2ContactViewListBoxModel::TParams& aParams,
       
    99     CPbk2ThumbnailManager& aThumbManager )
       
   100     {
       
   101     CPbk2ContactViewDoubleListBoxModel* self =
       
   102         new ( ELeave ) CPbk2ContactViewDoubleListBoxModel( 
       
   103 		    aParams, aThumbManager );
       
   104 
       
   105     CleanupStack::PushL(self);
       
   106     self->ConstructL( aParams.iStoreProperties, aParams.iUiExtension );
       
   107     CleanupStack::Pop();
       
   108     return self;
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2ContactViewDoubleListBoxModel::FormatBufferL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 void CPbk2ContactViewDoubleListBoxModel::FormatBufferL( const TInt aIndex ) const
       
   116     {
       
   117     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   118         ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), begin"),
       
   119         this);
       
   120 
       
   121     const MVPbkViewContact& contact = iView->ContactAtL(aIndex);
       
   122     FormatBufferForContactL(contact, aIndex );
       
   123     
       
   124     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   125         ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), end"),
       
   126         this);
       
   127     }
       
   128 
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 void CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension(
       
   135         CPbk2ContactViewDoubleListboxDataElement& aDataElement,
       
   136         TInt aIndex,
       
   137         const MVPbkContactLink& aLink ) const
       
   138     {
       
   139     // Get element data from extension
       
   140     // 
       
   141     if( iDoubleListExtensionPoint )
       
   142         {
       
   143         TRAPD( err, 
       
   144             iDoubleListExtensionPoint->FormatDataL( 
       
   145                     aLink, aDataElement ) );
       
   146         if( err )
       
   147             {
       
   148             // extension's errors are ignored.  
       
   149             PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   150             "CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension format error %d"),
       
   151                 err );
       
   152             }
       
   153         }
       
   154 
       
   155     // Clip secondary text if it's a phone number 
       
   156     if( MPbk2DoubleListboxDataElement::ETypePhoneNumber == 
       
   157         aDataElement.TextType( MPbk2DoubleListboxDataElement::EStatusText ) && 
       
   158         iClipListBoxText )
       
   159         {
       
   160         TPtr secondary( aDataElement.TextPtr( 
       
   161             MPbk2DoubleListboxDataElement::EStatusText ) );
       
   162         iClipListBoxText->ClipFromBeginning( 
       
   163             secondary, aIndex, KSecondaryTextColumn );
       
   164         }    
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL
       
   169 // --------------------------------------------------------------------------
       
   170 //
       
   171 void CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL(
       
   172     const MVPbkViewContact& aViewContact, 
       
   173     TInt aIndex ) const
       
   174     {
       
   175     CPbk2ContactViewDoubleListboxDataElement* element = 
       
   176         CPbk2ContactViewDoubleListboxDataElement::NewLC();
       
   177 
       
   178     // get data for element
       
   179     // get user name
       
   180     HBufC* name = NULL;
       
   181     if( FeatureManager::FeatureSupported( KFeatureIdFfContactsCompanyNames ))
       
   182         {
       
   183         MPbk2ContactNameFormatter2* nameformatterExtension =
       
   184             reinterpret_cast<MPbk2ContactNameFormatter2*>(iNameFormatter.
       
   185             ContactNameFormatterExtension( MPbk2ContactNameFormatterExtension2Uid ) );
       
   186         name = nameformatterExtension->GetContactTitleWithCompanyNameL(
       
   187             aViewContact.Fields(), KDefaultListFormatting );
       
   188         }
       
   189     else
       
   190         {
       
   191         name = iNameFormatter.GetContactTitleL(
       
   192             aViewContact.Fields(), KDefaultListFormatting );
       
   193         }
       
   194     CleanupStack::PushL( name );
       
   195     TPtr namePtr( name->Des() );
       
   196 
       
   197     // Replace characters that can not be displayed correctly
       
   198     Pbk2PresentationUtils::ReplaceNonGraphicCharacters(
       
   199         namePtr, KGraphicReplaceCharacter );
       
   200     
       
   201     if( CutFromBeginningFieldL( aViewContact.Fields() ) && iClipListBoxText )
       
   202         {
       
   203         iClipListBoxText->ClipFromBeginning( namePtr, aIndex, KNameColumn );
       
   204         }
       
   205 
       
   206     // takes ownership of 'name'
       
   207     element->SetText( MPbk2DoubleListboxDataElement::EName, name, 
       
   208         MPbk2DoubleListboxDataElement::ETypeGenericText );
       
   209     CleanupStack::Pop( name );
       
   210 
       
   211 
       
   212     // get icons
       
   213     RArray<TPbk2IconId> ids;
       
   214     CleanupClosePushL( ids );
       
   215     iContactIcons->GetIconIdsForContactL( aViewContact, ids );
       
   216 
       
   217     // ids should contain at least one empty icon in any case
       
   218     if( ids.Count() == 0 )
       
   219         {
       
   220         ids.Append( iEmptyIconId );
       
   221         }
       
   222     
       
   223     element->SetIconId( MPbk2DoubleListboxDataElement::EMainIcon, ids[0] );
       
   224     CleanupStack::PopAndDestroy( &ids );
       
   225 
       
   226     MVPbkContactLink* link = aViewContact.CreateLinkLC();
       
   227     
       
   228     // Get element data from extension
       
   229     FetchDataFromExtension( *element, aIndex, *link );
       
   230 
       
   231     // start format data for the avkon list
       
   232     iBuffer.Zero();
       
   233     
       
   234     AppendThumbnailL( *element, aIndex, *link );
       
   235     
       
   236     // Format line buffer based on element's content
       
   237     FormatBufferFromElement( *element );
       
   238     
       
   239     CleanupStack::PopAndDestroy( 2, element ); // link, element
       
   240     }
       
   241 
       
   242 // --------------------------------------------------------------------------
       
   243 // CPbk2ContactViewDoubleListBoxModel::FormatBufferFromElement
       
   244 // --------------------------------------------------------------------------
       
   245 //
       
   246 void CPbk2ContactViewDoubleListBoxModel::FormatBufferFromElement(
       
   247     const CPbk2ContactViewDoubleListboxDataElement& aElement ) const
       
   248     {
       
   249 
       
   250     // List model format:
       
   251     //   [thumbnail icon] \t [contact name] \t [secondary text] \t
       
   252     //   [trailing icon]
       
   253 
       
   254     // (2) Contact name
       
   255     AppendName( aElement.TextPtr( 
       
   256             MPbk2DoubleListboxDataElement::EName ).Left( KMaxTxtLength ) );
       
   257     iBuffer.Append( KListColumnSeparator );
       
   258     
       
   259     // (3) Secondary text
       
   260     TPtr status( aElement.TextPtr( MPbk2DoubleListboxDataElement::EStatusText ) );
       
   261     AppendText( status );
       
   262     
       
   263     // (4) Trailing icon
       
   264     AppendIconIndexIfFound( 
       
   265         aElement.IconId( MPbk2DoubleListboxDataElement::EMainIcon ) );
       
   266     }
       
   267 
       
   268 // --------------------------------------------------------------------------
       
   269 // CPbk2ContactViewDoubleListBoxModel::AppendThumbnailL
       
   270 // --------------------------------------------------------------------------
       
   271 //
       
   272 void CPbk2ContactViewDoubleListBoxModel::AppendThumbnailL( 
       
   273         CPbk2ContactViewDoubleListboxDataElement& aDataElement, 
       
   274         TInt aIndex,
       
   275         const MVPbkContactLink& aLink ) const
       
   276     {
       
   277     // (1) Add thumbnail icon
       
   278     //
       
   279     TInt index = iThumbManager.GetPbkIconIndexL( 
       
   280             aIndex, aLink );
       
   281     if( index != KErrNotFound )
       
   282         {
       
   283         iBuffer.AppendNum( index );
       
   284         }
       
   285     iBuffer.Append( KListColumnSeparator );
       
   286     }
       
   287 
       
   288 // --------------------------------------------------------------------------
       
   289 // CPbk2ContactViewDoubleListBoxModel::AppendText
       
   290 // --------------------------------------------------------------------------
       
   291 //
       
   292 void CPbk2ContactViewDoubleListBoxModel::AppendText( TDes& aText ) const
       
   293     {
       
   294 	//Convert numbers to some languages specific version. E.g.: Arabic.
       
   295     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( aText );
       
   296     
       
   297     // replace non-allowed characters with ' '
       
   298     Pbk2PresentationUtils::ReplaceNonGraphicCharacters(
       
   299         aText, KGraphicReplaceCharacter );
       
   300     AknTextUtils::ReplaceCharacters(
       
   301         aText, KAknReplaceListControlChars, KGraphicReplaceCharacter );
       
   302     
       
   303     iBuffer.Append( aText.Left( KMaxTxtLength ) );
       
   304     iBuffer.Append( KListColumnSeparator );
       
   305     }
       
   306 
       
   307 // --------------------------------------------------------------------------
       
   308 // CPbk2ContactViewDoubleListBoxModel::AppendIconIndexIfFound
       
   309 // --------------------------------------------------------------------------
       
   310 //
       
   311 void CPbk2ContactViewDoubleListBoxModel::AppendIconIndexIfFound(  const TPbk2IconId& aIconId ) const
       
   312 	{
       
   313 	TInt iconIndex = iIconArray->FindIcon( aIconId );
       
   314 	// if icon is found
       
   315 	if( iconIndex != KErrNotFound )
       
   316 		{
       
   317 		iBuffer.AppendNum( iconIndex );
       
   318 		iBuffer.Append( KListColumnSeparator );
       
   319 		}
       
   320 	}
       
   321 
       
   322 
       
   323 //  End of File