filemanager/Engine/src/CFileManagerItemProperties.cpp
changeset 0 6a9f87576119
child 17 529f3bf5c2f1
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     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:  Holds item information
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <e32base.h>
       
    21 #include <f32file.h>
       
    22 #include <tz.h>
       
    23 #include "CFileManagerItemProperties.h"
       
    24 #include "CFileManagerUtils.h"
       
    25 #include "CFilemanagerMimeIconArray.h"
       
    26 #include "Cfilemanagerfolderarray.h"
       
    27 #include "Cfilemanageractivesize.h"
       
    28 #include "CFilemanagerActiveCount.h"
       
    29 #include "CFileManagerEngine.h" 
       
    30 #include "CGflmGroupItem.h"
       
    31 #include "CGflmFileSystemItem.h"
       
    32 #include "CGflmDriveItem.h"
       
    33 #include "CGflmGlobalActionItem.h"
       
    34 
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 // -----------------------------------------------------------------------------
       
    38 // CFileManagerItemProperties::CFileManagerItemProperties
       
    39 // 
       
    40 // -----------------------------------------------------------------------------
       
    41 // 
       
    42 CFileManagerItemProperties::CFileManagerItemProperties( 
       
    43         CFileManagerUtils& aUtils,
       
    44         CFileManagerEngine& aEngine ) :
       
    45             iSize( KErrNotFound ),
       
    46             iFilesContained( KErrNotFound ),
       
    47             iFoldersContained( KErrNotFound ),
       
    48             iOpenFiles( KErrNotFound ),
       
    49             iUtils( aUtils ),
       
    50             iEngine( aEngine )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFileManagerItemProperties::NewL
       
    56 // 
       
    57 // -----------------------------------------------------------------------------
       
    58 // 
       
    59 CFileManagerItemProperties* CFileManagerItemProperties::NewL( 
       
    60         const TDesC& aFullPath,
       
    61         CFileManagerUtils& aUtils,
       
    62         CFileManagerEngine& aEngine )
       
    63     {
       
    64     CFileManagerItemProperties* self =
       
    65         new (ELeave) CFileManagerItemProperties( aUtils, aEngine );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( aFullPath );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CFileManagerItemProperties::NewL
       
    74 // 
       
    75 // -----------------------------------------------------------------------------
       
    76 // 
       
    77 CFileManagerItemProperties* CFileManagerItemProperties::NewL(
       
    78         const CGflmGroupItem& aItem,
       
    79         CFileManagerUtils& aUtils,
       
    80         CFileManagerEngine& aEngine )
       
    81     {
       
    82     CFileManagerItemProperties* self =
       
    83         new (ELeave) CFileManagerItemProperties( aUtils, aEngine );
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL( aItem );
       
    86     CleanupStack::Pop( self );
       
    87     return self;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CFileManagerItemProperties::ConstructL
       
    92 // 
       
    93 // -----------------------------------------------------------------------------
       
    94 // 
       
    95 void CFileManagerItemProperties::ConstructL( const TDesC& aFullPath )
       
    96     {
       
    97     iFullPath = aFullPath.AllocL();
       
    98 
       
    99     // Setup the rest of entry data when needed first time
       
   100     if ( CFileManagerUtils::HasFinalBackslash( aFullPath ) )
       
   101         {
       
   102         iState |= EItemDirectory;
       
   103         }
       
   104     else
       
   105         {
       
   106         iState |= EItemFile;
       
   107         }
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CFileManagerItemProperties::ConstructL
       
   112 // 
       
   113 // -----------------------------------------------------------------------------
       
   114 // 
       
   115 void CFileManagerItemProperties::ConstructL(
       
   116         const TDesC& aFullPath, const TEntry& aEntry )
       
   117     {
       
   118     iFullPath = aFullPath.AllocL();
       
   119 
       
   120     // Setup all entry data now
       
   121     SetEntryData( aEntry );
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CFileManagerItemProperties::ConstructL
       
   126 // 
       
   127 // -----------------------------------------------------------------------------
       
   128 // 
       
   129 void CFileManagerItemProperties::ConstructL( const CGflmGroupItem& aItem )
       
   130     {
       
   131     switch ( aItem.Type() )
       
   132         {
       
   133         case CGflmGroupItem::EFile:
       
   134         case CGflmGroupItem::EDirectory:
       
   135             {
       
   136             const CGflmFileSystemItem& fsItem =
       
   137                 static_cast< const CGflmFileSystemItem& >( aItem );
       
   138             HBufC* fullPath = fsItem.FullPathLC();
       
   139             ConstructL( *fullPath, fsItem.Entry() );
       
   140             if ( iUtils.IsRemoteDrive( *fullPath ) )
       
   141                 {
       
   142                 iState |= EItemRemoteDrive;
       
   143                 }
       
   144             CleanupStack::PopAndDestroy( fullPath );
       
   145             break;
       
   146             }
       
   147         case CGflmGroupItem::EDrive:
       
   148             {
       
   149             const CGflmDriveItem& drvItem =
       
   150                 static_cast< const CGflmDriveItem& >( aItem );
       
   151             iFullPath = drvItem.RootDirectory().AllocL();
       
   152 #ifdef RD_MULTIPLE_DRIVE
       
   153             iName = iUtils.GetDriveNameL(
       
   154                 drvItem.Drive(),
       
   155                 CFileManagerUtils::EMainLayout );
       
   156 #else // RD_MULTIPLE_DRIVE
       
   157             iName = drvItem.Name().AllocL();
       
   158 #endif // RD_MULTIPLE_DRIVE
       
   159             iState |= EItemDrive;
       
   160             if ( iUtils.IsRemoteDrive( *iFullPath ) )
       
   161                 {
       
   162                 iState |= EItemRemoteDrive;
       
   163                 }
       
   164             break;
       
   165             }
       
   166         case CGflmGroupItem::EGlobalActionItem:
       
   167             {
       
   168             const CGflmGlobalActionItem& actItem = 
       
   169                 static_cast< const CGflmGlobalActionItem& >( aItem );
       
   170             if ( actItem.Id() == EFileManagerBackupAction )
       
   171                 {
       
   172                 // Ignore error
       
   173                 iEngine.LatestBackupTime( iModified );
       
   174                 }
       
   175             iName = aItem.Name().AllocL();
       
   176             // Action items do not have entry data, so mark it as fetched
       
   177             iState |= EItemAction | EItemEntryDataFetched;
       
   178             break;
       
   179             }
       
   180         default:
       
   181             {
       
   182             User::Leave( KErrNotFound );
       
   183             break;
       
   184             }
       
   185         }
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CFileManagerItemProperties::~CFileManagerItemProperties
       
   190 // 
       
   191 // -----------------------------------------------------------------------------
       
   192 // 
       
   193 CFileManagerItemProperties::~CFileManagerItemProperties()
       
   194     {
       
   195     delete iFullPath;
       
   196     delete iActiveSize;
       
   197     delete iActiveCount;
       
   198     delete iName;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CFileManagerItemProperties::Name() const
       
   203 //
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C TPtrC CFileManagerItemProperties::Name() const
       
   207     {
       
   208     if ( iState & EItemNotFileOrDir )
       
   209         {
       
   210         return iName->Des();
       
   211         }
       
   212     TParsePtrC parse( CFileManagerUtils::StripFinalBackslash( *iFullPath ) );
       
   213     return parse.Name();
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CFileManagerItemProperties::ModifiedDate() const
       
   218 //
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C TTime CFileManagerItemProperties::ModifiedDate() const
       
   222     {
       
   223     EnsureEntryDataFetched();
       
   224     return iModified;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CFileManagerItemProperties::SizeL()
       
   229 //
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 EXPORT_C TInt64 CFileManagerItemProperties::SizeL()
       
   233     {
       
   234     if ( iState & EItemNotFileOrDir )
       
   235         {
       
   236         return 0;
       
   237         }
       
   238     if( iSize == KErrNotFound )
       
   239         {
       
   240         if ( iState & EItemFile )
       
   241             {
       
   242             EnsureEntryDataFetched();
       
   243             }
       
   244         else
       
   245             {
       
   246             iSize = FolderSizeL( *iFullPath );
       
   247             }
       
   248         }
       
   249     return iSize;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CFileManagerItemProperties::FilesContainedL()
       
   254 //
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 EXPORT_C TInt CFileManagerItemProperties::FilesContainedL()
       
   258     {
       
   259     if( iFilesContained == KErrNotFound )
       
   260         {
       
   261         CountItemsL( CFileManagerItemProperties::EFile );
       
   262         }
       
   263     return iFilesContained;
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CFileManagerItemProperties::FoldersContainedL()
       
   268 //
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C TInt CFileManagerItemProperties::FoldersContainedL()
       
   272     {
       
   273     if( iFoldersContained == KErrNotFound )
       
   274         {
       
   275         CountItemsL( CFileManagerItemProperties::EFolder );
       
   276         }
       
   277     return iFoldersContained;
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CFileManagerItemProperties::OpenFilesL()
       
   282 //
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 EXPORT_C TInt CFileManagerItemProperties::OpenFilesL()
       
   286     {
       
   287     if( iOpenFiles == KErrNotFound )
       
   288         {
       
   289         CountItemsL( CFileManagerItemProperties::EOpen );
       
   290         }
       
   291     return iOpenFiles;
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CFileManagerItemProperties::TypeL()
       
   296 //
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 EXPORT_C TUint32 CFileManagerItemProperties::TypeL()
       
   300     {
       
   301     if( iType == CFileManagerItemProperties::ENotDefined )
       
   302         {
       
   303         iType = iUtils.FileTypeL( *iFullPath );
       
   304         }
       
   305     return iType;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CFileManagerItemProperties::Ext() const
       
   310 //
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 EXPORT_C TPtrC CFileManagerItemProperties::Ext() const
       
   314     {
       
   315     if ( iState & EItemNotFileOrDir )
       
   316         {
       
   317         return TPtrC( KNullDesC );
       
   318         }
       
   319     TParsePtrC parse( *iFullPath );
       
   320     TPtrC ext( parse.Ext() );
       
   321     return ext;
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // CFileManagerItemProperties::CountItemsL
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 TInt CFileManagerItemProperties::CountItemsL(
       
   329         const TFileManagerFileType& aType )
       
   330     {
       
   331     if ( !( iState & ( EItemDirectory | EItemDrive ) ) )
       
   332         {
       
   333         // It's not a folder
       
   334         return KErrNotFound;
       
   335         }
       
   336 
       
   337     delete iActiveCount;
       
   338     iActiveCount = NULL;
       
   339 
       
   340     iActiveCount = CFileManagerActiveCount::NewL(
       
   341         iEngine.Fs(), *iFullPath, aType );
       
   342 
       
   343     if ( !iActiveCount->IsProcessDone() )
       
   344         {
       
   345         iEngine.ShowWaitDialogL( *iActiveCount );
       
   346         }
       
   347 
       
   348     if ( iFilesContained == KErrNotFound )
       
   349         {
       
   350         iFilesContained = iActiveCount->FileCount();
       
   351         }
       
   352 
       
   353     if ( iFoldersContained == KErrNotFound )
       
   354         {
       
   355         iFoldersContained = iActiveCount->FolderCount();
       
   356         }
       
   357 
       
   358     if ( iOpenFiles == KErrNotFound )
       
   359         {
       
   360         iOpenFiles = iActiveCount->OpenFiles();
       
   361         }
       
   362 
       
   363     return KErrNone;
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CFileManagerItemProperties::FolderSizeL
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 TInt64 CFileManagerItemProperties::FolderSizeL( const TDesC& aFullPath )
       
   371     {
       
   372     if ( !( iState & EItemDirectory ) )
       
   373         {
       
   374         // It's not a folder
       
   375         return KErrNotFound;
       
   376         }
       
   377 
       
   378     delete iActiveSize;
       
   379     iActiveSize = NULL;
       
   380     iActiveSize = CFileManagerActiveSize::NewL( iEngine.Fs(), aFullPath );
       
   381     iEngine.ShowWaitDialogL( *iActiveSize );
       
   382     return iActiveSize->GetFolderSize();
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CFileManagerItemProperties::FullPath() const
       
   387 //
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 EXPORT_C TPtrC CFileManagerItemProperties::FullPath() const
       
   391     {
       
   392     if ( iFullPath )
       
   393         {
       
   394         return iFullPath->Des();
       
   395         }
       
   396     return TPtrC( KNullDesC );
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CFileManagerItemProperties::NameAndExt() const
       
   401 //
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 EXPORT_C TPtrC CFileManagerItemProperties::NameAndExt() const
       
   405     {
       
   406     if ( iState & EItemNotFileOrDir )
       
   407         {
       
   408         return iName->Des();
       
   409         }
       
   410     TParsePtrC parse( CFileManagerUtils::StripFinalBackslash( *iFullPath ) );
       
   411     return parse.NameAndExt();
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CFileManagerItemProperties::LocalizedName() const
       
   416 //
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C TPtrC CFileManagerItemProperties::LocalizedName() const
       
   420     {
       
   421     if (iState & EItemDirectory )
       
   422         {
       
   423         TPtrC ptr( iUtils.LocalizedName( *iFullPath ) );
       
   424         if ( ptr.Length() )
       
   425             {
       
   426             return ptr;
       
   427             }
       
   428         }
       
   429     return NameAndExt();
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CFileManagerItemProperties::ModifiedLocalDate() const
       
   434 //
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C TInt CFileManagerItemProperties::ModifiedLocalDate(
       
   438         TTime& aTime ) const
       
   439     {
       
   440     aTime = ModifiedDate(); // convert from universal time
       
   441     RTz tz;
       
   442     TInt err( tz.Connect() );
       
   443     if ( err == KErrNone )
       
   444         {
       
   445         err = tz.ConvertToLocalTime( aTime );
       
   446         if ( err != KErrNone )
       
   447             {
       
   448             aTime = ModifiedDate(); // use universal time
       
   449             }
       
   450         tz.Close();
       
   451         }
       
   452     return err;
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CFileManagerItemProperties::ContainsAnyFilesOrFolders()
       
   457 //
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 EXPORT_C TInt CFileManagerItemProperties::ContainsAnyFilesOrFolders()
       
   461     {
       
   462     if ( !( iState & EItemDirectory ) ||
       
   463          ( iState & EItemHasNoFilesOrFolders ) )
       
   464         {
       
   465         return EFalse;
       
   466         }
       
   467     if ( iState & EItemHasFilesOrFolders )
       
   468         {
       
   469         return ETrue;
       
   470         }
       
   471     TBool ret( CFileManagerUtils::HasAny(
       
   472         iEngine.Fs(),
       
   473         *iFullPath,
       
   474         KEntryAttNormal | KEntryAttDir | KEntryAttHidden | KEntryAttSystem ) );
       
   475     if ( ret )
       
   476         {
       
   477         iState |= EItemHasFilesOrFolders;
       
   478         }
       
   479     else
       
   480         {
       
   481         iState |= EItemHasNoFilesOrFolders;
       
   482         }
       
   483     return ret;
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CFileManagerItemProperties::MimeTypeL()
       
   488 //
       
   489 // -----------------------------------------------------------------------------
       
   490 // 
       
   491 EXPORT_C TPtrC CFileManagerItemProperties::MimeTypeL()
       
   492     {
       
   493     if ( iState & EItemNotFileOrDir )
       
   494         {
       
   495         return TPtrC( KNullDesC );
       
   496         }
       
   497     return iUtils.MimeTypeL( *iFullPath );
       
   498     }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CFileManagerItemProperties::IsDrive()
       
   502 //
       
   503 // -----------------------------------------------------------------------------
       
   504 // 
       
   505 EXPORT_C TBool CFileManagerItemProperties::IsDrive() const
       
   506     {
       
   507     if ( iState & EItemDrive )
       
   508         {
       
   509         return ETrue;
       
   510         }
       
   511     return EFalse;
       
   512     }
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CFileManagerItemProperties::DriveName()
       
   516 //
       
   517 // -----------------------------------------------------------------------------
       
   518 // 
       
   519 EXPORT_C TPtrC CFileManagerItemProperties::DriveName() const
       
   520     {
       
   521     if ( iState & EItemDrive )
       
   522         {
       
   523         return Name();
       
   524         }
       
   525     return iEngine.CurrentDriveName();
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CFileManagerItemProperties::IsRemoteDrive()
       
   530 //
       
   531 // -----------------------------------------------------------------------------
       
   532 // 
       
   533 EXPORT_C TBool CFileManagerItemProperties::IsRemoteDrive() const
       
   534     {
       
   535     if ( iState & EItemRemoteDrive )
       
   536         {
       
   537         return ETrue;
       
   538         }
       
   539     return EFalse;
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CFileManagerItemProperties::EnsureEntryDataFetched
       
   544 // 
       
   545 // -----------------------------------------------------------------------------
       
   546 // 
       
   547 void CFileManagerItemProperties::EnsureEntryDataFetched() const
       
   548     {
       
   549     if ( iState & EItemEntryDataFetched )
       
   550         {
       
   551         return;
       
   552         }
       
   553 
       
   554     iState |= EItemEntryDataFetched; // Do not try fetch more than once
       
   555 
       
   556     TEntry entry;
       
   557     if ( iEngine.Fs().Entry( *iFullPath, entry ) != KErrNone )
       
   558         {
       
   559         return;
       
   560         }
       
   561 
       
   562     SetEntryData( entry );
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 // CFileManagerItemProperties::SetEntryData
       
   567 // 
       
   568 // -----------------------------------------------------------------------------
       
   569 // 
       
   570 void CFileManagerItemProperties::SetEntryData( const TEntry& aEntry ) const
       
   571     {
       
   572     iState |= EItemEntryDataFetched;
       
   573 
       
   574     iModified = aEntry.iModified;
       
   575 
       
   576     if ( aEntry.IsDir() )
       
   577         {
       
   578         iState |= EItemDirectory;
       
   579         }
       
   580     else
       
   581         {
       
   582         iState |= EItemFile;
       
   583         iSize = (TUint) aEntry.iSize;
       
   584         }
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CFileManagerItemProperties::DriveId
       
   589 // 
       
   590 // -----------------------------------------------------------------------------
       
   591 // 
       
   592 EXPORT_C TInt CFileManagerItemProperties::DriveId() const
       
   593     {
       
   594     TInt ret( KErrNotFound );
       
   595     if ( iFullPath )
       
   596         {
       
   597         ret = TDriveUnit( *iFullPath );
       
   598         }
       
   599     return ret;
       
   600     }
       
   601 
       
   602 // End of File