uigraphics/AknIcon/src/AknFileProviderIconManager.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     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 "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:   Implementation of class CAknFileProviderIconManager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <mifconvdefs.h>
       
    23 #include "AknFileProviderIconManager.h"
       
    24 #include "AknIconUtils.h"
       
    25 #include "AknBitmap.h"
       
    26 #include "AknIconPanic.h"
       
    27 #include "AknIconTraces.h"
       
    28 
       
    29 
       
    30 // ============================ GLOBAL FUNCTIONS ===============================
       
    31 
       
    32 GLREF_C void CleanupFileProvider( TAny* aParam )
       
    33     {
       
    34     static_cast<MAknIconFileProvider*>( aParam )->Finished();
       
    35     }
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CAknFileProviderIconManager::CAknFileProviderIconManager
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CAknFileProviderIconManager::CAknFileProviderIconManager(
       
    46     MAknIconFileProvider& aFileProvider,
       
    47     const TInt16 aBitmapId,
       
    48     const TInt16 aMaskId ) :
       
    49         iFileProvider( aFileProvider ), iFileType( -1 )
       
    50 	{
       
    51     iBitmapId = aBitmapId;
       
    52     iMaskId = aMaskId;
       
    53 	}
       
    54 
       
    55 CAknFileProviderIconManager* CAknFileProviderIconManager::NewL(
       
    56     MAknIconFileProvider& aFileProvider,
       
    57     const TInt16 aBitmapId,
       
    58     const TInt16 aMaskId )
       
    59     {
       
    60     // Make sure that MAknIconFileProvider::Finished is called if manager creation fails.
       
    61     CleanupStack::PushL( TCleanupItem( CleanupFileProvider, &aFileProvider ) );
       
    62 
       
    63     CAknFileProviderIconManager* self = new( ELeave )
       
    64         CAknFileProviderIconManager( aFileProvider, aBitmapId, aMaskId );
       
    65 
       
    66     // From now on, MAknIconFileProvider::Finished is called by
       
    67     // CAknFileProviderIconManager destructor.
       
    68 
       
    69     CleanupStack::Pop(); // CleanupFileProvider
       
    70 
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop();
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CAknFileProviderIconManager::ConstructL
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CAknFileProviderIconManager::ConstructL()
       
    83     {
       
    84     FileHandleL( MAknIconFileProvider::EMifFile );
       
    85     
       
    86     // Verify the file name and store information of it.
       
    87     TFileName name;
       
    88     User::LeaveIfError( iFile.FullName( name ) ); // This causes a server call.
       
    89 
       
    90 #ifdef __AKNICON_TRACES
       
    91     RDebug::Print( _L("AknIcon: %x CAknFileProviderIconManager::ConstructL - iFile: %S"), this, &name);
       
    92 #endif   
       
    93     // Test that the given file has the correct extension.
       
    94     if ( name.Length() <= KExtensionLength )
       
    95         {
       
    96         User::Leave( KErrArgument );
       
    97         }
       
    98 
       
    99     if ( name.Right( KExtensionLength ).CompareF( KMifExtension ) )
       
   100         {
       
   101         User::Leave( KErrArgument );
       
   102         }
       
   103 
       
   104     InitIconFileNameL(name);    
       
   105     }
       
   106 
       
   107 // Destructor
       
   108 CAknFileProviderIconManager::~CAknFileProviderIconManager()
       
   109     {
       
   110     iFile.Close();
       
   111 
       
   112     // Informs the file provider object that it is not needed any more.
       
   113     // It is the responsibility of its implementation to take care of
       
   114     // deleting self.
       
   115     iFileProvider.Finished();
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CAknFileProviderIconManager::LoadBitmapIconL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CAknFileProviderIconManager::LoadBitmapIconL()
       
   123     {
       
   124     RFile* file = FileHandleL( MAknIconFileProvider::EMbmFile );
       
   125 
       
   126     User::LeaveIfError( iBitmap->Load( *file, iBitmapId ) );
       
   127     
       
   128     if ( iMask )
       
   129         {
       
   130         User::LeaveIfError( iMask->Load( *file, iMaskId ) );
       
   131         }
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CAknFileProviderIconManager::FileHandleL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 RFile* CAknFileProviderIconManager::FileHandleL(
       
   139     MAknIconFileProvider::TIconFileType aType )
       
   140     {
       
   141     if ( !iFile.SubSessionHandle() || iFileType != aType )
       
   142         {
       
   143         iFile.Close();
       
   144         iFileType = -1;
       
   145         iFileProvider.RetrieveIconFileHandleL( iFile, aType );
       
   146         iFileType = aType;
       
   147 #ifdef _DEBUG        
       
   148         // Verify that the file name has not changed after calling ConstructL
       
   149         if (iFileName)
       
   150             {                  
       
   151             TFileName origname, currname;
       
   152             GetFullFileName( origname );
       
   153             User::LeaveIfError( iFile.FullName( currname ) ); 
       
   154             if (origname.Length() < KExtensionLength ||
       
   155                 currname.Length() < KExtensionLength ||
       
   156                 (origname.SetLength( origname.Length() - KExtensionLength ),
       
   157                  currname.SetLength( currname.Length() - KExtensionLength ),
       
   158                  origname.CompareF(currname)))
       
   159                 {
       
   160                 User::Panic( KAknIconPanicCategory, EFileProviderCorrupt );
       
   161                 }
       
   162             }            
       
   163 #endif        
       
   164         }
       
   165 
       
   166     return &iFile;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CAknFileProviderIconManager::ReleaseFileHandle
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CAknFileProviderIconManager::ReleaseFileHandle()
       
   174     {
       
   175     CAknIconManager::ReleaseFileHandle();
       
   176     iFile.Close();
       
   177     }
       
   178 
       
   179 //  End of File