mpviewplugins/mpmediawallviewplugin/src/mpmediawallview.cpp
changeset 55 f3930dda3342
parent 51 560ce2306a17
equal deleted inserted replaced
51:560ce2306a17 55:f3930dda3342
    21 #include <hbicon.h>
    21 #include <hbicon.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbapplication.h>
    23 #include <hbapplication.h>
    24 #include <hbscrollbar.h>
    24 #include <hbscrollbar.h>
    25 #include <hblabel.h>
    25 #include <hblabel.h>
    26 #include <hbtoolbutton.h>
       
    27 #include <hblistview.h>
    26 #include <hblistview.h>
    28 #include <hbstyleloader.h>
    27 #include <hbstyleloader.h>
    29 #include <hbmessagebox.h>
    28 #include <hbmessagebox.h>
    30 
       
    31 
    29 
    32 #include <hgmediawall.h>
    30 #include <hgmediawall.h>
    33 
    31 
    34 #include "mpmediawallview.h"
    32 #include "mpmediawallview.h"
    35 #include "mpmediawalldocumentloader.h"
    33 #include "mpmediawalldocumentloader.h"
    40 #include "mpplaybackdata.h"
    38 #include "mpplaybackdata.h"
    41 #include "mpalbumcoverwidget.h"
    39 #include "mpalbumcoverwidget.h"
    42 #include "mptracklistwidget.h"
    40 #include "mptracklistwidget.h"
    43 #include "mpcollectiontbonelistdatamodel.h"
    41 #include "mpcollectiontbonelistdatamodel.h"
    44 #include "mptrace.h"
    42 #include "mptrace.h"
    45 #include "mpreflectioneffect.h"
       
    46 
    43 
    47 const char*MUSIC_MEDIAWALL_DOCML = ":/mediawallviewdocml/mediawall.docml";
    44 const char*MUSIC_MEDIAWALL_DOCML = ":/mediawallviewdocml/mediawall.docml";
    48 
    45 
    49 /*!
    46 /*!
    50     \class MpMediaWallView
    47     \class MpMediaWallView
    69       mCollectionData( 0 ),
    66       mCollectionData( 0 ),
    70       mModel( 0 ),
    67       mModel( 0 ),
    71       mMediaWallWidget( 0 ),
    68       mMediaWallWidget( 0 ),
    72       mNoMusic( 0 ),
    69       mNoMusic( 0 ),
    73       mDocumentLoader( 0 ),
    70       mDocumentLoader( 0 ),
    74       mPlayPauseContainer( 0 ),
       
    75       mPlayIcon( 0 ),
       
    76       mPauseIcon( 0 ),
       
    77       mPlayPauseAction( 0 ),
       
    78       mLibraryUpdating( false ),
    71       mLibraryUpdating( false ),
    79       mPlaybackData( 0 ),
    72       mPlaybackData( 0 ),
    80       mActivated( false ),
       
    81       mIconUpdateNedded( false ),
       
    82       mListShowAnimationGroup( 0 ),
    73       mListShowAnimationGroup( 0 ),
    83       mListShowListAnimation( 0 ),
    74       mListShowListAnimation( 0 ),
    84       mCoverShowListAnimation( 0 ),
    75       mCoverShowListAnimation( 0 ),
    85       mShowingSongsList( false ),
    76       mShowingSongsList( false ),
    86       mAlbumCover( 0 ),
    77       mAlbumCover( 0 ),
    99 MpMediaWallView::~MpMediaWallView()
    90 MpMediaWallView::~MpMediaWallView()
   100 {
    91 {
   101     TX_ENTRY
    92     TX_ENTRY
   102     //delete not parented objects
    93     //delete not parented objects
   103     delete mDocumentLoader;
    94     delete mDocumentLoader;
   104     delete mPlayIcon;
       
   105     delete mPauseIcon;
       
   106     TX_EXIT
    95     TX_EXIT
   107 }
    96 }
   108 
    97 
   109 /*!
    98 /*!
   110  Initializes the media wall view.
    99  Initializes the media wall view.
   119     bool ok = false;
   108     bool ok = false;
   120     mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, &ok );
   109     mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, &ok );
   121     if ( ok ) {
   110     if ( ok ) {
   122         QGraphicsWidget *widget;
   111         QGraphicsWidget *widget;
   123         
   112         
   124         //Setup fake softkey to hide the app
       
   125         widget = mDocumentLoader->findWidget( QString( "navigationButton" ) );
       
   126         HbAction  *action;
       
   127         action = new HbAction( Hb::BackNaviAction, this );
       
   128         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( sendToBackground() ) );
       
   129         qobject_cast<HbToolButton*>( widget )->setAction( action );
       
   130         
   113         
   131         //Setup the play/pause command button
       
   132         widget = mDocumentLoader->findWidget( QString( "playPauseButton" ) );
       
   133         mPauseIcon = new HbIcon( "qtg_mono_pause" );
       
   134         mPlayIcon = new HbIcon( "qtg_mono_play" );
       
   135         mPlayPauseAction = new HbAction( HbIcon() , QString(), this );  
       
   136         mPlaybackData = MpEngineFactory::sharedEngine()->playbackData();
   114         mPlaybackData = MpEngineFactory::sharedEngine()->playbackData();
   137         qobject_cast<HbToolButton*>( widget )->setAction( mPlayPauseAction );
   115                
   138         //we need this widget to hide the play pause button, for some reason it does not want to hide.
       
   139         mPlayPauseContainer = mDocumentLoader->findWidget( QString( "playPauseButtonContainer" ) );
       
   140         updatePlayPauseAction();
       
   141         connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
       
   142                  this, SLOT( updatePlayPauseAction() ) );
       
   143         connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
       
   144                  MpEngineFactory::sharedEngine(), SLOT( playPause() ) );
       
   145 
       
   146         
       
   147         //Get the main container and set as widget.
   116         //Get the main container and set as widget.
   148         widget = mDocumentLoader->findWidget( QString( "container" ) );
   117         widget = mDocumentLoader->findWidget( QString( "container" ) );
   149         setWidget( widget );
   118         setWidget( widget );
   150         
   119         
   151         mEngine = MpEngineFactory::createIsolatedEngine( MpEngine::MediaBrowsing );
   120         mEngine = MpEngineFactory::createIsolatedEngine( MpEngine::MediaBrowsing );
   152         mCollectionData = mEngine->collectionData();
   121         mCollectionData = mEngine->collectionData();
   153         mModel = new MpCollectionDataModel( mCollectionData, mPlaybackData, this );
   122         mModel = new MpCollectionDataModel( mCollectionData, 0, this );
   154         
   123         
   155         connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), 
   124         connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), 
   156                  this, SLOT( contextOpened( TCollectionContext ) ) );
   125                  this, SLOT( contextOpened( TCollectionContext ) ) );
   157         connect( mEngine, SIGNAL( containerContentsChanged() ),
   126         connect( mEngine, SIGNAL( containerContentsChanged() ),
   158                 this, SLOT( containerContentsChanged() ) );
   127                 this, SLOT( containerContentsChanged() ) );
   162     }
   131     }
   163     else {
   132     else {
   164         TX_LOG_ARGS( "Error: invalid xml file." );
   133         TX_LOG_ARGS( "Error: invalid xml file." );
   165         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   134         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   166     }
   135     }
   167     
   136        
   168     mAlbumCover = new MpAlbumCoverWidget( this );
       
   169     mAlbumCover->setGraphicsEffect( new MpReflectionEffect(mAlbumCover) );
       
   170     mAlbumCover->setDefaultIcon( HbIcon( "qtg_large_album_art" ) );
       
   171     mAlbumCover->hide();
       
   172     
       
   173     mTrackList = new MpTrackListWidget( this );
   137     mTrackList = new MpTrackListWidget( this );
   174     mTrackList->setGraphicsEffect( new MpReflectionEffect(mTrackList) );
       
   175     MpCollectionTBoneListDataModel *model = new MpCollectionTBoneListDataModel(mCollectionData, mPlaybackData, mTrackList );
   138     MpCollectionTBoneListDataModel *model = new MpCollectionTBoneListDataModel(mCollectionData, mPlaybackData, mTrackList );
   176     model->enablePlaybackIndicatorEnable(true);
   139     model->enablePlaybackIndicatorEnable(true);
   177     mTrackList->list()->setModel( model );
   140     mTrackList->list()->setModel( model );
   178     mTrackList->hide();
   141     mTrackList->hide();
   179     
   142     
       
   143     mAlbumCover = new MpAlbumCoverWidget( this );
       
   144     mAlbumCover->setDefaultIcon( HbIcon( "qtg_large_album_art" ) );
       
   145     mAlbumCover->hide();
       
   146     
   180     connect(mAlbumCover,SIGNAL(clicked()),this, SLOT(hideTracksList()));
   147     connect(mAlbumCover,SIGNAL(clicked()),this, SLOT(hideTracksList()));
   181     connect(mTrackList->list(), SIGNAL(activated(QModelIndex)), this, SLOT(listItemActivated(QModelIndex)));
   148     connect(mTrackList->list(), SIGNAL(activated(QModelIndex)), this, SLOT(listItemActivated(QModelIndex)));
   182     connect(mTrackList,SIGNAL(closed()),this, SLOT(hideTracksList()));
   149     connect(mTrackList,SIGNAL(closed()),this, SLOT(hideTracksList()));
   183 
   150 
   184     HbStyleLoader::registerFilePath(":/css/mpcustommediawall.css");
   151     HbStyleLoader::registerFilePath(":/css/mpcustommediawall.css");
   192  Activates the media wall view.
   159  Activates the media wall view.
   193  */
   160  */
   194 void MpMediaWallView::activateView()
   161 void MpMediaWallView::activateView()
   195 {
   162 {
   196     TX_ENTRY
   163     TX_ENTRY
   197     mActivated = true;
       
   198     if ( mIconUpdateNedded ) {
       
   199         updatePlayPauseAction();
       
   200         mIconUpdateNedded = false;
       
   201     }
       
   202     scrollToNowPlaying();   
   164     scrollToNowPlaying();   
   203     TX_EXIT
   165     TX_EXIT
   204 }
   166 }
   205 
   167 
   206 /*!
   168 /*!
   207  Deactivates the media wall view.
   169  Deactivates the media wall view.
   208  */
   170  */
   209 void MpMediaWallView::deactivateView()
   171 void MpMediaWallView::deactivateView()
   210 {
   172 {
   211     TX_ENTRY
   173     TX_ENTRY
   212     mActivated = false;
       
   213     dismissListClosingAnimation();
   174     dismissListClosingAnimation();
   214     TX_EXIT
   175     TX_EXIT
   215 }
   176 }
   216 
   177 
   217 /*!
   178 /*!
   239             if ( ok ) {
   200             if ( ok ) {
   240                 QGraphicsWidget *widget;
   201                 QGraphicsWidget *widget;
   241                 widget = mDocumentLoader->findWidget(QString("MPmediaWallWidget"));
   202                 widget = mDocumentLoader->findWidget(QString("MPmediaWallWidget"));
   242                 mMediaWallWidget = qobject_cast<HgMediawall*>(widget);
   203                 mMediaWallWidget = qobject_cast<HgMediawall*>(widget);
   243                 //set these items as children of the media wall so they show behind the scrollbar.
   204                 //set these items as children of the media wall so they show behind the scrollbar.
   244                 mTrackList->setParentItem(mMediaWallWidget);
       
   245                 mAlbumCover->setParentItem(mMediaWallWidget);
       
   246                 mModel->refreshModel();
   205                 mModel->refreshModel();
   247                 setUpMediaWallWidget();
   206                 setUpMediaWallWidget();
   248             }
   207             }
   249             else {
   208             else {
   250                 TX_LOG_ARGS("Error: invalid xml file.");
   209                 TX_LOG_ARGS("Error: invalid xml file.");
   254         }
   213         }
   255     }
   214     }
   256     else {
   215     else {
   257         if ( mMediaWallWidget ) {
   216         if ( mMediaWallWidget ) {
   258             //Take ownership of these items to prevent delete from media wall widget.
   217             //Take ownership of these items to prevent delete from media wall widget.
   259             mTrackList->setParentItem( this );
       
   260             mAlbumCover->setParentItem( this );
       
   261             delete mMediaWallWidget;
   218             delete mMediaWallWidget;
   262             mMediaWallWidget = 0;
   219             mMediaWallWidget = 0;
   263             
   220             
   264         }
   221         }
   265         if ( !mNoMusic ) {
   222         if ( !mNoMusic ) {
   308         mEngine->openCollection( ECollectionContextAlbumsMediaWall );
   265         mEngine->openCollection( ECollectionContextAlbumsMediaWall );
   309     }
   266     }
   310 }
   267 }
   311 
   268 
   312 /*!
   269 /*!
   313  Slot to be called to send to background.
       
   314  */
       
   315 void MpMediaWallView::sendToBackground()
       
   316 {
       
   317     TX_ENTRY
       
   318     emit command( MpCommon::SendToBackground );
       
   319     TX_EXIT
       
   320 }
       
   321 
       
   322 /*!
       
   323  Slot to update teh play pause action icon.
       
   324  */
       
   325 void MpMediaWallView::updatePlayPauseAction()
       
   326 {
       
   327     if ( !mActivated ) {
       
   328         mIconUpdateNedded = true;
       
   329         return;
       
   330     }
       
   331     TX_ENTRY
       
   332     switch ( mPlaybackData->playbackState() ) {
       
   333         case MpPlaybackData::Playing:
       
   334             TX_LOG_ARGS( "MpPlaybackData::Playing" )
       
   335             mPlayPauseAction->setIcon( *mPauseIcon );
       
   336             mPlayPauseContainer->show();
       
   337             break;
       
   338         case MpPlaybackData::Paused:
       
   339         case MpPlaybackData::Stopped:
       
   340             TX_LOG_ARGS( "MpPlaybackData::Paused" )
       
   341             mPlayPauseAction->setIcon( *mPlayIcon );
       
   342             mPlayPauseContainer->show();
       
   343             break;
       
   344         case MpPlaybackData::NotPlaying:
       
   345             mPlayPauseContainer->hide();       
       
   346             break;
       
   347         default:
       
   348             break;
       
   349     }
       
   350     TX_EXIT
       
   351 }
       
   352 
       
   353 /*!
       
   354  Slot called to start the album and list opening animation.
   270  Slot called to start the album and list opening animation.
   355  */
   271  */
   356 void MpMediaWallView::showTrackList()
   272 void MpMediaWallView::showTrackList()
   357 {
   273 {
   358     if( mShowingSongsList ) {
   274     if( mShowingSongsList ) {
   394 /*!
   310 /*!
   395  Slot to be called when a list item is selected by the user.
   311  Slot to be called when a list item is selected by the user.
   396  */
   312  */
   397 void MpMediaWallView::listItemActivated( const QModelIndex &index )
   313 void MpMediaWallView::listItemActivated( const QModelIndex &index )
   398 {
   314 {
   399     if (!mCollectionData->hasAlbumSongProperty(index.row(), MpMpxCollectionData::Corrupted)) {
   315     if (mCollectionData->hasAlbumSongProperty(index.row(), MpMpxCollectionData::Corrupted)) {
   400         int albumIndex = mMediaWallWidget->currentIndex().row();
       
   401         //We are playing on the shared engine, but we pass the collection data that
       
   402         //points to albums on media wall, this is used to construct the playlist.
       
   403         MpEngineFactory::sharedEngine()->playAlbumSongs( albumIndex, index.row(), mCollectionData );
       
   404     }
       
   405     else{
       
   406         //pop up corrupted note
   316         //pop up corrupted note
   407         HbMessageBox *messageBox = new HbMessageBox( hbTrId( "txt_mus_info_file_is_corrupt" ), HbMessageBox::MessageTypeInformation );
   317         HbMessageBox *messageBox = new HbMessageBox( hbTrId( "txt_mus_info_file_is_corrupt" ), HbMessageBox::MessageTypeInformation );
   408         messageBox->setAttribute( Qt::WA_DeleteOnClose );
   318         messageBox->setAttribute( Qt::WA_DeleteOnClose );
   409         messageBox->setIcon( HbIcon( QString("qtg_small_fail") ) ); 
   319         messageBox->setIcon( HbIcon( QString("qtg_small_fail") ) ); 
   410         messageBox->show();   
   320         messageBox->show();   
   411     }
   321     }
       
   322     else if	( (mPlaybackData->playbackState() != MpPlaybackData::NotPlaying ) 
       
   323         && ( mPlaybackData->id() == mCollectionData->albumSongId( index.row() ) ) ) {
       
   324          MpEngineFactory::sharedEngine()->playPause();
       
   325     }
       
   326     else {
       
   327         int albumIndex = mMediaWallWidget->currentIndex().row();
       
   328         //We are playing on the shared engine, but we pass the collection data that
       
   329         //points to albums on media wall, this is used to construct the playlist.
       
   330         MpEngineFactory::sharedEngine()->playAlbumSongs( albumIndex, index.row(), mCollectionData );
       
   331     }
   412 }
   332 }
   413 
   333 
   414 /*!
   334 /*!
   415  Slot to be called to fetch the songs for an album.
   335  Slot to be called to fetch the songs for an album.
   416  */
   336  */
   427 void MpMediaWallView::setUpMediaWallWidget()
   347 void MpMediaWallView::setUpMediaWallWidget()
   428 {
   348 {
   429     HbIcon defaultIcon( "qtg_large_album_art" );
   349     HbIcon defaultIcon( "qtg_large_album_art" );
   430     defaultIcon.setSize(mMediaWallWidget->itemSize());
   350     defaultIcon.setSize(mMediaWallWidget->itemSize());
   431     mMediaWallWidget->setDefaultImage( defaultIcon.pixmap().toImage() );
   351     mMediaWallWidget->setDefaultImage( defaultIcon.pixmap().toImage() );
   432     mMediaWallWidget->enableReflections( true );
   352     mMediaWallWidget->enableReflections( false );
   433     mMediaWallWidget->setModel( mModel );
   353     mMediaWallWidget->setModel( mModel );
   434     scrollToDefault();
   354     scrollToDefault();
   435     mMediaWallWidget->setTitleFontSpec( HbFontSpec( HbFontSpec::Primary ) );
   355     mMediaWallWidget->setTitleFontSpec( HbFontSpec( HbFontSpec::Primary ) );
   436     mMediaWallWidget->setDescriptionFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
   356     mMediaWallWidget->setDescriptionFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
   437     mMediaWallWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); //HgWidget::ScrollBarAutoHide
   357     mMediaWallWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); //HgWidget::ScrollBarAutoHide