--- a/radioapp/radiowidgets/src/radiofrequencyscanner.cpp Fri Apr 16 14:58:55 2010 +0300
+++ b/radioapp/radiowidgets/src/radiofrequencyscanner.cpp Mon May 03 12:31:41 2010 +0300
@@ -17,13 +17,21 @@
// System includes
#include <HbProgressDialog>
+#include <QTimer>
+#include <HbLabel>
+#include <HbPushButton>
// User includes
#include "radiofrequencyscanner.h"
-#include "radiolocalization.h"
+#include "radioscannerengine.h"
#include "radiouiengine.h"
#include "radiologger.h"
#include "radiostationmodel.h"
+#include "radiofrequencystrip.h"
+#include "radiostationcarousel.h"
+#include "radiouiutilities.h"
+#include "radiotuningview.h"
+#include "radioxmluiloader.h"
// Constants
const int KExtraRoomToMaxValue = 100000;
@@ -34,38 +42,92 @@
RadioFrequencyScanner::RadioFrequencyScanner( RadioUiEngine& uiEngine, QObject* parent ) :
QObject( parent ),
mUiEngine( uiEngine ),
+ mInTuningView( parent->metaObject()->className() == RadioTuningView::staticMetaObject.className() ),
+ mScannerEngine( mUiEngine.createScannerEngine() ),
mScanningProgressNote( new HbProgressDialog( HbProgressDialog::ProgressDialog ) ),
mChannelCount( 0 ),
- mMinFrequency( 0 )
+ mStripScrollTime( 0 ),
+ mCarouselScrollTime( 0 )
{
- mScanningProgressNote->setModal( true );
- mScanningProgressNote->setAutoClose( true );
-
- mMinFrequency = mUiEngine.minFrequency();
+}
- // Add some extra to the maximum value to allow room for the station at the low band edge
- mScanningProgressNote->setRange( mMinFrequency, mUiEngine.maxFrequency() + KExtraRoomToMaxValue );
- mScanningProgressNote->setProgressValue( mMinFrequency );
- mScanningProgressNote->setText( TRANSLATE( KProgressTitleScanStations ) );
-
- RadioStationModel* stationModel = &mUiEngine.model();
- connectAndTest( stationModel, SIGNAL(stationAdded(RadioStation)),
- this, SLOT(updateScanAndSaveProgress(RadioStation)) );
-
- connectAndTest( &mUiEngine, SIGNAL(scanAndSaveFinished()),
- this, SLOT(scanAndSavePresetsFinished()) );
-
- connectAndTest( mScanningProgressNote, SIGNAL(cancelled()),
- this, SLOT(scanAndSavePresetsCancelled()) );
+/*!
+ *
+ */
+RadioFrequencyScanner::~RadioFrequencyScanner()
+{
+ restoreUiControls();
}
/*!
*
*/
-void RadioFrequencyScanner::startScanning()
+void RadioFrequencyScanner::startScanning( RadioXmlUiLoader& uiLoader )
{
- mUiEngine.scanFrequencyBand();
- mScanningProgressNote->show();
+ mChannelCount = 0;
+ RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip();
+ RadioStationCarousel* carousel = RadioUiUtilities::carousel();
+
+ disconnect( &mUiEngine, SIGNAL(tunedToFrequency(uint,int)),
+ frequencyStrip, SLOT(setFrequency(uint,int)) );
+ disconnect( frequencyStrip, SIGNAL(frequencyChanged(uint,int)),
+ &mUiEngine, SLOT(tuneWithDelay(uint,int)) );
+ disconnect( carousel, SIGNAL(frequencyChanged(uint,int)),
+ frequencyStrip, SLOT(setFrequency(uint,int)) );
+ disconnect( frequencyStrip, SIGNAL(frequencyChanged(uint,int)),
+ carousel, SLOT(setFrequency(uint)) );
+
+ if ( mInTuningView ) {
+ bool ok = false;
+ uiLoader.load( DOCML::FILE_TUNINGVIEW, "scanning", &ok );
+
+ HbLabel* infoText = uiLoader.findWidget<HbLabel>( DOCML::TV_NAME_INFO_TEXT );
+ infoText->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
+ infoText->setTextWrapping( Hb::TextWordWrap );
+
+ mStripScrollTime = frequencyStrip->autoScrollTime();
+ mCarouselScrollTime = carousel->autoScrollTime();
+
+ carousel->setScanningMode( true );
+ carousel->setAutoScrollTime( 1000 );
+ frequencyStrip->setAutoScrollTime( 1100 );
+
+ connectAndTest( carousel, SIGNAL(scanAnimationFinished()),
+ this, SLOT(continueScanning()) );
+
+ static_cast<RadioTuningView*>( parent() )->setScanningMode( true );
+ frequencyStrip->setScanningMode( true );
+ frequencyStrip->setFrequency( mUiEngine.minFrequency() );
+ frequencyStrip->setFrequency( mUiEngine.minFrequency() + 100 ); // scanning jamming
+ } else {
+ mScanningProgressNote->setModal( true );
+ mScanningProgressNote->setAutoClose( true );
+
+ carousel->setStationModel( NULL );
+
+ // Add some extra to the maximum value to allow room for the station at the low band edge
+ mScanningProgressNote->setRange( mUiEngine.minFrequency(), mUiEngine.maxFrequency() + KExtraRoomToMaxValue );
+ mScanningProgressNote->setProgressValue( mUiEngine.minFrequency() );
+ mScanningProgressNote->setText( hbTrId( "txt_rad_info_searching_local_stations_please_wait" ) );
+ mScanningProgressNote->show();
+
+ connectAndTest( mScanningProgressNote, SIGNAL(cancelled()),
+ this, SLOT(scanAndSavePresetsCancelled()) );
+ }
+
+ connectAndTest( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)),
+ this, SLOT(updateScanAndSaveProgress(RadioStation)) );
+
+ QTimer::singleShot( 1000, this, SLOT(delayedStart()) );
+}
+
+/*!
+ * Private slot
+ *
+ */
+void RadioFrequencyScanner::delayedStart()
+{
+ mScannerEngine->startScanning();
}
/*!
@@ -74,37 +136,41 @@
*/
void RadioFrequencyScanner::updateScanAndSaveProgress( const RadioStation& station )
{
+ if ( !station.isValid() ) {
+ scanAndSavePresetsFinished();
+ return;
+ }
+
const uint frequency = station.frequency();
LOG_FORMAT( "RadioFrequencyScanner::updateScanAndSaveProgress frequency: %d", frequency );
- // Check for special case that can happen during scanning.
- // If there is a valid radio station at the low frequency band edge it will be reported last after
- // all of the higher frequencies. We don't update the progress value here because the value would
- // be lower than the previous one. The progress value is set to maximum when the scanner finishes.
- if ( frequency != mMinFrequency ) {
- mScanningProgressNote->setProgressValue( frequency );
- }
+ if ( mInTuningView ) {
+
+ RadioUiUtilities::frequencyStrip()->setFrequency( frequency, TuneReason::Unspecified );
+ RadioUiUtilities::carousel()->animateNewStation( station );
- ++mChannelCount;
- mScanningProgressNote->setText( QString( TRANSLATE( KProgressTitleStationsFound ) ).arg( mChannelCount ) );
+ } else {
+ // Check for special case that can happen during scanning.
+ // If there is a valid radio station at the low frequency band edge it will be reported last after
+ // all of the higher frequencies. We don't update the progress value here because the value would
+ // be lower than the previous one. The progress value is set to maximum when the scanner finishes.
+ if ( frequency != mUiEngine.minFrequency() ) {
+ mScanningProgressNote->setProgressValue( frequency );
+ }
+
+ ++mChannelCount;
+// mScanningProgressNote->setText( QString( TRANSLATE( KProgressTitleStationsFound ) ).arg( mChannelCount ) );
+ mScannerEngine->continueScanning();
+ }
}
/*!
* Private slot
*
*/
-void RadioFrequencyScanner::scanAndSavePresetsFinished()
+void RadioFrequencyScanner::continueScanning()
{
- mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() );
-
- disconnect( &mUiEngine.model(), SIGNAL(stationAdded(RadioStation)),
- this, SLOT(updateScanAndSaveProgress(RadioStation)) );
- disconnect( &mUiEngine, SIGNAL(scanAndSaveFinished()),
- this, SLOT(scanAndSavePresetsFinished()) );
-
- emit frequencyScannerFinished();
- mScanningProgressNote->deleteLater();
- deleteLater();
+ mScannerEngine->continueScanning();
}
/*!
@@ -113,8 +179,79 @@
*/
void RadioFrequencyScanner::scanAndSavePresetsCancelled()
{
- mUiEngine.cancelScanFrequencyBand();
+ mScannerEngine->cancel();
scanAndSavePresetsFinished();
mScanningProgressNote = 0;
mChannelCount = 0;
}
+
+/*!
+ * Private slot
+ *
+ */
+void RadioFrequencyScanner::restoreUiControls()
+{
+ RadioUiUtilities::frequencyStrip()->setScanningMode( false );
+ static_cast<RadioTuningView*>( parent() )->setScanningMode( false );
+ RadioUiUtilities::carousel()->setScanningMode( false );
+// disconnect( RadioUiUtilities::carousel(), SIGNAL(scrollingEnded()),
+// this, SLOT(restoreUiControls()) );
+}
+
+/*!
+ *
+ */
+void RadioFrequencyScanner::scanAndSavePresetsFinished()
+{
+ RadioFrequencyStrip* frequencyStrip = RadioUiUtilities::frequencyStrip();
+ RadioStationCarousel* carousel = RadioUiUtilities::carousel();
+
+ connectAndTest( &mUiEngine, SIGNAL(tunedToFrequency(uint,int)),
+ frequencyStrip, SLOT(setFrequency(uint,int)) );
+ connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)),
+ &mUiEngine, SLOT(tuneWithDelay(uint,int)), Qt::QueuedConnection );
+ connectAndTest( carousel, SIGNAL(frequencyChanged(uint,int)),
+ frequencyStrip, SLOT(setFrequency(uint,int)) );
+ connectAndTest( frequencyStrip, SIGNAL(frequencyChanged(uint,int)),
+ carousel, SLOT(setFrequency(uint)) );
+
+ if ( mInTuningView ) {
+ RadioStationModel& model = mUiEngine.model();
+
+ // Scroll the carousel and frequency strip through all of the scanned stations
+ const int stationCount = model.rowCount();
+ if ( stationCount > 1 ) {
+// connectAndTest( carousel, SIGNAL(scrollingEnded()),
+// this, SLOT(restoreUiControls()) );
+
+ frequencyStrip->setAutoScrollTime( 1000 );
+ carousel->setAutoScrollTime( 1000 );
+ const uint frequency = model.data( model.index( 0, 0 ), RadioStationModel::RadioStationRole ).value<RadioStation>().frequency();
+ frequencyStrip->setFrequency( frequency );
+
+ frequencyStrip->setAutoScrollTime( mStripScrollTime );
+ carousel->setAutoScrollTime( mCarouselScrollTime );
+ } else {
+ QTimer::singleShot( 100, this, SLOT(restoreUiControls()) );
+ }
+
+ QTimer::singleShot( 1000, this, SLOT(deleteLater()) );
+
+ } else {
+ mScannerEngine->cancel();
+
+ mScanningProgressNote->setProgressValue( mScanningProgressNote->maximum() );
+ mScanningProgressNote->deleteLater();
+ deleteLater();
+
+ disconnect( mScanningProgressNote, SIGNAL(cancelled()),
+ this, SLOT(scanAndSavePresetsCancelled()) );
+
+ carousel->setStationModel( &mUiEngine.model() );
+ }
+
+ disconnect( mScannerEngine.data(), SIGNAL(stationFound(RadioStation)),
+ this, SLOT(updateScanAndSaveProgress(RadioStation)) );
+
+ emit frequencyScannerFinished();
+}