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