filemanager/Engine/src/CFilemanagerMimeIconArray.cpp
branchRCL_3
changeset 39 65326cf895ed
parent 0 6a9f87576119
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Maps the mime or file extension to icon
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <barsread.h>
       
    22 #include <AknUtils.h> 
       
    23 #include <coemain.h> 
       
    24 #include "CFilemanagerMimeIconArray.h"
       
    25 #include "CGflmNavigatorModel.h"
       
    26 #include "CDirectoryLocalizer.h"
       
    27 #include "CFileManagerCommonDefinitions.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CFileManagerMimeIconArray::NewL
       
    34 // 
       
    35 // -----------------------------------------------------------------------------
       
    36 // 
       
    37 CFileManagerMimeIconArray* CFileManagerMimeIconArray::NewL(
       
    38         TInt aResId, CGflmNavigatorModel& aNavigator )
       
    39     {
       
    40     CFileManagerMimeIconArray* self = new( ELeave )
       
    41         CFileManagerMimeIconArray( aNavigator );
       
    42 
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructFromResourceL( aResId );
       
    45     CleanupStack::Pop( self );
       
    46 
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CFileManagerMimeIconArray::CFileManagerMimeIconArray
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CFileManagerMimeIconArray::CFileManagerMimeIconArray(
       
    57         CGflmNavigatorModel& aNavigator )
       
    58         : iNavigator( aNavigator )
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CFileManagerMimeIconArray::ConstructFromResourceL
       
    64 // 
       
    65 // -----------------------------------------------------------------------------
       
    66 // 
       
    67 void CFileManagerMimeIconArray::ConstructFromResourceL( TInt aResId )
       
    68     {
       
    69     TResourceReader reader;
       
    70     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );
       
    71     
       
    72     TInt count( reader.ReadInt16() );
       
    73 
       
    74     iArray.ReserveL( count );
       
    75 
       
    76     for( TInt i( 0 ); i < count; i++ )
       
    77         {
       
    78         const TPtrC mime( reader.ReadTPtrC() );
       
    79         const TInt iconId( reader.ReadInt16() );
       
    80         CMimeIconEntry* entry = CMimeIconEntry::NewLC( mime, iconId );
       
    81         iArray.AppendL( entry );
       
    82         CleanupStack::Pop( entry );
       
    83         }
       
    84 
       
    85     CleanupStack::PopAndDestroy(); // reader
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CFileManagerMimeIconArray::~CFileManagerMimeIconArray
       
    90 // Destructor
       
    91 // -----------------------------------------------------------------------------
       
    92 // 
       
    93 CFileManagerMimeIconArray::~CFileManagerMimeIconArray()
       
    94     {
       
    95     iArray.ResetAndDestroy();
       
    96     iArray.Close();
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CFileManagerMimeIconArray::ResolveIconL
       
   101 // 
       
   102 // -----------------------------------------------------------------------------
       
   103 // 
       
   104 TInt CFileManagerMimeIconArray::ResolveIconL( const TDesC& aFullPath )
       
   105     {
       
   106     TPtrC fileType( iNavigator.ResolveMimeTypeL( aFullPath ) );
       
   107     TParsePtrC parse( aFullPath );
       
   108     TPtrC fileExt( parse.Ext() );
       
   109     TInt count( iArray.Count() );
       
   110 
       
   111     for( TInt i( 0 ); i < count; ++i )
       
   112         {
       
   113         CMimeIconEntry* entry = iArray[ i ];
       
   114         TPtrC mime( entry->iMime->Des() );
       
   115         if ( fileType.FindF( mime ) != KErrNotFound ||
       
   116             fileExt.FindF( mime ) != KErrNotFound )
       
   117             {
       
   118             return entry->iIconId;
       
   119             }
       
   120         }
       
   121     if ( fileType.Length() )
       
   122         {
       
   123         // File is recognized, but there is no own icon defined for this type.
       
   124         // Use note icon to indicate the user that file is not unsupported.
       
   125         return EFileManagerNoteFileIcon;
       
   126         }
       
   127     return EFileManagerOtherFileIcon;
       
   128     }
       
   129 
       
   130 //-------------------------------------------------------------------------------
       
   131 // CFileManagerMimeIconArray::CMimeIconEntry::CMimeIconEntry
       
   132 // 
       
   133 // -----------------------------------------------------------------------------
       
   134 // 
       
   135 CFileManagerMimeIconArray::CMimeIconEntry::CMimeIconEntry(
       
   136         const TInt aIconId ) :
       
   137     iIconId( aIconId )
       
   138     {
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CFileManagerMimeIconArray::CMimeIconEntry::~CMimeIconEntry
       
   143 // 
       
   144 // -----------------------------------------------------------------------------
       
   145 // 
       
   146 CFileManagerMimeIconArray::CMimeIconEntry::~CMimeIconEntry()
       
   147     {
       
   148     delete iMime;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CFileManagerMimeIconArray::CMimeIconEntry::NewLC
       
   153 // 
       
   154 // -----------------------------------------------------------------------------
       
   155 // 
       
   156 CFileManagerMimeIconArray::CMimeIconEntry*
       
   157     CFileManagerMimeIconArray::CMimeIconEntry::NewLC(
       
   158         const TDesC& aMime, const TInt aIconId )
       
   159     {
       
   160     CMimeIconEntry* self = new( ELeave ) CMimeIconEntry( aIconId );
       
   161     CleanupStack::PushL( self );
       
   162     self->ConstructL( aMime );
       
   163     return self;
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CFileManagerMimeIconArray::CMimeIconEntry::ConstructL
       
   168 // 
       
   169 // -----------------------------------------------------------------------------
       
   170 // 
       
   171 void CFileManagerMimeIconArray::CMimeIconEntry::ConstructL(
       
   172         const TDesC& aMime )
       
   173     {
       
   174     iMime = aMime.AllocL();
       
   175     }
       
   176 
       
   177 //  End of File