camerauis/cameraapp/generic/src/CamAppController.cpp
branchRCL_3
changeset 54 bac7acad7cb3
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     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 <akntoolbarextension.h>
       
    36 #include <centralrepository.h>
       
    37 
       
    38 #include <ctsydomainpskeys.h>
       
    39 #include <ProfileEngineSDKCRKeys.h>
       
    40 #include <sysutildomaincrkeys.h>
       
    41 #include <ScreensaverInternalPSKeys.h>
       
    42 #include <musresourceproperties.h>
       
    43 #include <cameraplatpskeys.h>
       
    44 #include <bitmaptransforms.h>
       
    45 #include <sensrvorientationsensor.h>
       
    46 #include <sensrvchannel.h>
       
    47 #include <sensrvchannelfinder.h>
       
    48 
       
    49 #include <UsbWatcherInternalPSKeys.h>
       
    50 #include <usbpersonalityids.h>
       
    51 
       
    52 #include <UikonInternalPSKeys.h>
       
    53 
       
    54 #include <cameraapp.rsg>
       
    55 #include <vgacamsettings.rsg>
       
    56 #include "CamSettingsInternal.hrh"
       
    57 #include "CamProductSpecificSettings.hrh"
       
    58 #include "CameraappPrivateCRKeys.h"
       
    59 #include "CamAppController.h"
       
    60 #include "CamUtility.h"
       
    61 #include "CamLogger.h"
       
    62 #include "CamSettings.hrh"
       
    63 #include "CamSettingsModel.h"
       
    64 #include "CamPanic.h"
       
    65 #include "CamBurstCaptureArray.h"
       
    66 #include "CamTimer.h"
       
    67 #include "CamImageSaveActive.h"
       
    68 #include "CamAppUi.h"
       
    69 #include "CamObserverHandler.h"
       
    70 #include "CamSelfTimer.h"
       
    71 #include "camflashstatus.h"
       
    72 
       
    73 #include "CamPerformance.h"
       
    74 #include "OstTraceDefinitions.h"
       
    75 #ifdef OST_TRACE_COMPILER_IN_USE
       
    76 #include "CamAppControllerTraces.h"
       
    77 #endif
       
    78 
       
    79 #include "CamVideoQualityLevel.h"
       
    80 #include "CamCallStateAo.h"    
       
    81 #include "CamPropertyWatcher.h"
       
    82 #include <avkondomainpskeys.h>
       
    83 #include <ProfileEngineInternalPSKeys.h>
       
    84 #include <ProfileEnginePrivatePSKeys.h>
       
    85 
       
    86 #ifndef __WINSCW__
       
    87   #include "rlocationtrail.h"
       
    88   #include "locationtrailpskeys.h"
       
    89 #endif
       
    90 //#include "camconstantsettingprovider.h"
       
    91 #include "camsettingprovider.h"
       
    92 #include "camsettingconversion.h"
       
    93 #include "camcamerarequests.h"
       
    94 #include "camcameraevents.h"
       
    95 #include "camcameracontrollertypes.h"
       
    96 #include "camcameracontroller.h"
       
    97 #include "cambuffershare.h"
       
    98 #include "cambuffersharecleanup.h"
       
    99 #include "camaudioplayercontroller.h"
       
   100 #include "camuidconstants.h"
       
   101 #include "camconfiguration.h"
       
   102 #include "CamPreCaptureViewBase.h"
       
   103 #include "CamPostCaptureViewBase.h"
       
   104 
       
   105 #include <cfclient.h>
       
   106 #include <cfcontextobject.h>
       
   107 #include <cfcontextquery.h>
       
   108 
       
   109 #include "camvideotime.h"
       
   110 #include "CamGSInterface.h"
       
   111 #include "CameraUiConfigManager.h"
       
   112 #include "camsnapshotrotator.h"
       
   113 #include "CamVideoPreCaptureView.h"
       
   114 
       
   115 #include <bitmaptransforms.h> 
       
   116 
       
   117 #ifdef _DEBUG
       
   118 #ifdef _AO_TRACKING
       
   119 struct CFakeActiveScheduler : public CActiveScheduler {
       
   120   virtual TInt Extension_( TUint, TAny *&, TAny* ) { return 0; }
       
   121 };
       
   122 #endif // _AO_TRACKING
       
   123 #endif // _DEBUG
       
   124 
       
   125 // ===========================================================================
       
   126 // Local constants
       
   127 
       
   128 // Sequence mode related constants that define the amount of pictures taken
       
   129 // with sequence mode.
       
   130 const TInt KShortBurstCount  = 18;   // number of images captured during burst
       
   131 const TInt KMinBurstCount    = 2;    // minimum of images captured
       
   132 const TInt KBurstEstimate    = 10;   // Correction of underestimated file size  
       
   133 
       
   134 const TUint32 KCamLatestFilePath      = 0x00000001;
       
   135 
       
   136 
       
   137 // temporary constants until image naming is implemented
       
   138 _LIT( KImageExtension, ".jpg" );
       
   139 _LIT( KVideo3GPExtension, ".3gp" );
       
   140 #ifndef __WINS__
       
   141 _LIT( KVideoMP4Extension, ".mp4" );
       
   142 #endif
       
   143 
       
   144 const TInt KMaxExtension = 4;
       
   145 //const TInt64 KBurstInterval = 0;
       
   146 
       
   147 const TInt KIdleTimeout     = 1000000 * 60; // 60 seconds
       
   148 const TInt KDeepSleepTimeout = KIdleTimeout*2; // Measuring time is two minutes  
       
   149 const TInt KVideoArrayUsers = 1;
       
   150 const TInt KImageArrayUsers = 2;
       
   151 
       
   152 const TInt KVideoNameRetryCount = 1;    // Maximum number of video naming retries
       
   153 
       
   154 // UID for central repository file
       
   155 const TInt KCRCamShutterSound = 0x7; // key for shutter sound
       
   156 
       
   157 const TInt KMicroSecsInMilliSec = 1000;
       
   158 const TInt KSecondInMicSec = 1000000;
       
   159 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
   160 const TInt KLocTrailCloseRetryTime = 5 * KSecondInMicSec;
       
   161 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
   162 
       
   163 // Estimated time needed to complete autofocus
       
   164 const TInt KFocusingDurationSeconds = 2;
       
   165 
       
   166 const TInt KCCorFocused = 0x00000002;
       
   167 
       
   168 const TInt KCamMaxDateLen = 8;
       
   169 
       
   170 static const TInt KTimelapseArrayGranularity = 6;
       
   171 
       
   172 // Backlight / Inactivity timer related
       
   173 //   Callback interval is set to 4s. 
       
   174 //   Smallest value that the user can select from Phone Settings is 5s.
       
   175 static const TInt KBacklighTimerPriority = CActive::EPriorityHigh;
       
   176 static const TInt KBacklighTimerInterval = 4*1000*1000; 
       
   177 
       
   178 // Camera Controller events interest.
       
   179 //   Want to receive all events.
       
   180 //   Vf frames needed for correct zoom handling (should be left out otherwise).
       
   181 static const TUint KCamEventInterest = (  ECamCameraEventClassAll );
       
   182 
       
   183 static const TInt KLensCoverDelay = 500*1000;
       
   184 
       
   185 _LIT( KCamContextSource, "Application" );
       
   186 _LIT( KCamContextType, "Camera.Zoom" );
       
   187 _LIT( KCamContextValueEnable, "Enabled" );
       
   188 _LIT( KCamContextValueDisable, "Disabled" );
       
   189 _LIT_SECURITY_POLICY_PASS( KCamContextSecurity );
       
   190 
       
   191 static const TInt KCriticalMemoryLevel = 5*1000*1000;
       
   192 // ===========================================================================
       
   193 // Local namespace
       
   194 namespace NCamAppController
       
   195   {
       
   196   // -------------------------------------------------------
       
   197   // Request sequences 
       
   198 //  static const TCamCameraRequestId KCamSequencePowerOffOn[] = 
       
   199 //    { 
       
   200 //    ECamRequestPowerOff, 
       
   201 //    ECamRequestPowerOn
       
   202 //    };
       
   203   
       
   204   // -------------------------------------------------------
       
   205   // Local methods
       
   206 
       
   207   inline TInt ResetBitmap( CFbsBitmap*& aBitmap )
       
   208     {
       
   209     if( aBitmap )
       
   210       {
       
   211       aBitmap->Reset();
       
   212       return KErrNone;
       
   213       }
       
   214     else
       
   215       {
       
   216       TRAPD( create, aBitmap = new (ELeave) CFbsBitmap() );
       
   217       return create;
       
   218       }
       
   219     };
       
   220 
       
   221   inline void ClearSequenceBusyFlag( TAny* aBusyFlags )
       
   222     {
       
   223     TUint* flags = static_cast<TUint*>( aBusyFlags );
       
   224     if( flags )
       
   225       {
       
   226       *flags &= ~EBusySequence;
       
   227       }
       
   228     };
       
   229 
       
   230   inline void ClearRequestBusyFlag( TAny* aBusyFlags )
       
   231     {
       
   232     TUint* flags = static_cast<TUint*>( aBusyFlags );
       
   233     if( flags )
       
   234       {
       
   235       *flags &= ~EBusyRequest;
       
   236       }
       
   237     };
       
   238   }
       
   239 
       
   240 #include "camflagutility.inl"
       
   241 #include "campointerutility.inl"
       
   242 
       
   243 using namespace NCamAppController;
       
   244 using namespace NCamCameraController;
       
   245 // ===========================================================================
       
   246 
       
   247 
       
   248 // ===========================================================================
       
   249 // Member functions
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CCamAppController::NewL
       
   253 // Two-phased constructor.
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 CCamAppController* CCamAppController::NewL()
       
   257     {
       
   258     CCamAppController* self = new( ELeave ) CCamAppController();
       
   259     CleanupStack::PushL( self );
       
   260     self->ConstructL();
       
   261     CleanupStack::Pop( self );
       
   262     return self;
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CCamAppController::CompleteConstructionL
       
   268 // The camera engine cannot be instantiated until the application orientation has 
       
   269 // been set by the CCamAppUi. This does not exist when the CCamAppController is 
       
   270 // constructed. CompleteConstructionL must be called in CCamAppUi::ConstructL()
       
   271 // ---------------------------------------------------------------------------
       
   272 //    
       
   273 void CCamAppController::CompleteConstructionL()
       
   274   {
       
   275   PRINT( _L("Camera => CCamAppController::CompleteConstructionL" ))
       
   276 
       
   277   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
   278   
       
   279   // Memory critical levels reading moved to the point when
       
   280   // those values are actually needed for the first time.   
       
   281 
       
   282   TInt index = 0;
       
   283   iInfo.iActiveCamera = ECamActiveCameraPrimary;
       
   284   PRINT1( _L("Camera <> Cameras available: %d"), CamerasAvailable() )
       
   285   
       
   286   PRINT( _L("Camera <> Store primary camera settings"))
       
   287   iSettingsModel->StorePrimaryCameraSettingsL();
       
   288 
       
   289 
       
   290   PRINT1( _L("Camera <> CCamAppController::CompleteConstructionL iSlideState initial value = %d" ), iSlideState)
       
   291   if ( iConfigManager->IsLensCoverSupported() )
       
   292       {
       
   293       // Request notification of slide state changes
       
   294       iSlideStateWatcher->Subscribe();
       
   295 
       
   296       // Read the current slider status - use the front camera (if there is one) as default if
       
   297       // there are any errors.
       
   298       TInt slideErr = iSlideStateWatcher->Get( iSlideState );
       
   299       PRINT1( _L("Camera <> CCamAppController::CompleteConstructionL setting iSlideState to %d" ), iSlideState)
       
   300       TInt requiredOrientation;
       
   301       if ( ( appUi->CamOrientation() == ECamOrientationCamcorderLeft && iSlideState == CameraPlatPSKeys::EClosed ) ||
       
   302             ( appUi->CamOrientation() == ECamOrientationCamcorder && iSlideState == CameraPlatPSKeys::EClosed ) )
       
   303         {
       
   304         if ( appUi->IsQwerty2ndCamera() )
       
   305             {  
       
   306             PRINT( _L("Camera <> Do not exit. Reload landscape 2nd camera settings") )
       
   307             index = 1;
       
   308             iInfo.iActiveCamera = ECamActiveCameraSecondary;
       
   309             CCamAppUi* appUi = static_cast<CCamAppUi*>( 
       
   310                                CEikonEnv::Static()->AppUi() ); 
       
   311             // We may have primary camera settings loaded 
       
   312             LoadStaticSettingsL( appUi->IsEmbedded() );   
       
   313             CamUtility::GetPsiInt( ECamPsiSecondaryCameraOrientation, 
       
   314                                    requiredOrientation );
       
   315             }
       
   316         else
       
   317             {
       
   318             PRINT( _L("Camera <> Lens cover has been closed during camera construction. Exit camera.") )
       
   319             appUi->HandleCommandL( EEikCmdExit);
       
   320             }
       
   321         }
       
   322       else  
       
   323         {  
       
   324         // if the slide is closed or there is an error, then use the front camera
       
   325         // check that there is more than 1 camera and that the current orientation is correct
       
   326         if ( ( iSlideState == CameraPlatPSKeys::EClosed               
       
   327               || slideErr    != KErrNone )
       
   328               && CamerasAvailable() > 1 )
       
   329           {
       
   330           PRINT( _L("Camera <> CCamAppController::CompleteConstructionL slider is not open" ))
       
   331           index = 1;
       
   332           iInfo.iActiveCamera = ECamActiveCameraSecondary;
       
   333           CamUtility::GetPsiInt( ECamPsiSecondaryCameraOrientation, requiredOrientation );
       
   334           }
       
   335         else // slide is open or using primary camera as default
       
   336           {
       
   337           PRINT( _L("Camera <> CCamAppController::CompleteConstructionL slider is open- primary camera in use" ))
       
   338           index = 0;
       
   339           iInfo.iActiveCamera = ECamActiveCameraPrimary;
       
   340 
       
   341           //when active camera is primary camera,orientation must be landscape,
       
   342           //so need to fix orientation
       
   343           if ( ECamOrientationPortrait == appUi->CamOrientation() )
       
   344             {
       
   345             TInt primaryOrientation;
       
   346             CamUtility::GetPsiInt( ECamPsiPrimaryCameraOrientation, 
       
   347                                       primaryOrientation );
       
   348             appUi->SetOrientationL( ( CAknAppUiBase::TAppUiOrientation ) primaryOrientation );		
       
   349             appUi->SetCamOrientationToLandscape();
       
   350             }
       
   351           }   
       
   352         }
       
   353       }
       
   354 
       
   355   ConstructCameraControllerL( index );
       
   356   
       
   357   // Send startup sequence ?
       
   358 
       
   359   /**
       
   360    * Removed all custom interfaces requested from engine
       
   361    */
       
   362   iAccSensorListening = EFalse;
       
   363 
       
   364   iCallStateAo = CCamCallStateAo::NewL( this );             
       
   365   
       
   366   // Use backlight timer instead of every Nth vf frame event
       
   367   // to reset inactivity timer. This is to avoid adding load
       
   368   // when higher VF frame rates are used (and overall load is
       
   369   // already higher).
       
   370   iBacklightTimer = CPeriodic::NewL( KBacklighTimerPriority );
       
   371 
       
   372 #ifdef _DEBUG
       
   373 #ifdef _AO_TRACKING
       
   374   TAny *iAoBacklightTimer = (TAny *)iBacklightTimer;
       
   375   PRINT2( _L("Camera <> CCamAppController: BacklightTimer=%x, %d"),iBacklightTimer, iAoBacklightTimer );
       
   376   CActiveScheduler *pAS = CActiveScheduler::Current();
       
   377   CFakeActiveScheduler *pFAS = static_cast<CFakeActiveScheduler*>(pAS);
       
   378   pFAS->Extension_( 0, iAoBacklightTimer, (TAny *)("iBacklightTimer") );
       
   379 #endif // _AO_TRACKING
       
   380 #endif // _DEBUG
       
   381 
       
   382 #ifdef _DEBUG
       
   383 #ifdef _AO_TRACKING
       
   384   TAny *iAoDeepSleepTimer = (TAny *)iDeepSleepTimer;
       
   385   PRINT2( _L("Camera <> CCamAppController: DeepSleepTimer=%x, %d"),iDeepSleepTimer, iAoDeepSleepTimer );
       
   386   CActiveScheduler *pAS2 = CActiveScheduler::Current();
       
   387   CFakeActiveScheduler *pFAS2 = static_cast<CFakeActiveScheduler*>(pAS2);
       
   388   pFAS2->Extension_( 0, iAoDeepSleepTimer, (TAny *)("iDeepSleepTimer") );
       
   389 #endif // _AO_TRACKING
       
   390 #endif // _DEBUG
       
   391 
       
   392 
       
   393   if ( UiConfigManagerPtr()->IsXenonFlashSupported() )
       
   394       {
       
   395       PRINT( _L("Camera <> CCamAppController: Create flash status observer..") );
       
   396       iFlashStatus = CCamFlashStatus::NewL( *this );
       
   397       }
       
   398 
       
   399   PRINT( _L("Camera <= CCamAppController::CompleteConstructionL" ))
       
   400   }    
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // 
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 TInt 
       
   408 CCamAppController::GetCriticalMemoryLevelL( const TCamMediaStorage& aStorage )
       
   409   {
       
   410   PRINT( _L("Camera => CCamAppController::GetCriticalMemoryLevelL" ) )
       
   411 
       
   412   // If this is the first call here, get the critical levels from
       
   413   // Central repository. Later the cached values will be used.
       
   414   if( KErrNotFound == iRamDiskCriticalLevel
       
   415    || KErrNotFound == iDiskCriticalLevel   )
       
   416     {
       
   417     CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
   418     TInt err;
       
   419     err = repository->Get( KDiskCriticalThreshold , iDiskCriticalLevel );
       
   420     if ( KErrNone != err )
       
   421       {
       
   422       CamPanic( ECamPanicDefaultNotFoundInIniFile );      
       
   423       }
       
   424     err = repository->Get( KRamDiskCriticalLevel , iRamDiskCriticalLevel ); 
       
   425     if ( KErrNone != err )
       
   426       {
       
   427       CamPanic( ECamPanicDefaultNotFoundInIniFile ); 
       
   428       } 
       
   429     CleanupStack::PopAndDestroy( repository );
       
   430     }
       
   431   
       
   432   TInt level = ( aStorage == ECamMediaStoragePhone ) 
       
   433              ? iRamDiskCriticalLevel
       
   434              : iDiskCriticalLevel;
       
   435 
       
   436   PRINT1( _L("Camera <= CCamAppController::GetCriticalMemoryLevelL, level:%d" ), level )
       
   437   return level;
       
   438   }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // CCamAppController::~CCamAppController
       
   442 // Destructor
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 CCamAppController::~CCamAppController()
       
   446   { 
       
   447   PRINT( _L("Camera => ~CCamAppController") );
       
   448   // As a precaution, make sure the screen saver is never left in a disabled state
       
   449   EnableScreenSaver( ETrue );
       
   450 
       
   451   RProperty::Set( KPSUidCamcorderNotifier, KCCorFocused, 0 );
       
   452   
       
   453   if ( iFlashStatus )
       
   454     {
       
   455     delete iFlashStatus;
       
   456     }
       
   457 
       
   458   delete iSoundPlayer;
       
   459 
       
   460   PRINT( _L("Camera <> close observers array..") );
       
   461   __ASSERT_DEBUG( iControllerObservers.Count() == 0, CamPanic( ECamPanicResourceLeak ) );
       
   462   iControllerObservers.Close();
       
   463 
       
   464   delete iCallStateAo;    
       
   465 
       
   466   delete iBurstTimer;
       
   467 
       
   468 // Using timer also on bitmap mode.
       
   469   if( iBacklightTimer )
       
   470     {
       
   471     iBacklightTimer->Cancel();
       
   472     delete iBacklightTimer;
       
   473     }
       
   474 
       
   475     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && 
       
   476     		iAccSensorListening )
       
   477         {
       
   478         iAccSensorChannel->StopDataListening();
       
   479         iAccSensorChannel->CloseChannel();
       
   480         }
       
   481     delete iAccSensorChannel;
       
   482 
       
   483   if ( iSlideStateWatcher )
       
   484     {
       
   485     iSlideStateWatcher->Cancel();
       
   486     delete iSlideStateWatcher;
       
   487     }
       
   488   
       
   489   if ( iSliderCallBack )
       
   490     { 
       
   491     iSliderCallBack->Cancel();
       
   492     delete iSliderCallBack;
       
   493     iSliderCallBack = NULL;
       
   494     }
       
   495 
       
   496   if ( iKeyLockStatusWatcher && iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
   497     {
       
   498     iKeyLockStatusWatcher->Cancel();
       
   499     delete iKeyLockStatusWatcher;
       
   500     }
       
   501   
       
   502   if ( iProfileStatusWatcher )
       
   503       {
       
   504       iProfileStatusWatcher->Cancel();
       
   505       delete iProfileStatusWatcher;
       
   506       }
       
   507   
       
   508   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() )
       
   509       {
       
   510       TRAP_IGNORE ( PublishZoomStateL( EFalse ) );
       
   511       delete iContextFwClient;      
       
   512       }
       
   513 
       
   514   if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
   515     {
       
   516     if( iLocationTrailTimer )
       
   517       {
       
   518       iLocationTrailTimer->Cancel();
       
   519       delete iLocationTrailTimer;
       
   520       iLocationTrailTimer = NULL;
       
   521       }
       
   522     }
       
   523       
       
   524   if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
   525     {
       
   526     // stop trail and close session
       
   527     StopLocationTrail( ETrue );
       
   528     }
       
   529 
       
   530   if ( iImageSaveActive )  
       
   531     {
       
   532       iImageSaveActive->ForceCancel();
       
   533     delete iImageSaveActive;
       
   534     }
       
   535 
       
   536   PRINT( _L("Camera <> delete settingsmodel..") );
       
   537   delete iSettingsModel;  // Must be before iEngine deleted
       
   538   iSettingsPreviewHandler = NULL; // Currently the Settings Model object.
       
   539   iPreviewRollbacks.Close();
       
   540 
       
   541 
       
   542   delete iCaptureArray;
       
   543   delete iRotationArray;
       
   544   if ( iSequenceFilenameArray )
       
   545     {
       
   546     iSequenceFilenameArray->Reset();
       
   547     delete iSequenceFilenameArray;
       
   548     }    
       
   549 
       
   550   if( iDeepSleepTimer )
       
   551     {
       
   552     iDeepSleepTimer->Cancel();
       
   553     delete iDeepSleepTimer;
       
   554     }
       
   555 
       
   556   if( iIdleTimer )
       
   557     {
       
   558     iIdleTimer->Cancel();
       
   559     delete iIdleTimer;
       
   560     }
       
   561 
       
   562   if ( iTimeLapseTimer )
       
   563     {
       
   564     iTimeLapseTimer->Cancel();
       
   565     delete iTimeLapseTimer;
       
   566     }
       
   567 
       
   568   if( iCaptureToneDelayTimer )
       
   569     {
       
   570     iCaptureToneDelayTimer->Cancel();
       
   571     delete iCaptureToneDelayTimer;
       
   572     }
       
   573 
       
   574   delete iCaptureCompletionObserverHandler;      
       
   575   delete iSnapShotCopy; 
       
   576     
       
   577   iJpegDataSizes.Close();
       
   578   iSequencePostProcessDataSizes.Close();
       
   579   
       
   580   // Close the arrays
       
   581   iPendingObserversArray.Close();
       
   582   iCameraEventInterested.Close();
       
   583 
       
   584   // Controller handles releasing CCamera if needed.
       
   585   PRINT( _L("Camera <> delete camera controller..") );
       
   586   delete iCameraController;
       
   587   PRINT( _L("Camera <> delete setting provider..") );
       
   588   delete iSettingProvider;
       
   589   PRINT( _L("Camera <= ~CCamAppController") );
       
   590   
       
   591   PRINT( _L("Camera <> delete Configuration Manager..") );
       
   592   delete iConfiguration;
       
   593   iConfiguration = NULL;  
       
   594 
       
   595   RProperty::Delete( KPSUidCamcorderNotifier, KCCorFocused );  
       
   596     if( iPlugin )
       
   597         {
       
   598         // Destroy Ecom plugin
       
   599         iPlugin->DestroyPlugin();
       
   600         }
       
   601   iPlugin = NULL;
       
   602   delete iDriveChangeNotifier;
       
   603   iFs.Close();
       
   604   
       
   605   if( iRotatorAo )
       
   606       {
       
   607       delete iRotatorAo;
       
   608       }
       
   609 
       
   610   delete iSnapShotRotator;
       
   611   
       
   612   if( iTvAccessoryMonitor )
       
   613       {
       
   614       delete iTvAccessoryMonitor;
       
   615       iTvAccessoryMonitor = NULL;
       
   616       }
       
   617   
       
   618   PRINT( _L("Camera <= ~CCamAppController") );
       
   619   }
       
   620 
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 // CCamAppController::SavedCurrentImage
       
   624 // Returns whether the last requested captured image has been saved or not.
       
   625 // ---------------------------------------------------------------------------
       
   626 //
       
   627 TBool CCamAppController::SavedCurrentImage() const
       
   628   {
       
   629   PRINT( _L("Camera => CCamAppController::SavedCurrentImage") );
       
   630   TBool saved( ETrue );
       
   631 
       
   632   // If we are waiting for a save request then image has not been saved.
       
   633   if( iImageSaveRequestPending )
       
   634     {
       
   635     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: iImageSaveRequestPending") )
       
   636     saved = EFalse;
       
   637     }
       
   638   else if( CurrentFullFileName() == KNullDesC )
       
   639     {
       
   640     saved = EFalse;
       
   641     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: filename not yet reserved") ) 
       
   642     }
       
   643   else if( !iCaptureArray->AlreadySavedFile( CurrentFullFileName() ) ||
       
   644             iCaptureArray->CurrentlySavingFile( CurrentFullFileName() ) )
       
   645     {
       
   646     PRINT( _L("Camera <> CCamAppController::SavedCurrentImage: capture array not saved file or currently saving file") )
       
   647     saved = EFalse;
       
   648     }
       
   649   else if ( iInfo.iOperation == ECamCapturing || iInfo.iOperation == ECamCompleting )
       
   650     {
       
   651    	PRINT(_L("Camera CCamAppController::SavedCurrentImage returning false, capturing/completing") )
       
   652    	saved = EFalse;    
       
   653     }
       
   654   else
       
   655     {
       
   656     // empty
       
   657     }
       
   658 
       
   659   PRINT1( _L("Camera <= CCamAppController::SavedCurrentImage, return %d"), saved );
       
   660   return saved;
       
   661   }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // CCamAppController::RenameCurrentFileL
       
   665 // Rename image/video.
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 TBool 
       
   669 CCamAppController::RenameCurrentFileL( const TDesC&          aNewName, 
       
   670                                        const TCamCameraMode& /*aMode*/ )
       
   671   {
       
   672   TBool status = EFalse;
       
   673 
       
   674   // If file to rename has already been saved then remove from album,
       
   675   // rename the file and add the renamed file to the album.
       
   676   if ( BurstCaptureArray()->AlreadySavedFile( CurrentFullFileName() ) )
       
   677     {                
       
   678     // Rename the file.
       
   679     TFileName filePath = CurrentFullFileName();
       
   680     CamUtility::RenameStillImageL( filePath, aNewName, filePath );
       
   681     
       
   682     // Update capture array with new name and path.
       
   683     BurstCaptureArray()->SetNameL( filePath, aNewName, iCurrentImageIndex );
       
   684     
       
   685     status = ETrue;
       
   686     }
       
   687   // Otherwise, if the file is not currently being saved, modify the names 
       
   688   // in the capture array before it is saved.
       
   689   else if ( !BurstCaptureArray()->CurrentlySavingFile( CurrentFullFileName() ) )
       
   690     {
       
   691     // Update capture array with new name and path.
       
   692     // ...determine new path.
       
   693     TParsePtrC parse( CurrentFullFileName() );
       
   694     TFileName fullNewPath;
       
   695     fullNewPath = parse.DriveAndPath();
       
   696     fullNewPath.Append( aNewName );
       
   697     fullNewPath.Append( parse.Ext() );
       
   698 
       
   699     BurstCaptureArray()->SetNameL( fullNewPath, aNewName, iCurrentImageIndex );
       
   700 
       
   701     status = ETrue;
       
   702     }
       
   703   // Otherwise, the file is in the process of being saved, and 
       
   704   // so that renaming must wait until completed.
       
   705   else
       
   706     {
       
   707     // Leave status to EFalse
       
   708     }
       
   709     
       
   710   return status;
       
   711   }
       
   712 
       
   713 
       
   714 // ---------------------------------------------------------------------------
       
   715 // CCamAppController::AddControllerObserverL
       
   716 // Add a controller observer.
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 void CCamAppController::AddControllerObserverL( const MCamControllerObserver* aObserver )
       
   720   {
       
   721   if( aObserver &&
       
   722       KErrNotFound == iControllerObservers.Find( aObserver ) )
       
   723     {
       
   724     User::LeaveIfError( iControllerObservers.Append( aObserver ) );
       
   725     }
       
   726   }
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // CCamAppController::RemoveControllerObserver
       
   730 // Remove a controller observer.
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 void CCamAppController::RemoveControllerObserver( const MCamControllerObserver* aObserver )
       
   734   {
       
   735   // Errors ignored
       
   736   if( aObserver )
       
   737     {
       
   738     TInt index = iControllerObservers.Find( aObserver );
       
   739     if( KErrNotFound != index )
       
   740       {
       
   741       iControllerObservers.Remove( index );
       
   742       }
       
   743     }
       
   744   }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // AddCameraObserverL
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void 
       
   751 CCamAppController
       
   752 ::AddCameraObserverL( const MCamCameraObserver* aObserver, 
       
   753                       const TUint&              aEventInterest )
       
   754   {
       
   755   PRINT1( _L("Camera => CCamAppController::AddCameraObserverL aObserver=%d"), aObserver );
       
   756 
       
   757   // First check that observer is not in array already
       
   758   if( KErrNotFound == iPendingObserversArray.Find( aObserver ) )
       
   759       {  
       
   760       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL add Observer") );
       
   761 
       
   762       iPendingObserversArray.AppendL( aObserver );
       
   763       iCameraEventInterested.AppendL( aEventInterest );
       
   764       }
       
   765 
       
   766   if( iCameraController )
       
   767       {
       
   768       PRINT(_L("Camera <> CCamAppController::AddCameraObserverL camera controller available") );
       
   769       while ( iPendingObserversArray.Count() > 0 &&
       
   770               iCameraEventInterested.Count() > 0 )
       
   771           {
       
   772           const MCamCameraObserver* camEventObserver = iPendingObserversArray[0];
       
   773           TUint eventInterest = iCameraEventInterested[0];
       
   774           iCameraController->AttachObserverL( camEventObserver, eventInterest );
       
   775           iPendingObserversArray.Remove( 0 );
       
   776           iCameraEventInterested.Remove( 0 );
       
   777           } 
       
   778       }
       
   779   PRINT(_L("Camera <= CCamAppController::AddCameraObserverL") );
       
   780   }
       
   781 
       
   782 // ---------------------------------------------------------------------------
       
   783 // RemoveCameraObserver
       
   784 // ---------------------------------------------------------------------------
       
   785 //
       
   786 void 
       
   787 CCamAppController
       
   788 ::RemoveCameraObserver( const MCamCameraObserver* aObserver )
       
   789   {
       
   790   if( iCameraController )
       
   791     iCameraController->DetachObserver( aObserver );
       
   792   }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // AddSettingsObserverL
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void
       
   799 CCamAppController
       
   800 ::AddSettingsObserverL( const MCamSettingsModelObserver* aObserver )
       
   801   {
       
   802   if( iSettingsModel )
       
   803     iSettingsModel->AttachObserverL( aObserver );
       
   804   else
       
   805     User::Leave( KErrNotReady );
       
   806   }
       
   807 
       
   808 // ---------------------------------------------------------------------------
       
   809 // RemoveCameraObserver
       
   810 // ---------------------------------------------------------------------------
       
   811 //
       
   812 void 
       
   813 CCamAppController
       
   814 ::RemoveSettingsObserver( const MCamSettingsModelObserver* aObserver )
       
   815   {
       
   816   if( iSettingsModel )
       
   817     iSettingsModel->DetachObserver( aObserver );
       
   818   }
       
   819 
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 void 
       
   826 CCamAppController::ConstructCameraControllerL( TInt aCameraIndex )
       
   827   {
       
   828   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 1" );
       
   829   PRINT( _L("Camera => CCamAppController::ConstructCameraControllerL") )
       
   830   PERF_EVENT_START_L2( EPerfEventCAEConstruction );
       
   831 
       
   832   if( !iCameraController )
       
   833     {
       
   834     iCameraController = CCamCameraController::NewL( *iSettingProvider, *this,
       
   835                                                     aCameraIndex ); 
       
   836     //If uiorientationoverride feature is not supported, the camera switch has
       
   837     // to be finished here                                                    
       
   838     if( !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() ) )
       
   839       {
       
   840       iCameraController->CompleteSwitchCameraL();
       
   841       }
       
   842     }
       
   843 
       
   844   // Attach as Camera Controller observer to get events
       
   845   PRINT1( _L("Camera <> Attaching as camera observer with interest:%032b"), KCamEventInterest );
       
   846   iCameraController->AttachObserverL( this, KCamEventInterest );
       
   847 
       
   848 
       
   849   PERF_EVENT_END_L2( EPerfEventCAEConstruction );
       
   850   PRINT( _L("Camera <= CCamAppController::ConstructCameraControllerL") )
       
   851   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_CONSTRUCTCAMERACONTROLLERL, "e_CCamAppController_ConstructCameraControllerL 0" );
       
   852   }
       
   853 
       
   854 // #################################################################################################
       
   855 
       
   856 // ---------------------------------------------------------------------------
       
   857 // Returns the current camera controller state
       
   858 // (Bitfield of type TCamCameraStateFlags )
       
   859 // ---------------------------------------------------------------------------
       
   860 //
       
   861 TUint
       
   862 CCamAppController::CameraControllerState() const
       
   863   {
       
   864   TUint state( ECamIdle );
       
   865   if( iCameraController )
       
   866     {
       
   867     state = iCameraController->State();
       
   868     }
       
   869   PRINT1( _L("Camera =><= CCamAppController::CameraControllerState(): %032b"), state );
       
   870   return state;
       
   871   }
       
   872   
       
   873 // ---------------------------------------------------------------------------
       
   874 // Returns the current camera state
       
   875 // (TCamCameraState)
       
   876 // ---------------------------------------------------------------------------
       
   877 //
       
   878 TCamCameraState
       
   879 CCamAppController::CameraState() const
       
   880   {
       
   881   TCamCameraState state( ECamCameraIdle );  
       
   882   
       
   883   TUint controllerState = CameraControllerState();
       
   884  
       
   885   // Convert controller state to TCamCameraState
       
   886   // Use the state represented by the "most significant"
       
   887   // bit in the bitfield. Ignore VF state.
       
   888   if( IsFlagOn( controllerState, ECamImageOn ) )
       
   889     {
       
   890     state = ECamCameraPreparedImage;
       
   891     }
       
   892   else if( IsFlagOn( controllerState, ECamVideoOn ) )
       
   893     {
       
   894     state = ECamCameraPreparedVideo;  
       
   895     }
       
   896   else if( IsFlagOn( controllerState, ECamPowerOn ) )  
       
   897     {
       
   898     state = ECamCameraPowerOn;  
       
   899     }
       
   900   else if( IsFlagOn( controllerState, ECamReserved ) )  
       
   901     {
       
   902     state = ECamCameraReserved;  
       
   903     }
       
   904     
       
   905   PRINT1( _L("Camera =><= CCamAppController::CameraState(): %d"), state );
       
   906   return state;
       
   907   }  
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 //
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 TCamCameraMode
       
   914 CCamAppController::CurrentMode() const
       
   915   {
       
   916   PRINT1( _L("Camera <> CCamAppController::CurrentMode:%d"), iInfo.iMode );
       
   917   return iInfo.iMode;
       
   918   }
       
   919 
       
   920 // ---------------------------------------------------------------------------
       
   921 //
       
   922 // ---------------------------------------------------------------------------
       
   923 //
       
   924 TCamCameraMode
       
   925 CCamAppController::TargetMode() const
       
   926   {
       
   927   return iInfo.iTargetMode;
       
   928   }
       
   929 
       
   930 // ---------------------------------------------------------------------------
       
   931 //
       
   932 // ---------------------------------------------------------------------------
       
   933 //
       
   934 // CCamAppController::CurrentCaptureModeSetup()
       
   935 TCamImageCaptureMode
       
   936 CCamAppController::CurrentImageModeSetup() const
       
   937   {
       
   938   TCamImageCaptureMode captureMode = ECamImageCaptureSingle; 
       
   939   if( IsAppUiAvailable() ) 
       
   940     { 
       
   941     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
   942     if ( appUi->IsBurstEnabled() ) 
       
   943       { 
       
   944       captureMode = appUi->CurrentBurstMode(); 
       
   945       } 
       
   946     } 
       
   947   return captureMode; 
       
   948   }
       
   949 
       
   950 // ---------------------------------------------------------------------------
       
   951 //
       
   952 // ---------------------------------------------------------------------------
       
   953 //
       
   954 TCamCaptureOperation
       
   955 CCamAppController::CurrentOperation() const
       
   956   {
       
   957   return iInfo.iOperation;
       
   958   }
       
   959 
       
   960 // ---------------------------------------------------------------------------
       
   961 //
       
   962 // ---------------------------------------------------------------------------
       
   963 //
       
   964 TCamCaptureOperation
       
   965 CCamAppController::CurrentImageOperation() const
       
   966   {
       
   967   if( ECamControllerImage == iInfo.iMode )
       
   968     return iInfo.iOperation;
       
   969   else
       
   970     return ECamNoOperation;
       
   971   }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 TCamCaptureOperation  
       
   978 CCamAppController::CurrentVideoOperation() const
       
   979   {
       
   980   if( ECamControllerVideo == iInfo.iMode )
       
   981     return iInfo.iOperation;
       
   982   else
       
   983     return ECamNoOperation;
       
   984   }
       
   985 
       
   986 // ---------------------------------------------------------------------------
       
   987 //
       
   988 // ---------------------------------------------------------------------------
       
   989 //
       
   990 TCamImageCaptureMode  CCamAppController::CurrentImageMode() const
       
   991     {
       
   992     return iInfo.iImageMode;
       
   993     }
       
   994 // ---------------------------------------------------------------------------
       
   995 //
       
   996 // ---------------------------------------------------------------------------
       
   997 //
       
   998 TCamCameraTriState CCamAppController::ViewfinderTargetState() const
       
   999   {
       
  1000   return iInfo.iTargetVfState;
       
  1001   }
       
  1002 
       
  1003 
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 // ---------------------------------------------------------------------------
       
  1007 //
       
  1008 void 
       
  1009 CCamAppController::SetMode( const TCamCameraMode& aNewMode )
       
  1010   {
       
  1011   PRINT3( _L("Camera => CCamAppController::SetMode old[%s] new[%s] target[%s]"), 
       
  1012           KCamModeNames[iInfo.iMode], 
       
  1013           KCamModeNames[aNewMode],
       
  1014           KCamModeNames[iInfo.iTargetMode] );
       
  1015 
       
  1016   if( aNewMode != iInfo.iMode )
       
  1017     {
       
  1018     // In shutdown mode will not accept leaving ECamControllerShutdown state.
       
  1019     TBool newModeNotAccepted = ( IsInShutdownMode() 
       
  1020                               && ECamControllerShutdown == iInfo.iMode 
       
  1021                               && ECamControllerShutdown != aNewMode );
       
  1022     if( !newModeNotAccepted )
       
  1023       {
       
  1024       iInfo.iMode = aNewMode;
       
  1025       NotifyControllerObservers( ECamEventEngineStateChanged );
       
  1026       }
       
  1027     else
       
  1028       {
       
  1029       PRINT( _L("Camera <> this mode change not acceptable in shutdown mode!") );
       
  1030       }      
       
  1031     }
       
  1032   PRINT( _L("Camera <= CCamAppController::SetMode") );
       
  1033   }
       
  1034 
       
  1035 // ---------------------------------------------------------------------------
       
  1036 //
       
  1037 // ---------------------------------------------------------------------------
       
  1038 //
       
  1039 void 
       
  1040 CCamAppController::SetTargetMode( const TCamCameraMode& aNewMode )
       
  1041   {
       
  1042   PRINT2( _L("Camera =><= CCamAppController::SetTargetMode [%s] -> [%s]"), 
       
  1043           KCamModeNames[iInfo.iTargetMode],
       
  1044           KCamModeNames[aNewMode         ] );
       
  1045 
       
  1046   iInfo.iTargetMode = aNewMode;
       
  1047   }
       
  1048 
       
  1049 // ---------------------------------------------------------------------------
       
  1050 //
       
  1051 // ---------------------------------------------------------------------------
       
  1052 //
       
  1053 void 
       
  1054 CCamAppController::SetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1055   {
       
  1056   PRINT2( _L("Camera =><= CCamAppController::SetImageMode [%s] -> [%s]"), 
       
  1057           KCamImageModeNames[iInfo.iImageMode],
       
  1058           KCamImageModeNames[aNewMode        ] );
       
  1059 
       
  1060   iInfo.iImageMode = aNewMode;
       
  1061   // Notify ??
       
  1062   }
       
  1063 
       
  1064 
       
  1065 // ---------------------------------------------------------------------------
       
  1066 //
       
  1067 // ---------------------------------------------------------------------------
       
  1068 //
       
  1069 void 
       
  1070 CCamAppController::SetTargetImageMode( const TCamImageCaptureMode& aNewMode )
       
  1071   {
       
  1072   PRINT2( _L("Camera =><= CCamAppController::SetTargetImageMode [%s] -> [%s]"), 
       
  1073           KCamImageModeNames[iInfo.iTargetImageMode],
       
  1074           KCamImageModeNames[aNewMode              ] );
       
  1075 
       
  1076   iInfo.iTargetImageMode = aNewMode;
       
  1077   }
       
  1078 
       
  1079 
       
  1080 // ---------------------------------------------------------------------------
       
  1081 //
       
  1082 // ---------------------------------------------------------------------------
       
  1083 //
       
  1084 void CCamAppController::SetOperation( TCamCaptureOperation aNewOperation, 
       
  1085                                       TInt                 aError /*= KErrNone*/ )
       
  1086   {
       
  1087   PRINT2( _L("Camera => CCamAppController::SetOperation: [%s] -> [%s]"), 
       
  1088           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1089           KCamCaptureOperationNames[aNewOperation   ] );
       
  1090     PERF_OPERATION_STATE_CHANGE( aNewOperation ); 
       
  1091     
       
  1092     if( iInfo.iOperation != aNewOperation 
       
  1093      || aError           != KErrNone ) 
       
  1094       {      
       
  1095       iInfo.iOperation = aNewOperation;
       
  1096       NotifyControllerObservers( ECamEventOperationStateChanged, aError );
       
  1097       if( aNewOperation == ECamStandby )
       
  1098           {
       
  1099           ClearSequenceBusyFlag( &iBusyFlags );
       
  1100           TCamControllerInfo& info = const_cast<TCamControllerInfo&>( iCameraController->ControllerInfo() );
       
  1101           ClearFlags( info.iBusy , ECamBusySequence );
       
  1102           }
       
  1103       }
       
  1104 
       
  1105   PRINT( _L("Camera <= CCamAppController::SetOperation") );
       
  1106   }
       
  1107 
       
  1108 
       
  1109 
       
  1110 // ---------------------------------------------------------------------------
       
  1111 // CCamAppController::ImagesRemaining
       
  1112 // Return the number of images that can still be saved
       
  1113 // ---------------------------------------------------------------------------
       
  1114 //
       
  1115 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1116                                          TBool            aBurstActive )
       
  1117   {
       
  1118   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1119         ( iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoSize ) ); 
       
  1120 
       
  1121   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1122   }
       
  1123 
       
  1124 // ---------------------------------------------------------------------------
       
  1125 // CCamAppController::ImagesRemaining
       
  1126 // Return the number of images that can still be saved
       
  1127 // ---------------------------------------------------------------------------
       
  1128 //
       
  1129 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1130                                          TBool            aBurstActive, 
       
  1131                                          TInt             aQualityIndex )
       
  1132   {
       
  1133   TCamPhotoSizeId size = static_cast<TCamPhotoSizeId>
       
  1134         ( iSettingsModel->PhotoResolution( aQualityIndex ) );
       
  1135 
       
  1136   return ImagesRemaining( aStorage, aBurstActive, size );
       
  1137   }
       
  1138 
       
  1139 // ---------------------------------------------------------------------------
       
  1140 // CCamAppController::ImagesRemaining
       
  1141 // Return the number of images that can still be saved
       
  1142 // ---------------------------------------------------------------------------
       
  1143 //
       
  1144 TInt CCamAppController::ImagesRemaining( TCamMediaStorage aStorage,
       
  1145                                          TBool            aBurstActive, 
       
  1146                                          TCamPhotoSizeId  aSize        )
       
  1147   {
       
  1148   PRINT( _L("Camera => CCamAppController::ImagesRemaining" ))
       
  1149   if ( ECamMediaStorageCurrent == aStorage )
       
  1150     {
       
  1151     TCamMediaStorage store_unfiltered = static_cast<TCamMediaStorage>
       
  1152         ( IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );    
       
  1153    
       
  1154     // check to see if the MMC has been removed and we are waiting on a storage switch note
       
  1155     // before we start returning the values for phone memory
       
  1156     if( ECamMediaStorageCard == store_unfiltered
       
  1157      && static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->IsMMCRemovedNotePending() 
       
  1158       )
       
  1159       {
       
  1160       PRINT( _L("Camera <= CCamAppController::ImagesRemaining mmc removed - returning 0" ))
       
  1161       return 0;// UI Behaves as if MMC is still memory in use, thus we return zero images remaining as MMC is removed
       
  1162       }                       
       
  1163 
       
  1164     // use current storage location
       
  1165     aStorage = static_cast<TCamMediaStorage>
       
  1166         ( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ); 
       
  1167     }
       
  1168   else
       
  1169     {
       
  1170     // use specified location
       
  1171     }
       
  1172         
       
  1173 
       
  1174   TInt remaining     = 0;
       
  1175   TInt criticalLevel = 0;
       
  1176 
       
  1177   PRINT( _L("Camera <> Get critical memory level.." ))
       
  1178   TRAPD( err, criticalLevel = GetCriticalMemoryLevelL( aStorage ) );
       
  1179   if( !err )
       
  1180     remaining = iConfiguration->ImagesRemaining( aStorage, aSize, criticalLevel, aBurstActive  );
       
  1181   
       
  1182   // There is a factor in cenrep that defined a correction factor in percent.
       
  1183   // This feature makes possible to define separate file size estimates in 
       
  1184   // burst capture mode.  100 = 100%, 50 = half of single capture size etc.
       
  1185   if ( aBurstActive ) 
       
  1186      {
       
  1187      TInt corrFactor = iConfigManager->BurstFileSizeEstimateFactor();
       
  1188      PRINT1( _L("Camera <> CCamAppController::ImagesRemaining, factor: %d"), corrFactor )
       
  1189      remaining = TInt( remaining * corrFactor / 100 );
       
  1190      }
       
  1191 
       
  1192   PRINT1( _L("Camera <= CCamAppController::ImagesRemaining, return:%d"), remaining )
       
  1193   return remaining;
       
  1194   }
       
  1195 
       
  1196 // ---------------------------------------------------------------------------
       
  1197 // CCamAppController::RecordTimeElapsed
       
  1198 // Return the length of video that has been recorded
       
  1199 // ---------------------------------------------------------------------------
       
  1200 //
       
  1201 TTimeIntervalMicroSeconds CCamAppController::RecordTimeElapsed() const
       
  1202     {
       
  1203     return iVideoTimeElapsed;
       
  1204     }
       
  1205 
       
  1206 // ---------------------------------------------------------------------------
       
  1207 // CCamAppController::RecordTimeElapsed
       
  1208 // Return the length of video that has been recorded
       
  1209 // ---------------------------------------------------------------------------
       
  1210 //
       
  1211 void CCamAppController::RecordTimeElapsed(TTimeIntervalMicroSeconds aElapsed )
       
  1212     {
       
  1213     iVideoTimeElapsed=aElapsed;
       
  1214     }
       
  1215 
       
  1216 // ---------------------------------------------------------------------------
       
  1217 // CCamAppController::RecordTimeRemaining
       
  1218 // Return the length of video that can still be saved
       
  1219 // ---------------------------------------------------------------------------
       
  1220 //
       
  1221 TTimeIntervalMicroSeconds 
       
  1222 CCamAppController::RecordTimeRemaining() 
       
  1223     {
       
  1224     PRINT( _L("Camera => CCamAppController::RecordTimeRemaining" ));
       
  1225     TTimeIntervalMicroSeconds remain( 0 );
       
  1226   
       
  1227     // All the time we get this information from the CaeEngine which is thru camera controller.
       
  1228 
       
  1229     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1230     if( appUi->SettingsLaunchedFromCamera() || iDismountPending )
       
  1231         {
       
  1232         // In case settings plugin is being run or mmc dismount is pending
       
  1233         // due to usb activation, we calculate the remaining time here, 
       
  1234         // instead of repreparing the engine and getting it from there  
       
  1235         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1236         if( KErrNone != err )
       
  1237             {
       
  1238             iVideoTimeRemaining = 0;
       
  1239             }
       
  1240         }
       
  1241     else
       
  1242         {    
       
  1243         if( iInfo.iOperation == ECamCapturing    ||
       
  1244             iInfo.iOperation == ECamPausing      ||
       
  1245             iInfo.iOperation == ECamPaused       ||
       
  1246             iInfo.iOperation == ECamResuming     ||
       
  1247             iInfo.iOperation == ECamCompleting )
       
  1248             {    
       
  1249             iVideoTimeRemaining = RemainingVideoRecordingTime();  
       
  1250             }
       
  1251         else 
       
  1252             {
       
  1253             PRINT( _L("Camera <> CCamAppController::RecordTimeRemaining - video mode not yet initialized" ));
       
  1254             TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  1255             if( KErrNone != err )
       
  1256                 {
       
  1257                 iVideoTimeRemaining = 0;
       
  1258                 }
       
  1259             }
       
  1260         }
       
  1261    if ( ECamControllerVideo == CurrentMode() &&
       
  1262             iInfo.iOperation == ECamNoOperation && 
       
  1263    	    ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) &&
       
  1264    	    appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) )
       
  1265         {
       
  1266         iVideoTimeRemaining =  0; 
       
  1267         }
       
  1268   
       
  1269     // if the storage location is MMC but the MMC is not accessible then
       
  1270     // return 0 time remaining
       
  1271     if ( appUi->IsMMCRemovedNotePending() )
       
  1272         {
       
  1273         // Return remaining time of zero, it will be reset when
       
  1274         // a card is reinserted or storage location is changed
       
  1275         PRINT( _L("Camera <> MMC note pending, return 0") );
       
  1276         }
       
  1277     else
       
  1278         {
       
  1279         // If the time we have is greater than the maximum allowed, return the
       
  1280         // maximum
       
  1281         TTimeIntervalMicroSeconds maxRecordingLength( static_cast<TInt64>(KMaxRecordingLength) );
       
  1282     
       
  1283         if ( iVideoTimeRemaining > maxRecordingLength )
       
  1284             {
       
  1285             remain = maxRecordingLength;
       
  1286             }
       
  1287         else
       
  1288             {
       
  1289             remain = iVideoTimeRemaining;
       
  1290             }
       
  1291         }
       
  1292 
       
  1293     PRINT1( _L("Camera <= CCamAppController::RecordTimeRemaining, %Ld" ), remain.Int64() );
       
  1294     return remain;
       
  1295     }
       
  1296 
       
  1297 // ---------------------------------------------------------------------------
       
  1298 // SetNoBurstCancel
       
  1299 //
       
  1300 //Set iNoBurstCancel flag which is used to prevent stopping burst
       
  1301 // when actual burst capture has started after focusing. Flag is
       
  1302 // used in CancelFocusAndCapture method.
       
  1303 // ---------------------------------------------------------------------------
       
  1304 //
       
  1305 void
       
  1306 CCamAppController::SetNoBurstCancel(TBool aValue )
       
  1307   {
       
  1308   PRINT1 ( _L("Camera =><= CCamAppController::SetNoBurstCancel, aValue=%d"),aValue );
       
  1309   	iNoBurstCancel=aValue;
       
  1310   }
       
  1311 
       
  1312 
       
  1313 // ---------------------------------------------------------------------------
       
  1314 // SoftStopBurstL
       
  1315 //
       
  1316 // Stop burst as soon as possible given the following constrains:
       
  1317 //   - if quick burst is ongoing, it's continued to the end, unless
       
  1318 //     aFastStop is true. Then the minimum of 2 images is allowed.
       
  1319 //     For "immediate" stop, StopSequenceCapture should be used.
       
  1320 //   - if press and hold burst is ongoing, stop after next image.
       
  1321 // ---------------------------------------------------------------------------
       
  1322 //
       
  1323 void
       
  1324 CCamAppController::SoftStopBurstL( TBool aFastStop /*=EFalse*/ )
       
  1325   {
       
  1326   PRINT ( _L("Camera => CCamAppController::SoftStopBurstL") );
       
  1327   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  1328 
       
  1329   // Still in short burst mode, if
       
  1330   // a) no burst timer at all (long burst not supported)
       
  1331   // b) burst timer still ticking
       
  1332   // c) in self-timer initiated burst, which is always short burst.
       
  1333   TBool shortBurst = ( !iBurstTimer 
       
  1334                     ||  iBurstTimer->IsActive() 
       
  1335                     ||  appUi->SelfTimerEnabled() );
       
  1336 
       
  1337   PRINT1( _L("Camera <> CCamAppController::SoftStopBurstL .. is short burst: %d"), shortBurst );
       
  1338 
       
  1339   StopBurstTimer();
       
  1340 
       
  1341   if( iSequenceCaptureInProgress )
       
  1342     {
       
  1343     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst ongoing") );
       
  1344     if( aFastStop || !shortBurst )
       
  1345       {
       
  1346       // Camera controller takes care of setting "high enough" limit.
       
  1347       // SetCaptureLimitL takes care of setting right count to 
       
  1348       // stop as early as possible.
       
  1349       SetCaptureLimitL( 0 );
       
  1350       }
       
  1351     }
       
  1352   else if( ECamFocusing != iInfo.iOperation &&
       
  1353        !iAutoFocusRequested )
       
  1354     {
       
  1355     PRINT ( _L("Camera <> CCamAppController::SoftStopBurstL .. burst NOT ongoing, just cancel pending..") );
       
  1356     iCaptureRequested = EFalse;
       
  1357     }
       
  1358   PRINT ( _L("Camera <= CCamAppController::SoftStopBurstL") );
       
  1359   }
       
  1360 
       
  1361 // ---------------------------------------------------------------------------
       
  1362 // StartBurstTimerL
       
  1363 // ---------------------------------------------------------------------------
       
  1364 //
       
  1365 void
       
  1366 CCamAppController::StartBurstTimerL()
       
  1367   {
       
  1368   PRINT ( _L("Camera => CCamAppController::StartBurstTimerL") );
       
  1369   if( iBurstTimer )
       
  1370     {
       
  1371     StopBurstTimer();
       
  1372     }
       
  1373   else
       
  1374     {
       
  1375     TInt timeout( 0 );
       
  1376     User::LeaveIfError( CamUtility::GetPsiInt( ECamPsiLongCaptureKeyPressInterval, timeout ) );
       
  1377 
       
  1378     PRINT1( _L("Camera <> CCamAppController::StartBurstTimerL .. Creating timer with timeout value of [%d ms]"), timeout );
       
  1379 
       
  1380     // Multiply timeout by 1000 to get microseconds
       
  1381     TCallBack cb( CCamAppController::ShortBurstTimeout, this );
       
  1382     iBurstTimer = CCamTimer::NewL( timeout*1000, cb );
       
  1383     }
       
  1384 
       
  1385   PRINT ( _L("Camera <> CCamAppController::StartBurstTimerL .. Starting timer..") );
       
  1386   iBurstTimer->StartTimer();
       
  1387 
       
  1388   PRINT ( _L("Camera <= CCamAppController::StartBurstTimerL") );
       
  1389   }
       
  1390 
       
  1391 // ---------------------------------------------------------------------------
       
  1392 // StopBurstTimer
       
  1393 // ---------------------------------------------------------------------------
       
  1394 //
       
  1395 void
       
  1396 CCamAppController::StopBurstTimer()
       
  1397   {
       
  1398   PRINT( _L("Camera => CCamAppController::StopBurstTimer") );
       
  1399   if( iBurstTimer )
       
  1400     {
       
  1401     iBurstTimer->Cancel();
       
  1402     }
       
  1403   PRINT( _L("Camera <= CCamAppController::StopBurstTimer") );
       
  1404   }
       
  1405 
       
  1406 // ---------------------------------------------------------------------------
       
  1407 // ShortBurstTimeout
       
  1408 // ---------------------------------------------------------------------------
       
  1409 //
       
  1410 TInt 
       
  1411 CCamAppController::ShortBurstTimeout( TAny* aController )
       
  1412   {
       
  1413   PRINT( _L("Camera => CCamAppController::ShortBurstTimeout") );  
       
  1414 
       
  1415   CCamAppController* self = static_cast<CCamAppController*>( aController );
       
  1416   TRAP_IGNORE( self->DoShortBurstTimeoutL() );
       
  1417   
       
  1418   PRINT( _L("Camera <= CCamAppController::ShortBurstTimeout") );
       
  1419   return KErrNone; // no more callbacks
       
  1420   }
       
  1421 
       
  1422 
       
  1423 // ---------------------------------------------------------------------------
       
  1424 // DoShortBurstTimeoutL
       
  1425 // ---------------------------------------------------------------------------
       
  1426 //
       
  1427 void
       
  1428 CCamAppController::DoShortBurstTimeoutL()
       
  1429   {
       
  1430   PRINT( _L("Camera => CCamAppController::DoShortBurstTimeoutL") );
       
  1431   PRINT2( _L("Camera <> CCamAppController::DoShortBurstTimeoutL iInfo.iImageMode: %d, iSequenceCaptureInProgress: %d"), iInfo.iImageMode, iSequenceCaptureInProgress );
       
  1432   if( ECamImageCaptureBurst == iInfo.iImageMode 
       
  1433    && iSequenceCaptureInProgress )
       
  1434     {
       
  1435     TInt longBurstLimit( 0 );
       
  1436     CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, longBurstLimit );
       
  1437 
       
  1438     PRINT1( _L("Camera <> CCamAppController::DoShortBurstTimeoutL .. product long burst limit: %d"), longBurstLimit );  
       
  1439 
       
  1440     SetCaptureLimitL( longBurstLimit );
       
  1441     }
       
  1442 
       
  1443   PRINT( _L("Camera <= CCamAppController::DoShortBurstTimeoutL") );
       
  1444   }
       
  1445 
       
  1446 // ---------------------------------------------------------------------------
       
  1447 // Actual capture limit value.
       
  1448 // ---------------------------------------------------------------------------
       
  1449 //
       
  1450 TInt
       
  1451 CCamAppController::CaptureLimit() const
       
  1452   {
       
  1453   TInt limit( 1 );
       
  1454 
       
  1455   if( iCameraController && ECamImageCaptureBurst == iInfo.iImageMode )
       
  1456     {
       
  1457     limit = iCameraController->ControllerInfo().iCaptureLimit;
       
  1458     }
       
  1459 
       
  1460   return limit;
       
  1461   }
       
  1462 
       
  1463 // ---------------------------------------------------------------------------
       
  1464 // CaptureLimitSetting
       
  1465 //
       
  1466 // Stored for Setting Provider to give to Camera Controller.
       
  1467 // ---------------------------------------------------------------------------
       
  1468 //
       
  1469 TInt
       
  1470 CCamAppController::CaptureLimitSetting() const
       
  1471   {
       
  1472   TInt limit( 1 );
       
  1473 
       
  1474   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1475     {
       
  1476     limit = iRequestedCaptureCount;
       
  1477     }
       
  1478 
       
  1479   return limit;  
       
  1480   }
       
  1481 
       
  1482 // ---------------------------------------------------------------------------
       
  1483 // SetCaptureLimitL
       
  1484 // ---------------------------------------------------------------------------
       
  1485 //
       
  1486 void 
       
  1487 CCamAppController::SetCaptureLimitL( TInt aLimit )
       
  1488   {
       
  1489   PRINT1( _L("Camera => CCamAppController::SetCaptureLimitL .. requested limit: %d"), aLimit );
       
  1490 
       
  1491   if( ECamImageCaptureBurst == iInfo.iTargetImageMode )
       
  1492     {
       
  1493     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. burst mode active") );
       
  1494     // We give the total amount of images during burst, not the remaining ones.
       
  1495     // Need to subtract captures that have already been taken,
       
  1496     // before comparing to the disk limit.
       
  1497     if( iSequenceCaptureInProgress )
       
  1498       {
       
  1499       //TInt captured  = iCameraController->ControllerInfo().iCaptureCount;
       
  1500       TInt captured  = iCameraController->ControllerInfo().iSnapshotCount;
       
  1501       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. captured already: %d"), captured );
       
  1502 
       
  1503       if( aLimit > captured )
       
  1504         {
       
  1505         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. some more captures requested..") );
       
  1506 
       
  1507         // Check which is more restrictive - disk space or given limit.
       
  1508         TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1509         TInt remaining = Min( aLimit - captured, diskLimit );
       
  1510 
       
  1511         PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1512 
       
  1513         iRequestedCaptureCount = Max( KMinBurstCount, captured + remaining );
       
  1514         if ( diskLimit - KMinBurstCount < iRequestedCaptureCount ) 
       
  1515             {
       
  1516             // Estimated file size is not worst case estimate and long burst 
       
  1517             // sequence accumulates error, thus critical disk space limit may
       
  1518             // be reached. Requested capture count is decreased here if needed. 
       
  1519             iRequestedCaptureCount -= 
       
  1520                         (iRequestedCaptureCount+KMinBurstCount)/KBurstEstimate;
       
  1521             PRINT( _L("Camera <> CCamAppController::SetCaptureLimitL .. Near to critical level, adjust iRequestedCaptureCount"));
       
  1522             }
       
  1523         }
       
  1524       else
       
  1525         {
       
  1526         PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. capturing should be stopped as soon as possible..") );
       
  1527         // Stop as fast as possible requested.
       
  1528         // Still need to request minimum of 2.
       
  1529         iRequestedCaptureCount = Max( KMinBurstCount, captured + 1 );
       
  1530         }
       
  1531       }
       
  1532     // Not capturing - adjust freely
       
  1533     else
       
  1534       {
       
  1535       TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, ETrue );
       
  1536       PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1537 
       
  1538       iRequestedCaptureCount = Max( KMinBurstCount, Min( aLimit, diskLimit ) );
       
  1539       }
       
  1540 
       
  1541     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1542 
       
  1543     // In burst mode camera needs to be updated with the limit.
       
  1544     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  1545     }
       
  1546   else
       
  1547     {
       
  1548     PRINT ( _L("Camera <> CCamAppController::SetCaptureLimitL .. single / timelapse mode active") );
       
  1549     TInt diskLimit = ImagesRemaining( ECamMediaStorageCurrent, EFalse );
       
  1550     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. disk limit: %d"), diskLimit );
       
  1551 
       
  1552     iRequestedCaptureCount = Min( aLimit, diskLimit );
       
  1553 
       
  1554     PRINT1( _L("Camera <> CCamAppController::SetCaptureLimitL .. setting the request limit to: %d"), iRequestedCaptureCount );
       
  1555     }
       
  1556   PRINT ( _L("Camera <= CCamAppController::SetCaptureLimitL") );
       
  1557   }
       
  1558 // ---------------------------------------------------------------------------
       
  1559 // CCamAppController::SetTimeLapseInterval
       
  1560 // Updates the interval used in next TimeLapse capture
       
  1561 // ---------------------------------------------------------------------------
       
  1562 //
       
  1563 void CCamAppController::SetTimeLapseInterval( TTimeIntervalMicroSeconds aInterval )
       
  1564   {
       
  1565   iTimeLapseInterval = aInterval;
       
  1566   }
       
  1567 
       
  1568 // ---------------------------------------------------------------------------
       
  1569 // CCamAppController::TimeLapseInterval
       
  1570 // Returns the interval used in next TimeLapse capture
       
  1571 // ---------------------------------------------------------------------------
       
  1572 //   
       
  1573 TTimeIntervalMicroSeconds CCamAppController::TimeLapseInterval()
       
  1574   {    
       
  1575   return iTimeLapseInterval;
       
  1576   } 
       
  1577     
       
  1578 // ---------------------------------------------------------------------------
       
  1579 // CCamAppController::TimeLapseCountdown
       
  1580 // Returns the remaining time lapse interval until the next capture
       
  1581 // ---------------------------------------------------------------------------
       
  1582 // 
       
  1583 TTimeIntervalMicroSeconds CCamAppController::TimeLapseCountdown()
       
  1584   {
       
  1585   TInt64 remainingTime( 0 );    // Assume uninitialised start time
       
  1586   
       
  1587   // If the start time is uninitialised then the first capture is about to be initiated
       
  1588   if ( iTimeLapseStartTime == remainingTime )
       
  1589     {
       
  1590     return remainingTime;
       
  1591     }
       
  1592   // Otherwise, work out how much time is left before the next capture
       
  1593   TTime now;
       
  1594   now.HomeTime();
       
  1595   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  1596   remainingTime = Max ( remainingTime, iTimeLapseInterval.Int64() - elapsedTime.Int64() );   
       
  1597   return remainingTime;            
       
  1598   } 
       
  1599 
       
  1600 // ---------------------------------------------------------------------------
       
  1601 // CCamAppController::StartAutoFocus
       
  1602 // Start the autofocus procedure
       
  1603 // ---------------------------------------------------------------------------
       
  1604 //
       
  1605 void CCamAppController::StartAutoFocus()
       
  1606     {
       
  1607     PRINT (_L("Camera => CCamAppController::StartAutoFocus"));
       
  1608     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  1609     PRINT1(_L("Camera <> CCamAppController::StartAutoFocus - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  1610 
       
  1611     if( iConfigManager 
       
  1612      && iConfigManager->IsAutoFocusSupported()
       
  1613      && IsViewFinding() 
       
  1614      && !iAFCancelInProgress 
       
  1615      && ECamNoOperation == iInfo.iOperation )
       
  1616         {
       
  1617 
       
  1618         PRINT(_L("Camera <> Calling TryAutoFocus" ) );  
       
  1619         TryAutoFocus();        
       
  1620         }
       
  1621     PRINT(_L("Camera <= CCamAppController::StartAutoFocus"));
       
  1622     }
       
  1623 
       
  1624 // ---------------------------------------------------------------------------
       
  1625 // CCamAppController::Capture
       
  1626 // Begin the capture procedure
       
  1627 // ---------------------------------------------------------------------------
       
  1628 //
       
  1629 void CCamAppController::Capture()
       
  1630   {
       
  1631   PRINT2( _L("Camera => CCamAppController::Capture(), operation[%s], iSaving:%d"), 
       
  1632           KCamCaptureOperationNames[iInfo.iOperation], 
       
  1633           iSaving );    
       
  1634 
       
  1635   // If the camera orientation changed during capture and not in burst mode, 
       
  1636   // set the new orientation
       
  1637   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  1638        && iOrientationChangeOccured
       
  1639        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  1640     {
       
  1641     iOrientationChangeOccured = EFalse;
       
  1642     TRAP_IGNORE( SetImageOrientationL() );
       
  1643     }
       
  1644     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && !iAccSensorListening )
       
  1645         {
       
  1646         // Delayed sensor initialization has not yet happened, but shutter key has been pressed.
       
  1647         // Force initialization now, causing an addition to shutter lag - this is a very
       
  1648         // rare case, as there should always be enough idle time to run the delayed
       
  1649         // initialization.  
       
  1650         TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  1651         }
       
  1652 
       
  1653   PERF_EVENT_END_L1( EPerfEventKeyToCapture );   
       
  1654 
       
  1655   // Set to EFalse for burst 
       
  1656   iAllSnapshotsReceived = EFalse;
       
  1657   
       
  1658   if ( ECamFocusing == iInfo.iOperation ||
       
  1659        iAFCancelInProgress ||
       
  1660        iAutoFocusRequested || IsAfNeeded() )
       
  1661     {
       
  1662     PRINT( _L("Camera <> Focusing going on, cannot start capture - setting iCaptureRequested" ) );
       
  1663     iCaptureRequested = ETrue;
       
  1664     if( !IsAfNeeded() )
       
  1665         {
       
  1666         CancelAFNow();
       
  1667         }        
       
  1668     } 
       
  1669   // -------------------------------------------------------
       
  1670   //Quick pressed capture key after backing to precapture from postcapture in burst mode
       
  1671   //Quick pressed capture key during cancelling autofocus(eg. backing to precapture from setting view ) 
       
  1672   else if ( ECamNoOperation == iInfo.iOperation
       
  1673     && ( ( ECamImageCaptureTimeLapse == iInfo.iImageMode ) 
       
  1674       || ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  1675       || ( ECamImageCaptureSingle == iInfo.iImageMode ) )      
       
  1676     && iAFCancelInProgress )
       
  1677     {
       
  1678     PRINT(_L("Camera <> Cancelling auto focus going on, cannot start capture - setting iCaptureRequested")); 
       
  1679     // delay the start of capture until cancelling autofocus has finished
       
  1680     iCaptureRequested = ETrue;
       
  1681     }    
       
  1682   // -------------------------------------------------------
       
  1683   // Quick pressed after capture, during image processing 
       
  1684   else if ( ECamCompleting         == iInfo.iOperation
       
  1685     && ECamImageCaptureSingle == iInfo.iImageMode )
       
  1686     {
       
  1687     PRINT(_L("Camera <> operation state is capture completing setting iCaptureRequested")); 
       
  1688      // delay the start of capture until current capture has finished
       
  1689     iCaptureRequested = ETrue;
       
  1690     }
       
  1691   // -------------------------------------------------------
       
  1692   // Ready for new shot
       
  1693   else if( ECamNoOperation == iInfo.iOperation 
       
  1694         || ECamFocused     == iInfo.iOperation
       
  1695         || ECamFocusFailed == iInfo.iOperation )
       
  1696     {
       
  1697     PRINT(_L("Camera <> operation state is no operation")); 
       
  1698     
       
  1699     // Update current capture mode
       
  1700 //    iInfo.iImageMode = CurrentImageModeSetup();
       
  1701 
       
  1702     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  1703         {
       
  1704         // If AF sound hasn't finished playing yet, stop it now
       
  1705         // to make sure it does not block capture sound playing.
       
  1706         iSoundPlayer->CancelPlaying( ECamAutoFocusComplete );
       
  1707         }
       
  1708     
       
  1709 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1710     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  1711       {       
       
  1712       // Do not log the single image start events in burst mode, as the end
       
  1713       // events would arrive for all images at once after all images have been taken
       
  1714       PERF_EVENT_START_L1( EPerfEventShotToSnapshot );  
       
  1715       PERF_EVENT_START_L1( EPerfEventShotToStillImageReady );  
       
  1716       PERF_EVENT_START_L1( EPerfEventShotToSave );
       
  1717       }
       
  1718     else
       
  1719       {
       
  1720       PERF_EVENT_START_L1( EPerfEventSequenceCapture ); 
       
  1721       }
       
  1722 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  1723 
       
  1724     if( ECamImageCaptureTimeLapse == iInfo.iImageMode &&
       
  1725         !iSequenceCaptureInProgress )
       
  1726       {
       
  1727       // First image of timelapse, reset capture count  
       
  1728       iTimeLapseCaptureCount = 0;
       
  1729       }  
       
  1730 
       
  1731     if( iInfo.iImageMode == ECamImageCaptureNone )  
       
  1732         {
       
  1733         PRINT(_L("Camera <= CCamAppController::Capture() - request ignored")); 
       
  1734         return;
       
  1735         }
       
  1736 
       
  1737     // iCaptureRequested is reset in DoCaptureL
       
  1738     TBool capture = EFalse;
       
  1739     TInt err = KErrNone;
       
  1740     iFilenameReserved = EFalse;
       
  1741     TRAP( err, capture = DoCaptureL() );
       
  1742     if ( KErrNone != err )
       
  1743        {
       
  1744        // Sequence capture is not in progress as capture failed 
       
  1745        iSequenceCaptureInProgress = EFalse; 
       
  1746        }
       
  1747 
       
  1748     PRINT1( _L("Camera <> Tried to start capture, status:%d"), capture ); 
       
  1749     }
       
  1750   // -------------------------------------------------------
       
  1751   // Not ready for a capture
       
  1752   else
       
  1753     {
       
  1754     // request ignored
       
  1755     }  
       
  1756   // -------------------------------------------------------
       
  1757   PRINT(_L("Camera <= CCamAppController::Capture()"));    
       
  1758   }
       
  1759 
       
  1760 
       
  1761 // ---------------------------------------------------------------------------
       
  1762 // CCamAppController::StopSequenceCaptureL
       
  1763 // Stop and complete the burst capture operation
       
  1764 // ---------------------------------------------------------------------------
       
  1765 //
       
  1766 void CCamAppController::StopSequenceCaptureL()
       
  1767   {
       
  1768   PRINT( _L("Camera => CCamAppController::StopSequenceCaptureL()") );
       
  1769 
       
  1770   iSequenceCaptureInProgress = EFalse;
       
  1771   iNoBurstCancel = EFalse;
       
  1772 
       
  1773   // Re-enable screen saver
       
  1774   EnableScreenSaver( ETrue );
       
  1775 
       
  1776   TCamImageCaptureMode captureModeSetup = CurrentImageModeSetup();
       
  1777   // Test that this method was not called in single capture mode
       
  1778   __ASSERT_DEBUG( captureModeSetup != ECamImageCaptureSingle, CamPanic( ECamPanicInvalidState ) );
       
  1779 
       
  1780   // If a burst sequence is currently active or has been requested
       
  1781   if ( iInfo.iImageMode == ECamImageCaptureBurst 
       
  1782     || ( captureModeSetup == ECamImageCaptureBurst && iCaptureRequested ) )
       
  1783     {
       
  1784     IssueDirectRequestL( ECamRequestImageCancel );
       
  1785     if ( iInfo.iOperation != ECamCapturing )
       
  1786       {
       
  1787       CompleteBurstOperation();
       
  1788       }
       
  1789     
       
  1790     }
       
  1791   // If a timelapse sequence is currently active or has been requested        
       
  1792   else if ( iInfo.iImageMode == ECamImageCaptureTimeLapse ||
       
  1793             ( captureModeSetup == ECamImageCaptureTimeLapse &&
       
  1794               iCaptureRequested ) )
       
  1795     {
       
  1796     if ( TimeLapseSupported() )
       
  1797       {
       
  1798       if ( iTimeLapseTimer )
       
  1799         {
       
  1800         iTimeLapseTimer->Cancel();
       
  1801         delete iTimeLapseTimer;
       
  1802         iTimeLapseTimer = NULL;
       
  1803         }
       
  1804 
       
  1805       // The current state is in between captures the next one has now been cancelled
       
  1806       // so just ensure that the view switch occurs           
       
  1807       // if ( iInfo.iOperation != ECamCapturing && !iCaptureRequested )
       
  1808       if ( iInfo.iOperation != ECamCapturing )
       
  1809         {
       
  1810         CompleteTimeLapseOperation();
       
  1811         } 
       
  1812       // Either the first capture is queued or a capture is still in stages of
       
  1813       // completion. Any future capture has been cancelled so all that remains is to ensure the
       
  1814       // completion code is run when the capture finally completes    
       
  1815       else
       
  1816         {
       
  1817         iCompleteTimeLapsePending = ETrue;
       
  1818         }
       
  1819       }
       
  1820     }
       
  1821   else // Otherwise there is no active or pending burst
       
  1822     {
       
  1823     // Do nothing
       
  1824     }
       
  1825 
       
  1826   PRINT( _L("Camera <= CCamAppController::StopSequenceCaptureL()") );
       
  1827   }
       
  1828 
       
  1829 
       
  1830 // ---------------------------------------------------------------------------
       
  1831 // CCamAppController::CapturePending
       
  1832 // Whether or not a capture is pending
       
  1833 // ---------------------------------------------------------------------------
       
  1834 //
       
  1835 TBool CCamAppController::CapturePending() const
       
  1836     {
       
  1837     // iOperation can be ECamFocusing but a 
       
  1838     // request to start still capture has been made and is waiting for the
       
  1839     // focus operation to complete
       
  1840     return iCaptureRequested;
       
  1841     }
       
  1842 
       
  1843 // ---------------------------------------------------------------------------
       
  1844 // CCamAppController::VideoRecordPending
       
  1845 // Whether or not video recording is pending
       
  1846 // ---------------------------------------------------------------------------
       
  1847 //
       
  1848 TBool CCamAppController::VideoRecordPending() const
       
  1849     {
       
  1850     // iOperation can be ECamFocusing but a 
       
  1851     // request to start video has been made and is waiting for the
       
  1852     // focus operation to complete
       
  1853     return iVideoRequested;
       
  1854     }
       
  1855 
       
  1856 // ---------------------------------------------------------------------------
       
  1857 // CCamAppController::SequenceCaptureInProgress
       
  1858 // Whether or not sequence capture is active
       
  1859 // ---------------------------------------------------------------------------
       
  1860 //
       
  1861 TBool CCamAppController::SequenceCaptureInProgress() const
       
  1862   {
       
  1863   return iSequenceCaptureInProgress;  
       
  1864   }
       
  1865 
       
  1866 // -----------------------------------------------------------------------------
       
  1867 // CCamAppController::StartVideoRecordingL
       
  1868 // Begin the video recording procedure
       
  1869 // -----------------------------------------------------------------------------
       
  1870 //
       
  1871 void CCamAppController::StartVideoRecordingL()
       
  1872   {
       
  1873   PRINT( _L("Camera => CCamAppController::StartVideoRecordingL") );    
       
  1874   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  1875   if ( ECamControllerVideo == iInfo.iMode )
       
  1876       {
       
  1877       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  1878       if ( IntegerSettingValue( ECamSettingItemStopRecordingInHdmiMode) &&
       
  1879                IsHdmiCableConnected() )
       
  1880           {
       
  1881           appUi->HandleHdmiEventL( ECamHdmiCableConnectedBeforeRecording );
       
  1882           return;
       
  1883           }
       
  1884       if ( !iVideoRequested
       
  1885               &&  ECamNoOperation == iInfo.iOperation )
       
  1886           {
       
  1887           iVideoRequested = ETrue;     
       
  1888       if( !iSilentProfile || iShutterSndAlwaysOn  )
       
  1889           {
       
  1890           // Load (and play) the start video sound	
       
  1891           PlaySound( ECamVideoStartSoundId , ETrue );  
       
  1892           }   
       
  1893   
       
  1894           // initialise the array accessing values
       
  1895           iArrayUsageCount   = KVideoArrayUsers;
       
  1896           iCurrentImageIndex = 0;
       
  1897   
       
  1898           if ( ECamMediaStorageCard == 
       
  1899                    IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  1900               {
       
  1901               TRAPD( err, ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1902               if ( err )
       
  1903                   {
       
  1904                   PRINT( _L("Camera <> invalid MMC") );        
       
  1905                   NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  1906   
       
  1907                   // If we have got here, we can't access MMC. Switch to phone memory
       
  1908                   TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  1909                                                          //this actually uses the internal mass memory
       
  1910                   // Ignore for now, let fail when recording.
       
  1911                   TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone, ETrue ) );
       
  1912                   }
       
  1913               }
       
  1914           else
       
  1915               {
       
  1916               // Ignore for now, let fail when recording.
       
  1917               TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, ECamImageCaptureNone ) );
       
  1918               }
       
  1919 
       
  1920           if( iSilentProfile && !iShutterSndAlwaysOn )
       
  1921               {
       
  1922               PlaySoundComplete();
       
  1923               }
       
  1924           // Remember where are we recording
       
  1925           iInitialVideoStorageLocation = static_cast<TCamMediaStorage>( 
       
  1926                IntegerSettingValue( ECamSettingItemVideoMediaStorage ) );
       
  1927           }
       
  1928       else
       
  1929           {
       
  1930           // Video already requested or other operation busy.
       
  1931           // Request ignored.
       
  1932           }
       
  1933       }
       
  1934   // Note: The code to actually START video recording has been moved
       
  1935   // to the PlaySoundComplete function so as to only start when
       
  1936   // sound playback has completed.
       
  1937   }
       
  1938 
       
  1939 // ---------------------------------------------------------------------------
       
  1940 // CCamAppController::StopVideoRecording
       
  1941 // End the video recording procedure
       
  1942 // ---------------------------------------------------------------------------
       
  1943 //
       
  1944 void 
       
  1945 CCamAppController::StopVideoRecording()
       
  1946   {
       
  1947   PRINT( _L("Camera => CCamAppController::StopVideoRecording") );
       
  1948   // if a video capture operation is pending
       
  1949   if ( iVideoRequested )
       
  1950       {
       
  1951       iVideoRequested = EFalse;
       
  1952       }
       
  1953   // otherwise, if a video recording operation is in progress or is paused
       
  1954   /*  else */
       
  1955   if ( ECamCapturing == CurrentVideoOperation() 
       
  1956          || ECamPaused    == CurrentVideoOperation() )
       
  1957     {
       
  1958     //  TRAPD( err, iAutoFocus->StopContinuousFocusL() );
       
  1959     //  iFocusLocked = EFalse;
       
  1960     // Keep track of the fact we are now in "saving" state
       
  1961     iSaving = ETrue;
       
  1962     TRAP_IGNORE( 
       
  1963       {
       
  1964       // IssueDirectRequestL( ECamRequestVfStop );
       
  1965       StopViewFinder(); 
       
  1966       IssueRequestL( ECamRequestVideoStop ); // Rest handled when event comes.
       
  1967       });
       
  1968     
       
  1969     StartIdleTimer();
       
  1970     }
       
  1971   else
       
  1972     {
       
  1973     // otherwise there is no current recording operation
       
  1974     }
       
  1975   PRINT( _L("Camera <= CCamAppController::StopVideoRecording") );
       
  1976   }
       
  1977 
       
  1978 // ---------------------------------------------------------------------------
       
  1979 // CCamAppController::StopVideoRecordingAsync
       
  1980 // End the video recording procedure asynchronously
       
  1981 // ---------------------------------------------------------------------------
       
  1982 //
       
  1983 void 
       
  1984 CCamAppController::StopVideoRecordingAsync()
       
  1985   {
       
  1986   PRINT( _L("Camera => CCamAppController::StopVideoRecordingAsync") );
       
  1987   
       
  1988   // Change CAE and MMF mode to async
       
  1989   TRAP_IGNORE( IssueRequestL( ECamRequestSetAsyncVideoStopMode ) ); 
       
  1990   StopVideoRecording();  // Call normal stop, mode is set to sync in call-backs
       
  1991 
       
  1992   PRINT( _L("Camera <= CCamAppController::StopVideoRecordingAsync") );
       
  1993   }
       
  1994 
       
  1995 // ---------------------------------------------------------------------------
       
  1996 // HandleVideoAsyncStopEvent
       
  1997 // ---------------------------------------------------------------------------
       
  1998 //
       
  1999 void
       
  2000 CCamAppController::HandleVideoAsyncStopEvent( TInt aStatus )
       
  2001   {
       
  2002   PRINT1( _L( "Camera => CCamAppController::HandleVideoAsyncStopEvent, status:%d" ), aStatus );
       
  2003   (void)aStatus; // remove compiler warning
       
  2004   
       
  2005   // We DO NOT play the stop sound when recording stopped due to
       
  2006   // an incoming call.  UI Spec 1.0, 4.4.1.
       
  2007   if ( !iInCallOrRinging 
       
  2008     && !iVideoStoppedForPhoneApp )
       
  2009     {
       
  2010     PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  2011     }
       
  2012 
       
  2013   // Recording completed, so we can re-enable key sounds
       
  2014   iSoundPlayer->EnableAllKeySounds();
       
  2015     
       
  2016   PRINT( _L( "Camera <= CCamAppController::HandleVideoAsyncStopEvent" ) );
       
  2017   }
       
  2018 
       
  2019 // ---------------------------------------------------------------------------
       
  2020 // HandleVideoStopEvent
       
  2021 // ---------------------------------------------------------------------------
       
  2022 //
       
  2023 void
       
  2024 CCamAppController::HandleVideoStopEvent( TInt aStatus )
       
  2025   {
       
  2026   PRINT1( _L( "Camera => CCamAppController::HandleVideoStopEvent, status:%d" ), aStatus );
       
  2027     
       
  2028   PERF_EVENT_END_L1( EPerfEventVideoStopToSave );        
       
  2029         
       
  2030   if ( KErrDiskFull   == aStatus 
       
  2031     || KErrCompletion == aStatus)
       
  2032     {
       
  2033     // if recording ends due to disk full condition or end of
       
  2034     // specified recording period do not propogate the error
       
  2035     aStatus = KErrNone;
       
  2036     }
       
  2037     // Play sound here if async mode is not supported
       
  2038     // If it is then next playing is copyed to HandleVideoAsyncStopEvent
       
  2039     if ( iCameraController && !iCameraController->AsyncVideoStopModeSupported() )
       
  2040         {
       
  2041         // We DO NOT play the stop sound when recording stopped due to
       
  2042         // an incoming call.  UI Spec 1.0, 4.4.1.
       
  2043         if ( !iInCallOrRinging 
       
  2044             && !iVideoStoppedForPhoneApp )
       
  2045             {
       
  2046             PlaySound( ECamVideoStopSoundId, EFalse ); // No callback
       
  2047             }
       
  2048 
       
  2049         // Recording completed, so we can re-enable key sounds
       
  2050         iSoundPlayer->EnableAllKeySounds();
       
  2051         }
       
  2052   // Keep track of the fact we are now leaving saving state
       
  2053   iSaving = EFalse;
       
  2054   
       
  2055   // try closing video record to free up resources
       
  2056   // Test - <eo> commented out, no such direct request supported
       
  2057   // TRAP_IGNORE( IssueDirectRequestL( ECamRequestVideoRelease ) );
       
  2058   
       
  2059   // if video post capture is off then force re-prepare so
       
  2060   // that remaining record time is updated
       
  2061   // REMOVED
       
  2062 
       
  2063   // if using direct viewfinding pause viewfinder
       
  2064   // REMOVED
       
  2065 
       
  2066   // report to LifeBlog
       
  2067   RProperty::Set( KPSUidCamcorderNotifier, KCamLatestFilePath, iSuggestedVideoPath ); 
       
  2068   // Add to album if this is enabled for videos
       
  2069   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  2070               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));       
       
  2071   if ( iSettingsModel->IntegerSettingValue
       
  2072                      ( ECamSettingItemVideoStoreInAlbum ) == ECamSettYes )
       
  2073     {
       
  2074     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, ETrue, defaultAlbumId );
       
  2075     }
       
  2076   else // Harvest the file but dont add to the default album
       
  2077     {
       
  2078     iImageSaveActive->AddToAlbum( iSuggestedVideoPath, EFalse, defaultAlbumId );
       
  2079     }
       
  2080 
       
  2081   //create thumbnail
       
  2082   if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  2083       {
       
  2084       TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  2085       }
       
  2086   NotifyControllerObservers( ECamEventRecordComplete,   aStatus );
       
  2087   SetOperation( ECamNoOperation );
       
  2088   PRINT( _L( "Camera <> calling HandleCaptureCompletion.." ) )        
       
  2089   HandleCaptureCompletion();
       
  2090   NotifyControllerObservers( ECamEventMediaFileChanged, aStatus );
       
  2091   PRINT( _L( "Camera <= CCamAppController::HandleVideoStopEvent" ) );
       
  2092   }
       
  2093 
       
  2094     
       
  2095 // ---------------------------------------------------------------------------
       
  2096 // CCamAppController::SetVideoStoppedForPhoneApp
       
  2097 // Store the cause of the video stopping
       
  2098 // ---------------------------------------------------------------------------
       
  2099 //
       
  2100 void 
       
  2101 CCamAppController::SetVideoStoppedForPhoneApp( TBool aIsPhoneApp )
       
  2102   {
       
  2103   iVideoStoppedForPhoneApp = aIsPhoneApp;
       
  2104   }
       
  2105     
       
  2106 
       
  2107 // ---------------------------------------------------------------------------
       
  2108 // CCamAppController::PauseVideoRecording
       
  2109 // Pause the video recording procedure
       
  2110 // ---------------------------------------------------------------------------
       
  2111 //
       
  2112 void CCamAppController::PauseVideoRecording()
       
  2113     {
       
  2114     PRINT( _L("Camera => CCamAppController::PauseVideoRecording") );
       
  2115     if( ECamCapturing == CurrentVideoOperation() )
       
  2116         {
       
  2117         TRAPD( error, IssueRequestL( ECamRequestVideoPause ) );
       
  2118         if( KErrNone != error )
       
  2119             {
       
  2120             PRINT( _L("Camera <> PAUSING FAILED!!") );
       
  2121             }
       
  2122         else
       
  2123             {
       
  2124             // start video pause timeout
       
  2125             StartIdleTimer();
       
  2126             }
       
  2127         }  
       
  2128     PRINT( _L("Camera <= CCamAppController::PauseVideoRecording") );
       
  2129     }
       
  2130 
       
  2131 
       
  2132 // ---------------------------------------------------------------------------
       
  2133 // CCamAppController::ContinueVideoRecording
       
  2134 // Continue the video recording procedure
       
  2135 // ---------------------------------------------------------------------------
       
  2136 //
       
  2137 void CCamAppController::ContinueVideoRecording()
       
  2138   {
       
  2139   PRINT( _L("Camera => CCamAppController::ContinueVideoRecording") );
       
  2140   if ( ECamPaused == CurrentVideoOperation() )
       
  2141     {
       
  2142     SetOperation( ECamResuming );
       
  2143     // Restart video when sound played
       
  2144     PlaySound( ECamVideoResumeSoundId, ETrue );        
       
  2145     }
       
  2146   PRINT( _L("Camera <= CCamAppController::ContinueVideoRecording") );
       
  2147   }
       
  2148 
       
  2149 // ---------------------------------------------------------------------------
       
  2150 // CCamAppController::TryAFRequest
       
  2151 // issue AF request if there are no pending AF requests currently
       
  2152 // ---------------------------------------------------------------------------
       
  2153 //
       
  2154 TBool CCamAppController::TryAFRequest( TInt aAFRequest ) 
       
  2155   {
       
  2156   PRINT( _L( "Camera => TryAFRequest") );
       
  2157   PRINT3( _L( "iPendingAFRequest=%d aAFRequest=%d ,iCurrentAFRequest=%d"), iPendingAFRequest,
       
  2158     aAFRequest, iCurrentAFRequest );
       
  2159   switch( aAFRequest )
       
  2160     {    
       
  2161     case  ECamRequestCancelAutofocus:
       
  2162     case ECamRequestStartAutofocus:
       
  2163         {
       
  2164         if( iPendingAFRequest == 0 ||
       
  2165           ( !iAFCancelInProgress &&
       
  2166             iPendingAFRequest == ECamRequestCancelAutofocus &&
       
  2167             iCurrentAFRequest == ECamRequestCancelAutofocus ) )
       
  2168             {
       
  2169             if ( !( UiConfigManagerPtr()->IsContinuosAutofocusSupported()&& ECamControllerVideo == CurrentMode() ) ) 
       
  2170                 {
       
  2171                 iPendingAFRequest=aAFRequest;
       
  2172                 TRAPD( err, IssueDirectRequestL( TCamCameraRequestId(aAFRequest) ) );
       
  2173                 //TRAPD( err, iCameraController->DirectRequestL( aAFRequest ) );            
       
  2174                 if ( err != KErrNone )
       
  2175                     {
       
  2176                     // There is an error, we leave without focusing
       
  2177                     iPendingAFRequest=0;
       
  2178                     return EFalse; // Not doing any autofocus request.
       
  2179                     //This is only case where AFrequest cause EFalse to be returned.
       
  2180                     }
       
  2181                 }
       
  2182             } 
       
  2183         else
       
  2184             {
       
  2185             CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2186             if ( appUi->AlwaysDrawPreCaptureCourtesyUI()
       
  2187                 && !CurrentSceneHasForcedFocus() )
       
  2188                 {
       
  2189                 appUi->SetActivePaletteVisibility( EFalse );
       
  2190                 }
       
  2191             iPendingAFRequest=aAFRequest;
       
  2192             }
       
  2193         }
       
  2194         break;
       
  2195     default:
       
  2196         {
       
  2197         //Not type of autofocus request. Ignoring.
       
  2198         }
       
  2199         break;    
       
  2200     }
       
  2201   PRINT( _L( "Camera <= TryAFRequest") );
       
  2202   return ETrue;              
       
  2203   }
       
  2204 
       
  2205 // ---------------------------------------------------------------------------
       
  2206 // CCamAppController::CancelAFNow
       
  2207 // Cancel AutoFocus 
       
  2208 // ---------------------------------------------------------------------------
       
  2209 //
       
  2210 void CCamAppController::CancelAFNow()
       
  2211   {    
       
  2212   PRINT( _L("Camera => CCamAppController::CancelAfNow()") );
       
  2213   
       
  2214   if( !iAFCancelInProgress && ECamFocusing == CurrentOperation() ) 
       
  2215     {
       
  2216     TRAPD( err, IssueDirectRequestL( ECamRequestCancelAutofocus ) );          
       
  2217     if( KErrNone == err ) 
       
  2218       {
       
  2219       iAFCancelInProgress = ETrue;  
       
  2220       iCurrentAFRequest = ECamRequestCancelAutofocus;      
       
  2221       iPendingAFRequest = ECamRequestCancelAutofocus;
       
  2222       }
       
  2223     }
       
  2224   else 
       
  2225     {
       
  2226     PRINT( _L("AF Cancel already in progress or not focusing") );
       
  2227     }   
       
  2228     
       
  2229   PRINT( _L("Camera <= CCamAppController::CancelAfNow()") );
       
  2230   }
       
  2231 // CCamAppController::CancelFocusAndCapture
       
  2232 // Cancel the focus and capture procedures
       
  2233 // ---------------------------------------------------------------------------
       
  2234 //
       
  2235 void CCamAppController::CancelFocusAndCapture()
       
  2236   {
       
  2237   PRINT( _L( "Camera => CCamAppController::CancelFocusAndCapture") );            
       
  2238   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - CurrentOperation() = [%s]"), KCamCaptureOperationNames[iInfo.iOperation] );
       
  2239   PRINT1( _L("Camera <> CCamAppController::CancelFocusAndCapture - IsViewFinding()    = [%d]"), IsViewFinding() );
       
  2240   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2241   // Only cancels autofocus if needed, burst capture is no longer
       
  2242   // stopped if capture key pressed during burst
       
  2243   
       
  2244   if( !iNoBurstCancel 
       
  2245    && ECamNoOperation != CurrentOperation()
       
  2246    && ECamCompleting  != CurrentOperation() )
       
  2247     {  
       
  2248     // If we are currently focused, cancel autofocus
       
  2249     if ( IsViewFinding() && CurrentOperation() != ECamCapturing &&  // Cannot do AF operations if VF not on. AF is anyway cancelled on VF start event.
       
  2250         iCurrentAFRequest != ECamRequestCancelAutofocus ) // Don't cancel twice
       
  2251       {
       
  2252       if( ECamFocusing == CurrentOperation() )
       
  2253         {
       
  2254         CancelAFNow();
       
  2255         if ( IsTouchScreenSupported() )
       
  2256             {
       
  2257             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  2258             if ( fixedToolbar )
       
  2259               {
       
  2260               fixedToolbar->SetToolbarVisibility( ETrue );
       
  2261               }        
       
  2262             }
       
  2263         }   
       
  2264       else 
       
  2265         {
       
  2266         TryAFRequest( ECamRequestCancelAutofocus );
       
  2267         }
       
  2268       }
       
  2269     iCaptureRequested = EFalse;
       
  2270     }
       
  2271   PRINT( _L( "Camera <= CCamAppController::CancelFocusAndCapture") );            
       
  2272   }
       
  2273 
       
  2274 
       
  2275 // ---------------------------------------------------------------------------
       
  2276 // CCamAppController::SnapshotImage
       
  2277 // Get post-exposure snapshot bitmap, if available.
       
  2278 //
       
  2279 // Returns: pointer to post-exposure snapshot bitmap. Does not transfer ownership.
       
  2280 //          May be NULL if no image available.
       
  2281 // 
       
  2282 // ---------------------------------------------------------------------------
       
  2283 //
       
  2284 const CFbsBitmap* 
       
  2285 CCamAppController::SnapshotImage()
       
  2286   {
       
  2287   PRINT ( _L("Camera => CCamAppController::SnapshotImage") ); 
       
  2288   PRINT1( _L("Camera <> CCamAppController::SnapshotImage .. current image index: %d"), iCurrentImageIndex ); 
       
  2289   PRINT1( _L("Camera => CCamAppController::SnapshotImage .. saved current image: %d"), SavedCurrentImage() ); 
       
  2290 
       
  2291   PRINT1( _L("Camera <> CCamAppController::SnapshotImage - iSnapshotRedrawNeeded:%d"), iSnapshotRedrawNeeded );
       
  2292   if ( iSnapShotRotator->IsActive() )
       
  2293     {
       
  2294     // Avoid flickering. Do not show original snapshot, if it needs to be rotated
       
  2295     // Snapshot might need a separate draw if rotation takes long time 
       
  2296     iSnapshotRedrawNeeded = ETrue;
       
  2297     PRINT( _L("Camera <= CCamAppController::SnapshotImage - return null") );
       
  2298     return NULL;
       
  2299     }
       
  2300   iSnapshotRedrawNeeded = EFalse;
       
  2301 
       
  2302   //Sometime burst capture array includes more than one image in single capture mode, 
       
  2303   //so just display the latest image here.
       
  2304   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2305   if ( BurstCaptureArray()->Count() > 1 && !appUi->IsBurstEnabled() )
       
  2306       {
       
  2307       TInt currentImageIndex = BurstCaptureArray()->Count() - 1;
       
  2308       const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( currentImageIndex );
       
  2309       PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2310       return ss;
       
  2311       }
       
  2312 
       
  2313   const CFbsBitmap* ss = BurstCaptureArray()->Snapshot( iCurrentImageIndex );
       
  2314   PRINT( _L("Camera <= CCamAppController::SnapshotImage") ); 
       
  2315   return ss;
       
  2316   }
       
  2317 
       
  2318 
       
  2319 // ---------------------------------------------------------------------------
       
  2320 // CCamAppController::SetAsCurrentImage
       
  2321 // Sets the specified index as the "current image", as will be used by the 
       
  2322 // post capture view
       
  2323 // ---------------------------------------------------------------------------
       
  2324 //
       
  2325 void 
       
  2326 CCamAppController::SetAsCurrentImage( TInt aIndex )
       
  2327   {
       
  2328   iCurrentImageIndex = aIndex;
       
  2329   }
       
  2330 
       
  2331 // ---------------------------------------------------------------------------
       
  2332 // CCamAppController::CurrentImageName
       
  2333 // Get the user-visible name for the current image 
       
  2334 // used in post-capture views.
       
  2335 // ---------------------------------------------------------------------------
       
  2336 //
       
  2337 const TDesC& 
       
  2338 CCamAppController::CurrentImageName() const
       
  2339   {
       
  2340   return BurstCaptureArray()->ImageName( iCurrentImageIndex );
       
  2341   }
       
  2342 
       
  2343 // ---------------------------------------------------------------------------
       
  2344 // CCamAppController::BurstCaptureArray
       
  2345 // Return a pointer to the array representing a burst capture
       
  2346 // ---------------------------------------------------------------------------
       
  2347 //
       
  2348 CCamBurstCaptureArray* 
       
  2349 CCamAppController::BurstCaptureArray() const
       
  2350   {
       
  2351   return iCaptureArray;
       
  2352   }        
       
  2353 
       
  2354 // ---------------------------------------------------------------------------
       
  2355 // CCamAppController::CurrentItemCount
       
  2356 // Return the count of non-deleted items in the burst array
       
  2357 // ---------------------------------------------------------------------------
       
  2358 //
       
  2359 TInt 
       
  2360 CCamAppController::CurrentItemCount()
       
  2361   {
       
  2362   if ( !BurstCaptureArray() )
       
  2363     {
       
  2364     return 0;
       
  2365     }
       
  2366   return BurstCaptureArray()->ImagesRemaining();
       
  2367   }
       
  2368 
       
  2369 // ---------------------------------------------------------------------------
       
  2370 // CCamAppController::CurrentCapturedCount
       
  2371 // Return the count of burst capture moments that have taken
       
  2372 // place in a current burst
       
  2373 // ---------------------------------------------------------------------------
       
  2374 //    
       
  2375 TInt 
       
  2376 CCamAppController::CurrentCapturedCount()
       
  2377   {
       
  2378   //return iActualBurstCount;
       
  2379   TInt count( 0 );
       
  2380   if( iCameraController )
       
  2381     {
       
  2382     // Using snapshot as count, because UI updates counter
       
  2383     // on snapshot events.
       
  2384     count = iCameraController->ControllerInfo().iSnapshotCount;
       
  2385     }
       
  2386   return count;  
       
  2387   }
       
  2388 
       
  2389 // ---------------------------------------------------------------------------
       
  2390 // CCamAppController::TimeLapseImageCount
       
  2391 // Return the count of items in the timelapse sequence array
       
  2392 // ---------------------------------------------------------------------------
       
  2393 //    
       
  2394 TInt 
       
  2395 CCamAppController::TimeLapseImageCount()
       
  2396   {
       
  2397   return iTimeLapseCaptureCount;
       
  2398   }
       
  2399 
       
  2400 // ---------------------------------------------------------------------------
       
  2401 // CCamAppController::ResetTimelapseArray
       
  2402 // Resets the timelapse sequence array
       
  2403 // ---------------------------------------------------------------------------
       
  2404 //    
       
  2405 void CCamAppController::ResetTimelapseArray()
       
  2406   {
       
  2407   iSequenceFilenameArray->Reset();
       
  2408   }
       
  2409 
       
  2410 // ---------------------------------------------------------------------------
       
  2411 // CCamAppController::PlaySound
       
  2412 // Play a sound with given id.
       
  2413 // ---------------------------------------------------------------------------
       
  2414 //
       
  2415 void CCamAppController::PlaySound( TCamSoundId aSoundId, TBool aEnableCallback )
       
  2416     {
       
  2417     PRINT1( _L("Camera => CCamAppController::PlaySound %d"), aSoundId );
       
  2418     if ( ToneShouldBeSilent( aSoundId ) &&
       
  2419          !iShutterSndAlwaysOn && 
       
  2420          iSilentProfile )
       
  2421         {
       
  2422         PRINT( _L("Camera <> Profile silent, do not play sound") );  
       
  2423         // Don't play shutter sound if we are following
       
  2424         // current profile setting and profile is silent.
       
  2425         // Notify the observer right away. E.g. video start
       
  2426         // depends on the notification
       
  2427         if( aEnableCallback )
       
  2428           {
       
  2429           PlayComplete( aSoundId, KErrNone );
       
  2430           }
       
  2431         /* OLD
       
  2432         if ( aSoundId == ECamVideoStartSoundId ||
       
  2433              aSoundId == ECamVideoPauseSoundId ||
       
  2434              aSoundId == ECamVideoResumeSoundId )
       
  2435             {
       
  2436             // Force the callback to start recording without sound.
       
  2437             PlaySoundComplete();
       
  2438             }
       
  2439         */
       
  2440         }
       
  2441     else
       
  2442         {
       
  2443         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUND, "e_CAM_APP_CAPTURE_SOUND_PLAY 1" );   //CCORAPP_CAPTURE_SOUND_PLAY_START
       
  2444         iSoundPlayer->CancelAllPlaying();
       
  2445         iSoundPlayer->PlaySound( aSoundId, aEnableCallback ); 
       
  2446 
       
  2447         }
       
  2448         
       
  2449     // If in timelapse mode the remaining time counter should be updated
       
  2450     // as soon as the capture tone has played, but as there is no callback
       
  2451     // this is the closest we can get            
       
  2452     if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )  
       
  2453         {
       
  2454         NotifyControllerObservers( ECamEventCounterUpdated );   
       
  2455         }       
       
  2456         
       
  2457     PRINT( _L("Camera <= CCamAppController::PlaySound") );                 
       
  2458     }
       
  2459 
       
  2460 
       
  2461 // ---------------------------------------------------------------------------
       
  2462 // CCamAppController::AllOptionsVisibleForSettingItem
       
  2463 // Returns true if all the settings list options for a particular setting
       
  2464 // item are visible.
       
  2465 // ---------------------------------------------------------------------------
       
  2466 //
       
  2467 TBool CCamAppController::AllOptionsVisibleForSettingItem( TInt aSettingItem, 
       
  2468                                                     TInt& aRevisedResourceId )
       
  2469   {
       
  2470   if ( ( aSettingItem == ECamSettingItemVideoQuality ) && 
       
  2471        ( iInfo.iActiveCamera == ECamActiveCameraSecondary ) )
       
  2472     {
       
  2473     aRevisedResourceId = ROID(R_CAM_FRONT_CAMERA_VIDEO_QUALITY_TEXT_ARRAY);
       
  2474     return EFalse;
       
  2475     }
       
  2476   // Otherwise, all options are visible for the setting item
       
  2477   return ETrue;
       
  2478   }
       
  2479 
       
  2480 // ----------------------------------------------------
       
  2481 // CCamAppController::SwitchCameraL
       
  2482 // Switch the camera
       
  2483 // ----------------------------------------------------
       
  2484 //
       
  2485 void CCamAppController::SwitchCameraL()
       
  2486   {
       
  2487   PRINT( _L("Camera => CCamAppController::SwitchCameraL") );
       
  2488 
       
  2489   TCamAppControllerInfo oldInfo      = iInfo;
       
  2490   TCamActiveCamera      targetCamera = ECamActiveCameraNone;
       
  2491   // If something goes wrong when changing from 2nd to 1st camera,
       
  2492   // we need to make sure, that 2nd cam settings are not stored 
       
  2493   // to CR by accident.
       
  2494   iInfo = TCamAppControllerInfo(); // reset
       
  2495   
       
  2496   // reset zoom waiting flag. this flag is only used with bitmap viewfinder
       
  2497   // and it might cause problems if one camera uses bitmap viewfinder and the
       
  2498   // other one uses direct viewfinder
       
  2499   iZoomWaitingForCamera = EFalse;
       
  2500 
       
  2501   CancelPreviewChangesL();
       
  2502 
       
  2503   if( ECamActiveCameraPrimary == oldInfo.iActiveCamera )
       
  2504     {
       
  2505     // Currently using primary camera, switch to secondary
       
  2506     PRINT( _L("Camera <> switch to 2nd cam") );
       
  2507  
       
  2508 #ifdef _DEBUG
       
  2509     PRINT ( _L("Camera <> ======================================") );
       
  2510     PRINT ( _L("Camera <> Photo quality index:                  ") );
       
  2511     PRINT1( _L("Camera <> Before loading 2nd cam settings: %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2512 #endif
       
  2513     
       
  2514     // Scene mode is forced to Automatic while secondary camera is in use.
       
  2515     iSceneModeForcedBySecondaryCamera = ETrue;
       
  2516 
       
  2517     LoadSecondaryCameraSettingsL();
       
  2518   
       
  2519 #ifdef _DEBUG
       
  2520     PRINT1( _L("Camera <> After loading 2nd cam settings:  %d   "), IntegerSettingValue( ECamSettingItemPhotoQuality ) );
       
  2521     PRINT ( _L("Camera <> ======================================") );
       
  2522 #endif
       
  2523 
       
  2524     targetCamera = ECamActiveCameraSecondary;
       
  2525     }
       
  2526   else
       
  2527     {
       
  2528     // Currently using secondary camera, switch to primary
       
  2529     // or landscape secondary camera  
       
  2530     PRINT( _L("Camera <> switch to 1st camera or change 2nd camera mode") )
       
  2531     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  2532     if( appUi->IsEmbedded() )
       
  2533         {
       
  2534         LoadStaticSettingsL( appUi->IsEmbedded() );
       
  2535         }
       
  2536     else if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2537         {
       
  2538         iSettingsModel->RestorePrimaryCameraSettingsL();
       
  2539         }
       
  2540 
       
  2541     if ( CameraSwitchQueued() != ESwitchSecondaryOrientation )
       
  2542         {
       
  2543         PRINT( _L("Camera <> switch to 1st cam") )
       
  2544         targetCamera = ECamActiveCameraPrimary;
       
  2545         
       
  2546         // Primary camera will use its previously selected scene mode after camera switch.
       
  2547         iSceneModeForcedBySecondaryCamera = EFalse;
       
  2548         }
       
  2549     else
       
  2550         {
       
  2551         PRINT( _L("Camera <> change 2nd camera mode") )
       
  2552         targetCamera = ECamActiveCameraSecondary;
       
  2553         }
       
  2554     }	            
       
  2555   SetCameraSwitchRequired( ESwitchDone );  
       
  2556   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2557   iCameraController->SwitchCameraL( (ECamActiveCameraPrimary == targetCamera) ? 0 : 1 );
       
  2558   if( UiConfigManagerPtr()->IsUIOrientationOverrideSupported() )
       
  2559       {
       
  2560       RArray<TInt> screenModeValues;
       
  2561       UiConfigManagerPtr()->SupportedScreenModesL( screenModeValues );
       
  2562       TInt landscapeScreenMode = screenModeValues[0];
       
  2563       SetCameraOrientationModeL( landscapeScreenMode );
       
  2564       }
       
  2565   iCameraController->CompleteSwitchCameraL();
       
  2566   // Force to get a sensor data after switch camera from primary to secondary 
       
  2567   // when always holding in camera with portrait mode. 
       
  2568   if( iConfigManager 
       
  2569       && iConfigManager->IsOrientationSensorSupported() )
       
  2570     {
       
  2571     if( iAccSensorListening )
       
  2572       {
       
  2573       iAccSensorListening = EFalse;
       
  2574       }
       
  2575     if( iAccSensorChannel )
       
  2576       {
       
  2577       delete iAccSensorChannel;
       
  2578       iAccSensorChannel = NULL;
       
  2579       }        
       
  2580     TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  2581     }
       
  2582 
       
  2583   // Camera switched.
       
  2584   // a) Set current camera index to the new one.
       
  2585   // b) Set target mode (video/image) to the one before mode switch.
       
  2586   // c) Image mode is single shot after camera switch
       
  2587   // d) Ensure vf start
       
  2588   iInfo.iActiveCamera    = targetCamera; // a)
       
  2589   iInfo.iTargetMode      = appUi->TargetMode(); // b)
       
  2590   iInfo.iTargetImageMode = ( ECamControllerVideo==iInfo.iTargetMode )
       
  2591                          ? ECamImageCaptureNone : ECamImageCaptureSingle; // c)
       
  2592   iInfo.iTargetVfState   = ECamTriActive; // d)
       
  2593   if( oldInfo.iMode != ECamControllerShutdown )
       
  2594   	{
       
  2595   	IssueModeChangeSequenceL();
       
  2596   	}
       
  2597   	
       
  2598   appUi->SetDrawPreCaptureCourtesyUI( ETrue );
       
  2599 
       
  2600   NotifyControllerObservers( ECamEventCameraChanged );
       
  2601 
       
  2602   PRINT( _L("Camera <= CCamAppController::SwitchCameraL") );
       
  2603   }
       
  2604 
       
  2605 // ---------------------------------------------------------------------------
       
  2606 // CCamAppController::ActiveCamera
       
  2607 // Returns the active camera
       
  2608 // ---------------------------------------------------------------------------
       
  2609 //
       
  2610 TCamActiveCamera 
       
  2611 CCamAppController::ActiveCamera() const
       
  2612   {
       
  2613   return iInfo.iActiveCamera;
       
  2614   }
       
  2615 
       
  2616 // ---------------------------------------------------------------------------
       
  2617 // CCamAppController::CameraSwitchQueued
       
  2618 // Returns whether a camera switch is pending
       
  2619 // ---------------------------------------------------------------------------
       
  2620 //
       
  2621 TCameraSwitchRequired 
       
  2622 CCamAppController::CameraSwitchQueued() const   
       
  2623   {
       
  2624   PRINT1( _L("Camera =><= CCamAppController::CameraSwitchQueued %d"), iCameraSwitchRequired )
       
  2625   return iCameraSwitchRequired;
       
  2626   }
       
  2627 
       
  2628 // ---------------------------------------------------------------------------
       
  2629 // CCamAppController::CheckExitStatus
       
  2630 // Check whether exit is required
       
  2631 // ---------------------------------------------------------------------------
       
  2632 //
       
  2633 TBool 
       
  2634 CCamAppController::CheckExitStatus()
       
  2635   {
       
  2636   PRINT( _L("Camera => CCamAppController::CheckExitStatus" ) )
       
  2637   TBool exit = EFalse;
       
  2638   if ( iEndKeyWaiting )
       
  2639       {
       
  2640       exit = ETrue;
       
  2641       }   
       
  2642   else if ( iConfigManager  && iConfigManager->IsLensCoverSupported() )
       
  2643       {
       
  2644       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2645 
       
  2646       if ( iSliderCloseEvent && !appUi->IsEmbedded() && !appUi->Embedding() )
       
  2647           {
       
  2648           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - slider closed, not embedded/embedding" ) )
       
  2649           exit = ETrue;
       
  2650           }
       
  2651       else
       
  2652           {
       
  2653           PRINT( _L("Camera <> CCamAppController::CheckExitStatus - embedded/embedding, not exiting" ) )
       
  2654           exit = EFalse;
       
  2655           }
       
  2656       }
       
  2657   else
       
  2658       {
       
  2659       exit = EFalse;
       
  2660       }
       
  2661 
       
  2662   PRINT1( _L("Camera <= CCamAppController::CheckExitStatus - return %d" ), exit )
       
  2663   return exit;
       
  2664   }
       
  2665     
       
  2666 // ---------------------------------------------------------------------------
       
  2667 // CCamAppController::SetEndKeyExitWaiting
       
  2668 // Update whether exit is required
       
  2669 // ---------------------------------------------------------------------------
       
  2670 //
       
  2671 void 
       
  2672 CCamAppController::SetEndKeyExitWaiting( TBool aEndKeyWaiting )
       
  2673   {
       
  2674   iEndKeyWaiting = aEndKeyWaiting;
       
  2675   }    
       
  2676 
       
  2677 // ---------------------------------------------------------------------------
       
  2678 // CCamAppController::CameraSlideState
       
  2679 // Returns the status of the camera slide
       
  2680 // ---------------------------------------------------------------------------
       
  2681 //
       
  2682 TInt 
       
  2683 CCamAppController::CameraSlideState() const
       
  2684   {
       
  2685   return iSlideState;
       
  2686   }
       
  2687 
       
  2688 // ---------------------------------------------------------------------------
       
  2689 // CCamAppController::SliderCloseEventActioned
       
  2690 // Update whether exit is required
       
  2691 // ---------------------------------------------------------------------------
       
  2692 //
       
  2693 void 
       
  2694 CCamAppController::SliderCloseEventActioned()
       
  2695   {
       
  2696   iSliderCloseEvent = EFalse;
       
  2697   }   
       
  2698 
       
  2699 // ---------------------------------------------------------------------------
       
  2700 // CCamAppController::SetCameraSwitchRequired
       
  2701 // ---------------------------------------------------------------------------
       
  2702 //
       
  2703 void 
       
  2704 CCamAppController::SetCameraSwitchRequired( TCameraSwitchRequired aSwitchRequired )  
       
  2705   {
       
  2706   iCameraSwitchRequired = aSwitchRequired;
       
  2707   }   
       
  2708 
       
  2709 
       
  2710 // ---------------------------------------------------------------------------
       
  2711 // CCamAppController::CheckSlideStatus
       
  2712 // Check the slide state and schedule a camera switch if needed
       
  2713 // ---------------------------------------------------------------------------
       
  2714 //
       
  2715 void CCamAppController::CheckSlideStatus()
       
  2716   {
       
  2717   PRINT( _L("Camera => CCamAppController::CheckSlideStatus") );
       
  2718   // if only 1 camera available then can't switch camera
       
  2719   if ( CamerasAvailable() <= 1 )
       
  2720     {
       
  2721     PRINT( _L("Camera <> Only one camera, no action") );
       
  2722     }
       
  2723   else
       
  2724     {
       
  2725     RefreshSlideStatus();
       
  2726     // if the slide is closed then schedule a camera switch
       
  2727     // if the back camera is active
       
  2728     if ( CameraSlideState() == CameraPlatPSKeys::EClosed  || 
       
  2729          CameraSlideState() == KErrNone )
       
  2730       {
       
  2731       if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  2732         {
       
  2733         PRINT( _L("Camera <> slide closed or uninitialized -> switch to secondary") );
       
  2734         iCameraSwitchRequired = ESwitchPrimaryToSecondary;
       
  2735         }
       
  2736       else
       
  2737         {
       
  2738         PRINT( _L("Camera <> no camera switch needed") );
       
  2739         iCameraSwitchRequired = ESwitchDone;
       
  2740         }
       
  2741       }
       
  2742     // if the slide is open then schedule a camera switch
       
  2743     // if the front camera is active
       
  2744     else if ( CameraSlideState() == CameraPlatPSKeys::EOpen )
       
  2745       {
       
  2746       if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  2747         {
       
  2748         PRINT( _L("Camera <> slide open -> switch to primary") );
       
  2749         iCameraSwitchRequired = ESwitchSecondaryToPrimary;
       
  2750         }
       
  2751       else
       
  2752         {
       
  2753         PRINT( _L("Camera <> no camera switch needed") );
       
  2754         iCameraSwitchRequired = ESwitchDone;
       
  2755         }
       
  2756       }
       
  2757     else
       
  2758       {
       
  2759       // do nothing
       
  2760       PRINT( _L("Camera <> not recognized slider state -> no action") );
       
  2761       }
       
  2762     }
       
  2763   PRINT( _L("Camera <= CCamAppController::CheckSlideStatus") );
       
  2764   }
       
  2765 
       
  2766 
       
  2767 // ----------------------------------------------------
       
  2768 // CCamAppController::EvRange
       
  2769 // Range of EV value supported by current product
       
  2770 // ----------------------------------------------------
       
  2771 //
       
  2772 TCamEvCompRange CCamAppController::EvRange() const
       
  2773   {
       
  2774   PRINT( _L("Camera =><= CCamAppController::EvRange") );
       
  2775   return iEvRange;
       
  2776   }            
       
  2777 
       
  2778 
       
  2779 // ----------------------------------------------------
       
  2780 // CCamAppController::CallStateChanged
       
  2781 // Callback for when the current phone call state changes
       
  2782 // ----------------------------------------------------
       
  2783 //
       
  2784 void 
       
  2785 CCamAppController::CallStateChanged( TPSCTsyCallState aState, 
       
  2786                                      TInt                  /* aError */ )
       
  2787   {
       
  2788   PRINT1( _L("Camera => CCamAppController::CallStateChanged aState: %d"), aState);
       
  2789 
       
  2790   TBool oldState = iInCallOrRinging;
       
  2791 
       
  2792   if ( aState == EPSCTsyCallStateAlerting ||
       
  2793        aState == EPSCTsyCallStateRinging ||
       
  2794        aState == EPSCTsyCallStateDialling ||
       
  2795        aState == EPSCTsyCallStateAnswering ||
       
  2796        aState == EPSCTsyCallStateDisconnecting ||
       
  2797        aState == EPSCTsyCallStateConnected ||
       
  2798        aState == EPSCTsyCallStateHold )
       
  2799     {
       
  2800     // If not already in a call/ringing state, and the new state
       
  2801     // indicates this, stop recording
       
  2802     if ( !iInCallOrRinging )
       
  2803       {
       
  2804       // Set the flag before handle call, as this may need to 
       
  2805       // know the call state for stopping video.
       
  2806       iInCallOrRinging = ETrue;
       
  2807       PRINT( _L("Camera <> CCamAppController::CallStateChanged: calling handleincomingcallL") );
       
  2808       HandleIncomingCall();                                     
       
  2809       }
       
  2810     }
       
  2811   else
       
  2812     {
       
  2813     iInCallOrRinging = EFalse;
       
  2814     }
       
  2815   // If the state has changed from in a call to not, notify the
       
  2816   // observers
       
  2817   // Also notify again if the state has reached connected so that
       
  2818   // the observer can reconsider its actions now that connection is complete
       
  2819   if ( iInCallOrRinging               != oldState ||
       
  2820        EPSCTsyCallStateConnected == aState )
       
  2821     {
       
  2822     PRINT( _L("Camera <> CCamAppController::CallStateChanged: telling call observers") );
       
  2823     NotifyControllerObservers( ECamEventCallStateChanged, KErrNone );        
       
  2824     }
       
  2825 
       
  2826   PRINT1( _L("Camera <= CCamAppController::CallStateChanged(%d, %d)"), aState );
       
  2827   }
       
  2828 
       
  2829 
       
  2830 
       
  2831 
       
  2832 
       
  2833 
       
  2834 // ---------------------------------------------------------------------------
       
  2835 // ReleaseCamera
       
  2836 //
       
  2837 // Releases the camera hardware for other apps to use
       
  2838 // ---------------------------------------------------------------------------
       
  2839 //
       
  2840 void CCamAppController::ReleaseCamera()   
       
  2841     {    
       
  2842     PRINT( _L("Camera => CCamAppController::ReleaseCamera") );
       
  2843 
       
  2844     if ( IsAppUiAvailable())  
       
  2845       {
       
  2846       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  2847       if ( appUi )
       
  2848         {
       
  2849         appUi->SetAssumePostCaptureView( EFalse ); 
       
  2850         } 
       
  2851       }
       
  2852                                                                                          
       
  2853     if ( Busy() )
       
  2854       {
       
  2855       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: set release pending") );
       
  2856       iPendingRelease = ETrue;
       
  2857       }
       
  2858     else if ( iCameraController && ECamCameraIdle != CameraState() )
       
  2859       {      
       
  2860       // No leaving code here. Clear the flag before any operation
       
  2861       // to prevent calling this from the event callbacks caused
       
  2862       // by the following requests.
       
  2863       iPendingRelease = EFalse;
       
  2864 
       
  2865       if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  2866           SequenceCaptureInProgress() )
       
  2867         {
       
  2868         // Cancel ongoing burst capture
       
  2869         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  2870         // and actual cancelling is done when next imagedata arrives.
       
  2871         // However, in this case camera is going to be released, and there won't
       
  2872         // be next image data, so give ECamRequestImageCancel and capture
       
  2873         // completion event here to avoid problems
       
  2874         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: Going to bacgkround in the middle of a burst capture") ); 
       
  2875         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  2876         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );          
       
  2877         }
       
  2878       //In SetOperation(), it notify observer with ECamEventOperationStateChanged, 
       
  2879       //the clear work for flash indicator flag can be done with ECamEventOperationStateChanged in some abnormal cases.
       
  2880       if ( ECamControllerImage == CurrentMode() && iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  2881         {             
       
  2882         SetOperation( ECamNoOperation );
       
  2883         }
       
  2884 
       
  2885         
       
  2886       //iInfo.iMode            = ECamControllerShutdown;
       
  2887       //iInfo.iTargetMode      = ECamControllerIdle;
       
  2888       iInfo.iTargetMode      = ECamControllerIdle;
       
  2889       iInfo.iImageMode       = ECamImageCaptureNone;
       
  2890       iInfo.iTargetImageMode = ECamImageCaptureNone; 
       
  2891       iInfo.iOperation       = ECamNoOperation;
       
  2892 
       
  2893       iCaptureModeTransitionInProgress = EFalse;
       
  2894 
       
  2895       // Last change to stop view finder if we were "busy" previously in 
       
  2896       // ExitViewfinderMode method. View finder must be stopped in case where 
       
  2897       // orientation is changed, so Posting API display control doesn't try to 
       
  2898       // draw outside existing area. Otherwise KErrTooBig error is encountered. 
       
  2899       StopViewFinder();
       
  2900 
       
  2901       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: requesting release directly..") );
       
  2902       // iInfo.iMode set when complete
       
  2903       TRAP_IGNORE( IssueDirectRequestL( ECamRequestRelease ) );
       
  2904       //iPendingRelease = EFalse;
       
  2905       //shutdown the orientation channel
       
  2906       if( iConfigManager && iConfigManager->IsOrientationSensorSupported() && 
       
  2907       		iAccSensorListening )
       
  2908         {
       
  2909         TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  2910         }
       
  2911       }
       
  2912     else
       
  2913       {
       
  2914       // No action needed.
       
  2915       PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle!!") );
       
  2916       if(ECamControllerIdle != iInfo.iMode )
       
  2917         {
       
  2918         PRINT( _L("Camera <> CCamAppController::ReleaseCamera: camera already idle correcting state!!") );
       
  2919         iInfo.iMode = ECamControllerIdle;
       
  2920         }
       
  2921       }
       
  2922     PRINT( _L("Camera <= CCamAppController::ReleaseCamera") );
       
  2923     }
       
  2924 
       
  2925 
       
  2926 // ---------------------------------------------------------------------------
       
  2927 // IncCameraUsers
       
  2928 //
       
  2929 // Increments the camera usage count
       
  2930 // ---------------------------------------------------------------------------
       
  2931 //
       
  2932 void CCamAppController::IncCameraUsers()
       
  2933   {
       
  2934   PRINT ( _L("Camera => CCamAppController::IncCameraUsers") );
       
  2935   iCameraReferences++;
       
  2936   PRINT1( _L("Camera <= CCamAppController::IncCameraUsers, count now %d"), iCameraReferences );
       
  2937   }
       
  2938 
       
  2939 
       
  2940 // ---------------------------------------------------------------------------
       
  2941 // DecCameraUsers
       
  2942 //
       
  2943 // Decrements the camera usage count
       
  2944 // ---------------------------------------------------------------------------
       
  2945 //
       
  2946 void CCamAppController::DecCameraUsers()
       
  2947   {
       
  2948   PRINT ( _L("Camera => CCamAppController::DecCameraUsers") );
       
  2949 
       
  2950   __ASSERT_DEBUG( iCameraReferences > 0, CamPanic( ECamPanicInvalidState ) );
       
  2951   iCameraReferences--;
       
  2952 
       
  2953   PRINT1( _L("Camera <> CCamAppController::DecCameraUsers: count now %d"), iCameraReferences );
       
  2954   // If the engine is no longer required then release it.
       
  2955   if ( iCameraReferences <= 0 )
       
  2956     {
       
  2957     ReleaseCamera();
       
  2958     }       
       
  2959   PRINT ( _L("Camera <= CCamAppController::DecCameraUsers") );
       
  2960   }
       
  2961 
       
  2962 
       
  2963     
       
  2964 
       
  2965 // ----------------------------------------------------
       
  2966 // CCamAppController::InCallOrRinging
       
  2967 // Whether we are in call or ringing
       
  2968 // ----------------------------------------------------
       
  2969 //
       
  2970 TBool 
       
  2971 CCamAppController::InCallOrRinging() const
       
  2972   {
       
  2973   return iInCallOrRinging;
       
  2974   }
       
  2975 
       
  2976 // ----------------------------------------------------
       
  2977 // CCamAppController::InVideocallOrRinging
       
  2978 // Whether we are in videocall or ringing
       
  2979 // ----------------------------------------------------
       
  2980 //
       
  2981 TBool 
       
  2982 CCamAppController::InVideocallOrRinging()
       
  2983     {
       
  2984     if ( InCallOrRinging() )
       
  2985         {
       
  2986         TInt callType( EPSCTsyCallTypeUninitialized );
       
  2987         TInt err = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType, callType );
       
  2988         if ( err == KErrNone && callType == EPSCTsyCallTypeH324Multimedia )
       
  2989             {
       
  2990             return ETrue;
       
  2991             }
       
  2992         else
       
  2993             {
       
  2994             return EFalse;
       
  2995             }
       
  2996         }
       
  2997     else
       
  2998         {
       
  2999         return EFalse;
       
  3000         }
       
  3001     
       
  3002     }
       
  3003   
       
  3004 // ----------------------------------------------------
       
  3005 // CCamAppController::CurrentlySavingVideo
       
  3006 // Whether we are currently saving a video clip or not
       
  3007 // ----------------------------------------------------
       
  3008 //
       
  3009 TBool 
       
  3010 CCamAppController::CurrentlySavingVideo() const
       
  3011   {
       
  3012   return iSaving;
       
  3013   }
       
  3014         
       
  3015 
       
  3016 
       
  3017 // ---------------------------------------------------------------------------
       
  3018 // IssueModeChangeSequenceL
       
  3019 // ---------------------------------------------------------------------------
       
  3020 //
       
  3021 void
       
  3022 CCamAppController::IssueModeChangeSequenceL( TBool aStartup )
       
  3023   {
       
  3024   PRINT( _L( "Camera => CCamAppController::IssueModeChangeSequenceL" ) );
       
  3025   // Generate the request sequence and issue to Camera Controller.
       
  3026   RCamRequestArray sequence;
       
  3027   CleanupClosePushL( sequence );
       
  3028 
       
  3029   if( !aStartup )
       
  3030     {
       
  3031     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3032     TVwsViewId activeView;
       
  3033     (void) appUi->GetActiveViewId( activeView ); // ignore error
       
  3034     
       
  3035     if(IntegerSettingValue(ECamSettingItemRemovePhoneMemoryUsage) &&
       
  3036             !IsMemoryAvailable(ECamMediaStorageMassStorage) &&
       
  3037             !IsMemoryAvailable(ECamMediaStorageCard) &&
       
  3038             ( appUi->PreCaptureMode() == ECamPreCapViewfinder ||
       
  3039               appUi->PreCaptureMode() == ECamPreCapGenericSetting ) &&
       
  3040               activeView.iViewUid.iUid != ECamViewIdPhotoUserSceneSetup )
       
  3041         {
       
  3042         TBool usbPersonality = 0;
       
  3043         #ifndef __WINSCW__
       
  3044         User::LeaveIfError ( RProperty::Get (KPSUidUsbWatcher, 
       
  3045                           KUsbWatcherSelectedPersonality, usbPersonality));
       
  3046         #endif // __WINSCW__     
       
  3047         TInt mmcInserted = 0;
       
  3048         User::LeaveIfError( RProperty::Get( KPSUidUikon, KUikMMCInserted, mmcInserted ) );
       
  3049 
       
  3050         if( KUsbPersonalityIdMS == usbPersonality )
       
  3051             {
       
  3052             SwitchToStandbyL( ECamErrMassStorageMode );
       
  3053             }
       
  3054         else if( !mmcInserted )
       
  3055             {
       
  3056             SwitchToStandbyL( ECamErrMemoryCardNotInserted );
       
  3057             }
       
  3058         else
       
  3059             {
       
  3060             CamPanic(ECamPanicInvalidState);
       
  3061             }
       
  3062         
       
  3063         iIssueModeChangeSequenceSucceeded = EFalse;
       
  3064         ClearSequenceBusyFlag( &iBusyFlags );
       
  3065         }
       
  3066     else
       
  3067         {
       
  3068         GenerateModeChangeSequenceL( sequence );
       
  3069         
       
  3070         if( iCameraReferences ) 
       
  3071             {
       
  3072             SetFlags( iBusyFlags, EBusySequence );
       
  3073             TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  3074             CleanupStack::PushL( clearBusy );
       
  3075             iCameraController->RequestSequenceL( sequence );
       
  3076             CleanupStack::Pop();
       
  3077             
       
  3078             iCaptureModeTransitionInProgress = ETrue;
       
  3079             
       
  3080             }
       
  3081         else 
       
  3082             {
       
  3083             PRINT( _L("Camera <> No camera users, not requesting sequence.") );
       
  3084             }
       
  3085         iIssueModeChangeSequenceSucceeded = ETrue;
       
  3086         }  
       
  3087     }
       
  3088   else
       
  3089     {
       
  3090     GenerateStartupSequenceL( sequence );
       
  3091 	
       
  3092 	SetFlags( iBusyFlags, EBusySequence );
       
  3093     TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
  3094     CleanupStack::PushL( clearBusy );
       
  3095     iCameraController->RequestSequenceL( sequence );
       
  3096     CleanupStack::Pop();
       
  3097     iIssueModeChangeSequenceSucceeded = ETrue;
       
  3098     }
       
  3099   
       
  3100   CleanupStack::PopAndDestroy(); // sequence.Close()
       
  3101   PRINT( _L( "Camera <= CCamAppController::IssueModeChangeSequenceL" ) );
       
  3102   }
       
  3103 
       
  3104 // ---------------------------------------------------------------------------
       
  3105 // 
       
  3106 // ---------------------------------------------------------------------------
       
  3107 //
       
  3108 void
       
  3109 CCamAppController::GenerateModeChangeSequenceL( RCamRequestArray& aSequence )
       
  3110   {
       
  3111   PRINT( _L( "Camera => CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3112   TBool vfStartDone = EFalse;
       
  3113   //Have to empty autofocusrequest values here because modechange could override
       
  3114   //currently processed autofocus request.
       
  3115   iPendingAFRequest=0;
       
  3116   iCurrentAFRequest=0;
       
  3117   iNoBurstCancel = EFalse;
       
  3118   iKeyUP = EFalse;
       
  3119   iAFCancelInProgress = EFalse;
       
  3120   iTouchCapture = EFalse;
       
  3121 
       
  3122   // -------------------------------------------------------
       
  3123   if( ECamTriIdle != iCameraController->ViewfinderState() )
       
  3124     {
       
  3125     // If VF is not stopped, frames might come when we are not
       
  3126     // in either image or video mode.
       
  3127     if( ECamControllerIdle != iInfo.iMode 
       
  3128      && iInfo.iTargetMode  != iInfo.iMode )    
       
  3129       {
       
  3130       aSequence.Append( ECamRequestVfRelease );    
       
  3131       } 
       
  3132     else  
       
  3133       
       
  3134     if( ECamTriIdle == iInfo.iTargetVfState )
       
  3135       {
       
  3136       aSequence.Append( ECamRequestVfRelease );      
       
  3137       }
       
  3138     else if( ECamTriInactive == iInfo.iTargetVfState )
       
  3139       {
       
  3140       aSequence.Append( ECamRequestVfStop );      
       
  3141       }
       
  3142     else
       
  3143       {
       
  3144       // Nothing needed here
       
  3145       }
       
  3146 
       
  3147     }
       
  3148 
       
  3149   switch( iInfo.iMode )
       
  3150     {
       
  3151     // ---------------------------------
       
  3152     case ECamControllerImage:
       
  3153       {
       
  3154       if( ECamControllerImage != iInfo.iTargetMode )
       
  3155         {
       
  3156         aSequence.Append( ECamRequestImageRelease );
       
  3157         }
       
  3158       break;
       
  3159       }
       
  3160     // ---------------------------------
       
  3161     case ECamControllerVideo:
       
  3162       {
       
  3163       if( ECamControllerVideo != iInfo.iTargetMode )
       
  3164         {
       
  3165         aSequence.Append( ECamRequestVideoRelease );
       
  3166         }
       
  3167       break;
       
  3168       }
       
  3169     // ---------------------------------
       
  3170     default:
       
  3171       {
       
  3172       // If we need to get to video or image mode
       
  3173       // make sure camera has power on before further requests.
       
  3174       if( ECamControllerImage == iInfo.iTargetMode
       
  3175        || ECamControllerVideo == iInfo.iTargetMode )
       
  3176         {
       
  3177         TUint cameraState( iCameraController->State() );
       
  3178 
       
  3179         if( !(ECamPowerOn&cameraState) )
       
  3180           {
       
  3181           if( !(ECamReserved&cameraState) )
       
  3182             {
       
  3183             aSequence.Append( ECamRequestReserve );
       
  3184             }
       
  3185           aSequence.Append( ECamRequestPowerOn );
       
  3186           }
       
  3187         }
       
  3188       break;
       
  3189       }
       
  3190     // ---------------------------------
       
  3191     }
       
  3192 
       
  3193   // -------------------------------------------------------
       
  3194   // Append prepare operations to achieve target camera mode
       
  3195   switch( iInfo.iTargetMode )
       
  3196     {
       
  3197     // ---------------------------------
       
  3198     case ECamControllerImage:
       
  3199       {
       
  3200       if( ECamImageCaptureNone != iInfo.iTargetImageMode )
       
  3201         {
       
  3202         aSequence.Append( ECamRequestImageInit );      
       
  3203 
       
  3204         // Snapshot may have to be released and restarted because the
       
  3205         // snapshot size may change.
       
  3206         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3207         if( appUi )
       
  3208             {
       
  3209             if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3210                 {
       
  3211                 // If vf needs to be (re)started.
       
  3212                 // Camera Controller checks from Setting Provider if
       
  3213                 // viewfinder mode (direct/bitmap) has changed, and
       
  3214                 // releases old type first if needed.
       
  3215                 if( ECamTriActive == iInfo.iTargetVfState )
       
  3216                   {
       
  3217                   PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3218                   aSequence.Append( ECamRequestVfStart );
       
  3219                   vfStartDone = ETrue;
       
  3220                   }
       
  3221                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3222                 aSequence.Append( ECamRequestSsRelease );
       
  3223                 aSequence.Append( ECamRequestSsStart );
       
  3224                 }
       
  3225             else
       
  3226                 {
       
  3227                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3228                 aSequence.Append( ECamRequestSsRelease );
       
  3229                 aSequence.Append( ECamRequestSsStart ); // SS is requested and delivered to tn-manager, but not shown on display
       
  3230                 }
       
  3231             }
       
  3232         }
       
  3233 
       
  3234       break;
       
  3235       }
       
  3236     // ---------------------------------
       
  3237     case ECamControllerVideo:
       
  3238       {
       
  3239       // Video recorder needs to be initialized and prepared
       
  3240       // if we are not already in video mode.
       
  3241       if ( iInfo.iMode != ECamControllerVideo )
       
  3242           {
       
  3243           iVideoInitNeeded = ETrue;
       
  3244           }
       
  3245        aSequence.Append( ECamRequestVideoInit );
       
  3246        
       
  3247       // Snapshot has to be released and restarted because the
       
  3248       // snapshot size may change.
       
  3249       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3250       if( appUi )
       
  3251           {
       
  3252           if( appUi->ShowPostCaptureView() || iInfo.iTargetImageMode == ECamImageCaptureBurst )
       
  3253               {
       
  3254               // If vf needs to be (re)started.
       
  3255               // Camera Controller checks from Setting Provider if
       
  3256               // viewfinder mode (direct/bitmap) has changed, and
       
  3257               // releases old type first if needed.
       
  3258               if( ECamTriActive == iInfo.iTargetVfState )
       
  3259                 {
       
  3260                 PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3261                 aSequence.Append( ECamRequestVfStart );
       
  3262                 vfStartDone = ETrue;
       
  3263                 }
       
  3264               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3265               aSequence.Append( ECamRequestSsRelease );
       
  3266               aSequence.Append( ECamRequestSsStart );
       
  3267               }
       
  3268           else
       
  3269               {
       
  3270               PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: Snapshot on" ) );
       
  3271               aSequence.Append( ECamRequestSsRelease );
       
  3272               aSequence.Append( ECamRequestSsStart );
       
  3273               }
       
  3274           }
       
  3275       break;
       
  3276       }
       
  3277     // ---------------------------------
       
  3278     default:
       
  3279       break;
       
  3280     // ---------------------------------
       
  3281     }
       
  3282 
       
  3283   // If vf needs to be (re)started.
       
  3284   // Camera Controller checks from Setting Provider if
       
  3285   // viewfinder mode (direct/bitmap) has changed, and
       
  3286   // releases old type first if needed.
       
  3287   if( !vfStartDone && ECamTriActive == iInfo.iTargetVfState )
       
  3288     {
       
  3289     PRINT( _L( "Camera <> CCamAppController::GenerateModeChangeSequenceL: VF start needed" ) );
       
  3290     aSequence.Append( ECamRequestVfStart );
       
  3291     }
       
  3292 
       
  3293 
       
  3294   // -------------------------------------------------------
       
  3295 #ifdef _DEBUG
       
  3296   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
  3297   for( TInt i = 0; i < aSequence.Count(); i++ )
       
  3298     {
       
  3299     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
  3300     }
       
  3301 #endif  
       
  3302   PRINT( _L( "Camera <= CCamAppController::GenerateModeChangeSequenceL" ) );
       
  3303   }
       
  3304 
       
  3305 
       
  3306 // ---------------------------------------------------------------------------
       
  3307 // CCamAppController::SettingsPhotoResolution
       
  3308 // Returns the photo resolution stored by the Settings Model
       
  3309 // ---------------------------------------------------------------------------
       
  3310 //
       
  3311 TCamPhotoSizeId  CCamAppController::SettingsPhotoResolution() const
       
  3312     {
       
  3313     return iSettingsModel->CurrentPhotoResolution();
       
  3314     }
       
  3315 
       
  3316 // ---------------------------------------------------------------------------
       
  3317 // CCamAppController::GetCurrentImageDimensions
       
  3318 // ---------------------------------------------------------------------------
       
  3319 //
       
  3320 TSize 
       
  3321 CCamAppController::GetCurrentImageDimensions() const
       
  3322   {
       
  3323   TCamPhotoSizeId index = iSettingsModel->CurrentPhotoResolution();
       
  3324   TSize           size  = iSettingsModel->ImageResolutionFromIndex( index );
       
  3325   return size;
       
  3326   }
       
  3327 
       
  3328 // ---------------------------------------------------------------------------
       
  3329 // CCamAppController::GetCurrentImageResolution
       
  3330 // Gets the current image resolution used.  May not be the same at that stored in Settings
       
  3331 // if Zoom state is not 1x
       
  3332 // ---------------------------------------------------------------------------
       
  3333 //
       
  3334 TCamPhotoSizeId CCamAppController::GetCurrentImageResolution() const
       
  3335     {   
       
  3336     TCamPhotoSizeId size = iSettingsModel->CurrentPhotoResolution();
       
  3337     return size;    
       
  3338     }
       
  3339     
       
  3340 // ---------------------------------------------------------------------------
       
  3341 // CCamAppController::GetCurrentImageCompression
       
  3342 // Returns the photo compression level from the Settings Model
       
  3343 // ---------------------------------------------------------------------------
       
  3344 //
       
  3345 TInt  CCamAppController::GetCurrentImageCompression() const
       
  3346     {
       
  3347     return iSettingsModel->CurrentPhotoCompression();
       
  3348     }
       
  3349 
       
  3350 // ---------------------------------------------------------------------------
       
  3351 // CCamAppController::GetCurrentVideoResolution
       
  3352 // Gets the current video resolution used.  
       
  3353 // ---------------------------------------------------------------------------
       
  3354 //
       
  3355 TCamVideoResolution CCamAppController::GetCurrentVideoResolution() const
       
  3356     {   
       
  3357     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  3358     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];        
       
  3359     return static_cast<TCamVideoResolution>( level.VideoResolution() );
       
  3360     }
       
  3361 
       
  3362 // ---------------------------------------------------------------------------
       
  3363 // CCamAppController::UsePhoneMemoryL
       
  3364 // Force use of phone memory storage.  
       
  3365 // ---------------------------------------------------------------------------
       
  3366 //
       
  3367 void CCamAppController::UsePhoneMemoryL() const
       
  3368     {
       
  3369 #ifdef PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE   
       
  3370     // This function is used to directly force the value of media storage
       
  3371     // Bypasses any updates the controller does for change to these values
       
  3372 
       
  3373     if( ExistMassStorage() )
       
  3374         {
       
  3375         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3376                                              ECamMediaStorageMassStorage );
       
  3377         
       
  3378         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3379                                              ECamMediaStorageMassStorage );
       
  3380         }
       
  3381     else
       
  3382         {        
       
  3383         TCamMediaStorage storage = iSettingModel->
       
  3384                                     IntegerSettingValue( ECamSettingItemRemovePhoneMemoryUsage )?
       
  3385                                     ECamMediaStorageNone:
       
  3386                                     ECamMediaStoragePhone;
       
  3387 
       
  3388         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, 
       
  3389                                                     storage );
       
  3390         
       
  3391         iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  3392                                                     storage );
       
  3393         }
       
  3394 
       
  3395 #endif // PRODUCT_SUPPORTS_FORCE_MEDIA_STORAGE_VALUE
       
  3396     }
       
  3397 
       
  3398 
       
  3399 // ===========================================================================
       
  3400 // From MCamSettingsModelObserver
       
  3401 
       
  3402 // ---------------------------------------------------------------------------
       
  3403 // CCamAppController::IntSettingChangedL
       
  3404 //
       
  3405 // ---------------------------------------------------------------------------
       
  3406 //
       
  3407 void 
       
  3408 CCamAppController::IntSettingChangedL( TCamSettingItemIds aSettingItem, 
       
  3409                                        TInt               aSettingValue )
       
  3410   {
       
  3411   PRINT( _L("Camera => CCamAppController::IntSettingChangedL") );  
       
  3412   switch( aSettingItem )
       
  3413     {
       
  3414     case ECamSettingItemDynamicSelfTimer:
       
  3415       {
       
  3416       TCamSelfTimerFunctions function( ECamSelfTimerDisabled );
       
  3417       switch( aSettingValue )
       
  3418         {
       
  3419         case ECamSelfTimer2:  function = ECamSelfTimerMode1; break;
       
  3420         case ECamSelfTimer10: function = ECamSelfTimerMode2; break;
       
  3421         case ECamSelfTimer20: function = ECamSelfTimerMode3; break;            
       
  3422         default:                                             break;
       
  3423         }
       
  3424       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3425       if( appUi ) 
       
  3426         {
       
  3427         appUi->SelfTimerEnableL( function );
       
  3428         }
       
  3429       break;
       
  3430       }
       
  3431     case ECamSettingItemPhotoQuality:
       
  3432         {
       
  3433         HandleImageQualitySettingChangeL();
       
  3434         break;
       
  3435         }
       
  3436     case ECamSettingItemVideoQuality:
       
  3437        NotifyControllerObservers( ECamEventVideoQualityChanged, KErrNone );
       
  3438        break;
       
  3439     case ECamSettingItemVideoAudioRec:
       
  3440       {
       
  3441       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  3442       break;
       
  3443       }
       
  3444     case ECamSettingItemContinuousAutofocus:  
       
  3445       {
       
  3446       NotifyControllerObservers( ECamEventContAFStateChanged );
       
  3447       break;
       
  3448       }
       
  3449       
       
  3450     case ECamSettingItemFaceTracking:
       
  3451       {
       
  3452       PRINT( _L("Camera => ECamSettingItemFaceTracking") );
       
  3453       TCamCameraSettingId cameraId( 
       
  3454         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3455       iCameraController->DirectSettingsChangeL( cameraId );
       
  3456       NotifyControllerObservers( ECamEventFaceTrackingStateChanged );
       
  3457       
       
  3458       // If Face tracking was turned off by user (not forced off by a scene mode)
       
  3459       // update iPreviousFaceTrack to the current state as we are not going to
       
  3460       // reset to the previous state automatically at any point.
       
  3461       TCamSceneId scene = static_cast< TCamSceneId > 
       
  3462           ( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
  3463       
       
  3464       if ( scene != ECamSceneMacro &&
       
  3465            scene != ECamSceneScenery &&
       
  3466            scene != ECamSceneSports && 
       
  3467            !iSceneModeForcedBySecondaryCamera )
       
  3468           {
       
  3469           PRINT1( _L("Camera MK: Changing face tracking state -> update iPreviousFaceTrack to %d"), aSettingValue );
       
  3470           iSettingsModel->SetPreviousFaceTrack( static_cast<TCamSettingsOnOff>( aSettingValue ) );
       
  3471           }
       
  3472       
       
  3473       break;
       
  3474       }  
       
  3475     case ECamSettingItemDynamicVideoFlash:  
       
  3476       {
       
  3477       PRINT( _L("Camera => ECamSettingItemDynamicVideoFlash") );
       
  3478       TCamCameraSettingId cameraId( 
       
  3479         CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
  3480       iCameraController->DirectSettingsChangeL( cameraId );
       
  3481       break;
       
  3482       }  
       
  3483     default:
       
  3484       {
       
  3485       break;
       
  3486       }
       
  3487     }
       
  3488   PRINT( _L("Camera <= CCamAppController::IntSettingChangedL") );
       
  3489   }
       
  3490 
       
  3491 // ---------------------------------------------------------------------------
       
  3492 // CCamAppController::TextSettingChangedL
       
  3493 //
       
  3494 // ---------------------------------------------------------------------------
       
  3495 //
       
  3496 void 
       
  3497 CCamAppController::TextSettingChangedL( TCamSettingItemIds /*aSettingItem*/, 
       
  3498                                         const TDesC&       /*aSettingValue*/ )
       
  3499   {
       
  3500   }
       
  3501 
       
  3502 // ---------------------------------------------------------------------------
       
  3503 // HandleImageQualitySettingChangeL
       
  3504 // ---------------------------------------------------------------------------
       
  3505 //
       
  3506 void 
       
  3507 CCamAppController::HandleImageQualitySettingChangeL() 
       
  3508   {
       
  3509   PRINT( _L("Camera => CCamAppController::HandleImageQualitySettingChangeL") );
       
  3510   if( IsViewFinding() ) 
       
  3511     {
       
  3512     PRINT( _L("Camera <> CCamAppController - viewfinder on, stop vf / re-prepare / start vf..") );
       
  3513     TRAPD( status, 
       
  3514       {
       
  3515       IssueDirectRequestL( ECamRequestVfStop    );
       
  3516       IssueDirectRequestL( ECamRequestSsRelease );
       
  3517       IssueDirectRequestL( ECamRequestImageInit );
       
  3518       IssueDirectRequestL( ECamRequestVfStart   );
       
  3519       IssueDirectRequestL( ECamRequestSsStart   );
       
  3520       });
       
  3521       
       
  3522     if( KErrNone != status )
       
  3523       {
       
  3524       SetOperation( ECamStandby, status );
       
  3525       }
       
  3526     }
       
  3527 
       
  3528   NotifyControllerObservers( ECamEventImageQualityChanged, KErrNone );      
       
  3529   PRINT( _L("Camera <= CCamAppController::HandleImageQualitySettingChangeL") );
       
  3530   }
       
  3531 
       
  3532 // ---------------------------------------------------------------------------
       
  3533 // CCamAppController::BurstModeActive
       
  3534 //
       
  3535 // ---------------------------------------------------------------------------
       
  3536 //
       
  3537 void
       
  3538 CCamAppController::BurstModeActiveL( TBool aActive, TBool /*aStillModeActive*/ )
       
  3539   { 
       
  3540   PRINT1( _L("Camera => CCamAppController::BurstModeActiveL %d"), aActive );  
       
  3541   if( ECamControllerImage == iInfo.iMode )  
       
  3542     {
       
  3543     //TCamImageCaptureMode oldImageMode = iInfo.iImageMode; 
       
  3544     // We are in still capture mode     
       
  3545     if( aActive )
       
  3546       {
       
  3547       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = appUi->CurrentBurstMode() ") );  
       
  3548       // Burst mode active. Query current mode from AppUi  
       
  3549       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3550       // iInfo.iImageMode = appUi->CurrentBurstMode();
       
  3551       SetImageMode( appUi->CurrentBurstMode() );
       
  3552       // reset image orientation
       
  3553       iImageOrientation = ECamOrientation0;
       
  3554       TRAP_IGNORE( SetImageOrientationL() );
       
  3555       
       
  3556       }
       
  3557     else
       
  3558       {
       
  3559       // Burst mode not active  
       
  3560       PRINT( _L("Camera <> CCamAppController .. iInfo.iImageMode = ECamImageCaptureSingle ") );
       
  3561       // iInfo.iImageMode = ECamImageCaptureSingle;
       
  3562       SetImageMode( ECamImageCaptureSingle );
       
  3563       }  
       
  3564     iRequestedCaptureCount = ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3565                              ? KShortBurstCount
       
  3566                              : 1;
       
  3567     iCameraController->DirectSettingsChangeL( ECameraSettingCaptureLimit );
       
  3568     // set image orientation in case it was changed during burst mode
       
  3569     if( iOrientationChangeOccured )
       
  3570         {
       
  3571         iOrientationChangeOccured = EFalse;	
       
  3572         TRAP_IGNORE( SetImageOrientationL() );
       
  3573         }
       
  3574 
       
  3575     }
       
  3576   else
       
  3577     {
       
  3578     PRINT( _L("Camera <> CCamAppController .. [WARNING] Not in image mode, set iInfo.iImageMode = ECamImageCaptureNone") );  
       
  3579     // iInfo.iImageMode = ECamImageCaptureNone;  
       
  3580     SetImageMode( ECamImageCaptureNone );
       
  3581     } 
       
  3582   PRINT( _L("Camera <= CCamAppController::BurstModeActiveL %d") );    
       
  3583   }
       
  3584 
       
  3585 
       
  3586 // ---------------------------------------------------------------------------
       
  3587 // CCamAppController::SetVideoLengthL
       
  3588 // Set video length (max or short)
       
  3589 // ---------------------------------------------------------------------------
       
  3590 //
       
  3591 void CCamAppController::SetVideoLengthL( TInt /*aLength*/ )
       
  3592     {
       
  3593     PRINT( _L( "Camera => CCamAppController::SetVideoLengthL" ) );
       
  3594     User::Leave( KErrNotSupported );
       
  3595     }
       
  3596 
       
  3597 // ---------------------------------------------------------------------------
       
  3598 // CCamAppController::CurrentPhotoStorageLocation
       
  3599 // Returns the current photo storage location filtered by MMC presence
       
  3600 // ---------------------------------------------------------------------------
       
  3601 TInt CCamAppController::CurrentPhotoStorageLocation() const
       
  3602   {
       
  3603   TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  3604   
       
  3605   // added iForceUseOfPhoneMemory part to treat current location 
       
  3606   // as Mass Storage / Phone, also if it is forced.
       
  3607   if (  iForceUseOfPhoneMemory ||  
       
  3608         ( ( storageLocation == ECamMediaStorageCard ) &&
       
  3609           ( CamUtility::MemoryCardStatus() != ECamMemoryCardInserted ) ) )
       
  3610     {
       
  3611     if ( ExistMassStorage() )
       
  3612       {
       
  3613       storageLocation = ECamMediaStorageMassStorage;
       
  3614       }
       
  3615     else
       
  3616       {
       
  3617       storageLocation = IntegerSettingValue( ECamSettingItemRemovePhoneMemoryUsage)? 
       
  3618                           ECamMediaStorageNone:
       
  3619                           ECamMediaStoragePhone;
       
  3620       }
       
  3621     }
       
  3622   return storageLocation;
       
  3623   }
       
  3624 
       
  3625 // ---------------------------------------------------------------------------
       
  3626 // CCamAppController::CurrentVideoStorageLocation
       
  3627 // Returns the current video storage location filtered by MMC presence
       
  3628 // ---------------------------------------------------------------------------
       
  3629 TInt CCamAppController::CurrentVideoStorageLocation() const
       
  3630 	{
       
  3631 	TInt storageLocation = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoMediaStorage );        
       
  3632 
       
  3633 	// added iForceUseOfPhoneMemory part to treat current location 
       
  3634 	// as Mass Storage / Phone, also if it is forced.
       
  3635 	
       
  3636   if ( iForceUseOfPhoneMemory )
       
  3637     {
       
  3638     storageLocation = iForcedStorageLocation;
       
  3639     }
       
  3640   return storageLocation;
       
  3641   }
       
  3642 
       
  3643 
       
  3644 
       
  3645 // ---------------------------------------------------------------------------
       
  3646 // CCamAppController::ReleaseArray
       
  3647 // Record that the view has finished with the array
       
  3648 // ---------------------------------------------------------------------------
       
  3649 //
       
  3650 void CCamAppController::ReleaseArray( TBool aForcedRelease )
       
  3651   {
       
  3652   PRINT( _L("Camera => CCamAppController::ReleaseArray") );
       
  3653   // Otherwise  we were using the real capture array, so reset it
       
  3654   if( iArrayUsageCount > 0 )
       
  3655       {
       
  3656       iArrayUsageCount--;
       
  3657       }
       
  3658 
       
  3659   if ( iArrayUsageCount == 0 || aForcedRelease )
       
  3660       {
       
  3661       PRINT( _L("Camere <> CCamAppController::ReleaseArray .. usage to 0") );
       
  3662       iCaptureArray->Reset();
       
  3663       iCurrentImageIndex = 0;
       
  3664       // May have released a large amount of memory, so compress the heap
       
  3665       User::Heap().Compress();
       
  3666       }        
       
  3667 
       
  3668   PRINT( _L("Camera <= CCamAppController::ReleaseArray") );
       
  3669   }
       
  3670 
       
  3671 // ---------------------------------------------------------------------------
       
  3672 // CCamAppController::RestoreFactorySettingsL
       
  3673 // Delete 
       
  3674 // ---------------------------------------------------------------------------
       
  3675 //    
       
  3676 void CCamAppController::RestoreFactorySettingsL( TBool aIsEmbedded )
       
  3677   {          
       
  3678   PRINT( _L("Camera => CCamAppController::RestoreFactorySettingsL") );
       
  3679   iSettingsModel->ResetRepository();
       
  3680     
       
  3681   // reload static settings
       
  3682   LoadStaticSettingsL( aIsEmbedded );
       
  3683   
       
  3684   // reload dynamic settings
       
  3685   SetDynamicSettingsToDefaults();
       
  3686   
       
  3687   // Restoring camera settings didn't set the capture mode to single capture, 
       
  3688   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  3689   appUi->SwitchStillCaptureModeL( ECamImageCaptureSingle, EFalse, EFalse );
       
  3690   //
       
  3691   SetMode( ECamControllerIdle );  
       
  3692       
       
  3693   if( iLocationTrailStarted &&
       
  3694       ECamLocationOn != IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  3695     {    
       
  3696     PRINT( _L("Camera <> CCamAppController::RestoreFactorySettingsL - Stop location trail") );
       
  3697     // Location trail has been started, but setting off after restore -> stop trail
       
  3698     // Starting (if needed after restore) happens when still precap view is activated
       
  3699     StopLocationTrail();
       
  3700     }
       
  3701         
       
  3702   //
       
  3703   NotifyControllerObservers( ECamEventRestoreCameraSettings );
       
  3704   PRINT( _L("Camera <= CCamAppController::RestoreFactorySettingsL") );
       
  3705   }
       
  3706 
       
  3707 
       
  3708 
       
  3709 
       
  3710 // ---------------------------------------------------------------------------
       
  3711 // PlayComplete
       
  3712 //
       
  3713 // Called from when sound playing completes.
       
  3714 // ---------------------------------------------------------------------------
       
  3715 //
       
  3716 void 
       
  3717 CCamAppController::PlayComplete( TInt /*aStatus*/, TInt /*aSoundId*/ )
       
  3718   {
       
  3719   PlaySoundComplete();
       
  3720   }
       
  3721 
       
  3722 // ---------------------------------------------------------------------------
       
  3723 // CCamAppController::PlaySoundComplete
       
  3724 // Called when playback of a sound has completed.  Typically used in conjunction
       
  3725 // with Video recording (must only start recording AFTER sound has finished
       
  3726 // to avoid recording the sound in the recorded clip).
       
  3727 // ---------------------------------------------------------------------------
       
  3728 //
       
  3729 void CCamAppController::PlaySoundComplete()
       
  3730   {
       
  3731   PRINT( _L("Camera => CCamAppController::PlaySoundComplete") );
       
  3732   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_PLAYSOUNDCOMPLETE, "e_CAM_APP_CAPTURE_SOUND_PLAY 0" );    //CCORAPP_CAPTURE_SOUND_PLAY_END
       
  3733   
       
  3734   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  3735   if( ECamControllerVideo == iInfo.iMode && !IsKeyLockOn() )
       
  3736     {
       
  3737     switch( CurrentVideoOperation() )
       
  3738       {
       
  3739       case ECamResuming:
       
  3740         {
       
  3741         // Restarting video
       
  3742         DoRecord();
       
  3743         break;
       
  3744         }
       
  3745       case ECamPausing:
       
  3746         {
       
  3747         // Notifies observers, so paused icon and softkeys can be updated.
       
  3748         SetOperation( ECamPaused );
       
  3749         break;
       
  3750         }
       
  3751       case ECamNoOperation:
       
  3752         {
       
  3753         // Starting the video capture
       
  3754         // If the next file path has not changed, start capturing
       
  3755         if ( BurstCaptureArray()->FileName( 0 ).Compare( iSuggestedVideoPath ) == 0 )
       
  3756           {
       
  3757           PRINT( _L("Camera <> starting to record..") );
       
  3758           DoRecord();
       
  3759           }
       
  3760         // File path changed. Prepare the engine with the new video file path.
       
  3761         // Start video recording when filename changed (event)
       
  3762         else 
       
  3763           {
       
  3764           iVideoRequested = ETrue;
       
  3765           iSuggestedVideoPath.Copy( BurstCaptureArray()->FileName( 0 ) );
       
  3766           PRINT1( _L("Camera <> Requesting Camera controller to set the video name, iSuggestedVideoPath = [%S] "), &iSuggestedVideoPath );          
       
  3767           TRAP_IGNORE(
       
  3768             {
       
  3769             // Set video name change pending and request setting it to camera controller.
       
  3770             iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  3771             IssueSettingsChangeRequestL();
       
  3772             });
       
  3773           iVideoNameRetries = KVideoNameRetryCount;
       
  3774           }      
       
  3775         }
       
  3776       default:
       
  3777         {
       
  3778         // No operation. 
       
  3779         // Should be stopping video
       
  3780         }
       
  3781       }
       
  3782     }
       
  3783   else
       
  3784     {
       
  3785     // Image mode or keylock on, no action
       
  3786     }
       
  3787   PRINT( _L("Camera <= CCamAppController::PlaySoundComplete") );
       
  3788   }
       
  3789 // ---------------------------------------------------------------------------
       
  3790 // CCamAppController::MediaFileChangedNotification
       
  3791 //Helper function for making notification about deleted files
       
  3792 // ---------------------------------------------------------------------------
       
  3793 //
       
  3794 void  
       
  3795 CCamAppController::MediaFileChangedNotification()
       
  3796   {
       
  3797   PRINT( _L("Camera => CCamAppController::MediaFileChangedNotification") );
       
  3798   NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3799   PRINT( _L("Camera <= CCamAppController::MediaFileChangedNotification") );
       
  3800   }
       
  3801 
       
  3802 
       
  3803 // ---------------------------------------------------------------------------
       
  3804 // CCamAppController::DeleteCurrentFile
       
  3805 // Delete the current image/video file
       
  3806 // ---------------------------------------------------------------------------
       
  3807 //
       
  3808 TInt 
       
  3809 CCamAppController::DeleteCurrentFile( TBool aNotify /*=ETrue*/ )
       
  3810   {
       
  3811   PRINT( _L("Camera => CCamAppController::DeleteCurrentFile") );
       
  3812   iImageSaveRequestPending = EFalse;
       
  3813 
       
  3814   TInt err( KErrNone );
       
  3815   if( BurstCaptureArray()->Count() > 0 )
       
  3816     {
       
  3817     err = BurstCaptureArray()->SetDeleted( iCurrentImageIndex, ETrue );
       
  3818     if ( aNotify && err == KErrNone )
       
  3819       {
       
  3820       NotifyControllerObservers( ECamEventMediaFileChanged );
       
  3821       }
       
  3822     }
       
  3823 
       
  3824   PRINT( _L("Camera <= CCamAppController::DeleteCurrentFile") );
       
  3825   return err;
       
  3826   }
       
  3827 
       
  3828 // ---------------------------------------------------------------------------
       
  3829 // CCamAppController::DeleteTimeLapseFiles
       
  3830 // Delete the current timelapse sequence
       
  3831 // ---------------------------------------------------------------------------
       
  3832 //
       
  3833 void 
       
  3834 CCamAppController::DeleteTimeLapseFiles()    
       
  3835   {
       
  3836   // Count() is inline
       
  3837   for ( TInt i = 0; i < iSequenceFilenameArray->Count(); i++ )
       
  3838     {
       
  3839     TPtrC filename( iSequenceFilenameArray->MdcaPoint( i ) );
       
  3840     // Error ignored
       
  3841     (void)iImageSaveActive->DeleteFile( filename, ETrue );
       
  3842     }
       
  3843   iSequenceFilenameArray->Reset();        
       
  3844   }
       
  3845  
       
  3846 // ---------------------------------------------------------------------------
       
  3847 // CCamAppController::IsProcessingCapture
       
  3848 // Indicate whether or not the controller is actively engaged in still
       
  3849 // or video capture
       
  3850 // ---------------------------------------------------------------------------
       
  3851 //   
       
  3852 
       
  3853 TBool CCamAppController::IsProcessingCapture()
       
  3854     {
       
  3855     return ( iCaptureRequested  // if a still capture is pending
       
  3856           || iVideoRequested    // if a video capture is pending                            
       
  3857           || EngineProcessingCapture() // if recording or capture is active
       
  3858           || ECamImageCaptureTimeLapse == iInfo.iImageMode  // if capturing time lapse
       
  3859           || CurrentlySavingVideo() );        // if a video save is in progress  
       
  3860     }
       
  3861   
       
  3862 // ---------------------------------------------------------------------------
       
  3863 // CCamAppController::CompleteCaptureAndNotifyL
       
  3864 // Request that any current processes complete, then notify observers
       
  3865 // ---------------------------------------------------------------------------
       
  3866 //   
       
  3867 void 
       
  3868 CCamAppController::CompleteCaptureAndNotifyL( MCamObserver* aObserver, 
       
  3869                                               TBool         aSafeCompletion )    
       
  3870   {
       
  3871   PRINT( _L( "Camera => CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3872   
       
  3873   RProperty::Set( KPSUidCamcorderNotifier, KCCorFocused, 0 );
       
  3874     
       
  3875   // Add the observer to the observer handler for capture completion.
       
  3876   if ( !iCaptureCompletionObserverHandler )
       
  3877     {
       
  3878     iCaptureCompletionObserverHandler = CCamObserverHandler::NewL();
       
  3879     }
       
  3880   iCaptureCompletionObserverHandler->RegisterObserverL( aObserver );
       
  3881     
       
  3882   // if the capture has not yet begun, all that is required is to switch off
       
  3883   // the pending capture
       
  3884   iCaptureRequested = EFalse;
       
  3885   iVideoRequested   = EFalse;
       
  3886                
       
  3887   // if no capture is actively in progress
       
  3888   if ( !IsProcessingCapture() )
       
  3889     {
       
  3890     PRINT( _L( "Camera <> not capturing calling HandleCaptureCompletion" ) )
       
  3891     HandleCaptureCompletion();
       
  3892     }
       
  3893 
       
  3894   // if recording is active
       
  3895   else if ( ECamControllerVideo == iInfo.iMode )
       
  3896     {
       
  3897     if( ECamCapturing == iInfo.iOperation
       
  3898      || ECamPausing   == iInfo.iOperation
       
  3899      || ECamPaused    == iInfo.iOperation
       
  3900      || ECamResuming  == iInfo.iOperation )
       
  3901       {
       
  3902       PRINT( _L( "Camera <> currently recording calling StopVideoRecording()" ) )
       
  3903       StopVideoRecording();
       
  3904       // iCaptureCompletionObserverHandler will be notified when the record completes
       
  3905       // in McaeoVideoRecordingComplete
       
  3906       }
       
  3907     }        
       
  3908   else if ( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  3909     {
       
  3910     PRINT( _L( "Camera <> Calling StopSequenceCapture" ) )
       
  3911     StopSequenceCaptureL();
       
  3912     // iCaptureCompletionObserverHandler will be notified when the 
       
  3913     // next image saving completes
       
  3914     }
       
  3915             
       
  3916   // if a burst capture is in early stages
       
  3917   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  3918     {
       
  3919     if( ECamCapturing == iInfo.iOperation )
       
  3920       {
       
  3921       if ( !aSafeCompletion )
       
  3922         {
       
  3923         //iEngine->CancelCaptureStill();
       
  3924         PRINT( _L( "Camera <> Safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3925         IssueDirectRequestL( ECamRequestImageCancel );
       
  3926         CompleteBurstOperation();
       
  3927         }
       
  3928       else
       
  3929         {
       
  3930         //iEngine->StopStillBurstCapture();
       
  3931         PRINT( _L( "Camera <> Not safe completion requested, currently capturing burst, issue ECamRequestImageCancel" ) )
       
  3932         IssueDirectRequestL( ECamRequestImageCancel );
       
  3933         // iCaptureCompletionObserverHandler will be notified when the 
       
  3934         // image saving completes
       
  3935         }
       
  3936       }
       
  3937     }
       
  3938   else // do nothing
       
  3939     {
       
  3940     PRINT( _L( "Camera <> currently waiting for capture completion" ) )
       
  3941     // e.g. iOperation == ECamCaptureCompleting
       
  3942     // iCaptureCompletionObserverHandler will be notified when the 
       
  3943     // image saving completes
       
  3944     
       
  3945     // e.g. CurrentlySavingVideo()
       
  3946     // iCaptureCompletionObserverHandler will be notified when the 
       
  3947     // video saving completes in McaeoVideoRecordingComplete
       
  3948     
       
  3949     // e.g. iOperation == ECamCaptureInProgress (single capture)
       
  3950     // iCaptureCompletionObserverHandler will be notified when the 
       
  3951     // image saving completes
       
  3952     }        
       
  3953   PRINT( _L( "Camera <= CCamAppController::CompleteCaptureAndNotifyL" ) )
       
  3954   }
       
  3955 
       
  3956 // ---------------------------------------------------------------------------
       
  3957 // CCamAppController::EnterShutdownMode
       
  3958 // Enter shutdown mode as the application is closing
       
  3959 // ---------------------------------------------------------------------------
       
  3960 //
       
  3961 void 
       
  3962 CCamAppController::EnterShutdownMode( TBool aImmediateShutdown )
       
  3963   {
       
  3964   PRINT1( _L( "Camera => CCamAppController::EnterShutdownMode( aImmediateShutdown=%d )"), aImmediateShutdown );
       
  3965   
       
  3966   DeRegisterHarverterClientEvents();  
       
  3967 
       
  3968   if ( !IsInShutdownMode() )
       
  3969     {
       
  3970     PRINT ( _L( "Camera <> CCamAppController::EnterShutdownMode: set target mode to ECamControllerShutdown..") );
       
  3971     SetTargetMode( ECamControllerShutdown );
       
  3972     }
       
  3973 
       
  3974   // if not close down straightaway (i.e. for embedded )
       
  3975   if ( !aImmediateShutdown )
       
  3976     {
       
  3977     // cancel any outstanding sound requests
       
  3978     // iSoundPlayer->CancelTonePlayer();
       
  3979     iSoundPlayer->CancelAllPlaying();
       
  3980     
       
  3981     TRAPD( err, CompleteCaptureAndNotifyL( this, EFalse ) )
       
  3982     if ( err )
       
  3983       {
       
  3984       NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  3985       }
       
  3986     }
       
  3987   else
       
  3988     {
       
  3989     // This checks for any ongoing operation.
       
  3990     ReleaseCamera();
       
  3991     }
       
  3992 
       
  3993   PRINT ( _L( "Camera <= CCamAppController::EnterShutdownMode") );
       
  3994   }
       
  3995 
       
  3996 // ---------------------------------------------------------------------------
       
  3997 // CCamAppController::IsInShutdownMode
       
  3998 // Whether or not the controller is in shutdown mode
       
  3999 // ---------------------------------------------------------------------------
       
  4000 //
       
  4001 TBool CCamAppController::IsInShutdownMode() const
       
  4002     {
       
  4003     return ( ECamControllerShutdown == iInfo.iTargetMode );
       
  4004     }
       
  4005 
       
  4006 
       
  4007 // ---------------------------------------------------------------------------
       
  4008 // CCamAppController::IsAppUiAvailable
       
  4009 // Returns true if AppUi has been constructed, and not yet destructed
       
  4010 // ---------------------------------------------------------------------------
       
  4011 //
       
  4012 TBool CCamAppController::IsAppUiAvailable() const
       
  4013     {
       
  4014     PRINT1(_L("Camera <> CCamAppController::IsAppUiAvailable=%d"),iAppUiAvailable);
       
  4015     return iAppUiAvailable;
       
  4016     }       
       
  4017     
       
  4018 // ---------------------------------------------------------------------------
       
  4019 // CCamAppController::SetAppUiAvailable
       
  4020 // Sets AppUi availablility (see IsAppUiAvailable)
       
  4021 // ---------------------------------------------------------------------------
       
  4022 //    
       
  4023 void CCamAppController::SetAppUiAvailable( TBool aAvailable )
       
  4024     {
       
  4025     iAppUiAvailable = aAvailable;  
       
  4026     }
       
  4027 
       
  4028 
       
  4029 // ---------------------------------------------------------------------------
       
  4030 // CCamAppController::GetZoomRange
       
  4031 // Returns the minimum and maximum supported zoom values
       
  4032 // ---------------------------------------------------------------------------
       
  4033 //
       
  4034 void 
       
  4035 CCamAppController::GetZoomRange( TInt& aMinZoom, TInt& aMaxZoom ) const
       
  4036   {
       
  4037   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  4038   aMinZoom = 0;
       
  4039   aMaxZoom = iCameraController->CameraInfo().iMaxDigitalZoom;
       
  4040   }
       
  4041 
       
  4042 // ---------------------------------------------------------------------------
       
  4043 // CCamAppController::ZoomValue
       
  4044 // Returns the current zoom value
       
  4045 // ---------------------------------------------------------------------------
       
  4046 //
       
  4047 TInt 
       
  4048 CCamAppController::ZoomValue() const
       
  4049   {       
       
  4050   return iDesiredZoomVal;
       
  4051   }
       
  4052 
       
  4053 // ---------------------------------------------------------------------------
       
  4054 // CCamAppController::SetZoomValue
       
  4055 // Sets a new zoom value
       
  4056 // ---------------------------------------------------------------------------
       
  4057 //
       
  4058 void CCamAppController::SetZoomValue( TInt aValue )
       
  4059   {
       
  4060   PRINT1( _L("Camera => CCamAppController::SetZoomValue( %d )"), aValue );
       
  4061   __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  4062 
       
  4063   // Check the requested value for validity
       
  4064   __ASSERT_DEBUG( Rng( 0, aValue, iCameraController->CameraInfo().iMaxDigitalZoom ), 
       
  4065                   CamPanic( ECamPanicInvalidZoomValue ) );
       
  4066   
       
  4067   if ( ECamControllerImage == iInfo.iMode
       
  4068     || ECamControllerVideo == iInfo.iMode )
       
  4069     {
       
  4070     // Setting provider asks for the zoom value from us
       
  4071     iDesiredZoomVal = aValue;
       
  4072 
       
  4073     if ( !iZoomWaitingForCamera )
       
  4074       {
       
  4075       PRINT( _L("Camera <> CCamAppController: calling Camera Controller..") );
       
  4076       
       
  4077       TRAPD( error,
       
  4078         {
       
  4079         iCameraController->DirectSettingsChangeL( ECameraSettingDigitalZoom );
       
  4080         });
       
  4081 
       
  4082       // If no leave occurred, notification is done in HandleSettingEventL
       
  4083       if( KErrNone != error )
       
  4084         {
       
  4085         NotifyControllerObservers( ECamEventZoomStateChanged, error );
       
  4086         }
       
  4087 
       
  4088       // iZoomWaitingForCamera is set to EFalse when vf frame arrives.
       
  4089       // With direct vf, this never happens, so do not set to ETrue.
       
  4090       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4091       if ( appUi && !appUi->IsDirectViewfinderActive() )
       
  4092         {
       
  4093         iZoomWaitingForCamera = ETrue;
       
  4094         }
       
  4095       iNewZoomPending = EFalse;
       
  4096       }
       
  4097     else
       
  4098       {
       
  4099       PRINT( _L("Camera <> CCamAppController: zoom is waiting for VF update") );
       
  4100       iNewZoomPending = ETrue;
       
  4101       }
       
  4102     }
       
  4103   PRINT( _L("Camera <= CCamAppController::SetZoomValue") );
       
  4104   }
       
  4105 
       
  4106 
       
  4107 
       
  4108 // ---------------------------------------------------------------------------
       
  4109 // CCamAppController::ResetUserSceneL
       
  4110 // Resets all the user scene settings to their defaults.
       
  4111 // ---------------------------------------------------------------------------
       
  4112 //
       
  4113 void CCamAppController::ResetUserSceneL()
       
  4114     {
       
  4115     iSettingsModel->ResetUserSceneL();
       
  4116     }
       
  4117 
       
  4118 // ---------------------------------------------------------------------------
       
  4119 // CCamAppController::PreviewSettingChangeL
       
  4120 // 
       
  4121 // Previews a new value for the specified integer setting.
       
  4122 // If method leaves, preview is not activated.
       
  4123 // ---------------------------------------------------------------------------
       
  4124 //
       
  4125 void 
       
  4126 CCamAppController::PreviewSettingChangeL( TInt aSettingItem, 
       
  4127                                           TInt aSettingValue )
       
  4128   {
       
  4129   PRINT( _L("Camera => CCamAppController::PreviewSettingChangeL") );
       
  4130   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4131   
       
  4132   TCamSettingItemIds settingId( 
       
  4133       static_cast<TCamSettingItemIds>(aSettingItem) );
       
  4134 
       
  4135   PRINT1( _L("Camera <> Setting to be previewed [%s]"), KCamSettingItemNames[settingId] );
       
  4136 
       
  4137   if ( settingId == ECamSettingItemDynamicSelfTimer )
       
  4138       {
       
  4139       SetSlideInSelfTimerPreview(ETrue);
       
  4140       }
       
  4141 
       
  4142   // Activate the preview as a first thing.
       
  4143   // If requests are issued to Camera Controller,
       
  4144   // it asks for the setting value through Setting Provider and
       
  4145   // the setting needs to be already in preview at that point.
       
  4146   // If this fails, there's nothing we need to roll back.
       
  4147   iSettingsPreviewHandler->ActivatePreviewL( settingId, aSettingValue );
       
  4148 
       
  4149 
       
  4150   // Check which setting is previewed.
       
  4151   // Some need special attention, or should/need not be set to Camera at this point.
       
  4152   TInt status( KErrNone );
       
  4153   switch( settingId )
       
  4154     {
       
  4155     // ---------------------------------
       
  4156     // Image quality
       
  4157     case ECamSettingItemPhotoQuality:
       
  4158       // Still image quality does not require re-prepare,
       
  4159       // as even the remining images counting is done 
       
  4160       // based on local size esimates.
       
  4161       // Need to do notification to update counters.
       
  4162       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4163       break;
       
  4164     // ---------------------------------
       
  4165     // Video quality
       
  4166     case ECamSettingItemVideoQuality:
       
  4167       // Video needs to be re-prepared to be able to update
       
  4168       // remaining time counters.
       
  4169       NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4170       break;
       
  4171     // ---------------------------------
       
  4172     // Self timer
       
  4173     case ECamSettingItemDynamicSelfTimer:
       
  4174       // Just set the preview. Once committed, set via AppUi.
       
  4175       break;
       
  4176     // ---------------------------------
       
  4177     // Others - set to Camera to see the effect.
       
  4178     default:
       
  4179       {
       
  4180       TCamCameraSettingId cameraId( 
       
  4181         CCamSettingConversion::Map2CameraControllerSettingId( settingId ) );
       
  4182 
       
  4183       //PRINT1( _L("Camera <> CCamAppController: Setting the preview to Camera, id[%s]"), KCameraSettingNames[settingId] );
       
  4184 
       
  4185       // Assertation to notice if some setting is not properly handled.
       
  4186       __ASSERT_DEBUG( ECameraSettingNone != cameraId, CamPanic( ECamPanicNotSupported ) );
       
  4187       
       
  4188       if( ECameraSettingNone != cameraId )
       
  4189         {
       
  4190         // Preview is active.
       
  4191         // Camera controller will ask the value during DirectSettingsChangeL.
       
  4192         // Need trap to be able to cancel on failure.
       
  4193         TRAP( status, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4194         }      
       
  4195       break;
       
  4196       }
       
  4197     // ---------------------------------
       
  4198     }
       
  4199 
       
  4200   if( KErrNone != status )
       
  4201     {
       
  4202     PRINT( _L("Camera <> CCamAppController: Problem in preview, cancelling!!!") );     
       
  4203 
       
  4204     // Invalid id does not cause problem here.
       
  4205     iSettingsPreviewHandler->CancelPreview( settingId );
       
  4206     User::Leave( status );
       
  4207     }
       
  4208   PRINT( _L("Camera <= CCamAppController::PreviewSettingChangeL") );
       
  4209   }
       
  4210 
       
  4211 // ---------------------------------------------------------------------------
       
  4212 // CCamAppController::CancelPreviewChangesL
       
  4213 // Cancels all preview changes, since last commit/cancel.
       
  4214 // ---------------------------------------------------------------------------
       
  4215 //
       
  4216 void
       
  4217 CCamAppController::CancelPreviewChangesL()
       
  4218   {
       
  4219   PRINT( _L("Camera => CCamAppController::CancelPreviewChangesL") );
       
  4220 
       
  4221   // Just check non-null, but no panic. 
       
  4222   if ( iSettingsPreviewHandler )
       
  4223     {
       
  4224     RArray<TCamSettingItemIds> previews;
       
  4225     CleanupClosePushL( previews );
       
  4226 
       
  4227     // Get all active previews
       
  4228     iSettingsPreviewHandler->ActivePreviewsL( previews );
       
  4229     // Reset all previews so the Setting Provider does
       
  4230     // not get those values anymore.
       
  4231     iSettingsPreviewHandler->CancelAllPreviews();
       
  4232 
       
  4233     // Reset the original setting values to Camera
       
  4234     TInt                errorOne( KErrNone           );
       
  4235     TInt                errorAll( KErrNone           );    
       
  4236     TCamCameraSettingId cameraId( ECameraSettingNone );
       
  4237     for( TInt i = previews.Count() - 1; i >= 0; i-- )
       
  4238       {
       
  4239       if( ECamSettingItemVideoQuality == previews[i] )
       
  4240         {
       
  4241         TRAP( errorOne, RePrepareVideoL() );
       
  4242         }
       
  4243       else
       
  4244         {
       
  4245         cameraId =
       
  4246           CCamSettingConversion::Map2CameraControllerSettingId( previews[i] );
       
  4247       
       
  4248         if( ECameraSettingNone != cameraId )
       
  4249           {
       
  4250           TRAP( errorOne, iCameraController->DirectSettingsChangeL( cameraId ) );
       
  4251           }
       
  4252         /* All previews are not set to Camera.
       
  4253         else
       
  4254           {
       
  4255           errorOne = KErrNotSupported;
       
  4256           }
       
  4257         */
       
  4258         }
       
  4259 
       
  4260       if( KErrNone == errorAll 
       
  4261        && KErrNone != errorOne )
       
  4262         {
       
  4263         errorAll = errorOne;
       
  4264         }
       
  4265       }
       
  4266     User::LeaveIfError( errorAll );
       
  4267 
       
  4268     CleanupStack::PopAndDestroy(); // previews
       
  4269     }
       
  4270   PRINT( _L("Camera <= CCamAppController::CancelPreviewChangesL") );
       
  4271   }
       
  4272 
       
  4273 // ---------------------------------------------------------------------------
       
  4274 // CCamAppController::CommitPreviewChanges
       
  4275 // Commits last preview change.
       
  4276 // ---------------------------------------------------------------------------
       
  4277 //
       
  4278 void 
       
  4279 CCamAppController::CommitPreviewChanges()
       
  4280   {
       
  4281   PRINT( _L("Camera => CCamAppController::CommitPreviewChanges") );
       
  4282   __ASSERT_DEBUG( iSettingsPreviewHandler, CamPanic( ECamPanicNullPointer ) );
       
  4283 
       
  4284   // All previews have been set to Camera already.
       
  4285   // Only need to request the model to store new values.
       
  4286   // Currently ignore error, if settings model cannot save the preview.
       
  4287   TRAPD( error, iSettingsPreviewHandler->CommitAllPreviewsL() );
       
  4288   if( KErrNone != error )
       
  4289     {
       
  4290     // Ignored.
       
  4291     PRINT( _L("Camera <> Settings model could not save the preview!!!") );
       
  4292     }
       
  4293   PRINT( _L("Camera <= CCamAppController::CommitPreviewChanges") );
       
  4294   }
       
  4295 
       
  4296 
       
  4297 // ---------------------------------------------------------------------------
       
  4298 // RePrepareVideoL
       
  4299 //
       
  4300 // Helper method for re-preparing video if e.g. a setting change
       
  4301 // requires it. If Camera Controller is currently processing
       
  4302 // some request, set the flag to issue the request later.
       
  4303 //
       
  4304 // Used atleast in PreviewSettingChangeL and CancelPreviewChangesL.
       
  4305 // ---------------------------------------------------------------------------
       
  4306 //
       
  4307 void
       
  4308 CCamAppController::RePrepareVideoL()
       
  4309   {
       
  4310   PRINT( _L("Camera => CCamAppController::RePrepareVideoL") );
       
  4311 
       
  4312   GenerateNextValidVideoPathL();
       
  4313   if( !Busy() )
       
  4314     {
       
  4315     iVideoPrepareNeeded = EFalse;
       
  4316     IssueRequestL( ECamRequestVideoInit );
       
  4317     }
       
  4318   else
       
  4319     {
       
  4320     iVideoPrepareNeeded = ETrue;
       
  4321     }
       
  4322   PRINT( _L("Camera <= CCamAppController::RePrepareVideoL") );
       
  4323   }
       
  4324 
       
  4325 
       
  4326 
       
  4327 // ---------------------------------------------------------------------------
       
  4328 // CCamAppController::IntegerSettingValue
       
  4329 // Returns the current integer value for the specified setting
       
  4330 // ---------------------------------------------------------------------------
       
  4331 //
       
  4332 TInt 
       
  4333 CCamAppController::IntegerSettingValue( TInt aSettingItem ) const
       
  4334   {
       
  4335   // If the requested item is the photo storage location, this must be filtered
       
  4336   // based on the availability of the MMC.
       
  4337   if ( aSettingItem == ECamSettingItemPhotoMediaStorage )
       
  4338     {
       
  4339     return CurrentPhotoStorageLocation();
       
  4340     }
       
  4341 
       
  4342   // If the requested item is the video storage location, this must be filtered
       
  4343   // based on the availability of the MMC.
       
  4344   if ( aSettingItem == ECamSettingItemVideoMediaStorage )
       
  4345     {
       
  4346     return CurrentVideoStorageLocation();
       
  4347     }
       
  4348 
       
  4349   // Not a setting we sometimes need to filter
       
  4350   return IntegerSettingValueUnfiltered( aSettingItem );
       
  4351   }
       
  4352 
       
  4353 // ---------------------------------------------------------------------------
       
  4354 // CCamAppController::IntegerSettingValueUnfiltered
       
  4355 // Returns the current integer value for the specified setting
       
  4356 // ---------------------------------------------------------------------------
       
  4357 //
       
  4358 TInt 
       
  4359 CCamAppController::IntegerSettingValueUnfiltered( TInt aSettingItem ) const
       
  4360   {
       
  4361   if( aSettingItem == ECamSettingItemVideoFileType )
       
  4362     {
       
  4363     TInt videoQuality = iSettingsModel->IntegerSettingValue( ECamSettingItemVideoQuality );
       
  4364   
       
  4365     CCamVideoQualityLevel& level = *( iSettingsModel->VideoQualityArray() )[videoQuality];
       
  4366   
       
  4367     return level.VideoType();
       
  4368     }
       
  4369   // Query the relevant settings model.
       
  4370   return iSettingsModel->IntegerSettingValue( aSettingItem );
       
  4371   }
       
  4372 
       
  4373 // ---------------------------------------------------------------------------
       
  4374 // CCamAppController::SetIntegerSettingValueL
       
  4375 // Sets a new value for the specified integer setting
       
  4376 // ---------------------------------------------------------------------------
       
  4377 //
       
  4378 void 
       
  4379 CCamAppController::SetIntegerSettingValueL( TInt aSettingItem, 
       
  4380                                             TInt aSettingValue )
       
  4381   {
       
  4382   PRINT( _L("Camera => CCamAppController::SetIntegerSettingValueL"))
       
  4383   // Update the settings model.
       
  4384   iSettingsModel->SetIntegerSettingValueL( aSettingItem, aSettingValue );
       
  4385 
       
  4386   // Update observers with any changes that do not directly affect the
       
  4387   // engine. That is, they need to be updated now because the settings model
       
  4388   // will not pass these to this observer.
       
  4389   switch( aSettingItem )
       
  4390     {
       
  4391     case ECamSettingItemPhotoMediaStorage:
       
  4392     case ECamSettingItemVideoMediaStorage:
       
  4393       {
       
  4394       PRINT1(_L("Camera SetIntegerSettingValueL calling SetPathnamesToNewStorageL %d" ), aSettingValue);
       
  4395       // reset iForceUseOfPhoneMemory flag when user chooses 
       
  4396       // from settings.
       
  4397       iForceUseOfPhoneMemory = EFalse;
       
  4398       SetPathnamesToNewStorageL(static_cast < TCamMediaStorage > ( aSettingValue ) );
       
  4399       InitCaptureLimitL();
       
  4400       break;
       
  4401       }
       
  4402     case ECamSettingItemDynamicVideoScene:
       
  4403       {
       
  4404       iVideoInitNeeded = ETrue;
       
  4405       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4406       break;
       
  4407       }
       
  4408     case ECamSettingItemDynamicPhotoScene:
       
  4409     case ECamSettingItemUserSceneBasedOnScene:
       
  4410       {
       
  4411       if( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  4412         {
       
  4413         // Check for macro or landscape scene/based on scene and
       
  4414         // set up AF accordingly. For other scenes, the AF mode
       
  4415         // is setup at capture
       
  4416         CheckAfModeForScene();
       
  4417         }
       
  4418       NotifyControllerObservers( ECamEventSceneStateChanged );
       
  4419       break;
       
  4420       }
       
  4421     case ECamSettingItemVideoAudioRec:
       
  4422       {
       
  4423       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  4424       if ( appUi->IsEmbedded() )
       
  4425         {
       
  4426         iCameraController->DirectSettingsChangeL( ECameraSettingAudioMute );
       
  4427         }
       
  4428       NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4429       break;
       
  4430       }
       
  4431     case ECamSettingItemContinuousAutofocus:
       
  4432       {
       
  4433       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemContinuousAutofocus );
       
  4434       IssueSettingsChangeRequestL();
       
  4435       break;
       
  4436       }
       
  4437     case ECamSettingItemPhotoStoreInAlbum:
       
  4438     case ECamSettingItemVideoStoreInAlbum:
       
  4439       {
       
  4440       TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4441               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4442 
       
  4443       iImageSaveActive->SetAddImageToAlbum( aSettingValue == ECamSettYes,
       
  4444                                             defaultAlbumId );
       
  4445       break;
       
  4446       }
       
  4447     case ECamSettingItemRecLocation:
       
  4448       {
       
  4449       // Set the location utility active object
       
  4450       if ( ECamLocationOff == aSettingValue )
       
  4451           {
       
  4452           StopLocationTrail();
       
  4453           }
       
  4454       else if ( ECamLocationOn == aSettingValue )
       
  4455           {
       
  4456           StartLocationTrailL();
       
  4457           }
       
  4458       
       
  4459       // Notify observers
       
  4460       NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4461       break;  
       
  4462       }
       
  4463     // Need to support more zoom settings.
       
  4464     // Digital/extended setting combined to 
       
  4465     // ECamSettingItemPhotoDigitalZoom and ECamSettingItemVideoDigitalZoom
       
  4466     case ECamSettingItemPhotoDigitalZoom:
       
  4467     case ECamSettingItemVideoDigitalZoom:
       
  4468       {
       
  4469       // Notify observers
       
  4470       NotifyControllerObservers( ECamEventZoomSetupChanged );
       
  4471       break;
       
  4472       }
       
  4473 
       
  4474     default:
       
  4475       {
       
  4476       // no action for others here
       
  4477       break;
       
  4478       }
       
  4479     }
       
  4480 
       
  4481   PRINT( _L("Camera <= CCamAppController::SetIntegerSettingValueL"))        
       
  4482   }
       
  4483 
       
  4484 
       
  4485 
       
  4486 // ---------------------------------------------------------------------------
       
  4487 // CCamAppController::SetPathnamesToNewStorageL
       
  4488 // Sets pathnames for video and image files to point to new storage
       
  4489 // ---------------------------------------------------------------------------
       
  4490 void CCamAppController::SetPathnamesToNewStorageL( TCamMediaStorage aMediaStorage )
       
  4491   {    
       
  4492   PRINT(_L("Camera => CCamAppController::SetPathnamesToNewStorageL" ))
       
  4493   
       
  4494   iSetNewPathnamesPending = ECamMediaStorageNone;
       
  4495   TFileName path;
       
  4496   
       
  4497   // If the engine is prepared for image capture then check that the required 
       
  4498   // image folder exists
       
  4499   if ( IsFlagOn( CameraControllerState(), ECamImageOn ) )
       
  4500     {
       
  4501     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4502                                      aMediaStorage, 
       
  4503                                      path, 
       
  4504                                      ECamControllerImage, 
       
  4505                                      EFalse ); 
       
  4506     iCurrentStorage = aMediaStorage;
       
  4507     }
       
  4508    
       
  4509   // If the engine is prepared for video capture then check that the required 
       
  4510   // month folder exists and set up the engine with the new video path, this
       
  4511   // will be adjusted with the appropriate month counter folder when video
       
  4512   // capture begins
       
  4513   else if ( IsFlagOn( CameraControllerState(), ECamVideoOn ) )
       
  4514     {
       
  4515     CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  4516                                      aMediaStorage, 
       
  4517                                      path, 
       
  4518                                      ECamControllerVideo, 
       
  4519                                      EFalse ); 
       
  4520      if( iInfo.iOperation != ECamCapturing    &&
       
  4521           iInfo.iOperation != ECamPausing      &&
       
  4522           iInfo.iOperation != ECamPaused       &&
       
  4523           iInfo.iOperation != ECamResuming   &&
       
  4524           iInfo.iOperation != ECamCompleting )
       
  4525       {
       
  4526        GenerateNextValidVideoPathL();
       
  4527       }
       
  4528     iCurrentStorage = aMediaStorage;
       
  4529     
       
  4530     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  4531     
       
  4532     if( !appUi->SettingsLaunchedFromCamera() )
       
  4533       {
       
  4534       // Set video name change pending and request setting it to camera controller.
       
  4535       if( iInfo.iOperation != ECamCapturing    &&
       
  4536           iInfo.iOperation != ECamPausing      &&
       
  4537           iInfo.iOperation != ECamPaused       &&
       
  4538           iInfo.iOperation != ECamResuming   &&
       
  4539           iInfo.iOperation != ECamCompleting )
       
  4540     	{
       
  4541         iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );
       
  4542         // Can't set the new pathname, if camera controller is busy.
       
  4543         if ( CameraControllerBusy() )
       
  4544           {
       
  4545           PRINT( _L("Camera <> Camera controller busy. New pathname not set. Set iSetNewPathnamesPending.") )
       
  4546           iSetNewPathnamesPending = aMediaStorage;
       
  4547           }
       
  4548         else
       
  4549           {
       
  4550           IssueSettingsChangeRequestL();
       
  4551           }
       
  4552     	}
       
  4553         
       
  4554       iVideoNameRetries   = KVideoNameRetryCount;    
       
  4555       //iVideoTimeRemaining = KMaxRecordingLength;
       
  4556       if( iInfo.iOperation == ECamCapturing    ||
       
  4557           iInfo.iOperation == ECamPausing      ||
       
  4558           iInfo.iOperation == ECamPaused       ||
       
  4559           iInfo.iOperation == ECamResuming     ||
       
  4560           iInfo.iOperation == ECamCompleting )
       
  4561         {          
       
  4562         iVideoTimeRemaining = RemainingVideoRecordingTime();  
       
  4563         }
       
  4564       else 
       
  4565         {
       
  4566         PRINT( _L("Camera <> CCamAppController::SetPathnamesToNewStorageL - video mode not yet initialized" ));
       
  4567         TRAPD( err, iVideoTimeRemaining = CalculateVideoTimeRemainingL() );
       
  4568         if( KErrNone != err )
       
  4569           {
       
  4570           iVideoTimeRemaining = 0;
       
  4571           }
       
  4572         }
       
  4573       }
       
  4574     }
       
  4575     
       
  4576   // The engine is not yet prepared, the folder will be checked when the engine preparation
       
  4577   // takes place. The controller also checks the state of iSetNewPathnamesPending when 
       
  4578   // preparation completes, just in case preparation is currently in progress.
       
  4579   else
       
  4580     {
       
  4581     iSetNewPathnamesPending = aMediaStorage;
       
  4582     }  
       
  4583               
       
  4584   NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4585   PRINT(_L("Camera <= CCamAppController::SetPathnamesToNewStorageL" ))
       
  4586   }
       
  4587 
       
  4588 // ---------------------------------------------------------------------------
       
  4589 // CCamAppController::SetTextSettingValueL
       
  4590 // Sets a new text value for the specified setting
       
  4591 // ---------------------------------------------------------------------------
       
  4592 //
       
  4593 void 
       
  4594 CCamAppController::SetTextSettingValueL(       TInt   aSettingItem, 
       
  4595                                          const TDesC& aSettingValue )
       
  4596   {
       
  4597   // Update the relevant settings model.
       
  4598   iSettingsModel->SetTextSettingValueL( aSettingItem, aSettingValue );
       
  4599   }
       
  4600 
       
  4601 
       
  4602 // ---------------------------------------------------------------------------
       
  4603 // CCamAppController::TextSettingValue
       
  4604 // Returns the current text value for the specified setting
       
  4605 // ---------------------------------------------------------------------------
       
  4606 //
       
  4607 TPtrC 
       
  4608 CCamAppController::TextSettingValue( TInt aSettingItem ) const
       
  4609   {
       
  4610   // Query the relevant settings model.
       
  4611   return iSettingsModel->TextSettingValue( aSettingItem );
       
  4612   }
       
  4613 
       
  4614 // ---------------------------------------------------------------------------
       
  4615 // CCamAppController::SettingValueEnabled
       
  4616 // Returns whether a particular setting value can be set or not.
       
  4617 // ---------------------------------------------------------------------------
       
  4618 //
       
  4619 TBool 
       
  4620 CCamAppController::SettingValueEnabled( TInt aSettingItem, 
       
  4621                                         TInt aSettingValue ) const 
       
  4622   {
       
  4623   return iSettingsModel->SettingValueEnabled( aSettingItem, aSettingValue );
       
  4624   }
       
  4625 
       
  4626 // ---------------------------------------------------------------------------
       
  4627 // CCamAppController::LoadStaticSettingsL
       
  4628 // Loads the static settings from shared data
       
  4629 // ---------------------------------------------------------------------------
       
  4630 //
       
  4631 void 
       
  4632 CCamAppController::LoadStaticSettingsL( TBool aIsEmbedded )
       
  4633   {
       
  4634   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 1" );
       
  4635   PRINT(_L("Camera => CCamAppController::LoadStaticSettingsL" ))
       
  4636   iSettingsModel->LoadStaticSettingsL( aIsEmbedded );
       
  4637   
       
  4638   // Cache the image 'add to album' setting in the saving active object
       
  4639   // it will change infrequently
       
  4640   TInt value = iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoStoreInAlbum );
       
  4641   
       
  4642   TUint32 defaultAlbumId = static_cast<TUint32>( 
       
  4643               IntegerSettingValue( ECamSettingItemDefaultAlbumId ));
       
  4644   iImageSaveActive->SetAddImageToAlbum( value == ECamSettYes,
       
  4645                                         defaultAlbumId );
       
  4646 
       
  4647   // Ensure that the navipane is upto date with the current save location.
       
  4648   if ( !aIsEmbedded )
       
  4649     {
       
  4650     NotifyControllerObservers( ECamEventAudioMuteStateChanged );
       
  4651     NotifyControllerObservers( ECamEventVideoQualityChanged );
       
  4652     }
       
  4653     NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  4654     NotifyControllerObservers( ECamEventVideoStabChanged );
       
  4655     if ( iConfigManager  && iConfigManager->IsLocationSupported() )
       
  4656         {
       
  4657         NotifyControllerObservers( ECamEventLocationSettingChanged );
       
  4658         }
       
  4659     NotifyControllerObservers( ECamEventVideoFileTypeChanged );
       
  4660   NotifyControllerObservers( ECamEventImageQualityChanged );
       
  4661   NotifyControllerObservers( ECamEventContAFStateChanged ); 
       
  4662   PRINT(_L("Camera <= CCamAppController::LoadStaticSettingsL" ))
       
  4663   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSTATICSETTINGSL, "e_CCamAppController_LoadStaticSettingsL 0" );
       
  4664   }
       
  4665 
       
  4666 
       
  4667 // ---------------------------------------------------------------------------
       
  4668 // DynamicSettingDefaultValue
       
  4669 // Get the setting default value.
       
  4670 // ---------------------------------------------------------------------------
       
  4671 //
       
  4672 TInt 
       
  4673 CCamAppController::DynamicSettingDefaultValue( TInt aSettingId ) const
       
  4674   {
       
  4675   return iSettingsModel->DynamicSettingDefaultValue( aSettingId );
       
  4676   }
       
  4677 
       
  4678 // ---------------------------------------------------------------------------
       
  4679 // CCamAppController::SetDynamicSettingsToDefaults
       
  4680 // Sets all dynamic settings to their defaults.
       
  4681 // ---------------------------------------------------------------------------
       
  4682 //
       
  4683 void 
       
  4684 CCamAppController::SetDynamicSettingsToDefaults()
       
  4685   {
       
  4686   iSettingsModel->SetDynamicSettingsToDefaults();
       
  4687   }
       
  4688 
       
  4689 // ---------------------------------------------------------------------------
       
  4690 // CCamAppController::SetDynamicSettingsToDefaults
       
  4691 // Sets a dynamic setting to its default.
       
  4692 // ---------------------------------------------------------------------------
       
  4693 //
       
  4694 void 
       
  4695 CCamAppController::SetDynamicSettingToDefault(TInt aSettingItem)
       
  4696   {
       
  4697   iSettingsModel->SetDynamicSettingToDefault(aSettingItem);
       
  4698   }
       
  4699 
       
  4700 // ---------------------------------------------------------------------------
       
  4701 // SetDynamicSettingToSceneDefaultL
       
  4702 // 
       
  4703 // Set the dynamic setting identified by aSettingId to scene default.
       
  4704 // Because video and photo scenes can have sama identifiers, aVideoScene
       
  4705 // is needed to decide which ones to look for.
       
  4706 // ---------------------------------------------------------------------------
       
  4707 //
       
  4708 TInt
       
  4709 CCamAppController::SetDynamicSettingToSceneDefaultL( TInt  aSceneId,
       
  4710                                                      TInt  aSceneField,
       
  4711                                                      TInt  aSettingId,
       
  4712                                                      TBool aVideoScene )
       
  4713   {
       
  4714   return iSettingsModel->SetDynamicSettingToSceneDefaultL( aSceneId, 
       
  4715                                                            aSceneField, 
       
  4716                                                            aSettingId,
       
  4717                                                            aVideoScene );
       
  4718   }
       
  4719 
       
  4720 
       
  4721 
       
  4722 
       
  4723 #ifdef PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4724 // ---------------------------------------------------------------------------
       
  4725 // CCamAppController::VideoSceneDefaultsAreSet
       
  4726 // Returns whether the video setup settings are set to the defaults
       
  4727 // for its current scene.
       
  4728 // ---------------------------------------------------------------------------
       
  4729 //
       
  4730 TBool 
       
  4731 CCamAppController::VideoSceneDefaultsAreSet()
       
  4732     {
       
  4733     return iSettingsModel->VideoSceneDefaultsAreSet();
       
  4734     }
       
  4735 
       
  4736 // ---------------------------------------------------------------------------
       
  4737 // CCamAppController::PhotoSceneDefaultsAreSet
       
  4738 // Returns whether the photo setup settings are set to the defaults
       
  4739 // for its current scene.
       
  4740 // ---------------------------------------------------------------------------
       
  4741 //
       
  4742 TBool 
       
  4743 CCamAppController::PhotoSceneDefaultsAreSet()
       
  4744     {
       
  4745     return iSettingsModel->PhotoSceneDefaultsAreSet();
       
  4746     }
       
  4747 
       
  4748 #endif // PRODUCT_USES_GENERIC_SETUP_INDICATOR
       
  4749 
       
  4750 
       
  4751 // ---------------------------------------------------------------------------
       
  4752 // CCamAppController::CurrentFullFileName
       
  4753 // ---------------------------------------------------------------------------
       
  4754 //
       
  4755 const TDesC& 
       
  4756 CCamAppController::CurrentFullFileName() const
       
  4757   {
       
  4758   PRINT1( _L("Camera => CCamAppController::CurrentFullFileName, index:%d"), iCurrentImageIndex );
       
  4759   const TDesC& name( BurstCaptureArray()->FileName( iCurrentImageIndex ) );
       
  4760 
       
  4761   if( name != KNullDesC )
       
  4762     {
       
  4763     PRINT1( _L("Camera <= CCamAppController::CurrentFullFileName, return:[%S]"), &name );
       
  4764     }
       
  4765   else
       
  4766     {
       
  4767     PRINT( _L("Camera <= CCamAppController::CurrentFullFileName, name not set.") ); 
       
  4768     }   
       
  4769   return name;
       
  4770   }
       
  4771 
       
  4772 const TDesC& 
       
  4773 CCamAppController::CurrentVideoFileName() const
       
  4774   {
       
  4775   return iSuggestedVideoPath;
       
  4776   }
       
  4777 
       
  4778 // ---------------------------------------------------------------------------
       
  4779 // CCamAppController::CCamAppController
       
  4780 // C++ default constructor can NOT contain any code, that
       
  4781 // might leave.
       
  4782 // ---------------------------------------------------------------------------
       
  4783 //
       
  4784 CCamAppController::CCamAppController()
       
  4785   : iBusyFlags( EBusyNone )
       
  4786   , iDiskCriticalLevel   ( KErrNotFound )
       
  4787   , iRamDiskCriticalLevel( KErrNotFound )
       
  4788   , iImageOrientation( ECamOrientation0 )
       
  4789   , iLastImageOrientation( ECamOrientation0 )
       
  4790   , iPendingHdmiEvent( ECamHdmiNoEvent )
       
  4791   {
       
  4792   }
       
  4793 
       
  4794 // ---------------------------------------------------------------------------
       
  4795 // CCamAppController::ConstructL
       
  4796 // Symbian 2nd phase constructor can leave.
       
  4797 // ---------------------------------------------------------------------------
       
  4798 //
       
  4799 void CCamAppController::ConstructL()
       
  4800   {
       
  4801   PRINT( _L("Camera => CCamAppController::ConstructL"));
       
  4802   iPendingAFRequest=0;
       
  4803   iCurrentAFRequest=0;
       
  4804   iNoBurstCancel=EFalse;
       
  4805 
       
  4806   PRINT( _L("Camera <> CCamAppController::ConstructL - constructing Configuration Manager"));
       
  4807   iConfiguration = CCamConfiguration::NewL();      
       
  4808   
       
  4809  
       
  4810   CCamFolderUtility::ResetCounters( iMonthFolderCounters );
       
  4811   iCaptureKeyPressedWhileImageSaving = EFalse;
       
  4812 
       
  4813   iCaptureModeTransitionInProgress = ETrue;
       
  4814 
       
  4815   iSettingsModel = CCamSettingsModel::NewL( *iConfiguration );  
       
  4816   iSettingsModel->AttachObserverL( this );
       
  4817   
       
  4818   // Get the config pointer from settings model
       
  4819   iConfigManager = static_cast<CCamSettingsModel*>(iSettingsModel)->UiConfigManagerPtr();
       
  4820   
       
  4821   RArray<TInt> supportedValues;
       
  4822   CleanupClosePushL( supportedValues );
       
  4823     
       
  4824   // Get the EV slider info
       
  4825   // these values should be read before camsettingsprovided is constructd
       
  4826   // as the EV step value is needed during the construction of camsettingsprovider.
       
  4827   iConfigManager->SupportedEVSettingsL( supportedValues );
       
  4828 
       
  4829   if ( supportedValues.Count() > 0 )
       
  4830       {
       
  4831       iEvRange.iMinValue     = supportedValues[0];
       
  4832       iEvRange.iMaxValue     = supportedValues[1];
       
  4833       iEvRange.iStepsPerUnit = supportedValues[2];      
       
  4834       }
       
  4835 
       
  4836   CleanupStack::PopAndDestroy( &supportedValues );
       
  4837     
       
  4838   // The Settings Model handles the previews at the moment
       
  4839   iSettingsPreviewHandler = static_cast<CCamSettingsModel*>( iSettingsModel ); 
       
  4840 
       
  4841   //iSettingProvider = CCamConstantSettingProvider::NewL( *this );
       
  4842   iSettingProvider = CCamSettingProvider::NewL( *this, iSettingsModel );
       
  4843  
       
  4844   iDeepSleepTimer = CCamTimer::NewL( KDeepSleepTimeout, 
       
  4845                     TCallBack( CCamAppController::DeepSleepTimeout, this ) );
       
  4846   
       
  4847   iIdleTimer             = CCamTimer::NewL( KIdleTimeout, 
       
  4848                                             TCallBack( CCamAppController::IdleTimeoutL, this ) );
       
  4849   iImageSaveActive       = CCamImageSaveActive::NewL( *this , *this );        
       
  4850   iCaptureArray          = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4851   iRotationArray         = CCamBurstCaptureArray::NewL( *iImageSaveActive );
       
  4852   iSnapShotRotator       = CCamSnapShotRotator::NewL( *this );
       
  4853   iSequenceFilenameArray = new( ELeave ) CDesCArraySeg( KTimelapseArrayGranularity );
       
  4854   iSoundPlayer           = CCamAudioPlayerController::NewL( *this, *this );
       
  4855 
       
  4856   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  4857        {
       
  4858        // create property watcher for slide state
       
  4859        PRINT( _L("Camera <> CCamAppController: Define Camera slider P&S key..") );
       
  4860        
       
  4861        // Whole slider position reading could be removed after PCFW has implemented
       
  4862        // creation for KLensCoverStatus key
       
  4863        TInt sliderPosition;
       
  4864        TInt err = RProperty::Get(
       
  4865                    CameraPlatPSKeys::KPSCameraPlatUid,
       
  4866                    CameraPlatPSKeys::KLensCoverStatus,
       
  4867                    sliderPosition );  
       
  4868   
       
  4869  
       
  4870        if( err != KErrNone )
       
  4871            {
       
  4872            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4873                    NMusResourceApi::KCategoryUid, 
       
  4874                    NMusResourceApi::KCameraAvailability );
       
  4875            }
       
  4876        else
       
  4877            {
       
  4878            iSlideStateWatcher     = CCamPropertyWatcher::NewL( *this, 
       
  4879                    CameraPlatPSKeys::KPSCameraPlatUid, 
       
  4880                    CameraPlatPSKeys::KLensCoverStatus );
       
  4881            }
       
  4882        }
       
  4883   
       
  4884   if ( iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
  4885       {
       
  4886       iKeyLockStatusWatcher  = CCamPropertyWatcher::NewL( *this,
       
  4887                                                           KPSUidAvkonDomain,
       
  4888                                                           KAknKeyguardStatus );
       
  4889       // request notifications about key lock status
       
  4890       iKeyLockStatusWatcher->Subscribe();     
       
  4891       }
       
  4892   
       
  4893   iProfileStatusWatcher = CCamPropertyWatcher::NewL( *this,
       
  4894                                                      KPSUidProfileEngine,
       
  4895                                                      KProEngActiveProfileChanged );
       
  4896   // request notifications about profile status
       
  4897   iProfileStatusWatcher->Subscribe();    
       
  4898   IsProfileSilent();
       
  4899   
       
  4900   // read central repository value indicating whether camera shutter sound
       
  4901   // should be played always or depending on the current profile setting
       
  4902   CRepository* cr = CRepository::NewLC( KCRUidCamcorderFeatures );
       
  4903   TInt value;
       
  4904   TInt err;
       
  4905   User::LeaveIfError( cr->Get( KCRCamShutterSound, value ) );
       
  4906   CleanupStack::PopAndDestroy( cr );
       
  4907   iShutterSndAlwaysOn = value;
       
  4908         
       
  4909   // get data for monitoring free RAM during sequence capture
       
  4910   CamUtility::GetPsiInt( ECamPsiSnapshotSize, iSnapshotDataSize );
       
  4911 
       
  4912   iConfiguration->GetPsiIntArrayL( ECamPsiJpegDataSizes, iJpegDataSizes );
       
  4913   iConfiguration->GetPsiIntArrayL( ECamPsiSequencePostProcessDataSizes,
       
  4914                                    iSequencePostProcessDataSizes );
       
  4915                                
       
  4916   if ( iConfigManager && iConfigManager->IsCaptureToneDelaySupported() )
       
  4917     {
       
  4918     TInt captureToneDelay = iConfigManager->CaptureToneDelay();
       
  4919     TCallBack captureToneCb( CCamAppController::CaptureToneDelayTimeout, this );
       
  4920     iCaptureToneDelayTimer = 
       
  4921         CCamTimer::NewL( captureToneDelay * KMicroSecsInMilliSec, 
       
  4922                          captureToneCb );
       
  4923     }
       
  4924 
       
  4925   PRINT( _L("Camera <> CCamAppController: Define Camera focused P&S key..") );
       
  4926   err = RProperty::Define( KPSUidCamcorderNotifier, 
       
  4927                                  KCCorFocused,
       
  4928                                  RProperty::EInt );
       
  4929   if ( KErrNone != err )
       
  4930     {
       
  4931     // Error handling. Remove warning.
       
  4932     }
       
  4933     
       
  4934   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() )
       
  4935       { // Publish zoom state
       
  4936       iContextFwClient = CCFClient::NewL( *this );
       
  4937       
       
  4938       // Defining the context using the Context Framework.
       
  4939       err = iContextFwClient->DefineContext(
       
  4940                                             KCamContextSource,
       
  4941                                             KCamContextType,
       
  4942                                             KCamContextSecurity );
       
  4943       if( KErrNone == err )
       
  4944         {
       
  4945         iDefineContextSuccessful = ETrue;
       
  4946         PublishZoomStateL( EFalse );
       
  4947         }
       
  4948       else
       
  4949         {
       
  4950         // We make sure that we dont proceed with publishing the zoom state
       
  4951         // if the context definition fails.
       
  4952         iDefineContextSuccessful = EFalse;
       
  4953         }      
       
  4954       } // Publish zoom state
       
  4955 
       
  4956   iLocationTrailStarted = EFalse;
       
  4957 
       
  4958   CamUtility::GetPsiInt( ECamPsiMaxBurstCapture, iLongSequenceLimit );
       
  4959 
       
  4960   User::LeaveIfError( iFs.Connect() ); 
       
  4961   iDriveChangeNotifier = CCamDriveChangeNotifier::NewL( iFs, *this ); 
       
  4962   
       
  4963   iTvAccessoryMonitor = CCamTvAccessoryMonitor::NewL( this );
       
  4964   iTvAccessoryMonitor->StartListeningL();
       
  4965   
       
  4966   PRINT( _L("Camera <= CCamAppController::ConstructL"));
       
  4967   }
       
  4968 
       
  4969 
       
  4970 
       
  4971 /*
       
  4972 * CCamAppController::PublishZoomStateL
       
  4973 */
       
  4974 void CCamAppController::PublishZoomStateL( const TBool aEnabled )
       
  4975   {
       
  4976   // We publish the zoom state only when context definition is
       
  4977   // successful. the value of the zoom state is controlled by the
       
  4978   // boolean flag "aEnabled".
       
  4979   if ( iConfigManager  && iConfigManager->IsPublishZoomStateSupported() ) 
       
  4980       {
       
  4981       if ( iDefineContextSuccessful )
       
  4982         {
       
  4983         CCFContextQuery* query = CCFContextQuery::NewLC();
       
  4984         query->SetSourceL( KCamContextSource );
       
  4985         query->SetTypeL( KCamContextType );
       
  4986         RContextObjectArray result;
       
  4987         TInt err = iContextFwClient->RequestContext( *query, result );
       
  4988         if( err == KErrNone  && result.Count() > 0 )
       
  4989             {
       
  4990             if ( aEnabled )
       
  4991                 {
       
  4992                 result[0]->SetValueL( KCamContextValueEnable );
       
  4993                 }
       
  4994             else
       
  4995                 {
       
  4996                 result[0]->SetValueL( KCamContextValueDisable );
       
  4997                 }
       
  4998             TInt err = iContextFwClient->PublishContext( *result[0] );
       
  4999             if ( err != KErrNone )
       
  5000                 {
       
  5001                 // Define how to handle the error case.
       
  5002                 }
       
  5003             }
       
  5004         else
       
  5005             {
       
  5006             // ignoring the error case.
       
  5007             }
       
  5008             result.ResetAndDestroy();
       
  5009             CleanupStack::PopAndDestroy( query );
       
  5010         }      
       
  5011       }
       
  5012   }
       
  5013 
       
  5014 
       
  5015    
       
  5016 // ---------------------------------------------------------------------------
       
  5017 // CCamAppController::IsViewFinding
       
  5018 // Check if viewfinder is active
       
  5019 // ---------------------------------------------------------------------------
       
  5020 //
       
  5021 TBool CCamAppController::IsViewFinding() const
       
  5022   {
       
  5023   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5024   return ( iCameraController
       
  5025         && iCameraController->ViewfinderState() == ECamTriActive );
       
  5026   }
       
  5027     
       
  5028 
       
  5029 
       
  5030 // ---------------------------------------------------------------------------
       
  5031 // CCamAppController::NotifyControllerObservers
       
  5032 // Notify the controller observers that a new controller event has occurred
       
  5033 // ---------------------------------------------------------------------------
       
  5034 //
       
  5035 void 
       
  5036 CCamAppController
       
  5037 ::NotifyControllerObservers( TCamControllerEvent aEvent,
       
  5038                              TInt                aError ) const
       
  5039   {
       
  5040   PRINT( _L("Camera => CCamAppController::NotifyControllerObservers"));
       
  5041   // We might need to stop notification for some time.
       
  5042   if( !iMuteNotifications )
       
  5043     {
       
  5044     for ( TInt i = 0; i < iControllerObservers.Count(); i++ )
       
  5045       {
       
  5046       // NON-NULL checked when adding observers.
       
  5047       // If the notification leaves, continue for the other observers
       
  5048       TRAP_IGNORE( iControllerObservers[i]->HandleControllerEventL( aEvent, aError ) )
       
  5049       }
       
  5050     }
       
  5051   PRINT( _L("Camera <= CCamAppController::NotifyControllerObservers"));
       
  5052   }
       
  5053 
       
  5054 
       
  5055 
       
  5056 // ---------------------------------------------------------------------------
       
  5057 // ---------------------------------------------------------------------------
       
  5058 //
       
  5059 void 
       
  5060 CCamAppController
       
  5061 ::EnterViewfinderMode( const TCamCameraMode& aMode )
       
  5062   {
       
  5063   PRINT( _L("Camera => CCamAppController::EnterViewfinderMode"));
       
  5064 
       
  5065   TInt error( KErrNone );
       
  5066   iPendingRelease = EFalse;
       
  5067 
       
  5068   // start monitoring mmc dismount notifications
       
  5069   StartDismountMonitoring();
       
  5070   
       
  5071   if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  5072       {
       
  5073       TRAP_IGNORE ( PublishZoomStateL( ETrue ) );
       
  5074       }
       
  5075 
       
  5076   // Clear these just in case some video prepare is pending.
       
  5077   iVideoPrepareNeeded = EFalse;
       
  5078 
       
  5079   
       
  5080   if( ECamControllerVideo == aMode )
       
  5081     {
       
  5082     // Filename generation needs to be done in all case, not only
       
  5083     // when the current path is null.  
       
  5084     // if( KNullDesC() == iSuggestedVideoPath )
       
  5085       {
       
  5086       TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  5087       }
       
  5088 
       
  5089     // Clear this to be sure it doesn't block recording
       
  5090     iVideoRequested = EFalse;
       
  5091     SetTargetMode     ( ECamControllerVideo  );
       
  5092     SetTargetImageMode( ECamImageCaptureNone );
       
  5093     // shutdown the orientation channel when going to videomode
       
  5094     if ( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  5095         {
       
  5096 	    TRAP_IGNORE( UpdateSensorApiL( EFalse ) );
       
  5097 		}
       
  5098     }
       
  5099   else if( ECamControllerImage == aMode )
       
  5100     {
       
  5101     SetTargetMode     ( ECamControllerImage    );
       
  5102 //    SetTargetImageMode( ECamImageCaptureSingle );
       
  5103     SetTargetImageMode( CurrentImageModeSetup() );
       
  5104     }
       
  5105   else
       
  5106     {
       
  5107     SetOperation( ECamStandby, KErrGeneral );
       
  5108     return;
       
  5109     }
       
  5110 
       
  5111   iInfo.iTargetVfState = ECamTriActive;
       
  5112   if( !Busy() )
       
  5113     {
       
  5114     TRAP( error, IssueModeChangeSequenceL() );
       
  5115     if ( KErrNone    != error
       
  5116       && ECamStandby != iInfo.iOperation )
       
  5117       {
       
  5118       SetOperation( ECamStandby, error );
       
  5119       }
       
  5120     }
       
  5121   else
       
  5122     {
       
  5123     // operation will continue when busy sequence or request completes
       
  5124     }
       
  5125   PRINT( _L("Camera <= CCamAppController::EnterViewfinderMode"));
       
  5126   }
       
  5127 
       
  5128 // ---------------------------------------------------------------------------
       
  5129 // ---------------------------------------------------------------------------
       
  5130 //
       
  5131 void 
       
  5132 CCamAppController::ExitViewfinderMode( const TCamCameraMode& aMode )
       
  5133   {
       
  5134   PRINT( _L("Camera => CCamAppController::ExitViewfinderMode"));
       
  5135   // The check here is to ensure that the viewfinder isn't stopped by the still precapture
       
  5136   // view when it has just lost the foreground to the video precapture view and vice versa.
       
  5137   // In that case the mode in parameter would not match the target mode.
       
  5138   if( iInfo.iOperation != ECamStandby )
       
  5139     {
       
  5140     if ( aMode == iInfo.iTargetMode )
       
  5141       {
       
  5142       iInfo.iTargetVfState = ECamTriIdle;
       
  5143       SetTargetImageMode( ECamImageCaptureNone );
       
  5144   
       
  5145       if( !Busy() )
       
  5146         {
       
  5147         if ( iConfigManager && iConfigManager->IsPublishZoomStateSupported() )
       
  5148             {
       
  5149             TRAP_IGNORE ( PublishZoomStateL( EFalse ) );            
       
  5150             }
       
  5151         TRAPD( error, IssueDirectRequestL( ECamRequestVfRelease ) );
       
  5152         if ( KErrNone             != error
       
  5153           && ECamStandby != iInfo.iOperation )
       
  5154           {
       
  5155           SetOperation( ECamStandby, error );
       
  5156           }
       
  5157         }
       
  5158       else
       
  5159         {
       
  5160         // operation will continue when busy sequence or request completes
       
  5161         }
       
  5162       }
       
  5163     }
       
  5164   PRINT( _L("Camera <= CCamAppController::ExitViewfinderMode"));
       
  5165   }
       
  5166 
       
  5167 
       
  5168 // ---------------------------------------------------------------------------
       
  5169 // CCamAppController::StartViewFinder();
       
  5170 // Non-leaving version of StartViewFinderL() 
       
  5171 // ---------------------------------------------------------------------------
       
  5172 //
       
  5173 void 
       
  5174 CCamAppController::StartViewFinder()
       
  5175   {
       
  5176   PRINT( _L("Camera => CCamAppController::StartViewFinder" ))
       
  5177   iInfo.iTargetVfState = ECamTriActive; 
       
  5178 
       
  5179   if( !Busy() )
       
  5180     {
       
  5181     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STARTVIEWFINDER, "e_CAM_APP_VF_INIT 0" );   //CCORAPP_APP_VF_INIT_END
       
  5182     
       
  5183     TRAPD( error, IssueDirectRequestL( ECamRequestVfStart ) );
       
  5184     if ( KErrNone    != error
       
  5185       && ECamStandby != iInfo.iOperation )
       
  5186       {
       
  5187       PRINT( _L("Camera <> CCamAppController::StartViewFinder - [ERROR] VF start failed, go to standby" ))
       
  5188       SetOperation( ECamStandby, error );
       
  5189       }
       
  5190     }
       
  5191   else
       
  5192     {
       
  5193     // Vf started at earliest convenient time when ongoing requests finish.
       
  5194     }
       
  5195   PRINT(_L("Camera <= CCamAppController::StartViewFinder") );
       
  5196   }
       
  5197 
       
  5198 // ---------------------------------------------------------------------------
       
  5199 // StopViewFinder
       
  5200 // Stop the viewfinder immediately
       
  5201 // ---------------------------------------------------------------------------
       
  5202 //
       
  5203 void 
       
  5204 CCamAppController::StopViewFinder()
       
  5205   {
       
  5206   PRINT( _L("Camera => CCamAppController::StopViewFinderNow" ) )
       
  5207   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5208   
       
  5209   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5210 
       
  5211   if ( iBacklightTimer && iBacklightTimer->IsActive() )
       
  5212     {
       
  5213     iBacklightTimer->Cancel();
       
  5214     }
       
  5215   
       
  5216   // Only stop if active.
       
  5217   // Idle and inactive need no action at this point.
       
  5218   if( ECamTriActive == iCameraController->ViewfinderState() )
       
  5219     {
       
  5220     iInfo.iTargetVfState = ECamTriInactive;
       
  5221     
       
  5222     // Can only fail to OOM when state is checked.
       
  5223     TRAPD( error, iCameraController->DirectRequestL( ECamRequestVfStop ) );
       
  5224     if( KErrNone             != error 
       
  5225      && ECamStandby != iInfo.iOperation )
       
  5226       {
       
  5227       SetOperation( ECamStandby, error );
       
  5228       }
       
  5229     }
       
  5230     
       
  5231   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDER, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5232     
       
  5233   PRINT( _L("Camera <= CCamAppController::StopViewFinderNow" ) )
       
  5234   }
       
  5235 
       
  5236 // ---------------------------------------------------------------------------
       
  5237 // StopViewFinderEcam
       
  5238 // Stop the viewfinder immediately without changing states
       
  5239 // ---------------------------------------------------------------------------
       
  5240 //
       
  5241 void 
       
  5242 CCamAppController::StopViewFinderEcam()
       
  5243   {
       
  5244   PRINT( _L("Camera => CCamAppController::StopViewFinderEcam" ) )
       
  5245   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) ); 
       
  5246   
       
  5247   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 1" );  //CCORAPP_STOP_VF_START
       
  5248   
       
  5249   // Trap and ignore error
       
  5250   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestVfStopEcam ) );
       
  5251   
       
  5252   OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_STOPVIEWFINDERECAM, "e_CAM_APP_STOP_VF 0" ); //CCORAPP_STOP_VF_END
       
  5253     
       
  5254   PRINT( _L("Camera <= CCamAppController::StopViewFinderEcam" ) )
       
  5255   }
       
  5256 
       
  5257 // ---------------------------------------------------------------------------
       
  5258 // CCamAppController::FreezeViewFinder
       
  5259 // Copy the next viewfinder frame then stop the viewfinder
       
  5260 // ---------------------------------------------------------------------------
       
  5261 //
       
  5262 void CCamAppController::FreezeViewFinder( TBool aFreeze )
       
  5263   {
       
  5264   // If the viewfinder needs to freeze
       
  5265   if ( aFreeze )
       
  5266     {
       
  5267     PERF_MESSAGE_L2( EPerfMessagePausingViewFinder );
       
  5268     iFreezeViewFinder  = ETrue;
       
  5269     iUpdateFrozenFrame = ETrue;
       
  5270     }
       
  5271   // Restarting the viewfinder
       
  5272   else 
       
  5273     {
       
  5274     iFreezeViewFinder  = EFalse;
       
  5275     iUpdateFrozenFrame = EFalse;
       
  5276     if ( ECamTriActive != iCameraController->ControllerInfo().iVfState )
       
  5277       {
       
  5278       StartViewFinder();
       
  5279       }
       
  5280     }
       
  5281   }
       
  5282 
       
  5283 
       
  5284 // ---------------------------------------------------------------------------
       
  5285 // CCamAppController::SetKeyUp
       
  5286 // Set  iKeyUP value which is used to determine if burst
       
  5287 // timer should be activated or not
       
  5288 // ---------------------------------------------------------------------------
       
  5289 //
       
  5290 void CCamAppController::SetKeyUp( TBool aValue /*= EFalse*/ )
       
  5291     {
       
  5292     PRINT1(_L("Camera => CCamAppController::SetKeyUp, iKeyUP=%d"), aValue );
       
  5293     iKeyUP=aValue; 
       
  5294     }
       
  5295 
       
  5296 // ---------------------------------------------------------------------------
       
  5297 // CCamAppController::DoCaptureL
       
  5298 // Initiate image capture
       
  5299 // ---------------------------------------------------------------------------
       
  5300 //
       
  5301 TBool CCamAppController::DoCaptureL()
       
  5302   {
       
  5303   PRINT( _L("Camera => CCamAppController::DoCaptureL()"));
       
  5304   PRINT2(_L("Camera <> mode[%s] imagemode[%s]"), KCamModeNames[iInfo.iMode], KCamImageModeNames[iInfo.iImageMode] );
       
  5305 
       
  5306   // ReleaseArray();
       
  5307   if( iImageSaveActive->Count() <= 0 )
       
  5308       {
       
  5309       ReleaseArray( ETrue );
       
  5310       }
       
  5311   iCurrentImageIndex = 0;
       
  5312   iArrayUsageCount   = KImageArrayUsers;
       
  5313 
       
  5314   iCameraWoken = EFalse;
       
  5315     
       
  5316   TBool continueWithCapture = ETrue;
       
  5317   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
  5318   
       
  5319   // Cancel capture if there are settings pending
       
  5320   if ( IsFlagOn( iBusyFlags, EBusySetting ) )
       
  5321       {
       
  5322       continueWithCapture = EFalse;
       
  5323       }
       
  5324 
       
  5325   switch( iInfo.iImageMode )
       
  5326     {
       
  5327     // -----------------------------------------------------
       
  5328     // Burst capture
       
  5329     case ECamImageCaptureBurst:
       
  5330       {
       
  5331       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureBurst") );
       
  5332       /*
       
  5333       TCamPhotoSizeId sizeId( GetCurrentImageResolution() );
       
  5334 
       
  5335       TInt memoryNeed( iJpegDataSizes[sizeId]
       
  5336                      + iSequencePostProcessDataSizes[sizeId] 
       
  5337                      + iSnapshotDataSize );  
       
  5338       TInt memoryFree( 0 );
       
  5339       HAL::Get( HALData::EMemoryRAMFree, memoryFree ); // error ignored
       
  5340 
       
  5341       if( memoryFree < memoryNeed )
       
  5342         {      
       
  5343         PRINT( _L( "Camera <> Not enough memory for more burst captures - complete capture" ) );  
       
  5344         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5345         // Force re-prepare of engine
       
  5346         appUi->HandleCommandL( ECamCmdSequence );
       
  5347                 
       
  5348         // Display out of memory note
       
  5349         NotifyControllerObservers( ECamEventSnapshotReady, KErrNoMemory );
       
  5350                 
       
  5351         // Return app to burst precapture state from burst in-capture
       
  5352         SetOperation( ECamNoOperation );
       
  5353         NotifyControllerObservers( ECamEventCaptureComplete );  
       
  5354                 
       
  5355         // Force update of UI furniture
       
  5356         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5357         appUi->UpdateCba();
       
  5358 
       
  5359         iCaptureRequested = EFalse;
       
  5360         HandleCaptureCompletion();
       
  5361         continueWithCapture = EFalse;
       
  5362         }
       
  5363       else
       
  5364         {
       
  5365         iSequenceCaptureInProgress = ETrue;  
       
  5366         iActualBurstCount = 0;
       
  5367         FreezeViewFinder( ETrue );
       
  5368         // Stop the screensaver from coming on when burst mode is active
       
  5369         EnableScreenSaver( EFalse );
       
  5370         // Make navi counter update itself
       
  5371         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5372         }
       
  5373       */
       
  5374 
       
  5375       if( !appUi->SelfTimerEnabled() )
       
  5376         {
       
  5377         // Start timer to change burst mode to press and hold
       
  5378         // if not determined to be short burst before that.
       
  5379         
       
  5380         //One such case is if capturekeyup event has occured before
       
  5381         //DocaptureL method
       
  5382         if( !iKeyUP && !iNoBurstCancel )
       
  5383             {
       
  5384             StartBurstTimerL();            
       
  5385             }
       
  5386         }
       
  5387       iSequenceCaptureInProgress = ETrue;  
       
  5388        iValueIsStored = EFalse;
       
  5389       FreezeViewFinder( ETrue );
       
  5390       EnableScreenSaver( EFalse );
       
  5391 	  if(  iBacklightTimer 
       
  5392        && !iBacklightTimer->IsActive() )
       
  5393         {
       
  5394         iBacklightTimer->Start( 0,
       
  5395                                 KBacklighTimerInterval, 
       
  5396                                 TCallBack( ResetInactivityTimer, this ) );
       
  5397         }
       
  5398       NotifyControllerObservers( ECamEventCounterUpdated );
       
  5399 
       
  5400       break;
       
  5401       }
       
  5402     // -----------------------------------------------------
       
  5403     // Timelapse capture
       
  5404     case ECamImageCaptureTimeLapse:
       
  5405       {
       
  5406       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureTimeLapse") );
       
  5407       iSequenceCaptureInProgress = ETrue;  
       
  5408       // Stop the screensaver from coming on when burst mode is active
       
  5409       EnableScreenSaver( EFalse );
       
  5410             
       
  5411       // Get the remaining image count and only start the timer for the next capture if there is enough
       
  5412       // space, taking into account that the current capture will also use up one image     
       
  5413       TCamMediaStorage storage( (TCamMediaStorage)IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) );
       
  5414       TCamPhotoSizeId  sizeId ( GetCurrentImageResolution() );
       
  5415 
       
  5416       TInt remainingCount = ImagesRemaining( storage, ETrue, sizeId );
       
  5417 
       
  5418       // Check if the advanced sequence is limited (by starting from selftimer)
       
  5419       if( remainingCount  >= 1
       
  5420        && iRequestedCaptureCount <= TimeLapseImageCount()+1 )
       
  5421         {
       
  5422         iCompleteTimeLapsePending = ETrue;
       
  5423         }
       
  5424             
       
  5425       // if there isn't space for this capture (e.g. some memory has been used since the timer was initiated
       
  5426       // or there isn't enough space to initiate a further capture
       
  5427       else if ( remainingCount <= 1 )
       
  5428         {
       
  5429         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. only space for one capture, stop timer") );
       
  5430 
       
  5431         // The timer is no longer needed
       
  5432         if ( iTimeLapseTimer )
       
  5433           {
       
  5434           iTimeLapseTimer->Cancel();
       
  5435           delete iTimeLapseTimer;
       
  5436           iTimeLapseTimer = NULL;
       
  5437           }
       
  5438         // if there isn't even enough space for this capture
       
  5439         if ( remainingCount < 1 ) 
       
  5440           {
       
  5441           // complete the timelapse capture now (prevent the current capture from starting)
       
  5442           continueWithCapture = EFalse;
       
  5443           iArrayUsageCount = 0;
       
  5444           CompleteTimeLapseOperation();
       
  5445           }
       
  5446         else // if there isn't enough space to initiate a further capture
       
  5447           {
       
  5448           // ensure that the time lapse capture completes after the current capture
       
  5449           iCompleteTimeLapsePending = ETrue;
       
  5450           }                   
       
  5451         }
       
  5452             
       
  5453       else // there is space to initiate a further capture
       
  5454         {                
       
  5455         PRINT( _L("Camera <> CCamAppController::DoCaptureL .. space for more than this capture, timer set on..") );
       
  5456         if ( !iTimeLapseTimer )
       
  5457           {
       
  5458           RestartTimeLapseTimerL();
       
  5459                 
       
  5460           //Products which support autofocus needs to reduce time for second picture
       
  5461           //about the time needed by autofocus.
       
  5462           if( iConfigManager && iConfigManager->IsAutoFocusSupported() 
       
  5463               && !CurrentSceneHasForcedFocus() )
       
  5464             {
       
  5465             iTimeLapseStartTime = iTimeLapseStartTime - TTimeIntervalSeconds( KFocusingDurationSeconds );
       
  5466             }
       
  5467           }
       
  5468         }
       
  5469       break;
       
  5470       }
       
  5471     // -----------------------------------------------------
       
  5472     // Single capture
       
  5473     case ECamImageCaptureSingle:
       
  5474       PRINT( _L("Camera <> CCamAppController::DoCaptureL .. case ECamImageCaptureSingle") );
       
  5475       // Should not take so long to get the image captured and saved,
       
  5476       // but 
       
  5477       EnableScreenSaver( EFalse );
       
  5478       SetCaptureKeyPressedWhileImageSaving(EFalse);
       
  5479       break;
       
  5480     // -----------------------------------------------------
       
  5481     default:
       
  5482       PRINT(_L("Camera <> Not in any image capture mode, LEAVE!!"));
       
  5483       User::Leave( KErrGeneral );
       
  5484       break;
       
  5485     // -----------------------------------------------------
       
  5486     }
       
  5487 
       
  5488   if ( continueWithCapture )
       
  5489     {
       
  5490     IssueRequestL( ECamRequestImageCapture );
       
  5491     // Operation in progress is updated in HandleCameraEventL
       
  5492     // store the orientation at capture time, needed in thumbnail creation
       
  5493     iCaptureOrientation = iLastImageOrientation;
       
  5494     }
       
  5495 
       
  5496   iCaptureStoppedForUsb = EFalse; 
       
  5497   PRINT( _L("Camera <= CCamAppController::DoCaptureL()"));
       
  5498   return continueWithCapture;
       
  5499   }
       
  5500 
       
  5501 
       
  5502 // ---------------------------------------------------------------------------
       
  5503 // CCamAppController::DoRecord
       
  5504 // Initiate video recording
       
  5505 // ---------------------------------------------------------------------------
       
  5506 //
       
  5507 void CCamAppController::DoRecord()
       
  5508   {
       
  5509   PRINT( _L("Camera => CCamAppController::DoRecord") );
       
  5510   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
  5511 
       
  5512   StopIdleTimer();
       
  5513 
       
  5514   // No key sounds when recording
       
  5515   TRAP_IGNORE( iSoundPlayer->DisableAllKeySoundsL() );
       
  5516 
       
  5517   PRINT( _L("Camera <> Requesting video capture start..") );
       
  5518   TRAPD( error, IssueRequestL( ECamRequestVideoStart ) );
       
  5519   PRINT1( _L("Camera <> ..request issued, status:%d"), error );
       
  5520 
       
  5521   if( KErrNone != error ) SetOperation( ECamStandby, error );    
       
  5522   else                    SetOperation( ECamCapturing );
       
  5523 
       
  5524   // Request is handled
       
  5525   iVideoRequested = EFalse;
       
  5526 
       
  5527   iCaptureStoppedForUsb = EFalse;
       
  5528   PRINT( _L("Camera <= CCamAppController::DoRecord") );
       
  5529   }
       
  5530 
       
  5531 
       
  5532 // ---------------------------------------------------------------------------
       
  5533 // CCamAppController::ReserveFileNamesL
       
  5534 // Reserve a set of filenames for a burst capture
       
  5535 // ---------------------------------------------------------------------------
       
  5536 //
       
  5537 void 
       
  5538 CCamAppController::ReserveFileNamesL( 
       
  5539     const TCamCameraMode&        aCaptureMode,
       
  5540     const TCamImageCaptureMode&  aImageMode,
       
  5541           TBool                  aForcePhoneMem /*= EFalse*/ )
       
  5542   {
       
  5543   PRINT( _L("Camera => CCamAppController::ReserveFileNamesL") )
       
  5544   TInt captureCount = 1;
       
  5545   TInt store        = ECamMediaStorageNone; 
       
  5546   TBuf<KMaxExtension> extension; 
       
  5547 
       
  5548   // If the next file will be a photo
       
  5549   if ( ECamControllerImage == aCaptureMode )
       
  5550     {         
       
  5551     extension = KImageExtension;
       
  5552     }
       
  5553   // Otherwise the next file will be a video
       
  5554   else
       
  5555     {
       
  5556 #ifndef __WINS__
       
  5557     TCamVideoFileType fileType = static_cast<TCamVideoFileType> 
       
  5558         ( IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5559         
       
  5560     extension = ( ECamVideoMpeg4 == fileType )
       
  5561                 ? KVideoMP4Extension
       
  5562                 : KVideo3GPExtension;
       
  5563 #else
       
  5564     extension = KVideo3GPExtension;
       
  5565 #endif
       
  5566     }
       
  5567 
       
  5568   store = ( ECamControllerImage == aCaptureMode ) ? 
       
  5569                  CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();
       
  5570 
       
  5571   TPath basePath;
       
  5572 
       
  5573   // Take a snapshot of the date - to ensure a sequence on a date boundary isn't split into
       
  5574   // different months
       
  5575   TTime now;
       
  5576   now.HomeTime();
       
  5577   // Need to check that there is enough space for the files. If this is a sequence of 20 images or 
       
  5578   // less then ensure there is enough space in the current folder, otherwise only one space is needed
       
  5579   TInt guaranteedGroup = 1;
       
  5580   if ( captureCount < CCamFolderUtility::KMaxGuaranteedBurstGroup )
       
  5581     {
       
  5582     guaranteedGroup = captureCount;
       
  5583     }
       
  5584   
       
  5585   // Leaves if errors generating the path
       
  5586   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5587                                    store, 
       
  5588                                    basePath, 
       
  5589                                    aCaptureMode, 
       
  5590                                    ETrue, 
       
  5591                                    guaranteedGroup, 
       
  5592                                    now ); 
       
  5593      
       
  5594   iCurrentStorage = static_cast<TCamMediaStorage>( store );  
       
  5595 //  TInt numberSettingId( KErrNotFound );
       
  5596   TInt typeSettingId( KErrNotFound );
       
  5597   TInt baseSettingId( KErrNotFound );
       
  5598   TInt counter( 0 );
       
  5599 
       
  5600   if( ECamControllerVideo == aCaptureMode )
       
  5601     {
       
  5602 //    numberSettingId = ECamSettingItemVideoNumber;
       
  5603     counter         = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5604     typeSettingId   = ECamSettingItemVideoNameBaseType;
       
  5605     baseSettingId   = ECamSettingItemVideoNameBase;
       
  5606     }
       
  5607   else
       
  5608     {
       
  5609 //    numberSettingId = ECamSettingItemPhotoNumber;
       
  5610     counter         = iImageNumberCache;
       
  5611     typeSettingId   = ECamSettingItemPhotoNameBaseType;
       
  5612     baseSettingId   = ECamSettingItemPhotoNameBase;
       
  5613     }
       
  5614 
       
  5615 //  TInt counter( IntegerSettingValue( numberSettingId ) );
       
  5616   TBuf<KCamMaxDateLen> dateNameBase;
       
  5617   TPtrC nameBase;
       
  5618   if ( ECamNameBaseDate == iSettingsModel->IntegerSettingValue( typeSettingId ) )
       
  5619       {       
       
  5620       CamUtility::FormatDateFileNameL( dateNameBase );
       
  5621       nameBase.Set( dateNameBase );
       
  5622       }
       
  5623     else
       
  5624       {
       
  5625       nameBase.Set( TextSettingValue( baseSettingId ) );
       
  5626       }
       
  5627 
       
  5628   RFs rfs;
       
  5629   User::LeaveIfError( rfs.Connect() );
       
  5630   CleanupClosePushL( rfs );        
       
  5631         
       
  5632   TEntry entry;
       
  5633 
       
  5634   TInt namedImages = 0;
       
  5635   while ( namedImages < captureCount )
       
  5636     {
       
  5637     // Generate new name
       
  5638     TFileName newFileName;
       
  5639 
       
  5640     CamUtility::FormatFileName( counter, nameBase, newFileName );
       
  5641 
       
  5642     TFileName newPath( basePath );
       
  5643     newPath.Append( newFileName );
       
  5644     newPath.Append( extension );
       
  5645 
       
  5646     // if there is no file in the current location with this name
       
  5647     TEntry entry;  // Prevent LINT error
       
  5648     TInt ferr = rfs.Entry( newPath, entry );
       
  5649     if ( KErrNotFound == ferr )
       
  5650       {
       
  5651       // A file with that name was not found, so the filename is okay.
       
  5652       PRINT( _L("Camera <> Filename OK.") )
       
  5653       namedImages++;
       
  5654       StoreNextFileNameL( newPath );
       
  5655           
       
  5656       // If this is time lapse capture then the full set of file names
       
  5657       // will be needed for the 'delete sequence' option. The burst capture array
       
  5658       // in timelapse only holds data for one item at a time so a separate array
       
  5659       // is used to keep track of all the images file names. The redundancy in filename
       
  5660       // storage is limited to a single file name.             
       
  5661       if ( ECamImageCaptureTimeLapse == aImageMode )         
       
  5662         {                                     
       
  5663         TRAP_IGNORE( iSequenceFilenameArray->AppendL( newPath ) );
       
  5664         // Update the images captured count
       
  5665         NotifyControllerObservers( ECamEventCounterUpdated );
       
  5666         }
       
  5667       counter++;
       
  5668       }
       
  5669     else if ( KErrNone == ferr )
       
  5670       {
       
  5671       // A file with that name exists already. Increment the counter and try again.
       
  5672       PRINT( _L("Camera <> Filename already in use!") ) 
       
  5673       counter++;   // Try the next index number
       
  5674       }
       
  5675     else
       
  5676       {
       
  5677       // There was some other error. Can not save file -> Leave.
       
  5678       PRINT1( _L("Camera <> File server returned error: %d"), ferr );
       
  5679       User::Leave( ferr );
       
  5680       }
       
  5681       
       
  5682     }
       
  5683   CleanupStack::PopAndDestroy( &rfs );
       
  5684 
       
  5685   // SetIntegerSettingValueL( numberSettingId, counter );
       
  5686   if( ECamControllerVideo == aCaptureMode )
       
  5687     {
       
  5688     SetIntegerSettingValueL( ECamSettingItemVideoNumber, counter );
       
  5689     }
       
  5690   else
       
  5691     {
       
  5692     // SetIntegerSettingValueL called when capture ends. 
       
  5693     iImageNumberCache = counter;
       
  5694     }
       
  5695 
       
  5696   PRINT( _L("Camera <= CCamAppController::ReserveFileNamesL") )
       
  5697   }
       
  5698 
       
  5699     
       
  5700 // ---------------------------------------------------------------------------
       
  5701 // CCamAppController::CreateDummyFileL
       
  5702 // Create dummy file ready for image storage
       
  5703 // ---------------------------------------------------------------------------
       
  5704 //
       
  5705 TInt 
       
  5706 CCamAppController::CreateDummyFileL( RFs& aFs, const TDesC& aFullPath )
       
  5707   {
       
  5708   PRINT1( _L("Camera => CCamAppController::CreateDummyFileL [%S]"), &aFullPath );  
       
  5709   RFile file;
       
  5710   CleanupClosePushL( file );
       
  5711   
       
  5712   TInt err = file.Create( aFs, aFullPath, EFileWrite );
       
  5713   if ( err == KErrNone )
       
  5714     {
       
  5715     // Still image files are made writable and non-hidden
       
  5716     // just before the save operation
       
  5717     // file is set to hidden so that media gallery does not detect it
       
  5718     file.SetAtt( KEntryAttReadOnly|KEntryAttHidden, 0 );
       
  5719     }
       
  5720   
       
  5721   CleanupStack::PopAndDestroy( &file );
       
  5722   
       
  5723   PRINT1( _L("Camera <= CCamAppController::CreateDummyFileL, status:%d"), err );  
       
  5724   return err;
       
  5725   }
       
  5726   
       
  5727   
       
  5728 // ---------------------------------------------------------------------------
       
  5729 // CCamAppController::StoreNextFileNameL
       
  5730 // Add newly generated filename to array of names
       
  5731 // ---------------------------------------------------------------------------
       
  5732 //
       
  5733 void CCamAppController::StoreNextFileNameL( const TDesC& aFullPath )
       
  5734     {
       
  5735     PRINT( _L("Camera => CCamAppController::StoreNextFileNameL") );
       
  5736     TParse parse;
       
  5737     parse.Set( aFullPath, NULL, NULL );
       
  5738     
       
  5739     // Store the path + filename and plain filename for future reference
       
  5740     if( ECamControllerVideo == iInfo.iMode && BurstCaptureArray()->Count() > 0 )
       
  5741       {
       
  5742        BurstCaptureArray()->SetNameL( aFullPath, parse.Name(), 0 );	
       
  5743       }
       
  5744     else
       
  5745       {
       
  5746       BurstCaptureArray()->SetNextNameL( aFullPath, parse.Name() );		
       
  5747       }
       
  5748     
       
  5749     PRINT( _L("Camera <= CCamAppController::StoreNextFileNameL") );
       
  5750     }
       
  5751 
       
  5752 // ---------------------------------------------------------------------------
       
  5753 // CCamAppController::GenerateNextVideoFilePathL
       
  5754 // Generate a new file name and full path to save the next
       
  5755 // video 
       
  5756 // ---------------------------------------------------------------------------
       
  5757 //
       
  5758 void CCamAppController::GenerateNextVideoFilePathL( TBool aForcePhoneMem )
       
  5759   {
       
  5760   PRINT1( _L( "Camera => CCamAppController::GenerateNextVideoFilePathL, force phone mem:%d" ), aForcePhoneMem )    
       
  5761   if( aForcePhoneMem )
       
  5762     {
       
  5763     ForceUsePhoneMemoryL( ETrue );
       
  5764     }
       
  5765   TInt store = IntegerSettingValue( ECamSettingItemVideoMediaStorage ); 
       
  5766   
       
  5767   TBuf<KMaxExtension> extension;        
       
  5768 
       
  5769 #ifdef __WINS__
       
  5770   extension = KVideo3GPExtension;
       
  5771 #else
       
  5772   // If the video file type is MP3, then display this icon.
       
  5773   TCamVideoFileType fileType = 
       
  5774     static_cast<TCamVideoFileType>( 
       
  5775         IntegerSettingValue( ECamSettingItemVideoFileType ) );
       
  5776 
       
  5777   extension = (fileType == ECamVideoMpeg4)
       
  5778             ? KVideoMP4Extension
       
  5779             : KVideo3GPExtension;
       
  5780 #endif
       
  5781   
       
  5782   TBuf<KCamMaxDateLen> dateNameBase;
       
  5783   TPtrC baseVideoName;
       
  5784           
       
  5785   if ( iSettingsModel->IntegerSettingValue( 
       
  5786                         ECamSettingItemVideoNameBaseType ) == ECamNameBaseDate )
       
  5787     {       
       
  5788     CamUtility::FormatDateFileNameL( dateNameBase );
       
  5789     baseVideoName.Set( dateNameBase );
       
  5790     }
       
  5791   else
       
  5792     {
       
  5793     baseVideoName.Set( TextSettingValue( ECamSettingItemVideoNameBase ) );
       
  5794     }
       
  5795 
       
  5796   TFileName nextFileName( baseVideoName );
       
  5797 
       
  5798   store = ( ECamControllerImage == iInfo.iMode ) ? 
       
  5799                 CurrentPhotoStorageLocation() : CurrentVideoStorageLocation();  
       
  5800 
       
  5801   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5802 
       
  5803   if ( IsAppUiAvailable() &&
       
  5804        appUi &&
       
  5805        appUi->IsMemoryFullOrUnavailable( ECamMediaStorageCard ) &&
       
  5806        ECamMediaStorageCard == store )
       
  5807     {
       
  5808     if ( ExistMassStorage() )
       
  5809       {
       
  5810       // with multiple drives, the mass memory is the default
       
  5811       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  5812       store = ECamMediaStorageMassStorage;
       
  5813       }
       
  5814     else
       
  5815       {
       
  5816       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  5817       store = IntegerSettingValue(ECamSettingItemRemovePhoneMemoryUsage)?
       
  5818                   ECamMediaStorageNone:
       
  5819                   ECamMediaStoragePhone;
       
  5820       }
       
  5821     }
       
  5822 
       
  5823   TInt fileNameCounter = IntegerSettingValue( ECamSettingItemVideoNumber );
       
  5824  
       
  5825   // Update contents of iSuggestedVideoPath (drive and folders only)
       
  5826   CCamFolderUtility::GetBasePathL( iMonthFolderCounters, 
       
  5827                                    store,
       
  5828                                    iSuggestedVideoPath,
       
  5829                                    ECamControllerVideo,
       
  5830                                    ETrue );
       
  5831                                    
       
  5832   iCurrentStorage = static_cast<TCamMediaStorage>( store );   
       
  5833   // Update contents of iSuggestedVideoPath (appending filename and extension)
       
  5834   CamUtility::GetUniqueNameL( iSuggestedVideoPath, nextFileName, fileNameCounter, extension );
       
  5835   PRINT( _L( "Camera <= CamAppController::GenerateNextVideoFilePathL" ) )
       
  5836   }
       
  5837 
       
  5838 // ---------------------------------------------------------------------------
       
  5839 // CCamAppController::GenerateNextValidVideoPathL
       
  5840 // Generate a new file name and full path to save the next video.
       
  5841 // If the generated file (using settings to suggest the drive) can not be opened
       
  5842 // try again, forcing the file to be on C: instead.
       
  5843 // ---------------------------------------------------------------------------
       
  5844 //
       
  5845 void CCamAppController::GenerateNextValidVideoPathL()
       
  5846   {
       
  5847   PRINT( _L("Camera => CCamAppController::GenerateNextValidVideoPathL()"));    
       
  5848   
       
  5849   // If USB is active, use phone memory
       
  5850   if( CamUtility::IsUsbActive() )
       
  5851       {
       
  5852       GenerateNextVideoFilePathL( ETrue );	
       
  5853       }
       
  5854   else
       
  5855       {    	
       
  5856       // Generate a file path using the settings
       
  5857       TRAPD( err, GenerateNextVideoFilePathL() );
       
  5858       
       
  5859       // If left (possibly due to corrupt MMC), try again with phone memory
       
  5860       if ( err )
       
  5861           {
       
  5862           // If we have got here, we can't access MMC. 
       
  5863           // Don't switch to phone memory, but prepare the engine with a video
       
  5864           // name in phone memory. This will be reset if needed when the user actually
       
  5865           // starts recording
       
  5866           PRINT( _L( "Could not generate next file path!  Corrupt MMC?" ) );
       
  5867           GenerateNextVideoFilePathL( ETrue );    
       
  5868           }
       
  5869       }
       
  5870 
       
  5871   PRINT( _L("Camera <= CCamAppController::GenerateNextValidVideoPathL()"));        
       
  5872   }
       
  5873 
       
  5874 // ---------------------------------------------------------------------------
       
  5875 // CCamAppController::GenerateNextValidImagesPathL
       
  5876 // Generate a new path to save the next image.
       
  5877 // ---------------------------------------------------------------------------
       
  5878 //
       
  5879 void CCamAppController::GenerateNextValidImagesPathL()
       
  5880   {
       
  5881   PRINT( _L("Camera => CCamAppController::GenerateNextValidImagesPathL()"));    
       
  5882   // Generate a file path using the settings
       
  5883   // Ensure the image folder exists
       
  5884   TFileName path;
       
  5885   TInt storage = IntegerSettingValue( ECamSettingItemPhotoMediaStorage );
       
  5886   CCamFolderUtility::GetBasePathL( iMonthFolderCounters,
       
  5887                                    storage,
       
  5888                                    path,
       
  5889                                    ECamControllerImage,
       
  5890                                    EFalse ); 
       
  5891                                    
       
  5892   iCurrentStorage = static_cast<TCamMediaStorage>( storage );                                 
       
  5893   PRINT( _L("Camera <= CCamAppController::GenerateNextValidImagesPathL()"));        
       
  5894   }    
       
  5895 
       
  5896 
       
  5897 // ---------------------------------------------------------------------------
       
  5898 // CCamAppController::CaptureModeTranstionInProgress
       
  5899 // Report whather a capture mode is currently being prepared
       
  5900 // ---------------------------------------------------------------------------
       
  5901 //
       
  5902 TBool CCamAppController::CaptureModeTransitionInProgress()
       
  5903   {
       
  5904   PRINT1( _L("Camera => CCamAppController::CaptureModeTransitionInProgress (%d)"), iCaptureModeTransitionInProgress )
       
  5905   return iCaptureModeTransitionInProgress;
       
  5906   }
       
  5907 
       
  5908 // ---------------------------------------------------------------------------
       
  5909 // CCamAppController::HandleSaveEvent
       
  5910 // From MCamImageSaveObserver.
       
  5911 // Handle completion of image saving
       
  5912 // ---------------------------------------------------------------------------
       
  5913 //
       
  5914 void 
       
  5915 CCamAppController::HandleSaveEvent( TCamSaveEvent aEvent )
       
  5916   {
       
  5917   PRINT3( _L( "Camera => CCamAppController::HandleSaveEvent .. event[%s] imagemode[%s] operation[%s]" ),
       
  5918           KCamSaveEventNames       [aEvent          ],
       
  5919           KCamImageModeNames       [iInfo.iImageMode], 
       
  5920           KCamCaptureOperationNames[iInfo.iOperation] )
       
  5921    
       
  5922   TBool mediaFileChanged = EFalse;     
       
  5923   
       
  5924   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  5925   if( ( iCaptureArray->ImagesRemaining() <= 0 ) 
       
  5926           && appUi 
       
  5927           && appUi->IsInPretendExit() )
       
  5928       {
       
  5929       ReleaseArray( ETrue );
       
  5930       }
       
  5931   
       
  5932   if( ECamSaveEventCriticalError == aEvent )
       
  5933     {
       
  5934     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5935     SetOperation( ECamStandby, KErrGeneral );
       
  5936     PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  5937     return;
       
  5938     }
       
  5939 
       
  5940   if( aEvent == ECamSaveEventSaveError ) 
       
  5941     {
       
  5942     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5943     if( iInfo.iImageMode == ECamImageCaptureBurst &&
       
  5944         SequenceCaptureInProgress() )
       
  5945         {
       
  5946         // Cancel ongoing burst capture
       
  5947         // Burst capture is normally cancelled by setting iRequestedBurstCount,
       
  5948         // and actual cancelling is done when next imagedata arrives.
       
  5949         // However, in this case camera is going to be released, and there won't
       
  5950         // be next image data, so give ECamRequestImageCancel and capture
       
  5951         // completion event here to avoid problems
       
  5952         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Cancel burst due to error") ); 
       
  5953         TRAP_IGNORE ( IssueDirectRequestL( ECamRequestImageCancel ) );
       
  5954         NotifyControllerObservers( ECamEventCaptureComplete, KErrCancel );   
       
  5955         }
       
  5956     else
       
  5957         {
       
  5958         PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent: critical error, going to standby.." ) )
       
  5959         SetOperation( ECamStandby, KErrGeneral );
       
  5960         }   
       
  5961     PRINT( _L("Camera <= CCamAppController::HandleSaveEvent - ECamSaveEventSaveError!") );
       
  5962     return;
       
  5963     }
       
  5964 
       
  5965   // if a save completes 
       
  5966   if ( aEvent == ECamSaveEventComplete )
       
  5967     {
       
  5968     PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventComplete") );
       
  5969 
       
  5970 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  5971     if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  5972       {
       
  5973       // Do not log in burst mode
       
  5974       PERF_EVENT_END_L1( EPerfEventShotToSave );      
       
  5975       }
       
  5976 #endif
       
  5977 
       
  5978     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SAVE 0" );  //CCORAPP_PRI_SHOT_TO_SAVE_END
       
  5979 
       
  5980     // Check that this is the completion of the last pending 
       
  5981     // single image save.
       
  5982     // Note burst capture completion is handled separately
       
  5983     TBool savedAll   = ( iImageSaveActive->Count()== 0                );
       
  5984     TBool completing = ( ECamCompleting           == iInfo.iOperation );
       
  5985 
       
  5986     switch( iInfo.iImageMode )
       
  5987       {
       
  5988       case ECamImageCaptureNone: // In postcapture, waiting for saving
       
  5989       case ECamImageCaptureSingle:
       
  5990         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureSingle/None") );
       
  5991         if( savedAll )
       
  5992           {
       
  5993           OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );    //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  5994     
       
  5995           PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. calling HandleCaptureCompletion()") );
       
  5996           if( !iSaveStarted )
       
  5997               {
       
  5998               HandleCaptureCompletion();
       
  5999               NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  6000               }
       
  6001           else
       
  6002               {
       
  6003               iSaveStarted = EFalse;
       
  6004               }
       
  6005           
       
  6006           // If we have returned from postcapture to precapture before 
       
  6007           // the filename has been sent to the gallery (i.e. pressing back
       
  6008           // key during image processing), iArrayUsageCount will be reduced 
       
  6009           // to zero and capture array will be released. In that case, we must
       
  6010           // send the filename to gallery before it happens.
       
  6011           if ( iArrayUsageCount == 1 )
       
  6012               {
       
  6013               NotifyControllerObservers( ECamEventMediaFileChanged );   
       
  6014               mediaFileChanged = ETrue;
       
  6015               }
       
  6016 
       
  6017           CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6018           if( iImageSaveActive && IsAppUiAvailable() )
       
  6019               {
       
  6020               if( iImageSaveActive->Count() <= 0 && ECamViewStatePostCapture != appUi->CurrentViewState() )
       
  6021                   {
       
  6022                   ReleaseArray();
       
  6023                   }
       
  6024               }
       
  6025           }
       
  6026         break;
       
  6027       case ECamImageCaptureTimeLapse:
       
  6028         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureTimeLapse") );
       
  6029         // If image capture has finished, but waiting for file to be saved.
       
  6030         if( ECamNoOperation == iInfo.iOperation || ECamCompleting == iInfo.iOperation )
       
  6031           {
       
  6032           PRINT( _L("Camera <> CCamAppController .. current file saved, complete this capture") );
       
  6033           SetOperation( ECamNoOperation );
       
  6034           ReleaseArray();
       
  6035           }
       
  6036         break;        
       
  6037       case ECamImageCaptureBurst:
       
  6038         PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. case ECamImageCaptureBurst") );
       
  6039         // After the whole burst has stopped, we get Image Stop event from Camera Controller,
       
  6040         // and enter completing state.
       
  6041         if( completing && savedAll )
       
  6042           {
       
  6043           // Modify this event to "burst complete" one.
       
  6044           aEvent = ECamSaveEventBurstComplete;
       
  6045           }
       
  6046         break;
       
  6047       default:
       
  6048         break;
       
  6049       } 
       
  6050 
       
  6051     NotifyControllerObservers( ECamEventSaveComplete );
       
  6052     }
       
  6053   
       
  6054   if ( aEvent == ECamSaveEventStarted )
       
  6055      {
       
  6056      if( iInfo.iImageMode == ECamImageCaptureSingle )
       
  6057          {
       
  6058          PRINT( _L("Camera <> CCamAppController::HandleSaveEvent .. Saving started") );
       
  6059          OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 1" ); //CCORAPP_PREP_FOR_NEXT_SHOT_START      
       
  6060          HandleCaptureCompletion();
       
  6061          NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  6062          iSaveStarted = ETrue;
       
  6063          NotifyControllerObservers( ECamEventSaveComplete );
       
  6064          iCaptureRequested = EFalse;
       
  6065          OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_APP_PREP_FOR_NEXT_SHOT 0" ); //CCORAPP_PREP_FOR_NEXT_SHOT_END
       
  6066          OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SHOT_TO_SHOT 0" ); //CCORAPP_PRI_SHOT_TO_SHOT_END   
       
  6067          }
       
  6068      }
       
  6069      
       
  6070   // If the user cancelled a save
       
  6071   if ( aEvent == ECamSaveEventUserCancelled )
       
  6072     {
       
  6073     PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. ECamSaveEventUserCancelled" ) )
       
  6074     //iInfo.iImageMode = ECamImageModeNone;
       
  6075     // Make sure that any further engine callbacks are ignored until next capture
       
  6076     SetOperation( ECamNoOperation );
       
  6077 
       
  6078     // Delete dummy files for unsaved images
       
  6079     TInt nextSavingImage = BurstCaptureArray()->NextFileIndex();
       
  6080     TInt lastImage = BurstCaptureArray()->Count();
       
  6081     TInt i;
       
  6082     // delete the next and following files
       
  6083     for ( i = nextSavingImage; i < lastImage; i++ )
       
  6084       {
       
  6085       SetAsCurrentImage( i );
       
  6086       DeleteCurrentFile();
       
  6087       }
       
  6088     SetAsCurrentImage( 0 );
       
  6089     // Empty out the array - this ensures the thumbnail view doesn't open
       
  6090     BurstCaptureArray()->Reset();
       
  6091 
       
  6092     NotifyControllerObservers( ECamEventSaveCancelled );
       
  6093     }
       
  6094     
       
  6095   // if a burst capture has completed
       
  6096   if ( aEvent == ECamSaveEventBurstComplete )
       
  6097     {
       
  6098     CompleteBurstOperation();
       
  6099 
       
  6100     if( ECamCompleting == iInfo.iOperation )
       
  6101       {
       
  6102       PRINT( _L( "Camera <> CCamAppController::HandleSaveEvent .. completing burst capture" ) )
       
  6103       SetOperation( ECamNoOperation );
       
  6104       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  6105       ReleaseArray();
       
  6106       }
       
  6107 
       
  6108     OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLESAVEEVENT, "e_CAM_PRI_SERIAL_SHOOTING 0" );  //CCORAPP_PRI_SERIAL_SHOOTING_END
       
  6109     }
       
  6110   else
       
  6111     {
       
  6112     if ( iImageSaveActive->Count() == 0 || aEvent == ECamSaveEventStarted )
       
  6113       {
       
  6114       iSaving = EFalse;
       
  6115       }        
       
  6116     }
       
  6117   if ( !mediaFileChanged )
       
  6118       {
       
  6119       NotifyControllerObservers( ECamEventMediaFileChanged );    
       
  6120       }
       
  6121 
       
  6122   PRINT( _L( "Camera <= CCamAppController::HandleSaveEvent" ) )
       
  6123   }
       
  6124 
       
  6125 
       
  6126 // ---------------------------------------------------------------------------
       
  6127 // HandleViewfinderFrame
       
  6128 // ---------------------------------------------------------------------------
       
  6129 //
       
  6130 void 
       
  6131 CCamAppController::HandleViewfinderFrame( TInt        /*aStatus*/, 
       
  6132                                           CFbsBitmap* /*aFrame*/ )
       
  6133   {
       
  6134   PRINT_FRQ( _L( "Camera => CCamAppController::HandleViewfinderFrame" ) );   
       
  6135 
       
  6136 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6137   // This function is called when a viewfinder bitmap arrives
       
  6138   if( EPerfWaitingForStartup == iPerformanceState )
       
  6139     {
       
  6140     iPerformanceState = EPerfIdle;
       
  6141     PERF_EVENT_END_L1( EPerfEventApplicationStartup );
       
  6142     }   
       
  6143   else if( EPerfWaitingForStillMode == iPerformanceState )
       
  6144     {
       
  6145     iPerformanceState = EPerfIdle;
       
  6146     PERF_EVENT_END_L1( EPerfEventSwitchToStillMode );
       
  6147     }
       
  6148   else if( EPerfWaitingForVideoMode == iPerformanceState )
       
  6149     {
       
  6150     iPerformanceState = EPerfIdle;
       
  6151     PERF_EVENT_END_L1( EPerfEventSwitchToVideoMode );
       
  6152     }
       
  6153   else if( EPerfWaitingForBurstFrame == iPerformanceState )
       
  6154     {
       
  6155     iPerformanceState = EPerfIdle;
       
  6156     PERF_EVENT_END_L1( EPerfEventBurstCaptureMomentToViewfinderFrame );
       
  6157     }
       
  6158 #endif
       
  6159 
       
  6160   if( ECamControllerVideo == iInfo.iMode )
       
  6161     {
       
  6162     // removed first vf frame usage as snapshot.
       
  6163     // snapshot received now from Camera 
       
  6164     }
       
  6165   else if( ECamControllerImage == iInfo.iMode )
       
  6166     {
       
  6167     // No need to duplicate here.
       
  6168     }
       
  6169   else
       
  6170     {
       
  6171     // Not valid state for vf frame.
       
  6172     __ASSERT_DEBUG( EFalse, CamPanic( ECamPanicInvalidState ) );
       
  6173     }
       
  6174 
       
  6175   if ( iZoomWaitingForCamera )
       
  6176     {
       
  6177     iZoomWaitingForCamera = EFalse;
       
  6178     if ( iNewZoomPending )
       
  6179       {
       
  6180       SetZoomValue( iDesiredZoomVal );
       
  6181       }
       
  6182     }
       
  6183   PRINT_FRQ( _L( "Camera <= CCamAppController::HandleViewfinderFrame" ) );
       
  6184   }
       
  6185 
       
  6186 
       
  6187 // ---------------------------------------------------------------------------
       
  6188 // ---------------------------------------------------------------------------
       
  6189 //
       
  6190 void CCamAppController::HandleSnapshotEvent( TInt aStatus,
       
  6191                                              CFbsBitmap* aBitmap )
       
  6192   {
       
  6193   PRINT1( _L( "Camera => CCamAppController::HandleSnapshotEvent, status:%d" ), aStatus );
       
  6194 
       
  6195 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6196   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6197     {
       
  6198     // Do not log in burst mode
       
  6199     PERF_EVENT_END_L1( EPerfEventShotToSnapshot );      
       
  6200     }
       
  6201   else
       
  6202     {
       
  6203     // In burst mode    
       
  6204     PERF_MESSAGE_L2( EPerfMessageBurstSnapshotReady );
       
  6205     }
       
  6206 #endif   
       
  6207 
       
  6208   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLESNAPSHOTEVENT, "e_CAM_APP_SHOT_TO_SNAPSHOT 0" );    //CCORAPP_SHOT_TO_SNAPSHOT_END
       
  6209 
       
  6210 // ---------------------------------------------------------------------------
       
  6211 // Video snapshot handling
       
  6212   if( ECamControllerVideo == iInfo.iMode )
       
  6213     {
       
  6214     PRINT( _L("Camera <> Snapshot in video mode") ); 
       
  6215     if( KErrNone == aStatus )
       
  6216       {
       
  6217       // Make a copy of the snapshot and set it as current video ss.        
       
  6218       CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6219       if( iSnapShotCopy )
       
  6220         {
       
  6221         if (BurstCaptureArray()->Count() > 0 )
       
  6222           {
       
  6223           const CFbsBitmap* tempSnapShotCopy = iSnapShotCopy;
       
  6224           TRAP_IGNORE( BurstCaptureArray()->ReplaceSnapshot( tempSnapShotCopy, 0 ) );	
       
  6225           } 
       
  6226         else
       
  6227           {
       
  6228           TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *iSnapShotCopy ) );	
       
  6229           }
       
  6230         }        
       
  6231       }
       
  6232       
       
  6233       // If video recording has already stopped, give snapshot event,
       
  6234       // which causes snapshot to be updated in postcapture view.
       
  6235       // 
       
  6236       // If recording is still in progress, the event would cause
       
  6237       // too early switch to pastcapture.
       
  6238       if( ECamNoOperation == iInfo.iOperation ||
       
  6239           ECamCompleting == iInfo.iOperation )
       
  6240         {  
       
  6241         NotifyControllerObservers( ECamEventSnapshotReady, aStatus );  
       
  6242         }        
       
  6243       
       
  6244     return;
       
  6245     }
       
  6246 
       
  6247 // ---------------------------------------------------------------------------
       
  6248 // Still snapshot handling
       
  6249 
       
  6250   PRINT( _L("Camera <> Snapshot in still mode") ); 
       
  6251 
       
  6252   if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  6253     {
       
  6254     // Update time lapse count during snapshot, so the update counter value
       
  6255     // appears at the same time as snapshot.  
       
  6256     iTimeLapseCaptureCount++;
       
  6257     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6258     }        
       
  6259   else if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6260     {
       
  6261     // Re-enable the screen saver if burst capture is completing. 
       
  6262     // This has to be done when all captures complete for timelapse.
       
  6263     // EnableScreenSaver( ETrue );
       
  6264     
       
  6265     NotifyControllerObservers( ECamEventCounterUpdated );  
       
  6266     iUpdateFrozenFrame = ETrue;    
       
  6267         
       
  6268     }
       
  6269 
       
  6270   // -------------------------------------------------------
       
  6271   // if there is an error with the still capture operation
       
  6272   if ( KErrNone != aStatus )
       
  6273     {
       
  6274     PRINT( _L("Camera <> CCamAppController: error in, cancel saving etc..") );
       
  6275     // Store this now, as it's cleared by TidyCaptureArray
       
  6276     // but needed a little later
       
  6277     TBool wasCapturingBurst = (ECamImageCaptureBurst == iInfo.iImageMode);
       
  6278 
       
  6279     iImageSaveActive->Cancel();
       
  6280 
       
  6281     TidyCaptureArray( BurstCaptureArray()->NextFileIndex(), aStatus );
       
  6282     PRINT( _L("Camera <> cancel further capturing") );
       
  6283     TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  6284 
       
  6285     NotifyControllerObservers( ECamEventSnapshotReady, aStatus );
       
  6286 
       
  6287     if ( wasCapturingBurst )
       
  6288       {
       
  6289       // Need this here to allow the AppUi to update the state correctly
       
  6290       // following the error condition.  This needs to be *after* the
       
  6291       // change to OperationNone (called in TidyCaptureArray) so when the 
       
  6292       // AppUi forces CBA update we're not still in burst capture state.
       
  6293       NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6294       }
       
  6295 
       
  6296     PRINT( _L( "Camera <> calling HandleCaptureCompletion()" ) )
       
  6297     HandleCaptureCompletion();
       
  6298     }
       
  6299   // -------------------------------------------------------
       
  6300   // No error reported
       
  6301   else
       
  6302     {
       
  6303     PRINT( _L("Camera <> CCamAppController: status in KErrNone..") );
       
  6304     __ASSERT_ALWAYS( aBitmap, CamPanic( ECamPanicNullPointer ) );
       
  6305     
       
  6306     // The secondary camera postcapture snapshot is rotated here. 
       
  6307     // Due to the viewfinder mirroring along the landscape axis the 
       
  6308     // portrait (or upside down portrait) postcapture snapshot would 
       
  6309     // otherwise be upside down.
       
  6310     // This affects the snapshot seen in postcapture view.
       
  6311    
       
  6312     if( iInfo.iActiveCamera == ECamActiveCameraSecondary &&
       
  6313         iCaptureOrientation == ECamOrientation180 &&
       
  6314         ECamSettOn == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) )
       
  6315         {
       
  6316         PRINT( _L( "Camera <> Rotate portrait secondary camera snapshot image 180 degrees" ) )
       
  6317         TRAP_IGNORE( iSnapShotRotator->RotateL( aBitmap ) );
       
  6318         }
       
  6319      
       
  6320     CopySnapshotIfNeeded( *aBitmap, aStatus );
       
  6321      
       
  6322     // Removed filename reservation when snapshot arrives.
       
  6323     // From now on, it's always done in HandleImageCaptureEvent,
       
  6324     // even if snapshot comes first.
       
  6325        
       
  6326     // This is being ignored, but there is nothing to display in the app
       
  6327     TRAP_IGNORE( BurstCaptureArray()->SetNextSnapshotL( *aBitmap ) )
       
  6328 
       
  6329     NotifyControllerObservers( ECamEventSnapshotReady );
       
  6330       
       
  6331     // If this is not a burst capture and snapshot came before image
       
  6332     // data, then the operation is now entering the completion phase.
       
  6333     // In case iFilenameReserved is set, imagedata has already
       
  6334     // arrived and we don't need to change state here.
       
  6335     if ( ECamCompleting != iInfo.iOperation && 
       
  6336          ECamImageCaptureBurst != iInfo.iImageMode && 
       
  6337          !iFilenameReserved )    
       
  6338       {  
       
  6339       SetOperation( ECamCompleting );      
       
  6340       }
       
  6341        
       
  6342     if( CurrentCapturedCount() < CaptureLimit() )
       
  6343         {
       
  6344         // Play capture sound for the next burst image
       
  6345         PlaySound( CaptureToneId(), EFalse );
       
  6346         }
       
  6347 
       
  6348     }
       
  6349   // -------------------------------------------------------
       
  6350 
       
  6351   PRINT( _L( "Camera <= CCamAppController::HandleSnapshotEvent" ) );    
       
  6352   }
       
  6353 
       
  6354 
       
  6355 // ---------------------------------------------------------------------------
       
  6356 // HandleImageCaptureEventL
       
  6357 // ---------------------------------------------------------------------------
       
  6358 //
       
  6359 void
       
  6360 CCamAppController::HandleImageCaptureEventL( TInt             aStatus, 
       
  6361                                              CCamBufferShare* aShare  )
       
  6362   {
       
  6363   PRINT1( _L("Camera => CCamAppController::HandleImageCaptureEventL, status:%d"), aStatus ); 
       
  6364 
       
  6365 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6366   if( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6367     {
       
  6368     // Do not log in burst mode
       
  6369     PERF_EVENT_END_L1( EPerfEventShotToStillImageReady );     
       
  6370     }
       
  6371   else
       
  6372     {
       
  6373     PERF_MESSAGE_L2( EPerfMessageBurstStillimageReady );
       
  6374     }
       
  6375 #endif // CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  6376 
       
  6377   OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLEIMAGECAPTUREEVENTL, "e_CAM_APP_SHOT_TO_STILL 0" );  //CCORAPP_SHOT_TO_STILL_END
       
  6378 /*
       
  6379   // Check if we need to stop the burst capture.        
       
  6380   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6381     {    
       
  6382     if( CurrentCapturedCount() < CaptureLimit() )
       
  6383       {
       
  6384       // Play capture sound for the next burst image
       
  6385       PlaySound( CaptureToneId(), EFalse );
       
  6386       }
       
  6387     }
       
  6388 */
       
  6389    // If we have all the needed snapshots set the flag
       
  6390    // so the processing image text is shown.
       
  6391    // Do it here instead of handlesnapshotevent so that
       
  6392    // the counter has time to show the last image as well 
       
  6393    if( CurrentCapturedCount() == CaptureLimit() )  
       
  6394        {
       
  6395        iAllSnapshotsReceived = ETrue;	
       
  6396        }
       
  6397         
       
  6398   if( KErrNone == aStatus )
       
  6399     {
       
  6400     PRINT( _L("Camera <> CCamAppController: image capture status KErrNone") );
       
  6401     aShare->Reserve();
       
  6402     CleanupStack::PushL( TCleanupItem( CamBufferShareCleanup, aShare ) );
       
  6403 
       
  6404     // Reserve filename for saving the image. In case there's problem
       
  6405     // with current media, switch to internal memory
       
  6406     TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) );
       
  6407     if( KErrNone != err )
       
  6408      {
       
  6409      if( ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) )
       
  6410        {
       
  6411        PRINT( _L("Camera <> Memory card access failed.") )
       
  6412        NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  6413        }            
       
  6414        // If we have got here, we can't access MMC. Switch to phone memory
       
  6415         
       
  6416      TRAP_IGNORE( ForceUsePhoneMemoryL() ); //with multiple drive support, 
       
  6417                                               //this actually uses the internal mass memory 
       
  6418      TRAPD(err, ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode ) ); 
       
  6419      if( KErrNone != err )
       
  6420       {
       
  6421       PRINT( _L("Camera <> Mass memory or phone memory access also failed.") )
       
  6422       TRAP_IGNORE( ForceUsePhoneMemoryL() );
       
  6423       TRAP_IGNORE( ReserveFileNamesL( iInfo.iMode, iInfo.iImageMode, ETrue ) );
       
  6424       }                 
       
  6425     }
       
  6426     
       
  6427     TBool markedForDelete = BurstCaptureArray()->IsNextImageDeleted();
       
  6428     PRINT1( _L("Camera <> Next image delete mark:%d"), markedForDelete );
       
  6429     if ( !markedForDelete )
       
  6430       {
       
  6431       PRINT( _L("Camera <> setting iImageSaveRequestPending to false"))
       
  6432       iImageSaveRequestPending = EFalse;
       
  6433       const TDesC& nextName( BurstCaptureArray()->NextFileName() );
       
  6434       PRINT( _L("Camera <> BurstCaptureArray()->NextFileName() returned") );
       
  6435       PRINT1( _L("Camera <> Set image to be saved, name:[%S]"), &nextName );
       
  6436       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6437       if( ( iInfo.iImageMode == ECamImageCaptureSingle ) 
       
  6438               && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto )
       
  6439               && iInfo.iActiveCamera == ECamActiveCameraPrimary
       
  6440               && !appUi->IsEmbedded() )
       
  6441           {
       
  6442           HandleSaveEvent( ECamSaveEventStarted );
       
  6443           }
       
  6444       TBool added = iImageSaveActive->AddToSave( nextName, aShare ); 
       
  6445       
       
  6446       if ( !added )
       
  6447         {
       
  6448         PRINT( _L("Camera <> Image saving start unsuccessful!") );
       
  6449         // The system state is consistent if this fails so ignore the error
       
  6450         }
       
  6451       else
       
  6452         {
       
  6453         PRINT( _L("Camera <> Image saving started ok.") );
       
  6454         // Ownership of the data has now been passed to CCamImageSaveActive
       
  6455         if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  6456           {          
       
  6457           NotifyControllerObservers( ECamEventImageData );  
       
  6458           }
       
  6459         PRINT1( _L("Camera <> CCamAppController::HandleImageCaptureEventL array count:%d"), BurstCaptureArray()->Count() );  
       
  6460 
       
  6461         // Snapshots are rotated here if necessary, so that the thumbnails created by 
       
  6462         // ThumbNailManager accurately represent the actual images.
       
  6463         // This affects the thumbnails seen in Photos.
       
  6464         
       
  6465         // check if snapshot bitmap needs to be rotated before creating a thumbnail from it
       
  6466         TBool rotate( ( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) || 
       
  6467                       iInfo.iActiveCamera == ECamActiveCameraSecondary ) &&
       
  6468                       iCaptureOrientation != ECamOrientation0 );
       
  6469 
       
  6470         if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  6471           {
       
  6472           //create thumbnail or rotate first if needed
       
  6473           if ( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  6474               {
       
  6475               if ( rotate )
       
  6476                   {
       
  6477                   RotateSnapshotL();
       
  6478                   }
       
  6479               else
       
  6480                   {       
       
  6481                   TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  6482                   }
       
  6483               } 
       
  6484           }
       
  6485         }
       
  6486       }
       
  6487     CleanupStack::PopAndDestroy(); // aShare->Release()
       
  6488     aShare = NULL;
       
  6489     }
       
  6490   else
       
  6491     {
       
  6492     PRINT( _L("Camera <> CCamAppController: capture status *not* KErrNone, mark current file for delete") );
       
  6493     DeleteCurrentFile();
       
  6494     }
       
  6495 
       
  6496 
       
  6497   iFilenameReserved = ETrue;
       
  6498 
       
  6499   PRINT( _L( "Camera <= CCamAppController::HandleImageCaptureEventL" ) );        
       
  6500   }
       
  6501 
       
  6502 
       
  6503 
       
  6504 // ---------------------------------------------------------------------------
       
  6505 // HandleImageStopEventL
       
  6506 // ---------------------------------------------------------------------------
       
  6507 //
       
  6508 void
       
  6509 CCamAppController::HandleImageStopEventL( TInt aStatus, TInt aFullCaptureCount )
       
  6510   {
       
  6511   PRINT2( _L("Camera => CCamAppController::HandleImageStopEventL, status:%d, full captures:%d"), aStatus, aFullCaptureCount );
       
  6512 
       
  6513   TBool saved = ( iImageSaveActive->Count()== 0 );
       
  6514 
       
  6515   switch( iInfo.iImageMode )
       
  6516     {
       
  6517     // -----------------------------------------------------
       
  6518     case ECamImageCaptureBurst:
       
  6519       {
       
  6520       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureBurst" ) );
       
  6521       // CompleteBurstOperation();
       
  6522      
       
  6523       // Re-enable screen saver
       
  6524       EnableScreenSaver( ETrue );
       
  6525       if( iBacklightTimer )
       
  6526         {
       
  6527         iBacklightTimer->Cancel();
       
  6528         }
       
  6529       
       
  6530       TInt started( iCameraController->ControllerInfo().iSnapshotCount );
       
  6531       if ( aFullCaptureCount < started )
       
  6532         {
       
  6533         PRINT ( _L("Camera <> CCamAppController .. [WARNING] Incomplete captures detected, cleaning up.." ) );
       
  6534         PRINT1( _L("Camera <> CCamAppController .. [WARNING] snapshot     count: %d"), started );
       
  6535         PRINT1( _L("Camera <> CCamAppController .. [WARNING] full capture count: %d"), aFullCaptureCount            );
       
  6536         PRINT1( _L("Camera <> CCamAppController .. [WARNING] burst array  count: %d"), BurstCaptureArray()->Count() );
       
  6537         TInt stopAt = Min( started, BurstCaptureArray()->Count() );
       
  6538         for ( TInt index = aFullCaptureCount; index < stopAt; index++ )
       
  6539           {
       
  6540           PRINT1( _L("Camera <> CCamAppController .. [WARNING] deleting temp file from index %d.."), index );
       
  6541           SetAsCurrentImage( index );
       
  6542           // Parameter: notify about file system change only on last delete.
       
  6543           DeleteCurrentFile( stopAt-1 == index );
       
  6544           }
       
  6545         PRINT1( _L("Camera <> CCamAppController .. [WARNING] setting as current image %d.."), aFullCaptureCount );
       
  6546         SetAsCurrentImage( aFullCaptureCount );
       
  6547         PRINT ( _L("Camera <> CCamAppController .. [WARNING] resetting burst array to required count..") );
       
  6548         BurstCaptureArray()->Reset( aFullCaptureCount );
       
  6549         }
       
  6550 
       
  6551       SetOperation( ECamCompleting );
       
  6552 
       
  6553       // We may have deleted all the images, so check the status here.
       
  6554       if( iImageSaveActive->Count()== 0 )
       
  6555         {
       
  6556         PRINT( _L( "Camera <> CCamAppController .. images already saved, completing burst capture" ) )
       
  6557         SetOperation( ECamNoOperation );
       
  6558         NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6559         ReleaseArray();
       
  6560         }
       
  6561       // if no images were taken, clear AssumePostCaptureView flag  
       
  6562       if ( started == 0 )
       
  6563         {
       
  6564         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6565         if ( appUi )
       
  6566           {
       
  6567           appUi->SetAssumePostCaptureView( EFalse );	
       
  6568           }	
       
  6569         }  
       
  6570       break;
       
  6571       }
       
  6572     // -----------------------------------------------------
       
  6573     case ECamImageCaptureSingle:
       
  6574       {
       
  6575       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureSingle" ) );
       
  6576 
       
  6577       // In secondary camera we can get snapshot as last event
       
  6578       // so we might still be in capturing state.
       
  6579       if( ECamCapturing == iInfo.iOperation )
       
  6580         {
       
  6581         PRINT( _L( "Camera <> CCamAppController .. still in capturing phase, set to completing first.." ) );
       
  6582         SetOperation( ECamCompleting );  
       
  6583         }
       
  6584 
       
  6585   	  // In case of secondary camera, image may be saved before Stop event is received.
       
  6586   	  // Notify capture complete event to the observers and other completion handling here.
       
  6587       if( saved && ECamCompleting == iInfo.iOperation )
       
  6588         {
       
  6589         PRINT( _L( "Camera <> CCamAppController .. file saved, complete capture" ) );
       
  6590 
       
  6591 		// Operation mode is also set in HandleCaptureCompletion
       
  6592 		HandleCaptureCompletion();
       
  6593 		NotifyControllerObservers( ECamEventCaptureComplete, aStatus );
       
  6594         ReleaseArray();
       
  6595         }
       
  6596       
       
  6597       break;
       
  6598       }
       
  6599     // -----------------------------------------------------
       
  6600     case ECamImageCaptureTimeLapse:
       
  6601       {
       
  6602       PRINT( _L( "Camera <> CCamAppController .. case ECamImageCaptureTimeLapse" ) );
       
  6603       if( saved )
       
  6604         {
       
  6605         PRINT( _L( "Camera <> CCamAppController .. current file saved, complete this capture" ) );
       
  6606         SetOperation( ECamNoOperation );
       
  6607         ReleaseArray();
       
  6608         }
       
  6609 
       
  6610       if ( iCompleteTimeLapsePending )
       
  6611         {
       
  6612         CompleteTimeLapseOperation();
       
  6613         }
       
  6614       else
       
  6615         {
       
  6616         // If the camera orientation changed during capture, set the new orientation in the engine
       
  6617         // ready for the next timelapse capture
       
  6618         if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  6619          		 && iOrientationChangeOccured )  
       
  6620           {
       
  6621           iOrientationChangeOccured = EFalse;
       
  6622           TRAP_IGNORE( SetImageOrientationL() );
       
  6623           }
       
  6624         }   
       
  6625       break;
       
  6626       }
       
  6627     // -----------------------------------------------------
       
  6628     default:
       
  6629       break;
       
  6630     // -----------------------------------------------------
       
  6631     }
       
  6632   PRINT( _L( "Camera <= CCamAppController::HandleImageStopEventL" ) );
       
  6633   }
       
  6634 
       
  6635 
       
  6636 // ---------------------------------------------------------------------------
       
  6637 // CCamAppController::IdleTimeoutL
       
  6638 // ---------------------------------------------------------------------------
       
  6639 //
       
  6640 TInt CCamAppController::IdleTimeoutL( TAny* aPtr )
       
  6641     {
       
  6642     return static_cast<CCamAppController*>( aPtr )->DoIdleTimeoutL();
       
  6643     }
       
  6644 
       
  6645 // ---------------------------------------------------------------------------
       
  6646 // CCamAppController::DoIdleTimeoutL
       
  6647 // ---------------------------------------------------------------------------
       
  6648 //
       
  6649 TInt CCamAppController::DoIdleTimeoutL()
       
  6650   {
       
  6651   // if a video recording has been paused for 60 seconds without key presses
       
  6652   if ( ECamPaused == CurrentVideoOperation() )
       
  6653     {
       
  6654     NotifyControllerObservers( ECamEventVideoPauseTimeout, KErrNone );
       
  6655     }
       
  6656 
       
  6657   // notify switch to standby mode and stop timer
       
  6658   else if( ECamStandby != iInfo.iOperation && ECamTriActive == iCameraController->ViewfinderState())
       
  6659     {
       
  6660     SetOperation( ECamStandby );
       
  6661     }
       
  6662   else
       
  6663     {
       
  6664     // For Lint
       
  6665     }
       
  6666 
       
  6667   iIdleTimer->Cancel();
       
  6668 
       
  6669 // Use backlight timer also with bitmap vf
       
  6670   if( iBacklightTimer )
       
  6671     {
       
  6672 	if( ECamTriActive == iCameraController->ViewfinderState() )
       
  6673 	  {
       
  6674 	  User::ResetInactivityTime();
       
  6675       }
       
  6676     iBacklightTimer->Cancel();
       
  6677     }
       
  6678 
       
  6679   return EFalse;
       
  6680   }
       
  6681 
       
  6682 // ---------------------------------------------------------------------------
       
  6683 // CCamAppController::StartIdleTimer
       
  6684 // ---------------------------------------------------------------------------
       
  6685 //
       
  6686 void CCamAppController::StartIdleTimer()
       
  6687   {
       
  6688   PRINT( _L( "Camera => CCamAppController::StartIdleTimer" ) ); 
       
  6689   // if in standby mode notify of switch back to pre-capture
       
  6690   if ( ECamStandby == iInfo.iOperation )
       
  6691     {
       
  6692     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer ECamStandby" ) );
       
  6693     SetOperation( ECamNoOperation );
       
  6694     }
       
  6695   // if recording is in progress don't go to standby
       
  6696   else if ( ECamCapturing == CurrentVideoOperation() )             
       
  6697     {
       
  6698     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer no restart" ) );
       
  6699     // don't restart if recording operation in progress
       
  6700     return;
       
  6701     }
       
  6702   // if recording is paused, use the idle timer to stop recording after 60 secs
       
  6703   else
       
  6704     {
       
  6705     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer else part" ) );
       
  6706     // empty else statement to remove LINT error
       
  6707     }
       
  6708 
       
  6709   // restart timer
       
  6710   iIdleTimer->Cancel();
       
  6711 
       
  6712   // don't restart if capturing burst, setting time lapse or in a pretend exit state
       
  6713   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6714   if ( !SequenceCaptureInProgress() && appUi && !appUi->IsInPretendExit() 
       
  6715        && !appUi->TimeLapseSliderShown())
       
  6716     {
       
  6717     // restart timer
       
  6718     PRINT( _L( "Camera <> CCamAppController::StartIdleTimer starting timer" ) );
       
  6719     iIdleTimer->StartTimer();
       
  6720     }
       
  6721 
       
  6722   if ( iDeepSleepTimer )
       
  6723     {
       
  6724     if ( iDeepSleepTimer->IsActive() )
       
  6725         {
       
  6726         PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - restart deep sleep timer" ) );
       
  6727         DeepSleepTimerCancel();
       
  6728         DeepSleepTimerStart();
       
  6729         }
       
  6730     else if ( iDeepSleepTimerExpired )
       
  6731         {
       
  6732         iDeepSleepTimerExpired = EFalse; // clear flag
       
  6733         TVwsViewId activeView;
       
  6734         CCamAppUi* appUi = 
       
  6735             static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  6736         (void) appUi->GetActiveViewId( activeView ); // ignore error
       
  6737         
       
  6738         if ( !IsViewFinding() && !InVideocallOrRinging() &&
       
  6739             activeView.iViewUid.iUid != ECamViewIdVideoPostCapture && 
       
  6740             activeView.iViewUid.iUid != ECamViewIdStillPostCapture &&
       
  6741             activeView.iViewUid.iUid != ECamViewIdBurstThumbnail )
       
  6742             {
       
  6743             PRINT( _L( "Camera <> CCamAppController::StartIdleTimer - Deep sleep timer expired. Restart VF" ) );
       
  6744             TCamCameraMode mode = CurrentMode() == ECamControllerVideo?
       
  6745                                   ECamControllerVideo : ECamControllerImage;
       
  6746             EnterViewfinderMode( mode ); 
       
  6747             DeepSleepTimerStart();
       
  6748             }
       
  6749         }
       
  6750     }
       
  6751 
       
  6752   PRINT( _L( "Camera <= CCamAppController::StartIdleTimer" ) );
       
  6753   }
       
  6754 
       
  6755 // ---------------------------------------------------------------------------
       
  6756 // CCamAppController::StopIdleTimer
       
  6757 // ---------------------------------------------------------------------------
       
  6758 //
       
  6759 void CCamAppController::StopIdleTimer()
       
  6760     {
       
  6761     PRINT( _L( "Camera => CCamAppController::StopIdleTimer" ) );
       
  6762     if( iIdleTimer )
       
  6763         {
       
  6764         iIdleTimer->Cancel();
       
  6765         }
       
  6766     PRINT( _L( "Camera <= CCamAppController::StopIdleTimer" ) );
       
  6767     }
       
  6768 
       
  6769 // ---------------------------------------------------------------------------
       
  6770 // CCamAppController::TimeLapseTimeoutL
       
  6771 // ---------------------------------------------------------------------------
       
  6772 //
       
  6773 TInt CCamAppController::TimeLapseTimeoutL( TAny* aPtr )
       
  6774     {
       
  6775     return static_cast<CCamAppController*>( aPtr )->DoTimeLapseTimeoutL();
       
  6776     }    
       
  6777     
       
  6778 // ---------------------------------------------------------------------------
       
  6779 // CCamAppController::DoTimeLapseTimeoutL
       
  6780 // ---------------------------------------------------------------------------
       
  6781 //
       
  6782 TInt CCamAppController::DoTimeLapseTimeoutL()
       
  6783   {
       
  6784   PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL" ))      
       
  6785   // Work out how much time is left before the next capture
       
  6786   TTime now;
       
  6787   now.HomeTime();
       
  6788   TTimeIntervalMicroSeconds elapsedTime = now.MicroSecondsFrom( iTimeLapseStartTime );
       
  6789   TInt64 remainingTime = iTimeLapseInterval.Int64() - elapsedTime.Int64();              
       
  6790   // update the remaining time countdown 
       
  6791   NotifyControllerObservers( ECamEventCounterUpdated );
       
  6792   
       
  6793   //if the total timelapse period has now completed
       
  6794   if ( remainingTime <= 0 )
       
  6795     {
       
  6796         // Workaround for DoTimeLapseTimeoutL firing while in inappropriate state
       
  6797     	// cause capture to be delayed by 1 sec 
       
  6798     	if( ECamNoOperation != iInfo.iOperation ) 
       
  6799     		{
       
  6800     		PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL workaround" ))      
       
  6801 			//remainingTime = TInt64( KSecondInMicSec );    	
       
  6802 		    iTimeLapseTimer->StartTimer();
       
  6803     		}    	
       
  6804 	else
       
  6805 		{
       
  6806 	    TInt remainingCount = ImagesRemaining( static_cast<TCamMediaStorage>( IntegerSettingValue( ECamSettingItemPhotoMediaStorage ) ), ETrue );
       
  6807 	    if ( remainingCount > 0 )
       
  6808 	      	{
       
  6809 	      PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL about to do next capture" ))   
       
  6810 	      // About to do the next capture so decrement the view's usage count on the array
       
  6811 	      ReleaseArray();
       
  6812             if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  6813                 {
       
  6814                 if( !CurrentSceneHasForcedFocus() )
       
  6815                     {
       
  6816                     if( !IsViewFinding() )
       
  6817                         {
       
  6818                         StartViewFinder();
       
  6819                         }
       
  6820                     StartAutoFocus();
       
  6821                     iCaptureRequested = ETrue; //Has to be set before focused/not focused event.
       
  6822                     }
       
  6823                 else
       
  6824                     {
       
  6825                     PRINT( _L("Camera <> CCamAppController::DoTimeLapseTimeoutL capture with forcedfocus scene" ))   
       
  6826                     Capture();            
       
  6827                     }
       
  6828                 }
       
  6829             else 
       
  6830                 {
       
  6831             	Capture();            
       
  6832                 }
       
  6833 			RestartTimeLapseTimerL();
       
  6834       	}
       
  6835 	    else
       
  6836 	     {
       
  6837 	     		PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL capture is complete" ))   
       
  6838 	      	CompleteTimeLapseOperation();
       
  6839 	     }
       
  6840 	   }              
       
  6841     return EFalse;
       
  6842     }
       
  6843   // Otherwise restart the timer for the next period    
       
  6844   else
       
  6845     {
       
  6846     if ( remainingTime < TInt64( KSecondInMicSec ) )
       
  6847       {
       
  6848       PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL shortening timer" ))   
       
  6849       iTimeLapseTimer->SetTimeout( (TInt)remainingTime );
       
  6850       }
       
  6851      else if(  ( remainingTime < TInt64( 5 *KSecondInMicSec )) && !iCameraWoken )
       
  6852      	{
       
  6853 		iCameraWoken = ETrue;
       
  6854 		if( !IsViewFinding() )
       
  6855 		{
       
  6856 			StartViewFinder();
       
  6857 		}
       
  6858 		User::ResetInactivityTime();     		
       
  6859      	}
       
  6860      
       
  6861     PRINT( _L("Camera => CCamAppController::DoTimeLapseTimeoutL restarting timer" ))               
       
  6862     iTimeLapseTimer->StartTimer();
       
  6863     }
       
  6864   return EFalse;        
       
  6865   }
       
  6866 
       
  6867 // ---------------------------------------------------------------------------
       
  6868 // CCamAppController::SupportedFlashModes
       
  6869 // Return flash modes supported engine
       
  6870 // ---------------------------------------------------------------------------
       
  6871 //
       
  6872 TUint32 CCamAppController::SupportedFlashModes()
       
  6873   {
       
  6874   if( iCameraController )
       
  6875     return iCameraController->CameraInfo().iFlashModesSupported;
       
  6876   else
       
  6877     return 0;
       
  6878   //iSupportedFlashModes;
       
  6879   }
       
  6880   
       
  6881 // ---------------------------------------------------------------------------
       
  6882 // CCamAppController::SupportedWBModes
       
  6883 // Return white balance modes supported engine
       
  6884 // ---------------------------------------------------------------------------
       
  6885 //  
       
  6886 TUint32 CCamAppController::SupportedWBModes()
       
  6887   {
       
  6888   if( iCameraController )
       
  6889     return iCameraController->CameraInfo().iWhiteBalanceModesSupported;
       
  6890   else
       
  6891     return 0;
       
  6892   //iSupportedWBModes;
       
  6893   }
       
  6894   
       
  6895 // ---------------------------------------------------------------------------
       
  6896 // CCamAppController::SupportedEVModes
       
  6897 // Return EV modes supported engine
       
  6898 // ---------------------------------------------------------------------------
       
  6899 //  
       
  6900 TUint32 CCamAppController::SupportedEVModes()
       
  6901   {
       
  6902   if( iCameraController )
       
  6903     return iCameraController->CameraInfo().iExposureModesSupported;
       
  6904   else
       
  6905     return 0;
       
  6906   //iSupportedEVModes;
       
  6907   } 
       
  6908 
       
  6909 // ---------------------------------------------------------------------------
       
  6910 // CCamAppController::CaptureState
       
  6911 // ---------------------------------------------------------------------------
       
  6912 //  
       
  6913 TInt CCamAppController::CaptureState()  
       
  6914   {
       
  6915   if( iCameraController )
       
  6916     {
       
  6917     return iCameraController->ControllerInfo().iCaptureState;
       
  6918     }
       
  6919   else
       
  6920     {
       
  6921     return KErrNotFound;
       
  6922     }
       
  6923   } 
       
  6924 
       
  6925 
       
  6926 
       
  6927 // -----------------------------------------------------------------------------
       
  6928 // CCamAppController::FlashStatus()
       
  6929 // Returns pointer to FlashStatus object
       
  6930 // -----------------------------------------------------------------------------
       
  6931 //
       
  6932 CCamFlashStatus* 
       
  6933 CCamAppController::FlashStatus() const
       
  6934   {
       
  6935   return iFlashStatus;    
       
  6936   }
       
  6937        
       
  6938 
       
  6939 // -----------------------------------------------------------------------------
       
  6940 // CCamAppController::FlashRequired()
       
  6941 // 
       
  6942 // -----------------------------------------------------------------------------
       
  6943 //
       
  6944 TBool 
       
  6945 CCamAppController::FlashRequired() const
       
  6946   {
       
  6947   if( ECamSceneSports == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  6948     {
       
  6949     // Flash is not required in sport scene, even if the flash mode
       
  6950     // is forced or redeye.
       
  6951     return EFalse;
       
  6952     }
       
  6953     
       
  6954   // Make decision based on current flash mode    
       
  6955   TInt flashMode = IntegerSettingValue( ECamSettingItemDynamicPhotoFlash );            
       
  6956   switch( flashMode )
       
  6957     {
       
  6958     case ECamFlashOff:
       
  6959       {
       
  6960       return EFalse;    
       
  6961       }
       
  6962     case ECamFlashAntiRedEye: // Flowthrough
       
  6963     case ECamFlashForced:
       
  6964       {
       
  6965       return ETrue;    
       
  6966       }
       
  6967     default:
       
  6968       {
       
  6969       // Just return true in the default case.
       
  6970       // Automatic mode will decide if flash is used or not.
       
  6971       return ETrue;
       
  6972       }
       
  6973     } 
       
  6974   }
       
  6975 
       
  6976 // -----------------------------------------------------------------------------
       
  6977 // CCamAppController::CheckFlash()
       
  6978 // 
       
  6979 // -----------------------------------------------------------------------------
       
  6980 //     
       
  6981 TBool 
       
  6982 CCamAppController::CheckFlash() const
       
  6983   {            
       
  6984   PRINT ( _L("Camera => CCamAppController::CheckFlash") );
       
  6985   PRINT1( _L("Camera <> CCamAppController:              flash required :%d  "), FlashRequired() );
       
  6986   PRINT1( _L("Camera <> CCamAppController: FlashStatus: flash ready    :%d  "), iFlashStatus->FlashReady() );
       
  6987   PRINT1( _L("Camera <> CCamAppController: CameraCtrl:  flash status   :[%s]"),
       
  6988           KCamCameraReadyStateNames[iCameraController->FlashState()] );
       
  6989 
       
  6990   TBool ok( !FlashRequired() || iFlashStatus->FlashReady() );
       
  6991 
       
  6992   PRINT1( _L("Camera <= CCamAppController::CheckFlash, return:%d"), ok );
       
  6993 #ifdef __WINSCW__
       
  6994   return ETrue;
       
  6995 #else  
       
  6996   return ok;
       
  6997 #endif  
       
  6998   }
       
  6999 
       
  7000 
       
  7001 // -----------------------------------------------------------------------------
       
  7002 // CCamAppController::SaveFlashMode()
       
  7003 // 
       
  7004 // -----------------------------------------------------------------------------
       
  7005 //    
       
  7006 void CCamAppController::SaveFlashMode()
       
  7007   {    
       
  7008   iFlashModeSaved  = ETrue;
       
  7009   iSavedFlashMode  = static_cast<TCamFlashId>( IntegerSettingValue( ECamSettingItemDynamicPhotoFlash ) );
       
  7010   iSavedFlashScene = static_cast<TCamSceneId>( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
  7011   }
       
  7012     
       
  7013 // -----------------------------------------------------------------------------
       
  7014 // CCamAppController::RestoreFlashMode
       
  7015 // 
       
  7016 // -----------------------------------------------------------------------------
       
  7017 //    
       
  7018 void CCamAppController::RestoreFlashMode()
       
  7019   {                
       
  7020   if( iFlashModeSaved )
       
  7021     {
       
  7022     if( iSavedFlashScene == IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) )
       
  7023       {
       
  7024       // Set saved flash mode    
       
  7025       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, iSavedFlashMode ) );
       
  7026       }
       
  7027     else
       
  7028       {
       
  7029       // Set default flash mode for this scene   
       
  7030       // SetDynamicSettingToDefault( ECamSettingItemDynamicPhotoFlash );          
       
  7031       TInt scene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  7032       TInt sceneFlashMode = iSettingsModel->SceneSettingValue( scene, ECamSettingItemSceneFlashMode );
       
  7033       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemDynamicPhotoFlash, sceneFlashMode ) );
       
  7034       
       
  7035       }
       
  7036     }
       
  7037   iFlashModeSaved = EFalse;   
       
  7038   }
       
  7039 
       
  7040 
       
  7041 // ---------------------------------------------------------------------------
       
  7042 // CCamAppController::ForceUsePhoneMemoryL
       
  7043 // ---------------------------------------------------------------------------
       
  7044 //
       
  7045 void CCamAppController::ForceUsePhoneMemoryL( TBool aEnable )
       
  7046 	{
       
  7047 	PRINT( _L("Camera => CCamAppController::ForceUsePhoneMemoryL") );
       
  7048 
       
  7049 	if( aEnable )
       
  7050 		{
       
  7051 		iForceUseOfPhoneMemory = ETrue;
       
  7052     if( ExistMassStorage() )
       
  7053       {
       
  7054       // with multiple drives, the mass memory is the default
       
  7055       PRINT( _L("Camera <> Force ECamMediaStorageMassStorage") );
       
  7056       iForcedStorageLocation = ECamMediaStorageMassStorage;
       
  7057       SetPathnamesToNewStorageL( ECamMediaStorageMassStorage );
       
  7058       }
       
  7059     else
       
  7060       {
       
  7061       PRINT( _L("Camera <> Force ECamMediaStoragePhone") );
       
  7062       TCamMediaStorage storage = IntegerSettingValue(ECamSettingItemRemovePhoneMemoryUsage)?
       
  7063                                   ECamMediaStorageNone:
       
  7064                                   ECamMediaStoragePhone;
       
  7065       iForcedStorageLocation = storage;
       
  7066       SetPathnamesToNewStorageL( storage );
       
  7067       }
       
  7068 		}
       
  7069 	// Revert back to memory card, if aEnable is EFalse
       
  7070 	else
       
  7071 		{
       
  7072 		iForceUseOfPhoneMemory = EFalse;
       
  7073     iForcedStorageLocation = ECamMediaStorageNone;
       
  7074     SetPathnamesToNewStorageL( iPreferredStorageLocation );
       
  7075 		}
       
  7076 
       
  7077 	NotifyControllerObservers( ECamEventSaveLocationChanged );
       
  7078 	PRINT( _L("Camera <= CCamAppController::ForceUsePhoneMemoryL") );
       
  7079 	}
       
  7080 
       
  7081 
       
  7082 
       
  7083 // ---------------------------------------------------------------------------
       
  7084 // CCamAppController::IsPhoneMemoryForced
       
  7085 // Check whether the use of phone memory is forced, because of unavailibility 
       
  7086 // or problems encountered in using MMC.
       
  7087 // ---------------------------------------------------------------------------
       
  7088 //
       
  7089 TBool CCamAppController::IsPhoneMemoryForced()
       
  7090 	{
       
  7091 	return iForceUseOfPhoneMemory;
       
  7092 	}
       
  7093 
       
  7094 // ---------------------------------------------------------------------------
       
  7095 // CCamAppController::CheckMemoryToUseL
       
  7096 // Set the appropriate memory to use. Use Phone memory if MMC not available.
       
  7097 // ---------------------------------------------------------------------------
       
  7098 //
       
  7099 TBool CCamAppController::CheckMemoryToUseL()
       
  7100 	{
       
  7101   TInt key = ( ECamControllerImage == CurrentMode() )
       
  7102                ? ECamSettingItemPhotoMediaStorage
       
  7103                : ECamSettingItemVideoMediaStorage;
       
  7104 
       
  7105   TCamMediaStorage storageLocation = static_cast<TCamMediaStorage> ( IntegerSettingValueUnfiltered(key) );
       
  7106   TBool mmcAvailable = IsMemoryAvailable ( ECamMediaStorageCard );
       
  7107     
       
  7108   PRINT1( _L("Camera :: CCamAppController::CheckMemoryToUse preferred storage:%d"), 
       
  7109               storageLocation );
       
  7110     
       
  7111   // If MMC is preferred storage location but is not available 
       
  7112 	if ( storageLocation == ECamMediaStorageCard && !mmcAvailable )
       
  7113 		{
       
  7114 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use phone memory / mass storage") )
       
  7115 		ForceUsePhoneMemoryL( ETrue );
       
  7116 		return ETrue;
       
  7117 		}
       
  7118 	// Preferred location is MMC and its available now -> stop forcing phone memory 
       
  7119 	else if( storageLocation == ECamMediaStorageCard && mmcAvailable && 
       
  7120 	         iForceUseOfPhoneMemory ) 
       
  7121 		{
       
  7122 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use MMC") )
       
  7123 		ForceUsePhoneMemoryL( EFalse );
       
  7124 		return ETrue;
       
  7125 		}
       
  7126   if ( storageLocation == ECamMediaStorageMassStorage && !ExistMassStorage() )
       
  7127 		{
       
  7128 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - no mass storage, use phone memory") )
       
  7129 		ForceUsePhoneMemoryL( ETrue );
       
  7130 		return ETrue;
       
  7131 		}
       
  7132 	// Mass storage is available now -> stop forcing phone memory
       
  7133 	else if( storageLocation == ECamMediaStorageMassStorage && ExistMassStorage() && iForceUseOfPhoneMemory ) 
       
  7134 		{
       
  7135 		PRINT( _L("Camera :: CCamAppController::CheckMemoryToUse - use mass memory") )
       
  7136 		ForceUsePhoneMemoryL( EFalse );
       
  7137 		return ETrue;
       
  7138 		}
       
  7139 	else
       
  7140 	  {
       
  7141 	  SetPathnamesToNewStorageL( storageLocation );
       
  7142 	  }
       
  7143 
       
  7144   return EFalse;
       
  7145 	}
       
  7146 
       
  7147 
       
  7148 
       
  7149 // ---------------------------------------------------------------------------
       
  7150 // CCamAppController::CompleteBurstOperation
       
  7151 // Complete the burst operation
       
  7152 // ---------------------------------------------------------------------------
       
  7153 //
       
  7154 void CCamAppController::CompleteBurstOperation()
       
  7155   {
       
  7156   PRINT( _L( "Camera => CCamAppController::CompleteBurstOperation" ) );
       
  7157   iSequenceCaptureInProgress = EFalse;
       
  7158   iNoBurstCancel=EFalse;
       
  7159   
       
  7160   if( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7161       {
       
  7162       PRINT1( _L("Camera <> CCamAppController::CompleteBurstOperation array count:%d"), BurstCaptureArray()->Count() );    
       
  7163       // Create thumbnails
       
  7164       if( iConfigManager && iConfigManager->IsThumbnailManagerAPISupported() )
       
  7165           {
       
  7166           TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *BurstCaptureArray() ) );
       
  7167           }
       
  7168       	
       
  7169       // Re-enable screen saver
       
  7170       EnableScreenSaver( ETrue );
       
  7171 	  if( iBacklightTimer )
       
  7172 		{
       
  7173 		iBacklightTimer->Cancel();
       
  7174 		}
       
  7175       SetOperation( ECamNoOperation );
       
  7176   
       
  7177       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );
       
  7178       HandleCaptureCompletion();
       
  7179       }
       
  7180   PRINT( _L( "Camera <= CCamAppController::CompleteBurstOperation" ) );          
       
  7181   }
       
  7182 
       
  7183 // ---------------------------------------------------------------------------
       
  7184 // CCamAppController::CompleteTimeLapseOperation
       
  7185 // Complete the time lapse operation
       
  7186 // ---------------------------------------------------------------------------
       
  7187 //
       
  7188 void CCamAppController::CompleteTimeLapseOperation()    
       
  7189     {
       
  7190     PRINT( _L( "Camera => CCamAppController::CompleteTimeLapseOperation" ) );
       
  7191 
       
  7192     iSequenceCaptureInProgress = EFalse;
       
  7193 
       
  7194     if ( iTimeLapseTimer )
       
  7195       {
       
  7196       iTimeLapseTimer->Cancel();
       
  7197       delete iTimeLapseTimer;
       
  7198       iTimeLapseTimer = NULL;
       
  7199       }
       
  7200 
       
  7201     if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  7202       {
       
  7203       // Re-enable screen saver
       
  7204       EnableScreenSaver( ETrue );
       
  7205       iCompleteTimeLapsePending = EFalse;
       
  7206   
       
  7207 //      SetImageMode( ECamImageCaptureNone );   
       
  7208       SetOperation( ECamNoOperation      );
       
  7209   
       
  7210       NotifyControllerObservers( ECamEventCaptureComplete, KErrNone );   
       
  7211       HandleCaptureCompletion();
       
  7212       iTimeLapseStartTime = TInt64( 0 );
       
  7213       }
       
  7214 
       
  7215     PRINT( _L( "Camera <= CCamAppController::CompleteTimeLapseOperation" ) );   
       
  7216     }
       
  7217 
       
  7218 
       
  7219 // ---------------------------------------------------------------------------
       
  7220 // CCamAppController::EngineProcessingCapture
       
  7221 // Return whether or not the engine is carrying out a capture operation
       
  7222 // ---------------------------------------------------------------------------
       
  7223 //
       
  7224 TBool 
       
  7225 CCamAppController::EngineProcessingCapture() const
       
  7226   {
       
  7227   TBool engineIsProcessing = EFalse;
       
  7228 
       
  7229   if ( ECamCapturing  == iInfo.iOperation
       
  7230     || ECamPausing    == iInfo.iOperation
       
  7231     || ECamPaused     == iInfo.iOperation
       
  7232     || ECamResuming   == iInfo.iOperation
       
  7233     || ECamCompleting == iInfo.iOperation 
       
  7234      )
       
  7235     {
       
  7236     engineIsProcessing = ETrue;
       
  7237     }
       
  7238 
       
  7239   return engineIsProcessing;
       
  7240   }
       
  7241 
       
  7242 // ---------------------------------------------------------------------------
       
  7243 // CCamAppController::HandleIncomingCall
       
  7244 // Stop video recording (or burst capture in early stages)
       
  7245 // ---------------------------------------------------------------------------
       
  7246 //
       
  7247 void CCamAppController::HandleIncomingCall()
       
  7248   {
       
  7249   PRINT2( _L("Camera => CCamAppController::HandleIncomingCallL .. mode[%s] operation[%s]"), 
       
  7250           KCamModeNames[iInfo.iMode], 
       
  7251           KCamCaptureOperationNames[iInfo.iOperation]
       
  7252         );
       
  7253 
       
  7254   if( ECamControllerVideo == iInfo.iMode )
       
  7255     {
       
  7256     // if video is recording or paused
       
  7257     if ( !iSaving
       
  7258       && ( ECamCapturing == iInfo.iOperation
       
  7259         || ECamPaused    == iInfo.iOperation ) )
       
  7260       {
       
  7261       StopVideoRecording();  
       
  7262       }
       
  7263     }
       
  7264   else if( ECamControllerImage == iInfo.iMode )
       
  7265     {
       
  7266     iCaptureRequested = EFalse;
       
  7267     switch( iInfo.iImageMode ) 
       
  7268       {
       
  7269       // if a timelapse operation is in progress
       
  7270       case ECamImageCaptureTimeLapse:
       
  7271         {
       
  7272         TRAP_IGNORE( StopSequenceCaptureL() );
       
  7273         break;
       
  7274         }
       
  7275       case ECamImageCaptureBurst:
       
  7276         {
       
  7277         TRAP_IGNORE( SoftStopBurstL( ETrue ) );
       
  7278         /*
       
  7279         if ( ECamCompleting == iInfo.iOperation )
       
  7280           {
       
  7281           // if some of the image captures failed
       
  7282           // release the reserved filenames and tidy the array
       
  7283           TInt captured( iCameraController->ControllerInfo().iCaptureCount );
       
  7284           if ( BurstCaptureArray()->NextFileIndex() < captured )
       
  7285             {
       
  7286             TInt index;
       
  7287             TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7288             for ( index = BurstCaptureArray()->NextFileIndex(); index < stopAt; index++ )
       
  7289               {
       
  7290               SetAsCurrentImage( index );
       
  7291               DeleteCurrentFile();
       
  7292               }
       
  7293             SetAsCurrentImage( 0 );
       
  7294       
       
  7295             BurstCaptureArray()->Reset( BurstCaptureArray()->NextFileIndex() );
       
  7296             // Finished with this now
       
  7297             }
       
  7298 //          SetImageMode( ECamImageCaptureNone );
       
  7299           if( iImageSaveActive )
       
  7300             iImageSaveActive->DismissProgressNote();
       
  7301           StartIdleTimer();
       
  7302           }
       
  7303         */
       
  7304         break;
       
  7305         }
       
  7306       default:
       
  7307         break;
       
  7308       }
       
  7309     }
       
  7310   else
       
  7311     {
       
  7312     // no action needed
       
  7313     }
       
  7314   PRINT( _L( "Camera <= CCamAppController::HandleIncomingCallL" ) ); 
       
  7315   }
       
  7316 
       
  7317     
       
  7318 // ---------------------------------------------------------------------------
       
  7319 // CCamAppController::FileSize
       
  7320 // Returns the file size of the specified captured item, or KErrNotFound if doesn't exist
       
  7321 // ---------------------------------------------------------------------------
       
  7322 //
       
  7323 TInt CCamAppController::FileSize( TDesC& aFilename ) const
       
  7324   {       
       
  7325   return iImageSaveActive->FileSize( aFilename );
       
  7326   }
       
  7327 
       
  7328 // ---------------------------------------------------------------------------
       
  7329 // CCamAppController::CancelStillCaptureNow
       
  7330 // Immediately cancels an ongoing still capture
       
  7331 // ---------------------------------------------------------------------------
       
  7332 //
       
  7333 void CCamAppController::CancelStillCaptureNow()
       
  7334   {
       
  7335   PRINT( _L( "Camera => CCamAppController::CancelStillCaptureNow" ) )
       
  7336   // Re-enable screen saver
       
  7337   EnableScreenSaver( ETrue ); 
       
  7338 //    iEngine->CancelCaptureStill();
       
  7339   TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  7340 
       
  7341   // ensure that any outstanding images are discarded
       
  7342   SetOperation( ECamCompleting  );
       
  7343   SetOperation( ECamNoOperation );
       
  7344 
       
  7345   // If sequence mode, remove items from the array
       
  7346   // this prevents the post capture view from showing
       
  7347   if ( ECamImageCaptureBurst == iInfo.iImageMode )
       
  7348     {
       
  7349     BurstCaptureArray()->Reset( 0 );
       
  7350     }   
       
  7351   else // single capture, the array is no longer needed
       
  7352     {
       
  7353     PRINT( _L( "Camera <> single capture so releasing array and starting vf" ) )
       
  7354     ReleaseArray();
       
  7355     FreezeViewFinder( EFalse );
       
  7356     }
       
  7357   // Cancel any pending saves, this will call CompleteBurstOperation for sequence
       
  7358   PRINT( _L( "Camera <> calling iImageSaveArray->Cancel" ) )
       
  7359   iImageSaveActive->Cancel(); 
       
  7360   PRINT( _L( "Camera <= CCamAppController::CancelStillCaptureNow" ) )
       
  7361   }
       
  7362     
       
  7363 
       
  7364 
       
  7365 // ---------------------------------------------------------------------------
       
  7366 // CCamAppController::TidyCaptureArray
       
  7367 // Tidy up capture array in event of burst capture failure
       
  7368 // ---------------------------------------------------------------------------
       
  7369 //
       
  7370 void
       
  7371 CCamAppController::TidyCaptureArray( TInt aImageCountDelivered, 
       
  7372                                      TInt /*aError*/               )
       
  7373   {
       
  7374   PRINT1( _L("Camera => CCamAppController::TidyCaptureArray img count %d"), aImageCountDelivered )
       
  7375   iSoundPlayer->EnableAllKeySounds();
       
  7376 
       
  7377   // if some of the image captures failed
       
  7378   // release the reserved filenames and tidy the array
       
  7379 
       
  7380   TInt captured( iCameraController->ControllerInfo().iSnapshotCount );
       
  7381   if ( aImageCountDelivered < captured )
       
  7382     {
       
  7383     TInt index;
       
  7384     TInt stopAt = Min( captured, BurstCaptureArray()->Count() );
       
  7385     for ( index = aImageCountDelivered; index < stopAt; index++ )
       
  7386       {
       
  7387       PRINT1( _L("Camera <> TidyCaptureArray delete current %d"),index )
       
  7388       SetAsCurrentImage( index );
       
  7389       DeleteCurrentFile();
       
  7390       }
       
  7391     SetAsCurrentImage( 0 );
       
  7392     iCaptureArray->Reset( aImageCountDelivered );
       
  7393     // Finished with this now
       
  7394     }
       
  7395 
       
  7396   SetImageMode( ECamImageCaptureNone );
       
  7397   StartIdleTimer();
       
  7398 
       
  7399   // Need to release the array
       
  7400   ReleaseArray();
       
  7401 
       
  7402 
       
  7403   // Unfreeze the viewfinder
       
  7404   FreezeViewFinder( EFalse );
       
  7405 
       
  7406   // Change op state to none
       
  7407   SetOperation( ECamNoOperation );
       
  7408 
       
  7409   PRINT( _L("Camera <= CCamAppController::TidyCaptureArray") )
       
  7410   }
       
  7411 
       
  7412 
       
  7413 // ---------------------------------------------------------------------------
       
  7414 // CCamAppController::CaptureToneId
       
  7415 // Returns the current capture tone
       
  7416 //
       
  7417 // ---------------------------------------------------------------------------
       
  7418 //
       
  7419 TCamSoundId CCamAppController::CaptureToneId( )
       
  7420   {
       
  7421   TCamSoundId toneId = ECamStillCaptureSoundId1;
       
  7422 
       
  7423   switch(iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoCaptureTone ) )
       
  7424     {
       
  7425     case ECamSettTone1:
       
  7426       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7427         {
       
  7428         toneId = ECamBurstCaptureSoundId1;
       
  7429         }
       
  7430       else 
       
  7431         {
       
  7432         toneId = ECamStillCaptureSoundId1;
       
  7433         }
       
  7434       break;
       
  7435     case ECamSettTone2:
       
  7436       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7437         {
       
  7438         toneId = ECamBurstCaptureSoundId2;
       
  7439         }
       
  7440       else 
       
  7441         {
       
  7442         toneId = ECamStillCaptureSoundId2;
       
  7443         }
       
  7444       break;
       
  7445     case ECamSettTone3:
       
  7446       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7447         {
       
  7448         toneId = ECamBurstCaptureSoundId3;
       
  7449         }
       
  7450       else 
       
  7451         {
       
  7452         toneId = ECamStillCaptureSoundId3;
       
  7453         }
       
  7454       break;
       
  7455     case ECamSettTone4:
       
  7456       if ( ECamImageCaptureBurst == iInfo.iImageMode ) 
       
  7457         {
       
  7458         toneId = ECamBurstCaptureSoundId4;
       
  7459         }
       
  7460       else 
       
  7461         {
       
  7462         toneId = ECamStillCaptureSoundId4;
       
  7463         }
       
  7464       break;
       
  7465     default:
       
  7466       break;
       
  7467     }
       
  7468 
       
  7469   return toneId;
       
  7470   }
       
  7471 
       
  7472 // ---------------------------------------------------------------------------
       
  7473 // CCamAppController::LoadSecondaryCameraSettingsL()
       
  7474 // Update settings for secondary camera
       
  7475 // ---------------------------------------------------------------------------
       
  7476 //  
       
  7477 void CCamAppController::LoadSecondaryCameraSettingsL()
       
  7478   {
       
  7479   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 1" );
       
  7480   PRINT( _L("Camera => CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7481   iSettingsModel->StorePrimaryCameraSettingsL();
       
  7482   iSettingsModel->StoreUserSceneSettingsL();
       
  7483 
       
  7484   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL B" ))
       
  7485   
       
  7486   SetIntegerSettingValueL( ECamSettingItemPhotoQuality, 
       
  7487                            iConfiguration->SecondaryCameraImageQuality() );
       
  7488   PRINT(  _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL C" ))
       
  7489   SetIntegerSettingValueL( ECamSettingItemVideoQuality,
       
  7490                            iConfiguration->SecondaryCameraVideoQuality() );  
       
  7491 
       
  7492 
       
  7493   // Remember the previous state of face tracking,
       
  7494   // current state of face tracking and
       
  7495   // the previous scene mode
       
  7496   TCamSettingsOnOff previousFaceTrack = iSettingsModel->GetPreviousFaceTrack();
       
  7497   TCamSettingsOnOff faceTracking = static_cast<TCamSettingsOnOff>( IntegerSettingValue( ECamSettingItemFaceTracking ) );
       
  7498   TCamSceneId previousSceneMode = iSettingsModel->GetPreviousSceneMode();
       
  7499   
       
  7500   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL E" ))
       
  7501   SetIntegerSettingValueL( ECamSettingItemDynamicPhotoScene, ECamSceneAuto );
       
  7502   SetIntegerSettingValueL( ECamSettingItemDynamicVideoScene, ECamSceneNormal );
       
  7503   
       
  7504 
       
  7505   // Restore the previous state of face tracking,
       
  7506   // current state of face tracking and
       
  7507   // the previous scene mode
       
  7508   iSettingsModel->SetPreviousFaceTrack( previousFaceTrack );
       
  7509   SetIntegerSettingValueL( ECamSettingItemFaceTracking, faceTracking );
       
  7510   iSettingsModel->SetPreviousSceneMode( previousSceneMode );
       
  7511   
       
  7512   PRINT( _L("Camera <> CCamAppController::LoadSecondaryCameraSettingsL F" ))
       
  7513 
       
  7514   PRINT( _L("Camera <= CCamAppController::LoadSecondaryCameraSettingsL" ))
       
  7515   OstTrace0( CAMERAAPP_PERFORMANCE_DETAIL, DUP1_CCAMAPPCONTROLLER_LOADSECONDARYCAMERASETTINGSL, "e_CCamAppController_LoadSecondaryCameraSettingsL 0" );
       
  7516   }
       
  7517 
       
  7518 // ---------------------------------------------------------------------------
       
  7519 // ImageOrientation <<public>>
       
  7520 //
       
  7521 // Return the current image orientation based on data from orientation sensor.
       
  7522 // If "image rotation" setting is OFF, the value has been overriden with 
       
  7523 // "no rotation" value (ECamOrientation0).
       
  7524 // 
       
  7525 // Provided (primarily) for Camera Controller even if orientation
       
  7526 // sensor is not supported. In that case the returned
       
  7527 // value is always ECamOrientation0.
       
  7528 // ---------------------------------------------------------------------------
       
  7529 //
       
  7530 TCamImageOrientation 
       
  7531 CCamAppController::ImageOrientation() const
       
  7532   {
       
  7533   return iImageOrientation;
       
  7534   }
       
  7535 
       
  7536 
       
  7537 // ---------------------------------------------------------------------------
       
  7538 // Indicates data is available in the receiving buffer. A client can read 
       
  7539 // the data through GetData()-function in the related channel object. Data 
       
  7540 // is valid until the data received notification occurs again.
       
  7541 //
       
  7542 // @param[in] aChannel Reference to the related channel object
       
  7543 // @param[in] aCount Data object count in receiving buffer. Not used in this implementation.
       
  7544 // @param[in] aDataLost Number of lost data items. Not used in this implementation. It does not
       
  7545 //     matter if some data event is lost.
       
  7546 // ---------------------------------------------------------------------------
       
  7547 //
       
  7548 void CCamAppController::DataReceived( CSensrvChannel& aChannel, 
       
  7549                                       TInt aCount, 
       
  7550                                       TInt aDataLost )
       
  7551     {
       
  7552     PRINT3( _L("Camera => CCamAppController::DataReceived aChannel %d aCount %d aDataLost %d"), 
       
  7553                 aChannel.GetChannelInfo().iChannelType, aCount, aDataLost );
       
  7554 
       
  7555     if ( KSensrvChannelTypeIdOrientationData == aChannel.GetChannelInfo().iChannelType )
       
  7556         {
       
  7557         // Rotation is used in primary camera whenever the feature is enabled by user.
       
  7558         // A rotation is always set for secondary camera in portrait and upside down
       
  7559         // portrait orientations due to the the viewfinder mirroring along the landscape axis.
       
  7560         // This affects the final JPEG file.
       
  7561         TBool rotate( ECamSettOn == iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) 
       
  7562                       || iInfo.iActiveCamera == ECamActiveCameraSecondary );
       
  7563 
       
  7564         if( rotate )
       
  7565             {
       
  7566             TSensrvOrientationData orientationData;
       
  7567             TPckg<TSensrvOrientationData> orientationPackage( orientationData );
       
  7568             aChannel.GetData( orientationPackage );
       
  7569 
       
  7570             iImageOrientation =
       
  7571                 MapSensorOrientatio2CamOrientation( orientationData.iDeviceOrientation, 
       
  7572                                                     iLastImageOrientation, 
       
  7573                                                     iInfo.iActiveCamera );
       
  7574             }
       
  7575         else
       
  7576             {
       
  7577             // If "rotate images" setting is OFF, set "no rotation" value
       
  7578             iImageOrientation = ECamOrientation0;
       
  7579             }
       
  7580         
       
  7581         // rotate image if we are in still capture mode but not currently
       
  7582         // capturing image, no rotation in burst mode or if orientation has stayed the same
       
  7583         if( IsFlagOn( CameraControllerState(), ECamImageOn ) && 
       
  7584             rotate && 
       
  7585             iLastImageOrientation != iImageOrientation &&
       
  7586             iImageOrientation != ECamOrientationIgnore)
       
  7587             {
       
  7588             if( ECamCapturing   != CurrentOperation() &&
       
  7589                 ECamFocusing    != CurrentOperation() &&
       
  7590                 ECamFocused     != CurrentOperation() &&
       
  7591                 ECamFocusFailed != CurrentOperation() &&
       
  7592                 ECamCompleting  != CurrentOperation() &&
       
  7593                 ECamImageCaptureBurst != iInfo.iImageMode &&
       
  7594                 ECamImageCaptureBurst != iInfo.iTargetImageMode )
       
  7595                 {
       
  7596                 PRINT( _L("Camera <> CCamAppController:DataReceived calling SetImageOrientationL()") );	
       
  7597                 TRAP_IGNORE( SetImageOrientationL() );
       
  7598                 }
       
  7599             else
       
  7600                 {
       
  7601                 // queue a request to re-prepare still capture
       
  7602                 PRINT( _L("Camera <> CCamAppController: Queueing an orientation change event") );	
       
  7603                 iOrientationChangeOccured = ETrue;
       
  7604                 }
       
  7605             }
       
  7606         else
       
  7607             {
       
  7608             iOrientationChangeOccured = EFalse;
       
  7609             }
       
  7610         
       
  7611         if( iImageOrientation != ECamOrientationIgnore )    
       
  7612             {
       
  7613             iLastImageOrientation = iImageOrientation; 	           
       
  7614             }
       
  7615         }
       
  7616 
       
  7617     PRINT ( _L("Camera <= CCamAppController::DataReceived") );
       
  7618     }
       
  7619 
       
  7620 // ---------------------------------------------------------------------------
       
  7621 // Data listening failed. 
       
  7622 // If error was fatal, channel has also been closed and sensor server session 
       
  7623 // terminated. If error was minor, some data has potentially been lost.
       
  7624 // iAccSensorChannel needs to be closed in fatal error case. A new channel will
       
  7625 // be created the next time we call UpdateSensorApiL().
       
  7626 //
       
  7627 // @param[in] aChannel Reference to the related channel object
       
  7628 // @param[in] aError Error code.
       
  7629 // ---------------------------------------------------------------------------
       
  7630 //
       
  7631 void CCamAppController::DataError( CSensrvChannel& aChannel, 
       
  7632                                    TSensrvErrorSeverity aError )
       
  7633     {
       
  7634     PRINT2( _L("Camera => CCamAppController::DataError aChannel %d aError %d"), aChannel.GetChannelInfo().iChannelType, aError );	
       
  7635     if ( ESensrvErrorSeverityFatal == aError ) 
       
  7636         {
       
  7637         // Delete sensor api object
       
  7638         delete iAccSensorChannel;
       
  7639         iAccSensorChannel = NULL;
       
  7640         iAccSensorListening = EFalse;
       
  7641 
       
  7642         // Set orientation back to default if not already there.
       
  7643         iImageOrientation   = ECamOrientation0;
       
  7644         }
       
  7645     }
       
  7646 
       
  7647 // ---------------------------------------------------------------------------
       
  7648 // Returns a pointer to a specified interface 
       
  7649 //
       
  7650 // @since S60 5.0
       
  7651 // @param aInterfaceUid Identifier of the interface to be retrieved
       
  7652 // @param aInterface A reference to a pointer that retrieves the specified interface.
       
  7653 // ---------------------------------------------------------------------------
       
  7654 //
       
  7655 void CCamAppController::GetDataListenerInterfaceL( TUid aInterfaceUid, 
       
  7656                                                    TAny*& aInterface )
       
  7657     {
       
  7658     aInterface = NULL;
       
  7659     }                                
       
  7660                                         
       
  7661 // ---------------------------------------------------------------------------
       
  7662 // CCamAppController::SetImageOrientationL()
       
  7663 // Setup image rotation parameters
       
  7664 //
       
  7665 // ---------------------------------------------------------------------------
       
  7666 //  
       
  7667 void CCamAppController::SetImageOrientationL()
       
  7668     {
       
  7669     PRINT( _L("Camera => CCamAppController::SetImageOrientationL") );
       
  7670     if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  7671     		&& iCameraController )
       
  7672         {
       
  7673         // Camera controller asks for the current orientation through
       
  7674         // our ImageOrientation(). Value for that was updated in 
       
  7675         // DataReceived() callback.
       
  7676         iCameraController->DirectSettingsChangeL( ECameraSettingOrientation );
       
  7677         }
       
  7678     PRINT( _L("Camera <= CCamAppController::SetImageOrientationL"))   
       
  7679     }
       
  7680 
       
  7681 
       
  7682 // ---------------------------------------------------------------------------
       
  7683 // MapSensorOrientatio2CamOrientation
       
  7684 // ---------------------------------------------------------------------------
       
  7685 //
       
  7686 TCamImageOrientation 
       
  7687 CCamAppController::MapSensorOrientatio2CamOrientation( 
       
  7688     const TSensrvOrientationData::TSensrvDeviceOrientation& aSensorOrientation, TCamImageOrientation aLastImageOrientation,
       
  7689     TCamActiveCamera aActiveCamera )
       
  7690     {
       
  7691     PRINT1 ( _L("Camera => CCamAppController::MapSensorOrientatio2CamOrientation aSensorOrientation: %d"), aSensorOrientation );   
       
  7692 
       
  7693     TCamImageOrientation cameraOrientation( ECamOrientation0 );
       
  7694 
       
  7695     // Primary camera rotation
       
  7696     if ( aActiveCamera == ECamActiveCameraPrimary ) 
       
  7697       {
       
  7698       switch( aSensorOrientation )
       
  7699         {        
       
  7700         case TSensrvOrientationData::EOrientationDisplayUpwards:
       
  7701             // If coming from upside down portrait...
       
  7702             if ( ECamOrientation270 == aLastImageOrientation )
       
  7703               {
       
  7704             	// Switch from upside down portrait to normal portrait.") )
       
  7705               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7706               }
       
  7707             // If coming from upside down landscape...
       
  7708             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7709               {
       
  7710             	// Switch from upside down landscape to normal landscape...") )
       
  7711               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7712               }
       
  7713             // If neither one, keep the current image orientation.
       
  7714             else
       
  7715               {
       
  7716               cameraOrientation = ECamOrientationIgnore;
       
  7717               }
       
  7718             break;
       
  7719 
       
  7720         case TSensrvOrientationData::EOrientationDisplayDownwards:
       
  7721         	  // Camera is pointing up now. Check if it was upside down previously.
       
  7722             // If coming from upside down portrait...
       
  7723             if ( ECamOrientation270 == aLastImageOrientation )
       
  7724               {
       
  7725             	// Switch from upside down portrait to normal portrait...") )
       
  7726               cameraOrientation = ECamOrientation90; // Set normal portrait
       
  7727               }
       
  7728             // If coming from upside down landscape...
       
  7729             else if ( ECamOrientation180 == aLastImageOrientation )
       
  7730               {
       
  7731             	// Switch from upside down landscape to normal landscape...") )
       
  7732               cameraOrientation = ECamOrientation0; // Set normal lanscape
       
  7733               }
       
  7734             // If neither one, keep the current image orientation.
       
  7735             else
       
  7736               {
       
  7737               cameraOrientation = ECamOrientationIgnore;
       
  7738               }
       
  7739         	  break;
       
  7740         case TSensrvOrientationData::EOrientationDisplayRightUp:            
       
  7741         case TSensrvOrientationData::EOrientationUndefined:
       
  7742             cameraOrientation = ECamOrientation0;     
       
  7743             break;
       
  7744         case TSensrvOrientationData::EOrientationDisplayUp:
       
  7745             cameraOrientation = ECamOrientation90;
       
  7746             break;
       
  7747         case TSensrvOrientationData::EOrientationDisplayLeftUp:
       
  7748             cameraOrientation = ECamOrientation180;
       
  7749             break;
       
  7750         case TSensrvOrientationData::EOrientationDisplayDown:
       
  7751             cameraOrientation = ECamOrientation270;
       
  7752             break;
       
  7753         default:
       
  7754             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7755             break;
       
  7756         }
       
  7757       }
       
  7758     // Secondary camera rotations
       
  7759     else if ( aActiveCamera == ECamActiveCameraSecondary )
       
  7760       {
       
  7761       if ( aSensorOrientation == TSensrvOrientationData::EOrientationDisplayUp ) // Portrait
       
  7762         {
       
  7763         cameraOrientation = ECamOrientation180; 
       
  7764         }
       
  7765       else if ( aSensorOrientation == TSensrvOrientationData::EOrientationDisplayDown )  // Upside down portrait
       
  7766         {
       
  7767         cameraOrientation = ECamOrientation180;
       
  7768         }
       
  7769       else
       
  7770         {
       
  7771         cameraOrientation = ECamOrientation0;
       
  7772         }
       
  7773       }
       
  7774       
       
  7775     PRINT1( _L("Camera <= CCamAppController::MapSensorOrientatio2CamOrientation, return [%s]"), 
       
  7776             KCamOrientationNames[cameraOrientation] );
       
  7777 
       
  7778     return cameraOrientation;
       
  7779     }
       
  7780 
       
  7781 // ---------------------------------------------------------------------------
       
  7782 // MapCamOrientation2RotationAngle
       
  7783 // ---------------------------------------------------------------------------
       
  7784 //
       
  7785 CBitmapRotator::TRotationAngle 
       
  7786 CCamAppController::MapCamOrientation2RotationAngle( 
       
  7787                    const TCamImageOrientation aOrientation )
       
  7788     {
       
  7789     PRINT1 ( _L("Camera => CCamAppController::MapCamOrientation2RotationAngle aOrientation: %d"), aOrientation );   
       
  7790 
       
  7791     CBitmapRotator::TRotationAngle angle;
       
  7792     
       
  7793     switch( aOrientation )
       
  7794         {        
       
  7795         case ECamOrientation90:
       
  7796             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7797             break;
       
  7798         case ECamOrientation180:
       
  7799             angle = CBitmapRotator::ERotation180DegreesClockwise;
       
  7800             break;
       
  7801         case ECamOrientation270:
       
  7802             angle = CBitmapRotator::ERotation270DegreesClockwise;
       
  7803             break;
       
  7804         default:
       
  7805             PRINT( _L("Camera <> Unexpected orientation value") );
       
  7806             // using a value to avoid compiler warning
       
  7807             angle = CBitmapRotator::ERotation90DegreesClockwise;
       
  7808             break;
       
  7809         }
       
  7810     PRINT1( _L("Camera <= CCamAppController::MapCamOrientation2RotationAngle, return %d"), angle );
       
  7811     return angle;    
       
  7812     }
       
  7813         
       
  7814         
       
  7815 // ---------------------------------------------------------------------------
       
  7816 // CCamAppController::UpdateSensorApiL() <<public>>
       
  7817 // Updates the sensorApi object when the app focus changes
       
  7818 //
       
  7819 // ---------------------------------------------------------------------------
       
  7820 //  
       
  7821 
       
  7822 void CCamAppController::UpdateSensorApiL(TBool aStartupApi) 
       
  7823     {
       
  7824     PRINT(_L("Camera => CCamAppController::UpdateSensorApiL"));
       
  7825     if( iConfigManager && iConfigManager->IsOrientationSensorSupported() )
       
  7826     	{
       
  7827 	    if(aStartupApi)
       
  7828 	        {
       
  7829 	        // only activate the orientation channel for image mode	
       
  7830 	        if( ECamControllerImage == CurrentMode() )
       
  7831 	          {
       
  7832 	        // This if-statement intentionally not a condition of the first if.
       
  7833 	        // If the iAccSensorChannel is already active, we don't want to recreate it
       
  7834 	        // and leak memory, but at the same time, we don't want to destroy it either.
       
  7835 	        
       
  7836 	        if( !iAccSensorChannel )
       
  7837 	            {
       
  7838 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - Starting new sensor channel api - info not yet initialized"));
       
  7839 	            //Construct a channel finder.
       
  7840 	            CSensrvChannelFinder* channelFinder;
       
  7841 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannelFinder::NewL()"));
       
  7842 	            //CSensorChannelFinder* channelFinder;
       
  7843 	            channelFinder = CSensrvChannelFinder::NewL();
       
  7844 	            //channelFinder = CSensorChannelFinder::NewL();
       
  7845 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - CSensrvChannelFinder::NewL() returned without a leave"));
       
  7846 	            CleanupStack::PushL( channelFinder );    
       
  7847 	            
       
  7848 	            //List of found channels.
       
  7849 	            RSensrvChannelInfoList channelInfoList;
       
  7850 	            CleanupClosePushL( channelInfoList );
       
  7851 	  
       
  7852 	            //Create and fill channel search criteria.
       
  7853 	            TSensrvChannelInfo channelInfo;
       
  7854 	            channelInfo.iChannelType = KSensrvChannelTypeIdOrientationData;
       
  7855 	        
       
  7856 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling channelFinder->FindChannelsL"));
       
  7857 	            //Find the orientation channel
       
  7858 	            channelFinder->FindChannelsL( channelInfoList, channelInfo );
       
  7859 	           
       
  7860 	            if( channelInfoList.Count() != 1 )
       
  7861 	                {
       
  7862 	                //The device doesn’t support orientation data channel or
       
  7863 	                //there are several orientation channels.
       
  7864 	                PRINT1(_L("Camera <=> CCamAppController::UpdateSensorApiL - The device doesn’t support orientation data channel or there are several orientation channels: %d channels found"),channelInfoList.Count());
       
  7865 	                User::Leave( KErrNotSupported );
       
  7866 	                }
       
  7867 	            else
       
  7868 	                {
       
  7869 	                //orientation channel found 
       
  7870 	                PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - orientation channel found"));
       
  7871 	                }
       
  7872 	            //Open the orientation channel.
       
  7873 	            //When the channel object is created the channel info object 
       
  7874 	            //must be an object returned by CSensrvChannelFinder::FindChannelsL().
       
  7875 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling CSensrvChannel::NewL"));
       
  7876 	            iAccSensorChannel = CSensrvChannel::NewL( channelInfoList[ 0 ] );
       
  7877 	            //iAccSensorChannel = CSensorChannel::NewL( channelInfoList[ 0 ] );
       
  7878 	            //CleanupStack::PushL( iAccSensorChannel ); 
       
  7879 	            CleanupStack::PopAndDestroy( &channelInfoList ); //Close() is being called on "channelInfoList"
       
  7880 	            CleanupStack::PopAndDestroy( channelFinder );
       
  7881 	          }
       
  7882 	        
       
  7883 	        if( !iAccSensorListening )
       
  7884 	            {
       
  7885 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->OpenChannelL()"));
       
  7886 	            TRAPD(channelerror, iAccSensorChannel->OpenChannelL() );
       
  7887 	            if (channelerror!=KErrNone)
       
  7888 	                {
       
  7889 	                PRINT1(_L("CCamAppController::UpdateSensorApiL - iAccSensorChannel->OpenChannelL() failed. Error code: %d"),channelerror);
       
  7890 	                User::Leave( channelerror );
       
  7891 	                }
       
  7892 	            //iAccSensorChannel->OpenChannelL();
       
  7893 	            //orientation channel is now open.
       
  7894 	            
       
  7895 	            // start listening
       
  7896 	            PRINT(_L("Camera <=> CCamAppController::UpdateSensorApiL - calling iAccSensorChannel->StartDataListeningL"));
       
  7897 	            iAccSensorChannel->StartDataListeningL( this, //this object is data listener for this channel
       
  7898 	                                                   1, //aDesiredCount is one, i.e. each orientation change is notified separately
       
  7899 	                                                   1, //aMaximumCount is one, i.e. object count in receiving data buffer is one
       
  7900 	                                                   0 );//buffering period is not used
       
  7901 	            iAccSensorListening = ETrue;
       
  7902 	            iLastImageOrientation = ECamOrientation0;
       
  7903 	            }
       
  7904 	          }
       
  7905 	        }
       
  7906 	    else // shut down the sensorApi object
       
  7907 	        {
       
  7908 	        PRINT(_L("Camera <=> UpdateSensorApiL shutting down iAccSensor"))
       
  7909 	        if(iAccSensorListening)
       
  7910 	            {
       
  7911 	            // Stop listening to the events
       
  7912 	            iAccSensorChannel->StopDataListening();
       
  7913 	            iAccSensorListening = EFalse;
       
  7914 	            }
       
  7915 	            
       
  7916 	        // Delete sensor api object
       
  7917 	        delete iAccSensorChannel;
       
  7918 	        iAccSensorChannel = NULL;
       
  7919 	        }
       
  7920       }
       
  7921     PRINT(_L("Camera <= CCamAppController::UpdateSensorApiL"));
       
  7922     }
       
  7923 
       
  7924 
       
  7925 
       
  7926 // ---------------------------------------------------------------------------
       
  7927 // CCamAppController::HandlePropertyChangedL()
       
  7928 // Handle changes in specified property
       
  7929 //
       
  7930 // ---------------------------------------------------------------------------
       
  7931 //  
       
  7932 void CCamAppController::HandlePropertyChangedL( const TUid& aCategory, const TUint aKey )
       
  7933   {
       
  7934   PRINT( _L("Camera => CCamAppController::HandlePropertyChangedL"))
       
  7935 #if !( defined(__WINS__) || defined(__WINSCW__) )  
       
  7936   
       
  7937   if ( iConfigManager && iConfigManager->IsLensCoverSupported() )
       
  7938       { 
       
  7939       // First if condition could be removed after PCFW has released 
       
  7940       // creation for KLensCoverStatus key
       
  7941       if ( ( aCategory == NMusResourceApi::KCategoryUid && 
       
  7942            aKey == NMusResourceApi::KCameraAvailability ) ||              
       
  7943            ( aCategory == CameraPlatPSKeys::KPSCameraPlatUid && 
       
  7944            aKey == CameraPlatPSKeys::KLensCoverStatus ) )        
       
  7945           {    
       
  7946 
       
  7947           TInt err = iSlideStateWatcher->Get( iNewSlideState );
       
  7948 
       
  7949           PRINT2( _L( "Camera HandlePropertyChangedL getting slider state = %d, err = %d" ), iNewSlideState, err )
       
  7950           
       
  7951           if ( iNewSlideState != iSlideState  )
       
  7952               {
       
  7953               delete iSliderCallBack;
       
  7954               iSliderCallBack = NULL;
       
  7955               iSliderCallBack = CPeriodic::NewL( CActive::EPriorityIdle );
       
  7956               iSliderCallBack->Start( KLensCoverDelay, KLensCoverDelay, TCallBack( LensCoverUpdateL, this ) );
       
  7957               }
       
  7958           }
       
  7959       else
       
  7960           {
       
  7961           (void)aCategory;
       
  7962           (void)aKey;
       
  7963           }
       
  7964       }
       
  7965       
       
  7966       // if its key lock state changed
       
  7967       if ( aCategory == KPSUidAvkonDomain && aKey == KAknKeyguardStatus )
       
  7968           {
       
  7969           PRINT( _L("Camera <> aCategory == KPSUidAvkonDomain && aKey == KAknKeyguardStatus") );
       
  7970           if ( !IsKeyLockOn() )
       
  7971               {
       
  7972               PRINT( _L("Camera <> !IsKeyLockOn()") );
       
  7973               // if in standby view and the slide is opened then exit standby view
       
  7974               CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  7975               TVwsViewId activeView;
       
  7976               appUi->GetActiveViewId( activeView );
       
  7977               CCamPreCaptureViewBase* view = static_cast<CCamPreCaptureViewBase*>( appUi->View( activeView.iViewUid ) );
       
  7978               if ( iInfo.iOperation == ECamStandby ||
       
  7979                    ( view && view->IsInStandbyMode() ) && appUi->IsRecoverableStatus() )
       
  7980                   {
       
  7981                    PRINT( _L("Camera HandleSlideOpenedL => Exit Standby view") );
       
  7982                    view->HandleCommandL( ECamCmdExitStandby );
       
  7983                   }
       
  7984               }
       
  7985           }
       
  7986       
       
  7987       if ( aCategory == KPSUidProfileEngine && aKey == KProEngActiveProfileChanged )
       
  7988           {
       
  7989           PRINT( _L("Camera <> aCategory == KCRUidProfileEngine && aKey == KProEngActiveWarningTones") );
       
  7990           IsProfileSilent();
       
  7991           }
       
  7992 
       
  7993 #endif // !( defined(__WINS__) || defined(__WINSCW__        
       
  7994 
       
  7995   PRINT( _L("Camera <= CCamAppController::HandlePropertyChangedL"))
       
  7996 
       
  7997   }                             
       
  7998 
       
  7999 // ---------------------------------------------------------------------------
       
  8000 // CCamAppController::LensCoverUpdate()
       
  8001 // Callback function that is called when lens cover state changes.
       
  8002 // Used to implement delayed handling of lens cover events.
       
  8003 // ---------------------------------------------------------------------------
       
  8004 //  
       
  8005 TInt CCamAppController::LensCoverUpdateL( TAny* aPtr ) 
       
  8006     {
       
  8007     PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL()" ) )
       
  8008     CCamAppController* self = static_cast<CCamAppController*>( aPtr );
       
  8009     if ( self->iNewSlideState != self->iSlideState ||
       
  8010          self->iNewSlideState == CameraPlatPSKeys::EClosed // always handle closing
       
  8011        )
       
  8012         {
       
  8013 
       
  8014         self->iSlideState = self->iNewSlideState;
       
  8015 
       
  8016         if ( self->iSlideState == CameraPlatPSKeys::EClosed )
       
  8017             {
       
  8018             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE CLOSED" ) )
       
  8019             self->HandleSlideClosedL();
       
  8020             }
       
  8021         else if ( self->iSlideState == CameraPlatPSKeys::EOpen )
       
  8022             {
       
  8023             PRINT( _L( "Camera => CCamAppController::LensCoverUpdateL() SLIDE OPENED" ) )
       
  8024             self->HandleSlideOpenedL();
       
  8025             }
       
  8026         }
       
  8027     self->iSliderCallBack->Cancel();
       
  8028     delete self->iSliderCallBack;
       
  8029     self->iSliderCallBack = 0;
       
  8030             
       
  8031     PRINT( _L( "Camera <= CCamAppController::LensCoverUpdateL()" ) )
       
  8032     return KErrNone;
       
  8033 
       
  8034     }
       
  8035 // ---------------------------------------------------------------------------
       
  8036 // CCamAppController::RefreshSlideState
       
  8037 // Force a refresh of the slide status
       
  8038 // ---------------------------------------------------------------------------
       
  8039 //
       
  8040 void CCamAppController::RefreshSlideStatus()
       
  8041     {
       
  8042     PRINT( _L("Camera => CCamAppController::RefreshSlideStatus") );  
       
  8043     // read the slider status from P & S key
       
  8044     if ( iSlideStateWatcher->Get( iSlideState ) != KErrNone )
       
  8045            {
       
  8046            iSlideState = KErrNone;
       
  8047            }   
       
  8048     }
       
  8049       
       
  8050 // ---------------------------------------------------------------------------
       
  8051 // CCamAppController::HandleSlideClosedL
       
  8052 // Handle the slide closed event
       
  8053 // ---------------------------------------------------------------------------
       
  8054 //
       
  8055 void CCamAppController::HandleSlideClosedL()
       
  8056     {
       
  8057     PRINT( _L("Camera => CCamAppController::HandleSlideClosedL") );
       
  8058 
       
  8059     NotifyControllerObservers( ECamEventSliderClosed );
       
  8060     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8061     
       
  8062     if ( appUi->IsInPretendExit() )
       
  8063         {
       
  8064         PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL already in pretend exit") );        
       
  8065         return;
       
  8066         }
       
  8067     SetCameraSwitchRequired( ESwitchDone );
       
  8068     // shutdown the camera on slide closing if EDGE variant/standalone app
       
  8069     // don't close app if embedded or embedding
       
  8070     TInt camerasAvailable = CamerasAvailable();
       
  8071     TVwsViewId activeView;
       
  8072     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  8073 
       
  8074     TBool embedded = appUi->IsEmbedded();
       
  8075     TBool embedding = appUi->Embedding();
       
  8076     if ( camerasAvailable == 1 ) // EDGE variant
       
  8077         {
       
  8078         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable == 1") );
       
  8079         // if embedding another app then don't exit just yet
       
  8080         if ( embedding )
       
  8081             {
       
  8082             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedding mode") );
       
  8083             // remember that the slider has been closed
       
  8084             iSliderCloseEvent = ETrue;
       
  8085             }
       
  8086         // Embedded post capture view
       
  8087         else if ( embedded && viewErr == KErrNone && 
       
  8088                 ( activeView.iViewUid.iUid == ECamViewIdStillPostCapture ||
       
  8089                   activeView.iViewUid.iUid == ECamViewIdVideoPostCapture ) )
       
  8090             {
       
  8091             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded post capture") );
       
  8092             // remember that the slider has been closed
       
  8093             iSliderCloseEvent = ETrue;
       
  8094             }
       
  8095         // if standalone app performing a burst capture, 
       
  8096         // don't exit till complete
       
  8097         else if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  8098                 ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  8099             {
       
  8100             // remember that the slider has been closed
       
  8101             iSliderCloseEvent = ETrue;
       
  8102             StopSequenceCaptureL();
       
  8103             }
       
  8104         else // standalone or embedded pre capture view
       
  8105             {
       
  8106             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  8107             appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  8108             }
       
  8109         }
       
  8110     else // variants with > 1 camera
       
  8111         {
       
  8112         PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - camerasAvailable > 1") );
       
  8113         if ( !embedding && !embedded )
       
  8114             {
       
  8115             // if standalone app performing a burst capture, 
       
  8116             // don't exit till complete
       
  8117             if ( ECamImageCaptureBurst == iInfo.iImageMode ||
       
  8118                  ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  8119                 {
       
  8120                 // remember that the slider has been closed
       
  8121                 iSliderCloseEvent = ETrue;
       
  8122                 StopSequenceCaptureL();
       
  8123                 }
       
  8124             else
       
  8125                 {
       
  8126                 PRINT( _L("Camera Normal mode-handle ECamCmdSlideClosedExit") );
       
  8127                 appUi->SetLensCoverExit( ETrue ); 
       
  8128                 if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid ) 
       
  8129                    {
       
  8130                    // stop recording and save the video
       
  8131                    StopVideoRecording();                          
       
  8132                    }
       
  8133                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - emit ECamCmdSlideClosedExit") );
       
  8134                 appUi->HandleCommandL( ECamCmdSlideClosedExit );
       
  8135                 
       
  8136 				// 2ndary camera, slider closed -> application to be closed, 
       
  8137 				// not in embedded mode
       
  8138                 if ( iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  8139                    {
       
  8140                    PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera slider closed, app closing...") );
       
  8141                    appUi->CloseAppL(); 
       
  8142                    }
       
  8143                 }
       
  8144             }
       
  8145         else // we are embedded in an app or embedding another app
       
  8146             {
       
  8147             // remember that the slider has been closed
       
  8148             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - Embedded/Embedding mode") );
       
  8149             
       
  8150             if ( viewErr == KErrNone )
       
  8151                 {
       
  8152                 iSliderCloseEvent = ETrue;
       
  8153 
       
  8154                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - active view %d"), activeView.iViewUid.iUid );
       
  8155                 PRINT1( _L("Camera <> CCamAppController::HandleSlideClosedL - iInfo.iOperation %d"), iInfo.iOperation );
       
  8156     
       
  8157                 // switch the camera if slide is closed and primary camera
       
  8158                 // is active in embedded mode
       
  8159                 switch ( activeView.iViewUid.iUid )
       
  8160                     {
       
  8161                     case ECamViewIdStillPreCapture:
       
  8162                     case ECamViewIdVideoPreCapture:
       
  8163                         {
       
  8164                         // if in pre capture view and slide is closed
       
  8165                         if ( iInfo.iActiveCamera == ECamActiveCameraPrimary )
       
  8166                             {
       
  8167                             if ( iInfo.iOperation != ECamPaused &&
       
  8168                                  iInfo.iOperation != ECamCapturing &&
       
  8169                                  iInfo.iOperation != ECamCompleting && 
       
  8170                                  iInfo.iOperation != ECamPausing &&
       
  8171                                  iInfo.iOperation != ECamResuming &&
       
  8172                                  !iVideoRequested )
       
  8173                                 {
       
  8174                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8175                                 }
       
  8176                             else if ( iInfo.iOperation == ECamCapturing ||
       
  8177                                       iInfo.iOperation == ECamPaused )
       
  8178                                 {
       
  8179                                 StopVideoRecording();                                
       
  8180                                 }
       
  8181                             else if ( iVideoRequested )
       
  8182                                 {
       
  8183                                 StopVideoRecording();
       
  8184                                 // cancel any outstanding sound requests
       
  8185                                 iSoundPlayer->CancelAllPlaying();
       
  8186 
       
  8187                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8188                                 }
       
  8189                             else // lint
       
  8190                                 {
       
  8191                                 }
       
  8192                             }
       
  8193                          else 
       
  8194                             {
       
  8195                             // Embedded camera not closed even if lens cover is closed.
       
  8196                             PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - 2ndary camera, no action..") );
       
  8197                             }
       
  8198                         }
       
  8199                         break;
       
  8200                     case ECamViewIdStillPostCapture:
       
  8201                     case ECamViewIdVideoPostCapture:
       
  8202                         {
       
  8203                         // Embedded camera not closed even if lens cover is closed.
       
  8204                         }
       
  8205                         break;
       
  8206                     default:
       
  8207                         break;
       
  8208                     }
       
  8209                 }
       
  8210                else if ( viewErr == KErrNotFound  )
       
  8211                 {
       
  8212                 PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - view not found") );
       
  8213                 if ( ECamActiveCameraPrimary == iInfo.iActiveCamera ) 
       
  8214                     {              
       
  8215                     PRINT( _L("Camera <> CCamAppController::HandleSlideClosedL - need switch to 2ndary") );
       
  8216                     SetCameraSwitchRequired( ESwitchPrimaryToSecondary );
       
  8217                     if ( !appUi->AppInBackground( ETrue ) )
       
  8218                         {
       
  8219                         appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8220                         }
       
  8221                     }
       
  8222                 }
       
  8223             }
       
  8224         }
       
  8225 
       
  8226     PRINT( _L("Camera <= CCamAppController::HandleSlideClosedL") );
       
  8227     }
       
  8228 
       
  8229 // ---------------------------------------------------------------------------
       
  8230 // CCamAppController::HandleSlideOpenedL
       
  8231 // Handles the slide opened event
       
  8232 // ---------------------------------------------------------------------------
       
  8233 //
       
  8234 void CCamAppController::HandleSlideOpenedL()
       
  8235     {
       
  8236     PRINT( _L("Camera => CCamAppController::HandleSlideOpenedL") );
       
  8237     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8238     // reset slider event flag
       
  8239     if ( iSliderCloseEvent )
       
  8240         {
       
  8241         iSliderCloseEvent = EFalse;
       
  8242         }
       
  8243 
       
  8244     TVwsViewId activeView;
       
  8245     TInt viewErr = appUi->GetActiveViewId( activeView );
       
  8246     if ( viewErr == KErrNone )
       
  8247         {
       
  8248         PRINT1( _L("Camera HandleSlideOpenedL => active view %d"), 
       
  8249                 activeView.iViewUid.iUid );
       
  8250 
       
  8251         // For EDGE variant 
       
  8252         TInt camerasAvailable = CamerasAvailable();
       
  8253         if ( camerasAvailable == 1 )
       
  8254             {
       
  8255             // if in standby view and the slide is opened then exit standby view
       
  8256             if ( iInfo.iOperation == ECamStandby )
       
  8257                 {
       
  8258                 PRINT( _L("Camera HandleSlideOpenedL => Exit Standby view") );
       
  8259                 appUi->View( activeView.iViewUid )->HandleCommandL( 
       
  8260                         ECamCmdExitStandby );
       
  8261                 }
       
  8262             }
       
  8263         else // variants with > 1 camera
       
  8264             {
       
  8265             PRINT1( _L("Camera HandleSlideOpenedL => iInfo.iOperation %d"), 
       
  8266                     iInfo.iOperation );
       
  8267             PRINT1( _L("Camera HandleSlideOpenedL => CameraState() %d"), 
       
  8268                     CameraState());
       
  8269             switch ( activeView.iViewUid.iUid )
       
  8270                 {
       
  8271                 // if we are in the photo/video capture view and the
       
  8272                 // second camera is enabled then switch to the main camera
       
  8273                 // so long as video/photo capture is not in progress
       
  8274                 case ECamViewIdStillPreCapture:
       
  8275                 case ECamViewIdVideoPreCapture:
       
  8276                     {
       
  8277                     if ( iInfo.iActiveCamera == ECamActiveCameraSecondary &&
       
  8278                          iInfo.iOperation != ECamCapturing &&
       
  8279                          iInfo.iOperation != ECamPaused &&
       
  8280                          iInfo.iOperation != ECamPausing &&
       
  8281                          iInfo.iOperation != ECamResuming &&
       
  8282                          iInfo.iOperation != ECamCompleting && 
       
  8283                          (CameraState() == ECamCameraPreparedImage ||
       
  8284                          CameraState() == ECamCameraPreparedVideo
       
  8285                          ||
       
  8286                          CameraState() == ECamCameraReserved ||
       
  8287                          CameraState() == ECamCameraPowerOn
       
  8288                          ) &&
       
  8289                          !VideoRecordPending() )
       
  8290                         {
       
  8291                         PRINT( _L("Camera precapture 2nd camera - switching now") ); 
       
  8292                         SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8293                         if ( !appUi->AppInBackground( ETrue ) )
       
  8294                             {
       
  8295                             appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8296                             }
       
  8297                         }
       
  8298                     else 
       
  8299                         {
       
  8300                         PRINT( _L("Camera capturing, paused etc. in precapview") );  
       
  8301                         
       
  8302                         if ( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid && 
       
  8303                            ( ECamCapturing == iInfo.iOperation || 
       
  8304                              ECamPaused == iInfo.iOperation ) ) 
       
  8305                             {
       
  8306                             StopVideoRecording(); // stop recording and save the video                         
       
  8307                             }
       
  8308                         if ( ECamActiveCameraSecondary == iInfo.iActiveCamera ) 
       
  8309                             {              
       
  8310                             PRINT( _L("Camera HandleSlideOpenedL, switchCamera") );
       
  8311                             SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8312                             if ( !appUi->AppInBackground( ETrue ) )
       
  8313                                 {
       
  8314                                 appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8315                                 }
       
  8316                             }
       
  8317                         }
       
  8318                     }    
       
  8319                     break;
       
  8320                 case ECamViewIdStillPostCapture:
       
  8321                 case ECamViewIdVideoPostCapture:
       
  8322                     {
       
  8323                     if ( ECamActiveCameraSecondary == iInfo.iActiveCamera )
       
  8324                        {                    
       
  8325                        SetCameraSwitchRequired( ESwitchSecondaryToPrimary );
       
  8326                        if ( !appUi->AppInBackground( ETrue ) )
       
  8327                            {
       
  8328                            appUi->HandleCommandL( ECamCmdSwitchCamera );
       
  8329                            }
       
  8330                        }
       
  8331                     }
       
  8332                     break;
       
  8333                 default:
       
  8334                     break;
       
  8335                 }
       
  8336             }       
       
  8337         }
       
  8338 
       
  8339     else if ( viewErr == KErrNotFound && 
       
  8340                 iInfo.iActiveCamera == ECamActiveCameraSecondary )
       
  8341           {
       
  8342           // If no view is found it means that camera is in background.
       
  8343           // We don't want to do camera switch in embdedded/embedding mode
       
  8344           // post-capture when in background
       
  8345           if ( ( !appUi->IsEmbedded() &&
       
  8346                  !appUi->Embedding() ) ||
       
  8347                appUi->CurrentViewState() != ECamViewStatePostCapture )
       
  8348               {
       
  8349               PRINT( _L("Camera HandleSlideOpenedL => view not found, 2nd active") );
       
  8350               iCameraSwitchRequired = ESwitchToUnknown;
       
  8351               }
       
  8352           }
       
  8353     else
       
  8354         {
       
  8355         }
       
  8356     NotifyControllerObservers( ECamEventSliderOpen );
       
  8357     PRINT( _L("Camera <= CamAppController::HandleSlideOpenedL") );
       
  8358     }
       
  8359 
       
  8360 
       
  8361 // ---------------------------------------------------------------------------
       
  8362 // CCamAppController::VideoViewFinderResourceId()
       
  8363 // Resource Id for video viewfinder layout
       
  8364 //
       
  8365 // ---------------------------------------------------------------------------
       
  8366 //    
       
  8367 TInt CCamAppController::VideoViewFinderResourceId( TCamVideoResolution aResolution )
       
  8368   {
       
  8369   PRINT( _L( "Camera => CCamAppController::VideoViewFinderResourceIdL"))
       
  8370   TInt vidVFRes;
       
  8371   
       
  8372     TCamOrientation orient = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() )->CamOrientation();   
       
  8373     if( orient == ECamOrientationCamcorder || orient == ECamOrientationCamcorderLeft )
       
  8374       {
       
  8375       vidVFRes = CamUtility::MapVideoQualityToViewFinderRes( aResolution );
       
  8376       }
       
  8377   else
       
  8378     {
       
  8379     TInt resId;
       
  8380     TInt err = CamUtility::GetPsiInt( ECamPsiVideoVFResSecondaryCamera, resId );
       
  8381     if( err )
       
  8382       {
       
  8383       vidVFRes = ROID( R_CAM_VIEWFINDER_RECT_CIF_ID );
       
  8384       }
       
  8385     else
       
  8386       {
       
  8387       vidVFRes = ROID( resId );
       
  8388       }
       
  8389     }
       
  8390     
       
  8391   PRINT1( _L( "Camera => CCamAppController::VideoViewFinderResourceId res id "), vidVFRes )
       
  8392   return vidVFRes;
       
  8393   }
       
  8394 
       
  8395 // ---------------------------------------------------------------------------
       
  8396 // CCamAppController::HandleObservedEvent()
       
  8397 // Receives event codes from observables
       
  8398 //
       
  8399 // ---------------------------------------------------------------------------
       
  8400 //
       
  8401 void CCamAppController::HandleObservedEvent( TCamObserverEvent aEvent )
       
  8402     {
       
  8403     switch( aEvent )
       
  8404         {
       
  8405         case ECamObserverEventCaptureProcessComplete:
       
  8406             {
       
  8407             NotifyControllerObservers( ECamEventExitRequested, KErrNone );
       
  8408             }
       
  8409             break;
       
  8410         default:
       
  8411             break;            
       
  8412         }
       
  8413     }
       
  8414 
       
  8415 // ---------------------------------------------------------------------------
       
  8416 // CCamAppController::IsProfileSilent
       
  8417 // Return whether current profile is silent or not, uses warning
       
  8418 // tones setting to determine whether silent or not
       
  8419 // ---------------------------------------------------------------------------
       
  8420 //  
       
  8421 TBool CCamAppController::IsProfileSilent()
       
  8422     {
       
  8423     if ( !iShutterSndAlwaysOn )
       
  8424         {
       
  8425         TRAPD( ignore, iSilentProfile = IsProfileSilentL() );
       
  8426         if ( ignore )
       
  8427             {
       
  8428             // If reading the warning tone (= camera tones) value fails
       
  8429             // we set tones off by default
       
  8430             iSilentProfile = ETrue;
       
  8431             }
       
  8432         return iSilentProfile;
       
  8433         }
       
  8434     else
       
  8435         {
       
  8436         return EFalse;
       
  8437         }
       
  8438     }
       
  8439 
       
  8440 
       
  8441 // ---------------------------------------------------------------------------
       
  8442 // CCamAppController::IsProfileSilentL
       
  8443 // Return whether current profile is silent or not, uses warning
       
  8444 // tones setting to determine whether silent or not
       
  8445 // ---------------------------------------------------------------------------
       
  8446 //  
       
  8447 TBool CCamAppController::IsProfileSilentL()
       
  8448     {
       
  8449     // If camera tones have been set off from settings, return true here 
       
  8450     if ( iSettingsModel->IntegerSettingValue( ECamSettingItemPhotoCaptureTone )
       
  8451                 == ECamSettToneOff )
       
  8452         {
       
  8453         return ETrue;
       
  8454         }
       
  8455     
       
  8456     // Get current keypad volume as an indication of whether
       
  8457     // or not we have a silent profile
       
  8458     CRepository* cr = CRepository::NewLC( KCRUidProfileEngine );
       
  8459     TInt value;
       
  8460     User::LeaveIfError( cr->Get( KProEngActiveWarningTones, value ) );
       
  8461     PRINT1(_L("Camera <> CCamAppController::IsProfileSilentL() value = %d"), value)
       
  8462     CleanupStack::PopAndDestroy( cr );
       
  8463     
       
  8464     return ( value == 0 );
       
  8465     }
       
  8466 
       
  8467 
       
  8468 // ---------------------------------------------------------------------------
       
  8469 // ResetInactivityTimer <<static>>
       
  8470 // ---------------------------------------------------------------------------
       
  8471 //  
       
  8472 TInt 
       
  8473 CCamAppController::ResetInactivityTimer( TAny* /*aPtr*/ )
       
  8474   {
       
  8475 	PRINT( _L("Camera =><= CCamAppController::ResetInactivityTimer") );
       
  8476 
       
  8477   User::ResetInactivityTime();
       
  8478 
       
  8479 	return KErrNone;
       
  8480   }
       
  8481     
       
  8482 // ---------------------------------------------------------------------------
       
  8483 // CCamAppController::ToneShouldBeSilent
       
  8484 // Returns ETrue if the supplied toneId should be silent if the profile is 
       
  8485 // set to silent. Does *not* take into account network variant forcing 
       
  8486 // sounds on.
       
  8487 // ---------------------------------------------------------------------------
       
  8488 //      
       
  8489 TBool CCamAppController::ToneShouldBeSilent( TCamSoundId aSoundId )
       
  8490     {    
       
  8491     if ( aSoundId == CaptureToneId() ||
       
  8492          aSoundId == ECamVideoStartSoundId ||
       
  8493          aSoundId == ECamVideoStopSoundId ||
       
  8494          aSoundId == ECamVideoPauseSoundId ||
       
  8495          aSoundId == ECamVideoResumeSoundId ||
       
  8496          aSoundId == ECamAutoFocusComplete ||
       
  8497          aSoundId == ECamSelfTimerSoundId )
       
  8498         {
       
  8499         return ETrue;
       
  8500         }
       
  8501     else
       
  8502         {
       
  8503         return EFalse;
       
  8504         }         
       
  8505     }
       
  8506     
       
  8507 // ---------------------------------------------------------------------------
       
  8508 // CCamAppController::HandleCaptureCompletion
       
  8509 // Inform any observers that are waiting for a capture completion event
       
  8510 // ---------------------------------------------------------------------------
       
  8511 //  
       
  8512 void CCamAppController::HandleCaptureCompletion()
       
  8513   {
       
  8514   PRINT( _L( "Camera => CCamAppController::HandleCaptureCompletion()" ) )
       
  8515 
       
  8516   SetOperation( ECamNoOperation );
       
  8517   
       
  8518   // Re-enable screensaver
       
  8519   EnableScreenSaver( ETrue );
       
  8520 
       
  8521   // If mmc dismount notification came while saving, allow the dismount now
       
  8522   if( iDismountPending )
       
  8523     {
       
  8524     iDismountPending = EFalse;
       
  8525     iDriveChangeNotifier->SendAllowDismount();	
       
  8526     }
       
  8527   
       
  8528   // If any observers are waiting for a capture completion event
       
  8529   if ( iCaptureCompletionObserverHandler )
       
  8530     {
       
  8531     iCaptureCompletionObserverHandler->BroadcastEvent( ECamObserverEventCaptureProcessComplete );
       
  8532     delete iCaptureCompletionObserverHandler;
       
  8533     iCaptureCompletionObserverHandler = NULL;
       
  8534     }
       
  8535 
       
  8536   // If the camera orientation changed during capture and not in burst mode, 
       
  8537   // set the new orientation
       
  8538   if ( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  8539        && iOrientationChangeOccured
       
  8540        && iInfo.iImageMode != ECamImageCaptureBurst )
       
  8541     {
       
  8542     iOrientationChangeOccured = EFalse;
       
  8543     TRAP_IGNORE( SetImageOrientationL() );
       
  8544     }
       
  8545 
       
  8546   if ( iPendingRelease )
       
  8547     {
       
  8548        PRINT( _L( "Camera <> CCamAppController::HandleCaptureCompletion(), DATAMAKE2" ) )        	
       
  8549        ReleaseCamera();
       
  8550     }
       
  8551   PRINT( _L( "Camera <= CCamAppController::HandleCaptureCompletion()" ) )        
       
  8552   }    
       
  8553 
       
  8554 
       
  8555 
       
  8556 // ---------------------------------------------------------------------------
       
  8557 // CCamAppController::CheckAfModeForScene
       
  8558 // Checks the current scene/based on scene to see if AF mode needs setting
       
  8559 // ---------------------------------------------------------------------------
       
  8560 //           
       
  8561 void CCamAppController::CheckAfModeForScene( TBool aForceAFReset )
       
  8562     {
       
  8563     PRINT(_L("Camera => CCamAppController::CheckAfModeForScene"));
       
  8564 
       
  8565     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8566         {
       
  8567         TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );
       
  8568         }
       
  8569 
       
  8570     PRINT(_L("Camera <= CCamAppController::CheckAfModeForScene"));
       
  8571     }
       
  8572 
       
  8573 
       
  8574 // ---------------------------------------------------------------------------
       
  8575 // CCamAppController::TryAutoFocus
       
  8576 // Start an AF operation, if needed
       
  8577 // ---------------------------------------------------------------------------
       
  8578 //      
       
  8579 TBool CCamAppController::TryAutoFocus()   
       
  8580     {  
       
  8581     PRINT( _L("Camera => CCamAppController::TryAutoFocus()") );  
       
  8582     OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_TRYAUTOFOCUS, "e_CAM_APP_AF_LOCK 1" );  //CCORAPP_AF_LOCK_START
       
  8583     
       
  8584     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8585         {
       
  8586         if( ECamActiveCameraPrimary != iInfo.iActiveCamera ||
       
  8587             ECamControllerImage != iInfo.iMode )
       
  8588           {
       
  8589           PRINT( _L("Returning EFalse - Not using primary camera in still mode") );  
       
  8590           // Not using primary camera in still mode      
       
  8591           return EFalse; // Not focusing
       
  8592           }
       
  8593                 
       
  8594         PRINT( _L("Calling IssueDirectRequestL( ECamRequestStartAutofocus )") );       
       
  8595         return TryAFRequest( ECamRequestStartAutofocus );
       
  8596         }
       
  8597     else 
       
  8598         {
       
  8599         return ETrue;
       
  8600         }
       
  8601     }
       
  8602 
       
  8603 
       
  8604 // ---------------------------------------------------------
       
  8605 // CCamAppController::CurrentSceneHasForcedFocus
       
  8606 // Returns whether the current scene has focus forced to 
       
  8607 // a particular value ( eg Macro/Landscape modes may have
       
  8608 // focus fixed to Macro/Infinite )
       
  8609 // ---------------------------------------------------------
       
  8610 //  
       
  8611 TBool CCamAppController::CurrentSceneHasForcedFocus() const
       
  8612     {
       
  8613     if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
  8614         {
       
  8615         // Work out what the current scene is (or if current scene is user
       
  8616         // scene, what it's based on).
       
  8617         TInt currentScene = IntegerSettingValue( ECamSettingItemDynamicPhotoScene );
       
  8618         if ( currentScene  == ECamSceneUser )
       
  8619             {
       
  8620             currentScene = IntegerSettingValue( ECamSettingItemUserSceneBasedOnScene );
       
  8621             }
       
  8622 
       
  8623         TBool isFaceTrackingOn = (iConfigManager &&
       
  8624                     iConfigManager->IsFaceTrackingSupported() &&
       
  8625                     (iSettingsModel->IntegerSettingValue( 
       
  8626                     ECamSettingItemFaceTracking ) == ECamSettOn ) );
       
  8627     
       
  8628         // Check if the current (or based on) scene is one that should *not* have 
       
  8629         // a reticule.
       
  8630         if ( ( currentScene == ECamSceneScenery 
       
  8631           || currentScene == ECamSceneNightScenery 
       
  8632           || currentScene == ECamSceneSports )
       
  8633           && !isFaceTrackingOn )
       
  8634             {
       
  8635             return ETrue;
       
  8636             }
       
  8637         else
       
  8638             {
       
  8639             return EFalse;
       
  8640             }
       
  8641         }
       
  8642     else
       
  8643         {
       
  8644         return ETrue;
       
  8645         }
       
  8646     }
       
  8647 
       
  8648 // ---------------------------------------------------------------------------
       
  8649 // CCamAppController::CaptureToneDelayTimeout
       
  8650 // Timeout from capture tone delay timer
       
  8651 // ---------------------------------------------------------------------------
       
  8652 //
       
  8653 TInt CCamAppController::CaptureToneDelayTimeout( TAny* aPtr )
       
  8654     {
       
  8655     PRINT( _L("Camera => CCamAppController::CaptureToneDelayTimeoutL") )
       
  8656     static_cast<CCamAppController*>( aPtr )->PlayDelayedCaptureTone();
       
  8657     return KErrNone;
       
  8658     }
       
  8659 
       
  8660 // ---------------------------------------------------------------------------
       
  8661 // CCamAppController::PlayDelayedCaptureTone
       
  8662 // Play capture tone
       
  8663 // ---------------------------------------------------------------------------
       
  8664 //  
       
  8665 void CCamAppController::PlayDelayedCaptureTone()
       
  8666     {
       
  8667     PlaySound( CaptureToneId(), EFalse );
       
  8668     }
       
  8669 
       
  8670 // ---------------------------------------------------------------------------
       
  8671 // CCamAppController::InitAutoFocusL
       
  8672 // Initalises the AutoFocus interface, if needed
       
  8673 // ---------------------------------------------------------------------------
       
  8674 //
       
  8675 void CCamAppController::InitAutoFocusL()
       
  8676     {
       
  8677     PRINT( _L("Camera => CCamAppController::InitAutoFocusL") )
       
  8678     PRINT(_L("Camera !! DISABLED"));
       
  8679     PRINT( _L("Camera <= CCamAppController::InitAutoFocusL") )
       
  8680     }
       
  8681 
       
  8682 // ---------------------------------------------------------------------------
       
  8683 // CCamAppController::CopySnapshotIfNeededL
       
  8684 // Helper function for McaeoSnapImageReady that makes a copy of the snapshot
       
  8685 // if needed to fake a viewfinder or for image rotation.
       
  8686 // ---------------------------------------------------------------------------
       
  8687 //
       
  8688 
       
  8689 void 
       
  8690 CCamAppController::CopySnapshotIfNeeded( const CFbsBitmap& aSnapshot, TInt aError )
       
  8691   { 
       
  8692   if ( ECamImageCaptureTimeLapse == iInfo.iImageMode 
       
  8693     || ECamControllerVideo == iInfo.iMode   
       
  8694     || ( iConfigManager && iConfigManager->IsOrientationSensorSupported() &&
       
  8695         ( iSettingsModel->IntegerSettingValue( ECamSettingItemImageRotation ) == ECamSettOn 
       
  8696           || iInfo.iActiveCamera == ECamActiveCameraSecondary ) )
       
  8697      )
       
  8698     {
       
  8699     StopIdleTimer();
       
  8700     delete iSnapShotCopy;
       
  8701     iSnapShotCopy = NULL;
       
  8702     TRAP_IGNORE ( ( iSnapShotCopy = new(ELeave) CFbsBitmap() ) );
       
  8703     
       
  8704     if ( iSnapShotCopy )
       
  8705       {
       
  8706       TInt dupeError = iSnapShotCopy->Duplicate( aSnapshot.Handle() );
       
  8707       
       
  8708       if ( dupeError )
       
  8709         {
       
  8710         iSnapShotCopy->Reset();
       
  8711         delete iSnapShotCopy;
       
  8712         iSnapShotCopy = NULL;
       
  8713         }
       
  8714       else if ( iConfigManager && !iConfigManager->IsOrientationSensorSupported() )
       
  8715         {
       
  8716         if( ECamImageCaptureTimeLapse == iInfo.iImageMode )
       
  8717           {
       
  8718           // simulate the receipt of a viewfinder frame using the snapshot image
       
  8719           // McaeoViewFinderFrameReady( *iSnapShotCopy, aError );  
       
  8720           HandleViewfinderFrame( aError, iSnapShotCopy );
       
  8721           }
       
  8722         }                
       
  8723       }        
       
  8724     }
       
  8725   }
       
  8726 
       
  8727 
       
  8728 
       
  8729 // ---------------------------------------------------------------------------
       
  8730 // CCamAppController::EnableScreenSaver
       
  8731 // Turns the screen saver on or off for timelapse capture
       
  8732 //
       
  8733 // ---------------------------------------------------------------------------
       
  8734 //  
       
  8735 void 
       
  8736 CCamAppController::EnableScreenSaver( TBool aEnable )  
       
  8737   {
       
  8738   if ( !aEnable ) 
       
  8739     {
       
  8740     // Stop the screensaver from appearing
       
  8741     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 1 );        
       
  8742     }
       
  8743   else
       
  8744     {
       
  8745     // Allow the screensaver to appear
       
  8746     RProperty::Set( KPSUidScreenSaver, KScreenSaverAllowScreenSaver, 0 );
       
  8747     User::ResetInactivityTime();      
       
  8748     }        
       
  8749   }
       
  8750 
       
  8751 
       
  8752 #ifdef CAMERAAPP_PERFORMANCE_MEASUREMENT
       
  8753 // ---------------------------------------------------------------------------
       
  8754 // CCamAppController::SetPerformanceState
       
  8755 //
       
  8756 // ---------------------------------------------------------------------------
       
  8757 //  
       
  8758 void CCamAppController::SetPerformanceState( TCamPerformanceState aState )  
       
  8759   {
       
  8760   iPerformanceState = aState;
       
  8761   }
       
  8762 #endif
       
  8763 
       
  8764 // ---------------------------------------------------------------------------
       
  8765 // CCamAppController::StartLocationTrailL()
       
  8766 // Connects and starts the locationtrail
       
  8767 // ---------------------------------------------------------------------------
       
  8768 //
       
  8769 void CCamAppController::StartLocationTrailL()
       
  8770   {
       
  8771   PRINT( _L("Camera => CCamAppController::StartLocationTrailL") );
       
  8772   CCamAppUi* appUI = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  8773 
       
  8774   if( !iRepository )
       
  8775     {
       
  8776     iRepository = CRepository::NewL( KCRUidCameraappSettings ); 
       
  8777     }
       
  8778 
       
  8779     TInt ftuValue=-1;
       
  8780     TInt retErr=0;
       
  8781     retErr = iRepository->Get( KCamCrFtuMessageFlag, ftuValue );
       
  8782 	if( ftuValue == 0 )
       
  8783 		{
       
  8784 		return;
       
  8785 		}
       
  8786 
       
  8787 	if( iRepository )
       
  8788 		{
       
  8789 		delete  iRepository;
       
  8790 		iRepository = NULL;
       
  8791 		}
       
  8792 
       
  8793 
       
  8794   // If a stop request is pending but the trail is being restarted, stop 
       
  8795   // and delete the timer
       
  8796   if( iLocationTrailTimer )
       
  8797   	{
       
  8798   	iLocationTrailTimer->Cancel();
       
  8799    	delete iLocationTrailTimer;
       
  8800    	iLocationTrailTimer = NULL;
       
  8801    	}
       
  8802   
       
  8803   TInt err = KErrNone;
       
  8804 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) 
       
  8805   if ( !iLocationTrailStarted )
       
  8806 	  {
       
  8807 	  if ( !iLocationUtilityConnected ) 
       
  8808 	    {
       
  8809 	    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Connect()") );
       
  8810 	    TVwsViewId activeView;
       
  8811 	    if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8812 	      {
       
  8813 	      if( ECamViewIdStillPreCapture == activeView.iViewUid.iUid  )
       
  8814 	          {
       
  8815 	          CCamPreCaptureViewBase* view = static_cast<CCamPreCaptureViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8816 	          view->SetLocationTrailConnecting();
       
  8817 	          }
       
  8818 	      }
       
  8819 	    User::LeaveIfError( iLocationUtility.Connect() );
       
  8820 	    iLocationUtilityConnected = ETrue;
       
  8821 	    }
       
  8822 	  err = iLocationUtility.StartLocationTrail( RLocationTrail::ECaptureAll );
       
  8823 	  }
       
  8824 #endif
       
  8825   // If start fails, change the setting to off 
       
  8826   if( KErrNone != err )
       
  8827     {
       
  8828     PRINT1( _L("Camera :: CCamAppController::StartLocationTrailL error:%d encountered while starting location trail"), err )
       
  8829     
       
  8830 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8831     // Disconnect from the location utility
       
  8832     PRINT( _L("Camera => CCamAppController::StartLocationTrailL - Starting of LocationTrail failed -> iLocationUtility.Close()") );
       
  8833     iLocationUtility.Close();
       
  8834     iLocationUtilityConnected = EFalse;
       
  8835     SetIntegerSettingValueL( ECamSettingItemRecLocation, ECamLocationOff );
       
  8836 #endif
       
  8837     
       
  8838     // Going to standby mode, location trail disabled
       
  8839 	  /*
       
  8840     TVwsViewId activeView;
       
  8841     if ( appUI->GetActiveViewId( activeView ) == KErrNone )
       
  8842       {
       
  8843       CCamViewBase* view = static_cast<CCamViewBase*>( appUI->View( activeView.iViewUid ) );
       
  8844       view->SwitchToStandbyModeL( TCamAppViewIds(activeView.iViewUid.iUid), err );
       
  8845       }
       
  8846       */
       
  8847     appUI->SetStandbyStatus( err );
       
  8848     appUI->HandleCommandL( ECamCmdGoToStandby );
       
  8849     }
       
  8850   else
       
  8851   	{
       
  8852   	iLocationTrailStarted = ETrue;
       
  8853   	}
       
  8854   PRINT( _L("Camera <= CCamAppController::StartLocationTrailL") );
       
  8855   }
       
  8856 
       
  8857 // ---------------------------------------------------------------------------
       
  8858 // CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8859 // Stops the locationtrail
       
  8860 // ---------------------------------------------------------------------------
       
  8861 //    
       
  8862 void CCamAppController::StopLocationTrail( TBool aCloseSession )
       
  8863 	  {
       
  8864 	  PRINT1( _L("Camera => CCamAppController::StopLocationTrail operation mode:%d"), iInfo.iOperation );
       
  8865 #if defined(RD_MDS_2_5) && !defined(__WINSCW__)
       
  8866 	  if( iLocationTrailStarted )
       
  8867 		{
       
  8868 		// if not ECamCapturing, ECamPausing, ECamPaused, ECamResuming or ECamCompleting
       
  8869 		if( (iInfo.iOperation < ECamCapturing || iInfo.iOperation > ECamCompleting ) && 
       
  8870 		    ( CurrentFullFileName() == KNullDesC || SavedCurrentImage() )
       
  8871 		  )
       
  8872 			{
       
  8873 			PRINT( _L("Camera :: CCamAppController::StopLocationTrail - stopping location trail") )
       
  8874 			iLocationUtility.StopLocationTrail();
       
  8875 			if ( aCloseSession ) 
       
  8876 			    {
       
  8877 			    PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Close()") );
       
  8878 			    iLocationUtility.Close();
       
  8879 			    iLocationUtilityConnected = EFalse;
       
  8880 			    }
       
  8881 			iLocationTrailStarted = EFalse;
       
  8882 			
       
  8883 			// If a timer was used to stop the location trail, then cancel and delete the timer
       
  8884 	        if( iLocationTrailTimer )
       
  8885 	        	{
       
  8886 	        	iLocationTrailTimer->Cancel();
       
  8887 	        	delete iLocationTrailTimer;
       
  8888 	        	iLocationTrailTimer = NULL;
       
  8889 	        	}		
       
  8890 			}
       
  8891 		else
       
  8892 			{
       
  8893 			// Use a timer to close the trail in a few seconds
       
  8894 	    	PRINT( _L("Camera :: CCamAppController::StopLocationTrail - location trail in use") )
       
  8895 	    	if( !iLocationTrailTimer )
       
  8896 	    		{
       
  8897 	    		TRAP_IGNORE( iLocationTrailTimer = CCamTimer::NewL( KLocTrailCloseRetryTime, 
       
  8898 	    		  TCallBack( CCamAppController::RetryStopLocationTrail, this ) ) );
       
  8899 	    		}
       
  8900 	    	else // restart the timer
       
  8901 	    		{
       
  8902 				iLocationTrailTimer->Cancel();
       
  8903 				iLocationTrailTimer->SetTimeout( KLocTrailCloseRetryTime );
       
  8904 	    		}
       
  8905 	    	iLocationTrailTimer->StartTimer();
       
  8906 			}
       
  8907 		}
       
  8908       else if ( aCloseSession ) 
       
  8909         {
       
  8910 		PRINT( _L("Camera => CCamAppController::StartLocationTrailL - iLocationUtility.Close()") );
       
  8911         // location trail already stopped, but we are exiting app, so close the utility
       
  8912 		iLocationUtility.Close();
       
  8913 		iLocationUtilityConnected = EFalse;
       
  8914 		}
       
  8915 
       
  8916 	#endif
       
  8917 	  PRINT( _L("Camera <= CCamAppController::StopLocationTrail") );
       
  8918 	  }
       
  8919 
       
  8920 // ---------------------------------------------------------------------------
       
  8921 // CCamAppController::RetryStopLocationTrail()
       
  8922 // Timer callback function to attempt to remove the location trail periodically
       
  8923 // ---------------------------------------------------------------------------
       
  8924 //    
       
  8925 TInt CCamAppController::RetryStopLocationTrail( TAny* aPtr )
       
  8926 	{
       
  8927 	PRINT( _L("Camera => CCamAppController::RetryStopLocationTrail") )
       
  8928 	static_cast<CCamAppController*>( aPtr )->StopLocationTrail();
       
  8929 	PRINT( _L("Camera <= CCamAppController::RetryStopLocationTrail") )
       
  8930 	return KErrNone;
       
  8931 	}
       
  8932   
       
  8933 // -----------------------------------------------------------------------------
       
  8934 // CCamAppController::CaptureKeyPressedWhileImageSaving
       
  8935 // Whether or not a capture key pressed during image saving
       
  8936 // -----------------------------------------------------------------------------
       
  8937 //
       
  8938 TBool CCamAppController::CaptureKeyPressedWhileImageSaving() const
       
  8939 	{
       
  8940 	return iCaptureKeyPressedWhileImageSaving;
       
  8941 	}
       
  8942 	
       
  8943 // -----------------------------------------------------------------------------
       
  8944 // CCamAppController::SetCaptureKeyPressedWhileImageSaving
       
  8945 // -----------------------------------------------------------------------------
       
  8946 //
       
  8947 void CCamAppController::SetCaptureKeyPressedWhileImageSaving(TBool aCaptureKeyPressed)
       
  8948 	{
       
  8949 	iCaptureKeyPressedWhileImageSaving = aCaptureKeyPressed;
       
  8950 	}
       
  8951   
       
  8952 
       
  8953 
       
  8954 // ---------------------------------------------------------------------------
       
  8955 // CamerasAvailable <<static>>
       
  8956 //
       
  8957 // Commonly needed in UI classes, so added also support to get this info
       
  8958 // through this class. This way we avoid unnecessary binding of 
       
  8959 // CCameraController and UI classes.
       
  8960 // ---------------------------------------------------------------------------
       
  8961 //
       
  8962 TInt 
       
  8963 CCamAppController::CamerasAvailable()
       
  8964   {
       
  8965   return CCamCameraController::CamerasAvailable();
       
  8966   }
       
  8967 
       
  8968 TBool 
       
  8969 CCamAppController::TimeLapseSupported()
       
  8970   {
       
  8971   return (ECamSupportOn == iSettingsModel->VariantInfo().iTimeLapseSupport);
       
  8972   }
       
  8973     
       
  8974 TBool 
       
  8975 CCamAppController::AlwaysOnSupported()
       
  8976   {
       
  8977   return (ECamSupportOn == iSettingsModel->VariantInfo().iAlwaysOnSupport);
       
  8978   }
       
  8979 
       
  8980 const TVersion& 
       
  8981 CCamAppController::Version()
       
  8982   {
       
  8983   return iSettingsModel->VariantInfo().iVersion;
       
  8984   }
       
  8985 
       
  8986 
       
  8987 // <<public>>
       
  8988 TBool 
       
  8989 CCamAppController::Busy() const
       
  8990   {
       
  8991   PRINT1(_L("Camera <> CCamAppController::Busy:%d"), iBusyFlags );
       
  8992   return (EBusyNone != iBusyFlags || CameraControllerBusy() );
       
  8993   }
       
  8994 
       
  8995 TBool 
       
  8996 CCamAppController::CameraControllerBusy() const
       
  8997   {
       
  8998   PRINT1(_L("Camera <> CCamAppController::CameraControllerBusy:%d"), iCameraController->ControllerInfo().iBusy );  
       
  8999   return (iCameraController && ECamBusyOff != iCameraController->ControllerInfo().iBusy );
       
  9000   }
       
  9001 
       
  9002 // ===========================================================================
       
  9003 // From MCamCameraObserver
       
  9004 
       
  9005 // ---------------------------------------------------------------------------
       
  9006 // HandleCameraEventL <<virtual>>
       
  9007 // ---------------------------------------------------------------------------
       
  9008 //
       
  9009 void 
       
  9010 CCamAppController
       
  9011 ::HandleCameraEventL( TInt              aStatus, 
       
  9012                       TCamCameraEventId aEventId, 
       
  9013                       TAny*             aEventData /*= NULL*/ )
       
  9014   {
       
  9015 #ifdef _DEBUG    
       
  9016   // Log viewfinder events with PRINT_FRQ
       
  9017   // #ifdef _DEBUG is used to avoid extra if in release builds
       
  9018   // where logging is not used anyway.
       
  9019   if( ECamCameraEventVfFrameReady == aEventId )  
       
  9020     {
       
  9021     PRINT_FRQ1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  9022           KCamCameraEventNames[aEventId] );    
       
  9023     }
       
  9024   else
       
  9025 #endif // _DEBUG    
       
  9026     {
       
  9027     PRINT1( _L( "Camera => CCamAppController::HandleCameraEventL, event[%s]" ),
       
  9028             KCamCameraEventNames[aEventId] );
       
  9029     }
       
  9030  
       
  9031   // in case we get poweron event before appui is completely constructed
       
  9032   // finish it here
       
  9033   if ( aEventId == ECamCameraEventPowerOn )
       
  9034       {
       
  9035       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9036       if ( iConfigManager && 
       
  9037            iConfigManager->IsUIOrientationOverrideSupported() && 
       
  9038            !appUi->IsUiConstructionComplete() )
       
  9039           {
       
  9040           appUi->AppUIConstructCallbackL( appUi );  
       
  9041           }
       
  9042       }       
       
  9043 
       
  9044   TInt handleError( KErrNone );
       
  9045 
       
  9046   if( ECamCameraEventVfFrameReady != aEventId &&
       
  9047       KErrNone == aStatus || KErrDiskFull == aStatus || KErrCompletion == aStatus ) 
       
  9048     {
       
  9049     // Called for all events, except viewfinder frame ready event.    
       
  9050     SetStateFromEvent( aEventId );
       
  9051     }
       
  9052   
       
  9053   if( ECamCameraEventImageInit == aEventId ||
       
  9054       ECamCameraEventVideoInit == aEventId )
       
  9055     {  
       
  9056     iSettingsRestoreNeeded = ETrue;  
       
  9057     }
       
  9058 
       
  9059 
       
  9060   // NOTE: Consider that the ones needing these events
       
  9061   //       receive them directly from Camera Controller?
       
  9062   switch( aEventId )
       
  9063     {
       
  9064     case ECamCameraEventVfStart:
       
  9065       {
       
  9066       CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  9067       // For forced focus scenes, do one autofocus request once vf starts if needed
       
  9068       if( UiConfigManagerPtr()->IsAutoFocusSupported() )
       
  9069         {
       
  9070         if( CurrentSceneHasForcedFocus() || UiConfigManagerPtr()->IsAutofocusSetInHyperfocalAtStartup() ) 
       
  9071             {
       
  9072             PRINT( _L( "Camera => CCamAppController::HandleCameraEventL, TryAFRequest( ECamRequestCancelAutofocus )") );
       
  9073             TryAFRequest( ECamRequestCancelAutofocus ); 
       
  9074             }
       
  9075         }
       
  9076       if( iSettingsRestoreNeeded )
       
  9077         {
       
  9078         iSettingsRestoreNeeded = EFalse;  
       
  9079         TRAP_IGNORE( iCameraController->DirectSettingsChangeL( ECameraSettingFacetracking ) );
       
  9080         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  9081         }
       
  9082       // fixed toolbar is used only with touch devices
       
  9083       if ( IsTouchScreenSupported() && appUi )
       
  9084           {
       
  9085           CAknToolbar* toolbar = appUi->CurrentFixedToolbar();
       
  9086           if ( toolbar )
       
  9087               {
       
  9088               CAknToolbarExtension* toolbarextension = toolbar->ToolbarExtension();
       
  9089               if ( toolbarextension && toolbarextension->IsShown() )
       
  9090                   {
       
  9091                   appUi->SetToolbarVisibility();// avoid flickering in settings view
       
  9092                   }
       
  9093               else
       
  9094                   {
       
  9095                   appUi->SubmergeToolbar();
       
  9096                   }
       
  9097               }
       
  9098           PRINT( _L( "Camera <> SetToolbarVisibility done ") );
       
  9099           }
       
  9100       // else use AP    
       
  9101       else
       
  9102           {
       
  9103           if( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() )
       
  9104               {
       
  9105               NotifyControllerObservers( ECamEventInitReady );
       
  9106               }
       
  9107           }
       
  9108 
       
  9109       if ( UiConfigManagerPtr()->IsLocationSupported() &&
       
  9110               ECamLocationOn == IntegerSettingValue( ECamSettingItemRecLocation ) )
       
  9111         {
       
  9112         StartLocationTrailL();
       
  9113         }
       
  9114 
       
  9115       //Check if profile is silent and/or camera tones are set off
       
  9116       IsProfileSilent();
       
  9117 
       
  9118       break;
       
  9119       }
       
  9120     case ECamCameraEventVfFrameReady:
       
  9121       {      
       
  9122       HandleViewfinderFrame( aStatus, static_cast<CFbsBitmap*>( aEventData ) );
       
  9123       
       
  9124       if( KErrNone == aStatus && iSettingsRestoreNeeded )
       
  9125         {
       
  9126         iSettingsRestoreNeeded = EFalse;  
       
  9127         TRAP( aStatus, RestoreSettingsToCameraL() );  
       
  9128         }
       
  9129       return;
       
  9130       }
       
  9131     case ECamCameraEventSsReady:
       
  9132       {
       
  9133       TRAP_IGNORE( HandleSnapshotEvent( aStatus, static_cast<CFbsBitmap*>( aEventData ) ) );
       
  9134       
       
  9135       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  9136              CurrentCapturedCount() < CaptureLimit() )
       
  9137             {
       
  9138             // check memory level
       
  9139             TInt memoryLeft = 0;
       
  9140             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  9141                                           
       
  9142             if ( memoryLeft < KCriticalMemoryLevel )
       
  9143                 {
       
  9144                 PRINT( _L("Camera <> RAM is below critical level #1") )
       
  9145                 // memory below critical level, need to stop capture
       
  9146                 SoftStopBurstL( ETrue );
       
  9147                 EventHandlingErrorRecovery( KErrNoMemory );
       
  9148                 }
       
  9149             }
       
  9150       
       
  9151       break;
       
  9152       }
       
  9153     case ECamCameraEventImageData:
       
  9154       {
       
  9155 //      TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<HBufC8*>( aEventData ) ) ); 
       
  9156       TRAP_IGNORE( HandleImageCaptureEventL( aStatus, static_cast<CCamBufferShare*>( aEventData ) ) );
       
  9157       if ( ECamImageCaptureBurst == iInfo.iImageMode &&
       
  9158              CurrentCapturedCount() < CaptureLimit() )
       
  9159             {
       
  9160             // check memory level
       
  9161             TInt memoryLeft = 0;
       
  9162             HAL::Get( HALData::EMemoryRAMFree, memoryLeft );
       
  9163             if ( memoryLeft < KCriticalMemoryLevel )
       
  9164                 {
       
  9165                 PRINT( _L("Camera <> RAM is below critical level #2") )
       
  9166                 // memory below critical level, need to stop capture
       
  9167                 TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestImageCancel ) );
       
  9168                 EventHandlingErrorRecovery( KErrNoMemory );
       
  9169                 }
       
  9170             }
       
  9171       break;
       
  9172       }
       
  9173     case ECamCameraEventImageStop:
       
  9174       {
       
  9175       TRAP( aStatus, HandleImageStopEventL( aStatus, aEventData ? *static_cast<TInt*>( aEventData ) : 0 ) );
       
  9176       break;
       
  9177       }
       
  9178 
       
  9179     case ECamCameraEventAutofocusSuccessful: // Flowthrough
       
  9180     case ECamCameraEventAutofocusFailed:
       
  9181       {        
       
  9182       // Autofocusing is done, do possible pending capture  
       
  9183       SetAfNeeded( EFalse );
       
  9184       if( iCaptureRequested && !EngineProcessingCapture() )
       
  9185         {
       
  9186         iCaptureRequested = EFalse;
       
  9187         OstTrace0( CAMERAAPP_PERFORMANCE, DUP7_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_AF 0" );
       
  9188         OstTrace0( CAMERAAPP_PERFORMANCE, DUP8_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_AF_LOCK 0" );
       
  9189         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_SNAPSHOT 1" );
       
  9190         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SNAPSHOT 1" );
       
  9191         OstTrace0( CAMERAAPP_PERFORMANCE, DUP2_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SAVE 1" );
       
  9192         OstTrace0( CAMERAAPP_PERFORMANCE, DUP3_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SHOT_TO_SHOT 1" );
       
  9193         OstTrace0( CAMERAAPP_PERFORMANCE, DUP4_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_SHOT_TO_STILL 1" );
       
  9194         OstTrace0( CAMERAAPP_PERFORMANCE, DUP5_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_APP_CAPTURE_START 1" );
       
  9195         OstTrace0( CAMERAAPP_PERFORMANCE, DUP6_CCAMAPPCONTROLLER_HANDLECAMERAEVENTL, "e_CAM_PRI_SERIAL_SHOOTING 1" );
       
  9196         
       
  9197         // When image capture is started with touch capture button, a short
       
  9198         // delay is added after AF completes, but before capturing starts to 
       
  9199         // avoid blurry screen sometimes when VF is frozen and before the 
       
  9200         // snapshot is drawn. Delay also helps to see focus reticule. 
       
  9201         if( iTouchCapture )
       
  9202             {
       
  9203             User::After( 50000 );
       
  9204             iTouchCapture = EFalse;
       
  9205             }
       
  9206         Capture();  
       
  9207         }           
       
  9208       break;  
       
  9209       }
       
  9210       
       
  9211     case ECamCameraEventSettingsSingle:
       
  9212       {
       
  9213       TRAP_IGNORE( HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  9214       return;
       
  9215       }
       
  9216     case ECamCameraEventVideoAsyncStop: 
       
  9217     case ECamCameraEventVideoStop:
       
  9218       {
       
  9219       // we always want to handle these events. set the flag because
       
  9220       // there is a possibility that some other event has come before
       
  9221       // and caused the flag to be cleared
       
  9222       SetFlags(iBusyFlags, EBusyRequest);
       
  9223       if ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) 
       
  9224 	     && CurrentStorage() == ECamMediaStorageCard )
       
  9225       	{
       
  9226         aStatus = KErrNone; 
       
  9227       	}
       
  9228       if( aStatus != KErrNone && aStatus != KErrDiskFull && aStatus != KErrCompletion 
       
  9229               && !( aStatus == KErrPathNotFound && IsCaptureStoppedForUsb() ) )
       
  9230           {
       
  9231           iSaving = EFalse;
       
  9232           SetOperation( ECamStandby, KErrGeneral );
       
  9233           }
       
  9234       else
       
  9235           {
       
  9236           // In case of no error, we are already in appropriate state
       
  9237           }
       
  9238 	  break;
       
  9239       }
       
  9240     case ECamCameraEventIveRecover:  
       
  9241       {
       
  9242       if( !Busy() )
       
  9243         {
       
  9244         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Issue new recovery sequence" ) );
       
  9245         SetStateFromEvent( ECamCameraEventReserveLose );  
       
  9246         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9247         // Find target mode from appUi and set this controller target mode 
       
  9248         if( appUi->TargetMode() ==  ECamControllerVideo )
       
  9249             {
       
  9250             PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - recover to video mode" ) );
       
  9251             SetTargetMode( ECamControllerVideo  );
       
  9252             SetTargetImageMode( ECamImageCaptureNone );
       
  9253             }
       
  9254         else
       
  9255             {
       
  9256             PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - recover to still mode" ) );
       
  9257             SetTargetMode( ECamControllerImage );
       
  9258             SetTargetImageMode( CurrentImageModeSetup() );
       
  9259             }
       
  9260         IssueModeChangeSequenceL();
       
  9261         }
       
  9262       else
       
  9263         {
       
  9264         PRINT( _L( "Camera => CCamAppController::HandleCameraEventL - Recovery sequence is active" ) );
       
  9265         }
       
  9266       break;
       
  9267       }
       
  9268     case ECamCameraEventSequenceEnd:
       
  9269       {
       
  9270       // only for image mode	
       
  9271       if( iConfigManager && iConfigManager->IsOrientationSensorSupported()
       
  9272           && ECamControllerImage == CurrentMode() )
       
  9273         {	
       
  9274         // If the camera orientation changed during initialization sequence and not in burst mode, 
       
  9275         // set the new orientation
       
  9276         if ( iOrientationChangeOccured &&
       
  9277              iInfo.iImageMode != ECamImageCaptureBurst )  
       
  9278           {
       
  9279           iOrientationChangeOccured = EFalse;
       
  9280           TRAP_IGNORE( SetImageOrientationL() );
       
  9281           }
       
  9282         if( !iAccSensorListening )
       
  9283           {
       
  9284           TRAP_IGNORE( UpdateSensorApiL( ETrue ) );            
       
  9285           }
       
  9286         }
       
  9287         if ( aStatus == KErrCancel )
       
  9288             {
       
  9289             // sequence canceled, no need to event further
       
  9290             return;
       
  9291             }
       
  9292         else if( aStatus == KErrNone )
       
  9293             {
       
  9294             //Reset standbystatus. Needed if recovered from error.
       
  9295             if( IsAppUiAvailable() ) 
       
  9296               {
       
  9297               if ( !InVideocallOrRinging() )
       
  9298                   {
       
  9299                   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  9300                   appUi->SetStandbyStatus( aStatus );               
       
  9301                   }
       
  9302               } 
       
  9303             }
       
  9304       break;
       
  9305       }
       
  9306     //Image capture event  
       
  9307     case ECamCameraEventImageCaptureEvent:
       
  9308       {
       
  9309       PlaySound( CaptureToneId(), EFalse );
       
  9310       }
       
  9311       break;  
       
  9312     default:
       
  9313       break;
       
  9314     }
       
  9315 
       
  9316 
       
  9317   // -------------------------------------------------------
       
  9318   // We have requested a series of operations.
       
  9319   // The sequences have ids, which we use to determine
       
  9320   // the right procedure. React when sequence ends.
       
  9321   if( IsFlagOn( iBusyFlags, EBusySequence ) )
       
  9322     {
       
  9323     PRINT( _L( "Camera <> Sequence of requests pending" ) );
       
  9324     TRAP( handleError, HandleSequenceEventL( aStatus, aEventId, aEventData ) );
       
  9325     }
       
  9326   // -------------------------------------------------------
       
  9327   // We have single request pending.
       
  9328   else if( IsFlagOn( iBusyFlags, EBusyRequest ) )
       
  9329     {
       
  9330     PRINT( _L( "Camera <> Single request pending" ) );
       
  9331     TRAP( handleError, HandleRequestEventL( aStatus, aEventId, aEventData ) );
       
  9332     }
       
  9333   else if( IsFlagOn( iBusyFlags, EBusySetting ) )
       
  9334     {
       
  9335     PRINT( _L( "Camera <> Settings finished" ) );
       
  9336     TRAP( handleError, HandleSettingEventL( aStatus, aEventId, aEventData ) );
       
  9337     }
       
  9338   // -------------------------------------------------------
       
  9339   // No request pending for us.
       
  9340   // Direct request issued to Camera controller.
       
  9341   else
       
  9342     {
       
  9343     PRINT( _L( "Camera <> No requests pending!!" ) );
       
  9344     // handle these ..
       
  9345     }
       
  9346 
       
  9347   // -------------------------------------------------------
       
  9348   if( KErrNone != handleError )
       
  9349     {
       
  9350     EventHandlingErrorRecovery( handleError );
       
  9351     }
       
  9352 
       
  9353   // Reserve lost event is always handled.
       
  9354   if( ECamCameraEventReserveLose == aEventId && KErrNone != aStatus )
       
  9355     {
       
  9356     SetOperation( ECamStandby, aStatus );
       
  9357     }
       
  9358     
       
  9359   if( iPendingRelease && !Busy() &&
       
  9360       !IsSavingInProgress() && iInfo.iOperation != ECamCapturing ) 
       
  9361     {  
       
  9362     // Finally, if camera release is pending, and we are no longer busy,
       
  9363     // call ReleaseCamera to get it done.
       
  9364     // ReleaseCamera is used instead of simply setting iInfo.iTargetMode,
       
  9365     // because it also handles stopping ongoing burst captures.
       
  9366     PRINT( _L( "Camera <> CCamAppController::HandleCameraEventL, release pending, calling ReleaseCamera..") );
       
  9367     ReleaseCamera();  
       
  9368     }    
       
  9369 
       
  9370 #ifdef _DEBUG    
       
  9371   // Log viewfinder events with PRINT_FRQ
       
  9372   if( ECamCameraEventVfFrameReady == aEventId )  
       
  9373     {
       
  9374     PRINT_FRQ( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );  
       
  9375     }
       
  9376   else  
       
  9377 #endif // _DEBUG    
       
  9378     {
       
  9379     PRINT( _L( "Camera <= CCamAppController::HandleCameraEventL" ) );
       
  9380     }
       
  9381   }
       
  9382 
       
  9383 // ===========================================================================
       
  9384 
       
  9385 
       
  9386 // ---------------------------------------------------------------------------
       
  9387 // EventHandlingErrorRecovery
       
  9388 // ---------------------------------------------------------------------------
       
  9389 //
       
  9390 void
       
  9391 CCamAppController::EventHandlingErrorRecovery( TInt aError )
       
  9392   {
       
  9393   PRINT1( _L( "Camera => CCamAppController::EventHandlingErrorRecovery, error:%d" ), aError );
       
  9394 
       
  9395   __ASSERT_ALWAYS( aError != KErrNone, CamPanic( ECamPanicInvalidState ) );
       
  9396 
       
  9397   iCaptureModeTransitionInProgress = EFalse;
       
  9398 
       
  9399   // Reset the saving flag to ensure that camera does not get stuck
       
  9400   iSaving = EFalse;  
       
  9401 
       
  9402   iMuteNotifications = ETrue;
       
  9403 
       
  9404   // Cancel ongoing sequence if any
       
  9405   iCameraController->CancelSequence();
       
  9406 
       
  9407   // Clear busy flags
       
  9408   iBusyFlags           = EBusyNone;
       
  9409   iInfo.iBusyRequestId = ECamRequestNone;
       
  9410 
       
  9411   iMuteNotifications = EFalse;
       
  9412 
       
  9413   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9414   //Don't change to Stand by mode if -4 error gotten during burst (somehow expected)
       
  9415   if(SequenceCaptureInProgress() && appUi->CurrentBurstMode() == ECamImageCaptureBurst && KErrNoMemory == aError )
       
  9416     {
       
  9417     TRAP_IGNORE( appUi->HandleCameraErrorL(aError) );
       
  9418     }
       
  9419   else
       
  9420     {
       
  9421     SetOperation( ECamStandby, aError );
       
  9422     }
       
  9423 
       
  9424   NotifyControllerObservers( ECamEventControllerReady, aError );
       
  9425 
       
  9426   PRINT( _L( "Camera <= CCamAppController::EventHandlingErrorRecovery" ) );
       
  9427   }
       
  9428 
       
  9429 // ---------------------------------------------------------------------------
       
  9430 // HandleSettingEventL
       
  9431 // ---------------------------------------------------------------------------
       
  9432 //
       
  9433 void
       
  9434 CCamAppController::HandleSettingEventL( TInt              aStatus, 
       
  9435                                         TCamCameraEventId aEventId, 
       
  9436                                         TAny*             aEventData )
       
  9437   {
       
  9438   PRINT( _L( "Camera => CCamAppController::HandleSettingEventL" ) );
       
  9439   // -------------------------------------------------------
       
  9440   if( ECamCameraEventSettingsDone == aEventId )
       
  9441     {
       
  9442     ClearFlags( iBusyFlags, EBusySetting );
       
  9443 
       
  9444     // Need to clear any pending settings.
       
  9445     iSettingProvider->Reset();
       
  9446 
       
  9447     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9448       {
       
  9449       PRINT( _L( "Camera <> CCamAppController: Releasing camera.." ) );
       
  9450       IssueRequestL( ECamRequestRelease );
       
  9451       }
       
  9452     else
       
  9453       {
       
  9454       PRINT( _L( "Camera <> CCamAppController: Got setting end event.." ) );      
       
  9455       if( KErrNone != aStatus )
       
  9456         {
       
  9457         TCamCameraSettingId* cameraSetting =
       
  9458             static_cast<TCamCameraSettingId*>( aEventData );
       
  9459 
       
  9460         // Leave with the incoming error, if setting id not provided.
       
  9461         CheckNonNullL( cameraSetting, aStatus );
       
  9462 
       
  9463         if( ECameraSettingFileName == *cameraSetting )
       
  9464           {
       
  9465           DoVideoNameRetryL( aStatus );
       
  9466           }
       
  9467         else
       
  9468           {
       
  9469           User::Leave( aStatus );
       
  9470           }
       
  9471         }
       
  9472       else
       
  9473         {
       
  9474         ProceedPendingOrNotifyReadyL();
       
  9475         }
       
  9476       }
       
  9477     }
       
  9478   // -------------------------------------------------------
       
  9479   else if( ECamCameraEventSettingsSingle == aEventId )
       
  9480     {
       
  9481     TCamCameraSettingId* cameraSetting =
       
  9482         static_cast<TCamCameraSettingId*>( aEventData );
       
  9483 
       
  9484     CheckNonNullL( cameraSetting, KErrNotFound );
       
  9485     switch( *cameraSetting )
       
  9486       {
       
  9487       case ECameraSettingDigitalZoom:
       
  9488       case ECameraSettingOpticalZoom:
       
  9489         {
       
  9490         PRINT( _L( "Camera <> CCamAppController: zoom event" ) );
       
  9491         NotifyControllerObservers( ECamEventZoomStateChanged, aStatus );
       
  9492         // Pending zooming done in HandleViewfinderFrame
       
  9493         break;
       
  9494         }
       
  9495       default:
       
  9496         PRINT( _L( "Camera <> CCamAppController: unhandled setting event" ) );
       
  9497         break;
       
  9498       }
       
  9499     }
       
  9500   // -------------------------------------------------------
       
  9501   else
       
  9502     {
       
  9503     // Ignored
       
  9504     }
       
  9505   // -------------------------------------------------------
       
  9506   PRINT( _L( "Camera <= CCamAppController::HandleSettingEventL" ) );
       
  9507   }
       
  9508 
       
  9509 // ---------------------------------------------------------------------------
       
  9510 // DoVideoNameRetryL
       
  9511 // ---------------------------------------------------------------------------
       
  9512 //
       
  9513 void
       
  9514 CCamAppController::DoVideoNameRetryL( TInt aStatus )
       
  9515   {
       
  9516   PRINT( _L( "Camera => CCamAppController::DoVideoNameRetryL" ) );
       
  9517   if ( IsFlagOn( iCameraController->State(), ECamVideoOn )
       
  9518     && iVideoNameRetries > 0 )        
       
  9519     {
       
  9520     PRINT1( _L( "Camera <> video rename failed retries = %d retrying rename" ), iVideoNameRetries );
       
  9521 
       
  9522     // Try again
       
  9523     --iVideoNameRetries;
       
  9524     TRAP_IGNORE( GenerateNextValidVideoPathL() );
       
  9525     if ( ECamCapturing != iInfo.iOperation && ECamPaused != iInfo.iOperation )
       
  9526       {
       
  9527       iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoNameBase );    
       
  9528       }
       
  9529     IssueSettingsChangeRequestL();
       
  9530     }
       
  9531   else if ( KErrDiskFull         == aStatus 
       
  9532          && ECamMediaStorageCard == IntegerSettingValue( ECamSettingItemVideoMediaStorage ) )
       
  9533     {
       
  9534     PRINT( _L( "Camera McaeoVideoPrepareComplete disk full and set to memory card " ) );
       
  9535     NotifyControllerObservers( ECamEventInvalidMemoryCard );
       
  9536 
       
  9537     // ForceUsePhoneMemory
       
  9538     if( ExistMassStorage() )
       
  9539         {
       
  9540         TRAP_IGNORE( 
       
  9541             {
       
  9542             iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9543             									     ECamMediaStorageMassStorage );
       
  9544             GenerateNextValidVideoPathL();
       
  9545             });
       
  9546         }
       
  9547     else
       
  9548         {
       
  9549         TCamMediaStorage storage = IntegerSettingValue(ECamSettingItemRemovePhoneMemoryUsage)?
       
  9550                                 ECamMediaStorageNone:
       
  9551                                 ECamMediaStoragePhone;
       
  9552         TRAP_IGNORE( 
       
  9553            {
       
  9554            iSettingsModel->SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, 
       
  9555                                                        storage );
       
  9556            GenerateNextValidVideoPathL();
       
  9557            });       
       
  9558         
       
  9559         }
       
  9560     iSettingProvider->AddPendingSettingChangeL( ECamSettingItemVideoMediaStorage );        
       
  9561     IssueSettingsChangeRequestL();
       
  9562     }
       
  9563   // No retries left
       
  9564   else 
       
  9565     {
       
  9566     PRINT1( _L( "Camera <> video prep failed retries = %d removing iVideoRequested" ), iVideoNameRetries );
       
  9567     // remove pending request, so that new attempts to record are not blocked
       
  9568     if ( iVideoRequested )
       
  9569       iVideoRequested = EFalse;
       
  9570 
       
  9571     User::LeaveIfError( aStatus );
       
  9572     }
       
  9573   PRINT( _L( "Camera <= CCamAppController::DoVideoNameRetryL" ) );
       
  9574   }
       
  9575 
       
  9576 // ---------------------------------------------------------------------------
       
  9577 // HandleCameraSequenceComplete
       
  9578 // ---------------------------------------------------------------------------
       
  9579 //
       
  9580 void
       
  9581 CCamAppController::HandleSequenceEventL( TInt              aStatus, 
       
  9582                                          TCamCameraEventId aEventId, 
       
  9583                                          TAny*             /*aEventData*/ )
       
  9584   {
       
  9585   PRINT( _L( "Camera => CCamAppController::HandleSequenceEventL" ) );
       
  9586 
       
  9587   if( iDismountPending &&
       
  9588     ( ECamCameraEventImageInit == aEventId ||
       
  9589       ECamCameraEventVideoInit == aEventId ||
       
  9590       ECamCameraEventSequenceEnd == aEventId ) )
       
  9591     {
       
  9592     iDismountPending = EFalse;
       
  9593     iDriveChangeNotifier->SendAllowDismount();	
       
  9594     }
       
  9595   if( ECamCameraEventSequenceEnd == aEventId )
       
  9596     {
       
  9597     ClearFlags( iBusyFlags, EBusySequence );
       
  9598 
       
  9599     if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && iInfo.iMode != ECamControllerShutdown )
       
  9600       {
       
  9601       PRINT( _L( "Camera <> In shutdown mode!!" ) );
       
  9602       IssueRequestL( ECamRequestRelease );
       
  9603       }
       
  9604     else
       
  9605       {
       
  9606       User::LeaveIfError( aStatus );
       
  9607       if( iCameraController && !iCameraController->IsWaitingIveResources() )
       
  9608         {
       
  9609         PRINT( _L( "Camera <> sequence end, proceed with pending.." ) );
       
  9610         ProceedPendingOrNotifyReadyL();  
       
  9611         }
       
  9612       }
       
  9613     }
       
  9614 
       
  9615   PRINT( _L( "Camera <= CCamAppController::HandleSequenceEventL" ) );
       
  9616   }
       
  9617 
       
  9618 // ---------------------------------------------------------------------------
       
  9619 // HandleRequestEventL
       
  9620 // ---------------------------------------------------------------------------
       
  9621 //
       
  9622 void
       
  9623 CCamAppController::HandleRequestEventL( TInt              aStatus, 
       
  9624                                         TCamCameraEventId aEventId, 
       
  9625                                         TAny*             /*aEventData*/ )
       
  9626   {
       
  9627   PRINT( _L( "Camera => CCamAppController::HandleRequestEventL" ) );
       
  9628 
       
  9629   // Check if pending operations that need immediate attention.
       
  9630   if( IsInShutdownMode() && iInfo.iMode != ECamControllerIdle && 
       
  9631       iInfo.iMode != ECamControllerShutdown && 
       
  9632       !iSaving && iInfo.iOperation != ECamCapturing && 
       
  9633       iInfo.iOperation != ECamCompleting ) 
       
  9634     {
       
  9635     PRINT( _L( "Camera <> in shutdown mode, release camera.." ) );
       
  9636     IssueDirectRequestL( ECamRequestRelease );
       
  9637     }
       
  9638   else
       
  9639     {
       
  9640     if( ECamCameraEventVideoStop == aEventId )
       
  9641       {
       
  9642       ClearFlags( iBusyFlags, EBusyRequest );
       
  9643       HandleVideoStopEvent( aStatus );
       
  9644       //If postcapture view is set to off notify controller ready event
       
  9645       //for updating counter.
       
  9646       if(IntegerSettingValue(ECamSettingItemVideoShowCapturedVideo)!=ECamSettOn )
       
  9647           {
       
  9648           NotifyControllerObservers( ECamEventControllerReady, KErrNone );
       
  9649           }
       
  9650       }
       
  9651     else if( ECamCameraEventVideoAsyncStop == aEventId )
       
  9652       {
       
  9653       HandleVideoAsyncStopEvent( aStatus );
       
  9654       }
       
  9655     else
       
  9656       {
       
  9657       // Error handling in one place
       
  9658       User::LeaveIfError( aStatus );
       
  9659   
       
  9660       // If our request is fully processed.
       
  9661       if( !CameraControllerBusy() )
       
  9662         {
       
  9663         PRINT( _L( "Camera <> camera not busy, proceed or notify ready.." ) );
       
  9664         ClearFlags( iBusyFlags, EBusyRequest );
       
  9665         ProceedPendingOrNotifyReadyL();
       
  9666         }
       
  9667       }
       
  9668     }
       
  9669   PRINT( _L( "Camera <= CCamAppController::HandleRequestEventL" ) );
       
  9670   }
       
  9671 
       
  9672 
       
  9673 // ---------------------------------------------------------------------------
       
  9674 // IssueRequestL
       
  9675 // ---------------------------------------------------------------------------
       
  9676 //
       
  9677 void
       
  9678 CCamAppController
       
  9679 ::IssueRequestL( const TCamCameraRequestId& aId )
       
  9680   {
       
  9681   PRINT1( _L("Camera => CCamAppController::IssueRequestL request[%s]"), KCamRequestNames[aId] );
       
  9682 
       
  9683   SetFlags( iBusyFlags, EBusyRequest );
       
  9684   iInfo.iBusyRequestId = aId;
       
  9685   
       
  9686   TRAPD( error, iCameraController->RequestL( iInfo.iBusyRequestId ) );
       
  9687   if( error != KErrNone )
       
  9688     {
       
  9689     ClearFlags( iBusyFlags, EBusyRequest );
       
  9690     iInfo.iBusyRequestId = ECamRequestNone;
       
  9691     User::Leave( error );
       
  9692     }
       
  9693 
       
  9694   PRINT( _L("Camera <= CCamAppController::IssueRequestL") );
       
  9695   }
       
  9696 
       
  9697 // ---------------------------------------------------------------------------
       
  9698 // IssueDirectRequestL
       
  9699 // ---------------------------------------------------------------------------
       
  9700 //
       
  9701 void
       
  9702 CCamAppController
       
  9703 ::IssueDirectRequestL( const TCamCameraRequestId& aId )
       
  9704   {
       
  9705   PRINT( _L("Camera => CCamAppController::IssueDirectRequestL") );
       
  9706   iCameraController->DirectRequestL( aId );
       
  9707   PRINT( _L("Camera <= CCamAppController::IssueDirectRequestL") );
       
  9708   }
       
  9709 
       
  9710 
       
  9711 // ---------------------------------------------------------------------------
       
  9712 // IssueSettingsChangeRequestL
       
  9713 // ---------------------------------------------------------------------------
       
  9714 //
       
  9715 void
       
  9716 CCamAppController::IssueSettingsChangeRequestL()
       
  9717   {
       
  9718   PRINT( _L("Camera => CCamAppController::IssueSettingsChangeRequestL") );
       
  9719   SetFlags( iBusyFlags, EBusySetting );
       
  9720 
       
  9721   TRAPD( error, iCameraController->RequestSettingsChangeL() );
       
  9722   if( KErrNone != error )
       
  9723     {
       
  9724     ClearFlags( iBusyFlags, EBusySetting );
       
  9725     User::Leave( error );
       
  9726     }
       
  9727   PRINT( _L("Camera <= CCamAppController::IssueSettingsChangeRequestL") );
       
  9728   }
       
  9729 
       
  9730 // ---------------------------------------------------------------------------
       
  9731 // ProceedPendingOrNotifyReadyL
       
  9732 // ---------------------------------------------------------------------------
       
  9733 //
       
  9734 void 
       
  9735 CCamAppController::ProceedPendingOrNotifyReadyL()
       
  9736   {
       
  9737   PRINT( _L("Camera => CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9738   PRINT4( _L("Camera <> iMode[%s] iTargetMode[%s] iImageMode[%s] iTargetImageMode[%s]"), 
       
  9739          KCamModeNames[iInfo.iMode], 
       
  9740          KCamModeNames[iInfo.iTargetMode], 
       
  9741          KCamImageModeNames[iInfo.iImageMode], 
       
  9742          KCamImageModeNames[iInfo.iTargetImageMode] );
       
  9743 
       
  9744   __ASSERT_DEBUG( iCameraController, CamPanic( ECamPanicNullPointer ) );
       
  9745 
       
  9746   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
  9747 
       
  9748   if( iInfo.iMode != iInfo.iTargetMode )
       
  9749     {
       
  9750     if ( !IsInShutdownMode() && !iSaving && iInfo.iOperation != ECamCapturing && iInfo.iOperation != ECamStandby ) 
       
  9751         {
       
  9752         PRINT1( _L("Camera <> CCamAppController: not in target mode, need to issue requests iInfo.iOperation=%d"), iInfo.iOperation );
       
  9753         IssueModeChangeSequenceL();
       
  9754         }
       
  9755     }
       
  9756   else if( iCameraController->ViewfinderState() != iInfo.iTargetVfState &&
       
  9757            IsAppUiAvailable () &&
       
  9758            !appUi->AppInBackground( ETrue ) &&
       
  9759            !( iConfigManager && iConfigManager->IsUIOrientationOverrideSupported() &&
       
  9760              iPendingRelease ) )
       
  9761     {
       
  9762     PRINT( _L("Camera <> CCamAppController: need to start/stop viewfinder..") );
       
  9763     IssueModeChangeSequenceL();
       
  9764     }
       
  9765   else if( iSettingProvider 
       
  9766         && iSettingProvider->PendingSettingChangeCount() > 0 )
       
  9767     {
       
  9768     PRINT( _L("Camera <> CCamAppController: settings pending, proceed now..") );
       
  9769     IssueSettingsChangeRequestL();
       
  9770     }
       
  9771   else if( iVideoPrepareNeeded )
       
  9772     {
       
  9773     PRINT( _L("Camera <> CCamAppController: video prepare pending, proceed now..") );
       
  9774     iVideoPrepareNeeded = EFalse;
       
  9775     IssueRequestL( ECamRequestVideoInit );
       
  9776     }
       
  9777   else
       
  9778     {
       
  9779     PRINT( _L("Camera <> CCamAppController: Target mode achieved") );
       
  9780     if( iCaptureModeTransitionInProgress )
       
  9781       {
       
  9782       PRINT( _L("Camera <> CCamAppController: capture mode transition complete") );
       
  9783       iCaptureModeTransitionInProgress = EFalse;
       
  9784       SetImageMode( iInfo.iTargetImageMode );
       
  9785       }
       
  9786 
       
  9787     if ( iSetNewPathnamesPending > ECamMediaStorageNone )
       
  9788       {
       
  9789       TRAP_IGNORE( SetPathnamesToNewStorageL( iSetNewPathnamesPending ) );
       
  9790       }
       
  9791 
       
  9792     if( iVideoRequested )
       
  9793       {
       
  9794       PRINT( _L("Camera <> starting recording..") );
       
  9795       iVideoRequested = EFalse;
       
  9796       IssueRequestL( ECamRequestVideoStart );
       
  9797       PRINT( _L("Camera <> ..done") );
       
  9798       }
       
  9799 
       
  9800 
       
  9801     NotifyControllerObservers( ECamEventEngineStateChanged, KErrNone ); 
       
  9802     NotifyControllerObservers( ECamEventControllerReady,    KErrNone ); 
       
  9803     }
       
  9804   PRINT( _L("Camera <= CCamAppController::ProceedPendingOrNotifyReadyL") );
       
  9805   }
       
  9806 
       
  9807 // ---------------------------------------------------------------------------
       
  9808 // SetStateFromEvent
       
  9809 // ---------------------------------------------------------------------------
       
  9810 //
       
  9811 void
       
  9812 CCamAppController::SetStateFromEvent( TCamCameraEventId aEventId )
       
  9813   {   
       
  9814   PRINT3( _L("Camera => CCamAppController::SetStateFromEvent mode[%s] operation[%s] event[%s]"), 
       
  9815           KCamModeNames[iInfo.iMode], 
       
  9816           KCamCaptureOperationNames[iInfo.iOperation],
       
  9817           KCamCameraEventNames[aEventId]
       
  9818         );
       
  9819   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() ); 
       
  9820   switch( aEventId )
       
  9821     {
       
  9822     // =================================
       
  9823     case ECamCameraEventReserveLose:
       
  9824       // SetMode( ECamControllerShutdown );
       
  9825       SetMode( ECamControllerIdle );
       
  9826       SetOperation( ECamNoOperation );
       
  9827       // we dont need location trail anymore.
       
  9828       StopLocationTrail();
       
  9829       break;
       
  9830     // ---------------------------------
       
  9831     case ECamCameraEventPowerOn:
       
  9832       PRINT( _L("Camera <> Init key sound system..") );
       
  9833       iSoundPlayer->InitKeySoundSystem();
       
  9834       PRINT( _L("Camera <> ..Init key sound system done") );      
       
  9835       break;
       
  9836     // ---------------------------------
       
  9837     case ECamCameraEventPowerOff:
       
  9838       // Reset the flash error status
       
  9839       if( iFlashStatus ) iFlashStatus->SetFlashError( EFalse );
       
  9840       SetMode( ECamControllerIdle );
       
  9841       SetOperation( ECamNoOperation );
       
  9842       break;
       
  9843     // =================================
       
  9844     // VF events
       
  9845     case ECamCameraEventVfStart:
       
  9846       if(  iBacklightTimer 
       
  9847        && !iBacklightTimer->IsActive() )
       
  9848         {
       
  9849         //iBacklightTimer->Start( KBacklighTimerInterval,
       
  9850         //                        KBacklighTimerInterval, 
       
  9851         //                        TCallBack( ResetInactivityTimer, this ) );        
       
  9852         iBacklightTimer->Start( 0,
       
  9853                                 KBacklighTimerInterval, 
       
  9854                                 TCallBack( ResetInactivityTimer, this ) );
       
  9855         }
       
  9856 		iAFCancelInProgress = EFalse;
       
  9857       break;
       
  9858     // ---------------------------------
       
  9859     case ECamCameraEventVfStop:
       
  9860       if( iBacklightTimer )
       
  9861         {
       
  9862         iBacklightTimer->Cancel();
       
  9863         }
       
  9864       break;
       
  9865     // =================================
       
  9866     case ECamCameraEventImageInit:
       
  9867       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageInit") );      
       
  9868       SetMode( ECamControllerImage );
       
  9869 
       
  9870       // Set the capture count now, so we don't need to set it when starting capture.
       
  9871       TRAP_IGNORE( InitCaptureLimitL() );
       
  9872       SetOperation( ECamNoOperation );
       
  9873       NotifyControllerObservers( ECamEventImageQualityChanged );
       
  9874 
       
  9875       break;
       
  9876     // ---------------------------------
       
  9877     case ECamCameraEventImageStart: // Capture started, not finished.
       
  9878       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStart") );      
       
  9879       SetOperation( ECamCapturing );
       
  9880 
       
  9881       // Make sure our cached value for image filename number is up to date.      
       
  9882       iImageNumberCache = IntegerSettingValue( ECamSettingItemPhotoNumber );
       
  9883       break;
       
  9884     // ---------------------------------
       
  9885     case ECamCameraEventImageStop: // Capture finished, unless in burst    
       
  9886       PRINT ( _L("Camera <> CCamAppController::SetStateFromEvent .. case ECamCameraEventImageStop") );      
       
  9887       // Store image counter now.
       
  9888       TRAP_IGNORE( SetIntegerSettingValueL( ECamSettingItemPhotoNumber, iImageNumberCache ) );
       
  9889 
       
  9890       if ( ECamImageCaptureBurst != iInfo.iImageMode )
       
  9891         {
       
  9892         
       
  9893         //If canceled autofocusing previously then have to set
       
  9894         //autofocus range to get autofocusing work again.
       
  9895 
       
  9896         if(iAFCancelInProgress )
       
  9897         {
       
  9898            iAFCancelInProgress = EFalse; 
       
  9899            TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );                                                                  
       
  9900 
       
  9901         }
       
  9902 
       
  9903         
       
  9904 // No operation change here.
       
  9905 // Set to Completing in SS event, and ECamNoOperation when image saved.
       
  9906 //        SetOperation( ECamNoOperation );
       
  9907         }
       
  9908       break;
       
  9909     // ---------------------------------
       
  9910     case ECamCameraEventImageRelease:
       
  9911       SetMode( ECamControllerIdle );
       
  9912       SetOperation( ECamNoOperation );
       
  9913       break;
       
  9914     // =================================
       
  9915     case ECamCameraEventVideoInit:
       
  9916       SetMode( ECamControllerVideo );
       
  9917       SetOperation( ECamNoOperation );
       
  9918       break;
       
  9919     // ---------------------------------
       
  9920     case ECamCameraEventVideoStart:
       
  9921       iVideoRequested = EFalse;
       
  9922       SetOperation( ECamCapturing );
       
  9923       break;
       
  9924     // ---------------------------------
       
  9925      case ECamCameraEventVideoPause:
       
  9926        PlaySound( ECamVideoPauseSoundId, EFalse );
       
  9927        SetOperation( ECamPaused );
       
  9928        break;            
       
  9929     // ---------------------------------
       
  9930     case ECamCameraEventVideoStop:
       
  9931       SetOperation( ECamCompleting );
       
  9932       break;
       
  9933     // ---------------------------------
       
  9934     case ECamCameraEventVideoRelease:
       
  9935       SetMode( ECamControllerIdle );
       
  9936       SetOperation( ECamNoOperation );
       
  9937       break;
       
  9938     // =================================        
       
  9939     case ECamCameraEventStartAutofocus:
       
  9940 
       
  9941       if ( !CurrentSceneHasForcedFocus() &&
       
  9942            !iAFCancelInProgress )
       
  9943         {       
       
  9944         PRINT( _L("ECamCameraEventStartAutofocus -> Set operation state to ECamFocusing") );
       
  9945         iCurrentAFRequest=ECamRequestStartAutofocus;
       
  9946         SetOperation( ECamFocusing );
       
  9947         // fixed toolbar is used only with touch devices
       
  9948         if ( IsTouchScreenSupported() )
       
  9949             {
       
  9950             CAknToolbar* fixedToolbar = appUi->CurrentFixedToolbar();
       
  9951             if ( fixedToolbar )
       
  9952                 {
       
  9953                 CAknToolbarExtension* extension = fixedToolbar->ToolbarExtension();
       
  9954                 if ( extension )
       
  9955                     {
       
  9956                     // Keep toolbar extension hidden after the half press key is released 
       
  9957                     extension->SetShown( EFalse );
       
  9958                     }
       
  9959                 fixedToolbar->SetToolbarVisibility( EFalse );
       
  9960                 } 
       
  9961             }
       
  9962         }    
       
  9963       break;       
       
  9964     // ---------------------------------
       
  9965     case ECamCameraEventAutofocusSuccessful:
       
  9966     case ECamCameraEventAutofocusFailed:
       
  9967         {
       
  9968         OstTrace0( CAMERAAPP_PERFORMANCE, CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_AF_LOCK 0" ); //CCORAPP_AF_LOCK_END
       
  9969         OstTrace0( CAMERAAPP_PERFORMANCE, DUP1_CCAMAPPCONTROLLER_SETSTATEFROMEVENT, "e_CAM_APP_OVERLAY_UPD 1" );    //CCORAPP_OVERLAY_UPD_START
       
  9970         PRINT2( _L("Camera <> CCamAppController::SetStateFromEvent - iPendingAFRequest[%s] iCurrentAFRequest[%s]"), 
       
  9971                 KCamRequestNames[iPendingAFRequest], 
       
  9972                 KCamRequestNames[iCurrentAFRequest] );
       
  9973    	    
       
  9974    	    if( iAFCancelInProgress && ECamRequestCancelAutofocus == iCurrentAFRequest &&
       
  9975    	         ECamRequestCancelAutofocus == iPendingAFRequest )
       
  9976    		    {
       
  9977             // Cancelling done, camera lens is in hyperfocal position.
       
  9978             // Return AF range back to normal, so that next autofocus request
       
  9979             // will use the right range for this scene.
       
  9980             iAFCancelInProgress = EFalse;  
       
  9981             TRAP_IGNORE( iCameraController->DirectRequestL( ECamRequestSetAfRange ) );	    
       
  9982    		    iPendingAFRequest=0;
       
  9983    		    iCurrentAFRequest=0;
       
  9984    		    NotifyControllerObservers( ECamEventFocusCancelled );
       
  9985    		    
       
  9986             if ( !iCaptureRequested )
       
  9987                 {
       
  9988                 SetOperation( ECamNoOperation );
       
  9989                 }
       
  9990             else
       
  9991                 {
       
  9992                 // do not notify observers if this happens after capture
       
  9993                 // has been requested as that would result in invalid ui state
       
  9994                 iInfo.iOperation = ECamNoOperation;
       
  9995                 if( IsAfNeeded() )
       
  9996                     {
       
  9997                     SetAfNeeded( EFalse );
       
  9998                     StartAutoFocus();
       
  9999                     }
       
 10000                 }
       
 10001    		    }
       
 10002    		 else if( iCurrentAFRequest==iPendingAFRequest &&
       
 10003    		        iPendingAFRequest==ECamRequestStartAutofocus
       
 10004                 && !CurrentSceneHasForcedFocus()
       
 10005              )
       
 10006              {
       
 10007 	         if( aEventId==ECamCameraEventAutofocusSuccessful )
       
 10008 	            {
       
 10009 
       
 10010                 PRINT( _L("ECamCameraEventAutofocusSuccessful -> Set operation state to ECamFocused") );
       
 10011           
       
 10012         
       
 10013                 if( iConfigManager && iConfigManager->IsAutoFocusSupported() &&
       
 10014                     !iCaptureRequested && appUi &&	appUi->SelfTimer() && 
       
 10015                     !appUi->SelfTimer()->IsActive())
       
 10016                     {
       
 10017                     if ( !iSilentProfile || iShutterSndAlwaysOn  )
       
 10018                         {
       
 10019                         // Play only if camera tones are not set off
       
 10020                         PlaySound(ECamAutoFocusComplete, EFalse);
       
 10021                         }
       
 10022                     }
       
 10023                 SetOperation( ECamFocused );
       
 10024 	            }    
       
 10025 	        else if(  aEventId==ECamCameraEventAutofocusFailed )
       
 10026 	    	    {
       
 10027                 PRINT( _L("ECamCameraEventAutofocusFailed -> Set operation state to ECamFocusFailed") );
       
 10028                 if ( iConfigManager && iConfigManager->IsAutoFocusSupported() )
       
 10029                     {
       
 10030                     PlaySound( ECamAutoFocusFailed, EFalse );
       
 10031                     }
       
 10032                 SetOperation( ECamFocusFailed );
       
 10033                 }
       
 10034             iPendingAFRequest=0;
       
 10035             iCurrentAFRequest=0;	        
       
 10036             }
       
 10037         else if( iCurrentAFRequest != iPendingAFRequest && iPendingAFRequest !=0 
       
 10038                  && !CurrentSceneHasForcedFocus()
       
 10039             )
       
 10040             {
       
 10041             iCurrentAFRequest=iPendingAFRequest;
       
 10042             iPendingAFRequest=0;
       
 10043             TryAFRequest( iCurrentAFRequest ); 
       
 10044             }
       
 10045         else if( CurrentSceneHasForcedFocus() )
       
 10046             {
       
 10047             // Autofocus flags has to be reset in forced focus cases
       
 10048             iPendingAFRequest=0;
       
 10049             iCurrentAFRequest=0;
       
 10050             }
       
 10051         }
       
 10052       break;
       
 10053     // ---------------------------------      
       
 10054     case ECamCameraEventCancelAutofocus:
       
 10055         {  
       
 10056         // Set iAFCancelInProgress to true so that we don't change the 
       
 10057         // reticule for the next focus successful/focus failed event.
       
 10058         iAFCancelInProgress = ETrue;
       
 10059         iCurrentAFRequest = ECamRequestCancelAutofocus;
       
 10060         // fixed toolbar is used only with touch devices
       
 10061         if ( !iCaptureRequested && IsTouchScreenSupported() )
       
 10062             {
       
 10063             appUi->SetToolbarVisibility();  // avoid flickering in settings view
       
 10064             }
       
 10065         }
       
 10066       break;             
       
 10067     // =================================        
       
 10068     default:
       
 10069       // No change to state with other events
       
 10070       break;
       
 10071     // =================================        
       
 10072     }
       
 10073   PRINT2( _L("Camera <= CCamAppController::SetStateFromEvent mode[%s] operation[%s]"), 
       
 10074           KCamModeNames[iInfo.iMode], 
       
 10075           KCamCaptureOperationNames[iInfo.iOperation] );
       
 10076   }
       
 10077 
       
 10078 void 
       
 10079 CCamAppController::InitCaptureLimitL()
       
 10080   {
       
 10081   // Set the capture count now, so we don't need to set it when starting capture.
       
 10082   switch( iInfo.iTargetImageMode )
       
 10083     {
       
 10084     case ECamImageCaptureBurst:
       
 10085       PRINT1( _L("Camera <> CCamAppController .. burst mode as target, set capture limit to %d"), KShortBurstCount );      
       
 10086       SetCaptureLimitL( KShortBurstCount );
       
 10087       break;
       
 10088     case ECamImageCaptureTimeLapse:
       
 10089       PRINT1( _L("Camera <> CCamAppController .. timelapse mode as target, set capture limit locally to max %d"), iLongSequenceLimit );      
       
 10090       SetCaptureLimitL( iLongSequenceLimit );
       
 10091       break;
       
 10092     default:
       
 10093       PRINT( _L("Camera <> CCamAppController .. single mode as target, set capture limit locally to 1") );      
       
 10094       SetCaptureLimitL( 1 );
       
 10095       break;
       
 10096     }
       
 10097   }
       
 10098 
       
 10099 
       
 10100 // ===========================================================================
       
 10101 // 
       
 10102 TCamAppControllerInfo::TCamAppControllerInfo()
       
 10103   :  iActiveCamera         ( ECamActiveCameraNone ),
       
 10104      iMode                 ( ECamControllerIdle   ),
       
 10105      iTargetMode           ( ECamControllerIdle   ),
       
 10106      iImageMode            ( ECamImageCaptureNone ),
       
 10107      iTargetImageMode      ( ECamImageCaptureNone ),     
       
 10108      iOperation            ( ECamNoOperation      ),
       
 10109      iTargetVfState        ( ECamTriIdle          ),
       
 10110      iViewfinderMirror     ( EFalse               ),
       
 10111      iTargetImageResolution( 0                    ),
       
 10112      iTargetImageQuality   ( 0                    ),
       
 10113      iBusyRequestId        ( ECamRequestNone      )
       
 10114   {
       
 10115   }
       
 10116 
       
 10117  
       
 10118 // ===========================================================================
       
 10119 
       
 10120 
       
 10121 //
       
 10122 //
       
 10123 //
       
 10124 void CCamAppController::HandleFileHarvestingComplete()
       
 10125     {
       
 10126     PRINT( _L("Camera => CCamAppController::HandleFileHarvestingComplete" ) );
       
 10127     // If release required but not done in postcapture not shown mode this is the
       
 10128 	// last time to do it. Otherwise problems occurs in 2ndary camera if opened
       
 10129     if ( iPendingRelease && ECamSettOff == IntegerSettingValue( ECamSettingItemShowCapturedPhoto ) )
       
 10130        {
       
 10131        PRINT( _L("Camera <> CCamAppController::HandleFileHarvestingComplete, releasing" ) );	
       
 10132        ReleaseCamera();	
       
 10133        }
       
 10134     PRINT( _L("Camera <= CCamAppController::HandleFileHarvestingComplete" ) );
       
 10135     }
       
 10136 
       
 10137 
       
 10138 //
       
 10139 //CCamAppController::DeRegisterHarverterClientEvents
       
 10140 //
       
 10141 void CCamAppController::DeRegisterHarverterClientEvents()
       
 10142     {
       
 10143     if ( iImageSaveActive )
       
 10144         {
       
 10145 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
 10146         iImageSaveActive->DeRegisterHarverterClientEvents();
       
 10147 #endif //defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__)
       
 10148         }
       
 10149     }
       
 10150 
       
 10151 
       
 10152 // ---------------------------------------------------------------------------
       
 10153 // CCamAppController::Configuration
       
 10154 //
       
 10155 // ---------------------------------------------------------------------------
       
 10156 //
       
 10157 CCamConfiguration* 
       
 10158 CCamAppController::Configuration() const
       
 10159     {
       
 10160     return iConfiguration;  
       
 10161     }
       
 10162 
       
 10163 
       
 10164 // ---------------------------------------------------------------------------
       
 10165 // CCamAppController::RestoreSettingsToCameraL
       
 10166 // Calls RestoreSettingIfNecessaryL for all supported camera settings.
       
 10167 // In case there were settings needing restoring, and camera controller
       
 10168 // is not busy, request camera controller to start setting changes.
       
 10169 // ---------------------------------------------------------------------------
       
 10170 // 
       
 10171 void
       
 10172 CCamAppController::RestoreSettingsToCameraL()
       
 10173     {
       
 10174     PRINT( _L("Camera => CCamAppController::RestoreSettingsToCameraL" ) );  
       
 10175     const TCamCameraMode mode = CurrentMode(); 
       
 10176     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 10177     if ( IsAppUiAvailable() && appUi->CurrentViewState()==ECamViewStateUserSceneSetup )
       
 10178         {
       
 10179         //restore user scence setting
       
 10180         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneWhitebalance );
       
 10181         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneExposure );
       
 10182         DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneFlash ); 
       
 10183         if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
 10184           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneColourFilter );        
       
 10185         if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
 10186           DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneBrightness ); 
       
 10187         if ( UiConfigManagerPtr()->IsContrastSupported() )
       
 10188            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneContrast );   
       
 10189         if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )	
       
 10190            DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneLightSensitivity );
       
 10191         if ( ECamControllerImage == mode )
       
 10192           {
       
 10193           if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
 10194             DirectRestoreSettingIfNecessaryL( ECamSettingItemUserSceneImageSharpness );
       
 10195           DirectRestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
 10196           }
       
 10197         else if ( ECamControllerVideo == mode )
       
 10198           {
       
 10199           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
 10200           DirectRestoreSettingIfNecessaryL( ECamSettingItemVideoStab);
       
 10201           }
       
 10202         }
       
 10203     else if(iInfo.iActiveCamera == ECamActiveCameraPrimary)
       
 10204 	    {
       
 10205         if ( ECamControllerImage == mode )
       
 10206 	        {
       
 10207 	        // Add rest of the pending settings where needed
       
 10208 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoWhiteBalance );
       
 10209 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoExposure );
       
 10210 
       
 10211 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
 10212 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoColourFilter );        
       
 10213 	        
       
 10214 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
 10215 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoBrightness );
       
 10216 
       
 10217 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
 10218 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoContrast );
       
 10219 
       
 10220 	        if ( UiConfigManagerPtr()->IsSharpnessFeatureSupported() )
       
 10221 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoImageSharpness );
       
 10222 	      
       
 10223 	        if ( UiConfigManagerPtr()->IsISOSupported() || UiConfigManagerPtr()->IsExtendedLightSensitivitySupported() )
       
 10224 	            {
       
 10225 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoLightSensitivity );
       
 10226 	            }
       
 10227 	        
       
 10228 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicPhotoFlash );
       
 10229 	        
       
 10230 	        RestoreSettingIfNecessaryL( ECamSettingItemPhotoDigitalZoom );
       
 10231 	        }    
       
 10232 	    else if ( ECamControllerVideo == mode )
       
 10233 	        {
       
 10234 	        // Video settings in the toolbar
       
 10235 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoWhiteBalance );
       
 10236 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoExposure );
       
 10237 
       
 10238 	        if ( UiConfigManagerPtr()->IsColorToneFeatureSupported() )
       
 10239 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoColourFilter );
       
 10240 	        
       
 10241 	        // The following settings are not supported in video mode toolbar
       
 10242 	        // However, the values may need to be reset, in case the setting was
       
 10243 	        // changed in image mode
       
 10244 	        if ( UiConfigManagerPtr()->IsBrightnessSupported() )
       
 10245 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoBrightness );
       
 10246 
       
 10247 	        if ( UiConfigManagerPtr()->IsContrastSupported() )
       
 10248 	            RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoContrast );
       
 10249 
       
 10250 	        if ( UiConfigManagerPtr()->IsVideoStabilizationSupported() )
       
 10251 	            {
       
 10252 	            RestoreSettingIfNecessaryL( ECamSettingItemVideoStab );      
       
 10253 	            }
       
 10254 	        RestoreSettingIfNecessaryL( ECamSettingItemVideoDigitalZoom );
       
 10255 	        
       
 10256 	        RestoreSettingIfNecessaryL( ECamSettingItemDynamicVideoFlash );
       
 10257 	        
       
 10258 	        RestoreSettingIfNecessaryL( ECamSettingItemContinuousAutofocus ); 
       
 10259 	        }
       
 10260 	    }
       
 10261     else if(iInfo.iActiveCamera == ECamActiveCameraSecondary)
       
 10262         {
       
 10263         if ( ECamControllerImage == mode )
       
 10264                 {
       
 10265                 // Not needed
       
 10266                 }    
       
 10267             else if ( ECamControllerVideo == mode )
       
 10268                 {
       
 10269                 // Not needed
       
 10270                 }
       
 10271         }
       
 10272     else
       
 10273         {
       
 10274         // Do nothing
       
 10275         }
       
 10276     
       
 10277     if( iSettingProvider->PendingSettingChangeCount() > 0 &&
       
 10278         !iCameraController->ControllerInfo().iBusy )
       
 10279         {
       
 10280         PRINT( _L("Camera <> CCamAppController::RestoreSettingsToCameraL - Issue settings change request") );
       
 10281         IssueSettingsChangeRequestL( );    
       
 10282         }
       
 10283         
       
 10284     PRINT( _L("Camera <= CCamAppController::RestoreSettingsToCameraL" ) );          
       
 10285     }
       
 10286  
       
 10287 // ---------------------------------------------------------------------------
       
 10288 // CCamAppController::RestoreSettingIfNecessaryL
       
 10289 // Checks from camera controller, whether the value of the setting given
       
 10290 // as argument has same value in camera hw and settings model (UI).
       
 10291 // If value is not the same, add the setting id to settingsmodel's list
       
 10292 // of pending changes.
       
 10293 // ---------------------------------------------------------------------------
       
 10294 //     
       
 10295 void
       
 10296 CCamAppController::RestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
 10297     {    
       
 10298     // Convert UI setting ID to camera controller setting ID  
       
 10299     TCamCameraSettingId camSettingId = 
       
 10300       CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem );
       
 10301     
       
 10302     if( !iCameraController->SettingValueUpToDateL( camSettingId ) )
       
 10303         {
       
 10304         PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
 10305         iSettingProvider->AddPendingSettingChangeL( aSettingItem );  
       
 10306         }
       
 10307     else
       
 10308         {
       
 10309         if( aSettingItem == ECamSettingItemDynamicVideoFlash )
       
 10310             {
       
 10311             TCamCameraSettingId cameraId( 
       
 10312                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
 10313             iCameraController->DirectSettingsChangeL( cameraId );
       
 10314             }
       
 10315         PRINT1( _L("RestoreSettingIfNecessaryL - Setting %s has up-to-date value, no need to restore"), KCamSettingItemNames[aSettingItem] );      
       
 10316         } 
       
 10317     }            
       
 10318 
       
 10319 
       
 10320 // ---------------------------------------------------------------------------
       
 10321 // CCamAppController::DirectRestoreSettingIfNecessaryL
       
 10322 // Checks if the setting needs restoring (UI setting value doesn't match
       
 10323 // the actual setting value in camera).  In that case, function 
       
 10324 // directly set settting to camera
       
 10325 // ---------------------------------------------------------------------------
       
 10326 // 
       
 10327 void
       
 10328 CCamAppController::DirectRestoreSettingIfNecessaryL( TCamSettingItemIds aSettingItem )
       
 10329     {
       
 10330 
       
 10331     TCamCameraSettingId cameraId( 
       
 10332                 CCamSettingConversion::Map2CameraControllerSettingId( aSettingItem ) );
       
 10333     if ( !iCameraController->SettingValueUpToDateL( cameraId ) )
       
 10334       {
       
 10335       PRINT1( _L("RestoreSettingIfNecessaryL - Restoring value for setting %s"), KCamSettingItemNames[aSettingItem] );   
       
 10336       iCameraController->DirectSettingsChangeL( cameraId );  
       
 10337       }
       
 10338     }
       
 10339 // -----------------------------------------------------------------------------
       
 10340 // CCamAppController::RestartTimeLapseTimerL()
       
 10341 // 
       
 10342 // -----------------------------------------------------------------------------
       
 10343 //   
       
 10344 void CCamAppController::RestartTimeLapseTimerL()
       
 10345 	{
       
 10346 	PRINT( _L("Camera => CCamAppController::RestartTimeLapseTimerL inside this function" ))  
       
 10347    	if ( iTimeLapseTimer )
       
 10348 		{
       
 10349 		iTimeLapseTimer->Cancel();		
       
 10350 		iTimeLapseTimer->SetTimeout( KSecondInMicSec );
       
 10351 		}
       
 10352     else
       
 10353         {
       
 10354         iTimeLapseTimer = CCamTimer::NewL( KSecondInMicSec, TCallBack( CCamAppController::TimeLapseTimeoutL, this ) );
       
 10355         }
       
 10356 
       
 10357     NotifyControllerObservers( ECamEventCounterUpdated );
       
 10358     PRINT( _L("Camera <> CCamAppController::RestartTimeLapseTimerL starting timelapse timer" ));
       
 10359     
       
 10360     iTimeLapseStartTime.HomeTime(); 
       
 10361     iTimeLapseTimer->StartTimer();
       
 10362 	
       
 10363 	// Following trace may be useful to see timing related handling in TimeLapse mode 
       
 10364 	// TDateTime stTime = iTimeLapseStartTime.DateTime();
       
 10365 	// PRINT3( _L("Start time: %d:%d:%d"), stTime.Minute(), stTime.Second(), stTime.MicroSecond() );
       
 10366 	
       
 10367 	PRINT( _L("Camera <= CCamAppController::RestartTimeLapseTimerL" ))  
       
 10368 	}
       
 10369  
       
 10370      
       
 10371 // ---------------------------------------------------------------------------
       
 10372 // SetSettingsRestoreNeeded
       
 10373 // ---------------------------------------------------------------------------
       
 10374 //     
       
 10375 void  
       
 10376 CCamAppController::SetSettingsRestoreNeeded()
       
 10377   {
       
 10378   iSettingsRestoreNeeded = ETrue;
       
 10379   }
       
 10380 
       
 10381 // ---------------------------------------------------------------------------
       
 10382 // IsSettingsRestoreNeeded
       
 10383 // ---------------------------------------------------------------------------
       
 10384 //     
       
 10385 TBool 
       
 10386 CCamAppController::IsSettingsRestoreNeeded() const
       
 10387   {
       
 10388   return iSettingsRestoreNeeded;
       
 10389   }    
       
 10390 
       
 10391 // ---------------------------------------------------------------------------
       
 10392 // StaticSettingsModel
       
 10393 //
       
 10394 // Gets the handle to the settings model, which is used inturn by the
       
 10395 // plugin to call the interfaces for performing needed actions.
       
 10396 // ---------------------------------------------------------------------------
       
 10397 //
       
 10398 TBool 
       
 10399 CCamAppController::IsSceneSupported( const TInt aSceneId, TBool aPhotoScene ) const
       
 10400   {
       
 10401   if ( aPhotoScene )
       
 10402       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsImageSceneSupported( aSceneId );
       
 10403   else
       
 10404       return static_cast<CCamSettingsModel*>(iSettingsModel)->IsVideoSceneSupported( aSceneId );
       
 10405   }
       
 10406 
       
 10407 // ---------------------------------------------------------------------------
       
 10408 // StaticSettingsModel
       
 10409 //
       
 10410 // Gets the handle to the settings model, which is used inturn by the
       
 10411 // plugin to call the interfaces for performing needed actions.
       
 10412 // ---------------------------------------------------------------------------
       
 10413 //
       
 10414 MCamStaticSettings& 
       
 10415 CCamAppController::StaticSettingsModel()
       
 10416   {
       
 10417   return static_cast<CCamSettingsModel*>(iSettingsModel)->StaticSettingsModel();
       
 10418   }
       
 10419 
       
 10420 
       
 10421 // ---------------------------------------------------------------------------
       
 10422 // EngineRequestsPending
       
 10423 // ---------------------------------------------------------------------------
       
 10424 //     
       
 10425 TBool CCamAppController::EngineRequestsPending() const
       
 10426    {
       
 10427    return IsFlagOn( iBusyFlags, EBusyRequest );
       
 10428    }  
       
 10429  
       
 10430 // ---------------------------------------------------------------------------
       
 10431 // CalculateVideoTimeRemainingL
       
 10432 //
       
 10433 // ---------------------------------------------------------------------------
       
 10434 //
       
 10435 TTimeIntervalMicroSeconds
       
 10436 CCamAppController::CalculateVideoTimeRemainingL( TCamMediaStorage aStorage )
       
 10437   {
       
 10438   RFs& fs = CEikonEnv::Static()->FsSession();
       
 10439   TInt drive = 0;
       
 10440   // Check if setting the new video path is pending. The path may not have been 
       
 10441   // set if camera controller was busy or video mode not initialized. This 
       
 10442   // happens e.g. while in Settings menu.
       
 10443   // If yes, use the storage media that is going to be used next.
       
 10444   if( iSetNewPathnamesPending != ECamMediaStorageNone )
       
 10445     {
       
 10446     aStorage = iSetNewPathnamesPending;
       
 10447     }
       
 10448   if(aStorage == ECamMediaStorageCurrent)
       
 10449 	{
       
 10450   const TDesC& filename = CurrentVideoFileName();
       
 10451   TParse fp;
       
 10452   User::LeaveIfError(fs.Parse(filename, fp));
       
 10453   TPtrC driveletter = fp.Drive();
       
 10454   TChar drl = driveletter[0];
       
 10455   User::LeaveIfError(fs.CharToDrive(drl, drive));  
       
 10456 	}
       
 10457   else
       
 10458 	{
       
 10459 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10460 	switch(aStorage)
       
 10461 		{
       
 10462 		case ECamMediaStoragePhone:
       
 10463 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10464 			break; 
       
 10465 		case ECamMediaStorageCard:
       
 10466 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10467 			break;
       
 10468 		case ECamMediaStorageMassStorage:
       
 10469 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10470 			break;
       
 10471 		default:
       
 10472 			break;
       
 10473 		}
       
 10474 	User::LeaveIfError(DriveInfo::GetDefaultDrive( driveInfo, drive ));
       
 10475 	}
       
 10476     
       
 10477   // Get critical level for this drive type
       
 10478   TDriveInfo driveInfo;
       
 10479   fs.Drive(driveInfo, drive);
       
 10480     
       
 10481   TInt criticalDiskVal = 0;
       
 10482   if( driveInfo.iType == EMediaRam ) //RAM drives have diff critical levels
       
 10483 	{
       
 10484 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10485 	User::LeaveIfError( 
       
 10486 		repository->Get( KRamDiskCriticalLevel, criticalDiskVal ) );
       
 10487 	CleanupStack::PopAndDestroy( repository );			
       
 10488 	}
       
 10489   else // Some other media type
       
 10490 	{
       
 10491 	CRepository* repository = CRepository::NewLC( KCRUidDiskLevel );
       
 10492 	User::LeaveIfError( 
       
 10493 		repository->Get( KDiskCriticalThreshold, criticalDiskVal ) );
       
 10494 	CleanupStack::PopAndDestroy( repository );			
       
 10495 	}   
       
 10496  
       
 10497   // Get the available space in volumeinfo.iFree
       
 10498   TVolumeInfo volumeinfo; 
       
 10499   User::LeaveIfError(fs.Volume(volumeinfo, drive));   
       
 10500    
       
 10501   // Get the current video quality data
       
 10502   TInt videoQuality = iSettingsModel->IntegerSettingValue( 
       
 10503   										ECamSettingItemVideoQuality );
       
 10504   CCamVideoQualityLevel& level = *( iSettingsModel->
       
 10505   									VideoQualityArray() )[videoQuality];     
       
 10506   
       
 10507   // Audio recording on/muted
       
 10508   TInt audioRec = iSettingsModel->IntegerSettingValue( 
       
 10509   									ECamSettingItemVideoAudioRec );
       
 10510   TBool audioMute = ECamSettOff == audioRec;
       
 10511   
       
 10512   TInt64 videoLimit =  KMaxTUint32; // 4G limit
       
 10513   // Video file size limit (MMS case)
       
 10514   if( ECamVideoClipShort == level.VideoLength() )
       
 10515     {
       
 10516     // Short video, needs to fit into MMS message
       
 10517     videoLimit = CamUtility::MaxMmsSizeInBytesL();  
       
 10518     }
       
 10519   
       
 10520   TCamVideoTime videoTime( volumeinfo.iFree,            // Free space
       
 10521                            criticalDiskVal,             // Critical space
       
 10522                            //level.VideoFileType(),       // Video codec
       
 10523                            level.VideoBitRate(),        // Video bitrate
       
 10524                            //level.AudioType(),           // Audio FourCC
       
 10525                            level.AudioBitRate(),        // Audio bitrate
       
 10526                            videoLimit,                  // File size limit
       
 10527                            audioMute,                   // Mute audio?
       
 10528                            iConfiguration->CMRAvgVideoBitRateScaler() );
       
 10529                                                 
       
 10530   return videoTime.GetRemainingTimeL();    
       
 10531   }
       
 10532 
       
 10533 
       
 10534 // ---------------------------------------------------------------------------
       
 10535 // SetRemainingImageStored
       
 10536 // ---------------------------------------------------------------------------
       
 10537 //     
       
 10538 void  
       
 10539 CCamAppController::SetRemainingImageStored()
       
 10540   {
       
 10541   iValueIsStored = ETrue;
       
 10542   }
       
 10543 // ---------------------------------------------------------------------------
       
 10544 // IsRemainingImageStored
       
 10545 // ---------------------------------------------------------------------------
       
 10546 //
       
 10547 TBool 
       
 10548 CCamAppController::IsRemainingImageStored() const
       
 10549   {
       
 10550   return iValueIsStored;
       
 10551   }
       
 10552 
       
 10553 // ---------------------------------------------------------------------------
       
 10554 // IsSavingInProgress
       
 10555 // ---------------------------------------------------------------------------
       
 10556 //
       
 10557 TBool 
       
 10558 CCamAppController::IsSavingInProgress() const
       
 10559   {
       
 10560   return ( iImageSaveActive->Count() > 0 );
       
 10561   }
       
 10562 
       
 10563 // ---------------------------------------------------------------------------
       
 10564 // CapturedImages
       
 10565 // ---------------------------------------------------------------------------
       
 10566 //
       
 10567  TInt CCamAppController::CapturedImages() const
       
 10568   {
       
 10569   return iCameraController->ControllerInfo().iCaptureCount;
       
 10570   }
       
 10571         
       
 10572 // -----------------------------------------------------------------------------
       
 10573 //
       
 10574 // -----------------------------------------------------------------------------
       
 10575 //
       
 10576 void CCamAppController::SetSettingsPlugin( CCamGSInterface* aPlugin )
       
 10577 	{
       
 10578 	iPlugin = aPlugin;
       
 10579 	}
       
 10580 
       
 10581 // ---------------------------------------------------------------------------
       
 10582 // CCamAppController::SetViewfinderWindowHandle
       
 10583 // ---------------------------------------------------------------------------
       
 10584 //
       
 10585 void CCamAppController::SetViewfinderWindowHandle( RWindowBase* aWindow )
       
 10586     {
       
 10587     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10588 
       
 10589     iCameraController->SetViewfinderWindowHandle( aWindow );
       
 10590     }
       
 10591 
       
 10592 // ---------------------------------------------------------------------------
       
 10593 // CCamAppController::ViewfinderWindowDeleted
       
 10594 // ---------------------------------------------------------------------------
       
 10595 //
       
 10596 void CCamAppController::ViewfinderWindowDeleted( RWindowBase* aWindow )
       
 10597     {
       
 10598     __ASSERT_ALWAYS( iCameraController, CamPanic( ECamPanicInvalidState ) );
       
 10599 
       
 10600     iCameraController->ViewfinderWindowDeleted( aWindow );
       
 10601     }
       
 10602 
       
 10603 
       
 10604 // ---------------------------------------------------------------------------
       
 10605 // CCamAppController::ExistMassStorage()
       
 10606 // ---------------------------------------------------------------------------
       
 10607 //
       
 10608 TBool CCamAppController::ExistMassStorage() const
       
 10609     {
       
 10610     const TUint KMassStorageBits = DriveInfo::EDriveInternal |
       
 10611                                    DriveInfo::EDriveExternallyMountable;    
       
 10612     TInt drive;
       
 10613     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive );
       
 10614     
       
 10615     if ( err != KErrNone )
       
 10616         {
       
 10617         return EFalse;
       
 10618         }
       
 10619     
       
 10620     TUint driveStatus(0);    
       
 10621     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10622                                      drive, 
       
 10623                                      driveStatus );
       
 10624 
       
 10625     TInt usbPersonality;
       
 10626     TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10627     						  KUsbWatcherSelectedPersonality,
       
 10628     						  usbPersonality);
       
 10629     
       
 10630     if ( err != KErrNone )
       
 10631         {
       
 10632         return EFalse;
       
 10633         }
       
 10634         
       
 10635     if ( (driveStatus & KMassStorageBits) == KMassStorageBits &&
       
 10636 		 !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10637     	(  KErrNotFound == ret || // USB watcher is not loaded
       
 10638     	        ( (KErrNone == ret) && (KUsbPersonalityIdMS != usbPersonality) ) ) )
       
 10639         {
       
 10640         return ETrue;
       
 10641         }
       
 10642         
       
 10643     return EFalse;
       
 10644     }
       
 10645 
       
 10646 
       
 10647 // ------------------------------------------------------------------------
       
 10648 // CCamAppController::IsMemoryAvailable()
       
 10649 // ------------------------------------------------------------------------
       
 10650 //
       
 10651 TBool 
       
 10652 CCamAppController::IsMemoryAvailable(const TCamMediaStorage aStorage, TBool aIgnoreUsbPersonality ) const
       
 10653 	{
       
 10654 	TInt currentStorage = aStorage;
       
 10655 	if(aStorage == ECamMediaStorageCurrent)
       
 10656 		{
       
 10657 		TCamCameraMode mode = CurrentMode();
       
 10658 
       
 10659 		if((ECamControllerImage != mode) && (ECamControllerVideo != mode))
       
 10660             {
       
 10661             //This is needed for case where current mode is not yet set.
       
 10662             mode = TargetMode();
       
 10663             }
       
 10664 		
       
 10665 		if(ECamControllerImage == mode)
       
 10666 			{
       
 10667 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10668 								IntegerSettingValue( 
       
 10669 									ECamSettingItemPhotoMediaStorage ) );
       
 10670 			}
       
 10671 		else if(ECamControllerVideo == mode)
       
 10672 			{
       
 10673 			currentStorage = static_cast<TCamMediaStorage>( 
       
 10674 								IntegerSettingValue( 
       
 10675 									ECamSettingItemVideoMediaStorage ) );
       
 10676 			}
       
 10677 		else
       
 10678 			{
       
 10679 			//No impl
       
 10680 			}
       
 10681 		}
       
 10682 	
       
 10683 	TInt usbPersonality;
       
 10684 	TInt ret = RProperty::Get(KPSUidUsbWatcher, 
       
 10685 							  KUsbWatcherSelectedPersonality,
       
 10686 							  usbPersonality);
       
 10687   if ( !aIgnoreUsbPersonality )
       
 10688     {
       
 10689     if ( ( currentStorage != ECamMediaStoragePhone ) && ( KErrNone == ret ) && 
       
 10690          ( KUsbPersonalityIdMS == usbPersonality ) )
       
 10691       {
       
 10692       return EFalse;
       
 10693       }
       
 10694     }
       
 10695 		
       
 10696 	DriveInfo::TDefaultDrives driveInfo = static_cast<DriveInfo::TDefaultDrives>(KErrNotFound);
       
 10697 	switch(currentStorage)
       
 10698 		{
       
 10699 		case ECamMediaStoragePhone:
       
 10700 			driveInfo = DriveInfo::EDefaultPhoneMemory;
       
 10701 			break; 
       
 10702 		case ECamMediaStorageCard:
       
 10703 			driveInfo = DriveInfo::EDefaultRemovableMassStorage;
       
 10704 			break;
       
 10705 		case ECamMediaStorageMassStorage:
       
 10706 			driveInfo = DriveInfo::EDefaultMassStorage;
       
 10707 			break;
       
 10708 		default:
       
 10709 			break;
       
 10710 		}
       
 10711 	
       
 10712 	
       
 10713 	TInt drive;
       
 10714 	TInt err = DriveInfo::GetDefaultDrive( driveInfo, drive );
       
 10715 	if(err)
       
 10716 		{
       
 10717 		return EFalse;
       
 10718 		}
       
 10719     TUint driveStatus(0);    
       
 10720     err = DriveInfo::GetDriveStatus( CCoeEnv::Static()->FsSession(), 
       
 10721                                      drive, 
       
 10722                                      driveStatus );
       
 10723     if(err)
       
 10724     	{
       
 10725     	return EFalse;
       
 10726     	}
       
 10727     
       
 10728     return ( (driveStatus & DriveInfo::EDrivePresent) && 
       
 10729 		   !(driveStatus & DriveInfo::EDriveCorrupt) &&
       
 10730 	       (driveStatus & DriveInfo::EDriveUserVisible) &&
       
 10731 	       !(driveStatus & DriveInfo::EDriveInUse) &&
       
 10732 	       !(driveStatus & DriveInfo::EDriveReadOnly) );
       
 10733 	}
       
 10734  
       
 10735 	
       
 10736 // ---------------------------------------------------------------------------
       
 10737 // CCamAppController::IsDemandKeyRelease()
       
 10738 // ---------------------------------------------------------------------------
       
 10739 //
       
 10740 TBool CCamAppController::IsDemandKeyRelease()
       
 10741     {
       
 10742     return iDemandKeyRelease;
       
 10743     }
       
 10744 
       
 10745 // ---------------------------------------------------------------------------
       
 10746 // CCamAppController::SetDemandKeyRelease()
       
 10747 // ---------------------------------------------------------------------------
       
 10748 //
       
 10749 void CCamAppController::SetDemandKeyRelease( TBool aDemand )
       
 10750     {
       
 10751     iDemandKeyRelease = aDemand;
       
 10752     }
       
 10753 
       
 10754 
       
 10755 // ---------------------------------------------------------------------------
       
 10756 // CCamAppController::IsKeyLockOn()
       
 10757 // ---------------------------------------------------------------------------
       
 10758 //
       
 10759 TBool CCamAppController::IsKeyLockOn()
       
 10760     {
       
 10761     if ( iKeyLockStatusWatcher && iConfigManager && iConfigManager->IsKeyLockWatcherSupported() )
       
 10762         {
       
 10763         TInt iKeyLockStatus = 0;
       
 10764         iKeyLockStatusWatcher->Get( iKeyLockStatus );
       
 10765         if ( iKeyLockStatus == EKeyguardLocked )
       
 10766             {
       
 10767             return ETrue;
       
 10768             }
       
 10769         else
       
 10770             {
       
 10771             return EFalse;
       
 10772             }        
       
 10773         }
       
 10774     return EFalse;
       
 10775     }
       
 10776 
       
 10777 
       
 10778 // ---------------------------------------------------------------------------
       
 10779 // CCamAppController::DriveChangeL
       
 10780 // ---------------------------------------------------------------------------
       
 10781 //
       
 10782 TInt CCamAppController::DriveChangeL( const TCamDriveChangeType aType )
       
 10783   {
       
 10784   PRINT1( _L("Camera => CCamAppController::DriveChangeL aType: %d" ), aType );
       
 10785   CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 10786   appUi->CheckMemoryAvailableForCapturing();
       
 10787   
       
 10788     
       
 10789   TCamCameraMode mode = CurrentMode();
       
 10790   TCamMediaStorage currentStorage;
       
 10791 		
       
 10792   // Photos and videos are saved onto the same media, so no need to 
       
 10793   // differentiate between still/video 
       
 10794   currentStorage = static_cast<TCamMediaStorage>( 
       
 10795           IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ) );
       
 10796     
       
 10797   PRINT1( _L("Camera <> iPreferredStorageLocation is now %d"), 
       
 10798                                                   iPreferredStorageLocation );
       
 10799   PRINT1( _L("Camera <> Update iPreferredStorageLocation to %d"), 
       
 10800                                                             currentStorage );
       
 10801     
       
 10802   iPreferredStorageLocation = currentStorage; 
       
 10803     
       
 10804   if ( ECamMediaStoragePhone == iPreferredStorageLocation )
       
 10805     {
       
 10806     PRINT( _L("Camera <> Phone memory is the preferred storage location. Nothing to be done here. Return KErrNone.") )
       
 10807     PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );
       
 10808     return KErrNone;
       
 10809     }
       
 10810    
       
 10811   if  ( ( !IsMemoryAvailable( ECamMediaStorageCard, EFalse ) || 
       
 10812           !IsMemoryAvailable( ECamMediaStorageMassStorage, EFalse ) ) ||
       
 10813         !IsMemoryAvailable( iPreferredStorageLocation, ETrue ) )
       
 10814     {  
       
 10815     PRINT( _L("Camera <> USB personality is 'Mass storage' or iPreferredStorageLocation (MMC or mass memory) is unavailable") )
       
 10816 
       
 10817     // Stop if recording a video to mass memory or MMC
       
 10818     if ( CurrentVideoOperation() == ECamCapturing ||
       
 10819          CurrentVideoOperation() == ECamPaused )
       
 10820       {
       
 10821       PRINT( _L("Camera <> Video capture in progress...") )
       
 10822         
       
 10823       if ( !IsMemoryAvailable( iInitialVideoStorageLocation ) ) 
       
 10824         {
       
 10825         PRINT( _L("Camera <> ...Stop  video recording.") )
       
 10826         iCaptureStoppedForUsb = ETrue;	
       
 10827         StopVideoRecording();
       
 10828         }
       
 10829       else
       
 10830         {
       
 10831         PRINT( _L("Camera <> ...Phone memory in use. No need to stop.") )
       
 10832         }
       
 10833                        
       
 10834       }
       
 10835     // Cancel if pending recording	
       
 10836     else if( iVideoRequested )
       
 10837       {
       
 10838       iVideoRequested = EFalse;
       
 10839       }
       
 10840     
       
 10841     if ( appUi->SelfTimerEnabled() && appUi->AllMemoriesFullOrUnavailable() )
       
 10842       {
       
 10843       PRINT( _L("Camera <> All storages full or unavailable. Cancel selftimer.") )
       
 10844       appUi->HandleCommandL( ECamCmdSelfTimerCancel );
       
 10845       }
       
 10846     
       
 10847     if ( SequenceCaptureInProgress() )
       
 10848       {
       
 10849       PRINT( _L("Camera <> Sequence capture in progress. -> Stop and skip postcapture.") )
       
 10850             
       
 10851       iCaptureStoppedForUsb = ETrue;
       
 10852       SoftStopBurstL( ETrue );
       
 10853       }
       
 10854     // If in the middle of init sequence or saving a file, set the dismount
       
 10855     // pending so that the AllowDismount call will be made later
       
 10856     if( IsFlagOn( iBusyFlags, EBusySequence ) || iSaving )
       
 10857       {
       
 10858       PRINT( _L("Camera <> CCamAppController::DriveChangeL sequence or saving ongoing" ) );  		
       
 10859       
       
 10860       iDismountPending = ETrue;    
       
 10861       // Mass memory may be the forced storage location. Then it's necessary 
       
 10862       // to switch to (forced) phone memory
       
 10863       TRAP_IGNORE( ForceUsePhoneMemoryL( ETrue ) );
       
 10864       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount pending" ) );  	
       
 10865 
       
 10866       }
       
 10867     else
       
 10868       {    	           
       
 10869       // Mass memory may be the forced storage location. Then it's necessary 
       
 10870       // to switch to (forced) phone memory
       
 10871       TRAP_IGNORE( ForceUsePhoneMemoryL( ETrue ) );
       
 10872       PRINT( _L("Camera <= CCamAppController::DriveChangeL dismount ok" ) );  	    
       
 10873 
       
 10874       }        
       
 10875     }
       
 10876   else if ( IsMemoryAvailable( iPreferredStorageLocation, ETrue ) &&
       
 10877             ( ECamMediaStorageCard == iPreferredStorageLocation ||
       
 10878               ECamMediaStorageMassStorage  == iPreferredStorageLocation ) )
       
 10879     {
       
 10880     PRINT( _L("Camera <> iPreferredStorageLocation (MMC or mass memory) is now available.") )
       
 10881  
       
 10882     // if phone memory forced, then revert back to user selected location
       
 10883     if ( iForceUseOfPhoneMemory )
       
 10884       {
       
 10885       PRINT( _L("Camera <> Phone memory is forced, switch back to user selected storage location.") )
       
 10886       TRAP_IGNORE( ForceUsePhoneMemoryL( EFalse ) );
       
 10887       }
       
 10888     else
       
 10889       {
       
 10890       PRINT( _L("Camera <> !IsPhoneMemoryForced() -> No action.") )
       
 10891       }
       
 10892     }
       
 10893   
       
 10894   if( IntegerSettingValue(ECamSettingItemRemovePhoneMemoryUsage) )
       
 10895         {
       
 10896         if( aType == EDriveMount &&
       
 10897             !appUi->IsRecoverableStatus() )
       
 10898               {
       
 10899               SwitchToStandbyL( KErrNone );
       
 10900               }
       
 10901           else if( aType == EDriveDismount &&
       
 10902                   appUi->IsRecoverableStatus() )
       
 10903               {
       
 10904               TInt mmcInserted = 0;
       
 10905               TInt usbPersonality = 0;
       
 10906               User::LeaveIfError( RProperty::Get( KPSUidUikon, KUikMMCInserted, mmcInserted ) );
       
 10907               User::LeaveIfError(RProperty::Get(KPSUidUsbWatcher, 
       
 10908                                             KUsbWatcherSelectedPersonality,
       
 10909                                             usbPersonality) );
       
 10910               if( !IsMemoryAvailable(ECamMediaStorageMassStorage) &&
       
 10911                    !IsMemoryAvailable(ECamMediaStorageCard) )
       
 10912                   {
       
 10913                   if( KUsbPersonalityIdMS == usbPersonality )
       
 10914                       {
       
 10915                       SwitchToStandbyL( ECamErrMassStorageMode );
       
 10916                       }
       
 10917                   else if ( !mmcInserted )
       
 10918                       {
       
 10919                       SwitchToStandbyL( ECamErrMemoryCardNotInserted );
       
 10920                       }
       
 10921                   }
       
 10922               }
       
 10923           else if ( aType == EDriveUSBMassStorageModeOn &&
       
 10924                   appUi->IsRecoverableStatus() )
       
 10925               {
       
 10926               SwitchToStandbyL(ECamErrMassStorageMode);
       
 10927               }
       
 10928           else if ( aType == EDriveUSBMassStorageModeOff &&
       
 10929                   !appUi->IsRecoverableStatus() )
       
 10930               {
       
 10931               SwitchToStandbyL( KErrNone );
       
 10932               }
       
 10933         }
       
 10934     
       
 10935   if( appUi->CurrentViewState() == ECamViewStatePostCapture  )
       
 10936       {
       
 10937       if( aType == EDriveDismount && !IsMemoryAvailable( currentStorage, EFalse ))
       
 10938           {
       
 10939           TVwsViewId activeView;
       
 10940           if ( appUi->GetActiveViewId( activeView ) == KErrNone )
       
 10941               {
       
 10942               if( ECamViewIdStillPostCapture == activeView.iViewUid.iUid  ||
       
 10943                   ECamViewIdVideoPostCapture == activeView.iViewUid.iUid   )
       
 10944                   {
       
 10945                   CCamPostCaptureViewBase* view = 
       
 10946                           static_cast<CCamPostCaptureViewBase*>( appUi->View( activeView.iViewUid ) );
       
 10947                   if( view )
       
 10948                       {
       
 10949                       view->HandleCommandL( EAknSoftkeyBack );
       
 10950                       }
       
 10951                   }
       
 10952               }
       
 10953           }
       
 10954       }
       
 10955 
       
 10956   PRINT( _L("Camera <= CCamAppController::DriveChangeL" ) );  	
       
 10957   return KErrNone;
       
 10958   }
       
 10959 
       
 10960 // ---------------------------------------------------------------------------
       
 10961 // CCamAppController::CurrentStorage
       
 10962 // ---------------------------------------------------------------------------
       
 10963 //    
       
 10964 TCamMediaStorage CCamAppController::CurrentStorage()   
       
 10965     {
       
 10966     return iCurrentStorage;
       
 10967     }	 
       
 10968 
       
 10969 // ---------------------------------------------------------------------------
       
 10970 // CCamAppController::IsAfNeeded
       
 10971 // ---------------------------------------------------------------------------
       
 10972 // 
       
 10973 TBool CCamAppController::IsAfNeeded()
       
 10974     {
       
 10975     return iAfNeeded;
       
 10976     }
       
 10977 
       
 10978 // ---------------------------------------------------------------------------
       
 10979 // CCamAppController::SetAfNeeded
       
 10980 // ---------------------------------------------------------------------------
       
 10981 // 
       
 10982 void CCamAppController::SetAfNeeded( TBool aAfNeeded )
       
 10983     {
       
 10984     iAfNeeded = aAfNeeded;
       
 10985     }
       
 10986 	
       
 10987 // ---------------------------------------------------------------------------
       
 10988 // CCamAppController::IsCaptureStoppedForUsb
       
 10989 // ---------------------------------------------------------------------------
       
 10990 //    
       
 10991 TBool CCamAppController::IsCaptureStoppedForUsb()
       
 10992     {
       
 10993     return iCaptureStoppedForUsb;	
       
 10994     }
       
 10995 
       
 10996 // ---------------------------------------------------------------------------
       
 10997 // CCamAppController::SetCaptureStoppedForUsb
       
 10998 // ---------------------------------------------------------------------------
       
 10999 //    
       
 11000 void CCamAppController::SetCaptureStoppedForUsb( TBool aCaptureStoppedForUsb )
       
 11001     {
       
 11002     iCaptureStoppedForUsb = aCaptureStoppedForUsb;	
       
 11003     }
       
 11004     
       
 11005 // ---------------------------------------------------------------------------
       
 11006 // CCamAppController::CancelDismountMonitoring
       
 11007 // ---------------------------------------------------------------------------
       
 11008 //    
       
 11009 void CCamAppController::CancelDismountMonitoring()
       
 11010     {
       
 11011     if( iDriveChangeNotifier )
       
 11012         {
       
 11013         iDriveChangeNotifier->CancelMonitoring();		
       
 11014         }
       
 11015     }
       
 11016 
       
 11017 
       
 11018 // ---------------------------------------------------------------------------
       
 11019 // CCamAppController::StartDismountMonitoring
       
 11020 // ---------------------------------------------------------------------------
       
 11021 //    
       
 11022 void CCamAppController::StartDismountMonitoring()
       
 11023     {
       
 11024     if( iDriveChangeNotifier )
       
 11025         {
       
 11026         iDriveChangeNotifier->StartMonitoring();		
       
 11027         }
       
 11028     }
       
 11029 
       
 11030 // ---------------------------------------------------------------------------
       
 11031 // CCamAppController::DeepSleepTimeout
       
 11032 // ---------------------------------------------------------------------------
       
 11033 //
       
 11034 TInt CCamAppController::DeepSleepTimeout( TAny* aPtr )
       
 11035     {
       
 11036     static_cast<CCamAppController*>( aPtr )->DoDeepSleepTimeout();
       
 11037     return EFalse; // dummy
       
 11038     }
       
 11039 
       
 11040 // ---------------------------------------------------------------------------
       
 11041 // CCamAppController::DoDeepSleepTimeout
       
 11042 // ---------------------------------------------------------------------------
       
 11043 //
       
 11044 void CCamAppController::DoDeepSleepTimeout()
       
 11045     {
       
 11046     PRINT( _L("Camera => CCamAppController::DoDeepSleepTimeout") );
       
 11047 
       
 11048     ReleaseCamera();
       
 11049     iDeepSleepTimerExpired = ETrue;
       
 11050     iDeepSleepTimer->Cancel();
       
 11051 
       
 11052     PRINT( _L("Camera <= CCamAppController::DoDeepSleepTimeout") );
       
 11053     }
       
 11054 
       
 11055 // ---------------------------------------------------------------------------
       
 11056 // CCamAppController::DeepSleepTimerStart
       
 11057 // ---------------------------------------------------------------------------
       
 11058 //
       
 11059 void CCamAppController::DeepSleepTimerStart()
       
 11060     {
       
 11061     PRINT( _L("Camera : DeepSleepTimerStart") );
       
 11062     iDeepSleepTimerExpired = EFalse;
       
 11063     if ( iDeepSleepTimer && !iDeepSleepTimer->IsActive() )
       
 11064         {
       
 11065         iDeepSleepTimer->StartTimer();
       
 11066         }
       
 11067     }
       
 11068 
       
 11069 // ---------------------------------------------------------------------------
       
 11070 // CCamAppController::DeepSleepTimerCancel
       
 11071 // ---------------------------------------------------------------------------
       
 11072 //
       
 11073 void CCamAppController::DeepSleepTimerCancel()
       
 11074     {
       
 11075     PRINT( _L("Camera : DeepSleepTimerCancel") );
       
 11076     if ( iDeepSleepTimer )
       
 11077         {
       
 11078         iDeepSleepTimer->Cancel();
       
 11079         }
       
 11080     }
       
 11081 
       
 11082 // ---------------------------------------------------------------------------
       
 11083 // CCamAppController::AllSnapshotsReceived
       
 11084 // ---------------------------------------------------------------------------
       
 11085 //    
       
 11086 TBool CCamAppController::AllSnapshotsReceived()
       
 11087     {
       
 11088     PRINT1( _L("Camera <> AllSnapshotsReceived %d"), iAllSnapshotsReceived );	
       
 11089     return iAllSnapshotsReceived;	
       
 11090     }
       
 11091 
       
 11092 // ---------------------------------------------------------------------------
       
 11093 // CCamAppController::PendingAFRequest
       
 11094 // ---------------------------------------------------------------------------
       
 11095 // 
       
 11096 TInt CCamAppController::PendingAFRequest()
       
 11097     {
       
 11098     return iPendingAFRequest;
       
 11099     }
       
 11100 
       
 11101 
       
 11102 
       
 11103 // CCamAppController::IsTouchScreenSupported
       
 11104 // Return whether the device supports touch screen
       
 11105 // ---------------------------------------------------------------------------
       
 11106 //  
       
 11107 TBool CCamAppController::IsTouchScreenSupported()
       
 11108     {
       
 11109     return AknLayoutUtils::PenEnabled();
       
 11110     }
       
 11111 
       
 11112 // ---------------------------------------------------------------------------
       
 11113 // CCamAppController::IsTouchScreenSupported
       
 11114 // Return whether the device supports direct screen viewfinder
       
 11115 // ---------------------------------------------------------------------------
       
 11116 //  
       
 11117 TBool CCamAppController::IsDirectScreenVFSupported( TBool aPrimaryCamera )
       
 11118     {
       
 11119     // test for integration
       
 11120     return iConfigManager->IsDSAViewFinderSupported( aPrimaryCamera );
       
 11121     }
       
 11122 
       
 11123 // ---------------------------------------------------------------------------
       
 11124 // CCamAppController::UiConfigManagerPtr
       
 11125 // handle  to CameraUiConfigManager
       
 11126 // ---------------------------------------------------------------------------
       
 11127 //  
       
 11128 CCameraUiConfigManager* CCamAppController::UiConfigManagerPtr()
       
 11129     {
       
 11130 	__ASSERT_DEBUG(iConfigManager, CamPanic(ECamPanicNullPointer));
       
 11131     return iConfigManager;
       
 11132     }
       
 11133 
       
 11134 	
       
 11135 // ---------------------------------------------------------------------------
       
 11136 // CCamAppController::SetCameraOrientationModeL
       
 11137 // 
       
 11138 // ---------------------------------------------------------------------------
       
 11139 //  
       
 11140 void CCamAppController::SetCameraOrientationModeL( TInt aOrientation )
       
 11141     {
       
 11142     iCameraController->SetOrientationModeL( aOrientation );
       
 11143     }
       
 11144     
       
 11145 // ---------------------------------------------------------------------------
       
 11146 // CCamAppController::CompleteCameraConstruction
       
 11147 // 
       
 11148 // ---------------------------------------------------------------------------
       
 11149 //  
       
 11150 void CCamAppController::CompleteCameraConstructionL()
       
 11151     {
       
 11152     PRINT( _L( "Camera => CCamAppController::CompleteCameraConstructionL" ) );    	
       
 11153     iCameraController->CompleteSwitchCameraL();
       
 11154     // start reserve and poweron already here unless embedded mode used
       
 11155     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 11156     if( appUi && !appUi->IsEmbedded() )
       
 11157         {
       
 11158         IssueModeChangeSequenceL( ETrue );
       
 11159         }
       
 11160     PRINT( _L( "Camera <= CCamAppController::CompleteCameraConstructionL" ) );    	    
       
 11161     }
       
 11162 
       
 11163 // ---------------------------------------------------------------------------
       
 11164 // CCamAppController::CurrentImageIndex
       
 11165 // 
       
 11166 // ---------------------------------------------------------------------------
       
 11167 //  
       
 11168 TInt CCamAppController::CurrentImageIndex()
       
 11169     {
       
 11170     return iCurrentImageIndex;
       
 11171     }
       
 11172 // ---------------------------------------------------------------------------
       
 11173 // 
       
 11174 // ---------------------------------------------------------------------------
       
 11175 //
       
 11176 void
       
 11177 CCamAppController::GenerateStartupSequenceL( RCamRequestArray& aSequence )
       
 11178   {
       
 11179   PRINT( _L( "Camera => CCamAppController::GenerateStartupSequenceL" ) );
       
 11180 
       
 11181   //Have to empty autofocusrequest values here because modechange could override
       
 11182   //currently processed autofocus request.
       
 11183   iPendingAFRequest=0;
       
 11184   iCurrentAFRequest=0;
       
 11185   iNoBurstCancel = EFalse;
       
 11186   iKeyUP = EFalse;
       
 11187 
       
 11188   aSequence.Append( ECamRequestReserve );
       
 11189   aSequence.Append( ECamRequestPowerOn );
       
 11190 
       
 11191   // -------------------------------------------------------
       
 11192 #ifdef _DEBUG
       
 11193   PRINT( _L( "Camera <> Generated sequence: " ) );      
       
 11194   for( TInt i = 0; i < aSequence.Count(); i++ )
       
 11195     {
       
 11196     PRINT2( _L( "Camera <> %d) %s" ), i, KCamRequestNames[aSequence[i]] );
       
 11197     }
       
 11198 #endif  
       
 11199   PRINT( _L( "Camera <= CCamAppController::GenerateStartupSequenceL" ) );
       
 11200   }    
       
 11201   
       
 11202 // ---------------------------------------------------------------------------
       
 11203 // CCamAppController::RotateSnapshotL
       
 11204 // Copy and rotate snapshot bitmap before it is used to
       
 11205 // create a thumbnail
       
 11206 // ---------------------------------------------------------------------------
       
 11207 //  
       
 11208 void CCamAppController::RotateSnapshotL()
       
 11209     {
       
 11210     PRINT( _L( "Camera => CCamAppController::RotateSnapshotL" ) );
       
 11211     // empty the array
       
 11212     if( iRotationArray->Count() > 0 )
       
 11213         {
       
 11214         iRotationArray->Reset();
       
 11215         }
       
 11216     if( BurstCaptureArray()->Snapshot( iCurrentImageIndex ) ) 
       
 11217         {
       
 11218     // copy snapshot to preserve the original snapshot bitmap
       
 11219     // first get the handle for the original snapshot bitmap
       
 11220     CFbsBitmap* snapshot = new (ELeave)CFbsBitmap();
       
 11221     CleanupStack::PushL( snapshot );
       
 11222     snapshot->Duplicate( BurstCaptureArray()->Snapshot( iCurrentImageIndex )->Handle() );
       
 11223     //create a new bitmap with the same dimensions as the original snapshot
       
 11224     iRotatedSnapshot = new (ELeave)CFbsBitmap();
       
 11225     iRotatedSnapshot->Create( snapshot->SizeInPixels(), snapshot->DisplayMode() );
       
 11226     TRect tmpRect( TPoint( 0, 0 ), snapshot->SizeInPixels() );
       
 11227     TInt tmpLen = tmpRect.Width() * tmpRect.Height() * 4;
       
 11228     //copy the snapshot data
       
 11229     iRotatedSnapshot->BeginDataAccess();
       
 11230     snapshot->BeginDataAccess();
       
 11231     Mem::Copy( iRotatedSnapshot->DataAddress(), snapshot->DataAddress(), tmpLen );
       
 11232     iRotatedSnapshot->EndDataAccess();
       
 11233     snapshot->EndDataAccess();
       
 11234     // copy the filename 
       
 11235     iRotationArray->SetNextNameL( BurstCaptureArray()->FileName( iCurrentImageIndex ), BurstCaptureArray()->ImageName( iCurrentImageIndex ));
       
 11236     // rotate the copied snapshot 
       
 11237     if ( !iRotatorAo )
       
 11238         {
       
 11239         iRotatorAo = CCamSyncRotatorAo::NewL( *this );
       
 11240         }    
       
 11241     iRotatorAo->RotateL( iRotatedSnapshot, MapCamOrientation2RotationAngle( iCaptureOrientation ) );
       
 11242         
       
 11243     CleanupStack::PopAndDestroy(snapshot);
       
 11244         } 
       
 11245     PRINT( _L( "Camera <= CCamAppController::RotateSnapshotL" ) );    
       
 11246     } 
       
 11247     
       
 11248 // ---------------------------------------------------------------------------
       
 11249 // CCamAppController::RotationCompleteL
       
 11250 // Notification of bitmap rotation complete events
       
 11251 // ---------------------------------------------------------------------------
       
 11252 //  
       
 11253 void CCamAppController::RotationCompleteL( TInt aErr )
       
 11254     {
       
 11255     PRINT1( _L( "Camera => CCamAppController::RotationCompleteL aErr:%d" ), aErr );
       
 11256     // rotation completed, use the rotated bitmap to create a thumbnail    
       
 11257     // in case of error, don't use the snapshot, thumbnail is created from 
       
 11258     // the imagefile instead
       
 11259     if ( !aErr )
       
 11260         {
       
 11261         iRotationArray->ReplaceSnapshot( iRotatedSnapshot, 0 );
       
 11262         }
       
 11263     TRAP_IGNORE( iImageSaveActive->CreateThumbnailsL( *iRotationArray ) );
       
 11264             
       
 11265     delete iRotatedSnapshot; 
       
 11266     iRotatedSnapshot = NULL;
       
 11267     PRINT( _L( "Camera <= CCamAppController::RotationCompleteL" ) );         
       
 11268     }     
       
 11269       
       
 11270 // ---------------------------------------------------------------------------
       
 11271 // CCamAppController::StoreFaceTrackingValue
       
 11272 // Calls CamSettingModel to save user defined FT setting
       
 11273 // ---------------------------------------------------------------------------
       
 11274 //  
       
 11275 void CCamAppController::StoreFaceTrackingValue()
       
 11276    {
       
 11277    iSettingsModel->StoreFaceTrackingValue();	
       
 11278    }
       
 11279 
       
 11280 // ---------------------------------------------------------------------------
       
 11281 // CCamAppController::SetVideoInitNeeded
       
 11282 // Sets the value defining the need for CAE video init and prepare
       
 11283 // ---------------------------------------------------------------------------
       
 11284 //  
       
 11285 void CCamAppController::SetVideoInitNeeded( TBool aVideoInitNeeded )
       
 11286     {
       
 11287     iVideoInitNeeded = aVideoInitNeeded;  
       
 11288     }
       
 11289 
       
 11290 // ---------------------------------------------------------------------------
       
 11291 // CCamAppController::VideoInitNeeded
       
 11292 // Returns the value defining the need for CAE video init and prepare
       
 11293 // ---------------------------------------------------------------------------
       
 11294 //  
       
 11295 TBool CCamAppController::VideoInitNeeded()
       
 11296     {
       
 11297     return iVideoInitNeeded;  
       
 11298     }
       
 11299     
       
 11300 // ---------------------------------------------------------------------------
       
 11301 // StoreUserSceneSettingsL
       
 11302 // Stores the UserScene settings
       
 11303 // ---------------------------------------------------------------------------
       
 11304 //  
       
 11305 void CCamAppController::StoreUserSceneSettingsL()
       
 11306     {
       
 11307     iSettingsModel->StoreUserSceneSettingsL();	    
       
 11308     }      
       
 11309 
       
 11310 // ---------------------------------------------------------------------------
       
 11311 // HandleVideoQualitySettingChangeL
       
 11312 // ---------------------------------------------------------------------------
       
 11313 //
       
 11314 void 
       
 11315 CCamAppController::HandleVideoQualitySettingChangeL() 
       
 11316   {
       
 11317   PRINT( _L("Camera => CCamAppController::HandleVideoQualitySettingChangeL") );
       
 11318   if( IsViewFinding() && !Busy() ) 
       
 11319     {
       
 11320     PRINT( _L("Camera <> CCamAppController - viewfinder on, stop vf / re-prepare / start vf..") );
       
 11321     TRAPD( status, 
       
 11322       {
       
 11323       // Generate the request sequence and issue to Camera Controller.
       
 11324       RCamRequestArray sequence;
       
 11325       CleanupClosePushL( sequence );
       
 11326 
       
 11327       // Asynchronously init video. No need to reconstruct video names etc.
       
 11328       sequence.Append( ECamRequestVfStop );
       
 11329       sequence.Append( ECamRequestSsRelease );
       
 11330       
       
 11331       SetVideoInitNeeded( ETrue );
       
 11332 
       
 11333       sequence.Append( ECamRequestVideoRelease );
       
 11334       sequence.Append( ECamRequestVideoInit );
       
 11335 
       
 11336       sequence.Append( ECamRequestSsStart );
       
 11337       sequence.Append( ECamRequestVfStart );
       
 11338 
       
 11339       // Set busy flags to indicate sequence in progress and execute the seq 
       
 11340       SetFlags( iBusyFlags, EBusySequence );
       
 11341       TCleanupItem clearBusy( ClearSequenceBusyFlag, &iBusyFlags );
       
 11342       CleanupStack::PushL( clearBusy );
       
 11343       iCameraController->RequestSequenceL( sequence );
       
 11344       CleanupStack::Pop();
       
 11345    
       
 11346       iCaptureModeTransitionInProgress = ETrue;
       
 11347       CleanupStack::PopAndDestroy(); // sequence.Close()
       
 11348       });
       
 11349 
       
 11350     if( KErrNone != status )
       
 11351       {
       
 11352       PRINT1( _L("Camera <> CCamAppController::HandleVideoQualitySettingChangeL, error:%d"), status );
       
 11353       SetOperation( ECamStandby, status );
       
 11354       }
       
 11355     }
       
 11356 
       
 11357   PRINT( _L("Camera <= CCamAppController::HandleVideoQualitySettingChangeL") );
       
 11358   }
       
 11359 
       
 11360 // ---------------------------------------------------------------------------
       
 11361 // CCamAppController::ToggleWideScreenQuality
       
 11362 // Toggles between wide-screen (16:9) and VGA (4:3) screen resolutions.
       
 11363 // Applicable only for highest quality settings for 16:9 & 4:3.
       
 11364 // ---------------------------------------------------------------------------
       
 11365 //
       
 11366 TBool CCamAppController::ToggleWideScreenQuality( TBool aWide )
       
 11367     {
       
 11368     TBool qualityChanged = EFalse;
       
 11369     
       
 11370     if ( ECamControllerImage == iInfo.iMode && ECamActiveCameraPrimary == iInfo.iActiveCamera )
       
 11371         {
       
 11372         PRINT( _L("Camera => CCamAppController::ToggleWideScreenQuality - image mode") );
       
 11373         TInt qualityIndex = IntegerSettingValue( ECamSettingItemPhotoQuality );
       
 11374         if ( qualityIndex <= EImageQualityPrint )
       
 11375             {
       
 11376             if ( ( qualityIndex == EImageQualityPrintHigh &&  aWide )  
       
 11377                  || ( qualityIndex == EImageQualityPrint && !aWide ) )
       
 11378                 {
       
 11379                 qualityIndex = (EImageQualityPrint==qualityIndex) ? EImageQualityPrintHigh 
       
 11380                                                                   : EImageQualityPrint;
       
 11381 
       
 11382                 // Ensure that the setting value is enabled/usable.
       
 11383                 if ( iSettingsModel->SettingValueEnabled( ECamSettingItemPhotoQuality, qualityIndex ) )
       
 11384                     {
       
 11385                     SetIntegerSettingValueL( ECamSettingItemPhotoQuality, qualityIndex );
       
 11386                     qualityChanged = ETrue;
       
 11387                     }
       
 11388                 }
       
 11389             else
       
 11390                 ; // skip
       
 11391             }
       
 11392         PRINT( _L("Camera <= CCamAppController::ToggleWideScreenQuality") );
       
 11393         }
       
 11394     else if ( ECamControllerVideo == iInfo.iMode && ECamActiveCameraPrimary == iInfo.iActiveCamera ) 
       
 11395         {
       
 11396         PRINT( _L("Camera => CCamAppController::ToggleWideScreenQuality - video mode") );        
       
 11397         TInt qualityIndex = IntegerSettingValue( ECamSettingItemVideoQuality );
       
 11398         if ( qualityIndex <= ECamVideoQualityNormalHigh )
       
 11399             {
       
 11400             TVideoQualitySettings videoQuality = iConfiguration->VideoQuality( qualityIndex );
       
 11401             qualityIndex = (ECamVideoQualityNormalHigh==qualityIndex) ? ECamVideoQualityHigh
       
 11402                                                                       : ECamVideoQualityNormalHigh;
       
 11403 
       
 11404             if ( ( videoQuality.iVideoResolution == ECamVideoResolutionVGA &&  aWide ) || 
       
 11405                  ( videoQuality.iVideoResolution == ECamVideoResolutionHD  && !aWide ) )
       
 11406                 {
       
 11407                 // Ensure that the setting value is enabled/usable.
       
 11408                 if ( iSettingsModel->SettingValueEnabled( ECamSettingItemVideoQuality, qualityIndex ) )
       
 11409                     {
       
 11410                     SetIntegerSettingValueL( ECamSettingItemVideoQuality, qualityIndex );
       
 11411                     HandleVideoQualitySettingChangeL();
       
 11412                     qualityChanged = ETrue;
       
 11413                     }
       
 11414                 }
       
 11415             }
       
 11416         PRINT( _L("Camera <= CCamAppController::ToggleWideScreenQuality") );
       
 11417         }
       
 11418     else // avoids LINT warning.
       
 11419         PRINT( _L("Camera =><= CCamAppController::ToggleWideScreenQuality - current quality level NOT high") );
       
 11420 
       
 11421     return qualityChanged;
       
 11422     }
       
 11423 
       
 11424 // ---------------------------------------------------------------------------
       
 11425 // CCamAppController::IsSaveStarted
       
 11426 // 
       
 11427 // ---------------------------------------------------------------------------
       
 11428 //
       
 11429 TBool CCamAppController::IsSaveStarted()
       
 11430     {
       
 11431     return iSaveStarted;    
       
 11432     }
       
 11433 
       
 11434 // ---------------------------------------------------------------------------
       
 11435 // CCamAppController::SwitchToStandby
       
 11436 // 
       
 11437 // ---------------------------------------------------------------------------
       
 11438 //
       
 11439 void CCamAppController::SwitchToStandbyL( TInt aStatus )
       
 11440     {
       
 11441     PRINT( _L("Camera => CCamAppController::SwitchToStandbyL") );
       
 11442     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 11443     __ASSERT_DEBUG( appUi, CamPanic( ECamPanicNullPointer ) );
       
 11444     if( !appUi->ChangeStandbyStatusL(aStatus) )
       
 11445         {
       
 11446         SetOperation( ECamStandby, aStatus );
       
 11447         iIdleTimer->Cancel();
       
 11448 
       
 11449         // Use backlight timer also with bitmap vf
       
 11450         if( iBacklightTimer )
       
 11451             {
       
 11452             if( ECamTriActive == iCameraController->ViewfinderState() )
       
 11453                 {
       
 11454                 User::ResetInactivityTime();
       
 11455                 }
       
 11456             iBacklightTimer->Cancel();
       
 11457             }
       
 11458         }
       
 11459     switch( aStatus )
       
 11460         {
       
 11461         case ECamErrMassStorageMode:
       
 11462         case ECamErrMemoryCardNotInserted:
       
 11463             {
       
 11464             iCurrentStorage = static_cast<TCamMediaStorage>(IntegerSettingValueUnfiltered( ECamSettingItemPhotoMediaStorage ));
       
 11465             }
       
 11466             break;
       
 11467         default:
       
 11468             {
       
 11469             SetIntegerSettingValueL( ECamSettingItemPhotoMediaStorage, iCurrentStorage );
       
 11470             SetIntegerSettingValueL( ECamSettingItemVideoMediaStorage, iCurrentStorage );
       
 11471             }
       
 11472             break;
       
 11473         }
       
 11474     PRINT( _L("Camera <= CCamAppController::SwitchToStandbyL") );
       
 11475     }	
       
 11476 
       
 11477 // ---------------------------------------------------------------------------
       
 11478 // CCamAppController::IssueModeChangeSequenceSucceeded
       
 11479 // 
       
 11480 // ---------------------------------------------------------------------------
       
 11481 //
       
 11482 TBool CCamAppController::IssueModeChangeSequenceSucceeded()
       
 11483     {
       
 11484     return iIssueModeChangeSequenceSucceeded;
       
 11485     }
       
 11486 	
       
 11487 // ---------------------------------------------------------------------------
       
 11488 // CCamAppController::EmbeddedStartupSequence
       
 11489 // 
       
 11490 // ---------------------------------------------------------------------------
       
 11491 //
       
 11492 void CCamAppController::EmbeddedStartupSequence()
       
 11493     {
       
 11494     // If startup sequence fails at this point, it will be tried again later
       
 11495     TRAP_IGNORE( IssueModeChangeSequenceL( ETrue ) );
       
 11496     }
       
 11497 
       
 11498 // ---------------------------------------------------------------------------
       
 11499 // CCamAppController::SnapshotRotationComplete
       
 11500 // 
       
 11501 // ---------------------------------------------------------------------------
       
 11502 //
       
 11503 void CCamAppController::SnapshotRotationComplete()
       
 11504     {
       
 11505     PRINT( _L( "Camera => CCamAppController::SnapshotRotationComplete" ) );          
       
 11506     // If snapshot rotation takes too long, it might not be drawn
       
 11507     // unless specifically requested
       
 11508     if( iSnapshotRedrawNeeded )
       
 11509         {
       
 11510         iSnapshotRedrawNeeded = EFalse;
       
 11511         NotifyControllerObservers( ECamEventSnapshotRotated );    
       
 11512         }
       
 11513     PRINT( _L( "Camera <= CCamAppController::SnapshotRotationComplete" ) );    
       
 11514     }
       
 11515 
       
 11516 // ---------------------------------------------------------------------------
       
 11517 // CCamAppController::HandleTvAccessoryConnectedL
       
 11518 // 
       
 11519 // ---------------------------------------------------------------------------
       
 11520 //
       
 11521 void CCamAppController::HandleTvAccessoryConnectedL()
       
 11522     {
       
 11523     PRINT(_L("Camera => CCamAppController::HandleTvAccessoryConnectedL "));
       
 11524     if( IntegerSettingValue( ECamSettingItemStopRecordingInHdmiMode) 
       
 11525             && IsHdmiCableConnected() )
       
 11526         {
       
 11527         if( ECamCapturing == iInfo.iOperation || 
       
 11528             ECamPaused == iInfo.iOperation )
       
 11529             {
       
 11530             CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 11531             iHdmiCableConnectedDuringRecording = ETrue;
       
 11532             TVwsViewId activeView;
       
 11533             if ( appUi->GetActiveViewId( activeView ) == KErrNone )
       
 11534               {
       
 11535               if( ECamViewIdVideoPreCapture == activeView.iViewUid.iUid  )
       
 11536                   {
       
 11537                   CCamVideoPreCaptureView* view = static_cast<CCamVideoPreCaptureView*>( appUi->View( activeView.iViewUid ) );
       
 11538                   view->HandleCommandL( ECamCmdStop );
       
 11539                   }
       
 11540               }
       
 11541             }
       
 11542         }
       
 11543     PRINT(_L("Camera <= CCamAppController::HandleTvAccessoryConnectedL "));
       
 11544     }
       
 11545 
       
 11546 // ---------------------------------------------------------------------------
       
 11547 // CCamAppController::HandleTvAccessoryConnectedL
       
 11548 // 
       
 11549 // ---------------------------------------------------------------------------
       
 11550 //
       
 11551 void CCamAppController::HandleTvAccessoryDisconnectedL()
       
 11552     {
       
 11553     
       
 11554     }
       
 11555 
       
 11556 // ---------------------------------------------------------------------------
       
 11557 // CCamAppController::IsHdmiCableConnected
       
 11558 // 
       
 11559 // ---------------------------------------------------------------------------
       
 11560 //
       
 11561 TBool CCamAppController::IsHdmiCableConnected()
       
 11562     {
       
 11563     return iTvAccessoryMonitor->IsHdmiCableConnected();
       
 11564     }
       
 11565 //  End of File  
       
 11566 
       
 11567 
       
 11568 // ---------------------------------------------------------------------------
       
 11569 // CCamAppController::RemainingVideoRecordingTime
       
 11570 // 
       
 11571 // ---------------------------------------------------------------------------
       
 11572 //
       
 11573 TTimeIntervalMicroSeconds CCamAppController::RemainingVideoRecordingTime()
       
 11574     {
       
 11575     return iCameraController->RemainingVideoRecordingTime();
       
 11576     }
       
 11577 
       
 11578 // ---------------------------------------------------------------------------
       
 11579 // CCamAppController::HandlePostHdmiConnectDuringRecordingEventL
       
 11580 // 
       
 11581 // ---------------------------------------------------------------------------
       
 11582 //
       
 11583 void CCamAppController::HandlePostHdmiConnectDuringRecordingEventL()
       
 11584     {
       
 11585     if( iHdmiCableConnectedDuringRecording == TBool(ETrue) )
       
 11586         {
       
 11587         iHdmiCableConnectedDuringRecording = EFalse;
       
 11588         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 11589         appUi->HandleHdmiEventL( ECamHdmiCableConnectedDuringRecording );
       
 11590         }  
       
 11591     }
       
 11592 
       
 11593 
       
 11594 // ---------------------------------------------------------------------------
       
 11595 // CCamAppController::SetPendingHdmiEvent
       
 11596 // 
       
 11597 // ---------------------------------------------------------------------------
       
 11598 //
       
 11599 void CCamAppController::SetPendingHdmiEvent( TCamHdmiEvent aPendingHdmiEvent )
       
 11600     {
       
 11601     iPendingHdmiEvent = aPendingHdmiEvent;
       
 11602     }
       
 11603 
       
 11604 
       
 11605 // ---------------------------------------------------------------------------
       
 11606 // CCamAppController::HandlePendingHdmiEvent
       
 11607 // 
       
 11608 // ---------------------------------------------------------------------------
       
 11609 //
       
 11610 void CCamAppController::HandlePendingHdmiEvent()
       
 11611     {
       
 11612     if( iPendingHdmiEvent != ECamHdmiNoEvent )
       
 11613         {
       
 11614         CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );
       
 11615         appUi->HandleHdmiEventL( iPendingHdmiEvent );
       
 11616         iPendingHdmiEvent = ECamHdmiNoEvent;
       
 11617         }
       
 11618     }
       
 11619 
       
 11620     
       
 11621 // ---------------------------------------------------------------------------
       
 11622 // CCamAppController::HandleSecondaryCameraExit
       
 11623 // 
       
 11624 // Place here any extra things that need to be done when
       
 11625 // exiting camera app. in secondary camera mode
       
 11626 // ---------------------------------------------------------------------------
       
 11627 //
       
 11628 void CCamAppController::HandleSecondaryCameraExitL()
       
 11629     {
       
 11630     PRINT( _L( "Camera => CCamAppController::HandleSecondaryCameraExit" ) );          
       
 11631     
       
 11632     // Scene mode and face tracking issues --->
       
 11633     CCamAppUi* appUi = static_cast<CCamAppUi*>( CEikonEnv::Static()->AppUi() );  
       
 11634     // Do a switch to primary camera.
       
 11635     appUi->HandleCommandL( ECamCmdSwitchCamera );
       
 11636     // Set correct settings for primary camera.
       
 11637     SetDynamicSettingsToDefaults();
       
 11638     // Check if "User" scene mode should be on.
       
 11639     iSettingsModel->SetUserSceneDefault();
       
 11640     // PhotoSceneHasChangedL() needs to be called to 
       
 11641     // get also face tracking to the correct state.
       
 11642     iSettingsModel->PhotoSceneHasChangedL( IntegerSettingValue( ECamSettingItemDynamicPhotoScene ) );
       
 11643     // StoreFaceTrackingValue() does nothing in 2ndary camera mode.
       
 11644     // (Because scene mode is forced to Auto while in 2ndary camera.)
       
 11645     // -> Always save face tracking state when exiting from 2ndary cam.
       
 11646     SetIntegerSettingValueL( ECamSettingItemFaceTracking, iSettingsModel->GetPreviousFaceTrack() );   
       
 11647     // <--- Scene mode and face tracking issues
       
 11648     
       
 11649     PRINT( _L( "Camera <= CCamAppController::HandleSecondaryCameraExit" ) );    
       
 11650     }    
       
 11651 
       
 11652 // ---------------------------------------------------------------------------
       
 11653 // CCamAppController::SceneModeForcedBySecondaryCamera
       
 11654 // 
       
 11655 // ---------------------------------------------------------------------------
       
 11656 //    
       
 11657 TBool CCamAppController::SceneModeForcedBySecondaryCamera()
       
 11658     {
       
 11659     return iSceneModeForcedBySecondaryCamera;
       
 11660     }
       
 11661 
       
 11662 // ---------------------------------------------------------------------------
       
 11663 // CCamAppController::SetTouchCapture
       
 11664 // 
       
 11665 // ---------------------------------------------------------------------------
       
 11666 //
       
 11667 void CCamAppController::SetTouchCapture( TBool aTouchCapture )
       
 11668     {
       
 11669     iTouchCapture = aTouchCapture;
       
 11670     }
       
 11671 //  End of File  
       
 11672