radioapp/radiowidgets/src/radiomainview.cpp
changeset 23 a2b50a479edf
parent 19 afea38384506
child 24 6df133bd92e1
equal deleted inserted replaced
19:afea38384506 23:a2b50a479edf
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QTimer>
       
    20 #include <HbLabel>
       
    21 #include <HbPushButton>
       
    22 #include <HbAction>
       
    23 
       
    24 // User includes
       
    25 #include "radiowindow.h"
       
    26 #include "radiomainview.h"
       
    27 #include "radiofrequencystrip.h"
       
    28 #include "radiouiengine.h"
       
    29 #include "radiologger.h"
       
    30 #include "radiostationcarousel.h"
       
    31 #include "radiouiloader.h"
       
    32 #include "radiouiutilities.h"
       
    33 #include "radiostationmodel.h"
       
    34 #include "radiofrequencyscanner.h"
       
    35 
       
    36 // Constants
       
    37 
       
    38 /*!
       
    39  *
       
    40  */
       
    41 RadioMainView::RadioMainView() :
       
    42     RadioViewBase( false ),
       
    43     mCarousel( NULL ),
       
    44     mFrequencyStrip( NULL )
       
    45 {
       
    46 }
       
    47 
       
    48 /*!
       
    49  *
       
    50  */
       
    51 RadioMainView::~RadioMainView()
       
    52 {
       
    53 }
       
    54 
       
    55 /*!
       
    56  * \reimp
       
    57  *
       
    58  */
       
    59 void RadioMainView::setScanningMode( bool scanning )
       
    60 {
       
    61     if ( scanning ) {
       
    62         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_SCANNING );
       
    63     } else {
       
    64         loadSection( DOCML::FILE_MAINVIEW, DOCML::MV_SECTION_NORMAL );
       
    65         mFrequencyScanner.take();
       
    66     }
       
    67 }
       
    68 
       
    69 /*!
       
    70  * \reimp
       
    71  *
       
    72  */
       
    73 void RadioMainView::init()
       
    74 {
       
    75     LOG_METHOD;
       
    76     mInitialized = true;
       
    77     mCarousel = mUiLoader->findObject<RadioStationCarousel>( DOCML::MV_NAME_STATION_CAROUSEL );
       
    78     mCarousel->init( *mUiLoader, &mMainWindow->uiEngine() );
       
    79 
       
    80     // Note! UI connections are already made in the DocML file. Here we need to connect UI to engine
       
    81     RadioUiEngine* engine = &mMainWindow->uiEngine();
       
    82     mFrequencyStrip = mUiLoader->findObject<RadioFrequencyStrip>( DOCML::MV_NAME_FREQUENCY_STRIP );
       
    83     mFrequencyStrip->init( engine );
       
    84 
       
    85     RadioStationModel* stationModel = &engine->stationModel();
       
    86 
       
    87     connectAndTest( mFrequencyStrip,            SIGNAL(frequencyChanged(uint,int)),
       
    88                     this,                       SLOT(setFrequencyFromWidget(uint,int)) );
       
    89     connectAndTest( mCarousel,                  SIGNAL(frequencyChanged(uint,int)),
       
    90                     this,                       SLOT(setFrequencyFromWidget(uint,int)) );
       
    91     connectAndTest( engine,                     SIGNAL(tunedToFrequency(uint,int)),
       
    92                     this,                       SLOT(setFrequencyFromEngine(uint,int)) );
       
    93 
       
    94     connectAndTest( mFrequencyStrip,            SIGNAL(skipRequested(int)),
       
    95                     this,                       SLOT(skip(int)) );
       
    96     connectAndTest( mFrequencyStrip,            SIGNAL(seekRequested(int)),
       
    97                     engine,                     SLOT(seekStation(int)) );
       
    98 
       
    99     connectAndTest( stationModel,               SIGNAL(favoriteChanged(RadioStation)),
       
   100                     mFrequencyStrip,            SLOT(updateFavorite(RadioStation)) );
       
   101 
       
   102     connectAndTest( engine,                     SIGNAL(seekingStarted(int)),
       
   103                     this,                       SLOT(seekingStarted()) );
       
   104     connectAndTest( engine,                     SIGNAL(antennaStatusChanged(bool)),
       
   105                     mCarousel,                  SLOT(updateAntennaStatus(bool)) );
       
   106     connectAndTest( engine,                     SIGNAL(audioRouteChanged(bool)),
       
   107                     this,                       SLOT(updateAudioRoute(bool)) );
       
   108 
       
   109     HbPushButton* stationsButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_STATIONS_BUTTON );
       
   110     connectAndTest( stationsButton,             SIGNAL(clicked()),
       
   111                     mMainWindow,                SLOT(activateStationsView()) );
       
   112 
       
   113     HbPushButton* scanButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_SCAN_BUTTON );
       
   114     connectAndTest( scanButton,                 SIGNAL(clicked()),
       
   115                     this,                       SLOT(toggleScanning()) );
       
   116 
       
   117     HbPushButton* loudspeakerButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_SPEAKER_BUTTON );
       
   118     connectAndTest( loudspeakerButton,          SIGNAL(clicked()),
       
   119                     engine,                     SLOT(toggleAudioRoute()) );
       
   120 
       
   121     // "Play history" menu item
       
   122     connectViewChangeMenuItem( DOCML::MV_NAME_HISTORYVIEW_ACTION, SLOT(activateHistoryView()) );
       
   123 
       
   124     updateAudioRoute( mMainWindow->uiEngine().isUsingLoudspeaker() );
       
   125 
       
   126     // Add "back" navigation action to put the application to background
       
   127     HbAction* backAction = new HbAction( Hb::BackNaviAction, this );
       
   128     connectAndTest( backAction,     SIGNAL(triggered()),
       
   129                     mMainWindow,    SLOT(lower()) );
       
   130     setNavigationAction( backAction );
       
   131 
       
   132     const bool firsTimeStart = engine->isFirstTimeStart();
       
   133     const int rowCount = engine->stationModel().rowCount();
       
   134     if ( firsTimeStart && rowCount == 0 ){
       
   135         QTimer::singleShot( 100, this, SLOT(toggleScanning()) );
       
   136     }
       
   137 }
       
   138 
       
   139 /*!
       
   140  * \reimp
       
   141  *
       
   142  */
       
   143 void RadioMainView::setOrientation()
       
   144 {
       
   145     loadSection( DOCML::FILE_MAINVIEW, mMainWindow->orientationSection() );
       
   146 }
       
   147 
       
   148 /*!
       
   149  * \reimp
       
   150  *
       
   151  */
       
   152 void RadioMainView::userAccepted()
       
   153 {
       
   154     mFrequencyScanner.reset( new RadioFrequencyScanner( mMainWindow->uiEngine(), this ) );
       
   155     mFrequencyScanner->startScanning();
       
   156 }
       
   157 
       
   158 /*!
       
   159  * Private slot
       
   160  */
       
   161 void RadioMainView::setFrequencyFromWidget( uint frequency, int reason )
       
   162 {
       
   163     LOG_FORMAT( "RadioMainView::setFrequencyFromWidget: %u, reason = %d", frequency, reason );
       
   164     if ( !RadioUiUtilities::isScannerAlive() ) {
       
   165         if ( reason == TuneReason::FrequencyStrip ) {
       
   166             mCarousel->setFrequency( frequency, reason );
       
   167             mMainWindow->uiEngine().tuneWithDelay( frequency, reason );
       
   168         } else if ( reason == TuneReason::StationCarousel ) {
       
   169             mFrequencyStrip->setFrequency( frequency, reason );
       
   170             mMainWindow->uiEngine().tuneFrequency( frequency, reason );
       
   171         }
       
   172     }
       
   173 }
       
   174 
       
   175 /*!
       
   176  * Private slot
       
   177  */
       
   178 void RadioMainView::setFrequencyFromEngine( uint frequency, int reason )
       
   179 {
       
   180     if ( !RadioUiUtilities::isScannerAlive() ) {
       
   181         mCarousel->clearInfoText();
       
   182         if ( reason != TuneReason::FrequencyStrip &&
       
   183              reason != TuneReason::StationCarousel &&
       
   184              reason != TuneReason::Skip ) {
       
   185             mCarousel->setFrequency( frequency, reason );
       
   186             mFrequencyStrip->setFrequency( frequency, reason );
       
   187         }
       
   188     }
       
   189 }
       
   190 
       
   191 /*!
       
   192  * Private slot
       
   193  */
       
   194 void RadioMainView::skip( int skipMode )
       
   195 {
       
   196     if ( ( skipMode == StationSkip::PreviousFavorite || skipMode == StationSkip::NextFavorite ) &&
       
   197         mMainWindow->uiEngine().stationModel().favoriteCount() == 0 ) {
       
   198         mCarousel->setInfoText( CarouselInfoText::NoFavorites );
       
   199     } else {
       
   200         const uint currentFrequency = mFrequencyStrip->frequency();
       
   201         const uint frequency = mMainWindow->uiEngine().skipStation( static_cast<StationSkip::Mode>( skipMode ),
       
   202                                                                     currentFrequency);
       
   203         mCarousel->setFrequency( frequency, TuneReason::Skip );
       
   204         mFrequencyStrip->setFrequency( frequency, TuneReason::Skip );
       
   205     }
       
   206 }
       
   207 
       
   208 /*!
       
   209  * Private slot
       
   210  */
       
   211 void RadioMainView::toggleScanning()
       
   212 {
       
   213     if ( mFrequencyScanner ) {
       
   214         mFrequencyScanner->cancelScanning();
       
   215     } else {
       
   216         const int rowCount =  mMainWindow->uiEngine().stationModel().rowCount();
       
   217         if ( rowCount > 0 ) {
       
   218             askQuestion( hbTrId( "txt_rad_info_all_stations_in_stations_list_will_be" ) );
       
   219         } else {
       
   220             userAccepted();
       
   221         }
       
   222     }
       
   223 }
       
   224 
       
   225 /*!
       
   226  * Private slot
       
   227  */
       
   228 void RadioMainView::seekingStarted()
       
   229 {
       
   230     if ( !RadioUiUtilities::isScannerAlive() ) {
       
   231         mCarousel->setInfoText( CarouselInfoText::Seeking );
       
   232     }
       
   233 }
       
   234 
       
   235 /*!
       
   236  * Private slot
       
   237  */
       
   238 void RadioMainView::updateAudioRoute( bool loudspeaker )
       
   239 {
       
   240     HbPushButton* loudspeakerButton = mUiLoader->findWidget<HbPushButton>( DOCML::MV_NAME_SPEAKER_BUTTON );
       
   241     if ( loudspeaker ) {
       
   242         loudspeakerButton->setIcon( HbIcon( "qtg_mono_speaker_off.svg" ) );
       
   243         loudspeakerButton->setText( hbTrId( "txt_rad_button_deactivate_loudspeaker" ) );
       
   244     } else {
       
   245         loudspeakerButton->setIcon( HbIcon( "qtg_mono_speaker.svg" ) );
       
   246         loudspeakerButton->setText( hbTrId( "txt_rad_button_activate_loudspeaker" ) );
       
   247     }
       
   248 }