radioapp/radioenginewrapper/src/radiofrequencyscanninghandler.cpp
changeset 16 f54ebcfc1b80
parent 14 63aabac4416d
child 17 2cf3bab7c5c6
child 19 afea38384506
equal deleted inserted replaced
14:63aabac4416d 16:f54ebcfc1b80
     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 "radiofrequencyscanninghandler.h"
       
    23 #include "radioenginewrapper_p.h"
       
    24 #include "cradioenginehandler.h"
       
    25 #include "radiostationhandlerif.h"
       
    26 
       
    27 /*!
       
    28  *
       
    29  */
       
    30 RadioFrequencyScanningHandler::RadioFrequencyScanningHandler( RadioEngineWrapperPrivate& radioEngine ) :
       
    31     QObject( 0 ),
       
    32     mEngine( radioEngine ),
       
    33     mLastFoundFrequency( 0 )
       
    34 {
       
    35 }
       
    36 
       
    37 /*!
       
    38  * From MRadioScanObserver
       
    39  *
       
    40  */
       
    41 void RadioFrequencyScanningHandler::ScanFrequencyEventL( TUint32 aFrequency )
       
    42 {
       
    43     // The scanning logic starts from the minimun frequency and advances as long as
       
    44     // the found frequency is higher than the last one. When it loops around from the highest
       
    45     // frequency back to the lowest one we check if it stops at the minimun frequency and
       
    46     // add the station there. This logic handles the special case where there is a station in the
       
    47     // minimum frequency, but does not work if there are no stations at all. The adaptation has a
       
    48     // timeout timer that stops the scanning if nothing is found and reports the scanning start
       
    49     // frequency which is this case will be the minimum frequency. In that case this logic will
       
    50     // assume that it was an audible station and adds it.
       
    51 
       
    52     uint frequency = static_cast<uint>( aFrequency );
       
    53     mEngine.mStationHandler.setCurrentStation( frequency );
       
    54     if ( frequency > mLastFoundFrequency ) {
       
    55         mLastFoundFrequency = frequency;
       
    56         addFoundStation( frequency );
       
    57     } else if ( frequency == mEngine.mEngineHandler->MinFrequency() ) {
       
    58         // Special case. A station has been found in the mininmum frequency
       
    59         addFoundStation( frequency );
       
    60     }
       
    61 }
       
    62 
       
    63 /*!
       
    64  * From MRadioScanObserver
       
    65  *
       
    66  */
       
    67 void RadioFrequencyScanningHandler::ScanCompletedEventL( TInt aError )
       
    68 {
       
    69     Q_UNUSED( aError )
       
    70   
       
    71     mEngine.frequencyScannerFinished(); // Causes the scanner to be deleted so nothing can be done after this
       
    72 }
       
    73 
       
    74 
       
    75 /*!
       
    76  * Starts the scanning
       
    77  */
       
    78 void RadioFrequencyScanningHandler::startScanning( bool muted )
       
    79 {
       
    80     Q_UNUSED( muted )
       
    81     cancel();
       
    82     QTimer::singleShot( 1000, this, SLOT(delayedStart()) );
       
    83 }
       
    84 
       
    85 /*!
       
    86  * Adds a new station that was found
       
    87  */
       
    88 void RadioFrequencyScanningHandler::addFoundStation( const uint frequency )
       
    89 {
       
    90     mEngine.mStationHandler.addScannedFrequency( frequency );
       
    91 }
       
    92 
       
    93 /*!
       
    94  * Cancels the scanning process
       
    95  */
       
    96 void RadioFrequencyScanningHandler::cancel()
       
    97 {
       
    98     mEngine.mEngineHandler->StopScan();
       
    99 }
       
   100 
       
   101 /*!
       
   102  *
       
   103  */
       
   104 void RadioFrequencyScanningHandler::delayedStart()
       
   105 {
       
   106     mEngine.mStationHandler.removeLocalStations();
       
   107 
       
   108     mLastFoundFrequency = mEngine.mEngineHandler->MinFrequency();
       
   109     mEngine.mEngineHandler->StartScan( *this );
       
   110 }