browserui/browser/FavouritesSrc/BrowserFavouritesListboxModel.cpp
branchRCL_3
changeset 64 6385c4c93049
parent 63 4baee4f15982
child 65 8e6fa1719340
equal deleted inserted replaced
63:4baee4f15982 64:6385c4c93049
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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: 
       
    15 *      Implementation of CBrowserFavouritesListboxModel.
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <eiklbx.h>
       
    24 #include <calslbs.h>
       
    25 #include <favouritesitem.h>
       
    26 #include <favouritesitemlist.h>
       
    27 #include "BrowserFavouritesListboxModel.h"
       
    28 #include "BrowserFavouritesIconIndexArray.h"
       
    29 #include "BrowserUtil.h"
       
    30 
       
    31 // ================= LOCAL FUNCTIONS =======================
       
    32 
       
    33 /**
       
    34 * Copy aSOurce to aTarget, replacing TAB characters with spaces.
       
    35 * @param aSource Source descriptor.
       
    36 * @param aTarget Target descriptor.
       
    37 */
       
    38 LOCAL_C void RemoveTabs( const TDesC& aSource, TDes& aTarget )
       
    39     {
       
    40     TChar ch;
       
    41     TInt i;
       
    42     TInt length = aSource.Length();
       
    43     // Initialize target to empty string.
       
    44     aTarget.SetLength( 0 );
       
    45     // Copy source to target, replace whitespace with space.
       
    46     for ( i = 0; i < length; i++ )
       
    47         {
       
    48         ch = aSource[i];
       
    49         if ( ch == '\t' )
       
    50             {
       
    51             ch = ' ';
       
    52             }
       
    53         aTarget.Append( ch );
       
    54         }
       
    55     }
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 // ====== TBrowserFavouritesListboxFilterTextArray =======
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // TBrowserFavouritesListboxItemTextArray::MdcaCount
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 TInt TBrowserFavouritesListboxItemTextArray::MdcaCount() const
       
    65     {
       
    66     return iItems->Count();
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // TBrowserFavouritesListboxItemTextArray::MdcaPoint
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 TPtrC TBrowserFavouritesListboxItemTextArray::MdcaPoint
       
    74 ( TInt aIndex ) const
       
    75     {
       
    76     // Sorry, need to cast away the const-ness from the buffer.
       
    77     // It was made definitely for formatting! Odd that this method
       
    78     // is const.
       
    79     CFavouritesItem* item = iItems->At( aIndex );
       
    80     TBrowserFavouritesIconIndexes iconIndexes = iIconIndexes->At( aIndex );
       
    81 
       
    82     TBuf<KFavouritesMaxName> name;
       
    83 
       
    84 	RemoveTabs( item->Name(), name );
       
    85 
       
    86     if ( iconIndexes.iBearerIcon == KBrowserFavouritesNoBearerIcon )
       
    87         {
       
    88         _LIT( KFormatNoBearer, "%d\t%S\t\t" );
       
    89         MUTABLE_CAST( TBuf<KMaxFavouritesItemListboxName>&, iBuf 
       
    90             ). //lint !e665 expression macro param ok
       
    91             Format
       
    92                 (
       
    93                 KFormatNoBearer,
       
    94                 iconIndexes.iItemIcon,
       
    95                 &name
       
    96                 );
       
    97         }
       
    98     else
       
    99         {
       
   100         _LIT( KFormatWithBearer, "%d\t%S\t%d\t" );
       
   101         MUTABLE_CAST( TBuf<KMaxFavouritesItemListboxName>&, iBuf 
       
   102             ). //lint !e665 expression macro param ok
       
   103             Format
       
   104                 (
       
   105                 KFormatWithBearer,
       
   106                 iconIndexes.iItemIcon,
       
   107                 &name,
       
   108                 iconIndexes.iBearerIcon
       
   109                 );
       
   110         }
       
   111     return iBuf;
       
   112     }
       
   113 
       
   114 // ================= MEMBER FUNCTIONS =======================
       
   115 // ====== TBrowserFavouritesListboxFilterTextArray =======
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // TBrowserFavouritesListboxFilterTextArray::MdcaCount
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 TInt TBrowserFavouritesListboxFilterTextArray::MdcaCount() const
       
   122     {
       
   123     return iItems->Count();
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // TBrowserFavouritesListboxFilterTextArray::MdcaPoint
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 TPtrC TBrowserFavouritesListboxFilterTextArray::MdcaPoint
       
   131 ( TInt aIndex ) const
       
   132     {
       
   133     return iItems->At( aIndex )->Name();
       
   134     }
       
   135 
       
   136 // ================= MEMBER FUNCTIONS =======================
       
   137 // =========== CBrowserFavouritesListboxModel ============
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CBrowserFavouritesListboxModel::NewL
       
   141 // ---------------------------------------------------------
       
   142 //
       
   143 CBrowserFavouritesListboxModel* CBrowserFavouritesListboxModel::NewL
       
   144         (
       
   145         const CFavouritesItemList& aItems,
       
   146         const CBrowserFavouritesIconIndexArray& aIconIndexes
       
   147         )
       
   148     {
       
   149     CBrowserFavouritesListboxModel* model =
       
   150         new (ELeave) CBrowserFavouritesListboxModel( aItems, aIconIndexes );
       
   151     CleanupStack::PushL( model );
       
   152     model->ConstructL();
       
   153     CleanupStack::Pop();    // model
       
   154     return model;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CBrowserFavouritesListboxModel::SetItemArray
       
   159 // ---------------------------------------------------------
       
   160 //
       
   161 void CBrowserFavouritesListboxModel::SetItemArray()
       
   162     {
       
   163     // Need to set them after the listbox has been constructed; otherwise
       
   164     // listbox construction will reset the item text array to NULL.
       
   165     SetItemTextArray( &iItemTexts );
       
   166     SetOwnershipType( ELbmDoesNotOwnItemArray ); 
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CBrowserFavouritesListboxModel::~CBrowserFavouritesListboxModel
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 CBrowserFavouritesListboxModel::~CBrowserFavouritesListboxModel()
       
   174     {
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------
       
   178 // CBrowserFavouritesListboxModel::SetData
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 void CBrowserFavouritesListboxModel::SetData
       
   182         (
       
   183         const CFavouritesItemList& aItems,
       
   184         const CBrowserFavouritesIconIndexArray& aIconIndexes
       
   185         )
       
   186     {
       
   187     iItems = &aItems;
       
   188     iIconIndexes = &aIconIndexes;
       
   189     __ASSERT_DEBUG( iItems->Count() == iIconIndexes->Count(), \
       
   190         Util::Panic( Util::EFavouritesBadIconIndexArray ) );
       
   191     // Propagate data to formatting classes.
       
   192     iItemTexts.iItems = iItems;
       
   193     iItemTexts.iIconIndexes = iIconIndexes;
       
   194     iFilterTexts.iItems = iItems;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CBrowserFavouritesListboxModel::MatchableTextArray
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 const MDesCArray* CBrowserFavouritesListboxModel::MatchableTextArray() const
       
   202     {
       
   203     return &iFilterTexts;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CBrowserFavouritesListboxModel::CBrowserFavouritesListboxModel
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 CBrowserFavouritesListboxModel::CBrowserFavouritesListboxModel
       
   211         (
       
   212         const CFavouritesItemList& aItems,
       
   213         const CBrowserFavouritesIconIndexArray& aIconIndexes
       
   214         )
       
   215 : CAknFilteredTextListBoxModel(), iItems( &aItems ),
       
   216   iIconIndexes( &aIconIndexes )
       
   217     {
       
   218     __ASSERT_DEBUG( iItems->Count() == iIconIndexes->Count(), \
       
   219         Util::Panic( Util::EFavouritesBadIconIndexArray ) );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------
       
   223 // CBrowserFavouritesListboxModel::ConstructL
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CBrowserFavouritesListboxModel::ConstructL()
       
   227     {
       
   228     // Propagate data to formatting classes.
       
   229     iItemTexts.iItems = iItems;
       
   230     iItemTexts.iIconIndexes = iIconIndexes;
       
   231     iFilterTexts.iItems = iItems;
       
   232     // Base class method already called by listbox. Nasty buggy mess.
       
   233     }
       
   234 
       
   235 // End of File