15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // System includes |
18 // System includes |
19 #include <HbProgressDialog> |
19 #include <HbProgressDialog> |
|
20 #include <QTimer> |
|
21 #include <HbLabel> |
|
22 #include <HbPushButton> |
20 |
23 |
21 // User includes |
24 // User includes |
22 #include "radiofrequencyscanner.h" |
25 #include "radiofrequencyscanner.h" |
23 #include "radiolocalization.h" |
26 #include "radioscannerengine.h" |
24 #include "radiouiengine.h" |
27 #include "radiouiengine.h" |
25 #include "radiologger.h" |
28 #include "radiologger.h" |
26 #include "radiostationmodel.h" |
29 #include "radiostationmodel.h" |
|
30 #include "radiofrequencystrip.h" |
|
31 #include "radiostationcarousel.h" |
|
32 #include "radiouiutilities.h" |
|
33 #include "radiotuningview.h" |
|
34 #include "radioxmluiloader.h" |
27 |
35 |
28 // Constants |
36 // Constants |
29 const int KExtraRoomToMaxValue = 100000; |
37 const int KExtraRoomToMaxValue = 100000; |
30 |
38 |
31 /*! |
39 /*! |
32 * |
40 * |
33 */ |
41 */ |
34 RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) : |
42 RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) : |
35 QObject( parent ), |
43 QObject( parent ), |
36 mUiEngine( uiEngine ), |
44 mUiEngine( uiEngine ), |
|
45 mInTuningView( parent->metaObject()->className() == RadioTuningView::staticMetaObject.className() ), |
|
46 mScannerEngine( mUiEngine.createScannerEngine() ), |
37 mScanningProgressNote( new HbProgressDialog( HbProgressDialog::ProgressDialog ) ), |
47 mScanningProgressNote( new HbProgressDialog( HbProgressDialog::ProgressDialog ) ), |
38 mChannelCount( 0 ), |
48 mChannelCount( 0 ), |
39 mMinFrequency( 0 ) |
49 mStripScrollTime( 0 ), |
40 { |
50 mCarouselScrollTime( 0 ) |
41 mScanningProgressNote->setModal( true ); |
51 { |
42 mScanningProgressNote->setAutoClose( true ); |
52 } |
43 |
53 |
44 mMinFrequency = mUiEngine.minFrequency(); |
54 /*! |
45 |
55 * |
46 // Add some extra to the maximum value to allow room for the station at the low band edge |
56 */ |
47 mScanningProgressNote->setRange( mMinFrequency, mUiEngine.maxFrequency() + KExtraRoomToMaxValue ); |
57 RadioFrequencyScanner::~RadioFrequencyScanner() |
48 mScanningProgressNote->setProgressValue( mMinFrequency ); |
58 { |
49 mScanningProgressNote->setText( TRANSLATE( KProgressTitleScanStations ) ); |
59 restoreUiControls(); |
50 |
60 } |
51 RadioStationModel* stationModel = &mUiEngine.model(); |
61 |
52 connectAndTest( stationModel, SIGNAL(stationAdded(RadioStation)), |
62 /*! |
|
63 * |
|
64 */ |
|
65 void RadioFrequencyScanner::startScanning( RadioXmlUiLoader& uiLoader ) |
|
66 { |
|
67 mChannelCount = 0; |
|
68 RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip(); |
|
69 RadioStationCarousel* carousel = RadioUiUtilities::carousel(); |
|
70 |
|
71 disconnect( &mUiEngine, SIGNAL(tunedToFrequency(uint,int)), |
|
72 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
|
73 disconnect( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
|
74 &mUiEngine, SLOT(tuneWithDelay(uint,int)) ); |
|
75 disconnect( carousel, SIGNAL(frequencyChanged(uint,int)), |
|
76 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
|
77 disconnect( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
|
78 carousel, SLOT(setFrequency(uint)) ); |
|
79 |
|
80 if ( mInTuningView ) { |
|
81 bool ok = false; |
|
82 uiLoader.load( DOCML::FILE_TUNINGVIEW, "scanning", &ok ); |
|
83 |
|
84 HbLabel* infoText = uiLoader.findWidget<HbLabel>( DOCML::TV_NAME_INFO_TEXT ); |
|
85 infoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter ); |
|
86 infoText->setTextWrapping( Hb::TextWordWrap ); |
|
87 |
|
88 mStripScrollTime = frequencyStrip->autoScrollTime(); |
|
89 mCarouselScrollTime = carousel->autoScrollTime(); |
|
90 |
|
91 carousel->setScanningMode( true ); |
|
92 carousel->setAutoScrollTime( 1000 ); |
|
93 frequencyStrip->setAutoScrollTime( 1100 ); |
|
94 |
|
95 connectAndTest( carousel, SIGNAL(scanAnimationFinished()), |
|
96 this, SLOT(continueScanning()) ); |
|
97 |
|
98 static_cast<RadioTuningView*>( parent() )->setScanningMode( true ); |
|
99 frequencyStrip->setScanningMode( true ); |
|
100 frequencyStrip->setFrequency( mUiEngine.minFrequency() ); |
|
101 frequencyStrip->setFrequency( mUiEngine.minFrequency() + 100 ); // scanning jamming |
|
102 } else { |
|
103 mScanningProgressNote->setModal( true ); |
|
104 mScanningProgressNote->setAutoClose( true ); |
|
105 |
|
106 carousel->setStationModel( NULL ); |
|
107 |
|
108 // Add some extra to the maximum value to allow room for the station at the low band edge |
|
109 mScanningProgressNote->setRange( mUiEngine.minFrequency(), mUiEngine.maxFrequency() + KExtraRoomToMaxValue ); |
|
110 mScanningProgressNote->setProgressValue( mUiEngine.minFrequency() ); |
|
111 mScanningProgressNote->setText( hbTrId( "txt_rad_info_searching_local_stations_please_wait" ) ); |
|
112 mScanningProgressNote->show(); |
|
113 |
|
114 connectAndTest( mScanningProgressNote, SIGNAL(cancelled()), |
|
115 this, SLOT(scanAndSavePresetsCancelled()) ); |
|
116 } |
|
117 |
|
118 connectAndTest( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), |
53 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
119 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
54 |
120 |
55 connectAndTest( &mUiEngine, SIGNAL(scanAndSaveFinished()), |
121 QTimer::singleShot( 1000, this, SLOT(delayedStart()) ); |
56 this, SLOT(scanAndSavePresetsFinished()) ); |
122 } |
57 |
123 |
58 connectAndTest( mScanningProgressNote, SIGNAL(cancelled()), |
124 /*! |
59 this, SLOT(scanAndSavePresetsCancelled()) ); |
125 * Private slot |
60 } |
126 * |
61 |
127 */ |
62 /*! |
128 void RadioFrequencyScanner::delayedStart() |
63 * |
129 { |
64 */ |
130 mScannerEngine->startScanning(); |
65 void RadioFrequencyScanner::startScanning() |
|
66 { |
|
67 mUiEngine.scanFrequencyBand(); |
|
68 mScanningProgressNote->show(); |
|
69 } |
131 } |
70 |
132 |
71 /*! |
133 /*! |
72 * Private slot |
134 * Private slot |
73 * |
135 * |
74 */ |
136 */ |
75 void RadioFrequencyScanner::updateScanAndSaveProgress( const RadioStation& station ) |
137 void RadioFrequencyScanner::updateScanAndSaveProgress( const RadioStation& station ) |
76 { |
138 { |
|
139 if ( !station.isValid() ) { |
|
140 scanAndSavePresetsFinished(); |
|
141 return; |
|
142 } |
|
143 |
77 const uint frequency = station.frequency(); |
144 const uint frequency = station.frequency(); |
78 LOG_FORMAT( "RadioFrequencyScanner::updateScanAndSaveProgress frequency: %d", frequency ); |
145 LOG_FORMAT( "RadioFrequencyScanner::updateScanAndSaveProgress frequency: %d", frequency ); |
79 |
146 |
80 // Check for special case that can happen during scanning. |
147 if ( mInTuningView ) { |
81 // If there is a valid radio station at the low frequency band edge it will be reported last after |
148 |
82 // all of the higher frequencies. We don't update the progress value here because the value would |
149 RadioUiUtilities::frequencyStrip()->setFrequency( frequency, TuneReason::Unspecified ); |
83 // be lower than the previous one. The progress value is set to maximum when the scanner finishes. |
150 RadioUiUtilities::carousel()->animateNewStation( station ); |
84 if ( frequency != mMinFrequency ) { |
151 |
85 mScanningProgressNote->setProgressValue( frequency ); |
152 } else { |
86 } |
153 // Check for special case that can happen during scanning. |
87 |
154 // If there is a valid radio station at the low frequency band edge it will be reported last after |
88 ++mChannelCount; |
155 // all of the higher frequencies. We don't update the progress value here because the value would |
89 mScanningProgressNote->setText( QString( TRANSLATE( KProgressTitleStationsFound ) ).arg( mChannelCount ) ); |
156 // be lower than the previous one. The progress value is set to maximum when the scanner finishes. |
90 } |
157 if ( frequency != mUiEngine.minFrequency() ) { |
91 |
158 mScanningProgressNote->setProgressValue( frequency ); |
92 /*! |
159 } |
93 * Private slot |
160 |
94 * |
161 ++mChannelCount; |
95 */ |
162 // mScanningProgressNote->setText( QString( TRANSLATE( KProgressTitleStationsFound ) ).arg( mChannelCount ) ); |
96 void RadioFrequencyScanner::scanAndSavePresetsFinished() |
163 mScannerEngine->continueScanning(); |
97 { |
164 } |
98 mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() ); |
165 } |
99 |
166 |
100 disconnect( &mUiEngine.model(), SIGNAL(stationAdded(RadioStation)), |
167 /*! |
101 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
168 * Private slot |
102 disconnect( &mUiEngine, SIGNAL(scanAndSaveFinished()), |
169 * |
103 this, SLOT(scanAndSavePresetsFinished()) ); |
170 */ |
104 |
171 void RadioFrequencyScanner::continueScanning() |
105 emit frequencyScannerFinished(); |
172 { |
106 mScanningProgressNote->deleteLater(); |
173 mScannerEngine->continueScanning(); |
107 deleteLater(); |
|
108 } |
174 } |
109 |
175 |
110 /*! |
176 /*! |
111 * Private slot |
177 * Private slot |
112 * |
178 * |
113 */ |
179 */ |
114 void RadioFrequencyScanner::scanAndSavePresetsCancelled() |
180 void RadioFrequencyScanner::scanAndSavePresetsCancelled() |
115 { |
181 { |
116 mUiEngine.cancelScanFrequencyBand(); |
182 mScannerEngine->cancel(); |
117 scanAndSavePresetsFinished(); |
183 scanAndSavePresetsFinished(); |
118 mScanningProgressNote = 0; |
184 mScanningProgressNote = 0; |
119 mChannelCount = 0; |
185 mChannelCount = 0; |
120 } |
186 } |
|
187 |
|
188 /*! |
|
189 * Private slot |
|
190 * |
|
191 */ |
|
192 void RadioFrequencyScanner::restoreUiControls() |
|
193 { |
|
194 RadioUiUtilities::frequencyStrip()->setScanningMode( false ); |
|
195 static_cast<RadioTuningView*>( parent() )->setScanningMode( false ); |
|
196 RadioUiUtilities::carousel()->setScanningMode( false ); |
|
197 // disconnect( RadioUiUtilities::carousel(), SIGNAL(scrollingEnded()), |
|
198 // this, SLOT(restoreUiControls()) ); |
|
199 } |
|
200 |
|
201 /*! |
|
202 * |
|
203 */ |
|
204 void RadioFrequencyScanner::scanAndSavePresetsFinished() |
|
205 { |
|
206 RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip(); |
|
207 RadioStationCarousel* carousel = RadioUiUtilities::carousel(); |
|
208 |
|
209 connectAndTest( &mUiEngine, SIGNAL(tunedToFrequency(uint,int)), |
|
210 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
|
211 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
|
212 &mUiEngine, SLOT(tuneWithDelay(uint,int)), Qt::QueuedConnection ); |
|
213 connectAndTest( carousel, SIGNAL(frequencyChanged(uint,int)), |
|
214 frequencyStrip, SLOT(setFrequency(uint,int)) ); |
|
215 connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)), |
|
216 carousel, SLOT(setFrequency(uint)) ); |
|
217 |
|
218 if ( mInTuningView ) { |
|
219 RadioStationModel& model = mUiEngine.model(); |
|
220 |
|
221 // Scroll the carousel and frequency strip through all of the scanned stations |
|
222 const int stationCount = model.rowCount(); |
|
223 if ( stationCount > 1 ) { |
|
224 // connectAndTest( carousel, SIGNAL(scrollingEnded()), |
|
225 // this, SLOT(restoreUiControls()) ); |
|
226 |
|
227 frequencyStrip->setAutoScrollTime( 1000 ); |
|
228 carousel->setAutoScrollTime( 1000 ); |
|
229 const uint frequency = model.data( model.index( 0, 0 ), RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
|
230 frequencyStrip->setFrequency( frequency ); |
|
231 |
|
232 frequencyStrip->setAutoScrollTime( mStripScrollTime ); |
|
233 carousel->setAutoScrollTime( mCarouselScrollTime ); |
|
234 } else { |
|
235 QTimer::singleShot( 100, this, SLOT(restoreUiControls()) ); |
|
236 } |
|
237 |
|
238 QTimer::singleShot( 1000, this, SLOT(deleteLater()) ); |
|
239 |
|
240 } else { |
|
241 mScannerEngine->cancel(); |
|
242 |
|
243 mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() ); |
|
244 mScanningProgressNote->deleteLater(); |
|
245 deleteLater(); |
|
246 |
|
247 disconnect( mScanningProgressNote, SIGNAL(cancelled()), |
|
248 this, SLOT(scanAndSavePresetsCancelled()) ); |
|
249 |
|
250 carousel->setStationModel( &mUiEngine.model() ); |
|
251 } |
|
252 |
|
253 disconnect( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), |
|
254 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
|
255 |
|
256 emit frequencyScannerFinished(); |
|
257 } |