mobilemessaging/audiomsg/src/audiomessagelaunchoperation.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005-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:   This file contains the application launch oper. functions. 
       
    15 *  				 Prepare body icon. Inserts smil if aplication 
       
    16 *				 is launched from the gallery.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include <AknsConstants.h>
       
    23 #include <data_caging_path_literals.hrh> // KDC_APP_BITMAP_DIR
       
    24 #include <mmsvattachmentmanager.h>
       
    25 #include <mmsvattachmentmanagersync.h>
       
    26 #include <cmsvmimeheaders.h>
       
    27 #include <StringLoader.h>	
       
    28 #include <MsgEditorCommon.h>
       
    29 #include <AknUtils.h>
       
    30 #include <aknlayoutscalable_apps.cdl.h>
       
    31 #include <msgimagecontrol.h> 
       
    32 #include <MsgMimeTypes.h>
       
    33 #include <MsgMediaResolver.h>
       
    34 #include <MsgMediaInfo.h>
       
    35 #include "msgtextutils.h"
       
    36 
       
    37 #include <audiomessage.rsg>
       
    38 #include <audiomessage.mbg> 
       
    39 #include "audiomessagelaunchoperation.h"
       
    40 #include "audiomessagerecorder.h"
       
    41 #include "audiomessage.hrh"
       
    42 
       
    43 _LIT( KAmsMbmFile, "audiomessage.mif" );
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CAudioMessageLaunchOperation::NewL
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CAudioMessageLaunchOperation* CAudioMessageLaunchOperation::NewL(
       
    53         MAmsOperationObserver& aOperationObserver,
       
    54         CAudioMessageDocument& aDocument,
       
    55         CMsgEditorView& aView )
       
    56     {
       
    57     CAudioMessageLaunchOperation* self = 
       
    58         new ( ELeave ) CAudioMessageLaunchOperation( aOperationObserver, aDocument, aView );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CAudioMessageLaunchOperation::Constructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CAudioMessageLaunchOperation::CAudioMessageLaunchOperation(
       
    67         MAmsOperationObserver& aOperationObserver,
       
    68         CAudioMessageDocument& aDocument,
       
    69         CMsgEditorView& aView ) :
       
    70     CAudioMessageOperation( aOperationObserver, aDocument ),
       
    71     iView( aView )
       
    72     {
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CAudioMessageLaunchOperation::Destructor
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 CAudioMessageLaunchOperation::~CAudioMessageLaunchOperation()
       
    80     {
       
    81     Cancel();
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CAudioMessageLaunchOperation::Launch
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CAudioMessageLaunchOperation::Launch()
       
    89     {
       
    90     ResetError();
       
    91     iLaunchState = EAmsLaunchInitialize;
       
    92     CompleteSelf( KErrNone );
       
    93     }
       
    94  
       
    95 // ---------------------------------------------------------
       
    96 // CAudioMessageLaunchOperation::DoLaunchStepL
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 void CAudioMessageLaunchOperation::DoLaunchStepL()
       
   100     {
       
   101     switch ( iLaunchState )
       
   102         {
       
   103         case EAmsLaunchInitialize:
       
   104             DoInitializeL();
       
   105             break;
       
   106         case EAmsCheckAttach:
       
   107    			CheckAttasL( );
       
   108 			CompleteSelf( KErrNone );
       
   109 			break;
       
   110         case EAmsHandleAudio:
       
   111         	DoHandleAudioL();
       
   112         	break;
       
   113         case EAmsLaunchPrepareContent:
       
   114            	DoPrepareContentL();
       
   115           	CompleteSelf( KErrNone );
       
   116             break;
       
   117         case EAmsLaunchAddNeededSmil:
       
   118            	if ( !SmilExists() )
       
   119            		{
       
   120            		AddSmilL();
       
   121            		}
       
   122         	CompleteSelf( KErrNone );
       
   123             break;
       
   124         case EAmsLaunchUnInitialize:
       
   125             UnInit();
       
   126     		CompleteSelf( KErrNone );
       
   127             break;
       
   128         case EAmsLaunchPrepareBody:
       
   129             DoPrepareBodyL();
       
   130             break;
       
   131         case EAmsLaunchEnd:
       
   132             iObserver.EditorOperationEvent(
       
   133                 EAmsOperationLaunch,
       
   134                 EAmsOperationComplete ); 
       
   135             break;
       
   136 		case EAmsLaunchErrorReport:
       
   137 			UnInit();
       
   138 			iObserver.EditorOperationEvent(
       
   139 				EAmsOperationLaunch,
       
   140 				EAmsOperationError );
       
   141 			break;
       
   142         default:
       
   143             iObserver.EditorOperationEvent(
       
   144                 EAmsOperationLaunch,
       
   145                 EAmsOperationError ); 
       
   146             break;
       
   147         }
       
   148     iLaunchState++;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CAudioMessageLaunchOperation::DoInitializeL
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 void CAudioMessageLaunchOperation::DoInitializeL()
       
   156     {
       
   157     if ( iDocument.GetAppMode() == EAmsViewer )
       
   158     	{
       
   159     	DoReadInitL();
       
   160     	}
       
   161     else
       
   162     	{
       
   163     	DoEditInitL();
       
   164     	}
       
   165    	iDocument.InitializeL( );
       
   166     CompleteSelf( KErrNone );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CAudioMessageLaunchOperation::DoPrepareBodyL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CAudioMessageLaunchOperation::DoPrepareBodyL()
       
   174     {
       
   175    	if ( iDocument.GetClipStatus() == EAmsClipAttachment )
       
   176    		{
       
   177        	DoPrepareBodyL( EAudioInserted );
       
   178    		}
       
   179    	else if ( iDocument.GetClipStatus() == EAmsClipCorrupted )
       
   180    		{
       
   181    		DoPrepareBodyL( EAudioCorrupted );
       
   182    		}
       
   183    	else
       
   184    		{
       
   185    		DoPrepareBodyL( EAudioInsert );
       
   186    		}
       
   187     CompleteSelf( KErrNone );
       
   188     }
       
   189     
       
   190 // ---------------------------------------------------------------------------
       
   191 // CAudioMessageLaunchOperation::DoPrepareBodyL
       
   192 // Prepares voice clip icon (insert/inserted) according to status of the clip
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CAudioMessageLaunchOperation::DoPrepareBodyL( TAmsRecordIconStatus aType )
       
   196     {
       
   197   	TParse fileParse;
       
   198     fileParse.Set( KAmsMbmFile, &KDC_APP_BITMAP_DIR, NULL );
       
   199     TAknsItemID id;
       
   200     TInt icon;
       
   201     TInt mask;
       
   202     iDocument.SetRecordIconStatus( aType );
       
   203     if ( aType == EAudioInserted && iDocument.Entry().iError != KErrCorrupt )
       
   204     	{
       
   205     	id = KAknsIIDQgnGrafMmsAudioInserted;
       
   206         icon = EMbmAudiomessageQgn_graf_mms_audio_inserted;
       
   207         mask = EMbmAudiomessageQgn_graf_mms_audio_inserted_mask;
       
   208     	}
       
   209     else if ( aType == EAudioInsert && iDocument.Entry().iError != KErrCorrupt )
       
   210     	{
       
   211     	id = KAknsIIDQgnGrafMmsAudioInsert;
       
   212         icon = EMbmAudiomessageQgn_graf_mms_audio_insert;
       
   213         mask = EMbmAudiomessageQgn_graf_mms_audio_insert_mask;
       
   214     	}
       
   215     else if ( aType == EAudioCorrupted && iDocument.Entry().iError != KErrCorrupt  )
       
   216     	{
       
   217     	//Create a copy TmsvEntry based on returned const ref
       
   218     	TMsvEntry modifiableEntry = iDocument.Entry();
       
   219     	modifiableEntry.iError = KErrCorrupt; 
       
   220     	iDocument.CurrentEntry().ChangeL( modifiableEntry );
       
   221     	
       
   222     	id = KAknsIIDQgnGrafMmsAudioCorrupted;
       
   223     	icon = EMbmAudiomessageQgn_graf_mms_audio_corrupted;
       
   224         mask = EMbmAudiomessageQgn_graf_mms_audio_corrupted_mask; 
       
   225     	}
       
   226     else  
       
   227     	{
       
   228     	id = KAknsIIDQgnGrafMmsAudioCorrupted;
       
   229     	icon = EMbmAudiomessageQgn_graf_mms_audio_corrupted;
       
   230         mask = EMbmAudiomessageQgn_graf_mms_audio_corrupted_mask; 
       
   231     	}
       
   232     	
       
   233 
       
   234     TAknLayoutRect iconLayout;
       
   235     iconLayout.LayoutRect(
       
   236         MsgEditorCommons::MsgDataPane(),
       
   237         AknLayoutScalable_Apps::msg_data_pane_g7().LayoutLine() );
       
   238 
       
   239     if ( !iImageControl )
       
   240     	{
       
   241     	iImageControl = CMsgImageControl::NewL( iView, NULL );
       
   242     	iImageControl->LoadIconL( fileParse.FullName(), id, icon, mask );
       
   243     	iImageControl->SetControlId( EMsgComponentIdImage );
       
   244         iImageControl->SetIconSizeL( iconLayout.Rect().Size() );
       
   245         iImageControl->SetIconVisible( ETrue );
       
   246     	iView.AddControlL( iImageControl, EMsgComponentIdImage, EMsgFirstControl, EMsgBody );
       
   247   		}
       
   248   	else
       
   249     	{
       
   250     	iImageControl->LoadIconL( fileParse.FullName(), id, icon, mask );
       
   251         iImageControl->SetIconSizeL( iconLayout.Rect().Size() );
       
   252         iImageControl->SetIconVisible( ETrue );
       
   253         iImageControl->DrawDeferred();
       
   254         }
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CAudioMessageLaunchOperation::DoCancel
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 void CAudioMessageLaunchOperation::DoCancel()
       
   262     {
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------
       
   266 // CAudioMessageLaunchOperation::RunL
       
   267 // ---------------------------------------------------------
       
   268 //
       
   269 void CAudioMessageLaunchOperation::RunL()
       
   270     {
       
   271     if ( iStatus.Int() != KErrNone )
       
   272         {
       
   273         // if EAmsExit, next error code is reason to exit
       
   274         SetError( iStatus.Int() );
       
   275         iObserver.EditorOperationEvent(
       
   276             EAmsOperationLaunch,
       
   277             EAmsOperationError );
       
   278         }
       
   279     else
       
   280 	    {
       
   281 	    DoLaunchStepL();
       
   282 	    }
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CAudioMessageLaunchOperation::DoPrepareContentL
       
   287 // ---------------------------------------------------------
       
   288 //
       
   289 void CAudioMessageLaunchOperation::DoPrepareContentL()
       
   290 	{
       
   291  	SetSmilExists(ETrue);
       
   292     TInt attaCount = iManager->AttachmentCount();
       
   293     if ( attaCount == 1 )
       
   294     	if ( iDocument.GetAppMode() != EAmsViewer )
       
   295     	{
       
   296  			SetSmilExists(EFalse);
       
   297     		iDocument.SetInsertedStatus( EAmsSmilAdded );
       
   298     	}
       
   299 
       
   300 	if( attaCount > 0 )
       
   301     	{
       
   302 		RFile attaFile = iManager->GetAttachmentFileL( iDocument.iAudio );
       
   303    		CleanupClosePushL( attaFile ); // RFile must be closed
       
   304    		//We must get the duration for the SMIL
       
   305    		CAudioMessageRecorder *recorder = CAudioMessageRecorder::NewL( attaFile, EFalse );
       
   306         iDocument.SetDuration( recorder->GetDuration() );
       
   307         delete recorder;
       
   308   	    recorder = NULL;
       
   309 	
       
   310        	if ( !SmilExists() ) 
       
   311        		{
       
   312   		    attaFile.Name( iContentLocationFileName );
       
   313   			TParsePtrC newName( iContentLocationFileName );
       
   314   			CMsvAttachment* atta = iManager->GetAttachmentInfoL( iDocument.iAudio );
       
   315     		CleanupStack::PushL( atta );	
       
   316     		CMsvMimeHeaders* msvMime = CMsvMimeHeaders::NewLC();
       
   317     		msvMime->RestoreL( *atta );
       
   318 	        //Now the filename still may contains дце etc
       
   319 	        msvMime->SetSuggestedFilenameL( newName.NameAndExt()  );
       
   320 	        
       
   321             //Replace дце to _ , real name not needed anymore
       
   322 	        CMsgTextUtils::TrimAndRemoveNonAlphaDigit( iContentLocationFileName );
       
   323 	        
       
   324 	        msvMime->SetContentLocationL( iContentLocationFileName );
       
   325 	        
       
   326 	        msvMime->StoreL( *atta );
       
   327             CleanupStack::Pop( msvMime );
       
   328             CleanupStack::Pop( atta );
       
   329             CleanupStack::PushL( msvMime );
       
   330             iManagerSync->ModifyAttachmentInfoL( atta );
       
   331 	        MakeCommitL( );
       
   332 	        CleanupStack::PopAndDestroy( msvMime ); 
       
   333        		} 
       
   334 		iDocument.SetClipStatus( EAmsClipAttachment );
       
   335     	CleanupStack::PopAndDestroy( &attaFile );
       
   336 		}
       
   337 	}
       
   338 
       
   339 
       
   340 
       
   341 // ---------------------------------------------------------
       
   342 // CAudioMessageLaunchOperation::SmilExists
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 TBool CAudioMessageLaunchOperation::SmilExists()
       
   346 	{
       
   347     return iSmilExist;
       
   348     }
       
   349     
       
   350 // ---------------------------------------------------------
       
   351 // CAudioMessageLaunchOperation::SetSmilExists
       
   352 // ---------------------------------------------------------
       
   353 //
       
   354 void CAudioMessageLaunchOperation::SetSmilExists( TBool aSel )
       
   355     {
       
   356     iSmilExist = aSel;
       
   357     }
       
   358 
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CAudioMessageLaunchOperation::DoHandleAudioL
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 void CAudioMessageLaunchOperation::DoHandleAudioL( )
       
   365     {
       
   366     if ( iDocument.iAudio != 0 )
       
   367         {
       
   368         if( iDocument.MessageType( ) == EAmsSendAs )
       
   369         	{ // SendAs -> Lets see what's inside
       
   370 			RFile audioFile = iManager->GetAttachmentFileL( iDocument.iAudio );
       
   371             CleanupClosePushL( audioFile );
       
   372 
       
   373 		 	CMsgMediaInfo* attaInfo = iDocument.MediaResolver()->CreateMediaInfoL( audioFile );
       
   374             iDocument.MediaResolver()->ParseInfoDetailsL( attaInfo, audioFile );
       
   375             
       
   376             if ( attaInfo->Protection() )
       
   377                 {
       
   378                 CleanupStack::PopAndDestroy( &audioFile );
       
   379 		        SetError( EAmsProtectedObject );
       
   380 		        iLaunchState = EAmsLaunchErrorReport;
       
   381 				CompleteSelf( -1 );
       
   382 				return;
       
   383                 }
       
   384             else if ( ( attaInfo->FileSize( ) > iDocument.MaxMessageSize() ) ||
       
   385                  ( attaInfo->MimeType( ).CompareF( KMsgMimeAudioAmr ) != 0  ) )
       
   386                 {
       
   387                 CleanupStack::PopAndDestroy( &audioFile );
       
   388 		        SetError( EAmsSendUiUnsupported );
       
   389 		        iLaunchState = EAmsLaunchErrorReport;
       
   390 				CompleteSelf( -1 );
       
   391 				return;		    	    
       
   392                 }
       
   393             else if ( attaInfo->Corrupt() )
       
   394                 {
       
   395                 CleanupStack::PopAndDestroy( &audioFile );
       
   396 		        SetError( EAmsSendUiCorrupted );
       
   397 		        iLaunchState = EAmsLaunchErrorReport;
       
   398 				CompleteSelf( -1 );
       
   399 				return;
       
   400                 }
       
   401             
       
   402             CleanupStack::PopAndDestroy( &audioFile );
       
   403 		    delete attaInfo;
       
   404         	}
       
   405     	}
       
   406         CompleteSelf( KErrNone );
       
   407 	}
       
   408 	
       
   409 /**
       
   410 * gets the framsize
       
   411 */	
       
   412 TSize CAudioMessageLaunchOperation::FrameSize()
       
   413     {
       
   414     return iImageControl->FrameSize();
       
   415     }
       
   416     
       
   417