radioapp/radiouiengine/src/radioscannerengine.cpp
branchRCL_3
changeset 45 cce62ebc198e
equal deleted inserted replaced
43:1a6714c53019 45:cce62ebc198e
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QTimer>
       
    20 
       
    21 // User includes
       
    22 #include "radioscannerengine.h"
       
    23 #include "radioscannerengine_p.h"
       
    24 #include "radiouiengine.h"
       
    25 #include "radiouiengine_p.h"
       
    26 #include "radioenginewrapper.h"
       
    27 #include "radiostationhandlerif.h"
       
    28 #include "radiostationmodel.h"
       
    29 #include "radiostation.h"
       
    30 #include "radiologger.h"
       
    31 
       
    32 /*!
       
    33  *
       
    34  */
       
    35 RadioScannerEngine::RadioScannerEngine( RadioUiEnginePrivate& uiEngine ) :
       
    36     QObject( &uiEngine.api() ),
       
    37     d_ptr( new RadioScannerEnginePrivate( this, uiEngine ) )
       
    38 {
       
    39 }
       
    40 
       
    41 /*!
       
    42  *
       
    43  */
       
    44 RadioScannerEngine::~RadioScannerEngine()
       
    45 {
       
    46     cancel();
       
    47 }
       
    48 
       
    49 /*!
       
    50  * Starts the scanning from minimum frequency
       
    51  */
       
    52 void RadioScannerEngine::startScanning()
       
    53 {
       
    54     Q_D( RadioScannerEngine );
       
    55     d->mUiEngine.cancelSeeking();
       
    56 
       
    57 //    d->mUiEngine.wrapper().setRdsEnabled( false );
       
    58 
       
    59     d->mIsScanning = true;
       
    60 
       
    61     if ( !d->mUiEngine.api().isMuted() ) {
       
    62         d->mUiEngine.api().setMute( true );
       
    63         d->mMutedByScanner = true;
       
    64     }
       
    65 
       
    66     d->mUiEngine.api().emitSeekingStarted( Seek::Up );
       
    67 
       
    68     d->mUiEngine.api().stationModel().removeAll( RadioStationModel::RemoveLocalStations );
       
    69     d->mLastFoundFrequency = d->mUiEngine.api().minFrequency();
       
    70 
       
    71     if ( d->mUiEngine.wrapper().currentFrequency() == d->mLastFoundFrequency ) {
       
    72         // Engine was already at the minimun frequency so start scanning
       
    73         d->mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan );
       
    74     } else {
       
    75         // Engine must be initialized to minimum frequency before scanning can start
       
    76         d->mUiEngine.wrapper().setFrequency( d->mLastFoundFrequency, TuneReason::StationScanInitialization );
       
    77     }
       
    78 }
       
    79 
       
    80 /*!
       
    81  * Continues the scanning upwards from current frequency
       
    82  */
       
    83 void RadioScannerEngine::continueScanning()
       
    84 {
       
    85     Q_D( RadioScannerEngine );
       
    86     d->mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan );
       
    87 }
       
    88 
       
    89 /*!
       
    90  * Checks if the scanning is ongoing
       
    91  */
       
    92 bool RadioScannerEngine::isScanning() const
       
    93 {
       
    94     Q_D( const RadioScannerEngine );
       
    95     return d->mIsScanning;
       
    96 }
       
    97 
       
    98 /*!
       
    99  * Cancels the scanning process
       
   100  */
       
   101 void RadioScannerEngine::cancel()
       
   102 {
       
   103     Q_D( RadioScannerEngine );
       
   104     if ( isScanning() ) {
       
   105         d->mIsScanning = false;
       
   106         d->mUiEngine.cancelSeeking();
       
   107     }
       
   108 
       
   109     if ( d->mMutedByScanner ) {
       
   110         d->mUiEngine.api().setMute( false );
       
   111         d->mMutedByScanner = false;
       
   112     }
       
   113 
       
   114 //    d->mUiEngine.wrapper().setRdsEnabled( true );
       
   115 }
       
   116 
       
   117 /*!
       
   118  * Adds a new station that was found
       
   119  */
       
   120 void RadioScannerEngine::addScannedFrequency( const uint frequency )
       
   121 {
       
   122     Q_D( RadioScannerEngine );
       
   123     if ( frequency > d->mLastFoundFrequency ) {
       
   124         // Station has been found normally
       
   125         d->mLastFoundFrequency = frequency;
       
   126         d->addFrequencyAndReport( frequency );
       
   127     } else if ( frequency == d->mUiEngine.api().minFrequency() ) {
       
   128         // Special case. A station has been found in the mininmum frequency
       
   129         d->addFrequencyAndReport( frequency );
       
   130     } else {
       
   131         // Seeking looped around the frequency band. Send invalid station as indicator that the scanning should stop
       
   132         emit stationFound( RadioStation() );
       
   133     }
       
   134 }
       
   135 
       
   136 /*!
       
   137  *
       
   138  */
       
   139 void RadioScannerEngine::emitStationFound( const RadioStation& station )
       
   140 {
       
   141     emit stationFound( station );
       
   142 }