radioapp/radiouiengine/src/radiouiengine_p.cpp
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
child 32 189d20c34778
equal deleted inserted replaced
24:6df133bd92e1 28:075425b8d9a4
    30 #include "radiouiengine_p.h"
    30 #include "radiouiengine_p.h"
    31 #include "radioenginewrapper.h"
    31 #include "radioenginewrapper.h"
    32 #include "radiostationmodel.h"
    32 #include "radiostationmodel.h"
    33 #include "radiostationmodel_p.h"
    33 #include "radiostationmodel_p.h"
    34 #include "radiohistorymodel.h"
    34 #include "radiohistorymodel.h"
    35 #include "radiocarouselmodel.h"
       
    36 #include "radiopresetstorage.h"
    35 #include "radiopresetstorage.h"
    37 #include "radiosettings.h"
    36 #include "radiosettings.h"
    38 #include "radiostation.h"
    37 #include "radiostation.h"
    39 #include "radioscannerengine.h"
    38 #include "radioscannerengine.h"
    40 #include "radiostationhandlerif.h"
    39 #include "radiostationhandlerif.h"
    41 #ifndef BUILD_WIN32
    40 #include "radiocontrolservice.h"
    42 #   include "radiocontrolservice.h"
    41 #include "radiomonitorservice.h"
    43 #   include "radiomonitorservice.h"
       
    44 #else
       
    45 #   include "radiomonitorservice_win32.h"
       
    46 #endif
       
    47 #include "radioservicedef.h"
    42 #include "radioservicedef.h"
    48 #include "radiologger.h"
    43 #include "radiologger.h"
    49 
    44 
    50 /*!
    45 /*!
    51  *
    46  *
    81 /*!
    76 /*!
    82  *
    77  *
    83  */
    78  */
    84 bool RadioUiEnginePrivate::init()
    79 bool RadioUiEnginePrivate::init()
    85 {
    80 {
    86 #ifndef BUILD_WIN32
       
    87     mControlService.reset( new RadioControlService( *q_ptr ) );
    81     mControlService.reset( new RadioControlService( *q_ptr ) );
    88 #endif
       
    89     mMonitorService.reset( new RadioMonitorService( *this ) );
    82     mMonitorService.reset( new RadioMonitorService( *this ) );
    90     mStationModel.reset( new RadioStationModel( *this ) );
    83     mStationModel.reset( new RadioStationModel( *this ) );
       
    84 
    91     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
    85     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
       
    86     if ( !mEngineWrapper->init() ) {
       
    87         return false;
       
    88     }
    92     mEngineWrapper->addObserver( this );
    89     mEngineWrapper->addObserver( this );
       
    90 
    93     mPresetStorage.reset( new RadioPresetStorage() );
    91     mPresetStorage.reset( new RadioPresetStorage() );
    94     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
    92     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
    95     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
    93     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
    96 
    94 
    97 #ifndef BUILD_WIN32
    95 #ifndef BUILD_WIN32
   105     }
   103     }
   106 #endif
   104 #endif
   107 
   105 
   108     mMonitorService->init();
   106     mMonitorService->init();
   109 
   107 
   110     return mEngineWrapper->isEngineConstructed();
   108     return true;
   111 }
   109 }
   112 
   110 
   113 /*!
   111 /*!
   114  *
   112  *
   115  */
   113  */
   140  */
   138  */
   141 void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn )
   139 void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn )
   142 {
   140 {
   143     Q_Q( RadioUiEngine );
   141     Q_Q( RadioUiEngine );
   144     q->emitRadioStatusChanged( radioIsOn );
   142     q->emitRadioStatusChanged( radioIsOn );
   145 
       
   146     if ( radioIsOn ) {
       
   147         Q_Q( RadioUiEngine );
       
   148         QStringList args; // = qApp->arguments();
       
   149         if ( args.count() == 2 )
       
   150         {
       
   151             if ( args.at( 0 ) == "-f" ) // Frequency
       
   152             {
       
   153                 uint frequency = args.at( 1 ).toUInt();
       
   154 
       
   155                 if ( frequency >= mEngineWrapper->minFrequency() && frequency <= mEngineWrapper->maxFrequency() )
       
   156                 {
       
   157                     LOG_FORMAT( "RadioApplication::handleArguments, Tuning to frequency: %d", frequency );
       
   158                     q->tuneFrequency( frequency, 0 );
       
   159                 }
       
   160             }
       
   161             else if ( args.at( 0 ) == "-i" ) // Preset index
       
   162             {
       
   163                 int preset = args.at( 1 ).toInt();
       
   164                 if ( preset > 0 && preset < mStationModel->rowCount() )
       
   165                 {
       
   166                     LOG_FORMAT( "RadioApplication::handleArguments, Tuning to preset %d", preset );
       
   167                     q->tunePreset( preset );
       
   168                 }
       
   169             }
       
   170         }
       
   171     }
       
   172 }
   143 }
   173 
   144 
   174 /*!
   145 /*!
   175  *
   146  *
   176  */
   147  */
   181 }
   152 }
   182 
   153 
   183 /*!
   154 /*!
   184  *
   155  *
   185  */
   156  */
       
   157 void RadioUiEnginePrivate::increaseVolume()
       
   158 {
       
   159     Q_Q( RadioUiEngine );
       
   160     if( q->isScanning() ){
       
   161         // volume not changed while scanning
       
   162     } else {
       
   163         mEngineWrapper->increaseVolume();
       
   164     }
       
   165 }
       
   166 
       
   167 /*!
       
   168  *
       
   169  */
       
   170 void RadioUiEnginePrivate::decreaseVolume()
       
   171 {
       
   172     Q_Q( RadioUiEngine );
       
   173     if( q->isScanning() ) {
       
   174         // volume not changed while scanning
       
   175     } else {
       
   176         mEngineWrapper->decreaseVolume();
       
   177     }
       
   178 }
       
   179 
       
   180 /*!
       
   181  *
       
   182  */
   186 void RadioUiEnginePrivate::volumeChanged( int volume )
   183 void RadioUiEnginePrivate::volumeChanged( int volume )
   187 {
   184 {
   188     Q_Q( RadioUiEngine );
   185     Q_Q( RadioUiEngine );
   189     q->emitVolumeChanged( volume );
   186     q->emitVolumeChanged( volume );
   190 }
   187 }
   219 /*!
   216 /*!
   220  *
   217  *
   221  */
   218  */
   222 void RadioUiEnginePrivate::skipPrevious()
   219 void RadioUiEnginePrivate::skipPrevious()
   223 {
   220 {
   224     skip( StationSkip::PreviousFavorite );
   221     skip( StationSkip::PreviousFavorite, 0, TuneReason::SkipFromEngine );
   225 }
   222 }
   226 
   223 
   227 /*!
   224 /*!
   228  *
   225  *
   229  */
   226  */
   230 void RadioUiEnginePrivate::skipNext()
   227 void RadioUiEnginePrivate::skipNext()
   231 {
   228 {
   232     skip( StationSkip::NextFavorite );
   229     skip( StationSkip::NextFavorite, 0, TuneReason::SkipFromEngine );
   233 }
   230 }
   234 
   231 
   235 /*!
   232 /*!
   236  * Tunes to next or previous station
   233  * Tunes to next or previous station
   237  */
   234  */
   238 uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency )
   235 uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency, const int reason )
   239 {
   236 {
   240     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
   237     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
   241     if ( startFrequency == 0 ) {
   238     if ( startFrequency == 0 ) {
   242         startFrequency = mEngineWrapper->currentFrequency();
   239         startFrequency = mEngineWrapper->currentFrequency();
   243     }
   240     }
   244 
   241 
   245     const uint newFrequency = mStationModel->findClosest( startFrequency, mode ).frequency();
   242     const int favoriteCount = mStationModel->favoriteCount();
   246 
   243     if ( favoriteCount < 2 ) {
   247     LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
   244         if ( mode == StationSkip::NextFavorite ) {
   248     mEngineWrapper->tuneFrequency( newFrequency, TuneReason::Skip );
   245             mode = StationSkip::Next;
   249     return newFrequency;
   246         } else if ( mode == StationSkip::PreviousFavorite ) {
   250 }
   247             mode = StationSkip::Previous;
   251 
   248         }
       
   249     }
       
   250 
       
   251     const RadioStation station = mStationModel->findClosest( startFrequency, mode );
       
   252     if ( station.isValid() ) {
       
   253         const uint newFrequency = station.frequency();
       
   254 
       
   255         LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
       
   256         mEngineWrapper->setFrequency( newFrequency, reason );
       
   257         return newFrequency;
       
   258     }
       
   259     return startFrequency;
       
   260 }
       
   261