filemanager/Engine/src/Cfilemanagerfolderarray.cpp
changeset 0 6a9f87576119
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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 the array of CFileManagerFolderEntry
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsread.h>				// TResourceReader
       
    21 #include <bautils.h>				// BaflUtils::EnsurePathExists
       
    22 #include <coemain.h>				// CCoeEnv
       
    23 #ifdef RD_MULTIPLE_DRIVE
       
    24  #include <pathinfo.h>
       
    25  #include <driveinfo.h>
       
    26 #endif // RD_MULTIPLE_DRIVE
       
    27 #include "Cfilemanagerfolderarray.h"
       
    28 #ifndef RD_MULTIPLE_DRIVE
       
    29  #include "cfilemanagerfolderentry.h"
       
    30 #endif // RD_MULTIPLE_DRIVE
       
    31 #include "CFileManagerCommonDefinitions.h"
       
    32 #include "CFileManagerUtils.h"
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 const TInt KCreateCheckMaskMax = 32;
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CFileManagerFolderArray::NewL
       
    43 // 
       
    44 // -----------------------------------------------------------------------------
       
    45 // 
       
    46 #ifdef RD_MULTIPLE_DRIVE
       
    47 CFileManagerFolderArray* CFileManagerFolderArray::NewL(
       
    48         CFileManagerUtils& aUtils )
       
    49 	{
       
    50 	return new ( ELeave ) CFileManagerFolderArray( aUtils );
       
    51     }
       
    52 #else // RD_MULTIPLE_DRIVE
       
    53 CFileManagerFolderArray* CFileManagerFolderArray::NewL(
       
    54         TInt aResId, CFileManagerUtils& aUtils )
       
    55 	{
       
    56 	CFileManagerFolderArray* self =
       
    57 	    new( ELeave ) CFileManagerFolderArray(
       
    58 	        aUtils );
       
    59 
       
    60 	CleanupStack::PushL( self );
       
    61 	self->ConstructL( aResId );
       
    62 	CleanupStack::Pop( self );
       
    63 
       
    64 	return self;
       
    65 	}
       
    66 #endif // RD_MULTIPLE_DRIVE
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CFileManagerFolderArray::CFileManagerFolderArray
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CFileManagerFolderArray::CFileManagerFolderArray(
       
    75         CFileManagerUtils& aUtils ) :
       
    76     iUtils( aUtils )
       
    77     {
       
    78     }
       
    79 
       
    80 #ifndef RD_MULTIPLE_DRIVE
       
    81 // -----------------------------------------------------------------------------
       
    82 // CFileManagerFolderArray::ConstructL
       
    83 // 
       
    84 // -----------------------------------------------------------------------------
       
    85 // 
       
    86 void CFileManagerFolderArray::ConstructL( TInt aResId )
       
    87 	{
       
    88     RArray< TInt > removableDrives;
       
    89     CleanupClosePushL( removableDrives );
       
    90 
       
    91     iUtils.DriveList( removableDrives, KDriveAttRemovable );
       
    92     TInt drvCount( removableDrives.Count() );
       
    93 
       
    94 	TResourceReader reader;
       
    95     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );
       
    96 	TInt count( reader.ReadInt16() );
       
    97 
       
    98     TChar drvLetter( 0 );
       
    99     TBool isRemovable( EFalse );
       
   100 
       
   101 	for( TInt i( 0 ); i < count; i++ )
       
   102 		{
       
   103 		CFileManagerFolderEntry* entry =
       
   104 		    CFileManagerFolderEntry::NewLC( reader );
       
   105 		iFolderArray.AppendL( entry );
       
   106 		CleanupStack::Pop( entry );
       
   107 
       
   108         // The default folders are same to all removable drives.
       
   109         // Add the folders dynamically for undefined removable drives.
       
   110         TPtrC ptr( entry->Name() );
       
   111         if ( ptr[ 0 ] != drvLetter )
       
   112             {
       
   113             drvLetter = ptr[ 0 ];
       
   114             isRemovable = iUtils.IsRemovableDrive( ptr );
       
   115             }
       
   116 		if ( isRemovable )
       
   117 		    {
       
   118 		    TInt baseDrv = TDriveUnit( ptr );
       
   119 		    for( TInt j( 0 ); j < drvCount; j++ )
       
   120 		        {
       
   121 		        TInt drv( removableDrives[ j ] );
       
   122 		        if ( drv != baseDrv )
       
   123 		            {
       
   124 		            entry = CFileManagerFolderEntry::NewLC( drv, ptr );
       
   125 		            iFolderArray.AppendL( entry );
       
   126 		            CleanupStack::Pop( entry );
       
   127 		            }
       
   128 		        }
       
   129 		    }
       
   130 		}
       
   131 
       
   132     CleanupStack::PopAndDestroy(); // reader
       
   133     CleanupStack::PopAndDestroy( &removableDrives );
       
   134 	}
       
   135 #endif // RD_MULTIPLE_DRIVE
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CFileManagerFolderArray::~CFileManagerFolderArray
       
   139 // Destructor
       
   140 // -----------------------------------------------------------------------------
       
   141 // 
       
   142 CFileManagerFolderArray::~CFileManagerFolderArray()
       
   143     {
       
   144 #ifndef RD_MULTIPLE_DRIVE
       
   145     iFolderArray.ResetAndDestroy();
       
   146     iFolderArray.Close();
       
   147 #endif // RD_MULTIPLE_DRIVE
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CFileManagerFolderArray::Contains
       
   152 // 
       
   153 // -----------------------------------------------------------------------------
       
   154 // 
       
   155 TBool CFileManagerFolderArray::Contains( const TDesC& aFolderName )
       
   156 	{
       
   157 #ifdef RD_MULTIPLE_DRIVE
       
   158     // Remote drives has no default folders
       
   159     if ( !iUtils.IsRemoteDrive( aFolderName ) )
       
   160         {
       
   161         TInt pathType( PathInfo::PathType( aFolderName ) );
       
   162         switch ( pathType )
       
   163             {
       
   164             // If non default folder but localized,
       
   165             // handle it here as default folder
       
   166             case PathInfo::ENotSystemPath:
       
   167                 {
       
   168                 TPtrC ptr( iUtils.LocalizedName( aFolderName ) );
       
   169                 if ( ptr.Length() )
       
   170                     {
       
   171                     return ETrue;
       
   172                     }
       
   173                 return EFalse;
       
   174                 }
       
   175             // Ignore root folders
       
   176             case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH
       
   177             case PathInfo::EMemoryCardRootPath: // FALL THROUGH
       
   178             case PathInfo::ERomRootPath:
       
   179                 {
       
   180                 return EFalse;
       
   181                 }
       
   182             // Accept other folders
       
   183             default:
       
   184                 {
       
   185                 return ETrue;
       
   186                 }
       
   187             }
       
   188         }
       
   189     return EFalse;
       
   190 #else  // RD_MULTIPLE_DRIVE
       
   191 	CFileManagerFolderEntry* entry = FindFolder( aFolderName );
       
   192 	return ( entry ? ETrue : EFalse );
       
   193 #endif // RD_MULTIPLE_DRIVE
       
   194 	}
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CFileManagerFolderArray::CreateFolders
       
   198 // 
       
   199 // -----------------------------------------------------------------------------
       
   200 // 
       
   201 void CFileManagerFolderArray::CreateFolders(
       
   202         const TInt aDrive, const TBool aForced )
       
   203 	{
       
   204     // If not forced creation, check if folders have been already created
       
   205     if ( !aForced && aDrive >= 0 && aDrive < KCreateCheckMaskMax  )
       
   206         {
       
   207         if ( ( 1 << aDrive ) & iCreateCheckMask )
       
   208             {
       
   209             return; // Folders have already been created
       
   210             }
       
   211         }
       
   212 #ifdef RD_MULTIPLE_DRIVE
       
   213     if ( aDrive != KErrNotFound ) // Support only explicitly given drive id
       
   214         {
       
   215         TRAP_IGNORE( DoCreateFoldersL( aDrive ) );
       
   216         // Update folder creation mask
       
   217         iCreateCheckMask |= 1 << aDrive;
       
   218         }
       
   219 #else // RD_MULTIPLE_DRIVE
       
   220     RFs& fs( iUtils.Fs() );
       
   221     TInt count( iFolderArray.Count() );
       
   222 	for( TInt i( 0 ); i < count; i++ )
       
   223 		{
       
   224 		TPtrC defFolder( iFolderArray[ i ]->Name() );
       
   225 
       
   226         TInt drv = TDriveUnit( defFolder );
       
   227         if ( aDrive >= 0 )
       
   228             {
       
   229             // Apply drive filtering
       
   230             if ( drv != aDrive )
       
   231                 {
       
   232                 continue;
       
   233                 }
       
   234             }
       
   235 
       
   236         // Update folder creation mask
       
   237         iCreateCheckMask |= 1 << drv;
       
   238 
       
   239         // Make sure that path exists
       
   240         fs.MkDirAll( defFolder );
       
   241 
       
   242         // Clear the possible hidden flag, all default folders
       
   243         // should be visible
       
   244         TEntry entry;
       
   245         if ( fs.Entry( defFolder, entry ) == KErrNone )
       
   246             {
       
   247             if( entry.IsHidden() )
       
   248                 {
       
   249                 // If setting fails, File Manager can still go on
       
   250                 fs.SetEntry(
       
   251                     defFolder, entry.iModified, 0, KEntryAttHidden );
       
   252                 }
       
   253             }
       
   254 		}
       
   255 #endif // RD_MULTIPLE_DRIVE
       
   256     }
       
   257 
       
   258 #ifndef RD_MULTIPLE_DRIVE
       
   259 // -----------------------------------------------------------------------------
       
   260 // CFileManagerFolderArray::FindFolder
       
   261 // 
       
   262 // -----------------------------------------------------------------------------
       
   263 // 
       
   264 CFileManagerFolderEntry* CFileManagerFolderArray::FindFolder(
       
   265         const TDesC& aFolderName )
       
   266 	{
       
   267     if ( !iSorted )
       
   268         {
       
   269         TLinearOrder< CFileManagerFolderEntry > key(
       
   270             CFileManagerFolderEntry::CompareSort );
       
   271         iFolderArray.Sort( key );
       
   272         iSorted = ETrue;
       
   273         }
       
   274 
       
   275     TInt index( iFolderArray.FindInOrder(
       
   276         aFolderName, CFileManagerFolderEntry::CompareFind ) );
       
   277     if ( index >= 0 && index < iFolderArray.Count() )
       
   278         {
       
   279         // Match found
       
   280         return iFolderArray[ index ];
       
   281         }
       
   282 
       
   283     return NULL;
       
   284 	}
       
   285 #endif // RD_MULTIPLE_DRIVE
       
   286 
       
   287 #ifdef RD_MULTIPLE_DRIVE
       
   288 // -----------------------------------------------------------------------------
       
   289 // CFileManagerFolderArray::DoCreateFolders
       
   290 // 
       
   291 // -----------------------------------------------------------------------------
       
   292 // 
       
   293 void CFileManagerFolderArray::DoCreateFoldersL( const TInt aDrive )
       
   294     {
       
   295     TUint drvStatus( 0 );
       
   296     RFs& fs( iUtils.Fs() );
       
   297     User::LeaveIfError( DriveInfo::GetDriveStatus( fs, aDrive, drvStatus ) );
       
   298     if ( !( drvStatus & DriveInfo::EDriveUserVisible ) ||
       
   299         ( drvStatus & ( DriveInfo::EDriveRemote |
       
   300                         DriveInfo::EDriveReadOnly |
       
   301                         DriveInfo::EDriveUsbMemory ) ) )
       
   302         {
       
   303         return; // Default folder creation is not allowed for this drive type
       
   304         }
       
   305 
       
   306     TEntry entry;
       
   307     CDesCArray* array = PathInfo::GetListOfPathsLC( aDrive );
       
   308     TInt count( array->MdcaCount() );
       
   309     for ( TInt i( 0 ); i < count; ++i )
       
   310         {
       
   311         TPtrC fullPath( array->MdcaPoint( i ) );
       
   312         TBool allow( ETrue );
       
   313 
       
   314         if ( drvStatus & DriveInfo::EDriveRemovable )
       
   315             {
       
   316             // Filter few folder types from physically removable memory cards
       
   317             TInt pathType( PathInfo::PathType( fullPath ) );
       
   318             switch( pathType )
       
   319                 {
       
   320                 case PathInfo::EGamesPath: // FALL THROUGH
       
   321                 case PathInfo::EInstallsPath: // FALL THROUGH
       
   322                 case PathInfo::EGsmPicturesPath: // FALL THROUGH
       
   323                 case PathInfo::EMmsBackgroundImagesPath: // FALL THROUGH
       
   324                 case PathInfo::EPresenceLogosPath:
       
   325                     {
       
   326                     allow = EFalse;
       
   327                     }
       
   328                 default:
       
   329                     {
       
   330                     break;
       
   331                     }
       
   332                 }
       
   333             }
       
   334 
       
   335         if ( allow )
       
   336             {
       
   337         fs.MkDirAll( fullPath ); // Ignore error
       
   338 
       
   339         // Clear the possible hidden flag, all default folders
       
   340         // should be visible
       
   341         if ( fs.Entry( fullPath, entry ) == KErrNone )
       
   342             {
       
   343             if( entry.IsHidden() )
       
   344                 {
       
   345                 // If setting fails, File Manager can still go on
       
   346                 fs.SetEntry(
       
   347                     fullPath, entry.iModified, 0, KEntryAttHidden );
       
   348                     }
       
   349                 }
       
   350             }
       
   351         }
       
   352     CleanupStack::PopAndDestroy( array );
       
   353     }
       
   354 #endif // RD_MULTIPLE_DRIVE
       
   355 
       
   356 //  End of File