mpengine/src/mpengine.cpp
changeset 43 0f32e550d9d8
parent 38 b93f525c9244
child 45 612c4815aebe
equal deleted inserted replaced
38:b93f525c9244 43:0f32e550d9d8
    20 
    20 
    21 #include "mpengine.h"
    21 #include "mpengine.h"
    22 #include "mpmpxharvesterframeworkwrapper.h"
    22 #include "mpmpxharvesterframeworkwrapper.h"
    23 #include "mpmpxcollectionframeworkwrapper.h"
    23 #include "mpmpxcollectionframeworkwrapper.h"
    24 #include "mpmpxplaybackframeworkwrapper.h"
    24 #include "mpmpxplaybackframeworkwrapper.h"
    25 #include "mpmpxdetailsframeworkwrapper.h"
       
    26 #include "mpaudioeffectsframeworkwrapper.h"
    25 #include "mpaudioeffectsframeworkwrapper.h"
    27 #include "mpequalizerframeworkwrapper.h"
    26 #include "mpequalizerframeworkwrapper.h"
    28 #include "mpmediakeyhandler.h"
    27 #include "mpmediakeyhandler.h"
    29 #include "mptrace.h"
    28 #include "mptrace.h"
    30 #include "mpsettingsmanager.h"
    29 #include "mpsettingsmanager.h"
    31 #include "mpsongscanner.h"
    30 #include "mpsongscanner.h"
       
    31 #include "mpsongdata.h"
    32 
    32 
    33 /*!
    33 /*!
    34     \class MpEngine
    34     \class MpEngine
    35     \brief Engine for musicplayer - mpx framework utilities.
    35     \brief Engine for musicplayer - mpx framework utilities.
    36 
    36 
    91 
    91 
    92 /*!
    92 /*!
    93     \fn void usbSynchronizationFinished()
    93     \fn void usbSynchronizationFinished()
    94 
    94 
    95     This signal is emitted when usb in synchronizing state is disconnected.
    95     This signal is emitted when usb in synchronizing state is disconnected.
    96 
       
    97  */
       
    98 
       
    99 /*!
       
   100     \fn void libraryRefreshNeeded()
       
   101 
       
   102     This signal is emitted when usb in MassStorage mode is disconnected.
       
   103 
    96 
   104  */
    97  */
   105 
    98 
   106 
    99 
   107 /*!
   100 /*!
   190     : mMpxHarvesterWrapper(0),
   183     : mMpxHarvesterWrapper(0),
   191       mSongScanner(0),
   184       mSongScanner(0),
   192       mMediaKeyHandler(0),
   185       mMediaKeyHandler(0),
   193       mMpxCollectionWrapper(0),
   186       mMpxCollectionWrapper(0),
   194       mMpxPlaybackWrapper(0),
   187       mMpxPlaybackWrapper(0),
   195       mMpxDetailsWrapper(0),
       
   196       mAudioEffectsWrapper(0),
   188       mAudioEffectsWrapper(0),
   197       mEqualizerWrapper(0),
   189       mEqualizerWrapper(0),
   198       mCurrentPresetIndex(KEqualizerPresetNone),
   190       mCurrentPresetIndex(KEqualizerPresetNone),
       
   191       mSongData(0),
   199       mUsbBlockingState(USB_NotConnected),
   192       mUsbBlockingState(USB_NotConnected),
   200       mPreviousUsbState(USB_NotConnected)
   193       mPreviousUsbState(USB_NotConnected)
   201 {
   194 {
   202     TX_LOG
   195     TX_LOG
   203 }
   196 }
   208 MpEngine::~MpEngine()
   201 MpEngine::~MpEngine()
   209 {
   202 {
   210     TX_ENTRY
   203     TX_ENTRY
   211     delete mMediaKeyHandler;
   204     delete mMediaKeyHandler;
   212     delete mMpxPlaybackWrapper;
   205     delete mMpxPlaybackWrapper;
   213     delete mMpxDetailsWrapper;
       
   214     delete mMpxHarvesterWrapper;
   206     delete mMpxHarvesterWrapper;
   215     delete mMpxCollectionWrapper;
   207     delete mMpxCollectionWrapper;
   216     delete mAudioEffectsWrapper;
   208     delete mAudioEffectsWrapper;
   217     delete mEqualizerWrapper;
   209     delete mEqualizerWrapper;
   218     delete mSongScanner;
   210     delete mSongScanner;
       
   211     delete mSongData;
   219     TX_EXIT
   212     TX_EXIT
   220 }
   213 }
   221 
   214 
   222 /*!
   215 /*!
   223  Initialize engine
   216  Initialize engine
   224  */
   217  */
   225 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   218 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   226 {
   219 {
   227     TX_ENTRY
   220     TX_ENTRY_ARGS("hostUid=" << hostUid.iUid << ", mode=" << mode);
   228     mHostUid = hostUid;
   221     mHostUid = hostUid;
   229 
   222     mMediaKeyHandler = new MpMediaKeyHandler();
   230     if( mode == StandAlone || mode == Fetch ){
   223 
       
   224     if ( StandAlone == mode ) {
       
   225         mSongData = new MpSongData();
       
   226 
   231         // Harvesting Wrapper
   227         // Harvesting Wrapper
   232         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   228         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   233         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   229         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
   234                  this, SLOT( handleScanStarted() ), Qt::QueuedConnection );
   230                  this, SLOT( handleScanStarted() ), 
   235         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ), 
   231 				 Qt::QueuedConnection );
   236                  this, SLOT( handleScanEnded(int, int) ), Qt::QueuedConnection );
   232         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
       
   233                  this, SLOT( handleScanEnded(int, int) ), 
       
   234 				 Qt::QueuedConnection );
   237         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   235         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   238         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   236         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ),
   239                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   237                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), 
       
   238 				 Qt::QueuedConnection );
   240         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   239         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   241         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   240         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
   242                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );
   241                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
   243         mMediaKeyHandler = new MpMediaKeyHandler();
   242 				 Qt::QueuedConnection );
   244     }
   243 
   245 
       
   246     if ( mode == StandAlone || mode == Fetch || mode == MediaBrowsing) {
       
   247         
       
   248         // Collection Wrapper
   244         // Collection Wrapper
   249         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid );
   245         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, mSongData );
   250         
       
   251         //disabling these since fetch mode plays only one song at a time.
       
   252         mMpxCollectionWrapper->setRepeatFeatureEnabled( mode != Fetch );
       
   253         mMpxCollectionWrapper->setShuffleFeatureEnabled( mode != Fetch );
       
   254         
       
   255         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   246         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   256                 this, SIGNAL( collectionPlaylistOpened() ),
   247                  this, SIGNAL( collectionPlaylistOpened() ), 
   257                 Qt::QueuedConnection );
   248 				 Qt::QueuedConnection );
   258         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs( int ) ),
   249         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs(int) ),
   259                 this, SIGNAL( aboutToAddSongs( int ) ) );
   250                  this, SIGNAL( aboutToAddSongs(int) ) );
   260         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   251         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved(bool) ),
   261                 this, SIGNAL( playlistSaved( bool ) ),
   252                  this, SIGNAL( playlistSaved(bool) ), 
   262                 Qt::QueuedConnection );
   253 				 Qt::QueuedConnection );
   263         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed( bool ) ),
   254         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed(bool) ),
   264                 this, SIGNAL( playlistsRenamed( bool ) ),
   255                  this, SIGNAL( playlistsRenamed(bool) ), 
   265                 Qt::QueuedConnection );
   256 				 Qt::QueuedConnection );
   266         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   257         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened(MpMpxCollectionData*) ),
   267                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   258                  this, SIGNAL( isolatedCollectionOpened(MpMpxCollectionData*) ), 
   268                 Qt::QueuedConnection );
   259 				 Qt::QueuedConnection );
   269         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   260         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   270                 this, SIGNAL( containerContentsChanged() ),
   261                  this, SIGNAL( containerContentsChanged() ), 
   271                 Qt::QueuedConnection );
   262 				 Qt::QueuedConnection );
   272         connect( mMpxCollectionWrapper, SIGNAL( deleteStarted( TCollectionContext, int ) ),
   263         connect( mMpxCollectionWrapper, SIGNAL( deleteStarted(TCollectionContext, int) ),
   273                 this, SLOT( handleDeleteStarted( TCollectionContext, int ) ) );
   264                  this, SLOT( handleDeleteStarted(TCollectionContext, int) ) );
   274         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted( bool ) ),
   265         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted(bool) ),
   275                 this, SLOT( handleDeleteEnded( bool ) ),
   266                  this, SLOT( handleDeleteEnded(bool) ), 
   276                 Qt::QueuedConnection );
   267 				 Qt::QueuedConnection );
   277         connect( mMpxCollectionWrapper, SIGNAL( restorePathFailed() ),
   268         connect( mMpxCollectionWrapper, SIGNAL( restorePathFailed() ),
   278                 this, SIGNAL( restorePathFailed() ),
   269                  this, SIGNAL( restorePathFailed() ),
   279                 Qt::QueuedConnection );
   270                  Qt::QueuedConnection );
   280     }
   271         // Equalizer wrapper; this needs to be created before playback wrapper.
   281 
       
   282     if( mode == StandAlone ){
       
   283         // Equalizer wrapper , this needs to be created before playback wrapper.
       
   284         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   272         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   285         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ), 
   273         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ),
   286                  this, SLOT( handleEqualizerReady() ), Qt::QueuedConnection );
   274                  this, SLOT( handleEqualizerReady() ), 
   287     }
   275 				 Qt::QueuedConnection );
   288     
   276 
   289     if ( mode == StandAlone || mode == Fetch || mode == Embedded ) {
   277         // Playback Wrapper
   290         // Playback Wrapper 
   278         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, mSongData );
   291         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid );
   279 
   292         
       
   293         // Details Wrapper
       
   294         mMpxDetailsWrapper = new MpMpxDetailsFrameworkWrapper( mHostUid );
       
   295     }
       
   296 
       
   297     if( mode == StandAlone ){
       
   298         // AudioEffects wrapper
   280         // AudioEffects wrapper
   299         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
   281         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
       
   282     }
       
   283     else if ( Fetch == mode ) {
       
   284         // Harvesting Wrapper
       
   285         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
       
   286         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ),
       
   287                  this, SLOT( handleScanStarted() ), 
       
   288 				 Qt::QueuedConnection );
       
   289         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ),
       
   290                  this, SLOT( handleScanEnded(int, int) ), 
       
   291 				 Qt::QueuedConnection );
       
   292         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
       
   293         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ),
       
   294                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), 
       
   295 				 Qt::QueuedConnection );
       
   296         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
       
   297         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ),
       
   298                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), 
       
   299 				 Qt::QueuedConnection );
       
   300 
       
   301         // Collection Wrapper
       
   302         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, 0 );
       
   303         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
       
   304                  this, SIGNAL( collectionPlaylistOpened() ), 
       
   305 				 Qt::QueuedConnection );
       
   306         // Disabling these since fetch mode plays only one song at a time.
       
   307         mMpxCollectionWrapper->setRepeatFeatureEnabled( false );
       
   308         mMpxCollectionWrapper->setShuffleFeatureEnabled( false );
       
   309 
       
   310         // Playback Wrapper
       
   311         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, 0 );
       
   312     }
       
   313     else if ( MediaBrowsing == mode ) {
       
   314         // Collection Wrapper
       
   315         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid, 0 );
       
   316         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
       
   317                  this, SIGNAL( collectionPlaylistOpened() ), 
       
   318 				 Qt::QueuedConnection );
       
   319         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
       
   320                  this, SIGNAL( containerContentsChanged() ), 
       
   321 				 Qt::QueuedConnection );
       
   322     }
       
   323     else if ( Embedded == mode ) {
       
   324         mSongData = new MpSongData();
       
   325         // Playback Wrapper
       
   326         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid, mSongData );
   300     }
   327     }
   301     TX_EXIT
   328     TX_EXIT
   302 }
   329 }
   303 
   330 
   304 /*!
   331 /*!
   466     mMediaKeyHandler->setEnabled(true);
   493     mMediaKeyHandler->setEnabled(true);
   467 
   494 
   468     changeUsbBlockingState( USB_NotConnected );
   495     changeUsbBlockingState( USB_NotConnected );
   469     emit usbBlocked(false);
   496     emit usbBlocked(false);
   470     emit usbSynchronizationFinished();
   497     emit usbSynchronizationFinished();
   471     emit libraryRefreshNeeded();
   498     refreshLibrary();
   472 
   499 
   473     TX_EXIT
   500     TX_EXIT
   474 }
   501 }
   475 
   502 
   476 /*!
   503 /*!
   855 {
   882 {
   856     mMpxPlaybackWrapper->setRepeat( mode );
   883     mMpxPlaybackWrapper->setRepeat( mode );
   857 }
   884 }
   858 
   885 
   859 /*!
   886 /*!
   860  Returns pointer to MpSongData, which is the song data for detail's view.
   887  Returns pointer to MpSongData, which is the song data for Details View.
   861  */
   888  */
   862 MpSongData *MpEngine::songData()
   889 MpSongData *MpEngine::songData()
   863 {
   890 {
   864     return mMpxDetailsWrapper->songData();
   891     return mSongData;
   865 }
   892 }
   866 
   893 
   867 /*!
   894 /*!
   868  Retrieve song informatioin
   895  Retrieves song details for the specified \a index.
   869  */
   896  */
   870 void MpEngine::retrieveSong()
   897 void MpEngine::retrieveSongDetails( int index )
   871 {
   898 {
   872     TX_ENTRY
   899     TX_ENTRY
   873     mMpxDetailsWrapper->retrieveSong();
   900     if ( index == -1 ) {
       
   901         // Retrieve song details of currently playing song
       
   902         mMpxPlaybackWrapper->retrieveSongDetails();
       
   903     }
       
   904     else {
       
   905         mMpxCollectionWrapper->retrieveSongDetails(index);
       
   906     }
   874     TX_EXIT
   907     TX_EXIT
   875 }
   908 }
   876 
   909 
   877 /*!
   910 /*!
   878  Retrieve balance informatioin from audio effects
   911  Retrieve balance informatioin from audio effects