radioapp/radiowidgets/src/radiomainwindow.cpp
changeset 16 f54ebcfc1b80
parent 14 63aabac4416d
equal deleted inserted replaced
14:63aabac4416d 16:f54ebcfc1b80
    21 #include <HbVolumeSliderPopup>
    21 #include <HbVolumeSliderPopup>
    22 
    22 
    23 #include "radiomainwindow.h"
    23 #include "radiomainwindow.h"
    24 #include "radiotuningview.h"
    24 #include "radiotuningview.h"
    25 #include "radiostationsview.h"
    25 #include "radiostationsview.h"
    26 #include "radiowizardview.h"
       
    27 #include "radiouiengine.h"
    26 #include "radiouiengine.h"
    28 #include "radiostationmodel.h"
    27 #include "radiostationmodel.h"
    29 #include "radiologger.h"
    28 #include "radiologger.h"
    30 #include "radioxmluiloader.h"
    29 #include "radioxmluiloader.h"
    31 #include "radiolocalization.h"
       
    32 
    30 
    33 // Constants
    31 // Constants
    34 
    32 
    35 /**
    33 /**
    36  * Desired amount of delay of volumesliderpopup
    34  * Desired amount of delay of volumesliderpopup
    59  */
    57  */
    60 bool RadioMainWindow::isOfflineUsageAllowed()
    58 bool RadioMainWindow::isOfflineUsageAllowed()
    61 {
    59 {
    62     DummyViewPtr dummyView = prepareToShowDialog();
    60     DummyViewPtr dummyView = prepareToShowDialog();
    63 
    61 
    64     const bool answer = HbMessageBox::question( hbTrId( "txt_rad_info_activate_radio_in_offline_mode" ) );
    62     HbMessageBox box( HbMessageBox::MessageTypeQuestion );
       
    63     box.setText( hbTrId( "txt_rad_info_activate_radio_in_offline_mode" ) );
       
    64     box.setTimeout( HbPopup::NoTimeout );
       
    65     box.setDismissPolicy( HbPopup::NoDismiss );
       
    66 
       
    67     HbAction* primaryAction = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
    68     box.setPrimaryAction( primaryAction );
       
    69     HbAction* secondaryAction = new HbAction( hbTrId( "txt_common_button_no" ) );
       
    70     box.setSecondaryAction( secondaryAction );
       
    71 
       
    72     const bool answer = box.exec() == box.primaryAction();
    65 
    73 
    66     dialogShown( dummyView );
    74     dialogShown( dummyView );
    67 
    75 
    68     return answer;
    76     return answer;
    69 }
    77 }
    93     connectAndTest( hbInstance->allMainWindows().first(),   SIGNAL(orientationChanged(Qt::Orientation)),
   101     connectAndTest( hbInstance->allMainWindows().first(),   SIGNAL(orientationChanged(Qt::Orientation)),
    94                     this,                                   SLOT(updateOrientation(Qt::Orientation)) );
   102                     this,                                   SLOT(updateOrientation(Qt::Orientation)) );
    95 
   103 
    96     connectAndTest( mUiEngine,  SIGNAL(volumeChanged(int)),
   104     connectAndTest( mUiEngine,  SIGNAL(volumeChanged(int)),
    97                     this,       SLOT(showVolumeLevel(int)) );
   105                     this,       SLOT(showVolumeLevel(int)) );
    98     connectAndTest( mUiEngine,  SIGNAL(headsetStatusChanged(bool)),
   106     connectAndTest( mUiEngine,  SIGNAL(antennaStatusChanged(bool)),
    99                     this,       SLOT(headsetStatusChanged(bool)) );
   107                     this,       SLOT(updateAntennaStatus(bool)) );
   100 
   108 
   101     const bool firstTimeStart = mUiEngine->isFirstTimeStart();
   109     activateTuningView();
   102     const int rowCount = mUiEngine->model().rowCount();
       
   103     if( firstTimeStart && rowCount == 0 ) {
       
   104         activateWizardView();
       
   105     } else {
       
   106         activateTuningView();
       
   107     }
       
   108 }
   110 }
   109 
   111 
   110 /*!
   112 /*!
   111  *
   113  *
   112  */
   114  */
   118 /*!
   120 /*!
   119  * Returns the XML layout section that corresponds to the view orientation
   121  * Returns the XML layout section that corresponds to the view orientation
   120  */
   122  */
   121 QString RadioMainWindow::orientationSection()
   123 QString RadioMainWindow::orientationSection()
   122 {
   124 {
   123     return orientation() == Qt::Vertical ? DOCML_LAYOUT_PORTRAIT : DOCML_LAYOUT_LANDSCAPE;
   125     return orientation() == Qt::Vertical ? DOCML::SECTION_PORTRAIT : DOCML::SECTION_LANDSCAPE;
   124 }
   126 }
   125 
   127 
   126 /*!
   128 /*!
   127  *
   129  *
   128  */
   130  */
   129 void RadioMainWindow::activateTuningView()
   131 void RadioMainWindow::activateTuningView()
   130 {
   132 {
   131     activateView( mTuningView, DOCML_TUNINGVIEW_FILE, Hb::ViewSwitchUseBackAnim );
   133     activateView( mTuningView, DOCML::FILE_TUNINGVIEW, Hb::ViewSwitchUseBackAnim );
   132 }
       
   133 
       
   134 /*!
       
   135  *
       
   136  */
       
   137 void RadioMainWindow::activateWizardView()
       
   138 {
       
   139     activateView( mWizardView, DOCML_WIZARDVIEW_FILE );
       
   140 }
   134 }
   141 
   135 
   142 /*!
   136 /*!
   143  *
   137  *
   144  */
   138  */
   145 void RadioMainWindow::activateStationsView()
   139 void RadioMainWindow::activateStationsView()
   146 {
   140 {
   147     activateView( mStationsView, DOCML_STATIONSVIEW_FILE );
   141     activateView( mStationsView, DOCML::FILE_STATIONSVIEW );
   148 }
   142 }
   149 
   143 
   150 /*!
   144 /*!
   151  *
   145  *
   152  */
   146  */
   153 void RadioMainWindow::activatePlayLogView()
   147 void RadioMainWindow::activateHistoryView()
   154 {
   148 {
   155     activateView( mPlayLogView, DOCML_PLAYLOGVIEW_FILE );
   149     activateView( mHistoryView, DOCML::FILE_HISTORYVIEW );
   156 }
   150 }
   157 
   151 
   158 /*!
   152 /*!
   159  * Private slot
   153  * Private slot
   160  *
   154  *
   172  * Private slot
   166  * Private slot
   173  *
   167  *
   174  */
   168  */
   175 void RadioMainWindow::showVolumeLevel( int volume )
   169 void RadioMainWindow::showVolumeLevel( int volume )
   176 {
   170 {
   177     if ( !mVolSlider )
   171     if ( !mVolSlider ) {
   178     {
   172         mVolSlider.reset( new HbVolumeSliderPopup() );
   179         mVolSlider = VolumeSliderPtr( new HbVolumeSliderPopup() );
       
   180         mVolSlider->setRange( 0, KMaximumVolumeLevel );
   173         mVolSlider->setRange( 0, KMaximumVolumeLevel );
   181         mVolSlider->setSingleStep( 1 );
   174         mVolSlider->setSingleStep( 1 );
   182         mVolSlider->setTimeout( KVolumeSliderDelay );
   175         mVolSlider->setTimeout( KVolumeSliderDelay );
   183         connectAndTest( mVolSlider.data(),  SIGNAL(valueChanged(int)),
   176         connectAndTest( mVolSlider.data(),  SIGNAL(valueChanged(int)),
   184                         mUiEngine,          SLOT(setVolume(int)) );
   177                         mUiEngine,          SLOT(setVolume(int)) );
   191 
   184 
   192 /*!
   185 /*!
   193  * Private slot
   186  * Private slot
   194  *
   187  *
   195  */
   188  */
   196 void RadioMainWindow::headsetStatusChanged( bool connected )
   189 void RadioMainWindow::updateAntennaStatus( bool connected )
   197 {
   190 {
   198     if ( !connected ) {
   191     if ( !connected ) {
   199         HbMessageBox infoBox( hbTrId( "txt_rad_dpophead_connect_wired_headset" ) );
   192         HbMessageBox infoBox( hbTrId( "txt_rad_dpophead_connect_wired_headset" ) );
   200         infoBox.exec();
   193         infoBox.exec();
   201     }
   194     }
   219 
   212 
   220     bool viewCreated = false;
   213     bool viewCreated = false;
   221     if ( !aMember ) {
   214     if ( !aMember ) {
   222         viewCreated = true;
   215         viewCreated = true;
   223 
   216 
   224         RadioXmlUiLoader* uiLoader = new RadioXmlUiLoader( *this );
   217         RadioXmlUiLoader* uiLoader = new RadioXmlUiLoader();
   225         bool ok = false;
   218         bool ok = false;
   226 
   219 
   227         // View takes ownership of the ui loader when it is created inside the load function
   220         // View takes ownership of the ui loader when it is created inside the load function
   228         uiLoader->load( docmlFile, &ok );
   221         QObjectList objectList = uiLoader->load( docmlFile, &ok );
   229 
   222 
   230         RADIO_ASSERT( ok , "FMRadio", "invalid DocML file" );
   223         RADIO_ASSERT( ok , "FMRadio", "invalid DocML file" );
   231         if ( !ok ) {
   224         if ( !ok ) {
   232             delete uiLoader;
   225             delete uiLoader;
   233             uiLoader = 0;
   226             uiLoader = 0;
   234             return;
   227             return;
   235         }
   228         }
   236 
   229 
   237         aMember = ViewPtr( uiLoader->findObject<RadioViewBase>( DOCML_NAME_VIEW ) );
   230         aMember = ViewPtr( uiLoader->findObject<RadioViewBase>( DOCML::NAME_VIEW ) );
   238         aMember->init( this, &mUiEngine->model() );
   231 
       
   232         foreach( QObject* object, objectList ) {
       
   233             const QString className = object->metaObject()->className();
       
   234             if ( !object->parent() && object != aMember.data() ) {
       
   235                 object->setParent( aMember.data() );
       
   236             }
       
   237         }
       
   238 
       
   239         aMember->init( uiLoader, this );
   239 
   240 
   240         addView( aMember );
   241         addView( aMember );
   241     }
   242     }
   242 
   243 
   243     aMember->updateOrientation( orientation(), viewCreated );
   244     aMember->updateOrientation( orientation(), viewCreated );