filemanager/Engine/src/CFileManagerEngine.cpp
changeset 14 1957042d8c7e
parent 1 d1daf54a55b5
child 16 ada7962b4308
equal deleted inserted replaced
1:d1daf54a55b5 14:1957042d8c7e
     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:  Main class of the filemanagerengine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <barsread.h>
       
    23 #include <sysutil.h>
       
    24 #include <bautils.h>
       
    25 //#include <cmgxfilemanager.h>
       
    26 //#include <mgxfilemanagerfactory.h>
       
    27 //#include <cmgalbummanager.h>
       
    28 #include <pathinfo.h>
       
    29 #include <AknServerApp.h>
       
    30 #include <FileManagerEngine.rsg>
       
    31 #ifdef RD_MULTIPLE_DRIVE
       
    32 #include <driveinfo.h>
       
    33 #endif // RD_MULTIPLE_DRIVE
       
    34 #include "CFileManagerEngine.h"
       
    35 #include "CGflmNavigatorModel.h"
       
    36 #include "CGflmGroupItem.h"
       
    37 #include "CGflmFileSystemItem.h"
       
    38 #include "CGflmDriveItem.h"
       
    39 #include "CGflmGlobalActionItem.h"
       
    40 #include "MGflmItemGroup.h"
       
    41 #include "Cfilemanagerfolderarray.h"
       
    42 #include "CFilemanagerMimeIconArray.h"
       
    43 #include "CFileManagerActiveExecute.h"
       
    44 #include "CFileManagerRefresher.h"
       
    45 #include "Cfilemanagerfilesystemevent.h"
       
    46 #include "Cfilemanageractivesize.h"
       
    47 #include "Cfilemanageractivedelete.h"
       
    48 #include "FileManagerEngine.hrh"
       
    49 #include "CFileManagerCommonDefinitions.h"
       
    50 #include "CFileManagerUtils.h"
       
    51 #include "CFileManagerItemFilter.h"
       
    52 #include "CFileManagerDocHandler.h"
       
    53 #include "FileManagerDebug.h"
       
    54 #include "CFileManagerItemProperties.h"
       
    55 #include "CFileManagerRemovableDriveHandler.h"
       
    56 #include "CFileManagerRemoteDriveHandler.h"
       
    57 #include "CFileManagerBackupSettings.h"
       
    58 #include "CFileManagerRestoreSettings.h"
       
    59 #include "CFileManagerActiveRename.h"
       
    60 #include "CFileManagerFeatureManager.h"
       
    61 
       
    62 // CONSTANTS
       
    63 const TUint16 KIllegalChars[] = {
       
    64     '<', '>', '"', '/', '\\', '|', ':', '*', '?',
       
    65     0xFF02, // Full width quote
       
    66     0xFF0A, // Full width asterisk
       
    67     0xFF0F, // Full width slash
       
    68     0xFF1A, // Full width colon
       
    69     0xFF1C, // Full width left arrow
       
    70     0xFF1E, // Full width right arrow
       
    71     0xFF1F, // Full width question mark
       
    72     0xFF3C, // Full width back slash
       
    73     0xFF5C, // Full width pipe
       
    74     0x201C, // Left quote
       
    75     0x201D, // Right quote
       
    76     0x201F, // Reversed quote
       
    77     0x21B2, // Downwards arrow with tip leftwards
       
    78     0, // Array terminator
       
    79 };
       
    80 
       
    81 //const TInt KMGFileArrayGranularity = 32;
       
    82 
       
    83 
       
    84 // ============================ LOCAL FUNCTIONS ================================
       
    85 // -----------------------------------------------------------------------------
       
    86 // SearchMGAlbumIdL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 /*static TInt SearchMGAlbumIdL(
       
    90         CMGAlbumManager& aAlbumManager, const TDesC& aFilename )
       
    91     {
       
    92     CDesCArray* fileArray =
       
    93         new ( ELeave ) CDesCArraySeg( KMGFileArrayGranularity );
       
    94     CleanupStack::PushL( fileArray );
       
    95     TInt albumCount( aAlbumManager.AlbumCount() );
       
    96     TInt ret( KErrNotFound );
       
    97     for( TInt i( 0 ); i < albumCount; ++i )
       
    98         {
       
    99         CMGAlbumInfo* albumInfo = aAlbumManager.AlbumInfoLC( i );
       
   100         TInt albumId( albumInfo->Id() );
       
   101         CleanupStack::PopAndDestroy( albumInfo );
       
   102         fileArray->Reset();
       
   103         aAlbumManager.GetAlbumFileArrayL( albumId, *fileArray );
       
   104         TInt pos( 0 );
       
   105         if( !fileArray->Find( aFilename, pos ) )
       
   106             {
       
   107             ret = albumId;
       
   108             break;
       
   109             }
       
   110         }
       
   111     CleanupStack::PopAndDestroy( fileArray );
       
   112     return ret;
       
   113     }
       
   114 */
       
   115 
       
   116 // ============================ MEMBER FUNCTIONS ===============================
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CFileManagerEngine::CFileManagerEngine
       
   120 // C++ default constructor can NOT contain any code, that
       
   121 // might leave.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CFileManagerEngine::CFileManagerEngine( RFs& aFs ) :
       
   125 		iFs( aFs ), iObserver( NULL ), iSisFile( EFalse )
       
   126     {
       
   127     FUNC_LOG
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CFileManagerEngine::NewL
       
   132 // Two-phased constructor.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C CFileManagerEngine* CFileManagerEngine::NewL( RFs& aFs )
       
   136     {
       
   137     CFileManagerEngine* self = new ( ELeave ) CFileManagerEngine( aFs );
       
   138 
       
   139     CleanupStack::PushL( self );
       
   140     self->ConstructL();
       
   141     CleanupStack::Pop( self );
       
   142 
       
   143     return self;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CFileManagerEngine::ConstructL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CFileManagerEngine::ConstructL()
       
   151     {
       
   152     FUNC_LOG
       
   153 
       
   154     INFO_LOG( "CFileManagerEngine::ConstructL()-Create Feature Manager" )
       
   155     iFeatureManager = CFileManagerFeatureManager::NewL();
       
   156 
       
   157     iState = ENavigation;
       
   158 
       
   159     INFO_LOG( "CFileManagerEngine::ConstructL()-Create navigator" )
       
   160     iNavigator = CGflmNavigatorModel::NewL( iFs );
       
   161 
       
   162     // Create drives group
       
   163     MGflmItemGroup* newGroup = iNavigator->CreateGroupL(
       
   164         EFileManagerDrivesGroup, EDrives );
       
   165 #ifdef RD_FILE_MANAGER_BACKUP
       
   166     // Set backup action
       
   167     HBufC* actionCaption = StringLoader::LoadLC( R_QTN_FMGR_MAIN_BACKUP );
       
   168     newGroup->AddActionItemL( EFileManagerBackupAction, *actionCaption );
       
   169     CleanupStack::PopAndDestroy( actionCaption );
       
   170 #endif // RD_FILE_MANAGER_BACKUP
       
   171 
       
   172     // Create files and folders groups
       
   173     iNavigator->CreateGroupL( EFileManagerFilesGroup, EDirectories | EFiles );
       
   174 
       
   175     INFO_LOG( "CFileManagerEngine::ConstructL()-Create refresher" )
       
   176     iRefresher = CFileManagerRefresher::NewL( *iNavigator );
       
   177 
       
   178     INFO_LOG( "CFileManagerEngine::ConstructL()-Create utils" )
       
   179     iUtils = CFileManagerUtils::NewL( iFs, *iNavigator, *iFeatureManager );
       
   180 
       
   181     INFO_LOG( "CFileManagerEngine::ConstructL()-Create disk event" )
       
   182     iDiskEvent = CFileManagerFileSystemEvent::NewL( iFs, *this, ENotifyDisk );
       
   183 
       
   184     INFO_LOG( "CFileManagerEngine::ConstructL()-Create removable drive handler" )
       
   185     iRemovableDrvHandler = CFileManagerRemovableDriveHandler::NewL(
       
   186         iFs, *iUtils, *this );
       
   187     INFO_LOG( "CFileManagerEngine::ConstructL()-Create remote drive handler" )
       
   188     iRemoteDrvHandler = CFileManagerRemoteDriveHandler::NewL(
       
   189         *this, *iUtils );
       
   190 
       
   191     INFO_LOG( "CFileManagerEngine::ConstructL()-Create item filter" )
       
   192     iItemFilter = CFileManagerItemFilter::NewL( *this );
       
   193     iNavigator->SetCustomFilter( iItemFilter );
       
   194 
       
   195     // Store new starting index
       
   196     iNavigationIndices.AppendL( KErrNotFound );
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CFileManagerEngine::~CFileManagerEngine
       
   201 // Destructor
       
   202 // -----------------------------------------------------------------------------
       
   203 // 
       
   204 EXPORT_C CFileManagerEngine::~CFileManagerEngine()
       
   205     {
       
   206     delete iActiveRename;
       
   207     iNavigationIndices.Reset();
       
   208     delete iRemoteDrvHandler;
       
   209     delete iBackupSettings;
       
   210     delete iRestoreSettings;
       
   211     delete iRemovableDrvHandler;
       
   212     delete iDocHandler;
       
   213     //delete iMgxFileManager;
       
   214     delete iFileSystemEvent;
       
   215     delete iRefresher;
       
   216     delete iNavigator;
       
   217     delete iItemFilter;
       
   218     delete iSearchString;
       
   219     delete iSearchFolder;
       
   220     delete iActiveSize;
       
   221     delete iDiskEvent;
       
   222     delete iUtils;
       
   223     delete iDriveName;
       
   224     delete iFeatureManager;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CFileManagerEngine::SetFileSystemEventL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CFileManagerEngine::SetFileSystemEventL( const TDesC& aFullPath )
       
   232     {
       
   233     delete iFileSystemEvent;
       
   234     iFileSystemEvent = NULL;
       
   235     if ( aFullPath != KNullDesC )
       
   236         {
       
   237         iFileSystemEvent = CFileManagerFileSystemEvent::NewL(
       
   238             iFs, *this, ENotifyEntry, aFullPath );
       
   239         }
       
   240     else
       
   241         {
       
   242         iFileSystemEvent = CFileManagerFileSystemEvent::NewL(
       
   243             iFs, *this, ENotifyEntry );
       
   244         }
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CFileManagerEngine::IndexToFullPathL
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C HBufC* CFileManagerEngine::IndexToFullPathL(
       
   252         const TInt aIndex ) const
       
   253     {
       
   254     if ( aIndex < 0 || aIndex >= iNavigator->MdcaCount() )
       
   255         {
       
   256         User::Leave( KErrNotFound );
       
   257         }
       
   258     CGflmGroupItem* item = iNavigator->Item( aIndex );
       
   259     HBufC* fullPath = NULL;
       
   260     switch ( item->Type() )
       
   261         {
       
   262         case CGflmGroupItem::EFile: // Fall through
       
   263         case CGflmGroupItem::EDirectory:
       
   264             {
       
   265             CGflmFileSystemItem* fsItem =
       
   266                 static_cast< CGflmFileSystemItem* >( item );
       
   267             fullPath = fsItem->FullPathL();
       
   268             break;
       
   269             }
       
   270         case CGflmGroupItem::EDrive:
       
   271             {
       
   272             CGflmDriveItem* drvItem =
       
   273                 static_cast< CGflmDriveItem* >( item );
       
   274             fullPath = drvItem->RootDirectory().AllocL();
       
   275             break;
       
   276             }
       
   277         default:
       
   278             {
       
   279             User::Leave( KErrNotFound );
       
   280             break;
       
   281             }
       
   282         }
       
   283     return fullPath;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CFileManagerEngine::IndexToFullPathLC
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 EXPORT_C HBufC* CFileManagerEngine::IndexToFullPathLC(
       
   291         const TInt aIndex ) const
       
   292     {
       
   293     HBufC* fullPath = IndexToFullPathL( aIndex );
       
   294     CleanupStack::PushL( fullPath );
       
   295     return fullPath;
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CFileManagerEngine::AddFullPathLC
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 HBufC* CFileManagerEngine::AddFullPathLC(
       
   303         const TDesC& aName, const TBool aIsFolder )
       
   304     {
       
   305     TPtrC dir( iNavigator->CurrentDirectory() );
       
   306     TInt len( dir.Length() + aName.Length() );
       
   307     if ( aIsFolder )
       
   308         {
       
   309         ++len; // Ensure space for backslash
       
   310         }
       
   311     HBufC* fullPath = HBufC::NewLC( len );
       
   312     TPtr ptr( fullPath->Des() );
       
   313     ptr.Append( dir );
       
   314     ptr.Append( aName );
       
   315     if ( aIsFolder )
       
   316         {
       
   317         CFileManagerUtils::EnsureFinalBackslash( ptr );
       
   318         }
       
   319     return fullPath;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CFileManagerEngine::SetMemoryL
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 EXPORT_C TInt CFileManagerEngine::SetMemoryL( TFileManagerMemory /*aMemory*/ )
       
   327     {
       
   328     // Just check current drive avaibility, no matter what memory is set
       
   329     iLastDriveAvailable = CurrentDriveAvailable();
       
   330     return KErrNone;
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CFileManagerEngine::Memory
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 EXPORT_C TFileManagerMemory CFileManagerEngine::Memory() const
       
   338     {
       
   339 #ifdef RD_MULTIPLE_DRIVE
       
   340     CGflmDriveItem* drvItem = iNavigator->CurrentDrive();
       
   341     if ( drvItem )
       
   342         {
       
   343         TUint driveStatus( drvItem->DriveStatus() );
       
   344         if ( driveStatus & DriveInfo::EDriveInternal )
       
   345             {
       
   346             if ( driveStatus & DriveInfo::EDriveExternallyMountable )
       
   347                 {
       
   348                 return EFmMassStorage;
       
   349                 }
       
   350             return EFmPhoneMemory;
       
   351             }
       
   352         else if ( driveStatus & DriveInfo::EDriveUsbMemory )
       
   353             {
       
   354             return EFmUsbMemory;
       
   355             }
       
   356         else if ( driveStatus & DriveInfo::EDriveRemovable )
       
   357             {
       
   358             return EFmMemoryCard;
       
   359             }
       
   360         else if ( driveStatus & DriveInfo::EDriveRemote )
       
   361             {
       
   362             return EFmRemoteDrive;
       
   363             }
       
   364         }
       
   365     return EFmPhoneMemory;
       
   366 #else // RD_MULTIPLE_DRIVE
       
   367     CGflmDriveItem* drvItem = iNavigator->CurrentDrive();
       
   368     if ( drvItem )
       
   369         {
       
   370         const TVolumeInfo vol( drvItem->VolumeInfo() );
       
   371         if ( vol.iDrive.iDriveAtt & KDriveAttInternal )
       
   372             {
       
   373             return EFmPhoneMemory;
       
   374             }
       
   375         else if ( vol.iDrive.iDriveAtt & KDriveAttRemovable )
       
   376             {
       
   377             return EFmMemoryCard;
       
   378             }
       
   379         else if ( vol.iDrive.iDriveAtt & KDriveAttRemote )
       
   380             {
       
   381             return EFmRemoteDrive;
       
   382             }
       
   383         }
       
   384     return EFmPhoneMemory;
       
   385 #endif // RD_MULTIPLE_DRIVE
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CFileManagerEngine::FileList
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 EXPORT_C MDesCArray* CFileManagerEngine::FileList() const
       
   393     {
       
   394     return iNavigator;
       
   395     }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // CFileManagerEngine::OpenL
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 EXPORT_C void CFileManagerEngine::OpenL( const TInt aIndex )
       
   402     {
       
   403     // Store drive letter for current drive changed checking
       
   404     TChar prevDrive( 0 );
       
   405     TPtrC prevDir( iNavigator->CurrentDirectory() );
       
   406     if ( prevDir.Length() )
       
   407         {
       
   408         prevDrive = prevDir[ 0 ];
       
   409         }   
       
   410 
       
   411     if ( aIndex < 0 || aIndex >= iNavigator->MdcaCount() )
       
   412         {
       
   413         User::Leave( KErrNotFound );
       
   414         }
       
   415     CGflmGroupItem* item = iNavigator->Item( aIndex );
       
   416     switch ( item->Type() )
       
   417         {
       
   418         case CGflmGroupItem::EFile: // Fall through
       
   419         case CGflmGroupItem::EDirectory: // Fall through
       
   420         case CGflmGroupItem::EDrive:
       
   421             {
       
   422 
       
   423 #ifdef RD_MULTIPLE_DRIVE
       
   424             // Ensure that default folders exist
       
   425             if ( item->Type() == CGflmGroupItem::EDrive )
       
   426                 {
       
   427                 CGflmDriveItem* drvItem =
       
   428                     static_cast< CGflmDriveItem* >( item );
       
   429                 iUtils->CreateDefaultFolders(
       
   430                     drvItem->Drive(), EFalse );
       
   431                 }
       
   432 #endif // RD_MULTIPLE_DRIVE
       
   433 
       
   434             // Store navigation position
       
   435             SetCurrentIndex( aIndex );
       
   436 
       
   437             HBufC* fullPath = IndexToFullPathLC( aIndex );
       
   438             if ( item->Type() == CGflmGroupItem::EFile )
       
   439                 {
       
   440                 OpenFileL( *fullPath );
       
   441                 }
       
   442             else
       
   443                 {
       
   444                 OpenDirectoryL( *fullPath );
       
   445 
       
   446                 // Setup new navigation position
       
   447                 iNavigationIndices.AppendL( 0 );
       
   448                 }
       
   449             CleanupStack::PopAndDestroy( fullPath );
       
   450             break;
       
   451             }
       
   452         case CGflmGroupItem::EGlobalActionItem:
       
   453             {
       
   454             CGflmGlobalActionItem* actItem = 
       
   455                 static_cast< CGflmGlobalActionItem* >( item );
       
   456             if ( iProcessObserver )
       
   457                 {
       
   458                 iProcessObserver->NotifyL(
       
   459                     MFileManagerProcessObserver::ENotifyActionSelected,
       
   460                     actItem->Id() );
       
   461                 }
       
   462             break;
       
   463             }
       
   464         default:
       
   465             {
       
   466             break;
       
   467             }
       
   468         }
       
   469  
       
   470     // Ensure that cached current drive info gets updated if drive was changed
       
   471     TPtrC dir( iNavigator->CurrentDirectory() );
       
   472     if ( dir.Length() )
       
   473         {
       
   474         if ( dir[ 0 ] != prevDrive )
       
   475             {
       
   476             iCurrentDriveInfoRefreshed = EFalse;
       
   477             }
       
   478         }
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CFileManagerEngine::SetObserver
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 EXPORT_C void CFileManagerEngine::SetObserver(
       
   486         MFileManagerProcessObserver* aObserver )
       
   487     {
       
   488     iProcessObserver = aObserver;
       
   489     iRefresher->SetObserver( aObserver );
       
   490     iRemovableDrvHandler->SetObserver( aObserver );
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CFileManagerEngine::CurrentDirectory
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 EXPORT_C TPtrC CFileManagerEngine::CurrentDirectory() const
       
   498     {
       
   499     return iNavigator->CurrentDirectory();
       
   500     }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CFileManagerEngine::CurrentDirectory
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 EXPORT_C TPtrC CFileManagerEngine::LocalizedNameOfCurrentDirectory() const
       
   507     {
       
   508     return iNavigator->LocalizedNameOfCurrentDirectory();
       
   509     }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CFileManagerEngine::BackstepL
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 EXPORT_C void CFileManagerEngine::BackstepL()
       
   516     {
       
   517     // Store drive letter for current drive changed checking
       
   518     TChar prevDrive( 0 );
       
   519     // Note that prevDir gets invalid after BackstepL
       
   520     TPtrC prevDir( iNavigator->CurrentDirectory() );
       
   521     if ( prevDir.Length() )
       
   522         {
       
   523         prevDrive = prevDir[ 0 ];
       
   524         }
       
   525 
       
   526     // Setup backstep navigation index
       
   527     if ( !iNavigator->NavigationLevel() )
       
   528         {
       
   529         // Always first for initial root level
       
   530         iCurrentItemName.Zero();
       
   531         }
       
   532     else if( !iCurrentItemName.Length() )
       
   533         {
       
   534         // Otherwise previously opened folder
       
   535         iCurrentItemName.Copy(
       
   536             iNavigator->LocalizedNameOfCurrentDirectory() );
       
   537         }
       
   538     TInt pos( iNavigationIndices.Count() - 1 );
       
   539     if ( pos >= 0 )
       
   540         {
       
   541         iNavigationIndices.Remove( pos );
       
   542         }
       
   543 
       
   544     iNavigator->BackstepL();
       
   545 
       
   546     // Ensure that cached current drive info gets updated if drive was changed
       
   547     TPtrC dir( iNavigator->CurrentDirectory() );
       
   548     if ( dir.Length() )
       
   549         {
       
   550         if ( dir[ 0 ] != prevDrive )
       
   551             {
       
   552             iCurrentDriveInfoRefreshed = EFalse;
       
   553             }
       
   554         }
       
   555     else
       
   556         {
       
   557         // Make sure that drive info is refreshed
       
   558         ClearDriveInfo();
       
   559         }
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CFileManagerEngine::FileTypeL
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 EXPORT_C TUint32 CFileManagerEngine::FileTypeL( const TInt aIndex ) const
       
   567     {
       
   568     TUint32 fileType( CFileManagerItemProperties::ENotDefined );
       
   569     if ( aIndex >= 0 )
       
   570         {
       
   571         HBufC* fullPath = IndexToFullPathLC( aIndex );
       
   572         fileType = FileTypeL( *fullPath );
       
   573         CleanupStack::PopAndDestroy( fullPath ); 
       
   574         }
       
   575     return fileType;
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // CFileManagerEngine::FileTypeL
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 EXPORT_C TUint32 CFileManagerEngine::FileTypeL( const TDesC& aFullPath ) const
       
   583     {
       
   584     return iUtils->FileTypeL( aFullPath );
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CFileManagerEngine::DeleteL
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 EXPORT_C CFileManagerActiveDelete* CFileManagerEngine::CreateActiveDeleteL( 
       
   592                                               CArrayFixFlat< TInt >& aIndexList )
       
   593     {
       
   594 
       
   595     CFileManagerActiveDelete* activeDelete = 
       
   596         CFileManagerActiveDelete::NewL( aIndexList, *this, *iUtils );
       
   597     return activeDelete;
       
   598     }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CFileManagerEngine::NewFolder
       
   602 // -----------------------------------------------------------------------------
       
   603 //
       
   604 EXPORT_C void CFileManagerEngine::NewFolderL( const TDesC& aFolderName )
       
   605     {   
       
   606     // Add backslash to end so that MkDir realizes that it is directory
       
   607     HBufC* fullPath = AddFullPathLC( aFolderName, ETrue );
       
   608     TPtr ptr( fullPath->Des() );
       
   609 
       
   610     if ( ptr.Length() <= KMaxFileName )
       
   611         {
       
   612         iCurrentItemName.Copy( aFolderName );
       
   613 
       
   614         // Remove white spaces from end, file server also ignores those
       
   615         iCurrentItemName.TrimRight();
       
   616 
       
   617         User::LeaveIfError( iFs.MkDir( ptr ) );
       
   618         }
       
   619     else
       
   620         {
       
   621         User::Leave( KErrBadName );
       
   622         }
       
   623 
       
   624     CleanupStack::PopAndDestroy( fullPath ); 
       
   625     }
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // CFileManagerEngine::SetCurrentItemName
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 EXPORT_C void CFileManagerEngine::SetCurrentItemName( const TDesC& aFileName )
       
   632     { 
       
   633 
       
   634     iCurrentItemName.Copy( aFileName );
       
   635 
       
   636     // Remove white spaces from end, file server also ignores those
       
   637     iCurrentItemName.TrimRight();
       
   638 
       
   639     }
       
   640 // -----------------------------------------------------------------------------
       
   641 // CFileManagerEngine::RenameL
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 EXPORT_C void CFileManagerEngine::RenameL(
       
   645         const TInt aIndex,
       
   646         const TDesC& aNewFileName )
       
   647     {
       
   648     FUNC_LOG
       
   649 
       
   650     // Make those given names as full paths
       
   651     TBool isFolder( IsFolder( aIndex ) );
       
   652     HBufC* fullPathOld = IndexToFullPathLC( aIndex );
       
   653     HBufC* fullPathNew = AddFullPathLC( aNewFileName, isFolder );
       
   654 
       
   655     if ( !fullPathOld->Compare( *fullPathNew ) )
       
   656         {
       
   657         // The name has not changed, rename is not required
       
   658         CleanupStack::PopAndDestroy( fullPathNew );
       
   659         CleanupStack::PopAndDestroy( fullPathOld );
       
   660         return;
       
   661         }
       
   662 
       
   663     // Gallery notification is relevant only for local drives
       
   664     TBool isRemoteDrive( iUtils->IsRemoteDrive( *fullPathOld ) );
       
   665 
       
   666     // Media Gallery albums get easily messed up when files are renamed.
       
   667     // Direct album editing seems a trick but it is seems to only way 
       
   668     // to update Gallery properly.
       
   669     /*CMGAlbumManager* albumManager = MGAlbumManagerFactory::NewAlbumManagerL();
       
   670     CleanupStack:: PushL( albumManager );
       
   671     TInt albumId( KErrNotFound );
       
   672     if ( !isFolder && !isRemoteDrive )
       
   673         {
       
   674         // Do album search for files only
       
   675         TRAPD( err, albumId = SearchMGAlbumIdL( *albumManager, *fullPathOld ) );
       
   676         if( err != KErrNone )
       
   677             {
       
   678             albumId = KErrNotFound;
       
   679             }
       
   680         }
       
   681 */
       
   682     // Handle rename
       
   683     delete iActiveRename;
       
   684     iActiveRename = NULL;
       
   685     iActiveRename = CFileManagerActiveRename::NewL(
       
   686         *this, *iUtils, *fullPathOld, *fullPathNew );
       
   687     ShowWaitDialogL( *iActiveRename );
       
   688     User::LeaveIfError( iActiveRename->Result() );
       
   689 
       
   690     // Update Media Gallery album if file exist in album
       
   691     /*if( albumId != KErrNotFound )
       
   692         {
       
   693         TRAP_IGNORE( { albumManager->RemoveFromAlbumL( *fullPathOld, albumId );
       
   694             albumManager->AddToAlbumL( *fullPathNew, albumId ); } );
       
   695         }
       
   696     CleanupStack::PopAndDestroy( albumManager );*/
       
   697 
       
   698     iCurrentItemName.Copy( aNewFileName );
       
   699 
       
   700     /*if ( !isRemoteDrive )
       
   701         {
       
   702         // Notify Media Gallery again
       
   703         TRAP_IGNORE( MGXFileManagerL().UpdateL( *fullPathOld, *fullPathNew ) );
       
   704         }*/
       
   705 
       
   706     CleanupStack::PopAndDestroy( fullPathNew );
       
   707     CleanupStack::PopAndDestroy( fullPathOld );
       
   708     }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // CFileManagerEngine::FolderLevel
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 EXPORT_C TInt CFileManagerEngine::FolderLevel()
       
   715     {
       
   716     CGflmDriveItem* drvItem = iNavigator->CurrentDrive();
       
   717     if ( !drvItem )
       
   718         {
       
   719         return KErrNotFound;  // Main level
       
   720         }
       
   721     TPtrC dir( iNavigator->CurrentDirectory() );
       
   722     TInt count( dir.Length() );
       
   723     if ( !count )
       
   724         {
       
   725         return KErrNotFound; // Main level
       
   726         }
       
   727     // Count how many backslashes is in string to figure out the deepness
       
   728     TInt min( drvItem->RootDirectory().Length() );
       
   729 	TInt bsCount( 0 );
       
   730 	while( count > min )
       
   731 		{
       
   732         --count;
       
   733 		if ( dir[ count ] == KFmgrBackslash()[ 0 ] )
       
   734 			{
       
   735 			++bsCount;
       
   736 			}
       
   737 		}
       
   738 	return bsCount;
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CFileManagerEngine::IsNameFoundL
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 EXPORT_C TBool CFileManagerEngine::IsNameFoundL( const TDesC& aName )
       
   746     {
       
   747     return iUtils->IsNameFoundL( aName );
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CFileManagerEngine::CurrentDrive
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 EXPORT_C TInt CFileManagerEngine::CurrentDrive()
       
   755     {
       
   756     TInt ret( KErrNotFound );
       
   757     TPtrC ptr( iNavigator->CurrentDirectory() );
       
   758     if ( ptr.Length() )
       
   759         {
       
   760         if( RFs::CharToDrive( ptr[ 0 ], ret ) != KErrNone )
       
   761             {
       
   762             ret = KErrNotFound;
       
   763             }
       
   764         }
       
   765     return ret;
       
   766     }
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // CFileManagerEngine::GetItemInfoL
       
   770 // -----------------------------------------------------------------------------
       
   771 //
       
   772 EXPORT_C CFileManagerItemProperties* CFileManagerEngine::GetItemInfoL( 
       
   773                                                 const TInt aIndex )
       
   774     {
       
   775     if ( aIndex < 0 || aIndex >= iNavigator->MdcaCount() )
       
   776         {
       
   777         User::Leave( KErrNotFound );
       
   778         }
       
   779     CGflmGroupItem* item = iNavigator->Item( aIndex );
       
   780     return CFileManagerItemProperties::NewL( *item, *iUtils, *this );
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CFileManagerEngine::SetState
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 EXPORT_C void CFileManagerEngine::SetState( TState aState )
       
   788     {
       
   789     iState = aState;
       
   790     iNavigator->EnableSearchMode( iState == ESearch );
       
   791     }
       
   792 
       
   793 // -----------------------------------------------------------------------------
       
   794 // CFileManagerEngine::SetState
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 EXPORT_C CFileManagerEngine::TState CFileManagerEngine::State() const
       
   798     {
       
   799     return iState;
       
   800     }
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // CFileManagerEngine::RefreshDirectory
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 EXPORT_C void CFileManagerEngine::RefreshDirectory()
       
   807     {
       
   808     FUNC_LOG
       
   809 
       
   810 #ifdef FILE_MANAGER_INFO_LOG_ENABLED
       
   811     if ( iState == ENavigation )
       
   812         {
       
   813         TPtrC dir( iNavigator->CurrentDirectory() );
       
   814         INFO_LOG1( "CFileManagerEngine::RefreshDirectory-dir=%S", &dir );
       
   815         }
       
   816 #endif // FILE_MANAGER_INFO_LOG_ENABLED
       
   817 
       
   818     iRefresher->Refresh();
       
   819     }
       
   820 
       
   821 // -----------------------------------------------------------------------------
       
   822 // CFileManagerEngine::GetMMCInfoL
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 EXPORT_C TFileManagerDriveInfo CFileManagerEngine::GetMMCInfoL() const
       
   826     {
       
   827     TFileManagerDriveInfo drvInfo;
       
   828     GetDriveInfoL(
       
   829         PathInfo::MemoryCardRootPath(), drvInfo );
       
   830     return drvInfo;
       
   831     }
       
   832 
       
   833 // -----------------------------------------------------------------------------
       
   834 // CFileManagerEngine::SearchString
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 EXPORT_C TPtrC CFileManagerEngine::SearchString() const
       
   838     {
       
   839     if ( iSearchString )
       
   840         {
       
   841         return iSearchString->Des();
       
   842         }
       
   843     return TPtrC( KNullDesC );
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // CFileManagerEngine::IsValidName
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 EXPORT_C TBool CFileManagerEngine::IsValidName(
       
   851         const TDesC& aDriveAndPath, const TDesC& aName, TBool aIsFolder ) const
       
   852     {
       
   853     // Check name for bad chars
       
   854     const TUint16 KMinAllowedChar = 0x0020;
       
   855     const TUint16 KParagraphSeparator = 0x2029;
       
   856     const TUint16 KDot = '.';
       
   857     TInt nameLen( aName.Length() );
       
   858     if ( !nameLen )
       
   859         {
       
   860         return EFalse;
       
   861         }
       
   862     for ( TInt i( 0 ); i < nameLen; i++ )
       
   863         {
       
   864         TUint16 ch( aName[ i ] );
       
   865         if ( ch < KMinAllowedChar || ch == KParagraphSeparator )
       
   866             {
       
   867             return EFalse;
       
   868             }
       
   869         }
       
   870     // File system ignores totally dot in the end of name, so 
       
   871     // we set here as not valid name, so that user gets correctly informed
       
   872     if ( aName[ nameLen - 1 ] == KDot || IllegalChars( aName ) )
       
   873         {
       
   874         return EFalse;
       
   875         }
       
   876     // Get full path length
       
   877     TPtrC pathPtr( aDriveAndPath.Length() ?
       
   878         TPtrC( aDriveAndPath ) : TPtrC( iNavigator->CurrentDirectory() ) );
       
   879     TInt pathLen( pathPtr.Length() );
       
   880     if ( !pathLen )
       
   881         {
       
   882         return EFalse;
       
   883         }
       
   884     TInt fullPathLen( pathLen );
       
   885     if ( !CFileManagerUtils::HasFinalBackslash( pathPtr ) )
       
   886         {
       
   887         ++fullPathLen; // Add backslash before name
       
   888         }
       
   889     fullPathLen += nameLen;
       
   890     if ( aIsFolder )
       
   891         {
       
   892         ++fullPathLen; // Add folder final backslash
       
   893         }
       
   894 
       
   895     TBool ret( EFalse );
       
   896     if ( fullPathLen <= KMaxFileName )
       
   897         {
       
   898         // Check full path
       
   899         HBufC* fullPath = HBufC::New( KMaxFileName );
       
   900         if ( fullPath )
       
   901             {
       
   902             TPtr ptr( fullPath->Des() );
       
   903             ptr.Copy( pathPtr );
       
   904             CFileManagerUtils::EnsureFinalBackslash( ptr ); // Add backslash before name
       
   905             ptr.Append( aName );
       
   906             ret = iFs.IsValidName( ptr );
       
   907             delete fullPath;
       
   908             }
       
   909         }
       
   910     return ret;
       
   911     }
       
   912 
       
   913 // -----------------------------------------------------------------------------
       
   914 // CFileManagerEngine::IllegalChars
       
   915 // -----------------------------------------------------------------------------
       
   916 //
       
   917 EXPORT_C TBool CFileManagerEngine::IllegalChars( const TDesC& aName ) const
       
   918     {
       
   919     for ( TInt i( 0 ); KIllegalChars[ i ]; i++ )
       
   920         {
       
   921         if ( aName.Locate( KIllegalChars[ i ] ) != KErrNotFound )
       
   922             {
       
   923             return ETrue;
       
   924             }
       
   925         }
       
   926     return EFalse;
       
   927     }
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // CFileManagerEngine::EnoughSpaceL
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 EXPORT_C TBool CFileManagerEngine::EnoughSpaceL(
       
   934         const TDesC& aToFolder, 
       
   935         TInt64 aSize, 
       
   936         MFileManagerProcessObserver::TFileManagerProcess aOperation ) const
       
   937     {
       
   938     TPtrC src( iNavigator->CurrentDirectory() );
       
   939     TInt srcDrv( KErrNotFound );
       
   940     if ( src.Length() )
       
   941         {
       
   942         User::LeaveIfError( RFs::CharToDrive( src[ 0 ], srcDrv ) );
       
   943         }
       
   944     TInt dstDrv( KErrNotFound );
       
   945     if ( aToFolder.Length() )
       
   946         {
       
   947         User::LeaveIfError( RFs::CharToDrive( aToFolder[ 0 ], dstDrv ) );
       
   948         }
       
   949     else
       
   950         {
       
   951         return ETrue; // Invalid destination
       
   952         }
       
   953 
       
   954     TBool ret( EFalse );
       
   955 
       
   956     // if operation is move and drive is same so there is always enough memory
       
   957     if ( srcDrv == dstDrv &&
       
   958         aOperation == MFileManagerProcessObserver::EMoveProcess )
       
   959         {
       
   960         ret = ETrue;
       
   961         }
       
   962     else
       
   963         {
       
   964         ret = !SysUtil::DiskSpaceBelowCriticalLevelL(
       
   965             &iFs,  aSize , dstDrv );
       
   966         }
       
   967 
       
   968     return ret;
       
   969     }
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 // CFileManagerEngine::FileSystemEvent
       
   973 // -----------------------------------------------------------------------------
       
   974 //
       
   975 EXPORT_C void CFileManagerEngine::FileSystemEvent( TBool aEventOn )
       
   976     {
       
   977     INFO_LOG2(
       
   978         "CFileManagerEngine::FileSystemEvent-aEventOn=%d,iFileSystemEventEnabled=%d",
       
   979         aEventOn, iFileSystemEventEnabled )
       
   980 
       
   981     INFO_LOG2(
       
   982         "CFileManagerEngine::FileSystemEvent-iDriveAddedOrChangedPostponed=%d,iEmbeddedApplicationOn=%d ",
       
   983         iDriveAddedOrChangedPostponed, iEmbeddedApplicationOn )
       
   984 
       
   985     if ( !iFileSystemEventEnabled && aEventOn )
       
   986         {
       
   987         iDriveAddedOrChangedPostponed = EFalse;
       
   988         iFileSystemEventEnabled = ETrue;
       
   989         }
       
   990     else if ( iFileSystemEventEnabled && !aEventOn )
       
   991         {
       
   992         iFileSystemEventEnabled = EFalse;
       
   993         if ( iDriveAddedOrChangedPostponed )
       
   994             {
       
   995             iDriveAddedOrChangedPostponed = EFalse;
       
   996             TRAP_IGNORE( DriveAddedOrChangedL() );
       
   997             }
       
   998         }
       
   999 
       
  1000     if ( iUtils->IsRemoteDrive( iNavigator->CurrentDirectory() ) )
       
  1001         {
       
  1002          // At the moment no use to have event for remote drives
       
  1003         delete iFileSystemEvent;
       
  1004         iFileSystemEvent = NULL;
       
  1005         return;
       
  1006         }
       
  1007 
       
  1008     // Set event on when there is no embedded app with event
       
  1009     if ( aEventOn &&
       
  1010          !( iEmbeddedApplicationOn && iFileSystemEvent ) )
       
  1011         {
       
  1012         TInt err( KErrNone );
       
  1013         switch ( iState )
       
  1014             {
       
  1015             case ENavigation:
       
  1016                 {
       
  1017                 TRAP( err, SetFileSystemEventL( iNavigator->CurrentDirectory() ) );
       
  1018                 break;
       
  1019                 }
       
  1020             case ESearch:
       
  1021                 {
       
  1022                 TRAP( err, SetFileSystemEventL() );
       
  1023                 break;
       
  1024                 }
       
  1025             default:
       
  1026                 {
       
  1027                 break;
       
  1028                 }
       
  1029             }
       
  1030         if ( err != KErrNone && iProcessObserver )
       
  1031             {
       
  1032             iProcessObserver->Error( err );
       
  1033             }
       
  1034         }
       
  1035     // Check event and set it off when there is no embedded app
       
  1036     else if( !iEmbeddedApplicationOn && iFileSystemEvent )
       
  1037         {
       
  1038         iFileSystemEvent->CheckFileSystemEvent();
       
  1039         delete iFileSystemEvent;
       
  1040         iFileSystemEvent = NULL;
       
  1041         }
       
  1042     }
       
  1043 
       
  1044 // ------------------------------------------------------------------------------
       
  1045 // CFileManagerEngine::CurrentIndex
       
  1046 //
       
  1047 // ------------------------------------------------------------------------------
       
  1048 //
       
  1049 EXPORT_C TInt CFileManagerEngine::CurrentIndex()
       
  1050     {
       
  1051     if ( iCurrentItemName.Length() )
       
  1052         {
       
  1053         TInt count( iNavigator->MdcaCount() );
       
  1054         for( TInt i( 0 ); i < count; ++i )
       
  1055             {
       
  1056             CGflmGroupItem* item = iNavigator->Item( i );
       
  1057             if ( !item->Name().CompareF( iCurrentItemName ) )
       
  1058                 {
       
  1059                 iCurrentItemName.Zero();
       
  1060                 return i;
       
  1061                 }
       
  1062             }
       
  1063         iCurrentItemName.Zero();
       
  1064         }
       
  1065 
       
  1066     // Top navigation index
       
  1067     TInt pos( iNavigationIndices.Count() - 1 );
       
  1068     if ( pos >= 0 )
       
  1069         {
       
  1070         return iNavigationIndices[ pos ];
       
  1071         }
       
  1072     return KErrNotFound;
       
  1073     }
       
  1074 
       
  1075 // ------------------------------------------------------------------------------
       
  1076 // CFileManagerEngine::CanDelete
       
  1077 //
       
  1078 // ------------------------------------------------------------------------------
       
  1079 //
       
  1080 TBool CFileManagerEngine::CanDelete( const TDesC& aFileName ) const
       
  1081     {
       
  1082     return iUtils->CanDelete( aFileName );
       
  1083     }
       
  1084 
       
  1085 // ------------------------------------------------------------------------------
       
  1086 // CFileManagerEngine::LocalizedName
       
  1087 //
       
  1088 // ------------------------------------------------------------------------------
       
  1089 //
       
  1090 EXPORT_C TPtrC CFileManagerEngine::LocalizedName(
       
  1091         const TDesC& aFullPath ) const
       
  1092     {
       
  1093     return iUtils->LocalizedName( aFullPath );
       
  1094     }
       
  1095 
       
  1096 // ------------------------------------------------------------------------------
       
  1097 // CFileManagerEngine::FilesInFolderL
       
  1098 //
       
  1099 // ------------------------------------------------------------------------------
       
  1100 //
       
  1101 EXPORT_C TInt CFileManagerEngine::FilesInFolderL()
       
  1102     {
       
  1103     TInt ret( 0 );
       
  1104     switch ( iState )
       
  1105         {
       
  1106         case ENavigation: // Fall through
       
  1107         case ESearch:
       
  1108             {
       
  1109             TInt count( iNavigator->MdcaCount() );
       
  1110             for( TInt i( 0 ); i < count; ++i )
       
  1111                 {
       
  1112                 CGflmGroupItem* item = iNavigator->Item( i );
       
  1113                 if ( item->Type() == CGflmGroupItem::EFile )
       
  1114                     {
       
  1115                     ++ret;
       
  1116                     }
       
  1117                 }
       
  1118             break;
       
  1119             }
       
  1120         default:
       
  1121             {
       
  1122             break;
       
  1123             }
       
  1124         }
       
  1125     return ret;
       
  1126     }
       
  1127 
       
  1128 // ------------------------------------------------------------------------------
       
  1129 // CFileManagerEngine::CancelRefresh
       
  1130 //
       
  1131 // ------------------------------------------------------------------------------
       
  1132 //
       
  1133 EXPORT_C TBool CFileManagerEngine::CancelRefresh()
       
  1134     {
       
  1135     switch ( iState )
       
  1136         {
       
  1137         case ENavigation:
       
  1138             {
       
  1139             CancelTransfer( iNavigator->CurrentDirectory() );
       
  1140             break;
       
  1141             }
       
  1142         case ESearch:
       
  1143             {
       
  1144             if ( iSearchFolder )
       
  1145                 {
       
  1146                 CancelTransfer( *iSearchFolder );
       
  1147                 }
       
  1148             break;
       
  1149             }
       
  1150         default:
       
  1151             {
       
  1152             break;
       
  1153             }
       
  1154         }
       
  1155     return iRefresher->CancelRefresh();
       
  1156     }
       
  1157 
       
  1158 // ------------------------------------------------------------------------------
       
  1159 // CFileManagerEngine::DriveAddedOrChangedL
       
  1160 //
       
  1161 // ------------------------------------------------------------------------------
       
  1162 //
       
  1163 void CFileManagerEngine::DriveAddedOrChangedL()
       
  1164     {
       
  1165     FUNC_LOG
       
  1166     
       
  1167     if( iDiskEvent )
       
  1168         {
       
  1169         iDiskEvent->Setup();
       
  1170         }
       
  1171         
       
  1172     TBool processOngoing( iRemovableDrvHandler->IsProcessOngoing() );
       
  1173 
       
  1174     INFO_LOG3( "CFileManagerEngine::DriveAddedOrChangedL-event=%d,process=%d,postponed=%d ",
       
  1175         iFileSystemEventEnabled, processOngoing, iDriveAddedOrChangedPostponed )
       
  1176 
       
  1177     if ( iFileSystemEventEnabled || processOngoing )
       
  1178         {
       
  1179         iDriveAddedOrChangedPostponed = ETrue;
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         iDriveAddedOrChangedPostponed = EFalse;
       
  1184         ClearDriveInfo();
       
  1185         if ( iProcessObserver &&
       
  1186              !iEmbeddedApplicationOn &&
       
  1187              !iWaitDialogOn &&
       
  1188              !iRefresher->IsActive() )
       
  1189             {
       
  1190             TPtrC dir( iNavigator->CurrentDirectory() );
       
  1191             if ( dir.Length() )
       
  1192                 {
       
  1193                 TBool isAvailable( CurrentDriveAvailable() );
       
  1194 
       
  1195                 if ( iUtils->IsRemoteDrive( dir ) )
       
  1196                     {
       
  1197                     // Notify whether remote drive has become available
       
  1198                     // So when receiving remote drive connection event,
       
  1199                     // View will be refreshed
       
  1200                     //if ( !iLastDriveAvailable && isAvailable )
       
  1201                     //    {
       
  1202                         iProcessObserver->NotifyL(
       
  1203                             MFileManagerProcessObserver::ENotifyDisksChanged, 0 );
       
  1204                     //    }
       
  1205                     }
       
  1206                 else
       
  1207                     {
       
  1208                     // Notify if drive has become unavailable or
       
  1209                     // avaibility has changed
       
  1210                     if ( !isAvailable ||
       
  1211                         isAvailable != iLastDriveAvailable )
       
  1212                         {
       
  1213                         iProcessObserver->NotifyL(
       
  1214                             MFileManagerProcessObserver::ENotifyDisksChanged, 0 );
       
  1215                         }
       
  1216                     }
       
  1217                 }
       
  1218             else
       
  1219                 {
       
  1220                 // Notify always when no folder is opened
       
  1221                 iProcessObserver->NotifyL(
       
  1222                     MFileManagerProcessObserver::ENotifyDisksChanged, 0 );
       
  1223                 }
       
  1224             }
       
  1225         }
       
  1226     }
       
  1227 
       
  1228 // ------------------------------------------------------------------------------
       
  1229 // CFileManagerEngine::FolderContentChangedL
       
  1230 //
       
  1231 // ------------------------------------------------------------------------------
       
  1232 //
       
  1233 void CFileManagerEngine::FolderContentChangedL()
       
  1234     {
       
  1235     if( iProcessObserver )
       
  1236         {
       
  1237         iProcessObserver->NotifyL(
       
  1238             MFileManagerProcessObserver::ENotifyDisksChanged, 0 );
       
  1239         }
       
  1240     else
       
  1241         {
       
  1242         RefreshDirectory();
       
  1243         }
       
  1244     }
       
  1245 
       
  1246 // ------------------------------------------------------------------------------
       
  1247 // CFileManagerEngine::IsFolder
       
  1248 //
       
  1249 // ------------------------------------------------------------------------------
       
  1250 //
       
  1251 EXPORT_C TBool CFileManagerEngine::IsFolder( const TInt aIndex ) const
       
  1252     {
       
  1253     if ( aIndex < 0 || aIndex >= iNavigator->MdcaCount() )
       
  1254         {
       
  1255         return EFalse;
       
  1256         }
       
  1257     CGflmGroupItem* item = iNavigator->Item( aIndex );
       
  1258     TBool ret( EFalse );
       
  1259     switch ( item->Type() )
       
  1260         {
       
  1261         case CGflmGroupItem::EDirectory: // Fallthrough
       
  1262         case CGflmGroupItem::EDrive: // Fallthrough
       
  1263         case CGflmGroupItem::EGlobalActionItem:
       
  1264             {
       
  1265             ret = ETrue;
       
  1266             break;
       
  1267             }
       
  1268         default:
       
  1269             {
       
  1270             break;
       
  1271             }
       
  1272         }
       
  1273     return ret;
       
  1274     }
       
  1275 
       
  1276 // ------------------------------------------------------------------------------
       
  1277 // CFileManagerEngine::IconIdL
       
  1278 //
       
  1279 // ------------------------------------------------------------------------------
       
  1280 //
       
  1281 EXPORT_C TInt CFileManagerEngine::IconIdL( const TInt aIndex ) const
       
  1282     {
       
  1283     if ( aIndex < 0 || aIndex >= iNavigator->MdcaCount() )
       
  1284         {
       
  1285         User::Leave( KErrNotFound );
       
  1286         }
       
  1287     CGflmGroupItem* item = iNavigator->Item( aIndex );
       
  1288     return iUtils->ResolveIconL( *item );
       
  1289     }
       
  1290 
       
  1291 // -----------------------------------------------------------------------------
       
  1292 // CFileManagerEngine::ShowWaitDialogL( MAknBackgroundProcess& aProcess )
       
  1293 //
       
  1294 // -----------------------------------------------------------------------------
       
  1295 //
       
  1296 void CFileManagerEngine::ShowWaitDialogL( MAknBackgroundProcess& aProcess )
       
  1297     {
       
  1298     iWaitDialogOn = ETrue;
       
  1299     TRAPD( err, iProcessObserver->ShowWaitDialogL( aProcess ) );
       
  1300     iWaitDialogOn = EFalse;
       
  1301     User::LeaveIfError( err );
       
  1302     }
       
  1303 
       
  1304 // -----------------------------------------------------------------------------
       
  1305 // CFileManagerEngine::EmbeddedAppStatus( TBool aStatus )
       
  1306 //
       
  1307 // -----------------------------------------------------------------------------
       
  1308 //
       
  1309 void CFileManagerEngine::EmbeddedAppStatus( TBool aStatus )
       
  1310     {
       
  1311     iEmbeddedApplicationOn = aStatus;
       
  1312     FileSystemEvent( aStatus );
       
  1313     }
       
  1314 
       
  1315 // -----------------------------------------------------------------------------
       
  1316 // CFileManagerEngine::IsSystemFolder
       
  1317 //
       
  1318 // -----------------------------------------------------------------------------
       
  1319 //
       
  1320 EXPORT_C TBool CFileManagerEngine::IsSystemFolder( const TDesC& aFullPath ) const
       
  1321     {
       
  1322     _LIT( KSystemFolder, "?:\\system\\*" );
       
  1323     _LIT( KSysFolder, "?:\\sys\\*" );
       
  1324     _LIT( KPrivateFolder, "?:\\private\\*" );
       
  1325     _LIT( KResourceFolder, "?:\\resource\\*" );
       
  1326 
       
  1327     if ( aFullPath.MatchF( KSystemFolder ) != KErrNotFound ||
       
  1328         aFullPath.MatchF( KSysFolder ) != KErrNotFound ||
       
  1329         aFullPath.MatchF( KResourceFolder ) != KErrNotFound ||
       
  1330         aFullPath.MatchF( KPrivateFolder ) != KErrNotFound )
       
  1331         {
       
  1332         return ETrue;
       
  1333         }
       
  1334     return EFalse;
       
  1335     }
       
  1336 
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // CFileManagerEngine::CurrentDriveName()
       
  1339 //
       
  1340 // -----------------------------------------------------------------------------
       
  1341 //
       
  1342 EXPORT_C TPtrC CFileManagerEngine::CurrentDriveName()
       
  1343     {
       
  1344 #ifdef RD_MULTIPLE_DRIVE
       
  1345     TPtrC dir( iNavigator->CurrentDirectory() );
       
  1346     if ( dir.Length() )
       
  1347         {
       
  1348         TInt drive = TDriveUnit( dir );
       
  1349         return DriveName( drive );
       
  1350         }
       
  1351 #else // RD_MULTIPLE_DRIVE
       
  1352     CGflmDriveItem* drvItem = iNavigator->CurrentDrive();
       
  1353     if ( drvItem )
       
  1354         {
       
  1355         return drvItem->Name();
       
  1356         }
       
  1357 #endif // RD_MULTIPLE_DRIVE
       
  1358     return TPtrC( KNullDesC );
       
  1359     }
       
  1360 
       
  1361 // -----------------------------------------------------------------------------
       
  1362 // CFileManagerEngine::GetDriveInfoL()
       
  1363 //
       
  1364 // -----------------------------------------------------------------------------
       
  1365 //
       
  1366 EXPORT_C void CFileManagerEngine::GetDriveInfoL(
       
  1367         TFileManagerDriveInfo& aInfo )
       
  1368     {
       
  1369     if ( iCurrentDriveInfoRefreshed )
       
  1370         {
       
  1371         // Use cached info
       
  1372         aInfo = iCurrentDriveInfo;
       
  1373         return;
       
  1374         }
       
  1375 
       
  1376     CGflmDriveItem* drvItem = iNavigator->CurrentDrive();
       
  1377     if ( drvItem )
       
  1378         {
       
  1379         GetDriveInfoL( drvItem->Drive(), aInfo );
       
  1380 
       
  1381         // Store info for later use
       
  1382         iCurrentDriveInfo = aInfo;
       
  1383         iCurrentDriveInfoRefreshed = ETrue;
       
  1384         }
       
  1385     else
       
  1386         {
       
  1387         User::Leave( KErrNotFound );
       
  1388         }
       
  1389     }
       
  1390 
       
  1391 // -----------------------------------------------------------------------------
       
  1392 // CFileManagerEngine::IsDistributableFile()
       
  1393 //
       
  1394 // -----------------------------------------------------------------------------
       
  1395 //
       
  1396 EXPORT_C TInt CFileManagerEngine::IsDistributableFile(
       
  1397         const TDesC& aFullPath, TBool& aIsProtected ) const
       
  1398     {
       
  1399     return iUtils->IsDistributableFile( aFullPath, aIsProtected );
       
  1400     }
       
  1401 
       
  1402 // -----------------------------------------------------------------------------
       
  1403 // CFileManagerEngine::RenameDrive()
       
  1404 //
       
  1405 // -----------------------------------------------------------------------------
       
  1406 //
       
  1407 EXPORT_C TInt CFileManagerEngine::RenameDrive(
       
  1408         const TInt aDrive,
       
  1409         const TDesC& aName )
       
  1410     {
       
  1411     TInt len( aName.Length( ) );
       
  1412     for( TInt i( 0 ); i < len; i++ )
       
  1413         {
       
  1414         TChar ch( aName[ i ] );
       
  1415         // If not alphadigit or space, return error
       
  1416         if( !ch.IsAlphaDigit() && !ch.IsSpace() )
       
  1417             {
       
  1418             return KErrBadName;
       
  1419             }
       
  1420         }
       
  1421     TInt err( iFs.SetVolumeLabel( aName, aDrive ) );
       
  1422     if ( err == KErrNone )
       
  1423         {
       
  1424         // Refresh drive info after rename
       
  1425         ClearDriveInfo();
       
  1426         }
       
  1427     return err;
       
  1428     }
       
  1429 
       
  1430 // -----------------------------------------------------------------------------
       
  1431 // CFileManagerEngine::SetDrivePassword()
       
  1432 //
       
  1433 // -----------------------------------------------------------------------------
       
  1434 //
       
  1435 EXPORT_C TInt CFileManagerEngine::SetDrivePassword(
       
  1436         const TInt aDrive,
       
  1437         const TMediaPassword& aOld,
       
  1438         const TMediaPassword& aNew )
       
  1439     {
       
  1440     ClearDriveInfo();
       
  1441     TInt err( iFs.LockDrive( aDrive, aOld, aNew, ETrue ) );
       
  1442     INFO_LOG1( "CFileManagerEngine::SetDrivePassword err %d", err );
       
  1443     return err;
       
  1444     }
       
  1445 
       
  1446 // -----------------------------------------------------------------------------
       
  1447 // CFileManagerEngine::RemoveDrivePassword()
       
  1448 //
       
  1449 // -----------------------------------------------------------------------------
       
  1450 //
       
  1451 EXPORT_C TInt CFileManagerEngine::RemoveDrivePassword(
       
  1452         const TInt aDrive,
       
  1453         const TMediaPassword& aPwd )
       
  1454     {
       
  1455     ClearDriveInfo();
       
  1456     TInt err( iFs.ClearPassword( aDrive, aPwd ) );
       
  1457     INFO_LOG1( "CFileManagerEngine::RemoveDrivePassword err %d", err );
       
  1458     return err;
       
  1459     }
       
  1460 
       
  1461 // -----------------------------------------------------------------------------
       
  1462 // CFileManagerEngine::UnlockDrive()
       
  1463 //
       
  1464 // -----------------------------------------------------------------------------
       
  1465 //    
       
  1466 EXPORT_C TInt CFileManagerEngine::UnlockDrive(
       
  1467         const TInt aDrive,
       
  1468         const TMediaPassword& aPwd )
       
  1469     {
       
  1470     ClearDriveInfo();
       
  1471     TInt err( iFs.UnlockDrive( aDrive, aPwd, ETrue ) );
       
  1472     INFO_LOG1( "CFileManagerEngine::UnlockDrive err %d", err );
       
  1473     return err;
       
  1474     }
       
  1475 
       
  1476 // -----------------------------------------------------------------------------
       
  1477 // CFileManagerEngine::StartFormatProcessL()
       
  1478 //
       
  1479 // -----------------------------------------------------------------------------
       
  1480 //  
       
  1481 EXPORT_C void CFileManagerEngine::StartFormatProcessL(
       
  1482         const TInt aDrive )
       
  1483     {
       
  1484     ClearDriveInfo();
       
  1485     iRemovableDrvHandler->StartFormatL( aDrive );
       
  1486     }
       
  1487 
       
  1488 // -----------------------------------------------------------------------------
       
  1489 // CFileManagerEngine::StartEjectProcessL()
       
  1490 //
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //  
       
  1493 EXPORT_C void CFileManagerEngine::StartEjectProcessL( const TInt /*aDrive*/ )
       
  1494     {
       
  1495     ClearDriveInfo();
       
  1496     iRemovableDrvHandler->StartEjectL();
       
  1497     }
       
  1498 
       
  1499 // -----------------------------------------------------------------------------
       
  1500 // CFileManagerEngine::StartBackupProcessL()
       
  1501 //
       
  1502 // -----------------------------------------------------------------------------
       
  1503 //  
       
  1504 EXPORT_C void CFileManagerEngine::StartBackupProcessL(
       
  1505         MFileManagerProcessObserver::TFileManagerProcess aProcess )
       
  1506     {
       
  1507     switch( aProcess )
       
  1508         {
       
  1509         case MFileManagerProcessObserver::EBackupProcess: // FALLTHROUGH
       
  1510         case MFileManagerProcessObserver::ESchBackupProcess:
       
  1511             {
       
  1512             // Make sure that there is no embedded apps open
       
  1513             delete iDocHandler;
       
  1514             iDocHandler = NULL;
       
  1515 
       
  1516             ClearDriveInfo();
       
  1517             iRemovableDrvHandler->StartBackupL( aProcess );
       
  1518             break;
       
  1519             }
       
  1520         case MFileManagerProcessObserver::ERestoreProcess:
       
  1521             {
       
  1522             ClearDriveInfo();
       
  1523             iRemovableDrvHandler->StartRestoreL();
       
  1524             break;
       
  1525             }
       
  1526         default:
       
  1527             {
       
  1528             User::Leave( KErrNotSupported );
       
  1529             break;
       
  1530             }
       
  1531         }
       
  1532     }
       
  1533 
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // CFileManagerEngine::CancelProcess()
       
  1536 //
       
  1537 // -----------------------------------------------------------------------------
       
  1538 //  
       
  1539 EXPORT_C void CFileManagerEngine::CancelProcess(
       
  1540         MFileManagerProcessObserver::TFileManagerProcess aProcess )
       
  1541     {
       
  1542     switch( aProcess )
       
  1543         {
       
  1544         case MFileManagerProcessObserver::EFormatProcess:
       
  1545         case MFileManagerProcessObserver::EBackupProcess: // FALLTHROUGH
       
  1546         case MFileManagerProcessObserver::ERestoreProcess: // FALLTHROUGH
       
  1547         case MFileManagerProcessObserver::ESchBackupProcess: // FALLTHROUGH
       
  1548             {
       
  1549             iRemovableDrvHandler->CancelProcess();
       
  1550             break;
       
  1551             }
       
  1552         case MFileManagerProcessObserver::EFileOpenProcess:
       
  1553             {
       
  1554             if ( iDocHandler )
       
  1555                 {
       
  1556                 iDocHandler->CancelFileOpen();
       
  1557                 }
       
  1558             break;
       
  1559             }
       
  1560         default:
       
  1561             {
       
  1562             break;
       
  1563             }
       
  1564         }
       
  1565     }
       
  1566 
       
  1567 // -----------------------------------------------------------------------------
       
  1568 // CFileManagerEngine::GetDriveInfoL()
       
  1569 //
       
  1570 // -----------------------------------------------------------------------------
       
  1571 // 
       
  1572 void CFileManagerEngine::GetDriveInfoL(
       
  1573         const TDesC& aPath,
       
  1574         TFileManagerDriveInfo& aInfo ) const
       
  1575     {
       
  1576     if ( !aPath.Length() )
       
  1577         {
       
  1578         User::Leave( KErrNotFound );
       
  1579         }
       
  1580     TInt drv( 0 );
       
  1581     User::LeaveIfError( RFs::CharToDrive( aPath[ 0 ], drv ) );
       
  1582     GetDriveInfoL( drv, aInfo );
       
  1583     }
       
  1584 
       
  1585 // -----------------------------------------------------------------------------
       
  1586 // CFileManagerEngine::DriveState()
       
  1587 //
       
  1588 // -----------------------------------------------------------------------------
       
  1589 // 
       
  1590 EXPORT_C TInt CFileManagerEngine::DriveState(
       
  1591         TUint32& aState, const TDesC& aPath ) const
       
  1592     {
       
  1593     TFileManagerDriveInfo info;
       
  1594     TRAPD( err, GetDriveInfoL( aPath, info ) );
       
  1595     if ( err == KErrNone )
       
  1596         {
       
  1597         aState = info.iState;
       
  1598         }
       
  1599     else
       
  1600         {
       
  1601         aState = 0;
       
  1602         }
       
  1603     return err;
       
  1604     }
       
  1605 
       
  1606 // -----------------------------------------------------------------------------
       
  1607 // CFileManagerEngine::DriveState()
       
  1608 //
       
  1609 // -----------------------------------------------------------------------------
       
  1610 // 
       
  1611 EXPORT_C TInt CFileManagerEngine::DriveState(
       
  1612         TUint32& aState, const TInt aDrive ) const
       
  1613     {
       
  1614     TFileManagerDriveInfo info;
       
  1615     TRAPD( err, GetDriveInfoL( aDrive, info ) );
       
  1616     if ( err == KErrNone )
       
  1617         {
       
  1618         aState = info.iState;
       
  1619         }
       
  1620     else
       
  1621         {
       
  1622         aState = 0;
       
  1623         }
       
  1624     return err;
       
  1625     }
       
  1626 
       
  1627 // -----------------------------------------------------------------------------
       
  1628 // CFileManagerEngine::MGXFileManagerL()
       
  1629 //
       
  1630 // -----------------------------------------------------------------------------
       
  1631 // 
       
  1632 /*CMGXFileManager& CFileManagerEngine::MGXFileManagerL()
       
  1633     {
       
  1634     // MG2 notification object
       
  1635     if ( !iMgxFileManager )
       
  1636         {
       
  1637         INFO_LOG( "CFileManagerEngine::MGXFileManagerL()-Create" )
       
  1638         iMgxFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
       
  1639         }
       
  1640     return *iMgxFileManager;
       
  1641     }*/
       
  1642 
       
  1643 // -----------------------------------------------------------------------------
       
  1644 // CFileManagerEngine::Fs()
       
  1645 //
       
  1646 // -----------------------------------------------------------------------------
       
  1647 // 
       
  1648 RFs& CFileManagerEngine::Fs() const
       
  1649     {
       
  1650     return iFs;
       
  1651     }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CFileManagerEngine::IsRemoteDriveConnected()
       
  1655 //
       
  1656 // -----------------------------------------------------------------------------
       
  1657 // 
       
  1658 TBool CFileManagerEngine::IsRemoteDriveConnected( const TInt aDrive  ) const
       
  1659     {
       
  1660     return iRemoteDrvHandler->IsConnected( aDrive );
       
  1661     }
       
  1662 
       
  1663 // -----------------------------------------------------------------------------
       
  1664 // CFileManagerEngine::SetRemoteDriveConnection()
       
  1665 //
       
  1666 // -----------------------------------------------------------------------------
       
  1667 // 
       
  1668 EXPORT_C TInt CFileManagerEngine::SetRemoteDriveConnection(
       
  1669         const TInt aDrive, TBool aConnect )
       
  1670     {
       
  1671     return iRemoteDrvHandler->SetConnection( aDrive, aConnect );
       
  1672     }
       
  1673 
       
  1674 // -----------------------------------------------------------------------------
       
  1675 // CFileManagerEngine::DeleteRemoteDrive()
       
  1676 //
       
  1677 // -----------------------------------------------------------------------------
       
  1678 // 
       
  1679 EXPORT_C TInt CFileManagerEngine::DeleteRemoteDrive( const TInt aDrive )
       
  1680     {
       
  1681     return iRemoteDrvHandler->DeleteSettings( aDrive );
       
  1682     }
       
  1683 
       
  1684 // -----------------------------------------------------------------------------
       
  1685 // CFileManagerEngine::BackupFileExistsL()
       
  1686 //
       
  1687 // -----------------------------------------------------------------------------
       
  1688 // 
       
  1689 #ifndef RD_FILE_MANAGER_BACKUP
       
  1690 
       
  1691 TBool CFileManagerEngine::BackupFileExistsL( const TInt aDrive ) const
       
  1692     {
       
  1693     return iRemovableDrvHandler->BackupFileExistsL( aDrive );
       
  1694     }
       
  1695 
       
  1696 #endif // RD_FILE_MANAGER_BACKUP
       
  1697 
       
  1698 // -----------------------------------------------------------------------------
       
  1699 // CFileManagerEngine::OpenFileL()
       
  1700 //
       
  1701 // -----------------------------------------------------------------------------
       
  1702 // 
       
  1703 void CFileManagerEngine::OpenFileL( const TDesC& aFullPath )
       
  1704     {
       
  1705     if ( !iDocHandler )
       
  1706         {
       
  1707         iDocHandler = CFileManagerDocHandler::NewL( *this, *iUtils );
       
  1708         }
       
  1709     iDocHandler->OpenFileL( aFullPath, iProcessObserver );
       
  1710     }
       
  1711 
       
  1712 // -----------------------------------------------------------------------------
       
  1713 // CFileManagerEngine::OpenDirectoryL()
       
  1714 //
       
  1715 // -----------------------------------------------------------------------------
       
  1716 // 
       
  1717 void CFileManagerEngine::OpenDirectoryL( const TDesC& aFullPath )
       
  1718     {
       
  1719     iNavigator->GoToDirectoryL( aFullPath, ETrue );
       
  1720     }
       
  1721 
       
  1722 // -----------------------------------------------------------------------------
       
  1723 // CFileManagerEngine::DriveRootDirectory()
       
  1724 //
       
  1725 // -----------------------------------------------------------------------------
       
  1726 //
       
  1727 EXPORT_C TPtrC CFileManagerEngine::DriveRootDirectory( TInt aDrive ) const
       
  1728     {
       
  1729     CGflmDriveItem* drvItem = iNavigator->DriveFromId( aDrive );
       
  1730     if ( drvItem )
       
  1731         {
       
  1732         return drvItem->RootDirectory();
       
  1733         }
       
  1734     return TPtrC( KNullDesC );
       
  1735     }
       
  1736 
       
  1737 // -----------------------------------------------------------------------------
       
  1738 // CFileManagerEngine::BackupSettingsL()
       
  1739 //
       
  1740 // -----------------------------------------------------------------------------
       
  1741 //
       
  1742 EXPORT_C CFileManagerBackupSettings& CFileManagerEngine::BackupSettingsL()
       
  1743     {
       
  1744     if ( !iBackupSettings )
       
  1745         {
       
  1746         INFO_LOG( "CFileManagerEngine::BackupSettingsL()-Create" )
       
  1747         iBackupSettings = CFileManagerBackupSettings::NewL( *this );
       
  1748         }
       
  1749     return *iBackupSettings;
       
  1750     }
       
  1751 
       
  1752 // -----------------------------------------------------------------------------
       
  1753 // CFileManagerEngine::RestoreSettingsL()
       
  1754 //
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //
       
  1757 EXPORT_C CFileManagerRestoreSettings& CFileManagerEngine::RestoreSettingsL()
       
  1758     {
       
  1759     if ( !iRestoreSettings )
       
  1760         {
       
  1761         INFO_LOG( "CFileManagerEngine::RestoreSettingsL()-Create" )
       
  1762         iRestoreSettings = CFileManagerRestoreSettings::NewL( *this );
       
  1763         }
       
  1764     return *iRestoreSettings;
       
  1765     }
       
  1766 
       
  1767 // -----------------------------------------------------------------------------
       
  1768 // CFileManagerEngine::GetRestoreInfoArrayL()
       
  1769 //
       
  1770 // -----------------------------------------------------------------------------
       
  1771 //
       
  1772 EXPORT_C void CFileManagerEngine::GetRestoreInfoArrayL(
       
  1773         RArray< CFileManagerRestoreSettings::TInfo >& aArray,
       
  1774         const TInt aDrive ) const
       
  1775     {
       
  1776     return iRemovableDrvHandler->GetRestoreInfoArrayL( aArray, aDrive );
       
  1777     }
       
  1778 
       
  1779 // -----------------------------------------------------------------------------
       
  1780 // CFileManagerEngine::DriveName()
       
  1781 //
       
  1782 // -----------------------------------------------------------------------------
       
  1783 //
       
  1784 EXPORT_C TPtrC CFileManagerEngine::DriveName( const TInt aDrive )
       
  1785     {
       
  1786     CGflmDriveItem* drvItem = iNavigator->DriveFromId( aDrive );
       
  1787     if ( drvItem )
       
  1788         {
       
  1789 #ifdef RD_MULTIPLE_DRIVE
       
  1790         delete iDriveName;
       
  1791         iDriveName = NULL;
       
  1792 
       
  1793         TRAPD( err, iDriveName = iUtils->GetDriveNameL(
       
  1794             drvItem->Drive(), CFileManagerUtils::ETitleLayout ) );
       
  1795         if ( err == KErrNone )
       
  1796             {
       
  1797             return iDriveName->Des();
       
  1798             }
       
  1799 #else // RD_MULTIPLE_DRIVE
       
  1800         return drvItem->Name();
       
  1801 #endif // RD_MULTIPLE_DRIVE
       
  1802         }
       
  1803     return TPtrC( KNullDesC );
       
  1804     }
       
  1805 
       
  1806 // -----------------------------------------------------------------------------
       
  1807 // CFileManagerEngine::GetDriveInfoL()
       
  1808 //
       
  1809 // -----------------------------------------------------------------------------
       
  1810 //
       
  1811 EXPORT_C void CFileManagerEngine::GetDriveInfoL(
       
  1812             const TInt aDrive, TFileManagerDriveInfo& aInfo ) const
       
  1813     {
       
  1814     aInfo.GetInfoL( *this, aDrive );
       
  1815     }
       
  1816 
       
  1817 // -----------------------------------------------------------------------------
       
  1818 // CFileManagerEngine::CurrentDriveAvailable()
       
  1819 //
       
  1820 // -----------------------------------------------------------------------------
       
  1821 //
       
  1822 TBool CFileManagerEngine::CurrentDriveAvailable()
       
  1823     {
       
  1824     TFileManagerDriveInfo info;
       
  1825     TRAPD( err, GetDriveInfoL( info ) );
       
  1826     if ( err != KErrNone )
       
  1827         {
       
  1828         return EFalse;
       
  1829         }
       
  1830 
       
  1831     TInt ret( ETrue );
       
  1832     if ( info.iState & (
       
  1833             TFileManagerDriveInfo::EDriveCorrupted |
       
  1834             TFileManagerDriveInfo::EDriveLocked ) )
       
  1835         {
       
  1836         ret = EFalse;
       
  1837         }
       
  1838     else if ( !( info.iState & TFileManagerDriveInfo::EDrivePresent ) )
       
  1839         {
       
  1840         ret = EFalse;
       
  1841         }
       
  1842 
       
  1843     if ( ( info.iState & TFileManagerDriveInfo::EDriveRemote ) &&
       
  1844          !( info.iState & TFileManagerDriveInfo::EDriveConnected ) )
       
  1845         {
       
  1846         ret = EFalse;
       
  1847         }
       
  1848     return ret;
       
  1849     }
       
  1850 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // CFileManagerEngine::ClearDriveInfo()
       
  1853 //
       
  1854 // -----------------------------------------------------------------------------
       
  1855 //
       
  1856 void CFileManagerEngine::ClearDriveInfo()
       
  1857     {
       
  1858     iCurrentDriveInfoRefreshed = EFalse;
       
  1859     iNavigator->ClearDriveInfo();
       
  1860     }
       
  1861 
       
  1862 // -----------------------------------------------------------------------------
       
  1863 // CFileManagerEngine::AnyEjectableDrivePresent()
       
  1864 //
       
  1865 // -----------------------------------------------------------------------------
       
  1866 //
       
  1867 EXPORT_C TBool CFileManagerEngine::AnyEjectableDrivePresent() const
       
  1868     {
       
  1869     RArray< TInt > drives;
       
  1870     iUtils->DriveList( drives, KDriveAttRemovable );
       
  1871     TInt ret( EFalse );
       
  1872     TInt count( drives.Count() );
       
  1873     const TInt KPresentBits(
       
  1874         TFileManagerDriveInfo::EDriveEjectable |
       
  1875         TFileManagerDriveInfo::EDrivePresent );
       
  1876     for( TInt i( 0 ); i < count; ++i )
       
  1877         {
       
  1878         TUint32 state( 0 );
       
  1879         if ( DriveState( state, drives[ i ] ) == KErrNone )
       
  1880             {
       
  1881             if ( ( state & KPresentBits ) == KPresentBits )
       
  1882                 {
       
  1883                 ret = ETrue;
       
  1884                 break;
       
  1885                 }
       
  1886             }
       
  1887         }
       
  1888     drives.Close();
       
  1889     return ret;
       
  1890     }
       
  1891 
       
  1892 // -----------------------------------------------------------------------------
       
  1893 // CFileManagerEngine::ForcedRefreshDirectory()
       
  1894 //
       
  1895 // -----------------------------------------------------------------------------
       
  1896 //
       
  1897 EXPORT_C void CFileManagerEngine::ForcedRefreshDirectory()
       
  1898     {
       
  1899     TPtrC ptr( iNavigator->CurrentDirectory() );
       
  1900     if ( ptr.Length() && iUtils->IsRemoteDrive( ptr ) )
       
  1901         {
       
  1902         // Ensure that remote directory is reloaded
       
  1903         iRemoteDrvHandler->RefreshDirectory( ptr );
       
  1904         }
       
  1905     RefreshDirectory();
       
  1906     }
       
  1907 
       
  1908 // -----------------------------------------------------------------------------
       
  1909 // CFileManagerEngine::HasAppRemoteDriveSupport()
       
  1910 //
       
  1911 // -----------------------------------------------------------------------------
       
  1912 //
       
  1913 TBool CFileManagerEngine::HasAppRemoteDriveSupport( TUid aUid )
       
  1914     {
       
  1915     return iRemoteDrvHandler->HasAppRemoteDriveSupport( aUid );
       
  1916     }
       
  1917 
       
  1918 // -----------------------------------------------------------------------------
       
  1919 // CFileManagerEngine::GetFileSizesL()
       
  1920 //
       
  1921 // -----------------------------------------------------------------------------
       
  1922 //
       
  1923 EXPORT_C TInt64 CFileManagerEngine::GetFileSizesL(
       
  1924         const CArrayFixFlat<TInt>& aIndexList )
       
  1925     {
       
  1926     FUNC_LOG
       
  1927 
       
  1928     TBool isCanceled( EFalse );
       
  1929     TInt64 size( 0 );
       
  1930     TInt count( aIndexList.Count() );
       
  1931 
       
  1932     for( TInt i( 0 ); i < count; ++i )
       
  1933         {
       
  1934         CGflmGroupItem* item = iNavigator->Item( aIndexList.At( i ) );
       
  1935         switch ( item->Type() )
       
  1936             {
       
  1937             case CGflmGroupItem::EFile:
       
  1938                 {
       
  1939                 CGflmFileSystemItem* fsItem =
       
  1940                     static_cast< CGflmFileSystemItem* >( item );
       
  1941                 size += static_cast<TUint>(fsItem->Entry().iSize);
       
  1942                 break;
       
  1943                 }
       
  1944             case CGflmGroupItem::EDirectory:
       
  1945                 {                        
       
  1946                 CGflmFileSystemItem* fsItem =
       
  1947                     static_cast< CGflmFileSystemItem* >( item );
       
  1948                 HBufC* fullPath = fsItem->FullPathLC();
       
  1949 
       
  1950                 delete iActiveSize;
       
  1951                 iActiveSize = NULL;
       
  1952 
       
  1953                 iActiveSize = CFileManagerActiveSize::NewL(
       
  1954                     iFs, *fullPath );
       
  1955 
       
  1956                 ShowWaitDialogL( *iActiveSize );
       
  1957 
       
  1958                 TInt64 folderSize( iActiveSize->GetFolderSize() );
       
  1959                 if ( folderSize == KErrNotFound )
       
  1960                     {
       
  1961                     // Calculation was canceled by the user
       
  1962                     isCanceled = ETrue;
       
  1963                     }
       
  1964                 else
       
  1965                     {
       
  1966                     size += folderSize;
       
  1967                     }
       
  1968 
       
  1969                 CleanupStack::PopAndDestroy( fullPath );
       
  1970                 break;
       
  1971                 }
       
  1972             default:
       
  1973                 {
       
  1974                 break;
       
  1975                 }
       
  1976             }
       
  1977 
       
  1978         if ( isCanceled )
       
  1979             {
       
  1980             break;
       
  1981             }
       
  1982         }
       
  1983 
       
  1984     if ( isCanceled )
       
  1985         {
       
  1986         return KErrNotFound;
       
  1987         }
       
  1988     return size;
       
  1989     }
       
  1990 
       
  1991 // -----------------------------------------------------------------------------
       
  1992 // CFileManagerEngine::CancelTransfer()
       
  1993 //
       
  1994 // -----------------------------------------------------------------------------
       
  1995 //
       
  1996 void CFileManagerEngine::CancelTransfer( const TDesC& aFullPath )
       
  1997     {
       
  1998     if ( iUtils->IsRemoteDrive( aFullPath ) )
       
  1999         {
       
  2000         iRemoteDrvHandler->CancelTransfer( aFullPath );
       
  2001         }
       
  2002     }
       
  2003 
       
  2004 // -----------------------------------------------------------------------------
       
  2005 // CFileManagerEngine::NavigationLevel
       
  2006 // -----------------------------------------------------------------------------
       
  2007 //
       
  2008 EXPORT_C TInt CFileManagerEngine::NavigationLevel() const
       
  2009     {
       
  2010     return iNavigator->NavigationLevel();
       
  2011     }
       
  2012 
       
  2013 #ifdef RD_MULTIPLE_DRIVE
       
  2014 // -----------------------------------------------------------------------------
       
  2015 // CFileManagerEngine::GetFormattedDriveNameLC
       
  2016 // -----------------------------------------------------------------------------
       
  2017 //
       
  2018 EXPORT_C HBufC* CFileManagerEngine::GetFormattedDriveNameLC(
       
  2019         const TInt aDrive,
       
  2020         const TInt aTextIdForDefaultName,
       
  2021         const TInt aTextIdForName ) const
       
  2022     {
       
  2023     return iUtils->GetFormattedDriveNameLC(
       
  2024         aDrive, aTextIdForDefaultName, aTextIdForName );
       
  2025     }
       
  2026 #else // RD_MULTIPLE_DRIVE
       
  2027 EXPORT_C HBufC* CFileManagerEngine::GetFormattedDriveNameLC(
       
  2028         const TInt /*aDrive*/,
       
  2029         const TInt /*aTextIdForDefaultName*/,
       
  2030         const TInt /*aTextIdForName*/  ) const
       
  2031     {
       
  2032     User::Leave( KErrNotSupported );
       
  2033     return NULL;
       
  2034     }
       
  2035 #endif // RD_MULTIPLE_DRIVE
       
  2036 
       
  2037 // -----------------------------------------------------------------------------
       
  2038 // CFileManagerEngine::GetItemInfoLC
       
  2039 // -----------------------------------------------------------------------------
       
  2040 //
       
  2041 EXPORT_C CFileManagerItemProperties* CFileManagerEngine::GetItemInfoLC(
       
  2042         const TInt aIndex )
       
  2043     {
       
  2044     CFileManagerItemProperties* ret = GetItemInfoL( aIndex );
       
  2045     CleanupStack::PushL( ret );
       
  2046     return ret;
       
  2047     }
       
  2048 
       
  2049 // -----------------------------------------------------------------------------
       
  2050 // CFileManagerEngine::SetSearchStringL
       
  2051 // -----------------------------------------------------------------------------
       
  2052 //
       
  2053 EXPORT_C void CFileManagerEngine::SetSearchStringL( const TDesC& aSearchString )
       
  2054     {
       
  2055     delete iSearchString;
       
  2056     iSearchString = NULL;
       
  2057     iSearchString = aSearchString.AllocL();
       
  2058     iNavigator->SetSearchStringL( aSearchString );
       
  2059     }
       
  2060 
       
  2061 // -----------------------------------------------------------------------------
       
  2062 // CFileManagerEngine::SetSearchFolderL
       
  2063 // -----------------------------------------------------------------------------
       
  2064 //
       
  2065 EXPORT_C void CFileManagerEngine::SetSearchFolderL( const TDesC& aSearchFolder )
       
  2066     {
       
  2067     delete iSearchFolder;
       
  2068     iSearchFolder = NULL;
       
  2069     iSearchFolder = aSearchFolder.AllocL();
       
  2070     iNavigator->SetSearchFolderL( aSearchFolder );
       
  2071     }
       
  2072 
       
  2073 // -----------------------------------------------------------------------------
       
  2074 // CFileManagerEngine::SetDirectoryWithBackstepsL
       
  2075 // -----------------------------------------------------------------------------
       
  2076 //
       
  2077 EXPORT_C void CFileManagerEngine::SetDirectoryWithBackstepsL(
       
  2078         const TDesC& aDirectory )
       
  2079     {
       
  2080     CGflmDriveItem* drvItem = iNavigator->DriveFromPath( aDirectory );
       
  2081     if ( !drvItem )
       
  2082         {
       
  2083         return;
       
  2084         }
       
  2085     // Build backsteps
       
  2086     iNavigator->GoToDirectoryL( drvItem->RootDirectory(), aDirectory );
       
  2087 
       
  2088     // Build navigation indices
       
  2089     iNavigationIndices.Reset();
       
  2090     iNavigationIndices.AppendL( KErrNotFound ); // Set initial
       
  2091     TInt count( iNavigator->NavigationLevel() ); // Set backsteps
       
  2092     for( TInt i( 0 ); i < count; ++i )
       
  2093         {
       
  2094         iNavigationIndices.AppendL( KErrNotFound );
       
  2095         }
       
  2096     iNavigationIndices.AppendL( KErrNotFound ); // Set current
       
  2097     }
       
  2098 
       
  2099 // -----------------------------------------------------------------------------
       
  2100 // CFileManagerEngine::SetCurrentIndex
       
  2101 // -----------------------------------------------------------------------------
       
  2102 //
       
  2103 EXPORT_C void CFileManagerEngine::SetCurrentIndex( const TInt aIndex )
       
  2104     {
       
  2105     TInt pos( iNavigationIndices.Count() - 1 );
       
  2106     if ( pos >= 0 )
       
  2107         {
       
  2108         iNavigationIndices[ pos ] = aIndex;
       
  2109         }
       
  2110     }
       
  2111 
       
  2112 // -----------------------------------------------------------------------------
       
  2113 // CFileManagerEngine::SetSortMethod
       
  2114 // -----------------------------------------------------------------------------
       
  2115 //
       
  2116 EXPORT_C void CFileManagerEngine::SetSortMethod( TSortMethod aSortMethod )
       
  2117     {
       
  2118     switch ( aSortMethod )
       
  2119         {
       
  2120         case EByName:          // Fallthrough
       
  2121         case EByType:          // Fallthrough
       
  2122         case EMostRecentFirst: // Fallthrough
       
  2123         case ELargestFirst:    // Fallthrough
       
  2124         case EByMatch:
       
  2125             {
       
  2126             // Make sure that the enums do match
       
  2127             iNavigator->SetSortMethod(
       
  2128                 static_cast< TGflmSortMethod >( aSortMethod ) );
       
  2129             break;
       
  2130             }
       
  2131         default:
       
  2132             {
       
  2133             ERROR_LOG1(
       
  2134                 "CFileManagerEngine::SetSortMethod-InvalidMethod=%d",
       
  2135                 aSortMethod )
       
  2136             break;
       
  2137             }
       
  2138         }
       
  2139     }
       
  2140 
       
  2141 // -----------------------------------------------------------------------------
       
  2142 // CFileManagerEngine::SortMethod
       
  2143 // -----------------------------------------------------------------------------
       
  2144 //
       
  2145 EXPORT_C CFileManagerEngine::TSortMethod CFileManagerEngine::SortMethod() const
       
  2146     {
       
  2147     // Make sure that the enums do match
       
  2148     return static_cast< TSortMethod >( iNavigator->SortMethod() );
       
  2149     }
       
  2150 
       
  2151 // -----------------------------------------------------------------------------
       
  2152 // CFileManagerEngine::RefreshSort
       
  2153 // -----------------------------------------------------------------------------
       
  2154 //
       
  2155 EXPORT_C void CFileManagerEngine::RefreshSort()
       
  2156     {
       
  2157     iRefresher->Refresh( ERefreshSort );
       
  2158     }
       
  2159 
       
  2160 // -----------------------------------------------------------------------------
       
  2161 // CFileManagerEngine::FeatureManager
       
  2162 // -----------------------------------------------------------------------------
       
  2163 //
       
  2164 EXPORT_C CFileManagerFeatureManager& CFileManagerEngine::FeatureManager() const
       
  2165     {
       
  2166     return *iFeatureManager;
       
  2167     }
       
  2168 
       
  2169 // -----------------------------------------------------------------------------
       
  2170 // CFileManagerEngine::SetAppExitOb
       
  2171 // -----------------------------------------------------------------------------
       
  2172 //
       
  2173 EXPORT_C void CFileManagerEngine::SetAppExitOb( MAknServerAppExitObserver* aObserver )
       
  2174     {
       
  2175     iObserver = aObserver;
       
  2176     }
       
  2177 
       
  2178 // -----------------------------------------------------------------------------
       
  2179 // CFileManagerEngine::NoticeServerAppExit
       
  2180 // -----------------------------------------------------------------------------
       
  2181 //
       
  2182 void CFileManagerEngine::NoticeServerAppExit( TInt aReason )
       
  2183     {
       
  2184     if ( iObserver && iSisFile )
       
  2185         {
       
  2186         iUtils->FlushCache();
       
  2187         iObserver->HandleServerAppExit( aReason );
       
  2188         iSisFile = EFalse;
       
  2189         }
       
  2190     }
       
  2191 
       
  2192 // -----------------------------------------------------------------------------
       
  2193 // CFileManagerEngine::SetSisFile
       
  2194 // -----------------------------------------------------------------------------
       
  2195 //
       
  2196 void CFileManagerEngine::SetSisFile( TBool aSisFile )
       
  2197     {
       
  2198     iSisFile = aSisFile;
       
  2199     }
       
  2200 
       
  2201 // ---------------------------------------------------------------------------
       
  2202 // CFileManagerEngine::LatestBackupTimeL()
       
  2203 // ---------------------------------------------------------------------------
       
  2204 //
       
  2205 TInt CFileManagerEngine::LatestBackupTime( TTime& aBackupTime )
       
  2206     {
       
  2207     TRAPD( err, iRemovableDrvHandler->LatestBackupTimeL( aBackupTime ) );
       
  2208     return err;
       
  2209     }
       
  2210 
       
  2211 // ---------------------------------------------------------------------------
       
  2212 // CFileManagerEngine::DeleteBackupsL()
       
  2213 // ---------------------------------------------------------------------------
       
  2214 //
       
  2215 EXPORT_C void CFileManagerEngine::DeleteBackupsL()
       
  2216     {
       
  2217     iRemovableDrvHandler->DeleteBackupsL();
       
  2218     }
       
  2219 
       
  2220 
       
  2221 //  End of File