radioapp/radiouiengine/src/radiomonitorservice.cpp
changeset 57 21be958eb3ce
parent 51 bbebb0235466
equal deleted inserted replaced
56:04837bf3a628 57:21be958eb3ce
    85                     this,           SLOT(notifyLocalCount()) );
    85                     this,           SLOT(notifyLocalCount()) );
    86     Radio::connect( stationModel,   SIGNAL(stationDataChanged(RadioStation)),
    86     Radio::connect( stationModel,   SIGNAL(stationDataChanged(RadioStation)),
    87                     this,           SLOT(notifyStationChange(RadioStation)) );
    87                     this,           SLOT(notifyStationChange(RadioStation)) );
    88     Radio::connect( stationModel,   SIGNAL(radioTextReceived(RadioStation)),
    88     Radio::connect( stationModel,   SIGNAL(radioTextReceived(RadioStation)),
    89                     this,           SLOT(notifyStationChange(RadioStation)) );
    89                     this,           SLOT(notifyStationChange(RadioStation)) );
    90 
    90     Radio::connect( stationModel,   SIGNAL(dynamicPsChanged(RadioStation)),
       
    91                     this,           SLOT(notifyStationChange(RadioStation)) );
       
    92     
    91     RadioUiEngine* uiEngine = &mUiEngine.api();
    93     RadioUiEngine* uiEngine = &mUiEngine.api();
    92     Radio::connect( uiEngine,       SIGNAL(seekingStarted(int)),
    94     Radio::connect( uiEngine,       SIGNAL(seekingStarted(int)),
    93                     this,           SLOT(notifyRadioStatus()) );
    95                     this,           SLOT(notifyRadioStatus()) );
    94     Radio::connect( uiEngine,       SIGNAL(muteChanged(bool)),
    96     Radio::connect( uiEngine,       SIGNAL(muteChanged(bool)),
    95                     this,           SLOT(notifyRadioStatus()) );
    97                     this,           SLOT(notifyRadioStatus()) );
    96     Radio::connect( uiEngine,       SIGNAL(antennaStatusChanged(bool)),
    98     Radio::connect( uiEngine,       SIGNAL(antennaStatusChanged(bool)),
    97                     this,           SLOT(notifyRadioStatus()) );
    99                     this,           SLOT(notifyRadioStatus()) );
    98     Radio::connect( uiEngine,       SIGNAL(powerOffRequested()),
   100 //    Radio::connect( uiEngine,       SIGNAL(powerOffRequested()),
    99                     this,           SLOT(notifyRadioStatus()) );
   101 //                    this,           SLOT(notifyRadioStatus()) );
   100 
   102 
   101     mUiEngine.wrapper().addObserver( this );
   103     mUiEngine.wrapper().addObserver( this );
   102 
   104 
   103     notifyRadioStatus();
   105     notifyRadioStatus();
   104 }
   106 }
   176 {
   178 {
   177     RadioStatus::Status radioStatus = determineRadioStatus();
   179     RadioStatus::Status radioStatus = determineRadioStatus();
   178 
   180 
   179     if ( radioStatus != mRadioStatus ) {
   181     if ( radioStatus != mRadioStatus ) {
   180         if ( radioStatus == RadioStatus::Seeking ) {
   182         if ( radioStatus == RadioStatus::Seeking ) {
   181             if ( RadioScannerEngine* scannerEngine = mUiEngine.api().scannerEngine() ) {
   183             RadioScannerEngine* scannerEngine = mUiEngine.api().scannerEngine();
       
   184             if ( scannerEngine ) {
   182                 Radio::connect( scannerEngine,  SIGNAL(destroyed()),
   185                 Radio::connect( scannerEngine,  SIGNAL(destroyed()),
   183                                 this,           SLOT(notifyRadioStatus()) );
   186                                 this,           SLOT(notifyRadioStatus()) );
   184             }
   187             }
   185         }
   188         }
   186 
   189 
   195  */
   198  */
   196 void RadioMonitorService::notifyFavoriteCount()
   199 void RadioMonitorService::notifyFavoriteCount()
   197 {
   200 {
   198     const int favoriteCount = mUiEngine.api().stationModel().favoriteCount();
   201     const int favoriteCount = mUiEngine.api().stationModel().favoriteCount();
   199     RUN_NOTIFY( FavoriteCount, favoriteCount );
   202     RUN_NOTIFY( FavoriteCount, favoriteCount );
   200 
   203     checkIfCurrentStationIsFavorite();
   201     if ( favoriteCount == 1 ) {
       
   202         checkIfCurrentStationIsFavorite();
       
   203     }
       
   204 }
   204 }
   205 
   205 
   206 /*!
   206 /*!
   207  * Private slot
   207  * Private slot
   208  *
   208  *
   246         const QString trimmedRadioText = trimHtmlTags( station.radioText() );
   246         const QString trimmedRadioText = trimHtmlTags( station.radioText() );
   247         notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, trimmedRadioText ) );
   247         notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, trimmedRadioText ) );
   248         list.append( notification );
   248         list.append( notification );
   249     }
   249     }
   250 
   250 
   251     notifyList( list );
   251     notify( list );
       
   252 
   252 }
   253 }
   253 
   254 
   254 /*!
   255 /*!
   255  * Private slot
   256  * Private slot
   256  *
   257  *
   257  */
   258  */
   258 void RadioMonitorService::sendNotifications()
   259 void RadioMonitorService::sendNotifications()
   259 {
   260 {
   260     notifyList( mNotificationList );
   261 
   261     mNotificationList.clear();
   262     if ( !mNotificationQueue.isEmpty() )
       
   263     {
       
   264         notifyList( mNotificationQueue.dequeue() );
       
   265     }
       
   266     if ( !mNotificationQueue.isEmpty() )
       
   267     {
       
   268         mNotificationTimer->start();
       
   269     }
   262 }
   270 }
   263 
   271 
   264 /*!
   272 /*!
   265  * \reimp
   273  * \reimp
   266  */
   274  */
   267 void RadioMonitorService::tunedToFrequency( uint frequency, int reason )
   275 void RadioMonitorService::tunedToFrequency( uint frequency, int reason )
   268 {
   276 {
   269     Q_UNUSED( reason );
   277     Q_UNUSED( reason );
   270     if ( !mUiEngine.api().isScanning() ) {
   278     if ( !mUiEngine.api().isScanning() ) {
       
   279 
       
   280         // frequency changed, cancel any pending notification as it has become invalid
       
   281         mNotificationTimer->stop();
       
   282         mNotificationQueue.clear();
       
   283         
   271         RUN_NOTIFY( Frequency, RadioStation::parseFrequency( frequency ) );
   284         RUN_NOTIFY( Frequency, RadioStation::parseFrequency( frequency ) );
   272         RadioStation station;
   285         RadioStation station;
   273         if ( mUiEngine.api().stationModel().findFrequency( frequency, station ) && !station.name().isEmpty() ) {
   286         if ( mUiEngine.api().stationModel().findFrequency( frequency, station ) && !station.name().isEmpty() ) {
   274             RUN_NOTIFY( Name, station.name() );
   287             RUN_NOTIFY( Name, station.name() );
   275         }
   288         }
   276 
   289 
   277         const int favoriteCount = mUiEngine.api().stationModel().favoriteCount();
   290         const int favoriteCount = mUiEngine.api().stationModel().favoriteCount();
   278         if ( favoriteCount == 1 ) {
   291         checkIfCurrentStationIsFavorite();
   279             checkIfCurrentStationIsFavorite();
       
   280         }
       
   281     }
   292     }
   282 }
   293 }
   283 
   294 
   284 /*!
   295 /*!
   285  *
   296  *
   324 /*!
   335 /*!
   325  *
   336  *
   326  */
   337  */
   327 void RadioMonitorService::notify( const QVariant& notification )
   338 void RadioMonitorService::notify( const QVariant& notification )
   328 {
   339 {
   329     mNotificationTimer->stop();
   340     QVariantList list;
   330     mNotificationList.append( notification );
   341     list.append( notification );
   331     mNotificationTimer->start();
   342     notify( list );
       
   343 }
       
   344 
       
   345 /*!
       
   346  *
       
   347  */
       
   348 void RadioMonitorService::notify( const QVariantList& list )
       
   349 {
       
   350     mNotificationQueue.enqueue( list );
       
   351     if ( !mNotificationTimer->isActive() )
       
   352     {
       
   353         mNotificationTimer->start();
       
   354     }
   332 }
   355 }
   333 
   356 
   334 /*!
   357 /*!
   335  *
   358  *
   336  */
   359  */