videditor/SimpleCutVideo/src/VeiSimpleCutVideoView.cpp
changeset 9 d87d32eab1a9
parent 0 951a5db380a0
equal deleted inserted replaced
0:951a5db380a0 9:d87d32eab1a9
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description: 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 // System includes
       
    22 #include <aknviewappui.h>
       
    23 #include <avkon.hrh>
       
    24 #include <vedsimplecutvideo.rsg>
       
    25 
       
    26 #include <akntitle.h> 
       
    27 #include <stringloader.h> 
       
    28 #include <aknnotewrappers.h>
       
    29 #include <aknquerydialog.h>
       
    30 #include <aknlists.h>
       
    31 #include <aknPopup.h>
       
    32 #include <AknProgressDialog.h>
       
    33 #include <eikprogi.h>
       
    34 #include <CAknMemorySelectionDialog.h>
       
    35 #include <CAknFileNamePromptDialog.h>
       
    36 #include <apparc.h>
       
    37 #include <aknselectionlist.h>
       
    38 #include <sysutil.h>
       
    39 #include <aknwaitdialog.h>
       
    40 #include <e32property.h>
       
    41 #include <PathInfo.h> 
       
    42 #include <AknCommonDialogsDynMem.h> 
       
    43 #include <CAknMemorySelectionDialogMultiDrive.h> 
       
    44 
       
    45 // User includes
       
    46 #include "VeiSimpleCutVideoAppUi.h"
       
    47 #include "VeiSimpleCutVideoView.h"
       
    48 #include "VeiSimpleCutVideoContainer.h" 
       
    49 #include "VedSimpleCutVideo.hrh"
       
    50 #include "veitempmaker.h"
       
    51 #include "VeiTimeLabelNavi.h"
       
    52 #include "videoeditorcommon.h"
       
    53 #include "VideoeditorUtils.h"
       
    54 #include "VeiErrorUi.h"
       
    55 #include "veinavipanecontrol.h"
       
    56 
       
    57 void CVeiSimpleCutVideoView::ConstructL()
       
    58     {
       
    59 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::ConstructL: in");
       
    60 
       
    61     BaseConstructL( R_VEI_CUT_VIDEO_VIEW );
       
    62 
       
    63 	iCVeiNaviPaneControl = CVeiNaviPaneControl::NewL( StatusPane() );
       
    64 
       
    65 	iErrorUI = CVeiErrorUI::NewL( *iCoeEnv );	
       
    66 
       
    67 	iTimeUpdater = CPeriodic::NewL( CActive::EPriorityLow );
       
    68 
       
    69 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::ConstructL: creating iMovie");
       
    70 	iMovie = CVedMovie::NewL( NULL );
       
    71 	iMovie->RegisterMovieObserverL( this );
       
    72 	
       
    73 	iTempMaker = CVeiTempMaker::NewL();
       
    74 	
       
    75 	iOverWriteFile = EFalse;
       
    76 	iPaused = EFalse; 
       
    77 		
       
    78 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::ConstructL: out");
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 TInt CVeiSimpleCutVideoView::AddClipL( const TDesC& aFilename, TBool /*aStartNow*/ )
       
    83 	{
       
    84 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::AddClipL: In: %S", &aFilename);
       
    85 	
       
    86 	iMovie->InsertVideoClipL( aFilename, 0 );
       
    87 	
       
    88 	iWaitDialog = new ( ELeave ) CAknWaitDialog( 
       
    89 	    REINTERPRET_CAST( CEikDialog**, &iWaitDialog ), ETrue);
       
    90 	iWaitDialog->PrepareLC(R_VEI_WAIT_NOTE_WITH_CANCEL);
       
    91 	iWaitDialog->SetCallback(this);
       
    92 
       
    93 	HBufC* stringholder = StringLoader::LoadLC( R_VEI_OPENING, iEikonEnv );
       
    94 	iWaitDialog->SetTextL( *stringholder );	
       
    95 	CleanupStack::PopAndDestroy(stringholder);
       
    96 
       
    97 	iWaitDialog->RunLD();
       
    98 
       
    99     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::AddClipL: Out");
       
   100 	return KErrNone;
       
   101 	}
       
   102     
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CVeiSimpleCutVideoView::~CVeiSimpleCutVideoView()
       
   106 // ?implementation_description
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 CVeiSimpleCutVideoView::~CVeiSimpleCutVideoView()
       
   110     {
       
   111     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::~CVeiSimpleCutVideoView(): In");
       
   112 
       
   113 	if ( iProgressNote )
       
   114 		{
       
   115 		delete iProgressNote;
       
   116 		iProgressNote = NULL;
       
   117 		}
       
   118 	if ( iAnimatedProgressDialog )
       
   119 		{
       
   120 		delete iAnimatedProgressDialog;
       
   121 		iAnimatedProgressDialog = NULL;
       
   122 		}
       
   123 	
       
   124 	if (iWaitDialog)
       
   125 		{
       
   126 		CloseWaitDialog();
       
   127 		iWaitDialog->MakeVisible( EFalse );
       
   128 		delete iWaitDialog;
       
   129 		iWaitDialog = NULL;	
       
   130 		}
       
   131     
       
   132     if ( iContainer )
       
   133         {
       
   134         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   135 		delete iContainer;
       
   136 		iContainer = 0;
       
   137         }	
       
   138 	
       
   139 	if ( iTimeUpdater )
       
   140 		{
       
   141 		iTimeUpdater->Cancel();
       
   142 		delete iTimeUpdater;
       
   143 		}
       
   144 		
       
   145 	if ( iErrorUI )
       
   146 		{
       
   147 		delete iErrorUI;
       
   148 		}
       
   149 			
       
   150 	if ( iMovie )
       
   151 		{
       
   152 		iMovie->Reset();		
       
   153 		iMovie->UnregisterMovieObserver( this );			
       
   154 		delete iMovie;
       
   155 		iMovie = NULL;
       
   156 		}
       
   157 	
       
   158 	if ( iTempMaker )
       
   159 		{
       
   160 		delete iTempMaker;
       
   161 		iTempMaker = NULL;
       
   162 		}
       
   163 		
       
   164 	if ( iSaveToFileName )
       
   165 		{
       
   166 		delete iSaveToFileName;
       
   167 		iSaveToFileName = NULL;
       
   168 		}
       
   169 				
       
   170 	if ( iTempFile )
       
   171 		{
       
   172 		TInt err = iEikonEnv->FsSession().Delete( *iTempFile );
       
   173 		if ( err ) 
       
   174 			{
       
   175 			// what to do when error occurs in destructor???
       
   176 			}
       
   177 		delete iTempFile;
       
   178 		iTempFile = NULL;
       
   179 		}
       
   180 	
       
   181 	delete iCallBack;	
       
   182 	delete iCVeiNaviPaneControl;
       
   183 
       
   184 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::~CVeiSimpleCutVideoView(): Out");
       
   185     }
       
   186 
       
   187 TUid CVeiSimpleCutVideoView::Id() const
       
   188      {
       
   189      return TUid::Uid( EVeiSimpleCutVideoView );
       
   190      }
       
   191 
       
   192 void CVeiSimpleCutVideoView::DialogDismissedL( TInt aButtonId )
       
   193 	{
       
   194 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: In, abuttonId:%d", aButtonId);	
       
   195 	if (iSaving)
       
   196 		{	
       
   197 		LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 2");
       
   198 		iSaving = EFalse;	
       
   199 		if ( aButtonId != EAknSoftkeyDone )
       
   200 			{	
       
   201 			LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 3");
       
   202 			iMovie->CancelProcessing();
       
   203 			LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 4");
       
   204 			}
       
   205 		else if (KErrNone == iErrorNmb)
       
   206 			{	
       
   207 			LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 5");
       
   208 			iErrorNmb = 0;
       
   209 			RFs& fs = iEikonEnv->FsSession();		
       
   210 			CFileMan* fileman = CFileMan::NewL( fs );	
       
   211 			CleanupStack::PushL( fileman );
       
   212 			
       
   213 			TInt moveErr( KErrNone );
       
   214 
       
   215 			// the user selects to overwrite the existing file
       
   216 			if (iOverWriteFile) 
       
   217 				{
       
   218 				// temp file located in the same drive as the target file
       
   219 				if ( iTempFile->Left(1) == iMovie->VideoClipInfo( iIndex )->FileName().Left(1) )
       
   220 					{
       
   221 					moveErr = fileman->Rename( *iTempFile, iMovie->VideoClipInfo( iIndex )->FileName(), CFileMan::EOverWrite ); 
       
   222 					}
       
   223 				else
       
   224 					{
       
   225 					moveErr = fileman->Move( *iTempFile, iMovie->VideoClipInfo( iIndex )->FileName(), CFileMan::EOverWrite );
       
   226 					}
       
   227 				if (!moveErr)
       
   228 					{
       
   229 					//AddClipL( iMovie->VideoClipInfo( iIndex )->FileName(), NULL );
       
   230 					ClearInOutL(ETrue, ETrue); 
       
   231 					iContainer->StopL(); 	
       
   232 					TTimeIntervalMicroSeconds pos = iContainer->PlaybackPositionL();
       
   233 					iContainer->GetThumbL( iMovie->VideoClipInfo( iIndex )->FileName() );		
       
   234 					}
       
   235 				}
       
   236 			// the user selects to save with a new file name						
       
   237 			else 
       
   238 				{	
       
   239 				// both files located in the same drive
       
   240 				if ( iTempFile->Left(1) == iSaveToFileName->Left(1) )
       
   241 					{
       
   242 					moveErr = fileman->Rename( *iTempFile, *iSaveToFileName );	
       
   243 					}
       
   244 				else
       
   245 					{
       
   246 					moveErr = fileman->Move( *iTempFile, *iSaveToFileName );	
       
   247 					}
       
   248 				if (!moveErr)
       
   249 					{
       
   250 					ClearInOutL(ETrue, ETrue); 
       
   251 					iContainer->StopL(); 
       
   252 					iMovie->RemoveVideoClip(0);
       
   253 					AddClipL( *iSaveToFileName, NULL );
       
   254 					}
       
   255 				}
       
   256 			CleanupStack::PopAndDestroy( fileman ); 
       
   257 
       
   258 			delete iTempFile;
       
   259 			iTempFile = NULL;
       
   260 
       
   261 			if ( moveErr )
       
   262 				{
       
   263 				iErrorUI->ShowGlobalErrorNote( moveErr );			
       
   264 				}
       
   265 			
       
   266 			//if ( BaflUtils::FileExists(fs, *iSaveToFileName) )
       
   267 			// Checking for iSaveToFileName doesn't work when overwriting so moveErr has to be used. 
       
   268 			else
       
   269 				{
       
   270 				// Video saved successfully!
       
   271 				LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 6");
       
   272 				
       
   273 				// The marks can be removed now that the video is saved
       
   274 			//	ClearInOutL(ETrue, ETrue); 
       
   275 			//	iContainer->StopL(); 
       
   276 				//TTimeIntervalMicroSeconds pos = iContainer->PlaybackPositionL();
       
   277 							
       
   278 				// Publish & Subscribe API used to make the saved file name available to AIW provider
       
   279 				LOG(KVideoEditorLogFile, "CVeiEditVideoView::UpdateMediaGalleryL(): Calling RProperty::Define(KUidVideoEditorProperties, VideoEditor::EPropertyFilename, RProperty::EText); ");
       
   280 				TInt err = RProperty::Define(KUidVideoEditorProperties, VideoEditor::EPropertyFilename, RProperty::EText);
       
   281 				if (err != KErrAlreadyExists)
       
   282 					{
       
   283 					User::LeaveIfError(err);
       
   284 					}
       
   285 				User::LeaveIfError(RProperty::Set(KUidVideoEditorProperties, VideoEditor::EPropertyFilename, iSaveToFileName->Des()));
       
   286 
       
   287 	
       
   288 				// the user has selected "Cut" or "Exit"			
       
   289 				if (!iSaveOnly) 
       
   290 					{					
       
   291 					//AppUi()->Exit();
       
   292 					if (! iCallBack)
       
   293 						{		
       
   294 						TCallBack cb (CVeiSimpleCutVideoView::AsyncExit, this);
       
   295 						iCallBack = new (ELeave) CAsyncCallBack(cb, CActive::EPriorityStandard);
       
   296 						}
       
   297 					iCallBack->CallBack();									
       
   298 					}	
       
   299 
       
   300 				}				
       
   301 				LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 7");
       
   302 			}
       
   303 		else
       
   304 			{
       
   305 			LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 8");
       
   306 			iErrorUI->ShowGlobalErrorNote( iErrorNmb );
       
   307 			iErrorNmb = 0;
       
   308 			}
       
   309 		}
       
   310 	else if (KErrCancel != aButtonId && iErrorNmb)
       
   311 			{			
       
   312 			LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: 9");
       
   313 			if (KErrCorrupt == iErrorNmb || KErrTooShortVideoForCut == iErrorNmb)
       
   314 				{
       
   315 				HBufC* stringholder = StringLoader::LoadLC( R_VEI_VIDEO_FAILED, iEikonEnv );								
       
   316 				CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue );
       
   317 				dlg->ExecuteLD( *stringholder );
       
   318 				CleanupStack::PopAndDestroy( stringholder );	
       
   319 				}
       
   320 			else
       
   321 				{				
       
   322 				iErrorUI->ShowGlobalErrorNote( iErrorNmb );
       
   323 				}
       
   324 			
       
   325 			if (! iCallBack)
       
   326 				{		
       
   327 				TCallBack cb (CVeiSimpleCutVideoView::AsyncExit, this);
       
   328 				iCallBack = new (ELeave) CAsyncCallBack(cb, CActive::EPriorityStandard);
       
   329 				}
       
   330 			iCallBack->CallBack();
       
   331 			iErrorNmb = 0;
       
   332 			}
       
   333 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DialogDismissedL: Out");
       
   334 	}
       
   335 		
       
   336 TInt CVeiSimpleCutVideoView::AsyncExit(TAny* aThis)
       
   337 	{
       
   338     LOG( KVideoEditorLogFile, "CVeiSimpleCutVideoView::AsyncExit");
       
   339 
       
   340     // In the asynchronous version, trap the rest of the functions 
       
   341     // to make sure that the caller's TRequestStatus is always 
       
   342     // completed, also in case of failures.
       
   343 	CVeiSimpleCutVideoView* view = static_cast<CVeiSimpleCutVideoView*>(aThis);
       
   344 	view->PrepareForTermination();
       
   345 	view->AppUi()->Exit();
       
   346 	return KErrNone;
       
   347 	}
       
   348 
       
   349 void CVeiSimpleCutVideoView::DynInitMenuPaneL( TInt aResourceId,CEikMenuPane* aMenuPane )
       
   350 	{
       
   351 	TInt state = iContainer->State();
       
   352 
       
   353 	if (aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU_CLEAR_MARKS)
       
   354 		{
       
   355 		// delete in, out, in & out as necessary.
       
   356 
       
   357 		if (iMovie->VideoClipCutInTime(iIndex) <= TTimeIntervalMicroSeconds(0)) 
       
   358 			{
       
   359 			aMenuPane->SetItemDimmed(EVeiCmdCutVideoViewClearMarksIn, ETrue);
       
   360 			}
       
   361 		if (iMovie->VideoClipCutOutTime(iIndex) >= iMovie->VideoClipInfo(iIndex)->Duration()) 
       
   362 			{
       
   363 			aMenuPane->SetItemDimmed(EVeiCmdCutVideoViewClearMarksOut, ETrue);
       
   364 			}
       
   365 
       
   366 		if (!((iMovie->VideoClipCutOutTime(iIndex) < iMovie->VideoClipInfo(iIndex)->Duration())
       
   367 			&& (iMovie->VideoClipCutInTime(iIndex) > TTimeIntervalMicroSeconds(0))))
       
   368 			{
       
   369 			aMenuPane->SetItemDimmed(EVeiCmdCutVideoViewClearMarksInOut, ETrue);
       
   370 			}
       
   371 		}
       
   372 
       
   373 	if ( aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU )
       
   374 		{
       
   375 		if ( iPopupMenuOpened != EFalse )
       
   376 			{
       
   377 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewClearMarks, ETrue );
       
   378 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoTakeSnapshot, ETrue );
       
   379 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewHelp, ETrue );
       
   380 			}
       
   381 		if ( !IsCutMarkSet() )
       
   382 			{
       
   383 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewSave, ETrue );
       
   384 			}			
       
   385 		}
       
   386 	if ( !(( aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU ) ||
       
   387 			( aResourceId == R_VEI_CUT_VIDEO_VIEW_CONTEXT_MENU ) ) ) 
       
   388 		return;
       
   389 
       
   390 	if ( iContainer->PlaybackPositionL() >= iContainer->TotalLength() )
       
   391 		{
       
   392 		if (aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU) 
       
   393 			{
       
   394 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewPlay, ETrue );
       
   395 			}
       
   396 
       
   397 		}
       
   398 	if ( ( state == CVeiSimpleCutVideoContainer::EStatePaused ) ||
       
   399 			( state == CVeiSimpleCutVideoContainer::EStateInitializing ) )
       
   400 		{
       
   401 		if (aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU) 
       
   402 			{		
       
   403 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewPlay, ETrue  );
       
   404 			}
       
   405 		}
       
   406 
       
   407 	if ( ( state != CVeiSimpleCutVideoContainer::EStateStopped ) && 
       
   408 		( state != CVeiSimpleCutVideoContainer::EStateStoppedInitial ) &&
       
   409 		( state != CVeiSimpleCutVideoContainer::EStatePaused ) )
       
   410 		{
       
   411 		if (aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU) 
       
   412 			{		
       
   413 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewPlay, ETrue  );
       
   414 			}
       
   415 		aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewMarkIn, ETrue  );
       
   416 		aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewMarkOut, ETrue  );	
       
   417 		}
       
   418 	else
       
   419 		{
       
   420 		TTimeIntervalMicroSeconds pos = iContainer->PlaybackPositionL(); 
       
   421 		CVedVideoClipInfo* info = iMovie->VideoClipInfo( iIndex );
       
   422 		
       
   423 		TInt cutInFrameIndex = info->GetVideoFrameIndexL( iMovie->VideoClipCutInTime( iIndex ));
       
   424 		TInt cutOutFrameIndex =	info->GetVideoFrameIndexL( iMovie->VideoClipCutOutTime( iIndex ));
       
   425 		TInt videoFrameCount = info->VideoFrameCount();
       
   426 		
       
   427 		// if we are in the existing start/end mark position the start/end mark is removed from the menu
       
   428 		if (info->GetVideoFrameIndexL(pos) == cutInFrameIndex)
       
   429 			{
       
   430 			aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewMarkIn );	
       
   431 			}		
       
   432 		else if (info->GetVideoFrameIndexL(pos) == cutOutFrameIndex)
       
   433 			{
       
   434 			aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewMarkOut );	
       
   435 			}	
       
   436 		
       
   437 		if( cutInFrameIndex < (videoFrameCount-1 ) )
       
   438 			{
       
   439 			cutInFrameIndex++;
       
   440 			}
       
   441 
       
   442 		if( cutOutFrameIndex > 0 )
       
   443 			{
       
   444 			cutOutFrameIndex--;
       
   445 			}
       
   446 
       
   447 		TTimeIntervalMicroSeconds nextFramePosCutIn = info->VideoFrameStartTimeL( cutInFrameIndex );
       
   448 		TTimeIntervalMicroSeconds previousFramePosCutOut = info->VideoFrameStartTimeL( cutOutFrameIndex );
       
   449 
       
   450 		if ( pos < nextFramePosCutIn )
       
   451 			{
       
   452 			aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewMarkOut );	
       
   453 			}
       
   454 		else 
       
   455 			{
       
   456 			if ( pos > previousFramePosCutOut )
       
   457 				{
       
   458 				aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewMarkIn );
       
   459 				}
       
   460 			}
       
   461 		// something crashes somewhere outside VED UI if end mark is put to near to begin				
       
   462 		TInt ind = -1;	
       
   463 		if (aMenuPane->MenuItemExists(EVeiCmdCutVideoViewMarkOut, ind) && pos.Int64() < KMinCutVideoLength)	
       
   464 			{
       
   465 			aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewMarkOut );	
       
   466 			}	
       
   467 		}
       
   468 	if ( ( iMovie->VideoClipCutInTime( iIndex ) == TTimeIntervalMicroSeconds( 0 ) && 
       
   469 		iMovie->VideoClipCutOutTime( iIndex ) == iMovie->VideoClipInfo( iIndex )->Duration() ) )
       
   470 		{
       
   471 		aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewPlayMarked );
       
   472 		}
       
   473 	if ( state != CVeiSimpleCutVideoContainer::EStatePlayingMenuOpen && 
       
   474 			state != CVeiSimpleCutVideoContainer::EStatePaused )
       
   475 		{
       
   476 		aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewContinue );
       
   477 		}
       
   478 	if ( ( state == CVeiSimpleCutVideoContainer::EStateStopped ) ||
       
   479 		 ( state == CVeiSimpleCutVideoContainer::EStateStoppedInitial ) ||
       
   480 		 ( state == CVeiSimpleCutVideoContainer::EStateOpening ) ||
       
   481 		 ( state == CVeiSimpleCutVideoContainer::EStateBuffering ) )
       
   482 		{
       
   483 			aMenuPane->DeleteMenuItem( EVeiCmdCutVideoViewStop );
       
   484 		}
       
   485 
       
   486 	if ( ( iMovie->VideoClipCutOutTime( iIndex ) >= iMovie->VideoClipInfo( iIndex )->Duration() ) &&
       
   487 		( iMovie->VideoClipCutInTime( iIndex ) <= TTimeIntervalMicroSeconds( 0 ) ) ) 
       
   488 		{
       
   489 		if (aResourceId == R_VEI_CUT_VIDEO_VIEW_MENU) 
       
   490 			{		
       
   491 			aMenuPane->SetItemDimmed( EVeiCmdCutVideoViewClearMarks, ETrue );
       
   492 			}
       
   493 		}
       
   494 	}
       
   495 
       
   496 void CVeiSimpleCutVideoView::HandleCommandL(TInt aCommand)
       
   497     {
       
   498     LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::HandleCommandL( %d ): In", aCommand);
       
   499 
       
   500     switch ( aCommand )
       
   501         {
       
   502 		case EAknSoftkeyOk:
       
   503 			{
       
   504 			iPopupMenuOpened = ETrue;
       
   505 			if (iContainer->State() == CVeiSimpleCutVideoContainer::EStatePlaying) 
       
   506 				{
       
   507 				PausePreviewL();
       
   508 				iContainer->SetStateL(CVeiSimpleCutVideoContainer::EStatePlayingMenuOpen);
       
   509 				}
       
   510 
       
   511 			MenuBar()->TryDisplayMenuBarL();
       
   512 			if (iContainer->State() == CVeiSimpleCutVideoContainer::EStatePlayingMenuOpen) 
       
   513 				{
       
   514 				iContainer->SetStateL(CVeiSimpleCutVideoContainer::EStatePaused);
       
   515 				}
       
   516 			iPopupMenuOpened = EFalse;
       
   517 			break;
       
   518 			}		
       
   519 		case EVeiCmdCutVideoViewBack:
       
   520         case EAknSoftkeyBack:
       
   521         	{	
       
   522         	PrepareForTermination();
       
   523         	AppUi()->Exit();
       
   524         	break;
       
   525         	}
       
   526        	case EVeiCmdCutVideoViewExit: 
       
   527        		{
       
   528             iSaveOnly = EFalse; 
       
   529 			StopNaviPaneUpdateL();
       
   530 
       
   531 			iContainer->StopL();
       
   532 			iContainer->CloseStreamL();
       
   533 
       
   534 			if ( ( iMovie->VideoClipCutInTime( 0 ) > TTimeIntervalMicroSeconds( 0 ) ) ||
       
   535 				 ( iMovie->VideoClipCutOutTime( 0 ) < iMovie->VideoClipInfo(0)->Duration() ) )
       
   536 				{
       
   537 				if (VideoEditorUtils::LaunchSaveChangesQueryL())
       
   538 					{
       
   539 	            	QueryAndSaveL();	    
       
   540 					}				
       
   541 				else
       
   542 					{
       
   543 					PrepareForTermination();
       
   544 					AppUi()->Exit();
       
   545 					}	
       
   546 				}
       
   547 			else
       
   548 				{
       
   549 				PrepareForTermination();
       
   550 				AppUi()->Exit();
       
   551 				}       		
       
   552        		}
       
   553        		break;
       
   554 		case EVeiCmdCutVideoViewCut: 
       
   555             {
       
   556             iSaveOnly = EFalse; 
       
   557 			StopNaviPaneUpdateL();
       
   558 
       
   559 			iContainer->StopL();
       
   560 			iContainer->CloseStreamL();
       
   561 
       
   562 			if ( ( iMovie->VideoClipCutInTime( 0 ) > TTimeIntervalMicroSeconds( 0 ) ) ||
       
   563 				 ( iMovie->VideoClipCutOutTime( 0 ) < iMovie->VideoClipInfo(0)->Duration() ) )
       
   564 				{
       
   565 				QueryAndSaveL(); 
       
   566 				}
       
   567             break;
       
   568             }
       
   569         case EVeiCmdCutVideoViewSave:
       
   570         	{
       
   571         	iSaveOnly = ETrue; 
       
   572 
       
   573 			StopNaviPaneUpdateL();
       
   574 			iContainer->StopL();
       
   575 			iContainer->CloseStreamL();
       
   576 
       
   577         	QueryAndSaveL(); 
       
   578         	break;
       
   579         	}
       
   580         case EVeiCmdCutVideoViewMarkIn:
       
   581             {
       
   582 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( ETrue );
       
   583 			MarkInL();
       
   584             break;
       
   585             }
       
   586         case EVeiCmdCutVideoViewMarkOut:
       
   587             {
       
   588 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( ETrue );
       
   589 			MarkOutL();
       
   590             break;
       
   591             }
       
   592         case EVeiCmdCutVideoViewClearMarksInOut:
       
   593             {
       
   594 			ClearInOutL( ETrue, ETrue );
       
   595             break;
       
   596             }
       
   597         case EVeiCmdCutVideoViewClearMarksIn:
       
   598             {
       
   599 			ClearInOutL( ETrue, EFalse );
       
   600             break;
       
   601             }
       
   602         case EVeiCmdCutVideoViewClearMarksOut:
       
   603             {
       
   604 			ClearInOutL( EFalse, ETrue );
       
   605             break;
       
   606             }
       
   607         case EVeiCmdCutVideoViewPlayMarked:
       
   608             {
       
   609 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( EFalse );
       
   610 			PlayMarkedL();
       
   611             break;
       
   612             }
       
   613 		case EVeiCmdCutVideoViewPlay:
       
   614 			{
       
   615 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( EFalse );
       
   616 			PlayPreviewL();
       
   617 			break;
       
   618 			}
       
   619 		case EVeiCmdCutVideoViewStop:
       
   620 			{
       
   621 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( EFalse );
       
   622 			StopNaviPaneUpdateL();
       
   623 			iContainer->StopL();
       
   624 			break;
       
   625 			}
       
   626 		case EVeiCmdCutVideoViewContinue:
       
   627             {
       
   628 			iCVeiNaviPaneControl->SetPauseIconVisibilityL( EFalse );
       
   629 			PlayPreviewL();
       
   630             break;
       
   631             }
       
   632 		case EVeiCmdCutVideoTakeSnapshot:
       
   633 			{
       
   634 			if( IsEnoughFreeSpaceToSaveL() )
       
   635 				{
       
   636 				iContainer->TakeSnapshotL();
       
   637 				}
       
   638 			break;
       
   639 			}
       
   640         
       
   641         //
       
   642         // Options->Help
       
   643         //
       
   644         case EVeiCmdCutVideoViewHelp:
       
   645             {
       
   646             // CS Help launching is handled in Video Editor's AppUi.
       
   647             AppUi()->HandleCommandL( EVeiCmdCutVideoViewHelp );
       
   648             break;
       
   649             }
       
   650         default:
       
   651             {
       
   652             AppUi()->HandleCommandL( aCommand );
       
   653             break;
       
   654             }
       
   655         }
       
   656 
       
   657     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::HandleCommandL: out");
       
   658     }
       
   659 
       
   660 void CVeiSimpleCutVideoView::NotifyMovieProcessingStartedL( CVedMovie& /*aMovie*/ )
       
   661 	{
       
   662 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyMovieProcessingStartedL: In");	
       
   663 	iProcessed = 0;
       
   664 	// @ : r_ved_cutting_note_animation
       
   665 	//StartAnimatedProgressNote();
       
   666 	StartProgressNoteL();
       
   667 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyMovieProcessingStartedL: Out");	
       
   668 	}
       
   669 
       
   670 void CVeiSimpleCutVideoView::NotifyMovieProcessingProgressed( CVedMovie& /*aMovie*/, TInt aPercentage )
       
   671 	{
       
   672 	//Not allow screensaver, when processing image.
       
   673 	User::ResetInactivityTime();
       
   674 	
       
   675 	iProcessed = aPercentage;
       
   676 	if (iAnimatedProgressDialog)
       
   677 		{		
       
   678 		iAnimatedProgressDialog->GetProgressInfoL()->SetAndDraw( aPercentage );
       
   679 		}
       
   680    	else if (iProgressNote)
       
   681 	   	{   		
       
   682 		iProgressNote->GetProgressInfoL()->SetAndDraw( aPercentage );
       
   683 	   	}
       
   684 	}
       
   685 
       
   686 void CVeiSimpleCutVideoView::NotifyMovieProcessingCompleted( CVedMovie& /*aMovie*/, TInt aError )
       
   687 	{
       
   688 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyMovieProcessingCompleted: In, aError:%d", aError);			
       
   689 	iErrorNmb = aError;
       
   690 	if (iAnimatedProgressDialog)
       
   691 		{
       
   692    		iAnimatedProgressDialog->GetProgressInfoL()->SetAndDraw( 100 );	
       
   693 		delete iAnimatedProgressDialog;
       
   694 		iAnimatedProgressDialog = NULL;
       
   695 		DialogDismissedL(EAknSoftkeyDone);
       
   696 		//TRAP_IGNORE( iAnimatedProgressDialog->ProcessFinishedL() );
       
   697 		}
       
   698 	else if (iProgressNote)
       
   699 		{
       
   700 		iProgressNote->GetProgressInfoL()->SetAndDraw(100);		
       
   701 		iProgressNote->ProcessFinishedL();
       
   702 		}
       
   703 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyMovieProcessingCompleted: Out");	
       
   704 	}
       
   705 
       
   706 void CVeiSimpleCutVideoView::NotifyVideoClipAdded( CVedMovie& /*aMovie*/, TInt aIndex)
       
   707 	{
       
   708 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyVideoClipAdded: In");	
       
   709 
       
   710 	iErrorNmb = 0;
       
   711 	
       
   712 	TTimeIntervalMicroSeconds duration = iMovie->Duration();
       
   713 	LOGFMT(KVideoEditorLogFile, "CVeiCutVideCVeiSimpleCutVideoView::NotifyVideoClipAdded, 2, duration:%Ld", duration.Int64());
       
   714 //	if (duration.Int64() < KMinCutVideoLength)
       
   715 //		{
       
   716 //		LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyVideoClipAdded: 3");	
       
   717 //		iErrorNmb = KErrTooShortVideoForCut;			
       
   718 //		iClosing = ETrue;
       
   719 //		}
       
   720 //	else
       
   721 		{
       
   722 		iAudioMuted = !( iMovie->VideoClipEditedHasAudio( aIndex ) );	
       
   723 
       
   724 		iCVeiNaviPaneControl->SetPauseIconVisibilityL( EFalse );
       
   725 
       
   726 		if ( iAudioMuted  )
       
   727 			{
       
   728 			iCVeiNaviPaneControl->SetVolumeIconVisibilityL( EFalse );
       
   729 			VolumeMuteL();
       
   730 			}
       
   731 		else
       
   732 			{
       
   733 			iCVeiNaviPaneControl->SetVolumeIconVisibilityL( ETrue );
       
   734 			}
       
   735 			
       
   736 //		iContainer->SetInTime( iMovie->VideoClipCutInTime( aIndex ) );
       
   737 //		iContainer->SetOutTime( iMovie->VideoClipCutOutTime( aIndex ) );	
       
   738 		iContainer->GetThumbL( iMovie->VideoClipInfo( iIndex )->FileName() );		
       
   739 		}
       
   740 
       
   741 	if (iWaitDialog)
       
   742 		{
       
   743 		delete iWaitDialog;
       
   744 		iWaitDialog = NULL;	
       
   745 		}
       
   746 //	CloseWaitDialog();
       
   747 	iContainer->DrawDeferred();
       
   748 
       
   749 	// video clip has to be added before setting the title pane text	
       
   750 	// : handle leave
       
   751 	SetTitlePaneTextL(); 
       
   752 			
       
   753 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyVideoClipAdded: Out");		
       
   754 	}
       
   755 
       
   756 void CVeiSimpleCutVideoView::NotifyVideoClipAddingFailed( CVedMovie& /*aMovie*/, TInt aError )
       
   757 	{
       
   758 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyVideoClipAddingFailed: In, aError:%d", aError);	
       
   759 	iErrorNmb = aError;	
       
   760 	iClosing = ETrue;
       
   761 	
       
   762 	CloseWaitDialog();
       
   763 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::NotifyVideoClipAddingFailed: Out");			
       
   764 	}
       
   765 
       
   766 void CVeiSimpleCutVideoView::NotifyVideoClipRemoved( CVedMovie& /*aMovie*/, TInt /*aIndex*/ )
       
   767 	{
       
   768 	}
       
   769 
       
   770 void CVeiSimpleCutVideoView::NotifyVideoClipIndicesChanged( CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, 
       
   771 									           TInt /*aNewIndex*/ )
       
   772 	{
       
   773 	}
       
   774 
       
   775 void CVeiSimpleCutVideoView::NotifyVideoClipTimingsChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ )
       
   776 	{
       
   777 	}
       
   778 
       
   779 void CVeiSimpleCutVideoView::NotifyVideoClipColorEffectChanged( CVedMovie& /*aMovie*/, TInt /*aIndex*/ )
       
   780 	{
       
   781 	}
       
   782 
       
   783 void CVeiSimpleCutVideoView::NotifyVideoClipAudioSettingsChanged( CVedMovie& /*aMovie*/,
       
   784 											         TInt /*aIndex*/ )
       
   785 	{
       
   786 	}
       
   787 
       
   788 void CVeiSimpleCutVideoView::NotifyStartTransitionEffectChanged( CVedMovie& /*aMovie*/ )
       
   789 	{
       
   790 	}
       
   791 
       
   792 void CVeiSimpleCutVideoView::NotifyMiddleTransitionEffectChanged( CVedMovie& /*aMovie*/, 
       
   793 													 TInt /*aIndex*/ )
       
   794 	{
       
   795 	}
       
   796 
       
   797 void CVeiSimpleCutVideoView::NotifyEndTransitionEffectChanged( CVedMovie& /*aMovie*/ )
       
   798 	{
       
   799 	}
       
   800 
       
   801 void CVeiSimpleCutVideoView::NotifyAudioClipAdded( CVedMovie& /*aMovie*/, TInt /*aIndex*/ )
       
   802 	{
       
   803 	}
       
   804 
       
   805 void CVeiSimpleCutVideoView::NotifyAudioClipAddingFailed( CVedMovie& /*aMovie*/, TInt /*aError*/ )
       
   806 	{
       
   807 	}
       
   808 
       
   809 void CVeiSimpleCutVideoView::NotifyAudioClipRemoved( CVedMovie& /*aMovie*/, TInt /*aIndex*/ )
       
   810 	{
       
   811 	}
       
   812 
       
   813 void CVeiSimpleCutVideoView::NotifyAudioClipIndicesChanged( CVedMovie& /*aMovie*/, TInt /*aOldIndex*/, 
       
   814 									           TInt /*aNewIndex*/ )
       
   815 	{
       
   816 	}
       
   817 
       
   818 void CVeiSimpleCutVideoView::NotifyAudioClipTimingsChanged( CVedMovie& /*aMovie*/,
       
   819 											   TInt /*aIndex*/ )
       
   820 	{
       
   821 	}
       
   822 
       
   823 void CVeiSimpleCutVideoView::NotifyMovieReseted( CVedMovie& /*aMovie*/ )
       
   824 	{
       
   825 	}
       
   826 
       
   827 void CVeiSimpleCutVideoView::NotifyVideoClipGeneratorSettingsChanged(CVedMovie& /*aMovie*/,
       
   828 											             TInt /*aIndex*/) 
       
   829 	{
       
   830 	}
       
   831 
       
   832 void CVeiSimpleCutVideoView::NotifyVideoClipDescriptiveNameChanged(CVedMovie& /*aMovie*/, TInt /*aIndex*/)
       
   833 	{
       
   834 	}
       
   835 
       
   836 void CVeiSimpleCutVideoView::NotifyMovieQualityChanged(CVedMovie& /*aMovie*/)
       
   837 	{
       
   838 	}
       
   839 
       
   840 void CVeiSimpleCutVideoView::NotifyMovieOutputParametersChanged(CVedMovie& /*aMovie*/)
       
   841 	{
       
   842 	}
       
   843 
       
   844 void CVeiSimpleCutVideoView::NotifyAudioClipDynamicLevelMarkInserted(CVedMovie& /*aMovie*/, 
       
   845                                                          TInt /*aClipIndex*/, 
       
   846                                                          TInt /*aMarkIndex*/)
       
   847 	{
       
   848 	}
       
   849 
       
   850 void CVeiSimpleCutVideoView::NotifyAudioClipDynamicLevelMarkRemoved(CVedMovie& /*aMovie*/, 
       
   851                                                         TInt /*aClipIndex*/, 
       
   852                                                         TInt /*aMarkIndex*/)
       
   853 	{
       
   854 	}
       
   855 
       
   856 void CVeiSimpleCutVideoView::NotifyVideoClipDynamicLevelMarkInserted(CVedMovie& /*aMovie*/,
       
   857                                                          TInt /*aClipIndex*/, 
       
   858                                                          TInt /*aMarkIndex*/)
       
   859 	{
       
   860 	}
       
   861 
       
   862 void CVeiSimpleCutVideoView::NotifyVideoClipDynamicLevelMarkRemoved(CVedMovie& /*aMovie*/, 
       
   863                                                         TInt /*aClipIndex*/, 
       
   864                                                         TInt /*aMarkIndex*/)
       
   865 	{
       
   866 	}
       
   867 
       
   868 void CVeiSimpleCutVideoView::CloseWaitDialog()
       
   869     {
       
   870     if ( iWaitDialog )
       
   871         {
       
   872         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
   873         }       
       
   874     }
       
   875 
       
   876 
       
   877 void CVeiSimpleCutVideoView::DoActivateL(
       
   878    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   879    const TDesC8& /*aCustomMessage*/)
       
   880     {
       
   881 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DoActivateL, In");
       
   882 	iPaused = EFalse;
       
   883     if (!iContainer)
       
   884         {
       
   885 		iContainer = CVeiSimpleCutVideoContainer::NewL( AppUi()->ClientRect(), *this, *iErrorUI );
       
   886 		iContainer->SetMopParent( this );
       
   887 		AppUi()->AddToStackL( *this, iContainer );
       
   888 		iCVeiNaviPaneControl->SetObserver( iContainer );
       
   889         }
       
   890 
       
   891 	UpdateCBAL( CVeiSimpleCutVideoContainer::EStateInitializing );
       
   892 	
       
   893 	CheckMemoryCardAvailabilityL();
       
   894 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::DoActivateL, out");
       
   895 	}
       
   896 
       
   897 // ---------------------------------------------------------
       
   898 // CVeiSimpleCutVideoView::HandleCommandL(TInt aCommand)
       
   899 // ?implementation_description
       
   900 // ---------------------------------------------------------
       
   901 //
       
   902 void CVeiSimpleCutVideoView::DoDeactivate()
       
   903    {    
       
   904 	if ( iTimeUpdater )
       
   905 		{
       
   906 		iTimeUpdater->Cancel();
       
   907 		}
       
   908 
       
   909 	if ( iContainer )
       
   910         {
       
   911         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   912 
       
   913 		delete iContainer;
       
   914 		iContainer = NULL;
       
   915         }
       
   916 	}
       
   917 
       
   918 void CVeiSimpleCutVideoView::PlayPreviewL()
       
   919 	{
       
   920 	iPaused = EFalse;
       
   921 	StartNaviPaneUpdateL();
       
   922 	iContainer->PlayL( iMovie->VideoClipInfo( iIndex )->FileName() );
       
   923 	}
       
   924 
       
   925 void CVeiSimpleCutVideoView::PausePreviewL()
       
   926 	{
       
   927 	iCVeiNaviPaneControl->SetPauseIconVisibilityL( ETrue );
       
   928 	StopNaviPaneUpdateL();
       
   929 
       
   930 	iContainer->PauseL();
       
   931 	}
       
   932 
       
   933 void CVeiSimpleCutVideoView::UpdateCBAL(TInt aState)
       
   934 	{	
       
   935 	MenuBar()->SetContextMenuTitleResourceId( R_VEI_MENUBAR_CUT_VIDEO_VIEW_CONTEXT ); 
       
   936 	switch (aState)
       
   937 		{
       
   938 		case CVeiSimpleCutVideoContainer::EStateInitializing:
       
   939 		case CVeiSimpleCutVideoContainer::EStateOpening:
       
   940 		case CVeiSimpleCutVideoContainer::EStateBuffering:		
       
   941 			{
       
   942 			if (! iClosing)
       
   943 				{				
       
   944 				Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY); 
       
   945 				}
       
   946 			break;
       
   947 			}
       
   948 		case CVeiSimpleCutVideoContainer::EStateStoppedInitial:
       
   949 			{
       
   950 			if (! iClosing)
       
   951 				{		
       
   952 				// no marks set
       
   953 				if ( ( iMovie->VideoClipCutInTime( 0 ) == TTimeIntervalMicroSeconds( 0 ) ) &&
       
   954 				 ( iMovie->VideoClipCutOutTime( 0 ) == iMovie->VideoClipInfo(0)->Duration() ) )
       
   955 					{		
       
   956 					// playhead in the beginning	
       
   957 					if ( iContainer->PlaybackPositionL() == 0 || AknLayoutUtils::PenEnabled() )
       
   958 						{
       
   959 						Cba()->SetCommandSetL(R_VEI_SOFTKEYS_OPTIONS_BACK__PLAY); 
       
   960 					}
       
   961 					// playhead not in the beginning
       
   962 					else
       
   963 						{
       
   964 						Cba()->SetCommandSetL(R_VEI_SOFTKEYS_IN_OUT__MENU);	
       
   965 						}
       
   966 					}
       
   967 				//start or end mark has been set	
       
   968 				else 
       
   969 					{
       
   970 					// start mark has been set, end mark has not been set 
       
   971 					// and the the playhead is on the right hand side of the start mark
       
   972 					if (( iMovie->VideoClipCutInTime( 0 ) != TTimeIntervalMicroSeconds( 0 ) ) && 
       
   973 					    ( iMovie->VideoClipCutOutTime( 0 ) == iMovie->VideoClipInfo(0)->Duration() ) &&
       
   974 					    ( iContainer->PlaybackPositionL() > iMovie->VideoClipCutInTime( 0 ))
       
   975 					    && !AknLayoutUtils::PenEnabled() )
       
   976 					    {
       
   977 					    Cba()->SetCommandSetL( R_VEI_SOFTKEYS_OPTIONS_OUT__MENU ); 
       
   978 					    }
       
   979 					else
       
   980 					    {
       
   981 					    Cba()->SetCommandSetL(R_VEI_SOFTKEYS_OPTIONS_CUT__MENU);
       
   982 					    }
       
   983 					}
       
   984 				}
       
   985 			break;
       
   986 			}
       
   987 		case CVeiSimpleCutVideoContainer::EStatePaused:
       
   988 		case CVeiSimpleCutVideoContainer::EStateStopped:
       
   989 			{							
       
   990 			
       
   991 			// no marks set
       
   992 			if ( ( iMovie->VideoClipCutInTime( 0 ) == TTimeIntervalMicroSeconds( 0 ) ) &&
       
   993 				 ( iMovie->VideoClipCutOutTime( 0 ) == iMovie->VideoClipInfo(0)->Duration() ) )
       
   994 				{
       
   995 				// playhead in the beginning		
       
   996 				if (iContainer->PlaybackPositionL() == 0 || AknLayoutUtils::PenEnabled() )
       
   997 					{
       
   998 					Cba()->SetCommandSetL(R_VEI_SOFTKEYS_OPTIONS_BACK__PLAY); 
       
   999 					}
       
  1000 				else
       
  1001 					{
       
  1002 					Cba()->SetCommandSetL(R_VEI_SOFTKEYS_IN_OUT__MENU);	
       
  1003 					}
       
  1004 				}
       
  1005 			// start or end mark has been set
       
  1006 			else
       
  1007 				{		
       
  1008 					// start mark has been set, end mark has not been set 
       
  1009 					// and the the playhead is on the right hand side of the start mark
       
  1010 					if (( iMovie->VideoClipCutInTime( 0 ) != TTimeIntervalMicroSeconds( 0 ) ) && 
       
  1011 					    ( iMovie->VideoClipCutOutTime( 0 ) == iMovie->VideoClipInfo(0)->Duration() ) &&					
       
  1012 					    ( iContainer->PlaybackPositionL() > iMovie->VideoClipCutInTime( 0 ))
       
  1013 					    && !AknLayoutUtils::PenEnabled() ) 
       
  1014 					    {
       
  1015 					    Cba()->SetCommandSetL( R_VEI_SOFTKEYS_OPTIONS_OUT__MENU );    
       
  1016 					    }
       
  1017 					else
       
  1018 					    {																
       
  1019         				Cba()->SetCommandSetL(R_VEI_SOFTKEYS_OPTIONS_CUT__MENU); 
       
  1020 					    }
       
  1021 				}
       
  1022 			break;
       
  1023 			}
       
  1024 		case CVeiSimpleCutVideoContainer::EStatePlaying:
       
  1025 			{			
       
  1026 			// playhead outside cut area
       
  1027 			if ( iContainer->PlaybackPositionL() < iMovie->VideoClipCutInTime( iIndex ) )
       
  1028 				{
       
  1029 				if ( AknLayoutUtils::PenEnabled() )
       
  1030 					{
       
  1031 					Cba()->SetCommandSetL( R_VEI_SOFTKEYS_IN_NONE__MENU ); 
       
  1032 					}
       
  1033 				else
       
  1034 					{
       
  1035 					Cba()->SetCommandSetL( R_VEI_SOFTKEYS_IN_STOP__MENU ); 
       
  1036 					}
       
  1037 				iMarkState = EMarkStateIn;
       
  1038 				}
       
  1039 			// playdhead inside cut area	
       
  1040 			else if ( iContainer->PlaybackPositionL() < iMovie->VideoClipCutOutTime( iIndex ) )
       
  1041 				{
       
  1042 				Cba()->SetCommandSetL( R_VEI_SOFTKEYS_IN_OUT__MENU ); 
       
  1043 				iMarkState = EMarkStateInOut;
       
  1044 				}
       
  1045 			// playhead outside cut area
       
  1046 			else
       
  1047 				{
       
  1048 				if ( AknLayoutUtils::PenEnabled() )
       
  1049 					{
       
  1050 					Cba()->SetCommandSetL( R_VEI_SOFTKEYS_NONE_OUT__MENU ); 
       
  1051 					}
       
  1052 				else
       
  1053 					{
       
  1054 					Cba()->SetCommandSetL( R_VEI_SOFTKEYS_STOP_OUT__MENU ); 
       
  1055 					}
       
  1056 				iMarkState = EMarkStateOut;
       
  1057 				}
       
  1058 				
       
  1059 			break;
       
  1060 			}
       
  1061 		case CVeiSimpleCutVideoContainer::EStateTerminating:
       
  1062 			{
       
  1063 			return;
       
  1064 			}
       
  1065 		default:
       
  1066 			{
       
  1067 			break;	
       
  1068 			}
       
  1069 		}
       
  1070 	Cba()->DrawDeferred();
       
  1071 	}
       
  1072 
       
  1073 void CVeiSimpleCutVideoView::PlayMarkedL()
       
  1074 	{
       
  1075 	LOGFMT3(KVideoEditorLogFile, "CVeiSimpleCutVideoView::PlayMarkedL: In: iIndex:%d, iMovie->VideoClipCutInTime():%Ld, iMovie->VideoClipCutOutTime():%Ld", iIndex, iMovie->VideoClipCutInTime( iIndex ).Int64(), iMovie->VideoClipCutOutTime( iIndex ).Int64());
       
  1076 	iPaused = EFalse;
       
  1077 	StartNaviPaneUpdateL();	
       
  1078 	iContainer->PlayMarkedL( iMovie->VideoClipInfo( iIndex )->FileName(),
       
  1079 		iMovie->VideoClipCutInTime( iIndex ), iMovie->VideoClipCutOutTime( iIndex ) );		
       
  1080 	
       
  1081 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::PlayMarkedL: Out");
       
  1082 	}
       
  1083 
       
  1084 void CVeiSimpleCutVideoView::ClearInOutL( TBool aClearIn, TBool aClearOut )
       
  1085 	{
       
  1086 	if ( aClearIn ) 
       
  1087 		{
       
  1088 		iMovie->VideoClipSetCutInTime( iIndex, TTimeIntervalMicroSeconds( 0 ) );
       
  1089 		iContainer->SetInTime( iMovie->VideoClipCutInTime( iIndex ) );
       
  1090 		}
       
  1091 	if ( aClearOut ) 
       
  1092 		{
       
  1093 		iMovie->VideoClipSetCutOutTime( iIndex, iMovie->VideoClipInfo( iIndex )->Duration() );
       
  1094 		iContainer->SetOutTime( iMovie->VideoClipInfo( iIndex )->Duration() );
       
  1095 		}
       
  1096 	TTimeIntervalMicroSeconds cutin = iMovie->VideoClipCutInTime( 0 );
       
  1097 	TTimeIntervalMicroSeconds cutout = iMovie->VideoClipCutOutTime( 0 );
       
  1098 	
       
  1099 	if ( ( cutin == TTimeIntervalMicroSeconds( 0 ) ) &&
       
  1100 		 ( cutout == iMovie->VideoClipInfo(0)->Duration() ) )
       
  1101 		{		
       
  1102 		Cba()->SetCommandSetL(R_VEI_SOFTKEYS_OPTIONS_BACK__MENU); 
       
  1103 		Cba()->DrawDeferred();
       
  1104 		}
       
  1105 	}
       
  1106 
       
  1107 void CVeiSimpleCutVideoView::MarkInL()
       
  1108 	{
       
  1109 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkInL, In");
       
  1110 	TTimeIntervalMicroSeconds pos = iContainer->PlaybackPositionL();
       
  1111 
       
  1112     // the start mark can't be put right to the beginning
       
  1113     // because start mark is at position 0 when it is not set
       
  1114     if (pos == 0)
       
  1115         {
       
  1116         pos = 1;
       
  1117         }
       
  1118 	
       
  1119 //	TTimeIntervalMicroSeconds clipDuration = iMovie->VideoClipInfo( iIndex )->Duration();
       
  1120 //	CVedVideoClipInfo* info = iMovie->VideoClipInfo( iIndex );
       
  1121 //	TTimeIntervalMicroSeconds intraPos = info->VideoFrameStartTimeL( 
       
  1122 //			info->GetVideoFrameIndexL( pos ) );
       
  1123 	if (iMovie->VideoClipCutOutTime(iIndex) > pos)
       
  1124 		{
       
  1125 		StopNaviPaneUpdateL();		
       
  1126 		LOGFMT2(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkInL, 2, iIndex:%d, pos:%Ld", iIndex, pos.Int64());
       
  1127 		iMovie->VideoClipSetCutInTime( iIndex, pos );
       
  1128 		iContainer->MarkedInL();	
       
  1129 		}
       
  1130 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkInL, Out");
       
  1131 	}
       
  1132 
       
  1133 void CVeiSimpleCutVideoView::MarkOutL()
       
  1134 	{
       
  1135 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkOutL, In");
       
  1136 	TTimeIntervalMicroSeconds pos = iContainer->PlaybackPositionL();
       
  1137 //	CVedVideoClipInfo* info = iMovie->VideoClipInfo( iIndex );
       
  1138 //	TTimeIntervalMicroSeconds intraPos = info->VideoFrameStartTimeL( 
       
  1139 //			info->GetVideoFrameIndexL( pos ) );
       
  1140 
       
  1141 	if (iMovie->VideoClipCutInTime(iIndex) < pos)
       
  1142 		{			
       
  1143 		StopNaviPaneUpdateL();
       
  1144 		iMovie->VideoClipSetCutOutTime( iIndex, pos );
       
  1145 		LOGFMT2(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkOutL, 2, iIndex:%d, pos:%Ld", iIndex, pos.Int64() );		
       
  1146 		iContainer->MarkedOutL();
       
  1147 		}
       
  1148 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MarkOutL, Out");
       
  1149 	}
       
  1150 
       
  1151 
       
  1152 void CVeiSimpleCutVideoView::MoveStartOrEndMarkL(TTimeIntervalMicroSeconds aPosition, CVeiSimpleCutVideoContainer::TCutMark aMarkType)
       
  1153 	{
       
  1154 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MoveStartOrEndMarkL, In");
       
  1155 	
       
  1156 	StopNaviPaneUpdateL();
       
  1157 	
       
  1158 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MoveStartOrEndMarkL, 2");
       
  1159 	
       
  1160 	if (aMarkType == CVeiSimpleCutVideoContainer::EStartMark)
       
  1161 		{
       
  1162 		iMovie->VideoClipSetCutInTime( iIndex, aPosition);
       
  1163 		}
       
  1164 	else if (aMarkType == CVeiSimpleCutVideoContainer::EEndMark)
       
  1165 		{
       
  1166 		iMovie->VideoClipSetCutOutTime( iIndex, aPosition);
       
  1167 		}		
       
  1168 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::MoveStartOrEndMarkL, Out");
       
  1169 	}
       
  1170 
       
  1171 TUint CVeiSimpleCutVideoView::InPointTime()
       
  1172 	{
       
  1173 	if ( !iMovie )
       
  1174 		{
       
  1175 		return 0;
       
  1176 		}
       
  1177 	else
       
  1178 		{
       
  1179 		return static_cast<TInt32>((iMovie->VideoClipCutInTime(iIndex).Int64() / 1000));
       
  1180 		}
       
  1181 	}
       
  1182 
       
  1183 TUint CVeiSimpleCutVideoView::OutPointTime()
       
  1184 	{
       
  1185 	if ( !iMovie )
       
  1186 		{
       
  1187 		return 0;
       
  1188 		}
       
  1189 	else
       
  1190 		{
       
  1191 		return static_cast<TInt32>(iMovie->VideoClipCutOutTime(iIndex).Int64() / 1000);
       
  1192 		}
       
  1193 	}
       
  1194 
       
  1195 TInt CVeiSimpleCutVideoView::UpdateTimeCallbackL(TAny* aPtr)
       
  1196 	{
       
  1197 	CVeiSimpleCutVideoView* view = (CVeiSimpleCutVideoView*)aPtr;
       
  1198 
       
  1199     view->UpdateTimeL();
       
  1200 
       
  1201 	return 1;
       
  1202 	}
       
  1203 
       
  1204 
       
  1205 void CVeiSimpleCutVideoView::UpdateTimeL()
       
  1206 	{
       
  1207 	DrawTimeNaviL();
       
  1208 
       
  1209 	if (iMarkState == EMarkStateIn) 
       
  1210 		{
       
  1211 		if (iContainer->PlaybackPositionL() > iMovie->VideoClipCutInTime( iIndex )) 
       
  1212 			{
       
  1213 			UpdateCBAL(iContainer->State());
       
  1214 			}
       
  1215 		}
       
  1216 	else if (iMarkState == EMarkStateOut) 
       
  1217 		{
       
  1218 		if (iContainer->PlaybackPositionL() < iMovie->VideoClipCutOutTime( iIndex )) 
       
  1219 			{
       
  1220 			UpdateCBAL(iContainer->State());
       
  1221 			}
       
  1222 		}
       
  1223 	else 
       
  1224 		{
       
  1225 		if ((iContainer->PlaybackPositionL() < iMovie->VideoClipCutInTime( iIndex )) ||
       
  1226 			(iContainer->PlaybackPositionL() > iMovie->VideoClipCutOutTime( iIndex ))) 
       
  1227 			{
       
  1228 			UpdateCBAL(iContainer->State());
       
  1229 			}
       
  1230 		}
       
  1231 	}
       
  1232 
       
  1233 void CVeiSimpleCutVideoView::DrawTimeNaviL()
       
  1234 	{
       
  1235 	TTime elapsed( iContainer->PlaybackPositionL().Int64() );
       
  1236 	TTime total( iContainer->TotalLength().Int64() );
       
  1237 	iCVeiNaviPaneControl->DrawTimeNaviL( elapsed, total );
       
  1238 	}
       
  1239 
       
  1240 
       
  1241 void CVeiSimpleCutVideoView::StartNaviPaneUpdateL()
       
  1242 	{
       
  1243 	DrawTimeNaviL();
       
  1244 	if (iTimeUpdater && !iTimeUpdater->IsActive())
       
  1245 		{
       
  1246 		iTimeUpdater->Start(200000, 1000000/10, TCallBack(CVeiSimpleCutVideoView::UpdateTimeCallbackL, this));
       
  1247 		}
       
  1248 	}
       
  1249 
       
  1250 void CVeiSimpleCutVideoView::StopNaviPaneUpdateL()
       
  1251 	{
       
  1252 	if (iContainer)
       
  1253 		{
       
  1254 		DrawTimeNaviL();
       
  1255 		}
       
  1256 	if (iTimeUpdater)
       
  1257 		{
       
  1258 		iTimeUpdater->Cancel();
       
  1259 		}
       
  1260 	}
       
  1261 
       
  1262 
       
  1263 void CVeiSimpleCutVideoView::VolumeMuteL()
       
  1264 	{
       
  1265 	iContainer->MuteL();
       
  1266 	}
       
  1267 
       
  1268 
       
  1269 
       
  1270 void CVeiSimpleCutVideoView::ShowVolumeLabelL( TInt aVolume )
       
  1271 	{
       
  1272 	iCVeiNaviPaneControl->ShowVolumeLabelL( aVolume );	
       
  1273 	}
       
  1274 
       
  1275 void CVeiSimpleCutVideoView::HandleForegroundEventL  ( TBool aForeground )
       
  1276 	{
       
  1277 	if ( !aForeground )
       
  1278 		{
       
  1279 		// If the application is closing down, calling PauseL could result in 
       
  1280 		// a callback from the MMF player after the container is already deleted,
       
  1281 		// causing KERN-EXEC 3
       
  1282 		if ( iOnTheWayToDestruction || 
       
  1283 		     static_cast<CVeiSimpleCutVideoAppUi*>( AppUi() )->AppIsOnTheWayToDestruction() )
       
  1284 			{
       
  1285 			iContainer->PrepareForTerminationL();
       
  1286 			return;
       
  1287 			}
       
  1288 		else
       
  1289 			{
       
  1290 			if( iContainer->State() == CVeiSimpleCutVideoContainer::EStatePlaying ||
       
  1291 		    	iContainer->State() == CVeiSimpleCutVideoContainer::EStatePlayingMenuOpen )
       
  1292 				{
       
  1293 				iPaused = ETrue;
       
  1294 				iContainer->PauseL( EFalse );
       
  1295 				}
       
  1296 			}
       
  1297 		}
       
  1298 	else
       
  1299 		{
       
  1300 		UpdateCBAL( iContainer->State() );
       
  1301 		if( 0 )
       
  1302 //		if( iPaused )
       
  1303 			{
       
  1304 			iPaused = EFalse;
       
  1305 			PlayPreviewL();
       
  1306 			}
       
  1307 		}
       
  1308 	}
       
  1309 
       
  1310 // ---------------------------------------------------------
       
  1311 // CVeiSimpleCutVideoView::HandleStatusPaneSizeChange()
       
  1312 // ---------------------------------------------------------
       
  1313 //
       
  1314 void CVeiSimpleCutVideoView::HandleStatusPaneSizeChange()
       
  1315     {
       
  1316     if ( iContainer )
       
  1317         {
       
  1318         iContainer->SetRect( AppUi()->ClientRect() );
       
  1319         }
       
  1320     }
       
  1321 
       
  1322 TBool CVeiSimpleCutVideoView::IsEnoughFreeSpaceToSaveL()// const
       
  1323 	{
       
  1324 	RFs&	fs = iEikonEnv->FsSession();
       
  1325 	TBool spaceBelowCriticalLevel( EFalse );
       
  1326 
       
  1327 	/* seek position of clip */
       
  1328 	TTimeIntervalMicroSeconds frame;
       
  1329 	frame = iContainer->PlaybackPositionL();
       
  1330 
       
  1331 	/* frame index of position */
       
  1332 	TInt frameIndex;
       
  1333 	frameIndex = iMovie->VideoClipInfo( iIndex )->GetVideoFrameIndexL( frame );
       
  1334 
       
  1335 	/* frame size */
       
  1336 	TInt sizeEstimate; 
       
  1337 	sizeEstimate = iMovie->VideoClipInfo( iIndex )->VideoFrameSizeL( frameIndex );
       
  1338 
       
  1339 	// In this case, we decide the target drive automatically when starting 
       
  1340 	// to save the video. Thus it is enough to know that there is free space 
       
  1341 	// on either drive at this stage.
       
  1342 	spaceBelowCriticalLevel = SysUtil::DiskSpaceBelowCriticalLevelL( &fs, sizeEstimate, EDriveC );
       
  1343 	if( spaceBelowCriticalLevel )
       
  1344 		{
       
  1345 		spaceBelowCriticalLevel = SysUtil::MMCSpaceBelowCriticalLevelL( &fs, sizeEstimate );
       
  1346 		}	
       
  1347 
       
  1348 
       
  1349 	if ( !spaceBelowCriticalLevel )
       
  1350 		{
       
  1351 		return ETrue;
       
  1352 		}
       
  1353 	else 
       
  1354 		{
       
  1355 		HBufC* stringholder;
       
  1356 		stringholder = StringLoader::LoadLC( R_VEI_MEMORY_RUNNING_OUT, iEikonEnv );
       
  1357 		CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue );
       
  1358 		dlg->ExecuteLD( *stringholder );
       
  1359 		CleanupStack::PopAndDestroy( stringholder ); 
       
  1360 
       
  1361 		return EFalse;
       
  1362 		}
       
  1363 	}
       
  1364 
       
  1365 TTimeIntervalMicroSeconds CVeiSimpleCutVideoView::GetVideoClipCutInTime()
       
  1366 	{
       
  1367 	TTimeIntervalMicroSeconds cutInTime(0);
       
  1368 	if ( iMovie )
       
  1369 		{
       
  1370 		cutInTime = iMovie->VideoClipCutInTime( iIndex );
       
  1371 		}
       
  1372 	return cutInTime;
       
  1373 	}
       
  1374 
       
  1375 TTimeIntervalMicroSeconds CVeiSimpleCutVideoView::GetVideoClipCutOutTime()
       
  1376 	{
       
  1377 	TTimeIntervalMicroSeconds cutOutTime(0);
       
  1378 	if ( iMovie )
       
  1379 		{
       
  1380 		cutOutTime = iMovie->VideoClipCutOutTime( iIndex );
       
  1381 		}
       
  1382 	return cutOutTime;
       
  1383 	}
       
  1384 
       
  1385 void CVeiSimpleCutVideoView::HandleResourceChange(TInt aType)
       
  1386     {
       
  1387     LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::HandleResourceChange() In, aType:%d", aType);
       
  1388     
       
  1389     if ( iContainer )
       
  1390     	{    	
       
  1391     	if ( aType == KEikMessageFadeAllWindows && (iContainer->State() == CVeiSimpleCutVideoContainer::EStatePlaying) )
       
  1392     		{
       
  1393     		this->PausePreviewL();
       
  1394     		iSelectionKeyPopup = ETrue;
       
  1395     		}
       
  1396     	else if ( iSelectionKeyPopup && aType == KEikMessageUnfadeWindows && (iContainer->State() == CVeiSimpleCutVideoContainer::EStatePaused) )
       
  1397     		{
       
  1398     		this->PlayPreviewL();
       
  1399     		iSelectionKeyPopup = EFalse;
       
  1400     		}
       
  1401     	}
       
  1402     
       
  1403     if (KAknsMessageSkinChange == aType)
       
  1404         {
       
  1405         // Handle skin change in the navi label controls - they do not receive 
       
  1406         // it automatically since they are not in the control stack
       
  1407         iCVeiNaviPaneControl->HandleResourceChange( aType );
       
  1408         }
       
  1409     
       
  1410     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::HandleResourceChange() Out");
       
  1411     }
       
  1412 
       
  1413 //=======================================================================================================
       
  1414 const CVedMovie* CVeiSimpleCutVideoView::Movie() const
       
  1415 	{
       
  1416 	return iMovie;
       
  1417 	}
       
  1418 
       
  1419 //=======================================================================================================
       
  1420 TBool CVeiSimpleCutVideoView::SaveL()
       
  1421 	{
       
  1422 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::SaveL: in");
       
  1423 
       
  1424 	TFileName outputFile;
       
  1425 	TBool ret = EFalse;
       
  1426 
       
  1427 	TTimeIntervalMicroSeconds cutin;
       
  1428 	TTimeIntervalMicroSeconds cutout;
       
  1429 	cutin = iMovie->VideoClipCutInTime( 0 );
       
  1430 	cutout = iMovie->VideoClipCutOutTime( 0 );
       
  1431 
       
  1432 	if ( ( cutin != TTimeIntervalMicroSeconds( 0 ) ) ||
       
  1433 		 ( cutout!= iMovie->VideoClipInfo(0)->Duration() ) )
       
  1434 		{
       
  1435 		RFs&	fs = iEikonEnv->FsSession();
       
  1436 
       
  1437 		// GenerateNewDocumentNameL also checks disk space
       
  1438 		TInt err(KErrNone);
       
  1439 		if(!iOverWriteFile)
       
  1440 			{
       
  1441 			err = VideoEditorUtils::GenerateNewDocumentNameL (
       
  1442 				fs,
       
  1443 				iMovie->VideoClipInfo( iIndex )->FileName(),
       
  1444 				outputFile,
       
  1445 				iMovie->Format(),
       
  1446 				iMovie->GetSizeEstimateL() );
       
  1447 			}
       
  1448 		else
       
  1449 			{
       
  1450 			outputFile.Zero();
       
  1451 			outputFile.Copy(iMovie->VideoClipInfo( iIndex )->FileName());
       
  1452 			}
       
  1453 		
       
  1454 		LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::SaveL: 1, err:%d", err);
       
  1455 
       
  1456 		if ( KErrNone == err )
       
  1457 			{
       
  1458 			if (iSaveToFileName)
       
  1459 				{
       
  1460 				delete iSaveToFileName;
       
  1461 				iSaveToFileName = NULL;	
       
  1462 				}
       
  1463 			iSaveToFileName = HBufC::NewL( outputFile.Length() );
       
  1464 			*iSaveToFileName = outputFile;
       
  1465 
       
  1466 			// Start saviong the video. 
       
  1467 			// To be finished in DialogDismissedL...
       
  1468 			iSaving = ETrue;
       
  1469 			StartTempFileProcessingL();
       
  1470 
       
  1471             ret = ETrue;
       
  1472 			}
       
  1473 		else 
       
  1474 			{
       
  1475 			iErrorUI->ShowGlobalErrorNote( err );
       
  1476 			ret = EFalse;
       
  1477 			}						
       
  1478 		}
       
  1479 	else 
       
  1480 		{
       
  1481 		ret = EFalse;
       
  1482 		}
       
  1483 
       
  1484 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::SaveL: out: %d", ret);
       
  1485 
       
  1486 	return ret;
       
  1487 	}
       
  1488 
       
  1489 
       
  1490 //=============================================================================
       
  1491 TInt CVeiSimpleCutVideoView::QueryAndSaveL()
       
  1492 {
       
  1493 
       
  1494 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::QueryAndSaveL: in");
       
  1495 
       
  1496 	TFileName outputFile;
       
  1497 	TBool ret = EFalse;
       
  1498 
       
  1499 	TTimeIntervalMicroSeconds cutin;
       
  1500 	TTimeIntervalMicroSeconds cutout;
       
  1501 	cutin = iMovie->VideoClipCutInTime( 0 );
       
  1502 	cutout = iMovie->VideoClipCutOutTime( 0 );
       
  1503 
       
  1504 	if ( ( cutin != TTimeIntervalMicroSeconds( 0 ) ) ||
       
  1505 		 ( cutout!= iMovie->VideoClipInfo(0)->Duration() ) )
       
  1506 		{
       
  1507 		RFs	fs = CCoeEnv::Static()->FsSession();
       
  1508 
       
  1509 
       
  1510  		// launch query with choices "Replace original" and "Save with a new file name" 
       
  1511  		TInt userSelection = VideoEditorUtils::LaunchSaveVideoQueryL(); 
       
  1512  		
       
  1513 	  	if(userSelection == 0) 
       
  1514 	  	// the user selects to save with a new file name
       
  1515 			{
       
  1516 			iOverWriteFile = EFalse;
       
  1517 
       
  1518             // Multiple drive support enabled
       
  1519 #ifdef RD_MULTIPLE_DRIVE	
       
  1520 		    TDriveNumber driveNumber;
       
  1521             TFileName driveAndPath;
       
  1522             CAknMemorySelectionDialogMultiDrive* multiDriveDlg = CAknMemorySelectionDialogMultiDrive::NewL(ECFDDialogTypeSave, EFalse );			
       
  1523 		    CleanupStack::PushL( multiDriveDlg );
       
  1524 		    
       
  1525 			// launch "Select memory" query
       
  1526             if (multiDriveDlg->ExecuteL( driveNumber, &driveAndPath, NULL ))
       
  1527     			{
       
  1528 	    		outputFile.Zero();				
       
  1529 			
       
  1530 		    	// Generate a default name for the new file
       
  1531 			    TInt err = VideoEditorUtils::GenerateFileNameL (
       
  1532                                     					fs,
       
  1533                                     					iMovie->VideoClipInfo( iIndex )->FileName(),		
       
  1534                                     					outputFile,
       
  1535                                     					iMovie->Format(),
       
  1536                                     					iMovie->GetSizeEstimateL(),
       
  1537                                     					driveAndPath);	
       
  1538 				
       
  1539                 driveAndPath.Append( PathInfo::VideosPath() );					
       
  1540 				
       
  1541 			    if ( KErrNone == err )
       
  1542 					{
       
  1543 					if (iSaveToFileName)
       
  1544 						{
       
  1545 						delete iSaveToFileName;
       
  1546 						iSaveToFileName = NULL;	
       
  1547 						}				 
       
  1548 
       
  1549 					// launch file name prompt dialog
       
  1550 					if (CAknFileNamePromptDialog::RunDlgLD(outputFile, driveAndPath, KNullDesC))
       
  1551 						{
       
  1552 						driveAndPath.Append(outputFile);
       
  1553 						outputFile.Copy(driveAndPath);
       
  1554 						iSaveToFileName = HBufC::NewL( outputFile.Length() );
       
  1555 						*iSaveToFileName = outputFile;
       
  1556 
       
  1557 						// Start saving the video. 
       
  1558 						// To be finished in DialogDismissedL...
       
  1559 						iSaving = ETrue;
       
  1560 						StartTempFileProcessingL();
       
  1561 
       
  1562 			            ret = ETrue;
       
  1563 			            }
       
  1564 					}
       
  1565 				else // err != KErrNone 
       
  1566 					{
       
  1567 					ret = EFalse;
       
  1568 					}						
       
  1569     			}
       
  1570 		    CleanupStack::PopAndDestroy( multiDriveDlg );
       
  1571 #else // no multiple drive support
       
  1572 			// launch "Select memory" query
       
  1573 		    CAknMemorySelectionDialog::TMemory selectedMemory(CAknMemorySelectionDialog::EPhoneMemory);		
       
  1574 			if (CAknMemorySelectionDialog::RunDlgLD(selectedMemory))
       
  1575 				{
       
  1576 				// create path for the image	
       
  1577 				TFileName driveAndPath;        		
       
  1578 				VideoEditor::TMemory memorySelection = VideoEditor::EMemPhoneMemory;		 
       
  1579 				if (selectedMemory == CAknMemorySelectionDialog::EPhoneMemory)
       
  1580 					{
       
  1581 					memorySelection = VideoEditor::EMemPhoneMemory;
       
  1582 					driveAndPath.Copy( PathInfo::PhoneMemoryRootPath() );
       
  1583 					driveAndPath.Append( PathInfo::VideosPath() );							
       
  1584 					}
       
  1585 				else if (selectedMemory == CAknMemorySelectionDialog::EMemoryCard)
       
  1586 					{	
       
  1587 					memorySelection = VideoEditor::EMemMemoryCard;				
       
  1588 					driveAndPath.Copy( PathInfo::MemoryCardRootPath() );
       
  1589 					driveAndPath.Append( PathInfo::VideosPath() );							
       
  1590 					}        				 
       
  1591 
       
  1592 				// GenerateNewDocumentNameL also checks disk space
       
  1593 				TInt err = VideoEditorUtils::GenerateNewDocumentNameL (
       
  1594 					fs,
       
  1595 					iMovie->VideoClipInfo( iIndex )->FileName(),
       
  1596 					outputFile,
       
  1597 					iMovie->Format(),
       
  1598 					iMovie->GetSizeEstimateL(),
       
  1599 					memorySelection );
       
  1600 					
       
  1601 				if ( KErrNone == err )
       
  1602 					{
       
  1603 					if (iSaveToFileName)
       
  1604 						{
       
  1605 						delete iSaveToFileName;
       
  1606 						iSaveToFileName = NULL;	
       
  1607 						}				 
       
  1608 
       
  1609 					// launch file name prompt dialog
       
  1610 					if (CAknFileNamePromptDialog::RunDlgLD(outputFile, driveAndPath, KNullDesC))
       
  1611 						{
       
  1612 						driveAndPath.Append(outputFile);
       
  1613 						outputFile.Copy(driveAndPath);
       
  1614 						iSaveToFileName = HBufC::NewL( outputFile.Length() );
       
  1615 						*iSaveToFileName = outputFile;
       
  1616 
       
  1617 						// Start saving the video. 
       
  1618 						// To be finished in DialogDismissedL...
       
  1619 						iSaving = ETrue;
       
  1620 						StartTempFileProcessingL();
       
  1621 
       
  1622 			            ret = ETrue;
       
  1623 			            }
       
  1624 					}
       
  1625 				else // err != KErrNone 
       
  1626 					{
       
  1627 					ret = EFalse;
       
  1628 					}						
       
  1629 				}
       
  1630 #endif				
       
  1631 			}
       
  1632 		// user selects to overwrite
       
  1633 		else if (userSelection == 1)
       
  1634 		
       
  1635 			{
       
  1636 			iOverWriteFile = ETrue;
       
  1637 			ret = SaveL();
       
  1638 			return ret;	
       
  1639 			}
       
  1640 		else // user cancelled
       
  1641 			{
       
  1642 			ret = EFalse;
       
  1643 			}
       
  1644 		}
       
  1645 	else 
       
  1646 		{
       
  1647 		ret = EFalse;
       
  1648 		}
       
  1649 
       
  1650 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::QueryAndSaveL: out: %d", ret);
       
  1651 
       
  1652 	return ret;
       
  1653 }
       
  1654 
       
  1655 
       
  1656 
       
  1657 //=======================================================================================================
       
  1658 TBool CVeiSimpleCutVideoView::IsCutMarkSet()
       
  1659 	{
       
  1660 	ASSERT( iMovie ); // We always have iMovie
       
  1661 	TTimeIntervalMicroSeconds cutIn( iMovie->VideoClipCutInTime( iIndex ) ); 
       
  1662 	TTimeIntervalMicroSeconds cutOut( iMovie->VideoClipCutOutTime( iIndex ) ); 
       
  1663 	TTimeIntervalMicroSeconds duration( iMovie->VideoClipInfo(iIndex)->Duration() );
       
  1664 	// cutIn or cutOut mark is set
       
  1665 	return (cutIn != TTimeIntervalMicroSeconds( 0 ) || cutOut != duration);
       
  1666 	}
       
  1667 
       
  1668 //=======================================================================================================
       
  1669 void CVeiSimpleCutVideoView::StartTempFileProcessingL()
       
  1670 	{
       
  1671 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::StartTempFileProcessingL: in");
       
  1672 
       
  1673 	RFs&	fs = iEikonEnv->FsSession();
       
  1674 
       
  1675 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::StartTempFileProcessingL() -- NEW TEMP");
       
  1676 
       
  1677 	if (iTempFile)
       
  1678 		{
       
  1679 		delete iTempFile;
       
  1680 		iTempFile = NULL;
       
  1681 		}
       
  1682 	iTempFile = HBufC::NewL(KMaxFileName);
       
  1683 	iTempMaker->GenerateTempFileName( *iTempFile, iMovieSaveSettings.MemoryInUse(), iMovie->Format() );
       
  1684 	LOGFMT(KVideoEditorLogFile, "CVeiSimpleCutVideoView::StartTempFileProcessingL: 1, iTempFile:%S", iTempFile);
       
  1685 
       
  1686 	if ( !IsEnoughFreeSpaceToSaveL() )
       
  1687 		{
       
  1688 		LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::StartTempFileProcessingL: 2");
       
  1689 		return;
       
  1690 		}
       
  1691 
       
  1692 	iMovie->ProcessL( *iTempFile, *this );
       
  1693 
       
  1694 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::StartTempFileProcessingL: out");
       
  1695 	}
       
  1696 
       
  1697 //=======================================================================================================
       
  1698 void CVeiSimpleCutVideoView::ShowErrorNoteL( const TInt aResourceId, TInt aError ) const
       
  1699 	{
       
  1700 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::ShowErrorNoteL: in");
       
  1701 
       
  1702 	HBufC* stringholder;
       
  1703 	if ( aError == 0 )
       
  1704 		{
       
  1705 		stringholder = StringLoader::LoadLC( aResourceId, iEikonEnv );
       
  1706 		}
       
  1707 	else
       
  1708 		{
       
  1709 		stringholder = StringLoader::LoadLC( aResourceId, aError, iEikonEnv );
       
  1710 		}
       
  1711 
       
  1712 	CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue );
       
  1713 	dlg->ExecuteLD( *stringholder );
       
  1714 
       
  1715 	CleanupStack::PopAndDestroy( stringholder );
       
  1716 
       
  1717 	LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::ShowErrorNoteL: out");
       
  1718 	}
       
  1719 
       
  1720 //=======================================================================================================
       
  1721 
       
  1722 void CVeiSimpleCutVideoView::StartProgressNoteL()
       
  1723 {
       
  1724 	iProgressNote = 
       
  1725 		new (ELeave) CAknProgressDialog(REINTERPRET_CAST(CEikDialog**, 
       
  1726 		&iProgressNote), ETrue);
       
  1727 	iProgressNote->SetCallback(this);
       
  1728 	iProgressNote->ExecuteDlgLD( R_VEI_PROGRESS_NOTE_WITH_CANCEL );
       
  1729 
       
  1730 	HBufC* stringholder;
       
  1731     TApaAppCaption caption;
       
  1732     TRAPD( err, iContainer->ResolveCaptionNameL( caption ) );
       
  1733     
       
  1734     // If something goes wrong, show basic "Saving" note
       
  1735     if ( err )
       
  1736         {
       
  1737         stringholder = iEikonEnv->AllocReadResourceLC( R_VEI_PROGRESS_NOTE_SAVING );
       
  1738         }
       
  1739     else
       
  1740         {
       
  1741         stringholder = StringLoader::LoadLC( R_VEI_PROGRESS_NOTE_CUTTING_VIDEO, caption, iEikonEnv );
       
  1742         }        
       
  1743 
       
  1744 	iProgressNote->SetTextL( *stringholder );
       
  1745 	CleanupStack::PopAndDestroy( stringholder );	
       
  1746 	
       
  1747 	iProgressNote->GetProgressInfoL()->SetFinalValue(100);	
       
  1748 }
       
  1749 
       
  1750 //=======================================================================================================
       
  1751 void CVeiSimpleCutVideoView::StartAnimatedProgressNoteL()
       
  1752 {
       
  1753 	if (iAnimatedProgressDialog)
       
  1754     	{
       
  1755     	delete iAnimatedProgressDialog;
       
  1756     	iAnimatedProgressDialog = NULL;
       
  1757     	}
       
  1758     	
       
  1759    
       
  1760 	iAnimatedProgressDialog = new (ELeave) CExtProgressDialog( &iAnimatedProgressDialog);
       
  1761 	iAnimatedProgressDialog->PrepareLC(R_WAIT_DIALOG);	
       
  1762 	iAnimatedProgressDialog->SetCallback( this );
       
  1763 	
       
  1764 	HBufC* stringholder = StringLoader::LoadLC( R_VEI_PROGRESS_NOTE_CUTTING_VIDEO, iEikonEnv );
       
  1765 	iAnimatedProgressDialog->SetTextL( *stringholder );
       
  1766 	CleanupStack::PopAndDestroy(stringholder);
       
  1767 	
       
  1768 	iAnimatedProgressDialog->SetAnimationResourceIdL( VideoEditor::EAnimationCut );
       
  1769 	iAnimatedProgressDialog->GetProgressInfoL()->SetFinalValue( 100 );
       
  1770 	iAnimatedProgressDialog->StartAnimationL();
       
  1771 	iAnimatedProgressDialog->RunLD();
       
  1772 }
       
  1773 
       
  1774 // ----------------------------------------------------------------------------
       
  1775 // CVeiSimpleCutVideoView::CheckMemoryCardAvailability()
       
  1776 //
       
  1777 //  Checks the memory card availability if MMC is selected as save store in
       
  1778 //  application settings. An information note is shown in following
       
  1779 //  situations:
       
  1780 //  - MMC not inserted
       
  1781 //  - MMC corrupted (unformatted)
       
  1782 //  [- MMC is read-only (not implemented)]
       
  1783 //  
       
  1784 //  If note is popped up, this function waits until it's dismissed.
       
  1785 // ----------------------------------------------------------------------------
       
  1786 //
       
  1787 void CVeiSimpleCutVideoView::CheckMemoryCardAvailabilityL()
       
  1788     {
       
  1789     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::CheckMemoryCardAvailability(): in");
       
  1790 
       
  1791     // Read the video editor settings from ini file.
       
  1792         
       
  1793     STATIC_CAST(CVeiSimpleCutVideoAppUi*,AppUi())->ReadSettingsL( iMovieSaveSettings );
       
  1794     
       
  1795     CAknMemorySelectionDialog::TMemory memoryInUse( iMovieSaveSettings.MemoryInUse() );
       
  1796 
       
  1797     // Check the MMC accessibility only if MMC is used as saving store.
       
  1798     if( memoryInUse == CAknMemorySelectionDialog::EMemoryCard )
       
  1799         {
       
  1800         RFs& fs = iEikonEnv->FsSession();
       
  1801         TDriveInfo driveInfo;
       
  1802         
       
  1803         User::LeaveIfError( fs.Drive( driveInfo, KMmcDrive ) );
       
  1804 
       
  1805         // Media is not present (MMC card not inserted).
       
  1806         if( EMediaNotPresent == driveInfo.iType )
       
  1807             {
       
  1808             LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::CheckMemoryCardAvailability(): no media");
       
  1809             
       
  1810             iMovieSaveSettings.MemoryInUse() = CAknMemorySelectionDialog::EPhoneMemory;
       
  1811             // do not overwrite because doing so permanently sets memory to phone memory
       
  1812 			//STATIC_CAST( CVeiSimpleCutVideoAppUi*, AppUi() )->WriteSettingsL( settings );
       
  1813     	    }
       
  1814         // Media is present
       
  1815         else
       
  1816             {
       
  1817             LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::CheckMemoryCardAvailability(): media present");
       
  1818 
       
  1819             TVolumeInfo volumeInfo;
       
  1820             TInt volumeErr = fs.Volume( volumeInfo, KMmcDrive );
       
  1821             LOGFMT(KVideoEditorLogFile, "CEditVideoView::CheckMemoryCardAvailability() Volume(): %d", volumeErr);
       
  1822 
       
  1823             // Show note if media is corrupted/unformatted.
       
  1824             if( KErrCorrupt == volumeErr )
       
  1825                 {
       
  1826                 HBufC* noteText = StringLoader::LoadLC( R_VED_MMC_NOT_INSERTED,
       
  1827                                                     iEikonEnv );
       
  1828                 CAknInformationNote* informationNote = 
       
  1829                                 new(ELeave)CAknInformationNote( ETrue );
       
  1830                 informationNote->ExecuteLD( *noteText );
       
  1831 
       
  1832                 CleanupStack::PopAndDestroy( noteText );
       
  1833 
       
  1834 				iMovieSaveSettings.MemoryInUse() = CAknMemorySelectionDialog::EPhoneMemory;
       
  1835 				// do not overwrite because doing so permanently sets memory to phone memory
       
  1836 				//STATIC_CAST( CVeiSimpleCutVideoAppUi*, AppUi() )->WriteSettingsL( settings );
       
  1837                 }
       
  1838             }
       
  1839         }
       
  1840 
       
  1841     LOG(KVideoEditorLogFile, "CVeiSimpleCutVideoView::CheckMemoryCardAvailability(): out");
       
  1842     }
       
  1843 
       
  1844 void CVeiSimpleCutVideoView::PrepareForTermination()
       
  1845 	{
       
  1846 	iOnTheWayToDestruction = ETrue;
       
  1847 	}
       
  1848 
       
  1849 void CVeiSimpleCutVideoView::SetTitlePaneTextL ()
       
  1850 {
       
  1851 
       
  1852 	TPtrC fileName = iMovie->VideoClipInfo( iIndex )->FileName();
       
  1853 	HBufC * title_text = HBufC::NewLC( fileName.Length() );
       
  1854 	TPtr title_text_ptr = title_text->Des();
       
  1855 			
       
  1856 	title_text_ptr.Copy (fileName);
       
  1857 	TParsePtr parser (title_text_ptr); 
       
  1858 	title_text_ptr = parser.Name();
       
  1859 	
       
  1860     //  Set title pane text
       
  1861    	CEikStatusPane *statusPane = ( ( CAknAppUi* )iEikonEnv->EikAppUi() )->StatusPane();
       
  1862     CAknTitlePane* titlePane = ( CAknTitlePane* ) statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) );
       
  1863 	titlePane->SetTextL(title_text_ptr);
       
  1864 	
       
  1865 	CleanupStack::PopAndDestroy( title_text ); 
       
  1866 }
       
  1867 
       
  1868 // End of File
       
  1869