radioapp/radioenginewrapper/src/radiofrequencyscanninghandler.cpp
changeset 13 46974bebc798
child 14 63aabac4416d
equal deleted inserted replaced
0:f3d95d9c00ab 13:46974bebc798
       
     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     cancel();
       
    81     QTimer::singleShot( 1000, this, SLOT(delayedStart()) );
       
    82 }
       
    83 
       
    84 /*!
       
    85  * Adds a new station that was found
       
    86  */
       
    87 void RadioFrequencyScanningHandler::addFoundStation( const uint frequency )
       
    88 {
       
    89     mEngine.mStationHandler.addScannedFrequency( frequency );
       
    90 }
       
    91 
       
    92 /*!
       
    93  * Cancels the scanning process
       
    94  */
       
    95 void RadioFrequencyScanningHandler::cancel()
       
    96 {
       
    97     mEngine.mEngineHandler->StopScan();
       
    98 }
       
    99 
       
   100 /*!
       
   101  *
       
   102  */
       
   103 void RadioFrequencyScanningHandler::delayedStart()
       
   104 {
       
   105     mEngine.mStationHandler.removeLocalStations();
       
   106 
       
   107     mLastFoundFrequency = mEngine.mEngineHandler->MinFrequency();
       
   108     mEngine.mEngineHandler->StartScan( *this );
       
   109 }