radioapp/radiowidgets/src/radiomainview.cpp
changeset 32 189d20c34778
parent 28 075425b8d9a4
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <QTimer>
    19 #include <QTimer>
    20 #include <HbLabel>
       
    21 #include <HbPushButton>
    20 #include <HbPushButton>
    22 #include <HbAction>
    21 #include <HbAction>
    23 #include <HbMenu>
    22 #include <HbMenu>
    24 #include <QApplication>
    23 #include <QApplication>
    25 
    24 
    64 {
    63 {
    65     if ( scanning ) {
    64     if ( scanning ) {
    66         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_SCANNING );
    65         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_SCANNING );
    67     } else {
    66     } else {
    68         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_NORMAL );
    67         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_NORMAL );
       
    68         updateFavoriteButton();
    69         mFrequencyScanner.take();
    69         mFrequencyScanner.take();
    70 
    70 
    71         const bool firsTimeStart = mUiEngine->isFirstTimeStart();
    71         const bool firsTimeStart = mUiEngine->isFirstTimeStart();
    72         const int rowCount = mUiEngine->stationModel().rowCount();
    72         const int rowCount = mUiEngine->stationModel().rowCount();
    73         if ( firsTimeStart && rowCount != 0 ) {
    73         if ( firsTimeStart && rowCount != 0 ) {
    85     LOG_METHOD;
    85     LOG_METHOD;
    86     loadSection( DOCML::FILE_MAINVIEW, DOCML::SECTION_LAZY_LOAD );
    86     loadSection( DOCML::FILE_MAINVIEW, DOCML::SECTION_LAZY_LOAD );
    87     mCarousel = mUiLoader->findObject<RadioStationCarousel>( DOCML::MV_NAME_STATION_CAROUSEL );
    87     mCarousel = mUiLoader->findObject<RadioStationCarousel>( DOCML::MV_NAME_STATION_CAROUSEL );
    88     mCarousel->init( *mUiLoader, mUiEngine.data() );
    88     mCarousel->init( *mUiLoader, mUiEngine.data() );
    89 
    89 
    90     // Note! UI connections are already made in the DocML file. Here we need to connect UI to engine
       
    91     mFrequencyStrip = mUiLoader->findObject<RadioFrequencyStrip>( DOCML::MV_NAME_FREQUENCY_STRIP );
    90     mFrequencyStrip = mUiLoader->findObject<RadioFrequencyStrip>( DOCML::MV_NAME_FREQUENCY_STRIP );
    92     mFrequencyStrip->init( mUiEngine.data(), *mUiLoader );
    91     mFrequencyStrip->init( mUiEngine.data(), *mUiLoader );
    93 
    92 
    94     RadioStationModel* stationModel = &mUiEngine->stationModel();
    93     RadioStationModel* stationModel = &mUiEngine->stationModel();
    95 
    94 
   120                     this,                       SLOT(handleFavoriteChange(RadioStation)) );
   119                     this,                       SLOT(handleFavoriteChange(RadioStation)) );
   121 
   120 
   122     connectXmlElement( DOCML::MV_NAME_STATIONS_BUTTON,  SIGNAL(clicked()),
   121     connectXmlElement( DOCML::MV_NAME_STATIONS_BUTTON,  SIGNAL(clicked()),
   123                        mMainWindow,                     SLOT(activateStationsView()) );
   122                        mMainWindow,                     SLOT(activateStationsView()) );
   124 
   123 
   125     connectXmlElement( DOCML::MV_NAME_SCAN_BUTTON,      SIGNAL(clicked()),
   124     connectXmlElement( DOCML::MV_NAME_FAVORITE_BUTTON,  SIGNAL(clicked()),
   126                        this,                            SLOT(toggleScanning()) );
   125                        this,                            SLOT(toggleFavorite()) );
   127 
   126 
   128     connectXmlElement( DOCML::MV_NAME_SPEAKER_BUTTON,   SIGNAL(clicked()),
   127     connectXmlElement( DOCML::MV_NAME_SPEAKER_BUTTON,   SIGNAL(clicked()),
   129                        mUiEngine.data(),                SLOT(toggleAudioRoute()) );
   128                        mUiEngine.data(),                SLOT(toggleAudioRoute()) );
   130 
   129 
       
   130     connectXmlElement( DOCML::MV_NAME_SCAN_ACTION,      SIGNAL(triggered()),
       
   131                        this,                            SLOT(toggleScanning()) );
       
   132 
       
   133     updateFavoriteButton();
       
   134 
   131     connectCommonMenuItem( MenuItem::Exit );
   135     connectCommonMenuItem( MenuItem::Exit );
   132 
   136 
   133     // "Play history" menu item
   137     // "Play history" menu item
   134     connectViewChangeMenuItem( DOCML::MV_NAME_HISTORYVIEW_ACTION, SLOT(activateHistoryView()) );
   138     connectViewChangeMenuItem( DOCML::MV_NAME_HISTORYVIEW_ACTION, SLOT(activateHistoryView()) );
   135 
   139 
   136     //TODO: REMOVE. THIS IS TEMPORARY TEST CODE
   140     //TODO: REMOVE. THIS IS TEMPORARY TEST CODE
   137     toggleSkippingMode();
   141     toggleSkippingMode();
   138     menu()->addAction( "Reset start count", this, SLOT(resetFirstTimeCount()) );
   142     menu()->addAction( "-- Reset start count", this, SLOT(resetFirstTimeCount()) );
   139     // END TEMPORARY TEST CODE
   143     // END TEMPORARY TEST CODE
   140 
   144 
   141     updateAudioRoute( mUiEngine->isUsingLoudspeaker() );
   145     updateAudioRoute( mUiEngine->isUsingLoudspeaker() );
   142 
   146 
   143     // Add "back" navigation action to put the application to background
   147     // Add "back" navigation action to put the application to background
   221  * Private slot
   225  * Private slot
   222  */
   226  */
   223 void RadioMainView::setFrequencyFromEngine( uint frequency, int reason )
   227 void RadioMainView::setFrequencyFromEngine( uint frequency, int reason )
   224 {
   228 {
   225     LOG_FORMAT( "RadioMainView::setFrequencyFromEngine reason: %d", reason );
   229     LOG_FORMAT( "RadioMainView::setFrequencyFromEngine reason: %d", reason );
   226     if ( !RadioUtil::isScannerAlive() && !mFrequencyStrip->isInManualSeekMode() ) {
   230     if ( RadioUtil::scanStatus() != Scan::ScanningInMainView && !mFrequencyStrip->isInManualSeekMode() ) {
   227         mCarousel->clearInfoText();
   231         mCarousel->clearInfoText();
       
   232         updateFavoriteButton();
   228         if ( reason != TuneReason::FrequencyStrip &&
   233         if ( reason != TuneReason::FrequencyStrip &&
   229              reason != TuneReason::StationCarousel &&
   234              reason != TuneReason::StationCarousel &&
   230              reason != TuneReason::Skip ) {
   235              reason != TuneReason::Skip ) {
   231             mCarousel->setFrequency( frequency, reason, Scroll::Shortest );
   236             mCarousel->setFrequency( frequency, reason, Scroll::Shortest );
   232             mFrequencyStrip->setFrequency( frequency, reason, Scroll::Shortest );
   237             mFrequencyStrip->setFrequency( frequency, reason, Scroll::Shortest );
   302 }
   307 }
   303 
   308 
   304 /*!
   309 /*!
   305  * Private slot
   310  * Private slot
   306  */
   311  */
       
   312 void RadioMainView::toggleFavorite()
       
   313 {
       
   314     if ( RadioUtil::isScannerAlive() ) {
       
   315         toggleScanning();
       
   316     } else {
       
   317         mUiEngine->stationModel().setData( QModelIndex(), mFrequencyStrip->frequency(), RadioRole::ToggleFavoriteRole );
       
   318     }
       
   319 }
       
   320 
       
   321 /*!
       
   322  * Private slot
       
   323  */
   307 void RadioMainView::seekingStarted()
   324 void RadioMainView::seekingStarted()
   308 {
   325 {
   309     if ( !RadioUtil::isScannerAlive() ) {
   326     if ( !RadioUtil::isScannerAlive() ) {
   310         mCarousel->setInfoText( CarouselInfoText::Seeking );
   327         mCarousel->setInfoText( CarouselInfoText::Seeking );
   311     }
   328     }
   318 {
   335 {
   319     if ( !connected ) {
   336     if ( !connected ) {
   320         mFrequencyStrip->cancelManualSeek();
   337         mFrequencyStrip->cancelManualSeek();
   321     }
   338     }
   322 
   339 
   323     HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_SCAN_BUTTON );
   340     HbAction* scanAction = mUiLoader->findObject<HbAction>( DOCML::MV_NAME_SCAN_ACTION );
   324     scanButton->setEnabled( connected );
   341     scanAction->setEnabled( connected );
   325     mCarousel->updateAntennaStatus( connected );
   342     mCarousel->updateAntennaStatus( connected );
   326 }
   343 }
   327 
   344 
   328 /*!
   345 /*!
   329  * Private slot
   346  * Private slot
   345  */
   362  */
   346 void RadioMainView::setManualSeekMode( bool manualSeekActive )
   363 void RadioMainView::setManualSeekMode( bool manualSeekActive )
   347 {
   364 {
   348     if ( manualSeekActive ) {
   365     if ( manualSeekActive ) {
   349         qApp->installEventFilter( this );
   366         qApp->installEventFilter( this );
       
   367 
       
   368         mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_FAVORITE_BUTTON )->setText( hbTrId( "txt_rad_button_add_to_favourites" ) );
   350     } else {
   369     } else {
   351         qApp->removeEventFilter( this );
   370         qApp->removeEventFilter( this );
       
   371 
       
   372         updateFavoriteButton();
   352     }
   373     }
   353 
   374 
   354     mUiEngine->setManualSeekMode( manualSeekActive );
   375     mUiEngine->setManualSeekMode( manualSeekActive );
   355 
   376 
   356     mCarousel->setManualSeekMode( manualSeekActive );
   377     mCarousel->setManualSeekMode( manualSeekActive );
   360  * Private slot
   381  * Private slot
   361  */
   382  */
   362 void RadioMainView::handleFavoriteChange( const RadioStation& station )
   383 void RadioMainView::handleFavoriteChange( const RadioStation& station )
   363 {
   384 {
   364     mFrequencyStrip->updateFavorite( station );
   385     mFrequencyStrip->updateFavorite( station );
   365     if ( station.isFavorite() ) {
   386     updateFavoriteButton();
   366         RadioUtil::showDiscreetNote( "Station added to Favourites." );
       
   367     } else {
       
   368         RadioUtil::showDiscreetNote( "Station removed from Favourites." );
       
   369     }
       
   370 }
   387 }
   371 
   388 
   372 /*!
   389 /*!
   373  * Private slot
   390  * Private slot
   374  */
   391  */
   379     }
   396     }
   380 
   397 
   381     mAlternateSkipping = !mAlternateSkipping;
   398     mAlternateSkipping = !mAlternateSkipping;
   382     mCarousel->setAlternateSkippingMode( mAlternateSkipping );
   399     mCarousel->setAlternateSkippingMode( mAlternateSkipping );
   383     if ( mAlternateSkipping ) {
   400     if ( mAlternateSkipping ) {
   384         mSkippingAction->setText( "Normal skipping mode" );
   401         mSkippingAction->setText( "-- Normal skipping mode" );
   385     } else {
   402     } else {
   386         mSkippingAction->setText( "Alternate skipping mode" );
   403         mSkippingAction->setText( "-- Alternate skipping mode" );
   387     }
   404     }
   388 }
   405 }
   389 
   406 
   390 /*!
   407 /*!
   391  * Private slot
   408  * Private slot
   392  */
   409  */
   393 void RadioMainView::resetFirstTimeCount()
   410 void RadioMainView::resetFirstTimeCount()
   394 {
   411 {
   395     mUiEngine->setFirstTimeStartPerformed( false );
   412     mUiEngine->setFirstTimeStartPerformed( false );
   396 }
   413 }
       
   414 
       
   415 /*!
       
   416  *
       
   417  */
       
   418 void RadioMainView::updateFavoriteButton()
       
   419 {
       
   420     RadioStation station;
       
   421     RadioStationModel& model = mUiEngine->stationModel();
       
   422     model.findFrequency( mUiEngine->currentFrequency(), station );
       
   423     HbPushButton* favoriteButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_FAVORITE_BUTTON );
       
   424     if ( station.isFavorite() ) {
       
   425         //TODO: Get localized text
       
   426         favoriteButton->setText( "Remove from favourites" );
       
   427 //        favoriteButton->setIcon( HbIcon( ":/images/pri_small_star_inactive.svg" ) );
       
   428     } else {
       
   429         favoriteButton->setText( hbTrId( "txt_rad_button_add_to_favourites" ) );
       
   430 //        favoriteButton->setIcon( HbIcon( ":/images/pri_small_star.svg" ) );
       
   431     }
       
   432 }