mpengine/src/mpengine.cpp
changeset 34 2c5162224003
parent 22 ecf06a08d4d9
child 29 8192e5b5c935
--- a/mpengine/src/mpengine.cpp	Mon May 03 12:29:20 2010 +0300
+++ b/mpengine/src/mpengine.cpp	Fri Apr 30 19:33:32 2010 -0500
@@ -19,6 +19,7 @@
 #include <QLocale>
 #include <hbmessagebox.h>
 #include <hbprogressdialog.h>
+#include <hbaction.h>
 #include <hbinstance.h>
 #include <xqsharablefile.h>
 
@@ -66,7 +67,7 @@
  */
 
 /*!
-    \fn void libraryRefreshed()
+    \fn void libraryUpdated()
 
     This signal is emitted when MpSongScannerHelper ends scanning,
     or USB-MTP Synchronization finishes.
@@ -182,7 +183,7 @@
     : mMpxHarvesterWrapper(0),
       mSongScanner(0),
       mMediaKeyHandler(0),
-      mUsbBlockingNote(0),
+      mUsbOutstandingNote(0),
       mMpxCollectionWrapper(0),
       mMpxPlaybackWrapper(0),
       mMpTranslator(0),
@@ -284,8 +285,8 @@
     mSongScanner = 0;
     delete mMediaKeyHandler;
     mMediaKeyHandler = 0;   
-    delete mUsbBlockingNote;
-    mUsbBlockingNote = 0;
+    delete mUsbOutstandingNote;
+    mUsbOutstandingNote = 0;
     delete mMpxPlaybackWrapper;
     mMpxPlaybackWrapper = 0;
     delete mMpxHarvesterWrapper;
@@ -301,20 +302,6 @@
 */
 
 /*!
- Refresh library by starting the scan.
- If scanning is already ongoing, this request is ignored.
- */
-void MpEngine::refreshLibrary()
-{
-    TX_ENTRY
-    if ( !verifyUsbBlocking( true ) ) {
-        emit libraryAboutToRefresh();
-        mSongScanner->scan();
-    }
-    TX_EXIT
-}
-
-/*!
  \
  Used to verify if an action can be executed depending on USB blocking state.
  If not, a notification note might be displayed.
@@ -326,10 +313,11 @@
     if ( mUsbBlockingState == USB_Connected ) {
         result = true;
         if ( showMessage ) {
-            HbMessageBox dialog ( HbMessageBox::MessageTypeInformation );
-            dialog.setText( QString( tr( "USB connection in progress. Cannot proceed with operation" ) ) );
-            dialog.setModal( true );
-            dialog.exec();
+            HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
+            dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
+            dialog->setModal( true );
+            setOutstandingPopup( dialog );
+            mUsbOutstandingNote->show();;
         }
     }
     TX_EXIT
@@ -348,6 +336,20 @@
 }
 
 /*!
+ Slot to be called to start Refresh library process.
+ If scanning is already ongoing, this request is ignored.
+ */
+void MpEngine::refreshLibrary()
+{
+    TX_ENTRY
+    if ( !verifyUsbBlocking( true ) ) {
+        emit libraryAboutToUpdate();
+        mSongScanner->scan();
+    }
+    TX_EXIT
+}
+
+/*!
  Slot to be called when song scanning starts.
  */
 void MpEngine::handleScanStarted() {
@@ -364,7 +366,7 @@
     Q_UNUSED( count );
     Q_UNUSED( error );
     mMediaKeyHandler->setEnabled(true);
-    emit libraryRefreshed();
+    emit libraryUpdated();
     TX_EXIT
 }
 
@@ -383,7 +385,7 @@
             break;
         case DiskRemoved:
             if ( mUsbBlockingState != USB_Synchronizing ) {
-                emit libraryRefreshed();
+                emit libraryUpdated();
             }
             break;
         case DiskInserted:
@@ -391,7 +393,7 @@
                 refreshLibrary();
             }
             else if ( mUsbBlockingState == USB_Connected ) {
-                emit libraryRefreshed();
+                emit libraryUpdated();
             }
             break;
         default:
@@ -428,12 +430,12 @@
 }
 
 /*!
- Slot to be called when mUsbBlockingNote is about to close.
+ Slot to be called when mUsbOutstandingNote is about to close.
  */
-void MpEngine::handleBlockingNoteClosing()
+void MpEngine::handleOutstandingNoteClosing()
 {
     TX_ENTRY
-    mUsbBlockingNote = 0;
+    mUsbOutstandingNote = 0;
     TX_EXIT
 }
 
@@ -463,18 +465,20 @@
 
     changeUsbBlockingState( USB_NotConnected );
     emit usbBlocked(false);
-    
-    if ( mUsbBlockingNote ) {
-        mUsbBlockingNote->close();
-    }
-    HbMessageBox promptRefresh( HbMessageBox::MessageTypeQuestion );
-    promptRefresh.setText( QString( tr( "List may need refreshing due to recent USB synchronisation. Refresh now?" ) ) );
-    promptRefresh.setTimeout( HbPopup::NoTimeout );
-    promptRefresh.setModal( true );
-    HbAction *action = promptRefresh.exec();
-    if ( action == promptRefresh.primaryAction() ) {
-        refreshLibrary();
-    }
+
+    HbAction *action;
+    HbMessageBox *promptRefresh = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
+    promptRefresh->setText( hbTrId( "txt_mus_info_music_may_need_to_be_refreshed" ) );
+    promptRefresh->setTimeout( HbPopup::NoTimeout );
+    promptRefresh->setModal( true );
+    promptRefresh->clearActions();
+    action = new HbAction( hbTrId( "txt_common_button_yes" ) );
+    connect( action, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );
+    promptRefresh->addAction( action );
+    action = new HbAction( hbTrId( "txt_common_button_no" ) );
+    promptRefresh->addAction( action );
+    setOutstandingPopup( promptRefresh );
+    mUsbOutstandingNote->show();
     TX_EXIT
 }
 
@@ -490,7 +494,7 @@
     emit usbBlocked(true);
     
     //Cancel any ongoing operation.
-    emit libraryAboutToRefresh();
+    emit libraryAboutToUpdate();
     
     launchBlockingNote();
     
@@ -508,11 +512,11 @@
     changeUsbBlockingState( USB_NotConnected );
     emit usbBlocked(false);
     
-    if ( mUsbBlockingNote ) {
-        mUsbBlockingNote->close();
+    if ( mUsbOutstandingNote ) {
+        mUsbOutstandingNote->close();
     }
     if ( mPreviousUsbState == USB_Synchronizing ) {
-        emit libraryRefreshed();
+        emit libraryUpdated();
     }
     TX_EXIT
 }
@@ -547,19 +551,38 @@
 void MpEngine::launchBlockingNote()
 {
     TX_ENTRY
-    if ( !mUsbBlockingNote ) {
-        mUsbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );        
-        mUsbBlockingNote->setModal( true );
-        mUsbBlockingNote->setPrimaryAction( 0 );
-        mUsbBlockingNote->setTextAlignment( Qt::AlignCenter );
-        mUsbBlockingNote->setAttribute( Qt::WA_DeleteOnClose );
-        mUsbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );        
-        mUsbBlockingNote->setText( QString( tr( "USB connection in progress" ) ) );
-        connect( mUsbBlockingNote, SIGNAL( aboutToClose() ), this, SLOT( handleBlockingNoteClosing() ) );
+
+    HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
+    usbBlockingNote->setModal( true );
+    if ( usbBlockingNote->actions().count() ) {
+        //Hide cancel action.
+        usbBlockingNote->actions().at( 0 )->setVisible( false );
     }
-    
-    mUsbBlockingNote->show();
+    usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
+    usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
+    setOutstandingPopup( usbBlockingNote );
+    mUsbOutstandingNote->show();
+
+    TX_EXIT
+}
 
+/*!
+ \internal
+ sets \a popup as the current outstanding popup and cancels any other active popup.
+ */
+void MpEngine::setOutstandingPopup( HbPopup *popup )
+{
+    TX_ENTRY
+    //Close previous popup (Normally blocking usb note)
+    if ( mUsbOutstandingNote ) {
+        disconnect( mUsbOutstandingNote, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
+        mUsbOutstandingNote->close();
+    }
+
+    //Set new outstanding popup
+    popup->setAttribute( Qt::WA_DeleteOnClose );
+    connect( popup, SIGNAL( aboutToClose() ), this, SLOT( handleOutstandingNoteClosing() ) );
+    mUsbOutstandingNote = popup;
     TX_EXIT
 }