phonebookui/Phonebook2/UIControls/src/cpbk2contactviewdoublelistboxmodel.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 
       
    43 // CONSTANTS
       
    44 
       
    45 // Character used to replace invalid characters for UI
       
    46 const TText KGraphicReplaceCharacter    = ' ';
       
    47 
       
    48 // Character used to separate listbox columns
       
    49 const TText KListColumnSeparator        = '\t';
       
    50 
       
    51 // Index of contact name column
       
    52 const TInt KNameColumn                  = 1;
       
    53 
       
    54 // Index of secondary text column
       
    55 const TInt KSecondaryTextColumn         = 2;
       
    56 
       
    57 // Default formating used for contacts
       
    58 const TInt KDefaultListFormatting =
       
    59         MPbk2ContactNameFormatter::EUseSeparator |
       
    60         MPbk2ContactNameFormatter::EPreserveLeadingSpaces;
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel(
       
    67     CPbk2ContactViewListBoxModel::TParams& aParams,
       
    68     CPbk2ThumbnailManager& aThumbManager ) :
       
    69     CPbk2ContactViewListBoxModel( aParams ),
       
    70     iThumbManager( aThumbManager )
       
    71     {
       
    72     TAny* object = aParams.iUiExtension->ContactUiControlExtensionExtension
       
    73             ( TUid::Uid( KPbk2ContactUiControlExtensionExtensionUID ) );
       
    74     iDoubleListExtensionPoint =
       
    75             static_cast<MPbk2ContactUiControlDoubleListboxExtension*>( object );
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel()
       
    83     {
       
    84     }
       
    85 
       
    86 // --------------------------------------------------------------------------
       
    87 // CPbk2ContactViewDoubleListBoxModel::NewL
       
    88 // --------------------------------------------------------------------------
       
    89 //
       
    90 CPbk2ContactViewDoubleListBoxModel* CPbk2ContactViewDoubleListBoxModel::NewL(
       
    91     CPbk2ContactViewListBoxModel::TParams& aParams,
       
    92     CPbk2ThumbnailManager& aThumbManager )
       
    93     {
       
    94     CPbk2ContactViewDoubleListBoxModel* self =
       
    95         new ( ELeave ) CPbk2ContactViewDoubleListBoxModel( aParams, aThumbManager );
       
    96 
       
    97     CleanupStack::PushL(self);
       
    98     self->ConstructL( aParams.iStoreProperties, aParams.iUiExtension );
       
    99     CleanupStack::Pop();
       
   100     return self;
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 void CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL(
       
   108     const MVPbkViewContact& aViewContact, TInt aIndex ) const
       
   109     {
       
   110     // Reset buffer
       
   111     iBuffer.Zero();
       
   112     
       
   113     CPbk2ContactViewDoubleListboxDataElement* element = 
       
   114         CPbk2ContactViewDoubleListboxDataElement::NewLC();
       
   115 
       
   116     // Fill data element cells
       
   117     
       
   118     // (1) Add thumbnail icon
       
   119     //
       
   120     // TODO: to be fixed
       
   121     //const TPbk2IconId& thumb = iThumbManager.GetPbkIconIndex( aIndex, aViewContact );
       
   122     //element->SetIconId( MPbk2DoubleListboxDataElement::EThumbnail, thumb );
       
   123     // -- temporary sollution:
       
   124     TInt index = iThumbManager.GetPbkIconIndex( aIndex, aViewContact );
       
   125     if( index != KErrNotFound )
       
   126         {
       
   127         iBuffer.AppendNum( index );
       
   128         }
       
   129     iBuffer.Append( KListColumnSeparator );
       
   130     // --
       
   131 
       
   132     // (2) Add contact name
       
   133     //
       
   134     HBufC* name = NULL;
       
   135     if( FeatureManager::FeatureSupported( KFeatureIdFfContactsCompanyNames ))
       
   136         {
       
   137         MPbk2ContactNameFormatter2* nameformatterExtension =
       
   138             reinterpret_cast<MPbk2ContactNameFormatter2*>(iNameFormatter.
       
   139             ContactNameFormatterExtension( MPbk2ContactNameFormatterExtension2Uid ) );
       
   140         name = nameformatterExtension->GetContactTitleWithCompanyNameL(
       
   141             aViewContact.Fields(), KDefaultListFormatting );
       
   142         }
       
   143     else
       
   144         {
       
   145         name = iNameFormatter.GetContactTitleL(
       
   146             aViewContact.Fields(), KDefaultListFormatting );
       
   147         }
       
   148     CleanupStack::PushL( name );
       
   149     TPtr namePtr( name->Des() );
       
   150 
       
   151     // Replace characters that can not be displayed correctly
       
   152     Pbk2PresentationUtils::ReplaceNonGraphicCharacters(
       
   153         namePtr, KGraphicReplaceCharacter );
       
   154     
       
   155     if( CutFromBeginningFieldL( aViewContact.Fields() ) && iClipListBoxText )
       
   156         {
       
   157         iClipListBoxText->ClipFromBeginning( namePtr, aIndex, KNameColumn );
       
   158         }
       
   159 
       
   160     // takes ownership of 'name'
       
   161     element->SetText( MPbk2DoubleListboxDataElement::EName, name, 
       
   162         MPbk2DoubleListboxDataElement::ETypeGenericText );
       
   163     CleanupStack::Pop( name );
       
   164 
       
   165     // (3, 4) Secondary text and icon
       
   166     //
       
   167     // -> These are empty by default
       
   168   
       
   169 
       
   170     // (5) Trailing icon
       
   171     //
       
   172     RArray<TPbk2IconId> ids;
       
   173     CleanupClosePushL( ids );
       
   174     iContactIcons->GetIconIdsForContactL( aViewContact, ids );
       
   175 
       
   176     // ids should contain at least one empty icon in any case
       
   177     if( ids.Count() == 0 )
       
   178         {
       
   179         ids.Append( iEmptyIconId );
       
   180         }
       
   181     
       
   182     element->SetIconId( MPbk2DoubleListboxDataElement::EMainIcon, ids[0] );
       
   183     CleanupStack::PopAndDestroy( &ids );
       
   184 
       
   185     // Get element data from extension
       
   186     if( iDoubleListExtensionPoint )
       
   187         {
       
   188         TRAPD( err, 
       
   189             iDoubleListExtensionPoint->FormatDataL( aViewContact, *element ) );
       
   190         if( err )
       
   191             {
       
   192             // extension's errors are ignored.  
       
   193             PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   194             "CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL format error %d"),
       
   195                 err );
       
   196             }
       
   197         }
       
   198 
       
   199     // Clip secondary text if it's a phone number 
       
   200     if( MPbk2DoubleListboxDataElement::ETypePhoneNumber == 
       
   201         element->TextType( MPbk2DoubleListboxDataElement::EStatusText ) )
       
   202         {
       
   203         TPtr secondary( element->TextPtr( 
       
   204             MPbk2DoubleListboxDataElement::EStatusText ) );
       
   205         iClipListBoxText->ClipFromBeginning( 
       
   206             secondary, aIndex, KSecondaryTextColumn );
       
   207         }
       
   208     
       
   209     // Format line buffer based on element's content
       
   210     FormatBufferFromElement( *element );
       
   211     
       
   212     CleanupStack::PopAndDestroy( element ); 
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------------
       
   216 // CPbk2ContactViewDoubleListBoxModel::FormatBufferFromElement
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 void CPbk2ContactViewDoubleListBoxModel::FormatBufferFromElement(
       
   220     const CPbk2ContactViewDoubleListboxDataElement& aElement ) const
       
   221     {
       
   222 
       
   223     // List model format:
       
   224     //   [thumbnail icon] \t [contact name] \t [secondary text] \t
       
   225     //   [secondary icon] \t [trailing icon]
       
   226 
       
   227     // (1) Thumbnail icon
       
   228     // TODO: to be fixed
       
   229     //AppendIconIndex( 
       
   230     //    aElement.IconId( MPbk2DoubleListboxDataElement::EThumbnail ) );
       
   231 
       
   232     // (2) Contact name
       
   233     AppendName( aElement.TextPtr( MPbk2DoubleListboxDataElement::EName ) );
       
   234     iBuffer.Append( KListColumnSeparator );
       
   235     
       
   236     // (3) Secondary text
       
   237     TPtr status( aElement.TextPtr( MPbk2DoubleListboxDataElement::EStatusText ) );
       
   238     AppendText( status );
       
   239        
       
   240 #if 0	// Service icon is removed for now.
       
   241     // (4) Secondary icon
       
   242     AppendIconIndexIfFound( 
       
   243         aElement.IconId( MPbk2DoubleListboxDataElement::EServiceIcon ) );
       
   244 #endif
       
   245     
       
   246     // (5) Trailing icon
       
   247     AppendIconIndexIfFound( 
       
   248         aElement.IconId( MPbk2DoubleListboxDataElement::EMainIcon ) );
       
   249     }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // CPbk2ContactViewDoubleListBoxModel::AppendText
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 void CPbk2ContactViewDoubleListBoxModel::AppendText( TDes& aText ) const
       
   256     {
       
   257     // replace non-allowed characters with ' '
       
   258     Pbk2PresentationUtils::ReplaceNonGraphicCharacters(
       
   259         aText, KGraphicReplaceCharacter );
       
   260     AknTextUtils::ReplaceCharacters(
       
   261         aText, KAknReplaceListControlChars, KGraphicReplaceCharacter );
       
   262     
       
   263     iBuffer.Append( aText );
       
   264     iBuffer.Append( KListColumnSeparator );
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CPbk2ContactViewDoubleListBoxModel::AppendIconIndexIfFound
       
   269 // --------------------------------------------------------------------------
       
   270 //
       
   271 void CPbk2ContactViewDoubleListBoxModel::AppendIconIndexIfFound(  const TPbk2IconId& aIconId ) const
       
   272 	{
       
   273 	TInt iconIndex = iIconArray->FindIcon( aIconId );
       
   274 	// if icon is found
       
   275 	if( iconIndex != KErrNotFound )
       
   276 		{
       
   277 		iBuffer.AppendNum( iconIndex );
       
   278 		iBuffer.Append( KListColumnSeparator );
       
   279 		}
       
   280 	}
       
   281 
       
   282 
       
   283 //  End of File