videoplayback/videoplaybackview/viewsrc/videobaseplaybackview.cpp
changeset 44 518105d52e45
child 49 824471cb468a
equal deleted inserted replaced
42:17f382c040b1 44:518105d52e45
       
     1 /*
       
     2 * Copyright (c) 2009 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 base playback view
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: da1mmcf#45 %
       
    19 
       
    20 
       
    21 
       
    22 //  Include Files
       
    23 
       
    24 
       
    25 
       
    26 #include <QTimer>
       
    27 #include <QGraphicsSceneEvent>
       
    28 
       
    29 #include <hbmenu.h>
       
    30 #include <hbaction.h>
       
    31 #include <hbinstance.h>
       
    32 #include <hbnotificationdialog.h>
       
    33 #include <hblabel.h>
       
    34 #include <hbtapgesture.h>
       
    35 #include <hbpangesture.h>
       
    36 
       
    37 #include <textresolver.h>
       
    38 #include <mmf/common/mmferrors.h>
       
    39 #include <DRMHelper.h>
       
    40 
       
    41 #include <mpxvideoplaybackdefs.h>
       
    42 #include <mpxplaybackcommanddefs.h>
       
    43 #include <mpxhbvideocommondefs.h>
       
    44 
       
    45 #include "mpxvideo_debug.h"
       
    46 #include "mpxvideoviewwrapper.h"
       
    47 #include "mpxvideoplaybackuids.hrh"
       
    48 #include "videobaseplaybackview.h"
       
    49 #include "videoactivitystate.h"   
       
    50 #include "videoplaybackviewfiledetails.h"  
       
    51 #include "mpxcommonvideoplaybackview.hrh"
       
    52 
       
    53 
       
    54 //  Member Functions
       
    55 
       
    56 // -------------------------------------------------------------------------------------------------
       
    57 // VideoBasePlaybackView::VideoBasePlaybackView()
       
    58 // -------------------------------------------------------------------------------------------------
       
    59 //
       
    60 VideoBasePlaybackView::VideoBasePlaybackView()
       
    61     : mVideoMpxWrapper( NULL )
       
    62     , mTimerForClosingView( NULL )
       
    63     , mActivated( false )
       
    64     , mStayPaused ( false )
       
    65 {
       
    66     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::VideoBasePlaybackView()"));
       
    67 }
       
    68 
       
    69 // -------------------------------------------------------------------------------------------------
       
    70 //   VideoBasePlaybackView::initializeVideoPlaybackView()
       
    71 // -------------------------------------------------------------------------------------------------
       
    72 //
       
    73 void VideoBasePlaybackView::initializeVideoPlaybackView()
       
    74 {
       
    75     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::initializeVideoPlaybackView()"));
       
    76 
       
    77     //
       
    78     // Need to set to control full screen including status pane area
       
    79     //
       
    80     setContentFullScreen();
       
    81 
       
    82     mTimerForClosingView = new QTimer();
       
    83     mTimerForClosingView->setSingleShot( true );
       
    84     mTimerForClosingView->setInterval( 10 );
       
    85     connect( mTimerForClosingView, SIGNAL( timeout() ), this, SIGNAL( activatePreviousView() ) );
       
    86     
       
    87     //
       
    88     // Read activity data ...
       
    89     // If last playback was forced to terminate due to low memory (GOOM, etc.)
       
    90     // then the clip needs to be restored to the last played position 
       
    91     // and the state needs to be paused, since forced termination can only occur for
       
    92     // background apps - so if this happened Video Player must have been in background
       
    93     // which implies paused state
       
    94     //    
       
    95     int lastViewType = VideoActivityState::instance().getActivityData(KEY_VIEWPLUGIN_TYPE).toInt();    
       
    96     if ( lastViewType == MpxHbVideoCommon::PlaybackView ) 
       
    97     {
       
    98         QVariant data = VideoActivityState::instance().getActivityData(KEY_LAST_PLAY_POSITION_ID);
       
    99         mLastPlayPosition = data.toInt();   
       
   100         
       
   101         mStayPaused = true;
       
   102     }     
       
   103 }
       
   104 
       
   105 // -------------------------------------------------------------------------------------------------
       
   106 // VideoBasePlaybackView::~VideoBasePlaybackView()
       
   107 // -------------------------------------------------------------------------------------------------
       
   108 //
       
   109 VideoBasePlaybackView::~VideoBasePlaybackView()
       
   110 {
       
   111     MPX_DEBUG(_L("VideoBasePlaybackView::~VideoBasePlaybackView()"));
       
   112 
       
   113     if ( mTimerForClosingView )
       
   114     {
       
   115         disconnect( mTimerForClosingView, SIGNAL( timeout() ), this, SIGNAL( activatePreviousView() ) );
       
   116 
       
   117         if ( mTimerForClosingView->isActive() )
       
   118         {
       
   119             mTimerForClosingView->stop();
       
   120         }
       
   121 
       
   122         delete mTimerForClosingView;
       
   123         mTimerForClosingView = NULL;
       
   124     }
       
   125 
       
   126     if ( mVideoMpxWrapper )
       
   127     {
       
   128         delete mVideoMpxWrapper;
       
   129         mVideoMpxWrapper = NULL;
       
   130     }
       
   131 
       
   132     setParentItem( 0 );
       
   133 }
       
   134 
       
   135 // -------------------------------------------------------------------------------------------------
       
   136 //   VideoBasePlaybackView::handleActivateView()
       
   137 // -------------------------------------------------------------------------------------------------
       
   138 //
       
   139 void VideoBasePlaybackView::handleActivateView()
       
   140 {
       
   141     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::handleActivateView()"));
       
   142 
       
   143     MPX_TRAPD( err, mVideoMpxWrapper = CMPXVideoViewWrapper::NewL( this ) );
       
   144 
       
   145     QCoreApplication::instance()->installEventFilter( this );
       
   146 
       
   147     //
       
   148     //  Request the needed Media from the Playback Plugin
       
   149     //
       
   150     MPX_TRAP( err, mVideoMpxWrapper->RequestMediaL() );
       
   151 
       
   152     menu()->close();
       
   153 
       
   154     //
       
   155     // Landscape orientation
       
   156     // Workaround: Disable orientation transition effect
       
   157 	// since orbit couldn't emit the orientationChanged signal with transition effect
       
   158 	//
       
   159     hbInstance->allMainWindows()[0]->setOrientation( Qt::Horizontal, false );
       
   160 
       
   161     mActivated = true;
       
   162 }
       
   163 
       
   164 // -------------------------------------------------------------------------------------------------
       
   165 //   VideoBasePlaybackView::handleDeactivateView()
       
   166 // -------------------------------------------------------------------------------------------------
       
   167 //
       
   168 void VideoBasePlaybackView::handleDeactivateView()
       
   169 {
       
   170     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::handleDeactivateView()"));
       
   171 
       
   172     saveActivityData();
       
   173     
       
   174     mActivated = false;
       
   175 
       
   176     QCoreApplication::instance()->removeEventFilter( this );
       
   177 
       
   178     //
       
   179     //  Close the playback plugin to release all references to previous clip
       
   180     //
       
   181     MPX_TRAPD( err, mVideoMpxWrapper->HandleCommandL( EMPXPbvCmdClose ) );
       
   182 
       
   183     if ( mVideoMpxWrapper )
       
   184     {
       
   185         delete mVideoMpxWrapper;
       
   186         mVideoMpxWrapper = NULL;
       
   187     }
       
   188 
       
   189     //
       
   190     // go back to device orientation
       
   191     //
       
   192     //hbInstance->allMainWindows()[0]->unsetOrientation();
       
   193 }
       
   194 
       
   195 // -------------------------------------------------------------------------------------------------
       
   196 //   VideoBasePlaybackView::saveActivityData()
       
   197 // -------------------------------------------------------------------------------------------------
       
   198 //
       
   199 void VideoBasePlaybackView::saveActivityData()
       
   200 {
       
   201     MPX_DEBUG( _L("VideoBasePlaybackView::saveActivityData()") );  
       
   202     
       
   203     // save the activity data
       
   204     QVariant data = QString( mVideoMpxWrapper->iFileDetails->mClipName );
       
   205     VideoActivityState::instance().setActivityData(data, KEY_LAST_PLAYED_CLIP); 
       
   206     
       
   207     data = int( mVideoMpxWrapper->iPlayPosition );
       
   208     VideoActivityState::instance().setActivityData(data, KEY_LAST_PLAY_POSITION_ID);
       
   209     
       
   210     data = bool( mVideoMpxWrapper->iFileDetails->mPlaybackMode == EMPXVideoLocal );
       
   211     VideoActivityState::instance().setActivityData(data, KEY_LAST_LOCAL_PLAYBACK);     
       
   212 }
       
   213 
       
   214 // -------------------------------------------------------------------------------------------------
       
   215 //   VideoBasePlaybackView::handleClosePlaybackView()
       
   216 // -------------------------------------------------------------------------------------------------
       
   217 //
       
   218 void VideoBasePlaybackView::handleClosePlaybackView()
       
   219 {
       
   220     MPX_DEBUG(
       
   221       _L("VideoBasePlaybackView::handleClosePlaybackView()") );
       
   222 
       
   223     if ( mVideoMpxWrapper && mVideoMpxWrapper->IsMultiItemPlaylist() )
       
   224     {
       
   225         TRAP_IGNORE( mVideoMpxWrapper->HandleCommandL( EMPXPbvCmdNextListItem ) );
       
   226     }
       
   227     else
       
   228     {
       
   229         closePlaybackView();
       
   230     }
       
   231 }
       
   232 
       
   233 // -------------------------------------------------------------------------------------------------
       
   234 //   VideoBasePlaybackView::handlePluginError()
       
   235 // -------------------------------------------------------------------------------------------------
       
   236 //
       
   237 void VideoBasePlaybackView::handlePluginError( int aError )
       
   238 {
       
   239     MPX_DEBUG(
       
   240       _L("VideoBasePlaybackView::handlePluginError() aError = %d"), aError );
       
   241 
       
   242     switch ( aError )
       
   243     {
       
   244         case KErrCancel:
       
   245 		{
       
   246             handleClosePlaybackView();
       
   247             break;
       
   248         }
       
   249         case KErrMMDRMNotAuthorized:
       
   250         case KErrCANoRights:
       
   251         case KErrCANoPermission:
       
   252         {
       
   253             showDialog( hbTrId( "txt_videos_info_license_has_expired_or_it_is_missi" ) );
       
   254             break;
       
   255         }
       
   256         case KMPXVideoCallOngoingError:
       
   257         {
       
   258             showDialog( hbTrId( "txt_videos_info_video_playback_is_not_allowed_duri" ), false );
       
   259             break;
       
   260         }
       
   261         default:
       
   262         {
       
   263             TRAP_IGNORE(
       
   264 
       
   265                 //
       
   266                 //  TextResolver instance for error resolving.
       
   267                 //
       
   268                 CTextResolver* textresolver = CTextResolver::NewLC();
       
   269 
       
   270                 //
       
   271                 //  Resolve the error text
       
   272                 //
       
   273                 TPtrC text;
       
   274                 text.Set( textresolver->ResolveErrorString( aError ) );
       
   275 
       
   276                 //
       
   277                 // convert to QString
       
   278                 //
       
   279                 const QString qString( (QChar*)text.Ptr(), text.Length() );
       
   280 
       
   281                 //
       
   282                 // clean up textresolver
       
   283                 //
       
   284                 CleanupStack::PopAndDestroy( textresolver );
       
   285 
       
   286                 //
       
   287                 // display error and close playback view
       
   288                 //
       
   289                 showDialog( qString );
       
   290             );
       
   291         }
       
   292     }
       
   293 }
       
   294 
       
   295 // -------------------------------------------------------------------------------------------------
       
   296 //   VideoBasePlaybackView::showDialog
       
   297 // -------------------------------------------------------------------------------------------------
       
   298 //
       
   299 void VideoBasePlaybackView::showDialog( const QString& qString, bool closeView )
       
   300 {
       
   301     MPX_DEBUG(_L("VideoBasePlaybackView::showDialog( %s, %d )"), qString.data(), closeView );
       
   302 
       
   303     //
       
   304     // create pop-up dialog for error notes,
       
   305     //     set its position to the middle of the screen
       
   306     //     and make sure pop-up dialog gets deleted on close.
       
   307     //
       
   308     QRectF screenRect = hbInstance->allMainWindows()[0]->rect();
       
   309     HbNotificationDialog* dlg = new HbNotificationDialog();
       
   310     dlg->setAttribute( Qt::WA_DeleteOnClose );
       
   311     dlg->setMinimumSize( QSizeF(200, 100) );
       
   312     dlg->setPreferredPos( QPointF( screenRect.height()/2, screenRect.width()/2 ),
       
   313                           HbPopup::Center );
       
   314 
       
   315 	if ( closeView )
       
   316 	{
       
   317         //
       
   318         // connect aboutToClose() signal to handleClosePopupDialog() slot so that
       
   319         // when pop-up dialog is closed, playback view is closed also
       
   320         //
       
   321         connect( dlg, SIGNAL( aboutToClose() ), this, SLOT( handleClosePopupDialog() ) );
       
   322     }
       
   323 
       
   324     //
       
   325     // convert string to label so text alignment can be set
       
   326     //
       
   327     HbLabel *label = new HbLabel( qString );
       
   328     label->setAlignment( Qt::AlignCenter );
       
   329 
       
   330     //
       
   331     // set label as content widget and show pop-up dialog
       
   332     //
       
   333     dlg->setContentWidget( label );
       
   334     dlg->show();
       
   335 }
       
   336 
       
   337 // -------------------------------------------------------------------------------------------------
       
   338 //   VideoBasePlaybackView::doClosePlayer
       
   339 // -------------------------------------------------------------------------------------------------
       
   340 //
       
   341 void VideoBasePlaybackView::doClosePlayer()
       
   342 {
       
   343     MPX_DEBUG(_L("VideoBasePlaybackView::doClosePlayer()"));
       
   344 
       
   345     handleDeactivateView();
       
   346 
       
   347     qApp->quit();
       
   348 }
       
   349 
       
   350 // -------------------------------------------------------------------------------------------------
       
   351 //   VideoBasePlaybackView::issuePlayCommand
       
   352 // -------------------------------------------------------------------------------------------------
       
   353 //
       
   354 void VideoBasePlaybackView::issuePlayCommand()
       
   355 {
       
   356     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::issuePlayCommand()"));
       
   357 
       
   358     int err = KErrNone;
       
   359 
       
   360     TRAP( err, mVideoMpxWrapper->CreateGeneralPlaybackCommandL( EPbCmdPlay ));
       
   361 
       
   362     MPX_DEBUG(_L("VideoBasePlaybackView::issuePlayCommand() error = %d"), err);
       
   363 }
       
   364 
       
   365 // -------------------------------------------------------------------------------------------------
       
   366 //   VideoBasePlaybackView::retrievePdlInformation
       
   367 // -------------------------------------------------------------------------------------------------
       
   368 //
       
   369 void VideoBasePlaybackView::retrievePdlInformation()
       
   370 {
       
   371     MPX_DEBUG(_L("VideoBasePlaybackView::retrievePdlInformation()"));
       
   372 }
       
   373 
       
   374 // -------------------------------------------------------------------------------------------------
       
   375 //   VideoBasePlaybackView::handleBufferingState
       
   376 // -------------------------------------------------------------------------------------------------
       
   377 //
       
   378 void VideoBasePlaybackView::handleBufferingState()
       
   379 {
       
   380     MPX_DEBUG(_L("VideoBasePlaybackView::handleBufferingState()"));
       
   381 }
       
   382 
       
   383 // -------------------------------------------------------------------------------------------------
       
   384 //   VideoBasePlaybackView::closePlaybackView()
       
   385 // -------------------------------------------------------------------------------------------------
       
   386 //
       
   387 void VideoBasePlaybackView::closePlaybackView()
       
   388 {
       
   389     MPX_ENTER_EXIT(_L("VideoBasePlaybackView::closePlaybackView()"));
       
   390 
       
   391     mTimerForClosingView->start( 0 );
       
   392 }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // VideoBasePlaybackView::eventFilter
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 bool VideoBasePlaybackView::eventFilter( QObject *object, QEvent *event )
       
   399 {
       
   400     Q_UNUSED( object );
       
   401 
       
   402     switch ( event->type() )
       
   403     {
       
   404         case QEvent::ApplicationActivate:
       
   405         {
       
   406             if ( mActivated )
       
   407             {
       
   408                 MPX_DEBUG(_L("VideoBasePlaybackView::eventFilter foreground()") );
       
   409                 TRAP_IGNORE( mVideoMpxWrapper->IssueVideoAppForegroundCmdL( true ) );
       
   410             }
       
   411             break;
       
   412         }
       
   413         case QEvent::ApplicationDeactivate:
       
   414         {
       
   415             if ( mActivated )
       
   416             {
       
   417                 MPX_DEBUG(_L("VideoBasePlaybackView::eventFilter background()") );
       
   418                 TRAP_IGNORE( mVideoMpxWrapper->IssueVideoAppForegroundCmdL( false ) );
       
   419             }
       
   420             break;
       
   421         }
       
   422     }
       
   423 
       
   424     return QObject::eventFilter( object, event );
       
   425 }
       
   426 
       
   427 // -------------------------------------------------------------------------------------------------
       
   428 //   VideoBasePlaybackView::getWindow()
       
   429 // -------------------------------------------------------------------------------------------------
       
   430 //
       
   431 RWindow *VideoBasePlaybackView::getWindow()
       
   432 {
       
   433     return static_cast<RWindow*>( hbInstance->allMainWindows()[0]->effectiveWinId()->DrawableWindow() );
       
   434 }
       
   435 
       
   436 // -------------------------------------------------------------------------------------------------
       
   437 //   VideoBasePlaybackView::handleClosePopupDialog()
       
   438 // -------------------------------------------------------------------------------------------------
       
   439 //
       
   440 void VideoBasePlaybackView::handleClosePopupDialog()
       
   441 {
       
   442     MPX_DEBUG(_L("VideoBasePlaybackView::handleClosePopupDialog()") );
       
   443 
       
   444     handleClosePlaybackView();
       
   445 }
       
   446 
       
   447 // -------------------------------------------------------------------------------------------------
       
   448 //   VideoBasePlaybackView::gestureEvent()
       
   449 // -------------------------------------------------------------------------------------------------
       
   450 //
       
   451 void VideoBasePlaybackView::gestureEvent( QGestureEvent* event )
       
   452 {
       
   453     if ( HbTapGesture * gesture = static_cast<HbTapGesture *>( event->gesture( Qt::TapGesture ) ) )
       
   454     {
       
   455         if ( gesture->state() == Qt::GestureFinished && mActivated )
       
   456         {
       
   457             MPX_DEBUG(_L("VideoBasePlaybackView::gestureEvent() tapGesture finished") );
       
   458 
       
   459             emit tappedOnScreen();
       
   460         }
       
   461     }
       
   462     else if ( HbPanGesture* gesture = static_cast<HbPanGesture*>( event->gesture( Qt::PanGesture ) ) )
       
   463     {
       
   464         if ( gesture->state() == Qt::GestureFinished && mActivated )
       
   465         {
       
   466             QPointF delta( gesture->sceneDelta() );
       
   467 
       
   468             if ( delta.x() > 0 )
       
   469             {
       
   470                 MPX_DEBUG(_L("VideoBasePlaybackView::gestureEvent() right") );
       
   471 
       
   472                 emit pannedToRight();
       
   473             }
       
   474             else
       
   475             {
       
   476                 MPX_DEBUG(_L("VideoBasePlaybackView::gestureEvent() left") );
       
   477 
       
   478                 emit pannedToLeft();
       
   479             }
       
   480         }
       
   481     }
       
   482 }
       
   483 
       
   484 // EOF