filemanager/GFLM/src/CGflmItemGroupImpl.cpp
changeset 0 6a9f87576119
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:  Concrete implementation of MGflmItemGroup interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CGflmItemGroupImpl.h"
       
    22 #include "MGflmItemFilter.h"
       
    23 #include "CGflmItemLocalizer.h"
       
    24 #include "CGflmDriveResolver.h"
       
    25 #include "CGflmFileRecognizer.h"
       
    26 #include "CGflmDirectoryListingCache.h"
       
    27 #include "CGflmGlobalActionItem.h"
       
    28 #include "CGflmFileSystemItem.h"
       
    29 #include "CGflmDriveItem.h"
       
    30 #include "GFLMConsts.h"
       
    31 #include "GFLM.hrh"
       
    32 #include "GflmUtils.h"
       
    33 #include <f32file.h>
       
    34 
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CGflmItemGroupImpl::CGflmItemGroupImpl
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CGflmItemGroupImpl::CGflmItemGroupImpl(
       
    46         const TInt aId,
       
    47         RFs& aFss,
       
    48         CGflmDirectoryListingCache& aCache,
       
    49         CGflmItemLocalizer& aLocalizer,
       
    50         CGflmDriveResolver& aResolver ) :
       
    51     iId( aId ),
       
    52     iFss( aFss ),
       
    53     iListingCache( aCache ),
       
    54     iItemLocalizer( aLocalizer ),
       
    55     iDriveResolver( aResolver )
       
    56     {
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CGflmItemGroupImpl::~CGflmItemGroupImpl
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CGflmItemGroupImpl::~CGflmItemGroupImpl()
       
    65     {
       
    66     iVolatileItems.ResetAndDestroy();
       
    67     iVolatileItems.Close();
       
    68 
       
    69     iStaticItems.ResetAndDestroy();
       
    70     iStaticItems.Close();
       
    71 
       
    72     iItemReferences.Close();
       
    73 
       
    74     delete iDirectory;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CGflmItemGroupImpl::NewLC
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CGflmItemGroupImpl* CGflmItemGroupImpl::NewLC(
       
    83         const TInt aId,
       
    84         RFs& aFss,
       
    85         CGflmDirectoryListingCache& aCache,
       
    86         CGflmItemLocalizer& aLocalizer,
       
    87         CGflmDriveResolver& aResolver )
       
    88     {
       
    89     CGflmItemGroupImpl* self = new( ELeave ) CGflmItemGroupImpl(
       
    90         aId, aFss, aCache, aLocalizer, aResolver );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93     return self;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CGflmItemGroupImpl::ContructL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CGflmItemGroupImpl::ConstructL()
       
   101     {
       
   102     iSortCollationMethod = *Mem::CollationMethodByIndex( 0 );
       
   103     iSortCollationMethod.iFlags |=
       
   104         TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CGflmItemGroupImpl::RefreshL()
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CGflmItemGroupImpl::RefreshL(
       
   113         MGflmItemFilter* aFilter,
       
   114         TGflmSortMethod aSortMethod,
       
   115         TGflmRefreshMode aRefreshMode )
       
   116     {
       
   117     FUNC_LOG
       
   118 
       
   119     INFO_LOG2(
       
   120         "CGflmItemGroupImpl::RefreshL-aRefreshMode=%d, aSortMethod=%d",
       
   121         aRefreshMode, aSortMethod )
       
   122 
       
   123     if ( aRefreshMode == ERefreshItems )
       
   124         {
       
   125         // Reset reference list
       
   126         iItemReferences.Reset();
       
   127 
       
   128         // Destroy old filesystem items
       
   129         iVolatileItems.ResetAndDestroy();
       
   130 
       
   131         // Re-read contents of the assigned directories, filter out unwanted
       
   132         // items and add rest to the item list
       
   133         TIMESTAMP( "GFLM reading and filtering directories started: " )
       
   134         PopulateReferenceListL( aFilter );
       
   135         TIMESTAMP( "GFLM reading and filtering directories ended: " )
       
   136         }
       
   137 
       
   138     if ( aRefreshMode == ERefreshItems || aRefreshMode == ERefreshSort )
       
   139         {
       
   140         if ( !( iInclusion & EDrives ) )
       
   141             {
       
   142             TIMESTAMP( "GFLM group sorting started: " )
       
   143             iItemReferences.Sort( CGflmGroupItem::GetSortL( aSortMethod ) );
       
   144             TIMESTAMP( "GFLM group sorting ended: " )
       
   145             }
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CGflmItemGroupImpl::PopulateReferenceListL()
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CGflmItemGroupImpl::PopulateReferenceListL( MGflmItemFilter* aFilter )
       
   155     {
       
   156     CGflmGroupItem* item = NULL;
       
   157     TInt i( 0 );
       
   158 
       
   159     // Add drive items to the reference list
       
   160     if ( iInclusion & EDrives )
       
   161         {
       
   162         if ( iDirectory )
       
   163             {
       
   164             // Hide drive selection when location inside folder.
       
   165             return;
       
   166             }
       
   167 
       
   168         TInt count( iDriveResolver.DriveCount() );
       
   169         for ( i = 0; i < count; i++ )
       
   170             {
       
   171             // Add directly, items are filtered from drive resolver
       
   172             CGflmDriveItem* drvItem = iDriveResolver.DriveAt( i );
       
   173             iItemReferences.AppendL( drvItem );
       
   174             drvItem->SetGroup( this );
       
   175             }
       
   176         }
       
   177 
       
   178     // Add pointers to the static items (action items) to the
       
   179     // reference list
       
   180     TInt staticCount( iStaticItems.Count() );
       
   181 
       
   182     for ( i = 0; i < staticCount; i++ )
       
   183         {
       
   184         item = iStaticItems[ i ];
       
   185         if ( !aFilter ||
       
   186             ( aFilter && aFilter->FilterItemL( item, iId, NULL ) ) )
       
   187             {
       
   188             iItemReferences.AppendL( item );
       
   189             item->SetGroup( this );
       
   190             }
       
   191         }
       
   192 
       
   193     if ( iInclusion & ( EFiles | EDirectories ) )
       
   194         {
       
   195         if ( iDirectory )
       
   196             {
       
   197             // Check directory name length validity
       
   198             TPtrC directory( iDirectory->Des() );
       
   199             TInt dirLen( directory.Length() );
       
   200             if ( !dirLen || dirLen > KMaxFileName )
       
   201                 {
       
   202                 return;
       
   203                 }
       
   204 
       
   205             // Get the drive where items are located
       
   206             CGflmDriveItem* drvItem = iDriveResolver.DriveFromPath(
       
   207                 directory );
       
   208 
       
   209             const CGflmDirectoryListingCache::CEntryArray* dir =
       
   210                 iListingCache.ListingL( directory );
       
   211             TInt entryCount( dir->Count() );
       
   212 
       
   213             // Reserve room for all entries at once to avoid overhead
       
   214             iVolatileItems.ReserveL( entryCount );
       
   215             iItemReferences.ReserveL( iItemReferences.Count() + entryCount );
       
   216 
       
   217             // Create buffer for filenames
       
   218             HBufC* buffer = HBufC::NewLC( KMaxFileName );
       
   219             TPtr filename( buffer->Des() );
       
   220 
       
   221             TIMESTAMP( "GFLM files and folders list genaration started: " )
       
   222 
       
   223             TInt bsLen( KGFLMBackslash().Length() );
       
   224 
       
   225             // For all items in a directory listing
       
   226             for( i = 0; i < entryCount; i++ )
       
   227                 {
       
   228                 const TEntry& entry( ( *dir )[ i ] );
       
   229                 TBool isDir( entry.IsDir() );
       
   230                 TInt extLen( isDir ? bsLen : 0 ); // Handle final backslash
       
   231                 if ( dirLen + entry.iName.Length() + extLen > KMaxFileName )
       
   232                     {
       
   233                     continue; // Too long name
       
   234                     }
       
   235                 if ( isDir && !( iInclusion & EDirectories ) )
       
   236                     {
       
   237                     continue; // No directories allowed
       
   238                     }
       
   239                 if ( !isDir && !( iInclusion & EFiles ) )
       
   240                     {
       
   241                     continue; // No files allowed
       
   242                     }
       
   243 
       
   244                 // Create a new filesystem item
       
   245                 CGflmFileSystemItem* fsItem = CGflmFileSystemItem::NewLC(
       
   246                     entry, directory );
       
   247 
       
   248                 // Filter out unwanted items
       
   249                 if ( !aFilter ||
       
   250                     ( aFilter && aFilter->FilterItemL( fsItem, iId, drvItem ) ) )
       
   251                     {
       
   252                     // Only directory items can be localized
       
   253                     if ( isDir )
       
   254                         {
       
   255                         // Get localized name for the item, if it has one
       
   256                         GflmUtils::GetFullPath( directory, entry, filename );
       
   257                         TPtrC localizedName(
       
   258                             iItemLocalizer.LocalizeFromWorkThread( filename ) );
       
   259                         if ( localizedName.Length() )
       
   260                             {
       
   261                             fsItem->SetLocalizedNameL( localizedName );
       
   262                             }
       
   263                         }
       
   264                     iVolatileItems.AppendL( fsItem );
       
   265                     CleanupStack::Pop( fsItem );
       
   266                     iItemReferences.AppendL( fsItem );
       
   267                     fsItem->SetGroup( this );
       
   268                     }
       
   269                 else
       
   270                     {
       
   271                     CleanupStack::PopAndDestroy( fsItem );
       
   272                     }
       
   273                 }
       
   274 
       
   275             CleanupStack::PopAndDestroy( buffer );
       
   276 
       
   277             TIMESTAMP( "GFLM files and folders list genaration ended: " )
       
   278 
       
   279             }
       
   280         }
       
   281 
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CGflmItemGroupImpl::ItemCount()
       
   286 // (other items were commented in a header).
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TInt CGflmItemGroupImpl::ItemCount() const
       
   290     {
       
   291     return iItemReferences.Count();
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CGflmItemGroupImpl::Item()
       
   296 // (other items were commented in a header).
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 CGflmGroupItem* CGflmItemGroupImpl::Item( TInt aIndex )
       
   300     {
       
   301     return iItemReferences[ aIndex ];
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CGflmItemGroupImpl::Id()
       
   306 // (other items were commented in a header).
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 TInt CGflmItemGroupImpl::Id() const
       
   310     {
       
   311     return iId;
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CGflmItemGroupImpl::SetInclusion()
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CGflmItemGroupImpl::SetInclusion( TUint aInclusion )
       
   320     {
       
   321     iInclusion = aInclusion;
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // CGflmItemGroupImpl::AddSourceL()
       
   326 // (other items were commented in a header).
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 void CGflmItemGroupImpl::AddSourceL( const TDesC& aDirectory )
       
   330     {
       
   331     HBufC* temp = aDirectory.AllocL();
       
   332     delete iDirectory;
       
   333     iDirectory = temp;
       
   334     // Reset reference list to cleanup all references to deleted directory
       
   335     iItemReferences.Reset();
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CGflmItemGroupImpl::ResetSources()
       
   340 // (other items were commented in a header).
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CGflmItemGroupImpl::ResetSources()
       
   344     {
       
   345     delete iDirectory;
       
   346     iDirectory = NULL;
       
   347     // Reset reference list to cleanup all references to deleted directory
       
   348     iItemReferences.Reset();
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CGflmItemGroupImpl::AddActionItemL
       
   353 // (other items were commented in a header).
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CGflmItemGroupImpl::AddActionItemL( TInt aId, const TDesC& aCaption )
       
   357     {
       
   358     CGflmGlobalActionItem* actionItem =
       
   359         CGflmGlobalActionItem::NewLC( aId, aCaption );
       
   360     iStaticItems.AppendL( actionItem );
       
   361     CleanupStack::Pop( actionItem );
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CGflmItemGroupImpl::CollationMethod
       
   366 // (other items were commented in a header).
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 const TCollationMethod* CGflmItemGroupImpl::CollationMethod()
       
   370     {
       
   371     return &iSortCollationMethod;
       
   372     }
       
   373 
       
   374 //  End of File