mmsharing/mmshindicator/src/musresourceutil.cpp
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Provides means to read resource strings from resource files.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "musresourcefinderutil.h"
       
    21 #include "muslogger.h"
       
    22 #include "musresourceutil.h"
       
    23 #include <f32file.h>
       
    24 #include <barsc.h>
       
    25 
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // Reads resource string from file.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 HBufC16* MusResourceUtil::ReadResourceString16LC( TUint aId, const TDesC& aFilename )
       
    35     {
       
    36     HBufC8* tmp = ReadResourceString8LC( aId, aFilename );
       
    37     HBufC* result = ConvertResourceStringLC( *tmp );
       
    38     CleanupStack::Pop( result );
       
    39     CleanupStack::PopAndDestroy( tmp );
       
    40     CleanupStack::PushL( result );
       
    41     return result;
       
    42     }
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // Reads resource string from file.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 HBufC16* MusResourceUtil::ReadResourceString16L( TUint aId, const TDesC& aFilename )
       
    50     {
       
    51     HBufC* result = ReadResourceString16LC( aId, aFilename );
       
    52     CleanupStack::Pop( result );
       
    53     return result;
       
    54     }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // Reads resource string from file.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 HBufC8* MusResourceUtil::ReadResourceString8LC( TUint aId, const TDesC& aFilename )
       
    62     {
       
    63     HBufC8* result = ReadResourceString8L( aId, aFilename );
       
    64     CleanupStack::PushL( result );
       
    65     return result;
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // Reads resource string from file.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 HBufC8* MusResourceUtil::ReadResourceString8L( TUint aId, const TDesC& aFilename )
       
    74     {
       
    75     MUS_LOG( "mus: [MUSIND ] -> MusIndicatorApi::ReadResourceString8L" )
       
    76 
       
    77     RFs fs;
       
    78     User::LeaveIfError( fs.Connect() );
       
    79     CleanupClosePushL( fs );
       
    80 
       
    81     HBufC* filenameBuf = ResourceFilenameLC( aFilename );
       
    82 
       
    83     TFileName filename( *filenameBuf );
       
    84 
       
    85     CleanupStack::PopAndDestroy( filenameBuf );
       
    86 
       
    87     RResourceFile resource;
       
    88     resource.OpenL( fs, filename );
       
    89     CleanupClosePushL( resource );
       
    90     resource.ConfirmSignatureL();
       
    91     HBufC8* resString;
       
    92     resString = resource.AllocReadL( aId );
       
    93     CleanupStack::PopAndDestroy(); // resource
       
    94     CleanupStack::PopAndDestroy(); // fs
       
    95 
       
    96     MUS_LOG( "mus: [MUSIND ] <- MusResourceUtil::ReadResourceString8L" )
       
    97     return resString;
       
    98     }
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // Converts HBufC8 to HBufC.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 HBufC* MusResourceUtil::ConvertResourceStringLC( const TDesC8& aText )
       
   106     {
       
   107     MUS_LOG( "mus: [MUSIND ] -> MusResourceUtil::ConvertResourceStringLC" )
       
   108     HBufC16* result = HBufC16::NewL( aText.Length() / 2 );
       
   109     result->Des().Copy( (TUint16*) aText.Ptr(), aText.Length() / 2 );
       
   110 
       
   111     // push dlgPrompt now to cleanup stack
       
   112     CleanupStack::PushL( result );
       
   113 
       
   114     MUS_LOG( "mus: [MUSIND ] <- MusResourceUtil::ConvertResourceStringLC" )
       
   115     return result;
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // Constructs name of resource file.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 HBufC* MusResourceUtil::ResourceFilenameLC( const TDesC& aFilename )
       
   124     {
       
   125     MUS_LOG( "mus: [MUSIND ]  -> MusResourceUtil::ResourceFilenameLC" )
       
   126     HBufC* fileName = MusResourceFinderUtil::ResourcePathL( aFilename );
       
   127     CleanupStack::PushL( fileName );
       
   128     MUS_LOG( "mus: [MUSIND ]  <- MusResourceUtil::ResourceFilenameLC" )
       
   129     return fileName;
       
   130     }