browserui/browser/FavouritesSrc/BrowserFavouritesFolderSelector.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 CBrowserFavouritesFolderSelector.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <AknLists.h>
       
    24 #include <AknPopup.h>
       
    25 #include <gulicon.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <favouritesdb.h>
       
    28 #include <favouritesitem.h>
       
    29 #include <favouritesitemlist.h>
       
    30 #include <BrowserNG.rsg>
       
    31 #include <AknsConstants.h>
       
    32 #include "BrowserFavouritesFolderSelector.h"
       
    33 #include "BrowserFavouritesModel.h"
       
    34 #include "BrowserFavouritesIconIndexArray.h"
       
    35 #include "BrowserUtil.h"
       
    36 #include "ApiProvider.h"
       
    37 #include "CommsModel.h"
       
    38 #include "CommonConstants.h"
       
    39 #include "BrowserFavouritesView.h"
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 /**
       
    44 * Granularity of the listbox item array.
       
    45 */
       
    46 LOCAL_C const TInt KGranularity = 4;
       
    47 
       
    48 /**
       
    49 * Buffer size for formatting listbox text. Maximum item name
       
    50 * plus listbox internals (tabulators for icons etc.) must fit into it.
       
    51 * The format is "<icon index max 3 char>\t<name>",
       
    52 * so the added length is 4.
       
    53 */
       
    54 LOCAL_C const TInt KMaxListboxLineLen = KFavouritesMaxName + 4;
       
    55 
       
    56 /**
       
    57 * Format for formatting a listbox line.
       
    58 */
       
    59 _LIT( KListboxLineFormat, "%d\t%S" );
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CBrowserFavouritesFolderSelectorListbox::CBrowserFavouritesFolderSelectorListbox
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 CBrowserFavouritesFolderSelectorListbox::CBrowserFavouritesFolderSelectorListbox( const TBrowserFavouritesFolderListboxIconHandler* aIconHandler ) :
       
    66  CAknSingleGraphicPopupMenuStyleListBox()
       
    67     {
       
    68     iIconHandler = aIconHandler;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CBrowserFavouritesFolderSelectorListbox::HandleResourceChange
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 void CBrowserFavouritesFolderSelectorListbox::HandleResourceChange( TInt aType )
       
    76 {
       
    77 	if ( aType == KAknsMessageSkinChange )
       
    78 		{
       
    79         CArrayPtr<CGulIcon>* array = 
       
    80         ItemDrawer()->ColumnData()->IconArray();
       
    81 
       
    82         array->ResetAndDestroy();
       
    83         delete array;
       
    84         
       
    85         CAknIconArray* iconArray = NULL;
       
    86         TRAPD( err, 
       
    87                 iconArray = iIconHandler->CreateIconArrayL()
       
    88                 )
       
    89         
       
    90         if ( !err )
       
    91             {            
       
    92 	        ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
    93             }
       
    94         delete iconArray;
       
    95         }
       
    96 	return;
       
    97 }
       
    98 
       
    99 // ================= MEMBER FUNCTIONS =======================
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CBrowserFavouritesFolderSelector::NewL
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 CBrowserFavouritesFolderSelector* CBrowserFavouritesFolderSelector::NewL
       
   106         (
       
   107         CBrowserFavouritesModel& aModel,
       
   108         MApiProvider& aApiProvider,
       
   109         TInt aExcludeFolder
       
   110         )
       
   111     {
       
   112     CBrowserFavouritesFolderSelector* selector =
       
   113         new (ELeave) CBrowserFavouritesFolderSelector
       
   114         ( aModel, aApiProvider, aExcludeFolder );
       
   115     CleanupStack::PushL( selector );
       
   116     selector->ConstructL();
       
   117     CleanupStack::Pop();    // selector
       
   118     return selector;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CBrowserFavouritesFolderSelector::CBrowserFavouritesFolderSelector
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 CBrowserFavouritesFolderSelector::CBrowserFavouritesFolderSelector
       
   126         (
       
   127         CBrowserFavouritesModel& aModel,
       
   128         MApiProvider& aApiProvider,
       
   129         TInt aExcludeFolder
       
   130         )
       
   131 : iModel( &aModel ),
       
   132   iApiProvider( &aApiProvider ),
       
   133   iExcludeFolder( aExcludeFolder )
       
   134     {
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CBrowserFavouritesFolderSelector::~CBrowserFavouritesFolderSelector
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 CBrowserFavouritesFolderSelector::~CBrowserFavouritesFolderSelector()
       
   142     {
       
   143     delete iListboxItemArray;
       
   144     delete iListbox;
       
   145     delete iIconIndexes;
       
   146     delete iItems;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CBrowserFavouritesFolderSelector::ConstructL
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 void CBrowserFavouritesFolderSelector::ConstructL()
       
   154     {
       
   155     iListbox = new (ELeave) CBrowserFavouritesFolderSelectorListbox( &iIconHandler );
       
   156 	iPopupList = CAknPopupList::NewL
       
   157         ( iListbox, R_BROWSER_FAVOURITES_CBA_MOVETOFOLDER_MOVECANCEL_MOVE );
       
   158     HBufC* title = CCoeEnv::Static()->AllocReadResourceLC
       
   159         ( R_BROWSER_FAVOURITES_TEXT_MOVE_TO_PRMPT );
       
   160     iPopupList->SetTitleL( *title );
       
   161     CleanupStack::PopAndDestroy();  // title
       
   162     iListbox->ConstructL
       
   163         ( iPopupList, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
       
   164     iListboxItemArray = new (ELeave) CDesCArrayFlat( KGranularity );
       
   165     CTextListBoxModel* listboxModel = iListbox->Model();
       
   166     listboxModel->SetItemTextArray( iListboxItemArray );
       
   167     listboxModel->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   168     iListbox->CreateScrollBarFrameL( ETrue );
       
   169     iListbox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   170         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   171     iListbox->ItemDrawer()->ColumnData()->SetIconArray
       
   172         ( iIconHandler.CreateIconArrayL() );
       
   173 	iListbox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CBrowserFavouritesFolderSelector::ExecuteLD
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 TInt CBrowserFavouritesFolderSelector::ExecuteLD()
       
   181     {
       
   182     TInt uid = KFavouritesNullUid;
       
   183     GetDataL();
       
   184     FillListboxL();
       
   185     if ( iPopupList->ExecuteLD() )
       
   186         {
       
   187         uid = iItems->IndexToUid( iListbox->View()->CurrentItemIndex() );
       
   188         }
       
   189     iPopupList = NULL;  // ExecuteLD has already deleted it.
       
   190     delete this;
       
   191     return uid;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // CBrowserFavouritesFolderSelector::GetDataL
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 void CBrowserFavouritesFolderSelector::GetDataL()
       
   199     {
       
   200     // Getting data. Make sure that the item and icon index data does not
       
   201     // go out of sync - only set them to members when both is gotten.
       
   202     CFavouritesItemList* items = GetItemsLC();
       
   203     CBrowserFavouritesIconIndexArray* iconIndexes =
       
   204         GetIconIndexesLC( *items );
       
   205     // Replace data with new.
       
   206     delete iIconIndexes;                            // Not NULL-ed, because...
       
   207     delete iItems;                                  // Not NULL-ed, because...
       
   208     iItems = items;                                 // ... this cannot leave
       
   209     iIconIndexes = iconIndexes;                     // ... this cannot leave
       
   210     CleanupStack::Pop( 2 ); // iconIndexes, items: now members.
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------
       
   214 // CBrowserFavouritesFolderSelector::FillListboxL
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 void CBrowserFavouritesFolderSelector::FillListboxL()
       
   218     {
       
   219     TBuf<KMaxListboxLineLen> buf;
       
   220     TBuf<KMaxListboxLineLen> name;
       
   221     TInt i;
       
   222     TInt resId = 0;
       
   223 
       
   224     iListboxItemArray->Reset();
       
   225 
       
   226     for ( i = 0; i < iItems->Count(); i++ )
       
   227         {
       
   228             if(!iItems->At(i)->IsHidden())
       
   229             {
       
   230         
       
   231                 resId = CBrowserFavouritesView::GetSeamlessFolderResourceID( 
       
   232                             iItems->At(i)->ContextId() );
       
   233 
       
   234                if(resId) // a seamless link folder. Get the localised name.
       
   235                     {
       
   236                     HBufC* seamlessLinkName = CCoeEnv::Static()->AllocReadResourceLC( resId );
       
   237                     name = seamlessLinkName->Des();
       
   238                     CleanupStack::PopAndDestroy(); // seamlessLinkName
       
   239                     }
       
   240                 else // not a seamless link folder.
       
   241                     {
       
   242                     name = iItems->At( i )->Name();
       
   243                     // Replace TAB characters with spaces.
       
   244                     for ( TInt i = 0; i < name.Length(); i++ )
       
   245                         {
       
   246                         if ( name[i] == '\t' )
       
   247                             {
       
   248                             name[i] = ' ';
       
   249                             }
       
   250                         }
       
   251                     }
       
   252 
       
   253                 buf.Format( KListboxLineFormat, iIconIndexes->At( i ).iItemIcon, &name );
       
   254                 iListboxItemArray->AppendL( buf );
       
   255                 }
       
   256             else
       
   257                 {
       
   258                 iItems->Delete(i);
       
   259                 i--;
       
   260                 }
       
   261             }
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------
       
   265 // CBrowserFavouritesFolderSelector::GetItemsLC
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 CFavouritesItemList* CBrowserFavouritesFolderSelector::GetItemsLC()
       
   269     {
       
   270     CFavouritesItemList* items = new (ELeave) CFavouritesItemList();
       
   271     CleanupStack::PushL( items );
       
   272 
       
   273     if ( iModel->BeginL( /*aWrite=*/EFalse, /*aDbErrorNote=*/ETrue )
       
   274                                                                 == KErrNone )
       
   275         {
       
   276         // Get all folders.
       
   277         iModel->Database().GetAll
       
   278             ( *items, KFavouritesNullUid, CFavouritesItem::EFolder );
       
   279         iModel->CommitL();
       
   280 
       
   281         // Remove iExcludeFolder.
       
   282         TInt index = items->UidToIndex( iExcludeFolder );
       
   283         if ( index >= 0 )
       
   284             {
       
   285             items->Delete( index );
       
   286             }
       
   287 
       
   288         // Set custom localized name for root.
       
   289         index = items->UidToIndex( KFavouritesRootUid );
       
   290         if ( index >= 0 )
       
   291             {
       
   292             HBufC* rootName = CCoeEnv::Static()->AllocReadResourceLC
       
   293                 ( R_BROWSER_FAVOURITES_TEXT_FLDR_ROOT_LEVEL );
       
   294             items->At( index )->SetNameL( *rootName );
       
   295             CleanupStack::PopAndDestroy();  // rootName
       
   296             }
       
   297 
       
   298         CArrayFixFlat<TInt>* orderArray = new (ELeave) CArrayFixFlat<TInt>( KGranularityHigh );
       
   299         CleanupStack::PushL( orderArray );
       
   300         CBrowserBookmarksOrder* currentOrder = CBrowserBookmarksOrder::NewLC();;
       
   301         if ( iModel->Database().GetData( KFavouritesRootUid ,*currentOrder ) == KErrNone)
       
   302             {
       
   303             if ( currentOrder->GetBookMarksOrder().Count() > 0 )
       
   304                 {
       
   305                 orderArray->AppendL( &( currentOrder->GetBookMarksOrder()[0] ), currentOrder->GetBookMarksOrder().Count());
       
   306                 orderArray->InsertL( 0 , KFavouritesRootUid );
       
   307                 iModel->ManualSortL( KFavouritesRootUid, currentOrder, orderArray, items );
       
   308                 }
       
   309             }
       
   310         else
       
   311             {
       
   312             iModel->SortL( *items );
       
   313             }
       
   314         CleanupStack::Pop(2);// orderArray, currentOrder
       
   315         }
       
   316 
       
   317     return items;
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CBrowserFavouritesFolderSelector::GetIconIndexesLC
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 CBrowserFavouritesIconIndexArray*
       
   325 CBrowserFavouritesFolderSelector::GetIconIndexesLC
       
   326 ( CFavouritesItemList& aItems )
       
   327     {
       
   328     // Create new empty list.
       
   329     CBrowserFavouritesIconIndexArray* iconIndexes =
       
   330         new (ELeave) CBrowserFavouritesIconIndexArray( KGranularity );
       
   331     CleanupStack::PushL( iconIndexes );
       
   332     // Get list of access points. Not copy, owned by the AP model.
       
   333    // const CApListItemList* apList = iApiProvider->CommsModel().AccessPoints();
       
   334     // Fill the list.
       
   335     TInt i = 0;
       
   336     TInt count = aItems.Count();
       
   337     for ( i = 0; i < count; i++ )
       
   338         {
       
   339         iconIndexes->AppendL
       
   340             ( iIconHandler.IconIndexes(  *(aItems.At( i ) ) ) );
       
   341         }
       
   342     return iconIndexes;
       
   343     }
       
   344 
       
   345 // End of File