radioapp/radiouiengine/src/radioscannerengine_p.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 19 cce62ebc198e
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
     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 // User includes
       
    19 #include "radioscannerengine_p.h"
       
    20 #include "radioscannerengine.h"
       
    21 #include "radiouiengine_p.h"
       
    22 #include "radiouiengine.h"
       
    23 #include "radiostationhandlerif.h"
       
    24 #include "radioenginewrapper.h"
       
    25 #include "radiostation.h"
       
    26 #include "radiostationmodel.h"
       
    27 
       
    28 /*!
       
    29  *
       
    30  * @param scanner
       
    31  * @param uiEngine
       
    32  */
       
    33 RadioScannerEnginePrivate::RadioScannerEnginePrivate( RadioScannerEngine* scanner, RadioUiEnginePrivate& uiEngine ) :
       
    34     q_ptr( scanner ),
       
    35     mUiEngine( uiEngine ),
       
    36     mLastFoundFrequency( 0 ),
       
    37     mMutedByScanner( false ),
       
    38     mIsScanning( false )
       
    39 {
       
    40     mUiEngine.wrapper().addObserver( this );
       
    41 }
       
    42 
       
    43 /*!
       
    44  *
       
    45  */
       
    46 RadioScannerEnginePrivate::~RadioScannerEnginePrivate()
       
    47 {
       
    48     mUiEngine.wrapper().removeObserver( this );
       
    49 }
       
    50 
       
    51 /*!
       
    52  * \reimp
       
    53  */
       
    54 void RadioScannerEnginePrivate::tunedToFrequency( uint frequency, int reason )
       
    55 {
       
    56     if ( !mIsScanning ) {
       
    57         return;
       
    58     }
       
    59 
       
    60     Q_Q( RadioScannerEngine );
       
    61     if ( reason == TuneReason::StationScanInitialization ) {
       
    62         mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan );
       
    63     } else if ( reason == TuneReason::StationScan ) {
       
    64         if ( frequency == mLastFoundFrequency ) {
       
    65             // Stop scanning
       
    66             q->emitStationFound( RadioStation() );
       
    67         } else if ( frequency > mLastFoundFrequency ) {
       
    68             // Station has been found normally
       
    69             mLastFoundFrequency = frequency;
       
    70             addFrequencyAndReport( frequency );
       
    71         } else if ( frequency == mUiEngine.api().minFrequency() ) {
       
    72             // Special case. A station has been found in the mininmum frequency
       
    73             addFrequencyAndReport( frequency );
       
    74         } else {
       
    75             // Seeking looped around the frequency band. Send invalid station as indicator that the scanning should stop
       
    76             q->emitStationFound( RadioStation() );
       
    77         }
       
    78     } else {
       
    79         q->emitStationFound( RadioStation() );
       
    80     }
       
    81 }
       
    82 
       
    83 /*!
       
    84  *
       
    85  */
       
    86 void RadioScannerEnginePrivate::addFrequencyAndReport( const uint frequency )
       
    87 {
       
    88     RadioStationModel& stationModel = mUiEngine.api().stationModel();
       
    89     stationModel.stationHandlerIf().addScannedFrequency( frequency );
       
    90 
       
    91     // Return value of findFrequency() is intentionally ignored. The station was just added
       
    92     // to the model in the previous line so it should be found and if it isn't then an
       
    93     // empty station is sent with the signal and scanner will stop the scanning process.
       
    94     RadioStation station;
       
    95     stationModel.findFrequency( frequency, station );
       
    96 
       
    97     Q_Q( RadioScannerEngine );
       
    98     q->emitStationFound( station );
       
    99 }
       
   100