videoplayback/videoplaybackcontrols/src/mpxvideoplaybackcontrol.cpp
changeset 0 96612d01cf9f
child 6 7d91903f795f
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 CMPXVideoPlaybackControl
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 18 %
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <avkon.hrh>
       
    23 #include <e32std.h>
       
    24 #include <AknUtils.h>
       
    25 
       
    26 #include "mpxcommonvideoplaybackview.hrh"
       
    27 #include "mpxvideoplaybackcontrol.h"
       
    28 #include "mpxvideoplaybackvolumebar.h"
       
    29 #include "mpxvideoplaybackbuttonbar.h"
       
    30 #include "mpxvideoplaybackprogressbar.h"
       
    31 #include "mpxvideoplaybackcontrolscontroller.h"
       
    32 #include "mpxvideoplaybackviewfiledetails.h"
       
    33 #include "mpxvideoplaybackaspectratioicon.h"
       
    34 #include "mpxvideoplaybackbrandinganimation.h"
       
    35 #include "mpxvideoplaybackuserinputhandler.h"
       
    36 #include "mpxvideoplaybackcontainer.h"
       
    37 #include "mpxvideo_debug.h"
       
    38 
       
    39 #ifdef RD_TACTILE_FEEDBACK
       
    40 #include <touchfeedback.h>
       
    41 #endif //RD_TACTILE_FEEDBACK
       
    42 
       
    43 // ================= MEMBER FUNCTIONS ==============================================================
       
    44 
       
    45 // -------------------------------------------------------------------------------------------------
       
    46 // CMPXVideoPlaybackControl::CMPXVideoPlaybackControl()
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -------------------------------------------------------------------------------------------------
       
    50 //
       
    51 CMPXVideoPlaybackControl::CMPXVideoPlaybackControl(
       
    52         CMPXVideoPlaybackControlsController* aController,
       
    53         CCoeControl* aControl,
       
    54         TMPXVideoPlaybackControls aControlIndex,
       
    55         TUint aProperties )
       
    56     : iController( aController )
       
    57     , iControl( aControl )
       
    58     , iControlIndex( aControlIndex )
       
    59     , iProperties( aProperties )
       
    60 {
       
    61 }
       
    62 
       
    63 // -------------------------------------------------------------------------------------------------
       
    64 // CMPXVideoPlaybackControl::ConstructL()
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -------------------------------------------------------------------------------------------------
       
    67 //
       
    68 void CMPXVideoPlaybackControl::ConstructL( TRect aRect )
       
    69 {
       
    70     MPX_DEBUG(_L("CMPXVideoPlaybackControl::ConstructL()"));
       
    71 
       
    72     CreateWindowL();
       
    73     EnableDragEvents();
       
    74 
       
    75     iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityDefault );
       
    76 
       
    77     SetRect( aRect );
       
    78 
       
    79     iControl->SetContainerWindowL( *this );
       
    80     iControl->SetRect( Rect() );
       
    81     SetComponentsToInheritVisibility( ETrue );
       
    82 
       
    83 #ifdef RD_TACTILE_FEEDBACK
       
    84     if ( iProperties & EMPXSoftkeyControl )
       
    85     {
       
    86         iFeedback = MTouchFeedback::Instance();
       
    87     }
       
    88 #endif //RD_TACTILE_FEEDBACK
       
    89 
       
    90     Window().SetNonFading( ETrue );
       
    91 
       
    92     ActivateL();
       
    93 }
       
    94 
       
    95 // -------------------------------------------------------------------------------------------------
       
    96 // CMPXVideoPlaybackControl::NewL()
       
    97 // Two-phased constructor.
       
    98 // -------------------------------------------------------------------------------------------------
       
    99 //
       
   100 CMPXVideoPlaybackControl* CMPXVideoPlaybackControl::NewL(
       
   101     CMPXVideoPlaybackControlsController* aController,
       
   102     CCoeControl* aControl,
       
   103     TRect aRect,
       
   104     TMPXVideoPlaybackControls aControlIndex,
       
   105     TUint aProperties )
       
   106 {
       
   107     MPX_DEBUG(_L("CMPXVideoPlaybackControl::NewL()"));
       
   108 
       
   109     CMPXVideoPlaybackControl* self =
       
   110         new (ELeave) CMPXVideoPlaybackControl( aController, aControl, aControlIndex, aProperties );
       
   111 
       
   112     CleanupStack::PushL(self);
       
   113     self->ConstructL( aRect );
       
   114     CleanupStack::Pop();
       
   115 
       
   116     return self;
       
   117 }
       
   118 
       
   119 // -------------------------------------------------------------------------------------------------
       
   120 // CMPXVideoPlaybackControl::~CMPXVideoPlaybackControlsController()
       
   121 // Destructor.
       
   122 // -------------------------------------------------------------------------------------------------
       
   123 //
       
   124 CMPXVideoPlaybackControl::~CMPXVideoPlaybackControl()
       
   125 {
       
   126     MPX_DEBUG(_L("CMPXVideoPlaybackControl::~CMPXVideoPlaybackControl()"));
       
   127 
       
   128     iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   129 
       
   130 #ifdef RD_TACTILE_FEEDBACK
       
   131     if ( iFeedback )
       
   132     {
       
   133        iFeedback->RemoveFeedbackForControl( this );
       
   134     }
       
   135 #endif //RD_TACTILE_FEEDBACK
       
   136 
       
   137     if ( iControl )
       
   138     {
       
   139         delete iControl;
       
   140         iControl = NULL;
       
   141     }
       
   142 
       
   143     CloseWindow();
       
   144 }
       
   145 
       
   146 // -------------------------------------------------------------------------------------------------
       
   147 // From CCoeControl
       
   148 // Gets the number of controls contained in a compound control.
       
   149 // -------------------------------------------------------------------------------------------------
       
   150 //
       
   151 TInt CMPXVideoPlaybackControl::CountComponentControls() const
       
   152 {
       
   153     return 1;
       
   154 }
       
   155 
       
   156 // -------------------------------------------------------------------------------------------------
       
   157 // From CCoeControl
       
   158 // Gets an indexed component of a compound control.
       
   159 // -------------------------------------------------------------------------------------------------
       
   160 //
       
   161 CCoeControl* CMPXVideoPlaybackControl::ComponentControl( TInt /*aIndex*/ ) const
       
   162 {
       
   163     return iControl;
       
   164 }
       
   165 
       
   166 // -------------------------------------------------------------------------------------------------
       
   167 // CMPXVideoPlaybackControl::Draw()
       
   168 // -------------------------------------------------------------------------------------------------
       
   169 //
       
   170 void CMPXVideoPlaybackControl::Draw( const TRect& aRect ) const
       
   171 {
       
   172     MPX_DEBUG(_L("CMPXVideoPlaybackControl::Draw()"));
       
   173 
       
   174     CWindowGc& gc = SystemGc();
       
   175     gc.SetClippingRect( aRect );
       
   176 
       
   177     if ( Window().DisplayMode() == EColor16MAP )
       
   178     {
       
   179         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   180         gc.SetBrushColor( TRgb::Color16MAP( 255 ) );
       
   181     }
       
   182     else if ( Window().DisplayMode() == EColor16MA )
       
   183     {
       
   184         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   185         gc.SetBrushColor( TRgb::Color16MA( 0 ) );
       
   186     }
       
   187     else
       
   188     {
       
   189         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   190         gc.SetBrushColor( KRgbBlack );
       
   191     }
       
   192 
       
   193     gc.Clear( aRect );
       
   194 }
       
   195 
       
   196 // -------------------------------------------------------------------------------------------------
       
   197 // CMPXVideoPlaybackControl::HandlePointerEventL()
       
   198 // -------------------------------------------------------------------------------------------------
       
   199 //
       
   200 void CMPXVideoPlaybackControl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   201 {
       
   202     MPX_DEBUG(_L("CMPXVideoPlaybackControl::HandlePointerEventL()"));
       
   203 
       
   204     iController->iContainer->UserInputHandler()->ProcessPointerEventL( this,
       
   205                                                                        aPointerEvent,
       
   206                                                                        EMpxVideoPlaybackControl );
       
   207 }
       
   208 
       
   209 // -------------------------------------------------------------------------------------------------
       
   210 // CMPXVideoPlaybackControl::DoHandlePointerEventL()
       
   211 // -------------------------------------------------------------------------------------------------
       
   212 //
       
   213 EXPORT_C void CMPXVideoPlaybackControl::DoHandlePointerEventL( const TPointerEvent& aPointerEvent)
       
   214 {
       
   215     MPX_DEBUG(_L("CMPXVideoPlaybackControl::DoHandlePointerEventL()"));
       
   216 
       
   217     if ( AknLayoutUtils::PenEnabled() )
       
   218     {
       
   219         switch( iControlIndex )
       
   220         {
       
   221             case EMPXProgressBar:
       
   222             case EMPXVolumeBar:
       
   223             case EMPXButtonBar:
       
   224             case EMPXAspectRatioIcon:
       
   225             case EMPXMediaDetailsViewer:
       
   226             {
       
   227                 if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   228                 {
       
   229                     iController->ResetDisappearingTimers( EMPXTimerCancel );
       
   230 
       
   231                     iControl->SetPointerCapture( ETrue );
       
   232                     iControl->ClaimPointerGrab( ETrue );
       
   233                 }
       
   234                 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   235                 {
       
   236                     iController->ResetDisappearingTimers( EMPXTimerReset );
       
   237 
       
   238                     iControl->SetPointerCapture( EFalse );
       
   239                     iControl->ClaimPointerGrab( EFalse );
       
   240                 }
       
   241 
       
   242                 //
       
   243                 // Pass an event to controller
       
   244                 //
       
   245                 iControl->HandlePointerEventL( aPointerEvent );
       
   246                 break;
       
   247             }
       
   248             case EMPXSoftkeyDetails:
       
   249             {
       
   250                 if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   251                 {
       
   252 #ifdef RD_TACTILE_FEEDBACK
       
   253                     if ( iFeedback )
       
   254                     {
       
   255                         iFeedback->InstantFeedback( ETouchFeedbackBasic );
       
   256                     }
       
   257 #endif //RD_TACTILE_FEEDBACK
       
   258 
       
   259                     iController->HandleCommandL( EMPXPbvCmdShowFileDetails );
       
   260                 }
       
   261                 break;
       
   262             }
       
   263             case EMPXSoftkeyBack:
       
   264             {
       
   265                 if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   266                 {
       
   267 #ifdef RD_TACTILE_FEEDBACK
       
   268                     if ( iFeedback )
       
   269                     {
       
   270                         iFeedback->InstantFeedback( ETouchFeedbackBasic );
       
   271                     }
       
   272 #endif //RD_TACTILE_FEEDBACK
       
   273 
       
   274                     iController->HandleCommandL( EAknSoftkeyBack );
       
   275                 }
       
   276                 break;
       
   277             }
       
   278             case EMPXNoVideoBitmap:
       
   279             case EMPXRealAudioBitmap:
       
   280             case EMPXSoundBitmap:
       
   281             case EMPXTitleLabel:
       
   282             case EMPXArtistLabel:
       
   283             case EMPXBrandingAnimation:
       
   284             default:
       
   285             {
       
   286                 //
       
   287                 //  Ignore pointer events for these controls
       
   288                 //
       
   289                 break;
       
   290             }
       
   291         }
       
   292     }
       
   293 }
       
   294 
       
   295 // -------------------------------------------------------------------------------------------------
       
   296 // CMPXVideoPlaybackControl::SetVisibility()
       
   297 // -------------------------------------------------------------------------------------------------
       
   298 //
       
   299 void CMPXVideoPlaybackControl::SetVisibility( TMPXPlaybackState aState )
       
   300 {
       
   301     TBool visible = EFalse;
       
   302 
       
   303     switch( aState )
       
   304     {
       
   305         case EPbStatePlaying:
       
   306         {
       
   307             if ( iProperties & EMPXShownWhenPlaying )
       
   308             {
       
   309                 visible = ETrue;
       
   310             }
       
   311             break;
       
   312         }
       
   313         case EPbStatePaused:
       
   314         {
       
   315             if ( iProperties & EMPXShownWhenPaused )
       
   316             {
       
   317                 visible = ETrue;
       
   318             }
       
   319             break;
       
   320         }
       
   321         case EPbStatePluginSeeking:
       
   322         {
       
   323             if ( iProperties & EMPXShownWhenSeeking )
       
   324             {
       
   325                 visible = ETrue;
       
   326             }
       
   327             break;
       
   328         }
       
   329         case EPbStateBuffering:
       
   330         {
       
   331             if ( iProperties & EMPXBufferingControl )
       
   332             {
       
   333                 visible = ETrue;
       
   334             }
       
   335             break;
       
   336         }
       
   337         case EPbStateStopped:
       
   338         {
       
   339             if ( iProperties & EMPXShownWhenStopped )
       
   340             {
       
   341                 visible = ETrue;
       
   342             }
       
   343             break;
       
   344         }
       
   345         case EPbStateNotInitialised:
       
   346         case EPbStateInitialising:
       
   347         {
       
   348             if ( iProperties & EMPXShownWhenInitializing )
       
   349             {
       
   350                 visible = ETrue;
       
   351             }
       
   352             break;
       
   353         }
       
   354     }
       
   355 
       
   356     MPX_DEBUG(_L("CMPXVideoPlaybackControl::SetVisibility(%d)"), visible);
       
   357 
       
   358     MakeVisible( visible );
       
   359 }
       
   360 
       
   361 // -------------------------------------------------------------------------------------------------
       
   362 // CMPXVideoPlaybackControl::ControlIndex()
       
   363 // -------------------------------------------------------------------------------------------------
       
   364 //
       
   365 TMPXVideoPlaybackControls CMPXVideoPlaybackControl::ControlIndex()
       
   366 {
       
   367     return iControlIndex;
       
   368 }
       
   369 
       
   370 // -------------------------------------------------------------------------------------------------
       
   371 // CMPXVideoPlaybackControl::VolumeChanged()
       
   372 // -------------------------------------------------------------------------------------------------
       
   373 //
       
   374 TBool CMPXVideoPlaybackControl::VolumeChanged( TInt aVolume )
       
   375 {
       
   376     TBool changed = EFalse;
       
   377 
       
   378     if ( iControlIndex == EMPXVolumeBar )
       
   379     {
       
   380         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::VolumeChanged() [%d]"), aVolume);
       
   381 
       
   382         static_cast<CMPXVideoPlaybackVolumeBar*>(iControl)->VolumeChanged( aVolume );
       
   383 
       
   384         changed = ETrue;
       
   385     }
       
   386 
       
   387     return changed;
       
   388 }
       
   389 
       
   390 // -------------------------------------------------------------------------------------------------
       
   391 // CMPXVideoPlaybackControl::DurationChangedL()
       
   392 // -------------------------------------------------------------------------------------------------
       
   393 //
       
   394 TBool CMPXVideoPlaybackControl::DurationChangedL( TInt aDuration )
       
   395 {
       
   396     TBool changed = EFalse;
       
   397 
       
   398     if ( iControlIndex == EMPXProgressBar )
       
   399     {
       
   400         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::DurationChangedL() [%d]"), aDuration);
       
   401 
       
   402         static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->DurationChangedL( aDuration );
       
   403 
       
   404         changed = ETrue;
       
   405     }
       
   406 
       
   407     return changed;
       
   408 }
       
   409 
       
   410 // -------------------------------------------------------------------------------------------------
       
   411 // CMPXVideoPlaybackControl::PositionChangedL()
       
   412 // -------------------------------------------------------------------------------------------------
       
   413 //
       
   414 TBool CMPXVideoPlaybackControl::PositionChangedL( TInt aPosition )
       
   415 {
       
   416     TBool changed = EFalse;
       
   417 
       
   418     if ( iControlIndex == EMPXProgressBar )
       
   419     {
       
   420         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::PositionChangedL() [%d]"), aPosition);
       
   421 
       
   422         static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->PositionChangedL( aPosition );
       
   423 
       
   424         changed = ETrue;
       
   425     }
       
   426 
       
   427     return changed;
       
   428 }
       
   429 
       
   430 // -------------------------------------------------------------------------------------------------
       
   431 // CMPXVideoPlaybackControl::AspectRatioChanged()
       
   432 // -------------------------------------------------------------------------------------------------
       
   433 //
       
   434 TBool CMPXVideoPlaybackControl::AspectRatioChanged( TInt aAspectRatio )
       
   435 {
       
   436     TBool changed = EFalse;
       
   437 
       
   438     if ( iControlIndex == EMPXAspectRatioIcon )
       
   439     {
       
   440         MPX_DEBUG(
       
   441             _L("CMPXVideoPlaybackControlsController::AspectRatioChanged() [%d]"), aAspectRatio);
       
   442 
       
   443         static_cast<CMPXVideoPlaybackAspectRatioIcon*>(iControl)->
       
   444             AspectRatioChanged( aAspectRatio );
       
   445 
       
   446         changed = ETrue;
       
   447     }
       
   448 
       
   449     return changed;
       
   450 }
       
   451 
       
   452 // -------------------------------------------------------------------------------------------------
       
   453 //   CMPXVideoPlaybackControl::SetDownloadSize()
       
   454 // -------------------------------------------------------------------------------------------------
       
   455 //
       
   456 TBool CMPXVideoPlaybackControl::SetDownloadSize( TInt aSize )
       
   457 {
       
   458     TBool changed = EFalse;
       
   459 
       
   460     if ( iControlIndex == EMPXProgressBar )
       
   461     {
       
   462         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::SetDownloadSize() [%d]"), aSize);
       
   463 
       
   464         static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->SetDownloadSize( aSize );
       
   465 
       
   466         changed = ETrue;
       
   467     }
       
   468 
       
   469     return changed;
       
   470 }
       
   471 
       
   472 // -------------------------------------------------------------------------------------------------
       
   473 //   CMPXVideoPlaybackControl::UpdateDownloadPosition()
       
   474 // -------------------------------------------------------------------------------------------------
       
   475 //
       
   476 TBool CMPXVideoPlaybackControl::UpdateDownloadPosition( TInt aSize )
       
   477 {
       
   478     TBool changed = EFalse;
       
   479 
       
   480     if ( iControlIndex == EMPXProgressBar )
       
   481     {
       
   482         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::UpdateDownloadPosition() [%d]"), aSize);
       
   483 
       
   484         static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->UpdateDownloadPosition( aSize );
       
   485 
       
   486         changed = ETrue;
       
   487     }
       
   488 
       
   489     return changed;
       
   490 }
       
   491 
       
   492 // -------------------------------------------------------------------------------------------------
       
   493 // CMPXVideoPlaybackControl::UpdateStateOnButtonBar()
       
   494 // -------------------------------------------------------------------------------------------------
       
   495 //
       
   496 TBool CMPXVideoPlaybackControl::UpdateStateOnButtonBar( TMPXPlaybackState aState )
       
   497 {
       
   498     TBool changed = EFalse;
       
   499 
       
   500     if ( iControlIndex == EMPXButtonBar )
       
   501     {
       
   502         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::UpdateStateOnButtonBar() [%d]"), aState);
       
   503 
       
   504         static_cast<CMPXVideoPlaybackButtonBar*>(iControl)->UpdateStateOnButtonBar( aState );
       
   505 
       
   506         changed = ETrue;
       
   507     }
       
   508 
       
   509     return changed;
       
   510 }
       
   511 
       
   512 // -------------------------------------------------------------------------------------------------
       
   513 // CMPXVideoPlaybackControl::UpdateControlsWithFileDetailsL()
       
   514 // -------------------------------------------------------------------------------------------------
       
   515 //
       
   516 void CMPXVideoPlaybackControl::UpdateControlsWithFileDetailsL(
       
   517         CMPXVideoPlaybackViewFileDetails* aDetails )
       
   518 {
       
   519     iPlaybackMode = aDetails->iPlaybackMode;
       
   520 
       
   521     //
       
   522     //  Controls should be shown when if there is no video or the TV-Out is connected
       
   523     //
       
   524     if ( iControlIndex == EMPXButtonBar )
       
   525     {
       
   526         static_cast<CMPXVideoPlaybackButtonBar*>(iControl)->UpdateButtonBarState( aDetails );
       
   527     }
       
   528     else if ( iControlIndex == EMPXProgressBar )
       
   529     {
       
   530         static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->UpdateProgressBarStateL( aDetails );
       
   531     }
       
   532 }
       
   533 
       
   534 // -------------------------------------------------------------------------------------------------
       
   535 // CMPXVideoPlaybackControl::StopBrandingAnimationTimer()
       
   536 // -------------------------------------------------------------------------------------------------
       
   537 //
       
   538 TBool CMPXVideoPlaybackControl::StopBrandingAnimationTimer()
       
   539 {
       
   540     TBool changed = EFalse;
       
   541 
       
   542     if ( iControlIndex == EMPXBrandingAnimation )
       
   543     {
       
   544         MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::StopBrandingAnimationTimer()"));
       
   545 
       
   546         static_cast<CMPXVideoPlaybackBrandingAnimation*>(iControl)->CancelBrandingTimer();
       
   547 
       
   548         changed = ETrue;
       
   549     }
       
   550 
       
   551     return changed;
       
   552 }
       
   553 
       
   554 // -------------------------------------------------------------------------------------------------
       
   555 // CMPXVideoPlaybackControl::ResetControl()
       
   556 // -------------------------------------------------------------------------------------------------
       
   557 //
       
   558 void CMPXVideoPlaybackControl::ResetControl()
       
   559 {
       
   560     MPX_DEBUG(_L("CMPXVideoPlaybackControlsController::ResetControl()"));
       
   561 
       
   562     switch( iControlIndex )
       
   563     {
       
   564         case EMPXButtonBar:
       
   565         {
       
   566             static_cast<CMPXVideoPlaybackButtonBar*>(iControl)->Reset();
       
   567             break;
       
   568         }
       
   569         case EMPXProgressBar:
       
   570         {
       
   571             static_cast<CMPXVideoPlaybackProgressBar*>(iControl)->Reset();
       
   572             break;
       
   573         }
       
   574         case EMPXVolumeBar:
       
   575         {
       
   576              static_cast<CMPXVideoPlaybackVolumeBar*>(iControl)->Reset();
       
   577              break;
       
   578         }
       
   579         case EMPXAspectRatioIcon:
       
   580         default:
       
   581             break;
       
   582     }
       
   583 }
       
   584 
       
   585 // End of File