voicerecorder/RecViewSrc/CVRRecViewModel.cpp
branchRCL_3
changeset 20 072a5fa0c63b
parent 19 2f5c9ee7098c
child 21 c6bafb5162d8
equal deleted inserted replaced
19:2f5c9ee7098c 20:072a5fa0c63b
     1 /*
       
     2 * Copyright (c) 2002 - 2006 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: 
       
    15 *     This class is the data model and state machine of the Recorder View.
       
    16 *     The state machine is defined by a VR_STATEMACHINE resource structure.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <bldvariant.hrh>
       
    24 #include <e32cmn.h>
       
    25 #include <ctsydomainpskeys.h>
       
    26 #include <UsbWatcherInternalPSKeys.h>
       
    27 #include <usbpersonalityids.h>
       
    28 #include <barsread.h>
       
    29 #include <eikenv.h>
       
    30 #include <eikappui.h>
       
    31 #include <avkon.rsg>
       
    32 #include <StringLoader.h>
       
    33 #include <bautils.h>
       
    34 #include <avkon.hrh>		// Key definitions
       
    35 #include <AknGlobalNote.h>
       
    36 #include <sendui.h>
       
    37 #include <AknLayoutDef.h>
       
    38 #include <AknUtils.h>
       
    39 #include <featmgr.h>
       
    40 #include <data_caging_path_literals.hrh>
       
    41 #include <CMessageData.h>
       
    42 
       
    43 #include <featmgr.h>	// Feature manager
       
    44 #include <SendUiConsts.h>          // Disable e-mail  
       
    45 #include "MessagingDomainCRKeys.h" // Disable e-mail variation flag
       
    46 
       
    47 #include <centralrepository.h> // link against centralrepository.lib
       
    48 #ifdef RD_MULTIPLE_DRIVE
       
    49 #include <driveinfo.h>
       
    50 #endif
       
    51 #include "VoiceRecorderInternalCRKeys.h"
       
    52 
       
    53 #include <voicerecorder.rsg>
       
    54 #include "CVRMemo.h"
       
    55 #include "TVRState.h"
       
    56 #include "CVRMdaRecorder.h"
       
    57 #include "VRConsts.h"
       
    58 #include "CVRSystemEventHandler.h"
       
    59 #include "CVRMediaRemovalMonitor.h"
       
    60 #include "VRUtils.h"
       
    61 #include "CVRRecViewModel.h"
       
    62 #include <csxhelp/vorec.hlp.hrh>
       
    63 
       
    64 #include "VRUSBStateHanlder.h"
       
    65 
       
    66 
       
    67 // CONSTANTS
       
    68 const TInt KAllowInCallRecording( 1 );
       
    69 
       
    70 // Shown if maximum recording time is not known
       
    71 _LIT( KVRBeforeFirstEstimateLabel, "--:--:--" );
       
    72 // MMS/High text is inserted here
       
    73 _LIT( placeForQuality, "%U" );
       
    74 
       
    75 
       
    76 // ================= MEMBER FUNCTIONS ========================================
       
    77 // ---------------------------------------------------------------------------
       
    78 // CVRRecViewModel::CVRRecViewModel
       
    79 // 
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CVRRecViewModel::CVRRecViewModel()
       
    83 	: iStateArray( 2 ),
       
    84 	iLabelSets( 2 ),
       
    85 	iPreviousCallState( EPSCTsyCallStateNone ),
       
    86 	iCanHandleCommands( ETrue ),
       
    87 	iCBAEnabled( ETrue ),
       
    88 	iIsDriveReady( ETrue )
       
    89 	{
       
    90 	}
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CVRRecViewModel::~CVRRecViewModel
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CVRRecViewModel::~CVRRecViewModel()
       
    99 	{
       
   100 	// It might be possible to make this method leaving and put it
       
   101 	// somewhere else than destructor
       
   102 	SaveVolumeSettings();
       
   103 	iLabelSets.ResetAndDestroy();
       
   104 	iStateArray.Reset();
       
   105 
       
   106 	delete[] iLabelLayoutLinks;
       
   107 	delete iMemo;
       
   108 	delete iRecorder;
       
   109 	if ( iGlobalNote && iIsNoteLaunched )
       
   110 		{
       
   111 		// nothing much to do but ignore.
       
   112 		TRAP_IGNORE( iGlobalNote->CancelNoteL( iNoteId ) );
       
   113 		}
       
   114 
       
   115 	delete iGlobalNote;
       
   116 	
       
   117 	if (iCurrentCallHandler) 
       
   118 		{
       
   119 		delete iCurrentCallHandler;
       
   120 		}
       
   121 	delete iCurrentMMCEjectHandler;
       
   122 	
       
   123 	}
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CVRRecViewModel::ConstructFromResourceL
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CVRRecViewModel::ConstructFromResourceL( TResourceReader& aReader )
       
   132 	{
       
   133 
       
   134 	TRAP_IGNORE( iCurrentCallHandler = CVRSystemEventHandler::NewL() );
       
   135 	iCurrentCallHandler->Listen( KPSUidCtsyCallInformation, KCTsyCallState, 
       
   136 								 this );
       
   137 	//listen MMC eject
       
   138 	TInt driveRemovableMassStorage = VRUtils::GetRemovableMassStorageL();
       
   139 	iCurrentMMCEjectHandler = CVRMediaRemovalMonitor::NewL(driveRemovableMassStorage, CEikonEnv::Static()->FsSession(), this);
       
   140 
       
   141 	if ( FeatureManager::FeatureSupported( KFeatureIdKeypadNoVoiceKey ) &&
       
   142 		FeatureManager::FeatureSupported( 
       
   143 						KFeatureIdApplicationControllableAudioRouting ) )
       
   144 		{
       
   145 		ReadDefaultSpeakerL();
       
   146 		}
       
   147 	else
       
   148 		{
       
   149 		iIhfState = ETrue;
       
   150 		}
       
   151 
       
   152 	LoadVolumeSettingsL();
       
   153    // Connecting and initialization:
       
   154     CRepository* myRepSession = CRepository::NewLC( KCRUidVoiceRecorder );
       
   155 
       
   156     // Get the values from the repository
       
   157     User::LeaveIfError( myRepSession->Get( KVRDefaultAudioFormat, 
       
   158     									   iVRAudioFormat ) );
       
   159     									   
       
   160     User::LeaveIfError( myRepSession->Get( KVRAllowInCallRecording, 
       
   161     									   iVRAllowInCallRecording ) );
       
   162     CleanupStack::PopAndDestroy( myRepSession ); 
       
   163 
       
   164 	iGlobalNote = CAknGlobalNote::NewL();
       
   165 
       
   166 	iMemo = new( ELeave ) CVRMemo;
       
   167 	iMemo->ConstructL( iVRAudioFormat );
       
   168 
       
   169 	TInt numLabelSets( aReader.ReadInt16() );
       
   170 	TInt i;
       
   171 
       
   172 	for ( i = 0; i < numLabelSets; i++ )
       
   173 		{
       
   174 		CDesCArray* labelSet;
       
   175 		TInt numLabels( aReader.ReadInt16() );
       
   176 
       
   177 		if ( numLabels > 0 )
       
   178 			{
       
   179 			// TResourceReader re-reads the length, have to rewind
       
   180 			aReader.Rewind( sizeof( TInt16 ) );
       
   181 			labelSet = aReader.ReadDesCArrayL();
       
   182 			}
       
   183 		else
       
   184 			{
       
   185 			// create an empty array "by hand",
       
   186 			// TResourceReader is not able to do this
       
   187 			labelSet = new( ELeave ) CDesCArrayFlat( 1 );
       
   188 			}
       
   189 
       
   190 		CleanupStack::PushL( labelSet );
       
   191 		iLabelSets.AppendL( labelSet );
       
   192 		CleanupStack::Pop( labelSet);
       
   193 		}
       
   194 
       
   195 	TInt linkCount( aReader.ReadInt16() );
       
   196 	iLabelLayoutLinks = new( ELeave ) TVRLabelLayoutLink[ linkCount ];
       
   197 	for ( i = 0; i < linkCount; i++ )
       
   198 		{
       
   199 		iLabelLayoutLinks[ i ].ReadFromResource( aReader );
       
   200 		}
       
   201 
       
   202 	TInt numUiStates( aReader.ReadInt16() );
       
   203 
       
   204 	TVRState uistate;
       
   205 	for ( i = 0; i < numUiStates; i++ )
       
   206 		{
       
   207 		uistate.ReadFromResource( aReader );
       
   208 		uistate.iId =  i;
       
   209 		iStateArray.AppendL( uistate );
       
   210 		}
       
   211 
       
   212 	iState = &iStateArray.At( 0 );
       
   213 
       
   214 	TInt numContexts( aReader.ReadInt16() );
       
   215 	for ( i = 0; i < numContexts; i++ )
       
   216 		{
       
   217 		TInt id( aReader.ReadInt8() );
       
   218 		TVRContext* context = &iContexts[ id ];
       
   219 		context->iValid = ETrue;
       
   220 		context->iInitialTransition.iCommandId = aReader.ReadUint8();
       
   221 		context->iInitialTransition.iNewState = aReader.ReadUint8();
       
   222 		context->iInitialTransition.iFunctionId = aReader.ReadUint8();
       
   223 		context->iInitialTransition.iValid = ETrue;
       
   224 
       
   225 
       
   226 		TInt numStates( aReader.ReadInt16() );
       
   227 		for ( TInt j = 0; j < numStates; j++ )
       
   228 			{
       
   229 			TInt id( aReader.ReadInt8() );
       
   230 			TVRContext::TState* state = &context->iStates[ id ];
       
   231 			state->iValid = ETrue;
       
   232 			TInt numTransitions( aReader.ReadInt16() );
       
   233 			__ASSERT_DEBUG( numTransitions <= KVRMaxTransitions,
       
   234 						User::Panic( KVRPanic, EPanicTooManyTransitions ) );
       
   235 
       
   236 			for ( TInt k = 0; k < numTransitions; k++ )
       
   237 				{
       
   238 				TVRContext::TTransition* trans = &state->iTransitions[ k ];
       
   239 				trans->iCommandId = aReader.ReadUint8();
       
   240 				trans->iNewState = aReader.ReadUint8();
       
   241 				trans->iFunctionId = aReader.ReadUint8();
       
   242 				trans->iValid = ETrue;
       
   243 				}
       
   244 			}
       
   245 		}
       
   246 
       
   247 	StringLoader::Load( iDateUsualWithZero, R_QTN_DATE_USUAL_WITH_ZERO );
       
   248 	StringLoader::Load( iTimeUsualWithZero, R_QTN_TIME_USUAL_WITH_ZERO );
       
   249 	StringLoader::Load( iTimeDuratLong,	R_QTN_TIME_DURAT_LONG );	
       
   250 	StringLoader::Load( iTimeDuratMinSecWithZero,
       
   251 										R_QTN_TIME_DURAT_MIN_SEC_WITH_ZERO );
       
   252 										
       
   253 										
       
   254 	
       
   255 	}
       
   256 
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CVRRecViewModel::ProcessKeyEventL
       
   260 // 
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 TBool CVRRecViewModel::ProcessKeyEventL( const TKeyEvent& aKeyEvent,
       
   264 										 const TEventCode aType )
       
   265 	{
       
   266 	TBool retval( EFalse );
       
   267 	if ( aType != EEventKey )
       
   268 		{
       
   269 		return retval;
       
   270 		}
       
   271 
       
   272 	switch ( aKeyEvent.iCode )
       
   273 		{
       
   274 		case EKeyPhoneEnd:
       
   275 			{
       
   276 			TInt currentState( iCurrentCallHandler->StateL(KPSUidCtsyCallInformation, KCTsyCallState) );
       
   277         										
       
   278 			if ( ( currentState != EPSCTsyCallStateNone ) )
       
   279 				{
       
   280 				HandleCommandL( ECmdDisconnectCall );
       
   281 				retval = EKeyWasNotConsumed;
       
   282 				}
       
   283 			else
       
   284 				{
       
   285 				// Voice recorder wasn't here =), retval stays EFalse
       
   286 				iIsEndKey = ETrue;	
       
   287 				
       
   288 				// Exit if app is not fully initialized
       
   289 				if ( !iContextEntered )
       
   290 					{
       
   291 					CEikonEnv::Static()->EikAppUi()->
       
   292 											HandleCommandL( EEikCmdExit );
       
   293 					}
       
   294 				}
       
   295 			break;
       
   296 			}
       
   297 		case EKeyBackspace:
       
   298 			{
       
   299 			HandleCommandL( ECmdDelete );
       
   300 			retval = ETrue;
       
   301 			break;
       
   302 			}
       
   303 		case EKeyYes:
       
   304 			{
       
   305 			if( aKeyEvent.iRepeats > 0 )
       
   306 				{
       
   307 				if( VisualStateId() == EStateRecording ||
       
   308 						VisualStateId() == EStatePlaying )
       
   309 					{
       
   310 					HandleCommandL( ECmdPause );
       
   311 					}
       
   312 				}
       
   313 			break;
       
   314 			}
       
   315 		case EKeySide:
       
   316             {
       
   317             retval = ETrue;
       
   318             
       
   319             if ( aKeyEvent.iRepeats )
       
   320                 {
       
   321                 switch ( iState->iId )
       
   322                     {
       
   323                     case EStateIdle:
       
   324                         {
       
   325                         HandleCommandL( ECmdPlay );
       
   326                         break;
       
   327                         }
       
   328                     case EStateRecording:
       
   329                     case EStateRecordEmbedded:
       
   330                     case EStateRecordingPaused:
       
   331                     case EStatePlaying:
       
   332                     case EStatePlayingPaused:
       
   333                         {
       
   334                         HandleCommandL( ECmdStop );
       
   335                         break;
       
   336                         }
       
   337                     case EStateDeleted:
       
   338                     default:
       
   339                         {
       
   340                         retval = EFalse;
       
   341                         break;
       
   342                         }
       
   343                     }
       
   344                 }
       
   345             else
       
   346                 {
       
   347                 switch ( iState->iId )
       
   348                     {
       
   349                     case EStateIdle:
       
   350                     case EStateDeleted:
       
   351                     case EStateRecordingPaused:
       
   352                         {
       
   353                         HandleCommandL( ECmdRecord );
       
   354                         break;
       
   355                         }
       
   356                     case EStateRecording:
       
   357                     case EStateRecordEmbedded:
       
   358                     case EStatePlaying:
       
   359                         {
       
   360                         HandleCommandL( ECmdPause );
       
   361                         break;
       
   362                         }
       
   363                     case EStatePlayingPaused:
       
   364                         {
       
   365                         HandleCommandL( ECmdPlay );
       
   366                         break;
       
   367                         }
       
   368                     default:
       
   369                         {
       
   370                         retval = EFalse;
       
   371                         break;
       
   372                         }
       
   373                     }
       
   374                 }
       
   375             break;
       
   376             }
       
   377 		default:
       
   378 			{
       
   379 			break;
       
   380 			}
       
   381 		}
       
   382 	return retval;
       
   383 	}
       
   384 
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // CVRRecViewModel::HandleCommandL
       
   388 // 
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void CVRRecViewModel::HandleCommandL( TInt aCommandId )
       
   392 	{
       
   393 	// This command must be acceptable all times.
       
   394 	if ( aCommandId == ECmdCancelNote )
       
   395 		{
       
   396 		if ( iIsNoteLaunched )
       
   397 			{
       
   398 			// nothing much to do but ignore.
       
   399 			TRAP_IGNORE( iGlobalNote->CancelNoteL( iNoteId ) );
       
   400 			}
       
   401 		return;
       
   402 		}
       
   403 
       
   404 	if ( !CanAcceptCommands() )
       
   405 		{
       
   406 		return;
       
   407 		}
       
   408 
       
   409 	if ( !CanHandleCommands() )
       
   410 		{
       
   411 		return;
       
   412 		}
       
   413 	if ( EStateRecording == iState->iId && ECmdRecord == aCommandId ||
       
   414 			EStateRecording == iState->iId && ECmdRename == aCommandId )
       
   415 		{
       
   416 		return;
       
   417 		}
       
   418 	
       
   419 	switch ( aCommandId )
       
   420 		{
       
   421 		case ECmdHelp:
       
   422 			{
       
   423 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   424 			break;
       
   425 			}	
       
   426 		case EEikCmdExit:
       
   427 			{
       
   428 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( EAknSoftkeyExit);
       
   429 			break;
       
   430 			}
       
   431 		
       
   432 		case EAknSoftkeyExit:
       
   433 			{
       
   434 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   435 			break;
       
   436 			}
       
   437 		case ECmdSendVia:
       
   438 			{
       
   439 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( aCommandId );
       
   440 			break;
       
   441 			}
       
   442 		case ECmdSaveAttachment:
       
   443 			{
       
   444 			__ASSERT_DEBUG( iRecorder, User::Panic( KVRPanic, KErrNotFound ) );
       
   445 			iRecorder->DetachMemo();
       
   446 			// Save permanently but do not remove the original
       
   447 
       
   448 			HBufC* label = StringLoader::LoadLC( R_VR_SAVE_WAITNOTE_LABEL );
       
   449 
       
   450 			iIsNoteLaunched = ETrue;
       
   451 			iMemo->SavePermanentlyL( iGlobalNote, iNoteId, *label, ETrue );
       
   452 
       
   453 			if ( iStateInfoObserver )
       
   454 				{
       
   455 				iStateInfoObserver->Update();
       
   456 				}
       
   457 			iRecorder->AttachToMemoL( iMemo );
       
   458 
       
   459 			// Remove the waitnote
       
   460 			iGlobalNote->CancelNoteL( iNoteId );
       
   461 			iIsNoteLaunched = EFalse;
       
   462 
       
   463 			CleanupStack::PopAndDestroy( label );
       
   464 			break;
       
   465 			}
       
   466 		// FLOWTHROUGH
       
   467 		// in case of end key, different command must be given to state
       
   468 		// machine - recview gives ECmdAutoStopInterrupted
       
   469 		case ECmdAutoStopInterrupted:
       
   470 			{
       
   471 			if ( iIsEndKey )
       
   472 				{
       
   473 				aCommandId = ECmdEndKey;
       
   474 				iIsEndKey = EFalse;
       
   475 				}
       
   476 			}
       
   477 		// Other commands are given to the state machine
       
   478 		default:
       
   479 			{
       
   480 			TVRContext::TTransition transition;
       
   481 			GetTransition( transition, aCommandId );
       
   482 			TBool functionOK( ETrue );
       
   483 			TRAPD( err, functionOK = 
       
   484 								CallFunctionByIdL( transition.iFunctionId ) );
       
   485 			
       
   486 			if ( err != KErrNone )
       
   487 				{
       
   488 				// This is done to enable button events
       
   489 				iCanHandleCommands = ETrue;
       
   490 				}
       
   491 				
       
   492 			// We may have detached memo and we must reattach
       
   493 			if ( err == KErrInUse )
       
   494 				{
       
   495 				__ASSERT_DEBUG( iRecorder, 
       
   496 								User::Panic( KVRPanic, KErrNotFound ) );
       
   497 				iRecorder->AttachToMemoL( iMemo );
       
   498 				}
       
   499 
       
   500 			if ( err == KErrNotReady && iIsNoteLaunched && iGlobalNote )
       
   501 				{
       
   502 				// nothing much to do but ignore.
       
   503 				TRAP_IGNORE( iGlobalNote->CancelNoteL( iNoteId ) );
       
   504 				}
       
   505 
       
   506 			// If the disk gets full while saving, the next state is deleted
       
   507 			if ( err == KErrDiskFull || err == KErrArgument )
       
   508 				{
       
   509 				if ( iContext == EContextRecordNewNormal ||
       
   510 					 iContext == EContextNormal ||
       
   511 					 iContext == EContextEmptyNormal )
       
   512 					{
       
   513 					ChangeState( EStateDeleted, ETrue );
       
   514 					}
       
   515 				else
       
   516 					{
       
   517 					// In record new embedded context the UI is left in
       
   518 					// idle state, so the memo must be attached
       
   519 					// (EFunctionOK detaches it)
       
   520 					__ASSERT_DEBUG( iRecorder, 
       
   521 									User::Panic( KVRPanic, KErrNotFound ) );
       
   522 					if(!dynamic_cast<CVRMdaRecorder*>(iRecorder)->IsAttachedToMemo())
       
   523 						{
       
   524 					    iRecorder->AttachToMemoL( iMemo );	
       
   525 						}
       
   526 					}
       
   527 
       
   528 				if ( err == KErrDiskFull )
       
   529 					{
       
   530 					// Maybe an error note should be shown
       
   531 					return;
       
   532 					}
       
   533 
       
   534 				// Propagate to the error handler to show a note.
       
   535 				User::Leave( err );
       
   536 				}
       
   537 			else
       
   538 				{
       
   539 				// The LeaveIfError must be here because CallFunctionByIdL
       
   540 				// might have called Exit() (leaving with -1002) and the
       
   541 				// framework might be half-dead leading to access violation,
       
   542 				// if the UI state is changed
       
   543 				User::LeaveIfError( err );
       
   544 				if ( functionOK )
       
   545 					{
       
   546 					// If the in-call recording disabling feature is active,
       
   547 					// then the state of the UI will have to reflect that
       
   548 					TUint newState(transition.iNewState);
       
   549 
       
   550 					if ( iVRAllowInCallRecording != KAllowInCallRecording )
       
   551 						{
       
   552 						TInt currentState( iCurrentCallHandler->StateL(	KPSUidCtsyCallInformation, KCTsyCallState ) );
       
   553 												
       
   554 						if ( currentState != EPSCTsyCallStateNone )
       
   555 							{
       
   556 							currentState = iCurrentCallHandler->StateL(
       
   557 												KPSUidCtsyCallInformation, KCTsyCallType );
       
   558 
       
   559 							switch ( currentState )
       
   560 								{
       
   561 								case EPSCTsyCallTypeCSVoice:
       
   562 								case EPSCTsyCallTypeHSCSD:
       
   563 								case EPSCTsyCallTypeH324Multimedia:
       
   564 								case EPSCTsyCallTypeVoIP:
       
   565 									{
       
   566 									newState = EStateDisableButtons;										
       
   567 									break;
       
   568 									}
       
   569 								default:
       
   570 									{
       
   571 									break;										
       
   572 									}
       
   573 								}
       
   574 														
       
   575 							}
       
   576 						}
       
   577 
       
   578 					// Function didn't want to cancel the state change
       
   579 					ChangeState( newState );
       
   580 					}
       
   581 				}
       
   582 
       
   583 			break;
       
   584 			}
       
   585 		}
       
   586 	}
       
   587 
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // CVRRecViewModel::GetTransition
       
   591 // 
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 void CVRRecViewModel::GetTransition( TVRContext::TTransition& aTransition,
       
   595 									 TUint aCommandId ) const
       
   596 	{
       
   597 	__ASSERT_DEBUG( iContexts[ iContext ].iValid, User::Panic( KVRPanic,
       
   598 					EPanicInvalidContext ) );
       
   599 	__ASSERT_DEBUG( iContexts[ iContext ].iStates[ iState->iId ].iValid,
       
   600 					User::Panic( KVRPanic, EPanicInvalidState ) );
       
   601 
       
   602 	const TVRContext::TState* state =
       
   603 							&(iContexts[ iContext ].iStates[ iState->iId ]);
       
   604 	for ( TInt i = 0; i < KVRMaxTransitions; i++ )
       
   605 		{
       
   606 		const TVRContext::TTransition* transition = &state->iTransitions[ i ];
       
   607 		if ( ( transition->iCommandId == aCommandId ) &&
       
   608 			( transition->iValid ) )
       
   609 			{
       
   610 			aTransition = *transition;
       
   611 			return;
       
   612 			}
       
   613 		}
       
   614 
       
   615 	User::Panic( KVRPanic, EPanicInvalidTransition );
       
   616 	}
       
   617 
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 // CVRRecViewModel::GetTransition
       
   621 // 
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CVRRecViewModel::GetTransition(
       
   625 								TVRContext::TTransition& aTransition ) const
       
   626 	{
       
   627 	aTransition = iContexts[ iContext ].iInitialTransition;
       
   628 	}
       
   629 
       
   630 
       
   631 // ---------------------------------------------------------------------------
       
   632 // CVRRecViewModel::ChangeState
       
   633 // 
       
   634 // ---------------------------------------------------------------------------
       
   635 //
       
   636 void CVRRecViewModel::ChangeState( TUint aNewState, TBool aForced )
       
   637 	{
       
   638 	if ( !aForced )
       
   639 		{
       
   640 		if ( ( aNewState == iState->iId ) || ( aNewState == EStateInitial ) )
       
   641 			{
       
   642 			return;
       
   643 			}
       
   644 		}
       
   645 
       
   646 	iState = &iStateArray.At( aNewState );
       
   647 
       
   648 	if ( iStateInfoObserver )
       
   649 		{
       
   650 		iStateInfoObserver->Update();
       
   651 		}
       
   652 	if ( iButtonPanelObserver )
       
   653 		{
       
   654 		iResetButtons = ETrue;
       
   655 		iButtonPanelObserver->Update( EVRUpdateStateChange );
       
   656 		}
       
   657 	if ( iDecoratorObserver )
       
   658 		{
       
   659 		iDecoratorObserver->Update();
       
   660 		}
       
   661 	}
       
   662 
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // CVRRecViewModel::EnterContextL
       
   666 // 
       
   667 // ---------------------------------------------------------------------------
       
   668 //
       
   669 void CVRRecViewModel::EnterContextL( const TVRRecViewContexts& aContext )
       
   670 	{
       
   671 	iContextEntered = EFalse;
       
   672 	if ( iRecorder )
       
   673 		{
       
   674 		delete iRecorder;
       
   675 		iRecorder = NULL;
       
   676 		}
       
   677 
       
   678 	CVRMdaRecorder* recorder = new( ELeave ) CVRMdaRecorder();
       
   679 	CleanupStack::PushL( recorder );
       
   680 	recorder->ConstructL();
       
   681 	CleanupStack::Pop();
       
   682 	iRecorder = recorder;
       
   683 
       
   684 	iRecorder->RegisterObserver( iStateInfoObserver );
       
   685 	iRecorder->SetAutoStopObserver( this );
       
   686 
       
   687 	LeaveContext();
       
   688 	iContext = aContext;
       
   689 
       
   690 	iRecorder->AttachToMemoL(iMemo);
       
   691 
       
   692 	TVRContext::TTransition transition;
       
   693 	GetTransition( transition );
       
   694 
       
   695 	ChangeState( transition.iNewState, ETrue );
       
   696 	CallFunctionByIdL( transition.iFunctionId );
       
   697 
       
   698 	iContextEntered = ETrue;
       
   699 	}
       
   700 
       
   701 
       
   702 // ---------------------------------------------------------------------------
       
   703 // CVRRecViewModel::LeaveContext
       
   704 // 
       
   705 // ---------------------------------------------------------------------------
       
   706 //
       
   707 void CVRRecViewModel::LeaveContext()
       
   708 	{
       
   709 	iContextEntered = EFalse;
       
   710 	if( iRecorder )
       
   711 		{
       
   712 		iRecorder->UnregisterObserver( iStateInfoObserver );
       
   713 		iRecorder->UnregisterObserver( iButtonPanelObserver );
       
   714 
       
   715 		iRecorder->DetachMemo();
       
   716 
       
   717 		iRecorder->RegisterObserver( iStateInfoObserver );
       
   718 		iRecorder->RegisterObserver( iButtonPanelObserver );
       
   719 		}
       
   720 	}
       
   721 
       
   722 
       
   723 // ---------------------------------------------------------------------------
       
   724 // CVRRecViewModel::CbaResourceId
       
   725 // 
       
   726 // ---------------------------------------------------------------------------
       
   727 //
       
   728 TInt CVRRecViewModel::CbaResourceId() const
       
   729 	{
       
   730 	return iState->iCbaResourceId;
       
   731 	}
       
   732 
       
   733 
       
   734 // ---------------------------------------------------------------------------
       
   735 // CVRRecViewModel::GetHelpContext
       
   736 // 
       
   737 // ---------------------------------------------------------------------------
       
   738 //
       
   739 void CVRRecViewModel::GetHelpContext( TCoeHelpContext& aContext ) const
       
   740 	{
       
   741        if (FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   742   	   {   
       
   743 		  if ( iState->iId == EStateDeleted )
       
   744 			{
       
   745 			aContext.iContext = KVOREC_HLP_EMPTY_RECORDER;
       
   746 			}
       
   747 		   else
       
   748 			{
       
   749 			aContext.iContext = KVOREC_HLP_MAIN;
       
   750 			}
       
   751     	}
       
   752 	}
       
   753 
       
   754 // ---------------------------------------------------------------------------
       
   755 // CVRRecViewModel::SetDecoratorObserver
       
   756 // 
       
   757 // ---------------------------------------------------------------------------
       
   758 //
       
   759 void CVRRecViewModel::SetDecoratorObserver( MVRObserver* aObserver )
       
   760 	{
       
   761 	iDecoratorObserver = aObserver;
       
   762 	}
       
   763 
       
   764 
       
   765 // ---------------------------------------------------------------------------
       
   766 // CVRRecViewModel::MenuBarResourceId
       
   767 // 
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 TInt CVRRecViewModel::MenuBarResourceId() const
       
   771 	{
       
   772 	return iState->iMenubarResourceId;
       
   773 	}
       
   774 
       
   775 
       
   776 // ---------------------------------------------------------------------------
       
   777 // CVRRecViewModel::ButtonCount
       
   778 // 
       
   779 // ---------------------------------------------------------------------------
       
   780 //
       
   781 TInt CVRRecViewModel::ButtonCount() const
       
   782 	{
       
   783 
       
   784 	return iState->iButtonCount;
       
   785 	}
       
   786 
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // CVRRecViewModel::CBAEnabled
       
   790 // from MVRDecoratorModel
       
   791 // ---------------------------------------------------------------------------
       
   792 //	
       
   793 TBool CVRRecViewModel::CBAEnabled() const
       
   794 	{
       
   795 	return iCBAEnabled;	
       
   796 	}
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 // CVRRecViewModel::ButtonState
       
   801 // Checks and returns whether the state of the button should be in active or 
       
   802 // dimmed state. aButtonId tells the index of the button to be checked. Few 
       
   803 // special cases (end and the beginning of the clip) can be handled here.
       
   804 // ---------------------------------------------------------------------------
       
   805 //	
       
   806 TInt CVRRecViewModel::ButtonState( TInt aButtonId ) const
       
   807 	{
       
   808     if(CVRUSBStateHanlder::IsUsbActive() || !iIsDriveReady)
       
   809         {
       
   810             return EDimmed;
       
   811         }
       
   812 	// Disable rewind button if there's nothing to rewind
       
   813 	if ( aButtonId == EButtonRewind &&
       
   814 		( Position().Int64() / KVRSecondAsMicroSeconds ) < 1 )
       
   815 		{
       
   816 		return EDimmed;
       
   817 		}
       
   818 	
       
   819 	// Disable forward button if position is at the end or the length of the
       
   820 	// clip is smaller than 1	
       
   821 	if ( aButtonId == EButtonForward && ( Position() == Duration() || 
       
   822 			( Duration().Int64() / KVRSecondAsMicroSeconds ) < 1 ) )
       
   823 		{
       
   824 		return EDimmed;
       
   825 		}
       
   826 
       
   827     // Jeffery: the following ifs are temperary.  they need to be removed after "Pause" is supported in plugin
       
   828 #ifdef    __AAC_ENCODER_PLUGIN 
       
   829     if  ( iState->iId == EStateRecording &&  aButtonId == EButtonRecord  && iMemo->Quality() == EQualityHigh)
       
   830 		{
       
   831 		return EDimmed;
       
   832 		}
       
   833 #endif
       
   834 		
       
   835 	return iState->ButtonState( aButtonId );
       
   836 	}
       
   837 
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // CVRRecViewModel::CommandId
       
   841 // 
       
   842 // ---------------------------------------------------------------------------
       
   843 //
       
   844 TInt CVRRecViewModel::CommandId( TInt aButtonId ) const
       
   845 	{
       
   846 	return iState->ButtonCommandId( aButtonId );
       
   847 	}
       
   848 
       
   849 
       
   850 // ---------------------------------------------------------------------------
       
   851 // CVRRecViewModel::InitialFocusButtonId
       
   852 // 
       
   853 // ---------------------------------------------------------------------------
       
   854 //
       
   855 TInt CVRRecViewModel::InitialFocusButtonId() const
       
   856 	{
       
   857 	return iState->iFocusButtonId;
       
   858 	}
       
   859 
       
   860 
       
   861 // ---------------------------------------------------------------------------
       
   862 // CVRRecViewModel::SetButtonPanelObserver
       
   863 // 
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 void CVRRecViewModel::SetButtonPanelObserver( MVRObserver* aObserver )
       
   867 	{
       
   868 	if ( iRecorder )
       
   869 		{
       
   870 		if ( iButtonPanelObserver )
       
   871 			{
       
   872 			iRecorder->RegisterObserver( aObserver );
       
   873 			}
       
   874 		else
       
   875 			{
       
   876 			iRecorder->UnregisterObserver( iButtonPanelObserver );
       
   877 			}
       
   878 		}
       
   879 		
       
   880 		iButtonPanelObserver = aObserver;	
       
   881 	}
       
   882 
       
   883 
       
   884 // ---------------------------------------------------------------------------
       
   885 // CVRRecViewModel::ResetNeeded
       
   886 // 
       
   887 // ---------------------------------------------------------------------------
       
   888 //
       
   889 TBool CVRRecViewModel::ResetNeeded()
       
   890 	{
       
   891 	if ( iResetButtons )
       
   892 		{
       
   893 		iResetButtons = EFalse;
       
   894 		return ETrue;		
       
   895 		}
       
   896 
       
   897 	return iResetButtons; // EFalse always
       
   898 	}
       
   899 
       
   900 	
       
   901 // ---------------------------------------------------------------------------
       
   902 // CVRRecViewModel::VisualStateId()
       
   903 // Returns the id of VR current (visual) state
       
   904 // ---------------------------------------------------------------------------
       
   905 //	
       
   906 TUint CVRRecViewModel::VisualStateId() const
       
   907 	{
       
   908 	return iState->iStateId;	
       
   909 	}
       
   910 
       
   911 	
       
   912 // ---------------------------------------------------------------------------
       
   913 // CVRRecViewModel::CanHandleCommands()
       
   914 // Returns ETrue if model can handle new commands, EFalse otherwise
       
   915 // ---------------------------------------------------------------------------
       
   916 //	
       
   917 TBool CVRRecViewModel::CanHandleCommands() const
       
   918 	{
       
   919 	return iCanHandleCommands;
       
   920 	}
       
   921 
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 // CVRRecViewModel::Duration
       
   925 // 
       
   926 // ---------------------------------------------------------------------------
       
   927 //	
       
   928 TTimeIntervalMicroSeconds CVRRecViewModel::Duration() const
       
   929 	{
       
   930 	if ( ( iState->iId == EStateRecording ) ||
       
   931 		 ( iState->iId == EStateRecordingPaused ) )
       
   932 		{
       
   933 		return iMemo->MaxDuration();
       
   934 		}
       
   935 	return iMemo->Duration();
       
   936 	}
       
   937 
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 // CVRRecViewModel::Position
       
   941 // 
       
   942 // ---------------------------------------------------------------------------
       
   943 //
       
   944 TTimeIntervalMicroSeconds CVRRecViewModel::Position() const
       
   945 	{
       
   946 	if ( ( iState->iId == EStateRecording ) ||
       
   947 		 ( iState->iId == EStateRecordingPaused ) )
       
   948 		{
       
   949 		return iMemo->Duration();
       
   950 		}
       
   951 	return iMemo->Position();
       
   952 	}
       
   953 
       
   954 
       
   955 // ---------------------------------------------------------------------------
       
   956 // CVRRecViewModel::GetLabel
       
   957 // Non-leaving version
       
   958 // ---------------------------------------------------------------------------
       
   959 //
       
   960 void CVRRecViewModel::GetLabel( TDes& aName, TInt aLabelIndex ) const
       
   961 	{
       
   962 	TRAP_IGNORE( GetLabelL( aName, aLabelIndex ) );
       
   963 	}
       
   964 
       
   965 
       
   966 // ---------------------------------------------------------------------------
       
   967 // CVRRecViewModel::GetLabelL
       
   968 // 
       
   969 // ---------------------------------------------------------------------------
       
   970 //
       
   971 void CVRRecViewModel::GetLabelL( TDes& aName, TInt aLabelIndex ) const
       
   972 	{
       
   973 	if ( !iMemo->IsValid() )
       
   974 		{
       
   975 		aName.SetLength( 0 );
       
   976 		return;
       
   977 		}
       
   978 
       
   979 	CDesCArray* labels = iLabelSets.At( iState->iLabelSetId );
       
   980 	User::LeaveIfNull( labels );
       
   981 
       
   982 	if ( aLabelIndex < labels->Count() )
       
   983 		{
       
   984 		TInt index = aLabelIndex;
       
   985 
       
   986 		TBuf< VRLABELMAXLENGTH > formatStr(
       
   987 										labels->MdcaPoint( index ) );
       
   988 		TBuf< VRLABELMAXLENGTH > formattedTime;
       
   989 
       
   990 		switch ( aLabelIndex )
       
   991 			{
       
   992 			case ELabelMemoName:
       
   993 				{
       
   994 				//StringLoader::Format( aName, formatStr, -1, iMemo->Name() );
       
   995                                 aName.Copy(iMemo->Name());
       
   996 				break;
       
   997 				}
       
   998 			case ELabelMemoDate:
       
   999 				{
       
  1000 				iMemo->DateCreated().FormatL( formattedTime,
       
  1001 											  iDateUsualWithZero );
       
  1002 				StringLoader::Format( aName, formatStr, 0, formattedTime );
       
  1003 
       
  1004 				iMemo->DateCreated().FormatL( formattedTime,
       
  1005 											  iTimeUsualWithZero );
       
  1006 				formatStr.Copy( aName );
       
  1007 				StringLoader::Format( aName, formatStr, 1, formattedTime );
       
  1008 				AknTextUtils::LanguageSpecificNumberConversion( aName );
       
  1009 				break;
       
  1010 				}
       
  1011 			case ELabelMemoQuality:
       
  1012 				{
       
  1013 				// Display empty row if feature is not on
       
  1014                 if ( !VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
  1015                     {
       
  1016                     aName.Copy( KNullDesC );
       
  1017                     break;
       
  1018                     }
       
  1019 				
       
  1020 				aName.Copy( formatStr );
       
  1021 				break;
       
  1022 				}
       
  1023 			case ELabelQualityText:	
       
  1024 				{
       
  1025 					// Display empty row if feature is not on
       
  1026                 if ( !VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
  1027                     {
       
  1028                     aName.Copy( KNullDesC );
       
  1029                     break;
       
  1030                     }
       
  1031                     
       
  1032 				formatStr.Copy( placeForQuality );
       
  1033 					
       
  1034 					switch( iMemo->Quality() )
       
  1035 				    {
       
  1036 				    case EQualityMMSOptimized:
       
  1037 				        {
       
  1038 				        StringLoader::Load( formattedTime, R_VOREC_QUALITY_MMS_OPTIMIZED );
       
  1039 				        StringLoader::Format( aName, formatStr, -1, formattedTime );
       
  1040 				        break;
       
  1041 				        }
       
  1042 				        
       
  1043 				        // EQualityNormal is used only when mp4 is supported.  In this case the file is saved as wav.
       
  1044 #ifdef  __AAC_ENCODER_PLUGIN
       
  1045 				    case EQualityNormal:
       
  1046 				        {
       
  1047 				        StringLoader::Load( formattedTime, R_VOREC_QUALITY_NORMAL );				        
       
  1048 				        StringLoader::Format( aName, formatStr, -1, formattedTime );				        
       
  1049 				        break;
       
  1050 				        }
       
  1051 #endif
       
  1052 
       
  1053 				    case EQualityHigh:
       
  1054 				        {
       
  1055 				        StringLoader::Load( formattedTime, R_VOREC_QUALITY_HIGH );				        
       
  1056 				        StringLoader::Format( aName, formatStr, -1, formattedTime );				        
       
  1057 				        break;
       
  1058 				        }
       
  1059 				    default:
       
  1060 				        {
       
  1061 				        aName.Copy( KNullDesC );
       
  1062 				        break;
       
  1063 				        }
       
  1064 				    }
       
  1065 				break;
       
  1066 				}
       
  1067 			case ELabelBarMin:
       
  1068 				{
       
  1069 				aName.Copy( KNullDesC );
       
  1070 				break;
       
  1071 				}
       
  1072 			case ELabelBarMax:
       
  1073 				{
       
  1074 				// This label layout is nowadays taking automatically care of 
       
  1075 				// string mirroring in the case of mirrored layout. So use of 
       
  1076 				// AknLayoutUtils::LayoutMirrored() isn't needed anymore
       
  1077 				
       
  1078 				TTimeIntervalMicroSeconds max( 0 );
       
  1079 				if ( ( iState->iId == EStateRecording ) ||
       
  1080 				 ( iState->iId == EStateRecordingPaused ) )
       
  1081 					{
       
  1082 					max = iMemo->MaxDuration();
       
  1083 					}
       
  1084 				else
       
  1085 					{
       
  1086 					max = iMemo->Duration().Int64();
       
  1087 
       
  1088 					if ( max.Int64() < 0 )
       
  1089 						{
       
  1090 						max = 0;
       
  1091 						}
       
  1092 					}
       
  1093 
       
  1094 				TTime lengthAsTime( max.Int64() );
       
  1095 				TTime positionAsTime( iMemo->Position().Int64() );
       
  1096 				TBuf< VRLABELMAXLENGTH > formattedPosition;
       
  1097 
       
  1098 				// current memo quality 
       
  1099 				TVRQuality quality( iMemo->Quality() );
       
  1100 				
       
  1101 				// Show --:--:-- if estimate for maximum recording time is not
       
  1102 				// known yet. Done only when memo quality is High
       
  1103 				if ( ( ( iState->iId == EStateRecording ) || 
       
  1104 					   ( iState->iId == EStateRecordingPaused )) && 
       
  1105 					   ( Position() < KVRFirstEstimateTime ) && 
       
  1106 					   ( quality == EQualityHigh ) &&
       
  1107 					   ( max.Int64() < 0) )
       
  1108 					{
       
  1109 					formattedTime.Append( KVRBeforeFirstEstimateLabel );
       
  1110 					}
       
  1111 				// Show normal maximum time	
       
  1112 				else	
       
  1113 					{
       
  1114 					// Show longer format if time is more than 1 hour
       
  1115 					FormatTimeL( lengthAsTime, formattedTime );		
       
  1116 					}
       
  1117 	
       
  1118 				// Show longer format if time is more than 1 hour
       
  1119 				FormatTimeL( positionAsTime, formattedPosition );
       
  1120 						
       
  1121 				StringLoader::Format( aName, formatStr, 0, formattedPosition );
       
  1122 				formatStr.Copy( aName );
       
  1123 				StringLoader::Format( aName, formatStr, 1, formattedTime );
       
  1124 				AknTextUtils::LanguageSpecificNumberConversion( aName );
       
  1125 
       
  1126 				break;						
       
  1127 				}
       
  1128 			case ELabelStatus:
       
  1129 				{
       
  1130 				aName.Copy( iState->iStatus );
       
  1131 				break;
       
  1132 				}
       
  1133 			default:
       
  1134 				{
       
  1135 				break;
       
  1136 				}
       
  1137 			}
       
  1138 		}
       
  1139 	else
       
  1140 		{
       
  1141 		aName.SetLength( 0 );
       
  1142 		}
       
  1143 	}
       
  1144 
       
  1145 
       
  1146 // ---------------------------------------------------------------------------
       
  1147 // CVRRecViewModel::ResourceIdForLabel
       
  1148 // 
       
  1149 // ---------------------------------------------------------------------------
       
  1150 //
       
  1151 TInt CVRRecViewModel::ResourceIdForLabel( TInt aLabelIndex,
       
  1152 										  TAknLayoutId aLayout ) const
       
  1153 	{
       
  1154 	switch ( aLayout )
       
  1155 		{
       
  1156 		case EAknLayoutIdELAF:
       
  1157 		default:
       
  1158 			return iLabelLayoutLinks[ aLabelIndex ].iEuroId;
       
  1159 
       
  1160 		case EAknLayoutIdABRW:
       
  1161 			return iLabelLayoutLinks[ aLabelIndex ].iArabicHebrewId;
       
  1162 
       
  1163 		case EAknLayoutIdAPAC:
       
  1164 			return iLabelLayoutLinks[ aLabelIndex ].iApacId;
       
  1165 
       
  1166 		}
       
  1167 
       
  1168 	}
       
  1169 
       
  1170 
       
  1171 // ---------------------------------------------------------------------------
       
  1172 // CVRRecViewModel::SetStateInfoObserver
       
  1173 // 
       
  1174 // ---------------------------------------------------------------------------
       
  1175 //
       
  1176 void CVRRecViewModel::SetStateInfoObserver( MVRObserver* aObserver )
       
  1177 	{
       
  1178 	iStateInfoObserver = aObserver;
       
  1179 	if( iRecorder )
       
  1180 		{
       
  1181 		iRecorder->RegisterObserver( iStateInfoObserver );
       
  1182 		}
       
  1183 	}
       
  1184 
       
  1185 
       
  1186 // ---------------------------------------------------------------------------
       
  1187 // CVRRecViewModel::SetStateInfoPanelObserver
       
  1188 // Observes changes in state info panel
       
  1189 // ---------------------------------------------------------------------------
       
  1190 //	
       
  1191 void CVRRecViewModel::SetStateInfoPanelObserver( MVRStateInfoObserver* 
       
  1192 																	aObserver )
       
  1193 	{
       
  1194 	iStateInfoPanelObserver = aObserver;
       
  1195 	}
       
  1196 
       
  1197 
       
  1198 // ---------------------------------------------------------------------------
       
  1199 // CVRRecViewModel::HasProgressBar
       
  1200 // 
       
  1201 // ---------------------------------------------------------------------------
       
  1202 //	
       
  1203 TBool CVRRecViewModel::HasProgressBar() const
       
  1204 	{
       
  1205 	return iState->iHasProgressBar;
       
  1206 	}
       
  1207 
       
  1208 
       
  1209 // ---------------------------------------------------------------------------
       
  1210 // CVRRecViewModel::GetSelectedFilesLC
       
  1211 // 
       
  1212 // ---------------------------------------------------------------------------
       
  1213 //
       
  1214 MDesCArray* CVRRecViewModel::GetSelectedFilesLC() const
       
  1215 	{
       
  1216 	CDesCArray* array = new( ELeave ) CDesCArrayFlat( 1 ); // granularity = 1
       
  1217 	CleanupStack::PushL( array );
       
  1218 	array->AppendL( iMemo->Filename() );
       
  1219 	return array;
       
  1220 	}
       
  1221 
       
  1222 
       
  1223 // ---------------------------------------------------------------------------
       
  1224 // CVRRecViewModel::SetVolume
       
  1225 // 
       
  1226 // ---------------------------------------------------------------------------
       
  1227 //
       
  1228 void CVRRecViewModel::SetVolume( TInt aStep, TInt aMaxSteps )
       
  1229 	{
       
  1230 	iIhfVolume = aStep;
       
  1231     iRecorder->SetVolume( aStep, aMaxSteps );
       
  1232 	}
       
  1233 
       
  1234 
       
  1235 // ---------------------------------------------------------------------------
       
  1236 // CVRRecViewModel::SetMemoName
       
  1237 // 
       
  1238 // ---------------------------------------------------------------------------
       
  1239 //
       
  1240 void CVRRecViewModel::SetMemoName( const TDesC& aFilename )
       
  1241 	{
       
  1242 	iMemo->SetName( aFilename );
       
  1243 	}
       
  1244 
       
  1245 
       
  1246 // ---------------------------------------------------------------------------
       
  1247 // CVRRecViewModel::SetMemoNameNewL
       
  1248 // 
       
  1249 // ---------------------------------------------------------------------------
       
  1250 //
       
  1251 void CVRRecViewModel::SetMemoNameNewL( TBool aEmbedded )
       
  1252 	{
       
  1253 	iMemo->SetTemporaryNameL( aEmbedded );
       
  1254 	}
       
  1255 
       
  1256 
       
  1257 // ---------------------------------------------------------------------------
       
  1258 // CVRRecViewModel::Filename
       
  1259 // 
       
  1260 // ---------------------------------------------------------------------------
       
  1261 //
       
  1262 const TDesC& CVRRecViewModel::Filename() const
       
  1263 	{
       
  1264 	return iMemo->Filename();
       
  1265 	}
       
  1266 
       
  1267 void CVRRecViewModel::SetSavingLocationL( const TDesC& aPath )
       
  1268 	{
       
  1269 	iMemo->SetSavingLocationL( aPath );
       
  1270 	}
       
  1271 
       
  1272 
       
  1273 // ---------------------------------------------------------------------------
       
  1274 // CVRRecViewModel::Update
       
  1275 // 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 //
       
  1278 void CVRRecViewModel::Update( TVRUpdateCommand /*aCommand*/ )
       
  1279 	{
       
  1280 	// Error is propagated to error handling method
       
  1281 	TRAPD( err, HandleCommandL( ECmdAutoStopAtEnd ) );
       
  1282 
       
  1283 	// Ignore further errors
       
  1284 	TRAP_IGNORE( HandleUpdateErrorL( err ) );
       
  1285 	}
       
  1286 
       
  1287 
       
  1288 // ---------------------------------------------------------------------------
       
  1289 // CVRRecViewModel::IsEmbedded
       
  1290 // 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 //
       
  1293 TBool CVRRecViewModel::IsEmbedded() const
       
  1294 	{
       
  1295 	return ( iContext == EContextRecordNewForRemote )
       
  1296 			|| ( iContext == EContextViewer );
       
  1297 	}
       
  1298 
       
  1299 
       
  1300 // ---------------------------------------------------------------------------
       
  1301 // CVRRecViewModel::CanAcceptCommands
       
  1302 // 
       
  1303 // ---------------------------------------------------------------------------
       
  1304 //
       
  1305 TBool CVRRecViewModel::CanAcceptCommands() const
       
  1306 	{
       
  1307 	return ( iContextEntered != EFalse ) && iRecorder->CanAcceptCommands();
       
  1308 	}
       
  1309 
       
  1310 
       
  1311 // ---------------------------------------------------------------------------
       
  1312 // CVRRecViewModel::SendViaL
       
  1313 // 
       
  1314 // ---------------------------------------------------------------------------
       
  1315 //
       
  1316 void CVRRecViewModel::SendViaL( CSendUi* aSendUi )
       
  1317 	{
       
  1318 	// Don't accept commands during sending operation
       
  1319 	iContextEntered = EFalse;
       
  1320 	
       
  1321 	iRecorder->DetachMemo();
       
  1322 	// Detaching resets the clip position so button panel needs to be updated
       
  1323 	iButtonPanelObserver->Update( EVRUpdatePositionChange );
       
  1324 	
       
  1325 	TSendingCapabilities capabilities
       
  1326 			(0, KVRSendUiMsgSize, TSendingCapabilities::ESupportsAttachments);
       
  1327 	CMessageData* messageData = CMessageData::NewL();
       
  1328 	CleanupStack::PushL( messageData );
       
  1329 
       
  1330 	messageData->AppendAttachmentHandleL( iMemo->File() );
       
  1331 	
       
  1332 	// Get an array of the services that should be dimmed
       
  1333 	CArrayFixFlat< TUid >* servicesToDim = SendViaServicesToDimLC();
       
  1334 
       
  1335 	// For some reason this function leaves when 'NO' is selected in bluetooth 
       
  1336 	// case's activation question. If this is not Trapped iContextEntered stays
       
  1337 	// EFalse and no commands can be executed
       
  1338 	TRAPD( err, aSendUi->ShowQueryAndSendL( messageData, 
       
  1339 											capabilities, 
       
  1340 											servicesToDim ) );
       
  1341 	
       
  1342 	CleanupStack::PopAndDestroy( servicesToDim );
       
  1343 	CleanupStack::PopAndDestroy( messageData );
       
  1344 
       
  1345 	iRecorder->AttachToMemoL( iMemo );
       
  1346 	
       
  1347 	iContextEntered = ETrue;
       
  1348 	
       
  1349 	// This is done so we get possible "Feature not supported" 
       
  1350 	// infonote from the framework
       
  1351 	User::LeaveIfError( err );
       
  1352 	}
       
  1353 
       
  1354 
       
  1355 // ---------------------------------------------------------------------------
       
  1356 // CVRRecViewModel::SendViaServicesToDimLC
       
  1357 // Generates an array of the services (Uids) that should be dimmed from Send
       
  1358 // via menu. Returns a pointer to that array. Configuration in Messaging 
       
  1359 // central repository defines services to dim.
       
  1360 // ---------------------------------------------------------------------------
       
  1361 //	
       
  1362 CArrayFixFlat<TUid>* CVRRecViewModel::SendViaServicesToDimLC()
       
  1363 	{
       
  1364 	CArrayFixFlat< TUid >* servicesToDim = 
       
  1365 									new( ELeave ) CArrayFixFlat< TUid >( 1 );
       
  1366     CleanupStack::PushL( servicesToDim );
       
  1367      
       
  1368     CRepository* repository = 
       
  1369     					CRepository::NewL( KCRUidMuiuMessagingConfiguration );
       
  1370     TInt configuration = 0;
       
  1371     if ( !repository->Get( KMuiuSendUiConfiguration, configuration ) )
       
  1372         {
       
  1373         configuration = configuration & KMuiuEmailDisabledInMultimedia;
       
  1374         }
       
  1375     delete repository;
       
  1376 
       
  1377   	if ( configuration )
       
  1378     	{
       
  1379     	servicesToDim->AppendL( KSenduiMtmSmtpUid );		// normal email
       
  1380     	servicesToDim->AppendL( KSenduiMtmSyncMLEmailUid );	// sync email
       
  1381     	}
       
  1382     	
       
  1383     return servicesToDim;	
       
  1384 	}
       
  1385 
       
  1386 
       
  1387 // ---------------------------------------------------------------------------
       
  1388 // CVRRecViewModel::CallFunctionByIdL
       
  1389 // 
       
  1390 // ---------------------------------------------------------------------------
       
  1391 //	
       
  1392 /*
       
  1393 IMPLEMENTATION NOTE:
       
  1394 This method needs refactoring with CVRMemo and CVRMdaRecorder.
       
  1395 Probably most of the logic should be transferred to CVRMemo.
       
  1396 */
       
  1397 TBool CVRRecViewModel::CallFunctionByIdL( TInt aFunctionId )
       
  1398 	{
       
  1399 	switch ( aFunctionId )
       
  1400 		{
       
  1401 		case EFunctionPlay:
       
  1402 			{
       
  1403 			CVRMdaRecorder* iRecorderUtility = NULL;
       
  1404 			iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);
       
  1405 			if ( VRUtils::UnsupportedCallTypeOngoing( ETrue ) || iRecorderUtility == NULL || !iRecorderUtility->IsAttachedToMemo())
       
  1406 				{
       
  1407 				return EFalse;
       
  1408 				}
       
  1409 
       
  1410 			iIgnoreNextIhfChange = EFalse;
       
  1411 			SetRecorderVolume();
       
  1412 			SetIHFIfCallNotActive( iIhfState );
       
  1413 			TInt mediaservErr( KErrNone );
       
  1414 			
       
  1415 			// Don't accept CBA commands
       
  1416 			iCBAEnabled = EFalse;
       
  1417 			// Update CBAs
       
  1418 			iDecoratorObserver->Update( EVRUpdateCBA );
       
  1419 			TRAPD( leaveErr, mediaservErr = iRecorder->PlayL() );
       
  1420 			
       
  1421 			// Accept CBAs again. CBAs are updated when state is changed
       
  1422 			iCBAEnabled = ETrue;
       
  1423 			
       
  1424 			if ( leaveErr == KErrNotReady )
       
  1425 				{
       
  1426 				ShowNoteL( R_VR_CORRUPT_INFONOTE_LABEL, EAknGlobalErrorNote );
       
  1427 				return EFalse;
       
  1428 				}
       
  1429 
       
  1430 			if ( mediaservErr != KErrNone )
       
  1431 				{
       
  1432 				// cancel the state change
       
  1433 				// the error note is shown in CVRMdaRecorder
       
  1434 				return EFalse;
       
  1435 				}
       
  1436 			User::LeaveIfError( leaveErr );
       
  1437 			break;
       
  1438 			}
       
  1439 		case EFunctionStop:
       
  1440 			{
       
  1441 			// Turn off the IHF after playing
       
  1442 			SetIHFIfCallNotActive( EFalse );
       
  1443 			iRecorder->Stop();
       
  1444 			CheckIhfState();
       
  1445 			break;
       
  1446 			}
       
  1447 		case EFunctionStopWithNote:
       
  1448 			{
       
  1449 			// No need to do anything to IHF here since this is
       
  1450 			// called after recording (IHF is not used)
       
  1451 			iRecorder->Stop();
       
  1452 			ShowNoteL( R_VR_STOP_INFONOTE_LABEL, EAknGlobalInformationNote );
       
  1453 			break;
       
  1454 			}
       
  1455 		case EFunctionStopAndSave:
       
  1456 			{
       
  1457 			// No need to do anything to IHF here since this is
       
  1458 			// called after recording (IHF is not used)
       
  1459 			StopAndSaveL( 0 );
       
  1460 			break;
       
  1461 			}
       
  1462 		case EFunctionAutoStopAndSave:
       
  1463 			{
       
  1464 			// No need to do anything to IHF here since this is
       
  1465 			// called after recording (IHF is not used)
       
  1466 			StopAndSaveL( R_VR_STOP_INFONOTE_LABEL );
       
  1467 			break;
       
  1468 			}
       
  1469 		case EFunctionSilentStopAndSave:
       
  1470 			{
       
  1471 			// No need to do anything to IHF here since this is
       
  1472 			// called after recording (IHF is not used)
       
  1473 			StopAndSaveL( 0 );
       
  1474 			break;
       
  1475 			}
       
  1476 
       
  1477 		case EFunctionAutoStop:
       
  1478 			{
       
  1479 			// Turn off the IHF after playing
       
  1480 			SetIHFIfCallNotActive( EFalse );
       
  1481 			iRecorder->Stop();
       
  1482 			CheckIhfState();
       
  1483 			break;
       
  1484 			}
       
  1485 		case EFunctionSaveBeforeExit:
       
  1486 			{
       
  1487 			StopAndCloseL( R_VR_STOP_SAVE_WAITNOTE_LABEL );
       
  1488 			break;
       
  1489 			}
       
  1490 		case EFunctionRecord:
       
  1491 			{
       
  1492 			CVRMdaRecorder* iRecorderUtility = NULL;
       
  1493 			if ( VRUtils::UnsupportedCallTypeOngoing( ETrue ) )
       
  1494 				{
       
  1495 				return EFalse;
       
  1496 				}			
       
  1497          
       
  1498 			//if ( iRecorder->RecordL() != KErrNone )
       
  1499 			//	{
       
  1500 			//	return EFalse;
       
  1501 			//	}
       
  1502 			
       
  1503 			if(iCurrentCallHandler->StateL(KPSUidCtsyCallInformation,KCTsyCallState )==EPSCTsyCallStateConnected)
       
  1504 				{
       
  1505 				iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);
       
  1506 				if(iRecorderUtility != NULL)
       
  1507 					{
       
  1508 					iRecorderUtility->SetAudioInputL(CAudioInput::EVoiceCall);	
       
  1509 					iRecorderUtility->ConfigSampleRateOfVoiceCallL();
       
  1510 					}
       
  1511 				}
       
  1512 			//Audioinput can't be changed after Record
       
  1513 			if ( iRecorder->RecordL() != KErrNone )
       
  1514 				{
       
  1515 				return EFalse;
       
  1516 				}	
       
  1517 			break;
       
  1518 			}
       
  1519 		case EFunctionPause:
       
  1520 			{
       
  1521 			
       
  1522 			iRecorder->Pause();
       
  1523 			// Turn off the IHF after playing
       
  1524 			SetIHFIfCallNotActive( EFalse );         
       
  1525 			break;
       
  1526 			}
       
  1527 		case EFunctionForward:
       
  1528 			{
       
  1529 			TInt result = iRecorder->ForwardL();
       
  1530 
       
  1531 			// The volume setting is lost when the media server client object
       
  1532 			// is stopped.
       
  1533 			SetRecorderVolume();
       
  1534 
       
  1535 			if ( result )
       
  1536 				{
       
  1537 				return EFalse;
       
  1538 				}
       
  1539 			break;
       
  1540 			}
       
  1541 		case EFunctionRewind:
       
  1542 			{
       
  1543 			iRecorder->RewindL();
       
  1544 			if ( iButtonPanelObserver )
       
  1545 			    {
       
  1546 			    iButtonPanelObserver->Update();
       
  1547 			    }
       
  1548 
       
  1549 			// The volume setting is lost when the media server client object
       
  1550 			// is stopped
       
  1551 			SetRecorderVolume();
       
  1552 			break;
       
  1553 			}
       
  1554 		case EFunctionRecordNew:
       
  1555 			{
       
  1556 			CVRMdaRecorder* iRecorderUtility = NULL;
       
  1557 			if ( VRUtils::UnsupportedCallTypeOngoing( ETrue ) )
       
  1558 				{
       
  1559 				return EFalse;
       
  1560 				}
       
  1561 			iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);
       
  1562 			if(iRecorderUtility == NULL)
       
  1563 				{
       
  1564 				return EFalse;
       
  1565 				}
       
  1566 			iRecorderUtility->SetInRecordingFlag(ETrue);
       
  1567             
       
  1568 			iCanHandleCommands = EFalse;
       
  1569 			// Don't accept CBA commands
       
  1570 			iCBAEnabled = EFalse;
       
  1571 			// Update CBAs
       
  1572 			iDecoratorObserver->Update( EVRUpdateCBA );
       
  1573             
       
  1574 		    iRecorder->DetachMemo();
       
  1575 			
       
  1576 			TRAPD( leaveErr1, SetMemoNameNewL( 
       
  1577 					iContext == EContextRecordNewForRemote ) );
       
  1578 			
       
  1579 			// Can't attach if memo name couldn't be generated
       
  1580 			TInt leaveErr2( KErrNone );
       
  1581 			if( !leaveErr1 )
       
  1582 				{
       
  1583 				TRAP( leaveErr2, iRecorder->AttachToMemoL( iMemo ) );	
       
  1584 				}
       
  1585 			
       
  1586 			TBool ifAttach = iRecorderUtility->IsAttachedToMemo();		
       
  1587 	
       
  1588 			if ( leaveErr1 || leaveErr2 || !ifAttach)
       
  1589 				{
       
  1590 				iCanHandleCommands = ETrue;
       
  1591 				iCBAEnabled = ETrue;
       
  1592 				if ( leaveErr1 == KErrDiskFull || leaveErr2 == KErrDiskFull )	
       
  1593 					{
       
  1594 					if ( iMemo->StorageDrive() == VRUtils::GetRemovableMassStorageL())
       
  1595 						{
       
  1596 		 				VRUtils::ShowMemoryFullConfirmationQuery(ETrue);
       
  1597 						}
       
  1598 					else
       
  1599 						{
       
  1600 				 		VRUtils::ShowMemoryFullConfirmationQuery();
       
  1601 						}
       
  1602 					}
       
  1603 				}
       
  1604 			
       
  1605 			User::LeaveIfError( leaveErr1 );
       
  1606 			User::LeaveIfError( leaveErr2 );
       
  1607 			if(!ifAttach)
       
  1608 				{
       
  1609 			    User::Leave(KErrNotReady);	
       
  1610 				}
       
  1611 				
       
  1612 			// Indicates that a new memo is attached but not yet recording 
       
  1613 			// started -> handle can be reused and memo can be deleted in exit
       
  1614 			iMemo->SetRecorded( EFalse );
       
  1615 			
       
  1616 			TInt recError( KErrNone );
       
  1617 
       
  1618 			//TRAPD( recLeaveErr, recError = iRecorder->RecordL() );
       
  1619 			if(iCurrentCallHandler->StateL(KPSUidCtsyCallInformation,KCTsyCallState )==EPSCTsyCallStateConnected)
       
  1620 				{
       
  1621 				iRecorderUtility->SetAudioInputL(CAudioInput::EVoiceCall);
       
  1622 				iRecorderUtility->ConfigSampleRateOfVoiceCallL();
       
  1623 				}
       
  1624 			//Change for CS call:Audio input can't be changed after Record
       
  1625             TRAPD( recLeaveErr, recError = iRecorder->RecordL() );
       
  1626             
       
  1627             if (GetInRecordingFlag())
       
  1628             	{
       
  1629             	iRecorderUtility->SetInRecordingFlag(EFalse);
       
  1630             	}
       
  1631             	
       
  1632 			if ( recError != KErrNone || recLeaveErr )
       
  1633 				{
       
  1634 				iCanHandleCommands = ETrue;
       
  1635 				iCBAEnabled = ETrue;
       
  1636 				if ( recLeaveErr )
       
  1637 					{
       
  1638 					User::LeaveIfError( recLeaveErr );					
       
  1639 					}
       
  1640 				else
       
  1641 					{
       
  1642 					return EFalse;	
       
  1643 					}
       
  1644 				}
       
  1645 			
       
  1646 			
       
  1647 			iCanHandleCommands = ETrue;	
       
  1648 			// Accept CBAs again. CBAs are updated when state is changed
       
  1649 			iCBAEnabled = ETrue;
       
  1650 			break;
       
  1651 			}
       
  1652 		case EFunctionDelete:
       
  1653 			{
       
  1654 			iRecorder->DetachMemo();
       
  1655 			// Detaching resets the clip position so button panel 
       
  1656 			// needs to be updated
       
  1657 			iButtonPanelObserver->Update( EVRUpdatePositionChange );
       
  1658 			if ( !iMemo->QueryAndDeleteL() )
       
  1659 				{
       
  1660 				iRecorder->AttachToMemoL( iMemo );
       
  1661 				return EFalse;
       
  1662 				}
       
  1663 			break;
       
  1664 			}
       
  1665 		case EFunctionRename:
       
  1666 			{
       
  1667 			iRecorder->DetachMemo();
       
  1668 			// Detaching resets the clip position so button panel 
       
  1669 			// needs to be updated
       
  1670 			iButtonPanelObserver->Update( EVRUpdatePositionChange );
       
  1671 			if ( iMemo->QueryAndRenameL() )
       
  1672 				{
       
  1673 				if ( iStateInfoObserver )
       
  1674 					{
       
  1675 					iStateInfoObserver->Update();
       
  1676 					}
       
  1677 				}
       
  1678 			iRecorder->AttachToMemoL( iMemo );
       
  1679 			break;
       
  1680 			}
       
  1681 		case EFunctionOk:
       
  1682 			{
       
  1683 
       
  1684 			HBufC* label = StringLoader::LoadLC( R_VR_SAVE_WAITNOTE_LABEL );
       
  1685 
       
  1686 			iRecorder->DetachMemo();
       
  1687 			iIsNoteLaunched = ETrue;
       
  1688 			iMemo->SavePermanentlyL( iGlobalNote, iNoteId, *label );
       
  1689 
       
  1690 			CEikonEnv::Static()->EikAppUi()->HandleCommandL( 
       
  1691 												ECmdEmbeddedRecordingReady );
       
  1692 
       
  1693 			iGlobalNote->CancelNoteL( iNoteId );
       
  1694 			iIsNoteLaunched = EFalse;
       
  1695 #ifdef _DEBUG
       
  1696 			RDebug::Print( _L( 
       
  1697 						"VoiceRecorder: CVRRecViewModel Note cancelled" ) );
       
  1698 #endif
       
  1699 			CleanupStack::PopAndDestroy( label );
       
  1700 
       
  1701 			HandleCommandL( EEikCmdExit );
       
  1702 			break;
       
  1703 			}
       
  1704 		case EFunctionCancel:
       
  1705 			{
       
  1706 			iRecorder->DetachMemo();
       
  1707 			iMemo->DeleteL();
       
  1708 			HandleCommandL( EEikCmdExit );
       
  1709 			break;
       
  1710 			}
       
  1711 		case EFunctionNop:
       
  1712 			{
       
  1713 			// dummy command, do nothing
       
  1714 			break;
       
  1715 			}
       
  1716 		case EFunctionNRTStop:
       
  1717 			{
       
  1718 			// Turn off the IHF after playing
       
  1719 			SetIHFIfCallNotActive( EFalse );
       
  1720 
       
  1721 			iRecorder->Stop();
       
  1722 			CheckIhfState();
       
  1723 			break;
       
  1724 			}
       
  1725 		case EFunctionNRTAutoStop:
       
  1726 			{
       
  1727 			// Turn off the IHF after playing
       
  1728 			SetIHFIfCallNotActive( EFalse );
       
  1729 			CheckIhfState();
       
  1730 			break;
       
  1731 			}
       
  1732 		case EFunctionSetNewPosition:	
       
  1733 			{
       
  1734 			TInt newValue( 0 );
       
  1735 			if ( iStateInfoPanelObserver )
       
  1736 				{
       
  1737 				newValue = iStateInfoPanelObserver->ProgressBarPosition();		
       
  1738 				}
       
  1739 
       
  1740 			iRecorder->SetPositionL( newValue );
       
  1741 			
       
  1742 			//Inform button Panel
       
  1743 			if ( iButtonPanelObserver )
       
  1744 			    {
       
  1745 			    iButtonPanelObserver->Update( EVRUpdateStateChange );
       
  1746 			    }
       
  1747 			break;
       
  1748 			}	
       
  1749 		default:
       
  1750 			{
       
  1751 			User::Panic( KVRPanic, EPanicFunctionUnknown );
       
  1752 			break;
       
  1753 			}
       
  1754 		}
       
  1755 		return ETrue;
       
  1756 	}
       
  1757 
       
  1758 
       
  1759 // ---------------------------------------------------------------------------
       
  1760 // CVRRecViewModel::StopAndSaveL
       
  1761 // 
       
  1762 // ---------------------------------------------------------------------------
       
  1763 //
       
  1764 void CVRRecViewModel::StopAndSaveL( TInt aResourceId )
       
  1765 	{
       
  1766 	HBufC* label = NULL;
       
  1767 
       
  1768 	// Don't show the note if aResourceId was not defined
       
  1769 	if ( aResourceId )
       
  1770 		{
       
  1771 		label = StringLoader::LoadLC( aResourceId );
       
  1772 		}
       
  1773 
       
  1774 	iRecorder->DetachMemo();
       
  1775 
       
  1776 	if ( label )
       
  1777 		{
       
  1778 		iIsNoteLaunched = ETrue;
       
  1779 		if(iMemo)
       
  1780 			{
       
  1781 		    iMemo->SavePermanentlyL( iGlobalNote, iNoteId, *label );	
       
  1782 			}
       
  1783 		
       
  1784 		// There is no more note showing in SavePermanentlyL() -function
       
  1785 		// the note is shown here
       
  1786 		ShowNoteL( aResourceId, EAknGlobalInformationNote );
       
  1787 		}
       
  1788 	else
       
  1789 		{
       
  1790 		iIsNoteLaunched = ETrue;
       
  1791 		if(iMemo)
       
  1792 			{
       
  1793 		    iMemo->SavePermanentlyL( iGlobalNote, iNoteId, KNullDesC );
       
  1794 			}
       
  1795 		}
       
  1796 
       
  1797 	TRAP_IGNORE(iRecorder->AttachToMemoL( iMemo ));
       
  1798 
       
  1799 	iGlobalNote->CancelNoteL( iNoteId );
       
  1800 	iIsNoteLaunched = EFalse;
       
  1801 
       
  1802 	if ( aResourceId )
       
  1803 		{
       
  1804 		CleanupStack::PopAndDestroy( label );
       
  1805 		}
       
  1806 	}
       
  1807 
       
  1808 
       
  1809 // ---------------------------------------------------------------------------
       
  1810 // CVRRecViewModel::StopAndCloseL
       
  1811 // 
       
  1812 // ---------------------------------------------------------------------------
       
  1813 //
       
  1814 void CVRRecViewModel::StopAndCloseL( TInt aResourceId )
       
  1815 	{
       
  1816 	HBufC* label = NULL;
       
  1817 
       
  1818 	// Don't show the note if aResourceId was not defined
       
  1819 	if ( aResourceId )
       
  1820 		{
       
  1821 		label = StringLoader::LoadLC( aResourceId );
       
  1822 		}
       
  1823 
       
  1824 	iRecorder->DetachMemo();
       
  1825 
       
  1826 	if ( label )
       
  1827 		{
       
  1828 		iIsNoteLaunched = ETrue;
       
  1829 		if(iMemo)
       
  1830 			{
       
  1831 		    iMemo->SavePermanentlyL( iGlobalNote, iNoteId, *label );	
       
  1832 			}
       
  1833 		}
       
  1834 	else
       
  1835 		{
       
  1836 		iIsNoteLaunched = ETrue;
       
  1837 		if(iMemo)
       
  1838 			{
       
  1839 		    iMemo->SavePermanentlyL( iGlobalNote, iNoteId, KNullDesC );	
       
  1840 			}
       
  1841 		}
       
  1842 
       
  1843 	iGlobalNote->CancelNoteL( iNoteId );
       
  1844 	iIsNoteLaunched = EFalse;
       
  1845 
       
  1846 	if ( aResourceId )
       
  1847 		{
       
  1848 		CleanupStack::PopAndDestroy( label );
       
  1849 		}
       
  1850 	}
       
  1851 
       
  1852 void CVRRecViewModel::ShowNoteL( TInt aResourceId,
       
  1853 								 TAknGlobalNoteType aNoteType )
       
  1854 	{
       
  1855 	HBufC* label = StringLoader::LoadLC( aResourceId );
       
  1856 	iGlobalNote->ShowNoteL( aNoteType, *label );
       
  1857 	CleanupStack::PopAndDestroy( label );
       
  1858 	}
       
  1859 
       
  1860 
       
  1861 // ---------------------------------------------------------------------------
       
  1862 // CVRRecViewModel::GetVolumeControlState
       
  1863 // 
       
  1864 // ---------------------------------------------------------------------------
       
  1865 //
       
  1866 void CVRRecViewModel::GetVolumeControlState( TVRVolumeControlState& aState,
       
  1867 											TInt& aVolume )
       
  1868 	{
       
  1869 	// ignored
       
  1870 	TRAP_IGNORE( ReadDefaultSpeakerL() );
       
  1871 	if ( iState->iHasVolumeControl )
       
  1872 		{
       
  1873 		if ( iIhfState )
       
  1874 			{
       
  1875 			aState = EIhf;
       
  1876 
       
  1877 			}
       
  1878 		else
       
  1879 			{
       
  1880 			aState = EEarPiece;
       
  1881 			}
       
  1882 		aVolume = iIhfVolume;
       
  1883 		}
       
  1884 	else
       
  1885 		{
       
  1886 		aState = EDisabled;
       
  1887 		}
       
  1888 	}
       
  1889 
       
  1890 
       
  1891 // ---------------------------------------------------------------------------
       
  1892 // CVRRecViewModel::LoadVolumeSettingsL
       
  1893 // 
       
  1894 // ---------------------------------------------------------------------------
       
  1895 //
       
  1896 void CVRRecViewModel::LoadVolumeSettingsL()
       
  1897 	{
       
  1898 	iIhfVolume = VRUtils::DefaultVolumeL( ESpeakerIhf );
       
  1899 	// Prevent using incorrect values
       
  1900 	if ( iIhfVolume < KVRVolumeControlMin ||
       
  1901 		iIhfVolume > KVRVolumeControlMax )
       
  1902 		{
       
  1903 		iIhfVolume = KVRDefaultVolume;
       
  1904 		}		
       
  1905 	}
       
  1906 
       
  1907 
       
  1908 // ---------------------------------------------------------------------------
       
  1909 // CVRRecViewModel::SaveVolumeSettings
       
  1910 // 
       
  1911 // ---------------------------------------------------------------------------
       
  1912 //
       
  1913 void CVRRecViewModel::SaveVolumeSettings()
       
  1914 	{
       
  1915 	// Ignore all errors, because this will be called in destructor. It isn't 
       
  1916 	// disastrous if new values aren't saved, the previous values will be there
       
  1917 	TRAP_IGNORE( VRUtils::SetDefaultVolumeL( ESpeakerIhf, iIhfVolume ); );
       
  1918 	}
       
  1919 
       
  1920 
       
  1921 // ---------------------------------------------------------------------------
       
  1922 // CVRRecViewModel::HandleSystemEventL
       
  1923 // 
       
  1924 // ---------------------------------------------------------------------------
       
  1925 //
       
  1926 void CVRRecViewModel::HandleSystemEventL()
       
  1927 	{
       
  1928 	// Fetch the changed value from Pubsub
       
  1929 	TInt currentState( iCurrentCallHandler->StateL(KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1930 
       
  1931 	if ( !iActive )
       
  1932 		{
       
  1933 		iPreviousCallState = currentState;
       
  1934 		return;
       
  1935 		}
       
  1936 
       
  1937 
       
  1938 	// Actions to take when playing
       
  1939 	if ( iState->iId == EStatePlaying )
       
  1940 		{
       
  1941 		switch ( currentState )
       
  1942 			{
       
  1943 			case EPSCTsyCallStateAlerting:
       
  1944 			case EPSCTsyCallStateRinging:
       
  1945 			case EPSCTsyCallStateAnswering:
       
  1946 				{
       
  1947 				HandleCommandL( ECmdAutoStopAtEnd );
       
  1948 				break;
       
  1949 				}
       
  1950 			default:
       
  1951 				{
       
  1952 				break;
       
  1953 				}
       
  1954 			}			
       
  1955 		}
       
  1956 
       
  1957 	// Actions to take when recording
       
  1958 	if ( iState->iId == EStateRecording )
       
  1959 		{
       
  1960 		switch ( currentState )
       
  1961 			{
       
  1962 			case EPSCTsyCallStateAlerting:
       
  1963 			case EPSCTsyCallStateRinging:
       
  1964 			case EPSCTsyCallStateAnswering:
       
  1965 			case EPSCTsyCallStateDisconnecting:
       
  1966 				{
       
  1967 				HandleCommandL( ECmdAutoStopAtEnd );
       
  1968 				break;
       
  1969 				}
       
  1970 			case EPSCTsyCallStateNone:
       
  1971 				{
       
  1972 				if( iPreviousCallState == EPSCTsyCallStateConnected )
       
  1973 					{
       
  1974 					CVRMdaRecorder* iRecorderUtility = NULL;
       
  1975 					iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);
       
  1976 					if(iRecorderUtility != NULL)
       
  1977 						{
       
  1978 						iRecorderUtility->SetAudioInputL(CAudioInput::EDefaultMic);					
       
  1979 						}
       
  1980 					HandleCommandL( ECmdAutoStopAtEnd );
       
  1981 					}
       
  1982 				break;										
       
  1983 				}
       
  1984 			default:
       
  1985 				{
       
  1986 				break;
       
  1987 				}
       
  1988 			}			
       
  1989 		}		
       
  1990 
       
  1991 	if ( iState->iId == EStateIdle && 
       
  1992 		 currentState == EPSCTsyCallStateNone )
       
  1993 		{
       
  1994 		iIhfState = ETrue;
       
  1995 		}
       
  1996 
       
  1997 	/* -------------------------
       
  1998 	 * Disable in-call recording
       
  1999 	 * -------------------------
       
  2000 	 */
       
  2001 	if ( iVRAllowInCallRecording != KAllowInCallRecording )
       
  2002 		{
       
  2003 		if (( iState->iId == EStateIdle || iState->iId == EStateDeleted ) &&
       
  2004 			 currentState == EPSCTsyCallStateAnswering)
       
  2005 			{
       
  2006 			// Disable record button
       
  2007 			ChangeState( EStateDisableButtons, ETrue );
       
  2008 			}
       
  2009 		if (( iState->iId == EStateDisableButtons ) &&
       
  2010 			 ((currentState == EPSCTsyCallStateDisconnecting)|| (currentState == EPSCTsyCallStateNone)))
       
  2011 			{
       
  2012 			if (iContext != EContextRecordNewForRemote)
       
  2013 				{
       
  2014 			// Enable record button
       
  2015 			ChangeState( EStateDeleted, ETrue );
       
  2016 				}
       
  2017 		     else
       
  2018 		        {
       
  2019 		        if (!(iMemo->Duration() > TTimeIntervalMicroSeconds(0)))
       
  2020 		        	{
       
  2021 		        	ChangeState( EStateRecordEmbedded, ETrue );
       
  2022 		        	}
       
  2023 		        else
       
  2024 		        	{
       
  2025 		        	ChangeState( EStateIdleRecordEmbedded, ETrue );
       
  2026 		        	}
       
  2027 		        }
       
  2028 			}
       
  2029 		}
       
  2030 		
       
  2031 	iPreviousCallState = currentState;
       
  2032 	}
       
  2033 
       
  2034 
       
  2035 // ---------------------------------------------------------------------------
       
  2036 // CVRRecViewModel::SetIHFIfCallNotActive
       
  2037 // 
       
  2038 // ---------------------------------------------------------------------------
       
  2039 //
       
  2040 void CVRRecViewModel::SetIHFIfCallNotActive( TBool aIhf )
       
  2041 	{
       
  2042 	if ( FeatureManager::FeatureSupported( 
       
  2043 							KFeatureIdApplicationControllableAudioRouting ) )
       
  2044 		{
       
  2045 		TInt currentState( EPSCTsyCallStateNone );
       
  2046         // Ignore the error, ihf is not set
       
  2047 		TRAP_IGNORE( currentState = iCurrentCallHandler->StateL( 
       
  2048 									KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  2049 
       
  2050 		if ( currentState == EPSCTsyCallStateNone )
       
  2051 			{
       
  2052 			if ( iRecorder->SetIhf( aIhf ) == KErrNone )
       
  2053 				{
       
  2054 				// So that the model knows that the next notify from shared 
       
  2055 				// data client is not a voice key activated IHF change.
       
  2056 				iIgnoreNextIhfChange = ETrue;
       
  2057 				}
       
  2058 			}
       
  2059 		}
       
  2060 	}
       
  2061 
       
  2062 
       
  2063 // ---------------------------------------------------------------------------
       
  2064 // CVRRecViewModel::CheckIhfState
       
  2065 // 
       
  2066 // ---------------------------------------------------------------------------
       
  2067 //
       
  2068 void CVRRecViewModel::CheckIhfState()
       
  2069 	{
       
  2070 	if ( FeatureManager::FeatureSupported( KFeatureIdKeypadNoVoiceKey ) &&
       
  2071 		FeatureManager::FeatureSupported( 
       
  2072 							KFeatureIdApplicationControllableAudioRouting ) )
       
  2073 		{
       
  2074 		if ( iDefaultSpeaker == ESpeakerIhf )
       
  2075 			{
       
  2076 			iIhfState = ETrue;
       
  2077 			}
       
  2078 		else
       
  2079 			{
       
  2080 			iIhfState = EFalse;
       
  2081 			}
       
  2082 		}
       
  2083 	else
       
  2084 		{
       
  2085 		// IHF is default on phones with voice key
       
  2086 		iIhfState = ETrue;
       
  2087 		}
       
  2088 	}
       
  2089 
       
  2090 
       
  2091 // ---------------------------------------------------------------------------
       
  2092 // CVRRecViewModel::SetRecorderVolume
       
  2093 // 
       
  2094 // ---------------------------------------------------------------------------
       
  2095 //
       
  2096 void CVRRecViewModel::SetRecorderVolume()
       
  2097 	{
       
  2098 	TInt activeVolume = iIhfVolume;
       
  2099 	iRecorder->SetVolume( activeVolume, KVRMaxVolumeSteps );
       
  2100 	}
       
  2101 
       
  2102 
       
  2103 // ---------------------------------------------------------------------------
       
  2104 // CVRRecViewModel::ActivateL
       
  2105 // 
       
  2106 // ---------------------------------------------------------------------------
       
  2107 //
       
  2108 void CVRRecViewModel::ActivateL()
       
  2109 	{
       
  2110 	iActive = ETrue;
       
  2111 
       
  2112 	if ( FeatureManager::FeatureSupported( KFeatureIdKeypadNoVoiceKey ) &&
       
  2113 		FeatureManager::FeatureSupported( 
       
  2114 				KFeatureIdApplicationControllableAudioRouting ) )
       
  2115 		{
       
  2116 		// The user has visited another view and possibly altered the
       
  2117 		// settings
       
  2118 		ReadDefaultSpeakerL();
       
  2119 		}
       
  2120 
       
  2121 	// If the in-call disable recording feature has been enabled, then check 
       
  2122 	// current status and enable/disable UI accordingly
       
  2123 	if ( iVRAllowInCallRecording != KAllowInCallRecording )
       
  2124 		{
       
  2125 		TInt currentState( iCurrentCallHandler->StateL(
       
  2126 			KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  2127 		if ( currentState != EPSCTsyCallStateNone )
       
  2128 			{
       
  2129 			ChangeState (EStateDisableButtons, ETrue);
       
  2130 			}
       
  2131         }
       
  2132 	}
       
  2133 
       
  2134 
       
  2135 // ---------------------------------------------------------------------------
       
  2136 // CVRRecViewModel::Deactivate
       
  2137 // 
       
  2138 // ---------------------------------------------------------------------------
       
  2139 //
       
  2140 void CVRRecViewModel::Deactivate()
       
  2141 	{
       
  2142 	iActive = EFalse;
       
  2143 	}
       
  2144 
       
  2145 // ---------------------------------------------------------------------------
       
  2146 // CVRRecViewModel::ReadDefaultSpeakerL
       
  2147 // 
       
  2148 // ---------------------------------------------------------------------------
       
  2149 //
       
  2150 void CVRRecViewModel::ReadDefaultSpeakerL()
       
  2151 	{
       
  2152 	iDefaultSpeaker = VRUtils::DefaultSpeakerL();
       
  2153 
       
  2154 	if ( iDefaultSpeaker == ESpeakerIhf )
       
  2155 		{
       
  2156 		iIhfState = ETrue;
       
  2157 		}
       
  2158 	else
       
  2159 		{
       
  2160 		iIhfState = EFalse;
       
  2161 		}
       
  2162 	}
       
  2163 
       
  2164 
       
  2165 // ---------------------------------------------------------------------------
       
  2166 // CVRRecViewModel::TVRLabelLayoutLink::ReadFromResource
       
  2167 // 
       
  2168 // ---------------------------------------------------------------------------
       
  2169 //
       
  2170 void CVRRecViewModel::TVRLabelLayoutLink::ReadFromResource
       
  2171 										( TResourceReader& aReader )
       
  2172 	{
       
  2173 	iEuroId = aReader.ReadUint32();
       
  2174 	iApacId = aReader.ReadUint32();
       
  2175 	iArabicHebrewId = aReader.ReadUint32();
       
  2176 	}
       
  2177 
       
  2178 
       
  2179 // ---------------------------------------------------------------------------
       
  2180 // CVRRecViewModel::CanSetVolume
       
  2181 // 
       
  2182 // ---------------------------------------------------------------------------
       
  2183 //
       
  2184 TBool CVRRecViewModel::CanSetVolume()
       
  2185 	{
       
  2186 	return ETrue;
       
  2187 	}
       
  2188 
       
  2189 
       
  2190 // ---------------------------------------------------------------------------
       
  2191 // CVRRecViewModel::HandleUpdateErrorL
       
  2192 // 
       
  2193 // ---------------------------------------------------------------------------
       
  2194 //
       
  2195 void CVRRecViewModel::HandleUpdateErrorL( TInt aErr )
       
  2196 	{
       
  2197 	// Show error note.
       
  2198 	if ( aErr == KErrDiskFull )
       
  2199 		{
       
  2200 
       
  2201 #ifndef RD_MULTIPLE_DRIVE    
       
  2202 		if ( VRUtils::MemoStoreL() == EMemoStorePhoneMemory )
       
  2203 			{
       
  2204 			ShowNoteL( R_VR_MEMORY_WARNING, EAknGlobalWarningNote );
       
  2205 			}
       
  2206 		else
       
  2207 			{
       
  2208 			ShowNoteL( R_VR_MEMORY_MMC_WARNING, EAknGlobalWarningNote );
       
  2209 			}
       
  2210 			
       
  2211 //multiple drive
       
  2212 #else
       
  2213 		TInt memoDrive = VRUtils::MemoDriveL();
       
  2214 		TUint status( 0 );
       
  2215 		VRUtils::GetDriveInfo( memoDrive, status );
       
  2216 		        
       
  2217 		if ( status & DriveInfo::EDriveInternal )
       
  2218 		    {
       
  2219 			ShowNoteL( R_VR_MEMORY_WARNING, EAknGlobalWarningNote );
       
  2220 			}
       
  2221 		else
       
  2222 			{
       
  2223 			ShowNoteL( R_VR_MEMORY_MMC_WARNING, EAknGlobalWarningNote );
       
  2224 			}
       
  2225 #endif
       
  2226 
       
  2227 
       
  2228 		}
       
  2229 	}
       
  2230 
       
  2231 
       
  2232 // ---------------------------------------------------------------------------
       
  2233 // CVRRecViewModel::MemoFileHandle
       
  2234 // 
       
  2235 // ---------------------------------------------------------------------------
       
  2236 //
       
  2237 RFile& CVRRecViewModel::MemoFileHandle()
       
  2238 	{
       
  2239 	return iMemo->File();
       
  2240 	}
       
  2241 
       
  2242 
       
  2243 // ---------------------------------------------------------------------------
       
  2244 // CVRRecViewModel::SetFileHandle
       
  2245 // 
       
  2246 // ---------------------------------------------------------------------------
       
  2247 //	
       
  2248 void CVRRecViewModel::SetFileHandle( RFile& aFile )
       
  2249 	{
       
  2250 	// Use app startup type as embbedding flag
       
  2251 	iMemo->SetFileHandle( aFile, CEikonEnv::Static()->StartedAsServerApp() );
       
  2252 	if ( iRecorder )
       
  2253 		{
       
  2254 		// First detach if already attached
       
  2255 		iRecorder->DetachMemo();
       
  2256 		// The media server error will rise again somewhere where it's
       
  2257 		// easier to handle if needed
       
  2258 		TRAP_IGNORE( iRecorder->AttachToMemoL( iMemo ) );		
       
  2259 		}
       
  2260 
       
  2261 	}	
       
  2262 
       
  2263 
       
  2264 // ---------------------------------------------------------------------------
       
  2265 // CVRRecViewModel::FormatTimeL
       
  2266 // 
       
  2267 // ---------------------------------------------------------------------------
       
  2268 //
       
  2269 void CVRRecViewModel::FormatTimeL( const TTime& aTime, TDes& aString ) const
       
  2270 	{
       
  2271 
       
  2272 	// Show longer format if duration more than 1 hour
       
  2273 	if ( aTime.DateTime().Hour() >= 1 )
       
  2274 		{
       
  2275 		aTime.FormatL( aString,
       
  2276 			  iTimeDuratLong );						
       
  2277 		}
       
  2278 	else
       
  2279 		{
       
  2280 		aTime.FormatL( aString,
       
  2281 			  iTimeDuratMinSecWithZero );						
       
  2282 		}	
       
  2283 	}
       
  2284 
       
  2285 // ---------------------------------------------------------------------------
       
  2286 // CVRRecViewModel::EnableVolumeControl
       
  2287 // Enables/Disables the navi pane Volume Control drawing in the VR current 
       
  2288 // visual state
       
  2289 // ---------------------------------------------------------------------------
       
  2290 //	
       
  2291 void CVRRecViewModel::EnableVolumeControl( TBool aVolumeControl )
       
  2292 	{
       
  2293 	iState->iHasVolumeControl = aVolumeControl;
       
  2294 	}
       
  2295 
       
  2296 // ---------------------------------------------------------------------------
       
  2297 // CVRRecViewModel::HasVolumeControl
       
  2298 // Returns ETrue if volume setting is enabled in this VoiceRecorder state.
       
  2299 // Otherwise returns EFalse
       
  2300 // ---------------------------------------------------------------------------
       
  2301 //
       
  2302 TBool CVRRecViewModel::HasVolumeControl() const
       
  2303 	{
       
  2304 	if( iState->iHasVolumeControl )
       
  2305 		{
       
  2306 		return ETrue;
       
  2307 		}
       
  2308 	return EFalse;	
       
  2309 	}
       
  2310 
       
  2311 
       
  2312 // ---------------------------------------------------------------------------
       
  2313 // CVRRecViewModel::IncomingCall
       
  2314 // Returns ETrue if a phone call is coming.
       
  2315 // Otherwise returns EFalse
       
  2316 // ---------------------------------------------------------------------------
       
  2317 //
       
  2318 TBool CVRRecViewModel::IncomingCall() const
       
  2319 	{
       
  2320 #ifdef _DEBUG
       
  2321 	RDebug::Print( _L("CVRRecViewModel::IncomingCall enter") );
       
  2322 #endif	
       
  2323 	
       
  2324 	// Fetch the current value from Pubsub
       
  2325 	TInt currentState = 0;
       
  2326 	TRAP_IGNORE(currentState = iCurrentCallHandler->StateL( KPSUidCtsyCallInformation, KCTsyCallState ));
       
  2327 	
       
  2328 	if (currentState == EPSCTsyCallStateAlerting ||
       
  2329 		currentState == EPSCTsyCallStateRinging ||
       
  2330 		currentState == EPSCTsyCallStateAnswering )
       
  2331 		{
       
  2332 		return ETrue;
       
  2333 		}
       
  2334 	else
       
  2335 		{
       
  2336 		return EFalse;	
       
  2337 		}	
       
  2338 	}
       
  2339 
       
  2340 
       
  2341 // ---------------------------------------------------------------------------
       
  2342 //Returns the active quality setting.
       
  2343 //return Quality setting of the active memo
       
  2344 // ---------------------------------------------------------------------------
       
  2345 TVRQuality CVRRecViewModel::Quality() const
       
  2346 	{
       
  2347 		return iMemo->Quality();
       
  2348 	}
       
  2349 
       
  2350 
       
  2351 // ---------------------------------------------------------
       
  2352 // GetInRecordingFlag
       
  2353 // 
       
  2354 // ---------------------------------------------------------
       
  2355 //		
       
  2356 TBool CVRRecViewModel::GetInRecordingFlag()
       
  2357 	{
       
  2358 	if(iRecorder)
       
  2359 		{
       
  2360 		CVRMdaRecorder* iRecorderUtility = NULL;
       
  2361 		iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);	
       
  2362 		if(iRecorderUtility != NULL)
       
  2363 			{
       
  2364 			return iRecorderUtility->GetInRecordingFlag();
       
  2365 			}
       
  2366 		return EFalse;
       
  2367 		}
       
  2368 	else
       
  2369 		{
       
  2370 		return EFalse;
       
  2371 		}
       
  2372 		
       
  2373 	}
       
  2374 	
       
  2375 
       
  2376 // ---------------------------------------------------------
       
  2377 // GetIfStopCalled
       
  2378 // 
       
  2379 // ---------------------------------------------------------
       
  2380 //		
       
  2381 TBool CVRRecViewModel::GetIfStopCalled()
       
  2382 	{
       
  2383 	if(iRecorder)
       
  2384 		{
       
  2385 		CVRMdaRecorder* iRecorderUtility = NULL;
       
  2386 		iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);	
       
  2387 		if(iRecorderUtility != NULL)
       
  2388 			{
       
  2389 			return iRecorderUtility->GetIfStopCalled();
       
  2390 			}
       
  2391 		return EFalse;
       
  2392 		}
       
  2393 	else
       
  2394 		{
       
  2395 		return EFalse;
       
  2396 		}
       
  2397 		
       
  2398 	}
       
  2399 
       
  2400 	
       
  2401 // ---------------------------------------------------------
       
  2402 // SetInRecordingFlag
       
  2403 // ---------------------------------------------------------
       
  2404 //
       
  2405 void CVRRecViewModel::SetInRecordingFlag(TBool aFlag)
       
  2406 	{
       
  2407 	if(iRecorder)
       
  2408 		{
       
  2409 		CVRMdaRecorder* iRecorderUtility = NULL;
       
  2410 		iRecorderUtility = dynamic_cast<CVRMdaRecorder*>(iRecorder);	
       
  2411 		if(iRecorderUtility != NULL)
       
  2412 			{
       
  2413 			return iRecorderUtility->SetInRecordingFlag(aFlag);
       
  2414 			}		
       
  2415 		}
       
  2416 	}
       
  2417 
       
  2418 
       
  2419 
       
  2420 
       
  2421 // ---------------------------------------------------------------------------
       
  2422 // CVRRecViewModel::HandleMMCEjectEventL
       
  2423 // 
       
  2424 // ---------------------------------------------------------------------------
       
  2425 //
       
  2426 void CVRRecViewModel::HandleMMCEjectEventL()
       
  2427 	{
       
  2428 	
       
  2429 	// Actions to take when recording
       
  2430 	TInt storageDrive = VRUtils::MemoDriveL();   	 
       
  2431     if ( ( ( storageDrive == VRUtils::GetRemovableMassStorageL()) ||
       
  2432             ( iMemo != NULL && iMemo->StorageDrive() == VRUtils::GetRemovableMassStorageL() ) ) && 
       
  2433             ( !CVRUSBStateHanlder::IsUsbActive() ) )
       
  2434 		{
       
  2435         //exit for mmc dismount	
       
  2436         SendExitEvent();   
       
  2437 		}
       
  2438     }
       
  2439 
       
  2440 // ---------------------------------------------------------------------------
       
  2441 // CVRRecViewModel::SendExitEvent
       
  2442 // 
       
  2443 // ---------------------------------------------------------------------------
       
  2444 //
       
  2445 void CVRRecViewModel::SendExitEvent()
       
  2446     {
       
  2447     TWsEvent event;
       
  2448     event.SetType( EAknSoftkeyExit );
       
  2449     event.SetTimeNow();
       
  2450     event.SetHandle( CCoeEnv::Static()->WsSession().WsHandle() );
       
  2451     CCoeEnv::Static()->WsSession().SendEventToWindowGroup( CEikonEnv::Static()->RootWin().Identifier(), event );
       
  2452     return;
       
  2453     }
       
  2454 
       
  2455 // ---------------------------------------------------------------------------
       
  2456 // CVRRecViewModel::SetIsDriveReady
       
  2457 // 
       
  2458 // ---------------------------------------------------------------------------
       
  2459 //
       
  2460 void CVRRecViewModel::SetIsDriveReady(TBool aIsDriveReady)
       
  2461     {
       
  2462     iIsDriveReady = aIsDriveReady;
       
  2463     }
       
  2464 
       
  2465 // ---------------------------------------------------------------------------
       
  2466 // CVRRecViewModel::GetIsDriveReady
       
  2467 // 
       
  2468 // ---------------------------------------------------------------------------
       
  2469 //
       
  2470 TBool CVRRecViewModel::GetIsDriveReady()
       
  2471     {
       
  2472     return iIsDriveReady;
       
  2473     }
       
  2474 
       
  2475 
       
  2476 // End of file