videoplayback/videoplaybackviews/src/mpxvideoplaybackcontainer.cpp
changeset 0 96612d01cf9f
child 9 5294c000a26d
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of Video playback view's container.
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 22 %
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include <w32std.h> // RWindowBase
       
    25 #include <e32base.h>
       
    26 #include <StringLoader.h>
       
    27 #include <AknUtils.h>
       
    28 #include <eikclbd.h>
       
    29 #include <aknconsts.h>
       
    30 #include <AknUtils.h>
       
    31 #include <AknIconUtils.h>  // SetSize for the icons
       
    32 #include <remconcoreapi.h>
       
    33 #include <remconcoreapitarget.h>
       
    34 #include <remconinterfaceselector.h> // Side volume key
       
    35 #include <data_caging_path_literals.hrh> // KDC_APP_BITMAP_DIR
       
    36 #include <aknlayoutscalable_apps.cdl.h>
       
    37 #include <aknlayoutscalable_avkon.cdl.h>
       
    38 #include <mpxvideoplaybackviews.rsg>
       
    39 
       
    40 #include "mpxcommonvideoplaybackview.hrh"
       
    41 #include "mpxvideoplaybackview.h"
       
    42 #include "mpxvideoplaybackviewfiledetails.h"
       
    43 #include "mpxvideoplaybackcontainer.h"
       
    44 #include "mpxvideoplaybackcontrolscontroller.h"
       
    45 #include "mpxvideoplaybackuserinputhandler.h"
       
    46 #include <mpxvideoplaybackdefs.h>
       
    47 #include "mpxvideo_debug.h"
       
    48 
       
    49 using namespace AknLayoutScalable_Apps;
       
    50 
       
    51 // CONSTANTS
       
    52 
       
    53 // ======== MEMBER FUNCTIONS =======================================================================
       
    54 
       
    55 // -------------------------------------------------------------------------------------------------
       
    56 // CMPXVideoPlaybackContainer::CMPXVideoPlaybackContainer()
       
    57 // -------------------------------------------------------------------------------------------------
       
    58 //
       
    59 CMPXVideoPlaybackContainer::CMPXVideoPlaybackContainer( CMPXVideoBasePlaybackView* aView )
       
    60     : iView( aView )
       
    61 {
       
    62 }
       
    63 
       
    64 // -------------------------------------------------------------------------------------------------
       
    65 // CMPXVideoPlaybackContainer::NewL()
       
    66 // -------------------------------------------------------------------------------------------------
       
    67 //
       
    68 CMPXVideoPlaybackContainer* CMPXVideoPlaybackContainer::NewL( CMPXVideoBasePlaybackView* aView )
       
    69 {
       
    70     MPX_DEBUG(_L("CMPXVideoPlaybackContainer::NewL()"));
       
    71 
       
    72     CMPXVideoPlaybackContainer* self = new (ELeave) CMPXVideoPlaybackContainer( aView );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop();
       
    76     return self;
       
    77 }
       
    78 
       
    79 // -------------------------------------------------------------------------------------------------
       
    80 // CMPNormalScreenPlaybackContainer::ConstructL
       
    81 // Symbian 2nd phase constructor can leave.
       
    82 // -------------------------------------------------------------------------------------------------
       
    83 //
       
    84 void CMPXVideoPlaybackContainer::ConstructL()
       
    85 {
       
    86     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::ConstructL()"));
       
    87 
       
    88     SetMopParent( iView );
       
    89     CreateWindowL();
       
    90 
       
    91     TAknWindowLineLayout screenLayout = AknLayout::screen();
       
    92     TRect screenRect = screenLayout.Rect();
       
    93 
       
    94     SetRect( screenRect );
       
    95 
       
    96     CreateControlsL();
       
    97 
       
    98     iUserInputHandler =
       
    99         CMPXVideoPlaybackUserInputHandler::NewL( this, iFileDetails->iTvOutConnected );
       
   100 
       
   101     ActivateL();
       
   102 }
       
   103 
       
   104 // -------------------------------------------------------------------------------------------------
       
   105 // CMPXVideoPlaybackContainer::~CMPXVideoPlaybackContainer()
       
   106 // -------------------------------------------------------------------------------------------------
       
   107 //
       
   108 CMPXVideoPlaybackContainer::~CMPXVideoPlaybackContainer()
       
   109 {
       
   110     if ( iFileDetails )
       
   111     {
       
   112         delete iFileDetails;
       
   113         iFileDetails = NULL;
       
   114     }
       
   115 
       
   116     if ( iControlsController )
       
   117     {
       
   118         delete iControlsController;
       
   119         iControlsController = NULL;
       
   120     }
       
   121 
       
   122     if ( iUserInputHandler )
       
   123     {
       
   124         delete iUserInputHandler;
       
   125         iUserInputHandler = NULL;
       
   126     }
       
   127 
       
   128     CloseWindow();
       
   129 }
       
   130 
       
   131 // -------------------------------------------------------------------------------------------------
       
   132 // CMPXVideoPlaybackContainer::AddFileDetailsL()
       
   133 // -------------------------------------------------------------------------------------------------
       
   134 //
       
   135 void CMPXVideoPlaybackContainer::AddFileDetailsL( CMPXVideoPlaybackViewFileDetails* aDetails )
       
   136 {
       
   137     iControlsController->AddFileDetailsL( aDetails );
       
   138 
       
   139     //
       
   140     //  Delete the temp file details since plugin initialization is complete
       
   141     //
       
   142     if ( iFileDetails )
       
   143     {
       
   144         delete iFileDetails;
       
   145         iFileDetails = NULL;
       
   146     }
       
   147 }
       
   148 
       
   149 // -------------------------------------------------------------------------------------------------
       
   150 // CMPXVideoPlaybackContainer::GetWindow()
       
   151 // -------------------------------------------------------------------------------------------------
       
   152 //
       
   153 RWindow& CMPXVideoPlaybackContainer::GetWindow() const
       
   154 {
       
   155     return Window();
       
   156 }
       
   157 
       
   158 // -------------------------------------------------------------------------------------------------
       
   159 // From CCoeControl
       
   160 // Handles key events.
       
   161 // -------------------------------------------------------------------------------------------------
       
   162 //
       
   163 TKeyResponse CMPXVideoPlaybackContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   164                                                          TEventCode aType )
       
   165 {
       
   166     MPX_ENTER_EXIT(
       
   167         _L("CMPXVideoPlaybackContainer::OfferKeyEventL()"),
       
   168         _L("iCode = %d iScanCode = %d aType = %d"),
       
   169         aKeyEvent.iCode, aKeyEvent.iScanCode, aType );
       
   170 
       
   171     iKeyResponse = EKeyWasNotConsumed;
       
   172 
       
   173     iUserInputHandler->ProcessKeyEventL( aKeyEvent, aType );
       
   174 
       
   175     return iKeyResponse;
       
   176 }
       
   177 
       
   178 
       
   179 // -------------------------------------------------------------------------------------------------
       
   180 // CMPXVideoPlaybackContainer::DoHandleKeyEventL()
       
   181 // -------------------------------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C void
       
   184 CMPXVideoPlaybackContainer::DoHandleKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   185 {
       
   186     MPX_DEBUG(_L("CMPXVideoPlaybackContainer::DoHandleKeyEventL()"));
       
   187 
       
   188     switch ( aKeyEvent.iScanCode )
       
   189     {
       
   190         case EStdKeyDevice3:        // rocker middle key
       
   191         case EStdKeyEnter:          // enter key on a qwerty key board
       
   192         {
       
   193             HandleRockerMiddleKeyL( aKeyEvent, aType );
       
   194             iKeyResponse = EKeyWasConsumed;
       
   195             break;
       
   196         }
       
   197         case EStdKeyUpArrow:        // rocker up key
       
   198         {
       
   199             if ( aType == EEventKeyDown )
       
   200             {
       
   201                 HandleCommandL( EMPXPbvCmdIncreaseVolume );
       
   202                 iKeyResponse = EKeyWasConsumed;
       
   203             }
       
   204             break;
       
   205         }
       
   206         case EStdKeyDownArrow:      // rocker down key
       
   207         {
       
   208             if ( aType == EEventKeyDown )
       
   209             {
       
   210                 HandleCommandL( EMPXPbvCmdDecreaseVolume );
       
   211                 iKeyResponse = EKeyWasConsumed;
       
   212             }
       
   213             break;
       
   214         }
       
   215         case EStdKeyLeftArrow:      // rocker left key
       
   216         {
       
   217             HandleSeekBackL(aType);
       
   218             iKeyResponse = EKeyWasConsumed;
       
   219             break;
       
   220         }
       
   221         case EStdKeyRightArrow:     // rocker right key
       
   222         {
       
   223             HandleSeekFwdL(aType);
       
   224             iKeyResponse = EKeyWasConsumed;
       
   225             break;
       
   226         }
       
   227         case EStdKeyDevice0:
       
   228         case EStdKeyDevice1:
       
   229         {
       
   230             if ( aType == EEventKeyUp )
       
   231             {
       
   232                 iControlsController->HandleEventL( EMPXControlCmdSoftKeyPressed,
       
   233                 		                           aKeyEvent.iScanCode );
       
   234             }
       
   235 
       
   236             iKeyResponse = EKeyWasConsumed;
       
   237             break;
       
   238         }
       
   239     }
       
   240 }
       
   241 
       
   242 // -------------------------------------------------------------------------------------------------
       
   243 // Handles rocker's middle key =>  Toggles between play & pause
       
   244 // -------------------------------------------------------------------------------------------------
       
   245 //
       
   246 void CMPXVideoPlaybackContainer::HandleRockerMiddleKeyL(const TKeyEvent& aKeyEvent,
       
   247                                                        TEventCode aType)
       
   248 {
       
   249     if ( aKeyEvent.iCode == EKeyNull && aType == EEventKeyDown  )
       
   250     {
       
   251         iView->HandleCommandL(EMPXPbvCmdPlayPause);
       
   252     }
       
   253 }
       
   254 
       
   255 // -------------------------------------------------------------------------------------------------
       
   256 // Starts/Stops Seeking Forward
       
   257 // -------------------------------------------------------------------------------------------------
       
   258 //
       
   259 void CMPXVideoPlaybackContainer::HandleSeekFwdL(TEventCode aType)
       
   260 {
       
   261     if (aType == EEventKeyDown)
       
   262     {
       
   263         iView->HandleCommandL(EMPXPbvCmdSeekForward);
       
   264     }
       
   265     else if (aType == EEventKeyUp)
       
   266     {
       
   267         iView->HandleCommandL(EMPXPbvCmdEndSeek);
       
   268     }
       
   269 }
       
   270 
       
   271 // -------------------------------------------------------------------------------------------------
       
   272 // Starts/Stops Seeking Backward
       
   273 // -------------------------------------------------------------------------------------------------
       
   274 //
       
   275 void CMPXVideoPlaybackContainer::HandleSeekBackL(TEventCode aType)
       
   276 {
       
   277     if (aType == EEventKeyDown)
       
   278     {
       
   279         iView->HandleCommandL(EMPXPbvCmdSeekBackward);
       
   280     }
       
   281     else if (aType == EEventKeyUp)
       
   282     {
       
   283         iView->HandleCommandL(EMPXPbvCmdEndSeek);
       
   284     }
       
   285 }
       
   286 
       
   287 // -------------------------------------------------------------------------------------------------
       
   288 // From CCoeControl
       
   289 // Handles a change to the control's resources.
       
   290 // -------------------------------------------------------------------------------------------------
       
   291 //
       
   292 void CMPXVideoPlaybackContainer::HandleResourceChange( TInt aType )
       
   293 {
       
   294     CCoeControl::HandleResourceChange( aType );
       
   295 }
       
   296 
       
   297 // -------------------------------------------------------------------------------------------------
       
   298 // From CCoeControl
       
   299 // Gets the control's help context.
       
   300 // -------------------------------------------------------------------------------------------------
       
   301 //
       
   302 void CMPXVideoPlaybackContainer::GetHelpContext( TCoeHelpContext& /*aContext*/ ) const
       
   303 {
       
   304     //aContext.iMajor = KAppUidMusicPlayerX;
       
   305 }
       
   306 
       
   307 // -------------------------------------------------------------------------------------------------
       
   308 // From CCoeControl
       
   309 // Gets the number of controls contained in a compound control.
       
   310 // -------------------------------------------------------------------------------------------------
       
   311 //
       
   312 TInt CMPXVideoPlaybackContainer::CountComponentControls() const
       
   313 {
       
   314 	TInt count = 0;
       
   315 
       
   316 	if ( iRealOneBitmap )
       
   317 	{
       
   318         count = 1;
       
   319 	}
       
   320 
       
   321 	return count;
       
   322 }
       
   323 
       
   324 // -------------------------------------------------------------------------------------------------
       
   325 // From CCoeControl
       
   326 // Gets an indexed component of a compound control.
       
   327 // -------------------------------------------------------------------------------------------------
       
   328 //
       
   329 CCoeControl* CMPXVideoPlaybackContainer::ComponentControl( TInt aIndex ) const
       
   330 {
       
   331     CCoeControl* control = NULL;
       
   332 
       
   333     switch ( aIndex )
       
   334     {
       
   335         case 0:
       
   336         {
       
   337             control = iRealOneBitmap;
       
   338             break;
       
   339         }
       
   340     }
       
   341 
       
   342     return control;
       
   343 }
       
   344 
       
   345 // -------------------------------------------------------------------------------------------------
       
   346 // CMPXVideoPlaybackContainer::HandlePointerEventL()
       
   347 // -------------------------------------------------------------------------------------------------
       
   348 //
       
   349 void CMPXVideoPlaybackContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   350 {
       
   351     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::HandlePointerEventL()"));
       
   352 
       
   353     iUserInputHandler->ProcessPointerEventL(this, aPointerEvent, EMpxVideoPlaybackContainer);
       
   354 }
       
   355 
       
   356 
       
   357 // -------------------------------------------------------------------------------------------------
       
   358 // CMPXVideoPlaybackContainer::DoHandlePointerEventL()
       
   359 //
       
   360 // Gets called from the Controls Controller
       
   361 // only if if OK to handle pointer events
       
   362 // -------------------------------------------------------------------------------------------------
       
   363 //
       
   364 EXPORT_C void CMPXVideoPlaybackContainer::DoHandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   365 {
       
   366     MPX_DEBUG(_L("CMPXVideoPlaybackContainer::DoHandlePointerEventL()"));
       
   367 
       
   368     if ( AknLayoutUtils::PenEnabled() && aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   369     {
       
   370         iControlsController->HandleEventL( EMPXControlCmdToggleVisibility );
       
   371     }
       
   372 }
       
   373 
       
   374 // -------------------------------------------------------------------------------------------------
       
   375 //   CMPXVideoPlaybackContainer::Draw()
       
   376 // -------------------------------------------------------------------------------------------------
       
   377 //
       
   378 void CMPXVideoPlaybackContainer::Draw( const TRect& aRect ) const
       
   379 {
       
   380     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::Draw()"));
       
   381 
       
   382     CWindowGc& gc = SystemGc();
       
   383     
       
   384     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   385 
       
   386     //
       
   387     //  Make the window transparent when a surface has been created
       
   388     //  unless TV-Out is connected
       
   389     //
       
   390     if ( iSurfaceCreated && ! iTvOutConnected )
       
   391     {
       
   392         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   393 
       
   394         if ( Window().DisplayMode() == EColor16MAP )
       
   395         {
       
   396             gc.SetBrushColor( TRgb::Color16MAP(255) );
       
   397         }
       
   398         else if ( Window().DisplayMode() == EColor16MA )
       
   399         {
       
   400             gc.SetBrushColor( TRgb::Color16MA(0) );
       
   401         }
       
   402 
       
   403         gc.Clear( aRect );
       
   404     }
       
   405     else
       
   406     {
       
   407         //
       
   408         //  Set the background to black
       
   409         //
       
   410         gc.SetBrushColor( KRgbBlack );
       
   411         gc.DrawRect( aRect );
       
   412     }
       
   413 }
       
   414 
       
   415 // -------------------------------------------------------------------------------------------------
       
   416 // CMPXVideoPlaybackContainer::HandleEventL()
       
   417 // -------------------------------------------------------------------------------------------------
       
   418 //
       
   419 void CMPXVideoPlaybackContainer::HandleEventL( TMPXVideoPlaybackControlCommandIds aEvent,
       
   420                                                TInt aValue )
       
   421 {
       
   422     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::HandleEventL()"));
       
   423 
       
   424     if ( aEvent == EMPXControlCmdHandleBackgroundEvent )
       
   425     {
       
   426         iUserInputHandler->SetForeground(EFalse);
       
   427     }
       
   428     else if ( aEvent == EMPXControlCmdHandleForegroundEvent )
       
   429     {
       
   430         iUserInputHandler->SetForeground(ETrue);
       
   431     }
       
   432     else if ( aEvent == EMPXControlCmdTvOutConnected )
       
   433     {
       
   434     	iTvOutConnected = ETrue;
       
   435         iUserInputHandler->HandleTVOutEvent(ETrue);
       
   436         DrawNow();
       
   437     }
       
   438     else if ( aEvent == EMPXControlCmdTvOutDisconnected )
       
   439     {
       
   440     	iTvOutConnected = EFalse;
       
   441         iUserInputHandler->HandleTVOutEvent(EFalse);
       
   442         DrawNow();
       
   443     }
       
   444 
       
   445     iControlsController->HandleEventL( aEvent, aValue );
       
   446 }
       
   447 
       
   448 // -------------------------------------------------------------------------------------------------
       
   449 //   CMPXVideoPlaybackContainer::HandleCommandL()
       
   450 // -------------------------------------------------------------------------------------------------
       
   451 //
       
   452 EXPORT_C void CMPXVideoPlaybackContainer::HandleCommandL( TInt aCommand, TInt aValue )
       
   453 {
       
   454     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::HandleCommandL()"),
       
   455                    _L("aCommand = %d  aValue = %d"), aCommand, aValue );
       
   456 
       
   457     switch ( aCommand )
       
   458     {
       
   459         case EMPXPbvCmdSetPosition:
       
   460         {
       
   461             iView->SetPropertyL( EPbPropertyPosition, (TInt)aValue * KPbMilliMultiplier );
       
   462             break;
       
   463         }
       
   464         case EMPXPbvCmdResetControls:
       
   465         {
       
   466             //
       
   467             //  Recreate the controls with the new clip
       
   468             //
       
   469             CreateControlsL();
       
   470 
       
   471             //
       
   472             //  Retrieve the PDL information for container
       
   473             //
       
   474             iView->RetrievePdlInformationL();
       
   475 
       
   476             iControlsController->HandleEventL( EMPXControlCmdCloseFileDetailsViewer );
       
   477 
       
   478             break;
       
   479         }
       
   480         case EAknSoftkeyOptions:
       
   481         {
       
   482             static_cast<CAknView*>(iView)->ProcessCommandL( EAknSoftkeyOptions );
       
   483             break;
       
   484         }
       
   485         case EMPXPbvCmdSetVolume:
       
   486         {
       
   487             iView->SetPropertyL( EPbPropertyVolume, aValue );
       
   488             break;
       
   489         }
       
   490         case EMPXPbvSurfaceCreated:
       
   491         {
       
   492         	iSurfaceCreated = ETrue;
       
   493 			iControlsController->HandleEventL( EMPXControlCmdSurfaceCreated );
       
   494         	DrawNow();
       
   495             break;
       
   496         }
       
   497         default:
       
   498         {
       
   499             iView->HandleCommandL( aCommand );
       
   500             break;
       
   501         }
       
   502     }
       
   503 }
       
   504 
       
   505 // -------------------------------------------------------------------------------------------------
       
   506 //   CMPXVideoPlaybackContainer::CreateControlsL()
       
   507 // -------------------------------------------------------------------------------------------------
       
   508 //
       
   509 void CMPXVideoPlaybackContainer::CreateControlsL()
       
   510 {
       
   511     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackContainer::CreateControlsL()"));
       
   512 
       
   513     //
       
   514     //  Query playback plugin for filename and mode
       
   515     //
       
   516     CMPXCommand* cmd = CMPXCommand::NewL();
       
   517     CleanupStack::PushL( cmd );
       
   518 
       
   519     iView->RetrieveFileNameAndModeL( cmd );
       
   520 
       
   521     //
       
   522     //  Create a temporary file details that is populated with the
       
   523     //  file name and playback mode.  This will be delete when
       
   524     //  plugin initialization is complete
       
   525     //
       
   526     if ( iFileDetails )
       
   527     {
       
   528         delete iFileDetails;
       
   529         iFileDetails = NULL;
       
   530     }
       
   531 
       
   532     iFileDetails = CMPXVideoPlaybackViewFileDetails::NewL();
       
   533 
       
   534     TPtrC fileName( cmd->ValueText( KMPXMediaVideoPlaybackFileName ) );
       
   535     iFileDetails->iClipName = fileName.AllocL();
       
   536 
       
   537     iFileDetails->iPlaybackMode = (TMPXVideoMode) cmd->ValueTObjectL<TInt>( KMPXMediaVideoMode );
       
   538 
       
   539     iFileDetails->iTvOutConnected   = cmd->ValueTObjectL<TInt>( KMPXMediaVideoTvOutConnected );
       
   540     iFileDetails->iTvOutPlayAllowed = cmd->ValueTObjectL<TInt>( KMPXMediaVideoTvOutPlayAllowed );
       
   541 
       
   542     TPtrC mimeType( cmd->ValueText( KMPXMediaVideoRecognizedMimeType ) );
       
   543     iFileDetails->iMimeType = mimeType.AllocL();
       
   544 
       
   545     CleanupStack::PopAndDestroy( cmd );
       
   546 
       
   547     if ( iControlsController )
       
   548     {
       
   549         delete iControlsController;
       
   550         iControlsController = NULL;
       
   551     }
       
   552 
       
   553     iControlsController = CMPXVideoPlaybackControlsController::NewL( this, Rect(), iFileDetails );
       
   554 
       
   555     //
       
   556     //  Retrieve the Real One Logo bitmap
       
   557     //
       
   558     iRealOneBitmap = iControlsController->GetBitmap( EMPXRealLogoBitmap );
       
   559     iTvOutConnected = iFileDetails->iTvOutConnected;
       
   560 }
       
   561 
       
   562 // -------------------------------------------------------------------------------------------------
       
   563 //   CMPXVideoPlaybackContainer::UserInputHandler()
       
   564 // -------------------------------------------------------------------------------------------------
       
   565 //
       
   566 EXPORT_C CMPXVideoPlaybackUserInputHandler* CMPXVideoPlaybackContainer::UserInputHandler()
       
   567 {
       
   568     MPX_DEBUG(_L("CMPXVideoPlaybackContainer::UserInputHandler()"));
       
   569 
       
   570     return iUserInputHandler;
       
   571 }
       
   572 
       
   573 // EOF