app/src/mpglobalpopuphandler.cpp
changeset 41 ea59c434026a
child 43 0f32e550d9d8
child 48 af3740e3753f
equal deleted inserted replaced
32:c163ef0b758d 41:ea59c434026a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Music Player global popup handler.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <hblabel.h>
       
    20 #include <hbaction.h>
       
    21 #include <hbfontspec.h>
       
    22 #include <hbmessagebox.h>
       
    23 #include <hbprogressdialog.h>
       
    24 #include <hbnotificationdialog.h>
       
    25 
       
    26 #include "mpglobalpopuphandler.h"
       
    27 #include "mpsettingsmanager.h"
       
    28 #include "mpenginefactory.h"
       
    29 #include "mpsongscanner.h"
       
    30 #include "mpmtpinfolink.h"
       
    31 #include "mptrace.h"
       
    32 
       
    33 /*!
       
    34     \class MpGlobalPopupHandler
       
    35     \brief Music Player global popup handler.
       
    36 
       
    37     This class controls the asynchronous operation of all global dialogs. 
       
    38 */
       
    39 
       
    40 // Popups launched by this class
       
    41 const QString KScanProgressDialog = QString( "ScanProgressDialog" );
       
    42 const QString KDiskFullDialog = QString( "DiskFullDialog" );
       
    43 const QString KScanFinished = QString( "ScanFinishedDialog" );
       
    44 const QString KUnableToContinueDueUSB = QString( "UnableToContinueDueUSB" );
       
    45 const QString KUsbBlockingNote = QString( "UsbBlockingNote" );
       
    46 const QString KPromptRefresh = QString( "PromptRefresh" );
       
    47 const QString KMTPInfoDialog = QString( "MTPInfoDialog" );
       
    48 
       
    49 // Popups Actions
       
    50 const QString KYes = QString( "yes" );
       
    51 const QString KNo = QString( "no" );
       
    52 
       
    53 /*!
       
    54  Constructs the collection popup handler.
       
    55  */
       
    56 MpGlobalPopupHandler::MpGlobalPopupHandler( QObject *parent )
       
    57     : QObject( parent ),
       
    58       mOutstandingPopup( 0 ),
       
    59       mMpEngine( 0 ),
       
    60       mMpSongScanner( 0 )
       
    61 {
       
    62     TX_ENTRY
       
    63     mMpEngine = MpEngineFactory::sharedEngine();
       
    64     connect( mMpEngine, SIGNAL( libraryAboutToUpdate() ), this, SLOT( handleLibraryAboutToUpdate() ) );
       
    65     connect( mMpEngine, SIGNAL( unableToCotinueDueUSB() ), this, SLOT( launchUnableToCotinueDueUsb() ) );
       
    66     connect( mMpEngine, SIGNAL( usbSynchronizationStarted() ), this, SLOT( launchUsbBlockingNote() ) );
       
    67     connect( mMpEngine, SIGNAL( usbSynchronizationFinished() ), this, SLOT( closeUsbBlockingNote() ) );
       
    68     connect( mMpEngine, SIGNAL( libraryRefreshNeeded() ), this, SLOT( launchRefreshLibraryRequest() ) );
       
    69     TX_EXIT
       
    70 }
       
    71 
       
    72 /*!
       
    73  Destructs the collection popup handler.
       
    74  */
       
    75 MpGlobalPopupHandler::~MpGlobalPopupHandler()
       
    76 {
       
    77     TX_ENTRY
       
    78     delete mOutstandingPopup;
       
    79     TX_EXIT
       
    80 }
       
    81 
       
    82 /*!
       
    83  Closes any active popup
       
    84  */
       
    85 void MpGlobalPopupHandler::cancelOngoingPopup()
       
    86 {
       
    87     TX_ENTRY
       
    88     if ( mOutstandingPopup ) {
       
    89          mOutstandingPopup->close();
       
    90     }
       
    91     TX_EXIT
       
    92 }
       
    93 
       
    94 /*!
       
    95  Slot called upon MpEngine signal libraryAboutToUpdate(). Used to connect with SongScanner.
       
    96  */
       
    97 void MpGlobalPopupHandler::handleLibraryAboutToUpdate()
       
    98 {
       
    99     TX_ENTRY
       
   100     if ( !mMpSongScanner && mMpEngine->songScanner() ) {
       
   101         mMpSongScanner = mMpEngine->songScanner();
       
   102         connect( mMpSongScanner, SIGNAL( scanStarted() ), this, SLOT( launchScanDialog() ) );
       
   103         connect( mMpSongScanner, SIGNAL( scanCountChanged( int ) ), this, SLOT( scanCountChanged( int ) ) );
       
   104         connect( mMpSongScanner, SIGNAL( scanFinished( int, int ) ), 
       
   105                  this, SLOT( handleScanFinished( int, int ) ) );
       
   106     }
       
   107     TX_EXIT
       
   108 }
       
   109 
       
   110 /*!
       
   111  Slot called upon notification from MpSongScanner indicating start of
       
   112  scanning process.
       
   113  */
       
   114 void MpGlobalPopupHandler::launchScanDialog()
       
   115 {
       
   116     TX_ENTRY
       
   117     HbProgressDialog* scanProgressDialog = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   118     connect( scanProgressDialog, SIGNAL( cancelled() ), mMpSongScanner, SLOT( cancelScan() ) );
       
   119     scanProgressDialog->setModal( true );
       
   120     HbLabel *title = new HbLabel( hbTrId( "txt_mus_title_refreshing" ) );
       
   121     title->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   122 
       
   123     scanProgressDialog->setHeadingWidget( title );
       
   124     scanProgressDialog->setText( QString("") );
       
   125     scanProgressDialog->setAttribute( Qt::WA_DeleteOnClose );
       
   126     scanProgressDialog->setObjectName( KScanProgressDialog );
       
   127     setOutstandingPopup( scanProgressDialog );
       
   128     scanProgressDialog->show();
       
   129     TX_EXIT
       
   130 }
       
   131 
       
   132 /*!
       
   133  Slot called upon notification from MpSongScanner indicating the number of
       
   134  songs scanned so far.
       
   135  */
       
   136 void MpGlobalPopupHandler::scanCountChanged(int count)
       
   137 {
       
   138     TX_ENTRY_ARGS("count " << count )
       
   139     if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KScanProgressDialog ) ) {
       
   140         HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
       
   141         QString added;
       
   142         added = hbTrId( "txt_mus_info_ln_songs_added" , count );
       
   143         dialog->setText( added );
       
   144     }
       
   145     TX_EXIT
       
   146 }
       
   147 
       
   148 /*!
       
   149  Slot called upon notification from MpSongScanner. Used to close current scan progress note,
       
   150  and display scan results.
       
   151  
       
   152  */
       
   153 void MpGlobalPopupHandler::handleScanFinished( int error, int itemsAdded )
       
   154 {
       
   155     TX_ENTRY_ARGS("error: " << error << " Items added: " << itemsAdded )
       
   156     if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KScanProgressDialog ) ) {
       
   157         HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
       
   158         disconnect( dialog, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
   159         mOutstandingPopup = 0;
       
   160         dialog->close();
       
   161     }
       
   162 
       
   163     switch( error ) {
       
   164         case MpSongScanner::ScanErrorNone :
       
   165             launchScanFinishedDialog( true, itemsAdded );
       
   166             break;
       
   167         case MpSongScanner::ScanGeneralError :
       
   168             launchScanFinishedDialog( false, itemsAdded );
       
   169             break;
       
   170         case MpSongScanner::ScanErrorDiskFull :
       
   171             launchDiskFullDialog();
       
   172             break;
       
   173         case MpSongScanner::ScanInterrupted :
       
   174         default:
       
   175             //When scan interrupted (DiskEvent) just dimsiss the scanning progress note.
       
   176             break;
       
   177     }
       
   178     TX_EXIT
       
   179 }
       
   180 
       
   181 /*!
       
   182  Slot called when MpEngine emits unableToCotinueDueUSB() signal
       
   183  */
       
   184 void MpGlobalPopupHandler::launchUnableToCotinueDueUsb()
       
   185 {
       
   186     HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeInformation );
       
   187     dialog->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   188     dialog->setModal( true );
       
   189     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
   190     dialog->setObjectName( KUnableToContinueDueUSB );
       
   191     setOutstandingPopup( dialog );
       
   192     dialog->show();
       
   193 }
       
   194 
       
   195 /*!
       
   196  Slot called when MpEngine emits usbSynchronizationStarted() signal
       
   197  */
       
   198 void MpGlobalPopupHandler::launchUsbBlockingNote()
       
   199 {
       
   200     HbProgressDialog *usbBlockingNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   201     usbBlockingNote->setModal( true );
       
   202     if ( usbBlockingNote->actions().count() ) {
       
   203         //Hide cancel action.
       
   204         usbBlockingNote->actions().at( 0 )->setVisible( false );
       
   205     }
       
   206     usbBlockingNote->setDismissPolicy( HbPopup::NoDismiss );
       
   207     usbBlockingNote->setText( hbTrId( "txt_mus_info_usb_conn_in_progress" ) );
       
   208     usbBlockingNote->setAttribute( Qt::WA_DeleteOnClose );
       
   209     usbBlockingNote->setObjectName( KUsbBlockingNote );
       
   210     setOutstandingPopup( usbBlockingNote );
       
   211     usbBlockingNote->show();
       
   212 }
       
   213 
       
   214 /*!
       
   215  Slot called when MpEngine emits usbSynchronizationFinished() signal
       
   216  */
       
   217 void MpGlobalPopupHandler::closeUsbBlockingNote()
       
   218 {
       
   219     if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KUsbBlockingNote ) ) {
       
   220         HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
       
   221         dialog->cancel();
       
   222     }
       
   223 }
       
   224 
       
   225 /*!
       
   226  Slot called when MpEngine emits libraryRefreshNeeded() signal
       
   227  */
       
   228 void MpGlobalPopupHandler::launchRefreshLibraryRequest()
       
   229 {
       
   230     HbAction *action;
       
   231     HbMessageBox *promptRefresh = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
       
   232     promptRefresh->setText( hbTrId( "txt_mus_info_music_may_need_to_be_refreshed" ) );
       
   233     promptRefresh->setTimeout( HbPopup::NoTimeout );
       
   234     promptRefresh->setModal( true );
       
   235     promptRefresh->clearActions();
       
   236     action = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
   237     action->setObjectName( KYes );
       
   238     connect( action, SIGNAL( triggered() ), mMpEngine, SLOT( refreshLibrary() ) );
       
   239     promptRefresh->addAction( action );
       
   240     action = new HbAction( hbTrId( "txt_common_button_no" ) );
       
   241     action->setObjectName( KNo );
       
   242     promptRefresh->addAction( action );
       
   243     promptRefresh->setAttribute( Qt::WA_DeleteOnClose );
       
   244     promptRefresh->setObjectName( KPromptRefresh );
       
   245     setOutstandingPopup( promptRefresh );
       
   246     promptRefresh->show();
       
   247 }
       
   248 
       
   249 /*!
       
   250   Slot to launch the MTP educating info dialog
       
   251  */
       
   252 void MpGlobalPopupHandler::launchMTPInfoDialog()
       
   253 {
       
   254     TX_ENTRY
       
   255     HbDialog *dialog = new HbDialog();
       
   256     dialog->setContentWidget( new MpMtpInfoLink() );
       
   257     dialog->setModal( true );
       
   258     dialog->setDismissPolicy( HbPopup::NoDismiss);
       
   259     dialog->setTimeout( HbPopup::NoTimeout );
       
   260     HbAction *action;
       
   261     action = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
   262     action->setObjectName( KYes );
       
   263     dialog->addAction( action );
       
   264     action = new HbAction( hbTrId( "txt_common_button_no" ) );
       
   265     action->setObjectName( KNo );
       
   266     dialog->addAction( action );
       
   267     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
   268     dialog->setObjectName( KMTPInfoDialog );
       
   269     setOutstandingPopup( dialog );
       
   270     dialog->open( this, SLOT( hanldeMTPInfoDialogFinished( HbAction* ) ) );
       
   271     TX_EXIT
       
   272 }
       
   273 
       
   274 /*!
       
   275  Slot to be called when MtpInfoDialog has finished.
       
   276  */
       
   277 void MpGlobalPopupHandler::hanldeMTPInfoDialogFinished( HbAction *selectedAction )
       
   278 {
       
   279     TX_ENTRY
       
   280     if ( selectedAction && selectedAction->objectName() == KNo ) {
       
   281         MpSettingsManager::instance()->stopShowingMtpInfo();
       
   282     }
       
   283     TX_EXIT
       
   284 }
       
   285 
       
   286 /*!
       
   287  Slot to be called when a popup is getting closed. Usefull when a dialog is closed before it finishes
       
   288  (dialog not closed by a direct user action).
       
   289  */
       
   290 void MpGlobalPopupHandler::outstandingPopupClosing()
       
   291 {
       
   292     TX_ENTRY
       
   293     HbPopup *popup = qobject_cast<HbPopup *>( sender() );
       
   294     if ( popup ) {
       
   295         Q_ASSERT( popup == mOutstandingPopup );
       
   296         mOutstandingPopup = 0;
       
   297     }
       
   298     TX_EXIT
       
   299 }
       
   300 
       
   301 /*!
       
   302  \internal
       
   303  Launches Scan Finished Notification.
       
   304  */
       
   305 void MpGlobalPopupHandler::launchScanFinishedDialog( bool ok, int itemsAdded )
       
   306 {
       
   307     QString added;
       
   308     HbNotificationDialog *finishedDialog = new HbNotificationDialog();
       
   309     finishedDialog->setModal(true);
       
   310     added = hbTrId( "txt_mus_dpopinfo_ln_songs_added", itemsAdded );
       
   311     finishedDialog->setText( added );
       
   312     finishedDialog->setAttribute( Qt::WA_DeleteOnClose );
       
   313     finishedDialog->setObjectName( KScanFinished );
       
   314     // Connect aboutToClose with outstandingPopupClosing() first, and then with launchMTPInfoDialog
       
   315     // in order to get finishDialog cleared before MtpInfoDialog is launched.
       
   316     setOutstandingPopup( finishedDialog );
       
   317 
       
   318     if( ok ) {
       
   319         finishedDialog->setIcon( HbIcon( QString("qtg_large_ok") ) );
       
   320         finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_complete" ) );
       
   321         if ( MpSettingsManager::showMtpInfo() && !mMpSongScanner->isAutomaticScan() ) {
       
   322             connect( finishedDialog, SIGNAL( aboutToClose() ), this, SLOT( launchMTPInfoDialog() ) );
       
   323         }
       
   324     }
       
   325     else {
       
   326         finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
       
   327         finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) );
       
   328     }
       
   329 
       
   330     finishedDialog->show();
       
   331 }
       
   332 
       
   333 /*!
       
   334  \internal
       
   335  Launches DiskFull Notification
       
   336  */
       
   337 void MpGlobalPopupHandler::launchDiskFullDialog()
       
   338 {
       
   339     TX_ENTRY
       
   340     QString diskfull;
       
   341     diskfull = hbTrId( "txt_mus_title_refresh_cancelled" );
       
   342     diskfull.append(" ");
       
   343     diskfull.append( hbTrId( "txt_mus_info_out_of_disk_space" ) );
       
   344     HbMessageBox *diskFullDialog = new HbMessageBox();
       
   345     diskFullDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
       
   346     diskFullDialog->setText( diskfull );
       
   347     diskFullDialog->setTimeout( HbPopup::NoTimeout);
       
   348     diskFullDialog->setAttribute( Qt::WA_DeleteOnClose );
       
   349     diskFullDialog->setObjectName( KDiskFullDialog );
       
   350     setOutstandingPopup( diskFullDialog );
       
   351     diskFullDialog->show();
       
   352     TX_EXIT
       
   353 }
       
   354 
       
   355 /*!
       
   356  \internal
       
   357  sets \a popup as the current outstanding popup and cancels any other previous popup.
       
   358  */
       
   359 void MpGlobalPopupHandler::setOutstandingPopup( HbPopup *popup )
       
   360 {
       
   361     TX_ENTRY
       
   362     if ( mOutstandingPopup ) {
       
   363         TX_LOG_ARGS( "Warning: Multiple popups attempted to be displayed" );
       
   364         if ( mOutstandingPopup->objectName() == KScanFinished ) {
       
   365             disconnect( mOutstandingPopup, SIGNAL( aboutToClose() ), this, SLOT( launchMTPInfoDialog() ) );
       
   366         }
       
   367         mOutstandingPopup->close();
       
   368     }
       
   369 
       
   370     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
   371     mOutstandingPopup = popup;
       
   372     TX_EXIT
       
   373 }
       
   374