phonebookui/Phonebook2/Presentation/src/RPbk2LocalizedResourceFile.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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: 
       
    15 *     Localized resource file for Phonebook 2.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <RPbk2LocalizedResourceFile.h>
       
    22 
       
    23 // From System
       
    24 #include <coemain.h>
       
    25 #include <bautils.h>
       
    26 
       
    27 // Debugging headers
       
    28 #include <Pbk2Debug.h>
       
    29 
       
    30 // Unnamed namespace for local definitions
       
    31 namespace {
       
    32 // Definition for backslash
       
    33 _LIT(KBackslash, "\\");
       
    34 
       
    35 /**
       
    36  * Ensures that path includes backslashs in correct places. Either left hand
       
    37  * side descriptor's or right hand side's last descriptor needs to be 
       
    38  * backslash. If backslash is not found, it is added to result descriptor
       
    39  *
       
    40  * @param aLhs      Left hand side operator.
       
    41  * @param aRhs      Right hand side operator.
       
    42  * @param aResult   On return contains correctly modified descriptor.
       
    43  */
       
    44 void EnsureBackslashInMiddle(
       
    45         const TDesC& aLhs, 
       
    46         const TDesC& aRhs, 
       
    47         TDes& aResult)
       
    48     {
       
    49     if (aLhs[aLhs.Length() - 1] != KBackslash()[0] &&
       
    50         (aRhs.Length() == 0 || aRhs[0] != KBackslash()[0]))
       
    51         {
       
    52         aResult.Append(KBackslash);
       
    53         }
       
    54     }
       
    55 } // namespace
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // RPbk2LocalizedResourceFile::RPbk2LocalizedResourceFile
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C RPbk2LocalizedResourceFile::RPbk2LocalizedResourceFile(
       
    64         CCoeEnv& aCoeEnv) :
       
    65     iFs( &aCoeEnv.FsSession() ), iCoeEnv(&aCoeEnv), iOffset(0)
       
    66     {
       
    67     }
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // RPbk2LocalizedResourceFile::RPbk2LocalizedResourceFile
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C RPbk2LocalizedResourceFile::RPbk2LocalizedResourceFile( RFs* aFs ) :
       
    74         iFs( aFs ), iCoeEnv( NULL ), iOffset( 0 )
       
    75     {
       
    76     }
       
    77     
       
    78 // --------------------------------------------------------------------------
       
    79 // RPbk2LocalizedResourceFile::OpenLC
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C void RPbk2LocalizedResourceFile::OpenLC
       
    83         (const TDesC& aDrive, const TDesC& aPath, const TDesC& aFileName)
       
    84     {
       
    85     EnsureOpenFileSystemSessionL();
       
    86     
       
    87     TFileName fileName(aDrive);
       
    88     EnsureBackslashInMiddle(fileName, aPath, fileName);
       
    89     fileName.Append(aPath);
       
    90     EnsureBackslashInMiddle(fileName, aFileName, fileName);
       
    91     fileName.Append(aFileName);
       
    92 
       
    93     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
    94         ("RPbk2LocalizedResourceFile::OpenLC() resource filename: %S"),
       
    95         &fileName);
       
    96 
       
    97     BaflUtils::NearestLanguageFile(*iFs, fileName);
       
    98     
       
    99     if ( iCoeEnv )
       
   100         {
       
   101         iOffset = iCoeEnv->AddResourceFileL(fileName);
       
   102         CleanupClosePushL(*this);
       
   103         }
       
   104     else
       
   105         {
       
   106         RResourceFile::OpenL(*iFs, fileName);
       
   107         CleanupClosePushL(*this);
       
   108         ConfirmSignatureL();
       
   109         }
       
   110     }
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // RPbk2LocalizedResourceFile::OpenL
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C void RPbk2LocalizedResourceFile::OpenL
       
   117         (const TDesC& aDrive, const TDesC& aPath, const TDesC& aFileName)
       
   118     {
       
   119     OpenLC(aDrive, aPath, aFileName);
       
   120     CleanupStack::Pop();
       
   121     }
       
   122 
       
   123 // --------------------------------------------------------------------------
       
   124 // RPbk2LocalizedResourceFile::OpenL
       
   125 // --------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C void RPbk2LocalizedResourceFile::OpenL(const TDesC& aFullPath)
       
   128     {
       
   129     EnsureOpenFileSystemSessionL();
       
   130     
       
   131     TFileName fileName(aFullPath);
       
   132 
       
   133     BaflUtils::NearestLanguageFile(*iFs, fileName);
       
   134     if ( iCoeEnv )
       
   135         {
       
   136         iOffset = iCoeEnv->AddResourceFileL(fileName);
       
   137         }
       
   138     else
       
   139         {
       
   140         RResourceFile::OpenL(*iFs, fileName);
       
   141         ConfirmSignatureL();
       
   142         }
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // RPbk2LocalizedResourceFile::Close
       
   147 // --------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C void RPbk2LocalizedResourceFile::Close()
       
   150     {
       
   151     if (iOffset && iCoeEnv)
       
   152         {
       
   153         iCoeEnv->DeleteResourceFile(iOffset);
       
   154         iOffset = 0;
       
   155         }
       
   156     else
       
   157         {
       
   158         RResourceFile::Close();
       
   159         }
       
   160     
       
   161     if ( iOwnFs.Handle() )
       
   162         {
       
   163         iOwnFs.Close();
       
   164         }
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // RPbk2LocalizedResourceFile::Offset
       
   169 // --------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C TInt RPbk2LocalizedResourceFile::Offset()
       
   172     {
       
   173     return iOffset;
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // RPbk2LocalizedResourceFile::EnsureOpenFileSystemSessionL
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180 void RPbk2LocalizedResourceFile::EnsureOpenFileSystemSessionL()
       
   181     {
       
   182     if ( !iFs )
       
   183         {
       
   184         User::LeaveIfError( iOwnFs.Connect() );
       
   185         iFs = &iOwnFs;
       
   186         }
       
   187     }
       
   188 // End of File