mpengine/src/mpengine.cpp
changeset 29 8192e5b5c935
parent 25 3ec52facab4d
child 32 c163ef0b758d
equal deleted inserted replaced
25:3ec52facab4d 29:8192e5b5c935
    20 #include <hbmessagebox.h>
    20 #include <hbmessagebox.h>
    21 #include <hbprogressdialog.h>
    21 #include <hbprogressdialog.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbinstance.h>
    23 #include <hbinstance.h>
    24 #include <xqsharablefile.h>
    24 #include <xqsharablefile.h>
       
    25 #include <EqualizerConstants.h>
    25 
    26 
    26 #include "mpengine.h"
    27 #include "mpengine.h"
    27 #include "mpmpxharvesterframeworkwrapper.h"
    28 #include "mpmpxharvesterframeworkwrapper.h"
    28 #include "mpmpxcollectionframeworkwrapper.h"
    29 #include "mpmpxcollectionframeworkwrapper.h"
    29 #include "mpmpxplaybackframeworkwrapper.h"
    30 #include "mpmpxplaybackframeworkwrapper.h"
    30 #include "mpsongscanner.h"
    31 #include "mpmpxdetailsframeworkwrapper.h"
       
    32 #include "mpaudioeffectsframeworkwrapper.h"
       
    33 #include "mpequalizerframeworkwrapper.h"
    31 #include "mpmediakeyhandler.h"
    34 #include "mpmediakeyhandler.h"
    32 #include "mptrace.h"
    35 #include "mptrace.h"
       
    36 #include "mpsettingsmanager.h"
       
    37 #include "mpprogressdialoghandler.h"
    33 
    38 
    34 /*!
    39 /*!
    35     \class MpEngine
    40     \class MpEngine
    36     \brief Engine for musicplayer - mpx framework utilities.
    41     \brief Engine for musicplayer - mpx framework utilities.
    37 
    42 
   175     This signal is emitted when an isolated collection is opened on \a context
   180     This signal is emitted when an isolated collection is opened on \a context
   176 
   181 
   177  */
   182  */
   178 
   183 
   179 /*!
   184 /*!
       
   185     \fn void containerContentsChanged()
       
   186 
       
   187     This signal is emitted when items are removed or inserted on the current 
       
   188     container.
       
   189 
       
   190  */
       
   191 
       
   192 /*!
   180  Constructs music player engine.
   193  Constructs music player engine.
   181  */
   194  */
   182 MpEngine::MpEngine()
   195 MpEngine::MpEngine()
   183     : mMpxHarvesterWrapper(0),
   196     : mMpxHarvesterWrapper(0),
   184       mSongScanner(0),
       
   185       mMediaKeyHandler(0),
   197       mMediaKeyHandler(0),
   186       mUsbOutstandingNote(0),
   198       mUsbOutstandingNote(0),
   187       mMpxCollectionWrapper(0),
   199       mMpxCollectionWrapper(0),
   188       mMpxPlaybackWrapper(0),
   200       mMpxPlaybackWrapper(0),
       
   201       mMpxDetailsWrapper(0),
       
   202       mAudioEffectsWrapper(0),
       
   203       mEqualizerWrapper(0),
       
   204       mCurrentPresetIndex(KEqualizerPresetNone),
   189       mMpTranslator(0),
   205       mMpTranslator(0),
   190       mUsbBlockingState(USB_NotConnected),
   206       mUsbBlockingState(USB_NotConnected),
   191       mPreviousUsbState(USB_NotConnected),
   207       mPreviousUsbState(USB_NotConnected),
   192       mViewMode(MpCommon::DefaultView)
   208       mProgressDialogHandler(0)
   193 {
   209 {
   194     TX_LOG
   210     TX_LOG
   195 }
   211 }
   196 
   212 
   197 /*!
   213 /*!
   198  Destructs music player engine.
   214  Destructs music player engine.
   199  */
   215  */
   200 MpEngine::~MpEngine()
   216 MpEngine::~MpEngine()
   201 {
   217 {
   202     TX_ENTRY
   218     TX_ENTRY
   203     TX_EXIT
   219     delete mMpTranslator;
   204 }
   220     delete mMediaKeyHandler;
   205 
   221     delete mUsbOutstandingNote;
   206 /*!
   222     delete mMpxPlaybackWrapper;
   207  Returns the singleton instance of music player engine.
   223     delete mMpxDetailsWrapper;
   208  */
   224     delete mMpxHarvesterWrapper;
   209 MpEngine * MpEngine::instance()
   225     delete mMpxCollectionWrapper;
   210 {
   226     delete mAudioEffectsWrapper;
   211     static MpEngine instance;
   227     delete mEqualizerWrapper;
   212     return &instance;
   228 	delete mProgressDialogHandler;
       
   229     TX_EXIT
   213 }
   230 }
   214 
   231 
   215 /*!
   232 /*!
   216  Initialize engine
   233  Initialize engine
   217  */
   234  */
   218 void MpEngine::initialize( MpCommon::MpViewMode viewMode, TUid hostUid )
   235 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   219 {
   236 {
   220     TX_ENTRY
   237     TX_ENTRY
   221     mViewMode = viewMode;
       
   222     mHostUid = hostUid;
   238     mHostUid = hostUid;
   223     
   239     
   224     //Load musicplayer translator
   240     //Load musicplayer translator
   225     QString lang = QLocale::system().name();
   241     QString lang = QLocale::system().name();
   226     QString path = QString( "z:/resource/qt/translations/" );
   242     QString path = QString( "z:/resource/qt/translations/" );
   230     translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
   246     translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
   231     TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
   247     TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
   232     if ( translatorLoaded ) {
   248     if ( translatorLoaded ) {
   233         qApp->installTranslator( mMpTranslator );
   249         qApp->installTranslator( mMpTranslator );
   234     }
   250     }
   235     
   251 
   236     if( mViewMode == MpCommon::DefaultView || mViewMode == MpCommon::FetchView ){
   252     if( mode == StandAlone || mode == Fetch ){
   237         // Harvesting Wrapper
   253         // Harvesting Wrapper
   238         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mViewMode, mHostUid );
   254         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   239         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   255         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   240                  this, SLOT( handleScanStarted() ), Qt::QueuedConnection );
   256                  this, SLOT( handleScanStarted() ), Qt::QueuedConnection );
   241         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ), 
   257         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ), 
   242                  this, SLOT( handleScanEnded(int, int) ), Qt::QueuedConnection );
   258                  this, SLOT( handleScanEnded(int, int) ), Qt::QueuedConnection );
   243         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   259         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   244         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   260         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   245                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   261                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   246         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   262         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   247         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   263         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   248                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );
   264                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );       
   249         mSongScanner = new MpSongScanner( mMpxHarvesterWrapper );
       
   250         mMediaKeyHandler = new MpMediaKeyHandler();
   265         mMediaKeyHandler = new MpMediaKeyHandler();
       
   266     }
       
   267         
       
   268     if ( mode == StandAlone || mode == Fetch || mode == MediaBrowsing) {
   251         
   269         
   252         // Collection Wrapper
   270         // Collection Wrapper
   253         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mViewMode, mHostUid );
   271         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid );
       
   272         
       
   273         //disabling these since fetch mode plays only one song at a time.
       
   274         mMpxCollectionWrapper->setRepeatFeatureEnabled( mode != Fetch );
       
   275         mMpxCollectionWrapper->setShuffleFeatureEnabled( mode != Fetch );
       
   276         
   254         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   277         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   255                 this, SIGNAL( collectionPlaylistOpened() ),
   278                 this, SIGNAL( collectionPlaylistOpened() ),
   256                 Qt::QueuedConnection );
   279                 Qt::QueuedConnection );
   257         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   280         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   258                 this, SIGNAL( playlistSaved( bool ) ),
   281                 this, SIGNAL( playlistSaved( bool ) ),
   264                 this, SIGNAL( playlistsRenamed( bool ) ),
   287                 this, SIGNAL( playlistsRenamed( bool ) ),
   265                 Qt::QueuedConnection );
   288                 Qt::QueuedConnection );
   266         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   289         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   267                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   290                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   268                 Qt::QueuedConnection );
   291                 Qt::QueuedConnection );
   269     }
   292         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   270 
   293                 this, SIGNAL( containerContentsChanged() ),
   271     // Playback Wrapper 
   294                 Qt::QueuedConnection );
   272     mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mViewMode, mHostUid );
   295         connect( mProgressDialogHandler, SIGNAL( deleteStarted() ), 
   273 
   296                this, SLOT( handleDeleteStarted() ),
   274     TX_EXIT
   297                Qt::QueuedConnection );
   275 }
   298        connect( mProgressDialogHandler, SIGNAL( songsDeleted( bool ) ),
   276 
   299                this, SLOT( handleDeleteEnded( bool ) ),
   277 /*!
   300                Qt::QueuedConnection );
   278   Deinitialize wrappers
   301     }
   279  */
   302     
   280 void MpEngine::close( )
   303     if( mode == StandAlone ){
   281 {
   304         // Equalizer wrapper , this needs to be created before playback wrapper.
   282     delete mMpTranslator;
   305         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   283     mMpTranslator = 0;
   306         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ), 
   284     delete mSongScanner;
   307                  this, SLOT( handleEqualizerReady() ), Qt::QueuedConnection );
   285     mSongScanner = 0;
   308     }
   286     delete mMediaKeyHandler;
   309     
   287     mMediaKeyHandler = 0;   
   310     if ( mode == StandAlone || mode == Fetch || mode == Embedded ) {
   288     delete mUsbOutstandingNote;
   311         // Playback Wrapper 
   289     mUsbOutstandingNote = 0;
   312         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid );
   290     delete mMpxPlaybackWrapper;
   313         
   291     mMpxPlaybackWrapper = 0;
   314         // Details Wrapper
   292     delete mMpxHarvesterWrapper;
   315         mMpxDetailsWrapper = new MpMpxDetailsFrameworkWrapper( mHostUid );
   293     mMpxHarvesterWrapper = 0;
   316     }
   294     delete mMpxCollectionWrapper;
   317 
   295     mMpxCollectionWrapper = 0;
   318     if( mode == StandAlone ){
       
   319         // AudioEffects wrapper
       
   320         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
       
   321     }
       
   322     if (mMpxHarvesterWrapper && mMpxCollectionWrapper){
       
   323         mProgressDialogHandler = new MpProgressDialogHandler(mMpxCollectionWrapper, mMpxHarvesterWrapper);
       
   324     }
       
   325 	TX_EXIT
   296 }
   326 }
   297 
   327 
   298 /*!
   328 /*!
   299 -------------------------------------------------------------------------------
   329 -------------------------------------------------------------------------------
   300     Harvesting related
   330     Harvesting related
   342 void MpEngine::refreshLibrary()
   372 void MpEngine::refreshLibrary()
   343 {
   373 {
   344     TX_ENTRY
   374     TX_ENTRY
   345     if ( !verifyUsbBlocking( true ) ) {
   375     if ( !verifyUsbBlocking( true ) ) {
   346         emit libraryAboutToUpdate();
   376         emit libraryAboutToUpdate();
   347         mSongScanner->scan();
   377         mProgressDialogHandler->scan();
   348     }
   378     }
   349     TX_EXIT
   379     TX_EXIT
   350 }
   380 }
   351 
   381 
   352 /*!
   382 /*!
   685  Deletes \a selection from the collection.
   715  Deletes \a selection from the collection.
   686  */
   716  */
   687 void MpEngine::deleteSongs( QList<int> &selection )
   717 void MpEngine::deleteSongs( QList<int> &selection )
   688 {
   718 {
   689     if ( !verifyUsbBlocking( true ) ) {
   719     if ( !verifyUsbBlocking( true ) ) {
   690         mMpxCollectionWrapper->deleteSongs( selection );
   720         mProgressDialogHandler->deleteSongs( selection );
   691     }
   721     }
   692 }
   722 }
   693 
   723 
   694 
   724 
   695 
   725 
   717  Releases the resources used for the isolated collection.
   747  Releases the resources used for the isolated collection.
   718  */
   748  */
   719 void MpEngine::releaseIsolatedCollection()
   749 void MpEngine::releaseIsolatedCollection()
   720 {
   750 {
   721     mMpxCollectionWrapper->releaseIsolatedCollection();
   751     mMpxCollectionWrapper->releaseIsolatedCollection();
       
   752 }
       
   753 
       
   754 /*!
       
   755  Finds all songs beloging to the album specified by the \a index.
       
   756  */
       
   757 void MpEngine::findAlbumSongs( int index )
       
   758 {
       
   759     mMpxCollectionWrapper->findAlbumSongs(index);
       
   760 }
       
   761 
       
   762 /*!
       
   763  Plays album with \a albumIndex starting with the songs with \a songIndex.
       
   764  */
       
   765 void MpEngine::playAlbumSongs( int albumIndex, int songIndex, MpMpxCollectionData* collectionData  )
       
   766 {
       
   767     mMpxCollectionWrapper->playAlbumSongs(albumIndex, songIndex, collectionData);
   722 }
   768 }
   723 
   769 
   724 /*!
   770 /*!
   725  Returns pointer to MpMpxCollectionData, which is the collection data.
   771  Returns pointer to MpMpxCollectionData, which is the collection data.
   726  */
   772  */
   788 {
   834 {
   789     mMpxPlaybackWrapper->stop();
   835     mMpxPlaybackWrapper->stop();
   790 }
   836 }
   791 
   837 
   792 /*!
   838 /*!
   793  Slot to handle a skeep forward.
   839  Slot to handle a skip forward.
   794  */
   840  */
   795 void MpEngine::skipForward()
   841 void MpEngine::skipForward()
   796 {
   842 {
   797     mMpxPlaybackWrapper->skipForward();
   843     mMpxPlaybackWrapper->skipForward();
   798 }
   844 }
   799 
   845 
   800 /*!
   846 /*!
   801  Slot to handle a skeep backwards.
   847  Slot to handle  seek forward.
       
   848  */
       
   849 void MpEngine::startSeekForward()
       
   850 {
       
   851     mMpxPlaybackWrapper->startSeekForward();
       
   852 }
       
   853 
       
   854 /*!
       
   855  Slot to handle stop seeking.
       
   856  */
       
   857 void MpEngine::stopSeeking()
       
   858 {
       
   859     mMpxPlaybackWrapper->stopSeeking();
       
   860 }
       
   861 
       
   862 /*!
       
   863  Slot to handle a skip backwards.
   802  */
   864  */
   803 void MpEngine::skipBackward()
   865 void MpEngine::skipBackward()
   804 {
   866 {
   805     mMpxPlaybackWrapper->skipBackward();
   867     mMpxPlaybackWrapper->skipBackward();
   806 }
   868 }
   807 
   869 
   808 /*!
   870 /*!
       
   871  Slot to handle seek backwards.
       
   872  */
       
   873 void MpEngine::startSeekBackward()
       
   874 {
       
   875     mMpxPlaybackWrapper->startSeekBackward();
       
   876 }
       
   877 /*!
   809  Slot to handle a request to change \a position.
   878  Slot to handle a request to change \a position.
   810  */
   879  */
   811 void MpEngine::setPosition( int position )
   880 void MpEngine::setPosition( int position )
   812 {
   881 {
   813     mMpxPlaybackWrapper->setPosition( position );
   882     mMpxPlaybackWrapper->setPosition( position );
   827 void MpEngine::setRepeat( bool mode )
   896 void MpEngine::setRepeat( bool mode )
   828 {
   897 {
   829     mMpxPlaybackWrapper->setRepeat( mode );
   898     mMpxPlaybackWrapper->setRepeat( mode );
   830 }
   899 }
   831 
   900 
       
   901 /*!
       
   902  Returns pointer to MpSongData, which is the song data for detail's view.
       
   903  */
       
   904 MpSongData *MpEngine::songData()
       
   905 {
       
   906     return mMpxDetailsWrapper->songData();
       
   907 }
       
   908 
       
   909 /*!
       
   910  Retrieve song informatioin
       
   911  */
       
   912 void MpEngine::retrieveSong()
       
   913 {
       
   914     TX_ENTRY
       
   915     mMpxDetailsWrapper->retrieveSong();
       
   916     TX_EXIT
       
   917 }
       
   918 
       
   919 /*!
       
   920  Retrieve balance informatioin from audio effects
       
   921  */
       
   922 int MpEngine::balance()
       
   923 {
       
   924     return mAudioEffectsWrapper->balance();
       
   925 }
       
   926 
       
   927 /*!
       
   928  Retrieve loudness informatioin from audio effects
       
   929  */
       
   930 bool MpEngine::loudness()
       
   931 {
       
   932     return mAudioEffectsWrapper->loudness();
       
   933 }
       
   934 
       
   935 /*!
       
   936  Slot to handle a request to change \a balance in audio effects.
       
   937  */
       
   938 void MpEngine::setBalance( int balance )
       
   939 {
       
   940     TX_ENTRY
       
   941     
       
   942     if ( mAudioEffectsWrapper->balance() != balance ) {
       
   943         mAudioEffectsWrapper->setBalance( balance );
       
   944         mMpxPlaybackWrapper->setBalance( balance );
       
   945     }
       
   946     
       
   947     TX_EXIT
       
   948 }
       
   949 
       
   950 /*!
       
   951  Slot to handle a request to change loudness \a mode in audio effects.
       
   952  */
       
   953 void MpEngine::setLoudness( bool mode )
       
   954 {
       
   955     TX_ENTRY
       
   956     
       
   957     if( mAudioEffectsWrapper->loudness() != mode ) { //do not set same value twice
       
   958         mAudioEffectsWrapper->setLoudness( mode );
       
   959         mMpxPlaybackWrapper->applyAudioEffects();
       
   960     }
       
   961     
       
   962     TX_EXIT
       
   963 }
       
   964 
       
   965 /*!
       
   966  Apply the preset by giving \a presetIndex. The index is subtracted by 1 because
       
   967  index 0 represent "Off" at UI level.
       
   968  */
       
   969 void MpEngine::applyPreset( int presetIndex )
       
   970 {
       
   971     TX_ENTRY_ARGS( "presetIndex=" << presetIndex );
       
   972     
       
   973     TInt presetKey = mEqualizerWrapper->getPresetNameKey( presetIndex - 1 );
       
   974     
       
   975     if ( presetKey != KEqualizerPresetNone ) {
       
   976         TX_LOG_ARGS( "Preset key in engine =" << presetKey );
       
   977         // Store in CenRep file
       
   978         MpSettingsManager::setPreset( presetKey );
       
   979         // Notify playback framework of the change.
       
   980         mMpxPlaybackWrapper->applyEqualizer();
       
   981         mCurrentPresetIndex = presetIndex;
       
   982     }
       
   983     else {
       
   984         TX_LOG_ARGS("getPresetNameKey Error  = " << KEqualizerPresetNone);
       
   985     }
       
   986     
       
   987     TX_EXIT
       
   988 }
       
   989 
       
   990 /*!
       
   991  Disabling equalizer by setting the preset to -1 and apply it to 
       
   992  disable current preset.
       
   993  */
       
   994 void MpEngine::disableEqualizer()
       
   995 {
       
   996     TX_ENTRY
       
   997 
       
   998     mCurrentPresetIndex = KEqualizerPresetNone;
       
   999     // Store in CenRep file
       
  1000     MpSettingsManager::setPreset( mCurrentPresetIndex );
       
  1001     // Notify playback framework of the change.
       
  1002     mMpxPlaybackWrapper->applyEqualizer();
       
  1003 
       
  1004     TX_EXIT
       
  1005 }
       
  1006 
       
  1007 /*!
       
  1008  Return current preset index (UI)
       
  1009  */
       
  1010 int MpEngine::activePreset()
       
  1011 {
       
  1012     TX_LOG_ARGS("mCurrentPresetIndex = " << mCurrentPresetIndex );
       
  1013 
       
  1014     return mCurrentPresetIndex;
       
  1015 }
       
  1016 
       
  1017 /*!
       
  1018  Retrieve list of preset names from equalizer wrapper
       
  1019  */
       
  1020 QStringList MpEngine::presetNames()
       
  1021 {
       
  1022     return mEqualizerWrapper->presetNames(); 
       
  1023 }
       
  1024 
       
  1025 /*!
       
  1026  Slot to handle equalizer ready signal from equalizer wrapper.
       
  1027  */
       
  1028 void MpEngine::handleEqualizerReady()
       
  1029 {
       
  1030     TX_ENTRY
       
  1031     
       
  1032     // Get preset id from cenrep
       
  1033     TInt presetKey( MpSettingsManager::preset() );
       
  1034     
       
  1035     mCurrentPresetIndex = mEqualizerWrapper->getPresetIndex( presetKey );
       
  1036     emit equalizerReady();
       
  1037     
       
  1038     TX_EXIT
       
  1039 }
       
  1040 
       
  1041 /*!
       
  1042  Slot to be called when song deleting starts.
       
  1043  */
       
  1044 void MpEngine::handleDeleteStarted() {
       
  1045     TX_ENTRY
       
  1046     mMediaKeyHandler->setEnabled(false);
       
  1047     TX_EXIT
       
  1048 }
       
  1049 
       
  1050 /*!
       
  1051  Slot to be called when song deleting ends.
       
  1052  */
       
  1053 void MpEngine::handleDeleteEnded() {
       
  1054     TX_ENTRY
       
  1055     mMediaKeyHandler->setEnabled(true);
       
  1056     TX_EXIT
       
  1057 }
       
  1058