filesystemuis/memscaneng/serversrc/msengdirectoryscanner.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *       Scan directories
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <bautils.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "msengdirectoryscanner.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT(KMsengPathDelimiter, "\\");
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS ========================================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CMsengDirectoryScanner::CMsengDirectoryScanner()
       
    35 //
       
    36 // Default C++ constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 CMsengDirectoryScanner::CMsengDirectoryScanner(
       
    39                                             MMsengScannerObserver& aObserver,
       
    40                                             CMsengInfoArray& aScanArray,
       
    41                                             RFs& aFsSession )
       
    42 : CMsengScannerBase(aObserver, aScanArray, aFsSession)
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CMsengDirectoryScanner::~CMsengDirectoryScanner()
       
    49 //
       
    50 // Destructor
       
    51 // ---------------------------------------------------------------------------
       
    52 CMsengDirectoryScanner::~CMsengDirectoryScanner()
       
    53     {
       
    54     delete iDirectoryList;
       
    55     delete iScanner;
       
    56     }
       
    57 
       
    58 
       
    59 
       
    60 
       
    61 
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CMsengDirectoryScanner::ScanL()
       
    66 // 
       
    67 //
       
    68 // ---------------------------------------------------------------------------
       
    69 void CMsengDirectoryScanner::ScanL(const CDesCArray& aRootDirs)
       
    70     {
       
    71     if (iDirectoryList)
       
    72         {
       
    73         iDirectoryList->Reset();
       
    74         }
       
    75     else
       
    76         {
       
    77         iDirectoryList = new(ELeave) CDesCArraySeg(KDirectoryListGranularity);
       
    78         }
       
    79     if  (!iScanner)
       
    80         {
       
    81         iScanner = CDirScan::NewL(FsSession());
       
    82         }
       
    83     // Copy existing directories over
       
    84     const TInt count = iNumberOfRootDirectories = aRootDirs.Count();
       
    85     for(TInt i=0; i<count; i++)
       
    86         {
       
    87         // Make sure the copied root dirs exist. Otherwise the RunL()
       
    88         // would leave with KErrPathNotFound. After having the list
       
    89         // of root dirs, all scanned dirs are taken from the list obtained
       
    90         // by a CDirScan instance and are thus known to exist because 
       
    91         if( InfoArray().FolderExists(FsSession(),aRootDirs[i]) ) 
       
    92             {            
       
    93             iDirectoryList->AppendL(aRootDirs[i]);
       
    94 #ifdef __SHOW_RDEBUG_PRINT_
       
    95             TPtrC dir = aRootDirs[i];
       
    96             RDebug::Print(_L("Root directory: %S"), &dir);
       
    97 #endif // __SHOW_RDEBUG_PRINT_
       
    98             }
       
    99         else 
       
   100             {
       
   101             iNumberOfRootDirectories--;
       
   102             }
       
   103         }
       
   104 
       
   105     // Start the scan going
       
   106     CompleteRequest();
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CMsengDirectoryScanner::PerformStepL()
       
   112 // 
       
   113 //
       
   114 // ---------------------------------------------------------------------------
       
   115 CMsengScannerBase::TStepResult CMsengDirectoryScanner::PerformStepL()
       
   116     {
       
   117     TStepResult result = ECompleteRequest;
       
   118     RFs& fsSession = FsSession();
       
   119 
       
   120     // Expand the root directories to a full list of 
       
   121     // subdirectories
       
   122     if (iState == EExpandingRootDirs)
       
   123         {
       
   124         if (iCurrentIndex >= iNumberOfRootDirectories)
       
   125             {
       
   126             // Finished scanning for the subdirectories. 
       
   127             // Reset the current index so that we pass all the directories
       
   128             // (including the root paths) to the subclasses.
       
   129             iCurrentIndex = 0;
       
   130             iState = EScanningSubDirs;
       
   131             }
       
   132         else
       
   133             {
       
   134             const TPtrC pFolder(iDirectoryList->MdcaPoint(iCurrentIndex++));
       
   135 
       
   136             // Do the recursive scanning: First set scan data.
       
   137             iScanner->SetScanDataL(
       
   138                 pFolder,
       
   139                 KEntryAttDir|KEntryAttMatchExclusive,
       
   140                 ESortNone,
       
   141                 CDirScan::EScanDownTree
       
   142                 );
       
   143 
       
   144             // Add all the located subdirectories to the array
       
   145             iState = EParsingExpandedList;
       
   146             }
       
   147         }
       
   148     else if (iState == EParsingExpandedList)
       
   149         {
       
   150         CDir* list = NULL;
       
   151         iScanner->NextL(list);
       
   152         
       
   153         if (list)
       
   154             {
       
   155             CleanupStack::PushL(list);
       
   156         
       
   157             const TPtrC pFullPath(iScanner->FullPath());
       
   158             TFileName file;
       
   159         
       
   160             const TInt count = list->Count();
       
   161             for(TInt i=0; i<count; i++)
       
   162                 {
       
   163                 const TPtrC pEntry((*list)[i].iName);
       
   164                 file = pFullPath;
       
   165                 file += pEntry;
       
   166                 file += KMsengPathDelimiter;
       
   167 #ifdef __SHOW_RDEBUG_PRINT_
       
   168                 // Don't add text, all print space (256 chars) may be required
       
   169                 RDebug::Print(_L("%S"), &file); 
       
   170 #endif // __SHOW_RDEBUG_PRINT_
       
   171                 AppendDirectoryL(file);
       
   172                 }
       
   173             //
       
   174             CleanupStack::PopAndDestroy(list);
       
   175             }
       
   176         else
       
   177             {
       
   178             // No more processing to do in this state
       
   179             iState = EExpandingRootDirs;
       
   180             }
       
   181         }
       
   182     else if (iState == EScanningSubDirs)
       
   183         {
       
   184         // Scan this folder
       
   185         if (iCurrentIndex < iDirectoryList->Count())
       
   186             {
       
   187             const TPtrC pFolder(iDirectoryList->MdcaPoint(iCurrentIndex));
       
   188             const TScanDirectoryResult scanDirectoryResult = 
       
   189                 ScanDirectoryL(pFolder, fsSession);
       
   190             
       
   191             // Check whether we continue with this directory next time
       
   192             if (scanDirectoryResult == EContinueToNextDirectory)
       
   193                 {
       
   194                 iCurrentIndex++;
       
   195                 }
       
   196             }
       
   197         else
       
   198             {
       
   199             // All directories scanned now
       
   200             result = EScanComplete;
       
   201             }
       
   202         }
       
   203 
       
   204     // Return the response back to the base scanner
       
   205     return result;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CMsengDirectoryScanner::AppendDirectoryL()
       
   211 //
       
   212 //
       
   213 // ---------------------------------------------------------------------------
       
   214 void CMsengDirectoryScanner::AppendDirectoryL(const TDesC& aDirectory)
       
   215     {
       
   216     // Append the directory to the directory list,
       
   217     // unless it is listed as excluded directory
       
   218     if( IsSpecialDir(aDirectory) || !IsExcludedDir(aDirectory) )
       
   219         {
       
   220         iDirectoryList->AppendL(aDirectory);
       
   221         }
       
   222     else
       
   223         {
       
   224 #ifdef __SHOW_RDEBUG_PRINT_
       
   225         RDebug::Print(_L("Dir is excluded! %S"), &aDirectory);
       
   226 #endif // __SHOW_RDEBUG_PRINT_
       
   227         }
       
   228     }
       
   229 
       
   230 //  End of File