mpengine/src/mpengine.cpp
changeset 55 f3930dda3342
parent 51 560ce2306a17
child 59 cd9e40a08dda
equal deleted inserted replaced
51:560ce2306a17 55:f3930dda3342
    26 #include "mpequalizerframeworkwrapper.h"
    26 #include "mpequalizerframeworkwrapper.h"
    27 #include "mptrace.h"
    27 #include "mptrace.h"
    28 #include "mpsettingsmanager.h"
    28 #include "mpsettingsmanager.h"
    29 #include "mpsongscanner.h"
    29 #include "mpsongscanner.h"
    30 #include "mpsongdata.h"
    30 #include "mpsongdata.h"
       
    31 #include "mpapplicationmonitor.h"
    31 
    32 
    32 /*!
    33 /*!
    33     \class MpEngine
    34     \class MpEngine
    34     \brief Engine for musicplayer - mpx framework utilities.
    35     \brief Engine for musicplayer - mpx framework utilities.
    35 
    36 
   205       mMpxPlaybackWrapper(0),
   206       mMpxPlaybackWrapper(0),
   206       mAudioEffectsWrapper(0),
   207       mAudioEffectsWrapper(0),
   207       mEqualizerWrapper(0),
   208       mEqualizerWrapper(0),
   208       mCurrentPresetIndex(0),
   209       mCurrentPresetIndex(0),
   209       mSongData(0),
   210       mSongData(0),
       
   211       mApplicationMonitor(0),
   210       mUsbBlockingState(USB_NotConnected),
   212       mUsbBlockingState(USB_NotConnected),
   211       mPreviousUsbState(USB_NotConnected),
   213       mPreviousUsbState(USB_NotConnected),
   212       mHandleMediaCommands(true)
   214       mHandleMediaCommands(true)
   213 {
   215 {
   214     TX_LOG
   216     TX_LOG
   225     delete mMpxCollectionWrapper;
   227     delete mMpxCollectionWrapper;
   226     delete mAudioEffectsWrapper;
   228     delete mAudioEffectsWrapper;
   227     delete mEqualizerWrapper;
   229     delete mEqualizerWrapper;
   228     delete mSongScanner;
   230     delete mSongScanner;
   229     delete mSongData;
   231     delete mSongData;
       
   232     delete mApplicationMonitor;
   230     TX_EXIT
   233     TX_EXIT
   231 }
   234 }
   232 
   235 
   233 /*!
   236 /*!
   234  Initialize engine
   237  Initialize engine
   235  */
   238  */
   236 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   239 void MpEngine::initialize( quint32 clientSecureId, EngineMode mode )
   237 {
   240 {
   238     TX_ENTRY_ARGS("hostUid=" << hostUid.iUid << ", mode=" << mode);
   241     TX_ENTRY_ARGS("clientSecureId=" << clientSecureId << ", mode=" << mode);
   239     mHostUid = hostUid;
   242 
   240 
   243     mEngineMode = mode;
   241     if ( StandAlone == mode ) {
   244     if ( StandAlone == mode ) {
   242         mSongData = new MpSongData();
   245         mSongData = new MpSongData();
   243 
   246 
   244         // Harvesting Wrapper
   247         // Harvesting Wrapper
   245         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   248         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( clientSecureId );
   246         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
   249         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
   247                  this, SLOT( handleScanStarted() ), 
   250                  this, SLOT( handleScanStarted() ), 
   248 				 Qt::QueuedConnection );
   251 				 Qt::QueuedConnection );
   249         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
   252         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
   250                  this, SLOT( handleScanEnded(int, int) ), 
   253                  this, SLOT( handleScanEnded(int, int) ), 
   257         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
   260         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
   258                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
   261                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
   259 				 Qt::QueuedConnection );
   262 				 Qt::QueuedConnection );
   260 
   263 
   261         // Collection Wrapper
   264         // Collection Wrapper
   262         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, mSongData );
   265         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( clientSecureId, mSongData );
   263         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   266         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   264                  this, SIGNAL( collectionPlaylistOpened() ), 
   267                  this, SIGNAL( collectionPlaylistOpened() ), 
   265 				 Qt::QueuedConnection );
   268 				 Qt::QueuedConnection );
   266         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs(int) ),
   269         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs(int) ),
   267                  this, SIGNAL( aboutToAddSongs(int) ) );
   270                  this, SIGNAL( aboutToAddSongs(int) ) );
   290         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ),
   293         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ),
   291                  this, SLOT( handleEqualizerReady() ), 
   294                  this, SLOT( handleEqualizerReady() ), 
   292 				 Qt::QueuedConnection );
   295 				 Qt::QueuedConnection );
   293 
   296 
   294         // Playback Wrapper
   297         // Playback Wrapper
   295         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, mSongData );
   298         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( clientSecureId, mSongData );
   296         connect( this, SIGNAL( libraryUpdated() ),
   299         connect( this, SIGNAL( libraryUpdated() ),
   297                  mMpxPlaybackWrapper, SLOT( closeCurrentPlayback() ) );
   300                  mMpxPlaybackWrapper, SLOT( closeCurrentPlayback() ) );
   298         connect( mMpxPlaybackWrapper, SIGNAL ( corruptedStop() ),
   301         connect( mMpxPlaybackWrapper, SIGNAL ( corruptedStop(bool) ),
   299                  this, SIGNAL( corruptedStop() ));
   302                  this, SLOT( handleCorruptedStop(bool) ));
   300 		connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   303 		connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   301                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   304                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   302 
   305 
   303         // AudioEffects wrapper
   306         // AudioEffects wrapper
   304         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
   307         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
   305     }
   308     }
   306     else if ( Fetch == mode ) {
   309     else if ( Fetch == mode ) {
   307         // Harvesting Wrapper
   310         // Harvesting Wrapper
   308         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   311         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( clientSecureId );
   309         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
   312         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
   310                  this, SLOT( handleScanStarted() ), 
   313                  this, SLOT( handleScanStarted() ), 
   311 				 Qt::QueuedConnection );
   314 				 Qt::QueuedConnection );
   312         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
   315         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
   313                  this, SLOT( handleScanEnded(int, int) ), 
   316                  this, SLOT( handleScanEnded(int, int) ), 
   320         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
   323         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
   321                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
   324                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
   322 				 Qt::QueuedConnection );
   325 				 Qt::QueuedConnection );
   323 
   326 
   324         // Collection Wrapper
   327         // Collection Wrapper
   325         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, 0 );
   328         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( clientSecureId, 0 );
   326         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   329         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   327                  this, SIGNAL( collectionPlaylistOpened() ), 
   330                  this, SIGNAL( collectionPlaylistOpened() ), 
   328 				 Qt::QueuedConnection );
   331 				 Qt::QueuedConnection );
   329         // Disabling these since fetch mode plays only one song at a time.
   332         // Disabling these since fetch mode plays only one song at a time.
   330         mMpxCollectionWrapper->setRepeatFeatureEnabled( false );
   333         mMpxCollectionWrapper->setRepeatFeatureEnabled( false );
   331         mMpxCollectionWrapper->setShuffleFeatureEnabled( false );
   334         mMpxCollectionWrapper->setShuffleFeatureEnabled( false );
   332 
   335 
   333         // Playback Wrapper
   336         // Playback Wrapper
   334         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, 0 );
   337         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( clientSecureId, 0 );
   335         connect( this, SIGNAL( libraryUpdated() ),
   338         connect( this, SIGNAL( libraryUpdated() ),
   336                  mMpxPlaybackWrapper, SLOT( closeCurrentPlayback() ) );
   339                  mMpxPlaybackWrapper, SLOT( closeCurrentPlayback() ) );
   337 	    connect( mMpxPlaybackWrapper, SIGNAL ( corruptedStop() ),
   340         connect( mMpxPlaybackWrapper, SIGNAL ( corruptedStop(bool) ),
   338 				 this, SIGNAL( corruptedStop() ));
   341                  this, SLOT( handleCorruptedStop(bool) ));				 
   339 	    connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   342 	    connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   340                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   343                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   341 
   344 
   342     }
   345     }
   343     else if ( MediaBrowsing == mode ) {
   346     else if ( MediaBrowsing == mode ) {
   344         // Collection Wrapper
   347         // Collection Wrapper
   345         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, 0 );
   348         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( clientSecureId, 0 );
   346         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   349         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   347                  this, SIGNAL( collectionPlaylistOpened() ), 
   350                  this, SIGNAL( collectionPlaylistOpened() ), 
   348 				 Qt::QueuedConnection );
   351 				 Qt::QueuedConnection );
   349         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   352         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   350                  this, SIGNAL( containerContentsChanged() ), 
   353                  this, SIGNAL( containerContentsChanged() ), 
   351 				 Qt::QueuedConnection );
   354 				 Qt::QueuedConnection );
   352     }
   355     }
   353     else if ( Embedded == mode ) {
   356     else if ( Embedded == mode ) {
   354         mSongData = new MpSongData();
   357         mSongData = new MpSongData();
   355         // Playback Wrapper
   358         // Playback Wrapper
   356         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, mSongData );
   359         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( clientSecureId, mSongData );
   357         connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   360         connect( mMpxPlaybackWrapper, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ),
   358                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   361                  this, SIGNAL( volumePropertyChanged( MpCommon::MpVolumeProperty, int ) ) );
   359 
   362         connect( mMpxPlaybackWrapper, SIGNAL ( corruptedStop(bool) ),
       
   363                  this, SLOT( handleCorruptedStop(bool) ));
       
   364     }
       
   365     else if ( HomeScreen == mode ) {
       
   366         // Harvesting Wrapper
       
   367         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( clientSecureId );
       
   368         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
       
   369                  this, SLOT( handleScanStarted() ),
       
   370                  Qt::QueuedConnection );
       
   371         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
       
   372                  this, SLOT( handleScanEnded(int, int) ),
       
   373                  Qt::QueuedConnection );
       
   374         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
       
   375         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ),
       
   376                  this, SLOT( handleDiskEvent(MpxDiskEvents) ),
       
   377                  Qt::QueuedConnection );
       
   378         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
       
   379         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
       
   380                  this, SLOT( handleUsbEvent(MpxUsbEvents) ),
       
   381                  Qt::QueuedConnection );
       
   382 
       
   383         // Playback Wrapper
       
   384         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( clientSecureId, mSongData );
   360     }
   385     }
   361     TX_EXIT
   386     TX_EXIT
   362 }
   387 }
   363 
   388 
   364 /*!
   389 /*!
   426  Slot to be called when song scanning starts.
   451  Slot to be called when song scanning starts.
   427  */
   452  */
   428 void MpEngine::handleScanStarted() {
   453 void MpEngine::handleScanStarted() {
   429     TX_ENTRY
   454     TX_ENTRY
   430     mHandleMediaCommands = false;
   455     mHandleMediaCommands = false;
       
   456     emit libraryUpdateStarted();
   431     TX_EXIT
   457     TX_EXIT
   432 }
   458 }
   433 
   459 
   434 /*!
   460 /*!
   435  Slot to be called when song scanning ends.
   461  Slot to be called when song scanning ends.
   461                 emit libraryUpdated();
   487                 emit libraryUpdated();
   462             }
   488             }
   463             break;
   489             break;
   464         case DiskInserted:
   490         case DiskInserted:
   465             if ( mUsbBlockingState == USB_NotConnected ) {
   491             if ( mUsbBlockingState == USB_NotConnected ) {
   466                 refreshLibrary( true );
   492                 autoRefreshLibrary(true);
   467             }
   493             }
   468             else if ( mUsbBlockingState == USB_Connected ) {
   494             else if ( mUsbBlockingState == USB_Connected ) {
   469                 emit libraryUpdated();
   495                 emit libraryUpdated();
   470             }
   496             }
   471             break;
   497             break;
   526     mHandleMediaCommands = true;
   552     mHandleMediaCommands = true;
   527 
   553 
   528     changeUsbBlockingState( USB_NotConnected );
   554     changeUsbBlockingState( USB_NotConnected );
   529     emit usbBlocked(false);
   555     emit usbBlocked(false);
   530     emit usbSynchronizationFinished();
   556     emit usbSynchronizationFinished();
   531     refreshLibrary();
   557     autoRefreshLibrary();
   532 
   558 
   533     TX_EXIT
   559     TX_EXIT
   534 }
   560 }
   535 
   561 
   536 /*!
   562 /*!
   588 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   614 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   589 {
   615 {
   590     TX_ENTRY
   616     TX_ENTRY
   591     mPreviousUsbState = mUsbBlockingState;
   617     mPreviousUsbState = mUsbBlockingState;
   592     mUsbBlockingState = state;
   618     mUsbBlockingState = state;
       
   619     TX_EXIT
       
   620 }
       
   621 
       
   622 /*!
       
   623  Internal
       
   624  */
       
   625 void MpEngine::autoRefreshLibrary( bool automaticRequest )
       
   626 {
       
   627     TX_ENTRY_ARGS( "mEngineMode=" << mEngineMode );
       
   628     if ( mEngineMode == StandAlone ) {
       
   629         refreshLibrary(automaticRequest);
       
   630     }
       
   631     else if ( mEngineMode == Fetch ) {
       
   632         if ( !mApplicationMonitor ) {
       
   633             mApplicationMonitor = new MpApplicationMonitor();
       
   634         }
       
   635         if ( !mApplicationMonitor->isApplicationRunning() ) {
       
   636             // In Fetcher mode, only perform library update when main Music
       
   637             // Player application is not running. Otherwise, let the main
       
   638             // application take care.
       
   639             refreshLibrary(automaticRequest);
       
   640         }
       
   641     }
   593     TX_EXIT
   642     TX_EXIT
   594 }
   643 }
   595 
   644 
   596 /*!
   645 /*!
   597 -------------------------------------------------------------------------------
   646 -------------------------------------------------------------------------------
  1024  */
  1073  */
  1025 void MpEngine::unmute()
  1074 void MpEngine::unmute()
  1026 {
  1075 {
  1027     if ( mHandleMediaCommands ) {
  1076     if ( mHandleMediaCommands ) {
  1028         mMpxPlaybackWrapper->unmute();
  1077         mMpxPlaybackWrapper->unmute();
       
  1078     }
       
  1079 }
       
  1080 
       
  1081 /*!
       
  1082  Slot to be called when playback encounters a corrupted song. \a lastSong
       
  1083     indicates whether this is the last song of the playlist.
       
  1084  */
       
  1085 void MpEngine::handleCorruptedStop( bool lastSong )
       
  1086 {
       
  1087     if ( lastSong ) {
       
  1088         emit corruptedStop();
       
  1089     }
       
  1090     else {
       
  1091         if ( mEngineMode == StandAlone ) {
       
  1092             skipForward();
       
  1093         }
  1029     }
  1094     }
  1030 }
  1095 }
  1031 
  1096 
  1032 /*!
  1097 /*!
  1033  Returns pointer to MpSongData, which is the song data for Details View.
  1098  Returns pointer to MpSongData, which is the song data for Details View.