wvuing/wvvariant/Src/CCAIconFileProvider.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 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:  Icon file provider.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "ccaiconfileprovider.h"
       
    21 #include	<aknappui.h>
       
    22 #include    <akniconutils.h>
       
    23 
       
    24 _LIT( KMif, ".mif" );
       
    25 _LIT( KMbm, ".mbm" );
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CCAIconFileProvider::CCAIconFileProvider
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CCAIconFileProvider::CCAIconFileProvider( RFs& aFs )
       
    36         :   iFs( aFs )
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CCAIconFileProvider::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CCAIconFileProvider::ConstructL( const TDesC& aIconFilename )
       
    46     {
       
    47     iFilename = aIconFilename.AllocL();
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCAIconFileProvider::NewL
       
    52 // Two-phased constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CCAIconFileProvider* CCAIconFileProvider::NewL(
       
    56     RFs& aFs, const TDesC& aIconFilename )
       
    57     {
       
    58     CCAIconFileProvider* self = new( ELeave ) CCAIconFileProvider( aFs );
       
    59 
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL( aIconFilename );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // Destructor
       
    67 CCAIconFileProvider::~CCAIconFileProvider()
       
    68     {
       
    69     delete iFilename;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCAIconFileProvider::RetrieveIconFileHandleL
       
    74 // (other items were commented in a header).
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CCAIconFileProvider::RetrieveIconFileHandleL(
       
    78     RFile& aFile, const TIconFileType aType )
       
    79     {
       
    80     if ( ! iFilename->Length() )
       
    81         {
       
    82         User::Leave( KErrNotFound );
       
    83         }
       
    84 
       
    85     // get the wanted extension
       
    86     TPtrC ext( aType == MAknIconFileProvider::EMbmFile ? KMbm : KMif );
       
    87     TInt extLen( ext.Length() );
       
    88 
       
    89     // and replace it to given filename
       
    90     HBufC* name = iFilename->AllocLC();
       
    91     TPtr namePtr( name->Des() );
       
    92     TInt nameLen( namePtr.Length() );
       
    93 
       
    94     if ( nameLen <= extLen )
       
    95         {
       
    96         // name was invalid
       
    97         User::Leave( KErrArgument );
       
    98         }
       
    99 
       
   100     namePtr.Replace( nameLen - extLen, extLen, ext );
       
   101 
       
   102     // load file
       
   103     TInt retCode = aFile.Open( iFs, namePtr, EFileRead | EFileShareReadersOnly );
       
   104     User::LeaveIfError( retCode );
       
   105     CleanupStack::PopAndDestroy( name );
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCAIconFileProvider::Finished
       
   110 // (other items were commented in a header).
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CCAIconFileProvider::Finished()
       
   114     {
       
   115     // commit suicide because Avkon Icon Server said so
       
   116     delete this;
       
   117     }
       
   118 
       
   119 //  End of File