VideoAppUi.cpp
上传用户:xinrui0099
上传日期:2010-03-05
资源大小:48k
文件大小:15k
- /*
- * ============================================================================
- * Name : CVideoAppUi from VideoAppUi.cpp
- * Part of : Video
- * Created : 10/14/2003 by Forum Nokia
- * Implementation notes:
- * Version :
- * Copyright: Nokia Corporation, 2003
- * ============================================================================
- */
- #include "VideoAppUi.h"
- #include "VideoContainer.h"
- #include <Video.rsg>
- #include "video.hrh"
- #include "VideoEngine.h"
- #include "VideoNaviDecoratorTime.h"
- #include "VideoFileDetailsDialog.h"
- #include <avkon.hrh>
- #include <documenthandler.h>
- #include <apmstd.h>
- #include <aknnavi.h>
- #include <aknnavide.h>
- #include <stringloader.h>
- #include <eikmenup.h>
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::ConstructL()
- Description: second phase constructor
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::ConstructL()
- {
- BaseConstructL();
- iAppContainer = new (ELeave) CVideoContainer;
- iAppContainer->SetMopParent( this );
- iAppContainer->ConstructL( ClientRect() );
- AddToStackL( iAppContainer );
- iEngine = CVideoEngine::NewL();
- // Show tabs for main views from resources
- CEikStatusPane* sp = StatusPane();
- iNaviPane = (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
- iTimeNavi = CreateTimeNaviL();
- iNaviPane->PushL( *iTimeNavi );
- // Read time format strings from AVKON resource;
- iMinSecFormatString =
- iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_MIN_SEC);
-
- iHourMinSecFormatString =
- iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_LONG);
- iCba = NULL;
- }
- /*
- -----------------------------------------------------------------------------
- CVideoAppUi::~CVideoAppUi()
- Description: destructor, free all the resources
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- CVideoAppUi::~CVideoAppUi()
- {
- if ( iAppContainer )
- {
- RemoveFromStack( iAppContainer );
- delete iAppContainer;
- }
- delete iEngine;
- delete iTimeNavi;
- delete iMinSecFormatString;
- delete iHourMinSecFormatString;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DynInitMenuPaneL(
- TInt aResourceId,CEikMenuPane* aMenuPane)
- Description: This function is called by the EIKON framework just before
- it displays a menu pane. Its default implementation is empty,
- and by overriding it, the application can set the state of menu
- items dynamically according to the state of application data.
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DynInitMenuPaneL(
- TInt aResourceId,CEikMenuPane* aMenuPane)
- {
- if ( aResourceId == R_VIDEO_MENU )
- {
- // Check whether the database has been created or not
- if ( iEngine->GetEngineState() != EPPlaying )
- {
- // The video clip is not being played
- aMenuPane->SetItemDimmed( EVideoCmdAppStop, ETrue );
- aMenuPane->SetItemDimmed( EVideoCmdAppPause, ETrue );
- }
- // If there is no item in the list box, hide the play, docplay
- // and file info menu items
- if ( !iAppContainer->GetNumOfItemsInListBox() )
- {
- aMenuPane->SetItemDimmed( EVideoCmdAppDocFileInfo, ETrue );
- aMenuPane->SetItemDimmed( EVideoCmdAppDocPlay, ETrue );
- aMenuPane->SetItemDimmed( EVideoCmdAppPlay, ETrue );
- }
- }
- }
- /*
- -----------------------------------------------------------------------------
- TKeyResponse CVideoAppUi::HandleKeyEventL(
- const TKeyEvent& aKeyEvent,TEventCode aType)
- Description: takes care of key event handling
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- TKeyResponse CVideoAppUi::HandleKeyEventL(
- const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
- {
- return EKeyWasNotConsumed;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::HandleCommandL(TInt aCommand)
- Description: takes care of command handling
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::HandleCommandL(TInt aCommand)
- {
- switch ( aCommand )
- {
- case EAknSoftkeyExit:
- case EAknSoftkeyBack:
- case EEikCmdExit:
- {
- Exit();
- break;
- }
-
- // Play command is selected
- case EVideoCmdAppPlay:
- {
- DoPlayL();
- break;
- }
- // Stop command is selected
- case EVideoCmdAppStop:
- {
- DoStopL();
- break;
- }
-
- // Pause command is selected
- case EVideoCmdAppPause:
- {
- DoPauseL();
- break;
- }
- // DocPlay command is selected
- case EVideoCmdAppDocPlay:
- {
- DoDocPlayL();
- break;
- }
- // File info command is selected
- case EVideoCmdAppDocFileInfo:
- {
- DoGetFileInfoL();
- break;
- }
-
- // Continuer command is selected
- case EVideoCmdAppContinue:
- {
- DoResumeL();
- break;
- }
- // Return command is selected
- case EVideoCmdAppReturn:
- {
- DoStopL();
- break;
- }
- default:
- break;
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoPlayL()
- Description: Call engine to play a video clip
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoPlayL()
- {
- // Set the file name first
- TFileName fileName;
- iAppContainer->GetCurrentVideoFileNameL( fileName );
- // Play the video file
- PlayVideoFileL( fileName );
- // We need change the memu to something else "Pause" and "Stop".
- iCba = CEikButtonGroupContainer::Current();
- if( iCba)
- {
- iCba->SetCommandSetL( R_VIDEO_PAUSE_STOP );
- iCba->DrawNow();
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoResumeL()
- Description: Resumes a paused video clip
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoResumeL()
- {
- if ( iEngine->GetEngineState() != EPPaused )
- return;
- iEngine->DoPlayL();
-
- // We need change the memu to something else "Pause" and "Stop".
- iCba = CEikButtonGroupContainer::Current();
- if( iCba)
- {
- iCba->SetCommandSetL( R_VIDEO_PAUSE_STOP );
- iCba->DrawNow();
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::PlayVideoFileL(TDesC &aFileName)
- Description: Play a video file
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::PlayVideoFileL(TDesC &aFileName)
- {
- // Set the file name first
- iEngine->SetNewFileL( aFileName );
- // Set time navi pane to "Loading...."
- _LIT( KLoading, "Loading..." );
- SetNaviLabelL( KLoading );
-
- // Init the controller
- DoInitControllerL();
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoStopL()
- Description: Stop a playing video file
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoStopL()
- {
- SetNaviLabelL( KNullDesC );
- iEngine->DoStop();
- iCba = CEikButtonGroupContainer::Current();
- if( iCba)
- {
- iCba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_EXIT );
- iCba->DrawNow();
- }
- // Refresh the List window.
- iAppContainer->DrawNow();
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::InitControllerCompletedL(TInt aError )
- Description: It is called when the controller is initialized
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::InitControllerCompletedL(TInt /*aError*/ )
- {
- // play it
- iEngine->DoPlayL();
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::PlayCompletedL(TInt aError )
- Description: called after a video has been completed
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::PlayCompletedL(TInt /*aError*/)
- {
-
- // The play has been completed, we need to refresh the display now.
- iAppContainer->DrawNow();
- SetNaviLabelL( KNullDesC );
- iCba = CEikButtonGroupContainer::Current();
- if( iCba)
- {
- iCba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_EXIT );
- iCba->DrawNow();
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoInitControllerL()
- Description: Initialize the video engine
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoInitControllerL()
- {
- if ( iAppContainer )
- {
- TRect tmp = iAppContainer->VideoRect();
- iEngine->InitControllerL( this, iAppContainer->ClientWsSession(),
- iAppContainer->ScreenDevice(),
- iAppContainer->ClientWindow(), tmp, tmp );
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoPauseL()
- Description: Pause a playing video clip
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoPauseL()
- {
- iEngine->DoPauseL();
- // Change the CBA to "continue" and "stop"
- iCba = CEikButtonGroupContainer::Current();
- if( iCba)
- {
- iCba->SetCommandSetL( R_VIDEO_CONTINUE_RETURN );
- iCba->DrawNow();
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoDocPlayL()
- Description: Launch a video player using a document handler
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoDocPlayL()
- {
- TDataType data = TDataType( KNullUid );
- // Set the file name first
- TFileName fileName;
- iAppContainer->GetCurrentVideoFileNameL( fileName );
- iEngine->DocumentHandlerL().OpenFileEmbeddedL( fileName, data );
- }
- /*
- -----------------------------------------------------------------------------
- CAknNavigationDecorator* CVideoAppUi::CreateTimeNaviL()
- Description: Create a Navi pane to show the time progress.
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- CAknNavigationDecorator* CVideoAppUi::CreateTimeNaviL()
- {
- CVideoNaviDecoratorTime* timeNavi = CVideoNaviDecoratorTime::NewL();
- CleanupStack::PushL(timeNavi);
- CAknNavigationDecorator* decoratedFolder =
- CAknNavigationDecorator::NewL( iNaviPane, timeNavi,
- CAknNavigationDecorator::ENotSpecified );
- CleanupStack::Pop(); // timeNavi, decoratedFolder owns it now.
-
- CleanupStack::PushL( decoratedFolder );
- decoratedFolder->SetContainerWindowL( *iNaviPane );
- timeNavi->SetContainerWindowL( *decoratedFolder);
- CleanupStack::Pop(); // decoratedFolder
-
- decoratedFolder->MakeScrollButtonVisible( EFalse );
- return decoratedFolder;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::SetNaviLabelL(TDesC &aLabel)
- Description: Set the text for the time Navi pane
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::SetNaviLabelL(const TDesC &aLabel)
- {
- CVideoNaviDecoratorTime* timeNavi =
- static_cast<CVideoNaviDecoratorTime*>(iTimeNavi->DecoratedControl());
- timeNavi->SetLabelL( aLabel);
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::DoGetFileInfoL()
- Description: Get the video file information
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::DoGetFileInfoL()
- {
- CVideoFileDetailsDialog* dlg = CVideoFileDetailsDialog::NewL();
- TFileName fileName;
- iAppContainer->GetCurrentVideoFileNameL( fileName );
- dlg->ExecuteLD( fileName);
- }
- /*
- -----------------------------------------------------------------------------
- CVideoEngine* CVideoAppUi::GetVideoEngine()
- Description: Get the video engine
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- CVideoEngine* CVideoAppUi::GetVideoEngine()
- {
- return iEngine;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoAppUi::PlaybackPositionChangedL(TInt64 aPlaybackPosInSeconds,
- TInt64 aTotalLengthInSeconds)
- Description: Set the play back time poistion (play progress)
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoAppUi::PlaybackPositionChangedL(TInt64 aPlaybackPosInSeconds, TInt64 aTotalLengthInSeconds)
- {
-
- TTime posTime = TTime( aPlaybackPosInSeconds*KMPOneSecond );
- TTime durTime = TTime( aTotalLengthInSeconds*KMPOneSecond );
- TBuf<16> pos;
- TBuf<16> dur;
- if (aTotalLengthInSeconds > 0 && aTotalLengthInSeconds < KOneHourInSeconds)
- {
- // Format time to user readable format. (min:sec)
- posTime.FormatL(pos, *iMinSecFormatString);
- durTime.FormatL(dur, *iMinSecFormatString);
- }
- else
- {
- // Format time to user readable format. (hour:min:sec)
- posTime.FormatL(pos, *iHourMinSecFormatString);
- aTotalLengthInSeconds = 0;
- }
-
- // if duration greated than 0, show postion in 00:00/00:00 format
- if (aTotalLengthInSeconds > 0)
- {
- CDesCArrayFlat* strings = new CDesCArrayFlat(2);
- CleanupStack::PushL(strings);
- strings->AppendL(pos); //First string (position)
- strings->AppendL(dur); //Second string (duration)
- HBufC* stringholder = StringLoader::LoadLC(R_VIDEO_NAVI_TIME,*strings,iEikonEnv);
- static_cast<CVideoNaviDecoratorTime*> (iTimeNavi->DecoratedControl())->SetLabelL(*stringholder);
- CleanupStack::PopAndDestroy(2); // strings & stringholder
- }
- else // show position in 00:00:00 format
- {
- static_cast<CVideoNaviDecoratorTime*>(iTimeNavi->DecoratedControl())->SetLabelL(pos);
- }
- }