browserui/browser/FavouritesSrc/BrowserBookmarksModel.cpp
branchRCL_3
changeset 65 8e6fa1719340
equal deleted inserted replaced
64:6385c4c93049 65:8e6fa1719340
       
     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 CWmlBrowserBookmarksModel.
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "BrowserBookmarksModel.h"
       
    24 #include "BrowserUtil.h"
       
    25 #include <BrowserNG.rsg>
       
    26 #include <favouritesitem.h>
       
    27 #include <favouritesitemlist.h>
       
    28 #include <StringLoader.h>
       
    29 #include <FeatMgr.h>
       
    30 #include "ApiProvider.h"
       
    31 #include "Preferences.h"
       
    32 #include "CommonConstants.h"
       
    33 
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CBrowserBookmarksModel::CBrowserBookmarksModel
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CBrowserBookmarksModel::CBrowserBookmarksModel( MApiProvider& aApiProvider )
       
    42 	: CBrowserFavouritesModel( aApiProvider ), iApiProvider( aApiProvider )
       
    43 	{
       
    44 	}
       
    45 	
       
    46 // ---------------------------------------------------------
       
    47 // CBrowserBookmarksModel::ApiProvider
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 MApiProvider& CBrowserBookmarksModel::ApiProvider()
       
    51     {
       
    52     return iApiProvider;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CBrowserBookmarksModel::NewL
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CBrowserBookmarksModel* CBrowserBookmarksModel::NewL( MApiProvider& aApiProvider )
       
    60 	{
       
    61 	CBrowserBookmarksModel* model =
       
    62         new (ELeave) CBrowserBookmarksModel( aApiProvider );
       
    63 	CleanupStack::PushL( model );
       
    64 	model->ConstructL();
       
    65 	CleanupStack::Pop();
       
    66 	return model;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CBrowserBookmarksModel::StringResourceId
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 TInt CBrowserBookmarksModel::StringResourceId
       
    74         (
       
    75         const CFavouritesItem& aItem,
       
    76         CBrowserFavouritesModel::TTextResourceType aType
       
    77         ) const
       
    78     {
       
    79     switch ( aType )
       
    80         {
       
    81         case CBrowserFavouritesModel::EDefaultName:
       
    82             {
       
    83             if ( aItem.IsFolder() )
       
    84                 {
       
    85                 return R_BROWSER_FAVOURITES_TEXT_FLDR_NAME_DEFAULT;
       
    86                 }
       
    87             else
       
    88                 {
       
    89                 return R_BROWSER_BOOKMARKS_TEXT_DEFAULT_BM_TITLE;
       
    90                 }
       
    91             }
       
    92 
       
    93         case CBrowserFavouritesModel::ERenamePrompt:
       
    94             {
       
    95             if ( aItem.IsFolder() )
       
    96                 {
       
    97                 return R_BROWSER_FAVOURITES_TEXT_FLDR_ITEM_NAME_PRMPT;
       
    98                 }
       
    99             else
       
   100                 {
       
   101                 return R_BROWSER_FAVOURITES_TEXT_PRMPT_EDIT_NAME;
       
   102                 }
       
   103             }
       
   104 
       
   105         case CBrowserFavouritesModel::ENewPrompt:
       
   106             {
       
   107             if ( aItem.IsFolder() )
       
   108                 {
       
   109                 return R_BROWSER_FAVOURITES_TEXT_FLDR_NAME_PRMPT;
       
   110                 }
       
   111             else
       
   112                 {
       
   113                 return R_BROWSER_FAVOURITES_TEXT_PRMPT_EDIT_NAME;
       
   114                 }
       
   115             }
       
   116 
       
   117         case CBrowserFavouritesModel::ESaved:
       
   118             {
       
   119             return R_BROWSER_BOOKMARKS_TEXT_BM_SAVED;
       
   120             }
       
   121 
       
   122         case CBrowserFavouritesModel::ENotSaved:
       
   123             {
       
   124             return R_BROWSER_BOOKMARKS_TEXT_BM_NOT_SAVED;
       
   125             }
       
   126 
       
   127         default:
       
   128             {
       
   129             break;
       
   130             }
       
   131         }
       
   132 
       
   133     Util::Panic( Util::EUnExpected );
       
   134     /*NOTREACHED*/
       
   135     return 0;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CBrowserBookmarksModel::GetFoldersSortedLC
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 CFavouritesItemList* CBrowserBookmarksModel::GetFoldersSortedLC()
       
   143     {
       
   144     CFavouritesItemList* folders = new (ELeave) CFavouritesItemList();
       
   145     CleanupStack::PushL( folders );
       
   146 
       
   147     if ((ADAPTIVEBOOKMARKS)&&(ApiProvider().Preferences().AdaptiveBookmarks()==EWmlSettingsAdaptiveBookmarksOn ))
       
   148         {
       
   149         CFavouritesItem* adaptiveItemsFolder = Database().CreateAdaptiveItemsFolderL();
       
   150         CleanupStack::PushL(adaptiveItemsFolder);
       
   151         HBufC* folderName=StringLoader::LoadLC(R_BROWSER_ADAPTIVE_BOOKMARKS_FOLDER);
       
   152         adaptiveItemsFolder->SetNameL(*folderName);
       
   153         CleanupStack::PopAndDestroy();//folderName
       
   154         folders->AppendL( adaptiveItemsFolder );
       
   155         CleanupStack::Pop();    // adaptiveItemsFolder: owner is the list now.
       
   156         }
       
   157 
       
   158     // Get all folders.
       
   159     Database().GetAll( *folders, KFavouritesRootUid, CFavouritesItem::EFolder );
       
   160     // Sort folders,
       
   161     CBrowserBookmarksOrder* currentOrder = CBrowserBookmarksOrder::NewLC();
       
   162     CArrayFixFlat<TInt>* orderArray = new (ELeave) CArrayFixFlat<TInt>(KGranularityHigh);
       
   163     CleanupStack::PushL(orderArray);
       
   164     if( Database().GetData( KFavouritesRootUid ,*currentOrder ) == KErrNone )
       
   165         {
       
   166         if( currentOrder->GetBookMarksOrder().Count() > 0 )
       
   167             {
       
   168             orderArray->AppendL( &( currentOrder->GetBookMarksOrder()[0] ), currentOrder->GetBookMarksOrder().Count());
       
   169             ManualSortL(KFavouritesRootUid, currentOrder, orderArray, folders);
       
   170             }
       
   171         }
       
   172     CleanupStack::PopAndDestroy(2); //currentOrder, orderArray
       
   173 
       
   174     return folders;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------
       
   178 // CBrowserBookmarksModel::GetDBName
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 const TDesC& CBrowserBookmarksModel::GetDBName()
       
   182     {
       
   183     return KBrowserBookmarks; 
       
   184     }
       
   185 
       
   186 // End of File