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