filemanager/GFLM/src/CGflmItemLocalizer.cpp
changeset 0 6a9f87576119
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     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:  This class is used to provide localized names
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CGflmItemLocalizer.h"
       
    22 #include "GflmUtils.h"
       
    23 #include "GFLM.hrh"
       
    24 #include <CDirectoryLocalizer.h>
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CGflmItemLocalizer::CGflmItemLocalizer
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CGflmItemLocalizer::CGflmItemLocalizer()
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CGflmItemLocalizer::NewL
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CGflmItemLocalizer* CGflmItemLocalizer::NewL()
       
    45     {
       
    46     CGflmItemLocalizer* self = new( ELeave ) CGflmItemLocalizer();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CGflmItemLocalizer::ConstructL
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CGflmItemLocalizer::ConstructL()
       
    58     {
       
    59     iLocalizer = CDirectoryLocalizer::NewL();
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CGflmItemLocalizer::~CGflmItemLocalizer
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CGflmItemLocalizer::~CGflmItemLocalizer()
       
    67     {
       
    68     delete iLocalizer;
       
    69     // iWorkThreadLocalizer cannot be freed here because it was 
       
    70     // allocated by another thread
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CGflmItemLocalizer::Localize()
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TPtrC CGflmItemLocalizer::Localize( const TDesC& aPath ) const
       
    78     {
       
    79     return Localize( *iLocalizer, aPath );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CGflmItemLocalizer::LocalizeFromWorkThread()
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 TPtrC CGflmItemLocalizer::LocalizeFromWorkThread( const TDesC& aPath ) const
       
    87     {
       
    88     if ( iWorkThreadLocalizer )
       
    89         {
       
    90         return Localize( *iWorkThreadLocalizer, aPath );
       
    91         }
       
    92     return TPtrC( KNullDesC );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CGflmItemLocalizer::SetupWorkThreadLocalizerL()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CGflmItemLocalizer::SetupWorkThreadLocalizerL()
       
   100     {
       
   101     if ( !iWorkThreadLocalizer )
       
   102         {
       
   103         iWorkThreadLocalizer = CDirectoryLocalizer::NewL();
       
   104         }
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CGflmItemLocalizer::SetupWorkThreadLocalizer()
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CGflmItemLocalizer::ReleaseWorkThreadLocalizer()
       
   112     {
       
   113     delete iWorkThreadLocalizer;
       
   114     iWorkThreadLocalizer = NULL;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CGflmItemLocalizer::SetupWorkThreadLocalizer()
       
   119 // (other items were commented in a header).
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TPtrC CGflmItemLocalizer::Localize(
       
   123         CDirectoryLocalizer& aLocalizer, const TDesC& aPath ) const
       
   124     {
       
   125     aLocalizer.SetFullPath( aPath );
       
   126     if( aLocalizer.IsLocalized() )
       
   127         {
       
   128         // Ensure that localized name is legal.
       
   129         // Some localizations may have dot in the end that makes it 
       
   130         // invalid for file system point of view.
       
   131         return GflmUtils::StripFinalDot( aLocalizer.LocalizedName() );
       
   132         }
       
   133     return TPtrC( KNullDesC );
       
   134     }
       
   135 
       
   136 //  End of File