mpengine/src/mpsongscanner.cpp
changeset 20 82baf59ce8dd
child 22 ecf06a08d4d9
equal deleted inserted replaced
19:4e84c994a771 20:82baf59ce8dd
       
     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 song scanner.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbprogressdialog.h>
       
    19 #include <hbnotificationdialog.h>
       
    20 #include <hblabel.h>
       
    21 #include <hbfontspec.h>
       
    22 
       
    23 #include "mpsongscanner.h"
       
    24 #include "mpmpxframeworkwrapper.h"
       
    25 #include "mptrace.h"
       
    26 
       
    27 /*!
       
    28     \class MpSongScanner
       
    29     \brief Music Player song scanner.
       
    30 
       
    31     Song scanner interfaces with MPX Harvesting Framework to harvest
       
    32     music files in the device.
       
    33 */
       
    34 
       
    35 /*!
       
    36  \fn void scanEnd()
       
    37 
       
    38  This signal is emitted when scanning is ended.
       
    39 
       
    40  \sa scan()
       
    41 */
       
    42 
       
    43 /*!
       
    44  Constructs the song scanner.
       
    45  */
       
    46 MpSongScanner::MpSongScanner( MpMpxFrameworkWrapper *wrapper, QObject *parent )
       
    47     : QObject( parent ),
       
    48       mMpxWrapper(wrapper),
       
    49       mScanProgressNote(0),
       
    50       mScanning(false)
       
    51 {
       
    52     TX_ENTRY
       
    53     connect( mMpxWrapper, SIGNAL(scanStarted()), this, SLOT(handleScanStarted()) );
       
    54     connect( mMpxWrapper, SIGNAL(scanEnded( int, int )), this, SLOT(handleScanEnded( int, int )) );
       
    55     connect( mMpxWrapper, SIGNAL(scanCountChanged(int)), this, SLOT(handleScanCountChanged(int)) );
       
    56     TX_EXIT
       
    57 }
       
    58 
       
    59 /*!
       
    60  Destructs the song scanner.
       
    61  */
       
    62 MpSongScanner::~MpSongScanner()
       
    63 {
       
    64     TX_LOG
       
    65 }
       
    66 
       
    67 /*!
       
    68  Initiates song scanning.
       
    69  */
       
    70 void MpSongScanner::scan()
       
    71 {
       
    72     if ( !mScanning ) {
       
    73         mScanning = true;
       
    74         mMpxWrapper->scan();
       
    75     }
       
    76 }
       
    77 
       
    78 /*!
       
    79  Returns true if scanning is ongoing.
       
    80  */
       
    81 bool MpSongScanner::isScanning()
       
    82 {
       
    83     return mScanning;
       
    84 }
       
    85 
       
    86 /*!
       
    87  Cancels ongoing song scanning, if any.
       
    88 
       
    89  \sa scan()
       
    90  */
       
    91 void MpSongScanner::cancelScan()
       
    92 {
       
    93     if ( mScanning ) {
       
    94         mScanning = false;
       
    95         mMpxWrapper->cancelScan();
       
    96     }
       
    97 }
       
    98 
       
    99 /*!
       
   100  Slot called upon notification from MPX Harvesting FW indicating start of
       
   101  scanning process.
       
   102  */
       
   103 void MpSongScanner::handleScanStarted()
       
   104 {
       
   105     if ( !mScanProgressNote ) {
       
   106         mScanProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   107         connect( mScanProgressNote, SIGNAL( cancelled() ), this, SLOT( cancelScan() ) );
       
   108         connect( mScanProgressNote, SIGNAL( aboutToClose() ), this, SLOT( handleProgressNoteClosing() ) );
       
   109     }
       
   110     mScanProgressNote->setModal( true );
       
   111     HbLabel *title = new HbLabel( hbTrId( "txt_mus_title_refreshing" ) );
       
   112     title->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   113 
       
   114     mScanProgressNote->setHeadingWidget( title );
       
   115     mScanProgressNote->setTextAlignment( Qt::AlignCenter );
       
   116     mScanProgressNote->setText( QString("") );
       
   117     mScanProgressNote->setAttribute( Qt::WA_DeleteOnClose );
       
   118     mScanProgressNote->show();
       
   119 }
       
   120 
       
   121 /*!
       
   122  Slot called upon notification from MPX Harvesting FW indicating end of
       
   123  scanning process.
       
   124  */
       
   125 void MpSongScanner::handleScanEnded( int numItemsAdded, int error )
       
   126 {
       
   127     QString added;
       
   128 
       
   129     HbNotificationDialog *finishedDialog = new HbNotificationDialog();
       
   130     finishedDialog->setModal(true);
       
   131     finishedDialog->setAttribute( Qt::WA_DeleteOnClose );
       
   132 
       
   133     added = hbTrId( "txt_mus_dpopinfo_ln_songs_added", numItemsAdded );
       
   134     finishedDialog->setText( added );
       
   135 
       
   136     if( error < 0) {
       
   137         if ( mScanProgressNote ) {     
       
   138             mScanProgressNote->cancel();
       
   139         }
       
   140         finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
       
   141         finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) );
       
   142     }
       
   143     else if ( mScanning ) {
       
   144         if ( mScanProgressNote ) {     
       
   145             mScanProgressNote->cancel();
       
   146         }
       
   147         finishedDialog->setIcon( HbIcon( QString("qtg_large_ok") ) );
       
   148         finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_complete" ) );
       
   149     }
       
   150     else {
       
   151         finishedDialog->setIcon( HbIcon( QString("qtg_small_fail") ) );
       
   152         finishedDialog->setTitle( hbTrId( "txt_mus_dpophead_refresh_cancelled" ) );
       
   153     }
       
   154     mScanning = false;
       
   155     finishedDialog->show();
       
   156 }
       
   157 
       
   158 /*!
       
   159  Slot called upon notification from MPX Harvesting FW indicating the number of
       
   160  songs scanned so far.
       
   161  */
       
   162 void MpSongScanner::handleScanCountChanged(int count)
       
   163 {
       
   164     QString added;
       
   165 
       
   166     added = hbTrId( "txt_mus_info_ln_songs_added" , count );
       
   167     if ( mScanProgressNote ) {
       
   168         mScanProgressNote->setText( added );
       
   169     }
       
   170 }
       
   171 
       
   172 /*!
       
   173  Slot to be called when disk event is received from MPX framework.
       
   174  */
       
   175 void MpSongScanner::handleDiskEvent( MpxDiskEvents event )
       
   176 {
       
   177     Q_UNUSED( event );
       
   178     if ( mScanning ) {
       
   179         if ( mScanProgressNote ) {
       
   180             mScanProgressNote->cancel();
       
   181         }
       
   182         mScanning = false;
       
   183         // AK - Should we show a dialog?
       
   184     }
       
   185     TX_EXIT
       
   186 }
       
   187 
       
   188 /*!
       
   189  Slot used to clear mScanProgressNote when dialog is closing.
       
   190  */
       
   191 void MpSongScanner::handleProgressNoteClosing()
       
   192 {
       
   193     mScanProgressNote = 0;
       
   194 }
       
   195