mpviewplugins/mpcollectionviewplugin/src/mpcollectionview.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 view.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <time.h>
       
    20 #include <cstdlib>
       
    21 #include <qtcore>
       
    22 
       
    23 #include <hbinstance.h>
       
    24 #include <hbapplication.h>
       
    25 #include <hbaction.h>
       
    26 #include <hbtoolbar.h>
       
    27 #include <hbmenu.h>
       
    28 #include <hbmessagebox.h>
       
    29 #include <hblistdialog.h>
       
    30 #include <hbinputdialog.h>
       
    31 #include <hblabel.h>
       
    32 
       
    33 #include "mpcollectionview.h"
       
    34 #include "mpcollectiondocumentloader.h"
       
    35 #include "mpcollectioncontainerfactory.h"
       
    36 #include "mpcollectioncontainer.h"
       
    37 #include "mpcollectiondatamodel.h"
       
    38 #include "mpcollectionsongscanner.h"
       
    39 #include "mpmpxframeworkwrapper.h"
       
    40 #include "mpmpxcollectiondata.h"
       
    41 #include "mpnowplayingwidget.h"
       
    42 #include "mpcommondefs.h"
       
    43 #include "mptrace.h"
       
    44 #include "mpsnapshotwidget.h"
       
    45 #include "mpsettingsmanager.h"
       
    46 
       
    47 
       
    48 const char*MUSIC_COLLECTION_DOCML = ":/docml/musiccollection.docml";
       
    49 const char*EFFECT_SELECT = ":/effects/select.fxml";
       
    50 const char*EFFECT_SELECT_END = ":/effects/select_end.fxml";
       
    51 
       
    52 const int KMainToolBarAll = 0;
       
    53 const int KMainToolBarArtists = 1;
       
    54 const int KMainToolBarPlaylists = 2;
       
    55 
       
    56 //const int KPlaylistToolBarAdd = 0;
       
    57 const int KPlaylistToolBarRemove = 1;
       
    58 const int KplaylistToolBarReorder = 2;
       
    59 
       
    60 
       
    61 
       
    62 /*!
       
    63     \class MpCollectionView
       
    64     \brief Music Player collection view.
       
    65 
       
    66     Collection view provides access to music collection in the device.
       
    67     This class owns the menu and the toolbar. In addition, it is
       
    68     responsible for creating UI containers and the underlying engine
       
    69     components and connecting them to work together.
       
    70 */
       
    71 
       
    72 /*!
       
    73     \fn void command( int command )
       
    74 
       
    75     This signal is emitted when the view issues a \a command to the
       
    76     application such as request to switch to a different view.
       
    77  */
       
    78 
       
    79 /*!
       
    80  Constructs the collection view.
       
    81  */
       
    82 MpCollectionView::MpCollectionView()
       
    83     : mCollectionContext(ECollectionContextUnknown),
       
    84       mMpxWrapper(0),
       
    85       mContainerFactory(0),
       
    86       mCollectionContainer(0),
       
    87       mCollectionDataModel(0),
       
    88       mActivated(false),
       
    89       mNowPlayingBanner(0),
       
    90       mBannerAttached(false),
       
    91       mEffectOnGoing(false),
       
    92       mDocumentLoader(0),
       
    93       mMainContainer(0),
       
    94       mMainToolBar(0),
       
    95       mPlaylistToolBar(0),
       
    96       mSnapshot(0),
       
    97       mSongScanner(0),
       
    98       mScanning(false)
       
    99 {
       
   100     TX_LOG
       
   101 }
       
   102 
       
   103 /*!
       
   104  Destructs the collection view.
       
   105  */
       
   106 MpCollectionView::~MpCollectionView()
       
   107 {
       
   108     TX_ENTRY
       
   109     delete mSongScanner;
       
   110     delete mSnapshot;
       
   111     delete mSoftKeyQuit;
       
   112     delete mSoftKeyBack;
       
   113 
       
   114     HbToolBar *toolBar = takeToolBar();
       
   115     if ( mMainToolBar != toolBar && mPlaylistToolBar != toolBar ) {
       
   116         delete toolBar;
       
   117     }
       
   118     if ( mMainToolBar) {
       
   119         mMainToolBar->deleteLater();
       
   120     }
       
   121     if ( mPlaylistToolBar ) {
       
   122         mPlaylistToolBar->deleteLater();
       
   123     }
       
   124     
       
   125     delete mCollectionDataModel;
       
   126     delete mCollectionContainer;
       
   127     delete mContainerFactory;
       
   128     delete mMpxWrapper;
       
   129     delete mDocumentLoader;
       
   130     TX_EXIT
       
   131 }
       
   132 
       
   133 /*!
       
   134  Initializes the collection view. Allocates all resources needed by the view.
       
   135  */
       
   136 void MpCollectionView::initializeView()
       
   137 {
       
   138     TX_ENTRY
       
   139 
       
   140     mWindow = mainWindow();
       
   141 
       
   142     // Create softkey actions
       
   143     mSoftKeyQuit = new HbAction(Hb::QuitAction, this);
       
   144     connect( mSoftKeyQuit, SIGNAL(triggered()), this, SLOT(back()) );
       
   145 
       
   146     mSoftKeyBack = new HbAction(Hb::BackAction, this);
       
   147     connect( mSoftKeyBack, SIGNAL(triggered()), this, SLOT(back()) );
       
   148 
       
   149     mMpxWrapper = new MpMpxFrameworkWrapper(mViewMode);
       
   150     connect( mMpxWrapper, SIGNAL(collectionPlaylistOpened()), this, SLOT(startPlaybackView()) );
       
   151     connect( mMpxWrapper, SIGNAL(playlistSaved(bool)), this, SLOT(playlistSaved(bool)), Qt::QueuedConnection );
       
   152     connect( mMpxWrapper, SIGNAL(songsDeleted(bool)), this, SLOT(songsDeleted(bool)), Qt::QueuedConnection );
       
   153     connect( mMpxWrapper, SIGNAL(playlistsRenamed(bool)), this, SLOT(playlistsRenamed(bool)), Qt::QueuedConnection );
       
   154     mCollectionData = mMpxWrapper->collectionData();
       
   155     connect( mCollectionData, SIGNAL(contextChanged(TCollectionContext)), this, SLOT(setContext(TCollectionContext)) );
       
   156     mCollectionDataModel = new MpCollectionDataModel( mCollectionData );
       
   157 
       
   158     mDocumentLoader = new MpCollectionDocumentLoader();
       
   159     bool ok = false;
       
   160     mDocumentLoader->load( MUSIC_COLLECTION_DOCML, &ok );
       
   161     if ( ok ) {
       
   162         QGraphicsWidget *widget;
       
   163 
       
   164         widget = mDocumentLoader->findWidget(QString("nowPlaying"));
       
   165         mNowPlayingBanner = qobject_cast<MpNowPlayingWidget*>(widget);
       
   166 
       
   167         if ( mViewMode == MpCommon::FetchView ) {
       
   168             // Banner is not needed since playback is stopped when returning
       
   169             // from playback preview. Disable the banner from updating.
       
   170             mNowPlayingBanner->setEnabled(false);
       
   171         }
       
   172         else {
       
   173             connect( mNowPlayingBanner, SIGNAL(clicked()), this, SLOT(nowPlayingBannerActivated()) );
       
   174             connect( mNowPlayingBanner, SIGNAL(playbackAttachmentChanged(bool)), this, SLOT(attachNowPlayingBanner(bool)) );
       
   175             HbEffect::add( QString("banner"), EFFECT_SELECT, QString("chosen") );
       
   176             HbEffect::add( QString("banner"), EFFECT_SELECT_END, QString("chosenEnd") );
       
   177         }
       
   178 
       
   179         widget = mDocumentLoader->findWidget(QString("mainContainer"));
       
   180         mMainContainer = qobject_cast<HbWidget*>(widget);
       
   181 
       
   182         setWidget(mMainContainer);
       
   183 
       
   184         HbEffect::add(QString("container"),
       
   185                 QString(":/effects/slide_out_to_left.fxml"),
       
   186                 QString("slide_out_to_left") );
       
   187 
       
   188         HbEffect::add(QString("container"),
       
   189                 QString(":/effects/slide_out_to_right.fxml"),
       
   190                 QString("slide_out_to_right") );
       
   191 
       
   192         HbEffect::add(QString("container"),
       
   193                 QString(":/effects/slide_out_to_top.fxml"),
       
   194                 QString("slide_out_to_top") );
       
   195 
       
   196         HbEffect::add(QString("container"),
       
   197                 QString(":/effects/slide_in_to_right_and_fade_in.fxml"),
       
   198                 QString("slide_in_to_right_and_fade_in") );
       
   199 
       
   200         HbEffect::add(QString("container"),
       
   201                 QString(":/effects/slide_in_to_left_and_fade_in.fxml"),
       
   202                 QString("slide_in_to_left_and_fade_in") );
       
   203 
       
   204         HbEffect::add(QString("container"),
       
   205                 QString(":/effects/slide_in_to_top_and_fade_in.fxml"),
       
   206                 QString("slide_in_to_top_and_fade_in") );
       
   207     }
       
   208     else {
       
   209         TX_LOG_ARGS("Error: invalid xml file.");
       
   210         Q_ASSERT_X(ok, "MpCollectionView::initializeView", "invalid xml file");
       
   211     }
       
   212 
       
   213     mContainerFactory = new MpCollectionContainerFactory(this, mDocumentLoader);
       
   214 
       
   215     if ( MpSettingsManager::firstStartup() ) {
       
   216         mSongScanner = new MpCollectionSongScanner(mMpxWrapper);
       
   217         connect(mSongScanner, SIGNAL(scanEnded()), this, SLOT(handleScanningComplete()));
       
   218         mScanning = true;
       
   219         mSongScanner->scan();
       
   220     }
       
   221 
       
   222     TX_EXIT
       
   223 }
       
   224 
       
   225 /*!
       
   226  Activates the collection view.
       
   227  */
       
   228 void MpCollectionView::activateView()
       
   229 {
       
   230     if ( mScanning ) {
       
   231         return;
       
   232     }
       
   233     mActivated = true;
       
   234     TX_ENTRY_ARGS("mCollectionContext=" << mCollectionContext);
       
   235     if ( mCollectionContext == ECollectionContextUnknown ) {
       
   236         // Open 'All Songs' by default
       
   237         mMpxWrapper->openCollection( ECollectionContextAllSongs );
       
   238     }
       
   239     else {
       
   240         // This true when returning from other views, e.g. playback view
       
   241         setSoftkey();
       
   242     }
       
   243     TX_EXIT
       
   244 }
       
   245 
       
   246 /*!
       
   247  Deactivates the collection view.
       
   248  */
       
   249 void MpCollectionView::deactivateView()
       
   250 {
       
   251     TX_ENTRY
       
   252     clearSoftkey();
       
   253     mActivated = false;
       
   254     TX_EXIT
       
   255 }
       
   256 
       
   257 /*!
       
   258  Loads the correct layout based on the \a orientation.
       
   259  */
       
   260 void MpCollectionView::orientationChange( Qt::Orientation orientation )
       
   261 {
       
   262     if ( mCollectionContainer ) {
       
   263         mCollectionContainer->orientationChange(orientation);
       
   264     }
       
   265 
       
   266     if ( mBannerAttached ) {
       
   267         if ( orientation == Qt::Vertical ) {
       
   268             setBannerVisibility(true);
       
   269         }
       
   270         else {
       
   271             setBannerVisibility(false);
       
   272         }
       
   273     }
       
   274 }
       
   275 
       
   276 /*!
       
   277  Slot to be called when collection context is changed as a result of Open
       
   278  operation.
       
   279  */
       
   280 void MpCollectionView::setContext( TCollectionContext context )
       
   281 {
       
   282     TX_ENTRY_ARGS("context=" << context);
       
   283     if (mActivated) {
       
   284         startContainerTransition(mCollectionContext, context);
       
   285     }
       
   286     mCollectionContext = context;
       
   287     mCollectionContainer = mContainerFactory->createContainer(context);
       
   288     mCollectionContainer->setViewMode(mViewMode);
       
   289     mCollectionDataModel->refreshModel();
       
   290     mCollectionContainer->setDataModel(mCollectionDataModel);
       
   291 
       
   292     // Reset softkey and the menu
       
   293     if (mActivated) {
       
   294         clearSoftkey();
       
   295         setSoftkey();
       
   296     }
       
   297     updateToolBar();
       
   298     updateMenu();
       
   299     TX_EXIT
       
   300 }
       
   301 
       
   302 /*!
       
   303  Slot to be called when 'All Songs' action is triggered from the toolbar.
       
   304  */
       
   305 void MpCollectionView::openSongs()
       
   306 {
       
   307     TX_ENTRY
       
   308     mMpxWrapper->openCollection( ECollectionContextAllSongs );
       
   309     TX_EXIT
       
   310 }
       
   311 
       
   312 /*!
       
   313  Slot to be called when 'Artists' action is triggered from the toolbar.
       
   314  */
       
   315 void MpCollectionView::openArtists()
       
   316 {
       
   317     TX_ENTRY
       
   318     mMpxWrapper->openCollection( ECollectionContextArtistAlbums );
       
   319     TX_EXIT
       
   320 }
       
   321 
       
   322 /*!
       
   323  Slot to be called when 'Playlists' action is triggered from the toolbar.
       
   324  */
       
   325 void MpCollectionView::openPlaylists()
       
   326 {
       
   327     TX_ENTRY
       
   328     mMpxWrapper->openCollection( ECollectionContextPlaylists );
       
   329     TX_EXIT
       
   330 }
       
   331 
       
   332 /*!
       
   333  Slot to be called when 'Genres' action is triggered from the toolbar.
       
   334  */
       
   335 void MpCollectionView::openGenres()
       
   336 {
       
   337     TX_ENTRY
       
   338     mMpxWrapper->openCollection( ECollectionContextGenres );
       
   339     TX_EXIT
       
   340 }
       
   341 
       
   342 /*!
       
   343  Slot to be called when 'Find' action is triggered from the toolbar.
       
   344  */
       
   345 void MpCollectionView::find()
       
   346 {
       
   347     // Todo
       
   348     HbMessageBox messageBox("Not ready!", HbMessageBox::MessageTypeInformation);
       
   349     messageBox.exec();
       
   350     updateToolBar();
       
   351 }
       
   352 
       
   353 /*!
       
   354  Slot to be called when 'Music Store' action is triggered from the toolbar.
       
   355  */
       
   356 void MpCollectionView::openMusicStore()
       
   357 {
       
   358     // Todo
       
   359     HbMessageBox messageBox("Not ready!", HbMessageBox::MessageTypeInformation);
       
   360     messageBox.exec();
       
   361     updateToolBar();
       
   362 }
       
   363 
       
   364 /*!
       
   365  Slot to be called when an item is selected by the user.
       
   366  */
       
   367 void MpCollectionView::openIndex( int index )
       
   368 {
       
   369     TX_ENTRY_ARGS("index=" << index);
       
   370     bool doOpen = true;
       
   371     if ( mViewMode == MpCommon::FetchView ) {
       
   372         QString songUri;
       
   373         switch ( mCollectionContext ) {
       
   374             case ECollectionContextAllSongs:
       
   375             case ECollectionContextAlbumSongs:
       
   376             case ECollectionContextPlaylistSongs:
       
   377             case ECollectionContextGenreSongs:
       
   378                 doOpen = false;
       
   379                 songUri = mCollectionData->itemData(index, MpMpxCollectionData::Uri);
       
   380                 emit songSelected(songUri);
       
   381                 break;
       
   382             default:
       
   383                 break;
       
   384         }
       
   385     }
       
   386     if ( doOpen ) {
       
   387         mMpxWrapper->openCollectionItem( index );
       
   388     }
       
   389     TX_EXIT
       
   390 }
       
   391 
       
   392 /*!
       
   393  Slot to be called when back/quit softkey is pressed.
       
   394  */
       
   395 void MpCollectionView::back()
       
   396 {
       
   397     TX_ENTRY_ARGS("mCollectionContext=" << mCollectionContext);
       
   398     bool doExit(false);
       
   399     switch ( mCollectionContext ) {
       
   400         case ECollectionContextAllSongs:
       
   401         case ECollectionContextArtistAlbums:
       
   402         case ECollectionContextPlaylists:
       
   403         case ECollectionContextGenres:
       
   404             // Exit from these levels.
       
   405             doExit = true;
       
   406             break;
       
   407         case ECollectionContextAlbumSongs:
       
   408         case ECollectionContextPlaylistSongs:
       
   409         case ECollectionContextGenreSongs:
       
   410             mMpxWrapper->back();
       
   411             break;
       
   412         default:
       
   413             doExit = true;
       
   414             break;
       
   415     }
       
   416 
       
   417     if ( doExit ) {
       
   418 	    if ( mViewMode == MpCommon::FetchView ) {
       
   419             // Send an empty string to indicate that user has cancelled
       
   420             // the fetch operation
       
   421             emit songSelected("");
       
   422         }
       
   423         else {
       
   424             emit command( MpCommon::Exit );
       
   425         }
       
   426     }
       
   427     TX_EXIT
       
   428 }
       
   429 
       
   430 /*!
       
   431  Slot to be called to exit.
       
   432  */
       
   433 void MpCollectionView::exit()
       
   434 {
       
   435     TX_ENTRY
       
   436     emit command( MpCommon::Exit );
       
   437     TX_EXIT
       
   438 }
       
   439 
       
   440 
       
   441 /*!
       
   442  Slot to be called to activate playback view.
       
   443  */
       
   444 void MpCollectionView::startPlaybackView()
       
   445 {
       
   446     TX_LOG
       
   447     emit command( MpCommon::ActivatePlaybackView );
       
   448 }
       
   449 
       
   450 /*!
       
   451  Slot to be called when 'Now Playing Banner' state changes. If active, 'Now
       
   452  Playing Banner' is attached/shown in the collection view.
       
   453  */
       
   454 void MpCollectionView::attachNowPlayingBanner( bool active )
       
   455 {
       
   456     TX_ENTRY
       
   457     setBannerVisibility( active );
       
   458     mBannerAttached = active;
       
   459     updateMenu();
       
   460     TX_EXIT
       
   461 }
       
   462 
       
   463 /*!
       
   464  Slot to be called when 'Now Playing Banner' is clicked by the user.
       
   465  */
       
   466 void MpCollectionView::nowPlayingBannerActivated()
       
   467 {
       
   468     if ( !mEffectOnGoing ) {
       
   469         HbEffect::start(mNowPlayingBanner, QString("banner"), QString("chosen"), this, "nowPlayingBannerChosenFxComplete1");
       
   470         mEffectOnGoing = true;
       
   471     }
       
   472 }
       
   473 
       
   474 /*!
       
   475  Slot for 'Now Playing Banner' effects part 1.
       
   476  */
       
   477 void MpCollectionView::nowPlayingBannerChosenFxComplete1( const HbEffect::EffectStatus &status )
       
   478 {
       
   479     Q_UNUSED(status);
       
   480     HbEffect::start(mNowPlayingBanner, QString("banner"), QString("chosenEnd"), this, "nowPlayingBannerChosenFxComplete2");
       
   481 }
       
   482 
       
   483 /*!
       
   484  Slot for 'Now Playing Banner' effects part 2. The end.
       
   485  */
       
   486 void MpCollectionView::nowPlayingBannerChosenFxComplete2( const HbEffect::EffectStatus &status )
       
   487 {
       
   488     Q_UNUSED(status);
       
   489     mEffectOnGoing = false;
       
   490     startPlaybackView();
       
   491 }
       
   492 
       
   493 /*!
       
   494  Slot for container transition end.
       
   495  */
       
   496 void MpCollectionView::containerTransitionComplete( const HbEffect::EffectStatus &status )
       
   497 {
       
   498     Q_UNUSED(status);
       
   499     qobject_cast<QGraphicsView *>(mWindow)->scene()->removeItem(mSnapshot);
       
   500     delete mSnapshot;
       
   501     mSnapshot = 0;
       
   502 }
       
   503 
       
   504 /*!
       
   505  Slot to be called when 'Shuffle play all' is clicked by the user from the menu.
       
   506  */
       
   507 void MpCollectionView::shufflePlayAll()
       
   508 {
       
   509     mMpxWrapper->setShuffle(true);
       
   510     MpSettingsManager::setShuffle(true);
       
   511     int index = generateShuffleIndex();
       
   512     openIndex(index);
       
   513 }
       
   514 
       
   515 
       
   516 /*!
       
   517  Slot to be called when 'Refresh Library' is clicked by the user from the menu.
       
   518  */
       
   519 void MpCollectionView::refreshLibrary()
       
   520 {
       
   521     if ( !mSongScanner ) {
       
   522         mSongScanner = new MpCollectionSongScanner(mMpxWrapper);
       
   523         connect(mSongScanner, SIGNAL(scanEnded()), this, SLOT(handleScanningComplete()));
       
   524     }
       
   525     mScanning = true;
       
   526     mSongScanner->scan();
       
   527 }
       
   528 
       
   529 /*!
       
   530  Slot to be called when 'Add to playlist' is clicked by the user from the menu.
       
   531  */
       
   532 void MpCollectionView::addToPlaylist()
       
   533 {
       
   534     QModelIndexList SelectedModelIndexes;
       
   535     bool ok;
       
   536     SelectedModelIndexes = HbListDialog::getModelIndexes(QString(tr("Select songs:")), 
       
   537             mCollectionDataModel,
       
   538             &ok,
       
   539             HbAbstractItemView::MultiSelection);
       
   540                 
       
   541     if (ok && SelectedModelIndexes.count()) {
       
   542         QList<int> selection;
       
   543         for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   544             selection.append( SelectedModelIndexes.at(i).row() );
       
   545         }
       
   546     launchAddToPlaylistDialog(selection);
       
   547     } 
       
   548 }
       
   549 
       
   550 /*!
       
   551  Slot to be called when 'Delete' is clicked by the user from the menu.
       
   552  */
       
   553 void MpCollectionView::deleteSongs()
       
   554 {
       
   555     QModelIndexList SelectedModelIndexes;
       
   556     bool ok;
       
   557     SelectedModelIndexes = HbListDialog::getModelIndexes(QString(tr("Select songs:")), 
       
   558             mCollectionDataModel,
       
   559             &ok,
       
   560             HbAbstractItemView::MultiSelection);
       
   561                 
       
   562     if (ok && SelectedModelIndexes.count()) {
       
   563         QList<int> selection;
       
   564         for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   565             selection.append( SelectedModelIndexes.at(i).row() );
       
   566         }
       
   567     requestDelete(selection);
       
   568     updateMenu();
       
   569     }
       
   570 }
       
   571 
       
   572 /*!
       
   573  Slot to be called when 'Rename Playlist' is clicked by the user from the menu.
       
   574  */
       
   575 void MpCollectionView::renameCurrentPlaylistContainer()
       
   576 {
       
   577     QString currentName;
       
   578     currentName = mCollectionData->collectionTitle();
       
   579     bool ok = false;
       
   580     QString newName;
       
   581     newName = HbInputDialog::getText(QString(tr("Enter name:")), currentName, &ok);
       
   582     if ( ok && ( currentName != newName ) ) 
       
   583     mMpxWrapper->renamePlaylist( newName );   
       
   584 }
       
   585 
       
   586 
       
   587 /*!
       
   588  Slot to be called when 'Add to playlist' operation has completed.
       
   589  */
       
   590 void MpCollectionView::playlistSaved( bool success )
       
   591 {
       
   592     if (success && mCollectionContext == ECollectionContextPlaylists) {
       
   593 	      mMpxWrapper->reopenCollection();
       
   594     }
       
   595 }
       
   596 
       
   597 /*!
       
   598  Slot to be called when 'Delete' operation has completed.
       
   599  */
       
   600 void MpCollectionView::songsDeleted( bool success )
       
   601 {
       
   602     if ( success ) {
       
   603         mMpxWrapper->reopenCollection();
       
   604     }
       
   605 }
       
   606 /*!
       
   607  Slot to be called when 'Rename' operation has completed.
       
   608  */
       
   609 void MpCollectionView::playlistsRenamed( bool success )
       
   610 {
       
   611     if ( success ) {
       
   612         mMpxWrapper->reopenCollection();
       
   613     }
       
   614 }
       
   615 
       
   616 /*!
       
   617  Slot to be called when scan completes.
       
   618  */
       
   619 void MpCollectionView::handleScanningComplete()
       
   620 {
       
   621     TX_ENTRY
       
   622     mScanning = false;
       
   623     if ( mActivated ) {
       
   624         mMpxWrapper->reopenCollection();
       
   625     }
       
   626     else {
       
   627         activateView();
       
   628     }
       
   629     TX_EXIT
       
   630 }
       
   631 
       
   632 /*!
       
   633  Slot to be called when an item is long pressed by the user.
       
   634  */
       
   635 void MpCollectionView::openContextMenu( int index, const QPointF &coords )
       
   636 {
       
   637     TX_ENTRY_ARGS("index=" << index);
       
   638     switch ( mViewMode ) {
       
   639         case MpCommon::DefaultView:
       
   640             openDefaultViewContextMenu(index, coords);
       
   641             break;
       
   642         case MpCommon::FetchView:
       
   643             openFetchViewContextMenu(index, coords);
       
   644             break;
       
   645         default:
       
   646             break;
       
   647     }
       
   648     TX_EXIT
       
   649 }
       
   650 
       
   651 /*!
       
   652  Default view context menu.
       
   653  */
       
   654 void MpCollectionView::openDefaultViewContextMenu(int index, const QPointF &coords)
       
   655 {
       
   656     HbMenu *contextMenu = 0;
       
   657     HbAction *action;
       
   658     switch (mCollectionContext) {
       
   659         case ECollectionContextAllSongs:
       
   660         case ECollectionContextAlbumSongs:
       
   661             contextMenu = new HbMenu();
       
   662             action = contextMenu->addAction(QString(tr("Add to playlist")));
       
   663             action->setObjectName("add");
       
   664             action = contextMenu->addAction(QString(tr("Delete")));
       
   665             action->setObjectName("delete");
       
   666             break;
       
   667         case ECollectionContextArtistAlbums:
       
   668             contextMenu = new HbMenu();
       
   669             action = contextMenu->addAction(QString(tr("Add to playlist")));
       
   670             action->setObjectName("add");
       
   671             action = contextMenu->addAction(QString(tr("Delete")));
       
   672             action->setObjectName("delete");
       
   673             break;
       
   674         case ECollectionContextPlaylists:
       
   675             if ( !mCollectionData->isAutoPlaylist(index) ) {
       
   676                 contextMenu = new HbMenu();
       
   677                 action = contextMenu->addAction(QString(tr("Delete")));
       
   678                 action->setObjectName("delete");
       
   679                 action = contextMenu->addAction(QString(tr("Rename")));
       
   680                 action->setObjectName("rename playlist");
       
   681             }
       
   682             break;
       
   683         case ECollectionContextPlaylistSongs:
       
   684             if ( !mCollectionData->isAutoPlaylist() ) {
       
   685                 contextMenu = new HbMenu();
       
   686                 action = contextMenu->addAction(QString(tr("Remove")));
       
   687                 action->setObjectName("delete");
       
   688             }
       
   689             break;
       
   690         default:
       
   691             break;
       
   692     }
       
   693 
       
   694     if ( contextMenu ) {
       
   695         HbAction *selectedAction = contextMenu->exec(coords);
       
   696         if ( selectedAction ) {
       
   697             QString objectName = selectedAction->objectName();
       
   698             QList<int> selection;
       
   699             selection.append(index);
       
   700             if ( objectName == "add" ) {
       
   701                 launchAddToPlaylistDialog(selection);
       
   702             }
       
   703             else if ( objectName == "delete" ) {
       
   704                 requestDelete(selection);
       
   705             }
       
   706             else if ( objectName == "rename playlist" ) {
       
   707                 QString currentName;
       
   708                 currentName = mCollectionData->itemData(index, MpMpxCollectionData::Title);
       
   709                 bool ok = false;
       
   710                 QString newName;
       
   711                 newName = HbInputDialog::getText(QString(tr("Enter name:")), currentName, &ok);
       
   712                 if ( ok && ( currentName != newName ) ) {
       
   713                     mMpxWrapper->renamePlaylist( newName, index );   
       
   714                 }
       
   715             }
       
   716         }
       
   717     }
       
   718     contextMenu->deleteLater();
       
   719     TX_EXIT
       
   720 }
       
   721 
       
   722 /*!
       
   723  Fetch view context menu
       
   724  */
       
   725 void MpCollectionView::openFetchViewContextMenu( int index, const QPointF &coords )
       
   726 {
       
   727     TX_ENTRY_ARGS("index=" << index);
       
   728 
       
   729     HbMenu *contextMenu = 0;
       
   730     switch ( mCollectionContext ) {
       
   731         case ECollectionContextAllSongs:
       
   732         case ECollectionContextAlbumSongs:
       
   733         case ECollectionContextPlaylistSongs:
       
   734         case ECollectionContextGenreSongs:
       
   735             contextMenu = new HbMenu();
       
   736             contextMenu->addAction(QString(tr("Play")));
       
   737             break;
       
   738         default:
       
   739             break;
       
   740     }
       
   741 
       
   742     if ( contextMenu) {
       
   743         if ( contextMenu->exec(coords) ) {
       
   744             // Start the playback process. View will switch to playbackview.
       
   745             mMpxWrapper->previewItem( index );
       
   746         }
       
   747     }
       
   748     contextMenu->deleteLater();
       
   749     TX_EXIT
       
   750 }
       
   751 
       
   752 /*!
       
   753  \internal
       
   754  Sets the main (default) toolbar for the view.
       
   755  */
       
   756 void MpCollectionView::setMainToolBar()
       
   757 {
       
   758     TX_ENTRY
       
   759     if ( !mMainToolBar ) {
       
   760         //Create the toolbar.
       
   761         mMainToolBar = new HbToolBar();
       
   762         mMainToolBar->setOrientation(Qt::Horizontal);
       
   763         QActionGroup *actionsGroup = new QActionGroup( mMainToolBar );
       
   764         HbAction *action;
       
   765     
       
   766         // All Songs
       
   767         action = createToolBarAction(actionsGroup,
       
   768                 ":/icons/all_songs_on",
       
   769                 ":/icons/all_songs",
       
   770                 tr("All"));
       
   771         connect( action, SIGNAL(triggered(bool)), this, SLOT(openSongs()) );
       
   772         mMainToolBar->addAction(action);
       
   773     
       
   774         // Artists
       
   775         action = createToolBarAction(actionsGroup,
       
   776                 ":/icons/artists_on",
       
   777                 ":/icons/artists",
       
   778                 tr("Artists"));
       
   779         connect( action, SIGNAL(triggered(bool)), this, SLOT(openArtists()) );
       
   780         mMainToolBar->addAction(action);
       
   781     
       
   782         // Playlists
       
   783         action = createToolBarAction(actionsGroup,
       
   784                 ":/icons/playlists_on",
       
   785                 ":/icons/playlists",
       
   786                 tr("Playlists"));
       
   787         connect( action, SIGNAL(triggered(bool)), this, SLOT(openPlaylists()) );
       
   788         mMainToolBar->addAction(action);
       
   789     
       
   790         // Genres
       
   791         action = createToolBarAction(actionsGroup,
       
   792                 ":/icons/search_on",
       
   793                 ":/icons/search",
       
   794                 tr("Search"));
       
   795         connect( action, SIGNAL(triggered(bool)), this, SLOT(find()) );
       
   796         mMainToolBar->addAction(action);
       
   797     
       
   798         if ( mViewMode != MpCommon::FetchView ) {
       
   799             // Music Store
       
   800             action = createToolBarAction(actionsGroup,
       
   801                     ":/icons/ovi_on",
       
   802                     ":/icons/ovi",
       
   803                     tr("Ovi"));
       
   804             connect( action, SIGNAL(triggered(bool)), this, SLOT(openMusicStore()) );
       
   805             mMainToolBar->addAction(action);
       
   806         }
       
   807     }
       
   808     HbAction* action = 0;
       
   809     switch ( mCollectionContext ) {
       
   810         case ECollectionContextAllSongs:
       
   811             action = qobject_cast<HbAction*>(mMainToolBar->actions()[KMainToolBarAll]);
       
   812             break;
       
   813         case ECollectionContextArtistAlbums:
       
   814         case ECollectionContextAlbumSongs:
       
   815             action = qobject_cast<HbAction*>(mMainToolBar->actions()[KMainToolBarArtists]);
       
   816             break;
       
   817         case ECollectionContextPlaylists:
       
   818         case ECollectionContextPlaylistSongs:
       
   819             action = qobject_cast<HbAction*>(mMainToolBar->actions()[KMainToolBarPlaylists]);
       
   820             break;
       
   821     }
       
   822     if ( action ) {
       
   823         action->setChecked(true);
       
   824     }
       
   825     if ( toolBar() != mMainToolBar ) {
       
   826         HbToolBar *tmpToolBar = takeToolBar();
       
   827         if ( tmpToolBar && tmpToolBar->actions().empty() ) {
       
   828             tmpToolBar->deleteLater();
       
   829         }
       
   830         setToolBar(mMainToolBar);
       
   831     }
       
   832     TX_EXIT
       
   833 }
       
   834 
       
   835 /*!
       
   836  \internal
       
   837  Sets the playlist toolbar for the view.
       
   838  Used only on the playlist container.
       
   839  */
       
   840 void MpCollectionView::setPlaylistToolBar()
       
   841 {
       
   842     TX_ENTRY
       
   843     if ( !mPlaylistToolBar ) {
       
   844         mPlaylistToolBar = new HbToolBar();
       
   845         mPlaylistToolBar->setOrientation(Qt::Horizontal);
       
   846         HbAction *action;      
       
   847         
       
   848         action = new HbAction( tr("Add") );
       
   849         connect( action, SIGNAL(triggered(bool)), this, SLOT(notimplemented()) );
       
   850         mPlaylistToolBar->addAction(action);
       
   851         
       
   852         action = new HbAction( tr("Remove") );
       
   853         connect( action, SIGNAL(triggered(bool)), this, SLOT(deleteSongs()));
       
   854         mPlaylistToolBar->addAction(action);
       
   855     
       
   856         action = new HbAction( tr("Reorder") );
       
   857         connect( action, SIGNAL(triggered(bool)), this, SLOT(notimplemented()) );
       
   858         mPlaylistToolBar->addAction(action);
       
   859     }
       
   860  
       
   861     int items = mCollectionData->count();
       
   862         
       
   863     //no use for remove if there are no items.
       
   864     mPlaylistToolBar->actions()[KPlaylistToolBarRemove]->setEnabled(items > 0); 
       
   865      
       
   866     //no use for reorder if there is no more than 1 item.
       
   867     mPlaylistToolBar->actions()[KplaylistToolBarReorder]->setEnabled(items > 1);
       
   868         
       
   869     if ( toolBar() != mPlaylistToolBar ) {
       
   870         HbToolBar *tmpToolBar = takeToolBar();
       
   871         if (tmpToolBar && tmpToolBar->actions().empty ()) {
       
   872             tmpToolBar->deleteLater();
       
   873         }
       
   874         setToolBar(mPlaylistToolBar);
       
   875     }
       
   876     TX_EXIT
       
   877 }
       
   878 
       
   879 /*!
       
   880  \internal
       
   881  Creates action associated with the action group for the toolbar.
       
   882  */
       
   883 HbAction *MpCollectionView::createToolBarAction(
       
   884     QActionGroup *actionsGroup,
       
   885     const QString& iconOn,
       
   886     const QString& iconOff,
       
   887     const QString& toolTip )
       
   888 {
       
   889     HbIcon actionIcon(iconOff);
       
   890     // button pressed icon
       
   891     actionIcon.setIconName(iconOn, QIcon::Normal, QIcon::On );
       
   892 
       
   893     HbAction *action = new HbAction(actionsGroup);
       
   894     action->setToolTip(toolTip);
       
   895     action->setIcon(actionIcon);
       
   896     action->setCheckable(true);
       
   897     return action;
       
   898 }
       
   899 
       
   900 /*!
       
   901  \internal
       
   902  Updates the options menu according to current context.
       
   903  */
       
   904 void MpCollectionView::updateMenu()
       
   905 {
       
   906     TX_ENTRY
       
   907     HbMenu* myMenu = new HbMenu();
       
   908     if ( mViewMode == MpCommon::DefaultView ) {
       
   909         bool items = mCollectionData->count() != 0;
       
   910         if ( mBannerAttached ) {
       
   911             connect( myMenu->addAction(tr("Go to Now Playing")), SIGNAL(triggered()), this, SLOT(startPlaybackView()) );
       
   912         }
       
   913         switch (mCollectionContext) {
       
   914             case ECollectionContextAllSongs:
       
   915                 if (items) {
       
   916                     connect( myMenu->addAction(tr("Shuffle play all")), SIGNAL(triggered()), this, SLOT(shufflePlayAll()) );
       
   917                 }
       
   918                 connect( myMenu->addAction(tr("Refresh library")), SIGNAL(triggered()), this, SLOT(refreshLibrary()) );
       
   919                 if (items) {
       
   920                     connect( myMenu->addAction(tr("Add to playlist")), SIGNAL(triggered()), this, SLOT(addToPlaylist()), Qt::QueuedConnection );
       
   921                 }
       
   922                 connect( myMenu->addAction(tr("Exit")), SIGNAL(triggered()), this, SLOT(exit()) );
       
   923                 break;
       
   924             case ECollectionContextArtistAlbums:
       
   925                 //connect( myMenu->addAction(tr("Add to playlist")), SIGNAL(triggered()), this, SLOT(addToPlaylist()), Qt::QueuedConnection );
       
   926                 // Todo: View as coverflow
       
   927                 break;
       
   928             case ECollectionContextAlbumSongs:
       
   929                 if (items) {
       
   930                     connect( myMenu->addAction(tr("Add to playlist")), SIGNAL(triggered()), this, SLOT(addToPlaylist()), Qt::QueuedConnection );
       
   931                 }
       
   932                 break;
       
   933             case ECollectionContextPlaylists:
       
   934                 // Todo: Create new playlist
       
   935                 break;
       
   936             case ECollectionContextPlaylistSongs:
       
   937                 if ( !mCollectionData->isAutoPlaylist() ) {
       
   938                     connect( myMenu->addAction(tr("Rename playlist")), SIGNAL(triggered()), this, SLOT(renameCurrentPlaylistContainer()), Qt::QueuedConnection );
       
   939                 }
       
   940                 break;
       
   941             default:
       
   942                 break;
       
   943         }
       
   944     }
       
   945     else if (mViewMode == MpCommon::FetchView ) {
       
   946         if ( mCollectionContext == ECollectionContextAllSongs ) {
       
   947             connect( myMenu->addAction(tr("Refresh library")), SIGNAL(triggered()), this, SLOT(refreshLibrary()) );
       
   948         }
       
   949     }
       
   950 
       
   951     setMenu(myMenu);
       
   952     TX_EXIT
       
   953 }
       
   954 
       
   955 /*!
       
   956  \internal
       
   957  Updates the Toolbar according to current context.
       
   958  */
       
   959 void MpCollectionView::updateToolBar()
       
   960 {
       
   961     TX_ENTRY
       
   962 
       
   963     switch (mCollectionContext) {
       
   964         case ECollectionContextPlaylistSongs:
       
   965             if ( !mCollectionData->isAutoPlaylist() ) {
       
   966                 setPlaylistToolBar();
       
   967             }
       
   968             else if (!toolBar()->actions().empty()) {
       
   969                 takeToolBar();
       
   970                 setToolBar(new HbToolBar);
       
   971             } 
       
   972             break;
       
   973         case ECollectionContextAlbumSongs:
       
   974         case ECollectionContextGenreSongs:
       
   975             if (!toolBar()->actions().empty()) {
       
   976                 takeToolBar();
       
   977                 setToolBar(new HbToolBar);
       
   978             }
       
   979             break;
       
   980         default:
       
   981             setMainToolBar();
       
   982             break;
       
   983     }
       
   984     TX_EXIT
       
   985 }
       
   986 
       
   987 /*!
       
   988  \internal
       
   989  Updates the softkey according to current context.
       
   990  */
       
   991 void MpCollectionView::setSoftkey()
       
   992 {
       
   993     if ( mViewMode == MpCommon::FetchView ) {
       
   994         // 'Back' is used in all views in fetch mode because we must
       
   995         // appear as an embedded application.
       
   996         mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack);
       
   997     }
       
   998     else {
       
   999         switch ( mCollectionContext ) {
       
  1000             case ECollectionContextAllSongs:
       
  1001             case ECollectionContextArtistAlbums:
       
  1002             case ECollectionContextPlaylists:
       
  1003             case ECollectionContextGenres:
       
  1004                 mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyQuit);
       
  1005                 break;
       
  1006             default:
       
  1007                 mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack);
       
  1008                 break;
       
  1009         }
       
  1010     }
       
  1011 }
       
  1012 
       
  1013 /*!
       
  1014  \internal
       
  1015  Clears the softkey set by this view. Restore to previous.
       
  1016  */
       
  1017 void MpCollectionView::clearSoftkey()
       
  1018 {
       
  1019     mWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBack);
       
  1020     mWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyQuit);
       
  1021 }
       
  1022 
       
  1023 /*!
       
  1024  \internal
       
  1025  Sets the Now Playing Banner visibility based on \a visible.
       
  1026  */
       
  1027 void MpCollectionView::setBannerVisibility( bool visible )
       
  1028 {
       
  1029     bool ok = false;
       
  1030     if ( visible && (hbInstance->allMainWindows()[0]->orientation() == Qt::Vertical)) {
       
  1031         mDocumentLoader->load(MUSIC_COLLECTION_DOCML, "showBanner", &ok);
       
  1032         mNowPlayingBanner->show();
       
  1033     }
       
  1034     else {
       
  1035         mDocumentLoader->load(MUSIC_COLLECTION_DOCML, "hideBanner", &ok);
       
  1036         mNowPlayingBanner->hide();
       
  1037     }
       
  1038 
       
  1039     if ( !ok ) {
       
  1040         TX_LOG_ARGS("Error: invalid xml file.");
       
  1041         Q_ASSERT_X(ok, "MpCollectionView::setBannerVisibility", "invalid xml file");
       
  1042     }
       
  1043 }
       
  1044 
       
  1045 /*!
       
  1046  \internal
       
  1047  Generates a random index for shuffle all.
       
  1048  */
       
  1049 int MpCollectionView::generateShuffleIndex()
       
  1050 {
       
  1051     int low = 0;
       
  1052     int high = mCollectionData->count();
       
  1053 
       
  1054     time_t seconds;
       
  1055     time(&seconds);
       
  1056     srand((unsigned int) seconds);
       
  1057 
       
  1058     int index = rand() % (high - low + 1) + low;
       
  1059     return index;
       
  1060 }
       
  1061 
       
  1062 /*!
       
  1063  \internal
       
  1064  Launches the 'Add to playlist' dialog.
       
  1065  */
       
  1066 void MpCollectionView::launchAddToPlaylistDialog( QList<int> selection )
       
  1067 {
       
  1068     QString newPlaylistName;
       
  1069     int playlistIndex;
       
  1070     bool canceled = false;
       
  1071 
       
  1072     forever {
       
  1073         QStringList list;
       
  1074         mMpxWrapper->findPlaylists(list);
       
  1075         if ( list.count()) {
       
  1076             HbListDialog dialog;
       
  1077             dialog.setStringItems(list);
       
  1078             dialog.setSelectionMode(HbAbstractItemView::SingleSelection);
       
  1079             dialog.setHeadingWidget(new HbLabel(QString(tr("Choose a playlist:"))));
       
  1080             dialog.setPrimaryAction(new HbAction(QString(tr("New"))));
       
  1081             dialog.setSecondaryAction(new HbAction(QString(tr("Cancel"))));
       
  1082             HbAction *selectedAction = dialog.exec();
       
  1083             if ( selectedAction == dialog.secondaryAction() ) {
       
  1084                 // Cancel
       
  1085                 break;
       
  1086             }
       
  1087             else if ( selectedAction != dialog.primaryAction()) {
       
  1088                 // User selected existing playlist
       
  1089                 playlistIndex = dialog.selectedItems().at(0);
       
  1090                 mMpxWrapper->saveToPlaylist(playlistIndex, selection);
       
  1091                 break;
       
  1092             }
       
  1093         }
       
  1094         else if (canceled) {
       
  1095             break;
       
  1096         }
       
  1097 
       
  1098         // New - create a suggested name for the playlist
       
  1099         QString suggestedPlaylistName(tr("Playlist"));
       
  1100         int i = 0;
       
  1101         for (;
       
  1102              list.contains( QString( suggestedPlaylistName + "(" + QString::number(i) + ")" ) ) ;
       
  1103              i++ ) {};
       
  1104         suggestedPlaylistName += QString("(" + QString::number( i ) + ")");
       
  1105         // Loop until the user cancels or enters a valid name
       
  1106         forever {
       
  1107             QString suggestedText;
       
  1108             bool ok = false;
       
  1109             suggestedText = HbInputDialog::getText(QString(tr("Enter a name for the new playlist:")), suggestedPlaylistName, &ok);
       
  1110             if ( !ok ) {
       
  1111                 canceled = true;
       
  1112                 break;
       
  1113             }
       
  1114             if ( !list.contains(suggestedText) ) {
       
  1115             	  newPlaylistName = suggestedText;
       
  1116                 mMpxWrapper->createPlaylist(newPlaylistName, selection);
       
  1117                 return;
       
  1118             }
       
  1119         }
       
  1120     }
       
  1121 }
       
  1122 
       
  1123 /*!
       
  1124  \internal
       
  1125  starts a transition of the main container with a decoy snapshot.
       
  1126  */
       
  1127 void MpCollectionView::startContainerTransition(TCollectionContext contextFrom, TCollectionContext contextTo)
       
  1128 {
       
  1129     if (!mSnapshot)
       
  1130       mSnapshot = new MpSnapshotWidget();
       
  1131     mSnapshot->capture(mWindow, mMainContainer );
       
  1132     mWindow->scene()->addItem(mSnapshot);
       
  1133 
       
  1134 
       
  1135     if ( ( contextFrom == ECollectionContextArtistAlbums && contextTo == ECollectionContextAlbumSongs ) ||
       
  1136             ( contextFrom == ECollectionContextPlaylists && contextTo == ECollectionContextPlaylistSongs ) ||
       
  1137             ( contextFrom == ECollectionContextGenres && contextTo == ECollectionContextGenreSongs ) ){
       
  1138         HbEffect::start(mSnapshot,
       
  1139                 QString("container"),
       
  1140                 QString("slide_out_to_left"));
       
  1141 
       
  1142         HbEffect::start(mMainContainer,
       
  1143                 QString("container"),
       
  1144                 QString("slide_in_to_left_and_fade_in"),
       
  1145                 this,
       
  1146                 "containerTransitionComplete");
       
  1147     }
       
  1148     else if(( contextFrom == ECollectionContextAlbumSongs && contextTo == ECollectionContextArtistAlbums) ||
       
  1149             ( contextFrom == ECollectionContextPlaylistSongs && contextTo == ECollectionContextPlaylists) ||
       
  1150             ( contextFrom == ECollectionContextGenreSongs && contextTo == ECollectionContextGenres)) {
       
  1151         HbEffect::start(mSnapshot,
       
  1152                 QString("container"),
       
  1153                 QString("slide_out_to_right"));
       
  1154 
       
  1155         HbEffect::start(mMainContainer,
       
  1156                 QString("container"),
       
  1157                 QString("slide_in_to_right_and_fade_in"),
       
  1158                 this,
       
  1159                 "containerTransitionComplete");
       
  1160     }
       
  1161     else {
       
  1162         HbEffect::start(mSnapshot,
       
  1163                 QString("container"),
       
  1164                 QString("slide_out_to_top"));
       
  1165 
       
  1166         HbEffect::start(mMainContainer,
       
  1167                 QString("container"),
       
  1168                 QString("slide_in_to_top_and_fade_in"),
       
  1169                 this,
       
  1170                 "containerTransitionComplete");
       
  1171     }
       
  1172 
       
  1173 }
       
  1174 
       
  1175 /*!
       
  1176  \internal
       
  1177  request a delete operation always it has been confirmed.
       
  1178  */
       
  1179 void MpCollectionView::requestDelete(QList<int> selection)
       
  1180 {           
       
  1181     bool confirmation(false);
       
  1182     // Todo: Use HbMessageBox::question when time-out removed from it
       
  1183     HbMessageBox dialog(HbMessageBox::MessageTypeQuestion);
       
  1184     QString message;
       
  1185     HbAction *action;
       
  1186     
       
  1187     switch (mCollectionContext) {
       
  1188         case ECollectionContextAllSongs:
       
  1189         case ECollectionContextAlbumSongs:
       
  1190             message = QString(tr("Delete song?"));
       
  1191             dialog.setText(message);
       
  1192             dialog.setTimeout(HbPopup::NoTimeout);
       
  1193             action = dialog.exec();
       
  1194             if (action == dialog.primaryAction()) {
       
  1195                 confirmation = true;
       
  1196             }
       
  1197             break;
       
  1198         case ECollectionContextArtistAlbums:
       
  1199             message = QString(tr("Delete album?"));
       
  1200             dialog.setText(message);
       
  1201             dialog.setTimeout(HbPopup::NoTimeout);
       
  1202             action = dialog.exec();
       
  1203             if (action == dialog.primaryAction()) {
       
  1204                 confirmation = true;
       
  1205             }
       
  1206             break;
       
  1207         case ECollectionContextPlaylists:
       
  1208             message = QString(tr("Delete playlist?"));
       
  1209             dialog.setText(message);
       
  1210             dialog.setTimeout(HbPopup::NoTimeout);
       
  1211             action = dialog.exec();
       
  1212             if (action == dialog.primaryAction()) {
       
  1213                 confirmation = true;
       
  1214             }
       
  1215             break;            
       
  1216         case ECollectionContextPlaylistSongs:
       
  1217         case ECollectionContextGenres:
       
  1218         case ECollectionContextGenreSongs:
       
  1219             confirmation = true;
       
  1220             break;
       
  1221         case ECollectionContextUnknown:
       
  1222         default:
       
  1223             // We shouldn't be here
       
  1224             TX_LOG_ARGS("Invalid Collection Context:" << mCollectionContext);
       
  1225             break;
       
  1226     }
       
  1227 
       
  1228     if ( confirmation ) {
       
  1229         mMpxWrapper->deleteSongs(selection);
       
  1230     }    
       
  1231 }