mpviewplugins/mpcollectionviewplugin/src/mpcollectioncontainerplaylists.cpp
changeset 19 4e84c994a771
child 20 82baf59ce8dd
equal deleted inserted replaced
5:2a40e88564c8 19:4e84c994a771
       
     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 
       
    23 #include "mpcollectioncontainerplaylists.h"
       
    24 #include "mpmpxcollectiondata.h"
       
    25 #include "mpcollectioninfobar.h"
       
    26 #include "mptrace.h"
       
    27 
       
    28 
       
    29 /*!
       
    30     \class MpCollectionContainerPlaylists
       
    31     \brief Music Player collection container definition - Playlists.
       
    32 
       
    33     'Playlists' collection container implements the interface specified
       
    34     by MpCollectionContainer. It provides a layout and widgets for the
       
    35     'Playlists' view.
       
    36 
       
    37     This container handles the following contexts:
       
    38     \li ECollectionContextPlaylists
       
    39     \li ECollectionContextPlaylistSongs
       
    40 
       
    41     \sa MpCollectionContainer
       
    42 */
       
    43 
       
    44 /*!
       
    45  Constructs the collection container.
       
    46  This container handles the both the auto playlists and user created playlists.
       
    47  */
       
    48 MpCollectionContainerPlaylists::MpCollectionContainerPlaylists( HbDocumentLoader *loader, QGraphicsItem *parent )
       
    49     : MpCollectionListContainer(loader, parent),
       
    50       mInfoBar(0),
       
    51       mListInitialized(false)
       
    52 {
       
    53     TX_LOG
       
    54 }
       
    55 
       
    56 /*!
       
    57  Destructs the collection container.
       
    58  */
       
    59 MpCollectionContainerPlaylists::~MpCollectionContainerPlaylists()
       
    60 {
       
    61     TX_ENTRY
       
    62     delete mInfoBar;
       
    63     delete mList;
       
    64     TX_EXIT
       
    65 }
       
    66 
       
    67 /*!
       
    68  Sets up the container by organizing widgets according to its layout.
       
    69 
       
    70  \reimp
       
    71  */
       
    72 void MpCollectionContainerPlaylists::setupContainer()
       
    73 {
       
    74     TX_ENTRY_ARGS("mCollectionContext=" << mCollectionContext);
       
    75 
       
    76     if ( !mList ) {
       
    77         bool ok = false;
       
    78         mDocumentLoader->load(QString(":/docml/musiccollection.docml"), "playlist", &ok);
       
    79 
       
    80         if ( !ok ) {
       
    81             TX_LOG_ARGS("Error: invalid xml file.");
       
    82             Q_ASSERT_X(ok, "MpCollectionContainerPlaylists::setupContainer", "invalid xml file");
       
    83         }
       
    84 
       
    85         QGraphicsWidget *widget;
       
    86         widget = mDocumentLoader->findWidget(QString("playlistDetail"));
       
    87         mInfoBar = qobject_cast<MpCollectionInfoBar*>(widget);
       
    88 
       
    89         widget = mDocumentLoader->findWidget(QString("playlistList"));
       
    90         mList = qobject_cast<HbListView*>(widget);
       
    91         initializeList();
       
    92     }
       
    93 
       
    94     int count = mCollectionData->count();
       
    95     QString details;
       
    96     QString detailsCount;
       
    97     QString playlist;
       
    98     switch ( mCollectionContext ) {
       
    99     case ECollectionContextPlaylists:
       
   100         details.setNum(count);
       
   101         details.append( tr(" playlist(s)") );
       
   102         mInfoBar->setText(details);
       
   103         break;
       
   104     case ECollectionContextPlaylistSongs:
       
   105         if ( mViewMode == MpCommon::FetchView ) {
       
   106             details = "Select a song";
       
   107         }
       
   108         else {
       
   109             details = QString( tr("Playlist: ") );
       
   110             playlist = mCollectionData->collectionTitle();
       
   111             if ( playlist.isEmpty() ) {
       
   112                 playlist = QString( tr("Unknown") );
       
   113             }
       
   114             details.append(playlist);
       
   115             detailsCount.setNum(count);
       
   116         }
       
   117         mInfoBar->setText(details, detailsCount);
       
   118         break;
       
   119     default:
       
   120         TX_LOG_ARGS("Error: Wrong context; should never get here.");
       
   121         break;
       
   122     }
       
   123     TX_EXIT
       
   124 }
       
   125