filemanager/Engine/src/CfilemanagerActiveCount.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:  Calculates given folder size
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CFilemanagerActiveCount.h"
       
    21 
       
    22 // CONSTANTS
       
    23 const TInt KFileManagerProcessFilesPerCycle = 20;
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CFileManagerActiveCount::CFileManagerActiveCount
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CFileManagerActiveCount::CFileManagerActiveCount( RFs& aFs ) :
       
    34     iFs( aFs ),
       
    35     iFolders( KErrNotFound ),
       
    36     iFiles( KErrNotFound),
       
    37     iOpenFiles( KErrNotFound )
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CFileManagerActiveCount::NewL
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CFileManagerActiveCount* CFileManagerActiveCount::NewL( 
       
    47     RFs& aFs,
       
    48     const TDesC& aRootFolder,
       
    49     const CFileManagerItemProperties::TFileManagerFileType aType
       
    50     )
       
    51     {
       
    52     CFileManagerActiveCount* self = new( ELeave ) CFileManagerActiveCount( 
       
    53         aFs );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL( aRootFolder, aType );
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CFileManagerActiveCount::ConstructL
       
    62 // 
       
    63 // -----------------------------------------------------------------------------
       
    64 // 
       
    65 void CFileManagerActiveCount::ConstructL( 
       
    66     const TDesC& aRootFolder,
       
    67     const CFileManagerItemProperties::TFileManagerFileType aType )
       
    68     {
       
    69 
       
    70     iDirScan = CDirScan::NewL( iFs );
       
    71 
       
    72     if ( aType == CFileManagerItemProperties::EFolder )
       
    73         {
       
    74         // Set scanning from current directory, take only folders
       
    75         // No sorting needed
       
    76         iDirScan->SetScanDataL(
       
    77             aRootFolder,
       
    78             KEntryAttDir | KEntryAttMatchExclusive,
       
    79             ESortNone );
       
    80         }
       
    81     else if ( aType == CFileManagerItemProperties::EFile ||
       
    82              aType == CFileManagerItemProperties::EOpen ||
       
    83              aType == CFileManagerItemProperties::EReadOnly )
       
    84         {
       
    85         // Set scanning from current directory, take only file
       
    86         // No sorting needed
       
    87         iDirScan->SetScanDataL(
       
    88             aRootFolder,
       
    89             KEntryAttNormal | KEntryAttHidden | KEntryAttSystem,
       
    90             ESortNone );
       
    91         }
       
    92     else
       
    93         {
       
    94         // Set scanning from current directory,
       
    95         // take file and folders except hidden and system files
       
    96         // No sorting needed
       
    97         iDirScan->SetScanDataL( aRootFolder, KEntryAttDir, ESortNone );
       
    98         }
       
    99 
       
   100     TRAPD( err, iDirScan->NextL( iDir ) );
       
   101 
       
   102     if ( err == KErrNone && iDir )
       
   103         {
       
   104         if ( aType == CFileManagerItemProperties::EOpen ||
       
   105              aType == CFileManagerItemProperties::EReadOnly )
       
   106             {
       
   107             iFiles = iDir->Count();
       
   108             iOpenFiles = 0;
       
   109             }
       
   110         else if ( aType == CFileManagerItemProperties::EFolder )
       
   111             {
       
   112             iFolders = iDir->Count();
       
   113             delete iDir;
       
   114             iDir = NULL;
       
   115             iProcessDone = ETrue;
       
   116             }
       
   117         else if ( aType == CFileManagerItemProperties::EFile )
       
   118             {
       
   119             iFiles = iDir->Count();
       
   120             delete iDir;
       
   121             iDir = NULL;
       
   122             iProcessDone = ETrue;
       
   123             }
       
   124         }
       
   125 
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CFileManagerActiveCount::~CFileManagerActiveCount
       
   130 // Destructor
       
   131 // -----------------------------------------------------------------------------
       
   132 // 
       
   133 CFileManagerActiveCount::~CFileManagerActiveCount()
       
   134     {
       
   135     delete iDirScan;
       
   136     delete iDir;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CFileManagerActiveCount::IsProcessDone
       
   141 // 
       
   142 // -----------------------------------------------------------------------------
       
   143 // 
       
   144 TBool CFileManagerActiveCount::IsProcessDone() const
       
   145     {
       
   146     return iProcessDone;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CFileManagerActiveCount::StepL
       
   151 // 
       
   152 // -----------------------------------------------------------------------------
       
   153 // 
       
   154 void CFileManagerActiveCount::StepL()
       
   155     {
       
   156     if( !iDir )
       
   157         {
       
   158         iProcessDone = ETrue;
       
   159         return;
       
   160         }
       
   161 
       
   162     TInt processCount( KFileManagerProcessFilesPerCycle );
       
   163     while( iFileCounter < iDir->Count() && processCount )
       
   164         {
       
   165         const TEntry& entry( ( *iDir )[ iFileCounter ] );
       
   166         iFileName.Copy( iDirScan->FullPath() );
       
   167         iFileName.Append( entry.iName );
       
   168         TBool fileIsOpen( EFalse );
       
   169         if ( KErrNone == iFs.IsFileOpen( iFileName, fileIsOpen ) )
       
   170             {
       
   171             if ( fileIsOpen )
       
   172                 {
       
   173                 ++iOpenFiles;
       
   174                 }
       
   175             }
       
   176         ++iFileCounter;
       
   177         --processCount;
       
   178         }
       
   179 
       
   180     if ( iFileCounter >= iDir->Count() )
       
   181         {
       
   182         delete iDir;
       
   183         iDir = NULL;
       
   184         iDirScan->NextL( iDir );
       
   185         if ( !iDir )
       
   186             {
       
   187             iProcessDone = ETrue;
       
   188             }
       
   189         iFileCounter = 0;
       
   190         }
       
   191 
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CFileManagerActiveCount::FolderCount()
       
   196 // 
       
   197 // -----------------------------------------------------------------------------
       
   198 // 
       
   199 TInt CFileManagerActiveCount::FolderCount() const
       
   200     {
       
   201     if ( iProcessDone )
       
   202         {
       
   203         return iFolders;
       
   204         }
       
   205     return KErrNotFound;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CFileManagerActiveCount::FileCount()
       
   210 //
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TInt CFileManagerActiveCount::FileCount() const
       
   214     {
       
   215     if ( iProcessDone )
       
   216         {
       
   217         return iFiles;
       
   218         }
       
   219     return KErrNotFound;
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CFileManagerActiveCount::OpenFiles()
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TInt CFileManagerActiveCount::OpenFiles() const
       
   228     {
       
   229     if ( iProcessDone )
       
   230         {
       
   231         return iOpenFiles;
       
   232         }
       
   233     return KErrNotFound;
       
   234     }
       
   235 
       
   236 // End of File