filemanager/Engine/src/Cfilemanageractivesize.cpp
branchRCL_3
changeset 21 65326cf895ed
equal deleted inserted replaced
20:491b3ed49290 21:65326cf895ed
       
     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:  Calculates given folder size
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "Cfilemanageractivesize.h"
       
    21 
       
    22 // CONSTANTS
       
    23 const TInt KFileManagerProcessFilesPerCycle = 20;
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CFileManagerActiveSize::CFileManagerActiveSize
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CFileManagerActiveSize::CFileManagerActiveSize( RFs& aFs ) :
       
    34     iFs( aFs )
       
    35     {
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CFileManagerActiveSize::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CFileManagerActiveSize* CFileManagerActiveSize::NewL(
       
    44         RFs& aFs, const TDesC& aRootFolder )
       
    45     {
       
    46     CFileManagerActiveSize* self = new( ELeave ) CFileManagerActiveSize(
       
    47         aFs );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aRootFolder );
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFileManagerActiveSize::ConstructL
       
    56 // 
       
    57 // -----------------------------------------------------------------------------
       
    58 // 
       
    59 void CFileManagerActiveSize::ConstructL( const TDesC& aRootFolder )
       
    60     {
       
    61     iDirScan = CDirScan::NewL( iFs );
       
    62     // Set scanning from current directory,
       
    63     // take files and folder including the hidden and system files
       
    64     // No sorting needed
       
    65     iDirScan->SetScanDataL(
       
    66         aRootFolder,
       
    67         KEntryAttNormal | KEntryAttHidden | KEntryAttSystem,
       
    68         ESortNone );
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CFileManagerActiveSize::~CFileManagerActiveSize
       
    73 // Destructor
       
    74 // -----------------------------------------------------------------------------
       
    75 // 
       
    76 CFileManagerActiveSize::~CFileManagerActiveSize()
       
    77     {
       
    78     delete iDirScan;
       
    79     delete iDir;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CFileManagerActiveSize::IsProcessDone
       
    84 // 
       
    85 // -----------------------------------------------------------------------------
       
    86 // 
       
    87 TBool CFileManagerActiveSize::IsProcessDone() const
       
    88     {
       
    89     return iProcessDone;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CFileManagerActiveSize::StepL
       
    94 // 
       
    95 // -----------------------------------------------------------------------------
       
    96 // 
       
    97 void CFileManagerActiveSize::StepL()
       
    98     {
       
    99     if ( !iDir )
       
   100         {
       
   101         iDirScan->NextL( iDir );
       
   102         if( !iDir )
       
   103             {
       
   104             iProcessDone = ETrue;
       
   105             return;
       
   106             }
       
   107         }
       
   108 
       
   109     TInt processCount( KFileManagerProcessFilesPerCycle );
       
   110     while( iFileCounter < iDir->Count() && processCount )
       
   111         {
       
   112         const TEntry& item( ( *iDir )[ iFileCounter ] );
       
   113         iSize += item.FileSize();
       
   114         ++iFileCounter;
       
   115         --processCount;
       
   116         }
       
   117 
       
   118     if ( iFileCounter >= iDir->Count() )
       
   119         {
       
   120         delete iDir;
       
   121         iDir = NULL;
       
   122         iFileCounter = 0;
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CFileManagerActiveSize::GetFolderSize()
       
   128 // 
       
   129 // -----------------------------------------------------------------------------
       
   130 // 
       
   131 TInt64 CFileManagerActiveSize::GetFolderSize() const
       
   132     {
       
   133     if( iProcessDone )
       
   134         {
       
   135         return iSize;
       
   136         }
       
   137     return KErrNotFound;
       
   138     }
       
   139 
       
   140 // End of File