18 // System includes |
18 // System includes |
19 #include <HbProgressDialog> |
19 #include <HbProgressDialog> |
20 #include <QTimer> |
20 #include <QTimer> |
21 #include <HbLabel> |
21 #include <HbLabel> |
22 #include <HbPushButton> |
22 #include <HbPushButton> |
|
23 #include <HbMessageBox> |
23 |
24 |
24 // User includes |
25 // User includes |
25 #include "radiofrequencyscanner.h" |
26 #include "radiofrequencyscanner.h" |
26 #include "radioscannerengine.h" |
27 #include "radioscannerengine.h" |
27 #include "radiouiengine.h" |
28 #include "radiouiengine.h" |
28 #include "radiologger.h" |
29 #include "radiologger.h" |
29 #include "radiostationmodel.h" |
30 #include "radiostationmodel.h" |
30 #include "radiofrequencystrip.h" |
31 #include "radiofrequencystrip.h" |
31 #include "radiostationcarousel.h" |
32 #include "radiostationcarousel.h" |
32 #include "radiouiutilities.h" |
33 #include "radioutil.h" |
33 #include "radiomainview.h" |
34 #include "radiomainview.h" |
34 |
35 |
35 // Constants |
36 // Constants |
36 const int KExtraRoomToMaxValue = 100000; |
37 const int EXTRA_TO_PROGRESS_MAX_VALUE = 100000; |
|
38 const int CAROUSEL_FINISH_SCROLL_TIME = 1000; |
|
39 const int STRIP_FINISH_SCROLL_TIME = 1100; |
|
40 const int CAROUSEL_SCROLL_TIME = 1000; |
|
41 const int STRIP_SCROLL_TIME = 1100; |
|
42 const int START_DELAY = 1000; |
37 |
43 |
38 /*! |
44 /*! |
39 * |
45 * |
40 */ |
46 */ |
41 RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) : |
47 RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) : |
42 QObject( parent ), |
48 QObject( parent ), |
43 mUiEngine( uiEngine ), |
49 mUiEngine( uiEngine ), |
44 mInMainView( parent->metaObject()->className() == RadioMainView::staticMetaObject.className() ), |
50 mInMainView( parent->metaObject()->className() == RadioMainView::staticMetaObject.className() ), |
45 mScannerEngine( mUiEngine.scannerEngine() ), |
51 mScannerEngine( mUiEngine.createScannerEngine() ), |
46 mStripScrollTime( 0 ), |
52 mStripScrollTime( 0 ), |
47 mCarouselScrollTime( 0 ), |
53 mCarouselScrollTime( 0 ), |
48 mIsAlive( false ) |
54 mIsAlive( false ), |
49 { |
55 mUserCanceled( false ) |
50 RadioUiUtilities::setFrequencyScanner( this ); |
56 { |
|
57 RadioUtil::setFrequencyScanner( this ); |
|
58 |
|
59 Radio::connect( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), |
|
60 this, SLOT(updateScanProgress(RadioStation)) ); |
51 } |
61 } |
52 |
62 |
53 /*! |
63 /*! |
54 * |
64 * |
55 */ |
65 */ |
56 RadioFrequencyScanner::~RadioFrequencyScanner() |
66 RadioFrequencyScanner::~RadioFrequencyScanner() |
57 { |
67 { |
|
68 RadioUtil::setScanStatus( Scan::NotScanning ); |
58 } |
69 } |
59 |
70 |
60 /*! |
71 /*! |
61 * |
72 * |
62 */ |
73 */ |
63 void RadioFrequencyScanner::startScanning() |
74 void RadioFrequencyScanner::startScanning() |
64 { |
75 { |
65 mIsAlive = true; |
76 mIsAlive = true; |
66 RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip(); |
77 RadioFrequencyStrip* frequencyStrip = RadioUtil::frequencyStrip(); |
67 RadioStationCarousel* carousel = RadioUiUtilities::carousel(); |
78 RadioStationCarousel* carousel = RadioUtil::carousel(); |
68 |
79 |
69 if ( mInMainView ) { |
80 if ( mInMainView ) { |
|
81 |
|
82 // If this is the first time start, bring application to foreground |
|
83 if ( mUiEngine.isFirstTimeStart() ) { |
|
84 static_cast<RadioMainView*>( parent() )->bringToForeground(); |
|
85 } |
|
86 |
|
87 RadioUtil::setScanStatus( Scan::ScanningInMainView ); |
70 mStripScrollTime = frequencyStrip->autoScrollTime(); |
88 mStripScrollTime = frequencyStrip->autoScrollTime(); |
71 mCarouselScrollTime = carousel->autoScrollTime(); |
89 mCarouselScrollTime = carousel->autoScrollTime(); |
72 |
90 |
73 carousel->setScanningMode( true ); |
91 carousel->setScanningMode( true ); |
74 carousel->setAutoScrollTime( 1000 ); |
92 carousel->setAutoScrollTime( CAROUSEL_SCROLL_TIME ); |
75 frequencyStrip->setAutoScrollTime( 1100 ); |
93 frequencyStrip->setAutoScrollTime( STRIP_SCROLL_TIME ); |
76 |
94 |
77 connectAndTest( carousel, SIGNAL(scanAnimationFinished()), |
95 Radio::connect( carousel, SIGNAL(scanAnimationFinished()), |
78 this, SLOT(continueScanning()) ); |
96 this, SLOT(continueScanning()) ); |
79 |
97 |
80 static_cast<RadioMainView*>( parent() )->setScanningMode( true ); |
98 static_cast<RadioMainView*>( parent() )->setScanningMode( true ); |
81 frequencyStrip->setScanningMode( true ); |
99 frequencyStrip->setScanningMode( true ); |
82 } else { |
100 } else { |
83 carousel->setCarouselModel( NULL ); |
101 RadioUtil::setScanStatus( Scan::ScanningInStationsView ); |
84 |
102 mScanningProgressNote = new HbProgressDialog( HbProgressDialog::ProgressDialog ); |
85 mScanningProgressNote.reset( new HbProgressDialog( HbProgressDialog::ProgressDialog ) ), |
|
86 mScanningProgressNote->setModal( true ); |
103 mScanningProgressNote->setModal( true ); |
87 mScanningProgressNote->setAutoClose( true ); |
104 mScanningProgressNote->setAutoClose( true ); |
88 |
105 |
89 // Add some extra to the maximum value to allow room for the station at the low band edge |
106 // Add some extra to the maximum value to allow room for the station at the low band edge |
90 mScanningProgressNote->setRange( mUiEngine.minFrequency(), mUiEngine.maxFrequency() + KExtraRoomToMaxValue ); |
107 mScanningProgressNote->setRange( mUiEngine.minFrequency(), mUiEngine.maxFrequency() + EXTRA_TO_PROGRESS_MAX_VALUE ); |
91 mScanningProgressNote->setProgressValue( mUiEngine.minFrequency() ); |
108 mScanningProgressNote->setProgressValue( mUiEngine.minFrequency() ); |
92 mScanningProgressNote->setText( hbTrId( "txt_rad_info_searching_local_stations_please_wait" ) ); |
109 mScanningProgressNote->setText( hbTrId( "txt_rad_info_searching_local_stations_please_wait" ) ); |
93 mScanningProgressNote->show(); |
110 mScanningProgressNote->setAttribute( Qt::WA_DeleteOnClose, true ); |
94 |
111 mScanningProgressNote->open(); |
95 connectAndTest( mScanningProgressNote.data(), SIGNAL(cancelled()), |
112 |
|
113 Radio::connect( mScanningProgressNote.data(), SIGNAL(cancelled()), |
96 this, SLOT(cancelScanning()) ); |
114 this, SLOT(cancelScanning()) ); |
97 } |
115 } |
98 |
116 |
99 connectAndTest( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), |
117 QTimer::singleShot( START_DELAY, this, SLOT(delayedStart()) ); |
100 this, SLOT(updateScanProgress(RadioStation)) ); |
|
101 |
|
102 QTimer::singleShot( 1000, this, SLOT(delayedStart()) ); |
|
103 } |
118 } |
104 |
119 |
105 /*! |
120 /*! |
106 * |
121 * |
107 */ |
122 */ |
188 * |
210 * |
189 */ |
211 */ |
190 void RadioFrequencyScanner::finishScanning() |
212 void RadioFrequencyScanner::finishScanning() |
191 { |
213 { |
192 mScannerEngine->cancel(); |
214 mScannerEngine->cancel(); |
193 RadioUiUtilities::setFrequencyScanner( NULL ); |
215 RadioUtil::setScanStatus( Scan::NotScanning ); |
194 mIsAlive = false; |
216 RadioUtil::setFrequencyScanner( NULL ); |
195 RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip(); |
217 RadioFrequencyStrip* frequencyStrip = RadioUtil::frequencyStrip(); |
196 RadioStationCarousel* carousel = RadioUiUtilities::carousel(); |
218 RadioStationCarousel* carousel = RadioUtil::carousel(); |
197 |
219 |
198 if ( mInMainView ) { |
220 disconnect( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), this, 0 ); |
199 RadioStationModel& model = mUiEngine.stationModel(); |
221 |
|
222 RadioStationModel& model = mUiEngine.stationModel(); |
|
223 const int stationCount = model.rowCount(); |
|
224 |
|
225 if ( mInMainView ) { |
|
226 |
|
227 disconnect( carousel, SIGNAL(scanAnimationFinished()), this, 0 ); |
200 |
228 |
201 // Scroll the carousel and frequency strip through all of the scanned stations |
229 // Scroll the carousel and frequency strip through all of the scanned stations |
202 const int stationCount = model.rowCount(); |
|
203 if ( stationCount > 1 ) { |
230 if ( stationCount > 1 ) { |
204 frequencyStrip->setAutoScrollTime( 1000 ); |
231 frequencyStrip->setAutoScrollTime( STRIP_FINISH_SCROLL_TIME ); |
205 carousel->setAutoScrollTime( 1000 ); |
232 carousel->setAutoScrollTime( CAROUSEL_FINISH_SCROLL_TIME ); |
206 const uint frequency = model.data( model.index( 0, 0 ), RadioStationModel::RadioStationRole ).value<RadioStation>().frequency(); |
233 |
207 frequencyStrip->setFrequency( frequency, TuneReason::StationScan ); |
234 Radio::connect( carousel, SIGNAL(scrollingEnded()), |
208 carousel->setFrequency( frequency, TuneReason::StationScan ); |
235 this, SLOT(restoreUiControls()) ); |
|
236 |
|
237 const uint frequency = model.stationAt( 0 ).frequency(); |
|
238 frequencyStrip->setFrequency( frequency, TuneReason::StationScanFinalize, Scroll::Right ); |
|
239 carousel->setFrequency( frequency, TuneReason::StationScanFinalize, Scroll::Right ); |
209 |
240 |
210 frequencyStrip->setAutoScrollTime( mStripScrollTime ); |
241 frequencyStrip->setAutoScrollTime( mStripScrollTime ); |
211 carousel->setAutoScrollTime( mCarouselScrollTime ); |
242 carousel->setAutoScrollTime( mCarouselScrollTime ); |
212 } |
243 } else { |
213 |
244 const uint frequency = mUiEngine.minFrequency(); |
214 QTimer::singleShot( 100, this, SLOT(restoreUiControls()) ); |
245 frequencyStrip->setFrequency( frequency, TuneReason::Unspecified ); |
|
246 carousel->setFrequency( frequency, TuneReason::Unspecified ); |
|
247 |
|
248 if ( !mUserCanceled ) { |
|
249 HbMessageBox* box = new HbMessageBox( HbMessageBox::MessageTypeInformation ); |
|
250 box->setTimeout( HbPopup::NoTimeout ); |
|
251 box->setText( hbTrId( "txt_rad_dpophead_no_stations_found_try_searching" ) ); |
|
252 box->setDismissPolicy( HbPopup::NoDismiss ); |
|
253 box->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
254 box->open(); |
|
255 } |
|
256 |
|
257 restoreUiControls(); |
|
258 } |
215 |
259 |
216 } else { |
260 } else { |
217 mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() ); |
261 if ( !mUserCanceled ) { |
218 deleteLater(); |
262 if ( mScanningProgressNote ) { |
219 |
263 mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() ); |
220 carousel->setCarouselModel( mUiEngine.carouselModel() ); |
264 mScanningProgressNote->close(); |
221 } |
265 } |
222 |
266 |
223 disconnect( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)), |
267 if ( stationCount == 0 ) { |
224 this, SLOT(updateScanAndSaveProgress(RadioStation)) ); |
268 HbMessageBox* box = new HbMessageBox( HbMessageBox::MessageTypeInformation ); |
225 |
269 box->setTimeout( HbPopup::NoTimeout ); |
|
270 box->setText( hbTrId( "txt_rad_dpophead_no_stations_found_try_searching" ) ); |
|
271 box->setDismissPolicy( HbPopup::NoDismiss ); |
|
272 box->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
273 box->open(); |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 mIsAlive = false; |
226 emit frequencyScannerFinished(); |
279 emit frequencyScannerFinished(); |
227 } |
280 |
|
281 if ( !mInMainView ) { |
|
282 if ( mUserCanceled ) { |
|
283 deleteLater(); |
|
284 } else { |
|
285 delete this; //TODO: Remove this weird hack once the problem with deleteLater is clear |
|
286 } |
|
287 } |
|
288 } |