camerauis/cameraapp/generic/src/CamAppController.cpp
changeset 0 1ddebce53859
child 1 f5ec9446e5bf
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Class for managing intercommunication between Camera UI*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // ===========================================================================
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <bldvariant.hrh> // for feature definitions
       
    23 
       
    24 #include <e32property.h>
       
    25 #include <apparc.h>
       
    26 #include <fbs.h>
       
    27 #include <eikenv.h>
       
    28 
       
    29 #include <hal.h>
       
    30 #include <hal_data.h>
       
    31 #include <pathinfo.h>
       
    32 #include <barsread.h>
       
    33 #include <AknUtils.h>
       
    34 #include <akntoolbar.h>
       
    35 #include <ProductVariant.hrh>
       
    36 #include <centralrepository.h>
       
    37 
       
    38 #include <ctsydomainpskeys.h>
       
    39 #include <ProfileEngineSDKCRKeys.h>
       
    40 #include <sysutildomaincrkeys.h>
       
    41 #include <ScreensaverInternalPSKeys.h>
       
    42 #include <musresourceproperties.h>
       
    43 #include <cameraplatpskeys.h>
       
    44 #include <bitmaptransforms.h>
       
    45 #include <sensrvorientationsensor.h>
       
    46 #include <sensrvchannel.h>
       
    47 #include <sensrvchannelfinder.h>
       
    48 
       
    49 #include <UsbWatcherInternalPSKeys.h>
       
    50 #include <usbpersonalityids.h>
       
    51 
       
    52 
       
    53 #include <cameraapp.rsg>
       
    54 #include <vgacamsettings.rsg>
       
    55 #include "CamSettingsInternal.hrh"
       
    56 #include "CamProductSpecificSettings.hrh"
       
    57 #include "CameraappPrivateCRKeys.h"
       
    58 #include "CamAppController.h"
       
    59 #include "CamUtility.h"
       
    60 #include "CamLogger.h"
       
    61 #include "CamSettings.hrh"
       
    62 #include "CamSettingsModel.h"
       
    63 #include "CamPanic.h"
       
    64 #include "CamBurstCaptureArray.h"
       
    65 #include "CamTimer.h"
       
    66 #include "CamImageSaveActive.h"
       
    67 #include "CamAppUi.h"
       
    68 #include "CamObserverHandler.h"
       
    69 #include "CamSelfTimer.h"
       
    70 #include "camflashstatus.h"
       
    71 
       
    72 #include "CamPerformance.h"
       
    73 #include "OstTraceDefinitions.h"
       
    74 #ifdef OST_TRACE_COMPILER_IN_USE
       
    75 #include "CamAppControllerTraces.h"
       
    76 #endif
       
    77 
       
    78 #include "CamVideoQualityLevel.h"
       
    79 #include "CamCallStateAo.h"    
       
    80 #include "CamPropertyWatcher.h"
       
    81 #include <avkondomainpskeys.h>
       
    82 
       
    83 #ifndef __WINSCW__
       
    84   #include "rlocationtrail.h"
       
    85   #include "locationtrailpskeys.h"
       
    86 #endif
       
    87 //#include "camconstantsettingprovider.h"
       
    88 #include "camsettingprovider.h"
       
    89 #include "camsettingconversion.h"
       
    90 #include "camcamerarequests.h"
       
    91 #include "camcameraevents.h"
       
    92 #include "camcameracontrollertypes.h"
       
    93 #include "camcameracontroller.h"
       
    94 #include "cambuffershare.h"
       
    95 #include "cambuffersharecleanup.h"
       
    96 #include "camaudioplayercontroller.h"
       
    97 #include "camuidconstants.h"
       
    98 #include "camconfiguration.h"
       
    99 #include "CamPreCaptureViewBase.h"
       
   100 
       
   101 #include <cfclient.h>
       
   102 #include <cfcontextobject.h>
       
   103 #include <cfcontextquery.h>
       
   104 
       
   105 #include "camvideotime.h"
       
   106 #include "CamGSInterface.h"
       
   107 #include "CameraUiConfigManager.h"
       
   108 #include <bitmaptransforms.h> 
       
   109 
       
   110 #ifdef _DEBUG
       
   111 #ifdef _AO_TRACKING
       
   112 struct CFakeActiveScheduler : public CActiveScheduler {
       
   113   virtual TInt Extension_( TUint, TAny *&, TAny* ) { return 0; }
       
   114 };
       
   115 #endif // _AO_TRACKING
       
   116 #endif // _DEBUG
       
   117 
       
   118 // ===========================================================================
       
   119 // Local constants
       
   120 
       
   121 // Sequence mode related constants that define the amount of pictures taken
       
   122 // with sequence mode.
       
   123 const TInt KShortBurstCount  = 18;   // number of images captured during burst
       
   124 const TInt KMinBurstCount    = 2;    // minimum of images captured
       
   125 const TInt KBurstEstimate    = 10;   // Correction of underestimated file size  
       
   126 
       
   127 const TUint32 KCamLatestFilePath      = 0x00000001;
       
   128 
       
   129 
       
   130 // temporary constants until image naming is implemented
       
   131 _LIT( KImageExtension, ".jpg" );
       
   132 _LIT( KVideo3GPExtension, ".3gp" );
       
   133 #ifndef __WINS__
       
   134 _LIT( KVideoMP4Extension, ".mp4" );
       
   135 #endif
       
   136 
       
   137 const TInt KMaxExtension = 4;
       
   138 //const TInt64 KBurstInterval = 0;
       
   139 
       
   140 const TInt KIdleTimeout     = 1000000 * 60; // 60 seconds
       
   141 const TInt KDeepSleepTimeout = KIdleTimeout*2; // Measuring time is two minutes  
       
   142 const TInt KVideoArrayUsers = 1;
       
   143 const TInt KImageArrayUsers = 2;
       
   144 
       
   145 const TInt KVideoNameRetryCount = 1;    // Maximum number of video naming retries
       
   146 
       
   147 // UID for central repository file
       
   148 const TInt KCRCamShutterSound = 0x7; // key for shutter sound
       
   149 
       
   150 const TInt KMicroSecsInMilliSec = 1000;
       
   151 const TInt KSecondInMicSec = 1000000;
       
   152 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
   153 const TInt KLocTrailCloseRetryTime = 5 * KSecondInMicSec;
       
   154 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
   155 
       
   156 // Estimated time needed to complete autofocus
       
   157 const TInt KFocusingDurationSeconds = 2;
       
   158 
       
   159 const TInt KCCorFocused = 0x00000002;
       
   160 
       
   161 const TInt KCamMaxDateLen = 8;
       
   162 
       
   163 static const TInt KTimelapseArrayGranularity = 6;
       
   164 
       
   165 // Backlight / Inactivity timer related
       
   166 //   Callback interval is set to 4s. 
       
   167 //   Smallest value that the user can select from Phone Settings is 5s.
       
   168 static const TInt KBacklighTimerPriority = CActive::EPriorityHigh;
       
   169 static const TInt KBacklighTimerInterval = 4*1000*1000; 
       
   170 
       
   171 // Camera Controller events interest.
       
   172 //   Want to receive all events.
       
   173 //   Vf frames needed for correct zoom handling (should be left out otherwise).
       
   174 static const TUint KCamEventInterest = (  ECamCameraEventClassAll );
       
   175 
       
   176 static const TInt KLensCoverDelay = 500*1000;
       
   177 
       
   178 _LIT( KCamContextSource, "Application" );
       
   179 _LIT( KCamContextType, "Camera.Zoom" );
       
   180 _LIT( KCamContextValueEnable, "Enabled" );
       
   181 _LIT( KCamContextValueDisable, "Disabled" );
       
   182 _LIT_SECURITY_POLICY_PASS( KCamContextSecurity );
       
   183 
       
   184 static const TInt KCriticalMemoryLevel = 5*1000*1000;
       
   185 // ===========================================================================
       
   186 // Local namespace
       
   187 namespace NCamAppController
       
   188   {
       
   189   // -------------------------------------------------------
       
   190   // Request sequences 
       
   191 //  static const TCamCameraRequestId KCamSequencePowerOffOn[] = 
       
   192 //    { 
       
   193 //    ECamRequestPowerOff, 
       
   194 //    ECamRequestPowerOn
       
   195 //    };
       
   196   
       
   197   // -------------------------------------------------------
       
   198   // Local methods
       
   199 
       
   200   inline TInt ResetBitmap( CFbsBitmap*& aBitmap )
       
   201     {
       
   202     if( aBitmap )
       
   203       {
       
   204       aBitmap->Reset();
       
   205       return KErrNone;
       
   206       }
       
   207     else
       
   208       {
       
   209       TRAPD( create, aBitmap = new (ELeave) CFbsBitmap() );
       
   210       return create;
       
   211       }
       
   212     };
       
   213 
       
   214   inline void ClearSequenceBusyFlag( TAny* aBusyFlags )
       
   215     {
       
   216     TUint* flags = static_cast<TUint*>( aBusyFlags );
       
   217     if( flags )
       
   218       {
       
   219       *flags &= ~EBusySequence;
       
   220       }
       
   221     };
       
   222 
       
   223   inline void ClearRequestBusyFlag( TAny* aBusyFlags )
       
   224     {
       
   225     TUint* flags = static_cast<TUint*>( aBusyFlags );
       
   226     if( flags )
       
   227       {
       
   228       *flags &= ~EBusyRequest;
       
   229       }
       
   230     };
       
   231   }
       
   232 
       
   233 #include "camflagutility.inl"
       
   234 #include "campointerutility.inl"
       
   235 
       
   236 using namespace NCamAppController;
       
   237 using namespace NCamCameraController;
       
   238 // ===========================================================================
       
   239 
       
   240 
       
   241 // ===========================================================================
       
   242 // Member functions
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CCamAppController::NewL
       
   246 // Two-phased constructor.
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 CCamAppController* CCamAppController::NewL()
       
   250     {
       
   251     CCamAppController* self = new( ELeave ) CCamAppController();
       
   252     CleanupStack::PushL( self );
       
   253     self->ConstructL();
       
   254     CleanupStack::Pop( self );
       
   255     return self;
       
   256     }
       
   257 
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CCamAppController::CompleteConstructionL
       
   261 // The camera engine cannot be instantiated until the application orientation has 
       
   262 // been set by the CCamAppUi. This does not exist when the CCamAppController is 
       
   263 // constructed. CompleteConstructionL must be called in CCamAppUi::ConstructL()
       
   264 // ---------------------------------------------------------------------------
       
   265 //    
       
   266 void CCamAppController::CompleteConstructionL()
       
   267   {
       
   268   PRINT( _L("Camera => CCamAppController::CompleteConstructionL" ))
       
   269 
       
   270   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
   271   
       
   272   // Memory critical levels reading moved to the point when
       
   273   // those values are actually needed for the first time.   
       
   274 
       
   275   TInt index = 0;
       
   276   iInfo.iActiveCamera = ECamActiveCameraPrimary;
       
   277   PRINT1( _L("Camera <> Cameras available: %d"), CamerasAvailable() )
       
   278   
       
   279   PRINT( _L("Camera <> Store primary camera settings"))
       
   280   iSettingsModel->StorePrimaryCameraSettingsL();
       
   281 
       
   282 
       
   283   PRINT1( _L("Camera <> CCamAppController::CompleteConstructionL iSlideState initial value = %d" ), iSlideState)
       
   284   if ( iConfigManager->IsLensCoverSupported() )
       
   285       {
       
   286       // Request notification of slide state changes
       
   287       iSlideStateWatcher->Subscribe();
       
   288 
       
   289       // Read the current slider status - use the front camera (if there is one) as default if
       
   290       // there are any errors.
       
   291       TInt slideErr = iSlideStateWatcher->Get( iSlideState );
       
   292       PRINT1( _L("Camera <> CCamAppController::CompleteConstructionL setting iSlideState to %d" ), iSlideState)
       
   293       TInt requiredOrientation;
       
   294       if ( ( appUi->CamOrientation() == ECamOrientationCamcorderLeft && iSlideState == CameraPlatPSKeys::EClosed ) ||
       
   295             ( appUi->CamOrientation() == ECamOrientationCamcorder && iSlideState == CameraPlatPSKeys::EClosed ) )
       
   296         {
       
   297         if ( appUi->IsQwerty2ndCamera() )
       
   298             {  
       
   299             PRINT( _L("Camera <> Do not exit. Reload landscape 2nd camera settings") )
       
   300             index = 1;
       
   301             iInfo.iActiveCamera = ECamActiveCameraSecondary;
       
   302             CCamAppUi* appUi = static_cast<CCamAppUi*>( 
       
   303                                CEikonEnv::Static()->AppUi() ); 
       
   304             // We may have primary camera settings loaded 
       
   305             LoadStaticSettingsL( appUi->IsEmbedded() );   
       
   306             CamUtility::GetPsiInt( ECamPsiSecondaryCameraOrientation, 
       
   307                                    requiredOrientation );
       
   308             }
       
   309         else
       
   310             {
       
   311             PRINT( _L("Camera <> Lens cover has been closed during camera construction. Exit camera.") )
       
   312             appUi->HandleCommandL( EEikCmdExit);
       
   313             }
       
   314         }
       
   315       else  
       
   316         {  
       
   317         // if the slide is closed or there is an error, then use the front camera
       
   318         // check that there is more than 1 camera and that the current orientation is correct
       
   319         if ( ( iSlideState == CameraPlatPSKeys::EClosed               
       
   320               || slideErr    != KErrNone )
       
   321               && CamerasAvailable() > 1 )
       
   322           {
       
   323           PRINT( _L("Camera <> CCamAppController::CompleteConstructionL slider is not open" ))
       
   324           index = 1;
       
   325           iInfo.iActiveCamera = ECamActiveCameraSecondary;
       
   326           CamUtility::GetPsiInt( ECamPsiSecondaryCameraOrientation, requiredOrientation );
       
   327           }
       
   328         else // slide is open or using primary camera as default
       
   329           {
       
   330           PRINT( _L("Camera <> CCamAppController::CompleteConstructionL slider is open- primary camera in use" ))
       
   331           index = 0;
       
   332           iInfo.iActiveCamera = ECamActiveCameraPrimary;
       
   333 
       
   334           //when active camera is primary camera,orientation must be landscape,
       
   335           //so need to fix orientation
       
   336           if ( ECamOrientationPortrait == appUi->CamOrientation() )
       
   337             {
       
   338             TInt primaryOrientation;
       
   339             CamUtility::GetPsiInt( ECamPsiPrimaryCameraOrientation, 
       
   340                                       primaryOrientation );
       
   341             appUi->SetOrientationL( ( CAknAppUiBase::TAppUiOrientation ) primaryOrientation );		
       
   342             appUi->SetCamOrientationToLandscape();
       
   343             }
       
   344           }   
       
   345         }
       
   346       }
       
   347 
       
   348   ConstructCameraControllerL( index );
       
   349   
       
   350   // Send startup sequence ?
       
   351 
       
   352   /**
       
   353    * Removed all custom interfaces requested from engine
       
   354    */
       
   355   iAccSensorListening = EFalse;
       
   356 
       
   357   iCallStateAo = CCamCallStateAo::NewL( this );             
       
   358   
       
   359   // Use backlight timer instead of every Nth vf frame event
       
   360   // to reset inactivity timer. This is to avoid adding load
       
   361   // when higher VF frame rates are used (and overall load is
       
   362   // already higher).
       
   363   iBacklightTimer = CPeriodic::NewL( KBacklighTimerPriority );
       
   364 
       
   365 #ifdef _DEBUG
       
   366 #ifdef _AO_TRACKING
       
   367   TAny *iAoBacklightTimer = (TAny *)iBacklightTimer;
       
   368   PRINT2( _L("Camera <> CCamAppController: BacklightTimer=%x, %d"),iBacklightTimer, iAoBacklightTimer );
       
   369   CActiveScheduler *pAS = CActiveScheduler::Current();
       
   370   CFakeActiveScheduler *pFAS = static_cast<CFakeActiveScheduler*>(pAS);
       
   371   pFAS->Extension_( 0, iAoBacklightTimer, (TAny *)("iBacklightTimer") );
       
   372 #endif // _AO_TRACKING
       
   373 #endif // _DEBUG
       
   374 
       
   375 #ifdef _DEBUG
       
   376 #ifdef _AO_TRACKING
       
   377   TAny *iAoDeepSleepTimer = (TAny *)iDeepSleepTimer;
       
   378   PRINT2( _L("Camera <> CCamAppController: DeepSleepTimer=%x, %d"),iDeepSleepTimer, iAoDeepSleepTimer );
       
   379   CActiveScheduler *pAS2 = CActiveScheduler::Current();
       
   380   CFakeActiveScheduler *pFAS2 = static_cast<CFakeActiveScheduler*>(pAS2);
       
   381   pFAS2->Extension_( 0, iAoDeepSleepTimer, (TAny *)("iDeepSleepTimer") );
       
   382 #endif // _AO_TRACKING
       
   383 #endif // _DEBUG
       
   384 
       
   385 
       
   386   if ( UiConfigManagerPtr()->IsXenonFlashSupported() )
       
   387       {
       
   388       PRINT( _L("Camera <> CCamAppController: Create flash status observer..") );
       
   389       iFlashStatus = CCamFlashStatus::NewL( *this );
       
   390       }
       
   391 
       
   392   PRINT( _L("Camera <= CCamAppController::CompleteConstructionL" ))
       
   393   }    
       
   394 
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // 
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 TInt 
       
   401 CCamAppController::GetCriticalMemoryLevelL( const TCamMediaStorage& aStorage )
       
   402   {
       
   403   PRINT( _L("Camera => CCamAppController::GetCriticalMemoryLevelL" ) )
       
   404 
       
   405   // If this is the first call here, get the critical levels from
       
   406   // Central repository. Later the cached values will be used.
       
   407   if( KErrNotFound == iRamDiskCriticalLevel
       
   408    || KErrNotFound == iDiskCriticalLevel   )
       
   409     {
       
   410     CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
   411     TInt err;
       
   412     err = repository->Get( KDiskCriticalThreshold , iDiskCriticalLevel );
       
   413     if ( KErrNone != err )
       
   414       {
       
   415       CamPanic( ECamPanicDefaultNotFoundInIniFile );      
       
   416       }
       
   417     err = repository->Get( KRamDiskCriticalLevel , iRamDiskCriticalLevel ); 
       
   418     if ( KErrNone != err )
       
   419       {
       
   420       CamPanic( ECamPanicDefaultNotFoundInIniFile ); 
       
   421       } 
       
   422     CleanupStack::PopAndDestroy( repository );
       
   423     }
       
   424   
       
   425   TInt level = ( aStorage == ECamMediaStoragePhone ) 
       
   426              ? iRamDiskCriticalLevel
       
   427              : iDiskCriticalLevel;
       
   428 
       
   429   PRINT1( _L("Camera <= CCamAppController::GetCriticalMemoryLevelL, level:%d" ), level )
       
   430   return level;
       
   431   }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CCamAppController::~CCamAppController
       
   435 // Destructor
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 CCamAppController::~CCamAppController()
       
   439   { 
       
   440   PRINT( _L("Camera => ~CCamAppController") );
       
   441   // As a precaution, make sure the screen saver is never left in a disabled state
       
   442   EnableScreenSaver( ETrue );
       
   443 
       
   444   RProperty::Set( KPSUidCamcorderNotifier, KCCorFocused, 0 );
       
   445   
       
   446   if ( iFlashStatus )
       
   447     {
       
   448     delete iFlashStatus;
       
   449     }
       
   450 
       
   451   delete iSoundPlayer;
       
   452 
       
   453   PRINT( _L("Camera <> close observers array..") );
       
   454   __ASSERT_DEBUG( iControllerObservers.Count() == 0, CamPanic( ECamPanicResourceLeak ) );
       
   455   iControllerObservers.Close();
       
   456 
       
   457   delete iCallStateAo;    
       
   458 
       
   459   delete iBurstTimer;
       
   460 
       
   461 // Using timer also on bitmap mode.
       
   462   if( iBacklightTimer )
       
   463     {
       
   464     iBacklightTimer->Cancel();
       
   465     delete iBacklightTimer;
       
   466     }
       
   467 
       
   468     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && 
       
   469     		iAccSensorListening )
       
   470         {
       
   471         iAccSensorChannel->StopDataListening();
       
   472         iAccSensorChannel->CloseChannel();
       
   473         }
       
   474     delete iAccSensorChannel;
       
   475 
       
   476   if ( iSlideStateWatcher )
       
   477     {
       
   478     iSlideStateWatcher->Cancel();
       
   479     delete iSlideStateWatcher;
       
   480     }
       
   481   
       
   482   if ( iSliderCallBack )
       
   483     { 
       
   484     iSliderCallBack->Cancel();
       
   485     delete iSliderCallBack;
       
   486     iSliderCallBack = NULL;
       
   487     }
       
   488 
       
   489   if ( iKeyLockStatusWatcher && iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
   490     {
       
   491     iKeyLockStatusWatcher->Cancel();
       
   492     delete iKeyLockStatusWatcher;
       
   493     }
       
   494   
       
   495   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() )
       
   496       {
       
   497       TRAP_IGNORE ( PublishZoomStateL( EFalse ) );
       
   498       delete iContextFwClient;      
       
   499       }
       
   500 
       
   501   if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
   502     {
       
   503     if( iLocationTrailTimer )
       
   504       {
       
   505       iLocationTrailTimer->Cancel();
       
   506       delete iLocationTrailTimer;
       
   507       iLocationTrailTimer = NULL;
       
   508       }
       
   509     }
       
   510       
       
   511   if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
   512     {
       
   513     // stop trail and close session
       
   514     StopLocationTrail( ETrue );
       
   515     }
       
   516 
       
   517   if ( iImageSaveActive )  
       
   518     {
       
   519       iImageSaveActive->ForceCancel();
       
   520     delete iImageSaveActive;
       
   521     }
       
   522 
       
   523   PRINT( _L("Camera <> delete settingsmodel..") );
       
   524   delete iSettingsModel;  // Must be before iEngine deleted
       
   525   iSettingsPreviewHandler = NULL; // Currently the Settings Model object.
       
   526   iPreviewRollbacks.Close();
       
   527 
       
   528 
       
   529   delete iCaptureArray;
       
   530   delete iRotationArray;
       
   531   if ( iSequenceFilenameArray )
       
   532     {
       
   533     iSequenceFilenameArray->Reset();
       
   534     delete iSequenceFilenameArray;
       
   535     }    
       
   536 
       
   537   if( iDeepSleepTimer )
       
   538     {
       
   539     iDeepSleepTimer->Cancel();
       
   540     delete iDeepSleepTimer;
       
   541     }
       
   542 
       
   543   if( iIdleTimer )
       
   544     {
       
   545     iIdleTimer->Cancel();
       
   546     delete iIdleTimer;
       
   547     }
       
   548 
       
   549   if ( iTimeLapseTimer )
       
   550     {
       
   551     iTimeLapseTimer->Cancel();
       
   552     delete iTimeLapseTimer;
       
   553     }
       
   554 
       
   555   if( iCaptureToneDelayTimer )
       
   556     {
       
   557     iCaptureToneDelayTimer->Cancel();
       
   558     delete iCaptureToneDelayTimer;
       
   559     }
       
   560 
       
   561   delete iCaptureCompletionObserverHandler;      
       
   562   delete iSnapShotCopy; 
       
   563     
       
   564   iJpegDataSizes.Close();
       
   565   iSequencePostProcessDataSizes.Close();
       
   566   
       
   567   // Close the arrays
       
   568   iPendingObserversArray.Close();
       
   569   iCameraEventInterested.Close();
       
   570 
       
   571   // Controller handles releasing CCamera if needed.
       
   572   PRINT( _L("Camera <> delete camera controller..") );
       
   573   delete iCameraController;
       
   574   PRINT( _L("Camera <> delete setting provider..") );
       
   575   delete iSettingProvider;
       
   576   PRINT( _L("Camera <= ~CCamAppController") );
       
   577   
       
   578   PRINT( _L("Camera <> delete Configuration Manager..") );
       
   579   delete iConfiguration;
       
   580   iConfiguration = NULL;  
       
   581 
       
   582   RProperty::Delete( KPSUidCamcorderNotifier, KCCorFocused );  
       
   583     if( iPlugin )
       
   584         {
       
   585         // Destroy Ecom plugin
       
   586         iPlugin->DestroyPlugin();
       
   587         }
       
   588   iPlugin = NULL;
       
   589   delete iDriveChangeNotifier;
       
   590   iFs.Close();
       
   591   
       
   592   if( iRotatorAo )
       
   593       {
       
   594       delete iRotatorAo;
       
   595       }
       
   596   PRINT( _L("Camera <= ~CCamAppController") );
       
   597   }
       
   598 
       
   599 
       
   600 // ---------------------------------------------------------------------------
       
   601 // CCamAppController::SavedCurrentImage
       
   602 // Returns whether the last requested captured image has been saved or not.
       
   603 // ---------------------------------------------------------------------------
       
   604 //
       
   605 TBool CCamAppController::SavedCurrentImage() const
       
   606   {
       
   607   PRINT( _L("Camera => CCamAppController::SavedCurrentImage") );
       
   608   TBool saved( ETrue );
       
   609 
       
   610   // If we are waiting for a save request then image has not been saved.
       
   611   if( iImageSaveRequestPending )
       
   612     {
       
   613     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: iImageSaveRequestPending") )
       
   614     saved = EFalse;
       
   615     }
       
   616   else if( CurrentFullFileName() == KNullDesC )
       
   617     {
       
   618     saved = EFalse;
       
   619     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: filename not yet reserved") ) 
       
   620     }
       
   621   else if( !iCaptureArray->AlreadySavedFile( CurrentFullFileName() ) ||
       
   622             iCaptureArray->CurrentlySavingFile( CurrentFullFileName() ) )
       
   623     {
       
   624     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: capture array not saved file or currently saving file") )
       
   625     saved = EFalse;
       
   626     }
       
   627   else if ( iInfo.iOperation == ECamCapturing || iInfo.iOperation == ECamCompleting )
       
   628     {
       
   629    	PRINT(_L("Camera CCamAppController::SavedCurrentImage returning false, capturing/completing") )
       
   630    	saved = EFalse;    
       
   631     }
       
   632   else
       
   633     {
       
   634     // empty
       
   635     }
       
   636 
       
   637   PRINT1( _L("Camera <= CCamAppController::SavedCurrentImage, return %d"), saved );
       
   638   return saved;
       
   639   }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // CCamAppController::RenameCurrentFileL
       
   643 // Rename image/video.
       
   644 // ---------------------------------------------------------------------------
       
   645 //
       
   646 TBool 
       
   647 CCamAppController::RenameCurrentFileL( const TDesC&          aNewName, 
       
   648                                        const TCamCameraMode& /*aMode*/ )
       
   649   {
       
   650   TBool status = EFalse;
       
   651 
       
   652   // If file to rename has already been saved then remove from album,
       
   653   // rename the file and add the renamed file to the album.
       
   654   if ( BurstCaptureArray()->AlreadySavedFile( CurrentFullFileName() ) )
       
   655     {                
       
   656     // Rename the file.
       
   657     TFileName filePath = CurrentFullFileName();
       
   658     CamUtility::RenameStillImageL( filePath, aNewName, filePath );
       
   659     
       
   660     // Update capture array with new name and path.
       
   661     BurstCaptureArray()->SetNameL( filePath, aNewName, iCurrentImageIndex );
       
   662     
       
   663     status = ETrue;
       
   664     }
       
   665   // Otherwise, if the file is not currently being saved, modify the names 
       
   666   // in the capture array before it is saved.
       
   667   else if ( !BurstCaptureArray()->CurrentlySavingFile( CurrentFullFileName() ) )
       
   668     {
       
   669     // Update capture array with new name and path.
       
   670     // ...determine new path.
       
   671     TParsePtrC parse( CurrentFullFileName() );
       
   672     TFileName fullNewPath;
       
   673     fullNewPath = parse.DriveAndPath();
       
   674     fullNewPath.Append( aNewName );
       
   675     fullNewPath.Append( parse.Ext() );
       
   676 
       
   677     BurstCaptureArray()->SetNameL( fullNewPath, aNewName, iCurrentImageIndex );
       
   678 
       
   679     status = ETrue;
       
   680     }
       
   681   // Otherwise, the file is in the process of being saved, and 
       
   682   // so that renaming must wait until completed.
       
   683   else
       
   684     {
       
   685     // Leave status to EFalse
       
   686     }
       
   687     
       
   688   return status;
       
   689   }
       
   690 
       
   691 
       
   692 // ---------------------------------------------------------------------------
       
   693 // CCamAppController::AddControllerObserverL
       
   694 // Add a controller observer.
       
   695 // ---------------------------------------------------------------------------
       
   696 //
       
   697 void CCamAppController::AddControllerObserverL( const MCamControllerObserver* aObserver )
       
   698   {
       
   699   if( aObserver &&
       
   700       KErrNotFound == iControllerObservers.Find( aObserver ) )
       
   701     {
       
   702     User::LeaveIfError( iControllerObservers.Append( aObserver ) );
       
   703     }
       
   704   }
       
   705 
       
   706 // ---------------------------------------------------------------------------
       
   707 // CCamAppController::RemoveControllerObserver
       
   708 // Remove a controller observer.
       
   709 // ---------------------------------------------------------------------------
       
   710 //
       
   711 void CCamAppController::RemoveControllerObserver( const MCamControllerObserver* aObserver )
       
   712   {
       
   713   // Errors ignored
       
   714   if( aObserver )
       
   715     {
       
   716     TInt index = iControllerObservers.Find( aObserver );
       
   717     if( KErrNotFound != index )
       
   718       {
       
   719       iControllerObservers.Remove( index );
       
   720       }
       
   721     }
       
   722   }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // AddCameraObserverL
       
   726 // ---------------------------------------------------------------------------
       
   727 //
       
   728 void 
       
   729 CCamAppController
       
   730 ::AddCameraObserverL( const MCamCameraObserver* aObserver, 
       
   731                       const TUint&              aEventInterest )
       
   732   {
       
   733   PRINT1( _L("Camera => CCamAppController::AddCameraObserverL aObserver=%d"), aObserver );
       
   734 
       
   735   // First check that observer is not in array already
       
   736   if( KErrNotFound == iPendingObserversArray.Find( aObserver ) )
       
   737       {  
       
   738       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL add Observer") );
       
   739 
       
   740       iPendingObserversArray.AppendL( aObserver );
       
   741       iCameraEventInterested.AppendL( aEventInterest );
       
   742       }
       
   743 
       
   744   if( iCameraController )
       
   745       {
       
   746       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL camera controller available") );
       
   747       while ( iPendingObserversArray.Count() > 0 &&
       
   748               iCameraEventInterested.Count() > 0 )
       
   749           {
       
   750           const MCamCameraObserver* camEventObserver = iPendingObserversArray[0];
       
   751           TUint eventInterest = iCameraEventInterested[0];
       
   752           iCameraController->AttachObserverL( camEventObserver, eventInterest );
       
   753           iPendingObserversArray.Remove( 0 );
       
   754           iCameraEventInterested.Remove( 0 );
       
   755           } 
       
   756       }
       
   757   PRINT(_L("Camera <= CCamAppController::AddCameraObserverL") );
       
   758   }
       
   759 
       
   760 // ---------------------------------------------------------------------------
       
   761 // RemoveCameraObserver
       
   762 // ---------------------------------------------------------------------------
       
   763 //
       
   764 void 
       
   765 CCamAppController
       
   766 ::RemoveCameraObserver( const MCamCameraObserver* aObserver )
       
   767   {
       
   768   if( iCameraController )
       
   769     iCameraController->DetachObserver( aObserver );
       
   770   }
       
   771 
       
   772 // ---------------------------------------------------------------------------
       
   773 // AddSettingsObserverL
       
   774 // ---------------------------------------------------------------------------
       
   775 //
       
   776 void
       
   777 CCamAppController
       
   778 ::AddSettingsObserverL( const MCamSettingsModelObserver* aObserver )
       
   779   {
       
   780   if( iSettingsModel )
       
   781     iSettingsModel->AttachObserverL( aObserver );
       
   782   else
       
   783     User::Leave( KErrNotReady );
       
   784   }
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // RemoveCameraObserver
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 void 
       
   791 CCamAppController
       
   792 ::RemoveSettingsObserver( const MCamSettingsModelObserver* aObserver )
       
   793   {
       
   794   if( iSettingsModel )
       
   795     iSettingsModel->DetachObserver( aObserver );
       
   796   }
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 void 
       
   804 CCamAppController::ConstructCameraControllerL( TInt aCameraIndex )
       
   805   {
       
   806   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 1" );
       
   807   PRINT( _L("Camera => CCamAppController::ConstructCameraControllerL") )
       
   808   PERF_EVENT_START_L2( EPerfEventCAEConstruction );
       
   809 
       
   810   if( !iCameraController )
       
   811     {
       
   812     iCameraController = CCamCameraController::NewL( *iSettingProvider, *this,
       
   813                                                     aCameraIndex ); 
       
   814     //If uiorientationoverride feature is not supported, the camera switch has
       
   815     // to be finished here                                                    
       
   816     if( !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() ) )
       
   817       {
       
   818       iCameraController->CompleteSwitchCameraL();
       
   819       }
       
   820     }
       
   821 
       
   822   // Attach as Camera Controller observer to get events
       
   823   PRINT1( _L("Camera <> Attaching as camera observer with interest:%032b"), KCamEventInterest );
       
   824   iCameraController->AttachObserverL( this, KCamEventInterest );
       
   825 
       
   826 
       
   827   PERF_EVENT_END_L2( EPerfEventCAEConstruction );
       
   828   PRINT( _L("Camera <= CCamAppController::ConstructCameraControllerL") )
       
   829   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 0" );
       
   830   }
       
   831 
       
   832 // #################################################################################################
       
   833 
       
   834 // ---------------------------------------------------------------------------
       
   835 // Returns the current camera controller state
       
   836 // (Bitfield of type TCamCameraStateFlags )
       
   837 // ---------------------------------------------------------------------------
       
   838 //
       
   839 TUint
       
   840 CCamAppController::CameraControllerState() const
       
   841   {
       
   842   TUint state( ECamIdle );
       
   843   if( iCameraController )
       
   844     {
       
   845     state = iCameraController->State();
       
   846     }
       
   847   PRINT1( _L("Camera =><= CCamAppController::CameraControllerState(): %032b"), state );
       
   848   return state;
       
   849   }
       
   850   
       
   851 // ---------------------------------------------------------------------------
       
   852 // Returns the current camera state
       
   853 // (TCamCameraState)
       
   854 // ---------------------------------------------------------------------------
       
   855 //
       
   856 TCamCameraState
       
   857 CCamAppController::CameraState() const
       
   858   {
       
   859   TCamCameraState state( ECamCameraIdle );  
       
   860   
       
   861   TUint controllerState = CameraControllerState();
       
   862  
       
   863   // Convert controller state to TCamCameraState
       
   864   // Use the state represented by the "most significant"
       
   865   // bit in the bitfield. Ignore VF state.
       
   866   if( IsFlagOn( controllerState, ECamImageOn ) )
       
   867     {
       
   868     state = ECamCameraPreparedImage;
       
   869     }
       
   870   else if( IsFlagOn( controllerState, ECamVideoOn ) )
       
   871     {
       
   872     state = ECamCameraPreparedVideo;  
       
   873     }
       
   874   else if( IsFlagOn( controllerState, ECamPowerOn ) )  
       
   875     {
       
   876     state = ECamCameraPowerOn;  
       
   877     }
       
   878   else if( IsFlagOn( controllerState, ECamReserved ) )  
       
   879     {
       
   880     state = ECamCameraReserved;  
       
   881     }
       
   882     
       
   883   PRINT1( _L("Camera =><= CCamAppController::CameraState(): %d"), state );
       
   884   return state;
       
   885   }  
       
   886 
       
   887 // ---------------------------------------------------------------------------
       
   888 //
       
   889 // ---------------------------------------------------------------------------
       
   890 //
       
   891 TCamCameraMode
       
   892 CCamAppController::CurrentMode() const
       
   893   {
       
   894   return iInfo.iMode;
       
   895   }
       
   896 
       
   897 // ---------------------------------------------------------------------------
       
   898 //
       
   899 // ---------------------------------------------------------------------------
       
   900 //
       
   901 TCamCameraMode
       
   902 CCamAppController::TargetMode() const
       
   903   {
       
   904   return iInfo.iTargetMode;
       
   905   }
       
   906 
       
   907 // ---------------------------------------------------------------------------
       
   908 //
       
   909 // ---------------------------------------------------------------------------
       
   910 //
       
   911 // CCamAppController::CurrentCaptureModeSetup()
       
   912 TCamImageCaptureMode
       
   913 CCamAppController::CurrentImageModeSetup() const
       
   914   {
       
   915   TCamImageCaptureMode captureMode = ECamImageCaptureSingle; 
       
   916   if( IsAppUiAvailable() ) 
       
   917     { 
       
   918     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
   919     if ( appUi->IsBurstEnabled() ) 
       
   920       { 
       
   921       captureMode = appUi->CurrentBurstMode(); 
       
   922       } 
       
   923     } 
       
   924   return captureMode; 
       
   925   }
       
   926 
       
   927 // ---------------------------------------------------------------------------
       
   928 //
       
   929 // ---------------------------------------------------------------------------
       
   930 //
       
   931 TCamCaptureOperation
       
   932 CCamAppController::CurrentOperation() const
       
   933   {
       
   934   return iInfo.iOperation;
       
   935   }
       
   936 
       
   937 // ---------------------------------------------------------------------------
       
   938 //
       
   939 // ---------------------------------------------------------------------------
       
   940 //
       
   941 TCamCaptureOperation
       
   942 CCamAppController::CurrentImageOperation() const
       
   943   {
       
   944   if( ECamControllerImage == iInfo.iMode )
       
   945     return iInfo.iOperation;
       
   946   else
       
   947     return ECamNoOperation;
       
   948   }
       
   949 
       
   950 // ---------------------------------------------------------------------------
       
   951 //
       
   952 // ---------------------------------------------------------------------------
       
   953 //
       
   954 TCamCaptureOperation  
       
   955 CCamAppController::CurrentVideoOperation() const
       
   956   {
       
   957   if( ECamControllerVideo == iInfo.iMode )
       
   958     return iInfo.iOperation;
       
   959   else
       
   960     return ECamNoOperation;
       
   961   }
       
   962 
       
   963 // ---------------------------------------------------------------------------
       
   964 //
       
   965 // ---------------------------------------------------------------------------
       
   966 //
       
   967 TCamImageCaptureMode  CCamAppController::CurrentImageMode() const
       
   968     {
       
   969     return iInfo.iImageMode;
       
   970     }
       
   971 // ---------------------------------------------------------------------------
       
   972 //
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 TCamCameraTriState CCamAppController::ViewfinderTargetState() const
       
   976   {
       
   977   return iInfo.iTargetVfState;
       
   978   }
       
   979 
       
   980 
       
   981 // ---------------------------------------------------------------------------
       
   982 //
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 void 
       
   986 CCamAppController::SetMode( const TCamCameraMode& aNewMode )
       
   987   {
       
   988   PRINT3( _L("Camera => CCamAppController::SetMode old[%s] new[%s] target[%s]"), 
       
   989           KCamModeNames[iInfo.iMode], 
       
   990           KCamModeNames[aNewMode],
       
   991           KCamModeNames[iInfo.iTargetMode] );
       
   992 
       
   993   if( aNewMode != iInfo.iMode )
       
   994     {
       
   995     // In shutdown mode will not accept leaving ECamControllerShutdown state.
       
   996     TBool newModeNotAccepted = ( IsInShutdownMode() 
       
   997                               && ECamControllerShutdown == iInfo.iMode 
       
   998                               && ECamControllerShutdown != aNewMode );
       
   999     if( !newModeNotAccepted )
       
  1000       {
       
  1001       iInfo.iMode = aNewMode;
       
  1002       NotifyControllerObservers( ECamEventEngineStateChanged );
       
  1003       }
       
  1004     else
       
  1005       {
       
  1006       PRINT( _L("Camera <> this mode change not acceptable in shutdown mode!") );
       
  1007       }      
       
  1008     }
       
  1009   PRINT( _L("Camera <= CCamAppController::SetMode") );
       
  1010   }
       
  1011 
       
  1012 // ---------------------------------------------------------------------------
       
  1013 //
       
  1014 // ---------------------------------------------------------------------------
       
  1015 //
       
  1016 void 
       
  1017 CCamAppController::SetTargetMode( const TCamCameraMode& aNewMode )
       
  1018   {
       
  1019   PRINT2( _L("Camera =><= CCamAppController::SetTargetMode [%s] -> [%s]"), 
       
  1020           KCamModeNames[iInfo.iTargetMode],
       
  1021           KCamModeNames[aNewMode         ] );
       
  1022 
       
  1023   iInfo.iTargetMode = aNewMode;
       
  1024   }
       
  1025 
       
  1026 // ---------------------------------------------------------------------------
       
  1027 //
       
  1028 // ---------------------------------------------------------------------------
       
  1029 //
       
  1030 void 
       
  1031 CCamAppController::SetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1032   {
       
  1033   PRINT2( _L("Camera =><= CCamAppController::SetImageMode [%s] -> [%s]"), 
       
  1034           KCamImageModeNames[iInfo.iImageMode],
       
  1035           KCamImageModeNames[aNewMode        ] );
       
  1036 
       
  1037   iInfo.iImageMode = aNewMode;
       
  1038   // Notify ??
       
  1039   }
       
  1040 
       
  1041 
       
  1042 // ---------------------------------------------------------------------------
       
  1043 //
       
  1044 // ---------------------------------------------------------------------------
       
  1045 //
       
  1046 void 
       
  1047 CCamAppController::SetTargetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1048   {
       
  1049   PRINT2( _L("Camera =><= CCamAppController::SetTargetImageMode [%s] -> [%s]"), 
       
  1050           KCamImageModeNames[iInfo.iTargetImageMode],
       
  1051           KCamImageModeNames[aNewMode              ] );
       
  1052 
       
  1053   iInfo.iTargetImageMode = aNewMode;
       
  1054   }
       
  1055 
       
  1056 
       
  1057 // ---------------------------------------------------------------------------
       
  1058 //
       
  1059 // ---------------------------------------------------------------------------
       
  1060 //
       
  1061 void CCamAppController::SetOperation( TCamCaptureOperation aNewOperation, 
       
  1062                                       TInt                 aError /*= KErrNone*/ )
       
  1063   {
       
  1064   PRINT2( _L("Camera => CCamAppController::SetOperation: [%s] -> [%s]"), 
       
  1065           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1066           KCamCaptureOperationNames[aNewOperation   ] );
       
  1067     PERF_OPERATION_STATE_CHANGE( aNewOperation ); 
       
  1068     
       
  1069     if( iInfo.iOperation != aNewOperation 
       
  1070      || aError           != KErrNone ) 
       
  1071       {      
       
  1072       iInfo.iOperation = aNewOperation;
       
  1073       NotifyControllerObservers( ECamEventOperationStateChanged, aError );
       
  1074       }
       
  1075 
       
  1076   PRINT( _L("Camera <= CCamAppController::SetOperation") );
       
  1077   }
       
  1078 
       
  1079 
       
  1080 
       
  1081 // ---------------------------------------------------------------------------
       
  1082 // CCamAppController::ImagesRemaining
       
  1083 // Return the number of images that can still be saved
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //
       
  1086 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1087                                          TBool            aBurstActive )
       
  1088   {
       
  1089   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1090         ( iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoSize ) ); 
       
  1091 
       
  1092   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1093   }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // CCamAppController::ImagesRemaining
       
  1097 // Return the number of images that can still be saved
       
  1098 // ---------------------------------------------------------------------------
       
  1099 //
       
  1100 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1101                                          TBool            aBurstActive, 
       
  1102                                          TInt             aQualityIndex )
       
  1103   {
       
  1104   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1105         ( iSettingsModel->PhotoResolution( aQualityIndex ) );
       
  1106 
       
  1107   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1108   }
       
  1109 
       
  1110 // ---------------------------------------------------------------------------
       
  1111 // CCamAppController::ImagesRemaining
       
  1112 // Return the number of images that can still be saved
       
  1113 // ---------------------------------------------------------------------------
       
  1114 //
       
  1115 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1116                                          TBool            aBurstActive, 
       
  1117                                          TCamPhotoSizeId  aSize        )
       
  1118   {
       
  1119   PRINT( _L("Camera => CCamAppController::ImagesRemaining" ))
       
  1120   if ( ECamMediaStorageCurrent == aStorage )
       
  1121     {
       
  1122     TCamMediaStorage store_unfiltered = static_cast<TCamMediaStorage>
       
  1123         ( IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );    
       
  1124    
       
  1125     // check to see if the MMC has been removed and we are waiting on a storage switch note
       
  1126     // before we start returning the values for phone memory
       
  1127     if( ECamMediaStorageCard == store_unfiltered
       
  1128      && static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->IsMMCRemovedNotePending() 
       
  1129       )
       
  1130       {
       
  1131       PRINT( _L("Camera <= CCamAppController::ImagesRemaining mmc removed - returning 0" ))
       
  1132       return 0;// UI Behaves as if MMC is still memory in use, thus we return zero images remaining as MMC is removed
       
  1133       }                       
       
  1134 
       
  1135     // use current storage location
       
  1136     aStorage = static_cast<TCamMediaStorage>
       
  1137         ( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ); 
       
  1138     }
       
  1139   else
       
  1140     {
       
  1141     // use specified location
       
  1142     }
       
  1143         
       
  1144 
       
  1145   TInt remaining     = 0;
       
  1146   TInt criticalLevel = 0;
       
  1147 
       
  1148   PRINT( _L("Camera <> Get critical memory level.." ))
       
  1149   TRAPD( err, criticalLevel = GetCriticalMemoryLevelL( aStorage ) );
       
  1150   if( !err )
       
  1151     remaining = iConfiguration->ImagesRemaining( aStorage, aSize, criticalLevel, aBurstActive  );
       
  1152   
       
  1153   // There is a factor in cenrep that defined a correction factor in percent.
       
  1154   // This feature makes possible to define separate file size estimates in 
       
  1155   // burst capture mode.  100 = 100%, 50 = half of single capture size etc.
       
  1156   if ( aBurstActive ) 
       
  1157      {
       
  1158      TInt corrFactor = iConfigManager->BurstFileSizeEstimateFactor();
       
  1159      PRINT1( _L("Camera <> CCamAppController::ImagesRemaining, factor: %d"), corrFactor )
       
  1160      remaining = TInt( remaining * corrFactor / 100 );
       
  1161      }
       
  1162 
       
  1163   PRINT1( _L("Camera <= CCamAppController::ImagesRemaining, return:%d"), remaining )
       
  1164   return remaining;
       
  1165   }
       
  1166 
       
  1167 // ---------------------------------------------------------------------------
       
  1168 // CCamAppController::RecordTimeElapsed
       
  1169 // Return the length of video that has been recorded
       
  1170 // ---------------------------------------------------------------------------
       
  1171 //
       
  1172 TTimeIntervalMicroSeconds CCamAppController::RecordTimeElapsed() const
       
  1173     {
       
  1174     return iVideoTimeElapsed;
       
  1175     }
       
  1176 
       
  1177 // ---------------------------------------------------------------------------
       
  1178 // CCamAppController::RecordTimeElapsed
       
  1179 // Return the length of video that has been recorded
       
  1180 // ---------------------------------------------------------------------------
       
  1181 //
       
  1182 void CCamAppController::RecordTimeElapsed(TTimeIntervalMicroSeconds aElapsed )
       
  1183     {
       
  1184     iVideoTimeElapsed=aElapsed;
       
  1185     }
       
  1186 
       
  1187 // ---------------------------------------------------------------------------
       
  1188 // CCamAppController::RecordTimeRemaining
       
  1189 // Return the length of video that can still be saved
       
  1190 // ---------------------------------------------------------------------------
       
  1191 //
       
  1192 TTimeIntervalMicroSeconds 
       
  1193 CCamAppController::RecordTimeRemaining() 
       
  1194     {
       
  1195     PRINT( _L("Camera => CCamAppController::RecordTimeRemaining" ));
       
  1196     TTimeIntervalMicroSeconds remain( 0 );
       
  1197   
       
  1198     // All the time we get this information from the CaeEngine which is thru camera controller.
       
  1199 
       
  1200     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1201     if( appUi->SettingsLaunchedFromCamera() || iDismountPending )
       
  1202         {
       
  1203         // In case settings plugin is being run or mmc dismount is pending
       
  1204         // due to usb activation, we calculate the remaining time here, 
       
  1205         // instead of repreparing the engine and getting it from there  
       
  1206         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1207         if( KErrNone != err )
       
  1208             {
       
  1209             iVideoTimeRemaining = 0;
       
  1210             }
       
  1211         }
       
  1212     else
       
  1213         {    
       
  1214         if( iInfo.iOperation == ECamCapturing    ||
       
  1215             iInfo.iOperation == ECamPausing      ||
       
  1216             iInfo.iOperation == ECamPaused       ||
       
  1217             iInfo.iOperation == ECamResuming     ||
       
  1218             iInfo.iOperation == ECamCompleting )
       
  1219             {    
       
  1220             iVideoTimeRemaining = iCameraController->RemainingVideoRecordingTime();  
       
  1221             }
       
  1222         else 
       
  1223             {
       
  1224             PRINT( _L("Camera <> CCamAppController::RecordTimeRemaining - video mode not yet initialized" ));
       
  1225             TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1226             if( KErrNone != err )
       
  1227                 {
       
  1228                 iVideoTimeRemaining = 0;
       
  1229                 }
       
  1230             }
       
  1231         }
       
  1232    if ( ECamControllerVideo == CurrentMode() &&
       
  1233    	    ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) &&
       
  1234    	    appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) )
       
  1235         {
       
  1236         iVideoTimeRemaining =  0; 
       
  1237         }
       
  1238   
       
  1239     // if the storage location is MMC but the MMC is not accessible then
       
  1240     // return 0 time remaining
       
  1241     if ( appUi->IsMMCRemovedNotePending() )
       
  1242         {
       
  1243         // Return remaining time of zero, it will be reset when
       
  1244         // a card is reinserted or storage location is changed
       
  1245         PRINT( _L("Camera <> MMC note pending, return 0") );
       
  1246         }
       
  1247     else
       
  1248         {
       
  1249         // If the time we have is greater than the maximum allowed, return the
       
  1250         // maximum
       
  1251         TTimeIntervalMicroSeconds maxRecordingLength( static_cast<TInt64>(KMaxRecordingLength) );
       
  1252     
       
  1253         if ( iVideoTimeRemaining > maxRecordingLength )
       
  1254             {
       
  1255             remain = maxRecordingLength;
       
  1256             }
       
  1257         else
       
  1258             {
       
  1259             remain = iVideoTimeRemaining;
       
  1260             }
       
  1261         }
       
  1262 
       
  1263     PRINT1( _L("Camera <= CCamAppController::RecordTimeRemaining, %Ld" ), remain.Int64() );
       
  1264     return remain;
       
  1265     }
       
  1266 
       
  1267 // ---------------------------------------------------------------------------
       
  1268 // SetNoBurstCancel
       
  1269 //
       
  1270 //Set iNoBurstCancel flag which is used to prevent stopping burst
       
  1271 // when actual burst capture has started after focusing. Flag is
       
  1272 // used in CancelFocusAndCapture method.
       
  1273 // ---------------------------------------------------------------------------
       
  1274 //
       
  1275 void
       
  1276 CCamAppController::SetNoBurstCancel(TBool aValue )
       
  1277   {
       
  1278   PRINT1 ( _L("Camera =><= CCamAppController::SetNoBurstCancel, aValue=%d"),aValue );
       
  1279   	iNoBurstCancel=aValue;
       
  1280   }
       
  1281 
       
  1282 
       
  1283 // ---------------------------------------------------------------------------
       
  1284 // SoftStopBurstL
       
  1285 //
       
  1286 // Stop burst as soon as possible given the following constrains:
       
  1287 //   - if quick burst is ongoing, it's continued to the end, unless
       
  1288 //     aFastStop is true. Then the minimum of 2 images is allowed.
       
  1289 //     For "immediate" stop, StopSequenceCapture should be used.
       
  1290 //   - if press and hold burst is ongoing, stop after next image.
       
  1291 // ---------------------------------------------------------------------------
       
  1292 //
       
  1293 void
       
  1294 CCamAppController::SoftStopBurstL( TBool aFastStop /*=EFalse*/ )
       
  1295   {
       
  1296   PRINT ( _L("Camera => CCamAppController::SoftStopBurstL") );
       
  1297   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1298 
       
  1299   // Still in short burst mode, if
       
  1300   // a) no burst timer at all (long burst not supported)
       
  1301   // b) burst timer still ticking
       
  1302   // c) in self-timer initiated burst, which is always short burst.
       
  1303   TBool shortBurst = ( !iBurstTimer 
       
  1304                     ||  iBurstTimer->IsActive() 
       
  1305                     ||  appUi->SelfTimerEnabled() );
       
  1306 
       
  1307   PRINT1( _L("Camera <> CCamAppController::SoftStopBurstL .. is short burst: %d"), shortBurst );
       
  1308 
       
  1309   StopBurstTimer();
       
  1310 
       
  1311   if( iSequenceCaptureInProgress )
       
  1312     {
       
  1313     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst ongoing") );
       
  1314     if( aFastStop || !shortBurst )
       
  1315       {
       
  1316       // Camera controller takes care of setting "high enough" limit.
       
  1317       // SetCaptureLimitL takes care of setting right count to 
       
  1318       // stop as early as possible.
       
  1319       SetCaptureLimitL( 0 );
       
  1320       }
       
  1321     }
       
  1322   else if( ECamFocusing != iInfo.iOperation &&
       
  1323        !iAutoFocusRequested )
       
  1324     {
       
  1325     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst NOT ongoing, just cancel pending..") );
       
  1326     iCaptureRequested = EFalse;
       
  1327     }
       
  1328   PRINT ( _L("Camera <= CCamAppController::SoftStopBurstL") );
       
  1329   }
       
  1330 
       
  1331 // ---------------------------------------------------------------------------
       
  1332 // StartBurstTimerL
       
  1333 // ---------------------------------------------------------------------------
       
  1334 //
       
  1335 void
       
  1336 CCamAppController::StartBurstTimerL()
       
  1337   {
       
  1338   PRINT ( _L("Camera => CCamAppController::StartBurstTimerL") );
       
  1339   if( iBurstTimer )
       
  1340     {
       
  1341     StopBurstTimer();
       
  1342     }
       
  1343   else
       
  1344     {
       
  1345     TInt timeout( 0 );
       
  1346     User::LeaveIfError( CamUtility::GetPsiInt( ECamPsiLongCaptureKeyPressInterval, timeout ) );
       
  1347 
       
  1348     PRINT1( _L("Camera <> CCamAppController::StartBurstTimerL .. Creating timer with timeout value of [%d ms]"), timeout );
       
  1349 
       
  1350     // Multiply timeout by 1000 to get microseconds
       
  1351     TCallBack cb( CCamAppController::ShortBurstTimeout, this );
       
  1352     iBurstTimer = CCamTimer::NewL( timeout*1000, cb );
       
  1353     }
       
  1354 
       
  1355   PRINT ( _L("Camera <> CCamAppController::StartBurstTimerL .. Starting timer..") );
       
  1356   iBurstTimer->StartTimer();
       
  1357 
       
  1358   PRINT ( _L("Camera <= CCamAppController::StartBurstTimerL") );
       
  1359   }
       
  1360 
       
  1361 // ---------------------------------------------------------------------------
       
  1362 // StopBurstTimer
       
  1363 // ---------------------------------------------------------------------------
       
  1364 //
       
  1365 void
       
  1366 CCamAppController::StopBurstTimer()
       
  1367   {
       
  1368   PRINT( _L("Camera => CCamAppController::StopBurstTimer") );
       
  1369   if( iBurstTimer )
       
  1370     {
       
  1371     iBurstTimer->Cancel();
       
  1372     }
       
  1373   PRINT( _L("Camera <= CCamAppController::StopBurstTimer") );
       
  1374   }
       
  1375 
       
  1376 // ---------------------------------------------------------------------------
       
  1377 // ShortBurstTimeout
       
  1378 // ---------------------------------------------------------------------------
       
  1379 //
       
  1380 TInt 
       
  1381 CCamAppController::ShortBurstTimeout( TAny* aController )
       
  1382   {
       
  1383   PRINT( _L("Camera => CCamAppController::ShortBurstTimeout") );  
       
  1384 
       
  1385   CCamAppController* self = static_cast<CCamAppController*>( aController );
       
  1386   TRAP_IGNORE( self->DoShortBurstTimeoutL() );
       
  1387   
       
  1388   PRINT( _L("Camera <= CCamAppController::ShortBurstTimeout") );
       
  1389   return KErrNone; // no more callbacks
       
  1390   }
       
  1391 
       
  1392 
       
  1393 // ---------------------------------------------------------------------------
       
  1394 // DoShortBurstTimeoutL
       
  1395 // ---------------------------------------------------------------------------
       
  1396 //
       
  1397 void
       
  1398 CCamAppController::DoShortBurstTimeoutL()
       
  1399   {
       
  1400   PRINT( _L("Camera => CCamAppController::DoShortBurstTimeoutL") );
       
  1401   PRINT2( _L("Camera <> CCamAppController::DoShortBurstTimeoutL iInfo.iImageMode: %d, iSequenceCaptureInProgress: %d"), iInfo.iImageMode, iSequenceCaptureInProgress );
       
  1402   if( ECamImageCaptureBurst == iInfo.iImageMode 
       
  1403    && iSequenceCaptureInProgress )
       
  1404     {
       
  1405     TInt longBurstLimit( 0 );
       
  1406     CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, longBurstLimit );
       
  1407 
       
  1408     PRINT1( _L("Camera <> CCamAppController::DoShortBurstTimeoutL .. product long burst limit: %d"), longBurstLimit );  
       
  1409 
       
  1410     SetCaptureLimitL( longBurstLimit );
       
  1411     }
       
  1412 
       
  1413   PRINT( _L("Camera <= CCamAppController::DoShortBurstTimeoutL") );
       
  1414   }
       
  1415 
       
  1416 // ---------------------------------------------------------------------------
       
  1417 // Actual capture limit value.
       
  1418 // ---------------------------------------------------------------------------
       
  1419 //
       
  1420 TInt
       
  1421 CCamAppController::CaptureLimit() const
       
  1422   {
       
  1423   TInt limit( 1 );
       
  1424 
       
  1425   if( iCameraController && ECamImageCaptureBurst == iInfo.iImageMode )
       
  1426     {
       
  1427     limit = iCameraController->ControllerInfo().iCaptureLimit;
       
  1428     }
       
  1429 
       
  1430   return limit;
       
  1431   }
       
  1432 
       
  1433 // ---------------------------------------------------------------------------
       
  1434 // CaptureLimitSetting
       
  1435 //
       
  1436 // Stored for Setting Provider to give to Camera Controller.
       
  1437 // ---------------------------------------------------------------------------
       
  1438 //
       
  1439 TInt
       
  1440 CCamAppController::CaptureLimitSetting() const
       
  1441   {
       
  1442   TInt limit( 1 );
       
  1443 
       
  1444   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1445     {
       
  1446     limit = iRequestedCaptureCount;
       
  1447     }
       
  1448 
       
  1449   return limit;  
       
  1450   }
       
  1451 
       
  1452 // ---------------------------------------------------------------------------
       
  1453 // SetCaptureLimitL
       
  1454 // ---------------------------------------------------------------------------
       
  1455 //
       
  1456 void 
       
  1457 CCamAppController::SetCaptureLimitL( TInt aLimit )
       
  1458   {
       
  1459   PRINT1( _L("Camera => CCamAppController::SetCaptureLimitL .. requested limit: %d"), aLimit );
       
  1460 
       
  1461   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1462     {
       
  1463     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. burst mode active") );
       
  1464     // We give the total amount of images during burst, not the remaining ones.
       
  1465     // Need to subtract captures that have already been taken,
       
  1466     // before comparing to the disk limit.
       
  1467     if( iSequenceCaptureInProgress )
       
  1468       {
       
  1469       //TInt captured  = iCameraController->ControllerInfo().iCaptureCount;
       
  1470       TInt captured  = iCameraController->ControllerInfo().iSnapshotCount;
       
  1471       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. captured already: %d"), captured );
       
  1472 
       
  1473       if( aLimit > captured )
       
  1474         {
       
  1475         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. some more captures requested..") );
       
  1476 
       
  1477         // Check which is more restrictive - disk space or given limit.
       
  1478         TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1479         TInt remaining = Min( aLimit - captured, diskLimit );
       
  1480 
       
  1481         PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1482 
       
  1483         iRequestedCaptureCount = Max( KMinBurstCount, captured + remaining );
       
  1484         if ( diskLimit - KMinBurstCount < iRequestedCaptureCount ) 
       
  1485             {
       
  1486             // Estimated file size is not worst case estimate and long burst 
       
  1487             // sequence accumulates error, thus critical disk space limit may
       
  1488             // be reached. Requested capture count is decreased here if needed. 
       
  1489             iRequestedCaptureCount -= 
       
  1490                         (iRequestedCaptureCount+KMinBurstCount)/KBurstEstimate;
       
  1491             PRINT( _L("Camera <> CCamAppController::SetCaptureLimitL .. Near to critical level, adjust iRequestedCaptureCount"));
       
  1492             }
       
  1493         }
       
  1494       else
       
  1495         {
       
  1496         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. capturing should be stopped as soon as possible..") );
       
  1497         // Stop as fast as possible requested.
       
  1498         // Still need to request minimum of 2.
       
  1499         iRequestedCaptureCount = Max( KMinBurstCount, captured + 1 );
       
  1500         }
       
  1501       }
       
  1502     // Not capturing - adjust freely
       
  1503     else
       
  1504       {
       
  1505       TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1506       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1507 
       
  1508       iRequestedCaptureCount = Max( KMinBurstCount, Min( aLimit, diskLimit ) );
       
  1509       }
       
  1510 
       
  1511     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1512 
       
  1513     // In burst mode camera needs to be updated with the limit.
       
  1514     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  1515     }
       
  1516   else
       
  1517     {
       
  1518     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. single / timelapse mode active") );
       
  1519     TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, EFalse );
       
  1520     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1521 
       
  1522     iRequestedCaptureCount = Min( aLimit, diskLimit );
       
  1523 
       
  1524     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1525     }
       
  1526   PRINT ( _L("Camera <= CCamAppController::SetCaptureLimitL") );
       
  1527   }
       
  1528 // ---------------------------------------------------------------------------
       
  1529 // CCamAppController::SetTimeLapseInterval
       
  1530 // Updates the interval used in next TimeLapse capture
       
  1531 // ---------------------------------------------------------------------------
       
  1532 //
       
  1533 void CCamAppController::SetTimeLapseInterval( TTimeIntervalMicroSeconds aInterval )
       
  1534   {
       
  1535   iTimeLapseInterval = aInterval;
       
  1536   }
       
  1537 
       
  1538 // ---------------------------------------------------------------------------
       
  1539 // CCamAppController::TimeLapseInterval
       
  1540 // Returns the interval used in next TimeLapse capture
       
  1541 // ---------------------------------------------------------------------------
       
  1542 //   
       
  1543 TTimeIntervalMicroSeconds CCamAppController::TimeLapseInterval()
       
  1544   {    
       
  1545   return iTimeLapseInterval;
       
  1546   } 
       
  1547     
       
  1548 // ---------------------------------------------------------------------------
       
  1549 // CCamAppController::TimeLapseCountdown
       
  1550 // Returns the remaining time lapse interval until the next capture
       
  1551 // ---------------------------------------------------------------------------
       
  1552 // 
       
  1553 TTimeIntervalMicroSeconds CCamAppController::TimeLapseCountdown()
       
  1554   {
       
  1555   TInt64 remainingTime( 0 );    // Assume uninitialised start time
       
  1556   
       
  1557   // If the start time is uninitialised then the first capture is about to be initiated
       
  1558   if ( iTimeLapseStartTime == remainingTime )
       
  1559     {
       
  1560     return remainingTime;
       
  1561     }
       
  1562   // Otherwise, work out how much time is left before the next capture
       
  1563   TTime now;
       
  1564   now.HomeTime();
       
  1565   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  1566   remainingTime = Max ( remainingTime, iTimeLapseInterval.Int64() - elapsedTime.Int64() );   
       
  1567   return remainingTime;            
       
  1568   } 
       
  1569 
       
  1570 // ---------------------------------------------------------------------------
       
  1571 // CCamAppController::StartAutoFocus
       
  1572 // Start the autofocus procedure
       
  1573 // ---------------------------------------------------------------------------
       
  1574 //
       
  1575 void CCamAppController::StartAutoFocus()
       
  1576     {
       
  1577     PRINT (_L("Camera => CCamAppController::StartAutoFocus"));
       
  1578     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  1579     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  1580 
       
  1581     if( iConfigManager 
       
  1582      && iConfigManager->IsAutoFocusSupported()
       
  1583      && IsViewFinding() 
       
  1584      && !iAFCancelInProgress 
       
  1585      && ECamNoOperation == iInfo.iOperation )
       
  1586         {
       
  1587 
       
  1588         PRINT(_L("Camera <> Calling TryAutoFocus" ) );  
       
  1589         TryAutoFocus();        
       
  1590         }
       
  1591     PRINT(_L("Camera <= CCamAppController::StartAutoFocus"));
       
  1592     }
       
  1593 
       
  1594 // ---------------------------------------------------------------------------
       
  1595 // CCamAppController::Capture
       
  1596 // Begin the capture procedure
       
  1597 // ---------------------------------------------------------------------------
       
  1598 //
       
  1599 void CCamAppController::Capture()
       
  1600   {
       
  1601   PRINT2( _L("Camera => CCamAppController::Capture(), operation[%s], iSaving:%d"), 
       
  1602           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1603           iSaving );    
       
  1604 
       
  1605   // If the camera orientation changed during capture and not in burst mode, 
       
  1606   // set the new orientation
       
  1607   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  1608        && iOrientationChangeOccured
       
  1609        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  1610     {
       
  1611     iOrientationChangeOccured = EFalse;
       
  1612     TRAP_IGNORE( SetImageOrientationL() );
       
  1613     }
       
  1614     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && !iAccSensorListening )
       
  1615         {
       
  1616         // Delayed sensor initialization has not yet happened, but shutter key has been pressed.
       
  1617         // Force initialization now, causing an addition to shutter lag - this is a very
       
  1618         // rare case, as there should always be enough idle time to run the delayed
       
  1619         // initialization.  
       
  1620         TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  1621         }
       
  1622 
       
  1623   PERF_EVENT_END_L1( EPerfEventKeyToCapture );   
       
  1624 
       
  1625   // Set to EFalse for burst 
       
  1626   iAllSnapshotsReceived = EFalse;
       
  1627   
       
  1628   if ( ECamFocusing == iInfo.iOperation ||
       
  1629        iAFCancelInProgress ||
       
  1630        iAutoFocusRequested || IsAfNeeded() )
       
  1631     {
       
  1632     PRINT( _L("Camera <> Focusing going on, cannot start capture - setting iCaptureRequested" ) );
       
  1633     if( !IsAfNeeded() )
       
  1634         {
       
  1635         CancelAFNow();
       
  1636         }
       
  1637     iCaptureRequested = ETrue;    
       
  1638     } 
       
  1639   // -------------------------------------------------------
       
  1640   //Quick pressed capture key after backing to precapture from postcapture in burst mode
       
  1641   //Quick pressed capture key during cancelling autofocus(eg. backing to precapture from setting view ) 
       
  1642   else if ( ECamNoOperation == iInfo.iOperation
       
  1643     && ( ( ECamImageCaptureTimeLapse == iInfo.iImageMode ) 
       
  1644       || ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  1645       || ( ECamImageCaptureSingle == iInfo.iImageMode ) )      
       
  1646     && iAFCancelInProgress )
       
  1647     {
       
  1648     PRINT(_L("Camera <> Cancelling auto focus going on, cannot start capture - setting iCaptureRequested")); 
       
  1649     // delay the start of capture until cancelling autofocus has finished
       
  1650     iCaptureRequested = ETrue;
       
  1651     }    
       
  1652   // -------------------------------------------------------
       
  1653   // Quick pressed after capture, during image processing 
       
  1654   else if ( ECamCompleting         == iInfo.iOperation
       
  1655     && ECamImageCaptureSingle == iInfo.iImageMode )
       
  1656     {
       
  1657     PRINT(_L("Camera <> operation state is capture completing setting iCaptureRequested")); 
       
  1658      // delay the start of capture until current capture has finished
       
  1659     iCaptureRequested = ETrue;
       
  1660     }
       
  1661   // -------------------------------------------------------
       
  1662   // Ready for new shot
       
  1663   else if( ECamNoOperation == iInfo.iOperation 
       
  1664         || ECamFocused     == iInfo.iOperation
       
  1665         || ECamFocusFailed == iInfo.iOperation )
       
  1666     {
       
  1667     PRINT(_L("Camera <> operation state is no operation")); 
       
  1668     
       
  1669     // Update current capture mode
       
  1670 //    iInfo.iImageMode = CurrentImageModeSetup();
       
  1671 
       
  1672     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  1673         {
       
  1674         // If AF sound hasn't finished playing yet, stop it now
       
  1675         // to make sure it does not block capture sound playing.
       
  1676         iSoundPlayer->CancelPlaying( ECamAutoFocusComplete );
       
  1677         }
       
  1678     
       
  1679 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1680     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  1681       {       
       
  1682       // Do not log the single image start events in burst mode, as the end
       
  1683       // events would arrive for all images at once after all images have been taken
       
  1684       PERF_EVENT_START_L1( EPerfEventShotToSnapshot );  
       
  1685       PERF_EVENT_START_L1( EPerfEventShotToStillImageReady );  
       
  1686       PERF_EVENT_START_L1( EPerfEventShotToSave );
       
  1687       }
       
  1688     else
       
  1689       {
       
  1690       PERF_EVENT_START_L1( EPerfEventSequenceCapture ); 
       
  1691       }
       
  1692 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1693 
       
  1694     if( ECamImageCaptureTimeLapse == iInfo.iImageMode &&
       
  1695         !iSequenceCaptureInProgress )
       
  1696       {
       
  1697       // First image of timelapse, reset capture count  
       
  1698       iTimeLapseCaptureCount = 0;
       
  1699       }  
       
  1700 
       
  1701     if( iInfo.iImageMode == ECamImageCaptureNone )  
       
  1702         {
       
  1703         PRINT(_L("Camera <= CCamAppController::Capture() - request ignored")); 
       
  1704         return;
       
  1705         }
       
  1706 
       
  1707     // iCaptureRequested is reset in DoCaptureL
       
  1708     TBool capture = EFalse;
       
  1709     TInt err = KErrNone;
       
  1710     iFilenameReserved = EFalse;
       
  1711     TRAP( err, capture = DoCaptureL() );
       
  1712     if ( KErrNone != err )
       
  1713        {
       
  1714        // Sequence capture is not in progress as capture failed 
       
  1715        iSequenceCaptureInProgress = EFalse; 
       
  1716        }
       
  1717 
       
  1718     PRINT1( _L("Camera <> Tried to start capture, status:%d"), capture ); 
       
  1719     if ( capture )
       
  1720       {
       
  1721       if( ECamActiveCameraPrimary == iInfo.iActiveCamera
       
  1722           && iConfigManager && iConfigManager->IsCaptureToneDelaySupported() )
       
  1723         {
       
  1724         // first cancel to make sure
       
  1725         iCaptureToneDelayTimer->Cancel();
       
  1726         // delay playing of capture tone
       
  1727         iCaptureToneDelayTimer->StartTimer();
       
  1728         }
       
  1729       else
       
  1730         {
       
  1731         // Play capture sound
       
  1732         PlaySound( CaptureToneId(), EFalse );
       
  1733         }
       
  1734       }
       
  1735     }
       
  1736   // -------------------------------------------------------
       
  1737   // Not ready for a capture
       
  1738   else
       
  1739     {
       
  1740     // request ignored
       
  1741     }  
       
  1742   // -------------------------------------------------------
       
  1743   PRINT(_L("Camera <= CCamAppController::Capture()"));    
       
  1744   }
       
  1745 
       
  1746 
       
  1747 // ---------------------------------------------------------------------------
       
  1748 // CCamAppController::StopSequenceCaptureL
       
  1749 // Stop and complete the burst capture operation
       
  1750 // ---------------------------------------------------------------------------
       
  1751 //
       
  1752 void CCamAppController::StopSequenceCaptureL()
       
  1753   {
       
  1754   PRINT( _L("Camera => CCamAppController::StopSequenceCaptureL()") );
       
  1755 
       
  1756   iSequenceCaptureInProgress = EFalse;
       
  1757   iNoBurstCancel = EFalse;
       
  1758 
       
  1759   // Re-enable screen saver
       
  1760   EnableScreenSaver( ETrue );
       
  1761 
       
  1762   TCamImageCaptureMode captureModeSetup = CurrentImageModeSetup();
       
  1763   // Test that this method was not called in single capture mode
       
  1764   __ASSERT_DEBUG( captureModeSetup != ECamImageCaptureSingle, CamPanic( ECamPanicInvalidState ) );
       
  1765 
       
  1766   // If a burst sequence is currently active or has been requested
       
  1767   if ( iInfo.iImageMode == ECamImageCaptureBurst 
       
  1768     || ( captureModeSetup == ECamImageCaptureBurst && iCaptureRequested ) )
       
  1769     {
       
  1770     IssueDirectRequestL( ECamRequestImageCancel );
       
  1771     if ( iInfo.iOperation != ECamCapturing )
       
  1772       {
       
  1773       CompleteBurstOperation();
       
  1774       }
       
  1775     
       
  1776     }
       
  1777   // If a timelapse sequence is currently active or has been requested        
       
  1778   else if ( iInfo.iImageMode == ECamImageCaptureTimeLapse ||
       
  1779             ( captureModeSetup == ECamImageCaptureTimeLapse &&
       
  1780               iCaptureRequested ) )
       
  1781     {
       
  1782     if ( TimeLapseSupported() )
       
  1783       {
       
  1784       if ( iTimeLapseTimer )
       
  1785         {
       
  1786         iTimeLapseTimer->Cancel();
       
  1787         delete iTimeLapseTimer;
       
  1788         iTimeLapseTimer = NULL;
       
  1789         }
       
  1790 
       
  1791       // The current state is in between captures the next one has now been cancelled
       
  1792       // so just ensure that the view switch occurs           
       
  1793       // if ( iInfo.iOperation != ECamCapturing && !iCaptureRequested )
       
  1794       if ( iInfo.iOperation != ECamCapturing )
       
  1795         {
       
  1796         CompleteTimeLapseOperation();
       
  1797         } 
       
  1798       // Either the first capture is queued or a capture is still in stages of
       
  1799       // completion. Any future capture has been cancelled so all that remains is to ensure the
       
  1800       // completion code is run when the capture finally completes    
       
  1801       else
       
  1802         {
       
  1803         iCompleteTimeLapsePending = ETrue;
       
  1804         }
       
  1805       }
       
  1806     }
       
  1807   else // Otherwise there is no active or pending burst
       
  1808     {
       
  1809     // Do nothing
       
  1810     }
       
  1811 
       
  1812   PRINT( _L("Camera <= CCamAppController::StopSequenceCaptureL()") );
       
  1813   }
       
  1814 
       
  1815 
       
  1816 // ---------------------------------------------------------------------------
       
  1817 // CCamAppController::CapturePending
       
  1818 // Whether or not a capture is pending
       
  1819 // ---------------------------------------------------------------------------
       
  1820 //
       
  1821 TBool CCamAppController::CapturePending() const
       
  1822     {
       
  1823     // iOperation can be ECamFocusing but a 
       
  1824     // request to start still capture has been made and is waiting for the
       
  1825     // focus operation to complete
       
  1826     return iCaptureRequested;
       
  1827     }
       
  1828 
       
  1829 // ---------------------------------------------------------------------------
       
  1830 // CCamAppController::VideoRecordPending
       
  1831 // Whether or not video recording is pending
       
  1832 // ---------------------------------------------------------------------------
       
  1833 //
       
  1834 TBool CCamAppController::VideoRecordPending() const
       
  1835     {
       
  1836     // iOperation can be ECamFocusing but a 
       
  1837     // request to start video has been made and is waiting for the
       
  1838     // focus operation to complete
       
  1839     return iVideoRequested;
       
  1840     }
       
  1841 
       
  1842 // ---------------------------------------------------------------------------
       
  1843 // CCamAppController::SequenceCaptureInProgress
       
  1844 // Whether or not sequence capture is active
       
  1845 // ---------------------------------------------------------------------------
       
  1846 //
       
  1847 TBool CCamAppController::SequenceCaptureInProgress() const
       
  1848   {
       
  1849   return iSequenceCaptureInProgress;  
       
  1850   }
       
  1851 
       
  1852 // -----------------------------------------------------------------------------
       
  1853 // CCamAppController::StartVideoRecordingL
       
  1854 // Begin the video recording procedure
       
  1855 // -----------------------------------------------------------------------------
       
  1856 //
       
  1857 void CCamAppController::StartVideoRecordingL()
       
  1858   {
       
  1859   PRINT( _L("Camera => CCamAppController::StartVideoRecordingL") );    
       
  1860   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  1861   if( ECamControllerVideo == iInfo.iMode )
       
  1862     {
       
  1863     if( !iVideoRequested
       
  1864      &&  ECamNoOperation == iInfo.iOperation )
       
  1865       {
       
  1866       iVideoRequested = ETrue;     
       
  1867       if( !iSilentProfile || iShutterSndAlwaysOn  )
       
  1868         	{
       
  1869         	// Load (and play) the start video sound	
       
  1870         	PlaySound( ECamVideoStartSoundId , ETrue );  
       
  1871         	}   
       
  1872   
       
  1873       // initialise the array accessing values
       
  1874       iArrayUsageCount   = KVideoArrayUsers;
       
  1875       iCurrentImageIndex = 0;
       
  1876   
       
  1877       if( ECamMediaStorageCard == 
       
  1878               IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  1879         {
       
  1880         TRAPD( err, ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1881         if ( err )
       
  1882           {
       
  1883           PRINT( _L("Camera <> invalid MMC") );        
       
  1884           NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  1885   
       
  1886           // If we have got here, we can't access MMC. Switch to phone memory
       
  1887           TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  1888                                                  //this actually uses the internal mass memory
       
  1889           // Ignore for now, let fail when recording.
       
  1890           TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone, ETrue ) );
       
  1891           }
       
  1892         }
       
  1893       else
       
  1894         {
       
  1895         // Ignore for now, let fail when recording.
       
  1896         TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1897         }
       
  1898 
       
  1899         if( iSilentProfile && !iShutterSndAlwaysOn )
       
  1900         	{
       
  1901         	PlaySoundComplete();
       
  1902         	}
       
  1903       // Remember where are we recording
       
  1904       iInitialVideoStorageLocation = static_cast<TCamMediaStorage>( 
       
  1905                     IntegerSettingValue( ECamSettingItemVideoMediaStorage ) );
       
  1906       }
       
  1907     else
       
  1908       {
       
  1909       // Video already requested or other operation busy.
       
  1910       // Request ignored.
       
  1911       }
       
  1912     }
       
  1913   // Note: The code to actually START video recording has been moved
       
  1914   // to the PlaySoundComplete function so as to only start when
       
  1915   // sound playback has completed.
       
  1916   }
       
  1917 
       
  1918 // ---------------------------------------------------------------------------
       
  1919 // CCamAppController::StopVideoRecording
       
  1920 // End the video recording procedure
       
  1921 // ---------------------------------------------------------------------------
       
  1922 //
       
  1923 void 
       
  1924 CCamAppController::StopVideoRecording()
       
  1925   {
       
  1926   PRINT( _L("Camera => CCamAppController::StopVideoRecording") );
       
  1927   // if a video capture operation is pending
       
  1928   if ( iVideoRequested )
       
  1929       {
       
  1930       iVideoRequested = EFalse;
       
  1931       }
       
  1932   // otherwise, if a video recording operation is in progress or is paused
       
  1933   /*  else */
       
  1934   if ( ECamCapturing == CurrentVideoOperation() 
       
  1935          || ECamPaused    == CurrentVideoOperation() )
       
  1936     {
       
  1937     //  TRAPD( err, iAutoFocus->StopContinuousFocusL() );
       
  1938     //  iFocusLocked = EFalse;
       
  1939     // Keep track of the fact we are now in "saving" state
       
  1940     iSaving = ETrue;
       
  1941     TRAP_IGNORE( 
       
  1942       {
       
  1943       // IssueDirectRequestL( ECamRequestVfStop );
       
  1944       StopViewFinder(); 
       
  1945       IssueRequestL( ECamRequestVideoStop ); // Rest handled when event comes.
       
  1946       });
       
  1947     
       
  1948     StartIdleTimer();
       
  1949     }
       
  1950   else
       
  1951     {
       
  1952     // otherwise there is no current recording operation
       
  1953     }
       
  1954   PRINT( _L("Camera <= CCamAppController::StopVideoRecording") );
       
  1955   }
       
  1956 
       
  1957 // ---------------------------------------------------------------------------
       
  1958 // CCamAppController::StopVideoRecordingAsync
       
  1959 // End the video recording procedure asynchronously
       
  1960 // ---------------------------------------------------------------------------
       
  1961 //
       
  1962 void 
       
  1963 CCamAppController::StopVideoRecordingAsync()
       
  1964   {
       
  1965   PRINT( _L("Camera => CCamAppController::StopVideoRecordingAsync") );
       
  1966   
       
  1967   // Change CAE and MMF mode to async
       
  1968   TRAP_IGNORE( IssueRequestL( ECamRequestSetAsyncVideoStopMode ) ); 
       
  1969   StopVideoRecording();  // Call normal stop, mode is set to sync in call-backs
       
  1970 
       
  1971   PRINT( _L("Camera <= CCamAppController::StopVideoRecordingAsync") );
       
  1972   }
       
  1973 
       
  1974 // ---------------------------------------------------------------------------
       
  1975 // HandleVideoAsyncStopEvent
       
  1976 // ---------------------------------------------------------------------------
       
  1977 //
       
  1978 void
       
  1979 CCamAppController::HandleVideoAsyncStopEvent( TInt aStatus )
       
  1980   {
       
  1981   PRINT1( _L( "Camera => CCamAppController::HandleVideoAsyncStopEvent, status:%d" ), aStatus );
       
  1982   (void)aStatus; // remove compiler warning
       
  1983   
       
  1984   // We DO NOT play the stop sound when recording stopped due to
       
  1985   // an incoming call.  UI Spec 1.0, 4.4.1.
       
  1986   if ( !iInCallOrRinging 
       
  1987     && !iVideoStoppedForPhoneApp )
       
  1988     {
       
  1989     PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  1990     }
       
  1991 
       
  1992   // Recording completed, so we can re-enable key sounds
       
  1993   iSoundPlayer->EnableAllKeySounds();
       
  1994     
       
  1995   PRINT( _L( "Camera <= CCamAppController::HandleVideoAsyncStopEvent" ) );
       
  1996   }
       
  1997 
       
  1998 // ---------------------------------------------------------------------------
       
  1999 // HandleVideoStopEvent
       
  2000 // ---------------------------------------------------------------------------
       
  2001 //
       
  2002 void
       
  2003 CCamAppController::HandleVideoStopEvent( TInt aStatus )
       
  2004   {
       
  2005   PRINT1( _L( "Camera => CCamAppController::HandleVideoStopEvent, status:%d" ), aStatus );
       
  2006     
       
  2007   PERF_EVENT_END_L1( EPerfEventVideoStopToSave );        
       
  2008         
       
  2009   if ( KErrDiskFull   == aStatus 
       
  2010     || KErrCompletion == aStatus)
       
  2011     {
       
  2012     // if recording ends due to disk full condition or end of
       
  2013     // specified recording period do not propogate the error
       
  2014     aStatus = KErrNone;
       
  2015     }
       
  2016     // Play sound here if async mode is not supported
       
  2017     // If it is then next playing is copyed to HandleVideoAsyncStopEvent
       
  2018     if ( iCameraController && !iCameraController->AsyncVideoStopModeSupported() )
       
  2019         {
       
  2020         // We DO NOT play the stop sound when recording stopped due to
       
  2021         // an incoming call.  UI Spec 1.0, 4.4.1.
       
  2022         if ( !iInCallOrRinging 
       
  2023             && !iVideoStoppedForPhoneApp )
       
  2024             {
       
  2025             PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  2026             }
       
  2027 
       
  2028         // Recording completed, so we can re-enable key sounds
       
  2029         iSoundPlayer->EnableAllKeySounds();
       
  2030         }
       
  2031   // Keep track of the fact we are now leaving saving state
       
  2032   iSaving = EFalse;
       
  2033   
       
  2034   // try closing video record to free up resources
       
  2035   // Test - <eo> commented out, no such direct request supported
       
  2036   // TRAP_IGNORE( IssueDirectRequestL( ECamRequestVideoRelease ) );
       
  2037   
       
  2038   // if video post capture is off then force re-prepare so
       
  2039   // that remaining record time is updated
       
  2040   // REMOVED
       
  2041 
       
  2042   // if using direct viewfinding pause viewfinder
       
  2043   // REMOVED
       
  2044 
       
  2045   // report to LifeBlog
       
  2046   RProperty::Set( KPSUidCamcorderNotifier, KCamLatestFilePath, iSuggestedVideoPath ); 
       
  2047   // Add to album if this is enabled for videos
       
  2048   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  2049               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));       
       
  2050   if ( iSettingsModel->IntegerSettingValue
       
  2051                      ( ECamSettingItemVideoStoreInAlbum ) == ECamSettYes )
       
  2052     {
       
  2053     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, ETrue, defaultAlbumId );
       
  2054     }
       
  2055   else // Harvest the file but dont add to the default album
       
  2056     {
       
  2057     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, EFalse, defaultAlbumId );
       
  2058     }
       
  2059 
       
  2060   //create thumbnail
       
  2061   if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  2062       {
       
  2063       TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  2064       }
       
  2065   NotifyControllerObservers( ECamEventRecordComplete,   aStatus );
       
  2066   SetOperation( ECamNoOperation );
       
  2067   PRINT( _L( "Camera <> calling HandleCaptureCompletion.." ) )        
       
  2068   HandleCaptureCompletion();
       
  2069   NotifyControllerObservers( ECamEventMediaFileChanged, aStatus );
       
  2070   PRINT( _L( "Camera <= CCamAppController::HandleVideoStopEvent" ) );
       
  2071   }
       
  2072 
       
  2073     
       
  2074 // ---------------------------------------------------------------------------
       
  2075 // CCamAppController::SetVideoStoppedForPhoneApp
       
  2076 // Store the cause of the video stopping
       
  2077 // ---------------------------------------------------------------------------
       
  2078 //
       
  2079 void 
       
  2080 CCamAppController::SetVideoStoppedForPhoneApp( TBool aIsPhoneApp )
       
  2081   {
       
  2082   iVideoStoppedForPhoneApp = aIsPhoneApp;
       
  2083   }
       
  2084     
       
  2085 
       
  2086 // ---------------------------------------------------------------------------
       
  2087 // CCamAppController::PauseVideoRecording
       
  2088 // Pause the video recording procedure
       
  2089 // ---------------------------------------------------------------------------
       
  2090 //
       
  2091 void CCamAppController::PauseVideoRecording()
       
  2092     {
       
  2093     PRINT( _L("Camera => CCamAppController::PauseVideoRecording") );
       
  2094     if( ECamCapturing == CurrentVideoOperation() )
       
  2095         {
       
  2096         TRAPD( error, IssueRequestL( ECamRequestVideoPause ) );
       
  2097         if( KErrNone != error )
       
  2098             {
       
  2099             PRINT( _L("Camera <> PAUSING FAILED!!") );
       
  2100             }
       
  2101         else
       
  2102             {
       
  2103             // start video pause timeout
       
  2104             StartIdleTimer();
       
  2105             }
       
  2106         }  
       
  2107     PRINT( _L("Camera <= CCamAppController::PauseVideoRecording") );
       
  2108     }
       
  2109 
       
  2110 
       
  2111 // ---------------------------------------------------------------------------
       
  2112 // CCamAppController::ContinueVideoRecording
       
  2113 // Continue the video recording procedure
       
  2114 // ---------------------------------------------------------------------------
       
  2115 //
       
  2116 void CCamAppController::ContinueVideoRecording()
       
  2117   {
       
  2118   PRINT( _L("Camera => CCamAppController::ContinueVideoRecording") );
       
  2119   if ( ECamPaused == CurrentVideoOperation() )
       
  2120     {
       
  2121     SetOperation( ECamResuming );
       
  2122     // Restart video when sound played
       
  2123     PlaySound( ECamVideoResumeSoundId, ETrue );        
       
  2124     }
       
  2125   PRINT( _L("Camera <= CCamAppController::ContinueVideoRecording") );
       
  2126   }
       
  2127 
       
  2128 // ---------------------------------------------------------------------------
       
  2129 // CCamAppController::TryAFRequest
       
  2130 // issue AF request if there are no pending AF requests currently
       
  2131 // ---------------------------------------------------------------------------
       
  2132 //
       
  2133 TBool CCamAppController::TryAFRequest( TInt aAFRequest ) 
       
  2134   {
       
  2135   PRINT( _L( "Camera => TryAFRequest") );
       
  2136   PRINT3( _L( "iPendingAFRequest=%d aAFRequest=%d ,iCurrentAFRequest=%d"), iPendingAFRequest,
       
  2137     aAFRequest, iCurrentAFRequest );
       
  2138   switch( aAFRequest )
       
  2139     {    
       
  2140     case  ECamRequestCancelAutofocus:
       
  2141     case ECamRequestStartAutofocus:
       
  2142         {
       
  2143         if(iPendingAFRequest==0)
       
  2144             {
       
  2145             if ( !( UiConfigManagerPtr()->IsContinuosAutofocusSupported()&& ECamControllerVideo == CurrentMode() ) ) 
       
  2146                             {
       
  2147             iPendingAFRequest=aAFRequest;
       
  2148             TRAPD( err, IssueDirectRequestL( TCamCameraRequestId(aAFRequest) ) );
       
  2149             //TRAPD( err, iCameraController->DirectRequestL( aAFRequest ) );            
       
  2150             if ( err != KErrNone )
       
  2151                 {
       
  2152                 // There is an error, we leave without focusing
       
  2153                 iPendingAFRequest=0;
       
  2154                 return EFalse; // Not doing any autofocus request.
       
  2155                 //This is only case where AFrequest cause EFalse to be returned.
       
  2156                 }
       
  2157             }
       
  2158             }
       
  2159         else
       
  2160             {
       
  2161             CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2162             if ( appUi->AlwaysDrawPreCaptureCourtesyUI()
       
  2163                 && !CurrentSceneHasForcedFocus() )
       
  2164                 {
       
  2165                 appUi->SetActivePaletteVisibility( EFalse );
       
  2166                 }
       
  2167             iPendingAFRequest=aAFRequest;
       
  2168             }
       
  2169         }
       
  2170         break;
       
  2171     default:
       
  2172         {
       
  2173         //Not type of autofocus request. Ignoring.
       
  2174         }
       
  2175         break;    
       
  2176     }
       
  2177   PRINT( _L( "Camera <= TryAFRequest") );
       
  2178   return ETrue;              
       
  2179   }
       
  2180 
       
  2181 // ---------------------------------------------------------------------------
       
  2182 // CCamAppController::CancelAFNow
       
  2183 // Cancel AutoFocus 
       
  2184 // ---------------------------------------------------------------------------
       
  2185 //
       
  2186 void CCamAppController::CancelAFNow()
       
  2187   {    
       
  2188   PRINT( _L("Camera => CCamAppController::CancelAfNow()") );
       
  2189   
       
  2190   if( !iAFCancelInProgress && ECamFocusing == CurrentOperation() ) 
       
  2191     {
       
  2192     TRAPD( err, IssueDirectRequestL( ECamRequestCancelAutofocus ) );          
       
  2193     if( KErrNone == err ) 
       
  2194       {
       
  2195       iAFCancelInProgress = ETrue;  
       
  2196       iCurrentAFRequest = ECamRequestCancelAutofocus;      
       
  2197       iPendingAFRequest = ECamRequestCancelAutofocus;
       
  2198       }
       
  2199     }
       
  2200   else 
       
  2201     {
       
  2202     PRINT( _L("AF Cancel already in progress or not focusing") );
       
  2203     }   
       
  2204     
       
  2205   PRINT( _L("Camera <= CCamAppController::CancelAfNow()") );
       
  2206   }
       
  2207 // CCamAppController::CancelFocusAndCapture
       
  2208 // Cancel the focus and capture procedures
       
  2209 // ---------------------------------------------------------------------------
       
  2210 //
       
  2211 void CCamAppController::CancelFocusAndCapture()
       
  2212   {
       
  2213   PRINT( _L( "Camera => CCamAppController::CancelFocusAndCapture") );            
       
  2214   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  2215   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  2216   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2217   // Only cancels autofocus if needed, burst capture is no longer
       
  2218   // stopped if capture key pressed during burst
       
  2219   
       
  2220   if( !iNoBurstCancel 
       
  2221    && ECamNoOperation != CurrentOperation()
       
  2222    && ECamCompleting  != CurrentOperation() )
       
  2223     {  
       
  2224     // If we are currently focused, cancel autofocus
       
  2225     if ( IsViewFinding() && CurrentOperation() != ECamCapturing ) // Cannot do AF operations if VF not on. AF is anyway cancelled on VF start event.
       
  2226       {
       
  2227       if( ECamFocusing == CurrentOperation() )
       
  2228         {
       
  2229         CancelAFNow();
       
  2230         if ( IsTouchScreenSupported() )
       
  2231             {
       
  2232             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  2233             if ( fixedToolbar )
       
  2234               {
       
  2235               fixedToolbar->SetToolbarVisibility( ETrue );
       
  2236               }        
       
  2237             }
       
  2238         }   
       
  2239       else 
       
  2240         {
       
  2241         TryAFRequest( ECamRequestCancelAutofocus );
       
  2242         }
       
  2243       }
       
  2244     iCaptureRequested = EFalse;
       
  2245     }
       
  2246   PRINT( _L( "Camera <= CCamAppController::CancelFocusAndCapture") );            
       
  2247   }
       
  2248 
       
  2249 
       
  2250 // ---------------------------------------------------------------------------
       
  2251 // CCamAppController::SnapshotImage
       
  2252 // Get post-exposure snapshot bitmap, if available.
       
  2253 //
       
  2254 // Returns: pointer to post-exposure snapshot bitmap. Does not transfer ownership.
       
  2255 //          May be NULL if no image available.
       
  2256 // 
       
  2257 // ---------------------------------------------------------------------------
       
  2258 //
       
  2259 const CFbsBitmap* 
       
  2260 CCamAppController::SnapshotImage() const
       
  2261   {
       
  2262   PRINT ( _L("Camera => CCamAppController::SnapshotImage") ); 
       
  2263   PRINT1( _L("Camera <> CCamAppController::SnapshotImage .. current image index: %d"), iCurrentImageIndex ); 
       
  2264   PRINT1( _L("Camera => CCamAppController::SnapshotImage .. saved current image: %d"), SavedCurrentImage() ); 
       
  2265 
       
  2266   //Sometime burst capture array includes more than one image in single capture mode, 
       
  2267   //so just display the latest image here.
       
  2268   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2269   if ( BurstCaptureArray()->Count() > 1 && !appUi->IsBurstEnabled() )
       
  2270       {
       
  2271       TInt currentImageIndex = BurstCaptureArray()->Count() - 1;
       
  2272       const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( currentImageIndex );
       
  2273       PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2274       return ss;
       
  2275       }
       
  2276 
       
  2277   const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( iCurrentImageIndex );
       
  2278   PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2279   return ss;
       
  2280   }
       
  2281 
       
  2282 
       
  2283 // ---------------------------------------------------------------------------
       
  2284 // CCamAppController::SetAsCurrentImage
       
  2285 // Sets the specified index as the "current image", as will be used by the 
       
  2286 // post capture view
       
  2287 // ---------------------------------------------------------------------------
       
  2288 //
       
  2289 void 
       
  2290 CCamAppController::SetAsCurrentImage( TInt aIndex )
       
  2291   {
       
  2292   iCurrentImageIndex = aIndex;
       
  2293   }
       
  2294 
       
  2295 // ---------------------------------------------------------------------------
       
  2296 // CCamAppController::CurrentImageName
       
  2297 // Get the user-visible name for the current image 
       
  2298 // used in post-capture views.
       
  2299 // ---------------------------------------------------------------------------
       
  2300 //
       
  2301 const TDesC& 
       
  2302 CCamAppController::CurrentImageName() const
       
  2303   {
       
  2304   return BurstCaptureArray()->ImageName( iCurrentImageIndex );
       
  2305   }
       
  2306 
       
  2307 // ---------------------------------------------------------------------------
       
  2308 // CCamAppController::BurstCaptureArray
       
  2309 // Return a pointer to the array representing a burst capture
       
  2310 // ---------------------------------------------------------------------------
       
  2311 //
       
  2312 CCamBurstCaptureArray* 
       
  2313 CCamAppController::BurstCaptureArray() const
       
  2314   {
       
  2315   return iCaptureArray;
       
  2316   }        
       
  2317 
       
  2318 // ---------------------------------------------------------------------------
       
  2319 // CCamAppController::CurrentItemCount
       
  2320 // Return the count of non-deleted items in the burst array
       
  2321 // ---------------------------------------------------------------------------
       
  2322 //
       
  2323 TInt 
       
  2324 CCamAppController::CurrentItemCount()
       
  2325   {
       
  2326   if ( !BurstCaptureArray() )
       
  2327     {
       
  2328     return 0;
       
  2329     }
       
  2330   return BurstCaptureArray()->ImagesRemaining();
       
  2331   }
       
  2332 
       
  2333 // ---------------------------------------------------------------------------
       
  2334 // CCamAppController::CurrentCapturedCount
       
  2335 // Return the count of burst capture moments that have taken
       
  2336 // place in a current burst
       
  2337 // ---------------------------------------------------------------------------
       
  2338 //    
       
  2339 TInt 
       
  2340 CCamAppController::CurrentCapturedCount()
       
  2341   {
       
  2342   //return iActualBurstCount;
       
  2343   TInt count( 0 );
       
  2344   if( iCameraController )
       
  2345     {
       
  2346     // Using snapshot as count, because UI updates counter
       
  2347     // on snapshot events.
       
  2348     count = iCameraController->ControllerInfo().iSnapshotCount;
       
  2349     }
       
  2350   return count;  
       
  2351   }
       
  2352 
       
  2353 // ---------------------------------------------------------------------------
       
  2354 // CCamAppController::TimeLapseImageCount
       
  2355 // Return the count of items in the timelapse sequence array
       
  2356 // ---------------------------------------------------------------------------
       
  2357 //    
       
  2358 TInt 
       
  2359 CCamAppController::TimeLapseImageCount()
       
  2360   {
       
  2361   return iTimeLapseCaptureCount;
       
  2362   }
       
  2363 
       
  2364 // ---------------------------------------------------------------------------
       
  2365 // CCamAppController::ResetTimelapseArray
       
  2366 // Resets the timelapse sequence array
       
  2367 // ---------------------------------------------------------------------------
       
  2368 //    
       
  2369 void CCamAppController::ResetTimelapseArray()
       
  2370   {
       
  2371   iSequenceFilenameArray->Reset();
       
  2372   }
       
  2373 
       
  2374 // ---------------------------------------------------------------------------
       
  2375 // CCamAppController::PlaySound
       
  2376 // Play a sound with given id.
       
  2377 // ---------------------------------------------------------------------------
       
  2378 //
       
  2379 void CCamAppController::PlaySound( TCamSoundId aSoundId, TBool aEnableCallback )
       
  2380     {
       
  2381     PRINT1( _L("Camera => CCamAppController::PlaySound %d"), aSoundId );
       
  2382     if ( ToneShouldBeSilent( aSoundId ) &&
       
  2383          !iShutterSndAlwaysOn && 
       
  2384          iSilentProfile )
       
  2385         {
       
  2386         PRINT( _L("Camera <> Profile silent, do not play sound") );  
       
  2387         // Don't play shutter sound if we are following
       
  2388         // current profile setting and profile is silent.
       
  2389         // Notify the observer right away. E.g. video start
       
  2390         // depends on the notification
       
  2391         if( aEnableCallback )
       
  2392           {
       
  2393           PlayComplete( aSoundId, KErrNone );
       
  2394           }
       
  2395         /* OLD
       
  2396         if ( aSoundId == ECamVideoStartSoundId ||
       
  2397              aSoundId == ECamVideoPauseSoundId ||
       
  2398              aSoundId == ECamVideoResumeSoundId )
       
  2399             {
       
  2400             // Force the callback to start recording without sound.
       
  2401             PlaySoundComplete();
       
  2402             }
       
  2403         */
       
  2404         }
       
  2405     else
       
  2406         {
       
  2407         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUND, "e_CAM_APP_CAPTURE_SOUND_PLAY 1" );   //CCORAPP_CAPTURE_SOUND_PLAY_START
       
  2408         iSoundPlayer->CancelAllPlaying();
       
  2409         iSoundPlayer->PlaySound( aSoundId, aEnableCallback ); 
       
  2410 
       
  2411         }
       
  2412         
       
  2413     // If in timelapse mode the remaining time counter should be updated
       
  2414     // as soon as the capture tone has played, but as there is no callback
       
  2415     // this is the closest we can get            
       
  2416     if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )  
       
  2417         {
       
  2418         NotifyControllerObservers( ECamEventCounterUpdated );   
       
  2419         }       
       
  2420         
       
  2421     PRINT( _L("Camera <= CCamAppController::PlaySound") );                 
       
  2422     }
       
  2423 
       
  2424 
       
  2425 // ---------------------------------------------------------------------------
       
  2426 // CCamAppController::PlayTone
       
  2427 // Play a tone with specified frequency, period and volume
       
  2428 // ---------------------------------------------------------------------------
       
  2429 //
       
  2430 void CCamAppController::PlayTone( TInt      aToneHz, 
       
  2431                                   TInt      aLenMicSec, 
       
  2432                                   TReal32   aVolume, 
       
  2433                                   TBool     aEnableCallback )
       
  2434   {    
       
  2435   if ( !iShutterSndAlwaysOn && 
       
  2436      iSilentProfile )
       
  2437     {
       
  2438     // don't play shutter sound if we are following
       
  2439     // current profile setting and profile is silent
       
  2440     }
       
  2441   else
       
  2442     {    
       
  2443     iSoundPlayer->PlayTone( aToneHz, aLenMicSec, aVolume, aEnableCallback );
       
  2444     }
       
  2445   }
       
  2446 
       
  2447 // ---------------------------------------------------------------------------
       
  2448 // CCamAppController::AllOptionsVisibleForSettingItem
       
  2449 // Returns true if all the settings list options for a particular setting
       
  2450 // item are visible.
       
  2451 // ---------------------------------------------------------------------------
       
  2452 //
       
  2453 TBool CCamAppController::AllOptionsVisibleForSettingItem( TInt aSettingItem, 
       
  2454                                                     TInt& aRevisedResourceId )
       
  2455   {
       
  2456   if ( ( aSettingItem == ECamSettingItemVideoQuality ) && 
       
  2457        ( iInfo.iActiveCamera == ECamActiveCameraSecondary ) )
       
  2458     {
       
  2459     aRevisedResourceId = ROID(R_CAM_FRONT_CAMERA_VIDEO_QUALITY_TEXT_ARRAY);
       
  2460     return EFalse;
       
  2461     }
       
  2462   // Otherwise, all options are visible for the setting item
       
  2463   return ETrue;
       
  2464   }
       
  2465 
       
  2466 // ----------------------------------------------------
       
  2467 // CCamAppController::SwitchCameraL
       
  2468 // Switch the camera
       
  2469 // ----------------------------------------------------
       
  2470 //
       
  2471 void CCamAppController::SwitchCameraL()
       
  2472   {
       
  2473   PRINT( _L("Camera => CCamAppController::SwitchCameraL") );
       
  2474 
       
  2475   TCamAppControllerInfo oldInfo      = iInfo;
       
  2476   TCamActiveCamera      targetCamera = ECamActiveCameraNone;
       
  2477   // If something goes wrong when changing from 2nd to 1st camera,
       
  2478   // we need to make sure, that 2nd cam settings are not stored 
       
  2479   // to CR by accident.
       
  2480   iInfo = TCamAppControllerInfo(); // reset
       
  2481   
       
  2482   // reset zoom waiting flag. this flag is only used with bitmap viewfinder
       
  2483   // and it might cause problems if one camera uses bitmap viewfinder and the
       
  2484   // other one uses direct viewfinder
       
  2485   iZoomWaitingForCamera = EFalse;
       
  2486 
       
  2487   CancelPreviewChangesL();
       
  2488 
       
  2489   if( ECamActiveCameraPrimary == oldInfo.iActiveCamera )
       
  2490     {
       
  2491     // Currently using primary camera, switch to secondary
       
  2492     PRINT( _L("Camera <> switch to 2nd cam") );
       
  2493  
       
  2494 #ifdef _DEBUG
       
  2495     PRINT ( _L("Camera <> ======================================") );
       
  2496     PRINT ( _L("Camera <> Photo quality index:                  ") );
       
  2497     PRINT1( _L("Camera <> Before loading 2nd cam settings: %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2498 #endif
       
  2499 
       
  2500     LoadSecondaryCameraSettingsL();
       
  2501   
       
  2502 #ifdef _DEBUG
       
  2503     PRINT1( _L("Camera <> After loading 2nd cam settings:  %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2504     PRINT ( _L("Camera <> ======================================") );
       
  2505 #endif
       
  2506 
       
  2507     targetCamera = ECamActiveCameraSecondary;
       
  2508     }
       
  2509   else
       
  2510     {
       
  2511     // Currently using secondary camera, switch to primary
       
  2512     // or landscape secondary camera  
       
  2513     PRINT( _L("Camera <> switch to 1st camera or change 2nd camera mode") )
       
  2514     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2515     if( appUi->IsEmbedded() )
       
  2516         {
       
  2517         LoadStaticSettingsL( appUi->IsEmbedded() );
       
  2518         }
       
  2519     else if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2520         {
       
  2521         iSettingsModel->RestorePrimaryCameraSettingsL();
       
  2522         }
       
  2523 
       
  2524     if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2525         {
       
  2526         PRINT( _L("Camera <> switch to 1st cam") )
       
  2527         targetCamera = ECamActiveCameraPrimary;
       
  2528         }
       
  2529     else
       
  2530         {
       
  2531         PRINT( _L("Camera <> change 2nd camera mode") )
       
  2532         targetCamera = ECamActiveCameraSecondary;
       
  2533         }
       
  2534     }	            
       
  2535   SetCameraSwitchRequired( ESwitchDone );  
       
  2536   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2537   iCameraController->SwitchCameraL( (ECamActiveCameraPrimary == targetCamera) ? 0 : 1 );
       
  2538   iCameraController->CompleteSwitchCameraL();
       
  2539 
       
  2540   // Camera switched.
       
  2541   // a) Set current camera index to the new one.
       
  2542   // b) Set target mode (video/image) to the one before mode switch.
       
  2543   // c) Image mode is single shot after camera switch
       
  2544   // d) Ensure vf start
       
  2545   iInfo.iActiveCamera    = targetCamera; // a)
       
  2546   iInfo.iTargetMode      = appUi->TargetMode(); // b)
       
  2547   iInfo.iTargetImageMode = ( ECamControllerVideo==iInfo.iTargetMode )
       
  2548                          ? ECamImageCaptureNone : ECamImageCaptureSingle; // c)
       
  2549   iInfo.iTargetVfState   = ECamTriActive; // d)
       
  2550   if( oldInfo.iMode != ECamControllerShutdown )
       
  2551   	{
       
  2552   	IssueModeChangeSequenceL();
       
  2553   	}
       
  2554   	
       
  2555   appUi->SetDrawPreCaptureCourtesyUI( ETrue );
       
  2556 
       
  2557   NotifyControllerObservers( ECamEventCameraChanged );
       
  2558 
       
  2559   PRINT( _L("Camera <= CCamAppController::SwitchCameraL") );
       
  2560   }
       
  2561 
       
  2562 // ---------------------------------------------------------------------------
       
  2563 // CCamAppController::ActiveCamera
       
  2564 // Returns the active camera
       
  2565 // ---------------------------------------------------------------------------
       
  2566 //
       
  2567 TCamActiveCamera 
       
  2568 CCamAppController::ActiveCamera() const
       
  2569   {
       
  2570   return iInfo.iActiveCamera;
       
  2571   }
       
  2572 
       
  2573 // ---------------------------------------------------------------------------
       
  2574 // CCamAppController::CameraSwitchQueued
       
  2575 // Returns whether a camera switch is pending
       
  2576 // ---------------------------------------------------------------------------
       
  2577 //
       
  2578 TCameraSwitchRequired 
       
  2579 CCamAppController::CameraSwitchQueued() const   
       
  2580   {
       
  2581   PRINT1( _L("Camera =><= CCamAppController::CameraSwitchQueued %d"), iCameraSwitchRequired )
       
  2582   return iCameraSwitchRequired;
       
  2583   }
       
  2584 
       
  2585 // ---------------------------------------------------------------------------
       
  2586 // CCamAppController::CheckExitStatus
       
  2587 // Check whether exit is required
       
  2588 // ---------------------------------------------------------------------------
       
  2589 //
       
  2590 TBool 
       
  2591 CCamAppController::CheckExitStatus()
       
  2592   {
       
  2593   PRINT( _L("Camera => CCamAppController::CheckExitStatus" ) )
       
  2594   TBool exit = EFalse;
       
  2595   if ( iEndKeyWaiting )
       
  2596       {
       
  2597       exit = ETrue;
       
  2598       }   
       
  2599   else if ( iConfigManager  && iConfigManager->IsLensCoverSupported() )
       
  2600       {
       
  2601       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2602 
       
  2603       if ( iSliderCloseEvent && !appUi->IsEmbedded() && !appUi->Embedding() )
       
  2604           {
       
  2605           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - slider closed, not embedded/embedding" ) )
       
  2606           exit = ETrue;
       
  2607           }
       
  2608       else
       
  2609           {
       
  2610           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - embedded/embedding, not exiting" ) )
       
  2611           exit = EFalse;
       
  2612           }
       
  2613       }
       
  2614   else
       
  2615       {
       
  2616       exit = EFalse;
       
  2617       }
       
  2618 
       
  2619   PRINT1( _L("Camera <= CCamAppController::CheckExitStatus - return %d" ), exit )
       
  2620   return exit;
       
  2621   }
       
  2622     
       
  2623 // ---------------------------------------------------------------------------
       
  2624 // CCamAppController::SetEndKeyExitWaiting
       
  2625 // Update whether exit is required
       
  2626 // ---------------------------------------------------------------------------
       
  2627 //
       
  2628 void 
       
  2629 CCamAppController::SetEndKeyExitWaiting( TBool aEndKeyWaiting )
       
  2630   {
       
  2631   iEndKeyWaiting = aEndKeyWaiting;
       
  2632   }    
       
  2633 
       
  2634 // ---------------------------------------------------------------------------
       
  2635 // CCamAppController::CameraSlideState
       
  2636 // Returns the status of the camera slide
       
  2637 // ---------------------------------------------------------------------------
       
  2638 //
       
  2639 TInt 
       
  2640 CCamAppController::CameraSlideState() const
       
  2641   {
       
  2642   return iSlideState;
       
  2643   }
       
  2644 
       
  2645 // ---------------------------------------------------------------------------
       
  2646 // CCamAppController::SliderCloseEventActioned
       
  2647 // Update whether exit is required
       
  2648 // ---------------------------------------------------------------------------
       
  2649 //
       
  2650 void 
       
  2651 CCamAppController::SliderCloseEventActioned()
       
  2652   {
       
  2653   iSliderCloseEvent = EFalse;
       
  2654   }   
       
  2655 
       
  2656 // ---------------------------------------------------------------------------
       
  2657 // CCamAppController::SetCameraSwitchRequired
       
  2658 // ---------------------------------------------------------------------------
       
  2659 //
       
  2660 void 
       
  2661 CCamAppController::SetCameraSwitchRequired( TCameraSwitchRequired aSwitchRequired )  
       
  2662   {
       
  2663   iCameraSwitchRequired = aSwitchRequired;
       
  2664   }   
       
  2665 
       
  2666 
       
  2667 // ---------------------------------------------------------------------------
       
  2668 // CCamAppController::CheckSlideStatus
       
  2669 // Check the slide state and schedule a camera switch if needed
       
  2670 // ---------------------------------------------------------------------------
       
  2671 //
       
  2672 void CCamAppController::CheckSlideStatus()
       
  2673   {
       
  2674   PRINT( _L("Camera => CCamAppController::CheckSlideStatus") );
       
  2675   // if only 1 camera available then can't switch camera
       
  2676   if ( CamerasAvailable() <= 1 )
       
  2677     {
       
  2678     PRINT( _L("Camera <> Only one camera, no action") );
       
  2679     }
       
  2680   else
       
  2681     {
       
  2682     RefreshSlideStatus();
       
  2683     // if the slide is closed then schedule a camera switch
       
  2684     // if the back camera is active
       
  2685     if ( CameraSlideState() == CameraPlatPSKeys::EClosed  || 
       
  2686          CameraSlideState() == KErrNone )
       
  2687       {
       
  2688       if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  2689         {
       
  2690         PRINT( _L("Camera <> slide closed or uninitialized -> switch to secondary") );
       
  2691         iCameraSwitchRequired = ESwitchPrimaryToSecondary;
       
  2692         }
       
  2693       else
       
  2694         {
       
  2695         PRINT( _L("Camera <> no camera switch needed") );
       
  2696         iCameraSwitchRequired = ESwitchDone;
       
  2697         }
       
  2698       }
       
  2699     // if the slide is open then schedule a camera switch
       
  2700     // if the front camera is active
       
  2701     else if ( CameraSlideState() == CameraPlatPSKeys::EOpen )
       
  2702       {
       
  2703       if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  2704         {
       
  2705         PRINT( _L("Camera <> slide open -> switch to primary") );
       
  2706         iCameraSwitchRequired = ESwitchSecondaryToPrimary;
       
  2707         }
       
  2708       else
       
  2709         {
       
  2710         PRINT( _L("Camera <> no camera switch needed") );
       
  2711         iCameraSwitchRequired = ESwitchDone;
       
  2712         }
       
  2713       }
       
  2714     else
       
  2715       {
       
  2716       // do nothing
       
  2717       PRINT( _L("Camera <> not recognized slider state -> no action") );
       
  2718       }
       
  2719     }
       
  2720   PRINT( _L("Camera <= CCamAppController::CheckSlideStatus") );
       
  2721   }
       
  2722 
       
  2723 
       
  2724 // ----------------------------------------------------
       
  2725 // CCamAppController::EvRange
       
  2726 // Range of EV value supported by current product
       
  2727 // ----------------------------------------------------
       
  2728 //
       
  2729 TCamEvCompRange CCamAppController::EvRange() const
       
  2730   {
       
  2731   PRINT( _L("Camera =><= CCamAppController::EvRange") );
       
  2732   return iEvRange;
       
  2733   }            
       
  2734 
       
  2735 
       
  2736 // ----------------------------------------------------
       
  2737 // CCamAppController::CallStateChanged
       
  2738 // Callback for when the current phone call state changes
       
  2739 // ----------------------------------------------------
       
  2740 //
       
  2741 void 
       
  2742 CCamAppController::CallStateChanged( TPSCTsyCallState aState, 
       
  2743                                      TInt                  /* aError */ )
       
  2744   {
       
  2745   PRINT1( _L("Camera => CCamAppController::CallStateChanged aState: %d"), aState);
       
  2746 
       
  2747   TBool oldState = iInCallOrRinging;
       
  2748 
       
  2749   if ( aState == EPSCTsyCallStateAlerting ||
       
  2750        aState == EPSCTsyCallStateRinging ||
       
  2751        aState == EPSCTsyCallStateDialling ||
       
  2752        aState == EPSCTsyCallStateAnswering ||
       
  2753        aState == EPSCTsyCallStateDisconnecting ||
       
  2754        aState == EPSCTsyCallStateConnected ||
       
  2755        aState == EPSCTsyCallStateHold )
       
  2756     {
       
  2757     // If not already in a call/ringing state, and the new state
       
  2758     // indicates this, stop recording
       
  2759     if ( !iInCallOrRinging )
       
  2760       {
       
  2761       // Set the flag before handle call, as this may need to 
       
  2762       // know the call state for stopping video.
       
  2763       iInCallOrRinging = ETrue;
       
  2764       PRINT( _L("Camera <> CCamAppController::CallStateChanged: calling handleincomingcallL") );
       
  2765       HandleIncomingCall();                                     
       
  2766       }
       
  2767     }
       
  2768   else
       
  2769     {
       
  2770     iInCallOrRinging = EFalse;
       
  2771     }
       
  2772   // If the state has changed from in a call to not, notify the
       
  2773   // observers
       
  2774   // Also notify again if the state has reached connected so that
       
  2775   // the observer can reconsider its actions now that connection is complete
       
  2776   if ( iInCallOrRinging               != oldState ||
       
  2777        EPSCTsyCallStateConnected == aState )
       
  2778     {
       
  2779     PRINT( _L("Camera <> CCamAppController::CallStateChanged: telling call observers") );
       
  2780     NotifyControllerObservers( ECamEventCallStateChanged, KErrNone );        
       
  2781     }
       
  2782 
       
  2783   PRINT1( _L("Camera <= CCamAppController::CallStateChanged(%d, %d)"), aState );
       
  2784   }
       
  2785 
       
  2786 
       
  2787 
       
  2788 
       
  2789 
       
  2790 
       
  2791 // ---------------------------------------------------------------------------
       
  2792 // ReleaseCamera
       
  2793 //
       
  2794 // Releases the camera hardware for other apps to use
       
  2795 // ---------------------------------------------------------------------------
       
  2796 //
       
  2797 void CCamAppController::ReleaseCamera()   
       
  2798     {    
       
  2799     PRINT( _L("Camera => CCamAppController::ReleaseCamera") );
       
  2800 
       
  2801     if ( IsAppUiAvailable())  
       
  2802       {
       
  2803       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2804       if ( appUi )
       
  2805         {
       
  2806         appUi->SetAssumePostCaptureView( EFalse ); 
       
  2807         } 
       
  2808       }
       
  2809 
       
  2810     if ( Busy() )
       
  2811       {
       
  2812       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: set release pending") );
       
  2813       iPendingRelease = ETrue;
       
  2814       }
       
  2815     else if ( iCameraController && ECamCameraIdle != CameraState() )
       
  2816       {      
       
  2817       // No leaving code here. Clear the flag before any operation
       
  2818       // to prevent calling this from the event callbacks caused
       
  2819       // by the following requests.
       
  2820       iPendingRelease = EFalse;
       
  2821 
       
  2822       if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  2823           SequenceCaptureInProgress() )
       
  2824         {
       
  2825         // Cancel ongoing burst capture
       
  2826         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  2827         // and actual cancelling is done when next imagedata arrives.
       
  2828         // However, in this case camera is going to be released, and there won't
       
  2829         // be next image data, so give ECamRequestImageCancel and capture
       
  2830         // completion event here to avoid problems
       
  2831         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: Going to bacgkround in the middle of a burst capture") ); 
       
  2832         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  2833         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );          
       
  2834         }
       
  2835         
       
  2836       //iInfo.iMode            = ECamControllerShutdown;
       
  2837       //iInfo.iTargetMode      = ECamControllerIdle;
       
  2838       iInfo.iTargetMode      = ECamControllerIdle;
       
  2839       iInfo.iImageMode       = ECamImageCaptureNone;
       
  2840       iInfo.iTargetImageMode = ECamImageCaptureNone; 
       
  2841       iInfo.iOperation       = ECamNoOperation;
       
  2842 
       
  2843       iCaptureModeTransitionInProgress = EFalse;
       
  2844 
       
  2845       // Last change to stop view finder if we were "busy" previously in 
       
  2846       // ExitViewfinderMode method. View finder must be stopped in case where 
       
  2847       // orientation is changed, so Posting API display control doesn't try to 
       
  2848       // draw outside existing area. Otherwise KErrTooBig error is encountered. 
       
  2849       StopViewFinder();
       
  2850 
       
  2851       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: requesting release directly..") );
       
  2852       // iInfo.iMode set when complete
       
  2853       TRAP_IGNORE( IssueDirectRequestL( ECamRequestRelease ) );
       
  2854       //iPendingRelease = EFalse;
       
  2855       //shutdown the orientation channel
       
  2856       if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && 
       
  2857       		iAccSensorListening )
       
  2858         {
       
  2859         TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  2860         }
       
  2861       }
       
  2862     else
       
  2863       {
       
  2864       // No action needed.
       
  2865       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle!!") );
       
  2866       if(ECamControllerIdle != iInfo.iMode )
       
  2867         {
       
  2868         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle correcting state!!") );
       
  2869         iInfo.iMode = ECamControllerIdle;
       
  2870         }
       
  2871       }
       
  2872     PRINT( _L("Camera <= CCamAppController::ReleaseCamera") );
       
  2873     }
       
  2874 
       
  2875 
       
  2876 // ---------------------------------------------------------------------------
       
  2877 // IncCameraUsers
       
  2878 //
       
  2879 // Increments the camera usage count
       
  2880 // ---------------------------------------------------------------------------
       
  2881 //
       
  2882 void CCamAppController::IncCameraUsers()
       
  2883   {
       
  2884   PRINT ( _L("Camera => CCamAppController::IncCameraUsers") );
       
  2885   iCameraReferences++;
       
  2886   PRINT1( _L("Camera <= CCamAppController::IncCameraUsers, count now %d"), iCameraReferences );
       
  2887   }
       
  2888 
       
  2889 
       
  2890 // ---------------------------------------------------------------------------
       
  2891 // DecCameraUsers
       
  2892 //
       
  2893 // Decrements the camera usage count
       
  2894 // ---------------------------------------------------------------------------
       
  2895 //
       
  2896 void CCamAppController::DecCameraUsers()
       
  2897   {
       
  2898   PRINT ( _L("Camera => CCamAppController::DecCameraUsers") );
       
  2899 
       
  2900   __ASSERT_DEBUG( iCameraReferences > 0, CamPanic( ECamPanicInvalidState ) );
       
  2901   iCameraReferences--;
       
  2902 
       
  2903   PRINT1( _L("Camera <> CCamAppController::DecCameraUsers: count now %d"), iCameraReferences );
       
  2904   // If the engine is no longer required then release it.
       
  2905   if ( iCameraReferences <= 0 )
       
  2906     {
       
  2907     ReleaseCamera();
       
  2908     }       
       
  2909   PRINT ( _L("Camera <= CCamAppController::DecCameraUsers") );
       
  2910   }
       
  2911 
       
  2912 
       
  2913     
       
  2914 
       
  2915 // ----------------------------------------------------
       
  2916 // CCamAppController::InCallOrRinging
       
  2917 // Whether we are in call or ringing
       
  2918 // ----------------------------------------------------
       
  2919 //
       
  2920 TBool 
       
  2921 CCamAppController::InCallOrRinging() const
       
  2922   {
       
  2923   return iInCallOrRinging;
       
  2924   }
       
  2925 
       
  2926 // ----------------------------------------------------
       
  2927 // CCamAppController::InVideocallOrRinging
       
  2928 // Whether we are in videocall or ringing
       
  2929 // ----------------------------------------------------
       
  2930 //
       
  2931 TBool 
       
  2932 CCamAppController::InVideocallOrRinging()
       
  2933     {
       
  2934     if ( InCallOrRinging() )
       
  2935         {
       
  2936         TInt callType( EPSCTsyCallTypeUninitialized );
       
  2937         TInt err = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType, callType );
       
  2938         if ( err == KErrNone && callType == EPSCTsyCallTypeH324Multimedia )
       
  2939             {
       
  2940             return ETrue;
       
  2941             }
       
  2942         else
       
  2943             {
       
  2944             return EFalse;
       
  2945             }
       
  2946         }
       
  2947     else
       
  2948         {
       
  2949         return EFalse;
       
  2950         }
       
  2951     
       
  2952     }
       
  2953   
       
  2954 // ----------------------------------------------------
       
  2955 // CCamAppController::CurrentlySavingVideo
       
  2956 // Whether we are currently saving a video clip or not
       
  2957 // ----------------------------------------------------
       
  2958 //
       
  2959 TBool 
       
  2960 CCamAppController::CurrentlySavingVideo() const
       
  2961   {
       
  2962   return iSaving;
       
  2963   }
       
  2964         
       
  2965 
       
  2966 
       
  2967 // ---------------------------------------------------------------------------
       
  2968 // IssueModeChangeSequenceL
       
  2969 // ---------------------------------------------------------------------------
       
  2970 //
       
  2971 void
       
  2972 CCamAppController::IssueModeChangeSequenceL( TBool aStartup )
       
  2973   {
       
  2974   PRINT( _L( "Camera => CCamAppController::IssueModeChangeSequenceL" ) );
       
  2975   // Generate the request sequence and issue to Camera Controller.
       
  2976   RCamRequestArray sequence;
       
  2977   CleanupClosePushL( sequence );
       
  2978 
       
  2979   if( !aStartup )
       
  2980     {
       
  2981     GenerateModeChangeSequenceL( sequence );
       
  2982 	
       
  2983 	if( iCameraReferences ) 
       
  2984       {
       
  2985       SetFlags( iBusyFlags, EBusySequence );
       
  2986       TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  2987       CleanupStack::PushL( clearBusy );
       
  2988       iCameraController->RequestSequenceL( sequence );
       
  2989       CleanupStack::Pop();
       
  2990    
       
  2991       iCaptureModeTransitionInProgress = ETrue;
       
  2992       
       
  2993       }
       
  2994     else 
       
  2995   	  {
       
  2996       PRINT( _L("Camera <> No camera users, not requesting sequence.") );
       
  2997       }
       
  2998     }
       
  2999   else
       
  3000     {
       
  3001     GenerateStartupSequenceL( sequence );
       
  3002 	
       
  3003 	SetFlags( iBusyFlags, EBusySequence );
       
  3004     TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  3005     CleanupStack::PushL( clearBusy );
       
  3006     iCameraController->RequestSequenceL( sequence );
       
  3007     CleanupStack::Pop();
       
  3008     }
       
  3009   
       
  3010   CleanupStack::PopAndDestroy(); // sequence.Close()
       
  3011   PRINT( _L( "Camera <= CCamAppController::IssueModeChangeSequenceL" ) );
       
  3012   }
       
  3013 
       
  3014 // ---------------------------------------------------------------------------
       
  3015 // 
       
  3016 // ---------------------------------------------------------------------------
       
  3017 //
       
  3018 void
       
  3019 CCamAppController::GenerateModeChangeSequenceL( RCamRequestArray& aSequence )
       
  3020   {
       
  3021   PRINT( _L( "Camera => CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3022   TBool vfStartDone = EFalse;
       
  3023   //Have to empty autofocusrequest values here because modechange could override
       
  3024   //currently processed autofocus request.
       
  3025   iPendingAFRequest=0;
       
  3026   iCurrentAFRequest=0;
       
  3027   iNoBurstCancel = EFalse;
       
  3028   iKeyUP = EFalse;
       
  3029   iAFCancelInProgress = EFalse;
       
  3030 
       
  3031   // -------------------------------------------------------
       
  3032   if( ECamTriIdle != iCameraController->ViewfinderState() )
       
  3033     {
       
  3034     // If VF is not stopped, frames might come when we are not
       
  3035     // in either image or video mode.
       
  3036     if( ECamControllerIdle != iInfo.iMode 
       
  3037      && iInfo.iTargetMode  != iInfo.iMode )    
       
  3038       {
       
  3039       aSequence.Append( ECamRequestVfRelease );    
       
  3040       } 
       
  3041     else  
       
  3042       
       
  3043     if( ECamTriIdle == iInfo.iTargetVfState )
       
  3044       {
       
  3045       aSequence.Append( ECamRequestVfRelease );      
       
  3046       }
       
  3047     else if( ECamTriInactive == iInfo.iTargetVfState )
       
  3048       {
       
  3049       aSequence.Append( ECamRequestVfStop );      
       
  3050       }
       
  3051     else
       
  3052       {
       
  3053       // Nothing needed here
       
  3054       }
       
  3055 
       
  3056     }
       
  3057 
       
  3058   switch( iInfo.iMode )
       
  3059     {
       
  3060     // ---------------------------------
       
  3061     case ECamControllerImage:
       
  3062       {
       
  3063       if( ECamControllerImage != iInfo.iTargetMode )
       
  3064         {
       
  3065         aSequence.Append( ECamRequestImageRelease );
       
  3066         }
       
  3067       break;
       
  3068       }
       
  3069     // ---------------------------------
       
  3070     case ECamControllerVideo:
       
  3071       {
       
  3072       if( ECamControllerVideo != iInfo.iTargetMode )
       
  3073         {
       
  3074         aSequence.Append( ECamRequestVideoRelease );
       
  3075         }
       
  3076       break;
       
  3077       }
       
  3078     // ---------------------------------
       
  3079     default:
       
  3080       {
       
  3081       // If we need to get to video or image mode
       
  3082       // make sure camera has power on before further requests.
       
  3083       if( ECamControllerImage == iInfo.iTargetMode
       
  3084        || ECamControllerVideo == iInfo.iTargetMode )
       
  3085         {
       
  3086         TUint cameraState( iCameraController->State() );
       
  3087 
       
  3088         if( !(ECamPowerOn&cameraState) )
       
  3089           {
       
  3090           if( !(ECamReserved&cameraState) )
       
  3091             {
       
  3092             aSequence.Append( ECamRequestReserve );
       
  3093             }
       
  3094           aSequence.Append( ECamRequestPowerOn );
       
  3095           }
       
  3096         }
       
  3097       break;
       
  3098       }
       
  3099     // ---------------------------------
       
  3100     }
       
  3101 
       
  3102   // -------------------------------------------------------
       
  3103   // Append prepare operations to achieve target camera mode
       
  3104   switch( iInfo.iTargetMode )
       
  3105     {
       
  3106     // ---------------------------------
       
  3107     case ECamControllerImage:
       
  3108       {
       
  3109       if( ECamImageCaptureNone != iInfo.iTargetImageMode )
       
  3110         {
       
  3111         aSequence.Append( ECamRequestImageInit );      
       
  3112 
       
  3113         // Snapshot may have to be released and restarted because the
       
  3114         // snapshot size may change.
       
  3115         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3116         if( appUi )
       
  3117             {
       
  3118             if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3119                 {
       
  3120                 // If vf needs to be (re)started.
       
  3121                 // Camera Controller checks from Setting Provider if
       
  3122                 // viewfinder mode (direct/bitmap) has changed, and
       
  3123                 // releases old type first if needed.
       
  3124                 if( ECamTriActive == iInfo.iTargetVfState )
       
  3125                   {
       
  3126                   PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3127                   aSequence.Append( ECamRequestVfStart );
       
  3128                   vfStartDone = ETrue;
       
  3129                   }
       
  3130                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3131                 aSequence.Append( ECamRequestSsRelease );
       
  3132                 aSequence.Append( ECamRequestSsStart );
       
  3133                 }
       
  3134             else
       
  3135                 {
       
  3136                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot off" ) );
       
  3137                 aSequence.Append( ECamRequestSsRelease );
       
  3138                 aSequence.Append( ECamRequestSsStop );
       
  3139                 }
       
  3140             }
       
  3141         }
       
  3142 
       
  3143       break;
       
  3144       }
       
  3145     // ---------------------------------
       
  3146     case ECamControllerVideo:
       
  3147       {
       
  3148       // Video recorder needs to be initialized and prepared
       
  3149       // if we are not already in video mode.
       
  3150       if ( iInfo.iMode != ECamControllerVideo )
       
  3151           {
       
  3152           iVideoInitNeeded = ETrue;
       
  3153           }
       
  3154        aSequence.Append( ECamRequestVideoInit );
       
  3155        
       
  3156       // Snapshot has to be released and restarted because the
       
  3157       // snapshot size may change.
       
  3158       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3159       if( appUi )
       
  3160           {
       
  3161           if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3162               {
       
  3163               // If vf needs to be (re)started.
       
  3164               // Camera Controller checks from Setting Provider if
       
  3165               // viewfinder mode (direct/bitmap) has changed, and
       
  3166               // releases old type first if needed.
       
  3167               if( ECamTriActive == iInfo.iTargetVfState )
       
  3168                 {
       
  3169                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3170                 aSequence.Append( ECamRequestVfStart );
       
  3171                 vfStartDone = ETrue;
       
  3172                 }
       
  3173               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3174               aSequence.Append( ECamRequestSsRelease );
       
  3175               aSequence.Append( ECamRequestSsStart );
       
  3176               }
       
  3177           else
       
  3178               {
       
  3179               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot off" ) );
       
  3180               aSequence.Append( ECamRequestSsRelease );
       
  3181               aSequence.Append( ECamRequestSsStop );
       
  3182               }
       
  3183           }
       
  3184       break;
       
  3185       }
       
  3186     // ---------------------------------
       
  3187     default:
       
  3188       break;
       
  3189     // ---------------------------------
       
  3190     }
       
  3191 
       
  3192   // If vf needs to be (re)started.
       
  3193   // Camera Controller checks from Setting Provider if
       
  3194   // viewfinder mode (direct/bitmap) has changed, and
       
  3195   // releases old type first if needed.
       
  3196   if( !vfStartDone && ECamTriActive == iInfo.iTargetVfState )
       
  3197     {
       
  3198     PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3199     aSequence.Append( ECamRequestVfStart );
       
  3200     }
       
  3201 
       
  3202 
       
  3203   // -------------------------------------------------------
       
  3204 #ifdef _DEBUG
       
  3205   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
  3206   for( TInt i = 0; i < aSequence.Count(); i++ )
       
  3207     {
       
  3208     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
  3209     }
       
  3210 #endif  
       
  3211   PRINT( _L( "Camera <= CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3212   }
       
  3213 
       
  3214 
       
  3215 // ---------------------------------------------------------------------------
       
  3216 // CCamAppController::SettingsPhotoResolution
       
  3217 // Returns the photo resolution stored by the Settings Model
       
  3218 // ---------------------------------------------------------------------------
       
  3219 //
       
  3220 TCamPhotoSizeId  CCamAppController::SettingsPhotoResolution() const
       
  3221     {
       
  3222     return iSettingsModel->CurrentPhotoResolution();
       
  3223     }
       
  3224 
       
  3225 // ---------------------------------------------------------------------------
       
  3226 // CCamAppController::GetCurrentImageDimensions
       
  3227 // ---------------------------------------------------------------------------
       
  3228 //
       
  3229 TSize 
       
  3230 CCamAppController::GetCurrentImageDimensions() const
       
  3231   {
       
  3232   TCamPhotoSizeId index = iSettingsModel->CurrentPhotoResolution();
       
  3233   TSize           size  = iSettingsModel->ImageResolutionFromIndex( index );
       
  3234   return size;
       
  3235   }
       
  3236 
       
  3237 // ---------------------------------------------------------------------------
       
  3238 // CCamAppController::GetCurrentImageResolution
       
  3239 // Gets the current image resolution used.  May not be the same at that stored in Settings
       
  3240 // if Zoom state is not 1x
       
  3241 // ---------------------------------------------------------------------------
       
  3242 //
       
  3243 TCamPhotoSizeId CCamAppController::GetCurrentImageResolution() const
       
  3244     {   
       
  3245     TCamPhotoSizeId size = iSettingsModel->CurrentPhotoResolution();
       
  3246     return size;    
       
  3247     }
       
  3248     
       
  3249 // ---------------------------------------------------------------------------
       
  3250 // CCamAppController::GetCurrentImageCompression
       
  3251 // Returns the photo compression level from the Settings Model
       
  3252 // ---------------------------------------------------------------------------
       
  3253 //
       
  3254 TInt  CCamAppController::GetCurrentImageCompression() const
       
  3255     {
       
  3256     return iSettingsModel->CurrentPhotoCompression();
       
  3257     }
       
  3258 
       
  3259 // ---------------------------------------------------------------------------
       
  3260 // CCamAppController::GetCurrentVideoResolution
       
  3261 // Gets the current video resolution used.  
       
  3262 // ---------------------------------------------------------------------------
       
  3263 //
       
  3264 TCamVideoResolution CCamAppController::GetCurrentVideoResolution() const
       
  3265     {   
       
  3266     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  3267     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];        
       
  3268     return static_cast<TCamVideoResolution>( level.VideoResolution() );
       
  3269     }
       
  3270 
       
  3271 // ---------------------------------------------------------------------------
       
  3272 // CCamAppController::UsePhoneMemoryL
       
  3273 // Force use of phone memory storage.  
       
  3274 // ---------------------------------------------------------------------------
       
  3275 //
       
  3276 void CCamAppController::UsePhoneMemoryL() const
       
  3277     {
       
  3278 #ifdef PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE   
       
  3279     // This function is used to directly force the value of media storage
       
  3280     // Bypasses any updates the controller does for change to these values
       
  3281 
       
  3282     if( ExistMassStorage() )
       
  3283         {
       
  3284         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3285                                              ECamMediaStorageMassStorage );
       
  3286         
       
  3287         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3288                                              ECamMediaStorageMassStorage );
       
  3289         }
       
  3290     else
       
  3291         {        
       
  3292         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3293                                              ECamMediaStoragePhone );
       
  3294         
       
  3295         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3296                                              ECamMediaStoragePhone );
       
  3297         }
       
  3298 
       
  3299 #endif // PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE
       
  3300     }
       
  3301 
       
  3302 
       
  3303 // ===========================================================================
       
  3304 // From MCamSettingsModelObserver
       
  3305 
       
  3306 // ---------------------------------------------------------------------------
       
  3307 // CCamAppController::IntSettingChangedL
       
  3308 //
       
  3309 // ---------------------------------------------------------------------------
       
  3310 //
       
  3311 void 
       
  3312 CCamAppController::IntSettingChangedL( TCamSettingItemIds aSettingItem, 
       
  3313                                        TInt               aSettingValue )
       
  3314   {
       
  3315   switch( aSettingItem )
       
  3316     {
       
  3317     case ECamSettingItemDynamicSelfTimer:
       
  3318       {
       
  3319       TCamSelfTimerFunctions function( ECamSelfTimerDisabled );
       
  3320       switch( aSettingValue )
       
  3321         {
       
  3322         case ECamSelfTimer2:  function = ECamSelfTimerMode1; break;
       
  3323         case ECamSelfTimer10: function = ECamSelfTimerMode2; break;
       
  3324         case ECamSelfTimer20: function = ECamSelfTimerMode3; break;            
       
  3325         default:                                             break;
       
  3326         }
       
  3327       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3328       if( appUi ) 
       
  3329         {
       
  3330         appUi->SelfTimerEnableL( function );
       
  3331         }
       
  3332       break;
       
  3333       }
       
  3334     case ECamSettingItemPhotoQuality:
       
  3335         {
       
  3336         HandleImageQualitySettingChangeL();
       
  3337         break;
       
  3338         }
       
  3339     case ECamSettingItemVideoQuality:
       
  3340        NotifyControllerObservers( ECamEventVideoQualityChanged, KErrNone );
       
  3341        break;
       
  3342     case ECamSettingItemVideoAudioRec:
       
  3343       {
       
  3344       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  3345       break;
       
  3346       }
       
  3347     case ECamSettingItemContinuousAutofocus:  
       
  3348       {
       
  3349       NotifyControllerObservers( ECamEventContAFStateChanged );
       
  3350       break;
       
  3351       }
       
  3352       
       
  3353     case ECamSettingItemFaceTracking:
       
  3354       {
       
  3355       PRINT( _L("Camera => ECamSettingItemFaceTracking") );
       
  3356       TCamCameraSettingId cameraId( 
       
  3357         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3358       iCameraController->DirectSettingsChangeL( cameraId );
       
  3359       NotifyControllerObservers( ECamEventFaceTrackingStateChanged );
       
  3360       break;
       
  3361       }  
       
  3362     case ECamSettingItemDynamicVideoFlash:  
       
  3363       {
       
  3364       PRINT( _L("Camera => ECamSettingItemDynamicVideoFlash") );
       
  3365       TCamCameraSettingId cameraId( 
       
  3366         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3367       iCameraController->DirectSettingsChangeL( cameraId );
       
  3368       break;
       
  3369       }  
       
  3370     default:
       
  3371       {
       
  3372       break;
       
  3373       }
       
  3374     }
       
  3375   }
       
  3376 
       
  3377 // ---------------------------------------------------------------------------
       
  3378 // CCamAppController::TextSettingChangedL
       
  3379 //
       
  3380 // ---------------------------------------------------------------------------
       
  3381 //
       
  3382 void 
       
  3383 CCamAppController::TextSettingChangedL( TCamSettingItemIds /*aSettingItem*/, 
       
  3384                                         const TDesC&       /*aSettingValue*/ )
       
  3385   {
       
  3386   }
       
  3387 
       
  3388 // ---------------------------------------------------------------------------
       
  3389 // HandleImageQualitySettingChangeL
       
  3390 // ---------------------------------------------------------------------------
       
  3391 //
       
  3392 void 
       
  3393 CCamAppController::HandleImageQualitySettingChangeL() 
       
  3394   {
       
  3395   PRINT( _L("Camera => CCamAppController::HandleImageQualitySettingChangeL") );
       
  3396   if( IsViewFinding() ) 
       
  3397     {
       
  3398     PRINT( _L("Camera <> CCamAppController - viewfinder on, stop vf / re-prepare / start vf..") );
       
  3399     TRAPD( status, 
       
  3400       {
       
  3401       IssueDirectRequestL( ECamRequestVfStop    );
       
  3402       IssueDirectRequestL( ECamRequestSsRelease );
       
  3403       IssueDirectRequestL( ECamRequestImageInit );
       
  3404       IssueDirectRequestL( ECamRequestSsStart   );
       
  3405       IssueDirectRequestL( ECamRequestVfStart   );
       
  3406       });
       
  3407       
       
  3408     if( KErrNone != status )
       
  3409       {
       
  3410       SetOperation( ECamStandby, status );
       
  3411       }
       
  3412     }
       
  3413 
       
  3414   NotifyControllerObservers( ECamEventImageQualityChanged, KErrNone );      
       
  3415   PRINT( _L("Camera <= CCamAppController::HandleImageQualitySettingChangeL") );
       
  3416   }
       
  3417 
       
  3418 // ---------------------------------------------------------------------------
       
  3419 // CCamAppController::BurstModeActive
       
  3420 //
       
  3421 // ---------------------------------------------------------------------------
       
  3422 //
       
  3423 void
       
  3424 CCamAppController::BurstModeActiveL( TBool aActive, TBool /*aStillModeActive*/ )
       
  3425   { 
       
  3426   PRINT1( _L("Camera => CCamAppController::BurstModeActiveL %d"), aActive );  
       
  3427   if( ECamControllerImage == iInfo.iMode )  
       
  3428     {
       
  3429     //TCamImageCaptureMode oldImageMode = iInfo.iImageMode; 
       
  3430     // We are in still capture mode     
       
  3431     if( aActive )
       
  3432       {
       
  3433       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = appUi->CurrentBurstMode() ") );  
       
  3434       // Burst mode active. Query current mode from AppUi  
       
  3435       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3436       // iInfo.iImageMode = appUi->CurrentBurstMode();
       
  3437       SetImageMode( appUi->CurrentBurstMode() );
       
  3438       // reset image orientation
       
  3439       iImageOrientation = ECamOrientation0;
       
  3440       TRAP_IGNORE( SetImageOrientationL() );
       
  3441       
       
  3442       }
       
  3443     else
       
  3444       {
       
  3445       // Burst mode not active  
       
  3446       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = ECamImageCaptureSingle ") );
       
  3447       // iInfo.iImageMode = ECamImageCaptureSingle;
       
  3448       SetImageMode( ECamImageCaptureSingle );
       
  3449       }  
       
  3450     iRequestedCaptureCount = ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3451                              ? KShortBurstCount
       
  3452                              : 1;
       
  3453     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  3454     // set image orientation in case it was changed during burst mode
       
  3455     if( iOrientationChangeOccured )
       
  3456         {
       
  3457         iOrientationChangeOccured = EFalse;	
       
  3458         TRAP_IGNORE( SetImageOrientationL() );
       
  3459         }
       
  3460 
       
  3461     }
       
  3462   else
       
  3463     {
       
  3464     PRINT( _L("Camera <> CCamAppController .. [WARNING] Not in image mode, set iInfo.iImageMode = ECamImageCaptureNone") );  
       
  3465     // iInfo.iImageMode = ECamImageCaptureNone;  
       
  3466     SetImageMode( ECamImageCaptureNone );
       
  3467     } 
       
  3468   PRINT( _L("Camera <= CCamAppController::BurstModeActiveL %d") );    
       
  3469   }
       
  3470 
       
  3471 
       
  3472 // ---------------------------------------------------------------------------
       
  3473 // CCamAppController::SetVideoLengthL
       
  3474 // Set video length (max or short)
       
  3475 // ---------------------------------------------------------------------------
       
  3476 //
       
  3477 void CCamAppController::SetVideoLengthL( TInt /*aLength*/ )
       
  3478     {
       
  3479     PRINT( _L( "Camera => CCamAppController::SetVideoLengthL" ) );
       
  3480     User::Leave( KErrNotSupported );
       
  3481     }
       
  3482 
       
  3483 // ---------------------------------------------------------------------------
       
  3484 // CCamAppController::CurrentPhotoStorageLocation
       
  3485 // Returns the current photo storage location filtered by MMC presence
       
  3486 // ---------------------------------------------------------------------------
       
  3487 TInt CCamAppController::CurrentPhotoStorageLocation() const
       
  3488   {
       
  3489   TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  3490   
       
  3491   // added iForceUseOfPhoneMemory part to treat current location 
       
  3492   // as Mass Storage / Phone, also if it is forced.
       
  3493   if (  iForceUseOfPhoneMemory ||  
       
  3494         ( ( storageLocation == ECamMediaStorageCard ) &&
       
  3495           ( CamUtility::MemoryCardStatus() != ECamMemoryCardInserted ) ) )
       
  3496     {
       
  3497     if ( ExistMassStorage() )
       
  3498       {
       
  3499       storageLocation = ECamMediaStorageMassStorage;
       
  3500       }
       
  3501     else
       
  3502       {
       
  3503       storageLocation = ECamMediaStoragePhone;
       
  3504       }
       
  3505     }
       
  3506   return storageLocation;
       
  3507   }
       
  3508 
       
  3509 // ---------------------------------------------------------------------------
       
  3510 // CCamAppController::CurrentVideoStorageLocation
       
  3511 // Returns the current video storage location filtered by MMC presence
       
  3512 // ---------------------------------------------------------------------------
       
  3513 TInt CCamAppController::CurrentVideoStorageLocation() const
       
  3514 	{
       
  3515 	TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoMediaStorage );        
       
  3516 
       
  3517 	// added iForceUseOfPhoneMemory part to treat current location 
       
  3518 	// as Mass Storage / Phone, also if it is forced.
       
  3519 	
       
  3520   if ( iForceUseOfPhoneMemory )
       
  3521     {
       
  3522     storageLocation = iForcedStorageLocation;
       
  3523     }
       
  3524   return storageLocation;
       
  3525   }
       
  3526 
       
  3527 
       
  3528 
       
  3529 // ---------------------------------------------------------------------------
       
  3530 // CCamAppController::ReleaseArray
       
  3531 // Record that the view has finished with the array
       
  3532 // ---------------------------------------------------------------------------
       
  3533 //
       
  3534 void CCamAppController::ReleaseArray( TBool aForcedRelease )
       
  3535   {
       
  3536   PRINT( _L("Camera => CCamAppController::ReleaseArray") );
       
  3537   // Otherwise  we were using the real capture array, so reset it
       
  3538   if( iArrayUsageCount > 0 )
       
  3539       {
       
  3540       iArrayUsageCount--;
       
  3541       }
       
  3542 
       
  3543   if ( iArrayUsageCount == 0 || aForcedRelease )
       
  3544       {
       
  3545       PRINT( _L("Camere <> CCamAppController::ReleaseArray .. usage to 0") );
       
  3546       iCaptureArray->Reset();
       
  3547       iCurrentImageIndex = 0;
       
  3548       // May have released a large amount of memory, so compress the heap
       
  3549       User::Heap().Compress();
       
  3550       }        
       
  3551 
       
  3552   PRINT( _L("Camera <= CCamAppController::ReleaseArray") );
       
  3553   }
       
  3554 
       
  3555 // ---------------------------------------------------------------------------
       
  3556 // CCamAppController::RestoreFactorySettingsL
       
  3557 // Delete 
       
  3558 // ---------------------------------------------------------------------------
       
  3559 //    
       
  3560 void CCamAppController::RestoreFactorySettingsL( TBool aIsEmbedded )
       
  3561   {          
       
  3562   PRINT( _L("Camera => CCamAppController::RestoreFactorySettingsL") );
       
  3563   iSettingsModel->ResetRepository();
       
  3564     
       
  3565   // reload static settings
       
  3566   LoadStaticSettingsL( aIsEmbedded );
       
  3567   
       
  3568   // reload dynamic settings
       
  3569   SetDynamicSettingsToDefaults();
       
  3570   
       
  3571   // Restoring camera settings didn't set the capture mode to single capture, 
       
  3572   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3573   appUi->SwitchStillCaptureModeL( ECamImageCaptureSingle, EFalse, EFalse );
       
  3574   //
       
  3575   SetMode( ECamControllerIdle );  
       
  3576       
       
  3577   if( iLocationTrailStarted &&
       
  3578       ECamLocationOn != IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  3579     {    
       
  3580     PRINT( _L("Camera <> CCamAppController::RestoreFactorySettingsL - Stop location trail") );
       
  3581     // Location trail has been started, but setting off after restore -> stop trail
       
  3582     // Starting (if needed after restore) happens when still precap view is activated
       
  3583     StopLocationTrail();
       
  3584     }
       
  3585         
       
  3586   //
       
  3587   NotifyControllerObservers( ECamEventRestoreCameraSettings );
       
  3588   PRINT( _L("Camera <= CCamAppController::RestoreFactorySettingsL") );
       
  3589   }
       
  3590 
       
  3591 
       
  3592 
       
  3593 
       
  3594 // ---------------------------------------------------------------------------
       
  3595 // PlayComplete
       
  3596 //
       
  3597 // Called from when sound playing completes.
       
  3598 // ---------------------------------------------------------------------------
       
  3599 //
       
  3600 void 
       
  3601 CCamAppController::PlayComplete( TInt /*aStatus*/, TInt /*aSoundId*/ )
       
  3602   {
       
  3603   PlaySoundComplete();
       
  3604   }
       
  3605 
       
  3606 // ---------------------------------------------------------------------------
       
  3607 // CCamAppController::PlaySoundComplete
       
  3608 // Called when playback of a sound has completed.  Typically used in conjunction
       
  3609 // with Video recording (must only start recording AFTER sound has finished
       
  3610 // to avoid recording the sound in the recorded clip).
       
  3611 // ---------------------------------------------------------------------------
       
  3612 //
       
  3613 void CCamAppController::PlaySoundComplete()
       
  3614   {
       
  3615   PRINT( _L("Camera => CCamAppController::PlaySoundComplete") );
       
  3616   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUNDCOMPLETE, "e_CAM_APP_CAPTURE_SOUND_PLAY 0" );    //CCORAPP_CAPTURE_SOUND_PLAY_END
       
  3617   
       
  3618   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  3619   if( ECamControllerVideo == iInfo.iMode && !IsKeyLockOn() )
       
  3620     {
       
  3621     switch( CurrentVideoOperation() )
       
  3622       {
       
  3623       case ECamResuming:
       
  3624         {
       
  3625         // Restarting video
       
  3626         DoRecord();
       
  3627         break;
       
  3628         }
       
  3629       case ECamPausing:
       
  3630         {
       
  3631         // Notifies observers, so paused icon and softkeys can be updated.
       
  3632         SetOperation( ECamPaused );
       
  3633         break;
       
  3634         }
       
  3635       case ECamNoOperation:
       
  3636         {
       
  3637         // Starting the video capture
       
  3638         // If the next file path has not changed, start capturing
       
  3639         if ( BurstCaptureArray()->FileName( 0 ).Compare( iSuggestedVideoPath ) == 0 )
       
  3640           {
       
  3641           PRINT( _L("Camera <> starting to record..") );
       
  3642           DoRecord();
       
  3643           }
       
  3644         // File path changed. Prepare the engine with the new video file path.
       
  3645         // Start video recording when filename changed (event)
       
  3646         else 
       
  3647           {
       
  3648           iVideoRequested = ETrue;
       
  3649           iSuggestedVideoPath.Copy( BurstCaptureArray()->FileName( 0 ) );
       
  3650           PRINT1( _L("Camera <> Requesting Camera controller to set the video name, iSuggestedVideoPath = [%S] "), &iSuggestedVideoPath );          
       
  3651           TRAP_IGNORE(
       
  3652             {
       
  3653             // Set video name change pending and request setting it to camera controller.
       
  3654             iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  3655             IssueSettingsChangeRequestL();
       
  3656             });
       
  3657           iVideoNameRetries = KVideoNameRetryCount;
       
  3658           }      
       
  3659         }
       
  3660       default:
       
  3661         {
       
  3662         // No operation. 
       
  3663         // Should be stopping video
       
  3664         }
       
  3665       }
       
  3666     }
       
  3667   else
       
  3668     {
       
  3669     // Image mode or keylock on, no action
       
  3670     }
       
  3671   PRINT( _L("Camera <= CCamAppController::PlaySoundComplete") );
       
  3672   }
       
  3673 // ---------------------------------------------------------------------------
       
  3674 // CCamAppController::MediaFileChangedNotification
       
  3675 //Helper function for making notification about deleted files
       
  3676 // ---------------------------------------------------------------------------
       
  3677 //
       
  3678 void  
       
  3679 CCamAppController::MediaFileChangedNotification()
       
  3680   {
       
  3681   PRINT( _L("Camera => CCamAppController::MediaFileChangedNotification") );
       
  3682   NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3683   PRINT( _L("Camera <= CCamAppController::MediaFileChangedNotification") );
       
  3684   }
       
  3685 
       
  3686 
       
  3687 // ---------------------------------------------------------------------------
       
  3688 // CCamAppController::DeleteCurrentFile
       
  3689 // Delete the current image/video file
       
  3690 // ---------------------------------------------------------------------------
       
  3691 //
       
  3692 TInt 
       
  3693 CCamAppController::DeleteCurrentFile( TBool aNotify /*=ETrue*/ )
       
  3694   {
       
  3695   PRINT( _L("Camera => CCamAppController::DeleteCurrentFile") );
       
  3696   iImageSaveRequestPending = EFalse;
       
  3697 
       
  3698   TInt err( KErrNone );
       
  3699   if( BurstCaptureArray()->Count() > 0 )
       
  3700     {
       
  3701     err = BurstCaptureArray()->SetDeleted( iCurrentImageIndex, ETrue );
       
  3702     if ( aNotify && err == KErrNone )
       
  3703       {
       
  3704       NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3705       }
       
  3706     }
       
  3707 
       
  3708   PRINT( _L("Camera <= CCamAppController::DeleteCurrentFile") );
       
  3709   return err;
       
  3710   }
       
  3711 
       
  3712 // ---------------------------------------------------------------------------
       
  3713 // CCamAppController::DeleteTimeLapseFiles
       
  3714 // Delete the current timelapse sequence
       
  3715 // ---------------------------------------------------------------------------
       
  3716 //
       
  3717 void 
       
  3718 CCamAppController::DeleteTimeLapseFiles()    
       
  3719   {
       
  3720   // Count() is inline
       
  3721   for ( TInt i = 0; i < iSequenceFilenameArray->Count(); i++ )
       
  3722     {
       
  3723     TPtrC filename( iSequenceFilenameArray->MdcaPoint( i ) );
       
  3724     // Error ignored
       
  3725     (void)iImageSaveActive->DeleteFile( filename, ETrue );
       
  3726     }
       
  3727   iSequenceFilenameArray->Reset();        
       
  3728   }
       
  3729  
       
  3730 // ---------------------------------------------------------------------------
       
  3731 // CCamAppController::IsProcessingCapture
       
  3732 // Indicate whether or not the controller is actively engaged in still
       
  3733 // or video capture
       
  3734 // ---------------------------------------------------------------------------
       
  3735 //   
       
  3736 
       
  3737 TBool CCamAppController::IsProcessingCapture()
       
  3738     {
       
  3739     return ( iCaptureRequested  // if a still capture is pending
       
  3740           || iVideoRequested    // if a video capture is pending                            
       
  3741           || EngineProcessingCapture() // if recording or capture is active
       
  3742           || ECamImageCaptureTimeLapse == iInfo.iImageMode  // if capturing time lapse
       
  3743           || CurrentlySavingVideo() );        // if a video save is in progress  
       
  3744     }
       
  3745   
       
  3746 // ---------------------------------------------------------------------------
       
  3747 // CCamAppController::CompleteCaptureAndNotifyL
       
  3748 // Request that any current processes complete, then notify observers
       
  3749 // ---------------------------------------------------------------------------
       
  3750 //   
       
  3751 void 
       
  3752 CCamAppController::CompleteCaptureAndNotifyL( MCamObserver* aObserver, 
       
  3753                                               TBool         aSafeCompletion )    
       
  3754   {
       
  3755   PRINT( _L( "Camera => CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3756   
       
  3757   RProperty::Set( KPSUidCamcorderNotifier, KCCorFocused, 0 );
       
  3758     
       
  3759   // Add the observer to the observer handler for capture completion.
       
  3760   if ( !iCaptureCompletionObserverHandler )
       
  3761     {
       
  3762     iCaptureCompletionObserverHandler = CCamObserverHandler::NewL();
       
  3763     }
       
  3764   iCaptureCompletionObserverHandler->RegisterObserverL( aObserver );
       
  3765     
       
  3766   // if the capture has not yet begun, all that is required is to switch off
       
  3767   // the pending capture
       
  3768   iCaptureRequested = EFalse;
       
  3769   iVideoRequested   = EFalse;
       
  3770                
       
  3771   // if no capture is actively in progress
       
  3772   if ( !IsProcessingCapture() )
       
  3773     {
       
  3774     PRINT( _L( "Camera <> not capturing calling HandleCaptureCompletion" ) )
       
  3775     HandleCaptureCompletion();
       
  3776     }
       
  3777 
       
  3778   // if recording is active
       
  3779   else if ( ECamControllerVideo == iInfo.iMode )
       
  3780     {
       
  3781     if( ECamCapturing == iInfo.iOperation
       
  3782      || ECamPausing   == iInfo.iOperation
       
  3783      || ECamPaused    == iInfo.iOperation
       
  3784      || ECamResuming  == iInfo.iOperation )
       
  3785       {
       
  3786       PRINT( _L( "Camera <> currently recording calling StopVideoRecording()" ) )
       
  3787       StopVideoRecording();
       
  3788       // iCaptureCompletionObserverHandler will be notified when the record completes
       
  3789       // in McaeoVideoRecordingComplete
       
  3790       }
       
  3791     }        
       
  3792   else if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  3793     {
       
  3794     PRINT( _L( "Camera <> Calling StopSequenceCapture" ) )
       
  3795     StopSequenceCaptureL();
       
  3796     // iCaptureCompletionObserverHandler will be notified when the 
       
  3797     // next image saving completes
       
  3798     }
       
  3799             
       
  3800   // if a burst capture is in early stages
       
  3801   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3802     {
       
  3803     if( ECamCapturing == iInfo.iOperation )
       
  3804       {
       
  3805       if ( !aSafeCompletion )
       
  3806         {
       
  3807         //iEngine->CancelCaptureStill();
       
  3808         PRINT( _L( "Camera <> Safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3809         IssueDirectRequestL( ECamRequestImageCancel );
       
  3810         CompleteBurstOperation();
       
  3811         }
       
  3812       else
       
  3813         {
       
  3814         //iEngine->StopStillBurstCapture();
       
  3815         PRINT( _L( "Camera <> Not safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3816         IssueDirectRequestL( ECamRequestImageCancel );
       
  3817         // iCaptureCompletionObserverHandler will be notified when the 
       
  3818         // image saving completes
       
  3819         }
       
  3820       }
       
  3821     }
       
  3822   else // do nothing
       
  3823     {
       
  3824     PRINT( _L( "Camera <> currently waiting for capture completion" ) )
       
  3825     // e.g. iOperation == ECamCaptureCompleting
       
  3826     // iCaptureCompletionObserverHandler will be notified when the 
       
  3827     // image saving completes
       
  3828     
       
  3829     // e.g. CurrentlySavingVideo()
       
  3830     // iCaptureCompletionObserverHandler will be notified when the 
       
  3831     // video saving completes in McaeoVideoRecordingComplete
       
  3832     
       
  3833     // e.g. iOperation == ECamCaptureInProgress (single capture)
       
  3834     // iCaptureCompletionObserverHandler will be notified when the 
       
  3835     // image saving completes
       
  3836     }        
       
  3837   PRINT( _L( "Camera <= CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3838   }
       
  3839 
       
  3840 // ---------------------------------------------------------------------------
       
  3841 // CCamAppController::EnterShutdownMode
       
  3842 // Enter shutdown mode as the application is closing
       
  3843 // ---------------------------------------------------------------------------
       
  3844 //
       
  3845 void 
       
  3846 CCamAppController::EnterShutdownMode( TBool aImmediateShutdown )
       
  3847   {
       
  3848   PRINT1( _L( "Camera => CCamAppController::EnterShutdownMode( aImmediateShutdown=%d )"), aImmediateShutdown );
       
  3849   
       
  3850   DeRegisterHarverterClientEvents();  
       
  3851 
       
  3852   if ( !IsInShutdownMode() )
       
  3853     {
       
  3854     PRINT ( _L( "Camera <> CCamAppController::EnterShutdownMode: set target mode to ECamControllerShutdown..") );
       
  3855     SetTargetMode( ECamControllerShutdown );
       
  3856     }
       
  3857 
       
  3858   // if not close down straightaway (i.e. for embedded )
       
  3859   if ( !aImmediateShutdown )
       
  3860     {
       
  3861     // cancel any outstanding sound requests
       
  3862     // iSoundPlayer->CancelTonePlayer();
       
  3863     iSoundPlayer->CancelAllPlaying();
       
  3864     
       
  3865     TRAPD( err, CompleteCaptureAndNotifyL( this, EFalse ) )
       
  3866     if ( err )
       
  3867       {
       
  3868       NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  3869       }
       
  3870     }
       
  3871   else
       
  3872     {
       
  3873     // This checks for any ongoing operation.
       
  3874     ReleaseCamera();
       
  3875     }
       
  3876 
       
  3877   PRINT ( _L( "Camera <= CCamAppController::EnterShutdownMode") );
       
  3878   }
       
  3879 
       
  3880 // ---------------------------------------------------------------------------
       
  3881 // CCamAppController::IsInShutdownMode
       
  3882 // Whether or not the controller is in shutdown mode
       
  3883 // ---------------------------------------------------------------------------
       
  3884 //
       
  3885 TBool CCamAppController::IsInShutdownMode() const
       
  3886     {
       
  3887     return ( ECamControllerShutdown == iInfo.iTargetMode );
       
  3888     }
       
  3889 
       
  3890 
       
  3891 // ---------------------------------------------------------------------------
       
  3892 // CCamAppController::IsAppUiAvailable
       
  3893 // Returns true if AppUi has been constructed, and not yet destructed
       
  3894 // ---------------------------------------------------------------------------
       
  3895 //
       
  3896 TBool CCamAppController::IsAppUiAvailable() const
       
  3897     {
       
  3898     return iAppUiAvailable;
       
  3899     }       
       
  3900     
       
  3901 // ---------------------------------------------------------------------------
       
  3902 // CCamAppController::SetAppUiAvailable
       
  3903 // Sets AppUi availablility (see IsAppUiAvailable)
       
  3904 // ---------------------------------------------------------------------------
       
  3905 //    
       
  3906 void CCamAppController::SetAppUiAvailable( TBool aAvailable )
       
  3907     {
       
  3908     iAppUiAvailable = aAvailable;  
       
  3909     }
       
  3910 
       
  3911 
       
  3912 // ---------------------------------------------------------------------------
       
  3913 // CCamAppController::GetZoomRange
       
  3914 // Returns the minimum and maximum supported zoom values
       
  3915 // ---------------------------------------------------------------------------
       
  3916 //
       
  3917 void 
       
  3918 CCamAppController::GetZoomRange( TInt& aMinZoom, TInt& aMaxZoom ) const
       
  3919   {
       
  3920   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  3921   aMinZoom = 0;
       
  3922   aMaxZoom = iCameraController->CameraInfo().iMaxDigitalZoom;
       
  3923   }
       
  3924 
       
  3925 // ---------------------------------------------------------------------------
       
  3926 // CCamAppController::ZoomValue
       
  3927 // Returns the current zoom value
       
  3928 // ---------------------------------------------------------------------------
       
  3929 //
       
  3930 TInt 
       
  3931 CCamAppController::ZoomValue() const
       
  3932   {       
       
  3933   return iDesiredZoomVal;
       
  3934   }
       
  3935 
       
  3936 // ---------------------------------------------------------------------------
       
  3937 // CCamAppController::SetZoomValue
       
  3938 // Sets a new zoom value
       
  3939 // ---------------------------------------------------------------------------
       
  3940 //
       
  3941 void CCamAppController::SetZoomValue( TInt aValue )
       
  3942   {
       
  3943   PRINT1( _L("Camera => CCamAppController::SetZoomValue( %d )"), aValue );
       
  3944   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  3945 
       
  3946   // Check the requested value for validity
       
  3947   __ASSERT_DEBUG( Rng( 0, aValue, iCameraController->CameraInfo().iMaxDigitalZoom ), 
       
  3948                   CamPanic( ECamPanicInvalidZoomValue ) );
       
  3949   
       
  3950   if ( ECamControllerImage == iInfo.iMode
       
  3951     || ECamControllerVideo == iInfo.iMode )
       
  3952     {
       
  3953     // Setting provider asks for the zoom value from us
       
  3954     iDesiredZoomVal = aValue;
       
  3955 
       
  3956     if ( !iZoomWaitingForCamera )
       
  3957       {
       
  3958       PRINT( _L("Camera <> CCamAppController: calling Camera Controller..") );
       
  3959       
       
  3960       TRAPD( error,
       
  3961         {
       
  3962         iCameraController->DirectSettingsChangeL( ECameraSettingDigitalZoom );
       
  3963         });
       
  3964 
       
  3965       // If no leave occurred, notification is done in HandleSettingEventL
       
  3966       if( KErrNone != error )
       
  3967         {
       
  3968         NotifyControllerObservers( ECamEventZoomStateChanged, error );
       
  3969         }
       
  3970 
       
  3971       // iZoomWaitingForCamera is set to EFalse when vf frame arrives.
       
  3972       // With direct vf, this never happens, so do not set to ETrue.
       
  3973       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3974       if ( appUi && !appUi->IsDirectViewfinderActive() )
       
  3975         {
       
  3976         iZoomWaitingForCamera = ETrue;
       
  3977         }
       
  3978       iNewZoomPending = EFalse;
       
  3979       }
       
  3980     else
       
  3981       {
       
  3982       PRINT( _L("Camera <> CCamAppController: zoom is waiting for VF update") );
       
  3983       iNewZoomPending = ETrue;
       
  3984       }
       
  3985     }
       
  3986   PRINT( _L("Camera <= CCamAppController::SetZoomValue") );
       
  3987   }
       
  3988 
       
  3989 
       
  3990 
       
  3991 // ---------------------------------------------------------------------------
       
  3992 // CCamAppController::ResetUserSceneL
       
  3993 // Resets all the user scene settings to their defaults.
       
  3994 // ---------------------------------------------------------------------------
       
  3995 //
       
  3996 void CCamAppController::ResetUserSceneL()
       
  3997     {
       
  3998     iSettingsModel->ResetUserSceneL();
       
  3999     }
       
  4000 
       
  4001 // ---------------------------------------------------------------------------
       
  4002 // CCamAppController::PreviewSettingChangeL
       
  4003 // 
       
  4004 // Previews a new value for the specified integer setting.
       
  4005 // If method leaves, preview is not activated.
       
  4006 // ---------------------------------------------------------------------------
       
  4007 //
       
  4008 void 
       
  4009 CCamAppController::PreviewSettingChangeL( TInt aSettingItem, 
       
  4010                                           TInt aSettingValue )
       
  4011   {
       
  4012   PRINT( _L("Camera => CCamAppController::PreviewSettingChangeL") );
       
  4013   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4014   
       
  4015   TCamSettingItemIds settingId( 
       
  4016       static_cast<TCamSettingItemIds>(aSettingItem) );
       
  4017 
       
  4018   PRINT1( _L("Camera <> Setting to be previewed [%s]"), KCamSettingItemNames[settingId] );
       
  4019 
       
  4020   if ( settingId == ECamSettingItemDynamicSelfTimer )
       
  4021       {
       
  4022       SetSlideInSelfTimerPreview(ETrue);
       
  4023       }
       
  4024 
       
  4025   // Activate the preview as a first thing.
       
  4026   // If requests are issued to Camera Controller,
       
  4027   // it asks for the setting value through Setting Provider and
       
  4028   // the setting needs to be already in preview at that point.
       
  4029   // If this fails, there's nothing we need to roll back.
       
  4030   iSettingsPreviewHandler->ActivatePreviewL( settingId, aSettingValue );
       
  4031 
       
  4032 
       
  4033   // Check which setting is previewed.
       
  4034   // Some need special attention, or should/need not be set to Camera at this point.
       
  4035   TInt status( KErrNone );
       
  4036   switch( settingId )
       
  4037     {
       
  4038     // ---------------------------------
       
  4039     // Image quality
       
  4040     case ECamSettingItemPhotoQuality:
       
  4041       // Still image quality does not require re-prepare,
       
  4042       // as even the remining images counting is done 
       
  4043       // based on local size esimates.
       
  4044       // Need to do notification to update counters.
       
  4045       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4046       break;
       
  4047     // ---------------------------------
       
  4048     // Video quality
       
  4049     case ECamSettingItemVideoQuality:
       
  4050       // Video needs to be re-prepared to be able to update
       
  4051       // remaining time counters.
       
  4052       NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4053       break;
       
  4054     // ---------------------------------
       
  4055     // Self timer
       
  4056     case ECamSettingItemDynamicSelfTimer:
       
  4057       // Just set the preview. Once committed, set via AppUi.
       
  4058       break;
       
  4059     // ---------------------------------
       
  4060     // Others - set to Camera to see the effect.
       
  4061     default:
       
  4062       {
       
  4063       TCamCameraSettingId cameraId( 
       
  4064         CCamSettingConversion::Map2CameraControllerSettingId( settingId ) );
       
  4065 
       
  4066       //PRINT1( _L("Camera <> CCamAppController: Setting the preview to Camera, id[%s]"), KCameraSettingNames[settingId] );
       
  4067 
       
  4068       // Assertation to notice if some setting is not properly handled.
       
  4069       __ASSERT_DEBUG( ECameraSettingNone != cameraId, CamPanic( ECamPanicNotSupported ) );
       
  4070       
       
  4071       if( ECameraSettingNone != cameraId )
       
  4072         {
       
  4073         // Preview is active.
       
  4074         // Camera controller will ask the value during DirectSettingsChangeL.
       
  4075         // Need trap to be able to cancel on failure.
       
  4076         TRAP( status, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4077         }      
       
  4078       break;
       
  4079       }
       
  4080     // ---------------------------------
       
  4081     }
       
  4082 
       
  4083   if( KErrNone != status )
       
  4084     {
       
  4085     PRINT( _L("Camera <> CCamAppController: Problem in preview, cancelling!!!") );     
       
  4086 
       
  4087     // Invalid id does not cause problem here.
       
  4088     iSettingsPreviewHandler->CancelPreview( settingId );
       
  4089     User::Leave( status );
       
  4090     }
       
  4091   PRINT( _L("Camera <= CCamAppController::PreviewSettingChangeL") );
       
  4092   }
       
  4093 
       
  4094 // ---------------------------------------------------------------------------
       
  4095 // CCamAppController::CancelPreviewChangesL
       
  4096 // Cancels all preview changes, since last commit/cancel.
       
  4097 // ---------------------------------------------------------------------------
       
  4098 //
       
  4099 void
       
  4100 CCamAppController::CancelPreviewChangesL()
       
  4101   {
       
  4102   PRINT( _L("Camera => CCamAppController::CancelPreviewChangesL") );
       
  4103 
       
  4104   // Just check non-null, but no panic. 
       
  4105   if ( iSettingsPreviewHandler )
       
  4106     {
       
  4107     RArray<TCamSettingItemIds> previews;
       
  4108     CleanupClosePushL( previews );
       
  4109 
       
  4110     // Get all active previews
       
  4111     iSettingsPreviewHandler->ActivePreviewsL( previews );
       
  4112     // Reset all previews so the Setting Provider does
       
  4113     // not get those values anymore.
       
  4114     iSettingsPreviewHandler->CancelAllPreviews();
       
  4115 
       
  4116     // Reset the original setting values to Camera
       
  4117     TInt                errorOne( KErrNone           );
       
  4118     TInt                errorAll( KErrNone           );    
       
  4119     TCamCameraSettingId cameraId( ECameraSettingNone );
       
  4120     for( TInt i = previews.Count() - 1; i >= 0; i-- )
       
  4121       {
       
  4122       if( ECamSettingItemVideoQuality == previews[i] )
       
  4123         {
       
  4124         TRAP( errorOne, RePrepareVideoL() );
       
  4125         }
       
  4126       else
       
  4127         {
       
  4128         cameraId =
       
  4129           CCamSettingConversion::Map2CameraControllerSettingId( previews[i] );
       
  4130       
       
  4131         if( ECameraSettingNone != cameraId )
       
  4132           {
       
  4133           TRAP( errorOne, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4134           }
       
  4135         /* All previews are not set to Camera.
       
  4136         else
       
  4137           {
       
  4138           errorOne = KErrNotSupported;
       
  4139           }
       
  4140         */
       
  4141         }
       
  4142 
       
  4143       if( KErrNone == errorAll 
       
  4144        && KErrNone != errorOne )
       
  4145         {
       
  4146         errorAll = errorOne;
       
  4147         }
       
  4148       }
       
  4149     User::LeaveIfError( errorAll );
       
  4150 
       
  4151     CleanupStack::PopAndDestroy(); // previews
       
  4152     }
       
  4153   PRINT( _L("Camera <= CCamAppController::CancelPreviewChangesL") );
       
  4154   }
       
  4155 
       
  4156 // ---------------------------------------------------------------------------
       
  4157 // CCamAppController::CommitPreviewChanges
       
  4158 // Commits last preview change.
       
  4159 // ---------------------------------------------------------------------------
       
  4160 //
       
  4161 void 
       
  4162 CCamAppController::CommitPreviewChanges()
       
  4163   {
       
  4164   PRINT( _L("Camera => CCamAppController::CommitPreviewChanges") );
       
  4165   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4166 
       
  4167   // All previews have been set to Camera already.
       
  4168   // Only need to request the model to store new values.
       
  4169   // Currently ignore error, if settings model cannot save the preview.
       
  4170   TRAPD( error, iSettingsPreviewHandler->CommitAllPreviewsL() );
       
  4171   if( KErrNone != error )
       
  4172     {
       
  4173     // Ignored.
       
  4174     PRINT( _L("Camera <> Settings model could not save the preview!!!") );
       
  4175     }
       
  4176   PRINT( _L("Camera <= CCamAppController::CommitPreviewChanges") );
       
  4177   }
       
  4178 
       
  4179 
       
  4180 // ---------------------------------------------------------------------------
       
  4181 // RePrepareVideoL
       
  4182 //
       
  4183 // Helper method for re-preparing video if e.g. a setting change
       
  4184 // requires it. If Camera Controller is currently processing
       
  4185 // some request, set the flag to issue the request later.
       
  4186 //
       
  4187 // Used atleast in PreviewSettingChangeL and CancelPreviewChangesL.
       
  4188 // ---------------------------------------------------------------------------
       
  4189 //
       
  4190 void
       
  4191 CCamAppController::RePrepareVideoL()
       
  4192   {
       
  4193   PRINT( _L("Camera => CCamAppController::RePrepareVideoL") );
       
  4194 
       
  4195   GenerateNextValidVideoPathL();
       
  4196   if( !Busy() )
       
  4197     {
       
  4198     iVideoPrepareNeeded = EFalse;
       
  4199     IssueRequestL( ECamRequestVideoInit );
       
  4200     }
       
  4201   else
       
  4202     {
       
  4203     iVideoPrepareNeeded = ETrue;
       
  4204     }
       
  4205   PRINT( _L("Camera <= CCamAppController::RePrepareVideoL") );
       
  4206   }
       
  4207 
       
  4208 
       
  4209 
       
  4210 // ---------------------------------------------------------------------------
       
  4211 // CCamAppController::IntegerSettingValue
       
  4212 // Returns the current integer value for the specified setting
       
  4213 // ---------------------------------------------------------------------------
       
  4214 //
       
  4215 TInt 
       
  4216 CCamAppController::IntegerSettingValue( TInt aSettingItem ) const
       
  4217   {
       
  4218   // If the requested item is the photo storage location, this must be filtered
       
  4219   // based on the availability of the MMC.
       
  4220   if ( aSettingItem == ECamSettingItemPhotoMediaStorage )
       
  4221     {
       
  4222     return CurrentPhotoStorageLocation();
       
  4223     }
       
  4224 
       
  4225   // If the requested item is the video storage location, this must be filtered
       
  4226   // based on the availability of the MMC.
       
  4227   if ( aSettingItem == ECamSettingItemVideoMediaStorage )
       
  4228     {
       
  4229     return CurrentVideoStorageLocation();
       
  4230     }
       
  4231 
       
  4232   // Not a setting we sometimes need to filter
       
  4233   return IntegerSettingValueUnfiltered( aSettingItem );
       
  4234   }
       
  4235 
       
  4236 // ---------------------------------------------------------------------------
       
  4237 // CCamAppController::IntegerSettingValueUnfiltered
       
  4238 // Returns the current integer value for the specified setting
       
  4239 // ---------------------------------------------------------------------------
       
  4240 //
       
  4241 TInt 
       
  4242 CCamAppController::IntegerSettingValueUnfiltered( TInt aSettingItem ) const
       
  4243   {
       
  4244   if( aSettingItem == ECamSettingItemVideoFileType )
       
  4245     {
       
  4246     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  4247   
       
  4248     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];
       
  4249   
       
  4250     return level.VideoType();
       
  4251     }
       
  4252   // Query the relevant settings model.
       
  4253   return iSettingsModel->IntegerSettingValue( aSettingItem );
       
  4254   }
       
  4255 
       
  4256 // ---------------------------------------------------------------------------
       
  4257 // CCamAppController::SetIntegerSettingValueL
       
  4258 // Sets a new value for the specified integer setting
       
  4259 // ---------------------------------------------------------------------------
       
  4260 //
       
  4261 void 
       
  4262 CCamAppController::SetIntegerSettingValueL( TInt aSettingItem, 
       
  4263                                             TInt aSettingValue )
       
  4264   {
       
  4265   PRINT( _L("Camera => CCamAppController::SetIntegerSettingValueL"))
       
  4266   // Update the settings model.
       
  4267   iSettingsModel->SetIntegerSettingValueL( aSettingItem, aSettingValue );
       
  4268 
       
  4269   // Update observers with any changes that do not directly affect the
       
  4270   // engine. That is, they need to be updated now because the settings model
       
  4271   // will not pass these to this observer.
       
  4272   switch( aSettingItem )
       
  4273     {
       
  4274     case ECamSettingItemPhotoMediaStorage:
       
  4275     case ECamSettingItemVideoMediaStorage:
       
  4276       {
       
  4277       PRINT(_L("Camera SetIntegerSettingValueL calling SetPathnamesToNewStorageL" ))
       
  4278       // reset iForceUseOfPhoneMemory flag when user chooses 
       
  4279       // from settings.
       
  4280       iForceUseOfPhoneMemory = EFalse;
       
  4281       SetPathnamesToNewStorageL(static_cast < TCamMediaStorage > ( aSettingValue ) );
       
  4282       InitCaptureLimitL();
       
  4283       break;
       
  4284       }
       
  4285     case ECamSettingItemDynamicVideoScene:
       
  4286       {
       
  4287       iVideoInitNeeded = ETrue;
       
  4288       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4289       break;
       
  4290       }
       
  4291     case ECamSettingItemDynamicPhotoScene:
       
  4292     case ECamSettingItemUserSceneBasedOnScene:
       
  4293       {
       
  4294       if( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  4295         {
       
  4296         // Check for macro or landscape scene/based on scene and
       
  4297         // set up AF accordingly. For other scenes, the AF mode
       
  4298         // is setup at capture
       
  4299         CheckAfModeForScene();
       
  4300         }
       
  4301       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4302       break;
       
  4303       }
       
  4304     case ECamSettingItemVideoAudioRec:
       
  4305       {
       
  4306       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4307       if ( appUi->IsEmbedded() )
       
  4308         {
       
  4309         iCameraController->DirectSettingsChangeL( ECameraSettingAudioMute );
       
  4310         }
       
  4311       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4312       break;
       
  4313       }
       
  4314     case ECamSettingItemContinuousAutofocus:
       
  4315       {
       
  4316       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemContinuousAutofocus );
       
  4317       IssueSettingsChangeRequestL();
       
  4318       break;
       
  4319       }
       
  4320     case ECamSettingItemPhotoStoreInAlbum:
       
  4321     case ECamSettingItemVideoStoreInAlbum:
       
  4322       {
       
  4323       TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4324               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4325 
       
  4326       iImageSaveActive->SetAddImageToAlbum( aSettingValue == ECamSettYes,
       
  4327                                             defaultAlbumId );
       
  4328       break;
       
  4329       }
       
  4330     case ECamSettingItemRecLocation:
       
  4331       {
       
  4332       // Set the location utility active object
       
  4333       if ( ECamLocationOff == aSettingValue )
       
  4334           {
       
  4335           StopLocationTrail();
       
  4336           }
       
  4337       else if ( ECamLocationOn == aSettingValue )
       
  4338           {
       
  4339           StartLocationTrailL();
       
  4340           }
       
  4341       
       
  4342       // Notify observers
       
  4343       NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4344       break;  
       
  4345       }
       
  4346     // Need to support more zoom settings.
       
  4347     // Digital/extended setting combined to 
       
  4348     // ECamSettingItemPhotoDigitalZoom and ECamSettingItemVideoDigitalZoom
       
  4349     case ECamSettingItemPhotoDigitalZoom:
       
  4350     case ECamSettingItemVideoDigitalZoom:
       
  4351       {
       
  4352       // Notify observers
       
  4353       NotifyControllerObservers( ECamEventZoomSetupChanged );
       
  4354       break;
       
  4355       }
       
  4356 
       
  4357     default:
       
  4358       {
       
  4359       // no action for others here
       
  4360       break;
       
  4361       }
       
  4362     }
       
  4363 
       
  4364   PRINT( _L("Camera <= CCamAppController::SetIntegerSettingValueL"))        
       
  4365   }
       
  4366 
       
  4367 
       
  4368 
       
  4369 // ---------------------------------------------------------------------------
       
  4370 // CCamAppController::SetPathnamesToNewStorageL
       
  4371 // Sets pathnames for video and image files to point to new storage
       
  4372 // ---------------------------------------------------------------------------
       
  4373 void CCamAppController::SetPathnamesToNewStorageL( TCamMediaStorage aMediaStorage )
       
  4374   {    
       
  4375   PRINT(_L("Camera => CCamAppController::SetPathnamesToNewStorageL" ))
       
  4376   
       
  4377   iSetNewPathnamesPending = ECamMediaStorageNone;
       
  4378   TFileName path;
       
  4379   
       
  4380   // If the engine is prepared for image capture then check that the required 
       
  4381   // image folder exists
       
  4382   if ( IsFlagOn( CameraControllerState(), ECamImageOn ) )
       
  4383     {
       
  4384     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4385                                      aMediaStorage, 
       
  4386                                      path, 
       
  4387                                      ECamControllerImage, 
       
  4388                                      EFalse ); 
       
  4389     iCurrentStorage = aMediaStorage;
       
  4390     }
       
  4391    
       
  4392   // If the engine is prepared for video capture then check that the required 
       
  4393   // month folder exists and set up the engine with the new video path, this
       
  4394   // will be adjusted with the appropriate month counter folder when video
       
  4395   // capture begins
       
  4396   else if ( IsFlagOn( CameraControllerState(), ECamVideoOn ) )
       
  4397     {
       
  4398     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4399                                      aMediaStorage, 
       
  4400                                      path, 
       
  4401                                      ECamControllerVideo, 
       
  4402                                      EFalse ); 
       
  4403      if( iInfo.iOperation != ECamCapturing    &&
       
  4404           iInfo.iOperation != ECamPausing      &&
       
  4405           iInfo.iOperation != ECamPaused       &&
       
  4406           iInfo.iOperation != ECamResuming   &&
       
  4407           iInfo.iOperation != ECamCompleting )
       
  4408       {
       
  4409        GenerateNextValidVideoPathL();
       
  4410       }
       
  4411     iCurrentStorage = aMediaStorage;
       
  4412     
       
  4413     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  4414     
       
  4415     if( !appUi->SettingsLaunchedFromCamera() )
       
  4416       {
       
  4417       // Set video name change pending and request setting it to camera controller.
       
  4418       if( iInfo.iOperation != ECamCapturing    &&
       
  4419           iInfo.iOperation != ECamPausing      &&
       
  4420           iInfo.iOperation != ECamPaused       &&
       
  4421           iInfo.iOperation != ECamResuming   &&
       
  4422           iInfo.iOperation != ECamCompleting )
       
  4423     	{
       
  4424         iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  4425         // Can't set the new pathname, if camera controller is busy.
       
  4426         if ( CameraControllerBusy() )
       
  4427           {
       
  4428           PRINT( _L("Camera <> Camera controller busy. New pathname not set. Set iSetNewPathnamesPending.") )
       
  4429           iSetNewPathnamesPending = aMediaStorage;
       
  4430           }
       
  4431         else
       
  4432           {
       
  4433           IssueSettingsChangeRequestL();
       
  4434           }
       
  4435     	}
       
  4436         
       
  4437       iVideoNameRetries   = KVideoNameRetryCount;    
       
  4438       //iVideoTimeRemaining = KMaxRecordingLength;
       
  4439       if( iInfo.iOperation == ECamCapturing    ||
       
  4440           iInfo.iOperation == ECamPausing      ||
       
  4441           iInfo.iOperation == ECamPaused       ||
       
  4442           iInfo.iOperation == ECamResuming     ||
       
  4443           iInfo.iOperation == ECamCompleting )
       
  4444         {          
       
  4445         iVideoTimeRemaining = iCameraController->RemainingVideoRecordingTime();  
       
  4446         }
       
  4447       else 
       
  4448         {
       
  4449         PRINT( _L("Camera <> CCamAppController::SetPathnamesToNewStorageL - video mode not yet initialized" ));
       
  4450         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  4451         if( KErrNone != err )
       
  4452           {
       
  4453           iVideoTimeRemaining = 0;
       
  4454           }
       
  4455         }
       
  4456       }
       
  4457     }
       
  4458     
       
  4459   // The engine is not yet prepared, the folder will be checked when the engine preparation
       
  4460   // takes place. The controller also checks the state of iSetNewPathnamesPending when 
       
  4461   // preparation completes, just in case preparation is currently in progress.
       
  4462   else
       
  4463     {
       
  4464     iSetNewPathnamesPending = aMediaStorage;
       
  4465     }  
       
  4466               
       
  4467   NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4468   PRINT(_L("Camera <= CCamAppController::SetPathnamesToNewStorageL" ))
       
  4469   }
       
  4470 
       
  4471 // ---------------------------------------------------------------------------
       
  4472 // CCamAppController::SetTextSettingValueL
       
  4473 // Sets a new text value for the specified setting
       
  4474 // ---------------------------------------------------------------------------
       
  4475 //
       
  4476 void 
       
  4477 CCamAppController::SetTextSettingValueL(       TInt   aSettingItem, 
       
  4478                                          const TDesC& aSettingValue )
       
  4479   {
       
  4480   // Update the relevant settings model.
       
  4481   iSettingsModel->SetTextSettingValueL( aSettingItem, aSettingValue );
       
  4482   }
       
  4483 
       
  4484 
       
  4485 // ---------------------------------------------------------------------------
       
  4486 // CCamAppController::TextSettingValue
       
  4487 // Returns the current text value for the specified setting
       
  4488 // ---------------------------------------------------------------------------
       
  4489 //
       
  4490 TPtrC 
       
  4491 CCamAppController::TextSettingValue( TInt aSettingItem ) const
       
  4492   {
       
  4493   // Query the relevant settings model.
       
  4494   return iSettingsModel->TextSettingValue( aSettingItem );
       
  4495   }
       
  4496 
       
  4497 // ---------------------------------------------------------------------------
       
  4498 // CCamAppController::SettingValueEnabled
       
  4499 // Returns whether a particular setting value can be set or not.
       
  4500 // ---------------------------------------------------------------------------
       
  4501 //
       
  4502 TBool 
       
  4503 CCamAppController::SettingValueEnabled( TInt aSettingItem, 
       
  4504                                         TInt aSettingValue ) const 
       
  4505   {
       
  4506   return iSettingsModel->SettingValueEnabled( aSettingItem, aSettingValue );
       
  4507   }
       
  4508 
       
  4509 // ---------------------------------------------------------------------------
       
  4510 // CCamAppController::LoadStaticSettingsL
       
  4511 // Loads the static settings from shared data
       
  4512 // ---------------------------------------------------------------------------
       
  4513 //
       
  4514 void 
       
  4515 CCamAppController::LoadStaticSettingsL( TBool aIsEmbedded )
       
  4516   {
       
  4517   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 1" );
       
  4518   PRINT(_L("Camera => CCamAppController::LoadStaticSettingsL" ))
       
  4519   iSettingsModel->LoadStaticSettingsL( aIsEmbedded );
       
  4520   
       
  4521   // Cache the image 'add to album' setting in the saving active object
       
  4522   // it will change infrequently
       
  4523   TInt value = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoStoreInAlbum );
       
  4524   
       
  4525   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4526               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4527   iImageSaveActive->SetAddImageToAlbum( value == ECamSettYes,
       
  4528                                         defaultAlbumId );
       
  4529 
       
  4530   // Ensure that the navipane is upto date with the current save location.
       
  4531   if ( !aIsEmbedded )
       
  4532     {
       
  4533     NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4534     NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4535     }
       
  4536     NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4537     NotifyControllerObservers( ECamEventVideoStabChanged );
       
  4538     if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
  4539         {
       
  4540         NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4541         }
       
  4542     NotifyControllerObservers( ECamEventVideoFileTypeChanged );
       
  4543   NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4544   NotifyControllerObservers( ECamEventContAFStateChanged ); 
       
  4545   PRINT(_L("Camera <= CCamAppController::LoadStaticSettingsL" ))
       
  4546   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 0" );
       
  4547   }
       
  4548 
       
  4549 
       
  4550 // ---------------------------------------------------------------------------
       
  4551 // DynamicSettingDefaultValue
       
  4552 // Get the setting default value.
       
  4553 // ---------------------------------------------------------------------------
       
  4554 //
       
  4555 TInt 
       
  4556 CCamAppController::DynamicSettingDefaultValue( TInt aSettingId ) const
       
  4557   {
       
  4558   return iSettingsModel->DynamicSettingDefaultValue( aSettingId );
       
  4559   }
       
  4560 
       
  4561 // ---------------------------------------------------------------------------
       
  4562 // CCamAppController::SetDynamicSettingsToDefaults
       
  4563 // Sets all dynamic settings to their defaults.
       
  4564 // ---------------------------------------------------------------------------
       
  4565 //
       
  4566 void 
       
  4567 CCamAppController::SetDynamicSettingsToDefaults()
       
  4568   {
       
  4569   iSettingsModel->SetDynamicSettingsToDefaults();
       
  4570   }
       
  4571 
       
  4572 // ---------------------------------------------------------------------------
       
  4573 // CCamAppController::SetDynamicSettingsToDefaults
       
  4574 // Sets a dynamic setting to its default.
       
  4575 // ---------------------------------------------------------------------------
       
  4576 //
       
  4577 void 
       
  4578 CCamAppController::SetDynamicSettingToDefault(TInt aSettingItem)
       
  4579   {
       
  4580   iSettingsModel->SetDynamicSettingToDefault(aSettingItem);
       
  4581   }
       
  4582 
       
  4583 // ---------------------------------------------------------------------------
       
  4584 // SetDynamicSettingToSceneDefaultL
       
  4585 // 
       
  4586 // Set the dynamic setting identified by aSettingId to scene default.
       
  4587 // Because video and photo scenes can have sama identifiers, aVideoScene
       
  4588 // is needed to decide which ones to look for.
       
  4589 // ---------------------------------------------------------------------------
       
  4590 //
       
  4591 TInt
       
  4592 CCamAppController::SetDynamicSettingToSceneDefaultL( TInt  aSceneId,
       
  4593                                                      TInt  aSceneField,
       
  4594                                                      TInt  aSettingId,
       
  4595                                                      TBool aVideoScene )
       
  4596   {
       
  4597   return iSettingsModel->SetDynamicSettingToSceneDefaultL( aSceneId, 
       
  4598                                                            aSceneField, 
       
  4599                                                            aSettingId,
       
  4600                                                            aVideoScene );
       
  4601   }
       
  4602 
       
  4603 
       
  4604 
       
  4605 
       
  4606 #ifdef PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4607 // ---------------------------------------------------------------------------
       
  4608 // CCamAppController::VideoSceneDefaultsAreSet
       
  4609 // Returns whether the video setup settings are set to the defaults
       
  4610 // for its current scene.
       
  4611 // ---------------------------------------------------------------------------
       
  4612 //
       
  4613 TBool 
       
  4614 CCamAppController::VideoSceneDefaultsAreSet()
       
  4615     {
       
  4616     return iSettingsModel->VideoSceneDefaultsAreSet();
       
  4617     }
       
  4618 
       
  4619 // ---------------------------------------------------------------------------
       
  4620 // CCamAppController::PhotoSceneDefaultsAreSet
       
  4621 // Returns whether the photo setup settings are set to the defaults
       
  4622 // for its current scene.
       
  4623 // ---------------------------------------------------------------------------
       
  4624 //
       
  4625 TBool 
       
  4626 CCamAppController::PhotoSceneDefaultsAreSet()
       
  4627     {
       
  4628     return iSettingsModel->PhotoSceneDefaultsAreSet();
       
  4629     }
       
  4630 
       
  4631 #endif // PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4632 
       
  4633 
       
  4634 // ---------------------------------------------------------------------------
       
  4635 // CCamAppController::CurrentFullFileName
       
  4636 // ---------------------------------------------------------------------------
       
  4637 //
       
  4638 const TDesC& 
       
  4639 CCamAppController::CurrentFullFileName() const
       
  4640   {
       
  4641   PRINT1( _L("Camera => CCamAppController::CurrentFullFileName, index:%d"), iCurrentImageIndex );
       
  4642   const TDesC& name( BurstCaptureArray()->FileName( iCurrentImageIndex ) );
       
  4643 
       
  4644   if( name != KNullDesC )
       
  4645     {
       
  4646     PRINT1( _L("Camera <= CCamAppController::CurrentFullFileName, return:[%S]"), &name );
       
  4647     }
       
  4648   else
       
  4649     {
       
  4650     PRINT( _L("Camera <= CCamAppController::CurrentFullFileName, name not set.") ); 
       
  4651     }   
       
  4652   return name;
       
  4653   }
       
  4654 
       
  4655 const TDesC& 
       
  4656 CCamAppController::CurrentVideoFileName() const
       
  4657   {
       
  4658   return iSuggestedVideoPath;
       
  4659   }
       
  4660 
       
  4661 // ---------------------------------------------------------------------------
       
  4662 // CCamAppController::CCamAppController
       
  4663 // C++ default constructor can NOT contain any code, that
       
  4664 // might leave.
       
  4665 // ---------------------------------------------------------------------------
       
  4666 //
       
  4667 CCamAppController::CCamAppController()
       
  4668   : iBusyFlags( EBusyNone )
       
  4669   , iDiskCriticalLevel   ( KErrNotFound )
       
  4670   , iRamDiskCriticalLevel( KErrNotFound )
       
  4671   , iImageOrientation( ECamOrientation0 )
       
  4672   , iLastImageOrientation( ECamOrientation0 )
       
  4673   {
       
  4674   }
       
  4675 
       
  4676 // ---------------------------------------------------------------------------
       
  4677 // CCamAppController::ConstructL
       
  4678 // Symbian 2nd phase constructor can leave.
       
  4679 // ---------------------------------------------------------------------------
       
  4680 //
       
  4681 void CCamAppController::ConstructL()
       
  4682   {
       
  4683   PRINT( _L("Camera => CCamAppController::ConstructL"));
       
  4684   iPendingAFRequest=0;
       
  4685   iCurrentAFRequest=0;
       
  4686   iNoBurstCancel=EFalse;
       
  4687 
       
  4688   PRINT( _L("Camera <> CCamAppController::ConstructL - constructing Configuration Manager"));
       
  4689   iConfiguration = CCamConfiguration::NewL();      
       
  4690   
       
  4691  
       
  4692   CCamFolderUtility::ResetCounters( iMonthFolderCounters );
       
  4693   iCaptureKeyPressedWhileImageSaving = EFalse;
       
  4694 
       
  4695   iCaptureModeTransitionInProgress = ETrue;
       
  4696 
       
  4697   iSettingsModel = CCamSettingsModel::NewL( *iConfiguration );  
       
  4698   iSettingsModel->AttachObserverL( this );
       
  4699   
       
  4700   // Get the config pointer from settings model
       
  4701   iConfigManager = static_cast<CCamSettingsModel*>(iSettingsModel)->UiConfigManagerPtr();
       
  4702   
       
  4703   RArray<TInt> supportedValues;
       
  4704   CleanupClosePushL( supportedValues );
       
  4705     
       
  4706   // Get the EV slider info
       
  4707   // these values should be read before camsettingsprovided is constructd
       
  4708   // as the EV step value is needed during the construction of camsettingsprovider.
       
  4709   iConfigManager->SupportedEVSettingsL( supportedValues );
       
  4710 
       
  4711   if ( supportedValues.Count() > 0 )
       
  4712       {
       
  4713       iEvRange.iMinValue     = supportedValues[0];
       
  4714       iEvRange.iMaxValue     = supportedValues[1];
       
  4715       iEvRange.iStepsPerUnit = supportedValues[2];      
       
  4716       }
       
  4717 
       
  4718   CleanupStack::PopAndDestroy( &supportedValues );
       
  4719     
       
  4720   // The Settings Model handles the previews at the moment
       
  4721   iSettingsPreviewHandler = static_cast<CCamSettingsModel*>( iSettingsModel ); 
       
  4722 
       
  4723   //iSettingProvider = CCamConstantSettingProvider::NewL( *this );
       
  4724   iSettingProvider = CCamSettingProvider::NewL( *this, iSettingsModel );
       
  4725  
       
  4726   iDeepSleepTimer = CCamTimer::NewL( KDeepSleepTimeout, 
       
  4727                     TCallBack( CCamAppController::DeepSleepTimeout, this ) );
       
  4728   
       
  4729   iIdleTimer             = CCamTimer::NewL( KIdleTimeout, 
       
  4730                                             TCallBack( CCamAppController::IdleTimeoutL, this ) );
       
  4731   iImageSaveActive       = CCamImageSaveActive::NewL( *this , *this );        
       
  4732   iCaptureArray          = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4733   iRotationArray         = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4734   iSequenceFilenameArray = new( ELeave ) CDesCArraySeg( KTimelapseArrayGranularity );
       
  4735   iSoundPlayer           = CCamAudioPlayerController::NewL( *this, *this );
       
  4736 
       
  4737   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  4738        {
       
  4739        // create property watcher for slide state
       
  4740        PRINT( _L("Camera <> CCamAppController: Define Camera slider P&S key..") );
       
  4741        
       
  4742        // Whole slider position reading could be removed after PCFW has implemented
       
  4743        // creation for KLensCoverStatus key
       
  4744        TInt sliderPosition;
       
  4745        TInt err = RProperty::Get(
       
  4746                    CameraPlatPSKeys::KPSCameraPlatUid,
       
  4747                    CameraPlatPSKeys::KLensCoverStatus,
       
  4748                    sliderPosition );  
       
  4749   
       
  4750  
       
  4751        if( err != KErrNone )
       
  4752            {
       
  4753            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4754                    NMusResourceApi::KCategoryUid, 
       
  4755                    NMusResourceApi::KCameraAvailability );
       
  4756            }
       
  4757        else
       
  4758            {
       
  4759            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4760                    CameraPlatPSKeys::KPSCameraPlatUid, 
       
  4761                    CameraPlatPSKeys::KLensCoverStatus );
       
  4762            }
       
  4763        }
       
  4764   
       
  4765   if ( iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
  4766       {
       
  4767       iKeyLockStatusWatcher  = CCamPropertyWatcher::NewL( *this,
       
  4768                                                           KPSUidAvkonDomain,
       
  4769                                                           KAknKeyguardStatus );      
       
  4770       }
       
  4771   // read central repository value indicating whether camera shutter sound
       
  4772   // should be played always or depending on the current profile setting
       
  4773   CRepository* cr = CRepository::NewLC( KCRUidCamcorderFeatures );
       
  4774   TInt value;
       
  4775   TInt err;
       
  4776   User::LeaveIfError( cr->Get( KCRCamShutterSound, value ) );
       
  4777   CleanupStack::PopAndDestroy( cr );
       
  4778   iShutterSndAlwaysOn = value;
       
  4779         
       
  4780   // get data for monitoring free RAM during sequence capture
       
  4781   CamUtility::GetPsiInt( ECamPsiSnapshotSize, iSnapshotDataSize );
       
  4782 
       
  4783   iConfiguration->GetPsiIntArrayL( ECamPsiJpegDataSizes, iJpegDataSizes );
       
  4784   iConfiguration->GetPsiIntArrayL( ECamPsiSequencePostProcessDataSizes,
       
  4785                                    iSequencePostProcessDataSizes );
       
  4786                                
       
  4787   if ( iConfigManager && iConfigManager->IsCaptureToneDelaySupported() )
       
  4788     {
       
  4789     TInt captureToneDelay = iConfigManager->CaptureToneDelay();
       
  4790     TCallBack captureToneCb( CCamAppController::CaptureToneDelayTimeout, this );
       
  4791     iCaptureToneDelayTimer = 
       
  4792         CCamTimer::NewL( captureToneDelay * KMicroSecsInMilliSec, 
       
  4793                          captureToneCb );
       
  4794     }
       
  4795 
       
  4796   PRINT( _L("Camera <> CCamAppController: Define Camera focused P&S key..") );
       
  4797   err = RProperty::Define( KPSUidCamcorderNotifier, 
       
  4798                                  KCCorFocused,
       
  4799                                  RProperty::EInt );
       
  4800   if ( KErrNone != err )
       
  4801     {
       
  4802     // Error handling. Remove warning.
       
  4803     }
       
  4804     
       
  4805   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() )
       
  4806       { // Publish zoom state
       
  4807       iContextFwClient = CCFClient::NewL( *this );
       
  4808       
       
  4809       // Defining the context using the Context Framework.
       
  4810       err = iContextFwClient->DefineContext(
       
  4811                                             KCamContextSource,
       
  4812                                             KCamContextType,
       
  4813                                             KCamContextSecurity );
       
  4814       if( KErrNone == err )
       
  4815         {
       
  4816         iDefineContextSuccessful = ETrue;
       
  4817         PublishZoomStateL( EFalse );
       
  4818         }
       
  4819       else
       
  4820         {
       
  4821         // We make sure that we dont proceed with publishing the zoom state
       
  4822         // if the context definition fails.
       
  4823         iDefineContextSuccessful = EFalse;
       
  4824         }      
       
  4825       } // Publish zoom state
       
  4826 
       
  4827   iLocationTrailStarted = EFalse;
       
  4828 
       
  4829   CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, iLongSequenceLimit );
       
  4830 
       
  4831   User::LeaveIfError( iFs.Connect() ); 
       
  4832   iDriveChangeNotifier = CCamDriveChangeNotifier::NewL( iFs, *this ); 
       
  4833 
       
  4834   PRINT( _L("Camera <= CCamAppController::ConstructL"));
       
  4835   }
       
  4836 
       
  4837 
       
  4838 
       
  4839 /*
       
  4840 * CCamAppController::PublishZoomStateL
       
  4841 */
       
  4842 void CCamAppController::PublishZoomStateL( const TBool aEnabled )
       
  4843   {
       
  4844   // We publish the zoom state only when context definition is
       
  4845   // successful. the value of the zoom state is controlled by the
       
  4846   // boolean flag "aEnabled".
       
  4847   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() ) 
       
  4848       {
       
  4849       if ( iDefineContextSuccessful )
       
  4850         {
       
  4851         CCFContextQuery* query = CCFContextQuery::NewLC();
       
  4852         query->SetSourceL( KCamContextSource );
       
  4853         query->SetTypeL( KCamContextType );
       
  4854         RContextObjectArray result;
       
  4855         TInt err = iContextFwClient->RequestContext( *query, result );
       
  4856         if( err == KErrNone  && result.Count() > 0 )
       
  4857             {
       
  4858             if ( aEnabled )
       
  4859                 {
       
  4860                 result[0]->SetValueL( KCamContextValueEnable );
       
  4861                 }
       
  4862             else
       
  4863                 {
       
  4864                 result[0]->SetValueL( KCamContextValueDisable );
       
  4865                 }
       
  4866             TInt err = iContextFwClient->PublishContext( *result[0] );
       
  4867             if ( err != KErrNone )
       
  4868                 {
       
  4869                 // Define how to handle the error case.
       
  4870                 }
       
  4871             }
       
  4872         else
       
  4873             {
       
  4874             // ignoring the error case.
       
  4875             }
       
  4876             result.ResetAndDestroy();
       
  4877             CleanupStack::PopAndDestroy( query );
       
  4878         }      
       
  4879       }
       
  4880   }
       
  4881 
       
  4882 
       
  4883    
       
  4884 // ---------------------------------------------------------------------------
       
  4885 // CCamAppController::IsViewFinding
       
  4886 // Check if viewfinder is active
       
  4887 // ---------------------------------------------------------------------------
       
  4888 //
       
  4889 TBool CCamAppController::IsViewFinding() const
       
  4890   {
       
  4891   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  4892   return ( iCameraController
       
  4893         && iCameraController->ViewfinderState() == ECamTriActive );
       
  4894   }
       
  4895     
       
  4896 
       
  4897 
       
  4898 // ---------------------------------------------------------------------------
       
  4899 // CCamAppController::NotifyControllerObservers
       
  4900 // Notify the controller observers that a new controller event has occurred
       
  4901 // ---------------------------------------------------------------------------
       
  4902 //
       
  4903 void 
       
  4904 CCamAppController
       
  4905 ::NotifyControllerObservers( TCamControllerEvent aEvent,
       
  4906                              TInt                aError ) const
       
  4907   {
       
  4908   PRINT( _L("Camera => CCamAppController::NotifyControllerObservers"));
       
  4909   // We might need to stop notification for some time.
       
  4910   if( !iMuteNotifications )
       
  4911     {
       
  4912     for ( TInt i = 0; i < iControllerObservers.Count(); i++ )
       
  4913       {
       
  4914       // NON-NULL checked when adding observers.
       
  4915       // If the notification leaves, continue for the other observers
       
  4916       TRAP_IGNORE( iControllerObservers[i]->HandleControllerEventL( aEvent, aError ) )
       
  4917       }
       
  4918     }
       
  4919   PRINT( _L("Camera <= CCamAppController::NotifyControllerObservers"));
       
  4920   }
       
  4921 
       
  4922 
       
  4923 
       
  4924 // ---------------------------------------------------------------------------
       
  4925 // ---------------------------------------------------------------------------
       
  4926 //
       
  4927 void 
       
  4928 CCamAppController
       
  4929 ::EnterViewfinderMode( const TCamCameraMode& aMode )
       
  4930   {
       
  4931   PRINT( _L("Camera => CCamAppController::EnterViewfinderMode"));
       
  4932 
       
  4933   TInt error( KErrNone );
       
  4934   iPendingRelease = EFalse;
       
  4935 
       
  4936   // start monitoring mmc dismount notifications
       
  4937   StartDismountMonitoring();
       
  4938   
       
  4939   if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  4940       {
       
  4941       TRAP_IGNORE ( PublishZoomStateL( ETrue ) );
       
  4942       }
       
  4943 
       
  4944   // Clear these just in case some video prepare is pending.
       
  4945   iVideoPrepareNeeded = EFalse;
       
  4946 
       
  4947   
       
  4948   if( ECamControllerVideo == aMode )
       
  4949     {
       
  4950     // Filename generation needs to be done in all case, not only
       
  4951     // when the current path is null.  
       
  4952     // if( KNullDesC() == iSuggestedVideoPath )
       
  4953       {
       
  4954       TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  4955       }
       
  4956 
       
  4957     // Clear this to be sure it doesn't block recording
       
  4958     iVideoRequested = EFalse;
       
  4959     SetTargetMode     ( ECamControllerVideo  );
       
  4960     SetTargetImageMode( ECamImageCaptureNone );
       
  4961     // shutdown the orientation channel when going to videomode
       
  4962 		if ( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  4963 			{
       
  4964 	    TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  4965 			}
       
  4966     }
       
  4967   else if( ECamControllerImage == aMode )
       
  4968     {
       
  4969     SetTargetMode     ( ECamControllerImage    );
       
  4970 //    SetTargetImageMode( ECamImageCaptureSingle );
       
  4971     SetTargetImageMode( CurrentImageModeSetup() );
       
  4972     }
       
  4973   else
       
  4974     {
       
  4975     SetOperation( ECamStandby, KErrGeneral );
       
  4976     return;
       
  4977     }
       
  4978 
       
  4979   iInfo.iTargetVfState = ECamTriActive;
       
  4980   if( !Busy() )
       
  4981     {
       
  4982     TRAP( error, IssueModeChangeSequenceL() );
       
  4983     if ( KErrNone    != error
       
  4984       && ECamStandby != iInfo.iOperation )
       
  4985       {
       
  4986       SetOperation( ECamStandby, error );
       
  4987       }
       
  4988     }
       
  4989   else
       
  4990     {
       
  4991     // operation will continue when busy sequence or request completes
       
  4992     }
       
  4993   PRINT( _L("Camera <= CCamAppController::EnterViewfinderMode"));
       
  4994   }
       
  4995 
       
  4996 // ---------------------------------------------------------------------------
       
  4997 // ---------------------------------------------------------------------------
       
  4998 //
       
  4999 void 
       
  5000 CCamAppController::ExitViewfinderMode( const TCamCameraMode& aMode )
       
  5001   {
       
  5002   PRINT( _L("Camera => CCamAppController::ExitViewfinderMode"));
       
  5003   // The check here is to ensure that the viewfinder isn't stopped by the still precapture
       
  5004   // view when it has just lost the foreground to the video precapture view and vice versa.
       
  5005   // In that case the mode in parameter would not match the target mode.
       
  5006   if( iInfo.iOperation != ECamStandby )
       
  5007     {
       
  5008     if ( aMode == iInfo.iTargetMode )
       
  5009       {
       
  5010       iInfo.iTargetVfState = ECamTriIdle;
       
  5011       SetTargetImageMode( ECamImageCaptureNone );
       
  5012   
       
  5013       if( !Busy() )
       
  5014         {
       
  5015         if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  5016             {
       
  5017             TRAP_IGNORE ( PublishZoomStateL( EFalse ) );            
       
  5018             }
       
  5019         TRAPD( error, IssueDirectRequestL( ECamRequestVfRelease ) );
       
  5020         if ( KErrNone             != error
       
  5021           && ECamStandby != iInfo.iOperation )
       
  5022           {
       
  5023           SetOperation( ECamStandby, error );
       
  5024           }
       
  5025         }
       
  5026       else
       
  5027         {
       
  5028         // operation will continue when busy sequence or request completes
       
  5029         }
       
  5030       }
       
  5031     }
       
  5032   PRINT( _L("Camera <= CCamAppController::ExitViewfinderMode"));
       
  5033   }
       
  5034 
       
  5035 
       
  5036 // ---------------------------------------------------------------------------
       
  5037 // CCamAppController::StartViewFinder();
       
  5038 // Non-leaving version of StartViewFinderL() 
       
  5039 // ---------------------------------------------------------------------------
       
  5040 //
       
  5041 void 
       
  5042 CCamAppController::StartViewFinder()
       
  5043   {
       
  5044   PRINT( _L("Camera => CCamAppController::StartViewFinder" ))
       
  5045   iInfo.iTargetVfState = ECamTriActive; 
       
  5046 
       
  5047   if( !Busy() )
       
  5048     {
       
  5049     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STARTVIEWFINDER, "e_CAM_APP_VF_INIT 0" );   //CCORAPP_APP_VF_INIT_END
       
  5050     OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STARTVIEWFINDER, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
       
  5051     
       
  5052     TRAPD( error, IssueDirectRequestL( ECamRequestVfStart ) );
       
  5053     if ( KErrNone    != error
       
  5054       && ECamStandby != iInfo.iOperation )
       
  5055       {
       
  5056       PRINT( _L("Camera <> CCamAppController::StartViewFinder - [ERROR] VF start failed, go to standby" ))
       
  5057       SetOperation( ECamStandby, error );
       
  5058       }
       
  5059     }
       
  5060   else
       
  5061     {
       
  5062     // Vf started at earliest convenient time when ongoing requests finish.
       
  5063     }
       
  5064   PRINT(_L("Camera <= CCamAppController::StartViewFinder") );
       
  5065   }
       
  5066 
       
  5067 // ---------------------------------------------------------------------------
       
  5068 // StopViewFinder
       
  5069 // Stop the viewfinder immediately
       
  5070 // ---------------------------------------------------------------------------
       
  5071 //
       
  5072 void 
       
  5073 CCamAppController::StopViewFinder()
       
  5074   {
       
  5075   PRINT( _L("Camera => CCamAppController::StopViewFinderNow" ) )
       
  5076   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5077   
       
  5078   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5079 
       
  5080   if ( iBacklightTimer && iBacklightTimer->IsActive() )
       
  5081     {
       
  5082     iBacklightTimer->Cancel();
       
  5083     }
       
  5084   
       
  5085   // Only stop if active.
       
  5086   // Idle and inactive need no action at this point.
       
  5087   if( ECamTriActive == iCameraController->ViewfinderState() )
       
  5088     {
       
  5089     iInfo.iTargetVfState = ECamTriInactive;
       
  5090     
       
  5091     // Can only fail to OOM when state is checked.
       
  5092     TRAPD( error, iCameraController->DirectRequestL( ECamRequestVfStop ) );
       
  5093     if( KErrNone             != error 
       
  5094      && ECamStandby != iInfo.iOperation )
       
  5095       {
       
  5096       SetOperation( ECamStandby, error );
       
  5097       }
       
  5098     }
       
  5099     
       
  5100   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5101     
       
  5102   PRINT( _L("Camera <= CCamAppController::StopViewFinderNow" ) )
       
  5103   }
       
  5104 
       
  5105 // ---------------------------------------------------------------------------
       
  5106 // StopViewFinderEcam
       
  5107 // Stop the viewfinder immediately without changing states
       
  5108 // ---------------------------------------------------------------------------
       
  5109 //
       
  5110 void 
       
  5111 CCamAppController::StopViewFinderEcam()
       
  5112   {
       
  5113   PRINT( _L("Camera => CCamAppController::StopViewFinderEcam" ) )
       
  5114   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5115   
       
  5116   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5117   
       
  5118   // Trap and ignore error
       
  5119   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestVfStopEcam ) );
       
  5120   
       
  5121   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5122     
       
  5123   PRINT( _L("Camera <= CCamAppController::StopViewFinderEcam" ) )
       
  5124   }
       
  5125 
       
  5126 // ---------------------------------------------------------------------------
       
  5127 // CCamAppController::FreezeViewFinder
       
  5128 // Copy the next viewfinder frame then stop the viewfinder
       
  5129 // ---------------------------------------------------------------------------
       
  5130 //
       
  5131 void CCamAppController::FreezeViewFinder( TBool aFreeze )
       
  5132   {
       
  5133   // If the viewfinder needs to freeze
       
  5134   if ( aFreeze )
       
  5135     {
       
  5136     PERF_MESSAGE_L2( EPerfMessagePausingViewFinder );
       
  5137     iFreezeViewFinder  = ETrue;
       
  5138     iUpdateFrozenFrame = ETrue;
       
  5139     }
       
  5140   // Restarting the viewfinder
       
  5141   else 
       
  5142     {
       
  5143     iFreezeViewFinder  = EFalse;
       
  5144     iUpdateFrozenFrame = EFalse;
       
  5145     if ( ECamTriActive != iCameraController->ControllerInfo().iVfState )
       
  5146       {
       
  5147       StartViewFinder();
       
  5148       }
       
  5149     }
       
  5150   }
       
  5151 
       
  5152 
       
  5153 // ---------------------------------------------------------------------------
       
  5154 // CCamAppController::SetKeyUp
       
  5155 // Set  iKeyUP value which is used to determine if burst
       
  5156 // timer should be activated or not
       
  5157 // ---------------------------------------------------------------------------
       
  5158 //
       
  5159 void CCamAppController::SetKeyUp( TBool aValue /*= EFalse*/ )
       
  5160     {
       
  5161     PRINT1(_L("Camera => CCamAppController::SetKeyUp, iKeyUP=%d"), aValue );
       
  5162     iKeyUP=aValue; 
       
  5163     }
       
  5164 
       
  5165 // ---------------------------------------------------------------------------
       
  5166 // CCamAppController::DoCaptureL
       
  5167 // Initiate image capture
       
  5168 // ---------------------------------------------------------------------------
       
  5169 //
       
  5170 TBool CCamAppController::DoCaptureL()
       
  5171   {
       
  5172   PRINT( _L("Camera => CCamAppController::DoCaptureL()"));
       
  5173   PRINT2(_L("Camera <> mode[%s] imagemode[%s]"), KCamModeNames[iInfo.iMode], KCamImageModeNames[iInfo.iImageMode] );
       
  5174 
       
  5175   // ReleaseArray();
       
  5176   if( iImageSaveActive->Count() <= 0 )
       
  5177       {
       
  5178       ReleaseArray( ETrue );
       
  5179       }
       
  5180   iCurrentImageIndex = 0;
       
  5181   iArrayUsageCount   = KImageArrayUsers;
       
  5182 
       
  5183   iCameraWoken = EFalse;
       
  5184     
       
  5185   TBool continueWithCapture = ETrue;
       
  5186   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  5187   
       
  5188   // Capture needed as fast as possible.
       
  5189   // Use direct stopping of viewfinder
       
  5190   // unless there are settings pending,
       
  5191   // otherwise cancel capture
       
  5192   if ( !IsFlagOn( iBusyFlags, EBusySetting ) )
       
  5193       {
       
  5194       // Stop VF for burst mode or for secondary or
       
  5195       // embedded camera before capturing.
       
  5196       // VF stopping will increase capture lag.
       
  5197       if ( iInfo.iImageMode == ECamImageCaptureBurst ||
       
  5198            iInfo.iActiveCamera == ECamActiveCameraSecondary ||
       
  5199            appUi->IsEmbedded() )
       
  5200           {
       
  5201           StopViewFinder();
       
  5202           }
       
  5203       }
       
  5204   else
       
  5205       {
       
  5206       continueWithCapture = EFalse;
       
  5207       }
       
  5208   
       
  5209 
       
  5210   switch( iInfo.iImageMode )
       
  5211     {
       
  5212     // -----------------------------------------------------
       
  5213     // Burst capture
       
  5214     case ECamImageCaptureBurst:
       
  5215       {
       
  5216       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureBurst") );
       
  5217       /*
       
  5218       TCamPhotoSizeId sizeId( GetCurrentImageResolution() );
       
  5219 
       
  5220       TInt memoryNeed( iJpegDataSizes[sizeId]
       
  5221                      + iSequencePostProcessDataSizes[sizeId] 
       
  5222                      + iSnapshotDataSize );  
       
  5223       TInt memoryFree( 0 );
       
  5224       HAL::Get( HALData::EMemoryRAMFree, memoryFree ); // error ignored
       
  5225 
       
  5226       if( memoryFree < memoryNeed )
       
  5227         {      
       
  5228         PRINT( _L( "Camera <> Not enough memory for more burst captures - complete capture" ) );  
       
  5229         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5230         // Force re-prepare of engine
       
  5231         appUi->HandleCommandL( ECamCmdSequence );
       
  5232                 
       
  5233         // Display out of memory note
       
  5234         NotifyControllerObservers( ECamEventSnapshotReady, KErrNoMemory );
       
  5235                 
       
  5236         // Return app to burst precapture state from burst in-capture
       
  5237         SetOperation( ECamNoOperation );
       
  5238         NotifyControllerObservers( ECamEventCaptureComplete );  
       
  5239                 
       
  5240         // Force update of UI furniture
       
  5241         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5242         appUi->UpdateCba();
       
  5243 
       
  5244         iCaptureRequested = EFalse;
       
  5245         HandleCaptureCompletion();
       
  5246         continueWithCapture = EFalse;
       
  5247         }
       
  5248       else
       
  5249         {
       
  5250         iSequenceCaptureInProgress = ETrue;  
       
  5251         iActualBurstCount = 0;
       
  5252         FreezeViewFinder( ETrue );
       
  5253         // Stop the screensaver from coming on when burst mode is active
       
  5254         EnableScreenSaver( EFalse );
       
  5255         // Make navi counter update itself
       
  5256         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5257         }
       
  5258       */
       
  5259 
       
  5260       if( !appUi->SelfTimerEnabled() )
       
  5261         {
       
  5262         // Start timer to change burst mode to press and hold
       
  5263         // if not determined to be short burst before that.
       
  5264         
       
  5265         //One such case is if capturekeyup event has occured before
       
  5266         //DocaptureL method
       
  5267         if( !iKeyUP && !iNoBurstCancel )
       
  5268             {
       
  5269             StartBurstTimerL();            
       
  5270             }
       
  5271         }
       
  5272       iSequenceCaptureInProgress = ETrue;  
       
  5273        iValueIsStored = EFalse;
       
  5274       FreezeViewFinder( ETrue );
       
  5275       EnableScreenSaver( EFalse );
       
  5276 	  if(  iBacklightTimer 
       
  5277        && !iBacklightTimer->IsActive() )
       
  5278         {
       
  5279         iBacklightTimer->Start( 0,
       
  5280                                 KBacklighTimerInterval, 
       
  5281                                 TCallBack( ResetInactivityTimer, this ) );
       
  5282         }
       
  5283       NotifyControllerObservers( ECamEventCounterUpdated );
       
  5284 
       
  5285       break;
       
  5286       }
       
  5287     // -----------------------------------------------------
       
  5288     // Timelapse capture
       
  5289     case ECamImageCaptureTimeLapse:
       
  5290       {
       
  5291       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureTimeLapse") );
       
  5292       iSequenceCaptureInProgress = ETrue;  
       
  5293       // Stop the screensaver from coming on when burst mode is active
       
  5294       EnableScreenSaver( EFalse );
       
  5295             
       
  5296       // Get the remaining image count and only start the timer for the next capture if there is enough
       
  5297       // space, taking into account that the current capture will also use up one image     
       
  5298       TCamMediaStorage storage( (TCamMediaStorage)IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) );
       
  5299       TCamPhotoSizeId  sizeId ( GetCurrentImageResolution() );
       
  5300 
       
  5301       TInt remainingCount = ImagesRemaining( storage, ETrue, sizeId );
       
  5302 
       
  5303       // Check if the advanced sequence is limited (by starting from selftimer)
       
  5304       if( remainingCount  >= 1
       
  5305        && iRequestedCaptureCount <= TimeLapseImageCount()+1 )
       
  5306         {
       
  5307         iCompleteTimeLapsePending = ETrue;
       
  5308         }
       
  5309             
       
  5310       // if there isn't space for this capture (e.g. some memory has been used since the timer was initiated
       
  5311       // or there isn't enough space to initiate a further capture
       
  5312       else if ( remainingCount <= 1 )
       
  5313         {
       
  5314         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. only space for one capture, stop timer") );
       
  5315 
       
  5316         // The timer is no longer needed
       
  5317         if ( iTimeLapseTimer )
       
  5318           {
       
  5319           iTimeLapseTimer->Cancel();
       
  5320           delete iTimeLapseTimer;
       
  5321           iTimeLapseTimer = NULL;
       
  5322           }
       
  5323         // if there isn't even enough space for this capture
       
  5324         if ( remainingCount < 1 ) 
       
  5325           {
       
  5326           // complete the timelapse capture now (prevent the current capture from starting)
       
  5327           continueWithCapture = EFalse;
       
  5328           iArrayUsageCount = 0;
       
  5329           CompleteTimeLapseOperation();
       
  5330           }
       
  5331         else // if there isn't enough space to initiate a further capture
       
  5332           {
       
  5333           // ensure that the time lapse capture completes after the current capture
       
  5334           iCompleteTimeLapsePending = ETrue;
       
  5335           }                   
       
  5336         }
       
  5337             
       
  5338       else // there is space to initiate a further capture
       
  5339         {                
       
  5340         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. space for more than this capture, timer set on..") );
       
  5341         if ( !iTimeLapseTimer )
       
  5342           {
       
  5343           RestartTimeLapseTimerL();
       
  5344                 
       
  5345           //Products which support autofocus needs to reduce time for second picture
       
  5346           //about the time needed by autofocus.
       
  5347           if( iConfigManager && iConfigManager->IsAutoFocusSupported() 
       
  5348               && !CurrentSceneHasForcedFocus() )
       
  5349             {
       
  5350             iTimeLapseStartTime = iTimeLapseStartTime - TTimeIntervalSeconds( KFocusingDurationSeconds );
       
  5351             }
       
  5352           }
       
  5353         }
       
  5354       break;
       
  5355       }
       
  5356     // -----------------------------------------------------
       
  5357     // Single capture
       
  5358     case ECamImageCaptureSingle:
       
  5359       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureSingle") );
       
  5360       // Should not take so long to get the image captured and saved,
       
  5361       // but 
       
  5362       EnableScreenSaver( EFalse );
       
  5363       SetCaptureKeyPressedWhileImageSaving(EFalse);
       
  5364       break;
       
  5365     // -----------------------------------------------------
       
  5366     default:
       
  5367       PRINT(_L("Camera <> Not in any image capture mode, LEAVE!!"));
       
  5368       User::Leave( KErrGeneral );
       
  5369       break;
       
  5370     // -----------------------------------------------------
       
  5371     }
       
  5372 
       
  5373   if ( continueWithCapture )
       
  5374     {
       
  5375     IssueRequestL( ECamRequestImageCapture );
       
  5376     // Operation in progress is updated in HandleCameraEventL
       
  5377     // store the orientation at capture time, needed in thumbnail creation
       
  5378     iCaptureOrientation = iLastImageOrientation;
       
  5379     }
       
  5380 
       
  5381   iCaptureStoppedForUsb = EFalse; 
       
  5382   PRINT( _L("Camera <= CCamAppController::DoCaptureL()"));
       
  5383   return continueWithCapture;
       
  5384   }
       
  5385 
       
  5386 
       
  5387 // ---------------------------------------------------------------------------
       
  5388 // CCamAppController::DoRecord
       
  5389 // Initiate video recording
       
  5390 // ---------------------------------------------------------------------------
       
  5391 //
       
  5392 void CCamAppController::DoRecord()
       
  5393   {
       
  5394   PRINT( _L("Camera => CCamAppController::DoRecord") );
       
  5395   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  5396 
       
  5397   StopIdleTimer();
       
  5398 
       
  5399   // No key sounds when recording
       
  5400   TRAP_IGNORE( iSoundPlayer->DisableAllKeySoundsL() );
       
  5401 
       
  5402   PRINT( _L("Camera <> Requesting video capture start..") );
       
  5403   TRAPD( error, IssueRequestL( ECamRequestVideoStart ) );
       
  5404   PRINT1( _L("Camera <> ..request issued, status:%d"), error );
       
  5405 
       
  5406   if( KErrNone != error ) SetOperation( ECamStandby, error );    
       
  5407   else                    SetOperation( ECamCapturing );
       
  5408 
       
  5409   // Request is handled
       
  5410   iVideoRequested = EFalse;
       
  5411 
       
  5412   iCaptureStoppedForUsb = EFalse;
       
  5413   PRINT( _L("Camera <= CCamAppController::DoRecord") );
       
  5414   }
       
  5415 
       
  5416 
       
  5417 // ---------------------------------------------------------------------------
       
  5418 // CCamAppController::ReserveFileNamesL
       
  5419 // Reserve a set of filenames for a burst capture
       
  5420 // ---------------------------------------------------------------------------
       
  5421 //
       
  5422 void 
       
  5423 CCamAppController::ReserveFileNamesL( 
       
  5424     const TCamCameraMode&        aCaptureMode,
       
  5425     const TCamImageCaptureMode&  aImageMode,
       
  5426           TBool                  aForcePhoneMem /*= EFalse*/ )
       
  5427   {
       
  5428   PRINT( _L("Camera => CCamAppController::ReserveFileNamesL") )
       
  5429   TInt captureCount = 1;
       
  5430   TInt store        = ECamMediaStorageNone; 
       
  5431   TBuf<KMaxExtension> extension; 
       
  5432 
       
  5433   // If the next file will be a photo
       
  5434   if ( ECamControllerImage == aCaptureMode )
       
  5435     {         
       
  5436     extension = KImageExtension;
       
  5437     }
       
  5438   // Otherwise the next file will be a video
       
  5439   else
       
  5440     {
       
  5441 #ifndef __WINS__
       
  5442     TCamVideoFileType fileType = static_cast<TCamVideoFileType> 
       
  5443         ( IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5444         
       
  5445     extension = ( ECamVideoMpeg4 == fileType )
       
  5446                 ? KVideoMP4Extension
       
  5447                 : KVideo3GPExtension;
       
  5448 #else
       
  5449     extension = KVideo3GPExtension;
       
  5450 #endif
       
  5451     }
       
  5452 
       
  5453   store = ( ECamControllerImage == aCaptureMode ) ? 
       
  5454                  CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();
       
  5455 
       
  5456   TPath basePath;
       
  5457 
       
  5458   // Take a snapshot of the date - to ensure a sequence on a date boundary isn't split into
       
  5459   // different months
       
  5460   TTime now;
       
  5461   now.HomeTime();
       
  5462   // Need to check that there is enough space for the files. If this is a sequence of 20 images or 
       
  5463   // less then ensure there is enough space in the current folder, otherwise only one space is needed
       
  5464   TInt guaranteedGroup = 1;
       
  5465   if ( captureCount < CCamFolderUtility::KMaxGuaranteedBurstGroup )
       
  5466     {
       
  5467     guaranteedGroup = captureCount;
       
  5468     }
       
  5469   
       
  5470   // Leaves if errors generating the path
       
  5471   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5472                                    store, 
       
  5473                                    basePath, 
       
  5474                                    aCaptureMode, 
       
  5475                                    ETrue, 
       
  5476                                    guaranteedGroup, 
       
  5477                                    now ); 
       
  5478      
       
  5479   iCurrentStorage = static_cast<TCamMediaStorage>( store );  
       
  5480 //  TInt numberSettingId( KErrNotFound );
       
  5481   TInt typeSettingId( KErrNotFound );
       
  5482   TInt baseSettingId( KErrNotFound );
       
  5483   TInt counter( 0 );
       
  5484 
       
  5485   if( ECamControllerVideo == aCaptureMode )
       
  5486     {
       
  5487 //    numberSettingId = ECamSettingItemVideoNumber;
       
  5488     counter         = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5489     typeSettingId   = ECamSettingItemVideoNameBaseType;
       
  5490     baseSettingId   = ECamSettingItemVideoNameBase;
       
  5491     }
       
  5492   else
       
  5493     {
       
  5494 //    numberSettingId = ECamSettingItemPhotoNumber;
       
  5495     counter         = iImageNumberCache;
       
  5496     typeSettingId   = ECamSettingItemPhotoNameBaseType;
       
  5497     baseSettingId   = ECamSettingItemPhotoNameBase;
       
  5498     }
       
  5499 
       
  5500 //  TInt counter( IntegerSettingValue( numberSettingId ) );
       
  5501   TBuf<KCamMaxDateLen> dateNameBase;
       
  5502   TPtrC nameBase;
       
  5503   if ( ECamNameBaseDate == iSettingsModel->IntegerSettingValue( typeSettingId ) )
       
  5504       {       
       
  5505       CamUtility::FormatDateFileNameL( dateNameBase );
       
  5506       nameBase.Set( dateNameBase );
       
  5507       }
       
  5508     else
       
  5509       {
       
  5510       nameBase.Set( TextSettingValue( baseSettingId ) );
       
  5511       }
       
  5512 
       
  5513   RFs rfs;
       
  5514   User::LeaveIfError( rfs.Connect() );
       
  5515   CleanupClosePushL( rfs );        
       
  5516         
       
  5517   TEntry entry;
       
  5518 
       
  5519   TInt namedImages = 0;
       
  5520   while ( namedImages < captureCount )
       
  5521     {
       
  5522     // Generate new name
       
  5523     TFileName newFileName;
       
  5524 
       
  5525     CamUtility::FormatFileName( counter, nameBase, newFileName );
       
  5526 
       
  5527     TFileName newPath( basePath );
       
  5528     newPath.Append( newFileName );
       
  5529     newPath.Append( extension );
       
  5530 
       
  5531     // if there is no file in the current location with this name
       
  5532     TEntry entry;  // Prevent LINT error
       
  5533     TInt ferr = rfs.Entry( newPath, entry );
       
  5534     if ( KErrNotFound == ferr )
       
  5535       {
       
  5536       // A file with that name was not found, so the filename is okay.
       
  5537       PRINT( _L("Camera <> Filename OK.") )
       
  5538       namedImages++;
       
  5539       StoreNextFileNameL( newPath );
       
  5540           
       
  5541       // If this is time lapse capture then the full set of file names
       
  5542       // will be needed for the 'delete sequence' option. The burst capture array
       
  5543       // in timelapse only holds data for one item at a time so a separate array
       
  5544       // is used to keep track of all the images file names. The redundancy in filename
       
  5545       // storage is limited to a single file name.             
       
  5546       if ( ECamImageCaptureTimeLapse == aImageMode )         
       
  5547         {                                     
       
  5548         TRAP_IGNORE( iSequenceFilenameArray->AppendL( newPath ) );
       
  5549         // Update the images captured count
       
  5550         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5551         }
       
  5552       counter++;
       
  5553       }
       
  5554     else if ( KErrNone == ferr )
       
  5555       {
       
  5556       // A file with that name exists already. Increment the counter and try again.
       
  5557       PRINT( _L("Camera <> Filename already in use!") ) 
       
  5558       counter++;   // Try the next index number
       
  5559       }
       
  5560     else
       
  5561       {
       
  5562       // There was some other error. Can not save file -> Leave.
       
  5563       PRINT1( _L("Camera <> File server returned error: %d"), ferr );
       
  5564       User::Leave( ferr );
       
  5565       }
       
  5566       
       
  5567     }
       
  5568   CleanupStack::PopAndDestroy( &rfs );
       
  5569 
       
  5570   // SetIntegerSettingValueL( numberSettingId, counter );
       
  5571   if( ECamControllerVideo == aCaptureMode )
       
  5572     {
       
  5573     SetIntegerSettingValueL( ECamSettingItemVideoNumber, counter );
       
  5574     }
       
  5575   else
       
  5576     {
       
  5577     // SetIntegerSettingValueL called when capture ends. 
       
  5578     iImageNumberCache = counter;
       
  5579     }
       
  5580 
       
  5581   PRINT( _L("Camera <= CCamAppController::ReserveFileNamesL") )
       
  5582   }
       
  5583 
       
  5584     
       
  5585 // ---------------------------------------------------------------------------
       
  5586 // CCamAppController::CreateDummyFileL
       
  5587 // Create dummy file ready for image storage
       
  5588 // ---------------------------------------------------------------------------
       
  5589 //
       
  5590 TInt 
       
  5591 CCamAppController::CreateDummyFileL( RFs& aFs, const TDesC& aFullPath )
       
  5592   {
       
  5593   PRINT1( _L("Camera => CCamAppController::CreateDummyFileL [%S]"), &aFullPath );  
       
  5594   RFile file;
       
  5595   CleanupClosePushL( file );
       
  5596   
       
  5597   TInt err = file.Create( aFs, aFullPath, EFileWrite );
       
  5598   if ( err == KErrNone )
       
  5599     {
       
  5600     // Still image files are made writable and non-hidden
       
  5601     // just before the save operation
       
  5602     // file is set to hidden so that media gallery does not detect it
       
  5603     file.SetAtt( KEntryAttReadOnly|KEntryAttHidden, 0 );
       
  5604     }
       
  5605   
       
  5606   CleanupStack::PopAndDestroy( &file );
       
  5607   
       
  5608   PRINT1( _L("Camera <= CCamAppController::CreateDummyFileL, status:%d"), err );  
       
  5609   return err;
       
  5610   }
       
  5611   
       
  5612   
       
  5613 // ---------------------------------------------------------------------------
       
  5614 // CCamAppController::StoreNextFileNameL
       
  5615 // Add newly generated filename to array of names
       
  5616 // ---------------------------------------------------------------------------
       
  5617 //
       
  5618 void CCamAppController::StoreNextFileNameL( const TDesC& aFullPath )
       
  5619     {
       
  5620     PRINT( _L("Camera => CCamAppController::StoreNextFileNameL") );
       
  5621     TParse parse;
       
  5622     parse.Set( aFullPath, NULL, NULL );
       
  5623     
       
  5624     // Store the path + filename and plain filename for future reference
       
  5625     if( ECamControllerVideo == iInfo.iMode && BurstCaptureArray()->Count() > 0 )
       
  5626       {
       
  5627        BurstCaptureArray()->SetNameL( aFullPath, parse.Name(), 0 );	
       
  5628       }
       
  5629     else
       
  5630       {
       
  5631       BurstCaptureArray()->SetNextNameL( aFullPath, parse.Name() );		
       
  5632       }
       
  5633     
       
  5634     PRINT( _L("Camera <= CCamAppController::StoreNextFileNameL") );
       
  5635     }
       
  5636 
       
  5637 // ---------------------------------------------------------------------------
       
  5638 // CCamAppController::GenerateNextVideoFilePathL
       
  5639 // Generate a new file name and full path to save the next
       
  5640 // video 
       
  5641 // ---------------------------------------------------------------------------
       
  5642 //
       
  5643 void CCamAppController::GenerateNextVideoFilePathL( TBool aForcePhoneMem )
       
  5644   {
       
  5645   PRINT1( _L( "Camera => CCamAppController::GenerateNextVideoFilePathL, force phone mem:%d" ), aForcePhoneMem )    
       
  5646   TInt store = IntegerSettingValue( ECamSettingItemVideoMediaStorage ); 
       
  5647   
       
  5648   TBuf<KMaxExtension> extension;        
       
  5649 
       
  5650 #ifdef __WINS__
       
  5651   extension = KVideo3GPExtension;
       
  5652 #else
       
  5653   // If the video file type is MP3, then display this icon.
       
  5654   TCamVideoFileType fileType = 
       
  5655     static_cast<TCamVideoFileType>( 
       
  5656         IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5657 
       
  5658   extension = (fileType == ECamVideoMpeg4)
       
  5659             ? KVideoMP4Extension
       
  5660             : KVideo3GPExtension;
       
  5661 #endif
       
  5662   
       
  5663   TBuf<KCamMaxDateLen> dateNameBase;
       
  5664   TPtrC baseVideoName;
       
  5665           
       
  5666   if ( iSettingsModel->IntegerSettingValue( 
       
  5667                         ECamSettingItemVideoNameBaseType ) == ECamNameBaseDate )
       
  5668     {       
       
  5669     CamUtility::FormatDateFileNameL( dateNameBase );
       
  5670     baseVideoName.Set( dateNameBase );
       
  5671     }
       
  5672   else
       
  5673     {
       
  5674     baseVideoName.Set( TextSettingValue( ECamSettingItemVideoNameBase ) );
       
  5675     }
       
  5676 
       
  5677   TFileName nextFileName( baseVideoName );
       
  5678 
       
  5679   store = ( ECamControllerImage == iInfo.iMode ) ? 
       
  5680                 CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();  
       
  5681 
       
  5682   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5683 
       
  5684   if ( IsAppUiAvailable() &&
       
  5685        appUi &&
       
  5686        appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) &&
       
  5687        ECamMediaStorageCard == store )
       
  5688     {
       
  5689     if ( ExistMassStorage() )
       
  5690       {
       
  5691       // with multiple drives, the mass memory is the default
       
  5692       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  5693       store = ECamMediaStorageMassStorage;
       
  5694       }
       
  5695     else
       
  5696       {
       
  5697       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  5698       store = ECamMediaStoragePhone;
       
  5699       }
       
  5700     }
       
  5701 
       
  5702   TInt fileNameCounter = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5703  
       
  5704   // Update contents of iSuggestedVideoPath (drive and folders only)
       
  5705   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5706                                    store,
       
  5707                                    iSuggestedVideoPath,
       
  5708                                    ECamControllerVideo,
       
  5709                                    ETrue );
       
  5710                                    
       
  5711   iCurrentStorage = static_cast<TCamMediaStorage>( store );   
       
  5712   // Update contents of iSuggestedVideoPath (appending filename and extension)
       
  5713   CamUtility::GetUniqueNameL( iSuggestedVideoPath, nextFileName, fileNameCounter, extension );
       
  5714   PRINT( _L( "Camera <= CamAppController::GenerateNextVideoFilePathL" ) )
       
  5715   }
       
  5716 
       
  5717 // ---------------------------------------------------------------------------
       
  5718 // CCamAppController::GenerateNextValidVideoPathL
       
  5719 // Generate a new file name and full path to save the next video.
       
  5720 // If the generated file (using settings to suggest the drive) can not be opened
       
  5721 // try again, forcing the file to be on C: instead.
       
  5722 // ---------------------------------------------------------------------------
       
  5723 //
       
  5724 void CCamAppController::GenerateNextValidVideoPathL()
       
  5725   {
       
  5726   PRINT( _L("Camera => CCamAppController::GenerateNextValidVideoPathL()"));    
       
  5727   
       
  5728   // If USB is active, use phone memory
       
  5729   if( CamUtility::IsUsbActive() )
       
  5730       {
       
  5731       GenerateNextVideoFilePathL( ETrue );	
       
  5732       }
       
  5733   else
       
  5734       {    	
       
  5735       // Generate a file path using the settings
       
  5736       TRAPD( err, GenerateNextVideoFilePathL() );
       
  5737       
       
  5738       // If left (possibly due to corrupt MMC), try again with phone memory
       
  5739       if ( err )
       
  5740           {
       
  5741           // If we have got here, we can't access MMC. 
       
  5742           // Don't switch to phone memory, but prepare the engine with a video
       
  5743           // name in phone memory. This will be reset if needed when the user actually
       
  5744           // starts recording
       
  5745           PRINT( _L( "Could not generate next file path!  Corrupt MMC?" ) );
       
  5746           GenerateNextVideoFilePathL( ETrue );    
       
  5747           }
       
  5748       }
       
  5749 
       
  5750   PRINT( _L("Camera <= CCamAppController::GenerateNextValidVideoPathL()"));        
       
  5751   }
       
  5752 
       
  5753 // ---------------------------------------------------------------------------
       
  5754 // CCamAppController::GenerateNextValidImagesPathL
       
  5755 // Generate a new path to save the next image.
       
  5756 // ---------------------------------------------------------------------------
       
  5757 //
       
  5758 void CCamAppController::GenerateNextValidImagesPathL()
       
  5759   {
       
  5760   PRINT( _L("Camera => CCamAppController::GenerateNextValidImagesPathL()"));    
       
  5761   // Generate a file path using the settings
       
  5762   // Ensure the image folder exists
       
  5763   TFileName path;
       
  5764   TInt storage = IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  5765   CCamFolderUtility::GetBasePathL( iMonthFolderCounters,
       
  5766                                    storage,
       
  5767                                    path,
       
  5768                                    ECamControllerImage,
       
  5769                                    EFalse ); 
       
  5770                                    
       
  5771   iCurrentStorage = static_cast<TCamMediaStorage>( storage );                                 
       
  5772   PRINT( _L("Camera <= CCamAppController::GenerateNextValidImagesPathL()"));        
       
  5773   }    
       
  5774 
       
  5775 
       
  5776 // ---------------------------------------------------------------------------
       
  5777 // CCamAppController::CaptureModeTranstionInProgress
       
  5778 // Report whather a capture mode is currently being prepared
       
  5779 // ---------------------------------------------------------------------------
       
  5780 //
       
  5781 TBool CCamAppController::CaptureModeTransitionInProgress()
       
  5782   {
       
  5783   PRINT1( _L("Camera => CCamAppController::CaptureModeTransitionInProgress (%d)"), iCaptureModeTransitionInProgress )
       
  5784   return iCaptureModeTransitionInProgress;
       
  5785   }
       
  5786 
       
  5787 // ---------------------------------------------------------------------------
       
  5788 // CCamAppController::HandleSaveEvent
       
  5789 // From MCamImageSaveObserver.
       
  5790 // Handle completion of image saving
       
  5791 // ---------------------------------------------------------------------------
       
  5792 //
       
  5793 void 
       
  5794 CCamAppController::HandleSaveEvent( TCamSaveEvent aEvent )
       
  5795   {
       
  5796   PRINT3( _L( "Camera => CCamAppController::HandleSaveEvent .. event[%s] imagemode[%s] operation[%s]" ),
       
  5797           KCamSaveEventNames       [aEvent          ],
       
  5798           KCamImageModeNames       [iInfo.iImageMode], 
       
  5799           KCamCaptureOperationNames[iInfo.iOperation] )
       
  5800    
       
  5801   TBool mediaFileChanged = EFalse;     
       
  5802   
       
  5803   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5804   if( ( iCaptureArray->ImagesRemaining() <= 0 ) 
       
  5805           && appUi 
       
  5806           && appUi->IsInPretendExit() )
       
  5807       {
       
  5808       ReleaseArray( ETrue );
       
  5809       }
       
  5810   
       
  5811   if( ECamSaveEventCriticalError == aEvent )
       
  5812     {
       
  5813     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5814     SetOperation( ECamStandby, KErrGeneral );
       
  5815     PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  5816     return;
       
  5817     }
       
  5818 
       
  5819   if( aEvent == ECamSaveEventSaveError ) 
       
  5820     {
       
  5821     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5822     if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  5823         SequenceCaptureInProgress() )
       
  5824         {
       
  5825         // Cancel ongoing burst capture
       
  5826         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  5827         // and actual cancelling is done when next imagedata arrives.
       
  5828         // However, in this case camera is going to be released, and there won't
       
  5829         // be next image data, so give ECamRequestImageCancel and capture
       
  5830         // completion event here to avoid problems
       
  5831         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Cancel burst due to error") ); 
       
  5832         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  5833         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );   
       
  5834         }
       
  5835     else
       
  5836         {
       
  5837         PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5838         SetOperation( ECamStandby, KErrGeneral );
       
  5839         }   
       
  5840     PRINT( _L("Camera <= CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5841     return;
       
  5842     }
       
  5843 
       
  5844   // if a save completes 
       
  5845   if ( aEvent == ECamSaveEventComplete )
       
  5846     {
       
  5847     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventComplete") );
       
  5848 
       
  5849 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  5850     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  5851       {
       
  5852       // Do not log in burst mode
       
  5853       PERF_EVENT_END_L1( EPerfEventShotToSave );      
       
  5854       }
       
  5855 #endif
       
  5856 
       
  5857     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SAVE 0" );  //CCORAPP_PRI_SHOT_TO_SAVE_END
       
  5858 
       
  5859     // Check that this is the completion of the last pending 
       
  5860     // single image save.
       
  5861     // Note burst capture completion is handled separately
       
  5862     TBool savedAll   = ( iImageSaveActive->Count()== 0                );
       
  5863     TBool completing = ( ECamCompleting           == iInfo.iOperation );
       
  5864 
       
  5865     switch( iInfo.iImageMode )
       
  5866       {
       
  5867       case ECamImageCaptureNone: // In postcapture, waiting for saving
       
  5868       case ECamImageCaptureSingle:
       
  5869         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureSingle/None") );
       
  5870         if( savedAll )
       
  5871           {
       
  5872           OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );    //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  5873     
       
  5874           PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. calling HandleCaptureCompletion()") );
       
  5875           if( !iSaveStarted )
       
  5876               {
       
  5877               HandleCaptureCompletion();
       
  5878               NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5879               }
       
  5880           else
       
  5881               {
       
  5882               iSaveStarted = EFalse;
       
  5883               }
       
  5884           
       
  5885           // If we have returned from postcapture to precapture before 
       
  5886           // the filename has been sent to the gallery (i.e. pressing back
       
  5887           // key during image processing), iArrayUsageCount will be reduced 
       
  5888           // to zero and capture array will be released. In that case, we must
       
  5889           // send the filename to gallery before it happens.
       
  5890           if ( iArrayUsageCount == 1 )
       
  5891               {
       
  5892               NotifyControllerObservers( ECamEventMediaFileChanged );   
       
  5893               mediaFileChanged = ETrue;
       
  5894               }
       
  5895 
       
  5896           CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5897           if( iImageSaveActive && IsAppUiAvailable() )
       
  5898               {
       
  5899               if( iImageSaveActive->Count() <= 0 && ECamViewStatePostCapture != appUi->CurrentViewState() )
       
  5900                   {
       
  5901                   ReleaseArray();
       
  5902                   }
       
  5903               }
       
  5904           }
       
  5905         break;
       
  5906       case ECamImageCaptureTimeLapse:
       
  5907         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureTimeLapse") );
       
  5908         // If image capture has finished, but waiting for file to be saved.
       
  5909         if( ECamNoOperation == iInfo.iOperation || ECamCompleting == iInfo.iOperation )
       
  5910           {
       
  5911           PRINT( _L("Camera <> CCamAppController .. current file saved, complete this capture") );
       
  5912           SetOperation( ECamNoOperation );
       
  5913           ReleaseArray();
       
  5914           }
       
  5915         break;        
       
  5916       case ECamImageCaptureBurst:
       
  5917         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureBurst") );
       
  5918         // After the whole burst has stopped, we get Image Stop event from Camera Controller,
       
  5919         // and enter completing state.
       
  5920         if( completing && savedAll )
       
  5921           {
       
  5922           // Modify this event to "burst complete" one.
       
  5923           aEvent = ECamSaveEventBurstComplete;
       
  5924           }
       
  5925         break;
       
  5926       default:
       
  5927         break;
       
  5928       } 
       
  5929 
       
  5930     NotifyControllerObservers( ECamEventSaveComplete );
       
  5931     }
       
  5932   
       
  5933   if ( aEvent == ECamSaveEventStarted )
       
  5934      {
       
  5935      if( iInfo.iImageMode == ECamImageCaptureSingle )
       
  5936          {
       
  5937          PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Saving started") );
       
  5938          OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 1" ); //CCORAPP_PREP_FOR_NEXT_SHOT_START      
       
  5939          HandleCaptureCompletion();
       
  5940          NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5941          NotifyControllerObservers( ECamEventSaveComplete );
       
  5942          iCaptureRequested = EFalse;
       
  5943          iSaveStarted = ETrue;
       
  5944          OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 0" ); //CCORAPP_PREP_FOR_NEXT_SHOT_END
       
  5945          OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SHOT 0" ); //CCORAPP_PRI_SHOT_TO_SHOT_END   
       
  5946          }
       
  5947      }
       
  5948      
       
  5949   // If the user cancelled a save
       
  5950   if ( aEvent == ECamSaveEventUserCancelled )
       
  5951     {
       
  5952     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventUserCancelled" ) )
       
  5953     //iInfo.iImageMode = ECamImageModeNone;
       
  5954     // Make sure that any further engine callbacks are ignored until next capture
       
  5955     SetOperation( ECamNoOperation );
       
  5956 
       
  5957     // Delete dummy files for unsaved images
       
  5958     TInt nextSavingImage = BurstCaptureArray()->NextFileIndex();
       
  5959     TInt lastImage = BurstCaptureArray()->Count();
       
  5960     TInt i;
       
  5961     // delete the next and following files
       
  5962     for ( i = nextSavingImage; i < lastImage; i++ )
       
  5963       {
       
  5964       SetAsCurrentImage( i );
       
  5965       DeleteCurrentFile();
       
  5966       }
       
  5967     SetAsCurrentImage( 0 );
       
  5968     // Empty out the array - this ensures the thumbnail view doesn't open
       
  5969     BurstCaptureArray()->Reset();
       
  5970 
       
  5971     NotifyControllerObservers( ECamEventSaveCancelled );
       
  5972     }
       
  5973     
       
  5974   // if a burst capture has completed
       
  5975   if ( aEvent == ECamSaveEventBurstComplete )
       
  5976     {
       
  5977     CompleteBurstOperation();
       
  5978 
       
  5979     if( ECamCompleting == iInfo.iOperation )
       
  5980       {
       
  5981       PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. completing burst capture" ) )
       
  5982       SetOperation( ECamNoOperation );
       
  5983       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5984       ReleaseArray();
       
  5985       }
       
  5986 
       
  5987     OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );  //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  5988     }
       
  5989   else
       
  5990     {
       
  5991     if ( iImageSaveActive->Count() == 0 || aEvent == ECamSaveEventStarted )
       
  5992       {
       
  5993       iSaving = EFalse;
       
  5994       }        
       
  5995     }
       
  5996   if ( !mediaFileChanged )
       
  5997       {
       
  5998       NotifyControllerObservers( ECamEventMediaFileChanged );    
       
  5999       }
       
  6000 
       
  6001   PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  6002   }
       
  6003 
       
  6004 
       
  6005 // ---------------------------------------------------------------------------
       
  6006 // HandleViewfinderFrame
       
  6007 // ---------------------------------------------------------------------------
       
  6008 //
       
  6009 void 
       
  6010 CCamAppController::HandleViewfinderFrame( TInt        /*aStatus*/, 
       
  6011                                           CFbsBitmap* /*aFrame*/ )
       
  6012   {
       
  6013   PRINT_FRQ( _L( "Camera => CCamAppController::HandleViewfinderFrame" ) );   
       
  6014 
       
  6015 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6016   // This function is called when a viewfinder bitmap arrives
       
  6017   if( EPerfWaitingForStartup == iPerformanceState )
       
  6018     {
       
  6019     iPerformanceState = EPerfIdle;
       
  6020     PERF_EVENT_END_L1( EPerfEventApplicationStartup );
       
  6021     }   
       
  6022   else if( EPerfWaitingForStillMode == iPerformanceState )
       
  6023     {
       
  6024     iPerformanceState = EPerfIdle;
       
  6025     PERF_EVENT_END_L1( EPerfEventSwitchToStillMode );
       
  6026     }
       
  6027   else if( EPerfWaitingForVideoMode == iPerformanceState )
       
  6028     {
       
  6029     iPerformanceState = EPerfIdle;
       
  6030     PERF_EVENT_END_L1( EPerfEventSwitchToVideoMode );
       
  6031     }
       
  6032   else if( EPerfWaitingForBurstFrame == iPerformanceState )
       
  6033     {
       
  6034     iPerformanceState = EPerfIdle;
       
  6035     PERF_EVENT_END_L1( EPerfEventBurstCaptureMomentToViewfinderFrame );
       
  6036     }
       
  6037 #endif
       
  6038 
       
  6039   if( ECamControllerVideo == iInfo.iMode )
       
  6040     {
       
  6041     // removed first vf frame usage as snapshot.
       
  6042     // snapshot received now from Camera 
       
  6043     }
       
  6044   else if( ECamControllerImage == iInfo.iMode )
       
  6045     {
       
  6046     // No need to duplicate here.
       
  6047     }
       
  6048   else
       
  6049     {
       
  6050     // Not valid state for vf frame.
       
  6051     __ASSERT_DEBUG( EFalse, CamPanic( ECamPanicInvalidState ) );
       
  6052     }
       
  6053 
       
  6054   if ( iZoomWaitingForCamera )
       
  6055     {
       
  6056     iZoomWaitingForCamera = EFalse;
       
  6057     if ( iNewZoomPending )
       
  6058       {
       
  6059       SetZoomValue( iDesiredZoomVal );
       
  6060       }
       
  6061     }
       
  6062   PRINT_FRQ( _L( "Camera <= CCamAppController::HandleViewfinderFrame" ) );
       
  6063   }
       
  6064 
       
  6065 
       
  6066 // ---------------------------------------------------------------------------
       
  6067 // ---------------------------------------------------------------------------
       
  6068 //
       
  6069 void CCamAppController::HandleSnapshotEvent( TInt aStatus,
       
  6070                                              CFbsBitmap* aBitmap )
       
  6071   {
       
  6072   PRINT1( _L( "Camera => CCamAppController::HandleSnapshotEvent, status:%d" ), aStatus );
       
  6073 
       
  6074 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6075   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6076     {
       
  6077     // Do not log in burst mode
       
  6078     PERF_EVENT_END_L1( EPerfEventShotToSnapshot );      
       
  6079     }
       
  6080   else
       
  6081     {
       
  6082     // In burst mode    
       
  6083     PERF_MESSAGE_L2( EPerfMessageBurstSnapshotReady );
       
  6084     }
       
  6085 #endif   
       
  6086 
       
  6087   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESNAPSHOTEVENT, "e_CAM_APP_SHOT_TO_SNAPSHOT 0" );    //CCORAPP_SHOT_TO_SNAPSHOT_END
       
  6088 
       
  6089 // ---------------------------------------------------------------------------
       
  6090 // Video snapshot handling
       
  6091   if( ECamControllerVideo == iInfo.iMode )
       
  6092     {
       
  6093     PRINT( _L("Camera <> Snapshot in video mode") ); 
       
  6094     if( KErrNone == aStatus )
       
  6095       {
       
  6096       // Make a copy of the snapshot and set it as current video ss.        
       
  6097       CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6098       if( iSnapShotCopy )
       
  6099         {
       
  6100         if (BurstCaptureArray()->Count() > 0 )
       
  6101           {
       
  6102           const CFbsBitmap* tempSnapShotCopy = iSnapShotCopy;
       
  6103           TRAP_IGNORE( BurstCaptureArray()->ReplaceSnapshot( tempSnapShotCopy, 0 ) );	
       
  6104           } 
       
  6105         else
       
  6106           {
       
  6107           TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *iSnapShotCopy ) );	
       
  6108           }
       
  6109         }        
       
  6110       }
       
  6111       
       
  6112       // If video recording has already stopped, give snapshot event,
       
  6113       // which causes snapshot to be updated in postcapture view.
       
  6114       // 
       
  6115       // If recording is still in progress, the event would cause
       
  6116       // too early switch to pastcapture.
       
  6117       if( ECamNoOperation == iInfo.iOperation ||
       
  6118           ECamCompleting == iInfo.iOperation )
       
  6119         {  
       
  6120         NotifyControllerObservers( ECamEventSnapshotReady, aStatus );  
       
  6121         }        
       
  6122       
       
  6123     return;
       
  6124     }
       
  6125 
       
  6126 // ---------------------------------------------------------------------------
       
  6127 // Still snapshot handling
       
  6128 
       
  6129   PRINT( _L("Camera <> Snapshot in still mode") ); 
       
  6130 
       
  6131   if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  6132     {
       
  6133     // Update time lapse count during snapshot, so the update counter value
       
  6134     // appears at the same time as snapshot.  
       
  6135     iTimeLapseCaptureCount++;
       
  6136     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6137     }        
       
  6138   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6139     {
       
  6140     // Re-enable the screen saver if burst capture is completing. 
       
  6141     // This has to be done when all captures complete for timelapse.
       
  6142     // EnableScreenSaver( ETrue );
       
  6143     
       
  6144     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6145     iUpdateFrozenFrame = ETrue;    
       
  6146         
       
  6147     }
       
  6148 
       
  6149   // -------------------------------------------------------
       
  6150   // if there is an error with the still capture operation
       
  6151   if ( KErrNone != aStatus )
       
  6152     {
       
  6153     PRINT( _L("Camera <> CCamAppController: error in, cancel saving etc..") );
       
  6154     // Store this now, as it's cleared by TidyCaptureArray
       
  6155     // but needed a little later
       
  6156     TBool wasCapturingBurst = (ECamImageCaptureBurst == iInfo.iImageMode);
       
  6157 
       
  6158     iImageSaveActive->Cancel();
       
  6159 
       
  6160     TidyCaptureArray( BurstCaptureArray()->NextFileIndex(), aStatus );
       
  6161     PRINT( _L("Camera <> cancel further capturing") );
       
  6162     TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  6163 
       
  6164     NotifyControllerObservers( ECamEventSnapshotReady, aStatus );
       
  6165 
       
  6166     if ( wasCapturingBurst )
       
  6167       {
       
  6168       // Need this here to allow the AppUi to update the state correctly
       
  6169       // following the error condition.  This needs to be *after* the
       
  6170       // change to OperationNone (called in TidyCaptureArray) so when the 
       
  6171       // AppUi forces CBA update we're not still in burst capture state.
       
  6172       NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6173       }
       
  6174 
       
  6175     PRINT( _L( "Camera <> calling HandleCaptureCompletion()" ) )
       
  6176     HandleCaptureCompletion();
       
  6177     }
       
  6178   // -------------------------------------------------------
       
  6179   // No error reported
       
  6180   else
       
  6181     {
       
  6182     PRINT( _L("Camera <> CCamAppController: status in KErrNone..") );
       
  6183     __ASSERT_ALWAYS( aBitmap, CamPanic( ECamPanicNullPointer ) );
       
  6184 
       
  6185           
       
  6186     CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6187      
       
  6188     // Removed filename reservation when snapshot arrives.
       
  6189     // From now on, it's always done in HandleImageCaptureEvent,
       
  6190     // even if snapshot comes first.
       
  6191        
       
  6192     // This is being ignored, but there is nothing to display in the app
       
  6193     TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *aBitmap ) )
       
  6194 
       
  6195     NotifyControllerObservers( ECamEventSnapshotReady );
       
  6196       
       
  6197     // If this is not a burst capture and snapshot came before image
       
  6198     // data, then the operation is now entering the completion phase.
       
  6199     // In case iFilenameReserved is set, imagedata has already
       
  6200     // arrived and we don't need to change state here.
       
  6201     if ( ECamCompleting != iInfo.iOperation && 
       
  6202          ECamImageCaptureBurst != iInfo.iImageMode && 
       
  6203          !iFilenameReserved )    
       
  6204       {  
       
  6205       SetOperation( ECamCompleting );      
       
  6206       }
       
  6207        
       
  6208     if( CurrentCapturedCount() < CaptureLimit() )
       
  6209         {
       
  6210         // Play capture sound for the next burst image
       
  6211         PlaySound( CaptureToneId(), EFalse );
       
  6212         }
       
  6213 
       
  6214     }
       
  6215   // -------------------------------------------------------
       
  6216 
       
  6217   PRINT( _L( "Camera <= CCamAppController::HandleSnapshotEvent" ) );    
       
  6218   }
       
  6219 
       
  6220 
       
  6221 // ---------------------------------------------------------------------------
       
  6222 // HandleImageCaptureEventL
       
  6223 // ---------------------------------------------------------------------------
       
  6224 //
       
  6225 void
       
  6226 CCamAppController::HandleImageCaptureEventL( TInt             aStatus, 
       
  6227                                              CCamBufferShare* aShare  )
       
  6228   {
       
  6229   PRINT1( _L("Camera => CCamAppController::HandleImageCaptureEventL, status:%d"), aStatus ); 
       
  6230 
       
  6231 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6232   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6233     {
       
  6234     // Do not log in burst mode
       
  6235     PERF_EVENT_END_L1( EPerfEventShotToStillImageReady );     
       
  6236     }
       
  6237   else
       
  6238     {
       
  6239     PERF_MESSAGE_L2( EPerfMessageBurstStillimageReady );
       
  6240     }
       
  6241 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6242 
       
  6243   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLEIMAGECAPTUREEVENTL, "e_CAM_APP_SHOT_TO_STILL 0" );  //CCORAPP_SHOT_TO_STILL_END
       
  6244 /*
       
  6245   // Check if we need to stop the burst capture.        
       
  6246   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6247     {    
       
  6248     if( CurrentCapturedCount() < CaptureLimit() )
       
  6249       {
       
  6250       // Play capture sound for the next burst image
       
  6251       PlaySound( CaptureToneId(), EFalse );
       
  6252       }
       
  6253     }
       
  6254 */
       
  6255    // If we have all the needed snapshots set the flag
       
  6256    // so the processing image text is shown.
       
  6257    // Do it here instead of handlesnapshotevent so that
       
  6258    // the counter has time to show the last image as well 
       
  6259    if( CurrentCapturedCount() == CaptureLimit() )  
       
  6260        {
       
  6261        iAllSnapshotsReceived = ETrue;	
       
  6262        }
       
  6263         
       
  6264   if( KErrNone == aStatus )
       
  6265     {
       
  6266     PRINT( _L("Camera <> CCamAppController: image capture status KErrNone") );
       
  6267     aShare->Reserve();
       
  6268     CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, aShare ) );
       
  6269 
       
  6270     // Reserve filename for saving the image. In case there's problem
       
  6271     // with current media, switch to internal memory
       
  6272     TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) );
       
  6273     if( KErrNone != err )
       
  6274      {
       
  6275      if( ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) )
       
  6276        {
       
  6277        PRINT( _L("Camera <> Memory card access failed.") )
       
  6278        NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  6279        }            
       
  6280        // If we have got here, we can't access MMC. Switch to phone memory
       
  6281         
       
  6282      TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  6283                                               //this actually uses the internal mass memory 
       
  6284      TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) ); 
       
  6285      if( KErrNone != err )
       
  6286       {
       
  6287       PRINT( _L("Camera <> Mass memory or phone memory access also failed.") )
       
  6288       TRAP_IGNORE( ForceUsePhoneMemoryL() );
       
  6289       TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode, ETrue ) );
       
  6290       }                 
       
  6291     }
       
  6292     
       
  6293     TBool markedForDelete = BurstCaptureArray()->IsNextImageDeleted();
       
  6294     PRINT1( _L("Camera <> Next image delete mark:%d"), markedForDelete );
       
  6295     if ( !markedForDelete )
       
  6296       {
       
  6297       PRINT( _L("Camera <> setting iImageSaveRequestPending to false"))
       
  6298       iImageSaveRequestPending = EFalse;
       
  6299       const TDesC& nextName( BurstCaptureArray()->NextFileName() );
       
  6300       PRINT( _L("Camera <> BurstCaptureArray()->NextFileName() returned") );
       
  6301       PRINT1( _L("Camera <> Set image to be saved, name:[%S]"), &nextName );
       
  6302       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6303       if( ( iInfo.iImageMode == ECamImageCaptureSingle ) 
       
  6304               && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto )
       
  6305               && iInfo.iActiveCamera == ECamActiveCameraPrimary
       
  6306               && !appUi->IsEmbedded() )
       
  6307           {
       
  6308           HandleSaveEvent( ECamSaveEventStarted );
       
  6309           }
       
  6310       TBool added = iImageSaveActive->AddToSave( nextName, aShare ); 
       
  6311       
       
  6312       if ( !added )
       
  6313         {
       
  6314         PRINT( _L("Camera <> Image saving start unsuccessful!") );
       
  6315         // The system state is consistent if this fails so ignore the error
       
  6316         }
       
  6317       else
       
  6318         {
       
  6319         PRINT( _L("Camera <> Image saving started ok.") );
       
  6320         // Ownership of the data has now been passed to CCamImageSaveActive
       
  6321         if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6322           {          
       
  6323           NotifyControllerObservers( ECamEventImageData );  
       
  6324           }
       
  6325         PRINT1( _L("Camera <> CCamAppController::HandleImageCaptureEventL array count:%d"), BurstCaptureArray()->Count() );  
       
  6326         // check if snapshot bitmap needs to be rotated before creating a thumbnail from it
       
  6327         TBool rotate( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) &&
       
  6328                       ECamSettOn == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) &&
       
  6329                       iCaptureOrientation != ECamOrientation0 &&
       
  6330                       iInfo.iActiveCamera == ECamActiveCameraPrimary );
       
  6331         if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6332           {
       
  6333           //create thumbnail or rotate first if needed
       
  6334           if ( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  6335               {
       
  6336               if ( rotate )
       
  6337                   {
       
  6338                   RotateSnapshotL();
       
  6339                   }
       
  6340               else
       
  6341                   {       
       
  6342                   TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  6343                   }
       
  6344               } 
       
  6345           }
       
  6346         }
       
  6347       }
       
  6348     CleanupStack::PopAndDestroy(); // aShare->Release()
       
  6349     aShare = NULL;
       
  6350     }
       
  6351   else
       
  6352     {
       
  6353     PRINT( _L("Camera <> CCamAppController: capture status *not* KErrNone, mark current file for delete") );
       
  6354     DeleteCurrentFile();
       
  6355     }
       
  6356 
       
  6357 
       
  6358   iFilenameReserved = ETrue;
       
  6359 
       
  6360   PRINT( _L( "Camera <= CCamAppController::HandleImageCaptureEventL" ) );        
       
  6361   }
       
  6362 
       
  6363 
       
  6364 
       
  6365 // ---------------------------------------------------------------------------
       
  6366 // HandleImageStopEventL
       
  6367 // ---------------------------------------------------------------------------
       
  6368 //
       
  6369 void
       
  6370 CCamAppController::HandleImageStopEventL( TInt aStatus, TInt aFullCaptureCount )
       
  6371   {
       
  6372   PRINT2( _L("Camera => CCamAppController::HandleImageStopEventL, status:%d, full captures:%d"), aStatus, aFullCaptureCount );
       
  6373 
       
  6374   TBool saved = ( iImageSaveActive->Count()== 0 );
       
  6375 
       
  6376   switch( iInfo.iImageMode )
       
  6377     {
       
  6378     // -----------------------------------------------------
       
  6379     case ECamImageCaptureBurst:
       
  6380       {
       
  6381       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureBurst" ) );
       
  6382       // CompleteBurstOperation();
       
  6383      
       
  6384       // Re-enable screen saver
       
  6385       EnableScreenSaver( ETrue );
       
  6386       if( iBacklightTimer )
       
  6387         {
       
  6388         iBacklightTimer->Cancel();
       
  6389         }
       
  6390       
       
  6391       TInt started( iCameraController->ControllerInfo().iSnapshotCount );
       
  6392       if ( aFullCaptureCount < started )
       
  6393         {
       
  6394         PRINT ( _L("Camera <> CCamAppController .. [WARNING] Incomplete captures detected, cleaning up.." ) );
       
  6395         PRINT1( _L("Camera <> CCamAppController .. [WARNING] snapshot     count: %d"), started );
       
  6396         PRINT1( _L("Camera <> CCamAppController .. [WARNING] full capture count: %d"), aFullCaptureCount            );
       
  6397         PRINT1( _L("Camera <> CCamAppController .. [WARNING] burst array  count: %d"), BurstCaptureArray()->Count() );
       
  6398         TInt stopAt = Min( started, BurstCaptureArray()->Count() );
       
  6399         for ( TInt index = aFullCaptureCount; index < stopAt; index++ )
       
  6400           {
       
  6401           PRINT1( _L("Camera <> CCamAppController .. [WARNING] deleting temp file from index %d.."), index );
       
  6402           SetAsCurrentImage( index );
       
  6403           // Parameter: notify about file system change only on last delete.
       
  6404           DeleteCurrentFile( stopAt-1 == index );
       
  6405           }
       
  6406         PRINT1( _L("Camera <> CCamAppController .. [WARNING] setting as current image %d.."), aFullCaptureCount );
       
  6407         SetAsCurrentImage( aFullCaptureCount );
       
  6408         PRINT ( _L("Camera <> CCamAppController .. [WARNING] resetting burst array to required count..") );
       
  6409         BurstCaptureArray()->Reset( aFullCaptureCount );
       
  6410         }
       
  6411 
       
  6412       SetOperation( ECamCompleting );
       
  6413 
       
  6414       // We may have deleted all the images, so check the status here.
       
  6415       if( iImageSaveActive->Count()== 0 )
       
  6416         {
       
  6417         PRINT( _L( "Camera <> CCamAppController .. images already saved, completing burst capture" ) )
       
  6418         SetOperation( ECamNoOperation );
       
  6419         NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6420         ReleaseArray();
       
  6421         }
       
  6422       // if no images were taken, clear AssumePostCaptureView flag  
       
  6423       if ( started == 0 )
       
  6424         {
       
  6425         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6426         if ( appUi )
       
  6427           {
       
  6428           appUi->SetAssumePostCaptureView( EFalse );	
       
  6429           }	
       
  6430         }  
       
  6431       break;
       
  6432       }
       
  6433     // -----------------------------------------------------
       
  6434     case ECamImageCaptureSingle:
       
  6435       {
       
  6436       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureSingle" ) );
       
  6437 
       
  6438       // In secondary camera we can get snapshot as last event
       
  6439       // so we might still be in capturing state.
       
  6440       if( ECamCapturing == iInfo.iOperation )
       
  6441         {
       
  6442         PRINT( _L( "Camera <> CCamAppController .. still in capturing phase, set to completing first.." ) );
       
  6443         SetOperation( ECamCompleting );  
       
  6444         }
       
  6445 
       
  6446   	  // In case of secondary camera, image may be saved before Stop event is received.
       
  6447   	  // Notify capture complete event to the observers and other completion handling here.
       
  6448       if( saved && ECamCompleting == iInfo.iOperation )
       
  6449         {
       
  6450         PRINT( _L( "Camera <> CCamAppController .. file saved, complete capture" ) );
       
  6451 
       
  6452 		// Operation mode is also set in HandleCaptureCompletion
       
  6453 		HandleCaptureCompletion();
       
  6454 		NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6455         ReleaseArray();
       
  6456         }
       
  6457       
       
  6458       break;
       
  6459       }
       
  6460     // -----------------------------------------------------
       
  6461     case ECamImageCaptureTimeLapse:
       
  6462       {
       
  6463       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureTimeLapse" ) );
       
  6464       if( saved )
       
  6465         {
       
  6466         PRINT( _L( "Camera <> CCamAppController .. current file saved, complete this capture" ) );
       
  6467         SetOperation( ECamNoOperation );
       
  6468         ReleaseArray();
       
  6469         }
       
  6470 
       
  6471       if ( iCompleteTimeLapsePending )
       
  6472         {
       
  6473         CompleteTimeLapseOperation();
       
  6474         }
       
  6475       else
       
  6476         {
       
  6477         // If the camera orientation changed during capture, set the new orientation in the engine
       
  6478         // ready for the next timelapse capture
       
  6479         if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  6480          		 && iOrientationChangeOccured )  
       
  6481           {
       
  6482           iOrientationChangeOccured = EFalse;
       
  6483           TRAP_IGNORE( SetImageOrientationL() );
       
  6484           }
       
  6485         }   
       
  6486       break;
       
  6487       }
       
  6488     // -----------------------------------------------------
       
  6489     default:
       
  6490       break;
       
  6491     // -----------------------------------------------------
       
  6492     }
       
  6493   PRINT( _L( "Camera <= CCamAppController::HandleImageStopEventL" ) );
       
  6494   }
       
  6495 
       
  6496 
       
  6497 // ---------------------------------------------------------------------------
       
  6498 // CCamAppController::IdleTimeoutL
       
  6499 // ---------------------------------------------------------------------------
       
  6500 //
       
  6501 TInt CCamAppController::IdleTimeoutL( TAny* aPtr )
       
  6502     {
       
  6503     return static_cast<CCamAppController*>( aPtr )->DoIdleTimeoutL();
       
  6504     }
       
  6505 
       
  6506 // ---------------------------------------------------------------------------
       
  6507 // CCamAppController::DoIdleTimeoutL
       
  6508 // ---------------------------------------------------------------------------
       
  6509 //
       
  6510 TInt CCamAppController::DoIdleTimeoutL()
       
  6511   {
       
  6512   // if a video recording has been paused for 60 seconds without key presses
       
  6513   if ( ECamPaused == CurrentVideoOperation() )
       
  6514     {
       
  6515     NotifyControllerObservers( ECamEventVideoPauseTimeout, KErrNone );
       
  6516     }
       
  6517 
       
  6518   // notify switch to standby mode and stop timer
       
  6519   else if( ECamStandby != iInfo.iOperation && ECamTriActive == iCameraController->ViewfinderState())
       
  6520     {
       
  6521     SetOperation( ECamStandby );
       
  6522     }
       
  6523   else
       
  6524     {
       
  6525     // For Lint
       
  6526     }
       
  6527 
       
  6528   iIdleTimer->Cancel();
       
  6529 
       
  6530 // Use backlight timer also with bitmap vf
       
  6531   if( iBacklightTimer )
       
  6532     {
       
  6533 	if( ECamTriActive == iCameraController->ViewfinderState() )
       
  6534 	  {
       
  6535 	  User::ResetInactivityTime();
       
  6536       }
       
  6537     iBacklightTimer->Cancel();
       
  6538     }
       
  6539 
       
  6540   return EFalse;
       
  6541   }
       
  6542 
       
  6543 // ---------------------------------------------------------------------------
       
  6544 // CCamAppController::StartIdleTimer
       
  6545 // ---------------------------------------------------------------------------
       
  6546 //
       
  6547 void CCamAppController::StartIdleTimer()
       
  6548   {
       
  6549   PRINT( _L( "Camera => CCamAppController::StartIdleTimer" ) ); 
       
  6550   // if in standby mode notify of switch back to pre-capture
       
  6551   if ( ECamStandby == iInfo.iOperation )
       
  6552     {
       
  6553     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer ECamStandby" ) );
       
  6554     SetOperation( ECamNoOperation );
       
  6555     }
       
  6556   // if recording is in progress don't go to standby
       
  6557   else if ( ECamCapturing == CurrentVideoOperation() )             
       
  6558     {
       
  6559     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer no restart" ) );
       
  6560     // don't restart if recording operation in progress
       
  6561     return;
       
  6562     }
       
  6563   // if recording is paused, use the idle timer to stop recording after 60 secs
       
  6564   else
       
  6565     {
       
  6566     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer else part" ) );
       
  6567     // empty else statement to remove LINT error
       
  6568     }
       
  6569 
       
  6570   // restart timer
       
  6571   iIdleTimer->Cancel();
       
  6572 
       
  6573   // don't restart if capturing burst, setting time lapse or in a pretend exit state
       
  6574   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6575   if ( !SequenceCaptureInProgress() && appUi && !appUi->IsInPretendExit() 
       
  6576        && !appUi->TimeLapseSliderShown())
       
  6577     {
       
  6578     // restart timer
       
  6579     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer starting timer" ) );
       
  6580     iIdleTimer->StartTimer();
       
  6581     }
       
  6582 
       
  6583   if ( iDeepSleepTimer )
       
  6584     {
       
  6585     if ( iDeepSleepTimer->IsActive() )
       
  6586         {
       
  6587         PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - restart deep sleep timer" ) );
       
  6588         DeepSleepTimerCancel();
       
  6589         DeepSleepTimerStart();
       
  6590         }
       
  6591     else if ( iDeepSleepTimerExpired )
       
  6592         {
       
  6593         iDeepSleepTimerExpired = EFalse; // clear flag
       
  6594         TVwsViewId activeView;
       
  6595         CCamAppUi* appUi = 
       
  6596             static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6597         (void) appUi->GetActiveViewId( activeView ); // ignore error
       
  6598         
       
  6599         if ( !IsViewFinding() && !InVideocallOrRinging() &&
       
  6600             activeView.iViewUid.iUid != ECamViewIdVideoPostCapture && 
       
  6601             activeView.iViewUid.iUid != ECamViewIdStillPostCapture &&
       
  6602             activeView.iViewUid.iUid != ECamViewIdBurstThumbnail )
       
  6603             {
       
  6604             PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - Deep sleep timer expired. Restart VF" ) );
       
  6605             TCamCameraMode mode = CurrentMode() == ECamControllerVideo?
       
  6606                                   ECamControllerVideo : ECamControllerImage;
       
  6607             EnterViewfinderMode( mode ); 
       
  6608             DeepSleepTimerStart();
       
  6609             }
       
  6610         }
       
  6611     }
       
  6612 
       
  6613   PRINT( _L( "Camera <= CCamAppController::StartIdleTimer" ) );
       
  6614   }
       
  6615 
       
  6616 // ---------------------------------------------------------------------------
       
  6617 // CCamAppController::StopIdleTimer
       
  6618 // ---------------------------------------------------------------------------
       
  6619 //
       
  6620 void CCamAppController::StopIdleTimer()
       
  6621     {
       
  6622     PRINT( _L( "Camera => CCamAppController::StopIdleTimer" ) );
       
  6623     if( iIdleTimer )
       
  6624         {
       
  6625         iIdleTimer->Cancel();
       
  6626         }
       
  6627     PRINT( _L( "Camera <= CCamAppController::StopIdleTimer" ) );
       
  6628     }
       
  6629 
       
  6630 // ---------------------------------------------------------------------------
       
  6631 // CCamAppController::TimeLapseTimeoutL
       
  6632 // ---------------------------------------------------------------------------
       
  6633 //
       
  6634 TInt CCamAppController::TimeLapseTimeoutL( TAny* aPtr )
       
  6635     {
       
  6636     return static_cast<CCamAppController*>( aPtr )->DoTimeLapseTimeoutL();
       
  6637     }    
       
  6638     
       
  6639 // ---------------------------------------------------------------------------
       
  6640 // CCamAppController::DoTimeLapseTimeoutL
       
  6641 // ---------------------------------------------------------------------------
       
  6642 //
       
  6643 TInt CCamAppController::DoTimeLapseTimeoutL()
       
  6644   {
       
  6645   PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL" ))      
       
  6646   // Work out how much time is left before the next capture
       
  6647   TTime now;
       
  6648   now.HomeTime();
       
  6649   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  6650   TInt64 remainingTime = iTimeLapseInterval.Int64() - elapsedTime.Int64();              
       
  6651   // update the remaining time countdown 
       
  6652   NotifyControllerObservers( ECamEventCounterUpdated );
       
  6653   
       
  6654   //if the total timelapse period has now completed
       
  6655   if ( remainingTime <= 0 )
       
  6656     {
       
  6657         // Workaround for DoTimeLapseTimeoutL firing while in inappropriate state
       
  6658     	// cause capture to be delayed by 1 sec 
       
  6659     	if( ECamNoOperation != iInfo.iOperation ) 
       
  6660     		{
       
  6661     		PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL workaround" ))      
       
  6662 			//remainingTime = TInt64( KSecondInMicSec );    	
       
  6663 		    iTimeLapseTimer->StartTimer();
       
  6664     		}    	
       
  6665 	else
       
  6666 		{
       
  6667 	    TInt remainingCount = ImagesRemaining( static_cast<TCamMediaStorage>( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ), ETrue );
       
  6668 	    if ( remainingCount > 0 )
       
  6669 	      	{
       
  6670 	      PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL about to do next capture" ))   
       
  6671 	      // About to do the next capture so decrement the view's usage count on the array
       
  6672 	      ReleaseArray();
       
  6673             if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  6674                 {
       
  6675                 if( !CurrentSceneHasForcedFocus() )
       
  6676                     {
       
  6677                     if( !IsViewFinding() )
       
  6678                         {
       
  6679                         StartViewFinder();
       
  6680                         }
       
  6681                     StartAutoFocus();
       
  6682                     iCaptureRequested = ETrue; //Has to be set before focused/not focused event.
       
  6683                     }
       
  6684                 else
       
  6685                     {
       
  6686                     PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL capture with forcedfocus scene" ))   
       
  6687                     Capture();            
       
  6688                     }
       
  6689                 }
       
  6690             else 
       
  6691                 {
       
  6692             	Capture();            
       
  6693                 }
       
  6694 			RestartTimeLapseTimerL();
       
  6695       	}
       
  6696 	    else
       
  6697 	     {
       
  6698 	     		PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL capture is complete" ))   
       
  6699 	      	CompleteTimeLapseOperation();
       
  6700 	     }
       
  6701 	   }              
       
  6702     return EFalse;
       
  6703     }
       
  6704   // Otherwise restart the timer for the next period    
       
  6705   else
       
  6706     {
       
  6707     if ( remainingTime < TInt64( KSecondInMicSec ) )
       
  6708       {
       
  6709       PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL shortening timer" ))   
       
  6710       iTimeLapseTimer->SetTimeout( (TInt)remainingTime );
       
  6711       }
       
  6712      else if(  ( remainingTime < TInt64( 5 *KSecondInMicSec )) && !iCameraWoken )
       
  6713      	{
       
  6714 		iCameraWoken = ETrue;
       
  6715 		if( !IsViewFinding() )
       
  6716 		{
       
  6717 			StartViewFinder();
       
  6718 		}
       
  6719 		User::ResetInactivityTime();     		
       
  6720      	}
       
  6721      
       
  6722     PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL restarting timer" ))               
       
  6723     iTimeLapseTimer->StartTimer();
       
  6724     }
       
  6725   return EFalse;        
       
  6726   }
       
  6727 
       
  6728 // ---------------------------------------------------------------------------
       
  6729 // CCamAppController::SupportedFlashModes
       
  6730 // Return flash modes supported engine
       
  6731 // ---------------------------------------------------------------------------
       
  6732 //
       
  6733 TUint32 CCamAppController::SupportedFlashModes()
       
  6734   {
       
  6735   if( iCameraController )
       
  6736     return iCameraController->CameraInfo().iFlashModesSupported;
       
  6737   else
       
  6738     return 0;
       
  6739   //iSupportedFlashModes;
       
  6740   }
       
  6741   
       
  6742 // ---------------------------------------------------------------------------
       
  6743 // CCamAppController::SupportedWBModes
       
  6744 // Return white balance modes supported engine
       
  6745 // ---------------------------------------------------------------------------
       
  6746 //  
       
  6747 TUint32 CCamAppController::SupportedWBModes()
       
  6748   {
       
  6749   if( iCameraController )
       
  6750     return iCameraController->CameraInfo().iWhiteBalanceModesSupported;
       
  6751   else
       
  6752     return 0;
       
  6753   //iSupportedWBModes;
       
  6754   }
       
  6755   
       
  6756 // ---------------------------------------------------------------------------
       
  6757 // CCamAppController::SupportedEVModes
       
  6758 // Return EV modes supported engine
       
  6759 // ---------------------------------------------------------------------------
       
  6760 //  
       
  6761 TUint32 CCamAppController::SupportedEVModes()
       
  6762   {
       
  6763   if( iCameraController )
       
  6764     return iCameraController->CameraInfo().iExposureModesSupported;
       
  6765   else
       
  6766     return 0;
       
  6767   //iSupportedEVModes;
       
  6768   } 
       
  6769 
       
  6770 // ---------------------------------------------------------------------------
       
  6771 // CCamAppController::CaptureState
       
  6772 // ---------------------------------------------------------------------------
       
  6773 //  
       
  6774 TInt CCamAppController::CaptureState()  
       
  6775   {
       
  6776   if( iCameraController )
       
  6777     {
       
  6778     return iCameraController->ControllerInfo().iCaptureState;
       
  6779     }
       
  6780   else
       
  6781     {
       
  6782     return KErrNotFound;
       
  6783     }
       
  6784   } 
       
  6785 
       
  6786 
       
  6787 
       
  6788 // -----------------------------------------------------------------------------
       
  6789 // CCamAppController::FlashStatus()
       
  6790 // Returns pointer to FlashStatus object
       
  6791 // -----------------------------------------------------------------------------
       
  6792 //
       
  6793 CCamFlashStatus* 
       
  6794 CCamAppController::FlashStatus() const
       
  6795   {
       
  6796   return iFlashStatus;    
       
  6797   }
       
  6798        
       
  6799 
       
  6800 // -----------------------------------------------------------------------------
       
  6801 // CCamAppController::FlashRequired()
       
  6802 // 
       
  6803 // -----------------------------------------------------------------------------
       
  6804 //
       
  6805 TBool 
       
  6806 CCamAppController::FlashRequired() const
       
  6807   {
       
  6808   if( ECamSceneSports == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  6809     {
       
  6810     // Flash is not required in sport scene, even if the flash mode
       
  6811     // is forced or redeye.
       
  6812     return EFalse;
       
  6813     }
       
  6814     
       
  6815   // Make decision based on current flash mode    
       
  6816   TInt flashMode = IntegerSettingValue( ECamSettingItemDynamicPhotoFlash );            
       
  6817   switch( flashMode )
       
  6818     {
       
  6819     case ECamFlashOff:
       
  6820       {
       
  6821       return EFalse;    
       
  6822       }
       
  6823     case ECamFlashAntiRedEye: // Flowthrough
       
  6824     case ECamFlashForced:
       
  6825       {
       
  6826       return ETrue;    
       
  6827       }
       
  6828     default:
       
  6829       {
       
  6830       // Just return true in the default case.
       
  6831       // Automatic mode will decide if flash is used or not.
       
  6832       return ETrue;
       
  6833       }
       
  6834     } 
       
  6835   }
       
  6836 
       
  6837 // -----------------------------------------------------------------------------
       
  6838 // CCamAppController::CheckFlash()
       
  6839 // 
       
  6840 // -----------------------------------------------------------------------------
       
  6841 //     
       
  6842 TBool 
       
  6843 CCamAppController::CheckFlash() const
       
  6844   {            
       
  6845   PRINT ( _L("Camera => CCamAppController::CheckFlash") );
       
  6846   PRINT1( _L("Camera <> CCamAppController:              flash required :%d  "), FlashRequired() );
       
  6847   PRINT1( _L("Camera <> CCamAppController: FlashStatus: flash ready    :%d  "), iFlashStatus->FlashReady() );
       
  6848   PRINT1( _L("Camera <> CCamAppController: CameraCtrl:  flash status   :[%s]"),
       
  6849           KCamCameraReadyStateNames[iCameraController->FlashState()] );
       
  6850 
       
  6851   TBool ok( !FlashRequired() || iFlashStatus->FlashReady() );
       
  6852 
       
  6853   PRINT1( _L("Camera <= CCamAppController::CheckFlash, return:%d"), ok );
       
  6854 #ifdef __WINSCW__
       
  6855   return ETrue;
       
  6856 #else  
       
  6857   return ok;
       
  6858 #endif  
       
  6859   }
       
  6860 
       
  6861 
       
  6862 // -----------------------------------------------------------------------------
       
  6863 // CCamAppController::SaveFlashMode()
       
  6864 // 
       
  6865 // -----------------------------------------------------------------------------
       
  6866 //    
       
  6867 void CCamAppController::SaveFlashMode()
       
  6868   {    
       
  6869   iFlashModeSaved  = ETrue;
       
  6870   iSavedFlashMode  = static_cast<TCamFlashId>( IntegerSettingValue( ECamSettingItemDynamicPhotoFlash ) );
       
  6871   iSavedFlashScene = static_cast<TCamSceneId>( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
  6872   }
       
  6873     
       
  6874 // -----------------------------------------------------------------------------
       
  6875 // CCamAppController::RestoreFlashMode
       
  6876 // 
       
  6877 // -----------------------------------------------------------------------------
       
  6878 //    
       
  6879 void CCamAppController::RestoreFlashMode()
       
  6880   {                
       
  6881   if( iFlashModeSaved )
       
  6882     {
       
  6883     if( iSavedFlashScene == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  6884       {
       
  6885       // Set saved flash mode    
       
  6886       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, iSavedFlashMode ) );
       
  6887       }
       
  6888     else
       
  6889       {
       
  6890       // Set default flash mode for this scene   
       
  6891       // SetDynamicSettingToDefault( ECamSettingItemDynamicPhotoFlash );          
       
  6892       TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  6893       TInt sceneFlashMode = iSettingsModel->SceneSettingValue( scene, ECamSettingItemSceneFlashMode );
       
  6894       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, sceneFlashMode ) );
       
  6895       
       
  6896       }
       
  6897     }
       
  6898   iFlashModeSaved = EFalse;   
       
  6899   }
       
  6900 
       
  6901 
       
  6902 // ---------------------------------------------------------------------------
       
  6903 // CCamAppController::ForceUsePhoneMemoryL
       
  6904 // ---------------------------------------------------------------------------
       
  6905 //
       
  6906 void CCamAppController::ForceUsePhoneMemoryL( TBool aEnable )
       
  6907 	{
       
  6908 	PRINT( _L("Camera => CCamAppController::ForceUsePhoneMemoryL") );
       
  6909 
       
  6910 	if( aEnable )
       
  6911 		{
       
  6912 		iForceUseOfPhoneMemory = ETrue;
       
  6913     if( ExistMassStorage() )
       
  6914       {
       
  6915       // with multiple drives, the mass memory is the default
       
  6916       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  6917       iForcedStorageLocation = ECamMediaStorageMassStorage;
       
  6918       SetPathnamesToNewStorageL( ECamMediaStorageMassStorage );
       
  6919       }
       
  6920     else
       
  6921       {
       
  6922       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  6923       iForcedStorageLocation = ECamMediaStoragePhone;
       
  6924       SetPathnamesToNewStorageL( ECamMediaStoragePhone );
       
  6925       }
       
  6926 		}
       
  6927 	// Revert back to memory card, if aEnable is EFalse
       
  6928 	else
       
  6929 		{
       
  6930 		iForceUseOfPhoneMemory = EFalse;
       
  6931     iForcedStorageLocation = ECamMediaStorageNone;
       
  6932     SetPathnamesToNewStorageL( iPreferredStorageLocation );
       
  6933 		}
       
  6934 
       
  6935 	NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  6936 	PRINT( _L("Camera <= CCamAppController::ForceUsePhoneMemoryL") );
       
  6937 	}
       
  6938 
       
  6939 
       
  6940 
       
  6941 // ---------------------------------------------------------------------------
       
  6942 // CCamAppController::IsPhoneMemoryForced
       
  6943 // Check whether the use of phone memory is forced, because of unavailibility 
       
  6944 // or problems encountered in using MMC.
       
  6945 // ---------------------------------------------------------------------------
       
  6946 //
       
  6947 TBool CCamAppController::IsPhoneMemoryForced()
       
  6948 	{
       
  6949 	return iForceUseOfPhoneMemory;
       
  6950 	}
       
  6951 
       
  6952 // ---------------------------------------------------------------------------
       
  6953 // CCamAppController::CheckMemoryToUseL
       
  6954 // Set the appropriate memory to use. Use Phone memory if MMC not available.
       
  6955 // ---------------------------------------------------------------------------
       
  6956 //
       
  6957 TBool CCamAppController::CheckMemoryToUseL()
       
  6958 	{
       
  6959   TInt key = ( ECamControllerImage == CurrentMode() )
       
  6960                ? ECamSettingItemPhotoMediaStorage
       
  6961                : ECamSettingItemVideoMediaStorage;
       
  6962 
       
  6963   TCamMediaStorage storageLocation = static_cast<TCamMediaStorage> ( IntegerSettingValueUnfiltered(key) );
       
  6964   TBool mmcAvailable = IsMemoryAvailable ( ECamMediaStorageCard );
       
  6965     
       
  6966   PRINT1( _L("Camera :: CCamAppController::CheckMemoryToUse preferred storage:%d"), 
       
  6967               storageLocation );
       
  6968     
       
  6969   // If MMC is preferred storage location but is not available 
       
  6970 	if ( storageLocation == ECamMediaStorageCard && !mmcAvailable )
       
  6971 		{
       
  6972 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use phone memory / mass storage") )
       
  6973 		ForceUsePhoneMemoryL( ETrue );
       
  6974 		return ETrue;
       
  6975 		}
       
  6976 	// Preferred location is MMC and its available now -> stop forcing phone memory 
       
  6977 	else if( storageLocation == ECamMediaStorageCard && mmcAvailable && 
       
  6978 	         iForceUseOfPhoneMemory ) 
       
  6979 		{
       
  6980 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use MMC") )
       
  6981 		ForceUsePhoneMemoryL( EFalse );
       
  6982 		return ETrue;
       
  6983 		}
       
  6984   if ( storageLocation == ECamMediaStorageMassStorage && !ExistMassStorage() )
       
  6985 		{
       
  6986 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - no mass storage, use phone memory") )
       
  6987 		ForceUsePhoneMemoryL( ETrue );
       
  6988 		return ETrue;
       
  6989 		}
       
  6990 	// Mass storage is available now -> stop forcing phone memory
       
  6991 	else if( storageLocation == ECamMediaStorageMassStorage && ExistMassStorage() && iForceUseOfPhoneMemory ) 
       
  6992 		{
       
  6993 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use mass memory") )
       
  6994 		ForceUsePhoneMemoryL( EFalse );
       
  6995 		return ETrue;
       
  6996 		}
       
  6997 	else
       
  6998 	  {
       
  6999 	  SetPathnamesToNewStorageL( storageLocation );
       
  7000 	  }
       
  7001 
       
  7002   return EFalse;
       
  7003 	}
       
  7004 
       
  7005 
       
  7006 
       
  7007 // ---------------------------------------------------------------------------
       
  7008 // CCamAppController::CompleteBurstOperation
       
  7009 // Complete the burst operation
       
  7010 // ---------------------------------------------------------------------------
       
  7011 //
       
  7012 void CCamAppController::CompleteBurstOperation()
       
  7013   {
       
  7014   PRINT( _L( "Camera => CCamAppController::CompleteBurstOperation" ) );
       
  7015   iSequenceCaptureInProgress = EFalse;
       
  7016   iNoBurstCancel=EFalse;
       
  7017   
       
  7018   if( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7019       {
       
  7020       PRINT1( _L("Camera <> CCamAppController::CompleteBurstOperation array count:%d"), BurstCaptureArray()->Count() );    
       
  7021       // Create thumbnails
       
  7022       if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  7023           {
       
  7024           TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  7025           }
       
  7026       	
       
  7027       // Re-enable screen saver
       
  7028       EnableScreenSaver( ETrue );
       
  7029 	  if( iBacklightTimer )
       
  7030 		{
       
  7031 		iBacklightTimer->Cancel();
       
  7032 		}
       
  7033       SetOperation( ECamNoOperation );
       
  7034   
       
  7035       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  7036       HandleCaptureCompletion();
       
  7037       }
       
  7038   PRINT( _L( "Camera <= CCamAppController::CompleteBurstOperation" ) );          
       
  7039   }
       
  7040 
       
  7041 // ---------------------------------------------------------------------------
       
  7042 // CCamAppController::CompleteTimeLapseOperation
       
  7043 // Complete the time lapse operation
       
  7044 // ---------------------------------------------------------------------------
       
  7045 //
       
  7046 void CCamAppController::CompleteTimeLapseOperation()    
       
  7047     {
       
  7048     PRINT( _L( "Camera => CCamAppController::CompleteTimeLapseOperation" ) );
       
  7049 
       
  7050     iSequenceCaptureInProgress = EFalse;
       
  7051 
       
  7052     if ( iTimeLapseTimer )
       
  7053       {
       
  7054       iTimeLapseTimer->Cancel();
       
  7055       delete iTimeLapseTimer;
       
  7056       iTimeLapseTimer = NULL;
       
  7057       }
       
  7058 
       
  7059     if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7060       {
       
  7061       // Re-enable screen saver
       
  7062       EnableScreenSaver( ETrue );
       
  7063       iCompleteTimeLapsePending = EFalse;
       
  7064   
       
  7065 //      SetImageMode( ECamImageCaptureNone );   
       
  7066       SetOperation( ECamNoOperation      );
       
  7067   
       
  7068       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );   
       
  7069       HandleCaptureCompletion();
       
  7070       iTimeLapseStartTime = TInt64( 0 );
       
  7071       }
       
  7072 
       
  7073     PRINT( _L( "Camera <= CCamAppController::CompleteTimeLapseOperation" ) );   
       
  7074     }
       
  7075 
       
  7076 
       
  7077 // ---------------------------------------------------------------------------
       
  7078 // CCamAppController::EngineProcessingCapture
       
  7079 // Return whether or not the engine is carrying out a capture operation
       
  7080 // ---------------------------------------------------------------------------
       
  7081 //
       
  7082 TBool 
       
  7083 CCamAppController::EngineProcessingCapture() const
       
  7084   {
       
  7085   TBool engineIsProcessing = EFalse;
       
  7086 
       
  7087   if ( ECamCapturing  == iInfo.iOperation
       
  7088     || ECamPausing    == iInfo.iOperation
       
  7089     || ECamPaused     == iInfo.iOperation
       
  7090     || ECamResuming   == iInfo.iOperation
       
  7091     || ECamCompleting == iInfo.iOperation 
       
  7092      )
       
  7093     {
       
  7094     engineIsProcessing = ETrue;
       
  7095     }
       
  7096 
       
  7097   return engineIsProcessing;
       
  7098   }
       
  7099 
       
  7100 // ---------------------------------------------------------------------------
       
  7101 // CCamAppController::HandleIncomingCall
       
  7102 // Stop video recording (or burst capture in early stages)
       
  7103 // ---------------------------------------------------------------------------
       
  7104 //
       
  7105 void CCamAppController::HandleIncomingCall()
       
  7106   {
       
  7107   PRINT2( _L("Camera => CCamAppController::HandleIncomingCallL .. mode[%s] operation[%s]"), 
       
  7108           KCamModeNames[iInfo.iMode], 
       
  7109           KCamCaptureOperationNames[iInfo.iOperation]
       
  7110         );
       
  7111 
       
  7112   if( ECamControllerVideo == iInfo.iMode )
       
  7113     {
       
  7114     // if video is recording or paused
       
  7115     if ( !iSaving
       
  7116       && ( ECamCapturing == iInfo.iOperation
       
  7117         || ECamPaused    == iInfo.iOperation ) )
       
  7118       {
       
  7119       StopVideoRecording();  
       
  7120       }
       
  7121     }
       
  7122   else if( ECamControllerImage == iInfo.iMode )
       
  7123     {
       
  7124     iCaptureRequested = EFalse;
       
  7125     switch( iInfo.iImageMode ) 
       
  7126       {
       
  7127       // if a timelapse operation is in progress
       
  7128       case ECamImageCaptureTimeLapse:
       
  7129         {
       
  7130         TRAP_IGNORE( StopSequenceCaptureL() );
       
  7131         break;
       
  7132         }
       
  7133       case ECamImageCaptureBurst:
       
  7134         {
       
  7135         TRAP_IGNORE( SoftStopBurstL( ETrue ) );
       
  7136         /*
       
  7137         if ( ECamCompleting == iInfo.iOperation )
       
  7138           {
       
  7139           // if some of the image captures failed
       
  7140           // release the reserved filenames and tidy the array
       
  7141           TInt captured( iCameraController->ControllerInfo().iCaptureCount );
       
  7142           if ( BurstCaptureArray()->NextFileIndex() < captured )
       
  7143             {
       
  7144             TInt index;
       
  7145             TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7146             for ( index = BurstCaptureArray()->NextFileIndex(); index < stopAt; index++ )
       
  7147               {
       
  7148               SetAsCurrentImage( index );
       
  7149               DeleteCurrentFile();
       
  7150               }
       
  7151             SetAsCurrentImage( 0 );
       
  7152       
       
  7153             BurstCaptureArray()->Reset( BurstCaptureArray()->NextFileIndex() );
       
  7154             // Finished with this now
       
  7155             }
       
  7156 //          SetImageMode( ECamImageCaptureNone );
       
  7157           if( iImageSaveActive )
       
  7158             iImageSaveActive->DismissProgressNote();
       
  7159           StartIdleTimer();
       
  7160           }
       
  7161         */
       
  7162         break;
       
  7163         }
       
  7164       default:
       
  7165         break;
       
  7166       }
       
  7167     }
       
  7168   else
       
  7169     {
       
  7170     // no action needed
       
  7171     }
       
  7172   PRINT( _L( "Camera <= CCamAppController::HandleIncomingCallL" ) ); 
       
  7173   }
       
  7174 
       
  7175     
       
  7176 // ---------------------------------------------------------------------------
       
  7177 // CCamAppController::FileSize
       
  7178 // Returns the file size of the specified captured item, or KErrNotFound if doesn't exist
       
  7179 // ---------------------------------------------------------------------------
       
  7180 //
       
  7181 TInt CCamAppController::FileSize( TDesC& aFilename ) const
       
  7182   {       
       
  7183   return iImageSaveActive->FileSize( aFilename );
       
  7184   }
       
  7185 
       
  7186 // ---------------------------------------------------------------------------
       
  7187 // CCamAppController::CancelStillCaptureNow
       
  7188 // Immediately cancels an ongoing still capture
       
  7189 // ---------------------------------------------------------------------------
       
  7190 //
       
  7191 void CCamAppController::CancelStillCaptureNow()
       
  7192   {
       
  7193   PRINT( _L( "Camera => CCamAppController::CancelStillCaptureNow" ) )
       
  7194   // Re-enable screen saver
       
  7195   EnableScreenSaver( ETrue ); 
       
  7196 //    iEngine->CancelCaptureStill();
       
  7197   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  7198 
       
  7199   // ensure that any outstanding images are discarded
       
  7200   SetOperation( ECamCompleting  );
       
  7201   SetOperation( ECamNoOperation );
       
  7202 
       
  7203   // If sequence mode, remove items from the array
       
  7204   // this prevents the post capture view from showing
       
  7205   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7206     {
       
  7207     BurstCaptureArray()->Reset( 0 );
       
  7208     }   
       
  7209   else // single capture, the array is no longer needed
       
  7210     {
       
  7211     PRINT( _L( "Camera <> single capture so releasing array and starting vf" ) )
       
  7212     ReleaseArray();
       
  7213     FreezeViewFinder( EFalse );
       
  7214     }
       
  7215   // Cancel any pending saves, this will call CompleteBurstOperation for sequence
       
  7216   PRINT( _L( "Camera <> calling iImageSaveArray->Cancel" ) )
       
  7217   iImageSaveActive->Cancel(); 
       
  7218   PRINT( _L( "Camera <= CCamAppController::CancelStillCaptureNow" ) )
       
  7219   }
       
  7220     
       
  7221 
       
  7222 
       
  7223 // ---------------------------------------------------------------------------
       
  7224 // CCamAppController::TidyCaptureArray
       
  7225 // Tidy up capture array in event of burst capture failure
       
  7226 // ---------------------------------------------------------------------------
       
  7227 //
       
  7228 void
       
  7229 CCamAppController::TidyCaptureArray( TInt aImageCountDelivered, 
       
  7230                                      TInt /*aError*/               )
       
  7231   {
       
  7232   PRINT1( _L("Camera => CCamAppController::TidyCaptureArray img count %d"), aImageCountDelivered )
       
  7233   iSoundPlayer->EnableAllKeySounds();
       
  7234 
       
  7235   // if some of the image captures failed
       
  7236   // release the reserved filenames and tidy the array
       
  7237 
       
  7238   TInt captured( iCameraController->ControllerInfo().iSnapshotCount );
       
  7239   if ( aImageCountDelivered < captured )
       
  7240     {
       
  7241     TInt index;
       
  7242     TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7243     for ( index = aImageCountDelivered; index < stopAt; index++ )
       
  7244       {
       
  7245       PRINT1( _L("Camera <> TidyCaptureArray delete current %d"),index )
       
  7246       SetAsCurrentImage( index );
       
  7247       DeleteCurrentFile();
       
  7248       }
       
  7249     SetAsCurrentImage( 0 );
       
  7250     iCaptureArray->Reset( aImageCountDelivered );
       
  7251     // Finished with this now
       
  7252     }
       
  7253 
       
  7254   SetImageMode( ECamImageCaptureNone );
       
  7255   StartIdleTimer();
       
  7256 
       
  7257   // Need to release the array
       
  7258   ReleaseArray();
       
  7259 
       
  7260 
       
  7261   // Unfreeze the viewfinder
       
  7262   FreezeViewFinder( EFalse );
       
  7263 
       
  7264   // Change op state to none
       
  7265   SetOperation( ECamNoOperation );
       
  7266 
       
  7267   PRINT( _L("Camera <= CCamAppController::TidyCaptureArray") )
       
  7268   }
       
  7269 
       
  7270 
       
  7271 // ---------------------------------------------------------------------------
       
  7272 // CCamAppController::CaptureToneId
       
  7273 // Returns the current capture tone
       
  7274 //
       
  7275 // ---------------------------------------------------------------------------
       
  7276 //
       
  7277 TCamSoundId CCamAppController::CaptureToneId( )
       
  7278   {
       
  7279   TCamSoundId toneId = ECamStillCaptureSoundId1;
       
  7280 
       
  7281   switch(iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoCaptureTone ) )
       
  7282     {
       
  7283     case ECamSettTone1:
       
  7284       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7285         {
       
  7286         toneId = ECamBurstCaptureSoundId1;
       
  7287         }
       
  7288       else 
       
  7289         {
       
  7290         toneId = ECamStillCaptureSoundId1;
       
  7291         }
       
  7292       break;
       
  7293     case ECamSettTone2:
       
  7294       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7295         {
       
  7296         toneId = ECamBurstCaptureSoundId2;
       
  7297         }
       
  7298       else 
       
  7299         {
       
  7300         toneId = ECamStillCaptureSoundId2;
       
  7301         }
       
  7302       break;
       
  7303     case ECamSettTone3:
       
  7304       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7305         {
       
  7306         toneId = ECamBurstCaptureSoundId3;
       
  7307         }
       
  7308       else 
       
  7309         {
       
  7310         toneId = ECamStillCaptureSoundId3;
       
  7311         }
       
  7312       break;
       
  7313     case ECamSettTone4:
       
  7314       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7315         {
       
  7316         toneId = ECamBurstCaptureSoundId4;
       
  7317         }
       
  7318       else 
       
  7319         {
       
  7320         toneId = ECamStillCaptureSoundId4;
       
  7321         }
       
  7322       break;
       
  7323     default:
       
  7324       break;
       
  7325     }
       
  7326 
       
  7327   return toneId;
       
  7328   }
       
  7329 
       
  7330 // ---------------------------------------------------------------------------
       
  7331 // CCamAppController::LoadSecondaryCameraSettingsL()
       
  7332 // Update settings for secondary camera
       
  7333 // ---------------------------------------------------------------------------
       
  7334 //  
       
  7335 void CCamAppController::LoadSecondaryCameraSettingsL()
       
  7336   {
       
  7337   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 1" );
       
  7338   PRINT( _L("Camera => CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7339   iSettingsModel->StorePrimaryCameraSettingsL();
       
  7340 
       
  7341   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL B" ))
       
  7342   
       
  7343   SetIntegerSettingValueL( ECamSettingItemPhotoQuality, 
       
  7344                            iConfiguration->SecondaryCameraImageQuality() );
       
  7345   PRINT(  _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL C" ))
       
  7346   SetIntegerSettingValueL( ECamSettingItemVideoQuality,
       
  7347                            iConfiguration->SecondaryCameraVideoQuality() );  
       
  7348 
       
  7349     
       
  7350 
       
  7351   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL E" ))
       
  7352   SetIntegerSettingValueL( ECamSettingItemDynamicPhotoScene, ECamSceneAuto );
       
  7353   SetIntegerSettingValueL( ECamSettingItemDynamicVideoScene, ECamSceneNormal );
       
  7354   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL F" ))
       
  7355 
       
  7356   PRINT( _L("Camera <= CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7357   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 0" );
       
  7358   }
       
  7359 
       
  7360 // ---------------------------------------------------------------------------
       
  7361 // ImageOrientation <<public>>
       
  7362 //
       
  7363 // Return the current image orientation based on data from orientation sensor.
       
  7364 // If "image rotation" setting is OFF, the value has been overriden with 
       
  7365 // "no rotation" value (ECamOrientation0).
       
  7366 // 
       
  7367 // Provided (primarily) for Camera Controller even if orientation
       
  7368 // sensor is not supported. In that case the returned
       
  7369 // value is always ECamOrientation0.
       
  7370 // ---------------------------------------------------------------------------
       
  7371 //
       
  7372 TCamImageOrientation 
       
  7373 CCamAppController::ImageOrientation() const
       
  7374   {
       
  7375   return iImageOrientation;
       
  7376   }
       
  7377 
       
  7378 
       
  7379 // ---------------------------------------------------------------------------
       
  7380 // Indicates data is available in the receiving buffer. A client can read 
       
  7381 // the data through GetData()-function in the related channel object. Data 
       
  7382 // is valid until the data received notification occurs again.
       
  7383 //
       
  7384 // @param[in] aChannel Reference to the related channel object
       
  7385 // @param[in] aCount Data object count in receiving buffer. Not used in this implementation.
       
  7386 // @param[in] aDataLost Number of lost data items. Not used in this implementation. It does not
       
  7387 //     matter if some data event is lost.
       
  7388 // ---------------------------------------------------------------------------
       
  7389 //
       
  7390 void CCamAppController::DataReceived( CSensrvChannel& aChannel, 
       
  7391                                       TInt aCount, 
       
  7392                                       TInt aDataLost )
       
  7393     {
       
  7394     PRINT3( _L("Camera => CCamAppController::DataReceived aChannel %d aCount %d aDataLost %d"), 
       
  7395                 aChannel.GetChannelInfo().iChannelType, aCount, aDataLost );
       
  7396 
       
  7397     if ( KSensrvChannelTypeIdOrientationData == aChannel.GetChannelInfo().iChannelType )
       
  7398         {
       
  7399         TBool rotate( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) );
       
  7400 
       
  7401         if( rotate )
       
  7402             {
       
  7403             TSensrvOrientationData orientationData;
       
  7404             TPckg<TSensrvOrientationData> orientationPackage( orientationData );
       
  7405             aChannel.GetData( orientationPackage );
       
  7406 
       
  7407             iImageOrientation =
       
  7408                 MapSensorOrientatio2CamOrientation( orientationData.iDeviceOrientation, iLastImageOrientation );
       
  7409             }
       
  7410         else
       
  7411             {
       
  7412             // If "rotate images" setting is OFF, set "no rotation" value
       
  7413             iImageOrientation = ECamOrientation0;
       
  7414             }
       
  7415         
       
  7416         // rotate image if we are in still capture mode but not currently
       
  7417         // capturing image, no rotation in burst mode or if orientation has stayed the same
       
  7418         if( IsFlagOn( CameraControllerState(), ECamImageOn ) && 
       
  7419             rotate && 
       
  7420             iLastImageOrientation != iImageOrientation &&
       
  7421             iImageOrientation != ECamOrientationIgnore)
       
  7422             {
       
  7423             if( ECamCapturing   != CurrentOperation() &&
       
  7424                 ECamFocusing    != CurrentOperation() &&
       
  7425                 ECamFocused     != CurrentOperation() &&
       
  7426                 ECamFocusFailed != CurrentOperation() &&
       
  7427                 ECamCompleting  != CurrentOperation() &&
       
  7428                 ECamImageCaptureBurst != iInfo.iImageMode &&
       
  7429                 ECamImageCaptureBurst != iInfo.iTargetImageMode )
       
  7430                 {
       
  7431                 PRINT( _L("Camera <> CCamAppController:DataReceived calling SetImageOrientationL()") );	
       
  7432                 TRAP_IGNORE( SetImageOrientationL() );
       
  7433                 }
       
  7434             else
       
  7435                 {
       
  7436                 // queue a request to re-prepare still capture
       
  7437                 PRINT( _L("Camera <> CCamAppController: Queueing an orientation change event") );	
       
  7438                 iOrientationChangeOccured = ETrue;
       
  7439                 }
       
  7440             }
       
  7441         else
       
  7442             {
       
  7443             iOrientationChangeOccured = EFalse;
       
  7444             }
       
  7445         
       
  7446         if( iImageOrientation != ECamOrientationIgnore )    
       
  7447             {
       
  7448             iLastImageOrientation = iImageOrientation; 	           
       
  7449             }
       
  7450         }
       
  7451 
       
  7452     PRINT ( _L("Camera <= CCamAppController::DataReceived") );
       
  7453     }
       
  7454 
       
  7455 // ---------------------------------------------------------------------------
       
  7456 // Data listening failed. 
       
  7457 // If error was fatal, channel has also been closed and sensor server session 
       
  7458 // terminated. If error was minor, some data has potentially been lost.
       
  7459 // iAccSensorChannel needs to be closed in fatal error case. A new channel will
       
  7460 // be created the next time we call UpdateSensorApiL().
       
  7461 //
       
  7462 // @param[in] aChannel Reference to the related channel object
       
  7463 // @param[in] aError Error code.
       
  7464 // ---------------------------------------------------------------------------
       
  7465 //
       
  7466 void CCamAppController::DataError( CSensrvChannel& aChannel, 
       
  7467                                    TSensrvErrorSeverity aError )
       
  7468     {
       
  7469     PRINT2( _L("Camera => CCamAppController::DataError aChannel %d aError %d"), aChannel.GetChannelInfo().iChannelType, aError );	
       
  7470     if ( ESensrvErrorSeverityFatal == aError ) 
       
  7471         {
       
  7472         // Delete sensor api object
       
  7473         delete iAccSensorChannel;
       
  7474         iAccSensorChannel = NULL;
       
  7475         iAccSensorListening = EFalse;
       
  7476 
       
  7477         // Set orientation back to default if not already there.
       
  7478         iImageOrientation   = ECamOrientation0;
       
  7479         }
       
  7480     }
       
  7481 
       
  7482 // ---------------------------------------------------------------------------
       
  7483 // Returns a pointer to a specified interface 
       
  7484 //
       
  7485 // @since S60 5.0
       
  7486 // @param aInterfaceUid Identifier of the interface to be retrieved
       
  7487 // @param aInterface A reference to a pointer that retrieves the specified interface.
       
  7488 // ---------------------------------------------------------------------------
       
  7489 //
       
  7490 void CCamAppController::GetDataListenerInterfaceL( TUid aInterfaceUid, 
       
  7491                                                    TAny*& aInterface )
       
  7492     {
       
  7493     aInterface = NULL;
       
  7494     }                                
       
  7495                                         
       
  7496 // ---------------------------------------------------------------------------
       
  7497 // CCamAppController::SetImageOrientationL()
       
  7498 // Setup image rotation parameters
       
  7499 //
       
  7500 // ---------------------------------------------------------------------------
       
  7501 //  
       
  7502 void CCamAppController::SetImageOrientationL()
       
  7503     {
       
  7504     PRINT( _L("Camera => CCamAppController::SetImageOrientationL") );
       
  7505     if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  7506     		&& iCameraController )
       
  7507         {
       
  7508         if ( ECamActiveCameraPrimary == iInfo.iActiveCamera )
       
  7509             {
       
  7510             // Camera controller asks for the current orientation through
       
  7511             // our ImageOrientation(). Value for that was updated in 
       
  7512             // DataReceived() callback.
       
  7513             iCameraController->DirectSettingsChangeL( ECameraSettingOrientation );
       
  7514             }
       
  7515         else
       
  7516             {
       
  7517             // No action in secondary camera.
       
  7518             }
       
  7519         }
       
  7520     PRINT( _L("Camera <= CCamAppController::SetImageOrientationL"))   
       
  7521     }
       
  7522 
       
  7523 
       
  7524 // ---------------------------------------------------------------------------
       
  7525 // MapSensorOrientatio2CamOrientation
       
  7526 // ---------------------------------------------------------------------------
       
  7527 //
       
  7528 TCamImageOrientation 
       
  7529 CCamAppController::MapSensorOrientatio2CamOrientation( 
       
  7530     const TSensrvOrientationData::TSensrvDeviceOrientation& aSensorOrientation, TCamImageOrientation aLastImageOrientation )
       
  7531     {
       
  7532     PRINT1 ( _L("Camera => CCamAppController::MapSensorOrientatio2CamOrientation aSensorOrientation: %d"), aSensorOrientation );   
       
  7533 
       
  7534     TCamImageOrientation cameraOrientation( ECamOrientation0 );
       
  7535 
       
  7536     switch( aSensorOrientation )
       
  7537         {        
       
  7538         case TSensrvOrientationData::EOrientationDisplayUpwards:
       
  7539             // If coming from upside down portrait...
       
  7540             if ( ECamOrientation270 == aLastImageOrientation )
       
  7541               {
       
  7542             	// Switch from upside down portrait to normal portrait.") )
       
  7543               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7544               }
       
  7545             // If coming from upside down landscape...
       
  7546             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7547               {
       
  7548             	// Switch from upside down landscape to normal landscape...") )
       
  7549               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7550               }
       
  7551             // If neither one, keep the current image orientation.
       
  7552             else
       
  7553               {
       
  7554               cameraOrientation = ECamOrientationIgnore;
       
  7555               }
       
  7556             break;
       
  7557 
       
  7558         case TSensrvOrientationData::EOrientationDisplayDownwards:
       
  7559         	  // Camera is pointing up now. Check if it was upside down previously.
       
  7560             // If coming from upside down portrait...
       
  7561             if ( ECamOrientation270 == aLastImageOrientation )
       
  7562               {
       
  7563             	// Switch from upside down portrait to normal portrait...") )
       
  7564               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7565               }
       
  7566             // If coming from upside down landscape...
       
  7567             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7568               {
       
  7569             	// Switch from upside down landscape to normal landscape...") )
       
  7570               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7571               }
       
  7572             // If neither one, keep the current image orientation.
       
  7573             else
       
  7574               {
       
  7575               cameraOrientation = ECamOrientationIgnore;
       
  7576               }
       
  7577         	  break;
       
  7578         case TSensrvOrientationData::EOrientationDisplayRightUp:            
       
  7579         case TSensrvOrientationData::EOrientationUndefined:
       
  7580             cameraOrientation = ECamOrientation0;     
       
  7581             break;
       
  7582         case TSensrvOrientationData::EOrientationDisplayUp:
       
  7583             cameraOrientation = ECamOrientation90;
       
  7584             break;
       
  7585         case TSensrvOrientationData::EOrientationDisplayLeftUp:
       
  7586             cameraOrientation = ECamOrientation180;
       
  7587             break;
       
  7588         case TSensrvOrientationData::EOrientationDisplayDown:
       
  7589             cameraOrientation = ECamOrientation270;
       
  7590             break;
       
  7591         default:
       
  7592             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7593             break;
       
  7594         }
       
  7595     PRINT1( _L("Camera <= CCamAppController::MapSensorOrientatio2CamOrientation, return [%s]"), 
       
  7596             KCamOrientationNames[cameraOrientation] );
       
  7597 
       
  7598     return cameraOrientation;
       
  7599     }
       
  7600 
       
  7601 // ---------------------------------------------------------------------------
       
  7602 // MapSensorOrientatio2CamOrientation
       
  7603 // ---------------------------------------------------------------------------
       
  7604 //
       
  7605 CBitmapRotator::TRotationAngle 
       
  7606 CCamAppController::MapCamOrientation2RotationAngle( 
       
  7607                    const TCamImageOrientation aOrientation )
       
  7608     {
       
  7609     PRINT1 ( _L("Camera => CCamAppController::MapCamOrientation2RotationAngle aOrientation: %d"), aOrientation );   
       
  7610 
       
  7611     CBitmapRotator::TRotationAngle angle;
       
  7612     
       
  7613     switch( aOrientation )
       
  7614         {        
       
  7615         case ECamOrientation90:
       
  7616             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7617             break;
       
  7618         case ECamOrientation180:
       
  7619             angle = CBitmapRotator::ERotation180DegreesClockwise;
       
  7620             break;
       
  7621         case ECamOrientation270:
       
  7622             angle = CBitmapRotator::ERotation270DegreesClockwise;
       
  7623             break;
       
  7624         default:
       
  7625             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7626             // using a value to avoid compiler warning
       
  7627             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7628             break;
       
  7629         }
       
  7630     PRINT1( _L("Camera <= CCamAppController::MapCamOrientation2RotationAngle, return %d"), angle );
       
  7631     return angle;    
       
  7632     }
       
  7633         
       
  7634         
       
  7635 // ---------------------------------------------------------------------------
       
  7636 // CCamAppController::UpdateSensorApiL() <<public>>
       
  7637 // Updates the sensorApi object when the app focus changes
       
  7638 //
       
  7639 // ---------------------------------------------------------------------------
       
  7640 //  
       
  7641 
       
  7642 void CCamAppController::UpdateSensorApiL(TBool aStartupApi) 
       
  7643     {
       
  7644     PRINT(_L("Camera => CCamAppController::UpdateSensorApiL"));
       
  7645     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  7646     	{
       
  7647 	    if(aStartupApi)
       
  7648 	        {
       
  7649 	        // only activate the orientation channel for image mode	
       
  7650 	        if( ECamControllerImage == CurrentMode() )
       
  7651 	          {
       
  7652 	        // This if-statement intentionally not a condition of the first if.
       
  7653 	        // If the iAccSensorChannel is already active, we don't want to recreate it
       
  7654 	        // and leak memory, but at the same time, we don't want to destroy it either.
       
  7655 	        
       
  7656 	        if( !iAccSensorChannel )
       
  7657 	            {
       
  7658 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - Starting new sensor channel api - info not yet initialized"));
       
  7659 	            //Construct a channel finder.
       
  7660 	            CSensrvChannelFinder* channelFinder;
       
  7661 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannelFinder::NewL()"));
       
  7662 	            //CSensorChannelFinder* channelFinder;
       
  7663 	            channelFinder = CSensrvChannelFinder::NewL();
       
  7664 	            //channelFinder = CSensorChannelFinder::NewL();
       
  7665 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - CSensrvChannelFinder::NewL() returned without a leave"));
       
  7666 	            CleanupStack::PushL( channelFinder );    
       
  7667 	            
       
  7668 	            //List of found channels.
       
  7669 	            RSensrvChannelInfoList channelInfoList;
       
  7670 	            CleanupClosePushL( channelInfoList );
       
  7671 	  
       
  7672 	            //Create and fill channel search criteria.
       
  7673 	            TSensrvChannelInfo channelInfo;
       
  7674 	            channelInfo.iChannelType = KSensrvChannelTypeIdOrientationData;
       
  7675 	        
       
  7676 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling channelFinder->FindChannelsL"));
       
  7677 	            //Find the orientation channel
       
  7678 	            channelFinder->FindChannelsL( channelInfoList, channelInfo );
       
  7679 	           
       
  7680 	            if( channelInfoList.Count() != 1 )
       
  7681 	                {
       
  7682 	                //The device doesn’t support orientation data channel or
       
  7683 	                //there are several orientation channels.
       
  7684 	                PRINT1(_L("Camera <=> CCamAppController::UpdateSensorApiL - The device doesn’t support orientation data channel or there are several orientation channels: %d channels found"),channelInfoList.Count());
       
  7685 	                User::Leave( KErrNotSupported );
       
  7686 	                }
       
  7687 	            else
       
  7688 	                {
       
  7689 	                //orientation channel found 
       
  7690 	                PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - orientation channel found"));
       
  7691 	                }
       
  7692 	            //Open the orientation channel.
       
  7693 	            //When the channel object is created the channel info object 
       
  7694 	            //must be an object returned by CSensrvChannelFinder::FindChannelsL().
       
  7695 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannel::NewL"));
       
  7696 	            iAccSensorChannel = CSensrvChannel::NewL( channelInfoList[ 0 ] );
       
  7697 	            //iAccSensorChannel = CSensorChannel::NewL( channelInfoList[ 0 ] );
       
  7698 	            //CleanupStack::PushL( iAccSensorChannel ); 
       
  7699 	            CleanupStack::PopAndDestroy( &channelInfoList ); //Close() is being called on "channelInfoList"
       
  7700 	            CleanupStack::PopAndDestroy( channelFinder );
       
  7701 	          }
       
  7702 	        
       
  7703 	        if( !iAccSensorListening )
       
  7704 	            {
       
  7705 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->OpenChannelL()"));
       
  7706 	            TRAPD(channelerror, iAccSensorChannel->OpenChannelL() );
       
  7707 	            if (channelerror!=KErrNone)
       
  7708 	                {
       
  7709 	                PRINT1(_L("CCamAppController::UpdateSensorApiL - iAccSensorChannel->OpenChannelL() failed. Error code: %d"),channelerror);
       
  7710 	                User::Leave( channelerror );
       
  7711 	                }
       
  7712 	            //iAccSensorChannel->OpenChannelL();
       
  7713 	            //orientation channel is now open.
       
  7714 	            
       
  7715 	            // start listening
       
  7716 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->StartDataListeningL"));
       
  7717 	            iAccSensorChannel->StartDataListeningL( this, //this object is data listener for this channel
       
  7718 	                                                   1, //aDesiredCount is one, i.e. each orientation change is notified separately
       
  7719 	                                                   1, //aMaximumCount is one, i.e. object count in receiving data buffer is one
       
  7720 	                                                   0 );//buffering period is not used
       
  7721 	            iAccSensorListening = ETrue;
       
  7722 	            iLastImageOrientation = ECamOrientation0;
       
  7723 	            }
       
  7724 	          }
       
  7725 	        }
       
  7726 	    else // shut down the sensorApi object
       
  7727 	        {
       
  7728 	        PRINT(_L("Camera <=> UpdateSensorApiL shutting down iAccSensor"))
       
  7729 	        if(iAccSensorListening)
       
  7730 	            {
       
  7731 	            // Stop listening to the events
       
  7732 	            iAccSensorChannel->StopDataListening();
       
  7733 	            iAccSensorListening = EFalse;
       
  7734 	            }
       
  7735 	            
       
  7736 	        // Delete sensor api object
       
  7737 	        delete iAccSensorChannel;
       
  7738 	        iAccSensorChannel = NULL;
       
  7739 	        }
       
  7740       }
       
  7741     PRINT(_L("Camera <= CCamAppController::UpdateSensorApiL"));
       
  7742     }
       
  7743 
       
  7744 
       
  7745 
       
  7746 // ---------------------------------------------------------------------------
       
  7747 // CCamAppController::HandlePropertyChangedL()
       
  7748 // Handle changes in specified property
       
  7749 //
       
  7750 // ---------------------------------------------------------------------------
       
  7751 //  
       
  7752 void CCamAppController::HandlePropertyChangedL( const TUid& aCategory, const TUint aKey )
       
  7753   {
       
  7754   PRINT( _L("Camera => CCamAppController::HandlePropertyChangedL"))
       
  7755 #if !( defined(__WINS__) || defined(__WINSCW__) )  
       
  7756   
       
  7757   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  7758       { 
       
  7759       // First if condition could be removed after PCFW has released 
       
  7760       // creation for KLensCoverStatus key
       
  7761       if ( ( aCategory == NMusResourceApi::KCategoryUid && 
       
  7762            aKey == NMusResourceApi::KCameraAvailability ) ||              
       
  7763            ( aCategory == CameraPlatPSKeys::KPSCameraPlatUid && 
       
  7764            aKey == CameraPlatPSKeys::KLensCoverStatus ) )        
       
  7765           {    
       
  7766 
       
  7767           TInt err = iSlideStateWatcher->Get( iNewSlideState );
       
  7768 
       
  7769           PRINT2( _L( "Camera HandlePropertyChangedL getting slider state = %d, err = %d" ), iNewSlideState, err )
       
  7770           
       
  7771           if ( iNewSlideState != iSlideState  )
       
  7772               {
       
  7773               delete iSliderCallBack;
       
  7774               iSliderCallBack = NULL;
       
  7775               iSliderCallBack = CPeriodic::NewL( CActive::EPriorityIdle );
       
  7776               iSliderCallBack->Start( KLensCoverDelay, KLensCoverDelay, TCallBack( LensCoverUpdateL, this ) );
       
  7777               }
       
  7778           }
       
  7779       else
       
  7780           {
       
  7781           (void)aCategory;
       
  7782           (void)aKey;
       
  7783           }
       
  7784 
       
  7785       }
       
  7786 #endif // !( defined(__WINS__) || defined(__WINSCW__        
       
  7787 
       
  7788   PRINT( _L("Camera <= CCamAppController::HandlePropertyChangedL"))
       
  7789 
       
  7790   }                             
       
  7791 
       
  7792 // ---------------------------------------------------------------------------
       
  7793 // CCamAppController::LensCoverUpdate()
       
  7794 // Callback function that is called when lens cover state changes.
       
  7795 // Used to implement delayed handling of lens cover events.
       
  7796 // ---------------------------------------------------------------------------
       
  7797 //  
       
  7798 TInt CCamAppController::LensCoverUpdateL( TAny* aPtr ) 
       
  7799     {
       
  7800     PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL()" ) )
       
  7801     CCamAppController* self = static_cast<CCamAppController*>( aPtr );
       
  7802     if ( self->iNewSlideState != self->iSlideState ||
       
  7803          self->iNewSlideState == CameraPlatPSKeys::EClosed // always handle closing
       
  7804        )
       
  7805         {
       
  7806 
       
  7807         self->iSlideState = self->iNewSlideState;
       
  7808 
       
  7809         if ( self->iSlideState == CameraPlatPSKeys::EClosed )
       
  7810             {
       
  7811             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE CLOSED" ) )
       
  7812             self->HandleSlideClosedL();
       
  7813             }
       
  7814         else if ( self->iSlideState == CameraPlatPSKeys::EOpen )
       
  7815             {
       
  7816             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE OPENED" ) )
       
  7817             self->HandleSlideOpenedL();
       
  7818             }
       
  7819         }
       
  7820     self->iSliderCallBack->Cancel();
       
  7821     delete self->iSliderCallBack;
       
  7822     self->iSliderCallBack = 0;
       
  7823             
       
  7824     PRINT( _L( "Camera <= CCamAppController::LensCoverUpdateL()" ) )
       
  7825     return KErrNone;
       
  7826 
       
  7827     }
       
  7828 // ---------------------------------------------------------------------------
       
  7829 // CCamAppController::RefreshSlideState
       
  7830 // Force a refresh of the slide status
       
  7831 // ---------------------------------------------------------------------------
       
  7832 //
       
  7833 void CCamAppController::RefreshSlideStatus()
       
  7834     {
       
  7835     PRINT( _L("Camera => CCamAppController::RefreshSlideStatus") );  
       
  7836     // read the slider status from P & S key
       
  7837     if ( iSlideStateWatcher->Get( iSlideState ) != KErrNone )
       
  7838            {
       
  7839            iSlideState = KErrNone;
       
  7840            }   
       
  7841     }
       
  7842       
       
  7843 // ---------------------------------------------------------------------------
       
  7844 // CCamAppController::HandleSlideClosedL
       
  7845 // Handle the slide closed event
       
  7846 // ---------------------------------------------------------------------------
       
  7847 //
       
  7848 void CCamAppController::HandleSlideClosedL()
       
  7849     {
       
  7850     PRINT( _L("Camera => CCamAppController::HandleSlideClosedL") );
       
  7851 
       
  7852     NotifyControllerObservers( ECamEventSliderClosed );
       
  7853     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  7854     
       
  7855     if ( appUi->IsInPretendExit() )
       
  7856         {
       
  7857         PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL already in pretend exit") );        
       
  7858         return;
       
  7859         }
       
  7860     SetCameraSwitchRequired( ESwitchDone );
       
  7861     // shutdown the camera on slide closing if EDGE variant/standalone app
       
  7862     // don't close app if embedded or embedding
       
  7863     TInt camerasAvailable = CamerasAvailable();
       
  7864     TVwsViewId activeView;
       
  7865     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  7866 
       
  7867     TBool embedded = appUi->IsEmbedded();
       
  7868     TBool embedding = appUi->Embedding();
       
  7869     if ( camerasAvailable == 1 ) // EDGE variant
       
  7870         {
       
  7871         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable == 1") );
       
  7872         // if embedding another app then don't exit just yet
       
  7873         if ( embedding )
       
  7874             {
       
  7875             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedding mode") );
       
  7876             // remember that the slider has been closed
       
  7877             iSliderCloseEvent = ETrue;
       
  7878             }
       
  7879         // Embedded post capture view
       
  7880         else if ( embedded && viewErr == KErrNone && 
       
  7881                 ( activeView.iViewUid.iUid == ECamViewIdStillPostCapture ||
       
  7882                   activeView.iViewUid.iUid == ECamViewIdVideoPostCapture ) )
       
  7883             {
       
  7884             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded post capture") );
       
  7885             // remember that the slider has been closed
       
  7886             iSliderCloseEvent = ETrue;
       
  7887             }
       
  7888         // if standalone app performing a burst capture, 
       
  7889         // don't exit till complete
       
  7890         else if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  7891                 ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7892             {
       
  7893             // remember that the slider has been closed
       
  7894             iSliderCloseEvent = ETrue;
       
  7895             StopSequenceCaptureL();
       
  7896             }
       
  7897         else // standalone or embedded pre capture view
       
  7898             {
       
  7899             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  7900             appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  7901             }
       
  7902         }
       
  7903     else // variants with > 1 camera
       
  7904         {
       
  7905         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable > 1") );
       
  7906         if ( !embedding && !embedded )
       
  7907             {
       
  7908             // if standalone app performing a burst capture, 
       
  7909             // don't exit till complete
       
  7910             if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  7911                  ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7912                 {
       
  7913                 // remember that the slider has been closed
       
  7914                 iSliderCloseEvent = ETrue;
       
  7915                 StopSequenceCaptureL();
       
  7916                 }
       
  7917             else
       
  7918                 {
       
  7919                 PRINT( _L("Camera Normal mode-handle ECamCmdSlideClosedExit") );
       
  7920                 appUi->SetLensCoverExit( ETrue ); 
       
  7921                 if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid ) 
       
  7922                    {
       
  7923                    // stop recording and save the video
       
  7924                    StopVideoRecording();                          
       
  7925                    }
       
  7926                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  7927                 appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  7928                 
       
  7929 				// 2ndary camera, slider closed -> application to be closed, 
       
  7930 				// not in embedded mode
       
  7931                 if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  7932                    {
       
  7933                    PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera slider closed, app closing...") );
       
  7934                    appUi->CloseAppL(); 
       
  7935                    }
       
  7936                 }
       
  7937             }
       
  7938         else // we are embedded in an app or embedding another app
       
  7939             {
       
  7940             // remember that the slider has been closed
       
  7941             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded/Embedding mode") );
       
  7942             
       
  7943             if ( viewErr == KErrNone )
       
  7944                 {
       
  7945                 iSliderCloseEvent = ETrue;
       
  7946 
       
  7947                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - active view %d"), activeView.iViewUid.iUid );
       
  7948                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - iInfo.iOperation %d"), iInfo.iOperation );
       
  7949     
       
  7950                 // switch the camera if slide is closed and primary camera
       
  7951                 // is active in embedded mode
       
  7952                 switch ( activeView.iViewUid.iUid )
       
  7953                     {
       
  7954                     case ECamViewIdStillPreCapture:
       
  7955                     case ECamViewIdVideoPreCapture:
       
  7956                         {
       
  7957                         // if in pre capture view and slide is closed
       
  7958                         if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  7959                             {
       
  7960                             if ( iInfo.iOperation != ECamPaused &&
       
  7961                                  iInfo.iOperation != ECamCapturing &&
       
  7962                                  iInfo.iOperation != ECamCompleting && 
       
  7963                                  iInfo.iOperation != ECamPausing &&
       
  7964                                  iInfo.iOperation != ECamResuming &&
       
  7965                                  !iVideoRequested )
       
  7966                                 {
       
  7967                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  7968                                 }
       
  7969                             else if ( iInfo.iOperation == ECamCapturing ||
       
  7970                                       iInfo.iOperation == ECamPaused )
       
  7971                                 {
       
  7972                                 StopVideoRecording();                                
       
  7973                                 }
       
  7974                             else if ( iVideoRequested )
       
  7975                                 {
       
  7976                                 StopVideoRecording();
       
  7977                                 // cancel any outstanding sound requests
       
  7978                                 iSoundPlayer->CancelAllPlaying();
       
  7979 
       
  7980                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  7981                                 }
       
  7982                             else // lint
       
  7983                                 {
       
  7984                                 }
       
  7985                             }
       
  7986                          else 
       
  7987                             {
       
  7988                             // Embedded camera not closed even if lens cover is closed.
       
  7989                             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera, no action..") );
       
  7990                             }
       
  7991                         }
       
  7992                         break;
       
  7993                     case ECamViewIdStillPostCapture:
       
  7994                     case ECamViewIdVideoPostCapture:
       
  7995                         {
       
  7996                         // Embedded camera not closed even if lens cover is closed.
       
  7997                         }
       
  7998                         break;
       
  7999                     default:
       
  8000                         break;
       
  8001                     }
       
  8002                 }
       
  8003                else if ( viewErr == KErrNotFound  )
       
  8004                 {
       
  8005                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - view not found") );
       
  8006                 if ( ECamActiveCameraPrimary == iInfo.iActiveCamera ) 
       
  8007                     {              
       
  8008                     PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - need switch to 2ndary") );
       
  8009                     SetCameraSwitchRequired( ESwitchPrimaryToSecondary );
       
  8010                     if ( !appUi->AppInBackground( ETrue ) )
       
  8011                         {
       
  8012                         appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8013                         }
       
  8014                     }
       
  8015                 }
       
  8016             }
       
  8017         }
       
  8018 
       
  8019     PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL") );
       
  8020     }
       
  8021 
       
  8022 // ---------------------------------------------------------------------------
       
  8023 // CCamAppController::HandleSlideOpenedL
       
  8024 // Handles the slide opened event
       
  8025 // ---------------------------------------------------------------------------
       
  8026 //
       
  8027 void CCamAppController::HandleSlideOpenedL()
       
  8028     {
       
  8029     PRINT( _L("Camera => CCamAppController::HandleSlideOpenedL") );
       
  8030     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8031     // reset slider event flag
       
  8032     if ( iSliderCloseEvent )
       
  8033         {
       
  8034         iSliderCloseEvent = EFalse;
       
  8035         }
       
  8036 
       
  8037     TVwsViewId activeView;
       
  8038     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  8039     if ( viewErr == KErrNone )
       
  8040         {
       
  8041         PRINT1( _L("Camera HandleSlideOpenedL => active view %d"), 
       
  8042                 activeView.iViewUid.iUid );
       
  8043 
       
  8044         // For EDGE variant 
       
  8045         TInt camerasAvailable = CamerasAvailable();
       
  8046         if ( camerasAvailable == 1 )
       
  8047             {
       
  8048             // if in standby view and the slide is opened then exit standby view
       
  8049             if ( iInfo.iOperation == ECamStandby )
       
  8050                 {
       
  8051                 PRINT( _L("Camera HandleSlideOpenedL => Exit Standby view") );
       
  8052                 appUi->View( activeView.iViewUid )->HandleCommandL( 
       
  8053                         ECamCmdExitStandby );
       
  8054                 }
       
  8055             }
       
  8056         else // variants with > 1 camera
       
  8057             {
       
  8058             PRINT1( _L("Camera HandleSlideOpenedL => iInfo.iOperation %d"), 
       
  8059                     iInfo.iOperation );
       
  8060             PRINT1( _L("Camera HandleSlideOpenedL => CameraState() %d"), 
       
  8061                     CameraState());
       
  8062             switch ( activeView.iViewUid.iUid )
       
  8063                 {
       
  8064                 // if we are in the photo/video capture view and the
       
  8065                 // second camera is enabled then switch to the main camera
       
  8066                 // so long as video/photo capture is not in progress
       
  8067                 case ECamViewIdStillPreCapture:
       
  8068                 case ECamViewIdVideoPreCapture:
       
  8069                     {
       
  8070                     if ( iInfo.iActiveCamera == ECamActiveCameraSecondary &&
       
  8071                          iInfo.iOperation != ECamCapturing &&
       
  8072                          iInfo.iOperation != ECamPaused &&
       
  8073                          iInfo.iOperation != ECamPausing &&
       
  8074                          iInfo.iOperation != ECamResuming &&
       
  8075                          iInfo.iOperation != ECamCompleting && 
       
  8076                          (CameraState() == ECamCameraPreparedImage ||
       
  8077                          CameraState() == ECamCameraPreparedVideo
       
  8078                          ||
       
  8079                          CameraState() == ECamCameraReserved ||
       
  8080                          CameraState() == ECamCameraPowerOn
       
  8081                          ) &&
       
  8082                          !VideoRecordPending() )
       
  8083                         {
       
  8084                         PRINT( _L("Camera precapture 2nd camera - switching now") ); 
       
  8085                         SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8086                         if ( !appUi->AppInBackground( ETrue ) )
       
  8087                             {
       
  8088                             appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8089                             }
       
  8090                         }
       
  8091                     else 
       
  8092                         {
       
  8093                         PRINT( _L("Camera capturing, paused etc. in precapview") );  
       
  8094                         
       
  8095                         if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid && 
       
  8096                            ( ECamCapturing == iInfo.iOperation || 
       
  8097                              ECamPaused == iInfo.iOperation ) ) 
       
  8098                             {
       
  8099                             StopVideoRecording(); // stop recording and save the video                         
       
  8100                             }
       
  8101                         if ( ECamActiveCameraSecondary == iInfo.iActiveCamera ) 
       
  8102                             {              
       
  8103                             PRINT( _L("Camera HandleSlideOpenedL, switchCamera") );
       
  8104                             SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8105                             if ( !appUi->AppInBackground( ETrue ) )
       
  8106                                 {
       
  8107                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8108                                 }
       
  8109                             }
       
  8110                         }
       
  8111                     }    
       
  8112                     break;
       
  8113                 case ECamViewIdStillPostCapture:
       
  8114                 case ECamViewIdVideoPostCapture:
       
  8115                     {
       
  8116                     if ( ECamActiveCameraSecondary == iInfo.iActiveCamera )
       
  8117                        {                    
       
  8118                        SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8119                        if ( !appUi->AppInBackground( ETrue ) )
       
  8120                            {
       
  8121                            appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8122                            }
       
  8123                        }
       
  8124                     }
       
  8125                     break;
       
  8126                 default:
       
  8127                     break;
       
  8128                 }
       
  8129             }       
       
  8130         }
       
  8131 
       
  8132     else if ( viewErr == KErrNotFound && 
       
  8133                 iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  8134           {
       
  8135           // If no view is found it means that camera is in background.
       
  8136           // We don't want to do camera switch in embdedded/embedding mode
       
  8137           // post-capture when in background
       
  8138           if ( ( !appUi->IsEmbedded() &&
       
  8139                  !appUi->Embedding() ) ||
       
  8140                appUi->CurrentViewState() != ECamViewStatePostCapture )
       
  8141               {
       
  8142               PRINT( _L("Camera HandleSlideOpenedL => view not found, 2nd active") );
       
  8143               iCameraSwitchRequired = ESwitchToUnknown;
       
  8144               }
       
  8145           }
       
  8146     else
       
  8147         {
       
  8148         }
       
  8149     NotifyControllerObservers( ECamEventSliderOpen );
       
  8150     PRINT( _L("Camera <= CamAppController::HandleSlideOpenedL") );
       
  8151     }
       
  8152 
       
  8153 
       
  8154 // ---------------------------------------------------------------------------
       
  8155 // CCamAppController::VideoViewFinderResourceId()
       
  8156 // Resource Id for video viewfinder layout
       
  8157 //
       
  8158 // ---------------------------------------------------------------------------
       
  8159 //    
       
  8160 TInt CCamAppController::VideoViewFinderResourceId( TCamVideoResolution aResolution )
       
  8161   {
       
  8162   PRINT( _L( "Camera => CCamAppController::VideoViewFinderResourceIdL"))
       
  8163   TInt vidVFRes;
       
  8164   
       
  8165     TCamOrientation orient = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->CamOrientation();   
       
  8166     if( orient == ECamOrientationCamcorder || orient == ECamOrientationCamcorderLeft )
       
  8167       {
       
  8168       vidVFRes = CamUtility::MapVideoQualityToViewFinderRes( aResolution );
       
  8169       }
       
  8170   else
       
  8171     {
       
  8172     TInt resId;
       
  8173     TInt err = CamUtility::GetPsiInt( ECamPsiVideoVFResSecondaryCamera, resId );
       
  8174     if( err )
       
  8175       {
       
  8176       vidVFRes = ROID( R_CAM_VIEWFINDER_RECT_CIF_ID );
       
  8177       }
       
  8178     else
       
  8179       {
       
  8180       vidVFRes = ROID( resId );
       
  8181       }
       
  8182     }
       
  8183     
       
  8184   PRINT1( _L( "Camera => CCamAppController::VideoViewFinderResourceId res id "), vidVFRes )
       
  8185   return vidVFRes;
       
  8186   }
       
  8187 
       
  8188 // ---------------------------------------------------------------------------
       
  8189 // CCamAppController::HandleObservedEvent()
       
  8190 // Receives event codes from observables
       
  8191 //
       
  8192 // ---------------------------------------------------------------------------
       
  8193 //
       
  8194 void CCamAppController::HandleObservedEvent( TCamObserverEvent aEvent )
       
  8195     {
       
  8196     switch( aEvent )
       
  8197         {
       
  8198         case ECamObserverEventCaptureProcessComplete:
       
  8199             {
       
  8200             NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  8201             }
       
  8202             break;
       
  8203         default:
       
  8204             break;            
       
  8205         }
       
  8206     }
       
  8207 
       
  8208 // ---------------------------------------------------------------------------
       
  8209 // CCamAppController::IsProfileSilent
       
  8210 // Return whether current profile is silent or not, uses warning
       
  8211 // tones setting to determine whether silent or not
       
  8212 // ---------------------------------------------------------------------------
       
  8213 //  
       
  8214 TBool CCamAppController::IsProfileSilent()
       
  8215     {
       
  8216     TRAPD( ignore, iSilentProfile = IsProfileSilentL() );
       
  8217     if ( ignore )
       
  8218         {
       
  8219         }
       
  8220     return iSilentProfile;
       
  8221     }
       
  8222 
       
  8223 
       
  8224 // ---------------------------------------------------------------------------
       
  8225 // CCamAppController::IsProfileSilentL
       
  8226 // Return whether current profile is silent or not, uses warning
       
  8227 // tones setting to determine whether silent or not
       
  8228 // ---------------------------------------------------------------------------
       
  8229 //  
       
  8230 TBool CCamAppController::IsProfileSilentL()
       
  8231     {
       
  8232     // get current keypad volume as indication of whether
       
  8233     // or not we have a silent profile
       
  8234     CRepository* cr = CRepository::NewLC( KCRUidProfileEngine );
       
  8235     TInt value;
       
  8236     User::LeaveIfError( cr->Get( KProEngActiveWarningTones, value ) );
       
  8237     CleanupStack::PopAndDestroy( cr );
       
  8238 
       
  8239     return ( value == 0 );
       
  8240     }
       
  8241 
       
  8242 
       
  8243 // ---------------------------------------------------------------------------
       
  8244 // ResetInactivityTimer <<static>>
       
  8245 // ---------------------------------------------------------------------------
       
  8246 //  
       
  8247 TInt 
       
  8248 CCamAppController::ResetInactivityTimer( TAny* /*aPtr*/ )
       
  8249   {
       
  8250 	PRINT( _L("Camera =><= CCamAppController::ResetInactivityTimer") );
       
  8251 
       
  8252   User::ResetInactivityTime();
       
  8253 
       
  8254 	return KErrNone;
       
  8255   }
       
  8256     
       
  8257 // ---------------------------------------------------------------------------
       
  8258 // CCamAppController::ToneShouldBeSilent
       
  8259 // Returns ETrue if the supplied toneId should be silent if the profile is 
       
  8260 // set to silent. Does *not* take into account network variant forcing 
       
  8261 // sounds on.
       
  8262 // ---------------------------------------------------------------------------
       
  8263 //      
       
  8264 TBool CCamAppController::ToneShouldBeSilent( TCamSoundId aSoundId )
       
  8265     {    
       
  8266     if ( aSoundId == CaptureToneId() ||
       
  8267          aSoundId == ECamVideoStartSoundId ||
       
  8268          aSoundId == ECamVideoStopSoundId ||
       
  8269          aSoundId == ECamVideoPauseSoundId ||
       
  8270          aSoundId == ECamVideoResumeSoundId ||
       
  8271          aSoundId == ECamAutoFocusComplete ||
       
  8272          aSoundId == ECamSelfTimerSoundId )
       
  8273         {
       
  8274         return ETrue;
       
  8275         }
       
  8276     else
       
  8277         {
       
  8278         return EFalse;
       
  8279         }         
       
  8280     }
       
  8281     
       
  8282 // ---------------------------------------------------------------------------
       
  8283 // CCamAppController::HandleCaptureCompletion
       
  8284 // Inform any observers that are waiting for a capture completion event
       
  8285 // ---------------------------------------------------------------------------
       
  8286 //  
       
  8287 void CCamAppController::HandleCaptureCompletion()
       
  8288   {
       
  8289   PRINT( _L( "Camera => CCamAppController::HandleCaptureCompletion()" ) )
       
  8290 
       
  8291   SetOperation( ECamNoOperation );
       
  8292   
       
  8293   // Re-enable screensaver
       
  8294   EnableScreenSaver( ETrue );
       
  8295 
       
  8296   // If mmc dismount notification came while saving, allow the dismount now
       
  8297   if( iDismountPending )
       
  8298     {
       
  8299     iDismountPending = EFalse;
       
  8300     iDriveChangeNotifier->SendAllowDismount();	
       
  8301     }
       
  8302   
       
  8303   // If any observers are waiting for a capture completion event
       
  8304   if ( iCaptureCompletionObserverHandler )
       
  8305     {
       
  8306     iCaptureCompletionObserverHandler->BroadcastEvent( ECamObserverEventCaptureProcessComplete );
       
  8307     delete iCaptureCompletionObserverHandler;
       
  8308     iCaptureCompletionObserverHandler = NULL;
       
  8309     }
       
  8310 
       
  8311   // If the camera orientation changed during capture and not in burst mode, 
       
  8312   // set the new orientation
       
  8313   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  8314        && iOrientationChangeOccured
       
  8315        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  8316     {
       
  8317     iOrientationChangeOccured = EFalse;
       
  8318     TRAP_IGNORE( SetImageOrientationL() );
       
  8319     }
       
  8320 
       
  8321   if ( iPendingRelease )
       
  8322     {
       
  8323        PRINT( _L( "Camera <> CCamAppController::HandleCaptureCompletion(), DATAMAKE2" ) )        	
       
  8324        ReleaseCamera();
       
  8325     }
       
  8326   PRINT( _L( "Camera <= CCamAppController::HandleCaptureCompletion()" ) )        
       
  8327   }    
       
  8328 
       
  8329 
       
  8330 
       
  8331 // ---------------------------------------------------------------------------
       
  8332 // CCamAppController::CheckAfModeForScene
       
  8333 // Checks the current scene/based on scene to see if AF mode needs setting
       
  8334 // ---------------------------------------------------------------------------
       
  8335 //           
       
  8336 void CCamAppController::CheckAfModeForScene( TBool aForceAFReset )
       
  8337     {
       
  8338     PRINT(_L("Camera => CCamAppController::CheckAfModeForScene"));
       
  8339 
       
  8340     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8341         {
       
  8342         TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );
       
  8343         }
       
  8344 
       
  8345     PRINT(_L("Camera <= CCamAppController::CheckAfModeForScene"));
       
  8346     }
       
  8347 
       
  8348 
       
  8349 // ---------------------------------------------------------------------------
       
  8350 // CCamAppController::TryAutoFocus
       
  8351 // Start an AF operation, if needed
       
  8352 // ---------------------------------------------------------------------------
       
  8353 //      
       
  8354 TBool CCamAppController::TryAutoFocus()   
       
  8355     {  
       
  8356     PRINT( _L("Camera => CCamAppController::TryAutoFocus()") );  
       
  8357     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_TRYAUTOFOCUS, "e_CAM_APP_AF_LOCK 1" );  //CCORAPP_AF_LOCK_START
       
  8358     
       
  8359     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8360         {
       
  8361         if( ECamActiveCameraPrimary != iInfo.iActiveCamera ||
       
  8362             ECamControllerImage != iInfo.iMode )
       
  8363           {
       
  8364           PRINT( _L("Returning EFalse - Not using primary camera in still mode") );  
       
  8365           // Not using primary camera in still mode      
       
  8366           return EFalse; // Not focusing
       
  8367           }
       
  8368                 
       
  8369         PRINT( _L("Calling IssueDirectRequestL( ECamRequestStartAutofocus )") );       
       
  8370         return TryAFRequest( ECamRequestStartAutofocus );
       
  8371         }
       
  8372     else 
       
  8373         {
       
  8374         return ETrue;
       
  8375         }
       
  8376     }
       
  8377 
       
  8378 
       
  8379 // ---------------------------------------------------------
       
  8380 // CCamAppController::CurrentSceneHasForcedFocus
       
  8381 // Returns whether the current scene has focus forced to 
       
  8382 // a particular value ( eg Macro/Landscape modes may have
       
  8383 // focus fixed to Macro/Infinite )
       
  8384 // ---------------------------------------------------------
       
  8385 //  
       
  8386 TBool CCamAppController::CurrentSceneHasForcedFocus() const
       
  8387     {
       
  8388     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8389         {
       
  8390         // Work out what the current scene is (or if current scene is user
       
  8391         // scene, what it's based on).
       
  8392         TInt currentScene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  8393         if ( currentScene  == ECamSceneUser )
       
  8394             {
       
  8395             currentScene = IntegerSettingValue( ECamSettingItemUserSceneBasedOnScene );
       
  8396             }
       
  8397 
       
  8398         TBool isFaceTrackingOn = (iConfigManager &&
       
  8399                     iConfigManager->IsFaceTrackingSupported() &&
       
  8400                     (iSettingsModel->IntegerSettingValue( 
       
  8401                     ECamSettingItemFaceTracking ) == ECamSettOn ) );
       
  8402     
       
  8403         // Check if the current (or based on) scene is one that should *not* have 
       
  8404         // a reticule.
       
  8405         if ( ( currentScene == ECamSceneScenery 
       
  8406           || currentScene == ECamSceneNightScenery 
       
  8407           || currentScene == ECamSceneSports )
       
  8408           && !isFaceTrackingOn )
       
  8409             {
       
  8410             return ETrue;
       
  8411             }
       
  8412         else
       
  8413             {
       
  8414             return EFalse;
       
  8415             }
       
  8416         }
       
  8417     else
       
  8418         {
       
  8419         return ETrue;
       
  8420         }
       
  8421     }
       
  8422 
       
  8423 // ---------------------------------------------------------------------------
       
  8424 // CCamAppController::CaptureToneDelayTimeout
       
  8425 // Timeout from capture tone delay timer
       
  8426 // ---------------------------------------------------------------------------
       
  8427 //
       
  8428 TInt CCamAppController::CaptureToneDelayTimeout( TAny* aPtr )
       
  8429     {
       
  8430     PRINT( _L("Camera => CCamAppController::CaptureToneDelayTimeoutL") )
       
  8431     static_cast<CCamAppController*>( aPtr )->PlayDelayedCaptureTone();
       
  8432     return KErrNone;
       
  8433     }
       
  8434 
       
  8435 // ---------------------------------------------------------------------------
       
  8436 // CCamAppController::PlayDelayedCaptureTone
       
  8437 // Play capture tone
       
  8438 // ---------------------------------------------------------------------------
       
  8439 //  
       
  8440 void CCamAppController::PlayDelayedCaptureTone()
       
  8441     {
       
  8442     PlaySound( CaptureToneId(), EFalse );
       
  8443     }
       
  8444 
       
  8445 // ---------------------------------------------------------------------------
       
  8446 // CCamAppController::InitAutoFocusL
       
  8447 // Initalises the AutoFocus interface, if needed
       
  8448 // ---------------------------------------------------------------------------
       
  8449 //
       
  8450 void CCamAppController::InitAutoFocusL()
       
  8451     {
       
  8452     PRINT( _L("Camera => CCamAppController::InitAutoFocusL") )
       
  8453     PRINT(_L("Camera !! DISABLED"));
       
  8454     PRINT( _L("Camera <= CCamAppController::InitAutoFocusL") )
       
  8455     }
       
  8456 
       
  8457 // ---------------------------------------------------------------------------
       
  8458 // CCamAppController::CopySnapshotIfNeededL
       
  8459 // Helper function for McaeoSnapImageReady that makes a copy of the snapshot
       
  8460 // if needed to fake a viewfinder or for image rotation.
       
  8461 // ---------------------------------------------------------------------------
       
  8462 //
       
  8463 
       
  8464 void 
       
  8465 CCamAppController::CopySnapshotIfNeeded( const CFbsBitmap& aSnapshot, TInt aError )
       
  8466   { 
       
  8467   if ( ECamImageCaptureTimeLapse == iInfo.iImageMode 
       
  8468     || ECamControllerVideo == iInfo.iMode   
       
  8469     || ( iConfigManager && iConfigManager->IsOrientationSensorSupported() &&
       
  8470         iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) == ECamSettOn )
       
  8471      )
       
  8472     {
       
  8473     StopIdleTimer();
       
  8474     delete iSnapShotCopy;
       
  8475     iSnapShotCopy = NULL;
       
  8476     TRAP_IGNORE ( ( iSnapShotCopy = new(ELeave) CFbsBitmap() ) );
       
  8477     
       
  8478     if ( iSnapShotCopy )
       
  8479       {
       
  8480       TInt dupeError = iSnapShotCopy->Duplicate( aSnapshot.Handle() );
       
  8481       
       
  8482       if ( dupeError )
       
  8483         {
       
  8484         iSnapShotCopy->Reset();
       
  8485         delete iSnapShotCopy;
       
  8486         iSnapShotCopy = NULL;
       
  8487         }
       
  8488       else if ( iConfigManager && !iConfigManager->IsOrientationSensorSupported() )
       
  8489         {
       
  8490         if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  8491           {
       
  8492           // simulate the receipt of a viewfinder frame using the snapshot image
       
  8493           // McaeoViewFinderFrameReady( *iSnapShotCopy, aError );  
       
  8494           HandleViewfinderFrame( aError, iSnapShotCopy );
       
  8495           }
       
  8496         }                
       
  8497       }        
       
  8498     }
       
  8499   }
       
  8500 
       
  8501 
       
  8502 
       
  8503 // ---------------------------------------------------------------------------
       
  8504 // CCamAppController::EnableScreenSaver
       
  8505 // Turns the screen saver on or off for timelapse capture
       
  8506 //
       
  8507 // ---------------------------------------------------------------------------
       
  8508 //  
       
  8509 void 
       
  8510 CCamAppController::EnableScreenSaver( TBool aEnable )  
       
  8511   {
       
  8512   if ( !aEnable ) 
       
  8513     {
       
  8514     // Stop the screensaver from appearing
       
  8515     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 1 );        
       
  8516     }
       
  8517   else
       
  8518     {
       
  8519     // Allow the screensaver to appear
       
  8520     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 0 );
       
  8521     User::ResetInactivityTime();      
       
  8522     }        
       
  8523   }
       
  8524 
       
  8525 
       
  8526 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  8527 // ---------------------------------------------------------------------------
       
  8528 // CCamAppController::SetPerformanceState
       
  8529 //
       
  8530 // ---------------------------------------------------------------------------
       
  8531 //  
       
  8532 void CCamAppController::SetPerformanceState( TCamPerformanceState aState )  
       
  8533   {
       
  8534   iPerformanceState = aState;
       
  8535   }
       
  8536 #endif
       
  8537 
       
  8538 // ---------------------------------------------------------------------------
       
  8539 // CCamAppController::StartLocationTrailL()
       
  8540 // Connects and starts the locationtrail
       
  8541 // ---------------------------------------------------------------------------
       
  8542 //
       
  8543 void CCamAppController::StartLocationTrailL()
       
  8544   {
       
  8545   PRINT( _L("Camera => CCamAppController::StartLocationTrailL") );
       
  8546   CCamAppUi* appUI = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8547 
       
  8548   // If a stop request is pending but the trail is being restarted, stop 
       
  8549   // and delete the timer
       
  8550   if( iLocationTrailTimer )
       
  8551   	{
       
  8552   	iLocationTrailTimer->Cancel();
       
  8553    	delete iLocationTrailTimer;
       
  8554    	iLocationTrailTimer = NULL;
       
  8555    	}
       
  8556   
       
  8557   TInt err = KErrNone;
       
  8558 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) 
       
  8559   if ( !iLocationTrailStarted )
       
  8560 	  {
       
  8561 	  if ( !iLocationUtilityConnected ) 
       
  8562 	    {
       
  8563 	    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Connect()") );
       
  8564 	    TVwsViewId activeView;
       
  8565 	    if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8566 	      {
       
  8567 	      if( ECamViewIdStillPreCapture == activeView.iViewUid.iUid  )
       
  8568 	          {
       
  8569 	          CCamPreCaptureViewBase* view = static_cast<CCamPreCaptureViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8570 	          view->SetLocationTrailConnecting();
       
  8571 	          }
       
  8572 	      }
       
  8573 	    User::LeaveIfError( iLocationUtility.Connect() );
       
  8574 	    iLocationUtilityConnected = ETrue;
       
  8575 	    }
       
  8576 	  err = iLocationUtility.StartLocationTrail( RLocationTrail::ECaptureAll );
       
  8577 	  }
       
  8578 #endif
       
  8579   // If start fails, change the setting to off 
       
  8580   if( KErrNone != err )
       
  8581     {
       
  8582     PRINT1( _L("Camera :: CCamAppController::StartLocationTrailL error:%d encountered while starting location trail"), err )
       
  8583     
       
  8584 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8585     // Disconnect from the location utility
       
  8586     PRINT( _L("Camera => CCamAppController::StartLocationTrailL - Starting of LocationTrail failed -> iLocationUtility.Close()") );
       
  8587     iLocationUtility.Close();
       
  8588     iLocationUtilityConnected = EFalse;
       
  8589     SetIntegerSettingValueL( ECamSettingItemRecLocation, ECamLocationOff );
       
  8590 #endif
       
  8591     
       
  8592     // Going to standby mode, location trail disabled
       
  8593 	  /*
       
  8594     TVwsViewId activeView;
       
  8595     if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8596       {
       
  8597       CCamViewBase* view = static_cast<CCamViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8598       view->SwitchToStandbyModeL( TCamAppViewIds(activeView.iViewUid.iUid), err );
       
  8599       }
       
  8600       */
       
  8601     appUI->SetStandbyStatus( err );
       
  8602     appUI->HandleCommandL( ECamCmdGoToStandby );
       
  8603     }
       
  8604   else
       
  8605   	{
       
  8606   	iLocationTrailStarted = ETrue;
       
  8607   	}
       
  8608   PRINT( _L("Camera <= CCamAppController::StartLocationTrailL") );
       
  8609   }
       
  8610 
       
  8611 // ---------------------------------------------------------------------------
       
  8612 // CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8613 // Stops the locationtrail
       
  8614 // ---------------------------------------------------------------------------
       
  8615 //    
       
  8616 void CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8617 	  {
       
  8618 	  PRINT1( _L("Camera => CCamAppController::StopLocationTrail operation mode:%d"), iInfo.iOperation );
       
  8619 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8620 	  if( iLocationTrailStarted )
       
  8621 		{
       
  8622 		// if not ECamCapturing, ECamPausing, ECamPaused, ECamResuming or ECamCompleting
       
  8623 		if( (iInfo.iOperation < ECamCapturing || iInfo.iOperation > ECamCompleting ) && 
       
  8624 		    ( CurrentFullFileName() == KNullDesC || SavedCurrentImage() )
       
  8625 		  )
       
  8626 			{
       
  8627 			PRINT( _L("Camera :: CCamAppController::StopLocationTrail - stopping location trail") )
       
  8628 			iLocationUtility.StopLocationTrail();
       
  8629 			if ( aCloseSession ) 
       
  8630 			    {
       
  8631 			    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Close()") );
       
  8632 			    iLocationUtility.Close();
       
  8633 			    iLocationUtilityConnected = EFalse;
       
  8634 			    }
       
  8635 			iLocationTrailStarted = EFalse;
       
  8636 			
       
  8637 			// If a timer was used to stop the location trail, then cancel and delete the timer
       
  8638 	        if( iLocationTrailTimer )
       
  8639 	        	{
       
  8640 	        	iLocationTrailTimer->Cancel();
       
  8641 	        	delete iLocationTrailTimer;
       
  8642 	        	iLocationTrailTimer = NULL;
       
  8643 	        	}		
       
  8644 			}
       
  8645 		else
       
  8646 			{
       
  8647 			// Use a timer to close the trail in a few seconds
       
  8648 	    	PRINT( _L("Camera :: CCamAppController::StopLocationTrail - location trail in use") )
       
  8649 	    	if( !iLocationTrailTimer )
       
  8650 	    		{
       
  8651 	    		TRAP_IGNORE( iLocationTrailTimer = CCamTimer::NewL( KLocTrailCloseRetryTime, 
       
  8652 	    		  TCallBack( CCamAppController::RetryStopLocationTrail, this ) ) );
       
  8653 	    		}
       
  8654 	    	else // restart the timer
       
  8655 	    		{
       
  8656 				iLocationTrailTimer->Cancel();
       
  8657 				iLocationTrailTimer->SetTimeout( KLocTrailCloseRetryTime );
       
  8658 	    		}
       
  8659 	    	iLocationTrailTimer->StartTimer();
       
  8660 			}
       
  8661 		}
       
  8662 	#endif
       
  8663 	  PRINT( _L("Camera <= CCamAppController::StopLocationTrail") );
       
  8664 	  }
       
  8665 
       
  8666 // ---------------------------------------------------------------------------
       
  8667 // CCamAppController::RetryStopLocationTrail()
       
  8668 // Timer callback function to attempt to remove the location trail periodically
       
  8669 // ---------------------------------------------------------------------------
       
  8670 //    
       
  8671 TInt CCamAppController::RetryStopLocationTrail( TAny* aPtr )
       
  8672 	{
       
  8673 	PRINT( _L("Camera => CCamAppController::RetryStopLocationTrail") )
       
  8674 	static_cast<CCamAppController*>( aPtr )->StopLocationTrail();
       
  8675 	PRINT( _L("Camera <= CCamAppController::RetryStopLocationTrail") )
       
  8676 	return KErrNone;
       
  8677 	}
       
  8678   
       
  8679 // -----------------------------------------------------------------------------
       
  8680 // CCamAppController::CaptureKeyPressedWhileImageSaving
       
  8681 // Whether or not a capture key pressed during image saving
       
  8682 // -----------------------------------------------------------------------------
       
  8683 //
       
  8684 TBool CCamAppController::CaptureKeyPressedWhileImageSaving() const
       
  8685 	{
       
  8686 	return iCaptureKeyPressedWhileImageSaving;
       
  8687 	}
       
  8688 	
       
  8689 // -----------------------------------------------------------------------------
       
  8690 // CCamAppController::SetCaptureKeyPressedWhileImageSaving
       
  8691 // -----------------------------------------------------------------------------
       
  8692 //
       
  8693 void CCamAppController::SetCaptureKeyPressedWhileImageSaving(TBool aCaptureKeyPressed)
       
  8694 	{
       
  8695 	iCaptureKeyPressedWhileImageSaving = aCaptureKeyPressed;
       
  8696 	}
       
  8697   
       
  8698 
       
  8699 
       
  8700 // ---------------------------------------------------------------------------
       
  8701 // CamerasAvailable <<static>>
       
  8702 //
       
  8703 // Commonly needed in UI classes, so added also support to get this info
       
  8704 // through this class. This way we avoid unnecessary binding of 
       
  8705 // CCameraController and UI classes.
       
  8706 // ---------------------------------------------------------------------------
       
  8707 //
       
  8708 TInt 
       
  8709 CCamAppController::CamerasAvailable()
       
  8710   {
       
  8711   return CCamCameraController::CamerasAvailable();
       
  8712   }
       
  8713 
       
  8714 TBool 
       
  8715 CCamAppController::TimeLapseSupported()
       
  8716   {
       
  8717   return (ECamSupportOn == iSettingsModel->VariantInfo().iTimeLapseSupport);
       
  8718   }
       
  8719     
       
  8720 TBool 
       
  8721 CCamAppController::AlwaysOnSupported()
       
  8722   {
       
  8723   return (ECamSupportOn == iSettingsModel->VariantInfo().iAlwaysOnSupport);
       
  8724   }
       
  8725 
       
  8726 const TVersion& 
       
  8727 CCamAppController::Version()
       
  8728   {
       
  8729   return iSettingsModel->VariantInfo().iVersion;
       
  8730   }
       
  8731 
       
  8732 
       
  8733 // <<public>>
       
  8734 TBool 
       
  8735 CCamAppController::Busy() const
       
  8736   {
       
  8737   return (EBusyNone != iBusyFlags || CameraControllerBusy() );
       
  8738   }
       
  8739 
       
  8740 TBool 
       
  8741 CCamAppController::CameraControllerBusy() const
       
  8742   {
       
  8743   return (iCameraController && ECamBusyOff != iCameraController->ControllerInfo().iBusy );
       
  8744   }
       
  8745 
       
  8746 // ===========================================================================
       
  8747 // From MCamCameraObserver
       
  8748 
       
  8749 // ---------------------------------------------------------------------------
       
  8750 // HandleCameraEventL <<virtual>>
       
  8751 // ---------------------------------------------------------------------------
       
  8752 //
       
  8753 void 
       
  8754 CCamAppController
       
  8755 ::HandleCameraEventL( TInt              aStatus, 
       
  8756                       TCamCameraEventId aEventId, 
       
  8757                       TAny*             aEventData /*= NULL*/ )
       
  8758   {
       
  8759 #ifdef _DEBUG    
       
  8760   // Log viewfinder events with PRINT_FRQ
       
  8761   // #ifdef _DEBUG is used to avoid extra if in release builds
       
  8762   // where logging is not used anyway.
       
  8763   if( ECamCameraEventVfFrameReady == aEventId )  
       
  8764     {
       
  8765     PRINT_FRQ1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  8766           KCamCameraEventNames[aEventId] );    
       
  8767     }
       
  8768   else
       
  8769 #endif // _DEBUG    
       
  8770     {
       
  8771     PRINT1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  8772             KCamCameraEventNames[aEventId] );
       
  8773     }
       
  8774  
       
  8775   // in case we get poweron event before appui is completely constructed
       
  8776   // finish it here
       
  8777   if ( aEventId == ECamCameraEventPowerOn )
       
  8778       {
       
  8779       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8780       if ( iConfigManager && 
       
  8781            iConfigManager->IsUIOrientationOverrideSupported() && 
       
  8782            !appUi->IsUiConstructionComplete() )
       
  8783           {
       
  8784           appUi->AppUIConstructCallbackL( appUi );  
       
  8785           }
       
  8786       }       
       
  8787 
       
  8788   TInt handleError( KErrNone );
       
  8789 
       
  8790   if( ECamCameraEventVfFrameReady != aEventId &&
       
  8791       KErrNone == aStatus || KErrDiskFull == aStatus || KErrCompletion == aStatus ) 
       
  8792     {
       
  8793     // Called for all events, except viewfinder frame ready event.    
       
  8794     SetStateFromEvent( aEventId );
       
  8795     }
       
  8796   
       
  8797   if( ECamCameraEventImageInit == aEventId ||
       
  8798       ECamCameraEventVideoInit == aEventId )
       
  8799     {  
       
  8800     iSettingsRestoreNeeded = ETrue;  
       
  8801     }
       
  8802 
       
  8803 
       
  8804   // NOTE: Consider that the ones needing these events
       
  8805   //       receive them directly from Camera Controller?
       
  8806   switch( aEventId )
       
  8807     {
       
  8808     case ECamCameraEventVfStart:
       
  8809       {
       
  8810       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  8811       // For forced focus scenes, do one autofocus request once vf starts if needed
       
  8812       if( UiConfigManagerPtr()->IsAutoFocusSupported() )
       
  8813         {
       
  8814         if( CurrentSceneHasForcedFocus() || UiConfigManagerPtr()->IsAutofocusSetInHyperfocalAtStartup() ) 
       
  8815             {
       
  8816             PRINT( _L( "Camera => CCamAppController::HandleCameraEventL, TryAFRequest( ECamRequestCancelAutofocus )") );
       
  8817             TryAFRequest( ECamRequestCancelAutofocus ); 
       
  8818             }
       
  8819         }
       
  8820       if( iSettingsRestoreNeeded )
       
  8821         {
       
  8822         iSettingsRestoreNeeded = EFalse;  
       
  8823         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  8824         }
       
  8825       // fixed toolbar is used only with touch devices
       
  8826       if ( IsTouchScreenSupported() )
       
  8827           {
       
  8828           appUi->SetToolbarVisibility();// avoid flickering in settings view
       
  8829           PRINT( _L( "Camera <> SetToolbarVisibility done ") );
       
  8830           }
       
  8831       // else use AP    
       
  8832       else
       
  8833           {
       
  8834           if( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() )
       
  8835               {
       
  8836               NotifyControllerObservers( ECamEventInitReady );
       
  8837               }
       
  8838           }
       
  8839       
       
  8840       if ( UiConfigManagerPtr()->IsLocationSupported() &&
       
  8841                    !appUi->IsEmbedded())
       
  8842               {
       
  8843               if( ECamLocationOn == IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  8844                   {
       
  8845                   if( ECamActiveCameraPrimary == ActiveCamera() && ECamStandby != CurrentOperation() )
       
  8846                       {
       
  8847                       StartLocationTrailL();
       
  8848                       }
       
  8849                   else // Secondary camera 
       
  8850                       {
       
  8851                       PRINT( _L("Camera: CCamAppController::HandleCameraEventL - secondary camera, stop location trail") )
       
  8852                       StopLocationTrail();
       
  8853                       }
       
  8854                   }
       
  8855               }
       
  8856       break;
       
  8857       }
       
  8858     case ECamCameraEventVfFrameReady:
       
  8859       {      
       
  8860       HandleViewfinderFrame( aStatus, static_cast<CFbsBitmap*>( aEventData ) );
       
  8861       
       
  8862       if( KErrNone == aStatus && iSettingsRestoreNeeded )
       
  8863         {
       
  8864         iSettingsRestoreNeeded = EFalse;  
       
  8865         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  8866         }
       
  8867       return;
       
  8868       }
       
  8869     case ECamCameraEventSsReady:
       
  8870       {
       
  8871       TRAP_IGNORE( HandleSnapshotEvent( aStatus, static_cast<CFbsBitmap*>( aEventData ) ) );
       
  8872       
       
  8873       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  8874              CurrentCapturedCount() < CaptureLimit() )
       
  8875             {
       
  8876             // check memory level
       
  8877             TInt memoryLeft = 0;
       
  8878             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  8879                                           
       
  8880             if ( memoryLeft < KCriticalMemoryLevel )
       
  8881                 {
       
  8882                 PRINT( _L("Camera <> RAM is below critical level #1") )
       
  8883                 // memory below critical level, need to stop capture
       
  8884                 SoftStopBurstL( ETrue );
       
  8885                 EventHandlingErrorRecovery( KErrNoMemory );
       
  8886                 }
       
  8887             }
       
  8888       
       
  8889       break;
       
  8890       }
       
  8891     case ECamCameraEventImageData:
       
  8892       {
       
  8893 //      TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<HBufC8*>( aEventData ) ) ); 
       
  8894       TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<CCamBufferShare*>( aEventData ) ) );
       
  8895       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  8896              CurrentCapturedCount() < CaptureLimit() )
       
  8897             {
       
  8898             // check memory level
       
  8899             TInt memoryLeft = 0;
       
  8900             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  8901             if ( memoryLeft < KCriticalMemoryLevel )
       
  8902                 {
       
  8903                 PRINT( _L("Camera <> RAM is below critical level #2") )
       
  8904                 // memory below critical level, need to stop capture
       
  8905                 TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  8906                 EventHandlingErrorRecovery( KErrNoMemory );
       
  8907                 }
       
  8908             }
       
  8909       break;
       
  8910       }
       
  8911     case ECamCameraEventImageStop:
       
  8912       {
       
  8913       TRAP( aStatus, HandleImageStopEventL( aStatus, aEventData ? *static_cast<TInt*>( aEventData ) : 0 ) );
       
  8914       break;
       
  8915       }
       
  8916 
       
  8917     case ECamCameraEventAutofocusSuccessful: // Flowthrough
       
  8918     case ECamCameraEventAutofocusFailed:
       
  8919       {        
       
  8920       // Autofocusing is done, do possible pending capture  
       
  8921       SetAfNeeded( EFalse );
       
  8922       if( iCaptureRequested && !EngineProcessingCapture() )
       
  8923         {
       
  8924         iCaptureRequested = EFalse;
       
  8925         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_SNAPSHOT 1" );
       
  8926         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SNAPSHOT 1" );
       
  8927         OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SAVE 1" );
       
  8928         OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SHOT 1" );
       
  8929         OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_STILL 1" );
       
  8930         OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_CAPTURE_START 1" );
       
  8931         OstTrace0( CAMERAAPP_PERFORMANCE, DUP6_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SERIAL_SHOOTING 1" );
       
  8932         
       
  8933         Capture();  
       
  8934         }           
       
  8935       break;  
       
  8936       }
       
  8937       
       
  8938     case ECamCameraEventSettingsSingle:
       
  8939       {
       
  8940       TRAP_IGNORE( HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  8941       return;
       
  8942       }
       
  8943     case ECamCameraEventVideoAsyncStop: 
       
  8944     case ECamCameraEventVideoStop:
       
  8945       {
       
  8946       // we always want to handle these events. set the flag because
       
  8947       // there is a possibility that some other event has come before
       
  8948       // and caused the flag to be cleared
       
  8949       SetFlags(iBusyFlags, EBusyRequest);
       
  8950       if ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) 
       
  8951 	     && CurrentStorage() == ECamMediaStorageCard )
       
  8952       	{
       
  8953         aStatus = KErrNone; 
       
  8954       	}
       
  8955       if( aStatus != KErrNone && aStatus != KErrDiskFull && aStatus != KErrCompletion 
       
  8956               && !( aStatus == KErrPathNotFound && IsCaptureStoppedForUsb() ) )
       
  8957           {
       
  8958           iSaving = EFalse;
       
  8959           SetOperation( ECamStandby, KErrGeneral );
       
  8960           }
       
  8961       else
       
  8962           {
       
  8963           // In case of no error, we are already in appropriate state
       
  8964           }
       
  8965 	  break;
       
  8966       }
       
  8967     case ECamCameraEventIveRecover:  
       
  8968       {
       
  8969       if( !Busy() )
       
  8970         {
       
  8971         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Issue new recovery sequence" ) );
       
  8972         SetStateFromEvent( ECamCameraEventReserveLose );  
       
  8973         SetTargetMode( ECamControllerImage );
       
  8974         SetTargetImageMode( CurrentImageModeSetup() );
       
  8975         IssueModeChangeSequenceL();
       
  8976         }
       
  8977       else
       
  8978         {
       
  8979         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Recovery sequence is active" ) );
       
  8980         }
       
  8981       break;
       
  8982       }
       
  8983     case ECamCameraEventSequenceEnd:
       
  8984       {
       
  8985       // only for image mode	
       
  8986       if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  8987           && ECamControllerImage == CurrentMode() )
       
  8988         {	
       
  8989         // If the camera orientation changed during initialization sequence and not in burst mode, 
       
  8990         // set the new orientation
       
  8991         if ( iOrientationChangeOccured &&
       
  8992              iInfo.iImageMode != ECamImageCaptureBurst )  
       
  8993           {
       
  8994           iOrientationChangeOccured = EFalse;
       
  8995           TRAP_IGNORE( SetImageOrientationL() );
       
  8996           }
       
  8997         if( !iAccSensorListening )
       
  8998           {
       
  8999           TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  9000           }
       
  9001         }
       
  9002         if ( aStatus == KErrCancel )
       
  9003             {
       
  9004             // sequence canceled, no need to event further
       
  9005             return;
       
  9006             }
       
  9007       break;
       
  9008       }  
       
  9009     default:
       
  9010       break;
       
  9011     }
       
  9012 
       
  9013 
       
  9014   // -------------------------------------------------------
       
  9015   // We have requested a series of operations.
       
  9016   // The sequences have ids, which we use to determine
       
  9017   // the right procedure. React when sequence ends.
       
  9018   if( IsFlagOn( iBusyFlags, EBusySequence ) )
       
  9019     {
       
  9020     PRINT( _L( "Camera <> Sequence of requests pending" ) );
       
  9021     TRAP( handleError, HandleSequenceEventL( aStatus, aEventId, aEventData ) );
       
  9022     }
       
  9023   // -------------------------------------------------------
       
  9024   // We have single request pending.
       
  9025   else if( IsFlagOn( iBusyFlags, EBusyRequest ) )
       
  9026     {
       
  9027     PRINT( _L( "Camera <> Single request pending" ) );
       
  9028     TRAP( handleError, HandleRequestEventL( aStatus, aEventId, aEventData ) );
       
  9029     }
       
  9030   else if( IsFlagOn( iBusyFlags, EBusySetting ) )
       
  9031     {
       
  9032     PRINT( _L( "Camera <> Settings finished" ) );
       
  9033     TRAP( handleError, HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  9034     }
       
  9035   // -------------------------------------------------------
       
  9036   // No request pending for us.
       
  9037   // Direct request issued to Camera controller.
       
  9038   else
       
  9039     {
       
  9040     PRINT( _L( "Camera <> No requests pending!!" ) );
       
  9041     // handle these ..
       
  9042     }
       
  9043 
       
  9044   // -------------------------------------------------------
       
  9045   if( KErrNone != handleError )
       
  9046     {
       
  9047     EventHandlingErrorRecovery( handleError );
       
  9048     }
       
  9049 
       
  9050   // Reserve lost event is always handled.
       
  9051   if( ECamCameraEventReserveLose == aEventId && KErrNone != aStatus )
       
  9052     {
       
  9053     SetOperation( ECamStandby, aStatus );
       
  9054     }
       
  9055     
       
  9056   if( iPendingRelease && !Busy() &&
       
  9057       !IsSavingInProgress() && iInfo.iOperation != ECamCapturing ) 
       
  9058     {  
       
  9059     // Finally, if camera release is pending, and we are no longer busy,
       
  9060     // call ReleaseCamera to get it done.
       
  9061     // ReleaseCamera is used instead of simply setting iInfo.iTargetMode,
       
  9062     // because it also handles stopping ongoing burst captures.
       
  9063     PRINT( _L( "Camera <> CCamAppController::HandleCameraEventL, release pending, calling ReleaseCamera..") );
       
  9064     ReleaseCamera();  
       
  9065     }    
       
  9066 
       
  9067 #ifdef _DEBUG    
       
  9068   // Log viewfinder events with PRINT_FRQ
       
  9069   if( ECamCameraEventVfFrameReady == aEventId )  
       
  9070     {
       
  9071     PRINT_FRQ( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );  
       
  9072     }
       
  9073   else  
       
  9074 #endif // _DEBUG    
       
  9075     {
       
  9076     PRINT( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );
       
  9077     }
       
  9078   }
       
  9079 
       
  9080 // ===========================================================================
       
  9081 
       
  9082 
       
  9083 // ---------------------------------------------------------------------------
       
  9084 // EventHandlingErrorRecovery
       
  9085 // ---------------------------------------------------------------------------
       
  9086 //
       
  9087 void
       
  9088 CCamAppController::EventHandlingErrorRecovery( TInt aError )
       
  9089   {
       
  9090   PRINT1( _L( "Camera => CCamAppController::EventHandlingErrorRecovery, error:%d" ), aError );
       
  9091 
       
  9092   __ASSERT_ALWAYS( aError != KErrNone, CamPanic( ECamPanicInvalidState ) );
       
  9093 
       
  9094   iCaptureModeTransitionInProgress = EFalse;
       
  9095 
       
  9096   // Reset the saving flag to ensure that camera does not get stuck
       
  9097   iSaving = EFalse;  
       
  9098 
       
  9099   iMuteNotifications = ETrue;
       
  9100 
       
  9101   // Cancel ongoing sequence if any
       
  9102   iCameraController->CancelSequence();
       
  9103 
       
  9104   // Clear busy flags
       
  9105   iBusyFlags           = EBusyNone;
       
  9106   iInfo.iBusyRequestId = ECamRequestNone;
       
  9107 
       
  9108   iMuteNotifications = EFalse;
       
  9109 
       
  9110   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9111   //Don't change to Stand by mode if -4 error gotten during burst (somehow expected)
       
  9112   if(SequenceCaptureInProgress() && appUi->CurrentBurstMode() == ECamImageCaptureBurst && KErrNoMemory == aError )
       
  9113     {
       
  9114     TRAP_IGNORE( appUi->HandleCameraErrorL(aError) );
       
  9115     }
       
  9116   else
       
  9117     {
       
  9118     SetOperation( ECamStandby, aError );
       
  9119     }
       
  9120 
       
  9121   NotifyControllerObservers( ECamEventControllerReady, aError );
       
  9122 
       
  9123   PRINT( _L( "Camera <= CCamAppController::EventHandlingErrorRecovery" ) );
       
  9124   }
       
  9125 
       
  9126 // ---------------------------------------------------------------------------
       
  9127 // HandleSettingEventL
       
  9128 // ---------------------------------------------------------------------------
       
  9129 //
       
  9130 void
       
  9131 CCamAppController::HandleSettingEventL( TInt              aStatus, 
       
  9132                                         TCamCameraEventId aEventId, 
       
  9133                                         TAny*             aEventData )
       
  9134   {
       
  9135   PRINT( _L( "Camera => CCamAppController::HandleSettingEventL" ) );
       
  9136   // -------------------------------------------------------
       
  9137   if( ECamCameraEventSettingsDone == aEventId )
       
  9138     {
       
  9139     ClearFlags( iBusyFlags, EBusySetting );
       
  9140 
       
  9141     // Need to clear any pending settings.
       
  9142     iSettingProvider->Reset();
       
  9143 
       
  9144     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9145       {
       
  9146       PRINT( _L( "Camera <> CCamAppController: Releasing camera.." ) );
       
  9147       IssueRequestL( ECamRequestRelease );
       
  9148       }
       
  9149     else
       
  9150       {
       
  9151       PRINT( _L( "Camera <> CCamAppController: Got setting end event.." ) );      
       
  9152       if( KErrNone != aStatus )
       
  9153         {
       
  9154         TCamCameraSettingId* cameraSetting =
       
  9155             static_cast<TCamCameraSettingId*>( aEventData );
       
  9156 
       
  9157         // Leave with the incoming error, if setting id not provided.
       
  9158         CheckNonNullL( cameraSetting, aStatus );
       
  9159 
       
  9160         if( ECameraSettingFileName == *cameraSetting )
       
  9161           {
       
  9162           DoVideoNameRetryL( aStatus );
       
  9163           }
       
  9164         else
       
  9165           {
       
  9166           User::Leave( aStatus );
       
  9167           }
       
  9168         }
       
  9169       else
       
  9170         {
       
  9171         ProceedPendingOrNotifyReadyL();
       
  9172         }
       
  9173       }
       
  9174     }
       
  9175   // -------------------------------------------------------
       
  9176   else if( ECamCameraEventSettingsSingle == aEventId )
       
  9177     {
       
  9178     TCamCameraSettingId* cameraSetting =
       
  9179         static_cast<TCamCameraSettingId*>( aEventData );
       
  9180 
       
  9181     CheckNonNullL( cameraSetting, KErrNotFound );
       
  9182     switch( *cameraSetting )
       
  9183       {
       
  9184       case ECameraSettingDigitalZoom:
       
  9185       case ECameraSettingOpticalZoom:
       
  9186         {
       
  9187         PRINT( _L( "Camera <> CCamAppController: zoom event" ) );
       
  9188         NotifyControllerObservers( ECamEventZoomStateChanged, aStatus );
       
  9189         // Pending zooming done in HandleViewfinderFrame
       
  9190         break;
       
  9191         }
       
  9192       default:
       
  9193         PRINT( _L( "Camera <> CCamAppController: unhandled setting event" ) );
       
  9194         break;
       
  9195       }
       
  9196     }
       
  9197   // -------------------------------------------------------
       
  9198   else
       
  9199     {
       
  9200     // Ignored
       
  9201     }
       
  9202   // -------------------------------------------------------
       
  9203   PRINT( _L( "Camera <= CCamAppController::HandleSettingEventL" ) );
       
  9204   }
       
  9205 
       
  9206 // ---------------------------------------------------------------------------
       
  9207 // DoVideoNameRetryL
       
  9208 // ---------------------------------------------------------------------------
       
  9209 //
       
  9210 void
       
  9211 CCamAppController::DoVideoNameRetryL( TInt aStatus )
       
  9212   {
       
  9213   PRINT( _L( "Camera => CCamAppController::DoVideoNameRetryL" ) );
       
  9214   if ( IsFlagOn( iCameraController->State(), ECamVideoOn )
       
  9215     && iVideoNameRetries > 0 )        
       
  9216     {
       
  9217     PRINT1( _L( "Camera <> video rename failed retries = %d retrying rename" ), iVideoNameRetries );
       
  9218 
       
  9219     // Try again
       
  9220     --iVideoNameRetries;
       
  9221     TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  9222     if ( ECamCapturing != iInfo.iOperation && ECamPaused != iInfo.iOperation )
       
  9223       {
       
  9224       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );    
       
  9225       }
       
  9226     IssueSettingsChangeRequestL();
       
  9227     }
       
  9228   else if ( KErrDiskFull         == aStatus 
       
  9229          && ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  9230     {
       
  9231     PRINT( _L( "Camera McaeoVideoPrepareComplete disk full and set to memory card " ) );
       
  9232     NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  9233 
       
  9234     // ForceUsePhoneMemory
       
  9235     if( ExistMassStorage() )
       
  9236         {
       
  9237         TRAP_IGNORE( 
       
  9238             {
       
  9239             iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9240             									     ECamMediaStorageMassStorage );
       
  9241             GenerateNextValidVideoPathL();
       
  9242             });
       
  9243         }
       
  9244     else
       
  9245         {
       
  9246         TRAP_IGNORE( 
       
  9247            {
       
  9248            iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9249                                                     ECamMediaStoragePhone );
       
  9250            GenerateNextValidVideoPathL();
       
  9251            });       
       
  9252         
       
  9253         }
       
  9254     iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoMediaStorage );        
       
  9255     IssueSettingsChangeRequestL();
       
  9256     }
       
  9257   // No retries left
       
  9258   else 
       
  9259     {
       
  9260     PRINT1( _L( "Camera <> video prep failed retries = %d removing iVideoRequested" ), iVideoNameRetries );
       
  9261     // remove pending request, so that new attempts to record are not blocked
       
  9262     if ( iVideoRequested )
       
  9263       iVideoRequested = EFalse;
       
  9264 
       
  9265     User::LeaveIfError( aStatus );
       
  9266     }
       
  9267   PRINT( _L( "Camera <= CCamAppController::DoVideoNameRetryL" ) );
       
  9268   }
       
  9269 
       
  9270 // ---------------------------------------------------------------------------
       
  9271 // HandleCameraSequenceComplete
       
  9272 // ---------------------------------------------------------------------------
       
  9273 //
       
  9274 void
       
  9275 CCamAppController::HandleSequenceEventL( TInt              aStatus, 
       
  9276                                          TCamCameraEventId aEventId, 
       
  9277                                          TAny*             /*aEventData*/ )
       
  9278   {
       
  9279   PRINT( _L( "Camera => CCamAppController::HandleSequenceEventL" ) );
       
  9280 
       
  9281   if( iDismountPending &&
       
  9282     ( ECamCameraEventImageInit == aEventId ||
       
  9283       ECamCameraEventVideoInit == aEventId ||
       
  9284       ECamCameraEventSequenceEnd == aEventId ) )
       
  9285     {
       
  9286     iDismountPending = EFalse;
       
  9287     iDriveChangeNotifier->SendAllowDismount();	
       
  9288     }
       
  9289   if( ECamCameraEventSequenceEnd == aEventId )
       
  9290     {
       
  9291     ClearFlags( iBusyFlags, EBusySequence );
       
  9292 
       
  9293     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9294       {
       
  9295       PRINT( _L( "Camera <> In shutdown mode!!" ) );
       
  9296       IssueRequestL( ECamRequestRelease );
       
  9297       }
       
  9298     else
       
  9299       {
       
  9300       User::LeaveIfError( aStatus );
       
  9301       if( iCameraController && !iCameraController->IsWaitingIveResources() )
       
  9302         {
       
  9303         PRINT( _L( "Camera <> sequence end, proceed with pending.." ) );
       
  9304         ProceedPendingOrNotifyReadyL();  
       
  9305         }
       
  9306       }
       
  9307     }
       
  9308 
       
  9309   PRINT( _L( "Camera <= CCamAppController::HandleSequenceEventL" ) );
       
  9310   }
       
  9311 
       
  9312 // ---------------------------------------------------------------------------
       
  9313 // HandleRequestEventL
       
  9314 // ---------------------------------------------------------------------------
       
  9315 //
       
  9316 void
       
  9317 CCamAppController::HandleRequestEventL( TInt              aStatus, 
       
  9318                                         TCamCameraEventId aEventId, 
       
  9319                                         TAny*             /*aEventData*/ )
       
  9320   {
       
  9321   PRINT( _L( "Camera => CCamAppController::HandleRequestEventL" ) );
       
  9322 
       
  9323   // Check if pending operations that need immediate attention.
       
  9324   if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && 
       
  9325       iInfo.iMode != ECamControllerShutdown && 
       
  9326       !iSaving && iInfo.iOperation != ECamCapturing && 
       
  9327       iInfo.iOperation != ECamCompleting ) 
       
  9328     {
       
  9329     PRINT( _L( "Camera <> in shutdown mode, release camera.." ) );
       
  9330     IssueDirectRequestL( ECamRequestRelease );
       
  9331     }
       
  9332   else
       
  9333     {
       
  9334     if( ECamCameraEventVideoStop == aEventId )
       
  9335       {
       
  9336       ClearFlags( iBusyFlags, EBusyRequest );
       
  9337       HandleVideoStopEvent( aStatus );
       
  9338       //If postcapture view is set to off notify controller ready event
       
  9339       //for updating counter.
       
  9340       if(IntegerSettingValue(ECamSettingItemVideoShowCapturedVideo)!=ECamSettOn )
       
  9341           {
       
  9342           NotifyControllerObservers( ECamEventControllerReady, KErrNone );
       
  9343           }
       
  9344       }
       
  9345     else if( ECamCameraEventVideoAsyncStop == aEventId )
       
  9346       {
       
  9347       HandleVideoAsyncStopEvent( aStatus );
       
  9348       }
       
  9349     else
       
  9350       {
       
  9351       // Error handling in one place
       
  9352       User::LeaveIfError( aStatus );
       
  9353   
       
  9354       // If our request is fully processed.
       
  9355       if( !CameraControllerBusy() )
       
  9356         {
       
  9357         PRINT( _L( "Camera <> camera not busy, proceed or notify ready.." ) );
       
  9358         ClearFlags( iBusyFlags, EBusyRequest );
       
  9359         ProceedPendingOrNotifyReadyL();
       
  9360         }
       
  9361       }
       
  9362     }
       
  9363   PRINT( _L( "Camera <= CCamAppController::HandleRequestEventL" ) );
       
  9364   }
       
  9365 
       
  9366 
       
  9367 // ---------------------------------------------------------------------------
       
  9368 // IssueRequestL
       
  9369 // ---------------------------------------------------------------------------
       
  9370 //
       
  9371 void
       
  9372 CCamAppController
       
  9373 ::IssueRequestL( const TCamCameraRequestId& aId )
       
  9374   {
       
  9375   PRINT1( _L("Camera => CCamAppController::IssueRequestL request[%s]"), KCamRequestNames[aId] );
       
  9376 
       
  9377   SetFlags( iBusyFlags, EBusyRequest );
       
  9378   iInfo.iBusyRequestId = aId;
       
  9379   
       
  9380   TRAPD( error, iCameraController->RequestL( iInfo.iBusyRequestId ) );
       
  9381   if( error != KErrNone )
       
  9382     {
       
  9383     ClearFlags( iBusyFlags, EBusyRequest );
       
  9384     iInfo.iBusyRequestId = ECamRequestNone;
       
  9385     User::Leave( error );
       
  9386     }
       
  9387 
       
  9388   PRINT( _L("Camera <= CCamAppController::IssueRequestL") );
       
  9389   }
       
  9390 
       
  9391 // ---------------------------------------------------------------------------
       
  9392 // IssueDirectRequestL
       
  9393 // ---------------------------------------------------------------------------
       
  9394 //
       
  9395 void
       
  9396 CCamAppController
       
  9397 ::IssueDirectRequestL( const TCamCameraRequestId& aId )
       
  9398   {
       
  9399   PRINT( _L("Camera => CCamAppController::IssueDirectRequestL") );
       
  9400   iCameraController->DirectRequestL( aId );
       
  9401   PRINT( _L("Camera <= CCamAppController::IssueDirectRequestL") );
       
  9402   }
       
  9403 
       
  9404 
       
  9405 // ---------------------------------------------------------------------------
       
  9406 // IssueSettingsChangeRequestL
       
  9407 // ---------------------------------------------------------------------------
       
  9408 //
       
  9409 void
       
  9410 CCamAppController::IssueSettingsChangeRequestL()
       
  9411   {
       
  9412   PRINT( _L("Camera => CCamAppController::IssueSettingsChangeRequestL") );
       
  9413   SetFlags( iBusyFlags, EBusySetting );
       
  9414 
       
  9415   TRAPD( error, iCameraController->RequestSettingsChangeL() );
       
  9416   if( KErrNone != error )
       
  9417     {
       
  9418     ClearFlags( iBusyFlags, EBusySetting );
       
  9419     User::Leave( error );
       
  9420     }
       
  9421   PRINT( _L("Camera <= CCamAppController::IssueSettingsChangeRequestL") );
       
  9422   }
       
  9423 
       
  9424 // ---------------------------------------------------------------------------
       
  9425 // ProceedPendingOrNotifyReadyL
       
  9426 // ---------------------------------------------------------------------------
       
  9427 //
       
  9428 void 
       
  9429 CCamAppController::ProceedPendingOrNotifyReadyL()
       
  9430   {
       
  9431   PRINT( _L("Camera => CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9432   PRINT4( _L("Camera <> iMode[%s] iTargetMode[%s] iImageMode[%s] iTargetImageMode[%s]"), 
       
  9433          KCamModeNames[iInfo.iMode], 
       
  9434          KCamModeNames[iInfo.iTargetMode], 
       
  9435          KCamImageModeNames[iInfo.iImageMode], 
       
  9436          KCamImageModeNames[iInfo.iTargetImageMode] );
       
  9437 
       
  9438   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  9439 
       
  9440   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9441 
       
  9442   if( iInfo.iMode != iInfo.iTargetMode )
       
  9443     {
       
  9444     if ( !IsInShutdownMode() && !iSaving && iInfo.iOperation != ECamCapturing ) 
       
  9445         {
       
  9446         PRINT( _L("Camera <> CCamAppController: not in target mode, need to issue requests") );
       
  9447         IssueModeChangeSequenceL();
       
  9448         }
       
  9449     }
       
  9450   else if( iCameraController->ViewfinderState() != iInfo.iTargetVfState &&
       
  9451            IsAppUiAvailable () &&
       
  9452            !appUi->AppInBackground( ETrue ) &&
       
  9453            !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() &&
       
  9454              iPendingRelease ) )
       
  9455     {
       
  9456     PRINT( _L("Camera <> CCamAppController: need to start/stop viewfinder..") );
       
  9457     IssueModeChangeSequenceL();
       
  9458     }
       
  9459   else if( iSettingProvider 
       
  9460         && iSettingProvider->PendingSettingChangeCount() > 0 )
       
  9461     {
       
  9462     PRINT( _L("Camera <> CCamAppController: settings pending, proceed now..") );
       
  9463     IssueSettingsChangeRequestL();
       
  9464     }
       
  9465   else if( iVideoPrepareNeeded )
       
  9466     {
       
  9467     PRINT( _L("Camera <> CCamAppController: video prepare pending, proceed now..") );
       
  9468     iVideoPrepareNeeded = EFalse;
       
  9469     IssueRequestL( ECamRequestVideoInit );
       
  9470     }
       
  9471   else
       
  9472     {
       
  9473     PRINT( _L("Camera <> CCamAppController: Target mode achieved") );
       
  9474     if( iCaptureModeTransitionInProgress )
       
  9475       {
       
  9476       PRINT( _L("Camera <> CCamAppController: capture mode transition complete") );
       
  9477       iCaptureModeTransitionInProgress = EFalse;
       
  9478       SetImageMode( iInfo.iTargetImageMode );
       
  9479       }
       
  9480 
       
  9481     if ( iSetNewPathnamesPending > ECamMediaStorageNone )
       
  9482       {
       
  9483       TRAP_IGNORE( SetPathnamesToNewStorageL( iSetNewPathnamesPending ) );
       
  9484       }
       
  9485 
       
  9486     if( iVideoRequested )
       
  9487       {
       
  9488       PRINT( _L("Camera <> starting recording..") );
       
  9489       iVideoRequested = EFalse;
       
  9490       IssueRequestL( ECamRequestVideoStart );
       
  9491       PRINT( _L("Camera <> ..done") );
       
  9492       }
       
  9493 
       
  9494 
       
  9495     NotifyControllerObservers( ECamEventEngineStateChanged, KErrNone ); 
       
  9496     NotifyControllerObservers( ECamEventControllerReady,    KErrNone ); 
       
  9497     }
       
  9498   PRINT( _L("Camera <= CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9499   }
       
  9500 
       
  9501 // ---------------------------------------------------------------------------
       
  9502 // SetStateFromEvent
       
  9503 // ---------------------------------------------------------------------------
       
  9504 //
       
  9505 void
       
  9506 CCamAppController::SetStateFromEvent( TCamCameraEventId aEventId )
       
  9507   {   
       
  9508   PRINT3( _L("Camera => CCamAppController::SetStateFromEvent mode[%s] operation[%s] event[%s]"), 
       
  9509           KCamModeNames[iInfo.iMode], 
       
  9510           KCamCaptureOperationNames[iInfo.iOperation],
       
  9511           KCamCameraEventNames[aEventId]
       
  9512         );
       
  9513   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  9514   switch( aEventId )
       
  9515     {
       
  9516     // =================================
       
  9517     case ECamCameraEventReserveLose:
       
  9518       // SetMode( ECamControllerShutdown );
       
  9519       SetMode( ECamControllerIdle );
       
  9520       SetOperation( ECamNoOperation );
       
  9521       break;
       
  9522     // ---------------------------------
       
  9523     case ECamCameraEventPowerOn:
       
  9524       PRINT( _L("Camera <> Init key sound system..") );
       
  9525       iSoundPlayer->InitKeySoundSystem();
       
  9526       PRINT( _L("Camera <> ..Init key sound system done") );      
       
  9527       break;
       
  9528     // ---------------------------------
       
  9529     case ECamCameraEventPowerOff:
       
  9530       // Reset the flash error status
       
  9531       if( iFlashStatus ) iFlashStatus->SetFlashError( EFalse );
       
  9532       SetMode( ECamControllerIdle );
       
  9533       SetOperation( ECamNoOperation );
       
  9534       break;
       
  9535     // =================================
       
  9536     // VF events
       
  9537     case ECamCameraEventVfStart:
       
  9538       if(  iBacklightTimer 
       
  9539        && !iBacklightTimer->IsActive() )
       
  9540         {
       
  9541         //iBacklightTimer->Start( KBacklighTimerInterval,
       
  9542         //                        KBacklighTimerInterval, 
       
  9543         //                        TCallBack( ResetInactivityTimer, this ) );        
       
  9544         iBacklightTimer->Start( 0,
       
  9545                                 KBacklighTimerInterval, 
       
  9546                                 TCallBack( ResetInactivityTimer, this ) );
       
  9547         }
       
  9548 		iAFCancelInProgress = EFalse;
       
  9549       break;
       
  9550     // ---------------------------------
       
  9551     case ECamCameraEventVfStop:
       
  9552       if( iBacklightTimer )
       
  9553         {
       
  9554         iBacklightTimer->Cancel();
       
  9555         }
       
  9556       break;
       
  9557     // =================================
       
  9558     case ECamCameraEventImageInit:
       
  9559       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageInit") );      
       
  9560       SetMode( ECamControllerImage );
       
  9561 
       
  9562       // Set the capture count now, so we don't need to set it when starting capture.
       
  9563       TRAP_IGNORE( InitCaptureLimitL() );
       
  9564       SetOperation( ECamNoOperation );
       
  9565       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  9566 
       
  9567       break;
       
  9568     // ---------------------------------
       
  9569     case ECamCameraEventImageStart: // Capture started, not finished.
       
  9570       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStart") );      
       
  9571       SetOperation( ECamCapturing );
       
  9572 
       
  9573       // Make sure our cached value for image filename number is up to date.      
       
  9574       iImageNumberCache = IntegerSettingValue( ECamSettingItemPhotoNumber );
       
  9575       break;
       
  9576     // ---------------------------------
       
  9577     case ECamCameraEventImageStop: // Capture finished, unless in burst    
       
  9578       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStop") );      
       
  9579       // Store image counter now.
       
  9580       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemPhotoNumber, iImageNumberCache ) );
       
  9581 
       
  9582       if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  9583         {
       
  9584         
       
  9585         //If canceled autofocusing previously then have to set
       
  9586         //autofocus range to get autofocusing work again.
       
  9587 
       
  9588         if(iAFCancelInProgress )
       
  9589         {
       
  9590            iAFCancelInProgress = EFalse; 
       
  9591            TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );                                                                  
       
  9592 
       
  9593         }
       
  9594 
       
  9595         
       
  9596 // No operation change here.
       
  9597 // Set to Completing in SS event, and ECamNoOperation when image saved.
       
  9598 //        SetOperation( ECamNoOperation );
       
  9599         }
       
  9600       break;
       
  9601     // ---------------------------------
       
  9602     case ECamCameraEventImageRelease:
       
  9603       SetMode( ECamControllerIdle );
       
  9604       SetOperation( ECamNoOperation );
       
  9605       break;
       
  9606     // =================================
       
  9607     case ECamCameraEventVideoInit:
       
  9608       SetMode( ECamControllerVideo );
       
  9609       SetOperation( ECamNoOperation );
       
  9610       break;
       
  9611     // ---------------------------------
       
  9612     case ECamCameraEventVideoStart:
       
  9613       iVideoRequested = EFalse;
       
  9614       SetOperation( ECamCapturing );
       
  9615       break;
       
  9616     // ---------------------------------
       
  9617      case ECamCameraEventVideoPause:
       
  9618        PlaySound( ECamVideoPauseSoundId, EFalse );
       
  9619        SetOperation( ECamPaused );
       
  9620        break;            
       
  9621     // ---------------------------------
       
  9622     case ECamCameraEventVideoStop:
       
  9623       SetOperation( ECamCompleting );
       
  9624       break;
       
  9625     // ---------------------------------
       
  9626     case ECamCameraEventVideoRelease:
       
  9627       SetMode( ECamControllerIdle );
       
  9628       SetOperation( ECamNoOperation );
       
  9629       break;
       
  9630     // =================================        
       
  9631     case ECamCameraEventStartAutofocus:
       
  9632 
       
  9633       if ( !CurrentSceneHasForcedFocus() &&
       
  9634            !iAFCancelInProgress )
       
  9635         {       
       
  9636         PRINT( _L("ECamCameraEventStartAutofocus -> Set operation state to ECamFocusing") );
       
  9637         iCurrentAFRequest=ECamRequestStartAutofocus;
       
  9638         SetOperation( ECamFocusing );
       
  9639         // fixed toolbar is used only with touch devices
       
  9640         if ( IsTouchScreenSupported() )
       
  9641             {
       
  9642             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  9643             if ( fixedToolbar )
       
  9644                 {
       
  9645                 fixedToolbar->SetToolbarVisibility( EFalse );
       
  9646                 } 
       
  9647             }
       
  9648         }    
       
  9649       break;       
       
  9650     // ---------------------------------
       
  9651     case ECamCameraEventAutofocusSuccessful:
       
  9652     case ECamCameraEventAutofocusFailed:
       
  9653         {
       
  9654         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_AF_LOCK 0" ); //CCORAPP_AF_LOCK_END
       
  9655         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_OVERLAY_UPD 1" );    //CCORAPP_OVERLAY_UPD_START
       
  9656         PRINT2( _L("Camera <> CCamAppController::SetStateFromEvent - iPendingAFRequest[%s] iCurrentAFRequest[%s]"), 
       
  9657                 KCamRequestNames[iPendingAFRequest], 
       
  9658                 KCamRequestNames[iCurrentAFRequest] );
       
  9659    	    
       
  9660    	    if( iAFCancelInProgress && ECamRequestCancelAutofocus == iCurrentAFRequest &&
       
  9661    	         ECamRequestCancelAutofocus == iPendingAFRequest )
       
  9662    		    {
       
  9663             // Cancelling done, camera lens is in hyperfocal position.
       
  9664             // Return AF range back to normal, so that next autofocus request
       
  9665             // will use the right range for this scene.
       
  9666             iAFCancelInProgress = EFalse;  
       
  9667             TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );	    
       
  9668    		    iPendingAFRequest=0;
       
  9669    		    iCurrentAFRequest=0;
       
  9670    		    NotifyControllerObservers( ECamEventFocusCancelled );
       
  9671    		    
       
  9672             if ( !iCaptureRequested )
       
  9673                 {
       
  9674                 SetOperation( ECamNoOperation );
       
  9675                 }
       
  9676             else
       
  9677                 {
       
  9678                 // do not notify observers if this happens after capture
       
  9679                 // has been requested as that would result in invalid ui state
       
  9680                 iInfo.iOperation = ECamNoOperation;
       
  9681                 if( IsAfNeeded() )
       
  9682                     {
       
  9683                     SetAfNeeded( EFalse );
       
  9684                     StartAutoFocus();
       
  9685                     }
       
  9686                 }
       
  9687    		    }
       
  9688    		 else if( iCurrentAFRequest==iPendingAFRequest &&
       
  9689    		        iPendingAFRequest==ECamRequestStartAutofocus
       
  9690                 && !CurrentSceneHasForcedFocus()
       
  9691              )
       
  9692              {
       
  9693 	         if( aEventId==ECamCameraEventAutofocusSuccessful )
       
  9694 	            {
       
  9695 
       
  9696                 PRINT( _L("ECamCameraEventAutofocusSuccessful -> Set operation state to ECamFocused") );
       
  9697           
       
  9698         
       
  9699                 if( iConfigManager && iConfigManager->IsAutoFocusSupported() &&
       
  9700                     !iCaptureRequested && appUi &&	appUi->SelfTimer() && 
       
  9701                     !appUi->SelfTimer()->IsActive())
       
  9702                     {
       
  9703                     PlaySound( ECamAutoFocusComplete, EFalse );
       
  9704                     }
       
  9705                 SetOperation( ECamFocused );
       
  9706 	            }    
       
  9707 	        else if(  aEventId==ECamCameraEventAutofocusFailed )
       
  9708 	    	    {
       
  9709                 PRINT( _L("ECamCameraEventAutofocusFailed -> Set operation state to ECamFocusFailed") );
       
  9710                 if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  9711                     {
       
  9712                     PlaySound( ECamAutoFocusFailed, EFalse );
       
  9713                     }
       
  9714                 SetOperation( ECamFocusFailed );
       
  9715                 }
       
  9716             iPendingAFRequest=0;
       
  9717             iCurrentAFRequest=0;	        
       
  9718             }
       
  9719         else if( iCurrentAFRequest != iPendingAFRequest && iPendingAFRequest !=0 
       
  9720                  && !CurrentSceneHasForcedFocus()
       
  9721             )
       
  9722             {
       
  9723             iCurrentAFRequest=iPendingAFRequest;
       
  9724             iPendingAFRequest=0;
       
  9725             TryAFRequest( iCurrentAFRequest ); 
       
  9726             }
       
  9727         else if( CurrentSceneHasForcedFocus() )
       
  9728             {
       
  9729             // Autofocus flags has to be reset in forced focus cases
       
  9730             iPendingAFRequest=0;
       
  9731             iCurrentAFRequest=0;
       
  9732             }
       
  9733         }
       
  9734       break;
       
  9735     // ---------------------------------      
       
  9736     case ECamCameraEventCancelAutofocus:
       
  9737         {  
       
  9738         // Set iAFCancelInProgress to true so that we don't change the 
       
  9739         // reticule for the next focus successful/focus failed event.
       
  9740         iAFCancelInProgress = ETrue;
       
  9741         iCurrentAFRequest = ECamRequestCancelAutofocus;
       
  9742         // fixed toolbar is used only with touch devices
       
  9743         if ( !iCaptureRequested && IsTouchScreenSupported() )
       
  9744             {
       
  9745             appUi->SetToolbarVisibility();  // avoid flickering in settings view
       
  9746             }
       
  9747         }
       
  9748       break;             
       
  9749     // =================================        
       
  9750     default:
       
  9751       // No change to state with other events
       
  9752       break;
       
  9753     // =================================        
       
  9754     }
       
  9755   PRINT2( _L("Camera <= CCamAppController::SetStateFromEvent mode[%s] operation[%s]"), 
       
  9756           KCamModeNames[iInfo.iMode], 
       
  9757           KCamCaptureOperationNames[iInfo.iOperation] );
       
  9758   }
       
  9759 
       
  9760 void 
       
  9761 CCamAppController::InitCaptureLimitL()
       
  9762   {
       
  9763   // Set the capture count now, so we don't need to set it when starting capture.
       
  9764   switch( iInfo.iTargetImageMode )
       
  9765     {
       
  9766     case ECamImageCaptureBurst:
       
  9767       PRINT1( _L("Camera <> CCamAppController .. burst mode as target, set capture limit to %d"), KShortBurstCount );      
       
  9768       SetCaptureLimitL( KShortBurstCount );
       
  9769       break;
       
  9770     case ECamImageCaptureTimeLapse:
       
  9771       PRINT1( _L("Camera <> CCamAppController .. timelapse mode as target, set capture limit locally to max %d"), iLongSequenceLimit );      
       
  9772       SetCaptureLimitL( iLongSequenceLimit );
       
  9773       break;
       
  9774     default:
       
  9775       PRINT( _L("Camera <> CCamAppController .. single mode as target, set capture limit locally to 1") );      
       
  9776       SetCaptureLimitL( 1 );
       
  9777       break;
       
  9778     }
       
  9779   }
       
  9780 
       
  9781 
       
  9782 // ===========================================================================
       
  9783 // 
       
  9784 TCamAppControllerInfo::TCamAppControllerInfo()
       
  9785   :  iActiveCamera         ( ECamActiveCameraNone ),
       
  9786      iMode                 ( ECamControllerIdle   ),
       
  9787      iTargetMode           ( ECamControllerIdle   ),
       
  9788      iImageMode            ( ECamImageCaptureNone ),
       
  9789      iTargetImageMode      ( ECamImageCaptureNone ),     
       
  9790      iOperation            ( ECamNoOperation      ),
       
  9791      iTargetVfState        ( ECamTriIdle          ),
       
  9792      iViewfinderMirror     ( EFalse               ),
       
  9793      iTargetImageResolution( 0                    ),
       
  9794      iTargetImageQuality   ( 0                    ),
       
  9795      iBusyRequestId        ( ECamRequestNone      )
       
  9796   {
       
  9797   }
       
  9798 
       
  9799  
       
  9800 // ===========================================================================
       
  9801 
       
  9802 
       
  9803 //
       
  9804 //
       
  9805 //
       
  9806 void CCamAppController::HandleFileHarvestingComplete()
       
  9807     {
       
  9808     PRINT( _L("Camera => CCamAppController::HandleFileHarvestingComplete" ) );
       
  9809     // If release required but not done in postcapture not shown mode this is the
       
  9810 	// last time to do it. Otherwise problems occurs in 2ndary camera if opened
       
  9811     if ( iPendingRelease && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) )
       
  9812        {
       
  9813        PRINT( _L("Camera <> CCamAppController::HandleFileHarvestingComplete, releasing" ) );	
       
  9814        ReleaseCamera();	
       
  9815        }
       
  9816     PRINT( _L("Camera <= CCamAppController::HandleFileHarvestingComplete" ) );
       
  9817     }
       
  9818 
       
  9819 
       
  9820 //
       
  9821 //CCamAppController::DeRegisterHarverterClientEvents
       
  9822 //
       
  9823 void CCamAppController::DeRegisterHarverterClientEvents()
       
  9824     {
       
  9825     if ( iImageSaveActive )
       
  9826         {
       
  9827 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
  9828         iImageSaveActive->DeRegisterHarverterClientEvents();
       
  9829 #endif //defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
  9830         }
       
  9831     }
       
  9832 
       
  9833 
       
  9834 // ---------------------------------------------------------------------------
       
  9835 // CCamAppController::Configuration
       
  9836 //
       
  9837 // ---------------------------------------------------------------------------
       
  9838 //
       
  9839 CCamConfiguration* 
       
  9840 CCamAppController::Configuration() const
       
  9841     {
       
  9842     return iConfiguration;  
       
  9843     }
       
  9844 
       
  9845 
       
  9846 // ---------------------------------------------------------------------------
       
  9847 // CCamAppController::RestoreSettingsToCameraL
       
  9848 // Calls RestoreSettingIfNecessaryL for all supported camera settings.
       
  9849 // In case there were settings needing restoring, and camera controller
       
  9850 // is not busy, request camera controller to start setting changes.
       
  9851 // ---------------------------------------------------------------------------
       
  9852 // 
       
  9853 void
       
  9854 CCamAppController::RestoreSettingsToCameraL()
       
  9855     {
       
  9856     PRINT( _L("Camera => CCamAppController::RestoreSettingsToCameraL" ) );  
       
  9857     const TCamCameraMode mode = CurrentMode(); 
       
  9858     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9859     if ( IsAppUiAvailable() && appUi->CurrentViewState()==ECamViewStateUserSceneSetup )
       
  9860         {
       
  9861         //restore user scence setting
       
  9862         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneWhitebalance );
       
  9863         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneExposure );
       
  9864         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneFlash ); 
       
  9865         if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9866           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneColourFilter );        
       
  9867         if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9868           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneBrightness ); 
       
  9869         if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9870            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneContrast );   
       
  9871         if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )	
       
  9872            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneLightSensitivity );
       
  9873         if ( ECamControllerImage == mode )
       
  9874           {
       
  9875           if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
  9876             DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneImageSharpness );
       
  9877           DirectRestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
  9878           }
       
  9879         else if ( ECamControllerVideo == mode )
       
  9880           {
       
  9881           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
  9882           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoStab);
       
  9883           }
       
  9884         }
       
  9885     else if(iInfo.iActiveCamera == ECamActiveCameraPrimary)
       
  9886 	    {
       
  9887         if ( ECamControllerImage == mode )
       
  9888 	        {
       
  9889 	        // Add rest of the pending settings where needed
       
  9890 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoWhiteBalance );
       
  9891 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoExposure );
       
  9892 
       
  9893 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9894 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoColourFilter );        
       
  9895 	        
       
  9896 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9897 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoBrightness );
       
  9898 
       
  9899 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9900 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoContrast );
       
  9901 
       
  9902 	        if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
  9903 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoImageSharpness );
       
  9904 	      
       
  9905 	        if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )
       
  9906 	            {
       
  9907 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoLightSensitivity );
       
  9908 	            }
       
  9909 	        
       
  9910 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoFlash );
       
  9911 	        
       
  9912 	        RestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
  9913 	        }    
       
  9914 	    else if ( ECamControllerVideo == mode )
       
  9915 	        {
       
  9916 	        // Video settings in the toolbar
       
  9917 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoWhiteBalance );
       
  9918 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoExposure );
       
  9919 
       
  9920 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9921 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoColourFilter );
       
  9922 	        
       
  9923 	        // The following settings are not supported in video mode toolbar
       
  9924 	        // However, the values may need to be reset, in case the setting was
       
  9925 	        // changed in image mode
       
  9926 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9927 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoBrightness );
       
  9928 
       
  9929 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9930 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoContrast );
       
  9931 
       
  9932 	        if ( UiConfigManagerPtr()->IsVideoStabilizationSupported() )
       
  9933 	            {
       
  9934 	            RestoreSettingIfNecessaryL( ECamSettingItemVideoStab );      
       
  9935 	            }
       
  9936 	        RestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
  9937 	        
       
  9938 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoFlash );
       
  9939 	        
       
  9940 	        RestoreSettingIfNecessaryL( ECamSettingItemContinuousAutofocus ); 
       
  9941 	        }
       
  9942 	    }
       
  9943     else if(iInfo.iActiveCamera == ECamActiveCameraSecondary)
       
  9944         {
       
  9945         if ( ECamControllerImage == mode )
       
  9946                 {
       
  9947                 // Not needed
       
  9948                 }    
       
  9949             else if ( ECamControllerVideo == mode )
       
  9950                 {
       
  9951                 // Not needed
       
  9952                 }
       
  9953         }
       
  9954     else
       
  9955         {
       
  9956         // Do nothing
       
  9957         }
       
  9958     
       
  9959     if( iSettingProvider->PendingSettingChangeCount() > 0 &&
       
  9960         !iCameraController->ControllerInfo().iBusy )
       
  9961         {
       
  9962         PRINT( _L("Camera <> CCamAppController::RestoreSettingsToCameraL - Issue settings change request") );
       
  9963         IssueSettingsChangeRequestL( );    
       
  9964         }
       
  9965         
       
  9966     PRINT( _L("Camera <= CCamAppController::RestoreSettingsToCameraL" ) );          
       
  9967     }
       
  9968  
       
  9969 // ---------------------------------------------------------------------------
       
  9970 // CCamAppController::RestoreSettingIfNecessaryL
       
  9971 // Checks from camera controller, whether the value of the setting given
       
  9972 // as argument has same value in camera hw and settings model (UI).
       
  9973 // If value is not the same, add the setting id to settingsmodel's list
       
  9974 // of pending changes.
       
  9975 // ---------------------------------------------------------------------------
       
  9976 //     
       
  9977 void
       
  9978 CCamAppController::RestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
  9979     {    
       
  9980     // Convert UI setting ID to camera controller setting ID  
       
  9981     TCamCameraSettingId camSettingId = 
       
  9982       CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem );
       
  9983     
       
  9984     if( !iCameraController->SettingValueUpToDateL( camSettingId ) )
       
  9985         {
       
  9986         PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
  9987         iSettingProvider->AddPendingSettingChangeL( aSettingItem );  
       
  9988         }
       
  9989     else
       
  9990         {
       
  9991         if( aSettingItem == ECamSettingItemDynamicVideoFlash )
       
  9992             {
       
  9993             TCamCameraSettingId cameraId( 
       
  9994                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  9995             iCameraController->DirectSettingsChangeL( cameraId );
       
  9996             }
       
  9997         PRINT1( _L("RestoreSettingIfNecessaryL - Setting %s has up-to-date value, no need to restore"), KCamSettingItemNames[aSettingItem] );      
       
  9998         } 
       
  9999     }            
       
 10000 
       
 10001 
       
 10002 // ---------------------------------------------------------------------------
       
 10003 // CCamAppController::DirectRestoreSettingIfNecessaryL
       
 10004 // Checks if the setting needs restoring (UI setting value doesn't match
       
 10005 // the actual setting value in camera).  In that case, function 
       
 10006 // directly set settting to camera
       
 10007 // ---------------------------------------------------------------------------
       
 10008 // 
       
 10009 void
       
 10010 CCamAppController::DirectRestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
 10011     {
       
 10012 
       
 10013     TCamCameraSettingId cameraId( 
       
 10014                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
 10015     if ( !iCameraController->SettingValueUpToDateL( cameraId ) )
       
 10016       {
       
 10017       PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
 10018       iCameraController->DirectSettingsChangeL( cameraId );  
       
 10019       }
       
 10020     }
       
 10021 // -----------------------------------------------------------------------------
       
 10022 // CCamAppController::RestartTimeLapseTimerL()
       
 10023 // 
       
 10024 // -----------------------------------------------------------------------------
       
 10025 //   
       
 10026 void CCamAppController::RestartTimeLapseTimerL()
       
 10027 	{
       
 10028 	PRINT( _L("Camera => CCamAppController::RestartTimeLapseTimerL inside this function" ))  
       
 10029    	if ( iTimeLapseTimer )
       
 10030 		{
       
 10031 		iTimeLapseTimer->Cancel();		
       
 10032 		iTimeLapseTimer->SetTimeout( KSecondInMicSec );
       
 10033 		}
       
 10034     else
       
 10035         {
       
 10036         iTimeLapseTimer = CCamTimer::NewL( KSecondInMicSec, TCallBack( CCamAppController::TimeLapseTimeoutL, this ) );
       
 10037         }
       
 10038 
       
 10039     NotifyControllerObservers( ECamEventCounterUpdated );
       
 10040     PRINT( _L("Camera <> CCamAppController::RestartTimeLapseTimerL starting timelapse timer" ));
       
 10041     
       
 10042     iTimeLapseStartTime.HomeTime(); 
       
 10043     iTimeLapseTimer->StartTimer();
       
 10044 	
       
 10045 	// Following trace may be useful to see timing related handling in TimeLapse mode 
       
 10046 	// TDateTime stTime = iTimeLapseStartTime.DateTime();
       
 10047 	// PRINT3( _L("Start time: %d:%d:%d"), stTime.Minute(), stTime.Second(), stTime.MicroSecond() );
       
 10048 	
       
 10049 	PRINT( _L("Camera <= CCamAppController::RestartTimeLapseTimerL" ))  
       
 10050 	}
       
 10051  
       
 10052      
       
 10053 // ---------------------------------------------------------------------------
       
 10054 // SetSettingsRestoreNeeded
       
 10055 // ---------------------------------------------------------------------------
       
 10056 //     
       
 10057 void  
       
 10058 CCamAppController::SetSettingsRestoreNeeded()
       
 10059   {
       
 10060   iSettingsRestoreNeeded = ETrue;
       
 10061   }
       
 10062 
       
 10063 // ---------------------------------------------------------------------------
       
 10064 // IsSettingsRestoreNeeded
       
 10065 // ---------------------------------------------------------------------------
       
 10066 //     
       
 10067 TBool 
       
 10068 CCamAppController::IsSettingsRestoreNeeded() const
       
 10069   {
       
 10070   return iSettingsRestoreNeeded;
       
 10071   }    
       
 10072 
       
 10073 // ---------------------------------------------------------------------------
       
 10074 // StaticSettingsModel
       
 10075 //
       
 10076 // Gets the handle to the settings model, which is used inturn by the
       
 10077 // plugin to call the interfaces for performing needed actions.
       
 10078 // ---------------------------------------------------------------------------
       
 10079 //
       
 10080 TBool 
       
 10081 CCamAppController::IsSceneSupported( const TInt aSceneId, TBool aPhotoScene ) const
       
 10082   {
       
 10083   if ( aPhotoScene )
       
 10084       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsImageSceneSupported( aSceneId );
       
 10085   else
       
 10086       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsVideoSceneSupported( aSceneId );
       
 10087   }
       
 10088 
       
 10089 // ---------------------------------------------------------------------------
       
 10090 // StaticSettingsModel
       
 10091 //
       
 10092 // Gets the handle to the settings model, which is used inturn by the
       
 10093 // plugin to call the interfaces for performing needed actions.
       
 10094 // ---------------------------------------------------------------------------
       
 10095 //
       
 10096 MCamStaticSettings& 
       
 10097 CCamAppController::StaticSettingsModel()
       
 10098   {
       
 10099   return static_cast<CCamSettingsModel*>(iSettingsModel)->StaticSettingsModel();
       
 10100   }
       
 10101 
       
 10102 
       
 10103 // ---------------------------------------------------------------------------
       
 10104 // EngineRequestsPending
       
 10105 // ---------------------------------------------------------------------------
       
 10106 //     
       
 10107 TBool CCamAppController::EngineRequestsPending() const
       
 10108    {
       
 10109    return IsFlagOn( iBusyFlags, EBusyRequest );
       
 10110    }  
       
 10111  
       
 10112 // ---------------------------------------------------------------------------
       
 10113 // CalculateVideoTimeRemainingL
       
 10114 //
       
 10115 // ---------------------------------------------------------------------------
       
 10116 //
       
 10117 TTimeIntervalMicroSeconds
       
 10118 CCamAppController::CalculateVideoTimeRemainingL(const TCamMediaStorage aStorage)
       
 10119   {
       
 10120   RFs& fs = CEikonEnv::Static()->FsSession();
       
 10121   TInt drive = 0;
       
 10122   if(aStorage == ECamMediaStorageCurrent)
       
 10123 	{
       
 10124   const TDesC& filename = CurrentVideoFileName();
       
 10125   TParse fp;
       
 10126   User::LeaveIfError(fs.Parse(filename, fp));
       
 10127   TPtrC driveletter = fp.Drive();
       
 10128   TChar drl = driveletter[0];
       
 10129   User::LeaveIfError(fs.CharToDrive(drl, drive));  
       
 10130 	}
       
 10131   else
       
 10132 	{
       
 10133 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10134 	switch(aStorage)
       
 10135 		{
       
 10136 		case ECamMediaStoragePhone:
       
 10137 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10138 			break; 
       
 10139 		case ECamMediaStorageCard:
       
 10140 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10141 			break;
       
 10142 		case ECamMediaStorageMassStorage:
       
 10143 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10144 			break;
       
 10145 		default:
       
 10146 			break;
       
 10147 		}
       
 10148 	User::LeaveIfError(DriveInfo::GetDefaultDrive( driveInfo, drive ));
       
 10149 	}
       
 10150     
       
 10151   // Get critical level for this drive type
       
 10152   TDriveInfo driveInfo;
       
 10153   fs.Drive(driveInfo, drive);
       
 10154     
       
 10155   TInt criticalDiskVal = 0;
       
 10156   if( driveInfo.iType == EMediaRam ) //RAM drives have diff critical levels
       
 10157 	{
       
 10158 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10159 	User::LeaveIfError( 
       
 10160 		repository->Get( KRamDiskCriticalLevel, criticalDiskVal ) );
       
 10161 	CleanupStack::PopAndDestroy( repository );			
       
 10162 	}
       
 10163   else // Some other media type
       
 10164 	{
       
 10165 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10166 	User::LeaveIfError( 
       
 10167 		repository->Get( KDiskCriticalThreshold, criticalDiskVal ) );
       
 10168 	CleanupStack::PopAndDestroy( repository );			
       
 10169 	}   
       
 10170  
       
 10171   // Get the available space in volumeinfo.iFree
       
 10172   TVolumeInfo volumeinfo; 
       
 10173   User::LeaveIfError(fs.Volume(volumeinfo, drive));   
       
 10174    
       
 10175   // Get the current video quality data
       
 10176   TInt videoQuality = iSettingsModel->IntegerSettingValue( 
       
 10177   										ECamSettingItemVideoQuality );
       
 10178   CCamVideoQualityLevel& level = *( iSettingsModel->
       
 10179   									VideoQualityArray() )[videoQuality];     
       
 10180   
       
 10181   // Audio recording on/muted
       
 10182   TInt audioRec = iSettingsModel->IntegerSettingValue( 
       
 10183   									ECamSettingItemVideoAudioRec );
       
 10184   TBool audioMute = ECamSettOff == audioRec;
       
 10185   
       
 10186   // Video file size limit (MMS case)
       
 10187   TInt videoLimit = 0;
       
 10188   if( ECamVideoClipShort == level.VideoLength() )
       
 10189     {
       
 10190     // Short video, needs to fit into MMS message
       
 10191     videoLimit = CamUtility::MaxMmsSizeInBytesL();  
       
 10192     }
       
 10193   
       
 10194   TCamVideoTime videoTime( volumeinfo.iFree,            // Free space
       
 10195                            criticalDiskVal,             // Critical space
       
 10196                            //level.VideoFileType(),       // Video codec
       
 10197                            level.VideoBitRate(),        // Video bitrate
       
 10198                            //level.AudioType(),           // Audio FourCC
       
 10199                            level.AudioBitRate(),        // Audio bitrate
       
 10200                            videoLimit,                  // File size limit
       
 10201                            audioMute,                   // Mute audio?
       
 10202                            iConfiguration->CMRAvgVideoBitRateScaler() );
       
 10203                                                 
       
 10204   return videoTime.GetRemainingTimeL();    
       
 10205   }
       
 10206 
       
 10207 
       
 10208 // ---------------------------------------------------------------------------
       
 10209 // SetRemainingImageStored
       
 10210 // ---------------------------------------------------------------------------
       
 10211 //     
       
 10212 void  
       
 10213 CCamAppController::SetRemainingImageStored()
       
 10214   {
       
 10215   iValueIsStored = ETrue;
       
 10216   }
       
 10217 // ---------------------------------------------------------------------------
       
 10218 // IsRemainingImageStored
       
 10219 // ---------------------------------------------------------------------------
       
 10220 //
       
 10221 TBool 
       
 10222 CCamAppController::IsRemainingImageStored() const
       
 10223   {
       
 10224   return iValueIsStored;
       
 10225   }
       
 10226 
       
 10227 // ---------------------------------------------------------------------------
       
 10228 // IsSavingInProgress
       
 10229 // ---------------------------------------------------------------------------
       
 10230 //
       
 10231 TBool 
       
 10232 CCamAppController::IsSavingInProgress() const
       
 10233   {
       
 10234   return ( iImageSaveActive->Count() > 0 );
       
 10235   }
       
 10236 
       
 10237 // ---------------------------------------------------------------------------
       
 10238 // CapturedImages
       
 10239 // ---------------------------------------------------------------------------
       
 10240 //
       
 10241  TInt CCamAppController::CapturedImages() const
       
 10242   {
       
 10243   return iCameraController->ControllerInfo().iCaptureCount;
       
 10244   }
       
 10245         
       
 10246 // -----------------------------------------------------------------------------
       
 10247 //
       
 10248 // -----------------------------------------------------------------------------
       
 10249 //
       
 10250 void CCamAppController::SetSettingsPlugin( CCamGSInterface* aPlugin )
       
 10251 	{
       
 10252 	iPlugin = aPlugin;
       
 10253 	}
       
 10254 
       
 10255 // ---------------------------------------------------------------------------
       
 10256 // CCamAppController::SetViewfinderWindowHandle
       
 10257 // ---------------------------------------------------------------------------
       
 10258 //
       
 10259 void CCamAppController::SetViewfinderWindowHandle( RWindowBase* aWindow )
       
 10260     {
       
 10261     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10262 
       
 10263     iCameraController->SetViewfinderWindowHandle( aWindow );
       
 10264     }
       
 10265 
       
 10266 // ---------------------------------------------------------------------------
       
 10267 // CCamAppController::ViewfinderWindowDeleted
       
 10268 // ---------------------------------------------------------------------------
       
 10269 //
       
 10270 void CCamAppController::ViewfinderWindowDeleted( RWindowBase* aWindow )
       
 10271     {
       
 10272     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10273 
       
 10274     iCameraController->ViewfinderWindowDeleted( aWindow );
       
 10275     }
       
 10276 
       
 10277 
       
 10278 // ---------------------------------------------------------------------------
       
 10279 // CCamAppController::ExistMassStorage()
       
 10280 // ---------------------------------------------------------------------------
       
 10281 //
       
 10282 TBool CCamAppController::ExistMassStorage() const
       
 10283     {
       
 10284     const TUint KMassStorageBits = DriveInfo::EDriveInternal |
       
 10285                                    DriveInfo::EDriveExternallyMountable;    
       
 10286     TInt drive;
       
 10287     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive );
       
 10288     
       
 10289     if ( err != KErrNone )
       
 10290         {
       
 10291         return EFalse;
       
 10292         }
       
 10293     
       
 10294     TUint driveStatus(0);    
       
 10295     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10296                                      drive, 
       
 10297                                      driveStatus );
       
 10298 
       
 10299     TInt usbPersonality;
       
 10300     TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10301     						  KUsbWatcherSelectedPersonality,
       
 10302     						  usbPersonality);
       
 10303     
       
 10304     if ( err != KErrNone )
       
 10305         {
       
 10306         return EFalse;
       
 10307         }
       
 10308         
       
 10309     if ( (driveStatus & KMassStorageBits) == KMassStorageBits &&
       
 10310 		 !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10311     	((KErrNone == ret) && (KUsbPersonalityIdMS != usbPersonality) ) )
       
 10312         {
       
 10313         return ETrue;
       
 10314         }
       
 10315         
       
 10316     return EFalse;
       
 10317     }
       
 10318 
       
 10319 
       
 10320 // ------------------------------------------------------------------------
       
 10321 // CCamAppController::IsMemoryAvailable()
       
 10322 // ------------------------------------------------------------------------
       
 10323 //
       
 10324 TBool 
       
 10325 CCamAppController::IsMemoryAvailable(const TCamMediaStorage aStorage, TBool aIgnoreUsbPersonality ) const
       
 10326 	{
       
 10327 	TInt currentStorage = aStorage;
       
 10328 	if(aStorage == ECamMediaStorageCurrent)
       
 10329 		{
       
 10330 		TCamCameraMode mode = CurrentMode();
       
 10331 
       
 10332 		if((ECamControllerImage != mode) && (ECamControllerVideo != mode))
       
 10333             {
       
 10334             //This is needed for case where current mode is not yet set.
       
 10335             mode = TargetMode();
       
 10336             }
       
 10337 		
       
 10338 		if(ECamControllerImage == mode)
       
 10339 			{
       
 10340 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10341 								IntegerSettingValue( 
       
 10342 									ECamSettingItemPhotoMediaStorage ) );
       
 10343 			}
       
 10344 		else if(ECamControllerVideo == mode)
       
 10345 			{
       
 10346 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10347 								IntegerSettingValue( 
       
 10348 									ECamSettingItemVideoMediaStorage ) );
       
 10349 			}
       
 10350 		else
       
 10351 			{
       
 10352 			//No impl
       
 10353 			}
       
 10354 		}
       
 10355 	
       
 10356 	TInt usbPersonality;
       
 10357 	TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10358 							  KUsbWatcherSelectedPersonality,
       
 10359 							  usbPersonality);
       
 10360   if ( !aIgnoreUsbPersonality )
       
 10361     {
       
 10362     if ( ( currentStorage != ECamMediaStoragePhone ) && ( KErrNone == ret ) && 
       
 10363          ( KUsbPersonalityIdMS == usbPersonality ) )
       
 10364       {
       
 10365       return EFalse;
       
 10366       }
       
 10367     }
       
 10368 		
       
 10369 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10370 	switch(currentStorage)
       
 10371 		{
       
 10372 		case ECamMediaStoragePhone:
       
 10373 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10374 			break; 
       
 10375 		case ECamMediaStorageCard:
       
 10376 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10377 			break;
       
 10378 		case ECamMediaStorageMassStorage:
       
 10379 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10380 			break;
       
 10381 		default:
       
 10382 			break;
       
 10383 		}
       
 10384 	
       
 10385 	
       
 10386 	TInt drive;
       
 10387 	TInt err = DriveInfo::GetDefaultDrive( driveInfo, drive );
       
 10388 	if(err)
       
 10389 		{
       
 10390 		return EFalse;
       
 10391 		}
       
 10392     TUint driveStatus(0);    
       
 10393     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10394                                      drive, 
       
 10395                                      driveStatus );
       
 10396     if(err)
       
 10397     	{
       
 10398     	return EFalse;
       
 10399     	}
       
 10400     
       
 10401     return ( (driveStatus & DriveInfo::EDrivePresent) && 
       
 10402 		   !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10403 	       (driveStatus & DriveInfo::EDriveUserVisible) &&
       
 10404 	       !(driveStatus & DriveInfo::EDriveInUse) &&
       
 10405 	       !(driveStatus & DriveInfo::EDriveReadOnly) );
       
 10406 	}
       
 10407  
       
 10408 	
       
 10409 // ---------------------------------------------------------------------------
       
 10410 // CCamAppController::IsDemandKeyRelease()
       
 10411 // ---------------------------------------------------------------------------
       
 10412 //
       
 10413 TBool CCamAppController::IsDemandKeyRelease()
       
 10414     {
       
 10415     return iDemandKeyRelease;
       
 10416     }
       
 10417 
       
 10418 // ---------------------------------------------------------------------------
       
 10419 // CCamAppController::SetDemandKeyRelease()
       
 10420 // ---------------------------------------------------------------------------
       
 10421 //
       
 10422 void CCamAppController::SetDemandKeyRelease( TBool aDemand )
       
 10423     {
       
 10424     iDemandKeyRelease = aDemand;
       
 10425     }
       
 10426 
       
 10427 
       
 10428 // ---------------------------------------------------------------------------
       
 10429 // CCamAppController::IsKeyLockOn()
       
 10430 // ---------------------------------------------------------------------------
       
 10431 //
       
 10432 TBool CCamAppController::IsKeyLockOn()
       
 10433     {
       
 10434     if ( iKeyLockStatusWatcher && iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
 10435         {
       
 10436         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
 10437         TInt iKeyLockStatus = 0;
       
 10438         iKeyLockStatusWatcher->Get( iKeyLockStatus );
       
 10439         if ( iKeyLockStatus == EKeyguardLocked && appUi )
       
 10440             {
       
 10441             return ETrue;
       
 10442             }
       
 10443         else
       
 10444             {
       
 10445             return EFalse;
       
 10446             }        
       
 10447         }
       
 10448     return EFalse;
       
 10449     }
       
 10450 
       
 10451 
       
 10452 // ---------------------------------------------------------------------------
       
 10453 // CCamAppController::DriveChangeL
       
 10454 // ---------------------------------------------------------------------------
       
 10455 //
       
 10456 TInt CCamAppController::DriveChangeL( const TCamDriveChangeType aType )
       
 10457   {
       
 10458   PRINT1( _L("Camera => CCamAppController::DriveChangeL aType: %d" ), aType );
       
 10459     
       
 10460   TCamCameraMode mode = CurrentMode();
       
 10461   TCamMediaStorage currentStorage;
       
 10462 		
       
 10463   // Photos and videos are saved onto the same media, so no need to 
       
 10464   // differentiate between still/video 
       
 10465   currentStorage = static_cast<TCamMediaStorage>( 
       
 10466           IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );
       
 10467     
       
 10468   PRINT1( _L("Camera <> iPreferredStorageLocation is now %d"), 
       
 10469                                                   iPreferredStorageLocation );
       
 10470   PRINT1( _L("Camera <> Update iPreferredStorageLocation to %d"), 
       
 10471                                                             currentStorage );
       
 10472     
       
 10473   iPreferredStorageLocation = currentStorage; 
       
 10474     
       
 10475   if ( ECamMediaStoragePhone == iPreferredStorageLocation )
       
 10476     {
       
 10477     PRINT( _L("Camera <> Phone memory is the preferred storage location. Nothing to be done here. Return KErrNone.") )
       
 10478     PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );
       
 10479     return KErrNone;
       
 10480     }
       
 10481    
       
 10482   if  ( ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) || 
       
 10483           !IsMemoryAvailable( ECamMediaStorageMassStorage, EFalse ) ) ||
       
 10484         !IsMemoryAvailable( iPreferredStorageLocation, ETrue ) )
       
 10485     {  
       
 10486     PRINT( _L("Camera <> USB personality is 'Mass storage' or iPreferredStorageLocation (MMC or mass memory) is unavailable") )
       
 10487 
       
 10488     // Stop if recording a video to mass memory or MMC
       
 10489     if ( CurrentVideoOperation() == ECamCapturing ||
       
 10490          CurrentVideoOperation() == ECamPaused )
       
 10491       {
       
 10492       PRINT( _L("Camera <> Video capture in progress...") )
       
 10493         
       
 10494       if ( !IsMemoryAvailable( iInitialVideoStorageLocation ) ) 
       
 10495         {
       
 10496         PRINT( _L("Camera <> ...Stop  video recording.") )
       
 10497         iCaptureStoppedForUsb = ETrue;	
       
 10498         StopVideoRecording();
       
 10499         }
       
 10500       else
       
 10501         {
       
 10502         PRINT( _L("Camera <> ...Phone memory in use. No need to stop.") )
       
 10503         }
       
 10504                        
       
 10505       }
       
 10506     // Cancel if pending recording	
       
 10507     else if( iVideoRequested )
       
 10508       {
       
 10509       iVideoRequested = EFalse;
       
 10510       }
       
 10511     if ( SequenceCaptureInProgress() )
       
 10512       {
       
 10513       PRINT( _L("Camera <> Sequence capture in progress. -> Stop and skip postcapture.") )
       
 10514             
       
 10515       iCaptureStoppedForUsb = ETrue;
       
 10516       SoftStopBurstL( ETrue );
       
 10517       }
       
 10518     // If in the middle of init sequence or saving a file, set the dismount
       
 10519     // pending so that the AllowDismount call will be made later
       
 10520     if( IsFlagOn( iBusyFlags, EBusySequence ) || iSaving )
       
 10521       {
       
 10522       PRINT( _L("Camera <> CCamAppController::DriveChangeL sequence or saving ongoing" ) );  		
       
 10523       
       
 10524       iDismountPending = ETrue;    
       
 10525       // Mass memory may be the forced storage location. Then it's necessary 
       
 10526       // to switch to (forced) phone memory
       
 10527       ForceUsePhoneMemoryL( ETrue ); 
       
 10528       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount pending" ) );  	
       
 10529       return KErrNotReady;
       
 10530       }
       
 10531     else
       
 10532       {    	           
       
 10533       // Mass memory may be the forced storage location. Then it's necessary 
       
 10534       // to switch to (forced) phone memory
       
 10535       ForceUsePhoneMemoryL( ETrue );
       
 10536                 
       
 10537       // Make sure toolbar is visible
       
 10538       CCamAppUi* appUi = static_cast<CCamAppUi*>( 
       
 10539                                                 CEikonEnv::Static()->AppUi() );
       
 10540       CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
 10541       
       
 10542       if ( fixedToolbar && ECamNoOperation == CurrentOperation() )
       
 10543         {
       
 10544         fixedToolbar->SetToolbarVisibility( ETrue );
       
 10545         }
       
 10546         
       
 10547       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount ok" ) );  	    
       
 10548       return KErrNone;
       
 10549       }        
       
 10550     }
       
 10551   else if ( IsMemoryAvailable( iPreferredStorageLocation, ETrue ) &&
       
 10552             ( ECamMediaStorageCard == iPreferredStorageLocation ||
       
 10553               ECamMediaStorageMassStorage  == iPreferredStorageLocation ) )
       
 10554     {
       
 10555     PRINT( _L("Camera <> iPreferredStorageLocation (MMC or mass memory) is now available.") )
       
 10556  
       
 10557     // if phone memory forced, then revert back to user selected location
       
 10558     if ( iForceUseOfPhoneMemory )
       
 10559       {
       
 10560       PRINT( _L("Camera <> Phone memory is forced, switch back to user selected storage location.") )
       
 10561       ForceUsePhoneMemoryL( EFalse );
       
 10562       }
       
 10563     else
       
 10564       {
       
 10565       PRINT( _L("Camera <> !IsPhoneMemoryForced() -> No action.") )
       
 10566       }
       
 10567     }
       
 10568   
       
 10569   PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );  	
       
 10570   return KErrNone;
       
 10571   }
       
 10572 
       
 10573 // ---------------------------------------------------------------------------
       
 10574 // CCamAppController::CurrentStorage
       
 10575 // ---------------------------------------------------------------------------
       
 10576 //    
       
 10577 TCamMediaStorage CCamAppController::CurrentStorage()   
       
 10578     {
       
 10579     return iCurrentStorage;
       
 10580     }	 
       
 10581 
       
 10582 // ---------------------------------------------------------------------------
       
 10583 // CCamAppController::IsAfNeeded
       
 10584 // ---------------------------------------------------------------------------
       
 10585 // 
       
 10586 TBool CCamAppController::IsAfNeeded()
       
 10587     {
       
 10588     return iAfNeeded;
       
 10589     }
       
 10590 
       
 10591 // ---------------------------------------------------------------------------
       
 10592 // CCamAppController::SetAfNeeded
       
 10593 // ---------------------------------------------------------------------------
       
 10594 // 
       
 10595 void CCamAppController::SetAfNeeded( TBool aAfNeeded )
       
 10596     {
       
 10597     iAfNeeded = aAfNeeded;
       
 10598     }
       
 10599 	
       
 10600 // ---------------------------------------------------------------------------
       
 10601 // CCamAppController::IsCaptureStoppedForUsb
       
 10602 // ---------------------------------------------------------------------------
       
 10603 //    
       
 10604 TBool CCamAppController::IsCaptureStoppedForUsb()
       
 10605     {
       
 10606     return iCaptureStoppedForUsb;	
       
 10607     }
       
 10608 
       
 10609 // ---------------------------------------------------------------------------
       
 10610 // CCamAppController::SetCaptureStoppedForUsb
       
 10611 // ---------------------------------------------------------------------------
       
 10612 //    
       
 10613 void CCamAppController::SetCaptureStoppedForUsb( TBool aCaptureStoppedForUsb )
       
 10614     {
       
 10615     iCaptureStoppedForUsb = aCaptureStoppedForUsb;	
       
 10616     }
       
 10617     
       
 10618 // ---------------------------------------------------------------------------
       
 10619 // CCamAppController::CancelDismountMonitoring
       
 10620 // ---------------------------------------------------------------------------
       
 10621 //    
       
 10622 void CCamAppController::CancelDismountMonitoring()
       
 10623     {
       
 10624     if( iDriveChangeNotifier )
       
 10625         {
       
 10626         iDriveChangeNotifier->CancelMonitoring();		
       
 10627         }
       
 10628     }
       
 10629 
       
 10630 
       
 10631 // ---------------------------------------------------------------------------
       
 10632 // CCamAppController::StartDismountMonitoring
       
 10633 // ---------------------------------------------------------------------------
       
 10634 //    
       
 10635 void CCamAppController::StartDismountMonitoring()
       
 10636     {
       
 10637     if( iDriveChangeNotifier )
       
 10638         {
       
 10639         iDriveChangeNotifier->StartMonitoring();		
       
 10640         }
       
 10641     }
       
 10642 
       
 10643 // ---------------------------------------------------------------------------
       
 10644 // CCamAppController::DeepSleepTimeout
       
 10645 // ---------------------------------------------------------------------------
       
 10646 //
       
 10647 TInt CCamAppController::DeepSleepTimeout( TAny* aPtr )
       
 10648     {
       
 10649     static_cast<CCamAppController*>( aPtr )->DoDeepSleepTimeout();
       
 10650     return EFalse; // dummy
       
 10651     }
       
 10652 
       
 10653 // ---------------------------------------------------------------------------
       
 10654 // CCamAppController::DoDeepSleepTimeout
       
 10655 // ---------------------------------------------------------------------------
       
 10656 //
       
 10657 void CCamAppController::DoDeepSleepTimeout()
       
 10658     {
       
 10659     PRINT( _L("Camera => CCamAppController::DoDeepSleepTimeout") );
       
 10660 
       
 10661     ReleaseCamera();
       
 10662     iDeepSleepTimerExpired = ETrue;
       
 10663     iDeepSleepTimer->Cancel();
       
 10664 
       
 10665     PRINT( _L("Camera <= CCamAppController::DoDeepSleepTimeout") );
       
 10666     }
       
 10667 
       
 10668 // ---------------------------------------------------------------------------
       
 10669 // CCamAppController::DeepSleepTimerStart
       
 10670 // ---------------------------------------------------------------------------
       
 10671 //
       
 10672 void CCamAppController::DeepSleepTimerStart()
       
 10673     {
       
 10674     PRINT( _L("Camera : DeepSleepTimerStart") );
       
 10675     iDeepSleepTimerExpired = EFalse;
       
 10676     if ( iDeepSleepTimer && !iDeepSleepTimer->IsActive() )
       
 10677         {
       
 10678         iDeepSleepTimer->StartTimer();
       
 10679         }
       
 10680     }
       
 10681 
       
 10682 // ---------------------------------------------------------------------------
       
 10683 // CCamAppController::DeepSleepTimerCancel
       
 10684 // ---------------------------------------------------------------------------
       
 10685 //
       
 10686 void CCamAppController::DeepSleepTimerCancel()
       
 10687     {
       
 10688     PRINT( _L("Camera : DeepSleepTimerCancel") );
       
 10689     if ( iDeepSleepTimer )
       
 10690         {
       
 10691         iDeepSleepTimer->Cancel();
       
 10692         }
       
 10693     }
       
 10694 
       
 10695 // ---------------------------------------------------------------------------
       
 10696 // CCamAppController::AllSnapshotsReceived
       
 10697 // ---------------------------------------------------------------------------
       
 10698 //    
       
 10699 TBool CCamAppController::AllSnapshotsReceived()
       
 10700     {
       
 10701     PRINT1( _L("Camera <> AllSnapshotsReceived %d"), iAllSnapshotsReceived );	
       
 10702     return iAllSnapshotsReceived;	
       
 10703     }
       
 10704 
       
 10705 // ---------------------------------------------------------------------------
       
 10706 // CCamAppController::PendingAFRequest
       
 10707 // ---------------------------------------------------------------------------
       
 10708 // 
       
 10709 TInt CCamAppController::PendingAFRequest()
       
 10710     {
       
 10711     return iPendingAFRequest;
       
 10712     }
       
 10713 
       
 10714 
       
 10715 
       
 10716 // CCamAppController::IsTouchScreenSupported
       
 10717 // Return whether the device supports touch screen
       
 10718 // ---------------------------------------------------------------------------
       
 10719 //  
       
 10720 TBool CCamAppController::IsTouchScreenSupported()
       
 10721     {
       
 10722     return AknLayoutUtils::PenEnabled();
       
 10723     }
       
 10724 
       
 10725 // ---------------------------------------------------------------------------
       
 10726 // CCamAppController::IsTouchScreenSupported
       
 10727 // Return whether the device supports direct screen viewfinder
       
 10728 // ---------------------------------------------------------------------------
       
 10729 //  
       
 10730 TBool CCamAppController::IsDirectScreenVFSupported( TBool aPrimaryCamera )
       
 10731     {
       
 10732     // test for integration
       
 10733     return iConfigManager->IsDSAViewFinderSupported( aPrimaryCamera );
       
 10734     }
       
 10735 
       
 10736 // ---------------------------------------------------------------------------
       
 10737 // CCamAppController::UiConfigManagerPtr
       
 10738 // handle  to CameraUiConfigManager
       
 10739 // ---------------------------------------------------------------------------
       
 10740 //  
       
 10741 CCameraUiConfigManager* CCamAppController::UiConfigManagerPtr()
       
 10742     {
       
 10743 	__ASSERT_DEBUG(iConfigManager, CamPanic(ECamPanicNullPointer));
       
 10744     return iConfigManager;
       
 10745     }
       
 10746 
       
 10747 	
       
 10748 // ---------------------------------------------------------------------------
       
 10749 // CCamAppController::SetCameraOrientationModeL
       
 10750 // 
       
 10751 // ---------------------------------------------------------------------------
       
 10752 //  
       
 10753 void CCamAppController::SetCameraOrientationModeL( TInt aOrientation )
       
 10754     {
       
 10755     iCameraController->SetOrientationModeL( aOrientation );
       
 10756     }
       
 10757     
       
 10758 // ---------------------------------------------------------------------------
       
 10759 // CCamAppController::CompleteCameraConstruction
       
 10760 // 
       
 10761 // ---------------------------------------------------------------------------
       
 10762 //  
       
 10763 void CCamAppController::CompleteCameraConstructionL()
       
 10764     {
       
 10765     PRINT( _L( "Camera => CCamAppController::CompleteCameraConstructionL" ) );    	
       
 10766     iCameraController->CompleteSwitchCameraL();
       
 10767     // start reserve and poweron already here
       
 10768     IssueModeChangeSequenceL( ETrue );
       
 10769     PRINT( _L( "Camera <= CCamAppController::CompleteCameraConstructionL" ) );    	    
       
 10770     }
       
 10771 
       
 10772 // ---------------------------------------------------------------------------
       
 10773 // CCamAppController::CurrentImageIndex
       
 10774 // 
       
 10775 // ---------------------------------------------------------------------------
       
 10776 //  
       
 10777 TInt CCamAppController::CurrentImageIndex()
       
 10778     {
       
 10779     return iCurrentImageIndex;
       
 10780     }
       
 10781 // ---------------------------------------------------------------------------
       
 10782 // 
       
 10783 // ---------------------------------------------------------------------------
       
 10784 //
       
 10785 void
       
 10786 CCamAppController::GenerateStartupSequenceL( RCamRequestArray& aSequence )
       
 10787   {
       
 10788   PRINT( _L( "Camera => CCamAppController::GenerateStartupSequenceL" ) );
       
 10789 
       
 10790   //Have to empty autofocusrequest values here because modechange could override
       
 10791   //currently processed autofocus request.
       
 10792   iPendingAFRequest=0;
       
 10793   iCurrentAFRequest=0;
       
 10794   iNoBurstCancel = EFalse;
       
 10795   iKeyUP = EFalse;
       
 10796 
       
 10797   aSequence.Append( ECamRequestReserve );
       
 10798   aSequence.Append( ECamRequestPowerOn );
       
 10799 
       
 10800   // -------------------------------------------------------
       
 10801 #ifdef _DEBUG
       
 10802   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
 10803   for( TInt i = 0; i < aSequence.Count(); i++ )
       
 10804     {
       
 10805     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
 10806     }
       
 10807 #endif  
       
 10808   PRINT( _L( "Camera <= CCamAppController::GenerateStartupSequenceL" ) );
       
 10809   }    
       
 10810   
       
 10811 // ---------------------------------------------------------------------------
       
 10812 // CCamAppController::RotateSnapshotL
       
 10813 // Copy and rotate snapshot bitmap before it is used to
       
 10814 // create a thumbnail
       
 10815 // ---------------------------------------------------------------------------
       
 10816 //  
       
 10817 void CCamAppController::RotateSnapshotL()
       
 10818     {
       
 10819     PRINT( _L( "Camera => CCamAppController::RotateSnapshotL" ) );
       
 10820     // empty the array
       
 10821     if( iRotationArray->Count() > 0 )
       
 10822         {
       
 10823         iRotationArray->Reset();
       
 10824         }
       
 10825     // copy snapshot to preserve the original snapshot bitmap
       
 10826     // first get the handle for the original snapshot bitmap
       
 10827     CFbsBitmap* snapshot = new (ELeave)CFbsBitmap();
       
 10828     CleanupStack::PushL( snapshot );
       
 10829     snapshot->Duplicate( BurstCaptureArray()->Snapshot( iCurrentImageIndex )->Handle() );
       
 10830     //create a new bitmap with the same dimensions as the original snapshot
       
 10831     iRotatedSnapshot = new (ELeave)CFbsBitmap();
       
 10832     iRotatedSnapshot->Create( snapshot->SizeInPixels(), snapshot->DisplayMode() );
       
 10833     TRect tmpRect( TPoint( 0, 0 ), snapshot->SizeInPixels() );
       
 10834     TInt tmpLen = tmpRect.Width() * tmpRect.Height() * 4;
       
 10835     //copy the snapshot data
       
 10836     iRotatedSnapshot->BeginDataAccess();
       
 10837     snapshot->BeginDataAccess();
       
 10838     Mem::Copy( iRotatedSnapshot->DataAddress(), snapshot->DataAddress(), tmpLen );
       
 10839     iRotatedSnapshot->EndDataAccess();
       
 10840     snapshot->EndDataAccess();
       
 10841     // copy the filename 
       
 10842     iRotationArray->SetNextNameL( BurstCaptureArray()->FileName( iCurrentImageIndex ), BurstCaptureArray()->ImageName( iCurrentImageIndex ));
       
 10843     // rotate the copied snapshot 
       
 10844     if ( !iRotatorAo )
       
 10845         {
       
 10846         iRotatorAo = CCamSyncRotatorAo::NewL( *this );
       
 10847         }    
       
 10848     iRotatorAo->RotateL( iRotatedSnapshot, MapCamOrientation2RotationAngle( iCaptureOrientation ) );
       
 10849         
       
 10850     CleanupStack::Pop( snapshot );
       
 10851     PRINT( _L( "Camera <= CCamAppController::RotateSnapshotL" ) );    
       
 10852     } 
       
 10853     
       
 10854 // ---------------------------------------------------------------------------
       
 10855 // CCamAppController::RotationCompleteL
       
 10856 // Notification of bitmap rotation complete events
       
 10857 // ---------------------------------------------------------------------------
       
 10858 //  
       
 10859 void CCamAppController::RotationCompleteL( TInt aErr )
       
 10860     {
       
 10861     PRINT1( _L( "Camera => CCamAppController::RotationCompleteL aErr:%d" ), aErr );
       
 10862     // rotation completed, use the rotated bitmap to create a thumbnail    
       
 10863     // in case of error, don't use the snapshot, thumbnail is created from 
       
 10864     // the imagefile instead
       
 10865     if ( !aErr )
       
 10866         {
       
 10867         iRotationArray->ReplaceSnapshot( iRotatedSnapshot, 0 );
       
 10868         }
       
 10869     TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *iRotationArray ) );
       
 10870             
       
 10871     PRINT( _L( "Camera <= CCamAppController::RotationCompleteL" ) );         
       
 10872         }     
       
 10873       
       
 10874 // ---------------------------------------------------------------------------
       
 10875 // CCamAppController::StoreFaceTrackingValue
       
 10876 // Calls CamSettingModel to save user defined FT setting
       
 10877 // ---------------------------------------------------------------------------
       
 10878 //  
       
 10879 void CCamAppController::StoreFaceTrackingValue()
       
 10880    {
       
 10881    iSettingsModel->StoreFaceTrackingValue();	
       
 10882    }
       
 10883 
       
 10884 // ---------------------------------------------------------------------------
       
 10885 // CCamAppController::SetVideoInitNeeded
       
 10886 // Sets the value defining the need for CAE video init and prepare
       
 10887 // ---------------------------------------------------------------------------
       
 10888 //  
       
 10889 void CCamAppController::SetVideoInitNeeded( TBool aVideoInitNeeded )
       
 10890     {
       
 10891     iVideoInitNeeded = aVideoInitNeeded;  
       
 10892     }
       
 10893 
       
 10894 // ---------------------------------------------------------------------------
       
 10895 // CCamAppController::VideoInitNeeded
       
 10896 // Returns the value defining the need for CAE video init and prepare
       
 10897 // ---------------------------------------------------------------------------
       
 10898 //  
       
 10899 TBool CCamAppController::VideoInitNeeded()
       
 10900     {
       
 10901     return iVideoInitNeeded;  
       
 10902     }
       
 10903         
       
 10904 //  End of File