mpviewplugins/mpcollectionviewplugin/src/mpcollectionpopuphandler.cpp
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Music Player collection popup handler.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <hbaction.h>
       
    20 #include <hbmenu.h>
       
    21 #include <hbmessagebox.h>
       
    22 #include <hbprogressdialog.h>
       
    23 #include <hbselectiondialog.h>
       
    24 #include <hbinputdialog.h>
       
    25 #include <hblabel.h>
       
    26 #include <hblistview.h>
       
    27 #include <hbscrollbar.h>
       
    28 
       
    29 #include "mpenginefactory.h"
       
    30 #include "mpcollectionview.h"
       
    31 #include "mpmpxcollectiondata.h"
       
    32 #include "mpcollectiondatamodel.h"
       
    33 #include "mpcollectiontbonelistdatamodel.h"
       
    34 #include "mpcollectionpopuphandler.h"
       
    35 #include "mptrace.h"
       
    36 
       
    37 const int KNullIndex = -1;
       
    38 const int KSongsToDisplayProgressDlg = 100;
       
    39 
       
    40 // Popups launched by this class
       
    41 const QString KContextMenu = QString( "ContextMenu" );
       
    42 const QString KProgressDialog = QString( "ProgressDialog" );
       
    43 const QString KAddToPlaylistSelectionDialog = QString( "AddToPlaylistSelectionDialog" );
       
    44 const QString KInputTextDialog = QString( "InputTextDialog" );
       
    45 const QString KGetModelIndexesListDialog = QString( "GetModelIndexesListDialog" );
       
    46 const QString KArrangeSongsDialog = QString( "ArrangeSongsDialog" );
       
    47 const QString KRequestDeleteMessageBox = QString( "RequestDeleteMessageBox" );
       
    48 
       
    49 // Popups Actions
       
    50 const QString KOk = QString( "Ok" );
       
    51 const QString KCancel = QString( "Cancel" );
       
    52 const QString KNew = QString( "New" );
       
    53 const QString KOpen = QString( "Open" );
       
    54 const QString KAdd = QString( "Add" );
       
    55 const QString KDelete = QString( "Delete" );
       
    56 const QString KRenamePlayList = QString( "RenamePlayList" );
       
    57 const QString KDetails = QString( "Details" );
       
    58 
       
    59 
       
    60 //------------------------------------------------------------------
       
    61 //    MpPopupHandlerPermanentData
       
    62 //------------------------------------------------------------------
       
    63 
       
    64 /*!
       
    65     \class MpPopupHandlerPermanentData. This class is used by MpCollectionPopupHandler to
       
    66     store permanent data needed during asynchronous popups operation.
       
    67 
       
    68 */
       
    69 
       
    70 class MpPopupHandlerPermanentData : public QObject
       
    71 {
       
    72     public:
       
    73         MpPopupHandlerPermanentData( QObject *parent=0 );
       
    74         virtual ~MpPopupHandlerPermanentData();
       
    75         void clear();
       
    76     public:
       
    77         MpMpxCollectionData         *mIsolatedCollectionData;        // Not own
       
    78         QAbstractItemModel          *mAbstractItemModel;             // Own
       
    79         QList<int>                  mSelectedItems;
       
    80         QString                     mOriginalName;
       
    81         int                         mContextMenuIndex;
       
    82 };
       
    83 
       
    84 /*!
       
    85  Constructs the popup handler permanent data.
       
    86  */
       
    87 MpPopupHandlerPermanentData::MpPopupHandlerPermanentData( QObject *parent )
       
    88     : QObject( parent ),
       
    89       mIsolatedCollectionData( 0 ),
       
    90       mAbstractItemModel( 0 ),
       
    91       mContextMenuIndex( KNullIndex )
       
    92 {
       
    93       TX_ENTRY
       
    94       mSelectedItems.clear();
       
    95       mOriginalName.clear();
       
    96       TX_EXIT
       
    97 }
       
    98 
       
    99 /*!
       
   100  Destructs the popup handler permanent data.
       
   101  */
       
   102 MpPopupHandlerPermanentData::~MpPopupHandlerPermanentData()
       
   103 {
       
   104     TX_ENTRY
       
   105     clear();
       
   106     TX_EXIT
       
   107 }
       
   108 
       
   109 /*!
       
   110  \internal
       
   111   Clears all permanent data. 
       
   112  */
       
   113 void MpPopupHandlerPermanentData::clear()
       
   114 {
       
   115     TX_ENTRY
       
   116     mSelectedItems.clear();
       
   117     mOriginalName.clear();
       
   118     mContextMenuIndex = KNullIndex;
       
   119     if ( mIsolatedCollectionData ) {
       
   120         MpEngineFactory::sharedEngine()->releaseIsolatedCollection();
       
   121         mIsolatedCollectionData = 0;
       
   122     }
       
   123     if ( mAbstractItemModel ) {
       
   124         delete mAbstractItemModel;
       
   125         mAbstractItemModel = 0;
       
   126     }
       
   127     //clearing any child Objects.
       
   128     foreach (QObject* child, children()) {
       
   129         child->deleteLater();
       
   130     }
       
   131     TX_EXIT
       
   132 }
       
   133 
       
   134 
       
   135 //------------------------------------------------------------------
       
   136 //    MpCollectionPopupHandler
       
   137 //------------------------------------------------------------------
       
   138 
       
   139 /*!
       
   140     \class MpCollectionPopupHandler
       
   141     \brief Music Player collection popup handler.
       
   142 
       
   143     This class controls the asynchronous operation of all dialogs 
       
   144     used by collection view.
       
   145 */
       
   146 
       
   147 /*!
       
   148  Constructs the collection popup handler.
       
   149  */
       
   150 MpCollectionPopupHandler::MpCollectionPopupHandler( MpCollectionView *parent )
       
   151     : QObject( parent ),
       
   152       mView( parent ),
       
   153       mOutstandingPopup( 0 ),
       
   154       mMpEngine( 0 ),
       
   155       mPermanentData( 0 ),
       
   156       mExternalEventsConnected( false )
       
   157 {
       
   158     TX_ENTRY
       
   159     mMpEngine = MpEngineFactory::sharedEngine();
       
   160     mPermanentData = new MpPopupHandlerPermanentData( this );
       
   161     TX_EXIT
       
   162 }
       
   163 
       
   164 /*!
       
   165  Destructs the collection popup handler.
       
   166  */
       
   167 MpCollectionPopupHandler::~MpCollectionPopupHandler()
       
   168 {
       
   169     TX_ENTRY
       
   170     delete mOutstandingPopup;
       
   171     TX_EXIT
       
   172 }
       
   173 
       
   174 /*!
       
   175  Default view context menu.
       
   176  */
       
   177 void MpCollectionPopupHandler::openDefaultViewContextMenu( int index, const QPointF &coords )
       
   178 {
       
   179     TX_ENTRY
       
   180 
       
   181     if ( mView->isActivated() ) {
       
   182 
       
   183         HbMenu *contextMenu = 0;
       
   184         HbAction *action;
       
   185         bool usbBlocked = mMpEngine->verifyUsbBlocking();
       
   186 
       
   187         switch ( mMpEngine->collectionData()->context() ) {
       
   188             case ECollectionContextAllSongs:
       
   189             case ECollectionContextArtistAllSongs:
       
   190             case ECollectionContextArtistAlbumsTBone:
       
   191             case ECollectionContextAlbumsTBone:
       
   192                 contextMenu = new HbMenu();
       
   193                 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
       
   194                 action->setObjectName( KOpen );
       
   195                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
       
   196                 action->setObjectName( KAdd );
       
   197                 action->setEnabled( !usbBlocked );
       
   198                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   199                 action->setObjectName( KDelete );
       
   200                 action->setEnabled( !usbBlocked );
       
   201                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_view_details" ) );
       
   202                 action->setObjectName( KDetails );
       
   203                 break;
       
   204             case ECollectionContextAlbums:
       
   205             case ECollectionContextArtists:
       
   206             case ECollectionContextArtistAlbums:
       
   207                 contextMenu = new HbMenu();
       
   208                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
       
   209                 action->setObjectName( KOpen );
       
   210                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
       
   211                 action->setObjectName( KAdd );
       
   212                 action->setEnabled( !usbBlocked );
       
   213                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   214                 action->setObjectName( KDelete );
       
   215                 action->setEnabled( !usbBlocked );
       
   216                 break;
       
   217             case ECollectionContextPlaylists:
       
   218                 contextMenu = new HbMenu();
       
   219                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
       
   220                 action->setObjectName( KOpen );
       
   221                 if ( !mMpEngine->collectionData()->isAutoPlaylist( index ) ) {
       
   222                     action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   223                     action->setObjectName(KDelete);
       
   224                     action->setEnabled( !usbBlocked );
       
   225                     action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
       
   226                     action->setObjectName( KRenamePlayList );
       
   227                     action->setEnabled( !usbBlocked );
       
   228                 }
       
   229                 break;
       
   230             case ECollectionContextPlaylistSongs:
       
   231                 contextMenu = new HbMenu();
       
   232                 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
       
   233                 action->setObjectName( KOpen );
       
   234                 if ( !mMpEngine->collectionData()->isAutoPlaylist() ) {
       
   235                     action = contextMenu->addAction( hbTrId( "txt_common_menu_remove" ) );
       
   236                     action->setObjectName( KDelete );
       
   237                     action->setEnabled( !usbBlocked );
       
   238                 }
       
   239                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_view_details" ) );
       
   240                 action->setObjectName( KDetails );
       
   241                 break;
       
   242             default:
       
   243                 break;
       
   244         }
       
   245 
       
   246         if ( contextMenu ) {
       
   247             mPermanentData->mContextMenuIndex = index;
       
   248             contextMenu->setPreferredPos( coords );
       
   249             contextMenu->setObjectName( KContextMenu );
       
   250             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
       
   251             setOutstandingPopup( contextMenu );
       
   252             contextMenu->open( this, SLOT( defaultContextMenuOptionSelected( HbAction* ) ) );
       
   253         }
       
   254     }
       
   255 
       
   256     TX_EXIT
       
   257 }
       
   258 
       
   259 /*!
       
   260  Fetch view context menu
       
   261  */
       
   262 void MpCollectionPopupHandler::openFetchViewContextMenu( int index, const QPointF &coords )
       
   263 {
       
   264     TX_ENTRY_ARGS( "index=" << index );
       
   265 
       
   266     if ( mView->isActivated() ) {
       
   267 
       
   268         HbAction *action;
       
   269         HbMenu *contextMenu = 0;
       
   270 
       
   271         switch ( mMpEngine->collectionData()->context() ) {
       
   272             case ECollectionContextAllSongs:
       
   273             case ECollectionContextArtistAlbumsTBone:
       
   274             case ECollectionContextArtistAllSongs:
       
   275             case ECollectionContextAlbumsTBone:
       
   276             case ECollectionContextPlaylistSongs:
       
   277                 contextMenu = new HbMenu();
       
   278                 action = contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
       
   279                 action->setEnabled( !mMpEngine->verifyUsbBlocking() );
       
   280                 break;
       
   281             default:
       
   282                 break;
       
   283         }
       
   284 
       
   285         if ( contextMenu ) {
       
   286             mPermanentData->mContextMenuIndex = index;
       
   287             contextMenu->setPreferredPos( coords );
       
   288             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
       
   289             contextMenu->setObjectName( KContextMenu );
       
   290             setOutstandingPopup( contextMenu );
       
   291             contextMenu->open( this, SLOT( fetcherContextMenuOptionSelected( HbAction* ) ) );
       
   292         }
       
   293     }
       
   294 
       
   295     TX_EXIT
       
   296 }
       
   297 
       
   298 /*!
       
   299  Request a string to rename the playlist container.
       
   300  */
       
   301 void MpCollectionPopupHandler::openRenamePlaylistContainerDialog( const QString &currentName )
       
   302 {
       
   303     TX_ENTRY_ARGS( "Current name=" << currentName );
       
   304     mPermanentData->mOriginalName = currentName;
       
   305     getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName,
       
   306              SLOT( handleRenamePlaylistContainer( HbAction* ) ) );
       
   307     TX_EXIT
       
   308 }
       
   309 
       
   310 /*!
       
   311  Request a string to rename the playlist item.
       
   312  */
       
   313 void MpCollectionPopupHandler::openRenamePlaylistItemDialog( const QString &currentName )
       
   314 {
       
   315     TX_ENTRY_ARGS( "Current name=" << currentName );
       
   316     mPermanentData->mOriginalName = currentName;
       
   317     getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName,
       
   318              SLOT( handleRenamePlaylistItem( HbAction* ) ) );
       
   319     TX_EXIT
       
   320 }
       
   321 
       
   322 /*!
       
   323  Request to select songs to add to the playlist
       
   324  */
       
   325 void MpCollectionPopupHandler::openAddSongsToPlaylist( QAbstractItemModel* model )
       
   326 {
       
   327     TX_ENTRY
       
   328     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
       
   329                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
       
   330     TX_EXIT
       
   331 }
       
   332 
       
   333 /*!
       
   334  Request to select songs to add to the playlist from TBone
       
   335  */
       
   336 void MpCollectionPopupHandler::openAddSongsToPlaylistFromTBone( )
       
   337 {
       
   338     TX_ENTRY
       
   339     MpCollectionTBoneListDataModel *model;
       
   340     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
       
   341     //this item will be deleted when clearing permanent data.
       
   342     model->setParent(mPermanentData);
       
   343     model->refreshModel();
       
   344     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
       
   345                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
       
   346     TX_EXIT
       
   347 }
       
   348 
       
   349 /*!
       
   350  Request to select songs to be deleted
       
   351  */
       
   352 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
       
   353 {
       
   354     TX_ENTRY
       
   355     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model, 
       
   356                      SLOT( handleDeleteSongs( HbAction* ) ) );
       
   357     TX_EXIT
       
   358 }
       
   359 
       
   360 /*!
       
   361  Request to select songs to be added to the current play list
       
   362  */
       
   363 void MpCollectionPopupHandler::openAddToCurrentPlaylist( MpMpxCollectionData* collectionData )
       
   364 {
       
   365     TX_ENTRY
       
   366     mPermanentData->mIsolatedCollectionData = collectionData;
       
   367     MpCollectionDataModel *collectionDataModel;
       
   368     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   369     collectionDataModel->refreshModel();
       
   370     mPermanentData->mAbstractItemModel = collectionDataModel;
       
   371 
       
   372     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), collectionDataModel, 
       
   373                      SLOT( handleAddToCurrentPlaylist( HbAction* ) ) );
       
   374     TX_EXIT
       
   375 }
       
   376 
       
   377 /*!
       
   378  Request to create a new play list and then add songs to it.
       
   379  */
       
   380 void MpCollectionPopupHandler::openCreateNewPlaylist( MpMpxCollectionData* collectionData )
       
   381 {
       
   382     TX_ENTRY
       
   383     mPermanentData->mIsolatedCollectionData = collectionData;
       
   384 
       
   385     MpCollectionDataModel *collectionDataModel;
       
   386     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   387     collectionDataModel->refreshModel();
       
   388     mPermanentData->mAbstractItemModel = collectionDataModel;
       
   389 
       
   390     QStringList playlists;
       
   391     mMpEngine->findPlaylists( playlists );
       
   392     queryNewPlaylistName( playlists, SLOT( handleCreateNewPlaylistGetTextFinished( HbAction* ) ) );
       
   393     TX_EXIT
       
   394 }
       
   395 
       
   396 /*!
       
   397  Request to reorder songs
       
   398  */
       
   399 void MpCollectionPopupHandler::openArrangeSongs( )
       
   400 {
       
   401     TX_ENTRY
       
   402     launchArrangeSongsDialog();
       
   403     TX_EXIT
       
   404 }
       
   405 
       
   406 /*!
       
   407  Closes any active popup
       
   408  */
       
   409 void MpCollectionPopupHandler::cancelOngoingPopup( bool onlyContextMenu )
       
   410 {
       
   411     TX_ENTRY
       
   412     if ( mOutstandingPopup ) {
       
   413         if ( onlyContextMenu ) {
       
   414             if ( mOutstandingPopup->objectName() == KContextMenu ) {
       
   415                 mOutstandingPopup->close();
       
   416                 mPermanentData->clear();
       
   417             }
       
   418         }
       
   419         else {
       
   420             mOutstandingPopup->close();
       
   421             //Delete/Clear permanent data until current popup gets deleted
       
   422             mPermanentData->setParent( mOutstandingPopup );
       
   423             //Generate new permanent data for future popups
       
   424             mPermanentData = new MpPopupHandlerPermanentData( this );
       
   425         }
       
   426     }
       
   427     else {
       
   428         mPermanentData->clear();
       
   429     }
       
   430     TX_EXIT
       
   431 }
       
   432 
       
   433 /*!
       
   434  Slot to be called when an option has been selected from default context menu.
       
   435  */
       
   436 void MpCollectionPopupHandler::defaultContextMenuOptionSelected( HbAction *selectedAction )
       
   437 {
       
   438     TX_ENTRY
       
   439     if ( selectedAction ) {
       
   440         QString objectName = selectedAction->objectName();
       
   441         QList<int> selection;
       
   442         selection.append( mPermanentData->mContextMenuIndex );
       
   443         if ( objectName == KOpen ) {
       
   444             mView->openItem( mPermanentData->mContextMenuIndex );
       
   445         }
       
   446         if ( objectName == KAdd ) {
       
   447             launchAddToPlaylistDialog( selection );
       
   448         }
       
   449         else if ( objectName == KDelete ) {
       
   450             requestDelete( selection );
       
   451         }
       
   452         else if ( objectName == KRenamePlayList ) {
       
   453             QString currentName;
       
   454             currentName = mMpEngine->collectionData()->itemData( 
       
   455                     mPermanentData->mContextMenuIndex, MpMpxCollectionData::Title );
       
   456             openRenamePlaylistItemDialog( currentName );
       
   457         }
       
   458         else if ( objectName == KDetails ) {
       
   459             mView->showItemDetails( mPermanentData->mContextMenuIndex );
       
   460         }
       
   461     }
       
   462     TX_EXIT
       
   463 }
       
   464 
       
   465 /*!
       
   466  Slot to be called when play option has been selected from fetcher context menu.
       
   467  */
       
   468 void MpCollectionPopupHandler::fetcherContextMenuOptionSelected( HbAction *selectedAction )
       
   469 {
       
   470     TX_ENTRY
       
   471     if ( selectedAction ) {
       
   472         // Start the playback process. View will switch to playbackview.
       
   473         mMpEngine->previewItem( mPermanentData->mContextMenuIndex );
       
   474     }        
       
   475     TX_EXIT
       
   476 }
       
   477 
       
   478 /*!
       
   479  Slot to be called when AddToPlaylist dialog has finished
       
   480  */
       
   481 void MpCollectionPopupHandler::handleAddToPlaylistDialogFinished( HbAction *selectedAction )
       
   482 {
       
   483     TX_ENTRY
       
   484     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
       
   485     clearOutstandingPopup( dialog );
       
   486     bool operationCompleted( true );
       
   487 
       
   488     if ( selectedAction ) {
       
   489         QString objectName = selectedAction->objectName();
       
   490         if ( objectName == KNew ) {
       
   491             QStringList playlists;
       
   492             mMpEngine->findPlaylists( playlists );
       
   493             queryNewPlaylistName( playlists, SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
       
   494             operationCompleted = false;
       
   495         }
       
   496     } 
       
   497     else if ( dialog->selectedItems().count() ) {//this only works for SingleSelection
       
   498         // User selected existing playlist.
       
   499         mMpEngine->saveToPlaylist( dialog->selectedItems().at( 0 ).toInt(), mPermanentData->mSelectedItems );
       
   500     }
       
   501     
       
   502     if ( operationCompleted ) {
       
   503         mPermanentData->clear();
       
   504     }
       
   505     TX_EXIT
       
   506 }
       
   507 
       
   508 /*!
       
   509  Slot to be called when input dialog (getText) has finished, comming from AddToPlayList.
       
   510  */
       
   511 void MpCollectionPopupHandler::handleAddToPlaylistGetTextFinished( HbAction *selectedAction )
       
   512 {
       
   513     TX_ENTRY
       
   514     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
       
   515     clearOutstandingPopup( dialog );
       
   516     bool operationCompleted( true );
       
   517 
       
   518     if ( selectedAction ) {
       
   519         QString objectName = selectedAction->objectName();
       
   520         if ( objectName == KOk ) {
       
   521             QString newPlaylistName = dialog->value().toString();
       
   522             if ( newPlaylistName.length() ) {
       
   523                 //Create new playlist with given name
       
   524                 mMpEngine->createPlaylist( newPlaylistName, mPermanentData->mSelectedItems );
       
   525             }
       
   526             else {
       
   527                 //No valid name, prompt for one again.
       
   528                 getText( hbTrId( "txt_mus_dialog_enter_name" ), newPlaylistName,
       
   529                          SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
       
   530                 operationCompleted = false;
       
   531             }
       
   532         }
       
   533         else {
       
   534             // user decided to not provide a new name, go back to playlist list selection
       
   535             QStringList playlists;
       
   536             mMpEngine->findPlaylists( playlists );
       
   537             if ( playlists.count() ) {
       
   538                 //are saved playlists, back to playlist selection dialog
       
   539                 launchAddToPlaylistDialog( mPermanentData->mSelectedItems );
       
   540                 operationCompleted = false;
       
   541             }
       
   542         }
       
   543     }
       
   544 
       
   545     if ( operationCompleted ) {
       
   546         mPermanentData->clear();
       
   547     }
       
   548     TX_EXIT
       
   549 }
       
   550 
       
   551 /*!
       
   552  Slot to be called when input dialog (getText) has finished, comming from RenamePlaylistContainer.
       
   553  */
       
   554 void MpCollectionPopupHandler::handleRenamePlaylistContainer( HbAction *selectedAction )
       
   555 {
       
   556     TX_ENTRY
       
   557     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
       
   558     clearOutstandingPopup( dialog );
       
   559     bool operationCompleted( true );
       
   560 
       
   561     if ( selectedAction ) {
       
   562         QString objectName = selectedAction->objectName();
       
   563         if ( objectName == KOk ) {
       
   564             QString newPlaylistName = dialog->value().toString();
       
   565             if ( newPlaylistName.length() ) {
       
   566                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
       
   567                     mMpEngine->renamePlaylist( newPlaylistName );
       
   568                 }
       
   569             }
       
   570             else {
       
   571                 //No valid name, prompt for one again.
       
   572                 getText( hbTrId( "txt_mus_dialog_enter_name" ), newPlaylistName,
       
   573                          SLOT( handleRenamePlaylistContainer( HbAction* ) ) );
       
   574                 operationCompleted = false;
       
   575             }
       
   576         }
       
   577     }
       
   578 
       
   579     if ( operationCompleted ) {
       
   580         mPermanentData->clear();
       
   581     }
       
   582     TX_EXIT
       
   583 }
       
   584 
       
   585 /*!
       
   586  Slot to be called when input dialog (getText) has finished, comming from RenamePlaylist ContextMenu.
       
   587  */
       
   588 void MpCollectionPopupHandler::handleRenamePlaylistItem( HbAction *selectedAction )
       
   589 {
       
   590     TX_ENTRY
       
   591     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
       
   592     clearOutstandingPopup( dialog );
       
   593     bool operationCompleted( true );
       
   594 
       
   595     if ( selectedAction ) {
       
   596         QString objectName = selectedAction->objectName();
       
   597         if ( objectName == KOk ) {
       
   598             QString newPlaylistName = dialog->value().toString();
       
   599             if ( newPlaylistName.length() ) {
       
   600                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
       
   601                     mMpEngine->renamePlaylist( newPlaylistName, mPermanentData->mContextMenuIndex );
       
   602                 }
       
   603             }
       
   604             else {
       
   605                 //No valid name, prompt for one again.
       
   606                 getText( hbTrId( "txt_mus_dialog_enter_name" ), newPlaylistName,
       
   607                          SLOT( handleRenamePlaylistItem( HbAction* ) ) );
       
   608                 operationCompleted = false;
       
   609             }
       
   610         }
       
   611     }
       
   612 
       
   613     if ( operationCompleted ) {
       
   614         mPermanentData->clear();
       
   615     }
       
   616     TX_EXIT
       
   617 }
       
   618 
       
   619 /*!
       
   620  Slot to be called when select songs dialog (getModelIndexes) has finished, coming from AddSongsToPlayList.
       
   621  */
       
   622 void MpCollectionPopupHandler::handleAddSongsToPlayList( HbAction *selectedAction )
       
   623 {
       
   624     TX_ENTRY
       
   625     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
       
   626     clearOutstandingPopup( dialog );
       
   627 
       
   628     if ( selectedAction ) {
       
   629         QString objectName = selectedAction->objectName();
       
   630         if ( objectName == KOk ) {
       
   631             QModelIndexList selectedModelIndexes;
       
   632             selectedModelIndexes = dialog->selectedModelIndexes();
       
   633             if ( selectedModelIndexes.count() ) {
       
   634                 QList<int> selection;
       
   635                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
       
   636                     selection.append( selectedModelIndexes.at( i ).row() );
       
   637                 }
       
   638                 launchAddToPlaylistDialog( selection );
       
   639             }
       
   640         }
       
   641         else {
       
   642             mPermanentData->clear();
       
   643         }
       
   644     }
       
   645 
       
   646     //Dialog won't use CollectionView main model any more, return it to its original layout.
       
   647     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
       
   648     if ( mpModel ) {
       
   649         //setLayout() only applies for MpCollectionDataModel where we need to 
       
   650         //decide which layout to use for the secondary text.
       
   651         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
   652         mpModel->setLayout( ECollectionListView );
       
   653     }
       
   654     TX_EXIT
       
   655 }
       
   656 
       
   657 /*!
       
   658  Slot to be called when select songs dialog (getModelIndexes) has finished, coming from DeleteSongs.
       
   659  */
       
   660 void MpCollectionPopupHandler::handleDeleteSongs( HbAction *selectedAction )
       
   661 {
       
   662     TX_ENTRY
       
   663     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
       
   664     clearOutstandingPopup( dialog );
       
   665 
       
   666     if ( selectedAction ) {
       
   667         QString objectName = selectedAction->objectName();
       
   668         if ( objectName == KOk ) {
       
   669             QModelIndexList selectedModelIndexes;
       
   670             selectedModelIndexes = dialog->selectedModelIndexes();
       
   671             if ( selectedModelIndexes.count() ) {
       
   672                 QList<int> selection;
       
   673                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
       
   674                     selection.append( selectedModelIndexes.at( i ).row() );
       
   675                 }
       
   676                 requestDelete( selection );
       
   677             }
       
   678         }
       
   679     }
       
   680 
       
   681     //Dialog won't use CollectionView main model any more, return it to its original layout.
       
   682     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
       
   683     if ( mpModel ) {
       
   684         //setLayout() only applies for MpCollectionDataModel where we need to 
       
   685         //decide which layout to use for the secondary text.
       
   686         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
   687         mpModel->setLayout( ECollectionListView );
       
   688     }
       
   689     TX_EXIT
       
   690 }
       
   691 
       
   692 /*!
       
   693  Slot to be called when select songs dialog (getModelIndexes) has finished, coming from AddToCurrentPlaylist.
       
   694  */
       
   695 void MpCollectionPopupHandler::handleAddToCurrentPlaylist( HbAction *selectedAction )
       
   696 {
       
   697     TX_ENTRY
       
   698     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
       
   699     clearOutstandingPopup( dialog );
       
   700 
       
   701     if ( selectedAction ) {
       
   702         QString objectName = selectedAction->objectName();
       
   703         if ( objectName == KOk ) {
       
   704             QModelIndexList selectedModelIndexes;
       
   705             selectedModelIndexes = dialog->selectedModelIndexes();
       
   706             if ( selectedModelIndexes.count() ) {
       
   707                 QList<int> selection;
       
   708                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
       
   709                     selection.append( selectedModelIndexes.at( i ).row() );
       
   710                 }
       
   711                 mMpEngine->saveToCurrentPlaylist( selection,
       
   712                         mPermanentData->mIsolatedCollectionData );
       
   713             }
       
   714         }
       
   715     }
       
   716 
       
   717     //Dialog is using an isolated model which will be deleted, no need to change its layout.
       
   718     mPermanentData->clear();
       
   719 
       
   720     TX_EXIT
       
   721 }
       
   722 
       
   723 /*!
       
   724  Slot to be called when the input dialog (getText) has finished, comming from CreateNewPlaylist.
       
   725  */
       
   726 void MpCollectionPopupHandler::handleCreateNewPlaylistGetTextFinished( HbAction *selectedAction )
       
   727 {
       
   728     TX_ENTRY
       
   729     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
       
   730     clearOutstandingPopup( dialog );
       
   731     bool operationCompleted( true );
       
   732 
       
   733     if ( selectedAction ) {
       
   734         QString objectName = selectedAction->objectName();
       
   735         if ( objectName == KOk ) {
       
   736             QString newPlaylistName = dialog->value().toString();
       
   737             if ( newPlaylistName.length() ) {
       
   738                 //Store the new playlist name and query for the items to be added
       
   739                 mPermanentData->mOriginalName = newPlaylistName;
       
   740                 getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), 
       
   741                                  mPermanentData->mAbstractItemModel, 
       
   742                                  SLOT( handleCreateNewPlaylistGetModelIndexesFinished( HbAction* ) ) );
       
   743             }
       
   744             else {
       
   745                 //No valid name, prompt for one again.
       
   746                 getText( hbTrId( "txt_mus_dialog_enter_name" ), newPlaylistName,
       
   747                          SLOT( handleCreateNewPlaylistGetTextFinished( HbAction* ) ) );
       
   748             }
       
   749             operationCompleted = false;
       
   750         }
       
   751     }
       
   752 
       
   753     if ( operationCompleted ) {
       
   754         mPermanentData->clear();
       
   755     }
       
   756     TX_EXIT
       
   757 }
       
   758 
       
   759 /*!
       
   760  Slot to be called when the select songs dialog (getModelIndexes) has finished, coming from CreateNewPlaylist-GetText.
       
   761  */
       
   762 void MpCollectionPopupHandler::handleCreateNewPlaylistGetModelIndexesFinished( HbAction *selectedAction )
       
   763 {
       
   764     TX_ENTRY
       
   765     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
       
   766     clearOutstandingPopup( dialog );
       
   767 
       
   768     if ( selectedAction ) {
       
   769         QString objectName = selectedAction->objectName();
       
   770         if ( objectName == KOk ) {
       
   771             QList<int> selection;
       
   772             QModelIndexList selectedModelIndexes;
       
   773             selectedModelIndexes = dialog->selectedModelIndexes();
       
   774             if ( selectedModelIndexes.count() ) {
       
   775                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
       
   776                     selection.append( selectedModelIndexes.at( i ).row() );
       
   777                 }
       
   778             }
       
   779             //Creating Playlist even when there is no selection.
       
   780             mMpEngine->createPlaylist( mPermanentData->mOriginalName, selection,
       
   781                     mPermanentData->mIsolatedCollectionData );
       
   782         }
       
   783     }
       
   784 
       
   785     //Dialog is using an isolated model which will be deleted, no need to change its layout.
       
   786     mPermanentData->clear();
       
   787 
       
   788     TX_EXIT
       
   789 }
       
   790 
       
   791 /*!
       
   792  Slot to be called when arrange songs dialog has finished.
       
   793  */
       
   794 void MpCollectionPopupHandler::handleArrangeSongs( HbAction *selectedAction )
       
   795 {
       
   796     TX_ENTRY
       
   797     Q_UNUSED( selectedAction );
       
   798     HbDialog *dialog = qobject_cast<HbDialog *>( sender() );
       
   799     clearOutstandingPopup( dialog );
       
   800     
       
   801     //Reopen the collection so the ordinals get fixed on the view list, if we
       
   802     //delete items the index will not match to the item on the collection.
       
   803     mMpEngine->reopenCollection();
       
   804             
       
   805     TX_EXIT
       
   806 }
       
   807 
       
   808 /*!
       
   809  Slot to be called when delete confirmation dialog has finished.
       
   810  */
       
   811 void MpCollectionPopupHandler::handleRequestDelete( HbAction *selectedAction )
       
   812 {
       
   813     TX_ENTRY
       
   814     HbMessageBox *dialog = qobject_cast<HbMessageBox *>( sender() );
       
   815     clearOutstandingPopup( dialog );
       
   816     
       
   817     if ( selectedAction ) {
       
   818         QString objectName = selectedAction->objectName();
       
   819         if ( objectName == KOk ) {
       
   820             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
       
   821         }
       
   822         selectedAction->setEnabled( false );
       
   823     }
       
   824 
       
   825     mPermanentData->clear();
       
   826 
       
   827     TX_EXIT
       
   828 }
       
   829 
       
   830 /*!
       
   831  Slot called upon notification from MpEngine indicating start of
       
   832  deleting process.
       
   833  */
       
   834 void MpCollectionPopupHandler::handleDeleteStarted( TCollectionContext context, int count )
       
   835 {
       
   836     TX_ENTRY
       
   837     if ( context == ECollectionContextPlaylistSongs ) {
       
   838         if (count >= KSongsToDisplayProgressDlg) {  //show progress dialog if removing more than 100 songs
       
   839             launchProgressDialog( "txt_mus_info_removing_songs" );
       
   840         }
       
   841     }
       
   842     else if (context != ECollectionContextPlaylists ) {  //no progress dialog for delete playlist
       
   843         launchProgressDialog( "txt_common_info_deleting" );
       
   844     }
       
   845     TX_EXIT
       
   846 }
       
   847 
       
   848 /*!
       
   849  Slot called upon notification from MpEngine indicating 'count' songs are going to be added.
       
   850  */
       
   851 void MpCollectionPopupHandler::handleAddingSongs( int count )
       
   852 {
       
   853     TX_ENTRY
       
   854     if ( count >= KSongsToDisplayProgressDlg )
       
   855     {
       
   856         HbProgressDialog *addSongsWaitNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   857         connect( addSongsWaitNote, SIGNAL( cancelled() ), mMpEngine, SLOT( cancelCollectionRequest() ) );
       
   858         addSongsWaitNote->setModal( true );
       
   859         addSongsWaitNote->setText( hbTrId( "txt_mus_info_adding_songs" ) );
       
   860         addSongsWaitNote->setObjectName( KProgressDialog );
       
   861         addSongsWaitNote->setAttribute( Qt::WA_DeleteOnClose );
       
   862         setOutstandingPopup( addSongsWaitNote );
       
   863         addSongsWaitNote->show();
       
   864     }
       
   865     TX_EXIT
       
   866 }
       
   867 
       
   868 /*!
       
   869  Slot called upon notification from MpEngine indicating end of
       
   870  deleting or adding process.
       
   871  */
       
   872 void MpCollectionPopupHandler::handleOperationEnded( bool success )
       
   873 {
       
   874     TX_ENTRY
       
   875     Q_UNUSED( success );
       
   876     if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KProgressDialog ) ) {
       
   877         HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
       
   878         dialog->cancel();
       
   879     }
       
   880     TX_EXIT
       
   881 }
       
   882 
       
   883 /*!
       
   884  Slot to be called when a popup is getting closed. Usefull when a dialog is closed before it finishes
       
   885  (dialog not closed by a direct user action).
       
   886  */
       
   887 void MpCollectionPopupHandler::outstandingPopupClosing()
       
   888 {
       
   889     TX_ENTRY
       
   890     HbPopup *popup = qobject_cast<HbPopup *>( sender() );
       
   891     if ( popup ) {
       
   892         Q_ASSERT( popup == mOutstandingPopup );
       
   893         mOutstandingPopup = 0;
       
   894     }
       
   895     TX_EXIT
       
   896 }
       
   897 
       
   898 /*!
       
   899  \internal
       
   900  sets \a popup as the current outstanding popup and cancels any other previous popup.
       
   901  */
       
   902 void MpCollectionPopupHandler::setOutstandingPopup( HbPopup *popup )
       
   903 {
       
   904     TX_ENTRY
       
   905     if ( mOutstandingPopup ) {
       
   906         TX_LOG_ARGS( "Warning: Multiple popups attempted to be displayed" );
       
   907         mOutstandingPopup->close();
       
   908     }
       
   909 
       
   910     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
   911     mOutstandingPopup = popup;
       
   912     TX_EXIT
       
   913 }
       
   914 
       
   915 /*!
       
   916  \internal
       
   917  clears and disconnects \a popup. In some cases it's needed to open a new dialog when a current one has just finished.
       
   918  */
       
   919 void MpCollectionPopupHandler::clearOutstandingPopup( HbPopup *popup )
       
   920 {
       
   921     TX_ENTRY
       
   922     disconnect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
   923     mOutstandingPopup = 0;
       
   924     TX_EXIT
       
   925 }
       
   926 
       
   927 /*!
       
   928  \internal
       
   929  Launches the 'Add to playlist' dialog.
       
   930  */
       
   931 void MpCollectionPopupHandler::launchAddToPlaylistDialog( QList<int> &selection )
       
   932 {
       
   933     TX_ENTRY
       
   934 
       
   935     QStringList playlists;
       
   936     mPermanentData->mSelectedItems = selection;
       
   937     mMpEngine->findPlaylists( playlists );
       
   938     if ( playlists.count() ) {
       
   939         //There are saved playlists, query for a saved playlist or new.
       
   940         HbAction *action;
       
   941         HbSelectionDialog *dialog = new HbSelectionDialog();
       
   942         dialog->setStringItems( playlists );
       
   943         dialog->setSelectionMode( HbAbstractItemView::SingleSelection );
       
   944         dialog->setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) );
       
   945         dialog->clearActions();
       
   946         action = new HbAction( hbTrId( "txt_mus_button_new" ) );
       
   947         action->setObjectName( KNew );
       
   948         dialog->addAction( action );
       
   949         action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
   950         action->setObjectName( KCancel );
       
   951         dialog->addAction( action );
       
   952         dialog->setObjectName( KAddToPlaylistSelectionDialog );
       
   953         dialog->setAttribute( Qt::WA_DeleteOnClose );
       
   954         setOutstandingPopup( dialog );
       
   955         dialog->open( this, SLOT( handleAddToPlaylistDialogFinished( HbAction* ) ) );
       
   956     }
       
   957     else {
       
   958         //querying for a new playlist name.
       
   959         queryNewPlaylistName( playlists, SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
       
   960     }
       
   961     TX_EXIT
       
   962 }
       
   963 
       
   964 /*!
       
   965  \internal
       
   966  Trigger an imput text dialog with a suggested playlist name.
       
   967  uses \a playlists to generate a suggested playlist name
       
   968  \handler Slot that should be called when input dialog finished 
       
   969  */
       
   970 void MpCollectionPopupHandler::queryNewPlaylistName(const QStringList &playlists,
       
   971                                                     const char *handler ) 
       
   972 {
       
   973     TX_ENTRY
       
   974     int i = 0;
       
   975     for ( ;
       
   976          playlists.contains( hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i ) ) ;
       
   977          i++ ) {};
       
   978     QString suggestedPlaylistName = hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i );
       
   979     getText( hbTrId( "txt_mus_dialog_enter_name" ), suggestedPlaylistName, handler );
       
   980     TX_EXIT
       
   981 }
       
   982 
       
   983 /*!
       
   984  \internal
       
   985  Launches an input text dialog.
       
   986  \a label Dialog title.
       
   987  \a text Suggested text.
       
   988  \a handler Slot to be called when input dialog finishes.
       
   989  */
       
   990 void MpCollectionPopupHandler::getText( const QString &label, const QString &text,
       
   991                                         const char *handler )
       
   992 {
       
   993     TX_ENTRY
       
   994     HbAction *action;
       
   995     HbInputDialog *dialog = new HbInputDialog();
       
   996     dialog->setPromptText( label );
       
   997     dialog->setInputMode( HbInputDialog::TextInput );
       
   998     dialog->setValue( text );
       
   999     dialog->clearActions();
       
  1000     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
       
  1001     action->setObjectName( KOk );
       
  1002     dialog->addAction( action );
       
  1003     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
  1004     action->setObjectName( KCancel );
       
  1005     dialog->addAction( action );
       
  1006     dialog->setObjectName( KInputTextDialog );
       
  1007     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1008     setOutstandingPopup( dialog );
       
  1009     dialog->open( this, handler );
       
  1010     TX_EXIT
       
  1011 }
       
  1012 
       
  1013 /*!
       
  1014  \internal
       
  1015  Launches a list dialog to select items.
       
  1016  \a label Dialog title.
       
  1017  \a model List model.
       
  1018  \a handler Slot to be called when list dialog finishes.
       
  1019  */
       
  1020 void MpCollectionPopupHandler::getModelIndexes( const QString &label, QAbstractItemModel* model,
       
  1021                                                 const char *handler)
       
  1022 {   
       
  1023     TX_ENTRY
       
  1024 
       
  1025     connectExternalEvents();
       
  1026 
       
  1027     HbAction *action;
       
  1028     HbSelectionDialog *dialog = new HbSelectionDialog();
       
  1029     dialog->setHeadingWidget( new HbLabel( label ) );
       
  1030     dialog->setSelectionMode( HbAbstractItemView::MultiSelection );
       
  1031     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( model );
       
  1032     if ( mpModel ) {
       
  1033         //setLayout() only applies for MpCollectionDataModel where we need to 
       
  1034         //decide which layout to use for the secondary text.
       
  1035         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
  1036         mpModel->setLayout( ECollectionSelectionDialog );
       
  1037     }
       
  1038     dialog->setModel( model );
       
  1039     dialog->clearActions();
       
  1040     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
       
  1041     action->setObjectName( KOk );
       
  1042     dialog->addAction( action );
       
  1043     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
  1044     action->setObjectName( KCancel );
       
  1045     dialog->addAction( action );
       
  1046     dialog->setObjectName( KGetModelIndexesListDialog );
       
  1047     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1048     setOutstandingPopup( dialog );
       
  1049     dialog->open( this, handler );
       
  1050 
       
  1051     TX_EXIT
       
  1052 }
       
  1053 
       
  1054 /*!
       
  1055  \internal
       
  1056  Launches a list dialog to reorder them.
       
  1057  */
       
  1058 void MpCollectionPopupHandler::launchArrangeSongsDialog()
       
  1059 {   
       
  1060     TX_ENTRY
       
  1061 
       
  1062     HbListView *listView = new HbListView();
       
  1063     listView->setItemRecycling( true );
       
  1064     listView->setScrollingStyle( HbListView::PanOrFlick );
       
  1065     listView->setClampingStyle( HbListView::BounceBackClamping );
       
  1066     HbScrollBar *scrollbar = listView->verticalScrollBar();
       
  1067     scrollbar->show();
       
  1068     scrollbar->setInteractive( true);
       
  1069     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
       
  1070     MpCollectionDataModel *model;
       
  1071     //Ownership of the model is passed to the listView as a child object.
       
  1072     model = new MpCollectionDataModel( mMpEngine->collectionData() , mMpEngine->playbackData(), listView );
       
  1073     model->refreshModel();
       
  1074     connect( model,
       
  1075              SIGNAL( orderChanged( int, int, int, int ) ),
       
  1076              mMpEngine,
       
  1077              SLOT( reorderPlaylist( int, int, int, int ) ) );
       
  1078     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( model );
       
  1079     if ( mpModel ) {
       
  1080         //setLayout() only applies for MpCollectionDataModel where we need to 
       
  1081         //decide which layout to use for the secondary text.
       
  1082         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
  1083         mpModel->setLayout( ECollectionArrangeSongsDialog );
       
  1084     }
       
  1085     listView->setModel( model );
       
  1086     listView->setArrangeMode( true );
       
  1087     HbDialog *dialog = new HbDialog();
       
  1088     dialog->setDismissPolicy( HbPopup::NoDismiss );
       
  1089     dialog->setTimeout( HbPopup::NoTimeout );
       
  1090 
       
  1091     HbLabel *label = new HbLabel( hbTrId( "txt_mus_title_arrange"  ) );
       
  1092     dialog->setHeadingWidget( label );
       
  1093     dialog->setContentWidget( listView );
       
  1094     dialog->clearActions();
       
  1095     HbAction *action;
       
  1096     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
       
  1097     dialog->addAction( action );
       
  1098     dialog->setObjectName( KArrangeSongsDialog );
       
  1099     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1100     setOutstandingPopup(dialog);
       
  1101     dialog->open( this, SLOT( handleArrangeSongs( HbAction* ) ) );
       
  1102 
       
  1103     TX_EXIT
       
  1104 }
       
  1105 
       
  1106 /*!
       
  1107  \internal
       
  1108  Request a delete operation always it has been confirmed.
       
  1109  \a selection Items selected to be deleted.
       
  1110  */
       
  1111 void MpCollectionPopupHandler::requestDelete( QList<int> &selection )
       
  1112 {
       
  1113     TX_ENTRY
       
  1114     QString message;
       
  1115     mPermanentData->mSelectedItems = selection;
       
  1116     bool needsConfirmation = true;
       
  1117     connectExternalEvents();
       
  1118 
       
  1119     switch ( mMpEngine->collectionData()->context() ) {
       
  1120         case ECollectionContextAllSongs:
       
  1121         case ECollectionContextArtistAlbumsTBone:
       
  1122         case ECollectionContextArtistAllSongs:
       
  1123         case ECollectionContextAlbumsTBone:
       
  1124             message = hbTrId( "txt_mus_delete_song" );
       
  1125             break;
       
  1126         case ECollectionContextArtists:
       
  1127             message = hbTrId( "txt_mus_delete_artist" );
       
  1128             break;
       
  1129         case ECollectionContextAlbums:
       
  1130         case ECollectionContextArtistAlbums:
       
  1131             message = hbTrId( "txt_mus_delete_album" );
       
  1132             break;
       
  1133         case ECollectionContextPlaylists:
       
  1134             message = hbTrId( "txt_mus_delete_playlist" );
       
  1135             break;
       
  1136         case ECollectionContextPlaylistSongs:
       
  1137             needsConfirmation = false;
       
  1138             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
       
  1139             mPermanentData->clear();
       
  1140             break;
       
  1141         case ECollectionContextUnknown:
       
  1142         default:
       
  1143             // We shouldn't be here
       
  1144             needsConfirmation = false;
       
  1145             mPermanentData->clear();
       
  1146             TX_LOG_ARGS( "Invalid Collection Context" );
       
  1147             break;
       
  1148     }
       
  1149 
       
  1150     if ( needsConfirmation ) {
       
  1151         HbAction *action;
       
  1152         HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
       
  1153 
       
  1154         dialog->setText( message );
       
  1155         dialog->setTimeout( HbPopup::NoTimeout );
       
  1156         dialog->clearActions();
       
  1157         action = new HbAction( hbTrId( "txt_common_button_yes" ) );
       
  1158         action->setObjectName( KOk );
       
  1159         dialog->addAction( action );
       
  1160         action = new HbAction( hbTrId( "txt_common_button_no" ) );
       
  1161         action->setObjectName( KCancel );
       
  1162         dialog->addAction( action );
       
  1163         dialog->setObjectName( KRequestDeleteMessageBox );
       
  1164         dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1165         setOutstandingPopup( dialog );
       
  1166         dialog->open( this, SLOT( handleRequestDelete( HbAction* ) ) );
       
  1167     }
       
  1168 
       
  1169     TX_EXIT
       
  1170 }
       
  1171 
       
  1172 /*!
       
  1173  \internal
       
  1174  Launches a waiting progress note.
       
  1175  \a content String id to display in the dialog.
       
  1176  */
       
  1177 void MpCollectionPopupHandler::launchProgressDialog( const char *id )
       
  1178 {
       
  1179     HbProgressDialog *deleteProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
  1180     connect( deleteProgressNote, SIGNAL( cancelled() ), mMpEngine, SLOT( cancelCollectionRequest() ) );
       
  1181     deleteProgressNote->setModal( true );
       
  1182     deleteProgressNote->setDismissPolicy( HbPopup::NoDismiss );
       
  1183     deleteProgressNote->setText( hbTrId( id ) );
       
  1184     deleteProgressNote->setObjectName( KProgressDialog );
       
  1185     deleteProgressNote->setAttribute( Qt::WA_DeleteOnClose );
       
  1186     setOutstandingPopup( deleteProgressNote );
       
  1187     deleteProgressNote->show();
       
  1188 }
       
  1189 
       
  1190 /*!
       
  1191  \internal
       
  1192  Connects MpEngine signals on demand in order to save time at start up.
       
  1193   */
       
  1194 void MpCollectionPopupHandler::connectExternalEvents()
       
  1195 {
       
  1196     if ( !mExternalEventsConnected ) {
       
  1197         connect( mMpEngine, SIGNAL( deleteStarted( TCollectionContext, int ) ),
       
  1198                 this, SLOT( handleDeleteStarted( TCollectionContext, int ) ) );
       
  1199         connect( mMpEngine, SIGNAL( songsDeleted( bool ) ), this, SLOT( handleOperationEnded( bool ) ) );
       
  1200         connect( mMpEngine, SIGNAL( aboutToAddSongs( int ) ), this, SLOT( handleAddingSongs( int ) ) );
       
  1201         connect( mMpEngine, SIGNAL( playlistSaved( bool ) ), this, SLOT( handleOperationEnded( bool ) ) );
       
  1202         mExternalEventsConnected = true;
       
  1203     }
       
  1204 }
       
  1205