mpviewplugins/mpcollectionviewplugin/src/mpcollectionview.cpp
changeset 25 3ec52facab4d
parent 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
22:ecf06a08d4d9 25:3ec52facab4d
    24 #include <hbapplication.h>
    24 #include <hbapplication.h>
    25 #include <hbaction.h>
    25 #include <hbaction.h>
    26 #include <hbtoolbar.h>
    26 #include <hbtoolbar.h>
    27 #include <hbmenu.h>
    27 #include <hbmenu.h>
    28 #include <hbmessagebox.h>
    28 #include <hbmessagebox.h>
    29 #include <hblistdialog.h>
       
    30 #include <hbinputdialog.h>
       
    31 #include <hblabel.h>
    29 #include <hblabel.h>
    32 #include <QTranslator>
    30 #include <QTranslator>
    33 #include <QLocale>
    31 #include <QLocale>
    34 #include <hblistview.h>
    32 #include <hblistview.h>
    35 #include <hbscrollbar.h>
    33 #include <hbscrollbar.h>
    45 #include "mpcommondefs.h"
    43 #include "mpcommondefs.h"
    46 #include "mptrace.h"
    44 #include "mptrace.h"
    47 #include "mpsnapshotwidget.h"
    45 #include "mpsnapshotwidget.h"
    48 #include "mpsettingsmanager.h"
    46 #include "mpsettingsmanager.h"
    49 #include "mpcollectionlistcontainer.h"
    47 #include "mpcollectionlistcontainer.h"
       
    48 #include "mpcollectionpopuphandler.h"
    50 
    49 
    51 
    50 
    52 const char*MUSIC_COLLECTION_DOCML = ":/docml/musiccollection.docml";
    51 const char*MUSIC_COLLECTION_DOCML = ":/docml/musiccollection.docml";
    53 const char*EFFECT_SELECT = ":/effects/select.fxml";
    52 const char*EFFECT_SELECT = ":/effects/select.fxml";
    54 const char*EFFECT_SELECT_END = ":/effects/select_end.fxml";
    53 const char*EFFECT_SELECT_END = ":/effects/select_end.fxml";
    55 
    54 
    56 const int KMainToolBarAll = 0;
    55 const int KMainToolBarAll = 0;
    57 const int KMainToolBarArtists = 1;
    56 const int KMainToolBarArtists = 1;
    58 
    57 const int KMainToolBarAlbums = 2;
    59 const int KMainToolBarPlaylists = 3;
    58 const int KMainToolBarPlaylists = 3;
    60 
    59 
    61 const int KPlaylistToolBarAdd = 0;
    60 const int KPlaylistToolBarAdd = 0;
    62 const int KPlaylistToolBarRemove = 1;
    61 const int KPlaylistToolBarRemove = 1;
    63 const int KplaylistToolBarReorder = 2;
    62 const int KplaylistToolBarReorder = 2;
    89       mCollectionContainer( 0 ),
    88       mCollectionContainer( 0 ),
    90       mCollectionDataModel( 0 ),
    89       mCollectionDataModel( 0 ),
    91       mActivated( false ),
    90       mActivated( false ),
    92       mNowPlayingBanner( 0 ),
    91       mNowPlayingBanner( 0 ),
    93       mBannerAttached( false ),
    92       mBannerAttached( false ),
    94 	  mSoftKeyQuit( 0 ),
    93       mNavigationQuit( 0 ),
    95       mSoftKeyBack( 0 ),
    94       mNavigationBack( 0 ),
    96       mDocumentLoader( 0 ),
    95       mDocumentLoader( 0 ),
    97       mMainContainer( 0 ),
    96       mMainContainer( 0 ),
    98       mMainToolBar( 0 ),
    97       mMainToolBar( 0 ),
    99       mPlaylistToolBar( 0 ),
    98       mPlaylistToolBar( 0 ),
   100       mSnapshot( 0 ),
    99       mSnapshot( 0 ),
   101       mMpTranslator( 0 ),
   100       mMpTranslator( 0 ),
   102       mCommonTranslator( 0 ),
   101       mCommonTranslator( 0 ),
   103       mActivationWaiting( false ),
   102       mActivationWaiting( false ),
   104       mOutstandingPopup( 0 ),
   103       mMpPopupHandler( 0 ),
   105       mUsbBlocked( false )
   104       mUsbBlocked( false )
   106 {
   105 {
   107     TX_LOG
   106     TX_LOG
   108 }
   107 }
   109 
   108 
   112  */
   111  */
   113 MpCollectionView::~MpCollectionView()
   112 MpCollectionView::~MpCollectionView()
   114 {
   113 {
   115     TX_ENTRY
   114     TX_ENTRY
   116     delete mSnapshot;
   115     delete mSnapshot;
   117     delete mSoftKeyQuit;
   116     delete mNavigationQuit;
   118     delete mSoftKeyBack;
   117     delete mNavigationBack;
   119 
   118 
   120     HbToolBar *toolBar = takeToolBar();
   119     HbToolBar *toolBar = takeToolBar();
   121     if ( mMainToolBar != toolBar && mPlaylistToolBar != toolBar ) {
   120     if ( mMainToolBar != toolBar && mPlaylistToolBar != toolBar ) {
   122         delete toolBar;
   121         delete toolBar;
   123     }
   122     }
   164     }
   163     }
   165 
   164 
   166     mWindow = mainWindow();
   165     mWindow = mainWindow();
   167 
   166 
   168     // Create softkey actions
   167     // Create softkey actions
   169     mSoftKeyQuit = new HbAction( Hb::QuitAction, this );
   168     mNavigationQuit = new HbAction( Hb::QuitNaviAction, this );
   170     connect( mSoftKeyQuit, SIGNAL( triggered() ), this, SLOT( back() ) );
   169     connect( mNavigationQuit, SIGNAL( triggered() ), this, SLOT( back() ) );
   171 
   170 
   172     mSoftKeyBack = new HbAction( Hb::BackAction, this );
   171     mNavigationBack = new HbAction( Hb::BackNaviAction, this );
   173     connect( mSoftKeyBack, SIGNAL( triggered() ), this, SLOT( back() ) );
   172     connect( mNavigationBack, SIGNAL( triggered() ), this, SLOT( back() ) );
   174 
   173 
   175     mMpEngine = MpEngine::instance();
   174     mMpEngine = MpEngine::instance();
   176     
   175     
   177     connect( mMpEngine,
   176     connect( mMpEngine,
   178             SIGNAL( collectionPlaylistOpened() ),
   177             SIGNAL( collectionPlaylistOpened() ),
   253         TX_LOG_ARGS( "Error: invalid xml file." );
   252         TX_LOG_ARGS( "Error: invalid xml file." );
   254         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   253         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   255     }
   254     }
   256 
   255 
   257     mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader );
   256     mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader );
       
   257     
       
   258     mMpPopupHandler = new MpCollectionPopupHandler( this );
   258 
   259 
   259     connect( mMpEngine, SIGNAL( usbBlocked(bool) ),
   260     connect( mMpEngine, SIGNAL( usbBlocked(bool) ),
   260              this, SLOT( handleUsbBlocked(bool) ) );
   261              this, SLOT( handleUsbBlocked(bool) ) );
   261     connect( mMpEngine, SIGNAL( libraryAboutToRefresh() ),
   262     connect( mMpEngine, SIGNAL( libraryAboutToUpdate() ),
   262              this, SLOT( handleLibraryAboutToUpdate() ) );
   263              this, SLOT( handleLibraryAboutToUpdate() ) );
   263     connect( mMpEngine, SIGNAL( libraryRefreshed() ),
   264     connect( mMpEngine, SIGNAL( libraryUpdated() ),
   264              this, SLOT( handleLibraryUpdated() ) );
   265              this, SLOT( handleLibraryUpdated() ) );
   265     mUsbBlocked = mMpEngine->verifyUsbBlocking();
   266     mUsbBlocked = mMpEngine->verifyUsbBlocking();
   266 
   267 
   267     if ( MpSettingsManager::firstStartup() ) {
   268     if ( MpSettingsManager::firstStartup() ) {
   268         mActivationWaiting = true;
   269         mActivationWaiting = true;
   299 void MpCollectionView::deactivateView()
   300 void MpCollectionView::deactivateView()
   300 {
   301 {
   301     TX_ENTRY
   302     TX_ENTRY
   302     mActivated = false;
   303     mActivated = false;
   303 	
   304 	
   304     if ( mOutstandingPopup ) {
   305     cancelOngoingOperation();
   305         mOutstandingPopup->close();
       
   306     }        
       
   307     menu()->close();
       
   308 
   306 
   309     setNavigationAction( 0 );
   307     setNavigationAction( 0 );
   310     TX_EXIT
   308     TX_EXIT
   311 }
   309 }
   312 
   310 
   322     }
   320     }
   323 
   321 
   324     if ( mBannerAttached ) {
   322     if ( mBannerAttached ) {
   325         setBannerVisibility( false );
   323         setBannerVisibility( false );
   326     }
   324     }
   327 
   325     TX_EXIT
       
   326 }
       
   327 
       
   328 /*!
       
   329  Returns view activation status.
       
   330  */
       
   331 bool MpCollectionView::isActivated()
       
   332 {
       
   333     TX_LOG_ARGS( "View activated = " << mActivated );
       
   334     return mActivated;
       
   335 }
       
   336 
       
   337 /*!
       
   338  Opens or plays an item through collection container in order to keep track of the Artist / Album data used by infobar.
       
   339  */
       
   340 void MpCollectionView::openItem( int index )
       
   341 {
       
   342     TX_ENTRY_ARGS( "index = " << index );
       
   343     QModelIndex modelIndex;
       
   344     modelIndex = mCollectionDataModel->index( index );
       
   345     qobject_cast<MpCollectionListContainer*>(mCollectionContainer)->itemActivated( modelIndex );
   328     TX_EXIT
   346     TX_EXIT
   329 }
   347 }
   330 
   348 
   331 /*!
   349 /*!
   332  Slot to be called when collection context is changed as a result of Open
   350  Slot to be called when collection context is changed as a result of Open
   369  Slot to be called when 'Artists' action is triggered from the toolbar.
   387  Slot to be called when 'Artists' action is triggered from the toolbar.
   370  */
   388  */
   371 void MpCollectionView::openArtists()
   389 void MpCollectionView::openArtists()
   372 {
   390 {
   373     TX_ENTRY
   391     TX_ENTRY
       
   392     if ( mCollectionContext != ECollectionContextArtists ) {
       
   393         mMpEngine->openCollection( ECollectionContextArtists );
       
   394     }
       
   395     TX_EXIT
       
   396 }
       
   397 
       
   398 
       
   399 /*!
       
   400  Slot to be called when 'Albums' action is triggered from the toolbar.
       
   401  */
       
   402 void MpCollectionView::openAlbums()
       
   403 {
       
   404     TX_ENTRY
   374     if ( mCollectionContext != ECollectionContextAlbums ) {
   405     if ( mCollectionContext != ECollectionContextAlbums ) {
   375         mMpEngine->openCollection( ECollectionContextAlbums );
   406         mMpEngine->openCollection( ECollectionContextAlbums );
   376     }
   407     }
   377     TX_EXIT
   408     TX_EXIT
   378 }
   409 }
   405  Slot to be called when 'Find' action is triggered from the toolbar.
   436  Slot to be called when 'Find' action is triggered from the toolbar.
   406  */
   437  */
   407 void MpCollectionView::find()
   438 void MpCollectionView::find()
   408 {
   439 {
   409     // Todo
   440     // Todo
   410     HbMessageBox messageBox( "Not ready!", HbMessageBox::MessageTypeInformation );
   441     HbMessageBox *messageBox = new HbMessageBox( "Not ready!", HbMessageBox::MessageTypeInformation );
   411     messageBox.exec();
   442     messageBox->setAttribute( Qt::WA_DeleteOnClose );
       
   443     messageBox->show();
   412     updateToolBar();
   444     updateToolBar();
   413 }
   445 }
   414 
   446 
   415 /*!
   447 /*!
   416  Slot to be called when 'Music Store' action is triggered from the toolbar.
   448  Slot to be called when 'Music Store' action is triggered from the toolbar.
   417  */
   449  */
   418 void MpCollectionView::openMusicStore()
   450 void MpCollectionView::openMusicStore()
   419 {
   451 {
   420     // Todo
   452     // Todo
   421     HbMessageBox messageBox( "Not ready!", HbMessageBox::MessageTypeInformation );
   453     HbMessageBox *messageBox = new HbMessageBox( "Not ready!", HbMessageBox::MessageTypeInformation );
   422     messageBox.exec();
   454     messageBox->setAttribute( Qt::WA_DeleteOnClose );
       
   455     messageBox->show();
   423     updateToolBar();
   456     updateToolBar();
   424 }
   457 }
   425 
   458 
   426 /*!
   459 /*!
   427  Slot to be called when an item is selected by the user.
   460  Slot to be called when an item is selected by the user.
   432     bool doOpen = true;
   465     bool doOpen = true;
   433     if ( mViewMode == MpCommon::FetchView ) {
   466     if ( mViewMode == MpCommon::FetchView ) {
   434         QString songUri;
   467         QString songUri;
   435         switch ( mCollectionContext ) {
   468         switch ( mCollectionContext ) {
   436             case ECollectionContextAllSongs:
   469             case ECollectionContextAllSongs:
       
   470             case ECollectionContextArtistSongs:
   437             case ECollectionContextAlbumSongs:
   471             case ECollectionContextAlbumSongs:
   438             case ECollectionContextPlaylistSongs:
   472             case ECollectionContextPlaylistSongs:
   439             case ECollectionContextGenreSongs:
   473             case ECollectionContextGenreSongs:
   440                 doOpen = false;
   474                 doOpen = false;
   441                 songUri = mCollectionData->itemData( index, MpMpxCollectionData::Uri );
   475                 songUri = mCollectionData->itemData( index, MpMpxCollectionData::Uri );
   444             default:
   478             default:
   445                 break;
   479                 break;
   446         }
   480         }
   447     }
   481     }
   448     if ( doOpen ) {
   482     if ( doOpen ) {
   449         mMpEngine->openCollectionItem( index );
   483         // TODO: "if" used as workaround for HbListView multiple events: longPress and activated.
       
   484         //       Remove once HbListView get fixed (wk14 or 16)
       
   485         if ( !mMpPopupHandler->showingPopup() ) {
       
   486             mMpEngine->openCollectionItem( index );
       
   487         }
   450     }
   488     }
   451     TX_EXIT
   489     TX_EXIT
   452 }
   490 }
   453 
   491 
   454 /*!
   492 /*!
   458 {
   496 {
   459     TX_ENTRY_ARGS( "mCollectionContext=" << mCollectionContext );
   497     TX_ENTRY_ARGS( "mCollectionContext=" << mCollectionContext );
   460     bool doExit( false );
   498     bool doExit( false );
   461     switch ( mCollectionContext ) {
   499     switch ( mCollectionContext ) {
   462         case ECollectionContextAllSongs:
   500         case ECollectionContextAllSongs:
       
   501         case ECollectionContextArtists: 
   463         case ECollectionContextAlbums:
   502         case ECollectionContextAlbums:
   464         case ECollectionContextPlaylists:
   503         case ECollectionContextPlaylists:
   465         case ECollectionContextGenres:
   504         case ECollectionContextGenres:
   466             // Exit from these levels.
   505             // Exit from these levels.
   467             doExit = true;
   506             doExit = true;
   468             break;
   507             break;
   469         case ECollectionContextAlbumSongs:
   508         case ECollectionContextAlbumSongs:
       
   509         case ECollectionContextArtistAlbums:
       
   510         case ECollectionContextArtistSongs:
   470         case ECollectionContextPlaylistSongs:
   511         case ECollectionContextPlaylistSongs:
   471         case ECollectionContextGenreSongs:
   512         case ECollectionContextGenreSongs:
   472             mMpEngine->back();
   513             mMpEngine->back();
   473             break;
   514             break;
   474         default:
   515         default:
   557 /*!
   598 /*!
   558  Slot to be called when 'Add to playlist' is clicked by the user from the menu.
   599  Slot to be called when 'Add to playlist' is clicked by the user from the menu.
   559  */
   600  */
   560 void MpCollectionView::addToPlaylist()
   601 void MpCollectionView::addToPlaylist()
   561 {
   602 {
   562     if ( !mMpEngine->verifyUsbBlocking( true ) ) {
   603     mMpPopupHandler->openAddSongsToPlaylist( mCollectionDataModel );
   563         QModelIndexList SelectedModelIndexes;
       
   564         bool ok;
       
   565         SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),
       
   566                 mCollectionDataModel,
       
   567                 ok);
       
   568 
       
   569         if ( ok && SelectedModelIndexes.count() ) {
       
   570             QList<int> selection;
       
   571             for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   572                 selection.append( SelectedModelIndexes.at( i ).row() );
       
   573             }
       
   574             launchAddToPlaylistDialog( selection );
       
   575         }
       
   576     }
       
   577 }
   604 }
   578 
   605 
   579 /*!
   606 /*!
   580  Slot to be called when 'Delete' is clicked by the user from the menu.
   607  Slot to be called when 'Delete' is clicked by the user from the menu.
   581  */
   608  */
   582 void MpCollectionView::deleteSongs()
   609 void MpCollectionView::deleteSongs()
   583 {
   610 {
   584     QModelIndexList SelectedModelIndexes;
   611     mMpPopupHandler->openDeleteSongs( mCollectionDataModel );
   585     bool ok;
       
   586     SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),
       
   587             mCollectionDataModel,
       
   588             ok);
       
   589 
       
   590     if ( ok && SelectedModelIndexes.count() ) {
       
   591         QList<int> selection;
       
   592         for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   593             selection.append( SelectedModelIndexes.at( i ).row() );
       
   594         }
       
   595         requestDelete( selection );
       
   596         updateMenu();
       
   597     }
       
   598 }
   612 }
   599 
   613 
   600 /*!
   614 /*!
   601  Slot to be called when 'Rename Playlist' is clicked by the user from the menu.
   615  Slot to be called when 'Rename Playlist' is clicked by the user from the menu.
   602  */
   616  */
   603 void MpCollectionView::renameCurrentPlaylistContainer()
   617 void MpCollectionView::renameCurrentPlaylistContainer()
   604 {
   618 {
   605     if ( !mMpEngine->verifyUsbBlocking( true ) ) {
   619     QString currentName;
   606         QString currentName;
   620     currentName = mCollectionData->collectionTitle();    
   607         currentName = mCollectionData->collectionTitle();
   621     mMpPopupHandler->openRenamePlaylistContainerDialog( currentName );
   608         bool ok = false;
       
   609         QString newName;
       
   610         newName = getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName, ok );
       
   611         if ( ok && ( currentName != newName ) ) {
       
   612             mMpEngine->renamePlaylist( newName );
       
   613         }
       
   614     }
       
   615 }
   622 }
   616 
   623 
   617 
   624 
   618 /*!
   625 /*!
   619  Slot to be called when 'Add to playlist' operation has completed.
   626  Slot to be called when 'Add to playlist' operation has completed.
   650 /*!
   657 /*!
   651  Slot to be called to get ready for add to playlist using an isolated collection.
   658  Slot to be called to get ready for add to playlist using an isolated collection.
   652  */
   659  */
   653 void MpCollectionView::prepareToAddToPlaylist()
   660 void MpCollectionView::prepareToAddToPlaylist()
   654 {
   661 {
   655     TX_ENTRY    
   662     TX_ENTRY
   656     //We dismiss dialogs here since after open is complete we are triggering a dialog.
       
   657     setOutstandingPopup( 0 );
       
   658     mMpEngine->openIsolatedCollection( ECollectionContextAllSongs );
   663     mMpEngine->openIsolatedCollection( ECollectionContextAllSongs );
   659     TX_EXIT
   664     TX_EXIT
   660 }
   665 }
   661 
   666 
   662 /*!
   667 /*!
   663  Slot to be called when isolated collection is oppened.
   668  Slot to be called when isolated collection is oppened.
   664  */
   669  */
   665 void MpCollectionView::handleIsolatedCollectionOpened( MpMpxCollectionData* collectionData )
   670 void MpCollectionView::handleIsolatedCollectionOpened( MpMpxCollectionData* collectionData )
   666 {
   671 {
   667     TX_ENTRY
   672     TX_ENTRY
   668     if ( mActivated && !mOutstandingPopup ) {
   673     if ( mActivated ) {
   669 
   674 
   670         if (ECollectionContextPlaylistSongs == mCollectionContext) {
   675         if (ECollectionContextPlaylistSongs == mCollectionContext) {
   671            addToCurrentPlaylist( collectionData );
   676             mMpPopupHandler->openAddToCurrentPlaylist( collectionData );
   672         }
   677         }
   673         else if (ECollectionContextPlaylists == mCollectionContext) {
   678         else if (ECollectionContextPlaylists == mCollectionContext) {
   674             createNewPlaylist( collectionData );
   679             mMpPopupHandler->openCreateNewPlaylist( collectionData );
   675         }
   680         }
   676     }
   681     }
   677     //Playlist is saved asynchronosly by the default collection, it is OK to release now.
   682     TX_EXIT
   678     mMpEngine->releaseIsolatedCollection();
       
   679     TX_EXIT
       
   680 }
       
   681 
       
   682 
       
   683 /*!
       
   684  Slot to be called to add items to current playlist.
       
   685  */
       
   686 void MpCollectionView::addToCurrentPlaylist( MpMpxCollectionData* collectionData )
       
   687 {
       
   688     MpCollectionDataModel *collectionDataModel;
       
   689     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   690     collectionDataModel->refreshModel();
       
   691     QModelIndexList SelectedModelIndexes;
       
   692     bool ok;
       
   693     SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),
       
   694             collectionDataModel,
       
   695             ok);
       
   696 
       
   697     if ( ok && SelectedModelIndexes.count() ) {
       
   698         QList<int> selection;
       
   699         for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   700             selection.append( SelectedModelIndexes.at( i ).row() );
       
   701         }
       
   702         mMpEngine->saveToCurrentPlaylist( selection, collectionData );
       
   703     }
       
   704     delete collectionDataModel;
       
   705 }
       
   706 
       
   707 /*!
       
   708  Slot to be called to add items to new playlist.
       
   709  */
       
   710 void MpCollectionView::createNewPlaylist( MpMpxCollectionData* collectionData )
       
   711 {
       
   712     MpCollectionDataModel *collectionDataModel;
       
   713     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   714     collectionDataModel->refreshModel();
       
   715 
       
   716     QString newPlaylistName;
       
   717     bool ok;
       
   718     QStringList playlists;
       
   719     mMpEngine->findPlaylists( playlists );
       
   720     ok = queryNewPlaylistName(newPlaylistName , playlists);
       
   721     if ( ok ) {
       
   722         QModelIndexList SelectedModelIndexes;
       
   723         SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),
       
   724                 collectionDataModel,
       
   725                 ok);
       
   726         QList<int> selection;
       
   727         if ( ok && SelectedModelIndexes.count() ) {
       
   728             for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) {
       
   729                 selection.append( SelectedModelIndexes.at( i ).row() );
       
   730             }
       
   731         }
       
   732         //Creating Playlist even when there is no selection.
       
   733         mMpEngine->createPlaylist( newPlaylistName, selection, collectionData );
       
   734     }
       
   735     delete collectionDataModel;
       
   736 }
   683 }
   737 
   684 
   738 /*!
   685 /*!
   739  Slot to be called to arrange songs in a playlist.
   686  Slot to be called to arrange songs in a playlist.
   740  */
   687  */
   741 void MpCollectionView::arrangeSongs( )
   688 void MpCollectionView::arrangeSongs( )
   742 {
   689 {
   743     HbListView *listView = new HbListView();
   690     mMpPopupHandler->openArrangeSongs( mCollectionData );
   744     listView->setItemRecycling(true);
       
   745     listView->setScrollingStyle( HbListView::PanOrFlick );
       
   746     listView->setClampingStyle( HbListView::BounceBackClamping );
       
   747     HbScrollBar *scrollbar = listView->verticalScrollBar();
       
   748     scrollbar->show();
       
   749     scrollbar->setInteractive(true);
       
   750     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
       
   751     MpCollectionDataModel *model;
       
   752     //Ownership of the model is passed to the listView as a child object.
       
   753     model = new MpCollectionDataModel( mCollectionData, listView );
       
   754     model->refreshModel();
       
   755     connect( model,
       
   756             SIGNAL( orderChanged( int, int, int, int ) ),
       
   757             mMpEngine,
       
   758             SLOT( reorderPlaylist( int, int, int, int ) ) );
       
   759     listView->setModel( model );
       
   760     listView->setArrangeMode( true );
       
   761     HbDialog *popup = new HbDialog();
       
   762     popup->setAttribute( Qt::WA_DeleteOnClose );
       
   763     popup->setDismissPolicy( HbPopup::NoDismiss );
       
   764     popup->setTimeout( HbPopup::NoTimeout );
       
   765 
       
   766     HbLabel *label = new HbLabel( hbTrId( "txt_mus_title_arrange"  ) );
       
   767     popup->setHeadingWidget( label );
       
   768     popup->setContentWidget( listView );
       
   769     popup->setPrimaryAction( new HbAction( hbTrId( "txt_common_button_ok" ), popup ) );
       
   770     popup->setModal( true );
       
   771     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
   772     //Reopen the collection so the ordinals get fixed on the view list, if we
       
   773     //delete items the index will not match to the item on the collection.
       
   774     connect( popup, SIGNAL( aboutToClose() ), mMpEngine, SLOT( reopenCollection() ) );
       
   775     setOutstandingPopup(popup);
       
   776     popup->show();
       
   777 }
   691 }
   778 
   692 
   779 /*!
   693 /*!
   780  Slot to be called when an item is long pressed by the user.
   694  Slot to be called when an item is long pressed by the user.
   781  */
   695  */
   782 void MpCollectionView::openContextMenu( int index, const QPointF &coords )
   696 void MpCollectionView::openContextMenu( int index, const QPointF &coords )
   783 {
   697 {
   784     TX_ENTRY_ARGS( "index=" << index );
   698     TX_ENTRY_ARGS( "index=" << index );
   785     switch ( mViewMode ) {
   699     switch ( mViewMode ) {
   786         case MpCommon::DefaultView:
   700         case MpCommon::DefaultView:
   787             openDefaultViewContextMenu( index, coords );
   701             mMpPopupHandler->openDefaultViewContextMenu( index, coords );
   788             break;
   702             break;
   789         case MpCommon::FetchView:
   703         case MpCommon::FetchView:
   790             openFetchViewContextMenu( index, coords );
   704             mMpPopupHandler->openFetchViewContextMenu( index, coords );
   791             break;
   705             break;
   792         default:
   706         default:
   793             break;
   707             break;
   794     }
   708     }
   795     TX_EXIT
   709     TX_EXIT
   796 }
   710 }
   797 
   711 
   798 /*!
   712 /*!
   799  Slot to be called when a dialog is about to close.
       
   800  */
       
   801 void MpCollectionView::outstandingPopupClosing()
       
   802 {
       
   803    HbPopup *popup = qobject_cast<HbPopup *>( sender() );
       
   804    if ( popup ) {
       
   805        Q_ASSERT( popup != mOutstandingPopup );
       
   806        mOutstandingPopup = 0;
       
   807    }
       
   808 }
       
   809 
       
   810 /*!
       
   811  Slot to be called when USB blocking status changes.
   713  Slot to be called when USB blocking status changes.
   812  */
   714  */
   813 void MpCollectionView::handleUsbBlocked( bool blocked )
   715 void MpCollectionView::handleUsbBlocked( bool blocked )
   814 {
   716 {
   815     TX_ENTRY_ARGS( "blocked=" << blocked );
   717     TX_ENTRY_ARGS( "blocked=" << blocked );
   816     mUsbBlocked = blocked;
   718     mUsbBlocked = blocked;
   817     
   719         
   818     if ( mActivated && mUsbBlocked && mOutstandingPopup ) {
   720     cancelOngoingOperation();
   819         mOutstandingPopup->close();
       
   820         mMpEngine->verifyUsbBlocking( true );        
       
   821     }
       
   822     
   721     
   823     updateMenu();
   722     updateMenu();
   824     if ( mCollectionContext == ECollectionContextPlaylistSongs ) {
   723     if ( mCollectionContext == ECollectionContextPlaylistSongs ) {
   825          updateToolBar();
   724          updateToolBar();
   826     }
   725     }
   831  Slot to be called when library is going to be updated.
   730  Slot to be called when library is going to be updated.
   832  */
   731  */
   833 void MpCollectionView::handleLibraryAboutToUpdate()
   732 void MpCollectionView::handleLibraryAboutToUpdate()
   834 {
   733 {
   835     TX_ENTRY
   734     TX_ENTRY
   836 
   735     cancelOngoingOperation();
   837     if ( mActivated ) {
       
   838         if ( mOutstandingPopup ) {
       
   839             mOutstandingPopup->close();
       
   840         }        
       
   841         menu()->close();
       
   842     }
       
   843     TX_EXIT
   736     TX_EXIT
   844 }
   737 }
   845 
   738 
   846 /*!
   739 /*!
   847  Slot to be called when refreshing completes or library has been updated.
   740  Slot to be called when refreshing completes or library has been updated.
   852     if ( mActivationWaiting ) {
   745     if ( mActivationWaiting ) {
   853         mActivationWaiting = false;
   746         mActivationWaiting = false;
   854         activateView();
   747         activateView();
   855     }
   748     }
   856     else {
   749     else {
       
   750         cancelOngoingOperation();
       
   751         
   857         //Update cache, even if collection is in background.
   752         //Update cache, even if collection is in background.
   858         //Library refreshing could be triggered at any point due USB connect./disconnect.
   753         //Library refreshing could be triggered at any point due USB/MMC events.
   859         mMpEngine->reopenCollection();
   754         mMpEngine->reopenCollection();
   860     }
   755     }
   861     TX_EXIT
       
   862 }
       
   863 
       
   864 /*!
       
   865  Default view context menu.
       
   866  */
       
   867 void MpCollectionView::openDefaultViewContextMenu( int index, const QPointF &coords )
       
   868 {
       
   869     HbMenu *contextMenu = 0;
       
   870     HbAction *action;
       
   871     switch ( mCollectionContext ) {
       
   872         case ECollectionContextAllSongs:
       
   873         case ECollectionContextAlbumSongs:
       
   874             contextMenu = new HbMenu();
       
   875             action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
       
   876             action->setObjectName( "play" );
       
   877             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
       
   878             action->setObjectName( "add" );
       
   879             action->setEnabled( !mUsbBlocked );
       
   880             action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   881             action->setObjectName( "delete" );
       
   882             action->setEnabled( !mUsbBlocked );
       
   883             break;
       
   884         case ECollectionContextAlbums:
       
   885             contextMenu = new HbMenu();
       
   886             action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
       
   887             action->setObjectName( "open" );
       
   888             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
       
   889             action->setObjectName( "add" );
       
   890             action->setEnabled( !mUsbBlocked );
       
   891             action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   892             action->setObjectName( "delete" );
       
   893             action->setEnabled( !mUsbBlocked );
       
   894             break;
       
   895         case ECollectionContextPlaylists:
       
   896             if ( !mCollectionData->isAutoPlaylist( index ) ) {
       
   897                 contextMenu = new HbMenu();
       
   898                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
       
   899                 action->setObjectName( "open" );
       
   900                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   901                 action->setObjectName("delete");
       
   902                 action->setEnabled( !mUsbBlocked );
       
   903                 action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
       
   904                 action->setObjectName( "rename playlist" );
       
   905                 action->setEnabled( !mUsbBlocked );
       
   906             }
       
   907             break;
       
   908         case ECollectionContextPlaylistSongs:
       
   909             if ( !mCollectionData->isAutoPlaylist() ) {
       
   910                 contextMenu = new HbMenu();
       
   911                 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
       
   912                 action->setObjectName( "play" );
       
   913                 action = contextMenu->addAction( hbTrId( "txt_common_menu_remove" ) );
       
   914                 action->setObjectName( "delete" );
       
   915                 action->setEnabled( !mUsbBlocked );
       
   916             }
       
   917             break;
       
   918         default:
       
   919             break;
       
   920     }
       
   921 
       
   922     if ( contextMenu ) {
       
   923         setOutstandingPopup( contextMenu );
       
   924         HbAction *selectedAction = mActivated ? contextMenu->exec( coords ) : 0;
       
   925         setOutstandingPopup( 0 );
       
   926         if ( selectedAction ) {
       
   927             QString objectName = selectedAction->objectName();
       
   928             QList<int> selection;
       
   929             selection.append( index );
       
   930             if ( objectName == "open" || objectName == "play" ) {
       
   931                 QModelIndex modelIndex;
       
   932                 modelIndex = mCollectionDataModel->index(index);
       
   933                 qobject_cast<MpCollectionListContainer*>(mCollectionContainer)->itemActivated( modelIndex );
       
   934             }
       
   935             else if ( !mMpEngine->verifyUsbBlocking( true ) ) {
       
   936                 if ( objectName == "add" ) {
       
   937                     launchAddToPlaylistDialog( selection );
       
   938                 }
       
   939                 else if ( objectName == "delete" ) {
       
   940                     requestDelete( selection );
       
   941                 }
       
   942                 else if ( objectName == "rename playlist" ) {
       
   943                     QString currentName;
       
   944                     currentName = mCollectionData->itemData( index, MpMpxCollectionData::Title );
       
   945                     bool ok = false;
       
   946                     QString newName;
       
   947                     newName = getText( hbTrId("txt_mus_dialog_enter_name" ), currentName, ok );
       
   948                     if ( ok && ( currentName != newName ) ) {
       
   949                         mMpEngine->renamePlaylist( newName, index );   
       
   950                     }
       
   951                 }
       
   952             }
       
   953         }
       
   954     }
       
   955     contextMenu->deleteLater();
       
   956     TX_EXIT
       
   957 }
       
   958 
       
   959 /*!
       
   960  Fetch view context menu
       
   961  */
       
   962 void MpCollectionView::openFetchViewContextMenu( int index, const QPointF &coords )
       
   963 {
       
   964     TX_ENTRY_ARGS( "index=" << index );
       
   965 
       
   966     HbMenu *contextMenu = 0;
       
   967     switch ( mCollectionContext ) {
       
   968         case ECollectionContextAllSongs:
       
   969         case ECollectionContextAlbumSongs:
       
   970         case ECollectionContextPlaylistSongs:
       
   971         case ECollectionContextGenreSongs:
       
   972             contextMenu = new HbMenu();
       
   973             contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
       
   974             break;
       
   975         default:
       
   976             break;
       
   977     }
       
   978 
       
   979     if ( contextMenu ) {
       
   980         setOutstandingPopup( contextMenu );
       
   981         if ( mActivated ? contextMenu->exec( coords ) : 0 ) {
       
   982             // Start the playback process. View will switch to playbackview.
       
   983             mMpEngine->previewItem( index );
       
   984         }
       
   985         setOutstandingPopup( 0 );
       
   986     }
       
   987     contextMenu->deleteLater();
       
   988     TX_EXIT
   756     TX_EXIT
   989 }
   757 }
   990 
   758 
   991 /*!
   759 /*!
   992  \internal
   760  \internal
  1004 
   772 
  1005         // All Songs
   773         // All Songs
  1006         action = createToolBarAction( actionsGroup, "qtg_mono_songs_all" );
   774         action = createToolBarAction( actionsGroup, "qtg_mono_songs_all" );
  1007         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openSongs() ) );
   775         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openSongs() ) );
  1008         mMainToolBar->addAction( action );
   776         mMainToolBar->addAction( action );
       
   777         
       
   778         // Artists
       
   779         action = createToolBarAction( actionsGroup, "qtg_mono_artists" );
       
   780         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openArtists() ) );
       
   781         mMainToolBar->addAction( action );
  1009 
   782 
  1010         // Albums
   783         // Albums
  1011         action = createToolBarAction( actionsGroup, "qtg_mono_artists_albums" );
   784         action = createToolBarAction( actionsGroup, "qtg_mono_music_albums" );
  1012         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openArtists() ) );
   785         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openAlbums() ) );
  1013         mMainToolBar->addAction( action );
   786         mMainToolBar->addAction( action );
  1014 
   787 
  1015         // Playlists
   788         // Playlists
  1016         action = createToolBarAction( actionsGroup, "qtg_mono_playlist" );
   789         action = createToolBarAction( actionsGroup, "qtg_mono_playlist" );
  1017         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openPlaylists() ) );
   790         connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openPlaylists() ) );
  1032     HbAction* action = 0;
   805     HbAction* action = 0;
  1033     switch ( mCollectionContext ) {
   806     switch ( mCollectionContext ) {
  1034         case ECollectionContextAllSongs:
   807         case ECollectionContextAllSongs:
  1035             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarAll] );
   808             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarAll] );
  1036             break;
   809             break;
       
   810         case ECollectionContextArtists:
       
   811         case ECollectionContextArtistAlbums:
       
   812             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarArtists] );
       
   813             break;
  1037         case ECollectionContextAlbums:
   814         case ECollectionContextAlbums:
  1038         case ECollectionContextAlbumSongs:
   815         case ECollectionContextAlbumSongs:
  1039             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarArtists] );
   816             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarAlbums] );
  1040             break;
   817             break;
  1041         case ECollectionContextPlaylists:
   818         case ECollectionContextPlaylists:
  1042         case ECollectionContextPlaylistSongs:
   819         case ECollectionContextPlaylistSongs:
  1043             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarPlaylists] );
   820             action = qobject_cast<HbAction*>( mMainToolBar->actions()[KMainToolBarPlaylists] );
  1044             break;
   821             break;
  1160                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );                
   937                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );                
  1161                 }
   938                 }
  1162                 else {
   939                 else {
  1163                     menuAction->setDisabled( true );
   940                     menuAction->setDisabled( true );
  1164                 }
   941                 }
       
   942                 
       
   943                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
       
   944                 break;
       
   945   
       
   946             case ECollectionContextArtists:
       
   947                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) ); 
       
   948                 if ( !mUsbBlocked ) {
       
   949                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) );                
       
   950                 }
       
   951                 else {
       
   952                     menuAction->setDisabled( true );
       
   953                 }
  1165                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
   954                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
  1166                 break;
   955                 break;
  1167             case ECollectionContextAlbums:
   956             case ECollectionContextAlbums:
  1168                 //connect( myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ), SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
   957                 //connect( myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ), SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
  1169                 // Todo: View as coverflow
   958                 // Todo: View as coverflow
  1174                 else {
   963                 else {
  1175                     menuAction->setDisabled( true );
   964                     menuAction->setDisabled( true );
  1176                 }
   965                 }
  1177                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
   966                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
  1178                 break;
   967                 break;
       
   968             case ECollectionContextArtistSongs:
  1179             case ECollectionContextAlbumSongs:
   969             case ECollectionContextAlbumSongs:
  1180                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ); 
   970                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ); 
  1181                 if ( !mUsbBlocked ) {
   971                 if ( !mUsbBlocked ) {
  1182                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
   972                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
  1183                 }
   973                 }
  1257             else if ( !toolBar()->actions().empty() ) {
  1047             else if ( !toolBar()->actions().empty() ) {
  1258                 takeToolBar();
  1048                 takeToolBar();
  1259                 setToolBar( new HbToolBar );
  1049                 setToolBar( new HbToolBar );
  1260             }
  1050             }
  1261             break;
  1051             break;
       
  1052         case ECollectionContextArtistAlbums:
       
  1053         case ECollectionContextArtistSongs:
  1262         case ECollectionContextAlbumSongs:
  1054         case ECollectionContextAlbumSongs:
  1263         case ECollectionContextGenreSongs:
  1055         case ECollectionContextGenreSongs:
  1264             if ( !toolBar()->actions().empty() ) {
  1056             if ( !toolBar()->actions().empty() ) {
  1265                 takeToolBar();
  1057                 takeToolBar();
  1266                 setToolBar( new HbToolBar );
  1058                 setToolBar( new HbToolBar );
  1280 void MpCollectionView::setSoftkey()
  1072 void MpCollectionView::setSoftkey()
  1281 {
  1073 {
  1282     if ( mViewMode == MpCommon::FetchView ) {
  1074     if ( mViewMode == MpCommon::FetchView ) {
  1283         // 'Back' is used in all views in fetch mode because we must
  1075         // 'Back' is used in all views in fetch mode because we must
  1284         // appear as an embedded application.
  1076         // appear as an embedded application.
  1285         setNavigationAction( mSoftKeyBack );
  1077         setNavigationAction( mNavigationBack );
  1286     }
  1078     }
  1287     else {
  1079     else {
  1288         switch ( mCollectionContext ) {
  1080         switch ( mCollectionContext ) {
  1289             case ECollectionContextAllSongs:
  1081             case ECollectionContextAllSongs:
       
  1082             case ECollectionContextArtists:
  1290             case ECollectionContextAlbums:
  1083             case ECollectionContextAlbums:
  1291             case ECollectionContextPlaylists:
  1084             case ECollectionContextPlaylists:
  1292             case ECollectionContextGenres:
  1085             case ECollectionContextGenres:
  1293                 setNavigationAction( mSoftKeyQuit );
  1086                 setNavigationAction( mNavigationQuit );
  1294                 break;
  1087                 break;
  1295             default:
  1088             default:
  1296                 setNavigationAction( mSoftKeyBack );
  1089                 setNavigationAction( mNavigationBack );
  1297                 break;
  1090                 break;
  1298         }
  1091         }
  1299     }
  1092     }
  1300 }
  1093 }
  1301 
  1094 
  1338     return index;
  1131     return index;
  1339 }
  1132 }
  1340 
  1133 
  1341 /*!
  1134 /*!
  1342  \internal
  1135  \internal
  1343  Launches the 'Add to playlist' dialog.
       
  1344  */
       
  1345 void MpCollectionView::launchAddToPlaylistDialog( QList<int> &selection )
       
  1346 {
       
  1347     if (!mActivated) {
       
  1348        return;
       
  1349     }
       
  1350     QString newPlaylistName;
       
  1351     QStringList playlists;
       
  1352     mMpEngine->findPlaylists( playlists );
       
  1353     HbListDialog dialog;
       
  1354     dialog.setStringItems( playlists );
       
  1355     dialog.setSelectionMode( HbAbstractItemView::SingleSelection );
       
  1356     dialog.setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) );
       
  1357     dialog.setPrimaryAction(new HbAction( hbTrId( "txt_mus_button_new" ) ) );
       
  1358     dialog.setSecondaryAction(new HbAction( hbTrId( "txt_common_button_cancel" ) ) );
       
  1359 
       
  1360     forever {
       
  1361         if ( playlists.count() ) {
       
  1362             //There are saved playlists, query for a saved playlist or new.
       
  1363             setOutstandingPopup( &dialog );
       
  1364             HbAction *selectedAction = mActivated ? dialog.exec() : 0;
       
  1365             setOutstandingPopup( 0 );
       
  1366             if ( selectedAction == dialog.primaryAction() ) {
       
  1367                 //User selected pimaryAction "new", fall trough to new playlyst query.
       
  1368             }
       
  1369             else if ( dialog.selectedItems().count() ) {//this only works for SingleSelection
       
  1370                 // User selected existing playlist, add songs and exit the loop.
       
  1371                 mMpEngine->saveToPlaylist( dialog.selectedItems().at( 0 ), selection );                
       
  1372                 break;
       
  1373             }
       
  1374             else {
       
  1375                 //Cancel was pressed or dialog was closed or never executed, exit the loop.
       
  1376                 break;
       
  1377             }
       
  1378         }
       
  1379         //querying for a new playlist name.
       
  1380         if ( queryNewPlaylistName(newPlaylistName , playlists) ) {
       
  1381             // user selected a new playlist, save and exit the loop.
       
  1382             mMpEngine->createPlaylist( newPlaylistName, selection );
       
  1383             break;
       
  1384         }
       
  1385         else if (!playlists.count()) {
       
  1386             // user decided to not provide a new name and there are no saved playlists, exit the loop
       
  1387             break;
       
  1388         }
       
  1389         // user decided to not provide a new name and there are saved playlists, back to the top.
       
  1390     } //forever
       
  1391 }
       
  1392 
       
  1393 /*!
       
  1394  \internal
       
  1395  starts a transition of the main container with a decoy snapshot.
  1136  starts a transition of the main container with a decoy snapshot.
  1396  */
  1137  */
  1397 void MpCollectionView::startContainerTransition( TCollectionContext contextFrom, TCollectionContext contextTo )
  1138 void MpCollectionView::startContainerTransition( TCollectionContext contextFrom, TCollectionContext contextTo )
  1398 {
  1139 {
  1399     if (contextFrom == contextTo) {
  1140     if (contextFrom == contextTo) {
  1406     mSnapshot->capture( mWindow, mMainContainer );
  1147     mSnapshot->capture( mWindow, mMainContainer );
  1407     mWindow->scene()->addItem( mSnapshot );
  1148     mWindow->scene()->addItem( mSnapshot );
  1408 
  1149 
  1409 
  1150 
  1410     if ( ( contextFrom == ECollectionContextAlbums && contextTo == ECollectionContextAlbumSongs ) ||
  1151     if ( ( contextFrom == ECollectionContextAlbums && contextTo == ECollectionContextAlbumSongs ) ||
       
  1152             ( contextFrom == ECollectionContextArtists && contextTo == ECollectionContextArtistAlbums ) ||
       
  1153             ( contextFrom == ECollectionContextArtistAlbums && contextTo == ECollectionContextAlbumSongs ) ||
       
  1154             ( contextFrom == ECollectionContextArtistAlbums && contextTo == ECollectionContextArtistSongs ) ||
  1411             ( contextFrom == ECollectionContextPlaylists && contextTo == ECollectionContextPlaylistSongs ) ||
  1155             ( contextFrom == ECollectionContextPlaylists && contextTo == ECollectionContextPlaylistSongs ) ||
  1412             ( contextFrom == ECollectionContextGenres && contextTo == ECollectionContextGenreSongs ) ) {
  1156             ( contextFrom == ECollectionContextGenres && contextTo == ECollectionContextGenreSongs ) ) {
  1413         HbEffect::start( mSnapshot,
  1157         HbEffect::start( mSnapshot,
  1414                 QString( "container" ),
  1158                 QString( "container" ),
  1415                 QString( "slide_out_to_left" ),
  1159                 QString( "slide_out_to_left" ),
  1423                 this,
  1167                 this,
  1424                 "containerTransitionComplete",
  1168                 "containerTransitionComplete",
  1425                 QString( "mainContainer_effect") );
  1169                 QString( "mainContainer_effect") );
  1426     }
  1170     }
  1427     else if( ( contextFrom == ECollectionContextAlbumSongs && contextTo == ECollectionContextAlbums ) ||
  1171     else if( ( contextFrom == ECollectionContextAlbumSongs && contextTo == ECollectionContextAlbums ) ||
       
  1172             ( contextFrom == ECollectionContextArtistAlbums && contextTo == ECollectionContextArtists ) ||
       
  1173             ( contextFrom == ECollectionContextAlbumSongs && contextTo == ECollectionContextArtistAlbums ) ||
       
  1174             ( contextFrom == ECollectionContextArtistSongs && contextTo == ECollectionContextArtistAlbums ) ||
  1428             ( contextFrom == ECollectionContextPlaylistSongs && contextTo == ECollectionContextPlaylists ) ||
  1175             ( contextFrom == ECollectionContextPlaylistSongs && contextTo == ECollectionContextPlaylists ) ||
  1429             ( contextFrom == ECollectionContextGenreSongs && contextTo == ECollectionContextGenres ) ) {
  1176             ( contextFrom == ECollectionContextGenreSongs && contextTo == ECollectionContextGenres ) ) {
  1430         HbEffect::start( mSnapshot,
  1177         HbEffect::start( mSnapshot,
  1431                 QString( "container" ),
  1178                 QString( "container" ),
  1432                 QString( "slide_out_to_right" ),
  1179                 QString( "slide_out_to_right" ),
  1459 
  1206 
  1460 }
  1207 }
  1461 
  1208 
  1462 /*!
  1209 /*!
  1463  \internal
  1210  \internal
  1464  request a delete operation always it has been confirmed.
  1211  Closes any active dialog or menu.
  1465  */
  1212  */
  1466 void MpCollectionView::requestDelete( QList<int> &selection )
  1213 void MpCollectionView::cancelOngoingOperation()
  1467 {
  1214 {
  1468     bool confirmation( false );
  1215     if ( mActivated ) {
  1469     // Todo: Use HbMessageBox::question when time-out removed from it
  1216         mMpPopupHandler->cancelOngoingPopup();
  1470     HbMessageBox dialog( HbMessageBox::MessageTypeQuestion );
  1217         menu()->close();
  1471 
  1218     }
  1472     QString message;
  1219 }
  1473     HbAction *action = 0;
  1220 
  1474 
       
  1475     switch ( mCollectionContext ) {
       
  1476         case ECollectionContextAllSongs:
       
  1477         case ECollectionContextAlbumSongs:
       
  1478             message = hbTrId( "txt_mus_delete_song" );
       
  1479             dialog.setText( message );
       
  1480             dialog.setTimeout( HbPopup::NoTimeout );
       
  1481             setOutstandingPopup( &dialog );
       
  1482             action = mActivated ? dialog.exec() : 0;
       
  1483             setOutstandingPopup( 0 );
       
  1484             if ( action && action == dialog.primaryAction() ) {
       
  1485                 confirmation = true;
       
  1486             }
       
  1487             break;
       
  1488         case ECollectionContextAlbums:
       
  1489             message = hbTrId( "txt_mus_delete_album" );
       
  1490             dialog.setText( message );
       
  1491             dialog.setTimeout( HbPopup::NoTimeout );
       
  1492             setOutstandingPopup( &dialog );
       
  1493             action = mActivated ? dialog.exec() : 0;
       
  1494             setOutstandingPopup( 0 );
       
  1495             if ( action && action == dialog.primaryAction() ) {
       
  1496                 confirmation = true;
       
  1497             }
       
  1498             break;
       
  1499         case ECollectionContextPlaylists:
       
  1500             message = hbTrId( "txt_mus_delete_playlist" );
       
  1501             dialog.setText( message );
       
  1502             dialog.setTimeout( HbPopup::NoTimeout );
       
  1503             setOutstandingPopup( &dialog );
       
  1504             action = mActivated ? dialog.exec() : 0;
       
  1505             setOutstandingPopup( 0 );
       
  1506             if ( action && action == dialog.primaryAction() ) {
       
  1507                 confirmation = true;
       
  1508             }
       
  1509             break;
       
  1510         case ECollectionContextPlaylistSongs:
       
  1511         case ECollectionContextGenres:
       
  1512         case ECollectionContextGenreSongs:
       
  1513             confirmation = true;
       
  1514             break;
       
  1515         case ECollectionContextUnknown:
       
  1516         default:
       
  1517             // We shouldn't be here
       
  1518             TX_LOG_ARGS( "Invalid Collection Context:" << mCollectionContext );
       
  1519             break;
       
  1520     }
       
  1521 
       
  1522     if ( confirmation ) {
       
  1523         mMpEngine->deleteSongs( selection );
       
  1524     }
       
  1525 }
       
  1526 
       
  1527 /*!
       
  1528  \internal
       
  1529  Returns a list of itmes selected.
       
  1530  */
       
  1531 QModelIndexList MpCollectionView::getModelIndexes( const QString &label, QAbstractItemModel* model, bool &ok )
       
  1532 {
       
  1533     QModelIndexList result;
       
  1534 
       
  1535     if ( !mActivated ) {
       
  1536        ok = false;
       
  1537        return result;
       
  1538     }
       
  1539 
       
  1540     HbListDialog *dlg = new HbListDialog();
       
  1541     dlg->setHeadingWidget( new HbLabel( label ) );
       
  1542     dlg->setSelectionMode( HbAbstractItemView::MultiSelection );
       
  1543     dlg->setModel( model );
       
  1544     setOutstandingPopup( dlg );
       
  1545     HbAction* action = mActivated ? dlg->exec() : 0;
       
  1546     setOutstandingPopup( 0 );
       
  1547     if( action == dlg->primaryAction() ){ //OK was pressed
       
  1548         ok = true;
       
  1549         result = dlg->selectedModelIndexes();
       
  1550     }
       
  1551     else{ //Cancel was pressed or dialog was closed or never executed.
       
  1552         ok = false;
       
  1553     }
       
  1554     dlg->setModel( 0 );
       
  1555     delete dlg;
       
  1556     return result;
       
  1557 }
       
  1558 
       
  1559 /*!
       
  1560  \internal
       
  1561  Returns a string from user input.
       
  1562  */
       
  1563 QString MpCollectionView::getText( const QString &label,const QString &text,
       
  1564                                 bool &ok )
       
  1565 {
       
  1566     
       
  1567     QString result;
       
  1568     
       
  1569     if ( !mActivated ) {
       
  1570        ok = false;
       
  1571        return result;
       
  1572     }
       
  1573     
       
  1574     HbInputDialog *dlg = new HbInputDialog();
       
  1575     dlg->setPromptText( label );
       
  1576     dlg->setInputMode( HbInputDialog::TextInput );
       
  1577     dlg->setValue( text );
       
  1578     setOutstandingPopup( dlg ); 
       
  1579     HbAction* action = mActivated ? dlg->exec() : 0;
       
  1580     setOutstandingPopup( 0 );
       
  1581     if( action == dlg->primaryAction() ) { //OK was pressed
       
  1582         ok = true;
       
  1583         result = dlg->value().toString();
       
  1584     } else {  //Cancel was pressed or dialog was closed or never executed.
       
  1585         ok = false;
       
  1586     }
       
  1587     delete dlg;
       
  1588     return result;  
       
  1589 }
       
  1590 
       
  1591 /*!
       
  1592  \internal
       
  1593  sets \a popup as the current outstanding popup and cancels any otstanding popup.
       
  1594  */
       
  1595 void MpCollectionView::setOutstandingPopup( HbPopup *popup )
       
  1596 {
       
  1597     if ( mOutstandingPopup ) {
       
  1598         mOutstandingPopup->close();
       
  1599     } 
       
  1600     mOutstandingPopup = popup;
       
  1601 }
       
  1602 
       
  1603 /*!
       
  1604  \internal
       
  1605  sets \a newPlaylistName with imput name from the user, uses \a playlists to 
       
  1606  generate a suggested playlist name, retrns true if the user confirmed the query.
       
  1607  */
       
  1608 bool MpCollectionView::queryNewPlaylistName(QString &newPlaylistName , const QStringList &playlists ) 
       
  1609 {
       
  1610     bool ret= false;
       
  1611     if (!mActivated) {
       
  1612        return ret;
       
  1613     }
       
  1614     int i = 0;
       
  1615     for ( ;
       
  1616          playlists.contains( hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i ) ) ;
       
  1617          i++ ) {};
       
  1618     QString suggestedPlaylistName = hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i );
       
  1619     QString suggestedText;
       
  1620     bool ok = false;
       
  1621     suggestedText = getText( hbTrId("txt_mus_dialog_enter_name" ), suggestedPlaylistName, ok);
       
  1622     if ( ok ) {
       
  1623         newPlaylistName = suggestedText;
       
  1624         ret = true;
       
  1625     }
       
  1626     return ret;
       
  1627 }
       
  1628