filemanager/GFLM/src/CGflmDriveResolver.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Resolves different media types' drive letters
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CGflmDriveResolver.h"
       
    22 #include "CGflmDriveItem.h"
       
    23 #include "MGflmItemFilter.h"
       
    24 #include "GflmUtils.h"
       
    25 #include <f32file.h>
       
    26 #ifdef RD_MULTIPLE_DRIVE
       
    27  #include <driveinfo.h>
       
    28 #endif // RD_MULTIPLE_DRIVE
       
    29 
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CGflmDriveResolver::CGflmDriveResolver
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CGflmDriveResolver::CGflmDriveResolver( RFs& aFs ) :
       
    40         iFs( aFs )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CGflmDriveResolver::NewL
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CGflmDriveResolver* CGflmDriveResolver::NewL( RFs& aFs )
       
    50     {
       
    51     CGflmDriveResolver* self = new ( ELeave ) CGflmDriveResolver( aFs );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CGflmDriveResolver::ConstructL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CGflmDriveResolver::ConstructL()
       
    63     {
       
    64     User::LeaveIfError( iCs.CreateLocal() );
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CGflmDriveResolver::~CGflmDriveResolver
       
    69 //
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CGflmDriveResolver::~CGflmDriveResolver()
       
    73     {
       
    74     iDrives.ResetAndDestroy();
       
    75     iDrives.Close();
       
    76     iCs.Close();
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CGflmDriveResolver::RefreshDrives()
       
    81 //
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 TInt CGflmDriveResolver::RefreshDrives( MGflmItemFilter* aFilter )
       
    85     {
       
    86     iCs.Wait();
       
    87 
       
    88     TRAPD( ret, RefreshDrivesL( aFilter ) );
       
    89 
       
    90     LOG_IF_ERROR1(
       
    91         ret, "CGflmDriveResolver::RefreshDrives-ret=%d", ret )
       
    92 
       
    93     iCs.Signal();
       
    94 
       
    95     return ret;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CGflmDriveResolver::RefreshDrivesL()
       
   100 //
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CGflmDriveResolver::RefreshDrivesL( MGflmItemFilter* aFilter )
       
   104     {
       
   105     TIMESTAMP( "GFLM refresh drives started: " )
       
   106 
       
   107     if ( !iRefreshed )
       
   108         {
       
   109         iDrives.ResetAndDestroy();
       
   110         TDriveList drives;
       
   111         User::LeaveIfError( iFs.DriveList( drives, KDriveAttAll ) );
       
   112         TInt count( drives.Length() );
       
   113         for ( TInt i( 0 ); i < count; i++ )
       
   114             {
       
   115             if ( drives[ i ] )
       
   116                 {
       
   117                 AppendDriveL( i, aFilter );
       
   118                 }
       
   119             }
       
   120         iRefreshed = ETrue;
       
   121         }
       
   122 
       
   123     TIMESTAMP( "GFLM refresh drives ended: " )
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CGflmDriveResolver::DriveCount()
       
   128 //
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CGflmDriveResolver::DriveCount() const
       
   132     {
       
   133     return iDrives.Count();
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CGflmDriveResolver::DriveAt()
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 CGflmDriveItem* CGflmDriveResolver::DriveAt( const TInt aIndex ) const
       
   142     {
       
   143     return iDrives[ aIndex ];
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CGflmDriveResolver::DriveFromPath()
       
   148 //
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CGflmDriveItem* CGflmDriveResolver::DriveFromPath( const TDesC& aPath ) const
       
   152     {
       
   153     TInt drv( 0 );
       
   154     if ( aPath.Length() &&
       
   155          RFs::CharToDrive( aPath[ 0 ], drv ) == KErrNone )
       
   156         {
       
   157         return DriveFromId( drv );
       
   158         }
       
   159     return NULL;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CGflmDriveResolver::ClearDrives()
       
   164 //
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CGflmDriveResolver::ClearDrives()
       
   168     {
       
   169     iRefreshed = EFalse;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CGflmDriveResolver::IsRootPath()
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TBool CGflmDriveResolver::IsRootPath( const TDesC& aPath ) const
       
   178     {
       
   179     TInt count( iDrives.Count() );
       
   180     TInt pathLen( aPath.Length() );
       
   181 
       
   182     for ( TInt i( 0 ); i < count; i++ )
       
   183         {
       
   184         CGflmDriveItem* drvItem = iDrives[ i ];
       
   185         TPtrC root( drvItem->RootDirectory() );
       
   186 
       
   187         if ( pathLen == root.Length() && !root.CompareF( aPath ) )
       
   188             {
       
   189             return ETrue;
       
   190             }
       
   191         }
       
   192     return EFalse;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CGflmDriveResolver::AppendDriveL()
       
   197 //
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CGflmDriveResolver::AppendDriveL(
       
   201         const TInt aDrive, MGflmItemFilter* aFilter )
       
   202     {
       
   203     INFO_LOG1( "CGflmDriveResolver::AppendDriveL()-aDrive=%d", aDrive )
       
   204 
       
   205     TVolumeInfo volInfo;
       
   206     TInt err( iFs.Volume( volInfo, aDrive ) );
       
   207 
       
   208     LOG_IF_ERROR1( err, "CGflmDriveResolver::AppendDriveL()-err=%d", err )
       
   209 
       
   210     if ( err != KErrNone )
       
   211         {
       
   212         TInt err2( iFs.Drive( volInfo.iDrive, aDrive ) );
       
   213 
       
   214         LOG_IF_ERROR1( err2, "CGflmDriveResolver::AppendDriveL()-err2=%d", err )
       
   215 
       
   216         if ( err2 != KErrNone )
       
   217             {
       
   218             return;
       
   219             }
       
   220         }
       
   221 
       
   222     TDriveInfo& drvInfo( volInfo.iDrive );
       
   223     if ( drvInfo.iMediaAtt & KMediaAttLocked )
       
   224         {
       
   225         err = KErrLocked;
       
   226         }
       
   227     if ( drvInfo.iType == EMediaNotPresent )
       
   228         {
       
   229         err = KErrNotReady;
       
   230         }
       
   231 
       
   232     TUint drvStatus( 0 );
       
   233 
       
   234 #ifdef RD_MULTIPLE_DRIVE
       
   235     TInt err3( DriveInfo::GetDriveStatus( iFs, aDrive, drvStatus ) );
       
   236     LOG_IF_ERROR1( err3, "CGflmDriveResolver::AppendDriveL()-err3=%d", err3 )
       
   237     if ( err3 != KErrNone )
       
   238         {
       
   239         // Supress error
       
   240         }
       
   241 #endif // RD_MULTIPLE_DRIVE
       
   242 
       
   243     CGflmDriveItem* drvItem = CGflmDriveItem::NewLC(
       
   244         aDrive, volInfo, err, drvStatus );
       
   245 
       
   246     if ( drvInfo.iDriveAtt & KDriveAttRemote )
       
   247         {
       
   248         // Get remote drive name
       
   249         if ( iFs.GetDriveName( aDrive, iReadBuffer ) == KErrNone )
       
   250             {
       
   251             drvItem->SetLocalizedNameL( iReadBuffer );
       
   252             }
       
   253         }
       
   254 
       
   255     TBool allowed( ETrue );
       
   256     if ( aFilter )
       
   257         {
       
   258         allowed = aFilter->FilterItemL( drvItem, 0, NULL );
       
   259         }
       
   260     if ( allowed )
       
   261         {
       
   262         iDrives.AppendL( drvItem );
       
   263         CleanupStack::Pop( drvItem );
       
   264         }
       
   265     else
       
   266         {
       
   267         CleanupStack::PopAndDestroy( drvItem );
       
   268         }
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CGflmDriveResolver::IsRemoteDrive()
       
   273 //
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TBool CGflmDriveResolver::IsRemoteDrive( const TDesC& aPath ) const
       
   277     {
       
   278     CGflmDriveItem* drv = DriveFromPath( aPath );
       
   279     if ( drv )
       
   280         {
       
   281         const TVolumeInfo& vol( drv->VolumeInfo() );
       
   282         if ( vol.iDrive.iDriveAtt & KDriveAttRemote )
       
   283             {
       
   284             return ETrue;
       
   285             }
       
   286         }
       
   287     return EFalse;
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CGflmDriveResolver::DriveFromId()
       
   292 //
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 CGflmDriveItem* CGflmDriveResolver::DriveFromId( const TInt aDrive ) const
       
   296     {
       
   297     TInt count( iDrives.Count() );
       
   298     for ( TInt i( 0 ); i < count; i++ )
       
   299         {
       
   300         CGflmDriveItem* drvItem = iDrives[ i ];
       
   301         if ( aDrive == drvItem->Drive() )
       
   302             {
       
   303             return drvItem;
       
   304             }
       
   305         }
       
   306     return NULL;
       
   307     }
       
   308 
       
   309 //  End of File