filemanager/Engine/src/Cfilemanagerfilesystemevent.cpp
branchRCL_3
changeset 39 65326cf895ed
parent 0 6a9f87576119
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
       
     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:  This AO is signaled when directory entry is added or removed 
       
    15 *                from file system
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32std.h>
       
    23 #include "Cfilemanagerfilesystemevent.h"
       
    24 #include "CFileManagerEngine.h"
       
    25 #include "FileManagerDebug.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CFileManagerFileSystemEvent::CFileManagerFileSystemEvent
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 
       
    37 CFileManagerFileSystemEvent::CFileManagerFileSystemEvent(
       
    38         RFs& aFs,
       
    39         CFileManagerEngine& aEngine,
       
    40         TNotifyType aNotifyType ) :
       
    41     CActive( CActive::EPriorityLow ),
       
    42     iFs( aFs ),
       
    43     iEngine( aEngine),
       
    44     iNotifyType( aNotifyType )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CFileManagerFileSystemEvent::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CFileManagerFileSystemEvent::ConstructL( const TDesC& aFullPath )
       
    54     {
       
    55     CActiveScheduler::Add( this );
       
    56 
       
    57     if ( aFullPath.Length() )
       
    58         {
       
    59         iFullPath = aFullPath.AllocL();
       
    60         }
       
    61 
       
    62     Setup();
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CFileManagerFileSystemEvent::NewL
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CFileManagerFileSystemEvent* CFileManagerFileSystemEvent::NewL(
       
    71         RFs& aFs,
       
    72         CFileManagerEngine& aEngine,
       
    73         TNotifyType aNotifyType,
       
    74         const TDesC& aFullPath )
       
    75     {
       
    76     CFileManagerFileSystemEvent* self =
       
    77         new( ELeave ) CFileManagerFileSystemEvent( 
       
    78             aFs,
       
    79             aEngine,
       
    80             aNotifyType );
       
    81 
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL( aFullPath );
       
    84     CleanupStack::Pop( self );
       
    85 
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ------------------------------------------------------------------------------
       
    90 // CFileManagerFileSystemEvent::~CFileManagerFileSystemEvent
       
    91 //
       
    92 // ------------------------------------------------------------------------------
       
    93 CFileManagerFileSystemEvent::~CFileManagerFileSystemEvent()
       
    94     {
       
    95     Cancel();
       
    96     delete iFullPath;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CFileManagerFileSystemEvent::RunL
       
   101 // From CActive. Called when asynchronous request is completed. 
       
   102 // Notifies the observer
       
   103 // (other items were commented in a header).
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CFileManagerFileSystemEvent::RunL()
       
   107     {
       
   108     TInt err( iStatus.Int() );
       
   109 
       
   110     LOG_IF_ERROR1( err, "CFileManagerFileSystemEvent::RunL-err=%d", err )
       
   111 
       
   112     // Mark as received if there is no error
       
   113     if ( err == KErrNone )
       
   114         {
       
   115         iIsReceived = ETrue;
       
   116         }
       
   117 
       
   118     // If not ENotifyDisk, do refresh when event is checked
       
   119     // using CheckFileSystemEvent
       
   120     if ( iNotifyType == ENotifyDisk )
       
   121         {
       
   122         iEngine.DriveAddedOrChangedL();
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CFileManagerFileSystemEvent::RunError
       
   128 // From CActive. Called when error occurred in asynchronous request
       
   129 // Notifies the observer
       
   130 // (other items were commented in a header).
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TInt CFileManagerFileSystemEvent::RunError( TInt /*aError*/ )
       
   134     {
       
   135     return KErrNone;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CFileManagerFileSystemEvent::DoCancel
       
   140 // From CActive. Called when asynchronous request is canceled
       
   141 // (other items were commented in a header).
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CFileManagerFileSystemEvent::DoCancel()
       
   145     {
       
   146     iFs.NotifyChangeCancel( iStatus );
       
   147     }
       
   148 
       
   149 // ------------------------------------------------------------------------------
       
   150 // CFileManagerFileSystemEvent::Setup
       
   151 //
       
   152 // ------------------------------------------------------------------------------
       
   153 //
       
   154 void CFileManagerFileSystemEvent::Setup()
       
   155     {
       
   156     if( IsActive() )
       
   157         {
       
   158         return;
       
   159         }
       
   160 
       
   161     iIsReceived = EFalse;
       
   162 
       
   163     if( iFullPath )
       
   164         {
       
   165         iFs.NotifyChange( iNotifyType, iStatus, *iFullPath );
       
   166         }
       
   167     else
       
   168         {
       
   169         iFs.NotifyChange( iNotifyType, iStatus );
       
   170         }
       
   171 
       
   172     SetActive();
       
   173     }
       
   174 
       
   175 // ------------------------------------------------------------------------------
       
   176 // CFileManagerFileSystemEvent::CheckFileSystemEvent
       
   177 //
       
   178 // ------------------------------------------------------------------------------
       
   179 //
       
   180 void CFileManagerFileSystemEvent::CheckFileSystemEvent()
       
   181     {
       
   182     if( iIsReceived )
       
   183         {
       
   184         TRAP_IGNORE( iEngine.FolderContentChangedL() );
       
   185         }
       
   186     }
       
   187 
       
   188 //  End of File