mpengine/src/mpengine.cpp
changeset 34 2c5162224003
parent 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
22:ecf06a08d4d9 34:2c5162224003
    17 
    17 
    18 #include <QTranslator>
    18 #include <QTranslator>
    19 #include <QLocale>
    19 #include <QLocale>
    20 #include <hbmessagebox.h>
    20 #include <hbmessagebox.h>
    21 #include <hbprogressdialog.h>
    21 #include <hbprogressdialog.h>
       
    22 #include <hbaction.h>
    22 #include <hbinstance.h>
    23 #include <hbinstance.h>
    23 #include <xqsharablefile.h>
    24 #include <xqsharablefile.h>
    24 
    25 
    25 #include "mpengine.h"
    26 #include "mpengine.h"
    26 #include "mpmpxharvesterframeworkwrapper.h"
    27 #include "mpmpxharvesterframeworkwrapper.h"
    64     This signal is emitted when scan count is updated.
    65     This signal is emitted when scan count is updated.
    65 
    66 
    66  */
    67  */
    67 
    68 
    68 /*!
    69 /*!
    69     \fn void libraryRefreshed()
    70     \fn void libraryUpdated()
    70 
    71 
    71     This signal is emitted when MpSongScannerHelper ends scanning,
    72     This signal is emitted when MpSongScannerHelper ends scanning,
    72     or USB-MTP Synchronization finishes.
    73     or USB-MTP Synchronization finishes.
    73 
    74 
    74  */
    75  */
   180  */
   181  */
   181 MpEngine::MpEngine()
   182 MpEngine::MpEngine()
   182     : mMpxHarvesterWrapper(0),
   183     : mMpxHarvesterWrapper(0),
   183       mSongScanner(0),
   184       mSongScanner(0),
   184       mMediaKeyHandler(0),
   185       mMediaKeyHandler(0),
   185       mUsbBlockingNote(0),
   186       mUsbOutstandingNote(0),
   186       mMpxCollectionWrapper(0),
   187       mMpxCollectionWrapper(0),
   187       mMpxPlaybackWrapper(0),
   188       mMpxPlaybackWrapper(0),
   188       mMpTranslator(0),
   189       mMpTranslator(0),
   189       mUsbBlockingState(USB_NotConnected),
   190       mUsbBlockingState(USB_NotConnected),
   190       mPreviousUsbState(USB_NotConnected),
   191       mPreviousUsbState(USB_NotConnected),
   282     mMpTranslator = 0;
   283     mMpTranslator = 0;
   283     delete mSongScanner;
   284     delete mSongScanner;
   284     mSongScanner = 0;
   285     mSongScanner = 0;
   285     delete mMediaKeyHandler;
   286     delete mMediaKeyHandler;
   286     mMediaKeyHandler = 0;   
   287     mMediaKeyHandler = 0;   
   287     delete mUsbBlockingNote;
   288     delete mUsbOutstandingNote;
   288     mUsbBlockingNote = 0;
   289     mUsbOutstandingNote = 0;
   289     delete mMpxPlaybackWrapper;
   290     delete mMpxPlaybackWrapper;
   290     mMpxPlaybackWrapper = 0;
   291     mMpxPlaybackWrapper = 0;
   291     delete mMpxHarvesterWrapper;
   292     delete mMpxHarvesterWrapper;
   292     mMpxHarvesterWrapper = 0;
   293     mMpxHarvesterWrapper = 0;
   293     delete mMpxCollectionWrapper;
   294     delete mMpxCollectionWrapper;
   299     Harvesting related
   300     Harvesting related
   300 -------------------------------------------------------------------------------
   301 -------------------------------------------------------------------------------
   301 */
   302 */
   302 
   303 
   303 /*!
   304 /*!
   304  Refresh library by starting the scan.
       
   305  If scanning is already ongoing, this request is ignored.
       
   306  */
       
   307 void MpEngine::refreshLibrary()
       
   308 {
       
   309     TX_ENTRY
       
   310     if ( !verifyUsbBlocking( true ) ) {
       
   311         emit libraryAboutToRefresh();
       
   312         mSongScanner->scan();
       
   313     }
       
   314     TX_EXIT
       
   315 }
       
   316 
       
   317 /*!
       
   318  \
   305  \
   319  Used to verify if an action can be executed depending on USB blocking state.
   306  Used to verify if an action can be executed depending on USB blocking state.
   320  If not, a notification note might be displayed.
   307  If not, a notification note might be displayed.
   321  */
   308  */
   322 bool MpEngine::verifyUsbBlocking( bool showMessage )
   309 bool MpEngine::verifyUsbBlocking( bool showMessage )
   324     TX_ENTRY
   311     TX_ENTRY
   325     bool result( false );
   312     bool result( false );
   326     if ( mUsbBlockingState == USB_Connected ) {
   313     if ( mUsbBlockingState == USB_Connected ) {
   327         result = true;
   314         result = true;
   328         if ( showMessage ) {
   315         if ( showMessage ) {
   329             HbMessageBox dialog ( HbMessageBox::MessageTypeInformation );
   316             HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
   330             dialog.setText( QString( tr( "USB connection in progress. Cannot proceed with operation" ) ) );
   317             dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
   331             dialog.setModal( true );
   318             dialog->setModal( true );
   332             dialog.exec();
   319             setOutstandingPopup( dialog );
       
   320             mUsbOutstandingNote->show();;
   333         }
   321         }
   334     }
   322     }
   335     TX_EXIT
   323     TX_EXIT
   336     return result;
   324     return result;
   337 }
   325 }
   342  */
   330  */
   343 void MpEngine::checkForSystemEvents()
   331 void MpEngine::checkForSystemEvents()
   344 {
   332 {
   345     TX_ENTRY
   333     TX_ENTRY
   346     mMpxHarvesterWrapper->checkForSystemEvents();
   334     mMpxHarvesterWrapper->checkForSystemEvents();
       
   335     TX_EXIT
       
   336 }
       
   337 
       
   338 /*!
       
   339  Slot to be called to start Refresh library process.
       
   340  If scanning is already ongoing, this request is ignored.
       
   341  */
       
   342 void MpEngine::refreshLibrary()
       
   343 {
       
   344     TX_ENTRY
       
   345     if ( !verifyUsbBlocking( true ) ) {
       
   346         emit libraryAboutToUpdate();
       
   347         mSongScanner->scan();
       
   348     }
   347     TX_EXIT
   349     TX_EXIT
   348 }
   350 }
   349 
   351 
   350 /*!
   352 /*!
   351  Slot to be called when song scanning starts.
   353  Slot to be called when song scanning starts.
   362 void MpEngine::handleScanEnded( int count, int error ) {
   364 void MpEngine::handleScanEnded( int count, int error ) {
   363     TX_ENTRY
   365     TX_ENTRY
   364     Q_UNUSED( count );
   366     Q_UNUSED( count );
   365     Q_UNUSED( error );
   367     Q_UNUSED( error );
   366     mMediaKeyHandler->setEnabled(true);
   368     mMediaKeyHandler->setEnabled(true);
   367     emit libraryRefreshed();
   369     emit libraryUpdated();
   368     TX_EXIT
   370     TX_EXIT
   369 }
   371 }
   370 
   372 
   371 /*!
   373 /*!
   372  Slot to be called when disk event is received from MPX framework.
   374  Slot to be called when disk event is received from MPX framework.
   381         case DiskFormatEnded:
   383         case DiskFormatEnded:
   382             mMediaKeyHandler->setEnabled(true);
   384             mMediaKeyHandler->setEnabled(true);
   383             break;
   385             break;
   384         case DiskRemoved:
   386         case DiskRemoved:
   385             if ( mUsbBlockingState != USB_Synchronizing ) {
   387             if ( mUsbBlockingState != USB_Synchronizing ) {
   386                 emit libraryRefreshed();
   388                 emit libraryUpdated();
   387             }
   389             }
   388             break;
   390             break;
   389         case DiskInserted:
   391         case DiskInserted:
   390             if ( mUsbBlockingState == USB_NotConnected ) {
   392             if ( mUsbBlockingState == USB_NotConnected ) {
   391                 refreshLibrary();
   393                 refreshLibrary();
   392             }
   394             }
   393             else if ( mUsbBlockingState == USB_Connected ) {
   395             else if ( mUsbBlockingState == USB_Connected ) {
   394                 emit libraryRefreshed();
   396                 emit libraryUpdated();
   395             }
   397             }
   396             break;
   398             break;
   397         default:
   399         default:
   398             break;
   400             break;
   399     }
   401     }
   426     }
   428     }
   427     TX_EXIT
   429     TX_EXIT
   428 }
   430 }
   429 
   431 
   430 /*!
   432 /*!
   431  Slot to be called when mUsbBlockingNote is about to close.
   433  Slot to be called when mUsbOutstandingNote is about to close.
   432  */
   434  */
   433 void MpEngine::handleBlockingNoteClosing()
   435 void MpEngine::handleOutstandingNoteClosing()
   434 {
   436 {
   435     TX_ENTRY
   437     TX_ENTRY
   436     mUsbBlockingNote = 0;
   438     mUsbOutstandingNote = 0;
   437     TX_EXIT
   439     TX_EXIT
   438 }
   440 }
   439 
   441 
   440 /*!
   442 /*!
   441  To be called when EMcMsgUSBMassStorageStart event is received.
   443  To be called when EMcMsgUSBMassStorageStart event is received.
   461     TX_ENTRY
   463     TX_ENTRY
   462     mMediaKeyHandler->setEnabled(true);    
   464     mMediaKeyHandler->setEnabled(true);    
   463 
   465 
   464     changeUsbBlockingState( USB_NotConnected );
   466     changeUsbBlockingState( USB_NotConnected );
   465     emit usbBlocked(false);
   467     emit usbBlocked(false);
   466     
   468 
   467     if ( mUsbBlockingNote ) {
   469     HbAction *action;
   468         mUsbBlockingNote->close();
   470     HbMessageBox *promptRefresh = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
   469     }
   471     promptRefresh->setText( hbTrId( "txt_mus_info_music_may_need_to_be_refreshed" ) );
   470     HbMessageBox promptRefresh( HbMessageBox::MessageTypeQuestion );
   472     promptRefresh->setTimeout( HbPopup::NoTimeout );
   471     promptRefresh.setText( QString( tr( "List may need refreshing due to recent USB synchronisation. Refresh now?" ) ) );
   473     promptRefresh->setModal( true );
   472     promptRefresh.setTimeout( HbPopup::NoTimeout );
   474     promptRefresh->clearActions();
   473     promptRefresh.setModal( true );
   475     action = new HbAction( hbTrId( "txt_common_button_yes" ) );
   474     HbAction *action = promptRefresh.exec();
   476     connect( action, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );
   475     if ( action == promptRefresh.primaryAction() ) {
   477     promptRefresh->addAction( action );
   476         refreshLibrary();
   478     action = new HbAction( hbTrId( "txt_common_button_no" ) );
   477     }
   479     promptRefresh->addAction( action );
       
   480     setOutstandingPopup( promptRefresh );
       
   481     mUsbOutstandingNote->show();
   478     TX_EXIT
   482     TX_EXIT
   479 }
   483 }
   480 
   484 
   481 /*!
   485 /*!
   482  To be called when EMcMsgUSBMTPStart event is received.
   486  To be called when EMcMsgUSBMTPStart event is received.
   488     
   492     
   489     changeUsbBlockingState( USB_Synchronizing );
   493     changeUsbBlockingState( USB_Synchronizing );
   490     emit usbBlocked(true);
   494     emit usbBlocked(true);
   491     
   495     
   492     //Cancel any ongoing operation.
   496     //Cancel any ongoing operation.
   493     emit libraryAboutToRefresh();
   497     emit libraryAboutToUpdate();
   494     
   498     
   495     launchBlockingNote();
   499     launchBlockingNote();
   496     
   500     
   497     TX_EXIT
   501     TX_EXIT
   498 }
   502 }
   506     mMediaKeyHandler->setEnabled(true);    
   510     mMediaKeyHandler->setEnabled(true);    
   507 
   511 
   508     changeUsbBlockingState( USB_NotConnected );
   512     changeUsbBlockingState( USB_NotConnected );
   509     emit usbBlocked(false);
   513     emit usbBlocked(false);
   510     
   514     
   511     if ( mUsbBlockingNote ) {
   515     if ( mUsbOutstandingNote ) {
   512         mUsbBlockingNote->close();
   516         mUsbOutstandingNote->close();
   513     }
   517     }
   514     if ( mPreviousUsbState == USB_Synchronizing ) {
   518     if ( mPreviousUsbState == USB_Synchronizing ) {
   515         emit libraryRefreshed();
   519         emit libraryUpdated();
   516     }
   520     }
   517     TX_EXIT
   521     TX_EXIT
   518 }
   522 }
   519 
   523 
   520 /*!
   524 /*!
   545  Used to launch the usb blocking note
   549  Used to launch the usb blocking note
   546  */
   550  */
   547 void MpEngine::launchBlockingNote()
   551 void MpEngine::launchBlockingNote()
   548 {
   552 {
   549     TX_ENTRY
   553     TX_ENTRY
   550     if ( !mUsbBlockingNote ) {
   554 
   551         mUsbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );        
   555     HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
   552         mUsbBlockingNote->setModal( true );
   556     usbBlockingNote->setModal( true );
   553         mUsbBlockingNote->setPrimaryAction( 0 );
   557     if ( usbBlockingNote->actions().count() ) {
   554         mUsbBlockingNote->setTextAlignment( Qt::AlignCenter );
   558         //Hide cancel action.
   555         mUsbBlockingNote->setAttribute( Qt::WA_DeleteOnClose );
   559         usbBlockingNote->actions().at( 0 )->setVisible( false );
   556         mUsbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );        
   560     }
   557         mUsbBlockingNote->setText( QString( tr( "USB connection in progress" ) ) );
   561     usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
   558         connect( mUsbBlockingNote, SIGNAL( aboutToClose() ), this, SLOT( handleBlockingNoteClosing() ) );
   562     usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
   559     }
   563     setOutstandingPopup( usbBlockingNote );
   560     
   564     mUsbOutstandingNote->show();
   561     mUsbBlockingNote->show();
   565 
   562 
   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;
   563     TX_EXIT
   586     TX_EXIT
   564 }
   587 }
   565 
   588 
   566 /*!
   589 /*!
   567 -------------------------------------------------------------------------------
   590 -------------------------------------------------------------------------------