videoplayerapp/videoplayerengine/src/videoplayerengine.cpp
author hgs
Thu, 01 Apr 2010 22:38:49 +0300
changeset 30 4f111d64a341
child 34 bbb98528c666
permissions -rw-r--r--
201005
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Implementation of VideoPlayerEngine
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// Version : %version: 20 %
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <qapplication>
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
#include <hbinstance.h>
hgs
parents:
diff changeset
    24
#include <xqpluginloader.h>
hgs
parents:
diff changeset
    25
#include <xqplugininfo.h>
hgs
parents:
diff changeset
    26
#include <xqserviceutil.h>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include "videoplayerengine.h"
hgs
parents:
diff changeset
    29
#include "mpxvideoplaybackwrapper.h"
hgs
parents:
diff changeset
    30
#include "videoservices.h"
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    33
// QVideoPlayerEngine()
hgs
parents:
diff changeset
    34
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    35
//
hgs
parents:
diff changeset
    36
QVideoPlayerEngine::QVideoPlayerEngine(bool isService)
hgs
parents:
diff changeset
    37
    : mIsService( isService )
hgs
parents:
diff changeset
    38
    , mEmbedded(false)
hgs
parents:
diff changeset
    39
    , mCurrentViewPlugin( 0 )
hgs
parents:
diff changeset
    40
    , mPlaybackViewPlugin( 0 )
hgs
parents:
diff changeset
    41
    , mCollectionViewPlugin( 0 )
hgs
parents:
diff changeset
    42
    , mFileDetailsViewPlugin( 0 )
hgs
parents:
diff changeset
    43
    , mPlaybackWrapper( 0 )
hgs
parents:
diff changeset
    44
    , mVideoServices(0)
hgs
parents:
diff changeset
    45
{
hgs
parents:
diff changeset
    46
}
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    49
// ~QVideoPlayerEngine()
hgs
parents:
diff changeset
    50
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    51
//
hgs
parents:
diff changeset
    52
QVideoPlayerEngine::~QVideoPlayerEngine()
hgs
parents:
diff changeset
    53
{
hgs
parents:
diff changeset
    54
    if ( mVideoServices )
hgs
parents:
diff changeset
    55
    {
hgs
parents:
diff changeset
    56
    	mVideoServices->decreaseReferenceCount();
hgs
parents:
diff changeset
    57
    	mVideoServices = 0;
hgs
parents:
diff changeset
    58
    }
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
    if ( mCollectionViewPlugin ) 
hgs
parents:
diff changeset
    61
    {
hgs
parents:
diff changeset
    62
        mCollectionViewPlugin->destroyView();
hgs
parents:
diff changeset
    63
    }
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
    if ( mPlaybackViewPlugin ) 
hgs
parents:
diff changeset
    66
    {
hgs
parents:
diff changeset
    67
        mPlaybackViewPlugin->destroyView();
hgs
parents:
diff changeset
    68
    }
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
    if ( mFileDetailsViewPlugin ) 
hgs
parents:
diff changeset
    71
    {
hgs
parents:
diff changeset
    72
        mFileDetailsViewPlugin->destroyView();
hgs
parents:
diff changeset
    73
    }
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
    delete mPlaybackWrapper;
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
    // disconnect all signals 
hgs
parents:
diff changeset
    78
    disconnect();
hgs
parents:
diff changeset
    79
}
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    82
// initialize()
hgs
parents:
diff changeset
    83
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
    84
//
hgs
parents:
diff changeset
    85
void QVideoPlayerEngine::initialize()
hgs
parents:
diff changeset
    86
{
hgs
parents:
diff changeset
    87
    //
hgs
parents:
diff changeset
    88
    // Clean up QVideoPlayerEngine when qApp try to quit
hgs
parents:
diff changeset
    89
    //
hgs
parents:
diff changeset
    90
    connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( handleQuit() ) );
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
    //
hgs
parents:
diff changeset
    93
    // Create playback wrapper
hgs
parents:
diff changeset
    94
    //
hgs
parents:
diff changeset
    95
    if ( !mPlaybackWrapper )
hgs
parents:
diff changeset
    96
    {
hgs
parents:
diff changeset
    97
        mPlaybackWrapper = new QMpxVideoPlaybackWrapper();
hgs
parents:
diff changeset
    98
        connect( mPlaybackWrapper,
hgs
parents:
diff changeset
    99
                 SIGNAL( handlePlaybackView( int ) ),
hgs
parents:
diff changeset
   100
                 this,
hgs
parents:
diff changeset
   101
                 SLOT( handleCommand( int ) ) );
hgs
parents:
diff changeset
   102
    }
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
    //
hgs
parents:
diff changeset
   105
    // Get VideoServices instance
hgs
parents:
diff changeset
   106
    //
hgs
parents:
diff changeset
   107
    if( mIsService && !mVideoServices )
hgs
parents:
diff changeset
   108
    {
hgs
parents:
diff changeset
   109
		mVideoServices = VideoServices::instance(this);
hgs
parents:
diff changeset
   110
		connect( mVideoServices, SIGNAL(activated(int)), this, SLOT(handleCommand(int)));
hgs
parents:
diff changeset
   111
    }
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
    QList<XQPluginInfo> impls;
hgs
parents:
diff changeset
   114
    XQPluginLoader::listImplementations("org.nokia.mmdt.MpxViewPlugin/1.0", impls);
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    //
hgs
parents:
diff changeset
   117
    // Pre-load collectionview and playbackview plugins
hgs
parents:
diff changeset
   118
    //
hgs
parents:
diff changeset
   119
    loadPlugin( MpxHbVideoCommon::CollectionView );
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
    if ( mCollectionViewPlugin ) 
hgs
parents:
diff changeset
   122
    {
hgs
parents:
diff changeset
   123
        mCollectionViewPlugin->createView();
hgs
parents:
diff changeset
   124
    }
hgs
parents:
diff changeset
   125
    
hgs
parents:
diff changeset
   126
    loadPlugin( MpxHbVideoCommon::PlaybackView );
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
    if ( mPlaybackViewPlugin ) 
hgs
parents:
diff changeset
   129
    {
hgs
parents:
diff changeset
   130
        mPlaybackViewPlugin->createView();
hgs
parents:
diff changeset
   131
    }
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
	loadPlugin( MpxHbVideoCommon::VideoDetailsView );
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
	if ( mFileDetailsViewPlugin )
hgs
parents:
diff changeset
   136
	{
hgs
parents:
diff changeset
   137
		mFileDetailsViewPlugin->createView();
hgs
parents:
diff changeset
   138
	}
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
    //
hgs
parents:
diff changeset
   141
    // default view in the app is the collection view.
hgs
parents:
diff changeset
   142
    //
hgs
parents:
diff changeset
   143
    if(!mIsService)
hgs
parents:
diff changeset
   144
    {
hgs
parents:
diff changeset
   145
        activateView( MpxHbVideoCommon::CollectionView );
hgs
parents:
diff changeset
   146
    }            
hgs
parents:
diff changeset
   147
}
hgs
parents:
diff changeset
   148
hgs
parents:
diff changeset
   149
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   150
// handleCommand()
hgs
parents:
diff changeset
   151
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   152
//
hgs
parents:
diff changeset
   153
void QVideoPlayerEngine::handleCommand( int commandCode )
hgs
parents:
diff changeset
   154
{
hgs
parents:
diff changeset
   155
    switch ( commandCode )
hgs
parents:
diff changeset
   156
    {
hgs
parents:
diff changeset
   157
        case MpxHbVideoCommon::ActivateCollectionView:
hgs
parents:
diff changeset
   158
        {
hgs
parents:
diff changeset
   159
            if ( mCurrentViewPlugin != mCollectionViewPlugin )
hgs
parents:
diff changeset
   160
            { 
hgs
parents:
diff changeset
   161
                activateView( MpxHbVideoCommon::CollectionView );
hgs
parents:
diff changeset
   162
            }
hgs
parents:
diff changeset
   163
            break;
hgs
parents:
diff changeset
   164
        }
hgs
parents:
diff changeset
   165
        case MpxHbVideoCommon::ActivatePlaybackView:
hgs
parents:
diff changeset
   166
        {
hgs
parents:
diff changeset
   167
            if ( mCurrentViewPlugin != mPlaybackViewPlugin )
hgs
parents:
diff changeset
   168
            {                
hgs
parents:
diff changeset
   169
                activateView( MpxHbVideoCommon::PlaybackView );                
hgs
parents:
diff changeset
   170
            }
hgs
parents:
diff changeset
   171
            break;
hgs
parents:
diff changeset
   172
        }
hgs
parents:
diff changeset
   173
        case MpxHbVideoCommon::ActivateVideoDetailsView:
hgs
parents:
diff changeset
   174
        {
hgs
parents:
diff changeset
   175
            if ( mCurrentViewPlugin != mFileDetailsViewPlugin )
hgs
parents:
diff changeset
   176
			{
hgs
parents:
diff changeset
   177
				activateView( MpxHbVideoCommon::VideoDetailsView );                
hgs
parents:
diff changeset
   178
            }
hgs
parents:
diff changeset
   179
            break;
hgs
parents:
diff changeset
   180
        }
hgs
parents:
diff changeset
   181
        case MpxHbVideoCommon::LoadVideoDetailsView:
hgs
parents:
diff changeset
   182
        {
hgs
parents:
diff changeset
   183
			if ( mFileDetailsViewPlugin )
hgs
parents:
diff changeset
   184
			{
hgs
parents:
diff changeset
   185
				mFileDetailsViewPlugin->createView();
hgs
parents:
diff changeset
   186
			}
hgs
parents:
diff changeset
   187
			break;
hgs
parents:
diff changeset
   188
		}
hgs
parents:
diff changeset
   189
        
hgs
parents:
diff changeset
   190
        default:
hgs
parents:
diff changeset
   191
        {
hgs
parents:
diff changeset
   192
            break;
hgs
parents:
diff changeset
   193
        }
hgs
parents:
diff changeset
   194
    }    
hgs
parents:
diff changeset
   195
}
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   198
// activateView()
hgs
parents:
diff changeset
   199
// activate view based on view type.
hgs
parents:
diff changeset
   200
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   201
//
hgs
parents:
diff changeset
   202
void QVideoPlayerEngine::activateView( MpxHbVideoCommon::MpxHbVideoViewType viewType )
hgs
parents:
diff changeset
   203
{
hgs
parents:
diff changeset
   204
    disconnectView();
hgs
parents:
diff changeset
   205
    
hgs
parents:
diff changeset
   206
    if ( mCurrentViewPlugin )
hgs
parents:
diff changeset
   207
    {
hgs
parents:
diff changeset
   208
        mCurrentViewPlugin->deactivateView();
hgs
parents:
diff changeset
   209
        hbInstance->allMainWindows().value(0)->removeView( mCurrentViewPlugin->getView() );
hgs
parents:
diff changeset
   210
        mCurrentViewPlugin = NULL;
hgs
parents:
diff changeset
   211
    }
hgs
parents:
diff changeset
   212
hgs
parents:
diff changeset
   213
    if ( viewType == MpxHbVideoCommon::CollectionView && mCollectionViewPlugin  ) 
hgs
parents:
diff changeset
   214
    {
hgs
parents:
diff changeset
   215
        if ( mIsService &&  (VideoServices::EPlayback == mVideoServices->currentService()) )
hgs
parents:
diff changeset
   216
            {
hgs
parents:
diff changeset
   217
                qApp->quit();
hgs
parents:
diff changeset
   218
                XQServiceUtil::toBackground(false);
hgs
parents:
diff changeset
   219
                return;
hgs
parents:
diff changeset
   220
            }
hgs
parents:
diff changeset
   221
            else
hgs
parents:
diff changeset
   222
            {
hgs
parents:
diff changeset
   223
                mCurrentViewPlugin = mCollectionViewPlugin;
hgs
parents:
diff changeset
   224
            }
hgs
parents:
diff changeset
   225
    }
hgs
parents:
diff changeset
   226
    else if ( viewType == MpxHbVideoCommon::PlaybackView && mPlaybackViewPlugin ) 
hgs
parents:
diff changeset
   227
    {
hgs
parents:
diff changeset
   228
        mCurrentViewPlugin = mPlaybackViewPlugin;
hgs
parents:
diff changeset
   229
    }
hgs
parents:
diff changeset
   230
    else if ( viewType == MpxHbVideoCommon::VideoDetailsView && mFileDetailsViewPlugin ) 
hgs
parents:
diff changeset
   231
    {
hgs
parents:
diff changeset
   232
        mCurrentViewPlugin = mFileDetailsViewPlugin;
hgs
parents:
diff changeset
   233
    }
hgs
parents:
diff changeset
   234
    else
hgs
parents:
diff changeset
   235
    {
hgs
parents:
diff changeset
   236
        // invalid plugin activation request, do nothing
hgs
parents:
diff changeset
   237
        return;
hgs
parents:
diff changeset
   238
    }
hgs
parents:
diff changeset
   239
hgs
parents:
diff changeset
   240
    hbInstance->allMainWindows().value(0)->addView( mCurrentViewPlugin->getView() );
hgs
parents:
diff changeset
   241
    connectView();
hgs
parents:
diff changeset
   242
    mCurrentViewPlugin->activateView();
hgs
parents:
diff changeset
   243
}
hgs
parents:
diff changeset
   244
hgs
parents:
diff changeset
   245
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   246
// loadPlugin()
hgs
parents:
diff changeset
   247
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   248
//
hgs
parents:
diff changeset
   249
void QVideoPlayerEngine::loadPlugin( MpxHbVideoCommon::MpxHbVideoViewType viewType )
hgs
parents:
diff changeset
   250
{
hgs
parents:
diff changeset
   251
    int viewTypeUid( 0 );
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
    if ( viewType == MpxHbVideoCommon::CollectionView ) 
hgs
parents:
diff changeset
   254
    {
hgs
parents:
diff changeset
   255
        viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllCollectionUid;
hgs
parents:
diff changeset
   256
    }
hgs
parents:
diff changeset
   257
    else if ( viewType == MpxHbVideoCommon::PlaybackView ) 
hgs
parents:
diff changeset
   258
    {
hgs
parents:
diff changeset
   259
        viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllPlaybackUid;
hgs
parents:
diff changeset
   260
    }
hgs
parents:
diff changeset
   261
    else if( viewType == MpxHbVideoCommon::VideoDetailsView )
hgs
parents:
diff changeset
   262
    {
hgs
parents:
diff changeset
   263
        viewTypeUid = MpxHbVideoCommon::KMpxVideoPluginDllFileDetailsUid;
hgs
parents:
diff changeset
   264
    }
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
    if ( viewTypeUid )
hgs
parents:
diff changeset
   267
    {
hgs
parents:
diff changeset
   268
        // activate the collection view
hgs
parents:
diff changeset
   269
        XQPluginLoader pluginLoader( viewTypeUid );
hgs
parents:
diff changeset
   270
        QObject* instance = pluginLoader.instance();
hgs
parents:
diff changeset
   271
hgs
parents:
diff changeset
   272
        if ( instance )
hgs
parents:
diff changeset
   273
        {
hgs
parents:
diff changeset
   274
            if ( viewType == MpxHbVideoCommon::CollectionView ) 
hgs
parents:
diff changeset
   275
            {
hgs
parents:
diff changeset
   276
                mCollectionViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
hgs
parents:
diff changeset
   277
            }
hgs
parents:
diff changeset
   278
            else if ( viewType == MpxHbVideoCommon::PlaybackView )
hgs
parents:
diff changeset
   279
            {
hgs
parents:
diff changeset
   280
                mPlaybackViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
hgs
parents:
diff changeset
   281
            }
hgs
parents:
diff changeset
   282
            else if ( viewType == MpxHbVideoCommon::VideoDetailsView )
hgs
parents:
diff changeset
   283
            {
hgs
parents:
diff changeset
   284
                mFileDetailsViewPlugin = qobject_cast<MpxViewPlugin*>( instance )->viewPlugin();
hgs
parents:
diff changeset
   285
            }
hgs
parents:
diff changeset
   286
        }
hgs
parents:
diff changeset
   287
    }
hgs
parents:
diff changeset
   288
}
hgs
parents:
diff changeset
   289
hgs
parents:
diff changeset
   290
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   291
// connectView()
hgs
parents:
diff changeset
   292
// connect application to view by setting up the signals and slots.
hgs
parents:
diff changeset
   293
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   294
//
hgs
parents:
diff changeset
   295
void QVideoPlayerEngine::connectView()
hgs
parents:
diff changeset
   296
{
hgs
parents:
diff changeset
   297
    connect( mCurrentViewPlugin,
hgs
parents:
diff changeset
   298
             SIGNAL( command( int ) ),
hgs
parents:
diff changeset
   299
             this,
hgs
parents:
diff changeset
   300
             SLOT( handleCommand( int ) ) );
hgs
parents:
diff changeset
   301
}
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   304
// disconnectView()
hgs
parents:
diff changeset
   305
// connect application to view by setting up the signals and slots.
hgs
parents:
diff changeset
   306
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   307
//
hgs
parents:
diff changeset
   308
void QVideoPlayerEngine::disconnectView()
hgs
parents:
diff changeset
   309
{
hgs
parents:
diff changeset
   310
    if ( mCurrentViewPlugin )
hgs
parents:
diff changeset
   311
    {
hgs
parents:
diff changeset
   312
        disconnect( mCurrentViewPlugin,
hgs
parents:
diff changeset
   313
                    SIGNAL( command( int ) ),
hgs
parents:
diff changeset
   314
                    this,
hgs
parents:
diff changeset
   315
                    SLOT( handleCommand( int ) ) );   
hgs
parents:
diff changeset
   316
    }
hgs
parents:
diff changeset
   317
}
hgs
parents:
diff changeset
   318
hgs
parents:
diff changeset
   319
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   320
// handleQuit()
hgs
parents:
diff changeset
   321
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   322
//
hgs
parents:
diff changeset
   323
void QVideoPlayerEngine::handleQuit()
hgs
parents:
diff changeset
   324
{
hgs
parents:
diff changeset
   325
    delete this;
hgs
parents:
diff changeset
   326
}
hgs
parents:
diff changeset
   327
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   330
// playMedia()
hgs
parents:
diff changeset
   331
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   332
//
hgs
parents:
diff changeset
   333
void QVideoPlayerEngine::playMedia( QString filePath )
hgs
parents:
diff changeset
   334
{
hgs
parents:
diff changeset
   335
    mPlaybackWrapper->playMedia( filePath );
hgs
parents:
diff changeset
   336
}
hgs
parents:
diff changeset
   337
hgs
parents:
diff changeset
   338
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   339
// setEmbedded()
hgs
parents:
diff changeset
   340
// -------------------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   341
//
hgs
parents:
diff changeset
   342
void QVideoPlayerEngine::setEmbedded()
hgs
parents:
diff changeset
   343
{
hgs
parents:
diff changeset
   344
    mEmbedded = true;
hgs
parents:
diff changeset
   345
}
hgs
parents:
diff changeset
   346
hgs
parents:
diff changeset
   347
// End of file