voicerecorder/AppSrc/CVRNewFileService.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 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 part of new file service framework.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "CVRNewFileService.h"
       
    21 #include "CVRAppUi.h"
       
    22 #include <f32file.h>
       
    23 #include <eikenv.h>
       
    24 #include <eikappui.h>
       
    25 #include <eikapp.h>
       
    26 
       
    27 #include "voicerecorder.hrh"
       
    28 
       
    29 CVRNewFileService* CVRNewFileService::NewL()
       
    30 	{
       
    31 	return new( ELeave ) CVRNewFileService;
       
    32 	}
       
    33 
       
    34 CVRNewFileService::CVRNewFileService()
       
    35 : iCompleted( EFalse ), iFileHandleUsed( EFalse )
       
    36 	{
       
    37 		
       
    38 	}
       
    39 
       
    40 CVRNewFileService::~CVRNewFileService()
       
    41 	{
       
    42 	// Make sure that appui wont use this deleted class
       
    43 	CVRAppUi* appUi( static_cast<CVRAppUi*> (CEikonEnv::Static()
       
    44 	                ->EikAppUi() ) );
       
    45     if ( appUi )
       
    46         {
       
    47         appUi->SetEmbeddedObserver( NULL );
       
    48         }
       
    49           
       
    50 	if ( !iCompleted)
       
    51 		{
       
    52 		if ( iObserver )
       
    53 			{
       
    54 			// Can't leave in destructor
       
    55 			TRAP_IGNORE( iObserver->HandleCompletedNewServiceL( EFalse ) );				
       
    56 			iCompleted = ETrue;
       
    57 			}
       
    58 		}
       
    59 	}
       
    60 	
       
    61 void CVRNewFileService::HandleNewFileL( MNewFileServiceObserver* aObserver,
       
    62 							  CDesCArray& aFilenameArray,
       
    63 							  TNewServiceFileType aType,
       
    64 							  TBool /*aMultipleFiles*/ )
       
    65 	{
       
    66 	RFile dummyFile;
       
    67 
       
    68 	iFilenameArray = &aFilenameArray;
       
    69 	iObserver = aObserver;
       
    70 
       
    71 	if ( aType != ENewFileServiceAudio )
       
    72 		{
       
    73 		iCompleted = ETrue;
       
    74 		aObserver->HandleCompletedNewServiceL( EFalse );
       
    75 
       
    76 		// Send NULL to AppUi as observer, AppUi exits
       
    77 
       
    78 		( static_cast<CVRAppUi*> (CEikonEnv::Static()->EikAppUi() ) )
       
    79 			->RecordNewFileL( dummyFile, NULL );		
       
    80 		return;
       
    81 		}
       
    82 
       
    83 	// Send message to AppUi to fully construct application
       
    84 	( static_cast<CVRAppUi*> (CEikonEnv::Static()->EikAppUi() ) )
       
    85 		->RecordNewFileL( dummyFile, this );
       
    86 
       
    87 	}
       
    88 
       
    89 void CVRNewFileService::HandleNewFileL( MNewFileServiceObserver* aObserver,
       
    90 							  RFile& aFile,
       
    91 							  TNewServiceFileType aType )
       
    92 	{
       
    93 	iObserver = aObserver;
       
    94 
       
    95 	if ( aType != ENewFileServiceAudio )
       
    96 		{
       
    97 		iCompleted = ETrue;
       
    98 		aObserver->HandleCompletedNewServiceL( EFalse );
       
    99 
       
   100 		// Send NULL to AppUi as observer, AppUi exits
       
   101 		RFile dummyFile;
       
   102 		( static_cast<CVRAppUi*> (CEikonEnv::Static()->EikAppUi() ) )
       
   103 			->RecordNewFileL( dummyFile, NULL );		
       
   104 		return;
       
   105 		}
       
   106 
       
   107 	iFileHandleUsed = ETrue;
       
   108 
       
   109 	// Send the file handle to application and finish ui construction
       
   110 	( static_cast<CVRAppUi*> (CEikonEnv::Static()->EikAppUi() ) )
       
   111 	                        ->RecordNewFileL( aFile, this );
       
   112 	}
       
   113 
       
   114 TBool CVRNewFileService::FileCompleteL( const TDesC& aName )
       
   115 	{
       
   116 	if ( iFilenameArray )
       
   117 		{
       
   118 		iFilenameArray->AppendL( aName );
       
   119 		}
       
   120 
       
   121 	iCompleted = ETrue;
       
   122 	iObserver->HandleCompletedNewServiceL( ETrue );	
       
   123 
       
   124 	// Notify the appui
       
   125 	if ( iFileHandleUsed )
       
   126 		{
       
   127 		// Application can be closed immediately
       
   128 		return ETrue;
       
   129 		}
       
   130 	
       
   131 	// Application waits for ECmdNewFileServiceNotify before it quits
       
   132 	// File service needs to transfer filenames back to client first
       
   133 	return EFalse;
       
   134 	}
       
   135 
       
   136 void CVRNewFileService::ServiceCompleteL()
       
   137 	{
       
   138 	CEikonEnv::Static()->EikAppUi()->HandleCommandL( ECmdNewFileServiceNotify );	
       
   139 	}
       
   140 
       
   141 void CVRNewFileService::AbortL()
       
   142 	{
       
   143 	if ( !iCompleted )
       
   144 		{
       
   145 		iCompleted = ETrue;
       
   146 		iObserver->HandleCompletedNewServiceL( EFalse );
       
   147 		}
       
   148 	}
       
   149 
       
   150 // End of File