radioapp/radiouiengine/src/radiouiengine_p.cpp
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
child 32 189d20c34778
--- a/radioapp/radiouiengine/src/radiouiengine_p.cpp	Fri Jun 04 10:21:36 2010 +0100
+++ b/radioapp/radiouiengine/src/radiouiengine_p.cpp	Fri Jun 11 13:38:32 2010 +0300
@@ -32,18 +32,13 @@
 #include "radiostationmodel.h"
 #include "radiostationmodel_p.h"
 #include "radiohistorymodel.h"
-#include "radiocarouselmodel.h"
 #include "radiopresetstorage.h"
 #include "radiosettings.h"
 #include "radiostation.h"
 #include "radioscannerengine.h"
 #include "radiostationhandlerif.h"
-#ifndef BUILD_WIN32
-#   include "radiocontrolservice.h"
-#   include "radiomonitorservice.h"
-#else
-#   include "radiomonitorservice_win32.h"
-#endif
+#include "radiocontrolservice.h"
+#include "radiomonitorservice.h"
 #include "radioservicedef.h"
 #include "radiologger.h"
 
@@ -83,13 +78,16 @@
  */
 bool RadioUiEnginePrivate::init()
 {
-#ifndef BUILD_WIN32
     mControlService.reset( new RadioControlService( *q_ptr ) );
-#endif
     mMonitorService.reset( new RadioMonitorService( *this ) );
     mStationModel.reset( new RadioStationModel( *this ) );
+
     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
+    if ( !mEngineWrapper->init() ) {
+        return false;
+    }
     mEngineWrapper->addObserver( this );
+
     mPresetStorage.reset( new RadioPresetStorage() );
     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
@@ -107,7 +105,7 @@
 
     mMonitorService->init();
 
-    return mEngineWrapper->isEngineConstructed();
+    return true;
 }
 
 /*!
@@ -142,33 +140,6 @@
 {
     Q_Q( RadioUiEngine );
     q->emitRadioStatusChanged( radioIsOn );
-
-    if ( radioIsOn ) {
-        Q_Q( RadioUiEngine );
-        QStringList args; // = qApp->arguments();
-        if ( args.count() == 2 )
-        {
-            if ( args.at( 0 ) == "-f" ) // Frequency
-            {
-                uint frequency = args.at( 1 ).toUInt();
-
-                if ( frequency >= mEngineWrapper->minFrequency() && frequency <= mEngineWrapper->maxFrequency() )
-                {
-                    LOG_FORMAT( "RadioApplication::handleArguments, Tuning to frequency: %d", frequency );
-                    q->tuneFrequency( frequency, 0 );
-                }
-            }
-            else if ( args.at( 0 ) == "-i" ) // Preset index
-            {
-                int preset = args.at( 1 ).toInt();
-                if ( preset > 0 && preset < mStationModel->rowCount() )
-                {
-                    LOG_FORMAT( "RadioApplication::handleArguments, Tuning to preset %d", preset );
-                    q->tunePreset( preset );
-                }
-            }
-        }
-    }
 }
 
 /*!
@@ -183,6 +154,32 @@
 /*!
  *
  */
+void RadioUiEnginePrivate::increaseVolume()
+{
+    Q_Q( RadioUiEngine );
+    if( q->isScanning() ){
+        // volume not changed while scanning
+    } else {
+        mEngineWrapper->increaseVolume();
+    }
+}
+
+/*!
+ *
+ */
+void RadioUiEnginePrivate::decreaseVolume()
+{
+    Q_Q( RadioUiEngine );
+    if( q->isScanning() ) {
+        // volume not changed while scanning
+    } else {
+        mEngineWrapper->decreaseVolume();
+    }
+}
+
+/*!
+ *
+ */
 void RadioUiEnginePrivate::volumeChanged( int volume )
 {
     Q_Q( RadioUiEngine );
@@ -221,7 +218,7 @@
  */
 void RadioUiEnginePrivate::skipPrevious()
 {
-    skip( StationSkip::PreviousFavorite );
+    skip( StationSkip::PreviousFavorite, 0, TuneReason::SkipFromEngine );
 }
 
 /*!
@@ -229,23 +226,36 @@
  */
 void RadioUiEnginePrivate::skipNext()
 {
-    skip( StationSkip::NextFavorite );
+    skip( StationSkip::NextFavorite, 0, TuneReason::SkipFromEngine );
 }
 
 /*!
  * Tunes to next or previous station
  */
-uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency )
+uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency, const int reason )
 {
     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
     if ( startFrequency == 0 ) {
         startFrequency = mEngineWrapper->currentFrequency();
     }
 
-    const uint newFrequency = mStationModel->findClosest( startFrequency, mode ).frequency();
+    const int favoriteCount = mStationModel->favoriteCount();
+    if ( favoriteCount < 2 ) {
+        if ( mode == StationSkip::NextFavorite ) {
+            mode = StationSkip::Next;
+        } else if ( mode == StationSkip::PreviousFavorite ) {
+            mode = StationSkip::Previous;
+        }
+    }
 
-    LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
-    mEngineWrapper->tuneFrequency( newFrequency, TuneReason::Skip );
-    return newFrequency;
+    const RadioStation station = mStationModel->findClosest( startFrequency, mode );
+    if ( station.isValid() ) {
+        const uint newFrequency = station.frequency();
+
+        LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
+        mEngineWrapper->setFrequency( newFrequency, reason );
+        return newFrequency;
+    }
+    return startFrequency;
 }