videoplayerapp/videoplayerengine/src/videoplayerengine.cpp
changeset 15 cf5481c2bc0b
child 17 69946d1824c4
equal deleted inserted replaced
2:dec420019252 15:cf5481c2bc0b
       
     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 VideoPlayerEngine
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 23 %
       
    19 
       
    20 
       
    21 #include <QApplication>
       
    22 
       
    23 #include <hbinstance.h>
       
    24 #include <xqpluginloader.h>
       
    25 #include <xqplugininfo.h>
       
    26 #include <xqserviceutil.h>
       
    27 #include <hbview.h>
       
    28 
       
    29 #include "videoplayerengine.h"
       
    30 #include "mpxvideoplaybackwrapper.h"
       
    31 #include "videoservices.h"
       
    32 #include "mpxvideo_debug.h"
       
    33 
       
    34 // -------------------------------------------------------------------------------------------------
       
    35 // QVideoPlayerEngine()
       
    36 // -------------------------------------------------------------------------------------------------
       
    37 //
       
    38 QVideoPlayerEngine::QVideoPlayerEngine(bool isService)
       
    39     : mIsService( isService )
       
    40     , mEmbedded(false)
       
    41     , mDelayedLoadDone(false)
       
    42     , mCurrentViewPlugin( 0 )
       
    43     , mPlaybackViewPlugin( 0 )
       
    44     , mCollectionViewPlugin( 0 )
       
    45     , mFileDetailsViewPlugin( 0 )
       
    46     , mPlaybackWrapper( 0 )
       
    47     , mVideoServices(0)
       
    48 {
       
    49 }
       
    50 
       
    51 // -------------------------------------------------------------------------------------------------
       
    52 // ~QVideoPlayerEngine()
       
    53 // -------------------------------------------------------------------------------------------------
       
    54 //
       
    55 QVideoPlayerEngine::~QVideoPlayerEngine()
       
    56 {
       
    57     MPX_ENTER_EXIT(_L("QVideoPlayerEngine::~QVideoPlayerEngine()"));
       
    58     	
       
    59     if ( mVideoServices )
       
    60     {
       
    61     	mVideoServices->decreaseReferenceCount();
       
    62     	mVideoServices = 0;
       
    63     }
       
    64 
       
    65     if ( mCollectionViewPlugin ) 
       
    66     {
       
    67         mCollectionViewPlugin->destroyView();
       
    68     }
       
    69 
       
    70     if ( mPlaybackViewPlugin ) 
       
    71     {
       
    72         mPlaybackViewPlugin->destroyView();
       
    73     }
       
    74 
       
    75     if ( mFileDetailsViewPlugin ) 
       
    76     {
       
    77         mFileDetailsViewPlugin->destroyView();
       
    78     }
       
    79 
       
    80     delete mPlaybackWrapper;
       
    81 
       
    82     // disconnect all signals 
       
    83     disconnect();
       
    84 }
       
    85 
       
    86 // -------------------------------------------------------------------------------------------------
       
    87 // initialize()
       
    88 // -------------------------------------------------------------------------------------------------
       
    89 //
       
    90 void QVideoPlayerEngine::initialize()
       
    91 {
       
    92     MPX_ENTER_EXIT(_L("QVideoPlayerEngine::initialize()"));	
       
    93     //
       
    94     // Clean up QVideoPlayerEngine when qApp try to quit
       
    95     //
       
    96     connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( handleQuit() ) );
       
    97 
       
    98     //
       
    99     // Create playback wrapper
       
   100     //
       
   101     if ( !mPlaybackWrapper )
       
   102     {
       
   103         mPlaybackWrapper = new QMpxVideoPlaybackWrapper();
       
   104         connect( mPlaybackWrapper,
       
   105                  SIGNAL( handlePlaybackView( int ) ),
       
   106                  this,
       
   107                  SLOT( handleCommand( int ) ) );
       
   108     }
       
   109 
       
   110     //
       
   111     // Get VideoServices instance
       
   112     //
       
   113     if( mIsService && !mVideoServices )
       
   114     {
       
   115 		mVideoServices = VideoServices::instance(this);
       
   116 		connect( mVideoServices, SIGNAL(activated(int)), this, SLOT(handleCommand(int)));
       
   117     }
       
   118 
       
   119     QList<XQPluginInfo> impls;
       
   120     XQPluginLoader::listImplementations("org.nokia.mmdt.MpxViewPlugin/1.0", impls);
       
   121 
       
   122     //
       
   123     // Pre-load collectionview and playbackview plugins
       
   124     //
       
   125     loadPlugin( MpxHbVideoCommon::CollectionView );
       
   126 
       
   127     if ( mCollectionViewPlugin ) 
       
   128     {
       
   129         mCollectionViewPlugin->createView();
       
   130         hbInstance->allMainWindows().value(0)->addView( mCollectionViewPlugin->getView() );
       
   131     }
       
   132     
       
   133     //
       
   134     // default view in the app is the collection view.
       
   135     //
       
   136     if(!mIsService)
       
   137     {
       
   138         activateView( MpxHbVideoCommon::CollectionView );
       
   139     } 
       
   140     
       
   141     // delayed initialization of some uiengine member variables
       
   142     // to help application startup time & improve playback start time
       
   143     //
       
   144     mPlaybackWrapper->lateInit();        
       
   145     
       
   146 }
       
   147 
       
   148 // -------------------------------------------------------------------------------------------------
       
   149 // handleCommand()
       
   150 // -------------------------------------------------------------------------------------------------
       
   151 //
       
   152 void QVideoPlayerEngine::handleCommand( int commandCode )
       
   153 {
       
   154 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::handleCommand()"));	
       
   155 	  
       
   156     switch ( commandCode )
       
   157     {
       
   158         case MpxHbVideoCommon::ActivateCollectionView:
       
   159         {
       
   160             if ( mCurrentViewPlugin != mCollectionViewPlugin )
       
   161             { 
       
   162                 activateView( MpxHbVideoCommon::CollectionView );
       
   163             }
       
   164             break;
       
   165         }
       
   166         case MpxHbVideoCommon::ActivatePlaybackView:
       
   167         {
       
   168             if ( mCurrentViewPlugin != mPlaybackViewPlugin )
       
   169             {                
       
   170                 activateView( MpxHbVideoCommon::PlaybackView );                
       
   171             }
       
   172             break;
       
   173         }
       
   174         case MpxHbVideoCommon::ActivateVideoDetailsView:
       
   175         {
       
   176             if ( mCurrentViewPlugin != mFileDetailsViewPlugin )
       
   177 			{
       
   178 				activateView( MpxHbVideoCommon::VideoDetailsView );                
       
   179             }
       
   180             break;
       
   181         }
       
   182         case MpxHbVideoCommon::DoDelayedLoad:
       
   183         {
       
   184 			if ( !mDelayedLoadDone )
       
   185 			{
       
   186 				doDelayedLoad();
       
   187 			}
       
   188             break;
       
   189         }
       
   190         
       
   191         default:
       
   192         {
       
   193             break;
       
   194         }
       
   195     }    
       
   196 }
       
   197 
       
   198 // -------------------------------------------------------------------------------------------------
       
   199 // doDelayedLoad()
       
   200 // -------------------------------------------------------------------------------------------------
       
   201 //
       
   202 void QVideoPlayerEngine::doDelayedLoad()
       
   203 {
       
   204     if ( !mPlaybackViewPlugin )
       
   205 	{
       
   206 	    loadPlugin( MpxHbVideoCommon::PlaybackView );
       
   207 
       
   208 	    if ( mPlaybackViewPlugin ) 
       
   209 	    {
       
   210 	        mPlaybackViewPlugin->createView();
       
   211 	        hbInstance->allMainWindows().value(0)->addView( mPlaybackViewPlugin->getView() );
       
   212 	    }
       
   213 	}
       
   214 
       
   215     if ( !mFileDetailsViewPlugin )
       
   216 	{
       
   217 	    loadPlugin( MpxHbVideoCommon::VideoDetailsView );
       
   218 
       
   219 		if ( mFileDetailsViewPlugin )
       
   220 		{
       
   221 			mFileDetailsViewPlugin->createView();
       
   222 			hbInstance->allMainWindows().value(0)->addView( mFileDetailsViewPlugin->getView() );
       
   223 		}
       
   224 	}
       
   225 	
       
   226 	mDelayedLoadDone = true;
       
   227 }
       
   228 
       
   229 // -------------------------------------------------------------------------------------------------
       
   230 // activateView()
       
   231 // activate view based on view type.
       
   232 // -------------------------------------------------------------------------------------------------
       
   233 //
       
   234 void QVideoPlayerEngine::activateView( MpxHbVideoCommon::MpxHbVideoViewType viewType )
       
   235 {
       
   236 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::activateView()"));
       
   237 	  
       
   238     disconnectView();
       
   239     
       
   240     if ( mCurrentViewPlugin )
       
   241     {
       
   242         mCurrentViewPlugin->deactivateView();
       
   243         mCurrentViewPlugin = NULL;
       
   244     }
       
   245 
       
   246     if ( viewType == MpxHbVideoCommon::CollectionView && mCollectionViewPlugin  ) 
       
   247     {
       
   248         if ( mIsService &&  (VideoServices::EPlayback == mVideoServices->currentService()) )
       
   249             {
       
   250                 qApp->quit();
       
   251                 XQServiceUtil::toBackground(false);
       
   252                 return;
       
   253             }
       
   254             else
       
   255             {
       
   256                 mCurrentViewPlugin = mCollectionViewPlugin;
       
   257             }
       
   258     }
       
   259     else if ( viewType == MpxHbVideoCommon::PlaybackView ) 
       
   260     {
       
   261 		if(!mPlaybackViewPlugin)
       
   262     	{
       
   263     		loadPlugin( MpxHbVideoCommon::PlaybackView );
       
   264     	    if ( mPlaybackViewPlugin ) 
       
   265     	    {
       
   266     	        mPlaybackViewPlugin->createView();
       
   267     	        hbInstance->allMainWindows().value(0)->addView( mPlaybackViewPlugin->getView() );
       
   268     	    }
       
   269     		else
       
   270     		{
       
   271     			return;
       
   272     		}
       
   273     	}
       
   274         mCurrentViewPlugin = mPlaybackViewPlugin;
       
   275     }
       
   276     else if ( viewType == MpxHbVideoCommon::VideoDetailsView ) 
       
   277     {
       
   278 		if(!mFileDetailsViewPlugin)
       
   279     	{
       
   280     		loadPlugin( MpxHbVideoCommon::VideoDetailsView );	
       
   281     		if ( mFileDetailsViewPlugin )
       
   282     		{
       
   283     			mFileDetailsViewPlugin->createView();
       
   284     			hbInstance->allMainWindows().value(0)->addView( mFileDetailsViewPlugin->getView() );
       
   285     		}
       
   286     		else
       
   287     		{
       
   288     			return;
       
   289     		}
       
   290     	}
       
   291         mCurrentViewPlugin = mFileDetailsViewPlugin;
       
   292     }
       
   293     else
       
   294     {
       
   295         // invalid plugin activation request, do nothing
       
   296         return;
       
   297     }
       
   298     
       
   299     hbInstance->allMainWindows().value(0)->setCurrentView( static_cast<HbView*>( mCurrentViewPlugin->getView() ), false );
       
   300     connectView();
       
   301     mCurrentViewPlugin->activateView();
       
   302 }
       
   303 
       
   304 // -------------------------------------------------------------------------------------------------
       
   305 // loadPlugin()
       
   306 // -------------------------------------------------------------------------------------------------
       
   307 //
       
   308 void QVideoPlayerEngine::loadPlugin( MpxHbVideoCommon::MpxHbVideoViewType viewType )
       
   309 {
       
   310 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::loadPlugin()"));
       
   311 	  
       
   312     int viewTypeUid( 0 );
       
   313 
       
   314     if ( viewType == MpxHbVideoCommon::CollectionView ) 
       
   315     {
       
   316         viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllCollectionUid;
       
   317     }
       
   318     else if ( viewType == MpxHbVideoCommon::PlaybackView ) 
       
   319     {
       
   320         viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllPlaybackUid;
       
   321     }
       
   322     else if( viewType == MpxHbVideoCommon::VideoDetailsView )
       
   323     {
       
   324         viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllFileDetailsUid;
       
   325     }
       
   326 
       
   327     if ( viewTypeUid )
       
   328     {
       
   329         // activate the collection view
       
   330         XQPluginLoader pluginLoader( viewTypeUid );
       
   331         QObject* instance = pluginLoader.instance();
       
   332 
       
   333         if ( instance )
       
   334         {
       
   335             if ( viewType == MpxHbVideoCommon::CollectionView ) 
       
   336             {
       
   337                 mCollectionViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
       
   338             }
       
   339             else if ( viewType == MpxHbVideoCommon::PlaybackView )
       
   340             {
       
   341                 mPlaybackViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
       
   342             }
       
   343             else if ( viewType == MpxHbVideoCommon::VideoDetailsView )
       
   344             {
       
   345                 mFileDetailsViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
       
   346             }
       
   347         }
       
   348     }
       
   349 }
       
   350 
       
   351 // -------------------------------------------------------------------------------------------------
       
   352 // connectView()
       
   353 // connect application to view by setting up the signals and slots.
       
   354 // -------------------------------------------------------------------------------------------------
       
   355 //
       
   356 void QVideoPlayerEngine::connectView()
       
   357 {
       
   358 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::connectView()"));
       
   359 	  
       
   360     connect( mCurrentViewPlugin,
       
   361              SIGNAL( command( int ) ),
       
   362              this,
       
   363              SLOT( handleCommand( int ) ) );
       
   364 }
       
   365 
       
   366 // -------------------------------------------------------------------------------------------------
       
   367 // disconnectView()
       
   368 // connect application to view by setting up the signals and slots.
       
   369 // -------------------------------------------------------------------------------------------------
       
   370 //
       
   371 void QVideoPlayerEngine::disconnectView()
       
   372 {
       
   373 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::disconnectView()"));
       
   374 	  
       
   375     if ( mCurrentViewPlugin )
       
   376     {
       
   377         disconnect( mCurrentViewPlugin,
       
   378                     SIGNAL( command( int ) ),
       
   379                     this,
       
   380                     SLOT( handleCommand( int ) ) );   
       
   381     }
       
   382 }
       
   383 
       
   384 // -------------------------------------------------------------------------------------------------
       
   385 // handleQuit()
       
   386 // -------------------------------------------------------------------------------------------------
       
   387 //
       
   388 void QVideoPlayerEngine::handleQuit()
       
   389 {
       
   390 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::handleQuit()"));
       
   391 	  
       
   392     delete this;
       
   393 }
       
   394 
       
   395 
       
   396 // -------------------------------------------------------------------------------------------------
       
   397 // playMedia()
       
   398 // -------------------------------------------------------------------------------------------------
       
   399 //
       
   400 void QVideoPlayerEngine::playMedia( QString filePath )
       
   401 {
       
   402 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::playMedia()")); 
       
   403 	  	
       
   404     mPlaybackWrapper->playMedia( filePath );
       
   405 }
       
   406 
       
   407 // -------------------------------------------------------------------------------------------------
       
   408 // setEmbedded()
       
   409 // -------------------------------------------------------------------------------------------------
       
   410 //
       
   411 void QVideoPlayerEngine::setEmbedded()
       
   412 {
       
   413 	  MPX_ENTER_EXIT(_L("QVideoPlayerEngine::setEmbedded()")); 
       
   414 	  
       
   415     mEmbedded = true;
       
   416 }
       
   417 
       
   418 // End of file