mpviewplugins/mpcollectionviewplugin/src/mpcollectionsongscanner.cpp
changeset 19 4e84c994a771
equal deleted inserted replaced
5:2a40e88564c8 19:4e84c994a771
       
     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 collection song scanner.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbprogressnote.h>
       
    19 
       
    20 #include "mpcollectionsongscanner.h"
       
    21 #include "mpmpxframeworkwrapper.h"
       
    22 #include "mptrace.h"
       
    23 
       
    24 /*!
       
    25     \class MpCollectionSongScanner
       
    26     \brief Music Player collection song scanner.
       
    27 
       
    28     Song scanner interfaces with MPX Harvesting Framework to harvest
       
    29     music files in the device.
       
    30 */
       
    31 
       
    32 /*!
       
    33  \fn void scanEnd()
       
    34 
       
    35  This signal is emitted when scanning is ended.
       
    36 
       
    37  \sa scan()
       
    38 */
       
    39 
       
    40 /*!
       
    41  Constructs the collection song scanner.
       
    42  */
       
    43 MpCollectionSongScanner::MpCollectionSongScanner( MpMpxFrameworkWrapper *wrapper, QObject *parent )
       
    44     : QObject(parent),
       
    45       mMpxWrapper(wrapper),
       
    46       mScanning(false),
       
    47       mScanProgressNote(0)
       
    48 {
       
    49     TX_ENTRY
       
    50     connect( mMpxWrapper, SIGNAL(scanStarted()), this, SLOT(handleScanStarted()) );
       
    51     connect( mMpxWrapper, SIGNAL(scanEnded()), this, SLOT(handleScanEnded()) );
       
    52     connect( mMpxWrapper, SIGNAL(scanCountChanged(int)), this, SLOT(handleScanCountChanged(int)) );
       
    53     TX_EXIT
       
    54 }
       
    55 
       
    56 /*!
       
    57  Destructs the collection song scanner.
       
    58  */
       
    59 MpCollectionSongScanner::~MpCollectionSongScanner()
       
    60 {
       
    61     TX_ENTRY
       
    62     if ( mScanProgressNote ) {
       
    63         delete mScanProgressNote;
       
    64     }
       
    65     TX_EXIT
       
    66 }
       
    67 
       
    68 /*!
       
    69  Initiates song scanning.
       
    70  */
       
    71 void MpCollectionSongScanner::scan()
       
    72 {
       
    73     mScanning = true;
       
    74     mMpxWrapper->scan();
       
    75 }
       
    76 
       
    77 /*!
       
    78  Returns true if scanning is ongoing.
       
    79  */
       
    80 bool MpCollectionSongScanner::isScanning()
       
    81 {
       
    82     return mScanning;
       
    83 }
       
    84 
       
    85 /*!
       
    86  Cancels ongoing song scanning, if any.
       
    87 
       
    88  \sa scan()
       
    89  */
       
    90 void MpCollectionSongScanner::cancelScan()
       
    91 {
       
    92     if ( mScanning ) {
       
    93         mScanning = false;
       
    94         mMpxWrapper->cancelScan();
       
    95     }
       
    96 }
       
    97 
       
    98 /*!
       
    99  Slot called upon notification from MPX Harvesting FW indicating start of
       
   100  scanning process.
       
   101  */
       
   102 void MpCollectionSongScanner::handleScanStarted()
       
   103 {
       
   104     if ( !mScanProgressNote ) {
       
   105         mScanProgressNote = new HbProgressNote(HbProgressNote::WaitNote);
       
   106         connect(mScanProgressNote, SIGNAL(cancelled()), this, SLOT(cancelScan()));
       
   107     }
       
   108     mScanProgressNote->setText( QString("Scanning...") );
       
   109     mScanProgressNote->show();
       
   110 }
       
   111 
       
   112 /*!
       
   113  Slot called upon notification from MPX Harvesting FW indicating end of
       
   114  scanning process.
       
   115  */
       
   116 void MpCollectionSongScanner::handleScanEnded()
       
   117 {
       
   118     if ( mScanning ) {
       
   119         mScanning = false;
       
   120         mScanProgressNote->cancel();
       
   121     }
       
   122     emit scanEnded();
       
   123 }
       
   124 
       
   125 /*!
       
   126  Slot called upon notification from MPX Harvesting FW indicating the number of
       
   127  songs scanned so far.
       
   128  */
       
   129 void MpCollectionSongScanner::handleScanCountChanged(int count)
       
   130 {
       
   131     QString added;
       
   132     added.setNum(count);
       
   133     added.append(" file(s) added.");
       
   134     mScanProgressNote->setText(added);
       
   135 }
       
   136