15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <hbapplication.h> |
19 #include <hbapplication.h> |
20 #include <hbactivitymanager.h> |
|
21 #include <hbview.h> |
20 #include <hbview.h> |
22 #include <mpxviewpluginqt.h> |
21 #include <mpxviewpluginqt.h> |
23 #include <xqpluginloader.h> |
22 #include <xqpluginloader.h> |
24 #include <xqplugininfo.h> |
23 #include <xqplugininfo.h> |
25 #include <xqserviceutil.h> |
24 #include <xqserviceutil.h> |
26 #include <xqsharablefile.h> |
25 #include <xqsharablefile.h> |
|
26 #include <afactivitystorage.h> |
|
27 #include <afactivation.h> |
27 |
28 |
28 #include "mpmainwindow.h" |
29 #include "mpmainwindow.h" |
29 #include "mpviewbase.h" |
30 #include "mpviewbase.h" |
30 #include "musicservices.h" |
31 #include "musicservices.h" |
31 #include "mpenginefactory.h" |
32 #include "mpenginefactory.h" |
126 |
128 |
127 if ( XQServiceUtil::isService() ) { |
129 if ( XQServiceUtil::isService() ) { |
128 // Music Service mode |
130 // Music Service mode |
129 // Set the Collection View and Playback View to fetcher mode |
131 // Set the Collection View and Playback View to fetcher mode |
130 mMusicServices = new MusicServices(); |
132 mMusicServices = new MusicServices(); |
131 int err = connect(mMusicServices, SIGNAL(serviceActive( TUid )), this, SLOT(initializeServiceView( TUid ))); |
133 int err = connect(mMusicServices, SIGNAL(serviceActive( quint32 )), this, SLOT(initializeServiceView( quint32 ))); |
132 TX_LOG_ARGS("connection error: " << err); |
134 TX_LOG_ARGS("connection error: " << err); |
133 XQServiceUtil::toBackground( false ); |
135 XQServiceUtil::toBackground( false ); |
134 } |
136 } |
135 |
137 AfActivation *activation = new AfActivation( this ); |
|
138 |
|
139 |
|
140 mActivityStorage = new AfActivityStorage; |
136 if ( !mMusicServices ) { |
141 if ( !mMusicServices ) { |
137 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
142 QVariantHash params = activation->parameters(); |
138 QVariantHash params = app->activateParams(); |
143 ActivityMode mode = !params.value( "activityname" ).toString().compare( MUSIC_NOW_PLAYING_VIEW ) ? MpMainWindow::MusicNowPlayingView : MpMainWindow::MusicMainView; |
|
144 |
139 MpEngineFactory::createSharedEngine(); |
145 MpEngineFactory::createSharedEngine(); |
140 mPopupHandler = new MpGlobalPopupHandler( this ); |
146 mPopupHandler = new MpGlobalPopupHandler( this ); |
141 if( app->activateReason() == Hb::ActivationReasonActivity ) { |
147 if( activation->reason() == Af::ActivationReasonActivity ) { |
142 // Restoring an activity, not a fresh startup or a service |
148 // Restoring an activity, not a fresh startup or a service |
143 // Activities from Task switcher only have one parameter |
149 // Activities from Task switcher only have one parameter |
144 if( params.count() == 1 ) { |
150 if( params.count() == 1 ) { |
145 loadActivity( app->activateData() ); |
151 loadActivity( mActivityStorage->activityData( activation->name() ) ); |
146 } |
152 } |
147 } |
153 } |
148 if ( orientation() == Qt::Vertical ) { |
154 if ( orientation() == Qt::Vertical ) { |
149 // If first startup ignore shuffleAll and send to collection view to refresh library |
155 // If first startup ignore shuffleAll and send to collection view to refresh library |
150 if ( mode == MusicMainView || MpSettingsManager::firstStartup() ) { |
156 if ( mode == MusicMainView || MpSettingsManager::firstStartup() ) { |
181 } |
187 } |
182 connect(this, SIGNAL( orientationChanged( Qt::Orientation ) ), SLOT( switchView( Qt::Orientation ) ) ); |
188 connect(this, SIGNAL( orientationChanged( Qt::Orientation ) ), SLOT( switchView( Qt::Orientation ) ) ); |
183 connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) ); |
189 connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) ); |
184 MpEngineFactory::sharedEngine()->checkForSystemEvents(); |
190 MpEngineFactory::sharedEngine()->checkForSystemEvents(); |
185 //Register to application manager to wait for activities and clear previous activities on the task switcher |
191 //Register to application manager to wait for activities and clear previous activities on the task switcher |
186 mActivityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
192 qRegisterMetaType<Af::ActivationReason>( "Af::ActivationReason" ); |
187 mActivityManager->waitActivity(); |
193 connect( activation, SIGNAL( activated( Af::ActivationReason, QString, QVariantHash ) ), this, SLOT( loadActivityData( Af::ActivationReason, QString, QVariantHash ) ) ); |
188 mActivityManager->removeActivity( MUSIC_MAIN_VIEW ); |
194 connect( MpEngineFactory::sharedEngine(), SIGNAL( restorePathFailed() ), this, SLOT( handleRestorePathFailed() ) ); |
189 mActivityManager->removeActivity( MUSIC_NOW_PLAYING_VIEW ); |
195 mActivityStorage->removeActivity( MUSIC_MAIN_VIEW ); |
190 connect( app, SIGNAL( activate() ), this , SLOT( handleActivity() ) ); |
196 mActivityStorage->removeActivity( MUSIC_NOW_PLAYING_VIEW ); |
191 connect( app, SIGNAL( aboutToQuit() ), this, SLOT( saveActivity() ) ); |
197 connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( saveActivity() ) ); |
192 mMpMediaController = new MpMediaController(); |
198 mMpMediaController = new MpMediaController(); |
193 emit applicationReady(); |
199 emit applicationReady(); |
194 |
200 |
195 } |
201 } |
196 else { |
202 else { |
356 Reimp. |
362 Reimp. |
357 */ |
363 */ |
358 void MpMainWindow::keyPressEvent(QKeyEvent *event) |
364 void MpMainWindow::keyPressEvent(QKeyEvent *event) |
359 { |
365 { |
360 switch(event->key()) { |
366 switch(event->key()) { |
|
367 //RND feature to rotate on emulator. |
|
368 #ifdef __WINS__ |
361 case 16842753: |
369 case 16842753: |
362 case Qt::Key_Call: |
370 case Qt::Key_Call: |
363 if (orientation () == Qt::Vertical) { |
371 if (orientation () == Qt::Vertical) { |
364 setOrientation(Qt::Horizontal, false); |
372 setOrientation(Qt::Horizontal, false); |
365 } |
373 } |
366 else { |
374 else { |
367 setOrientation(Qt::Vertical, false); |
375 setOrientation(Qt::Vertical, false); |
368 } |
376 } |
369 break; |
377 break; |
|
378 #endif // __WINS__ |
370 default: |
379 default: |
371 HbMainWindow::keyPressEvent (event); |
380 HbMainWindow::keyPressEvent (event); |
372 break; |
381 break; |
373 } |
382 } |
374 } |
383 } |
375 |
384 |
376 /*! |
385 /*! |
377 Slot to initialize the view that corresponds to the requested service |
386 Slot to initialize the view that corresponds to the requested service |
378 */ |
387 */ |
379 void MpMainWindow::initializeServiceView( TUid hostUid ) |
388 void MpMainWindow::initializeServiceView( quint32 clientSecureId ) |
380 { |
389 { |
381 switch (mMusicServices->currentService()) { |
390 switch (mMusicServices->currentService()) { |
382 |
391 |
383 case MusicServices::EUriFetcher: |
392 case MusicServices::EUriFetcher: |
384 { |
393 { |
385 MpEngineFactory::createSharedEngine( hostUid , MpEngine::Fetch ); |
394 MpEngineFactory::createSharedEngine( clientSecureId , MpEngine::Fetch ); |
386 mPopupHandler = new MpGlobalPopupHandler( this ); |
395 mPopupHandler = new MpGlobalPopupHandler( this ); |
387 loadView( CollectionView, MpCommon::FetchView ); |
396 loadView( CollectionView, MpCommon::FetchView ); |
388 MpViewBase* collectionView = reinterpret_cast<MpViewBase*>(mCollectionViewPlugin->getView()); |
397 MpViewBase* collectionView = reinterpret_cast<MpViewBase*>(mCollectionViewPlugin->getView()); |
389 connect(collectionView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString))); |
398 connect(collectionView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString))); |
390 activateView( CollectionView ); |
399 activateView( CollectionView ); |
395 MpEngineFactory::sharedEngine()->checkForSystemEvents(); |
404 MpEngineFactory::sharedEngine()->checkForSystemEvents(); |
396 break; |
405 break; |
397 } |
406 } |
398 case MusicServices::EPlayback: |
407 case MusicServices::EPlayback: |
399 { |
408 { |
400 MpEngineFactory::createSharedEngine( hostUid , MpEngine::Embedded ); |
409 MpEngineFactory::createSharedEngine( clientSecureId , MpEngine::Embedded ); |
401 loadView(PlaybackView, MpCommon::EmbeddedView ); |
410 loadView(PlaybackView, MpCommon::EmbeddedView ); |
402 MpViewBase* playbackView = reinterpret_cast<MpViewBase*>(mPlaybackViewPlugin->getView()); |
411 MpViewBase* playbackView = reinterpret_cast<MpViewBase*>(mPlaybackViewPlugin->getView()); |
403 connect(mMusicServices, SIGNAL(playReady(QString)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(QString))); |
412 connect(mMusicServices, SIGNAL(playReady(QString)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(QString))); |
404 connect(mMusicServices, SIGNAL(playReady(const XQSharableFile&)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(const XQSharableFile&))); |
413 connect(mMusicServices, SIGNAL(playReady(const XQSharableFile&)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(const XQSharableFile&))); |
405 connect(playbackView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString))); |
414 connect(playbackView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString))); |
406 activateView( PlaybackView ); |
415 activateView( PlaybackView ); |
417 /*! |
426 /*! |
418 Slot to handle activity switching once the stand alone instance is running and registered |
427 Slot to handle activity switching once the stand alone instance is running and registered |
419 in the activity manager to wait for activities. |
428 in the activity manager to wait for activities. |
420 Only running activity supported at the moment is "MusicNowPlayingView" |
429 Only running activity supported at the moment is "MusicNowPlayingView" |
421 */ |
430 */ |
422 void MpMainWindow::handleActivity() |
431 |
423 { |
432 void MpMainWindow::loadActivityData( Af::ActivationReason reason, const QString &name, QVariantHash parameter ) |
424 TX_ENTRY |
433 { |
425 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
434 TX_ENTRY |
426 QString activityId = app->activateId(); |
435 if( reason == Af::ActivationReasonActivity ) { |
427 |
436 QString activityId = name; |
428 if( !activityId.compare( MUSIC_NOW_PLAYING_VIEW ) ) { |
437 QVariantHash params = parameter; |
429 if ( orientation() == Qt::Vertical ) { |
438 if( !activityId.compare( MUSIC_NOW_PLAYING_VIEW ) ) { |
430 if( mVerticalViewType != PlaybackView ) { |
439 if( params.contains( "shuffle" ) ) { |
431 activateView( PlaybackView ); |
440 if( !params.value( "shuffle" ).toString().compare( "yes" ) ) { |
432 } |
441 MpEngineFactory::sharedEngine()->shuffleAll(); |
433 } |
442 } |
434 } |
443 } |
435 |
444 if ( orientation() == Qt::Vertical ) { |
436 mActivityManager->waitActivity(); |
445 if( mVerticalViewType != PlaybackView ) { |
|
446 activateView( PlaybackView ); |
|
447 } |
|
448 } |
|
449 } |
|
450 } |
437 TX_EXIT |
451 TX_EXIT |
438 } |
452 } |
439 |
453 |
440 /*! |
454 /*! |
441 Slot to save activity upon exiting application |
455 Slot to save activity upon exiting application |
458 activityParameters.insert( "screenshot", QPixmap::grabWidget( this, this->rect() ) ); |
472 activityParameters.insert( "screenshot", QPixmap::grabWidget( this, this->rect() ) ); |
459 QVariantHash activityData; |
473 QVariantHash activityData; |
460 activityData.insert( "restorePath", serializedRestorePath ); |
474 activityData.insert( "restorePath", serializedRestorePath ); |
461 |
475 |
462 |
476 |
463 bool ok = mActivityManager->addActivity( activity , activityData, activityParameters ); |
477 bool ok = mActivityStorage->saveActivity( activity , activityData, activityParameters ); |
464 if ( !ok ){ |
478 if ( !ok ){ |
465 TX_LOG_ARGS( "Error: Add Failed; should never get here." ); |
479 TX_LOG_ARGS( "Error: Add Failed; should never get here." ); |
466 } |
480 } |
467 TX_EXIT |
481 TX_EXIT |
468 } |
482 } |
539 void MpMainWindow::loadActivity( QVariant data ) |
553 void MpMainWindow::loadActivity( QVariant data ) |
540 { |
554 { |
541 TX_ENTRY |
555 TX_ENTRY |
542 QVariantHash activityData = data.toHash(); |
556 QVariantHash activityData = data.toHash(); |
543 QByteArray serializedRestorePath = activityData.value( "restorePath" ).toByteArray(); |
557 QByteArray serializedRestorePath = activityData.value( "restorePath" ).toByteArray(); |
544 connect( MpEngineFactory::sharedEngine(), SIGNAL( restorePathFailed() ), this, SLOT( handleRestorePathFailed() ) ); |
|
545 MpEngineFactory::sharedEngine()->loadActivityData( serializedRestorePath ); |
558 MpEngineFactory::sharedEngine()->loadActivityData( serializedRestorePath ); |
546 TX_EXIT |
559 TX_EXIT |
547 } |
560 } |
548 |
561 |