commonuis/CommonUi/inc/DocResourceFile.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Tiny helper class for adding and removing DocHandler's 
       
    15 *                resource file for resource pool of the client app
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef DOCRESOURCEFILE_H
       
    21 #define DOCRESOURCEFILE_H
       
    22 
       
    23 #include <bautils.h>                // For NearestLanguageFile(..)
       
    24 
       
    25 class CDocResourceFile : public CBase
       
    26     {
       
    27     public:
       
    28     // Constructor
       
    29         CDocResourceFile( const TDesC& aResFilename, RFs& aFs ) : 
       
    30             iResFilename( aResFilename ),
       
    31             iFs( aFs )            
       
    32         {        
       
    33 #ifdef _DEBUG
       
    34         iResCount = 0;
       
    35 #endif
       
    36         }
       
    37 
       
    38     // Destructor
       
    39     ~CDocResourceFile()
       
    40         {
       
    41         CEikonEnv::Static()->DeleteResourceFile( iResFileOffset ); 
       
    42 #ifdef _DEBUG 
       
    43         RDebug::Print( _L("DocumentHandler: CDocResourceFile::~CDocResourceFile : %S removed. Count: %d"), &iResFilename, --iResCount);
       
    44 #endif
       
    45         }
       
    46 
       
    47     // Add resource file to the resource pool.
       
    48     // Pushes it self to the cleanupStack.
       
    49     static void AddLC( 
       
    50        const TDesC& aResFilename,   // Resource file name
       
    51        RFs& aFs )                   // Connected FileServer client 
       
    52         {
       
    53         CDocResourceFile* self = 
       
    54             new ( ELeave ) CDocResourceFile( aResFilename, aFs );
       
    55         CleanupStack::PushL( self );
       
    56         self->ConstructL();
       
    57         }
       
    58 
       
    59     // Removes the resource file and destroys it self
       
    60     static void Remove()
       
    61        {
       
    62         CleanupStack::PopAndDestroy(); // self
       
    63        }
       
    64    
       
    65     private:
       
    66 
       
    67     // Epoc constructor
       
    68     void ConstructL()
       
    69         {
       
    70         TFileName resourceFile( iResFilename );
       
    71         BaflUtils::NearestLanguageFile( iFs, resourceFile );
       
    72         iResFileOffset = CCoeEnv::Static()->AddResourceFileL( resourceFile );
       
    73 #ifdef _DEBUG 
       
    74         RDebug::Print( _L("DocumentHandler: CDocResourceFile::ConstructL : %S added. Count: %d"), &iResFilename, ++iResCount );
       
    75 #endif
       
    76         }
       
    77 
       
    78     // Remember the resrource file offset
       
    79     TInt iResFileOffset;
       
    80 
       
    81     // Resource filename
       
    82     TFileName iResFilename;
       
    83     
       
    84     // File server client
       
    85     RFs iFs;
       
    86 
       
    87 #ifdef _DEBUG 
       
    88     TInt iResCount;
       
    89 #endif
       
    90     };
       
    91 
       
    92 #endif      // DOCRESOURCEFILE_H
       
    93             
       
    94 // End of File