mpviewplugins/mpmediawallviewplugin/src/mpmediawallview.cpp
author hgs
Fri, 11 Jun 2010 19:36:32 -0500
changeset 37 eb79a7c355bf
parent 36 a0afa279b8fe
child 43 0f32e550d9d8
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: Music Player Settings view.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <QParallelAnimationGroup>
hgs
parents:
diff changeset
    19
#include <QPropertyAnimation>
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <hbicon.h>
hgs
parents:
diff changeset
    22
#include <hbaction.h>
hgs
parents:
diff changeset
    23
#include <hbapplication.h>
hgs
parents:
diff changeset
    24
#include <hbscrollbar.h>
hgs
parents:
diff changeset
    25
#include <hblabel.h>
hgs
parents:
diff changeset
    26
#include <hbtoolbutton.h>
37
hgs
parents: 36
diff changeset
    27
#include <hblistview.h>
hgs
parents: 36
diff changeset
    28
#include <hbstyleloader.h>
35
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
#include <hgmediawall.h>
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
#include "mpmediawallview.h"
hgs
parents:
diff changeset
    33
#include "mpmediawalldocumentloader.h"
hgs
parents:
diff changeset
    34
#include "mpcommondefs.h"
hgs
parents:
diff changeset
    35
#include "mpmpxcollectiondata.h"
hgs
parents:
diff changeset
    36
#include "mpcollectiondatamodel.h"
hgs
parents:
diff changeset
    37
#include "mpenginefactory.h"
hgs
parents:
diff changeset
    38
#include "mpplaybackdata.h"
hgs
parents:
diff changeset
    39
#include "mpalbumcoverwidget.h"
hgs
parents:
diff changeset
    40
#include "mptracklistwidget.h"
hgs
parents:
diff changeset
    41
#include "mpcollectiontbonelistdatamodel.h"
hgs
parents:
diff changeset
    42
#include "mptrace.h"
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
const char*MUSIC_MEDIAWALL_DOCML = ":/mediawallviewdocml/mediawall.docml";
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
/*!
hgs
parents:
diff changeset
    47
    \class MpMediaWallView
hgs
parents:
diff changeset
    48
    \brief Music Player Settings view.
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    Music player media wall view displays music players albums on an full screen view
hgs
parents:
diff changeset
    51
*/
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
/*!
hgs
parents:
diff changeset
    54
    \fn void command( int command )
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
    This signal is emitted when the view issues a \a command to the
hgs
parents:
diff changeset
    57
    application such as request to switch to a different view.
hgs
parents:
diff changeset
    58
 */
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
/*!
hgs
parents:
diff changeset
    62
 Constructs the media wall view.
hgs
parents:
diff changeset
    63
 */
hgs
parents:
diff changeset
    64
MpMediaWallView::MpMediaWallView()
hgs
parents:
diff changeset
    65
    : mEngine( 0 ),
hgs
parents:
diff changeset
    66
      mCollectionData( 0 ),
hgs
parents:
diff changeset
    67
      mModel( 0 ),
hgs
parents:
diff changeset
    68
      mMediaWallWidget( 0 ),
hgs
parents:
diff changeset
    69
      mNoMusic( 0 ),
hgs
parents:
diff changeset
    70
      mDocumentLoader( 0 ),
hgs
parents:
diff changeset
    71
      mPlayPauseContainer( 0 ),
hgs
parents:
diff changeset
    72
      mPlayIcon( 0 ),
hgs
parents:
diff changeset
    73
      mPauseIcon( 0 ),
hgs
parents:
diff changeset
    74
      mPlayPauseAction( 0 ),
hgs
parents:
diff changeset
    75
      mLibraryUpdating( false ),
hgs
parents:
diff changeset
    76
      mPlaybackData( 0 ),
hgs
parents:
diff changeset
    77
      mActivated( false ),
hgs
parents:
diff changeset
    78
      mIconUpdateNedded( false ),
hgs
parents:
diff changeset
    79
      mListShowAnimationGroup( 0 ),
hgs
parents:
diff changeset
    80
      mListShowListAnimation( 0 ),
hgs
parents:
diff changeset
    81
      mCoverShowListAnimation( 0 ),
hgs
parents:
diff changeset
    82
      mShowingSongsList( false ),
hgs
parents:
diff changeset
    83
      mAlbumCover( 0 ),
hgs
parents:
diff changeset
    84
      mTrackList( 0 )
hgs
parents:
diff changeset
    85
{
hgs
parents:
diff changeset
    86
    connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryAboutToUpdate() ),
hgs
parents:
diff changeset
    87
                    this, SLOT( libraryAboutToUpdate() ) );
hgs
parents:
diff changeset
    88
    connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ),
hgs
parents:
diff changeset
    89
                    this, SLOT( libraryUpdated() ) );
hgs
parents:
diff changeset
    90
    TX_LOG
hgs
parents:
diff changeset
    91
}
hgs
parents:
diff changeset
    92
    
hgs
parents:
diff changeset
    93
/*!
hgs
parents:
diff changeset
    94
 Destructs the media wall view.
hgs
parents:
diff changeset
    95
 */
hgs
parents:
diff changeset
    96
MpMediaWallView::~MpMediaWallView()
hgs
parents:
diff changeset
    97
{
hgs
parents:
diff changeset
    98
    TX_ENTRY
hgs
parents:
diff changeset
    99
    //delete not parented objects
hgs
parents:
diff changeset
   100
    delete mDocumentLoader;
hgs
parents:
diff changeset
   101
    delete mPlayIcon;
hgs
parents:
diff changeset
   102
    delete mPauseIcon;
hgs
parents:
diff changeset
   103
    TX_EXIT
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
/*!
hgs
parents:
diff changeset
   107
 Initializes the media wall view.
hgs
parents:
diff changeset
   108
 */
hgs
parents:
diff changeset
   109
void MpMediaWallView::initializeView()
hgs
parents:
diff changeset
   110
{
hgs
parents:
diff changeset
   111
    TX_ENTRY
hgs
parents:
diff changeset
   112
    setTitleBarVisible( false );
hgs
parents:
diff changeset
   113
    setStatusBarVisible( false );
hgs
parents:
diff changeset
   114
       
hgs
parents:
diff changeset
   115
    mDocumentLoader = new MpMediaWallDocumentLoader();  
hgs
parents:
diff changeset
   116
    bool ok = false;
hgs
parents:
diff changeset
   117
    mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, &ok );
hgs
parents:
diff changeset
   118
    if ( ok ) {
hgs
parents:
diff changeset
   119
        QGraphicsWidget *widget;
hgs
parents:
diff changeset
   120
        
hgs
parents:
diff changeset
   121
        //Setup fake softkey to hide the app
hgs
parents:
diff changeset
   122
        widget = mDocumentLoader->findWidget( QString( "navigationButton" ) );
hgs
parents:
diff changeset
   123
        HbAction  *action;
hgs
parents:
diff changeset
   124
        action = new HbAction( Hb::BackNaviAction, this );
hgs
parents:
diff changeset
   125
        connect( action, SIGNAL( triggered( bool ) ), this, SLOT( sendToBackground() ) );
hgs
parents:
diff changeset
   126
        qobject_cast<HbToolButton*>( widget )->setAction( action );
hgs
parents:
diff changeset
   127
        
hgs
parents:
diff changeset
   128
        //Setup the play/pause command button
hgs
parents:
diff changeset
   129
        widget = mDocumentLoader->findWidget( QString( "playPauseButton" ) );
hgs
parents:
diff changeset
   130
        mPauseIcon = new HbIcon( "qtg_mono_pause" );
hgs
parents:
diff changeset
   131
        mPlayIcon = new HbIcon( "qtg_mono_play" );
hgs
parents:
diff changeset
   132
        mPlayPauseAction = new HbAction( HbIcon() , QString(), this );  
hgs
parents:
diff changeset
   133
        mPlaybackData = MpEngineFactory::sharedEngine()->playbackData();
hgs
parents:
diff changeset
   134
        qobject_cast<HbToolButton*>( widget )->setAction( mPlayPauseAction );
37
hgs
parents: 36
diff changeset
   135
        //we need this widget to hide the play pause button, for some reason it does not want to hide.
35
hgs
parents:
diff changeset
   136
        mPlayPauseContainer = mDocumentLoader->findWidget( QString( "playPauseButtonContainer" ) );
hgs
parents:
diff changeset
   137
        updatePlayPauseAction();
hgs
parents:
diff changeset
   138
        connect( mPlaybackData, SIGNAL( playbackStateChanged() ),
hgs
parents:
diff changeset
   139
                 this, SLOT( updatePlayPauseAction() ) );
hgs
parents:
diff changeset
   140
        connect( mPlayPauseAction, SIGNAL( triggered( bool ) ),
hgs
parents:
diff changeset
   141
                 MpEngineFactory::sharedEngine(), SLOT( playPause() ) );
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
        
hgs
parents:
diff changeset
   144
        //Get the main container and set as widget.
hgs
parents:
diff changeset
   145
        widget = mDocumentLoader->findWidget( QString( "container" ) );
hgs
parents:
diff changeset
   146
        setWidget( widget );
hgs
parents:
diff changeset
   147
        
hgs
parents:
diff changeset
   148
        mEngine = MpEngineFactory::createIsolatedEngine( MpEngine::MediaBrowsing );
hgs
parents:
diff changeset
   149
        mCollectionData = mEngine->collectionData();
hgs
parents:
diff changeset
   150
        mModel = new MpCollectionDataModel( mCollectionData, this );
hgs
parents:
diff changeset
   151
        
hgs
parents:
diff changeset
   152
        connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), 
hgs
parents:
diff changeset
   153
                 this, SLOT( contextOpened( TCollectionContext ) ) );
hgs
parents:
diff changeset
   154
        connect( mEngine, SIGNAL( containerContentsChanged() ),
hgs
parents:
diff changeset
   155
                this, SLOT( containerContentsChanged() ) );
hgs
parents:
diff changeset
   156
        if ( !mLibraryUpdating ) {
hgs
parents:
diff changeset
   157
        mEngine->openCollection( ECollectionContextAlbumsMediaWall );
hgs
parents:
diff changeset
   158
        }
hgs
parents:
diff changeset
   159
    }
hgs
parents:
diff changeset
   160
    else {
hgs
parents:
diff changeset
   161
        TX_LOG_ARGS( "Error: invalid xml file." );
hgs
parents:
diff changeset
   162
        Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
hgs
parents:
diff changeset
   163
    }
hgs
parents:
diff changeset
   164
    
hgs
parents:
diff changeset
   165
    mAlbumCover = new MpAlbumCoverWidget( this );
37
hgs
parents: 36
diff changeset
   166
    mAlbumCover->setDefaultIcon( HbIcon( "qtg_large_album_art" ) );
35
hgs
parents:
diff changeset
   167
    mAlbumCover->hide();
hgs
parents:
diff changeset
   168
    
hgs
parents:
diff changeset
   169
    mTrackList = new MpTrackListWidget( this );
36
hgs
parents: 35
diff changeset
   170
    mTrackList->list()->setModel( new MpCollectionTBoneListDataModel(mCollectionData, mPlaybackData, mTrackList ) );
35
hgs
parents:
diff changeset
   171
    mTrackList->hide();
hgs
parents:
diff changeset
   172
    
hgs
parents:
diff changeset
   173
    connect(mAlbumCover,SIGNAL(clicked()),this, SLOT(hideTracksList()));
hgs
parents:
diff changeset
   174
    connect(mTrackList->list(), SIGNAL(activated(QModelIndex)), this, SLOT(listItemActivated(QModelIndex)));
37
hgs
parents: 36
diff changeset
   175
    connect(mTrackList,SIGNAL(closed()),this, SLOT(hideTracksList()));
35
hgs
parents:
diff changeset
   176
37
hgs
parents: 36
diff changeset
   177
    HbStyleLoader::registerFilePath(":/css/mpcustommediawall.css");
hgs
parents: 36
diff changeset
   178
    HbStyleLoader::registerFilePath(":/css/mpcustommediawall.hgmediawall.widgetml");  
35
hgs
parents:
diff changeset
   179
    
hgs
parents:
diff changeset
   180
    TX_EXIT
hgs
parents:
diff changeset
   181
}
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
/*!
hgs
parents:
diff changeset
   184
 Activates the media wall view.
hgs
parents:
diff changeset
   185
 */
hgs
parents:
diff changeset
   186
void MpMediaWallView::activateView()
hgs
parents:
diff changeset
   187
{
hgs
parents:
diff changeset
   188
    TX_ENTRY
hgs
parents:
diff changeset
   189
    mActivated = true;
hgs
parents:
diff changeset
   190
    if ( mIconUpdateNedded ) {
hgs
parents:
diff changeset
   191
        updatePlayPauseAction();
hgs
parents:
diff changeset
   192
        mIconUpdateNedded = false;
hgs
parents:
diff changeset
   193
    }
hgs
parents:
diff changeset
   194
    scrollToNowPlaying();   
hgs
parents:
diff changeset
   195
    TX_EXIT
hgs
parents:
diff changeset
   196
}
hgs
parents:
diff changeset
   197
hgs
parents:
diff changeset
   198
/*!
hgs
parents:
diff changeset
   199
 Deactivates the media wall view.
hgs
parents:
diff changeset
   200
 */
hgs
parents:
diff changeset
   201
void MpMediaWallView::deactivateView()
hgs
parents:
diff changeset
   202
{
hgs
parents:
diff changeset
   203
    TX_ENTRY
hgs
parents:
diff changeset
   204
    mActivated = false;
hgs
parents:
diff changeset
   205
    dismissListClosingAnimation();
hgs
parents:
diff changeset
   206
    TX_EXIT
hgs
parents:
diff changeset
   207
}
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
/*!
hgs
parents:
diff changeset
   210
 Slot to be called when the context is opened.
hgs
parents:
diff changeset
   211
 */
hgs
parents:
diff changeset
   212
void MpMediaWallView::contextOpened( TCollectionContext context )
hgs
parents:
diff changeset
   213
{
hgs
parents:
diff changeset
   214
    if ( context != ECollectionContextAlbumsMediaWall ) {
hgs
parents:
diff changeset
   215
        //Force the context to Albums Media Wall, this to get the model and 
hgs
parents:
diff changeset
   216
        //data to provide the right funtionality to media wall.
hgs
parents:
diff changeset
   217
        mCollectionData->setContext( ECollectionContextAlbumsMediaWall );
hgs
parents:
diff changeset
   218
        return;
hgs
parents:
diff changeset
   219
    }
hgs
parents:
diff changeset
   220
    if ( mCollectionData->count() ) {
hgs
parents:
diff changeset
   221
        if (mNoMusic) {
hgs
parents:
diff changeset
   222
            delete mNoMusic;
hgs
parents:
diff changeset
   223
            mNoMusic = 0;
hgs
parents:
diff changeset
   224
        }
hgs
parents:
diff changeset
   225
        if ( mMediaWallWidget ) {
hgs
parents:
diff changeset
   226
            mModel->refreshModel();
hgs
parents:
diff changeset
   227
        } else {
hgs
parents:
diff changeset
   228
            bool ok = false;
hgs
parents:
diff changeset
   229
            mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, "mediaWall", &ok);
hgs
parents:
diff changeset
   230
            if ( ok ) {
hgs
parents:
diff changeset
   231
                QGraphicsWidget *widget;
37
hgs
parents: 36
diff changeset
   232
                widget = mDocumentLoader->findWidget(QString("MPmediaWallWidget"));
35
hgs
parents:
diff changeset
   233
                mMediaWallWidget = qobject_cast<HgMediawall*>(widget);
37
hgs
parents: 36
diff changeset
   234
                //set these items as children of the media wall so they show behind the scrollbar.
hgs
parents: 36
diff changeset
   235
                mTrackList->setParentItem(mMediaWallWidget);
hgs
parents: 36
diff changeset
   236
                mAlbumCover->setParentItem(mMediaWallWidget);
35
hgs
parents:
diff changeset
   237
                mModel->refreshModel();
hgs
parents:
diff changeset
   238
                setUpMediaWallWidget();
hgs
parents:
diff changeset
   239
            }
hgs
parents:
diff changeset
   240
            else {
hgs
parents:
diff changeset
   241
                TX_LOG_ARGS("Error: invalid xml file.");
hgs
parents:
diff changeset
   242
                Q_ASSERT_X(ok, "MpMediaWallView::contextOpened", "invalid xml file");
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
            }          
hgs
parents:
diff changeset
   245
        }
hgs
parents:
diff changeset
   246
    }
hgs
parents:
diff changeset
   247
    else {
hgs
parents:
diff changeset
   248
        if ( mMediaWallWidget ) {
37
hgs
parents: 36
diff changeset
   249
            //Take ownership of these items to prevent delete from media wall widget.
hgs
parents: 36
diff changeset
   250
            mTrackList->setParentItem( this );
hgs
parents: 36
diff changeset
   251
            mAlbumCover->setParentItem( this );
35
hgs
parents:
diff changeset
   252
            delete mMediaWallWidget;
hgs
parents:
diff changeset
   253
            mMediaWallWidget = 0;
hgs
parents:
diff changeset
   254
            
hgs
parents:
diff changeset
   255
        }
hgs
parents:
diff changeset
   256
        if ( !mNoMusic ) {
hgs
parents:
diff changeset
   257
            bool ok = false;
hgs
parents:
diff changeset
   258
            mDocumentLoader->load( MUSIC_MEDIAWALL_DOCML, "empty", &ok);
hgs
parents:
diff changeset
   259
            if ( ok ) {
hgs
parents:
diff changeset
   260
                QGraphicsWidget *widget;
hgs
parents:
diff changeset
   261
                widget = mDocumentLoader->findWidget(QString("noMusic"));
hgs
parents:
diff changeset
   262
                mNoMusic = qobject_cast<HbLabel*>(widget);
hgs
parents:
diff changeset
   263
            }
hgs
parents:
diff changeset
   264
            else {
hgs
parents:
diff changeset
   265
                TX_LOG_ARGS("Error: invalid xml file.");
hgs
parents:
diff changeset
   266
                Q_ASSERT_X(ok, "MpMediaWallView::contextOpened", "invalid xml file");
hgs
parents:
diff changeset
   267
hgs
parents:
diff changeset
   268
            }
hgs
parents:
diff changeset
   269
        }
hgs
parents:
diff changeset
   270
    }
hgs
parents:
diff changeset
   271
}
hgs
parents:
diff changeset
   272
hgs
parents:
diff changeset
   273
/*!
hgs
parents:
diff changeset
   274
 Slot to be called when the container contents changed.
hgs
parents:
diff changeset
   275
 */
hgs
parents:
diff changeset
   276
void MpMediaWallView::containerContentsChanged() 
hgs
parents:
diff changeset
   277
{
hgs
parents:
diff changeset
   278
    if ( !mLibraryUpdating && mEngine ) {
hgs
parents:
diff changeset
   279
        mEngine->openCollection( ECollectionContextAlbumsMediaWall );
hgs
parents:
diff changeset
   280
    }
hgs
parents:
diff changeset
   281
}
hgs
parents:
diff changeset
   282
hgs
parents:
diff changeset
   283
/*!
hgs
parents:
diff changeset
   284
 Slot to be called when the container contents changed.
hgs
parents:
diff changeset
   285
 */
hgs
parents:
diff changeset
   286
void MpMediaWallView::libraryAboutToUpdate()
hgs
parents:
diff changeset
   287
{
hgs
parents:
diff changeset
   288
    mLibraryUpdating = true;
hgs
parents:
diff changeset
   289
}
hgs
parents:
diff changeset
   290
hgs
parents:
diff changeset
   291
/*!
hgs
parents:
diff changeset
   292
 Slot to be called when the container contents changed.
hgs
parents:
diff changeset
   293
 */
hgs
parents:
diff changeset
   294
void MpMediaWallView::libraryUpdated()
hgs
parents:
diff changeset
   295
{
hgs
parents:
diff changeset
   296
    mLibraryUpdating = false;
hgs
parents:
diff changeset
   297
    if ( mEngine ) {
hgs
parents:
diff changeset
   298
        mEngine->openCollection( ECollectionContextAlbumsMediaWall );
hgs
parents:
diff changeset
   299
    }
hgs
parents:
diff changeset
   300
}
hgs
parents:
diff changeset
   301
hgs
parents:
diff changeset
   302
/*!
hgs
parents:
diff changeset
   303
 Slot to be called to send to background.
hgs
parents:
diff changeset
   304
 */
hgs
parents:
diff changeset
   305
void MpMediaWallView::sendToBackground()
hgs
parents:
diff changeset
   306
{
hgs
parents:
diff changeset
   307
    TX_ENTRY
hgs
parents:
diff changeset
   308
    emit command( MpCommon::SendToBackground );
hgs
parents:
diff changeset
   309
    TX_EXIT
hgs
parents:
diff changeset
   310
}
hgs
parents:
diff changeset
   311
hgs
parents:
diff changeset
   312
/*!
hgs
parents:
diff changeset
   313
 Slot to update teh play pause action icon.
hgs
parents:
diff changeset
   314
 */
hgs
parents:
diff changeset
   315
void MpMediaWallView::updatePlayPauseAction()
hgs
parents:
diff changeset
   316
{
hgs
parents:
diff changeset
   317
    if ( !mActivated ) {
hgs
parents:
diff changeset
   318
        mIconUpdateNedded = true;
hgs
parents:
diff changeset
   319
        return;
hgs
parents:
diff changeset
   320
    }
hgs
parents:
diff changeset
   321
    TX_ENTRY
hgs
parents:
diff changeset
   322
    switch ( mPlaybackData->playbackState() ) {
hgs
parents:
diff changeset
   323
        case MpPlaybackData::Playing:
hgs
parents:
diff changeset
   324
            TX_LOG_ARGS( "MpPlaybackData::Playing" )
hgs
parents:
diff changeset
   325
            mPlayPauseAction->setIcon( *mPauseIcon );
hgs
parents:
diff changeset
   326
            mPlayPauseContainer->show();
hgs
parents:
diff changeset
   327
            break;
hgs
parents:
diff changeset
   328
        case MpPlaybackData::Paused:
hgs
parents:
diff changeset
   329
        case MpPlaybackData::Stopped:
hgs
parents:
diff changeset
   330
            TX_LOG_ARGS( "MpPlaybackData::Paused" )
hgs
parents:
diff changeset
   331
            mPlayPauseAction->setIcon( *mPlayIcon );
hgs
parents:
diff changeset
   332
            mPlayPauseContainer->show();
hgs
parents:
diff changeset
   333
            break;
hgs
parents:
diff changeset
   334
        case MpPlaybackData::NotPlaying:
hgs
parents:
diff changeset
   335
            mPlayPauseContainer->hide();       
hgs
parents:
diff changeset
   336
            break;
hgs
parents:
diff changeset
   337
        default:
hgs
parents:
diff changeset
   338
            break;
hgs
parents:
diff changeset
   339
    }
hgs
parents:
diff changeset
   340
    TX_EXIT
hgs
parents:
diff changeset
   341
}
hgs
parents:
diff changeset
   342
hgs
parents:
diff changeset
   343
/*!
hgs
parents:
diff changeset
   344
 Slot called to start the album and list opening animation.
hgs
parents:
diff changeset
   345
 */
hgs
parents:
diff changeset
   346
void MpMediaWallView::showTrackList()
hgs
parents:
diff changeset
   347
{
hgs
parents:
diff changeset
   348
    if( mShowingSongsList ) {
hgs
parents:
diff changeset
   349
        return;
hgs
parents:
diff changeset
   350
    }
hgs
parents:
diff changeset
   351
    mShowingSongsList = true;
hgs
parents:
diff changeset
   352
    setUpListAnimation();
hgs
parents:
diff changeset
   353
    mListShowAnimationGroup->setDirection(QAbstractAnimation::Forward);
hgs
parents:
diff changeset
   354
    mListShowAnimationGroup->start();
37
hgs
parents: 36
diff changeset
   355
    mModel->setItemVisibility( mMediaWallWidget->currentIndex(), false );
35
hgs
parents:
diff changeset
   356
}
hgs
parents:
diff changeset
   357
hgs
parents:
diff changeset
   358
/*!
hgs
parents:
diff changeset
   359
 Slot to be called to starts the album and list closing animation.
hgs
parents:
diff changeset
   360
 */
hgs
parents:
diff changeset
   361
void MpMediaWallView::hideTracksList()
hgs
parents:
diff changeset
   362
{
hgs
parents:
diff changeset
   363
    mListShowAnimationGroup->setDirection(QAbstractAnimation::Backward);
hgs
parents:
diff changeset
   364
    connect(mListShowAnimationGroup, SIGNAL(finished()), this, SLOT(dismissListClosingAnimation()));
hgs
parents:
diff changeset
   365
    mListShowAnimationGroup->start();
hgs
parents:
diff changeset
   366
}
hgs
parents:
diff changeset
   367
hgs
parents:
diff changeset
   368
/*!
hgs
parents:
diff changeset
   369
 Slot to be called when list closing animation is done or when we want to cancel the animation.
hgs
parents:
diff changeset
   370
 */
hgs
parents:
diff changeset
   371
void MpMediaWallView::dismissListClosingAnimation()
hgs
parents:
diff changeset
   372
{
hgs
parents:
diff changeset
   373
    if ( !mShowingSongsList ) {
hgs
parents:
diff changeset
   374
        return;
hgs
parents:
diff changeset
   375
    }
hgs
parents:
diff changeset
   376
    mShowingSongsList = false;
hgs
parents:
diff changeset
   377
    mAlbumCover->hide();
hgs
parents:
diff changeset
   378
    mTrackList->hide();
37
hgs
parents: 36
diff changeset
   379
    mModel->setItemVisibility( mMediaWallWidget->currentIndex(), true );
35
hgs
parents:
diff changeset
   380
    mListShowAnimationGroup->stop();
hgs
parents:
diff changeset
   381
    disconnect(mListShowAnimationGroup, SIGNAL(finished()), this, SLOT(dismissListClosingAnimation()));
hgs
parents:
diff changeset
   382
}
hgs
parents:
diff changeset
   383
hgs
parents:
diff changeset
   384
/*!
hgs
parents:
diff changeset
   385
 Slot to be called when a list item is selected by the user.
hgs
parents:
diff changeset
   386
 */
hgs
parents:
diff changeset
   387
void MpMediaWallView::listItemActivated( const QModelIndex &index )
hgs
parents:
diff changeset
   388
{
hgs
parents:
diff changeset
   389
    int albumIndex = mMediaWallWidget->currentIndex().row();
hgs
parents:
diff changeset
   390
    //We are playing on the shared engine, but we pass the collection data that
hgs
parents:
diff changeset
   391
    //points to albums on media wall, this is used to construct the playlist.
hgs
parents:
diff changeset
   392
    MpEngineFactory::sharedEngine()->playAlbumSongs( albumIndex, index.row(), mCollectionData );
hgs
parents:
diff changeset
   393
}
hgs
parents:
diff changeset
   394
hgs
parents:
diff changeset
   395
/*!
37
hgs
parents: 36
diff changeset
   396
 Slot to be called to fetch the songs for an album.
hgs
parents: 36
diff changeset
   397
 */
hgs
parents: 36
diff changeset
   398
void MpMediaWallView::fetchAlbumSongs(QModelIndex index)
hgs
parents: 36
diff changeset
   399
{
hgs
parents: 36
diff changeset
   400
    if ( !mCollectionData->setCurrentAlbum( index.row() ) ) {
hgs
parents: 36
diff changeset
   401
        mEngine->findAlbumSongs( index.row() );
hgs
parents: 36
diff changeset
   402
    }
hgs
parents: 36
diff changeset
   403
}
hgs
parents: 36
diff changeset
   404
hgs
parents: 36
diff changeset
   405
/*!
35
hgs
parents:
diff changeset
   406
 Loads the media wall widget.
hgs
parents:
diff changeset
   407
 */
hgs
parents:
diff changeset
   408
void MpMediaWallView::setUpMediaWallWidget()
hgs
parents:
diff changeset
   409
{
37
hgs
parents: 36
diff changeset
   410
    HbIcon defaultIcon( "qtg_large_album_art" );
35
hgs
parents:
diff changeset
   411
    defaultIcon.setSize(mMediaWallWidget->itemSize());
hgs
parents:
diff changeset
   412
    mMediaWallWidget->setDefaultImage( defaultIcon.pixmap().toImage() );
37
hgs
parents: 36
diff changeset
   413
    mMediaWallWidget->enableReflections( true );
35
hgs
parents:
diff changeset
   414
    mMediaWallWidget->setModel( mModel );
hgs
parents:
diff changeset
   415
    if ( mPlaybackData->playbackState() != MpPlaybackData::NotPlaying ) {
hgs
parents:
diff changeset
   416
        scrollToNowPlaying();
hgs
parents:
diff changeset
   417
    }
hgs
parents:
diff changeset
   418
    //The rest of the cases are attepting to balance the items on screen.
hgs
parents:
diff changeset
   419
    else if ( mModel->rowCount() >= 5 ) {
hgs
parents:
diff changeset
   420
        /* 5 and more
hgs
parents:
diff changeset
   421
        [0] [1] [X] [3] [4]...
hgs
parents:
diff changeset
   422
        */
hgs
parents:
diff changeset
   423
        QModelIndex index;
hgs
parents:
diff changeset
   424
        index = mModel->index( 2 );
hgs
parents:
diff changeset
   425
        mMediaWallWidget->scrollTo( index );
hgs
parents:
diff changeset
   426
    }
hgs
parents:
diff changeset
   427
    else if ( mModel->rowCount() >=3  ) {
hgs
parents:
diff changeset
   428
        /* 4 and 3
hgs
parents:
diff changeset
   429
        __ [0] [X] [2] [3]
hgs
parents:
diff changeset
   430
        __ [0] [X] [2] __
hgs
parents:
diff changeset
   431
        */
hgs
parents:
diff changeset
   432
        QModelIndex index;
hgs
parents:
diff changeset
   433
        index = mModel->index( 1 );
hgs
parents:
diff changeset
   434
        mMediaWallWidget->scrollTo( index );
hgs
parents:
diff changeset
   435
    }
hgs
parents:
diff changeset
   436
    else {
hgs
parents:
diff changeset
   437
        /* 2 and 1
hgs
parents:
diff changeset
   438
        __ __ [X] [1] __
hgs
parents:
diff changeset
   439
        __ __ [X] __ __
hgs
parents:
diff changeset
   440
        */
hgs
parents:
diff changeset
   441
        QModelIndex index;
hgs
parents:
diff changeset
   442
        index = mModel->index( 0 );
hgs
parents:
diff changeset
   443
        mMediaWallWidget->scrollTo( index );
hgs
parents:
diff changeset
   444
    }
hgs
parents:
diff changeset
   445
    mMediaWallWidget->setTitleFontSpec( HbFontSpec( HbFontSpec::Primary ) );
hgs
parents:
diff changeset
   446
    mMediaWallWidget->setDescriptionFontSpec( HbFontSpec( HbFontSpec::Secondary ) );
hgs
parents:
diff changeset
   447
    mMediaWallWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); //HgWidget::ScrollBarAutoHide
hgs
parents:
diff changeset
   448
    mMediaWallWidget->scrollBar()->setInteractive( true );
hgs
parents:
diff changeset
   449
    mMediaWallWidget->setIndexFeedbackPolicy( HgWidget::IndexFeedbackSingleCharacter );
37
hgs
parents: 36
diff changeset
   450
    connect(mMediaWallWidget, SIGNAL(animationAboutToEnd(QModelIndex)), SLOT(fetchAlbumSongs(QModelIndex)));
35
hgs
parents:
diff changeset
   451
    connect(mMediaWallWidget, SIGNAL(activated(QModelIndex)), SLOT(showTrackList()));
hgs
parents:
diff changeset
   452
    connect(mMediaWallWidget, SIGNAL(scrollingStarted()), SLOT(dismissListClosingAnimation()));
hgs
parents:
diff changeset
   453
}
hgs
parents:
diff changeset
   454
hgs
parents:
diff changeset
   455
/*!
hgs
parents:
diff changeset
   456
 Scrolls the media wall to now playing position.
hgs
parents:
diff changeset
   457
 */
hgs
parents:
diff changeset
   458
void MpMediaWallView::scrollToNowPlaying()
hgs
parents:
diff changeset
   459
{
hgs
parents:
diff changeset
   460
    if ( mMediaWallWidget  && mPlaybackData->playbackState() != MpPlaybackData::NotPlaying ) {
hgs
parents:
diff changeset
   461
        int albumId = mPlaybackData->albumId();
hgs
parents:
diff changeset
   462
        QModelIndex index;
hgs
parents:
diff changeset
   463
        index = mModel->index( mCollectionData->itemIndex( albumId ) );
hgs
parents:
diff changeset
   464
        mMediaWallWidget->scrollTo( index );
hgs
parents:
diff changeset
   465
    }
hgs
parents:
diff changeset
   466
}
hgs
parents:
diff changeset
   467
hgs
parents:
diff changeset
   468
/*!
hgs
parents:
diff changeset
   469
 Sets up the album and list animation.
hgs
parents:
diff changeset
   470
 */
hgs
parents:
diff changeset
   471
void MpMediaWallView::setUpListAnimation()
hgs
parents:
diff changeset
   472
{
hgs
parents:
diff changeset
   473
    if ( !mListShowAnimationGroup ) {
hgs
parents:
diff changeset
   474
        mListShowAnimationGroup = new QParallelAnimationGroup( this );
hgs
parents:
diff changeset
   475
        mCoverShowListAnimation = new QPropertyAnimation(mAlbumCover, "geometry", this );
hgs
parents:
diff changeset
   476
        mCoverShowListAnimation->setDuration( 400 );        
hgs
parents:
diff changeset
   477
        mCoverShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
hgs
parents:
diff changeset
   478
        mListShowAnimationGroup->addAnimation(mCoverShowListAnimation);
hgs
parents:
diff changeset
   479
        mListShowListAnimation = new QPropertyAnimation( mTrackList, "geometry", this );
hgs
parents:
diff changeset
   480
        mListShowListAnimation->setDuration( 400 );
hgs
parents:
diff changeset
   481
        mListShowListAnimation->setEasingCurve(QEasingCurve::InOutCubic);
37
hgs
parents: 36
diff changeset
   482
        mListShowAnimationGroup->addAnimation(mListShowListAnimation);      
35
hgs
parents:
diff changeset
   483
    }
hgs
parents:
diff changeset
   484
    
hgs
parents:
diff changeset
   485
    //Get the current album cover geometry.
hgs
parents:
diff changeset
   486
    QPolygonF poly;
hgs
parents:
diff changeset
   487
    QModelIndex index = mMediaWallWidget->currentIndex();
hgs
parents:
diff changeset
   488
    if ( !mMediaWallWidget->getItemOutline( index, poly ) ) {
hgs
parents:
diff changeset
   489
        return;
hgs
parents:
diff changeset
   490
    }
hgs
parents:
diff changeset
   491
    QRectF itemRect = poly.boundingRect();
hgs
parents:
diff changeset
   492
    
hgs
parents:
diff changeset
   493
    //Get the album cover icon.
hgs
parents:
diff changeset
   494
    QVariant image = mModel->data(index, Qt::DecorationRole);
hgs
parents:
diff changeset
   495
    if ( image.canConvert<HbIcon>() ) {
hgs
parents:
diff changeset
   496
       mAlbumCover->setIcon(image.value<HbIcon>());
hgs
parents:
diff changeset
   497
    }
hgs
parents:
diff changeset
   498
    else {
hgs
parents:
diff changeset
   499
        mAlbumCover->setIcon(HbIcon());
hgs
parents:
diff changeset
   500
    }
hgs
parents:
diff changeset
   501
    
hgs
parents:
diff changeset
   502
    //Mapping form local media wall coords to window coors.
hgs
parents:
diff changeset
   503
    itemRect.moveTo( mMediaWallWidget->geometry().topLeft() + itemRect.topLeft());   
hgs
parents:
diff changeset
   504
    //Calculate start and end position of items for the animation.
hgs
parents:
diff changeset
   505
    QRectF endRect = itemRect;
hgs
parents:
diff changeset
   506
    endRect.moveTo( endRect.topLeft().x() - endRect.size().width() / 2.0, endRect.topLeft().y() );
hgs
parents:
diff changeset
   507
    mCoverShowListAnimation->setStartValue(itemRect);
hgs
parents:
diff changeset
   508
    mCoverShowListAnimation->setEndValue(endRect);
37
hgs
parents: 36
diff changeset
   509
    endRect.moveTo( endRect.topRight() );
35
hgs
parents:
diff changeset
   510
    mListShowListAnimation->setStartValue(itemRect);
hgs
parents:
diff changeset
   511
    mListShowListAnimation->setEndValue(endRect);
hgs
parents:
diff changeset
   512
    
hgs
parents:
diff changeset
   513
    //set initial condition and show to prevent flicker.
hgs
parents:
diff changeset
   514
    mAlbumCover->setPos(itemRect.topLeft());
hgs
parents:
diff changeset
   515
    mTrackList->setPos(itemRect.topLeft());
hgs
parents:
diff changeset
   516
    mTrackList->setGeometry(itemRect);
hgs
parents:
diff changeset
   517
    mAlbumCover->show();
hgs
parents:
diff changeset
   518
    mTrackList->show();
hgs
parents:
diff changeset
   519
}
hgs
parents:
diff changeset
   520