filemanager/View/src/CFileManagerIconArray.cpp
branchRCL_3
changeset 39 65326cf895ed
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  All the files and folders icons are stored here
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <FileManagerEngine.hrh>
       
    21 #include <barsread.h>
       
    22 #include <coemain.h>
       
    23 #include <gulicon.h>
       
    24 #include <AknsItemID.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <filemanagerview.rsg>
       
    27 #include "CFileManagerIconArray.h"
       
    28 #include "FileManagerView.hrh"
       
    29 
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KGranularity = 1;
       
    34 
       
    35 // needed because _LIT macro does not expand parameter, which is also macro
       
    36 #define _CREATE_LIT( a, b ) _LIT( a, b )
       
    37 
       
    38 _CREATE_LIT( KFileManagerMifFile, filemanager_mbm_file_location );
       
    39 
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CFileManagerIconArray::CFileManagerIconArray
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CFileManagerIconArray::CFileManagerIconArray() :
       
    50         CArrayPtrFlat( KGranularity )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFileManagerIconArray::NewL
       
    56 // 
       
    57 // -----------------------------------------------------------------------------
       
    58 // 
       
    59 EXPORT_C CFileManagerIconArray* CFileManagerIconArray::NewL()
       
    60     {
       
    61     CFileManagerIconArray* self = new (ELeave) CFileManagerIconArray();
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CFileManagerIconArray::ConstructL
       
    70 // 
       
    71 // -----------------------------------------------------------------------------
       
    72 // 
       
    73 void CFileManagerIconArray::ConstructL()
       
    74     {
       
    75     TResourceReader reader;
       
    76     CCoeEnv::Static()->CreateResourceReaderLC(
       
    77         reader, R_FILEMANAGER_ICON_ARRAY );
       
    78 
       
    79     TInt count( reader.ReadInt16() );
       
    80     iIconInfo.ReserveL( count );
       
    81     SetReserveL( count );
       
    82 
       
    83     // Get File Manager mif drive from exe location
       
    84     TFileName exeFileName( RProcess().FileName() );
       
    85 
       
    86     // Load icon info now and actual icon data later when needed to decrease
       
    87     // construction time
       
    88     for( TInt i( 0 ); i < count; i++ )
       
    89         {
       
    90         TIconInfo info;
       
    91 
       
    92         info.iId = reader.ReadInt8();
       
    93         info.iFile = reader.ReadHBufCL();
       
    94         info.iIconId = reader.ReadInt16();
       
    95 
       
    96         TPtr ptr( info.iFile->Des() );
       
    97         if ( !ptr.CompareF( KFileManagerMifFile ) )
       
    98             {
       
    99             // Set correct File Manager mif drive
       
   100             ptr[ 0 ] = exeFileName[ 0 ];
       
   101             }
       
   102 
       
   103         info.iMaskId =  reader.ReadInt16();
       
   104         info.iMajorSkinId = reader.ReadInt32();
       
   105         info.iMinorSkinId = reader.ReadInt32();
       
   106         info.iIconType = reader.ReadInt8();
       
   107         info.iIndex = KErrNotFound;
       
   108 
       
   109         CleanupStack::PushL( info.iFile );
       
   110         iIconInfo.AppendL( info );
       
   111         CleanupStack::Pop( info.iFile );
       
   112         }
       
   113 
       
   114     CleanupStack::PopAndDestroy(); // reader
       
   115 
       
   116     LoadMandatoryIconsL();
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CFileManagerIconArray::~CFileManagerIconArray
       
   121 // Destructor
       
   122 // -----------------------------------------------------------------------------
       
   123 // 
       
   124 EXPORT_C CFileManagerIconArray::~CFileManagerIconArray()
       
   125     {
       
   126     TInt count( iIconInfo.Count() );
       
   127     for( TInt i( 0 ); i < count; i++ )
       
   128         {
       
   129         TIconInfo& info = iIconInfo[ i ];
       
   130         delete info.iFile;
       
   131         info.iFile = NULL;
       
   132         }
       
   133     iIconInfo.Close();
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CFileManagerIconArray::UpdateIconsL
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 // 
       
   141 EXPORT_C void CFileManagerIconArray::UpdateIconsL()
       
   142     {
       
   143     // Remove icon data and set info to load icon data again when needed
       
   144     ResetAndDestroy();
       
   145 
       
   146     TInt count( iIconInfo.Count() );
       
   147     SetReserveL( count );
       
   148 
       
   149     for( TInt i( 0 ); i < count; i++ )
       
   150         {
       
   151         TIconInfo& info = iIconInfo[ i ];
       
   152         info.iIndex = KErrNotFound;
       
   153         }
       
   154 
       
   155     LoadMandatoryIconsL();
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CFileManagerIconArray::FindIcon
       
   160 //
       
   161 // -----------------------------------------------------------------------------
       
   162 // 
       
   163 EXPORT_C TInt CFileManagerIconArray::FindIcon( TInt aIconId )
       
   164     {
       
   165     TInt count( iIconInfo.Count() );
       
   166     for( TInt i( 0 ); i < count; i++ )
       
   167         {
       
   168         TIconInfo& info = iIconInfo[ i ];
       
   169         if ( info.iId == aIconId )
       
   170             {
       
   171             if ( info.iIndex == KErrNotFound )
       
   172                 {
       
   173                 TRAPD( err, LoadIconL( info ) );
       
   174                 if ( err != KErrNone )
       
   175                     {
       
   176                     return err;
       
   177                     }
       
   178                 }
       
   179             return info.iIndex;
       
   180             }
       
   181         }
       
   182     return KErrNotFound;
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CFileManagerIconArray::LoadIconL
       
   187 //
       
   188 // -----------------------------------------------------------------------------
       
   189 // 
       
   190 void CFileManagerIconArray::LoadIconL( TIconInfo& aInfo )
       
   191     {
       
   192     CGulIcon* icon = LoadIconL(
       
   193         *aInfo.iFile,
       
   194         aInfo.iIconId,
       
   195         aInfo.iMaskId,
       
   196         aInfo.iMajorSkinId,
       
   197         aInfo.iMinorSkinId,
       
   198         aInfo.iIconType == EFileManagerIconColorIcon );
       
   199     CleanupStack::PushL( icon );
       
   200     TInt index( Count() );
       
   201     AppendL( icon );
       
   202     CleanupStack::Pop( icon );
       
   203     aInfo.iIndex = index;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CFileManagerIconArray::LoadMandatoryIconsL
       
   208 // 
       
   209 // -----------------------------------------------------------------------------
       
   210 // 
       
   211 void CFileManagerIconArray::LoadMandatoryIconsL()
       
   212     {
       
   213     // At least these icons must be loaded on startup.
       
   214     // Other icons can be loaded first time when needed.
       
   215 
       
   216     // Make sure that selection icon is always loaded to first index.
       
   217     // Required by list control.
       
   218     User::LeaveIfError( FindIcon( EFileManagerMarkIcon ) );
       
   219 
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CFileManagerIconArray::LoadIconL
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 // 
       
   227 EXPORT_C CGulIcon* CFileManagerIconArray::LoadIconL(
       
   228         const TDesC& aIconFile,
       
   229         TInt aIconId,
       
   230         TInt aMaskId,
       
   231         TInt aMajorSkin,
       
   232         TInt aMinorSkin,
       
   233         TBool aIsColorIcon )
       
   234     {
       
   235     TAknsItemID aknsItemId;
       
   236     aknsItemId.Set( aMajorSkin, aMinorSkin );
       
   237     MAknsSkinInstance* aknsSkin = AknsUtils::SkinInstance();
       
   238     CGulIcon* ret = NULL;
       
   239     if ( aIsColorIcon )
       
   240         {
       
   241         TRgb defaultColour( KRgbBlack );
       
   242         CFbsBitmap* bmap = NULL;
       
   243         CFbsBitmap* mask = NULL;
       
   244         AknsUtils::GetCachedColor(
       
   245             aknsSkin,
       
   246             defaultColour,
       
   247             KAknsIIDQsnIconColors,
       
   248             EAknsCIQsnIconColorsCG13 );
       
   249         AknsUtils::CreateColorIconLC(
       
   250             aknsSkin,
       
   251             aknsItemId,
       
   252             KAknsIIDQsnIconColors,
       
   253             EAknsCIQsnIconColorsCG13,
       
   254             bmap,
       
   255             mask,
       
   256             aIconFile,
       
   257             aIconId,
       
   258             aMaskId,
       
   259             defaultColour );
       
   260         ret = CGulIcon::NewL( bmap, mask );
       
   261         ret->SetBitmapsOwnedExternally( EFalse );
       
   262         CleanupStack::Pop( 2 ); // icon owns the bitmaps now
       
   263         }
       
   264     else
       
   265         {
       
   266         ret = AknsUtils::CreateGulIconL(
       
   267             aknsSkin, aknsItemId, aIconFile, aIconId, aMaskId );
       
   268         ret->SetBitmapsOwnedExternally( EFalse );
       
   269         }
       
   270     return ret;
       
   271     }
       
   272 
       
   273 //  End of File