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