radioapp/radiowidgets/src/radioviewbase.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    33  */
    33  */
    34 RadioViewBase::RadioViewBase( bool transient ) :
    34 RadioViewBase::RadioViewBase( bool transient ) :
    35     HbView( 0 ),
    35     HbView( 0 ),
    36     mMainWindow( 0 ),
    36     mMainWindow( 0 ),
    37     mUiLoader( 0 ),
    37     mUiLoader( 0 ),
    38     mInitialized( false ),
       
    39     mTransientView( transient ),
    38     mTransientView( transient ),
    40     mUseLoudspeakerAction( 0 ),
    39     mUseLoudspeakerAction( 0 ),
    41     mOrientation( Qt::Vertical )
    40     mOrientation( Qt::Vertical )
    42 {
    41 {
    43 }
    42 }
    53 }
    52 }
    54 
    53 
    55 /*!
    54 /*!
    56  *
    55  *
    57  */
    56  */
    58 void RadioViewBase::setMembers( RadioUiLoader* uiLoader, RadioWindow* mainWindow )
    57 void RadioViewBase::setMembers( RadioWindow* mainWindow, RadioUiLoader* uiLoader )
    59 {
    58 {
       
    59     mMainWindow = mainWindow;
    60     mUiLoader.reset( uiLoader );
    60     mUiLoader.reset( uiLoader );
    61     mMainWindow = mainWindow;
    61 }
       
    62 
       
    63 /*!
       
    64  *
       
    65  */
       
    66 void RadioViewBase::preLazyLoadInit()
       
    67 {
       
    68     // Default implementation does nothing
       
    69 }
       
    70 
       
    71 /*!
       
    72  *
       
    73  */
       
    74 void RadioViewBase::initialize( QSharedPointer<RadioUiEngine> uiEngine )
       
    75 {
       
    76     mUiEngine = uiEngine;
       
    77     init();
    62 }
    78 }
    63 
    79 
    64 /*!
    80 /*!
    65  *
    81  *
    66  */
    82  */
    67 bool RadioViewBase::isInitialized() const
    83 bool RadioViewBase::isInitialized() const
    68 {
    84 {
    69     return mInitialized;
    85     return mUiEngine;
    70 }
    86 }
    71 
    87 
    72 /*!
    88 /*!
    73  *
    89  *
    74  */
    90  */
    87         setOrientation();
   103         setOrientation();
    88     }
   104     }
    89 }
   105 }
    90 
   106 
    91 /*!
   107 /*!
       
   108  *
       
   109  */
       
   110 void RadioViewBase::bringToForeground()
       
   111 {
       
   112     mMainWindow->raise();
       
   113 }
       
   114 
       
   115 /*!
    92  * Protected slot
   116  * Protected slot
    93  *
   117  *
    94  */
   118  */
    95 void RadioViewBase::updateAudioRouting( bool loudspeaker )
   119 void RadioViewBase::updateAudioRouting( bool loudspeaker )
    96 {
   120 {
   118     qApp->quit();
   142     qApp->quit();
   119 }
   143 }
   120 
   144 
   121 /*!
   145 /*!
   122  * Private slot
   146  * Private slot
   123  * TODO: Refactor this awkwardness once Orbit figures out a better way
       
   124  */
   147  */
   125 void RadioViewBase::handleUserAnswer( HbAction* answer )
   148 void RadioViewBase::handleUserAnswer( HbAction* answer )
   126 {
   149 {
   127     HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() );
   150     HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() );
   128     if( dlg->actions().first() == answer ) {
   151     if( dlg->actions().first() == answer ) {
   135  */
   158  */
   136 void RadioViewBase::initBackAction()
   159 void RadioViewBase::initBackAction()
   137 {
   160 {
   138     // The default back button activates the tuning view
   161     // The default back button activates the tuning view
   139     HbAction* backAction = new HbAction( Hb::BackNaviAction, this );
   162     HbAction* backAction = new HbAction( Hb::BackNaviAction, this );
   140     connectAndTest( backAction,     SIGNAL(triggered()),
   163     Radio::connect( backAction,     SIGNAL(triggered()),
   141                     mMainWindow,    SLOT(activateMainView()) );
   164                     mMainWindow,    SLOT(activateMainView()) );
   142     setNavigationAction( backAction );    
   165     setNavigationAction( backAction );
   143 }
   166 }
   144 
   167 
   145 /*!
   168 /*!
   146  *
   169  *
   147  */
   170  */
   148 void RadioViewBase::connectCommonMenuItem( int menuItem )
   171 void RadioViewBase::connectCommonMenuItem( int menuItem )
   149 {
   172 {
   150     RadioUiEngine* engine = &mMainWindow->uiEngine();
       
   151     switch ( menuItem ) {
   173     switch ( menuItem ) {
   152         case MenuItem::UseLoudspeaker:
   174         case MenuItem::UseLoudspeaker:
   153             mUseLoudspeakerAction = mUiLoader->findObject<HbAction>( DOCML::NAME_LOUDSPEAKER_ACTION );
   175             mUseLoudspeakerAction = mUiLoader->findObject<HbAction>( DOCML::NAME_LOUDSPEAKER_ACTION );
   154             if ( mUseLoudspeakerAction ) {
   176             if ( mUseLoudspeakerAction ) {
   155                 connectAndTest( mUseLoudspeakerAction, SIGNAL(triggered()), engine, SLOT(toggleAudioRoute()) );
   177                 Radio::connect( mUseLoudspeakerAction, SIGNAL(triggered()), mUiEngine.data(), SLOT(toggleAudioRoute()) );
   156                 updateAudioRouting( engine->isUsingLoudspeaker() );
   178                 updateAudioRouting( mUiEngine->isUsingLoudspeaker() );
   157                 connectAndTest( engine, SIGNAL(audioRouteChanged(bool)), this, SLOT(updateAudioRouting(bool)) );
   179                 Radio::connect( mUiEngine.data(), SIGNAL(audioRouteChanged(bool)), this, SLOT(updateAudioRouting(bool)) );
   158             }
   180             }
   159             break;
   181             break;
   160 
   182 
       
   183         case MenuItem::Exit:
       
   184             if ( HbAction* exitAction = mUiLoader->findObject<HbAction>( DOCML::NAME_EXIT_ACTION ) ) {
       
   185                 Radio::connect( exitAction, SIGNAL(triggered()), this, SLOT(quit()) );
       
   186             }
       
   187             break;
       
   188 
   161         default:
   189         default:
   162             break;
   190             break;
   163     }
   191     }
   164 }
   192 }
   165 
   193 
   166 /*!
   194 /*!
   167  *
   195  *
   168  */
   196  */
   169 void RadioViewBase::connectXmlElement( const char* name, const char* signal, QObject* receiver, const char* slot )
   197 void RadioViewBase::connectXmlElement( const QString& name, const char* signal, QObject* receiver, const char* slot )
   170 {
   198 {
   171     if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) {
   199     if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) {
   172         connectAndTest( action, signal, receiver, slot );
   200         Radio::connect( action, signal, receiver, slot );
   173     }
   201     }
   174 }
   202 }
   175 
   203 
   176 /*!
   204 /*!
   177  *
   205  *
   178  */
   206  */
   179 void RadioViewBase::connectViewChangeMenuItem( QString name, const char* slot )
   207 void RadioViewBase::connectViewChangeMenuItem( QString name, const char* slot )
   180 {
   208 {
   181     if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) {
   209     if ( QObject* action = mUiLoader->findObject<QObject>( name ) ) {
   182         connectAndTest( action, SIGNAL(triggered()), mMainWindow, slot );
   210         Radio::connect( action, SIGNAL(triggered()), mMainWindow, slot );
   183     }
   211     }
   184 }
   212 }
   185 
   213 
   186 /*!
   214 /*!
   187  *
   215  *
   188  */
   216  */
   189 void RadioViewBase::loadSection( const QString& docml, const QString& section )
   217 void RadioViewBase::loadSection( const QString& docml, const QString& section )
   190 {
   218 {
   191     LOG_FORMAT( "RadioViewBase::loadSection: Docml: %s, section: %s", GETSTRING( docml ), GETSTRING( section ) );
   219     LOG_FORMAT( "RadioViewBase::loadSection: Docml: %s, section: %s", GETSTRING( docml ), GETSTRING( section ) );
   192     bool ok = false;    
   220     bool ok = false;
   193     mUiLoader->load( docml, section, &ok );
   221     mUiLoader->load( docml, section, &ok );
   194     LOG_ASSERT( ok, LOG_FORMAT( "Loading of section %s failed!", GETSTRING( section ) ) );
   222     LOG_ASSERT( ok, LOG_FORMAT( "Loading of section %s failed!", GETSTRING( section ) ) );
   195 }
   223 }
   196 
   224 
   197 /*!
   225 /*!