voicerecorder/AppSrc/CVRAppUI.cpp
changeset 0 845549f293a7
child 5 35a9006a7fc7
equal deleted inserted replaced
-1:000000000000 0:845549f293a7
       
     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 a part of the standard application framework.
       
    16  *     It instantiates the application views.
       
    17  *     It also acts as the default command handler for the application.
       
    18  *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 #include <ErrorUI.h>
       
    24 #include <coeutils.h>
       
    25 
       
    26 #include <AknDef.h> // For layout change event definitions
       
    27 
       
    28 #include "CVRRecView.h"
       
    29 #include "MVRSelectionProvider.h"
       
    30 #include "CVRAppUi.h"
       
    31 #include "CVRDocument.h"
       
    32 #include <featmgr.h>
       
    33 #include "VRConsts.h"
       
    34 
       
    35 #include <VoiceRecorderUID.h>
       
    36 #include <voicerecorder.rsg>
       
    37 #include "voicerecorder.hrh"
       
    38 #include "VRUtils.h"
       
    39 #include "CVRSettingsDialog.h"
       
    40 #include <hlplch.h>
       
    41 #include <AknsConstants.h>
       
    42 #include <aknnotewrappers.h>
       
    43 #include <csxhelp/vorec.hlp.hrh>
       
    44 #include <aknradiobuttonsettingpage.h>
       
    45 #include <CNewFileServiceBase.h>
       
    46 #include <e32property.h> 
       
    47 #include <UsbWatcherInternalPSKeys.h>
       
    48 #include <usbpersonalityids.h>
       
    49 #ifdef RD_MULTIPLE_DRIVE
       
    50 #include <driveinfo.h>
       
    51 #endif
       
    52 
       
    53 _LIT( KVRCommandRecord, "record" );
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CVRAppUi::CVRAppUi
       
    57 // 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CVRAppUi::CVRAppUi()
       
    61 	{
       
    62 	}
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CVRAppUi::~CVRAppUi
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CVRAppUi::~CVRAppUi()
       
    71     {
       
    72     if ( iActiveWait.IsStarted() )
       
    73     	{
       
    74     	iActiveWait.AsyncStop();
       
    75     	}
       
    76     
       
    77     if ( iDoorObserver )
       
    78          {
       
    79          iDoorObserver->NotifyExit( MApaEmbeddedDocObserver::EEmpty );
       
    80          }
       
    81 
       
    82 	delete iErrorUI;
       
    83 	FeatureManager::UnInitializeLib();
       
    84 	}
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 //CVRAppUi::ConstructL
       
    88 // 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CVRAppUi::ConstructL()
       
    92     {
       
    93     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
       
    94 
       
    95 	iErrorUI = CErrorUI::NewL();
       
    96 
       
    97 	// Exit if video or voip call is ongoing
       
    98 	if ( VRUtils::UnsupportedCallTypeOngoing( ETrue ) )
       
    99 		{
       
   100 		Exit();
       
   101 		}
       
   102 
       
   103 	FeatureManager::InitializeLibL();
       
   104 
       
   105 	if ( FeatureManager::FeatureSupported( KFeatureIdMmc ) )
       
   106 		{
       
   107 
       
   108 #ifndef RD_MULTIPLE_DRIVE
       
   109 		TVRDriveInfo mmcInfo;
       
   110 		VRUtils::GetMMCInfo( mmcInfo );
       
   111 		TVRMemoStore memoStore = VRUtils::MemoStoreL();
       
   112 
       
   113 		if ( memoStore == EMemoStoreMMC )
       
   114 			{
       
   115             // check if USB is connected, if so, then need to switch to phone memory
       
   116 			if (IsUsbActive())
       
   117 				{
       
   118 				HBufC* noteText = iCoeEnv->AllocReadResourceLC(
       
   119 														 R_QTN_MEMC_VOREC_NOTE1 );
       
   120 				CAknInformationNote* infoNote =
       
   121 									   new( ELeave ) CAknInformationNote( ETrue );
       
   122 				infoNote->ExecuteLD( *noteText );
       
   123 				CleanupStack::PopAndDestroy( noteText );
       
   124 				VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );				
       
   125 				}
       
   126 
       
   127 			// MMC not available or locked
       
   128 			else if ( memoStore && ( mmcInfo.iDriveLocked || !mmcInfo.iDrivePresent ) )
       
   129 				{
       
   130 				HBufC* noteText = iCoeEnv->AllocReadResourceLC(
       
   131 														 R_QTN_MEMC_VOREC_NOTE1 );
       
   132 				CAknInformationNote* infoNote =
       
   133 									   new( ELeave ) CAknInformationNote( ETrue );
       
   134 				infoNote->ExecuteLD( *noteText );
       
   135 				CleanupStack::PopAndDestroy( noteText );
       
   136 				VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );
       
   137 				}
       
   138 			else if ( mmcInfo.iDriveReadOnly )
       
   139 				{
       
   140 				HBufC* noteText = iCoeEnv->AllocReadResourceLC(
       
   141 														 R_QTN_MEMC_VOREC_NOTE2 );
       
   142 				CAknInformationNote* infoNote =
       
   143 									   new( ELeave ) CAknInformationNote( ETrue );
       
   144 				infoNote->ExecuteLD( *noteText );
       
   145 				CleanupStack::PopAndDestroy( noteText );				
       
   146 				VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );
       
   147 				}
       
   148 			else if ( mmcInfo.iDriveCorrupted )
       
   149 				{
       
   150 				// MMC corrupted -> use phone memory
       
   151 				VRUtils::SetMemoStoreL( EMemoStorePhoneMemory );
       
   152 				}
       
   153 			
       
   154 			}
       
   155 // for multiple drives
       
   156 #else
       
   157 		TInt memoDrive = VRUtils::MemoDriveL();
       
   158         TInt defaultDrive = VRUtils::DefaultMemoDriveL();
       
   159  
       
   160         //not default phone memory
       
   161 		if ( memoDrive != defaultDrive )
       
   162 			{
       
   163              // check if USB is connected, if so, then need to switch to phone memory
       
   164 			if (IsUsbActive())
       
   165 				{
       
   166 				HBufC* noteText = iCoeEnv->AllocReadResourceLC(
       
   167 														 R_QTN_MEMC_VOREC_NOTE1 );
       
   168 				CAknInformationNote* infoNote =
       
   169 									   new( ELeave ) CAknInformationNote( ETrue );
       
   170 				infoNote->ExecuteLD( *noteText );
       
   171 				CleanupStack::PopAndDestroy( noteText );
       
   172 				VRUtils::SetMemoDriveL((TDriveNumber)defaultDrive );
       
   173 				}
       
   174 			else
       
   175 				{
       
   176             	TUint status( 0 );
       
   177 	        	VRUtils::GetDriveInfo(memoDrive, status);
       
   178 				
       
   179 				// Drive not available or locked
       
   180 				if ((status & DriveInfo::EDriveLocked) || !(status & DriveInfo::EDrivePresent))
       
   181 			    	{
       
   182 			    	HBufC* noteText = iCoeEnv->AllocReadResourceLC(R_QTN_MEMC_VOREC_NOTE1 );
       
   183 					CAknInformationNote* infoNote = new( ELeave ) CAknInformationNote( ETrue );
       
   184 					infoNote->ExecuteLD( *noteText );
       
   185 					CleanupStack::PopAndDestroy( noteText );
       
   186 					VRUtils::SetMemoDriveL((TDriveNumber)defaultDrive );
       
   187 					}
       
   188 				else if ( status & DriveInfo::EDriveReadOnly )
       
   189 			    	{
       
   190 			    	HBufC* noteText = iCoeEnv->AllocReadResourceLC(R_QTN_MEMC_VOREC_NOTE2 );
       
   191 					CAknInformationNote* infoNote = new( ELeave ) CAknInformationNote( ETrue );
       
   192 					infoNote->ExecuteLD( *noteText );
       
   193 					CleanupStack::PopAndDestroy( noteText );				
       
   194 					VRUtils::SetMemoDriveL((TDriveNumber)defaultDrive );
       
   195 					}
       
   196 		    	else if ( status & DriveInfo::EDriveCorrupt )
       
   197 			    	{
       
   198 			    	// Drive corrupted -> use phone memory
       
   199 			    	VRUtils::SetMemoDriveL((TDriveNumber)defaultDrive );
       
   200 			    	}
       
   201 				}
       
   202 			}
       
   203 
       
   204 
       
   205 #endif
       
   206 
       
   207 		}
       
   208 
       
   209 	CVRRecView* view = CVRRecView::NewLC(
       
   210 									R_VR_RECORDER_VIEW, R_VR_RECVIEW_STATES );
       
   211 
       
   212 	AddViewL( view );
       
   213 	iLayoutChangeObserver = view;
       
   214 	CleanupStack::Pop( view );
       
   215 
       
   216 	SetDefaultViewL( *view );
       
   217 
       
   218     // Activate view straight away, if started through new file service	
       
   219 	if ( iEikonEnv->StartedAsServerApp() )
       
   220 		{
       
   221     	ActivateLocalViewL( TUid::Uid( KVRRecorderViewUID ),
       
   222         	TUid::Uid( EContextRecordNewForRemote ), KNullDesC8 );        	
       
   223 		}        
       
   224 
       
   225 	}
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CVRAppUi::HandleCommandL
       
   229 // 
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CVRAppUi::HandleCommandL( TInt aCommand )
       
   233     {
       
   234 	switch ( aCommand )
       
   235         {
       
   236 		case EAknSoftkeyExit:	// Fall through
       
   237 			{
       
   238 			if ( iView )
       
   239 				{
       
   240 				iView->HandleCommandL( ECmdCancelNote );				
       
   241 				}
       
   242             Exit();
       
   243 			break;
       
   244 			}
       
   245         case EEikCmdExit:
       
   246 		   	{
       
   247 			if ( iView )
       
   248 				{
       
   249 				iView->HandleCommandL( ECmdCancelNote );				
       
   250 				}
       
   251 
       
   252 			// The file service needs to abort if it's still going on
       
   253 			if ( iEmbeddedObserver )
       
   254 				{
       
   255 				dynamic_cast<CNewFileServiceBase*>(iEmbeddedObserver)->SetErrorCode(KErrAbort);
       
   256 				iEmbeddedObserver->AbortL();
       
   257 				}
       
   258 
       
   259             Exit();
       
   260 			break;
       
   261             }
       
   262 		case EAknCmdExit:
       
   263 			{
       
   264 			if ( iView )
       
   265 				{
       
   266 				iView->HandleCommandL( ECmdCancelNote );				
       
   267 				}
       
   268 
       
   269 			// The file service needs to abort if it's still going on
       
   270 			if ( iEmbeddedObserver )
       
   271 				{
       
   272 				dynamic_cast<CNewFileServiceBase*>(iEmbeddedObserver)->SetErrorCode(KErrAbort);
       
   273 				iEmbeddedObserver->AbortL();
       
   274 				}
       
   275 			
       
   276 			Exit();
       
   277             break;
       
   278 			}
       
   279 		case ECmdHelp:
       
   280 			{
       
   281 			if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   282 				{
       
   283 				if ( iIsSettingsOpen )
       
   284 					{
       
   285 					CArrayFix<TCoeHelpContext>* contexts = AppHelpContextL();
       
   286 					contexts->At(0).iContext = KVOREC_HLP_SETTINGS;
       
   287 					HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   288 													contexts );
       
   289 					}
       
   290 				else
       
   291 					{
       
   292 					HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   293 													AppHelpContextL() );
       
   294 					}
       
   295 				}
       
   296 			break;
       
   297 			}
       
   298 		case ECmdSettings:
       
   299 			{
       
   300 			if ( FeatureManager::FeatureSupported( KFeatureIdMmc ) ||
       
   301                  VRUtils::FeatureEnabled( EVRFeatureShowQualitySetting ) )
       
   302 				{
       
   303 				iIsSettingsOpen = ETrue;
       
   304 				CVRSettingsDialog* settingsDlg = CVRSettingsDialog::NewL();
       
   305 				settingsDlg->ExecuteLD( R_VR_SETTINGS_DIALOG );
       
   306 				iIsSettingsOpen = EFalse;
       
   307 				}
       
   308 			break;
       
   309 			}
       
   310        	case ECmdNewFileServiceNotify:
       
   311    			{
       
   312 			if ( iActiveWait.IsStarted() )
       
   313 				{
       
   314 				iActiveWait.AsyncStop();
       
   315 				}
       
   316 			break;
       
   317    			}
       
   318        	case ECmdEmbeddedRecordingReady:
       
   319    			{
       
   320    			if ( iEmbeddedObserver )
       
   321    				{
       
   322    				TBool canExit( ETrue );
       
   323    				
       
   324 				TVRSelectionStyle selStyle;
       
   325 				TPtrC memoFile( SelectionProviderL()->
       
   326 								GetSelectedFilesLC( selStyle )->
       
   327 								MdcaPoint( 0 ) );
       
   328 				if ( memoFile.Length() > 0 )
       
   329 					{   		
       
   330 					TFileName myFilename( memoFile );
       
   331 					canExit = iEmbeddedObserver->FileCompleteL( myFilename );
       
   332 					}
       
   333 
       
   334 				// destroy array from GetSelectedFilesLC()
       
   335 				CleanupStack::PopAndDestroy();
       
   336 
       
   337 				if ( canExit )
       
   338 					{
       
   339 					HandleCommandL( EEikCmdExit );
       
   340 					}
       
   341 				else
       
   342 					{
       
   343 					// Wait until file service has completed
       
   344 					// transfering filename array back to client
       
   345 					if( !iActiveWait.IsStarted() )
       
   346 					    {
       
   347 					    iActiveWait.Start(); // CSI: 10 #
       
   348 					    }
       
   349 					}
       
   350    				}
       
   351 			break;
       
   352   			}
       
   353        	
       
   354         default:
       
   355 			{
       
   356 			break;
       
   357 			}
       
   358         }
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CVRAppUi::SelectionProviderL
       
   363 // 
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 MVRSelectionProvider* CVRAppUi::SelectionProviderL()
       
   367 	{
       
   368     return reinterpret_cast< CVRRecView* >( iView );
       
   369 	}
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CVRAppUi::HandleResourceChangeL
       
   373 // 
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 void CVRAppUi::HandleResourceChangeL( TInt aType )
       
   377 	{
       
   378 	CAknViewAppUi::HandleResourceChangeL( aType );
       
   379 
       
   380 	if ( aType == KEikDynamicLayoutVariantSwitch ||
       
   381 		 aType == KAknsMessageSkinChange )
       
   382 		{
       
   383 		iLayoutChangeObserver->LayoutChangedL( aType );
       
   384 		}
       
   385 	}
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // CVRAppUi::RecordNewFileL
       
   389 // 
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CVRAppUi::RecordNewFileL( RFile& aFile, MVREmbeddedObserver* aObserver )
       
   393 	{
       
   394 	if ( aObserver )
       
   395 		{
       
   396 		iEmbeddedObserver = aObserver;
       
   397 
       
   398 		if ( aFile.SubSessionHandle() != 0)
       
   399 			{
       
   400 			// Pass file handle to recview
       
   401 			SelectionProviderL()->SetFileHandle( aFile );
       
   402 			}				
       
   403 		}
       
   404 	}
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // CVRAppUi::ProcessCommandParametersL
       
   408 // 
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 TBool CVRAppUi::ProcessCommandParametersL( TApaCommand /*aCommand*/,
       
   412     TFileName& aDocumentName, const TDesC8& aTail )
       
   413     {
       
   414 
       
   415 	// Check if we got "-record" as command line parameter
       
   416 	// convert 8-bit descriptor to a 16-bit one without altering data.
       
   417 	const TUint16* ptr16 = reinterpret_cast< const TUint16* >(
       
   418 												   aTail.Ptr() );
       
   419 	TPtrC16 tail( ptr16, aTail.Size() >> 1);	
       
   420 
       
   421 	if ( aDocumentName.Compare( KVRCommandRecord ) == 0
       
   422 		|| tail.Compare( KVRCommandRecord ) == 0 )
       
   423 		{
       
   424 		// Enter recording context
       
   425 		ActivateLocalViewL( TUid::Uid( KVRRecorderViewUID ),
       
   426 				TUid::Uid( EContextRecordNewNormal ), KNullDesC8 );
       
   427 		return EFalse;
       
   428 		}
       
   429     else // No record parameter, start normally
       
   430         {
       
   431     	ActivateLocalViewL( TUid::Uid( KVRRecorderViewUID ),
       
   432 	    	TUid::Uid( EContextEmptyNormal ), KNullDesC8 );        
       
   433         }
       
   434         
       
   435 	if ( !ConeUtils::FileExists( aDocumentName ) )
       
   436 		{
       
   437 		aDocumentName.Copy( aTail );
       
   438 		}		
       
   439 	return ConeUtils::FileExists( aDocumentName );
       
   440     }
       
   441 
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // CVRAppUi::SetEmbeddedObserver
       
   445 // 
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CVRAppUi::SetEmbeddedObserver( MVREmbeddedObserver* aObserver )
       
   449     {
       
   450     iEmbeddedObserver = aObserver;
       
   451     }
       
   452     
       
   453     
       
   454 // ---------------------------------------------------------------------------
       
   455 // CVRAppUi::IsUsbActive  
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 TBool CVRAppUi::IsUsbActive()
       
   459     {
       
   460     TInt usbState;
       
   461     TInt err = RProperty::Get(  KPSUidUsbWatcher, KUsbWatcherSelectedPersonality,usbState);
       
   462     return !err && usbState == KUsbPersonalityIdMS;
       
   463     }
       
   464 // End of file