filemanager/Engine/src/CFileManagerItemFilter.cpp
changeset 0 6a9f87576119
child 14 efe289f793e7
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Filter GFLM items
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CFileManagerItemFilter.h"
       
    22 #include "CFileManagerEngine.h"
       
    23 #include "CGflmGroupItem.h"
       
    24 #include "CGflmFileSystemItem.h"
       
    25 #include "CGflmDriveItem.h"
       
    26 #include "CGflmGlobalActionItem.h"
       
    27 #include "CFileManagerCommonDefinitions.h"
       
    28 #include "FileManagerDebug.h"
       
    29 #include "TFileManagerDriveInfo.h"
       
    30 #include "CFileManagerFeatureManager.h"
       
    31 #include <FileManagerEngine.rsg>
       
    32 #include <StringLoader.h>
       
    33 #include <pathinfo.h>
       
    34 #ifdef RD_MULTIPLE_DRIVE
       
    35 #include <driveinfo.h>
       
    36 #endif // RD_MULTIPLE_DRIVE
       
    37 
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CFileManagerItemFilter::CFileManagerItemFilter
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CFileManagerItemFilter::CFileManagerItemFilter( CFileManagerEngine& aEngine )
       
    46     : iEngine( aEngine )
       
    47     {
       
    48     }
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // CFileManagerItemFilter::ConstructL
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 void CFileManagerItemFilter::ConstructL()
       
    55     {
       
    56     // Phone memory root path
       
    57     iPhoneMemoryRootPath = PathInfo::PhoneMemoryRootPath().AllocL();
       
    58     iInternalDefaultName =
       
    59         StringLoader::LoadL( R_TEXT_PHONE_MEMORY );
       
    60     iRemovableDefaultName =
       
    61         StringLoader::LoadL( R_TEXT_MEMORY_CARD_DEFAULT );
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // CFileManagerItemFilter::NewL
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 CFileManagerItemFilter* CFileManagerItemFilter::NewL(
       
    69         CFileManagerEngine& aEngine )
       
    70     {
       
    71     CFileManagerItemFilter* self = new( ELeave ) CFileManagerItemFilter(
       
    72         aEngine );
       
    73 
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop( self );
       
    77 
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------------------------
       
    82 // CFileManagerItemFilter::~CFileManagerItemFilter
       
    83 // ----------------------------------------------------------------------------
       
    84 // 
       
    85 CFileManagerItemFilter::~CFileManagerItemFilter()
       
    86     {
       
    87     delete iPhoneMemoryRootPath;
       
    88     delete iInternalDefaultName;
       
    89     delete iRemovableDefaultName;
       
    90     }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CFileManagerItemFilter::FilterItemL
       
    94 // ----------------------------------------------------------------------------
       
    95 // 
       
    96 TBool CFileManagerItemFilter::FilterItemL(
       
    97         CGflmGroupItem* aItem,
       
    98         TInt /*aGroupId*/,
       
    99         CGflmDriveItem* /*aDrive*/ )
       
   100     {
       
   101     switch( aItem->Type() )
       
   102         {
       
   103         case CGflmGroupItem::EGlobalActionItem:
       
   104 			{
       
   105             CGflmGlobalActionItem* actItem =
       
   106                 static_cast< CGflmGlobalActionItem* >( aItem );
       
   107             switch( actItem->Id() )
       
   108                 {
       
   109                 case EFileManagerBackupAction:
       
   110                     {
       
   111                     // Disable backup in embedded mode, because it messes up 
       
   112                     // backup and restore operations since embedded apps are closed.
       
   113                     if ( iEngine.FeatureManager().IsEmbedded() )
       
   114                         {
       
   115                         return EFalse;
       
   116                         }
       
   117                     actItem->SetIconId( EFileManagerBackupMainIcon );
       
   118                     break;
       
   119                     }
       
   120                 default:
       
   121                     {
       
   122                     break;
       
   123                     }
       
   124                 }
       
   125             break;
       
   126 			}
       
   127         case CGflmGroupItem::EDirectory:
       
   128             {
       
   129             CGflmFileSystemItem* fsItem =
       
   130                 static_cast< CGflmFileSystemItem* >( aItem );
       
   131             fsItem->GetFullPath( iFileNameBuffer );
       
   132             return !iEngine.IsSystemFolder( iFileNameBuffer );
       
   133 			}
       
   134         case CGflmGroupItem::EDrive:
       
   135             {
       
   136             CGflmDriveItem* drvItem = static_cast< CGflmDriveItem* >( aItem );
       
   137 
       
   138 #ifndef RD_MULTIPLE_DRIVE
       
   139             const TVolumeInfo& vol( drvItem->VolumeInfo() );
       
   140             TInt drive( drvItem->Drive() );
       
   141 #endif // RD_MULTIPLE_DRIVE
       
   142 
       
   143             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-drive=%d",
       
   144                 drvItem->Drive() )
       
   145 
       
   146             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-driveAtt=%d",
       
   147                 drvItem->VolumeInfo().iDrive.iDriveAtt )
       
   148 
       
   149             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-mediaAtt=%d",
       
   150                 drvItem->VolumeInfo().iDrive.iMediaAtt )
       
   151 
       
   152             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-driveUniqueId=%u",
       
   153                 drvItem->VolumeInfo().iUniqueID )
       
   154 
       
   155             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-driveSize=%lu",
       
   156                 drvItem->VolumeInfo().iSize )
       
   157 
       
   158             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-VolumeStatus=%d",
       
   159                 drvItem->VolumeStatus() )
       
   160 
       
   161             INFO_LOG1( "CFileManagerItemFilter::FilterItemL()-DriveStatus=%d",
       
   162                 drvItem->DriveStatus() )
       
   163 
       
   164 #ifdef RD_MULTIPLE_DRIVE
       
   165             // Setup drive icon
       
   166             TUint driveStatus( drvItem->DriveStatus() );
       
   167             if ( !( driveStatus & DriveInfo::EDriveUserVisible ) )
       
   168                 {
       
   169                 ERROR_LOG( "CFileManagerItemFilter::FilterItemL()-Hidden-1" )
       
   170                 return EFalse;
       
   171                 }
       
   172             TInt icon( 0 );
       
   173             if ( driveStatus & DriveInfo::EDriveInternal )
       
   174                 {
       
   175                 icon = EFileManagerPhoneMemoryMainIcon;
       
   176                 if ( driveStatus & DriveInfo::EDriveExternallyMountable )
       
   177                     {
       
   178                     icon = EFileManagerMassStorageMainIcon;
       
   179                     }
       
   180                 }
       
   181             else if ( driveStatus & DriveInfo::EDriveUsbMemory )
       
   182                 {
       
   183                 if ( !( driveStatus & DriveInfo::EDrivePresent ) )
       
   184                     {
       
   185                     ERROR_LOG( "CFileManagerItemFilter::FilterItemL()-NotPresentUsbMemory" )
       
   186                     return EFalse; // Not present USB drive is not shown
       
   187                     }
       
   188                 icon = EFileManagerUsbMemoryMainIcon;
       
   189                 }
       
   190             else if ( driveStatus & DriveInfo::EDriveRemovable )
       
   191                 {
       
   192                 icon = EFileManagerMemoryCardNotPresentMainIcon;
       
   193                 if ( driveStatus & DriveInfo::EDrivePresent )
       
   194                     {
       
   195                     icon = EFileManagerMemoryCardPresentMainIcon;
       
   196                     }
       
   197                 }
       
   198             else if ( driveStatus & DriveInfo::EDriveRemote )
       
   199                 {
       
   200                 icon = EFileManagerRemoteDriveMainIcon;
       
   201                 }
       
   202             else
       
   203                 {
       
   204                 ERROR_LOG( "CFileManagerItemFilter::FilterItemL()-Hidden-2" )
       
   205                 return EFalse;
       
   206                 }
       
   207             drvItem->SetIconId( icon );
       
   208             // Setup root directory
       
   209             if ( PathInfo::GetRootPath( iFileNameBuffer, drvItem->Drive() ) != KErrNone )
       
   210                 {
       
   211                 ERROR_LOG( "CFileManagerItemFilter::FilterItemL()-Hidden-3" )
       
   212                 return EFalse;
       
   213                 }
       
   214             drvItem->SetRootDirectoryL( iFileNameBuffer );
       
   215             INFO_LOG( "CFileManagerItemFilter::FilterItemL()-Visible" )
       
   216 
       
   217 #else // RD_MULTIPLE_DRIVE
       
   218 
       
   219             TBool isPhoneMem( EFalse );
       
   220             TPtrC root( drvItem->RootDirectory() );
       
   221             TPtrC phoneMemRoot( *iPhoneMemoryRootPath );
       
   222             TInt len( Min( root.Length(), phoneMemRoot.Length() ) );
       
   223             if ( !root.CompareF( phoneMemRoot.Left( len ) ) )
       
   224                 {
       
   225                 // Drive is defined to phone memory
       
   226                 isPhoneMem = ETrue;
       
   227                 drvItem->SetRootDirectoryL( *iPhoneMemoryRootPath );
       
   228                 }
       
   229             else if ( vol.iDrive.iDriveAtt & KDriveAttInternal )
       
   230                 {
       
   231                 if ( drive == KFmgrRamDrive || drive == KFmgrRomDrive )
       
   232                     {
       
   233                     // Drive is not allowed internal drive
       
   234                     return EFalse;
       
   235                     }
       
   236                 }
       
   237             if ( vol.iDrive.iDriveAtt & KDriveAttSubsted )
       
   238                 {
       
   239                 // Substed drives are not allowed
       
   240                 return EFalse;
       
   241                 }
       
   242             // Setup drive name
       
   243             if ( !drvItem->Name().Length() )
       
   244                 {
       
   245                 if ( isPhoneMem )
       
   246                     {
       
   247                     drvItem->SetLocalizedNameL( *iInternalDefaultName );
       
   248                     }
       
   249                 else if ( ( vol.iDrive.iDriveAtt & KDriveAttRemovable ) ||
       
   250                         drive == KFmgrMemoryCardDrive )
       
   251                     {
       
   252                     drvItem->SetLocalizedNameL( *iRemovableDefaultName );
       
   253                     }
       
   254                 else
       
   255                     {
       
   256                     drvItem->SetLocalizedNameL( drvItem->RootDirectory() );
       
   257                     }
       
   258                 }
       
   259             // Setup drive icon
       
   260             if ( isPhoneMem )
       
   261                 {
       
   262                 drvItem->SetIconId( EFileManagerPhoneMemoryMainIcon );
       
   263                 }
       
   264             else if ( ( vol.iDrive.iDriveAtt & KDriveAttRemovable ) ||
       
   265                 drive == KFmgrMemoryCardDrive )
       
   266                 {
       
   267                 if ( vol.iDrive.iType == EMediaNotPresent )
       
   268                     {
       
   269                     drvItem->SetIconId( EFileManagerMemoryCardNotPresentMainIcon );
       
   270                     }
       
   271                 else
       
   272                     {
       
   273                     drvItem->SetIconId( EFileManagerMemoryCardPresentMainIcon );
       
   274                     }
       
   275                 }
       
   276             else if ( vol.iDrive.iDriveAtt & KDriveAttRemote )
       
   277                 {
       
   278                 drvItem->SetIconId( EFileManagerRemoteDriveMainIcon );
       
   279                 }
       
   280             else
       
   281                 {
       
   282                 return EFalse;
       
   283                 }
       
   284             INFO_LOG( "CFileManagerItemFilter::FilterItemL()-driveAllowed" )
       
   285 
       
   286 #endif // RD_MULTIPLE_DRIVE
       
   287             break;
       
   288             }
       
   289         default:
       
   290             {
       
   291             break;
       
   292             }
       
   293         }
       
   294     return ETrue;
       
   295     }
       
   296 
       
   297 //  End of File