mpviewplugins/mpcollectionviewplugin/src/mpcollectioncontaineralbums.cpp
changeset 20 82baf59ce8dd
child 29 8192e5b5c935
equal deleted inserted replaced
19:4e84c994a771 20:82baf59ce8dd
       
     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 - Albums.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtCore>
       
    19 
       
    20 #include <hbdocumentloader.h>
       
    21 #include <hblistview.h>
       
    22 #include <hbgroupbox.h>
       
    23 #include <hbindexfeedback.h>
       
    24 
       
    25 #include "mpcollectioncontaineralbums.h"
       
    26 #include "mpmpxcollectiondata.h"
       
    27 #include "mptrace.h"
       
    28 
       
    29 /*!
       
    30     \class MpCollectionContainerAlbums
       
    31     \brief Music Player collection container definition - Albums.
       
    32 
       
    33     'Albums' collection container implements the interface specified
       
    34     by MpCollectionContainer. It provides a layout and widgets for the
       
    35     'Albums' view.
       
    36 
       
    37     This container handles the following contexts:
       
    38     \li ECollectionContextAlbums
       
    39     \li ECollectionContextAlbumSongs
       
    40 
       
    41     \sa MpCollectionContainer
       
    42 */
       
    43 
       
    44 /*!
       
    45  Constructs the collection container.
       
    46  */
       
    47 MpCollectionContainerAlbums::MpCollectionContainerAlbums( HbDocumentLoader *loader, QGraphicsItem *parent )
       
    48     : MpCollectionListContainer(loader, parent),
       
    49       mInfoBar(0)
       
    50 {
       
    51     TX_LOG
       
    52 }
       
    53 
       
    54 /*!
       
    55  Destructs the collection container.
       
    56  */
       
    57 MpCollectionContainerAlbums::~MpCollectionContainerAlbums()
       
    58 {
       
    59     TX_ENTRY
       
    60     delete mInfoBar;
       
    61     delete mList;
       
    62     TX_EXIT
       
    63 }
       
    64 
       
    65 /*!
       
    66  Slot to be called when an item is selected by the user.
       
    67  */
       
    68 void MpCollectionContainerAlbums::itemActivated( const QModelIndex &index )
       
    69 {
       
    70     int row = index.row();
       
    71     TX_ENTRY_ARGS("index=" << row);
       
    72 
       
    73     mAlbum = mCollectionData->itemData(row, MpMpxCollectionData::Title);
       
    74     if ( mAlbum.isEmpty() ) {
       
    75         mAlbum = hbTrId("txt_mus_dblist_val_unknown3");
       
    76     }
       
    77 
       
    78     mArtist = mCollectionData->itemData(row, MpMpxCollectionData::Artist);
       
    79     if ( mArtist.isEmpty() ) {
       
    80         mArtist = hbTrId("txt_mus_subtitle_unknown");
       
    81     }
       
    82 
       
    83     MpCollectionListContainer::itemActivated(index);
       
    84     TX_EXIT
       
    85 }
       
    86 
       
    87 /*!
       
    88  Sets up the container by organizing widgets according to its layout.
       
    89 
       
    90  \reimp
       
    91  */
       
    92 void MpCollectionContainerAlbums::setupContainer()
       
    93 {
       
    94     TX_ENTRY_ARGS("mCollectionContext=" << mCollectionContext);
       
    95     if ( mCollectionData->count() ) {
       
    96         bool ok = false;
       
    97         QGraphicsWidget *widget;
       
    98         if ( mCollectionContext == ECollectionContextAlbums ) {
       
    99             mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "albums", &ok);
       
   100             if ( !ok ) {
       
   101                 TX_LOG_ARGS("Error: invalid xml file.");
       
   102                 Q_ASSERT_X(ok, "MpCollectionContainerAlbums::setupContainer", "invalid xml file");
       
   103             }
       
   104             if ( !mList ) {
       
   105                 widget = mDocumentLoader->findWidget(QString("albumsList"));
       
   106                 mList = qobject_cast<HbListView*>(widget);
       
   107                 mIndexFeedback->setItemView(mList);
       
   108                 initializeList();
       
   109             }
       
   110             if ( mInfoBar ) {
       
   111                 delete mInfoBar;
       
   112                 mInfoBar = 0;
       
   113             }
       
   114         }
       
   115         else if ( mCollectionContext == ECollectionContextAlbumSongs ) {
       
   116             mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "albumSongs", &ok);
       
   117             if ( !ok ) {
       
   118                 TX_LOG_ARGS("Error: invalid xml file.");
       
   119                 Q_ASSERT_X(ok, "MpCollectionContainerAlbums::setupContainer", "invalid xml file");
       
   120             }
       
   121 
       
   122             widget = mDocumentLoader->findWidget(QString("albumSongsDetail"));
       
   123             mInfoBar = qobject_cast<HbGroupBox*>(widget);
       
   124 
       
   125             QString details;
       
   126             if ( mViewMode == MpCommon::FetchView ) {
       
   127                 details = "Select a song";
       
   128             }
       
   129             else {
       
   130                 details = mArtist;
       
   131                 details.append(" : ");
       
   132                 details.append(mAlbum);
       
   133             }
       
   134             mInfoBar->setHeading(details);
       
   135         }
       
   136     }
       
   137     else {
       
   138         if ( mInfoBar ) {
       
   139             // When last song in an album is deleted and album list is reloaded
       
   140             delete mInfoBar;
       
   141             mInfoBar = 0;
       
   142         }
       
   143         // Call empty list from base class
       
   144         setupEmptyListContainer();
       
   145     }
       
   146     TX_EXIT
       
   147 }
       
   148