mpviewplugins/mpplaybackviewplugin/src/mpplaybackview.cpp
changeset 35 fdb31ab341af
parent 34 2c5162224003
child 37 eb79a7c355bf
equal deleted inserted replaced
34:2c5162224003 35:fdb31ab341af
    13 *
    13 *
    14 * Description: Music Player Playback view.
    14 * Description: Music Player Playback view.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <qpainter>
    18 #include <QPainter>
    19 #include <qtgui>
    19 #include <QtGui>
    20 
    20 
    21 #include <hbmenu.h>
    21 #include <hbmenu.h>
    22 #include <hbinstance.h>
    22 #include <hbinstance.h>
    23 #include <hbtoolbar.h>
    23 #include <hbtoolbar.h>
       
    24 #include <hbtoolbutton.h>
    24 #include <hbaction.h>
    25 #include <hbaction.h>
    25 #include <hbicon.h>
    26 #include <hbicon.h>
    26 #include <QTranslator>
    27 #include <QTranslator>
    27 #include <QLocale>
    28 #include <QLocale>
    28 
    29 
    29 #include "mpplaybackview.h"
    30 #include "mpplaybackview.h"
    30 #include "mpplaybackwidget.h"
    31 #include "mpplaybackwidget.h"
    31 #include "mpengine.h"
    32 #include "mpenginefactory.h"
    32 #include "mpplaybackdata.h"
    33 #include "mpplaybackdata.h"
    33 #include "mpsettingsmanager.h"
    34 #include "mpsettingsmanager.h"
    34 #include "mpcommondefs.h"
    35 #include "mpcommondefs.h"
    35 #include "mptrace.h"
    36 #include "mptrace.h"
    36 #include "mpequalizerwidget.h"
    37 #include "mpequalizerwidget.h"
    58  */
    59  */
    59 MpPlaybackView::MpPlaybackView()
    60 MpPlaybackView::MpPlaybackView()
    60     : mMpEngine( 0 ),
    61     : mMpEngine( 0 ),
    61       mPlaybackData( 0 ),
    62       mPlaybackData( 0 ),
    62       mPlaybackWidget( 0 ),
    63       mPlaybackWidget( 0 ),
    63       mEqualizerWidget( new MpEqualizerWidget() ),
    64       mEqualizerWidget( 0 ),
    64       mNavigationBack( 0 ),
    65       mSoftKeyBack( 0 ),
    65       mActivated( false ),
    66       mActivated( false ),
    66       mPlayIcon( 0 ),
    67       mPlayIcon( 0 ),
    67       mPauseIcon( 0 ),
    68       mPauseIcon( 0 ),
    68       mShuffleOnIcon( 0 ),
    69       mShuffleOnIcon( 0 ),
    69       mShuffleOffIcon( 0 ),
    70       mShuffleOffIcon( 0 ),
    70       mMpTranslator( 0 ),
    71       mMpTranslator( 0 ),
    71       mCommonTranslator( 0 )
    72       mCommonTranslator( 0 ),
       
    73       mTimer(0),
       
    74       mSeeking(false)
       
    75 
    72 {
    76 {
    73     TX_LOG
    77     TX_LOG
    74 }
    78 }
    75 
    79 
    76 /*!
    80 /*!
    77  Destructs the playback view.
    81  Destructs the playback view.
    78  */
    82  */
    79 MpPlaybackView::~MpPlaybackView()
    83 MpPlaybackView::~MpPlaybackView()
    80 {
    84 {
    81     TX_ENTRY
    85     TX_ENTRY
    82     delete mNavigationBack;
    86     delete mSoftKeyBack;
    83     delete mPlayIcon;
    87     delete mPlayIcon;
    84     delete mPauseIcon;
    88     delete mPauseIcon;
    85     delete mShuffleOnIcon;
    89     delete mShuffleOnIcon;
    86     delete mShuffleOffIcon;
    90     delete mShuffleOffIcon;
    87     delete mEqualizerWidget;
    91     delete mEqualizerWidget;
   117         qApp->installTranslator( mCommonTranslator );
   121         qApp->installTranslator( mCommonTranslator );
   118     }
   122     }
   119 
   123 
   120     mWindow = mainWindow();
   124     mWindow = mainWindow();
   121 
   125 
   122     mNavigationBack = new HbAction( Hb::BackNaviAction, this );
   126     mSoftKeyBack = new HbAction( Hb::BackNaviAction, this );
   123     connect( mNavigationBack, SIGNAL( triggered() ), this, SLOT( back() ) );
   127     connect( mSoftKeyBack, SIGNAL( triggered() ), this, SLOT( back() ) );
   124 
   128 
   125     mMpEngine = MpEngine::instance();
   129     mMpEngine = MpEngineFactory::sharedEngine();
   126     mPlaybackData = mMpEngine->playbackData();
   130     mPlaybackData = mMpEngine->playbackData();
   127     connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   131     connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   128              this, SLOT( playbackStateChanged() ) );
   132              this, SLOT( playbackStateChanged() ) );
   129 
   133 
   130     mPlaybackWidget = new MpPlaybackWidget( mPlaybackData );
   134     mPlaybackWidget = new MpPlaybackWidget( mPlaybackData );
   131     connect( mPlaybackWidget, SIGNAL( setPlaybackPosition( int ) ), mMpEngine, SLOT( setPosition( int ) ) );
   135     connect( mPlaybackWidget, SIGNAL( setPlaybackPosition( int ) ), mMpEngine, SLOT( setPosition( int ) ) );
   132 
   136     //repeat should not be displayed on fetcher or embedded.
       
   137     mRepeat = mViewMode == MpCommon::DefaultView ? MpSettingsManager::repeat() : false;
       
   138     mPlaybackWidget->repeatChanged( mRepeat );
   133     setWidget( mPlaybackWidget );
   139     setWidget( mPlaybackWidget );
   134     setupMenu();
   140     setupMenu();
   135     setupToolbar();
   141     setupToolbar();
   136 
   142     
   137     mEqualizerWidget->prepareDialog();
   143     //Connect FF and RW buttons when view (toolbar) is ready
   138 
   144     connect ( mWindow, SIGNAL( viewReady() ), this, SLOT( connectButtons() ) );
   139     // Observe changes in settings.
   145     
   140     connect( MpSettingsManager::instance(), SIGNAL( shuffleChanged( bool ) ),
   146     if ( mViewMode == MpCommon::DefaultView ) {
   141              this, SLOT( shuffleChanged( bool ) ) );
   147         mEqualizerWidget = new MpEqualizerWidget();
   142     connect( MpSettingsManager::instance(), SIGNAL( repeatChanged( bool ) ),
   148         mEqualizerWidget->prepareDialog();
   143              this, SLOT( repeatChanged( bool ) ) );
   149         // Observe changes in settings.
       
   150         connect( MpSettingsManager::instance(), SIGNAL( shuffleChanged( bool ) ),
       
   151                  this, SLOT( shuffleChanged( bool ) ) );
       
   152         connect( MpSettingsManager::instance(), SIGNAL( repeatChanged( bool ) ),
       
   153                  this, SLOT( repeatChanged( bool ) ) );
       
   154     }
   144 
   155 
   145     TX_EXIT
   156     TX_EXIT
   146 }
   157 }
   147 
   158 
   148 /*!
   159 /*!
   150  */
   161  */
   151 void MpPlaybackView::activateView()
   162 void MpPlaybackView::activateView()
   152 {
   163 {
   153     TX_ENTRY
   164     TX_ENTRY
   154     mActivated = true;
   165     mActivated = true;
   155     setNavigationAction( mNavigationBack );
   166     setNavigationAction( mSoftKeyBack );
   156     TX_EXIT
   167     TX_EXIT
   157 }
   168 }
   158 
   169 
   159 /*!
   170 /*!
   160  Deactivates the playback view.
   171  Deactivates the playback view.
   161  */
   172  */
   162 void MpPlaybackView::deactivateView()
   173 void MpPlaybackView::deactivateView()
   163 {
   174 {
   164     TX_ENTRY
   175     TX_ENTRY
   165     if ( mEqualizerWidget->isActive() ) {
   176     if ( mEqualizerWidget && mEqualizerWidget->isActive() ) {
   166         mEqualizerWidget->close();
   177         mEqualizerWidget->close();
   167     }
   178     }
   168 
   179 
   169     menu()->close();
   180     menu()->close();
   170 
   181 
   220  Slot to handle playback state changed.
   231  Slot to handle playback state changed.
   221  */
   232  */
   222 void MpPlaybackView::playbackStateChanged()
   233 void MpPlaybackView::playbackStateChanged()
   223 {
   234 {
   224     TX_ENTRY
   235     TX_ENTRY
   225     switch ( mPlaybackData->playbackState() ) {
   236     updatePlayPauseIcon();
   226         case MpPlaybackData::Playing:
   237     if ( MpPlaybackData::Stopped == mPlaybackData->playbackState() && mViewMode == MpCommon::FetchView ) {
   227             TX_LOG_ARGS( "MpPlaybackData::Playing" )
   238           back();
   228             mPlayPauseAction->setIcon( *mPauseIcon );
       
   229             break;
       
   230         case MpPlaybackData::Paused:
       
   231             TX_LOG_ARGS( "MpPlaybackData::Paused" )
       
   232             mPlayPauseAction->setIcon( *mPlayIcon );
       
   233             break;
       
   234         case MpPlaybackData::Stopped:
       
   235             TX_LOG_ARGS( "MpPlaybackData::Paused" )
       
   236             if ( mViewMode == MpCommon::FetchView ) {
       
   237                 back();
       
   238             }
       
   239             else {
       
   240                 // Treat it like pause in default mode
       
   241                 mPlayPauseAction->setIcon( *mPlayIcon );
       
   242             }
       
   243             break;
       
   244         default:
       
   245             break;
       
   246     }
   239     }
   247     TX_EXIT
   240     TX_EXIT
   248 }
   241 }
   249 
   242 
   250 /*!
   243 /*!
   289  */
   282  */
   290 void MpPlaybackView::repeatChanged( bool repeat )
   283 void MpPlaybackView::repeatChanged( bool repeat )
   291 {
   284 {
   292     mRepeat = repeat;
   285     mRepeat = repeat;
   293     mRepeatAction->setText( mRepeat ?  hbTrId( "txt_mus_opt_repeat_off" ) : hbTrId( "txt_mus_opt_repeat_on" ) );
   286     mRepeatAction->setText( mRepeat ?  hbTrId( "txt_mus_opt_repeat_off" ) : hbTrId( "txt_mus_opt_repeat_on" ) );
       
   287     mPlaybackWidget->repeatChanged( repeat );
   294 }
   288 }
   295 
   289 
   296 /*!
   290 /*!
   297  Slot called when a song is selected in fetch mode.
   291  Slot called when a song is selected in fetch mode.
   298  */
   292  */
   327  setup the toolbar.
   321  setup the toolbar.
   328  */
   322  */
   329 void MpPlaybackView::setupToolbar()
   323 void MpPlaybackView::setupToolbar()
   330 {
   324 {
   331     TX_ENTRY
   325     TX_ENTRY
   332     HbToolBar *toolBar = this->toolBar();
   326     HbToolBar *myToolBar = toolBar();
   333     toolBar->setOrientation( Qt::Horizontal );
   327     myToolBar->setOrientation( Qt::Horizontal );
   334     QActionGroup *actionsGroup = new QActionGroup( toolBar );
   328     QActionGroup *actionsGroup = new QActionGroup( myToolBar );
   335 
   329 
   336     if ( mViewMode == MpCommon::DefaultView || mViewMode == MpCommon::EmbeddedView ) {
   330     if ( mViewMode == MpCommon::DefaultView || mViewMode == MpCommon::EmbeddedView ) {
   337         mShuffleOnIcon = new HbIcon( "qtg_mono_shuffle" );
   331         mShuffleOnIcon = new HbIcon( "qtg_mono_shuffle" );
   338         mShuffleOffIcon = new HbIcon( "qtg_mono_shuffle_off" );
   332         mShuffleOffIcon = new HbIcon( "qtg_mono_shuffle_off" );
   339         mShuffleAction = new HbAction( actionsGroup );
   333         mShuffleAction = new HbAction( actionsGroup );
   347         }
   341         }
   348         else {
   342         else {
   349             mShuffleAction->setEnabled( false );
   343             mShuffleAction->setEnabled( false );
   350         }
   344         }
   351         
   345         
   352         toolBar->addAction( mShuffleAction );
   346         myToolBar->addAction( mShuffleAction );
   353 
   347 
   354         HbAction *action = new HbAction( actionsGroup );
   348         HbAction *action = new HbAction( actionsGroup );
   355         action->setIcon( HbIcon( "qtg_mono_previous" ) );
   349         action->setIcon( HbIcon( "qtg_mono_seek_previous" ) );
   356         action->setCheckable( false );
   350         action->setCheckable( false );
   357         connect( action, SIGNAL( triggered( bool ) ),
   351         action->setObjectName("previous");
   358                  mMpEngine, SLOT( skipBackward() ) );
   352         myToolBar->addAction( action );
   359         toolBar->addAction( action );
   353         
   360 
       
   361         mPlayPauseAction = new HbAction( actionsGroup );
   354         mPlayPauseAction = new HbAction( actionsGroup );
   362         mPlayIcon = new HbIcon( "qtg_mono_play" );
   355         mPlayIcon = new HbIcon( "qtg_mono_play" );
   363         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   356         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   364         mPlayPauseAction->setIcon( *mPlayIcon );
   357         updatePlayPauseIcon();
   365         mPlayPauseAction->setCheckable( false );
   358         mPlayPauseAction->setCheckable( false );
   366         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   359         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   367                  mMpEngine, SLOT( playPause() ) );
   360                  mMpEngine, SLOT( playPause() ) );
   368         toolBar->addAction( mPlayPauseAction );
   361         myToolBar->addAction( mPlayPauseAction );
   369 
   362 
   370         action = new HbAction( actionsGroup );
   363         action = new HbAction( actionsGroup );
   371         action->setIcon( HbIcon( "qtg_mono_next" ) );
   364         action->setIcon( HbIcon( "qtg_mono_seek_next" ) );
   372         action->setCheckable( false );
   365         action->setCheckable( false );
   373         connect( action, SIGNAL( triggered( bool ) ),
   366         action->setObjectName("next");
   374                  mMpEngine, SLOT( skipForward() ) );
   367         myToolBar->addAction( action );
   375         toolBar->addAction( action );
       
   376 
   368 
   377         HbIcon icon( "qtg_mono_info" );
   369         HbIcon icon( "qtg_mono_info" );
   378         action = new HbAction( actionsGroup );
   370         action = new HbAction( actionsGroup );
   379         action->setIcon( icon );
   371         action->setIcon( icon );
   380         action->setCheckable( false );
   372         action->setCheckable( false );
   381         //TODO: Remove once song details takes hostUid from engine
   373 
   382         if ( mViewMode == MpCommon::DefaultView ) {
   374         connect( action, SIGNAL( triggered( bool ) ),
   383             connect( action, SIGNAL( triggered( bool ) ),
   375                  this, SLOT( flip() ) );
   384                      this, SLOT( flip() ) );
   376 
   385         }
   377         myToolBar->addAction( action );
   386         else {
       
   387             action->setEnabled( false );
       
   388         }
       
   389         toolBar->addAction( action );
       
   390     }
   378     }
   391     else {
   379     else {
   392         // Fetch mode
   380         // Fetch mode
   393         HbAction *action = new HbAction( actionsGroup );
   381         HbAction *action = new HbAction( actionsGroup );
   394         action->setIcon( HbIcon( "qtg_mono_tick" ) );
   382         action->setIcon( HbIcon( "qtg_mono_tick" ) );
   395         action->setCheckable( false );
   383         action->setCheckable( false );
   396         connect( action, SIGNAL( triggered( bool ) ),
   384         connect( action, SIGNAL( triggered( bool ) ),
   397                  this, SLOT( handleSongSelected() ) );
   385                  this, SLOT( handleSongSelected() ) );
   398         toolBar->addAction( action );
   386         myToolBar->addAction( action );
   399 
   387 
   400         mPlayPauseAction = new HbAction( actionsGroup );
   388         mPlayPauseAction = new HbAction( actionsGroup );
   401         mPlayIcon = new HbIcon( "qtg_mono_play" );
   389         mPlayIcon = new HbIcon( "qtg_mono_play" );
   402         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   390         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   403         mPlayPauseAction->setIcon( *mPlayIcon );
   391         updatePlayPauseIcon();
   404         mPlayPauseAction->setCheckable( false );
   392         mPlayPauseAction->setCheckable( false );
   405         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   393         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   406                  mMpEngine, SLOT( playPause() ) );
   394                  mMpEngine, SLOT( playPause() ) );
   407         toolBar->addAction( mPlayPauseAction );
   395         myToolBar->addAction( mPlayPauseAction );
   408     }
   396     }
   409     
   397     
   410     
   398     
   411     TX_EXIT
   399     TX_EXIT
   412 }
   400 }
   413 
   401 
       
   402 /*!
       
   403  Updates the play pause icon on the toolbar base on playback state.
       
   404  */
       
   405 void MpPlaybackView::updatePlayPauseIcon()
       
   406 {
       
   407     TX_ENTRY
       
   408     switch ( mPlaybackData->playbackState() ) {
       
   409         case MpPlaybackData::Playing:
       
   410         case MpPlaybackData::NotPlaying:
       
   411             TX_LOG_ARGS( "MpPlaybackData::Playing" )
       
   412             mPlayPauseAction->setIcon( *mPauseIcon );
       
   413             break;
       
   414         case MpPlaybackData::Paused:
       
   415         case MpPlaybackData::Stopped:
       
   416             TX_LOG_ARGS( "MpPlaybackData::Paused" )
       
   417             mPlayPauseAction->setIcon( *mPlayIcon );
       
   418             break;
       
   419 
       
   420         default:
       
   421             break;
       
   422     }
       
   423     TX_EXIT
       
   424 }
       
   425 
       
   426 /*!
       
   427  start rewind long press detection
       
   428  */
       
   429 void MpPlaybackView::startRewindTimer()
       
   430 {
       
   431     if(mTimer){
       
   432         delete mTimer;
       
   433         mTimer = 0;
       
   434     }
       
   435     mTimer = new QTimer(this);
       
   436     mTimer->setSingleShot(true);
       
   437     connect(mTimer, SIGNAL(timeout()), this, SLOT(startSeekRewind()));
       
   438     mTimer->start(600);    
       
   439 }
       
   440 
       
   441 /*!
       
   442  start fast forward long press detection
       
   443  */
       
   444 void MpPlaybackView::startForwardTimer()
       
   445 {
       
   446     if(mTimer){
       
   447         delete mTimer;
       
   448         mTimer = 0;
       
   449     }
       
   450     mTimer = new QTimer(this);
       
   451     mTimer->setSingleShot(true);
       
   452     connect(mTimer, SIGNAL(timeout()), this, SLOT(startSeekForward()));
       
   453     mTimer->start(600);      
       
   454 }
       
   455 
       
   456 /*!
       
   457  start backward seeking
       
   458  */
       
   459 void MpPlaybackView::startSeekRewind()
       
   460 {
       
   461     mMpEngine->startSeekBackward();
       
   462     mSeeking = true;
       
   463 }
       
   464 
       
   465 /*!
       
   466  start forward seeking
       
   467  */
       
   468 void MpPlaybackView::startSeekForward()
       
   469 {
       
   470     mMpEngine->startSeekForward();
       
   471     mSeeking = true;
       
   472 }
       
   473 
       
   474 /*!
       
   475  end backward seeking or skip backward
       
   476  */
       
   477 void MpPlaybackView::endRewind()
       
   478 {
       
   479     if(mTimer){
       
   480         mTimer->stop();
       
   481         delete mTimer;
       
   482         mTimer = 0;
       
   483     }
       
   484     if( mSeeking ) {
       
   485         mMpEngine->stopSeeking();
       
   486     }
       
   487     else {
       
   488         mMpEngine->skipBackward();
       
   489     }
       
   490     mSeeking = false;
       
   491 }
       
   492 
       
   493 /*!
       
   494  end forward seeking or skip forward
       
   495  */
       
   496 void MpPlaybackView::endForward()
       
   497 {
       
   498     if(mTimer){
       
   499         mTimer->stop();
       
   500         delete mTimer;
       
   501         mTimer = 0;
       
   502     }
       
   503     if( mSeeking ) {
       
   504         mMpEngine->stopSeeking();
       
   505     }
       
   506     else {
       
   507         mMpEngine->skipForward();
       
   508     }
       
   509     mSeeking = false;
       
   510 }
       
   511 
       
   512 /*!
       
   513  Slot to connect seek forward and backward toolbar buttons
       
   514  */
       
   515 void MpPlaybackView::connectButtons()
       
   516 {
       
   517     
       
   518     HbToolBar *myToolBar = toolBar();
       
   519     QGraphicsLayout *layout = myToolBar->layout();
       
   520     if( layout ) {
       
   521         int count = layout->count();
       
   522         for ( int i = 0; i < count; i++ ) {
       
   523             HbToolButton *button = dynamic_cast<HbToolButton *>( layout->itemAt(i) );
       
   524             QString name = button->action()->objectName();
       
   525             
       
   526             if ( name == "previous" ) {
       
   527                 connect( button, SIGNAL( pressed() ),
       
   528                          this, SLOT( startRewindTimer() ) );
       
   529                 connect( button, SIGNAL( released() ),
       
   530                          this, SLOT( endRewind() ) );
       
   531             }
       
   532             if ( name == "next" ) {
       
   533                 connect( button, SIGNAL( pressed() ),
       
   534                          this, SLOT( startForwardTimer() ) );
       
   535                 connect( button, SIGNAL( released() ),
       
   536                          this, SLOT( endForward() ) );
       
   537                 disconnect ( mWindow, SIGNAL( viewReady() ), this, SLOT( connectButtons() ) );
       
   538             }
       
   539         }
       
   540     }
       
   541 }
   414 /*!
   542 /*!
   415  Slot to be called to activate equalizer dialog.
   543  Slot to be called to activate equalizer dialog.
   416  */
   544  */
   417 void MpPlaybackView::showEqualizerDialog()
   545 void MpPlaybackView::showEqualizerDialog()
   418 {
   546 {