uigraphics/AknIcon/srvsrc/AknIconSrvTlsData.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:   TLS data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "AknIconSrvTlsData.h"
       
    22 #include "AknIconLoader.h"
       
    23 #include "AknIconLocationInfo.h"
       
    24 #include "AknIconFileNameCache.h"
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // ================= MEMBER FUNCTIONS ==========================================
       
    29 
       
    30 CAknIconSrvTlsData::CAknIconSrvTlsData()
       
    31     {
       
    32     }
       
    33 
       
    34 CAknIconSrvTlsData::~CAknIconSrvTlsData()
       
    35     {
       
    36     iIconSession.Close();
       
    37     delete iLoader;
       
    38     iFsSession.Close();
       
    39     iPointers.Close();
       
    40     delete iFileName;
       
    41     iIconLocations.ResetAndDestroy();
       
    42     delete iFileNameCache;
       
    43     Dll::FreeTls();
       
    44     }
       
    45 
       
    46 void CAknIconSrvTlsData::CreateSingletonL()
       
    47     {
       
    48     CAknIconSrvTlsData* data = new( ELeave ) CAknIconSrvTlsData;
       
    49     CleanupStack::PushL( data );
       
    50     data->ConstructL();
       
    51     CleanupStack::Pop();
       
    52     }
       
    53 
       
    54 void CAknIconSrvTlsData::ConstructL()
       
    55     {
       
    56     User::LeaveIfError( iIconSession.ConnectToServer() );
       
    57     iIconSession.GetInitData( iInitData );
       
    58     iFileNameCache = CAknIconFileNameCache::NewL();
       
    59     User::LeaveIfError( Dll::SetTls( this ) );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CAknIconSrvTlsData::InitIconLoaderL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CAknIconSrvTlsData::InitIconLoaderL( const TDesC& aFileName, RFile* aFile )
       
    67     {
       
    68     // If the icon file name is different than the one used by the existing icon loader,
       
    69     // create a new icon loader. It also opens the file.
       
    70     if ( !iFileName || iFileName->CompareF( aFileName ) != 0 )
       
    71         {
       
    72         delete iFileName;
       
    73         iFileName = NULL;
       
    74 
       
    75         delete iLoader;
       
    76         iLoader = NULL;
       
    77         
       
    78         if ( aFile )
       
    79             {
       
    80             iLoader = CAknIconLoader::NewL( *aFile );
       
    81             }
       
    82         else
       
    83             {
       
    84             iLoader = CAknIconLoader::NewL( FsSessionL(), aFileName );
       
    85             }
       
    86         
       
    87         iFileName = aFileName.AllocL();
       
    88         }
       
    89     // Icon loader exists for the requested icon file. Re-open the file.
       
    90     else
       
    91         {
       
    92         if ( aFile )
       
    93             {
       
    94             iLoader->OpenFileL( *aFile );
       
    95             }
       
    96         else
       
    97             {
       
    98             iLoader->OpenFileL( FsSessionL(), aFileName );
       
    99             }
       
   100         }
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CAknIconSrvTlsData::GetIconLocationInfo
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CAknIconSrvTlsData::GetIconLocationInfo(
       
   108     const TDesC& aFileName, TInt16& aBitmapId, TInt16& aMaskId )
       
   109     {
       
   110     // Compare item. Can be instantiated in stack with this constructor.
       
   111     CAknIconLocationInfo info( aFileName );
       
   112 
       
   113     TInt index = iIconLocations.FindInOrder( 
       
   114         &info, CAknIconLocationInfo::LinearOrder );
       
   115 
       
   116     if ( index >= 0 )
       
   117         {
       
   118         return iIconLocations[index]->GetIconLocation( aBitmapId, aMaskId );
       
   119         }
       
   120     else
       
   121         {
       
   122         return KErrNotFound;
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CAknIconSrvTlsData::StoreIconLocationInfoL
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CAknIconSrvTlsData::StoreIconLocationInfoL( CAknIconLocationInfo* aInfo )
       
   131     {
       
   132     User::LeaveIfError( iIconLocations.InsertInOrder(
       
   133         aInfo, CAknIconLocationInfo::LinearOrder ) );
       
   134     }
       
   135     
       
   136 // -----------------------------------------------------------------------------
       
   137 // CAknIconSrvTlsData::FsSessionL
       
   138 // -----------------------------------------------------------------------------
       
   139 //  
       
   140 RFs& CAknIconSrvTlsData::FsSessionL()
       
   141     {
       
   142     if ( !iFsSession.Handle() )
       
   143         {
       
   144         User::LeaveIfError( iFsSession.Connect() );
       
   145         }
       
   146         
       
   147     return iFsSession;
       
   148     }
       
   149 
       
   150 //  End of File