mpengine/src/mpengine.cpp
changeset 37 eb79a7c355bf
parent 36 a0afa279b8fe
child 38 b93f525c9244
equal deleted inserted replaced
36:a0afa279b8fe 37:eb79a7c355bf
    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>
    25 #include <EqualizerConstants.h>
    19 #include <EqualizerConstants.h>
    26 
    20 
    27 #include "mpengine.h"
    21 #include "mpengine.h"
    28 #include "mpmpxharvesterframeworkwrapper.h"
    22 #include "mpmpxharvesterframeworkwrapper.h"
    32 #include "mpaudioeffectsframeworkwrapper.h"
    26 #include "mpaudioeffectsframeworkwrapper.h"
    33 #include "mpequalizerframeworkwrapper.h"
    27 #include "mpequalizerframeworkwrapper.h"
    34 #include "mpmediakeyhandler.h"
    28 #include "mpmediakeyhandler.h"
    35 #include "mptrace.h"
    29 #include "mptrace.h"
    36 #include "mpsettingsmanager.h"
    30 #include "mpsettingsmanager.h"
    37 #include "mpprogressdialoghandler.h"
    31 #include "mpsongscanner.h"
    38 
    32 
    39 /*!
    33 /*!
    40     \class MpEngine
    34     \class MpEngine
    41     \brief Engine for musicplayer - mpx framework utilities.
    35     \brief Engine for musicplayer - mpx framework utilities.
    42 
    36 
    49     Harvesting related signals
    43     Harvesting related signals
    50 -------------------------------------------------------------------------------
    44 -------------------------------------------------------------------------------
    51 */
    45 */
    52 
    46 
    53 /*!
    47 /*!
    54     \fn void scanStarted()
    48     \fn void libraryAboutToUpdate()
    55 
    49 
    56     This signal is emitted when scan operation is started.
    50     This signal is emitted when a scan operation has been requested or
    57 
    51     when MTP synchronization starts.
    58  */
       
    59 
       
    60 /*!
       
    61     \fn void scanEnded()
       
    62 
       
    63     This signal is emitted when scan operation ends.
       
    64 
       
    65  */
       
    66 
       
    67 /*!
       
    68     \fn void scanCountChanged( int count )
       
    69 
       
    70     This signal is emitted when scan count is updated.
       
    71 
    52 
    72  */
    53  */
    73 
    54 
    74 /*!
    55 /*!
    75     \fn void libraryUpdated()
    56     \fn void libraryUpdated()
    76 
    57 
    77     This signal is emitted when MpSongScannerHelper ends scanning,
    58     This signal is emitted when library has changed.
    78     or USB-MTP Synchronization finishes.
    59     
    79 
    60     \sa handleScanEnded()
    80  */
    61     \sa handleDiskEvent()
    81 
    62     \sa handleUsbMtpEndEvent()
    82 /*!
    63 
    83     \fn void formatStarted()
    64  */
    84 
    65 
    85     This signal is emitted when EMcMsgFormatStart is received from MPXCollectionUtility.
    66 /*!
    86 
    67     \fn void usbBlocked( bool blocked )
    87  */
    68 
    88 
    69     This signal is emitted to update the usb blocking state
    89 /*!
    70     due a previous usb event received.
    90     \fn void formatEnded()
    71     
    91 
    72     \sa handleUsbEvent()
    92     This signal is emitted when EMcMsgFormatEnd is received from MPXCollectionUtility.
    73 
    93 
    74  */
    94  */
    75 
    95 
    76 /*!
    96 /*!
    77     \fn void unableToCotinueDueUSB()
    97     \fn void diskRemoved()
    78 
    98 
    79     This signal is emitted if usb blocking verification returns true.
    99     This signal is emitted when EMcMsgDiskRemoved is received from MPXCollectionUtility.
    80     
   100 
    81     \sa verifyUsbBlocking()
   101  */
    82 
   102 
    83  */
   103 /*!
    84 
   104     \fn void diskInserted()
    85 /*!
   105 
    86     \fn void usbSynchronizationStarted()
   106     This signal is emitted when EMcMsgDiskInserted is received from MPXCollectionUtility.
    87 
   107 
    88     This signal is emitted when usb is connected in MassStorage mode or MTP mode and synchronizing.
   108  */
    89 
   109 
    90  */
   110 /*!
    91 
   111     \fn void usbMassStorageStarted()
    92 /*!
   112 
    93     \fn void usbSynchronizationFinished()
   113     This signal is emitted when EMcMsgUSBMassStorageStart is received from MPXCollectionUtility.
    94 
   114 
    95     This signal is emitted when usb in synchronizing state is disconnected.
   115  */
    96 
   116 
    97  */
   117 /*!
    98 
   118     \fn void usbMassStorageEnded()
    99 /*!
   119 
   100     \fn void libraryRefreshNeeded()
   120     This signal is emitted when EMcMsgUSBMassStorageEnd is received from MPXCollectionUtility.
   101 
   121 
   102     This signal is emitted when usb in MassStorage mode is disconnected.
   122  */
       
   123 
       
   124 /*!
       
   125     \fn void usbMtpStarted()
       
   126 
       
   127     This signal is emitted when EMcMsgUSBMtpStart is received from MPXCollectionUtility.
       
   128 
       
   129  */
       
   130 
       
   131 /*!
       
   132     \fn void usbMtpEnded()
       
   133 
       
   134     This signal is emitted when EMcMsgUSBMtpEnd is received from MPXCollectionUtility.
       
   135 
   103 
   136  */
   104  */
   137 
   105 
   138 
   106 
   139 /*!
   107 /*!
   157     indicates the operation \a success .
   125     indicates the operation \a success .
   158 
   126 
   159  */
   127  */
   160 
   128 
   161 /*!
   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 /*!
   162     \fn void songsDeleted( bool success )
   148     \fn void songsDeleted( bool success )
   163 
   149 
   164     This signal is emitted when song delete operation is completed, it 
   150     This signal is emitted when song delete operation is completed, it 
   165     indicates the operation \a success .
   151     indicates the operation \a success .
   166 
   152 
   192 /*!
   178 /*!
   193  Constructs music player engine.
   179  Constructs music player engine.
   194  */
   180  */
   195 MpEngine::MpEngine()
   181 MpEngine::MpEngine()
   196     : mMpxHarvesterWrapper(0),
   182     : mMpxHarvesterWrapper(0),
       
   183       mSongScanner(0),
   197       mMediaKeyHandler(0),
   184       mMediaKeyHandler(0),
   198       mUsbOutstandingNote(0),
       
   199       mMpxCollectionWrapper(0),
   185       mMpxCollectionWrapper(0),
   200       mMpxPlaybackWrapper(0),
   186       mMpxPlaybackWrapper(0),
   201       mMpxDetailsWrapper(0),
   187       mMpxDetailsWrapper(0),
   202       mAudioEffectsWrapper(0),
   188       mAudioEffectsWrapper(0),
   203       mEqualizerWrapper(0),
   189       mEqualizerWrapper(0),
   204       mCurrentPresetIndex(KEqualizerPresetNone),
   190       mCurrentPresetIndex(KEqualizerPresetNone),
   205       mMpTranslator(0),
       
   206       mUsbBlockingState(USB_NotConnected),
   191       mUsbBlockingState(USB_NotConnected),
   207       mPreviousUsbState(USB_NotConnected),
   192       mPreviousUsbState(USB_NotConnected)
   208       mProgressDialogHandler(0)
       
   209 {
   193 {
   210     TX_LOG
   194     TX_LOG
   211 }
   195 }
   212 
   196 
   213 /*!
   197 /*!
   214  Destructs music player engine.
   198  Destructs music player engine.
   215  */
   199  */
   216 MpEngine::~MpEngine()
   200 MpEngine::~MpEngine()
   217 {
   201 {
   218     TX_ENTRY
   202     TX_ENTRY
   219     delete mMpTranslator;
       
   220     delete mMediaKeyHandler;
   203     delete mMediaKeyHandler;
   221     delete mUsbOutstandingNote;
       
   222     delete mMpxPlaybackWrapper;
   204     delete mMpxPlaybackWrapper;
   223     delete mMpxDetailsWrapper;
   205     delete mMpxDetailsWrapper;
   224     delete mMpxHarvesterWrapper;
   206     delete mMpxHarvesterWrapper;
   225     delete mMpxCollectionWrapper;
   207     delete mMpxCollectionWrapper;
   226     delete mAudioEffectsWrapper;
   208     delete mAudioEffectsWrapper;
   227     delete mEqualizerWrapper;
   209     delete mEqualizerWrapper;
   228 	delete mProgressDialogHandler;
   210     delete mSongScanner;
   229     TX_EXIT
   211     TX_EXIT
   230 }
   212 }
   231 
   213 
   232 /*!
   214 /*!
   233  Initialize engine
   215  Initialize engine
   234  */
   216  */
   235 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   217 void MpEngine::initialize( TUid hostUid, EngineMode mode )
   236 {
   218 {
   237     TX_ENTRY
   219     TX_ENTRY
   238     mHostUid = hostUid;
   220     mHostUid = hostUid;
   239     
       
   240     //Load musicplayer translator
       
   241     QString lang = QLocale::system().name();
       
   242     QString path = QString( "z:/resource/qt/translations/" );
       
   243     bool translatorLoaded = false;
       
   244 
       
   245     mMpTranslator = new QTranslator( this );
       
   246     translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
       
   247     TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
       
   248     if ( translatorLoaded ) {
       
   249         qApp->installTranslator( mMpTranslator );
       
   250     }
       
   251 
   221 
   252     if( mode == StandAlone || mode == Fetch ){
   222     if( mode == StandAlone || mode == Fetch ){
   253         // Harvesting Wrapper
   223         // Harvesting Wrapper
   254         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   224         mMpxHarvesterWrapper = new MpMpxHarvesterFrameworkWrapper( mHostUid );
   255         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   225         connect( mMpxHarvesterWrapper, SIGNAL( scanStarted() ), 
   259         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   229         qRegisterMetaType<MpxDiskEvents>("MpxDiskEvents");
   260         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   230         connect( mMpxHarvesterWrapper, SIGNAL( diskEvent(MpxDiskEvents) ), 
   261                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   231                  this, SLOT( handleDiskEvent(MpxDiskEvents) ), Qt::QueuedConnection );
   262         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   232         qRegisterMetaType<MpxUsbEvents>("MpxUsbEvents");
   263         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   233         connect( mMpxHarvesterWrapper, SIGNAL( usbEvent(MpxUsbEvents) ), 
   264                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );       
   234                  this, SLOT( handleUsbEvent(MpxUsbEvents) ), Qt::QueuedConnection );
   265         mMediaKeyHandler = new MpMediaKeyHandler();
   235         mMediaKeyHandler = new MpMediaKeyHandler();
   266     }
   236     }
   267         
   237 
   268     if ( mode == StandAlone || mode == Fetch || mode == MediaBrowsing) {
   238     if ( mode == StandAlone || mode == Fetch || mode == MediaBrowsing) {
   269         
   239         
   270         // Collection Wrapper
   240         // Collection Wrapper
   271         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid );
   241         mMpxCollectionWrapper = new MpMpxCollectionFrameworkWrapper( mHostUid );
   272         
   242         
   275         mMpxCollectionWrapper->setShuffleFeatureEnabled( mode != Fetch );
   245         mMpxCollectionWrapper->setShuffleFeatureEnabled( mode != Fetch );
   276         
   246         
   277         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   247         connect( mMpxCollectionWrapper, SIGNAL( collectionPlaylistOpened() ),
   278                 this, SIGNAL( collectionPlaylistOpened() ),
   248                 this, SIGNAL( collectionPlaylistOpened() ),
   279                 Qt::QueuedConnection );
   249                 Qt::QueuedConnection );
       
   250         connect( mMpxCollectionWrapper, SIGNAL( aboutToAddSongs( int ) ),
       
   251                 this, SIGNAL( aboutToAddSongs( int ) ) );
   280         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   252         connect( mMpxCollectionWrapper, SIGNAL( playlistSaved( bool ) ),
   281                 this, SIGNAL( playlistSaved( bool ) ),
   253                 this, SIGNAL( playlistSaved( bool ) ),
   282                 Qt::QueuedConnection );
       
   283         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted( bool ) ),
       
   284                 this, SIGNAL( songsDeleted( bool ) ),
       
   285                 Qt::QueuedConnection );
   254                 Qt::QueuedConnection );
   286         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed( bool ) ),
   255         connect( mMpxCollectionWrapper, SIGNAL( playlistsRenamed( bool ) ),
   287                 this, SIGNAL( playlistsRenamed( bool ) ),
   256                 this, SIGNAL( playlistsRenamed( bool ) ),
   288                 Qt::QueuedConnection );
   257                 Qt::QueuedConnection );
   289         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   258         connect( mMpxCollectionWrapper, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   290                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   259                 this, SIGNAL( isolatedCollectionOpened( MpMpxCollectionData* ) ),
   291                 Qt::QueuedConnection );
   260                 Qt::QueuedConnection );
   292         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   261         connect( mMpxCollectionWrapper, SIGNAL( containerContentsChanged() ),
   293                 this, SIGNAL( containerContentsChanged() ),
   262                 this, SIGNAL( containerContentsChanged() ),
   294                 Qt::QueuedConnection );
   263                 Qt::QueuedConnection );
   295         connect( mProgressDialogHandler, SIGNAL( deleteStarted() ), 
   264         connect( mMpxCollectionWrapper, SIGNAL( deleteStarted( TCollectionContext, int ) ),
   296                this, SLOT( handleDeleteStarted() ),
   265                 this, SLOT( handleDeleteStarted( TCollectionContext, int ) ) );
   297                Qt::QueuedConnection );
   266         connect( mMpxCollectionWrapper, SIGNAL( songsDeleted( bool ) ),
   298        connect( mProgressDialogHandler, SIGNAL( songsDeleted( bool ) ),
   267                 this, SLOT( handleDeleteEnded( bool ) ),
   299                this, SLOT( handleDeleteEnded( bool ) ),
   268                 Qt::QueuedConnection );
   300                Qt::QueuedConnection );
   269     }
   301     }
   270 
   302     
       
   303     if( mode == StandAlone ){
   271     if( mode == StandAlone ){
   304         // Equalizer wrapper , this needs to be created before playback wrapper.
   272         // Equalizer wrapper , this needs to be created before playback wrapper.
   305         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   273         mEqualizerWrapper = new MpEqualizerFrameworkWrapper();
   306         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ), 
   274         connect( mEqualizerWrapper, SIGNAL( equalizerReady() ), 
   307                  this, SLOT( handleEqualizerReady() ), Qt::QueuedConnection );
   275                  this, SLOT( handleEqualizerReady() ), Qt::QueuedConnection );
   317 
   285 
   318     if( mode == StandAlone ){
   286     if( mode == StandAlone ){
   319         // AudioEffects wrapper
   287         // AudioEffects wrapper
   320         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
   288         mAudioEffectsWrapper = new MpAudioEffectsFrameworkWrapper();
   321     }
   289     }
   322     if (mMpxHarvesterWrapper && mMpxCollectionWrapper){
   290     TX_EXIT
   323         mProgressDialogHandler = new MpProgressDialogHandler(mMpxCollectionWrapper, mMpxHarvesterWrapper);
       
   324     }
       
   325 	TX_EXIT
       
   326 }
   291 }
   327 
   292 
   328 /*!
   293 /*!
   329 -------------------------------------------------------------------------------
   294 -------------------------------------------------------------------------------
   330     Harvesting related
   295     Harvesting related
   334 /*!
   299 /*!
   335  \
   300  \
   336  Used to verify if an action can be executed depending on USB blocking state.
   301  Used to verify if an action can be executed depending on USB blocking state.
   337  If not, a notification note might be displayed.
   302  If not, a notification note might be displayed.
   338  */
   303  */
   339 bool MpEngine::verifyUsbBlocking( bool showMessage )
   304 bool MpEngine::verifyUsbBlocking( bool notify )
   340 {
   305 {
   341     TX_ENTRY
   306     TX_ENTRY
   342     bool result( false );
   307     bool result( false );
   343     if ( mUsbBlockingState == USB_Connected ) {
   308     if ( mUsbBlockingState == USB_Connected ) {
   344         result = true;
   309         result = true;
   345         if ( showMessage ) {
   310         if ( notify ) {
   346             HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
   311             emit unableToCotinueDueUSB();
   347             dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   348             dialog->setModal( true );
       
   349             setOutstandingPopup( dialog );
       
   350             mUsbOutstandingNote->show();;
       
   351         }
   312         }
   352     }
   313     }
   353     TX_EXIT
   314     TX_EXIT
   354     return result;
   315     return result;
   355 }
   316 }
   364     mMpxHarvesterWrapper->checkForSystemEvents();
   325     mMpxHarvesterWrapper->checkForSystemEvents();
   365     TX_EXIT
   326     TX_EXIT
   366 }
   327 }
   367 
   328 
   368 /*!
   329 /*!
       
   330  \
       
   331  Returs the current songScanner instance
       
   332  */
       
   333 MpSongScanner *MpEngine::songScanner()
       
   334 {
       
   335     return mSongScanner;
       
   336 }
       
   337 /*!
   369  Slot to be called to start Refresh library process.
   338  Slot to be called to start Refresh library process.
   370  If scanning is already ongoing, this request is ignored.
   339  If scanning is already ongoing, this request is ignored.
   371  */
   340  */
   372 void MpEngine::refreshLibrary()
   341 void MpEngine::refreshLibrary( bool automaticRequest )
   373 {
   342 {
   374     TX_ENTRY
   343     TX_ENTRY
   375     if ( !verifyUsbBlocking( true ) ) {
   344     if ( !verifyUsbBlocking( true ) ) {
       
   345         if ( !mSongScanner ) {
       
   346             mSongScanner = new MpSongScanner( mMpxHarvesterWrapper );
       
   347         }
   376         emit libraryAboutToUpdate();
   348         emit libraryAboutToUpdate();
   377         mProgressDialogHandler->scan();
   349         mSongScanner->scan( automaticRequest );
   378     }
   350     }
   379     TX_EXIT
   351     TX_EXIT
   380 }
   352 }
   381 
   353 
   382 /*!
   354 /*!
   418                 emit libraryUpdated();
   390                 emit libraryUpdated();
   419             }
   391             }
   420             break;
   392             break;
   421         case DiskInserted:
   393         case DiskInserted:
   422             if ( mUsbBlockingState == USB_NotConnected ) {
   394             if ( mUsbBlockingState == USB_NotConnected ) {
   423                 refreshLibrary();
   395                 refreshLibrary( true );
   424             }
   396             }
   425             else if ( mUsbBlockingState == USB_Connected ) {
   397             else if ( mUsbBlockingState == USB_Connected ) {
   426                 emit libraryUpdated();
   398                 emit libraryUpdated();
   427             }
   399             }
   428             break;
   400             break;
   458     }
   430     }
   459     TX_EXIT
   431     TX_EXIT
   460 }
   432 }
   461 
   433 
   462 /*!
   434 /*!
   463  Slot to be called when mUsbOutstandingNote is about to close.
       
   464  */
       
   465 void MpEngine::handleOutstandingNoteClosing()
       
   466 {
       
   467     TX_ENTRY
       
   468     mUsbOutstandingNote = 0;
       
   469     TX_EXIT
       
   470 }
       
   471 
       
   472 /*!
       
   473  To be called when EMcMsgUSBMassStorageStart event is received.
   435  To be called when EMcMsgUSBMassStorageStart event is received.
   474  */
   436  */
   475 void MpEngine::handleUsbMassStorageStartEvent()
   437 void MpEngine::handleUsbMassStorageStartEvent()
   476 {
   438 {
   477     TX_ENTRY
   439     TX_ENTRY
   478     mMediaKeyHandler->setEnabled(false);
   440     mMediaKeyHandler->setEnabled(false);
   479 
   441 
   480     changeUsbBlockingState( USB_Synchronizing );
   442     changeUsbBlockingState( USB_Synchronizing );
   481     emit usbBlocked(true);
   443     emit usbBlocked(true);
   482     
   444     emit usbSynchronizationStarted();
   483     launchBlockingNote();
   445 
   484     
       
   485     TX_EXIT
   446     TX_EXIT
   486 }
   447 }
   487 
   448 
   488 /*!
   449 /*!
   489  To be called when EMcMsgUSBMassStorageEnd event is received.
   450  To be called when EMcMsgUSBMassStorageEnd event is received.
   490  */
   451  */
   491 void MpEngine::handleUsbMassStorageEndEvent()
   452 void MpEngine::handleUsbMassStorageEndEvent()
   492 {
   453 {
   493     TX_ENTRY
   454     TX_ENTRY
   494     mMediaKeyHandler->setEnabled(true);    
   455     mMediaKeyHandler->setEnabled(true);
   495 
   456 
   496     changeUsbBlockingState( USB_NotConnected );
   457     changeUsbBlockingState( USB_NotConnected );
   497     emit usbBlocked(false);
   458     emit usbBlocked(false);
   498 
   459     emit usbSynchronizationFinished();
   499     HbAction *action;
   460     emit libraryRefreshNeeded();
   500     HbMessageBox *promptRefresh = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
   461 
   501     promptRefresh->setText( hbTrId( "txt_mus_info_music_may_need_to_be_refreshed" ) );
       
   502     promptRefresh->setTimeout( HbPopup::NoTimeout );
       
   503     promptRefresh->setModal( true );
       
   504     promptRefresh->clearActions();
       
   505     action = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
   506     connect( action, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );
       
   507     promptRefresh->addAction( action );
       
   508     action = new HbAction( hbTrId( "txt_common_button_no" ) );
       
   509     promptRefresh->addAction( action );
       
   510     setOutstandingPopup( promptRefresh );
       
   511     mUsbOutstandingNote->show();
       
   512     TX_EXIT
   462     TX_EXIT
   513 }
   463 }
   514 
   464 
   515 /*!
   465 /*!
   516  To be called when EMcMsgUSBMTPStart event is received.
   466  To be called when EMcMsgUSBMTPStart event is received.
   524     emit usbBlocked(true);
   474     emit usbBlocked(true);
   525     
   475     
   526     //Cancel any ongoing operation.
   476     //Cancel any ongoing operation.
   527     emit libraryAboutToUpdate();
   477     emit libraryAboutToUpdate();
   528     
   478     
   529     launchBlockingNote();
   479     emit usbSynchronizationStarted();
   530     
   480     
   531     TX_EXIT
   481     TX_EXIT
   532 }
   482 }
   533 
   483 
   534 /*!
   484 /*!
   535  To be called when EMcMsgUSBMTPEnd event is received.
   485  To be called when EMcMsgUSBMTPEnd event is received.
   536  */
   486  */
   537 void MpEngine::handleUsbMtpEndEvent()
   487 void MpEngine::handleUsbMtpEndEvent()
   538 {
   488 {
   539     TX_ENTRY
   489     TX_ENTRY
   540     mMediaKeyHandler->setEnabled(true);    
   490     mMediaKeyHandler->setEnabled(true);
   541 
   491 
   542     changeUsbBlockingState( USB_NotConnected );
   492     changeUsbBlockingState( USB_NotConnected );
   543     emit usbBlocked(false);
   493     emit usbBlocked(false);
   544     
   494 
   545     if ( mUsbOutstandingNote ) {
       
   546         mUsbOutstandingNote->close();
       
   547     }
       
   548     if ( mPreviousUsbState == USB_Synchronizing ) {
   495     if ( mPreviousUsbState == USB_Synchronizing ) {
       
   496         emit usbSynchronizationFinished();
   549         emit libraryUpdated();
   497         emit libraryUpdated();
   550     }
   498     }
   551     TX_EXIT
   499     TX_EXIT
   552 }
   500 }
   553 
   501 
   569 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   517 void MpEngine::changeUsbBlockingState( UsbBlockingState state )
   570 {
   518 {
   571     TX_ENTRY
   519     TX_ENTRY
   572     mPreviousUsbState = mUsbBlockingState;
   520     mPreviousUsbState = mUsbBlockingState;
   573     mUsbBlockingState = state;
   521     mUsbBlockingState = state;
   574     TX_EXIT
       
   575 }
       
   576 
       
   577 /*!
       
   578  Internal
       
   579  Used to launch the usb blocking note
       
   580  */
       
   581 void MpEngine::launchBlockingNote()
       
   582 {
       
   583     TX_ENTRY
       
   584 
       
   585     HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   586     usbBlockingNote->setModal( true );
       
   587     if ( usbBlockingNote->actions().count() ) {
       
   588         //Hide cancel action.
       
   589         usbBlockingNote->actions().at( 0 )->setVisible( false );
       
   590     }
       
   591     usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
       
   592     usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   593     setOutstandingPopup( usbBlockingNote );
       
   594     mUsbOutstandingNote->show();
       
   595 
       
   596     TX_EXIT
       
   597 }
       
   598 
       
   599 /*!
       
   600  \internal
       
   601  sets \a popup as the current outstanding popup and cancels any other active popup.
       
   602  */
       
   603 void MpEngine::setOutstandingPopup( HbPopup *popup )
       
   604 {
       
   605     TX_ENTRY
       
   606     //Close previous popup (Normally blocking usb note)
       
   607     if ( mUsbOutstandingNote ) {
       
   608         disconnect( mUsbOutstandingNote, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
       
   609         mUsbOutstandingNote->close();
       
   610     }
       
   611 
       
   612     //Set new outstanding popup
       
   613     popup->setAttribute( Qt::WA_DeleteOnClose );
       
   614     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
       
   615     mUsbOutstandingNote = popup;
       
   616     TX_EXIT
   522     TX_EXIT
   617 }
   523 }
   618 
   524 
   619 /*!
   525 /*!
   620 -------------------------------------------------------------------------------
   526 -------------------------------------------------------------------------------
   715  Deletes \a selection from the collection.
   621  Deletes \a selection from the collection.
   716  */
   622  */
   717 void MpEngine::deleteSongs( QList<int> &selection )
   623 void MpEngine::deleteSongs( QList<int> &selection )
   718 {
   624 {
   719     if ( !verifyUsbBlocking( true ) ) {
   625     if ( !verifyUsbBlocking( true ) ) {
   720         mProgressDialogHandler->deleteSongs( selection );
   626         mMpxCollectionWrapper->deleteSongs( selection );
   721     }
   627     }
   722 }
   628 }
   723 
   629 
   724 
   630 
   725 
   631 
   791  \a originalOrdinal to \a newOrdinal.
   697  \a originalOrdinal to \a newOrdinal.
   792  */
   698  */
   793 void MpEngine::reorderPlaylist( int playlistId, int songId, int originalOrdinal, int newOrdinal )
   699 void MpEngine::reorderPlaylist( int playlistId, int songId, int originalOrdinal, int newOrdinal )
   794 {
   700 {
   795     mMpxCollectionWrapper->reorderPlaylist( playlistId, songId, originalOrdinal, newOrdinal );
   701     mMpxCollectionWrapper->reorderPlaylist( playlistId, songId, originalOrdinal, newOrdinal );
       
   702 }
       
   703 
       
   704 /*!
       
   705  Slot to be called when song deleting starts.
       
   706  */
       
   707 void MpEngine::handleDeleteStarted( TCollectionContext context, int count )
       
   708 {
       
   709     TX_ENTRY
       
   710     mMediaKeyHandler->setEnabled( false );
       
   711     emit deleteStarted( context, count );
       
   712     TX_EXIT
       
   713 }
       
   714 
       
   715 /*!
       
   716  Slot to be called when song deleting ends.
       
   717  */
       
   718 void MpEngine::handleDeleteEnded( bool success )
       
   719 {
       
   720     TX_ENTRY
       
   721     mMediaKeyHandler->setEnabled(true);
       
   722     emit songsDeleted( success );
       
   723     TX_EXIT
       
   724 }
       
   725 
       
   726 /*!
       
   727  Slot to be called when song deleting ends.
       
   728  */
       
   729 void MpEngine::cancelCollectionRequest()
       
   730 {
       
   731     TX_ENTRY
       
   732     mMpxCollectionWrapper->cancelRequest();
       
   733     TX_EXIT
   796 }
   734 }
   797 
   735 
   798 /*!
   736 /*!
   799  Returns pointer to MpPlaybackData, which is the playback data.
   737  Returns pointer to MpPlaybackData, which is the playback data.
   800  */
   738  */
  1047     emit equalizerReady();
   985     emit equalizerReady();
  1048     
   986     
  1049     TX_EXIT
   987     TX_EXIT
  1050 }
   988 }
  1051 
   989 
  1052 /*!
       
  1053  Slot to be called when song deleting starts.
       
  1054  */
       
  1055 void MpEngine::handleDeleteStarted() {
       
  1056     TX_ENTRY
       
  1057     mMediaKeyHandler->setEnabled(false);
       
  1058     TX_EXIT
       
  1059 }
       
  1060 
       
  1061 /*!
       
  1062  Slot to be called when song deleting ends.
       
  1063  */
       
  1064 void MpEngine::handleDeleteEnded() {
       
  1065     TX_ENTRY
       
  1066     mMediaKeyHandler->setEnabled(true);
       
  1067     TX_EXIT
       
  1068 }
       
  1069