mpviewplugins/mpcollectionviewplugin/src/mpcollectioncontainerplaylists.cpp
branchRCL_3
changeset 25 14979e23cb5e
equal deleted inserted replaced
24:26a1709b9fec 25:14979e23cb5e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Music Player collection container definition - Playlists.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtCore>
       
    19 
       
    20 #include <hbdocumentloader.h>
       
    21 #include <hblistview.h>
       
    22 #include <hbgroupbox.h>
       
    23 #include <hblabel.h>
       
    24 
       
    25 #include "mpcollectioncontainerplaylists.h"
       
    26 #include "mpcollectiondatamodel.h"
       
    27 #include "mpmpxcollectiondata.h"
       
    28 #include "mptrace.h"
       
    29 
       
    30 
       
    31 /*!
       
    32     \class MpCollectionContainerPlaylists
       
    33     \brief Music Player collection container definition - Playlists.
       
    34 
       
    35     'Playlists' collection container implements the interface specified
       
    36     by MpCollectionContainer. It provides a layout and widgets for the
       
    37     'Playlists' view.
       
    38 
       
    39     This container handles the following contexts:
       
    40     \li ECollectionContextPlaylists
       
    41     \li ECollectionContextPlaylistSongs
       
    42 
       
    43     \sa MpCollectionContainer
       
    44 */
       
    45 
       
    46 /*!
       
    47  Constructs the collection container.
       
    48  This container handles the both the auto playlists and user created playlists.
       
    49  */
       
    50 MpCollectionContainerPlaylists::MpCollectionContainerPlaylists( HbDocumentLoader *loader, QGraphicsItem *parent )
       
    51     : MpCollectionListContainer(loader, parent),
       
    52       mCurrentPlaylistIndex(0)
       
    53 {
       
    54     TX_LOG
       
    55     mCollectionContext = ECollectionContextPlaylists;
       
    56 
       
    57 }
       
    58 
       
    59 /*!
       
    60  Destructs the collection container.
       
    61  */
       
    62 MpCollectionContainerPlaylists::~MpCollectionContainerPlaylists()
       
    63 {
       
    64     TX_ENTRY
       
    65     delete mList;
       
    66     TX_EXIT
       
    67 }
       
    68 
       
    69 /*!
       
    70  Sets the data model for the container.
       
    71  */
       
    72 void MpCollectionContainerPlaylists::setDataModel( MpCollectionDataModel *dataModel )
       
    73 {
       
    74     TX_ENTRY
       
    75     MpCollectionListContainer::setDataModel(dataModel);
       
    76     if ( mCollectionContext == ECollectionContextPlaylists ) {
       
    77         if ( mList ) {
       
    78             if ( mCollectionData->count() ) {
       
    79                 mList->scrollTo( dataModel->index(mCurrentPlaylistIndex, 0) );
       
    80             }
       
    81         }
       
    82     }
       
    83     TX_EXIT
       
    84 }
       
    85 
       
    86 /*!
       
    87  Slot to be called when an item is selected by the user.
       
    88 */
       
    89 void MpCollectionContainerPlaylists::itemActivated( const QModelIndex &index )
       
    90 {
       
    91     if ( mCollectionContext == ECollectionContextPlaylists ) {
       
    92         mCurrentPlaylistIndex = index.row();
       
    93         TX_ENTRY_ARGS("mCurrentPlaylistIndex=" << mCurrentPlaylistIndex);
       
    94     }
       
    95     MpCollectionListContainer::itemActivated(index);
       
    96     TX_EXIT
       
    97 }
       
    98 
       
    99 /*!
       
   100  Slot to be called when data model has new data.
       
   101  Use cases:
       
   102      1) User renames a playlist.
       
   103 	 2) Song added or removed from playlist.
       
   104  */
       
   105 void MpCollectionContainerPlaylists::dataReloaded()
       
   106 {
       
   107     TX_ENTRY
       
   108     MpCollectionListContainer::dataReloaded();
       
   109     if ( mCollectionContext == ECollectionContextPlaylistSongs ) {
       
   110         // Playlist could have been renamed.
       
   111         QString details = mCollectionData->collectionTitle();
       
   112         mInfoBar->setHeading(details);
       
   113         if ( mCollectionData->count() > 1 ) {
       
   114             emit shuffleEnabled(true);
       
   115         }
       
   116         else {
       
   117             emit shuffleEnabled(false);
       
   118         }
       
   119     }
       
   120     TX_EXIT
       
   121 }
       
   122 
       
   123 /*!
       
   124  Sets up the container by organizing widgets according to its layout.
       
   125 
       
   126  \reimp
       
   127  */
       
   128 void MpCollectionContainerPlaylists::setupContainer()
       
   129 {
       
   130     TX_ENTRY_ARGS("mCollectionContext=" << mCollectionContext);
       
   131     
       
   132     mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "showInfoBar");
       
   133        
       
   134     if ( mCollectionData->count() ) {
       
   135         bool ok = false;
       
   136         QGraphicsWidget *widget;
       
   137         if ( mCollectionContext == ECollectionContextPlaylists ) {
       
   138             mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "playlists", &ok);
       
   139             if ( !ok ) {
       
   140                 TX_LOG_ARGS("Error: invalid xml file.");
       
   141                 Q_ASSERT_X(ok, "MpCollectionContainerPlaylists::setupContainer", "invalid xml file");
       
   142             }
       
   143             if ( !mList ) {
       
   144                 widget = mDocumentLoader->findWidget(QString("playlistsList"));
       
   145                 mList = qobject_cast<HbListView*>(widget);
       
   146                 initializeList();
       
   147             }
       
   148 
       
   149             mInfoBar->setHeading(hbTrId("txt_mus_subhead_playlists_1l").arg(mCollectionData->count()));
       
   150         }
       
   151         else if ( mCollectionContext == ECollectionContextPlaylistSongs ) {
       
   152             mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "playlistSongs", &ok);
       
   153             if ( !ok ) {
       
   154                 TX_LOG_ARGS("Error: invalid xml file.");
       
   155                 Q_ASSERT_X(ok, "MpCollectionContainerPlaylists::setupContainer", "invalid xml file");
       
   156             }
       
   157             
       
   158             QString details;
       
   159             if ( mViewMode == MpCommon::FetchView ) {
       
   160                 details = hbTrId("txt_mus_subtitle_select_song");
       
   161             }
       
   162             else {
       
   163                 details = hbTrId("txt_mus_subhead_1_2l").arg(mCollectionData->collectionTitle()).arg(mCollectionData->count()); 
       
   164             }
       
   165             mInfoBar->setHeading(details);
       
   166         }
       
   167         if ( mNoMusic ) {
       
   168             delete mNoMusic;
       
   169             mNoMusic = 0;
       
   170         }
       
   171     }
       
   172     else {
       
   173     
       
   174         mInfoBar->setHeading(hbTrId("txt_mus_subhead_1_2l").arg(mCollectionData->collectionTitle()).arg(0));
       
   175 
       
   176         // Call empty list from base class    
       
   177         setupEmptyListContainer();
       
   178     }
       
   179     TX_EXIT
       
   180 }
       
   181