radioapp/radiouiengine/src/radiouiengine_p.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 32 189d20c34778
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    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  *
    52  */
    47  */
    53 RadioUiEnginePrivate::RadioUiEnginePrivate( RadioUiEngine* engine ) :
    48 RadioUiEnginePrivate::RadioUiEnginePrivate( RadioUiEngine* engine ) :
    54     q_ptr( engine )
    49     q_ptr( engine ),
       
    50     mPowerOffTimer( NULL )
    55 {
    51 {
    56 }
    52 }
    57 
    53 
    58 /*!
    54 /*!
    59  *
    55  *
    63 #ifndef BUILD_WIN32
    59 #ifndef BUILD_WIN32
    64     XQSettingsManager settingsManager;
    60     XQSettingsManager settingsManager;
    65     XQPublishAndSubscribeUtils utils( settingsManager );
    61     XQPublishAndSubscribeUtils utils( settingsManager );
    66     XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey );
    62     XQPublishAndSubscribeSettingsKey radioStartupKey( KRadioPSUid, KRadioStartupKey );
    67     bool deleted = utils.deleteProperty( radioStartupKey );
    63     bool deleted = utils.deleteProperty( radioStartupKey );
    68     LOG_ASSERT( deleted, LOG( "RadioUiEnginePrivate::~RadioUiEnginePrivate(). Failed to delete P&S key" ) );
    64     LOG_ASSERT( deleted, LOG( "RadioUiEnginePrivate::~RadioUiEnginePrivate(). Failed to remove P&S key" ) );
    69 #endif
    65 #endif
    70 }
    66 }
    71 
    67 
    72 /*!
    68 /*!
    73  *
    69  *
    81 /*!
    77 /*!
    82  *
    78  *
    83  */
    79  */
    84 bool RadioUiEnginePrivate::init()
    80 bool RadioUiEnginePrivate::init()
    85 {
    81 {
    86 #ifndef BUILD_WIN32
       
    87     mControlService.reset( new RadioControlService( *q_ptr ) );
    82     mControlService.reset( new RadioControlService( *q_ptr ) );
    88 #endif
       
    89     mMonitorService.reset( new RadioMonitorService( *this ) );
    83     mMonitorService.reset( new RadioMonitorService( *this ) );
    90     mStationModel.reset( new RadioStationModel( *this ) );
    84     mStationModel.reset( new RadioStationModel( *this ) );
       
    85 
    91     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
    86     mEngineWrapper.reset( new RadioEngineWrapper( mStationModel->stationHandlerIf() ) );
       
    87     if ( !mEngineWrapper->init() ) {
       
    88         return false;
       
    89     }
    92     mEngineWrapper->addObserver( this );
    90     mEngineWrapper->addObserver( this );
       
    91 
    93     mPresetStorage.reset( new RadioPresetStorage() );
    92     mPresetStorage.reset( new RadioPresetStorage() );
    94     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
    93     mStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
    95     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
    94     mHistoryModel.reset( new RadioHistoryModel( *q_ptr ) );
    96 
    95 
    97 #ifndef BUILD_WIN32
    96 #ifndef BUILD_WIN32
   105     }
   104     }
   106 #endif
   105 #endif
   107 
   106 
   108     mMonitorService->init();
   107     mMonitorService->init();
   109 
   108 
   110     return mEngineWrapper->isEngineConstructed();
   109     return true;
   111 }
   110 }
   112 
   111 
   113 /*!
   112 /*!
   114  *
   113  *
   115  */
   114  */
   140  */
   139  */
   141 void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn )
   140 void RadioUiEnginePrivate::radioStatusChanged( bool radioIsOn )
   142 {
   141 {
   143     Q_Q( RadioUiEngine );
   142     Q_Q( RadioUiEngine );
   144     q->emitRadioStatusChanged( radioIsOn );
   143     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 }
   144 }
   173 
   145 
   174 /*!
   146 /*!
   175  *
   147  *
   176  */
   148  */
   181 }
   153 }
   182 
   154 
   183 /*!
   155 /*!
   184  *
   156  *
   185  */
   157  */
       
   158 void RadioUiEnginePrivate::increaseVolume()
       
   159 {
       
   160     Q_Q( RadioUiEngine );
       
   161     if( q->isScanning() ){
       
   162         // volume not changed while scanning
       
   163     } else {
       
   164         mEngineWrapper->increaseVolume();
       
   165     }
       
   166 }
       
   167 
       
   168 /*!
       
   169  *
       
   170  */
       
   171 void RadioUiEnginePrivate::decreaseVolume()
       
   172 {
       
   173     Q_Q( RadioUiEngine );
       
   174     if( q->isScanning() ) {
       
   175         // volume not changed while scanning
       
   176     } else {
       
   177         mEngineWrapper->decreaseVolume();
       
   178     }
       
   179 }
       
   180 
       
   181 /*!
       
   182  *
       
   183  */
   186 void RadioUiEnginePrivate::volumeChanged( int volume )
   184 void RadioUiEnginePrivate::volumeChanged( int volume )
   187 {
   185 {
   188     Q_Q( RadioUiEngine );
   186     Q_Q( RadioUiEngine );
   189     q->emitVolumeChanged( volume );
   187     q->emitVolumeChanged( volume );
   190 }
   188 }
   219 /*!
   217 /*!
   220  *
   218  *
   221  */
   219  */
   222 void RadioUiEnginePrivate::skipPrevious()
   220 void RadioUiEnginePrivate::skipPrevious()
   223 {
   221 {
   224     skip( StationSkip::PreviousFavorite );
   222     skip( StationSkip::PreviousFavorite, 0, TuneReason::SkipFromEngine );
   225 }
   223 }
   226 
   224 
   227 /*!
   225 /*!
   228  *
   226  *
   229  */
   227  */
   230 void RadioUiEnginePrivate::skipNext()
   228 void RadioUiEnginePrivate::skipNext()
   231 {
   229 {
   232     skip( StationSkip::NextFavorite );
   230     skip( StationSkip::NextFavorite, 0, TuneReason::SkipFromEngine );
   233 }
   231 }
   234 
   232 
   235 /*!
   233 /*!
   236  * Tunes to next or previous station
   234  * Tunes to next or previous station
   237  */
   235  */
   238 uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency )
   236 uint RadioUiEnginePrivate::skip( StationSkip::Mode mode, uint startFrequency, const int reason )
   239 {
   237 {
   240     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
   238     LOG_FORMAT( "RadioUiEnginePrivate::skip: mode: %d", mode );
   241     if ( startFrequency == 0 ) {
   239     if ( startFrequency == 0 ) {
   242         startFrequency = mEngineWrapper->currentFrequency();
   240         startFrequency = mEngineWrapper->currentFrequency();
   243     }
   241     }
   244 
   242 
   245     const uint newFrequency = mStationModel->findClosest( startFrequency, mode ).frequency();
   243     const int favoriteCount = mStationModel->favoriteCount();
   246 
   244     if ( favoriteCount < 2 ) {
   247     LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
   245         if ( mode == StationSkip::NextFavorite ) {
   248     mEngineWrapper->tuneFrequency( newFrequency, TuneReason::Skip );
   246             mode = StationSkip::Next;
   249     return newFrequency;
   247         } else if ( mode == StationSkip::PreviousFavorite ) {
   250 }
   248             mode = StationSkip::Previous;
   251 
   249         }
       
   250     }
       
   251 
       
   252     const RadioStation station = mStationModel->findClosest( startFrequency, mode );
       
   253     if ( station.isValid() ) {
       
   254         const uint newFrequency = station.frequency();
       
   255 
       
   256         LOG_FORMAT( "RadioUiEnginePrivate::skip. CurrentFreq: %u, tuning to: %u", startFrequency, newFrequency );
       
   257         mEngineWrapper->setFrequency( newFrequency, reason );
       
   258         return newFrequency;
       
   259     }
       
   260     return startFrequency;
       
   261 }
       
   262