filemanager/Engine/src/CFileManagerFolderEntry.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2002-2006 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:   Holds one default folder entry
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CFileManagerFolderEntry.h"
       
    22 #include <barsread.h>               // TResourceReader
       
    23 #include <bautils.h>                // BaflUtils::EnsurePathExists
       
    24 #include <coemain.h>                // CCoeEnv
       
    25 #include "CFileManagerUtils.h"
       
    26 #include "CFileManagerCommonDefinitions.h"
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CFileManagerFolderEntry::NewLC
       
    33 // 
       
    34 // -----------------------------------------------------------------------------
       
    35 // 
       
    36 CFileManagerFolderEntry* CFileManagerFolderEntry::NewLC(
       
    37         TResourceReader& aReader )
       
    38     {
       
    39     CFileManagerFolderEntry* self = new( ELeave ) CFileManagerFolderEntry;
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructFromResourceL( aReader );
       
    42 
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CFileManagerFolderEntry::NewL
       
    48 // 
       
    49 // -----------------------------------------------------------------------------
       
    50 // 
       
    51 CFileManagerFolderEntry* CFileManagerFolderEntry::NewL(
       
    52         TResourceReader& aReader )
       
    53     {
       
    54     CFileManagerFolderEntry* self = CFileManagerFolderEntry::NewLC( aReader );
       
    55     CleanupStack::Pop( self );
       
    56     
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CFileManagerFolderEntry::NewLC
       
    62 // 
       
    63 // -----------------------------------------------------------------------------
       
    64 // 
       
    65 CFileManagerFolderEntry* CFileManagerFolderEntry::NewLC(
       
    66         const TInt aDrive, const TDesC& aPath )
       
    67     {
       
    68     CFileManagerFolderEntry* self = new( ELeave ) CFileManagerFolderEntry;
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL( aDrive, aPath );
       
    71 
       
    72     return self;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CFileManagerFolderEntry::CFileManagerFolderEntry
       
    77 // 
       
    78 // -----------------------------------------------------------------------------
       
    79 // 
       
    80 CFileManagerFolderEntry::CFileManagerFolderEntry()
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CFileManagerFolderEntry::~CFileManagerFolderEntry
       
    86 // Destructor
       
    87 // -----------------------------------------------------------------------------
       
    88 // 
       
    89 CFileManagerFolderEntry::~CFileManagerFolderEntry()
       
    90     {
       
    91     delete iName;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CFileManagerFolderEntry::ConstructFromResourceL
       
    96 // 
       
    97 // -----------------------------------------------------------------------------
       
    98 // 
       
    99 void CFileManagerFolderEntry::ConstructFromResourceL( TResourceReader& aReader )
       
   100     {
       
   101     const TPtrC root( aReader.ReadTPtrC() );
       
   102     const TPtrC path( aReader.ReadTPtrC() );
       
   103 
       
   104     iIsMediaFolder = aReader.ReadInt8();
       
   105     iName = HBufC::NewL(
       
   106         root.Length() +
       
   107         path.Length() +
       
   108         KFmgrBackslashSpace +
       
   109         KFmgrBackslashSpace );
       
   110 
       
   111     TPtr ptr( iName->Des() );
       
   112     ptr.Copy( root );
       
   113     CFileManagerUtils::EnsureFinalBackslash( ptr );
       
   114     ptr.Append( path );
       
   115     CFileManagerUtils::EnsureFinalBackslash( ptr );
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CFileManagerFolderEntry::ConstructL
       
   120 // 
       
   121 // -----------------------------------------------------------------------------
       
   122 // 
       
   123 void CFileManagerFolderEntry::ConstructL(
       
   124         const TInt aDrive, const TDesC& aPath )
       
   125     {
       
   126     TChar driveLetter;
       
   127 
       
   128     User::LeaveIfError( RFs::DriveToChar( aDrive, driveLetter ) );
       
   129     iName = aPath.AllocL();
       
   130     iName->Des()[ 0 ] = driveLetter;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CFileManagerFolderEntry::IsMediaFolder
       
   135 // 
       
   136 // -----------------------------------------------------------------------------
       
   137 // 
       
   138 TBool CFileManagerFolderEntry::IsMediaFolder() const
       
   139     {
       
   140     return iIsMediaFolder;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CFileManagerFolderEntry::Name
       
   145 // 
       
   146 // -----------------------------------------------------------------------------
       
   147 // 
       
   148 TPtrC CFileManagerFolderEntry::Name() const
       
   149     {
       
   150     return iName->Des();
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CFileManagerFolderEntry::CompareSort
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CFileManagerFolderEntry::CompareSort(
       
   158         const CFileManagerFolderEntry& aFirst,
       
   159         const CFileManagerFolderEntry& aSecond )
       
   160     {
       
   161     return aFirst.iName->Des().CompareF( *( aSecond.iName ) );
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CFileManagerFolderEntry::CompareFind
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TInt CFileManagerFolderEntry::CompareFind(
       
   169         const TDesC* aPath,
       
   170         const CFileManagerFolderEntry& aItem )
       
   171     {
       
   172     return aPath->CompareF( *( aItem.iName ) );
       
   173     }
       
   174 
       
   175 //  End of File