camerauis/cameraapp/generic/src/CamAppController.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007-2010 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 <centralrepository.h>
       
    36 
       
    37 #include <ctsydomainpskeys.h>
       
    38 #include <ProfileEngineSDKCRKeys.h>
       
    39 #include <sysutildomaincrkeys.h>
       
    40 #include <ScreensaverInternalPSKeys.h>
       
    41 #include <musresourceproperties.h>
       
    42 #include <cameraplatpskeys.h>
       
    43 #include <bitmaptransforms.h>
       
    44 #include <sensrvorientationsensor.h>
       
    45 #include <sensrvchannel.h>
       
    46 #include <sensrvchannelfinder.h>
       
    47 
       
    48 #include <UsbWatcherInternalPSKeys.h>
       
    49 #include <usbpersonalityids.h>
       
    50 
       
    51 
       
    52 #include <cameraapp.rsg>
       
    53 #include <vgacamsettings.rsg>
       
    54 #include "CamSettingsInternal.hrh"
       
    55 #include "CamProductSpecificSettings.hrh"
       
    56 #include "CameraappPrivateCRKeys.h"
       
    57 #include "CamAppController.h"
       
    58 #include "CamUtility.h"
       
    59 #include "CamLogger.h"
       
    60 #include "CamSettings.hrh"
       
    61 #include "CamSettingsModel.h"
       
    62 #include "CamPanic.h"
       
    63 #include "CamBurstCaptureArray.h"
       
    64 #include "CamTimer.h"
       
    65 #include "CamImageSaveActive.h"
       
    66 #include "CamAppUi.h"
       
    67 #include "CamObserverHandler.h"
       
    68 #include "CamSelfTimer.h"
       
    69 #include "camflashstatus.h"
       
    70 
       
    71 #include "CamPerformance.h"
       
    72 #include "OstTraceDefinitions.h"
       
    73 #ifdef OST_TRACE_COMPILER_IN_USE
       
    74 #include "CamAppControllerTraces.h"
       
    75 #endif
       
    76 
       
    77 #include "CamVideoQualityLevel.h"
       
    78 #include "CamCallStateAo.h"    
       
    79 #include "CamPropertyWatcher.h"
       
    80 #include <avkondomainpskeys.h>
       
    81 
       
    82 #ifndef __WINSCW__
       
    83   #include "rlocationtrail.h"
       
    84   #include "locationtrailpskeys.h"
       
    85 #endif
       
    86 //#include "camconstantsettingprovider.h"
       
    87 #include "camsettingprovider.h"
       
    88 #include "camsettingconversion.h"
       
    89 #include "camcamerarequests.h"
       
    90 #include "camcameraevents.h"
       
    91 #include "camcameracontrollertypes.h"
       
    92 #include "camcameracontroller.h"
       
    93 #include "cambuffershare.h"
       
    94 #include "cambuffersharecleanup.h"
       
    95 #include "camaudioplayercontroller.h"
       
    96 #include "camuidconstants.h"
       
    97 #include "camconfiguration.h"
       
    98 #include "CamPreCaptureViewBase.h"
       
    99 
       
   100 #include <cfclient.h>
       
   101 #include <cfcontextobject.h>
       
   102 #include <cfcontextquery.h>
       
   103 
       
   104 #include "camvideotime.h"
       
   105 #include "CamGSInterface.h"
       
   106 #include "CameraUiConfigManager.h"
       
   107 #include "camsnapshotrotator.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 
       
   597   delete iSnapShotRotator;
       
   598   PRINT( _L("Camera <= ~CCamAppController") );
       
   599   }
       
   600 
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CCamAppController::SavedCurrentImage
       
   604 // Returns whether the last requested captured image has been saved or not.
       
   605 // ---------------------------------------------------------------------------
       
   606 //
       
   607 TBool CCamAppController::SavedCurrentImage() const
       
   608   {
       
   609   PRINT( _L("Camera => CCamAppController::SavedCurrentImage") );
       
   610   TBool saved( ETrue );
       
   611 
       
   612   // If we are waiting for a save request then image has not been saved.
       
   613   if( iImageSaveRequestPending )
       
   614     {
       
   615     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: iImageSaveRequestPending") )
       
   616     saved = EFalse;
       
   617     }
       
   618   else if( CurrentFullFileName() == KNullDesC )
       
   619     {
       
   620     saved = EFalse;
       
   621     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: filename not yet reserved") ) 
       
   622     }
       
   623   else if( !iCaptureArray->AlreadySavedFile( CurrentFullFileName() ) ||
       
   624             iCaptureArray->CurrentlySavingFile( CurrentFullFileName() ) )
       
   625     {
       
   626     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: capture array not saved file or currently saving file") )
       
   627     saved = EFalse;
       
   628     }
       
   629   else if ( iInfo.iOperation == ECamCapturing || iInfo.iOperation == ECamCompleting )
       
   630     {
       
   631    	PRINT(_L("Camera CCamAppController::SavedCurrentImage returning false, capturing/completing") )
       
   632    	saved = EFalse;    
       
   633     }
       
   634   else
       
   635     {
       
   636     // empty
       
   637     }
       
   638 
       
   639   PRINT1( _L("Camera <= CCamAppController::SavedCurrentImage, return %d"), saved );
       
   640   return saved;
       
   641   }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 // CCamAppController::RenameCurrentFileL
       
   645 // Rename image/video.
       
   646 // ---------------------------------------------------------------------------
       
   647 //
       
   648 TBool 
       
   649 CCamAppController::RenameCurrentFileL( const TDesC&          aNewName, 
       
   650                                        const TCamCameraMode& /*aMode*/ )
       
   651   {
       
   652   TBool status = EFalse;
       
   653 
       
   654   // If file to rename has already been saved then remove from album,
       
   655   // rename the file and add the renamed file to the album.
       
   656   if ( BurstCaptureArray()->AlreadySavedFile( CurrentFullFileName() ) )
       
   657     {                
       
   658     // Rename the file.
       
   659     TFileName filePath = CurrentFullFileName();
       
   660     CamUtility::RenameStillImageL( filePath, aNewName, filePath );
       
   661     
       
   662     // Update capture array with new name and path.
       
   663     BurstCaptureArray()->SetNameL( filePath, aNewName, iCurrentImageIndex );
       
   664     
       
   665     status = ETrue;
       
   666     }
       
   667   // Otherwise, if the file is not currently being saved, modify the names 
       
   668   // in the capture array before it is saved.
       
   669   else if ( !BurstCaptureArray()->CurrentlySavingFile( CurrentFullFileName() ) )
       
   670     {
       
   671     // Update capture array with new name and path.
       
   672     // ...determine new path.
       
   673     TParsePtrC parse( CurrentFullFileName() );
       
   674     TFileName fullNewPath;
       
   675     fullNewPath = parse.DriveAndPath();
       
   676     fullNewPath.Append( aNewName );
       
   677     fullNewPath.Append( parse.Ext() );
       
   678 
       
   679     BurstCaptureArray()->SetNameL( fullNewPath, aNewName, iCurrentImageIndex );
       
   680 
       
   681     status = ETrue;
       
   682     }
       
   683   // Otherwise, the file is in the process of being saved, and 
       
   684   // so that renaming must wait until completed.
       
   685   else
       
   686     {
       
   687     // Leave status to EFalse
       
   688     }
       
   689     
       
   690   return status;
       
   691   }
       
   692 
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // CCamAppController::AddControllerObserverL
       
   696 // Add a controller observer.
       
   697 // ---------------------------------------------------------------------------
       
   698 //
       
   699 void CCamAppController::AddControllerObserverL( const MCamControllerObserver* aObserver )
       
   700   {
       
   701   if( aObserver &&
       
   702       KErrNotFound == iControllerObservers.Find( aObserver ) )
       
   703     {
       
   704     User::LeaveIfError( iControllerObservers.Append( aObserver ) );
       
   705     }
       
   706   }
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // CCamAppController::RemoveControllerObserver
       
   710 // Remove a controller observer.
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 void CCamAppController::RemoveControllerObserver( const MCamControllerObserver* aObserver )
       
   714   {
       
   715   // Errors ignored
       
   716   if( aObserver )
       
   717     {
       
   718     TInt index = iControllerObservers.Find( aObserver );
       
   719     if( KErrNotFound != index )
       
   720       {
       
   721       iControllerObservers.Remove( index );
       
   722       }
       
   723     }
       
   724   }
       
   725 
       
   726 // ---------------------------------------------------------------------------
       
   727 // AddCameraObserverL
       
   728 // ---------------------------------------------------------------------------
       
   729 //
       
   730 void 
       
   731 CCamAppController
       
   732 ::AddCameraObserverL( const MCamCameraObserver* aObserver, 
       
   733                       const TUint&              aEventInterest )
       
   734   {
       
   735   PRINT1( _L("Camera => CCamAppController::AddCameraObserverL aObserver=%d"), aObserver );
       
   736 
       
   737   // First check that observer is not in array already
       
   738   if( KErrNotFound == iPendingObserversArray.Find( aObserver ) )
       
   739       {  
       
   740       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL add Observer") );
       
   741 
       
   742       iPendingObserversArray.AppendL( aObserver );
       
   743       iCameraEventInterested.AppendL( aEventInterest );
       
   744       }
       
   745 
       
   746   if( iCameraController )
       
   747       {
       
   748       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL camera controller available") );
       
   749       while ( iPendingObserversArray.Count() > 0 &&
       
   750               iCameraEventInterested.Count() > 0 )
       
   751           {
       
   752           const MCamCameraObserver* camEventObserver = iPendingObserversArray[0];
       
   753           TUint eventInterest = iCameraEventInterested[0];
       
   754           iCameraController->AttachObserverL( camEventObserver, eventInterest );
       
   755           iPendingObserversArray.Remove( 0 );
       
   756           iCameraEventInterested.Remove( 0 );
       
   757           } 
       
   758       }
       
   759   PRINT(_L("Camera <= CCamAppController::AddCameraObserverL") );
       
   760   }
       
   761 
       
   762 // ---------------------------------------------------------------------------
       
   763 // RemoveCameraObserver
       
   764 // ---------------------------------------------------------------------------
       
   765 //
       
   766 void 
       
   767 CCamAppController
       
   768 ::RemoveCameraObserver( const MCamCameraObserver* aObserver )
       
   769   {
       
   770   if( iCameraController )
       
   771     iCameraController->DetachObserver( aObserver );
       
   772   }
       
   773 
       
   774 // ---------------------------------------------------------------------------
       
   775 // AddSettingsObserverL
       
   776 // ---------------------------------------------------------------------------
       
   777 //
       
   778 void
       
   779 CCamAppController
       
   780 ::AddSettingsObserverL( const MCamSettingsModelObserver* aObserver )
       
   781   {
       
   782   if( iSettingsModel )
       
   783     iSettingsModel->AttachObserverL( aObserver );
       
   784   else
       
   785     User::Leave( KErrNotReady );
       
   786   }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // RemoveCameraObserver
       
   790 // ---------------------------------------------------------------------------
       
   791 //
       
   792 void 
       
   793 CCamAppController
       
   794 ::RemoveSettingsObserver( const MCamSettingsModelObserver* aObserver )
       
   795   {
       
   796   if( iSettingsModel )
       
   797     iSettingsModel->DetachObserver( aObserver );
       
   798   }
       
   799 
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 void 
       
   806 CCamAppController::ConstructCameraControllerL( TInt aCameraIndex )
       
   807   {
       
   808   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 1" );
       
   809   PRINT( _L("Camera => CCamAppController::ConstructCameraControllerL") )
       
   810   PERF_EVENT_START_L2( EPerfEventCAEConstruction );
       
   811 
       
   812   if( !iCameraController )
       
   813     {
       
   814     iCameraController = CCamCameraController::NewL( *iSettingProvider, *this,
       
   815                                                     aCameraIndex ); 
       
   816     //If uiorientationoverride feature is not supported, the camera switch has
       
   817     // to be finished here                                                    
       
   818     if( !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() ) )
       
   819       {
       
   820       iCameraController->CompleteSwitchCameraL();
       
   821       }
       
   822     }
       
   823 
       
   824   // Attach as Camera Controller observer to get events
       
   825   PRINT1( _L("Camera <> Attaching as camera observer with interest:%032b"), KCamEventInterest );
       
   826   iCameraController->AttachObserverL( this, KCamEventInterest );
       
   827 
       
   828 
       
   829   PERF_EVENT_END_L2( EPerfEventCAEConstruction );
       
   830   PRINT( _L("Camera <= CCamAppController::ConstructCameraControllerL") )
       
   831   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 0" );
       
   832   }
       
   833 
       
   834 // #################################################################################################
       
   835 
       
   836 // ---------------------------------------------------------------------------
       
   837 // Returns the current camera controller state
       
   838 // (Bitfield of type TCamCameraStateFlags )
       
   839 // ---------------------------------------------------------------------------
       
   840 //
       
   841 TUint
       
   842 CCamAppController::CameraControllerState() const
       
   843   {
       
   844   TUint state( ECamIdle );
       
   845   if( iCameraController )
       
   846     {
       
   847     state = iCameraController->State();
       
   848     }
       
   849   PRINT1( _L("Camera =><= CCamAppController::CameraControllerState(): %032b"), state );
       
   850   return state;
       
   851   }
       
   852   
       
   853 // ---------------------------------------------------------------------------
       
   854 // Returns the current camera state
       
   855 // (TCamCameraState)
       
   856 // ---------------------------------------------------------------------------
       
   857 //
       
   858 TCamCameraState
       
   859 CCamAppController::CameraState() const
       
   860   {
       
   861   TCamCameraState state( ECamCameraIdle );  
       
   862   
       
   863   TUint controllerState = CameraControllerState();
       
   864  
       
   865   // Convert controller state to TCamCameraState
       
   866   // Use the state represented by the "most significant"
       
   867   // bit in the bitfield. Ignore VF state.
       
   868   if( IsFlagOn( controllerState, ECamImageOn ) )
       
   869     {
       
   870     state = ECamCameraPreparedImage;
       
   871     }
       
   872   else if( IsFlagOn( controllerState, ECamVideoOn ) )
       
   873     {
       
   874     state = ECamCameraPreparedVideo;  
       
   875     }
       
   876   else if( IsFlagOn( controllerState, ECamPowerOn ) )  
       
   877     {
       
   878     state = ECamCameraPowerOn;  
       
   879     }
       
   880   else if( IsFlagOn( controllerState, ECamReserved ) )  
       
   881     {
       
   882     state = ECamCameraReserved;  
       
   883     }
       
   884     
       
   885   PRINT1( _L("Camera =><= CCamAppController::CameraState(): %d"), state );
       
   886   return state;
       
   887   }  
       
   888 
       
   889 // ---------------------------------------------------------------------------
       
   890 //
       
   891 // ---------------------------------------------------------------------------
       
   892 //
       
   893 TCamCameraMode
       
   894 CCamAppController::CurrentMode() const
       
   895   {
       
   896   return iInfo.iMode;
       
   897   }
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 //
       
   901 // ---------------------------------------------------------------------------
       
   902 //
       
   903 TCamCameraMode
       
   904 CCamAppController::TargetMode() const
       
   905   {
       
   906   return iInfo.iTargetMode;
       
   907   }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 //
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 // CCamAppController::CurrentCaptureModeSetup()
       
   914 TCamImageCaptureMode
       
   915 CCamAppController::CurrentImageModeSetup() const
       
   916   {
       
   917   TCamImageCaptureMode captureMode = ECamImageCaptureSingle; 
       
   918   if( IsAppUiAvailable() ) 
       
   919     { 
       
   920     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
   921     if ( appUi->IsBurstEnabled() ) 
       
   922       { 
       
   923       captureMode = appUi->CurrentBurstMode(); 
       
   924       } 
       
   925     } 
       
   926   return captureMode; 
       
   927   }
       
   928 
       
   929 // ---------------------------------------------------------------------------
       
   930 //
       
   931 // ---------------------------------------------------------------------------
       
   932 //
       
   933 TCamCaptureOperation
       
   934 CCamAppController::CurrentOperation() const
       
   935   {
       
   936   return iInfo.iOperation;
       
   937   }
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 //
       
   941 // ---------------------------------------------------------------------------
       
   942 //
       
   943 TCamCaptureOperation
       
   944 CCamAppController::CurrentImageOperation() const
       
   945   {
       
   946   if( ECamControllerImage == iInfo.iMode )
       
   947     return iInfo.iOperation;
       
   948   else
       
   949     return ECamNoOperation;
       
   950   }
       
   951 
       
   952 // ---------------------------------------------------------------------------
       
   953 //
       
   954 // ---------------------------------------------------------------------------
       
   955 //
       
   956 TCamCaptureOperation  
       
   957 CCamAppController::CurrentVideoOperation() const
       
   958   {
       
   959   if( ECamControllerVideo == iInfo.iMode )
       
   960     return iInfo.iOperation;
       
   961   else
       
   962     return ECamNoOperation;
       
   963   }
       
   964 
       
   965 // ---------------------------------------------------------------------------
       
   966 //
       
   967 // ---------------------------------------------------------------------------
       
   968 //
       
   969 TCamImageCaptureMode  CCamAppController::CurrentImageMode() const
       
   970     {
       
   971     return iInfo.iImageMode;
       
   972     }
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 TCamCameraTriState CCamAppController::ViewfinderTargetState() const
       
   978   {
       
   979   return iInfo.iTargetVfState;
       
   980   }
       
   981 
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 void 
       
   988 CCamAppController::SetMode( const TCamCameraMode& aNewMode )
       
   989   {
       
   990   PRINT3( _L("Camera => CCamAppController::SetMode old[%s] new[%s] target[%s]"), 
       
   991           KCamModeNames[iInfo.iMode], 
       
   992           KCamModeNames[aNewMode],
       
   993           KCamModeNames[iInfo.iTargetMode] );
       
   994 
       
   995   if( aNewMode != iInfo.iMode )
       
   996     {
       
   997     // In shutdown mode will not accept leaving ECamControllerShutdown state.
       
   998     TBool newModeNotAccepted = ( IsInShutdownMode() 
       
   999                               && ECamControllerShutdown == iInfo.iMode 
       
  1000                               && ECamControllerShutdown != aNewMode );
       
  1001     if( !newModeNotAccepted )
       
  1002       {
       
  1003       iInfo.iMode = aNewMode;
       
  1004       NotifyControllerObservers( ECamEventEngineStateChanged );
       
  1005       }
       
  1006     else
       
  1007       {
       
  1008       PRINT( _L("Camera <> this mode change not acceptable in shutdown mode!") );
       
  1009       }      
       
  1010     }
       
  1011   PRINT( _L("Camera <= CCamAppController::SetMode") );
       
  1012   }
       
  1013 
       
  1014 // ---------------------------------------------------------------------------
       
  1015 //
       
  1016 // ---------------------------------------------------------------------------
       
  1017 //
       
  1018 void 
       
  1019 CCamAppController::SetTargetMode( const TCamCameraMode& aNewMode )
       
  1020   {
       
  1021   PRINT2( _L("Camera =><= CCamAppController::SetTargetMode [%s] -> [%s]"), 
       
  1022           KCamModeNames[iInfo.iTargetMode],
       
  1023           KCamModeNames[aNewMode         ] );
       
  1024 
       
  1025   iInfo.iTargetMode = aNewMode;
       
  1026   }
       
  1027 
       
  1028 // ---------------------------------------------------------------------------
       
  1029 //
       
  1030 // ---------------------------------------------------------------------------
       
  1031 //
       
  1032 void 
       
  1033 CCamAppController::SetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1034   {
       
  1035   PRINT2( _L("Camera =><= CCamAppController::SetImageMode [%s] -> [%s]"), 
       
  1036           KCamImageModeNames[iInfo.iImageMode],
       
  1037           KCamImageModeNames[aNewMode        ] );
       
  1038 
       
  1039   iInfo.iImageMode = aNewMode;
       
  1040   // Notify ??
       
  1041   }
       
  1042 
       
  1043 
       
  1044 // ---------------------------------------------------------------------------
       
  1045 //
       
  1046 // ---------------------------------------------------------------------------
       
  1047 //
       
  1048 void 
       
  1049 CCamAppController::SetTargetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1050   {
       
  1051   PRINT2( _L("Camera =><= CCamAppController::SetTargetImageMode [%s] -> [%s]"), 
       
  1052           KCamImageModeNames[iInfo.iTargetImageMode],
       
  1053           KCamImageModeNames[aNewMode              ] );
       
  1054 
       
  1055   iInfo.iTargetImageMode = aNewMode;
       
  1056   }
       
  1057 
       
  1058 
       
  1059 // ---------------------------------------------------------------------------
       
  1060 //
       
  1061 // ---------------------------------------------------------------------------
       
  1062 //
       
  1063 void CCamAppController::SetOperation( TCamCaptureOperation aNewOperation, 
       
  1064                                       TInt                 aError /*= KErrNone*/ )
       
  1065   {
       
  1066   PRINT2( _L("Camera => CCamAppController::SetOperation: [%s] -> [%s]"), 
       
  1067           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1068           KCamCaptureOperationNames[aNewOperation   ] );
       
  1069     PERF_OPERATION_STATE_CHANGE( aNewOperation ); 
       
  1070     
       
  1071     if( iInfo.iOperation != aNewOperation 
       
  1072      || aError           != KErrNone ) 
       
  1073       {      
       
  1074       iInfo.iOperation = aNewOperation;
       
  1075       NotifyControllerObservers( ECamEventOperationStateChanged, aError );
       
  1076       }
       
  1077 
       
  1078   PRINT( _L("Camera <= CCamAppController::SetOperation") );
       
  1079   }
       
  1080 
       
  1081 
       
  1082 
       
  1083 // ---------------------------------------------------------------------------
       
  1084 // CCamAppController::ImagesRemaining
       
  1085 // Return the number of images that can still be saved
       
  1086 // ---------------------------------------------------------------------------
       
  1087 //
       
  1088 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1089                                          TBool            aBurstActive )
       
  1090   {
       
  1091   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1092         ( iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoSize ) ); 
       
  1093 
       
  1094   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1095   }
       
  1096 
       
  1097 // ---------------------------------------------------------------------------
       
  1098 // CCamAppController::ImagesRemaining
       
  1099 // Return the number of images that can still be saved
       
  1100 // ---------------------------------------------------------------------------
       
  1101 //
       
  1102 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1103                                          TBool            aBurstActive, 
       
  1104                                          TInt             aQualityIndex )
       
  1105   {
       
  1106   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1107         ( iSettingsModel->PhotoResolution( aQualityIndex ) );
       
  1108 
       
  1109   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1110   }
       
  1111 
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // CCamAppController::ImagesRemaining
       
  1114 // Return the number of images that can still be saved
       
  1115 // ---------------------------------------------------------------------------
       
  1116 //
       
  1117 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1118                                          TBool            aBurstActive, 
       
  1119                                          TCamPhotoSizeId  aSize        )
       
  1120   {
       
  1121   PRINT( _L("Camera => CCamAppController::ImagesRemaining" ))
       
  1122   if ( ECamMediaStorageCurrent == aStorage )
       
  1123     {
       
  1124     TCamMediaStorage store_unfiltered = static_cast<TCamMediaStorage>
       
  1125         ( IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );    
       
  1126    
       
  1127     // check to see if the MMC has been removed and we are waiting on a storage switch note
       
  1128     // before we start returning the values for phone memory
       
  1129     if( ECamMediaStorageCard == store_unfiltered
       
  1130      && static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->IsMMCRemovedNotePending() 
       
  1131       )
       
  1132       {
       
  1133       PRINT( _L("Camera <= CCamAppController::ImagesRemaining mmc removed - returning 0" ))
       
  1134       return 0;// UI Behaves as if MMC is still memory in use, thus we return zero images remaining as MMC is removed
       
  1135       }                       
       
  1136 
       
  1137     // use current storage location
       
  1138     aStorage = static_cast<TCamMediaStorage>
       
  1139         ( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ); 
       
  1140     }
       
  1141   else
       
  1142     {
       
  1143     // use specified location
       
  1144     }
       
  1145         
       
  1146 
       
  1147   TInt remaining     = 0;
       
  1148   TInt criticalLevel = 0;
       
  1149 
       
  1150   PRINT( _L("Camera <> Get critical memory level.." ))
       
  1151   TRAPD( err, criticalLevel = GetCriticalMemoryLevelL( aStorage ) );
       
  1152   if( !err )
       
  1153     remaining = iConfiguration->ImagesRemaining( aStorage, aSize, criticalLevel, aBurstActive  );
       
  1154   
       
  1155   // There is a factor in cenrep that defined a correction factor in percent.
       
  1156   // This feature makes possible to define separate file size estimates in 
       
  1157   // burst capture mode.  100 = 100%, 50 = half of single capture size etc.
       
  1158   if ( aBurstActive ) 
       
  1159      {
       
  1160      TInt corrFactor = iConfigManager->BurstFileSizeEstimateFactor();
       
  1161      PRINT1( _L("Camera <> CCamAppController::ImagesRemaining, factor: %d"), corrFactor )
       
  1162      remaining = TInt( remaining * corrFactor / 100 );
       
  1163      }
       
  1164 
       
  1165   PRINT1( _L("Camera <= CCamAppController::ImagesRemaining, return:%d"), remaining )
       
  1166   return remaining;
       
  1167   }
       
  1168 
       
  1169 // ---------------------------------------------------------------------------
       
  1170 // CCamAppController::RecordTimeElapsed
       
  1171 // Return the length of video that has been recorded
       
  1172 // ---------------------------------------------------------------------------
       
  1173 //
       
  1174 TTimeIntervalMicroSeconds CCamAppController::RecordTimeElapsed() const
       
  1175     {
       
  1176     return iVideoTimeElapsed;
       
  1177     }
       
  1178 
       
  1179 // ---------------------------------------------------------------------------
       
  1180 // CCamAppController::RecordTimeElapsed
       
  1181 // Return the length of video that has been recorded
       
  1182 // ---------------------------------------------------------------------------
       
  1183 //
       
  1184 void CCamAppController::RecordTimeElapsed(TTimeIntervalMicroSeconds aElapsed )
       
  1185     {
       
  1186     iVideoTimeElapsed=aElapsed;
       
  1187     }
       
  1188 
       
  1189 // ---------------------------------------------------------------------------
       
  1190 // CCamAppController::RecordTimeRemaining
       
  1191 // Return the length of video that can still be saved
       
  1192 // ---------------------------------------------------------------------------
       
  1193 //
       
  1194 TTimeIntervalMicroSeconds 
       
  1195 CCamAppController::RecordTimeRemaining() 
       
  1196     {
       
  1197     PRINT( _L("Camera => CCamAppController::RecordTimeRemaining" ));
       
  1198     TTimeIntervalMicroSeconds remain( 0 );
       
  1199   
       
  1200     // All the time we get this information from the CaeEngine which is thru camera controller.
       
  1201 
       
  1202     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1203     if( appUi->SettingsLaunchedFromCamera() || iDismountPending )
       
  1204         {
       
  1205         // In case settings plugin is being run or mmc dismount is pending
       
  1206         // due to usb activation, we calculate the remaining time here, 
       
  1207         // instead of repreparing the engine and getting it from there  
       
  1208         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1209         if( KErrNone != err )
       
  1210             {
       
  1211             iVideoTimeRemaining = 0;
       
  1212             }
       
  1213         }
       
  1214     else
       
  1215         {    
       
  1216         if( iInfo.iOperation == ECamCapturing    ||
       
  1217             iInfo.iOperation == ECamPausing      ||
       
  1218             iInfo.iOperation == ECamPaused       ||
       
  1219             iInfo.iOperation == ECamResuming     ||
       
  1220             iInfo.iOperation == ECamCompleting )
       
  1221             {    
       
  1222             iVideoTimeRemaining = iCameraController->RemainingVideoRecordingTime();  
       
  1223             }
       
  1224         else 
       
  1225             {
       
  1226             PRINT( _L("Camera <> CCamAppController::RecordTimeRemaining - video mode not yet initialized" ));
       
  1227             TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1228             if( KErrNone != err )
       
  1229                 {
       
  1230                 iVideoTimeRemaining = 0;
       
  1231                 }
       
  1232             }
       
  1233         }
       
  1234    if ( ECamControllerVideo == CurrentMode() &&
       
  1235    	    ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) &&
       
  1236    	    appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) )
       
  1237         {
       
  1238         iVideoTimeRemaining =  0; 
       
  1239         }
       
  1240   
       
  1241     // if the storage location is MMC but the MMC is not accessible then
       
  1242     // return 0 time remaining
       
  1243     if ( appUi->IsMMCRemovedNotePending() )
       
  1244         {
       
  1245         // Return remaining time of zero, it will be reset when
       
  1246         // a card is reinserted or storage location is changed
       
  1247         PRINT( _L("Camera <> MMC note pending, return 0") );
       
  1248         }
       
  1249     else
       
  1250         {
       
  1251         // If the time we have is greater than the maximum allowed, return the
       
  1252         // maximum
       
  1253         TTimeIntervalMicroSeconds maxRecordingLength( static_cast<TInt64>(KMaxRecordingLength) );
       
  1254     
       
  1255         if ( iVideoTimeRemaining > maxRecordingLength )
       
  1256             {
       
  1257             remain = maxRecordingLength;
       
  1258             }
       
  1259         else
       
  1260             {
       
  1261             remain = iVideoTimeRemaining;
       
  1262             }
       
  1263         }
       
  1264 
       
  1265     PRINT1( _L("Camera <= CCamAppController::RecordTimeRemaining, %Ld" ), remain.Int64() );
       
  1266     return remain;
       
  1267     }
       
  1268 
       
  1269 // ---------------------------------------------------------------------------
       
  1270 // SetNoBurstCancel
       
  1271 //
       
  1272 //Set iNoBurstCancel flag which is used to prevent stopping burst
       
  1273 // when actual burst capture has started after focusing. Flag is
       
  1274 // used in CancelFocusAndCapture method.
       
  1275 // ---------------------------------------------------------------------------
       
  1276 //
       
  1277 void
       
  1278 CCamAppController::SetNoBurstCancel(TBool aValue )
       
  1279   {
       
  1280   PRINT1 ( _L("Camera =><= CCamAppController::SetNoBurstCancel, aValue=%d"),aValue );
       
  1281   	iNoBurstCancel=aValue;
       
  1282   }
       
  1283 
       
  1284 
       
  1285 // ---------------------------------------------------------------------------
       
  1286 // SoftStopBurstL
       
  1287 //
       
  1288 // Stop burst as soon as possible given the following constrains:
       
  1289 //   - if quick burst is ongoing, it's continued to the end, unless
       
  1290 //     aFastStop is true. Then the minimum of 2 images is allowed.
       
  1291 //     For "immediate" stop, StopSequenceCapture should be used.
       
  1292 //   - if press and hold burst is ongoing, stop after next image.
       
  1293 // ---------------------------------------------------------------------------
       
  1294 //
       
  1295 void
       
  1296 CCamAppController::SoftStopBurstL( TBool aFastStop /*=EFalse*/ )
       
  1297   {
       
  1298   PRINT ( _L("Camera => CCamAppController::SoftStopBurstL") );
       
  1299   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1300 
       
  1301   // Still in short burst mode, if
       
  1302   // a) no burst timer at all (long burst not supported)
       
  1303   // b) burst timer still ticking
       
  1304   // c) in self-timer initiated burst, which is always short burst.
       
  1305   TBool shortBurst = ( !iBurstTimer 
       
  1306                     ||  iBurstTimer->IsActive() 
       
  1307                     ||  appUi->SelfTimerEnabled() );
       
  1308 
       
  1309   PRINT1( _L("Camera <> CCamAppController::SoftStopBurstL .. is short burst: %d"), shortBurst );
       
  1310 
       
  1311   StopBurstTimer();
       
  1312 
       
  1313   if( iSequenceCaptureInProgress )
       
  1314     {
       
  1315     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst ongoing") );
       
  1316     if( aFastStop || !shortBurst )
       
  1317       {
       
  1318       // Camera controller takes care of setting "high enough" limit.
       
  1319       // SetCaptureLimitL takes care of setting right count to 
       
  1320       // stop as early as possible.
       
  1321       SetCaptureLimitL( 0 );
       
  1322       }
       
  1323     }
       
  1324   else if( ECamFocusing != iInfo.iOperation &&
       
  1325        !iAutoFocusRequested )
       
  1326     {
       
  1327     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst NOT ongoing, just cancel pending..") );
       
  1328     iCaptureRequested = EFalse;
       
  1329     }
       
  1330   PRINT ( _L("Camera <= CCamAppController::SoftStopBurstL") );
       
  1331   }
       
  1332 
       
  1333 // ---------------------------------------------------------------------------
       
  1334 // StartBurstTimerL
       
  1335 // ---------------------------------------------------------------------------
       
  1336 //
       
  1337 void
       
  1338 CCamAppController::StartBurstTimerL()
       
  1339   {
       
  1340   PRINT ( _L("Camera => CCamAppController::StartBurstTimerL") );
       
  1341   if( iBurstTimer )
       
  1342     {
       
  1343     StopBurstTimer();
       
  1344     }
       
  1345   else
       
  1346     {
       
  1347     TInt timeout( 0 );
       
  1348     User::LeaveIfError( CamUtility::GetPsiInt( ECamPsiLongCaptureKeyPressInterval, timeout ) );
       
  1349 
       
  1350     PRINT1( _L("Camera <> CCamAppController::StartBurstTimerL .. Creating timer with timeout value of [%d ms]"), timeout );
       
  1351 
       
  1352     // Multiply timeout by 1000 to get microseconds
       
  1353     TCallBack cb( CCamAppController::ShortBurstTimeout, this );
       
  1354     iBurstTimer = CCamTimer::NewL( timeout*1000, cb );
       
  1355     }
       
  1356 
       
  1357   PRINT ( _L("Camera <> CCamAppController::StartBurstTimerL .. Starting timer..") );
       
  1358   iBurstTimer->StartTimer();
       
  1359 
       
  1360   PRINT ( _L("Camera <= CCamAppController::StartBurstTimerL") );
       
  1361   }
       
  1362 
       
  1363 // ---------------------------------------------------------------------------
       
  1364 // StopBurstTimer
       
  1365 // ---------------------------------------------------------------------------
       
  1366 //
       
  1367 void
       
  1368 CCamAppController::StopBurstTimer()
       
  1369   {
       
  1370   PRINT( _L("Camera => CCamAppController::StopBurstTimer") );
       
  1371   if( iBurstTimer )
       
  1372     {
       
  1373     iBurstTimer->Cancel();
       
  1374     }
       
  1375   PRINT( _L("Camera <= CCamAppController::StopBurstTimer") );
       
  1376   }
       
  1377 
       
  1378 // ---------------------------------------------------------------------------
       
  1379 // ShortBurstTimeout
       
  1380 // ---------------------------------------------------------------------------
       
  1381 //
       
  1382 TInt 
       
  1383 CCamAppController::ShortBurstTimeout( TAny* aController )
       
  1384   {
       
  1385   PRINT( _L("Camera => CCamAppController::ShortBurstTimeout") );  
       
  1386 
       
  1387   CCamAppController* self = static_cast<CCamAppController*>( aController );
       
  1388   TRAP_IGNORE( self->DoShortBurstTimeoutL() );
       
  1389   
       
  1390   PRINT( _L("Camera <= CCamAppController::ShortBurstTimeout") );
       
  1391   return KErrNone; // no more callbacks
       
  1392   }
       
  1393 
       
  1394 
       
  1395 // ---------------------------------------------------------------------------
       
  1396 // DoShortBurstTimeoutL
       
  1397 // ---------------------------------------------------------------------------
       
  1398 //
       
  1399 void
       
  1400 CCamAppController::DoShortBurstTimeoutL()
       
  1401   {
       
  1402   PRINT( _L("Camera => CCamAppController::DoShortBurstTimeoutL") );
       
  1403   PRINT2( _L("Camera <> CCamAppController::DoShortBurstTimeoutL iInfo.iImageMode: %d, iSequenceCaptureInProgress: %d"), iInfo.iImageMode, iSequenceCaptureInProgress );
       
  1404   if( ECamImageCaptureBurst == iInfo.iImageMode 
       
  1405    && iSequenceCaptureInProgress )
       
  1406     {
       
  1407     TInt longBurstLimit( 0 );
       
  1408     CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, longBurstLimit );
       
  1409 
       
  1410     PRINT1( _L("Camera <> CCamAppController::DoShortBurstTimeoutL .. product long burst limit: %d"), longBurstLimit );  
       
  1411 
       
  1412     SetCaptureLimitL( longBurstLimit );
       
  1413     }
       
  1414 
       
  1415   PRINT( _L("Camera <= CCamAppController::DoShortBurstTimeoutL") );
       
  1416   }
       
  1417 
       
  1418 // ---------------------------------------------------------------------------
       
  1419 // Actual capture limit value.
       
  1420 // ---------------------------------------------------------------------------
       
  1421 //
       
  1422 TInt
       
  1423 CCamAppController::CaptureLimit() const
       
  1424   {
       
  1425   TInt limit( 1 );
       
  1426 
       
  1427   if( iCameraController && ECamImageCaptureBurst == iInfo.iImageMode )
       
  1428     {
       
  1429     limit = iCameraController->ControllerInfo().iCaptureLimit;
       
  1430     }
       
  1431 
       
  1432   return limit;
       
  1433   }
       
  1434 
       
  1435 // ---------------------------------------------------------------------------
       
  1436 // CaptureLimitSetting
       
  1437 //
       
  1438 // Stored for Setting Provider to give to Camera Controller.
       
  1439 // ---------------------------------------------------------------------------
       
  1440 //
       
  1441 TInt
       
  1442 CCamAppController::CaptureLimitSetting() const
       
  1443   {
       
  1444   TInt limit( 1 );
       
  1445 
       
  1446   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1447     {
       
  1448     limit = iRequestedCaptureCount;
       
  1449     }
       
  1450 
       
  1451   return limit;  
       
  1452   }
       
  1453 
       
  1454 // ---------------------------------------------------------------------------
       
  1455 // SetCaptureLimitL
       
  1456 // ---------------------------------------------------------------------------
       
  1457 //
       
  1458 void 
       
  1459 CCamAppController::SetCaptureLimitL( TInt aLimit )
       
  1460   {
       
  1461   PRINT1( _L("Camera => CCamAppController::SetCaptureLimitL .. requested limit: %d"), aLimit );
       
  1462 
       
  1463   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1464     {
       
  1465     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. burst mode active") );
       
  1466     // We give the total amount of images during burst, not the remaining ones.
       
  1467     // Need to subtract captures that have already been taken,
       
  1468     // before comparing to the disk limit.
       
  1469     if( iSequenceCaptureInProgress )
       
  1470       {
       
  1471       //TInt captured  = iCameraController->ControllerInfo().iCaptureCount;
       
  1472       TInt captured  = iCameraController->ControllerInfo().iSnapshotCount;
       
  1473       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. captured already: %d"), captured );
       
  1474 
       
  1475       if( aLimit > captured )
       
  1476         {
       
  1477         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. some more captures requested..") );
       
  1478 
       
  1479         // Check which is more restrictive - disk space or given limit.
       
  1480         TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1481         TInt remaining = Min( aLimit - captured, diskLimit );
       
  1482 
       
  1483         PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1484 
       
  1485         iRequestedCaptureCount = Max( KMinBurstCount, captured + remaining );
       
  1486         if ( diskLimit - KMinBurstCount < iRequestedCaptureCount ) 
       
  1487             {
       
  1488             // Estimated file size is not worst case estimate and long burst 
       
  1489             // sequence accumulates error, thus critical disk space limit may
       
  1490             // be reached. Requested capture count is decreased here if needed. 
       
  1491             iRequestedCaptureCount -= 
       
  1492                         (iRequestedCaptureCount+KMinBurstCount)/KBurstEstimate;
       
  1493             PRINT( _L("Camera <> CCamAppController::SetCaptureLimitL .. Near to critical level, adjust iRequestedCaptureCount"));
       
  1494             }
       
  1495         }
       
  1496       else
       
  1497         {
       
  1498         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. capturing should be stopped as soon as possible..") );
       
  1499         // Stop as fast as possible requested.
       
  1500         // Still need to request minimum of 2.
       
  1501         iRequestedCaptureCount = Max( KMinBurstCount, captured + 1 );
       
  1502         }
       
  1503       }
       
  1504     // Not capturing - adjust freely
       
  1505     else
       
  1506       {
       
  1507       TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1508       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1509 
       
  1510       iRequestedCaptureCount = Max( KMinBurstCount, Min( aLimit, diskLimit ) );
       
  1511       }
       
  1512 
       
  1513     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1514 
       
  1515     // In burst mode camera needs to be updated with the limit.
       
  1516     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  1517     }
       
  1518   else
       
  1519     {
       
  1520     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. single / timelapse mode active") );
       
  1521     TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, EFalse );
       
  1522     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1523 
       
  1524     iRequestedCaptureCount = Min( aLimit, diskLimit );
       
  1525 
       
  1526     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1527     }
       
  1528   PRINT ( _L("Camera <= CCamAppController::SetCaptureLimitL") );
       
  1529   }
       
  1530 // ---------------------------------------------------------------------------
       
  1531 // CCamAppController::SetTimeLapseInterval
       
  1532 // Updates the interval used in next TimeLapse capture
       
  1533 // ---------------------------------------------------------------------------
       
  1534 //
       
  1535 void CCamAppController::SetTimeLapseInterval( TTimeIntervalMicroSeconds aInterval )
       
  1536   {
       
  1537   iTimeLapseInterval = aInterval;
       
  1538   }
       
  1539 
       
  1540 // ---------------------------------------------------------------------------
       
  1541 // CCamAppController::TimeLapseInterval
       
  1542 // Returns the interval used in next TimeLapse capture
       
  1543 // ---------------------------------------------------------------------------
       
  1544 //   
       
  1545 TTimeIntervalMicroSeconds CCamAppController::TimeLapseInterval()
       
  1546   {    
       
  1547   return iTimeLapseInterval;
       
  1548   } 
       
  1549     
       
  1550 // ---------------------------------------------------------------------------
       
  1551 // CCamAppController::TimeLapseCountdown
       
  1552 // Returns the remaining time lapse interval until the next capture
       
  1553 // ---------------------------------------------------------------------------
       
  1554 // 
       
  1555 TTimeIntervalMicroSeconds CCamAppController::TimeLapseCountdown()
       
  1556   {
       
  1557   TInt64 remainingTime( 0 );    // Assume uninitialised start time
       
  1558   
       
  1559   // If the start time is uninitialised then the first capture is about to be initiated
       
  1560   if ( iTimeLapseStartTime == remainingTime )
       
  1561     {
       
  1562     return remainingTime;
       
  1563     }
       
  1564   // Otherwise, work out how much time is left before the next capture
       
  1565   TTime now;
       
  1566   now.HomeTime();
       
  1567   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  1568   remainingTime = Max ( remainingTime, iTimeLapseInterval.Int64() - elapsedTime.Int64() );   
       
  1569   return remainingTime;            
       
  1570   } 
       
  1571 
       
  1572 // ---------------------------------------------------------------------------
       
  1573 // CCamAppController::StartAutoFocus
       
  1574 // Start the autofocus procedure
       
  1575 // ---------------------------------------------------------------------------
       
  1576 //
       
  1577 void CCamAppController::StartAutoFocus()
       
  1578     {
       
  1579     PRINT (_L("Camera => CCamAppController::StartAutoFocus"));
       
  1580     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  1581     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  1582 
       
  1583     if( iConfigManager 
       
  1584      && iConfigManager->IsAutoFocusSupported()
       
  1585      && IsViewFinding() 
       
  1586      && !iAFCancelInProgress 
       
  1587      && ECamNoOperation == iInfo.iOperation )
       
  1588         {
       
  1589 
       
  1590         PRINT(_L("Camera <> Calling TryAutoFocus" ) );  
       
  1591         TryAutoFocus();        
       
  1592         }
       
  1593     PRINT(_L("Camera <= CCamAppController::StartAutoFocus"));
       
  1594     }
       
  1595 
       
  1596 // ---------------------------------------------------------------------------
       
  1597 // CCamAppController::Capture
       
  1598 // Begin the capture procedure
       
  1599 // ---------------------------------------------------------------------------
       
  1600 //
       
  1601 void CCamAppController::Capture()
       
  1602   {
       
  1603   PRINT2( _L("Camera => CCamAppController::Capture(), operation[%s], iSaving:%d"), 
       
  1604           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1605           iSaving );    
       
  1606 
       
  1607   // If the camera orientation changed during capture and not in burst mode, 
       
  1608   // set the new orientation
       
  1609   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  1610        && iOrientationChangeOccured
       
  1611        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  1612     {
       
  1613     iOrientationChangeOccured = EFalse;
       
  1614     TRAP_IGNORE( SetImageOrientationL() );
       
  1615     }
       
  1616     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && !iAccSensorListening )
       
  1617         {
       
  1618         // Delayed sensor initialization has not yet happened, but shutter key has been pressed.
       
  1619         // Force initialization now, causing an addition to shutter lag - this is a very
       
  1620         // rare case, as there should always be enough idle time to run the delayed
       
  1621         // initialization.  
       
  1622         TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  1623         }
       
  1624 
       
  1625   PERF_EVENT_END_L1( EPerfEventKeyToCapture );   
       
  1626 
       
  1627   // Set to EFalse for burst 
       
  1628   iAllSnapshotsReceived = EFalse;
       
  1629   
       
  1630   if ( ECamFocusing == iInfo.iOperation ||
       
  1631        iAFCancelInProgress ||
       
  1632        iAutoFocusRequested || IsAfNeeded() )
       
  1633     {
       
  1634     PRINT( _L("Camera <> Focusing going on, cannot start capture - setting iCaptureRequested" ) );
       
  1635     if( !IsAfNeeded() )
       
  1636         {
       
  1637         CancelAFNow();
       
  1638         }
       
  1639     iCaptureRequested = ETrue;    
       
  1640     } 
       
  1641   // -------------------------------------------------------
       
  1642   //Quick pressed capture key after backing to precapture from postcapture in burst mode
       
  1643   //Quick pressed capture key during cancelling autofocus(eg. backing to precapture from setting view ) 
       
  1644   else if ( ECamNoOperation == iInfo.iOperation
       
  1645     && ( ( ECamImageCaptureTimeLapse == iInfo.iImageMode ) 
       
  1646       || ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  1647       || ( ECamImageCaptureSingle == iInfo.iImageMode ) )      
       
  1648     && iAFCancelInProgress )
       
  1649     {
       
  1650     PRINT(_L("Camera <> Cancelling auto focus going on, cannot start capture - setting iCaptureRequested")); 
       
  1651     // delay the start of capture until cancelling autofocus has finished
       
  1652     iCaptureRequested = ETrue;
       
  1653     }    
       
  1654   // -------------------------------------------------------
       
  1655   // Quick pressed after capture, during image processing 
       
  1656   else if ( ECamCompleting         == iInfo.iOperation
       
  1657     && ECamImageCaptureSingle == iInfo.iImageMode )
       
  1658     {
       
  1659     PRINT(_L("Camera <> operation state is capture completing setting iCaptureRequested")); 
       
  1660      // delay the start of capture until current capture has finished
       
  1661     iCaptureRequested = ETrue;
       
  1662     }
       
  1663   // -------------------------------------------------------
       
  1664   // Ready for new shot
       
  1665   else if( ECamNoOperation == iInfo.iOperation 
       
  1666         || ECamFocused     == iInfo.iOperation
       
  1667         || ECamFocusFailed == iInfo.iOperation )
       
  1668     {
       
  1669     PRINT(_L("Camera <> operation state is no operation")); 
       
  1670     
       
  1671     // Update current capture mode
       
  1672 //    iInfo.iImageMode = CurrentImageModeSetup();
       
  1673 
       
  1674     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  1675         {
       
  1676         // If AF sound hasn't finished playing yet, stop it now
       
  1677         // to make sure it does not block capture sound playing.
       
  1678         iSoundPlayer->CancelPlaying( ECamAutoFocusComplete );
       
  1679         }
       
  1680     
       
  1681 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1682     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  1683       {       
       
  1684       // Do not log the single image start events in burst mode, as the end
       
  1685       // events would arrive for all images at once after all images have been taken
       
  1686       PERF_EVENT_START_L1( EPerfEventShotToSnapshot );  
       
  1687       PERF_EVENT_START_L1( EPerfEventShotToStillImageReady );  
       
  1688       PERF_EVENT_START_L1( EPerfEventShotToSave );
       
  1689       }
       
  1690     else
       
  1691       {
       
  1692       PERF_EVENT_START_L1( EPerfEventSequenceCapture ); 
       
  1693       }
       
  1694 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1695 
       
  1696     if( ECamImageCaptureTimeLapse == iInfo.iImageMode &&
       
  1697         !iSequenceCaptureInProgress )
       
  1698       {
       
  1699       // First image of timelapse, reset capture count  
       
  1700       iTimeLapseCaptureCount = 0;
       
  1701       }  
       
  1702 
       
  1703     if( iInfo.iImageMode == ECamImageCaptureNone )  
       
  1704         {
       
  1705         PRINT(_L("Camera <= CCamAppController::Capture() - request ignored")); 
       
  1706         return;
       
  1707         }
       
  1708 
       
  1709     // iCaptureRequested is reset in DoCaptureL
       
  1710     TBool capture = EFalse;
       
  1711     TInt err = KErrNone;
       
  1712     iFilenameReserved = EFalse;
       
  1713     TRAP( err, capture = DoCaptureL() );
       
  1714     if ( KErrNone != err )
       
  1715        {
       
  1716        // Sequence capture is not in progress as capture failed 
       
  1717        iSequenceCaptureInProgress = EFalse; 
       
  1718        }
       
  1719 
       
  1720     PRINT1( _L("Camera <> Tried to start capture, status:%d"), capture ); 
       
  1721     if ( capture )
       
  1722       {
       
  1723       if( ECamActiveCameraPrimary == iInfo.iActiveCamera
       
  1724           && iConfigManager && iConfigManager->IsCaptureToneDelaySupported() )
       
  1725         {
       
  1726         // first cancel to make sure
       
  1727         iCaptureToneDelayTimer->Cancel();
       
  1728         // delay playing of capture tone
       
  1729         iCaptureToneDelayTimer->StartTimer();
       
  1730         }
       
  1731       else
       
  1732         {
       
  1733         // Play capture sound
       
  1734         PlaySound( CaptureToneId(), EFalse );
       
  1735         }
       
  1736       }
       
  1737     }
       
  1738   // -------------------------------------------------------
       
  1739   // Not ready for a capture
       
  1740   else
       
  1741     {
       
  1742     // request ignored
       
  1743     }  
       
  1744   // -------------------------------------------------------
       
  1745   PRINT(_L("Camera <= CCamAppController::Capture()"));    
       
  1746   }
       
  1747 
       
  1748 
       
  1749 // ---------------------------------------------------------------------------
       
  1750 // CCamAppController::StopSequenceCaptureL
       
  1751 // Stop and complete the burst capture operation
       
  1752 // ---------------------------------------------------------------------------
       
  1753 //
       
  1754 void CCamAppController::StopSequenceCaptureL()
       
  1755   {
       
  1756   PRINT( _L("Camera => CCamAppController::StopSequenceCaptureL()") );
       
  1757 
       
  1758   iSequenceCaptureInProgress = EFalse;
       
  1759   iNoBurstCancel = EFalse;
       
  1760 
       
  1761   // Re-enable screen saver
       
  1762   EnableScreenSaver( ETrue );
       
  1763 
       
  1764   TCamImageCaptureMode captureModeSetup = CurrentImageModeSetup();
       
  1765   // Test that this method was not called in single capture mode
       
  1766   __ASSERT_DEBUG( captureModeSetup != ECamImageCaptureSingle, CamPanic( ECamPanicInvalidState ) );
       
  1767 
       
  1768   // If a burst sequence is currently active or has been requested
       
  1769   if ( iInfo.iImageMode == ECamImageCaptureBurst 
       
  1770     || ( captureModeSetup == ECamImageCaptureBurst && iCaptureRequested ) )
       
  1771     {
       
  1772     IssueDirectRequestL( ECamRequestImageCancel );
       
  1773     if ( iInfo.iOperation != ECamCapturing )
       
  1774       {
       
  1775       CompleteBurstOperation();
       
  1776       }
       
  1777     
       
  1778     }
       
  1779   // If a timelapse sequence is currently active or has been requested        
       
  1780   else if ( iInfo.iImageMode == ECamImageCaptureTimeLapse ||
       
  1781             ( captureModeSetup == ECamImageCaptureTimeLapse &&
       
  1782               iCaptureRequested ) )
       
  1783     {
       
  1784     if ( TimeLapseSupported() )
       
  1785       {
       
  1786       if ( iTimeLapseTimer )
       
  1787         {
       
  1788         iTimeLapseTimer->Cancel();
       
  1789         delete iTimeLapseTimer;
       
  1790         iTimeLapseTimer = NULL;
       
  1791         }
       
  1792 
       
  1793       // The current state is in between captures the next one has now been cancelled
       
  1794       // so just ensure that the view switch occurs           
       
  1795       // if ( iInfo.iOperation != ECamCapturing && !iCaptureRequested )
       
  1796       if ( iInfo.iOperation != ECamCapturing )
       
  1797         {
       
  1798         CompleteTimeLapseOperation();
       
  1799         } 
       
  1800       // Either the first capture is queued or a capture is still in stages of
       
  1801       // completion. Any future capture has been cancelled so all that remains is to ensure the
       
  1802       // completion code is run when the capture finally completes    
       
  1803       else
       
  1804         {
       
  1805         iCompleteTimeLapsePending = ETrue;
       
  1806         }
       
  1807       }
       
  1808     }
       
  1809   else // Otherwise there is no active or pending burst
       
  1810     {
       
  1811     // Do nothing
       
  1812     }
       
  1813 
       
  1814   PRINT( _L("Camera <= CCamAppController::StopSequenceCaptureL()") );
       
  1815   }
       
  1816 
       
  1817 
       
  1818 // ---------------------------------------------------------------------------
       
  1819 // CCamAppController::CapturePending
       
  1820 // Whether or not a capture is pending
       
  1821 // ---------------------------------------------------------------------------
       
  1822 //
       
  1823 TBool CCamAppController::CapturePending() const
       
  1824     {
       
  1825     // iOperation can be ECamFocusing but a 
       
  1826     // request to start still capture has been made and is waiting for the
       
  1827     // focus operation to complete
       
  1828     return iCaptureRequested;
       
  1829     }
       
  1830 
       
  1831 // ---------------------------------------------------------------------------
       
  1832 // CCamAppController::VideoRecordPending
       
  1833 // Whether or not video recording is pending
       
  1834 // ---------------------------------------------------------------------------
       
  1835 //
       
  1836 TBool CCamAppController::VideoRecordPending() const
       
  1837     {
       
  1838     // iOperation can be ECamFocusing but a 
       
  1839     // request to start video has been made and is waiting for the
       
  1840     // focus operation to complete
       
  1841     return iVideoRequested;
       
  1842     }
       
  1843 
       
  1844 // ---------------------------------------------------------------------------
       
  1845 // CCamAppController::SequenceCaptureInProgress
       
  1846 // Whether or not sequence capture is active
       
  1847 // ---------------------------------------------------------------------------
       
  1848 //
       
  1849 TBool CCamAppController::SequenceCaptureInProgress() const
       
  1850   {
       
  1851   return iSequenceCaptureInProgress;  
       
  1852   }
       
  1853 
       
  1854 // -----------------------------------------------------------------------------
       
  1855 // CCamAppController::StartVideoRecordingL
       
  1856 // Begin the video recording procedure
       
  1857 // -----------------------------------------------------------------------------
       
  1858 //
       
  1859 void CCamAppController::StartVideoRecordingL()
       
  1860   {
       
  1861   PRINT( _L("Camera => CCamAppController::StartVideoRecordingL") );    
       
  1862   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  1863   if( ECamControllerVideo == iInfo.iMode )
       
  1864     {
       
  1865     if( !iVideoRequested
       
  1866      &&  ECamNoOperation == iInfo.iOperation )
       
  1867       {
       
  1868       iVideoRequested = ETrue;     
       
  1869       if( !iSilentProfile || iShutterSndAlwaysOn  )
       
  1870         	{
       
  1871         	// Load (and play) the start video sound	
       
  1872         	PlaySound( ECamVideoStartSoundId , ETrue );  
       
  1873         	}   
       
  1874   
       
  1875       // initialise the array accessing values
       
  1876       iArrayUsageCount   = KVideoArrayUsers;
       
  1877       iCurrentImageIndex = 0;
       
  1878   
       
  1879       if( ECamMediaStorageCard == 
       
  1880               IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  1881         {
       
  1882         TRAPD( err, ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1883         if ( err )
       
  1884           {
       
  1885           PRINT( _L("Camera <> invalid MMC") );        
       
  1886           NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  1887   
       
  1888           // If we have got here, we can't access MMC. Switch to phone memory
       
  1889           TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  1890                                                  //this actually uses the internal mass memory
       
  1891           // Ignore for now, let fail when recording.
       
  1892           TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone, ETrue ) );
       
  1893           }
       
  1894         }
       
  1895       else
       
  1896         {
       
  1897         // Ignore for now, let fail when recording.
       
  1898         TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1899         }
       
  1900 
       
  1901         if( iSilentProfile && !iShutterSndAlwaysOn )
       
  1902         	{
       
  1903         	PlaySoundComplete();
       
  1904         	}
       
  1905       // Remember where are we recording
       
  1906       iInitialVideoStorageLocation = static_cast<TCamMediaStorage>( 
       
  1907                     IntegerSettingValue( ECamSettingItemVideoMediaStorage ) );
       
  1908       }
       
  1909     else
       
  1910       {
       
  1911       // Video already requested or other operation busy.
       
  1912       // Request ignored.
       
  1913       }
       
  1914     }
       
  1915   // Note: The code to actually START video recording has been moved
       
  1916   // to the PlaySoundComplete function so as to only start when
       
  1917   // sound playback has completed.
       
  1918   }
       
  1919 
       
  1920 // ---------------------------------------------------------------------------
       
  1921 // CCamAppController::StopVideoRecording
       
  1922 // End the video recording procedure
       
  1923 // ---------------------------------------------------------------------------
       
  1924 //
       
  1925 void 
       
  1926 CCamAppController::StopVideoRecording()
       
  1927   {
       
  1928   PRINT( _L("Camera => CCamAppController::StopVideoRecording") );
       
  1929   // if a video capture operation is pending
       
  1930   if ( iVideoRequested )
       
  1931       {
       
  1932       iVideoRequested = EFalse;
       
  1933       }
       
  1934   // otherwise, if a video recording operation is in progress or is paused
       
  1935   /*  else */
       
  1936   if ( ECamCapturing == CurrentVideoOperation() 
       
  1937          || ECamPaused    == CurrentVideoOperation() )
       
  1938     {
       
  1939     //  TRAPD( err, iAutoFocus->StopContinuousFocusL() );
       
  1940     //  iFocusLocked = EFalse;
       
  1941     // Keep track of the fact we are now in "saving" state
       
  1942     iSaving = ETrue;
       
  1943     TRAP_IGNORE( 
       
  1944       {
       
  1945       // IssueDirectRequestL( ECamRequestVfStop );
       
  1946       StopViewFinder(); 
       
  1947       IssueRequestL( ECamRequestVideoStop ); // Rest handled when event comes.
       
  1948       });
       
  1949     
       
  1950     StartIdleTimer();
       
  1951     }
       
  1952   else
       
  1953     {
       
  1954     // otherwise there is no current recording operation
       
  1955     }
       
  1956   PRINT( _L("Camera <= CCamAppController::StopVideoRecording") );
       
  1957   }
       
  1958 
       
  1959 // ---------------------------------------------------------------------------
       
  1960 // CCamAppController::StopVideoRecordingAsync
       
  1961 // End the video recording procedure asynchronously
       
  1962 // ---------------------------------------------------------------------------
       
  1963 //
       
  1964 void 
       
  1965 CCamAppController::StopVideoRecordingAsync()
       
  1966   {
       
  1967   PRINT( _L("Camera => CCamAppController::StopVideoRecordingAsync") );
       
  1968   
       
  1969   // Change CAE and MMF mode to async
       
  1970   TRAP_IGNORE( IssueRequestL( ECamRequestSetAsyncVideoStopMode ) ); 
       
  1971   StopVideoRecording();  // Call normal stop, mode is set to sync in call-backs
       
  1972 
       
  1973   PRINT( _L("Camera <= CCamAppController::StopVideoRecordingAsync") );
       
  1974   }
       
  1975 
       
  1976 // ---------------------------------------------------------------------------
       
  1977 // HandleVideoAsyncStopEvent
       
  1978 // ---------------------------------------------------------------------------
       
  1979 //
       
  1980 void
       
  1981 CCamAppController::HandleVideoAsyncStopEvent( TInt aStatus )
       
  1982   {
       
  1983   PRINT1( _L( "Camera => CCamAppController::HandleVideoAsyncStopEvent, status:%d" ), aStatus );
       
  1984   (void)aStatus; // remove compiler warning
       
  1985   
       
  1986   // We DO NOT play the stop sound when recording stopped due to
       
  1987   // an incoming call.  UI Spec 1.0, 4.4.1.
       
  1988   if ( !iInCallOrRinging 
       
  1989     && !iVideoStoppedForPhoneApp )
       
  1990     {
       
  1991     PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  1992     }
       
  1993 
       
  1994   // Recording completed, so we can re-enable key sounds
       
  1995   iSoundPlayer->EnableAllKeySounds();
       
  1996     
       
  1997   PRINT( _L( "Camera <= CCamAppController::HandleVideoAsyncStopEvent" ) );
       
  1998   }
       
  1999 
       
  2000 // ---------------------------------------------------------------------------
       
  2001 // HandleVideoStopEvent
       
  2002 // ---------------------------------------------------------------------------
       
  2003 //
       
  2004 void
       
  2005 CCamAppController::HandleVideoStopEvent( TInt aStatus )
       
  2006   {
       
  2007   PRINT1( _L( "Camera => CCamAppController::HandleVideoStopEvent, status:%d" ), aStatus );
       
  2008     
       
  2009   PERF_EVENT_END_L1( EPerfEventVideoStopToSave );        
       
  2010         
       
  2011   if ( KErrDiskFull   == aStatus 
       
  2012     || KErrCompletion == aStatus)
       
  2013     {
       
  2014     // if recording ends due to disk full condition or end of
       
  2015     // specified recording period do not propogate the error
       
  2016     aStatus = KErrNone;
       
  2017     }
       
  2018     // Play sound here if async mode is not supported
       
  2019     // If it is then next playing is copyed to HandleVideoAsyncStopEvent
       
  2020     if ( iCameraController && !iCameraController->AsyncVideoStopModeSupported() )
       
  2021         {
       
  2022         // We DO NOT play the stop sound when recording stopped due to
       
  2023         // an incoming call.  UI Spec 1.0, 4.4.1.
       
  2024         if ( !iInCallOrRinging 
       
  2025             && !iVideoStoppedForPhoneApp )
       
  2026             {
       
  2027             PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  2028             }
       
  2029 
       
  2030         // Recording completed, so we can re-enable key sounds
       
  2031         iSoundPlayer->EnableAllKeySounds();
       
  2032         }
       
  2033   // Keep track of the fact we are now leaving saving state
       
  2034   iSaving = EFalse;
       
  2035   
       
  2036   // try closing video record to free up resources
       
  2037   // Test - <eo> commented out, no such direct request supported
       
  2038   // TRAP_IGNORE( IssueDirectRequestL( ECamRequestVideoRelease ) );
       
  2039   
       
  2040   // if video post capture is off then force re-prepare so
       
  2041   // that remaining record time is updated
       
  2042   // REMOVED
       
  2043 
       
  2044   // if using direct viewfinding pause viewfinder
       
  2045   // REMOVED
       
  2046 
       
  2047   // report to LifeBlog
       
  2048   RProperty::Set( KPSUidCamcorderNotifier, KCamLatestFilePath, iSuggestedVideoPath ); 
       
  2049   // Add to album if this is enabled for videos
       
  2050   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  2051               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));       
       
  2052   if ( iSettingsModel->IntegerSettingValue
       
  2053                      ( ECamSettingItemVideoStoreInAlbum ) == ECamSettYes )
       
  2054     {
       
  2055     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, ETrue, defaultAlbumId );
       
  2056     }
       
  2057   else // Harvest the file but dont add to the default album
       
  2058     {
       
  2059     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, EFalse, defaultAlbumId );
       
  2060     }
       
  2061 
       
  2062   //create thumbnail
       
  2063   if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  2064       {
       
  2065       TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  2066       }
       
  2067   NotifyControllerObservers( ECamEventRecordComplete,   aStatus );
       
  2068   SetOperation( ECamNoOperation );
       
  2069   PRINT( _L( "Camera <> calling HandleCaptureCompletion.." ) )        
       
  2070   HandleCaptureCompletion();
       
  2071   NotifyControllerObservers( ECamEventMediaFileChanged, aStatus );
       
  2072   PRINT( _L( "Camera <= CCamAppController::HandleVideoStopEvent" ) );
       
  2073   }
       
  2074 
       
  2075     
       
  2076 // ---------------------------------------------------------------------------
       
  2077 // CCamAppController::SetVideoStoppedForPhoneApp
       
  2078 // Store the cause of the video stopping
       
  2079 // ---------------------------------------------------------------------------
       
  2080 //
       
  2081 void 
       
  2082 CCamAppController::SetVideoStoppedForPhoneApp( TBool aIsPhoneApp )
       
  2083   {
       
  2084   iVideoStoppedForPhoneApp = aIsPhoneApp;
       
  2085   }
       
  2086     
       
  2087 
       
  2088 // ---------------------------------------------------------------------------
       
  2089 // CCamAppController::PauseVideoRecording
       
  2090 // Pause the video recording procedure
       
  2091 // ---------------------------------------------------------------------------
       
  2092 //
       
  2093 void CCamAppController::PauseVideoRecording()
       
  2094     {
       
  2095     PRINT( _L("Camera => CCamAppController::PauseVideoRecording") );
       
  2096     if( ECamCapturing == CurrentVideoOperation() )
       
  2097         {
       
  2098         TRAPD( error, IssueRequestL( ECamRequestVideoPause ) );
       
  2099         if( KErrNone != error )
       
  2100             {
       
  2101             PRINT( _L("Camera <> PAUSING FAILED!!") );
       
  2102             }
       
  2103         else
       
  2104             {
       
  2105             // start video pause timeout
       
  2106             StartIdleTimer();
       
  2107             }
       
  2108         }  
       
  2109     PRINT( _L("Camera <= CCamAppController::PauseVideoRecording") );
       
  2110     }
       
  2111 
       
  2112 
       
  2113 // ---------------------------------------------------------------------------
       
  2114 // CCamAppController::ContinueVideoRecording
       
  2115 // Continue the video recording procedure
       
  2116 // ---------------------------------------------------------------------------
       
  2117 //
       
  2118 void CCamAppController::ContinueVideoRecording()
       
  2119   {
       
  2120   PRINT( _L("Camera => CCamAppController::ContinueVideoRecording") );
       
  2121   if ( ECamPaused == CurrentVideoOperation() )
       
  2122     {
       
  2123     SetOperation( ECamResuming );
       
  2124     // Restart video when sound played
       
  2125     PlaySound( ECamVideoResumeSoundId, ETrue );        
       
  2126     }
       
  2127   PRINT( _L("Camera <= CCamAppController::ContinueVideoRecording") );
       
  2128   }
       
  2129 
       
  2130 // ---------------------------------------------------------------------------
       
  2131 // CCamAppController::TryAFRequest
       
  2132 // issue AF request if there are no pending AF requests currently
       
  2133 // ---------------------------------------------------------------------------
       
  2134 //
       
  2135 TBool CCamAppController::TryAFRequest( TInt aAFRequest ) 
       
  2136   {
       
  2137   PRINT( _L( "Camera => TryAFRequest") );
       
  2138   PRINT3( _L( "iPendingAFRequest=%d aAFRequest=%d ,iCurrentAFRequest=%d"), iPendingAFRequest,
       
  2139     aAFRequest, iCurrentAFRequest );
       
  2140   switch( aAFRequest )
       
  2141     {    
       
  2142     case  ECamRequestCancelAutofocus:
       
  2143     case ECamRequestStartAutofocus:
       
  2144         {
       
  2145         if(iPendingAFRequest==0)
       
  2146             {
       
  2147             if ( !( UiConfigManagerPtr()->IsContinuosAutofocusSupported()&& ECamControllerVideo == CurrentMode() ) ) 
       
  2148                             {
       
  2149             iPendingAFRequest=aAFRequest;
       
  2150             TRAPD( err, IssueDirectRequestL( TCamCameraRequestId(aAFRequest) ) );
       
  2151             //TRAPD( err, iCameraController->DirectRequestL( aAFRequest ) );            
       
  2152             if ( err != KErrNone )
       
  2153                 {
       
  2154                 // There is an error, we leave without focusing
       
  2155                 iPendingAFRequest=0;
       
  2156                 return EFalse; // Not doing any autofocus request.
       
  2157                 //This is only case where AFrequest cause EFalse to be returned.
       
  2158                 }
       
  2159             }
       
  2160             }
       
  2161         else
       
  2162             {
       
  2163             CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2164             if ( appUi->AlwaysDrawPreCaptureCourtesyUI()
       
  2165                 && !CurrentSceneHasForcedFocus() )
       
  2166                 {
       
  2167                 appUi->SetActivePaletteVisibility( EFalse );
       
  2168                 }
       
  2169             iPendingAFRequest=aAFRequest;
       
  2170             }
       
  2171         }
       
  2172         break;
       
  2173     default:
       
  2174         {
       
  2175         //Not type of autofocus request. Ignoring.
       
  2176         }
       
  2177         break;    
       
  2178     }
       
  2179   PRINT( _L( "Camera <= TryAFRequest") );
       
  2180   return ETrue;              
       
  2181   }
       
  2182 
       
  2183 // ---------------------------------------------------------------------------
       
  2184 // CCamAppController::CancelAFNow
       
  2185 // Cancel AutoFocus 
       
  2186 // ---------------------------------------------------------------------------
       
  2187 //
       
  2188 void CCamAppController::CancelAFNow()
       
  2189   {    
       
  2190   PRINT( _L("Camera => CCamAppController::CancelAfNow()") );
       
  2191   
       
  2192   if( !iAFCancelInProgress && ECamFocusing == CurrentOperation() ) 
       
  2193     {
       
  2194     TRAPD( err, IssueDirectRequestL( ECamRequestCancelAutofocus ) );          
       
  2195     if( KErrNone == err ) 
       
  2196       {
       
  2197       iAFCancelInProgress = ETrue;  
       
  2198       iCurrentAFRequest = ECamRequestCancelAutofocus;      
       
  2199       iPendingAFRequest = ECamRequestCancelAutofocus;
       
  2200       }
       
  2201     }
       
  2202   else 
       
  2203     {
       
  2204     PRINT( _L("AF Cancel already in progress or not focusing") );
       
  2205     }   
       
  2206     
       
  2207   PRINT( _L("Camera <= CCamAppController::CancelAfNow()") );
       
  2208   }
       
  2209 // CCamAppController::CancelFocusAndCapture
       
  2210 // Cancel the focus and capture procedures
       
  2211 // ---------------------------------------------------------------------------
       
  2212 //
       
  2213 void CCamAppController::CancelFocusAndCapture()
       
  2214   {
       
  2215   PRINT( _L( "Camera => CCamAppController::CancelFocusAndCapture") );            
       
  2216   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  2217   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  2218   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2219   // Only cancels autofocus if needed, burst capture is no longer
       
  2220   // stopped if capture key pressed during burst
       
  2221   
       
  2222   if( !iNoBurstCancel 
       
  2223    && ECamNoOperation != CurrentOperation()
       
  2224    && ECamCompleting  != CurrentOperation() )
       
  2225     {  
       
  2226     // If we are currently focused, cancel autofocus
       
  2227     if ( IsViewFinding() && CurrentOperation() != ECamCapturing ) // Cannot do AF operations if VF not on. AF is anyway cancelled on VF start event.
       
  2228       {
       
  2229       if( ECamFocusing == CurrentOperation() )
       
  2230         {
       
  2231         CancelAFNow();
       
  2232         if ( IsTouchScreenSupported() )
       
  2233             {
       
  2234             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  2235             if ( fixedToolbar )
       
  2236               {
       
  2237               fixedToolbar->SetToolbarVisibility( ETrue );
       
  2238               }        
       
  2239             }
       
  2240         }   
       
  2241       else 
       
  2242         {
       
  2243         TryAFRequest( ECamRequestCancelAutofocus );
       
  2244         }
       
  2245       }
       
  2246     iCaptureRequested = EFalse;
       
  2247     }
       
  2248   PRINT( _L( "Camera <= CCamAppController::CancelFocusAndCapture") );            
       
  2249   }
       
  2250 
       
  2251 
       
  2252 // ---------------------------------------------------------------------------
       
  2253 // CCamAppController::SnapshotImage
       
  2254 // Get post-exposure snapshot bitmap, if available.
       
  2255 //
       
  2256 // Returns: pointer to post-exposure snapshot bitmap. Does not transfer ownership.
       
  2257 //          May be NULL if no image available.
       
  2258 // 
       
  2259 // ---------------------------------------------------------------------------
       
  2260 //
       
  2261 const CFbsBitmap* 
       
  2262 CCamAppController::SnapshotImage() const
       
  2263   {
       
  2264   PRINT ( _L("Camera => CCamAppController::SnapshotImage") ); 
       
  2265   PRINT1( _L("Camera <> CCamAppController::SnapshotImage .. current image index: %d"), iCurrentImageIndex ); 
       
  2266   PRINT1( _L("Camera => CCamAppController::SnapshotImage .. saved current image: %d"), SavedCurrentImage() ); 
       
  2267 
       
  2268   if ( iSnapShotRotator->IsActive() )
       
  2269     {
       
  2270     // Avoid flickering. Do not show original snapshot, if it needs to be rotated
       
  2271     PRINT( _L("Camera <= CCamAppController::SnapshotImage - return null") );
       
  2272     return NULL;
       
  2273     }
       
  2274 
       
  2275   //Sometime burst capture array includes more than one image in single capture mode, 
       
  2276   //so just display the latest image here.
       
  2277   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2278   if ( BurstCaptureArray()->Count() > 1 && !appUi->IsBurstEnabled() )
       
  2279       {
       
  2280       TInt currentImageIndex = BurstCaptureArray()->Count() - 1;
       
  2281       const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( currentImageIndex );
       
  2282       PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2283       return ss;
       
  2284       }
       
  2285 
       
  2286   const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( iCurrentImageIndex );
       
  2287   PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2288   return ss;
       
  2289   }
       
  2290 
       
  2291 
       
  2292 // ---------------------------------------------------------------------------
       
  2293 // CCamAppController::SetAsCurrentImage
       
  2294 // Sets the specified index as the "current image", as will be used by the 
       
  2295 // post capture view
       
  2296 // ---------------------------------------------------------------------------
       
  2297 //
       
  2298 void 
       
  2299 CCamAppController::SetAsCurrentImage( TInt aIndex )
       
  2300   {
       
  2301   iCurrentImageIndex = aIndex;
       
  2302   }
       
  2303 
       
  2304 // ---------------------------------------------------------------------------
       
  2305 // CCamAppController::CurrentImageName
       
  2306 // Get the user-visible name for the current image 
       
  2307 // used in post-capture views.
       
  2308 // ---------------------------------------------------------------------------
       
  2309 //
       
  2310 const TDesC& 
       
  2311 CCamAppController::CurrentImageName() const
       
  2312   {
       
  2313   return BurstCaptureArray()->ImageName( iCurrentImageIndex );
       
  2314   }
       
  2315 
       
  2316 // ---------------------------------------------------------------------------
       
  2317 // CCamAppController::BurstCaptureArray
       
  2318 // Return a pointer to the array representing a burst capture
       
  2319 // ---------------------------------------------------------------------------
       
  2320 //
       
  2321 CCamBurstCaptureArray* 
       
  2322 CCamAppController::BurstCaptureArray() const
       
  2323   {
       
  2324   return iCaptureArray;
       
  2325   }        
       
  2326 
       
  2327 // ---------------------------------------------------------------------------
       
  2328 // CCamAppController::CurrentItemCount
       
  2329 // Return the count of non-deleted items in the burst array
       
  2330 // ---------------------------------------------------------------------------
       
  2331 //
       
  2332 TInt 
       
  2333 CCamAppController::CurrentItemCount()
       
  2334   {
       
  2335   if ( !BurstCaptureArray() )
       
  2336     {
       
  2337     return 0;
       
  2338     }
       
  2339   return BurstCaptureArray()->ImagesRemaining();
       
  2340   }
       
  2341 
       
  2342 // ---------------------------------------------------------------------------
       
  2343 // CCamAppController::CurrentCapturedCount
       
  2344 // Return the count of burst capture moments that have taken
       
  2345 // place in a current burst
       
  2346 // ---------------------------------------------------------------------------
       
  2347 //    
       
  2348 TInt 
       
  2349 CCamAppController::CurrentCapturedCount()
       
  2350   {
       
  2351   //return iActualBurstCount;
       
  2352   TInt count( 0 );
       
  2353   if( iCameraController )
       
  2354     {
       
  2355     // Using snapshot as count, because UI updates counter
       
  2356     // on snapshot events.
       
  2357     count = iCameraController->ControllerInfo().iSnapshotCount;
       
  2358     }
       
  2359   return count;  
       
  2360   }
       
  2361 
       
  2362 // ---------------------------------------------------------------------------
       
  2363 // CCamAppController::TimeLapseImageCount
       
  2364 // Return the count of items in the timelapse sequence array
       
  2365 // ---------------------------------------------------------------------------
       
  2366 //    
       
  2367 TInt 
       
  2368 CCamAppController::TimeLapseImageCount()
       
  2369   {
       
  2370   return iTimeLapseCaptureCount;
       
  2371   }
       
  2372 
       
  2373 // ---------------------------------------------------------------------------
       
  2374 // CCamAppController::ResetTimelapseArray
       
  2375 // Resets the timelapse sequence array
       
  2376 // ---------------------------------------------------------------------------
       
  2377 //    
       
  2378 void CCamAppController::ResetTimelapseArray()
       
  2379   {
       
  2380   iSequenceFilenameArray->Reset();
       
  2381   }
       
  2382 
       
  2383 // ---------------------------------------------------------------------------
       
  2384 // CCamAppController::PlaySound
       
  2385 // Play a sound with given id.
       
  2386 // ---------------------------------------------------------------------------
       
  2387 //
       
  2388 void CCamAppController::PlaySound( TCamSoundId aSoundId, TBool aEnableCallback )
       
  2389     {
       
  2390     PRINT1( _L("Camera => CCamAppController::PlaySound %d"), aSoundId );
       
  2391     if ( ToneShouldBeSilent( aSoundId ) &&
       
  2392          !iShutterSndAlwaysOn && 
       
  2393          iSilentProfile )
       
  2394         {
       
  2395         PRINT( _L("Camera <> Profile silent, do not play sound") );  
       
  2396         // Don't play shutter sound if we are following
       
  2397         // current profile setting and profile is silent.
       
  2398         // Notify the observer right away. E.g. video start
       
  2399         // depends on the notification
       
  2400         if( aEnableCallback )
       
  2401           {
       
  2402           PlayComplete( aSoundId, KErrNone );
       
  2403           }
       
  2404         /* OLD
       
  2405         if ( aSoundId == ECamVideoStartSoundId ||
       
  2406              aSoundId == ECamVideoPauseSoundId ||
       
  2407              aSoundId == ECamVideoResumeSoundId )
       
  2408             {
       
  2409             // Force the callback to start recording without sound.
       
  2410             PlaySoundComplete();
       
  2411             }
       
  2412         */
       
  2413         }
       
  2414     else
       
  2415         {
       
  2416         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUND, "e_CAM_APP_CAPTURE_SOUND_PLAY 1" );   //CCORAPP_CAPTURE_SOUND_PLAY_START
       
  2417         iSoundPlayer->CancelAllPlaying();
       
  2418         iSoundPlayer->PlaySound( aSoundId, aEnableCallback ); 
       
  2419 
       
  2420         }
       
  2421         
       
  2422     // If in timelapse mode the remaining time counter should be updated
       
  2423     // as soon as the capture tone has played, but as there is no callback
       
  2424     // this is the closest we can get            
       
  2425     if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )  
       
  2426         {
       
  2427         NotifyControllerObservers( ECamEventCounterUpdated );   
       
  2428         }       
       
  2429         
       
  2430     PRINT( _L("Camera <= CCamAppController::PlaySound") );                 
       
  2431     }
       
  2432 
       
  2433 
       
  2434 // ---------------------------------------------------------------------------
       
  2435 // CCamAppController::PlayTone
       
  2436 // Play a tone with specified frequency, period and volume
       
  2437 // ---------------------------------------------------------------------------
       
  2438 //
       
  2439 void CCamAppController::PlayTone( TInt      aToneHz, 
       
  2440                                   TInt      aLenMicSec, 
       
  2441                                   TReal32   aVolume, 
       
  2442                                   TBool     aEnableCallback )
       
  2443   {    
       
  2444   if ( !iShutterSndAlwaysOn && 
       
  2445      iSilentProfile )
       
  2446     {
       
  2447     // don't play shutter sound if we are following
       
  2448     // current profile setting and profile is silent
       
  2449     }
       
  2450   else
       
  2451     {    
       
  2452     iSoundPlayer->PlayTone( aToneHz, aLenMicSec, aVolume, aEnableCallback );
       
  2453     }
       
  2454   }
       
  2455 
       
  2456 // ---------------------------------------------------------------------------
       
  2457 // CCamAppController::AllOptionsVisibleForSettingItem
       
  2458 // Returns true if all the settings list options for a particular setting
       
  2459 // item are visible.
       
  2460 // ---------------------------------------------------------------------------
       
  2461 //
       
  2462 TBool CCamAppController::AllOptionsVisibleForSettingItem( TInt aSettingItem, 
       
  2463                                                     TInt& aRevisedResourceId )
       
  2464   {
       
  2465   if ( ( aSettingItem == ECamSettingItemVideoQuality ) && 
       
  2466        ( iInfo.iActiveCamera == ECamActiveCameraSecondary ) )
       
  2467     {
       
  2468     aRevisedResourceId = ROID(R_CAM_FRONT_CAMERA_VIDEO_QUALITY_TEXT_ARRAY);
       
  2469     return EFalse;
       
  2470     }
       
  2471   // Otherwise, all options are visible for the setting item
       
  2472   return ETrue;
       
  2473   }
       
  2474 
       
  2475 // ----------------------------------------------------
       
  2476 // CCamAppController::SwitchCameraL
       
  2477 // Switch the camera
       
  2478 // ----------------------------------------------------
       
  2479 //
       
  2480 void CCamAppController::SwitchCameraL()
       
  2481   {
       
  2482   PRINT( _L("Camera => CCamAppController::SwitchCameraL") );
       
  2483 
       
  2484   TCamAppControllerInfo oldInfo      = iInfo;
       
  2485   TCamActiveCamera      targetCamera = ECamActiveCameraNone;
       
  2486   // If something goes wrong when changing from 2nd to 1st camera,
       
  2487   // we need to make sure, that 2nd cam settings are not stored 
       
  2488   // to CR by accident.
       
  2489   iInfo = TCamAppControllerInfo(); // reset
       
  2490   
       
  2491   // reset zoom waiting flag. this flag is only used with bitmap viewfinder
       
  2492   // and it might cause problems if one camera uses bitmap viewfinder and the
       
  2493   // other one uses direct viewfinder
       
  2494   iZoomWaitingForCamera = EFalse;
       
  2495 
       
  2496   CancelPreviewChangesL();
       
  2497 
       
  2498   if( ECamActiveCameraPrimary == oldInfo.iActiveCamera )
       
  2499     {
       
  2500     // Currently using primary camera, switch to secondary
       
  2501     PRINT( _L("Camera <> switch to 2nd cam") );
       
  2502  
       
  2503 #ifdef _DEBUG
       
  2504     PRINT ( _L("Camera <> ======================================") );
       
  2505     PRINT ( _L("Camera <> Photo quality index:                  ") );
       
  2506     PRINT1( _L("Camera <> Before loading 2nd cam settings: %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2507 #endif
       
  2508 
       
  2509     LoadSecondaryCameraSettingsL();
       
  2510   
       
  2511 #ifdef _DEBUG
       
  2512     PRINT1( _L("Camera <> After loading 2nd cam settings:  %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2513     PRINT ( _L("Camera <> ======================================") );
       
  2514 #endif
       
  2515 
       
  2516     targetCamera = ECamActiveCameraSecondary;
       
  2517     }
       
  2518   else
       
  2519     {
       
  2520     // Currently using secondary camera, switch to primary
       
  2521     // or landscape secondary camera  
       
  2522     PRINT( _L("Camera <> switch to 1st camera or change 2nd camera mode") )
       
  2523     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2524     if( appUi->IsEmbedded() )
       
  2525         {
       
  2526         LoadStaticSettingsL( appUi->IsEmbedded() );
       
  2527         }
       
  2528     else if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2529         {
       
  2530         iSettingsModel->RestorePrimaryCameraSettingsL();
       
  2531         }
       
  2532 
       
  2533     if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2534         {
       
  2535         PRINT( _L("Camera <> switch to 1st cam") )
       
  2536         targetCamera = ECamActiveCameraPrimary;
       
  2537         }
       
  2538     else
       
  2539         {
       
  2540         PRINT( _L("Camera <> change 2nd camera mode") )
       
  2541         targetCamera = ECamActiveCameraSecondary;
       
  2542         }
       
  2543     }	            
       
  2544   SetCameraSwitchRequired( ESwitchDone );  
       
  2545   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2546   iCameraController->SwitchCameraL( (ECamActiveCameraPrimary == targetCamera) ? 0 : 1 );
       
  2547   iCameraController->CompleteSwitchCameraL();
       
  2548 
       
  2549   // Camera switched.
       
  2550   // a) Set current camera index to the new one.
       
  2551   // b) Set target mode (video/image) to the one before mode switch.
       
  2552   // c) Image mode is single shot after camera switch
       
  2553   // d) Ensure vf start
       
  2554   iInfo.iActiveCamera    = targetCamera; // a)
       
  2555   iInfo.iTargetMode      = appUi->TargetMode(); // b)
       
  2556   iInfo.iTargetImageMode = ( ECamControllerVideo==iInfo.iTargetMode )
       
  2557                          ? ECamImageCaptureNone : ECamImageCaptureSingle; // c)
       
  2558   iInfo.iTargetVfState   = ECamTriActive; // d)
       
  2559   if( oldInfo.iMode != ECamControllerShutdown )
       
  2560   	{
       
  2561   	IssueModeChangeSequenceL();
       
  2562   	}
       
  2563   	
       
  2564   appUi->SetDrawPreCaptureCourtesyUI( ETrue );
       
  2565 
       
  2566   NotifyControllerObservers( ECamEventCameraChanged );
       
  2567 
       
  2568   PRINT( _L("Camera <= CCamAppController::SwitchCameraL") );
       
  2569   }
       
  2570 
       
  2571 // ---------------------------------------------------------------------------
       
  2572 // CCamAppController::ActiveCamera
       
  2573 // Returns the active camera
       
  2574 // ---------------------------------------------------------------------------
       
  2575 //
       
  2576 TCamActiveCamera 
       
  2577 CCamAppController::ActiveCamera() const
       
  2578   {
       
  2579   return iInfo.iActiveCamera;
       
  2580   }
       
  2581 
       
  2582 // ---------------------------------------------------------------------------
       
  2583 // CCamAppController::CameraSwitchQueued
       
  2584 // Returns whether a camera switch is pending
       
  2585 // ---------------------------------------------------------------------------
       
  2586 //
       
  2587 TCameraSwitchRequired 
       
  2588 CCamAppController::CameraSwitchQueued() const   
       
  2589   {
       
  2590   PRINT1( _L("Camera =><= CCamAppController::CameraSwitchQueued %d"), iCameraSwitchRequired )
       
  2591   return iCameraSwitchRequired;
       
  2592   }
       
  2593 
       
  2594 // ---------------------------------------------------------------------------
       
  2595 // CCamAppController::CheckExitStatus
       
  2596 // Check whether exit is required
       
  2597 // ---------------------------------------------------------------------------
       
  2598 //
       
  2599 TBool 
       
  2600 CCamAppController::CheckExitStatus()
       
  2601   {
       
  2602   PRINT( _L("Camera => CCamAppController::CheckExitStatus" ) )
       
  2603   TBool exit = EFalse;
       
  2604   if ( iEndKeyWaiting )
       
  2605       {
       
  2606       exit = ETrue;
       
  2607       }   
       
  2608   else if ( iConfigManager  && iConfigManager->IsLensCoverSupported() )
       
  2609       {
       
  2610       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2611 
       
  2612       if ( iSliderCloseEvent && !appUi->IsEmbedded() && !appUi->Embedding() )
       
  2613           {
       
  2614           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - slider closed, not embedded/embedding" ) )
       
  2615           exit = ETrue;
       
  2616           }
       
  2617       else
       
  2618           {
       
  2619           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - embedded/embedding, not exiting" ) )
       
  2620           exit = EFalse;
       
  2621           }
       
  2622       }
       
  2623   else
       
  2624       {
       
  2625       exit = EFalse;
       
  2626       }
       
  2627 
       
  2628   PRINT1( _L("Camera <= CCamAppController::CheckExitStatus - return %d" ), exit )
       
  2629   return exit;
       
  2630   }
       
  2631     
       
  2632 // ---------------------------------------------------------------------------
       
  2633 // CCamAppController::SetEndKeyExitWaiting
       
  2634 // Update whether exit is required
       
  2635 // ---------------------------------------------------------------------------
       
  2636 //
       
  2637 void 
       
  2638 CCamAppController::SetEndKeyExitWaiting( TBool aEndKeyWaiting )
       
  2639   {
       
  2640   iEndKeyWaiting = aEndKeyWaiting;
       
  2641   }    
       
  2642 
       
  2643 // ---------------------------------------------------------------------------
       
  2644 // CCamAppController::CameraSlideState
       
  2645 // Returns the status of the camera slide
       
  2646 // ---------------------------------------------------------------------------
       
  2647 //
       
  2648 TInt 
       
  2649 CCamAppController::CameraSlideState() const
       
  2650   {
       
  2651   return iSlideState;
       
  2652   }
       
  2653 
       
  2654 // ---------------------------------------------------------------------------
       
  2655 // CCamAppController::SliderCloseEventActioned
       
  2656 // Update whether exit is required
       
  2657 // ---------------------------------------------------------------------------
       
  2658 //
       
  2659 void 
       
  2660 CCamAppController::SliderCloseEventActioned()
       
  2661   {
       
  2662   iSliderCloseEvent = EFalse;
       
  2663   }   
       
  2664 
       
  2665 // ---------------------------------------------------------------------------
       
  2666 // CCamAppController::SetCameraSwitchRequired
       
  2667 // ---------------------------------------------------------------------------
       
  2668 //
       
  2669 void 
       
  2670 CCamAppController::SetCameraSwitchRequired( TCameraSwitchRequired aSwitchRequired )  
       
  2671   {
       
  2672   iCameraSwitchRequired = aSwitchRequired;
       
  2673   }   
       
  2674 
       
  2675 
       
  2676 // ---------------------------------------------------------------------------
       
  2677 // CCamAppController::CheckSlideStatus
       
  2678 // Check the slide state and schedule a camera switch if needed
       
  2679 // ---------------------------------------------------------------------------
       
  2680 //
       
  2681 void CCamAppController::CheckSlideStatus()
       
  2682   {
       
  2683   PRINT( _L("Camera => CCamAppController::CheckSlideStatus") );
       
  2684   // if only 1 camera available then can't switch camera
       
  2685   if ( CamerasAvailable() <= 1 )
       
  2686     {
       
  2687     PRINT( _L("Camera <> Only one camera, no action") );
       
  2688     }
       
  2689   else
       
  2690     {
       
  2691     RefreshSlideStatus();
       
  2692     // if the slide is closed then schedule a camera switch
       
  2693     // if the back camera is active
       
  2694     if ( CameraSlideState() == CameraPlatPSKeys::EClosed  || 
       
  2695          CameraSlideState() == KErrNone )
       
  2696       {
       
  2697       if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  2698         {
       
  2699         PRINT( _L("Camera <> slide closed or uninitialized -> switch to secondary") );
       
  2700         iCameraSwitchRequired = ESwitchPrimaryToSecondary;
       
  2701         }
       
  2702       else
       
  2703         {
       
  2704         PRINT( _L("Camera <> no camera switch needed") );
       
  2705         iCameraSwitchRequired = ESwitchDone;
       
  2706         }
       
  2707       }
       
  2708     // if the slide is open then schedule a camera switch
       
  2709     // if the front camera is active
       
  2710     else if ( CameraSlideState() == CameraPlatPSKeys::EOpen )
       
  2711       {
       
  2712       if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  2713         {
       
  2714         PRINT( _L("Camera <> slide open -> switch to primary") );
       
  2715         iCameraSwitchRequired = ESwitchSecondaryToPrimary;
       
  2716         }
       
  2717       else
       
  2718         {
       
  2719         PRINT( _L("Camera <> no camera switch needed") );
       
  2720         iCameraSwitchRequired = ESwitchDone;
       
  2721         }
       
  2722       }
       
  2723     else
       
  2724       {
       
  2725       // do nothing
       
  2726       PRINT( _L("Camera <> not recognized slider state -> no action") );
       
  2727       }
       
  2728     }
       
  2729   PRINT( _L("Camera <= CCamAppController::CheckSlideStatus") );
       
  2730   }
       
  2731 
       
  2732 
       
  2733 // ----------------------------------------------------
       
  2734 // CCamAppController::EvRange
       
  2735 // Range of EV value supported by current product
       
  2736 // ----------------------------------------------------
       
  2737 //
       
  2738 TCamEvCompRange CCamAppController::EvRange() const
       
  2739   {
       
  2740   PRINT( _L("Camera =><= CCamAppController::EvRange") );
       
  2741   return iEvRange;
       
  2742   }            
       
  2743 
       
  2744 
       
  2745 // ----------------------------------------------------
       
  2746 // CCamAppController::CallStateChanged
       
  2747 // Callback for when the current phone call state changes
       
  2748 // ----------------------------------------------------
       
  2749 //
       
  2750 void 
       
  2751 CCamAppController::CallStateChanged( TPSCTsyCallState aState, 
       
  2752                                      TInt                  /* aError */ )
       
  2753   {
       
  2754   PRINT1( _L("Camera => CCamAppController::CallStateChanged aState: %d"), aState);
       
  2755 
       
  2756   TBool oldState = iInCallOrRinging;
       
  2757 
       
  2758   if ( aState == EPSCTsyCallStateAlerting ||
       
  2759        aState == EPSCTsyCallStateRinging ||
       
  2760        aState == EPSCTsyCallStateDialling ||
       
  2761        aState == EPSCTsyCallStateAnswering ||
       
  2762        aState == EPSCTsyCallStateDisconnecting ||
       
  2763        aState == EPSCTsyCallStateConnected ||
       
  2764        aState == EPSCTsyCallStateHold )
       
  2765     {
       
  2766     // If not already in a call/ringing state, and the new state
       
  2767     // indicates this, stop recording
       
  2768     if ( !iInCallOrRinging )
       
  2769       {
       
  2770       // Set the flag before handle call, as this may need to 
       
  2771       // know the call state for stopping video.
       
  2772       iInCallOrRinging = ETrue;
       
  2773       PRINT( _L("Camera <> CCamAppController::CallStateChanged: calling handleincomingcallL") );
       
  2774       HandleIncomingCall();                                     
       
  2775       }
       
  2776     }
       
  2777   else
       
  2778     {
       
  2779     iInCallOrRinging = EFalse;
       
  2780     }
       
  2781   // If the state has changed from in a call to not, notify the
       
  2782   // observers
       
  2783   // Also notify again if the state has reached connected so that
       
  2784   // the observer can reconsider its actions now that connection is complete
       
  2785   if ( iInCallOrRinging               != oldState ||
       
  2786        EPSCTsyCallStateConnected == aState )
       
  2787     {
       
  2788     PRINT( _L("Camera <> CCamAppController::CallStateChanged: telling call observers") );
       
  2789     NotifyControllerObservers( ECamEventCallStateChanged, KErrNone );        
       
  2790     }
       
  2791 
       
  2792   PRINT1( _L("Camera <= CCamAppController::CallStateChanged(%d, %d)"), aState );
       
  2793   }
       
  2794 
       
  2795 
       
  2796 
       
  2797 
       
  2798 
       
  2799 
       
  2800 // ---------------------------------------------------------------------------
       
  2801 // ReleaseCamera
       
  2802 //
       
  2803 // Releases the camera hardware for other apps to use
       
  2804 // ---------------------------------------------------------------------------
       
  2805 //
       
  2806 void CCamAppController::ReleaseCamera()   
       
  2807     {    
       
  2808     PRINT( _L("Camera => CCamAppController::ReleaseCamera") );
       
  2809 
       
  2810     if ( IsAppUiAvailable())  
       
  2811       {
       
  2812       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2813       if ( appUi )
       
  2814         {
       
  2815         appUi->SetAssumePostCaptureView( EFalse ); 
       
  2816         } 
       
  2817       }
       
  2818 
       
  2819     if ( Busy() )
       
  2820       {
       
  2821       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: set release pending") );
       
  2822       iPendingRelease = ETrue;
       
  2823       }
       
  2824     else if ( iCameraController && ECamCameraIdle != CameraState() )
       
  2825       {      
       
  2826       // No leaving code here. Clear the flag before any operation
       
  2827       // to prevent calling this from the event callbacks caused
       
  2828       // by the following requests.
       
  2829       iPendingRelease = EFalse;
       
  2830 
       
  2831       if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  2832           SequenceCaptureInProgress() )
       
  2833         {
       
  2834         // Cancel ongoing burst capture
       
  2835         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  2836         // and actual cancelling is done when next imagedata arrives.
       
  2837         // However, in this case camera is going to be released, and there won't
       
  2838         // be next image data, so give ECamRequestImageCancel and capture
       
  2839         // completion event here to avoid problems
       
  2840         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: Going to bacgkround in the middle of a burst capture") ); 
       
  2841         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  2842         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );          
       
  2843         }
       
  2844         
       
  2845       //iInfo.iMode            = ECamControllerShutdown;
       
  2846       //iInfo.iTargetMode      = ECamControllerIdle;
       
  2847       iInfo.iTargetMode      = ECamControllerIdle;
       
  2848       iInfo.iImageMode       = ECamImageCaptureNone;
       
  2849       iInfo.iTargetImageMode = ECamImageCaptureNone; 
       
  2850       iInfo.iOperation       = ECamNoOperation;
       
  2851 
       
  2852       iCaptureModeTransitionInProgress = EFalse;
       
  2853 
       
  2854       // Last change to stop view finder if we were "busy" previously in 
       
  2855       // ExitViewfinderMode method. View finder must be stopped in case where 
       
  2856       // orientation is changed, so Posting API display control doesn't try to 
       
  2857       // draw outside existing area. Otherwise KErrTooBig error is encountered. 
       
  2858       StopViewFinder();
       
  2859 
       
  2860       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: requesting release directly..") );
       
  2861       // iInfo.iMode set when complete
       
  2862       TRAP_IGNORE( IssueDirectRequestL( ECamRequestRelease ) );
       
  2863       //iPendingRelease = EFalse;
       
  2864       //shutdown the orientation channel
       
  2865       if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && 
       
  2866       		iAccSensorListening )
       
  2867         {
       
  2868         TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  2869         }
       
  2870       }
       
  2871     else
       
  2872       {
       
  2873       // No action needed.
       
  2874       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle!!") );
       
  2875       if(ECamControllerIdle != iInfo.iMode )
       
  2876         {
       
  2877         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle correcting state!!") );
       
  2878         iInfo.iMode = ECamControllerIdle;
       
  2879         }
       
  2880       }
       
  2881     PRINT( _L("Camera <= CCamAppController::ReleaseCamera") );
       
  2882     }
       
  2883 
       
  2884 
       
  2885 // ---------------------------------------------------------------------------
       
  2886 // IncCameraUsers
       
  2887 //
       
  2888 // Increments the camera usage count
       
  2889 // ---------------------------------------------------------------------------
       
  2890 //
       
  2891 void CCamAppController::IncCameraUsers()
       
  2892   {
       
  2893   PRINT ( _L("Camera => CCamAppController::IncCameraUsers") );
       
  2894   iCameraReferences++;
       
  2895   PRINT1( _L("Camera <= CCamAppController::IncCameraUsers, count now %d"), iCameraReferences );
       
  2896   }
       
  2897 
       
  2898 
       
  2899 // ---------------------------------------------------------------------------
       
  2900 // DecCameraUsers
       
  2901 //
       
  2902 // Decrements the camera usage count
       
  2903 // ---------------------------------------------------------------------------
       
  2904 //
       
  2905 void CCamAppController::DecCameraUsers()
       
  2906   {
       
  2907   PRINT ( _L("Camera => CCamAppController::DecCameraUsers") );
       
  2908 
       
  2909   __ASSERT_DEBUG( iCameraReferences > 0, CamPanic( ECamPanicInvalidState ) );
       
  2910   iCameraReferences--;
       
  2911 
       
  2912   PRINT1( _L("Camera <> CCamAppController::DecCameraUsers: count now %d"), iCameraReferences );
       
  2913   // If the engine is no longer required then release it.
       
  2914   if ( iCameraReferences <= 0 )
       
  2915     {
       
  2916     ReleaseCamera();
       
  2917     }       
       
  2918   PRINT ( _L("Camera <= CCamAppController::DecCameraUsers") );
       
  2919   }
       
  2920 
       
  2921 
       
  2922     
       
  2923 
       
  2924 // ----------------------------------------------------
       
  2925 // CCamAppController::InCallOrRinging
       
  2926 // Whether we are in call or ringing
       
  2927 // ----------------------------------------------------
       
  2928 //
       
  2929 TBool 
       
  2930 CCamAppController::InCallOrRinging() const
       
  2931   {
       
  2932   return iInCallOrRinging;
       
  2933   }
       
  2934 
       
  2935 // ----------------------------------------------------
       
  2936 // CCamAppController::InVideocallOrRinging
       
  2937 // Whether we are in videocall or ringing
       
  2938 // ----------------------------------------------------
       
  2939 //
       
  2940 TBool 
       
  2941 CCamAppController::InVideocallOrRinging()
       
  2942     {
       
  2943     if ( InCallOrRinging() )
       
  2944         {
       
  2945         TInt callType( EPSCTsyCallTypeUninitialized );
       
  2946         TInt err = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType, callType );
       
  2947         if ( err == KErrNone && callType == EPSCTsyCallTypeH324Multimedia )
       
  2948             {
       
  2949             return ETrue;
       
  2950             }
       
  2951         else
       
  2952             {
       
  2953             return EFalse;
       
  2954             }
       
  2955         }
       
  2956     else
       
  2957         {
       
  2958         return EFalse;
       
  2959         }
       
  2960     
       
  2961     }
       
  2962   
       
  2963 // ----------------------------------------------------
       
  2964 // CCamAppController::CurrentlySavingVideo
       
  2965 // Whether we are currently saving a video clip or not
       
  2966 // ----------------------------------------------------
       
  2967 //
       
  2968 TBool 
       
  2969 CCamAppController::CurrentlySavingVideo() const
       
  2970   {
       
  2971   return iSaving;
       
  2972   }
       
  2973         
       
  2974 
       
  2975 
       
  2976 // ---------------------------------------------------------------------------
       
  2977 // IssueModeChangeSequenceL
       
  2978 // ---------------------------------------------------------------------------
       
  2979 //
       
  2980 void
       
  2981 CCamAppController::IssueModeChangeSequenceL( TBool aStartup )
       
  2982   {
       
  2983   PRINT( _L( "Camera => CCamAppController::IssueModeChangeSequenceL" ) );
       
  2984   // Generate the request sequence and issue to Camera Controller.
       
  2985   RCamRequestArray sequence;
       
  2986   CleanupClosePushL( sequence );
       
  2987 
       
  2988   if( !aStartup )
       
  2989     {
       
  2990     GenerateModeChangeSequenceL( sequence );
       
  2991 	
       
  2992 	if( iCameraReferences ) 
       
  2993       {
       
  2994       SetFlags( iBusyFlags, EBusySequence );
       
  2995       TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  2996       CleanupStack::PushL( clearBusy );
       
  2997       iCameraController->RequestSequenceL( sequence );
       
  2998       CleanupStack::Pop();
       
  2999    
       
  3000       iCaptureModeTransitionInProgress = ETrue;
       
  3001       
       
  3002       }
       
  3003     else 
       
  3004   	  {
       
  3005       PRINT( _L("Camera <> No camera users, not requesting sequence.") );
       
  3006       }
       
  3007     }
       
  3008   else
       
  3009     {
       
  3010     GenerateStartupSequenceL( sequence );
       
  3011 	
       
  3012 	SetFlags( iBusyFlags, EBusySequence );
       
  3013     TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  3014     CleanupStack::PushL( clearBusy );
       
  3015     iCameraController->RequestSequenceL( sequence );
       
  3016     CleanupStack::Pop();
       
  3017     }
       
  3018   
       
  3019   CleanupStack::PopAndDestroy(); // sequence.Close()
       
  3020   PRINT( _L( "Camera <= CCamAppController::IssueModeChangeSequenceL" ) );
       
  3021   }
       
  3022 
       
  3023 // ---------------------------------------------------------------------------
       
  3024 // 
       
  3025 // ---------------------------------------------------------------------------
       
  3026 //
       
  3027 void
       
  3028 CCamAppController::GenerateModeChangeSequenceL( RCamRequestArray& aSequence )
       
  3029   {
       
  3030   PRINT( _L( "Camera => CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3031   TBool vfStartDone = EFalse;
       
  3032   //Have to empty autofocusrequest values here because modechange could override
       
  3033   //currently processed autofocus request.
       
  3034   iPendingAFRequest=0;
       
  3035   iCurrentAFRequest=0;
       
  3036   iNoBurstCancel = EFalse;
       
  3037   iKeyUP = EFalse;
       
  3038   iAFCancelInProgress = EFalse;
       
  3039 
       
  3040   // -------------------------------------------------------
       
  3041   if( ECamTriIdle != iCameraController->ViewfinderState() )
       
  3042     {
       
  3043     // If VF is not stopped, frames might come when we are not
       
  3044     // in either image or video mode.
       
  3045     if( ECamControllerIdle != iInfo.iMode 
       
  3046      && iInfo.iTargetMode  != iInfo.iMode )    
       
  3047       {
       
  3048       aSequence.Append( ECamRequestVfRelease );    
       
  3049       } 
       
  3050     else  
       
  3051       
       
  3052     if( ECamTriIdle == iInfo.iTargetVfState )
       
  3053       {
       
  3054       aSequence.Append( ECamRequestVfRelease );      
       
  3055       }
       
  3056     else if( ECamTriInactive == iInfo.iTargetVfState )
       
  3057       {
       
  3058       aSequence.Append( ECamRequestVfStop );      
       
  3059       }
       
  3060     else
       
  3061       {
       
  3062       // Nothing needed here
       
  3063       }
       
  3064 
       
  3065     }
       
  3066 
       
  3067   switch( iInfo.iMode )
       
  3068     {
       
  3069     // ---------------------------------
       
  3070     case ECamControllerImage:
       
  3071       {
       
  3072       if( ECamControllerImage != iInfo.iTargetMode )
       
  3073         {
       
  3074         aSequence.Append( ECamRequestImageRelease );
       
  3075         }
       
  3076       break;
       
  3077       }
       
  3078     // ---------------------------------
       
  3079     case ECamControllerVideo:
       
  3080       {
       
  3081       if( ECamControllerVideo != iInfo.iTargetMode )
       
  3082         {
       
  3083         aSequence.Append( ECamRequestVideoRelease );
       
  3084         }
       
  3085       break;
       
  3086       }
       
  3087     // ---------------------------------
       
  3088     default:
       
  3089       {
       
  3090       // If we need to get to video or image mode
       
  3091       // make sure camera has power on before further requests.
       
  3092       if( ECamControllerImage == iInfo.iTargetMode
       
  3093        || ECamControllerVideo == iInfo.iTargetMode )
       
  3094         {
       
  3095         TUint cameraState( iCameraController->State() );
       
  3096 
       
  3097         if( !(ECamPowerOn&cameraState) )
       
  3098           {
       
  3099           if( !(ECamReserved&cameraState) )
       
  3100             {
       
  3101             aSequence.Append( ECamRequestReserve );
       
  3102             }
       
  3103           aSequence.Append( ECamRequestPowerOn );
       
  3104           }
       
  3105         }
       
  3106       break;
       
  3107       }
       
  3108     // ---------------------------------
       
  3109     }
       
  3110 
       
  3111   // -------------------------------------------------------
       
  3112   // Append prepare operations to achieve target camera mode
       
  3113   switch( iInfo.iTargetMode )
       
  3114     {
       
  3115     // ---------------------------------
       
  3116     case ECamControllerImage:
       
  3117       {
       
  3118       if( ECamImageCaptureNone != iInfo.iTargetImageMode )
       
  3119         {
       
  3120         aSequence.Append( ECamRequestImageInit );      
       
  3121 
       
  3122         // Snapshot may have to be released and restarted because the
       
  3123         // snapshot size may change.
       
  3124         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3125         if( appUi )
       
  3126             {
       
  3127             if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3128                 {
       
  3129                 // If vf needs to be (re)started.
       
  3130                 // Camera Controller checks from Setting Provider if
       
  3131                 // viewfinder mode (direct/bitmap) has changed, and
       
  3132                 // releases old type first if needed.
       
  3133                 if( ECamTriActive == iInfo.iTargetVfState )
       
  3134                   {
       
  3135                   PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3136                   aSequence.Append( ECamRequestVfStart );
       
  3137                   vfStartDone = ETrue;
       
  3138                   }
       
  3139                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3140                 aSequence.Append( ECamRequestSsRelease );
       
  3141                 aSequence.Append( ECamRequestSsStart );
       
  3142                 }
       
  3143             else
       
  3144                 {
       
  3145                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot off" ) );
       
  3146                 aSequence.Append( ECamRequestSsRelease );
       
  3147                 aSequence.Append( ECamRequestSsStop );
       
  3148                 }
       
  3149             }
       
  3150         }
       
  3151 
       
  3152       break;
       
  3153       }
       
  3154     // ---------------------------------
       
  3155     case ECamControllerVideo:
       
  3156       {
       
  3157       // Video recorder needs to be initialized and prepared
       
  3158       // if we are not already in video mode.
       
  3159       if ( iInfo.iMode != ECamControllerVideo )
       
  3160           {
       
  3161           iVideoInitNeeded = ETrue;
       
  3162           }
       
  3163        aSequence.Append( ECamRequestVideoInit );
       
  3164        
       
  3165       // Snapshot has to be released and restarted because the
       
  3166       // snapshot size may change.
       
  3167       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3168       if( appUi )
       
  3169           {
       
  3170           if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3171               {
       
  3172               // If vf needs to be (re)started.
       
  3173               // Camera Controller checks from Setting Provider if
       
  3174               // viewfinder mode (direct/bitmap) has changed, and
       
  3175               // releases old type first if needed.
       
  3176               if( ECamTriActive == iInfo.iTargetVfState )
       
  3177                 {
       
  3178                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3179                 aSequence.Append( ECamRequestVfStart );
       
  3180                 vfStartDone = ETrue;
       
  3181                 }
       
  3182               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3183               aSequence.Append( ECamRequestSsRelease );
       
  3184               aSequence.Append( ECamRequestSsStart );
       
  3185               }
       
  3186           else
       
  3187               {
       
  3188               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot off" ) );
       
  3189               aSequence.Append( ECamRequestSsRelease );
       
  3190               aSequence.Append( ECamRequestSsStop );
       
  3191               }
       
  3192           }
       
  3193       break;
       
  3194       }
       
  3195     // ---------------------------------
       
  3196     default:
       
  3197       break;
       
  3198     // ---------------------------------
       
  3199     }
       
  3200 
       
  3201   // If vf needs to be (re)started.
       
  3202   // Camera Controller checks from Setting Provider if
       
  3203   // viewfinder mode (direct/bitmap) has changed, and
       
  3204   // releases old type first if needed.
       
  3205   if( !vfStartDone && ECamTriActive == iInfo.iTargetVfState )
       
  3206     {
       
  3207     PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3208     aSequence.Append( ECamRequestVfStart );
       
  3209     }
       
  3210 
       
  3211 
       
  3212   // -------------------------------------------------------
       
  3213 #ifdef _DEBUG
       
  3214   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
  3215   for( TInt i = 0; i < aSequence.Count(); i++ )
       
  3216     {
       
  3217     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
  3218     }
       
  3219 #endif  
       
  3220   PRINT( _L( "Camera <= CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3221   }
       
  3222 
       
  3223 
       
  3224 // ---------------------------------------------------------------------------
       
  3225 // CCamAppController::SettingsPhotoResolution
       
  3226 // Returns the photo resolution stored by the Settings Model
       
  3227 // ---------------------------------------------------------------------------
       
  3228 //
       
  3229 TCamPhotoSizeId  CCamAppController::SettingsPhotoResolution() const
       
  3230     {
       
  3231     return iSettingsModel->CurrentPhotoResolution();
       
  3232     }
       
  3233 
       
  3234 // ---------------------------------------------------------------------------
       
  3235 // CCamAppController::GetCurrentImageDimensions
       
  3236 // ---------------------------------------------------------------------------
       
  3237 //
       
  3238 TSize 
       
  3239 CCamAppController::GetCurrentImageDimensions() const
       
  3240   {
       
  3241   TCamPhotoSizeId index = iSettingsModel->CurrentPhotoResolution();
       
  3242   TSize           size  = iSettingsModel->ImageResolutionFromIndex( index );
       
  3243   return size;
       
  3244   }
       
  3245 
       
  3246 // ---------------------------------------------------------------------------
       
  3247 // CCamAppController::GetCurrentImageResolution
       
  3248 // Gets the current image resolution used.  May not be the same at that stored in Settings
       
  3249 // if Zoom state is not 1x
       
  3250 // ---------------------------------------------------------------------------
       
  3251 //
       
  3252 TCamPhotoSizeId CCamAppController::GetCurrentImageResolution() const
       
  3253     {   
       
  3254     TCamPhotoSizeId size = iSettingsModel->CurrentPhotoResolution();
       
  3255     return size;    
       
  3256     }
       
  3257     
       
  3258 // ---------------------------------------------------------------------------
       
  3259 // CCamAppController::GetCurrentImageCompression
       
  3260 // Returns the photo compression level from the Settings Model
       
  3261 // ---------------------------------------------------------------------------
       
  3262 //
       
  3263 TInt  CCamAppController::GetCurrentImageCompression() const
       
  3264     {
       
  3265     return iSettingsModel->CurrentPhotoCompression();
       
  3266     }
       
  3267 
       
  3268 // ---------------------------------------------------------------------------
       
  3269 // CCamAppController::GetCurrentVideoResolution
       
  3270 // Gets the current video resolution used.  
       
  3271 // ---------------------------------------------------------------------------
       
  3272 //
       
  3273 TCamVideoResolution CCamAppController::GetCurrentVideoResolution() const
       
  3274     {   
       
  3275     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  3276     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];        
       
  3277     return static_cast<TCamVideoResolution>( level.VideoResolution() );
       
  3278     }
       
  3279 
       
  3280 // ---------------------------------------------------------------------------
       
  3281 // CCamAppController::UsePhoneMemoryL
       
  3282 // Force use of phone memory storage.  
       
  3283 // ---------------------------------------------------------------------------
       
  3284 //
       
  3285 void CCamAppController::UsePhoneMemoryL() const
       
  3286     {
       
  3287 #ifdef PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE   
       
  3288     // This function is used to directly force the value of media storage
       
  3289     // Bypasses any updates the controller does for change to these values
       
  3290 
       
  3291     if( ExistMassStorage() )
       
  3292         {
       
  3293         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3294                                              ECamMediaStorageMassStorage );
       
  3295         
       
  3296         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3297                                              ECamMediaStorageMassStorage );
       
  3298         }
       
  3299     else
       
  3300         {        
       
  3301         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3302                                              ECamMediaStoragePhone );
       
  3303         
       
  3304         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3305                                              ECamMediaStoragePhone );
       
  3306         }
       
  3307 
       
  3308 #endif // PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE
       
  3309     }
       
  3310 
       
  3311 
       
  3312 // ===========================================================================
       
  3313 // From MCamSettingsModelObserver
       
  3314 
       
  3315 // ---------------------------------------------------------------------------
       
  3316 // CCamAppController::IntSettingChangedL
       
  3317 //
       
  3318 // ---------------------------------------------------------------------------
       
  3319 //
       
  3320 void 
       
  3321 CCamAppController::IntSettingChangedL( TCamSettingItemIds aSettingItem, 
       
  3322                                        TInt               aSettingValue )
       
  3323   {
       
  3324   switch( aSettingItem )
       
  3325     {
       
  3326     case ECamSettingItemDynamicSelfTimer:
       
  3327       {
       
  3328       TCamSelfTimerFunctions function( ECamSelfTimerDisabled );
       
  3329       switch( aSettingValue )
       
  3330         {
       
  3331         case ECamSelfTimer2:  function = ECamSelfTimerMode1; break;
       
  3332         case ECamSelfTimer10: function = ECamSelfTimerMode2; break;
       
  3333         case ECamSelfTimer20: function = ECamSelfTimerMode3; break;            
       
  3334         default:                                             break;
       
  3335         }
       
  3336       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3337       if( appUi ) 
       
  3338         {
       
  3339         appUi->SelfTimerEnableL( function );
       
  3340         }
       
  3341       break;
       
  3342       }
       
  3343     case ECamSettingItemPhotoQuality:
       
  3344         {
       
  3345         HandleImageQualitySettingChangeL();
       
  3346         break;
       
  3347         }
       
  3348     case ECamSettingItemVideoQuality:
       
  3349        NotifyControllerObservers( ECamEventVideoQualityChanged, KErrNone );
       
  3350        break;
       
  3351     case ECamSettingItemVideoAudioRec:
       
  3352       {
       
  3353       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  3354       break;
       
  3355       }
       
  3356     case ECamSettingItemContinuousAutofocus:  
       
  3357       {
       
  3358       NotifyControllerObservers( ECamEventContAFStateChanged );
       
  3359       break;
       
  3360       }
       
  3361       
       
  3362     case ECamSettingItemFaceTracking:
       
  3363       {
       
  3364       PRINT( _L("Camera => ECamSettingItemFaceTracking") );
       
  3365       TCamCameraSettingId cameraId( 
       
  3366         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3367       iCameraController->DirectSettingsChangeL( cameraId );
       
  3368       NotifyControllerObservers( ECamEventFaceTrackingStateChanged );
       
  3369       break;
       
  3370       }  
       
  3371     case ECamSettingItemDynamicVideoFlash:  
       
  3372       {
       
  3373       PRINT( _L("Camera => ECamSettingItemDynamicVideoFlash") );
       
  3374       TCamCameraSettingId cameraId( 
       
  3375         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3376       iCameraController->DirectSettingsChangeL( cameraId );
       
  3377       break;
       
  3378       }  
       
  3379     default:
       
  3380       {
       
  3381       break;
       
  3382       }
       
  3383     }
       
  3384   }
       
  3385 
       
  3386 // ---------------------------------------------------------------------------
       
  3387 // CCamAppController::TextSettingChangedL
       
  3388 //
       
  3389 // ---------------------------------------------------------------------------
       
  3390 //
       
  3391 void 
       
  3392 CCamAppController::TextSettingChangedL( TCamSettingItemIds /*aSettingItem*/, 
       
  3393                                         const TDesC&       /*aSettingValue*/ )
       
  3394   {
       
  3395   }
       
  3396 
       
  3397 // ---------------------------------------------------------------------------
       
  3398 // HandleImageQualitySettingChangeL
       
  3399 // ---------------------------------------------------------------------------
       
  3400 //
       
  3401 void 
       
  3402 CCamAppController::HandleImageQualitySettingChangeL() 
       
  3403   {
       
  3404   PRINT( _L("Camera => CCamAppController::HandleImageQualitySettingChangeL") );
       
  3405   if( IsViewFinding() ) 
       
  3406     {
       
  3407     PRINT( _L("Camera <> CCamAppController - viewfinder on, stop vf / re-prepare / start vf..") );
       
  3408     TRAPD( status, 
       
  3409       {
       
  3410       IssueDirectRequestL( ECamRequestVfStop    );
       
  3411       IssueDirectRequestL( ECamRequestSsRelease );
       
  3412       IssueDirectRequestL( ECamRequestImageInit );
       
  3413       IssueDirectRequestL( ECamRequestSsStart   );
       
  3414       IssueDirectRequestL( ECamRequestVfStart   );
       
  3415       });
       
  3416       
       
  3417     if( KErrNone != status )
       
  3418       {
       
  3419       SetOperation( ECamStandby, status );
       
  3420       }
       
  3421     }
       
  3422 
       
  3423   NotifyControllerObservers( ECamEventImageQualityChanged, KErrNone );      
       
  3424   PRINT( _L("Camera <= CCamAppController::HandleImageQualitySettingChangeL") );
       
  3425   }
       
  3426 
       
  3427 // ---------------------------------------------------------------------------
       
  3428 // CCamAppController::BurstModeActive
       
  3429 //
       
  3430 // ---------------------------------------------------------------------------
       
  3431 //
       
  3432 void
       
  3433 CCamAppController::BurstModeActiveL( TBool aActive, TBool /*aStillModeActive*/ )
       
  3434   { 
       
  3435   PRINT1( _L("Camera => CCamAppController::BurstModeActiveL %d"), aActive );  
       
  3436   if( ECamControllerImage == iInfo.iMode )  
       
  3437     {
       
  3438     //TCamImageCaptureMode oldImageMode = iInfo.iImageMode; 
       
  3439     // We are in still capture mode     
       
  3440     if( aActive )
       
  3441       {
       
  3442       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = appUi->CurrentBurstMode() ") );  
       
  3443       // Burst mode active. Query current mode from AppUi  
       
  3444       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3445       // iInfo.iImageMode = appUi->CurrentBurstMode();
       
  3446       SetImageMode( appUi->CurrentBurstMode() );
       
  3447       // reset image orientation
       
  3448       iImageOrientation = ECamOrientation0;
       
  3449       TRAP_IGNORE( SetImageOrientationL() );
       
  3450       
       
  3451       }
       
  3452     else
       
  3453       {
       
  3454       // Burst mode not active  
       
  3455       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = ECamImageCaptureSingle ") );
       
  3456       // iInfo.iImageMode = ECamImageCaptureSingle;
       
  3457       SetImageMode( ECamImageCaptureSingle );
       
  3458       }  
       
  3459     iRequestedCaptureCount = ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3460                              ? KShortBurstCount
       
  3461                              : 1;
       
  3462     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  3463     // set image orientation in case it was changed during burst mode
       
  3464     if( iOrientationChangeOccured )
       
  3465         {
       
  3466         iOrientationChangeOccured = EFalse;	
       
  3467         TRAP_IGNORE( SetImageOrientationL() );
       
  3468         }
       
  3469 
       
  3470     }
       
  3471   else
       
  3472     {
       
  3473     PRINT( _L("Camera <> CCamAppController .. [WARNING] Not in image mode, set iInfo.iImageMode = ECamImageCaptureNone") );  
       
  3474     // iInfo.iImageMode = ECamImageCaptureNone;  
       
  3475     SetImageMode( ECamImageCaptureNone );
       
  3476     } 
       
  3477   PRINT( _L("Camera <= CCamAppController::BurstModeActiveL %d") );    
       
  3478   }
       
  3479 
       
  3480 
       
  3481 // ---------------------------------------------------------------------------
       
  3482 // CCamAppController::SetVideoLengthL
       
  3483 // Set video length (max or short)
       
  3484 // ---------------------------------------------------------------------------
       
  3485 //
       
  3486 void CCamAppController::SetVideoLengthL( TInt /*aLength*/ )
       
  3487     {
       
  3488     PRINT( _L( "Camera => CCamAppController::SetVideoLengthL" ) );
       
  3489     User::Leave( KErrNotSupported );
       
  3490     }
       
  3491 
       
  3492 // ---------------------------------------------------------------------------
       
  3493 // CCamAppController::CurrentPhotoStorageLocation
       
  3494 // Returns the current photo storage location filtered by MMC presence
       
  3495 // ---------------------------------------------------------------------------
       
  3496 TInt CCamAppController::CurrentPhotoStorageLocation() const
       
  3497   {
       
  3498   TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  3499   
       
  3500   // added iForceUseOfPhoneMemory part to treat current location 
       
  3501   // as Mass Storage / Phone, also if it is forced.
       
  3502   if (  iForceUseOfPhoneMemory ||  
       
  3503         ( ( storageLocation == ECamMediaStorageCard ) &&
       
  3504           ( CamUtility::MemoryCardStatus() != ECamMemoryCardInserted ) ) )
       
  3505     {
       
  3506     if ( ExistMassStorage() )
       
  3507       {
       
  3508       storageLocation = ECamMediaStorageMassStorage;
       
  3509       }
       
  3510     else
       
  3511       {
       
  3512       storageLocation = ECamMediaStoragePhone;
       
  3513       }
       
  3514     }
       
  3515   return storageLocation;
       
  3516   }
       
  3517 
       
  3518 // ---------------------------------------------------------------------------
       
  3519 // CCamAppController::CurrentVideoStorageLocation
       
  3520 // Returns the current video storage location filtered by MMC presence
       
  3521 // ---------------------------------------------------------------------------
       
  3522 TInt CCamAppController::CurrentVideoStorageLocation() const
       
  3523 	{
       
  3524 	TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoMediaStorage );        
       
  3525 
       
  3526 	// added iForceUseOfPhoneMemory part to treat current location 
       
  3527 	// as Mass Storage / Phone, also if it is forced.
       
  3528 	
       
  3529   if ( iForceUseOfPhoneMemory )
       
  3530     {
       
  3531     storageLocation = iForcedStorageLocation;
       
  3532     }
       
  3533   return storageLocation;
       
  3534   }
       
  3535 
       
  3536 
       
  3537 
       
  3538 // ---------------------------------------------------------------------------
       
  3539 // CCamAppController::ReleaseArray
       
  3540 // Record that the view has finished with the array
       
  3541 // ---------------------------------------------------------------------------
       
  3542 //
       
  3543 void CCamAppController::ReleaseArray( TBool aForcedRelease )
       
  3544   {
       
  3545   PRINT( _L("Camera => CCamAppController::ReleaseArray") );
       
  3546   // Otherwise  we were using the real capture array, so reset it
       
  3547   if( iArrayUsageCount > 0 )
       
  3548       {
       
  3549       iArrayUsageCount--;
       
  3550       }
       
  3551 
       
  3552   if ( iArrayUsageCount == 0 || aForcedRelease )
       
  3553       {
       
  3554       PRINT( _L("Camere <> CCamAppController::ReleaseArray .. usage to 0") );
       
  3555       iCaptureArray->Reset();
       
  3556       iCurrentImageIndex = 0;
       
  3557       // May have released a large amount of memory, so compress the heap
       
  3558       User::Heap().Compress();
       
  3559       }        
       
  3560 
       
  3561   PRINT( _L("Camera <= CCamAppController::ReleaseArray") );
       
  3562   }
       
  3563 
       
  3564 // ---------------------------------------------------------------------------
       
  3565 // CCamAppController::RestoreFactorySettingsL
       
  3566 // Delete 
       
  3567 // ---------------------------------------------------------------------------
       
  3568 //    
       
  3569 void CCamAppController::RestoreFactorySettingsL( TBool aIsEmbedded )
       
  3570   {          
       
  3571   PRINT( _L("Camera => CCamAppController::RestoreFactorySettingsL") );
       
  3572   iSettingsModel->ResetRepository();
       
  3573     
       
  3574   // reload static settings
       
  3575   LoadStaticSettingsL( aIsEmbedded );
       
  3576   
       
  3577   // reload dynamic settings
       
  3578   SetDynamicSettingsToDefaults();
       
  3579   
       
  3580   // Restoring camera settings didn't set the capture mode to single capture, 
       
  3581   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3582   appUi->SwitchStillCaptureModeL( ECamImageCaptureSingle, EFalse, EFalse );
       
  3583   //
       
  3584   SetMode( ECamControllerIdle );  
       
  3585       
       
  3586   if( iLocationTrailStarted &&
       
  3587       ECamLocationOn != IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  3588     {    
       
  3589     PRINT( _L("Camera <> CCamAppController::RestoreFactorySettingsL - Stop location trail") );
       
  3590     // Location trail has been started, but setting off after restore -> stop trail
       
  3591     // Starting (if needed after restore) happens when still precap view is activated
       
  3592     StopLocationTrail();
       
  3593     }
       
  3594         
       
  3595   //
       
  3596   NotifyControllerObservers( ECamEventRestoreCameraSettings );
       
  3597   PRINT( _L("Camera <= CCamAppController::RestoreFactorySettingsL") );
       
  3598   }
       
  3599 
       
  3600 
       
  3601 
       
  3602 
       
  3603 // ---------------------------------------------------------------------------
       
  3604 // PlayComplete
       
  3605 //
       
  3606 // Called from when sound playing completes.
       
  3607 // ---------------------------------------------------------------------------
       
  3608 //
       
  3609 void 
       
  3610 CCamAppController::PlayComplete( TInt /*aStatus*/, TInt /*aSoundId*/ )
       
  3611   {
       
  3612   PlaySoundComplete();
       
  3613   }
       
  3614 
       
  3615 // ---------------------------------------------------------------------------
       
  3616 // CCamAppController::PlaySoundComplete
       
  3617 // Called when playback of a sound has completed.  Typically used in conjunction
       
  3618 // with Video recording (must only start recording AFTER sound has finished
       
  3619 // to avoid recording the sound in the recorded clip).
       
  3620 // ---------------------------------------------------------------------------
       
  3621 //
       
  3622 void CCamAppController::PlaySoundComplete()
       
  3623   {
       
  3624   PRINT( _L("Camera => CCamAppController::PlaySoundComplete") );
       
  3625   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUNDCOMPLETE, "e_CAM_APP_CAPTURE_SOUND_PLAY 0" );    //CCORAPP_CAPTURE_SOUND_PLAY_END
       
  3626   
       
  3627   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  3628   if( ECamControllerVideo == iInfo.iMode && !IsKeyLockOn() )
       
  3629     {
       
  3630     switch( CurrentVideoOperation() )
       
  3631       {
       
  3632       case ECamResuming:
       
  3633         {
       
  3634         // Restarting video
       
  3635         DoRecord();
       
  3636         break;
       
  3637         }
       
  3638       case ECamPausing:
       
  3639         {
       
  3640         // Notifies observers, so paused icon and softkeys can be updated.
       
  3641         SetOperation( ECamPaused );
       
  3642         break;
       
  3643         }
       
  3644       case ECamNoOperation:
       
  3645         {
       
  3646         // Starting the video capture
       
  3647         // If the next file path has not changed, start capturing
       
  3648         if ( BurstCaptureArray()->FileName( 0 ).Compare( iSuggestedVideoPath ) == 0 )
       
  3649           {
       
  3650           PRINT( _L("Camera <> starting to record..") );
       
  3651           DoRecord();
       
  3652           }
       
  3653         // File path changed. Prepare the engine with the new video file path.
       
  3654         // Start video recording when filename changed (event)
       
  3655         else 
       
  3656           {
       
  3657           iVideoRequested = ETrue;
       
  3658           iSuggestedVideoPath.Copy( BurstCaptureArray()->FileName( 0 ) );
       
  3659           PRINT1( _L("Camera <> Requesting Camera controller to set the video name, iSuggestedVideoPath = [%S] "), &iSuggestedVideoPath );          
       
  3660           TRAP_IGNORE(
       
  3661             {
       
  3662             // Set video name change pending and request setting it to camera controller.
       
  3663             iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  3664             IssueSettingsChangeRequestL();
       
  3665             });
       
  3666           iVideoNameRetries = KVideoNameRetryCount;
       
  3667           }      
       
  3668         }
       
  3669       default:
       
  3670         {
       
  3671         // No operation. 
       
  3672         // Should be stopping video
       
  3673         }
       
  3674       }
       
  3675     }
       
  3676   else
       
  3677     {
       
  3678     // Image mode or keylock on, no action
       
  3679     }
       
  3680   PRINT( _L("Camera <= CCamAppController::PlaySoundComplete") );
       
  3681   }
       
  3682 // ---------------------------------------------------------------------------
       
  3683 // CCamAppController::MediaFileChangedNotification
       
  3684 //Helper function for making notification about deleted files
       
  3685 // ---------------------------------------------------------------------------
       
  3686 //
       
  3687 void  
       
  3688 CCamAppController::MediaFileChangedNotification()
       
  3689   {
       
  3690   PRINT( _L("Camera => CCamAppController::MediaFileChangedNotification") );
       
  3691   NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3692   PRINT( _L("Camera <= CCamAppController::MediaFileChangedNotification") );
       
  3693   }
       
  3694 
       
  3695 
       
  3696 // ---------------------------------------------------------------------------
       
  3697 // CCamAppController::DeleteCurrentFile
       
  3698 // Delete the current image/video file
       
  3699 // ---------------------------------------------------------------------------
       
  3700 //
       
  3701 TInt 
       
  3702 CCamAppController::DeleteCurrentFile( TBool aNotify /*=ETrue*/ )
       
  3703   {
       
  3704   PRINT( _L("Camera => CCamAppController::DeleteCurrentFile") );
       
  3705   iImageSaveRequestPending = EFalse;
       
  3706 
       
  3707   TInt err( KErrNone );
       
  3708   if( BurstCaptureArray()->Count() > 0 )
       
  3709     {
       
  3710     err = BurstCaptureArray()->SetDeleted( iCurrentImageIndex, ETrue );
       
  3711     if ( aNotify && err == KErrNone )
       
  3712       {
       
  3713       NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3714       }
       
  3715     }
       
  3716 
       
  3717   PRINT( _L("Camera <= CCamAppController::DeleteCurrentFile") );
       
  3718   return err;
       
  3719   }
       
  3720 
       
  3721 // ---------------------------------------------------------------------------
       
  3722 // CCamAppController::DeleteTimeLapseFiles
       
  3723 // Delete the current timelapse sequence
       
  3724 // ---------------------------------------------------------------------------
       
  3725 //
       
  3726 void 
       
  3727 CCamAppController::DeleteTimeLapseFiles()    
       
  3728   {
       
  3729   // Count() is inline
       
  3730   for ( TInt i = 0; i < iSequenceFilenameArray->Count(); i++ )
       
  3731     {
       
  3732     TPtrC filename( iSequenceFilenameArray->MdcaPoint( i ) );
       
  3733     // Error ignored
       
  3734     (void)iImageSaveActive->DeleteFile( filename, ETrue );
       
  3735     }
       
  3736   iSequenceFilenameArray->Reset();        
       
  3737   }
       
  3738  
       
  3739 // ---------------------------------------------------------------------------
       
  3740 // CCamAppController::IsProcessingCapture
       
  3741 // Indicate whether or not the controller is actively engaged in still
       
  3742 // or video capture
       
  3743 // ---------------------------------------------------------------------------
       
  3744 //   
       
  3745 
       
  3746 TBool CCamAppController::IsProcessingCapture()
       
  3747     {
       
  3748     return ( iCaptureRequested  // if a still capture is pending
       
  3749           || iVideoRequested    // if a video capture is pending                            
       
  3750           || EngineProcessingCapture() // if recording or capture is active
       
  3751           || ECamImageCaptureTimeLapse == iInfo.iImageMode  // if capturing time lapse
       
  3752           || CurrentlySavingVideo() );        // if a video save is in progress  
       
  3753     }
       
  3754   
       
  3755 // ---------------------------------------------------------------------------
       
  3756 // CCamAppController::CompleteCaptureAndNotifyL
       
  3757 // Request that any current processes complete, then notify observers
       
  3758 // ---------------------------------------------------------------------------
       
  3759 //   
       
  3760 void 
       
  3761 CCamAppController::CompleteCaptureAndNotifyL( MCamObserver* aObserver, 
       
  3762                                               TBool         aSafeCompletion )    
       
  3763   {
       
  3764   PRINT( _L( "Camera => CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3765   
       
  3766   RProperty::Set( KPSUidCamcorderNotifier, KCCorFocused, 0 );
       
  3767     
       
  3768   // Add the observer to the observer handler for capture completion.
       
  3769   if ( !iCaptureCompletionObserverHandler )
       
  3770     {
       
  3771     iCaptureCompletionObserverHandler = CCamObserverHandler::NewL();
       
  3772     }
       
  3773   iCaptureCompletionObserverHandler->RegisterObserverL( aObserver );
       
  3774     
       
  3775   // if the capture has not yet begun, all that is required is to switch off
       
  3776   // the pending capture
       
  3777   iCaptureRequested = EFalse;
       
  3778   iVideoRequested   = EFalse;
       
  3779                
       
  3780   // if no capture is actively in progress
       
  3781   if ( !IsProcessingCapture() )
       
  3782     {
       
  3783     PRINT( _L( "Camera <> not capturing calling HandleCaptureCompletion" ) )
       
  3784     HandleCaptureCompletion();
       
  3785     }
       
  3786 
       
  3787   // if recording is active
       
  3788   else if ( ECamControllerVideo == iInfo.iMode )
       
  3789     {
       
  3790     if( ECamCapturing == iInfo.iOperation
       
  3791      || ECamPausing   == iInfo.iOperation
       
  3792      || ECamPaused    == iInfo.iOperation
       
  3793      || ECamResuming  == iInfo.iOperation )
       
  3794       {
       
  3795       PRINT( _L( "Camera <> currently recording calling StopVideoRecording()" ) )
       
  3796       StopVideoRecording();
       
  3797       // iCaptureCompletionObserverHandler will be notified when the record completes
       
  3798       // in McaeoVideoRecordingComplete
       
  3799       }
       
  3800     }        
       
  3801   else if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  3802     {
       
  3803     PRINT( _L( "Camera <> Calling StopSequenceCapture" ) )
       
  3804     StopSequenceCaptureL();
       
  3805     // iCaptureCompletionObserverHandler will be notified when the 
       
  3806     // next image saving completes
       
  3807     }
       
  3808             
       
  3809   // if a burst capture is in early stages
       
  3810   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3811     {
       
  3812     if( ECamCapturing == iInfo.iOperation )
       
  3813       {
       
  3814       if ( !aSafeCompletion )
       
  3815         {
       
  3816         //iEngine->CancelCaptureStill();
       
  3817         PRINT( _L( "Camera <> Safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3818         IssueDirectRequestL( ECamRequestImageCancel );
       
  3819         CompleteBurstOperation();
       
  3820         }
       
  3821       else
       
  3822         {
       
  3823         //iEngine->StopStillBurstCapture();
       
  3824         PRINT( _L( "Camera <> Not safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3825         IssueDirectRequestL( ECamRequestImageCancel );
       
  3826         // iCaptureCompletionObserverHandler will be notified when the 
       
  3827         // image saving completes
       
  3828         }
       
  3829       }
       
  3830     }
       
  3831   else // do nothing
       
  3832     {
       
  3833     PRINT( _L( "Camera <> currently waiting for capture completion" ) )
       
  3834     // e.g. iOperation == ECamCaptureCompleting
       
  3835     // iCaptureCompletionObserverHandler will be notified when the 
       
  3836     // image saving completes
       
  3837     
       
  3838     // e.g. CurrentlySavingVideo()
       
  3839     // iCaptureCompletionObserverHandler will be notified when the 
       
  3840     // video saving completes in McaeoVideoRecordingComplete
       
  3841     
       
  3842     // e.g. iOperation == ECamCaptureInProgress (single capture)
       
  3843     // iCaptureCompletionObserverHandler will be notified when the 
       
  3844     // image saving completes
       
  3845     }        
       
  3846   PRINT( _L( "Camera <= CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3847   }
       
  3848 
       
  3849 // ---------------------------------------------------------------------------
       
  3850 // CCamAppController::EnterShutdownMode
       
  3851 // Enter shutdown mode as the application is closing
       
  3852 // ---------------------------------------------------------------------------
       
  3853 //
       
  3854 void 
       
  3855 CCamAppController::EnterShutdownMode( TBool aImmediateShutdown )
       
  3856   {
       
  3857   PRINT1( _L( "Camera => CCamAppController::EnterShutdownMode( aImmediateShutdown=%d )"), aImmediateShutdown );
       
  3858   
       
  3859   DeRegisterHarverterClientEvents();  
       
  3860 
       
  3861   if ( !IsInShutdownMode() )
       
  3862     {
       
  3863     PRINT ( _L( "Camera <> CCamAppController::EnterShutdownMode: set target mode to ECamControllerShutdown..") );
       
  3864     SetTargetMode( ECamControllerShutdown );
       
  3865     }
       
  3866 
       
  3867   // if not close down straightaway (i.e. for embedded )
       
  3868   if ( !aImmediateShutdown )
       
  3869     {
       
  3870     // cancel any outstanding sound requests
       
  3871     // iSoundPlayer->CancelTonePlayer();
       
  3872     iSoundPlayer->CancelAllPlaying();
       
  3873     
       
  3874     TRAPD( err, CompleteCaptureAndNotifyL( this, EFalse ) )
       
  3875     if ( err )
       
  3876       {
       
  3877       NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  3878       }
       
  3879     }
       
  3880   else
       
  3881     {
       
  3882     // This checks for any ongoing operation.
       
  3883     ReleaseCamera();
       
  3884     }
       
  3885 
       
  3886   PRINT ( _L( "Camera <= CCamAppController::EnterShutdownMode") );
       
  3887   }
       
  3888 
       
  3889 // ---------------------------------------------------------------------------
       
  3890 // CCamAppController::IsInShutdownMode
       
  3891 // Whether or not the controller is in shutdown mode
       
  3892 // ---------------------------------------------------------------------------
       
  3893 //
       
  3894 TBool CCamAppController::IsInShutdownMode() const
       
  3895     {
       
  3896     return ( ECamControllerShutdown == iInfo.iTargetMode );
       
  3897     }
       
  3898 
       
  3899 
       
  3900 // ---------------------------------------------------------------------------
       
  3901 // CCamAppController::IsAppUiAvailable
       
  3902 // Returns true if AppUi has been constructed, and not yet destructed
       
  3903 // ---------------------------------------------------------------------------
       
  3904 //
       
  3905 TBool CCamAppController::IsAppUiAvailable() const
       
  3906     {
       
  3907     return iAppUiAvailable;
       
  3908     }       
       
  3909     
       
  3910 // ---------------------------------------------------------------------------
       
  3911 // CCamAppController::SetAppUiAvailable
       
  3912 // Sets AppUi availablility (see IsAppUiAvailable)
       
  3913 // ---------------------------------------------------------------------------
       
  3914 //    
       
  3915 void CCamAppController::SetAppUiAvailable( TBool aAvailable )
       
  3916     {
       
  3917     iAppUiAvailable = aAvailable;  
       
  3918     }
       
  3919 
       
  3920 
       
  3921 // ---------------------------------------------------------------------------
       
  3922 // CCamAppController::GetZoomRange
       
  3923 // Returns the minimum and maximum supported zoom values
       
  3924 // ---------------------------------------------------------------------------
       
  3925 //
       
  3926 void 
       
  3927 CCamAppController::GetZoomRange( TInt& aMinZoom, TInt& aMaxZoom ) const
       
  3928   {
       
  3929   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  3930   aMinZoom = 0;
       
  3931   aMaxZoom = iCameraController->CameraInfo().iMaxDigitalZoom;
       
  3932   }
       
  3933 
       
  3934 // ---------------------------------------------------------------------------
       
  3935 // CCamAppController::ZoomValue
       
  3936 // Returns the current zoom value
       
  3937 // ---------------------------------------------------------------------------
       
  3938 //
       
  3939 TInt 
       
  3940 CCamAppController::ZoomValue() const
       
  3941   {       
       
  3942   return iDesiredZoomVal;
       
  3943   }
       
  3944 
       
  3945 // ---------------------------------------------------------------------------
       
  3946 // CCamAppController::SetZoomValue
       
  3947 // Sets a new zoom value
       
  3948 // ---------------------------------------------------------------------------
       
  3949 //
       
  3950 void CCamAppController::SetZoomValue( TInt aValue )
       
  3951   {
       
  3952   PRINT1( _L("Camera => CCamAppController::SetZoomValue( %d )"), aValue );
       
  3953   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  3954 
       
  3955   // Check the requested value for validity
       
  3956   __ASSERT_DEBUG( Rng( 0, aValue, iCameraController->CameraInfo().iMaxDigitalZoom ), 
       
  3957                   CamPanic( ECamPanicInvalidZoomValue ) );
       
  3958   
       
  3959   if ( ECamControllerImage == iInfo.iMode
       
  3960     || ECamControllerVideo == iInfo.iMode )
       
  3961     {
       
  3962     // Setting provider asks for the zoom value from us
       
  3963     iDesiredZoomVal = aValue;
       
  3964 
       
  3965     if ( !iZoomWaitingForCamera )
       
  3966       {
       
  3967       PRINT( _L("Camera <> CCamAppController: calling Camera Controller..") );
       
  3968       
       
  3969       TRAPD( error,
       
  3970         {
       
  3971         iCameraController->DirectSettingsChangeL( ECameraSettingDigitalZoom );
       
  3972         });
       
  3973 
       
  3974       // If no leave occurred, notification is done in HandleSettingEventL
       
  3975       if( KErrNone != error )
       
  3976         {
       
  3977         NotifyControllerObservers( ECamEventZoomStateChanged, error );
       
  3978         }
       
  3979 
       
  3980       // iZoomWaitingForCamera is set to EFalse when vf frame arrives.
       
  3981       // With direct vf, this never happens, so do not set to ETrue.
       
  3982       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3983       if ( appUi && !appUi->IsDirectViewfinderActive() )
       
  3984         {
       
  3985         iZoomWaitingForCamera = ETrue;
       
  3986         }
       
  3987       iNewZoomPending = EFalse;
       
  3988       }
       
  3989     else
       
  3990       {
       
  3991       PRINT( _L("Camera <> CCamAppController: zoom is waiting for VF update") );
       
  3992       iNewZoomPending = ETrue;
       
  3993       }
       
  3994     }
       
  3995   PRINT( _L("Camera <= CCamAppController::SetZoomValue") );
       
  3996   }
       
  3997 
       
  3998 
       
  3999 
       
  4000 // ---------------------------------------------------------------------------
       
  4001 // CCamAppController::ResetUserSceneL
       
  4002 // Resets all the user scene settings to their defaults.
       
  4003 // ---------------------------------------------------------------------------
       
  4004 //
       
  4005 void CCamAppController::ResetUserSceneL()
       
  4006     {
       
  4007     iSettingsModel->ResetUserSceneL();
       
  4008     }
       
  4009 
       
  4010 // ---------------------------------------------------------------------------
       
  4011 // CCamAppController::PreviewSettingChangeL
       
  4012 // 
       
  4013 // Previews a new value for the specified integer setting.
       
  4014 // If method leaves, preview is not activated.
       
  4015 // ---------------------------------------------------------------------------
       
  4016 //
       
  4017 void 
       
  4018 CCamAppController::PreviewSettingChangeL( TInt aSettingItem, 
       
  4019                                           TInt aSettingValue )
       
  4020   {
       
  4021   PRINT( _L("Camera => CCamAppController::PreviewSettingChangeL") );
       
  4022   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4023   
       
  4024   TCamSettingItemIds settingId( 
       
  4025       static_cast<TCamSettingItemIds>(aSettingItem) );
       
  4026 
       
  4027   PRINT1( _L("Camera <> Setting to be previewed [%s]"), KCamSettingItemNames[settingId] );
       
  4028 
       
  4029   if ( settingId == ECamSettingItemDynamicSelfTimer )
       
  4030       {
       
  4031       SetSlideInSelfTimerPreview(ETrue);
       
  4032       }
       
  4033 
       
  4034   // Activate the preview as a first thing.
       
  4035   // If requests are issued to Camera Controller,
       
  4036   // it asks for the setting value through Setting Provider and
       
  4037   // the setting needs to be already in preview at that point.
       
  4038   // If this fails, there's nothing we need to roll back.
       
  4039   iSettingsPreviewHandler->ActivatePreviewL( settingId, aSettingValue );
       
  4040 
       
  4041 
       
  4042   // Check which setting is previewed.
       
  4043   // Some need special attention, or should/need not be set to Camera at this point.
       
  4044   TInt status( KErrNone );
       
  4045   switch( settingId )
       
  4046     {
       
  4047     // ---------------------------------
       
  4048     // Image quality
       
  4049     case ECamSettingItemPhotoQuality:
       
  4050       // Still image quality does not require re-prepare,
       
  4051       // as even the remining images counting is done 
       
  4052       // based on local size esimates.
       
  4053       // Need to do notification to update counters.
       
  4054       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4055       break;
       
  4056     // ---------------------------------
       
  4057     // Video quality
       
  4058     case ECamSettingItemVideoQuality:
       
  4059       // Video needs to be re-prepared to be able to update
       
  4060       // remaining time counters.
       
  4061       NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4062       break;
       
  4063     // ---------------------------------
       
  4064     // Self timer
       
  4065     case ECamSettingItemDynamicSelfTimer:
       
  4066       // Just set the preview. Once committed, set via AppUi.
       
  4067       break;
       
  4068     // ---------------------------------
       
  4069     // Others - set to Camera to see the effect.
       
  4070     default:
       
  4071       {
       
  4072       TCamCameraSettingId cameraId( 
       
  4073         CCamSettingConversion::Map2CameraControllerSettingId( settingId ) );
       
  4074 
       
  4075       //PRINT1( _L("Camera <> CCamAppController: Setting the preview to Camera, id[%s]"), KCameraSettingNames[settingId] );
       
  4076 
       
  4077       // Assertation to notice if some setting is not properly handled.
       
  4078       __ASSERT_DEBUG( ECameraSettingNone != cameraId, CamPanic( ECamPanicNotSupported ) );
       
  4079       
       
  4080       if( ECameraSettingNone != cameraId )
       
  4081         {
       
  4082         // Preview is active.
       
  4083         // Camera controller will ask the value during DirectSettingsChangeL.
       
  4084         // Need trap to be able to cancel on failure.
       
  4085         TRAP( status, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4086         }      
       
  4087       break;
       
  4088       }
       
  4089     // ---------------------------------
       
  4090     }
       
  4091 
       
  4092   if( KErrNone != status )
       
  4093     {
       
  4094     PRINT( _L("Camera <> CCamAppController: Problem in preview, cancelling!!!") );     
       
  4095 
       
  4096     // Invalid id does not cause problem here.
       
  4097     iSettingsPreviewHandler->CancelPreview( settingId );
       
  4098     User::Leave( status );
       
  4099     }
       
  4100   PRINT( _L("Camera <= CCamAppController::PreviewSettingChangeL") );
       
  4101   }
       
  4102 
       
  4103 // ---------------------------------------------------------------------------
       
  4104 // CCamAppController::CancelPreviewChangesL
       
  4105 // Cancels all preview changes, since last commit/cancel.
       
  4106 // ---------------------------------------------------------------------------
       
  4107 //
       
  4108 void
       
  4109 CCamAppController::CancelPreviewChangesL()
       
  4110   {
       
  4111   PRINT( _L("Camera => CCamAppController::CancelPreviewChangesL") );
       
  4112 
       
  4113   // Just check non-null, but no panic. 
       
  4114   if ( iSettingsPreviewHandler )
       
  4115     {
       
  4116     RArray<TCamSettingItemIds> previews;
       
  4117     CleanupClosePushL( previews );
       
  4118 
       
  4119     // Get all active previews
       
  4120     iSettingsPreviewHandler->ActivePreviewsL( previews );
       
  4121     // Reset all previews so the Setting Provider does
       
  4122     // not get those values anymore.
       
  4123     iSettingsPreviewHandler->CancelAllPreviews();
       
  4124 
       
  4125     // Reset the original setting values to Camera
       
  4126     TInt                errorOne( KErrNone           );
       
  4127     TInt                errorAll( KErrNone           );    
       
  4128     TCamCameraSettingId cameraId( ECameraSettingNone );
       
  4129     for( TInt i = previews.Count() - 1; i >= 0; i-- )
       
  4130       {
       
  4131       if( ECamSettingItemVideoQuality == previews[i] )
       
  4132         {
       
  4133         TRAP( errorOne, RePrepareVideoL() );
       
  4134         }
       
  4135       else
       
  4136         {
       
  4137         cameraId =
       
  4138           CCamSettingConversion::Map2CameraControllerSettingId( previews[i] );
       
  4139       
       
  4140         if( ECameraSettingNone != cameraId )
       
  4141           {
       
  4142           TRAP( errorOne, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4143           }
       
  4144         /* All previews are not set to Camera.
       
  4145         else
       
  4146           {
       
  4147           errorOne = KErrNotSupported;
       
  4148           }
       
  4149         */
       
  4150         }
       
  4151 
       
  4152       if( KErrNone == errorAll 
       
  4153        && KErrNone != errorOne )
       
  4154         {
       
  4155         errorAll = errorOne;
       
  4156         }
       
  4157       }
       
  4158     User::LeaveIfError( errorAll );
       
  4159 
       
  4160     CleanupStack::PopAndDestroy(); // previews
       
  4161     }
       
  4162   PRINT( _L("Camera <= CCamAppController::CancelPreviewChangesL") );
       
  4163   }
       
  4164 
       
  4165 // ---------------------------------------------------------------------------
       
  4166 // CCamAppController::CommitPreviewChanges
       
  4167 // Commits last preview change.
       
  4168 // ---------------------------------------------------------------------------
       
  4169 //
       
  4170 void 
       
  4171 CCamAppController::CommitPreviewChanges()
       
  4172   {
       
  4173   PRINT( _L("Camera => CCamAppController::CommitPreviewChanges") );
       
  4174   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4175 
       
  4176   // All previews have been set to Camera already.
       
  4177   // Only need to request the model to store new values.
       
  4178   // Currently ignore error, if settings model cannot save the preview.
       
  4179   TRAPD( error, iSettingsPreviewHandler->CommitAllPreviewsL() );
       
  4180   if( KErrNone != error )
       
  4181     {
       
  4182     // Ignored.
       
  4183     PRINT( _L("Camera <> Settings model could not save the preview!!!") );
       
  4184     }
       
  4185   PRINT( _L("Camera <= CCamAppController::CommitPreviewChanges") );
       
  4186   }
       
  4187 
       
  4188 
       
  4189 // ---------------------------------------------------------------------------
       
  4190 // RePrepareVideoL
       
  4191 //
       
  4192 // Helper method for re-preparing video if e.g. a setting change
       
  4193 // requires it. If Camera Controller is currently processing
       
  4194 // some request, set the flag to issue the request later.
       
  4195 //
       
  4196 // Used atleast in PreviewSettingChangeL and CancelPreviewChangesL.
       
  4197 // ---------------------------------------------------------------------------
       
  4198 //
       
  4199 void
       
  4200 CCamAppController::RePrepareVideoL()
       
  4201   {
       
  4202   PRINT( _L("Camera => CCamAppController::RePrepareVideoL") );
       
  4203 
       
  4204   GenerateNextValidVideoPathL();
       
  4205   if( !Busy() )
       
  4206     {
       
  4207     iVideoPrepareNeeded = EFalse;
       
  4208     IssueRequestL( ECamRequestVideoInit );
       
  4209     }
       
  4210   else
       
  4211     {
       
  4212     iVideoPrepareNeeded = ETrue;
       
  4213     }
       
  4214   PRINT( _L("Camera <= CCamAppController::RePrepareVideoL") );
       
  4215   }
       
  4216 
       
  4217 
       
  4218 
       
  4219 // ---------------------------------------------------------------------------
       
  4220 // CCamAppController::IntegerSettingValue
       
  4221 // Returns the current integer value for the specified setting
       
  4222 // ---------------------------------------------------------------------------
       
  4223 //
       
  4224 TInt 
       
  4225 CCamAppController::IntegerSettingValue( TInt aSettingItem ) const
       
  4226   {
       
  4227   // If the requested item is the photo storage location, this must be filtered
       
  4228   // based on the availability of the MMC.
       
  4229   if ( aSettingItem == ECamSettingItemPhotoMediaStorage )
       
  4230     {
       
  4231     return CurrentPhotoStorageLocation();
       
  4232     }
       
  4233 
       
  4234   // If the requested item is the video storage location, this must be filtered
       
  4235   // based on the availability of the MMC.
       
  4236   if ( aSettingItem == ECamSettingItemVideoMediaStorage )
       
  4237     {
       
  4238     return CurrentVideoStorageLocation();
       
  4239     }
       
  4240 
       
  4241   // Not a setting we sometimes need to filter
       
  4242   return IntegerSettingValueUnfiltered( aSettingItem );
       
  4243   }
       
  4244 
       
  4245 // ---------------------------------------------------------------------------
       
  4246 // CCamAppController::IntegerSettingValueUnfiltered
       
  4247 // Returns the current integer value for the specified setting
       
  4248 // ---------------------------------------------------------------------------
       
  4249 //
       
  4250 TInt 
       
  4251 CCamAppController::IntegerSettingValueUnfiltered( TInt aSettingItem ) const
       
  4252   {
       
  4253   if( aSettingItem == ECamSettingItemVideoFileType )
       
  4254     {
       
  4255     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  4256   
       
  4257     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];
       
  4258   
       
  4259     return level.VideoType();
       
  4260     }
       
  4261   // Query the relevant settings model.
       
  4262   return iSettingsModel->IntegerSettingValue( aSettingItem );
       
  4263   }
       
  4264 
       
  4265 // ---------------------------------------------------------------------------
       
  4266 // CCamAppController::SetIntegerSettingValueL
       
  4267 // Sets a new value for the specified integer setting
       
  4268 // ---------------------------------------------------------------------------
       
  4269 //
       
  4270 void 
       
  4271 CCamAppController::SetIntegerSettingValueL( TInt aSettingItem, 
       
  4272                                             TInt aSettingValue )
       
  4273   {
       
  4274   PRINT( _L("Camera => CCamAppController::SetIntegerSettingValueL"))
       
  4275   // Update the settings model.
       
  4276   iSettingsModel->SetIntegerSettingValueL( aSettingItem, aSettingValue );
       
  4277 
       
  4278   // Update observers with any changes that do not directly affect the
       
  4279   // engine. That is, they need to be updated now because the settings model
       
  4280   // will not pass these to this observer.
       
  4281   switch( aSettingItem )
       
  4282     {
       
  4283     case ECamSettingItemPhotoMediaStorage:
       
  4284     case ECamSettingItemVideoMediaStorage:
       
  4285       {
       
  4286       PRINT(_L("Camera SetIntegerSettingValueL calling SetPathnamesToNewStorageL" ))
       
  4287       // reset iForceUseOfPhoneMemory flag when user chooses 
       
  4288       // from settings.
       
  4289       iForceUseOfPhoneMemory = EFalse;
       
  4290       SetPathnamesToNewStorageL(static_cast < TCamMediaStorage > ( aSettingValue ) );
       
  4291       InitCaptureLimitL();
       
  4292       break;
       
  4293       }
       
  4294     case ECamSettingItemDynamicVideoScene:
       
  4295       {
       
  4296       iVideoInitNeeded = ETrue;
       
  4297       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4298       break;
       
  4299       }
       
  4300     case ECamSettingItemDynamicPhotoScene:
       
  4301     case ECamSettingItemUserSceneBasedOnScene:
       
  4302       {
       
  4303       if( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  4304         {
       
  4305         // Check for macro or landscape scene/based on scene and
       
  4306         // set up AF accordingly. For other scenes, the AF mode
       
  4307         // is setup at capture
       
  4308         CheckAfModeForScene();
       
  4309         }
       
  4310       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4311       break;
       
  4312       }
       
  4313     case ECamSettingItemVideoAudioRec:
       
  4314       {
       
  4315       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4316       if ( appUi->IsEmbedded() )
       
  4317         {
       
  4318         iCameraController->DirectSettingsChangeL( ECameraSettingAudioMute );
       
  4319         }
       
  4320       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4321       break;
       
  4322       }
       
  4323     case ECamSettingItemContinuousAutofocus:
       
  4324       {
       
  4325       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemContinuousAutofocus );
       
  4326       IssueSettingsChangeRequestL();
       
  4327       break;
       
  4328       }
       
  4329     case ECamSettingItemPhotoStoreInAlbum:
       
  4330     case ECamSettingItemVideoStoreInAlbum:
       
  4331       {
       
  4332       TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4333               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4334 
       
  4335       iImageSaveActive->SetAddImageToAlbum( aSettingValue == ECamSettYes,
       
  4336                                             defaultAlbumId );
       
  4337       break;
       
  4338       }
       
  4339     case ECamSettingItemRecLocation:
       
  4340       {
       
  4341       // Set the location utility active object
       
  4342       if ( ECamLocationOff == aSettingValue )
       
  4343           {
       
  4344           StopLocationTrail();
       
  4345           }
       
  4346       else if ( ECamLocationOn == aSettingValue )
       
  4347           {
       
  4348           StartLocationTrailL();
       
  4349           }
       
  4350       
       
  4351       // Notify observers
       
  4352       NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4353       break;  
       
  4354       }
       
  4355     // Need to support more zoom settings.
       
  4356     // Digital/extended setting combined to 
       
  4357     // ECamSettingItemPhotoDigitalZoom and ECamSettingItemVideoDigitalZoom
       
  4358     case ECamSettingItemPhotoDigitalZoom:
       
  4359     case ECamSettingItemVideoDigitalZoom:
       
  4360       {
       
  4361       // Notify observers
       
  4362       NotifyControllerObservers( ECamEventZoomSetupChanged );
       
  4363       break;
       
  4364       }
       
  4365 
       
  4366     default:
       
  4367       {
       
  4368       // no action for others here
       
  4369       break;
       
  4370       }
       
  4371     }
       
  4372 
       
  4373   PRINT( _L("Camera <= CCamAppController::SetIntegerSettingValueL"))        
       
  4374   }
       
  4375 
       
  4376 
       
  4377 
       
  4378 // ---------------------------------------------------------------------------
       
  4379 // CCamAppController::SetPathnamesToNewStorageL
       
  4380 // Sets pathnames for video and image files to point to new storage
       
  4381 // ---------------------------------------------------------------------------
       
  4382 void CCamAppController::SetPathnamesToNewStorageL( TCamMediaStorage aMediaStorage )
       
  4383   {    
       
  4384   PRINT(_L("Camera => CCamAppController::SetPathnamesToNewStorageL" ))
       
  4385   
       
  4386   iSetNewPathnamesPending = ECamMediaStorageNone;
       
  4387   TFileName path;
       
  4388   
       
  4389   // If the engine is prepared for image capture then check that the required 
       
  4390   // image folder exists
       
  4391   if ( IsFlagOn( CameraControllerState(), ECamImageOn ) )
       
  4392     {
       
  4393     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4394                                      aMediaStorage, 
       
  4395                                      path, 
       
  4396                                      ECamControllerImage, 
       
  4397                                      EFalse ); 
       
  4398     iCurrentStorage = aMediaStorage;
       
  4399     }
       
  4400    
       
  4401   // If the engine is prepared for video capture then check that the required 
       
  4402   // month folder exists and set up the engine with the new video path, this
       
  4403   // will be adjusted with the appropriate month counter folder when video
       
  4404   // capture begins
       
  4405   else if ( IsFlagOn( CameraControllerState(), ECamVideoOn ) )
       
  4406     {
       
  4407     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4408                                      aMediaStorage, 
       
  4409                                      path, 
       
  4410                                      ECamControllerVideo, 
       
  4411                                      EFalse ); 
       
  4412      if( iInfo.iOperation != ECamCapturing    &&
       
  4413           iInfo.iOperation != ECamPausing      &&
       
  4414           iInfo.iOperation != ECamPaused       &&
       
  4415           iInfo.iOperation != ECamResuming   &&
       
  4416           iInfo.iOperation != ECamCompleting )
       
  4417       {
       
  4418        GenerateNextValidVideoPathL();
       
  4419       }
       
  4420     iCurrentStorage = aMediaStorage;
       
  4421     
       
  4422     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  4423     
       
  4424     if( !appUi->SettingsLaunchedFromCamera() )
       
  4425       {
       
  4426       // Set video name change pending and request setting it to camera controller.
       
  4427       if( iInfo.iOperation != ECamCapturing    &&
       
  4428           iInfo.iOperation != ECamPausing      &&
       
  4429           iInfo.iOperation != ECamPaused       &&
       
  4430           iInfo.iOperation != ECamResuming   &&
       
  4431           iInfo.iOperation != ECamCompleting )
       
  4432     	{
       
  4433         iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  4434         // Can't set the new pathname, if camera controller is busy.
       
  4435         if ( CameraControllerBusy() )
       
  4436           {
       
  4437           PRINT( _L("Camera <> Camera controller busy. New pathname not set. Set iSetNewPathnamesPending.") )
       
  4438           iSetNewPathnamesPending = aMediaStorage;
       
  4439           }
       
  4440         else
       
  4441           {
       
  4442           IssueSettingsChangeRequestL();
       
  4443           }
       
  4444     	}
       
  4445         
       
  4446       iVideoNameRetries   = KVideoNameRetryCount;    
       
  4447       //iVideoTimeRemaining = KMaxRecordingLength;
       
  4448       if( iInfo.iOperation == ECamCapturing    ||
       
  4449           iInfo.iOperation == ECamPausing      ||
       
  4450           iInfo.iOperation == ECamPaused       ||
       
  4451           iInfo.iOperation == ECamResuming     ||
       
  4452           iInfo.iOperation == ECamCompleting )
       
  4453         {          
       
  4454         iVideoTimeRemaining = iCameraController->RemainingVideoRecordingTime();  
       
  4455         }
       
  4456       else 
       
  4457         {
       
  4458         PRINT( _L("Camera <> CCamAppController::SetPathnamesToNewStorageL - video mode not yet initialized" ));
       
  4459         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  4460         if( KErrNone != err )
       
  4461           {
       
  4462           iVideoTimeRemaining = 0;
       
  4463           }
       
  4464         }
       
  4465       }
       
  4466     }
       
  4467     
       
  4468   // The engine is not yet prepared, the folder will be checked when the engine preparation
       
  4469   // takes place. The controller also checks the state of iSetNewPathnamesPending when 
       
  4470   // preparation completes, just in case preparation is currently in progress.
       
  4471   else
       
  4472     {
       
  4473     iSetNewPathnamesPending = aMediaStorage;
       
  4474     }  
       
  4475               
       
  4476   NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4477   PRINT(_L("Camera <= CCamAppController::SetPathnamesToNewStorageL" ))
       
  4478   }
       
  4479 
       
  4480 // ---------------------------------------------------------------------------
       
  4481 // CCamAppController::SetTextSettingValueL
       
  4482 // Sets a new text value for the specified setting
       
  4483 // ---------------------------------------------------------------------------
       
  4484 //
       
  4485 void 
       
  4486 CCamAppController::SetTextSettingValueL(       TInt   aSettingItem, 
       
  4487                                          const TDesC& aSettingValue )
       
  4488   {
       
  4489   // Update the relevant settings model.
       
  4490   iSettingsModel->SetTextSettingValueL( aSettingItem, aSettingValue );
       
  4491   }
       
  4492 
       
  4493 
       
  4494 // ---------------------------------------------------------------------------
       
  4495 // CCamAppController::TextSettingValue
       
  4496 // Returns the current text value for the specified setting
       
  4497 // ---------------------------------------------------------------------------
       
  4498 //
       
  4499 TPtrC 
       
  4500 CCamAppController::TextSettingValue( TInt aSettingItem ) const
       
  4501   {
       
  4502   // Query the relevant settings model.
       
  4503   return iSettingsModel->TextSettingValue( aSettingItem );
       
  4504   }
       
  4505 
       
  4506 // ---------------------------------------------------------------------------
       
  4507 // CCamAppController::SettingValueEnabled
       
  4508 // Returns whether a particular setting value can be set or not.
       
  4509 // ---------------------------------------------------------------------------
       
  4510 //
       
  4511 TBool 
       
  4512 CCamAppController::SettingValueEnabled( TInt aSettingItem, 
       
  4513                                         TInt aSettingValue ) const 
       
  4514   {
       
  4515   return iSettingsModel->SettingValueEnabled( aSettingItem, aSettingValue );
       
  4516   }
       
  4517 
       
  4518 // ---------------------------------------------------------------------------
       
  4519 // CCamAppController::LoadStaticSettingsL
       
  4520 // Loads the static settings from shared data
       
  4521 // ---------------------------------------------------------------------------
       
  4522 //
       
  4523 void 
       
  4524 CCamAppController::LoadStaticSettingsL( TBool aIsEmbedded )
       
  4525   {
       
  4526   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 1" );
       
  4527   PRINT(_L("Camera => CCamAppController::LoadStaticSettingsL" ))
       
  4528   iSettingsModel->LoadStaticSettingsL( aIsEmbedded );
       
  4529   
       
  4530   // Cache the image 'add to album' setting in the saving active object
       
  4531   // it will change infrequently
       
  4532   TInt value = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoStoreInAlbum );
       
  4533   
       
  4534   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4535               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4536   iImageSaveActive->SetAddImageToAlbum( value == ECamSettYes,
       
  4537                                         defaultAlbumId );
       
  4538 
       
  4539   // Ensure that the navipane is upto date with the current save location.
       
  4540   if ( !aIsEmbedded )
       
  4541     {
       
  4542     NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4543     NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4544     }
       
  4545     NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4546     NotifyControllerObservers( ECamEventVideoStabChanged );
       
  4547     if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
  4548         {
       
  4549         NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4550         }
       
  4551     NotifyControllerObservers( ECamEventVideoFileTypeChanged );
       
  4552   NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4553   NotifyControllerObservers( ECamEventContAFStateChanged ); 
       
  4554   PRINT(_L("Camera <= CCamAppController::LoadStaticSettingsL" ))
       
  4555   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 0" );
       
  4556   }
       
  4557 
       
  4558 
       
  4559 // ---------------------------------------------------------------------------
       
  4560 // DynamicSettingDefaultValue
       
  4561 // Get the setting default value.
       
  4562 // ---------------------------------------------------------------------------
       
  4563 //
       
  4564 TInt 
       
  4565 CCamAppController::DynamicSettingDefaultValue( TInt aSettingId ) const
       
  4566   {
       
  4567   return iSettingsModel->DynamicSettingDefaultValue( aSettingId );
       
  4568   }
       
  4569 
       
  4570 // ---------------------------------------------------------------------------
       
  4571 // CCamAppController::SetDynamicSettingsToDefaults
       
  4572 // Sets all dynamic settings to their defaults.
       
  4573 // ---------------------------------------------------------------------------
       
  4574 //
       
  4575 void 
       
  4576 CCamAppController::SetDynamicSettingsToDefaults()
       
  4577   {
       
  4578   iSettingsModel->SetDynamicSettingsToDefaults();
       
  4579   }
       
  4580 
       
  4581 // ---------------------------------------------------------------------------
       
  4582 // CCamAppController::SetDynamicSettingsToDefaults
       
  4583 // Sets a dynamic setting to its default.
       
  4584 // ---------------------------------------------------------------------------
       
  4585 //
       
  4586 void 
       
  4587 CCamAppController::SetDynamicSettingToDefault(TInt aSettingItem)
       
  4588   {
       
  4589   iSettingsModel->SetDynamicSettingToDefault(aSettingItem);
       
  4590   }
       
  4591 
       
  4592 // ---------------------------------------------------------------------------
       
  4593 // SetDynamicSettingToSceneDefaultL
       
  4594 // 
       
  4595 // Set the dynamic setting identified by aSettingId to scene default.
       
  4596 // Because video and photo scenes can have sama identifiers, aVideoScene
       
  4597 // is needed to decide which ones to look for.
       
  4598 // ---------------------------------------------------------------------------
       
  4599 //
       
  4600 TInt
       
  4601 CCamAppController::SetDynamicSettingToSceneDefaultL( TInt  aSceneId,
       
  4602                                                      TInt  aSceneField,
       
  4603                                                      TInt  aSettingId,
       
  4604                                                      TBool aVideoScene )
       
  4605   {
       
  4606   return iSettingsModel->SetDynamicSettingToSceneDefaultL( aSceneId, 
       
  4607                                                            aSceneField, 
       
  4608                                                            aSettingId,
       
  4609                                                            aVideoScene );
       
  4610   }
       
  4611 
       
  4612 
       
  4613 
       
  4614 
       
  4615 #ifdef PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4616 // ---------------------------------------------------------------------------
       
  4617 // CCamAppController::VideoSceneDefaultsAreSet
       
  4618 // Returns whether the video setup settings are set to the defaults
       
  4619 // for its current scene.
       
  4620 // ---------------------------------------------------------------------------
       
  4621 //
       
  4622 TBool 
       
  4623 CCamAppController::VideoSceneDefaultsAreSet()
       
  4624     {
       
  4625     return iSettingsModel->VideoSceneDefaultsAreSet();
       
  4626     }
       
  4627 
       
  4628 // ---------------------------------------------------------------------------
       
  4629 // CCamAppController::PhotoSceneDefaultsAreSet
       
  4630 // Returns whether the photo setup settings are set to the defaults
       
  4631 // for its current scene.
       
  4632 // ---------------------------------------------------------------------------
       
  4633 //
       
  4634 TBool 
       
  4635 CCamAppController::PhotoSceneDefaultsAreSet()
       
  4636     {
       
  4637     return iSettingsModel->PhotoSceneDefaultsAreSet();
       
  4638     }
       
  4639 
       
  4640 #endif // PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4641 
       
  4642 
       
  4643 // ---------------------------------------------------------------------------
       
  4644 // CCamAppController::CurrentFullFileName
       
  4645 // ---------------------------------------------------------------------------
       
  4646 //
       
  4647 const TDesC& 
       
  4648 CCamAppController::CurrentFullFileName() const
       
  4649   {
       
  4650   PRINT1( _L("Camera => CCamAppController::CurrentFullFileName, index:%d"), iCurrentImageIndex );
       
  4651   const TDesC& name( BurstCaptureArray()->FileName( iCurrentImageIndex ) );
       
  4652 
       
  4653   if( name != KNullDesC )
       
  4654     {
       
  4655     PRINT1( _L("Camera <= CCamAppController::CurrentFullFileName, return:[%S]"), &name );
       
  4656     }
       
  4657   else
       
  4658     {
       
  4659     PRINT( _L("Camera <= CCamAppController::CurrentFullFileName, name not set.") ); 
       
  4660     }   
       
  4661   return name;
       
  4662   }
       
  4663 
       
  4664 const TDesC& 
       
  4665 CCamAppController::CurrentVideoFileName() const
       
  4666   {
       
  4667   return iSuggestedVideoPath;
       
  4668   }
       
  4669 
       
  4670 // ---------------------------------------------------------------------------
       
  4671 // CCamAppController::CCamAppController
       
  4672 // C++ default constructor can NOT contain any code, that
       
  4673 // might leave.
       
  4674 // ---------------------------------------------------------------------------
       
  4675 //
       
  4676 CCamAppController::CCamAppController()
       
  4677   : iBusyFlags( EBusyNone )
       
  4678   , iDiskCriticalLevel   ( KErrNotFound )
       
  4679   , iRamDiskCriticalLevel( KErrNotFound )
       
  4680   , iImageOrientation( ECamOrientation0 )
       
  4681   , iLastImageOrientation( ECamOrientation0 )
       
  4682   {
       
  4683   }
       
  4684 
       
  4685 // ---------------------------------------------------------------------------
       
  4686 // CCamAppController::ConstructL
       
  4687 // Symbian 2nd phase constructor can leave.
       
  4688 // ---------------------------------------------------------------------------
       
  4689 //
       
  4690 void CCamAppController::ConstructL()
       
  4691   {
       
  4692   PRINT( _L("Camera => CCamAppController::ConstructL"));
       
  4693   iPendingAFRequest=0;
       
  4694   iCurrentAFRequest=0;
       
  4695   iNoBurstCancel=EFalse;
       
  4696 
       
  4697   PRINT( _L("Camera <> CCamAppController::ConstructL - constructing Configuration Manager"));
       
  4698   iConfiguration = CCamConfiguration::NewL();      
       
  4699   
       
  4700  
       
  4701   CCamFolderUtility::ResetCounters( iMonthFolderCounters );
       
  4702   iCaptureKeyPressedWhileImageSaving = EFalse;
       
  4703 
       
  4704   iCaptureModeTransitionInProgress = ETrue;
       
  4705 
       
  4706   iSettingsModel = CCamSettingsModel::NewL( *iConfiguration );  
       
  4707   iSettingsModel->AttachObserverL( this );
       
  4708   
       
  4709   // Get the config pointer from settings model
       
  4710   iConfigManager = static_cast<CCamSettingsModel*>(iSettingsModel)->UiConfigManagerPtr();
       
  4711   
       
  4712   RArray<TInt> supportedValues;
       
  4713   CleanupClosePushL( supportedValues );
       
  4714     
       
  4715   // Get the EV slider info
       
  4716   // these values should be read before camsettingsprovided is constructd
       
  4717   // as the EV step value is needed during the construction of camsettingsprovider.
       
  4718   iConfigManager->SupportedEVSettingsL( supportedValues );
       
  4719 
       
  4720   if ( supportedValues.Count() > 0 )
       
  4721       {
       
  4722       iEvRange.iMinValue     = supportedValues[0];
       
  4723       iEvRange.iMaxValue     = supportedValues[1];
       
  4724       iEvRange.iStepsPerUnit = supportedValues[2];      
       
  4725       }
       
  4726 
       
  4727   CleanupStack::PopAndDestroy( &supportedValues );
       
  4728     
       
  4729   // The Settings Model handles the previews at the moment
       
  4730   iSettingsPreviewHandler = static_cast<CCamSettingsModel*>( iSettingsModel ); 
       
  4731 
       
  4732   //iSettingProvider = CCamConstantSettingProvider::NewL( *this );
       
  4733   iSettingProvider = CCamSettingProvider::NewL( *this, iSettingsModel );
       
  4734  
       
  4735   iDeepSleepTimer = CCamTimer::NewL( KDeepSleepTimeout, 
       
  4736                     TCallBack( CCamAppController::DeepSleepTimeout, this ) );
       
  4737   
       
  4738   iIdleTimer             = CCamTimer::NewL( KIdleTimeout, 
       
  4739                                             TCallBack( CCamAppController::IdleTimeoutL, this ) );
       
  4740   iImageSaveActive       = CCamImageSaveActive::NewL( *this , *this );        
       
  4741   iCaptureArray          = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4742   iRotationArray         = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4743   iSnapShotRotator       = CCamSnapShotRotator::NewL( *this );
       
  4744   iSequenceFilenameArray = new( ELeave ) CDesCArraySeg( KTimelapseArrayGranularity );
       
  4745   iSoundPlayer           = CCamAudioPlayerController::NewL( *this, *this );
       
  4746 
       
  4747   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  4748        {
       
  4749        // create property watcher for slide state
       
  4750        PRINT( _L("Camera <> CCamAppController: Define Camera slider P&S key..") );
       
  4751        
       
  4752        // Whole slider position reading could be removed after PCFW has implemented
       
  4753        // creation for KLensCoverStatus key
       
  4754        TInt sliderPosition;
       
  4755        TInt err = RProperty::Get(
       
  4756                    CameraPlatPSKeys::KPSCameraPlatUid,
       
  4757                    CameraPlatPSKeys::KLensCoverStatus,
       
  4758                    sliderPosition );  
       
  4759   
       
  4760  
       
  4761        if( err != KErrNone )
       
  4762            {
       
  4763            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4764                    NMusResourceApi::KCategoryUid, 
       
  4765                    NMusResourceApi::KCameraAvailability );
       
  4766            }
       
  4767        else
       
  4768            {
       
  4769            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4770                    CameraPlatPSKeys::KPSCameraPlatUid, 
       
  4771                    CameraPlatPSKeys::KLensCoverStatus );
       
  4772            }
       
  4773        }
       
  4774   
       
  4775   if ( iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
  4776       {
       
  4777       iKeyLockStatusWatcher  = CCamPropertyWatcher::NewL( *this,
       
  4778                                                           KPSUidAvkonDomain,
       
  4779                                                           KAknKeyguardStatus );      
       
  4780       }
       
  4781   // read central repository value indicating whether camera shutter sound
       
  4782   // should be played always or depending on the current profile setting
       
  4783   CRepository* cr = CRepository::NewLC( KCRUidCamcorderFeatures );
       
  4784   TInt value;
       
  4785   TInt err;
       
  4786   User::LeaveIfError( cr->Get( KCRCamShutterSound, value ) );
       
  4787   CleanupStack::PopAndDestroy( cr );
       
  4788   iShutterSndAlwaysOn = value;
       
  4789         
       
  4790   // get data for monitoring free RAM during sequence capture
       
  4791   CamUtility::GetPsiInt( ECamPsiSnapshotSize, iSnapshotDataSize );
       
  4792 
       
  4793   iConfiguration->GetPsiIntArrayL( ECamPsiJpegDataSizes, iJpegDataSizes );
       
  4794   iConfiguration->GetPsiIntArrayL( ECamPsiSequencePostProcessDataSizes,
       
  4795                                    iSequencePostProcessDataSizes );
       
  4796                                
       
  4797   if ( iConfigManager && iConfigManager->IsCaptureToneDelaySupported() )
       
  4798     {
       
  4799     TInt captureToneDelay = iConfigManager->CaptureToneDelay();
       
  4800     TCallBack captureToneCb( CCamAppController::CaptureToneDelayTimeout, this );
       
  4801     iCaptureToneDelayTimer = 
       
  4802         CCamTimer::NewL( captureToneDelay * KMicroSecsInMilliSec, 
       
  4803                          captureToneCb );
       
  4804     }
       
  4805 
       
  4806   PRINT( _L("Camera <> CCamAppController: Define Camera focused P&S key..") );
       
  4807   err = RProperty::Define( KPSUidCamcorderNotifier, 
       
  4808                                  KCCorFocused,
       
  4809                                  RProperty::EInt );
       
  4810   if ( KErrNone != err )
       
  4811     {
       
  4812     // Error handling. Remove warning.
       
  4813     }
       
  4814     
       
  4815   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() )
       
  4816       { // Publish zoom state
       
  4817       iContextFwClient = CCFClient::NewL( *this );
       
  4818       
       
  4819       // Defining the context using the Context Framework.
       
  4820       err = iContextFwClient->DefineContext(
       
  4821                                             KCamContextSource,
       
  4822                                             KCamContextType,
       
  4823                                             KCamContextSecurity );
       
  4824       if( KErrNone == err )
       
  4825         {
       
  4826         iDefineContextSuccessful = ETrue;
       
  4827         PublishZoomStateL( EFalse );
       
  4828         }
       
  4829       else
       
  4830         {
       
  4831         // We make sure that we dont proceed with publishing the zoom state
       
  4832         // if the context definition fails.
       
  4833         iDefineContextSuccessful = EFalse;
       
  4834         }      
       
  4835       } // Publish zoom state
       
  4836 
       
  4837   iLocationTrailStarted = EFalse;
       
  4838 
       
  4839   CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, iLongSequenceLimit );
       
  4840 
       
  4841   User::LeaveIfError( iFs.Connect() ); 
       
  4842   iDriveChangeNotifier = CCamDriveChangeNotifier::NewL( iFs, *this ); 
       
  4843 
       
  4844   PRINT( _L("Camera <= CCamAppController::ConstructL"));
       
  4845   }
       
  4846 
       
  4847 
       
  4848 
       
  4849 /*
       
  4850 * CCamAppController::PublishZoomStateL
       
  4851 */
       
  4852 void CCamAppController::PublishZoomStateL( const TBool aEnabled )
       
  4853   {
       
  4854   // We publish the zoom state only when context definition is
       
  4855   // successful. the value of the zoom state is controlled by the
       
  4856   // boolean flag "aEnabled".
       
  4857   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() ) 
       
  4858       {
       
  4859       if ( iDefineContextSuccessful )
       
  4860         {
       
  4861         CCFContextQuery* query = CCFContextQuery::NewLC();
       
  4862         query->SetSourceL( KCamContextSource );
       
  4863         query->SetTypeL( KCamContextType );
       
  4864         RContextObjectArray result;
       
  4865         TInt err = iContextFwClient->RequestContext( *query, result );
       
  4866         if( err == KErrNone  && result.Count() > 0 )
       
  4867             {
       
  4868             if ( aEnabled )
       
  4869                 {
       
  4870                 result[0]->SetValueL( KCamContextValueEnable );
       
  4871                 }
       
  4872             else
       
  4873                 {
       
  4874                 result[0]->SetValueL( KCamContextValueDisable );
       
  4875                 }
       
  4876             TInt err = iContextFwClient->PublishContext( *result[0] );
       
  4877             if ( err != KErrNone )
       
  4878                 {
       
  4879                 // Define how to handle the error case.
       
  4880                 }
       
  4881             }
       
  4882         else
       
  4883             {
       
  4884             // ignoring the error case.
       
  4885             }
       
  4886             result.ResetAndDestroy();
       
  4887             CleanupStack::PopAndDestroy( query );
       
  4888         }      
       
  4889       }
       
  4890   }
       
  4891 
       
  4892 
       
  4893    
       
  4894 // ---------------------------------------------------------------------------
       
  4895 // CCamAppController::IsViewFinding
       
  4896 // Check if viewfinder is active
       
  4897 // ---------------------------------------------------------------------------
       
  4898 //
       
  4899 TBool CCamAppController::IsViewFinding() const
       
  4900   {
       
  4901   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  4902   return ( iCameraController
       
  4903         && iCameraController->ViewfinderState() == ECamTriActive );
       
  4904   }
       
  4905     
       
  4906 
       
  4907 
       
  4908 // ---------------------------------------------------------------------------
       
  4909 // CCamAppController::NotifyControllerObservers
       
  4910 // Notify the controller observers that a new controller event has occurred
       
  4911 // ---------------------------------------------------------------------------
       
  4912 //
       
  4913 void 
       
  4914 CCamAppController
       
  4915 ::NotifyControllerObservers( TCamControllerEvent aEvent,
       
  4916                              TInt                aError ) const
       
  4917   {
       
  4918   PRINT( _L("Camera => CCamAppController::NotifyControllerObservers"));
       
  4919   // We might need to stop notification for some time.
       
  4920   if( !iMuteNotifications )
       
  4921     {
       
  4922     for ( TInt i = 0; i < iControllerObservers.Count(); i++ )
       
  4923       {
       
  4924       // NON-NULL checked when adding observers.
       
  4925       // If the notification leaves, continue for the other observers
       
  4926       TRAP_IGNORE( iControllerObservers[i]->HandleControllerEventL( aEvent, aError ) )
       
  4927       }
       
  4928     }
       
  4929   PRINT( _L("Camera <= CCamAppController::NotifyControllerObservers"));
       
  4930   }
       
  4931 
       
  4932 
       
  4933 
       
  4934 // ---------------------------------------------------------------------------
       
  4935 // ---------------------------------------------------------------------------
       
  4936 //
       
  4937 void 
       
  4938 CCamAppController
       
  4939 ::EnterViewfinderMode( const TCamCameraMode& aMode )
       
  4940   {
       
  4941   PRINT( _L("Camera => CCamAppController::EnterViewfinderMode"));
       
  4942 
       
  4943   TInt error( KErrNone );
       
  4944   iPendingRelease = EFalse;
       
  4945 
       
  4946   // start monitoring mmc dismount notifications
       
  4947   StartDismountMonitoring();
       
  4948   
       
  4949   if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  4950       {
       
  4951       TRAP_IGNORE ( PublishZoomStateL( ETrue ) );
       
  4952       }
       
  4953 
       
  4954   // Clear these just in case some video prepare is pending.
       
  4955   iVideoPrepareNeeded = EFalse;
       
  4956 
       
  4957   
       
  4958   if( ECamControllerVideo == aMode )
       
  4959     {
       
  4960     // Filename generation needs to be done in all case, not only
       
  4961     // when the current path is null.  
       
  4962     // if( KNullDesC() == iSuggestedVideoPath )
       
  4963       {
       
  4964       TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  4965       }
       
  4966 
       
  4967     // Clear this to be sure it doesn't block recording
       
  4968     iVideoRequested = EFalse;
       
  4969     SetTargetMode     ( ECamControllerVideo  );
       
  4970     SetTargetImageMode( ECamImageCaptureNone );
       
  4971     // shutdown the orientation channel when going to videomode
       
  4972     if ( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  4973         {
       
  4974 	    TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  4975 		}
       
  4976     }
       
  4977   else if( ECamControllerImage == aMode )
       
  4978     {
       
  4979     SetTargetMode     ( ECamControllerImage    );
       
  4980 //    SetTargetImageMode( ECamImageCaptureSingle );
       
  4981     SetTargetImageMode( CurrentImageModeSetup() );
       
  4982     }
       
  4983   else
       
  4984     {
       
  4985     SetOperation( ECamStandby, KErrGeneral );
       
  4986     return;
       
  4987     }
       
  4988 
       
  4989   iInfo.iTargetVfState = ECamTriActive;
       
  4990   if( !Busy() )
       
  4991     {
       
  4992     TRAP( error, IssueModeChangeSequenceL() );
       
  4993     if ( KErrNone    != error
       
  4994       && ECamStandby != iInfo.iOperation )
       
  4995       {
       
  4996       SetOperation( ECamStandby, error );
       
  4997       }
       
  4998     }
       
  4999   else
       
  5000     {
       
  5001     // operation will continue when busy sequence or request completes
       
  5002     }
       
  5003   PRINT( _L("Camera <= CCamAppController::EnterViewfinderMode"));
       
  5004   }
       
  5005 
       
  5006 // ---------------------------------------------------------------------------
       
  5007 // ---------------------------------------------------------------------------
       
  5008 //
       
  5009 void 
       
  5010 CCamAppController::ExitViewfinderMode( const TCamCameraMode& aMode )
       
  5011   {
       
  5012   PRINT( _L("Camera => CCamAppController::ExitViewfinderMode"));
       
  5013   // The check here is to ensure that the viewfinder isn't stopped by the still precapture
       
  5014   // view when it has just lost the foreground to the video precapture view and vice versa.
       
  5015   // In that case the mode in parameter would not match the target mode.
       
  5016   if( iInfo.iOperation != ECamStandby )
       
  5017     {
       
  5018     if ( aMode == iInfo.iTargetMode )
       
  5019       {
       
  5020       iInfo.iTargetVfState = ECamTriIdle;
       
  5021       SetTargetImageMode( ECamImageCaptureNone );
       
  5022   
       
  5023       if( !Busy() )
       
  5024         {
       
  5025         if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  5026             {
       
  5027             TRAP_IGNORE ( PublishZoomStateL( EFalse ) );            
       
  5028             }
       
  5029         TRAPD( error, IssueDirectRequestL( ECamRequestVfRelease ) );
       
  5030         if ( KErrNone             != error
       
  5031           && ECamStandby != iInfo.iOperation )
       
  5032           {
       
  5033           SetOperation( ECamStandby, error );
       
  5034           }
       
  5035         }
       
  5036       else
       
  5037         {
       
  5038         // operation will continue when busy sequence or request completes
       
  5039         }
       
  5040       }
       
  5041     }
       
  5042   PRINT( _L("Camera <= CCamAppController::ExitViewfinderMode"));
       
  5043   }
       
  5044 
       
  5045 
       
  5046 // ---------------------------------------------------------------------------
       
  5047 // CCamAppController::StartViewFinder();
       
  5048 // Non-leaving version of StartViewFinderL() 
       
  5049 // ---------------------------------------------------------------------------
       
  5050 //
       
  5051 void 
       
  5052 CCamAppController::StartViewFinder()
       
  5053   {
       
  5054   PRINT( _L("Camera => CCamAppController::StartViewFinder" ))
       
  5055   iInfo.iTargetVfState = ECamTriActive; 
       
  5056 
       
  5057   if( !Busy() )
       
  5058     {
       
  5059     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STARTVIEWFINDER, "e_CAM_APP_VF_INIT 0" );   //CCORAPP_APP_VF_INIT_END
       
  5060     OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STARTVIEWFINDER, "e_CAM_APP_OVERLAY_INIT 0" ); //CCORAPP_APP_OVERLAY_INIT_END
       
  5061     
       
  5062     TRAPD( error, IssueDirectRequestL( ECamRequestVfStart ) );
       
  5063     if ( KErrNone    != error
       
  5064       && ECamStandby != iInfo.iOperation )
       
  5065       {
       
  5066       PRINT( _L("Camera <> CCamAppController::StartViewFinder - [ERROR] VF start failed, go to standby" ))
       
  5067       SetOperation( ECamStandby, error );
       
  5068       }
       
  5069     }
       
  5070   else
       
  5071     {
       
  5072     // Vf started at earliest convenient time when ongoing requests finish.
       
  5073     }
       
  5074   PRINT(_L("Camera <= CCamAppController::StartViewFinder") );
       
  5075   }
       
  5076 
       
  5077 // ---------------------------------------------------------------------------
       
  5078 // StopViewFinder
       
  5079 // Stop the viewfinder immediately
       
  5080 // ---------------------------------------------------------------------------
       
  5081 //
       
  5082 void 
       
  5083 CCamAppController::StopViewFinder()
       
  5084   {
       
  5085   PRINT( _L("Camera => CCamAppController::StopViewFinderNow" ) )
       
  5086   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5087   
       
  5088   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5089 
       
  5090   if ( iBacklightTimer && iBacklightTimer->IsActive() )
       
  5091     {
       
  5092     iBacklightTimer->Cancel();
       
  5093     }
       
  5094   
       
  5095   // Only stop if active.
       
  5096   // Idle and inactive need no action at this point.
       
  5097   if( ECamTriActive == iCameraController->ViewfinderState() )
       
  5098     {
       
  5099     iInfo.iTargetVfState = ECamTriInactive;
       
  5100     
       
  5101     // Can only fail to OOM when state is checked.
       
  5102     TRAPD( error, iCameraController->DirectRequestL( ECamRequestVfStop ) );
       
  5103     if( KErrNone             != error 
       
  5104      && ECamStandby != iInfo.iOperation )
       
  5105       {
       
  5106       SetOperation( ECamStandby, error );
       
  5107       }
       
  5108     }
       
  5109     
       
  5110   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5111     
       
  5112   PRINT( _L("Camera <= CCamAppController::StopViewFinderNow" ) )
       
  5113   }
       
  5114 
       
  5115 // ---------------------------------------------------------------------------
       
  5116 // StopViewFinderEcam
       
  5117 // Stop the viewfinder immediately without changing states
       
  5118 // ---------------------------------------------------------------------------
       
  5119 //
       
  5120 void 
       
  5121 CCamAppController::StopViewFinderEcam()
       
  5122   {
       
  5123   PRINT( _L("Camera => CCamAppController::StopViewFinderEcam" ) )
       
  5124   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5125   
       
  5126   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5127   
       
  5128   // Trap and ignore error
       
  5129   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestVfStopEcam ) );
       
  5130   
       
  5131   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5132     
       
  5133   PRINT( _L("Camera <= CCamAppController::StopViewFinderEcam" ) )
       
  5134   }
       
  5135 
       
  5136 // ---------------------------------------------------------------------------
       
  5137 // CCamAppController::FreezeViewFinder
       
  5138 // Copy the next viewfinder frame then stop the viewfinder
       
  5139 // ---------------------------------------------------------------------------
       
  5140 //
       
  5141 void CCamAppController::FreezeViewFinder( TBool aFreeze )
       
  5142   {
       
  5143   // If the viewfinder needs to freeze
       
  5144   if ( aFreeze )
       
  5145     {
       
  5146     PERF_MESSAGE_L2( EPerfMessagePausingViewFinder );
       
  5147     iFreezeViewFinder  = ETrue;
       
  5148     iUpdateFrozenFrame = ETrue;
       
  5149     }
       
  5150   // Restarting the viewfinder
       
  5151   else 
       
  5152     {
       
  5153     iFreezeViewFinder  = EFalse;
       
  5154     iUpdateFrozenFrame = EFalse;
       
  5155     if ( ECamTriActive != iCameraController->ControllerInfo().iVfState )
       
  5156       {
       
  5157       StartViewFinder();
       
  5158       }
       
  5159     }
       
  5160   }
       
  5161 
       
  5162 
       
  5163 // ---------------------------------------------------------------------------
       
  5164 // CCamAppController::SetKeyUp
       
  5165 // Set  iKeyUP value which is used to determine if burst
       
  5166 // timer should be activated or not
       
  5167 // ---------------------------------------------------------------------------
       
  5168 //
       
  5169 void CCamAppController::SetKeyUp( TBool aValue /*= EFalse*/ )
       
  5170     {
       
  5171     PRINT1(_L("Camera => CCamAppController::SetKeyUp, iKeyUP=%d"), aValue );
       
  5172     iKeyUP=aValue; 
       
  5173     }
       
  5174 
       
  5175 // ---------------------------------------------------------------------------
       
  5176 // CCamAppController::DoCaptureL
       
  5177 // Initiate image capture
       
  5178 // ---------------------------------------------------------------------------
       
  5179 //
       
  5180 TBool CCamAppController::DoCaptureL()
       
  5181   {
       
  5182   PRINT( _L("Camera => CCamAppController::DoCaptureL()"));
       
  5183   PRINT2(_L("Camera <> mode[%s] imagemode[%s]"), KCamModeNames[iInfo.iMode], KCamImageModeNames[iInfo.iImageMode] );
       
  5184 
       
  5185   // ReleaseArray();
       
  5186   if( iImageSaveActive->Count() <= 0 )
       
  5187       {
       
  5188       ReleaseArray( ETrue );
       
  5189       }
       
  5190   iCurrentImageIndex = 0;
       
  5191   iArrayUsageCount   = KImageArrayUsers;
       
  5192 
       
  5193   iCameraWoken = EFalse;
       
  5194     
       
  5195   TBool continueWithCapture = ETrue;
       
  5196   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  5197   
       
  5198   // Capture needed as fast as possible.
       
  5199   // Use direct stopping of viewfinder
       
  5200   // unless there are settings pending,
       
  5201   // otherwise cancel capture
       
  5202   if ( !IsFlagOn( iBusyFlags, EBusySetting ) )
       
  5203       {
       
  5204       // Stop VF for burst mode or for secondary or
       
  5205       // embedded camera before capturing.
       
  5206       // VF stopping will increase capture lag.
       
  5207       if ( iInfo.iImageMode == ECamImageCaptureBurst ||
       
  5208            iInfo.iActiveCamera == ECamActiveCameraSecondary ||
       
  5209            appUi->IsEmbedded() )
       
  5210           {
       
  5211           StopViewFinder();
       
  5212           }
       
  5213       }
       
  5214   else
       
  5215       {
       
  5216       continueWithCapture = EFalse;
       
  5217       }
       
  5218   
       
  5219 
       
  5220   switch( iInfo.iImageMode )
       
  5221     {
       
  5222     // -----------------------------------------------------
       
  5223     // Burst capture
       
  5224     case ECamImageCaptureBurst:
       
  5225       {
       
  5226       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureBurst") );
       
  5227       /*
       
  5228       TCamPhotoSizeId sizeId( GetCurrentImageResolution() );
       
  5229 
       
  5230       TInt memoryNeed( iJpegDataSizes[sizeId]
       
  5231                      + iSequencePostProcessDataSizes[sizeId] 
       
  5232                      + iSnapshotDataSize );  
       
  5233       TInt memoryFree( 0 );
       
  5234       HAL::Get( HALData::EMemoryRAMFree, memoryFree ); // error ignored
       
  5235 
       
  5236       if( memoryFree < memoryNeed )
       
  5237         {      
       
  5238         PRINT( _L( "Camera <> Not enough memory for more burst captures - complete capture" ) );  
       
  5239         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5240         // Force re-prepare of engine
       
  5241         appUi->HandleCommandL( ECamCmdSequence );
       
  5242                 
       
  5243         // Display out of memory note
       
  5244         NotifyControllerObservers( ECamEventSnapshotReady, KErrNoMemory );
       
  5245                 
       
  5246         // Return app to burst precapture state from burst in-capture
       
  5247         SetOperation( ECamNoOperation );
       
  5248         NotifyControllerObservers( ECamEventCaptureComplete );  
       
  5249                 
       
  5250         // Force update of UI furniture
       
  5251         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5252         appUi->UpdateCba();
       
  5253 
       
  5254         iCaptureRequested = EFalse;
       
  5255         HandleCaptureCompletion();
       
  5256         continueWithCapture = EFalse;
       
  5257         }
       
  5258       else
       
  5259         {
       
  5260         iSequenceCaptureInProgress = ETrue;  
       
  5261         iActualBurstCount = 0;
       
  5262         FreezeViewFinder( ETrue );
       
  5263         // Stop the screensaver from coming on when burst mode is active
       
  5264         EnableScreenSaver( EFalse );
       
  5265         // Make navi counter update itself
       
  5266         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5267         }
       
  5268       */
       
  5269 
       
  5270       if( !appUi->SelfTimerEnabled() )
       
  5271         {
       
  5272         // Start timer to change burst mode to press and hold
       
  5273         // if not determined to be short burst before that.
       
  5274         
       
  5275         //One such case is if capturekeyup event has occured before
       
  5276         //DocaptureL method
       
  5277         if( !iKeyUP && !iNoBurstCancel )
       
  5278             {
       
  5279             StartBurstTimerL();            
       
  5280             }
       
  5281         }
       
  5282       iSequenceCaptureInProgress = ETrue;  
       
  5283        iValueIsStored = EFalse;
       
  5284       FreezeViewFinder( ETrue );
       
  5285       EnableScreenSaver( EFalse );
       
  5286 	  if(  iBacklightTimer 
       
  5287        && !iBacklightTimer->IsActive() )
       
  5288         {
       
  5289         iBacklightTimer->Start( 0,
       
  5290                                 KBacklighTimerInterval, 
       
  5291                                 TCallBack( ResetInactivityTimer, this ) );
       
  5292         }
       
  5293       NotifyControllerObservers( ECamEventCounterUpdated );
       
  5294 
       
  5295       break;
       
  5296       }
       
  5297     // -----------------------------------------------------
       
  5298     // Timelapse capture
       
  5299     case ECamImageCaptureTimeLapse:
       
  5300       {
       
  5301       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureTimeLapse") );
       
  5302       iSequenceCaptureInProgress = ETrue;  
       
  5303       // Stop the screensaver from coming on when burst mode is active
       
  5304       EnableScreenSaver( EFalse );
       
  5305             
       
  5306       // Get the remaining image count and only start the timer for the next capture if there is enough
       
  5307       // space, taking into account that the current capture will also use up one image     
       
  5308       TCamMediaStorage storage( (TCamMediaStorage)IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) );
       
  5309       TCamPhotoSizeId  sizeId ( GetCurrentImageResolution() );
       
  5310 
       
  5311       TInt remainingCount = ImagesRemaining( storage, ETrue, sizeId );
       
  5312 
       
  5313       // Check if the advanced sequence is limited (by starting from selftimer)
       
  5314       if( remainingCount  >= 1
       
  5315        && iRequestedCaptureCount <= TimeLapseImageCount()+1 )
       
  5316         {
       
  5317         iCompleteTimeLapsePending = ETrue;
       
  5318         }
       
  5319             
       
  5320       // if there isn't space for this capture (e.g. some memory has been used since the timer was initiated
       
  5321       // or there isn't enough space to initiate a further capture
       
  5322       else if ( remainingCount <= 1 )
       
  5323         {
       
  5324         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. only space for one capture, stop timer") );
       
  5325 
       
  5326         // The timer is no longer needed
       
  5327         if ( iTimeLapseTimer )
       
  5328           {
       
  5329           iTimeLapseTimer->Cancel();
       
  5330           delete iTimeLapseTimer;
       
  5331           iTimeLapseTimer = NULL;
       
  5332           }
       
  5333         // if there isn't even enough space for this capture
       
  5334         if ( remainingCount < 1 ) 
       
  5335           {
       
  5336           // complete the timelapse capture now (prevent the current capture from starting)
       
  5337           continueWithCapture = EFalse;
       
  5338           iArrayUsageCount = 0;
       
  5339           CompleteTimeLapseOperation();
       
  5340           }
       
  5341         else // if there isn't enough space to initiate a further capture
       
  5342           {
       
  5343           // ensure that the time lapse capture completes after the current capture
       
  5344           iCompleteTimeLapsePending = ETrue;
       
  5345           }                   
       
  5346         }
       
  5347             
       
  5348       else // there is space to initiate a further capture
       
  5349         {                
       
  5350         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. space for more than this capture, timer set on..") );
       
  5351         if ( !iTimeLapseTimer )
       
  5352           {
       
  5353           RestartTimeLapseTimerL();
       
  5354                 
       
  5355           //Products which support autofocus needs to reduce time for second picture
       
  5356           //about the time needed by autofocus.
       
  5357           if( iConfigManager && iConfigManager->IsAutoFocusSupported() 
       
  5358               && !CurrentSceneHasForcedFocus() )
       
  5359             {
       
  5360             iTimeLapseStartTime = iTimeLapseStartTime - TTimeIntervalSeconds( KFocusingDurationSeconds );
       
  5361             }
       
  5362           }
       
  5363         }
       
  5364       break;
       
  5365       }
       
  5366     // -----------------------------------------------------
       
  5367     // Single capture
       
  5368     case ECamImageCaptureSingle:
       
  5369       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureSingle") );
       
  5370       // Should not take so long to get the image captured and saved,
       
  5371       // but 
       
  5372       EnableScreenSaver( EFalse );
       
  5373       SetCaptureKeyPressedWhileImageSaving(EFalse);
       
  5374       break;
       
  5375     // -----------------------------------------------------
       
  5376     default:
       
  5377       PRINT(_L("Camera <> Not in any image capture mode, LEAVE!!"));
       
  5378       User::Leave( KErrGeneral );
       
  5379       break;
       
  5380     // -----------------------------------------------------
       
  5381     }
       
  5382 
       
  5383   if ( continueWithCapture )
       
  5384     {
       
  5385     IssueRequestL( ECamRequestImageCapture );
       
  5386     // Operation in progress is updated in HandleCameraEventL
       
  5387     // store the orientation at capture time, needed in thumbnail creation
       
  5388     iCaptureOrientation = iLastImageOrientation;
       
  5389     }
       
  5390 
       
  5391   iCaptureStoppedForUsb = EFalse; 
       
  5392   PRINT( _L("Camera <= CCamAppController::DoCaptureL()"));
       
  5393   return continueWithCapture;
       
  5394   }
       
  5395 
       
  5396 
       
  5397 // ---------------------------------------------------------------------------
       
  5398 // CCamAppController::DoRecord
       
  5399 // Initiate video recording
       
  5400 // ---------------------------------------------------------------------------
       
  5401 //
       
  5402 void CCamAppController::DoRecord()
       
  5403   {
       
  5404   PRINT( _L("Camera => CCamAppController::DoRecord") );
       
  5405   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  5406 
       
  5407   StopIdleTimer();
       
  5408 
       
  5409   // No key sounds when recording
       
  5410   TRAP_IGNORE( iSoundPlayer->DisableAllKeySoundsL() );
       
  5411 
       
  5412   PRINT( _L("Camera <> Requesting video capture start..") );
       
  5413   TRAPD( error, IssueRequestL( ECamRequestVideoStart ) );
       
  5414   PRINT1( _L("Camera <> ..request issued, status:%d"), error );
       
  5415 
       
  5416   if( KErrNone != error ) SetOperation( ECamStandby, error );    
       
  5417   else                    SetOperation( ECamCapturing );
       
  5418 
       
  5419   // Request is handled
       
  5420   iVideoRequested = EFalse;
       
  5421 
       
  5422   iCaptureStoppedForUsb = EFalse;
       
  5423   PRINT( _L("Camera <= CCamAppController::DoRecord") );
       
  5424   }
       
  5425 
       
  5426 
       
  5427 // ---------------------------------------------------------------------------
       
  5428 // CCamAppController::ReserveFileNamesL
       
  5429 // Reserve a set of filenames for a burst capture
       
  5430 // ---------------------------------------------------------------------------
       
  5431 //
       
  5432 void 
       
  5433 CCamAppController::ReserveFileNamesL( 
       
  5434     const TCamCameraMode&        aCaptureMode,
       
  5435     const TCamImageCaptureMode&  aImageMode,
       
  5436           TBool                  aForcePhoneMem /*= EFalse*/ )
       
  5437   {
       
  5438   PRINT( _L("Camera => CCamAppController::ReserveFileNamesL") )
       
  5439   TInt captureCount = 1;
       
  5440   TInt store        = ECamMediaStorageNone; 
       
  5441   TBuf<KMaxExtension> extension; 
       
  5442 
       
  5443   // If the next file will be a photo
       
  5444   if ( ECamControllerImage == aCaptureMode )
       
  5445     {         
       
  5446     extension = KImageExtension;
       
  5447     }
       
  5448   // Otherwise the next file will be a video
       
  5449   else
       
  5450     {
       
  5451 #ifndef __WINS__
       
  5452     TCamVideoFileType fileType = static_cast<TCamVideoFileType> 
       
  5453         ( IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5454         
       
  5455     extension = ( ECamVideoMpeg4 == fileType )
       
  5456                 ? KVideoMP4Extension
       
  5457                 : KVideo3GPExtension;
       
  5458 #else
       
  5459     extension = KVideo3GPExtension;
       
  5460 #endif
       
  5461     }
       
  5462 
       
  5463   store = ( ECamControllerImage == aCaptureMode ) ? 
       
  5464                  CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();
       
  5465 
       
  5466   TPath basePath;
       
  5467 
       
  5468   // Take a snapshot of the date - to ensure a sequence on a date boundary isn't split into
       
  5469   // different months
       
  5470   TTime now;
       
  5471   now.HomeTime();
       
  5472   // Need to check that there is enough space for the files. If this is a sequence of 20 images or 
       
  5473   // less then ensure there is enough space in the current folder, otherwise only one space is needed
       
  5474   TInt guaranteedGroup = 1;
       
  5475   if ( captureCount < CCamFolderUtility::KMaxGuaranteedBurstGroup )
       
  5476     {
       
  5477     guaranteedGroup = captureCount;
       
  5478     }
       
  5479   
       
  5480   // Leaves if errors generating the path
       
  5481   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5482                                    store, 
       
  5483                                    basePath, 
       
  5484                                    aCaptureMode, 
       
  5485                                    ETrue, 
       
  5486                                    guaranteedGroup, 
       
  5487                                    now ); 
       
  5488      
       
  5489   iCurrentStorage = static_cast<TCamMediaStorage>( store );  
       
  5490 //  TInt numberSettingId( KErrNotFound );
       
  5491   TInt typeSettingId( KErrNotFound );
       
  5492   TInt baseSettingId( KErrNotFound );
       
  5493   TInt counter( 0 );
       
  5494 
       
  5495   if( ECamControllerVideo == aCaptureMode )
       
  5496     {
       
  5497 //    numberSettingId = ECamSettingItemVideoNumber;
       
  5498     counter         = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5499     typeSettingId   = ECamSettingItemVideoNameBaseType;
       
  5500     baseSettingId   = ECamSettingItemVideoNameBase;
       
  5501     }
       
  5502   else
       
  5503     {
       
  5504 //    numberSettingId = ECamSettingItemPhotoNumber;
       
  5505     counter         = iImageNumberCache;
       
  5506     typeSettingId   = ECamSettingItemPhotoNameBaseType;
       
  5507     baseSettingId   = ECamSettingItemPhotoNameBase;
       
  5508     }
       
  5509 
       
  5510 //  TInt counter( IntegerSettingValue( numberSettingId ) );
       
  5511   TBuf<KCamMaxDateLen> dateNameBase;
       
  5512   TPtrC nameBase;
       
  5513   if ( ECamNameBaseDate == iSettingsModel->IntegerSettingValue( typeSettingId ) )
       
  5514       {       
       
  5515       CamUtility::FormatDateFileNameL( dateNameBase );
       
  5516       nameBase.Set( dateNameBase );
       
  5517       }
       
  5518     else
       
  5519       {
       
  5520       nameBase.Set( TextSettingValue( baseSettingId ) );
       
  5521       }
       
  5522 
       
  5523   RFs rfs;
       
  5524   User::LeaveIfError( rfs.Connect() );
       
  5525   CleanupClosePushL( rfs );        
       
  5526         
       
  5527   TEntry entry;
       
  5528 
       
  5529   TInt namedImages = 0;
       
  5530   while ( namedImages < captureCount )
       
  5531     {
       
  5532     // Generate new name
       
  5533     TFileName newFileName;
       
  5534 
       
  5535     CamUtility::FormatFileName( counter, nameBase, newFileName );
       
  5536 
       
  5537     TFileName newPath( basePath );
       
  5538     newPath.Append( newFileName );
       
  5539     newPath.Append( extension );
       
  5540 
       
  5541     // if there is no file in the current location with this name
       
  5542     TEntry entry;  // Prevent LINT error
       
  5543     TInt ferr = rfs.Entry( newPath, entry );
       
  5544     if ( KErrNotFound == ferr )
       
  5545       {
       
  5546       // A file with that name was not found, so the filename is okay.
       
  5547       PRINT( _L("Camera <> Filename OK.") )
       
  5548       namedImages++;
       
  5549       StoreNextFileNameL( newPath );
       
  5550           
       
  5551       // If this is time lapse capture then the full set of file names
       
  5552       // will be needed for the 'delete sequence' option. The burst capture array
       
  5553       // in timelapse only holds data for one item at a time so a separate array
       
  5554       // is used to keep track of all the images file names. The redundancy in filename
       
  5555       // storage is limited to a single file name.             
       
  5556       if ( ECamImageCaptureTimeLapse == aImageMode )         
       
  5557         {                                     
       
  5558         TRAP_IGNORE( iSequenceFilenameArray->AppendL( newPath ) );
       
  5559         // Update the images captured count
       
  5560         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5561         }
       
  5562       counter++;
       
  5563       }
       
  5564     else if ( KErrNone == ferr )
       
  5565       {
       
  5566       // A file with that name exists already. Increment the counter and try again.
       
  5567       PRINT( _L("Camera <> Filename already in use!") ) 
       
  5568       counter++;   // Try the next index number
       
  5569       }
       
  5570     else
       
  5571       {
       
  5572       // There was some other error. Can not save file -> Leave.
       
  5573       PRINT1( _L("Camera <> File server returned error: %d"), ferr );
       
  5574       User::Leave( ferr );
       
  5575       }
       
  5576       
       
  5577     }
       
  5578   CleanupStack::PopAndDestroy( &rfs );
       
  5579 
       
  5580   // SetIntegerSettingValueL( numberSettingId, counter );
       
  5581   if( ECamControllerVideo == aCaptureMode )
       
  5582     {
       
  5583     SetIntegerSettingValueL( ECamSettingItemVideoNumber, counter );
       
  5584     }
       
  5585   else
       
  5586     {
       
  5587     // SetIntegerSettingValueL called when capture ends. 
       
  5588     iImageNumberCache = counter;
       
  5589     }
       
  5590 
       
  5591   PRINT( _L("Camera <= CCamAppController::ReserveFileNamesL") )
       
  5592   }
       
  5593 
       
  5594     
       
  5595 // ---------------------------------------------------------------------------
       
  5596 // CCamAppController::CreateDummyFileL
       
  5597 // Create dummy file ready for image storage
       
  5598 // ---------------------------------------------------------------------------
       
  5599 //
       
  5600 TInt 
       
  5601 CCamAppController::CreateDummyFileL( RFs& aFs, const TDesC& aFullPath )
       
  5602   {
       
  5603   PRINT1( _L("Camera => CCamAppController::CreateDummyFileL [%S]"), &aFullPath );  
       
  5604   RFile file;
       
  5605   CleanupClosePushL( file );
       
  5606   
       
  5607   TInt err = file.Create( aFs, aFullPath, EFileWrite );
       
  5608   if ( err == KErrNone )
       
  5609     {
       
  5610     // Still image files are made writable and non-hidden
       
  5611     // just before the save operation
       
  5612     // file is set to hidden so that media gallery does not detect it
       
  5613     file.SetAtt( KEntryAttReadOnly|KEntryAttHidden, 0 );
       
  5614     }
       
  5615   
       
  5616   CleanupStack::PopAndDestroy( &file );
       
  5617   
       
  5618   PRINT1( _L("Camera <= CCamAppController::CreateDummyFileL, status:%d"), err );  
       
  5619   return err;
       
  5620   }
       
  5621   
       
  5622   
       
  5623 // ---------------------------------------------------------------------------
       
  5624 // CCamAppController::StoreNextFileNameL
       
  5625 // Add newly generated filename to array of names
       
  5626 // ---------------------------------------------------------------------------
       
  5627 //
       
  5628 void CCamAppController::StoreNextFileNameL( const TDesC& aFullPath )
       
  5629     {
       
  5630     PRINT( _L("Camera => CCamAppController::StoreNextFileNameL") );
       
  5631     TParse parse;
       
  5632     parse.Set( aFullPath, NULL, NULL );
       
  5633     
       
  5634     // Store the path + filename and plain filename for future reference
       
  5635     if( ECamControllerVideo == iInfo.iMode && BurstCaptureArray()->Count() > 0 )
       
  5636       {
       
  5637        BurstCaptureArray()->SetNameL( aFullPath, parse.Name(), 0 );	
       
  5638       }
       
  5639     else
       
  5640       {
       
  5641       BurstCaptureArray()->SetNextNameL( aFullPath, parse.Name() );		
       
  5642       }
       
  5643     
       
  5644     PRINT( _L("Camera <= CCamAppController::StoreNextFileNameL") );
       
  5645     }
       
  5646 
       
  5647 // ---------------------------------------------------------------------------
       
  5648 // CCamAppController::GenerateNextVideoFilePathL
       
  5649 // Generate a new file name and full path to save the next
       
  5650 // video 
       
  5651 // ---------------------------------------------------------------------------
       
  5652 //
       
  5653 void CCamAppController::GenerateNextVideoFilePathL( TBool aForcePhoneMem )
       
  5654   {
       
  5655   PRINT1( _L( "Camera => CCamAppController::GenerateNextVideoFilePathL, force phone mem:%d" ), aForcePhoneMem )    
       
  5656   TInt store = IntegerSettingValue( ECamSettingItemVideoMediaStorage ); 
       
  5657   
       
  5658   TBuf<KMaxExtension> extension;        
       
  5659 
       
  5660 #ifdef __WINS__
       
  5661   extension = KVideo3GPExtension;
       
  5662 #else
       
  5663   // If the video file type is MP3, then display this icon.
       
  5664   TCamVideoFileType fileType = 
       
  5665     static_cast<TCamVideoFileType>( 
       
  5666         IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5667 
       
  5668   extension = (fileType == ECamVideoMpeg4)
       
  5669             ? KVideoMP4Extension
       
  5670             : KVideo3GPExtension;
       
  5671 #endif
       
  5672   
       
  5673   TBuf<KCamMaxDateLen> dateNameBase;
       
  5674   TPtrC baseVideoName;
       
  5675           
       
  5676   if ( iSettingsModel->IntegerSettingValue( 
       
  5677                         ECamSettingItemVideoNameBaseType ) == ECamNameBaseDate )
       
  5678     {       
       
  5679     CamUtility::FormatDateFileNameL( dateNameBase );
       
  5680     baseVideoName.Set( dateNameBase );
       
  5681     }
       
  5682   else
       
  5683     {
       
  5684     baseVideoName.Set( TextSettingValue( ECamSettingItemVideoNameBase ) );
       
  5685     }
       
  5686 
       
  5687   TFileName nextFileName( baseVideoName );
       
  5688 
       
  5689   store = ( ECamControllerImage == iInfo.iMode ) ? 
       
  5690                 CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();  
       
  5691 
       
  5692   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5693 
       
  5694   if ( IsAppUiAvailable() &&
       
  5695        appUi &&
       
  5696        appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) &&
       
  5697        ECamMediaStorageCard == store )
       
  5698     {
       
  5699     if ( ExistMassStorage() )
       
  5700       {
       
  5701       // with multiple drives, the mass memory is the default
       
  5702       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  5703       store = ECamMediaStorageMassStorage;
       
  5704       }
       
  5705     else
       
  5706       {
       
  5707       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  5708       store = ECamMediaStoragePhone;
       
  5709       }
       
  5710     }
       
  5711 
       
  5712   TInt fileNameCounter = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5713  
       
  5714   // Update contents of iSuggestedVideoPath (drive and folders only)
       
  5715   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5716                                    store,
       
  5717                                    iSuggestedVideoPath,
       
  5718                                    ECamControllerVideo,
       
  5719                                    ETrue );
       
  5720                                    
       
  5721   iCurrentStorage = static_cast<TCamMediaStorage>( store );   
       
  5722   // Update contents of iSuggestedVideoPath (appending filename and extension)
       
  5723   CamUtility::GetUniqueNameL( iSuggestedVideoPath, nextFileName, fileNameCounter, extension );
       
  5724   PRINT( _L( "Camera <= CamAppController::GenerateNextVideoFilePathL" ) )
       
  5725   }
       
  5726 
       
  5727 // ---------------------------------------------------------------------------
       
  5728 // CCamAppController::GenerateNextValidVideoPathL
       
  5729 // Generate a new file name and full path to save the next video.
       
  5730 // If the generated file (using settings to suggest the drive) can not be opened
       
  5731 // try again, forcing the file to be on C: instead.
       
  5732 // ---------------------------------------------------------------------------
       
  5733 //
       
  5734 void CCamAppController::GenerateNextValidVideoPathL()
       
  5735   {
       
  5736   PRINT( _L("Camera => CCamAppController::GenerateNextValidVideoPathL()"));    
       
  5737   
       
  5738   // If USB is active, use phone memory
       
  5739   if( CamUtility::IsUsbActive() )
       
  5740       {
       
  5741       GenerateNextVideoFilePathL( ETrue );	
       
  5742       }
       
  5743   else
       
  5744       {    	
       
  5745       // Generate a file path using the settings
       
  5746       TRAPD( err, GenerateNextVideoFilePathL() );
       
  5747       
       
  5748       // If left (possibly due to corrupt MMC), try again with phone memory
       
  5749       if ( err )
       
  5750           {
       
  5751           // If we have got here, we can't access MMC. 
       
  5752           // Don't switch to phone memory, but prepare the engine with a video
       
  5753           // name in phone memory. This will be reset if needed when the user actually
       
  5754           // starts recording
       
  5755           PRINT( _L( "Could not generate next file path!  Corrupt MMC?" ) );
       
  5756           GenerateNextVideoFilePathL( ETrue );    
       
  5757           }
       
  5758       }
       
  5759 
       
  5760   PRINT( _L("Camera <= CCamAppController::GenerateNextValidVideoPathL()"));        
       
  5761   }
       
  5762 
       
  5763 // ---------------------------------------------------------------------------
       
  5764 // CCamAppController::GenerateNextValidImagesPathL
       
  5765 // Generate a new path to save the next image.
       
  5766 // ---------------------------------------------------------------------------
       
  5767 //
       
  5768 void CCamAppController::GenerateNextValidImagesPathL()
       
  5769   {
       
  5770   PRINT( _L("Camera => CCamAppController::GenerateNextValidImagesPathL()"));    
       
  5771   // Generate a file path using the settings
       
  5772   // Ensure the image folder exists
       
  5773   TFileName path;
       
  5774   TInt storage = IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  5775   CCamFolderUtility::GetBasePathL( iMonthFolderCounters,
       
  5776                                    storage,
       
  5777                                    path,
       
  5778                                    ECamControllerImage,
       
  5779                                    EFalse ); 
       
  5780                                    
       
  5781   iCurrentStorage = static_cast<TCamMediaStorage>( storage );                                 
       
  5782   PRINT( _L("Camera <= CCamAppController::GenerateNextValidImagesPathL()"));        
       
  5783   }    
       
  5784 
       
  5785 
       
  5786 // ---------------------------------------------------------------------------
       
  5787 // CCamAppController::CaptureModeTranstionInProgress
       
  5788 // Report whather a capture mode is currently being prepared
       
  5789 // ---------------------------------------------------------------------------
       
  5790 //
       
  5791 TBool CCamAppController::CaptureModeTransitionInProgress()
       
  5792   {
       
  5793   PRINT1( _L("Camera => CCamAppController::CaptureModeTransitionInProgress (%d)"), iCaptureModeTransitionInProgress )
       
  5794   return iCaptureModeTransitionInProgress;
       
  5795   }
       
  5796 
       
  5797 // ---------------------------------------------------------------------------
       
  5798 // CCamAppController::HandleSaveEvent
       
  5799 // From MCamImageSaveObserver.
       
  5800 // Handle completion of image saving
       
  5801 // ---------------------------------------------------------------------------
       
  5802 //
       
  5803 void 
       
  5804 CCamAppController::HandleSaveEvent( TCamSaveEvent aEvent )
       
  5805   {
       
  5806   PRINT3( _L( "Camera => CCamAppController::HandleSaveEvent .. event[%s] imagemode[%s] operation[%s]" ),
       
  5807           KCamSaveEventNames       [aEvent          ],
       
  5808           KCamImageModeNames       [iInfo.iImageMode], 
       
  5809           KCamCaptureOperationNames[iInfo.iOperation] )
       
  5810    
       
  5811   TBool mediaFileChanged = EFalse;     
       
  5812   
       
  5813   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5814   if( ( iCaptureArray->ImagesRemaining() <= 0 ) 
       
  5815           && appUi 
       
  5816           && appUi->IsInPretendExit() )
       
  5817       {
       
  5818       ReleaseArray( ETrue );
       
  5819       }
       
  5820   
       
  5821   if( ECamSaveEventCriticalError == aEvent )
       
  5822     {
       
  5823     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5824     SetOperation( ECamStandby, KErrGeneral );
       
  5825     PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  5826     return;
       
  5827     }
       
  5828 
       
  5829   if( aEvent == ECamSaveEventSaveError ) 
       
  5830     {
       
  5831     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5832     if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  5833         SequenceCaptureInProgress() )
       
  5834         {
       
  5835         // Cancel ongoing burst capture
       
  5836         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  5837         // and actual cancelling is done when next imagedata arrives.
       
  5838         // However, in this case camera is going to be released, and there won't
       
  5839         // be next image data, so give ECamRequestImageCancel and capture
       
  5840         // completion event here to avoid problems
       
  5841         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Cancel burst due to error") ); 
       
  5842         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  5843         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );   
       
  5844         }
       
  5845     else
       
  5846         {
       
  5847         PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5848         SetOperation( ECamStandby, KErrGeneral );
       
  5849         }   
       
  5850     PRINT( _L("Camera <= CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5851     return;
       
  5852     }
       
  5853 
       
  5854   // if a save completes 
       
  5855   if ( aEvent == ECamSaveEventComplete )
       
  5856     {
       
  5857     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventComplete") );
       
  5858 
       
  5859 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  5860     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  5861       {
       
  5862       // Do not log in burst mode
       
  5863       PERF_EVENT_END_L1( EPerfEventShotToSave );      
       
  5864       }
       
  5865 #endif
       
  5866 
       
  5867     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SAVE 0" );  //CCORAPP_PRI_SHOT_TO_SAVE_END
       
  5868 
       
  5869     // Check that this is the completion of the last pending 
       
  5870     // single image save.
       
  5871     // Note burst capture completion is handled separately
       
  5872     TBool savedAll   = ( iImageSaveActive->Count()== 0                );
       
  5873     TBool completing = ( ECamCompleting           == iInfo.iOperation );
       
  5874 
       
  5875     switch( iInfo.iImageMode )
       
  5876       {
       
  5877       case ECamImageCaptureNone: // In postcapture, waiting for saving
       
  5878       case ECamImageCaptureSingle:
       
  5879         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureSingle/None") );
       
  5880         if( savedAll )
       
  5881           {
       
  5882           OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );    //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  5883     
       
  5884           PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. calling HandleCaptureCompletion()") );
       
  5885           if( !iSaveStarted )
       
  5886               {
       
  5887               HandleCaptureCompletion();
       
  5888               NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5889               }
       
  5890           else
       
  5891               {
       
  5892               iSaveStarted = EFalse;
       
  5893               }
       
  5894           
       
  5895           // If we have returned from postcapture to precapture before 
       
  5896           // the filename has been sent to the gallery (i.e. pressing back
       
  5897           // key during image processing), iArrayUsageCount will be reduced 
       
  5898           // to zero and capture array will be released. In that case, we must
       
  5899           // send the filename to gallery before it happens.
       
  5900           if ( iArrayUsageCount == 1 )
       
  5901               {
       
  5902               NotifyControllerObservers( ECamEventMediaFileChanged );   
       
  5903               mediaFileChanged = ETrue;
       
  5904               }
       
  5905 
       
  5906           CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5907           if( iImageSaveActive && IsAppUiAvailable() )
       
  5908               {
       
  5909               if( iImageSaveActive->Count() <= 0 && ECamViewStatePostCapture != appUi->CurrentViewState() )
       
  5910                   {
       
  5911                   ReleaseArray();
       
  5912                   }
       
  5913               }
       
  5914           }
       
  5915         break;
       
  5916       case ECamImageCaptureTimeLapse:
       
  5917         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureTimeLapse") );
       
  5918         // If image capture has finished, but waiting for file to be saved.
       
  5919         if( ECamNoOperation == iInfo.iOperation || ECamCompleting == iInfo.iOperation )
       
  5920           {
       
  5921           PRINT( _L("Camera <> CCamAppController .. current file saved, complete this capture") );
       
  5922           SetOperation( ECamNoOperation );
       
  5923           ReleaseArray();
       
  5924           }
       
  5925         break;        
       
  5926       case ECamImageCaptureBurst:
       
  5927         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureBurst") );
       
  5928         // After the whole burst has stopped, we get Image Stop event from Camera Controller,
       
  5929         // and enter completing state.
       
  5930         if( completing && savedAll )
       
  5931           {
       
  5932           // Modify this event to "burst complete" one.
       
  5933           aEvent = ECamSaveEventBurstComplete;
       
  5934           }
       
  5935         break;
       
  5936       default:
       
  5937         break;
       
  5938       } 
       
  5939 
       
  5940     NotifyControllerObservers( ECamEventSaveComplete );
       
  5941     }
       
  5942   
       
  5943   if ( aEvent == ECamSaveEventStarted )
       
  5944      {
       
  5945      if( iInfo.iImageMode == ECamImageCaptureSingle )
       
  5946          {
       
  5947          PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Saving started") );
       
  5948          OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 1" ); //CCORAPP_PREP_FOR_NEXT_SHOT_START      
       
  5949          HandleCaptureCompletion();
       
  5950          NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5951          NotifyControllerObservers( ECamEventSaveComplete );
       
  5952          iCaptureRequested = EFalse;
       
  5953          iSaveStarted = ETrue;
       
  5954          OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 0" ); //CCORAPP_PREP_FOR_NEXT_SHOT_END
       
  5955          OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SHOT 0" ); //CCORAPP_PRI_SHOT_TO_SHOT_END   
       
  5956          }
       
  5957      }
       
  5958      
       
  5959   // If the user cancelled a save
       
  5960   if ( aEvent == ECamSaveEventUserCancelled )
       
  5961     {
       
  5962     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventUserCancelled" ) )
       
  5963     //iInfo.iImageMode = ECamImageModeNone;
       
  5964     // Make sure that any further engine callbacks are ignored until next capture
       
  5965     SetOperation( ECamNoOperation );
       
  5966 
       
  5967     // Delete dummy files for unsaved images
       
  5968     TInt nextSavingImage = BurstCaptureArray()->NextFileIndex();
       
  5969     TInt lastImage = BurstCaptureArray()->Count();
       
  5970     TInt i;
       
  5971     // delete the next and following files
       
  5972     for ( i = nextSavingImage; i < lastImage; i++ )
       
  5973       {
       
  5974       SetAsCurrentImage( i );
       
  5975       DeleteCurrentFile();
       
  5976       }
       
  5977     SetAsCurrentImage( 0 );
       
  5978     // Empty out the array - this ensures the thumbnail view doesn't open
       
  5979     BurstCaptureArray()->Reset();
       
  5980 
       
  5981     NotifyControllerObservers( ECamEventSaveCancelled );
       
  5982     }
       
  5983     
       
  5984   // if a burst capture has completed
       
  5985   if ( aEvent == ECamSaveEventBurstComplete )
       
  5986     {
       
  5987     CompleteBurstOperation();
       
  5988 
       
  5989     if( ECamCompleting == iInfo.iOperation )
       
  5990       {
       
  5991       PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. completing burst capture" ) )
       
  5992       SetOperation( ECamNoOperation );
       
  5993       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  5994       ReleaseArray();
       
  5995       }
       
  5996 
       
  5997     OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );  //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  5998     }
       
  5999   else
       
  6000     {
       
  6001     if ( iImageSaveActive->Count() == 0 || aEvent == ECamSaveEventStarted )
       
  6002       {
       
  6003       iSaving = EFalse;
       
  6004       }        
       
  6005     }
       
  6006   if ( !mediaFileChanged )
       
  6007       {
       
  6008       NotifyControllerObservers( ECamEventMediaFileChanged );    
       
  6009       }
       
  6010 
       
  6011   PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  6012   }
       
  6013 
       
  6014 
       
  6015 // ---------------------------------------------------------------------------
       
  6016 // HandleViewfinderFrame
       
  6017 // ---------------------------------------------------------------------------
       
  6018 //
       
  6019 void 
       
  6020 CCamAppController::HandleViewfinderFrame( TInt        /*aStatus*/, 
       
  6021                                           CFbsBitmap* /*aFrame*/ )
       
  6022   {
       
  6023   PRINT_FRQ( _L( "Camera => CCamAppController::HandleViewfinderFrame" ) );   
       
  6024 
       
  6025 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6026   // This function is called when a viewfinder bitmap arrives
       
  6027   if( EPerfWaitingForStartup == iPerformanceState )
       
  6028     {
       
  6029     iPerformanceState = EPerfIdle;
       
  6030     PERF_EVENT_END_L1( EPerfEventApplicationStartup );
       
  6031     }   
       
  6032   else if( EPerfWaitingForStillMode == iPerformanceState )
       
  6033     {
       
  6034     iPerformanceState = EPerfIdle;
       
  6035     PERF_EVENT_END_L1( EPerfEventSwitchToStillMode );
       
  6036     }
       
  6037   else if( EPerfWaitingForVideoMode == iPerformanceState )
       
  6038     {
       
  6039     iPerformanceState = EPerfIdle;
       
  6040     PERF_EVENT_END_L1( EPerfEventSwitchToVideoMode );
       
  6041     }
       
  6042   else if( EPerfWaitingForBurstFrame == iPerformanceState )
       
  6043     {
       
  6044     iPerformanceState = EPerfIdle;
       
  6045     PERF_EVENT_END_L1( EPerfEventBurstCaptureMomentToViewfinderFrame );
       
  6046     }
       
  6047 #endif
       
  6048 
       
  6049   if( ECamControllerVideo == iInfo.iMode )
       
  6050     {
       
  6051     // removed first vf frame usage as snapshot.
       
  6052     // snapshot received now from Camera 
       
  6053     }
       
  6054   else if( ECamControllerImage == iInfo.iMode )
       
  6055     {
       
  6056     // No need to duplicate here.
       
  6057     }
       
  6058   else
       
  6059     {
       
  6060     // Not valid state for vf frame.
       
  6061     __ASSERT_DEBUG( EFalse, CamPanic( ECamPanicInvalidState ) );
       
  6062     }
       
  6063 
       
  6064   if ( iZoomWaitingForCamera )
       
  6065     {
       
  6066     iZoomWaitingForCamera = EFalse;
       
  6067     if ( iNewZoomPending )
       
  6068       {
       
  6069       SetZoomValue( iDesiredZoomVal );
       
  6070       }
       
  6071     }
       
  6072   PRINT_FRQ( _L( "Camera <= CCamAppController::HandleViewfinderFrame" ) );
       
  6073   }
       
  6074 
       
  6075 
       
  6076 // ---------------------------------------------------------------------------
       
  6077 // ---------------------------------------------------------------------------
       
  6078 //
       
  6079 void CCamAppController::HandleSnapshotEvent( TInt aStatus,
       
  6080                                              CFbsBitmap* aBitmap )
       
  6081   {
       
  6082   PRINT1( _L( "Camera => CCamAppController::HandleSnapshotEvent, status:%d" ), aStatus );
       
  6083 
       
  6084 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6085   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6086     {
       
  6087     // Do not log in burst mode
       
  6088     PERF_EVENT_END_L1( EPerfEventShotToSnapshot );      
       
  6089     }
       
  6090   else
       
  6091     {
       
  6092     // In burst mode    
       
  6093     PERF_MESSAGE_L2( EPerfMessageBurstSnapshotReady );
       
  6094     }
       
  6095 #endif   
       
  6096 
       
  6097   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESNAPSHOTEVENT, "e_CAM_APP_SHOT_TO_SNAPSHOT 0" );    //CCORAPP_SHOT_TO_SNAPSHOT_END
       
  6098 
       
  6099 // ---------------------------------------------------------------------------
       
  6100 // Video snapshot handling
       
  6101   if( ECamControllerVideo == iInfo.iMode )
       
  6102     {
       
  6103     PRINT( _L("Camera <> Snapshot in video mode") ); 
       
  6104     if( KErrNone == aStatus )
       
  6105       {
       
  6106       // Make a copy of the snapshot and set it as current video ss.        
       
  6107       CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6108       if( iSnapShotCopy )
       
  6109         {
       
  6110         if (BurstCaptureArray()->Count() > 0 )
       
  6111           {
       
  6112           const CFbsBitmap* tempSnapShotCopy = iSnapShotCopy;
       
  6113           TRAP_IGNORE( BurstCaptureArray()->ReplaceSnapshot( tempSnapShotCopy, 0 ) );	
       
  6114           } 
       
  6115         else
       
  6116           {
       
  6117           TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *iSnapShotCopy ) );	
       
  6118           }
       
  6119         }        
       
  6120       }
       
  6121       
       
  6122       // If video recording has already stopped, give snapshot event,
       
  6123       // which causes snapshot to be updated in postcapture view.
       
  6124       // 
       
  6125       // If recording is still in progress, the event would cause
       
  6126       // too early switch to pastcapture.
       
  6127       if( ECamNoOperation == iInfo.iOperation ||
       
  6128           ECamCompleting == iInfo.iOperation )
       
  6129         {  
       
  6130         NotifyControllerObservers( ECamEventSnapshotReady, aStatus );  
       
  6131         }        
       
  6132       
       
  6133     return;
       
  6134     }
       
  6135 
       
  6136 // ---------------------------------------------------------------------------
       
  6137 // Still snapshot handling
       
  6138 
       
  6139   PRINT( _L("Camera <> Snapshot in still mode") ); 
       
  6140 
       
  6141   if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  6142     {
       
  6143     // Update time lapse count during snapshot, so the update counter value
       
  6144     // appears at the same time as snapshot.  
       
  6145     iTimeLapseCaptureCount++;
       
  6146     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6147     }        
       
  6148   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6149     {
       
  6150     // Re-enable the screen saver if burst capture is completing. 
       
  6151     // This has to be done when all captures complete for timelapse.
       
  6152     // EnableScreenSaver( ETrue );
       
  6153     
       
  6154     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6155     iUpdateFrozenFrame = ETrue;    
       
  6156         
       
  6157     }
       
  6158 
       
  6159   // -------------------------------------------------------
       
  6160   // if there is an error with the still capture operation
       
  6161   if ( KErrNone != aStatus )
       
  6162     {
       
  6163     PRINT( _L("Camera <> CCamAppController: error in, cancel saving etc..") );
       
  6164     // Store this now, as it's cleared by TidyCaptureArray
       
  6165     // but needed a little later
       
  6166     TBool wasCapturingBurst = (ECamImageCaptureBurst == iInfo.iImageMode);
       
  6167 
       
  6168     iImageSaveActive->Cancel();
       
  6169 
       
  6170     TidyCaptureArray( BurstCaptureArray()->NextFileIndex(), aStatus );
       
  6171     PRINT( _L("Camera <> cancel further capturing") );
       
  6172     TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  6173 
       
  6174     NotifyControllerObservers( ECamEventSnapshotReady, aStatus );
       
  6175 
       
  6176     if ( wasCapturingBurst )
       
  6177       {
       
  6178       // Need this here to allow the AppUi to update the state correctly
       
  6179       // following the error condition.  This needs to be *after* the
       
  6180       // change to OperationNone (called in TidyCaptureArray) so when the 
       
  6181       // AppUi forces CBA update we're not still in burst capture state.
       
  6182       NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6183       }
       
  6184 
       
  6185     PRINT( _L( "Camera <> calling HandleCaptureCompletion()" ) )
       
  6186     HandleCaptureCompletion();
       
  6187     }
       
  6188   // -------------------------------------------------------
       
  6189   // No error reported
       
  6190   else
       
  6191     {
       
  6192     PRINT( _L("Camera <> CCamAppController: status in KErrNone..") );
       
  6193     __ASSERT_ALWAYS( aBitmap, CamPanic( ECamPanicNullPointer ) );
       
  6194 
       
  6195     if( iInfo.iActiveCamera == ECamActiveCameraSecondary &&
       
  6196         iCaptureOrientation == ECamOrientation90 &&
       
  6197         ECamSettOn == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) )
       
  6198         {
       
  6199         PRINT( _L( "Camera <> Rotate portrait secondary camera snapshot image 180 degrees" ) )
       
  6200         TRAP_IGNORE( iSnapShotRotator->RotateL( aBitmap ) );
       
  6201         }
       
  6202      
       
  6203     CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6204      
       
  6205     // Removed filename reservation when snapshot arrives.
       
  6206     // From now on, it's always done in HandleImageCaptureEvent,
       
  6207     // even if snapshot comes first.
       
  6208        
       
  6209     // This is being ignored, but there is nothing to display in the app
       
  6210     TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *aBitmap ) )
       
  6211 
       
  6212     NotifyControllerObservers( ECamEventSnapshotReady );
       
  6213       
       
  6214     // If this is not a burst capture and snapshot came before image
       
  6215     // data, then the operation is now entering the completion phase.
       
  6216     // In case iFilenameReserved is set, imagedata has already
       
  6217     // arrived and we don't need to change state here.
       
  6218     if ( ECamCompleting != iInfo.iOperation && 
       
  6219          ECamImageCaptureBurst != iInfo.iImageMode && 
       
  6220          !iFilenameReserved )    
       
  6221       {  
       
  6222       SetOperation( ECamCompleting );      
       
  6223       }
       
  6224        
       
  6225     if( CurrentCapturedCount() < CaptureLimit() )
       
  6226         {
       
  6227         // Play capture sound for the next burst image
       
  6228         PlaySound( CaptureToneId(), EFalse );
       
  6229         }
       
  6230 
       
  6231     }
       
  6232   // -------------------------------------------------------
       
  6233 
       
  6234   PRINT( _L( "Camera <= CCamAppController::HandleSnapshotEvent" ) );    
       
  6235   }
       
  6236 
       
  6237 
       
  6238 // ---------------------------------------------------------------------------
       
  6239 // HandleImageCaptureEventL
       
  6240 // ---------------------------------------------------------------------------
       
  6241 //
       
  6242 void
       
  6243 CCamAppController::HandleImageCaptureEventL( TInt             aStatus, 
       
  6244                                              CCamBufferShare* aShare  )
       
  6245   {
       
  6246   PRINT1( _L("Camera => CCamAppController::HandleImageCaptureEventL, status:%d"), aStatus ); 
       
  6247 
       
  6248 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6249   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6250     {
       
  6251     // Do not log in burst mode
       
  6252     PERF_EVENT_END_L1( EPerfEventShotToStillImageReady );     
       
  6253     }
       
  6254   else
       
  6255     {
       
  6256     PERF_MESSAGE_L2( EPerfMessageBurstStillimageReady );
       
  6257     }
       
  6258 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6259 
       
  6260   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLEIMAGECAPTUREEVENTL, "e_CAM_APP_SHOT_TO_STILL 0" );  //CCORAPP_SHOT_TO_STILL_END
       
  6261 /*
       
  6262   // Check if we need to stop the burst capture.        
       
  6263   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6264     {    
       
  6265     if( CurrentCapturedCount() < CaptureLimit() )
       
  6266       {
       
  6267       // Play capture sound for the next burst image
       
  6268       PlaySound( CaptureToneId(), EFalse );
       
  6269       }
       
  6270     }
       
  6271 */
       
  6272    // If we have all the needed snapshots set the flag
       
  6273    // so the processing image text is shown.
       
  6274    // Do it here instead of handlesnapshotevent so that
       
  6275    // the counter has time to show the last image as well 
       
  6276    if( CurrentCapturedCount() == CaptureLimit() )  
       
  6277        {
       
  6278        iAllSnapshotsReceived = ETrue;	
       
  6279        }
       
  6280         
       
  6281   if( KErrNone == aStatus )
       
  6282     {
       
  6283     PRINT( _L("Camera <> CCamAppController: image capture status KErrNone") );
       
  6284     aShare->Reserve();
       
  6285     CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, aShare ) );
       
  6286 
       
  6287     // Reserve filename for saving the image. In case there's problem
       
  6288     // with current media, switch to internal memory
       
  6289     TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) );
       
  6290     if( KErrNone != err )
       
  6291      {
       
  6292      if( ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) )
       
  6293        {
       
  6294        PRINT( _L("Camera <> Memory card access failed.") )
       
  6295        NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  6296        }            
       
  6297        // If we have got here, we can't access MMC. Switch to phone memory
       
  6298         
       
  6299      TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  6300                                               //this actually uses the internal mass memory 
       
  6301      TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) ); 
       
  6302      if( KErrNone != err )
       
  6303       {
       
  6304       PRINT( _L("Camera <> Mass memory or phone memory access also failed.") )
       
  6305       TRAP_IGNORE( ForceUsePhoneMemoryL() );
       
  6306       TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode, ETrue ) );
       
  6307       }                 
       
  6308     }
       
  6309     
       
  6310     TBool markedForDelete = BurstCaptureArray()->IsNextImageDeleted();
       
  6311     PRINT1( _L("Camera <> Next image delete mark:%d"), markedForDelete );
       
  6312     if ( !markedForDelete )
       
  6313       {
       
  6314       PRINT( _L("Camera <> setting iImageSaveRequestPending to false"))
       
  6315       iImageSaveRequestPending = EFalse;
       
  6316       const TDesC& nextName( BurstCaptureArray()->NextFileName() );
       
  6317       PRINT( _L("Camera <> BurstCaptureArray()->NextFileName() returned") );
       
  6318       PRINT1( _L("Camera <> Set image to be saved, name:[%S]"), &nextName );
       
  6319       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6320       if( ( iInfo.iImageMode == ECamImageCaptureSingle ) 
       
  6321               && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto )
       
  6322               && iInfo.iActiveCamera == ECamActiveCameraPrimary
       
  6323               && !appUi->IsEmbedded() )
       
  6324           {
       
  6325           HandleSaveEvent( ECamSaveEventStarted );
       
  6326           }
       
  6327       TBool added = iImageSaveActive->AddToSave( nextName, aShare ); 
       
  6328       
       
  6329       if ( !added )
       
  6330         {
       
  6331         PRINT( _L("Camera <> Image saving start unsuccessful!") );
       
  6332         // The system state is consistent if this fails so ignore the error
       
  6333         }
       
  6334       else
       
  6335         {
       
  6336         PRINT( _L("Camera <> Image saving started ok.") );
       
  6337         // Ownership of the data has now been passed to CCamImageSaveActive
       
  6338         if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6339           {          
       
  6340           NotifyControllerObservers( ECamEventImageData );  
       
  6341           }
       
  6342         PRINT1( _L("Camera <> CCamAppController::HandleImageCaptureEventL array count:%d"), BurstCaptureArray()->Count() );  
       
  6343         // check if snapshot bitmap needs to be rotated before creating a thumbnail from it
       
  6344         TBool rotate( ( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) || 
       
  6345                       iInfo.iActiveCamera == ECamActiveCameraSecondary ) &&
       
  6346                       ECamSettOn == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) &&
       
  6347                       iCaptureOrientation != ECamOrientation0 );
       
  6348 
       
  6349         if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6350           {
       
  6351           //create thumbnail or rotate first if needed
       
  6352           if ( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  6353               {
       
  6354               if ( rotate )
       
  6355                   {
       
  6356                   RotateSnapshotL();
       
  6357                   }
       
  6358               else
       
  6359                   {       
       
  6360                   TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  6361                   }
       
  6362               } 
       
  6363           }
       
  6364         }
       
  6365       }
       
  6366     CleanupStack::PopAndDestroy(); // aShare->Release()
       
  6367     aShare = NULL;
       
  6368     }
       
  6369   else
       
  6370     {
       
  6371     PRINT( _L("Camera <> CCamAppController: capture status *not* KErrNone, mark current file for delete") );
       
  6372     DeleteCurrentFile();
       
  6373     }
       
  6374 
       
  6375 
       
  6376   iFilenameReserved = ETrue;
       
  6377 
       
  6378   PRINT( _L( "Camera <= CCamAppController::HandleImageCaptureEventL" ) );        
       
  6379   }
       
  6380 
       
  6381 
       
  6382 
       
  6383 // ---------------------------------------------------------------------------
       
  6384 // HandleImageStopEventL
       
  6385 // ---------------------------------------------------------------------------
       
  6386 //
       
  6387 void
       
  6388 CCamAppController::HandleImageStopEventL( TInt aStatus, TInt aFullCaptureCount )
       
  6389   {
       
  6390   PRINT2( _L("Camera => CCamAppController::HandleImageStopEventL, status:%d, full captures:%d"), aStatus, aFullCaptureCount );
       
  6391 
       
  6392   TBool saved = ( iImageSaveActive->Count()== 0 );
       
  6393 
       
  6394   switch( iInfo.iImageMode )
       
  6395     {
       
  6396     // -----------------------------------------------------
       
  6397     case ECamImageCaptureBurst:
       
  6398       {
       
  6399       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureBurst" ) );
       
  6400       // CompleteBurstOperation();
       
  6401      
       
  6402       // Re-enable screen saver
       
  6403       EnableScreenSaver( ETrue );
       
  6404       if( iBacklightTimer )
       
  6405         {
       
  6406         iBacklightTimer->Cancel();
       
  6407         }
       
  6408       
       
  6409       TInt started( iCameraController->ControllerInfo().iSnapshotCount );
       
  6410       if ( aFullCaptureCount < started )
       
  6411         {
       
  6412         PRINT ( _L("Camera <> CCamAppController .. [WARNING] Incomplete captures detected, cleaning up.." ) );
       
  6413         PRINT1( _L("Camera <> CCamAppController .. [WARNING] snapshot     count: %d"), started );
       
  6414         PRINT1( _L("Camera <> CCamAppController .. [WARNING] full capture count: %d"), aFullCaptureCount            );
       
  6415         PRINT1( _L("Camera <> CCamAppController .. [WARNING] burst array  count: %d"), BurstCaptureArray()->Count() );
       
  6416         TInt stopAt = Min( started, BurstCaptureArray()->Count() );
       
  6417         for ( TInt index = aFullCaptureCount; index < stopAt; index++ )
       
  6418           {
       
  6419           PRINT1( _L("Camera <> CCamAppController .. [WARNING] deleting temp file from index %d.."), index );
       
  6420           SetAsCurrentImage( index );
       
  6421           // Parameter: notify about file system change only on last delete.
       
  6422           DeleteCurrentFile( stopAt-1 == index );
       
  6423           }
       
  6424         PRINT1( _L("Camera <> CCamAppController .. [WARNING] setting as current image %d.."), aFullCaptureCount );
       
  6425         SetAsCurrentImage( aFullCaptureCount );
       
  6426         PRINT ( _L("Camera <> CCamAppController .. [WARNING] resetting burst array to required count..") );
       
  6427         BurstCaptureArray()->Reset( aFullCaptureCount );
       
  6428         }
       
  6429 
       
  6430       SetOperation( ECamCompleting );
       
  6431 
       
  6432       // We may have deleted all the images, so check the status here.
       
  6433       if( iImageSaveActive->Count()== 0 )
       
  6434         {
       
  6435         PRINT( _L( "Camera <> CCamAppController .. images already saved, completing burst capture" ) )
       
  6436         SetOperation( ECamNoOperation );
       
  6437         NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6438         ReleaseArray();
       
  6439         }
       
  6440       // if no images were taken, clear AssumePostCaptureView flag  
       
  6441       if ( started == 0 )
       
  6442         {
       
  6443         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6444         if ( appUi )
       
  6445           {
       
  6446           appUi->SetAssumePostCaptureView( EFalse );	
       
  6447           }	
       
  6448         }  
       
  6449       break;
       
  6450       }
       
  6451     // -----------------------------------------------------
       
  6452     case ECamImageCaptureSingle:
       
  6453       {
       
  6454       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureSingle" ) );
       
  6455 
       
  6456       // In secondary camera we can get snapshot as last event
       
  6457       // so we might still be in capturing state.
       
  6458       if( ECamCapturing == iInfo.iOperation )
       
  6459         {
       
  6460         PRINT( _L( "Camera <> CCamAppController .. still in capturing phase, set to completing first.." ) );
       
  6461         SetOperation( ECamCompleting );  
       
  6462         }
       
  6463 
       
  6464   	  // In case of secondary camera, image may be saved before Stop event is received.
       
  6465   	  // Notify capture complete event to the observers and other completion handling here.
       
  6466       if( saved && ECamCompleting == iInfo.iOperation )
       
  6467         {
       
  6468         PRINT( _L( "Camera <> CCamAppController .. file saved, complete capture" ) );
       
  6469 
       
  6470 		// Operation mode is also set in HandleCaptureCompletion
       
  6471 		HandleCaptureCompletion();
       
  6472 		NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6473         ReleaseArray();
       
  6474         }
       
  6475       
       
  6476       break;
       
  6477       }
       
  6478     // -----------------------------------------------------
       
  6479     case ECamImageCaptureTimeLapse:
       
  6480       {
       
  6481       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureTimeLapse" ) );
       
  6482       if( saved )
       
  6483         {
       
  6484         PRINT( _L( "Camera <> CCamAppController .. current file saved, complete this capture" ) );
       
  6485         SetOperation( ECamNoOperation );
       
  6486         ReleaseArray();
       
  6487         }
       
  6488 
       
  6489       if ( iCompleteTimeLapsePending )
       
  6490         {
       
  6491         CompleteTimeLapseOperation();
       
  6492         }
       
  6493       else
       
  6494         {
       
  6495         // If the camera orientation changed during capture, set the new orientation in the engine
       
  6496         // ready for the next timelapse capture
       
  6497         if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  6498          		 && iOrientationChangeOccured )  
       
  6499           {
       
  6500           iOrientationChangeOccured = EFalse;
       
  6501           TRAP_IGNORE( SetImageOrientationL() );
       
  6502           }
       
  6503         }   
       
  6504       break;
       
  6505       }
       
  6506     // -----------------------------------------------------
       
  6507     default:
       
  6508       break;
       
  6509     // -----------------------------------------------------
       
  6510     }
       
  6511   PRINT( _L( "Camera <= CCamAppController::HandleImageStopEventL" ) );
       
  6512   }
       
  6513 
       
  6514 
       
  6515 // ---------------------------------------------------------------------------
       
  6516 // CCamAppController::IdleTimeoutL
       
  6517 // ---------------------------------------------------------------------------
       
  6518 //
       
  6519 TInt CCamAppController::IdleTimeoutL( TAny* aPtr )
       
  6520     {
       
  6521     return static_cast<CCamAppController*>( aPtr )->DoIdleTimeoutL();
       
  6522     }
       
  6523 
       
  6524 // ---------------------------------------------------------------------------
       
  6525 // CCamAppController::DoIdleTimeoutL
       
  6526 // ---------------------------------------------------------------------------
       
  6527 //
       
  6528 TInt CCamAppController::DoIdleTimeoutL()
       
  6529   {
       
  6530   // if a video recording has been paused for 60 seconds without key presses
       
  6531   if ( ECamPaused == CurrentVideoOperation() )
       
  6532     {
       
  6533     NotifyControllerObservers( ECamEventVideoPauseTimeout, KErrNone );
       
  6534     }
       
  6535 
       
  6536   // notify switch to standby mode and stop timer
       
  6537   else if( ECamStandby != iInfo.iOperation && ECamTriActive == iCameraController->ViewfinderState())
       
  6538     {
       
  6539     SetOperation( ECamStandby );
       
  6540     }
       
  6541   else
       
  6542     {
       
  6543     // For Lint
       
  6544     }
       
  6545 
       
  6546   iIdleTimer->Cancel();
       
  6547 
       
  6548 // Use backlight timer also with bitmap vf
       
  6549   if( iBacklightTimer )
       
  6550     {
       
  6551 	if( ECamTriActive == iCameraController->ViewfinderState() )
       
  6552 	  {
       
  6553 	  User::ResetInactivityTime();
       
  6554       }
       
  6555     iBacklightTimer->Cancel();
       
  6556     }
       
  6557 
       
  6558   return EFalse;
       
  6559   }
       
  6560 
       
  6561 // ---------------------------------------------------------------------------
       
  6562 // CCamAppController::StartIdleTimer
       
  6563 // ---------------------------------------------------------------------------
       
  6564 //
       
  6565 void CCamAppController::StartIdleTimer()
       
  6566   {
       
  6567   PRINT( _L( "Camera => CCamAppController::StartIdleTimer" ) ); 
       
  6568   // if in standby mode notify of switch back to pre-capture
       
  6569   if ( ECamStandby == iInfo.iOperation )
       
  6570     {
       
  6571     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer ECamStandby" ) );
       
  6572     SetOperation( ECamNoOperation );
       
  6573     }
       
  6574   // if recording is in progress don't go to standby
       
  6575   else if ( ECamCapturing == CurrentVideoOperation() )             
       
  6576     {
       
  6577     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer no restart" ) );
       
  6578     // don't restart if recording operation in progress
       
  6579     return;
       
  6580     }
       
  6581   // if recording is paused, use the idle timer to stop recording after 60 secs
       
  6582   else
       
  6583     {
       
  6584     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer else part" ) );
       
  6585     // empty else statement to remove LINT error
       
  6586     }
       
  6587 
       
  6588   // restart timer
       
  6589   iIdleTimer->Cancel();
       
  6590 
       
  6591   // don't restart if capturing burst, setting time lapse or in a pretend exit state
       
  6592   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6593   if ( !SequenceCaptureInProgress() && appUi && !appUi->IsInPretendExit() 
       
  6594        && !appUi->TimeLapseSliderShown())
       
  6595     {
       
  6596     // restart timer
       
  6597     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer starting timer" ) );
       
  6598     iIdleTimer->StartTimer();
       
  6599     }
       
  6600 
       
  6601   if ( iDeepSleepTimer )
       
  6602     {
       
  6603     if ( iDeepSleepTimer->IsActive() )
       
  6604         {
       
  6605         PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - restart deep sleep timer" ) );
       
  6606         DeepSleepTimerCancel();
       
  6607         DeepSleepTimerStart();
       
  6608         }
       
  6609     else if ( iDeepSleepTimerExpired )
       
  6610         {
       
  6611         iDeepSleepTimerExpired = EFalse; // clear flag
       
  6612         TVwsViewId activeView;
       
  6613         CCamAppUi* appUi = 
       
  6614             static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6615         (void) appUi->GetActiveViewId( activeView ); // ignore error
       
  6616         
       
  6617         if ( !IsViewFinding() && !InVideocallOrRinging() &&
       
  6618             activeView.iViewUid.iUid != ECamViewIdVideoPostCapture && 
       
  6619             activeView.iViewUid.iUid != ECamViewIdStillPostCapture &&
       
  6620             activeView.iViewUid.iUid != ECamViewIdBurstThumbnail )
       
  6621             {
       
  6622             PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - Deep sleep timer expired. Restart VF" ) );
       
  6623             TCamCameraMode mode = CurrentMode() == ECamControllerVideo?
       
  6624                                   ECamControllerVideo : ECamControllerImage;
       
  6625             EnterViewfinderMode( mode ); 
       
  6626             DeepSleepTimerStart();
       
  6627             }
       
  6628         }
       
  6629     }
       
  6630 
       
  6631   PRINT( _L( "Camera <= CCamAppController::StartIdleTimer" ) );
       
  6632   }
       
  6633 
       
  6634 // ---------------------------------------------------------------------------
       
  6635 // CCamAppController::StopIdleTimer
       
  6636 // ---------------------------------------------------------------------------
       
  6637 //
       
  6638 void CCamAppController::StopIdleTimer()
       
  6639     {
       
  6640     PRINT( _L( "Camera => CCamAppController::StopIdleTimer" ) );
       
  6641     if( iIdleTimer )
       
  6642         {
       
  6643         iIdleTimer->Cancel();
       
  6644         }
       
  6645     PRINT( _L( "Camera <= CCamAppController::StopIdleTimer" ) );
       
  6646     }
       
  6647 
       
  6648 // ---------------------------------------------------------------------------
       
  6649 // CCamAppController::TimeLapseTimeoutL
       
  6650 // ---------------------------------------------------------------------------
       
  6651 //
       
  6652 TInt CCamAppController::TimeLapseTimeoutL( TAny* aPtr )
       
  6653     {
       
  6654     return static_cast<CCamAppController*>( aPtr )->DoTimeLapseTimeoutL();
       
  6655     }    
       
  6656     
       
  6657 // ---------------------------------------------------------------------------
       
  6658 // CCamAppController::DoTimeLapseTimeoutL
       
  6659 // ---------------------------------------------------------------------------
       
  6660 //
       
  6661 TInt CCamAppController::DoTimeLapseTimeoutL()
       
  6662   {
       
  6663   PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL" ))      
       
  6664   // Work out how much time is left before the next capture
       
  6665   TTime now;
       
  6666   now.HomeTime();
       
  6667   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  6668   TInt64 remainingTime = iTimeLapseInterval.Int64() - elapsedTime.Int64();              
       
  6669   // update the remaining time countdown 
       
  6670   NotifyControllerObservers( ECamEventCounterUpdated );
       
  6671   
       
  6672   //if the total timelapse period has now completed
       
  6673   if ( remainingTime <= 0 )
       
  6674     {
       
  6675         // Workaround for DoTimeLapseTimeoutL firing while in inappropriate state
       
  6676     	// cause capture to be delayed by 1 sec 
       
  6677     	if( ECamNoOperation != iInfo.iOperation ) 
       
  6678     		{
       
  6679     		PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL workaround" ))      
       
  6680 			//remainingTime = TInt64( KSecondInMicSec );    	
       
  6681 		    iTimeLapseTimer->StartTimer();
       
  6682     		}    	
       
  6683 	else
       
  6684 		{
       
  6685 	    TInt remainingCount = ImagesRemaining( static_cast<TCamMediaStorage>( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ), ETrue );
       
  6686 	    if ( remainingCount > 0 )
       
  6687 	      	{
       
  6688 	      PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL about to do next capture" ))   
       
  6689 	      // About to do the next capture so decrement the view's usage count on the array
       
  6690 	      ReleaseArray();
       
  6691             if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  6692                 {
       
  6693                 if( !CurrentSceneHasForcedFocus() )
       
  6694                     {
       
  6695                     if( !IsViewFinding() )
       
  6696                         {
       
  6697                         StartViewFinder();
       
  6698                         }
       
  6699                     StartAutoFocus();
       
  6700                     iCaptureRequested = ETrue; //Has to be set before focused/not focused event.
       
  6701                     }
       
  6702                 else
       
  6703                     {
       
  6704                     PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL capture with forcedfocus scene" ))   
       
  6705                     Capture();            
       
  6706                     }
       
  6707                 }
       
  6708             else 
       
  6709                 {
       
  6710             	Capture();            
       
  6711                 }
       
  6712 			RestartTimeLapseTimerL();
       
  6713       	}
       
  6714 	    else
       
  6715 	     {
       
  6716 	     		PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL capture is complete" ))   
       
  6717 	      	CompleteTimeLapseOperation();
       
  6718 	     }
       
  6719 	   }              
       
  6720     return EFalse;
       
  6721     }
       
  6722   // Otherwise restart the timer for the next period    
       
  6723   else
       
  6724     {
       
  6725     if ( remainingTime < TInt64( KSecondInMicSec ) )
       
  6726       {
       
  6727       PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL shortening timer" ))   
       
  6728       iTimeLapseTimer->SetTimeout( (TInt)remainingTime );
       
  6729       }
       
  6730      else if(  ( remainingTime < TInt64( 5 *KSecondInMicSec )) && !iCameraWoken )
       
  6731      	{
       
  6732 		iCameraWoken = ETrue;
       
  6733 		if( !IsViewFinding() )
       
  6734 		{
       
  6735 			StartViewFinder();
       
  6736 		}
       
  6737 		User::ResetInactivityTime();     		
       
  6738      	}
       
  6739      
       
  6740     PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL restarting timer" ))               
       
  6741     iTimeLapseTimer->StartTimer();
       
  6742     }
       
  6743   return EFalse;        
       
  6744   }
       
  6745 
       
  6746 // ---------------------------------------------------------------------------
       
  6747 // CCamAppController::SupportedFlashModes
       
  6748 // Return flash modes supported engine
       
  6749 // ---------------------------------------------------------------------------
       
  6750 //
       
  6751 TUint32 CCamAppController::SupportedFlashModes()
       
  6752   {
       
  6753   if( iCameraController )
       
  6754     return iCameraController->CameraInfo().iFlashModesSupported;
       
  6755   else
       
  6756     return 0;
       
  6757   //iSupportedFlashModes;
       
  6758   }
       
  6759   
       
  6760 // ---------------------------------------------------------------------------
       
  6761 // CCamAppController::SupportedWBModes
       
  6762 // Return white balance modes supported engine
       
  6763 // ---------------------------------------------------------------------------
       
  6764 //  
       
  6765 TUint32 CCamAppController::SupportedWBModes()
       
  6766   {
       
  6767   if( iCameraController )
       
  6768     return iCameraController->CameraInfo().iWhiteBalanceModesSupported;
       
  6769   else
       
  6770     return 0;
       
  6771   //iSupportedWBModes;
       
  6772   }
       
  6773   
       
  6774 // ---------------------------------------------------------------------------
       
  6775 // CCamAppController::SupportedEVModes
       
  6776 // Return EV modes supported engine
       
  6777 // ---------------------------------------------------------------------------
       
  6778 //  
       
  6779 TUint32 CCamAppController::SupportedEVModes()
       
  6780   {
       
  6781   if( iCameraController )
       
  6782     return iCameraController->CameraInfo().iExposureModesSupported;
       
  6783   else
       
  6784     return 0;
       
  6785   //iSupportedEVModes;
       
  6786   } 
       
  6787 
       
  6788 // ---------------------------------------------------------------------------
       
  6789 // CCamAppController::CaptureState
       
  6790 // ---------------------------------------------------------------------------
       
  6791 //  
       
  6792 TInt CCamAppController::CaptureState()  
       
  6793   {
       
  6794   if( iCameraController )
       
  6795     {
       
  6796     return iCameraController->ControllerInfo().iCaptureState;
       
  6797     }
       
  6798   else
       
  6799     {
       
  6800     return KErrNotFound;
       
  6801     }
       
  6802   } 
       
  6803 
       
  6804 
       
  6805 
       
  6806 // -----------------------------------------------------------------------------
       
  6807 // CCamAppController::FlashStatus()
       
  6808 // Returns pointer to FlashStatus object
       
  6809 // -----------------------------------------------------------------------------
       
  6810 //
       
  6811 CCamFlashStatus* 
       
  6812 CCamAppController::FlashStatus() const
       
  6813   {
       
  6814   return iFlashStatus;    
       
  6815   }
       
  6816        
       
  6817 
       
  6818 // -----------------------------------------------------------------------------
       
  6819 // CCamAppController::FlashRequired()
       
  6820 // 
       
  6821 // -----------------------------------------------------------------------------
       
  6822 //
       
  6823 TBool 
       
  6824 CCamAppController::FlashRequired() const
       
  6825   {
       
  6826   if( ECamSceneSports == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  6827     {
       
  6828     // Flash is not required in sport scene, even if the flash mode
       
  6829     // is forced or redeye.
       
  6830     return EFalse;
       
  6831     }
       
  6832     
       
  6833   // Make decision based on current flash mode    
       
  6834   TInt flashMode = IntegerSettingValue( ECamSettingItemDynamicPhotoFlash );            
       
  6835   switch( flashMode )
       
  6836     {
       
  6837     case ECamFlashOff:
       
  6838       {
       
  6839       return EFalse;    
       
  6840       }
       
  6841     case ECamFlashAntiRedEye: // Flowthrough
       
  6842     case ECamFlashForced:
       
  6843       {
       
  6844       return ETrue;    
       
  6845       }
       
  6846     default:
       
  6847       {
       
  6848       // Just return true in the default case.
       
  6849       // Automatic mode will decide if flash is used or not.
       
  6850       return ETrue;
       
  6851       }
       
  6852     } 
       
  6853   }
       
  6854 
       
  6855 // -----------------------------------------------------------------------------
       
  6856 // CCamAppController::CheckFlash()
       
  6857 // 
       
  6858 // -----------------------------------------------------------------------------
       
  6859 //     
       
  6860 TBool 
       
  6861 CCamAppController::CheckFlash() const
       
  6862   {            
       
  6863   PRINT ( _L("Camera => CCamAppController::CheckFlash") );
       
  6864   PRINT1( _L("Camera <> CCamAppController:              flash required :%d  "), FlashRequired() );
       
  6865   PRINT1( _L("Camera <> CCamAppController: FlashStatus: flash ready    :%d  "), iFlashStatus->FlashReady() );
       
  6866   PRINT1( _L("Camera <> CCamAppController: CameraCtrl:  flash status   :[%s]"),
       
  6867           KCamCameraReadyStateNames[iCameraController->FlashState()] );
       
  6868 
       
  6869   TBool ok( !FlashRequired() || iFlashStatus->FlashReady() );
       
  6870 
       
  6871   PRINT1( _L("Camera <= CCamAppController::CheckFlash, return:%d"), ok );
       
  6872 #ifdef __WINSCW__
       
  6873   return ETrue;
       
  6874 #else  
       
  6875   return ok;
       
  6876 #endif  
       
  6877   }
       
  6878 
       
  6879 
       
  6880 // -----------------------------------------------------------------------------
       
  6881 // CCamAppController::SaveFlashMode()
       
  6882 // 
       
  6883 // -----------------------------------------------------------------------------
       
  6884 //    
       
  6885 void CCamAppController::SaveFlashMode()
       
  6886   {    
       
  6887   iFlashModeSaved  = ETrue;
       
  6888   iSavedFlashMode  = static_cast<TCamFlashId>( IntegerSettingValue( ECamSettingItemDynamicPhotoFlash ) );
       
  6889   iSavedFlashScene = static_cast<TCamSceneId>( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
  6890   }
       
  6891     
       
  6892 // -----------------------------------------------------------------------------
       
  6893 // CCamAppController::RestoreFlashMode
       
  6894 // 
       
  6895 // -----------------------------------------------------------------------------
       
  6896 //    
       
  6897 void CCamAppController::RestoreFlashMode()
       
  6898   {                
       
  6899   if( iFlashModeSaved )
       
  6900     {
       
  6901     if( iSavedFlashScene == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  6902       {
       
  6903       // Set saved flash mode    
       
  6904       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, iSavedFlashMode ) );
       
  6905       }
       
  6906     else
       
  6907       {
       
  6908       // Set default flash mode for this scene   
       
  6909       // SetDynamicSettingToDefault( ECamSettingItemDynamicPhotoFlash );          
       
  6910       TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  6911       TInt sceneFlashMode = iSettingsModel->SceneSettingValue( scene, ECamSettingItemSceneFlashMode );
       
  6912       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, sceneFlashMode ) );
       
  6913       
       
  6914       }
       
  6915     }
       
  6916   iFlashModeSaved = EFalse;   
       
  6917   }
       
  6918 
       
  6919 
       
  6920 // ---------------------------------------------------------------------------
       
  6921 // CCamAppController::ForceUsePhoneMemoryL
       
  6922 // ---------------------------------------------------------------------------
       
  6923 //
       
  6924 void CCamAppController::ForceUsePhoneMemoryL( TBool aEnable )
       
  6925 	{
       
  6926 	PRINT( _L("Camera => CCamAppController::ForceUsePhoneMemoryL") );
       
  6927 
       
  6928 	if( aEnable )
       
  6929 		{
       
  6930 		iForceUseOfPhoneMemory = ETrue;
       
  6931     if( ExistMassStorage() )
       
  6932       {
       
  6933       // with multiple drives, the mass memory is the default
       
  6934       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  6935       iForcedStorageLocation = ECamMediaStorageMassStorage;
       
  6936       SetPathnamesToNewStorageL( ECamMediaStorageMassStorage );
       
  6937       }
       
  6938     else
       
  6939       {
       
  6940       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  6941       iForcedStorageLocation = ECamMediaStoragePhone;
       
  6942       SetPathnamesToNewStorageL( ECamMediaStoragePhone );
       
  6943       }
       
  6944 		}
       
  6945 	// Revert back to memory card, if aEnable is EFalse
       
  6946 	else
       
  6947 		{
       
  6948 		iForceUseOfPhoneMemory = EFalse;
       
  6949     iForcedStorageLocation = ECamMediaStorageNone;
       
  6950     SetPathnamesToNewStorageL( iPreferredStorageLocation );
       
  6951 		}
       
  6952 
       
  6953 	NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  6954 	PRINT( _L("Camera <= CCamAppController::ForceUsePhoneMemoryL") );
       
  6955 	}
       
  6956 
       
  6957 
       
  6958 
       
  6959 // ---------------------------------------------------------------------------
       
  6960 // CCamAppController::IsPhoneMemoryForced
       
  6961 // Check whether the use of phone memory is forced, because of unavailibility 
       
  6962 // or problems encountered in using MMC.
       
  6963 // ---------------------------------------------------------------------------
       
  6964 //
       
  6965 TBool CCamAppController::IsPhoneMemoryForced()
       
  6966 	{
       
  6967 	return iForceUseOfPhoneMemory;
       
  6968 	}
       
  6969 
       
  6970 // ---------------------------------------------------------------------------
       
  6971 // CCamAppController::CheckMemoryToUseL
       
  6972 // Set the appropriate memory to use. Use Phone memory if MMC not available.
       
  6973 // ---------------------------------------------------------------------------
       
  6974 //
       
  6975 TBool CCamAppController::CheckMemoryToUseL()
       
  6976 	{
       
  6977   TInt key = ( ECamControllerImage == CurrentMode() )
       
  6978                ? ECamSettingItemPhotoMediaStorage
       
  6979                : ECamSettingItemVideoMediaStorage;
       
  6980 
       
  6981   TCamMediaStorage storageLocation = static_cast<TCamMediaStorage> ( IntegerSettingValueUnfiltered(key) );
       
  6982   TBool mmcAvailable = IsMemoryAvailable ( ECamMediaStorageCard );
       
  6983     
       
  6984   PRINT1( _L("Camera :: CCamAppController::CheckMemoryToUse preferred storage:%d"), 
       
  6985               storageLocation );
       
  6986     
       
  6987   // If MMC is preferred storage location but is not available 
       
  6988 	if ( storageLocation == ECamMediaStorageCard && !mmcAvailable )
       
  6989 		{
       
  6990 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use phone memory / mass storage") )
       
  6991 		ForceUsePhoneMemoryL( ETrue );
       
  6992 		return ETrue;
       
  6993 		}
       
  6994 	// Preferred location is MMC and its available now -> stop forcing phone memory 
       
  6995 	else if( storageLocation == ECamMediaStorageCard && mmcAvailable && 
       
  6996 	         iForceUseOfPhoneMemory ) 
       
  6997 		{
       
  6998 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use MMC") )
       
  6999 		ForceUsePhoneMemoryL( EFalse );
       
  7000 		return ETrue;
       
  7001 		}
       
  7002   if ( storageLocation == ECamMediaStorageMassStorage && !ExistMassStorage() )
       
  7003 		{
       
  7004 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - no mass storage, use phone memory") )
       
  7005 		ForceUsePhoneMemoryL( ETrue );
       
  7006 		return ETrue;
       
  7007 		}
       
  7008 	// Mass storage is available now -> stop forcing phone memory
       
  7009 	else if( storageLocation == ECamMediaStorageMassStorage && ExistMassStorage() && iForceUseOfPhoneMemory ) 
       
  7010 		{
       
  7011 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use mass memory") )
       
  7012 		ForceUsePhoneMemoryL( EFalse );
       
  7013 		return ETrue;
       
  7014 		}
       
  7015 	else
       
  7016 	  {
       
  7017 	  SetPathnamesToNewStorageL( storageLocation );
       
  7018 	  }
       
  7019 
       
  7020   return EFalse;
       
  7021 	}
       
  7022 
       
  7023 
       
  7024 
       
  7025 // ---------------------------------------------------------------------------
       
  7026 // CCamAppController::CompleteBurstOperation
       
  7027 // Complete the burst operation
       
  7028 // ---------------------------------------------------------------------------
       
  7029 //
       
  7030 void CCamAppController::CompleteBurstOperation()
       
  7031   {
       
  7032   PRINT( _L( "Camera => CCamAppController::CompleteBurstOperation" ) );
       
  7033   iSequenceCaptureInProgress = EFalse;
       
  7034   iNoBurstCancel=EFalse;
       
  7035   
       
  7036   if( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7037       {
       
  7038       PRINT1( _L("Camera <> CCamAppController::CompleteBurstOperation array count:%d"), BurstCaptureArray()->Count() );    
       
  7039       // Create thumbnails
       
  7040       if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  7041           {
       
  7042           TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  7043           }
       
  7044       	
       
  7045       // Re-enable screen saver
       
  7046       EnableScreenSaver( ETrue );
       
  7047 	  if( iBacklightTimer )
       
  7048 		{
       
  7049 		iBacklightTimer->Cancel();
       
  7050 		}
       
  7051       SetOperation( ECamNoOperation );
       
  7052   
       
  7053       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  7054       HandleCaptureCompletion();
       
  7055       }
       
  7056   PRINT( _L( "Camera <= CCamAppController::CompleteBurstOperation" ) );          
       
  7057   }
       
  7058 
       
  7059 // ---------------------------------------------------------------------------
       
  7060 // CCamAppController::CompleteTimeLapseOperation
       
  7061 // Complete the time lapse operation
       
  7062 // ---------------------------------------------------------------------------
       
  7063 //
       
  7064 void CCamAppController::CompleteTimeLapseOperation()    
       
  7065     {
       
  7066     PRINT( _L( "Camera => CCamAppController::CompleteTimeLapseOperation" ) );
       
  7067 
       
  7068     iSequenceCaptureInProgress = EFalse;
       
  7069 
       
  7070     if ( iTimeLapseTimer )
       
  7071       {
       
  7072       iTimeLapseTimer->Cancel();
       
  7073       delete iTimeLapseTimer;
       
  7074       iTimeLapseTimer = NULL;
       
  7075       }
       
  7076 
       
  7077     if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7078       {
       
  7079       // Re-enable screen saver
       
  7080       EnableScreenSaver( ETrue );
       
  7081       iCompleteTimeLapsePending = EFalse;
       
  7082   
       
  7083 //      SetImageMode( ECamImageCaptureNone );   
       
  7084       SetOperation( ECamNoOperation      );
       
  7085   
       
  7086       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );   
       
  7087       HandleCaptureCompletion();
       
  7088       iTimeLapseStartTime = TInt64( 0 );
       
  7089       }
       
  7090 
       
  7091     PRINT( _L( "Camera <= CCamAppController::CompleteTimeLapseOperation" ) );   
       
  7092     }
       
  7093 
       
  7094 
       
  7095 // ---------------------------------------------------------------------------
       
  7096 // CCamAppController::EngineProcessingCapture
       
  7097 // Return whether or not the engine is carrying out a capture operation
       
  7098 // ---------------------------------------------------------------------------
       
  7099 //
       
  7100 TBool 
       
  7101 CCamAppController::EngineProcessingCapture() const
       
  7102   {
       
  7103   TBool engineIsProcessing = EFalse;
       
  7104 
       
  7105   if ( ECamCapturing  == iInfo.iOperation
       
  7106     || ECamPausing    == iInfo.iOperation
       
  7107     || ECamPaused     == iInfo.iOperation
       
  7108     || ECamResuming   == iInfo.iOperation
       
  7109     || ECamCompleting == iInfo.iOperation 
       
  7110      )
       
  7111     {
       
  7112     engineIsProcessing = ETrue;
       
  7113     }
       
  7114 
       
  7115   return engineIsProcessing;
       
  7116   }
       
  7117 
       
  7118 // ---------------------------------------------------------------------------
       
  7119 // CCamAppController::HandleIncomingCall
       
  7120 // Stop video recording (or burst capture in early stages)
       
  7121 // ---------------------------------------------------------------------------
       
  7122 //
       
  7123 void CCamAppController::HandleIncomingCall()
       
  7124   {
       
  7125   PRINT2( _L("Camera => CCamAppController::HandleIncomingCallL .. mode[%s] operation[%s]"), 
       
  7126           KCamModeNames[iInfo.iMode], 
       
  7127           KCamCaptureOperationNames[iInfo.iOperation]
       
  7128         );
       
  7129 
       
  7130   if( ECamControllerVideo == iInfo.iMode )
       
  7131     {
       
  7132     // if video is recording or paused
       
  7133     if ( !iSaving
       
  7134       && ( ECamCapturing == iInfo.iOperation
       
  7135         || ECamPaused    == iInfo.iOperation ) )
       
  7136       {
       
  7137       StopVideoRecording();  
       
  7138       }
       
  7139     }
       
  7140   else if( ECamControllerImage == iInfo.iMode )
       
  7141     {
       
  7142     iCaptureRequested = EFalse;
       
  7143     switch( iInfo.iImageMode ) 
       
  7144       {
       
  7145       // if a timelapse operation is in progress
       
  7146       case ECamImageCaptureTimeLapse:
       
  7147         {
       
  7148         TRAP_IGNORE( StopSequenceCaptureL() );
       
  7149         break;
       
  7150         }
       
  7151       case ECamImageCaptureBurst:
       
  7152         {
       
  7153         TRAP_IGNORE( SoftStopBurstL( ETrue ) );
       
  7154         /*
       
  7155         if ( ECamCompleting == iInfo.iOperation )
       
  7156           {
       
  7157           // if some of the image captures failed
       
  7158           // release the reserved filenames and tidy the array
       
  7159           TInt captured( iCameraController->ControllerInfo().iCaptureCount );
       
  7160           if ( BurstCaptureArray()->NextFileIndex() < captured )
       
  7161             {
       
  7162             TInt index;
       
  7163             TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7164             for ( index = BurstCaptureArray()->NextFileIndex(); index < stopAt; index++ )
       
  7165               {
       
  7166               SetAsCurrentImage( index );
       
  7167               DeleteCurrentFile();
       
  7168               }
       
  7169             SetAsCurrentImage( 0 );
       
  7170       
       
  7171             BurstCaptureArray()->Reset( BurstCaptureArray()->NextFileIndex() );
       
  7172             // Finished with this now
       
  7173             }
       
  7174 //          SetImageMode( ECamImageCaptureNone );
       
  7175           if( iImageSaveActive )
       
  7176             iImageSaveActive->DismissProgressNote();
       
  7177           StartIdleTimer();
       
  7178           }
       
  7179         */
       
  7180         break;
       
  7181         }
       
  7182       default:
       
  7183         break;
       
  7184       }
       
  7185     }
       
  7186   else
       
  7187     {
       
  7188     // no action needed
       
  7189     }
       
  7190   PRINT( _L( "Camera <= CCamAppController::HandleIncomingCallL" ) ); 
       
  7191   }
       
  7192 
       
  7193     
       
  7194 // ---------------------------------------------------------------------------
       
  7195 // CCamAppController::FileSize
       
  7196 // Returns the file size of the specified captured item, or KErrNotFound if doesn't exist
       
  7197 // ---------------------------------------------------------------------------
       
  7198 //
       
  7199 TInt CCamAppController::FileSize( TDesC& aFilename ) const
       
  7200   {       
       
  7201   return iImageSaveActive->FileSize( aFilename );
       
  7202   }
       
  7203 
       
  7204 // ---------------------------------------------------------------------------
       
  7205 // CCamAppController::CancelStillCaptureNow
       
  7206 // Immediately cancels an ongoing still capture
       
  7207 // ---------------------------------------------------------------------------
       
  7208 //
       
  7209 void CCamAppController::CancelStillCaptureNow()
       
  7210   {
       
  7211   PRINT( _L( "Camera => CCamAppController::CancelStillCaptureNow" ) )
       
  7212   // Re-enable screen saver
       
  7213   EnableScreenSaver( ETrue ); 
       
  7214 //    iEngine->CancelCaptureStill();
       
  7215   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  7216 
       
  7217   // ensure that any outstanding images are discarded
       
  7218   SetOperation( ECamCompleting  );
       
  7219   SetOperation( ECamNoOperation );
       
  7220 
       
  7221   // If sequence mode, remove items from the array
       
  7222   // this prevents the post capture view from showing
       
  7223   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7224     {
       
  7225     BurstCaptureArray()->Reset( 0 );
       
  7226     }   
       
  7227   else // single capture, the array is no longer needed
       
  7228     {
       
  7229     PRINT( _L( "Camera <> single capture so releasing array and starting vf" ) )
       
  7230     ReleaseArray();
       
  7231     FreezeViewFinder( EFalse );
       
  7232     }
       
  7233   // Cancel any pending saves, this will call CompleteBurstOperation for sequence
       
  7234   PRINT( _L( "Camera <> calling iImageSaveArray->Cancel" ) )
       
  7235   iImageSaveActive->Cancel(); 
       
  7236   PRINT( _L( "Camera <= CCamAppController::CancelStillCaptureNow" ) )
       
  7237   }
       
  7238     
       
  7239 
       
  7240 
       
  7241 // ---------------------------------------------------------------------------
       
  7242 // CCamAppController::TidyCaptureArray
       
  7243 // Tidy up capture array in event of burst capture failure
       
  7244 // ---------------------------------------------------------------------------
       
  7245 //
       
  7246 void
       
  7247 CCamAppController::TidyCaptureArray( TInt aImageCountDelivered, 
       
  7248                                      TInt /*aError*/               )
       
  7249   {
       
  7250   PRINT1( _L("Camera => CCamAppController::TidyCaptureArray img count %d"), aImageCountDelivered )
       
  7251   iSoundPlayer->EnableAllKeySounds();
       
  7252 
       
  7253   // if some of the image captures failed
       
  7254   // release the reserved filenames and tidy the array
       
  7255 
       
  7256   TInt captured( iCameraController->ControllerInfo().iSnapshotCount );
       
  7257   if ( aImageCountDelivered < captured )
       
  7258     {
       
  7259     TInt index;
       
  7260     TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7261     for ( index = aImageCountDelivered; index < stopAt; index++ )
       
  7262       {
       
  7263       PRINT1( _L("Camera <> TidyCaptureArray delete current %d"),index )
       
  7264       SetAsCurrentImage( index );
       
  7265       DeleteCurrentFile();
       
  7266       }
       
  7267     SetAsCurrentImage( 0 );
       
  7268     iCaptureArray->Reset( aImageCountDelivered );
       
  7269     // Finished with this now
       
  7270     }
       
  7271 
       
  7272   SetImageMode( ECamImageCaptureNone );
       
  7273   StartIdleTimer();
       
  7274 
       
  7275   // Need to release the array
       
  7276   ReleaseArray();
       
  7277 
       
  7278 
       
  7279   // Unfreeze the viewfinder
       
  7280   FreezeViewFinder( EFalse );
       
  7281 
       
  7282   // Change op state to none
       
  7283   SetOperation( ECamNoOperation );
       
  7284 
       
  7285   PRINT( _L("Camera <= CCamAppController::TidyCaptureArray") )
       
  7286   }
       
  7287 
       
  7288 
       
  7289 // ---------------------------------------------------------------------------
       
  7290 // CCamAppController::CaptureToneId
       
  7291 // Returns the current capture tone
       
  7292 //
       
  7293 // ---------------------------------------------------------------------------
       
  7294 //
       
  7295 TCamSoundId CCamAppController::CaptureToneId( )
       
  7296   {
       
  7297   TCamSoundId toneId = ECamStillCaptureSoundId1;
       
  7298 
       
  7299   switch(iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoCaptureTone ) )
       
  7300     {
       
  7301     case ECamSettTone1:
       
  7302       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7303         {
       
  7304         toneId = ECamBurstCaptureSoundId1;
       
  7305         }
       
  7306       else 
       
  7307         {
       
  7308         toneId = ECamStillCaptureSoundId1;
       
  7309         }
       
  7310       break;
       
  7311     case ECamSettTone2:
       
  7312       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7313         {
       
  7314         toneId = ECamBurstCaptureSoundId2;
       
  7315         }
       
  7316       else 
       
  7317         {
       
  7318         toneId = ECamStillCaptureSoundId2;
       
  7319         }
       
  7320       break;
       
  7321     case ECamSettTone3:
       
  7322       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7323         {
       
  7324         toneId = ECamBurstCaptureSoundId3;
       
  7325         }
       
  7326       else 
       
  7327         {
       
  7328         toneId = ECamStillCaptureSoundId3;
       
  7329         }
       
  7330       break;
       
  7331     case ECamSettTone4:
       
  7332       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7333         {
       
  7334         toneId = ECamBurstCaptureSoundId4;
       
  7335         }
       
  7336       else 
       
  7337         {
       
  7338         toneId = ECamStillCaptureSoundId4;
       
  7339         }
       
  7340       break;
       
  7341     default:
       
  7342       break;
       
  7343     }
       
  7344 
       
  7345   return toneId;
       
  7346   }
       
  7347 
       
  7348 // ---------------------------------------------------------------------------
       
  7349 // CCamAppController::LoadSecondaryCameraSettingsL()
       
  7350 // Update settings for secondary camera
       
  7351 // ---------------------------------------------------------------------------
       
  7352 //  
       
  7353 void CCamAppController::LoadSecondaryCameraSettingsL()
       
  7354   {
       
  7355   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 1" );
       
  7356   PRINT( _L("Camera => CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7357   iSettingsModel->StorePrimaryCameraSettingsL();
       
  7358   iSettingsModel->StoreUserSceneSettingsL();
       
  7359 
       
  7360   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL B" ))
       
  7361   
       
  7362   SetIntegerSettingValueL( ECamSettingItemPhotoQuality, 
       
  7363                            iConfiguration->SecondaryCameraImageQuality() );
       
  7364   PRINT(  _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL C" ))
       
  7365   SetIntegerSettingValueL( ECamSettingItemVideoQuality,
       
  7366                            iConfiguration->SecondaryCameraVideoQuality() );  
       
  7367 
       
  7368     
       
  7369 
       
  7370   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL E" ))
       
  7371   SetIntegerSettingValueL( ECamSettingItemDynamicPhotoScene, ECamSceneAuto );
       
  7372   SetIntegerSettingValueL( ECamSettingItemDynamicVideoScene, ECamSceneNormal );
       
  7373   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL F" ))
       
  7374 
       
  7375   PRINT( _L("Camera <= CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7376   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 0" );
       
  7377   }
       
  7378 
       
  7379 // ---------------------------------------------------------------------------
       
  7380 // ImageOrientation <<public>>
       
  7381 //
       
  7382 // Return the current image orientation based on data from orientation sensor.
       
  7383 // If "image rotation" setting is OFF, the value has been overriden with 
       
  7384 // "no rotation" value (ECamOrientation0).
       
  7385 // 
       
  7386 // Provided (primarily) for Camera Controller even if orientation
       
  7387 // sensor is not supported. In that case the returned
       
  7388 // value is always ECamOrientation0.
       
  7389 // ---------------------------------------------------------------------------
       
  7390 //
       
  7391 TCamImageOrientation 
       
  7392 CCamAppController::ImageOrientation() const
       
  7393   {
       
  7394   return iImageOrientation;
       
  7395   }
       
  7396 
       
  7397 
       
  7398 // ---------------------------------------------------------------------------
       
  7399 // Indicates data is available in the receiving buffer. A client can read 
       
  7400 // the data through GetData()-function in the related channel object. Data 
       
  7401 // is valid until the data received notification occurs again.
       
  7402 //
       
  7403 // @param[in] aChannel Reference to the related channel object
       
  7404 // @param[in] aCount Data object count in receiving buffer. Not used in this implementation.
       
  7405 // @param[in] aDataLost Number of lost data items. Not used in this implementation. It does not
       
  7406 //     matter if some data event is lost.
       
  7407 // ---------------------------------------------------------------------------
       
  7408 //
       
  7409 void CCamAppController::DataReceived( CSensrvChannel& aChannel, 
       
  7410                                       TInt aCount, 
       
  7411                                       TInt aDataLost )
       
  7412     {
       
  7413     PRINT3( _L("Camera => CCamAppController::DataReceived aChannel %d aCount %d aDataLost %d"), 
       
  7414                 aChannel.GetChannelInfo().iChannelType, aCount, aDataLost );
       
  7415 
       
  7416     if ( KSensrvChannelTypeIdOrientationData == aChannel.GetChannelInfo().iChannelType )
       
  7417         {
       
  7418         TBool rotate( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) 
       
  7419                       || iInfo.iActiveCamera == ECamActiveCameraSecondary );
       
  7420 
       
  7421         if( rotate )
       
  7422             {
       
  7423             TSensrvOrientationData orientationData;
       
  7424             TPckg<TSensrvOrientationData> orientationPackage( orientationData );
       
  7425             aChannel.GetData( orientationPackage );
       
  7426 
       
  7427             iImageOrientation =
       
  7428                 MapSensorOrientatio2CamOrientation( orientationData.iDeviceOrientation, iLastImageOrientation );
       
  7429             }
       
  7430         else
       
  7431             {
       
  7432             // If "rotate images" setting is OFF, set "no rotation" value
       
  7433             iImageOrientation = ECamOrientation0;
       
  7434             }
       
  7435         
       
  7436         // rotate image if we are in still capture mode but not currently
       
  7437         // capturing image, no rotation in burst mode or if orientation has stayed the same
       
  7438         if( IsFlagOn( CameraControllerState(), ECamImageOn ) && 
       
  7439             rotate && 
       
  7440             iLastImageOrientation != iImageOrientation &&
       
  7441             iImageOrientation != ECamOrientationIgnore)
       
  7442             {
       
  7443             if( ECamCapturing   != CurrentOperation() &&
       
  7444                 ECamFocusing    != CurrentOperation() &&
       
  7445                 ECamFocused     != CurrentOperation() &&
       
  7446                 ECamFocusFailed != CurrentOperation() &&
       
  7447                 ECamCompleting  != CurrentOperation() &&
       
  7448                 ECamImageCaptureBurst != iInfo.iImageMode &&
       
  7449                 ECamImageCaptureBurst != iInfo.iTargetImageMode )
       
  7450                 {
       
  7451                 PRINT( _L("Camera <> CCamAppController:DataReceived calling SetImageOrientationL()") );	
       
  7452                 TRAP_IGNORE( SetImageOrientationL() );
       
  7453                 }
       
  7454             else
       
  7455                 {
       
  7456                 // queue a request to re-prepare still capture
       
  7457                 PRINT( _L("Camera <> CCamAppController: Queueing an orientation change event") );	
       
  7458                 iOrientationChangeOccured = ETrue;
       
  7459                 }
       
  7460             }
       
  7461         else
       
  7462             {
       
  7463             iOrientationChangeOccured = EFalse;
       
  7464             }
       
  7465         
       
  7466         if( iImageOrientation != ECamOrientationIgnore )    
       
  7467             {
       
  7468             iLastImageOrientation = iImageOrientation; 	           
       
  7469             }
       
  7470         }
       
  7471 
       
  7472     PRINT ( _L("Camera <= CCamAppController::DataReceived") );
       
  7473     }
       
  7474 
       
  7475 // ---------------------------------------------------------------------------
       
  7476 // Data listening failed. 
       
  7477 // If error was fatal, channel has also been closed and sensor server session 
       
  7478 // terminated. If error was minor, some data has potentially been lost.
       
  7479 // iAccSensorChannel needs to be closed in fatal error case. A new channel will
       
  7480 // be created the next time we call UpdateSensorApiL().
       
  7481 //
       
  7482 // @param[in] aChannel Reference to the related channel object
       
  7483 // @param[in] aError Error code.
       
  7484 // ---------------------------------------------------------------------------
       
  7485 //
       
  7486 void CCamAppController::DataError( CSensrvChannel& aChannel, 
       
  7487                                    TSensrvErrorSeverity aError )
       
  7488     {
       
  7489     PRINT2( _L("Camera => CCamAppController::DataError aChannel %d aError %d"), aChannel.GetChannelInfo().iChannelType, aError );	
       
  7490     if ( ESensrvErrorSeverityFatal == aError ) 
       
  7491         {
       
  7492         // Delete sensor api object
       
  7493         delete iAccSensorChannel;
       
  7494         iAccSensorChannel = NULL;
       
  7495         iAccSensorListening = EFalse;
       
  7496 
       
  7497         // Set orientation back to default if not already there.
       
  7498         iImageOrientation   = ECamOrientation0;
       
  7499         }
       
  7500     }
       
  7501 
       
  7502 // ---------------------------------------------------------------------------
       
  7503 // Returns a pointer to a specified interface 
       
  7504 //
       
  7505 // @since S60 5.0
       
  7506 // @param aInterfaceUid Identifier of the interface to be retrieved
       
  7507 // @param aInterface A reference to a pointer that retrieves the specified interface.
       
  7508 // ---------------------------------------------------------------------------
       
  7509 //
       
  7510 void CCamAppController::GetDataListenerInterfaceL( TUid aInterfaceUid, 
       
  7511                                                    TAny*& aInterface )
       
  7512     {
       
  7513     aInterface = NULL;
       
  7514     }                                
       
  7515                                         
       
  7516 // ---------------------------------------------------------------------------
       
  7517 // CCamAppController::SetImageOrientationL()
       
  7518 // Setup image rotation parameters
       
  7519 //
       
  7520 // ---------------------------------------------------------------------------
       
  7521 //  
       
  7522 void CCamAppController::SetImageOrientationL()
       
  7523     {
       
  7524     PRINT( _L("Camera => CCamAppController::SetImageOrientationL") );
       
  7525     if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  7526     		&& iCameraController )
       
  7527         {
       
  7528         // Camera controller asks for the current orientation through
       
  7529         // our ImageOrientation(). Value for that was updated in 
       
  7530         // DataReceived() callback.
       
  7531         iCameraController->DirectSettingsChangeL( ECameraSettingOrientation );
       
  7532         }
       
  7533     PRINT( _L("Camera <= CCamAppController::SetImageOrientationL"))   
       
  7534     }
       
  7535 
       
  7536 
       
  7537 // ---------------------------------------------------------------------------
       
  7538 // MapSensorOrientatio2CamOrientation
       
  7539 // ---------------------------------------------------------------------------
       
  7540 //
       
  7541 TCamImageOrientation 
       
  7542 CCamAppController::MapSensorOrientatio2CamOrientation( 
       
  7543     const TSensrvOrientationData::TSensrvDeviceOrientation& aSensorOrientation, TCamImageOrientation aLastImageOrientation )
       
  7544     {
       
  7545     PRINT1 ( _L("Camera => CCamAppController::MapSensorOrientatio2CamOrientation aSensorOrientation: %d"), aSensorOrientation );   
       
  7546 
       
  7547     TCamImageOrientation cameraOrientation( ECamOrientation0 );
       
  7548 
       
  7549     switch( aSensorOrientation )
       
  7550         {        
       
  7551         case TSensrvOrientationData::EOrientationDisplayUpwards:
       
  7552             // If coming from upside down portrait...
       
  7553             if ( ECamOrientation270 == aLastImageOrientation )
       
  7554               {
       
  7555             	// Switch from upside down portrait to normal portrait.") )
       
  7556               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7557               }
       
  7558             // If coming from upside down landscape...
       
  7559             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7560               {
       
  7561             	// Switch from upside down landscape to normal landscape...") )
       
  7562               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7563               }
       
  7564             // If neither one, keep the current image orientation.
       
  7565             else
       
  7566               {
       
  7567               cameraOrientation = ECamOrientationIgnore;
       
  7568               }
       
  7569             break;
       
  7570 
       
  7571         case TSensrvOrientationData::EOrientationDisplayDownwards:
       
  7572         	  // Camera is pointing up now. Check if it was upside down previously.
       
  7573             // If coming from upside down portrait...
       
  7574             if ( ECamOrientation270 == aLastImageOrientation )
       
  7575               {
       
  7576             	// Switch from upside down portrait to normal portrait...") )
       
  7577               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7578               }
       
  7579             // If coming from upside down landscape...
       
  7580             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7581               {
       
  7582             	// Switch from upside down landscape to normal landscape...") )
       
  7583               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7584               }
       
  7585             // If neither one, keep the current image orientation.
       
  7586             else
       
  7587               {
       
  7588               cameraOrientation = ECamOrientationIgnore;
       
  7589               }
       
  7590         	  break;
       
  7591         case TSensrvOrientationData::EOrientationDisplayRightUp:            
       
  7592         case TSensrvOrientationData::EOrientationUndefined:
       
  7593             cameraOrientation = ECamOrientation0;     
       
  7594             break;
       
  7595         case TSensrvOrientationData::EOrientationDisplayUp:
       
  7596             cameraOrientation = ECamOrientation90;
       
  7597             break;
       
  7598         case TSensrvOrientationData::EOrientationDisplayLeftUp:
       
  7599             cameraOrientation = ECamOrientation180;
       
  7600             break;
       
  7601         case TSensrvOrientationData::EOrientationDisplayDown:
       
  7602             cameraOrientation = ECamOrientation270;
       
  7603             break;
       
  7604         default:
       
  7605             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7606             break;
       
  7607         }
       
  7608     PRINT1( _L("Camera <= CCamAppController::MapSensorOrientatio2CamOrientation, return [%s]"), 
       
  7609             KCamOrientationNames[cameraOrientation] );
       
  7610 
       
  7611     return cameraOrientation;
       
  7612     }
       
  7613 
       
  7614 // ---------------------------------------------------------------------------
       
  7615 // MapSensorOrientatio2CamOrientation
       
  7616 // ---------------------------------------------------------------------------
       
  7617 //
       
  7618 CBitmapRotator::TRotationAngle 
       
  7619 CCamAppController::MapCamOrientation2RotationAngle( 
       
  7620                    const TCamImageOrientation aOrientation )
       
  7621     {
       
  7622     PRINT1 ( _L("Camera => CCamAppController::MapCamOrientation2RotationAngle aOrientation: %d"), aOrientation );   
       
  7623 
       
  7624     CBitmapRotator::TRotationAngle angle;
       
  7625     
       
  7626     switch( aOrientation )
       
  7627         {        
       
  7628         case ECamOrientation90:
       
  7629             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7630             break;
       
  7631         case ECamOrientation180:
       
  7632             angle = CBitmapRotator::ERotation180DegreesClockwise;
       
  7633             break;
       
  7634         case ECamOrientation270:
       
  7635             angle = CBitmapRotator::ERotation270DegreesClockwise;
       
  7636             break;
       
  7637         default:
       
  7638             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7639             // using a value to avoid compiler warning
       
  7640             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7641             break;
       
  7642         }
       
  7643     PRINT1( _L("Camera <= CCamAppController::MapCamOrientation2RotationAngle, return %d"), angle );
       
  7644     return angle;    
       
  7645     }
       
  7646         
       
  7647         
       
  7648 // ---------------------------------------------------------------------------
       
  7649 // CCamAppController::UpdateSensorApiL() <<public>>
       
  7650 // Updates the sensorApi object when the app focus changes
       
  7651 //
       
  7652 // ---------------------------------------------------------------------------
       
  7653 //  
       
  7654 
       
  7655 void CCamAppController::UpdateSensorApiL(TBool aStartupApi) 
       
  7656     {
       
  7657     PRINT(_L("Camera => CCamAppController::UpdateSensorApiL"));
       
  7658     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  7659     	{
       
  7660 	    if(aStartupApi)
       
  7661 	        {
       
  7662 	        // only activate the orientation channel for image mode	
       
  7663 	        if( ECamControllerImage == CurrentMode() )
       
  7664 	          {
       
  7665 	        // This if-statement intentionally not a condition of the first if.
       
  7666 	        // If the iAccSensorChannel is already active, we don't want to recreate it
       
  7667 	        // and leak memory, but at the same time, we don't want to destroy it either.
       
  7668 	        
       
  7669 	        if( !iAccSensorChannel )
       
  7670 	            {
       
  7671 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - Starting new sensor channel api - info not yet initialized"));
       
  7672 	            //Construct a channel finder.
       
  7673 	            CSensrvChannelFinder* channelFinder;
       
  7674 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannelFinder::NewL()"));
       
  7675 	            //CSensorChannelFinder* channelFinder;
       
  7676 	            channelFinder = CSensrvChannelFinder::NewL();
       
  7677 	            //channelFinder = CSensorChannelFinder::NewL();
       
  7678 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - CSensrvChannelFinder::NewL() returned without a leave"));
       
  7679 	            CleanupStack::PushL( channelFinder );    
       
  7680 	            
       
  7681 	            //List of found channels.
       
  7682 	            RSensrvChannelInfoList channelInfoList;
       
  7683 	            CleanupClosePushL( channelInfoList );
       
  7684 	  
       
  7685 	            //Create and fill channel search criteria.
       
  7686 	            TSensrvChannelInfo channelInfo;
       
  7687 	            channelInfo.iChannelType = KSensrvChannelTypeIdOrientationData;
       
  7688 	        
       
  7689 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling channelFinder->FindChannelsL"));
       
  7690 	            //Find the orientation channel
       
  7691 	            channelFinder->FindChannelsL( channelInfoList, channelInfo );
       
  7692 	           
       
  7693 	            if( channelInfoList.Count() != 1 )
       
  7694 	                {
       
  7695 	                //The device doesn’t support orientation data channel or
       
  7696 	                //there are several orientation channels.
       
  7697 	                PRINT1(_L("Camera <=> CCamAppController::UpdateSensorApiL - The device doesn’t support orientation data channel or there are several orientation channels: %d channels found"),channelInfoList.Count());
       
  7698 	                User::Leave( KErrNotSupported );
       
  7699 	                }
       
  7700 	            else
       
  7701 	                {
       
  7702 	                //orientation channel found 
       
  7703 	                PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - orientation channel found"));
       
  7704 	                }
       
  7705 	            //Open the orientation channel.
       
  7706 	            //When the channel object is created the channel info object 
       
  7707 	            //must be an object returned by CSensrvChannelFinder::FindChannelsL().
       
  7708 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannel::NewL"));
       
  7709 	            iAccSensorChannel = CSensrvChannel::NewL( channelInfoList[ 0 ] );
       
  7710 	            //iAccSensorChannel = CSensorChannel::NewL( channelInfoList[ 0 ] );
       
  7711 	            //CleanupStack::PushL( iAccSensorChannel ); 
       
  7712 	            CleanupStack::PopAndDestroy( &channelInfoList ); //Close() is being called on "channelInfoList"
       
  7713 	            CleanupStack::PopAndDestroy( channelFinder );
       
  7714 	          }
       
  7715 	        
       
  7716 	        if( !iAccSensorListening )
       
  7717 	            {
       
  7718 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->OpenChannelL()"));
       
  7719 	            TRAPD(channelerror, iAccSensorChannel->OpenChannelL() );
       
  7720 	            if (channelerror!=KErrNone)
       
  7721 	                {
       
  7722 	                PRINT1(_L("CCamAppController::UpdateSensorApiL - iAccSensorChannel->OpenChannelL() failed. Error code: %d"),channelerror);
       
  7723 	                User::Leave( channelerror );
       
  7724 	                }
       
  7725 	            //iAccSensorChannel->OpenChannelL();
       
  7726 	            //orientation channel is now open.
       
  7727 	            
       
  7728 	            // start listening
       
  7729 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->StartDataListeningL"));
       
  7730 	            iAccSensorChannel->StartDataListeningL( this, //this object is data listener for this channel
       
  7731 	                                                   1, //aDesiredCount is one, i.e. each orientation change is notified separately
       
  7732 	                                                   1, //aMaximumCount is one, i.e. object count in receiving data buffer is one
       
  7733 	                                                   0 );//buffering period is not used
       
  7734 	            iAccSensorListening = ETrue;
       
  7735 	            iLastImageOrientation = ECamOrientation0;
       
  7736 	            }
       
  7737 	          }
       
  7738 	        }
       
  7739 	    else // shut down the sensorApi object
       
  7740 	        {
       
  7741 	        PRINT(_L("Camera <=> UpdateSensorApiL shutting down iAccSensor"))
       
  7742 	        if(iAccSensorListening)
       
  7743 	            {
       
  7744 	            // Stop listening to the events
       
  7745 	            iAccSensorChannel->StopDataListening();
       
  7746 	            iAccSensorListening = EFalse;
       
  7747 	            }
       
  7748 	            
       
  7749 	        // Delete sensor api object
       
  7750 	        delete iAccSensorChannel;
       
  7751 	        iAccSensorChannel = NULL;
       
  7752 	        }
       
  7753       }
       
  7754     PRINT(_L("Camera <= CCamAppController::UpdateSensorApiL"));
       
  7755     }
       
  7756 
       
  7757 
       
  7758 
       
  7759 // ---------------------------------------------------------------------------
       
  7760 // CCamAppController::HandlePropertyChangedL()
       
  7761 // Handle changes in specified property
       
  7762 //
       
  7763 // ---------------------------------------------------------------------------
       
  7764 //  
       
  7765 void CCamAppController::HandlePropertyChangedL( const TUid& aCategory, const TUint aKey )
       
  7766   {
       
  7767   PRINT( _L("Camera => CCamAppController::HandlePropertyChangedL"))
       
  7768 #if !( defined(__WINS__) || defined(__WINSCW__) )  
       
  7769   
       
  7770   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  7771       { 
       
  7772       // First if condition could be removed after PCFW has released 
       
  7773       // creation for KLensCoverStatus key
       
  7774       if ( ( aCategory == NMusResourceApi::KCategoryUid && 
       
  7775            aKey == NMusResourceApi::KCameraAvailability ) ||              
       
  7776            ( aCategory == CameraPlatPSKeys::KPSCameraPlatUid && 
       
  7777            aKey == CameraPlatPSKeys::KLensCoverStatus ) )        
       
  7778           {    
       
  7779 
       
  7780           TInt err = iSlideStateWatcher->Get( iNewSlideState );
       
  7781 
       
  7782           PRINT2( _L( "Camera HandlePropertyChangedL getting slider state = %d, err = %d" ), iNewSlideState, err )
       
  7783           
       
  7784           if ( iNewSlideState != iSlideState  )
       
  7785               {
       
  7786               delete iSliderCallBack;
       
  7787               iSliderCallBack = NULL;
       
  7788               iSliderCallBack = CPeriodic::NewL( CActive::EPriorityIdle );
       
  7789               iSliderCallBack->Start( KLensCoverDelay, KLensCoverDelay, TCallBack( LensCoverUpdateL, this ) );
       
  7790               }
       
  7791           }
       
  7792       else
       
  7793           {
       
  7794           (void)aCategory;
       
  7795           (void)aKey;
       
  7796           }
       
  7797 
       
  7798       }
       
  7799 #endif // !( defined(__WINS__) || defined(__WINSCW__        
       
  7800 
       
  7801   PRINT( _L("Camera <= CCamAppController::HandlePropertyChangedL"))
       
  7802 
       
  7803   }                             
       
  7804 
       
  7805 // ---------------------------------------------------------------------------
       
  7806 // CCamAppController::LensCoverUpdate()
       
  7807 // Callback function that is called when lens cover state changes.
       
  7808 // Used to implement delayed handling of lens cover events.
       
  7809 // ---------------------------------------------------------------------------
       
  7810 //  
       
  7811 TInt CCamAppController::LensCoverUpdateL( TAny* aPtr ) 
       
  7812     {
       
  7813     PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL()" ) )
       
  7814     CCamAppController* self = static_cast<CCamAppController*>( aPtr );
       
  7815     if ( self->iNewSlideState != self->iSlideState ||
       
  7816          self->iNewSlideState == CameraPlatPSKeys::EClosed // always handle closing
       
  7817        )
       
  7818         {
       
  7819 
       
  7820         self->iSlideState = self->iNewSlideState;
       
  7821 
       
  7822         if ( self->iSlideState == CameraPlatPSKeys::EClosed )
       
  7823             {
       
  7824             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE CLOSED" ) )
       
  7825             self->HandleSlideClosedL();
       
  7826             }
       
  7827         else if ( self->iSlideState == CameraPlatPSKeys::EOpen )
       
  7828             {
       
  7829             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE OPENED" ) )
       
  7830             self->HandleSlideOpenedL();
       
  7831             }
       
  7832         }
       
  7833     self->iSliderCallBack->Cancel();
       
  7834     delete self->iSliderCallBack;
       
  7835     self->iSliderCallBack = 0;
       
  7836             
       
  7837     PRINT( _L( "Camera <= CCamAppController::LensCoverUpdateL()" ) )
       
  7838     return KErrNone;
       
  7839 
       
  7840     }
       
  7841 // ---------------------------------------------------------------------------
       
  7842 // CCamAppController::RefreshSlideState
       
  7843 // Force a refresh of the slide status
       
  7844 // ---------------------------------------------------------------------------
       
  7845 //
       
  7846 void CCamAppController::RefreshSlideStatus()
       
  7847     {
       
  7848     PRINT( _L("Camera => CCamAppController::RefreshSlideStatus") );  
       
  7849     // read the slider status from P & S key
       
  7850     if ( iSlideStateWatcher->Get( iSlideState ) != KErrNone )
       
  7851            {
       
  7852            iSlideState = KErrNone;
       
  7853            }   
       
  7854     }
       
  7855       
       
  7856 // ---------------------------------------------------------------------------
       
  7857 // CCamAppController::HandleSlideClosedL
       
  7858 // Handle the slide closed event
       
  7859 // ---------------------------------------------------------------------------
       
  7860 //
       
  7861 void CCamAppController::HandleSlideClosedL()
       
  7862     {
       
  7863     PRINT( _L("Camera => CCamAppController::HandleSlideClosedL") );
       
  7864 
       
  7865     NotifyControllerObservers( ECamEventSliderClosed );
       
  7866     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  7867     
       
  7868     if ( appUi->IsInPretendExit() )
       
  7869         {
       
  7870         PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL already in pretend exit") );        
       
  7871         return;
       
  7872         }
       
  7873     SetCameraSwitchRequired( ESwitchDone );
       
  7874     // shutdown the camera on slide closing if EDGE variant/standalone app
       
  7875     // don't close app if embedded or embedding
       
  7876     TInt camerasAvailable = CamerasAvailable();
       
  7877     TVwsViewId activeView;
       
  7878     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  7879 
       
  7880     TBool embedded = appUi->IsEmbedded();
       
  7881     TBool embedding = appUi->Embedding();
       
  7882     if ( camerasAvailable == 1 ) // EDGE variant
       
  7883         {
       
  7884         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable == 1") );
       
  7885         // if embedding another app then don't exit just yet
       
  7886         if ( embedding )
       
  7887             {
       
  7888             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedding mode") );
       
  7889             // remember that the slider has been closed
       
  7890             iSliderCloseEvent = ETrue;
       
  7891             }
       
  7892         // Embedded post capture view
       
  7893         else if ( embedded && viewErr == KErrNone && 
       
  7894                 ( activeView.iViewUid.iUid == ECamViewIdStillPostCapture ||
       
  7895                   activeView.iViewUid.iUid == ECamViewIdVideoPostCapture ) )
       
  7896             {
       
  7897             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded post capture") );
       
  7898             // remember that the slider has been closed
       
  7899             iSliderCloseEvent = ETrue;
       
  7900             }
       
  7901         // if standalone app performing a burst capture, 
       
  7902         // don't exit till complete
       
  7903         else if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  7904                 ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7905             {
       
  7906             // remember that the slider has been closed
       
  7907             iSliderCloseEvent = ETrue;
       
  7908             StopSequenceCaptureL();
       
  7909             }
       
  7910         else // standalone or embedded pre capture view
       
  7911             {
       
  7912             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  7913             appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  7914             }
       
  7915         }
       
  7916     else // variants with > 1 camera
       
  7917         {
       
  7918         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable > 1") );
       
  7919         if ( !embedding && !embedded )
       
  7920             {
       
  7921             // if standalone app performing a burst capture, 
       
  7922             // don't exit till complete
       
  7923             if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  7924                  ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7925                 {
       
  7926                 // remember that the slider has been closed
       
  7927                 iSliderCloseEvent = ETrue;
       
  7928                 StopSequenceCaptureL();
       
  7929                 }
       
  7930             else
       
  7931                 {
       
  7932                 PRINT( _L("Camera Normal mode-handle ECamCmdSlideClosedExit") );
       
  7933                 appUi->SetLensCoverExit( ETrue ); 
       
  7934                 if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid ) 
       
  7935                    {
       
  7936                    // stop recording and save the video
       
  7937                    StopVideoRecording();                          
       
  7938                    }
       
  7939                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  7940                 appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  7941                 
       
  7942 				// 2ndary camera, slider closed -> application to be closed, 
       
  7943 				// not in embedded mode
       
  7944                 if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  7945                    {
       
  7946                    PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera slider closed, app closing...") );
       
  7947                    appUi->CloseAppL(); 
       
  7948                    }
       
  7949                 }
       
  7950             }
       
  7951         else // we are embedded in an app or embedding another app
       
  7952             {
       
  7953             // remember that the slider has been closed
       
  7954             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded/Embedding mode") );
       
  7955             
       
  7956             if ( viewErr == KErrNone )
       
  7957                 {
       
  7958                 iSliderCloseEvent = ETrue;
       
  7959 
       
  7960                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - active view %d"), activeView.iViewUid.iUid );
       
  7961                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - iInfo.iOperation %d"), iInfo.iOperation );
       
  7962     
       
  7963                 // switch the camera if slide is closed and primary camera
       
  7964                 // is active in embedded mode
       
  7965                 switch ( activeView.iViewUid.iUid )
       
  7966                     {
       
  7967                     case ECamViewIdStillPreCapture:
       
  7968                     case ECamViewIdVideoPreCapture:
       
  7969                         {
       
  7970                         // if in pre capture view and slide is closed
       
  7971                         if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  7972                             {
       
  7973                             if ( iInfo.iOperation != ECamPaused &&
       
  7974                                  iInfo.iOperation != ECamCapturing &&
       
  7975                                  iInfo.iOperation != ECamCompleting && 
       
  7976                                  iInfo.iOperation != ECamPausing &&
       
  7977                                  iInfo.iOperation != ECamResuming &&
       
  7978                                  !iVideoRequested )
       
  7979                                 {
       
  7980                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  7981                                 }
       
  7982                             else if ( iInfo.iOperation == ECamCapturing ||
       
  7983                                       iInfo.iOperation == ECamPaused )
       
  7984                                 {
       
  7985                                 StopVideoRecording();                                
       
  7986                                 }
       
  7987                             else if ( iVideoRequested )
       
  7988                                 {
       
  7989                                 StopVideoRecording();
       
  7990                                 // cancel any outstanding sound requests
       
  7991                                 iSoundPlayer->CancelAllPlaying();
       
  7992 
       
  7993                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  7994                                 }
       
  7995                             else // lint
       
  7996                                 {
       
  7997                                 }
       
  7998                             }
       
  7999                          else 
       
  8000                             {
       
  8001                             // Embedded camera not closed even if lens cover is closed.
       
  8002                             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera, no action..") );
       
  8003                             }
       
  8004                         }
       
  8005                         break;
       
  8006                     case ECamViewIdStillPostCapture:
       
  8007                     case ECamViewIdVideoPostCapture:
       
  8008                         {
       
  8009                         // Embedded camera not closed even if lens cover is closed.
       
  8010                         }
       
  8011                         break;
       
  8012                     default:
       
  8013                         break;
       
  8014                     }
       
  8015                 }
       
  8016                else if ( viewErr == KErrNotFound  )
       
  8017                 {
       
  8018                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - view not found") );
       
  8019                 if ( ECamActiveCameraPrimary == iInfo.iActiveCamera ) 
       
  8020                     {              
       
  8021                     PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - need switch to 2ndary") );
       
  8022                     SetCameraSwitchRequired( ESwitchPrimaryToSecondary );
       
  8023                     if ( !appUi->AppInBackground( ETrue ) )
       
  8024                         {
       
  8025                         appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8026                         }
       
  8027                     }
       
  8028                 }
       
  8029             }
       
  8030         }
       
  8031 
       
  8032     PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL") );
       
  8033     }
       
  8034 
       
  8035 // ---------------------------------------------------------------------------
       
  8036 // CCamAppController::HandleSlideOpenedL
       
  8037 // Handles the slide opened event
       
  8038 // ---------------------------------------------------------------------------
       
  8039 //
       
  8040 void CCamAppController::HandleSlideOpenedL()
       
  8041     {
       
  8042     PRINT( _L("Camera => CCamAppController::HandleSlideOpenedL") );
       
  8043     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8044     // reset slider event flag
       
  8045     if ( iSliderCloseEvent )
       
  8046         {
       
  8047         iSliderCloseEvent = EFalse;
       
  8048         }
       
  8049 
       
  8050     TVwsViewId activeView;
       
  8051     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  8052     if ( viewErr == KErrNone )
       
  8053         {
       
  8054         PRINT1( _L("Camera HandleSlideOpenedL => active view %d"), 
       
  8055                 activeView.iViewUid.iUid );
       
  8056 
       
  8057         // For EDGE variant 
       
  8058         TInt camerasAvailable = CamerasAvailable();
       
  8059         if ( camerasAvailable == 1 )
       
  8060             {
       
  8061             // if in standby view and the slide is opened then exit standby view
       
  8062             if ( iInfo.iOperation == ECamStandby )
       
  8063                 {
       
  8064                 PRINT( _L("Camera HandleSlideOpenedL => Exit Standby view") );
       
  8065                 appUi->View( activeView.iViewUid )->HandleCommandL( 
       
  8066                         ECamCmdExitStandby );
       
  8067                 }
       
  8068             }
       
  8069         else // variants with > 1 camera
       
  8070             {
       
  8071             PRINT1( _L("Camera HandleSlideOpenedL => iInfo.iOperation %d"), 
       
  8072                     iInfo.iOperation );
       
  8073             PRINT1( _L("Camera HandleSlideOpenedL => CameraState() %d"), 
       
  8074                     CameraState());
       
  8075             switch ( activeView.iViewUid.iUid )
       
  8076                 {
       
  8077                 // if we are in the photo/video capture view and the
       
  8078                 // second camera is enabled then switch to the main camera
       
  8079                 // so long as video/photo capture is not in progress
       
  8080                 case ECamViewIdStillPreCapture:
       
  8081                 case ECamViewIdVideoPreCapture:
       
  8082                     {
       
  8083                     if ( iInfo.iActiveCamera == ECamActiveCameraSecondary &&
       
  8084                          iInfo.iOperation != ECamCapturing &&
       
  8085                          iInfo.iOperation != ECamPaused &&
       
  8086                          iInfo.iOperation != ECamPausing &&
       
  8087                          iInfo.iOperation != ECamResuming &&
       
  8088                          iInfo.iOperation != ECamCompleting && 
       
  8089                          (CameraState() == ECamCameraPreparedImage ||
       
  8090                          CameraState() == ECamCameraPreparedVideo
       
  8091                          ||
       
  8092                          CameraState() == ECamCameraReserved ||
       
  8093                          CameraState() == ECamCameraPowerOn
       
  8094                          ) &&
       
  8095                          !VideoRecordPending() )
       
  8096                         {
       
  8097                         PRINT( _L("Camera precapture 2nd camera - switching now") ); 
       
  8098                         SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8099                         if ( !appUi->AppInBackground( ETrue ) )
       
  8100                             {
       
  8101                             appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8102                             }
       
  8103                         }
       
  8104                     else 
       
  8105                         {
       
  8106                         PRINT( _L("Camera capturing, paused etc. in precapview") );  
       
  8107                         
       
  8108                         if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid && 
       
  8109                            ( ECamCapturing == iInfo.iOperation || 
       
  8110                              ECamPaused == iInfo.iOperation ) ) 
       
  8111                             {
       
  8112                             StopVideoRecording(); // stop recording and save the video                         
       
  8113                             }
       
  8114                         if ( ECamActiveCameraSecondary == iInfo.iActiveCamera ) 
       
  8115                             {              
       
  8116                             PRINT( _L("Camera HandleSlideOpenedL, switchCamera") );
       
  8117                             SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8118                             if ( !appUi->AppInBackground( ETrue ) )
       
  8119                                 {
       
  8120                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8121                                 }
       
  8122                             }
       
  8123                         }
       
  8124                     }    
       
  8125                     break;
       
  8126                 case ECamViewIdStillPostCapture:
       
  8127                 case ECamViewIdVideoPostCapture:
       
  8128                     {
       
  8129                     if ( ECamActiveCameraSecondary == iInfo.iActiveCamera )
       
  8130                        {                    
       
  8131                        SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8132                        if ( !appUi->AppInBackground( ETrue ) )
       
  8133                            {
       
  8134                            appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8135                            }
       
  8136                        }
       
  8137                     }
       
  8138                     break;
       
  8139                 default:
       
  8140                     break;
       
  8141                 }
       
  8142             }       
       
  8143         }
       
  8144 
       
  8145     else if ( viewErr == KErrNotFound && 
       
  8146                 iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  8147           {
       
  8148           // If no view is found it means that camera is in background.
       
  8149           // We don't want to do camera switch in embdedded/embedding mode
       
  8150           // post-capture when in background
       
  8151           if ( ( !appUi->IsEmbedded() &&
       
  8152                  !appUi->Embedding() ) ||
       
  8153                appUi->CurrentViewState() != ECamViewStatePostCapture )
       
  8154               {
       
  8155               PRINT( _L("Camera HandleSlideOpenedL => view not found, 2nd active") );
       
  8156               iCameraSwitchRequired = ESwitchToUnknown;
       
  8157               }
       
  8158           }
       
  8159     else
       
  8160         {
       
  8161         }
       
  8162     NotifyControllerObservers( ECamEventSliderOpen );
       
  8163     PRINT( _L("Camera <= CamAppController::HandleSlideOpenedL") );
       
  8164     }
       
  8165 
       
  8166 
       
  8167 // ---------------------------------------------------------------------------
       
  8168 // CCamAppController::VideoViewFinderResourceId()
       
  8169 // Resource Id for video viewfinder layout
       
  8170 //
       
  8171 // ---------------------------------------------------------------------------
       
  8172 //    
       
  8173 TInt CCamAppController::VideoViewFinderResourceId( TCamVideoResolution aResolution )
       
  8174   {
       
  8175   PRINT( _L( "Camera => CCamAppController::VideoViewFinderResourceIdL"))
       
  8176   TInt vidVFRes;
       
  8177   
       
  8178     TCamOrientation orient = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->CamOrientation();   
       
  8179     if( orient == ECamOrientationCamcorder || orient == ECamOrientationCamcorderLeft )
       
  8180       {
       
  8181       vidVFRes = CamUtility::MapVideoQualityToViewFinderRes( aResolution );
       
  8182       }
       
  8183   else
       
  8184     {
       
  8185     TInt resId;
       
  8186     TInt err = CamUtility::GetPsiInt( ECamPsiVideoVFResSecondaryCamera, resId );
       
  8187     if( err )
       
  8188       {
       
  8189       vidVFRes = ROID( R_CAM_VIEWFINDER_RECT_CIF_ID );
       
  8190       }
       
  8191     else
       
  8192       {
       
  8193       vidVFRes = ROID( resId );
       
  8194       }
       
  8195     }
       
  8196     
       
  8197   PRINT1( _L( "Camera => CCamAppController::VideoViewFinderResourceId res id "), vidVFRes )
       
  8198   return vidVFRes;
       
  8199   }
       
  8200 
       
  8201 // ---------------------------------------------------------------------------
       
  8202 // CCamAppController::HandleObservedEvent()
       
  8203 // Receives event codes from observables
       
  8204 //
       
  8205 // ---------------------------------------------------------------------------
       
  8206 //
       
  8207 void CCamAppController::HandleObservedEvent( TCamObserverEvent aEvent )
       
  8208     {
       
  8209     switch( aEvent )
       
  8210         {
       
  8211         case ECamObserverEventCaptureProcessComplete:
       
  8212             {
       
  8213             NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  8214             }
       
  8215             break;
       
  8216         default:
       
  8217             break;            
       
  8218         }
       
  8219     }
       
  8220 
       
  8221 // ---------------------------------------------------------------------------
       
  8222 // CCamAppController::IsProfileSilent
       
  8223 // Return whether current profile is silent or not, uses warning
       
  8224 // tones setting to determine whether silent or not
       
  8225 // ---------------------------------------------------------------------------
       
  8226 //  
       
  8227 TBool CCamAppController::IsProfileSilent()
       
  8228     {
       
  8229     TRAPD( ignore, iSilentProfile = IsProfileSilentL() );
       
  8230     if ( ignore )
       
  8231         {
       
  8232         }
       
  8233     return iSilentProfile;
       
  8234     }
       
  8235 
       
  8236 
       
  8237 // ---------------------------------------------------------------------------
       
  8238 // CCamAppController::IsProfileSilentL
       
  8239 // Return whether current profile is silent or not, uses warning
       
  8240 // tones setting to determine whether silent or not
       
  8241 // ---------------------------------------------------------------------------
       
  8242 //  
       
  8243 TBool CCamAppController::IsProfileSilentL()
       
  8244     {
       
  8245     // get current keypad volume as indication of whether
       
  8246     // or not we have a silent profile
       
  8247     CRepository* cr = CRepository::NewLC( KCRUidProfileEngine );
       
  8248     TInt value;
       
  8249     User::LeaveIfError( cr->Get( KProEngActiveWarningTones, value ) );
       
  8250     CleanupStack::PopAndDestroy( cr );
       
  8251 
       
  8252     return ( value == 0 );
       
  8253     }
       
  8254 
       
  8255 
       
  8256 // ---------------------------------------------------------------------------
       
  8257 // ResetInactivityTimer <<static>>
       
  8258 // ---------------------------------------------------------------------------
       
  8259 //  
       
  8260 TInt 
       
  8261 CCamAppController::ResetInactivityTimer( TAny* /*aPtr*/ )
       
  8262   {
       
  8263 	PRINT( _L("Camera =><= CCamAppController::ResetInactivityTimer") );
       
  8264 
       
  8265   User::ResetInactivityTime();
       
  8266 
       
  8267 	return KErrNone;
       
  8268   }
       
  8269     
       
  8270 // ---------------------------------------------------------------------------
       
  8271 // CCamAppController::ToneShouldBeSilent
       
  8272 // Returns ETrue if the supplied toneId should be silent if the profile is 
       
  8273 // set to silent. Does *not* take into account network variant forcing 
       
  8274 // sounds on.
       
  8275 // ---------------------------------------------------------------------------
       
  8276 //      
       
  8277 TBool CCamAppController::ToneShouldBeSilent( TCamSoundId aSoundId )
       
  8278     {    
       
  8279     if ( aSoundId == CaptureToneId() ||
       
  8280          aSoundId == ECamVideoStartSoundId ||
       
  8281          aSoundId == ECamVideoStopSoundId ||
       
  8282          aSoundId == ECamVideoPauseSoundId ||
       
  8283          aSoundId == ECamVideoResumeSoundId ||
       
  8284          aSoundId == ECamAutoFocusComplete ||
       
  8285          aSoundId == ECamSelfTimerSoundId )
       
  8286         {
       
  8287         return ETrue;
       
  8288         }
       
  8289     else
       
  8290         {
       
  8291         return EFalse;
       
  8292         }         
       
  8293     }
       
  8294     
       
  8295 // ---------------------------------------------------------------------------
       
  8296 // CCamAppController::HandleCaptureCompletion
       
  8297 // Inform any observers that are waiting for a capture completion event
       
  8298 // ---------------------------------------------------------------------------
       
  8299 //  
       
  8300 void CCamAppController::HandleCaptureCompletion()
       
  8301   {
       
  8302   PRINT( _L( "Camera => CCamAppController::HandleCaptureCompletion()" ) )
       
  8303 
       
  8304   SetOperation( ECamNoOperation );
       
  8305   
       
  8306   // Re-enable screensaver
       
  8307   EnableScreenSaver( ETrue );
       
  8308 
       
  8309   // If mmc dismount notification came while saving, allow the dismount now
       
  8310   if( iDismountPending )
       
  8311     {
       
  8312     iDismountPending = EFalse;
       
  8313     iDriveChangeNotifier->SendAllowDismount();	
       
  8314     }
       
  8315   
       
  8316   // If any observers are waiting for a capture completion event
       
  8317   if ( iCaptureCompletionObserverHandler )
       
  8318     {
       
  8319     iCaptureCompletionObserverHandler->BroadcastEvent( ECamObserverEventCaptureProcessComplete );
       
  8320     delete iCaptureCompletionObserverHandler;
       
  8321     iCaptureCompletionObserverHandler = NULL;
       
  8322     }
       
  8323 
       
  8324   // If the camera orientation changed during capture and not in burst mode, 
       
  8325   // set the new orientation
       
  8326   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  8327        && iOrientationChangeOccured
       
  8328        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  8329     {
       
  8330     iOrientationChangeOccured = EFalse;
       
  8331     TRAP_IGNORE( SetImageOrientationL() );
       
  8332     }
       
  8333 
       
  8334   if ( iPendingRelease )
       
  8335     {
       
  8336        PRINT( _L( "Camera <> CCamAppController::HandleCaptureCompletion(), DATAMAKE2" ) )        	
       
  8337        ReleaseCamera();
       
  8338     }
       
  8339   PRINT( _L( "Camera <= CCamAppController::HandleCaptureCompletion()" ) )        
       
  8340   }    
       
  8341 
       
  8342 
       
  8343 
       
  8344 // ---------------------------------------------------------------------------
       
  8345 // CCamAppController::CheckAfModeForScene
       
  8346 // Checks the current scene/based on scene to see if AF mode needs setting
       
  8347 // ---------------------------------------------------------------------------
       
  8348 //           
       
  8349 void CCamAppController::CheckAfModeForScene( TBool aForceAFReset )
       
  8350     {
       
  8351     PRINT(_L("Camera => CCamAppController::CheckAfModeForScene"));
       
  8352 
       
  8353     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8354         {
       
  8355         TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );
       
  8356         }
       
  8357 
       
  8358     PRINT(_L("Camera <= CCamAppController::CheckAfModeForScene"));
       
  8359     }
       
  8360 
       
  8361 
       
  8362 // ---------------------------------------------------------------------------
       
  8363 // CCamAppController::TryAutoFocus
       
  8364 // Start an AF operation, if needed
       
  8365 // ---------------------------------------------------------------------------
       
  8366 //      
       
  8367 TBool CCamAppController::TryAutoFocus()   
       
  8368     {  
       
  8369     PRINT( _L("Camera => CCamAppController::TryAutoFocus()") );  
       
  8370     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_TRYAUTOFOCUS, "e_CAM_APP_AF_LOCK 1" );  //CCORAPP_AF_LOCK_START
       
  8371     
       
  8372     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8373         {
       
  8374         if( ECamActiveCameraPrimary != iInfo.iActiveCamera ||
       
  8375             ECamControllerImage != iInfo.iMode )
       
  8376           {
       
  8377           PRINT( _L("Returning EFalse - Not using primary camera in still mode") );  
       
  8378           // Not using primary camera in still mode      
       
  8379           return EFalse; // Not focusing
       
  8380           }
       
  8381                 
       
  8382         PRINT( _L("Calling IssueDirectRequestL( ECamRequestStartAutofocus )") );       
       
  8383         return TryAFRequest( ECamRequestStartAutofocus );
       
  8384         }
       
  8385     else 
       
  8386         {
       
  8387         return ETrue;
       
  8388         }
       
  8389     }
       
  8390 
       
  8391 
       
  8392 // ---------------------------------------------------------
       
  8393 // CCamAppController::CurrentSceneHasForcedFocus
       
  8394 // Returns whether the current scene has focus forced to 
       
  8395 // a particular value ( eg Macro/Landscape modes may have
       
  8396 // focus fixed to Macro/Infinite )
       
  8397 // ---------------------------------------------------------
       
  8398 //  
       
  8399 TBool CCamAppController::CurrentSceneHasForcedFocus() const
       
  8400     {
       
  8401     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8402         {
       
  8403         // Work out what the current scene is (or if current scene is user
       
  8404         // scene, what it's based on).
       
  8405         TInt currentScene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  8406         if ( currentScene  == ECamSceneUser )
       
  8407             {
       
  8408             currentScene = IntegerSettingValue( ECamSettingItemUserSceneBasedOnScene );
       
  8409             }
       
  8410 
       
  8411         TBool isFaceTrackingOn = (iConfigManager &&
       
  8412                     iConfigManager->IsFaceTrackingSupported() &&
       
  8413                     (iSettingsModel->IntegerSettingValue( 
       
  8414                     ECamSettingItemFaceTracking ) == ECamSettOn ) );
       
  8415     
       
  8416         // Check if the current (or based on) scene is one that should *not* have 
       
  8417         // a reticule.
       
  8418         if ( ( currentScene == ECamSceneScenery 
       
  8419           || currentScene == ECamSceneNightScenery 
       
  8420           || currentScene == ECamSceneSports )
       
  8421           && !isFaceTrackingOn )
       
  8422             {
       
  8423             return ETrue;
       
  8424             }
       
  8425         else
       
  8426             {
       
  8427             return EFalse;
       
  8428             }
       
  8429         }
       
  8430     else
       
  8431         {
       
  8432         return ETrue;
       
  8433         }
       
  8434     }
       
  8435 
       
  8436 // ---------------------------------------------------------------------------
       
  8437 // CCamAppController::CaptureToneDelayTimeout
       
  8438 // Timeout from capture tone delay timer
       
  8439 // ---------------------------------------------------------------------------
       
  8440 //
       
  8441 TInt CCamAppController::CaptureToneDelayTimeout( TAny* aPtr )
       
  8442     {
       
  8443     PRINT( _L("Camera => CCamAppController::CaptureToneDelayTimeoutL") )
       
  8444     static_cast<CCamAppController*>( aPtr )->PlayDelayedCaptureTone();
       
  8445     return KErrNone;
       
  8446     }
       
  8447 
       
  8448 // ---------------------------------------------------------------------------
       
  8449 // CCamAppController::PlayDelayedCaptureTone
       
  8450 // Play capture tone
       
  8451 // ---------------------------------------------------------------------------
       
  8452 //  
       
  8453 void CCamAppController::PlayDelayedCaptureTone()
       
  8454     {
       
  8455     PlaySound( CaptureToneId(), EFalse );
       
  8456     }
       
  8457 
       
  8458 // ---------------------------------------------------------------------------
       
  8459 // CCamAppController::InitAutoFocusL
       
  8460 // Initalises the AutoFocus interface, if needed
       
  8461 // ---------------------------------------------------------------------------
       
  8462 //
       
  8463 void CCamAppController::InitAutoFocusL()
       
  8464     {
       
  8465     PRINT( _L("Camera => CCamAppController::InitAutoFocusL") )
       
  8466     PRINT(_L("Camera !! DISABLED"));
       
  8467     PRINT( _L("Camera <= CCamAppController::InitAutoFocusL") )
       
  8468     }
       
  8469 
       
  8470 // ---------------------------------------------------------------------------
       
  8471 // CCamAppController::CopySnapshotIfNeededL
       
  8472 // Helper function for McaeoSnapImageReady that makes a copy of the snapshot
       
  8473 // if needed to fake a viewfinder or for image rotation.
       
  8474 // ---------------------------------------------------------------------------
       
  8475 //
       
  8476 
       
  8477 void 
       
  8478 CCamAppController::CopySnapshotIfNeeded( const CFbsBitmap& aSnapshot, TInt aError )
       
  8479   { 
       
  8480   if ( ECamImageCaptureTimeLapse == iInfo.iImageMode 
       
  8481     || ECamControllerVideo == iInfo.iMode   
       
  8482     || ( iConfigManager && iConfigManager->IsOrientationSensorSupported() &&
       
  8483         ( iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) == ECamSettOn 
       
  8484           || iInfo.iActiveCamera == ECamActiveCameraSecondary ) )
       
  8485      )
       
  8486     {
       
  8487     StopIdleTimer();
       
  8488     delete iSnapShotCopy;
       
  8489     iSnapShotCopy = NULL;
       
  8490     TRAP_IGNORE ( ( iSnapShotCopy = new(ELeave) CFbsBitmap() ) );
       
  8491     
       
  8492     if ( iSnapShotCopy )
       
  8493       {
       
  8494       TInt dupeError = iSnapShotCopy->Duplicate( aSnapshot.Handle() );
       
  8495       
       
  8496       if ( dupeError )
       
  8497         {
       
  8498         iSnapShotCopy->Reset();
       
  8499         delete iSnapShotCopy;
       
  8500         iSnapShotCopy = NULL;
       
  8501         }
       
  8502       else if ( iConfigManager && !iConfigManager->IsOrientationSensorSupported() )
       
  8503         {
       
  8504         if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  8505           {
       
  8506           // simulate the receipt of a viewfinder frame using the snapshot image
       
  8507           // McaeoViewFinderFrameReady( *iSnapShotCopy, aError );  
       
  8508           HandleViewfinderFrame( aError, iSnapShotCopy );
       
  8509           }
       
  8510         }                
       
  8511       }        
       
  8512     }
       
  8513   }
       
  8514 
       
  8515 
       
  8516 
       
  8517 // ---------------------------------------------------------------------------
       
  8518 // CCamAppController::EnableScreenSaver
       
  8519 // Turns the screen saver on or off for timelapse capture
       
  8520 //
       
  8521 // ---------------------------------------------------------------------------
       
  8522 //  
       
  8523 void 
       
  8524 CCamAppController::EnableScreenSaver( TBool aEnable )  
       
  8525   {
       
  8526   if ( !aEnable ) 
       
  8527     {
       
  8528     // Stop the screensaver from appearing
       
  8529     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 1 );        
       
  8530     }
       
  8531   else
       
  8532     {
       
  8533     // Allow the screensaver to appear
       
  8534     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 0 );
       
  8535     User::ResetInactivityTime();      
       
  8536     }        
       
  8537   }
       
  8538 
       
  8539 
       
  8540 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  8541 // ---------------------------------------------------------------------------
       
  8542 // CCamAppController::SetPerformanceState
       
  8543 //
       
  8544 // ---------------------------------------------------------------------------
       
  8545 //  
       
  8546 void CCamAppController::SetPerformanceState( TCamPerformanceState aState )  
       
  8547   {
       
  8548   iPerformanceState = aState;
       
  8549   }
       
  8550 #endif
       
  8551 
       
  8552 // ---------------------------------------------------------------------------
       
  8553 // CCamAppController::StartLocationTrailL()
       
  8554 // Connects and starts the locationtrail
       
  8555 // ---------------------------------------------------------------------------
       
  8556 //
       
  8557 void CCamAppController::StartLocationTrailL()
       
  8558   {
       
  8559   PRINT( _L("Camera => CCamAppController::StartLocationTrailL") );
       
  8560   CCamAppUi* appUI = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8561 
       
  8562   // If a stop request is pending but the trail is being restarted, stop 
       
  8563   // and delete the timer
       
  8564   if( iLocationTrailTimer )
       
  8565   	{
       
  8566   	iLocationTrailTimer->Cancel();
       
  8567    	delete iLocationTrailTimer;
       
  8568    	iLocationTrailTimer = NULL;
       
  8569    	}
       
  8570   
       
  8571   TInt err = KErrNone;
       
  8572 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) 
       
  8573   if ( !iLocationTrailStarted )
       
  8574 	  {
       
  8575 	  if ( !iLocationUtilityConnected ) 
       
  8576 	    {
       
  8577 	    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Connect()") );
       
  8578 	    TVwsViewId activeView;
       
  8579 	    if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8580 	      {
       
  8581 	      if( ECamViewIdStillPreCapture == activeView.iViewUid.iUid  )
       
  8582 	          {
       
  8583 	          CCamPreCaptureViewBase* view = static_cast<CCamPreCaptureViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8584 	          view->SetLocationTrailConnecting();
       
  8585 	          }
       
  8586 	      }
       
  8587 	    User::LeaveIfError( iLocationUtility.Connect() );
       
  8588 	    iLocationUtilityConnected = ETrue;
       
  8589 	    }
       
  8590 	  err = iLocationUtility.StartLocationTrail( RLocationTrail::ECaptureAll );
       
  8591 	  }
       
  8592 #endif
       
  8593   // If start fails, change the setting to off 
       
  8594   if( KErrNone != err )
       
  8595     {
       
  8596     PRINT1( _L("Camera :: CCamAppController::StartLocationTrailL error:%d encountered while starting location trail"), err )
       
  8597     
       
  8598 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8599     // Disconnect from the location utility
       
  8600     PRINT( _L("Camera => CCamAppController::StartLocationTrailL - Starting of LocationTrail failed -> iLocationUtility.Close()") );
       
  8601     iLocationUtility.Close();
       
  8602     iLocationUtilityConnected = EFalse;
       
  8603     SetIntegerSettingValueL( ECamSettingItemRecLocation, ECamLocationOff );
       
  8604 #endif
       
  8605     
       
  8606     // Going to standby mode, location trail disabled
       
  8607 	  /*
       
  8608     TVwsViewId activeView;
       
  8609     if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8610       {
       
  8611       CCamViewBase* view = static_cast<CCamViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8612       view->SwitchToStandbyModeL( TCamAppViewIds(activeView.iViewUid.iUid), err );
       
  8613       }
       
  8614       */
       
  8615     appUI->SetStandbyStatus( err );
       
  8616     appUI->HandleCommandL( ECamCmdGoToStandby );
       
  8617     }
       
  8618   else
       
  8619   	{
       
  8620   	iLocationTrailStarted = ETrue;
       
  8621   	}
       
  8622   PRINT( _L("Camera <= CCamAppController::StartLocationTrailL") );
       
  8623   }
       
  8624 
       
  8625 // ---------------------------------------------------------------------------
       
  8626 // CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8627 // Stops the locationtrail
       
  8628 // ---------------------------------------------------------------------------
       
  8629 //    
       
  8630 void CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8631 	  {
       
  8632 	  PRINT1( _L("Camera => CCamAppController::StopLocationTrail operation mode:%d"), iInfo.iOperation );
       
  8633 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8634 	  if( iLocationTrailStarted )
       
  8635 		{
       
  8636 		// if not ECamCapturing, ECamPausing, ECamPaused, ECamResuming or ECamCompleting
       
  8637 		if( (iInfo.iOperation < ECamCapturing || iInfo.iOperation > ECamCompleting ) && 
       
  8638 		    ( CurrentFullFileName() == KNullDesC || SavedCurrentImage() )
       
  8639 		  )
       
  8640 			{
       
  8641 			PRINT( _L("Camera :: CCamAppController::StopLocationTrail - stopping location trail") )
       
  8642 			iLocationUtility.StopLocationTrail();
       
  8643 			if ( aCloseSession ) 
       
  8644 			    {
       
  8645 			    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Close()") );
       
  8646 			    iLocationUtility.Close();
       
  8647 			    iLocationUtilityConnected = EFalse;
       
  8648 			    }
       
  8649 			iLocationTrailStarted = EFalse;
       
  8650 			
       
  8651 			// If a timer was used to stop the location trail, then cancel and delete the timer
       
  8652 	        if( iLocationTrailTimer )
       
  8653 	        	{
       
  8654 	        	iLocationTrailTimer->Cancel();
       
  8655 	        	delete iLocationTrailTimer;
       
  8656 	        	iLocationTrailTimer = NULL;
       
  8657 	        	}		
       
  8658 			}
       
  8659 		else
       
  8660 			{
       
  8661 			// Use a timer to close the trail in a few seconds
       
  8662 	    	PRINT( _L("Camera :: CCamAppController::StopLocationTrail - location trail in use") )
       
  8663 	    	if( !iLocationTrailTimer )
       
  8664 	    		{
       
  8665 	    		TRAP_IGNORE( iLocationTrailTimer = CCamTimer::NewL( KLocTrailCloseRetryTime, 
       
  8666 	    		  TCallBack( CCamAppController::RetryStopLocationTrail, this ) ) );
       
  8667 	    		}
       
  8668 	    	else // restart the timer
       
  8669 	    		{
       
  8670 				iLocationTrailTimer->Cancel();
       
  8671 				iLocationTrailTimer->SetTimeout( KLocTrailCloseRetryTime );
       
  8672 	    		}
       
  8673 	    	iLocationTrailTimer->StartTimer();
       
  8674 			}
       
  8675 		}
       
  8676 	#endif
       
  8677 	  PRINT( _L("Camera <= CCamAppController::StopLocationTrail") );
       
  8678 	  }
       
  8679 
       
  8680 // ---------------------------------------------------------------------------
       
  8681 // CCamAppController::RetryStopLocationTrail()
       
  8682 // Timer callback function to attempt to remove the location trail periodically
       
  8683 // ---------------------------------------------------------------------------
       
  8684 //    
       
  8685 TInt CCamAppController::RetryStopLocationTrail( TAny* aPtr )
       
  8686 	{
       
  8687 	PRINT( _L("Camera => CCamAppController::RetryStopLocationTrail") )
       
  8688 	static_cast<CCamAppController*>( aPtr )->StopLocationTrail();
       
  8689 	PRINT( _L("Camera <= CCamAppController::RetryStopLocationTrail") )
       
  8690 	return KErrNone;
       
  8691 	}
       
  8692   
       
  8693 // -----------------------------------------------------------------------------
       
  8694 // CCamAppController::CaptureKeyPressedWhileImageSaving
       
  8695 // Whether or not a capture key pressed during image saving
       
  8696 // -----------------------------------------------------------------------------
       
  8697 //
       
  8698 TBool CCamAppController::CaptureKeyPressedWhileImageSaving() const
       
  8699 	{
       
  8700 	return iCaptureKeyPressedWhileImageSaving;
       
  8701 	}
       
  8702 	
       
  8703 // -----------------------------------------------------------------------------
       
  8704 // CCamAppController::SetCaptureKeyPressedWhileImageSaving
       
  8705 // -----------------------------------------------------------------------------
       
  8706 //
       
  8707 void CCamAppController::SetCaptureKeyPressedWhileImageSaving(TBool aCaptureKeyPressed)
       
  8708 	{
       
  8709 	iCaptureKeyPressedWhileImageSaving = aCaptureKeyPressed;
       
  8710 	}
       
  8711   
       
  8712 
       
  8713 
       
  8714 // ---------------------------------------------------------------------------
       
  8715 // CamerasAvailable <<static>>
       
  8716 //
       
  8717 // Commonly needed in UI classes, so added also support to get this info
       
  8718 // through this class. This way we avoid unnecessary binding of 
       
  8719 // CCameraController and UI classes.
       
  8720 // ---------------------------------------------------------------------------
       
  8721 //
       
  8722 TInt 
       
  8723 CCamAppController::CamerasAvailable()
       
  8724   {
       
  8725   return CCamCameraController::CamerasAvailable();
       
  8726   }
       
  8727 
       
  8728 TBool 
       
  8729 CCamAppController::TimeLapseSupported()
       
  8730   {
       
  8731   return (ECamSupportOn == iSettingsModel->VariantInfo().iTimeLapseSupport);
       
  8732   }
       
  8733     
       
  8734 TBool 
       
  8735 CCamAppController::AlwaysOnSupported()
       
  8736   {
       
  8737   return (ECamSupportOn == iSettingsModel->VariantInfo().iAlwaysOnSupport);
       
  8738   }
       
  8739 
       
  8740 const TVersion& 
       
  8741 CCamAppController::Version()
       
  8742   {
       
  8743   return iSettingsModel->VariantInfo().iVersion;
       
  8744   }
       
  8745 
       
  8746 
       
  8747 // <<public>>
       
  8748 TBool 
       
  8749 CCamAppController::Busy() const
       
  8750   {
       
  8751   return (EBusyNone != iBusyFlags || CameraControllerBusy() );
       
  8752   }
       
  8753 
       
  8754 TBool 
       
  8755 CCamAppController::CameraControllerBusy() const
       
  8756   {
       
  8757   return (iCameraController && ECamBusyOff != iCameraController->ControllerInfo().iBusy );
       
  8758   }
       
  8759 
       
  8760 // ===========================================================================
       
  8761 // From MCamCameraObserver
       
  8762 
       
  8763 // ---------------------------------------------------------------------------
       
  8764 // HandleCameraEventL <<virtual>>
       
  8765 // ---------------------------------------------------------------------------
       
  8766 //
       
  8767 void 
       
  8768 CCamAppController
       
  8769 ::HandleCameraEventL( TInt              aStatus, 
       
  8770                       TCamCameraEventId aEventId, 
       
  8771                       TAny*             aEventData /*= NULL*/ )
       
  8772   {
       
  8773 #ifdef _DEBUG    
       
  8774   // Log viewfinder events with PRINT_FRQ
       
  8775   // #ifdef _DEBUG is used to avoid extra if in release builds
       
  8776   // where logging is not used anyway.
       
  8777   if( ECamCameraEventVfFrameReady == aEventId )  
       
  8778     {
       
  8779     PRINT_FRQ1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  8780           KCamCameraEventNames[aEventId] );    
       
  8781     }
       
  8782   else
       
  8783 #endif // _DEBUG    
       
  8784     {
       
  8785     PRINT1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  8786             KCamCameraEventNames[aEventId] );
       
  8787     }
       
  8788  
       
  8789   // in case we get poweron event before appui is completely constructed
       
  8790   // finish it here
       
  8791   if ( aEventId == ECamCameraEventPowerOn )
       
  8792       {
       
  8793       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8794       if ( iConfigManager && 
       
  8795            iConfigManager->IsUIOrientationOverrideSupported() && 
       
  8796            !appUi->IsUiConstructionComplete() )
       
  8797           {
       
  8798           appUi->AppUIConstructCallbackL( appUi );  
       
  8799           }
       
  8800       }       
       
  8801 
       
  8802   TInt handleError( KErrNone );
       
  8803 
       
  8804   if( ECamCameraEventVfFrameReady != aEventId &&
       
  8805       KErrNone == aStatus || KErrDiskFull == aStatus || KErrCompletion == aStatus ) 
       
  8806     {
       
  8807     // Called for all events, except viewfinder frame ready event.    
       
  8808     SetStateFromEvent( aEventId );
       
  8809     }
       
  8810   
       
  8811   if( ECamCameraEventImageInit == aEventId ||
       
  8812       ECamCameraEventVideoInit == aEventId )
       
  8813     {  
       
  8814     iSettingsRestoreNeeded = ETrue;  
       
  8815     }
       
  8816 
       
  8817 
       
  8818   // NOTE: Consider that the ones needing these events
       
  8819   //       receive them directly from Camera Controller?
       
  8820   switch( aEventId )
       
  8821     {
       
  8822     case ECamCameraEventVfStart:
       
  8823       {
       
  8824       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  8825       // For forced focus scenes, do one autofocus request once vf starts if needed
       
  8826       if( UiConfigManagerPtr()->IsAutoFocusSupported() )
       
  8827         {
       
  8828         if( CurrentSceneHasForcedFocus() || UiConfigManagerPtr()->IsAutofocusSetInHyperfocalAtStartup() ) 
       
  8829             {
       
  8830             PRINT( _L( "Camera => CCamAppController::HandleCameraEventL, TryAFRequest( ECamRequestCancelAutofocus )") );
       
  8831             TryAFRequest( ECamRequestCancelAutofocus ); 
       
  8832             }
       
  8833         }
       
  8834       if( iSettingsRestoreNeeded )
       
  8835         {
       
  8836         iSettingsRestoreNeeded = EFalse;  
       
  8837         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  8838         }
       
  8839       // fixed toolbar is used only with touch devices
       
  8840       if ( IsTouchScreenSupported() )
       
  8841           {
       
  8842           appUi->SetToolbarVisibility();// avoid flickering in settings view
       
  8843           PRINT( _L( "Camera <> SetToolbarVisibility done ") );
       
  8844           }
       
  8845       // else use AP    
       
  8846       else
       
  8847           {
       
  8848           if( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() )
       
  8849               {
       
  8850               NotifyControllerObservers( ECamEventInitReady );
       
  8851               }
       
  8852           }
       
  8853       
       
  8854       if ( UiConfigManagerPtr()->IsLocationSupported() &&
       
  8855                    !appUi->IsEmbedded())
       
  8856               {
       
  8857               if( ECamLocationOn == IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  8858                   {
       
  8859                   if( ECamActiveCameraPrimary == ActiveCamera() && ECamStandby != CurrentOperation() )
       
  8860                       {
       
  8861                       StartLocationTrailL();
       
  8862                       }
       
  8863                   else // Secondary camera 
       
  8864                       {
       
  8865                       PRINT( _L("Camera: CCamAppController::HandleCameraEventL - secondary camera, stop location trail") )
       
  8866                       StopLocationTrail();
       
  8867                       }
       
  8868                   }
       
  8869               }
       
  8870       break;
       
  8871       }
       
  8872     case ECamCameraEventVfFrameReady:
       
  8873       {      
       
  8874       HandleViewfinderFrame( aStatus, static_cast<CFbsBitmap*>( aEventData ) );
       
  8875       
       
  8876       if( KErrNone == aStatus && iSettingsRestoreNeeded )
       
  8877         {
       
  8878         iSettingsRestoreNeeded = EFalse;  
       
  8879         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  8880         }
       
  8881       return;
       
  8882       }
       
  8883     case ECamCameraEventSsReady:
       
  8884       {
       
  8885       TRAP_IGNORE( HandleSnapshotEvent( aStatus, static_cast<CFbsBitmap*>( aEventData ) ) );
       
  8886       
       
  8887       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  8888              CurrentCapturedCount() < CaptureLimit() )
       
  8889             {
       
  8890             // check memory level
       
  8891             TInt memoryLeft = 0;
       
  8892             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  8893                                           
       
  8894             if ( memoryLeft < KCriticalMemoryLevel )
       
  8895                 {
       
  8896                 PRINT( _L("Camera <> RAM is below critical level #1") )
       
  8897                 // memory below critical level, need to stop capture
       
  8898                 SoftStopBurstL( ETrue );
       
  8899                 EventHandlingErrorRecovery( KErrNoMemory );
       
  8900                 }
       
  8901             }
       
  8902       
       
  8903       break;
       
  8904       }
       
  8905     case ECamCameraEventImageData:
       
  8906       {
       
  8907 //      TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<HBufC8*>( aEventData ) ) ); 
       
  8908       TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<CCamBufferShare*>( aEventData ) ) );
       
  8909       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  8910              CurrentCapturedCount() < CaptureLimit() )
       
  8911             {
       
  8912             // check memory level
       
  8913             TInt memoryLeft = 0;
       
  8914             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  8915             if ( memoryLeft < KCriticalMemoryLevel )
       
  8916                 {
       
  8917                 PRINT( _L("Camera <> RAM is below critical level #2") )
       
  8918                 // memory below critical level, need to stop capture
       
  8919                 TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  8920                 EventHandlingErrorRecovery( KErrNoMemory );
       
  8921                 }
       
  8922             }
       
  8923       break;
       
  8924       }
       
  8925     case ECamCameraEventImageStop:
       
  8926       {
       
  8927       TRAP( aStatus, HandleImageStopEventL( aStatus, aEventData ? *static_cast<TInt*>( aEventData ) : 0 ) );
       
  8928       break;
       
  8929       }
       
  8930 
       
  8931     case ECamCameraEventAutofocusSuccessful: // Flowthrough
       
  8932     case ECamCameraEventAutofocusFailed:
       
  8933       {        
       
  8934       // Autofocusing is done, do possible pending capture  
       
  8935       SetAfNeeded( EFalse );
       
  8936       if( iCaptureRequested && !EngineProcessingCapture() )
       
  8937         {
       
  8938         iCaptureRequested = EFalse;
       
  8939         OstTrace0( CAMERAAPP_PERFORMANCE, DUP7_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_AF 0" );
       
  8940         OstTrace0( CAMERAAPP_PERFORMANCE, DUP8_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_AF_LOCK 0" );
       
  8941         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_SNAPSHOT 1" );
       
  8942         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SNAPSHOT 1" );
       
  8943         OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SAVE 1" );
       
  8944         OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SHOT 1" );
       
  8945         OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_STILL 1" );
       
  8946         OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_CAPTURE_START 1" );
       
  8947         OstTrace0( CAMERAAPP_PERFORMANCE, DUP6_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SERIAL_SHOOTING 1" );
       
  8948         
       
  8949         Capture();  
       
  8950         }           
       
  8951       break;  
       
  8952       }
       
  8953       
       
  8954     case ECamCameraEventSettingsSingle:
       
  8955       {
       
  8956       TRAP_IGNORE( HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  8957       return;
       
  8958       }
       
  8959     case ECamCameraEventVideoAsyncStop: 
       
  8960     case ECamCameraEventVideoStop:
       
  8961       {
       
  8962       // we always want to handle these events. set the flag because
       
  8963       // there is a possibility that some other event has come before
       
  8964       // and caused the flag to be cleared
       
  8965       SetFlags(iBusyFlags, EBusyRequest);
       
  8966       if ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) 
       
  8967 	     && CurrentStorage() == ECamMediaStorageCard )
       
  8968       	{
       
  8969         aStatus = KErrNone; 
       
  8970       	}
       
  8971       if( aStatus != KErrNone && aStatus != KErrDiskFull && aStatus != KErrCompletion 
       
  8972               && !( aStatus == KErrPathNotFound && IsCaptureStoppedForUsb() ) )
       
  8973           {
       
  8974           iSaving = EFalse;
       
  8975           SetOperation( ECamStandby, KErrGeneral );
       
  8976           }
       
  8977       else
       
  8978           {
       
  8979           // In case of no error, we are already in appropriate state
       
  8980           }
       
  8981 	  break;
       
  8982       }
       
  8983     case ECamCameraEventIveRecover:  
       
  8984       {
       
  8985       if( !Busy() )
       
  8986         {
       
  8987         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Issue new recovery sequence" ) );
       
  8988         SetStateFromEvent( ECamCameraEventReserveLose );  
       
  8989         SetTargetMode( ECamControllerImage );
       
  8990         SetTargetImageMode( CurrentImageModeSetup() );
       
  8991         IssueModeChangeSequenceL();
       
  8992         }
       
  8993       else
       
  8994         {
       
  8995         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Recovery sequence is active" ) );
       
  8996         }
       
  8997       break;
       
  8998       }
       
  8999     case ECamCameraEventSequenceEnd:
       
  9000       {
       
  9001       // only for image mode	
       
  9002       if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  9003           && ECamControllerImage == CurrentMode() )
       
  9004         {	
       
  9005         // If the camera orientation changed during initialization sequence and not in burst mode, 
       
  9006         // set the new orientation
       
  9007         if ( iOrientationChangeOccured &&
       
  9008              iInfo.iImageMode != ECamImageCaptureBurst )  
       
  9009           {
       
  9010           iOrientationChangeOccured = EFalse;
       
  9011           TRAP_IGNORE( SetImageOrientationL() );
       
  9012           }
       
  9013         if( !iAccSensorListening )
       
  9014           {
       
  9015           TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  9016           }
       
  9017         }
       
  9018         if ( aStatus == KErrCancel )
       
  9019             {
       
  9020             // sequence canceled, no need to event further
       
  9021             return;
       
  9022             }
       
  9023       break;
       
  9024       }  
       
  9025     default:
       
  9026       break;
       
  9027     }
       
  9028 
       
  9029 
       
  9030   // -------------------------------------------------------
       
  9031   // We have requested a series of operations.
       
  9032   // The sequences have ids, which we use to determine
       
  9033   // the right procedure. React when sequence ends.
       
  9034   if( IsFlagOn( iBusyFlags, EBusySequence ) )
       
  9035     {
       
  9036     PRINT( _L( "Camera <> Sequence of requests pending" ) );
       
  9037     TRAP( handleError, HandleSequenceEventL( aStatus, aEventId, aEventData ) );
       
  9038     }
       
  9039   // -------------------------------------------------------
       
  9040   // We have single request pending.
       
  9041   else if( IsFlagOn( iBusyFlags, EBusyRequest ) )
       
  9042     {
       
  9043     PRINT( _L( "Camera <> Single request pending" ) );
       
  9044     TRAP( handleError, HandleRequestEventL( aStatus, aEventId, aEventData ) );
       
  9045     }
       
  9046   else if( IsFlagOn( iBusyFlags, EBusySetting ) )
       
  9047     {
       
  9048     PRINT( _L( "Camera <> Settings finished" ) );
       
  9049     TRAP( handleError, HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  9050     }
       
  9051   // -------------------------------------------------------
       
  9052   // No request pending for us.
       
  9053   // Direct request issued to Camera controller.
       
  9054   else
       
  9055     {
       
  9056     PRINT( _L( "Camera <> No requests pending!!" ) );
       
  9057     // handle these ..
       
  9058     }
       
  9059 
       
  9060   // -------------------------------------------------------
       
  9061   if( KErrNone != handleError )
       
  9062     {
       
  9063     EventHandlingErrorRecovery( handleError );
       
  9064     }
       
  9065 
       
  9066   // Reserve lost event is always handled.
       
  9067   if( ECamCameraEventReserveLose == aEventId && KErrNone != aStatus )
       
  9068     {
       
  9069     SetOperation( ECamStandby, aStatus );
       
  9070     }
       
  9071     
       
  9072   if( iPendingRelease && !Busy() &&
       
  9073       !IsSavingInProgress() && iInfo.iOperation != ECamCapturing ) 
       
  9074     {  
       
  9075     // Finally, if camera release is pending, and we are no longer busy,
       
  9076     // call ReleaseCamera to get it done.
       
  9077     // ReleaseCamera is used instead of simply setting iInfo.iTargetMode,
       
  9078     // because it also handles stopping ongoing burst captures.
       
  9079     PRINT( _L( "Camera <> CCamAppController::HandleCameraEventL, release pending, calling ReleaseCamera..") );
       
  9080     ReleaseCamera();  
       
  9081     }    
       
  9082 
       
  9083 #ifdef _DEBUG    
       
  9084   // Log viewfinder events with PRINT_FRQ
       
  9085   if( ECamCameraEventVfFrameReady == aEventId )  
       
  9086     {
       
  9087     PRINT_FRQ( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );  
       
  9088     }
       
  9089   else  
       
  9090 #endif // _DEBUG    
       
  9091     {
       
  9092     PRINT( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );
       
  9093     }
       
  9094   }
       
  9095 
       
  9096 // ===========================================================================
       
  9097 
       
  9098 
       
  9099 // ---------------------------------------------------------------------------
       
  9100 // EventHandlingErrorRecovery
       
  9101 // ---------------------------------------------------------------------------
       
  9102 //
       
  9103 void
       
  9104 CCamAppController::EventHandlingErrorRecovery( TInt aError )
       
  9105   {
       
  9106   PRINT1( _L( "Camera => CCamAppController::EventHandlingErrorRecovery, error:%d" ), aError );
       
  9107 
       
  9108   __ASSERT_ALWAYS( aError != KErrNone, CamPanic( ECamPanicInvalidState ) );
       
  9109 
       
  9110   iCaptureModeTransitionInProgress = EFalse;
       
  9111 
       
  9112   // Reset the saving flag to ensure that camera does not get stuck
       
  9113   iSaving = EFalse;  
       
  9114 
       
  9115   iMuteNotifications = ETrue;
       
  9116 
       
  9117   // Cancel ongoing sequence if any
       
  9118   iCameraController->CancelSequence();
       
  9119 
       
  9120   // Clear busy flags
       
  9121   iBusyFlags           = EBusyNone;
       
  9122   iInfo.iBusyRequestId = ECamRequestNone;
       
  9123 
       
  9124   iMuteNotifications = EFalse;
       
  9125 
       
  9126   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9127   //Don't change to Stand by mode if -4 error gotten during burst (somehow expected)
       
  9128   if(SequenceCaptureInProgress() && appUi->CurrentBurstMode() == ECamImageCaptureBurst && KErrNoMemory == aError )
       
  9129     {
       
  9130     TRAP_IGNORE( appUi->HandleCameraErrorL(aError) );
       
  9131     }
       
  9132   else
       
  9133     {
       
  9134     SetOperation( ECamStandby, aError );
       
  9135     }
       
  9136 
       
  9137   NotifyControllerObservers( ECamEventControllerReady, aError );
       
  9138 
       
  9139   PRINT( _L( "Camera <= CCamAppController::EventHandlingErrorRecovery" ) );
       
  9140   }
       
  9141 
       
  9142 // ---------------------------------------------------------------------------
       
  9143 // HandleSettingEventL
       
  9144 // ---------------------------------------------------------------------------
       
  9145 //
       
  9146 void
       
  9147 CCamAppController::HandleSettingEventL( TInt              aStatus, 
       
  9148                                         TCamCameraEventId aEventId, 
       
  9149                                         TAny*             aEventData )
       
  9150   {
       
  9151   PRINT( _L( "Camera => CCamAppController::HandleSettingEventL" ) );
       
  9152   // -------------------------------------------------------
       
  9153   if( ECamCameraEventSettingsDone == aEventId )
       
  9154     {
       
  9155     ClearFlags( iBusyFlags, EBusySetting );
       
  9156 
       
  9157     // Need to clear any pending settings.
       
  9158     iSettingProvider->Reset();
       
  9159 
       
  9160     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9161       {
       
  9162       PRINT( _L( "Camera <> CCamAppController: Releasing camera.." ) );
       
  9163       IssueRequestL( ECamRequestRelease );
       
  9164       }
       
  9165     else
       
  9166       {
       
  9167       PRINT( _L( "Camera <> CCamAppController: Got setting end event.." ) );      
       
  9168       if( KErrNone != aStatus )
       
  9169         {
       
  9170         TCamCameraSettingId* cameraSetting =
       
  9171             static_cast<TCamCameraSettingId*>( aEventData );
       
  9172 
       
  9173         // Leave with the incoming error, if setting id not provided.
       
  9174         CheckNonNullL( cameraSetting, aStatus );
       
  9175 
       
  9176         if( ECameraSettingFileName == *cameraSetting )
       
  9177           {
       
  9178           DoVideoNameRetryL( aStatus );
       
  9179           }
       
  9180         else
       
  9181           {
       
  9182           User::Leave( aStatus );
       
  9183           }
       
  9184         }
       
  9185       else
       
  9186         {
       
  9187         ProceedPendingOrNotifyReadyL();
       
  9188         }
       
  9189       }
       
  9190     }
       
  9191   // -------------------------------------------------------
       
  9192   else if( ECamCameraEventSettingsSingle == aEventId )
       
  9193     {
       
  9194     TCamCameraSettingId* cameraSetting =
       
  9195         static_cast<TCamCameraSettingId*>( aEventData );
       
  9196 
       
  9197     CheckNonNullL( cameraSetting, KErrNotFound );
       
  9198     switch( *cameraSetting )
       
  9199       {
       
  9200       case ECameraSettingDigitalZoom:
       
  9201       case ECameraSettingOpticalZoom:
       
  9202         {
       
  9203         PRINT( _L( "Camera <> CCamAppController: zoom event" ) );
       
  9204         NotifyControllerObservers( ECamEventZoomStateChanged, aStatus );
       
  9205         // Pending zooming done in HandleViewfinderFrame
       
  9206         break;
       
  9207         }
       
  9208       default:
       
  9209         PRINT( _L( "Camera <> CCamAppController: unhandled setting event" ) );
       
  9210         break;
       
  9211       }
       
  9212     }
       
  9213   // -------------------------------------------------------
       
  9214   else
       
  9215     {
       
  9216     // Ignored
       
  9217     }
       
  9218   // -------------------------------------------------------
       
  9219   PRINT( _L( "Camera <= CCamAppController::HandleSettingEventL" ) );
       
  9220   }
       
  9221 
       
  9222 // ---------------------------------------------------------------------------
       
  9223 // DoVideoNameRetryL
       
  9224 // ---------------------------------------------------------------------------
       
  9225 //
       
  9226 void
       
  9227 CCamAppController::DoVideoNameRetryL( TInt aStatus )
       
  9228   {
       
  9229   PRINT( _L( "Camera => CCamAppController::DoVideoNameRetryL" ) );
       
  9230   if ( IsFlagOn( iCameraController->State(), ECamVideoOn )
       
  9231     && iVideoNameRetries > 0 )        
       
  9232     {
       
  9233     PRINT1( _L( "Camera <> video rename failed retries = %d retrying rename" ), iVideoNameRetries );
       
  9234 
       
  9235     // Try again
       
  9236     --iVideoNameRetries;
       
  9237     TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  9238     if ( ECamCapturing != iInfo.iOperation && ECamPaused != iInfo.iOperation )
       
  9239       {
       
  9240       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );    
       
  9241       }
       
  9242     IssueSettingsChangeRequestL();
       
  9243     }
       
  9244   else if ( KErrDiskFull         == aStatus 
       
  9245          && ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  9246     {
       
  9247     PRINT( _L( "Camera McaeoVideoPrepareComplete disk full and set to memory card " ) );
       
  9248     NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  9249 
       
  9250     // ForceUsePhoneMemory
       
  9251     if( ExistMassStorage() )
       
  9252         {
       
  9253         TRAP_IGNORE( 
       
  9254             {
       
  9255             iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9256             									     ECamMediaStorageMassStorage );
       
  9257             GenerateNextValidVideoPathL();
       
  9258             });
       
  9259         }
       
  9260     else
       
  9261         {
       
  9262         TRAP_IGNORE( 
       
  9263            {
       
  9264            iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9265                                                     ECamMediaStoragePhone );
       
  9266            GenerateNextValidVideoPathL();
       
  9267            });       
       
  9268         
       
  9269         }
       
  9270     iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoMediaStorage );        
       
  9271     IssueSettingsChangeRequestL();
       
  9272     }
       
  9273   // No retries left
       
  9274   else 
       
  9275     {
       
  9276     PRINT1( _L( "Camera <> video prep failed retries = %d removing iVideoRequested" ), iVideoNameRetries );
       
  9277     // remove pending request, so that new attempts to record are not blocked
       
  9278     if ( iVideoRequested )
       
  9279       iVideoRequested = EFalse;
       
  9280 
       
  9281     User::LeaveIfError( aStatus );
       
  9282     }
       
  9283   PRINT( _L( "Camera <= CCamAppController::DoVideoNameRetryL" ) );
       
  9284   }
       
  9285 
       
  9286 // ---------------------------------------------------------------------------
       
  9287 // HandleCameraSequenceComplete
       
  9288 // ---------------------------------------------------------------------------
       
  9289 //
       
  9290 void
       
  9291 CCamAppController::HandleSequenceEventL( TInt              aStatus, 
       
  9292                                          TCamCameraEventId aEventId, 
       
  9293                                          TAny*             /*aEventData*/ )
       
  9294   {
       
  9295   PRINT( _L( "Camera => CCamAppController::HandleSequenceEventL" ) );
       
  9296 
       
  9297   if( iDismountPending &&
       
  9298     ( ECamCameraEventImageInit == aEventId ||
       
  9299       ECamCameraEventVideoInit == aEventId ||
       
  9300       ECamCameraEventSequenceEnd == aEventId ) )
       
  9301     {
       
  9302     iDismountPending = EFalse;
       
  9303     iDriveChangeNotifier->SendAllowDismount();	
       
  9304     }
       
  9305   if( ECamCameraEventSequenceEnd == aEventId )
       
  9306     {
       
  9307     ClearFlags( iBusyFlags, EBusySequence );
       
  9308 
       
  9309     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9310       {
       
  9311       PRINT( _L( "Camera <> In shutdown mode!!" ) );
       
  9312       IssueRequestL( ECamRequestRelease );
       
  9313       }
       
  9314     else
       
  9315       {
       
  9316       User::LeaveIfError( aStatus );
       
  9317       if( iCameraController && !iCameraController->IsWaitingIveResources() )
       
  9318         {
       
  9319         PRINT( _L( "Camera <> sequence end, proceed with pending.." ) );
       
  9320         ProceedPendingOrNotifyReadyL();  
       
  9321         }
       
  9322       }
       
  9323     }
       
  9324 
       
  9325   PRINT( _L( "Camera <= CCamAppController::HandleSequenceEventL" ) );
       
  9326   }
       
  9327 
       
  9328 // ---------------------------------------------------------------------------
       
  9329 // HandleRequestEventL
       
  9330 // ---------------------------------------------------------------------------
       
  9331 //
       
  9332 void
       
  9333 CCamAppController::HandleRequestEventL( TInt              aStatus, 
       
  9334                                         TCamCameraEventId aEventId, 
       
  9335                                         TAny*             /*aEventData*/ )
       
  9336   {
       
  9337   PRINT( _L( "Camera => CCamAppController::HandleRequestEventL" ) );
       
  9338 
       
  9339   // Check if pending operations that need immediate attention.
       
  9340   if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && 
       
  9341       iInfo.iMode != ECamControllerShutdown && 
       
  9342       !iSaving && iInfo.iOperation != ECamCapturing && 
       
  9343       iInfo.iOperation != ECamCompleting ) 
       
  9344     {
       
  9345     PRINT( _L( "Camera <> in shutdown mode, release camera.." ) );
       
  9346     IssueDirectRequestL( ECamRequestRelease );
       
  9347     }
       
  9348   else
       
  9349     {
       
  9350     if( ECamCameraEventVideoStop == aEventId )
       
  9351       {
       
  9352       ClearFlags( iBusyFlags, EBusyRequest );
       
  9353       HandleVideoStopEvent( aStatus );
       
  9354       //If postcapture view is set to off notify controller ready event
       
  9355       //for updating counter.
       
  9356       if(IntegerSettingValue(ECamSettingItemVideoShowCapturedVideo)!=ECamSettOn )
       
  9357           {
       
  9358           NotifyControllerObservers( ECamEventControllerReady, KErrNone );
       
  9359           }
       
  9360       }
       
  9361     else if( ECamCameraEventVideoAsyncStop == aEventId )
       
  9362       {
       
  9363       HandleVideoAsyncStopEvent( aStatus );
       
  9364       }
       
  9365     else
       
  9366       {
       
  9367       // Error handling in one place
       
  9368       User::LeaveIfError( aStatus );
       
  9369   
       
  9370       // If our request is fully processed.
       
  9371       if( !CameraControllerBusy() )
       
  9372         {
       
  9373         PRINT( _L( "Camera <> camera not busy, proceed or notify ready.." ) );
       
  9374         ClearFlags( iBusyFlags, EBusyRequest );
       
  9375         ProceedPendingOrNotifyReadyL();
       
  9376         }
       
  9377       }
       
  9378     }
       
  9379   PRINT( _L( "Camera <= CCamAppController::HandleRequestEventL" ) );
       
  9380   }
       
  9381 
       
  9382 
       
  9383 // ---------------------------------------------------------------------------
       
  9384 // IssueRequestL
       
  9385 // ---------------------------------------------------------------------------
       
  9386 //
       
  9387 void
       
  9388 CCamAppController
       
  9389 ::IssueRequestL( const TCamCameraRequestId& aId )
       
  9390   {
       
  9391   PRINT1( _L("Camera => CCamAppController::IssueRequestL request[%s]"), KCamRequestNames[aId] );
       
  9392 
       
  9393   SetFlags( iBusyFlags, EBusyRequest );
       
  9394   iInfo.iBusyRequestId = aId;
       
  9395   
       
  9396   TRAPD( error, iCameraController->RequestL( iInfo.iBusyRequestId ) );
       
  9397   if( error != KErrNone )
       
  9398     {
       
  9399     ClearFlags( iBusyFlags, EBusyRequest );
       
  9400     iInfo.iBusyRequestId = ECamRequestNone;
       
  9401     User::Leave( error );
       
  9402     }
       
  9403 
       
  9404   PRINT( _L("Camera <= CCamAppController::IssueRequestL") );
       
  9405   }
       
  9406 
       
  9407 // ---------------------------------------------------------------------------
       
  9408 // IssueDirectRequestL
       
  9409 // ---------------------------------------------------------------------------
       
  9410 //
       
  9411 void
       
  9412 CCamAppController
       
  9413 ::IssueDirectRequestL( const TCamCameraRequestId& aId )
       
  9414   {
       
  9415   PRINT( _L("Camera => CCamAppController::IssueDirectRequestL") );
       
  9416   iCameraController->DirectRequestL( aId );
       
  9417   PRINT( _L("Camera <= CCamAppController::IssueDirectRequestL") );
       
  9418   }
       
  9419 
       
  9420 
       
  9421 // ---------------------------------------------------------------------------
       
  9422 // IssueSettingsChangeRequestL
       
  9423 // ---------------------------------------------------------------------------
       
  9424 //
       
  9425 void
       
  9426 CCamAppController::IssueSettingsChangeRequestL()
       
  9427   {
       
  9428   PRINT( _L("Camera => CCamAppController::IssueSettingsChangeRequestL") );
       
  9429   SetFlags( iBusyFlags, EBusySetting );
       
  9430 
       
  9431   TRAPD( error, iCameraController->RequestSettingsChangeL() );
       
  9432   if( KErrNone != error )
       
  9433     {
       
  9434     ClearFlags( iBusyFlags, EBusySetting );
       
  9435     User::Leave( error );
       
  9436     }
       
  9437   PRINT( _L("Camera <= CCamAppController::IssueSettingsChangeRequestL") );
       
  9438   }
       
  9439 
       
  9440 // ---------------------------------------------------------------------------
       
  9441 // ProceedPendingOrNotifyReadyL
       
  9442 // ---------------------------------------------------------------------------
       
  9443 //
       
  9444 void 
       
  9445 CCamAppController::ProceedPendingOrNotifyReadyL()
       
  9446   {
       
  9447   PRINT( _L("Camera => CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9448   PRINT4( _L("Camera <> iMode[%s] iTargetMode[%s] iImageMode[%s] iTargetImageMode[%s]"), 
       
  9449          KCamModeNames[iInfo.iMode], 
       
  9450          KCamModeNames[iInfo.iTargetMode], 
       
  9451          KCamImageModeNames[iInfo.iImageMode], 
       
  9452          KCamImageModeNames[iInfo.iTargetImageMode] );
       
  9453 
       
  9454   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  9455 
       
  9456   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9457 
       
  9458   if( iInfo.iMode != iInfo.iTargetMode )
       
  9459     {
       
  9460     if ( !IsInShutdownMode() && !iSaving && iInfo.iOperation != ECamCapturing ) 
       
  9461         {
       
  9462         PRINT( _L("Camera <> CCamAppController: not in target mode, need to issue requests") );
       
  9463         IssueModeChangeSequenceL();
       
  9464         }
       
  9465     }
       
  9466   else if( iCameraController->ViewfinderState() != iInfo.iTargetVfState &&
       
  9467            IsAppUiAvailable () &&
       
  9468            !appUi->AppInBackground( ETrue ) &&
       
  9469            !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() &&
       
  9470              iPendingRelease ) )
       
  9471     {
       
  9472     PRINT( _L("Camera <> CCamAppController: need to start/stop viewfinder..") );
       
  9473     IssueModeChangeSequenceL();
       
  9474     }
       
  9475   else if( iSettingProvider 
       
  9476         && iSettingProvider->PendingSettingChangeCount() > 0 )
       
  9477     {
       
  9478     PRINT( _L("Camera <> CCamAppController: settings pending, proceed now..") );
       
  9479     IssueSettingsChangeRequestL();
       
  9480     }
       
  9481   else if( iVideoPrepareNeeded )
       
  9482     {
       
  9483     PRINT( _L("Camera <> CCamAppController: video prepare pending, proceed now..") );
       
  9484     iVideoPrepareNeeded = EFalse;
       
  9485     IssueRequestL( ECamRequestVideoInit );
       
  9486     }
       
  9487   else
       
  9488     {
       
  9489     PRINT( _L("Camera <> CCamAppController: Target mode achieved") );
       
  9490     if( iCaptureModeTransitionInProgress )
       
  9491       {
       
  9492       PRINT( _L("Camera <> CCamAppController: capture mode transition complete") );
       
  9493       iCaptureModeTransitionInProgress = EFalse;
       
  9494       SetImageMode( iInfo.iTargetImageMode );
       
  9495       }
       
  9496 
       
  9497     if ( iSetNewPathnamesPending > ECamMediaStorageNone )
       
  9498       {
       
  9499       TRAP_IGNORE( SetPathnamesToNewStorageL( iSetNewPathnamesPending ) );
       
  9500       }
       
  9501 
       
  9502     if( iVideoRequested )
       
  9503       {
       
  9504       PRINT( _L("Camera <> starting recording..") );
       
  9505       iVideoRequested = EFalse;
       
  9506       IssueRequestL( ECamRequestVideoStart );
       
  9507       PRINT( _L("Camera <> ..done") );
       
  9508       }
       
  9509 
       
  9510 
       
  9511     NotifyControllerObservers( ECamEventEngineStateChanged, KErrNone ); 
       
  9512     NotifyControllerObservers( ECamEventControllerReady,    KErrNone ); 
       
  9513     }
       
  9514   PRINT( _L("Camera <= CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9515   }
       
  9516 
       
  9517 // ---------------------------------------------------------------------------
       
  9518 // SetStateFromEvent
       
  9519 // ---------------------------------------------------------------------------
       
  9520 //
       
  9521 void
       
  9522 CCamAppController::SetStateFromEvent( TCamCameraEventId aEventId )
       
  9523   {   
       
  9524   PRINT3( _L("Camera => CCamAppController::SetStateFromEvent mode[%s] operation[%s] event[%s]"), 
       
  9525           KCamModeNames[iInfo.iMode], 
       
  9526           KCamCaptureOperationNames[iInfo.iOperation],
       
  9527           KCamCameraEventNames[aEventId]
       
  9528         );
       
  9529   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  9530   switch( aEventId )
       
  9531     {
       
  9532     // =================================
       
  9533     case ECamCameraEventReserveLose:
       
  9534       // SetMode( ECamControllerShutdown );
       
  9535       SetMode( ECamControllerIdle );
       
  9536       SetOperation( ECamNoOperation );
       
  9537       break;
       
  9538     // ---------------------------------
       
  9539     case ECamCameraEventPowerOn:
       
  9540       PRINT( _L("Camera <> Init key sound system..") );
       
  9541       iSoundPlayer->InitKeySoundSystem();
       
  9542       PRINT( _L("Camera <> ..Init key sound system done") );      
       
  9543       break;
       
  9544     // ---------------------------------
       
  9545     case ECamCameraEventPowerOff:
       
  9546       // Reset the flash error status
       
  9547       if( iFlashStatus ) iFlashStatus->SetFlashError( EFalse );
       
  9548       SetMode( ECamControllerIdle );
       
  9549       SetOperation( ECamNoOperation );
       
  9550       break;
       
  9551     // =================================
       
  9552     // VF events
       
  9553     case ECamCameraEventVfStart:
       
  9554       if(  iBacklightTimer 
       
  9555        && !iBacklightTimer->IsActive() )
       
  9556         {
       
  9557         //iBacklightTimer->Start( KBacklighTimerInterval,
       
  9558         //                        KBacklighTimerInterval, 
       
  9559         //                        TCallBack( ResetInactivityTimer, this ) );        
       
  9560         iBacklightTimer->Start( 0,
       
  9561                                 KBacklighTimerInterval, 
       
  9562                                 TCallBack( ResetInactivityTimer, this ) );
       
  9563         }
       
  9564 		iAFCancelInProgress = EFalse;
       
  9565       break;
       
  9566     // ---------------------------------
       
  9567     case ECamCameraEventVfStop:
       
  9568       if( iBacklightTimer )
       
  9569         {
       
  9570         iBacklightTimer->Cancel();
       
  9571         }
       
  9572       break;
       
  9573     // =================================
       
  9574     case ECamCameraEventImageInit:
       
  9575       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageInit") );      
       
  9576       SetMode( ECamControllerImage );
       
  9577 
       
  9578       // Set the capture count now, so we don't need to set it when starting capture.
       
  9579       TRAP_IGNORE( InitCaptureLimitL() );
       
  9580       SetOperation( ECamNoOperation );
       
  9581       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  9582 
       
  9583       break;
       
  9584     // ---------------------------------
       
  9585     case ECamCameraEventImageStart: // Capture started, not finished.
       
  9586       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStart") );      
       
  9587       SetOperation( ECamCapturing );
       
  9588 
       
  9589       // Make sure our cached value for image filename number is up to date.      
       
  9590       iImageNumberCache = IntegerSettingValue( ECamSettingItemPhotoNumber );
       
  9591       break;
       
  9592     // ---------------------------------
       
  9593     case ECamCameraEventImageStop: // Capture finished, unless in burst    
       
  9594       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStop") );      
       
  9595       // Store image counter now.
       
  9596       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemPhotoNumber, iImageNumberCache ) );
       
  9597 
       
  9598       if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  9599         {
       
  9600         
       
  9601         //If canceled autofocusing previously then have to set
       
  9602         //autofocus range to get autofocusing work again.
       
  9603 
       
  9604         if(iAFCancelInProgress )
       
  9605         {
       
  9606            iAFCancelInProgress = EFalse; 
       
  9607            TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );                                                                  
       
  9608 
       
  9609         }
       
  9610 
       
  9611         
       
  9612 // No operation change here.
       
  9613 // Set to Completing in SS event, and ECamNoOperation when image saved.
       
  9614 //        SetOperation( ECamNoOperation );
       
  9615         }
       
  9616       break;
       
  9617     // ---------------------------------
       
  9618     case ECamCameraEventImageRelease:
       
  9619       SetMode( ECamControllerIdle );
       
  9620       SetOperation( ECamNoOperation );
       
  9621       break;
       
  9622     // =================================
       
  9623     case ECamCameraEventVideoInit:
       
  9624       SetMode( ECamControllerVideo );
       
  9625       SetOperation( ECamNoOperation );
       
  9626       break;
       
  9627     // ---------------------------------
       
  9628     case ECamCameraEventVideoStart:
       
  9629       iVideoRequested = EFalse;
       
  9630       SetOperation( ECamCapturing );
       
  9631       break;
       
  9632     // ---------------------------------
       
  9633      case ECamCameraEventVideoPause:
       
  9634        PlaySound( ECamVideoPauseSoundId, EFalse );
       
  9635        SetOperation( ECamPaused );
       
  9636        break;            
       
  9637     // ---------------------------------
       
  9638     case ECamCameraEventVideoStop:
       
  9639       SetOperation( ECamCompleting );
       
  9640       break;
       
  9641     // ---------------------------------
       
  9642     case ECamCameraEventVideoRelease:
       
  9643       SetMode( ECamControllerIdle );
       
  9644       SetOperation( ECamNoOperation );
       
  9645       break;
       
  9646     // =================================        
       
  9647     case ECamCameraEventStartAutofocus:
       
  9648 
       
  9649       if ( !CurrentSceneHasForcedFocus() &&
       
  9650            !iAFCancelInProgress )
       
  9651         {       
       
  9652         PRINT( _L("ECamCameraEventStartAutofocus -> Set operation state to ECamFocusing") );
       
  9653         iCurrentAFRequest=ECamRequestStartAutofocus;
       
  9654         SetOperation( ECamFocusing );
       
  9655         // fixed toolbar is used only with touch devices
       
  9656         if ( IsTouchScreenSupported() )
       
  9657             {
       
  9658             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  9659             if ( fixedToolbar )
       
  9660                 {
       
  9661                 fixedToolbar->SetToolbarVisibility( EFalse );
       
  9662                 } 
       
  9663             }
       
  9664         }    
       
  9665       break;       
       
  9666     // ---------------------------------
       
  9667     case ECamCameraEventAutofocusSuccessful:
       
  9668     case ECamCameraEventAutofocusFailed:
       
  9669         {
       
  9670         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_AF_LOCK 0" ); //CCORAPP_AF_LOCK_END
       
  9671         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_OVERLAY_UPD 1" );    //CCORAPP_OVERLAY_UPD_START
       
  9672         PRINT2( _L("Camera <> CCamAppController::SetStateFromEvent - iPendingAFRequest[%s] iCurrentAFRequest[%s]"), 
       
  9673                 KCamRequestNames[iPendingAFRequest], 
       
  9674                 KCamRequestNames[iCurrentAFRequest] );
       
  9675    	    
       
  9676    	    if( iAFCancelInProgress && ECamRequestCancelAutofocus == iCurrentAFRequest &&
       
  9677    	         ECamRequestCancelAutofocus == iPendingAFRequest )
       
  9678    		    {
       
  9679             // Cancelling done, camera lens is in hyperfocal position.
       
  9680             // Return AF range back to normal, so that next autofocus request
       
  9681             // will use the right range for this scene.
       
  9682             iAFCancelInProgress = EFalse;  
       
  9683             TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );	    
       
  9684    		    iPendingAFRequest=0;
       
  9685    		    iCurrentAFRequest=0;
       
  9686    		    NotifyControllerObservers( ECamEventFocusCancelled );
       
  9687    		    
       
  9688             if ( !iCaptureRequested )
       
  9689                 {
       
  9690                 SetOperation( ECamNoOperation );
       
  9691                 }
       
  9692             else
       
  9693                 {
       
  9694                 // do not notify observers if this happens after capture
       
  9695                 // has been requested as that would result in invalid ui state
       
  9696                 iInfo.iOperation = ECamNoOperation;
       
  9697                 if( IsAfNeeded() )
       
  9698                     {
       
  9699                     SetAfNeeded( EFalse );
       
  9700                     StartAutoFocus();
       
  9701                     }
       
  9702                 }
       
  9703    		    }
       
  9704    		 else if( iCurrentAFRequest==iPendingAFRequest &&
       
  9705    		        iPendingAFRequest==ECamRequestStartAutofocus
       
  9706                 && !CurrentSceneHasForcedFocus()
       
  9707              )
       
  9708              {
       
  9709 	         if( aEventId==ECamCameraEventAutofocusSuccessful )
       
  9710 	            {
       
  9711 
       
  9712                 PRINT( _L("ECamCameraEventAutofocusSuccessful -> Set operation state to ECamFocused") );
       
  9713           
       
  9714         
       
  9715                 if( iConfigManager && iConfigManager->IsAutoFocusSupported() &&
       
  9716                     !iCaptureRequested && appUi &&	appUi->SelfTimer() && 
       
  9717                     !appUi->SelfTimer()->IsActive())
       
  9718                     {
       
  9719                     PlaySound( ECamAutoFocusComplete, EFalse );
       
  9720                     }
       
  9721                 SetOperation( ECamFocused );
       
  9722 	            }    
       
  9723 	        else if(  aEventId==ECamCameraEventAutofocusFailed )
       
  9724 	    	    {
       
  9725                 PRINT( _L("ECamCameraEventAutofocusFailed -> Set operation state to ECamFocusFailed") );
       
  9726                 if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  9727                     {
       
  9728                     PlaySound( ECamAutoFocusFailed, EFalse );
       
  9729                     }
       
  9730                 SetOperation( ECamFocusFailed );
       
  9731                 }
       
  9732             iPendingAFRequest=0;
       
  9733             iCurrentAFRequest=0;	        
       
  9734             }
       
  9735         else if( iCurrentAFRequest != iPendingAFRequest && iPendingAFRequest !=0 
       
  9736                  && !CurrentSceneHasForcedFocus()
       
  9737             )
       
  9738             {
       
  9739             iCurrentAFRequest=iPendingAFRequest;
       
  9740             iPendingAFRequest=0;
       
  9741             TryAFRequest( iCurrentAFRequest ); 
       
  9742             }
       
  9743         else if( CurrentSceneHasForcedFocus() )
       
  9744             {
       
  9745             // Autofocus flags has to be reset in forced focus cases
       
  9746             iPendingAFRequest=0;
       
  9747             iCurrentAFRequest=0;
       
  9748             }
       
  9749         }
       
  9750       break;
       
  9751     // ---------------------------------      
       
  9752     case ECamCameraEventCancelAutofocus:
       
  9753         {  
       
  9754         // Set iAFCancelInProgress to true so that we don't change the 
       
  9755         // reticule for the next focus successful/focus failed event.
       
  9756         iAFCancelInProgress = ETrue;
       
  9757         iCurrentAFRequest = ECamRequestCancelAutofocus;
       
  9758         // fixed toolbar is used only with touch devices
       
  9759         if ( !iCaptureRequested && IsTouchScreenSupported() )
       
  9760             {
       
  9761             appUi->SetToolbarVisibility();  // avoid flickering in settings view
       
  9762             }
       
  9763         }
       
  9764       break;             
       
  9765     // =================================        
       
  9766     default:
       
  9767       // No change to state with other events
       
  9768       break;
       
  9769     // =================================        
       
  9770     }
       
  9771   PRINT2( _L("Camera <= CCamAppController::SetStateFromEvent mode[%s] operation[%s]"), 
       
  9772           KCamModeNames[iInfo.iMode], 
       
  9773           KCamCaptureOperationNames[iInfo.iOperation] );
       
  9774   }
       
  9775 
       
  9776 void 
       
  9777 CCamAppController::InitCaptureLimitL()
       
  9778   {
       
  9779   // Set the capture count now, so we don't need to set it when starting capture.
       
  9780   switch( iInfo.iTargetImageMode )
       
  9781     {
       
  9782     case ECamImageCaptureBurst:
       
  9783       PRINT1( _L("Camera <> CCamAppController .. burst mode as target, set capture limit to %d"), KShortBurstCount );      
       
  9784       SetCaptureLimitL( KShortBurstCount );
       
  9785       break;
       
  9786     case ECamImageCaptureTimeLapse:
       
  9787       PRINT1( _L("Camera <> CCamAppController .. timelapse mode as target, set capture limit locally to max %d"), iLongSequenceLimit );      
       
  9788       SetCaptureLimitL( iLongSequenceLimit );
       
  9789       break;
       
  9790     default:
       
  9791       PRINT( _L("Camera <> CCamAppController .. single mode as target, set capture limit locally to 1") );      
       
  9792       SetCaptureLimitL( 1 );
       
  9793       break;
       
  9794     }
       
  9795   }
       
  9796 
       
  9797 
       
  9798 // ===========================================================================
       
  9799 // 
       
  9800 TCamAppControllerInfo::TCamAppControllerInfo()
       
  9801   :  iActiveCamera         ( ECamActiveCameraNone ),
       
  9802      iMode                 ( ECamControllerIdle   ),
       
  9803      iTargetMode           ( ECamControllerIdle   ),
       
  9804      iImageMode            ( ECamImageCaptureNone ),
       
  9805      iTargetImageMode      ( ECamImageCaptureNone ),     
       
  9806      iOperation            ( ECamNoOperation      ),
       
  9807      iTargetVfState        ( ECamTriIdle          ),
       
  9808      iViewfinderMirror     ( EFalse               ),
       
  9809      iTargetImageResolution( 0                    ),
       
  9810      iTargetImageQuality   ( 0                    ),
       
  9811      iBusyRequestId        ( ECamRequestNone      )
       
  9812   {
       
  9813   }
       
  9814 
       
  9815  
       
  9816 // ===========================================================================
       
  9817 
       
  9818 
       
  9819 //
       
  9820 //
       
  9821 //
       
  9822 void CCamAppController::HandleFileHarvestingComplete()
       
  9823     {
       
  9824     PRINT( _L("Camera => CCamAppController::HandleFileHarvestingComplete" ) );
       
  9825     // If release required but not done in postcapture not shown mode this is the
       
  9826 	// last time to do it. Otherwise problems occurs in 2ndary camera if opened
       
  9827     if ( iPendingRelease && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) )
       
  9828        {
       
  9829        PRINT( _L("Camera <> CCamAppController::HandleFileHarvestingComplete, releasing" ) );	
       
  9830        ReleaseCamera();	
       
  9831        }
       
  9832     PRINT( _L("Camera <= CCamAppController::HandleFileHarvestingComplete" ) );
       
  9833     }
       
  9834 
       
  9835 
       
  9836 //
       
  9837 //CCamAppController::DeRegisterHarverterClientEvents
       
  9838 //
       
  9839 void CCamAppController::DeRegisterHarverterClientEvents()
       
  9840     {
       
  9841     if ( iImageSaveActive )
       
  9842         {
       
  9843 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
  9844         iImageSaveActive->DeRegisterHarverterClientEvents();
       
  9845 #endif //defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
  9846         }
       
  9847     }
       
  9848 
       
  9849 
       
  9850 // ---------------------------------------------------------------------------
       
  9851 // CCamAppController::Configuration
       
  9852 //
       
  9853 // ---------------------------------------------------------------------------
       
  9854 //
       
  9855 CCamConfiguration* 
       
  9856 CCamAppController::Configuration() const
       
  9857     {
       
  9858     return iConfiguration;  
       
  9859     }
       
  9860 
       
  9861 
       
  9862 // ---------------------------------------------------------------------------
       
  9863 // CCamAppController::RestoreSettingsToCameraL
       
  9864 // Calls RestoreSettingIfNecessaryL for all supported camera settings.
       
  9865 // In case there were settings needing restoring, and camera controller
       
  9866 // is not busy, request camera controller to start setting changes.
       
  9867 // ---------------------------------------------------------------------------
       
  9868 // 
       
  9869 void
       
  9870 CCamAppController::RestoreSettingsToCameraL()
       
  9871     {
       
  9872     PRINT( _L("Camera => CCamAppController::RestoreSettingsToCameraL" ) );  
       
  9873     const TCamCameraMode mode = CurrentMode(); 
       
  9874     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9875     if ( IsAppUiAvailable() && appUi->CurrentViewState()==ECamViewStateUserSceneSetup )
       
  9876         {
       
  9877         //restore user scence setting
       
  9878         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneWhitebalance );
       
  9879         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneExposure );
       
  9880         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneFlash ); 
       
  9881         if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9882           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneColourFilter );        
       
  9883         if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9884           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneBrightness ); 
       
  9885         if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9886            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneContrast );   
       
  9887         if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )	
       
  9888            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneLightSensitivity );
       
  9889         if ( ECamControllerImage == mode )
       
  9890           {
       
  9891           if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
  9892             DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneImageSharpness );
       
  9893           DirectRestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
  9894           }
       
  9895         else if ( ECamControllerVideo == mode )
       
  9896           {
       
  9897           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
  9898           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoStab);
       
  9899           }
       
  9900         }
       
  9901     else if(iInfo.iActiveCamera == ECamActiveCameraPrimary)
       
  9902 	    {
       
  9903         if ( ECamControllerImage == mode )
       
  9904 	        {
       
  9905 	        // Add rest of the pending settings where needed
       
  9906 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoWhiteBalance );
       
  9907 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoExposure );
       
  9908 
       
  9909 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9910 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoColourFilter );        
       
  9911 	        
       
  9912 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9913 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoBrightness );
       
  9914 
       
  9915 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9916 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoContrast );
       
  9917 
       
  9918 	        if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
  9919 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoImageSharpness );
       
  9920 	      
       
  9921 	        if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )
       
  9922 	            {
       
  9923 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoLightSensitivity );
       
  9924 	            }
       
  9925 	        
       
  9926 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoFlash );
       
  9927 	        
       
  9928 	        RestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
  9929 	        }    
       
  9930 	    else if ( ECamControllerVideo == mode )
       
  9931 	        {
       
  9932 	        // Video settings in the toolbar
       
  9933 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoWhiteBalance );
       
  9934 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoExposure );
       
  9935 
       
  9936 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
  9937 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoColourFilter );
       
  9938 	        
       
  9939 	        // The following settings are not supported in video mode toolbar
       
  9940 	        // However, the values may need to be reset, in case the setting was
       
  9941 	        // changed in image mode
       
  9942 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
  9943 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoBrightness );
       
  9944 
       
  9945 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
  9946 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoContrast );
       
  9947 
       
  9948 	        if ( UiConfigManagerPtr()->IsVideoStabilizationSupported() )
       
  9949 	            {
       
  9950 	            RestoreSettingIfNecessaryL( ECamSettingItemVideoStab );      
       
  9951 	            }
       
  9952 	        RestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
  9953 	        
       
  9954 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoFlash );
       
  9955 	        
       
  9956 	        RestoreSettingIfNecessaryL( ECamSettingItemContinuousAutofocus ); 
       
  9957 	        }
       
  9958 	    }
       
  9959     else if(iInfo.iActiveCamera == ECamActiveCameraSecondary)
       
  9960         {
       
  9961         if ( ECamControllerImage == mode )
       
  9962                 {
       
  9963                 // Not needed
       
  9964                 }    
       
  9965             else if ( ECamControllerVideo == mode )
       
  9966                 {
       
  9967                 // Not needed
       
  9968                 }
       
  9969         }
       
  9970     else
       
  9971         {
       
  9972         // Do nothing
       
  9973         }
       
  9974     
       
  9975     if( iSettingProvider->PendingSettingChangeCount() > 0 &&
       
  9976         !iCameraController->ControllerInfo().iBusy )
       
  9977         {
       
  9978         PRINT( _L("Camera <> CCamAppController::RestoreSettingsToCameraL - Issue settings change request") );
       
  9979         IssueSettingsChangeRequestL( );    
       
  9980         }
       
  9981         
       
  9982     PRINT( _L("Camera <= CCamAppController::RestoreSettingsToCameraL" ) );          
       
  9983     }
       
  9984  
       
  9985 // ---------------------------------------------------------------------------
       
  9986 // CCamAppController::RestoreSettingIfNecessaryL
       
  9987 // Checks from camera controller, whether the value of the setting given
       
  9988 // as argument has same value in camera hw and settings model (UI).
       
  9989 // If value is not the same, add the setting id to settingsmodel's list
       
  9990 // of pending changes.
       
  9991 // ---------------------------------------------------------------------------
       
  9992 //     
       
  9993 void
       
  9994 CCamAppController::RestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
  9995     {    
       
  9996     // Convert UI setting ID to camera controller setting ID  
       
  9997     TCamCameraSettingId camSettingId = 
       
  9998       CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem );
       
  9999     
       
 10000     if( !iCameraController->SettingValueUpToDateL( camSettingId ) )
       
 10001         {
       
 10002         PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
 10003         iSettingProvider->AddPendingSettingChangeL( aSettingItem );  
       
 10004         }
       
 10005     else
       
 10006         {
       
 10007         if( aSettingItem == ECamSettingItemDynamicVideoFlash )
       
 10008             {
       
 10009             TCamCameraSettingId cameraId( 
       
 10010                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
 10011             iCameraController->DirectSettingsChangeL( cameraId );
       
 10012             }
       
 10013         PRINT1( _L("RestoreSettingIfNecessaryL - Setting %s has up-to-date value, no need to restore"), KCamSettingItemNames[aSettingItem] );      
       
 10014         } 
       
 10015     }            
       
 10016 
       
 10017 
       
 10018 // ---------------------------------------------------------------------------
       
 10019 // CCamAppController::DirectRestoreSettingIfNecessaryL
       
 10020 // Checks if the setting needs restoring (UI setting value doesn't match
       
 10021 // the actual setting value in camera).  In that case, function 
       
 10022 // directly set settting to camera
       
 10023 // ---------------------------------------------------------------------------
       
 10024 // 
       
 10025 void
       
 10026 CCamAppController::DirectRestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
 10027     {
       
 10028 
       
 10029     TCamCameraSettingId cameraId( 
       
 10030                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
 10031     if ( !iCameraController->SettingValueUpToDateL( cameraId ) )
       
 10032       {
       
 10033       PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
 10034       iCameraController->DirectSettingsChangeL( cameraId );  
       
 10035       }
       
 10036     }
       
 10037 // -----------------------------------------------------------------------------
       
 10038 // CCamAppController::RestartTimeLapseTimerL()
       
 10039 // 
       
 10040 // -----------------------------------------------------------------------------
       
 10041 //   
       
 10042 void CCamAppController::RestartTimeLapseTimerL()
       
 10043 	{
       
 10044 	PRINT( _L("Camera => CCamAppController::RestartTimeLapseTimerL inside this function" ))  
       
 10045    	if ( iTimeLapseTimer )
       
 10046 		{
       
 10047 		iTimeLapseTimer->Cancel();		
       
 10048 		iTimeLapseTimer->SetTimeout( KSecondInMicSec );
       
 10049 		}
       
 10050     else
       
 10051         {
       
 10052         iTimeLapseTimer = CCamTimer::NewL( KSecondInMicSec, TCallBack( CCamAppController::TimeLapseTimeoutL, this ) );
       
 10053         }
       
 10054 
       
 10055     NotifyControllerObservers( ECamEventCounterUpdated );
       
 10056     PRINT( _L("Camera <> CCamAppController::RestartTimeLapseTimerL starting timelapse timer" ));
       
 10057     
       
 10058     iTimeLapseStartTime.HomeTime(); 
       
 10059     iTimeLapseTimer->StartTimer();
       
 10060 	
       
 10061 	// Following trace may be useful to see timing related handling in TimeLapse mode 
       
 10062 	// TDateTime stTime = iTimeLapseStartTime.DateTime();
       
 10063 	// PRINT3( _L("Start time: %d:%d:%d"), stTime.Minute(), stTime.Second(), stTime.MicroSecond() );
       
 10064 	
       
 10065 	PRINT( _L("Camera <= CCamAppController::RestartTimeLapseTimerL" ))  
       
 10066 	}
       
 10067  
       
 10068      
       
 10069 // ---------------------------------------------------------------------------
       
 10070 // SetSettingsRestoreNeeded
       
 10071 // ---------------------------------------------------------------------------
       
 10072 //     
       
 10073 void  
       
 10074 CCamAppController::SetSettingsRestoreNeeded()
       
 10075   {
       
 10076   iSettingsRestoreNeeded = ETrue;
       
 10077   }
       
 10078 
       
 10079 // ---------------------------------------------------------------------------
       
 10080 // IsSettingsRestoreNeeded
       
 10081 // ---------------------------------------------------------------------------
       
 10082 //     
       
 10083 TBool 
       
 10084 CCamAppController::IsSettingsRestoreNeeded() const
       
 10085   {
       
 10086   return iSettingsRestoreNeeded;
       
 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 TBool 
       
 10097 CCamAppController::IsSceneSupported( const TInt aSceneId, TBool aPhotoScene ) const
       
 10098   {
       
 10099   if ( aPhotoScene )
       
 10100       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsImageSceneSupported( aSceneId );
       
 10101   else
       
 10102       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsVideoSceneSupported( aSceneId );
       
 10103   }
       
 10104 
       
 10105 // ---------------------------------------------------------------------------
       
 10106 // StaticSettingsModel
       
 10107 //
       
 10108 // Gets the handle to the settings model, which is used inturn by the
       
 10109 // plugin to call the interfaces for performing needed actions.
       
 10110 // ---------------------------------------------------------------------------
       
 10111 //
       
 10112 MCamStaticSettings& 
       
 10113 CCamAppController::StaticSettingsModel()
       
 10114   {
       
 10115   return static_cast<CCamSettingsModel*>(iSettingsModel)->StaticSettingsModel();
       
 10116   }
       
 10117 
       
 10118 
       
 10119 // ---------------------------------------------------------------------------
       
 10120 // EngineRequestsPending
       
 10121 // ---------------------------------------------------------------------------
       
 10122 //     
       
 10123 TBool CCamAppController::EngineRequestsPending() const
       
 10124    {
       
 10125    return IsFlagOn( iBusyFlags, EBusyRequest );
       
 10126    }  
       
 10127  
       
 10128 // ---------------------------------------------------------------------------
       
 10129 // CalculateVideoTimeRemainingL
       
 10130 //
       
 10131 // ---------------------------------------------------------------------------
       
 10132 //
       
 10133 TTimeIntervalMicroSeconds
       
 10134 CCamAppController::CalculateVideoTimeRemainingL(const TCamMediaStorage aStorage)
       
 10135   {
       
 10136   RFs& fs = CEikonEnv::Static()->FsSession();
       
 10137   TInt drive = 0;
       
 10138   if(aStorage == ECamMediaStorageCurrent)
       
 10139 	{
       
 10140   const TDesC& filename = CurrentVideoFileName();
       
 10141   TParse fp;
       
 10142   User::LeaveIfError(fs.Parse(filename, fp));
       
 10143   TPtrC driveletter = fp.Drive();
       
 10144   TChar drl = driveletter[0];
       
 10145   User::LeaveIfError(fs.CharToDrive(drl, drive));  
       
 10146 	}
       
 10147   else
       
 10148 	{
       
 10149 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10150 	switch(aStorage)
       
 10151 		{
       
 10152 		case ECamMediaStoragePhone:
       
 10153 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10154 			break; 
       
 10155 		case ECamMediaStorageCard:
       
 10156 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10157 			break;
       
 10158 		case ECamMediaStorageMassStorage:
       
 10159 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10160 			break;
       
 10161 		default:
       
 10162 			break;
       
 10163 		}
       
 10164 	User::LeaveIfError(DriveInfo::GetDefaultDrive( driveInfo, drive ));
       
 10165 	}
       
 10166     
       
 10167   // Get critical level for this drive type
       
 10168   TDriveInfo driveInfo;
       
 10169   fs.Drive(driveInfo, drive);
       
 10170     
       
 10171   TInt criticalDiskVal = 0;
       
 10172   if( driveInfo.iType == EMediaRam ) //RAM drives have diff critical levels
       
 10173 	{
       
 10174 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10175 	User::LeaveIfError( 
       
 10176 		repository->Get( KRamDiskCriticalLevel, criticalDiskVal ) );
       
 10177 	CleanupStack::PopAndDestroy( repository );			
       
 10178 	}
       
 10179   else // Some other media type
       
 10180 	{
       
 10181 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10182 	User::LeaveIfError( 
       
 10183 		repository->Get( KDiskCriticalThreshold, criticalDiskVal ) );
       
 10184 	CleanupStack::PopAndDestroy( repository );			
       
 10185 	}   
       
 10186  
       
 10187   // Get the available space in volumeinfo.iFree
       
 10188   TVolumeInfo volumeinfo; 
       
 10189   User::LeaveIfError(fs.Volume(volumeinfo, drive));   
       
 10190    
       
 10191   // Get the current video quality data
       
 10192   TInt videoQuality = iSettingsModel->IntegerSettingValue( 
       
 10193   										ECamSettingItemVideoQuality );
       
 10194   CCamVideoQualityLevel& level = *( iSettingsModel->
       
 10195   									VideoQualityArray() )[videoQuality];     
       
 10196   
       
 10197   // Audio recording on/muted
       
 10198   TInt audioRec = iSettingsModel->IntegerSettingValue( 
       
 10199   									ECamSettingItemVideoAudioRec );
       
 10200   TBool audioMute = ECamSettOff == audioRec;
       
 10201   
       
 10202   // Video file size limit (MMS case)
       
 10203   TInt videoLimit = 0;
       
 10204   if( ECamVideoClipShort == level.VideoLength() )
       
 10205     {
       
 10206     // Short video, needs to fit into MMS message
       
 10207     videoLimit = CamUtility::MaxMmsSizeInBytesL();  
       
 10208     }
       
 10209   
       
 10210   TCamVideoTime videoTime( volumeinfo.iFree,            // Free space
       
 10211                            criticalDiskVal,             // Critical space
       
 10212                            //level.VideoFileType(),       // Video codec
       
 10213                            level.VideoBitRate(),        // Video bitrate
       
 10214                            //level.AudioType(),           // Audio FourCC
       
 10215                            level.AudioBitRate(),        // Audio bitrate
       
 10216                            videoLimit,                  // File size limit
       
 10217                            audioMute,                   // Mute audio?
       
 10218                            iConfiguration->CMRAvgVideoBitRateScaler() );
       
 10219                                                 
       
 10220   return videoTime.GetRemainingTimeL();    
       
 10221   }
       
 10222 
       
 10223 
       
 10224 // ---------------------------------------------------------------------------
       
 10225 // SetRemainingImageStored
       
 10226 // ---------------------------------------------------------------------------
       
 10227 //     
       
 10228 void  
       
 10229 CCamAppController::SetRemainingImageStored()
       
 10230   {
       
 10231   iValueIsStored = ETrue;
       
 10232   }
       
 10233 // ---------------------------------------------------------------------------
       
 10234 // IsRemainingImageStored
       
 10235 // ---------------------------------------------------------------------------
       
 10236 //
       
 10237 TBool 
       
 10238 CCamAppController::IsRemainingImageStored() const
       
 10239   {
       
 10240   return iValueIsStored;
       
 10241   }
       
 10242 
       
 10243 // ---------------------------------------------------------------------------
       
 10244 // IsSavingInProgress
       
 10245 // ---------------------------------------------------------------------------
       
 10246 //
       
 10247 TBool 
       
 10248 CCamAppController::IsSavingInProgress() const
       
 10249   {
       
 10250   return ( iImageSaveActive->Count() > 0 );
       
 10251   }
       
 10252 
       
 10253 // ---------------------------------------------------------------------------
       
 10254 // CapturedImages
       
 10255 // ---------------------------------------------------------------------------
       
 10256 //
       
 10257  TInt CCamAppController::CapturedImages() const
       
 10258   {
       
 10259   return iCameraController->ControllerInfo().iCaptureCount;
       
 10260   }
       
 10261         
       
 10262 // -----------------------------------------------------------------------------
       
 10263 //
       
 10264 // -----------------------------------------------------------------------------
       
 10265 //
       
 10266 void CCamAppController::SetSettingsPlugin( CCamGSInterface* aPlugin )
       
 10267 	{
       
 10268 	iPlugin = aPlugin;
       
 10269 	}
       
 10270 
       
 10271 // ---------------------------------------------------------------------------
       
 10272 // CCamAppController::SetViewfinderWindowHandle
       
 10273 // ---------------------------------------------------------------------------
       
 10274 //
       
 10275 void CCamAppController::SetViewfinderWindowHandle( RWindowBase* aWindow )
       
 10276     {
       
 10277     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10278 
       
 10279     iCameraController->SetViewfinderWindowHandle( aWindow );
       
 10280     }
       
 10281 
       
 10282 // ---------------------------------------------------------------------------
       
 10283 // CCamAppController::ViewfinderWindowDeleted
       
 10284 // ---------------------------------------------------------------------------
       
 10285 //
       
 10286 void CCamAppController::ViewfinderWindowDeleted( RWindowBase* aWindow )
       
 10287     {
       
 10288     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10289 
       
 10290     iCameraController->ViewfinderWindowDeleted( aWindow );
       
 10291     }
       
 10292 
       
 10293 
       
 10294 // ---------------------------------------------------------------------------
       
 10295 // CCamAppController::ExistMassStorage()
       
 10296 // ---------------------------------------------------------------------------
       
 10297 //
       
 10298 TBool CCamAppController::ExistMassStorage() const
       
 10299     {
       
 10300     const TUint KMassStorageBits = DriveInfo::EDriveInternal |
       
 10301                                    DriveInfo::EDriveExternallyMountable;    
       
 10302     TInt drive;
       
 10303     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive );
       
 10304     
       
 10305     if ( err != KErrNone )
       
 10306         {
       
 10307         return EFalse;
       
 10308         }
       
 10309     
       
 10310     TUint driveStatus(0);    
       
 10311     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10312                                      drive, 
       
 10313                                      driveStatus );
       
 10314 
       
 10315     TInt usbPersonality;
       
 10316     TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10317     						  KUsbWatcherSelectedPersonality,
       
 10318     						  usbPersonality);
       
 10319     
       
 10320     if ( err != KErrNone )
       
 10321         {
       
 10322         return EFalse;
       
 10323         }
       
 10324         
       
 10325     if ( (driveStatus & KMassStorageBits) == KMassStorageBits &&
       
 10326 		 !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10327     	((KErrNone == ret) && (KUsbPersonalityIdMS != usbPersonality) ) )
       
 10328         {
       
 10329         return ETrue;
       
 10330         }
       
 10331         
       
 10332     return EFalse;
       
 10333     }
       
 10334 
       
 10335 
       
 10336 // ------------------------------------------------------------------------
       
 10337 // CCamAppController::IsMemoryAvailable()
       
 10338 // ------------------------------------------------------------------------
       
 10339 //
       
 10340 TBool 
       
 10341 CCamAppController::IsMemoryAvailable(const TCamMediaStorage aStorage, TBool aIgnoreUsbPersonality ) const
       
 10342 	{
       
 10343 	TInt currentStorage = aStorage;
       
 10344 	if(aStorage == ECamMediaStorageCurrent)
       
 10345 		{
       
 10346 		TCamCameraMode mode = CurrentMode();
       
 10347 
       
 10348 		if((ECamControllerImage != mode) && (ECamControllerVideo != mode))
       
 10349             {
       
 10350             //This is needed for case where current mode is not yet set.
       
 10351             mode = TargetMode();
       
 10352             }
       
 10353 		
       
 10354 		if(ECamControllerImage == mode)
       
 10355 			{
       
 10356 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10357 								IntegerSettingValue( 
       
 10358 									ECamSettingItemPhotoMediaStorage ) );
       
 10359 			}
       
 10360 		else if(ECamControllerVideo == mode)
       
 10361 			{
       
 10362 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10363 								IntegerSettingValue( 
       
 10364 									ECamSettingItemVideoMediaStorage ) );
       
 10365 			}
       
 10366 		else
       
 10367 			{
       
 10368 			//No impl
       
 10369 			}
       
 10370 		}
       
 10371 	
       
 10372 	TInt usbPersonality;
       
 10373 	TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10374 							  KUsbWatcherSelectedPersonality,
       
 10375 							  usbPersonality);
       
 10376   if ( !aIgnoreUsbPersonality )
       
 10377     {
       
 10378     if ( ( currentStorage != ECamMediaStoragePhone ) && ( KErrNone == ret ) && 
       
 10379          ( KUsbPersonalityIdMS == usbPersonality ) )
       
 10380       {
       
 10381       return EFalse;
       
 10382       }
       
 10383     }
       
 10384 		
       
 10385 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10386 	switch(currentStorage)
       
 10387 		{
       
 10388 		case ECamMediaStoragePhone:
       
 10389 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10390 			break; 
       
 10391 		case ECamMediaStorageCard:
       
 10392 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10393 			break;
       
 10394 		case ECamMediaStorageMassStorage:
       
 10395 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10396 			break;
       
 10397 		default:
       
 10398 			break;
       
 10399 		}
       
 10400 	
       
 10401 	
       
 10402 	TInt drive;
       
 10403 	TInt err = DriveInfo::GetDefaultDrive( driveInfo, drive );
       
 10404 	if(err)
       
 10405 		{
       
 10406 		return EFalse;
       
 10407 		}
       
 10408     TUint driveStatus(0);    
       
 10409     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10410                                      drive, 
       
 10411                                      driveStatus );
       
 10412     if(err)
       
 10413     	{
       
 10414     	return EFalse;
       
 10415     	}
       
 10416     
       
 10417     return ( (driveStatus & DriveInfo::EDrivePresent) && 
       
 10418 		   !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10419 	       (driveStatus & DriveInfo::EDriveUserVisible) &&
       
 10420 	       !(driveStatus & DriveInfo::EDriveInUse) &&
       
 10421 	       !(driveStatus & DriveInfo::EDriveReadOnly) );
       
 10422 	}
       
 10423  
       
 10424 	
       
 10425 // ---------------------------------------------------------------------------
       
 10426 // CCamAppController::IsDemandKeyRelease()
       
 10427 // ---------------------------------------------------------------------------
       
 10428 //
       
 10429 TBool CCamAppController::IsDemandKeyRelease()
       
 10430     {
       
 10431     return iDemandKeyRelease;
       
 10432     }
       
 10433 
       
 10434 // ---------------------------------------------------------------------------
       
 10435 // CCamAppController::SetDemandKeyRelease()
       
 10436 // ---------------------------------------------------------------------------
       
 10437 //
       
 10438 void CCamAppController::SetDemandKeyRelease( TBool aDemand )
       
 10439     {
       
 10440     iDemandKeyRelease = aDemand;
       
 10441     }
       
 10442 
       
 10443 
       
 10444 // ---------------------------------------------------------------------------
       
 10445 // CCamAppController::IsKeyLockOn()
       
 10446 // ---------------------------------------------------------------------------
       
 10447 //
       
 10448 TBool CCamAppController::IsKeyLockOn()
       
 10449     {
       
 10450     if ( iKeyLockStatusWatcher && iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
 10451         {
       
 10452         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
 10453         TInt iKeyLockStatus = 0;
       
 10454         iKeyLockStatusWatcher->Get( iKeyLockStatus );
       
 10455         if ( iKeyLockStatus == EKeyguardLocked && appUi )
       
 10456             {
       
 10457             return ETrue;
       
 10458             }
       
 10459         else
       
 10460             {
       
 10461             return EFalse;
       
 10462             }        
       
 10463         }
       
 10464     return EFalse;
       
 10465     }
       
 10466 
       
 10467 
       
 10468 // ---------------------------------------------------------------------------
       
 10469 // CCamAppController::DriveChangeL
       
 10470 // ---------------------------------------------------------------------------
       
 10471 //
       
 10472 TInt CCamAppController::DriveChangeL( const TCamDriveChangeType aType )
       
 10473   {
       
 10474   PRINT1( _L("Camera => CCamAppController::DriveChangeL aType: %d" ), aType );
       
 10475     
       
 10476   TCamCameraMode mode = CurrentMode();
       
 10477   TCamMediaStorage currentStorage;
       
 10478 		
       
 10479   // Photos and videos are saved onto the same media, so no need to 
       
 10480   // differentiate between still/video 
       
 10481   currentStorage = static_cast<TCamMediaStorage>( 
       
 10482           IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );
       
 10483     
       
 10484   PRINT1( _L("Camera <> iPreferredStorageLocation is now %d"), 
       
 10485                                                   iPreferredStorageLocation );
       
 10486   PRINT1( _L("Camera <> Update iPreferredStorageLocation to %d"), 
       
 10487                                                             currentStorage );
       
 10488     
       
 10489   iPreferredStorageLocation = currentStorage; 
       
 10490     
       
 10491   if ( ECamMediaStoragePhone == iPreferredStorageLocation )
       
 10492     {
       
 10493     PRINT( _L("Camera <> Phone memory is the preferred storage location. Nothing to be done here. Return KErrNone.") )
       
 10494     PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );
       
 10495     return KErrNone;
       
 10496     }
       
 10497    
       
 10498   if  ( ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) || 
       
 10499           !IsMemoryAvailable( ECamMediaStorageMassStorage, EFalse ) ) ||
       
 10500         !IsMemoryAvailable( iPreferredStorageLocation, ETrue ) )
       
 10501     {  
       
 10502     PRINT( _L("Camera <> USB personality is 'Mass storage' or iPreferredStorageLocation (MMC or mass memory) is unavailable") )
       
 10503 
       
 10504     // Stop if recording a video to mass memory or MMC
       
 10505     if ( CurrentVideoOperation() == ECamCapturing ||
       
 10506          CurrentVideoOperation() == ECamPaused )
       
 10507       {
       
 10508       PRINT( _L("Camera <> Video capture in progress...") )
       
 10509         
       
 10510       if ( !IsMemoryAvailable( iInitialVideoStorageLocation ) ) 
       
 10511         {
       
 10512         PRINT( _L("Camera <> ...Stop  video recording.") )
       
 10513         iCaptureStoppedForUsb = ETrue;	
       
 10514         StopVideoRecording();
       
 10515         }
       
 10516       else
       
 10517         {
       
 10518         PRINT( _L("Camera <> ...Phone memory in use. No need to stop.") )
       
 10519         }
       
 10520                        
       
 10521       }
       
 10522     // Cancel if pending recording	
       
 10523     else if( iVideoRequested )
       
 10524       {
       
 10525       iVideoRequested = EFalse;
       
 10526       }
       
 10527     if ( SequenceCaptureInProgress() )
       
 10528       {
       
 10529       PRINT( _L("Camera <> Sequence capture in progress. -> Stop and skip postcapture.") )
       
 10530             
       
 10531       iCaptureStoppedForUsb = ETrue;
       
 10532       SoftStopBurstL( ETrue );
       
 10533       }
       
 10534     // If in the middle of init sequence or saving a file, set the dismount
       
 10535     // pending so that the AllowDismount call will be made later
       
 10536     if( IsFlagOn( iBusyFlags, EBusySequence ) || iSaving )
       
 10537       {
       
 10538       PRINT( _L("Camera <> CCamAppController::DriveChangeL sequence or saving ongoing" ) );  		
       
 10539       
       
 10540       iDismountPending = ETrue;    
       
 10541       // Mass memory may be the forced storage location. Then it's necessary 
       
 10542       // to switch to (forced) phone memory
       
 10543       ForceUsePhoneMemoryL( ETrue ); 
       
 10544       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount pending" ) );  	
       
 10545       return KErrNotReady;
       
 10546       }
       
 10547     else
       
 10548       {    	           
       
 10549       // Mass memory may be the forced storage location. Then it's necessary 
       
 10550       // to switch to (forced) phone memory
       
 10551       ForceUsePhoneMemoryL( ETrue );
       
 10552                 
       
 10553       // Make sure toolbar is visible
       
 10554       CCamAppUi* appUi = static_cast<CCamAppUi*>( 
       
 10555                                                 CEikonEnv::Static()->AppUi() );
       
 10556       CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
 10557       
       
 10558       if ( fixedToolbar && ECamNoOperation == CurrentOperation() )
       
 10559         {
       
 10560         fixedToolbar->SetToolbarVisibility( ETrue );
       
 10561         }
       
 10562         
       
 10563       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount ok" ) );  	    
       
 10564       return KErrNone;
       
 10565       }        
       
 10566     }
       
 10567   else if ( IsMemoryAvailable( iPreferredStorageLocation, ETrue ) &&
       
 10568             ( ECamMediaStorageCard == iPreferredStorageLocation ||
       
 10569               ECamMediaStorageMassStorage  == iPreferredStorageLocation ) )
       
 10570     {
       
 10571     PRINT( _L("Camera <> iPreferredStorageLocation (MMC or mass memory) is now available.") )
       
 10572  
       
 10573     // if phone memory forced, then revert back to user selected location
       
 10574     if ( iForceUseOfPhoneMemory )
       
 10575       {
       
 10576       PRINT( _L("Camera <> Phone memory is forced, switch back to user selected storage location.") )
       
 10577       ForceUsePhoneMemoryL( EFalse );
       
 10578       }
       
 10579     else
       
 10580       {
       
 10581       PRINT( _L("Camera <> !IsPhoneMemoryForced() -> No action.") )
       
 10582       }
       
 10583     }
       
 10584   
       
 10585   PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );  	
       
 10586   return KErrNone;
       
 10587   }
       
 10588 
       
 10589 // ---------------------------------------------------------------------------
       
 10590 // CCamAppController::CurrentStorage
       
 10591 // ---------------------------------------------------------------------------
       
 10592 //    
       
 10593 TCamMediaStorage CCamAppController::CurrentStorage()   
       
 10594     {
       
 10595     return iCurrentStorage;
       
 10596     }	 
       
 10597 
       
 10598 // ---------------------------------------------------------------------------
       
 10599 // CCamAppController::IsAfNeeded
       
 10600 // ---------------------------------------------------------------------------
       
 10601 // 
       
 10602 TBool CCamAppController::IsAfNeeded()
       
 10603     {
       
 10604     return iAfNeeded;
       
 10605     }
       
 10606 
       
 10607 // ---------------------------------------------------------------------------
       
 10608 // CCamAppController::SetAfNeeded
       
 10609 // ---------------------------------------------------------------------------
       
 10610 // 
       
 10611 void CCamAppController::SetAfNeeded( TBool aAfNeeded )
       
 10612     {
       
 10613     iAfNeeded = aAfNeeded;
       
 10614     }
       
 10615 	
       
 10616 // ---------------------------------------------------------------------------
       
 10617 // CCamAppController::IsCaptureStoppedForUsb
       
 10618 // ---------------------------------------------------------------------------
       
 10619 //    
       
 10620 TBool CCamAppController::IsCaptureStoppedForUsb()
       
 10621     {
       
 10622     return iCaptureStoppedForUsb;	
       
 10623     }
       
 10624 
       
 10625 // ---------------------------------------------------------------------------
       
 10626 // CCamAppController::SetCaptureStoppedForUsb
       
 10627 // ---------------------------------------------------------------------------
       
 10628 //    
       
 10629 void CCamAppController::SetCaptureStoppedForUsb( TBool aCaptureStoppedForUsb )
       
 10630     {
       
 10631     iCaptureStoppedForUsb = aCaptureStoppedForUsb;	
       
 10632     }
       
 10633     
       
 10634 // ---------------------------------------------------------------------------
       
 10635 // CCamAppController::CancelDismountMonitoring
       
 10636 // ---------------------------------------------------------------------------
       
 10637 //    
       
 10638 void CCamAppController::CancelDismountMonitoring()
       
 10639     {
       
 10640     if( iDriveChangeNotifier )
       
 10641         {
       
 10642         iDriveChangeNotifier->CancelMonitoring();		
       
 10643         }
       
 10644     }
       
 10645 
       
 10646 
       
 10647 // ---------------------------------------------------------------------------
       
 10648 // CCamAppController::StartDismountMonitoring
       
 10649 // ---------------------------------------------------------------------------
       
 10650 //    
       
 10651 void CCamAppController::StartDismountMonitoring()
       
 10652     {
       
 10653     if( iDriveChangeNotifier )
       
 10654         {
       
 10655         iDriveChangeNotifier->StartMonitoring();		
       
 10656         }
       
 10657     }
       
 10658 
       
 10659 // ---------------------------------------------------------------------------
       
 10660 // CCamAppController::DeepSleepTimeout
       
 10661 // ---------------------------------------------------------------------------
       
 10662 //
       
 10663 TInt CCamAppController::DeepSleepTimeout( TAny* aPtr )
       
 10664     {
       
 10665     static_cast<CCamAppController*>( aPtr )->DoDeepSleepTimeout();
       
 10666     return EFalse; // dummy
       
 10667     }
       
 10668 
       
 10669 // ---------------------------------------------------------------------------
       
 10670 // CCamAppController::DoDeepSleepTimeout
       
 10671 // ---------------------------------------------------------------------------
       
 10672 //
       
 10673 void CCamAppController::DoDeepSleepTimeout()
       
 10674     {
       
 10675     PRINT( _L("Camera => CCamAppController::DoDeepSleepTimeout") );
       
 10676 
       
 10677     ReleaseCamera();
       
 10678     iDeepSleepTimerExpired = ETrue;
       
 10679     iDeepSleepTimer->Cancel();
       
 10680 
       
 10681     PRINT( _L("Camera <= CCamAppController::DoDeepSleepTimeout") );
       
 10682     }
       
 10683 
       
 10684 // ---------------------------------------------------------------------------
       
 10685 // CCamAppController::DeepSleepTimerStart
       
 10686 // ---------------------------------------------------------------------------
       
 10687 //
       
 10688 void CCamAppController::DeepSleepTimerStart()
       
 10689     {
       
 10690     PRINT( _L("Camera : DeepSleepTimerStart") );
       
 10691     iDeepSleepTimerExpired = EFalse;
       
 10692     if ( iDeepSleepTimer && !iDeepSleepTimer->IsActive() )
       
 10693         {
       
 10694         iDeepSleepTimer->StartTimer();
       
 10695         }
       
 10696     }
       
 10697 
       
 10698 // ---------------------------------------------------------------------------
       
 10699 // CCamAppController::DeepSleepTimerCancel
       
 10700 // ---------------------------------------------------------------------------
       
 10701 //
       
 10702 void CCamAppController::DeepSleepTimerCancel()
       
 10703     {
       
 10704     PRINT( _L("Camera : DeepSleepTimerCancel") );
       
 10705     if ( iDeepSleepTimer )
       
 10706         {
       
 10707         iDeepSleepTimer->Cancel();
       
 10708         }
       
 10709     }
       
 10710 
       
 10711 // ---------------------------------------------------------------------------
       
 10712 // CCamAppController::AllSnapshotsReceived
       
 10713 // ---------------------------------------------------------------------------
       
 10714 //    
       
 10715 TBool CCamAppController::AllSnapshotsReceived()
       
 10716     {
       
 10717     PRINT1( _L("Camera <> AllSnapshotsReceived %d"), iAllSnapshotsReceived );	
       
 10718     return iAllSnapshotsReceived;	
       
 10719     }
       
 10720 
       
 10721 // ---------------------------------------------------------------------------
       
 10722 // CCamAppController::PendingAFRequest
       
 10723 // ---------------------------------------------------------------------------
       
 10724 // 
       
 10725 TInt CCamAppController::PendingAFRequest()
       
 10726     {
       
 10727     return iPendingAFRequest;
       
 10728     }
       
 10729 
       
 10730 
       
 10731 
       
 10732 // CCamAppController::IsTouchScreenSupported
       
 10733 // Return whether the device supports touch screen
       
 10734 // ---------------------------------------------------------------------------
       
 10735 //  
       
 10736 TBool CCamAppController::IsTouchScreenSupported()
       
 10737     {
       
 10738     return AknLayoutUtils::PenEnabled();
       
 10739     }
       
 10740 
       
 10741 // ---------------------------------------------------------------------------
       
 10742 // CCamAppController::IsTouchScreenSupported
       
 10743 // Return whether the device supports direct screen viewfinder
       
 10744 // ---------------------------------------------------------------------------
       
 10745 //  
       
 10746 TBool CCamAppController::IsDirectScreenVFSupported( TBool aPrimaryCamera )
       
 10747     {
       
 10748     // test for integration
       
 10749     return iConfigManager->IsDSAViewFinderSupported( aPrimaryCamera );
       
 10750     }
       
 10751 
       
 10752 // ---------------------------------------------------------------------------
       
 10753 // CCamAppController::UiConfigManagerPtr
       
 10754 // handle  to CameraUiConfigManager
       
 10755 // ---------------------------------------------------------------------------
       
 10756 //  
       
 10757 CCameraUiConfigManager* CCamAppController::UiConfigManagerPtr()
       
 10758     {
       
 10759 	__ASSERT_DEBUG(iConfigManager, CamPanic(ECamPanicNullPointer));
       
 10760     return iConfigManager;
       
 10761     }
       
 10762 
       
 10763 	
       
 10764 // ---------------------------------------------------------------------------
       
 10765 // CCamAppController::SetCameraOrientationModeL
       
 10766 // 
       
 10767 // ---------------------------------------------------------------------------
       
 10768 //  
       
 10769 void CCamAppController::SetCameraOrientationModeL( TInt aOrientation )
       
 10770     {
       
 10771     iCameraController->SetOrientationModeL( aOrientation );
       
 10772     }
       
 10773     
       
 10774 // ---------------------------------------------------------------------------
       
 10775 // CCamAppController::CompleteCameraConstruction
       
 10776 // 
       
 10777 // ---------------------------------------------------------------------------
       
 10778 //  
       
 10779 void CCamAppController::CompleteCameraConstructionL()
       
 10780     {
       
 10781     PRINT( _L( "Camera => CCamAppController::CompleteCameraConstructionL" ) );    	
       
 10782     iCameraController->CompleteSwitchCameraL();
       
 10783     // start reserve and poweron already here
       
 10784     IssueModeChangeSequenceL( ETrue );
       
 10785     PRINT( _L( "Camera <= CCamAppController::CompleteCameraConstructionL" ) );    	    
       
 10786     }
       
 10787 
       
 10788 // ---------------------------------------------------------------------------
       
 10789 // CCamAppController::CurrentImageIndex
       
 10790 // 
       
 10791 // ---------------------------------------------------------------------------
       
 10792 //  
       
 10793 TInt CCamAppController::CurrentImageIndex()
       
 10794     {
       
 10795     return iCurrentImageIndex;
       
 10796     }
       
 10797 // ---------------------------------------------------------------------------
       
 10798 // 
       
 10799 // ---------------------------------------------------------------------------
       
 10800 //
       
 10801 void
       
 10802 CCamAppController::GenerateStartupSequenceL( RCamRequestArray& aSequence )
       
 10803   {
       
 10804   PRINT( _L( "Camera => CCamAppController::GenerateStartupSequenceL" ) );
       
 10805 
       
 10806   //Have to empty autofocusrequest values here because modechange could override
       
 10807   //currently processed autofocus request.
       
 10808   iPendingAFRequest=0;
       
 10809   iCurrentAFRequest=0;
       
 10810   iNoBurstCancel = EFalse;
       
 10811   iKeyUP = EFalse;
       
 10812 
       
 10813   aSequence.Append( ECamRequestReserve );
       
 10814   aSequence.Append( ECamRequestPowerOn );
       
 10815 
       
 10816   // -------------------------------------------------------
       
 10817 #ifdef _DEBUG
       
 10818   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
 10819   for( TInt i = 0; i < aSequence.Count(); i++ )
       
 10820     {
       
 10821     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
 10822     }
       
 10823 #endif  
       
 10824   PRINT( _L( "Camera <= CCamAppController::GenerateStartupSequenceL" ) );
       
 10825   }    
       
 10826   
       
 10827 // ---------------------------------------------------------------------------
       
 10828 // CCamAppController::RotateSnapshotL
       
 10829 // Copy and rotate snapshot bitmap before it is used to
       
 10830 // create a thumbnail
       
 10831 // ---------------------------------------------------------------------------
       
 10832 //  
       
 10833 void CCamAppController::RotateSnapshotL()
       
 10834     {
       
 10835     PRINT( _L( "Camera => CCamAppController::RotateSnapshotL" ) );
       
 10836     // empty the array
       
 10837     if( iRotationArray->Count() > 0 )
       
 10838         {
       
 10839         iRotationArray->Reset();
       
 10840         }
       
 10841     // copy snapshot to preserve the original snapshot bitmap
       
 10842     // first get the handle for the original snapshot bitmap
       
 10843     CFbsBitmap* snapshot = new (ELeave)CFbsBitmap();
       
 10844     CleanupStack::PushL( snapshot );
       
 10845     snapshot->Duplicate( BurstCaptureArray()->Snapshot( iCurrentImageIndex )->Handle() );
       
 10846     //create a new bitmap with the same dimensions as the original snapshot
       
 10847     iRotatedSnapshot = new (ELeave)CFbsBitmap();
       
 10848     iRotatedSnapshot->Create( snapshot->SizeInPixels(), snapshot->DisplayMode() );
       
 10849     TRect tmpRect( TPoint( 0, 0 ), snapshot->SizeInPixels() );
       
 10850     TInt tmpLen = tmpRect.Width() * tmpRect.Height() * 4;
       
 10851     //copy the snapshot data
       
 10852     iRotatedSnapshot->BeginDataAccess();
       
 10853     snapshot->BeginDataAccess();
       
 10854     Mem::Copy( iRotatedSnapshot->DataAddress(), snapshot->DataAddress(), tmpLen );
       
 10855     iRotatedSnapshot->EndDataAccess();
       
 10856     snapshot->EndDataAccess();
       
 10857     // copy the filename 
       
 10858     iRotationArray->SetNextNameL( BurstCaptureArray()->FileName( iCurrentImageIndex ), BurstCaptureArray()->ImageName( iCurrentImageIndex ));
       
 10859     // rotate the copied snapshot 
       
 10860     if ( !iRotatorAo )
       
 10861         {
       
 10862         iRotatorAo = CCamSyncRotatorAo::NewL( *this );
       
 10863         }    
       
 10864     iRotatorAo->RotateL( iRotatedSnapshot, MapCamOrientation2RotationAngle( iCaptureOrientation ) );
       
 10865         
       
 10866     CleanupStack::Pop( snapshot );
       
 10867     PRINT( _L( "Camera <= CCamAppController::RotateSnapshotL" ) );    
       
 10868     } 
       
 10869     
       
 10870 // ---------------------------------------------------------------------------
       
 10871 // CCamAppController::RotationCompleteL
       
 10872 // Notification of bitmap rotation complete events
       
 10873 // ---------------------------------------------------------------------------
       
 10874 //  
       
 10875 void CCamAppController::RotationCompleteL( TInt aErr )
       
 10876     {
       
 10877     PRINT1( _L( "Camera => CCamAppController::RotationCompleteL aErr:%d" ), aErr );
       
 10878     // rotation completed, use the rotated bitmap to create a thumbnail    
       
 10879     // in case of error, don't use the snapshot, thumbnail is created from 
       
 10880     // the imagefile instead
       
 10881     if ( !aErr )
       
 10882         {
       
 10883         iRotationArray->ReplaceSnapshot( iRotatedSnapshot, 0 );
       
 10884         }
       
 10885     TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *iRotationArray ) );
       
 10886             
       
 10887     PRINT( _L( "Camera <= CCamAppController::RotationCompleteL" ) );         
       
 10888         }     
       
 10889       
       
 10890 // ---------------------------------------------------------------------------
       
 10891 // CCamAppController::StoreFaceTrackingValue
       
 10892 // Calls CamSettingModel to save user defined FT setting
       
 10893 // ---------------------------------------------------------------------------
       
 10894 //  
       
 10895 void CCamAppController::StoreFaceTrackingValue()
       
 10896    {
       
 10897    iSettingsModel->StoreFaceTrackingValue();	
       
 10898    }
       
 10899 
       
 10900 // ---------------------------------------------------------------------------
       
 10901 // CCamAppController::SetVideoInitNeeded
       
 10902 // Sets the value defining the need for CAE video init and prepare
       
 10903 // ---------------------------------------------------------------------------
       
 10904 //  
       
 10905 void CCamAppController::SetVideoInitNeeded( TBool aVideoInitNeeded )
       
 10906     {
       
 10907     iVideoInitNeeded = aVideoInitNeeded;  
       
 10908     }
       
 10909 
       
 10910 // ---------------------------------------------------------------------------
       
 10911 // CCamAppController::VideoInitNeeded
       
 10912 // Returns the value defining the need for CAE video init and prepare
       
 10913 // ---------------------------------------------------------------------------
       
 10914 //  
       
 10915 TBool CCamAppController::VideoInitNeeded()
       
 10916     {
       
 10917     return iVideoInitNeeded;  
       
 10918     }
       
 10919     
       
 10920 // ---------------------------------------------------------------------------
       
 10921 // StoreUserSceneSettingsL
       
 10922 // Stores the UserScene settings
       
 10923 // ---------------------------------------------------------------------------
       
 10924 //  
       
 10925 void CCamAppController::StoreUserSceneSettingsL()
       
 10926     {
       
 10927     iSettingsModel->StoreUserSceneSettingsL();	    
       
 10928     }      
       
 10929 //  End of File