phonebookui/Phonebook2/UIControls/inc/CPbk2FieldListBoxModel.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 #ifndef CPBK2FIELDLISTBOXMODEL_H
       
    20 #define CPBK2FIELDLISTBOXMODEL_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <TPbk2AppIconId.h>
       
    25 #include <bamdesca.h>
       
    26 #include <VPbkFieldTypeSelectorFactory.h>
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CPbk2IconArray;
       
    30 class CDesC16Array;
       
    31 class MPbk2ClipListBoxText;
       
    32 class MPbk2FieldAnalyzer;
       
    33 class CPbk2FieldFormatter;
       
    34 class CVPbkContactManager;
       
    35 class CPbk2PresentationContactField;
       
    36 class CPbk2PresentationContactFieldCollection;
       
    37 class MPbk2FieldPropertyArray;
       
    38 class MVPbkFieldType;
       
    39 class CPbk2ContactFieldDynamicProperties;
       
    40 //class CPbk2PresenceIconInfo;
       
    41 
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 /**
       
    46  * Phonebook 2 list box model row.
       
    47  *
       
    48  * @internal Only Phonebook 2 internal use supported!
       
    49  */
       
    50 NONSHARABLE_CLASS(CPbk2FieldListBoxRow) : public CBase
       
    51     {
       
    52     public: // Constructors and destructor
       
    53 
       
    54         /**
       
    55          * Creates a new instance of this class.
       
    56          *
       
    57          * @return  A new instance of this class.
       
    58          */
       
    59         static CPbk2FieldListBoxRow* NewL();
       
    60 
       
    61         /**
       
    62          * Destructor.
       
    63          */
       
    64         ~CPbk2FieldListBoxRow();
       
    65 
       
    66     public: // Interface
       
    67 
       
    68         /**
       
    69          * Returns the number of columns in this row.
       
    70          *
       
    71          * @return  Number of columns in this row.
       
    72          */
       
    73         TInt ColumnCount() const;
       
    74 
       
    75         /**
       
    76          * Returns the descriptor at the given position.
       
    77          *
       
    78          * @param aColumnIndex  Column index.
       
    79          * @return  The descriptor at the given index.
       
    80          */
       
    81         TPtrC At(
       
    82                 TInt aColumnIndex ) const;
       
    83 
       
    84         /**
       
    85          * Appends a given column to the row.
       
    86          *
       
    87          * @param aColumnText   Column to append.
       
    88          */
       
    89         void AppendColumnL(
       
    90                 const TDesC& aColumnText );
       
    91 
       
    92         /**
       
    93          * Returns the total descriptor length of all the columns.
       
    94          *
       
    95          * @return  Total row length.
       
    96          */
       
    97         TInt TotalLength() const;
       
    98 
       
    99         /**
       
   100          * Returns the maximum column length of this row.
       
   101          *
       
   102          * @return  Maximum column length.
       
   103          */
       
   104         TInt MaxColumnLength() const;
       
   105 
       
   106     private: // Implementation
       
   107         CPbk2FieldListBoxRow();
       
   108 
       
   109     private: // Data
       
   110         /// Own: Column array
       
   111         RPointerArray<HBufC> iColumns;
       
   112     };
       
   113 
       
   114 /**
       
   115  * Phonebook 2 field list box model.
       
   116  *
       
   117  * @internal Only Phonebook 2 internal use supported!
       
   118  */
       
   119 NONSHARABLE_CLASS(CPbk2FieldListBoxModel) : public CBase,
       
   120                                             public MDesCArray
       
   121     {
       
   122     public: // Types
       
   123 
       
   124         /**
       
   125          * Column indexes.
       
   126          */
       
   127         enum TColumnIndex
       
   128             {
       
   129             /// Icon column
       
   130             EIconColumn = 0,
       
   131             /// Label column
       
   132             ELabelColumn,
       
   133             /// Content column
       
   134             EContentColumn
       
   135             };
       
   136 
       
   137     public: // Data structures
       
   138         
       
   139         // structure to keep presence icon position in the common icon array 
       
   140         struct TPresenceIconPosInIconArray
       
   141             {
       
   142             // position of the icon in the common icon array
       
   143             TPbk2IconId iIconId;
       
   144             // service name
       
   145             const TDesC16& iServiceName; 
       
   146             TPresenceIconPosInIconArray( const TDesC16& aServiceName ):
       
   147                 iServiceName ( aServiceName )
       
   148                 {
       
   149                 }
       
   150             };
       
   151         
       
   152         /**
       
   153          * Construction parameters for CPbk2FieldListBoxModel.
       
   154          */
       
   155         class TParams
       
   156             {
       
   157             public: // Construction
       
   158                 /**
       
   159                  * Constructor.
       
   160                  *
       
   161                  * @param aFieldCollection      Array of fields to display.
       
   162                  * @param aContactManager       Virtual Phonebook
       
   163                  *                              contact manager.
       
   164                  * @param aFieldProperties      Field properties.
       
   165                  * @param aTimeFormat           Time formatting string
       
   166                  *                              to use.
       
   167                  * @param aIconArray            Icon array to use.
       
   168                  * @param aFieldAnalyzer        Interface for
       
   169                  *                              analyzing fields.
       
   170                  * @param aDynamicProperties    Dynamic field properties.
       
   171 	             * @param aCommMethod		Communication method type selected
       
   172                  */
       
   173                 TParams (
       
   174                         const CPbk2PresentationContactFieldCollection&
       
   175                             aFieldCollection,
       
   176                         const CVPbkContactManager& aContactManager,
       
   177                         const MPbk2FieldPropertyArray& aFieldProperties,
       
   178                         const TDesC& aTimeFormat,
       
   179                         const CPbk2IconArray& aIconArray,
       
   180                         const MPbk2FieldAnalyzer* aFieldAnalyzer,
       
   181                         const CPbk2ContactFieldDynamicProperties* aDynamicProperties,
       
   182 			            const TBool aFieldContentNeedToBeDuplicated,
       
   183 						VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aCommMethod = VPbkFieldTypeSelectorFactory::EEmptySelector) :
       
   184                     	    iFields( aFieldCollection ),
       
   185                     	    iContactManager( aContactManager ),
       
   186                     	    iFieldProperties( aFieldProperties ),
       
   187                     	    iTimeFormat( aTimeFormat ),
       
   188                     	    iIconArray( aIconArray ),
       
   189                     	    iDefaultIconId( EPbk2qgn_prop_nrtyp_empty ),
       
   190                     	    iFieldAnalyzer( aFieldAnalyzer ),
       
   191                     	    iDynamicProperties( aDynamicProperties ),
       
   192 			                iFieldContentNeedToBeDuplicated( aFieldContentNeedToBeDuplicated ),
       
   193 							iCommMethod( aCommMethod )
       
   194 	            {
       
   195 	            }
       
   196 
       
   197             public: // Data
       
   198                 /// Ref: Array of fields to display
       
   199                 const CPbk2PresentationContactFieldCollection& iFields;
       
   200                 /// Ref: Virtual Phonebook contact manager
       
   201                 const CVPbkContactManager& iContactManager;
       
   202                 /// Ref: Field properties
       
   203                 const MPbk2FieldPropertyArray& iFieldProperties;
       
   204                 /// Ref: Time formatting string
       
   205                 const TDesC& iTimeFormat;
       
   206                 /// Ref: Icon array
       
   207                 const CPbk2IconArray& iIconArray;
       
   208                 /// Own: Default icon id
       
   209                 TPbk2AppIconId iDefaultIconId;
       
   210                 /// Ref: Interface for analyzing field
       
   211                 const MPbk2FieldAnalyzer* iFieldAnalyzer;
       
   212                 /// Own: Dynamic properties for contact fields
       
   213                 const CPbk2ContactFieldDynamicProperties* iDynamicProperties;
       
   214 	            /// Own: The flag indicates the field content need to be duplicated
       
   215                 const TBool iFieldContentNeedToBeDuplicated;
       
   216 				/// Own: Communication method type selected
       
   217 				VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector iCommMethod;
       
   218             };
       
   219 
       
   220     public: // Constructors and destructor
       
   221 
       
   222         /**
       
   223          * Creates a new instance of this class.
       
   224          *
       
   225          * @param aParams   List box model parameters.
       
   226          * @param aFieldCollectionArray  Array of store contact fields arrays.
       
   227          * @return  A new instance of this class.
       
   228          */
       
   229         static CPbk2FieldListBoxModel* NewL(
       
   230             TParams& aParams,
       
   231             const TArray<CPbk2PresentationContactFieldCollection*>*
       
   232                 aFieldCollectionArray = NULL,
       
   233             const TArray<TPresenceIconPosInIconArray>* aPresenceIconsPos = NULL );
       
   234 
       
   235         /**
       
   236          * Destructor.
       
   237          */
       
   238         ~CPbk2FieldListBoxModel();
       
   239 
       
   240     public: // Interface
       
   241 
       
   242         /**
       
   243          * Appends a given row to the end of the model.
       
   244          *
       
   245          * @param aLine     The row to append.
       
   246          */
       
   247         void AppendRowL(
       
   248                 CPbk2FieldListBoxRow* aLine );
       
   249 
       
   250         /**
       
   251          * Sets the text clipper to given clipper.
       
   252          *
       
   253          * @param aTextClipper  The clipper to set.
       
   254          */
       
   255         void SetClipper(
       
   256                 MPbk2ClipListBoxText& aTextClipper );
       
   257                 
       
   258         /**
       
   259          * Formats fields. Needs to be call after construction.
       
   260          */                
       
   261         void FormatFieldsL();
       
   262         
       
   263         /**
       
   264          * Returns the index of the listbox selected item from the model
       
   265          * point of view, i.e. taking into account duplicates.
       
   266          *
       
   267          * @param aListboxIndex Listbox selected item index
       
   268          * @return Model index of the selected item
       
   269          */    
       
   270         TInt GetModelIndex( TInt aListboxIndex );
       
   271         
       
   272     public: // From MDesCArray
       
   273         TInt MdcaCount() const;
       
   274         TPtrC16 MdcaPoint(
       
   275                 TInt aIndex ) const;
       
   276 
       
   277     private: // Implementation
       
   278         CPbk2FieldListBoxModel(
       
   279                 TParams& aParams,
       
   280                 const TArray<CPbk2PresentationContactFieldCollection*>*
       
   281                     aFieldCollectionArray,
       
   282                 const TArray<TPresenceIconPosInIconArray>* aPresenceIconsPos );
       
   283         void ConstructL(
       
   284                 TParams& aParams );
       
   285         void FormatFieldL(
       
   286                 const CPbk2PresentationContactField& aField,
       
   287                 TParams& aParams );
       
   288         void FormatAddressFieldL(
       
   289                 const CPbk2PresentationContactField& aField,
       
   290                 TParams& aParams );
       
   291         void ExpandBuffersL(
       
   292                 const CPbk2FieldListBoxRow& aRow );
       
   293         TPtr ExpandColumnBufferL(
       
   294                 TInt aRequiredLength );
       
   295         void ClipText(
       
   296                 const CPbk2PresentationContactField& aField,
       
   297                 TInt aIndex,
       
   298                 TPtr& aColumnText,
       
   299                 TInt aColumnIndex ) const;
       
   300         void AppendFieldLabelL(
       
   301                 const CPbk2PresentationContactField& aField,
       
   302                 CPbk2FieldListBoxRow& aRow,
       
   303                 TPtr& aColumnBuf );
       
   304         void AppendAddressFieldLabelL(
       
   305                 const CPbk2PresentationContactField& aField,
       
   306                 CPbk2FieldListBoxRow& aRow,
       
   307                 TPtr& aColumnBuf );
       
   308         void AppendFieldContentL(
       
   309                 const CPbk2PresentationContactField& aField,
       
   310                 const MVPbkFieldType& aFieldType,
       
   311                 CPbk2FieldListBoxRow& aRow,
       
   312                 TPtr& aColumnBuf );
       
   313         void AppendAddressFieldContentL(
       
   314                 const CPbk2PresentationContactField& aField,
       
   315                 CPbk2FieldListBoxRow& aRow,
       
   316                 TPtr& aColumnBuf );
       
   317         void AppendIconsToBeginningL(
       
   318                 const CPbk2PresentationContactField& aField,
       
   319                 const MVPbkFieldType& aFieldType,
       
   320                 CPbk2FieldListBoxRow& aRow,
       
   321                 TParams& aParams );
       
   322         void AppendAddressIconsToBeginningL(
       
   323         		const CPbk2PresentationContactField& aField,
       
   324                 CPbk2FieldListBoxRow& aRow,
       
   325                 TParams& aParams );
       
   326         void AppendIconsToEndL(
       
   327                 const CPbk2PresentationContactField& aField,
       
   328                 CPbk2FieldListBoxRow& aRow,
       
   329                 TParams& aParams );
       
   330         TBool DuplicatesExist( TPtrC aContent );
       
   331         TBool DuplicatesAddressExist( TPtrC aContent, TInt aIndex );
       
   332         TBool IsGeoFieldForAddressL(
       
   333                 const CPbk2PresentationContactField& aField );
       
   334 
       
   335     private: // Data
       
   336         /// Own: Text row array
       
   337         CArrayPtrFlat<CPbk2FieldListBoxRow> iRows;
       
   338         /// Own: Buffer storing one formatted listbox row
       
   339         HBufC* iLineBuf;
       
   340         /// Own: Buffer for storing one formatted listbox column
       
   341         HBufC* iColumnBuf;
       
   342         /// Own: Field content formatter
       
   343         CPbk2FieldFormatter* iFieldFormatter;
       
   344         /// Ref: Object for clipping text
       
   345         MPbk2ClipListBoxText* iTextClipper;
       
   346         /// Own: Dynamic field properties
       
   347         const CPbk2ContactFieldDynamicProperties* iDynamicProperties;
       
   348         /// Own: Parameters
       
   349         TParams iParams;
       
   350         /// Ref: Field collection array for additional contacts
       
   351         const TArray<CPbk2PresentationContactFieldCollection*>*
       
   352                 iFieldCollectionArray;
       
   353         /// Own: array of duplicates in the rows
       
   354         RArray<TInt> iDuplicatesArray;
       
   355         /// Ref: Presence icons pos in common icons array
       
   356         const TArray<TPresenceIconPosInIconArray>* iPresenceIconsPos;
       
   357     };
       
   358 
       
   359 #endif // CPBK2FIELDLISTBOXMODEL_H
       
   360 
       
   361 // End of File