camerauis/cameraapp/generic/src/CamViewBase.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Base class for all views used in the Camera application*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "CamAppUi.h"
       
    21 #include "CamViewBase.h"
       
    22 #include "CamContainerBase.h"
       
    23 #include "CamStandbyContainer.h"
       
    24 #include "CamUtility.h"
       
    25 #include "CamPanic.h"
       
    26 #include <eikmenub.h>
       
    27  
       
    28 
       
    29 #include <StringLoader.h>
       
    30 #include <AknQueryDialog.h>
       
    31 #include <aknnotewrappers.h>
       
    32 
       
    33 #include <cameraapp.rsg>
       
    34 #include <vgacamsettings.rsg>
       
    35 #include <akntoolbar.h>
       
    36 
       
    37 #include "CamUtility.h"
       
    38 #include <AknWaitDialog.h>
       
    39 #include "CamWaitDialog.h"
       
    40 #include "CamCommandHandlerAo.h"
       
    41 #include "CameraUiConfigManager.h"
       
    42 
       
    43 
       
    44 static const TRect KCamCbaHiddenRect = TRect(640,640,640,640);
       
    45 
       
    46 
       
    47 // ========================= MEMBER FUNCTIONS ================================
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CCamViewBase destructor
       
    52 // 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CCamViewBase::~CCamViewBase()
       
    56   {
       
    57   PRINT( _L("Camera => ~CCamViewBase" ))  
       
    58   if ( iStandbyContainer )
       
    59     {
       
    60     CAknViewAppUi* appUi = AppUi();
       
    61     
       
    62     if ( appUi )
       
    63       {
       
    64       appUi->RemoveFromStack( iStandbyContainer );
       
    65       }
       
    66         
       
    67     delete iStandbyContainer;
       
    68     iStandbyContainer = NULL;
       
    69     }
       
    70 
       
    71   delete iContainer;
       
    72   iContainer = NULL;
       
    73   
       
    74   delete iCommandHandlerAo;
       
    75   iCommandHandlerAo = NULL;
       
    76   
       
    77   PRINT( _L("Camera <= ~CCamViewBase" ))  
       
    78   }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCamViewBase::HandleFocusLossL
       
    82 // Handle focus loss
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CCamViewBase::HandleFocusLossL()
       
    86     {
       
    87     // intentionally doing nothing
       
    88     }
       
    89     
       
    90 // ---------------------------------------------------------------------------
       
    91 // HandleAppEvent <<virtual>>
       
    92 //
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void 
       
    96 CCamViewBase::HandleAppEvent( const TCamAppEvent& aEvent )
       
    97   {
       
    98   PRINT1( _L("Camera => CCamViewBase::HandleAppEvent, event:%d"), aEvent );
       
    99   if( iContainer )
       
   100     {
       
   101     iContainer->HandleAppEvent( aEvent );
       
   102     }
       
   103   PRINT( _L("Camera <= CCamViewBase::HandleAppEvent") );
       
   104   }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCamViewBase::PrepareForModeChange
       
   109 // Prepare for mode change
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CCamViewBase::PrepareForModeChange()   
       
   113     {
       
   114     // intentionally doing nothing
       
   115     }
       
   116   
       
   117 // -----------------------------------------------------------------------------
       
   118 // CCamViewBase::HandleCommandL
       
   119 // Handle commands
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CCamViewBase::HandleCommandL( TInt aCommand )
       
   123     {
       
   124     PRINT( _L("Camera => CCamViewBase::HandleCommandL"))
       
   125     switch(aCommand)
       
   126         {
       
   127         case ECamCmdInternalExit:
       
   128             {   
       
   129             TInt standbyError = KErrNone;        
       
   130             if ( iStandbyModeActive && iStandbyContainer )
       
   131                 {
       
   132                 standbyError = iStandbyContainer->GetStandbyError();
       
   133                 ExitStandbyModeL();
       
   134                 }
       
   135 
       
   136             if ( standbyError != KErrNone )
       
   137                 {
       
   138                 AppUi()->HandleCommandL( EEikCmdExit );
       
   139                 }
       
   140             else
       
   141                 {
       
   142                 AppUi()->HandleCommandL( aCommand );
       
   143                 }
       
   144 
       
   145             // dismiss menu - if open
       
   146             StopDisplayingMenuBar();
       
   147             }
       
   148             break;
       
   149             
       
   150         case ECamCmdRedrawScreen:
       
   151             {
       
   152             if( iContainer )
       
   153             	{
       
   154             	iContainer->DrawDeferred();
       
   155             	}           
       
   156             }
       
   157             break;
       
   158             
       
   159         default:
       
   160             {
       
   161             AppUi()->HandleCommandL( aCommand );
       
   162             break;
       
   163             }
       
   164         }
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CCamViewBase::HandleForegroundEventL
       
   169 // Handle foreground event
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CCamViewBase::HandleForegroundEventL( TBool /*aForeground*/ )
       
   173     {
       
   174     PRINT( _L("CCamViewBase::HandleForegroundEventL") );
       
   175     CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>( AppUi() );  
       
   176     iEmbedded = appUi->IsEmbedded();
       
   177     PRINT1( _L("CCamViewBase::HandleForegroundEventL embedded %d"), iEmbedded );    
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CCamViewBase::DoActivateL
       
   182 // Activate this view
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void 
       
   186 CCamViewBase::DoActivateL( const TVwsViewId& /*aPostvViewId*/, 
       
   187                                  TUid        aCustomMessageId, 
       
   188                            const TDesC8&     /*aCustomMessage*/ )
       
   189   {
       
   190   PRINT( _L("Camera => CCamViewBase::DoActivateL"));    
       
   191 
       
   192   CCamContainerBase::DestroyActivePalette();     
       
   193 
       
   194 
       
   195   if(ECamViewMessageDeactivateFirst == aCustomMessageId.iUid)
       
   196     {
       
   197     PRINT( _L("CCamViewBase::DoActivateL call deactivate"));    
       
   198     TBool wasCameraUser = IsCameraUser();    
       
   199 
       
   200     DoDeactivate();
       
   201     // since we still use it
       
   202     if( wasCameraUser )
       
   203       {
       
   204       IncrementCameraUsers();
       
   205       }
       
   206     }
       
   207   
       
   208   CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>( AppUi() );  
       
   209   iEmbedded = appUi->IsEmbedded();
       
   210 
       
   211   PRINT1( _L("CCamViewBase::DoActivateL Embedded %d"), iEmbedded);    
       
   212   if ( !iContainer )
       
   213     {
       
   214     CreateContainerL();
       
   215     AppUi()->AddToStackL( *this, iContainer );
       
   216     iContainer->ActivateL();
       
   217     }
       
   218   
       
   219   SetTitlePaneTextL();
       
   220   
       
   221   TInt orientation;
       
   222   TCamPsiKey queryValue = ECamPsiOrientation;
       
   223   CCameraUiConfigManager* configManager = iController.UiConfigManagerPtr(); 
       
   224 
       
   225   if ( configManager && configManager->IsSecondaryCameraSupported() )
       
   226       {
       
   227       if ( appUi->IsSecondCameraEnabled() && !appUi->IsQwerty2ndCamera() ) // if front camera is active         
       
   228           {
       
   229           queryValue = ECamPsiSecondaryCameraOrientation;
       
   230           }
       
   231       else // back camera is active
       
   232           {
       
   233           queryValue = ECamPsiPrimaryCameraOrientation;
       
   234           }
       
   235       }
       
   236     
       
   237   CamUtility::GetPsiInt( queryValue, orientation );
       
   238 
       
   239   AppUi()->SetOrientationL( ( CAknAppUiBase::TAppUiOrientation ) orientation );
       
   240 
       
   241   TCamOrientation camOrientation = appUi->CamOrientation();
       
   242 
       
   243   // if in camcorder mode need to show navi-ctr
       
   244   if( camOrientation == ECamOrientationCamcorder ||  
       
   245       camOrientation == ECamOrientationCamcorderLeft || 
       
   246       camOrientation == ECamOrientationPortrait )
       
   247     {
       
   248 		iContainer->SetupNaviPanesL( CCamContainerBase::ECamPaneCounter );
       
   249 		}
       
   250   PRINT( _L("Camera <= CCamViewBase::DoActivateL"));    
       
   251   }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CCamViewBase::DoDeactivate
       
   255 // Deactivate this view
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CCamViewBase::DoDeactivate()
       
   259   {
       
   260   PRINT( _L("Camera => CCamViewBase::DoDeactivate" ))
       
   261 	// Both standard container and standby container should be deactivated
       
   262     if ( iStandbyContainer ) // implies IsInStandbyMode
       
   263         {
       
   264         AppUi()->RemoveFromStack( iStandbyContainer );
       
   265         delete iStandbyContainer;
       
   266         iStandbyContainer = NULL;
       
   267         SetStandbyModeActive( EFalse );
       
   268         }
       
   269 
       
   270 	if ( iContainer )
       
   271 		{
       
   272   		AppUi()->RemoveFromStack( iContainer );
       
   273     	delete iContainer;
       
   274     	iContainer = NULL;
       
   275     	}
       
   276     	
       
   277 	PRINT( _L("Camera <= CCamViewBase::DoDeactivate" ))
       
   278 	}
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CCamViewBase::CCamViewBase
       
   282 // C++ constructor
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 CCamViewBase::CCamViewBase( CCamAppController& aController )
       
   286     : iController( aController )
       
   287     {
       
   288     }
       
   289     
       
   290 // ---------------------------------------------------------------------------
       
   291 // CCamViewBase::UpdateCbaL
       
   292 // Update softkeys to reflect current state
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CCamViewBase::UpdateCbaL()
       
   296     {
       
   297     }
       
   298     
       
   299 
       
   300 // ----------------------------------------------------
       
   301 // CCamViewBase::BlankSoftKeysL
       
   302 // Blank the softkeys
       
   303 // ----------------------------------------------------
       
   304 //
       
   305 void CCamViewBase::BlankSoftkeysL()
       
   306     {
       
   307     // blank the cba 
       
   308     SetSoftKeysL( R_CAM_SOFTKEYS_BLANK );
       
   309     }
       
   310 
       
   311 
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CCamViewBase::SwitchToStandbyModeL
       
   315 // Switches to standby mode
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CCamViewBase::SwitchToStandbyModeL( TCamAppViewIds aViewId, TInt aError )
       
   319     {
       
   320     PRINT( _L("Camera => CCamViewBase::SwitchToStandbyModeL") );
       
   321     // check if already in standby mode
       
   322     if( iStandbyModeActive )
       
   323     	{
       
   324     	PRINT( _L("Camera <= CCamViewBase::SwitchToStandbyModeL: already in standby") );
       
   325     	return;
       
   326     	}
       
   327 
       
   328     StatusPane()->MakeVisible( ETrue );
       
   329     delete iStandbyContainer;
       
   330     iStandbyContainer = NULL;
       
   331     iStandbyContainer = CCamStandbyContainer::NewL( AppUi()->ClientRect(),
       
   332                                                     *this, iController, aError );
       
   333     // dismiss menu - if open
       
   334     StopDisplayingMenuBar();
       
   335 
       
   336     // save options menu id for reactivation
       
   337     if ( aViewId == ECamViewIdStillPreCapture )
       
   338         {
       
   339         if ( iEmbedded )
       
   340             {
       
   341             iPreviousMenuResourceId = ROID(R_CAM_STILL_EMBEDDED_PRE_CAPTURE_MENUBAR_ID);
       
   342             }
       
   343         else
       
   344             {
       
   345             iPreviousMenuResourceId = ROID(R_CAM_STILL_PRE_CAPTURE_MENUBAR_ID);
       
   346             }
       
   347         }
       
   348     else if ( aViewId == ECamViewIdVideoPreCapture )
       
   349         {
       
   350         if ( iEmbedded )
       
   351             {
       
   352             iPreviousMenuResourceId = ROID(R_CAM_VIDEO_EMBEDDED_PRE_CAPTURE_MENUBAR_ID);
       
   353             }
       
   354         else
       
   355             {
       
   356             iPreviousMenuResourceId = ROID(R_CAM_VIDEO_PRE_CAPTURE_MENUBAR_ID);
       
   357             }
       
   358         }
       
   359     else if ( aViewId == ECamViewIdVideoSettings )
       
   360         {
       
   361         iPreviousMenuResourceId = ROID(R_CAM_SETTINGS_LIST_MENUBAR_ID);
       
   362         }
       
   363     else if ( aViewId == ECamViewIdPhotoSettings )
       
   364         {
       
   365         iPreviousMenuResourceId = ROID(R_CAM_SETTINGS_LIST_MENUBAR_ID);
       
   366         }
       
   367     else
       
   368         {
       
   369         // remove Lint error
       
   370         }
       
   371 
       
   372     // activate standby container and deactivate current container
       
   373     iStandbyContainer->SetMopParent( this );   
       
   374     
       
   375     CCamAppUi* appUi =  static_cast<CCamAppUi*>( AppUi() );
       
   376     appUi->AddToStackL( *this, iStandbyContainer );
       
   377     iStandbyContainer->ActivateL();
       
   378     appUi->RemoveFromStack( iContainer );
       
   379     iContainer->MakeVisible( EFalse );   
       
   380     iStandbyContainer->MakeVisible( ETrue );
       
   381     iStandbyContainer->DrawNow();
       
   382 
       
   383     UnsetCourtesySoftKeysL();
       
   384 
       
   385     // update softkeys
       
   386     if ( !appUi->IsConstructionComplete() )
       
   387     	{
       
   388     	BlankSoftkeysL();
       
   389     	}
       
   390     else if ( appUi->StandbyStatus() == KErrInUse 
       
   391 	 ||  appUi->StandbyStatus() == KErrPermissionDenied )
       
   392         {
       
   393         SetSoftKeysL( R_CAM_SOFTKEYS_OPTIONS_EXIT );	
       
   394         }	
       
   395     else if ( iEmbedded )
       
   396         {
       
   397         SetSoftKeysL( R_CAM_SOFTKEYS_OPTIONS_BACK__CONTINUE );
       
   398         }
       
   399     else
       
   400         {
       
   401         SetSoftKeysL( R_CAM_SOFTKEYS_OPTIONS_EXIT__CONTINUE );
       
   402         }
       
   403 
       
   404     // change options menu
       
   405     CEikMenuBar* menuBar = MenuBar();
       
   406     if ( menuBar )
       
   407         {
       
   408         menuBar->SetMenuTitleResourceId( R_CAM_STANDBY_MENUBAR );
       
   409         }
       
   410 
       
   411 //    if ( iStandbyError != KErrNone )
       
   412     if ( appUi->StandbyStatus() != KErrNone )
       
   413         {
       
   414         // stop idle timer - non recoverable error
       
   415         iController.StopIdleTimer();
       
   416         }
       
   417 
       
   418     SetStandbyModeActive(ETrue);
       
   419 
       
   420     // Release the camera hardware
       
   421     iController.ReleaseCamera();
       
   422     
       
   423 
       
   424     // cancel self timer mode if active
       
   425     if ( appUi->SelfTimerEnabled() )
       
   426         {
       
   427         appUi->SelfTimerEnableL( ECamSelfTimerDisabled );
       
   428         }
       
   429   	PRINT( _L("Camera <= CCamViewBase::SwitchToStandbyModeL") );
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------------------------
       
   433 // CCamViewBase::ExitStandbyModeL
       
   434 // Exits standby mode
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CCamViewBase::ExitStandbyModeL()
       
   438     {
       
   439     PRINT( _L("Camera => CCamViewBase::ExitStandbyModeL") );    
       
   440     if ( !iStandbyModeActive )
       
   441         {
       
   442         return;
       
   443         }
       
   444 
       
   445     // delete standby container and reactivate previous container
       
   446     TRAPD( err, AppUi()->AddToStackL( *this, iContainer ) )
       
   447     iStandbyContainer->MakeVisible( EFalse );
       
   448     AppUi()->RemoveFromStack( iStandbyContainer );
       
   449     delete iStandbyContainer;
       
   450     iStandbyContainer = NULL;
       
   451     User::LeaveIfError( err );
       
   452 
       
   453     CCamAppUi* appUi = static_cast<CCamAppUi*>( AppUi() );
       
   454 
       
   455 
       
   456     iContainer->MakeVisible( ETrue );   
       
   457     SetStandbyModeActive( EFalse );
       
   458     
       
   459     if ( appUi->IsSecondCameraEnabled() && !appUi->IsQwerty2ndCamera() ) 
       
   460         {
       
   461         StatusPane()->MakeVisible( ETrue );
       
   462         }
       
   463     else
       
   464         {
       
   465         StatusPane()->MakeVisible( EFalse );
       
   466         }
       
   467 
       
   468     CCameraUiConfigManager* configManager = iController.UiConfigManagerPtr();
       
   469     if ( !( configManager && configManager->IsUIOrientationOverrideSupported() ) ) 
       
   470         {
       
   471         appUi->RaisePreCaptureCourtesyUI(ETrue);
       
   472         }
       
   473 
       
   474     if ( iPreviousMenuResourceId == ROID(R_CAM_SETTINGS_LIST_MENUBAR_ID)
       
   475             || iPreviousMenuResourceId == ROID(R_CAM_STILL_EMBEDDED_PRE_CAPTURE_MENUBAR_ID)
       
   476             || iPreviousMenuResourceId == ROID(R_CAM_VIDEO_EMBEDDED_PRE_CAPTURE_MENUBAR_ID))
       
   477         {
       
   478         if ( iController.CaptureModeTransitionInProgress() )
       
   479             {
       
   480             SetSoftKeysL( R_AVKON_SOFTKEYS_BACK ); 
       
   481             }
       
   482         else
       
   483             {
       
   484             SetSoftKeysL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
   485             }
       
   486         }
       
   487     else
       
   488         {
       
   489         SetSoftKeysL( R_CAM_SOFTKEYS_OPTIONS_EXIT );
       
   490         }
       
   491 
       
   492     // restore options menu
       
   493     CEikMenuBar* menuBar = MenuBar();
       
   494     if ( menuBar )
       
   495         {
       
   496         menuBar->SetMenuTitleResourceId( iPreviousMenuResourceId );
       
   497         }
       
   498 
       
   499     //SetStandbyModeActive(EFalse);
       
   500     SetTitlePaneTextL();    
       
   501 
       
   502     // restart idle timer
       
   503     iController.StartIdleTimer();
       
   504     PRINT( _L("Camera <= CCamViewBase::ExitStandbyModeL") );    
       
   505     }
       
   506 
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 // ExitAllModesL <<virtual>>
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 void 
       
   513 CCamViewBase::ExitAllModesL()
       
   514   {
       
   515   // Empty default implementation.
       
   516   }
       
   517 
       
   518 
       
   519 // ---------------------------------------------------------------------------
       
   520 // CCamViewBase::GetHelpContext
       
   521 // Called to identify the help context for this view
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 void CCamViewBase::GetHelpContext( TCoeHelpContext& /*aContext*/ ) const
       
   525     {
       
   526     // No context
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // CCamViewBase::QueryRenameL
       
   531 // Switches orientation if required - calls DoQueryRenameL
       
   532 // ---------------------------------------------------------------------------
       
   533 //
       
   534 void CCamViewBase::QueryRenameL( TCamCameraMode aMode )
       
   535     {
       
   536     // Ensure application is in editing orientation
       
   537     TInt error = KErrNone;
       
   538     CCamAppUi* appUi = static_cast<CCamAppUi*>( AppUi() );
       
   539     TInt editingOrientation = CAknAppUiBase::EAppUiOrientationUnspecified;
       
   540 
       
   541     error = CamUtility::GetPsiInt( ECamPsiOrientation, editingOrientation );   
       
   542     
       
   543     if ( !error )
       
   544         {
       
   545         appUi->SwitchOrientationIfRequiredL( editingOrientation );
       
   546         }    
       
   547     // Trap this to make sure the orientation is reverted back to normal        
       
   548     TRAPD( leaveErr, DoQueryRenameL( aMode ) )
       
   549     appUi->SwitchOrientationIfRequiredL( CAknAppUiBase::EAppUiOrientationUnspecified );
       
   550     User::LeaveIfError( leaveErr );    
       
   551     }
       
   552     
       
   553 // ---------------------------------------------------------------------------
       
   554 // CCamViewBase:DoQueryRenameL
       
   555 // Show rename query and rename file.
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CCamViewBase::DoQueryRenameL( TCamCameraMode aMode )
       
   559   {
       
   560   TBool done = EFalse;
       
   561   HBufC* lastFilePath = HBufC::NewLC( iController.CurrentFullFileName().Length() );
       
   562   TBuf<KMaxNameBaseLengthPlusNumbering> filename( iController.CurrentImageName() );
       
   563   
       
   564   // Repeat until successfully renamed or cancelled
       
   565   while ( !done )
       
   566     {
       
   567     // Show rename query
       
   568     if ( ShowRenameQueryL( filename, aMode ) )
       
   569       {
       
   570       // Try to rename file
       
   571       TRAPD( err, done = RenameCurrentFileL( filename, aMode ) );
       
   572       if ( KErrAlreadyExists == err )
       
   573         {
       
   574         // File exists -> show overwrite confirmation query
       
   575         if ( ShowOverwriteConfirmationQueryL( filename ) )
       
   576           {
       
   577           // Yes, overwrite
       
   578           TPtr lastFilePathPtr = lastFilePath->Des();
       
   579           lastFilePathPtr = iController.CurrentFullFileName();
       
   580           TParsePtr parseptr( lastFilePathPtr );
       
   581           TFileName fullpath = parseptr.DriveAndPath();
       
   582           fullpath.Append( filename );
       
   583           fullpath.Append( parseptr.Ext() );
       
   584 
       
   585           // Delete the file that gets overwritten.
       
   586           if ( ECamControllerVideo != aMode )
       
   587             {
       
   588             CamUtility::DeleteStillImageL( fullpath );
       
   589             }
       
   590           else
       
   591             {
       
   592             CamUtility::DeleteVideoL( fullpath );
       
   593             }
       
   594 
       
   595           // Rename
       
   596           RenameCurrentFileL( filename, aMode );
       
   597           done = ETrue;
       
   598           }
       
   599         else  // No, don't overwrite
       
   600           {
       
   601           // Generate a suitable suggestion for an unique name
       
   602           TInt key             = ( ECamControllerVideo == aMode )
       
   603                                  ? ECamSettingItemVideoNumber
       
   604                                  : ECamSettingItemPhotoNumber;         
       
   605           TInt fileNameCounter = iController.IntegerSettingValue( key );
       
   606 
       
   607           TParsePtrC parse( iController.CurrentFullFileName() );
       
   608           TFileName filePath = parse.DriveAndPath();
       
   609           
       
   610           const TUint KMax3Digits = 999;
       
   611 
       
   612           //if  0 < fileNameCounter <= 999, formatted file name like "Photo001", the length of number part ("001") is fixed 3
       
   613           const TUint KFixedNumberLength = 3; 
       
   614         
       
   615           TBool exceedMaxFileNameLength = EFalse;
       
   616           //if  0 < fileNameCounter <= 999, formatted file name like "Photo001"
       
   617           if ( fileNameCounter > 0 && 
       
   618              fileNameCounter <= KMax3Digits && 
       
   619              filename.Length() + KFixedNumberLength > filename.MaxLength() )
       
   620             {
       
   621             exceedMaxFileNameLength = ETrue;
       
   622             }         
       
   623           //if  fileNameCounter > 999, formatted file name like "Photo1234"
       
   624           else if ( fileNameCounter > KMax3Digits )
       
   625             {
       
   626             _LIT( KCamNameFormatFileNameCounter, "%d" );
       
   627             TBuf<KMaxNameBaseLengthPlusNumbering> strFileNameCounter;
       
   628             strFileNameCounter.Format( KCamNameFormatFileNameCounter, fileNameCounter );
       
   629             if ( filename.Length() + strFileNameCounter.Length() > filename.MaxLength() )
       
   630               {
       
   631               exceedMaxFileNameLength = ETrue;
       
   632               }
       
   633             }
       
   634         
       
   635           if ( !exceedMaxFileNameLength )
       
   636             {
       
   637             CamUtility::GetUniqueNameL( filePath, filename, fileNameCounter, parse.Ext() );
       
   638             }
       
   639                     
       
   640 
       
   641           }       
       
   642         }
       
   643       else
       
   644         {
       
   645         // If unknown error
       
   646         User::LeaveIfError( err );
       
   647         }
       
   648       }
       
   649     else
       
   650       {
       
   651       // User cancelled (ShowRenameQueryL() returned false)
       
   652       done = ETrue;
       
   653       }
       
   654     }
       
   655   CleanupStack::PopAndDestroy(); // lastFilePath
       
   656   }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CCamViewBase::ShowOverwriteConfirmationQueryL
       
   660 // Show an overwrite confirmation query. This is used
       
   661 // when trying to overwrite a file using rename.
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 TBool CCamViewBase::ShowOverwriteConfirmationQueryL( 
       
   665     const TDesC& aFilename )
       
   666     {
       
   667     HBufC* prompt =  StringLoader::LoadLC( R_QTN_FLDR_OVERWRITE_QUERY, 
       
   668                                            aFilename, CEikonEnv::Static() );
       
   669 
       
   670     CAknQueryDialog* overwriteQuery = 
       
   671         new ( ELeave ) CAknQueryDialog( *prompt );
       
   672     TBool result = overwriteQuery->ExecuteLD( R_CAM_OVERWRITE_QUERY );
       
   673 
       
   674     CleanupStack::PopAndDestroy(); // prompt
       
   675 
       
   676     return result;
       
   677     }
       
   678 
       
   679 // ---------------------------------------------------------------------------
       
   680 // CCamViewBase::ShowRenameQueryL
       
   681 // Show rename query.
       
   682 // ---------------------------------------------------------------------------
       
   683 //
       
   684 TBool CCamViewBase::ShowRenameQueryL( TDes& aFilename, TCamCameraMode aMode )
       
   685     {
       
   686     TBool done = EFalse;
       
   687     TBool res = ETrue;
       
   688 
       
   689     while ( !done )
       
   690         {
       
   691         // Show data query
       
   692         HBufC* prompt = NULL;
       
   693         if ( ECamControllerVideo == aMode )
       
   694             {
       
   695             prompt = 
       
   696                 StringLoader::LoadLC( R_CAM_QUERY_VIDEO_NAME );
       
   697             }
       
   698         else
       
   699             {
       
   700             prompt = 
       
   701                 StringLoader::LoadLC( R_CAM_QUERY_IMAGE_NAME );
       
   702             }
       
   703 
       
   704         CAknTextQueryDialog* nameQuery = 
       
   705             CAknTextQueryDialog::NewL( aFilename );
       
   706         nameQuery->SetMaxLength( KMaxNameBaseLengthPlusNumbering );   
       
   707         nameQuery->PrepareLC( R_CAM_RENAME_QUERY );
       
   708         nameQuery->SetPromptL( *prompt );
       
   709 
       
   710         TBool dialogRes = ( nameQuery->RunLD() == EAknSoftkeyOk );
       
   711         if ( dialogRes )
       
   712             {
       
   713             if ( !IsNewNameValidL( aFilename ) )
       
   714                 {
       
   715                 // New name is not valid for another reason.
       
   716                 // In practise, the user has attempted to overwrite
       
   717                 // an image already existing in the burst grid.
       
   718 
       
   719                 HBufC* text = StringLoader::LoadLC(
       
   720                     	R_QTN_FLDR_CANT_RENAME_ITEM,
       
   721                     	iController.CurrentImageName() );
       
   722 
       
   723                 CAknNoteWrapper* note = new ( ELeave ) CAknNoteWrapper();
       
   724                 note->ExecuteLD( R_CAM_UNABLE_TO_RENAME, *text );
       
   725 
       
   726                 CleanupStack::PopAndDestroy(); // text
       
   727 
       
   728                 // Don't show dialog again
       
   729                 res = EFalse;
       
   730                 done = ETrue;
       
   731                 }
       
   732             else if ( CamUtility::CheckFileNameValidityL( aFilename ) )
       
   733                 {
       
   734                 // New file name seems ok
       
   735                 res = ETrue;
       
   736                 done = ETrue;
       
   737                 }
       
   738             else
       
   739                 {
       
   740                 // File name is not suitable, ask again
       
   741                 }
       
   742             }
       
   743         else
       
   744             {
       
   745             // User cancelled rename
       
   746             res = EFalse;
       
   747             done = ETrue;
       
   748             }
       
   749 
       
   750         CleanupStack::PopAndDestroy(); // prompt
       
   751         }
       
   752 
       
   753     return res;
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // CCamViewBase::IsNewNameValidL
       
   758 // Check if renaming to the given name is valid.
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 TBool CCamViewBase::IsNewNameValidL( const TDesC& /* aFilename */ )
       
   762     {
       
   763     // This should be overridden in derived classes if needed
       
   764     return ETrue;
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CCamViewBase::RenameCurrentFileL
       
   769 // Renames the current capture array file.
       
   770 // ---------------------------------------------------------------------------
       
   771 //
       
   772 TBool 
       
   773 CCamViewBase::RenameCurrentFileL( const TDesC& aNewName, 
       
   774                                   TCamCameraMode aMode )
       
   775   {
       
   776   return iController.RenameCurrentFileL( aNewName, aMode );
       
   777   }
       
   778 
       
   779 // ---------------------------------------------------------------------------
       
   780 // CCamViewBase::Container
       
   781 // Returns the currently used container in the view.
       
   782 // ---------------------------------------------------------------------------
       
   783 //
       
   784 CCamContainerBase* CCamViewBase::Container()
       
   785     {
       
   786     if ( iStandbyContainer )
       
   787         {
       
   788         return iStandbyContainer;
       
   789         }
       
   790     else
       
   791         {
       
   792         return iContainer;
       
   793         }
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------------------------
       
   797 // CCamViewBase::SetSoftKeysL
       
   798 // Sets the softkeys to the specified Resource ID
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 void CCamViewBase::SetSoftKeysL(TInt aResource)
       
   802 	{
       
   803     CCamAppUi* appUi = static_cast<CCamAppUi*>( AppUi() );	  
       
   804     // If courtesy softkeys are enabled, check whether the UI can be drawn without being explicitly raised
       
   805     // (rare, but possible: e.g. when video recording starts
       
   806     if(aResource == R_CAM_SOFTKEYS_BLANK &&
       
   807        appUi->IsSecondCameraEnabled() &&
       
   808        !appUi->IsQwerty2ndCamera())
       
   809         {
       
   810         aResource = R_CAM_SOFTKEYS_BLANK_SECONDARY;
       
   811         }
       
   812     if ( iCourtesySoftkeys )
       
   813         {
       
   814         if ( appUi )
       
   815             {
       
   816             if (   (IsPreCapture()  && appUi->DrawPreCaptureCourtesyUI())
       
   817                 || (IsPostCapture() && appUi->DrawPostCaptureCourtesyUI()) )
       
   818                 {
       
   819                 // Disable the courtesy softkeys, otherwise nothing will be drawn when the rest of the
       
   820                 // courtesy UI has been turned back on
       
   821                 iCourtesySoftkeys = EFalse;
       
   822 
       
   823                 //when disabling the courtesy softkeys, Cba should be recovered to be visible
       
   824                 Cba()->MakeVisible( ETrue );
       
   825                 }
       
   826             }
       
   827         }
       
   828         
       
   829     if ( iCourtesySoftkeys || !Cba() )
       
   830         {
       
   831         // If the courtesy (blank) softkeys are being shown, make a note of what to change back to.
       
   832         iPreviousCbaResource = aResource;
       
   833         }
       
   834     else if ( iCurrentCbaResource != aResource )
       
   835         {
       
   836         iPreviousCbaResource = iCurrentCbaResource;
       
   837         iCurrentCbaResource = aResource;
       
   838 
       
   839         Cba()->SetCommandSetL( aResource );
       
   840         Cba()->DrawDeferred();
       
   841 
       
   842         }
       
   843 	}
       
   844 
       
   845 
       
   846 // ---------------------------------------------------------------------------
       
   847 // CCamViewBase::SetCourtesySoftKeysL
       
   848 // Blanks the softkeys for the Courtesy UI Off state. 
       
   849 // ---------------------------------------------------------------------------
       
   850 //
       
   851 void CCamViewBase::SetCourtesySoftKeysL()
       
   852     {
       
   853     if ( !iCourtesySoftkeys )
       
   854         {
       
   855         Cba()->MakeVisible( EFalse );
       
   856         iPreviousCbaResource = iCurrentCbaResource;
       
   857         iCourtesySoftkeys = ETrue;
       
   858         }
       
   859     }
       
   860 
       
   861 // ---------------------------------------------------------------------------
       
   862 // CCamViewBase::UnsetCourtesySoftKeysL
       
   863 // Returns the softkeys to their previous state after UI has been turned back on
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 void CCamViewBase::UnsetCourtesySoftKeysL()
       
   867     {
       
   868     if ( iCourtesySoftkeys )
       
   869         {
       
   870         iCourtesySoftkeys = EFalse;
       
   871         SetSoftKeysL(iPreviousCbaResource);
       
   872         Cba()->MakeVisible( ETrue );
       
   873         }
       
   874     }
       
   875 
       
   876 // ---------------------------------------------------------------------------
       
   877 // CCamViewBase::IsPreCapture
       
   878 // Returns whether the view is a precapture view
       
   879 // ---------------------------------------------------------------------------
       
   880 //
       
   881 TBool CCamViewBase::IsPreCapture()
       
   882     {
       
   883     return EFalse;
       
   884     }
       
   885 
       
   886 // ---------------------------------------------------------------------------
       
   887 // CCamViewBase::IsPostCapture
       
   888 // Returns whether the view is a postcapture view
       
   889 // ---------------------------------------------------------------------------
       
   890 //
       
   891 TBool CCamViewBase::IsPostCapture()
       
   892     {
       
   893     return EFalse;
       
   894     }
       
   895 
       
   896 // ---------------------------------------------------------------------------
       
   897 // CCamViewBase::IsBurstPostCapture
       
   898 // Returns whether the view is a burst mode postcapture view
       
   899 // ---------------------------------------------------------------------------
       
   900 //
       
   901 TBool CCamViewBase::IsBurstPostCapture()
       
   902     {
       
   903     return EFalse;
       
   904     }
       
   905 
       
   906     
       
   907 // ---------------------------------------------------------------------------
       
   908 // CCamViewBase::IsInStandbyMode
       
   909 // Returns whether the view is in standby mode
       
   910 // ---------------------------------------------------------------------------
       
   911 //
       
   912 TBool CCamViewBase::IsInStandbyMode()
       
   913     {
       
   914     return iStandbyModeActive;
       
   915     }
       
   916 
       
   917 
       
   918 // ---------------------------------------------------------------------------
       
   919 // CCamViewBase::SetStandbyModeActive
       
   920 // Sets the iStandbyModeActive flag
       
   921 // ---------------------------------------------------------------------------
       
   922 //
       
   923 void CCamViewBase::SetStandbyModeActive(TBool aActive)
       
   924     {
       
   925     // This should be the only place iStandbyModeActive is set!
       
   926     // We need to inform the AppUi
       
   927     iStandbyModeActive = aActive;
       
   928      if( iController.IsAppUiAvailable() )
       
   929      {
       
   930     CCamAppUiBase* appUi = static_cast<CCamAppUiBase*>( AppUi() );
       
   931     
       
   932     if ( appUi)
       
   933         {
       
   934         if ( aActive )
       
   935             {
       
   936             appUi->SetPreCaptureMode(ECamPreCapStandby);
       
   937             }
       
   938         else
       
   939             {
       
   940             appUi->SetPreCaptureMode(ECamPreCapViewfinder);
       
   941             }        
       
   942         }
       
   943         }
       
   944     }
       
   945 
       
   946 
       
   947 // ---------------------------------------------------------------------------
       
   948 // CCamViewBase::IncrementCameraUsers
       
   949 //
       
   950 // ---------------------------------------------------------------------------
       
   951 //
       
   952 void 
       
   953 CCamViewBase::IncrementCameraUsers()
       
   954     {
       
   955     if( !iIncEngineCount ) 
       
   956         {
       
   957         PRINT( _L("Camera == CCamViewBase::IncrementCameraUsers - incrementing") );
       
   958         iIncEngineCount = ETrue;
       
   959         iController.IncCameraUsers();
       
   960         }
       
   961     else
       
   962         {
       
   963         PRINT( _L("Camera == CCamViewBase::IncrementCameraUsers - already incremented, skipping") );
       
   964         }
       
   965     }
       
   966         
       
   967 
       
   968 // ---------------------------------------------------------------------------
       
   969 // CCamViewBase::DecrementCameraUsers
       
   970 //
       
   971 // ---------------------------------------------------------------------------
       
   972 //
       
   973 void 
       
   974 CCamViewBase::DecrementCameraUsers()
       
   975     {
       
   976     if( iIncEngineCount ) 
       
   977         {
       
   978         PRINT( _L("Camera == CCamViewBase::DecrementCameraUsers - decrementing") );
       
   979         iIncEngineCount = EFalse;
       
   980         iController.DecCameraUsers();
       
   981         }
       
   982     else
       
   983         {
       
   984         PRINT( _L("Camera == CCamViewBase::DecrementCameraUsers - not using camera, skipped") );
       
   985         }
       
   986     }
       
   987 
       
   988 
       
   989 // ---------------------------------------------------------------------------
       
   990 // CCamViewBase::IsCameraUser
       
   991 //
       
   992 // ---------------------------------------------------------------------------
       
   993 //
       
   994 TBool 
       
   995 CCamViewBase::IsCameraUser() const
       
   996     {
       
   997     return iIncEngineCount;
       
   998     }
       
   999 
       
  1000 
       
  1001 
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // CCamViewBase::RedrawAPArea
       
  1004 // -----------------------------------------------------------------------------
       
  1005 void CCamViewBase::RedrawAPArea(const TRect& aArea)
       
  1006     {
       
  1007     if ( iContainer )
       
  1008         {
       
  1009         iContainer->Redraw(aArea);
       
  1010         }
       
  1011     }
       
  1012 
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CCamViewBase::ViewCba
       
  1016 // -----------------------------------------------------------------------------
       
  1017 CEikButtonGroupContainer* CCamViewBase::ViewCba()
       
  1018     {
       
  1019     return Cba();
       
  1020     }
       
  1021 
       
  1022 // -----------------------------------------------------------------------------
       
  1023 // CCamViewBase::UpdateToolbarIconsL
       
  1024 // 
       
  1025 void CCamViewBase::UpdateToolbarIconsL()
       
  1026     {
       
  1027     
       
  1028     }
       
  1029 // -----------------------------------------------------------------------------
       
  1030 // CCamViewBase::HandleCommandAoL
       
  1031 // -----------------------------------------------------------------------------    
       
  1032     
       
  1033 void CCamViewBase::HandleCommandAoL( TInt aCommand )
       
  1034     {
       
  1035     if ( !iCommandHandlerAo )
       
  1036         {
       
  1037         iCommandHandlerAo = CCamCommandHandlerAo::NewL( this );
       
  1038         }
       
  1039     iCommandHandlerAo->HandleCommandL( aCommand );
       
  1040     }    
       
  1041 
       
  1042 //  End of File