mpviewplugins/mpplaybackviewplugin/src/mpplaybackview.cpp
changeset 20 82baf59ce8dd
parent 19 4e84c994a771
child 22 ecf06a08d4d9
equal deleted inserted replaced
19:4e84c994a771 20:82baf59ce8dd
    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 <hbaction.h>
    24 #include <hbaction.h>
    25 #include <hbicon.h>
    25 #include <hbicon.h>
       
    26 #include <QTranslator>
       
    27 #include <QLocale>
    26 
    28 
    27 #include "mpplaybackview.h"
    29 #include "mpplaybackview.h"
    28 #include "mpplaybackwidget.h"
    30 #include "mpplaybackwidget.h"
    29 #include "mpmpxpbframeworkwrapper.h"
    31 #include "mpmpxpbframeworkwrapper.h"
    30 #include "mpplaybackdata.h"
    32 #include "mpplaybackdata.h"
    31 #include "mpsettingsmanager.h"
    33 #include "mpsettingsmanager.h"
    32 #include "mpcommondefs.h"
    34 #include "mpcommondefs.h"
    33 #include "mptrace.h"
    35 #include "mptrace.h"
       
    36 #include "mpequalizerwidget.h"
    34 
    37 
    35 
    38 
    36 /*!
    39 /*!
    37     \class MpPlaybackView
    40     \class MpPlaybackView
    38     \brief Music Player playback view.
    41     \brief Music Player playback view.
    52 
    55 
    53 /*!
    56 /*!
    54  Constructs the playback view.
    57  Constructs the playback view.
    55  */
    58  */
    56 MpPlaybackView::MpPlaybackView()
    59 MpPlaybackView::MpPlaybackView()
    57     : mFrameworkWrapper(0),
    60     : mFrameworkWrapper( 0 ),
    58       mPlaybackData(0),
    61       mPlaybackData( 0 ),
    59       mPlaybackWidget(0),
    62       mPlaybackWidget( 0 ),
    60       mSoftKeyBack(0),
    63       mEqualizerWidget( new MpEqualizerWidget() ),
    61       mActivated(false),
    64       mSoftKeyBack( 0 ),
    62       mPlayIcon(0),
    65       mActivated( false ),
    63       mPauseIcon(0),
    66       mPlayIcon( 0 ),
    64       mShuffleOnIcon(0),
    67       mPauseIcon( 0 ),
    65       mShuffleOffIcon(0)
    68       mShuffleOnIcon( 0 ),
       
    69       mShuffleOffIcon( 0 ),
       
    70       mMpTranslator( 0 ),
       
    71       mCommonTranslator( 0 )
    66 {
    72 {
    67     TX_LOG
    73     TX_LOG
    68 }
    74 }
    69 
    75 
    70 /*!
    76 /*!
    77     delete mSoftKeyBack;
    83     delete mSoftKeyBack;
    78     delete mPlayIcon;
    84     delete mPlayIcon;
    79     delete mPauseIcon;
    85     delete mPauseIcon;
    80     delete mShuffleOnIcon;
    86     delete mShuffleOnIcon;
    81     delete mShuffleOffIcon;
    87     delete mShuffleOffIcon;
       
    88     delete mEqualizerWidget;
       
    89     delete mMpTranslator;
       
    90     delete mCommonTranslator;
    82     TX_EXIT
    91     TX_EXIT
    83 }
    92 }
    84 
    93 
    85 
    94 
    86 /*!
    95 /*!
    88  */
    97  */
    89 void MpPlaybackView::initializeView()
    98 void MpPlaybackView::initializeView()
    90 {
    99 {
    91     TX_ENTRY
   100     TX_ENTRY
    92 
   101 
       
   102     //Load musicplayer and common translators
       
   103     QString lang = QLocale::system().name();
       
   104     QString path = QString( "z:/resource/qt/translations/" );
       
   105     bool translatorLoaded = false;
       
   106 
       
   107     mMpTranslator = new QTranslator( this );
       
   108     translatorLoaded = mMpTranslator->load( path + "musicplayer_" + lang );
       
   109     TX_LOG_ARGS( "Loading translator ok=" << translatorLoaded );
       
   110     if ( translatorLoaded ) {
       
   111         qApp->installTranslator( mMpTranslator );
       
   112     }
       
   113 
       
   114     mCommonTranslator = new QTranslator( this );
       
   115     translatorLoaded = mCommonTranslator->load( path + "common_" + lang );
       
   116     TX_LOG_ARGS( "Loading common translator ok=" << translatorLoaded );
       
   117     if ( translatorLoaded ) {
       
   118         qApp->installTranslator( mCommonTranslator );
       
   119     }
       
   120 
    93     mWindow = mainWindow();
   121     mWindow = mainWindow();
    94 
   122 
    95     mSoftKeyBack = new HbAction(Hb::BackAction, this);
   123     mSoftKeyBack = new HbAction( Hb::BackAction, this );
    96     connect( mSoftKeyBack, SIGNAL(triggered()), this, SLOT(back()) );
   124     connect( mSoftKeyBack, SIGNAL( triggered() ), this, SLOT( back() ) );
    97 
   125 
    98     mFrameworkWrapper = new MpMpxPbFrameworkWrapper();
   126     mFrameworkWrapper = new MpMpxPbFrameworkWrapper();
    99     mPlaybackData = mFrameworkWrapper->playbackData();
   127     mPlaybackData = mFrameworkWrapper->playbackData();
   100     connect( mPlaybackData, SIGNAL(playbackStateChanged()),
   128     connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
   101              this, SLOT(playbackStateChanged()) );
   129              this, SLOT( playbackStateChanged() ) );
   102 
   130 
   103     mPlaybackWidget = new MpPlaybackWidget(mPlaybackData);
   131     mPlaybackWidget = new MpPlaybackWidget( mPlaybackData );
   104     connect( mPlaybackWidget, SIGNAL(setPlaybackPosition(int)), mFrameworkWrapper, SLOT( setPosition(int) ) );
   132     connect( mPlaybackWidget, SIGNAL( setPlaybackPosition( int ) ), mFrameworkWrapper, SLOT( setPosition( int ) ) );
   105 
   133 
   106     setWidget(mPlaybackWidget);
   134     setWidget( mPlaybackWidget );
   107     setupMenu();
   135     setupMenu();
   108     setupToolbar();
   136     setupToolbar();
   109 
   137 
       
   138     mEqualizerWidget->prepareDialog();
       
   139 
   110     // Observe changes in settings.
   140     // Observe changes in settings.
   111     connect( MpSettingsManager::instance(), SIGNAL(shuffleChanged(bool)),
   141     connect( MpSettingsManager::instance(), SIGNAL( shuffleChanged( bool ) ),
   112              this, SLOT(shuffleChanged(bool)) );
   142              this, SLOT( shuffleChanged( bool ) ) );
   113     connect( MpSettingsManager::instance(), SIGNAL(repeatChanged(bool)),
   143     connect( MpSettingsManager::instance(), SIGNAL( repeatChanged( bool ) ),
   114              this, SLOT(repeatChanged(bool)) );
   144              this, SLOT( repeatChanged( bool ) ) );
   115 
   145 
   116     TX_EXIT
   146     TX_EXIT
   117 }
   147 }
   118 
   148 
   119 /*!
   149 /*!
   121  */
   151  */
   122 void MpPlaybackView::activateView()
   152 void MpPlaybackView::activateView()
   123 {
   153 {
   124     TX_ENTRY
   154     TX_ENTRY
   125     mActivated = true;
   155     mActivated = true;
   126     mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack);
   156     setNavigationAction( mSoftKeyBack );
   127     TX_EXIT
   157     TX_EXIT
   128 }
   158 }
   129 
   159 
   130 /*!
   160 /*!
   131  Deactivates the playback view.
   161  Deactivates the playback view.
   132  */
   162  */
   133 void MpPlaybackView::deactivateView()
   163 void MpPlaybackView::deactivateView()
   134 {
   164 {
   135     TX_ENTRY
   165     TX_ENTRY
   136     mWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack);
   166     if ( mEqualizerWidget->isActive() ) {
       
   167         mEqualizerWidget->close();
       
   168     }
       
   169 
       
   170     menu()->close();
       
   171 
       
   172     setNavigationAction( 0 );
   137     mActivated = false;
   173     mActivated = false;
   138     TX_EXIT
   174     TX_EXIT
   139 }
   175 }
   140 
   176 
   141 /*!
   177 /*!
   142  Slot to be called to activate collection view.
   178  Slot to be called to activate settings view.
   143  */
   179  */
   144 void MpPlaybackView::startCollectionView()
   180 void MpPlaybackView::startSettingsView()
   145 {
   181 {
   146     TX_LOG
   182     TX_LOG
   147     emit command( MpCommon::ActivateCollectionView );
   183     emit command( MpCommon::ActivateSettingsView );
   148 }
   184 }
   149 
   185 
   150 /*!
   186 /*!
   151  Slot to handle back command from softkey.
   187  Slot to handle back command from softkey.
   152  */
   188  */
   172 }
   208 }
   173 
   209 
   174 /*!
   210 /*!
   175  Slot to handle playback state changed.
   211  Slot to handle playback state changed.
   176  */
   212  */
   177 void MpPlaybackView::playbackStateChanged( )
   213 void MpPlaybackView::playbackStateChanged()
   178 {
   214 {
   179     TX_ENTRY
   215     TX_ENTRY
   180     switch ( mPlaybackData->playbackState() ) {
   216     switch ( mPlaybackData->playbackState() ) {
   181         case MpPlaybackData::Playing:
   217         case MpPlaybackData::Playing:
   182             TX_LOG_ARGS("MpPlaybackData::Playing")
   218             TX_LOG_ARGS( "MpPlaybackData::Playing" )
   183             mPlayPauseAction->setIcon( *mPauseIcon );
   219             mPlayPauseAction->setIcon( *mPauseIcon );
   184             break;
   220             break;
   185         case MpPlaybackData::Paused:
   221         case MpPlaybackData::Paused:
   186             TX_LOG_ARGS("MpPlaybackData::Paused")
   222             TX_LOG_ARGS( "MpPlaybackData::Paused" )
   187             mPlayPauseAction->setIcon( *mPlayIcon );
   223             mPlayPauseAction->setIcon( *mPlayIcon );
   188             break;
   224             break;
   189         case MpPlaybackData::Stopped:
   225         case MpPlaybackData::Stopped:
   190             TX_LOG_ARGS("MpPlaybackData::Paused")
   226             TX_LOG_ARGS( "MpPlaybackData::Paused" )
   191             if ( mViewMode == MpCommon::FetchView ) {
   227             if ( mViewMode == MpCommon::FetchView ) {
   192                 back();
   228                 back();
   193             }
   229             }
   194             else {
   230             else {
   195                 // Treat it like pause in default mode
   231                 // Treat it like pause in default mode
   201     }
   237     }
   202     TX_EXIT
   238     TX_EXIT
   203 }
   239 }
   204 
   240 
   205 /*!
   241 /*!
       
   242  Slot to handle flip action.
       
   243  */
       
   244 void MpPlaybackView::flip()
       
   245 {
       
   246     TX_ENTRY
       
   247     emit command( MpCommon::ActivateDetailsView );
       
   248     TX_EXIT
       
   249 }
       
   250 
       
   251 /*!
   206  Slot to handle shuffle toggle.
   252  Slot to handle shuffle toggle.
   207  */
   253  */
   208 void MpPlaybackView::toggleShuffle()
   254 void MpPlaybackView::toggleShuffle()
   209 {
   255 {
   210     mFrameworkWrapper->setShuffle( !mShuffle );
   256     mFrameworkWrapper->setShuffle( !mShuffle );
   211     MpSettingsManager::setShuffle(!mShuffle);
   257     MpSettingsManager::setShuffle( !mShuffle );
   212 }
   258 }
   213 
   259 
   214 /*!
   260 /*!
   215  Slot to handle /a shuffle setting change.
   261  Slot to handle /a shuffle setting change.
   216  */
   262  */
   217 void MpPlaybackView::shuffleChanged( bool shuffle )
   263 void MpPlaybackView::shuffleChanged( bool shuffle )
   218 {
   264 {
   219     mShuffle = shuffle;
   265     mShuffle = shuffle;
   220     mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon);
   266     mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon );
   221 }
   267 }
   222 
   268 
   223 /*!
   269 /*!
   224  Slot to handle repeat toggle.
   270  Slot to handle repeat toggle.
   225  */
   271  */
   226 void MpPlaybackView::toggleRepeat()
   272 void MpPlaybackView::toggleRepeat()
   227 {
   273 {
   228     mFrameworkWrapper->setRepeat(!mRepeat);
   274     mFrameworkWrapper->setRepeat( !mRepeat );
   229     MpSettingsManager::setRepeat(!mRepeat);
   275     MpSettingsManager::setRepeat( !mRepeat );
   230 }
   276 }
   231 
   277 
   232 /*!
   278 /*!
   233  Slot to handle /a repeat setting change.
   279  Slot to handle /a repeat setting change.
   234  */
   280  */
   235 void MpPlaybackView::repeatChanged(bool repeat)
   281 void MpPlaybackView::repeatChanged( bool repeat )
   236 {
   282 {
   237     mRepeat = repeat;
   283     mRepeat = repeat;
   238     mRepeatAction->setText( mRepeat ?  tr("Repeat off") : tr("Repeat on"));
   284     mRepeatAction->setText( mRepeat ?  hbTrId( "txt_mus_opt_repeat_off" ) : hbTrId( "txt_mus_opt_repeat_on" ) );
   239 }
   285 }
   240 
   286 
   241 /*!
   287 /*!
   242  Slot called when a song is selected in fetch mode.
   288  Slot called when a song is selected in fetch mode.
   243  */
   289  */
   256 {
   302 {
   257     TX_ENTRY
   303     TX_ENTRY
   258     if ( mViewMode == MpCommon::DefaultView ) {
   304     if ( mViewMode == MpCommon::DefaultView ) {
   259         mRepeat = MpSettingsManager::repeat();
   305         mRepeat = MpSettingsManager::repeat();
   260         HbMenu* myMenu = new HbMenu();
   306         HbMenu* myMenu = new HbMenu();
   261         connect( myMenu->addAction(tr("Go to music library")), SIGNAL(triggered()), this, SLOT(startCollectionView()) );
   307         connect( myMenu->addAction( hbTrId( "txt_mus_opt_equalizer" ) ), SIGNAL( triggered() ), this, SLOT( showEqualizerDialog() ) );
   262         mRepeatAction = myMenu->addAction( mRepeat ?  tr("Repeat off") : tr("Repeat on"));
   308         connect( myMenu->addAction( hbTrId( "txt_mus_opt_audio_effects" ) ), SIGNAL( triggered() ), this, SLOT( startSettingsView() ) );
   263         connect( mRepeatAction , SIGNAL(triggered()), this, SLOT(toggleRepeat()) );
   309         mRepeatAction = myMenu->addAction( mRepeat ?  hbTrId( "txt_mus_opt_repeat_off" ) : hbTrId( "txt_mus_opt_repeat_on" ) );
   264         connect( myMenu->addAction(tr("Exit")), SIGNAL(triggered()), this, SLOT(exit()) );
   310         connect( mRepeatAction , SIGNAL( triggered() ), this, SLOT( toggleRepeat() ) );
   265         setMenu(myMenu);
   311         connect( myMenu->addAction( hbTrId( "txt_common_opt_exit" ) ), SIGNAL( triggered() ), this, SLOT( exit() ) );
       
   312         setMenu( myMenu );
   266     }
   313     }
   267     TX_EXIT
   314     TX_EXIT
   268 }
   315 }
   269 
   316 
   270 /*!
   317 /*!
   272  */
   319  */
   273 void MpPlaybackView::setupToolbar()
   320 void MpPlaybackView::setupToolbar()
   274 {
   321 {
   275     TX_ENTRY
   322     TX_ENTRY
   276     HbToolBar *toolBar = this->toolBar();
   323     HbToolBar *toolBar = this->toolBar();
   277     toolBar->setOrientation(Qt::Horizontal);
   324     toolBar->setOrientation( Qt::Horizontal );
   278     QActionGroup *actionsGroup = new QActionGroup( toolBar );
   325     QActionGroup *actionsGroup = new QActionGroup( toolBar );
   279 
   326 
   280     if ( mViewMode == MpCommon::DefaultView ) {
   327     if ( mViewMode == MpCommon::DefaultView ) {
   281         mShuffleOnIcon = new HbIcon(":/playbackviewicons/shuffle_on.svg");
   328         mShuffleOnIcon = new HbIcon( "qtg_mono_shuffle" );
   282         mShuffleOffIcon = new HbIcon( ":/playbackviewicons/shuffle_off.svg");
   329         mShuffleOffIcon = new HbIcon( "qtg_mono_shuffle_off" );
   283         mShuffleAction = new HbAction(actionsGroup);
   330         mShuffleAction = new HbAction( actionsGroup );
   284         mShuffle = MpSettingsManager::shuffle();
   331         mShuffle = MpSettingsManager::shuffle();
   285         mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon);
   332         mShuffleAction->setIcon( mShuffle ? *mShuffleOnIcon : *mShuffleOffIcon );
   286         mShuffleAction->setCheckable( false );
   333         mShuffleAction->setCheckable( false );
   287 
   334 
   288         connect( mShuffleAction, SIGNAL(triggered(bool)),
   335         connect( mShuffleAction, SIGNAL( triggered( bool ) ),
   289                  this, SLOT(toggleShuffle()) );
   336                  this, SLOT( toggleShuffle() ) );
   290         toolBar->addAction( mShuffleAction );
   337         toolBar->addAction( mShuffleAction );
   291 
   338 
   292         HbAction *action = new HbAction(actionsGroup);
   339         HbAction *action = new HbAction( actionsGroup );
   293         action->setIcon( HbIcon( ":/playbackviewicons/prev.svg") );
   340         action->setIcon( HbIcon( "qtg_mono_previous" ) );
   294         action->setCheckable( false );
   341         action->setCheckable( false );
   295         connect( action, SIGNAL(triggered(bool)),
   342         connect( action, SIGNAL( triggered( bool ) ),
   296                  mFrameworkWrapper, SLOT(skipBackward()) );
   343                  mFrameworkWrapper, SLOT( skipBackward() ) );
   297         toolBar->addAction( action );
   344         toolBar->addAction( action );
   298 
   345 
   299         mPlayPauseAction = new HbAction(actionsGroup);
   346         mPlayPauseAction = new HbAction( actionsGroup );
   300         mPlayIcon = new HbIcon(":/playbackviewicons/play.svg");
   347         mPlayIcon = new HbIcon( "qtg_mono_play" );
   301         mPauseIcon = new HbIcon( ":/playbackviewicons/pause.svg" );
   348         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   302         mPlayPauseAction->setIcon( *mPlayIcon );
   349         mPlayPauseAction->setIcon( *mPlayIcon );
   303         mPlayPauseAction->setCheckable( false );
   350         mPlayPauseAction->setCheckable( false );
   304         connect( mPlayPauseAction, SIGNAL(triggered(bool)),
   351         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   305                  mFrameworkWrapper, SLOT(playPause()) );
   352                  mFrameworkWrapper, SLOT( playPause() ) );
   306         toolBar->addAction( mPlayPauseAction );
   353         toolBar->addAction( mPlayPauseAction );
   307 
   354 
   308         action = new HbAction(actionsGroup);
   355         action = new HbAction( actionsGroup );
   309         action->setIcon( HbIcon(":/playbackviewicons/next.svg") );
   356         action->setIcon( HbIcon( "qtg_mono_next" ) );
   310         action->setCheckable( false );
   357         action->setCheckable( false );
   311         connect( action, SIGNAL(triggered(bool)),
   358         connect( action, SIGNAL( triggered( bool ) ),
   312                  mFrameworkWrapper, SLOT(skipForward()) );
   359                  mFrameworkWrapper, SLOT( skipForward() ) );
   313         toolBar->addAction( action );
   360         toolBar->addAction( action );
   314 
   361 
   315         HbIcon icon( ":/playbackviewicons/info.svg" );
   362         HbIcon icon( "qtg_mono_info" );
   316         action = new HbAction(actionsGroup);
   363         action = new HbAction( actionsGroup );
   317         action->setIcon( icon );
   364         action->setIcon( icon );
   318         action->setCheckable( false );
   365         action->setCheckable( false );
   319     /*
   366 
   320         connect( action, SIGNAL(triggered(bool)),
   367         connect( action, SIGNAL( triggered( bool ) ),
   321                  this, SLOT( flip()) );
   368                  this, SLOT( flip() ) );
   322     */
   369 
   323         toolBar->addAction( action );
   370         toolBar->addAction( action );
   324     }
   371     }
   325     else {
   372     else {
   326         // Fetch mode
   373         // Fetch mode
   327         HbAction *action = new HbAction(actionsGroup);
   374         HbAction *action = new HbAction( actionsGroup );
   328         action->setIcon( HbIcon(":/playbackviewicons/select.png") );
   375         action->setIcon( HbIcon( "qtg_mono_tick" ) );
   329         action->setCheckable( false );
   376         action->setCheckable( false );
   330         connect( action, SIGNAL(triggered(bool)),
   377         connect( action, SIGNAL( triggered( bool ) ),
   331                  this, SLOT(handleSongSelected()) );
   378                  this, SLOT( handleSongSelected() ) );
   332         toolBar->addAction( action );
   379         toolBar->addAction( action );
   333     
   380 
   334         mPlayPauseAction = new HbAction(actionsGroup);
   381         mPlayPauseAction = new HbAction( actionsGroup );
   335         mPlayIcon = new HbIcon(":/playbackviewicons/play.svg");
   382         mPlayIcon = new HbIcon( "qtg_mono_play" );
   336         mPauseIcon = new HbIcon( ":/playbackviewicons/pause.svg" );
   383         mPauseIcon = new HbIcon( "qtg_mono_pause" );
   337         mPlayPauseAction->setIcon( *mPlayIcon );
   384         mPlayPauseAction->setIcon( *mPlayIcon );
   338         mPlayPauseAction->setCheckable( false );
   385         mPlayPauseAction->setCheckable( false );
   339         connect( mPlayPauseAction, SIGNAL(triggered(bool)),
   386         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
   340                  mFrameworkWrapper, SLOT(playPause()) );
   387                  mFrameworkWrapper, SLOT( playPause() ) );
   341         toolBar->addAction( mPlayPauseAction );
   388         toolBar->addAction( mPlayPauseAction );
   342     }
   389     }
   343     TX_EXIT
   390     TX_EXIT
   344 }
   391 }
   345 
   392 
       
   393 /*!
       
   394  Slot to be called to activate equalizer dialog.
       
   395  */
       
   396 void MpPlaybackView::showEqualizerDialog()
       
   397 {
       
   398     TX_ENTRY
       
   399 
       
   400     if( mEqualizerWidget )
       
   401     {
       
   402         mEqualizerWidget->exec();
       
   403     }
       
   404 
       
   405     TX_EXIT
       
   406 }