author | Pat Downey <patd@symbian.org> |
Wed, 23 Jun 2010 17:20:24 +0100 | |
changeset 29 | 29ba091146f4 |
parent 28 | 075425b8d9a4 |
child 32 | 189d20c34778 |
permissions | -rw-r--r-- |
24 | 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" |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
30 |
#include "radiologger.h" |
24 | 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 |
delete d_ptr; |
|
48 |
} |
|
49 |
||
50 |
/*! |
|
51 |
* Starts the scanning from minimum frequency |
|
52 |
*/ |
|
53 |
void RadioScannerEngine::startScanning() |
|
54 |
{ |
|
55 |
Q_D( RadioScannerEngine ); |
|
56 |
d->mUiEngine.cancelSeeking(); |
|
57 |
||
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
58 |
// d->mUiEngine.wrapper().setRdsEnabled( false ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
59 |
|
24 | 60 |
d->mIsScanning = true; |
61 |
||
62 |
if ( !d->mUiEngine.api().isMuted() ) { |
|
63 |
d->mUiEngine.api().setMute( true ); |
|
64 |
d->mMutedByScanner = true; |
|
65 |
} |
|
66 |
||
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
67 |
d->mUiEngine.api().emitSeekingStarted( Seek::Up ); |
24 | 68 |
|
69 |
d->mUiEngine.api().stationModel().removeAll( RadioStationModel::RemoveLocalStations ); |
|
70 |
d->mLastFoundFrequency = d->mUiEngine.api().minFrequency(); |
|
71 |
||
72 |
if ( d->mUiEngine.wrapper().currentFrequency() == d->mLastFoundFrequency ) { |
|
73 |
// Engine was already at the minimun frequency so start scanning |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
74 |
d->mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan ); |
24 | 75 |
} else { |
76 |
// Engine must be initialized to minimum frequency before scanning can start |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
77 |
d->mUiEngine.wrapper().setFrequency( d->mLastFoundFrequency, TuneReason::StationScanInitialization ); |
24 | 78 |
} |
79 |
} |
|
80 |
||
81 |
/*! |
|
82 |
* Continues the scanning upwards from current frequency |
|
83 |
*/ |
|
84 |
void RadioScannerEngine::continueScanning() |
|
85 |
{ |
|
86 |
Q_D( RadioScannerEngine ); |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
87 |
d->mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan ); |
24 | 88 |
} |
89 |
||
90 |
/*! |
|
91 |
* Checks if the scanning is ongoing |
|
92 |
*/ |
|
93 |
bool RadioScannerEngine::isScanning() const |
|
94 |
{ |
|
95 |
Q_D( const RadioScannerEngine ); |
|
96 |
return d->mIsScanning; |
|
97 |
} |
|
98 |
||
99 |
/*! |
|
100 |
* Cancels the scanning process |
|
101 |
*/ |
|
102 |
void RadioScannerEngine::cancel() |
|
103 |
{ |
|
104 |
Q_D( RadioScannerEngine ); |
|
105 |
if ( isScanning() ) { |
|
106 |
d->mIsScanning = false; |
|
107 |
d->mUiEngine.cancelSeeking(); |
|
108 |
} |
|
109 |
||
110 |
if ( d->mMutedByScanner ) { |
|
111 |
d->mUiEngine.api().setMute( false ); |
|
112 |
d->mMutedByScanner = false; |
|
113 |
} |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
114 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
115 |
// d->mUiEngine.wrapper().setRdsEnabled( true ); |
24 | 116 |
} |
117 |
||
118 |
/*! |
|
119 |
* Adds a new station that was found |
|
120 |
*/ |
|
121 |
void RadioScannerEngine::addScannedFrequency( const uint frequency ) |
|
122 |
{ |
|
123 |
Q_D( RadioScannerEngine ); |
|
124 |
if ( frequency > d->mLastFoundFrequency ) { |
|
125 |
// Station has been found normally |
|
126 |
d->mLastFoundFrequency = frequency; |
|
127 |
d->addFrequencyAndReport( frequency ); |
|
128 |
} else if ( frequency == d->mUiEngine.api().minFrequency() ) { |
|
129 |
// Special case. A station has been found in the mininmum frequency |
|
130 |
d->addFrequencyAndReport( frequency ); |
|
131 |
} else { |
|
132 |
// Seeking looped around the frequency band. Send invalid station as indicator that the scanning should stop |
|
133 |
emit stationFound( RadioStation() ); |
|
134 |
} |
|
135 |
} |
|
136 |
||
137 |
/*! |
|
138 |
* |
|
139 |
*/ |
|
140 |
void RadioScannerEngine::emitStationFound( const RadioStation& station ) |
|
141 |
{ |
|
142 |
emit stationFound( station ); |
|
143 |
} |