mpengine/src/mpengine.cpp
branchGCC_SURGE
changeset 44 eff9df3d9c98
parent 42 79c49924ae23
child 43 0f32e550d9d8
child 48 af3740e3753f
equal deleted inserted replaced
30:b95ddb5a0d10 44:eff9df3d9c98
    13 *
    13 *
    14 * Description: Wrapper for mpx framework utilities.
    14 * Description: Wrapper for mpx framework utilities.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QTranslator>
       
    19 #include <QLocale>
       
    20 #include <hbmessagebox.h>
       
    21 #include <hbprogressdialog.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbinstance.h>
       
    24 #include <xqsharablefile.h>
    18 #include <xqsharablefile.h>
       
    19 #include <EqualizerConstants.h>
    25 
    20 
    26 #include "mpengine.h"
    21 #include "mpengine.h"
    27 #include "mpmpxharvesterframeworkwrapper.h"
    22 #include "mpmpxharvesterframeworkwrapper.h"
    28 #include "mpmpxcollectionframeworkwrapper.h"
    23 #include "mpmpxcollectionframeworkwrapper.h"
    29 #include "mpmpxplaybackframeworkwrapper.h"
    24 #include "mpmpxplaybackframeworkwrapper.h"
    30 #include "mpsongscanner.h"
    25 #include "mpmpxdetailsframeworkwrapper.h"
       
    26 #include "mpaudioeffectsframeworkwrapper.h"
       
    27 #include "mpequalizerframeworkwrapper.h"
    31 #include "mpmediakeyhandler.h"
    28 #include "mpmediakeyhandler.h"
    32 #include "mptrace.h"
    29 #include "mptrace.h"
       
    30 #include "mpsettingsmanager.h"
       
    31 #include "mpsongscanner.h"
    33 
    32 
    34 /*!
    33 /*!
    35     \class MpEngine
    34     \class MpEngine
    36     \brief Engine for musicplayer - mpx framework utilities.
    35     \brief Engine for musicplayer - mpx framework utilities.
    37 
    36 
    44     Harvesting related signals
    43     Harvesting related signals
    45 -------------------------------------------------------------------------------
    44 -------------------------------------------------------------------------------
    46 */
    45 */
    47 
    46 
    48 /*!
    47 /*!
    49     \fn void scanStarted()
    48     \fn void libraryAboutToUpdate()
    50 
    49 
    51     This signal is emitted when scan operation is started.
    50     This signal is emitted when a scan operation has been requested or
    52 
    51     when MTP synchronization starts.
    53  */
       
    54 
       
    55 /*!
       
    56     \fn void scanEnded()
       
    57 
       
    58     This signal is emitted when scan operation ends.
       
    59 
       
    60  */
       
    61 
       
    62 /*!
       
    63     \fn void scanCountChanged( int count )
       
    64 
       
    65     This signal is emitted when scan count is updated.
       
    66 
    52 
    67  */
    53  */
    68 
    54 
    69 /*!
    55 /*!
    70     \fn void libraryUpdated()
    56     \fn void libraryUpdated()
    71 
    57 
    72     This signal is emitted when MpSongScannerHelper ends scanning,
    58     This signal is emitted when library has changed.
    73     or USB-MTP Synchronization finishes.
    59     
    74 
    60     \sa handleScanEnded()
    75  */
    61     \sa handleDiskEvent()
    76 
    62     \sa handleUsbMtpEndEvent()
    77 /*!
    63 
    78     \fn void formatStarted()
    64  */
    79 
    65 
    80     This signal is emitted when EMcMsgFormatStart is received from MPXCollectionUtility.
    66 /*!
    81 
    67     \fn void usbBlocked( bool blocked )
    82  */
    68 
    83 
    69     This signal is emitted to update the usb blocking state
    84 /*!
    70     due a previous usb event received.
    85     \fn void formatEnded()
    71     
    86 
    72     \sa handleUsbEvent()
    87     This signal is emitted when EMcMsgFormatEnd is received from MPXCollectionUtility.
    73 
    88 
    74  */
    89  */
    75 
    90 
    76 /*!
    91 /*!
    77     \fn void unableToCotinueDueUSB()
    92     \fn void diskRemoved()
    78 
    93 
    79     This signal is emitted if usb blocking verification returns true.
    94     This signal is emitted when EMcMsgDiskRemoved is received from MPXCollectionUtility.
    80     
    95 
    81     \sa verifyUsbBlocking()
    96  */
    82 
    97 
    83  */
    98 /*!
    84 
    99     \fn void diskInserted()
    85 /*!
   100 
    86     \fn void usbSynchronizationStarted()
   101     This signal is emitted when EMcMsgDiskInserted is received from MPXCollectionUtility.
    87 
   102 
    88     This signal is emitted when usb is connected in MassStorage mode or MTP mode and synchronizing.
   103  */
    89 
   104 
    90  */
   105 /*!
    91 
   106     \fn void usbMassStorageStarted()
    92 /*!
   107 
    93     \fn void usbSynchronizationFinished()
   108     This signal is emitted when EMcMsgUSBMassStorageStart is received from MPXCollectionUtility.
    94 
   109 
    95     This signal is emitted when usb in synchronizing state is disconnected.
   110  */
    96 
   111 
    97  */
   112 /*!
    98 
   113     \fn void usbMassStorageEnded()
    99 /*!
   114 
   100     \fn void libraryRefreshNeeded()
   115     This signal is emitted when EMcMsgUSBMassStorageEnd is received from MPXCollectionUtility.
   101 
   116 
   102     This signal is emitted when usb in MassStorage mode is disconnected.
   117  */
       
   118 
       
   119 /*!
       
   120     \fn void usbMtpStarted()
       
   121 
       
   122     This signal is emitted when EMcMsgUSBMtpStart is received from MPXCollectionUtility.
       
   123 
       
   124  */
       
   125 
       
   126 /*!
       
   127     \fn void usbMtpEnded()
       
   128 
       
   129     This signal is emitted when EMcMsgUSBMtpEnd is received from MPXCollectionUtility.
       
   130 
   103 
   131  */
   104  */
   132 
   105 
   133 
   106 
   134 /*!
   107 /*!
   152     indicates the operation \a success .
   125     indicates the operation \a success .
   153 
   126 
   154  */
   127  */
   155 
   128 
   156 /*!
   129 /*!
       
   130     \fn void aboutToAddSongs( int count )
       
   131 
       
   132     Signal emitted up on a notification from MPX Collection wrapper, 
       
   133     when play list is prepared and about to be added.
       
   134     \a count Indicates number of songs to be added.
       
   135 
       
   136  */
       
   137 
       
   138 /*!
       
   139     \fn void deleteStarted(TCollectionContext context, int Count)
       
   140 
       
   141     This signal is emitted when song delete operation has started.
       
   142     \a context The context where delete operation is taking place.
       
   143     \a Count Number of items to delete.
       
   144 
       
   145  */
       
   146 
       
   147 /*!
   157     \fn void songsDeleted( bool success )
   148     \fn void songsDeleted( bool success )
   158 
   149 
   159     This signal is emitted when song delete operation is completed, it 
   150     This signal is emitted when song delete operation is completed, it 
   160     indicates the operation \a success .
   151     indicates the operation \a success .
   161 
   152 
   171 
   162 
   172 /*!
   163 /*!
   173     \fn void isolatedCollectionOpened( MpMpxCollectionData* collectionData )
   164     \fn void isolatedCollectionOpened( MpMpxCollectionData* collectionData )
   174 
   165 
   175     This signal is emitted when an isolated collection is opened on \a context
   166     This signal is emitted when an isolated collection is opened on \a context
       
   167 
       
   168  */
       
   169 
       
   170 /*!
       
   171     \fn void restorePathFailed()
       
   172 
       
   173     This signal is emitted when an the previous path cannot be restored 
       
   174     (i.e. no music in collection).
       
   175 
       
   176  */
       
   177 
       
   178 /*!
       
   179     \fn void containerContentsChanged()
       
   180 
       
   181     This signal is emitted when items are removed or inserted on the current 
       
   182     container.
   176 
   183 
   177  */
   184  */
   178 
   185 
   179 /*!
   186 /*!
   180  Constructs music player engine.
   187  Constructs music player engine.
   181  */
   188  */
   182 MpEngine::MpEngine()
   189 MpEngine::MpEngine()
   183     : mMpxHarvesterWrapper(0),
   190     : mMpxHarvesterWrapper(0),
   184       mSongScanner(0),
   191       mSongScanner(0),
   185       mMediaKeyHandler(0),
   192       mMediaKeyHandler(0),
   186       mUsbOutstandingNote(0),
       
   187       mMpxCollectionWrapper(0),
   193       mMpxCollectionWrapper(0),
   188       mMpxPlaybackWrapper(0),
   194       mMpxPlaybackWrapper(0),
   189       mMpTranslator(0),
   195       mMpxDetailsWrapper(0),
       
   196       mAudioEffectsWrapper(0),
       
   197       mEqualizerWrapper(0),
       
   198       mCurrentPresetIndex(KEqualizerPresetNone),
   190       mUsbBlockingState(USB_NotConnected),
   199       mUsbBlockingState(USB_NotConnected),
   191       mPreviousUsbState(USB_NotConnected),
   200       mPreviousUsbState(USB_NotConnected)
   192       mViewMode(MpCommon::DefaultView)
       
   193 {
   201 {
   194     TX_LOG
   202     TX_LOG
   195 }
   203 }
   196 
   204 
   197 /*!
   205 /*!
   198  Destructs music player engine.
   206  Destructs music player engine.
   199  */
   207  */
   200 MpEngine::~MpEngine()
   208 MpEngine::~MpEngine()
   201 {
   209 {
   202     TX_ENTRY
   210     TX_ENTRY
   203     TX_EXIT
   211     delete mMediaKeyHandler;
   204 }
   212     delete mMpxPlaybackWrapper;
   205 
   213     delete mMpxDetailsWrapper;
   206 /*!
   214     delete mMpxHarvesterWrapper;
   207  Returns the singleton instance of music player engine.
   215     delete mMpxCollectionWrapper;
   208  */
   216     delete mAudioEffectsWrapper;
   209 MpEngine * MpEngine::instance()
   217     delete mEqualizerWrapper;
   210 {
   218     delete mSongScanner;
   211     static MpEngine instance;
   219     TX_EXIT
   212     return &instance;
       
   213 }
   220 }
   214 
   221 
   215 /*!
   222 /*!
   216  Initialize engine
   223  Initialize engine
   217  */
   224  */
   218 void MpEngine::initialize( MpCommon::MpViewMode viewMode, TUid hostUid )
   225 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   219 {
   226 {
   220     TX_ENTRY
   227     TX_ENTRY
   221     mViewMode = viewMode;
       
   222     mHostUid = hostUid;
   228     mHostUid = hostUid;
   223     
   229 
   224     //Load musicplayer translator
   230     if( mode == StandAlone || mode == Fetch ){
   225     QString lang = QLocale::system().name();
       
   226     QString path = QString( "z:/resource/qt/translations/" );
       
   227     bool translatorLoaded = false;
       
   228 
       
   229     mMpTranslator = new QTranslator( this );
       
   230     translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
       
   231     TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
       
   232     if ( translatorLoaded ) {
       
   233         qApp->installTranslator( mMpTranslator );
       
   234     }
       
   235     
       
   236     if( mViewMode == MpCommon::DefaultView || mViewMode == MpCommon::FetchView ){
       
   237         // Harvesting Wrapper
   231         // Harvesting Wrapper
   238         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mViewMode, mHostUid );
   232         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   239         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   233         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   240                  this, SLOT( handleScanStarted() ), Qt::QueuedConnection );
   234                  this, SLOT( handleScanStarted() ), Qt::QueuedConnection );
   241         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ), 
   235         connect( mMpxHarvesterWrapper, SIGNAL( scanEnded(int, int) ), 
   242                  this, SLOT( handleScanEnded(int, int) ), Qt::QueuedConnection );
   236                  this, SLOT( handleScanEnded(int, int) ), Qt::QueuedConnection );
   243         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   237         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   244         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   238         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   245                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   239                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   246         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   240         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   247         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   241         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   248                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );
   242                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );
   249         mSongScanner = new MpSongScanner( mMpxHarvesterWrapper );
       
   250         mMediaKeyHandler = new MpMediaKeyHandler();
   243         mMediaKeyHandler = new MpMediaKeyHandler();
       
   244     }
       
   245 
       
   246     if ( mode == StandAlone || mode == Fetch || mode == MediaBrowsing) {
   251         
   247         
   252         // Collection Wrapper
   248         // Collection Wrapper
   253         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mViewMode, mHostUid );
   249         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid );
       
   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         
   254         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   255         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   255                 this, SIGNAL( collectionPlaylistOpened() ),
   256                 this, SIGNAL( collectionPlaylistOpened() ),
   256                 Qt::QueuedConnection );
   257                 Qt::QueuedConnection );
       
   258         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs( int ) ),
       
   259                 this, SIGNAL( aboutToAddSongs( int ) ) );
   257         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   260         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   258                 this, SIGNAL( playlistSaved( bool ) ),
   261                 this, SIGNAL( playlistSaved( bool ) ),
   259                 Qt::QueuedConnection );
       
   260         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted( bool ) ),
       
   261                 this, SIGNAL( songsDeleted( bool ) ),
       
   262                 Qt::QueuedConnection );
   262                 Qt::QueuedConnection );
   263         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed( bool ) ),
   263         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed( bool ) ),
   264                 this, SIGNAL( playlistsRenamed( bool ) ),
   264                 this, SIGNAL( playlistsRenamed( bool ) ),
   265                 Qt::QueuedConnection );
   265                 Qt::QueuedConnection );
   266         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   266         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   267                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   267                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   268                 Qt::QueuedConnection );
   268                 Qt::QueuedConnection );
   269     }
   269         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   270 
   270                 this, SIGNAL( containerContentsChanged() ),
   271     // Playback Wrapper 
   271                 Qt::QueuedConnection );
   272     mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mViewMode, mHostUid );
   272         connect( mMpxCollectionWrapper, SIGNAL( deleteStarted( TCollectionContext, int ) ),
   273 
   273                 this, SLOT( handleDeleteStarted( TCollectionContext, int ) ) );
   274     TX_EXIT
   274         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted( bool ) ),
   275 }
   275                 this, SLOT( handleDeleteEnded( bool ) ),
   276 
   276                 Qt::QueuedConnection );
   277 /*!
   277         connect( mMpxCollectionWrapper, SIGNAL( restorePathFailed() ),
   278   Deinitialize wrappers
   278                 this, SIGNAL( restorePathFailed() ),
   279  */
   279                 Qt::QueuedConnection );
   280 void MpEngine::close( )
   280     }
   281 {
   281 
   282     delete mMpTranslator;
   282     if( mode == StandAlone ){
   283     mMpTranslator = 0;
   283         // Equalizer wrapper , this needs to be created before playback wrapper.
   284     delete mSongScanner;
   284         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   285     mSongScanner = 0;
   285         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ), 
   286     delete mMediaKeyHandler;
   286                  this, SLOT( handleEqualizerReady() ), Qt::QueuedConnection );
   287     mMediaKeyHandler = 0;   
   287     }
   288     delete mUsbOutstandingNote;
   288     
   289     mUsbOutstandingNote = 0;
   289     if ( mode == StandAlone || mode == Fetch || mode == Embedded ) {
   290     delete mMpxPlaybackWrapper;
   290         // Playback Wrapper 
   291     mMpxPlaybackWrapper = 0;
   291         mMpxPlaybackWrapper = new MpMpxPlaybackFrameworkWrapper( mHostUid );
   292     delete mMpxHarvesterWrapper;
   292         
   293     mMpxHarvesterWrapper = 0;
   293         // Details Wrapper
   294     delete mMpxCollectionWrapper;
   294         mMpxDetailsWrapper = new MpMpxDetailsFrameworkWrapper( mHostUid );
   295     mMpxCollectionWrapper = 0;
   295     }
       
   296 
       
   297     if( mode == StandAlone ){
       
   298         // AudioEffects wrapper
       
   299         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
       
   300     }
       
   301     TX_EXIT
   296 }
   302 }
   297 
   303 
   298 /*!
   304 /*!
   299 -------------------------------------------------------------------------------
   305 -------------------------------------------------------------------------------
   300     Harvesting related
   306     Harvesting related
   304 /*!
   310 /*!
   305  \
   311  \
   306  Used to verify if an action can be executed depending on USB blocking state.
   312  Used to verify if an action can be executed depending on USB blocking state.
   307  If not, a notification note might be displayed.
   313  If not, a notification note might be displayed.
   308  */
   314  */
   309 bool MpEngine::verifyUsbBlocking( bool showMessage )
   315 bool MpEngine::verifyUsbBlocking( bool notify )
   310 {
   316 {
   311     TX_ENTRY
   317     TX_ENTRY
   312     bool result( false );
   318     bool result( false );
   313     if ( mUsbBlockingState == USB_Connected ) {
   319     if ( mUsbBlockingState == USB_Connected ) {
   314         result = true;
   320         result = true;
   315         if ( showMessage ) {
   321         if ( notify ) {
   316             HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
   322             emit unableToCotinueDueUSB();
   317             dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   318             dialog->setModal( true );
       
   319             setOutstandingPopup( dialog );
       
   320             mUsbOutstandingNote->show();;
       
   321         }
   323         }
   322     }
   324     }
   323     TX_EXIT
   325     TX_EXIT
   324     return result;
   326     return result;
   325 }
   327 }
   334     mMpxHarvesterWrapper->checkForSystemEvents();
   336     mMpxHarvesterWrapper->checkForSystemEvents();
   335     TX_EXIT
   337     TX_EXIT
   336 }
   338 }
   337 
   339 
   338 /*!
   340 /*!
       
   341  \
       
   342  Returs the current songScanner instance
       
   343  */
       
   344 MpSongScanner *MpEngine::songScanner()
       
   345 {
       
   346     return mSongScanner;
       
   347 }
       
   348 /*!
   339  Slot to be called to start Refresh library process.
   349  Slot to be called to start Refresh library process.
   340  If scanning is already ongoing, this request is ignored.
   350  If scanning is already ongoing, this request is ignored.
   341  */
   351  */
   342 void MpEngine::refreshLibrary()
   352 void MpEngine::refreshLibrary( bool automaticRequest )
   343 {
   353 {
   344     TX_ENTRY
   354     TX_ENTRY
   345     if ( !verifyUsbBlocking( true ) ) {
   355     if ( !verifyUsbBlocking( true ) ) {
       
   356         if ( !mSongScanner ) {
       
   357             mSongScanner = new MpSongScanner( mMpxHarvesterWrapper );
       
   358         }
   346         emit libraryAboutToUpdate();
   359         emit libraryAboutToUpdate();
   347         mSongScanner->scan();
   360         mSongScanner->scan( automaticRequest );
   348     }
   361     }
   349     TX_EXIT
   362     TX_EXIT
   350 }
   363 }
   351 
   364 
   352 /*!
   365 /*!
   388                 emit libraryUpdated();
   401                 emit libraryUpdated();
   389             }
   402             }
   390             break;
   403             break;
   391         case DiskInserted:
   404         case DiskInserted:
   392             if ( mUsbBlockingState == USB_NotConnected ) {
   405             if ( mUsbBlockingState == USB_NotConnected ) {
   393                 refreshLibrary();
   406                 refreshLibrary( true );
   394             }
   407             }
   395             else if ( mUsbBlockingState == USB_Connected ) {
   408             else if ( mUsbBlockingState == USB_Connected ) {
   396                 emit libraryUpdated();
   409                 emit libraryUpdated();
   397             }
   410             }
   398             break;
   411             break;
   428     }
   441     }
   429     TX_EXIT
   442     TX_EXIT
   430 }
   443 }
   431 
   444 
   432 /*!
   445 /*!
   433  Slot to be called when mUsbOutstandingNote is about to close.
       
   434  */
       
   435 void MpEngine::handleOutstandingNoteClosing()
       
   436 {
       
   437     TX_ENTRY
       
   438     mUsbOutstandingNote = 0;
       
   439     TX_EXIT
       
   440 }
       
   441 
       
   442 /*!
       
   443  To be called when EMcMsgUSBMassStorageStart event is received.
   446  To be called when EMcMsgUSBMassStorageStart event is received.
   444  */
   447  */
   445 void MpEngine::handleUsbMassStorageStartEvent()
   448 void MpEngine::handleUsbMassStorageStartEvent()
   446 {
   449 {
   447     TX_ENTRY
   450     TX_ENTRY
   448     mMediaKeyHandler->setEnabled(false);
   451     mMediaKeyHandler->setEnabled(false);
   449 
   452 
   450     changeUsbBlockingState( USB_Synchronizing );
   453     changeUsbBlockingState( USB_Synchronizing );
   451     emit usbBlocked(true);
   454     emit usbBlocked(true);
   452     
   455     emit usbSynchronizationStarted();
   453     launchBlockingNote();
   456 
   454     
       
   455     TX_EXIT
   457     TX_EXIT
   456 }
   458 }
   457 
   459 
   458 /*!
   460 /*!
   459  To be called when EMcMsgUSBMassStorageEnd event is received.
   461  To be called when EMcMsgUSBMassStorageEnd event is received.
   460  */
   462  */
   461 void MpEngine::handleUsbMassStorageEndEvent()
   463 void MpEngine::handleUsbMassStorageEndEvent()
   462 {
   464 {
   463     TX_ENTRY
   465     TX_ENTRY
   464     mMediaKeyHandler->setEnabled(true);    
   466     mMediaKeyHandler->setEnabled(true);
   465 
   467 
   466     changeUsbBlockingState( USB_NotConnected );
   468     changeUsbBlockingState( USB_NotConnected );
   467     emit usbBlocked(false);
   469     emit usbBlocked(false);
   468 
   470     emit usbSynchronizationFinished();
   469     HbAction *action;
   471     emit libraryRefreshNeeded();
   470     HbMessageBox *promptRefresh = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
   472 
   471     promptRefresh->setText( hbTrId( "txt_mus_info_music_may_need_to_be_refreshed" ) );
       
   472     promptRefresh->setTimeout( HbPopup::NoTimeout );
       
   473     promptRefresh->setModal( true );
       
   474     promptRefresh->clearActions();
       
   475     action = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
   476     connect( action, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );
       
   477     promptRefresh->addAction( action );
       
   478     action = new HbAction( hbTrId( "txt_common_button_no" ) );
       
   479     promptRefresh->addAction( action );
       
   480     setOutstandingPopup( promptRefresh );
       
   481     mUsbOutstandingNote->show();
       
   482     TX_EXIT
   473     TX_EXIT
   483 }
   474 }
   484 
   475 
   485 /*!
   476 /*!
   486  To be called when EMcMsgUSBMTPStart event is received.
   477  To be called when EMcMsgUSBMTPStart event is received.
   494     emit usbBlocked(true);
   485     emit usbBlocked(true);
   495     
   486     
   496     //Cancel any ongoing operation.
   487     //Cancel any ongoing operation.
   497     emit libraryAboutToUpdate();
   488     emit libraryAboutToUpdate();
   498     
   489     
   499     launchBlockingNote();
   490     emit usbSynchronizationStarted();
   500     
   491     
   501     TX_EXIT
   492     TX_EXIT
   502 }
   493 }
   503 
   494 
   504 /*!
   495 /*!
   505  To be called when EMcMsgUSBMTPEnd event is received.
   496  To be called when EMcMsgUSBMTPEnd event is received.
   506  */
   497  */
   507 void MpEngine::handleUsbMtpEndEvent()
   498 void MpEngine::handleUsbMtpEndEvent()
   508 {
   499 {
   509     TX_ENTRY
   500     TX_ENTRY
   510     mMediaKeyHandler->setEnabled(true);    
   501     mMediaKeyHandler->setEnabled(true);
   511 
   502 
   512     changeUsbBlockingState( USB_NotConnected );
   503     changeUsbBlockingState( USB_NotConnected );
   513     emit usbBlocked(false);
   504     emit usbBlocked(false);
   514     
   505 
   515     if ( mUsbOutstandingNote ) {
       
   516         mUsbOutstandingNote->close();
       
   517     }
       
   518     if ( mPreviousUsbState == USB_Synchronizing ) {
   506     if ( mPreviousUsbState == USB_Synchronizing ) {
       
   507         emit usbSynchronizationFinished();
   519         emit libraryUpdated();
   508         emit libraryUpdated();
   520     }
   509     }
   521     TX_EXIT
   510     TX_EXIT
   522 }
   511 }
   523 
   512 
   539 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   528 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   540 {
   529 {
   541     TX_ENTRY
   530     TX_ENTRY
   542     mPreviousUsbState = mUsbBlockingState;
   531     mPreviousUsbState = mUsbBlockingState;
   543     mUsbBlockingState = state;
   532     mUsbBlockingState = state;
   544     TX_EXIT
       
   545 }
       
   546 
       
   547 /*!
       
   548  Internal
       
   549  Used to launch the usb blocking note
       
   550  */
       
   551 void MpEngine::launchBlockingNote()
       
   552 {
       
   553     TX_ENTRY
       
   554 
       
   555     HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   556     usbBlockingNote->setModal( true );
       
   557     if ( usbBlockingNote->actions().count() ) {
       
   558         //Hide cancel action.
       
   559         usbBlockingNote->actions().at( 0 )->setVisible( false );
       
   560     }
       
   561     usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
       
   562     usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   563     setOutstandingPopup( usbBlockingNote );
       
   564     mUsbOutstandingNote->show();
       
   565 
       
   566     TX_EXIT
       
   567 }
       
   568 
       
   569 /*!
       
   570  \internal
       
   571  sets \a popup as the current outstanding popup and cancels any other active popup.
       
   572  */
       
   573 void MpEngine::setOutstandingPopup( HbPopup *popup )
       
   574 {
       
   575     TX_ENTRY
       
   576     //Close previous popup (Normally blocking usb note)
       
   577     if ( mUsbOutstandingNote ) {
       
   578         disconnect( mUsbOutstandingNote, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
       
   579         mUsbOutstandingNote->close();
       
   580     }
       
   581 
       
   582     //Set new outstanding popup
       
   583     popup->setAttribute( Qt::WA_DeleteOnClose );
       
   584     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
       
   585     mUsbOutstandingNote = popup;
       
   586     TX_EXIT
   533     TX_EXIT
   587 }
   534 }
   588 
   535 
   589 /*!
   536 /*!
   590 -------------------------------------------------------------------------------
   537 -------------------------------------------------------------------------------
   720 {
   667 {
   721     mMpxCollectionWrapper->releaseIsolatedCollection();
   668     mMpxCollectionWrapper->releaseIsolatedCollection();
   722 }
   669 }
   723 
   670 
   724 /*!
   671 /*!
       
   672  Finds all songs beloging to the album specified by the \a index.
       
   673  */
       
   674 void MpEngine::findAlbumSongs( int index )
       
   675 {
       
   676     mMpxCollectionWrapper->findAlbumSongs(index);
       
   677 }
       
   678 
       
   679 /*!
       
   680  Plays album with \a albumIndex starting with the songs with \a songIndex.
       
   681  */
       
   682 void MpEngine::playAlbumSongs( int albumIndex, int songIndex, MpMpxCollectionData* collectionData  )
       
   683 {
       
   684     mMpxCollectionWrapper->playAlbumSongs(albumIndex, songIndex, collectionData);
       
   685 }
       
   686 
       
   687 /*!
   725  Returns pointer to MpMpxCollectionData, which is the collection data.
   688  Returns pointer to MpMpxCollectionData, which is the collection data.
   726  */
   689  */
   727 MpMpxCollectionData *MpEngine::collectionData()
   690 MpMpxCollectionData *MpEngine::collectionData()
   728 {
   691 {
   729     return mMpxCollectionWrapper->collectionData();
   692     return mMpxCollectionWrapper->collectionData();
   748 {
   711 {
   749     mMpxCollectionWrapper->reorderPlaylist( playlistId, songId, originalOrdinal, newOrdinal );
   712     mMpxCollectionWrapper->reorderPlaylist( playlistId, songId, originalOrdinal, newOrdinal );
   750 }
   713 }
   751 
   714 
   752 /*!
   715 /*!
       
   716  Slot to be called when song deleting starts.
       
   717  */
       
   718 void MpEngine::handleDeleteStarted( TCollectionContext context, int count )
       
   719 {
       
   720     TX_ENTRY
       
   721     mMediaKeyHandler->setEnabled( false );
       
   722     emit deleteStarted( context, count );
       
   723     TX_EXIT
       
   724 }
       
   725 
       
   726 /*!
       
   727  Slot to be called when song deleting ends.
       
   728  */
       
   729 void MpEngine::handleDeleteEnded( bool success )
       
   730 {
       
   731     TX_ENTRY
       
   732     mMediaKeyHandler->setEnabled(true);
       
   733     emit songsDeleted( success );
       
   734     TX_EXIT
       
   735 }
       
   736 
       
   737 /*!
       
   738  Slot to be called when song deleting ends.
       
   739  */
       
   740 void MpEngine::cancelCollectionRequest()
       
   741 {
       
   742     TX_ENTRY
       
   743     mMpxCollectionWrapper->cancelRequest();
       
   744     TX_EXIT
       
   745 }
       
   746 
       
   747 /*!
   753  Returns pointer to MpPlaybackData, which is the playback data.
   748  Returns pointer to MpPlaybackData, which is the playback data.
   754  */
   749  */
   755 MpPlaybackData *MpEngine::playbackData()
   750 MpPlaybackData *MpEngine::playbackData()
   756 {
   751 {
   757     return mMpxPlaybackWrapper->playbackData();
   752     return mMpxPlaybackWrapper->playbackData();
   758 }
   753 }
       
   754 
       
   755 /*!
       
   756  Requests playback of all songs with shuffle enabled
       
   757  */
       
   758 void MpEngine::shuffleAll()
       
   759 {
       
   760     mMpxCollectionWrapper->openShuffleAllSongsPath();
       
   761 }
       
   762 
   759 /*!
   763 /*!
   760  Slot to be called to request embedded playback of item with Uri aFilename
   764  Slot to be called to request embedded playback of item with Uri aFilename
   761  */
   765  */
   762 
   766 
   763 void MpEngine::playEmbedded( QString aFilename )
   767 void MpEngine::playEmbedded( QString aFilename )
   788 {
   792 {
   789     mMpxPlaybackWrapper->stop();
   793     mMpxPlaybackWrapper->stop();
   790 }
   794 }
   791 
   795 
   792 /*!
   796 /*!
   793  Slot to handle a skeep forward.
   797  Slot to handle a skip forward.
   794  */
   798  */
   795 void MpEngine::skipForward()
   799 void MpEngine::skipForward()
   796 {
   800 {
   797     mMpxPlaybackWrapper->skipForward();
   801     mMpxPlaybackWrapper->skipForward();
   798 }
   802 }
   799 
   803 
   800 /*!
   804 /*!
   801  Slot to handle a skeep backwards.
   805  Slot to handle  seek forward.
       
   806  */
       
   807 void MpEngine::startSeekForward()
       
   808 {
       
   809     mMpxPlaybackWrapper->startSeekForward();
       
   810 }
       
   811 
       
   812 /*!
       
   813  Slot to handle stop seeking.
       
   814  */
       
   815 void MpEngine::stopSeeking()
       
   816 {
       
   817     mMpxPlaybackWrapper->stopSeeking();
       
   818 }
       
   819 
       
   820 /*!
       
   821  Slot to handle a skip backwards.
   802  */
   822  */
   803 void MpEngine::skipBackward()
   823 void MpEngine::skipBackward()
   804 {
   824 {
   805     mMpxPlaybackWrapper->skipBackward();
   825     mMpxPlaybackWrapper->skipBackward();
   806 }
   826 }
   807 
   827 
   808 /*!
   828 /*!
       
   829  Slot to handle seek backwards.
       
   830  */
       
   831 void MpEngine::startSeekBackward()
       
   832 {
       
   833     mMpxPlaybackWrapper->startSeekBackward();
       
   834 }
       
   835 /*!
   809  Slot to handle a request to change \a position.
   836  Slot to handle a request to change \a position.
   810  */
   837  */
   811 void MpEngine::setPosition( int position )
   838 void MpEngine::setPosition( int position )
   812 {
   839 {
   813     mMpxPlaybackWrapper->setPosition( position );
   840     mMpxPlaybackWrapper->setPosition( position );
   827 void MpEngine::setRepeat( bool mode )
   854 void MpEngine::setRepeat( bool mode )
   828 {
   855 {
   829     mMpxPlaybackWrapper->setRepeat( mode );
   856     mMpxPlaybackWrapper->setRepeat( mode );
   830 }
   857 }
   831 
   858 
       
   859 /*!
       
   860  Returns pointer to MpSongData, which is the song data for detail's view.
       
   861  */
       
   862 MpSongData *MpEngine::songData()
       
   863 {
       
   864     return mMpxDetailsWrapper->songData();
       
   865 }
       
   866 
       
   867 /*!
       
   868  Retrieve song informatioin
       
   869  */
       
   870 void MpEngine::retrieveSong()
       
   871 {
       
   872     TX_ENTRY
       
   873     mMpxDetailsWrapper->retrieveSong();
       
   874     TX_EXIT
       
   875 }
       
   876 
       
   877 /*!
       
   878  Retrieve balance informatioin from audio effects
       
   879  */
       
   880 int MpEngine::balance()
       
   881 {
       
   882     return mAudioEffectsWrapper->balance();
       
   883 }
       
   884 
       
   885 /*!
       
   886  Retrieve loudness informatioin from audio effects
       
   887  */
       
   888 bool MpEngine::loudness()
       
   889 {
       
   890     return mAudioEffectsWrapper->loudness();
       
   891 }
       
   892 
       
   893 /*!
       
   894  Slot to handle a request to change \a balance in audio effects.
       
   895  */
       
   896 void MpEngine::setBalance( int balance )
       
   897 {
       
   898     TX_ENTRY
       
   899     
       
   900     if ( mAudioEffectsWrapper->balance() != balance ) {
       
   901         mAudioEffectsWrapper->setBalance( balance );
       
   902         mMpxPlaybackWrapper->setBalance( balance );
       
   903     }
       
   904     
       
   905     TX_EXIT
       
   906 }
       
   907 
       
   908 /*!
       
   909  Slot to handle a request to change loudness \a mode in audio effects.
       
   910  */
       
   911 void MpEngine::setLoudness( bool mode )
       
   912 {
       
   913     TX_ENTRY
       
   914     
       
   915     if( mAudioEffectsWrapper->loudness() != mode ) { //do not set same value twice
       
   916         mAudioEffectsWrapper->setLoudness( mode );
       
   917         mMpxPlaybackWrapper->applyAudioEffects();
       
   918     }
       
   919     
       
   920     TX_EXIT
       
   921 }
       
   922 
       
   923 /*!
       
   924  Apply the preset by giving \a presetIndex. The index is subtracted by 1 because
       
   925  index 0 represent "Off" at UI level.
       
   926  */
       
   927 void MpEngine::applyPreset( int presetIndex )
       
   928 {
       
   929     TX_ENTRY_ARGS( "presetIndex=" << presetIndex );
       
   930     
       
   931     TInt presetKey = mEqualizerWrapper->getPresetNameKey( presetIndex - 1 );
       
   932     
       
   933     if ( presetKey != KEqualizerPresetNone ) {
       
   934         TX_LOG_ARGS( "Preset key in engine =" << presetKey );
       
   935         // Store in CenRep file
       
   936         MpSettingsManager::setPreset( presetKey );
       
   937         // Notify playback framework of the change.
       
   938         mMpxPlaybackWrapper->applyEqualizer();
       
   939         mCurrentPresetIndex = presetIndex;
       
   940     }
       
   941     else {
       
   942         TX_LOG_ARGS("getPresetNameKey Error  = " << KEqualizerPresetNone);
       
   943     }
       
   944     
       
   945     TX_EXIT
       
   946 }
       
   947 
       
   948 /*!
       
   949  Disabling equalizer by setting the preset to -1 and apply it to 
       
   950  disable current preset.
       
   951  */
       
   952 void MpEngine::disableEqualizer()
       
   953 {
       
   954     TX_ENTRY
       
   955 
       
   956     mCurrentPresetIndex = KEqualizerPresetNone;
       
   957     // Store in CenRep file
       
   958     MpSettingsManager::setPreset( mCurrentPresetIndex );
       
   959     // Notify playback framework of the change.
       
   960     mMpxPlaybackWrapper->applyEqualizer();
       
   961 
       
   962     TX_EXIT
       
   963 }
       
   964 
       
   965 /*!
       
   966  Return current preset index (UI)
       
   967  */
       
   968 int MpEngine::activePreset()
       
   969 {
       
   970     TX_LOG_ARGS("mCurrentPresetIndex = " << mCurrentPresetIndex );
       
   971 
       
   972     return mCurrentPresetIndex;
       
   973 }
       
   974 
       
   975 /*!
       
   976  Retrieve list of preset names from equalizer wrapper
       
   977  */
       
   978 QStringList MpEngine::presetNames()
       
   979 {
       
   980     return mEqualizerWrapper->presetNames(); 
       
   981 }
       
   982 
       
   983 /*!
       
   984  Save data needed to later restore state (activity)
       
   985  */
       
   986 void MpEngine::saveActivityData( QByteArray &data )
       
   987 {
       
   988     mMpxCollectionWrapper->savePath( data );
       
   989 }
       
   990 
       
   991 /*!
       
   992  Restore state from activity data 
       
   993  */
       
   994 void MpEngine::loadActivityData( const QByteArray &data ) 
       
   995 {
       
   996     mMpxCollectionWrapper->restorePath( data );
       
   997 }
       
   998 
       
   999 /*!
       
  1000  Slot to handle equalizer ready signal from equalizer wrapper.
       
  1001  */
       
  1002 void MpEngine::handleEqualizerReady()
       
  1003 {
       
  1004     TX_ENTRY
       
  1005     
       
  1006     // Get preset id from cenrep
       
  1007     TInt presetKey( MpSettingsManager::preset() );
       
  1008     
       
  1009     //Set the current preset index. 1 is added to index because index 0 represent "Off" at UI level.
       
  1010     mCurrentPresetIndex = mEqualizerWrapper->getPresetIndex( presetKey );
       
  1011     mCurrentPresetIndex++;
       
  1012     emit equalizerReady();
       
  1013     
       
  1014     TX_EXIT
       
  1015 }
       
  1016