app/src/mpmainwindow.cpp
changeset 38 b93f525c9244
parent 37 eb79a7c355bf
child 43 0f32e550d9d8
child 48 af3740e3753f
equal deleted inserted replaced
37:eb79a7c355bf 38:b93f525c9244
    31 #include "mpenginefactory.h"
    31 #include "mpenginefactory.h"
    32 #include "mpsettingsmanager.h"
    32 #include "mpsettingsmanager.h"
    33 #include "mpglobalpopuphandler.h"
    33 #include "mpglobalpopuphandler.h"
    34 #include "mptrace.h"
    34 #include "mptrace.h"
    35 
    35 
       
    36 const QString MUSIC_MAIN_VIEW = "MusicMainView";
       
    37 const QString MUSIC_NOW_PLAYING_VIEW = "MusicNowPlayingView";
       
    38 
    36 /*!
    39 /*!
    37    \class MpMainWindow
    40    \class MpMainWindow
    38    \brief The MpMainWindow class provides Main Window functionalities.
    41    \brief The MpMainWindow class provides Main Window functionalities.
    39 
    42 
    40    MpMainWindow handles activation of views
    43    MpMainWindow handles activation of views
    53       mDetailsViewPlugin(0),
    56       mDetailsViewPlugin(0),
    54       mMediaWallViewPlugin(0),
    57       mMediaWallViewPlugin(0),
    55       mCurrentViewPlugin(0),
    58       mCurrentViewPlugin(0),
    56       mVerticalViewType( CollectionView ),
    59       mVerticalViewType( CollectionView ),
    57       mMusicServices(0),
    60       mMusicServices(0),
    58       mPopupHandler(0)
    61       mPopupHandler(0),
       
    62       mUserExit( false ),
       
    63       mActivityManager(0)
    59 {
    64 {
    60     TX_LOG
    65     TX_LOG
    61 }
    66 }
    62 
    67 
    63 /*!
    68 /*!
   121         TX_LOG_ARGS("connection error: " << err);
   126         TX_LOG_ARGS("connection error: " << err);
   122         XQServiceUtil::toBackground( false );
   127         XQServiceUtil::toBackground( false );
   123     }
   128     }
   124 
   129 
   125     if ( !mMusicServices ) {
   130     if ( !mMusicServices ) {
       
   131         HbApplication* app = qobject_cast<HbApplication*>(qApp);
       
   132         QVariantHash params = app->activateParams();
   126         MpEngineFactory::createSharedEngine();
   133         MpEngineFactory::createSharedEngine();
   127         mPopupHandler = new MpGlobalPopupHandler( this );
   134         mPopupHandler = new MpGlobalPopupHandler( this );
       
   135         if( app->activateReason() == Hb::ActivationReasonActivity ) {
       
   136             // Restoring an activity, not a fresh startup or a service
       
   137             // Activities from Task switcher only have one parameter
       
   138             if( params.count() == 1 ) {
       
   139                  loadActivity( app->activateData() );
       
   140             }
       
   141         }
   128         if ( orientation() == Qt::Vertical ) {
   142         if ( orientation() == Qt::Vertical ) {
   129             // If first startup ignore shuffleAll and send to collection view to refresh library
   143             // If first startup ignore shuffleAll and send to collection view to refresh library
   130             if ( mode == MusicMainView  || MpSettingsManager::firstStartup() ) {
   144             if ( mode == MusicMainView  || MpSettingsManager::firstStartup() ) {
   131                 loadView(CollectionView);
   145                 loadView( CollectionView );
   132                 activateView(CollectionView);
   146                 activateView( CollectionView );
   133                 loadView(MediaWallView);
   147                 loadView( MediaWallView );
   134                 loadView( PlaybackView );
   148                 loadView( PlaybackView );
   135             } else if (mode == MusicNowPlayingViewShuffleAll ) {
   149             } else if ( mode == MusicNowPlayingView ) {
   136                 MpEngineFactory::sharedEngine()->shuffleAll();
   150                 if( params.contains( "shuffle" ) ) {
       
   151                     if( !params.value( "shuffle" ).toString().compare( "yes" ) ) {
       
   152                         MpEngineFactory::sharedEngine()->shuffleAll();
       
   153                     }
       
   154                 }
   137                 loadView( PlaybackView );
   155                 loadView( PlaybackView );
   138                 activateView(PlaybackView);
   156                 activateView( PlaybackView );
   139                 loadView(CollectionView);
   157                 loadView( CollectionView );
   140                 loadView(MediaWallView);
   158                 loadView( MediaWallView );
   141             }
   159             }
   142         }
   160         }
   143         else {
   161         else {
   144             // If first startup ignore shuffleAll and send to refresh library
   162             // If first startup ignore shuffleAll and send to refresh library
   145             if( mode == MusicNowPlayingViewShuffleAll && !MpSettingsManager::firstStartup() ) {
   163             if( mode == MusicNowPlayingView && !MpSettingsManager::firstStartup() ) {
   146                 MpEngineFactory::sharedEngine()->shuffleAll();
   164                 if( params.contains( "shuffle" ) ) {
       
   165                     if( !params.value( "shuffle" ).toString().compare( "yes" ) ) {
       
   166                         MpEngineFactory::sharedEngine()->shuffleAll();
       
   167                     }
       
   168                 }
   147                 mVerticalViewType = PlaybackView;
   169                 mVerticalViewType = PlaybackView;
   148             }
   170             }
   149             loadView(MediaWallView);
   171             loadView( MediaWallView );
   150             activateView(MediaWallView);
   172             activateView( MediaWallView );
   151             loadView(CollectionView);
   173             loadView( CollectionView );
   152             loadView( PlaybackView );
   174             loadView( PlaybackView );
   153         }
   175         }
   154         connect(this, SIGNAL( orientationChanged( Qt::Orientation ) ), SLOT( switchView( Qt::Orientation ) ) );
   176         connect(this, SIGNAL( orientationChanged( Qt::Orientation ) ), SLOT( switchView( Qt::Orientation ) ) );
   155         connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) );
   177         connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) );
   156         MpEngineFactory::sharedEngine()->checkForSystemEvents();
   178         MpEngineFactory::sharedEngine()->checkForSystemEvents();
   157         //Register to application manager to wait for activities
   179         //Register to application manager to wait for activities and clear previous activities on the task switcher
   158         HbApplication* app = qobject_cast<HbApplication*>(qApp);
   180         mActivityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
   159         app->activityManager()->waitActivity();
   181         mActivityManager->waitActivity();
       
   182         mActivityManager->removeActivity( MUSIC_MAIN_VIEW );
       
   183         mActivityManager->removeActivity( MUSIC_NOW_PLAYING_VIEW );
   160         connect( app, SIGNAL( activate() ), this , SLOT( handleActivity() ) );
   184         connect( app, SIGNAL( activate() ), this , SLOT( handleActivity() ) );
       
   185         connect( app, SIGNAL( aboutToQuit() ), this, SLOT( saveActivity() ) );
       
   186         emit applicationReady();
   161         
   187         
   162     }
   188     }
   163     else {
   189     else {
   164         setOrientation(Qt::Vertical, true);//This sould prevent media wall activation.
   190         setOrientation(Qt::Vertical, true);//This sould prevent media wall activation.
   165     }
   191     }
   180     switch ( commandCode ) {
   206     switch ( commandCode ) {
   181         case MpCommon::Exit:
   207         case MpCommon::Exit:
   182             if ( mCurrentViewPlugin ) {
   208             if ( mCurrentViewPlugin ) {
   183                 disconnectView();
   209                 disconnectView();
   184             }
   210             }
       
   211             mUserExit = true;
   185             qApp->quit();
   212             qApp->quit();
   186             break;
   213             break;
   187         case MpCommon::SendToBackground:
   214         case MpCommon::SendToBackground:
   188             lower();
   215             lower();
   189             break;
   216             break;
   324         HbMainWindow::keyPressEvent (event);
   351         HbMainWindow::keyPressEvent (event);
   325         break;          
   352         break;          
   326     }
   353     }
   327 }
   354 }
   328 
   355 
       
   356 /*!
       
   357   Slot to initialize the view that corresponds to the requested service  
       
   358  */
   329 void MpMainWindow::initializeServiceView( TUid hostUid )
   359 void MpMainWindow::initializeServiceView( TUid hostUid )
   330 {
   360 {
   331     switch (mMusicServices->currentService()) {
   361     switch (mMusicServices->currentService()) {
   332  
   362  
   333     case MusicServices::EUriFetcher:
   363     case MusicServices::EUriFetcher:
   358         }
   388         }
   359     default:
   389     default:
   360         Q_ASSERT_X(false, "MpMainWindow::initializeServiceView", "undefined service");
   390         Q_ASSERT_X(false, "MpMainWindow::initializeServiceView", "undefined service");
   361         break;
   391         break;
   362     }
   392     }
       
   393     emit applicationReady();
       
   394 }
       
   395 
       
   396 /*!
       
   397   Slot to handle activity switching once the stand alone instance is running and registered 
       
   398   in the activity manager to wait for activities.
       
   399   Only running activity supported at the moment is "MusicNowPlayingView"
       
   400  */
       
   401 void MpMainWindow::handleActivity()
       
   402 {
       
   403     TX_ENTRY
       
   404     HbApplication* app = qobject_cast<HbApplication*>(qApp);
       
   405     QString activityId = app->activateId();
       
   406     
       
   407     if( !activityId.compare( MUSIC_NOW_PLAYING_VIEW ) ) {
       
   408         if ( orientation() == Qt::Vertical ) {
       
   409             if( mVerticalViewType != PlaybackView ) {
       
   410                 activateView( PlaybackView );
       
   411             }
       
   412         }
       
   413     }
       
   414     
       
   415     mActivityManager->waitActivity();
       
   416     TX_EXIT
       
   417 }
       
   418 
       
   419 /*!
       
   420   Slot to save activity upon exiting application
       
   421  */
       
   422 void MpMainWindow::saveActivity()
       
   423 {
       
   424     TX_ENTRY
       
   425     QString activity = ( mVerticalViewType == CollectionView ) ? MUSIC_MAIN_VIEW : MUSIC_NOW_PLAYING_VIEW;
       
   426     //Get data from engine
       
   427     QByteArray serializedRestorePath;
       
   428     if ( mUserExit ) {
       
   429         //Internal exit will always return to the main view
       
   430         activity = MUSIC_MAIN_VIEW;
       
   431     }
       
   432     else {
       
   433         //Only saved data if exited via task switcher or GOOM
       
   434         MpEngineFactory::sharedEngine()->saveActivityData( serializedRestorePath );
       
   435     }
       
   436     QVariantHash activityParameters;
       
   437     activityParameters.insert( "screenshot", QPixmap::grabWidget( this, this->rect() ) );
       
   438     QVariantHash activityData;
       
   439     activityData.insert( "restorePath", serializedRestorePath );
       
   440        
       
   441     
       
   442     bool ok = mActivityManager->addActivity( activity , activityData, activityParameters );
       
   443     if ( !ok ){
       
   444         TX_LOG_ARGS( "Error: Add Failed; should never get here." );
       
   445     }
       
   446     TX_EXIT
       
   447 }
       
   448 
       
   449 /*!
       
   450   Slot to handle a failed path restoration. Switch to collection view if not already there.
       
   451  */
       
   452 void MpMainWindow::handleRestorePathFailed()
       
   453 {
       
   454     TX_ENTRY
       
   455     if ( orientation() == Qt::Vertical ) {
       
   456         if( mVerticalViewType != CollectionView ) {
       
   457             activateView( CollectionView );
       
   458         }
       
   459     }
       
   460     TX_EXIT
   363 }
   461 }
   364 
   462 
   365 /*!
   463 /*!
   366   loads a view if type \a  type, return the view plugin, if view is already loaded it will not reload the view.
   464   loads a view if type \a  type, return the view plugin, if view is already loaded it will not reload the view.
   367  */
   465  */
   412     Q_ASSERT( plugin ? *plugin : 0 );
   510     Q_ASSERT( plugin ? *plugin : 0 );
   413     return plugin ? *plugin : 0;
   511     return plugin ? *plugin : 0;
   414 }
   512 }
   415 
   513 
   416 /*!
   514 /*!
   417   Slot to handle activity switching once the stand alone instance is running and registered 
   515   Load activity called via task switcher
   418   in the activity manager to wait for activities.
   516   Restore view and playback path if applicable
   419   Only running activity supported at the moment is "MusicNowPlayingView"
   517  */
   420  */
   518 void MpMainWindow::loadActivity( QVariant data )
   421 void MpMainWindow::handleActivity()
   519 {
   422 {
   520     TX_ENTRY
   423     HbApplication* app = qobject_cast<HbApplication*>(qApp);
   521     QVariantHash activityData = data.toHash();
   424     QString activityId = app->activateId();
   522     QByteArray serializedRestorePath = activityData.value( "restorePath" ).toByteArray();
   425     
   523     MpEngineFactory::sharedEngine()->loadActivityData( serializedRestorePath );
   426     if( !activityId.compare( "MusicNowPlayingView&launchtype=standalone" ) ) {
   524     TX_EXIT
   427         if ( orientation() == Qt::Vertical ) {
   525 }
   428             if( mVerticalViewType != PlaybackView ) {
   526 
   429                 activateView( PlaybackView );
       
   430             }
       
   431         }
       
   432     }
       
   433     HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   434     activityManager->waitActivity();
       
   435 }
       
   436