camerauis/cameraapp/generic/src/CamFileCheckAo.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007-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:  Active object that checks if files have been deleted outside camera
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CamFileCheckAo.h"
       
    21 #include "camlogging.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CCamFileCheckAo::CCamFileCheckAo
       
    27 // C++ constructor
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CCamFileCheckAo::CCamFileCheckAo( CCamAppController& aController, MCamFileCheckObserver& aObserver )
       
    31     :CActive( EPriorityStandard ), iController( aController ), iObserver( aObserver )
       
    32     {
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CCamFileCheckAo::~CCamFileCheckAo
       
    37 // Destructor
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CCamFileCheckAo::~CCamFileCheckAo()
       
    41     {
       
    42     PRINT( _L("Camera => CCamFileCheckAo::~CCamFileCheckAo()") );
       
    43     Cancel();
       
    44     PRINT( _L("Camera <= CCamFileCheckAo::~CCamFileCheckAo()") );
       
    45     }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCamFileCheckAo::NewL
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CCamFileCheckAo* CCamFileCheckAo::NewL( CCamAppController& aController, MCamFileCheckObserver& aObserver )
       
    54     {
       
    55     CCamFileCheckAo* self = new( ELeave ) CCamFileCheckAo( aController, aObserver );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59 
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CCamFileCheckAo::ConstructL
       
    65 // 2nd phase construction
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CCamFileCheckAo::ConstructL()
       
    69    {
       
    70    CActiveScheduler::Add( this );
       
    71    }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCamFileCheckAo::DoCancel
       
    75 // Cancels the active object
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CCamFileCheckAo::DoCancel()
       
    79     {
       
    80     PRINT( _L("Camera => CCamFileCheckAo::DoCancel()") );
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CCamFileCheckAo::RunL
       
    85 // Check existance of next file in burstcapturearray.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CCamFileCheckAo::RunL()
       
    89     {
       
    90     PRINT1( _L("Camera => CCamFileCheckAo::RunL()  findex=%d"), iFileIndex )
       
    91 
       
    92     //Check to prevent crash. Some items from array might have been deleted
       
    93     //before this object have been activated...Or by different thread, active object and so on...
       
    94     if ( iFileIndex < iArray->Count() && iFileIndex >= 0 )
       
    95         {
       
    96         if ( !BaflUtils::FileExists( iFs, iArray->FileName( iFileIndex ) ) 
       
    97              && iArray->FileName( iFileIndex ) != KNullDesC )
       
    98             {
       
    99             PRINT1( _L("Camera <> CCamFileCheckAo::RunL: File %s didn't exist"),iArray->FileName( iFileIndex ).Ptr() )
       
   100             iArray->SetDeleted( iFileIndex, ETrue );             
       
   101             iFileCount--;
       
   102             }  	
       
   103         }
       
   104     else
       
   105         {
       
   106         PRINT( _L("Camera <> CCamFileCheckAo::RunL emptyrun") )
       
   107         iFileIndex = iArray->Count();
       
   108         iFileCount = iFileIndex;
       
   109         iEmptyRun=ETrue;
       
   110         }
       
   111 
       
   112     if( iFileIndex > 0 && iFileCount > 0 )
       
   113         {
       
   114         if( iEmptyRun )
       
   115             {
       
   116             if( iFileIndex > iFileCount)
       
   117                 {
       
   118                 iFileIndex = iFileCount;	
       
   119                 }
       
   120             else
       
   121                 {
       
   122                 iFileIndex--;	
       
   123                 }
       
   124             }
       
   125         else
       
   126             {
       
   127             iFileIndex--;          	
       
   128             }
       
   129         PRINT( _L("Camera <> CCamFileCheckAo::RunL: Set active again.") )
       
   130         StartRequest();
       
   131         }
       
   132     else
       
   133         {
       
   134         //File check is complete. Don't set active anymore.
       
   135         //Inform observer about result.
       
   136         TRAPD( err, iObserver.FileCheckingCompleteL( iFileCount, KErrNone ) );
       
   137         if( err != KErrNone )
       
   138             {
       
   139             User::Leave( err );
       
   140             }
       
   141         }
       
   142     }
       
   143 
       
   144 
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CCamFileCheckAo::Start
       
   148 // Initializes starting index and set active..
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CCamFileCheckAo::Start()
       
   152     {
       
   153     PRINT( _L("Camera => CCamFileCheckAo::Start()") );
       
   154     iArray = iController.BurstCaptureArray();
       
   155     iFileCount = iArray->Count();
       
   156     iFileIndex = iFileCount;
       
   157     iFs = CEikonEnv::Static()->FsSession();
       
   158 
       
   159     StartRequest();
       
   160     PRINT( _L("Camera <= CCamFileCheckAo::Start()") );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CCamFileCheckAo::StartRequest
       
   165 // Set active and starts new request immediately
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CCamFileCheckAo::StartRequest()
       
   169     {
       
   170     iEmptyRun = EFalse;
       
   171     SetActive();
       
   172     TRequestStatus* statusPtr = &iStatus;
       
   173     User::RequestComplete( statusPtr, KErrNone );
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CCamFileCheckAo::RunError
       
   178 // Called when an error has occurred.
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TInt CCamFileCheckAo::RunError( TInt aError )
       
   182     {
       
   183     PRINT( _L("Camera => CCamFileCheckAo::RunError()") );
       
   184     
       
   185     TRAP_IGNORE( iObserver.FileCheckingCompleteL( 0, aError ) )
       
   186     PRINT( _L("Camera <= CCamFileCheckAo::RunError()") );
       
   187     return KErrNone;
       
   188     }
       
   189 
       
   190 //  End of File